@n3rdw1z4rd/core 0.18.5 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +72 -10
  2. package/dist/astar.d.ts +44 -0
  3. package/dist/astar.js +118 -0
  4. package/dist/canvas-renderer.d.ts +154 -0
  5. package/dist/canvas-renderer.js +200 -0
  6. package/dist/clock.d.ts +69 -0
  7. package/dist/clock.js +108 -0
  8. package/dist/color-palette.d.ts +25 -0
  9. package/dist/color-palette.js +112 -0
  10. package/dist/color.d.ts +90 -0
  11. package/dist/color.js +224 -0
  12. package/dist/css/main.css +1 -3
  13. package/dist/disposable.d.ts +27 -0
  14. package/dist/disposable.js +32 -0
  15. package/dist/dungeon-generator.d.ts +142 -0
  16. package/dist/dungeon-generator.js +288 -0
  17. package/dist/ecs.d.ts +87 -0
  18. package/dist/ecs.js +101 -0
  19. package/dist/emitter.d.ts +40 -0
  20. package/dist/emitter.js +54 -0
  21. package/dist/event-queue.d.ts +29 -0
  22. package/dist/event-queue.js +40 -0
  23. package/dist/index.cjs +3813 -0
  24. package/dist/index.d.cts +2655 -0
  25. package/dist/index.d.ts +35 -873
  26. package/dist/index.js +34 -3981
  27. package/dist/input/action-map.d.ts +79 -0
  28. package/dist/input/action-map.js +131 -0
  29. package/dist/input/bindings.d.ts +273 -0
  30. package/dist/input/bindings.js +250 -0
  31. package/dist/input/gestures.d.ts +108 -0
  32. package/dist/input/gestures.js +159 -0
  33. package/dist/input/index.d.ts +5 -0
  34. package/dist/input/index.js +5 -0
  35. package/dist/input/input.d.ts +297 -0
  36. package/dist/input/input.js +695 -0
  37. package/dist/log.d.ts +8 -0
  38. package/dist/log.js +9 -0
  39. package/dist/map2d.d.ts +83 -0
  40. package/dist/map2d.js +120 -0
  41. package/dist/map3d-CHDJiq5T.d.cts +236 -0
  42. package/dist/map3d.d.ts +94 -0
  43. package/dist/map3d.js +148 -0
  44. package/dist/math.d.ts +176 -0
  45. package/dist/math.js +206 -0
  46. package/dist/misc.d.ts +46 -0
  47. package/dist/misc.js +71 -0
  48. package/dist/observable.d.ts +43 -0
  49. package/dist/observable.js +53 -0
  50. package/dist/particle-renderer.d.ts +47 -0
  51. package/dist/particle-renderer.js +82 -0
  52. package/dist/particle-system-2d.d.ts +60 -0
  53. package/dist/particle-system-2d.js +147 -0
  54. package/dist/random.d.ts +46 -0
  55. package/dist/random.js +74 -0
  56. package/dist/rectangle.d.ts +44 -0
  57. package/dist/rectangle.js +69 -0
  58. package/dist/rng.d.ts +72 -0
  59. package/dist/rng.js +152 -0
  60. package/dist/signal.d.ts +34 -0
  61. package/dist/signal.js +41 -0
  62. package/dist/spatial-partition-2d.d.ts +42 -0
  63. package/dist/spatial-partition-2d.js +52 -0
  64. package/dist/spatial-partition-3d-Ba-VBveM.cjs +1324 -0
  65. package/dist/spatial-partition-3d.d.ts +44 -0
  66. package/dist/spatial-partition-3d.js +57 -0
  67. package/dist/three/asteroid-mesh.d.ts +41 -0
  68. package/dist/three/asteroid-mesh.js +44 -0
  69. package/dist/three/camera-rig.d.ts +140 -0
  70. package/dist/three/camera-rig.js +197 -0
  71. package/dist/three/cube-sphere-geometry.d.ts +55 -0
  72. package/dist/three/cube-sphere-geometry.js +239 -0
  73. package/dist/three/ecs.d.ts +75 -0
  74. package/dist/three/ecs.js +64 -0
  75. package/dist/three/index.d.ts +12 -0
  76. package/dist/three/index.js +12 -0
  77. package/dist/three/particle-system-3d.d.ts +53 -0
  78. package/dist/three/particle-system-3d.js +224 -0
  79. package/dist/three/renderer.d.ts +38 -0
  80. package/dist/three/renderer.js +57 -0
  81. package/dist/three/starfield.d.ts +23 -0
  82. package/dist/three/starfield.js +64 -0
  83. package/dist/three/texture-atlas.d.ts +76 -0
  84. package/dist/three/texture-atlas.js +84 -0
  85. package/dist/three/texture-utils.d.ts +31 -0
  86. package/dist/three/texture-utils.js +44 -0
  87. package/dist/three/voxel-geometry.d.ts +72 -0
  88. package/dist/three/voxel-geometry.js +231 -0
  89. package/dist/three/voxel-mesh.d.ts +67 -0
  90. package/dist/three/voxel-mesh.js +71 -0
  91. package/dist/three.cjs +1307 -0
  92. package/dist/three.d.cts +655 -0
  93. package/dist/tilemap.d.ts +17 -0
  94. package/dist/tilemap.js +26 -0
  95. package/dist/types.d.ts +34 -0
  96. package/dist/types.js +0 -0
  97. package/dist/vector.d.ts +78 -0
  98. package/dist/vector.js +169 -0
  99. package/dist/webgl-renderer.d.ts +89 -0
  100. package/dist/webgl-renderer.js +140 -0
  101. package/dist/webgl.d.ts +357 -0
  102. package/dist/webgl.js +628 -0
  103. package/dist/worker-interface.d.ts +30 -0
  104. package/dist/worker-interface.js +39 -0
  105. package/package.json +55 -13
  106. package/dist/css/index.ts +0 -1
  107. package/dist/index.css +0 -104
  108. package/dist/index.d.mts +0 -873
  109. package/dist/index.mjs +0 -3977
