modern-canvas 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -9
- package/dist/index.cjs +8 -39
- package/dist/index.js +8 -39
- package/dist/index.mjs +477 -502
- package/package.json +1 -1
- package/types/app.d.ts +63 -0
- package/types/container.d.ts +0 -1
- package/types/create-app.d.ts +3 -0
- package/types/index.d.ts +3 -1
- package/types/material.d.ts +8 -10
- package/types/node.d.ts +0 -6
- package/types/options.d.ts +7 -0
- package/types/plugin.d.ts +2 -4
- package/types/plugins/index.d.ts +1 -7
- package/types/plugins/renderer2d.d.ts +1 -0
- package/types/query.d.ts +4 -0
- package/types/render.d.ts +13 -2
- package/types/setup.d.ts +2 -0
- package/types/shape.d.ts +6 -8
- package/types/system.d.ts +5 -0
- package/types/texture.d.ts +7 -0
- package/types/utils.d.ts +11 -0
- package/types/canvas.d.ts +0 -42
- package/types/gl.d.ts +0 -20
- package/types/node-renderer.d.ts +0 -18
- package/types/plugins/base.d.ts +0 -1
- package/types/plugins/fade.d.ts +0 -1
- package/types/plugins/node-image.d.ts +0 -1
- package/types/plugins/node-text.d.ts +0 -1
- package/types/plugins/selector2d.d.ts +0 -1
- package/types/plugins/transform2d.d.ts +0 -1
- package/types/resource.d.ts +0 -10
- package/types/utils/index.d.ts +0 -1
- package/types/utils/matrix3.d.ts +0 -7
package/package.json
CHANGED
package/types/app.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { QueryOptions } from './query';
|
|
2
|
+
import type { RenderNodeOptions } from './render';
|
|
3
|
+
import type { System } from './system';
|
|
4
|
+
import type { Texture } from './texture';
|
|
5
|
+
import type { Shape, UserShape } from './shape';
|
|
6
|
+
import type { Node } from './node';
|
|
7
|
+
import type { Material, UserMaterial } from './material';
|
|
8
|
+
import type { Plugin } from './plugin';
|
|
9
|
+
import type { Container } from './container';
|
|
10
|
+
export interface App extends Container {
|
|
11
|
+
view: HTMLCanvasElement;
|
|
12
|
+
children: Node[];
|
|
13
|
+
context: WebGLRenderingContext;
|
|
14
|
+
defaultTexture: WebGLTexture;
|
|
15
|
+
framebuffers: {
|
|
16
|
+
buffer: WebGLFramebuffer | null;
|
|
17
|
+
depthBuffer: WebGLRenderbuffer | null;
|
|
18
|
+
texture: WebGLTexture | null;
|
|
19
|
+
resize(): void;
|
|
20
|
+
}[];
|
|
21
|
+
drawModes: {
|
|
22
|
+
points: GLenum;
|
|
23
|
+
linear: GLenum;
|
|
24
|
+
triangles: GLenum;
|
|
25
|
+
triangleStrip: GLenum;
|
|
26
|
+
triangleFan: GLenum;
|
|
27
|
+
};
|
|
28
|
+
slTypes: Record<number, 'float' | 'vec2' | 'vec3' | 'vec4' | 'int' | 'ivec2' | 'ivec3' | 'ivec4' | 'uint' | 'uvec2' | 'uvec3' | 'uvec4' | 'bool' | 'bvec2' | 'bvec3' | 'bvec4' | 'mat2' | 'mat3' | 'mat4' | 'sampler2D' | 'samplerCube' | 'sampler2DArray'>;
|
|
29
|
+
extensions: {
|
|
30
|
+
loseContext: WEBGL_lose_context | null;
|
|
31
|
+
};
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
plugins: Map<string, Plugin>;
|
|
35
|
+
shapes: Map<string, Shape>;
|
|
36
|
+
registerShape(name: string, shape: UserShape): void;
|
|
37
|
+
materials: Map<string, Material>;
|
|
38
|
+
registerMaterial(name: string, material: UserMaterial): void;
|
|
39
|
+
textures: Map<number, Texture>;
|
|
40
|
+
registerTexture(id: number, source: TexImageSource): Promise<void>;
|
|
41
|
+
lastState?: {
|
|
42
|
+
material: string;
|
|
43
|
+
shape: string;
|
|
44
|
+
};
|
|
45
|
+
entities: Map<number, {
|
|
46
|
+
path: number[];
|
|
47
|
+
archetypeId: string;
|
|
48
|
+
}>;
|
|
49
|
+
components: Map<string, number>;
|
|
50
|
+
archetypes: Map<string, {
|
|
51
|
+
entityIds: Set<number>;
|
|
52
|
+
codePoints: number[];
|
|
53
|
+
}>;
|
|
54
|
+
systems: System[];
|
|
55
|
+
registerSystem(system: System): void;
|
|
56
|
+
query(where?: QueryOptions): Node;
|
|
57
|
+
setup(): void;
|
|
58
|
+
load(): Promise<void>;
|
|
59
|
+
renderNode(options: RenderNodeOptions): void;
|
|
60
|
+
render(time?: number): void;
|
|
61
|
+
start(): void;
|
|
62
|
+
destroy(): void;
|
|
63
|
+
}
|
package/types/container.d.ts
CHANGED
|
@@ -9,6 +9,5 @@ export interface Container {
|
|
|
9
9
|
set<T = any>(key: string, value: T): void;
|
|
10
10
|
bind<T = any>(key: string, value: () => T, shared?: boolean): void;
|
|
11
11
|
singleton<T = any>(key: string, value: () => T): void;
|
|
12
|
-
[key: string]: any;
|
|
13
12
|
}
|
|
14
13
|
export declare function createContainer(): Container;
|
package/types/index.d.ts
CHANGED
package/types/material.d.ts
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export interface Material {
|
|
4
|
-
name: string;
|
|
1
|
+
import type { App } from './app';
|
|
2
|
+
export interface UserMaterial {
|
|
5
3
|
vertexShader: string;
|
|
6
4
|
fragmentShader: string;
|
|
7
5
|
uniforms?: Record<string, any>;
|
|
8
6
|
}
|
|
9
|
-
export type
|
|
7
|
+
export type Material = UserMaterial & {
|
|
10
8
|
program: WebGLProgram;
|
|
11
9
|
attributes: Record<string, MaterialAttribute>;
|
|
12
10
|
uniforms: Record<string, MaterialUniform>;
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
setupAttributes(attributes: Record<string, any>): void;
|
|
12
|
+
setupUniforms(uniforms: Record<string, any>): void;
|
|
15
13
|
};
|
|
16
14
|
export interface MaterialAttribute {
|
|
17
|
-
type:
|
|
15
|
+
type: App['slTypes'][keyof App['slTypes']];
|
|
18
16
|
isArray: boolean;
|
|
19
17
|
location: GLint;
|
|
20
18
|
}
|
|
21
19
|
export interface MaterialUniform {
|
|
22
|
-
type:
|
|
20
|
+
type: App['slTypes'][keyof App['slTypes']];
|
|
23
21
|
isArray: boolean;
|
|
24
22
|
location: WebGLUniformLocation | null;
|
|
25
23
|
}
|
|
26
|
-
export declare function registerMaterial(
|
|
24
|
+
export declare function registerMaterial(app: App, name: string, userMaterial: UserMaterial): void;
|
package/types/node.d.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import type { Canvas } from './canvas';
|
|
2
1
|
export interface Node {
|
|
3
2
|
[key: string]: any;
|
|
4
|
-
x?: number;
|
|
5
|
-
y?: number;
|
|
6
|
-
width?: number;
|
|
7
|
-
height?: number;
|
|
8
3
|
children?: Node[];
|
|
9
4
|
}
|
|
10
|
-
export declare function forEachNode(canvas: Canvas, callbackFn: (node: Node, path: number[]) => void): void;
|
package/types/plugin.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { App } from './app';
|
|
2
2
|
export interface Plugin {
|
|
3
3
|
name: string;
|
|
4
|
-
register?(
|
|
5
|
-
beforeRender?(canvas: Canvas): void;
|
|
6
|
-
afterRender?(canvas: Canvas): void;
|
|
4
|
+
register?(app: App): void;
|
|
7
5
|
}
|
|
8
6
|
export declare function definePlugin(plugin: Plugin | (() => Plugin)): Plugin;
|
package/types/plugins/index.d.ts
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './fade';
|
|
3
|
-
export * from './node-image';
|
|
4
|
-
export * from './node-text';
|
|
5
|
-
export * from './selector2d';
|
|
6
|
-
export * from './transform2d';
|
|
7
|
-
export declare const plugins: import("../plugin").Plugin[];
|
|
1
|
+
export * from './renderer2d';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Renderer2d: import("../plugin").Plugin;
|
package/types/query.d.ts
ADDED
package/types/render.d.ts
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export
|
|
1
|
+
import type { App } from './app';
|
|
2
|
+
export interface RenderNodeOptions {
|
|
3
|
+
shape: string;
|
|
4
|
+
material: string;
|
|
5
|
+
uniforms?: Record<string, any>;
|
|
6
|
+
extraRenderers?: {
|
|
7
|
+
shape: string;
|
|
8
|
+
material: string;
|
|
9
|
+
uniforms?: Record<string, any>;
|
|
10
|
+
}[];
|
|
11
|
+
}
|
|
12
|
+
export declare function renderNode(app: App, options: RenderNodeOptions): void;
|
|
13
|
+
export declare function render(app: App, time?: number): void;
|
package/types/setup.d.ts
ADDED
package/types/shape.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export interface Shape {
|
|
4
|
-
name: string;
|
|
1
|
+
import type { App } from './app';
|
|
2
|
+
export interface UserShape {
|
|
5
3
|
type?: '2d' | '3d';
|
|
6
|
-
mode?: keyof
|
|
7
|
-
|
|
4
|
+
mode?: keyof App['drawModes'];
|
|
5
|
+
buffer?: Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | BigUint64Array | BigInt64Array | Float32Array | Float64Array;
|
|
8
6
|
}
|
|
9
|
-
export interface
|
|
7
|
+
export interface Shape {
|
|
10
8
|
mode: GLenum;
|
|
11
9
|
count: number;
|
|
12
10
|
buffer: WebGLBuffer | null;
|
|
13
11
|
}
|
|
14
|
-
export declare function registerShape(
|
|
12
|
+
export declare function registerShape(app: App, name: string, userShape: UserShape): void;
|
package/types/utils.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class Matrix3 extends Float32Array {
|
|
2
|
+
static identity(): Matrix3;
|
|
3
|
+
static translation(tx: number, ty: number): Matrix3;
|
|
4
|
+
static rotation(radians: number): Matrix3;
|
|
5
|
+
static scaling(sx: number, sy: number): Matrix3;
|
|
6
|
+
multiply(matrix3: Matrix3): this;
|
|
7
|
+
}
|
|
8
|
+
export declare function getArchetypeIdCodePoints(componentIds: number[]): number[];
|
|
9
|
+
export declare function createVideo(url: string): HTMLVideoElement;
|
|
10
|
+
export declare function createImage(url: string): HTMLImageElement;
|
|
11
|
+
export declare function resolveColor(value: string, defaultValue?: number[]): [number, number, number, number];
|
package/types/canvas.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { InternalResource, Resource } from './resource';
|
|
2
|
-
import type { InternalShape, Shape } from './shape';
|
|
3
|
-
import type { GlDrawModes, GlExtensions, GlFramebuffer, GlSlTypes } from './gl';
|
|
4
|
-
import type { InternalNodeRenderer, NodeRenderer } from './node-renderer';
|
|
5
|
-
import type { Node } from './node';
|
|
6
|
-
import type { InternalMaterial, Material } from './material';
|
|
7
|
-
import type { Plugin } from './plugin';
|
|
8
|
-
import type { Container } from './container';
|
|
9
|
-
export interface CanvasOptions extends WebGLContextAttributes {
|
|
10
|
-
view?: HTMLCanvasElement;
|
|
11
|
-
children?: Node[];
|
|
12
|
-
plugins?: Plugin[];
|
|
13
|
-
}
|
|
14
|
-
export interface Canvas extends Container {
|
|
15
|
-
view: HTMLCanvasElement;
|
|
16
|
-
children: Node[];
|
|
17
|
-
gl: WebGLRenderingContext;
|
|
18
|
-
glDefaultTexture: WebGLTexture;
|
|
19
|
-
glFramebuffers: GlFramebuffer[];
|
|
20
|
-
glDrawModes: GlDrawModes;
|
|
21
|
-
glSlTypes: GlSlTypes;
|
|
22
|
-
glExtensions: GlExtensions;
|
|
23
|
-
width: number;
|
|
24
|
-
height: number;
|
|
25
|
-
plugins: Map<string, Plugin>;
|
|
26
|
-
beforeRenderPlugins: Plugin[];
|
|
27
|
-
afterRenderPlugins: Plugin[];
|
|
28
|
-
shapes: Map<string, InternalShape>;
|
|
29
|
-
registerShape(shape: Shape): void;
|
|
30
|
-
materials: Map<string, InternalMaterial>;
|
|
31
|
-
registerMaterial(options: Material): void;
|
|
32
|
-
resources: Map<string, InternalResource>;
|
|
33
|
-
registerResource(options: Resource): void;
|
|
34
|
-
nodeRenderers: Map<string, InternalNodeRenderer>;
|
|
35
|
-
registerNodeRenderer(options: NodeRenderer): void;
|
|
36
|
-
forEachNode(callbackFn: (node: Node, path: number[]) => void): void;
|
|
37
|
-
load(): Promise<void>;
|
|
38
|
-
render(time?: number): void;
|
|
39
|
-
startRenderLoop(): void;
|
|
40
|
-
destroy(): void;
|
|
41
|
-
}
|
|
42
|
-
export declare function createCanvas(options?: CanvasOptions): Canvas;
|
package/types/gl.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { Canvas } from './canvas';
|
|
2
|
-
export interface GlDrawModes {
|
|
3
|
-
points: GLenum;
|
|
4
|
-
linear: GLenum;
|
|
5
|
-
triangles: GLenum;
|
|
6
|
-
triangleStrip: GLenum;
|
|
7
|
-
triangleFan: GLenum;
|
|
8
|
-
}
|
|
9
|
-
export type GlSlType = 'float' | 'vec2' | 'vec3' | 'vec4' | 'int' | 'ivec2' | 'ivec3' | 'ivec4' | 'uint' | 'uvec2' | 'uvec3' | 'uvec4' | 'bool' | 'bvec2' | 'bvec3' | 'bvec4' | 'mat2' | 'mat3' | 'mat4' | 'sampler2D' | 'samplerCube' | 'sampler2DArray';
|
|
10
|
-
export type GlSlTypes = Record<number, GlSlType>;
|
|
11
|
-
export interface GlFramebuffer {
|
|
12
|
-
buffer: WebGLFramebuffer | null;
|
|
13
|
-
depthBuffer: WebGLRenderbuffer | null;
|
|
14
|
-
texture: WebGLTexture | null;
|
|
15
|
-
resize(): void;
|
|
16
|
-
}
|
|
17
|
-
export interface GlExtensions {
|
|
18
|
-
loseContext: WEBGL_lose_context | null;
|
|
19
|
-
}
|
|
20
|
-
export declare function provideGl(canvas: Canvas, options?: WebGLContextAttributes): void;
|
package/types/node-renderer.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Canvas } from './canvas';
|
|
2
|
-
import type { Material } from './material';
|
|
3
|
-
import type { Shape } from './shape';
|
|
4
|
-
import type { Node } from './node';
|
|
5
|
-
export interface NodeRenderer {
|
|
6
|
-
name: string;
|
|
7
|
-
include?: (node: Node, path: number[]) => boolean;
|
|
8
|
-
exclude?: (node: Node, path: number[]) => boolean;
|
|
9
|
-
shape: string | Omit<Shape, 'name'>;
|
|
10
|
-
material: string | Omit<Material, 'name'>;
|
|
11
|
-
update?(node: Node, time: number): undefined | Record<string, any>;
|
|
12
|
-
}
|
|
13
|
-
export interface InternalNodeRenderer extends NodeRenderer {
|
|
14
|
-
shape: string;
|
|
15
|
-
material: string;
|
|
16
|
-
render(node: Node, time: number): void;
|
|
17
|
-
}
|
|
18
|
-
export declare function registerNodeRenderer(canvas: Canvas, renderer: NodeRenderer): void;
|
package/types/plugins/base.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const basePlugin: import("../plugin").Plugin;
|
package/types/plugins/fade.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const fadePlugin: import("../plugin").Plugin;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const nodeImagePlugin: import("../plugin").Plugin;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const nodeTextPlugin: import("../plugin").Plugin;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const selector2dPlugin: import("../plugin").Plugin;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const transform2dPlugin: import("../plugin").Plugin;
|
package/types/resource.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Canvas } from './canvas';
|
|
2
|
-
export interface Resource {
|
|
3
|
-
name: string;
|
|
4
|
-
data: TexImageSource;
|
|
5
|
-
}
|
|
6
|
-
export type InternalResource = {
|
|
7
|
-
loading: boolean;
|
|
8
|
-
texture: WebGLTexture | null;
|
|
9
|
-
};
|
|
10
|
-
export declare function registerResource(canvas: Canvas, resource: Resource): void;
|
package/types/utils/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './matrix3';
|
package/types/utils/matrix3.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare class Matrix3 extends Float32Array {
|
|
2
|
-
static identity(): Matrix3;
|
|
3
|
-
static translation(tx: number, ty: number): Matrix3;
|
|
4
|
-
static rotation(radians: number): Matrix3;
|
|
5
|
-
static scaling(sx: number, sy: number): Matrix3;
|
|
6
|
-
multiply(matrix3: Matrix3): this;
|
|
7
|
-
}
|