@visactor/vrender-kits 1.1.0-alpha.21 → 1.1.0-alpha.23

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 (92) hide show
  1. package/cjs/canvas/contributions/create-canvas-module.js +1 -1
  2. package/cjs/canvas/contributions/harmony/canvas.js +5 -1
  3. package/cjs/canvas/contributions/harmony/canvas.js.map +1 -1
  4. package/cjs/canvas/contributions/modules.js +1 -1
  5. package/cjs/env/contributions/browser-contribution.js +1 -1
  6. package/cjs/env/contributions/canvas-wrap.js +1 -1
  7. package/cjs/env/contributions/feishu-contribution.d.ts +15 -8
  8. package/cjs/env/contributions/feishu-contribution.js +26 -14
  9. package/cjs/env/contributions/feishu-contribution.js.map +1 -1
  10. package/cjs/env/contributions/harmony-contribution.d.ts +26 -7
  11. package/cjs/env/contributions/harmony-contribution.js +129 -21
  12. package/cjs/env/contributions/harmony-contribution.js.map +1 -1
  13. package/cjs/env/contributions/lynx-contribution.d.ts +35 -10
  14. package/cjs/env/contributions/lynx-contribution.js +128 -31
  15. package/cjs/env/contributions/lynx-contribution.js.map +1 -1
  16. package/cjs/env/contributions/miniapp-canvas.d.ts +18 -0
  17. package/cjs/env/contributions/miniapp-canvas.js +46 -0
  18. package/cjs/env/contributions/miniapp-canvas.js.map +1 -0
  19. package/cjs/env/contributions/taro-contribution.d.ts +6 -10
  20. package/cjs/env/contributions/taro-contribution.js +17 -18
  21. package/cjs/env/contributions/taro-contribution.js.map +1 -1
  22. package/cjs/env/contributions/tt-contribution.d.ts +14 -8
  23. package/cjs/env/contributions/tt-contribution.js +26 -49
  24. package/cjs/env/contributions/tt-contribution.js.map +1 -1
  25. package/cjs/env/contributions/wx-contribution.d.ts +15 -11
  26. package/cjs/env/contributions/wx-contribution.js +30 -54
  27. package/cjs/env/contributions/wx-contribution.js.map +1 -1
  28. package/cjs/event/extension/drag.js +1 -1
  29. package/cjs/event/extension/gesture.js +1 -1
  30. package/cjs/event/extension/index.js +1 -1
  31. package/cjs/event/extension/interface.js +1 -1
  32. package/cjs/window/contributions/feishu-contribution.js +6 -1
  33. package/cjs/window/contributions/feishu-contribution.js.map +1 -1
  34. package/cjs/window/contributions/harmony-contribution.js +70 -11
  35. package/cjs/window/contributions/harmony-contribution.js.map +1 -1
  36. package/cjs/window/contributions/lynx-contribution.d.ts +1 -2
  37. package/cjs/window/contributions/lynx-contribution.js +63 -9
  38. package/cjs/window/contributions/lynx-contribution.js.map +1 -1
  39. package/cjs/window/contributions/taro-contribution.js +6 -1
  40. package/cjs/window/contributions/taro-contribution.js.map +1 -1
  41. package/cjs/window/contributions/tt-contribution.js +6 -1
  42. package/cjs/window/contributions/tt-contribution.js.map +1 -1
  43. package/cjs/window/contributions/wx-contribution.d.ts +1 -2
  44. package/cjs/window/contributions/wx-contribution.js +29 -10
  45. package/cjs/window/contributions/wx-contribution.js.map +1 -1
  46. package/dist/index.es.js +721 -213
  47. package/es/canvas/contributions/create-canvas-module.js +1 -1
  48. package/es/canvas/contributions/harmony/canvas.js +5 -1
  49. package/es/canvas/contributions/harmony/canvas.js.map +1 -1
  50. package/es/canvas/contributions/modules.js +1 -1
  51. package/es/env/contributions/browser-contribution.js +1 -1
  52. package/es/env/contributions/canvas-wrap.js +1 -1
  53. package/es/env/contributions/feishu-contribution.d.ts +15 -8
  54. package/es/env/contributions/feishu-contribution.js +27 -14
  55. package/es/env/contributions/feishu-contribution.js.map +1 -1
  56. package/es/env/contributions/harmony-contribution.d.ts +26 -7
  57. package/es/env/contributions/harmony-contribution.js +132 -22
  58. package/es/env/contributions/harmony-contribution.js.map +1 -1
  59. package/es/env/contributions/lynx-contribution.d.ts +35 -10
  60. package/es/env/contributions/lynx-contribution.js +128 -29
  61. package/es/env/contributions/lynx-contribution.js.map +1 -1
  62. package/es/env/contributions/miniapp-canvas.d.ts +18 -0
  63. package/es/env/contributions/miniapp-canvas.js +37 -0
  64. package/es/env/contributions/miniapp-canvas.js.map +1 -0
  65. package/es/env/contributions/taro-contribution.d.ts +6 -10
  66. package/es/env/contributions/taro-contribution.js +17 -17
  67. package/es/env/contributions/taro-contribution.js.map +1 -1
  68. package/es/env/contributions/tt-contribution.d.ts +14 -8
  69. package/es/env/contributions/tt-contribution.js +28 -48
  70. package/es/env/contributions/tt-contribution.js.map +1 -1
  71. package/es/env/contributions/wx-contribution.d.ts +15 -11
  72. package/es/env/contributions/wx-contribution.js +32 -53
  73. package/es/env/contributions/wx-contribution.js.map +1 -1
  74. package/es/event/extension/drag.js +1 -1
  75. package/es/event/extension/gesture.js +1 -1
  76. package/es/event/extension/index.js +1 -1
  77. package/es/event/extension/interface.js +1 -1
  78. package/es/window/contributions/feishu-contribution.js +6 -1
  79. package/es/window/contributions/feishu-contribution.js.map +1 -1
  80. package/es/window/contributions/harmony-contribution.js +70 -11
  81. package/es/window/contributions/harmony-contribution.js.map +1 -1
  82. package/es/window/contributions/lynx-contribution.d.ts +1 -2
  83. package/es/window/contributions/lynx-contribution.js +62 -10
  84. package/es/window/contributions/lynx-contribution.js.map +1 -1
  85. package/es/window/contributions/taro-contribution.js +6 -1
  86. package/es/window/contributions/taro-contribution.js.map +1 -1
  87. package/es/window/contributions/tt-contribution.js +6 -1
  88. package/es/window/contributions/tt-contribution.js.map +1 -1
  89. package/es/window/contributions/wx-contribution.d.ts +1 -2
  90. package/es/window/contributions/wx-contribution.js +28 -11
  91. package/es/window/contributions/wx-contribution.js.map +1 -1
  92. package/package.json +2 -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;
