modern-canvas 0.17.2 → 0.18.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.
@@ -30,7 +30,7 @@ export declare class Assets extends Observable<AssetsEvents> {
30
30
  fetchImageBitmap(url: string | Blob, options?: ImageBitmapOptions): Promise<ImageBitmap>;
31
31
  get<T>(id: string): T | undefined;
32
32
  set(id: string, value: any): void;
33
- awaitBy(handler: () => Promise<void>): Promise<string>;
33
+ awaitBy<T = any>(handler: () => Promise<T>): Promise<T>;
34
34
  loadBy<T = Blob>(id: string, handler?: () => Promise<T>): Promise<T>;
35
35
  load<T>(url: string, options?: any): Promise<T>;
36
36
  waitUntilLoad(): Promise<void>;
package/dist/index.js CHANGED
@@ -1077,12 +1077,12 @@ var ft = class {
1077
1077
  }
1078
1078
  };
1079
1079
  //#endregion
1080
- //#region \0@oxc-project+runtime@0.128.0/helpers/decorateMetadata.js
1080
+ //#region \0@oxc-project+runtime@0.130.0/helpers/decorateMetadata.js
1081
1081
  function O(e, t) {
1082
1082
  if (typeof Reflect == "object" && typeof Reflect.metadata == "function") return Reflect.metadata(e, t);
1083
1083
  }
1084
1084
  //#endregion
