@utsp/types 0.1.1
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 -0
- package/README.md +36 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +1124 -0
- package/dist/index.mjs +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Thomas Piquet
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# @utsp/types
|
|
2
|
+
|
|
3
|
+
> ⚠️ **PROTOTYPE - NOT READY FOR PRODUCTION**
|
|
4
|
+
>
|
|
5
|
+
> This package is currently in early development and should **NOT** be used in production.
|
|
6
|
+
> The API is unstable and subject to breaking changes without notice.
|
|
7
|
+
|
|
8
|
+
Shared TypeScript types and interfaces for the UTSP (Universal Text Stream Protocol) monorepo.
|
|
9
|
+
|
|
10
|
+
[](https://opensource.org/licenses/MIT)
|
|
11
|
+
|
|
12
|
+
## ⚠️ Development Status
|
|
13
|
+
|
|
14
|
+
**This is a prototype package under active development.**
|
|
15
|
+
|
|
16
|
+
- ❌ No stable API
|
|
17
|
+
- ❌ No documentation available yet
|
|
18
|
+
- ❌ Breaking changes expected
|
|
19
|
+
- ❌ Not recommended for production use
|
|
20
|
+
|
|
21
|
+
**Please check back later for updates or watch the repository for release announcements.**
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @utsp/types
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Repository
|
|
30
|
+
|
|
31
|
+
- [GitHub](https://github.com/thp-software/utsp)
|
|
32
|
+
- [Issues](https://github.com/thp-software/utsp/issues)
|
|
33
|
+
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
MIT © 2025 Thomas Piquet
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var L=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var p=(e,r,h)=>r in e?L(e,r,{enumerable:!0,configurable:!0,writable:!0,value:h}):e[r]=h;var n=(e,r)=>L(e,"name",{value:r,configurable:!0});var K=(e,r)=>{for(var h in r)L(e,h,{get:r[h],enumerable:!0})},I=(e,r,h,f)=>{if(r&&typeof r=="object"||typeof r=="function")for(let D of d(r))!b.call(e,D)&&D!==h&&L(e,D,{get:()=>r[D],enumerable:!(f=R(r,D))||f.enumerable});return e};var ii=e=>I(L({},"__esModule",{value:!0}),e);var z=(e,r,h)=>(p(e,typeof r!="symbol"?r+"":r,h),h);var ri={};K(ri,{GamepadInput:()=>B,InputDeviceType:()=>P,KeyboardInput:()=>w,MouseInput:()=>A,NetworkState:()=>T,TVRemoteInput:()=>k,TouchInput:()=>S,Vector2:()=>Y,Vector3:()=>X,createInputDescriptor:()=>j,deserializeInputDescriptor:()=>V,gamepadAxisIndexToInput:()=>q,gamepadButtonIndexToInput:()=>u,getTouchXAxis:()=>O,getTouchYAxis:()=>W,inputDescriptorToString:()=>y,isAxis:()=>J,isButton:()=>E,isGamepadAxis:()=>F,isGamepadButton:()=>a,isMouseAxis:()=>N,isMouseButton:()=>M,isTVRemoteAxis:()=>Z,isTVRemoteButton:()=>Q,isTouchButton:()=>U,isTouchGesture:()=>$,isTouchPosition:()=>H,keyCodeToKeyboardInput:()=>C,keyboardInputToKeyCode:()=>v,parseInputDescriptor:()=>_,serializeInputDescriptor:()=>G});module.exports=ii(ri);var P=(g=>(g[g.Keyboard=0]="Keyboard",g[g.Mouse=1]="Mouse",g[g.Gamepad=2]="Gamepad",g[g.Touch=3]="Touch",g[g.TVRemote=4]="TVRemote",g[g.TextInput=5]="TextInput",g))(P||{});var w=(i=>(i[i.KeyA=0]="KeyA",i[i.KeyB=1]="KeyB",i[i.KeyC=2]="KeyC",i[i.KeyD=3]="KeyD",i[i.KeyE=4]="KeyE",i[i.KeyF=5]="KeyF",i[i.KeyG=6]="KeyG",i[i.KeyH=7]="KeyH",i[i.KeyI=8]="KeyI",i[i.KeyJ=9]="KeyJ",i[i.KeyK=10]="KeyK",i[i.KeyL=11]="KeyL",i[i.KeyM=12]="KeyM",i[i.KeyN=13]="KeyN",i[i.KeyO=14]="KeyO",i[i.KeyP=15]="KeyP",i[i.KeyQ=16]="KeyQ",i[i.KeyR=17]="KeyR",i[i.KeyS=18]="KeyS",i[i.KeyT=19]="KeyT",i[i.KeyU=20]="KeyU",i[i.KeyV=21]="KeyV",i[i.KeyW=22]="KeyW",i[i.KeyX=23]="KeyX",i[i.KeyY=24]="KeyY",i[i.KeyZ=25]="KeyZ",i[i.Digit0=26]="Digit0",i[i.Digit1=27]="Digit1",i[i.Digit2=28]="Digit2",i[i.Digit3=29]="Digit3",i[i.Digit4=30]="Digit4",i[i.Digit5=31]="Digit5",i[i.Digit6=32]="Digit6",i[i.Digit7=33]="Digit7",i[i.Digit8=34]="Digit8",i[i.Digit9=35]="Digit9",i[i.ArrowUp=36]="ArrowUp",i[i.ArrowDown=37]="ArrowDown",i[i.ArrowLeft=38]="ArrowLeft",i[i.ArrowRight=39]="ArrowRight",i[i.Space=40]="Space",i[i.Enter=41]="Enter",i[i.Escape=42]="Escape",i[i.Backspace=43]="Backspace",i[i.Tab=44]="Tab",i[i.ShiftLeft=45]="ShiftLeft",i[i.ShiftRight=46]="ShiftRight",i[i.ControlLeft=47]="ControlLeft",i[i.ControlRight=48]="ControlRight",i[i.AltLeft=49]="AltLeft",i[i.AltRight=50]="AltRight",i[i.MetaLeft=51]="MetaLeft",i[i.MetaRight=52]="MetaRight",i[i.CapsLock=53]="CapsLock",i[i.Delete=54]="Delete",i[i.Insert=55]="Insert",i[i.Home=56]="Home",i[i.End=57]="End",i[i.PageUp=58]="PageUp",i[i.PageDown=59]="PageDown",i[i.F1=60]="F1",i[i.F2=61]="F2",i[i.F3=62]="F3",i[i.F4=63]="F4",i[i.F5=64]="F5",i[i.F6=65]="F6",i[i.F7=66]="F7",i[i.F8=67]="F8",i[i.F9=68]="F9",i[i.F10=69]="F10",i[i.F11=70]="F11",i[i.F12=71]="F12",i[i.Minus=72]="Minus",i[i.Equal=73]="Equal",i[i.BracketLeft=74]="BracketLeft",i[i.BracketRight=75]="BracketRight",i[i.Backslash=76]="Backslash",i[i.Semicolon=77]="Semicolon",i[i.Quote=78]="Quote",i[i.Comma=79]="Comma",i[i.Period=80]="Period",i[i.Slash=81]="Slash",i[i.Backquote=82]="Backquote",i[i.Numpad0=91]="Numpad0",i[i.Numpad1=92]="Numpad1",i[i.Numpad2=93]="Numpad2",i[i.Numpad3=94]="Numpad3",i[i.Numpad4=95]="Numpad4",i[i.Numpad5=96]="Numpad5",i[i.Numpad6=97]="Numpad6",i[i.Numpad7=98]="Numpad7",i[i.Numpad8=99]="Numpad8",i[i.Numpad9=100]="Numpad9",i[i.NumpadAdd=101]="NumpadAdd",i[i.NumpadSubtract=102]="NumpadSubtract",i[i.NumpadMultiply=103]="NumpadMultiply",i[i.NumpadDivide=104]="NumpadDivide",i[i.NumpadDecimal=105]="NumpadDecimal",i[i.NumpadEnter=106]="NumpadEnter",i[i.NumLock=107]="NumLock",i[i.PrintScreen=111]="PrintScreen",i[i.ScrollLock=112]="ScrollLock",i[i.Pause=113]="Pause",i[i.ContextMenu=114]="ContextMenu",i))(w||{});function C(e){let r=w[e];return r!==void 0?r:null}n(C,"keyCodeToKeyboardInput");function v(e){return w[e]}n(v,"keyboardInputToKeyCode");var A=(x=>(x[x.LeftButton=0]="LeftButton",x[x.MiddleButton=1]="MiddleButton",x[x.RightButton=2]="RightButton",x[x.Button4=3]="Button4",x[x.Button5=4]="Button5",x[x.PositionX=100]="PositionX",x[x.PositionY=101]="PositionY",x[x.DeltaX=102]="DeltaX",x[x.DeltaY=103]="DeltaY",x[x.WheelDeltaY=104]="WheelDeltaY",x[x.WheelDeltaX=105]="WheelDeltaX",x))(A||{});function M(e){return e<100}n(M,"isMouseButton");function N(e){return e>=100}n(N,"isMouseAxis");var B=(c=>(c[c.ButtonA=0]="ButtonA",c[c.ButtonB=1]="ButtonB",c[c.ButtonX=2]="ButtonX",c[c.ButtonY=3]="ButtonY",c[c.LeftShoulder=4]="LeftShoulder",c[c.RightShoulder=5]="RightShoulder",c[c.LeftTrigger=6]="LeftTrigger",c[c.RightTrigger=7]="RightTrigger",c[c.Select=8]="Select",c[c.Start=9]="Start",c[c.LeftStick=10]="LeftStick",c[c.RightStick=11]="RightStick",c[c.DPadUp=12]="DPadUp",c[c.DPadDown=13]="DPadDown",c[c.DPadLeft=14]="DPadLeft",c[c.DPadRight=15]="DPadRight",c[c.Home=16]="Home",c[c.Touchpad=17]="Touchpad",c[c.LeftStickX=100]="LeftStickX",c[c.LeftStickY=101]="LeftStickY",c[c.RightStickX=102]="RightStickX",c[c.RightStickY=103]="RightStickY",c[c.LeftTriggerAxis=104]="LeftTriggerAxis",c[c.RightTriggerAxis=105]="RightTriggerAxis",c))(B||{});function a(e){return e<100}n(a,"isGamepadButton");function F(e){return e>=100}n(F,"isGamepadAxis");function u(e){return e>=0&&e<=19?e:null}n(u,"gamepadButtonIndexToInput");function q(e){return{0:100,1:101,2:102,3:103}[e]??null}n(q,"gamepadAxisIndexToInput");var S=(s=>(s[s.Touch0=0]="Touch0",s[s.Touch1=1]="Touch1",s[s.Touch2=2]="Touch2",s[s.Touch3=3]="Touch3",s[s.Touch4=4]="Touch4",s[s.Touch5=5]="Touch5",s[s.Touch6=6]="Touch6",s[s.Touch7=7]="Touch7",s[s.Touch8=8]="Touch8",s[s.Touch9=9]="Touch9",s[s.Touch0X=100]="Touch0X",s[s.Touch0Y=101]="Touch0Y",s[s.Touch1X=102]="Touch1X",s[s.Touch1Y=103]="Touch1Y",s[s.Touch2X=104]="Touch2X",s[s.Touch2Y=105]="Touch2Y",s[s.Touch3X=106]="Touch3X",s[s.Touch3Y=107]="Touch3Y",s[s.Touch4X=108]="Touch4X",s[s.Touch4Y=109]="Touch4Y",s[s.Touch5X=110]="Touch5X",s[s.Touch5Y=111]="Touch5Y",s[s.Touch6X=112]="Touch6X",s[s.Touch6Y=113]="Touch6Y",s[s.Touch7X=114]="Touch7X",s[s.Touch7Y=115]="Touch7Y",s[s.Touch8X=116]="Touch8X",s[s.Touch8Y=117]="Touch8Y",s[s.Touch9X=118]="Touch9X",s[s.Touch9Y=119]="Touch9Y",s[s.PinchScale=200]="PinchScale",s[s.RotationAngle=201]="RotationAngle",s[s.SwipeVelocityX=202]="SwipeVelocityX",s[s.SwipeVelocityY=203]="SwipeVelocityY",s))(S||{});function U(e){return e<100}n(U,"isTouchButton");function H(e){return e>=100&&e<200}n(H,"isTouchPosition");function $(e){return e>=200}n($,"isTouchGesture");function O(e){return e<0||e>9?null:100+e*2}n(O,"getTouchXAxis");function W(e){return e<0||e>9?null:101+e*2}n(W,"getTouchYAxis");var k=(t=>(t[t.DPadUp=0]="DPadUp",t[t.DPadDown=1]="DPadDown",t[t.DPadLeft=2]="DPadLeft",t[t.DPadRight=3]="DPadRight",t[t.DPadCenter=4]="DPadCenter",t[t.Play=5]="Play",t[t.Pause=6]="Pause",t[t.PlayPause=7]="PlayPause",t[t.Stop=8]="Stop",t[t.Rewind=9]="Rewind",t[t.FastForward=10]="FastForward",t[t.Previous=11]="Previous",t[t.Next=12]="Next",t[t.Record=13]="Record",t[t.VolumeUp=15]="VolumeUp",t[t.VolumeDown=16]="VolumeDown",t[t.Mute=17]="Mute",t[t.ChannelUp=18]="ChannelUp",t[t.ChannelDown=19]="ChannelDown",t[t.Back=20]="Back",t[t.Home=21]="Home",t[t.Menu=22]="Menu",t[t.Info=23]="Info",t[t.Guide=24]="Guide",t[t.Exit=25]="Exit",t[t.Red=30]="Red",t[t.Green=31]="Green",t[t.Yellow=32]="Yellow",t[t.Blue=33]="Blue",t[t.Digit0=40]="Digit0",t[t.Digit1=41]="Digit1",t[t.Digit2=42]="Digit2",t[t.Digit3=43]="Digit3",t[t.Digit4=44]="Digit4",t[t.Digit5=45]="Digit5",t[t.Digit6=46]="Digit6",t[t.Digit7=47]="Digit7",t[t.Digit8=48]="Digit8",t[t.Digit9=49]="Digit9",t[t.Input=50]="Input",t[t.Settings=51]="Settings",t[t.Subtitle=52]="Subtitle",t[t.Audio=53]="Audio",t[t.Power=54]="Power",t[t.PointerX=100]="PointerX",t[t.PointerY=101]="PointerY",t[t.GyroX=102]="GyroX",t[t.GyroY=103]="GyroY",t[t.GyroZ=104]="GyroZ",t))(k||{});function Q(e){return e<100}n(Q,"isTVRemoteButton");function Z(e){return e>=100}n(Z,"isTVRemoteAxis");function j(e,r){return{device:e,input:r}}n(j,"createInputDescriptor");function E(e){switch(e.device){case 0:return!0;case 1:return e.input<100;case 2:return e.input<100;case 3:return e.input<100;case 4:return e.input<100;default:return!1}}n(E,"isButton");function J(e){return!E(e)}n(J,"isAxis");function G(e){let r=new Uint8Array(3);return r[0]=e.device,r[1]=e.input&255,r[2]=e.input>>8&255,r}n(G,"serializeInputDescriptor");function V(e,r=0){let h=e[r],f=e[r+1]|e[r+2]<<8;return{device:h,input:f}}n(V,"deserializeInputDescriptor");function y(e){let r=P[e.device],h;switch(e.device){case 0:h=w[e.input];break;case 1:h=A[e.input];break;case 2:h=B[e.input];break;case 3:h=S[e.input];break;case 4:h=k[e.input];break;default:h="Unknown"}return`${r}:${h}`}n(y,"inputDescriptorToString");function _(e){let[r,h]=e.split(":");if(!r||!h)return null;let f=Object.entries(P).find(([m,g])=>m.toLowerCase()===r.toLowerCase()&&typeof g=="number")?.[1];if(f===void 0)return null;let D;switch(f){case 0:D=w[h];break;case 1:D=A[h];break;case 2:D=B[h];break;case 3:D=S[h];break;case 4:D=k[h];break}return D===void 0?null:{device:f,input:D}}n(_,"parseInputDescriptor");var l=class l{constructor(r=0,h=0){z(this,"x");z(this,"y");this.x=r,this.y=h}static zero(){return new l(0,0)}static one(){return new l(1,1)}static up(){return new l(0,-1)}static down(){return new l(0,1)}static left(){return new l(-1,0)}static right(){return new l(1,0)}add(r){return new l(this.x+r.x,this.y+r.y)}subtract(r){return new l(this.x-r.x,this.y-r.y)}multiply(r){return new l(this.x*r,this.y*r)}divide(r){if(r===0)throw new Error("Division by zero");return new l(this.x/r,this.y/r)}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}lengthSquared(){return this.x*this.x+this.y*this.y}normalize(){let r=this.length();return r===0?l.zero():this.divide(r)}distance(r){return this.subtract(r).length()}distanceSquared(r){return this.subtract(r).lengthSquared()}dot(r){return this.x*r.x+this.y*r.y}cross(r){return this.x*r.y-this.y*r.x}angle(){return Math.atan2(this.y,this.x)}angleTo(r){return Math.atan2(r.y-this.y,r.x-this.x)}rotate(r){let h=Math.cos(r),f=Math.sin(r);return new l(this.x*h-this.y*f,this.x*f+this.y*h)}lerp(r,h){return new l(this.x+(r.x-this.x)*h,this.y+(r.y-this.y)*h)}clone(){return new l(this.x,this.y)}equals(r){return this.x===r.x&&this.y===r.y}toString(){return`Vector2(${this.x}, ${this.y})`}toArray(){return[this.x,this.y]}set(r,h){return this.x=r,this.y=h,this}copy(r){return this.x=r.x,this.y=r.y,this}addInPlace(r){return this.x+=r.x,this.y+=r.y,this}subtractInPlace(r){return this.x-=r.x,this.y-=r.y,this}multiplyInPlace(r){return this.x*=r,this.y*=r,this}divideInPlace(r){if(r===0)throw new Error("Division by zero");return this.x/=r,this.y/=r,this}normalizeInPlace(){let r=this.length();return r===0?(this.x=0,this.y=0):(this.x/=r,this.y/=r),this}};n(l,"Vector2");var Y=l;var o=class o{constructor(r=0,h=0,f=0){z(this,"x");z(this,"y");z(this,"z");this.x=r,this.y=h,this.z=f}static zero(){return new o(0,0,0)}static one(){return new o(1,1,1)}static up(){return new o(0,1,0)}static down(){return new o(0,-1,0)}static left(){return new o(-1,0,0)}static right(){return new o(1,0,0)}static forward(){return new o(0,0,1)}static back(){return new o(0,0,-1)}add(r){return new o(this.x+r.x,this.y+r.y,this.z+r.z)}subtract(r){return new o(this.x-r.x,this.y-r.y,this.z-r.z)}multiply(r){return new o(this.x*r,this.y*r,this.z*r)}divide(r){if(r===0)throw new Error("Division by zero");return new o(this.x/r,this.y/r,this.z/r)}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}lengthSquared(){return this.x*this.x+this.y*this.y+this.z*this.z}normalize(){let r=this.length();return r===0?o.zero():this.divide(r)}distance(r){return this.subtract(r).length()}distanceSquared(r){return this.subtract(r).lengthSquared()}dot(r){return this.x*r.x+this.y*r.y+this.z*r.z}cross(r){return new o(this.y*r.z-this.z*r.y,this.z*r.x-this.x*r.z,this.x*r.y-this.y*r.x)}lerp(r,h){return new o(this.x+(r.x-this.x)*h,this.y+(r.y-this.y)*h,this.z+(r.z-this.z)*h)}clone(){return new o(this.x,this.y,this.z)}equals(r){return this.x===r.x&&this.y===r.y&&this.z===r.z}toString(){return`Vector3(${this.x}, ${this.y}, ${this.z})`}toArray(){return[this.x,this.y,this.z]}set(r,h,f){return this.x=r,this.y=h,this.z=f,this}copy(r){return this.x=r.x,this.y=r.y,this.z=r.z,this}addInPlace(r){return this.x+=r.x,this.y+=r.y,this.z+=r.z,this}subtractInPlace(r){return this.x-=r.x,this.y-=r.y,this.z-=r.z,this}multiplyInPlace(r){return this.x*=r,this.y*=r,this.z*=r,this}divideInPlace(r){if(r===0)throw new Error("Division by zero");return this.x/=r,this.y/=r,this.z/=r,this}normalizeInPlace(){let r=this.length();return r===0?(this.x=0,this.y=0,this.z=0):(this.x/=r,this.y/=r,this.z/=r),this}};n(o,"Vector3");var X=o;var T=(m=>(m[m.Disconnected=0]="Disconnected",m[m.Connecting=1]="Connecting",m[m.Connected=2]="Connected",m[m.Reconnecting=3]="Reconnecting",m[m.Error=4]="Error",m))(T||{});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input device types enumeration
|
|
3
|
+
* Each device type has its own input enum
|
|
4
|
+
*/
|
|
5
|
+
declare enum InputDeviceType {
|
|
6
|
+
Keyboard = 0,
|
|
7
|
+
Mouse = 1,
|
|
8
|
+
Gamepad = 2,
|
|
9
|
+
Touch = 3,
|
|
10
|
+
TVRemote = 4,
|
|
11
|
+
TextInput = 5
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Keyboard input enumeration
|
|
16
|
+
* Maps keyboard keys to numeric values for efficient storage and comparison
|
|
17
|
+
*
|
|
18
|
+
* Based on KeyboardEvent.code standard
|
|
19
|
+
*/
|
|
20
|
+
declare enum KeyboardInput {
|
|
21
|
+
KeyA = 0,
|
|
22
|
+
KeyB = 1,
|
|
23
|
+
KeyC = 2,
|
|
24
|
+
KeyD = 3,
|
|
25
|
+
KeyE = 4,
|
|
26
|
+
KeyF = 5,
|
|
27
|
+
KeyG = 6,
|
|
28
|
+
KeyH = 7,
|
|
29
|
+
KeyI = 8,
|
|
30
|
+
KeyJ = 9,
|
|
31
|
+
KeyK = 10,
|
|
32
|
+
KeyL = 11,
|
|
33
|
+
KeyM = 12,
|
|
34
|
+
KeyN = 13,
|
|
35
|
+
KeyO = 14,
|
|
36
|
+
KeyP = 15,
|
|
37
|
+
KeyQ = 16,
|
|
38
|
+
KeyR = 17,
|
|
39
|
+
KeyS = 18,
|
|
40
|
+
KeyT = 19,
|
|
41
|
+
KeyU = 20,
|
|
42
|
+
KeyV = 21,
|
|
43
|
+
KeyW = 22,
|
|
44
|
+
KeyX = 23,
|
|
45
|
+
KeyY = 24,
|
|
46
|
+
KeyZ = 25,
|
|
47
|
+
Digit0 = 26,
|
|
48
|
+
Digit1 = 27,
|
|
49
|
+
Digit2 = 28,
|
|
50
|
+
Digit3 = 29,
|
|
51
|
+
Digit4 = 30,
|
|
52
|
+
Digit5 = 31,
|
|
53
|
+
Digit6 = 32,
|
|
54
|
+
Digit7 = 33,
|
|
55
|
+
Digit8 = 34,
|
|
56
|
+
Digit9 = 35,
|
|
57
|
+
ArrowUp = 36,
|
|
58
|
+
ArrowDown = 37,
|
|
59
|
+
ArrowLeft = 38,
|
|
60
|
+
ArrowRight = 39,
|
|
61
|
+
Space = 40,
|
|
62
|
+
Enter = 41,
|
|
63
|
+
Escape = 42,
|
|
64
|
+
Backspace = 43,
|
|
65
|
+
Tab = 44,
|
|
66
|
+
ShiftLeft = 45,
|
|
67
|
+
ShiftRight = 46,
|
|
68
|
+
ControlLeft = 47,
|
|
69
|
+
ControlRight = 48,
|
|
70
|
+
AltLeft = 49,
|
|
71
|
+
AltRight = 50,
|
|
72
|
+
MetaLeft = 51,
|
|
73
|
+
MetaRight = 52,
|
|
74
|
+
CapsLock = 53,
|
|
75
|
+
Delete = 54,
|
|
76
|
+
Insert = 55,
|
|
77
|
+
Home = 56,
|
|
78
|
+
End = 57,
|
|
79
|
+
PageUp = 58,
|
|
80
|
+
PageDown = 59,
|
|
81
|
+
F1 = 60,
|
|
82
|
+
F2 = 61,
|
|
83
|
+
F3 = 62,
|
|
84
|
+
F4 = 63,
|
|
85
|
+
F5 = 64,
|
|
86
|
+
F6 = 65,
|
|
87
|
+
F7 = 66,
|
|
88
|
+
F8 = 67,
|
|
89
|
+
F9 = 68,
|
|
90
|
+
F10 = 69,
|
|
91
|
+
F11 = 70,
|
|
92
|
+
F12 = 71,
|
|
93
|
+
Minus = 72,
|
|
94
|
+
Equal = 73,
|
|
95
|
+
BracketLeft = 74,
|
|
96
|
+
BracketRight = 75,
|
|
97
|
+
Backslash = 76,
|
|
98
|
+
Semicolon = 77,
|
|
99
|
+
Quote = 78,
|
|
100
|
+
Comma = 79,
|
|
101
|
+
Period = 80,
|
|
102
|
+
Slash = 81,
|
|
103
|
+
Backquote = 82,
|
|
104
|
+
Numpad0 = 91,
|
|
105
|
+
Numpad1 = 92,
|
|
106
|
+
Numpad2 = 93,
|
|
107
|
+
Numpad3 = 94,
|
|
108
|
+
Numpad4 = 95,
|
|
109
|
+
Numpad5 = 96,
|
|
110
|
+
Numpad6 = 97,
|
|
111
|
+
Numpad7 = 98,
|
|
112
|
+
Numpad8 = 99,
|
|
113
|
+
Numpad9 = 100,
|
|
114
|
+
NumpadAdd = 101,
|
|
115
|
+
NumpadSubtract = 102,
|
|
116
|
+
NumpadMultiply = 103,
|
|
117
|
+
NumpadDivide = 104,
|
|
118
|
+
NumpadDecimal = 105,
|
|
119
|
+
NumpadEnter = 106,
|
|
120
|
+
NumLock = 107,
|
|
121
|
+
PrintScreen = 111,
|
|
122
|
+
ScrollLock = 112,
|
|
123
|
+
Pause = 113,
|
|
124
|
+
ContextMenu = 114
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Helper to convert KeyboardEvent.code to KeyboardInput enum
|
|
128
|
+
*/
|
|
129
|
+
declare function keyCodeToKeyboardInput(code: string): KeyboardInput | null;
|
|
130
|
+
/**
|
|
131
|
+
* Helper to convert KeyboardInput enum to KeyboardEvent.code
|
|
132
|
+
*/
|
|
133
|
+
declare function keyboardInputToKeyCode(input: KeyboardInput): string;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Mouse input enumeration
|
|
137
|
+
* Covers buttons and axes (position, delta, wheel)
|
|
138
|
+
*/
|
|
139
|
+
declare enum MouseInput {
|
|
140
|
+
LeftButton = 0,
|
|
141
|
+
MiddleButton = 1,
|
|
142
|
+
RightButton = 2,
|
|
143
|
+
Button4 = 3,// Back button
|
|
144
|
+
Button5 = 4,// Forward button
|
|
145
|
+
PositionX = 100,
|
|
146
|
+
PositionY = 101,
|
|
147
|
+
DeltaX = 102,
|
|
148
|
+
DeltaY = 103,
|
|
149
|
+
WheelDeltaY = 104,
|
|
150
|
+
WheelDeltaX = 105
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Check if the input is a button
|
|
154
|
+
*/
|
|
155
|
+
declare function isMouseButton(input: MouseInput): boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Check if the input is an axis
|
|
158
|
+
*/
|
|
159
|
+
declare function isMouseAxis(input: MouseInput): boolean;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Gamepad input enumeration
|
|
163
|
+
* Based on the Standard Gamepad mapping (W3C specification)
|
|
164
|
+
*
|
|
165
|
+
* Buttons: 0-99
|
|
166
|
+
* Axes: 100-199
|
|
167
|
+
*/
|
|
168
|
+
declare enum GamepadInput {
|
|
169
|
+
ButtonA = 0,// South (X on PlayStation, A on Xbox)
|
|
170
|
+
ButtonB = 1,// East (Circle on PlayStation, B on Xbox)
|
|
171
|
+
ButtonX = 2,// West (Square on PlayStation, X on Xbox)
|
|
172
|
+
ButtonY = 3,// North (Triangle on PlayStation, Y on Xbox)
|
|
173
|
+
LeftShoulder = 4,// L1 / LB
|
|
174
|
+
RightShoulder = 5,// R1 / RB
|
|
175
|
+
LeftTrigger = 6,// L2 / LT
|
|
176
|
+
RightTrigger = 7,// R2 / RT
|
|
177
|
+
Select = 8,// Select / Back / Share
|
|
178
|
+
Start = 9,// Start / Menu / Options
|
|
179
|
+
LeftStick = 10,// L3
|
|
180
|
+
RightStick = 11,// R3
|
|
181
|
+
DPadUp = 12,
|
|
182
|
+
DPadDown = 13,
|
|
183
|
+
DPadLeft = 14,
|
|
184
|
+
DPadRight = 15,
|
|
185
|
+
Home = 16,// PS button / Xbox button / Home
|
|
186
|
+
Touchpad = 17,// PlayStation touchpad button
|
|
187
|
+
LeftStickX = 100,
|
|
188
|
+
LeftStickY = 101,
|
|
189
|
+
RightStickX = 102,
|
|
190
|
+
RightStickY = 103,
|
|
191
|
+
LeftTriggerAxis = 104,// Alternative analog representation
|
|
192
|
+
RightTriggerAxis = 105
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Check if the input is a button
|
|
196
|
+
*/
|
|
197
|
+
declare function isGamepadButton(input: GamepadInput): boolean;
|
|
198
|
+
/**
|
|
199
|
+
* Check if the input is an axis
|
|
200
|
+
*/
|
|
201
|
+
declare function isGamepadAxis(input: GamepadInput): boolean;
|
|
202
|
+
/**
|
|
203
|
+
* Map from standard gamepad button index to GamepadInput enum
|
|
204
|
+
*/
|
|
205
|
+
declare function gamepadButtonIndexToInput(index: number): GamepadInput | null;
|
|
206
|
+
/**
|
|
207
|
+
* Map from standard gamepad axis index to GamepadInput enum
|
|
208
|
+
*/
|
|
209
|
+
declare function gamepadAxisIndexToInput(index: number): GamepadInput | null;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Physical source for an axis
|
|
213
|
+
*
|
|
214
|
+
* Different types of possible sources:
|
|
215
|
+
* - keyboard: Two keys (negative/positive)
|
|
216
|
+
* - gamepad: Analog axis (stick/trigger)
|
|
217
|
+
* - mouse: Mouse movement (delta X/Y or wheel)
|
|
218
|
+
* - gyroscope: Device orientation (pitch/roll/yaw)
|
|
219
|
+
* - touch: Virtual touch joystick
|
|
220
|
+
*/
|
|
221
|
+
interface AxisSource {
|
|
222
|
+
/** Unique source ID (0-255, for compression) */
|
|
223
|
+
sourceId: number;
|
|
224
|
+
/** Type of input source */
|
|
225
|
+
type: InputDeviceType;
|
|
226
|
+
/** Key for -1 value (e.g., KeyboardInput.ArrowLeft) */
|
|
227
|
+
negativeKey?: KeyboardInput;
|
|
228
|
+
/** Key for +1 value (e.g., KeyboardInput.ArrowRight) */
|
|
229
|
+
positiveKey?: KeyboardInput;
|
|
230
|
+
/** Gamepad index (0-3) */
|
|
231
|
+
gamepadIndex?: number;
|
|
232
|
+
/** Axis enum (e.g., GamepadInput.LeftStickX) */
|
|
233
|
+
axis?: GamepadInput;
|
|
234
|
+
/** Mouse axis enum (e.g., MouseInput.DeltaX, MouseInput.Wheel) */
|
|
235
|
+
mouseAxis?: MouseInput;
|
|
236
|
+
/** Rotation axis */
|
|
237
|
+
gyroAxis?: 'pitch' | 'roll' | 'yaw';
|
|
238
|
+
/** Virtual touch joystick ID (0-3) */
|
|
239
|
+
touchId?: number;
|
|
240
|
+
/** Joystick axis */
|
|
241
|
+
touchAxis?: 'x' | 'y';
|
|
242
|
+
/** Dead zone (default: 0.0) */
|
|
243
|
+
deadzone?: number;
|
|
244
|
+
/** Multiplier (default: 1.0) */
|
|
245
|
+
scale?: number;
|
|
246
|
+
/** Invert axis (default: false) */
|
|
247
|
+
invert?: boolean;
|
|
248
|
+
/** Sensitivity (for mouse/gyro, default: 1.0) */
|
|
249
|
+
sensitivity?: number;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Physical source for a button
|
|
254
|
+
*
|
|
255
|
+
* Different types of possible sources:
|
|
256
|
+
* - keyboard: A key
|
|
257
|
+
* - gamepad: A button
|
|
258
|
+
* - mouse: Mouse button
|
|
259
|
+
* - touch: Touch button
|
|
260
|
+
*/
|
|
261
|
+
interface ButtonSource {
|
|
262
|
+
/** Unique source ID (0-255, for compression) */
|
|
263
|
+
sourceId: number;
|
|
264
|
+
/** Type of input source */
|
|
265
|
+
type: InputDeviceType;
|
|
266
|
+
/** Key enum (e.g., KeyboardInput.Space) */
|
|
267
|
+
key?: KeyboardInput;
|
|
268
|
+
/** Gamepad index (0-3) */
|
|
269
|
+
gamepadIndex?: number;
|
|
270
|
+
/** Button enum (e.g., GamepadInput.A) */
|
|
271
|
+
button?: GamepadInput;
|
|
272
|
+
/** Mouse button enum (e.g., MouseInput.LeftButton) */
|
|
273
|
+
mouseButton?: MouseInput;
|
|
274
|
+
/** Touch button ID (0-9) */
|
|
275
|
+
touchButton?: number;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Axis binding definition
|
|
280
|
+
*
|
|
281
|
+
* Defines how an abstract axis (e.g., "MoveHorizontal") maps to
|
|
282
|
+
* physical input sources (keyboard, gamepad, etc.)
|
|
283
|
+
*/
|
|
284
|
+
interface AxisBinding {
|
|
285
|
+
/** Unique binding ID (0-255) */
|
|
286
|
+
bindingId: number;
|
|
287
|
+
/** Axis name (e.g., "MoveHorizontal", "CameraX") */
|
|
288
|
+
name: string;
|
|
289
|
+
/** Minimum value (e.g., -1.0) */
|
|
290
|
+
min: number;
|
|
291
|
+
/** Maximum value (e.g., +1.0) */
|
|
292
|
+
max: number;
|
|
293
|
+
/** Default value (e.g., 0.0) */
|
|
294
|
+
defaultValue: number;
|
|
295
|
+
/** Physical sources (values are added together) */
|
|
296
|
+
sources: AxisSource[];
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Button binding definition
|
|
301
|
+
*
|
|
302
|
+
* Defines how an abstract button (e.g., "Jump") maps to
|
|
303
|
+
* physical input sources (keyboard, gamepad, etc.)
|
|
304
|
+
*/
|
|
305
|
+
interface ButtonBinding {
|
|
306
|
+
/** Unique binding ID (0-255) */
|
|
307
|
+
bindingId: number;
|
|
308
|
+
/** Button name (e.g., "Jump", "Attack") */
|
|
309
|
+
name: string;
|
|
310
|
+
/** Default value (e.g., false) */
|
|
311
|
+
defaultValue: boolean;
|
|
312
|
+
/** Physical sources (combined with OR logic) */
|
|
313
|
+
sources: ButtonSource[];
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Load packet for input bindings
|
|
318
|
+
*
|
|
319
|
+
* This JSON packet is sent from server to client via the Load channel
|
|
320
|
+
* to configure which inputs the client should capture and send back.
|
|
321
|
+
*
|
|
322
|
+
* Architecture flow:
|
|
323
|
+
* 1. Server defines bindings (bindingId ↔ name + sources)
|
|
324
|
+
* 2. Server generates this LoadPacket as JSON
|
|
325
|
+
* 3. Client receives the packet and configures input mappings
|
|
326
|
+
* 4. Client captures physical inputs and sends compressed values
|
|
327
|
+
*/
|
|
328
|
+
interface InputBindingLoadPacket {
|
|
329
|
+
/** Packet type identifier */
|
|
330
|
+
type: 'input-binding';
|
|
331
|
+
/** Binding version (for future evolution) */
|
|
332
|
+
version: number;
|
|
333
|
+
/** Axis bindings configuration */
|
|
334
|
+
axes: AxisBinding[];
|
|
335
|
+
/** Button bindings configuration */
|
|
336
|
+
buttons: ButtonBinding[];
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Touch input enumeration
|
|
341
|
+
* Supports multi-touch with up to 10 simultaneous touches
|
|
342
|
+
*
|
|
343
|
+
* Each touch has an identifier (button) and position axes (X, Y)
|
|
344
|
+
*/
|
|
345
|
+
declare enum TouchInput {
|
|
346
|
+
Touch0 = 0,
|
|
347
|
+
Touch1 = 1,
|
|
348
|
+
Touch2 = 2,
|
|
349
|
+
Touch3 = 3,
|
|
350
|
+
Touch4 = 4,
|
|
351
|
+
Touch5 = 5,
|
|
352
|
+
Touch6 = 6,
|
|
353
|
+
Touch7 = 7,
|
|
354
|
+
Touch8 = 8,
|
|
355
|
+
Touch9 = 9,
|
|
356
|
+
Touch0X = 100,
|
|
357
|
+
Touch0Y = 101,
|
|
358
|
+
Touch1X = 102,
|
|
359
|
+
Touch1Y = 103,
|
|
360
|
+
Touch2X = 104,
|
|
361
|
+
Touch2Y = 105,
|
|
362
|
+
Touch3X = 106,
|
|
363
|
+
Touch3Y = 107,
|
|
364
|
+
Touch4X = 108,
|
|
365
|
+
Touch4Y = 109,
|
|
366
|
+
Touch5X = 110,
|
|
367
|
+
Touch5Y = 111,
|
|
368
|
+
Touch6X = 112,
|
|
369
|
+
Touch6Y = 113,
|
|
370
|
+
Touch7X = 114,
|
|
371
|
+
Touch7Y = 115,
|
|
372
|
+
Touch8X = 116,
|
|
373
|
+
Touch8Y = 117,
|
|
374
|
+
Touch9X = 118,
|
|
375
|
+
Touch9Y = 119,
|
|
376
|
+
PinchScale = 200,// Pinch-to-zoom scale
|
|
377
|
+
RotationAngle = 201,// Two-finger rotation
|
|
378
|
+
SwipeVelocityX = 202,// Swipe velocity
|
|
379
|
+
SwipeVelocityY = 203
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Check if the input is a touch identifier (button)
|
|
383
|
+
*/
|
|
384
|
+
declare function isTouchButton(input: TouchInput): boolean;
|
|
385
|
+
/**
|
|
386
|
+
* Check if the input is a position axis
|
|
387
|
+
*/
|
|
388
|
+
declare function isTouchPosition(input: TouchInput): boolean;
|
|
389
|
+
/**
|
|
390
|
+
* Check if the input is a gesture value
|
|
391
|
+
*/
|
|
392
|
+
declare function isTouchGesture(input: TouchInput): boolean;
|
|
393
|
+
/**
|
|
394
|
+
* Get the X position axis for a touch index
|
|
395
|
+
*/
|
|
396
|
+
declare function getTouchXAxis(touchIndex: number): TouchInput | null;
|
|
397
|
+
/**
|
|
398
|
+
* Get the Y position axis for a touch index
|
|
399
|
+
*/
|
|
400
|
+
declare function getTouchYAxis(touchIndex: number): TouchInput | null;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* TV Remote input enumeration
|
|
404
|
+
* Common buttons found on TV remotes and set-top box controllers
|
|
405
|
+
*/
|
|
406
|
+
declare enum TVRemoteInput {
|
|
407
|
+
DPadUp = 0,
|
|
408
|
+
DPadDown = 1,
|
|
409
|
+
DPadLeft = 2,
|
|
410
|
+
DPadRight = 3,
|
|
411
|
+
DPadCenter = 4,// OK/Select button
|
|
412
|
+
Play = 5,
|
|
413
|
+
Pause = 6,
|
|
414
|
+
PlayPause = 7,// Combined play/pause toggle
|
|
415
|
+
Stop = 8,
|
|
416
|
+
Rewind = 9,
|
|
417
|
+
FastForward = 10,
|
|
418
|
+
Previous = 11,// Previous track/channel
|
|
419
|
+
Next = 12,// Next track/channel
|
|
420
|
+
Record = 13,
|
|
421
|
+
VolumeUp = 15,
|
|
422
|
+
VolumeDown = 16,
|
|
423
|
+
Mute = 17,
|
|
424
|
+
ChannelUp = 18,
|
|
425
|
+
ChannelDown = 19,
|
|
426
|
+
Back = 20,
|
|
427
|
+
Home = 21,
|
|
428
|
+
Menu = 22,
|
|
429
|
+
Info = 23,
|
|
430
|
+
Guide = 24,
|
|
431
|
+
Exit = 25,
|
|
432
|
+
Red = 30,
|
|
433
|
+
Green = 31,
|
|
434
|
+
Yellow = 32,
|
|
435
|
+
Blue = 33,
|
|
436
|
+
Digit0 = 40,
|
|
437
|
+
Digit1 = 41,
|
|
438
|
+
Digit2 = 42,
|
|
439
|
+
Digit3 = 43,
|
|
440
|
+
Digit4 = 44,
|
|
441
|
+
Digit5 = 45,
|
|
442
|
+
Digit6 = 46,
|
|
443
|
+
Digit7 = 47,
|
|
444
|
+
Digit8 = 48,
|
|
445
|
+
Digit9 = 49,
|
|
446
|
+
Input = 50,// Switch input source
|
|
447
|
+
Settings = 51,
|
|
448
|
+
Subtitle = 52,
|
|
449
|
+
Audio = 53,// Audio track selection
|
|
450
|
+
Power = 54,
|
|
451
|
+
PointerX = 100,// For remotes with motion control
|
|
452
|
+
PointerY = 101,
|
|
453
|
+
GyroX = 102,// Gyroscope data
|
|
454
|
+
GyroY = 103,
|
|
455
|
+
GyroZ = 104
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Check if the input is a button
|
|
459
|
+
*/
|
|
460
|
+
declare function isTVRemoteButton(input: TVRemoteInput): boolean;
|
|
461
|
+
/**
|
|
462
|
+
* Check if the input is an axis (motion/pointer)
|
|
463
|
+
*/
|
|
464
|
+
declare function isTVRemoteAxis(input: TVRemoteInput): boolean;
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Universal Input System Types
|
|
468
|
+
*
|
|
469
|
+
* Provides type-safe input handling across all device types
|
|
470
|
+
* using numeric enums for performance and compact serialization.
|
|
471
|
+
*/
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Union type of all possible input enums
|
|
475
|
+
*/
|
|
476
|
+
type InputEnum = KeyboardInput | MouseInput | GamepadInput | TouchInput | TVRemoteInput;
|
|
477
|
+
/**
|
|
478
|
+
* Generic input descriptor
|
|
479
|
+
* Identifies any input across all device types
|
|
480
|
+
*/
|
|
481
|
+
interface InputDescriptor {
|
|
482
|
+
device: InputDeviceType;
|
|
483
|
+
input: InputEnum;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Type-safe input descriptors for each device
|
|
487
|
+
*/
|
|
488
|
+
interface KeyboardInputDescriptor {
|
|
489
|
+
device: InputDeviceType.Keyboard;
|
|
490
|
+
input: KeyboardInput;
|
|
491
|
+
}
|
|
492
|
+
interface MouseInputDescriptor {
|
|
493
|
+
device: InputDeviceType.Mouse;
|
|
494
|
+
input: MouseInput;
|
|
495
|
+
}
|
|
496
|
+
interface GamepadInputDescriptor {
|
|
497
|
+
device: InputDeviceType.Gamepad;
|
|
498
|
+
input: GamepadInput;
|
|
499
|
+
}
|
|
500
|
+
interface TouchInputDescriptor {
|
|
501
|
+
device: InputDeviceType.Touch;
|
|
502
|
+
input: TouchInput;
|
|
503
|
+
}
|
|
504
|
+
interface TVRemoteInputDescriptor {
|
|
505
|
+
device: InputDeviceType.TVRemote;
|
|
506
|
+
input: TVRemoteInput;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Discriminated union of all input descriptors
|
|
510
|
+
*/
|
|
511
|
+
type TypedInputDescriptor = KeyboardInputDescriptor | MouseInputDescriptor | GamepadInputDescriptor | TouchInputDescriptor | TVRemoteInputDescriptor;
|
|
512
|
+
/**
|
|
513
|
+
* Helper to create a typed input descriptor
|
|
514
|
+
*/
|
|
515
|
+
declare function createInputDescriptor<T extends InputDeviceType>(device: T, input: T extends InputDeviceType.Keyboard ? KeyboardInput : T extends InputDeviceType.Mouse ? MouseInput : T extends InputDeviceType.Gamepad ? GamepadInput : T extends InputDeviceType.Touch ? TouchInput : T extends InputDeviceType.TVRemote ? TVRemoteInput : never): InputDescriptor;
|
|
516
|
+
/**
|
|
517
|
+
* Check if an input is a button (vs axis)
|
|
518
|
+
*/
|
|
519
|
+
declare function isButton(descriptor: InputDescriptor): boolean;
|
|
520
|
+
/**
|
|
521
|
+
* Check if an input is an axis
|
|
522
|
+
*/
|
|
523
|
+
declare function isAxis(descriptor: InputDescriptor): boolean;
|
|
524
|
+
/**
|
|
525
|
+
* Serialize input descriptor to a compact binary format
|
|
526
|
+
* Format: [device: u8][input: u16] = 3 bytes total
|
|
527
|
+
*/
|
|
528
|
+
declare function serializeInputDescriptor(descriptor: InputDescriptor): Uint8Array;
|
|
529
|
+
/**
|
|
530
|
+
* Deserialize input descriptor from binary format
|
|
531
|
+
*/
|
|
532
|
+
declare function deserializeInputDescriptor(buffer: Uint8Array, offset?: number): InputDescriptor;
|
|
533
|
+
/**
|
|
534
|
+
* Convert input descriptor to human-readable string
|
|
535
|
+
* Format: "DeviceType:InputName"
|
|
536
|
+
*/
|
|
537
|
+
declare function inputDescriptorToString(descriptor: InputDescriptor): string;
|
|
538
|
+
/**
|
|
539
|
+
* Parse string format back to input descriptor
|
|
540
|
+
* Format: "DeviceType:InputName" or "devicetype:inputname"
|
|
541
|
+
*/
|
|
542
|
+
declare function parseInputDescriptor(str: string): InputDescriptor | null;
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Input system interface for querying input state
|
|
546
|
+
*/
|
|
547
|
+
interface IInputSystem {
|
|
548
|
+
/** Query button state (returns boolean) */
|
|
549
|
+
getButton(device: InputDeviceType, input: number): boolean;
|
|
550
|
+
/** Query if button was just pressed this frame (transition false→true) */
|
|
551
|
+
getButtonJustPressed(device: InputDeviceType, input: number): boolean;
|
|
552
|
+
/** Query if button was just released this frame (transition true→false) */
|
|
553
|
+
getButtonJustReleased(device: InputDeviceType, input: number): boolean;
|
|
554
|
+
/** Query axis value (returns number, typically -1 to 1) */
|
|
555
|
+
getAxis(device: InputDeviceType, input: number): number;
|
|
556
|
+
/** Start listening to events */
|
|
557
|
+
start(): void;
|
|
558
|
+
/** Stop listening to events */
|
|
559
|
+
stop(): void;
|
|
560
|
+
/** Reset all states */
|
|
561
|
+
reset(): void;
|
|
562
|
+
/** Cleanup */
|
|
563
|
+
destroy(): void;
|
|
564
|
+
/** Check if listening (optional) */
|
|
565
|
+
isListening?(): boolean;
|
|
566
|
+
/** Poll transient states - called once per frame */
|
|
567
|
+
poll?(): void;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* 2D vector with immutable and in-place operations
|
|
572
|
+
*/
|
|
573
|
+
declare class Vector2 {
|
|
574
|
+
x: number;
|
|
575
|
+
y: number;
|
|
576
|
+
constructor(x?: number, y?: number);
|
|
577
|
+
static zero(): Vector2;
|
|
578
|
+
static one(): Vector2;
|
|
579
|
+
static up(): Vector2;
|
|
580
|
+
static down(): Vector2;
|
|
581
|
+
static left(): Vector2;
|
|
582
|
+
static right(): Vector2;
|
|
583
|
+
add(v: Vector2): Vector2;
|
|
584
|
+
subtract(v: Vector2): Vector2;
|
|
585
|
+
multiply(scalar: number): Vector2;
|
|
586
|
+
divide(scalar: number): Vector2;
|
|
587
|
+
length(): number;
|
|
588
|
+
lengthSquared(): number;
|
|
589
|
+
normalize(): Vector2;
|
|
590
|
+
distance(v: Vector2): number;
|
|
591
|
+
distanceSquared(v: Vector2): number;
|
|
592
|
+
dot(v: Vector2): number;
|
|
593
|
+
cross(v: Vector2): number;
|
|
594
|
+
angle(): number;
|
|
595
|
+
angleTo(v: Vector2): number;
|
|
596
|
+
rotate(angle: number): Vector2;
|
|
597
|
+
lerp(v: Vector2, t: number): Vector2;
|
|
598
|
+
clone(): Vector2;
|
|
599
|
+
equals(v: Vector2): boolean;
|
|
600
|
+
toString(): string;
|
|
601
|
+
toArray(): [number, number];
|
|
602
|
+
set(x: number, y: number): this;
|
|
603
|
+
copy(v: Vector2): this;
|
|
604
|
+
addInPlace(v: Vector2): this;
|
|
605
|
+
subtractInPlace(v: Vector2): this;
|
|
606
|
+
multiplyInPlace(scalar: number): this;
|
|
607
|
+
divideInPlace(scalar: number): this;
|
|
608
|
+
normalizeInPlace(): this;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* 3D vector with immutable and in-place operations
|
|
613
|
+
*/
|
|
614
|
+
declare class Vector3 {
|
|
615
|
+
x: number;
|
|
616
|
+
y: number;
|
|
617
|
+
z: number;
|
|
618
|
+
constructor(x?: number, y?: number, z?: number);
|
|
619
|
+
static zero(): Vector3;
|
|
620
|
+
static one(): Vector3;
|
|
621
|
+
static up(): Vector3;
|
|
622
|
+
static down(): Vector3;
|
|
623
|
+
static left(): Vector3;
|
|
624
|
+
static right(): Vector3;
|
|
625
|
+
static forward(): Vector3;
|
|
626
|
+
static back(): Vector3;
|
|
627
|
+
add(v: Vector3): Vector3;
|
|
628
|
+
subtract(v: Vector3): Vector3;
|
|
629
|
+
multiply(scalar: number): Vector3;
|
|
630
|
+
divide(scalar: number): Vector3;
|
|
631
|
+
length(): number;
|
|
632
|
+
lengthSquared(): number;
|
|
633
|
+
normalize(): Vector3;
|
|
634
|
+
distance(v: Vector3): number;
|
|
635
|
+
distanceSquared(v: Vector3): number;
|
|
636
|
+
dot(v: Vector3): number;
|
|
637
|
+
cross(v: Vector3): Vector3;
|
|
638
|
+
lerp(v: Vector3, t: number): Vector3;
|
|
639
|
+
clone(): Vector3;
|
|
640
|
+
equals(v: Vector3): boolean;
|
|
641
|
+
toString(): string;
|
|
642
|
+
toArray(): [number, number, number];
|
|
643
|
+
set(x: number, y: number, z: number): this;
|
|
644
|
+
copy(v: Vector3): this;
|
|
645
|
+
addInPlace(v: Vector3): this;
|
|
646
|
+
subtractInPlace(v: Vector3): this;
|
|
647
|
+
multiplyInPlace(scalar: number): this;
|
|
648
|
+
divideInPlace(scalar: number): this;
|
|
649
|
+
normalizeInPlace(): this;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* RGBA color (0-255 per channel)
|
|
654
|
+
*/
|
|
655
|
+
interface RGBColor$1 {
|
|
656
|
+
/** Red (0-255) */
|
|
657
|
+
r: number;
|
|
658
|
+
/** Green (0-255) */
|
|
659
|
+
g: number;
|
|
660
|
+
/** Blue (0-255) */
|
|
661
|
+
b: number;
|
|
662
|
+
/** Alpha (0-255, 0=transparent, 255=opaque) */
|
|
663
|
+
a: number;
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Rendered cell with palette indices for optimal caching
|
|
667
|
+
*/
|
|
668
|
+
interface RenderedCell {
|
|
669
|
+
/** Character */
|
|
670
|
+
char: string;
|
|
671
|
+
/** Foreground color index (0-255) */
|
|
672
|
+
fgColorIndex: number;
|
|
673
|
+
/** Background color index (0-255) */
|
|
674
|
+
bgColorIndex: number;
|
|
675
|
+
/** Foreground emission (0-255, 0=none) */
|
|
676
|
+
fgEmission: number;
|
|
677
|
+
/** Background emission (0-255, 0=none) */
|
|
678
|
+
bgEmission: number;
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Display render state with cells and color palette
|
|
682
|
+
*/
|
|
683
|
+
interface RenderState {
|
|
684
|
+
/** Width in cells */
|
|
685
|
+
width: number;
|
|
686
|
+
/** Height in cells */
|
|
687
|
+
height: number;
|
|
688
|
+
/** Cell array (length = width × height) */
|
|
689
|
+
cells: RenderedCell[];
|
|
690
|
+
/** Color palette (256 colors) */
|
|
691
|
+
palette: RGBColor$1[];
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Complete user render state
|
|
695
|
+
*/
|
|
696
|
+
interface UserRenderState {
|
|
697
|
+
/** User ID */
|
|
698
|
+
userId: string;
|
|
699
|
+
/** User name */
|
|
700
|
+
userName: string;
|
|
701
|
+
/** Current tick number */
|
|
702
|
+
tick: number;
|
|
703
|
+
/** Render states for each display */
|
|
704
|
+
displays: RenderState[];
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* RGB color for palette configuration
|
|
709
|
+
*/
|
|
710
|
+
interface RGBColor {
|
|
711
|
+
r: number;
|
|
712
|
+
g: number;
|
|
713
|
+
b: number;
|
|
714
|
+
a: number;
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Renderer interface - Contract for all rendering implementations
|
|
718
|
+
*
|
|
719
|
+
* This is a universal interface that works in any environment (browser, Node.js, native).
|
|
720
|
+
* Canvas element is typed as `unknown` to avoid DOM dependencies in server code.
|
|
721
|
+
* Client code should cast to `HTMLCanvasElement` when needed.
|
|
722
|
+
*
|
|
723
|
+
* @example
|
|
724
|
+
* ```ts
|
|
725
|
+
* class TerminalGL implements IRenderer {
|
|
726
|
+
* renderDisplayData(data: RenderState): void { }
|
|
727
|
+
* resize(cols: number, rows: number): void { }
|
|
728
|
+
* destroy(): void { }
|
|
729
|
+
* getCols(): number { return this.cols; }
|
|
730
|
+
* getRows(): number { return this.rows; }
|
|
731
|
+
* isReady(): boolean { return this.ready; }
|
|
732
|
+
* getCanvas(): unknown { return this.canvas; }
|
|
733
|
+
* setBitmapFont(font, cw, ch, cellW, cellH): void { }
|
|
734
|
+
* setPalette(palette): void { }
|
|
735
|
+
* }
|
|
736
|
+
* ```
|
|
737
|
+
*/
|
|
738
|
+
interface IRenderer {
|
|
739
|
+
/**
|
|
740
|
+
* Render display data to screen (called every frame)
|
|
741
|
+
* @param data - Cell data with palette indices
|
|
742
|
+
*/
|
|
743
|
+
renderDisplayData(data: RenderState): void;
|
|
744
|
+
/**
|
|
745
|
+
* Resize renderer dimensions
|
|
746
|
+
* @param cols - Width in columns
|
|
747
|
+
* @param rows - Height in rows
|
|
748
|
+
*/
|
|
749
|
+
resize(cols: number, rows: number): void;
|
|
750
|
+
/** Clear display (optional) */
|
|
751
|
+
clear?(): void;
|
|
752
|
+
/** Cleanup resources */
|
|
753
|
+
destroy(): void;
|
|
754
|
+
/** Get width in columns */
|
|
755
|
+
getCols(): number;
|
|
756
|
+
/** Get height in rows */
|
|
757
|
+
getRows(): number;
|
|
758
|
+
/** Check if ready to render */
|
|
759
|
+
isReady(): boolean;
|
|
760
|
+
/**
|
|
761
|
+
* Get rendering offsets (for renderers that center content within canvas)
|
|
762
|
+
* Optional method - only implement if renderer centers content
|
|
763
|
+
* @returns Offset in pixels from canvas origin to rendered content
|
|
764
|
+
*/
|
|
765
|
+
getOffsets?(): {
|
|
766
|
+
offsetX: number;
|
|
767
|
+
offsetY: number;
|
|
768
|
+
} | undefined;
|
|
769
|
+
/**
|
|
770
|
+
* Get canvas element (typed as unknown to avoid DOM dependencies)
|
|
771
|
+
* Cast to HTMLCanvasElement in browser environments
|
|
772
|
+
* @returns Canvas element or null if not available
|
|
773
|
+
*/
|
|
774
|
+
getCanvas(): unknown;
|
|
775
|
+
/**
|
|
776
|
+
* Set bitmap font for character rendering
|
|
777
|
+
* @param font - Map of character codes to bitmap data (Uint8Array per character)
|
|
778
|
+
* @param charWidth - Character width in pixels
|
|
779
|
+
* @param charHeight - Character height in pixels
|
|
780
|
+
* @param cellWidth - Cell width in pixels (includes spacing)
|
|
781
|
+
* @param cellHeight - Cell height in pixels (includes spacing)
|
|
782
|
+
*/
|
|
783
|
+
setBitmapFont(font: Map<number, Uint8Array>, charWidth: number, charHeight: number, cellWidth: number, cellHeight: number): void;
|
|
784
|
+
/**
|
|
785
|
+
* Set color palette
|
|
786
|
+
* @param palette - Array of 256 RGB colors
|
|
787
|
+
*/
|
|
788
|
+
setPalette(palette: RGBColor[]): void;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Color palette interface
|
|
793
|
+
*
|
|
794
|
+
* @example
|
|
795
|
+
* ```ts
|
|
796
|
+
* const palette = new VGAPalette();
|
|
797
|
+
* const white = palette.getColor(15);
|
|
798
|
+
* ```
|
|
799
|
+
*/
|
|
800
|
+
interface IColorPalette {
|
|
801
|
+
/** Get color by index (returns CSS color string) */
|
|
802
|
+
getColor(index: number): string;
|
|
803
|
+
/** Set color at index */
|
|
804
|
+
setColor(index: number, color: string): void;
|
|
805
|
+
/** Get palette size */
|
|
806
|
+
getSize(): number;
|
|
807
|
+
/** Reset to default colors (optional) */
|
|
808
|
+
reset?(): void;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
/**
|
|
812
|
+
* Network client interface for client-to-server communication
|
|
813
|
+
* Implementations: Socket.IO, WebRTC, WebSocket, etc.
|
|
814
|
+
*/
|
|
815
|
+
/** Event handler callback */
|
|
816
|
+
type NetworkEventHandler<T = any> = (data: T) => void;
|
|
817
|
+
/** Connection state */
|
|
818
|
+
declare enum NetworkState {
|
|
819
|
+
Disconnected = 0,
|
|
820
|
+
Connecting = 1,
|
|
821
|
+
Connected = 2,
|
|
822
|
+
Reconnecting = 3,
|
|
823
|
+
Error = 4
|
|
824
|
+
}
|
|
825
|
+
/** Client connection options */
|
|
826
|
+
interface NetworkClientOptions {
|
|
827
|
+
/** Server URL */
|
|
828
|
+
url: string;
|
|
829
|
+
/** Auto-reconnect on disconnect */
|
|
830
|
+
autoReconnect?: boolean;
|
|
831
|
+
/** Reconnect delay (ms) */
|
|
832
|
+
reconnectDelay?: number;
|
|
833
|
+
/** Max reconnect attempts (0=infinite) */
|
|
834
|
+
maxReconnectAttempts?: number;
|
|
835
|
+
/** Connection timeout (ms) */
|
|
836
|
+
timeout?: number;
|
|
837
|
+
/** Auth data */
|
|
838
|
+
auth?: Record<string, any>;
|
|
839
|
+
/** Debug logging */
|
|
840
|
+
debug?: boolean;
|
|
841
|
+
}
|
|
842
|
+
/** Network client interface */
|
|
843
|
+
interface INetworkClient {
|
|
844
|
+
/** Current state */
|
|
845
|
+
readonly state: NetworkState;
|
|
846
|
+
/** Check if connected */
|
|
847
|
+
isConnected(): boolean;
|
|
848
|
+
/** Connect to server */
|
|
849
|
+
connect(): Promise<void>;
|
|
850
|
+
/** Disconnect from server */
|
|
851
|
+
disconnect(): void;
|
|
852
|
+
/** Send event to server */
|
|
853
|
+
send(event: string, data: any): void;
|
|
854
|
+
/** Listen for server events */
|
|
855
|
+
on<T = any>(event: string, handler: NetworkEventHandler<T>): void;
|
|
856
|
+
/** Remove event listener */
|
|
857
|
+
off<T = any>(event: string, handler: NetworkEventHandler<T>): void;
|
|
858
|
+
/** Remove all listeners for event */
|
|
859
|
+
removeAllListeners(event?: string): void;
|
|
860
|
+
/** Send and wait for response */
|
|
861
|
+
request<T = any>(event: string, data: any, timeout?: number): Promise<T>;
|
|
862
|
+
/** Get ping to server (ms) */
|
|
863
|
+
getPing(): number;
|
|
864
|
+
/** Cleanup */
|
|
865
|
+
destroy(): void;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
* Network server interface for server-side communication
|
|
870
|
+
* Implementations: Socket.IO, WebRTC, WebSocket, etc.
|
|
871
|
+
*/
|
|
872
|
+
/** Server event handler */
|
|
873
|
+
type ServerEventHandler<T = any> = (clientId: string, data: T) => void;
|
|
874
|
+
/** Connection handler */
|
|
875
|
+
type ConnectionHandler = (clientId: string) => void;
|
|
876
|
+
/** Disconnection handler */
|
|
877
|
+
type DisconnectionHandler = (clientId: string, reason: string) => void;
|
|
878
|
+
/** Server options */
|
|
879
|
+
interface NetworkServerOptions {
|
|
880
|
+
/** Port */
|
|
881
|
+
port: number;
|
|
882
|
+
/** Host (default: "0.0.0.0") */
|
|
883
|
+
host?: string;
|
|
884
|
+
/** CORS config */
|
|
885
|
+
cors?: {
|
|
886
|
+
origin: string | string[];
|
|
887
|
+
credentials?: boolean;
|
|
888
|
+
};
|
|
889
|
+
/** Max connections */
|
|
890
|
+
maxConnections?: number;
|
|
891
|
+
/** Ping interval (ms) */
|
|
892
|
+
pingInterval?: number;
|
|
893
|
+
/** Ping timeout (ms) */
|
|
894
|
+
pingTimeout?: number;
|
|
895
|
+
/** Debug logging */
|
|
896
|
+
debug?: boolean;
|
|
897
|
+
}
|
|
898
|
+
/** Client info */
|
|
899
|
+
interface ClientInfo {
|
|
900
|
+
/** Client ID */
|
|
901
|
+
id: string;
|
|
902
|
+
/** Connection timestamp */
|
|
903
|
+
connectedAt: number;
|
|
904
|
+
/** IP address */
|
|
905
|
+
address: string;
|
|
906
|
+
/** Custom data */
|
|
907
|
+
data: Record<string, any>;
|
|
908
|
+
}
|
|
909
|
+
/** Network server interface */
|
|
910
|
+
interface INetworkServer {
|
|
911
|
+
/** Check if running */
|
|
912
|
+
isRunning(): boolean;
|
|
913
|
+
/** Start server */
|
|
914
|
+
start(): Promise<void>;
|
|
915
|
+
/** Stop server */
|
|
916
|
+
stop(): Promise<void>;
|
|
917
|
+
/** Get connected client IDs */
|
|
918
|
+
getClients(): string[];
|
|
919
|
+
/** Get client info */
|
|
920
|
+
getClientInfo(clientId: string): ClientInfo | null;
|
|
921
|
+
/** Send to specific client */
|
|
922
|
+
sendToClient(clientId: string, event: string, data: any): void;
|
|
923
|
+
/** Send volatile (can be dropped if congested) */
|
|
924
|
+
sendToClientVolatile?(clientId: string, event: string, data: any): void;
|
|
925
|
+
/** Broadcast to all clients */
|
|
926
|
+
broadcast(event: string, data: any): void;
|
|
927
|
+
/** Broadcast volatile (can be dropped) */
|
|
928
|
+
broadcastVolatile?(event: string, data: any): void;
|
|
929
|
+
/** Broadcast except one client */
|
|
930
|
+
broadcastExcept(excludeClientId: string, event: string, data: any): void;
|
|
931
|
+
/** Send to room */
|
|
932
|
+
sendToRoom(room: string, event: string, data: any): void;
|
|
933
|
+
/** Add client to room */
|
|
934
|
+
joinRoom(clientId: string, room: string): void;
|
|
935
|
+
/** Remove client from room */
|
|
936
|
+
leaveRoom(clientId: string, room: string): void;
|
|
937
|
+
/** Get room clients */
|
|
938
|
+
getRoomClients(room: string): string[];
|
|
939
|
+
/** Disconnect client */
|
|
940
|
+
disconnectClient(clientId: string, reason?: string): void;
|
|
941
|
+
/** Listen for events */
|
|
942
|
+
on<T = any>(event: string, handler: ServerEventHandler<T>): void;
|
|
943
|
+
/** Listen for connections */
|
|
944
|
+
onConnect(handler: ConnectionHandler): void;
|
|
945
|
+
/** Listen for disconnections */
|
|
946
|
+
onDisconnect(handler: DisconnectionHandler): void;
|
|
947
|
+
/** Remove listener */
|
|
948
|
+
off<T = any>(event: string, handler: ServerEventHandler<T>): void;
|
|
949
|
+
/** Set client custom data */
|
|
950
|
+
setClientData(clientId: string, key: string, value: any): void;
|
|
951
|
+
/** Get client custom data */
|
|
952
|
+
getClientData(clientId: string, key: string): any;
|
|
953
|
+
/** Get server stats */
|
|
954
|
+
getStats(): {
|
|
955
|
+
connectedClients: number;
|
|
956
|
+
totalConnections: number;
|
|
957
|
+
uptime: number;
|
|
958
|
+
};
|
|
959
|
+
/** Cleanup */
|
|
960
|
+
destroy(): Promise<void>;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
* Network message types for UTSP protocol
|
|
965
|
+
*/
|
|
966
|
+
/** Base message */
|
|
967
|
+
interface NetworkMessage {
|
|
968
|
+
/** Message type */
|
|
969
|
+
type: string;
|
|
970
|
+
/** Timestamp (client send time) */
|
|
971
|
+
timestamp: number;
|
|
972
|
+
/** Sequence number (optional) */
|
|
973
|
+
seq?: number;
|
|
974
|
+
}
|
|
975
|
+
/** Client input (client→server) */
|
|
976
|
+
interface InputMessage extends NetworkMessage {
|
|
977
|
+
type: 'input';
|
|
978
|
+
data: Uint8Array;
|
|
979
|
+
}
|
|
980
|
+
/** Server update (server→client) */
|
|
981
|
+
interface UpdateMessage extends NetworkMessage {
|
|
982
|
+
type: 'update';
|
|
983
|
+
data: Uint8Array;
|
|
984
|
+
tick: number;
|
|
985
|
+
}
|
|
986
|
+
/** Asset load (server→client) */
|
|
987
|
+
interface LoadMessage extends NetworkMessage {
|
|
988
|
+
type: 'load';
|
|
989
|
+
data: Uint8Array;
|
|
990
|
+
}
|
|
991
|
+
/** Join game (client→server) */
|
|
992
|
+
interface JoinMessage extends NetworkMessage {
|
|
993
|
+
type: 'join';
|
|
994
|
+
username: string;
|
|
995
|
+
roomId?: string;
|
|
996
|
+
token?: string;
|
|
997
|
+
}
|
|
998
|
+
/** Join response (server→client) */
|
|
999
|
+
interface JoinResponseMessage extends NetworkMessage {
|
|
1000
|
+
type: 'join_response';
|
|
1001
|
+
success: boolean;
|
|
1002
|
+
userId?: string;
|
|
1003
|
+
roomId?: string;
|
|
1004
|
+
error?: string;
|
|
1005
|
+
}
|
|
1006
|
+
/** Leave game (client→server) */
|
|
1007
|
+
interface LeaveMessage extends NetworkMessage {
|
|
1008
|
+
type: 'leave';
|
|
1009
|
+
}
|
|
1010
|
+
/** Ping (latency measurement) */
|
|
1011
|
+
interface PingMessage extends NetworkMessage {
|
|
1012
|
+
type: 'ping';
|
|
1013
|
+
}
|
|
1014
|
+
/** Pong (ping response) */
|
|
1015
|
+
interface PongMessage extends NetworkMessage {
|
|
1016
|
+
type: 'pong';
|
|
1017
|
+
pingTime: number;
|
|
1018
|
+
}
|
|
1019
|
+
/** Error message */
|
|
1020
|
+
interface ErrorMessage extends NetworkMessage {
|
|
1021
|
+
type: 'error';
|
|
1022
|
+
code: string;
|
|
1023
|
+
message: string;
|
|
1024
|
+
}
|
|
1025
|
+
/** Chat message (example custom type) */
|
|
1026
|
+
interface ChatMessage extends NetworkMessage {
|
|
1027
|
+
type: 'chat';
|
|
1028
|
+
text: string;
|
|
1029
|
+
userId: string;
|
|
1030
|
+
username: string;
|
|
1031
|
+
}
|
|
1032
|
+
/** Union of all message types */
|
|
1033
|
+
type AnyNetworkMessage = InputMessage | UpdateMessage | LoadMessage | JoinMessage | JoinResponseMessage | LeaveMessage | PingMessage | PongMessage | ErrorMessage | ChatMessage;
|
|
1034
|
+
/** Message type literals */
|
|
1035
|
+
type MessageType = AnyNetworkMessage['type'];
|
|
1036
|
+
|
|
1037
|
+
/**
|
|
1038
|
+
* Application lifecycle interface for games, dashboards, signage, etc.
|
|
1039
|
+
* Supports single-user (local) and multi-user (networked) scenarios.
|
|
1040
|
+
*
|
|
1041
|
+
* @template TCore - Core type (typically Core)
|
|
1042
|
+
* @template TUser - User type (typically User)
|
|
1043
|
+
* @template TRuntime - Runtime type (optional)
|
|
1044
|
+
*/
|
|
1045
|
+
interface IApplication<TCore = any, TUser = any, TRuntime = unknown> {
|
|
1046
|
+
/**
|
|
1047
|
+
* Initialize application (called once at startup, before users)
|
|
1048
|
+
* @param core - Core instance
|
|
1049
|
+
* @param runtime - Runtime instance (optional)
|
|
1050
|
+
*/
|
|
1051
|
+
init(core: TCore, runtime?: TRuntime): void;
|
|
1052
|
+
/**
|
|
1053
|
+
* Update global logic (called every frame, runs once)
|
|
1054
|
+
* @param core - Core instance
|
|
1055
|
+
* @param deltaTime - Time since last update (seconds)
|
|
1056
|
+
*/
|
|
1057
|
+
update(core: TCore, deltaTime: number): void;
|
|
1058
|
+
/**
|
|
1059
|
+
* Initialize new user (called when user connects/joins)
|
|
1060
|
+
* @param core - Core instance
|
|
1061
|
+
* @param user - User instance
|
|
1062
|
+
* @param metadata - Optional user metadata (username, preferences, etc.)
|
|
1063
|
+
*/
|
|
1064
|
+
initUser(core: TCore, user: TUser, metadata?: UserMetadata): void;
|
|
1065
|
+
/**
|
|
1066
|
+
* Update user-specific logic (called every frame per user)
|
|
1067
|
+
* @param core - Core instance
|
|
1068
|
+
* @param user - User instance
|
|
1069
|
+
* @param deltaTime - Time since last update (seconds)
|
|
1070
|
+
*/
|
|
1071
|
+
updateUser(core: TCore, user: TUser, deltaTime: number): void;
|
|
1072
|
+
/**
|
|
1073
|
+
* Cleanup when user disconnects (optional)
|
|
1074
|
+
* @param core - Core instance
|
|
1075
|
+
* @param user - User instance
|
|
1076
|
+
* @param reason - Disconnect reason (optional)
|
|
1077
|
+
*/
|
|
1078
|
+
destroyUser?(core: TCore, user: TUser, reason?: string): void;
|
|
1079
|
+
/**
|
|
1080
|
+
* Cleanup when application shuts down (optional)
|
|
1081
|
+
*/
|
|
1082
|
+
destroy?(): void;
|
|
1083
|
+
/**
|
|
1084
|
+
* Commit changes after all updates (optional)
|
|
1085
|
+
* Called after update() and all updateUser() to trigger render/broadcast.
|
|
1086
|
+
* @param core - Core instance
|
|
1087
|
+
* @param deltaTime - Time since last update (seconds)
|
|
1088
|
+
*/
|
|
1089
|
+
onCommit?(core: TCore, deltaTime: number): void;
|
|
1090
|
+
/**
|
|
1091
|
+
* Handle errors during execution (optional)
|
|
1092
|
+
* @param core - Core instance
|
|
1093
|
+
* @param error - The error that occurred
|
|
1094
|
+
* @param context - Error context (phase, user, timestamp)
|
|
1095
|
+
* @returns true to continue, false to stop runtime
|
|
1096
|
+
*/
|
|
1097
|
+
onError?(core: TCore, error: Error, context: {
|
|
1098
|
+
phase: 'init' | 'update' | 'initUser' | 'updateUser' | 'destroyUser' | 'destroy';
|
|
1099
|
+
user?: TUser;
|
|
1100
|
+
timestamp: number;
|
|
1101
|
+
}): boolean;
|
|
1102
|
+
}
|
|
1103
|
+
/**
|
|
1104
|
+
* User metadata for initUser
|
|
1105
|
+
*/
|
|
1106
|
+
interface UserMetadata {
|
|
1107
|
+
/** Display name */
|
|
1108
|
+
username?: string;
|
|
1109
|
+
/** Avatar/skin ID */
|
|
1110
|
+
avatar?: string | number;
|
|
1111
|
+
/** Team/faction */
|
|
1112
|
+
team?: string | number;
|
|
1113
|
+
/** Color preference */
|
|
1114
|
+
color?: number;
|
|
1115
|
+
/** Theme preference */
|
|
1116
|
+
theme?: string;
|
|
1117
|
+
/** Auth token */
|
|
1118
|
+
token?: string;
|
|
1119
|
+
/** Custom data */
|
|
1120
|
+
[key: string]: unknown;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
export { GamepadInput, InputDeviceType, KeyboardInput, MouseInput, NetworkState, TVRemoteInput, TouchInput, Vector2, Vector3, createInputDescriptor, deserializeInputDescriptor, gamepadAxisIndexToInput, gamepadButtonIndexToInput, getTouchXAxis, getTouchYAxis, inputDescriptorToString, isAxis, isButton, isGamepadAxis, isGamepadButton, isMouseAxis, isMouseButton, isTVRemoteAxis, isTVRemoteButton, isTouchButton, isTouchGesture, isTouchPosition, keyCodeToKeyboardInput, keyboardInputToKeyCode, parseInputDescriptor, serializeInputDescriptor };
|
|
1124
|
+
export type { AnyNetworkMessage, AxisBinding, AxisSource, ButtonBinding, ButtonSource, ChatMessage, ClientInfo, ConnectionHandler, DisconnectionHandler, ErrorMessage, GamepadInputDescriptor, IApplication, IColorPalette, IInputSystem, INetworkClient, INetworkServer, IRenderer, InputBindingLoadPacket, InputDescriptor, InputEnum, InputMessage, JoinMessage, JoinResponseMessage, KeyboardInputDescriptor, LeaveMessage, LoadMessage, MessageType, MouseInputDescriptor, NetworkClientOptions, NetworkEventHandler, NetworkMessage, NetworkServerOptions, PingMessage, PongMessage, RGBColor, RenderState, RenderedCell, ServerEventHandler, TVRemoteInputDescriptor, TouchInputDescriptor, TypedInputDescriptor, UpdateMessage, UserMetadata, UserRenderState };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var X=Object.defineProperty;var C=(e,r,h)=>r in e?X(e,r,{enumerable:!0,configurable:!0,writable:!0,value:h}):e[r]=h;var n=(e,r)=>X(e,"name",{value:r,configurable:!0});var w=(e,r,h)=>(C(e,typeof r!="symbol"?r+"":r,h),h);var P=(f=>(f[f.Keyboard=0]="Keyboard",f[f.Mouse=1]="Mouse",f[f.Gamepad=2]="Gamepad",f[f.Touch=3]="Touch",f[f.TVRemote=4]="TVRemote",f[f.TextInput=5]="TextInput",f))(P||{});var z=(i=>(i[i.KeyA=0]="KeyA",i[i.KeyB=1]="KeyB",i[i.KeyC=2]="KeyC",i[i.KeyD=3]="KeyD",i[i.KeyE=4]="KeyE",i[i.KeyF=5]="KeyF",i[i.KeyG=6]="KeyG",i[i.KeyH=7]="KeyH",i[i.KeyI=8]="KeyI",i[i.KeyJ=9]="KeyJ",i[i.KeyK=10]="KeyK",i[i.KeyL=11]="KeyL",i[i.KeyM=12]="KeyM",i[i.KeyN=13]="KeyN",i[i.KeyO=14]="KeyO",i[i.KeyP=15]="KeyP",i[i.KeyQ=16]="KeyQ",i[i.KeyR=17]="KeyR",i[i.KeyS=18]="KeyS",i[i.KeyT=19]="KeyT",i[i.KeyU=20]="KeyU",i[i.KeyV=21]="KeyV",i[i.KeyW=22]="KeyW",i[i.KeyX=23]="KeyX",i[i.KeyY=24]="KeyY",i[i.KeyZ=25]="KeyZ",i[i.Digit0=26]="Digit0",i[i.Digit1=27]="Digit1",i[i.Digit2=28]="Digit2",i[i.Digit3=29]="Digit3",i[i.Digit4=30]="Digit4",i[i.Digit5=31]="Digit5",i[i.Digit6=32]="Digit6",i[i.Digit7=33]="Digit7",i[i.Digit8=34]="Digit8",i[i.Digit9=35]="Digit9",i[i.ArrowUp=36]="ArrowUp",i[i.ArrowDown=37]="ArrowDown",i[i.ArrowLeft=38]="ArrowLeft",i[i.ArrowRight=39]="ArrowRight",i[i.Space=40]="Space",i[i.Enter=41]="Enter",i[i.Escape=42]="Escape",i[i.Backspace=43]="Backspace",i[i.Tab=44]="Tab",i[i.ShiftLeft=45]="ShiftLeft",i[i.ShiftRight=46]="ShiftRight",i[i.ControlLeft=47]="ControlLeft",i[i.ControlRight=48]="ControlRight",i[i.AltLeft=49]="AltLeft",i[i.AltRight=50]="AltRight",i[i.MetaLeft=51]="MetaLeft",i[i.MetaRight=52]="MetaRight",i[i.CapsLock=53]="CapsLock",i[i.Delete=54]="Delete",i[i.Insert=55]="Insert",i[i.Home=56]="Home",i[i.End=57]="End",i[i.PageUp=58]="PageUp",i[i.PageDown=59]="PageDown",i[i.F1=60]="F1",i[i.F2=61]="F2",i[i.F3=62]="F3",i[i.F4=63]="F4",i[i.F5=64]="F5",i[i.F6=65]="F6",i[i.F7=66]="F7",i[i.F8=67]="F8",i[i.F9=68]="F9",i[i.F10=69]="F10",i[i.F11=70]="F11",i[i.F12=71]="F12",i[i.Minus=72]="Minus",i[i.Equal=73]="Equal",i[i.BracketLeft=74]="BracketLeft",i[i.BracketRight=75]="BracketRight",i[i.Backslash=76]="Backslash",i[i.Semicolon=77]="Semicolon",i[i.Quote=78]="Quote",i[i.Comma=79]="Comma",i[i.Period=80]="Period",i[i.Slash=81]="Slash",i[i.Backquote=82]="Backquote",i[i.Numpad0=91]="Numpad0",i[i.Numpad1=92]="Numpad1",i[i.Numpad2=93]="Numpad2",i[i.Numpad3=94]="Numpad3",i[i.Numpad4=95]="Numpad4",i[i.Numpad5=96]="Numpad5",i[i.Numpad6=97]="Numpad6",i[i.Numpad7=98]="Numpad7",i[i.Numpad8=99]="Numpad8",i[i.Numpad9=100]="Numpad9",i[i.NumpadAdd=101]="NumpadAdd",i[i.NumpadSubtract=102]="NumpadSubtract",i[i.NumpadMultiply=103]="NumpadMultiply",i[i.NumpadDivide=104]="NumpadDivide",i[i.NumpadDecimal=105]="NumpadDecimal",i[i.NumpadEnter=106]="NumpadEnter",i[i.NumLock=107]="NumLock",i[i.PrintScreen=111]="PrintScreen",i[i.ScrollLock=112]="ScrollLock",i[i.Pause=113]="Pause",i[i.ContextMenu=114]="ContextMenu",i))(z||{});function v(e){let r=z[e];return r!==void 0?r:null}n(v,"keyCodeToKeyboardInput");function M(e){return z[e]}n(M,"keyboardInputToKeyCode");var A=(x=>(x[x.LeftButton=0]="LeftButton",x[x.MiddleButton=1]="MiddleButton",x[x.RightButton=2]="RightButton",x[x.Button4=3]="Button4",x[x.Button5=4]="Button5",x[x.PositionX=100]="PositionX",x[x.PositionY=101]="PositionY",x[x.DeltaX=102]="DeltaX",x[x.DeltaY=103]="DeltaY",x[x.WheelDeltaY=104]="WheelDeltaY",x[x.WheelDeltaX=105]="WheelDeltaX",x))(A||{});function N(e){return e<100}n(N,"isMouseButton");function a(e){return e>=100}n(a,"isMouseAxis");var B=(c=>(c[c.ButtonA=0]="ButtonA",c[c.ButtonB=1]="ButtonB",c[c.ButtonX=2]="ButtonX",c[c.ButtonY=3]="ButtonY",c[c.LeftShoulder=4]="LeftShoulder",c[c.RightShoulder=5]="RightShoulder",c[c.LeftTrigger=6]="LeftTrigger",c[c.RightTrigger=7]="RightTrigger",c[c.Select=8]="Select",c[c.Start=9]="Start",c[c.LeftStick=10]="LeftStick",c[c.RightStick=11]="RightStick",c[c.DPadUp=12]="DPadUp",c[c.DPadDown=13]="DPadDown",c[c.DPadLeft=14]="DPadLeft",c[c.DPadRight=15]="DPadRight",c[c.Home=16]="Home",c[c.Touchpad=17]="Touchpad",c[c.LeftStickX=100]="LeftStickX",c[c.LeftStickY=101]="LeftStickY",c[c.RightStickX=102]="RightStickX",c[c.RightStickY=103]="RightStickY",c[c.LeftTriggerAxis=104]="LeftTriggerAxis",c[c.RightTriggerAxis=105]="RightTriggerAxis",c))(B||{});function F(e){return e<100}n(F,"isGamepadButton");function u(e){return e>=100}n(u,"isGamepadAxis");function q(e){return e>=0&&e<=19?e:null}n(q,"gamepadButtonIndexToInput");function U(e){return{0:100,1:101,2:102,3:103}[e]??null}n(U,"gamepadAxisIndexToInput");var S=(s=>(s[s.Touch0=0]="Touch0",s[s.Touch1=1]="Touch1",s[s.Touch2=2]="Touch2",s[s.Touch3=3]="Touch3",s[s.Touch4=4]="Touch4",s[s.Touch5=5]="Touch5",s[s.Touch6=6]="Touch6",s[s.Touch7=7]="Touch7",s[s.Touch8=8]="Touch8",s[s.Touch9=9]="Touch9",s[s.Touch0X=100]="Touch0X",s[s.Touch0Y=101]="Touch0Y",s[s.Touch1X=102]="Touch1X",s[s.Touch1Y=103]="Touch1Y",s[s.Touch2X=104]="Touch2X",s[s.Touch2Y=105]="Touch2Y",s[s.Touch3X=106]="Touch3X",s[s.Touch3Y=107]="Touch3Y",s[s.Touch4X=108]="Touch4X",s[s.Touch4Y=109]="Touch4Y",s[s.Touch5X=110]="Touch5X",s[s.Touch5Y=111]="Touch5Y",s[s.Touch6X=112]="Touch6X",s[s.Touch6Y=113]="Touch6Y",s[s.Touch7X=114]="Touch7X",s[s.Touch7Y=115]="Touch7Y",s[s.Touch8X=116]="Touch8X",s[s.Touch8Y=117]="Touch8Y",s[s.Touch9X=118]="Touch9X",s[s.Touch9Y=119]="Touch9Y",s[s.PinchScale=200]="PinchScale",s[s.RotationAngle=201]="RotationAngle",s[s.SwipeVelocityX=202]="SwipeVelocityX",s[s.SwipeVelocityY=203]="SwipeVelocityY",s))(S||{});function H(e){return e<100}n(H,"isTouchButton");function $(e){return e>=100&&e<200}n($,"isTouchPosition");function O(e){return e>=200}n(O,"isTouchGesture");function W(e){return e<0||e>9?null:100+e*2}n(W,"getTouchXAxis");function Q(e){return e<0||e>9?null:101+e*2}n(Q,"getTouchYAxis");var k=(t=>(t[t.DPadUp=0]="DPadUp",t[t.DPadDown=1]="DPadDown",t[t.DPadLeft=2]="DPadLeft",t[t.DPadRight=3]="DPadRight",t[t.DPadCenter=4]="DPadCenter",t[t.Play=5]="Play",t[t.Pause=6]="Pause",t[t.PlayPause=7]="PlayPause",t[t.Stop=8]="Stop",t[t.Rewind=9]="Rewind",t[t.FastForward=10]="FastForward",t[t.Previous=11]="Previous",t[t.Next=12]="Next",t[t.Record=13]="Record",t[t.VolumeUp=15]="VolumeUp",t[t.VolumeDown=16]="VolumeDown",t[t.Mute=17]="Mute",t[t.ChannelUp=18]="ChannelUp",t[t.ChannelDown=19]="ChannelDown",t[t.Back=20]="Back",t[t.Home=21]="Home",t[t.Menu=22]="Menu",t[t.Info=23]="Info",t[t.Guide=24]="Guide",t[t.Exit=25]="Exit",t[t.Red=30]="Red",t[t.Green=31]="Green",t[t.Yellow=32]="Yellow",t[t.Blue=33]="Blue",t[t.Digit0=40]="Digit0",t[t.Digit1=41]="Digit1",t[t.Digit2=42]="Digit2",t[t.Digit3=43]="Digit3",t[t.Digit4=44]="Digit4",t[t.Digit5=45]="Digit5",t[t.Digit6=46]="Digit6",t[t.Digit7=47]="Digit7",t[t.Digit8=48]="Digit8",t[t.Digit9=49]="Digit9",t[t.Input=50]="Input",t[t.Settings=51]="Settings",t[t.Subtitle=52]="Subtitle",t[t.Audio=53]="Audio",t[t.Power=54]="Power",t[t.PointerX=100]="PointerX",t[t.PointerY=101]="PointerY",t[t.GyroX=102]="GyroX",t[t.GyroY=103]="GyroY",t[t.GyroZ=104]="GyroZ",t))(k||{});function Z(e){return e<100}n(Z,"isTVRemoteButton");function j(e){return e>=100}n(j,"isTVRemoteAxis");function J(e,r){return{device:e,input:r}}n(J,"createInputDescriptor");function E(e){switch(e.device){case 0:return!0;case 1:return e.input<100;case 2:return e.input<100;case 3:return e.input<100;case 4:return e.input<100;default:return!1}}n(E,"isButton");function G(e){return!E(e)}n(G,"isAxis");function V(e){let r=new Uint8Array(3);return r[0]=e.device,r[1]=e.input&255,r[2]=e.input>>8&255,r}n(V,"serializeInputDescriptor");function y(e,r=0){let h=e[r],g=e[r+1]|e[r+2]<<8;return{device:h,input:g}}n(y,"deserializeInputDescriptor");function _(e){let r=P[e.device],h;switch(e.device){case 0:h=z[e.input];break;case 1:h=A[e.input];break;case 2:h=B[e.input];break;case 3:h=S[e.input];break;case 4:h=k[e.input];break;default:h="Unknown"}return`${r}:${h}`}n(_,"inputDescriptorToString");function T(e){let[r,h]=e.split(":");if(!r||!h)return null;let g=Object.entries(P).find(([D,f])=>D.toLowerCase()===r.toLowerCase()&&typeof f=="number")?.[1];if(g===void 0)return null;let m;switch(g){case 0:m=z[h];break;case 1:m=A[h];break;case 2:m=B[h];break;case 3:m=S[h];break;case 4:m=k[h];break}return m===void 0?null:{device:g,input:m}}n(T,"parseInputDescriptor");var l=class l{constructor(r=0,h=0){w(this,"x");w(this,"y");this.x=r,this.y=h}static zero(){return new l(0,0)}static one(){return new l(1,1)}static up(){return new l(0,-1)}static down(){return new l(0,1)}static left(){return new l(-1,0)}static right(){return new l(1,0)}add(r){return new l(this.x+r.x,this.y+r.y)}subtract(r){return new l(this.x-r.x,this.y-r.y)}multiply(r){return new l(this.x*r,this.y*r)}divide(r){if(r===0)throw new Error("Division by zero");return new l(this.x/r,this.y/r)}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}lengthSquared(){return this.x*this.x+this.y*this.y}normalize(){let r=this.length();return r===0?l.zero():this.divide(r)}distance(r){return this.subtract(r).length()}distanceSquared(r){return this.subtract(r).lengthSquared()}dot(r){return this.x*r.x+this.y*r.y}cross(r){return this.x*r.y-this.y*r.x}angle(){return Math.atan2(this.y,this.x)}angleTo(r){return Math.atan2(r.y-this.y,r.x-this.x)}rotate(r){let h=Math.cos(r),g=Math.sin(r);return new l(this.x*h-this.y*g,this.x*g+this.y*h)}lerp(r,h){return new l(this.x+(r.x-this.x)*h,this.y+(r.y-this.y)*h)}clone(){return new l(this.x,this.y)}equals(r){return this.x===r.x&&this.y===r.y}toString(){return`Vector2(${this.x}, ${this.y})`}toArray(){return[this.x,this.y]}set(r,h){return this.x=r,this.y=h,this}copy(r){return this.x=r.x,this.y=r.y,this}addInPlace(r){return this.x+=r.x,this.y+=r.y,this}subtractInPlace(r){return this.x-=r.x,this.y-=r.y,this}multiplyInPlace(r){return this.x*=r,this.y*=r,this}divideInPlace(r){if(r===0)throw new Error("Division by zero");return this.x/=r,this.y/=r,this}normalizeInPlace(){let r=this.length();return r===0?(this.x=0,this.y=0):(this.x/=r,this.y/=r),this}};n(l,"Vector2");var L=l;var o=class o{constructor(r=0,h=0,g=0){w(this,"x");w(this,"y");w(this,"z");this.x=r,this.y=h,this.z=g}static zero(){return new o(0,0,0)}static one(){return new o(1,1,1)}static up(){return new o(0,1,0)}static down(){return new o(0,-1,0)}static left(){return new o(-1,0,0)}static right(){return new o(1,0,0)}static forward(){return new o(0,0,1)}static back(){return new o(0,0,-1)}add(r){return new o(this.x+r.x,this.y+r.y,this.z+r.z)}subtract(r){return new o(this.x-r.x,this.y-r.y,this.z-r.z)}multiply(r){return new o(this.x*r,this.y*r,this.z*r)}divide(r){if(r===0)throw new Error("Division by zero");return new o(this.x/r,this.y/r,this.z/r)}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}lengthSquared(){return this.x*this.x+this.y*this.y+this.z*this.z}normalize(){let r=this.length();return r===0?o.zero():this.divide(r)}distance(r){return this.subtract(r).length()}distanceSquared(r){return this.subtract(r).lengthSquared()}dot(r){return this.x*r.x+this.y*r.y+this.z*r.z}cross(r){return new o(this.y*r.z-this.z*r.y,this.z*r.x-this.x*r.z,this.x*r.y-this.y*r.x)}lerp(r,h){return new o(this.x+(r.x-this.x)*h,this.y+(r.y-this.y)*h,this.z+(r.z-this.z)*h)}clone(){return new o(this.x,this.y,this.z)}equals(r){return this.x===r.x&&this.y===r.y&&this.z===r.z}toString(){return`Vector3(${this.x}, ${this.y}, ${this.z})`}toArray(){return[this.x,this.y,this.z]}set(r,h,g){return this.x=r,this.y=h,this.z=g,this}copy(r){return this.x=r.x,this.y=r.y,this.z=r.z,this}addInPlace(r){return this.x+=r.x,this.y+=r.y,this.z+=r.z,this}subtractInPlace(r){return this.x-=r.x,this.y-=r.y,this.z-=r.z,this}multiplyInPlace(r){return this.x*=r,this.y*=r,this.z*=r,this}divideInPlace(r){if(r===0)throw new Error("Division by zero");return this.x/=r,this.y/=r,this.z/=r,this}normalizeInPlace(){let r=this.length();return r===0?(this.x=0,this.y=0,this.z=0):(this.x/=r,this.y/=r,this.z/=r),this}};n(o,"Vector3");var Y=o;var R=(D=>(D[D.Disconnected=0]="Disconnected",D[D.Connecting=1]="Connecting",D[D.Connected=2]="Connected",D[D.Reconnecting=3]="Reconnecting",D[D.Error=4]="Error",D))(R||{});export{B as GamepadInput,P as InputDeviceType,z as KeyboardInput,A as MouseInput,R as NetworkState,k as TVRemoteInput,S as TouchInput,L as Vector2,Y as Vector3,J as createInputDescriptor,y as deserializeInputDescriptor,U as gamepadAxisIndexToInput,q as gamepadButtonIndexToInput,W as getTouchXAxis,Q as getTouchYAxis,_ as inputDescriptorToString,G as isAxis,E as isButton,u as isGamepadAxis,F as isGamepadButton,a as isMouseAxis,N as isMouseButton,j as isTVRemoteAxis,Z as isTVRemoteButton,H as isTouchButton,O as isTouchGesture,$ as isTouchPosition,v as keyCodeToKeyboardInput,M as keyboardInputToKeyCode,T as parseInputDescriptor,V as serializeInputDescriptor};
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@utsp/types",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Type definitions and interfaces for UTSP (Universal Text Stream Protocol)",
|
|
5
|
+
"author": "Thomas Piquet",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.mjs",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"typescript",
|
|
19
|
+
"types",
|
|
20
|
+
"utsp",
|
|
21
|
+
"terminal",
|
|
22
|
+
"rendering",
|
|
23
|
+
"input",
|
|
24
|
+
"networking",
|
|
25
|
+
"text-mode",
|
|
26
|
+
"ascii"
|
|
27
|
+
],
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/thp-software/utsp.git",
|
|
31
|
+
"directory": "packages/types"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/thp-software/utsp/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/thp-software/utsp/tree/master/packages/types#readme",
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=18.0.0"
|
|
39
|
+
},
|
|
40
|
+
"sideEffects": false,
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"README.md",
|
|
44
|
+
"LICENSE"
|
|
45
|
+
],
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"typescript": "^5.6.3"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "node ../../scripts/build-package.mjs packages/types",
|
|
54
|
+
"dev": "tsc --watch",
|
|
55
|
+
"clean": "rimraf dist",
|
|
56
|
+
"lint": "eslint \"src/**/*.ts\" --max-warnings 0",
|
|
57
|
+
"lint:fix": "eslint \"src/**/*.ts\" --fix",
|
|
58
|
+
"typecheck": "tsc --noEmit",
|
|
59
|
+
"test": "echo \"No tests configured yet\""
|
|
60
|
+
}
|
|
61
|
+
}
|