rapid-render 0.1.2 → 0.1.4
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/README.md +36 -100
- package/dist/depth.d.ts +8 -0
- package/dist/index.d.ts +4 -3
- package/dist/interface.d.ts +83 -34
- package/dist/line.d.ts +8 -1
- package/dist/log.d.ts +2 -0
- package/dist/math.d.ts +218 -44
- package/dist/rapid.global.js +1 -1
- package/dist/rapid.js +2453 -1
- package/dist/rapid.umd.cjs +1 -1
- package/dist/regions/attributes.d.ts +44 -0
- package/dist/regions/graphic_region.d.ts +5 -25
- package/dist/regions/region.d.ts +12 -5
- package/dist/regions/sprite_region.d.ts +2 -26
- package/dist/render.d.ts +91 -49
- package/dist/texture.d.ts +30 -2
- package/dist/tilemap.d.ts +92 -19
- package/dist/utils.d.ts +1 -0
- package/dist/webgl/glshader.d.ts +14 -4
- package/dist/webgl/uniform.d.ts +13 -0
- package/package.json +1 -1
package/dist/math.d.ts
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
import { WebGLContext } from "./interface";
|
|
2
|
-
|
|
1
|
+
import { IMathStruct as IMathObject, ITransform, WebGLContext } from "./interface";
|
|
2
|
+
/**
|
|
3
|
+
* @ignore
|
|
4
|
+
*/
|
|
5
|
+
export declare enum ArrayType {
|
|
6
|
+
Float32 = 0,
|
|
7
|
+
Uint32 = 1,
|
|
8
|
+
Uint16 = 2
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @ignore
|
|
12
|
+
*/
|
|
3
13
|
export declare class DynamicArrayBuffer {
|
|
4
14
|
usedElemNum: number;
|
|
5
|
-
protected typedArray: Float32Array | Uint16Array;
|
|
15
|
+
protected typedArray: Float32Array | Uint32Array | Uint16Array;
|
|
6
16
|
private arrayType;
|
|
7
17
|
protected maxElemNum: number;
|
|
8
18
|
readonly bytePerElem: number;
|
|
9
19
|
private arraybuffer;
|
|
10
|
-
/** if typedArray is Float32Array*/
|
|
11
20
|
private uint32?;
|
|
21
|
+
private float32?;
|
|
22
|
+
private uint16?;
|
|
12
23
|
constructor(arrayType: ArrayType);
|
|
24
|
+
getArrayType(arrayType: ArrayType): Float32ArrayConstructor | Uint32ArrayConstructor | Uint16ArrayConstructor;
|
|
25
|
+
updateTypedArray(): void;
|
|
13
26
|
clear(): void;
|
|
14
27
|
/**
|
|
15
28
|
* resize the array
|
|
@@ -18,12 +31,9 @@ export declare class DynamicArrayBuffer {
|
|
|
18
31
|
*/
|
|
19
32
|
resize(size?: number): void;
|
|
20
33
|
protected setMaxSize(size?: number): void;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*/
|
|
25
|
-
push(value: number): void;
|
|
26
|
-
pushUint(value: number): void;
|
|
34
|
+
pushUint32(value: number): void;
|
|
35
|
+
pushFloat32(value: number): void;
|
|
36
|
+
pushUint16(value: number): void;
|
|
27
37
|
/**
|
|
28
38
|
* pop a element
|
|
29
39
|
* @param num
|
|
@@ -35,12 +45,15 @@ export declare class DynamicArrayBuffer {
|
|
|
35
45
|
* @param end
|
|
36
46
|
* @returns
|
|
37
47
|
*/
|
|
38
|
-
getArray(begin?: number, end?: number):
|
|
48
|
+
getArray(begin?: number, end?: number): Uint32Array | Float32Array | Uint16Array;
|
|
39
49
|
/**
|
|
40
50
|
* length of the array
|
|
41
51
|
*/
|
|
42
52
|
get length(): number;
|
|
43
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* @ignore
|
|
56
|
+
*/
|
|
44
57
|
export declare class WebglBufferArray extends DynamicArrayBuffer {
|
|
45
58
|
buffer: WebGLBuffer;
|
|
46
59
|
gl: WebGLContext;
|
|
@@ -51,7 +64,9 @@ export declare class WebglBufferArray extends DynamicArrayBuffer {
|
|
|
51
64
|
*/
|
|
52
65
|
private webglBufferSize;
|
|
53
66
|
constructor(gl: WebGLContext, arrayType: ArrayType, type?: number);
|
|
54
|
-
|
|
67
|
+
pushFloat32(value: number): void;
|
|
68
|
+
pushUint32(value: number): void;
|
|
69
|
+
pushUint16(value: number): void;
|
|
55
70
|
/**
|
|
56
71
|
* bind buffer to gpu
|
|
57
72
|
*/
|
|
@@ -80,7 +95,7 @@ export declare class MatrixStack extends DynamicArrayBuffer {
|
|
|
80
95
|
* @param x - The amount to translate horizontally.
|
|
81
96
|
* @param y - The amount to translate vertically.
|
|
82
97
|
*/
|
|
83
|
-
translate(x: number | Vec2, y
|
|
98
|
+
translate(x: number | Vec2, y?: number): void;
|
|
84
99
|
/**
|
|
85
100
|
* Rotates the current matrix by the specified angle.
|
|
86
101
|
* @param angle - The angle, in radians, to rotate the matrix by.
|
|
@@ -96,7 +111,7 @@ export declare class MatrixStack extends DynamicArrayBuffer {
|
|
|
96
111
|
* Transforms a point by applying the current matrix stack.
|
|
97
112
|
* @returns The transformed point as an array `[newX, newY]`.
|
|
98
113
|
*/
|
|
99
|
-
apply(x: number | Vec2, y
|
|
114
|
+
apply(x: number | Vec2, y?: number): Vec2 | number[];
|
|
100
115
|
/**
|
|
101
116
|
* Obtain the inverse matrix of the current matrix
|
|
102
117
|
* @returns inverse matrix
|
|
@@ -112,7 +127,63 @@ export declare class MatrixStack extends DynamicArrayBuffer {
|
|
|
112
127
|
* @param array
|
|
113
128
|
*/
|
|
114
129
|
setTransform(array: Float32Array | number[]): void;
|
|
130
|
+
/**
|
|
131
|
+
* Get the global position in world space
|
|
132
|
+
* @returns The current matrix position in world space
|
|
133
|
+
*/
|
|
134
|
+
getGlobalPosition(): Vec2;
|
|
135
|
+
/**
|
|
136
|
+
* Set the global position in world space
|
|
137
|
+
* @param x - x coordinate or Vec2 object
|
|
138
|
+
* @param y - y coordinate (ignored if first parameter is Vec2)
|
|
139
|
+
*/
|
|
140
|
+
setGlobalPosition(x: number | Vec2, y?: number): void;
|
|
141
|
+
/**
|
|
142
|
+
* Get the global rotation angle
|
|
143
|
+
* @returns The current matrix rotation angle in radians
|
|
144
|
+
*/
|
|
145
|
+
getGlobalRotation(): number;
|
|
146
|
+
/**
|
|
147
|
+
* Set the global rotation angle
|
|
148
|
+
* @param angle - rotation angle in radians
|
|
149
|
+
*/
|
|
150
|
+
setGlobalRotation(angle: number): void;
|
|
151
|
+
/**
|
|
152
|
+
* Get the global scale
|
|
153
|
+
* @returns The current matrix scale values
|
|
154
|
+
*/
|
|
155
|
+
getGlobalScale(): Vec2;
|
|
156
|
+
/**
|
|
157
|
+
* Set the global scale
|
|
158
|
+
* @param x - x scale or Vec2 object
|
|
159
|
+
* @param y - y scale (ignored if first parameter is Vec2)
|
|
160
|
+
*/
|
|
161
|
+
setGlobalScale(x: number | Vec2, y?: number): void;
|
|
162
|
+
globalToLocal(global: Vec2): Vec2;
|
|
163
|
+
localToGlobal(local: Vec2): Vec2;
|
|
164
|
+
/**
|
|
165
|
+
* Convert the current matrix to a CSS transform string
|
|
166
|
+
* @returns CSS transform string representation of the matrix
|
|
167
|
+
*/
|
|
168
|
+
toCSSTransform(): string;
|
|
169
|
+
/**
|
|
170
|
+
* Reset the current matrix to identity matrix
|
|
171
|
+
*/
|
|
172
|
+
identity(): void;
|
|
173
|
+
/**
|
|
174
|
+
* Apply the transform to the current matrix
|
|
175
|
+
* @param transform - The transform to apply
|
|
176
|
+
* @returns offset position
|
|
177
|
+
*/
|
|
178
|
+
applyTransform(transform: ITransform, width?: number, height?: number): {
|
|
179
|
+
offsetX: number;
|
|
180
|
+
offsetY: number;
|
|
181
|
+
};
|
|
182
|
+
applyTransformAfter(transform: ITransform): void;
|
|
115
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* @ignore
|
|
186
|
+
*/
|
|
116
187
|
export declare class WebglElementBufferArray extends WebglBufferArray {
|
|
117
188
|
constructor(gl: WebGLContext, elemVertPerObj: number, vertexPerObject: number, maxBatch: number);
|
|
118
189
|
protected addObject(_vertex?: number): void;
|
|
@@ -120,7 +191,7 @@ export declare class WebglElementBufferArray extends WebglBufferArray {
|
|
|
120
191
|
/**
|
|
121
192
|
* Represents a color with red, green, blue, and alpha (transparency) components.
|
|
122
193
|
*/
|
|
123
|
-
export declare class Color {
|
|
194
|
+
export declare class Color implements IMathObject<Color> {
|
|
124
195
|
private _r;
|
|
125
196
|
private _g;
|
|
126
197
|
private _b;
|
|
@@ -133,7 +204,7 @@ export declare class Color {
|
|
|
133
204
|
* @param b - The blue component (0-255).
|
|
134
205
|
* @param a - The alpha component (0-255).
|
|
135
206
|
*/
|
|
136
|
-
constructor(r: number, g: number, b: number, a
|
|
207
|
+
constructor(r: number, g: number, b: number, a?: number);
|
|
137
208
|
/**
|
|
138
209
|
* Gets the red component.
|
|
139
210
|
*/
|
|
@@ -188,12 +259,17 @@ export declare class Color {
|
|
|
188
259
|
* @param color - The color to copy from.
|
|
189
260
|
*/
|
|
190
261
|
copy(color: Color): void;
|
|
262
|
+
/**
|
|
263
|
+
* Clone the current color
|
|
264
|
+
* @returns A new `Color` instance with the same RGBA values.
|
|
265
|
+
*/
|
|
266
|
+
clone(): Color;
|
|
191
267
|
/**
|
|
192
268
|
* Checks if the current color is equal to another color.
|
|
193
269
|
* @param color - The color to compare with.
|
|
194
270
|
* @returns True if the colors are equal, otherwise false.
|
|
195
271
|
*/
|
|
196
|
-
|
|
272
|
+
equal(color: Color): boolean;
|
|
197
273
|
/**
|
|
198
274
|
* Creates a Color instance from a hexadecimal color string.
|
|
199
275
|
* @param hexString - The hexadecimal color string, e.g., '#RRGGBB' or '#RRGGBBAA'.
|
|
@@ -212,13 +288,33 @@ export declare class Color {
|
|
|
212
288
|
* @returns A new Color instance with the result of the subtraction.
|
|
213
289
|
*/
|
|
214
290
|
subtract(color: Color): Color;
|
|
291
|
+
static Red: Color;
|
|
292
|
+
static Green: Color;
|
|
293
|
+
static Blue: Color;
|
|
294
|
+
static Yellow: Color;
|
|
295
|
+
static Purple: Color;
|
|
296
|
+
static Orange: Color;
|
|
297
|
+
static Pink: Color;
|
|
298
|
+
static Gray: Color;
|
|
299
|
+
static Brown: Color;
|
|
300
|
+
static Cyan: Color;
|
|
301
|
+
static Magenta: Color;
|
|
302
|
+
static Lime: Color;
|
|
303
|
+
static White: Color;
|
|
304
|
+
static Black: Color;
|
|
215
305
|
}
|
|
216
306
|
/**
|
|
217
307
|
* Represents a 2D vector with x and y components.
|
|
218
308
|
*/
|
|
219
|
-
export declare class Vec2 {
|
|
309
|
+
export declare class Vec2 implements IMathObject<Vec2> {
|
|
220
310
|
x: number;
|
|
221
311
|
y: number;
|
|
312
|
+
static ZERO: Vec2;
|
|
313
|
+
static ONE: Vec2;
|
|
314
|
+
static UP: Vec2;
|
|
315
|
+
static DOWN: Vec2;
|
|
316
|
+
static LEFT: Vec2;
|
|
317
|
+
static RIGHT: Vec2;
|
|
222
318
|
/**
|
|
223
319
|
* Creates an instance of Vec2.
|
|
224
320
|
* @param x - The x coordinate (default is 0).
|
|
@@ -226,11 +322,63 @@ export declare class Vec2 {
|
|
|
226
322
|
*/
|
|
227
323
|
constructor(x?: number, y?: number);
|
|
228
324
|
/**
|
|
229
|
-
*
|
|
230
|
-
* @param
|
|
231
|
-
* @returns
|
|
325
|
+
* Adds another vector to this vector.
|
|
326
|
+
* @param v - The vector to add.
|
|
327
|
+
* @returns A new Vec2 instance with the result of the addition.
|
|
232
328
|
*/
|
|
233
|
-
|
|
329
|
+
add(v: Vec2): Vec2;
|
|
330
|
+
/**
|
|
331
|
+
* Subtracts another vector from this vector.
|
|
332
|
+
* @param v - The vector to subtract.
|
|
333
|
+
* @returns A new Vec2 instance with the result of the subtraction.
|
|
334
|
+
*/
|
|
335
|
+
subtract(v: Vec2): Vec2;
|
|
336
|
+
/**
|
|
337
|
+
* Multiplies the vector by a scalar or another vector.
|
|
338
|
+
* @param f - The scalar value or vector to multiply by.
|
|
339
|
+
* @returns A new Vec2 instance with the result of the multiplication.
|
|
340
|
+
*/
|
|
341
|
+
multiply(f: number | Vec2): Vec2;
|
|
342
|
+
/**
|
|
343
|
+
* Divides the vector by a scalar or another vector.
|
|
344
|
+
* @param f - The scalar value or vector to divide by.
|
|
345
|
+
* @returns A new Vec2 instance with the result of the division.
|
|
346
|
+
*/
|
|
347
|
+
divide(f: number | Vec2): Vec2;
|
|
348
|
+
/**
|
|
349
|
+
* Calculates the dot product of this vector with another vector.
|
|
350
|
+
* @param v - The other vector.
|
|
351
|
+
* @returns The dot product result.
|
|
352
|
+
*/
|
|
353
|
+
dot(v: Vec2): number;
|
|
354
|
+
/**
|
|
355
|
+
* Calculates the cross product of this vector with another vector.
|
|
356
|
+
* @param v - The other vector.
|
|
357
|
+
* @returns The cross product result.
|
|
358
|
+
*/
|
|
359
|
+
cross(v: Vec2): number;
|
|
360
|
+
/**
|
|
361
|
+
* Calculates the distance to another point.
|
|
362
|
+
* @param v - The other point.
|
|
363
|
+
* @returns The distance between the two points.
|
|
364
|
+
*/
|
|
365
|
+
distanceTo(v: Vec2): number;
|
|
366
|
+
/**
|
|
367
|
+
* Clones the vector.
|
|
368
|
+
* @returns A new Vec2 instance with the same x and y values.
|
|
369
|
+
*/
|
|
370
|
+
clone(): Vec2;
|
|
371
|
+
/**
|
|
372
|
+
* Copy the vector
|
|
373
|
+
* @param vec - The vector to copy.
|
|
374
|
+
*/
|
|
375
|
+
copy(vec: Vec2): void;
|
|
376
|
+
/**
|
|
377
|
+
* Check if the vector is equal to another vector.
|
|
378
|
+
* @param vec - The vector to compare with.
|
|
379
|
+
* @returns True if the vectors are equal, otherwise false.
|
|
380
|
+
*/
|
|
381
|
+
equal(vec: Vec2): boolean;
|
|
234
382
|
/**
|
|
235
383
|
* Rotates the vector 90 degrees counterclockwise.
|
|
236
384
|
* @returns The current instance with updated values.
|
|
@@ -257,38 +405,64 @@ export declare class Vec2 {
|
|
|
257
405
|
*/
|
|
258
406
|
angle(): number;
|
|
259
407
|
/**
|
|
260
|
-
*
|
|
261
|
-
* @param
|
|
262
|
-
* @
|
|
263
|
-
|
|
408
|
+
* Calculates the middle point between the current vector and another vector.
|
|
409
|
+
* @param other - The other vector.
|
|
410
|
+
* @returns A new vector representing the middle point between the current vector and the other vector.
|
|
411
|
+
*/
|
|
412
|
+
middle(other: Vec2): Vec2;
|
|
413
|
+
/**
|
|
414
|
+
* Returns a new vector with the absolute values of the components.
|
|
415
|
+
* @returns A new vector with absolute values.
|
|
264
416
|
*/
|
|
265
|
-
|
|
417
|
+
abs(): Vec2;
|
|
266
418
|
/**
|
|
267
|
-
*
|
|
268
|
-
* @
|
|
269
|
-
* @param p1 - The second vector.
|
|
270
|
-
* @returns A new vector representing the sum of p0 and p1.
|
|
419
|
+
* Returns a new vector with floored components.
|
|
420
|
+
* @returns A new vector with components rounded down to the nearest integer.
|
|
271
421
|
*/
|
|
272
|
-
|
|
422
|
+
floor(): Vec2;
|
|
273
423
|
/**
|
|
274
|
-
*
|
|
275
|
-
* @
|
|
276
|
-
* @param p0 - The vector to subtract.
|
|
277
|
-
* @returns A new vector representing the difference between p1 and p0.
|
|
424
|
+
* Returns a new vector with ceiled components.
|
|
425
|
+
* @returns A new vector with components rounded up to the nearest integer.
|
|
278
426
|
*/
|
|
279
|
-
|
|
427
|
+
ceil(): Vec2;
|
|
280
428
|
/**
|
|
281
|
-
*
|
|
282
|
-
* @param
|
|
283
|
-
* @
|
|
284
|
-
* @returns A new vector representing the midpoint between p0 and p1.
|
|
429
|
+
* Snaps the vector components to the nearest increment.
|
|
430
|
+
* @param increment - The increment to snap to.
|
|
431
|
+
* @returns A new vector with components snapped to the nearest increment.
|
|
285
432
|
*/
|
|
286
|
-
|
|
433
|
+
snap(increment: number): Vec2;
|
|
434
|
+
/**
|
|
435
|
+
* Converts the vector to a string representation.
|
|
436
|
+
* @returns A string containing the vector's x and y coordinates.
|
|
437
|
+
*/
|
|
438
|
+
stringify(): string;
|
|
287
439
|
/**
|
|
288
440
|
* Converts an array of coordinate pairs into an array of Vec2 instances.
|
|
289
441
|
* @param array - An array of [x, y] coordinate pairs.
|
|
290
442
|
* @returns An array of Vec2 instances.
|
|
291
443
|
*/
|
|
292
|
-
static
|
|
444
|
+
static FromArray(array: number[][]): Vec2[];
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Provides utility methods for mathematical conversions.
|
|
448
|
+
*/
|
|
449
|
+
export declare class MathUtils {
|
|
450
|
+
/**
|
|
451
|
+
* Converts degrees to radians.
|
|
452
|
+
* @param degrees - The angle in degrees.
|
|
453
|
+
* @returns The equivalent angle in radians.
|
|
454
|
+
*/
|
|
455
|
+
static deg2rad(degrees: number): number;
|
|
456
|
+
/**
|
|
457
|
+
* Converts radians to degrees.
|
|
458
|
+
* @param rad - The angle in radians.
|
|
459
|
+
* @returns The equivalent angle in degrees.
|
|
460
|
+
*/
|
|
461
|
+
static rad2deg(rad: number): number;
|
|
462
|
+
/**
|
|
463
|
+
* Normalizes an angle in degrees to be within the range of 0 to 360 degrees.
|
|
464
|
+
* @param degrees - The angle in degrees to be normalized.
|
|
465
|
+
* @returns The normalized angle in degrees.
|
|
466
|
+
*/
|
|
467
|
+
static normalizeDegrees(degrees: number): number;
|
|
293
468
|
}
|
|
294
|
-
export {};
|
package/dist/rapid.global.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var rapid=function(t){"use strict";const e=(t,e,r)=>{const i=t.createShader(r);if(!i)throw new Error("Unable to create webgl shader");t.shaderSource(i,e),t.compileShader(i);if(!t.getShaderParameter(i,t.COMPILE_STATUS)){const r=t.getShaderInfoLog(i);throw console.error("Shader compilation failed:",r),new Error("Unable to compile shader: "+r+e)}return i};const r=5126;class i{constructor(t){this.usedElemNum=0,this.maxElemNum=512,this.bytePerElem=t.BYTES_PER_ELEMENT,this.arrayType=t,this.arraybuffer=new ArrayBuffer(this.maxElemNum*this.bytePerElem),this.typedArray=new t(this.arraybuffer),t==Float32Array&&(this.uint32=new Uint32Array(this.arraybuffer))}clear(){this.usedElemNum=0}resize(t=0){if((t+=this.usedElemNum)>this.maxElemNum){for(;t>this.maxElemNum;)this.maxElemNum<<=1;this.setMaxSize(this.maxElemNum)}}setMaxSize(t=this.maxElemNum){const e=this.typedArray;this.maxElemNum=t,this.arraybuffer=new ArrayBuffer(t*this.bytePerElem),this.typedArray=new this.arrayType(this.arraybuffer),this.uint32&&(this.uint32=new Uint32Array(this.arraybuffer)),this.typedArray.set(e)}push(t){this.typedArray[this.usedElemNum++]=t}pushUint(t){this.uint32[this.usedElemNum++]=t}pop(t){this.usedElemNum-=t}getArray(t=0,e){return null==e?this.typedArray:this.typedArray.subarray(t,e)}get length(){return this.typedArray.length}}class s extends i{constructor(t,e,r=t.ARRAY_BUFFER){super(e),this.dirty=!0,this.webglBufferSize=0,this.gl=t,this.buffer=t.createBuffer(),this.type=r}push(t){super.push(t),this.dirty=!0}bindBuffer(){this.gl.bindBuffer(this.type,this.buffer)}bufferData(){if(this.dirty){const t=this.gl;this.maxElemNum>this.webglBufferSize?(t.bufferData(this.type,this.getArray(),t.STATIC_DRAW),this.webglBufferSize=this.maxElemNum):t.bufferSubData(this.type,0,this.getArray(0,this.usedElemNum)),this.dirty=!1}}}class n extends i{constructor(){super(Float32Array)}pushMat(){const t=this.usedElemNum-6,e=this.typedArray;this.resize(6),this.push(e[t+0]),this.push(e[t+1]),this.push(e[t+2]),this.push(e[t+3]),this.push(e[t+4]),this.push(e[t+5])}popMat(){this.pop(6)}pushIdentity(){this.resize(6),this.push(1),this.push(0),this.push(0),this.push(1),this.push(0),this.push(0)}translate(t,e){if(t instanceof o)return this.translate(t.x,t.y);const r=this.usedElemNum-6,i=this.typedArray;i[r+4]=i[r+0]*t+i[r+2]*e+i[r+4],i[r+5]=i[r+1]*t+i[r+3]*e+i[r+5]}rotate(t){const e=this.usedElemNum-6,r=this.typedArray,i=Math.cos(t),s=Math.sin(t),n=r[e+0],a=r[e+1],h=r[e+2],o=r[e+3];r[e+0]=n*i-a*s,r[e+1]=n*s+a*i,r[e+2]=h*i-o*s,r[e+3]=h*s+o*i}scale(t,e){if(t instanceof o)return this.scale(t.x,t.y);e||(e=t);const r=this.usedElemNum-6,i=this.typedArray;i[r+0]=i[r+0]*t,i[r+1]=i[r+1]*t,i[r+2]=i[r+2]*e,i[r+3]=i[r+3]*e}apply(t,e){if(t instanceof o)return new o(...this.apply(t.x,t.y));const r=this.usedElemNum-6,i=this.typedArray;return[i[r+0]*t+i[r+2]*e+i[r+4],i[r+1]*t+i[r+3]*e+i[r+5]]}getInverse(){const t=this.usedElemNum-6,e=this.typedArray,r=e[t+0],i=e[t+1],s=e[t+2],n=e[t+3],a=e[t+4],h=e[t+5],o=r*n-i*s;return new Float32Array([n/o,-i/o,-s/o,r/o,(s*h-n*a)/o,(i*a-r*h)/o])}getTransform(){const t=this.usedElemNum-6,e=this.typedArray;return new Float32Array([e[t+0],e[t+1],e[t+2],e[t+3],e[t+4],e[t+5]])}setTransform(t){const e=this.usedElemNum-6,r=this.typedArray;r[e+0]=t[0],r[e+1]=t[1],r[e+2]=t[2],r[e+3]=t[3],r[e+4]=t[4],r[e+5]=t[5]}}class a extends s{constructor(t,e,r,i){super(t,Uint16Array,t.ELEMENT_ARRAY_BUFFER),this.setMaxSize(e*i);for(let t=0;t<i;t++)this.addObject(t*r);this.bindBuffer(),this.bufferData()}addObject(t){}}class h{constructor(t,e,r,i){this._r=t,this._g=e,this._b=r,this._a=i,this.updateUint()}get r(){return this._r}set r(t){this._r=t,this.updateUint()}get g(){return this._g}set g(t){this._g=t,this.updateUint()}get b(){return this._b}set b(t){this._b=t,this.updateUint()}get a(){return this._a}set a(t){this._a=t,this.updateUint()}updateUint(){this.uint32=(this._a<<24|this._b<<16|this._g<<8|this._r)>>>0}setRGBA(t,e,r,i){this.r=t,this.g=e,this.b=r,this.a=i,this.updateUint()}copy(t){this.setRGBA(t.r,t.g,t.b,t.a)}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b&&t.a===this.a}static fromHex(t){t.startsWith("#")&&(t=t.slice(1));const e=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);let s=255;return t.length>=8&&(s=parseInt(t.slice(6,8),16)),new h(e,r,i,s)}add(t){return new h(Math.min(this.r+t.r,255),Math.min(this.g+t.g,255),Math.min(this.b+t.b,255),Math.min(this.a+t.a,255))}subtract(t){return new h(Math.max(this.r-t.r,0),Math.max(this.g-t.g,0),Math.max(this.b-t.b,0),Math.max(this.a-t.a,0))}}class o{constructor(t,e){this.x=void 0!==t?t:0,this.y=void 0!==e?e:0}scalarMult(t){return this.x*=t,this.y*=t,this}perpendicular(){const t=this.x;return this.x=-this.y,this.y=t,this}invert(){return this.x=-this.x,this.y=-this.y,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}normalize(){const t=this.length();return this.x/=t,this.y/=t,this}angle(){return this.y/this.x}static Angle(t,e){return Math.atan2(e.y-t.y,e.x-t.x)}static Add(t,e){return new o(t.x+e.x,t.y+e.y)}static Sub(t,e){return new o(t.x-e.x,t.y-e.y)}static Middle(t,e){return o.Add(t,e).scalarMult(.5)}static FormArray(t){return t.map((t=>new o(t[0],t[1])))}}class u{constructor(t){this.cache=new Map,this.render=t}async textureFromUrl(t,e=!1){let r=this.cache.get(t);if(!r){const i=await this.loadImage(t);r=l.fromImageSource(this.render,i,e),this.cache.set(t,r)}return new c(r)}async loadImage(t){return new Promise((e=>{const r=new Image;r.onload=()=>{e(r)},r.src=t}))}createText(t){return new d(this.render,t)}}class l{constructor(t,e,r){this.texture=t,this.width=e,this.height=r}static fromImageSource(t,e,r=!1){return new l(function(t,e,r){const i=t.createTexture();if(t.bindTexture(t.TEXTURE_2D,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,r?t.LINEAR:t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,r?t.LINEAR:t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),!i)throw new Error("unable to create texture");return i}(t.gl,e,r),e.width,e.height)}}class c{constructor(t){this.scale=1,this.setBaseTextur(t)}setBaseTextur(t){t&&(this.base=t,this.setClipRegion(0,0,t.width,t.height))}setClipRegion(t,e,r,i){this.base&&(this.clipX=t/this.base.width,this.clipY=e/this.base.width,this.clipW=this.clipX+r/this.base.width,this.clipH=this.clipY+i/this.base.height,this.width=r*this.scale,this.height=i*this.scale)}static fromImageSource(t,e,r=!1){return new c(l.fromImageSource(t,e,r))}static fromUrl(t,e){return t.textures.textureFromUrl(e)}}class d extends c{constructor(t,e){super(),this.scale=.5,this.rapid=t,this.options=e,this.text=e.text||"",this.updateTextImage()}updateTextImage(){const t=this.createTextCanvas();this.setBaseTextur(l.fromImageSource(this.rapid,t,!0))}createTextCanvas(){const t=document.createElement("canvas"),e=t.getContext("2d");if(!e)throw new Error("Failed to get canvas context");e.font=`${this.options.fontSize||16}px ${this.options.fontFamily||"Arial"}`,e.fillStyle=this.options.color||"#000",e.textAlign=this.options.textAlign||"left",e.textBaseline=this.options.textBaseline||"top";const r=this.text.split("\n");let i=0,s=0;for(const t of r){const r=e.measureText(t);i=Math.max(i,r.width),s+=this.options.fontSize||16}t.width=2*i,t.height=2*s,e.scale(2,2),e.font=`${this.options.fontSize||16}px ${this.options.fontFamily||"Arial"}`,e.fillStyle=this.options.color||"#000",e.textAlign=this.options.textAlign||"left",e.textBaseline=this.options.textBaseline||"top";let n=0;for(const t of r)e.fillText(t,0,n),n+=this.options.fontSize||16;return t}setText(t){this.text!=t&&(this.text=t,this.updateTextImage())}}class p{constructor(t,r,i){this.attributeLoc={},this.uniformLoc={};const s=function(t,e){if(t.includes("%TEXTURE_NUM%")&&(t=t.replace("%TEXTURE_NUM%",e.toString())),t.includes("%GET_COLOR%")){let r="";for(let t=0;t<e;t++)r+=0==t?`if(vTextureId == ${t}.0)`:t==e-1?"else":`else if(vTextureId == ${t}.0)`,r+=`{color = texture2D(uTextures[${t}], vRegion);}`;t=t.replace("%GET_COLOR%",r)}return t}(i,t.maxTextureUnits);this.program=((t,r,i)=>{var s=t.createProgram(),n=e(t,r,35633),a=e(t,i,35632);if(!s)throw new Error("Unable to create program shader");if(t.attachShader(s,n),t.attachShader(s,a),t.linkProgram(s),!t.getProgramParameter(s,t.LINK_STATUS)){const e=t.getProgramInfoLog(s);throw new Error("Unable to link shader program: "+e)}return s})(t.gl,r,s),this.gl=t.gl,this.parseShader(r),this.parseShader(s)}setUniforms(t,e){var r;const i=this.gl;for(const s in t){const n=t[s],a=this.getUniform(s);if(n instanceof c&&(null===(r=n.base)||void 0===r?void 0:r.texture))i.activeTexture(i.TEXTURE0+e),i.bindTexture(i.TEXTURE_2D,n.base.texture),i.uniform1i(a,e),e+=1;else if("number"==typeof n)i.uniform1f(a,n);else if(Array.isArray(n))switch(n.length){case 1:Number.isInteger(n[0])?i.uniform1i(a,n[0]):i.uniform1f(a,n[0]);break;case 2:Number.isInteger(n[0])?i.uniform2iv(a,n):i.uniform2fv(a,n);break;case 3:Number.isInteger(n[0])?i.uniform3iv(a,n):i.uniform3fv(a,n);break;case 4:Number.isInteger(n[0])?i.uniform4iv(a,n):i.uniform4fv(a,n);break;case 9:i.uniformMatrix3fv(a,!1,n);break;case 16:i.uniformMatrix4fv(a,!1,n);break;default:console.error(`Unsupported uniform array length for ${s}:`,n.length)}else"boolean"==typeof n?i.uniform1i(a,n?1:0):console.error(`Unsupported uniform type for ${s}:`,typeof n)}}getUniform(t){return this.uniformLoc[t]}use(){this.gl.useProgram(this.program)}parseShader(t){const e=this.gl,r=t.match(/attribute\s+\w+\s+(\w+)/g);if(r)for(const t of r){const r=t.split(" ")[2],i=e.getAttribLocation(this.program,r);-1!=i&&(this.attributeLoc[r]=i)}const i=t.match(/uniform\s+\w+\s+(\w+)/g);if(i)for(const t of i){const r=t.split(" ")[2];this.uniformLoc[r]=e.getUniformLocation(this.program,r)}}setAttribute(t){const e=this.attributeLoc[t.name];if(void 0!==e){const r=this.gl;r.vertexAttribPointer(e,t.size,t.type,t.normalized||!1,t.stride,t.offset||0),r.enableVertexAttribArray(e)}}}class f{constructor(t,e){this.usedTextures=[],this.needBind=new Set,this.attribute=e,this.rapid=t,this.gl=t.gl,this.webglArrayBuffer=new s(t.gl,Float32Array,t.gl.ARRAY_BUFFER),this.TEXTURE_UNITS_ARRAY=Array.from({length:t.maxTextureUnits},((t,e)=>e))}addVertex(t,e,...r){const[i,s]=this.rapid.transformPoint(t,e);this.webglArrayBuffer.push(i),this.webglArrayBuffer.push(s)}useTexture(t){let e=this.usedTextures.indexOf(t);return-1===e&&(this.usedTextures.length>=this.rapid.maxTextureUnits&&this.render(),this.usedTextures.push(t),e=this.usedTextures.length-1,this.needBind.add(e)),e}enterRegion(t){this.currentShader=null!=t?t:this.defaultShader,this.currentShader.use(),this.initializeForNextRender(),this.webglArrayBuffer.bindBuffer();for(const t of this.attribute)this.currentShader.setAttribute(t);this.gl.uniformMatrix4fv(this.currentShader.uniformLoc.uProjectionMatrix,!1,this.rapid.projection)}exitRegion(){}initDefaultShader(t,e){this.webglArrayBuffer.bindBuffer(),this.defaultShader=new p(this.rapid,t,e)}render(){this.executeRender(),this.initializeForNextRender()}executeRender(){this.webglArrayBuffer.bufferData();const t=this.gl;for(const e of this.needBind)t.activeTexture(t.TEXTURE0+e),t.bindTexture(t.TEXTURE_2D,this.usedTextures[e]);this.needBind.clear()}initializeForNextRender(){this.webglArrayBuffer.clear(),this.usedTextures=[]}hasPendingContent(){return!1}}class g extends f{constructor(t){super(t,m),this.vertex=0,this.drawType=t.gl.TRIANGLE_FAN,this.initDefaultShader("precision mediump float;\r\n\r\nattribute vec2 aPosition;\r\nattribute vec4 aColor;\r\nattribute vec2 aRegion;\r\n\r\nvarying vec4 vColor;\r\nuniform mat4 uProjectionMatrix;\r\nuniform vec4 uColor;\r\nvarying vec2 vRegion;\r\n\r\nvoid main(void) {\r\n gl_Position = uProjectionMatrix * vec4(aPosition, 0.0, 1.0);\r\n vColor = aColor;\r\n vRegion = aRegion;\r\n}\r\n","precision mediump float;\r\nvarying vec2 vRegion;\r\nvarying vec4 vColor;\r\n\r\nuniform sampler2D uTexture;\r\nuniform int uUseTexture;\r\n\r\nvoid main(void) {\r\n if(uUseTexture > 0){\r\n gl_FragColor = texture2D(uTexture, vRegion) * vColor;\r\n }else{\r\n gl_FragColor = vColor;\r\n }\r\n}\r\n")}startRender(t){this.vertex=0,this.webglArrayBuffer.clear(),t&&t.base&&(this.texture=this.useTexture(t.base.texture))}addVertex(t,e,r,i,s){this.webglArrayBuffer.resize(3),super.addVertex(t,e),this.webglArrayBuffer.pushUint(s),this.webglArrayBuffer.push(r),this.webglArrayBuffer.push(i),this.vertex+=1}executeRender(){super.executeRender();const t=this.gl;t.uniform1i(this.currentShader.uniformLoc.uUseTexture,void 0===this.texture?0:1),this.texture&&t.uniform1i(this.currentShader.uniformLoc.uTexture,this.texture),t.drawArrays(this.drawType,0,this.vertex),this.drawType=this.rapid.gl.TRIANGLE_FAN,this.vertex=0,this.texture=void 0}}const m=[{name:"aPosition",size:2,type:r,stride:20},{name:"aColor",size:4,type:5121,stride:20,offset:2*Float32Array.BYTES_PER_ELEMENT,normalized:!0},{name:"aRegion",size:2,type:r,stride:20,offset:3*Float32Array.BYTES_PER_ELEMENT}];class x extends a{constructor(t,e){super(t,6,4,e)}addObject(t){super.addObject(),this.push(t),this.push(t+3),this.push(t+2),this.push(t),this.push(t+1),this.push(t+2)}}class y extends f{constructor(t){const e=t.gl;super(t,T),this.batchSprite=0,this.initDefaultShader("precision mediump float;\r\n\r\nattribute vec2 aPosition;\r\nattribute vec2 aRegion;\r\nattribute float aTextureId;\r\nattribute vec4 aColor;\r\n\r\nuniform mat4 uProjectionMatrix;\r\n\r\nvarying vec2 vRegion;\r\nvarying float vTextureId;\r\nvarying vec4 vColor;\r\n\r\nvoid main(void) {\r\n vRegion = aRegion;\r\n vTextureId = aTextureId;\r\n vColor = aColor;\r\n gl_Position = uProjectionMatrix * vec4(aPosition, 0.0, 1.0);\r\n}","precision mediump float;\r\nuniform sampler2D uTextures[%TEXTURE_NUM%];\r\n\r\nvarying vec2 vRegion;\r\nvarying float vTextureId;\r\nvarying vec4 vColor;\r\n\r\nvoid main(void) {\r\n vec4 color;\r\n %GET_COLOR%\r\n\r\n gl_FragColor = color*vColor;\r\n}"),this.MAX_BATCH=Math.floor(16384),this.indexBuffer=new x(e,this.MAX_BATCH)}addVertex(t,e,r,i,s,n){super.addVertex(t,e),this.webglArrayBuffer.push(r),this.webglArrayBuffer.push(i),this.webglArrayBuffer.push(s),this.webglArrayBuffer.pushUint(n)}renderSprite(t,e,r,i,s,n,a,h,o,u,l){var c;l&&(null===(c=this.currentShader)||void 0===c||c.setUniforms(l,1)),this.batchSprite>=this.MAX_BATCH&&this.render(),this.batchSprite++,this.webglArrayBuffer.resize(24);const d=this.useTexture(t),p=h+e,f=o+r,g=i+n,m=s+a;this.addVertex(h,o,i,s,d,u),this.addVertex(p,o,g,s,d,u),this.addVertex(p,f,g,m,d,u),this.addVertex(h,f,i,m,d,u)}executeRender(){super.executeRender();const t=this.gl;t.drawElements(t.TRIANGLES,6*this.batchSprite,t.UNSIGNED_SHORT,0)}enterRegion(t){super.enterRegion(t),this.indexBuffer.bindBuffer(),this.gl.uniform1iv(this.currentShader.uniformLoc.uTextures,this.TEXTURE_UNITS_ARRAY)}initializeForNextRender(){super.initializeForNextRender(),this.batchSprite=0}hasPendingContent(){return this.batchSprite>0}}const T=[{name:"aPosition",size:2,type:r,stride:24},{name:"aRegion",size:2,type:r,stride:24,offset:2*Float32Array.BYTES_PER_ELEMENT},{name:"aTextureId",size:1,type:r,stride:24,offset:4*Float32Array.BYTES_PER_ELEMENT},{name:"aColor",size:4,type:5121,stride:24,offset:5*Float32Array.BYTES_PER_ELEMENT,normalized:!0}];var E,A,b,R;t.JoinTyps=void 0,(E=t.JoinTyps||(t.JoinTyps={}))[E.BEVEL=0]="BEVEL",E[E.ROUND=1]="ROUND",E[E.MITER=2]="MITER",t.CapTyps=void 0,(A=t.CapTyps||(t.CapTyps={}))[A.BUTT=0]="BUTT",A[A.ROUND=1]="ROUND",A[A.SQUARE=2]="SQUARE",t.RenderStatus=void 0,(b=t.RenderStatus||(t.RenderStatus={}))[b.NORMAL=0]="NORMAL",b[b.MASK=1]="MASK",t.MaskType=void 0,(R=t.MaskType||(t.MaskType={})).Normal="normal",R.Inverse="inverse";const v=1e-4,S=(t,e,r,i)=>{i.push(t),i.push(o.Add(t,r)),i.push(o.Add(e,r)),i.push(e),i.push(o.Add(e,r)),i.push(t)},w=(t,e,r,i,s)=>{const n=o.Sub(t,e).length();let a=Math.atan2(r.y-t.y,r.x-t.x),h=Math.atan2(e.y-t.y,e.x-t.x);const u=a;h>a?h-a>=Math.PI-v&&(h-=2*Math.PI):a-h>=Math.PI-v&&(a-=2*Math.PI);let l=h-a;if(Math.abs(l)>=Math.PI-v&&Math.abs(l)<=Math.PI+v){const e=o.Sub(t,i);0===e.x?e.y>0&&(l=-l):e.x>=-1e-4&&(l=-l)}const c=(Math.abs(l*n)/7|0)+1,d=l/c;for(let e=0;e<c;e++)s.push(new o(t.x,t.y)),s.push(new o(t.x+n*Math.cos(u+d*e),t.y+n*Math.sin(u+d*e))),s.push(new o(t.x+n*Math.cos(u+d*(1+e)),t.y+n*Math.sin(u+d*(1+e))))},M=(e,r,i,s,n,a,h)=>{const u=o.Sub(r,e).perpendicular(),l=o.Sub(i,r).perpendicular();((t,e,r)=>(e.x-t.x)*(r.y-t.y)-(r.x-t.x)*(e.y-t.y))(e,r,i)>0&&(u.invert(),l.invert()),u.normalize().scalarMult(n),l.normalize().scalarMult(n);const c=((t,e,r,i)=>{const s=e.y-t.y,n=t.x-e.x,a=i.y-r.y,h=r.x-i.x,u=s*h-a*n;if(u>-1e-4&&u<v)return null;{const e=s*t.x+n*t.y,i=a*r.x+h*r.y;return new o((h*e-n*i)/u,(s*i-a*e)/u)}})(o.Add(u,e),o.Add(u,r),o.Add(l,i),o.Add(l,r));let d=null,p=Number.MAX_VALUE;c&&(d=o.Sub(c,r),p=d.length());const f=p/n|0,g=o.Sub(e,r).length(),m=o.Sub(r,i).length();if(p>g||p>m)s.push(o.Add(e,u)),s.push(o.Sub(e,u)),s.push(o.Add(r,u)),s.push(o.Sub(e,u)),s.push(o.Add(r,u)),s.push(o.Sub(r,u)),a===t.JoinTyps.ROUND?w(r,o.Add(r,u),o.Add(r,l),i,s):a===t.JoinTyps.BEVEL||a===t.JoinTyps.MITER&&f>=h?(s.push(r),s.push(o.Add(r,u)),s.push(o.Add(r,l))):a===t.JoinTyps.MITER&&f<h&&c&&(s.push(o.Add(r,u)),s.push(r),s.push(c),s.push(o.Add(r,l)),s.push(r),s.push(c)),s.push(o.Add(i,l)),s.push(o.Sub(r,l)),s.push(o.Add(r,l)),s.push(o.Add(i,l)),s.push(o.Sub(r,l)),s.push(o.Sub(i,l));else{if(s.push(o.Add(e,u)),s.push(o.Sub(e,u)),s.push(o.Sub(r,d)),s.push(o.Add(e,u)),s.push(o.Sub(r,d)),s.push(o.Add(r,u)),a===t.JoinTyps.ROUND){const t=o.Add(r,u),e=o.Add(r,l),i=o.Sub(r,d),n=r;s.push(t),s.push(n),s.push(i),w(n,t,e,i,s),s.push(n),s.push(e),s.push(i)}else(a===t.JoinTyps.BEVEL||a===t.JoinTyps.MITER&&f>=h)&&(s.push(o.Add(r,u)),s.push(o.Add(r,l)),s.push(o.Sub(r,d))),a===t.JoinTyps.MITER&&f<h&&(s.push(c),s.push(o.Add(r,u)),s.push(o.Add(r,l)));s.push(o.Add(i,l)),s.push(o.Sub(r,d)),s.push(o.Add(r,l)),s.push(o.Add(i,l)),s.push(o.Sub(r,d)),s.push(o.Sub(i,l))}};return t.BaseTexture=l,t.Color=h,t.DynamicArrayBuffer=i,t.GLShader=p,t.MatrixStack=n,t.Rapid=class{constructor(t){this.projectionDirty=!0,this.matrixStack=new n,this.textures=new u(this),this.devicePixelRatio=window.devicePixelRatio||1,this.defaultColor=new h(255,255,255,255),this.regions=new Map;const e=(t=>{const e={stencil:!0},r=t.getContext("webgl2",e)||t.getContext("webgl",e);if(!r)throw new Error("Unable to initialize WebGL. Your browser may not support it.");return r})(t.canvas);this.gl=e,this.canvas=t.canvas,this.maxTextureUnits=e.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS),this.width=t.width||this.canvas.width,this.height=t.width||this.canvas.height,this.backgroundColor=t.backgroundColor||new h(255,255,255,255),this.registerBuildInRegion(),this.initWebgl(e)}initWebgl(t){this.resize(this.width,this.height),t.enable(t.BLEND),t.disable(t.DEPTH_TEST),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),t.enable(t.STENCIL_TEST)}registerBuildInRegion(){this.registerRegion("sprite",y),this.registerRegion("graphic",g)}registerRegion(t,e){this.regions.set(t,new e(this))}quitCurrentRegion(){this.currentRegion&&this.currentRegion.hasPendingContent()&&(this.currentRegion.render(),this.currentRegion.exitRegion())}setRegion(t,e){if(t!=this.currentRegionName||e&&e!==this.currentRegion.currentShader){const r=this.regions.get(t);this.quitCurrentRegion(),this.currentRegion=r,this.currentRegionName=t,r.enterRegion(e)}}save(){this.matrixStack.pushMat()}restore(){this.matrixStack.popMat()}startRender(t=!0){this.clear(),t&&this.matrixStack.clear(),this.matrixStack.pushIdentity(),this.currentRegion=void 0,this.currentRegionName=void 0}endRender(){var t;null===(t=this.currentRegion)||void 0===t||t.render(),this.projectionDirty=!1}renderSprite(t,e=0,r=0,i){if(t.base){if(i instanceof h)return this.renderSprite(t,e,r,{color:i});this.setRegion("sprite",null==i?void 0:i.shader),this.currentRegion.renderSprite(t.base.texture,t.width,t.height,t.clipX,t.clipY,t.clipW,t.clipH,e,r,((null==i?void 0:i.color)||this.defaultColor).uint32,null==i?void 0:i.uniforms)}}renderLine(e=0,r=0,i){const s=((e,r)=>{if(e.length<2)return[];let i=r.cap||t.CapTyps.BUTT,s=r.join||t.JoinTyps.BEVEL,n=(r.width||1)/2,a=r.miterLimit||10,h=[],u=[];if(2===e.length)s=t.JoinTyps.BEVEL,M(e[0],o.Middle(e[0],e[1]),e[1],h,n,s,a);else{for(let t=0;t<e.length-1;t++)0===t?u.push(e[0]):t===e.length-2?u.push(e[e.length-1]):u.push(o.Middle(e[t],e[t+1]));for(let t=1;t<u.length;t++)M(u[t-1],e[t],u[t],h,n,s,a)}if(i===t.CapTyps.ROUND){let t=h[0],r=h[1],i=e[1],s=h[h.length-1],n=h[h.length-3],a=e[e.length-2];w(e[0],t,r,i,h),w(e[e.length-1],s,n,a,h)}else if(i===t.CapTyps.SQUARE){let t=h[h.length-1],r=h[h.length-3];S(h[0],h[1],o.Sub(e[0],e[1]).normalize().scalarMult(o.Sub(e[0],h[0]).length()),h),S(t,r,o.Sub(e[e.length-1],e[e.length-2]).normalize().scalarMult(o.Sub(r,e[e.length-1]).length()),h)}return h})(i.points,i);this.renderGraphic(e,r,{color:i.color,drawType:this.gl.TRIANGLES,points:s})}renderGraphic(t=0,e=0,r){if(r instanceof Array)return this.renderGraphic(t,e,{points:r});this.setRegion("graphic",r.shader);const i=this.currentRegion;i.startRender(r.texture),r.drawType&&(i.drawType=r.drawType),r.points.forEach(((s,n)=>{var a;const h=r.color instanceof Array?r.color[n]:r.color,o=null===(a=r.uv)||void 0===a?void 0:a[n];i.addVertex(s.x+t,s.y+e,null==o?void 0:o.x,null==o?void 0:o.y,(h||this.defaultColor).uint32)})),i.render()}renderRect(t,e,r,i,s=this.defaultColor){const n=[new o(0,0),new o(r,0),new o(r,i),new o(0,i)];this.renderGraphic(t,e,{points:n,color:s,drawType:this.gl.TRIANGLE_FAN})}renderCircle(t,e,r,i=this.defaultColor,s=32){const n=[];for(let t=0;t<=s;t++){const e=t/s*Math.PI*2,i=Math.cos(e)*r,a=Math.sin(e)*r;n.push(new o(i,a))}this.renderGraphic(t,e,{points:n,color:i,drawType:this.gl.TRIANGLE_FAN})}resize(t,e){this.width=t,this.height=e;const r=t*this.devicePixelRatio,i=e*this.devicePixelRatio;this.canvas.width=r,this.canvas.height=i,this.gl.viewport(0,0,r,i),this.projection=this.createOrthMatrix(0,t,e,0),this.projectionDirty=!0}clear(){const t=this.gl,e=this.backgroundColor;t.clearColor(e.r,e.g,e.b,e.a),t.clear(t.COLOR_BUFFER_BIT),this.clearMask()}createOrthMatrix(t,e,r,i){return new Float32Array([2/(e-t),0,0,0,0,2/(i-r),0,0,0,0,-1,0,-(e+t)/(e-t),-(i+r)/(i-r),0,1])}transformPoint(t,e){return this.matrixStack.apply(t,e)}startDrawMask(){const t=this.gl;this.quitCurrentRegion(),t.clearStencil(0),t.clear(t.STENCIL_BUFFER_BIT),t.stencilFunc(t.ALWAYS,1,255),t.stencilOp(t.KEEP,t.KEEP,t.REPLACE),t.colorMask(!1,!1,!1,!1)}endDrawMask(e=t.MaskType.Normal){const r=this.gl;this.quitCurrentRegion(),this.setMaskType(e),r.stencilOp(r.KEEP,r.KEEP,r.KEEP),r.colorMask(!0,!0,!0,!0)}setMaskType(e){const r=this.gl;switch(this.quitCurrentRegion(),e){case t.MaskType.Normal:r.stencilFunc(r.EQUAL,1,255);break;case t.MaskType.Inverse:r.stencilFunc(r.NOTEQUAL,1,255)}}clearMask(){const t=this.gl;t.clear(t.STENCIL_BUFFER_BIT)}},t.SCALEFACTOR=2,t.Text=d,t.Texture=c,t.TextureCache=u,t.Vec2=o,t.WebglBufferArray=s,t.WebglElementBufferArray=a,t.graphicAttributes=m,t.spriteAttributes=T,t}({});
|
|
1
|
+
var rapid=function(t){"use strict";const e=(t,e,r)=>{const i=t.createShader(r);if(!i)throw new Error("Unable to create webgl shader");t.shaderSource(i,e),t.compileShader(i);if(!t.getShaderParameter(i,t.COMPILE_STATUS)){const r=t.getShaderInfoLog(i);throw console.error("Shader compilation failed:",r),new Error("Unable to compile shader: "+r+e)}return i};const r=5126;class i{constructor(t){this.usedElemNum=0,this.maxElemNum=512,this.bytePerElem=t.BYTES_PER_ELEMENT,this.arrayType=t,this.arraybuffer=new ArrayBuffer(this.maxElemNum*this.bytePerElem),this.typedArray=new t(this.arraybuffer),t==Float32Array&&(this.uint32=new Uint32Array(this.arraybuffer))}clear(){this.usedElemNum=0}resize(t=0){if((t+=this.usedElemNum)>this.maxElemNum){for(;t>this.maxElemNum;)this.maxElemNum<<=1;this.setMaxSize(this.maxElemNum)}}setMaxSize(t=this.maxElemNum){const e=this.typedArray;this.maxElemNum=t,this.arraybuffer=new ArrayBuffer(t*this.bytePerElem),this.typedArray=new this.arrayType(this.arraybuffer),this.uint32&&(this.uint32=new Uint32Array(this.arraybuffer)),this.typedArray.set(e)}push(t){this.typedArray[this.usedElemNum++]=t}pushUint(t){this.uint32[this.usedElemNum++]=t}pop(t){this.usedElemNum-=t}getArray(t=0,e){return null==e?this.typedArray:this.typedArray.subarray(t,e)}get length(){return this.typedArray.length}}class s extends i{constructor(t,e,r=t.ARRAY_BUFFER){super(e),this.dirty=!0,this.webglBufferSize=0,this.gl=t,this.buffer=t.createBuffer(),this.type=r}push(t){super.push(t),this.dirty=!0}bindBuffer(){this.gl.bindBuffer(this.type,this.buffer)}bufferData(){if(this.dirty){const t=this.gl;this.maxElemNum>this.webglBufferSize?(t.bufferData(this.type,this.getArray(),t.STATIC_DRAW),this.webglBufferSize=this.maxElemNum):t.bufferSubData(this.type,0,this.getArray(0,this.usedElemNum)),this.dirty=!1}}}class n extends i{constructor(){super(Float32Array)}pushMat(){const t=this.usedElemNum-6,e=this.typedArray;this.resize(6),this.push(e[t+0]),this.push(e[t+1]),this.push(e[t+2]),this.push(e[t+3]),this.push(e[t+4]),this.push(e[t+5])}popMat(){this.pop(6)}pushIdentity(){this.resize(6),this.push(1),this.push(0),this.push(0),this.push(1),this.push(0),this.push(0)}translate(t,e){if(t instanceof o)return this.translate(t.x,t.y);const r=this.usedElemNum-6,i=this.typedArray;i[r+4]=i[r+0]*t+i[r+2]*e+i[r+4],i[r+5]=i[r+1]*t+i[r+3]*e+i[r+5]}rotate(t){const e=this.usedElemNum-6,r=this.typedArray,i=Math.cos(t),s=Math.sin(t),n=r[e+0],a=r[e+1],h=r[e+2],o=r[e+3];r[e+0]=n*i-a*s,r[e+1]=n*s+a*i,r[e+2]=h*i-o*s,r[e+3]=h*s+o*i}scale(t,e){if(t instanceof o)return this.scale(t.x,t.y);e||(e=t);const r=this.usedElemNum-6,i=this.typedArray;i[r+0]=i[r+0]*t,i[r+1]=i[r+1]*t,i[r+2]=i[r+2]*e,i[r+3]=i[r+3]*e}apply(t,e){if(t instanceof o)return new o(...this.apply(t.x,t.y));const r=this.usedElemNum-6,i=this.typedArray;return[i[r+0]*t+i[r+2]*e+i[r+4],i[r+1]*t+i[r+3]*e+i[r+5]]}getInverse(){const t=this.usedElemNum-6,e=this.typedArray,r=e[t+0],i=e[t+1],s=e[t+2],n=e[t+3],a=e[t+4],h=e[t+5],o=r*n-i*s;return new Float32Array([n/o,-i/o,-s/o,r/o,(s*h-n*a)/o,(i*a-r*h)/o])}getTransform(){const t=this.usedElemNum-6,e=this.typedArray;return new Float32Array([e[t+0],e[t+1],e[t+2],e[t+3],e[t+4],e[t+5]])}setTransform(t){const e=this.usedElemNum-6,r=this.typedArray;r[e+0]=t[0],r[e+1]=t[1],r[e+2]=t[2],r[e+3]=t[3],r[e+4]=t[4],r[e+5]=t[5]}}class a extends s{constructor(t,e,r,i){super(t,Uint16Array,t.ELEMENT_ARRAY_BUFFER),this.setMaxSize(e*i);for(let t=0;t<i;t++)this.addObject(t*r);this.bindBuffer(),this.bufferData()}addObject(t){}}class h{constructor(t,e,r,i){this._r=t,this._g=e,this._b=r,this._a=i,this.updateUint()}get r(){return this._r}set r(t){this._r=t,this.updateUint()}get g(){return this._g}set g(t){this._g=t,this.updateUint()}get b(){return this._b}set b(t){this._b=t,this.updateUint()}get a(){return this._a}set a(t){this._a=t,this.updateUint()}updateUint(){this.uint32=(this._a<<24|this._b<<16|this._g<<8|this._r)>>>0}setRGBA(t,e,r,i){this.r=t,this.g=e,this.b=r,this.a=i,this.updateUint()}copy(t){this.setRGBA(t.r,t.g,t.b,t.a)}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b&&t.a===this.a}static fromHex(t){t.startsWith("#")&&(t=t.slice(1));const e=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);let s=255;return t.length>=8&&(s=parseInt(t.slice(6,8),16)),new h(e,r,i,s)}add(t){return new h(Math.min(this.r+t.r,255),Math.min(this.g+t.g,255),Math.min(this.b+t.b,255),Math.min(this.a+t.a,255))}subtract(t){return new h(Math.max(this.r-t.r,0),Math.max(this.g-t.g,0),Math.max(this.b-t.b,0),Math.max(this.a-t.a,0))}}class o{constructor(t,e){this.x=void 0!==t?t:0,this.y=void 0!==e?e:0}scalarMult(t){return this.x*=t,this.y*=t,this}perpendicular(){const t=this.x;return this.x=-this.y,this.y=t,this}invert(){return this.x=-this.x,this.y=-this.y,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}normalize(){const t=this.length();return this.x/=t,this.y/=t,this}angle(){return this.y/this.x}static Angle(t,e){return Math.atan2(e.y-t.y,e.x-t.x)}static Add(t,e){return new o(t.x+e.x,t.y+e.y)}static Sub(t,e){return new o(t.x-e.x,t.y-e.y)}static Middle(t,e){return o.Add(t,e).scalarMult(.5)}static FromArray(t){return t.map((t=>new o(t[0],t[1])))}}class u{constructor(t){this.cache=new Map,this.render=t}async textureFromUrl(t,e=!1){let r=this.cache.get(t);if(!r){const i=await this.loadImage(t);r=l.fromImageSource(this.render,i,e),this.cache.set(t,r)}return new c(r)}async loadImage(t){return new Promise((e=>{const r=new Image;r.onload=()=>{e(r)},r.src=t}))}createText(t){return new d(this.render,t)}}class l{constructor(t,e,r){this.texture=t,this.width=e,this.height=r}static fromImageSource(t,e,r=!1){return new l(function(t,e,r){const i=t.createTexture();if(t.bindTexture(t.TEXTURE_2D,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,r?t.LINEAR:t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,r?t.LINEAR:t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),!i)throw new Error("unable to create texture");return i}(t.gl,e,r),e.width,e.height)}}class c{constructor(t){this.scale=1,this.setBaseTextur(t)}setBaseTextur(t){t&&(this.base=t,this.setClipRegion(0,0,t.width,t.height))}setClipRegion(t,e,r,i){this.base&&(this.clipX=t/this.base.width,this.clipY=e/this.base.width,this.clipW=this.clipX+r/this.base.width,this.clipH=this.clipY+i/this.base.height,this.width=r*this.scale,this.height=i*this.scale)}static fromImageSource(t,e,r=!1){return new c(l.fromImageSource(t,e,r))}static fromUrl(t,e){return t.textures.textureFromUrl(e)}}class d extends c{constructor(t,e){super(),this.scale=.5,this.rapid=t,this.options=e,this.text=e.text||"",this.updateTextImage()}updateTextImage(){const t=this.createTextCanvas();this.setBaseTextur(l.fromImageSource(this.rapid,t,!0))}createTextCanvas(){const t=document.createElement("canvas"),e=t.getContext("2d");if(!e)throw new Error("Failed to get canvas context");e.font=`${this.options.fontSize||16}px ${this.options.fontFamily||"Arial"}`,e.fillStyle=this.options.color||"#000",e.textAlign=this.options.textAlign||"left",e.textBaseline=this.options.textBaseline||"top";const r=this.text.split("\n");let i=0,s=0;for(const t of r){const r=e.measureText(t);i=Math.max(i,r.width),s+=this.options.fontSize||16}t.width=2*i,t.height=2*s,e.scale(2,2),e.font=`${this.options.fontSize||16}px ${this.options.fontFamily||"Arial"}`,e.fillStyle=this.options.color||"#000",e.textAlign=this.options.textAlign||"left",e.textBaseline=this.options.textBaseline||"top";let n=0;for(const t of r)e.fillText(t,0,n),n+=this.options.fontSize||16;return t}setText(t){this.text!=t&&(this.text=t,this.updateTextImage())}}class p{constructor(t,r,i){this.attributeLoc={},this.uniformLoc={};const s=function(t,e){if(t.includes("%TEXTURE_NUM%")&&(t=t.replace("%TEXTURE_NUM%",e.toString())),t.includes("%GET_COLOR%")){let r="";for(let t=0;t<e;t++)r+=0==t?`if(vTextureId == ${t}.0)`:t==e-1?"else":`else if(vTextureId == ${t}.0)`,r+=`{color = texture2D(uTextures[${t}], vRegion);}`;t=t.replace("%GET_COLOR%",r)}return t}(i,t.maxTextureUnits);this.program=((t,r,i)=>{var s=t.createProgram(),n=e(t,r,35633),a=e(t,i,35632);if(!s)throw new Error("Unable to create program shader");if(t.attachShader(s,n),t.attachShader(s,a),t.linkProgram(s),!t.getProgramParameter(s,t.LINK_STATUS)){const e=t.getProgramInfoLog(s);throw new Error("Unable to link shader program: "+e)}return s})(t.gl,r,s),this.gl=t.gl,this.parseShader(r),this.parseShader(s)}setUniforms(t,e){var r;const i=this.gl;for(const s in t){const n=t[s],a=this.getUniform(s);if(n instanceof c&&(null===(r=n.base)||void 0===r?void 0:r.texture))i.activeTexture(i.TEXTURE0+e),i.bindTexture(i.TEXTURE_2D,n.base.texture),i.uniform1i(a,e),e+=1;else if("number"==typeof n)i.uniform1f(a,n);else if(Array.isArray(n))switch(n.length){case 1:Number.isInteger(n[0])?i.uniform1i(a,n[0]):i.uniform1f(a,n[0]);break;case 2:Number.isInteger(n[0])?i.uniform2iv(a,n):i.uniform2fv(a,n);break;case 3:Number.isInteger(n[0])?i.uniform3iv(a,n):i.uniform3fv(a,n);break;case 4:Number.isInteger(n[0])?i.uniform4iv(a,n):i.uniform4fv(a,n);break;case 9:i.uniformMatrix3fv(a,!1,n);break;case 16:i.uniformMatrix4fv(a,!1,n);break;default:console.error(`Unsupported uniform array length for ${s}:`,n.length)}else"boolean"==typeof n?i.uniform1i(a,n?1:0):console.error(`Unsupported uniform type for ${s}:`,typeof n)}}getUniform(t){return this.uniformLoc[t]}use(){this.gl.useProgram(this.program)}parseShader(t){const e=this.gl,r=t.match(/attribute\s+\w+\s+(\w+)/g);if(r)for(const t of r){const r=t.split(" ")[2],i=e.getAttribLocation(this.program,r);-1!=i&&(this.attributeLoc[r]=i)}const i=t.match(/uniform\s+\w+\s+(\w+)/g);if(i)for(const t of i){const r=t.split(" ")[2];this.uniformLoc[r]=e.getUniformLocation(this.program,r)}}setAttribute(t){const e=this.attributeLoc[t.name];if(void 0!==e){const r=this.gl;r.vertexAttribPointer(e,t.size,t.type,t.normalized||!1,t.stride,t.offset||0),r.enableVertexAttribArray(e)}}}class f{constructor(t,e){this.usedTextures=[],this.needBind=new Set,this.attribute=e,this.rapid=t,this.gl=t.gl,this.webglArrayBuffer=new s(t.gl,Float32Array,t.gl.ARRAY_BUFFER),this.TEXTURE_UNITS_ARRAY=Array.from({length:t.maxTextureUnits},((t,e)=>e))}addVertex(t,e,...r){const[i,s]=this.rapid.transformPoint(t,e);this.webglArrayBuffer.push(i),this.webglArrayBuffer.push(s)}useTexture(t){let e=this.usedTextures.indexOf(t);return-1===e&&(this.usedTextures.length>=this.rapid.maxTextureUnits&&this.render(),this.usedTextures.push(t),e=this.usedTextures.length-1,this.needBind.add(e)),e}enterRegion(t){this.currentShader=null!=t?t:this.defaultShader,this.currentShader.use(),this.initializeForNextRender(),this.webglArrayBuffer.bindBuffer();for(const t of this.attribute)this.currentShader.setAttribute(t);this.gl.uniformMatrix4fv(this.currentShader.uniformLoc.uProjectionMatrix,!1,this.rapid.projection)}exitRegion(){}initDefaultShader(t,e){this.webglArrayBuffer.bindBuffer(),this.defaultShader=new p(this.rapid,t,e)}render(){this.executeRender(),this.initializeForNextRender()}executeRender(){this.webglArrayBuffer.bufferData();const t=this.gl;for(const e of this.needBind)t.activeTexture(t.TEXTURE0+e),t.bindTexture(t.TEXTURE_2D,this.usedTextures[e]);this.needBind.clear()}initializeForNextRender(){this.webglArrayBuffer.clear(),this.usedTextures=[]}hasPendingContent(){return!1}}class g extends f{constructor(t){super(t,m),this.vertex=0,this.drawType=t.gl.TRIANGLE_FAN,this.initDefaultShader("precision mediump float;\r\n\r\nattribute vec2 aPosition;\r\nattribute vec4 aColor;\r\nattribute vec2 aRegion;\r\n\r\nvarying vec4 vColor;\r\nuniform mat4 uProjectionMatrix;\r\nuniform vec4 uColor;\r\nvarying vec2 vRegion;\r\n\r\nvoid main(void) {\r\n gl_Position = uProjectionMatrix * vec4(aPosition, 0.0, 1.0);\r\n vColor = aColor;\r\n vRegion = aRegion;\r\n}\r\n","precision mediump float;\r\nvarying vec2 vRegion;\r\nvarying vec4 vColor;\r\n\r\nuniform sampler2D uTexture;\r\nuniform int uUseTexture;\r\n\r\nvoid main(void) {\r\n if(uUseTexture > 0){\r\n gl_FragColor = texture2D(uTexture, vRegion) * vColor;\r\n }else{\r\n gl_FragColor = vColor;\r\n }\r\n}\r\n")}startRender(t){this.vertex=0,this.webglArrayBuffer.clear(),t&&t.base&&(this.texture=this.useTexture(t.base.texture))}addVertex(t,e,r,i,s){this.webglArrayBuffer.resize(3),super.addVertex(t,e),this.webglArrayBuffer.pushUint(s),this.webglArrayBuffer.push(r),this.webglArrayBuffer.push(i),this.vertex+=1}executeRender(){super.executeRender();const t=this.gl;t.uniform1i(this.currentShader.uniformLoc.uUseTexture,void 0===this.texture?0:1),this.texture&&t.uniform1i(this.currentShader.uniformLoc.uTexture,this.texture),t.drawArrays(this.drawType,0,this.vertex),this.drawType=this.rapid.gl.TRIANGLE_FAN,this.vertex=0,this.texture=void 0}}const m=[{name:"aPosition",size:2,type:r,stride:20},{name:"aColor",size:4,type:5121,stride:20,offset:2*Float32Array.BYTES_PER_ELEMENT,normalized:!0},{name:"aRegion",size:2,type:r,stride:20,offset:3*Float32Array.BYTES_PER_ELEMENT}];class x extends a{constructor(t,e){super(t,6,4,e)}addObject(t){super.addObject(),this.push(t),this.push(t+3),this.push(t+2),this.push(t),this.push(t+1),this.push(t+2)}}class y extends f{constructor(t){const e=t.gl;super(t,T),this.batchSprite=0,this.initDefaultShader("precision mediump float;\r\n\r\nattribute vec2 aPosition;\r\nattribute vec2 aRegion;\r\nattribute float aTextureId;\r\nattribute vec4 aColor;\r\n\r\nuniform mat4 uProjectionMatrix;\r\n\r\nvarying vec2 vRegion;\r\nvarying float vTextureId;\r\nvarying vec4 vColor;\r\n\r\nvoid main(void) {\r\n vRegion = aRegion;\r\n vTextureId = aTextureId;\r\n vColor = aColor;\r\n gl_Position = uProjectionMatrix * vec4(aPosition, 0.0, 1.0);\r\n}","precision mediump float;\r\nuniform sampler2D uTextures[%TEXTURE_NUM%];\r\n\r\nvarying vec2 vRegion;\r\nvarying float vTextureId;\r\nvarying vec4 vColor;\r\n\r\nvoid main(void) {\r\n vec4 color;\r\n %GET_COLOR%\r\n\r\n gl_FragColor = color*vColor;\r\n}"),this.MAX_BATCH=Math.floor(16384),this.indexBuffer=new x(e,this.MAX_BATCH)}addVertex(t,e,r,i,s,n){super.addVertex(t,e),this.webglArrayBuffer.push(r),this.webglArrayBuffer.push(i),this.webglArrayBuffer.push(s),this.webglArrayBuffer.pushUint(n)}renderSprite(t,e,r,i,s,n,a,h,o,u,l){var c;l&&(null===(c=this.currentShader)||void 0===c||c.setUniforms(l,1)),this.batchSprite>=this.MAX_BATCH&&this.render(),this.batchSprite++,this.webglArrayBuffer.resize(24);const d=this.useTexture(t),p=h+e,f=o+r,g=i+n,m=s+a;this.addVertex(h,o,i,s,d,u),this.addVertex(p,o,g,s,d,u),this.addVertex(p,f,g,m,d,u),this.addVertex(h,f,i,m,d,u)}executeRender(){super.executeRender();const t=this.gl;t.drawElements(t.TRIANGLES,6*this.batchSprite,t.UNSIGNED_SHORT,0)}enterRegion(t){super.enterRegion(t),this.indexBuffer.bindBuffer(),this.gl.uniform1iv(this.currentShader.uniformLoc.uTextures,this.TEXTURE_UNITS_ARRAY)}initializeForNextRender(){super.initializeForNextRender(),this.batchSprite=0}hasPendingContent(){return this.batchSprite>0}}const T=[{name:"aPosition",size:2,type:r,stride:24},{name:"aRegion",size:2,type:r,stride:24,offset:2*Float32Array.BYTES_PER_ELEMENT},{name:"aTextureId",size:1,type:r,stride:24,offset:4*Float32Array.BYTES_PER_ELEMENT},{name:"aColor",size:4,type:5121,stride:24,offset:5*Float32Array.BYTES_PER_ELEMENT,normalized:!0}];var E,A,b,R;t.JoinTyps=void 0,(E=t.JoinTyps||(t.JoinTyps={}))[E.BEVEL=0]="BEVEL",E[E.ROUND=1]="ROUND",E[E.MITER=2]="MITER",t.CapTyps=void 0,(A=t.CapTyps||(t.CapTyps={}))[A.BUTT=0]="BUTT",A[A.ROUND=1]="ROUND",A[A.SQUARE=2]="SQUARE",t.RenderStatus=void 0,(b=t.RenderStatus||(t.RenderStatus={}))[b.NORMAL=0]="NORMAL",b[b.MASK=1]="MASK",t.MaskType=void 0,(R=t.MaskType||(t.MaskType={})).Normal="normal",R.Inverse="inverse";const v=1e-4,S=(t,e,r,i)=>{i.push(t),i.push(o.Add(t,r)),i.push(o.Add(e,r)),i.push(e),i.push(o.Add(e,r)),i.push(t)},w=(t,e,r,i,s)=>{const n=o.Sub(t,e).length();let a=Math.atan2(r.y-t.y,r.x-t.x),h=Math.atan2(e.y-t.y,e.x-t.x);const u=a;h>a?h-a>=Math.PI-v&&(h-=2*Math.PI):a-h>=Math.PI-v&&(a-=2*Math.PI);let l=h-a;if(Math.abs(l)>=Math.PI-v&&Math.abs(l)<=Math.PI+v){const e=o.Sub(t,i);0===e.x?e.y>0&&(l=-l):e.x>=-1e-4&&(l=-l)}const c=(Math.abs(l*n)/7|0)+1,d=l/c;for(let e=0;e<c;e++)s.push(new o(t.x,t.y)),s.push(new o(t.x+n*Math.cos(u+d*e),t.y+n*Math.sin(u+d*e))),s.push(new o(t.x+n*Math.cos(u+d*(1+e)),t.y+n*Math.sin(u+d*(1+e))))},M=(e,r,i,s,n,a,h)=>{const u=o.Sub(r,e).perpendicular(),l=o.Sub(i,r).perpendicular();((t,e,r)=>(e.x-t.x)*(r.y-t.y)-(r.x-t.x)*(e.y-t.y))(e,r,i)>0&&(u.invert(),l.invert()),u.normalize().scalarMult(n),l.normalize().scalarMult(n);const c=((t,e,r,i)=>{const s=e.y-t.y,n=t.x-e.x,a=i.y-r.y,h=r.x-i.x,u=s*h-a*n;if(u>-1e-4&&u<v)return null;{const e=s*t.x+n*t.y,i=a*r.x+h*r.y;return new o((h*e-n*i)/u,(s*i-a*e)/u)}})(o.Add(u,e),o.Add(u,r),o.Add(l,i),o.Add(l,r));let d=null,p=Number.MAX_VALUE;c&&(d=o.Sub(c,r),p=d.length());const f=p/n|0,g=o.Sub(e,r).length(),m=o.Sub(r,i).length();if(p>g||p>m)s.push(o.Add(e,u)),s.push(o.Sub(e,u)),s.push(o.Add(r,u)),s.push(o.Sub(e,u)),s.push(o.Add(r,u)),s.push(o.Sub(r,u)),a===t.JoinTyps.ROUND?w(r,o.Add(r,u),o.Add(r,l),i,s):a===t.JoinTyps.BEVEL||a===t.JoinTyps.MITER&&f>=h?(s.push(r),s.push(o.Add(r,u)),s.push(o.Add(r,l))):a===t.JoinTyps.MITER&&f<h&&c&&(s.push(o.Add(r,u)),s.push(r),s.push(c),s.push(o.Add(r,l)),s.push(r),s.push(c)),s.push(o.Add(i,l)),s.push(o.Sub(r,l)),s.push(o.Add(r,l)),s.push(o.Add(i,l)),s.push(o.Sub(r,l)),s.push(o.Sub(i,l));else{if(s.push(o.Add(e,u)),s.push(o.Sub(e,u)),s.push(o.Sub(r,d)),s.push(o.Add(e,u)),s.push(o.Sub(r,d)),s.push(o.Add(r,u)),a===t.JoinTyps.ROUND){const t=o.Add(r,u),e=o.Add(r,l),i=o.Sub(r,d),n=r;s.push(t),s.push(n),s.push(i),w(n,t,e,i,s),s.push(n),s.push(e),s.push(i)}else(a===t.JoinTyps.BEVEL||a===t.JoinTyps.MITER&&f>=h)&&(s.push(o.Add(r,u)),s.push(o.Add(r,l)),s.push(o.Sub(r,d))),a===t.JoinTyps.MITER&&f<h&&(s.push(c),s.push(o.Add(r,u)),s.push(o.Add(r,l)));s.push(o.Add(i,l)),s.push(o.Sub(r,d)),s.push(o.Add(r,l)),s.push(o.Add(i,l)),s.push(o.Sub(r,d)),s.push(o.Sub(i,l))}};return t.BaseTexture=l,t.Color=h,t.DynamicArrayBuffer=i,t.GLShader=p,t.MatrixStack=n,t.Rapid=class{constructor(t){this.projectionDirty=!0,this.matrixStack=new n,this.textures=new u(this),this.devicePixelRatio=window.devicePixelRatio||1,this.defaultColor=new h(255,255,255,255),this.regions=new Map;const e=(t=>{const e={stencil:!0},r=t.getContext("webgl2",e)||t.getContext("webgl",e);if(!r)throw new Error("Unable to initialize WebGL. Your browser may not support it.");return r})(t.canvas);this.gl=e,this.canvas=t.canvas,this.maxTextureUnits=e.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS),this.width=t.width||this.canvas.width,this.height=t.width||this.canvas.height,this.backgroundColor=t.backgroundColor||new h(255,255,255,255),this.registerBuildInRegion(),this.initWebgl(e)}initWebgl(t){this.resize(this.width,this.height),t.enable(t.BLEND),t.disable(t.DEPTH_TEST),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),t.enable(t.STENCIL_TEST)}registerBuildInRegion(){this.registerRegion("sprite",y),this.registerRegion("graphic",g)}registerRegion(t,e){this.regions.set(t,new e(this))}quitCurrentRegion(){this.currentRegion&&this.currentRegion.hasPendingContent()&&(this.currentRegion.render(),this.currentRegion.exitRegion())}setRegion(t,e){if(t!=this.currentRegionName||e&&e!==this.currentRegion.currentShader){const r=this.regions.get(t);this.quitCurrentRegion(),this.currentRegion=r,this.currentRegionName=t,r.enterRegion(e)}}save(){this.matrixStack.pushMat()}restore(){this.matrixStack.popMat()}startRender(t=!0){this.clear(),t&&this.matrixStack.clear(),this.matrixStack.pushIdentity(),this.currentRegion=void 0,this.currentRegionName=void 0}endRender(){var t;null===(t=this.currentRegion)||void 0===t||t.render(),this.projectionDirty=!1}renderSprite(t,e=0,r=0,i){if(t.base){if(i instanceof h)return this.renderSprite(t,e,r,{color:i});this.setRegion("sprite",null==i?void 0:i.shader),this.currentRegion.renderSprite(t.base.texture,t.width,t.height,t.clipX,t.clipY,t.clipW,t.clipH,e,r,((null==i?void 0:i.color)||this.defaultColor).uint32,null==i?void 0:i.uniforms)}}renderLine(e=0,r=0,i){const s=((e,r)=>{if(e.length<2)return[];let i=r.cap||t.CapTyps.BUTT,s=r.join||t.JoinTyps.BEVEL,n=(r.width||1)/2,a=r.miterLimit||10,h=[],u=[];if(2===e.length)s=t.JoinTyps.BEVEL,M(e[0],o.Middle(e[0],e[1]),e[1],h,n,s,a);else{for(let t=0;t<e.length-1;t++)0===t?u.push(e[0]):t===e.length-2?u.push(e[e.length-1]):u.push(o.Middle(e[t],e[t+1]));for(let t=1;t<u.length;t++)M(u[t-1],e[t],u[t],h,n,s,a)}if(i===t.CapTyps.ROUND){let t=h[0],r=h[1],i=e[1],s=h[h.length-1],n=h[h.length-3],a=e[e.length-2];w(e[0],t,r,i,h),w(e[e.length-1],s,n,a,h)}else if(i===t.CapTyps.SQUARE){let t=h[h.length-1],r=h[h.length-3];S(h[0],h[1],o.Sub(e[0],e[1]).normalize().scalarMult(o.Sub(e[0],h[0]).length()),h),S(t,r,o.Sub(e[e.length-1],e[e.length-2]).normalize().scalarMult(o.Sub(r,e[e.length-1]).length()),h)}return h})(i.points,i);this.renderGraphic(e,r,{color:i.color,drawType:this.gl.TRIANGLES,points:s})}renderGraphic(t=0,e=0,r){if(r instanceof Array)return this.renderGraphic(t,e,{points:r});this.setRegion("graphic",r.shader);const i=this.currentRegion;i.startRender(r.texture),r.drawType&&(i.drawType=r.drawType),r.points.forEach(((s,n)=>{var a;const h=r.color instanceof Array?r.color[n]:r.color,o=null===(a=r.uv)||void 0===a?void 0:a[n];i.addVertex(s.x+t,s.y+e,null==o?void 0:o.x,null==o?void 0:o.y,(h||this.defaultColor).uint32)})),i.render()}renderRect(t,e,r,i,s=this.defaultColor){const n=[new o(0,0),new o(r,0),new o(r,i),new o(0,i)];this.renderGraphic(t,e,{points:n,color:s,drawType:this.gl.TRIANGLE_FAN})}renderCircle(t,e,r,i=this.defaultColor,s=32){const n=[];for(let t=0;t<=s;t++){const e=t/s*Math.PI*2,i=Math.cos(e)*r,a=Math.sin(e)*r;n.push(new o(i,a))}this.renderGraphic(t,e,{points:n,color:i,drawType:this.gl.TRIANGLE_FAN})}resize(t,e){this.width=t,this.height=e;const r=t*this.devicePixelRatio,i=e*this.devicePixelRatio;this.canvas.width=r,this.canvas.height=i,this.gl.viewport(0,0,r,i),this.projection=this.createOrthMatrix(0,t,e,0),this.projectionDirty=!0}clear(){const t=this.gl,e=this.backgroundColor;t.clearColor(e.r,e.g,e.b,e.a),t.clear(t.COLOR_BUFFER_BIT),this.clearMask()}createOrthMatrix(t,e,r,i){return new Float32Array([2/(e-t),0,0,0,0,2/(i-r),0,0,0,0,-1,0,-(e+t)/(e-t),-(i+r)/(i-r),0,1])}transformPoint(t,e){return this.matrixStack.apply(t,e)}startDrawMask(){const t=this.gl;this.quitCurrentRegion(),t.clearStencil(0),t.clear(t.STENCIL_BUFFER_BIT),t.stencilFunc(t.ALWAYS,1,255),t.stencilOp(t.KEEP,t.KEEP,t.REPLACE),t.colorMask(!1,!1,!1,!1)}endDrawMask(e=t.MaskType.Normal){const r=this.gl;this.quitCurrentRegion(),this.setMaskType(e),r.stencilOp(r.KEEP,r.KEEP,r.KEEP),r.colorMask(!0,!0,!0,!0)}setMaskType(e){const r=this.gl;switch(this.quitCurrentRegion(),e){case t.MaskType.Normal:r.stencilFunc(r.EQUAL,1,255);break;case t.MaskType.Inverse:r.stencilFunc(r.NOTEQUAL,1,255)}}clearMask(){const t=this.gl;t.clear(t.STENCIL_BUFFER_BIT)}},t.SCALEFACTOR=2,t.Text=d,t.Texture=c,t.TextureCache=u,t.Vec2=o,t.WebglBufferArray=s,t.WebglElementBufferArray=a,t.graphicAttributes=m,t.spriteAttributes=T,t}({});
|