1085
- //#region \0@oxc-project+runtime@0.128.0/helpers/decorate.js
1085
+ //#region \0@oxc-project+runtime@0.130.0/helpers/decorate.js
1086
1086
  function k(e, t, n, r) {
1087
1087
  var i = arguments.length, a = i < 3 ? t : r === null ? r = Object.getOwnPropertyDescriptor(t, n) : r, o;
1088
1088
  if (typeof Reflect == "object" && typeof Reflect.decorate == "function") a = Reflect.decorate(e, t, n, r);
@@ -1127,6 +1127,7 @@ k([_({ fallback: 60 }), O("design:type", Number)], ht.prototype, "fps", void 0),
1127
1127
  var gt = /* @__PURE__ */ function(e) {
1128
1128
  return e[e.elementArrayBuffer = 34963] = "elementArrayBuffer", e[e.arrayBuffer = 34962] = "arrayBuffer", e[e.uniformBuffer = 35345] = "uniformBuffer", e;
1129
1129
  }({}), _t = class {
1130
+ native;
1130
1131
  target = gt.arrayBuffer;
1131
1132
  byteLength = 0;
1132
1133
  dirty = !0;
@@ -1539,6 +1540,7 @@ function zt(e, t) {
1539
1540
  //#endregion
1540
1541
  //#region src/core/renderers/gl/shader/GlProgramData.ts
1541
1542
  var Bt = class {
1543
+ native;
1542
1544
  constructor(e) {
1543
1545
  this.native = e;
1544
1546
  }
@@ -2108,7 +2110,7 @@ function $t(e) {
2108
2110
  var M = /* @__PURE__ */ function(e) {
2109
2111
  return e[e.disabled = 0] = "disabled", e[e.renderingMaskAdd = 1] = "renderingMaskAdd", e[e.maskActive = 2] = "maskActive", e[e.inverseMaskActive = 3] = "inverseMaskActive", e[e.renderingMaskRemove = 4] = "renderingMaskRemove", e[e.none = 5] = "none", e;
2110
2112
  }({}), en = /* @__PURE__ */ function(e) {
2111
- return e[e.none = 0] = "none", e[e.color = 16384] = "color", e[e.stencil = 1024] = "stencil", e[e.depth = 256] = "depth", e[e.colorDepth = e.color | e.depth] = "colorDepth", e[e.colorStencil = e.color | e.stencil] = "colorStencil", e[e.depthStencil = e.depth | e.stencil] = "depthStencil", e[e.all = e.color | e.depth | e.stencil] = "all", e;
2113
+ return e[e.none = 0] = "none", e[e.color = 16384] = "color", e[e.stencil = 1024] = "stencil", e[e.depth = 256] = "depth", e[e.colorDepth = 16640] = "colorDepth", e[e.colorStencil = 17408] = "colorStencil", e[e.depthStencil = 1280] = "depthStencil", e[e.all = 17664] = "all", e;
2112
2114
  }({}), tn = class extends j {
2113
2115
  install(e) {
2114
2116
  super.install(e), e.mask = this;
@@ -2251,6 +2253,7 @@ var rn = class extends j {
2251
2253
  t.x === n && t.y === r && t.width === i && t.height === a || (this._gl.viewport(n, r, i, a), t.x = n, t.y = r, t.width = i, t.height = a);
2252
2254
  }
2253
2255
  }, on = class {
2256
+ framebuffer;
2254
2257
  width = -1;
2255
2258
  height = -1;
2256
2259
  msaa = !1;
@@ -2390,6 +2393,7 @@ var rn = class extends j {
2390
2393
  }({}), N = /* @__PURE__ */ function(e) {
2391
2394
  return e[e.UNSIGNED_BYTE = 5121] = "UNSIGNED_BYTE", e[e.UNSIGNED_SHORT = 5123] = "UNSIGNED_SHORT", e[e.UNSIGNED_SHORT_5_6_5 = 33635] = "UNSIGNED_SHORT_5_6_5", e[e.UNSIGNED_SHORT_4_4_4_4 = 32819] = "UNSIGNED_SHORT_4_4_4_4", e[e.UNSIGNED_SHORT_5_5_5_1 = 32820] = "UNSIGNED_SHORT_5_5_5_1", e[e.UNSIGNED_INT = 5125] = "UNSIGNED_INT", e[e.UNSIGNED_INT_10F_11F_11F_REV = 35899] = "UNSIGNED_INT_10F_11F_11F_REV", e[e.UNSIGNED_INT_2_10_10_10_REV = 33640] = "UNSIGNED_INT_2_10_10_10_REV", e[e.UNSIGNED_INT_24_8 = 34042] = "UNSIGNED_INT_24_8", e[e.UNSIGNED_INT_5_9_9_9_REV = 35902] = "UNSIGNED_INT_5_9_9_9_REV", e[e.BYTE = 5120] = "BYTE", e[e.SHORT = 5122] = "SHORT", e[e.INT = 5124] = "INT", e[e.FLOAT = 5126] = "FLOAT", e[e.FLOAT_32_UNSIGNED_INT_24_8_REV = 36269] = "FLOAT_32_UNSIGNED_INT_24_8_REV", e[e.HALF_FLOAT = 36193] = "HALF_FLOAT", e;
2392
2395
  }({}), un = class {
2396
+ native;
2393
2397
  target = ln.TEXTURE_2D;
2394
2398
  width = -1;
2395
2399
  height = -1;
@@ -3692,6 +3696,7 @@ var er = class e extends z {
3692
3696
  _requestId;
3693
3697
  _resolve;
3694
3698
  _reject;
3699
+ _seekResolves = [];
3695
3700
  constructor(t, n) {
3696
3701
  let r = $n(n);
3697
3702
  if (!Ke(t)) {
@@ -3741,8 +3746,24 @@ var er = class e extends z {
3741
3746
  this.source.removeEventListener("error", this._onError, !0), this.emit("error", e), this._reject && (this._reject(e), this._reject = void 0, this._resolve = void 0);
3742
3747
  };
3743
3748
  _onSeeked = () => {
3744
- this.autoUpdate && !this.isPlaying && (this._nextTime = 0, this.requestUpload(), this._nextTime = 0);
3749
+ this.autoUpdate && !this.isPlaying && (this._nextTime = 0, this.requestUpload(), this._nextTime = 0), this._flushSeekResolves();
3745
3750
  };
3751
+ _flushSeekResolves() {
3752
+ if (this._seekResolves.length === 0) return;
3753
+ let e = this._seekResolves;
3754
+ this._seekResolves = [], e.forEach((e) => e());
3755
+ }
3756
+ waitSeek(e) {
3757
+ return !this.seeking || e?.aborted ? Promise.resolve() : new Promise((t) => {
3758
+ let n, r = () => {
3759
+ n && e?.removeEventListener("abort", n), t();
3760
+ };
3761
+ n = () => {
3762
+ let e = this._seekResolves.indexOf(r);
3763
+ e >= 0 && this._seekResolves.splice(e, 1), t();
3764
+ }, e?.addEventListener("abort", n, { once: !0 }), this._seekResolves.push(r);
3765
+ });
3766
+ }
3746
3767
  _setupAutoUpdate() {
3747
3768
  this.autoUpdate && this.isPlaying ? !this.fps && this.source.requestVideoFrameCallback ? (this._connected && (S.off(this.requestUpload), this._connected = !1, this._nextTime = 0), this._requestId === void 0 && (this._requestId = this.source.requestVideoFrameCallback(this._videoFrameRequestCallback))) : (this._requestId !== void 0 && (this.source.cancelVideoFrameCallback(this._requestId), this._requestId = void 0), this._connected || (S.on(this.requestUpload), this._connected = !0, this._nextTime = 0)) : (this._requestId !== void 0 && (this.source.cancelVideoFrameCallback(this._requestId), this._requestId = void 0), this._connected && (S.off(this.requestUpload), this._connected = !1, this._nextTime = 0));
3748
3769
  }
@@ -3763,7 +3784,7 @@ var er = class e extends z {
3763
3784
  return this._sourceLoad;
3764
3785
  }
3765
3786
  _destroy() {
3766
- this._setupAutoUpdate();
3787
+ this._setupAutoUpdate(), this._flushSeekResolves();
3767
3788
  let e = this.source;
3768
3789
  e && (e.removeEventListener("play", this._onPlayStart), e.removeEventListener("pause", this._onPlayStop), e.removeEventListener("seeked", this._onSeeked), e.removeEventListener("canplay", this._onCanPlay), e.removeEventListener("canplaythrough", this._onCanPlay), e.removeEventListener("error", this._onError, !0), e.pause(), e.src = "", e.load());
3769
3790
  }
@@ -3921,6 +3942,7 @@ var tr = class extends z {}, nr = class extends oe {
3921
3942
  return [...this.default];
3922
3943
  }
3923
3944
  }, ir = class extends C {
3945
+ parent;
3924
3946
  getPropertyDeclarations() {
3925
3947
  super.getPropertyDeclarations();
3926
3948
  let e = {};
@@ -6051,6 +6073,7 @@ function wi(e, t) {
6051
6073
  //#endregion
6052
6074
  //#region src/scene/2d/element/Element2DFill.ts
6053
6075
  var Y = class extends C {
6076
+ _parent;
6054
6077
  texture;
6055
6078
  animatedTexture;
6056
6079
  constructor(e) {
@@ -6163,6 +6186,7 @@ k([_(), O("design:type", Object)], Ti.prototype, "fillWithShape", void 0);
6163
6186
  //#endregion
6164
6187
  //#region src/scene/2d/element/Element2DConnection.ts
6165
6188
  var Ei = class extends C {
6189
+ _parent;
6166
6190
  constructor(e) {
6167
6191
  super(), this._parent = e;
6168
6192
  }
@@ -6248,6 +6272,7 @@ k([_(), O("design:type", Object)], Oi.prototype, "color", void 0), k([_(), O("de
6248
6272
  //#endregion
6249
6273
  //#region src/scene/2d/element/Element2DShadow.ts
6250
6274
  var ki = class extends C {
6275
+ _parent;
6251
6276
  constructor(e) {
6252
6277
  super(), this._parent = e;
6253
6278
  }
@@ -6274,6 +6299,7 @@ k([_({ fallback: !0 }), O("design:type", Boolean)], ki.prototype, "enabled", voi
6274
6299
  //#endregion
6275
6300
  //#region src/scene/2d/element/Element2DShape.ts
6276
6301
  var Ai = class extends C {
6302
+ _parent;
6277
6303
  _path2DSet = new se();
6278
6304
  constructor(e) {
6279
6305
  super(), this._parent = e, this._updatePath2DSet();
@@ -6353,6 +6379,7 @@ for (let e in Mi) i(ji, e, { fallback: Mi[e] });
6353
6379
  //#endregion
6354
6380
  //#region src/scene/2d/element/Element2DText.ts
6355
6381
  var Ni, X = class extends C {
6382
+ _parent;
6356
6383
  base;
6357
6384
  get textContent() {
6358
6385
  return this._textContent;
@@ -6567,6 +6594,7 @@ var Z = {
6567
6594
  "border-box": 0,
6568
6595
  "content-box": 1
6569
6596
  }, Ui = class e {
6597
+ _parent;
6570
6598
  static _yoga;
6571
6599
  static async load() {
6572
6600
  let { loadYoga: e } = await import("yoga-layout/load");
@@ -7143,6 +7171,7 @@ var Qi, $i = class extends Ji {
7143
7171
  return (this.texture?.duration ?? 0) * 1e3;
7144
7172
  }
7145
7173
  _wait = Promise.resolve();
7174
+ _loadAbort;
7146
7175
  constructor(e, t = []) {
7147
7176
  super(), this.setProperties(e), this.append(t);
7148
7177
  }
@@ -7157,7 +7186,14 @@ var Qi, $i = class extends Ji {
7157
7186
  return this._wait;
7158
7187
  }
7159
7188
  async _load(e) {
7160
- this.texture = await $.video.load(e), this.requestDraw();
7189
+ this._loadAbort?.abort();
7190
+ let t = new AbortController();
7191
+ this._loadAbort = t;
7192
+ let { signal: n } = t, r = await $.video.load(e);
7193
+ n.aborted || (this.texture = r, this._updateVideoCurrentTime(), !(r.seeking && (await $.awaitBy(() => r.waitSeek(n)), n.aborted)) && this.requestDraw());
7194
+ }
7195
+ _destroy() {
7196
+ this._loadAbort?.abort(), super._destroy();
7161
7197
  }
7162
7198
  _updateVideoCurrentTime() {
7163
7199
  let e = this.texture;
@@ -7529,6 +7565,7 @@ var la = class t extends e {
7529
7565
  e && (e.onended = null, e.onplay = null, e.onpause = null, this._stop()), this._source = null, this._playbackRate = 1, this._volume = 1, this._loop = !1, this._end = 0, this._start = 0, this._duration = 0, this._playing = !1, this._pausedReal = !1, this._paused = !1, this._muted = !1, this._audio &&= (this._audio.context.off("refresh", this.refresh), this._audio.context.off("refreshPaused", this.refreshPaused), null);
7530
7566
  }
7531
7567
  }, da = class {
7568
+ parent;
7532
7569
  source = new globalThis.Audio();
7533
7570
  _src = "";
7534
7571
  get src() {
@@ -7558,6 +7595,8 @@ var la = class t extends e {
7558
7595
  return new ua();
7559
7596
  }
7560
7597
  }, fa = class extends e {
7598
+ _input;
7599
+ _output;
7561
7600
  _processers = [];
7562
7601
  constructor(e, t) {
7563
7602
  super(), this._input = e, this._output = t;
@@ -7578,6 +7617,8 @@ var la = class t extends e {
7578
7617
  return this._input;
7579
7618
  }
7580
7619
  }, pa = class {
7620
+ destination;
7621
+ source;
7581
7622
  constructor(e, t = null) {
7582
7623
  this.destination = e, this.source = t;
7583
7624
  }
@@ -7820,6 +7861,7 @@ var ga = class e extends fa {
7820
7861
  super.destroy(), this._stop(), this._gain?.disconnect(), this._gain = null, this._audio?.context.off("refresh", this.refresh), this._audio?.context.off("refreshPaused", this.refreshPaused), this._audio = null, this._processors.forEach((e) => e.disconnect()), this._processors.length = 0, this._end = 0, this._playbackRate = 1, this._volume = 1, this._loop = !1, this._elapsed = 0, this._duration = 0, this._paused = !1, this._muted = !1, this._pausedReal = !1;
7821
7862
  }
7822
7863
  }, va = class extends fa {
7864
+ parent;
7823
7865
  _sourceBuffer;
7824
7866
  _sourceNode;
7825
7867
  _sourceLoad;
@@ -8250,7 +8292,7 @@ var Ma = class extends An {
8250
8292
  }
8251
8293
  }, La = class extends An {
8252
8294
  install(e) {
8253
- return this.load = (e) => new er(e).load(), e.video = this, this;
8295
+ return this.load = (t) => e.awaitBy(() => new er(t).load()), e.video = this, this;
8254
8296
  }
8255
8297
  }, Ra = Object.entries({
8256
8298
  "font/woff": ["woff"],
@@ -8344,7 +8386,7 @@ var Va = "WeakRef" in globalThis, Ha = class extends e {
8344
8386
  }
8345
8387
  async awaitBy(e) {
8346
8388
  let t = e(), n = c();
8347
- return t.finally(() => this._handleing.delete(n)), this._handleing.set(n, t), await t, n;
8389
+ return t.finally(() => this._handleing.delete(n)), this._handleing.set(n, t), await t;
8348
8390
  }
8349
8391
  async loadBy(e, t = () => this.fetch(e).then((e) => e.blob())) {
8350
8392
  let n = this.get(e) ?? this._handleing.get(e);
@@ -9,10 +9,12 @@ export declare class Video2D extends TextureRect2D<VideoTexture> {
9
9
  src: string;
10
10
  get videoDuration(): number;
11
11
  protected _wait: Promise<void>;
12
+ protected _loadAbort?: AbortController;
12
13
  constructor(properties?: Partial<Video2DProperties>, children?: Node[]);
13
14
  protected _updateProperty(key: string, value: any, oldValue: any): void;
14
15
  waitLoad(): Promise<void>;
15
16
  protected _load(src: string): Promise<void>;
17
+ protected _destroy(): void;
16
18
  protected _updateVideoCurrentTime(): void;
17
19
  protected _process(delta: number): void;
18
20
  }
@@ -30,6 +30,7 @@ export declare class VideoTexture extends Texture2D<HTMLVideoElement> {
30
30
  protected _requestId?: number;
31
31
  protected _resolve?: (val: this) => void;
32
32
  protected _reject?: (event: ErrorEvent) => void;
33
+ protected _seekResolves: Array<() => void>;
33
34
  constructor(source: HTMLVideoElement | (string | VideoTextureLike)[] | string, options?: VideoTextureOptions);
34
35
  protected _updateProperty(key: string, value: any, oldValue: any): void;
35
36
  protected _onPlayStart: () => void;
@@ -38,6 +39,8 @@ export declare class VideoTexture extends Texture2D<HTMLVideoElement> {
38
39
  protected _onError: (event: ErrorEvent) => void;
39
40
  /** Fired when the video is completed seeking to the current playback position. */
40
41
  protected _onSeeked: () => void;
42
+ protected _flushSeekResolves(): void;
43
+ waitSeek(signal?: AbortSignal): Promise<void>;
41
44
  protected _setupAutoUpdate(): void;
42
45
  protected _videoFrameRequestCallback: () => void;
43
46
  requestUpload: () => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.17.2",
4
+ "version": "0.18.0",
5
5
  "packageManager": "pnpm@10.19.0",
6
6
  "description": "A JavaScript WebGL rendering engine. only the ESM.",
7
7
  "author": "wxm",
@@ -64,8 +64,8 @@
64
64
  "earcut": "^3.0.2",
65
65
  "modern-font": "^0.5.0",
66
66
  "modern-idoc": "^0.11.4",
67
- "modern-path2d": "^1.5.6",
68
- "modern-text": "^1.11.0"
67
+ "modern-path2d": "^1.6.0",
68
+ "modern-text": "^1.11.1"
69
69
  },
70
70
  "peerDependencies": {
71
71
  "lottie-web": "^5",
@@ -84,18 +84,18 @@
84
84
  }
85
85
  },
86
86
  "devDependencies": {
87
- "@antfu/eslint-config": "^8.2.0",
87
+ "@antfu/eslint-config": "^9.0.0",
88
88
  "@types/earcut": "^3.0.0",
89
- "@types/node": "^25.6.2",
89
+ "@types/node": "^25.9.0",
90
90
  "bumpp": "^11.1.0",
91
91
  "conventional-changelog-cli": "^5.0.0",
92
- "eslint": "^10.3.0",
92
+ "eslint": "^10.4.0",
93
93
  "lottie-web": "^5.13.0",
94
94
  "modern-gif": "^2.1.0",
95
95
  "typescript": "^6.0.3",
96
96
  "unbuild": "^3.6.1",
97
- "vite": "^8.0.11",
98
- "vitest": "^4.1.5",
97
+ "vite": "^8.0.13",
98
+ "vitest": "^4.1.6",
99
99
  "yoga-layout": "^3.2.1"
100
100
  }
101
101
  }