@@ -6435,6 +6725,73 @@ let MiniAppEventManager$3 = class MiniAppEventManager {
6435
6725
  this.cache = {};
6436
6726
  }
6437
6727
  };
6728
+ function setMiniAppEventTarget$1(event, key, value) {
6729
+ if (!event || !value) {
6730
+ return;
6731
+ }
6732
+ try {
6733
+ event[key] = value;
6734
+ }
6735
+ catch (_a) {
6736
+ Object.defineProperty(event, key, {
6737
+ configurable: true,
6738
+ value
6739
+ });
6740
+ }
6741
+ }
6742
+ function isValidCoordinate$1(value) {
6743
+ return typeof value === 'number' && Number.isFinite(value);
6744
+ }
6745
+ function pickCoordinate$1(...values) {
6746
+ for (let i = 0; i < values.length; i++) {
6747
+ if (isValidCoordinate$1(values[i])) {
6748
+ return values[i];
6749
+ }
6750
+ }
6751
+ return undefined;
6752
+ }
6753
+ function setLynxEventValue(event, key, value) {
6754
+ try {
6755
+ event[key] = value;
6756
+ }
6757
+ catch (_a) {
6758
+ Object.defineProperty(event, key, {
6759
+ configurable: true,
6760
+ value
6761
+ });
6762
+ }
6763
+ }
6764
+ function normalizeLynxTouchEventPoint(event) {
6765
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
6766
+ 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];
6767
+ if (!touch) {
6768
+ return;
6769
+ }
6770
+ const x = pickCoordinate$1(event.x, event.offsetX, event.clientX, event.pageX, touch.x, touch.offsetX, touch.clientX, touch.pageX);
6771
+ const y = pickCoordinate$1(event.y, event.offsetY, event.clientY, event.pageY, touch.y, touch.offsetY, touch.clientY, touch.pageY);
6772
+ if (x == null || y == null) {
6773
+ return;
6774
+ }
6775
+ if (!event.touches && event.changedTouches) {
6776
+ setLynxEventValue(event, 'touches', event.type === 'touchend' || event.type === 'touchcancel' ? [] : event.changedTouches);
6777
+ }
6778
+ setLynxEventValue(event, 'x', x);
6779
+ setLynxEventValue(event, 'y', y);
6780
+ setLynxEventValue(event, 'offsetX', (_d = event.offsetX) !== null && _d !== void 0 ? _d : x);
6781
+ setLynxEventValue(event, 'offsetY', (_e = event.offsetY) !== null && _e !== void 0 ? _e : y);
6782
+ setLynxEventValue(event, 'clientX', (_f = event.clientX) !== null && _f !== void 0 ? _f : x);
6783
+ setLynxEventValue(event, 'clientY', (_g = event.clientY) !== null && _g !== void 0 ? _g : y);
6784
+ setLynxEventValue(event, 'pageX', (_h = event.pageX) !== null && _h !== void 0 ? _h : x);
6785
+ setLynxEventValue(event, 'pageY', (_j = event.pageY) !== null && _j !== void 0 ? _j : y);
6786
+ touch.x = (_k = touch.x) !== null && _k !== void 0 ? _k : x;
6787
+ touch.y = (_l = touch.y) !== null && _l !== void 0 ? _l : y;
6788
+ touch.offsetX = (_m = touch.offsetX) !== null && _m !== void 0 ? _m : x;
6789
+ touch.offsetY = (_o = touch.offsetY) !== null && _o !== void 0 ? _o : y;
6790
+ touch.clientX = (_p = touch.clientX) !== null && _p !== void 0 ? _p : x;
6791
+ touch.clientY = (_q = touch.clientY) !== null && _q !== void 0 ? _q : y;
6792
+ touch.pageX = (_r = touch.pageX) !== null && _r !== void 0 ? _r : x;
6793
+ touch.pageY = (_s = touch.pageY) !== null && _s !== void 0 ? _s : y;
6794
+ }
6438
6795
  class LynxWindowHandlerContribution extends BaseWindowHandlerContribution {
6439
6796
  get container() {
6440
6797
  return null;
@@ -6484,6 +6841,14 @@ class LynxWindowHandlerContribution extends BaseWindowHandlerContribution {
6484
6841
  let canvas;
6485
6842
  if (typeof params.canvas === 'string') {
6486
6843
  canvas = this.global.getElementById(params.canvas);
6844
+ if (!canvas) {
6845
+ canvas = this.global.createCanvas({
6846
+ id: params.canvas,
6847
+ width: params.width,
6848
+ height: params.height,
6849
+ dpr: params.dpr
6850
+ });
6851
+ }
6487
6852
  if (!canvas) {
6488
6853
  throw new Error('canvasId 参数不正确,请确认canvas存在并插入dom');
6489
6854
  }
@@ -6535,18 +6900,15 @@ class LynxWindowHandlerContribution extends BaseWindowHandlerContribution {
6535
6900
  this.eventManager.removeEventListener(type, listener);
6536
6901
  }
6537
6902
  dispatchEvent(event) {
6903
+ var _a;
6538
6904
  const { type } = event;
6539
6905
  if (!this.eventManager.cache[type]) {
6540
6906
  return false;
6541
6907
  }
6542
- if (event.changedTouches && event.changedTouches[0]) {
6543
- event.offsetX = event.changedTouches[0].x;
6544
- event.changedTouches[0].offsetX = event.changedTouches[0].x;
6545
- event.changedTouches[0].clientX = event.changedTouches[0].x;
6546
- event.offsetY = event.changedTouches[0].y;
6547
- event.changedTouches[0].offsetY = event.changedTouches[0].y;
6548
- event.changedTouches[0].clientY = event.changedTouches[0].y;
6549
- }
6908
+ const nativeCanvas = (_a = this.canvas) === null || _a === void 0 ? void 0 : _a.nativeCanvas;
6909
+ setMiniAppEventTarget$1(event, 'target', nativeCanvas);
6910
+ setMiniAppEventTarget$1(event, 'currentTarget', nativeCanvas);
6911
+ normalizeLynxTouchEventPoint(event);
6550
6912
  event.preventDefault = () => {
6551
6913
  return;
6552
6914
  };
@@ -6607,48 +6969,133 @@ function bindLynxWindowContribution(container) {
6607
6969
  }
6608
6970
  }
6609
6971
 
6610
- let ng = false;
6611
- try {
6612
- ng = !!lynx.createCanvasNG;
6972
+ const LYNX_CANVAS_BRIDGE_ERROR = 'Lynx canvas bridge is unavailable. VRender Lynx env requires envParams.canvasFactory ' +
6973
+ 'or a Lynx runtime that exposes createCanvasNG/createCanvas/createOffscreenCanvas/krypton canvas APIs.';
6974
+ const LYNX_CANVAS_SIZE_ERROR = 'Lynx canvas size is unavailable. Pass stage width/height when creating a Lynx stage canvas.';
6975
+ function isValidCoordinate(value) {
6976
+ return typeof value === 'number' && Number.isFinite(value);
6613
6977
  }
6614
- catch (err) {
6978
+ function pickCoordinate(...values) {
6979
+ for (let i = 0; i < values.length; i++) {
6980
+ if (isValidCoordinate(values[i])) {
6981
+ return values[i];
6982
+ }
6983
+ }
6984
+ return undefined;
6985
+ }
6986
+ function getPrimaryTouch(event) {
6987
+ var _a, _b, _c;
6988
+ 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];
6989
+ }
6990
+ function getLynxEventPoint(event) {
6991
+ const touch = getPrimaryTouch(event);
6992
+ const x = pickCoordinate(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);
6993
+ const y = pickCoordinate(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);
6994
+ return x == null || y == null ? null : { x, y };
6995
+ }
6996
+ function getGlobalLynxRuntime() {
6997
+ try {
6998
+ return typeof lynx !== 'undefined' ? lynx : undefined;
6999
+ }
7000
+ catch (err) {
7001
+ return undefined;
7002
+ }
7003
+ }
7004
+ function getGlobalSystemPixelRatio() {
7005
+ try {
7006
+ return typeof SystemInfo !== 'undefined' ? SystemInfo.pixelRatio : undefined;
7007
+ }
7008
+ catch (err) {
7009
+ return undefined;
7010
+ }
6615
7011
  }
6616
- function makeUpCanvas$3(domref, canvasIdLists, canvasMap, freeCanvasIdx, freeCanvasList, offscreen, pixelRatio) {
6617
- const dpr = pixelRatio !== null && pixelRatio !== void 0 ? pixelRatio : SystemInfo.pixelRatio;
6618
- canvasIdLists.forEach((id, i) => {
6619
- let _canvas;
6620
- if (offscreen) {
6621
- _canvas = lynx.createOffscreenCanvas();
7012
+ function getLynxRuntime(params) {
7013
+ var _a, _b;
7014
+ return (_b = (_a = params === null || params === void 0 ? void 0 : params.lynx) !== null && _a !== void 0 ? _a : params === null || params === void 0 ? void 0 : params.runtime) !== null && _b !== void 0 ? _b : getGlobalLynxRuntime();
7015
+ }
7016
+ function getLynxPixelRatio(params, runtime) {
7017
+ var _a, _b, _c, _d, _e;
7018
+ return (_e = (_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 : getGlobalSystemPixelRatio()) !== null && _e !== void 0 ? _e : 1;
7019
+ }
7020
+ function attachLynxCanvasToView(canvas, id) {
7021
+ var _a;
7022
+ (_a = canvas === null || canvas === void 0 ? void 0 : canvas.attachToCanvasView) === null || _a === void 0 ? void 0 : _a.call(canvas, id);
7023
+ return canvas;
7024
+ }
7025
+ function createBoundLynxCanvas(id, runtime) {
7026
+ var _a, _b, _c;
7027
+ if (typeof ((_a = runtime === null || runtime === void 0 ? void 0 : runtime.krypton) === null || _a === void 0 ? void 0 : _a.createCanvas) === 'function') {
7028
+ const canvas = runtime.krypton.createCanvas(id);
7029
+ if (canvas) {
7030
+ return canvas;
6622
7031
  }
6623
- else {
6624
- _canvas = ng ? lynx.createCanvasNG(id) : lynx.createCanvas(id);
6625
- ng && _canvas.attachToCanvasView(id);
7032
+ }
7033
+ if (typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createCanvasNG) === 'function') {
7034
+ const canvas = runtime.createCanvasNG(id);
7035
+ if (canvas) {
7036
+ return attachLynxCanvasToView(canvas, id);
6626
7037
  }
6627
- _canvas.width = domref.width * dpr;
6628
- _canvas.height = domref.height * dpr;
6629
- const ctx = _canvas.getContext('2d');
6630
- const canvas = new CanvasWrapEnableWH(_canvas, ctx, dpr, domref.width, domref.height, id);
6631
- canvasMap.set(id, canvas);
6632
- if (i > freeCanvasIdx) {
6633
- freeCanvasList.push(canvas);
7038
+ }
7039
+ if (typeof ((_b = runtime === null || runtime === void 0 ? void 0 : runtime.krypton) === null || _b === void 0 ? void 0 : _b.createCanvasNG) === 'function') {
7040
+ const canvas = runtime.krypton.createCanvasNG();
7041
+ if (canvas) {
7042
+ return attachLynxCanvasToView(canvas, id);
7043
+ }
7044
+ }
7045
+ if (typeof ((_c = runtime === null || runtime === void 0 ? void 0 : runtime.krypton) === null || _c === void 0 ? void 0 : _c.CanvasElement) === 'function') {
7046
+ return new runtime.krypton.CanvasElement(id);
7047
+ }
7048
+ if (typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createCanvas) === 'function') {
7049
+ const canvas = runtime.createCanvas(id);
7050
+ if (canvas) {
7051
+ return canvas;
6634
7052
  }
6635
- });
6636
- if (!freeCanvasList.length && lynx.createOffscreenCanvas) {
6637
- const _canvas = lynx.createOffscreenCanvas();
6638
- _canvas.width = domref.width * dpr;
6639
- _canvas.height = domref.height * dpr;
6640
- const ctx = _canvas.getContext('2d');
6641
- const id = Math.random().toString();
6642
- const canvas = new CanvasWrapEnableWH(_canvas, ctx, dpr, domref.width, domref.height, id);
6643
- canvasMap.set(id, canvas);
6644
- freeCanvasList.push(canvas);
6645
7053
  }
7054
+ return null;
6646
7055
  }
6647
- function createImageElement(src, isSvg = false) {
7056
+ function getCanvasSize(width, height) {
7057
+ if (!isValidCoordinate(width) || !isValidCoordinate(height)) {
7058
+ throw new Error(LYNX_CANVAS_SIZE_ERROR);
7059
+ }
7060
+ return { width, height };
7061
+ }
7062
+ function wrapLynxNativeCanvas(nativeCanvas, id, width, height, dpr) {
7063
+ nativeCanvas.width = width * dpr;
7064
+ nativeCanvas.height = height * dpr;
7065
+ const ctx = nativeCanvas.getContext('2d');
7066
+ return new CanvasWrapEnableWH(nativeCanvas, ctx, dpr, width, height, id);
7067
+ }
7068
+ function createLynxNativeCanvas(id, width, height, dpr, offscreen, params, runtime) {
7069
+ if (params.canvasFactory) {
7070
+ return params.canvasFactory({
7071
+ id,
7072
+ width,
7073
+ height,
7074
+ dpr,
7075
+ offscreen
7076
+ });
7077
+ }
7078
+ if (offscreen) {
7079
+ if (typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createOffscreenCanvas) === 'function') {
7080
+ return runtime.createOffscreenCanvas();
7081
+ }
7082
+ }
7083
+ else {
7084
+ const canvas = createBoundLynxCanvas(id, runtime);
7085
+ if (canvas) {
7086
+ return canvas;
7087
+ }
7088
+ }
7089
+ throw new Error(LYNX_CANVAS_BRIDGE_ERROR);
7090
+ }
7091
+ function createImageElement(src, isSvg = false, runtime = getGlobalLynxRuntime()) {
6648
7092
  if (isSvg) {
6649
7093
  return Promise.reject();
6650
7094
  }
6651
- const img = lynx.createImage(src);
7095
+ if (typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createImage) !== 'function') {
7096
+ return Promise.reject(new Error('Lynx image bridge is unavailable.'));
7097
+ }
7098
+ const img = runtime.createImage(src);
6652
7099
  const promise = new Promise((resolve, reject) => {
6653
7100
  img.onload = () => {
6654
7101
  resolve(img);
@@ -6678,10 +7125,11 @@ class LynxEnvContribution extends BaseEnvContribution {
6678
7125
  }
6679
7126
  this.applyStyles = true;
6680
7127
  }
6681
- configure(service, params) {
7128
+ configure(service, params = {}) {
6682
7129
  if (service.env === this.type) {
6683
7130
  service.setActiveEnvContribution(this);
6684
- makeUpCanvas$3(params.domref, params.canvasIdLists, this.canvasMap, params.freeCanvasIdx, this.freeCanvasList, !!params.offscreen, params.pixelRatio);
7131
+ this.lynxEnvParams = params;
7132
+ this.lynxRuntime = getLynxRuntime(params);
6685
7133
  }
6686
7134
  }
6687
7135
  getDynamicCanvasCount() {
@@ -6691,7 +7139,7 @@ class LynxEnvContribution extends BaseEnvContribution {
6691
7139
  return 9999;
6692
7140
  }
6693
7141
  loadImage(url) {
6694
- const imagePromise = createImageElement(url, false);
7142
+ const imagePromise = createImageElement(url, false, this.lynxRuntime);
6695
7143
  return imagePromise
6696
7144
  .then((img) => {
6697
7145
  return {
@@ -6707,12 +7155,43 @@ class LynxEnvContribution extends BaseEnvContribution {
6707
7155
  });
6708
7156
  }
6709
7157
  loadSvg(url) {
6710
- return Promise.reject();
7158
+ return Promise.resolve({
7159
+ data: null,
7160
+ loadState: 'fail'
7161
+ });
6711
7162
  }
6712
7163
  createCanvas(params) {
7164
+ var _a, _b, _c, _d;
7165
+ if (params.id != null) {
7166
+ const id = String(params.id);
7167
+ const existing = this.canvasMap.get(id);
7168
+ if (existing) {
7169
+ return existing;
7170
+ }
7171
+ const envParams = (_a = this.lynxEnvParams) !== null && _a !== void 0 ? _a : {};
7172
+ const runtime = getLynxRuntime(envParams);
7173
+ const dpr = (_b = params.dpr) !== null && _b !== void 0 ? _b : getLynxPixelRatio(envParams, runtime);
7174
+ const size = getCanvasSize(params.width, params.height);
7175
+ const nativeCanvas = createLynxNativeCanvas(id, size.width, size.height, dpr, false, envParams, runtime);
7176
+ const canvas = wrapLynxNativeCanvas(nativeCanvas, id, size.width, size.height, dpr);
7177
+ this.canvasMap.set(id, canvas);
7178
+ return canvas;
7179
+ }
6713
7180
  const result = this.freeCanvasList[this.canvasIdx] || this.freeCanvasList[this.freeCanvasList.length - 1];
6714
7181
  this.canvasIdx++;
6715
- return result;
7182
+ if (result) {
7183
+ return result;
7184
+ }
7185
+ const envParams = (_c = this.lynxEnvParams) !== null && _c !== void 0 ? _c : {};
7186
+ const runtime = getLynxRuntime(envParams);
7187
+ const dpr = (_d = params.dpr) !== null && _d !== void 0 ? _d : getLynxPixelRatio(envParams, runtime);
7188
+ const size = getCanvasSize(params.width, params.height);
7189
+ const id = Math.random().toString();
7190
+ const nativeCanvas = createLynxNativeCanvas(id, size.width, size.height, dpr, true, envParams, runtime);
7191
+ const canvas = wrapLynxNativeCanvas(nativeCanvas, id, size.width, size.height, dpr);
7192
+ this.canvasMap.set(id, canvas);
7193
+ this.freeCanvasList.push(canvas);
7194
+ return canvas;
6716
7195
  }
6717
7196
  createOffscreenCanvas(params) {
6718
7197
  return;
@@ -6721,7 +7200,7 @@ class LynxEnvContribution extends BaseEnvContribution {
6721
7200
  return;
6722
7201
  }
6723
7202
  getDevicePixelRatio() {
6724
- return SystemInfo.pixelRatio;
7203
+ return getLynxPixelRatio(undefined, this.lynxRuntime);
6725
7204
  }
6726
7205
  getRequestAnimationFrame() {
6727
7206
  return function (callback) {
@@ -6735,10 +7214,7 @@ class LynxEnvContribution extends BaseEnvContribution {
6735
7214
  }
6736
7215
  mapToCanvasPoint(event) {
6737
7216
  var _a;
6738
- if ((_a = event === null || event === void 0 ? void 0 : event.type) === null || _a === void 0 ? void 0 : _a.startsWith('mouse')) {
6739
- return event;
6740
- }
6741
- return event;
7217
+ return (_a = getLynxEventPoint(event)) !== null && _a !== void 0 ? _a : event;
6742
7218
  }
6743
7219
  addEventListener(type, listener, options) {
6744
7220
  return null;
@@ -7132,6 +7608,14 @@ class TaroWindowHandlerContribution extends BaseWindowHandlerContribution {
7132
7608
  let canvas;
7133
7609
  if (typeof params.canvas === 'string') {
7134
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
+ }
7135
7619
  if (!canvas) {
7136
7620
  throw new Error('canvasId 参数不正确,请确认canvas存在并插入dom');
7137
7621
  }
@@ -7259,26 +7743,16 @@ function bindTaroWindowContribution(container) {
7259
7743
  }
7260
7744
  }
7261
7745
 
7262
- function makeUpCanvas$2(domref, canvasIdLists, canvasMap, freeCanvasIdx, freeCanvasList, taro, dpr) {
7263
- canvasIdLists.forEach((id, i) => {
7264
- const ctx = taro.createCanvasContext(id);
7265
- const canvas = new CanvasWrapDisableWH(ctx.canvas || {}, ctx, dpr, domref.width, domref.height, id);
7266
- ctx.canvas = canvas;
7267
- canvasMap.set(id, canvas);
7268
- if (i >= freeCanvasIdx) {
7269
- freeCanvasList.push(canvas);
7270
- }
7271
- return canvas;
7272
- });
7273
- }
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).';
7274
7748
  class TaroEnvContribution extends BaseEnvContribution {
7275
7749
  constructor() {
7276
7750
  super();
7277
7751
  this.type = 'taro';
7278
7752
  this.supportEvent = true;
7279
7753
  this.canvasMap = new Map();
7280
- this.freeCanvasList = [];
7281
- this.canvasIdx = 0;
7754
+ this.pixelRatio = 1;
7755
+ this.taroEnvParams = {};
7282
7756
  this.supportsTouchEvents = true;
7283
7757
  try {
7284
7758
  this.supportsPointerEvents = !!globalThis.PointerEvent;
@@ -7291,7 +7765,7 @@ class TaroEnvContribution extends BaseEnvContribution {
7291
7765
  this.applyStyles = true;
7292
7766
  }
7293
7767
  getDynamicCanvasCount() {
7294
- return this.freeCanvasList.length;
7768
+ return 0;
7295
7769
  }
7296
7770
  getStaticCanvasCount() {
7297
7771
  return 9999;
@@ -7303,12 +7777,13 @@ class TaroEnvContribution extends BaseEnvContribution {
7303
7777
  }
7304
7778
  return event;
7305
7779
  }
7306
- configure(service, params) {
7780
+ configure(service, params = {}) {
7781
+ var _a;
7307
7782
  if (service.env === this.type) {
7308
7783
  service.setActiveEnvContribution(this);
7309
- makeUpCanvas$2(params.domref, params.canvasIdLists, this.canvasMap, params.freeCanvasIdx, this.freeCanvasList, params.taro, params.pixelRatio);
7784
+ this.taroEnvParams = params;
7310
7785
  this.taro = params.taro;
7311
- this.pixelRatio = params.pixelRatio;
7786
+ this.pixelRatio = (_a = params.pixelRatio) !== null && _a !== void 0 ? _a : 1;
7312
7787
  }
7313
7788
  }
7314
7789
  loadImage(url) {
@@ -7318,7 +7793,7 @@ class TaroEnvContribution extends BaseEnvContribution {
7318
7793
  });
7319
7794
  }
7320
7795
  loadSvg(svgStr) {
7321
- const _window = window || globalThis;
7796
+ const _window = typeof window !== 'undefined' ? window : globalThis;
7322
7797
  if (_window.DOMParser) {
7323
7798
  const parser = new _window.DOMParser();
7324
7799
  const svg = parser.parseFromString(svgStr, 'image/svg+xml').children[0];
@@ -7340,9 +7815,20 @@ class TaroEnvContribution extends BaseEnvContribution {
7340
7815
  return Promise.reject();
7341
7816
  }
7342
7817
  createCanvas(params) {
7343
- const result = this.freeCanvasList[this.canvasIdx] || this.freeCanvasList[this.freeCanvasList.length - 1];
7344
- this.canvasIdx++;
7345
- 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;
7346
7832
  }
7347
7833
  createOffscreenCanvas(params) {
7348
7834
  return;
@@ -7481,6 +7967,14 @@ class TTWindowHandlerContribution extends BaseWindowHandlerContribution {
7481
7967
  let canvas;
7482
7968
  if (typeof params.canvas === 'string') {
7483
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
+ }
7484
7978
  if (!canvas) {
7485
7979
  throw new Error('canvasId 参数不正确,请确认canvas存在并插入dom');
7486
7980
  }
@@ -7604,34 +8098,20 @@ function bindTTWindowContribution(container) {
7604
8098
  }
7605
8099
  }
7606
8100
 
7607
- function makeUpCanvas$1(domref, canvasIdLists, canvasMap, freeCanvasIdx, freeCanvasList, component) {
7608
- return __awaiter(this, void 0, void 0, function* () {
7609
- const dpr = tt.getSystemInfoSync().pixelRatio;
7610
- for (let i = 0; i < canvasIdLists.length; i++) {
7611
- const id = canvasIdLists[i];
7612
- yield new Promise(resolve => {
7613
- let data = tt.createSelectorQuery();
7614
- if (component) {
7615
- data = data.in(component);
7616
- }
7617
- data
7618
- .select(`#${id}`)
7619
- .node()
7620
- .exec((res) => {
7621
- const canvas = res[0].node;
7622
- const width = canvas.width;
7623
- const height = canvas.height;
7624
- canvas.width = width * dpr;
7625
- canvas.height = height * dpr;
7626
- canvasMap.set(id, canvas);
7627
- if (i >= freeCanvasIdx) {
7628
- freeCanvasList.push(canvas);
7629
- }
7630
- resolve(null);
7631
- });
7632
- });
7633
- }
7634
- });
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;
7635
8115
  }
7636
8116
  class TTEnvContribution extends BaseEnvContribution {
7637
8117
  constructor() {
@@ -7639,8 +8119,7 @@ class TTEnvContribution extends BaseEnvContribution {
7639
8119
  this.type = 'tt';
7640
8120
  this.supportEvent = true;
7641
8121
  this.canvasMap = new Map();
7642
- this.freeCanvasList = [];
7643
- this.canvasIdx = 0;
8122
+ this.ttEnvParams = {};
7644
8123
  this.supportsTouchEvents = true;
7645
8124
  try {
7646
8125
  this.supportsPointerEvents = !!globalThis.PointerEvent;
@@ -7652,11 +8131,10 @@ class TTEnvContribution extends BaseEnvContribution {
7652
8131
  }
7653
8132
  this.applyStyles = true;
7654
8133
  }
7655
- configure(service, params) {
8134
+ configure(service, params = {}) {
7656
8135
  if (service.env === this.type) {
7657
8136
  service.setActiveEnvContribution(this);
7658
- return makeUpCanvas$1(params.domref, params.canvasIdLists, this.canvasMap, params.freeCanvasIdx, this.freeCanvasList, params.component).then(() => {
7659
- });
8137
+ this.ttEnvParams = params;
7660
8138
  }
7661
8139
  }
7662
8140
  loadImage(url) {
@@ -7669,9 +8147,21 @@ class TTEnvContribution extends BaseEnvContribution {
7669
8147
  return Promise.reject();
7670
8148
  }
7671
8149
  createCanvas(params) {
7672
- const result = this.freeCanvasList[this.canvasIdx] || this.freeCanvasList[this.freeCanvasList.length - 1];
7673
- this.canvasIdx++;
7674
- 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;
7675
8165
  }
7676
8166
  createOffscreenCanvas(params) {
7677
8167
  return;
@@ -7680,7 +8170,7 @@ class TTEnvContribution extends BaseEnvContribution {
7680
8170
  return;
7681
8171
  }
7682
8172
  getDevicePixelRatio() {
7683
- return tt.getSystemInfoSync().pixelRatio;
8173
+ return getTTPixelRatio(this.ttEnvParams);
7684
8174
  }
7685
8175
  getRequestAnimationFrame() {
7686
8176
  return function (callback) {
@@ -7772,6 +8262,20 @@ class MiniAppEventManager {
7772
8262
  this.cache = {};
7773
8263
  }
7774
8264
  }
8265
+ function setMiniAppEventTarget(event, key, value) {
8266
+ if (!event || !value) {
8267
+ return;
8268
+ }
8269
+ try {
8270
+ event[key] = value;
8271
+ }
8272
+ catch (_a) {
8273
+ Object.defineProperty(event, key, {
8274
+ configurable: true,
8275
+ value
8276
+ });
8277
+ }
8278
+ }
7775
8279
  class WxWindowHandlerContribution extends BaseWindowHandlerContribution {
7776
8280
  get container() {
7777
8281
  return null;
@@ -7821,6 +8325,14 @@ class WxWindowHandlerContribution extends BaseWindowHandlerContribution {
7821
8325
  let canvas;
7822
8326
  if (typeof params.canvas === 'string') {
7823
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
+ }
7824
8336
  if (!canvas) {
7825
8337
  throw new Error('canvasId 参数不正确,请确认canvas存在并插入dom');
7826
8338
  }
@@ -7872,18 +8384,21 @@ class WxWindowHandlerContribution extends BaseWindowHandlerContribution {
7872
8384
  this.eventManager.removeEventListener(type, listener);
7873
8385
  }
7874
8386
  dispatchEvent(event) {
7875
- var _a, _b, _c, _d;
8387
+ var _a, _b, _c, _d, _e;
7876
8388
  const { type } = event;
7877
8389
  if (!this.eventManager.cache[type]) {
7878
8390
  return false;
7879
8391
  }
8392
+ const nativeCanvas = (_a = this.canvas) === null || _a === void 0 ? void 0 : _a.nativeCanvas;
8393
+ setMiniAppEventTarget(event, 'target', nativeCanvas);
8394
+ setMiniAppEventTarget(event, 'currentTarget', nativeCanvas);
7880
8395
  if (event.changedTouches && event.changedTouches[0]) {
7881
8396
  event.offsetX = event.changedTouches[0].x;
7882
- event.changedTouches[0].offsetX = (_a = event.changedTouches[0].x) !== null && _a !== void 0 ? _a : event.changedTouches[0].pageX;
7883
- event.changedTouches[0].clientX = (_b = event.changedTouches[0].x) !== null && _b !== void 0 ? _b : event.changedTouches[0].pageX;
8397
+ event.changedTouches[0].offsetX = (_b = event.changedTouches[0].x) !== null && _b !== void 0 ? _b : event.changedTouches[0].pageX;
8398
+ event.changedTouches[0].clientX = (_c = event.changedTouches[0].x) !== null && _c !== void 0 ? _c : event.changedTouches[0].pageX;
7884
8399
  event.offsetY = event.changedTouches[0].y;
7885
- event.changedTouches[0].offsetY = (_c = event.changedTouches[0].y) !== null && _c !== void 0 ? _c : event.changedTouches[0].pageY;
7886
- event.changedTouches[0].clientY = (_d = event.changedTouches[0].y) !== null && _d !== void 0 ? _d : event.changedTouches[0].pageY;
8400
+ event.changedTouches[0].offsetY = (_d = event.changedTouches[0].y) !== null && _d !== void 0 ? _d : event.changedTouches[0].pageY;
8401
+ event.changedTouches[0].clientY = (_e = event.changedTouches[0].y) !== null && _e !== void 0 ? _e : event.changedTouches[0].pageY;
7887
8402
  }
7888
8403
  event.preventDefault = () => {
7889
8404
  return;
@@ -7945,40 +8460,20 @@ function bindWxWindowContribution(container) {
7945
8460
  }
7946
8461
  }
7947
8462
 
7948
- function makeUpCanvas(domref, canvasIdLists, canvasMap, freeCanvasIdx, freeCanvasList, component, forceUpdate) {
7949
- return __awaiter(this, void 0, void 0, function* () {
7950
- const dpr = wx.getSystemInfoSync().pixelRatio;
7951
- for (let i = 0; i < canvasIdLists.length; i++) {
7952
- const id = canvasIdLists[i];
7953
- if (!forceUpdate && canvasMap.has(id)) {
7954
- continue;
7955
- }
7956
- yield new Promise(resolve => {
7957
- let data = wx.createSelectorQuery();
7958
- if (component) {
7959
- data = data.in(component);
7960
- }
7961
- data
7962
- .select(`#${id}`)
7963
- .fields({ node: true, size: true })
7964
- .exec((res) => {
7965
- if (!res[0]) {
7966
- return;
7967
- }
7968
- const canvas = res[0].node;
7969
- const width = res[0].width;
7970
- const height = res[0].height;
7971
- canvas.width = width * dpr;
7972
- canvas.height = height * dpr;
7973
- canvasMap.set(id, canvas);
7974
- if (i >= freeCanvasIdx) {
7975
- freeCanvasList.push(canvas);
7976
- }
7977
- resolve(null);
7978
- });
7979
- });
7980
- }
7981
- });
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;
7982
8477
  }
7983
8478
  class WxEnvContribution extends BaseEnvContribution {
7984
8479
  constructor() {
@@ -7986,8 +8481,7 @@ class WxEnvContribution extends BaseEnvContribution {
7986
8481
  this.type = 'wx';
7987
8482
  this.supportEvent = true;
7988
8483
  this.canvasMap = new Map();
7989
- this.freeCanvasList = [];
7990
- this.canvasIdx = 0;
8484
+ this.wxEnvParams = {};
7991
8485
  this.supportsTouchEvents = true;
7992
8486
  try {
7993
8487
  this.supportsPointerEvents = !!globalThis.PointerEvent;
@@ -7999,11 +8493,10 @@ class WxEnvContribution extends BaseEnvContribution {
7999
8493
  }
8000
8494
  this.applyStyles = true;
8001
8495
  }
8002
- configure(service, params) {
8496
+ configure(service, params = {}) {
8003
8497
  if (service.env === this.type) {
8004
8498
  service.setActiveEnvContribution(this);
8005
- return makeUpCanvas(params.domref, params.canvasIdLists, this.canvasMap, params.freeCanvasIdx, this.freeCanvasList, params.component, params.forceUpdate).then(() => {
8006
- });
8499
+ this.wxEnvParams = params;
8007
8500
  }
8008
8501
  }
8009
8502
  loadImage(url) {
@@ -8013,12 +8506,27 @@ class WxEnvContribution extends BaseEnvContribution {
8013
8506
  });
8014
8507
  }
8015
8508
  loadSvg(url) {
8016
- return Promise.reject();
8509
+ return Promise.resolve({
8510
+ data: null,
8511
+ loadState: 'fail'
8512
+ });
8017
8513
  }
8018
8514
  createCanvas(params) {
8019
- const result = this.freeCanvasList[this.canvasIdx] || this.freeCanvasList[this.freeCanvasList.length - 1];
8020
- this.canvasIdx++;
8021
- 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;
8022
8530
  }
8023
8531
  createOffscreenCanvas(params) {
8024
8532
  return;
@@ -8027,7 +8535,7 @@ class WxEnvContribution extends BaseEnvContribution {
8027
8535
  return;
8028
8536
  }
8029
8537
  getDevicePixelRatio() {
8030
- return wx.getSystemInfoSync().pixelRatio;
8538
+ return getWxPixelRatio(this.wxEnvParams);
8031
8539
  }
8032
8540
  getRequestAnimationFrame() {
8033
8541
  return function (callback) {