@visactor/vrender-kits 1.1.9 → 1.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -19533,101 +19533,6 @@ HarmonyCanvas.env = 'harmony';
19533
19533
 
19534
19534
  const bindHarmonyCanvasModules = createModule(HarmonyCanvas, HarmonyContext2d);
19535
19535
 
19536
- class LynxContext2d extends BrowserContext2d {
19537
- get globalAlpha() {
19538
- return this._globalAlpha;
19539
- }
19540
- set globalAlpha(ga) {
19541
- this.nativeContext.globalAlpha = ga * this.baseGlobalAlpha;
19542
- this._globalAlpha = ga * this.baseGlobalAlpha;
19543
- }
19544
- setLineDash(segments) {
19545
- const a = arguments;
19546
- const _context = this.nativeContext;
19547
- if (!!this.nativeContext.setLineDash) {
19548
- const lineDash = a[0];
19549
- if (lineDash[0] === 0 && lineDash[1] === 0) {
19550
- return;
19551
- }
19552
- lineDash && _context.setLineDash(lineDash);
19553
- }
19554
- }
19555
- _setStrokeStyle(params, attribute, offsetX, offsetY, defaultParams) {
19556
- const _context = this.nativeContext;
19557
- if (!defaultParams) {
19558
- defaultParams = this.strokeAttributes;
19559
- }
19560
- const { strokeOpacity = defaultParams.strokeOpacity, opacity = defaultParams.opacity } = attribute;
19561
- if (strokeOpacity > 1e-12 && opacity > 1e-12) {
19562
- const { lineWidth = defaultParams.lineWidth, stroke = defaultParams.stroke, lineJoin = defaultParams.lineJoin, lineDash = defaultParams.lineDash, lineCap = defaultParams.lineCap, miterLimit = defaultParams.miterLimit, keepStrokeScale = defaultParams.keepStrokeScale, lineDashOffset = defaultParams.lineDashOffset } = attribute;
19563
- _context.globalAlpha = strokeOpacity * opacity * this.baseGlobalAlpha;
19564
- _context.lineWidth = keepStrokeScale ? lineWidth : getScaledStroke$1(this, lineWidth, this.dpr);
19565
- _context.strokeStyle = createColor$1(this, stroke, params, offsetX, offsetY);
19566
- _context.lineJoin = lineJoin;
19567
- if (!(lineDash[0] === 0 && lineDash[1] === 0) && lineDash) {
19568
- _context.setLineDash(lineDash);
19569
- _context.lineDashOffset = lineDashOffset;
19570
- }
19571
- _context.lineCap = lineCap;
19572
- _context.miterLimit = miterLimit;
19573
- }
19574
- }
19575
- measureText(text, method = application.global.measureTextMethod) {
19576
- const dpr = this.dpr || 1;
19577
- this.setTransform(1, 0, 0, 1, 0, 0, true, dpr);
19578
- const metrics = super.measureText(text, method);
19579
- if (dpr === 1 || metrics.fontBoundingBoxAscent == null || metrics.fontBoundingBoxDescent == null) {
19580
- return metrics;
19581
- }
19582
- return Object.assign(Object.assign({}, metrics), { width: metrics.width, actualBoundingBoxLeft: metrics.actualBoundingBoxLeft, actualBoundingBoxRight: metrics.actualBoundingBoxRight, actualBoundingBoxAscent: metrics.actualBoundingBoxAscent, actualBoundingBoxDescent: metrics.actualBoundingBoxDescent, fontBoundingBoxAscent: metrics.fontBoundingBoxAscent / dpr, fontBoundingBoxDescent: metrics.fontBoundingBoxDescent / dpr });
19583
- }
19584
- createPattern(image, repetition) {
19585
- return null;
19586
- }
19587
- draw() {
19588
- const _context = this.nativeContext;
19589
- if (!_context.draw) {
19590
- return;
19591
- }
19592
- this.drawPromise = new Promise(resolve => {
19593
- _context.draw(true, () => {
19594
- this.drawPromise = null;
19595
- resolve(null);
19596
- });
19597
- });
19598
- }
19599
- }
19600
- LynxContext2d.env = 'lynx';
19601
-
19602
- class LynxCanvas extends BaseCanvas {
19603
- constructor(params) {
19604
- super(params);
19605
- }
19606
- init() {
19607
- this._context = new LynxContext2d(this, this._dpr);
19608
- }
19609
- resize(width, height) {
19610
- this._pixelWidth = width * this._dpr;
19611
- this._pixelHeight = height * this._dpr;
19612
- this._displayWidth = width;
19613
- this._displayHeight = height;
19614
- this._nativeCanvas.width = this._pixelWidth;
19615
- this._nativeCanvas.height = this._pixelHeight;
19616
- if (this._nativeCanvas.nativeCanvas) {
19617
- this._nativeCanvas.nativeCanvas.width = this._pixelWidth;
19618
- this._nativeCanvas.nativeCanvas.height = this._pixelHeight;
19619
- }
19620
- const _context = this._context;
19621
- _context.dpr = this._dpr;
19622
- }
19623
- release(...params) {
19624
- return;
19625
- }
19626
- }
19627
- LynxCanvas.env = 'lynx';
19628
-
19629
- const bindLynxCanvasModules = createModule(LynxCanvas, LynxContext2d);
19630
-
19631
19536
  class NodeContext2d extends BrowserContext2d {
19632
19537
  constructor(canvas, dpr) {
19633
19538
  super(canvas, dpr);
@@ -22766,119 +22671,22 @@ function initHarmonyEnv() {
22766
22671
  loadHarmonyEnv();
22767
22672
  }
22768
22673
 
22769
- let MiniAppEventManager$3 = class MiniAppEventManager {
22770
- constructor() {
22771
- this.cache = {};
22772
- }
22773
- addEventListener(type, func) {
22774
- if (!type || !func) {
22775
- return;
22776
- }
22777
- this.cache[type] = this.cache[type] || {
22778
- listener: []
22779
- };
22780
- this.cache[type].listener.push(func);
22781
- }
22782
- removeEventListener(type, func) {
22783
- if (!type || !func) {
22784
- return;
22785
- }
22786
- if (!this.cache[type]) {
22787
- return;
22788
- }
22789
- const index = this.cache[type].listener.findIndex((f) => f === func);
22790
- if (index >= 0) {
22791
- this.cache[type].listener.splice(index, 1);
22792
- }
22793
- }
22794
- cleanEvent() {
22795
- this.cache = {};
22796
- }
22797
- };
22798
- function setMiniAppEventTarget$1(event, key, value) {
22799
- if (!event || !value) {
22800
- return;
22801
- }
22802
- try {
22803
- event[key] = value;
22804
- }
22805
- catch (_a) {
22806
- Object.defineProperty(event, key, {
22807
- configurable: true,
22808
- value
22809
- });
22810
- }
22811
- }
22812
- function isValidCoordinate$1(value) {
22813
- return typeof value === 'number' && Number.isFinite(value);
22814
- }
22815
- function pickCoordinate$1(...values) {
22816
- for (let i = 0; i < values.length; i++) {
22817
- if (isValidCoordinate$1(values[i])) {
22818
- return values[i];
22819
- }
22820
- }
22821
- return undefined;
22822
- }
22823
- function setLynxEventValue(event, key, value) {
22824
- try {
22825
- event[key] = value;
22826
- }
22827
- catch (_a) {
22828
- Object.defineProperty(event, key, {
22829
- configurable: true,
22830
- value
22831
- });
22832
- }
22833
- }
22834
- function normalizeLynxTouchEventPoint(event) {
22835
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
22836
- 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];
22837
- if (!touch) {
22838
- return;
22839
- }
22840
- const x = pickCoordinate$1(event.x, event.offsetX, event.clientX, event.pageX, touch.x, touch.offsetX, touch.clientX, touch.pageX);
22841
- const y = pickCoordinate$1(event.y, event.offsetY, event.clientY, event.pageY, touch.y, touch.offsetY, touch.clientY, touch.pageY);
22842
- if (x == null || y == null) {
22843
- return;
22844
- }
22845
- if (!event.touches && event.changedTouches) {
22846
- setLynxEventValue(event, 'touches', event.type === 'touchend' || event.type === 'touchcancel' ? [] : event.changedTouches);
22847
- }
22848
- setLynxEventValue(event, 'x', x);
22849
- setLynxEventValue(event, 'y', y);
22850
- setLynxEventValue(event, 'offsetX', (_d = event.offsetX) !== null && _d !== void 0 ? _d : x);
22851
- setLynxEventValue(event, 'offsetY', (_e = event.offsetY) !== null && _e !== void 0 ? _e : y);
22852
- setLynxEventValue(event, 'clientX', (_f = event.clientX) !== null && _f !== void 0 ? _f : x);
22853
- setLynxEventValue(event, 'clientY', (_g = event.clientY) !== null && _g !== void 0 ? _g : y);
22854
- setLynxEventValue(event, 'pageX', (_h = event.pageX) !== null && _h !== void 0 ? _h : x);
22855
- setLynxEventValue(event, 'pageY', (_j = event.pageY) !== null && _j !== void 0 ? _j : y);
22856
- touch.x = (_k = touch.x) !== null && _k !== void 0 ? _k : x;
22857
- touch.y = (_l = touch.y) !== null && _l !== void 0 ? _l : y;
22858
- touch.offsetX = (_m = touch.offsetX) !== null && _m !== void 0 ? _m : x;
22859
- touch.offsetY = (_o = touch.offsetY) !== null && _o !== void 0 ? _o : y;
22860
- touch.clientX = (_p = touch.clientX) !== null && _p !== void 0 ? _p : x;
22861
- touch.clientY = (_q = touch.clientY) !== null && _q !== void 0 ? _q : y;
22862
- touch.pageX = (_r = touch.pageX) !== null && _r !== void 0 ? _r : x;
22863
- touch.pageY = (_s = touch.pageY) !== null && _s !== void 0 ? _s : y;
22864
- }
22865
- class LynxWindowHandlerContribution extends BaseWindowHandlerContribution {
22674
+ class NodeWindowHandlerContribution extends BaseWindowHandlerContribution {
22866
22675
  get container() {
22867
22676
  return null;
22868
22677
  }
22869
22678
  constructor(global = application.global) {
22870
22679
  super();
22871
22680
  this.global = global;
22872
- this.type = 'lynx';
22873
- this.eventManager = new MiniAppEventManager$3();
22681
+ this.type = 'node';
22874
22682
  }
22875
22683
  getTitle() {
22876
- return this.canvas.id && this.canvas.id.toString();
22684
+ return '';
22877
22685
  }
22878
22686
  getWH() {
22879
22687
  return {
22880
- width: this.canvas.width / (this.canvas.dpr || 1),
22881
- height: this.canvas.height / (this.canvas.dpr || 1)
22688
+ width: this.canvas.displayWidth,
22689
+ height: this.canvas.displayHeight
22882
22690
  };
22883
22691
  }
22884
22692
  getXY() {
@@ -22893,51 +22701,28 @@ class LynxWindowHandlerContribution extends BaseWindowHandlerContribution {
22893
22701
  }
22894
22702
  }
22895
22703
  createWindowByConfig(params) {
22896
- const nativeCanvas = this.global.createCanvas({
22897
- width: params.width,
22898
- height: params.height
22899
- });
22704
+ const nativeCanvas = this.global.createCanvas({ width: params.width, height: params.height });
22900
22705
  const options = {
22901
22706
  width: params.width,
22902
22707
  height: params.height,
22903
22708
  dpr: params.dpr,
22904
22709
  nativeCanvas,
22905
22710
  id: Generator.GenAutoIncrementId().toString(),
22906
- canvasControled: false
22711
+ canvasControled: true
22907
22712
  };
22908
- this.canvas = new LynxCanvas(options);
22713
+ this.canvas = new NodeCanvas(options);
22909
22714
  }
22910
22715
  createWindowByCanvas(params) {
22911
- let canvas;
22912
- if (typeof params.canvas === 'string') {
22913
- canvas = this.global.getElementById(params.canvas);
22914
- if (!canvas) {
22915
- canvas = this.global.createCanvas({
22916
- id: params.canvas,
22917
- width: params.width,
22918
- height: params.height,
22919
- dpr: params.dpr
22920
- });
22921
- }
22922
- if (!canvas) {
22923
- throw new Error('canvasId 参数不正确,请确认canvas存在并插入dom');
22924
- }
22925
- }
22926
- else {
22927
- canvas = params.canvas;
22928
- }
22716
+ var _a;
22717
+ const canvas = params.canvas;
22718
+ const dpr = (_a = params.dpr) !== null && _a !== void 0 ? _a : 1;
22929
22719
  let width = params.width;
22930
22720
  let height = params.height;
22931
22721
  if (width == null || height == null || !params.canvasControled) {
22932
- const data = canvas.getBoundingClientRect();
22933
- width = data.width;
22934
- height = data.height;
22935
- }
22936
- let dpr = params.dpr;
22937
- if (dpr == null) {
22938
- dpr = canvas.width / width;
22722
+ width = canvas.width / dpr;
22723
+ height = canvas.height / dpr;
22939
22724
  }
22940
- this.canvas = new LynxCanvas({
22725
+ this.canvas = new NodeCanvas({
22941
22726
  width: width,
22942
22727
  height: height,
22943
22728
  dpr: dpr,
@@ -22946,7 +22731,7 @@ class LynxWindowHandlerContribution extends BaseWindowHandlerContribution {
22946
22731
  });
22947
22732
  }
22948
22733
  releaseWindow() {
22949
- return;
22734
+ this.canvas.release();
22950
22735
  }
22951
22736
  resizeWindow(width, height) {
22952
22737
  this.canvas.resize(width, height);
@@ -22963,399 +22748,245 @@ class LynxWindowHandlerContribution extends BaseWindowHandlerContribution {
22963
22748
  getDpr() {
22964
22749
  return this.canvas.dpr;
22965
22750
  }
22966
- addEventListener(type, listener) {
22967
- this.eventManager.addEventListener(type, listener);
22751
+ getImageBuffer(type = 'image/png') {
22752
+ const canvas = this.canvas.nativeCanvas;
22753
+ return canvas.toBuffer(type);
22968
22754
  }
22969
- removeEventListener(type, listener) {
22970
- this.eventManager.removeEventListener(type, listener);
22755
+ addEventListener(type, listener, options) {
22756
+ return;
22971
22757
  }
22972
22758
  dispatchEvent(event) {
22973
- var _a;
22974
- const { type } = event;
22975
- if (!this.eventManager.cache[type]) {
22976
- return false;
22977
- }
22978
- const nativeCanvas = (_a = this.canvas) === null || _a === void 0 ? void 0 : _a.nativeCanvas;
22979
- setMiniAppEventTarget$1(event, 'target', nativeCanvas);
22980
- setMiniAppEventTarget$1(event, 'currentTarget', nativeCanvas);
22981
- normalizeLynxTouchEventPoint(event);
22982
- event.preventDefault = () => {
22983
- return;
22984
- };
22985
- event.stopPropagation = () => {
22986
- return;
22987
- };
22988
- if (this.eventManager.cache[type].listener) {
22989
- this.eventManager.cache[type].listener.forEach((f) => {
22990
- f(event);
22991
- });
22992
- }
22993
22759
  return true;
22994
22760
  }
22761
+ removeEventListener(type, listener, options) {
22762
+ return;
22763
+ }
22995
22764
  getStyle() {
22996
- return {};
22765
+ return;
22997
22766
  }
22998
22767
  setStyle(style) {
22999
22768
  return;
23000
22769
  }
23001
22770
  getBoundingClientRect() {
23002
- const wh = this.getWH();
23003
- return {
23004
- x: 0,
23005
- y: 0,
23006
- width: wh.width,
23007
- height: wh.height,
23008
- left: 0,
23009
- top: 0,
23010
- right: 0,
23011
- bottom: 0
23012
- };
22771
+ return null;
23013
22772
  }
23014
22773
  clearViewBox(color) {
23015
- const vb = this.viewBox;
23016
- const context = this.getContext();
23017
- const dpr = this.getDpr();
23018
- context.nativeContext.save();
23019
- context.nativeContext.setTransform(dpr, 0, 0, dpr, 0, 0);
23020
- context.clearRect(vb.x1, vb.y1, vb.x2 - vb.x1, vb.y2 - vb.y1);
23021
- if (color) {
23022
- context.fillStyle = color;
23023
- context.fillRect(vb.x1, vb.y1, vb.x2 - vb.x1, vb.y2 - vb.y1);
23024
- }
23025
- context.nativeContext.restore();
22774
+ return;
23026
22775
  }
23027
22776
  }
23028
- LynxWindowHandlerContribution.env = 'lynx';
23029
- function bindLynxWindowContribution(container) {
22777
+ NodeWindowHandlerContribution.env = 'node';
22778
+ function bindNodeWindowContribution(container) {
23030
22779
  var _a, _b;
23031
- if (!((_a = container.isBound) === null || _a === void 0 ? void 0 : _a.call(container, LynxWindowHandlerContribution))) {
23032
- container.bind(LynxWindowHandlerContribution).toSelf();
22780
+ if (!((_a = container.isBound) === null || _a === void 0 ? void 0 : _a.call(container, NodeWindowHandlerContribution))) {
22781
+ container.bind(NodeWindowHandlerContribution).toSelf();
23033
22782
  }
23034
- if (!((_b = container.getNamed) === null || _b === void 0 ? void 0 : _b.call(container, WindowHandlerContribution$1, LynxWindowHandlerContribution.env))) {
22783
+ if (!((_b = container.getNamed) === null || _b === void 0 ? void 0 : _b.call(container, WindowHandlerContribution$1, NodeWindowHandlerContribution.env))) {
23035
22784
  container
23036
22785
  .bind(WindowHandlerContribution$1)
23037
- .toService(LynxWindowHandlerContribution)
23038
- .whenTargetNamed(LynxWindowHandlerContribution.env);
22786
+ .toService(NodeWindowHandlerContribution)
22787
+ .whenTargetNamed(NodeWindowHandlerContribution.env);
23039
22788
  }
23040
22789
  }
23041
22790
 
23042
- const LYNX_CANVAS_BRIDGE_ERROR = 'Lynx canvas bridge is unavailable. VRender Lynx env requires envParams.canvasFactory ' +
23043
- 'or a Lynx runtime that exposes createCanvasNG/createCanvas/createOffscreenCanvas/krypton canvas APIs.';
23044
- const LYNX_CANVAS_SIZE_ERROR = 'Lynx canvas size is unavailable. Pass stage width/height when creating a Lynx stage canvas.';
23045
- function isValidCoordinate(value) {
23046
- return typeof value === 'number' && Number.isFinite(value);
23047
- }
23048
- function pickCoordinate(...values) {
23049
- for (let i = 0; i < values.length; i++) {
23050
- if (isValidCoordinate(values[i])) {
23051
- return values[i];
23052
- }
23053
- }
23054
- return undefined;
23055
- }
23056
- function getPrimaryTouch(event) {
23057
- var _a, _b, _c;
23058
- 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];
23059
- }
23060
- function getLynxEventPoint(event) {
23061
- const touch = getPrimaryTouch(event);
23062
- 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);
23063
- 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);
23064
- return x == null || y == null ? null : { x, y };
23065
- }
23066
- function getGlobalLynxRuntime() {
23067
- try {
23068
- return typeof lynx !== 'undefined' ? lynx : undefined;
23069
- }
23070
- catch (err) {
23071
- return undefined;
23072
- }
23073
- }
23074
- function getGlobalSystemPixelRatio() {
23075
- try {
23076
- return typeof SystemInfo !== 'undefined' ? SystemInfo.pixelRatio : undefined;
23077
- }
23078
- catch (err) {
23079
- return undefined;
23080
- }
23081
- }
23082
- function getLynxRuntime(params) {
23083
- var _a, _b;
23084
- 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();
23085
- }
23086
- const requestAnimationFrameBasedSTO = (callback) => rafBasedSto.call(callback);
23087
- const cancelAnimationFrameBasedSTO = (handle) => rafBasedSto.clear(handle);
23088
- function getLynxPixelRatio(params, runtime) {
23089
- var _a, _b, _c, _d, _e;
23090
- 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;
23091
- }
23092
- function attachLynxCanvasToView(canvas, id) {
23093
- var _a;
23094
- (_a = canvas === null || canvas === void 0 ? void 0 : canvas.attachToCanvasView) === null || _a === void 0 ? void 0 : _a.call(canvas, id);
23095
- return canvas;
23096
- }
23097
- function createBoundLynxCanvas(id, runtime) {
23098
- var _a, _b, _c;
23099
- if (typeof ((_a = runtime === null || runtime === void 0 ? void 0 : runtime.krypton) === null || _a === void 0 ? void 0 : _a.createCanvas) === 'function') {
23100
- const canvas = runtime.krypton.createCanvas(id);
23101
- if (canvas) {
23102
- return canvas;
23103
- }
22791
+ class NodeEnvContribution extends BaseEnvContribution {
22792
+ constructor() {
22793
+ super(...arguments);
22794
+ this.type = 'node';
22795
+ this._lastTime = 0;
22796
+ this.supportEvent = false;
23104
22797
  }
23105
- if (typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createCanvasNG) === 'function') {
23106
- const canvas = runtime.createCanvasNG(id);
23107
- if (canvas) {
23108
- return attachLynxCanvasToView(canvas, id);
22798
+ configure(service, pkg) {
22799
+ if (service.env === this.type) {
22800
+ service.setActiveEnvContribution(this);
22801
+ this.pkg = pkg;
23109
22802
  }
23110
22803
  }
23111
- if (typeof ((_b = runtime === null || runtime === void 0 ? void 0 : runtime.krypton) === null || _b === void 0 ? void 0 : _b.createCanvasNG) === 'function') {
23112
- const canvas = runtime.krypton.createCanvasNG();
23113
- if (canvas) {
23114
- return attachLynxCanvasToView(canvas, id);
22804
+ getNodePackage(feature, requiredKey) {
22805
+ if (!this.pkg || (requiredKey && typeof this.pkg[requiredKey] !== 'function')) {
22806
+ throw new Error(`Node env requires node-canvas package before ${feature}. ` +
22807
+ `Use vglobal.setEnv('node', CanvasPkg) before createNodeVRenderApp(), ` +
22808
+ `or createNodeVRenderApp({ envParams: CanvasPkg }).`);
23115
22809
  }
22810
+ return this.pkg;
23116
22811
  }
23117
- if (typeof ((_c = runtime === null || runtime === void 0 ? void 0 : runtime.krypton) === null || _c === void 0 ? void 0 : _c.CanvasElement) === 'function') {
23118
- return new runtime.krypton.CanvasElement(id);
22812
+ getDynamicCanvasCount() {
22813
+ return 0;
23119
22814
  }
23120
- if (typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createCanvas) === 'function') {
23121
- const canvas = runtime.createCanvas(id);
23122
- if (canvas) {
23123
- return canvas;
23124
- }
22815
+ getStaticCanvasCount() {
22816
+ return 999;
23125
22817
  }
23126
- return null;
23127
- }
23128
- function getCanvasSize(width, height) {
23129
- if (!isValidCoordinate(width) || !isValidCoordinate(height)) {
23130
- throw new Error(LYNX_CANVAS_SIZE_ERROR);
22818
+ loadJson(url) {
22819
+ const jsonPromise = fetch(url).then(data => data.json());
22820
+ jsonPromise
22821
+ .then(json => {
22822
+ return {
22823
+ data: json,
22824
+ state: 'success'
22825
+ };
22826
+ })
22827
+ .catch(() => {
22828
+ return {
22829
+ data: null,
22830
+ state: 'fail'
22831
+ };
22832
+ });
22833
+ return jsonPromise;
23131
22834
  }
23132
- return { width, height };
23133
- }
23134
- function wrapLynxNativeCanvas(nativeCanvas, id, width, height, dpr) {
23135
- nativeCanvas.width = width * dpr;
23136
- nativeCanvas.height = height * dpr;
23137
- const ctx = nativeCanvas.getContext('2d');
23138
- return new CanvasWrapEnableWH(nativeCanvas, ctx, dpr, width, height, id);
23139
- }
23140
- function createLynxNativeCanvas(id, width, height, dpr, offscreen, params, runtime) {
23141
- if (params.canvasFactory) {
23142
- return params.canvasFactory({
23143
- id,
23144
- width,
23145
- height,
23146
- dpr,
23147
- offscreen
22835
+ loadArrayBuffer(url) {
22836
+ const arrayBufferPromise = fetch(url).then(data => data.arrayBuffer());
22837
+ return arrayBufferPromise
22838
+ .then((arrayBuffer) => {
22839
+ return {
22840
+ data: arrayBuffer,
22841
+ loadState: 'success'
22842
+ };
22843
+ })
22844
+ .catch(() => {
22845
+ return {
22846
+ data: null,
22847
+ loadState: 'fail'
22848
+ };
23148
22849
  });
23149
22850
  }
23150
- if (offscreen) {
23151
- if (typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createOffscreenCanvas) === 'function') {
23152
- return runtime.createOffscreenCanvas();
22851
+ loadImage(url) {
22852
+ const { loadImage } = this.getNodePackage('loadImage', 'loadImage');
22853
+ if (loadImage) {
22854
+ return loadImage(url)
22855
+ .then((image) => {
22856
+ const loadState = image ? 'success' : 'fail';
22857
+ return {
22858
+ loadState,
22859
+ data: image
22860
+ };
22861
+ })
22862
+ .catch(() => {
22863
+ return {
22864
+ loadState: 'fail',
22865
+ data: null
22866
+ };
22867
+ });
23153
22868
  }
22869
+ return Promise.reject(new Error('node-canvas loadImage could not be found!'));
23154
22870
  }
23155
- else {
23156
- const canvas = createBoundLynxCanvas(id, runtime);
23157
- if (canvas) {
23158
- return canvas;
22871
+ loadSvg(svgStr) {
22872
+ const Resvg = this.getNodePackage('loadSvg').Resvg;
22873
+ if (!Resvg) {
22874
+ return Promise.reject(new Error('@resvg/resvg-js svgParser could not be found!'));
23159
22875
  }
22876
+ const resvg = new Resvg(svgStr);
22877
+ const pngData = resvg.render().asPng();
22878
+ return this.loadImage(pngData);
23160
22879
  }
23161
- throw new Error(LYNX_CANVAS_BRIDGE_ERROR);
23162
- }
23163
- function createImageElement(src, isSvg = false, runtime = getGlobalLynxRuntime()) {
23164
- if (isSvg) {
23165
- return Promise.reject();
22880
+ createCanvas(params) {
22881
+ const { createCanvas } = this.getNodePackage('createCanvas', 'createCanvas');
22882
+ const canvas = createCanvas(params.width, params.height);
22883
+ return canvas;
23166
22884
  }
23167
- if (typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createImage) !== 'function') {
23168
- return Promise.reject(new Error('Lynx image bridge is unavailable.'));
23169
- }
23170
- const img = runtime.createImage(src);
23171
- const promise = new Promise((resolve, reject) => {
23172
- img.onload = () => {
23173
- resolve(img);
23174
- };
23175
- img.onerror = () => {
23176
- reject(new Error('加载失败'));
23177
- };
23178
- });
23179
- return promise;
23180
- }
23181
- class LynxEnvContribution extends BaseEnvContribution {
23182
- constructor() {
23183
- super();
23184
- this.type = 'lynx';
23185
- this.supportEvent = true;
23186
- this.canvasMap = new Map();
23187
- this.freeCanvasList = [];
23188
- this.canvasIdx = 0;
23189
- this.requestAnimationFrame = requestAnimationFrameBasedSTO;
23190
- this.cancelAnimationFrame = cancelAnimationFrameBasedSTO;
23191
- this.supportsTouchEvents = true;
23192
- try {
23193
- this.supportsPointerEvents = !!globalThis.PointerEvent;
23194
- this.supportsMouseEvents = !!globalThis.MouseEvent;
23195
- }
23196
- catch (err) {
23197
- this.supportsPointerEvents = false;
23198
- this.supportsMouseEvents = false;
23199
- }
23200
- this.applyStyles = true;
23201
- }
23202
- configure(service, params = {}) {
23203
- var _a, _b;
23204
- if (service.env === this.type) {
23205
- service.setActiveEnvContribution(this);
23206
- this.lynxEnvParams = params;
23207
- this.lynxRuntime = getLynxRuntime(params);
23208
- if (typeof ((_a = this.lynxRuntime) === null || _a === void 0 ? void 0 : _a.requestAnimationFrame) === 'function' &&
23209
- typeof ((_b = this.lynxRuntime) === null || _b === void 0 ? void 0 : _b.cancelAnimationFrame) === 'function') {
23210
- this.requestAnimationFrame = this.lynxRuntime.requestAnimationFrame.bind(this.lynxRuntime);
23211
- this.cancelAnimationFrame = this.lynxRuntime.cancelAnimationFrame.bind(this.lynxRuntime);
23212
- }
23213
- else {
23214
- this.requestAnimationFrame = requestAnimationFrameBasedSTO;
23215
- this.cancelAnimationFrame = cancelAnimationFrameBasedSTO;
23216
- }
23217
- }
23218
- }
23219
- getDynamicCanvasCount() {
23220
- return this.freeCanvasList.length;
23221
- }
23222
- getStaticCanvasCount() {
23223
- return 9999;
23224
- }
23225
- loadImage(url) {
23226
- const imagePromise = createImageElement(url, false, this.lynxRuntime);
23227
- return imagePromise
23228
- .then((img) => {
23229
- return {
23230
- data: img,
23231
- loadState: 'success'
23232
- };
23233
- })
23234
- .catch(() => {
23235
- return {
23236
- data: null,
23237
- loadState: 'fail'
23238
- };
23239
- });
23240
- }
23241
- loadSvg(url) {
23242
- return Promise.resolve({
23243
- data: null,
23244
- loadState: 'fail'
23245
- });
23246
- }
23247
- createCanvas(params) {
23248
- var _a, _b, _c, _d;
23249
- if (params.id != null) {
23250
- const id = String(params.id);
23251
- const existing = this.canvasMap.get(id);
23252
- if (existing) {
23253
- return existing;
23254
- }
23255
- const envParams = (_a = this.lynxEnvParams) !== null && _a !== void 0 ? _a : {};
23256
- const runtime = getLynxRuntime(envParams);
23257
- const dpr = (_b = params.dpr) !== null && _b !== void 0 ? _b : getLynxPixelRatio(envParams, runtime);
23258
- const size = getCanvasSize(params.width, params.height);
23259
- const nativeCanvas = createLynxNativeCanvas(id, size.width, size.height, dpr, false, envParams, runtime);
23260
- const canvas = wrapLynxNativeCanvas(nativeCanvas, id, size.width, size.height, dpr);
23261
- this.canvasMap.set(id, canvas);
23262
- return canvas;
23263
- }
23264
- const result = this.freeCanvasList[this.canvasIdx] || this.freeCanvasList[this.freeCanvasList.length - 1];
23265
- this.canvasIdx++;
23266
- if (result) {
23267
- return result;
23268
- }
23269
- const envParams = (_c = this.lynxEnvParams) !== null && _c !== void 0 ? _c : {};
23270
- const runtime = getLynxRuntime(envParams);
23271
- const dpr = (_d = params.dpr) !== null && _d !== void 0 ? _d : getLynxPixelRatio(envParams, runtime);
23272
- const size = getCanvasSize(params.width, params.height);
23273
- const id = Math.random().toString();
23274
- const nativeCanvas = createLynxNativeCanvas(id, size.width, size.height, dpr, true, envParams, runtime);
23275
- const canvas = wrapLynxNativeCanvas(nativeCanvas, id, size.width, size.height, dpr);
23276
- this.canvasMap.set(id, canvas);
23277
- this.freeCanvasList.push(canvas);
23278
- return canvas;
23279
- }
23280
- createOffscreenCanvas(params) {
23281
- return;
23282
- }
23283
- releaseCanvas(canvas) {
23284
- return;
22885
+ releaseCanvas(canvas) {
22886
+ return;
23285
22887
  }
23286
22888
  getDevicePixelRatio() {
23287
- return getLynxPixelRatio(undefined, this.lynxRuntime);
22889
+ return 1;
23288
22890
  }
23289
22891
  getRequestAnimationFrame() {
23290
- return this.requestAnimationFrame;
22892
+ return function (callback) {
22893
+ return rafBasedSto.call(callback);
22894
+ };
23291
22895
  }
23292
22896
  getCancelAnimationFrame() {
23293
- return this.cancelAnimationFrame;
23294
- }
23295
- mapToCanvasPoint(event) {
23296
- var _a;
23297
- return (_a = getLynxEventPoint(event)) !== null && _a !== void 0 ? _a : event;
22897
+ return (h) => {
22898
+ rafBasedSto.clear(h);
22899
+ };
23298
22900
  }
23299
22901
  addEventListener(type, listener, options) {
23300
- return null;
22902
+ return;
23301
22903
  }
23302
22904
  removeEventListener(type, listener, options) {
23303
- return null;
23304
- }
23305
- dispatchEvent(event) {
23306
- return null;
22905
+ return;
23307
22906
  }
23308
22907
  getElementById(str) {
23309
- return this.canvasMap.get(str);
22908
+ return null;
23310
22909
  }
23311
22910
  getRootElement() {
23312
22911
  return null;
23313
22912
  }
23314
- getDocument() {
23315
- return null;
22913
+ dispatchEvent(event) {
22914
+ return;
23316
22915
  }
23317
22916
  release(...params) {
23318
22917
  return;
23319
22918
  }
22919
+ createOffscreenCanvas(params) {
22920
+ return;
22921
+ }
23320
22922
  }
23321
22923
 
23322
- function bindLynxEnv(container) {
22924
+ function bindNodeEnv(container) {
23323
22925
  var _a, _b;
23324
- if (!((_b = (_a = container).isBound) === null || _b === void 0 ? void 0 : _b.call(_a, LynxEnvContribution))) {
23325
- container.bind(LynxEnvContribution).toSelf().inSingletonScope();
23326
- container.bind(EnvContribution$1).toService(LynxEnvContribution);
22926
+ if (!((_b = (_a = container).isBound) === null || _b === void 0 ? void 0 : _b.call(_a, NodeEnvContribution))) {
22927
+ container.bind(NodeEnvContribution).toSelf().inSingletonScope();
22928
+ container.bind(EnvContribution$1).toService(NodeEnvContribution);
23327
22929
  }
23328
22930
  }
23329
- function loadLynxEnv(container = getLegacyBindingContext$1(), loadPicker = true) {
23330
- if (!loadLynxEnv.__loaded) {
23331
- loadLynxEnv.__loaded = true;
23332
- bindLynxEnv(container);
23333
- bindLynxCanvasModules(container);
23334
- bindLynxWindowContribution(container);
23335
- loadPicker && loadMathPicker(container);
22931
+ function loadNodeEnv(container = getLegacyBindingContext$1(), loadPicker = true) {
22932
+ if (!loadNodeEnv.__loaded) {
22933
+ loadNodeEnv.__loaded = true;
22934
+ bindNodeEnv(container);
22935
+ bindNodeCanvasModules(container);
22936
+ bindNodeWindowContribution(container);
23336
22937
  }
23337
22938
  }
23338
- loadLynxEnv.__loaded = false;
23339
- function initLynxEnv() {
23340
- loadLynxEnv();
22939
+ loadNodeEnv.__loaded = false;
22940
+ function initNodeEnv() {
22941
+ loadNodeEnv();
23341
22942
  }
23342
22943
 
23343
- class NodeWindowHandlerContribution extends BaseWindowHandlerContribution {
22944
+ let MiniAppEventManager$3 = class MiniAppEventManager {
22945
+ constructor() {
22946
+ this.cache = {};
22947
+ }
22948
+ addEventListener(type, func) {
22949
+ if (!type || !func) {
22950
+ return;
22951
+ }
22952
+ this.cache[type] = this.cache[type] || {
22953
+ listener: []
22954
+ };
22955
+ this.cache[type].listener.push(func);
22956
+ }
22957
+ removeEventListener(type, func) {
22958
+ if (!type || !func) {
22959
+ return;
22960
+ }
22961
+ if (!this.cache[type]) {
22962
+ return;
22963
+ }
22964
+ const index = this.cache[type].listener.findIndex((f) => f === func);
22965
+ if (index >= 0) {
22966
+ this.cache[type].listener.splice(index, 1);
22967
+ }
22968
+ }
22969
+ cleanEvent() {
22970
+ this.cache = {};
22971
+ }
22972
+ };
22973
+ class TaroWindowHandlerContribution extends BaseWindowHandlerContribution {
23344
22974
  get container() {
23345
22975
  return null;
23346
22976
  }
23347
22977
  constructor(global = application.global) {
23348
22978
  super();
23349
22979
  this.global = global;
23350
- this.type = 'node';
22980
+ this.type = 'taro';
22981
+ this.eventManager = new MiniAppEventManager$3();
23351
22982
  }
23352
22983
  getTitle() {
23353
- return '';
22984
+ return this.canvas.id.toString();
23354
22985
  }
23355
22986
  getWH() {
23356
22987
  return {
23357
- width: this.canvas.displayWidth,
23358
- height: this.canvas.displayHeight
22988
+ width: this.canvas.width / (this.canvas.dpr || 1),
22989
+ height: this.canvas.height / (this.canvas.dpr || 1)
23359
22990
  };
23360
22991
  }
23361
22992
  getXY() {
@@ -23370,28 +23001,51 @@ class NodeWindowHandlerContribution extends BaseWindowHandlerContribution {
23370
23001
  }
23371
23002
  }
23372
23003
  createWindowByConfig(params) {
23373
- const nativeCanvas = this.global.createCanvas({ width: params.width, height: params.height });
23004
+ const nativeCanvas = this.global.createCanvas({
23005
+ width: params.width,
23006
+ height: params.height
23007
+ });
23374
23008
  const options = {
23375
23009
  width: params.width,
23376
23010
  height: params.height,
23377
23011
  dpr: params.dpr,
23378
23012
  nativeCanvas,
23379
23013
  id: Generator.GenAutoIncrementId().toString(),
23380
- canvasControled: true
23014
+ canvasControled: false
23381
23015
  };
23382
- this.canvas = new NodeCanvas(options);
23016
+ this.canvas = new TaroCanvas(options);
23383
23017
  }
23384
23018
  createWindowByCanvas(params) {
23385
- var _a;
23386
- const canvas = params.canvas;
23387
- const dpr = (_a = params.dpr) !== null && _a !== void 0 ? _a : 1;
23019
+ let canvas;
23020
+ if (typeof params.canvas === 'string') {
23021
+ canvas = this.global.getElementById(params.canvas);
23022
+ if (!canvas) {
23023
+ canvas = this.global.createCanvas({
23024
+ id: params.canvas,
23025
+ width: params.width,
23026
+ height: params.height,
23027
+ dpr: params.dpr
23028
+ });
23029
+ }
23030
+ if (!canvas) {
23031
+ throw new Error('canvasId 参数不正确,请确认canvas存在并插入dom');
23032
+ }
23033
+ }
23034
+ else {
23035
+ canvas = params.canvas;
23036
+ }
23388
23037
  let width = params.width;
23389
23038
  let height = params.height;
23390
23039
  if (width == null || height == null || !params.canvasControled) {
23391
- width = canvas.width / dpr;
23392
- height = canvas.height / dpr;
23040
+ const data = canvas.getBoundingClientRect();
23041
+ width = data.width;
23042
+ height = data.height;
23393
23043
  }
23394
- this.canvas = new NodeCanvas({
23044
+ let dpr = params.dpr;
23045
+ if (dpr == null) {
23046
+ dpr = canvas.width / width;
23047
+ }
23048
+ this.canvas = new TaroCanvas({
23395
23049
  width: width,
23396
23050
  height: height,
23397
23051
  dpr: dpr,
@@ -23400,10 +23054,10 @@ class NodeWindowHandlerContribution extends BaseWindowHandlerContribution {
23400
23054
  });
23401
23055
  }
23402
23056
  releaseWindow() {
23403
- this.canvas.release();
23057
+ return;
23404
23058
  }
23405
23059
  resizeWindow(width, height) {
23406
- this.canvas.resize(width, height);
23060
+ return;
23407
23061
  }
23408
23062
  setDpr(dpr) {
23409
23063
  this.canvas.dpr = dpr;
@@ -23417,197 +23071,233 @@ class NodeWindowHandlerContribution extends BaseWindowHandlerContribution {
23417
23071
  getDpr() {
23418
23072
  return this.canvas.dpr;
23419
23073
  }
23420
- getImageBuffer(type = 'image/png') {
23421
- const canvas = this.canvas.nativeCanvas;
23422
- return canvas.toBuffer(type);
23074
+ addEventListener(type, listener) {
23075
+ this.eventManager.addEventListener(type, listener);
23423
23076
  }
23424
- addEventListener(type, listener, options) {
23425
- return;
23077
+ removeEventListener(type, listener) {
23078
+ this.eventManager.removeEventListener(type, listener);
23426
23079
  }
23427
23080
  dispatchEvent(event) {
23081
+ const { type } = event;
23082
+ if (!this.eventManager.cache[type]) {
23083
+ return false;
23084
+ }
23085
+ if (event.changedTouches.length > 0) {
23086
+ event.changedTouches.forEach((d, i) => {
23087
+ event.changedTouches[i] = Object.assign(Object.assign({}, event.changedTouches[i]), { offsetX: d.x, offsetY: d.y });
23088
+ });
23089
+ event.offsetX = event.changedTouches[0].offsetX;
23090
+ event.offsetY = event.changedTouches[0].offsetY;
23091
+ }
23092
+ if (event.touches.length > 0) {
23093
+ event.touches.forEach((d, i) => {
23094
+ event.touches[i] = Object.assign(Object.assign({}, event.touches[i]), { offsetX: d.x, offsetY: d.y });
23095
+ });
23096
+ }
23097
+ event.preventDefault = () => {
23098
+ return;
23099
+ };
23100
+ event.stopPropagation = () => {
23101
+ return;
23102
+ };
23103
+ if (this.eventManager.cache[type].listener) {
23104
+ this.eventManager.cache[type].listener.forEach((f) => {
23105
+ f(event);
23106
+ });
23107
+ }
23428
23108
  return true;
23429
23109
  }
23430
- removeEventListener(type, listener, options) {
23431
- return;
23432
- }
23433
23110
  getStyle() {
23434
- return;
23111
+ return {};
23435
23112
  }
23436
23113
  setStyle(style) {
23437
23114
  return;
23438
23115
  }
23439
23116
  getBoundingClientRect() {
23440
- return null;
23117
+ const wh = this.getWH();
23118
+ return {
23119
+ x: 0,
23120
+ y: 0,
23121
+ width: wh.width,
23122
+ height: wh.height,
23123
+ left: 0,
23124
+ top: 0,
23125
+ right: 0,
23126
+ bottom: 0
23127
+ };
23441
23128
  }
23442
23129
  clearViewBox(color) {
23443
- return;
23130
+ const vb = this.viewBox;
23131
+ const context = this.getContext();
23132
+ const dpr = this.getDpr();
23133
+ context.nativeContext.save();
23134
+ context.nativeContext.setTransform(dpr, 0, 0, dpr, 0, 0);
23135
+ context.clearRect(vb.x1, vb.y1, vb.x2 - vb.x1, vb.y2 - vb.y1);
23136
+ if (color) {
23137
+ context.fillStyle = color;
23138
+ context.fillRect(vb.x1, vb.y1, vb.x2 - vb.x1, vb.y2 - vb.y1);
23139
+ }
23140
+ context.nativeContext.restore();
23444
23141
  }
23445
23142
  }
23446
- NodeWindowHandlerContribution.env = 'node';
23447
- function bindNodeWindowContribution(container) {
23143
+ TaroWindowHandlerContribution.env = 'taro';
23144
+ function bindTaroWindowContribution(container) {
23448
23145
  var _a, _b;
23449
- if (!((_a = container.isBound) === null || _a === void 0 ? void 0 : _a.call(container, NodeWindowHandlerContribution))) {
23450
- container.bind(NodeWindowHandlerContribution).toSelf();
23146
+ if (!((_a = container.isBound) === null || _a === void 0 ? void 0 : _a.call(container, TaroWindowHandlerContribution))) {
23147
+ container.bind(TaroWindowHandlerContribution).toSelf();
23451
23148
  }
23452
- if (!((_b = container.getNamed) === null || _b === void 0 ? void 0 : _b.call(container, WindowHandlerContribution$1, NodeWindowHandlerContribution.env))) {
23149
+ if (!((_b = container.getNamed) === null || _b === void 0 ? void 0 : _b.call(container, WindowHandlerContribution$1, TaroWindowHandlerContribution.env))) {
23453
23150
  container
23454
23151
  .bind(WindowHandlerContribution$1)
23455
- .toService(NodeWindowHandlerContribution)
23456
- .whenTargetNamed(NodeWindowHandlerContribution.env);
23152
+ .toService(TaroWindowHandlerContribution)
23153
+ .whenTargetNamed(TaroWindowHandlerContribution.env);
23457
23154
  }
23458
23155
  }
23459
23156
 
23460
- class NodeEnvContribution extends BaseEnvContribution {
23157
+ const TARO_CANVAS_BRIDGE_ERROR = 'Taro canvas bridge is unavailable. VRender taro env requires envParams.canvasFactory, ' +
23158
+ 'a Stage canvas object, or envParams.taro.createCanvasContext(id).';
23159
+ class TaroEnvContribution extends BaseEnvContribution {
23461
23160
  constructor() {
23462
- super(...arguments);
23463
- this.type = 'node';
23464
- this._lastTime = 0;
23465
- this.supportEvent = false;
23466
- }
23467
- configure(service, pkg) {
23468
- if (service.env === this.type) {
23469
- service.setActiveEnvContribution(this);
23470
- this.pkg = pkg;
23161
+ super();
23162
+ this.type = 'taro';
23163
+ this.supportEvent = true;
23164
+ this.canvasMap = new Map();
23165
+ this.pixelRatio = 1;
23166
+ this.taroEnvParams = {};
23167
+ this.supportsTouchEvents = true;
23168
+ try {
23169
+ this.supportsPointerEvents = !!globalThis.PointerEvent;
23170
+ this.supportsMouseEvents = !!globalThis.MouseEvent;
23471
23171
  }
23472
- }
23473
- getNodePackage(feature, requiredKey) {
23474
- if (!this.pkg || (requiredKey && typeof this.pkg[requiredKey] !== 'function')) {
23475
- throw new Error(`Node env requires node-canvas package before ${feature}. ` +
23476
- `Use vglobal.setEnv('node', CanvasPkg) before createNodeVRenderApp(), ` +
23477
- `or createNodeVRenderApp({ envParams: CanvasPkg }).`);
23172
+ catch (err) {
23173
+ this.supportsPointerEvents = false;
23174
+ this.supportsMouseEvents = false;
23478
23175
  }
23479
- return this.pkg;
23176
+ this.applyStyles = true;
23480
23177
  }
23481
23178
  getDynamicCanvasCount() {
23482
23179
  return 0;
23483
23180
  }
23484
23181
  getStaticCanvasCount() {
23485
- return 999;
23182
+ return 9999;
23486
23183
  }
23487
- loadJson(url) {
23488
- const jsonPromise = fetch(url).then(data => data.json());
23489
- jsonPromise
23490
- .then(json => {
23491
- return {
23492
- data: json,
23493
- state: 'success'
23494
- };
23495
- })
23496
- .catch(() => {
23497
- return {
23498
- data: null,
23499
- state: 'fail'
23500
- };
23501
- });
23502
- return jsonPromise;
23184
+ mapToCanvasPoint(event) {
23185
+ var _a;
23186
+ if ((_a = event === null || event === void 0 ? void 0 : event.type) === null || _a === void 0 ? void 0 : _a.startsWith('mouse')) {
23187
+ return event;
23188
+ }
23189
+ return event;
23503
23190
  }
23504
- loadArrayBuffer(url) {
23505
- const arrayBufferPromise = fetch(url).then(data => data.arrayBuffer());
23506
- return arrayBufferPromise
23507
- .then((arrayBuffer) => {
23508
- return {
23509
- data: arrayBuffer,
23510
- loadState: 'success'
23511
- };
23512
- })
23513
- .catch(() => {
23514
- return {
23515
- data: null,
23516
- loadState: 'fail'
23517
- };
23518
- });
23191
+ configure(service, params = {}) {
23192
+ var _a;
23193
+ if (service.env === this.type) {
23194
+ service.setActiveEnvContribution(this);
23195
+ this.taroEnvParams = params;
23196
+ this.taro = params.taro;
23197
+ this.pixelRatio = (_a = params.pixelRatio) !== null && _a !== void 0 ? _a : 1;
23198
+ }
23519
23199
  }
23520
23200
  loadImage(url) {
23521
- const { loadImage } = this.getNodePackage('loadImage', 'loadImage');
23522
- if (loadImage) {
23523
- return loadImage(url)
23524
- .then((image) => {
23525
- const loadState = image ? 'success' : 'fail';
23526
- return {
23527
- loadState,
23528
- data: image
23529
- };
23530
- })
23531
- .catch(() => {
23532
- return {
23533
- loadState: 'fail',
23534
- data: null
23535
- };
23536
- });
23537
- }
23538
- return Promise.reject(new Error('node-canvas loadImage could not be found!'));
23201
+ return Promise.resolve({
23202
+ data: url,
23203
+ loadState: 'success'
23204
+ });
23539
23205
  }
23540
23206
  loadSvg(svgStr) {
23541
- const Resvg = this.getNodePackage('loadSvg').Resvg;
23542
- if (!Resvg) {
23543
- return Promise.reject(new Error('@resvg/resvg-js svgParser could not be found!'));
23207
+ const _window = typeof window !== 'undefined' ? window : globalThis;
23208
+ if (_window.DOMParser) {
23209
+ const parser = new _window.DOMParser();
23210
+ const svg = parser.parseFromString(svgStr, 'image/svg+xml').children[0];
23211
+ const data = new XMLSerializer().serializeToString(svg);
23212
+ const url = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(data)}`;
23213
+ return Promise.resolve({
23214
+ data: url,
23215
+ loadState: 'success'
23216
+ });
23544
23217
  }
23545
- const resvg = new Resvg(svgStr);
23546
- const pngData = resvg.render().asPng();
23547
- return this.loadImage(pngData);
23218
+ else if (_window.Blob) {
23219
+ const data = new _window.Blob([svgStr], { type: 'image/svg+xml' });
23220
+ const url = _window.URL.createObjectURL(data);
23221
+ return Promise.resolve({
23222
+ data: url,
23223
+ loadState: 'success'
23224
+ });
23225
+ }
23226
+ return Promise.reject();
23548
23227
  }
23549
23228
  createCanvas(params) {
23550
- const { createCanvas } = this.getNodePackage('createCanvas', 'createCanvas');
23551
- const canvas = createCanvas(params.width, params.height);
23229
+ var _a, _b;
23230
+ const envParams = this.taroEnvParams;
23231
+ const dpr = (_a = params.dpr) !== null && _a !== void 0 ? _a : this.getDevicePixelRatio();
23232
+ const factoryCanvas = createCanvasWithFactory(params, dpr, this.canvasMap, envParams.canvasFactory);
23233
+ if (factoryCanvas) {
23234
+ return factoryCanvas;
23235
+ }
23236
+ const options = getMiniAppCanvasOptions(params, dpr, false);
23237
+ if (options.id == null || typeof ((_b = envParams.taro) === null || _b === void 0 ? void 0 : _b.createCanvasContext) !== 'function') {
23238
+ throw new Error(TARO_CANVAS_BRIDGE_ERROR);
23239
+ }
23240
+ const canvas = wrapMiniAppContextCanvas(envParams.taro.createCanvasContext(options.id), options);
23241
+ this.canvasMap.set(options.id, canvas);
23552
23242
  return canvas;
23553
23243
  }
23244
+ createOffscreenCanvas(params) {
23245
+ return;
23246
+ }
23554
23247
  releaseCanvas(canvas) {
23555
23248
  return;
23556
23249
  }
23557
23250
  getDevicePixelRatio() {
23558
- return 1;
23251
+ return this.pixelRatio;
23559
23252
  }
23560
23253
  getRequestAnimationFrame() {
23561
- return function (callback) {
23562
- return rafBasedSto.call(callback);
23563
- };
23254
+ return requestAnimationFrame;
23564
23255
  }
23565
23256
  getCancelAnimationFrame() {
23566
- return (h) => {
23567
- rafBasedSto.clear(h);
23568
- };
23257
+ return cancelAnimationFrame;
23569
23258
  }
23570
23259
  addEventListener(type, listener, options) {
23571
- return;
23260
+ return null;
23572
23261
  }
23573
23262
  removeEventListener(type, listener, options) {
23574
- return;
23263
+ return null;
23575
23264
  }
23576
- getElementById(str) {
23265
+ dispatchEvent(event) {
23577
23266
  return null;
23578
23267
  }
23268
+ getElementById(str) {
23269
+ return this.canvasMap.get(str);
23270
+ }
23579
23271
  getRootElement() {
23580
23272
  return null;
23581
23273
  }
23582
- dispatchEvent(event) {
23583
- return;
23274
+ getDocument() {
23275
+ return null;
23584
23276
  }
23585
23277
  release(...params) {
23586
23278
  return;
23587
23279
  }
23588
- createOffscreenCanvas(params) {
23589
- return;
23590
- }
23591
23280
  }
23592
23281
 
23593
- function bindNodeEnv(container) {
23282
+ function bindTaroEnv(container) {
23594
23283
  var _a, _b;
23595
- if (!((_b = (_a = container).isBound) === null || _b === void 0 ? void 0 : _b.call(_a, NodeEnvContribution))) {
23596
- container.bind(NodeEnvContribution).toSelf().inSingletonScope();
23597
- container.bind(EnvContribution$1).toService(NodeEnvContribution);
23284
+ if (!((_b = (_a = container).isBound) === null || _b === void 0 ? void 0 : _b.call(_a, TaroEnvContribution))) {
23285
+ container.bind(TaroEnvContribution).toSelf().inSingletonScope();
23286
+ container.bind(EnvContribution$1).toService(TaroEnvContribution);
23598
23287
  }
23599
23288
  }
23600
- function loadNodeEnv(container = getLegacyBindingContext$1(), loadPicker = true) {
23601
- if (!loadNodeEnv.__loaded) {
23602
- loadNodeEnv.__loaded = true;
23603
- bindNodeEnv(container);
23604
- bindNodeCanvasModules(container);
23605
- bindNodeWindowContribution(container);
23289
+ function loadTaroEnv(container = getLegacyBindingContext$1(), loadPicker = true) {
23290
+ if (!loadTaroEnv.__loaded) {
23291
+ loadTaroEnv.__loaded = true;
23292
+ bindTaroEnv(container);
23293
+ bindTaroCanvasModules(container);
23294
+ bindTaroWindowContribution(container);
23295
+ loadPicker && loadMathPicker(container);
23606
23296
  }
23607
23297
  }
23608
- loadNodeEnv.__loaded = false;
23609
- function initNodeEnv() {
23610
- loadNodeEnv();
23298
+ loadTaroEnv.__loaded = false;
23299
+ function initTaroEnv() {
23300
+ loadTaroEnv();
23611
23301
  }
23612
23302
 
23613
23303
  let MiniAppEventManager$2 = class MiniAppEventManager {
@@ -23639,14 +23329,14 @@ let MiniAppEventManager$2 = class MiniAppEventManager {
23639
23329
  this.cache = {};
23640
23330
  }
23641
23331
  };
23642
- class TaroWindowHandlerContribution extends BaseWindowHandlerContribution {
23332
+ class TTWindowHandlerContribution extends BaseWindowHandlerContribution {
23643
23333
  get container() {
23644
23334
  return null;
23645
23335
  }
23646
23336
  constructor(global = application.global) {
23647
23337
  super();
23648
23338
  this.global = global;
23649
- this.type = 'taro';
23339
+ this.type = 'tt';
23650
23340
  this.eventManager = new MiniAppEventManager$2();
23651
23341
  }
23652
23342
  getTitle() {
@@ -23682,7 +23372,7 @@ class TaroWindowHandlerContribution extends BaseWindowHandlerContribution {
23682
23372
  id: Generator.GenAutoIncrementId().toString(),
23683
23373
  canvasControled: false
23684
23374
  };
23685
- this.canvas = new TaroCanvas(options);
23375
+ this.canvas = new TTCanvas(options);
23686
23376
  }
23687
23377
  createWindowByCanvas(params) {
23688
23378
  let canvas;
@@ -23714,7 +23404,7 @@ class TaroWindowHandlerContribution extends BaseWindowHandlerContribution {
23714
23404
  if (dpr == null) {
23715
23405
  dpr = canvas.width / width;
23716
23406
  }
23717
- this.canvas = new TaroCanvas({
23407
+ this.canvas = new TTCanvas({
23718
23408
  width: width,
23719
23409
  height: height,
23720
23410
  dpr: dpr,
@@ -23751,17 +23441,13 @@ class TaroWindowHandlerContribution extends BaseWindowHandlerContribution {
23751
23441
  if (!this.eventManager.cache[type]) {
23752
23442
  return false;
23753
23443
  }
23754
- if (event.changedTouches.length > 0) {
23755
- event.changedTouches.forEach((d, i) => {
23756
- event.changedTouches[i] = Object.assign(Object.assign({}, event.changedTouches[i]), { offsetX: d.x, offsetY: d.y });
23757
- });
23758
- event.offsetX = event.changedTouches[0].offsetX;
23759
- event.offsetY = event.changedTouches[0].offsetY;
23760
- }
23761
- if (event.touches.length > 0) {
23762
- event.touches.forEach((d, i) => {
23763
- event.touches[i] = Object.assign(Object.assign({}, event.touches[i]), { offsetX: d.x, offsetY: d.y });
23764
- });
23444
+ if (event.changedTouches && event.changedTouches[0]) {
23445
+ event.offsetX = event.changedTouches[0].x;
23446
+ event.changedTouches[0].offsetX = event.changedTouches[0].x;
23447
+ event.changedTouches[0].clientX = event.changedTouches[0].x;
23448
+ event.offsetY = event.changedTouches[0].y;
23449
+ event.changedTouches[0].offsetY = event.changedTouches[0].y;
23450
+ event.changedTouches[0].clientY = event.changedTouches[0].y;
23765
23451
  }
23766
23452
  event.preventDefault = () => {
23767
23453
  return;
@@ -23809,30 +23495,42 @@ class TaroWindowHandlerContribution extends BaseWindowHandlerContribution {
23809
23495
  context.nativeContext.restore();
23810
23496
  }
23811
23497
  }
23812
- TaroWindowHandlerContribution.env = 'taro';
23813
- function bindTaroWindowContribution(container) {
23498
+ TTWindowHandlerContribution.env = 'tt';
23499
+ function bindTTWindowContribution(container) {
23814
23500
  var _a, _b;
23815
- if (!((_a = container.isBound) === null || _a === void 0 ? void 0 : _a.call(container, TaroWindowHandlerContribution))) {
23816
- container.bind(TaroWindowHandlerContribution).toSelf();
23501
+ if (!((_a = container.isBound) === null || _a === void 0 ? void 0 : _a.call(container, TTWindowHandlerContribution))) {
23502
+ container.bind(TTWindowHandlerContribution).toSelf();
23817
23503
  }
23818
- if (!((_b = container.getNamed) === null || _b === void 0 ? void 0 : _b.call(container, WindowHandlerContribution$1, TaroWindowHandlerContribution.env))) {
23504
+ if (!((_b = container.getNamed) === null || _b === void 0 ? void 0 : _b.call(container, WindowHandlerContribution$1, TTWindowHandlerContribution.env))) {
23819
23505
  container
23820
23506
  .bind(WindowHandlerContribution$1)
23821
- .toService(TaroWindowHandlerContribution)
23822
- .whenTargetNamed(TaroWindowHandlerContribution.env);
23507
+ .toService(TTWindowHandlerContribution)
23508
+ .whenTargetNamed(TTWindowHandlerContribution.env);
23823
23509
  }
23824
23510
  }
23825
23511
 
23826
- const TARO_CANVAS_BRIDGE_ERROR = 'Taro canvas bridge is unavailable. VRender taro env requires envParams.canvasFactory, ' +
23827
- 'a Stage canvas object, or envParams.taro.createCanvasContext(id).';
23828
- class TaroEnvContribution extends BaseEnvContribution {
23512
+ const TT_CANVAS_BRIDGE_ERROR = 'TT canvas bridge is unavailable. VRender tt env requires envParams.canvasFactory, ' +
23513
+ 'a Stage canvas object, or a tt runtime that exposes createCanvasContext(id).';
23514
+ function getTTRuntime(params) {
23515
+ var _a, _b, _c;
23516
+ try {
23517
+ 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);
23518
+ }
23519
+ catch (_d) {
23520
+ 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;
23521
+ }
23522
+ }
23523
+ function getTTPixelRatio(params, runtime = getTTRuntime(params)) {
23524
+ var _a, _b, _c, _d;
23525
+ 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;
23526
+ }
23527
+ class TTEnvContribution extends BaseEnvContribution {
23829
23528
  constructor() {
23830
23529
  super();
23831
- this.type = 'taro';
23530
+ this.type = 'tt';
23832
23531
  this.supportEvent = true;
23833
23532
  this.canvasMap = new Map();
23834
- this.pixelRatio = 1;
23835
- this.taroEnvParams = {};
23533
+ this.ttEnvParams = {};
23836
23534
  this.supportsTouchEvents = true;
23837
23535
  try {
23838
23536
  this.supportsPointerEvents = !!globalThis.PointerEvent;
@@ -23844,26 +23542,10 @@ class TaroEnvContribution extends BaseEnvContribution {
23844
23542
  }
23845
23543
  this.applyStyles = true;
23846
23544
  }
23847
- getDynamicCanvasCount() {
23848
- return 0;
23849
- }
23850
- getStaticCanvasCount() {
23851
- return 9999;
23852
- }
23853
- mapToCanvasPoint(event) {
23854
- var _a;
23855
- if ((_a = event === null || event === void 0 ? void 0 : event.type) === null || _a === void 0 ? void 0 : _a.startsWith('mouse')) {
23856
- return event;
23857
- }
23858
- return event;
23859
- }
23860
23545
  configure(service, params = {}) {
23861
- var _a;
23862
23546
  if (service.env === this.type) {
23863
23547
  service.setActiveEnvContribution(this);
23864
- this.taroEnvParams = params;
23865
- this.taro = params.taro;
23866
- this.pixelRatio = (_a = params.pixelRatio) !== null && _a !== void 0 ? _a : 1;
23548
+ this.ttEnvParams = params;
23867
23549
  }
23868
23550
  }
23869
23551
  loadImage(url) {
@@ -23872,41 +23554,23 @@ class TaroEnvContribution extends BaseEnvContribution {
23872
23554
  loadState: 'success'
23873
23555
  });
23874
23556
  }
23875
- loadSvg(svgStr) {
23876
- const _window = typeof window !== 'undefined' ? window : globalThis;
23877
- if (_window.DOMParser) {
23878
- const parser = new _window.DOMParser();
23879
- const svg = parser.parseFromString(svgStr, 'image/svg+xml').children[0];
23880
- const data = new XMLSerializer().serializeToString(svg);
23881
- const url = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(data)}`;
23882
- return Promise.resolve({
23883
- data: url,
23884
- loadState: 'success'
23885
- });
23886
- }
23887
- else if (_window.Blob) {
23888
- const data = new _window.Blob([svgStr], { type: 'image/svg+xml' });
23889
- const url = _window.URL.createObjectURL(data);
23890
- return Promise.resolve({
23891
- data: url,
23892
- loadState: 'success'
23893
- });
23894
- }
23557
+ loadSvg(url) {
23895
23558
  return Promise.reject();
23896
23559
  }
23897
23560
  createCanvas(params) {
23898
- var _a, _b;
23899
- const envParams = this.taroEnvParams;
23900
- const dpr = (_a = params.dpr) !== null && _a !== void 0 ? _a : this.getDevicePixelRatio();
23561
+ var _a;
23562
+ const envParams = this.ttEnvParams;
23563
+ const runtime = getTTRuntime(envParams);
23564
+ const dpr = (_a = params.dpr) !== null && _a !== void 0 ? _a : getTTPixelRatio(envParams, runtime);
23901
23565
  const factoryCanvas = createCanvasWithFactory(params, dpr, this.canvasMap, envParams.canvasFactory);
23902
23566
  if (factoryCanvas) {
23903
23567
  return factoryCanvas;
23904
23568
  }
23905
23569
  const options = getMiniAppCanvasOptions(params, dpr, false);
23906
- if (options.id == null || typeof ((_b = envParams.taro) === null || _b === void 0 ? void 0 : _b.createCanvasContext) !== 'function') {
23907
- throw new Error(TARO_CANVAS_BRIDGE_ERROR);
23570
+ if (options.id == null || typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createCanvasContext) !== 'function') {
23571
+ throw new Error(TT_CANVAS_BRIDGE_ERROR);
23908
23572
  }
23909
- const canvas = wrapMiniAppContextCanvas(envParams.taro.createCanvasContext(options.id), options);
23573
+ const canvas = wrapMiniAppContextCanvas(runtime.createCanvasContext(options.id), options);
23910
23574
  this.canvasMap.set(options.id, canvas);
23911
23575
  return canvas;
23912
23576
  }
@@ -23917,13 +23581,17 @@ class TaroEnvContribution extends BaseEnvContribution {
23917
23581
  return;
23918
23582
  }
23919
23583
  getDevicePixelRatio() {
23920
- return this.pixelRatio;
23584
+ return getTTPixelRatio(this.ttEnvParams);
23921
23585
  }
23922
23586
  getRequestAnimationFrame() {
23923
- return requestAnimationFrame;
23587
+ return function (callback) {
23588
+ return rafBasedSto.call(callback);
23589
+ };
23924
23590
  }
23925
23591
  getCancelAnimationFrame() {
23926
- return cancelAnimationFrame;
23592
+ return (h) => {
23593
+ rafBasedSto.clear(h);
23594
+ };
23927
23595
  }
23928
23596
  addEventListener(type, listener, options) {
23929
23597
  return null;
@@ -23946,27 +23614,34 @@ class TaroEnvContribution extends BaseEnvContribution {
23946
23614
  release(...params) {
23947
23615
  return;
23948
23616
  }
23617
+ mapToCanvasPoint(event) {
23618
+ var _a;
23619
+ if ((_a = event === null || event === void 0 ? void 0 : event.type) === null || _a === void 0 ? void 0 : _a.startsWith('mouse')) {
23620
+ return event;
23621
+ }
23622
+ return event;
23623
+ }
23949
23624
  }
23950
23625
 
23951
- function bindTaroEnv(container) {
23626
+ function bindTTEnv(container) {
23952
23627
  var _a, _b;
23953
- if (!((_b = (_a = container).isBound) === null || _b === void 0 ? void 0 : _b.call(_a, TaroEnvContribution))) {
23954
- container.bind(TaroEnvContribution).toSelf().inSingletonScope();
23955
- container.bind(EnvContribution$1).toService(TaroEnvContribution);
23628
+ if (!((_b = (_a = container).isBound) === null || _b === void 0 ? void 0 : _b.call(_a, TTEnvContribution))) {
23629
+ container.bind(TTEnvContribution).toSelf().inSingletonScope();
23630
+ container.bind(EnvContribution$1).toService(TTEnvContribution);
23956
23631
  }
23957
23632
  }
23958
- function loadTaroEnv(container = getLegacyBindingContext$1(), loadPicker = true) {
23959
- if (!loadTaroEnv.__loaded) {
23960
- loadTaroEnv.__loaded = true;
23961
- bindTaroEnv(container);
23962
- bindTaroCanvasModules(container);
23963
- bindTaroWindowContribution(container);
23633
+ function loadTTEnv(container = getLegacyBindingContext$1(), loadPicker = true) {
23634
+ if (!loadTTEnv.__loaded) {
23635
+ loadTTEnv.__loaded = true;
23636
+ bindTTEnv(container);
23637
+ bindTTCanvasModules(container);
23638
+ bindTTWindowContribution(container);
23964
23639
  loadPicker && loadMathPicker(container);
23965
23640
  }
23966
23641
  }
23967
- loadTaroEnv.__loaded = false;
23968
- function initTaroEnv() {
23969
- loadTaroEnv();
23642
+ loadTTEnv.__loaded = false;
23643
+ function initTTEnv() {
23644
+ loadTTEnv();
23970
23645
  }
23971
23646
 
23972
23647
  let MiniAppEventManager$1 = class MiniAppEventManager {
@@ -23998,14 +23673,28 @@ let MiniAppEventManager$1 = class MiniAppEventManager {
23998
23673
  this.cache = {};
23999
23674
  }
24000
23675
  };
24001
- class TTWindowHandlerContribution extends BaseWindowHandlerContribution {
23676
+ function setMiniAppEventTarget$1(event, key, value) {
23677
+ if (!event || !value) {
23678
+ return;
23679
+ }
23680
+ try {
23681
+ event[key] = value;
23682
+ }
23683
+ catch (_a) {
23684
+ Object.defineProperty(event, key, {
23685
+ configurable: true,
23686
+ value
23687
+ });
23688
+ }
23689
+ }
23690
+ class WxWindowHandlerContribution extends BaseWindowHandlerContribution {
24002
23691
  get container() {
24003
23692
  return null;
24004
23693
  }
24005
23694
  constructor(global = application.global) {
24006
23695
  super();
24007
23696
  this.global = global;
24008
- this.type = 'tt';
23697
+ this.type = 'wx';
24009
23698
  this.eventManager = new MiniAppEventManager$1();
24010
23699
  }
24011
23700
  getTitle() {
@@ -24041,7 +23730,7 @@ class TTWindowHandlerContribution extends BaseWindowHandlerContribution {
24041
23730
  id: Generator.GenAutoIncrementId().toString(),
24042
23731
  canvasControled: false
24043
23732
  };
24044
- this.canvas = new TTCanvas(options);
23733
+ this.canvas = new WxCanvas(options);
24045
23734
  }
24046
23735
  createWindowByCanvas(params) {
24047
23736
  let canvas;
@@ -24073,7 +23762,7 @@ class TTWindowHandlerContribution extends BaseWindowHandlerContribution {
24073
23762
  if (dpr == null) {
24074
23763
  dpr = canvas.width / width;
24075
23764
  }
24076
- this.canvas = new TTCanvas({
23765
+ this.canvas = new WxCanvas({
24077
23766
  width: width,
24078
23767
  height: height,
24079
23768
  dpr: dpr,
@@ -24106,17 +23795,21 @@ class TTWindowHandlerContribution extends BaseWindowHandlerContribution {
24106
23795
  this.eventManager.removeEventListener(type, listener);
24107
23796
  }
24108
23797
  dispatchEvent(event) {
23798
+ var _a, _b, _c, _d, _e;
24109
23799
  const { type } = event;
24110
23800
  if (!this.eventManager.cache[type]) {
24111
23801
  return false;
24112
23802
  }
23803
+ const nativeCanvas = (_a = this.canvas) === null || _a === void 0 ? void 0 : _a.nativeCanvas;
23804
+ setMiniAppEventTarget$1(event, 'target', nativeCanvas);
23805
+ setMiniAppEventTarget$1(event, 'currentTarget', nativeCanvas);
24113
23806
  if (event.changedTouches && event.changedTouches[0]) {
24114
23807
  event.offsetX = event.changedTouches[0].x;
24115
- event.changedTouches[0].offsetX = event.changedTouches[0].x;
24116
- event.changedTouches[0].clientX = event.changedTouches[0].x;
23808
+ event.changedTouches[0].offsetX = (_b = event.changedTouches[0].x) !== null && _b !== void 0 ? _b : event.changedTouches[0].pageX;
23809
+ event.changedTouches[0].clientX = (_c = event.changedTouches[0].x) !== null && _c !== void 0 ? _c : event.changedTouches[0].pageX;
24117
23810
  event.offsetY = event.changedTouches[0].y;
24118
- event.changedTouches[0].offsetY = event.changedTouches[0].y;
24119
- event.changedTouches[0].clientY = event.changedTouches[0].y;
23811
+ event.changedTouches[0].offsetY = (_d = event.changedTouches[0].y) !== null && _d !== void 0 ? _d : event.changedTouches[0].pageY;
23812
+ event.changedTouches[0].clientY = (_e = event.changedTouches[0].y) !== null && _e !== void 0 ? _e : event.changedTouches[0].pageY;
24120
23813
  }
24121
23814
  event.preventDefault = () => {
24122
23815
  return;
@@ -24164,42 +23857,42 @@ class TTWindowHandlerContribution extends BaseWindowHandlerContribution {
24164
23857
  context.nativeContext.restore();
24165
23858
  }
24166
23859
  }
24167
- TTWindowHandlerContribution.env = 'tt';
24168
- function bindTTWindowContribution(container) {
23860
+ WxWindowHandlerContribution.env = 'wx';
23861
+ function bindWxWindowContribution(container) {
24169
23862
  var _a, _b;
24170
- if (!((_a = container.isBound) === null || _a === void 0 ? void 0 : _a.call(container, TTWindowHandlerContribution))) {
24171
- container.bind(TTWindowHandlerContribution).toSelf();
23863
+ if (!((_a = container.isBound) === null || _a === void 0 ? void 0 : _a.call(container, WxWindowHandlerContribution))) {
23864
+ container.bind(WxWindowHandlerContribution).toSelf();
24172
23865
  }
24173
- if (!((_b = container.getNamed) === null || _b === void 0 ? void 0 : _b.call(container, WindowHandlerContribution$1, TTWindowHandlerContribution.env))) {
23866
+ if (!((_b = container.getNamed) === null || _b === void 0 ? void 0 : _b.call(container, WindowHandlerContribution$1, WxWindowHandlerContribution.env))) {
24174
23867
  container
24175
23868
  .bind(WindowHandlerContribution$1)
24176
- .toService(TTWindowHandlerContribution)
24177
- .whenTargetNamed(TTWindowHandlerContribution.env);
23869
+ .toService(WxWindowHandlerContribution)
23870
+ .whenTargetNamed(WxWindowHandlerContribution.env);
24178
23871
  }
24179
23872
  }
24180
23873
 
24181
- const TT_CANVAS_BRIDGE_ERROR = 'TT canvas bridge is unavailable. VRender tt env requires envParams.canvasFactory, ' +
24182
- 'a Stage canvas object, or a tt runtime that exposes createCanvasContext(id).';
24183
- function getTTRuntime(params) {
23874
+ const WX_CANVAS_BRIDGE_ERROR = 'Wx canvas bridge is unavailable. VRender wx env requires envParams.canvasFactory, ' +
23875
+ 'a Stage canvas object, or a wx runtime that exposes createCanvasContext(id).';
23876
+ function getWxRuntime(params) {
24184
23877
  var _a, _b, _c;
24185
23878
  try {
24186
- 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);
23879
+ 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);
24187
23880
  }
24188
23881
  catch (_d) {
24189
- 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;
23882
+ 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;
24190
23883
  }
24191
23884
  }
24192
- function getTTPixelRatio(params, runtime = getTTRuntime(params)) {
23885
+ function getWxPixelRatio(params, runtime = getWxRuntime(params)) {
24193
23886
  var _a, _b, _c, _d;
24194
23887
  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;
24195
23888
  }
24196
- class TTEnvContribution extends BaseEnvContribution {
23889
+ class WxEnvContribution extends BaseEnvContribution {
24197
23890
  constructor() {
24198
23891
  super();
24199
- this.type = 'tt';
23892
+ this.type = 'wx';
24200
23893
  this.supportEvent = true;
24201
23894
  this.canvasMap = new Map();
24202
- this.ttEnvParams = {};
23895
+ this.wxEnvParams = {};
24203
23896
  this.supportsTouchEvents = true;
24204
23897
  try {
24205
23898
  this.supportsPointerEvents = !!globalThis.PointerEvent;
@@ -24214,7 +23907,7 @@ class TTEnvContribution extends BaseEnvContribution {
24214
23907
  configure(service, params = {}) {
24215
23908
  if (service.env === this.type) {
24216
23909
  service.setActiveEnvContribution(this);
24217
- this.ttEnvParams = params;
23910
+ this.wxEnvParams = params;
24218
23911
  }
24219
23912
  }
24220
23913
  loadImage(url) {
@@ -24224,20 +23917,23 @@ class TTEnvContribution extends BaseEnvContribution {
24224
23917
  });
24225
23918
  }
24226
23919
  loadSvg(url) {
24227
- return Promise.reject();
23920
+ return Promise.resolve({
23921
+ data: null,
23922
+ loadState: 'fail'
23923
+ });
24228
23924
  }
24229
23925
  createCanvas(params) {
24230
23926
  var _a;
24231
- const envParams = this.ttEnvParams;
24232
- const runtime = getTTRuntime(envParams);
24233
- const dpr = (_a = params.dpr) !== null && _a !== void 0 ? _a : getTTPixelRatio(envParams, runtime);
23927
+ const envParams = this.wxEnvParams;
23928
+ const runtime = getWxRuntime(envParams);
23929
+ const dpr = (_a = params.dpr) !== null && _a !== void 0 ? _a : getWxPixelRatio(envParams, runtime);
24234
23930
  const factoryCanvas = createCanvasWithFactory(params, dpr, this.canvasMap, envParams.canvasFactory);
24235
23931
  if (factoryCanvas) {
24236
23932
  return factoryCanvas;
24237
23933
  }
24238
23934
  const options = getMiniAppCanvasOptions(params, dpr, false);
24239
23935
  if (options.id == null || typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createCanvasContext) !== 'function') {
24240
- throw new Error(TT_CANVAS_BRIDGE_ERROR);
23936
+ throw new Error(WX_CANVAS_BRIDGE_ERROR);
24241
23937
  }
24242
23938
  const canvas = wrapMiniAppContextCanvas(runtime.createCanvasContext(options.id), options);
24243
23939
  this.canvasMap.set(options.id, canvas);
@@ -24250,7 +23946,7 @@ class TTEnvContribution extends BaseEnvContribution {
24250
23946
  return;
24251
23947
  }
24252
23948
  getDevicePixelRatio() {
24253
- return getTTPixelRatio(this.ttEnvParams);
23949
+ return getWxPixelRatio(this.wxEnvParams);
24254
23950
  }
24255
23951
  getRequestAnimationFrame() {
24256
23952
  return function (callback) {
@@ -24292,1199 +23988,1521 @@ class TTEnvContribution extends BaseEnvContribution {
24292
23988
  }
24293
23989
  }
24294
23990
 
24295
- function bindTTEnv(container) {
23991
+ function bindWxEnv(container) {
24296
23992
  var _a, _b;
24297
- if (!((_b = (_a = container).isBound) === null || _b === void 0 ? void 0 : _b.call(_a, TTEnvContribution))) {
24298
- container.bind(TTEnvContribution).toSelf().inSingletonScope();
24299
- container.bind(EnvContribution$1).toService(TTEnvContribution);
23993
+ if (!((_b = (_a = container).isBound) === null || _b === void 0 ? void 0 : _b.call(_a, WxEnvContribution))) {
23994
+ container.bind(WxEnvContribution).toSelf().inSingletonScope();
23995
+ container.bind(EnvContribution$1).toService(WxEnvContribution);
24300
23996
  }
24301
23997
  }
24302
- function loadTTEnv(container = getLegacyBindingContext$1(), loadPicker = true) {
24303
- if (!loadTTEnv.__loaded) {
24304
- loadTTEnv.__loaded = true;
24305
- bindTTEnv(container);
24306
- bindTTCanvasModules(container);
24307
- bindTTWindowContribution(container);
23998
+ function loadWxEnv(container = getLegacyBindingContext$1(), loadPicker = true) {
23999
+ if (!loadWxEnv.__loaded) {
24000
+ loadWxEnv.__loaded = true;
24001
+ bindWxEnv(container);
24002
+ bindWxCanvasModules(container);
24003
+ bindWxWindowContribution(container);
24308
24004
  loadPicker && loadMathPicker(container);
24309
24005
  }
24310
24006
  }
24311
- loadTTEnv.__loaded = false;
24312
- function initTTEnv() {
24313
- loadTTEnv();
24007
+ loadWxEnv.__loaded = false;
24008
+ function initWxEnv() {
24009
+ loadWxEnv();
24314
24010
  }
24315
24011
 
24316
- class MiniAppEventManager {
24317
- constructor() {
24318
- this.cache = {};
24319
- }
24320
- addEventListener(type, func) {
24321
- if (!type || !func) {
24322
- return;
24323
- }
24324
- this.cache[type] = this.cache[type] || {
24325
- listener: []
24326
- };
24327
- this.cache[type].listener.push(func);
24328
- }
24329
- removeEventListener(type, func) {
24330
- if (!type || !func) {
24331
- return;
24332
- }
24333
- if (!this.cache[type]) {
24334
- return;
24335
- }
24336
- const index = this.cache[type].listener.findIndex((f) => f === func);
24337
- if (index >= 0) {
24338
- this.cache[type].listener.splice(index, 1);
24339
- }
24340
- }
24341
- cleanEvent() {
24342
- this.cache = {};
24343
- }
24344
- }
24345
- function setMiniAppEventTarget(event, key, value) {
24346
- if (!event || !value) {
24347
- return;
24348
- }
24349
- try {
24350
- event[key] = value;
24351
- }
24352
- catch (_a) {
24353
- Object.defineProperty(event, key, {
24354
- configurable: true,
24355
- value
24356
- });
24357
- }
24012
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
24013
+
24014
+ function getDefaultExportFromCjs (x) {
24015
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
24358
24016
  }
24359
- class WxWindowHandlerContribution extends BaseWindowHandlerContribution {
24360
- get container() {
24361
- return null;
24362
- }
24363
- constructor(global = application.global) {
24364
- super();
24365
- this.global = global;
24366
- this.type = 'wx';
24367
- this.eventManager = new MiniAppEventManager();
24368
- }
24369
- getTitle() {
24370
- return this.canvas.id.toString();
24371
- }
24372
- getWH() {
24373
- return {
24374
- width: this.canvas.width / (this.canvas.dpr || 1),
24375
- height: this.canvas.height / (this.canvas.dpr || 1)
24376
- };
24017
+
24018
+ var lib$1 = {};
24019
+
24020
+ var gif = {};
24021
+
24022
+ var lib = {};
24023
+
24024
+ Object.defineProperty(lib, "__esModule", {
24025
+ value: true
24026
+ });
24027
+ lib.loop = lib.conditional = lib.parse = void 0;
24028
+ var parse = function parse(stream, schema) {
24029
+ var result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
24030
+ var parent = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : result;
24031
+ if (Array.isArray(schema)) {
24032
+ schema.forEach(function (partSchema) {
24033
+ return parse(stream, partSchema, result, parent);
24034
+ });
24035
+ } else if (typeof schema === 'function') {
24036
+ schema(stream, result, parent, parse);
24037
+ } else {
24038
+ var key = Object.keys(schema)[0];
24039
+ if (Array.isArray(schema[key])) {
24040
+ parent[key] = {};
24041
+ parse(stream, schema[key], result, parent[key]);
24042
+ } else {
24043
+ parent[key] = schema[key](stream, result, parent, parse);
24377
24044
  }
24378
- getXY() {
24379
- return { x: 0, y: 0 };
24045
+ }
24046
+ return result;
24047
+ };
24048
+ lib.parse = parse;
24049
+ var conditional = function conditional(schema, conditionFunc) {
24050
+ return function (stream, result, parent, parse) {
24051
+ if (conditionFunc(stream, result, parent)) {
24052
+ parse(stream, schema, result, parent);
24380
24053
  }
24381
- createWindow(params) {
24382
- if (!params.canvas) {
24383
- this.createWindowByConfig(params);
24384
- }
24385
- else {
24386
- this.createWindowByCanvas(params);
24387
- }
24054
+ };
24055
+ };
24056
+ lib.conditional = conditional;
24057
+ var loop = function loop(schema, continueFunc) {
24058
+ return function (stream, result, parent, parse) {
24059
+ var arr = [];
24060
+ var lastStreamPos = stream.pos;
24061
+ while (continueFunc(stream, result, parent)) {
24062
+ var newParent = {};
24063
+ parse(stream, schema, result, newParent); // cases when whole file is parsed but no termination is there and stream position is not getting updated as well
24064
+ // it falls into infinite recursion, null check to avoid the same
24065
+
24066
+ if (stream.pos === lastStreamPos) {
24067
+ break;
24068
+ }
24069
+ lastStreamPos = stream.pos;
24070
+ arr.push(newParent);
24388
24071
  }
24389
- createWindowByConfig(params) {
24390
- const nativeCanvas = this.global.createCanvas({
24391
- width: params.width,
24392
- height: params.height
24393
- });
24394
- const options = {
24395
- width: params.width,
24396
- height: params.height,
24397
- dpr: params.dpr,
24398
- nativeCanvas,
24399
- id: Generator.GenAutoIncrementId().toString(),
24400
- canvasControled: false
24401
- };
24402
- this.canvas = new WxCanvas(options);
24072
+ return arr;
24073
+ };
24074
+ };
24075
+ lib.loop = loop;
24076
+
24077
+ var uint8 = {};
24078
+
24079
+ Object.defineProperty(uint8, "__esModule", {
24080
+ value: true
24081
+ });
24082
+ uint8.readBits = uint8.readArray = uint8.readUnsigned = uint8.readString = uint8.peekBytes = uint8.readBytes = uint8.peekByte = uint8.readByte = uint8.buildStream = void 0;
24083
+
24084
+ // Default stream and parsers for Uint8TypedArray data type
24085
+ var buildStream = function buildStream(uint8Data) {
24086
+ return {
24087
+ data: uint8Data,
24088
+ pos: 0
24089
+ };
24090
+ };
24091
+ uint8.buildStream = buildStream;
24092
+ var readByte = function readByte() {
24093
+ return function (stream) {
24094
+ return stream.data[stream.pos++];
24095
+ };
24096
+ };
24097
+ uint8.readByte = readByte;
24098
+ var peekByte = function peekByte() {
24099
+ var offset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
24100
+ return function (stream) {
24101
+ return stream.data[stream.pos + offset];
24102
+ };
24103
+ };
24104
+ uint8.peekByte = peekByte;
24105
+ var readBytes = function readBytes(length) {
24106
+ return function (stream) {
24107
+ return stream.data.subarray(stream.pos, stream.pos += length);
24108
+ };
24109
+ };
24110
+ uint8.readBytes = readBytes;
24111
+ var peekBytes = function peekBytes(length) {
24112
+ return function (stream) {
24113
+ return stream.data.subarray(stream.pos, stream.pos + length);
24114
+ };
24115
+ };
24116
+ uint8.peekBytes = peekBytes;
24117
+ var readString = function readString(length) {
24118
+ return function (stream) {
24119
+ return Array.from(readBytes(length)(stream)).map(function (value) {
24120
+ return String.fromCharCode(value);
24121
+ }).join('');
24122
+ };
24123
+ };
24124
+ uint8.readString = readString;
24125
+ var readUnsigned = function readUnsigned(littleEndian) {
24126
+ return function (stream) {
24127
+ var bytes = readBytes(2)(stream);
24128
+ return littleEndian ? (bytes[1] << 8) + bytes[0] : (bytes[0] << 8) + bytes[1];
24129
+ };
24130
+ };
24131
+ uint8.readUnsigned = readUnsigned;
24132
+ var readArray = function readArray(byteSize, totalOrFunc) {
24133
+ return function (stream, result, parent) {
24134
+ var total = typeof totalOrFunc === 'function' ? totalOrFunc(stream, result, parent) : totalOrFunc;
24135
+ var parser = readBytes(byteSize);
24136
+ var arr = new Array(total);
24137
+ for (var i = 0; i < total; i++) {
24138
+ arr[i] = parser(stream);
24403
24139
  }
24404
- createWindowByCanvas(params) {
24405
- let canvas;
24406
- if (typeof params.canvas === 'string') {
24407
- canvas = this.global.getElementById(params.canvas);
24408
- if (!canvas) {
24409
- canvas = this.global.createCanvas({
24410
- id: params.canvas,
24411
- width: params.width,
24412
- height: params.height,
24413
- dpr: params.dpr
24414
- });
24415
- }
24416
- if (!canvas) {
24417
- throw new Error('canvasId 参数不正确,请确认canvas存在并插入dom');
24418
- }
24419
- }
24420
- else {
24421
- canvas = params.canvas;
24422
- }
24423
- let width = params.width;
24424
- let height = params.height;
24425
- if (width == null || height == null || !params.canvasControled) {
24426
- const data = canvas.getBoundingClientRect();
24427
- width = data.width;
24428
- height = data.height;
24429
- }
24430
- let dpr = params.dpr;
24431
- if (dpr == null) {
24432
- dpr = canvas.width / width;
24433
- }
24434
- this.canvas = new WxCanvas({
24435
- width: width,
24436
- height: height,
24437
- dpr: dpr,
24438
- nativeCanvas: canvas,
24439
- canvasControled: params.canvasControled
24440
- });
24441
- }
24442
- releaseWindow() {
24443
- return;
24444
- }
24445
- resizeWindow(width, height) {
24446
- return;
24447
- }
24448
- setDpr(dpr) {
24449
- this.canvas.dpr = dpr;
24450
- }
24451
- getContext() {
24452
- return this.canvas.getContext();
24453
- }
24454
- getNativeHandler() {
24455
- return this.canvas;
24456
- }
24457
- getDpr() {
24458
- return this.canvas.dpr;
24459
- }
24460
- addEventListener(type, listener) {
24461
- this.eventManager.addEventListener(type, listener);
24462
- }
24463
- removeEventListener(type, listener) {
24464
- this.eventManager.removeEventListener(type, listener);
24465
- }
24466
- dispatchEvent(event) {
24467
- var _a, _b, _c, _d, _e;
24468
- const { type } = event;
24469
- if (!this.eventManager.cache[type]) {
24470
- return false;
24471
- }
24472
- const nativeCanvas = (_a = this.canvas) === null || _a === void 0 ? void 0 : _a.nativeCanvas;
24473
- setMiniAppEventTarget(event, 'target', nativeCanvas);
24474
- setMiniAppEventTarget(event, 'currentTarget', nativeCanvas);
24475
- if (event.changedTouches && event.changedTouches[0]) {
24476
- event.offsetX = event.changedTouches[0].x;
24477
- event.changedTouches[0].offsetX = (_b = event.changedTouches[0].x) !== null && _b !== void 0 ? _b : event.changedTouches[0].pageX;
24478
- event.changedTouches[0].clientX = (_c = event.changedTouches[0].x) !== null && _c !== void 0 ? _c : event.changedTouches[0].pageX;
24479
- event.offsetY = event.changedTouches[0].y;
24480
- event.changedTouches[0].offsetY = (_d = event.changedTouches[0].y) !== null && _d !== void 0 ? _d : event.changedTouches[0].pageY;
24481
- event.changedTouches[0].clientY = (_e = event.changedTouches[0].y) !== null && _e !== void 0 ? _e : event.changedTouches[0].pageY;
24482
- }
24483
- event.preventDefault = () => {
24484
- return;
24485
- };
24486
- event.stopPropagation = () => {
24487
- return;
24488
- };
24489
- if (this.eventManager.cache[type].listener) {
24490
- this.eventManager.cache[type].listener.forEach((f) => {
24491
- f(event);
24492
- });
24493
- }
24494
- return true;
24495
- }
24496
- getStyle() {
24497
- return {};
24498
- }
24499
- setStyle(style) {
24500
- return;
24501
- }
24502
- getBoundingClientRect() {
24503
- const wh = this.getWH();
24504
- return {
24505
- x: 0,
24506
- y: 0,
24507
- width: wh.width,
24508
- height: wh.height,
24509
- left: 0,
24510
- top: 0,
24511
- right: 0,
24512
- bottom: 0
24513
- };
24514
- }
24515
- clearViewBox(color) {
24516
- const vb = this.viewBox;
24517
- const context = this.getContext();
24518
- const dpr = this.getDpr();
24519
- context.nativeContext.save();
24520
- context.nativeContext.setTransform(dpr, 0, 0, dpr, 0, 0);
24521
- context.clearRect(vb.x1, vb.y1, vb.x2 - vb.x1, vb.y2 - vb.y1);
24522
- if (color) {
24523
- context.fillStyle = color;
24524
- context.fillRect(vb.x1, vb.y1, vb.x2 - vb.x1, vb.y2 - vb.y1);
24525
- }
24526
- context.nativeContext.restore();
24527
- }
24528
- }
24529
- WxWindowHandlerContribution.env = 'wx';
24530
- function bindWxWindowContribution(container) {
24531
- var _a, _b;
24532
- if (!((_a = container.isBound) === null || _a === void 0 ? void 0 : _a.call(container, WxWindowHandlerContribution))) {
24533
- container.bind(WxWindowHandlerContribution).toSelf();
24534
- }
24535
- if (!((_b = container.getNamed) === null || _b === void 0 ? void 0 : _b.call(container, WindowHandlerContribution$1, WxWindowHandlerContribution.env))) {
24536
- container
24537
- .bind(WindowHandlerContribution$1)
24538
- .toService(WxWindowHandlerContribution)
24539
- .whenTargetNamed(WxWindowHandlerContribution.env);
24540
- }
24541
- }
24140
+ return arr;
24141
+ };
24142
+ };
24143
+ uint8.readArray = readArray;
24144
+ var subBitsTotal = function subBitsTotal(bits, startIndex, length) {
24145
+ var result = 0;
24146
+ for (var i = 0; i < length; i++) {
24147
+ result += bits[startIndex + i] && Math.pow(2, length - i - 1);
24148
+ }
24149
+ return result;
24150
+ };
24151
+ var readBits = function readBits(schema) {
24152
+ return function (stream) {
24153
+ var _byte = readByte()(stream); // convert the byte to bit array
24542
24154
 
24543
- const WX_CANVAS_BRIDGE_ERROR = 'Wx canvas bridge is unavailable. VRender wx env requires envParams.canvasFactory, ' +
24544
- 'a Stage canvas object, or a wx runtime that exposes createCanvasContext(id).';
24545
- function getWxRuntime(params) {
24546
- var _a, _b, _c;
24547
- try {
24548
- 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);
24549
- }
24550
- catch (_d) {
24551
- 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;
24552
- }
24553
- }
24554
- function getWxPixelRatio(params, runtime = getWxRuntime(params)) {
24555
- var _a, _b, _c, _d;
24556
- 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;
24557
- }
24558
- class WxEnvContribution extends BaseEnvContribution {
24559
- constructor() {
24560
- super();
24561
- this.type = 'wx';
24562
- this.supportEvent = true;
24563
- this.canvasMap = new Map();
24564
- this.wxEnvParams = {};
24565
- this.supportsTouchEvents = true;
24566
- try {
24567
- this.supportsPointerEvents = !!globalThis.PointerEvent;
24568
- this.supportsMouseEvents = !!globalThis.MouseEvent;
24569
- }
24570
- catch (err) {
24571
- this.supportsPointerEvents = false;
24572
- this.supportsMouseEvents = false;
24155
+ var bits = new Array(8);
24156
+ for (var i = 0; i < 8; i++) {
24157
+ bits[7 - i] = !!(_byte & 1 << i);
24158
+ } // convert the bit array to values based on the schema
24159
+
24160
+ return Object.keys(schema).reduce(function (res, key) {
24161
+ var def = schema[key];
24162
+ if (def.length) {
24163
+ res[key] = subBitsTotal(bits, def.index, def.length);
24164
+ } else {
24165
+ res[key] = bits[def.index];
24166
+ }
24167
+ return res;
24168
+ }, {});
24169
+ };
24170
+ };
24171
+ uint8.readBits = readBits;
24172
+
24173
+ (function (exports) {
24174
+
24175
+ Object.defineProperty(exports, "__esModule", {
24176
+ value: true
24177
+ });
24178
+ exports["default"] = void 0;
24179
+ var _ = lib;
24180
+ var _uint = uint8;
24181
+
24182
+ // a set of 0x00 terminated subblocks
24183
+ var subBlocksSchema = {
24184
+ blocks: function blocks(stream) {
24185
+ var terminator = 0x00;
24186
+ var chunks = [];
24187
+ var streamSize = stream.data.length;
24188
+ var total = 0;
24189
+ for (var size = (0, _uint.readByte)()(stream); size !== terminator; size = (0, _uint.readByte)()(stream)) {
24190
+ // size becomes undefined for some case when file is corrupted and terminator is not proper
24191
+ // null check to avoid recursion
24192
+ if (!size) break; // catch corrupted files with no terminator
24193
+
24194
+ if (stream.pos + size >= streamSize) {
24195
+ var availableSize = streamSize - stream.pos;
24196
+ chunks.push((0, _uint.readBytes)(availableSize)(stream));
24197
+ total += availableSize;
24198
+ break;
24573
24199
  }
24574
- this.applyStyles = true;
24200
+ chunks.push((0, _uint.readBytes)(size)(stream));
24201
+ total += size;
24202
+ }
24203
+ var result = new Uint8Array(total);
24204
+ var offset = 0;
24205
+ for (var i = 0; i < chunks.length; i++) {
24206
+ result.set(chunks[i], offset);
24207
+ offset += chunks[i].length;
24208
+ }
24209
+ return result;
24575
24210
  }
24576
- configure(service, params = {}) {
24577
- if (service.env === this.type) {
24578
- service.setActiveEnvContribution(this);
24579
- this.wxEnvParams = params;
24211
+ }; // global control extension
24212
+
24213
+ var gceSchema = (0, _.conditional)({
24214
+ gce: [{
24215
+ codes: (0, _uint.readBytes)(2)
24216
+ }, {
24217
+ byteSize: (0, _uint.readByte)()
24218
+ }, {
24219
+ extras: (0, _uint.readBits)({
24220
+ future: {
24221
+ index: 0,
24222
+ length: 3
24223
+ },
24224
+ disposal: {
24225
+ index: 3,
24226
+ length: 3
24227
+ },
24228
+ userInput: {
24229
+ index: 6
24230
+ },
24231
+ transparentColorGiven: {
24232
+ index: 7
24580
24233
  }
24581
- }
24582
- loadImage(url) {
24583
- return Promise.resolve({
24584
- data: url,
24585
- loadState: 'success'
24586
- });
24587
- }
24588
- loadSvg(url) {
24589
- return Promise.resolve({
24590
- data: null,
24591
- loadState: 'fail'
24592
- });
24593
- }
24594
- createCanvas(params) {
24595
- var _a;
24596
- const envParams = this.wxEnvParams;
24597
- const runtime = getWxRuntime(envParams);
24598
- const dpr = (_a = params.dpr) !== null && _a !== void 0 ? _a : getWxPixelRatio(envParams, runtime);
24599
- const factoryCanvas = createCanvasWithFactory(params, dpr, this.canvasMap, envParams.canvasFactory);
24600
- if (factoryCanvas) {
24601
- return factoryCanvas;
24602
- }
24603
- const options = getMiniAppCanvasOptions(params, dpr, false);
24604
- if (options.id == null || typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createCanvasContext) !== 'function') {
24605
- throw new Error(WX_CANVAS_BRIDGE_ERROR);
24606
- }
24607
- const canvas = wrapMiniAppContextCanvas(runtime.createCanvasContext(options.id), options);
24608
- this.canvasMap.set(options.id, canvas);
24609
- return canvas;
24610
- }
24611
- createOffscreenCanvas(params) {
24612
- return;
24613
- }
24614
- releaseCanvas(canvas) {
24615
- return;
24616
- }
24617
- getDevicePixelRatio() {
24618
- return getWxPixelRatio(this.wxEnvParams);
24619
- }
24620
- getRequestAnimationFrame() {
24621
- return function (callback) {
24622
- return rafBasedSto.call(callback);
24623
- };
24624
- }
24625
- getCancelAnimationFrame() {
24626
- return (h) => {
24627
- rafBasedSto.clear(h);
24628
- };
24629
- }
24630
- addEventListener(type, listener, options) {
24631
- return null;
24632
- }
24633
- removeEventListener(type, listener, options) {
24634
- return null;
24635
- }
24636
- dispatchEvent(event) {
24637
- return null;
24638
- }
24639
- getElementById(str) {
24640
- return this.canvasMap.get(str);
24641
- }
24642
- getRootElement() {
24643
- return null;
24644
- }
24645
- getDocument() {
24646
- return null;
24647
- }
24648
- release(...params) {
24649
- return;
24650
- }
24651
- mapToCanvasPoint(event) {
24652
- var _a;
24653
- if ((_a = event === null || event === void 0 ? void 0 : event.type) === null || _a === void 0 ? void 0 : _a.startsWith('mouse')) {
24654
- return event;
24655
- }
24656
- return event;
24657
- }
24658
- }
24234
+ })
24235
+ }, {
24236
+ delay: (0, _uint.readUnsigned)(true)
24237
+ }, {
24238
+ transparentColorIndex: (0, _uint.readByte)()
24239
+ }, {
24240
+ terminator: (0, _uint.readByte)()
24241
+ }]
24242
+ }, function (stream) {
24243
+ var codes = (0, _uint.peekBytes)(2)(stream);
24244
+ return codes[0] === 0x21 && codes[1] === 0xf9;
24245
+ }); // image pipeline block
24659
24246
 
24660
- function bindWxEnv(container) {
24661
- var _a, _b;
24662
- if (!((_b = (_a = container).isBound) === null || _b === void 0 ? void 0 : _b.call(_a, WxEnvContribution))) {
24663
- container.bind(WxEnvContribution).toSelf().inSingletonScope();
24664
- container.bind(EnvContribution$1).toService(WxEnvContribution);
24665
- }
24666
- }
24667
- function loadWxEnv(container = getLegacyBindingContext$1(), loadPicker = true) {
24668
- if (!loadWxEnv.__loaded) {
24669
- loadWxEnv.__loaded = true;
24670
- bindWxEnv(container);
24671
- bindWxCanvasModules(container);
24672
- bindWxWindowContribution(container);
24673
- loadPicker && loadMathPicker(container);
24674
- }
24675
- }
24676
- loadWxEnv.__loaded = false;
24677
- function initWxEnv() {
24678
- loadWxEnv();
24679
- }
24247
+ var imageSchema = (0, _.conditional)({
24248
+ image: [{
24249
+ code: (0, _uint.readByte)()
24250
+ }, {
24251
+ descriptor: [{
24252
+ left: (0, _uint.readUnsigned)(true)
24253
+ }, {
24254
+ top: (0, _uint.readUnsigned)(true)
24255
+ }, {
24256
+ width: (0, _uint.readUnsigned)(true)
24257
+ }, {
24258
+ height: (0, _uint.readUnsigned)(true)
24259
+ }, {
24260
+ lct: (0, _uint.readBits)({
24261
+ exists: {
24262
+ index: 0
24263
+ },
24264
+ interlaced: {
24265
+ index: 1
24266
+ },
24267
+ sort: {
24268
+ index: 2
24269
+ },
24270
+ future: {
24271
+ index: 3,
24272
+ length: 2
24273
+ },
24274
+ size: {
24275
+ index: 5,
24276
+ length: 3
24277
+ }
24278
+ })
24279
+ }]
24280
+ }, (0, _.conditional)({
24281
+ lct: (0, _uint.readArray)(3, function (stream, result, parent) {
24282
+ return Math.pow(2, parent.descriptor.lct.size + 1);
24283
+ })
24284
+ }, function (stream, result, parent) {
24285
+ return parent.descriptor.lct.exists;
24286
+ }), {
24287
+ data: [{
24288
+ minCodeSize: (0, _uint.readByte)()
24289
+ }, subBlocksSchema]
24290
+ }]
24291
+ }, function (stream) {
24292
+ return (0, _uint.peekByte)()(stream) === 0x2c;
24293
+ }); // plain text block
24680
24294
 
24681
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
24295
+ var textSchema = (0, _.conditional)({
24296
+ text: [{
24297
+ codes: (0, _uint.readBytes)(2)
24298
+ }, {
24299
+ blockSize: (0, _uint.readByte)()
24300
+ }, {
24301
+ preData: function preData(stream, result, parent) {
24302
+ return (0, _uint.readBytes)(parent.text.blockSize)(stream);
24303
+ }
24304
+ }, subBlocksSchema]
24305
+ }, function (stream) {
24306
+ var codes = (0, _uint.peekBytes)(2)(stream);
24307
+ return codes[0] === 0x21 && codes[1] === 0x01;
24308
+ }); // application block
24682
24309
 
24683
- function getDefaultExportFromCjs (x) {
24684
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
24685
- }
24310
+ var applicationSchema = (0, _.conditional)({
24311
+ application: [{
24312
+ codes: (0, _uint.readBytes)(2)
24313
+ }, {
24314
+ blockSize: (0, _uint.readByte)()
24315
+ }, {
24316
+ id: function id(stream, result, parent) {
24317
+ return (0, _uint.readString)(parent.blockSize)(stream);
24318
+ }
24319
+ }, subBlocksSchema]
24320
+ }, function (stream) {
24321
+ var codes = (0, _uint.peekBytes)(2)(stream);
24322
+ return codes[0] === 0x21 && codes[1] === 0xff;
24323
+ }); // comment block
24686
24324
 
24687
- var lib$1 = {};
24325
+ var commentSchema = (0, _.conditional)({
24326
+ comment: [{
24327
+ codes: (0, _uint.readBytes)(2)
24328
+ }, subBlocksSchema]
24329
+ }, function (stream) {
24330
+ var codes = (0, _uint.peekBytes)(2)(stream);
24331
+ return codes[0] === 0x21 && codes[1] === 0xfe;
24332
+ });
24333
+ var schema = [{
24334
+ header: [{
24335
+ signature: (0, _uint.readString)(3)
24336
+ }, {
24337
+ version: (0, _uint.readString)(3)
24338
+ }]
24339
+ }, {
24340
+ lsd: [{
24341
+ width: (0, _uint.readUnsigned)(true)
24342
+ }, {
24343
+ height: (0, _uint.readUnsigned)(true)
24344
+ }, {
24345
+ gct: (0, _uint.readBits)({
24346
+ exists: {
24347
+ index: 0
24348
+ },
24349
+ resolution: {
24350
+ index: 1,
24351
+ length: 3
24352
+ },
24353
+ sort: {
24354
+ index: 4
24355
+ },
24356
+ size: {
24357
+ index: 5,
24358
+ length: 3
24359
+ }
24360
+ })
24361
+ }, {
24362
+ backgroundColorIndex: (0, _uint.readByte)()
24363
+ }, {
24364
+ pixelAspectRatio: (0, _uint.readByte)()
24365
+ }]
24366
+ }, (0, _.conditional)({
24367
+ gct: (0, _uint.readArray)(3, function (stream, result) {
24368
+ return Math.pow(2, result.lsd.gct.size + 1);
24369
+ })
24370
+ }, function (stream, result) {
24371
+ return result.lsd.gct.exists;
24372
+ }),
24373
+ // content frames
24374
+ {
24375
+ frames: (0, _.loop)([gceSchema, applicationSchema, commentSchema, imageSchema, textSchema], function (stream) {
24376
+ var nextCode = (0, _uint.peekByte)()(stream); // rather than check for a terminator, we should check for the existence
24377
+ // of an ext or image block to avoid infinite loops
24378
+ //var terminator = 0x3B;
24379
+ //return nextCode !== terminator;
24688
24380
 
24689
- var gif = {};
24381
+ return nextCode === 0x21 || nextCode === 0x2c;
24382
+ })
24383
+ }];
24384
+ var _default = schema;
24385
+ exports["default"] = _default;
24386
+ })(gif);
24690
24387
 
24691
- var lib = {};
24388
+ var deinterlace$1 = {};
24692
24389
 
24693
- Object.defineProperty(lib, "__esModule", {
24390
+ Object.defineProperty(deinterlace$1, "__esModule", {
24694
24391
  value: true
24695
24392
  });
24696
- lib.loop = lib.conditional = lib.parse = void 0;
24697
- var parse = function parse(stream, schema) {
24698
- var result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
24699
- var parent = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : result;
24700
- if (Array.isArray(schema)) {
24701
- schema.forEach(function (partSchema) {
24702
- return parse(stream, partSchema, result, parent);
24703
- });
24704
- } else if (typeof schema === 'function') {
24705
- schema(stream, result, parent, parse);
24706
- } else {
24707
- var key = Object.keys(schema)[0];
24708
- if (Array.isArray(schema[key])) {
24709
- parent[key] = {};
24710
- parse(stream, schema[key], result, parent[key]);
24711
- } else {
24712
- parent[key] = schema[key](stream, result, parent, parse);
24713
- }
24714
- }
24715
- return result;
24716
- };
24717
- lib.parse = parse;
24718
- var conditional = function conditional(schema, conditionFunc) {
24719
- return function (stream, result, parent, parse) {
24720
- if (conditionFunc(stream, result, parent)) {
24721
- parse(stream, schema, result, parent);
24722
- }
24723
- };
24724
- };
24725
- lib.conditional = conditional;
24726
- var loop = function loop(schema, continueFunc) {
24727
- return function (stream, result, parent, parse) {
24728
- var arr = [];
24729
- var lastStreamPos = stream.pos;
24730
- while (continueFunc(stream, result, parent)) {
24731
- var newParent = {};
24732
- parse(stream, schema, result, newParent); // cases when whole file is parsed but no termination is there and stream position is not getting updated as well
24733
- // it falls into infinite recursion, null check to avoid the same
24393
+ deinterlace$1.deinterlace = void 0;
24734
24394
 
24735
- if (stream.pos === lastStreamPos) {
24736
- break;
24737
- }
24738
- lastStreamPos = stream.pos;
24739
- arr.push(newParent);
24395
+ /**
24396
+ * Deinterlace function from https://github.com/shachaf/jsgif
24397
+ */
24398
+ var deinterlace = function deinterlace(pixels, width) {
24399
+ var newPixels = new Array(pixels.length);
24400
+ var rows = pixels.length / width;
24401
+ var cpRow = function cpRow(toRow, fromRow) {
24402
+ var fromPixels = pixels.slice(fromRow * width, (fromRow + 1) * width);
24403
+ newPixels.splice.apply(newPixels, [toRow * width, width].concat(fromPixels));
24404
+ }; // See appendix E.
24405
+
24406
+ var offsets = [0, 4, 2, 1];
24407
+ var steps = [8, 8, 4, 2];
24408
+ var fromRow = 0;
24409
+ for (var pass = 0; pass < 4; pass++) {
24410
+ for (var toRow = offsets[pass]; toRow < rows; toRow += steps[pass]) {
24411
+ cpRow(toRow, fromRow);
24412
+ fromRow++;
24740
24413
  }
24741
- return arr;
24742
- };
24414
+ }
24415
+ return newPixels;
24743
24416
  };
24744
- lib.loop = loop;
24417
+ deinterlace$1.deinterlace = deinterlace;
24745
24418
 
24746
- var uint8 = {};
24419
+ var lzw$1 = {};
24747
24420
 
24748
- Object.defineProperty(uint8, "__esModule", {
24421
+ Object.defineProperty(lzw$1, "__esModule", {
24749
24422
  value: true
24750
24423
  });
24751
- uint8.readBits = uint8.readArray = uint8.readUnsigned = uint8.readString = uint8.peekBytes = uint8.readBytes = uint8.peekByte = uint8.readByte = uint8.buildStream = void 0;
24752
-
24753
- // Default stream and parsers for Uint8TypedArray data type
24754
- var buildStream = function buildStream(uint8Data) {
24755
- return {
24756
- data: uint8Data,
24757
- pos: 0
24758
- };
24759
- };
24760
- uint8.buildStream = buildStream;
24761
- var readByte = function readByte() {
24762
- return function (stream) {
24763
- return stream.data[stream.pos++];
24764
- };
24765
- };
24766
- uint8.readByte = readByte;
24767
- var peekByte = function peekByte() {
24768
- var offset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
24769
- return function (stream) {
24770
- return stream.data[stream.pos + offset];
24771
- };
24772
- };
24773
- uint8.peekByte = peekByte;
24774
- var readBytes = function readBytes(length) {
24775
- return function (stream) {
24776
- return stream.data.subarray(stream.pos, stream.pos += length);
24777
- };
24778
- };
24779
- uint8.readBytes = readBytes;
24780
- var peekBytes = function peekBytes(length) {
24781
- return function (stream) {
24782
- return stream.data.subarray(stream.pos, stream.pos + length);
24783
- };
24784
- };
24785
- uint8.peekBytes = peekBytes;
24786
- var readString = function readString(length) {
24787
- return function (stream) {
24788
- return Array.from(readBytes(length)(stream)).map(function (value) {
24789
- return String.fromCharCode(value);
24790
- }).join('');
24791
- };
24792
- };
24793
- uint8.readString = readString;
24794
- var readUnsigned = function readUnsigned(littleEndian) {
24795
- return function (stream) {
24796
- var bytes = readBytes(2)(stream);
24797
- return littleEndian ? (bytes[1] << 8) + bytes[0] : (bytes[0] << 8) + bytes[1];
24798
- };
24799
- };
24800
- uint8.readUnsigned = readUnsigned;
24801
- var readArray = function readArray(byteSize, totalOrFunc) {
24802
- return function (stream, result, parent) {
24803
- var total = typeof totalOrFunc === 'function' ? totalOrFunc(stream, result, parent) : totalOrFunc;
24804
- var parser = readBytes(byteSize);
24805
- var arr = new Array(total);
24806
- for (var i = 0; i < total; i++) {
24807
- arr[i] = parser(stream);
24808
- }
24809
- return arr;
24810
- };
24811
- };
24812
- uint8.readArray = readArray;
24813
- var subBitsTotal = function subBitsTotal(bits, startIndex, length) {
24814
- var result = 0;
24815
- for (var i = 0; i < length; i++) {
24816
- result += bits[startIndex + i] && Math.pow(2, length - i - 1);
24817
- }
24818
- return result;
24819
- };
24820
- var readBits = function readBits(schema) {
24821
- return function (stream) {
24822
- var _byte = readByte()(stream); // convert the byte to bit array
24823
-
24824
- var bits = new Array(8);
24825
- for (var i = 0; i < 8; i++) {
24826
- bits[7 - i] = !!(_byte & 1 << i);
24827
- } // convert the bit array to values based on the schema
24424
+ lzw$1.lzw = void 0;
24828
24425
 
24829
- return Object.keys(schema).reduce(function (res, key) {
24830
- var def = schema[key];
24831
- if (def.length) {
24832
- res[key] = subBitsTotal(bits, def.index, def.length);
24833
- } else {
24834
- res[key] = bits[def.index];
24835
- }
24836
- return res;
24837
- }, {});
24838
- };
24839
- };
24840
- uint8.readBits = readBits;
24426
+ /**
24427
+ * javascript port of java LZW decompression
24428
+ * Original java author url: https://gist.github.com/devunwired/4479231
24429
+ */
24430
+ var lzw = function lzw(minCodeSize, data, pixelCount) {
24431
+ var MAX_STACK_SIZE = 4096;
24432
+ var nullCode = -1;
24433
+ var npix = pixelCount;
24434
+ var available, clear, code_mask, code_size, end_of_information, in_code, old_code, bits, code, i, datum, data_size, first, top, bi, pi;
24435
+ var dstPixels = new Array(pixelCount);
24436
+ var prefix = new Array(MAX_STACK_SIZE);
24437
+ var suffix = new Array(MAX_STACK_SIZE);
24438
+ var pixelStack = new Array(MAX_STACK_SIZE + 1); // Initialize GIF data stream decoder.
24841
24439
 
24842
- (function (exports) {
24440
+ data_size = minCodeSize;
24441
+ clear = 1 << data_size;
24442
+ end_of_information = clear + 1;
24443
+ available = clear + 2;
24444
+ old_code = nullCode;
24445
+ code_size = data_size + 1;
24446
+ code_mask = (1 << code_size) - 1;
24447
+ for (code = 0; code < clear; code++) {
24448
+ prefix[code] = 0;
24449
+ suffix[code] = code;
24450
+ } // Decode GIF pixel stream.
24843
24451
 
24844
- Object.defineProperty(exports, "__esModule", {
24845
- value: true
24846
- });
24847
- exports["default"] = void 0;
24848
- var _ = lib;
24849
- var _uint = uint8;
24452
+ var datum, bits, first, top, pi, bi;
24453
+ datum = bits = first = top = pi = bi = 0;
24454
+ for (i = 0; i < npix;) {
24455
+ if (top === 0) {
24456
+ if (bits < code_size) {
24457
+ // get the next byte
24458
+ datum += data[bi] << bits;
24459
+ bits += 8;
24460
+ bi++;
24461
+ continue;
24462
+ } // Get the next code.
24850
24463
 
24851
- // a set of 0x00 terminated subblocks
24852
- var subBlocksSchema = {
24853
- blocks: function blocks(stream) {
24854
- var terminator = 0x00;
24855
- var chunks = [];
24856
- var streamSize = stream.data.length;
24857
- var total = 0;
24858
- for (var size = (0, _uint.readByte)()(stream); size !== terminator; size = (0, _uint.readByte)()(stream)) {
24859
- // size becomes undefined for some case when file is corrupted and terminator is not proper
24860
- // null check to avoid recursion
24861
- if (!size) break; // catch corrupted files with no terminator
24464
+ code = datum & code_mask;
24465
+ datum >>= code_size;
24466
+ bits -= code_size; // Interpret the code
24862
24467
 
24863
- if (stream.pos + size >= streamSize) {
24864
- var availableSize = streamSize - stream.pos;
24865
- chunks.push((0, _uint.readBytes)(availableSize)(stream));
24866
- total += availableSize;
24867
- break;
24868
- }
24869
- chunks.push((0, _uint.readBytes)(size)(stream));
24870
- total += size;
24468
+ if (code > available || code == end_of_information) {
24469
+ break;
24871
24470
  }
24872
- var result = new Uint8Array(total);
24873
- var offset = 0;
24874
- for (var i = 0; i < chunks.length; i++) {
24875
- result.set(chunks[i], offset);
24876
- offset += chunks[i].length;
24471
+ if (code == clear) {
24472
+ // Reset decoder.
24473
+ code_size = data_size + 1;
24474
+ code_mask = (1 << code_size) - 1;
24475
+ available = clear + 2;
24476
+ old_code = nullCode;
24477
+ continue;
24877
24478
  }
24878
- return result;
24879
- }
24880
- }; // global control extension
24479
+ if (old_code == nullCode) {
24480
+ pixelStack[top++] = suffix[code];
24481
+ old_code = code;
24482
+ first = code;
24483
+ continue;
24484
+ }
24485
+ in_code = code;
24486
+ if (code == available) {
24487
+ pixelStack[top++] = first;
24488
+ code = old_code;
24489
+ }
24490
+ while (code > clear) {
24491
+ pixelStack[top++] = suffix[code];
24492
+ code = prefix[code];
24493
+ }
24494
+ first = suffix[code] & 0xff;
24495
+ pixelStack[top++] = first; // add a new string to the table, but only if space is available
24496
+ // if not, just continue with current table until a clear code is found
24497
+ // (deferred clear code implementation as per GIF spec)
24881
24498
 
24882
- var gceSchema = (0, _.conditional)({
24883
- gce: [{
24884
- codes: (0, _uint.readBytes)(2)
24885
- }, {
24886
- byteSize: (0, _uint.readByte)()
24887
- }, {
24888
- extras: (0, _uint.readBits)({
24889
- future: {
24890
- index: 0,
24891
- length: 3
24892
- },
24893
- disposal: {
24894
- index: 3,
24895
- length: 3
24896
- },
24897
- userInput: {
24898
- index: 6
24899
- },
24900
- transparentColorGiven: {
24901
- index: 7
24499
+ if (available < MAX_STACK_SIZE) {
24500
+ prefix[available] = old_code;
24501
+ suffix[available] = first;
24502
+ available++;
24503
+ if ((available & code_mask) === 0 && available < MAX_STACK_SIZE) {
24504
+ code_size++;
24505
+ code_mask += available;
24902
24506
  }
24903
- })
24904
- }, {
24905
- delay: (0, _uint.readUnsigned)(true)
24906
- }, {
24907
- transparentColorIndex: (0, _uint.readByte)()
24908
- }, {
24909
- terminator: (0, _uint.readByte)()
24910
- }]
24911
- }, function (stream) {
24912
- var codes = (0, _uint.peekBytes)(2)(stream);
24913
- return codes[0] === 0x21 && codes[1] === 0xf9;
24914
- }); // image pipeline block
24915
-
24916
- var imageSchema = (0, _.conditional)({
24917
- image: [{
24918
- code: (0, _uint.readByte)()
24919
- }, {
24920
- descriptor: [{
24921
- left: (0, _uint.readUnsigned)(true)
24922
- }, {
24923
- top: (0, _uint.readUnsigned)(true)
24924
- }, {
24925
- width: (0, _uint.readUnsigned)(true)
24926
- }, {
24927
- height: (0, _uint.readUnsigned)(true)
24928
- }, {
24929
- lct: (0, _uint.readBits)({
24930
- exists: {
24931
- index: 0
24932
- },
24933
- interlaced: {
24934
- index: 1
24935
- },
24936
- sort: {
24937
- index: 2
24938
- },
24939
- future: {
24940
- index: 3,
24941
- length: 2
24942
- },
24943
- size: {
24944
- index: 5,
24945
- length: 3
24946
- }
24947
- })
24948
- }]
24949
- }, (0, _.conditional)({
24950
- lct: (0, _uint.readArray)(3, function (stream, result, parent) {
24951
- return Math.pow(2, parent.descriptor.lct.size + 1);
24952
- })
24953
- }, function (stream, result, parent) {
24954
- return parent.descriptor.lct.exists;
24955
- }), {
24956
- data: [{
24957
- minCodeSize: (0, _uint.readByte)()
24958
- }, subBlocksSchema]
24959
- }]
24960
- }, function (stream) {
24961
- return (0, _uint.peekByte)()(stream) === 0x2c;
24962
- }); // plain text block
24963
-
24964
- var textSchema = (0, _.conditional)({
24965
- text: [{
24966
- codes: (0, _uint.readBytes)(2)
24967
- }, {
24968
- blockSize: (0, _uint.readByte)()
24969
- }, {
24970
- preData: function preData(stream, result, parent) {
24971
- return (0, _uint.readBytes)(parent.text.blockSize)(stream);
24972
- }
24973
- }, subBlocksSchema]
24974
- }, function (stream) {
24975
- var codes = (0, _uint.peekBytes)(2)(stream);
24976
- return codes[0] === 0x21 && codes[1] === 0x01;
24977
- }); // application block
24978
-
24979
- var applicationSchema = (0, _.conditional)({
24980
- application: [{
24981
- codes: (0, _uint.readBytes)(2)
24982
- }, {
24983
- blockSize: (0, _uint.readByte)()
24984
- }, {
24985
- id: function id(stream, result, parent) {
24986
- return (0, _uint.readString)(parent.blockSize)(stream);
24987
24507
  }
24988
- }, subBlocksSchema]
24989
- }, function (stream) {
24990
- var codes = (0, _uint.peekBytes)(2)(stream);
24991
- return codes[0] === 0x21 && codes[1] === 0xff;
24992
- }); // comment block
24993
-
24994
- var commentSchema = (0, _.conditional)({
24995
- comment: [{
24996
- codes: (0, _uint.readBytes)(2)
24997
- }, subBlocksSchema]
24998
- }, function (stream) {
24999
- var codes = (0, _uint.peekBytes)(2)(stream);
25000
- return codes[0] === 0x21 && codes[1] === 0xfe;
25001
- });
25002
- var schema = [{
25003
- header: [{
25004
- signature: (0, _uint.readString)(3)
25005
- }, {
25006
- version: (0, _uint.readString)(3)
25007
- }]
25008
- }, {
25009
- lsd: [{
25010
- width: (0, _uint.readUnsigned)(true)
25011
- }, {
25012
- height: (0, _uint.readUnsigned)(true)
25013
- }, {
25014
- gct: (0, _uint.readBits)({
25015
- exists: {
25016
- index: 0
25017
- },
25018
- resolution: {
25019
- index: 1,
25020
- length: 3
25021
- },
25022
- sort: {
25023
- index: 4
25024
- },
25025
- size: {
25026
- index: 5,
25027
- length: 3
25028
- }
25029
- })
25030
- }, {
25031
- backgroundColorIndex: (0, _uint.readByte)()
25032
- }, {
25033
- pixelAspectRatio: (0, _uint.readByte)()
25034
- }]
25035
- }, (0, _.conditional)({
25036
- gct: (0, _uint.readArray)(3, function (stream, result) {
25037
- return Math.pow(2, result.lsd.gct.size + 1);
25038
- })
25039
- }, function (stream, result) {
25040
- return result.lsd.gct.exists;
25041
- }),
25042
- // content frames
25043
- {
25044
- frames: (0, _.loop)([gceSchema, applicationSchema, commentSchema, imageSchema, textSchema], function (stream) {
25045
- var nextCode = (0, _uint.peekByte)()(stream); // rather than check for a terminator, we should check for the existence
25046
- // of an ext or image block to avoid infinite loops
25047
- //var terminator = 0x3B;
25048
- //return nextCode !== terminator;
24508
+ old_code = in_code;
24509
+ } // Pop a pixel off the pixel stack.
25049
24510
 
25050
- return nextCode === 0x21 || nextCode === 0x2c;
25051
- })
25052
- }];
25053
- var _default = schema;
25054
- exports["default"] = _default;
25055
- })(gif);
24511
+ top--;
24512
+ dstPixels[pi++] = pixelStack[top];
24513
+ i++;
24514
+ }
24515
+ for (i = pi; i < npix; i++) {
24516
+ dstPixels[i] = 0; // clear missing pixels
24517
+ }
25056
24518
 
25057
- var deinterlace$1 = {};
24519
+ return dstPixels;
24520
+ };
24521
+ lzw$1.lzw = lzw;
25058
24522
 
25059
- Object.defineProperty(deinterlace$1, "__esModule", {
24523
+ Object.defineProperty(lib$1, "__esModule", {
25060
24524
  value: true
25061
24525
  });
25062
- deinterlace$1.deinterlace = void 0;
25063
-
25064
- /**
25065
- * Deinterlace function from https://github.com/shachaf/jsgif
25066
- */
25067
- var deinterlace = function deinterlace(pixels, width) {
25068
- var newPixels = new Array(pixels.length);
25069
- var rows = pixels.length / width;
25070
- var cpRow = function cpRow(toRow, fromRow) {
25071
- var fromPixels = pixels.slice(fromRow * width, (fromRow + 1) * width);
25072
- newPixels.splice.apply(newPixels, [toRow * width, width].concat(fromPixels));
25073
- }; // See appendix E.
25074
-
25075
- var offsets = [0, 4, 2, 1];
25076
- var steps = [8, 8, 4, 2];
25077
- var fromRow = 0;
25078
- for (var pass = 0; pass < 4; pass++) {
25079
- for (var toRow = offsets[pass]; toRow < rows; toRow += steps[pass]) {
25080
- cpRow(toRow, fromRow);
25081
- fromRow++;
25082
- }
24526
+ var decompressFrames_1 = lib$1.decompressFrames = lib$1.decompressFrame = parseGIF_1 = lib$1.parseGIF = void 0;
24527
+ var _gif = _interopRequireDefault(gif);
24528
+ var _jsBinarySchemaParser = lib;
24529
+ var _uint = uint8;
24530
+ var _deinterlace = deinterlace$1;
24531
+ var _lzw = lzw$1;
24532
+ function _interopRequireDefault(obj) {
24533
+ return obj && obj.__esModule ? obj : {
24534
+ "default": obj
24535
+ };
24536
+ }
24537
+ var parseGIF = function parseGIF(arrayBuffer) {
24538
+ var byteData = new Uint8Array(arrayBuffer);
24539
+ return (0, _jsBinarySchemaParser.parse)((0, _uint.buildStream)(byteData), _gif["default"]);
24540
+ };
24541
+ var parseGIF_1 = lib$1.parseGIF = parseGIF;
24542
+ var generatePatch = function generatePatch(image) {
24543
+ var totalPixels = image.pixels.length;
24544
+ var patchData = new Uint8ClampedArray(totalPixels * 4);
24545
+ for (var i = 0; i < totalPixels; i++) {
24546
+ var pos = i * 4;
24547
+ var colorIndex = image.pixels[i];
24548
+ var color = image.colorTable[colorIndex] || [0, 0, 0];
24549
+ patchData[pos] = color[0];
24550
+ patchData[pos + 1] = color[1];
24551
+ patchData[pos + 2] = color[2];
24552
+ patchData[pos + 3] = colorIndex !== image.transparentIndex ? 255 : 0;
25083
24553
  }
25084
- return newPixels;
24554
+ return patchData;
25085
24555
  };
25086
- deinterlace$1.deinterlace = deinterlace;
24556
+ var decompressFrame = function decompressFrame(frame, gct, buildImagePatch) {
24557
+ if (!frame.image) {
24558
+ console.warn('gif frame does not have associated image.');
24559
+ return;
24560
+ }
24561
+ var image = frame.image; // get the number of pixels
25087
24562
 
25088
- var lzw$1 = {};
24563
+ var totalPixels = image.descriptor.width * image.descriptor.height; // do lzw decompression
25089
24564
 
25090
- Object.defineProperty(lzw$1, "__esModule", {
25091
- value: true
25092
- });
25093
- lzw$1.lzw = void 0;
24565
+ var pixels = (0, _lzw.lzw)(image.data.minCodeSize, image.data.blocks, totalPixels); // deal with interlacing if necessary
25094
24566
 
25095
- /**
25096
- * javascript port of java LZW decompression
25097
- * Original java author url: https://gist.github.com/devunwired/4479231
25098
- */
25099
- var lzw = function lzw(minCodeSize, data, pixelCount) {
25100
- var MAX_STACK_SIZE = 4096;
25101
- var nullCode = -1;
25102
- var npix = pixelCount;
25103
- var available, clear, code_mask, code_size, end_of_information, in_code, old_code, bits, code, i, datum, data_size, first, top, bi, pi;
25104
- var dstPixels = new Array(pixelCount);
25105
- var prefix = new Array(MAX_STACK_SIZE);
25106
- var suffix = new Array(MAX_STACK_SIZE);
25107
- var pixelStack = new Array(MAX_STACK_SIZE + 1); // Initialize GIF data stream decoder.
24567
+ if (image.descriptor.lct.interlaced) {
24568
+ pixels = (0, _deinterlace.deinterlace)(pixels, image.descriptor.width);
24569
+ }
24570
+ var resultImage = {
24571
+ pixels: pixels,
24572
+ dims: {
24573
+ top: frame.image.descriptor.top,
24574
+ left: frame.image.descriptor.left,
24575
+ width: frame.image.descriptor.width,
24576
+ height: frame.image.descriptor.height
24577
+ }
24578
+ }; // color table
25108
24579
 
25109
- data_size = minCodeSize;
25110
- clear = 1 << data_size;
25111
- end_of_information = clear + 1;
25112
- available = clear + 2;
25113
- old_code = nullCode;
25114
- code_size = data_size + 1;
25115
- code_mask = (1 << code_size) - 1;
25116
- for (code = 0; code < clear; code++) {
25117
- prefix[code] = 0;
25118
- suffix[code] = code;
25119
- } // Decode GIF pixel stream.
24580
+ if (image.descriptor.lct && image.descriptor.lct.exists) {
24581
+ resultImage.colorTable = image.lct;
24582
+ } else {
24583
+ resultImage.colorTable = gct;
24584
+ } // add per frame relevant gce information
25120
24585
 
25121
- var datum, bits, first, top, pi, bi;
25122
- datum = bits = first = top = pi = bi = 0;
25123
- for (i = 0; i < npix;) {
25124
- if (top === 0) {
25125
- if (bits < code_size) {
25126
- // get the next byte
25127
- datum += data[bi] << bits;
25128
- bits += 8;
25129
- bi++;
25130
- continue;
25131
- } // Get the next code.
24586
+ if (frame.gce) {
24587
+ resultImage.delay = (frame.gce.delay || 10) * 10; // convert to ms
25132
24588
 
25133
- code = datum & code_mask;
25134
- datum >>= code_size;
25135
- bits -= code_size; // Interpret the code
24589
+ resultImage.disposalType = frame.gce.extras.disposal; // transparency
25136
24590
 
25137
- if (code > available || code == end_of_information) {
25138
- break;
25139
- }
25140
- if (code == clear) {
25141
- // Reset decoder.
25142
- code_size = data_size + 1;
25143
- code_mask = (1 << code_size) - 1;
25144
- available = clear + 2;
25145
- old_code = nullCode;
25146
- continue;
25147
- }
25148
- if (old_code == nullCode) {
25149
- pixelStack[top++] = suffix[code];
25150
- old_code = code;
25151
- first = code;
25152
- continue;
25153
- }
25154
- in_code = code;
25155
- if (code == available) {
25156
- pixelStack[top++] = first;
25157
- code = old_code;
25158
- }
25159
- while (code > clear) {
25160
- pixelStack[top++] = suffix[code];
25161
- code = prefix[code];
25162
- }
25163
- first = suffix[code] & 0xff;
25164
- pixelStack[top++] = first; // add a new string to the table, but only if space is available
25165
- // if not, just continue with current table until a clear code is found
25166
- // (deferred clear code implementation as per GIF spec)
24591
+ if (frame.gce.extras.transparentColorGiven) {
24592
+ resultImage.transparentIndex = frame.gce.transparentColorIndex;
24593
+ }
24594
+ } // create canvas usable imagedata if desired
25167
24595
 
25168
- if (available < MAX_STACK_SIZE) {
25169
- prefix[available] = old_code;
25170
- suffix[available] = first;
25171
- available++;
25172
- if ((available & code_mask) === 0 && available < MAX_STACK_SIZE) {
25173
- code_size++;
25174
- code_mask += available;
24596
+ if (buildImagePatch) {
24597
+ resultImage.patch = generatePatch(resultImage);
24598
+ }
24599
+ return resultImage;
24600
+ };
24601
+ lib$1.decompressFrame = decompressFrame;
24602
+ var decompressFrames = function decompressFrames(parsedGif, buildImagePatches) {
24603
+ return parsedGif.frames.filter(function (f) {
24604
+ return f.image;
24605
+ }).map(function (f) {
24606
+ return decompressFrame(f, parsedGif.gct, buildImagePatches);
24607
+ });
24608
+ };
24609
+ decompressFrames_1 = lib$1.decompressFrames = decompressFrames;
24610
+
24611
+ class GifImage extends Image$2 {
24612
+ constructor(params) {
24613
+ super(params);
24614
+ this.type = 'gif-image';
24615
+ this.numberType = GIFIMAGE_NUMBER_TYPE;
24616
+ this.loadGif();
24617
+ }
24618
+ loadGif() {
24619
+ if (isString(this.attribute.gifImage)) {
24620
+ ResourceLoader$1.GetFile(this.attribute.gifImage, 'arrayBuffer')
24621
+ .then((res) => {
24622
+ const gif = parseGIF_1(res);
24623
+ const frames = decompressFrames_1(gif, true);
24624
+ this.renderGIF(frames);
24625
+ })
24626
+ .catch(e => {
24627
+ console.error('Gif load error: ', e);
24628
+ });
24629
+ }
24630
+ else if (this.attribute.gifImage instanceof ArrayBuffer) {
24631
+ const gif = parseGIF_1(this.attribute.gifImage);
24632
+ const frames = decompressFrames_1(gif, true);
24633
+ this.renderGIF(frames);
24634
+ }
24635
+ }
24636
+ renderGIF(frames) {
24637
+ this.loadedFrames = frames;
24638
+ this.frameIndex = 0;
24639
+ if (!this.tempCanvas) {
24640
+ this.tempCanvas = application.global.createCanvas({});
24641
+ this.tempCtx = this.tempCanvas.getContext('2d');
24642
+ }
24643
+ if (!this.gifCanvas) {
24644
+ this.gifCanvas = application.global.createCanvas({});
24645
+ this.gifCtx = this.gifCanvas.getContext('2d');
24646
+ }
24647
+ this.gifCanvas.width = frames[0].dims.width;
24648
+ this.gifCanvas.height = frames[0].dims.height;
24649
+ this.playing = true;
24650
+ this.lastTime = new Date().getTime();
24651
+ const animation = this.animate();
24652
+ if (this.attribute.timeline) {
24653
+ animation.setTimeline(this.attribute.timeline);
24654
+ }
24655
+ animation.to({}, 1000, 'linear').loop(Infinity);
24656
+ }
24657
+ renderFrame(context, x, y) {
24658
+ const frame = this.loadedFrames[this.frameIndex || 0];
24659
+ if (frame.disposalType === 2) {
24660
+ this.gifCtx.clearRect(0, 0, this.gifCanvas.width, this.gifCanvas.height);
24661
+ }
24662
+ this.drawPatch(frame);
24663
+ this.manipulate(context, x, y);
24664
+ const diff = new Date().getTime() - this.lastTime;
24665
+ if (frame.delay < diff) {
24666
+ this.frameIndex++;
24667
+ this.lastTime = new Date().getTime();
24668
+ }
24669
+ if (this.frameIndex >= this.loadedFrames.length) {
24670
+ this.frameIndex = 0;
24671
+ }
24672
+ }
24673
+ drawPatch(frame) {
24674
+ const dims = frame.dims;
24675
+ if (!this.frameImageData ||
24676
+ dims.width !== this.frameImageData.width ||
24677
+ dims.height !== this.frameImageData.height) {
24678
+ this.tempCanvas.width = dims.width;
24679
+ this.tempCanvas.height = dims.height;
24680
+ this.frameImageData = this.tempCtx.createImageData(dims.width, dims.height);
24681
+ }
24682
+ this.frameImageData.data.set(frame.patch);
24683
+ this.tempCtx.putImageData(this.frameImageData, 0, 0);
24684
+ this.gifCtx.drawImage(this.tempCanvas, dims.left, dims.top);
24685
+ }
24686
+ manipulate(context, x, y) {
24687
+ context.drawImage(this.gifCanvas, 0, 0, this.gifCanvas.width, this.gifCanvas.height, x, y, this.attribute.width, this.attribute.height);
24688
+ }
24689
+ setAttribute(key, value, forceUpdateTag, context) {
24690
+ super.setAttribute(key, value, forceUpdateTag, context);
24691
+ if (key === 'gifImage') {
24692
+ this.loadGif();
24693
+ }
24694
+ }
24695
+ setAttributes(params, forceUpdateTag, context) {
24696
+ super.setAttributes(params, forceUpdateTag, context);
24697
+ if (params.gifImage) {
24698
+ this.loadGif();
24699
+ }
24700
+ }
24701
+ }
24702
+ function createGifImage(attributes) {
24703
+ return new GifImage(attributes);
24704
+ }
24705
+
24706
+ class DefaultCanvasGifImageRender extends DefaultCanvasImageRender$1 {
24707
+ constructor(imageRenderContribitions) {
24708
+ super(imageRenderContribitions);
24709
+ this.imageRenderContribitions = imageRenderContribitions;
24710
+ this.numberType = GIFIMAGE_NUMBER_TYPE;
24711
+ this._renderContribitions = undefined;
24712
+ this.builtinContributions = [defaultGifImageRenderContribution];
24713
+ this.init(imageRenderContribitions);
24714
+ }
24715
+ drawShape(image, context, x, y, drawContext, params, fillCb, strokeCb) {
24716
+ const imageAttribute = getTheme$1(image).image;
24717
+ const { x: originX = imageAttribute.x, y: originY = imageAttribute.y, fillStrokeOrder = imageAttribute.fillStrokeOrder } = image.attribute;
24718
+ const data = this.valid(image, imageAttribute, fillCb);
24719
+ if (!data) {
24720
+ return;
24721
+ }
24722
+ const { fVisible, sVisible, doFill, doStroke } = data;
24723
+ const _runFill = () => {
24724
+ if (doFill) {
24725
+ if (fillCb) {
24726
+ fillCb(context, image.attribute, imageAttribute);
24727
+ }
24728
+ }
24729
+ };
24730
+ const _runStroke = () => {
24731
+ if (doStroke) {
24732
+ if (strokeCb) {
24733
+ strokeCb(context, image.attribute, imageAttribute);
24734
+ }
24735
+ else if (sVisible) {
24736
+ context.setStrokeStyle(image, image.attribute, originX - x, originY - y, imageAttribute);
24737
+ context.stroke();
24738
+ }
24739
+ }
24740
+ };
24741
+ if (!fillStrokeOrder) {
24742
+ {
24743
+ context.save();
24744
+ context.clip();
24745
+ }
24746
+ this.beforeRenderStep(image, context, x, y, doFill, false, fVisible, false, imageAttribute, drawContext, fillCb);
24747
+ _runFill();
24748
+ {
24749
+ context.restore();
24750
+ }
24751
+ _runStroke();
24752
+ }
24753
+ else {
24754
+ _runStroke();
24755
+ {
24756
+ context.save();
24757
+ context.clip();
24758
+ }
24759
+ this.beforeRenderStep(image, context, x, y, doFill, false, fVisible, false, imageAttribute, drawContext, fillCb);
24760
+ _runFill();
24761
+ {
24762
+ context.restore();
24763
+ }
24764
+ }
24765
+ this.afterRenderStep(image, context, x, y, doFill, false, fVisible, false, imageAttribute, drawContext, fillCb);
24766
+ }
24767
+ draw(image, renderService, drawContext) {
24768
+ const { context } = renderService.drawParams;
24769
+ if (!context) {
24770
+ return;
24771
+ }
24772
+ const imageAttribute = getTheme$1(image).image;
24773
+ this._draw(image, imageAttribute, false, drawContext);
24774
+ }
24775
+ }
24776
+ class DefaultGifImageRenderContribution extends DefaultRectRenderContribution$1 {
24777
+ constructor() {
24778
+ super(...arguments);
24779
+ this.time = BaseRenderContributionTime$1.afterFillStroke;
24780
+ this.useStyle = true;
24781
+ this.order = 0;
24782
+ }
24783
+ drawShape(image, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb) {
24784
+ if (image.renderFrame && image.playing) {
24785
+ image.renderFrame(context, x, y);
24786
+ }
24787
+ }
24788
+ }
24789
+ const defaultGifImageRenderContribution = new DefaultGifImageRenderContribution();
24790
+
24791
+ let loadGifImageModule = false;
24792
+ function bindGifImageRenderContribution(container) {
24793
+ if (loadGifImageModule) {
24794
+ return;
24795
+ }
24796
+ loadGifImageModule = true;
24797
+ container
24798
+ .bind(DefaultCanvasGifImageRender)
24799
+ .toDynamicValue(() => new DefaultCanvasGifImageRender(createContributionProvider$1(ImageRenderContribution$1, container)))
24800
+ .inSingletonScope();
24801
+ container.bind(GraphicRender).toService(DefaultCanvasGifImageRender);
24802
+ }
24803
+
24804
+ function registerGifGraphic() {
24805
+ graphicCreator$1.RegisterGraphicCreator('gif', createGifImage);
24806
+ }
24807
+ function _registerGifImage() {
24808
+ if (_registerGifImage.__loaded) {
24809
+ return;
24810
+ }
24811
+ _registerGifImage.__loaded = true;
24812
+ const legacyContext = getLegacyBindingContext$1();
24813
+ registerGifGraphic();
24814
+ bindGifImageRenderContribution(legacyContext);
24815
+ bindGifImageCanvasPickerContribution(legacyContext);
24816
+ }
24817
+ _registerGifImage.__loaded = false;
24818
+ const registerGifImage = _registerGifImage;
24819
+
24820
+ class LynxContext2d extends BrowserContext2d {
24821
+ get globalAlpha() {
24822
+ return this._globalAlpha;
24823
+ }
24824
+ set globalAlpha(ga) {
24825
+ this.nativeContext.globalAlpha = ga * this.baseGlobalAlpha;
24826
+ this._globalAlpha = ga * this.baseGlobalAlpha;
24827
+ }
24828
+ setLineDash(segments) {
24829
+ const a = arguments;
24830
+ const _context = this.nativeContext;
24831
+ if (!!this.nativeContext.setLineDash) {
24832
+ const lineDash = a[0];
24833
+ if (lineDash[0] === 0 && lineDash[1] === 0) {
24834
+ return;
24835
+ }
24836
+ lineDash && _context.setLineDash(lineDash);
24837
+ }
24838
+ }
24839
+ _setStrokeStyle(params, attribute, offsetX, offsetY, defaultParams) {
24840
+ const _context = this.nativeContext;
24841
+ if (!defaultParams) {
24842
+ defaultParams = this.strokeAttributes;
24843
+ }
24844
+ const { strokeOpacity = defaultParams.strokeOpacity, opacity = defaultParams.opacity } = attribute;
24845
+ if (strokeOpacity > 1e-12 && opacity > 1e-12) {
24846
+ const { lineWidth = defaultParams.lineWidth, stroke = defaultParams.stroke, lineJoin = defaultParams.lineJoin, lineDash = defaultParams.lineDash, lineCap = defaultParams.lineCap, miterLimit = defaultParams.miterLimit, keepStrokeScale = defaultParams.keepStrokeScale, lineDashOffset = defaultParams.lineDashOffset } = attribute;
24847
+ _context.globalAlpha = strokeOpacity * opacity * this.baseGlobalAlpha;
24848
+ _context.lineWidth = keepStrokeScale ? lineWidth : getScaledStroke$1(this, lineWidth, this.dpr);
24849
+ _context.strokeStyle = createColor$1(this, stroke, params, offsetX, offsetY);
24850
+ _context.lineJoin = lineJoin;
24851
+ if (!(lineDash[0] === 0 && lineDash[1] === 0) && lineDash) {
24852
+ _context.setLineDash(lineDash);
24853
+ _context.lineDashOffset = lineDashOffset;
24854
+ }
24855
+ _context.lineCap = lineCap;
24856
+ _context.miterLimit = miterLimit;
24857
+ }
24858
+ }
24859
+ measureText(text, method = application.global.measureTextMethod) {
24860
+ const dpr = this.dpr || 1;
24861
+ this.setTransform(1, 0, 0, 1, 0, 0, true, dpr);
24862
+ const metrics = super.measureText(text, method);
24863
+ if (dpr === 1 || metrics.fontBoundingBoxAscent == null || metrics.fontBoundingBoxDescent == null) {
24864
+ return metrics;
24865
+ }
24866
+ return Object.assign(Object.assign({}, metrics), { width: metrics.width, actualBoundingBoxLeft: metrics.actualBoundingBoxLeft, actualBoundingBoxRight: metrics.actualBoundingBoxRight, actualBoundingBoxAscent: metrics.actualBoundingBoxAscent, actualBoundingBoxDescent: metrics.actualBoundingBoxDescent, fontBoundingBoxAscent: metrics.fontBoundingBoxAscent / dpr, fontBoundingBoxDescent: metrics.fontBoundingBoxDescent / dpr });
24867
+ }
24868
+ createPattern(image, repetition) {
24869
+ return null;
24870
+ }
24871
+ draw() {
24872
+ const _context = this.nativeContext;
24873
+ if (!_context.draw) {
24874
+ return;
24875
+ }
24876
+ this.drawPromise = new Promise(resolve => {
24877
+ _context.draw(true, () => {
24878
+ this.drawPromise = null;
24879
+ resolve(null);
24880
+ });
24881
+ });
24882
+ }
24883
+ }
24884
+ LynxContext2d.env = 'lynx';
24885
+
24886
+ class LynxCanvas extends BaseCanvas {
24887
+ constructor(params) {
24888
+ super(params);
24889
+ }
24890
+ init() {
24891
+ this._context = new LynxContext2d(this, this._dpr);
24892
+ }
24893
+ resize(width, height) {
24894
+ this._pixelWidth = width * this._dpr;
24895
+ this._pixelHeight = height * this._dpr;
24896
+ this._displayWidth = width;
24897
+ this._displayHeight = height;
24898
+ this._nativeCanvas.width = this._pixelWidth;
24899
+ this._nativeCanvas.height = this._pixelHeight;
24900
+ if (this._nativeCanvas.nativeCanvas) {
24901
+ this._nativeCanvas.nativeCanvas.width = this._pixelWidth;
24902
+ this._nativeCanvas.nativeCanvas.height = this._pixelHeight;
24903
+ }
24904
+ const _context = this._context;
24905
+ _context.dpr = this._dpr;
24906
+ }
24907
+ release(...params) {
24908
+ return;
24909
+ }
24910
+ }
24911
+ LynxCanvas.env = 'lynx';
24912
+
24913
+ const bindLynxCanvasModules = createModule(LynxCanvas, LynxContext2d);
24914
+
24915
+ class MiniAppEventManager {
24916
+ constructor() {
24917
+ this.cache = {};
24918
+ }
24919
+ addEventListener(type, func) {
24920
+ if (!type || !func) {
24921
+ return;
24922
+ }
24923
+ this.cache[type] = this.cache[type] || {
24924
+ listener: []
24925
+ };
24926
+ this.cache[type].listener.push(func);
24927
+ }
24928
+ removeEventListener(type, func) {
24929
+ if (!type || !func) {
24930
+ return;
24931
+ }
24932
+ if (!this.cache[type]) {
24933
+ return;
24934
+ }
24935
+ const index = this.cache[type].listener.findIndex((f) => f === func);
24936
+ if (index >= 0) {
24937
+ this.cache[type].listener.splice(index, 1);
24938
+ }
24939
+ }
24940
+ cleanEvent() {
24941
+ this.cache = {};
24942
+ }
24943
+ }
24944
+ function setMiniAppEventTarget(event, key, value) {
24945
+ if (!event || !value) {
24946
+ return;
24947
+ }
24948
+ try {
24949
+ event[key] = value;
24950
+ }
24951
+ catch (_a) {
24952
+ Object.defineProperty(event, key, {
24953
+ configurable: true,
24954
+ value
24955
+ });
24956
+ }
24957
+ }
24958
+ function isValidCoordinate$1(value) {
24959
+ return typeof value === 'number' && Number.isFinite(value);
24960
+ }
24961
+ function pickCoordinate$1(...values) {
24962
+ for (let i = 0; i < values.length; i++) {
24963
+ if (isValidCoordinate$1(values[i])) {
24964
+ return values[i];
24965
+ }
24966
+ }
24967
+ return undefined;
24968
+ }
24969
+ function setLynxEventValue(event, key, value) {
24970
+ try {
24971
+ event[key] = value;
24972
+ }
24973
+ catch (_a) {
24974
+ Object.defineProperty(event, key, {
24975
+ configurable: true,
24976
+ value
24977
+ });
24978
+ }
24979
+ }
24980
+ function normalizeLynxTouchEventPoint(event) {
24981
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
24982
+ 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];
24983
+ if (!touch) {
24984
+ return;
24985
+ }
24986
+ const x = pickCoordinate$1(event.x, event.offsetX, event.clientX, event.pageX, touch.x, touch.offsetX, touch.clientX, touch.pageX);
24987
+ const y = pickCoordinate$1(event.y, event.offsetY, event.clientY, event.pageY, touch.y, touch.offsetY, touch.clientY, touch.pageY);
24988
+ if (x == null || y == null) {
24989
+ return;
24990
+ }
24991
+ if (!event.touches && event.changedTouches) {
24992
+ setLynxEventValue(event, 'touches', event.type === 'touchend' || event.type === 'touchcancel' ? [] : event.changedTouches);
24993
+ }
24994
+ setLynxEventValue(event, 'x', x);
24995
+ setLynxEventValue(event, 'y', y);
24996
+ setLynxEventValue(event, 'offsetX', (_d = event.offsetX) !== null && _d !== void 0 ? _d : x);
24997
+ setLynxEventValue(event, 'offsetY', (_e = event.offsetY) !== null && _e !== void 0 ? _e : y);
24998
+ setLynxEventValue(event, 'clientX', (_f = event.clientX) !== null && _f !== void 0 ? _f : x);
24999
+ setLynxEventValue(event, 'clientY', (_g = event.clientY) !== null && _g !== void 0 ? _g : y);
25000
+ setLynxEventValue(event, 'pageX', (_h = event.pageX) !== null && _h !== void 0 ? _h : x);
25001
+ setLynxEventValue(event, 'pageY', (_j = event.pageY) !== null && _j !== void 0 ? _j : y);
25002
+ touch.x = (_k = touch.x) !== null && _k !== void 0 ? _k : x;
25003
+ touch.y = (_l = touch.y) !== null && _l !== void 0 ? _l : y;
25004
+ touch.offsetX = (_m = touch.offsetX) !== null && _m !== void 0 ? _m : x;
25005
+ touch.offsetY = (_o = touch.offsetY) !== null && _o !== void 0 ? _o : y;
25006
+ touch.clientX = (_p = touch.clientX) !== null && _p !== void 0 ? _p : x;
25007
+ touch.clientY = (_q = touch.clientY) !== null && _q !== void 0 ? _q : y;
25008
+ touch.pageX = (_r = touch.pageX) !== null && _r !== void 0 ? _r : x;
25009
+ touch.pageY = (_s = touch.pageY) !== null && _s !== void 0 ? _s : y;
25010
+ }
25011
+ class LynxWindowHandlerContribution extends BaseWindowHandlerContribution {
25012
+ get container() {
25013
+ return null;
25014
+ }
25015
+ constructor(global = application.global) {
25016
+ super();
25017
+ this.global = global;
25018
+ this.type = 'lynx';
25019
+ this.eventManager = new MiniAppEventManager();
25020
+ }
25021
+ getTitle() {
25022
+ return this.canvas.id && this.canvas.id.toString();
25023
+ }
25024
+ getWH() {
25025
+ return {
25026
+ width: this.canvas.width / (this.canvas.dpr || 1),
25027
+ height: this.canvas.height / (this.canvas.dpr || 1)
25028
+ };
25029
+ }
25030
+ getXY() {
25031
+ return { x: 0, y: 0 };
25032
+ }
25033
+ createWindow(params) {
25034
+ if (!params.canvas) {
25035
+ this.createWindowByConfig(params);
25036
+ }
25037
+ else {
25038
+ this.createWindowByCanvas(params);
25039
+ }
25040
+ }
25041
+ createWindowByConfig(params) {
25042
+ const nativeCanvas = this.global.createCanvas({
25043
+ width: params.width,
25044
+ height: params.height
25045
+ });
25046
+ const options = {
25047
+ width: params.width,
25048
+ height: params.height,
25049
+ dpr: params.dpr,
25050
+ nativeCanvas,
25051
+ id: Generator.GenAutoIncrementId().toString(),
25052
+ canvasControled: false
25053
+ };
25054
+ this.canvas = new LynxCanvas(options);
25055
+ }
25056
+ createWindowByCanvas(params) {
25057
+ let canvas;
25058
+ if (typeof params.canvas === 'string') {
25059
+ canvas = this.global.getElementById(params.canvas);
25060
+ if (!canvas) {
25061
+ canvas = this.global.createCanvas({
25062
+ id: params.canvas,
25063
+ width: params.width,
25064
+ height: params.height,
25065
+ dpr: params.dpr
25066
+ });
25067
+ }
25068
+ if (!canvas) {
25069
+ throw new Error('canvasId 参数不正确,请确认canvas存在并插入dom');
25070
+ }
25071
+ }
25072
+ else {
25073
+ canvas = params.canvas;
25074
+ }
25075
+ let width = params.width;
25076
+ let height = params.height;
25077
+ if (width == null || height == null || !params.canvasControled) {
25078
+ const data = canvas.getBoundingClientRect();
25079
+ width = data.width;
25080
+ height = data.height;
25081
+ }
25082
+ let dpr = params.dpr;
25083
+ if (dpr == null) {
25084
+ dpr = canvas.width / width;
25085
+ }
25086
+ this.canvas = new LynxCanvas({
25087
+ width: width,
25088
+ height: height,
25089
+ dpr: dpr,
25090
+ nativeCanvas: canvas,
25091
+ canvasControled: params.canvasControled
25092
+ });
25093
+ }
25094
+ releaseWindow() {
25095
+ return;
25096
+ }
25097
+ resizeWindow(width, height) {
25098
+ this.canvas.resize(width, height);
25099
+ }
25100
+ setDpr(dpr) {
25101
+ this.canvas.dpr = dpr;
25102
+ }
25103
+ getContext() {
25104
+ return this.canvas.getContext();
25105
+ }
25106
+ getNativeHandler() {
25107
+ return this.canvas;
25108
+ }
25109
+ getDpr() {
25110
+ return this.canvas.dpr;
25111
+ }
25112
+ addEventListener(type, listener) {
25113
+ this.eventManager.addEventListener(type, listener);
25114
+ }
25115
+ removeEventListener(type, listener) {
25116
+ this.eventManager.removeEventListener(type, listener);
25117
+ }
25118
+ dispatchEvent(event) {
25119
+ var _a;
25120
+ const { type } = event;
25121
+ if (!this.eventManager.cache[type]) {
25122
+ return false;
25123
+ }
25124
+ const nativeCanvas = (_a = this.canvas) === null || _a === void 0 ? void 0 : _a.nativeCanvas;
25125
+ setMiniAppEventTarget(event, 'target', nativeCanvas);
25126
+ setMiniAppEventTarget(event, 'currentTarget', nativeCanvas);
25127
+ normalizeLynxTouchEventPoint(event);
25128
+ event.preventDefault = () => {
25129
+ return;
25130
+ };
25131
+ event.stopPropagation = () => {
25132
+ return;
25133
+ };
25134
+ if (this.eventManager.cache[type].listener) {
25135
+ this.eventManager.cache[type].listener.forEach((f) => {
25136
+ f(event);
25137
+ });
25138
+ }
25139
+ return true;
25140
+ }
25141
+ getStyle() {
25142
+ return {};
25143
+ }
25144
+ setStyle(style) {
25145
+ return;
25146
+ }
25147
+ getBoundingClientRect() {
25148
+ const wh = this.getWH();
25149
+ return {
25150
+ x: 0,
25151
+ y: 0,
25152
+ width: wh.width,
25153
+ height: wh.height,
25154
+ left: 0,
25155
+ top: 0,
25156
+ right: 0,
25157
+ bottom: 0
25158
+ };
25159
+ }
25160
+ clearViewBox(color) {
25161
+ const vb = this.viewBox;
25162
+ const context = this.getContext();
25163
+ const dpr = this.getDpr();
25164
+ context.nativeContext.save();
25165
+ context.nativeContext.setTransform(dpr, 0, 0, dpr, 0, 0);
25166
+ context.clearRect(vb.x1, vb.y1, vb.x2 - vb.x1, vb.y2 - vb.y1);
25167
+ if (color) {
25168
+ context.fillStyle = color;
25169
+ context.fillRect(vb.x1, vb.y1, vb.x2 - vb.x1, vb.y2 - vb.y1);
25170
+ }
25171
+ context.nativeContext.restore();
25172
+ }
25173
+ }
25174
+ LynxWindowHandlerContribution.env = 'lynx';
25175
+ function bindLynxWindowContribution(container) {
25176
+ var _a, _b;
25177
+ if (!((_a = container.isBound) === null || _a === void 0 ? void 0 : _a.call(container, LynxWindowHandlerContribution))) {
25178
+ container.bind(LynxWindowHandlerContribution).toSelf();
25179
+ }
25180
+ if (!((_b = container.getNamed) === null || _b === void 0 ? void 0 : _b.call(container, WindowHandlerContribution$1, LynxWindowHandlerContribution.env))) {
25181
+ container
25182
+ .bind(WindowHandlerContribution$1)
25183
+ .toService(LynxWindowHandlerContribution)
25184
+ .whenTargetNamed(LynxWindowHandlerContribution.env);
25185
+ }
25186
+ }
25187
+
25188
+ const LYNX_CANVAS_BRIDGE_ERROR = 'Lynx canvas bridge is unavailable. VRender Lynx env requires envParams.canvasFactory ' +
25189
+ 'or a Lynx runtime that exposes createCanvasNG/createCanvas/createOffscreenCanvas/krypton canvas APIs.';
25190
+ const LYNX_CANVAS_SIZE_ERROR = 'Lynx canvas size is unavailable. Pass stage width/height when creating a Lynx stage canvas.';
25191
+ function isValidCoordinate(value) {
25192
+ return typeof value === 'number' && Number.isFinite(value);
25193
+ }
25194
+ function pickCoordinate(...values) {
25195
+ for (let i = 0; i < values.length; i++) {
25196
+ if (isValidCoordinate(values[i])) {
25197
+ return values[i];
25198
+ }
25199
+ }
25200
+ return undefined;
25201
+ }
25202
+ function getPrimaryTouch(event) {
25203
+ var _a, _b, _c;
25204
+ 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];
25205
+ }
25206
+ function getLynxEventPoint(event) {
25207
+ const touch = getPrimaryTouch(event);
25208
+ 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);
25209
+ 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);
25210
+ return x == null || y == null ? null : { x, y };
25211
+ }
25212
+ function getGlobalLynxRuntime() {
25213
+ try {
25214
+ return typeof lynx !== 'undefined' ? lynx : undefined;
25215
+ }
25216
+ catch (err) {
25217
+ return undefined;
25218
+ }
25219
+ }
25220
+ function getGlobalSystemPixelRatio() {
25221
+ try {
25222
+ return typeof SystemInfo !== 'undefined' ? SystemInfo.pixelRatio : undefined;
25223
+ }
25224
+ catch (err) {
25225
+ return undefined;
25226
+ }
25227
+ }
25228
+ function getLynxRuntime(params) {
25229
+ var _a, _b;
25230
+ 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();
25231
+ }
25232
+ const requestAnimationFrameBasedSTO = (callback) => rafBasedSto.call(callback);
25233
+ const cancelAnimationFrameBasedSTO = (handle) => rafBasedSto.clear(handle);
25234
+ function getLynxPixelRatio(params, runtime) {
25235
+ var _a, _b, _c, _d, _e;
25236
+ 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;
25237
+ }
25238
+ function attachLynxCanvasToView(canvas, id) {
25239
+ var _a;
25240
+ (_a = canvas === null || canvas === void 0 ? void 0 : canvas.attachToCanvasView) === null || _a === void 0 ? void 0 : _a.call(canvas, id);
25241
+ return canvas;
25242
+ }
25243
+ function createBoundLynxCanvas(id, runtime) {
25244
+ var _a, _b, _c;
25245
+ if (typeof ((_a = runtime === null || runtime === void 0 ? void 0 : runtime.krypton) === null || _a === void 0 ? void 0 : _a.createCanvas) === 'function') {
25246
+ const canvas = runtime.krypton.createCanvas(id);
25247
+ if (canvas) {
25248
+ return canvas;
25175
25249
  }
25176
- }
25177
- old_code = in_code;
25178
- } // Pop a pixel off the pixel stack.
25179
-
25180
- top--;
25181
- dstPixels[pi++] = pixelStack[top];
25182
- i++;
25183
- }
25184
- for (i = pi; i < npix; i++) {
25185
- dstPixels[i] = 0; // clear missing pixels
25186
- }
25187
-
25188
- return dstPixels;
25189
- };
25190
- lzw$1.lzw = lzw;
25191
-
25192
- Object.defineProperty(lib$1, "__esModule", {
25193
- value: true
25194
- });
25195
- var decompressFrames_1 = lib$1.decompressFrames = lib$1.decompressFrame = parseGIF_1 = lib$1.parseGIF = void 0;
25196
- var _gif = _interopRequireDefault(gif);
25197
- var _jsBinarySchemaParser = lib;
25198
- var _uint = uint8;
25199
- var _deinterlace = deinterlace$1;
25200
- var _lzw = lzw$1;
25201
- function _interopRequireDefault(obj) {
25202
- return obj && obj.__esModule ? obj : {
25203
- "default": obj
25204
- };
25250
+ }
25251
+ if (typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createCanvasNG) === 'function') {
25252
+ const canvas = runtime.createCanvasNG(id);
25253
+ if (canvas) {
25254
+ return attachLynxCanvasToView(canvas, id);
25255
+ }
25256
+ }
25257
+ if (typeof ((_b = runtime === null || runtime === void 0 ? void 0 : runtime.krypton) === null || _b === void 0 ? void 0 : _b.createCanvasNG) === 'function') {
25258
+ const canvas = runtime.krypton.createCanvasNG();
25259
+ if (canvas) {
25260
+ return attachLynxCanvasToView(canvas, id);
25261
+ }
25262
+ }
25263
+ if (typeof ((_c = runtime === null || runtime === void 0 ? void 0 : runtime.krypton) === null || _c === void 0 ? void 0 : _c.CanvasElement) === 'function') {
25264
+ return new runtime.krypton.CanvasElement(id);
25265
+ }
25266
+ if (typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createCanvas) === 'function') {
25267
+ const canvas = runtime.createCanvas(id);
25268
+ if (canvas) {
25269
+ return canvas;
25270
+ }
25271
+ }
25272
+ return null;
25205
25273
  }
25206
- var parseGIF = function parseGIF(arrayBuffer) {
25207
- var byteData = new Uint8Array(arrayBuffer);
25208
- return (0, _jsBinarySchemaParser.parse)((0, _uint.buildStream)(byteData), _gif["default"]);
25209
- };
25210
- var parseGIF_1 = lib$1.parseGIF = parseGIF;
25211
- var generatePatch = function generatePatch(image) {
25212
- var totalPixels = image.pixels.length;
25213
- var patchData = new Uint8ClampedArray(totalPixels * 4);
25214
- for (var i = 0; i < totalPixels; i++) {
25215
- var pos = i * 4;
25216
- var colorIndex = image.pixels[i];
25217
- var color = image.colorTable[colorIndex] || [0, 0, 0];
25218
- patchData[pos] = color[0];
25219
- patchData[pos + 1] = color[1];
25220
- patchData[pos + 2] = color[2];
25221
- patchData[pos + 3] = colorIndex !== image.transparentIndex ? 255 : 0;
25222
- }
25223
- return patchData;
25224
- };
25225
- var decompressFrame = function decompressFrame(frame, gct, buildImagePatch) {
25226
- if (!frame.image) {
25227
- console.warn('gif frame does not have associated image.');
25228
- return;
25229
- }
25230
- var image = frame.image; // get the number of pixels
25231
-
25232
- var totalPixels = image.descriptor.width * image.descriptor.height; // do lzw decompression
25233
-
25234
- var pixels = (0, _lzw.lzw)(image.data.minCodeSize, image.data.blocks, totalPixels); // deal with interlacing if necessary
25235
-
25236
- if (image.descriptor.lct.interlaced) {
25237
- pixels = (0, _deinterlace.deinterlace)(pixels, image.descriptor.width);
25238
- }
25239
- var resultImage = {
25240
- pixels: pixels,
25241
- dims: {
25242
- top: frame.image.descriptor.top,
25243
- left: frame.image.descriptor.left,
25244
- width: frame.image.descriptor.width,
25245
- height: frame.image.descriptor.height
25274
+ function getCanvasSize(width, height) {
25275
+ if (!isValidCoordinate(width) || !isValidCoordinate(height)) {
25276
+ throw new Error(LYNX_CANVAS_SIZE_ERROR);
25246
25277
  }
25247
- }; // color table
25248
-
25249
- if (image.descriptor.lct && image.descriptor.lct.exists) {
25250
- resultImage.colorTable = image.lct;
25251
- } else {
25252
- resultImage.colorTable = gct;
25253
- } // add per frame relevant gce information
25254
-
25255
- if (frame.gce) {
25256
- resultImage.delay = (frame.gce.delay || 10) * 10; // convert to ms
25257
-
25258
- resultImage.disposalType = frame.gce.extras.disposal; // transparency
25259
-
25260
- if (frame.gce.extras.transparentColorGiven) {
25261
- resultImage.transparentIndex = frame.gce.transparentColorIndex;
25278
+ return { width, height };
25279
+ }
25280
+ function wrapLynxNativeCanvas(nativeCanvas, id, width, height, dpr) {
25281
+ nativeCanvas.width = width * dpr;
25282
+ nativeCanvas.height = height * dpr;
25283
+ const ctx = nativeCanvas.getContext('2d');
25284
+ return new CanvasWrapEnableWH(nativeCanvas, ctx, dpr, width, height, id);
25285
+ }
25286
+ function createLynxNativeCanvas(id, width, height, dpr, offscreen, params, runtime) {
25287
+ if (params.canvasFactory) {
25288
+ return params.canvasFactory({
25289
+ id,
25290
+ width,
25291
+ height,
25292
+ dpr,
25293
+ offscreen
25294
+ });
25262
25295
  }
25263
- } // create canvas usable imagedata if desired
25264
-
25265
- if (buildImagePatch) {
25266
- resultImage.patch = generatePatch(resultImage);
25267
- }
25268
- return resultImage;
25269
- };
25270
- lib$1.decompressFrame = decompressFrame;
25271
- var decompressFrames = function decompressFrames(parsedGif, buildImagePatches) {
25272
- return parsedGif.frames.filter(function (f) {
25273
- return f.image;
25274
- }).map(function (f) {
25275
- return decompressFrame(f, parsedGif.gct, buildImagePatches);
25276
- });
25277
- };
25278
- decompressFrames_1 = lib$1.decompressFrames = decompressFrames;
25279
-
25280
- class GifImage extends Image$2 {
25281
- constructor(params) {
25282
- super(params);
25283
- this.type = 'gif-image';
25284
- this.numberType = GIFIMAGE_NUMBER_TYPE;
25285
- this.loadGif();
25296
+ if (offscreen) {
25297
+ if (typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createOffscreenCanvas) === 'function') {
25298
+ return runtime.createOffscreenCanvas();
25299
+ }
25286
25300
  }
25287
- loadGif() {
25288
- if (isString(this.attribute.gifImage)) {
25289
- ResourceLoader$1.GetFile(this.attribute.gifImage, 'arrayBuffer')
25290
- .then((res) => {
25291
- const gif = parseGIF_1(res);
25292
- const frames = decompressFrames_1(gif, true);
25293
- this.renderGIF(frames);
25294
- })
25295
- .catch(e => {
25296
- console.error('Gif load error: ', e);
25297
- });
25301
+ else {
25302
+ const canvas = createBoundLynxCanvas(id, runtime);
25303
+ if (canvas) {
25304
+ return canvas;
25298
25305
  }
25299
- else if (this.attribute.gifImage instanceof ArrayBuffer) {
25300
- const gif = parseGIF_1(this.attribute.gifImage);
25301
- const frames = decompressFrames_1(gif, true);
25302
- this.renderGIF(frames);
25306
+ }
25307
+ throw new Error(LYNX_CANVAS_BRIDGE_ERROR);
25308
+ }
25309
+ function createImageElement(src, isSvg = false, runtime = getGlobalLynxRuntime()) {
25310
+ if (isSvg) {
25311
+ return Promise.reject();
25312
+ }
25313
+ if (typeof (runtime === null || runtime === void 0 ? void 0 : runtime.createImage) !== 'function') {
25314
+ return Promise.reject(new Error('Lynx image bridge is unavailable.'));
25315
+ }
25316
+ const img = runtime.createImage(src);
25317
+ const promise = new Promise((resolve, reject) => {
25318
+ img.onload = () => {
25319
+ resolve(img);
25320
+ };
25321
+ img.onerror = () => {
25322
+ reject(new Error('加载失败'));
25323
+ };
25324
+ });
25325
+ return promise;
25326
+ }
25327
+ class LynxEnvContribution extends BaseEnvContribution {
25328
+ constructor() {
25329
+ super();
25330
+ this.type = 'lynx';
25331
+ this.supportEvent = true;
25332
+ this.canvasMap = new Map();
25333
+ this.freeCanvasList = [];
25334
+ this.canvasIdx = 0;
25335
+ this.requestAnimationFrame = requestAnimationFrameBasedSTO;
25336
+ this.cancelAnimationFrame = cancelAnimationFrameBasedSTO;
25337
+ this.supportsTouchEvents = true;
25338
+ try {
25339
+ this.supportsPointerEvents = !!globalThis.PointerEvent;
25340
+ this.supportsMouseEvents = !!globalThis.MouseEvent;
25341
+ }
25342
+ catch (err) {
25343
+ this.supportsPointerEvents = false;
25344
+ this.supportsMouseEvents = false;
25345
+ }
25346
+ this.applyStyles = true;
25347
+ }
25348
+ configure(service, params = {}) {
25349
+ var _a, _b;
25350
+ if (service.env === this.type) {
25351
+ service.setActiveEnvContribution(this);
25352
+ this.lynxEnvParams = params;
25353
+ this.lynxRuntime = getLynxRuntime(params);
25354
+ if (typeof ((_a = this.lynxRuntime) === null || _a === void 0 ? void 0 : _a.requestAnimationFrame) === 'function' &&
25355
+ typeof ((_b = this.lynxRuntime) === null || _b === void 0 ? void 0 : _b.cancelAnimationFrame) === 'function') {
25356
+ this.requestAnimationFrame = this.lynxRuntime.requestAnimationFrame.bind(this.lynxRuntime);
25357
+ this.cancelAnimationFrame = this.lynxRuntime.cancelAnimationFrame.bind(this.lynxRuntime);
25358
+ }
25359
+ else {
25360
+ this.requestAnimationFrame = requestAnimationFrameBasedSTO;
25361
+ this.cancelAnimationFrame = cancelAnimationFrameBasedSTO;
25362
+ }
25303
25363
  }
25304
25364
  }
25305
- renderGIF(frames) {
25306
- this.loadedFrames = frames;
25307
- this.frameIndex = 0;
25308
- if (!this.tempCanvas) {
25309
- this.tempCanvas = application.global.createCanvas({});
25310
- this.tempCtx = this.tempCanvas.getContext('2d');
25311
- }
25312
- if (!this.gifCanvas) {
25313
- this.gifCanvas = application.global.createCanvas({});
25314
- this.gifCtx = this.gifCanvas.getContext('2d');
25365
+ getDynamicCanvasCount() {
25366
+ return this.freeCanvasList.length;
25367
+ }
25368
+ getStaticCanvasCount() {
25369
+ return 9999;
25370
+ }
25371
+ loadImage(url) {
25372
+ const imagePromise = createImageElement(url, false, this.lynxRuntime);
25373
+ return imagePromise
25374
+ .then((img) => {
25375
+ return {
25376
+ data: img,
25377
+ loadState: 'success'
25378
+ };
25379
+ })
25380
+ .catch(() => {
25381
+ return {
25382
+ data: null,
25383
+ loadState: 'fail'
25384
+ };
25385
+ });
25386
+ }
25387
+ loadSvg(url) {
25388
+ return Promise.resolve({
25389
+ data: null,
25390
+ loadState: 'fail'
25391
+ });
25392
+ }
25393
+ createCanvas(params) {
25394
+ var _a, _b, _c, _d;
25395
+ if (params.id != null) {
25396
+ const id = String(params.id);
25397
+ const existing = this.canvasMap.get(id);
25398
+ if (existing) {
25399
+ return existing;
25400
+ }
25401
+ const envParams = (_a = this.lynxEnvParams) !== null && _a !== void 0 ? _a : {};
25402
+ const runtime = getLynxRuntime(envParams);
25403
+ const dpr = (_b = params.dpr) !== null && _b !== void 0 ? _b : getLynxPixelRatio(envParams, runtime);
25404
+ const size = getCanvasSize(params.width, params.height);
25405
+ const nativeCanvas = createLynxNativeCanvas(id, size.width, size.height, dpr, false, envParams, runtime);
25406
+ const canvas = wrapLynxNativeCanvas(nativeCanvas, id, size.width, size.height, dpr);
25407
+ this.canvasMap.set(id, canvas);
25408
+ return canvas;
25315
25409
  }
25316
- this.gifCanvas.width = frames[0].dims.width;
25317
- this.gifCanvas.height = frames[0].dims.height;
25318
- this.playing = true;
25319
- this.lastTime = new Date().getTime();
25320
- const animation = this.animate();
25321
- if (this.attribute.timeline) {
25322
- animation.setTimeline(this.attribute.timeline);
25410
+ const result = this.freeCanvasList[this.canvasIdx] || this.freeCanvasList[this.freeCanvasList.length - 1];
25411
+ this.canvasIdx++;
25412
+ if (result) {
25413
+ return result;
25323
25414
  }
25324
- animation.to({}, 1000, 'linear').loop(Infinity);
25415
+ const envParams = (_c = this.lynxEnvParams) !== null && _c !== void 0 ? _c : {};
25416
+ const runtime = getLynxRuntime(envParams);
25417
+ const dpr = (_d = params.dpr) !== null && _d !== void 0 ? _d : getLynxPixelRatio(envParams, runtime);
25418
+ const size = getCanvasSize(params.width, params.height);
25419
+ const id = Math.random().toString();
25420
+ const nativeCanvas = createLynxNativeCanvas(id, size.width, size.height, dpr, true, envParams, runtime);
25421
+ const canvas = wrapLynxNativeCanvas(nativeCanvas, id, size.width, size.height, dpr);
25422
+ this.canvasMap.set(id, canvas);
25423
+ this.freeCanvasList.push(canvas);
25424
+ return canvas;
25325
25425
  }
25326
- renderFrame(context, x, y) {
25327
- const frame = this.loadedFrames[this.frameIndex || 0];
25328
- if (frame.disposalType === 2) {
25329
- this.gifCtx.clearRect(0, 0, this.gifCanvas.width, this.gifCanvas.height);
25330
- }
25331
- this.drawPatch(frame);
25332
- this.manipulate(context, x, y);
25333
- const diff = new Date().getTime() - this.lastTime;
25334
- if (frame.delay < diff) {
25335
- this.frameIndex++;
25336
- this.lastTime = new Date().getTime();
25337
- }
25338
- if (this.frameIndex >= this.loadedFrames.length) {
25339
- this.frameIndex = 0;
25340
- }
25426
+ createOffscreenCanvas(params) {
25427
+ return;
25341
25428
  }
25342
- drawPatch(frame) {
25343
- const dims = frame.dims;
25344
- if (!this.frameImageData ||
25345
- dims.width !== this.frameImageData.width ||
25346
- dims.height !== this.frameImageData.height) {
25347
- this.tempCanvas.width = dims.width;
25348
- this.tempCanvas.height = dims.height;
25349
- this.frameImageData = this.tempCtx.createImageData(dims.width, dims.height);
25350
- }
25351
- this.frameImageData.data.set(frame.patch);
25352
- this.tempCtx.putImageData(this.frameImageData, 0, 0);
25353
- this.gifCtx.drawImage(this.tempCanvas, dims.left, dims.top);
25429
+ releaseCanvas(canvas) {
25430
+ return;
25354
25431
  }
25355
- manipulate(context, x, y) {
25356
- context.drawImage(this.gifCanvas, 0, 0, this.gifCanvas.width, this.gifCanvas.height, x, y, this.attribute.width, this.attribute.height);
25432
+ getDevicePixelRatio() {
25433
+ return getLynxPixelRatio(undefined, this.lynxRuntime);
25357
25434
  }
25358
- setAttribute(key, value, forceUpdateTag, context) {
25359
- super.setAttribute(key, value, forceUpdateTag, context);
25360
- if (key === 'gifImage') {
25361
- this.loadGif();
25362
- }
25435
+ getRequestAnimationFrame() {
25436
+ return this.requestAnimationFrame;
25363
25437
  }
25364
- setAttributes(params, forceUpdateTag, context) {
25365
- super.setAttributes(params, forceUpdateTag, context);
25366
- if (params.gifImage) {
25367
- this.loadGif();
25368
- }
25438
+ getCancelAnimationFrame() {
25439
+ return this.cancelAnimationFrame;
25369
25440
  }
25370
- }
25371
- function createGifImage(attributes) {
25372
- return new GifImage(attributes);
25373
- }
25374
-
25375
- class DefaultCanvasGifImageRender extends DefaultCanvasImageRender$1 {
25376
- constructor(imageRenderContribitions) {
25377
- super(imageRenderContribitions);
25378
- this.imageRenderContribitions = imageRenderContribitions;
25379
- this.numberType = GIFIMAGE_NUMBER_TYPE;
25380
- this._renderContribitions = undefined;
25381
- this.builtinContributions = [defaultGifImageRenderContribution];
25382
- this.init(imageRenderContribitions);
25441
+ mapToCanvasPoint(event) {
25442
+ var _a;
25443
+ return (_a = getLynxEventPoint(event)) !== null && _a !== void 0 ? _a : event;
25383
25444
  }
25384
- drawShape(image, context, x, y, drawContext, params, fillCb, strokeCb) {
25385
- const imageAttribute = getTheme$1(image).image;
25386
- const { x: originX = imageAttribute.x, y: originY = imageAttribute.y, fillStrokeOrder = imageAttribute.fillStrokeOrder } = image.attribute;
25387
- const data = this.valid(image, imageAttribute, fillCb);
25388
- if (!data) {
25389
- return;
25390
- }
25391
- const { fVisible, sVisible, doFill, doStroke } = data;
25392
- const _runFill = () => {
25393
- if (doFill) {
25394
- if (fillCb) {
25395
- fillCb(context, image.attribute, imageAttribute);
25396
- }
25397
- }
25398
- };
25399
- const _runStroke = () => {
25400
- if (doStroke) {
25401
- if (strokeCb) {
25402
- strokeCb(context, image.attribute, imageAttribute);
25403
- }
25404
- else if (sVisible) {
25405
- context.setStrokeStyle(image, image.attribute, originX - x, originY - y, imageAttribute);
25406
- context.stroke();
25407
- }
25408
- }
25409
- };
25410
- if (!fillStrokeOrder) {
25411
- {
25412
- context.save();
25413
- context.clip();
25414
- }
25415
- this.beforeRenderStep(image, context, x, y, doFill, false, fVisible, false, imageAttribute, drawContext, fillCb);
25416
- _runFill();
25417
- {
25418
- context.restore();
25419
- }
25420
- _runStroke();
25421
- }
25422
- else {
25423
- _runStroke();
25424
- {
25425
- context.save();
25426
- context.clip();
25427
- }
25428
- this.beforeRenderStep(image, context, x, y, doFill, false, fVisible, false, imageAttribute, drawContext, fillCb);
25429
- _runFill();
25430
- {
25431
- context.restore();
25432
- }
25433
- }
25434
- this.afterRenderStep(image, context, x, y, doFill, false, fVisible, false, imageAttribute, drawContext, fillCb);
25445
+ addEventListener(type, listener, options) {
25446
+ return null;
25435
25447
  }
25436
- draw(image, renderService, drawContext) {
25437
- const { context } = renderService.drawParams;
25438
- if (!context) {
25439
- return;
25440
- }
25441
- const imageAttribute = getTheme$1(image).image;
25442
- this._draw(image, imageAttribute, false, drawContext);
25448
+ removeEventListener(type, listener, options) {
25449
+ return null;
25443
25450
  }
25444
- }
25445
- class DefaultGifImageRenderContribution extends DefaultRectRenderContribution$1 {
25446
- constructor() {
25447
- super(...arguments);
25448
- this.time = BaseRenderContributionTime$1.afterFillStroke;
25449
- this.useStyle = true;
25450
- this.order = 0;
25451
+ dispatchEvent(event) {
25452
+ return null;
25451
25453
  }
25452
- drawShape(image, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb) {
25453
- if (image.renderFrame && image.playing) {
25454
- image.renderFrame(context, x, y);
25455
- }
25454
+ getElementById(str) {
25455
+ return this.canvasMap.get(str);
25456
25456
  }
25457
- }
25458
- const defaultGifImageRenderContribution = new DefaultGifImageRenderContribution();
25459
-
25460
- let loadGifImageModule = false;
25461
- function bindGifImageRenderContribution(container) {
25462
- if (loadGifImageModule) {
25457
+ getRootElement() {
25458
+ return null;
25459
+ }
25460
+ getDocument() {
25461
+ return null;
25462
+ }
25463
+ release(...params) {
25463
25464
  return;
25464
25465
  }
25465
- loadGifImageModule = true;
25466
- container
25467
- .bind(DefaultCanvasGifImageRender)
25468
- .toDynamicValue(() => new DefaultCanvasGifImageRender(createContributionProvider$1(ImageRenderContribution$1, container)))
25469
- .inSingletonScope();
25470
- container.bind(GraphicRender).toService(DefaultCanvasGifImageRender);
25471
25466
  }
25472
25467
 
25473
- function registerGifGraphic() {
25474
- graphicCreator$1.RegisterGraphicCreator('gif', createGifImage);
25468
+ function bindLynxEnv(container) {
25469
+ var _a, _b;
25470
+ if (!((_b = (_a = container).isBound) === null || _b === void 0 ? void 0 : _b.call(_a, LynxEnvContribution))) {
25471
+ container.bind(LynxEnvContribution).toSelf().inSingletonScope();
25472
+ container.bind(EnvContribution$1).toService(LynxEnvContribution);
25473
+ }
25475
25474
  }
25476
- function _registerGifImage() {
25477
- if (_registerGifImage.__loaded) {
25478
- return;
25475
+ function loadLynxEnv(container = getLegacyBindingContext$1(), loadPicker = true) {
25476
+ if (!loadLynxEnv.__loaded) {
25477
+ loadLynxEnv.__loaded = true;
25478
+ bindLynxEnv(container);
25479
+ bindLynxCanvasModules(container);
25480
+ bindLynxWindowContribution(container);
25481
+ loadPicker && loadMathPicker(container);
25479
25482
  }
25480
- _registerGifImage.__loaded = true;
25481
- const legacyContext = getLegacyBindingContext$1();
25482
- registerGifGraphic();
25483
- bindGifImageRenderContribution(legacyContext);
25484
- bindGifImageCanvasPickerContribution(legacyContext);
25485
25483
  }
25486
- _registerGifImage.__loaded = false;
25487
- const registerGifImage = _registerGifImage;
25484
+ loadLynxEnv.__loaded = false;
25485
+ function initLynxEnv() {
25486
+ loadLynxEnv();
25487
+ }
25488
+
25489
+ function createForcedEnvParams$1(envParams) {
25490
+ if (envParams != null && (typeof envParams === 'object' || typeof envParams === 'function')) {
25491
+ const forcedEnvParams = Object.create(envParams);
25492
+ forcedEnvParams.force = true;
25493
+ return forcedEnvParams;
25494
+ }
25495
+ return { force: true };
25496
+ }
25497
+ function installLynxEnvToApp(app, envParams) {
25498
+ configureRuntimeApplicationForApp(app);
25499
+ const bindingContext = getRuntimeInstallerBindingContext();
25500
+ bindLynxEnv(bindingContext);
25501
+ bindLynxCanvasModules(bindingContext);
25502
+ bindLynxWindowContribution(bindingContext);
25503
+ refreshRuntimeInstallerContributions();
25504
+ getRuntimeInstallerGlobal().setEnv('lynx', createForcedEnvParams$1(envParams));
25505
+ }
25488
25506
 
25489
25507
  const defaultGraphicInstallSteps = [
25490
25508
  { register: registerArcGraphic, bindModule: arcModule },
@@ -25632,13 +25650,6 @@ function installWxEnvToApp(app, envParams) {
25632
25650
  bindWindowContribution: bindWxWindowContribution
25633
25651
  }, envParams);
25634
25652
  }
25635
- function installLynxEnvToApp(app, envParams) {
25636
- installRuntimeEnvToApp(app, 'lynx', {
25637
- bindEnv: bindLynxEnv,
25638
- bindCanvasModules: bindLynxCanvasModules,
25639
- bindWindowContribution: bindLynxWindowContribution
25640
- }, envParams);
25641
- }
25642
25653
  function installHarmonyEnvToApp(app, envParams) {
25643
25654
  installRuntimeEnvToApp(app, 'harmony', {
25644
25655
  bindEnv: bindHarmonyEnv,