@visactor/vrender-kits 1.1.0-alpha.22 → 1.1.0-alpha.24

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.
Files changed (76) hide show
  1. package/cjs/canvas/contributions/harmony/canvas.js +5 -1
  2. package/cjs/canvas/contributions/harmony/canvas.js.map +1 -1
  3. package/cjs/env/contributions/feishu-contribution.d.ts +15 -8
  4. package/cjs/env/contributions/feishu-contribution.js +26 -14
  5. package/cjs/env/contributions/feishu-contribution.js.map +1 -1
  6. package/cjs/env/contributions/harmony-contribution.d.ts +26 -7
  7. package/cjs/env/contributions/harmony-contribution.js +129 -21
  8. package/cjs/env/contributions/harmony-contribution.js.map +1 -1
  9. package/cjs/env/contributions/lynx-contribution.d.ts +0 -4
  10. package/cjs/env/contributions/lynx-contribution.js +7 -21
  11. package/cjs/env/contributions/lynx-contribution.js.map +1 -1
  12. package/cjs/env/contributions/miniapp-canvas.d.ts +18 -0
  13. package/cjs/env/contributions/miniapp-canvas.js +46 -0
  14. package/cjs/env/contributions/miniapp-canvas.js.map +1 -0
  15. package/cjs/env/contributions/taro-contribution.d.ts +6 -10
  16. package/cjs/env/contributions/taro-contribution.js +17 -18
  17. package/cjs/env/contributions/taro-contribution.js.map +1 -1
  18. package/cjs/env/contributions/tt-contribution.d.ts +14 -8
  19. package/cjs/env/contributions/tt-contribution.js +26 -49
  20. package/cjs/env/contributions/tt-contribution.js.map +1 -1
  21. package/cjs/env/contributions/wx-contribution.d.ts +14 -9
  22. package/cjs/env/contributions/wx-contribution.js +26 -53
  23. package/cjs/env/contributions/wx-contribution.js.map +1 -1
  24. package/cjs/register/register-arc3d.js +2 -1
  25. package/cjs/register/register-gif.js +1 -2
  26. package/cjs/register/register-symbol.js +2 -1
  27. package/cjs/tools/dynamicTexture.js +2 -0
  28. package/cjs/window/contributions/feishu-contribution.js +6 -1
  29. package/cjs/window/contributions/feishu-contribution.js.map +1 -1
  30. package/cjs/window/contributions/harmony-contribution.js +70 -11
  31. package/cjs/window/contributions/harmony-contribution.js.map +1 -1
  32. package/cjs/window/contributions/taro-contribution.js +6 -1
  33. package/cjs/window/contributions/taro-contribution.js.map +1 -1
  34. package/cjs/window/contributions/tt-contribution.js +6 -1
  35. package/cjs/window/contributions/tt-contribution.js.map +1 -1
  36. package/cjs/window/contributions/wx-contribution.js +6 -1
  37. package/cjs/window/contributions/wx-contribution.js.map +1 -1
  38. package/dist/index.es.js +464 -191
  39. package/es/canvas/contributions/harmony/canvas.js +5 -1
  40. package/es/canvas/contributions/harmony/canvas.js.map +1 -1
  41. package/es/env/contributions/feishu-contribution.d.ts +15 -8
  42. package/es/env/contributions/feishu-contribution.js +27 -14
  43. package/es/env/contributions/feishu-contribution.js.map +1 -1
  44. package/es/env/contributions/harmony-contribution.d.ts +26 -7
  45. package/es/env/contributions/harmony-contribution.js +132 -22
  46. package/es/env/contributions/harmony-contribution.js.map +1 -1
  47. package/es/env/contributions/lynx-contribution.d.ts +0 -4
  48. package/es/env/contributions/lynx-contribution.js +7 -21
  49. package/es/env/contributions/lynx-contribution.js.map +1 -1
  50. package/es/env/contributions/miniapp-canvas.d.ts +18 -0
  51. package/es/env/contributions/miniapp-canvas.js +37 -0
  52. package/es/env/contributions/miniapp-canvas.js.map +1 -0
  53. package/es/env/contributions/taro-contribution.d.ts +6 -10
  54. package/es/env/contributions/taro-contribution.js +17 -17
  55. package/es/env/contributions/taro-contribution.js.map +1 -1
  56. package/es/env/contributions/tt-contribution.d.ts +14 -8
  57. package/es/env/contributions/tt-contribution.js +28 -48
  58. package/es/env/contributions/tt-contribution.js.map +1 -1
  59. package/es/env/contributions/wx-contribution.d.ts +14 -9
  60. package/es/env/contributions/wx-contribution.js +28 -52
  61. package/es/env/contributions/wx-contribution.js.map +1 -1
  62. package/es/register/register-arc3d.js +2 -1
  63. package/es/register/register-gif.js +1 -2
  64. package/es/register/register-symbol.js +2 -1
  65. package/es/tools/dynamicTexture.js +2 -0
  66. package/es/window/contributions/feishu-contribution.js +6 -1
  67. package/es/window/contributions/feishu-contribution.js.map +1 -1
  68. package/es/window/contributions/harmony-contribution.js +70 -11
  69. package/es/window/contributions/harmony-contribution.js.map +1 -1
  70. package/es/window/contributions/taro-contribution.js +6 -1
  71. package/es/window/contributions/taro-contribution.js.map +1 -1
  72. package/es/window/contributions/tt-contribution.js +6 -1
  73. package/es/window/contributions/tt-contribution.js.map +1 -1
  74. package/es/window/contributions/wx-contribution.js +6 -1
  75. package/es/window/contributions/wx-contribution.js.map +1 -1
  76. package/package.json +218 -2
package/dist/index.es.js CHANGED
@@ -3442,6 +3442,16 @@ class HarmonyCanvas extends BaseCanvas {
3442
3442
  this._context = new HarmonyContext2d(this, this._dpr);
3443
3443
  }
3444
3444
  resize(width, height) {
3445
+ if (!this.controled) {
3446
+ return;
3447
+ }
3448
+ this._pixelWidth = width * this._dpr;
3449
+ this._pixelHeight = height * this._dpr;
3450
+ this._displayWidth = width;
3451
+ this._displayHeight = height;
3452
+ this._nativeCanvas.width = this._pixelWidth;
3453
+ this._nativeCanvas.height = this._pixelHeight;
3454
+ this._context.dpr = this._dpr;
3445
3455
  return;
3446
3456
  }
