rapid-render 0.1.13 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import Rapid from "./render";
2
- import GLShader from "./webgl/glshader";
3
- import { Text } from "./texture";
4
- import { TileMapRender, TileSet } from "./tilemap";
5
- import { Uniform } from "./webgl/uniform";
6
- import { spriteAttributes, graphicAttributes } from "./regions/attributes";
7
- import { ParticleEmitter } from "./particle";
8
- export { Text, Rapid, GLShader, TileMapRender, TileSet, Uniform, ParticleEmitter, graphicAttributes, spriteAttributes, };
9
- export * from "./math";
10
- export * from "./interface";
11
- export * from "./texture";
12
- export * from "./render";
13
- export * from "./particle";
1
+ import Rapid from "./render";
2
+ import GLShader from "./webgl/glshader";
3
+ import { Text } from "./texture";
4
+ import { TileMapRender, TileSet } from "./tilemap";
5
+ import { Uniform } from "./webgl/uniform";
6
+ import { spriteAttributes, graphicAttributes } from "./regions/attributes";
7
+ import { ParticleEmitter } from "./particle";
8
+ export { Text, Rapid, GLShader, TileMapRender, TileSet, Uniform, ParticleEmitter, graphicAttributes, spriteAttributes, };
9
+ export * from "./math";
10
+ export * from "./interface";
11
+ export * from "./texture";
12
+ export * from "./render";
13
+ export * from "./particle";
@@ -1,312 +1,315 @@
1
- import { Color, Vec2 } from "./math";
2
- import { Texture } from "./texture";
3
- import { TileSet } from "./tilemap";
4
- import GLShader from "./webgl/glshader";
5
- import { Uniform } from "./webgl/uniform";
6
- /**
7
- * @ignore
8
- */
9
- export type WebGLContext = WebGL2RenderingContext | WebGLRenderingContext;
10
- /**
11
- * @ignore
12
- */
13
- export interface IMathStruct<T> {
14
- clone(obj: T): T;
15
- copy(obj: T): void;
16
- equal(obj: T): boolean;
17
- }
18
- export interface IRapidOptions {
19
- canvas: HTMLCanvasElement;
20
- width?: number;
21
- height?: number;
22
- backgroundColor?: Color;
23
- antialias?: boolean;
24
- }
25
- export interface IAttribute {
26
- name: string;
27
- size: number;
28
- type: number;
29
- normalized?: boolean;
30
- stride: number;
31
- offset?: number;
32
- }
33
- export interface ITransformOptions {
34
- position?: Vec2;
35
- scale?: Vec2 | number;
36
- rotation?: number;
37
- offset?: Vec2;
38
- x?: number;
39
- y?: number;
40
- offsetX?: number;
41
- offsetY?: number;
42
- origin?: Vec2 | number;
43
- restoreTransform?: boolean;
44
- saveTransform?: boolean;
45
- afterSave?(): unknown;
46
- beforRestore?(): unknown;
47
- }
48
- export interface ISpriteRenderOptions extends ITransformOptions, IShaderRenderOptions {
49
- color?: Color;
50
- texture?: Texture;
51
- offset?: Vec2;
52
- flipX?: boolean;
53
- flipY?: boolean;
54
- }
55
- export interface ITextTextureOptions {
56
- /**
57
- * The text string to be rendered.
58
- */
59
- text?: string;
60
- /**
61
- * The font size for the text.
62
- * Default is 16.
63
- */
64
- fontSize?: number;
65
- /**
66
- * The font family for the text.
67
- * Default is 'Arial'.
68
- */
69
- fontFamily?: string;
70
- /**
71
- * The color of the text.
72
- * Default is '#000000' (black).
73
- */
74
- color?: string;
75
- /**
76
- * The alignment of the text.
77
- * Possible values: 'left', 'right', 'center', 'start', 'end'.
78
- * Default is 'left'.
79
- */
80
- textAlign?: CanvasTextAlign;
81
- /**
82
- * The baseline of the text.
83
- * Possible values: 'top', 'hanging', 'middle', 'alphabetic', 'ideographic', 'bottom'.
84
- * Default is 'top'.
85
- */
86
- textBaseline?: CanvasTextBaseline;
87
- }
88
- export interface ILineRenderOptions extends IGraphicRenderOptions {
89
- width?: number;
90
- closed?: boolean;
91
- roundCap?: boolean;
92
- textureMode?: LineTextureMode;
93
- }
94
- export declare enum LineTextureMode {
95
- STRETCH = "stretch",
96
- REPEAT = "repeat"
97
- }
98
- export declare enum TextureWrapMode {
99
- REPEAT = "repeat",
100
- CLAMP = "clamp",
101
- MIRROR = "mirror"
102
- }
103
- export interface IRenderLineOptions extends ILineRenderOptions, ITransformOptions {
104
- }
105
- export interface IGraphicRenderOptions extends ITransformOptions, IShaderRenderOptions {
106
- points: Vec2[];
107
- color?: Color | Color[];
108
- drawType?: number;
109
- uv?: Vec2[];
110
- texture?: Texture;
111
- }
112
- export interface ICircleRenderOptions extends IGraphicRenderOptions {
113
- radius: number;
114
- segments?: number;
115
- }
116
- export interface IRectRenderOptions extends IGraphicRenderOptions {
117
- width: number;
118
- height: number;
119
- }
120
- export declare enum MaskType {
121
- Include = "normal",
122
- Exclude = "inverse"
123
- }
124
- export type UniformType = Record<string, number | Array<any> | boolean | Texture>;
125
- export type Images = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas;
126
- export interface IRegisterTileOptions extends ISpriteRenderOptions {
127
- texture: Texture;
128
- offsetX?: number;
129
- offsetY?: number;
130
- ySortOffset?: number;
131
- }
132
- export interface YSortCallback {
133
- ySort: number;
134
- render?: () => void;
135
- renderSprite?: ISpriteRenderOptions;
136
- }
137
- export interface ILayerRenderOptions extends ITransformOptions {
138
- error?: number | Vec2;
139
- errorX?: number;
140
- errorY?: number;
141
- ySortCallback?: Array<YSortCallback>;
142
- shape?: TilemapShape;
143
- tileSet: TileSet;
144
- eachTile?: (tileId: string | number, mapX: number, mapY: number) => ISpriteRenderOptions | undefined | void;
145
- }
146
- export interface IShaderRenderOptions {
147
- shader?: GLShader;
148
- uniforms?: Uniform;
149
- }
150
- export declare enum TilemapShape {
151
- SQUARE = "square",
152
- ISOMETRIC = "isometric"
153
- }
154
- export declare enum ShaderType {
155
- SPRITE = "sprite",
156
- GRAPHIC = "graphic"
157
- }
158
- export declare enum BlendMode {
159
- Additive = "additive",
160
- Subtractive = "subtractive",
161
- Mix = "mix"
162
- }
163
- /**
164
- * Interface for light rendering options
165
- */
166
- export interface ILightRenderOptions {
167
- /** Position of the light source */
168
- lightSource: Vec2;
169
- /** Array of vertex arrays for occlusion objects, each occlusion object is defined by a set of vertices */
170
- occlusion: Vec2[][];
171
- /** Base projection length that controls shadow length */
172
- baseProjectionLength?: number;
173
- /** Type of mask to apply */
174
- type?: MaskType;
175
- }
176
- export interface ICameraOptions extends ITransformOptions {
177
- }
178
- /**
179
- * Defines particle emitter shape types
180
- */
181
- export declare enum ParticleShape {
182
- /**
183
- * Point emitter, emits particles from a single point
184
- */
185
- POINT = "point",
186
- /**
187
- * Circle emitter, emits particles randomly from a circular area
188
- */
189
- CIRCLE = "circle",
190
- /**
191
- * Rectangle emitter, emits particles randomly from a rectangular area
192
- */
193
- RECT = "rect"
194
- }
195
- /**
196
- * Defines particle attribute animation
197
- * @template T Attribute type, can be number, vector or color
198
- */
199
- export interface ParticleAttribute<T extends number | Vec2 | Color> {
200
- /**
201
- * Damping coefficient, controls attribute decay rate over time
202
- */
203
- damping?: number;
204
- /**
205
- * Initial attribute value
206
- */
207
- start: T;
208
- /**
209
- * Final attribute value, uses initial value if not specified
210
- */
211
- end?: T;
212
- /**
213
- * Attribute change rate, automatically calculated from start and end if not specified
214
- */
215
- delta?: T;
216
- }
217
- /**
218
- * Particle system configuration options
219
- */
220
- export interface IParticleOptions extends ITransformOptions, IShaderRenderOptions {
221
- /**
222
- * Particle texture, can be a single texture, array of textures, or weighted texture array
223
- */
224
- texture: Texture | Texture[] | [Texture, number][];
225
- /**
226
- * Particle emission rate (particles per second)
227
- */
228
- emitRate?: number;
229
- /**
230
- * Emission time interval in seconds
231
- */
232
- emitTime?: number;
233
- /**
234
- * Maximum number of particles limit
235
- */
236
- maxParticles?: number;
237
- /**
238
- * Particle lifetime in seconds, can be fixed value or range
239
- */
240
- life?: number | [number, number];
241
- /**
242
- * Particle animation properties collection
243
- */
244
- animation: {
245
- /**
246
- * Velocity vector, controls particle movement direction and speed
247
- */
248
- velocity?: ParticleAttribute<Vec2>;
249
- /**
250
- * Acceleration vector, controls particle velocity changes
251
- */
252
- acceleration?: ParticleAttribute<Vec2>;
253
- /**
254
- * Speed scalar, used in combination with rotation direction
255
- */
256
- speed?: ParticleAttribute<number>;
257
- /**
258
- * Scale factor, controls particle size
259
- */
260
- scale?: ParticleAttribute<number>;
261
- /**
262
- * Rotation angle (in radians)
263
- */
264
- rotation?: ParticleAttribute<number>;
265
- /**
266
- * Color and transparency
267
- */
268
- color?: ParticleAttribute<Color>;
269
- };
270
- /**
271
- * Emitter shape
272
- */
273
- emitShape?: ParticleShape;
274
- /**
275
- * Circular emitter radius
276
- */
277
- emitRadius?: number;
278
- /**
279
- * Rectangular emitter dimensions
280
- */
281
- emitRect?: {
282
- width: number;
283
- height: number;
284
- };
285
- /**
286
- * Whether to use local coordinate system, true means particles are relative to emitter position,
287
- * false means using global coordinates
288
- */
289
- localSpace?: boolean;
290
- }
291
- /**
292
- * Particle attribute data types
293
- */
294
- export type ParticleAttributeTypes = number | Vec2 | Color;
295
- /**
296
- * Particle attribute runtime data
297
- * @template T Attribute type
298
- */
299
- export type ParticleAttributeData<T extends ParticleAttributeTypes> = {
300
- /**
301
- * Attribute change rate per second
302
- */
303
- delta?: T;
304
- /**
305
- * Current attribute value
306
- */
307
- value: T;
308
- /**
309
- * Damping coefficient
310
- */
311
- damping?: number;
312
- };
1
+ import { Color, Vec2 } from "./math";
2
+ import { Texture } from "./texture";
3
+ import { TileSet } from "./tilemap";
4
+ import GLShader from "./webgl/glshader";
5
+ import { Uniform } from "./webgl/uniform";
6
+ /**
7
+ * @ignore
8
+ */
9
+ export type WebGLContext = WebGL2RenderingContext | WebGLRenderingContext;
10
+ /**
11
+ * @ignore
12
+ */
13
+ export interface IMathStruct<T> {
14
+ clone(obj: T): T;
15
+ copy(obj: T): void;
16
+ equal(obj: T): boolean;
17
+ }
18
+ export interface IRapidOptions {
19
+ canvas: HTMLCanvasElement;
20
+ width?: number;
21
+ height?: number;
22
+ backgroundColor?: Color;
23
+ antialias?: boolean;
24
+ }
25
+ export interface IAttribute {
26
+ name: string;
27
+ size: number;
28
+ type: number;
29
+ normalized?: boolean;
30
+ stride: number;
31
+ offset?: number;
32
+ }
33
+ export interface ITransformOptions {
34
+ position?: Vec2;
35
+ scale?: Vec2 | number;
36
+ rotation?: number;
37
+ offset?: Vec2;
38
+ x?: number;
39
+ y?: number;
40
+ offsetX?: number;
41
+ offsetY?: number;
42
+ origin?: Vec2 | number;
43
+ restoreTransform?: boolean;
44
+ saveTransform?: boolean;
45
+ afterSave?(): unknown;
46
+ beforRestore?(): unknown;
47
+ }
48
+ export interface ISpriteRenderOptions extends ITransformOptions, IShaderRenderOptions {
49
+ color?: Color;
50
+ texture?: Texture;
51
+ offset?: Vec2;
52
+ flipX?: boolean;
53
+ flipY?: boolean;
54
+ }
55
+ export interface ITextTextureOptions {
56
+ /**
57
+ * The text string to be rendered.
58
+ */
59
+ text?: string;
60
+ /**
61
+ * The font size for the text.
62
+ * Default is 16.
63
+ */
64
+ fontSize?: number;
65
+ /**
66
+ * The font family for the text.
67
+ * Default is 'Arial'.
68
+ */
69
+ fontFamily?: string;
70
+ /**
71
+ * The color of the text.
72
+ * Default is '#000000' (black).
73
+ */
74
+ color?: string;
75
+ /**
76
+ * The alignment of the text.
77
+ * Possible values: 'left', 'right', 'center', 'start', 'end'.
78
+ * Default is 'left'.
79
+ */
80
+ textAlign?: CanvasTextAlign;
81
+ /**
82
+ * The baseline of the text.
83
+ * Possible values: 'top', 'hanging', 'middle', 'alphabetic', 'ideographic', 'bottom'.
84
+ * Default is 'top'.
85
+ */
86
+ textBaseline?: CanvasTextBaseline;
87
+ }
88
+ export interface ILineStyleOptions extends IGraphicRenderOptions {
89
+ width?: number;
90
+ closed?: boolean;
91
+ roundCap?: boolean;
92
+ textureMode?: LineTextureMode;
93
+ points: Vec2[];
94
+ }
95
+ export declare enum LineTextureMode {
96
+ STRETCH = "stretch",
97
+ REPEAT = "repeat"
98
+ }
99
+ export declare enum TextureWrapMode {
100
+ REPEAT = "repeat",
101
+ CLAMP = "clamp",
102
+ MIRROR = "mirror"
103
+ }
104
+ export interface IRenderLineOptions extends ILineStyleOptions, ITransformOptions {
105
+ }
106
+ export interface IGraphicRenderOptions extends ITransformOptions, IShaderRenderOptions {
107
+ color?: Color | Color[];
108
+ drawType?: number;
109
+ uv?: Vec2[];
110
+ texture?: Texture;
111
+ }
112
+ export interface IPolygonGraphicRenderOptions extends IGraphicRenderOptions {
113
+ points: Vec2[];
114
+ }
115
+ export interface ICircleRenderOptions extends IGraphicRenderOptions {
116
+ radius: number;
117
+ segments?: number;
118
+ }
119
+ export interface IRectRenderOptions extends IGraphicRenderOptions {
120
+ width: number;
121
+ height: number;
122
+ }
123
+ export declare enum MaskType {
124
+ Include = "normal",
125
+ Exclude = "inverse"
126
+ }
127
+ export type UniformType = Record<string, number | Array<any> | boolean | Texture>;
128
+ export type Images = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas;
129
+ export interface IRegisterTileOptions extends ISpriteRenderOptions {
130
+ texture: Texture;
131
+ offsetX?: number;
132
+ offsetY?: number;
133
+ ySortOffset?: number;
134
+ }
135
+ export interface YSortCallback {
136
+ ySort: number;
137
+ render?: () => void;
138
+ renderSprite?: ISpriteRenderOptions;
139
+ }
140
+ export interface ILayerRenderOptions extends ITransformOptions {
141
+ error?: number | Vec2;
142
+ errorX?: number;
143
+ errorY?: number;
144
+ ySortCallback?: Array<YSortCallback>;
145
+ shape?: TilemapShape;
146
+ tileSet: TileSet;
147
+ eachTile?: (tileId: string | number, mapX: number, mapY: number) => ISpriteRenderOptions | undefined | void;
148
+ }
149
+ export interface IShaderRenderOptions {
150
+ shader?: GLShader;
151
+ uniforms?: Uniform;
152
+ }
153
+ export declare enum TilemapShape {
154
+ SQUARE = "square",
155
+ ISOMETRIC = "isometric"
156
+ }
157
+ export declare enum ShaderType {
158
+ SPRITE = "sprite",
159
+ GRAPHIC = "graphic"
160
+ }
161
+ export declare enum BlendMode {
162
+ Additive = "additive",
163
+ Subtractive = "subtractive",
164
+ Mix = "mix"
165
+ }
166
+ /**
167
+ * Interface for light rendering options
168
+ */
169
+ export interface ILightRenderOptions {
170
+ /** Position of the light source */
171
+ lightSource: Vec2;
172
+ /** Array of vertex arrays for occlusion objects, each occlusion object is defined by a set of vertices */
173
+ occlusion: Vec2[][];
174
+ /** Base projection length that controls shadow length */
175
+ baseProjectionLength?: number;
176
+ /** Type of mask to apply */
177
+ type?: MaskType;
178
+ }
179
+ export interface ICameraOptions extends ITransformOptions {
180
+ }
181
+ /**
182
+ * Defines particle emitter shape types
183
+ */
184
+ export declare enum ParticleShape {
185
+ /**
186
+ * Point emitter, emits particles from a single point
187
+ */
188
+ POINT = "point",
189
+ /**
190
+ * Circle emitter, emits particles randomly from a circular area
191
+ */
192
+ CIRCLE = "circle",
193
+ /**
194
+ * Rectangle emitter, emits particles randomly from a rectangular area
195
+ */
196
+ RECT = "rect"
197
+ }
198
+ /**
199
+ * Defines particle attribute animation
200
+ * @template T Attribute type, can be number, vector or color
201
+ */
202
+ export interface ParticleAttribute<T extends number | Vec2 | Color> {
203
+ /**
204
+ * Damping coefficient, controls attribute decay rate over time
205
+ */
206
+ damping?: number;
207
+ /**
208
+ * Initial attribute value
209
+ */
210
+ start: T;
211
+ /**
212
+ * Final attribute value, uses initial value if not specified
213
+ */
214
+ end?: T;
215
+ /**
216
+ * Attribute change rate, automatically calculated from start and end if not specified
217
+ */
218
+ delta?: T;
219
+ }
220
+ /**
221
+ * Particle system configuration options
222
+ */
223
+ export interface IParticleOptions extends ITransformOptions, IShaderRenderOptions {
224
+ /**
225
+ * Particle texture, can be a single texture, array of textures, or weighted texture array
226
+ */
227
+ texture: Texture | Texture[] | [Texture, number][];
228
+ /**
229
+ * Particle emission rate (particles per second)
230
+ */
231
+ emitRate?: number;
232
+ /**
233
+ * Emission time interval in seconds
234
+ */
235
+ emitTime?: number;
236
+ /**
237
+ * Maximum number of particles limit
238
+ */
239
+ maxParticles?: number;
240
+ /**
241
+ * Particle lifetime in seconds, can be fixed value or range
242
+ */
243
+ life?: number | [number, number];
244
+ /**
245
+ * Particle animation properties collection
246
+ */
247
+ animation: {
248
+ /**
249
+ * Velocity vector, controls particle movement direction and speed
250
+ */
251
+ velocity?: ParticleAttribute<Vec2>;
252
+ /**
253
+ * Acceleration vector, controls particle velocity changes
254
+ */
255
+ acceleration?: ParticleAttribute<Vec2>;
256
+ /**
257
+ * Speed scalar, used in combination with rotation direction
258
+ */
259
+ speed?: ParticleAttribute<number>;
260
+ /**
261
+ * Scale factor, controls particle size
262
+ */
263
+ scale?: ParticleAttribute<number>;
264
+ /**
265
+ * Rotation angle (in radians)
266
+ */
267
+ rotation?: ParticleAttribute<number>;
268
+ /**
269
+ * Color and transparency
270
+ */
271
+ color?: ParticleAttribute<Color>;
272
+ };
273
+ /**
274
+ * Emitter shape
275
+ */
276
+ emitShape?: ParticleShape;
277
+ /**
278
+ * Circular emitter radius
279
+ */
280
+ emitRadius?: number;
281
+ /**
282
+ * Rectangular emitter dimensions
283
+ */
284
+ emitRect?: {
285
+ width: number;
286
+ height: number;
287
+ };
288
+ /**
289
+ * Whether to use local coordinate system, true means particles are relative to emitter position,
290
+ * false means using global coordinates
291
+ */
292
+ localSpace?: boolean;
293
+ }
294
+ /**
295
+ * Particle attribute data types
296
+ */
297
+ export type ParticleAttributeTypes = number | Vec2 | Color;
298
+ /**
299
+ * Particle attribute runtime data
300
+ * @template T Attribute type
301
+ */
302
+ export type ParticleAttributeData<T extends ParticleAttributeTypes> = {
303
+ /**
304
+ * Attribute change rate per second
305
+ */
306
+ delta?: T;
307
+ /**
308
+ * Current attribute value
309
+ */
310
+ value: T;
311
+ /**
312
+ * Damping coefficient
313
+ */
314
+ damping?: number;
315
+ };