@@ -0,0 +1,357 @@
1
+ //#region src/webgl.d.ts
2
+ /**
3
+ * Literal GLenum values, so importing this module doesn't require `WebGL2RenderingContext` to exist.
4
+ *
5
+ * @category WebGL
6
+ */
7
+ export declare enum ShaderType {
8
+ /** gl.VERTEX_SHADER */
9
+ VERTEX = 35633,
10
+ /** gl.FRAGMENT_SHADER */
11
+ FRAGMENT = 35632
12
+ }
13
+ /**
14
+ * Creates a WebGL2 context. Throws (instead of returning null) when WebGL2 isn't available.
15
+ *
16
+ * @param canvas defaults to a new canvas element
17
+ *
18
+ * @category WebGL
19
+ */
20
+ export declare function CreateWebGlContext(canvas?: HTMLCanvasElement | OffscreenCanvas, attributes?: WebGLContextAttributes): WebGL2RenderingContext;
21
+ /**
22
+ * Sizes the drawing buffer to `width` x `height` CSS pixels times the pixel ratio (sharp on
23
+ * high-DPI screens) and sets the viewport. Without a size, uses the canvas's parent (or its own)
24
+ * size on the page. Returns whether the size changed.
25
+ *
26
+ * @category WebGL
27
+ */
28
+ export declare function ResizeWebGlContext(gl: WebGL2RenderingContext, width?: number, height?: number, pixelRatio?: number): boolean;
29
+ /**
30
+ * Compiles a shader; throws an Error quoting the failing source lines.
31
+ *
32
+ * @category WebGL
33
+ */
34
+ export declare function CompileShader(gl: WebGL2RenderingContext, type: ShaderType, source: string): WebGLShader;
35
+ /**
36
+ * Links a program from shader sources (or compiled shaders). Shaders compiled here are deleted
37
+ * after linking; ones passed in are left to the caller.
38
+ *
39
+ * @category WebGL
40
+ */
41
+ export declare function CreateProgram(gl: WebGL2RenderingContext, vertexShader: WebGLShader | string, fragmentShader: WebGLShader | string): WebGLProgram;
42
+ /**
43
+ * An active vertex attribute of a linked program, from {@link GetProgramLocations}.
44
+ *
45
+ * @category WebGL
46
+ */
47
+ export interface AttributeInfo {
48
+ /** attribute location (the first one, for matrices) */
49
+ location: number;
50
+ /** GL type of the attribute (gl.FLOAT_VEC3, gl.FLOAT_MAT4, ...) */
51
+ type: number;
52
+ /** array length (1 for non-arrays) */
53
+ size: number;
54
+ }
55
+ /**
56
+ * An active uniform of a linked program, from {@link GetProgramLocations}.
57
+ *
58
+ * @category WebGL
59
+ */
60
+ export interface UniformInfo {
61
+ /** location to pass to `gl.uniform*` */
62
+ location: WebGLUniformLocation;
63
+ /** GL type (gl.FLOAT_VEC3, gl.SAMPLER_2D, ...) */
64
+ type: number;
65
+ /** array length (1 for non-arrays) */
66
+ size: number;
67
+ /** samplers: first texture unit assigned to this uniform */
68
+ textureUnit?: number;
69
+ }
70
+ /**
71
+ * A program's active attributes and uniforms, by name.
72
+ *
73
+ * @category WebGL
74
+ */
75
+ export type ProgramLocations = {
76
+ /** by attribute name; built-ins (`gl_*`) are left out */
77
+ attributes: Record<string, AttributeInfo>;
78
+ /** by uniform name (arrays by their base name); uniform block members are left out */
79
+ uniforms: Record<string, UniformInfo>;
80
+ };
81
+ /**
82
+ * A linked program (`program`) with its attribute and uniform info, from {@link CreateProgramInfo}.
83
+ *
84
+ * @category WebGL
85
+ */
86
+ export type ProgramInfo = ProgramLocations & {
87
+ /** the linked program */
88
+ program: WebGLProgram;
89
+ };
90
+ /**
91
+ * Active attributes and uniforms of a linked program. Array uniforms are listed by their base
92
+ * name (`uLights[0]` -> `uLights`); samplers are given consecutive texture units.
93
+ *
94
+ * @category WebGL
95
+ */
96
+ export declare function GetProgramLocations(gl: WebGL2RenderingContext, program: WebGLProgram): ProgramLocations;
97
+ /**
98
+ * Links a program and collects its attribute and uniform info.
99
+ *
100
+ * @category WebGL
101
+ */
102
+ export declare function CreateProgramInfo(gl: WebGL2RenderingContext, vertexShaderSource: string, fragmentShaderSource: string): ProgramInfo;
103
+ /**
104
+ * Deletes the program.
105
+ *
106
+ * @category WebGL
107
+ */
108
+ export declare function DeleteProgramInfo(gl: WebGL2RenderingContext, info: ProgramInfo): void;
109
+ /**
110
+ * A value for {@link SetUniforms}: a number or boolean for scalars, a numeric array for vectors,
111
+ * matrices (column-major) and arrays of them, or a texture (or array of textures) for samplers.
112
+ *
113
+ * @category WebGL
114
+ */
115
+ export type UniformValue = number | boolean | ArrayLike<number> | WebGLTexture | TextureInfo | (WebGLTexture | TextureInfo)[];
116
+ /**
117
+ * Sets uniforms by name; the right `gl.uniform*` call comes from each uniform's declared type.
118
+ * Textures are bound to the sampler's texture unit. Names the program doesn't use (e.g. optimized
119
+ * away by the compiler) are ignored. Makes the program current.
120
+ *
121
+ * @category WebGL
122
+ */
123
+ export declare function SetUniforms(gl: WebGL2RenderingContext, info: ProgramInfo, values: Record<string, UniformValue>): void;
124
+ /**
125
+ * Options for {@link CreateBuffer}.
126
+ *
127
+ * @category WebGL
128
+ */
129
+ export interface BufferOptions {
130
+ /** default gl.ARRAY_BUFFER (gl.ELEMENT_ARRAY_BUFFER for indices) */
131
+ target?: number;
132
+ /** default gl.STATIC_DRAW (gl.DYNAMIC_DRAW for data updated every frame) */
133
+ usage?: number;
134
+ }
135
+ /**
136
+ * Creates a buffer from data (a plain number array becomes a Float32Array) or with a byte size
137
+ * to fill later with UpdateBuffer.
138
+ *
139
+ * @category WebGL
140
+ */
141
+ export declare function CreateBuffer(gl: WebGL2RenderingContext, data: AllowSharedBufferSource | number[] | number, options?: BufferOptions): WebGLBuffer;
142
+ /**
143
+ * Writes data into an existing buffer, starting at `byteOffset`.
144
+ *
145
+ * @category WebGL
146
+ */
147
+ export declare function UpdateBuffer(gl: WebGL2RenderingContext, buffer: WebGLBuffer, data: AllowSharedBufferSource | number[], byteOffset?: number, target?: number): void;
148
+ /**
149
+ * Where and how a vertex attribute reads its data, for {@link CreateVertexArray}.
150
+ *
151
+ * @category WebGL
152
+ */
153
+ export interface AttributeSource {
154
+ /** the buffer holding the data */
155
+ buffer: WebGLBuffer;
156
+ /** components per vertex (per column for matrices) */
157
+ size: number;
158
+ /** default gl.FLOAT */
159
+ type?: number;
160
+ /** integer data read as 0..1 / -1..1 floats */
161
+ normalized?: boolean;
162
+ /** bytes; 0 = tightly packed */
163
+ stride?: number;
164
+ /** bytes */
165
+ offset?: number;
166
+ /** 1 = advance per instance (instancing); 0 = per vertex */
167
+ divisor?: number;
168
+ }
169
+ /**
170
+ * A vertex array object and the buffers it reads from, from {@link CreateVertexArray}.
171
+ *
172
+ * @category WebGL
173
+ */
174
+ export interface VertexArrayInfo {
175
+ /** the vertex array object */
176
+ vao: WebGLVertexArrayObject;
177
+ /** buffers used, for DeleteVertexArray (an index buffer passed in as a buffer is not included) */
178
+ buffers: WebGLBuffer[];
179
+ /** the element buffer, when indexed */
180
+ indexBuffer?: WebGLBuffer;
181
+ /** gl.UNSIGNED_SHORT etc. when indexed */
182
+ indexType?: number;
183
+ /** default draw count: the number of indices (or the given `count`), else the vertices in the shortest per-vertex buffer */
184
+ count?: number;
185
+ }
186
+ /**
187
+ * Records how the program's attributes read from buffers (and the index buffer) into a vertex
188
+ * array object. Integer attributes (int / uint / ivec / uvec) use vertexAttribIPointer
189
+ * automatically; matrix attributes (e.g. per-instance mat4) are spread over their columns.
190
+ * Attributes the program doesn't use are skipped.
191
+ *
192
+ * @param indices an index array (Uint16Array / Uint32Array / Uint8Array), or an existing buffer and its type
193
+ *
194
+ * @category WebGL
195
+ */
196
+ export declare function CreateVertexArray(gl: WebGL2RenderingContext, info: ProgramInfo, attributes: Record<string, AttributeSource>, indices?: Uint8Array | Uint16Array | Uint32Array | {
197
+ buffer: WebGLBuffer;
198
+ type: number;
199
+ count?: number;
200
+ }): VertexArrayInfo;
201
+ /**
202
+ * Deletes the vertex array; with `buffers`, also the buffers it reads from.
203
+ *
204
+ * @category WebGL
205
+ */
206
+ export declare function DeleteVertexArray(gl: WebGL2RenderingContext, info: VertexArrayInfo, options?: {
207
+ buffers?: boolean;
208
+ }): void;
209
+ /**
210
+ * Options for {@link CreateTexture} and {@link LoadWebGlTexture}.
211
+ *
212
+ * @category WebGL
213
+ */
214
+ export interface TextureOptions {
215
+ /** default 'linear' */
216
+ filter?: 'nearest' | 'linear';
217
+ /** default 'clamp' */
218
+ wrap?: 'clamp' | 'repeat' | 'mirror';
219
+ /** default false */
220
+ mipmaps?: boolean;
221
+ /** flip images vertically on upload (default false) */
222
+ flipY?: boolean;
223
+ /** default false */
224
+ premultiplyAlpha?: boolean;
225
+ /** data textures: default gl.RGBA8 */
226
+ internalFormat?: number;
227
+ /** data textures: default gl.RGBA */
228
+ format?: number;
229
+ /** data textures: default gl.UNSIGNED_BYTE */
230
+ type?: number;
231
+ }
232
+ /**
233
+ * Raw texture contents (or just a size) for {@link CreateTexture} and {@link UpdateTexture}.
234
+ *
235
+ * @category WebGL
236
+ */
237
+ export interface TextureData {
238
+ /** pixels */
239
+ width: number;
240
+ /** pixels */
241
+ height: number;
242
+ /** null / undefined = allocate only (e.g. render targets) */
243
+ data?: ArrayBufferView | null;
244
+ }
245
+ /**
246
+ * A 2D texture with its size, from {@link CreateTexture}. Can be passed directly as a sampler uniform.
247
+ *
248
+ * @category WebGL
249
+ */
250
+ export interface TextureInfo {
251
+ /** the texture object */
252
+ texture: WebGLTexture;
253
+ /** pixels, as of the last upload */
254
+ width: number;
255
+ /** pixels, as of the last upload */
256
+ height: number;
257
+ /** a copy of the options it was created with, reused by {@link UpdateTexture} */
258
+ options: TextureOptions;
259
+ }
260
+ /**
261
+ * Creates a 2D texture from an image / canvas / video / bitmap, or from raw data.
262
+ *
263
+ * @category WebGL
264
+ */
265
+ export declare function CreateTexture(gl: WebGL2RenderingContext, source: TexImageSource | TextureData, options?: TextureOptions): TextureInfo;
266
+ /**
267
+ * Re-uploads a texture's contents (the size may change); regenerates mipmaps if it has them.
268
+ *
269
+ * @category WebGL
270
+ */
271
+ export declare function UpdateTexture(gl: WebGL2RenderingContext, info: TextureInfo, source: TexImageSource | TextureData): void;
272
+ /**
273
+ * Loads an image from a URL into a texture.
274
+ *
275
+ * @category WebGL
276
+ */
277
+ export declare function LoadWebGlTexture(gl: WebGL2RenderingContext, url: string, options?: TextureOptions): Promise<TextureInfo>;
278
+ /**
279
+ * Deletes the texture.
280
+ *
281
+ * @category WebGL
282
+ */
283
+ export declare function DeleteTexture(gl: WebGL2RenderingContext, info: TextureInfo): void;
284
+ /**
285
+ * An offscreen framebuffer with a color texture, from {@link CreateRenderTarget}.
286
+ *
287
+ * @category WebGL
288
+ */
289
+ export interface RenderTarget {
290
+ /** the framebuffer object */
291
+ framebuffer: WebGLFramebuffer;
292
+ /** the color output; use it as a sampler uniform */
293
+ texture: TextureInfo;
294
+ /** the DEPTH24_STENCIL8 renderbuffer, unless created with `depth: false` */
295
+ depth?: WebGLRenderbuffer;
296
+ /** pixels */
297
+ width: number;
298
+ /** pixels */
299
+ height: number;
300
+ }
301
+ /**
302
+ * Options for {@link CreateRenderTarget}: the color texture's options, plus `depth`.
303
+ *
304
+ * @category WebGL
305
+ */
306
+ export interface RenderTargetOptions extends Omit<TextureOptions, 'mipmaps' | 'flipY' | 'premultiplyAlpha'> {
307
+ /** depth (and stencil) attachment. Default true. */
308
+ depth?: boolean;
309
+ }
310
+ /**
311
+ * An offscreen framebuffer with a color texture (and depth), for render-to-texture and post-processing.
312
+ *
313
+ * @category WebGL
314
+ */
315
+ export declare function CreateRenderTarget(gl: WebGL2RenderingContext, width: number, height: number, options?: RenderTargetOptions): RenderTarget;
316
+ /**
317
+ * Reallocates the target's color texture (and depth buffer) at a new size, discarding their contents. Does nothing if the size is unchanged.
318
+ *
319
+ * @category WebGL
320
+ */
321
+ export declare function ResizeRenderTarget(gl: WebGL2RenderingContext, target: RenderTarget, width: number, height: number): void;
322
+ /**
323
+ * Draws into `target` (or the canvas, with null) and sets the viewport to match.
324
+ *
325
+ * @category WebGL
326
+ */
327
+ export declare function BindRenderTarget(gl: WebGL2RenderingContext, target: RenderTarget | null): void;
328
+ /**
329
+ * Deletes the framebuffer, its color texture and its depth buffer.
330
+ *
331
+ * @category WebGL
332
+ */
333
+ export declare function DeleteRenderTarget(gl: WebGL2RenderingContext, target: RenderTarget): void;
334
+ /**
335
+ * Options for {@link Draw}.
336
+ *
337
+ * @category WebGL
338
+ */
339
+ export interface DrawOptions {
340
+ /** default gl.TRIANGLES */
341
+ mode?: number;
342
+ /** vertices (or indices); default: the vertex array's count */
343
+ count?: number;
344
+ /** first vertex (or index) */
345
+ offset?: number;
346
+ /** > 0: instanced draw */
347
+ instances?: number;
348
+ /** set with {@link SetUniforms} before drawing */
349
+ uniforms?: Record<string, UniformValue>;
350
+ }
351
+ /**
352
+ * Draws a vertex array with a program; indexed and instanced draws are picked automatically.
353
+ *
354
+ * @category WebGL
355
+ */
356
+ export declare function Draw(gl: WebGL2RenderingContext, info: ProgramInfo, vertexArray: VertexArrayInfo, options?: DrawOptions): void;
357
+ //#endregion