modern-canvas 0.14.3 → 0.14.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 CHANGED
@@ -39,7 +39,7 @@ npm i modern-canvas
39
39
  ## 🦄 Usage
40
40
 
41
41
  ```javascript
42
- import { Animation, Element2D, Engine, Image2D, Video2D } from 'modern-canvas'
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 Image2D({
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
- src: '/example.png',
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, Image2D } from 'modern-canvas'
96
+ import { EmbossEffect, Element2D } from 'modern-canvas'
107
97
 
108
98
  engine.root.appendChild(
109
- new Image2D({
110
- src: '/example.png',
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 { Image2D, TiltShiftTransition } from 'modern-canvas'
112
+ import { Element2D, TiltShiftTransition } from 'modern-canvas'
123
113
 
124
114
  engine.root.appendChild(
125
- new Image2D({
126
- src: '/example.png',
115
+ new Element2D({
116
+ foreground: { image: '/example.png' },
127
117
  }),
128
118
  new TiltShiftTransition(),
129
- new Image2D({
130
- src: '/example.gif',
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 { Image2D, Transition } from 'modern-canvas'
129
+ import { Element2D, Transition } from 'modern-canvas'
140
130
 
141
131
  engine.root.appendChild(
142
- new Image2D({
143
- src: '/example.png',
132
+ new Element2D({
133
+ foreground: { image: '/example.png' },
144
134
  }),
145
135
  new Transition({ glsl: bounceGLSL }),
146
- new Image2D({
147
- src: '/example.gif',
136
+ new Element2D({
137
+ foreground: { image: '/example.gif' },
148
138
  }),
149
139
  )
150
140
  ```
@@ -1,10 +1,15 @@
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
+ onRenderTargetChange(renderTarget: RenderTargetLike | null): void;
7
12
  push(rect: RectangleLike): void;
8
13
  pop(): void;
9
- bind(rect: RectangleLike): void;
14
+ bind(rect?: RectangleLike | null): void;
10
15
  }
@@ -50,7 +50,6 @@ export declare class GlStencilSystem extends GlSystem {
50
50
  };
51
51
  onUpdateContext(gl: GlRenderingContext): void;
52
52
  reset(): void;
53
- protected _activeRenderTarget: RenderTargetLike | null;
54
53
  onRenderTargetChange(renderTarget: RenderTargetLike | null): void;
55
54
  bind(stencilMode: StencilMode, refCount: number): void;
56
55
  }
package/dist/index.js CHANGED
@@ -3154,28 +3154,44 @@ function Go(r, e) {
3154
3154
  };
3155
3155
  }
3156
3156
  class Vo extends q {
3157
- scissorCounter = 0;
3158
3157
  install(e) {
3159
3158
  super.install(e), e.scissor = this;
3160
3159
  }
3160
+ current = {
3161
+ [-1]: {
3162
+ refCount: 0
3163
+ }
3164
+ };
3165
+ onRenderTargetChange(e) {
3166
+ if (e) {
3167
+ let t = this.current[e.instanceId];
3168
+ t || (t = this.current[e.instanceId] = {
3169
+ refCount: 0
3170
+ }), t.rect && t.refCount > 0 ? this.bind(t.rect) : this.bind(null);
3171
+ }
3172
+ }
3161
3173
  push(e) {
3162
3174
  const t = this._gl;
3163
- t.enable(t.SCISSOR_TEST), this.scissorCounter++, this.bind(e);
3175
+ t.enable(t.SCISSOR_TEST);
3176
+ const s = this.current[this._renderer.renderTarget.current?.instanceId ?? -1];
3177
+ s.refCount++, s.rect = e, this.bind(e);
3164
3178
  }
3165
3179
  pop() {
3166
- if (this.scissorCounter > 0 && this.scissorCounter--, this.scissorCounter <= 0) {
3167
- const e = this._gl;
3168
- e.disable(e.SCISSOR_TEST);
3169
- }
3180
+ const e = this.current[this._renderer.renderTarget.current?.instanceId ?? -1];
3181
+ e.refCount > 0 && e.refCount--, e.refCount <= 0 && this.bind(null);
3170
3182
  }
3171
3183
  bind(e) {
3172
- const { pixelRatio: t, viewport: s } = this._renderer, { viewMatrix: i } = this._renderer.shader.uniforms, { x: o, y: a, width: n, height: l } = Go(i, e), c = s.current.height / t - (a + l);
3173
- this._renderer.gl.scissor(
3174
- o * t,
3175
- c * t,
3176
- n * t,
3177
- l * t
3178
- );
3184
+ const t = this._gl;
3185
+ if (e) {
3186
+ const { pixelRatio: s, viewport: i } = this._renderer, { viewMatrix: o } = this._renderer.shader.uniforms, { x: a, y: n, width: l, height: c } = Go(o, e), u = i.current.height / s - (n + c);
3187
+ t.scissor(
3188
+ a * s,
3189
+ u * s,
3190
+ l * s,
3191
+ c * s
3192
+ );
3193
+ } else
3194
+ t.disable(t.SCISSOR_TEST);
3179
3195
  }
3180
3196
  }