3447
3457
  release(...params) {
@@ -5381,6 +5391,14 @@ class FeishuWindowHandlerContribution extends BaseWindowHandlerContribution {
5381
5391
  let canvas;
5382
5392
  if (typeof params.canvas === 'string') {
5383
5393
  canvas = this.global.getElementById(params.canvas);
5394
+ if (!canvas) {
5395
+ canvas = this.global.createCanvas({
5396
+ id: params.canvas,
5397
+ width: params.width,
5398
+ height: params.height,
5399
+ dpr: params.dpr
5400
+ });
5401
+ }
5384
5402
  if (!canvas) {
5385
5403
  throw new Error('canvasId 参数不正确,请确认canvas存在并插入dom');
5386
5404
  }
@@ -5955,17 +5973,65 @@ class CanvasWrapEnableWH {
5955
5973
  }
5956
5974
  }
5957
5975
 
5958
- function makeUpCanvas$4(domref, canvasIdLists, canvasMap, freeCanvasIdx, freeCanvasList, pixelRatio) {
5959
- const dpr = pixelRatio !== null && pixelRatio !== void 0 ? pixelRatio : tt.getSystemInfoSync().pixelRatio;
5960
- canvasIdLists.forEach((id, i) => {
5961
- const ctx = tt.createCanvasContext(id);
5962
- const canvas = new CanvasWrapDisableWH(ctx.canvas || {}, ctx, dpr, domref.width, domref.height, id);
5963
- ctx.canvas = canvas;
5964
- canvasMap.set(id, canvas);
5965
- if (i >= freeCanvasIdx) {
5966
- freeCanvasList.push(canvas);
5976
+ function getMiniAppCanvasOptions(params, pixelRatio, offscreen = params.id == null) {
5977
+ var _a, _b, _c;
5978
+ return {
5979
+ id: params.id == null ? undefined : String(params.id),
5980
+ width: (_a = params.width) !== null && _a !== void 0 ? _a : 0,
5981
+ height: (_b = params.height) !== null && _b !== void 0 ? _b : 0,
5982
+ dpr: (_c = params.dpr) !== null && _c !== void 0 ? _c : pixelRatio,
5983
+ offscreen
5984
+ };
5985
+ }
5986
+ function wrapMiniAppNativeCanvas(nativeCanvas, options) {
5987
+ var _a;
5988
+ const ctx = (_a = nativeCanvas === null || nativeCanvas === void 0 ? void 0 : nativeCanvas.getContext) === null || _a === void 0 ? void 0 : _a.call(nativeCanvas, '2d');
5989
+ if (!ctx) {
5990
+ throw new Error('MiniApp canvas bridge returned a canvas without getContext("2d").');
5991
+ }
5992
+ return new CanvasWrapEnableWH(nativeCanvas, ctx, options.dpr, options.width, options.height, options.id);
5993
+ }
5994
+ function wrapMiniAppContextCanvas(ctx, options) {
5995
+ if (!ctx) {
5996
+ throw new Error('MiniApp canvas bridge returned an empty 2d context.');
5997
+ }
5998
+ const canvas = new CanvasWrapDisableWH(ctx.canvas || {}, ctx, options.dpr, options.width, options.height, options.id);
5999
+ ctx.canvas = canvas;
6000
+ return canvas;
6001
+ }
6002
+ function createCanvasWithFactory(params, pixelRatio, canvasMap, factory) {
6003
+ const options = getMiniAppCanvasOptions(params, pixelRatio);
6004
+ const id = options.id;
6005
+ if (id != null) {
6006
+ const existing = canvasMap.get(id);
6007
+ if (existing) {
6008
+ return existing;
5967
6009
  }
5968
- });
6010
+ }
6011
+ if (!factory) {
6012
+ return null;
6013
+ }
6014
+ const canvas = wrapMiniAppNativeCanvas(factory(options), options);
6015
+ if (id != null) {
6016
+ canvasMap.set(id, canvas);
6017
+ }
6018
+ return canvas;
6019
+ }
6020
+
6021
+ const FEISHU_CANVAS_BRIDGE_ERROR = 'Feishu canvas bridge is unavailable. VRender feishu env requires envParams.canvasFactory, ' +
6022
+ 'a Stage canvas object, or a feishu/tt runtime that exposes createCanvasContext(id).';
6023
+ function getFeishuRuntime(params) {
6024
+ var _a, _b, _c, _d, _e;
6025
+ try {
6026
+ return (_c = (_b = (_a = params === null || params === void 0 ? void 0 : params.feishu) !== null && _a !== void 0 ? _a : params === null || params === void 0 ? void 0 : params.tt) !== null && _b !== void 0 ? _b : params === null || params === void 0 ? void 0 : params.runtime) !== null && _c !== void 0 ? _c : (typeof tt !== 'undefined' ? tt : undefined);
6027
+ }
6028
+ catch (_f) {
6029
+ return (_e = (_d = params === null || params === void 0 ? void 0 : params.feishu) !== null && _d !== void 0 ? _d : params === null || params === void 0 ? void 0 : params.tt) !== null && _e !== void 0 ? _e : params === null || params === void 0 ? void 0 : params.runtime;
6030
+ }
6031
+ }
6032
+ function getFeishuPixelRatio(params, runtime = getFeishuRuntime(params)) {
6033
+ var _a, _b, _c, _d;
6034
+ return (_d = (_a = params === null || params === void 0 ? void 0 : params.pixelRatio) !== null && _a !== void 0 ? _a : (_c = (_b = runtime === null || runtime === void 0 ? void 0 : runtime.getSystemInfoSync) === null || _b === void 0 ? void 0 : _b.call(runtime)) === null || _c === void 0 ? void 0 : _c.pixelRatio) !== null && _d !== void 0 ? _d : 1;
5969
6035
  }
5970
6036
  class FeishuEnvContribution extends BaseEnvContribution {
5971
6037
  constructor() {
@@ -5973,8 +6039,7 @@ class FeishuEnvContribution extends BaseEnvContribution {
5973
6039
  this.type = 'feishu';
5974
6040
  this.supportEvent = true;
5975
6041
  this.canvasMap = new Map();
5976
- this.freeCanvasList = [];
5977
- this.canvasIdx = 0;
6042
+ this.feishuEnvParams = {};
5978
6043
  this.supportsTouchEvents = true;
5979
6044
  try {
5980
6045
  this.supportsPointerEvents = !!globalThis.PointerEvent;
@@ -5987,15 +6052,15 @@ class FeishuEnvContribution extends BaseEnvContribution {
5987
6052
  this.applyStyles = true;
5988
6053
  }
5989
6054
  getDynamicCanvasCount() {
5990
- return this.freeCanvasList.length;
6055
+ return 0;
5991
6056
  }
5992
6057
  getStaticCanvasCount() {
5993
6058
  return 9999;
5994
6059
  }
5995
- configure(service, params) {
6060
+ configure(service, params = {}) {
5996
6061
  if (service.env === this.type) {
5997
6062
  service.setActiveEnvContribution(this);
5998
- makeUpCanvas$4(params.domref, params.canvasIdLists, this.canvasMap, params.freeCanvasIdx, this.freeCanvasList, params.pixelRatio);
6063
+ this.feishuEnvParams = params;
5999
6064
  }
6000
6065
  }
6001
6066
  loadImage(url) {
@@ -6008,9 +6073,21 @@ class FeishuEnvContribution extends BaseEnvContribution {
6008
6073
  return Promise.reject();
6009
6074
  }
6010
6075
  createCanvas(params) {
6011
- const result = this.freeCanvasList[this.canvasIdx] || this.freeCanvasList[this.freeCanvasList.length - 1];
6012
- this.canvasIdx++;
6013
- return result;
6076
+ var _a;
6077
+ const envParams = this.feishuEnvParams;
6078
+ const runtime = getFeishuRuntime(envParams);
6079
+ const dpr = (_a = params.dpr) !== null && _a !== void 0 ? _a : getFeishuPixelRatio(envParams, runtime);
6080
+ const factoryCanvas = createCanvasWithFactory(params, dpr, this.canvasMap, envParams.canvasFactory);
6081
+ if (factoryCanvas) {
6082
+ return factoryCanvas;
6083
+ }
6084
+ const options = getMiniAppCanvasOptions(params, dpr, false);
6085
+ if (options.id == null || typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createCanvasContext) !== 'function') {
6086
+ throw new Error(FEISHU_CANVAS_BRIDGE_ERROR);
6087
+ }
6088
+ const canvas = wrapMiniAppContextCanvas(runtime.createCanvasContext(options.id), options);
6089
+ this.canvasMap.set(options.id, canvas);
6090
+ return canvas;
6014
6091
  }
6015
6092
  createOffscreenCanvas(params) {
6016
6093
  return;
@@ -6019,7 +6096,7 @@ class FeishuEnvContribution extends BaseEnvContribution {
6019
6096
  return;
6020
6097
  }
6021
6098
  getDevicePixelRatio() {
6022
- return tt.getSystemInfoSync().pixelRatio;
6099
+ return getFeishuPixelRatio(this.feishuEnvParams);
6023
6100
  }
6024
6101
  getRequestAnimationFrame() {
6025
6102
  return function (callback) {
@@ -6111,6 +6188,73 @@ let MiniAppEventManager$4 = class MiniAppEventManager {
6111
6188
  this.cache = {};
6112
6189
  }
6113
6190
  };
6191
+ function setMiniAppEventTarget$2(event, key, value) {
6192
+ if (!event || !value) {
6193
+ return;
6194
+ }
6195
+ try {
6196
+ event[key] = value;
6197
+ }
6198
+ catch (_a) {
6199
+ Object.defineProperty(event, key, {
6200
+ configurable: true,
6201
+ value
6202
+ });
6203
+ }
6204
+ }
6205
+ function isValidCoordinate$3(value) {
6206
+ return typeof value === 'number' && Number.isFinite(value);
6207
+ }
6208
+ function pickCoordinate$3(...values) {
6209
+ for (let i = 0; i < values.length; i++) {
6210
+ if (isValidCoordinate$3(values[i])) {
6211
+ return values[i];
6212
+ }
6213
+ }
6214
+ return undefined;
6215
+ }
6216
+ function setHarmonyEventValue(event, key, value) {
6217
+ try {
6218
+ event[key] = value;
6219
+ }
6220
+ catch (_a) {
6221
+ Object.defineProperty(event, key, {
6222
+ configurable: true,
6223
+ value
6224
+ });
6225
+ }
6226
+ }
6227
+ function normalizeHarmonyTouchEventPoint(event) {
6228
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
6229
+ const touch = (_b = (_a = event === null || event === void 0 ? void 0 : event.changedTouches) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : (_c = event === null || event === void 0 ? void 0 : event.touches) === null || _c === void 0 ? void 0 : _c[0];
6230
+ if (!touch) {
6231
+ return;
6232
+ }
6233
+ const x = pickCoordinate$3(event.x, event.offsetX, event.clientX, event.pageX, touch.x, touch.offsetX, touch.clientX, touch.pageX);
6234
+ const y = pickCoordinate$3(event.y, event.offsetY, event.clientY, event.pageY, touch.y, touch.offsetY, touch.clientY, touch.pageY);
6235
+ if (x == null || y == null) {
6236
+ return;
6237
+ }
6238
+ if (!event.touches && event.changedTouches) {
6239
+ setHarmonyEventValue(event, 'touches', event.type === 'touchend' || event.type === 'touchcancel' ? [] : event.changedTouches);
6240
+ }
6241
+ setHarmonyEventValue(event, 'x', x);
6242
+ setHarmonyEventValue(event, 'y', y);
6243
+ setHarmonyEventValue(event, 'offsetX', (_d = event.offsetX) !== null && _d !== void 0 ? _d : x);
6244
+ setHarmonyEventValue(event, 'offsetY', (_e = event.offsetY) !== null && _e !== void 0 ? _e : y);
6245
+ setHarmonyEventValue(event, 'clientX', (_f = event.clientX) !== null && _f !== void 0 ? _f : x);
6246
+ setHarmonyEventValue(event, 'clientY', (_g = event.clientY) !== null && _g !== void 0 ? _g : y);
6247
+ setHarmonyEventValue(event, 'pageX', (_h = event.pageX) !== null && _h !== void 0 ? _h : x);
6248
+ setHarmonyEventValue(event, 'pageY', (_j = event.pageY) !== null && _j !== void 0 ? _j : y);
6249
+ touch.x = (_k = touch.x) !== null && _k !== void 0 ? _k : x;
6250
+ touch.y = (_l = touch.y) !== null && _l !== void 0 ? _l : y;
6251
+ touch.offsetX = (_m = touch.offsetX) !== null && _m !== void 0 ? _m : x;
6252
+ touch.offsetY = (_o = touch.offsetY) !== null && _o !== void 0 ? _o : y;
6253
+ touch.clientX = (_p = touch.clientX) !== null && _p !== void 0 ? _p : x;
6254
+ touch.clientY = (_q = touch.clientY) !== null && _q !== void 0 ? _q : y;
6255
+ touch.pageX = (_r = touch.pageX) !== null && _r !== void 0 ? _r : x;
6256
+ touch.pageY = (_s = touch.pageY) !== null && _s !== void 0 ? _s : y;
6257
+ }
6114
6258
  class HarmonyWindowHandlerContribution extends BaseWindowHandlerContribution {
6115
6259
  get container() {
6116
6260
  return null;
@@ -6144,7 +6288,8 @@ class HarmonyWindowHandlerContribution extends BaseWindowHandlerContribution {
6144
6288
  createWindowByConfig(params) {
6145
6289
  const nativeCanvas = this.global.createCanvas({
6146
6290
  width: params.width,
6147
- height: params.height
6291
+ height: params.height,
6292
+ dpr: params.dpr
6148
6293
  });
6149
6294
  const options = {
6150
6295
  width: params.width,
@@ -6160,6 +6305,14 @@ class HarmonyWindowHandlerContribution extends BaseWindowHandlerContribution {
6160
6305
  let canvas;
6161
6306
  if (typeof params.canvas === 'string') {
6162
6307
  canvas = this.global.getElementById(params.canvas);
6308
+ if (!canvas) {
6309
+ canvas = this.global.createCanvas({
6310
+ id: params.canvas,
6311
+ width: params.width,
6312
+ height: params.height,
6313
+ dpr: params.dpr
6314
+ });
6315
+ }
6163
6316
  if (!canvas) {
6164
6317
  throw new Error('canvasId 参数不正确,请确认canvas存在并插入dom');
6165
6318
  }
@@ -6174,15 +6327,22 @@ class HarmonyWindowHandlerContribution extends BaseWindowHandlerContribution {
6174
6327
  width = data.width;
6175
6328
  height = data.height;
6176
6329
  }
6330
+ let dpr = params.dpr;
6331
+ if (dpr == null) {
6332
+ dpr = canvas.width / width;
6333
+ }
6177
6334
  this.canvas = new HarmonyCanvas({
6178
6335
  width: width,
6179
6336
  height: height,
6180
- dpr: 1,
6337
+ dpr: dpr,
6181
6338
  nativeCanvas: canvas,
6182
6339
  canvasControled: params.canvasControled
6183
6340
  });
6184
6341
  }
6185
6342
  releaseWindow() {
6343
+ var _a, _b;
6344
+ this.eventManager.cleanEvent();
6345
+ (_b = (_a = this.canvas) === null || _a === void 0 ? void 0 : _a.release) === null || _b === void 0 ? void 0 : _b.call(_a);
6186
6346
  return;
6187
6347
  }
6188
6348
  resizeWindow(width, height) {
@@ -6207,18 +6367,15 @@ class HarmonyWindowHandlerContribution extends BaseWindowHandlerContribution {
6207
6367
  this.eventManager.removeEventListener(type, listener);
6208
6368
  }
6209
6369
  dispatchEvent(event) {
6370
+ var _a;
6210
6371
  const { type } = event;
6211
6372
  if (!this.eventManager.cache[type]) {
6212
6373
  return false;
6213
6374
  }
6214
- if (event.changedTouches && event.changedTouches[0]) {
6215
- event.offsetX = event.changedTouches[0].x;
6216
- event.changedTouches[0].offsetX = event.changedTouches[0].x;
6217
- event.changedTouches[0].clientX = event.changedTouches[0].x;
6218
- event.offsetY = event.changedTouches[0].y;
6219
- event.changedTouches[0].offsetY = event.changedTouches[0].y;
6220
- event.changedTouches[0].clientY = event.changedTouches[0].y;
6221
- }
6375
+ const nativeCanvas = (_a = this.canvas) === null || _a === void 0 ? void 0 : _a.nativeCanvas;
6376
+ setMiniAppEventTarget$2(event, 'target', nativeCanvas);
6377
+ setMiniAppEventTarget$2(event, 'currentTarget', nativeCanvas);
6378
+ normalizeHarmonyTouchEventPoint(event);
6222
6379
  event.preventDefault = () => {
6223
6380
  return;
6224
6381
  };
@@ -6279,31 +6436,114 @@ function bindHarmonyWindowContribution(container) {
6279
6436
  }
6280
6437
  }
6281
6438
 
6282
- function createCanvas(width, height, id) {
6283
- const _c = new OffscreenCanvas(width, height);
6284
- const context = _c.getContext('2d');
6285
- const nativeCanvas = {
6439
+ const HARMONY_CANVAS_BRIDGE_ERROR = 'Harmony canvas bridge is unavailable. VRender Harmony env requires envParams.canvasFactory ' +
6440
+ 'or a Harmony runtime that exposes a global createCanvas/createOffscreenCanvas capability.';
6441
+ const HARMONY_CANVAS_SIZE_ERROR = 'Harmony canvas size is unavailable. Pass stage width/height when creating a Harmony stage canvas.';
6442
+ function isValidCoordinate$2(value) {
6443
+ return typeof value === 'number' && Number.isFinite(value);
6444
+ }
6445
+ function pickCoordinate$2(...values) {
6446
+ for (let i = 0; i < values.length; i++) {
6447
+ if (isValidCoordinate$2(values[i])) {
6448
+ return values[i];
6449
+ }
6450
+ }
6451
+ return undefined;
6452
+ }
6453
+ function getPrimaryTouch$1(event) {
6454
+ var _a, _b, _c;
6455
+ return (_b = (_a = event === null || event === void 0 ? void 0 : event.changedTouches) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : (_c = event === null || event === void 0 ? void 0 : event.touches) === null || _c === void 0 ? void 0 : _c[0];
6456
+ }
6457
+ function getHarmonyEventPoint(event) {
6458
+ const touch = getPrimaryTouch$1(event);
6459
+ const x = pickCoordinate$2(event === null || event === void 0 ? void 0 : event.x, event === null || event === void 0 ? void 0 : event.offsetX, event === null || event === void 0 ? void 0 : event.clientX, event === null || event === void 0 ? void 0 : event.pageX, touch === null || touch === void 0 ? void 0 : touch.x, touch === null || touch === void 0 ? void 0 : touch.offsetX, touch === null || touch === void 0 ? void 0 : touch.clientX, touch === null || touch === void 0 ? void 0 : touch.pageX);
6460
+ const y = pickCoordinate$2(event === null || event === void 0 ? void 0 : event.y, event === null || event === void 0 ? void 0 : event.offsetY, event === null || event === void 0 ? void 0 : event.clientY, event === null || event === void 0 ? void 0 : event.pageY, touch === null || touch === void 0 ? void 0 : touch.y, touch === null || touch === void 0 ? void 0 : touch.offsetY, touch === null || touch === void 0 ? void 0 : touch.clientY, touch === null || touch === void 0 ? void 0 : touch.pageY);
6461
+ return x == null || y == null ? null : { x, y };
6462
+ }
6463
+ function getHarmonyRuntime(params) {
6464
+ var _a;
6465
+ return (_a = params === null || params === void 0 ? void 0 : params.harmony) !== null && _a !== void 0 ? _a : params === null || params === void 0 ? void 0 : params.runtime;
6466
+ }
6467
+ function getHarmonyPixelRatio(params) {
6468
+ var _a;
6469
+ return (_a = params === null || params === void 0 ? void 0 : params.pixelRatio) !== null && _a !== void 0 ? _a : 1;
6470
+ }
6471
+ function getCanvasSize$1(width, height) {
6472
+ if (!isValidCoordinate$2(width) || !isValidCoordinate$2(height)) {
6473
+ throw new Error(HARMONY_CANVAS_SIZE_ERROR);
6474
+ }
6475
+ return { width, height };
6476
+ }
6477
+ function getGlobalOffscreenCanvasCtor() {
6478
+ try {
6479
+ return typeof OffscreenCanvas !== 'undefined' ? OffscreenCanvas : undefined;
6480
+ }
6481
+ catch (err) {
6482
+ return undefined;
6483
+ }
6484
+ }
6485
+ function createFallbackOffscreenCanvas(width, height) {
6486
+ const OffscreenCanvasCtor = getGlobalOffscreenCanvasCtor();
6487
+ if (typeof OffscreenCanvasCtor !== 'function') {
6488
+ return null;
6489
+ }
6490
+ return new OffscreenCanvasCtor(width, height);
6491
+ }
6492
+ function wrapHarmonyNativeCanvas(nativeCanvas, id, width, height, dpr) {
6493
+ var _a, _b, _c;
6494
+ nativeCanvas.width = width * dpr;
6495
+ nativeCanvas.height = height * dpr;
6496
+ const context = (_b = (_a = nativeCanvas.getContext) === null || _a === void 0 ? void 0 : _a.call(nativeCanvas, '2d')) !== null && _b !== void 0 ? _b : (_c = nativeCanvas.getContext) === null || _c === void 0 ? void 0 : _c.call(nativeCanvas);
6497
+ if (!context) {
6498
+ throw new Error(HARMONY_CANVAS_BRIDGE_ERROR);
6499
+ }
6500
+ if (typeof nativeCanvas.getBoundingClientRect !== 'function') {
6501
+ nativeCanvas.getBoundingClientRect = () => ({
6502
+ width,
6503
+ height
6504
+ });
6505
+ }
6506
+ return new CanvasWrapEnableWH(nativeCanvas, context, dpr, width, height, id);
6507
+ }
6508
+ function createHarmonyNativeCanvas(id, width, height, dpr, offscreen, params, runtime) {
6509
+ const options = {
6510
+ id,
6286
6511
  width,
6287
6512
  height,
6288
- context,
6289
- _c,
6290
- getBoundingClientRect() {
6291
- return {
6292
- width,
6293
- height
6294
- };
6295
- },
6296
- getContext() {
6297
- return context;
6298
- }
6513
+ dpr,
6514
+ offscreen
6299
6515
  };
6300
- return new CanvasWrapDisableWH(nativeCanvas, context, 1, width, height, id);
6516
+ if (params.canvasFactory) {
6517
+ return params.canvasFactory(options);
6518
+ }
6519
+ if (offscreen && typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createOffscreenCanvas) === 'function') {
6520
+ const canvas = runtime.createOffscreenCanvas(options);
6521
+ if (canvas) {
6522
+ return canvas;
6523
+ }
6524
+ }
6525
+ if (!offscreen && typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createCanvas) === 'function') {
6526
+ const canvas = runtime.createCanvas(options);
6527
+ if (canvas) {
6528
+ return canvas;
6529
+ }
6530
+ }
6531
+ if (offscreen) {
6532
+ const canvas = createFallbackOffscreenCanvas(width * dpr, height * dpr);
6533
+ if (canvas) {
6534
+ return canvas;
6535
+ }
6536
+ }
6537
+ throw new Error(HARMONY_CANVAS_BRIDGE_ERROR);
6301
6538
  }
6302
6539
  class HarmonyEnvContribution extends BaseEnvContribution {
6303
6540
  constructor() {
6304
6541
  super();
6305
6542
  this.type = 'harmony';
6306
6543
  this.supportEvent = true;
6544
+ this.canvasMap = new Map();
6545
+ this.freeCanvasList = [];
6546
+ this.canvasIdx = 0;
6307
6547
  this.supportsTouchEvents = true;
6308
6548
  try {
6309
6549
  this.supportsPointerEvents = !!globalThis.PointerEvent;
@@ -6316,9 +6556,11 @@ class HarmonyEnvContribution extends BaseEnvContribution {
6316
6556
  this.applyStyles = true;
6317
6557
  this.rafSTO = new RafBasedSTO(0);
6318
6558
  }
6319
- configure(service, params) {
6559
+ configure(service, params = {}) {
6320
6560
  if (service.env === this.type) {
6321
6561
  service.setActiveEnvContribution(this);
6562
+ this.harmonyEnvParams = params;
6563
+ this.harmonyRuntime = getHarmonyRuntime(params);
6322
6564
  }
6323
6565
  }
6324
6566
  getDynamicCanvasCount() {
@@ -6328,13 +6570,63 @@ class HarmonyEnvContribution extends BaseEnvContribution {
6328
6570
  return 9999;
6329
6571
  }
6330
6572
  loadImage(url) {
6331
- return;
6573
+ var _a;
6574
+ if (typeof ((_a = this.harmonyRuntime) === null || _a === void 0 ? void 0 : _a.createImage) !== 'function') {
6575
+ return Promise.resolve({
6576
+ data: null,
6577
+ loadState: 'fail'
6578
+ });
6579
+ }
6580
+ const img = this.harmonyRuntime.createImage(url);
6581
+ return new Promise(resolve => {
6582
+ img.onload = () => {
6583
+ resolve({
6584
+ data: img,
6585
+ loadState: 'success'
6586
+ });
6587
+ };
6588
+ img.onerror = () => {
6589
+ resolve({
6590
+ data: null,
6591
+ loadState: 'fail'
6592
+ });
6593
+ };
6594
+ });
6332
6595
  }
6333
6596
  loadSvg(url) {
6334
- return Promise.reject();
6597
+ return Promise.resolve({
6598
+ data: null,
6599
+ loadState: 'fail'
6600
+ });
6335
6601
  }
6336
6602
  createCanvas(params) {
6337
- return createCanvas(params.width, params.height, params.id);
6603
+ var _a, _b;
6604
+ const envParams = (_a = this.harmonyEnvParams) !== null && _a !== void 0 ? _a : {};
6605
+ const runtime = getHarmonyRuntime(envParams);
6606
+ const dpr = (_b = params.dpr) !== null && _b !== void 0 ? _b : getHarmonyPixelRatio(envParams);
6607
+ const size = getCanvasSize$1(params.width, params.height);
6608
+ if (params.id != null) {
6609
+ const id = String(params.id);
6610
+ const existing = this.canvasMap.get(id);
6611
+ if (existing) {
6612
+ return existing;
6613
+ }
6614
+ const nativeCanvas = createHarmonyNativeCanvas(id, size.width, size.height, dpr, false, envParams, runtime);
6615
+ const canvas = wrapHarmonyNativeCanvas(nativeCanvas, id, size.width, size.height, dpr);
6616
+ this.canvasMap.set(id, canvas);
6617
+ return canvas;
6618
+ }
6619
+ const result = this.freeCanvasList[this.canvasIdx] || this.freeCanvasList[this.freeCanvasList.length - 1];
6620
+ this.canvasIdx++;
6621
+ if (result) {
6622
+ return result;
6623
+ }
6624
+ const id = Math.random().toString();
6625
+ const nativeCanvas = createHarmonyNativeCanvas(id, size.width, size.height, dpr, true, envParams, runtime);
6626
+ const canvas = wrapHarmonyNativeCanvas(nativeCanvas, id, size.width, size.height, dpr);
6627
+ this.canvasMap.set(id, canvas);
6628
+ this.freeCanvasList.push(canvas);
6629
+ return canvas;
6338
6630
  }
6339
6631
  createOffscreenCanvas(params) {
6340
6632
  return;
@@ -6343,7 +6635,7 @@ class HarmonyEnvContribution extends BaseEnvContribution {
6343
6635
  return;
6344
6636
  }
6345
6637
  getDevicePixelRatio() {
6346
- return 1;
6638
+ return getHarmonyPixelRatio(this.harmonyEnvParams);
6347
6639
  }
6348
6640
  getRequestAnimationFrame() {
6349
6641
  return (callback) => {
@@ -6357,10 +6649,7 @@ class HarmonyEnvContribution extends BaseEnvContribution {
6357
6649
  }
6358
6650
  mapToCanvasPoint(event) {
6359
6651
  var _a;
6360
- if ((_a = event === null || event === void 0 ? void 0 : event.type) === null || _a === void 0 ? void 0 : _a.startsWith('mouse')) {
6361
- return event;
6362
- }
6363
- return event;
6652
+ return (_a = getHarmonyEventPoint(event)) !== null && _a !== void 0 ? _a : event;
6364
6653
  }
6365
6654
  addEventListener(type, listener, options) {
6366
6655
  return null;
@@ -6372,7 +6661,8 @@ class HarmonyEnvContribution extends BaseEnvContribution {
6372
6661
  return null;
6373
6662
  }
6374
6663
  getElementById(str) {
6375
- return null;
6664
+ var _a;
6665
+ return (_a = this.canvasMap.get(str)) !== null && _a !== void 0 ? _a : null;
6376
6666
  }
6377
6667
  getRootElement() {
6378
6668
  return null;
@@ -6763,13 +7053,11 @@ function createBoundLynxCanvas(id, runtime) {
6763
7053
  }
6764
7054
  return null;
6765
7055
  }
6766
- function getCanvasSize(domref, width, height) {
6767
- const resolvedWidth = width !== null && width !== void 0 ? width : domref === null || domref === void 0 ? void 0 : domref.width;
6768
- const resolvedHeight = height !== null && height !== void 0 ? height : domref === null || domref === void 0 ? void 0 : domref.height;
6769
- if (!isValidCoordinate(resolvedWidth) || !isValidCoordinate(resolvedHeight)) {
7056
+ function getCanvasSize(width, height) {
7057
+ if (!isValidCoordinate(width) || !isValidCoordinate(height)) {
6770
7058
  throw new Error(LYNX_CANVAS_SIZE_ERROR);
6771
7059
  }
6772
- return { width: resolvedWidth, height: resolvedHeight };
7060
+ return { width, height };
6773
7061
  }
6774
7062
  function wrapLynxNativeCanvas(nativeCanvas, id, width, height, dpr) {
6775
7063
  nativeCanvas.width = width * dpr;
@@ -6800,32 +7088,6 @@ function createLynxNativeCanvas(id, width, height, dpr, offscreen, params, runti
6800
7088
  }
6801
7089
  throw new Error(LYNX_CANVAS_BRIDGE_ERROR);
6802
7090
  }
6803
- function makeUpCanvas$3(params = {}, canvasMap, freeCanvasList) {
6804
- const runtime = getLynxRuntime(params);
6805
- const { domref, canvasIdLists = [], freeCanvasIdx = 0 } = params;
6806
- const offscreen = !!params.offscreen;
6807
- const dpr = getLynxPixelRatio(params, runtime);
6808
- canvasIdLists.forEach((id, i) => {
6809
- const size = getCanvasSize(domref);
6810
- const _canvas = createLynxNativeCanvas(id, size.width, size.height, dpr, offscreen, params, runtime);
6811
- const canvas = wrapLynxNativeCanvas(_canvas, id, size.width, size.height, dpr);
6812
- canvasMap.set(id, canvas);
6813
- if (i > freeCanvasIdx) {
6814
- freeCanvasList.push(canvas);
6815
- }
6816
- });
6817
- if (!freeCanvasList.length && domref && typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createOffscreenCanvas) === 'function') {
6818
- const size = getCanvasSize(domref);
6819
- const _canvas = runtime.createOffscreenCanvas();
6820
- _canvas.width = size.width * dpr;
6821
- _canvas.height = size.height * dpr;
6822
- const ctx = _canvas.getContext('2d');
6823
- const id = Math.random().toString();
6824
- const canvas = new CanvasWrapEnableWH(_canvas, ctx, dpr, size.width, size.height, id);
6825
- canvasMap.set(id, canvas);
6826
- freeCanvasList.push(canvas);
6827
- }
6828
- }
6829
7091
  function createImageElement(src, isSvg = false, runtime = getGlobalLynxRuntime()) {
6830
7092
  if (isSvg) {
6831
7093
  return Promise.reject();
@@ -6868,7 +7130,6 @@ class LynxEnvContribution extends BaseEnvContribution {
6868
7130
  service.setActiveEnvContribution(this);
6869
7131
  this.lynxEnvParams = params;
6870
7132
  this.lynxRuntime = getLynxRuntime(params);
6871
- makeUpCanvas$3(params, this.canvasMap, this.freeCanvasList);
6872
7133
  }
6873
7134
  }
6874
7135
  getDynamicCanvasCount() {
@@ -6910,7 +7171,7 @@ class LynxEnvContribution extends BaseEnvContribution {
6910
7171
  const envParams = (_a = this.lynxEnvParams) !== null && _a !== void 0 ? _a : {};
6911
7172
  const runtime = getLynxRuntime(envParams);
6912
7173
  const dpr = (_b = params.dpr) !== null && _b !== void 0 ? _b : getLynxPixelRatio(envParams, runtime);
6913
- const size = getCanvasSize(envParams.domref, params.width, params.height);
7174
+ const size = getCanvasSize(params.width, params.height);
6914
7175
  const nativeCanvas = createLynxNativeCanvas(id, size.width, size.height, dpr, false, envParams, runtime);
6915
7176
  const canvas = wrapLynxNativeCanvas(nativeCanvas, id, size.width, size.height, dpr);
6916
7177
  this.canvasMap.set(id, canvas);
@@ -6924,7 +7185,7 @@ class LynxEnvContribution extends BaseEnvContribution {
6924
7185
  const envParams = (_c = this.lynxEnvParams) !== null && _c !== void 0 ? _c : {};
6925
7186
  const runtime = getLynxRuntime(envParams);
6926
7187
  const dpr = (_d = params.dpr) !== null && _d !== void 0 ? _d : getLynxPixelRatio(envParams, runtime);
6927
- const size = getCanvasSize(envParams.domref, params.width, params.height);
7188
+ const size = getCanvasSize(params.width, params.height);
6928
7189
  const id = Math.random().toString();
6929
7190
  const nativeCanvas = createLynxNativeCanvas(id, size.width, size.height, dpr, true, envParams, runtime);
6930
7191
  const canvas = wrapLynxNativeCanvas(nativeCanvas, id, size.width, size.height, dpr);
@@ -7347,6 +7608,14 @@ class TaroWindowHandlerContribution extends BaseWindowHandlerContribution {
7347
7608
  let canvas;
7348
7609
  if (typeof params.canvas === 'string') {
7349
7610
  canvas = this.global.getElementById(params.canvas);
7611
+ if (!canvas) {
7612
+ canvas = this.global.createCanvas({
7613
+ id: params.canvas,
7614
+ width: params.width,
7615
+ height: params.height,
7616
+ dpr: params.dpr
7617
+ });
7618
+ }
7350
7619
  if (!canvas) {
7351
7620
  throw new Error('canvasId 参数不正确,请确认canvas存在并插入dom');
7352
7621
  }
@@ -7474,26 +7743,16 @@ function bindTaroWindowContribution(container) {
7474
7743
  }
7475
7744
  }
7476
7745
 
7477
- function makeUpCanvas$2(domref, canvasIdLists, canvasMap, freeCanvasIdx, freeCanvasList, taro, dpr) {
7478
- canvasIdLists.forEach((id, i) => {
7479
- const ctx = taro.createCanvasContext(id);
7480
- const canvas = new CanvasWrapDisableWH(ctx.canvas || {}, ctx, dpr, domref.width, domref.height, id);
7481
- ctx.canvas = canvas;
7482
- canvasMap.set(id, canvas);
7483
- if (i >= freeCanvasIdx) {
7484
- freeCanvasList.push(canvas);
7485
- }
7486
- return canvas;
7487
- });
7488
- }
7746
+ const TARO_CANVAS_BRIDGE_ERROR = 'Taro canvas bridge is unavailable. VRender taro env requires envParams.canvasFactory, ' +
7747
+ 'a Stage canvas object, or envParams.taro.createCanvasContext(id).';
7489
7748
  class TaroEnvContribution extends BaseEnvContribution {
7490
7749
  constructor() {
7491
7750
  super();
7492
7751
  this.type = 'taro';
7493
7752
  this.supportEvent = true;
7494
7753
  this.canvasMap = new Map();
7495
- this.freeCanvasList = [];
7496
- this.canvasIdx = 0;
7754
+ this.pixelRatio = 1;
7755
+ this.taroEnvParams = {};
7497
7756
  this.supportsTouchEvents = true;
7498
7757
  try {
7499
7758
  this.supportsPointerEvents = !!globalThis.PointerEvent;
@@ -7506,7 +7765,7 @@ class TaroEnvContribution extends BaseEnvContribution {
7506
7765
  this.applyStyles = true;
7507
7766
  }
7508
7767
  getDynamicCanvasCount() {
7509
- return this.freeCanvasList.length;
7768
+ return 0;
7510
7769
  }
7511
7770
  getStaticCanvasCount() {
7512
7771
  return 9999;
@@ -7518,12 +7777,13 @@ class TaroEnvContribution extends BaseEnvContribution {
7518
7777
  }
7519
7778
  return event;
7520
7779
  }
7521
- configure(service, params) {
7780
+ configure(service, params = {}) {
7781
+ var _a;
7522
7782
  if (service.env === this.type) {
7523
7783
  service.setActiveEnvContribution(this);
7524
- makeUpCanvas$2(params.domref, params.canvasIdLists, this.canvasMap, params.freeCanvasIdx, this.freeCanvasList, params.taro, params.pixelRatio);
7784
+ this.taroEnvParams = params;
7525
7785
  this.taro = params.taro;
7526
- this.pixelRatio = params.pixelRatio;
7786
+ this.pixelRatio = (_a = params.pixelRatio) !== null && _a !== void 0 ? _a : 1;
7527
7787
  }
7528
7788
  }
7529
7789
  loadImage(url) {
@@ -7533,7 +7793,7 @@ class TaroEnvContribution extends BaseEnvContribution {
7533
7793
  });
7534
7794
  }
7535
7795
  loadSvg(svgStr) {
7536
- const _window = window || globalThis;
7796
+ const _window = typeof window !== 'undefined' ? window : globalThis;
7537
7797
  if (_window.DOMParser) {
7538
7798
  const parser = new _window.DOMParser();
7539
7799
  const svg = parser.parseFromString(svgStr, 'image/svg+xml').children[0];
@@ -7555,9 +7815,20 @@ class TaroEnvContribution extends BaseEnvContribution {
7555
7815
  return Promise.reject();
7556
7816
  }
7557
7817
  createCanvas(params) {
7558
- const result = this.freeCanvasList[this.canvasIdx] || this.freeCanvasList[this.freeCanvasList.length - 1];
7559
- this.canvasIdx++;
7560
- return result;
7818
+ var _a, _b;
7819
+ const envParams = this.taroEnvParams;
7820
+ const dpr = (_a = params.dpr) !== null && _a !== void 0 ? _a : this.getDevicePixelRatio();
7821
+ const factoryCanvas = createCanvasWithFactory(params, dpr, this.canvasMap, envParams.canvasFactory);
7822
+ if (factoryCanvas) {
7823
+ return factoryCanvas;
7824
+ }
7825
+ const options = getMiniAppCanvasOptions(params, dpr, false);
7826
+ if (options.id == null || typeof ((_b = envParams.taro) === null || _b === void 0 ? void 0 : _b.createCanvasContext) !== 'function') {
7827
+ throw new Error(TARO_CANVAS_BRIDGE_ERROR);
7828
+ }
7829
+ const canvas = wrapMiniAppContextCanvas(envParams.taro.createCanvasContext(options.id), options);
7830
+ this.canvasMap.set(options.id, canvas);
7831
+ return canvas;
7561
7832
  }
7562
7833
  createOffscreenCanvas(params) {
7563
7834
  return;
@@ -7696,6 +7967,14 @@ class TTWindowHandlerContribution extends BaseWindowHandlerContribution {
7696
7967
  let canvas;
7697
7968
  if (typeof params.canvas === 'string') {
7698
7969
  canvas = this.global.getElementById(params.canvas);
7970
+ if (!canvas) {
7971
+ canvas = this.global.createCanvas({
7972
+ id: params.canvas,
7973
+ width: params.width,
7974
+ height: params.height,
7975
+ dpr: params.dpr
7976
+ });
7977
+ }
7699
7978
  if (!canvas) {
7700
7979
  throw new Error('canvasId 参数不正确,请确认canvas存在并插入dom');
7701
7980
  }
@@ -7819,34 +8098,20 @@ function bindTTWindowContribution(container) {
7819
8098
  }
7820
8099
  }
7821
8100
 
7822
- function makeUpCanvas$1(domref, canvasIdLists, canvasMap, freeCanvasIdx, freeCanvasList, component) {
7823
- return __awaiter(this, void 0, void 0, function* () {
7824
- const dpr = tt.getSystemInfoSync().pixelRatio;
7825
- for (let i = 0; i < canvasIdLists.length; i++) {
7826
- const id = canvasIdLists[i];
7827
- yield new Promise(resolve => {
7828
- let data = tt.createSelectorQuery();
7829
- if (component) {
7830
- data = data.in(component);
7831
- }
7832
- data
7833
- .select(`#${id}`)
7834
- .node()
7835
- .exec((res) => {
7836
- const canvas = res[0].node;
7837
- const width = canvas.width;
7838
- const height = canvas.height;
7839
- canvas.width = width * dpr;
7840
- canvas.height = height * dpr;
7841
- canvasMap.set(id, canvas);
7842
- if (i >= freeCanvasIdx) {
7843
- freeCanvasList.push(canvas);
7844
- }
7845
- resolve(null);
7846
- });
7847
- });
7848
- }
7849
- });
8101
+ const TT_CANVAS_BRIDGE_ERROR = 'TT canvas bridge is unavailable. VRender tt env requires envParams.canvasFactory, ' +
8102
+ 'a Stage canvas object, or a tt runtime that exposes createCanvasContext(id).';
8103
+ function getTTRuntime(params) {
8104
+ var _a, _b, _c;
8105
+ try {
8106
+ return (_b = (_a = params === null || params === void 0 ? void 0 : params.tt) !== null && _a !== void 0 ? _a : params === null || params === void 0 ? void 0 : params.runtime) !== null && _b !== void 0 ? _b : (typeof tt !== 'undefined' ? tt : undefined);
8107
+ }
8108
+ catch (_d) {
8109
+ return (_c = params === null || params === void 0 ? void 0 : params.tt) !== null && _c !== void 0 ? _c : params === null || params === void 0 ? void 0 : params.runtime;
8110
+ }
8111
+ }
8112
+ function getTTPixelRatio(params, runtime = getTTRuntime(params)) {
8113
+ var _a, _b, _c, _d;
8114
+ return (_d = (_a = params === null || params === void 0 ? void 0 : params.pixelRatio) !== null && _a !== void 0 ? _a : (_c = (_b = runtime === null || runtime === void 0 ? void 0 : runtime.getSystemInfoSync) === null || _b === void 0 ? void 0 : _b.call(runtime)) === null || _c === void 0 ? void 0 : _c.pixelRatio) !== null && _d !== void 0 ? _d : 1;
7850
8115
  }
7851
8116
  class TTEnvContribution extends BaseEnvContribution {
7852
8117
  constructor() {
@@ -7854,8 +8119,7 @@ class TTEnvContribution extends BaseEnvContribution {
7854
8119
  this.type = 'tt';
7855
8120
  this.supportEvent = true;
7856
8121
  this.canvasMap = new Map();
7857
- this.freeCanvasList = [];
7858
- this.canvasIdx = 0;
8122
+ this.ttEnvParams = {};
7859
8123
  this.supportsTouchEvents = true;
7860
8124
  try {
7861
8125
  this.supportsPointerEvents = !!globalThis.PointerEvent;
@@ -7867,11 +8131,10 @@ class TTEnvContribution extends BaseEnvContribution {
7867
8131
  }
7868
8132
  this.applyStyles = true;
7869
8133
  }
7870
- configure(service, params) {
8134
+ configure(service, params = {}) {
7871
8135
  if (service.env === this.type) {
7872
8136
  service.setActiveEnvContribution(this);
7873
- return makeUpCanvas$1(params.domref, params.canvasIdLists, this.canvasMap, params.freeCanvasIdx, this.freeCanvasList, params.component).then(() => {
7874
- });
8137
+ this.ttEnvParams = params;
7875
8138
  }
7876
8139
  }
7877
8140
  loadImage(url) {
@@ -7884,9 +8147,21 @@ class TTEnvContribution extends BaseEnvContribution {
7884
8147
  return Promise.reject();
7885
8148
  }
7886
8149
  createCanvas(params) {
7887
- const result = this.freeCanvasList[this.canvasIdx] || this.freeCanvasList[this.freeCanvasList.length - 1];
7888
- this.canvasIdx++;
7889
- return result;
8150
+ var _a;
8151
+ const envParams = this.ttEnvParams;
8152
+ const runtime = getTTRuntime(envParams);
8153
+ const dpr = (_a = params.dpr) !== null && _a !== void 0 ? _a : getTTPixelRatio(envParams, runtime);
8154
+ const factoryCanvas = createCanvasWithFactory(params, dpr, this.canvasMap, envParams.canvasFactory);
8155
+ if (factoryCanvas) {
8156
+ return factoryCanvas;
8157
+ }
8158
+ const options = getMiniAppCanvasOptions(params, dpr, false);
8159
+ if (options.id == null || typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createCanvasContext) !== 'function') {
8160
+ throw new Error(TT_CANVAS_BRIDGE_ERROR);
8161
+ }
8162
+ const canvas = wrapMiniAppContextCanvas(runtime.createCanvasContext(options.id), options);
8163
+ this.canvasMap.set(options.id, canvas);
8164
+ return canvas;
7890
8165
  }
7891
8166
  createOffscreenCanvas(params) {
7892
8167
  return;
@@ -7895,7 +8170,7 @@ class TTEnvContribution extends BaseEnvContribution {
7895
8170
  return;
7896
8171
  }
7897
8172
  getDevicePixelRatio() {
7898
- return tt.getSystemInfoSync().pixelRatio;
8173
+ return getTTPixelRatio(this.ttEnvParams);
7899
8174
  }
7900
8175
  getRequestAnimationFrame() {
7901
8176
  return function (callback) {
@@ -8050,6 +8325,14 @@ class WxWindowHandlerContribution extends BaseWindowHandlerContribution {
8050
8325
  let canvas;
8051
8326
  if (typeof params.canvas === 'string') {
8052
8327
  canvas = this.global.getElementById(params.canvas);
8328
+ if (!canvas) {
8329
+ canvas = this.global.createCanvas({
8330
+ id: params.canvas,
8331
+ width: params.width,
8332
+ height: params.height,
8333
+ dpr: params.dpr
8334
+ });
8335
+ }
8053
8336
  if (!canvas) {
8054
8337
  throw new Error('canvasId 参数不正确,请确认canvas存在并插入dom');
8055
8338
  }
@@ -8177,40 +8460,20 @@ function bindWxWindowContribution(container) {
8177
8460
  }
8178
8461
  }
8179
8462
 
8180
- function makeUpCanvas(domref, canvasIdLists, canvasMap, freeCanvasIdx, freeCanvasList, component, forceUpdate) {
8181
- return __awaiter(this, void 0, void 0, function* () {
8182
- const dpr = wx.getSystemInfoSync().pixelRatio;
8183
- for (let i = 0; i < canvasIdLists.length; i++) {
8184
- const id = canvasIdLists[i];
8185
- if (!forceUpdate && canvasMap.has(id)) {
8186
- continue;
8187
- }
8188
- yield new Promise(resolve => {
8189
- let data = wx.createSelectorQuery();
8190
- if (component) {
8191
- data = data.in(component);
8192
- }
8193
- data
8194
- .select(`#${id}`)
8195
- .fields({ node: true, size: true })
8196
- .exec((res) => {
8197
- if (!res[0]) {
8198
- return;
8199
- }
8200
- const canvas = res[0].node;
8201
- const width = res[0].width;
8202
- const height = res[0].height;
8203
- canvas.width = width * dpr;
8204
- canvas.height = height * dpr;
8205
- canvasMap.set(id, canvas);
8206
- if (i >= freeCanvasIdx) {
8207
- freeCanvasList.push(canvas);
8208
- }
8209
- resolve(null);
8210
- });
8211
- });
8212
- }
8213
- });
8463
+ const WX_CANVAS_BRIDGE_ERROR = 'Wx canvas bridge is unavailable. VRender wx env requires envParams.canvasFactory, ' +
8464
+ 'a Stage canvas object, or a wx runtime that exposes createCanvasContext(id).';
8465
+ function getWxRuntime(params) {
8466
+ var _a, _b, _c;
8467
+ try {
8468
+ return (_b = (_a = params === null || params === void 0 ? void 0 : params.wx) !== null && _a !== void 0 ? _a : params === null || params === void 0 ? void 0 : params.runtime) !== null && _b !== void 0 ? _b : (typeof wx !== 'undefined' ? wx : undefined);
8469
+ }
8470
+ catch (_d) {
8471
+ return (_c = params === null || params === void 0 ? void 0 : params.wx) !== null && _c !== void 0 ? _c : params === null || params === void 0 ? void 0 : params.runtime;
8472
+ }
8473
+ }
8474
+ function getWxPixelRatio(params, runtime = getWxRuntime(params)) {
8475
+ var _a, _b, _c, _d;
8476
+ return (_d = (_a = params === null || params === void 0 ? void 0 : params.pixelRatio) !== null && _a !== void 0 ? _a : (_c = (_b = runtime === null || runtime === void 0 ? void 0 : runtime.getSystemInfoSync) === null || _b === void 0 ? void 0 : _b.call(runtime)) === null || _c === void 0 ? void 0 : _c.pixelRatio) !== null && _d !== void 0 ? _d : 1;
8214
8477
  }
8215
8478
  class WxEnvContribution extends BaseEnvContribution {
8216
8479
  constructor() {
@@ -8218,8 +8481,7 @@ class WxEnvContribution extends BaseEnvContribution {
8218
8481
  this.type = 'wx';
8219
8482
  this.supportEvent = true;
8220
8483
  this.canvasMap = new Map();
8221
- this.freeCanvasList = [];
8222
- this.canvasIdx = 0;
8484
+ this.wxEnvParams = {};
8223
8485
  this.supportsTouchEvents = true;
8224
8486
  try {
8225
8487
  this.supportsPointerEvents = !!globalThis.PointerEvent;
@@ -8231,11 +8493,10 @@ class WxEnvContribution extends BaseEnvContribution {
8231
8493
  }
8232
8494
  this.applyStyles = true;
8233
8495
  }
8234
- configure(service, params) {
8496
+ configure(service, params = {}) {
8235
8497
  if (service.env === this.type) {
8236
8498
  service.setActiveEnvContribution(this);
8237
- return makeUpCanvas(params.domref, params.canvasIdLists, this.canvasMap, params.freeCanvasIdx, this.freeCanvasList, params.component, params.forceUpdate).then(() => {
8238
- });
8499
+ this.wxEnvParams = params;
8239
8500
  }
8240
8501
  }
8241
8502
  loadImage(url) {
@@ -8251,9 +8512,21 @@ class WxEnvContribution extends BaseEnvContribution {
8251
8512
  });
8252
8513
  }
8253
8514
  createCanvas(params) {
8254
- const result = this.freeCanvasList[this.canvasIdx] || this.freeCanvasList[this.freeCanvasList.length - 1];
8255
- this.canvasIdx++;
8256
- return result;
8515
+ var _a;
8516
+ const envParams = this.wxEnvParams;
8517
+ const runtime = getWxRuntime(envParams);
8518
+ const dpr = (_a = params.dpr) !== null && _a !== void 0 ? _a : getWxPixelRatio(envParams, runtime);
8519
+ const factoryCanvas = createCanvasWithFactory(params, dpr, this.canvasMap, envParams.canvasFactory);
8520
+ if (factoryCanvas) {
8521
+ return factoryCanvas;
8522
+ }
8523
+ const options = getMiniAppCanvasOptions(params, dpr, false);
8524
+ if (options.id == null || typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createCanvasContext) !== 'function') {
8525
+ throw new Error(WX_CANVAS_BRIDGE_ERROR);
8526
+ }
8527
+ const canvas = wrapMiniAppContextCanvas(runtime.createCanvasContext(options.id), options);
8528
+ this.canvasMap.set(options.id, canvas);
8529
+ return canvas;
8257
8530
  }
8258
8531
  createOffscreenCanvas(params) {
8259
8532
  return;
@@ -8262,7 +8535,7 @@ class WxEnvContribution extends BaseEnvContribution {
8262
8535
  return;
8263
8536
  }
8264
8537
  getDevicePixelRatio() {
8265
- return wx.getSystemInfoSync().pixelRatio;
8538
+ return getWxPixelRatio(this.wxEnvParams);
8266
8539
  }
8267
8540
  getRequestAnimationFrame() {
8268
8541
  return function (callback) {