modern-canvas 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -17
- package/dist/index.cjs +14066 -47
- package/dist/index.d.cts +3115 -0
- package/dist/index.d.mts +3115 -0
- package/dist/index.d.ts +3115 -0
- package/dist/index.js +868 -47
- package/dist/index.mjs +13852 -630
- package/package.json +59 -28
- package/types/canvas.d.ts +0 -42
- package/types/container.d.ts +0 -14
- package/types/gl.d.ts +0 -20
- package/types/index.d.ts +0 -2
- package/types/material.d.ts +0 -26
- package/types/node-renderer.d.ts +0 -18
- package/types/node.d.ts +0 -10
- package/types/plugin.d.ts +0 -8
- package/types/plugins/base.d.ts +0 -1
- package/types/plugins/fade.d.ts +0 -1
- package/types/plugins/index.d.ts +0 -7
- 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/render.d.ts +0 -2
- package/types/resource.d.ts +0 -10
- package/types/shape.d.ts +0 -14
- package/types/utils/index.d.ts +0 -1
- package/types/utils/matrix3.d.ts +0 -7
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modern-canvas",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0
|
|
5
|
-
"packageManager": "pnpm@
|
|
6
|
-
"description": "A
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"packageManager": "pnpm@9.15.1",
|
|
6
|
+
"description": "A JavaScript WebGL rendering engine.",
|
|
7
7
|
"author": "wxm",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"homepage": "https://github.com/qq15725/modern-canvas",
|
|
@@ -23,46 +23,77 @@
|
|
|
23
23
|
"sideEffects": false,
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
26
|
-
"types": "./
|
|
27
|
-
"
|
|
28
|
-
"
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"import": "./dist/index.mjs",
|
|
28
|
+
"require": "./dist/index.cjs"
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
|
-
"main": "dist/index.mjs",
|
|
32
|
-
"module": "dist/index.mjs",
|
|
33
|
-
"types": "
|
|
34
|
-
"browser": "dist/index.js",
|
|
31
|
+
"main": "./dist/index.mjs",
|
|
32
|
+
"module": "./dist/index.mjs",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"browser": "./dist/index.js",
|
|
35
35
|
"typesVersions": {
|
|
36
36
|
"*": {
|
|
37
37
|
"*": [
|
|
38
|
-
"./
|
|
39
|
-
"./
|
|
38
|
+
"./dist/*",
|
|
39
|
+
"./dist/index.d.ts"
|
|
40
40
|
]
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
"files": [
|
|
44
|
-
"dist"
|
|
45
|
-
"types"
|
|
44
|
+
"dist"
|
|
46
45
|
],
|
|
47
46
|
"scripts": {
|
|
47
|
+
"build": "vite build && unbuild",
|
|
48
48
|
"dev": "vite docs",
|
|
49
49
|
"lint": "eslint src",
|
|
50
|
-
"test": "vitest --no-threads --no-isolate",
|
|
51
|
-
"build": "vite build && tsc --project tsconfig.build.json",
|
|
52
|
-
"build:docs": "vite build docs",
|
|
53
50
|
"version": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md",
|
|
54
|
-
"release": "bumpp package.json --commit \"release: v%s\" --push --all --tag"
|
|
51
|
+
"release": "bumpp package.json --commit \"release: v%s\" --push --all --tag",
|
|
52
|
+
"start": "esno src/index.ts",
|
|
53
|
+
"test": "vitest",
|
|
54
|
+
"typecheck": "tsc --noEmit",
|
|
55
|
+
"prepare": "simple-git-hooks"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"lottie-web": "^5",
|
|
59
|
+
"modern-gif": "^2"
|
|
60
|
+
},
|
|
61
|
+
"peerDependenciesMeta": {
|
|
62
|
+
"lottie-web": {
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
65
|
+
"modern-gif": {
|
|
66
|
+
"optional": true
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"colord": "^2.9.3",
|
|
71
|
+
"earcut": "^3.0.1",
|
|
72
|
+
"modern-font": "^0.3.5",
|
|
73
|
+
"modern-idoc": "^0.1.4",
|
|
74
|
+
"modern-path2d": "^1.0.1",
|
|
75
|
+
"modern-text": "^1.0.7"
|
|
55
76
|
},
|
|
56
77
|
"devDependencies": {
|
|
57
|
-
"@
|
|
58
|
-
"@types/
|
|
59
|
-
"@
|
|
60
|
-
"bumpp": "^
|
|
61
|
-
"conventional-changelog-cli": "^
|
|
62
|
-
"eslint": "^
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
78
|
+
"@antfu/eslint-config": "^3.12.1",
|
|
79
|
+
"@types/earcut": "^2.1.4",
|
|
80
|
+
"@types/node": "^22.10.3",
|
|
81
|
+
"bumpp": "^9.9.2",
|
|
82
|
+
"conventional-changelog-cli": "^5.0.0",
|
|
83
|
+
"eslint": "^9.17.0",
|
|
84
|
+
"lint-staged": "^15.3.0",
|
|
85
|
+
"lottie-web": "^5.12.2",
|
|
86
|
+
"modern-gif": "^2.0.4",
|
|
87
|
+
"simple-git-hooks": "^2.11.1",
|
|
88
|
+
"typescript": "^5.7.2",
|
|
89
|
+
"unbuild": "^3.2.0",
|
|
90
|
+
"vite": "^6.0.6",
|
|
91
|
+
"vitest": "^2.1.8"
|
|
92
|
+
},
|
|
93
|
+
"simple-git-hooks": {
|
|
94
|
+
"pre-commit": "pnpm lint-staged"
|
|
95
|
+
},
|
|
96
|
+
"lint-staged": {
|
|
97
|
+
"*": "eslint src --fix"
|
|
67
98
|
}
|
|
68
99
|
}
|
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/container.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export interface Container {
|
|
2
|
-
instances: Map<string, any>;
|
|
3
|
-
bindings: Map<string, {
|
|
4
|
-
value: () => any;
|
|
5
|
-
shared: boolean;
|
|
6
|
-
}>;
|
|
7
|
-
get<T = any>(key: string): T;
|
|
8
|
-
has(key: string): boolean;
|
|
9
|
-
set<T = any>(key: string, value: T): void;
|
|
10
|
-
bind<T = any>(key: string, value: () => T, shared?: boolean): void;
|
|
11
|
-
singleton<T = any>(key: string, value: () => T): void;
|
|
12
|
-
[key: string]: any;
|
|
13
|
-
}
|
|
14
|
-
export declare function createContainer(): Container;
|
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/index.d.ts
DELETED
package/types/material.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { GlSlType } from './gl';
|
|
2
|
-
import type { Canvas } from './canvas';
|
|
3
|
-
export interface Material {
|
|
4
|
-
name: string;
|
|
5
|
-
vertexShader: string;
|
|
6
|
-
fragmentShader: string;
|
|
7
|
-
uniforms?: Record<string, any>;
|
|
8
|
-
}
|
|
9
|
-
export type InternalMaterial = Material & {
|
|
10
|
-
program: WebGLProgram;
|
|
11
|
-
attributes: Record<string, MaterialAttribute>;
|
|
12
|
-
uniforms: Record<string, MaterialUniform>;
|
|
13
|
-
setAttributes(attributes: Record<string, any>): void;
|
|
14
|
-
setUniforms(uniforms: Record<string, any>): void;
|
|
15
|
-
};
|
|
16
|
-
export interface MaterialAttribute {
|
|
17
|
-
type: GlSlType;
|
|
18
|
-
isArray: boolean;
|
|
19
|
-
location: GLint;
|
|
20
|
-
}
|
|
21
|
-
export interface MaterialUniform {
|
|
22
|
-
type: GlSlType;
|
|
23
|
-
isArray: boolean;
|
|
24
|
-
location: WebGLUniformLocation | null;
|
|
25
|
-
}
|
|
26
|
-
export declare function registerMaterial(canvas: Canvas, material: Material): 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/node.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Canvas } from './canvas';
|
|
2
|
-
export interface Node {
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
x?: number;
|
|
5
|
-
y?: number;
|
|
6
|
-
width?: number;
|
|
7
|
-
height?: number;
|
|
8
|
-
children?: Node[];
|
|
9
|
-
}
|
|
10
|
-
export declare function forEachNode(canvas: Canvas, callbackFn: (node: Node, path: number[]) => void): void;
|
package/types/plugin.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Canvas } from './canvas';
|
|
2
|
-
export interface Plugin {
|
|
3
|
-
name: string;
|
|
4
|
-
register?(canvas: Canvas): void;
|
|
5
|
-
beforeRender?(canvas: Canvas): void;
|
|
6
|
-
afterRender?(canvas: Canvas): void;
|
|
7
|
-
}
|
|
8
|
-
export declare function definePlugin(plugin: Plugin | (() => Plugin)): Plugin;
|
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;
|
package/types/plugins/index.d.ts
DELETED
|
@@ -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/render.d.ts
DELETED
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/shape.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { GlDrawModes } from './gl';
|
|
2
|
-
import type { Canvas } from './canvas';
|
|
3
|
-
export interface Shape {
|
|
4
|
-
name: string;
|
|
5
|
-
type?: '2d' | '3d';
|
|
6
|
-
mode?: keyof GlDrawModes;
|
|
7
|
-
data?: Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | BigUint64Array | BigInt64Array | Float32Array | Float64Array;
|
|
8
|
-
}
|
|
9
|
-
export interface InternalShape {
|
|
10
|
-
mode: GLenum;
|
|
11
|
-
count: number;
|
|
12
|
-
buffer: WebGLBuffer | null;
|
|
13
|
-
}
|
|
14
|
-
export declare function registerShape(canvas: Canvas, shape: Shape): 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
|
-
}
|