modern-canvas 0.14.3 → 0.14.5
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 +16 -26
- package/dist/core/renderers/gl/GlScissorSystem.d.ts +9 -2
- package/dist/core/renderers/gl/GlStencilSystem.d.ts +4 -3
- package/dist/core/renderers/gl/renderTarget/GlRenderTargetSystem.d.ts +12 -1
- package/dist/core/renderers/gl/state/GlStateSystem.d.ts +1 -1
- package/dist/core/renderers/gl/system/GlSystem.d.ts +16 -4
- package/dist/core/renderers/gl/texture/GlTextureSystem.d.ts +1 -1
- package/dist/index.js +221 -173
- package/dist/scene/main/Effect.d.ts +2 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ npm i modern-canvas
|
|
|
39
39
|
## 🦄 Usage
|
|
40
40
|
|
|
41
41
|
```javascript
|
|
42
|
-
import { Animation, Element2D, Engine
|
|
42
|
+
import { Animation, Element2D, Engine } from 'modern-canvas'
|
|
43
43
|
import { fonts } from 'modern-font'
|
|
44
44
|
|
|
45
45
|
async function loadFallbackFont() {
|
|
@@ -50,7 +50,7 @@ loadFallbackFont().then(() => {
|
|
|
50
50
|
const engine = new Engine({ width: 500, height: 500 }).start()
|
|
51
51
|
|
|
52
52
|
engine.root.appendChild(
|
|
53
|
-
new
|
|
53
|
+
new Element2D({
|
|
54
54
|
style: {
|
|
55
55
|
left: 100,
|
|
56
56
|
top: 100,
|
|
@@ -61,7 +61,7 @@ loadFallbackFont().then(() => {
|
|
|
61
61
|
backgroundColor: '#00FF00',
|
|
62
62
|
filter: 'brightness(102%) contrast(90%) saturate(128%) sepia(18%)',
|
|
63
63
|
},
|
|
64
|
-
|
|
64
|
+
foreground: { image: '/example.png' },
|
|
65
65
|
}, [
|
|
66
66
|
new Animation({
|
|
67
67
|
duration: 3000,
|
|
@@ -79,16 +79,6 @@ loadFallbackFont().then(() => {
|
|
|
79
79
|
content: '/example.png',
|
|
80
80
|
},
|
|
81
81
|
}),
|
|
82
|
-
new Video2D({
|
|
83
|
-
style: {
|
|
84
|
-
left: 200,
|
|
85
|
-
top: 200,
|
|
86
|
-
width: 100,
|
|
87
|
-
height: 100,
|
|
88
|
-
maskImage: '/example.png',
|
|
89
|
-
},
|
|
90
|
-
src: '/example.mp4',
|
|
91
|
-
}),
|
|
92
82
|
])
|
|
93
83
|
)
|
|
94
84
|
|
|
@@ -103,11 +93,11 @@ loadFallbackFont().then(() => {
|
|
|
103
93
|
See all [preset special effects](./src/scene/effects)
|
|
104
94
|
|
|
105
95
|
```typescript
|
|
106
|
-
import { EmbossEffect,
|
|
96
|
+
import { EmbossEffect, Element2D } from 'modern-canvas'
|
|
107
97
|
|
|
108
98
|
engine.root.appendChild(
|
|
109
|
-
new
|
|
110
|
-
|
|
99
|
+
new Element2D({
|
|
100
|
+
foreground: { image: '/example.png' },
|
|
111
101
|
}, [
|
|
112
102
|
new EmbossEffect(),
|
|
113
103
|
])
|
|
@@ -119,15 +109,15 @@ engine.root.appendChild(
|
|
|
119
109
|
See all [preset transitions](./src/scene/transitions)
|
|
120
110
|
|
|
121
111
|
```typescript
|
|
122
|
-
import {
|
|
112
|
+
import { Element2D, TiltShiftTransition } from 'modern-canvas'
|
|
123
113
|
|
|
124
114
|
engine.root.appendChild(
|
|
125
|
-
new
|
|
126
|
-
|
|
115
|
+
new Element2D({
|
|
116
|
+
foreground: { image: '/example.png' },
|
|
127
117
|
}),
|
|
128
118
|
new TiltShiftTransition(),
|
|
129
|
-
new
|
|
130
|
-
|
|
119
|
+
new Element2D({
|
|
120
|
+
foreground: { image: '/example.gif' },
|
|
131
121
|
}),
|
|
132
122
|
)
|
|
133
123
|
```
|
|
@@ -136,15 +126,15 @@ Use https://github.com/gl-transitions/gl-transitions with `vite`
|
|
|
136
126
|
|
|
137
127
|
```ts
|
|
138
128
|
import bounceGLSL from 'gl-transitions/transitions/Bounce.glsl?raw'
|
|
139
|
-
import {
|
|
129
|
+
import { Element2D, Transition } from 'modern-canvas'
|
|
140
130
|
|
|
141
131
|
engine.root.appendChild(
|
|
142
|
-
new
|
|
143
|
-
|
|
132
|
+
new Element2D({
|
|
133
|
+
foreground: { image: '/example.png' },
|
|
144
134
|
}),
|
|
145
135
|
new Transition({ glsl: bounceGLSL }),
|
|
146
|
-
new
|
|
147
|
-
|
|
136
|
+
new Element2D({
|
|
137
|
+
foreground: { image: '/example.gif' },
|
|
148
138
|
}),
|
|
149
139
|
)
|
|
150
140
|
```
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import type { RectangleLike } from '../../math';
|
|
2
|
+
import type { RenderTargetLike } from '../shared';
|
|
2
3
|
import type { GlRenderer } from './GlRenderer';
|
|
3
4
|
import { GlSystem } from './system';
|
|
4
5
|
export declare class GlScissorSystem extends GlSystem {
|
|
5
|
-
scissorCounter: number;
|
|
6
6
|
install(renderer: GlRenderer): void;
|
|
7
|
+
current: Record<number, {
|
|
8
|
+
refCount: number;
|
|
9
|
+
rect?: RectangleLike;
|
|
10
|
+
}>;
|
|
11
|
+
protected _setup(): void;
|
|
12
|
+
protected _updateRenderTarget: (renderTarget: RenderTargetLike | null) => void;
|
|
7
13
|
push(rect: RectangleLike): void;
|
|
8
14
|
pop(): void;
|
|
9
|
-
bind(rect
|
|
15
|
+
bind(rect?: RectangleLike | null): void;
|
|
16
|
+
destroy(): void;
|
|
10
17
|
}
|
|
@@ -48,9 +48,10 @@ export declare class GlStencilSystem extends GlSystem {
|
|
|
48
48
|
'greater': number;
|
|
49
49
|
'greater-equal': number;
|
|
50
50
|
};
|
|
51
|
-
|
|
51
|
+
protected _updateContext(gl: GlRenderingContext): void;
|
|
52
|
+
protected _setup(): void;
|
|
52
53
|
reset(): void;
|
|
53
|
-
protected
|
|
54
|
-
onRenderTargetChange(renderTarget: RenderTargetLike | null): void;
|
|
54
|
+
protected _updateRenderTarget: (renderTarget: RenderTargetLike | null) => void;
|
|
55
55
|
bind(stencilMode: StencilMode, refCount: number): void;
|
|
56
|
+
destroy(): void;
|
|
56
57
|
}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import type { RectangleLike } from '../../../math';
|
|
2
2
|
import type { RenderTargetLike, TextureLike } from '../../shared';
|
|
3
3
|
import type { GlRenderer } from '../GlRenderer';
|
|
4
|
+
import type { GlSystemEvents } from '../system';
|
|
5
|
+
import type { GlRenderingContext } from '../types';
|
|
4
6
|
import { Projection2D } from '../../../math';
|
|
5
7
|
import { GlSystem } from '../system';
|
|
6
8
|
import { GlRenderTarget } from './GlRenderTarget';
|
|
9
|
+
export interface GlRenderTargetSystemEvents extends GlSystemEvents {
|
|
10
|
+
updateRenderTarget: [renderTarget: RenderTargetLike | null];
|
|
11
|
+
}
|
|
12
|
+
export interface GlRenderTargetSystem {
|
|
13
|
+
on: <K extends keyof GlRenderTargetSystemEvents & string>(event: K, listener: (...args: GlRenderTargetSystemEvents[K]) => void) => this;
|
|
14
|
+
once: <K extends keyof GlRenderTargetSystemEvents & string>(event: K, listener: (...args: GlRenderTargetSystemEvents[K]) => void) => this;
|
|
15
|
+
off: <K extends keyof GlRenderTargetSystemEvents & string>(event: K, listener: (...args: GlRenderTargetSystemEvents[K]) => void) => this;
|
|
16
|
+
emit: <K extends keyof GlRenderTargetSystemEvents & string>(event: K, ...args: GlRenderTargetSystemEvents[K]) => this;
|
|
17
|
+
}
|
|
7
18
|
export declare class GlRenderTargetSystem extends GlSystem {
|
|
8
19
|
install(renderer: GlRenderer): void;
|
|
9
20
|
readonly renderTargets: Map<number, RenderTargetLike>;
|
|
@@ -13,7 +24,7 @@ export declare class GlRenderTargetSystem extends GlSystem {
|
|
|
13
24
|
protected _hasMRT: boolean;
|
|
14
25
|
protected _writeDepthTexture: boolean;
|
|
15
26
|
projectionMatrix: Projection2D;
|
|
16
|
-
|
|
27
|
+
protected _updateContext(gl: GlRenderingContext): void;
|
|
17
28
|
bind(renderTarget: RenderTargetLike | null, frame?: RectangleLike): void;
|
|
18
29
|
unbind(): void;
|
|
19
30
|
getGlRenderTarget(renderTarget: RenderTargetLike): GlRenderTarget;
|
|
@@ -31,7 +31,7 @@ export declare class GlStateSystem extends GlSystem {
|
|
|
31
31
|
boundBlendMode?: string;
|
|
32
32
|
blendModes: Record<GlBlendMode, any>;
|
|
33
33
|
defaultState: GlState;
|
|
34
|
-
|
|
34
|
+
protected _updateContext(gl: GlRenderingContext): void;
|
|
35
35
|
toggle(boundPoint: number, enable: boolean): void;
|
|
36
36
|
setBlend(value: boolean): void;
|
|
37
37
|
setOffsets(value: boolean): void;
|
|
@@ -1,12 +1,24 @@
|
|
|
1
|
+
import type { ObservableEvents } from 'modern-idoc';
|
|
1
2
|
import type { GlRenderer } from '../GlRenderer';
|
|
2
3
|
import type { GlRenderingContext } from '../types';
|
|
3
|
-
|
|
4
|
+
import { Observable } from 'modern-idoc';
|
|
5
|
+
export interface GlSystemEvents extends ObservableEvents {
|
|
6
|
+
updateContext: [gl: GlRenderingContext];
|
|
7
|
+
setup: [];
|
|
8
|
+
}
|
|
9
|
+
export interface GlSystem {
|
|
10
|
+
on: <K extends keyof GlSystemEvents & string>(event: K, listener: (...args: GlSystemEvents[K]) => void) => this;
|
|
11
|
+
once: <K extends keyof GlSystemEvents & string>(event: K, listener: (...args: GlSystemEvents[K]) => void) => this;
|
|
12
|
+
off: <K extends keyof GlSystemEvents & string>(event: K, listener: (...args: GlSystemEvents[K]) => void) => this;
|
|
13
|
+
emit: <K extends keyof GlSystemEvents & string>(event: K, ...args: GlSystemEvents[K]) => this;
|
|
14
|
+
}
|
|
15
|
+
export declare abstract class GlSystem extends Observable {
|
|
4
16
|
protected _renderer: GlRenderer;
|
|
5
17
|
protected get _gl(): GlRenderingContext;
|
|
6
|
-
|
|
18
|
+
constructor();
|
|
7
19
|
install(renderer: GlRenderer): void;
|
|
8
|
-
|
|
20
|
+
protected _updateContext(gl: GlRenderingContext): void;
|
|
21
|
+
protected _setup(): void;
|
|
9
22
|
flush(): void;
|
|
10
23
|
reset(): void;
|
|
11
|
-
destroy(): void;
|
|
12
24
|
}
|
|
@@ -17,7 +17,7 @@ export declare class GlTextureSystem extends GlSystem {
|
|
|
17
17
|
protected _location: GlTextureLocation;
|
|
18
18
|
current: (TextureLike | null)[];
|
|
19
19
|
install(renderer: GlRenderer): void;
|
|
20
|
-
|
|
20
|
+
protected _updateContext(gl: GlRenderingContext): void;
|
|
21
21
|
getGlTexture(texture: TextureLike): GlTexture;
|
|
22
22
|
protected _createGlTexture(texture: TextureLike): GlTexture;
|
|
23
23
|
bind(texture?: TextureLike | null, location?: number): void;
|