3181
3197
  const Ie = [];
@@ -3235,7 +3251,12 @@ class $o extends q {
3235
3251
  stencilMode: D.none,
3236
3252
  refCount: 0
3237
3253
  };
3238
- current = /* @__PURE__ */ Object.create(null);
3254
+ current = {
3255
+ [-1]: {
3256
+ stencilMode: D.disabled,
3257
+ refCount: 0
3258
+ }
3259
+ };
3239
3260
  _passOpMap;
3240
3261
  _compareMap;
3241
3262
  onUpdateContext(e) {
@@ -3262,9 +3283,8 @@ class $o extends q {
3262
3283
  reset() {
3263
3284
  this._cache.enabled = !1, this._cache.stencilMode = D.none, this._cache.refCount = 0;
3264
3285
  }
3265
- _activeRenderTarget = null;
3266
3286
  onRenderTargetChange(e) {
3267
- if (this._activeRenderTarget !== e && (this._activeRenderTarget = e, e)) {
3287
+ if (e) {
3268
3288
  let t = this.current[e.instanceId];
3269
3289
  t || (t = this.current[e.instanceId] = {
3270
3290
  stencilMode: D.disabled,
@@ -3273,10 +3293,7 @@ class $o extends q {
3273
3293
  }
3274
3294
  }
3275
3295
  bind(e, t) {
3276
- const s = this._activeRenderTarget ? this.current[this._activeRenderTarget.instanceId] : {
3277
- stencilMode: D.disabled,
3278
- refCount: 0
3279
- }, i = this._gl, o = Ie[e], a = this._cache;
3296
+ const s = this.current[this._renderer.renderTarget.current?.instanceId ?? -1], i = this._gl, o = Ie[e], a = this._cache;
3280
3297
  if (s.stencilMode = e, s.refCount = t, e === D.disabled) {
3281
3298
  this._cache.enabled && (this._cache.enabled = !1, i.disable(i.STENCIL_TEST));
3282
3299
  return;
@@ -3345,7 +3362,7 @@ class jo extends q {
3345
3362
  width: this._renderer.screen.width * this._renderer.pixelRatio,
3346
3363
  height: this._renderer.screen.height * this._renderer.pixelRatio
3347
3364
  });
3348
- i && this._renderer.stencil.onRenderTargetChange(this.current);
3365
+ i && (this._renderer.scissor.onRenderTargetChange(this.current), this._renderer.stencil.onRenderTargetChange(this.current));
3349
3366
  }
3350
3367
  unbind() {
3351
3368
  return this.bind(null);
@@ -8496,7 +8513,6 @@ let nr = class extends Oe {
8496
8513
  this._allowPointerEvents = !V(e);
8497
8514
  break;
8498
8515
  case "borderRadius":
8499
- default:
8500
8516
  this.requestRender();
8501
8517
  break;
8502
8518
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.14.3",
4
+ "version": "0.14.4",
5
5
  "packageManager": "pnpm@10.19.0",
6
6
  "description": "A JavaScript WebGL rendering engine. only the ESM.",
7
7
  "author": "wxm",
@@ -65,7 +65,7 @@
65
65
  "earcut": "^3.0.2",
66
66
  "modern-font": "^0.4.4",
67
67
  "modern-idoc": "^0.10.6",
68
- "modern-path2d": "^1.4.11",
68
+ "modern-path2d": "^1.4.14",
69
69
  "modern-text": "^1.10.4"
70
70
  },
71
71
  "peerDependencies": {
@@ -85,7 +85,7 @@
85
85
  }
86
86
  },
87
87
  "devDependencies": {
88
- "@antfu/eslint-config": "^6.4.2",
88
+ "@antfu/eslint-config": "^6.5.1",
89
89
  "@types/earcut": "^3.0.0",
90
90
  "@types/node": "^24.10.1",
91
91
  "bumpp": "^10.3.2",
@@ -97,7 +97,7 @@
97
97
  "simple-git-hooks": "^2.13.1",
98
98
  "typescript": "^5.9.3",
99
99
  "unbuild": "^3.6.1",
100
- "vite": "^7.2.6",
100
+ "vite": "^7.2.7",
101
101
  "vitest": "^4.0.15",
102
102
  "yoga-layout": "^3.2.1"
103
103
  },