@antv/g-canvas 1.9.46 → 1.9.48
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/Canvas2DContextService.d.ts +1 -1
- package/dist/Canvas2DContextService.d.ts.map +1 -1
- package/dist/index.esm.js +31 -44
- package/dist/index.js +31 -44
- package/dist/index.umd.js +1346 -2699
- package/dist/index.umd.min.js +1 -1
- package/package.json +7 -7
package/dist/index.umd.js
CHANGED
|
@@ -1903,12 +1903,11 @@
|
|
|
1903
1903
|
var CanvasPickerPlugin = /*#__PURE__*/function () {
|
|
1904
1904
|
function CanvasPickerPlugin() {
|
|
1905
1905
|
var _this = this;
|
|
1906
|
-
this.
|
|
1907
|
-
this.
|
|
1908
|
-
this.
|
|
1909
|
-
this.isHit = function (displayObject, position, worldTransform, isClipPath, runtime) {
|
|
1906
|
+
this.context = void 0;
|
|
1907
|
+
this.runtime = void 0;
|
|
1908
|
+
this.isHit = function (displayObject, position, worldTransform, isClipPath) {
|
|
1910
1909
|
// use picker for current shape's type
|
|
1911
|
-
var pick = _this.pointInPathPickerFactory[displayObject.nodeName];
|
|
1910
|
+
var pick = _this.context.pointInPathPickerFactory[displayObject.nodeName];
|
|
1912
1911
|
if (pick) {
|
|
1913
1912
|
// invert with world matrix
|
|
1914
1913
|
var invertWorldMat = invert(tmpMat4, worldTransform);
|
|
@@ -1920,7 +1919,7 @@
|
|
|
1920
1919
|
var anchor = displayObject.parsedStyle.anchor;
|
|
1921
1920
|
localPosition[0] += (anchor && anchor[0] || 0) * halfExtents[0] * 2;
|
|
1922
1921
|
localPosition[1] += (anchor && anchor[1] || 0) * halfExtents[1] * 2;
|
|
1923
|
-
if (pick(displayObject, new gLite.Point(localPosition[0], localPosition[1]), isClipPath, _this.isPointInPath, runtime)) {
|
|
1922
|
+
if (pick(displayObject, new gLite.Point(localPosition[0], localPosition[1]), isClipPath, _this.isPointInPath, _this.context, _this.runtime)) {
|
|
1924
1923
|
return true;
|
|
1925
1924
|
}
|
|
1926
1925
|
}
|
|
@@ -1930,9 +1929,9 @@
|
|
|
1930
1929
|
* use native picking method
|
|
1931
1930
|
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/isPointInPath
|
|
1932
1931
|
*/
|
|
1933
|
-
this.isPointInPath = function (
|
|
1934
|
-
var context = runtime.offscreenCanvas.getOrCreateContext(_this.
|
|
1935
|
-
var generatePath = _this.pathGeneratorFactory[displayObject.nodeName];
|
|
1932
|
+
this.isPointInPath = function (displayObject, position) {
|
|
1933
|
+
var context = _this.runtime.offscreenCanvas.getOrCreateContext(_this.context.config.offscreenCanvas);
|
|
1934
|
+
var generatePath = _this.context.pathGeneratorFactory[displayObject.nodeName];
|
|
1936
1935
|
if (generatePath) {
|
|
1937
1936
|
context.beginPath();
|
|
1938
1937
|
generatePath(context, displayObject.parsedStyle);
|
|
@@ -1945,21 +1944,17 @@
|
|
|
1945
1944
|
_proto.apply = function apply(context, runtime) {
|
|
1946
1945
|
var _renderingContext$roo,
|
|
1947
1946
|
_this2 = this;
|
|
1948
|
-
var
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
pointInPathPickerFactory = context.pointInPathPickerFactory;
|
|
1953
|
-
this.canvasConfig = config;
|
|
1954
|
-
this.pathGeneratorFactory = pathGeneratorFactory;
|
|
1955
|
-
this.pointInPathPickerFactory = pointInPathPickerFactory;
|
|
1947
|
+
var renderingService = context.renderingService,
|
|
1948
|
+
renderingContext = context.renderingContext;
|
|
1949
|
+
this.context = context;
|
|
1950
|
+
this.runtime = runtime;
|
|
1956
1951
|
var document = (_renderingContext$roo = renderingContext.root) === null || _renderingContext$roo === void 0 ? void 0 : _renderingContext$roo.ownerDocument;
|
|
1957
1952
|
renderingService.hooks.pick.tapPromise(CanvasPickerPlugin.tag, /*#__PURE__*/function () {
|
|
1958
1953
|
var _ref = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee(result) {
|
|
1959
1954
|
return _regeneratorRuntime$1().wrap(function _callee$(_context) {
|
|
1960
1955
|
while (1) switch (_context.prev = _context.next) {
|
|
1961
1956
|
case 0:
|
|
1962
|
-
return _context.abrupt("return", _this2.pick(document, result
|
|
1957
|
+
return _context.abrupt("return", _this2.pick(document, result));
|
|
1963
1958
|
case 1:
|
|
1964
1959
|
case "end":
|
|
1965
1960
|
return _context.stop();
|
|
@@ -1971,10 +1966,10 @@
|
|
|
1971
1966
|
};
|
|
1972
1967
|
}());
|
|
1973
1968
|
renderingService.hooks.pickSync.tap(CanvasPickerPlugin.tag, function (result) {
|
|
1974
|
-
return _this2.pick(document, result
|
|
1969
|
+
return _this2.pick(document, result);
|
|
1975
1970
|
});
|
|
1976
1971
|
};
|
|
1977
|
-
_proto.pick = function pick(document, result
|
|
1972
|
+
_proto.pick = function pick(document, result) {
|
|
1978
1973
|
var topmost = result.topmost,
|
|
1979
1974
|
_result$position = result.position,
|
|
1980
1975
|
x = _result$position.x,
|
|
@@ -1989,13 +1984,13 @@
|
|
|
1989
1984
|
for (var _iterator = _createForOfIteratorHelperLoose(hitTestList), _step; !(_step = _iterator()).done;) {
|
|
1990
1985
|
var displayObject = _step.value;
|
|
1991
1986
|
var worldTransform = displayObject.getWorldTransform();
|
|
1992
|
-
var isHitOriginShape = this.isHit(displayObject, position, worldTransform, false
|
|
1987
|
+
var isHitOriginShape = this.isHit(displayObject, position, worldTransform, false);
|
|
1993
1988
|
if (isHitOriginShape) {
|
|
1994
1989
|
// should look up in the ancestor node
|
|
1995
1990
|
var clipped = gLite.findClosestClipPathTarget(displayObject);
|
|
1996
1991
|
if (clipped) {
|
|
1997
1992
|
var clipPath = clipped.parsedStyle.clipPath;
|
|
1998
|
-
var isHitClipPath = this.isHit(clipPath, position, clipPath.getWorldTransform(), true
|
|
1993
|
+
var isHitClipPath = this.isHit(clipPath, position, clipPath.getWorldTransform(), true);
|
|
1999
1994
|
if (isHitClipPath) {
|
|
2000
1995
|
if (topmost) {
|
|
2001
1996
|
result.picked = [displayObject];
|
|
@@ -2683,7 +2678,7 @@
|
|
|
2683
2678
|
}
|
|
2684
2679
|
return isHit;
|
|
2685
2680
|
}
|
|
2686
|
-
function isPointInPath$3(displayObject, position, isClipPath, isPointInPath, runtime) {
|
|
2681
|
+
function isPointInPath$3(displayObject, position, isClipPath, isPointInPath, renderingPluginContext, runtime) {
|
|
2687
2682
|
var _displayObject$parsed = displayObject.parsedStyle,
|
|
2688
2683
|
lineWidth = _displayObject$parsed.lineWidth,
|
|
2689
2684
|
increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
|
|
@@ -2709,7 +2704,7 @@
|
|
|
2709
2704
|
if (hasFill || isClipPath) {
|
|
2710
2705
|
if (hasArc) {
|
|
2711
2706
|
// 存在曲线时,暂时使用 canvas 的 api 计算,后续可以进行多边形切割
|
|
2712
|
-
isHit = isPointInPath(
|
|
2707
|
+
isHit = isPointInPath(displayObject, position);
|
|
2713
2708
|
} else {
|
|
2714
2709
|
// 提取出来的多边形包含闭合的和非闭合的,在这里统一按照多边形处理
|
|
2715
2710
|
isHit = inPolygons(polygons, position.x + x, position.y + y) || inPolygons(polylines, position.x + x, position.y + y);
|
|
@@ -2804,7 +2799,7 @@
|
|
|
2804
2799
|
// 仅填充时带有圆角的矩形直接通过图形拾取
|
|
2805
2800
|
// 以后可以改成纯数学的近似拾取,将圆弧切割成多边形
|
|
2806
2801
|
if (!isHit && (hasFill || isClipPath)) {
|
|
2807
|
-
isHit = isPointInPath(
|
|
2802
|
+
isHit = isPointInPath(displayObject, position);
|
|
2808
2803
|
}
|
|
2809
2804
|
return isHit;
|
|
2810
2805
|
}
|
|
@@ -2817,6 +2812,27 @@
|
|
|
2817
2812
|
blr = radiusArray[3];
|
|
2818
2813
|
return inLine(minX + tlr, minY, minX + width - trr, minY, lineWidth, x, y) || inLine(minX + width, minY + trr, minX + width, minY + height - brr, lineWidth, x, y) || inLine(minX + width - brr, minY + height, minX + blr, minY + height, lineWidth, x, y) || inLine(minX, minY + height - blr, minX, minY + tlr, lineWidth, x, y) || inArc(minX + width - trr, minY + trr, trr, 1.5 * Math.PI, 2 * Math.PI, lineWidth, x, y) || inArc(minX + width - brr, minY + height - brr, brr, 0, 0.5 * Math.PI, lineWidth, x, y) || inArc(minX + blr, minY + height - blr, blr, 0.5 * Math.PI, Math.PI, lineWidth, x, y) || inArc(minX + tlr, minY + tlr, tlr, Math.PI, 1.5 * Math.PI, lineWidth, x, y);
|
|
2819
2814
|
}
|
|
2815
|
+
function isPointInPath$7(displayObject, position, isClipPath, isPointInPath, renderingPluginContext, runtime) {
|
|
2816
|
+
var _displayObject$parsed = displayObject.parsedStyle,
|
|
2817
|
+
pointerEvents = _displayObject$parsed.pointerEvents,
|
|
2818
|
+
width = _displayObject$parsed.width,
|
|
2819
|
+
height = _displayObject$parsed.height;
|
|
2820
|
+
if (pointerEvents === 'non-transparent-pixel') {
|
|
2821
|
+
var offscreenCanvas = renderingPluginContext.config.offscreenCanvas;
|
|
2822
|
+
var canvas = runtime.offscreenCanvas.getOrCreateCanvas(offscreenCanvas);
|
|
2823
|
+
var context = runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas, {
|
|
2824
|
+
willReadFrequently: true
|
|
2825
|
+
});
|
|
2826
|
+
canvas.width = width;
|
|
2827
|
+
canvas.height = height;
|
|
2828
|
+
renderingPluginContext.defaultStyleRendererFactory[gLite.Shape.IMAGE].render(context, displayObject.parsedStyle, displayObject, undefined, undefined, undefined);
|
|
2829
|
+
var imagedata = context.getImageData(position.x, position.y, 1, 1).data;
|
|
2830
|
+
return imagedata.every(function (component) {
|
|
2831
|
+
return component !== 0;
|
|
2832
|
+
});
|
|
2833
|
+
}
|
|
2834
|
+
return true;
|
|
2835
|
+
}
|
|
2820
2836
|
var Plugin$1 = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
2821
2837
|
_inheritsLoose$2(Plugin, _AbstractRendererPlug);
|
|
2822
2838
|
function Plugin() {
|
|
@@ -2834,7 +2850,7 @@
|
|
|
2834
2850
|
var trueFunc = function trueFunc() {
|
|
2835
2851
|
return true;
|
|
2836
2852
|
};
|
|
2837
|
-
var pointInPathPickerFactory = (_pointInPathPickerFac = {}, _pointInPathPickerFac[gLite.Shape.CIRCLE] = isPointInPath, _pointInPathPickerFac[gLite.Shape.ELLIPSE] = isPointInPath$1, _pointInPathPickerFac[gLite.Shape.RECT] = isPointInPath$6, _pointInPathPickerFac[gLite.Shape.LINE] = isPointInPath$2, _pointInPathPickerFac[gLite.Shape.POLYLINE] = isPointInPath$5, _pointInPathPickerFac[gLite.Shape.POLYGON] = isPointInPath$4, _pointInPathPickerFac[gLite.Shape.PATH] = isPointInPath$3, _pointInPathPickerFac[gLite.Shape.TEXT] = trueFunc, _pointInPathPickerFac[gLite.Shape.GROUP] = null, _pointInPathPickerFac[gLite.Shape.IMAGE] =
|
|
2853
|
+
var pointInPathPickerFactory = (_pointInPathPickerFac = {}, _pointInPathPickerFac[gLite.Shape.CIRCLE] = isPointInPath, _pointInPathPickerFac[gLite.Shape.ELLIPSE] = isPointInPath$1, _pointInPathPickerFac[gLite.Shape.RECT] = isPointInPath$6, _pointInPathPickerFac[gLite.Shape.LINE] = isPointInPath$2, _pointInPathPickerFac[gLite.Shape.POLYLINE] = isPointInPath$5, _pointInPathPickerFac[gLite.Shape.POLYGON] = isPointInPath$4, _pointInPathPickerFac[gLite.Shape.PATH] = isPointInPath$3, _pointInPathPickerFac[gLite.Shape.TEXT] = trueFunc, _pointInPathPickerFac[gLite.Shape.GROUP] = null, _pointInPathPickerFac[gLite.Shape.IMAGE] = isPointInPath$7, _pointInPathPickerFac[gLite.Shape.HTML] = null, _pointInPathPickerFac[gLite.Shape.MESH] = null, _pointInPathPickerFac);
|
|
2838
2854
|
// @ts-ignore
|
|
2839
2855
|
this.context.pointInPathPickerFactory = pointInPathPickerFactory;
|
|
2840
2856
|
this.addRenderingPlugin(new CanvasPickerPlugin());
|
|
@@ -2852,2389 +2868,1072 @@
|
|
|
2852
2868
|
Plugin: Plugin$1
|
|
2853
2869
|
});
|
|
2854
2870
|
|
|
2855
|
-
function
|
|
2856
|
-
|
|
2857
|
-
|
|
2871
|
+
function _extends() {
|
|
2872
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
2873
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
2874
|
+
var source = arguments[i];
|
|
2875
|
+
for (var key in source) {
|
|
2876
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
2877
|
+
target[key] = source[key];
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2881
|
+
return target;
|
|
2858
2882
|
};
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2883
|
+
return _extends.apply(this, arguments);
|
|
2884
|
+
}
|
|
2885
|
+
function _inheritsLoose$3(subClass, superClass) {
|
|
2886
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
2887
|
+
subClass.prototype.constructor = subClass;
|
|
2888
|
+
_setPrototypeOf$3(subClass, superClass);
|
|
2889
|
+
}
|
|
2890
|
+
function _setPrototypeOf$3(o, p) {
|
|
2891
|
+
_setPrototypeOf$3 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
2892
|
+
o.__proto__ = p;
|
|
2893
|
+
return o;
|
|
2894
|
+
};
|
|
2895
|
+
return _setPrototypeOf$3(o, p);
|
|
2896
|
+
}
|
|
2897
|
+
|
|
2898
|
+
/**
|
|
2899
|
+
* support 2 modes in rendering:
|
|
2900
|
+
* * immediate
|
|
2901
|
+
* * delayed: render at the end of frame with dirty-rectangle
|
|
2902
|
+
*/
|
|
2903
|
+
var CanvasRendererPlugin = /*#__PURE__*/function () {
|
|
2904
|
+
function CanvasRendererPlugin(canvasRendererPluginOptions) {
|
|
2905
|
+
this.canvasRendererPluginOptions = void 0;
|
|
2906
|
+
this.context = void 0;
|
|
2907
|
+
this.pathGeneratorFactory = void 0;
|
|
2908
|
+
/**
|
|
2909
|
+
* RBush used in dirty rectangle rendering
|
|
2910
|
+
*/
|
|
2911
|
+
this.rBush = void 0;
|
|
2912
|
+
this.removedRBushNodeAABBs = [];
|
|
2913
|
+
this.renderQueue = [];
|
|
2914
|
+
/**
|
|
2915
|
+
* This stack is only used by clipPath for now.
|
|
2916
|
+
*/
|
|
2917
|
+
this.restoreStack = [];
|
|
2918
|
+
this.clearFullScreen = false;
|
|
2919
|
+
/**
|
|
2920
|
+
* view projection matrix
|
|
2921
|
+
*/
|
|
2922
|
+
this.vpMatrix = create();
|
|
2923
|
+
this.dprMatrix = create();
|
|
2924
|
+
this.tmpMat4 = create();
|
|
2925
|
+
this.vec3a = create$1();
|
|
2926
|
+
this.vec3b = create$1();
|
|
2927
|
+
this.vec3c = create$1();
|
|
2928
|
+
this.vec3d = create$1();
|
|
2929
|
+
this.canvasRendererPluginOptions = canvasRendererPluginOptions;
|
|
2876
2930
|
}
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2931
|
+
var _proto = CanvasRendererPlugin.prototype;
|
|
2932
|
+
_proto.apply = function apply(context, runtime) {
|
|
2933
|
+
var _this = this;
|
|
2934
|
+
this.context = context;
|
|
2935
|
+
var config = context.config,
|
|
2936
|
+
camera = context.camera,
|
|
2937
|
+
renderingService = context.renderingService,
|
|
2938
|
+
renderingContext = context.renderingContext,
|
|
2939
|
+
rBushRoot = context.rBushRoot,
|
|
2940
|
+
pathGeneratorFactory = context.pathGeneratorFactory;
|
|
2941
|
+
this.rBush = rBushRoot;
|
|
2942
|
+
this.pathGeneratorFactory = pathGeneratorFactory;
|
|
2943
|
+
var contextService = context.contextService;
|
|
2944
|
+
var canvas = renderingContext.root.ownerDocument.defaultView;
|
|
2945
|
+
var handleUnmounted = function handleUnmounted(e) {
|
|
2946
|
+
var object = e.target;
|
|
2947
|
+
// remove r-bush node
|
|
2948
|
+
// @ts-ignore
|
|
2949
|
+
var rBushNode = object.rBushNode;
|
|
2950
|
+
if (rBushNode.aabb) {
|
|
2951
|
+
// save removed aabbs for dirty-rectangle rendering later
|
|
2952
|
+
_this.removedRBushNodeAABBs.push(rBushNode.aabb);
|
|
2953
|
+
}
|
|
2882
2954
|
};
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
}), generator;
|
|
2891
|
-
}
|
|
2892
|
-
function tryCatch(fn, obj, arg) {
|
|
2893
|
-
try {
|
|
2894
|
-
return {
|
|
2895
|
-
type: "normal",
|
|
2896
|
-
arg: fn.call(obj, arg)
|
|
2897
|
-
};
|
|
2898
|
-
} catch (err) {
|
|
2899
|
-
return {
|
|
2900
|
-
type: "throw",
|
|
2901
|
-
arg: err
|
|
2902
|
-
};
|
|
2903
|
-
}
|
|
2904
|
-
}
|
|
2905
|
-
exports.wrap = wrap;
|
|
2906
|
-
var ContinueSentinel = {};
|
|
2907
|
-
function Generator() {}
|
|
2908
|
-
function GeneratorFunction() {}
|
|
2909
|
-
function GeneratorFunctionPrototype() {}
|
|
2910
|
-
var IteratorPrototype = {};
|
|
2911
|
-
define(IteratorPrototype, iteratorSymbol, function () {
|
|
2912
|
-
return this;
|
|
2913
|
-
});
|
|
2914
|
-
var getProto = Object.getPrototypeOf,
|
|
2915
|
-
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
2916
|
-
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
|
|
2917
|
-
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
2918
|
-
function defineIteratorMethods(prototype) {
|
|
2919
|
-
["next", "throw", "return"].forEach(function (method) {
|
|
2920
|
-
define(prototype, method, function (arg) {
|
|
2921
|
-
return this._invoke(method, arg);
|
|
2922
|
-
});
|
|
2923
|
-
});
|
|
2924
|
-
}
|
|
2925
|
-
function AsyncIterator(generator, PromiseImpl) {
|
|
2926
|
-
function invoke(method, arg, resolve, reject) {
|
|
2927
|
-
var record = tryCatch(generator[method], generator, arg);
|
|
2928
|
-
if ("throw" !== record.type) {
|
|
2929
|
-
var result = record.arg,
|
|
2930
|
-
value = result.value;
|
|
2931
|
-
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
|
|
2932
|
-
invoke("next", value, resolve, reject);
|
|
2933
|
-
}, function (err) {
|
|
2934
|
-
invoke("throw", err, resolve, reject);
|
|
2935
|
-
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
|
|
2936
|
-
result.value = unwrapped, resolve(result);
|
|
2937
|
-
}, function (error) {
|
|
2938
|
-
return invoke("throw", error, resolve, reject);
|
|
2939
|
-
});
|
|
2955
|
+
var handleCulled = function handleCulled(e) {
|
|
2956
|
+
var object = e.target;
|
|
2957
|
+
// @ts-ignore
|
|
2958
|
+
var rBushNode = object.rBushNode;
|
|
2959
|
+
if (rBushNode.aabb) {
|
|
2960
|
+
// save removed aabbs for dirty-rectangle rendering later
|
|
2961
|
+
_this.removedRBushNodeAABBs.push(rBushNode.aabb);
|
|
2940
2962
|
}
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2963
|
+
};
|
|
2964
|
+
renderingService.hooks.init.tap(CanvasRendererPlugin.tag, function () {
|
|
2965
|
+
canvas.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
|
|
2966
|
+
canvas.addEventListener(gLite.ElementEvent.CULLED, handleCulled);
|
|
2967
|
+
// clear fullscreen
|
|
2968
|
+
var dpr = contextService.getDPR();
|
|
2969
|
+
var width = config.width,
|
|
2970
|
+
height = config.height;
|
|
2971
|
+
var context = contextService.getContext();
|
|
2972
|
+
_this.clearRect(context, 0, 0, width * dpr, height * dpr, config.background);
|
|
2973
|
+
});
|
|
2974
|
+
renderingService.hooks.destroy.tap(CanvasRendererPlugin.tag, function () {
|
|
2975
|
+
canvas.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
|
|
2976
|
+
canvas.removeEventListener(gLite.ElementEvent.CULLED, handleCulled);
|
|
2977
|
+
// this.renderQueue = [];
|
|
2978
|
+
// this.removedRBushNodeAABBs = [];
|
|
2979
|
+
// this.restoreStack = [];
|
|
2980
|
+
});
|
|
2981
|
+
|
|
2982
|
+
renderingService.hooks.beginFrame.tap(CanvasRendererPlugin.tag, function () {
|
|
2983
|
+
var context = contextService.getContext();
|
|
2984
|
+
var dpr = contextService.getDPR();
|
|
2985
|
+
var width = config.width,
|
|
2986
|
+
height = config.height;
|
|
2987
|
+
var _this$canvasRendererP = _this.canvasRendererPluginOptions,
|
|
2988
|
+
dirtyObjectNumThreshold = _this$canvasRendererP.dirtyObjectNumThreshold,
|
|
2989
|
+
dirtyObjectRatioThreshold = _this$canvasRendererP.dirtyObjectRatioThreshold;
|
|
2990
|
+
// some heuristic conditions such as 80% object changed
|
|
2991
|
+
var _renderingService$get = renderingService.getStats(),
|
|
2992
|
+
total = _renderingService$get.total,
|
|
2993
|
+
rendered = _renderingService$get.rendered;
|
|
2994
|
+
var ratio = rendered / total;
|
|
2995
|
+
_this.clearFullScreen = renderingService.disableDirtyRectangleRendering() || rendered > dirtyObjectNumThreshold && ratio > dirtyObjectRatioThreshold;
|
|
2996
|
+
if (context) {
|
|
2997
|
+
context.resetTransform ? context.resetTransform() : context.setTransform(1, 0, 0, 1, 0, 0);
|
|
2998
|
+
if (_this.clearFullScreen) {
|
|
2999
|
+
_this.clearRect(context, 0, 0, width * dpr, height * dpr, config.background);
|
|
2950
3000
|
}
|
|
2951
|
-
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
2952
3001
|
}
|
|
2953
3002
|
});
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
return doneResult();
|
|
3003
|
+
var renderByZIndex = function renderByZIndex(object, context) {
|
|
3004
|
+
if (object.isVisible() && !object.isCulled()) {
|
|
3005
|
+
_this.renderDisplayObject(object, context, _this.context, _this.restoreStack, runtime);
|
|
3006
|
+
// if (object.renderable.) {
|
|
3007
|
+
// if we did a full screen rendering last frame
|
|
3008
|
+
_this.saveDirtyAABB(object);
|
|
3009
|
+
// }
|
|
2962
3010
|
}
|
|
2963
|
-
for (context.method = method, context.arg = arg;;) {
|
|
2964
|
-
var delegate = context.delegate;
|
|
2965
|
-
if (delegate) {
|
|
2966
|
-
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
2967
|
-
if (delegateResult) {
|
|
2968
|
-
if (delegateResult === ContinueSentinel) continue;
|
|
2969
|
-
return delegateResult;
|
|
2970
|
-
}
|
|
2971
|
-
}
|
|
2972
|
-
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
|
|
2973
|
-
if ("suspendedStart" === state) throw state = "completed", context.arg;
|
|
2974
|
-
context.dispatchException(context.arg);
|
|
2975
|
-
} else "return" === context.method && context.abrupt("return", context.arg);
|
|
2976
|
-
state = "executing";
|
|
2977
|
-
var record = tryCatch(innerFn, self, context);
|
|
2978
|
-
if ("normal" === record.type) {
|
|
2979
|
-
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
|
|
2980
|
-
return {
|
|
2981
|
-
value: record.arg,
|
|
2982
|
-
done: context.done
|
|
2983
|
-
};
|
|
2984
|
-
}
|
|
2985
|
-
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
|
|
2986
|
-
}
|
|
2987
|
-
};
|
|
2988
|
-
}
|
|
2989
|
-
function maybeInvokeDelegate(delegate, context) {
|
|
2990
|
-
var methodName = context.method,
|
|
2991
|
-
method = delegate.iterator[methodName];
|
|
2992
|
-
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
|
|
2993
|
-
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
2994
|
-
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
|
|
2995
|
-
var info = record.arg;
|
|
2996
|
-
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
|
|
2997
|
-
}
|
|
2998
|
-
function pushTryEntry(locs) {
|
|
2999
|
-
var entry = {
|
|
3000
|
-
tryLoc: locs[0]
|
|
3001
|
-
};
|
|
3002
|
-
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
|
|
3003
|
-
}
|
|
3004
|
-
function resetTryEntry(entry) {
|
|
3005
|
-
var record = entry.completion || {};
|
|
3006
|
-
record.type = "normal", delete record.arg, entry.completion = record;
|
|
3007
|
-
}
|
|
3008
|
-
function Context(tryLocsList) {
|
|
3009
|
-
this.tryEntries = [{
|
|
3010
|
-
tryLoc: "root"
|
|
3011
|
-
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
|
|
3012
|
-
}
|
|
3013
|
-
function values(iterable) {
|
|
3014
|
-
if (iterable) {
|
|
3015
|
-
var iteratorMethod = iterable[iteratorSymbol];
|
|
3016
|
-
if (iteratorMethod) return iteratorMethod.call(iterable);
|
|
3017
|
-
if ("function" == typeof iterable.next) return iterable;
|
|
3018
|
-
if (!isNaN(iterable.length)) {
|
|
3019
|
-
var i = -1,
|
|
3020
|
-
next = function next() {
|
|
3021
|
-
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
|
3022
|
-
return next.value = undefined, next.done = !0, next;
|
|
3023
|
-
};
|
|
3024
|
-
return next.next = next;
|
|
3025
|
-
}
|
|
3026
|
-
}
|
|
3027
|
-
return {
|
|
3028
|
-
next: doneResult
|
|
3029
|
-
};
|
|
3030
|
-
}
|
|
3031
|
-
function doneResult() {
|
|
3032
|
-
return {
|
|
3033
|
-
value: undefined,
|
|
3034
|
-
done: !0
|
|
3035
|
-
};
|
|
3036
|
-
}
|
|
3037
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
|
|
3038
|
-
value: GeneratorFunctionPrototype,
|
|
3039
|
-
configurable: !0
|
|
3040
|
-
}), defineProperty(GeneratorFunctionPrototype, "constructor", {
|
|
3041
|
-
value: GeneratorFunction,
|
|
3042
|
-
configurable: !0
|
|
3043
|
-
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
|
|
3044
|
-
var ctor = "function" == typeof genFun && genFun.constructor;
|
|
3045
|
-
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
|
|
3046
|
-
}, exports.mark = function (genFun) {
|
|
3047
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
|
|
3048
|
-
}, exports.awrap = function (arg) {
|
|
3049
|
-
return {
|
|
3050
|
-
__await: arg
|
|
3051
|
-
};
|
|
3052
|
-
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
3053
|
-
return this;
|
|
3054
|
-
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
3055
|
-
void 0 === PromiseImpl && (PromiseImpl = Promise);
|
|
3056
|
-
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
|
|
3057
|
-
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
|
|
3058
|
-
return result.done ? result.value : iter.next();
|
|
3059
|
-
});
|
|
3060
|
-
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
|
|
3061
|
-
return this;
|
|
3062
|
-
}), define(Gp, "toString", function () {
|
|
3063
|
-
return "[object Generator]";
|
|
3064
|
-
}), exports.keys = function (val) {
|
|
3065
|
-
var object = Object(val),
|
|
3066
|
-
keys = [];
|
|
3067
|
-
for (var key in object) keys.push(key);
|
|
3068
|
-
return keys.reverse(), function next() {
|
|
3069
|
-
for (; keys.length;) {
|
|
3070
|
-
var key = keys.pop();
|
|
3071
|
-
if (key in object) return next.value = key, next.done = !1, next;
|
|
3072
|
-
}
|
|
3073
|
-
return next.done = !0, next;
|
|
3074
|
-
};
|
|
3075
|
-
}, exports.values = values, Context.prototype = {
|
|
3076
|
-
constructor: Context,
|
|
3077
|
-
reset: function reset(skipTempReset) {
|
|
3078
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
|
|
3079
|
-
},
|
|
3080
|
-
stop: function stop() {
|
|
3081
|
-
this.done = !0;
|
|
3082
|
-
var rootRecord = this.tryEntries[0].completion;
|
|
3083
|
-
if ("throw" === rootRecord.type) throw rootRecord.arg;
|
|
3084
|
-
return this.rval;
|
|
3085
|
-
},
|
|
3086
|
-
dispatchException: function dispatchException(exception) {
|
|
3087
|
-
if (this.done) throw exception;
|
|
3088
|
-
var context = this;
|
|
3089
|
-
function handle(loc, caught) {
|
|
3090
|
-
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
|
|
3091
|
-
}
|
|
3092
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
3093
|
-
var entry = this.tryEntries[i],
|
|
3094
|
-
record = entry.completion;
|
|
3095
|
-
if ("root" === entry.tryLoc) return handle("end");
|
|
3096
|
-
if (entry.tryLoc <= this.prev) {
|
|
3097
|
-
var hasCatch = hasOwn.call(entry, "catchLoc"),
|
|
3098
|
-
hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
3099
|
-
if (hasCatch && hasFinally) {
|
|
3100
|
-
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
3101
|
-
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
3102
|
-
} else if (hasCatch) {
|
|
3103
|
-
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
3104
|
-
} else {
|
|
3105
|
-
if (!hasFinally) throw new Error("try statement without catch or finally");
|
|
3106
|
-
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
3107
|
-
}
|
|
3108
|
-
}
|
|
3109
|
-
}
|
|
3110
|
-
},
|
|
3111
|
-
abrupt: function abrupt(type, arg) {
|
|
3112
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
3113
|
-
var entry = this.tryEntries[i];
|
|
3114
|
-
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
|
3115
|
-
var finallyEntry = entry;
|
|
3116
|
-
break;
|
|
3117
|
-
}
|
|
3118
|
-
}
|
|
3119
|
-
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
|
|
3120
|
-
var record = finallyEntry ? finallyEntry.completion : {};
|
|
3121
|
-
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
|
|
3122
|
-
},
|
|
3123
|
-
complete: function complete(record, afterLoc) {
|
|
3124
|
-
if ("throw" === record.type) throw record.arg;
|
|
3125
|
-
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
|
|
3126
|
-
},
|
|
3127
|
-
finish: function finish(finallyLoc) {
|
|
3128
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
3129
|
-
var entry = this.tryEntries[i];
|
|
3130
|
-
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
|
|
3131
|
-
}
|
|
3132
|
-
},
|
|
3133
|
-
catch: function _catch(tryLoc) {
|
|
3134
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
3135
|
-
var entry = this.tryEntries[i];
|
|
3136
|
-
if (entry.tryLoc === tryLoc) {
|
|
3137
|
-
var record = entry.completion;
|
|
3138
|
-
if ("throw" === record.type) {
|
|
3139
|
-
var thrown = record.arg;
|
|
3140
|
-
resetTryEntry(entry);
|
|
3141
|
-
}
|
|
3142
|
-
return thrown;
|
|
3143
|
-
}
|
|
3144
|
-
}
|
|
3145
|
-
throw new Error("illegal catch attempt");
|
|
3146
|
-
},
|
|
3147
|
-
delegateYield: function delegateYield(iterable, resultName, nextLoc) {
|
|
3148
|
-
return this.delegate = {
|
|
3149
|
-
iterator: values(iterable),
|
|
3150
|
-
resultName: resultName,
|
|
3151
|
-
nextLoc: nextLoc
|
|
3152
|
-
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
|
|
3153
|
-
}
|
|
3154
|
-
}, exports;
|
|
3155
|
-
}
|
|
3156
|
-
function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
|
|
3157
|
-
try {
|
|
3158
|
-
var info = gen[key](arg);
|
|
3159
|
-
var value = info.value;
|
|
3160
|
-
} catch (error) {
|
|
3161
|
-
reject(error);
|
|
3162
|
-
return;
|
|
3163
|
-
}
|
|
3164
|
-
if (info.done) {
|
|
3165
|
-
resolve(value);
|
|
3166
|
-
} else {
|
|
3167
|
-
Promise.resolve(value).then(_next, _throw);
|
|
3168
|
-
}
|
|
3169
|
-
}
|
|
3170
|
-
function _asyncToGenerator$2(fn) {
|
|
3171
|
-
return function () {
|
|
3172
|
-
var self = this,
|
|
3173
|
-
args = arguments;
|
|
3174
|
-
return new Promise(function (resolve, reject) {
|
|
3175
|
-
var gen = fn.apply(self, args);
|
|
3176
|
-
function _next(value) {
|
|
3177
|
-
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
|
|
3178
|
-
}
|
|
3179
|
-
function _throw(err) {
|
|
3180
|
-
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
|
|
3181
|
-
}
|
|
3182
|
-
_next(undefined);
|
|
3183
|
-
});
|
|
3184
|
-
};
|
|
3185
|
-
}
|
|
3186
|
-
function _extends() {
|
|
3187
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
3188
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
3189
|
-
var source = arguments[i];
|
|
3190
|
-
for (var key in source) {
|
|
3191
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
3192
|
-
target[key] = source[key];
|
|
3193
|
-
}
|
|
3194
|
-
}
|
|
3195
|
-
}
|
|
3196
|
-
return target;
|
|
3197
|
-
};
|
|
3198
|
-
return _extends.apply(this, arguments);
|
|
3199
|
-
}
|
|
3200
|
-
function _inheritsLoose$3(subClass, superClass) {
|
|
3201
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
3202
|
-
subClass.prototype.constructor = subClass;
|
|
3203
|
-
_setPrototypeOf$3(subClass, superClass);
|
|
3204
|
-
}
|
|
3205
|
-
function _setPrototypeOf$3(o, p) {
|
|
3206
|
-
_setPrototypeOf$3 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
3207
|
-
o.__proto__ = p;
|
|
3208
|
-
return o;
|
|
3209
|
-
};
|
|
3210
|
-
return _setPrototypeOf$3(o, p);
|
|
3211
|
-
}
|
|
3212
|
-
|
|
3213
|
-
/**
|
|
3214
|
-
* support 2 modes in rendering:
|
|
3215
|
-
* * immediate
|
|
3216
|
-
* * delayed: render at the end of frame with dirty-rectangle
|
|
3217
|
-
*/
|
|
3218
|
-
var CanvasRendererPlugin = /*#__PURE__*/function () {
|
|
3219
|
-
function CanvasRendererPlugin(canvasRendererPluginOptions) {
|
|
3220
|
-
this.canvasRendererPluginOptions = void 0;
|
|
3221
|
-
this.context = void 0;
|
|
3222
|
-
this.pathGeneratorFactory = void 0;
|
|
3223
|
-
/**
|
|
3224
|
-
* RBush used in dirty rectangle rendering
|
|
3225
|
-
*/
|
|
3226
|
-
this.rBush = void 0;
|
|
3227
|
-
this.removedRBushNodeAABBs = [];
|
|
3228
|
-
this.renderQueue = [];
|
|
3229
|
-
/**
|
|
3230
|
-
* This stack is only used by clipPath for now.
|
|
3231
|
-
*/
|
|
3232
|
-
this.restoreStack = [];
|
|
3233
|
-
this.clearFullScreen = false;
|
|
3234
|
-
/**
|
|
3235
|
-
* view projection matrix
|
|
3236
|
-
*/
|
|
3237
|
-
this.vpMatrix = create();
|
|
3238
|
-
this.dprMatrix = create();
|
|
3239
|
-
this.tmpMat4 = create();
|
|
3240
|
-
this.vec3a = create$1();
|
|
3241
|
-
this.vec3b = create$1();
|
|
3242
|
-
this.vec3c = create$1();
|
|
3243
|
-
this.vec3d = create$1();
|
|
3244
|
-
this.canvasRendererPluginOptions = canvasRendererPluginOptions;
|
|
3245
|
-
}
|
|
3246
|
-
var _proto = CanvasRendererPlugin.prototype;
|
|
3247
|
-
_proto.apply = function apply(context, runtime) {
|
|
3248
|
-
var _this = this;
|
|
3249
|
-
this.context = context;
|
|
3250
|
-
var config = context.config,
|
|
3251
|
-
camera = context.camera,
|
|
3252
|
-
renderingService = context.renderingService,
|
|
3253
|
-
renderingContext = context.renderingContext,
|
|
3254
|
-
rBushRoot = context.rBushRoot,
|
|
3255
|
-
pathGeneratorFactory = context.pathGeneratorFactory;
|
|
3256
|
-
this.rBush = rBushRoot;
|
|
3257
|
-
this.pathGeneratorFactory = pathGeneratorFactory;
|
|
3258
|
-
var contextService = context.contextService;
|
|
3259
|
-
var canvas = renderingContext.root.ownerDocument.defaultView;
|
|
3260
|
-
var handleUnmounted = function handleUnmounted(e) {
|
|
3261
|
-
var object = e.target;
|
|
3262
|
-
// remove r-bush node
|
|
3263
|
-
// @ts-ignore
|
|
3264
|
-
var rBushNode = object.rBushNode;
|
|
3265
|
-
if (rBushNode.aabb) {
|
|
3266
|
-
// save removed aabbs for dirty-rectangle rendering later
|
|
3267
|
-
_this.removedRBushNodeAABBs.push(rBushNode.aabb);
|
|
3268
|
-
}
|
|
3269
|
-
};
|
|
3270
|
-
var handleCulled = function handleCulled(e) {
|
|
3271
|
-
var object = e.target;
|
|
3272
|
-
// @ts-ignore
|
|
3273
|
-
var rBushNode = object.rBushNode;
|
|
3274
|
-
if (rBushNode.aabb) {
|
|
3275
|
-
// save removed aabbs for dirty-rectangle rendering later
|
|
3276
|
-
_this.removedRBushNodeAABBs.push(rBushNode.aabb);
|
|
3277
|
-
}
|
|
3278
|
-
};
|
|
3279
|
-
renderingService.hooks.init.tapPromise(CanvasRendererPlugin.tag, /*#__PURE__*/_asyncToGenerator$2( /*#__PURE__*/_regeneratorRuntime$2().mark(function _callee() {
|
|
3280
|
-
var dpr, width, height, context;
|
|
3281
|
-
return _regeneratorRuntime$2().wrap(function _callee$(_context) {
|
|
3282
|
-
while (1) switch (_context.prev = _context.next) {
|
|
3283
|
-
case 0:
|
|
3284
|
-
canvas.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
|
|
3285
|
-
canvas.addEventListener(gLite.ElementEvent.CULLED, handleCulled);
|
|
3286
|
-
// clear fullscreen
|
|
3287
|
-
dpr = contextService.getDPR();
|
|
3288
|
-
width = config.width, height = config.height;
|
|
3289
|
-
context = contextService.getContext();
|
|
3290
|
-
_this.clearRect(context, 0, 0, width * dpr, height * dpr, config.background);
|
|
3291
|
-
case 6:
|
|
3292
|
-
case "end":
|
|
3293
|
-
return _context.stop();
|
|
3294
|
-
}
|
|
3295
|
-
}, _callee);
|
|
3296
|
-
})));
|
|
3297
|
-
renderingService.hooks.destroy.tap(CanvasRendererPlugin.tag, function () {
|
|
3298
|
-
canvas.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
|
|
3299
|
-
canvas.removeEventListener(gLite.ElementEvent.CULLED, handleCulled);
|
|
3300
|
-
// this.renderQueue = [];
|
|
3301
|
-
// this.removedRBushNodeAABBs = [];
|
|
3302
|
-
// this.restoreStack = [];
|
|
3303
|
-
});
|
|
3304
|
-
|
|
3305
|
-
renderingService.hooks.beginFrame.tap(CanvasRendererPlugin.tag, function () {
|
|
3306
|
-
var context = contextService.getContext();
|
|
3307
|
-
var dpr = contextService.getDPR();
|
|
3308
|
-
var width = config.width,
|
|
3309
|
-
height = config.height;
|
|
3310
|
-
var _this$canvasRendererP = _this.canvasRendererPluginOptions,
|
|
3311
|
-
dirtyObjectNumThreshold = _this$canvasRendererP.dirtyObjectNumThreshold,
|
|
3312
|
-
dirtyObjectRatioThreshold = _this$canvasRendererP.dirtyObjectRatioThreshold;
|
|
3313
|
-
// some heuristic conditions such as 80% object changed
|
|
3314
|
-
var _renderingService$get = renderingService.getStats(),
|
|
3315
|
-
total = _renderingService$get.total,
|
|
3316
|
-
rendered = _renderingService$get.rendered;
|
|
3317
|
-
var ratio = rendered / total;
|
|
3318
|
-
_this.clearFullScreen = renderingService.disableDirtyRectangleRendering() || rendered > dirtyObjectNumThreshold && ratio > dirtyObjectRatioThreshold;
|
|
3319
|
-
if (context) {
|
|
3320
|
-
context.resetTransform ? context.resetTransform() : context.setTransform(1, 0, 0, 1, 0, 0);
|
|
3321
|
-
if (_this.clearFullScreen) {
|
|
3322
|
-
_this.clearRect(context, 0, 0, width * dpr, height * dpr, config.background);
|
|
3323
|
-
}
|
|
3324
|
-
}
|
|
3325
|
-
});
|
|
3326
|
-
var renderByZIndex = function renderByZIndex(object, context) {
|
|
3327
|
-
if (object.isVisible() && !object.isCulled()) {
|
|
3328
|
-
_this.renderDisplayObject(object, context, _this.context, _this.restoreStack, runtime);
|
|
3329
|
-
// if (object.renderable.) {
|
|
3330
|
-
// if we did a full screen rendering last frame
|
|
3331
|
-
_this.saveDirtyAABB(object);
|
|
3332
|
-
// }
|
|
3333
|
-
}
|
|
3334
|
-
|
|
3335
|
-
var sorted = object.sortable.sorted || object.childNodes;
|
|
3336
|
-
// should account for z-index
|
|
3337
|
-
sorted.forEach(function (child) {
|
|
3338
|
-
renderByZIndex(child, context);
|
|
3339
|
-
});
|
|
3340
|
-
};
|
|
3341
|
-
// render at the end of frame
|
|
3342
|
-
renderingService.hooks.endFrame.tap(CanvasRendererPlugin.tag, function () {
|
|
3343
|
-
var context = contextService.getContext();
|
|
3344
|
-
// clear & clip dirty rectangle
|
|
3345
|
-
var dpr = contextService.getDPR();
|
|
3346
|
-
fromScaling(_this.dprMatrix, [dpr, dpr, 1]);
|
|
3347
|
-
multiply(_this.vpMatrix, _this.dprMatrix, camera.getOrthoMatrix());
|
|
3348
|
-
// if (this.clearFullScreen) {
|
|
3349
|
-
if (_this.clearFullScreen) {
|
|
3350
|
-
// console.log('canvas renderer fcp...');
|
|
3351
|
-
renderByZIndex(renderingContext.root, context);
|
|
3352
|
-
} else {
|
|
3353
|
-
// console.log('canvas renderer next...');
|
|
3354
|
-
// merge removed AABB
|
|
3355
|
-
var dirtyRenderBounds = _this.safeMergeAABB.apply(_this, [_this.mergeDirtyAABBs(_this.renderQueue)].concat(_this.removedRBushNodeAABBs.map(function (_ref2) {
|
|
3356
|
-
var minX = _ref2.minX,
|
|
3357
|
-
minY = _ref2.minY,
|
|
3358
|
-
maxX = _ref2.maxX,
|
|
3359
|
-
maxY = _ref2.maxY;
|
|
3360
|
-
var aabb = new gLite.AABB();
|
|
3361
|
-
aabb.setMinMax(
|
|
3362
|
-
// vec3.fromValues(minX, minY, 0),
|
|
3363
|
-
// vec3.fromValues(maxX, maxY, 0),
|
|
3364
|
-
[minX, minY, 0], [maxX, maxY, 0]);
|
|
3365
|
-
return aabb;
|
|
3366
|
-
})));
|
|
3367
|
-
_this.removedRBushNodeAABBs = [];
|
|
3368
|
-
if (gLite.AABB.isEmpty(dirtyRenderBounds)) {
|
|
3369
|
-
_this.renderQueue = [];
|
|
3370
|
-
return;
|
|
3371
|
-
}
|
|
3372
|
-
var dirtyRect = _this.convertAABB2Rect(dirtyRenderBounds);
|
|
3373
|
-
var x = dirtyRect.x,
|
|
3374
|
-
y = dirtyRect.y,
|
|
3375
|
-
width = dirtyRect.width,
|
|
3376
|
-
height = dirtyRect.height;
|
|
3377
|
-
var tl = transformMat4(_this.vec3a, [x, y, 0], _this.vpMatrix);
|
|
3378
|
-
var tr = transformMat4(_this.vec3b, [x + width, y, 0], _this.vpMatrix);
|
|
3379
|
-
var bl = transformMat4(_this.vec3c, [x, y + height, 0], _this.vpMatrix);
|
|
3380
|
-
var br = transformMat4(_this.vec3d, [x + width, y + height, 0], _this.vpMatrix);
|
|
3381
|
-
var minx = Math.min(tl[0], tr[0], br[0], bl[0]);
|
|
3382
|
-
var miny = Math.min(tl[1], tr[1], br[1], bl[1]);
|
|
3383
|
-
var maxx = Math.max(tl[0], tr[0], br[0], bl[0]);
|
|
3384
|
-
var maxy = Math.max(tl[1], tr[1], br[1], bl[1]);
|
|
3385
|
-
var ix = Math.floor(minx);
|
|
3386
|
-
var iy = Math.floor(miny);
|
|
3387
|
-
var iwidth = Math.ceil(maxx - minx);
|
|
3388
|
-
var iheight = Math.ceil(maxy - miny);
|
|
3389
|
-
context.save();
|
|
3390
|
-
_this.clearRect(context, ix, iy, iwidth, iheight, config.background);
|
|
3391
|
-
context.beginPath();
|
|
3392
|
-
context.rect(ix, iy, iwidth, iheight);
|
|
3393
|
-
context.clip();
|
|
3394
|
-
// @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
|
|
3395
|
-
context.setTransform(_this.vpMatrix[0], _this.vpMatrix[1], _this.vpMatrix[4], _this.vpMatrix[5], _this.vpMatrix[12], _this.vpMatrix[13]);
|
|
3396
|
-
// draw dirty rectangle
|
|
3397
|
-
var _config$renderer$getC = config.renderer.getConfig(),
|
|
3398
|
-
enableDirtyRectangleRenderingDebug = _config$renderer$getC.enableDirtyRectangleRenderingDebug;
|
|
3399
|
-
if (enableDirtyRectangleRenderingDebug) {
|
|
3400
|
-
canvas.dispatchEvent(new gLite.CustomEvent(gLite.CanvasEvent.DIRTY_RECTANGLE, {
|
|
3401
|
-
dirtyRect: {
|
|
3402
|
-
x: ix,
|
|
3403
|
-
y: iy,
|
|
3404
|
-
width: iwidth,
|
|
3405
|
-
height: iheight
|
|
3406
|
-
}
|
|
3407
|
-
}));
|
|
3408
|
-
}
|
|
3409
|
-
// search objects intersect with dirty rectangle
|
|
3410
|
-
var dirtyObjects = _this.searchDirtyObjects(dirtyRenderBounds);
|
|
3411
|
-
// do rendering
|
|
3412
|
-
dirtyObjects
|
|
3413
|
-
// sort by z-index
|
|
3414
|
-
.sort(function (a, b) {
|
|
3415
|
-
return a.sortable.renderOrder - b.sortable.renderOrder;
|
|
3416
|
-
}).forEach(function (object) {
|
|
3417
|
-
// culled object should not be rendered
|
|
3418
|
-
if (object && object.isVisible() && !object.isCulled()) {
|
|
3419
|
-
_this.renderDisplayObject(object, context, _this.context, _this.restoreStack, runtime);
|
|
3420
|
-
}
|
|
3421
|
-
});
|
|
3422
|
-
context.restore();
|
|
3423
|
-
// save dirty AABBs in last frame
|
|
3424
|
-
_this.renderQueue.forEach(function (object) {
|
|
3425
|
-
_this.saveDirtyAABB(object);
|
|
3426
|
-
});
|
|
3427
|
-
// clear queue
|
|
3428
|
-
_this.renderQueue = [];
|
|
3429
|
-
}
|
|
3430
|
-
// pop restore stack, eg. root -> parent -> child
|
|
3431
|
-
_this.restoreStack.forEach(function () {
|
|
3432
|
-
context.restore();
|
|
3433
|
-
});
|
|
3434
|
-
// clear restore stack
|
|
3435
|
-
_this.restoreStack = [];
|
|
3436
|
-
});
|
|
3437
|
-
renderingService.hooks.render.tap(CanvasRendererPlugin.tag, function (object) {
|
|
3438
|
-
if (!_this.clearFullScreen) {
|
|
3439
|
-
// render at the end of frame
|
|
3440
|
-
_this.renderQueue.push(object);
|
|
3441
|
-
}
|
|
3442
|
-
});
|
|
3443
|
-
};
|
|
3444
|
-
_proto.clearRect = function clearRect(context, x, y, width, height, background) {
|
|
3445
|
-
// clearRect is faster than fillRect @see https://stackoverflow.com/a/30830253
|
|
3446
|
-
context.clearRect(x, y, width, height);
|
|
3447
|
-
if (background) {
|
|
3448
|
-
context.fillStyle = background;
|
|
3449
|
-
context.fillRect(x, y, width, height);
|
|
3450
|
-
}
|
|
3451
|
-
};
|
|
3452
|
-
_proto.renderDisplayObject = function renderDisplayObject(object, context, canvasContext, restoreStack, runtime) {
|
|
3453
|
-
var nodeName = object.nodeName;
|
|
3454
|
-
// console.log('canvas render:', object);
|
|
3455
|
-
// restore to its ancestor
|
|
3456
|
-
var parent = restoreStack[restoreStack.length - 1];
|
|
3457
|
-
if (parent && !(object.compareDocumentPosition(parent) & Node.DOCUMENT_POSITION_CONTAINS)) {
|
|
3458
|
-
context.restore();
|
|
3459
|
-
restoreStack.pop();
|
|
3460
|
-
}
|
|
3461
|
-
// @ts-ignore
|
|
3462
|
-
var styleRenderer = this.context.styleRendererFactory[nodeName];
|
|
3463
|
-
var generatePath = this.pathGeneratorFactory[nodeName];
|
|
3464
|
-
// clip path
|
|
3465
|
-
var clipPath = object.parsedStyle.clipPath;
|
|
3466
|
-
if (clipPath) {
|
|
3467
|
-
this.applyWorldTransform(context, clipPath);
|
|
3468
|
-
// generate path in local space
|
|
3469
|
-
var _generatePath = this.pathGeneratorFactory[clipPath.nodeName];
|
|
3470
|
-
if (_generatePath) {
|
|
3471
|
-
context.save();
|
|
3472
|
-
// save clip
|
|
3473
|
-
restoreStack.push(object);
|
|
3474
|
-
context.beginPath();
|
|
3475
|
-
_generatePath(context, clipPath.parsedStyle);
|
|
3476
|
-
context.closePath();
|
|
3477
|
-
context.clip();
|
|
3478
|
-
}
|
|
3479
|
-
}
|
|
3480
|
-
// fill & stroke
|
|
3481
|
-
if (styleRenderer) {
|
|
3482
|
-
this.applyWorldTransform(context, object);
|
|
3483
|
-
context.save();
|
|
3484
|
-
// apply attributes to context
|
|
3485
|
-
this.applyAttributesToContext(context, object);
|
|
3486
|
-
}
|
|
3487
|
-
if (generatePath) {
|
|
3488
|
-
context.beginPath();
|
|
3489
|
-
generatePath(context, object.parsedStyle);
|
|
3490
|
-
if (object.nodeName !== gLite.Shape.LINE && object.nodeName !== gLite.Shape.PATH && object.nodeName !== gLite.Shape.POLYLINE) {
|
|
3491
|
-
context.closePath();
|
|
3492
|
-
}
|
|
3493
|
-
}
|
|
3494
|
-
// fill & stroke
|
|
3495
|
-
if (styleRenderer) {
|
|
3496
|
-
styleRenderer.render(context, object.parsedStyle, object, canvasContext, this, runtime);
|
|
3497
|
-
// restore applied attributes, eg. shadowBlur shadowColor...
|
|
3498
|
-
context.restore();
|
|
3499
|
-
}
|
|
3500
|
-
// finish rendering, clear dirty flag
|
|
3501
|
-
object.renderable.dirty = false;
|
|
3502
|
-
};
|
|
3503
|
-
_proto.convertAABB2Rect = function convertAABB2Rect(aabb) {
|
|
3504
|
-
var min = aabb.getMin();
|
|
3505
|
-
var max = aabb.getMax();
|
|
3506
|
-
// expand the rectangle a bit to avoid artifacts
|
|
3507
|
-
// @see https://www.yuque.com/antv/ou292n/bi8nix#ExvCu
|
|
3508
|
-
var minX = Math.floor(min[0]);
|
|
3509
|
-
var minY = Math.floor(min[1]);
|
|
3510
|
-
var maxX = Math.ceil(max[0]);
|
|
3511
|
-
var maxY = Math.ceil(max[1]);
|
|
3512
|
-
var width = maxX - minX;
|
|
3513
|
-
var height = maxY - minY;
|
|
3514
|
-
return {
|
|
3515
|
-
x: minX,
|
|
3516
|
-
y: minY,
|
|
3517
|
-
width: width,
|
|
3518
|
-
height: height
|
|
3519
|
-
};
|
|
3520
|
-
}
|
|
3521
|
-
/**
|
|
3522
|
-
* TODO: merge dirty rectangles with some strategies.
|
|
3523
|
-
* For now, we just simply merge all the rectangles into one.
|
|
3524
|
-
* @see https://idom.me/articles/841.html
|
|
3525
|
-
*/;
|
|
3526
|
-
_proto.mergeDirtyAABBs = function mergeDirtyAABBs(dirtyObjects) {
|
|
3527
|
-
// merge into a big AABB
|
|
3528
|
-
// TODO: skip descendant if ancestor is caculated, but compareNodePosition is really slow
|
|
3529
|
-
var aabb = new gLite.AABB();
|
|
3530
|
-
dirtyObjects.forEach(function (object) {
|
|
3531
|
-
var renderBounds = object.getRenderBounds();
|
|
3532
|
-
aabb.add(renderBounds);
|
|
3533
|
-
var dirtyRenderBounds = object.renderable.dirtyRenderBounds;
|
|
3534
|
-
if (dirtyRenderBounds) {
|
|
3535
|
-
aabb.add(dirtyRenderBounds);
|
|
3536
|
-
}
|
|
3537
|
-
});
|
|
3538
|
-
return aabb;
|
|
3539
|
-
};
|
|
3540
|
-
_proto.searchDirtyObjects = function searchDirtyObjects(dirtyRectangle) {
|
|
3541
|
-
// search in r-tree, get all affected nodes
|
|
3542
|
-
var _dirtyRectangle$getMi = dirtyRectangle.getMin(),
|
|
3543
|
-
minX = _dirtyRectangle$getMi[0],
|
|
3544
|
-
minY = _dirtyRectangle$getMi[1];
|
|
3545
|
-
var _dirtyRectangle$getMa = dirtyRectangle.getMax(),
|
|
3546
|
-
maxX = _dirtyRectangle$getMa[0],
|
|
3547
|
-
maxY = _dirtyRectangle$getMa[1];
|
|
3548
|
-
var rBushNodes = this.rBush.search({
|
|
3549
|
-
minX: minX,
|
|
3550
|
-
minY: minY,
|
|
3551
|
-
maxX: maxX,
|
|
3552
|
-
maxY: maxY
|
|
3553
|
-
});
|
|
3554
|
-
return rBushNodes.map(function (_ref3) {
|
|
3555
|
-
var displayObject = _ref3.displayObject;
|
|
3556
|
-
return displayObject;
|
|
3557
|
-
});
|
|
3558
|
-
};
|
|
3559
|
-
_proto.saveDirtyAABB = function saveDirtyAABB(object) {
|
|
3560
|
-
var renderable = object.renderable;
|
|
3561
|
-
if (!renderable.dirtyRenderBounds) {
|
|
3562
|
-
renderable.dirtyRenderBounds = new gLite.AABB();
|
|
3563
|
-
}
|
|
3564
|
-
var renderBounds = object.getRenderBounds();
|
|
3565
|
-
if (renderBounds) {
|
|
3566
|
-
// save last dirty aabb
|
|
3567
|
-
renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
|
|
3568
|
-
}
|
|
3569
|
-
}
|
|
3570
|
-
/**
|
|
3571
|
-
* TODO: batch the same global attributes
|
|
3572
|
-
*/;
|
|
3573
|
-
_proto.applyAttributesToContext = function applyAttributesToContext(context, object) {
|
|
3574
|
-
var _object$parsedStyle = object.parsedStyle,
|
|
3575
|
-
stroke = _object$parsedStyle.stroke,
|
|
3576
|
-
fill = _object$parsedStyle.fill,
|
|
3577
|
-
opacity = _object$parsedStyle.opacity,
|
|
3578
|
-
lineDash = _object$parsedStyle.lineDash,
|
|
3579
|
-
lineDashOffset = _object$parsedStyle.lineDashOffset;
|
|
3580
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash
|
|
3581
|
-
if (lineDash) {
|
|
3582
|
-
context.setLineDash(lineDash);
|
|
3583
|
-
}
|
|
3584
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
|
|
3585
|
-
if (!isNil(lineDashOffset)) {
|
|
3586
|
-
context.lineDashOffset = lineDashOffset;
|
|
3587
|
-
}
|
|
3588
|
-
if (!isNil(opacity)) {
|
|
3589
|
-
context.globalAlpha *= opacity;
|
|
3590
|
-
}
|
|
3591
|
-
if (!isNil(stroke) && !Array.isArray(stroke) && !stroke.isNone) {
|
|
3592
|
-
context.strokeStyle = object.attributes.stroke;
|
|
3593
|
-
}
|
|
3594
|
-
if (!isNil(fill) && !Array.isArray(fill) && !fill.isNone) {
|
|
3595
|
-
context.fillStyle = object.attributes.fill;
|
|
3596
|
-
}
|
|
3597
|
-
};
|
|
3598
|
-
_proto.applyWorldTransform = function applyWorldTransform(context, object, matrix) {
|
|
3599
|
-
var tx = 0;
|
|
3600
|
-
var ty = 0;
|
|
3601
|
-
var _ref4 = object.parsedStyle || {},
|
|
3602
|
-
anchor = _ref4.anchor;
|
|
3603
|
-
var anchorX = anchor && anchor[0] || 0;
|
|
3604
|
-
var anchorY = anchor && anchor[1] || 0;
|
|
3605
|
-
if (anchorX !== 0 || anchorY !== 0) {
|
|
3606
|
-
// const bounds = object.getGeometryBounds();
|
|
3607
|
-
var bounds = object.geometry.contentBounds;
|
|
3608
|
-
var width = bounds && bounds.halfExtents[0] * 2 || 0;
|
|
3609
|
-
var height = bounds && bounds.halfExtents[1] * 2 || 0;
|
|
3610
|
-
tx = -(anchorX * width);
|
|
3611
|
-
ty = -(anchorY * height);
|
|
3612
|
-
}
|
|
3613
|
-
// apply clip shape's RTS
|
|
3614
|
-
if (matrix) {
|
|
3615
|
-
copy(this.tmpMat4, object.getLocalTransform());
|
|
3616
|
-
this.vec3a[0] = tx;
|
|
3617
|
-
this.vec3a[1] = ty;
|
|
3618
|
-
this.vec3a[2] = 0;
|
|
3619
|
-
translate(this.tmpMat4, this.tmpMat4, this.vec3a);
|
|
3620
|
-
multiply(this.tmpMat4, matrix, this.tmpMat4);
|
|
3621
|
-
multiply(this.tmpMat4, this.vpMatrix, this.tmpMat4);
|
|
3622
|
-
} else {
|
|
3623
|
-
// apply RTS transformation in world space
|
|
3624
|
-
copy(this.tmpMat4, object.getWorldTransform());
|
|
3625
|
-
this.vec3a[0] = tx;
|
|
3626
|
-
this.vec3a[1] = ty;
|
|
3627
|
-
this.vec3a[2] = 0;
|
|
3628
|
-
translate(this.tmpMat4, this.tmpMat4, this.vec3a);
|
|
3629
|
-
multiply(this.tmpMat4, this.vpMatrix, this.tmpMat4);
|
|
3630
|
-
}
|
|
3631
|
-
// @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
|
|
3632
|
-
context.setTransform(this.tmpMat4[0], this.tmpMat4[1], this.tmpMat4[4], this.tmpMat4[5], this.tmpMat4[12], this.tmpMat4[13]);
|
|
3633
|
-
};
|
|
3634
|
-
_proto.safeMergeAABB = function safeMergeAABB() {
|
|
3635
|
-
var merged = new gLite.AABB();
|
|
3636
|
-
for (var _len = arguments.length, aabbs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3637
|
-
aabbs[_key] = arguments[_key];
|
|
3638
|
-
}
|
|
3639
|
-
aabbs.forEach(function (aabb) {
|
|
3640
|
-
merged.add(aabb);
|
|
3641
|
-
});
|
|
3642
|
-
return merged;
|
|
3643
|
-
};
|
|
3644
|
-
return CanvasRendererPlugin;
|
|
3645
|
-
}();
|
|
3646
|
-
CanvasRendererPlugin.tag = 'CanvasRenderer';
|
|
3647
|
-
var DefaultRenderer = /*#__PURE__*/function () {
|
|
3648
|
-
function DefaultRenderer(imagePool) {
|
|
3649
|
-
this.imagePool = void 0;
|
|
3650
|
-
this.imagePool = imagePool;
|
|
3651
|
-
}
|
|
3652
|
-
var _proto = DefaultRenderer.prototype;
|
|
3653
|
-
_proto.render = function render(context, parsedStyle, object, canvasContext, plugin, runtime) {
|
|
3654
|
-
var fill = parsedStyle.fill,
|
|
3655
|
-
fillRule = parsedStyle.fillRule,
|
|
3656
|
-
opacity = parsedStyle.opacity,
|
|
3657
|
-
fillOpacity = parsedStyle.fillOpacity,
|
|
3658
|
-
stroke = parsedStyle.stroke,
|
|
3659
|
-
strokeOpacity = parsedStyle.strokeOpacity,
|
|
3660
|
-
lineWidth = parsedStyle.lineWidth,
|
|
3661
|
-
lineCap = parsedStyle.lineCap,
|
|
3662
|
-
lineJoin = parsedStyle.lineJoin,
|
|
3663
|
-
shadowType = parsedStyle.shadowType,
|
|
3664
|
-
shadowColor = parsedStyle.shadowColor,
|
|
3665
|
-
shadowBlur = parsedStyle.shadowBlur,
|
|
3666
|
-
filter = parsedStyle.filter,
|
|
3667
|
-
miterLimit = parsedStyle.miterLimit;
|
|
3668
|
-
var hasFill = !isNil(fill) && !fill.isNone;
|
|
3669
|
-
var hasStroke = !isNil(stroke) && !stroke.isNone && lineWidth > 0;
|
|
3670
|
-
var isFillTransparent = fill.alpha === 0;
|
|
3671
|
-
var hasFilter = !!(filter && filter.length);
|
|
3672
|
-
var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
|
|
3673
|
-
var nodeName = object.nodeName;
|
|
3674
|
-
var isInnerShadow = shadowType === 'inner';
|
|
3675
|
-
var shouldDrawShadowWithStroke = hasStroke && hasShadow && (nodeName === gLite.Shape.PATH || nodeName === gLite.Shape.LINE || nodeName === gLite.Shape.POLYLINE || isFillTransparent || isInnerShadow);
|
|
3676
|
-
if (hasFill) {
|
|
3677
|
-
context.globalAlpha = opacity * fillOpacity;
|
|
3678
|
-
if (!shouldDrawShadowWithStroke) {
|
|
3679
|
-
setShadowAndFilter(object, context, hasShadow);
|
|
3680
|
-
}
|
|
3681
|
-
this.fill(context, object, fill, fillRule, canvasContext, plugin, runtime);
|
|
3682
|
-
if (!shouldDrawShadowWithStroke) {
|
|
3683
|
-
this.clearShadowAndFilter(context, hasFilter, hasShadow);
|
|
3684
|
-
}
|
|
3685
|
-
}
|
|
3686
|
-
if (hasStroke) {
|
|
3687
|
-
context.globalAlpha = opacity * strokeOpacity;
|
|
3688
|
-
context.lineWidth = lineWidth;
|
|
3689
|
-
if (!isNil(miterLimit)) {
|
|
3690
|
-
context.miterLimit = miterLimit;
|
|
3691
|
-
}
|
|
3692
|
-
if (!isNil(lineCap)) {
|
|
3693
|
-
context.lineCap = lineCap;
|
|
3694
|
-
}
|
|
3695
|
-
if (!isNil(lineJoin)) {
|
|
3696
|
-
context.lineJoin = lineJoin;
|
|
3697
|
-
}
|
|
3698
|
-
if (shouldDrawShadowWithStroke) {
|
|
3699
|
-
if (isInnerShadow) {
|
|
3700
|
-
context.globalCompositeOperation = 'source-atop';
|
|
3701
|
-
}
|
|
3702
|
-
setShadowAndFilter(object, context, true);
|
|
3703
|
-
if (isInnerShadow) {
|
|
3704
|
-
this.stroke(context, object, stroke, canvasContext, plugin, runtime);
|
|
3705
|
-
context.globalCompositeOperation = 'source-over';
|
|
3706
|
-
this.clearShadowAndFilter(context, hasFilter, true);
|
|
3707
|
-
}
|
|
3708
|
-
}
|
|
3709
|
-
this.stroke(context, object, stroke, canvasContext, plugin, runtime);
|
|
3710
|
-
}
|
|
3711
|
-
};
|
|
3712
|
-
_proto.clearShadowAndFilter = function clearShadowAndFilter(context, hasFilter, hasShadow) {
|
|
3713
|
-
if (hasShadow) {
|
|
3714
|
-
context.shadowColor = 'transparent';
|
|
3715
|
-
context.shadowBlur = 0;
|
|
3716
|
-
}
|
|
3717
|
-
if (hasFilter) {
|
|
3718
|
-
// save drop-shadow filter
|
|
3719
|
-
var oldFilter = context.filter;
|
|
3720
|
-
if (!isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
|
|
3721
|
-
context.filter = oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || 'none';
|
|
3722
|
-
}
|
|
3723
|
-
}
|
|
3724
|
-
};
|
|
3725
|
-
_proto.fill = function fill(context, object, _fill, fillRule, canvasContext, plugin, runtime) {
|
|
3726
|
-
var _this = this;
|
|
3727
|
-
if (Array.isArray(_fill)) {
|
|
3728
|
-
_fill.forEach(function (gradient) {
|
|
3729
|
-
context.fillStyle = _this.getColor(gradient, object, context);
|
|
3730
|
-
fillRule ? context.fill(fillRule) : context.fill();
|
|
3731
|
-
});
|
|
3732
|
-
} else {
|
|
3733
|
-
if (gLite.isPattern(_fill)) {
|
|
3734
|
-
context.fillStyle = this.getPattern(_fill, object, context, canvasContext, plugin, runtime);
|
|
3735
|
-
}
|
|
3736
|
-
fillRule ? context.fill(fillRule) : context.fill();
|
|
3737
|
-
}
|
|
3738
|
-
};
|
|
3739
|
-
_proto.stroke = function stroke(context, object, _stroke, canvasContext, plugin, runtime) {
|
|
3740
|
-
var _this2 = this;
|
|
3741
|
-
if (Array.isArray(_stroke)) {
|
|
3742
|
-
_stroke.forEach(function (gradient) {
|
|
3743
|
-
context.strokeStyle = _this2.getColor(gradient, object, context);
|
|
3744
|
-
context.stroke();
|
|
3745
|
-
});
|
|
3746
|
-
} else {
|
|
3747
|
-
if (gLite.isPattern(_stroke)) {
|
|
3748
|
-
context.strokeStyle = this.getPattern(_stroke, object, context, canvasContext, plugin, runtime);
|
|
3749
|
-
}
|
|
3750
|
-
context.stroke();
|
|
3751
|
-
}
|
|
3752
|
-
};
|
|
3753
|
-
_proto.getPattern = function getPattern(pattern, object, context, canvasContext, plugin, runtime) {
|
|
3754
|
-
var $offscreenCanvas;
|
|
3755
|
-
var dpr;
|
|
3756
|
-
if (pattern.image.nodeName === 'rect') {
|
|
3757
|
-
var _pattern$image$parsed = pattern.image.parsedStyle,
|
|
3758
|
-
width = _pattern$image$parsed.width,
|
|
3759
|
-
height = _pattern$image$parsed.height;
|
|
3760
|
-
dpr = canvasContext.contextService.getDPR();
|
|
3761
|
-
var offscreenCanvas = canvasContext.config.offscreenCanvas;
|
|
3762
|
-
$offscreenCanvas = runtime.offscreenCanvas.getOrCreateCanvas(offscreenCanvas);
|
|
3763
|
-
$offscreenCanvas.width = width * dpr;
|
|
3764
|
-
$offscreenCanvas.height = height * dpr;
|
|
3765
|
-
var offscreenCanvasContext = runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas);
|
|
3766
|
-
var restoreStack = [];
|
|
3767
|
-
// offscreenCanvasContext.scale(1 / dpr, 1 / dpr);
|
|
3768
|
-
pattern.image.forEach(function (object) {
|
|
3769
|
-
plugin.renderDisplayObject(object, offscreenCanvasContext, canvasContext, restoreStack, runtime);
|
|
3770
|
-
});
|
|
3771
|
-
restoreStack.forEach(function () {
|
|
3772
|
-
offscreenCanvasContext.restore();
|
|
3773
|
-
});
|
|
3774
|
-
}
|
|
3775
|
-
var canvasPattern = this.imagePool.getOrCreatePatternSync(pattern, context, $offscreenCanvas, dpr, function () {
|
|
3776
|
-
// set dirty rectangle flag
|
|
3777
|
-
object.renderable.dirty = true;
|
|
3778
|
-
canvasContext.renderingService.dirtify();
|
|
3779
|
-
});
|
|
3780
|
-
return canvasPattern;
|
|
3781
|
-
};
|
|
3782
|
-
_proto.getColor = function getColor(parsedColor, object, context) {
|
|
3783
|
-
var color;
|
|
3784
|
-
if (parsedColor.type === gLite.GradientType.LinearGradient || parsedColor.type === gLite.GradientType.RadialGradient) {
|
|
3785
|
-
var bounds = object.getGeometryBounds();
|
|
3786
|
-
var width = bounds && bounds.halfExtents[0] * 2 || 1;
|
|
3787
|
-
var height = bounds && bounds.halfExtents[1] * 2 || 1;
|
|
3788
|
-
color = this.imagePool.getOrCreateGradient(_extends({
|
|
3789
|
-
type: parsedColor.type
|
|
3790
|
-
}, parsedColor.value, {
|
|
3791
|
-
width: width,
|
|
3792
|
-
height: height
|
|
3793
|
-
}), context);
|
|
3794
|
-
}
|
|
3795
|
-
return color;
|
|
3796
|
-
};
|
|
3797
|
-
return DefaultRenderer;
|
|
3798
|
-
}();
|
|
3799
|
-
/**
|
|
3800
|
-
* apply before fill and stroke but only once
|
|
3801
|
-
*/
|
|
3802
|
-
function setShadowAndFilter(object, context, hasShadow) {
|
|
3803
|
-
var _object$parsedStyle = object.parsedStyle,
|
|
3804
|
-
filter = _object$parsedStyle.filter,
|
|
3805
|
-
shadowColor = _object$parsedStyle.shadowColor,
|
|
3806
|
-
shadowBlur = _object$parsedStyle.shadowBlur,
|
|
3807
|
-
shadowOffsetX = _object$parsedStyle.shadowOffsetX,
|
|
3808
|
-
shadowOffsetY = _object$parsedStyle.shadowOffsetY;
|
|
3809
|
-
if (filter && filter.length) {
|
|
3810
|
-
// use raw filter string
|
|
3811
|
-
context.filter = object.style.filter;
|
|
3812
|
-
}
|
|
3813
|
-
if (hasShadow) {
|
|
3814
|
-
context.shadowColor = shadowColor.toString();
|
|
3815
|
-
context.shadowBlur = shadowBlur || 0;
|
|
3816
|
-
context.shadowOffsetX = shadowOffsetX || 0;
|
|
3817
|
-
context.shadowOffsetY = shadowOffsetY || 0;
|
|
3818
|
-
}
|
|
3819
|
-
}
|
|
3820
|
-
var ImageRenderer = /*#__PURE__*/function () {
|
|
3821
|
-
function ImageRenderer(imagePool) {
|
|
3822
|
-
this.imagePool = void 0;
|
|
3823
|
-
this.imagePool = imagePool;
|
|
3824
|
-
}
|
|
3825
|
-
var _proto = ImageRenderer.prototype;
|
|
3826
|
-
_proto.render = function render(context, parsedStyle, object) {
|
|
3827
|
-
var width = parsedStyle.width,
|
|
3828
|
-
height = parsedStyle.height,
|
|
3829
|
-
img = parsedStyle.img,
|
|
3830
|
-
shadowColor = parsedStyle.shadowColor,
|
|
3831
|
-
shadowBlur = parsedStyle.shadowBlur;
|
|
3832
|
-
var image;
|
|
3833
|
-
var iw = width;
|
|
3834
|
-
var ih = height;
|
|
3835
|
-
if (isString(img)) {
|
|
3836
|
-
// image has been loaded in `mounted` hook
|
|
3837
|
-
image = this.imagePool.getImageSync(img);
|
|
3838
|
-
} else {
|
|
3839
|
-
iw || (iw = img.width);
|
|
3840
|
-
ih || (ih = img.height);
|
|
3841
|
-
image = img;
|
|
3842
|
-
}
|
|
3843
|
-
if (image) {
|
|
3844
|
-
var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
|
|
3845
|
-
setShadowAndFilter(object, context, hasShadow);
|
|
3846
|
-
// node-canvas will throw the following err:
|
|
3847
|
-
// Error: Image given has not completed loading
|
|
3848
|
-
try {
|
|
3849
|
-
context.drawImage(image, 0, 0, iw, ih);
|
|
3850
|
-
} catch (e) {}
|
|
3851
|
-
}
|
|
3852
|
-
};
|
|
3853
|
-
return ImageRenderer;
|
|
3854
|
-
}();
|
|
3855
|
-
var TextRenderer = /*#__PURE__*/function () {
|
|
3856
|
-
function TextRenderer() {}
|
|
3857
|
-
var _proto = TextRenderer.prototype;
|
|
3858
|
-
_proto.render = function render(context, parsedStyle, object) {
|
|
3859
|
-
var lineWidth = parsedStyle.lineWidth,
|
|
3860
|
-
textAlign = parsedStyle.textAlign,
|
|
3861
|
-
textBaseline = parsedStyle.textBaseline,
|
|
3862
|
-
lineJoin = parsedStyle.lineJoin,
|
|
3863
|
-
miterLimit = parsedStyle.miterLimit,
|
|
3864
|
-
letterSpacing = parsedStyle.letterSpacing,
|
|
3865
|
-
stroke = parsedStyle.stroke,
|
|
3866
|
-
fill = parsedStyle.fill,
|
|
3867
|
-
fillOpacity = parsedStyle.fillOpacity,
|
|
3868
|
-
strokeOpacity = parsedStyle.strokeOpacity,
|
|
3869
|
-
opacity = parsedStyle.opacity,
|
|
3870
|
-
metrics = parsedStyle.metrics,
|
|
3871
|
-
dx = parsedStyle.dx,
|
|
3872
|
-
dy = parsedStyle.dy,
|
|
3873
|
-
shadowColor = parsedStyle.shadowColor,
|
|
3874
|
-
shadowBlur = parsedStyle.shadowBlur;
|
|
3875
|
-
var font = metrics.font,
|
|
3876
|
-
lines = metrics.lines,
|
|
3877
|
-
height = metrics.height,
|
|
3878
|
-
lineHeight = metrics.lineHeight,
|
|
3879
|
-
lineMetrics = metrics.lineMetrics;
|
|
3880
|
-
context.font = font;
|
|
3881
|
-
context.lineWidth = lineWidth;
|
|
3882
|
-
context.textAlign = textAlign === 'middle' ? 'center' : textAlign;
|
|
3883
|
-
var formattedTextBaseline = textBaseline;
|
|
3884
|
-
if (
|
|
3885
|
-
// formattedTextBaseline === 'bottom' ||
|
|
3886
|
-
!gLite.runtime.enableCSSParsing && formattedTextBaseline === 'alphabetic') {
|
|
3887
|
-
formattedTextBaseline = 'bottom';
|
|
3888
|
-
}
|
|
3889
|
-
context.lineJoin = lineJoin;
|
|
3890
|
-
if (!isNil(miterLimit)) {
|
|
3891
|
-
context.miterLimit = miterLimit;
|
|
3892
|
-
}
|
|
3893
|
-
var linePositionY = 0;
|
|
3894
|
-
// handle vertical text baseline
|
|
3895
|
-
if (textBaseline === 'middle') {
|
|
3896
|
-
linePositionY = -height / 2 - lineHeight / 2;
|
|
3897
|
-
} else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
|
|
3898
|
-
linePositionY = -height;
|
|
3899
|
-
} else if (textBaseline === 'top' || textBaseline === 'hanging') {
|
|
3900
|
-
linePositionY = -lineHeight;
|
|
3901
|
-
}
|
|
3902
|
-
// account for dx & dy
|
|
3903
|
-
var offsetX = dx || 0;
|
|
3904
|
-
linePositionY += dy || 0;
|
|
3905
|
-
if (lines.length === 1) {
|
|
3906
|
-
if (formattedTextBaseline === 'bottom') {
|
|
3907
|
-
formattedTextBaseline = 'middle';
|
|
3908
|
-
linePositionY -= 0.5 * height;
|
|
3909
|
-
} else if (formattedTextBaseline === 'top') {
|
|
3910
|
-
formattedTextBaseline = 'middle';
|
|
3911
|
-
linePositionY += 0.5 * height;
|
|
3912
|
-
}
|
|
3913
|
-
}
|
|
3914
|
-
context.textBaseline = formattedTextBaseline;
|
|
3915
|
-
var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
|
|
3916
|
-
setShadowAndFilter(object, context, hasShadow);
|
|
3917
|
-
// draw lines line by line
|
|
3918
|
-
for (var i = 0; i < lines.length; i++) {
|
|
3919
|
-
var linePositionX = lineWidth / 2 + offsetX;
|
|
3920
|
-
linePositionY += lineHeight;
|
|
3921
|
-
// no need to re-position X, cause we already set text align
|
|
3922
|
-
// @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
|
|
3923
|
-
if (!isNil(stroke) && !stroke.isNone && lineWidth) {
|
|
3924
|
-
this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign, linePositionX, linePositionY, letterSpacing, fillOpacity, strokeOpacity, opacity, true);
|
|
3925
|
-
}
|
|
3926
|
-
if (!isNil(fill)) {
|
|
3927
|
-
this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign, linePositionX, linePositionY, letterSpacing, fillOpacity, strokeOpacity, opacity);
|
|
3928
|
-
}
|
|
3929
|
-
}
|
|
3930
|
-
};
|
|
3931
|
-
_proto.drawLetterSpacing = function drawLetterSpacing(context, text, lineMetrics, textAlign, x, y, letterSpacing, fillOpacity, strokeOpacity, opacity, isStroke) {
|
|
3932
|
-
if (isStroke === void 0) {
|
|
3933
|
-
isStroke = false;
|
|
3934
|
-
}
|
|
3935
|
-
// letterSpacing of 0 means normal, render all texts directly
|
|
3936
|
-
if (letterSpacing === 0) {
|
|
3937
|
-
if (isStroke) {
|
|
3938
|
-
this.strokeText(context, text, x, y, strokeOpacity);
|
|
3939
|
-
} else {
|
|
3940
|
-
this.fillText(context, text, x, y, fillOpacity, opacity);
|
|
3941
|
-
}
|
|
3942
|
-
return;
|
|
3943
|
-
}
|
|
3944
|
-
// draw text using left align
|
|
3945
|
-
var currentTextAlign = context.textAlign;
|
|
3946
|
-
context.textAlign = 'left';
|
|
3947
|
-
var currentPosition = x;
|
|
3948
|
-
if (textAlign === 'center' || textAlign === 'middle') {
|
|
3949
|
-
currentPosition = x - lineMetrics.width / 2;
|
|
3950
|
-
} else if (textAlign === 'right' || textAlign === 'end') {
|
|
3951
|
-
currentPosition = x - lineMetrics.width;
|
|
3952
|
-
}
|
|
3953
|
-
var stringArray = Array.from(text);
|
|
3954
|
-
var previousWidth = context.measureText(text).width;
|
|
3955
|
-
var currentWidth = 0;
|
|
3956
|
-
for (var i = 0; i < stringArray.length; ++i) {
|
|
3957
|
-
var currentChar = stringArray[i];
|
|
3958
|
-
if (isStroke) {
|
|
3959
|
-
this.strokeText(context, currentChar, currentPosition, y, strokeOpacity);
|
|
3960
|
-
} else {
|
|
3961
|
-
this.fillText(context, currentChar, currentPosition, y, fillOpacity, opacity);
|
|
3962
|
-
}
|
|
3963
|
-
currentWidth = context.measureText(text.substring(i + 1)).width;
|
|
3964
|
-
currentPosition += previousWidth - currentWidth + letterSpacing;
|
|
3965
|
-
previousWidth = currentWidth;
|
|
3966
|
-
}
|
|
3967
|
-
context.textAlign = currentTextAlign;
|
|
3968
|
-
};
|
|
3969
|
-
_proto.fillText = function fillText(context, text, x, y, fillOpacity, opacity) {
|
|
3970
|
-
var currentGlobalAlpha;
|
|
3971
|
-
var applyOpacity = !isNil(fillOpacity) && fillOpacity !== 1;
|
|
3972
|
-
if (applyOpacity) {
|
|
3973
|
-
currentGlobalAlpha = context.globalAlpha;
|
|
3974
|
-
context.globalAlpha = fillOpacity * opacity;
|
|
3975
|
-
}
|
|
3976
|
-
context.fillText(text, x, y);
|
|
3977
|
-
if (applyOpacity) {
|
|
3978
|
-
context.globalAlpha = currentGlobalAlpha;
|
|
3979
|
-
}
|
|
3980
|
-
};
|
|
3981
|
-
_proto.strokeText = function strokeText(context, text, x, y, strokeOpacity) {
|
|
3982
|
-
var currentGlobalAlpha;
|
|
3983
|
-
var applyOpacity = !isNil(strokeOpacity) && strokeOpacity !== 1;
|
|
3984
|
-
if (applyOpacity) {
|
|
3985
|
-
currentGlobalAlpha = context.globalAlpha;
|
|
3986
|
-
context.globalAlpha = strokeOpacity;
|
|
3987
|
-
}
|
|
3988
|
-
context.strokeText(text, x, y);
|
|
3989
|
-
if (applyOpacity) {
|
|
3990
|
-
context.globalAlpha = currentGlobalAlpha;
|
|
3991
|
-
}
|
|
3992
|
-
};
|
|
3993
|
-
return TextRenderer;
|
|
3994
|
-
}();
|
|
3995
|
-
var RectRenderer = /*#__PURE__*/function (_DefaultRenderer) {
|
|
3996
|
-
_inheritsLoose$3(RectRenderer, _DefaultRenderer);
|
|
3997
|
-
function RectRenderer() {
|
|
3998
|
-
return _DefaultRenderer.apply(this, arguments) || this;
|
|
3999
|
-
}
|
|
4000
|
-
return RectRenderer;
|
|
4001
|
-
}(DefaultRenderer);
|
|
4002
|
-
var CircleRenderer = /*#__PURE__*/function (_DefaultRenderer) {
|
|
4003
|
-
_inheritsLoose$3(CircleRenderer, _DefaultRenderer);
|
|
4004
|
-
function CircleRenderer() {
|
|
4005
|
-
return _DefaultRenderer.apply(this, arguments) || this;
|
|
4006
|
-
}
|
|
4007
|
-
return CircleRenderer;
|
|
4008
|
-
}(DefaultRenderer);
|
|
4009
|
-
var EllipseRenderer = /*#__PURE__*/function (_DefaultRenderer) {
|
|
4010
|
-
_inheritsLoose$3(EllipseRenderer, _DefaultRenderer);
|
|
4011
|
-
function EllipseRenderer() {
|
|
4012
|
-
return _DefaultRenderer.apply(this, arguments) || this;
|
|
4013
|
-
}
|
|
4014
|
-
return EllipseRenderer;
|
|
4015
|
-
}(DefaultRenderer);
|
|
4016
|
-
var LineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
|
|
4017
|
-
_inheritsLoose$3(LineRenderer, _DefaultRenderer);
|
|
4018
|
-
function LineRenderer() {
|
|
4019
|
-
return _DefaultRenderer.apply(this, arguments) || this;
|
|
4020
|
-
}
|
|
4021
|
-
return LineRenderer;
|
|
4022
|
-
}(DefaultRenderer);
|
|
4023
|
-
var PolylineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
|
|
4024
|
-
_inheritsLoose$3(PolylineRenderer, _DefaultRenderer);
|
|
4025
|
-
function PolylineRenderer() {
|
|
4026
|
-
return _DefaultRenderer.apply(this, arguments) || this;
|
|
4027
|
-
}
|
|
4028
|
-
return PolylineRenderer;
|
|
4029
|
-
}(DefaultRenderer);
|
|
4030
|
-
var PolygonRenderer = /*#__PURE__*/function (_DefaultRenderer) {
|
|
4031
|
-
_inheritsLoose$3(PolygonRenderer, _DefaultRenderer);
|
|
4032
|
-
function PolygonRenderer() {
|
|
4033
|
-
return _DefaultRenderer.apply(this, arguments) || this;
|
|
4034
|
-
}
|
|
4035
|
-
return PolygonRenderer;
|
|
4036
|
-
}(DefaultRenderer);
|
|
4037
|
-
var PathRenderer = /*#__PURE__*/function (_DefaultRenderer) {
|
|
4038
|
-
_inheritsLoose$3(PathRenderer, _DefaultRenderer);
|
|
4039
|
-
function PathRenderer() {
|
|
4040
|
-
return _DefaultRenderer.apply(this, arguments) || this;
|
|
4041
|
-
}
|
|
4042
|
-
return PathRenderer;
|
|
4043
|
-
}(DefaultRenderer);
|
|
4044
|
-
var Plugin$2 = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
4045
|
-
_inheritsLoose$3(Plugin, _AbstractRendererPlug);
|
|
4046
|
-
function Plugin(options) {
|
|
4047
|
-
var _this;
|
|
4048
|
-
if (options === void 0) {
|
|
4049
|
-
options = {};
|
|
4050
|
-
}
|
|
4051
|
-
_this = _AbstractRendererPlug.call(this) || this;
|
|
4052
|
-
_this.options = void 0;
|
|
4053
|
-
_this.name = 'canvas-renderer';
|
|
4054
|
-
_this.options = options;
|
|
4055
|
-
return _this;
|
|
4056
|
-
}
|
|
4057
|
-
var _proto = Plugin.prototype;
|
|
4058
|
-
_proto.init = function init() {
|
|
4059
|
-
var _defaultStyleRenderer;
|
|
4060
|
-
var canvasRendererPluginOptions = _extends({
|
|
4061
|
-
dirtyObjectNumThreshold: 500,
|
|
4062
|
-
dirtyObjectRatioThreshold: 0.8
|
|
4063
|
-
}, this.options);
|
|
4064
|
-
// @ts-ignore
|
|
4065
|
-
var imagePool = this.context.imagePool;
|
|
4066
|
-
var defaultRenderer = new DefaultRenderer(imagePool);
|
|
4067
|
-
var defaultStyleRendererFactory = (_defaultStyleRenderer = {}, _defaultStyleRenderer[gLite.Shape.CIRCLE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.ELLIPSE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.RECT] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.IMAGE] = new ImageRenderer(imagePool), _defaultStyleRenderer[gLite.Shape.TEXT] = new TextRenderer(), _defaultStyleRenderer[gLite.Shape.LINE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.POLYLINE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.POLYGON] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.PATH] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.GROUP] = undefined, _defaultStyleRenderer[gLite.Shape.HTML] = undefined, _defaultStyleRenderer[gLite.Shape.MESH] = undefined, _defaultStyleRenderer);
|
|
4068
|
-
this.context.defaultStyleRendererFactory = defaultStyleRendererFactory;
|
|
4069
|
-
this.context.styleRendererFactory = defaultStyleRendererFactory;
|
|
4070
|
-
this.addRenderingPlugin(new CanvasRendererPlugin(canvasRendererPluginOptions));
|
|
4071
|
-
};
|
|
4072
|
-
_proto.destroy = function destroy() {
|
|
4073
|
-
this.removeAllRenderingPlugins();
|
|
4074
|
-
delete this.context.defaultStyleRendererFactory;
|
|
4075
|
-
delete this.context.styleRendererFactory;
|
|
4076
|
-
};
|
|
4077
|
-
return Plugin;
|
|
4078
|
-
}(gLite.AbstractRendererPlugin);
|
|
4079
|
-
|
|
4080
|
-
var index_esm$2 = /*#__PURE__*/Object.freeze({
|
|
4081
|
-
__proto__: null,
|
|
4082
|
-
CircleRenderer: CircleRenderer,
|
|
4083
|
-
EllipseRenderer: EllipseRenderer,
|
|
4084
|
-
ImageRenderer: ImageRenderer,
|
|
4085
|
-
LineRenderer: LineRenderer,
|
|
4086
|
-
PathRenderer: PathRenderer,
|
|
4087
|
-
Plugin: Plugin$2,
|
|
4088
|
-
PolygonRenderer: PolygonRenderer,
|
|
4089
|
-
PolylineRenderer: PolylineRenderer,
|
|
4090
|
-
RectRenderer: RectRenderer,
|
|
4091
|
-
TextRenderer: TextRenderer
|
|
4092
|
-
});
|
|
4093
3011
|
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
var exports = {},
|
|
4099
|
-
Op = Object.prototype,
|
|
4100
|
-
hasOwn = Op.hasOwnProperty,
|
|
4101
|
-
defineProperty = Object.defineProperty || function (obj, key, desc) {
|
|
4102
|
-
obj[key] = desc.value;
|
|
4103
|
-
},
|
|
4104
|
-
$Symbol = "function" == typeof Symbol ? Symbol : {},
|
|
4105
|
-
iteratorSymbol = $Symbol.iterator || "@@iterator",
|
|
4106
|
-
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
|
|
4107
|
-
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
4108
|
-
function define(obj, key, value) {
|
|
4109
|
-
return Object.defineProperty(obj, key, {
|
|
4110
|
-
value: value,
|
|
4111
|
-
enumerable: !0,
|
|
4112
|
-
configurable: !0,
|
|
4113
|
-
writable: !0
|
|
4114
|
-
}), obj[key];
|
|
4115
|
-
}
|
|
4116
|
-
try {
|
|
4117
|
-
define({}, "");
|
|
4118
|
-
} catch (err) {
|
|
4119
|
-
define = function define(obj, key, value) {
|
|
4120
|
-
return obj[key] = value;
|
|
4121
|
-
};
|
|
4122
|
-
}
|
|
4123
|
-
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
4124
|
-
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
|
|
4125
|
-
generator = Object.create(protoGenerator.prototype),
|
|
4126
|
-
context = new Context(tryLocsList || []);
|
|
4127
|
-
return defineProperty(generator, "_invoke", {
|
|
4128
|
-
value: makeInvokeMethod(innerFn, self, context)
|
|
4129
|
-
}), generator;
|
|
4130
|
-
}
|
|
4131
|
-
function tryCatch(fn, obj, arg) {
|
|
4132
|
-
try {
|
|
4133
|
-
return {
|
|
4134
|
-
type: "normal",
|
|
4135
|
-
arg: fn.call(obj, arg)
|
|
4136
|
-
};
|
|
4137
|
-
} catch (err) {
|
|
4138
|
-
return {
|
|
4139
|
-
type: "throw",
|
|
4140
|
-
arg: err
|
|
4141
|
-
};
|
|
4142
|
-
}
|
|
4143
|
-
}
|
|
4144
|
-
exports.wrap = wrap;
|
|
4145
|
-
var ContinueSentinel = {};
|
|
4146
|
-
function Generator() {}
|
|
4147
|
-
function GeneratorFunction() {}
|
|
4148
|
-
function GeneratorFunctionPrototype() {}
|
|
4149
|
-
var IteratorPrototype = {};
|
|
4150
|
-
define(IteratorPrototype, iteratorSymbol, function () {
|
|
4151
|
-
return this;
|
|
4152
|
-
});
|
|
4153
|
-
var getProto = Object.getPrototypeOf,
|
|
4154
|
-
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
4155
|
-
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
|
|
4156
|
-
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
4157
|
-
function defineIteratorMethods(prototype) {
|
|
4158
|
-
["next", "throw", "return"].forEach(function (method) {
|
|
4159
|
-
define(prototype, method, function (arg) {
|
|
4160
|
-
return this._invoke(method, arg);
|
|
3012
|
+
var sorted = object.sortable.sorted || object.childNodes;
|
|
3013
|
+
// should account for z-index
|
|
3014
|
+
sorted.forEach(function (child) {
|
|
3015
|
+
renderByZIndex(child, context);
|
|
4161
3016
|
});
|
|
4162
|
-
}
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
3017
|
+
};
|
|
3018
|
+
// render at the end of frame
|
|
3019
|
+
renderingService.hooks.endFrame.tap(CanvasRendererPlugin.tag, function () {
|
|
3020
|
+
var context = contextService.getContext();
|
|
3021
|
+
// clear & clip dirty rectangle
|
|
3022
|
+
var dpr = contextService.getDPR();
|
|
3023
|
+
fromScaling(_this.dprMatrix, [dpr, dpr, 1]);
|
|
3024
|
+
multiply(_this.vpMatrix, _this.dprMatrix, camera.getOrthoMatrix());
|
|
3025
|
+
// if (this.clearFullScreen) {
|
|
3026
|
+
if (_this.clearFullScreen) {
|
|
3027
|
+
// console.log('canvas renderer fcp...');
|
|
3028
|
+
renderByZIndex(renderingContext.root, context);
|
|
3029
|
+
} else {
|
|
3030
|
+
// console.log('canvas renderer next...');
|
|
3031
|
+
// merge removed AABB
|
|
3032
|
+
var dirtyRenderBounds = _this.safeMergeAABB.apply(_this, [_this.mergeDirtyAABBs(_this.renderQueue)].concat(_this.removedRBushNodeAABBs.map(function (_ref) {
|
|
3033
|
+
var minX = _ref.minX,
|
|
3034
|
+
minY = _ref.minY,
|
|
3035
|
+
maxX = _ref.maxX,
|
|
3036
|
+
maxY = _ref.maxY;
|
|
3037
|
+
var aabb = new gLite.AABB();
|
|
3038
|
+
aabb.setMinMax(
|
|
3039
|
+
// vec3.fromValues(minX, minY, 0),
|
|
3040
|
+
// vec3.fromValues(maxX, maxY, 0),
|
|
3041
|
+
[minX, minY, 0], [maxX, maxY, 0]);
|
|
3042
|
+
return aabb;
|
|
3043
|
+
})));
|
|
3044
|
+
_this.removedRBushNodeAABBs = [];
|
|
3045
|
+
if (gLite.AABB.isEmpty(dirtyRenderBounds)) {
|
|
3046
|
+
_this.renderQueue = [];
|
|
3047
|
+
return;
|
|
3048
|
+
}
|
|
3049
|
+
var dirtyRect = _this.convertAABB2Rect(dirtyRenderBounds);
|
|
3050
|
+
var x = dirtyRect.x,
|
|
3051
|
+
y = dirtyRect.y,
|
|
3052
|
+
width = dirtyRect.width,
|
|
3053
|
+
height = dirtyRect.height;
|
|
3054
|
+
var tl = transformMat4(_this.vec3a, [x, y, 0], _this.vpMatrix);
|
|
3055
|
+
var tr = transformMat4(_this.vec3b, [x + width, y, 0], _this.vpMatrix);
|
|
3056
|
+
var bl = transformMat4(_this.vec3c, [x, y + height, 0], _this.vpMatrix);
|
|
3057
|
+
var br = transformMat4(_this.vec3d, [x + width, y + height, 0], _this.vpMatrix);
|
|
3058
|
+
var minx = Math.min(tl[0], tr[0], br[0], bl[0]);
|
|
3059
|
+
var miny = Math.min(tl[1], tr[1], br[1], bl[1]);
|
|
3060
|
+
var maxx = Math.max(tl[0], tr[0], br[0], bl[0]);
|
|
3061
|
+
var maxy = Math.max(tl[1], tr[1], br[1], bl[1]);
|
|
3062
|
+
var ix = Math.floor(minx);
|
|
3063
|
+
var iy = Math.floor(miny);
|
|
3064
|
+
var iwidth = Math.ceil(maxx - minx);
|
|
3065
|
+
var iheight = Math.ceil(maxy - miny);
|
|
3066
|
+
context.save();
|
|
3067
|
+
_this.clearRect(context, ix, iy, iwidth, iheight, config.background);
|
|
3068
|
+
context.beginPath();
|
|
3069
|
+
context.rect(ix, iy, iwidth, iheight);
|
|
3070
|
+
context.clip();
|
|
3071
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
|
|
3072
|
+
context.setTransform(_this.vpMatrix[0], _this.vpMatrix[1], _this.vpMatrix[4], _this.vpMatrix[5], _this.vpMatrix[12], _this.vpMatrix[13]);
|
|
3073
|
+
// draw dirty rectangle
|
|
3074
|
+
var _config$renderer$getC = config.renderer.getConfig(),
|
|
3075
|
+
enableDirtyRectangleRenderingDebug = _config$renderer$getC.enableDirtyRectangleRenderingDebug;
|
|
3076
|
+
if (enableDirtyRectangleRenderingDebug) {
|
|
3077
|
+
canvas.dispatchEvent(new gLite.CustomEvent(gLite.CanvasEvent.DIRTY_RECTANGLE, {
|
|
3078
|
+
dirtyRect: {
|
|
3079
|
+
x: ix,
|
|
3080
|
+
y: iy,
|
|
3081
|
+
width: iwidth,
|
|
3082
|
+
height: iheight
|
|
3083
|
+
}
|
|
3084
|
+
}));
|
|
4189
3085
|
}
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
}
|
|
4202
|
-
for (context.method = method, context.arg = arg;;) {
|
|
4203
|
-
var delegate = context.delegate;
|
|
4204
|
-
if (delegate) {
|
|
4205
|
-
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
4206
|
-
if (delegateResult) {
|
|
4207
|
-
if (delegateResult === ContinueSentinel) continue;
|
|
4208
|
-
return delegateResult;
|
|
3086
|
+
// search objects intersect with dirty rectangle
|
|
3087
|
+
var dirtyObjects = _this.searchDirtyObjects(dirtyRenderBounds);
|
|
3088
|
+
// do rendering
|
|
3089
|
+
dirtyObjects
|
|
3090
|
+
// sort by z-index
|
|
3091
|
+
.sort(function (a, b) {
|
|
3092
|
+
return a.sortable.renderOrder - b.sortable.renderOrder;
|
|
3093
|
+
}).forEach(function (object) {
|
|
3094
|
+
// culled object should not be rendered
|
|
3095
|
+
if (object && object.isVisible() && !object.isCulled()) {
|
|
3096
|
+
_this.renderDisplayObject(object, context, _this.context, _this.restoreStack, runtime);
|
|
4209
3097
|
}
|
|
4210
|
-
}
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
|
|
4219
|
-
return {
|
|
4220
|
-
value: record.arg,
|
|
4221
|
-
done: context.done
|
|
4222
|
-
};
|
|
4223
|
-
}
|
|
4224
|
-
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
|
|
4225
|
-
}
|
|
4226
|
-
};
|
|
4227
|
-
}
|
|
4228
|
-
function maybeInvokeDelegate(delegate, context) {
|
|
4229
|
-
var methodName = context.method,
|
|
4230
|
-
method = delegate.iterator[methodName];
|
|
4231
|
-
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
|
|
4232
|
-
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
4233
|
-
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
|
|
4234
|
-
var info = record.arg;
|
|
4235
|
-
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
|
|
4236
|
-
}
|
|
4237
|
-
function pushTryEntry(locs) {
|
|
4238
|
-
var entry = {
|
|
4239
|
-
tryLoc: locs[0]
|
|
4240
|
-
};
|
|
4241
|
-
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
|
|
4242
|
-
}
|
|
4243
|
-
function resetTryEntry(entry) {
|
|
4244
|
-
var record = entry.completion || {};
|
|
4245
|
-
record.type = "normal", delete record.arg, entry.completion = record;
|
|
4246
|
-
}
|
|
4247
|
-
function Context(tryLocsList) {
|
|
4248
|
-
this.tryEntries = [{
|
|
4249
|
-
tryLoc: "root"
|
|
4250
|
-
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
|
|
4251
|
-
}
|
|
4252
|
-
function values(iterable) {
|
|
4253
|
-
if (iterable) {
|
|
4254
|
-
var iteratorMethod = iterable[iteratorSymbol];
|
|
4255
|
-
if (iteratorMethod) return iteratorMethod.call(iterable);
|
|
4256
|
-
if ("function" == typeof iterable.next) return iterable;
|
|
4257
|
-
if (!isNaN(iterable.length)) {
|
|
4258
|
-
var i = -1,
|
|
4259
|
-
next = function next() {
|
|
4260
|
-
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
|
4261
|
-
return next.value = undefined, next.done = !0, next;
|
|
4262
|
-
};
|
|
4263
|
-
return next.next = next;
|
|
3098
|
+
});
|
|
3099
|
+
context.restore();
|
|
3100
|
+
// save dirty AABBs in last frame
|
|
3101
|
+
_this.renderQueue.forEach(function (object) {
|
|
3102
|
+
_this.saveDirtyAABB(object);
|
|
3103
|
+
});
|
|
3104
|
+
// clear queue
|
|
3105
|
+
_this.renderQueue = [];
|
|
4264
3106
|
}
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
return {
|
|
4272
|
-
value: undefined,
|
|
4273
|
-
done: !0
|
|
4274
|
-
};
|
|
4275
|
-
}
|
|
4276
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
|
|
4277
|
-
value: GeneratorFunctionPrototype,
|
|
4278
|
-
configurable: !0
|
|
4279
|
-
}), defineProperty(GeneratorFunctionPrototype, "constructor", {
|
|
4280
|
-
value: GeneratorFunction,
|
|
4281
|
-
configurable: !0
|
|
4282
|
-
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
|
|
4283
|
-
var ctor = "function" == typeof genFun && genFun.constructor;
|
|
4284
|
-
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
|
|
4285
|
-
}, exports.mark = function (genFun) {
|
|
4286
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
|
|
4287
|
-
}, exports.awrap = function (arg) {
|
|
4288
|
-
return {
|
|
4289
|
-
__await: arg
|
|
4290
|
-
};
|
|
4291
|
-
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
4292
|
-
return this;
|
|
4293
|
-
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
4294
|
-
void 0 === PromiseImpl && (PromiseImpl = Promise);
|
|
4295
|
-
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
|
|
4296
|
-
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
|
|
4297
|
-
return result.done ? result.value : iter.next();
|
|
3107
|
+
// pop restore stack, eg. root -> parent -> child
|
|
3108
|
+
_this.restoreStack.forEach(function () {
|
|
3109
|
+
context.restore();
|
|
3110
|
+
});
|
|
3111
|
+
// clear restore stack
|
|
3112
|
+
_this.restoreStack = [];
|
|
4298
3113
|
});
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
}), exports.keys = function (val) {
|
|
4304
|
-
var object = Object(val),
|
|
4305
|
-
keys = [];
|
|
4306
|
-
for (var key in object) keys.push(key);
|
|
4307
|
-
return keys.reverse(), function next() {
|
|
4308
|
-
for (; keys.length;) {
|
|
4309
|
-
var key = keys.pop();
|
|
4310
|
-
if (key in object) return next.value = key, next.done = !1, next;
|
|
4311
|
-
}
|
|
4312
|
-
return next.done = !0, next;
|
|
4313
|
-
};
|
|
4314
|
-
}, exports.values = values, Context.prototype = {
|
|
4315
|
-
constructor: Context,
|
|
4316
|
-
reset: function reset(skipTempReset) {
|
|
4317
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
|
|
4318
|
-
},
|
|
4319
|
-
stop: function stop() {
|
|
4320
|
-
this.done = !0;
|
|
4321
|
-
var rootRecord = this.tryEntries[0].completion;
|
|
4322
|
-
if ("throw" === rootRecord.type) throw rootRecord.arg;
|
|
4323
|
-
return this.rval;
|
|
4324
|
-
},
|
|
4325
|
-
dispatchException: function dispatchException(exception) {
|
|
4326
|
-
if (this.done) throw exception;
|
|
4327
|
-
var context = this;
|
|
4328
|
-
function handle(loc, caught) {
|
|
4329
|
-
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
|
|
4330
|
-
}
|
|
4331
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
4332
|
-
var entry = this.tryEntries[i],
|
|
4333
|
-
record = entry.completion;
|
|
4334
|
-
if ("root" === entry.tryLoc) return handle("end");
|
|
4335
|
-
if (entry.tryLoc <= this.prev) {
|
|
4336
|
-
var hasCatch = hasOwn.call(entry, "catchLoc"),
|
|
4337
|
-
hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
4338
|
-
if (hasCatch && hasFinally) {
|
|
4339
|
-
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
4340
|
-
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
4341
|
-
} else if (hasCatch) {
|
|
4342
|
-
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
4343
|
-
} else {
|
|
4344
|
-
if (!hasFinally) throw new Error("try statement without catch or finally");
|
|
4345
|
-
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
4346
|
-
}
|
|
4347
|
-
}
|
|
4348
|
-
}
|
|
4349
|
-
},
|
|
4350
|
-
abrupt: function abrupt(type, arg) {
|
|
4351
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
4352
|
-
var entry = this.tryEntries[i];
|
|
4353
|
-
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
|
4354
|
-
var finallyEntry = entry;
|
|
4355
|
-
break;
|
|
4356
|
-
}
|
|
3114
|
+
renderingService.hooks.render.tap(CanvasRendererPlugin.tag, function (object) {
|
|
3115
|
+
if (!_this.clearFullScreen) {
|
|
3116
|
+
// render at the end of frame
|
|
3117
|
+
_this.renderQueue.push(object);
|
|
4357
3118
|
}
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
3119
|
+
});
|
|
3120
|
+
};
|
|
3121
|
+
_proto.clearRect = function clearRect(context, x, y, width, height, background) {
|
|
3122
|
+
// clearRect is faster than fillRect @see https://stackoverflow.com/a/30830253
|
|
3123
|
+
context.clearRect(x, y, width, height);
|
|
3124
|
+
if (background) {
|
|
3125
|
+
context.fillStyle = background;
|
|
3126
|
+
context.fillRect(x, y, width, height);
|
|
3127
|
+
}
|
|
3128
|
+
};
|
|
3129
|
+
_proto.renderDisplayObject = function renderDisplayObject(object, context, canvasContext, restoreStack, runtime) {
|
|
3130
|
+
var nodeName = object.nodeName;
|
|
3131
|
+
// console.log('canvas render:', object);
|
|
3132
|
+
// restore to its ancestor
|
|
3133
|
+
var parent = restoreStack[restoreStack.length - 1];
|
|
3134
|
+
if (parent && !(object.compareDocumentPosition(parent) & Node.DOCUMENT_POSITION_CONTAINS)) {
|
|
3135
|
+
context.restore();
|
|
3136
|
+
restoreStack.pop();
|
|
3137
|
+
}
|
|
3138
|
+
// @ts-ignore
|
|
3139
|
+
var styleRenderer = this.context.styleRendererFactory[nodeName];
|
|
3140
|
+
var generatePath = this.pathGeneratorFactory[nodeName];
|
|
3141
|
+
// clip path
|
|
3142
|
+
var clipPath = object.parsedStyle.clipPath;
|
|
3143
|
+
if (clipPath) {
|
|
3144
|
+
this.applyWorldTransform(context, clipPath);
|
|
3145
|
+
// generate path in local space
|
|
3146
|
+
var _generatePath = this.pathGeneratorFactory[clipPath.nodeName];
|
|
3147
|
+
if (_generatePath) {
|
|
3148
|
+
context.save();
|
|
3149
|
+
// save clip
|
|
3150
|
+
restoreStack.push(object);
|
|
3151
|
+
context.beginPath();
|
|
3152
|
+
_generatePath(context, clipPath.parsedStyle);
|
|
3153
|
+
context.closePath();
|
|
3154
|
+
context.clip();
|
|
4370
3155
|
}
|
|
4371
|
-
}
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
3156
|
+
}
|
|
3157
|
+
// fill & stroke
|
|
3158
|
+
if (styleRenderer) {
|
|
3159
|
+
this.applyWorldTransform(context, object);
|
|
3160
|
+
context.save();
|
|
3161
|
+
// apply attributes to context
|
|
3162
|
+
this.applyAttributesToContext(context, object);
|
|
3163
|
+
}
|
|
3164
|
+
if (generatePath) {
|
|
3165
|
+
context.beginPath();
|
|
3166
|
+
generatePath(context, object.parsedStyle);
|
|
3167
|
+
if (object.nodeName !== gLite.Shape.LINE && object.nodeName !== gLite.Shape.PATH && object.nodeName !== gLite.Shape.POLYLINE) {
|
|
3168
|
+
context.closePath();
|
|
4383
3169
|
}
|
|
4384
|
-
throw new Error("illegal catch attempt");
|
|
4385
|
-
},
|
|
4386
|
-
delegateYield: function delegateYield(iterable, resultName, nextLoc) {
|
|
4387
|
-
return this.delegate = {
|
|
4388
|
-
iterator: values(iterable),
|
|
4389
|
-
resultName: resultName,
|
|
4390
|
-
nextLoc: nextLoc
|
|
4391
|
-
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
|
|
4392
3170
|
}
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
3171
|
+
// fill & stroke
|
|
3172
|
+
if (styleRenderer) {
|
|
3173
|
+
styleRenderer.render(context, object.parsedStyle, object, canvasContext, this, runtime);
|
|
3174
|
+
// restore applied attributes, eg. shadowBlur shadowColor...
|
|
3175
|
+
context.restore();
|
|
3176
|
+
}
|
|
3177
|
+
// finish rendering, clear dirty flag
|
|
3178
|
+
object.renderable.dirty = false;
|
|
3179
|
+
};
|
|
3180
|
+
_proto.convertAABB2Rect = function convertAABB2Rect(aabb) {
|
|
3181
|
+
var min = aabb.getMin();
|
|
3182
|
+
var max = aabb.getMax();
|
|
3183
|
+
// expand the rectangle a bit to avoid artifacts
|
|
3184
|
+
// @see https://www.yuque.com/antv/ou292n/bi8nix#ExvCu
|
|
3185
|
+
var minX = Math.floor(min[0]);
|
|
3186
|
+
var minY = Math.floor(min[1]);
|
|
3187
|
+
var maxX = Math.ceil(max[0]);
|
|
3188
|
+
var maxY = Math.ceil(max[1]);
|
|
3189
|
+
var width = maxX - minX;
|
|
3190
|
+
var height = maxY - minY;
|
|
3191
|
+
return {
|
|
3192
|
+
x: minX,
|
|
3193
|
+
y: minY,
|
|
3194
|
+
width: width,
|
|
3195
|
+
height: height
|
|
3196
|
+
};
|
|
4407
3197
|
}
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
3198
|
+
/**
|
|
3199
|
+
* TODO: merge dirty rectangles with some strategies.
|
|
3200
|
+
* For now, we just simply merge all the rectangles into one.
|
|
3201
|
+
* @see https://idom.me/articles/841.html
|
|
3202
|
+
*/;
|
|
3203
|
+
_proto.mergeDirtyAABBs = function mergeDirtyAABBs(dirtyObjects) {
|
|
3204
|
+
// merge into a big AABB
|
|
3205
|
+
// TODO: skip descendant if ancestor is caculated, but compareNodePosition is really slow
|
|
3206
|
+
var aabb = new gLite.AABB();
|
|
3207
|
+
dirtyObjects.forEach(function (object) {
|
|
3208
|
+
var renderBounds = object.getRenderBounds();
|
|
3209
|
+
aabb.add(renderBounds);
|
|
3210
|
+
var dirtyRenderBounds = object.renderable.dirtyRenderBounds;
|
|
3211
|
+
if (dirtyRenderBounds) {
|
|
3212
|
+
aabb.add(dirtyRenderBounds);
|
|
4420
3213
|
}
|
|
4421
|
-
_next(undefined);
|
|
4422
3214
|
});
|
|
3215
|
+
return aabb;
|
|
4423
3216
|
};
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
3217
|
+
_proto.searchDirtyObjects = function searchDirtyObjects(dirtyRectangle) {
|
|
3218
|
+
// search in r-tree, get all affected nodes
|
|
3219
|
+
var _dirtyRectangle$getMi = dirtyRectangle.getMin(),
|
|
3220
|
+
minX = _dirtyRectangle$getMi[0],
|
|
3221
|
+
minY = _dirtyRectangle$getMi[1];
|
|
3222
|
+
var _dirtyRectangle$getMa = dirtyRectangle.getMax(),
|
|
3223
|
+
maxX = _dirtyRectangle$getMa[0],
|
|
3224
|
+
maxY = _dirtyRectangle$getMa[1];
|
|
3225
|
+
var rBushNodes = this.rBush.search({
|
|
3226
|
+
minX: minX,
|
|
3227
|
+
minY: minY,
|
|
3228
|
+
maxX: maxX,
|
|
3229
|
+
maxY: maxY
|
|
3230
|
+
});
|
|
3231
|
+
return rBushNodes.map(function (_ref2) {
|
|
3232
|
+
var displayObject = _ref2.displayObject;
|
|
3233
|
+
return displayObject;
|
|
3234
|
+
});
|
|
4434
3235
|
};
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
3236
|
+
_proto.saveDirtyAABB = function saveDirtyAABB(object) {
|
|
3237
|
+
var renderable = object.renderable;
|
|
3238
|
+
if (!renderable.dirtyRenderBounds) {
|
|
3239
|
+
renderable.dirtyRenderBounds = new gLite.AABB();
|
|
3240
|
+
}
|
|
3241
|
+
var renderBounds = object.getRenderBounds();
|
|
3242
|
+
if (renderBounds) {
|
|
3243
|
+
// save last dirty aabb
|
|
3244
|
+
renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
|
|
3245
|
+
}
|
|
4445
3246
|
}
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
}
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
}
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
}
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
}
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
var
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
var
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
}
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
})));
|
|
4557
|
-
renderingService.hooks.destroy.tap(DOMInteractionPlugin.tag, function () {
|
|
4558
|
-
var $el = _this.context.contextService.getDomElement();
|
|
4559
|
-
// @ts-ignore
|
|
4560
|
-
if (runtime.globalThis.navigator.msPointerEnabled) {
|
|
4561
|
-
// @ts-ignore
|
|
4562
|
-
$el.style.msContentZooming = '';
|
|
4563
|
-
// @ts-ignore
|
|
4564
|
-
$el.style.msTouchAction = '';
|
|
4565
|
-
} else if (canvas.supportsPointerEvents) {
|
|
4566
|
-
$el.style.touchAction = '';
|
|
3247
|
+
/**
|
|
3248
|
+
* TODO: batch the same global attributes
|
|
3249
|
+
*/;
|
|
3250
|
+
_proto.applyAttributesToContext = function applyAttributesToContext(context, object) {
|
|
3251
|
+
var _object$parsedStyle = object.parsedStyle,
|
|
3252
|
+
stroke = _object$parsedStyle.stroke,
|
|
3253
|
+
fill = _object$parsedStyle.fill,
|
|
3254
|
+
opacity = _object$parsedStyle.opacity,
|
|
3255
|
+
lineDash = _object$parsedStyle.lineDash,
|
|
3256
|
+
lineDashOffset = _object$parsedStyle.lineDashOffset;
|
|
3257
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash
|
|
3258
|
+
if (lineDash) {
|
|
3259
|
+
context.setLineDash(lineDash);
|
|
3260
|
+
}
|
|
3261
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
|
|
3262
|
+
if (!isNil(lineDashOffset)) {
|
|
3263
|
+
context.lineDashOffset = lineDashOffset;
|
|
3264
|
+
}
|
|
3265
|
+
if (!isNil(opacity)) {
|
|
3266
|
+
context.globalAlpha *= opacity;
|
|
3267
|
+
}
|
|
3268
|
+
if (!isNil(stroke) && !Array.isArray(stroke) && !stroke.isNone) {
|
|
3269
|
+
context.strokeStyle = object.attributes.stroke;
|
|
3270
|
+
}
|
|
3271
|
+
if (!isNil(fill) && !Array.isArray(fill) && !fill.isNone) {
|
|
3272
|
+
context.fillStyle = object.attributes.fill;
|
|
3273
|
+
}
|
|
3274
|
+
};
|
|
3275
|
+
_proto.applyWorldTransform = function applyWorldTransform(context, object, matrix) {
|
|
3276
|
+
var tx = 0;
|
|
3277
|
+
var ty = 0;
|
|
3278
|
+
var _ref3 = object.parsedStyle || {},
|
|
3279
|
+
anchor = _ref3.anchor;
|
|
3280
|
+
var anchorX = anchor && anchor[0] || 0;
|
|
3281
|
+
var anchorY = anchor && anchor[1] || 0;
|
|
3282
|
+
if (anchorX !== 0 || anchorY !== 0) {
|
|
3283
|
+
// const bounds = object.getGeometryBounds();
|
|
3284
|
+
var bounds = object.geometry.contentBounds;
|
|
3285
|
+
var width = bounds && bounds.halfExtents[0] * 2 || 0;
|
|
3286
|
+
var height = bounds && bounds.halfExtents[1] * 2 || 0;
|
|
3287
|
+
tx = -(anchorX * width);
|
|
3288
|
+
ty = -(anchorY * height);
|
|
3289
|
+
}
|
|
3290
|
+
// apply clip shape's RTS
|
|
3291
|
+
if (matrix) {
|
|
3292
|
+
copy(this.tmpMat4, object.getLocalTransform());
|
|
3293
|
+
this.vec3a[0] = tx;
|
|
3294
|
+
this.vec3a[1] = ty;
|
|
3295
|
+
this.vec3a[2] = 0;
|
|
3296
|
+
translate(this.tmpMat4, this.tmpMat4, this.vec3a);
|
|
3297
|
+
multiply(this.tmpMat4, matrix, this.tmpMat4);
|
|
3298
|
+
multiply(this.tmpMat4, this.vpMatrix, this.tmpMat4);
|
|
3299
|
+
} else {
|
|
3300
|
+
// apply RTS transformation in world space
|
|
3301
|
+
copy(this.tmpMat4, object.getWorldTransform());
|
|
3302
|
+
this.vec3a[0] = tx;
|
|
3303
|
+
this.vec3a[1] = ty;
|
|
3304
|
+
this.vec3a[2] = 0;
|
|
3305
|
+
translate(this.tmpMat4, this.tmpMat4, this.vec3a);
|
|
3306
|
+
multiply(this.tmpMat4, this.vpMatrix, this.tmpMat4);
|
|
3307
|
+
}
|
|
3308
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
|
|
3309
|
+
context.setTransform(this.tmpMat4[0], this.tmpMat4[1], this.tmpMat4[4], this.tmpMat4[5], this.tmpMat4[12], this.tmpMat4[13]);
|
|
3310
|
+
};
|
|
3311
|
+
_proto.safeMergeAABB = function safeMergeAABB() {
|
|
3312
|
+
var merged = new gLite.AABB();
|
|
3313
|
+
for (var _len = arguments.length, aabbs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3314
|
+
aabbs[_key] = arguments[_key];
|
|
3315
|
+
}
|
|
3316
|
+
aabbs.forEach(function (aabb) {
|
|
3317
|
+
merged.add(aabb);
|
|
3318
|
+
});
|
|
3319
|
+
return merged;
|
|
3320
|
+
};
|
|
3321
|
+
return CanvasRendererPlugin;
|
|
3322
|
+
}();
|
|
3323
|
+
CanvasRendererPlugin.tag = 'CanvasRenderer';
|
|
3324
|
+
var DefaultRenderer = /*#__PURE__*/function () {
|
|
3325
|
+
function DefaultRenderer(imagePool) {
|
|
3326
|
+
this.imagePool = void 0;
|
|
3327
|
+
this.imagePool = imagePool;
|
|
3328
|
+
}
|
|
3329
|
+
var _proto = DefaultRenderer.prototype;
|
|
3330
|
+
_proto.render = function render(context, parsedStyle, object, canvasContext, plugin, runtime) {
|
|
3331
|
+
var fill = parsedStyle.fill,
|
|
3332
|
+
fillRule = parsedStyle.fillRule,
|
|
3333
|
+
opacity = parsedStyle.opacity,
|
|
3334
|
+
fillOpacity = parsedStyle.fillOpacity,
|
|
3335
|
+
stroke = parsedStyle.stroke,
|
|
3336
|
+
strokeOpacity = parsedStyle.strokeOpacity,
|
|
3337
|
+
lineWidth = parsedStyle.lineWidth,
|
|
3338
|
+
lineCap = parsedStyle.lineCap,
|
|
3339
|
+
lineJoin = parsedStyle.lineJoin,
|
|
3340
|
+
shadowType = parsedStyle.shadowType,
|
|
3341
|
+
shadowColor = parsedStyle.shadowColor,
|
|
3342
|
+
shadowBlur = parsedStyle.shadowBlur,
|
|
3343
|
+
filter = parsedStyle.filter,
|
|
3344
|
+
miterLimit = parsedStyle.miterLimit;
|
|
3345
|
+
var hasFill = !isNil(fill) && !fill.isNone;
|
|
3346
|
+
var hasStroke = !isNil(stroke) && !stroke.isNone && lineWidth > 0;
|
|
3347
|
+
var isFillTransparent = fill.alpha === 0;
|
|
3348
|
+
var hasFilter = !!(filter && filter.length);
|
|
3349
|
+
var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
|
|
3350
|
+
var nodeName = object.nodeName;
|
|
3351
|
+
var isInnerShadow = shadowType === 'inner';
|
|
3352
|
+
var shouldDrawShadowWithStroke = hasStroke && hasShadow && (nodeName === gLite.Shape.PATH || nodeName === gLite.Shape.LINE || nodeName === gLite.Shape.POLYLINE || isFillTransparent || isInnerShadow);
|
|
3353
|
+
if (hasFill) {
|
|
3354
|
+
context.globalAlpha = opacity * fillOpacity;
|
|
3355
|
+
if (!shouldDrawShadowWithStroke) {
|
|
3356
|
+
setShadowAndFilter(object, context, hasShadow);
|
|
4567
3357
|
}
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
removeMouseEventListener($el);
|
|
3358
|
+
this.fill(context, object, fill, fillRule, canvasContext, plugin, runtime);
|
|
3359
|
+
if (!shouldDrawShadowWithStroke) {
|
|
3360
|
+
this.clearShadowAndFilter(context, hasFilter, hasShadow);
|
|
4572
3361
|
}
|
|
4573
|
-
|
|
4574
|
-
|
|
3362
|
+
}
|
|
3363
|
+
if (hasStroke) {
|
|
3364
|
+
context.globalAlpha = opacity * strokeOpacity;
|
|
3365
|
+
context.lineWidth = lineWidth;
|
|
3366
|
+
if (!isNil(miterLimit)) {
|
|
3367
|
+
context.miterLimit = miterLimit;
|
|
4575
3368
|
}
|
|
4576
|
-
if (
|
|
4577
|
-
|
|
3369
|
+
if (!isNil(lineCap)) {
|
|
3370
|
+
context.lineCap = lineCap;
|
|
4578
3371
|
}
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
3372
|
+
if (!isNil(lineJoin)) {
|
|
3373
|
+
context.lineJoin = lineJoin;
|
|
3374
|
+
}
|
|
3375
|
+
if (shouldDrawShadowWithStroke) {
|
|
3376
|
+
if (isInnerShadow) {
|
|
3377
|
+
context.globalCompositeOperation = 'source-atop';
|
|
3378
|
+
}
|
|
3379
|
+
setShadowAndFilter(object, context, true);
|
|
3380
|
+
if (isInnerShadow) {
|
|
3381
|
+
this.stroke(context, object, stroke, canvasContext, plugin, runtime);
|
|
3382
|
+
context.globalCompositeOperation = 'source-over';
|
|
3383
|
+
this.clearShadowAndFilter(context, hasFilter, true);
|
|
3384
|
+
}
|
|
3385
|
+
}
|
|
3386
|
+
this.stroke(context, object, stroke, canvasContext, plugin, runtime);
|
|
4591
3387
|
}
|
|
4592
|
-
_this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
|
|
4593
|
-
_this.name = 'dom-interaction';
|
|
4594
|
-
return _this;
|
|
4595
|
-
}
|
|
4596
|
-
var _proto = Plugin.prototype;
|
|
4597
|
-
_proto.init = function init() {
|
|
4598
|
-
this.addRenderingPlugin(new DOMInteractionPlugin());
|
|
4599
3388
|
};
|
|
4600
|
-
_proto.
|
|
4601
|
-
|
|
3389
|
+
_proto.clearShadowAndFilter = function clearShadowAndFilter(context, hasFilter, hasShadow) {
|
|
3390
|
+
if (hasShadow) {
|
|
3391
|
+
context.shadowColor = 'transparent';
|
|
3392
|
+
context.shadowBlur = 0;
|
|
3393
|
+
}
|
|
3394
|
+
if (hasFilter) {
|
|
3395
|
+
// save drop-shadow filter
|
|
3396
|
+
var oldFilter = context.filter;
|
|
3397
|
+
if (!isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
|
|
3398
|
+
context.filter = oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || 'none';
|
|
3399
|
+
}
|
|
3400
|
+
}
|
|
4602
3401
|
};
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
3402
|
+
_proto.fill = function fill(context, object, _fill, fillRule, canvasContext, plugin, runtime) {
|
|
3403
|
+
var _this = this;
|
|
3404
|
+
if (Array.isArray(_fill)) {
|
|
3405
|
+
_fill.forEach(function (gradient) {
|
|
3406
|
+
context.fillStyle = _this.getColor(gradient, object, context);
|
|
3407
|
+
fillRule ? context.fill(fillRule) : context.fill();
|
|
3408
|
+
});
|
|
3409
|
+
} else {
|
|
3410
|
+
if (gLite.isPattern(_fill)) {
|
|
3411
|
+
context.fillStyle = this.getPattern(_fill, object, context, canvasContext, plugin, runtime);
|
|
3412
|
+
}
|
|
3413
|
+
fillRule ? context.fill(fillRule) : context.fill();
|
|
3414
|
+
}
|
|
4614
3415
|
};
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
value: value,
|
|
4628
|
-
enumerable: !0,
|
|
4629
|
-
configurable: !0,
|
|
4630
|
-
writable: !0
|
|
4631
|
-
}), obj[key];
|
|
4632
|
-
}
|
|
4633
|
-
try {
|
|
4634
|
-
define({}, "");
|
|
4635
|
-
} catch (err) {
|
|
4636
|
-
define = function define(obj, key, value) {
|
|
4637
|
-
return obj[key] = value;
|
|
4638
|
-
};
|
|
4639
|
-
}
|
|
4640
|
-
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
4641
|
-
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
|
|
4642
|
-
generator = Object.create(protoGenerator.prototype),
|
|
4643
|
-
context = new Context(tryLocsList || []);
|
|
4644
|
-
return defineProperty(generator, "_invoke", {
|
|
4645
|
-
value: makeInvokeMethod(innerFn, self, context)
|
|
4646
|
-
}), generator;
|
|
4647
|
-
}
|
|
4648
|
-
function tryCatch(fn, obj, arg) {
|
|
4649
|
-
try {
|
|
4650
|
-
return {
|
|
4651
|
-
type: "normal",
|
|
4652
|
-
arg: fn.call(obj, arg)
|
|
4653
|
-
};
|
|
4654
|
-
} catch (err) {
|
|
4655
|
-
return {
|
|
4656
|
-
type: "throw",
|
|
4657
|
-
arg: err
|
|
4658
|
-
};
|
|
3416
|
+
_proto.stroke = function stroke(context, object, _stroke, canvasContext, plugin, runtime) {
|
|
3417
|
+
var _this2 = this;
|
|
3418
|
+
if (Array.isArray(_stroke)) {
|
|
3419
|
+
_stroke.forEach(function (gradient) {
|
|
3420
|
+
context.strokeStyle = _this2.getColor(gradient, object, context);
|
|
3421
|
+
context.stroke();
|
|
3422
|
+
});
|
|
3423
|
+
} else {
|
|
3424
|
+
if (gLite.isPattern(_stroke)) {
|
|
3425
|
+
context.strokeStyle = this.getPattern(_stroke, object, context, canvasContext, plugin, runtime);
|
|
3426
|
+
}
|
|
3427
|
+
context.stroke();
|
|
4659
3428
|
}
|
|
4660
|
-
}
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
3429
|
+
};
|
|
3430
|
+
_proto.getPattern = function getPattern(pattern, object, context, canvasContext, plugin, runtime) {
|
|
3431
|
+
var $offscreenCanvas;
|
|
3432
|
+
var dpr;
|
|
3433
|
+
if (pattern.image.nodeName === 'rect') {
|
|
3434
|
+
var _pattern$image$parsed = pattern.image.parsedStyle,
|
|
3435
|
+
width = _pattern$image$parsed.width,
|
|
3436
|
+
height = _pattern$image$parsed.height;
|
|
3437
|
+
dpr = canvasContext.contextService.getDPR();
|
|
3438
|
+
var offscreenCanvas = canvasContext.config.offscreenCanvas;
|
|
3439
|
+
$offscreenCanvas = runtime.offscreenCanvas.getOrCreateCanvas(offscreenCanvas);
|
|
3440
|
+
$offscreenCanvas.width = width * dpr;
|
|
3441
|
+
$offscreenCanvas.height = height * dpr;
|
|
3442
|
+
var offscreenCanvasContext = runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas);
|
|
3443
|
+
var restoreStack = [];
|
|
3444
|
+
// offscreenCanvasContext.scale(1 / dpr, 1 / dpr);
|
|
3445
|
+
pattern.image.forEach(function (object) {
|
|
3446
|
+
plugin.renderDisplayObject(object, offscreenCanvasContext, canvasContext, restoreStack, runtime);
|
|
3447
|
+
});
|
|
3448
|
+
restoreStack.forEach(function () {
|
|
3449
|
+
offscreenCanvasContext.restore();
|
|
4678
3450
|
});
|
|
4679
|
-
});
|
|
4680
|
-
}
|
|
4681
|
-
function AsyncIterator(generator, PromiseImpl) {
|
|
4682
|
-
function invoke(method, arg, resolve, reject) {
|
|
4683
|
-
var record = tryCatch(generator[method], generator, arg);
|
|
4684
|
-
if ("throw" !== record.type) {
|
|
4685
|
-
var result = record.arg,
|
|
4686
|
-
value = result.value;
|
|
4687
|
-
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
|
|
4688
|
-
invoke("next", value, resolve, reject);
|
|
4689
|
-
}, function (err) {
|
|
4690
|
-
invoke("throw", err, resolve, reject);
|
|
4691
|
-
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
|
|
4692
|
-
result.value = unwrapped, resolve(result);
|
|
4693
|
-
}, function (error) {
|
|
4694
|
-
return invoke("throw", error, resolve, reject);
|
|
4695
|
-
});
|
|
4696
|
-
}
|
|
4697
|
-
reject(record.arg);
|
|
4698
3451
|
}
|
|
4699
|
-
var
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
return new PromiseImpl(function (resolve, reject) {
|
|
4704
|
-
invoke(method, arg, resolve, reject);
|
|
4705
|
-
});
|
|
4706
|
-
}
|
|
4707
|
-
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
4708
|
-
}
|
|
3452
|
+
var canvasPattern = this.imagePool.getOrCreatePatternSync(pattern, context, $offscreenCanvas, dpr, function () {
|
|
3453
|
+
// set dirty rectangle flag
|
|
3454
|
+
object.renderable.dirty = true;
|
|
3455
|
+
canvasContext.renderingService.dirtify();
|
|
4709
3456
|
});
|
|
3457
|
+
return canvasPattern;
|
|
3458
|
+
};
|
|
3459
|
+
_proto.getColor = function getColor(parsedColor, object, context) {
|
|
3460
|
+
var color;
|
|
3461
|
+
if (parsedColor.type === gLite.GradientType.LinearGradient || parsedColor.type === gLite.GradientType.RadialGradient) {
|
|
3462
|
+
var bounds = object.getGeometryBounds();
|
|
3463
|
+
var width = bounds && bounds.halfExtents[0] * 2 || 1;
|
|
3464
|
+
var height = bounds && bounds.halfExtents[1] * 2 || 1;
|
|
3465
|
+
color = this.imagePool.getOrCreateGradient(_extends({
|
|
3466
|
+
type: parsedColor.type
|
|
3467
|
+
}, parsedColor.value, {
|
|
3468
|
+
width: width,
|
|
3469
|
+
height: height
|
|
3470
|
+
}), context);
|
|
3471
|
+
}
|
|
3472
|
+
return color;
|
|
3473
|
+
};
|
|
3474
|
+
return DefaultRenderer;
|
|
3475
|
+
}();
|
|
3476
|
+
/**
|
|
3477
|
+
* apply before fill and stroke but only once
|
|
3478
|
+
*/
|
|
3479
|
+
function setShadowAndFilter(object, context, hasShadow) {
|
|
3480
|
+
var _object$parsedStyle = object.parsedStyle,
|
|
3481
|
+
filter = _object$parsedStyle.filter,
|
|
3482
|
+
shadowColor = _object$parsedStyle.shadowColor,
|
|
3483
|
+
shadowBlur = _object$parsedStyle.shadowBlur,
|
|
3484
|
+
shadowOffsetX = _object$parsedStyle.shadowOffsetX,
|
|
3485
|
+
shadowOffsetY = _object$parsedStyle.shadowOffsetY;
|
|
3486
|
+
if (filter && filter.length) {
|
|
3487
|
+
// use raw filter string
|
|
3488
|
+
context.filter = object.style.filter;
|
|
4710
3489
|
}
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
if ("throw" === method) throw arg;
|
|
4717
|
-
return doneResult();
|
|
4718
|
-
}
|
|
4719
|
-
for (context.method = method, context.arg = arg;;) {
|
|
4720
|
-
var delegate = context.delegate;
|
|
4721
|
-
if (delegate) {
|
|
4722
|
-
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
4723
|
-
if (delegateResult) {
|
|
4724
|
-
if (delegateResult === ContinueSentinel) continue;
|
|
4725
|
-
return delegateResult;
|
|
4726
|
-
}
|
|
4727
|
-
}
|
|
4728
|
-
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
|
|
4729
|
-
if ("suspendedStart" === state) throw state = "completed", context.arg;
|
|
4730
|
-
context.dispatchException(context.arg);
|
|
4731
|
-
} else "return" === context.method && context.abrupt("return", context.arg);
|
|
4732
|
-
state = "executing";
|
|
4733
|
-
var record = tryCatch(innerFn, self, context);
|
|
4734
|
-
if ("normal" === record.type) {
|
|
4735
|
-
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
|
|
4736
|
-
return {
|
|
4737
|
-
value: record.arg,
|
|
4738
|
-
done: context.done
|
|
4739
|
-
};
|
|
4740
|
-
}
|
|
4741
|
-
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
|
|
4742
|
-
}
|
|
4743
|
-
};
|
|
4744
|
-
}
|
|
4745
|
-
function maybeInvokeDelegate(delegate, context) {
|
|
4746
|
-
var methodName = context.method,
|
|
4747
|
-
method = delegate.iterator[methodName];
|
|
4748
|
-
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
|
|
4749
|
-
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
4750
|
-
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
|
|
4751
|
-
var info = record.arg;
|
|
4752
|
-
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
|
|
4753
|
-
}
|
|
4754
|
-
function pushTryEntry(locs) {
|
|
4755
|
-
var entry = {
|
|
4756
|
-
tryLoc: locs[0]
|
|
4757
|
-
};
|
|
4758
|
-
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
|
|
4759
|
-
}
|
|
4760
|
-
function resetTryEntry(entry) {
|
|
4761
|
-
var record = entry.completion || {};
|
|
4762
|
-
record.type = "normal", delete record.arg, entry.completion = record;
|
|
3490
|
+
if (hasShadow) {
|
|
3491
|
+
context.shadowColor = shadowColor.toString();
|
|
3492
|
+
context.shadowBlur = shadowBlur || 0;
|
|
3493
|
+
context.shadowOffsetX = shadowOffsetX || 0;
|
|
3494
|
+
context.shadowOffsetY = shadowOffsetY || 0;
|
|
4763
3495
|
}
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
3496
|
+
}
|
|
3497
|
+
var ImageRenderer = /*#__PURE__*/function () {
|
|
3498
|
+
function ImageRenderer(imagePool) {
|
|
3499
|
+
this.imagePool = void 0;
|
|
3500
|
+
this.imagePool = imagePool;
|
|
4768
3501
|
}
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
3502
|
+
var _proto = ImageRenderer.prototype;
|
|
3503
|
+
_proto.render = function render(context, parsedStyle, object) {
|
|
3504
|
+
var width = parsedStyle.width,
|
|
3505
|
+
height = parsedStyle.height,
|
|
3506
|
+
img = parsedStyle.img,
|
|
3507
|
+
shadowColor = parsedStyle.shadowColor,
|
|
3508
|
+
shadowBlur = parsedStyle.shadowBlur;
|
|
3509
|
+
var image;
|
|
3510
|
+
var iw = width;
|
|
3511
|
+
var ih = height;
|
|
3512
|
+
if (isString(img)) {
|
|
3513
|
+
// image has been loaded in `mounted` hook
|
|
3514
|
+
image = this.imagePool.getImageSync(img);
|
|
3515
|
+
} else {
|
|
3516
|
+
iw || (iw = img.width);
|
|
3517
|
+
ih || (ih = img.height);
|
|
3518
|
+
image = img;
|
|
4782
3519
|
}
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
}
|
|
4792
|
-
}
|
|
4793
|
-
return
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
}
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
3520
|
+
if (image) {
|
|
3521
|
+
var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
|
|
3522
|
+
setShadowAndFilter(object, context, hasShadow);
|
|
3523
|
+
// node-canvas will throw the following err:
|
|
3524
|
+
// Error: Image given has not completed loading
|
|
3525
|
+
try {
|
|
3526
|
+
context.drawImage(image, 0, 0, iw, ih);
|
|
3527
|
+
} catch (e) {}
|
|
3528
|
+
}
|
|
3529
|
+
};
|
|
3530
|
+
return ImageRenderer;
|
|
3531
|
+
}();
|
|
3532
|
+
var TextRenderer = /*#__PURE__*/function () {
|
|
3533
|
+
function TextRenderer() {}
|
|
3534
|
+
var _proto = TextRenderer.prototype;
|
|
3535
|
+
_proto.render = function render(context, parsedStyle, object) {
|
|
3536
|
+
var lineWidth = parsedStyle.lineWidth,
|
|
3537
|
+
textAlign = parsedStyle.textAlign,
|
|
3538
|
+
textBaseline = parsedStyle.textBaseline,
|
|
3539
|
+
lineJoin = parsedStyle.lineJoin,
|
|
3540
|
+
miterLimit = parsedStyle.miterLimit,
|
|
3541
|
+
letterSpacing = parsedStyle.letterSpacing,
|
|
3542
|
+
stroke = parsedStyle.stroke,
|
|
3543
|
+
fill = parsedStyle.fill,
|
|
3544
|
+
fillOpacity = parsedStyle.fillOpacity,
|
|
3545
|
+
strokeOpacity = parsedStyle.strokeOpacity,
|
|
3546
|
+
opacity = parsedStyle.opacity,
|
|
3547
|
+
metrics = parsedStyle.metrics,
|
|
3548
|
+
dx = parsedStyle.dx,
|
|
3549
|
+
dy = parsedStyle.dy,
|
|
3550
|
+
shadowColor = parsedStyle.shadowColor,
|
|
3551
|
+
shadowBlur = parsedStyle.shadowBlur;
|
|
3552
|
+
var font = metrics.font,
|
|
3553
|
+
lines = metrics.lines,
|
|
3554
|
+
height = metrics.height,
|
|
3555
|
+
lineHeight = metrics.lineHeight,
|
|
3556
|
+
lineMetrics = metrics.lineMetrics;
|
|
3557
|
+
context.font = font;
|
|
3558
|
+
context.lineWidth = lineWidth;
|
|
3559
|
+
context.textAlign = textAlign === 'middle' ? 'center' : textAlign;
|
|
3560
|
+
var formattedTextBaseline = textBaseline;
|
|
3561
|
+
if (
|
|
3562
|
+
// formattedTextBaseline === 'bottom' ||
|
|
3563
|
+
!gLite.runtime.enableCSSParsing && formattedTextBaseline === 'alphabetic') {
|
|
3564
|
+
formattedTextBaseline = 'bottom';
|
|
3565
|
+
}
|
|
3566
|
+
context.lineJoin = lineJoin;
|
|
3567
|
+
if (!isNil(miterLimit)) {
|
|
3568
|
+
context.miterLimit = miterLimit;
|
|
3569
|
+
}
|
|
3570
|
+
var linePositionY = 0;
|
|
3571
|
+
// handle vertical text baseline
|
|
3572
|
+
if (textBaseline === 'middle') {
|
|
3573
|
+
linePositionY = -height / 2 - lineHeight / 2;
|
|
3574
|
+
} else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
|
|
3575
|
+
linePositionY = -height;
|
|
3576
|
+
} else if (textBaseline === 'top' || textBaseline === 'hanging') {
|
|
3577
|
+
linePositionY = -lineHeight;
|
|
3578
|
+
}
|
|
3579
|
+
// account for dx & dy
|
|
3580
|
+
var offsetX = dx || 0;
|
|
3581
|
+
linePositionY += dy || 0;
|
|
3582
|
+
if (lines.length === 1) {
|
|
3583
|
+
if (formattedTextBaseline === 'bottom') {
|
|
3584
|
+
formattedTextBaseline = 'middle';
|
|
3585
|
+
linePositionY -= 0.5 * height;
|
|
3586
|
+
} else if (formattedTextBaseline === 'top') {
|
|
3587
|
+
formattedTextBaseline = 'middle';
|
|
3588
|
+
linePositionY += 0.5 * height;
|
|
4847
3589
|
}
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
} else {
|
|
4861
|
-
if (!hasFinally) throw new Error("try statement without catch or finally");
|
|
4862
|
-
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
4863
|
-
}
|
|
4864
|
-
}
|
|
3590
|
+
}
|
|
3591
|
+
context.textBaseline = formattedTextBaseline;
|
|
3592
|
+
var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
|
|
3593
|
+
setShadowAndFilter(object, context, hasShadow);
|
|
3594
|
+
// draw lines line by line
|
|
3595
|
+
for (var i = 0; i < lines.length; i++) {
|
|
3596
|
+
var linePositionX = lineWidth / 2 + offsetX;
|
|
3597
|
+
linePositionY += lineHeight;
|
|
3598
|
+
// no need to re-position X, cause we already set text align
|
|
3599
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
|
|
3600
|
+
if (!isNil(stroke) && !stroke.isNone && lineWidth) {
|
|
3601
|
+
this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign, linePositionX, linePositionY, letterSpacing, fillOpacity, strokeOpacity, opacity, true);
|
|
4865
3602
|
}
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
4869
|
-
var entry = this.tryEntries[i];
|
|
4870
|
-
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
|
4871
|
-
var finallyEntry = entry;
|
|
4872
|
-
break;
|
|
4873
|
-
}
|
|
3603
|
+
if (!isNil(fill)) {
|
|
3604
|
+
this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign, linePositionX, linePositionY, letterSpacing, fillOpacity, strokeOpacity, opacity);
|
|
4874
3605
|
}
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
3606
|
+
}
|
|
3607
|
+
};
|
|
3608
|
+
_proto.drawLetterSpacing = function drawLetterSpacing(context, text, lineMetrics, textAlign, x, y, letterSpacing, fillOpacity, strokeOpacity, opacity, isStroke) {
|
|
3609
|
+
if (isStroke === void 0) {
|
|
3610
|
+
isStroke = false;
|
|
3611
|
+
}
|
|
3612
|
+
// letterSpacing of 0 means normal, render all texts directly
|
|
3613
|
+
if (letterSpacing === 0) {
|
|
3614
|
+
if (isStroke) {
|
|
3615
|
+
this.strokeText(context, text, x, y, strokeOpacity);
|
|
3616
|
+
} else {
|
|
3617
|
+
this.fillText(context, text, x, y, fillOpacity, opacity);
|
|
4887
3618
|
}
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
3619
|
+
return;
|
|
3620
|
+
}
|
|
3621
|
+
// draw text using left align
|
|
3622
|
+
var currentTextAlign = context.textAlign;
|
|
3623
|
+
context.textAlign = 'left';
|
|
3624
|
+
var currentPosition = x;
|
|
3625
|
+
if (textAlign === 'center' || textAlign === 'middle') {
|
|
3626
|
+
currentPosition = x - lineMetrics.width / 2;
|
|
3627
|
+
} else if (textAlign === 'right' || textAlign === 'end') {
|
|
3628
|
+
currentPosition = x - lineMetrics.width;
|
|
3629
|
+
}
|
|
3630
|
+
var stringArray = Array.from(text);
|
|
3631
|
+
var previousWidth = context.measureText(text).width;
|
|
3632
|
+
var currentWidth = 0;
|
|
3633
|
+
for (var i = 0; i < stringArray.length; ++i) {
|
|
3634
|
+
var currentChar = stringArray[i];
|
|
3635
|
+
if (isStroke) {
|
|
3636
|
+
this.strokeText(context, currentChar, currentPosition, y, strokeOpacity);
|
|
3637
|
+
} else {
|
|
3638
|
+
this.fillText(context, currentChar, currentPosition, y, fillOpacity, opacity);
|
|
4900
3639
|
}
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
return this.delegate = {
|
|
4905
|
-
iterator: values(iterable),
|
|
4906
|
-
resultName: resultName,
|
|
4907
|
-
nextLoc: nextLoc
|
|
4908
|
-
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
|
|
3640
|
+
currentWidth = context.measureText(text.substring(i + 1)).width;
|
|
3641
|
+
currentPosition += previousWidth - currentWidth + letterSpacing;
|
|
3642
|
+
previousWidth = currentWidth;
|
|
4909
3643
|
}
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
var
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
3644
|
+
context.textAlign = currentTextAlign;
|
|
3645
|
+
};
|
|
3646
|
+
_proto.fillText = function fillText(context, text, x, y, fillOpacity, opacity) {
|
|
3647
|
+
var currentGlobalAlpha;
|
|
3648
|
+
var applyOpacity = !isNil(fillOpacity) && fillOpacity !== 1;
|
|
3649
|
+
if (applyOpacity) {
|
|
3650
|
+
currentGlobalAlpha = context.globalAlpha;
|
|
3651
|
+
context.globalAlpha = fillOpacity * opacity;
|
|
3652
|
+
}
|
|
3653
|
+
context.fillText(text, x, y);
|
|
3654
|
+
if (applyOpacity) {
|
|
3655
|
+
context.globalAlpha = currentGlobalAlpha;
|
|
3656
|
+
}
|
|
3657
|
+
};
|
|
3658
|
+
_proto.strokeText = function strokeText(context, text, x, y, strokeOpacity) {
|
|
3659
|
+
var currentGlobalAlpha;
|
|
3660
|
+
var applyOpacity = !isNil(strokeOpacity) && strokeOpacity !== 1;
|
|
3661
|
+
if (applyOpacity) {
|
|
3662
|
+
currentGlobalAlpha = context.globalAlpha;
|
|
3663
|
+
context.globalAlpha = strokeOpacity;
|
|
3664
|
+
}
|
|
3665
|
+
context.strokeText(text, x, y);
|
|
3666
|
+
if (applyOpacity) {
|
|
3667
|
+
context.globalAlpha = currentGlobalAlpha;
|
|
3668
|
+
}
|
|
3669
|
+
};
|
|
3670
|
+
return TextRenderer;
|
|
3671
|
+
}();
|
|
3672
|
+
var RectRenderer = /*#__PURE__*/function (_DefaultRenderer) {
|
|
3673
|
+
_inheritsLoose$3(RectRenderer, _DefaultRenderer);
|
|
3674
|
+
function RectRenderer() {
|
|
3675
|
+
return _DefaultRenderer.apply(this, arguments) || this;
|
|
4919
3676
|
}
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
3677
|
+
return RectRenderer;
|
|
3678
|
+
}(DefaultRenderer);
|
|
3679
|
+
var CircleRenderer = /*#__PURE__*/function (_DefaultRenderer) {
|
|
3680
|
+
_inheritsLoose$3(CircleRenderer, _DefaultRenderer);
|
|
3681
|
+
function CircleRenderer() {
|
|
3682
|
+
return _DefaultRenderer.apply(this, arguments) || this;
|
|
4924
3683
|
}
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
return
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
3684
|
+
return CircleRenderer;
|
|
3685
|
+
}(DefaultRenderer);
|
|
3686
|
+
var EllipseRenderer = /*#__PURE__*/function (_DefaultRenderer) {
|
|
3687
|
+
_inheritsLoose$3(EllipseRenderer, _DefaultRenderer);
|
|
3688
|
+
function EllipseRenderer() {
|
|
3689
|
+
return _DefaultRenderer.apply(this, arguments) || this;
|
|
3690
|
+
}
|
|
3691
|
+
return EllipseRenderer;
|
|
3692
|
+
}(DefaultRenderer);
|
|
3693
|
+
var LineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
|
|
3694
|
+
_inheritsLoose$3(LineRenderer, _DefaultRenderer);
|
|
3695
|
+
function LineRenderer() {
|
|
3696
|
+
return _DefaultRenderer.apply(this, arguments) || this;
|
|
3697
|
+
}
|
|
3698
|
+
return LineRenderer;
|
|
3699
|
+
}(DefaultRenderer);
|
|
3700
|
+
var PolylineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
|
|
3701
|
+
_inheritsLoose$3(PolylineRenderer, _DefaultRenderer);
|
|
3702
|
+
function PolylineRenderer() {
|
|
3703
|
+
return _DefaultRenderer.apply(this, arguments) || this;
|
|
3704
|
+
}
|
|
3705
|
+
return PolylineRenderer;
|
|
3706
|
+
}(DefaultRenderer);
|
|
3707
|
+
var PolygonRenderer = /*#__PURE__*/function (_DefaultRenderer) {
|
|
3708
|
+
_inheritsLoose$3(PolygonRenderer, _DefaultRenderer);
|
|
3709
|
+
function PolygonRenderer() {
|
|
3710
|
+
return _DefaultRenderer.apply(this, arguments) || this;
|
|
3711
|
+
}
|
|
3712
|
+
return PolygonRenderer;
|
|
3713
|
+
}(DefaultRenderer);
|
|
3714
|
+
var PathRenderer = /*#__PURE__*/function (_DefaultRenderer) {
|
|
3715
|
+
_inheritsLoose$3(PathRenderer, _DefaultRenderer);
|
|
3716
|
+
function PathRenderer() {
|
|
3717
|
+
return _DefaultRenderer.apply(this, arguments) || this;
|
|
3718
|
+
}
|
|
3719
|
+
return PathRenderer;
|
|
3720
|
+
}(DefaultRenderer);
|
|
3721
|
+
var Plugin$2 = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
3722
|
+
_inheritsLoose$3(Plugin, _AbstractRendererPlug);
|
|
3723
|
+
function Plugin(options) {
|
|
3724
|
+
var _this;
|
|
3725
|
+
if (options === void 0) {
|
|
3726
|
+
options = {};
|
|
3727
|
+
}
|
|
3728
|
+
_this = _AbstractRendererPlug.call(this) || this;
|
|
3729
|
+
_this.options = void 0;
|
|
3730
|
+
_this.name = 'canvas-renderer';
|
|
3731
|
+
_this.options = options;
|
|
3732
|
+
return _this;
|
|
3733
|
+
}
|
|
3734
|
+
var _proto = Plugin.prototype;
|
|
3735
|
+
_proto.init = function init() {
|
|
3736
|
+
var _defaultStyleRenderer;
|
|
3737
|
+
var canvasRendererPluginOptions = _extends({
|
|
3738
|
+
dirtyObjectNumThreshold: 500,
|
|
3739
|
+
dirtyObjectRatioThreshold: 0.8
|
|
3740
|
+
}, this.options);
|
|
3741
|
+
// @ts-ignore
|
|
3742
|
+
var imagePool = this.context.imagePool;
|
|
3743
|
+
var defaultRenderer = new DefaultRenderer(imagePool);
|
|
3744
|
+
var defaultStyleRendererFactory = (_defaultStyleRenderer = {}, _defaultStyleRenderer[gLite.Shape.CIRCLE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.ELLIPSE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.RECT] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.IMAGE] = new ImageRenderer(imagePool), _defaultStyleRenderer[gLite.Shape.TEXT] = new TextRenderer(), _defaultStyleRenderer[gLite.Shape.LINE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.POLYLINE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.POLYGON] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.PATH] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.GROUP] = undefined, _defaultStyleRenderer[gLite.Shape.HTML] = undefined, _defaultStyleRenderer[gLite.Shape.MESH] = undefined, _defaultStyleRenderer);
|
|
3745
|
+
this.context.defaultStyleRendererFactory = defaultStyleRendererFactory;
|
|
3746
|
+
this.context.styleRendererFactory = defaultStyleRendererFactory;
|
|
3747
|
+
this.addRenderingPlugin(new CanvasRendererPlugin(canvasRendererPluginOptions));
|
|
4940
3748
|
};
|
|
4941
|
-
|
|
4942
|
-
|
|
3749
|
+
_proto.destroy = function destroy() {
|
|
3750
|
+
this.removeAllRenderingPlugins();
|
|
3751
|
+
delete this.context.defaultStyleRendererFactory;
|
|
3752
|
+
delete this.context.styleRendererFactory;
|
|
3753
|
+
};
|
|
3754
|
+
return Plugin;
|
|
3755
|
+
}(gLite.AbstractRendererPlugin);
|
|
3756
|
+
|
|
3757
|
+
var index_esm$2 = /*#__PURE__*/Object.freeze({
|
|
3758
|
+
__proto__: null,
|
|
3759
|
+
CircleRenderer: CircleRenderer,
|
|
3760
|
+
EllipseRenderer: EllipseRenderer,
|
|
3761
|
+
ImageRenderer: ImageRenderer,
|
|
3762
|
+
LineRenderer: LineRenderer,
|
|
3763
|
+
PathRenderer: PathRenderer,
|
|
3764
|
+
Plugin: Plugin$2,
|
|
3765
|
+
PolygonRenderer: PolygonRenderer,
|
|
3766
|
+
PolylineRenderer: PolylineRenderer,
|
|
3767
|
+
RectRenderer: RectRenderer,
|
|
3768
|
+
TextRenderer: TextRenderer
|
|
3769
|
+
});
|
|
3770
|
+
|
|
3771
|
+
function _inheritsLoose$4(subClass, superClass) {
|
|
4943
3772
|
subClass.prototype = Object.create(superClass.prototype);
|
|
4944
3773
|
subClass.prototype.constructor = subClass;
|
|
4945
|
-
_setPrototypeOf$
|
|
3774
|
+
_setPrototypeOf$4(subClass, superClass);
|
|
4946
3775
|
}
|
|
4947
|
-
function _setPrototypeOf$
|
|
4948
|
-
_setPrototypeOf$
|
|
3776
|
+
function _setPrototypeOf$4(o, p) {
|
|
3777
|
+
_setPrototypeOf$4 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
4949
3778
|
o.__proto__ = p;
|
|
4950
3779
|
return o;
|
|
4951
3780
|
};
|
|
4952
|
-
return _setPrototypeOf$
|
|
3781
|
+
return _setPrototypeOf$4(o, p);
|
|
4953
3782
|
}
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
3783
|
+
|
|
3784
|
+
// const MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
|
|
3785
|
+
/**
|
|
3786
|
+
* listen to mouse/touch/pointer events on DOM wrapper, trigger pointer events
|
|
3787
|
+
*/
|
|
3788
|
+
var DOMInteractionPlugin = /*#__PURE__*/function () {
|
|
3789
|
+
function DOMInteractionPlugin() {
|
|
4958
3790
|
this.context = void 0;
|
|
4959
|
-
/**
|
|
4960
|
-
* wrapper for camera
|
|
4961
|
-
*/
|
|
4962
|
-
this.$camera = void 0;
|
|
4963
3791
|
}
|
|
4964
|
-
var _proto =
|
|
4965
|
-
_proto.
|
|
4966
|
-
return "matrix(" + [matrix[0], matrix[1], matrix[4], matrix[5], matrix[12], matrix[13]].join(',') + ")";
|
|
4967
|
-
};
|
|
4968
|
-
_proto.apply = function apply(context) {
|
|
3792
|
+
var _proto = DOMInteractionPlugin.prototype;
|
|
3793
|
+
_proto.apply = function apply(context, runtime) {
|
|
4969
3794
|
var _this = this;
|
|
4970
|
-
var
|
|
3795
|
+
var renderingService = context.renderingService,
|
|
4971
3796
|
renderingContext = context.renderingContext,
|
|
4972
|
-
|
|
3797
|
+
config = context.config;
|
|
4973
3798
|
this.context = context;
|
|
4974
3799
|
var canvas = renderingContext.root.ownerDocument.defaultView;
|
|
4975
|
-
|
|
4976
|
-
|
|
3800
|
+
// const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
|
|
3801
|
+
var onPointerMove = function onPointerMove(ev) {
|
|
3802
|
+
renderingService.hooks.pointerMove.call(ev);
|
|
4977
3803
|
};
|
|
4978
|
-
var
|
|
4979
|
-
|
|
4980
|
-
if (object.nodeName === gLite.Shape.HTML) {
|
|
4981
|
-
if (!_this.$camera) {
|
|
4982
|
-
_this.$camera = _this.createCamera(camera);
|
|
4983
|
-
}
|
|
4984
|
-
// create DOM element
|
|
4985
|
-
var $el = _this.getOrCreateEl(object);
|
|
4986
|
-
_this.$camera.appendChild($el);
|
|
4987
|
-
// apply documentElement's style
|
|
4988
|
-
var attributes = object.ownerDocument.documentElement.attributes;
|
|
4989
|
-
Object.keys(attributes).forEach(function (name) {
|
|
4990
|
-
$el.style[name] = attributes[name];
|
|
4991
|
-
});
|
|
4992
|
-
Object.keys(object.attributes).forEach(function (name) {
|
|
4993
|
-
_this.updateAttribute(name, object);
|
|
4994
|
-
});
|
|
4995
|
-
setTransform(object, $el);
|
|
4996
|
-
gLite.runtime.nativeHTMLMap.set($el, object);
|
|
4997
|
-
}
|
|
3804
|
+
var onPointerUp = function onPointerUp(ev) {
|
|
3805
|
+
renderingService.hooks.pointerUp.call(ev);
|
|
4998
3806
|
};
|
|
4999
|
-
var
|
|
5000
|
-
|
|
5001
|
-
if (object.nodeName === gLite.Shape.HTML && _this.$camera) {
|
|
5002
|
-
var $el = _this.getOrCreateEl(object);
|
|
5003
|
-
if ($el) {
|
|
5004
|
-
$el.remove();
|
|
5005
|
-
gLite.runtime.nativeHTMLMap.delete($el);
|
|
5006
|
-
}
|
|
5007
|
-
// const existedId = this.getId(object);
|
|
5008
|
-
// const $existedElement: HTMLElement | null = this.$camera.querySelector('#' + existedId);
|
|
5009
|
-
// if ($existedElement) {
|
|
5010
|
-
// this.$camera.removeChild($existedElement);
|
|
5011
|
-
// }
|
|
5012
|
-
}
|
|
3807
|
+
var onPointerDown = function onPointerDown(ev) {
|
|
3808
|
+
renderingService.hooks.pointerDown.call(ev);
|
|
5013
3809
|
};
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
var object = e.target;
|
|
5017
|
-
if (object.nodeName === gLite.Shape.HTML) {
|
|
5018
|
-
var attrName = e.attrName;
|
|
5019
|
-
_this.updateAttribute(attrName, object);
|
|
5020
|
-
}
|
|
3810
|
+
var onPointerOver = function onPointerOver(ev) {
|
|
3811
|
+
renderingService.hooks.pointerOver.call(ev);
|
|
5021
3812
|
};
|
|
5022
|
-
var
|
|
5023
|
-
|
|
5024
|
-
if (object.nodeName === gLite.Shape.HTML) {
|
|
5025
|
-
var $el = _this.getOrCreateEl(object);
|
|
5026
|
-
setTransform(object, $el);
|
|
5027
|
-
}
|
|
3813
|
+
var onPointerOut = function onPointerOut(ev) {
|
|
3814
|
+
renderingService.hooks.pointerOut.call(ev);
|
|
5028
3815
|
};
|
|
5029
|
-
var
|
|
5030
|
-
|
|
5031
|
-
var _this$context$config = _this.context.config,
|
|
5032
|
-
width = _this$context$config.width,
|
|
5033
|
-
height = _this$context$config.height;
|
|
5034
|
-
_this.$camera.style.width = (width || 0) + "px";
|
|
5035
|
-
_this.$camera.style.height = (height || 0) + "px";
|
|
5036
|
-
}
|
|
3816
|
+
var onPointerCancel = function onPointerCancel(ev) {
|
|
3817
|
+
renderingService.hooks.pointerCancel.call(ev);
|
|
5037
3818
|
};
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
3819
|
+
var onPointerWheel = function onPointerWheel(ev) {
|
|
3820
|
+
renderingService.hooks.pointerWheel.call(ev);
|
|
3821
|
+
};
|
|
3822
|
+
var onClick = function onClick(ev) {
|
|
3823
|
+
renderingService.hooks.click.call(ev);
|
|
3824
|
+
};
|
|
3825
|
+
var addPointerEventListener = function addPointerEventListener($el) {
|
|
3826
|
+
runtime.globalThis.document.addEventListener('pointermove', onPointerMove, true);
|
|
3827
|
+
$el.addEventListener('pointerdown', onPointerDown, true);
|
|
3828
|
+
$el.addEventListener('pointerleave', onPointerOut, true);
|
|
3829
|
+
$el.addEventListener('pointerover', onPointerOver, true);
|
|
3830
|
+
runtime.globalThis.addEventListener('pointerup', onPointerUp, true);
|
|
3831
|
+
runtime.globalThis.addEventListener('pointercancel', onPointerCancel, true);
|
|
3832
|
+
};
|
|
3833
|
+
var addTouchEventListener = function addTouchEventListener($el) {
|
|
3834
|
+
$el.addEventListener('touchstart', onPointerDown, true);
|
|
3835
|
+
$el.addEventListener('touchend', onPointerUp, true);
|
|
3836
|
+
$el.addEventListener('touchmove', onPointerMove, true);
|
|
3837
|
+
$el.addEventListener('touchcancel', onPointerCancel, true);
|
|
3838
|
+
};
|
|
3839
|
+
var addMouseEventListener = function addMouseEventListener($el) {
|
|
3840
|
+
runtime.globalThis.document.addEventListener('mousemove', onPointerMove, true);
|
|
3841
|
+
$el.addEventListener('mousedown', onPointerDown, true);
|
|
3842
|
+
$el.addEventListener('mouseout', onPointerOut, true);
|
|
3843
|
+
$el.addEventListener('mouseover', onPointerOver, true);
|
|
3844
|
+
runtime.globalThis.addEventListener('mouseup', onPointerUp, true);
|
|
3845
|
+
};
|
|
3846
|
+
var removePointerEventListener = function removePointerEventListener($el) {
|
|
3847
|
+
runtime.globalThis.document.removeEventListener('pointermove', onPointerMove, true);
|
|
3848
|
+
$el.removeEventListener('pointerdown', onPointerDown, true);
|
|
3849
|
+
$el.removeEventListener('pointerleave', onPointerOut, true);
|
|
3850
|
+
$el.removeEventListener('pointerover', onPointerOver, true);
|
|
3851
|
+
runtime.globalThis.removeEventListener('pointerup', onPointerUp, true);
|
|
3852
|
+
};
|
|
3853
|
+
var removeTouchEventListener = function removeTouchEventListener($el) {
|
|
3854
|
+
$el.removeEventListener('touchstart', onPointerDown, true);
|
|
3855
|
+
$el.removeEventListener('touchend', onPointerUp, true);
|
|
3856
|
+
$el.removeEventListener('touchmove', onPointerMove, true);
|
|
3857
|
+
$el.removeEventListener('touchcancel', onPointerCancel, true);
|
|
3858
|
+
};
|
|
3859
|
+
var removeMouseEventListener = function removeMouseEventListener($el) {
|
|
3860
|
+
runtime.globalThis.document.removeEventListener('mousemove', onPointerMove, true);
|
|
3861
|
+
$el.removeEventListener('mousedown', onPointerDown, true);
|
|
3862
|
+
$el.removeEventListener('mouseout', onPointerOut, true);
|
|
3863
|
+
$el.removeEventListener('mouseover', onPointerOver, true);
|
|
3864
|
+
runtime.globalThis.removeEventListener('mouseup', onPointerUp, true);
|
|
3865
|
+
};
|
|
3866
|
+
renderingService.hooks.init.tap(DOMInteractionPlugin.tag, function () {
|
|
3867
|
+
var $el = _this.context.contextService.getDomElement();
|
|
3868
|
+
// @ts-ignore
|
|
3869
|
+
if (runtime.globalThis.navigator.msPointerEnabled) {
|
|
3870
|
+
// @ts-ignore
|
|
3871
|
+
$el.style.msContentZooming = 'none';
|
|
3872
|
+
// @ts-ignore
|
|
3873
|
+
$el.style.msTouchAction = 'none';
|
|
3874
|
+
} else if (canvas.supportsPointerEvents) {
|
|
3875
|
+
$el.style.touchAction = 'none';
|
|
5056
3876
|
}
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
|
|
5061
|
-
_this.$camera.remove();
|
|
3877
|
+
if (canvas.supportsPointerEvents) {
|
|
3878
|
+
addPointerEventListener($el);
|
|
3879
|
+
} else {
|
|
3880
|
+
addMouseEventListener($el);
|
|
5062
3881
|
}
|
|
5063
|
-
canvas.
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
});
|
|
5069
|
-
};
|
|
5070
|
-
_proto.getId = function getId(object) {
|
|
5071
|
-
return object.id || HTML_PREFIX + object.entity;
|
|
5072
|
-
};
|
|
5073
|
-
_proto.createCamera = function createCamera(camera) {
|
|
5074
|
-
var _this$context$config2 = this.context.config,
|
|
5075
|
-
doc = _this$context$config2.document,
|
|
5076
|
-
width = _this$context$config2.width,
|
|
5077
|
-
height = _this$context$config2.height;
|
|
5078
|
-
var $canvas = this.context.contextService.getDomElement();
|
|
5079
|
-
var $container = $canvas.parentNode;
|
|
5080
|
-
if ($container) {
|
|
5081
|
-
var cameraId = CANVAS_CAMERA_ID;
|
|
5082
|
-
var $existedCamera = $container.querySelector('#' + cameraId);
|
|
5083
|
-
if (!$existedCamera) {
|
|
5084
|
-
var $camera = (doc || document).createElement('div');
|
|
5085
|
-
$existedCamera = $camera;
|
|
5086
|
-
$camera.id = cameraId;
|
|
5087
|
-
// use absolute position
|
|
5088
|
-
$camera.style.position = 'absolute';
|
|
5089
|
-
// account for DOM element's offset @see https://github.com/antvis/G/issues/1150
|
|
5090
|
-
$camera.style.left = ($canvas.offsetLeft || 0) + "px";
|
|
5091
|
-
$camera.style.top = ($canvas.offsetTop || 0) + "px";
|
|
5092
|
-
$camera.style.transformOrigin = 'left top';
|
|
5093
|
-
$camera.style.transform = this.joinTransformMatrix(camera.getOrthoMatrix());
|
|
5094
|
-
// HTML elements should not overflow with canvas @see https://github.com/antvis/G/issues/1163
|
|
5095
|
-
$camera.style.overflow = 'hidden';
|
|
5096
|
-
$camera.style.pointerEvents = 'none';
|
|
5097
|
-
$camera.style.width = (width || 0) + "px";
|
|
5098
|
-
$camera.style.height = (height || 0) + "px";
|
|
5099
|
-
$container.appendChild($camera);
|
|
3882
|
+
if (canvas.supportsTouchEvents) {
|
|
3883
|
+
addTouchEventListener($el);
|
|
3884
|
+
}
|
|
3885
|
+
if (config.useNativeClickEvent) {
|
|
3886
|
+
$el.addEventListener('click', onClick, true);
|
|
5100
3887
|
}
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
3888
|
+
// use passive event listeners
|
|
3889
|
+
// @see https://zhuanlan.zhihu.com/p/24555031
|
|
3890
|
+
$el.addEventListener('wheel', onPointerWheel, {
|
|
3891
|
+
passive: true,
|
|
3892
|
+
capture: true
|
|
3893
|
+
});
|
|
3894
|
+
});
|
|
3895
|
+
renderingService.hooks.destroy.tap(DOMInteractionPlugin.tag, function () {
|
|
3896
|
+
var $el = _this.context.contextService.getDomElement();
|
|
3897
|
+
// @ts-ignore
|
|
3898
|
+
if (runtime.globalThis.navigator.msPointerEnabled) {
|
|
3899
|
+
// @ts-ignore
|
|
3900
|
+
$el.style.msContentZooming = '';
|
|
3901
|
+
// @ts-ignore
|
|
3902
|
+
$el.style.msTouchAction = '';
|
|
3903
|
+
} else if (canvas.supportsPointerEvents) {
|
|
3904
|
+
$el.style.touchAction = '';
|
|
5115
3905
|
}
|
|
5116
|
-
if (
|
|
5117
|
-
$
|
|
3906
|
+
if (canvas.supportsPointerEvents) {
|
|
3907
|
+
removePointerEventListener($el);
|
|
3908
|
+
} else {
|
|
3909
|
+
removeMouseEventListener($el);
|
|
5118
3910
|
}
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
$
|
|
5126
|
-
}
|
|
5127
|
-
return $existedElement;
|
|
5128
|
-
};
|
|
5129
|
-
_proto.updateAttribute = function updateAttribute(name, object) {
|
|
5130
|
-
var $el = this.getOrCreateEl(object);
|
|
5131
|
-
switch (name) {
|
|
5132
|
-
case 'innerHTML':
|
|
5133
|
-
var innerHTML = object.parsedStyle.innerHTML;
|
|
5134
|
-
if (isString(innerHTML)) {
|
|
5135
|
-
$el.innerHTML = innerHTML;
|
|
5136
|
-
} else {
|
|
5137
|
-
$el.innerHTML = '';
|
|
5138
|
-
$el.appendChild(innerHTML);
|
|
5139
|
-
}
|
|
5140
|
-
break;
|
|
5141
|
-
case 'transformOrigin':
|
|
5142
|
-
var transformOrigin = object.parsedStyle.transformOrigin;
|
|
5143
|
-
$el.style['transform-origin'] = transformOrigin[0].value + " " + transformOrigin[1].value;
|
|
5144
|
-
break;
|
|
5145
|
-
case 'width':
|
|
5146
|
-
if (gLite.runtime.enableCSSParsing) {
|
|
5147
|
-
var width = object.computedStyleMap().get('width');
|
|
5148
|
-
$el.style.width = width.toString();
|
|
5149
|
-
} else {
|
|
5150
|
-
var _width = object.parsedStyle.width;
|
|
5151
|
-
$el.style.width = isNumber(_width) ? _width + "px" : _width.toString();
|
|
5152
|
-
}
|
|
5153
|
-
break;
|
|
5154
|
-
case 'height':
|
|
5155
|
-
if (gLite.runtime.enableCSSParsing) {
|
|
5156
|
-
var height = object.computedStyleMap().get('height');
|
|
5157
|
-
$el.style.height = height.toString();
|
|
5158
|
-
} else {
|
|
5159
|
-
var _height = object.parsedStyle.height;
|
|
5160
|
-
$el.style.height = isNumber(_height) ? _height + "px" : _height.toString();
|
|
5161
|
-
}
|
|
5162
|
-
break;
|
|
5163
|
-
case 'zIndex':
|
|
5164
|
-
var zIndex = object.parsedStyle.zIndex;
|
|
5165
|
-
$el.style['z-index'] = "" + zIndex;
|
|
5166
|
-
break;
|
|
5167
|
-
case 'visibility':
|
|
5168
|
-
var visibility = object.parsedStyle.visibility;
|
|
5169
|
-
$el.style.visibility = visibility;
|
|
5170
|
-
break;
|
|
5171
|
-
case 'pointerEvents':
|
|
5172
|
-
var pointerEvents = object.parsedStyle.pointerEvents;
|
|
5173
|
-
$el.style.pointerEvents = pointerEvents;
|
|
5174
|
-
break;
|
|
5175
|
-
case 'opacity':
|
|
5176
|
-
var opacity = object.parsedStyle.opacity;
|
|
5177
|
-
$el.style.opacity = "" + opacity;
|
|
5178
|
-
break;
|
|
5179
|
-
case 'fill':
|
|
5180
|
-
var fill = object.parsedStyle.fill;
|
|
5181
|
-
var color = '';
|
|
5182
|
-
if (gLite.isCSSRGB(fill)) {
|
|
5183
|
-
if (fill.isNone) {
|
|
5184
|
-
color = 'transparent';
|
|
5185
|
-
} else {
|
|
5186
|
-
color = object.getAttribute('fill');
|
|
5187
|
-
}
|
|
5188
|
-
} else if (Array.isArray(fill)) {
|
|
5189
|
-
color = object.getAttribute('fill');
|
|
5190
|
-
} else if (gLite.isPattern(fill)) ;
|
|
5191
|
-
$el.style.background = color;
|
|
5192
|
-
break;
|
|
5193
|
-
case 'stroke':
|
|
5194
|
-
var stroke = object.parsedStyle.stroke;
|
|
5195
|
-
var borderColor = '';
|
|
5196
|
-
if (gLite.isCSSRGB(stroke)) {
|
|
5197
|
-
if (stroke.isNone) {
|
|
5198
|
-
borderColor = 'transparent';
|
|
5199
|
-
} else {
|
|
5200
|
-
borderColor = object.getAttribute('stroke');
|
|
5201
|
-
}
|
|
5202
|
-
} else if (Array.isArray(stroke)) {
|
|
5203
|
-
borderColor = object.getAttribute('stroke');
|
|
5204
|
-
} else if (gLite.isPattern(stroke)) ;
|
|
5205
|
-
$el.style['border-color'] = borderColor;
|
|
5206
|
-
$el.style['border-style'] = 'solid';
|
|
5207
|
-
break;
|
|
5208
|
-
case 'lineWidth':
|
|
5209
|
-
var lineWidth = object.parsedStyle.lineWidth;
|
|
5210
|
-
$el.style['border-width'] = (lineWidth || 0) + "px";
|
|
5211
|
-
break;
|
|
5212
|
-
case 'lineDash':
|
|
5213
|
-
$el.style['border-style'] = 'dashed';
|
|
5214
|
-
break;
|
|
5215
|
-
case 'filter':
|
|
5216
|
-
var filter = object.style.filter;
|
|
5217
|
-
$el.style.filter = filter;
|
|
5218
|
-
break;
|
|
5219
|
-
}
|
|
3911
|
+
if (canvas.supportsTouchEvents) {
|
|
3912
|
+
removeTouchEventListener($el);
|
|
3913
|
+
}
|
|
3914
|
+
if (config.useNativeClickEvent) {
|
|
3915
|
+
$el.removeEventListener('click', onClick, true);
|
|
3916
|
+
}
|
|
3917
|
+
$el.removeEventListener('wheel', onPointerWheel, true);
|
|
3918
|
+
});
|
|
5220
3919
|
};
|
|
5221
|
-
return
|
|
3920
|
+
return DOMInteractionPlugin;
|
|
5222
3921
|
}();
|
|
5223
|
-
|
|
5224
|
-
var Plugin$
|
|
5225
|
-
_inheritsLoose$
|
|
3922
|
+
DOMInteractionPlugin.tag = 'DOMInteraction';
|
|
3923
|
+
var Plugin$3 = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
3924
|
+
_inheritsLoose$4(Plugin, _AbstractRendererPlug);
|
|
5226
3925
|
function Plugin() {
|
|
5227
3926
|
var _this;
|
|
5228
3927
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
5229
3928
|
args[_key] = arguments[_key];
|
|
5230
3929
|
}
|
|
5231
3930
|
_this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
|
|
5232
|
-
_this.name = '
|
|
3931
|
+
_this.name = 'dom-interaction';
|
|
5233
3932
|
return _this;
|
|
5234
3933
|
}
|
|
5235
3934
|
var _proto = Plugin.prototype;
|
|
5236
3935
|
_proto.init = function init() {
|
|
5237
|
-
this.addRenderingPlugin(new
|
|
3936
|
+
this.addRenderingPlugin(new DOMInteractionPlugin());
|
|
5238
3937
|
};
|
|
5239
3938
|
_proto.destroy = function destroy() {
|
|
5240
3939
|
this.removeAllRenderingPlugins();
|
|
@@ -5242,342 +3941,311 @@
|
|
|
5242
3941
|
return Plugin;
|
|
5243
3942
|
}(gLite.AbstractRendererPlugin);
|
|
5244
3943
|
|
|
5245
|
-
var index_esm$
|
|
5246
|
-
__proto__: null,
|
|
5247
|
-
Plugin: Plugin$
|
|
5248
|
-
});
|
|
5249
|
-
|
|
5250
|
-
function
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5271
|
-
}
|
|
5272
|
-
try {
|
|
5273
|
-
define({}, "");
|
|
5274
|
-
} catch (err) {
|
|
5275
|
-
define = function define(obj, key, value) {
|
|
5276
|
-
return obj[key] = value;
|
|
5277
|
-
};
|
|
5278
|
-
}
|
|
5279
|
-
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
5280
|
-
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
|
|
5281
|
-
generator = Object.create(protoGenerator.prototype),
|
|
5282
|
-
context = new Context(tryLocsList || []);
|
|
5283
|
-
return defineProperty(generator, "_invoke", {
|
|
5284
|
-
value: makeInvokeMethod(innerFn, self, context)
|
|
5285
|
-
}), generator;
|
|
5286
|
-
}
|
|
5287
|
-
function tryCatch(fn, obj, arg) {
|
|
5288
|
-
try {
|
|
5289
|
-
return {
|
|
5290
|
-
type: "normal",
|
|
5291
|
-
arg: fn.call(obj, arg)
|
|
5292
|
-
};
|
|
5293
|
-
} catch (err) {
|
|
5294
|
-
return {
|
|
5295
|
-
type: "throw",
|
|
5296
|
-
arg: err
|
|
5297
|
-
};
|
|
5298
|
-
}
|
|
5299
|
-
}
|
|
5300
|
-
exports.wrap = wrap;
|
|
5301
|
-
var ContinueSentinel = {};
|
|
5302
|
-
function Generator() {}
|
|
5303
|
-
function GeneratorFunction() {}
|
|
5304
|
-
function GeneratorFunctionPrototype() {}
|
|
5305
|
-
var IteratorPrototype = {};
|
|
5306
|
-
define(IteratorPrototype, iteratorSymbol, function () {
|
|
5307
|
-
return this;
|
|
5308
|
-
});
|
|
5309
|
-
var getProto = Object.getPrototypeOf,
|
|
5310
|
-
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
5311
|
-
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
|
|
5312
|
-
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
5313
|
-
function defineIteratorMethods(prototype) {
|
|
5314
|
-
["next", "throw", "return"].forEach(function (method) {
|
|
5315
|
-
define(prototype, method, function (arg) {
|
|
5316
|
-
return this._invoke(method, arg);
|
|
5317
|
-
});
|
|
5318
|
-
});
|
|
5319
|
-
}
|
|
5320
|
-
function AsyncIterator(generator, PromiseImpl) {
|
|
5321
|
-
function invoke(method, arg, resolve, reject) {
|
|
5322
|
-
var record = tryCatch(generator[method], generator, arg);
|
|
5323
|
-
if ("throw" !== record.type) {
|
|
5324
|
-
var result = record.arg,
|
|
5325
|
-
value = result.value;
|
|
5326
|
-
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
|
|
5327
|
-
invoke("next", value, resolve, reject);
|
|
5328
|
-
}, function (err) {
|
|
5329
|
-
invoke("throw", err, resolve, reject);
|
|
5330
|
-
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
|
|
5331
|
-
result.value = unwrapped, resolve(result);
|
|
5332
|
-
}, function (error) {
|
|
5333
|
-
return invoke("throw", error, resolve, reject);
|
|
5334
|
-
});
|
|
5335
|
-
}
|
|
5336
|
-
reject(record.arg);
|
|
5337
|
-
}
|
|
5338
|
-
var previousPromise;
|
|
5339
|
-
defineProperty(this, "_invoke", {
|
|
5340
|
-
value: function value(method, arg) {
|
|
5341
|
-
function callInvokeWithMethodAndArg() {
|
|
5342
|
-
return new PromiseImpl(function (resolve, reject) {
|
|
5343
|
-
invoke(method, arg, resolve, reject);
|
|
5344
|
-
});
|
|
5345
|
-
}
|
|
5346
|
-
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
5347
|
-
}
|
|
5348
|
-
});
|
|
3944
|
+
var index_esm$3 = /*#__PURE__*/Object.freeze({
|
|
3945
|
+
__proto__: null,
|
|
3946
|
+
Plugin: Plugin$3
|
|
3947
|
+
});
|
|
3948
|
+
|
|
3949
|
+
function _inheritsLoose$5(subClass, superClass) {
|
|
3950
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
3951
|
+
subClass.prototype.constructor = subClass;
|
|
3952
|
+
_setPrototypeOf$5(subClass, superClass);
|
|
3953
|
+
}
|
|
3954
|
+
function _setPrototypeOf$5(o, p) {
|
|
3955
|
+
_setPrototypeOf$5 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
3956
|
+
o.__proto__ = p;
|
|
3957
|
+
return o;
|
|
3958
|
+
};
|
|
3959
|
+
return _setPrototypeOf$5(o, p);
|
|
3960
|
+
}
|
|
3961
|
+
var HTML_PREFIX = 'g-html-';
|
|
3962
|
+
var CANVAS_CAMERA_ID = 'g-canvas-camera';
|
|
3963
|
+
var HTMLRenderingPlugin = /*#__PURE__*/function () {
|
|
3964
|
+
function HTMLRenderingPlugin() {
|
|
3965
|
+
this.context = void 0;
|
|
3966
|
+
/**
|
|
3967
|
+
* wrapper for camera
|
|
3968
|
+
*/
|
|
3969
|
+
this.$camera = void 0;
|
|
5349
3970
|
}
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
return
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
if (
|
|
5368
|
-
|
|
5369
|
-
context.dispatchException(context.arg);
|
|
5370
|
-
} else "return" === context.method && context.abrupt("return", context.arg);
|
|
5371
|
-
state = "executing";
|
|
5372
|
-
var record = tryCatch(innerFn, self, context);
|
|
5373
|
-
if ("normal" === record.type) {
|
|
5374
|
-
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
|
|
5375
|
-
return {
|
|
5376
|
-
value: record.arg,
|
|
5377
|
-
done: context.done
|
|
5378
|
-
};
|
|
3971
|
+
var _proto = HTMLRenderingPlugin.prototype;
|
|
3972
|
+
_proto.joinTransformMatrix = function joinTransformMatrix(matrix) {
|
|
3973
|
+
return "matrix(" + [matrix[0], matrix[1], matrix[4], matrix[5], matrix[12], matrix[13]].join(',') + ")";
|
|
3974
|
+
};
|
|
3975
|
+
_proto.apply = function apply(context) {
|
|
3976
|
+
var _this = this;
|
|
3977
|
+
var camera = context.camera,
|
|
3978
|
+
renderingContext = context.renderingContext,
|
|
3979
|
+
renderingService = context.renderingService;
|
|
3980
|
+
this.context = context;
|
|
3981
|
+
var canvas = renderingContext.root.ownerDocument.defaultView;
|
|
3982
|
+
var setTransform = function setTransform(object, $el) {
|
|
3983
|
+
$el.style.transform = _this.joinTransformMatrix(object.getWorldTransform());
|
|
3984
|
+
};
|
|
3985
|
+
var handleMounted = function handleMounted(e) {
|
|
3986
|
+
var object = e.target;
|
|
3987
|
+
if (object.nodeName === gLite.Shape.HTML) {
|
|
3988
|
+
if (!_this.$camera) {
|
|
3989
|
+
_this.$camera = _this.createCamera(camera);
|
|
5379
3990
|
}
|
|
5380
|
-
|
|
3991
|
+
// create DOM element
|
|
3992
|
+
var $el = _this.getOrCreateEl(object);
|
|
3993
|
+
_this.$camera.appendChild($el);
|
|
3994
|
+
// apply documentElement's style
|
|
3995
|
+
var attributes = object.ownerDocument.documentElement.attributes;
|
|
3996
|
+
Object.keys(attributes).forEach(function (name) {
|
|
3997
|
+
$el.style[name] = attributes[name];
|
|
3998
|
+
});
|
|
3999
|
+
Object.keys(object.attributes).forEach(function (name) {
|
|
4000
|
+
_this.updateAttribute(name, object);
|
|
4001
|
+
});
|
|
4002
|
+
setTransform(object, $el);
|
|
4003
|
+
gLite.runtime.nativeHTMLMap.set($el, object);
|
|
5381
4004
|
}
|
|
5382
4005
|
};
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
4006
|
+
var handleUnmounted = function handleUnmounted(e) {
|
|
4007
|
+
var object = e.target;
|
|
4008
|
+
if (object.nodeName === gLite.Shape.HTML && _this.$camera) {
|
|
4009
|
+
var $el = _this.getOrCreateEl(object);
|
|
4010
|
+
if ($el) {
|
|
4011
|
+
$el.remove();
|
|
4012
|
+
gLite.runtime.nativeHTMLMap.delete($el);
|
|
4013
|
+
}
|
|
4014
|
+
// const existedId = this.getId(object);
|
|
4015
|
+
// const $existedElement: HTMLElement | null = this.$camera.querySelector('#' + existedId);
|
|
4016
|
+
// if ($existedElement) {
|
|
4017
|
+
// this.$camera.removeChild($existedElement);
|
|
4018
|
+
// }
|
|
4019
|
+
}
|
|
5396
4020
|
};
|
|
5397
|
-
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
function Context(tryLocsList) {
|
|
5404
|
-
this.tryEntries = [{
|
|
5405
|
-
tryLoc: "root"
|
|
5406
|
-
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
|
|
5407
|
-
}
|
|
5408
|
-
function values(iterable) {
|
|
5409
|
-
if (iterable) {
|
|
5410
|
-
var iteratorMethod = iterable[iteratorSymbol];
|
|
5411
|
-
if (iteratorMethod) return iteratorMethod.call(iterable);
|
|
5412
|
-
if ("function" == typeof iterable.next) return iterable;
|
|
5413
|
-
if (!isNaN(iterable.length)) {
|
|
5414
|
-
var i = -1,
|
|
5415
|
-
next = function next() {
|
|
5416
|
-
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
|
5417
|
-
return next.value = undefined, next.done = !0, next;
|
|
5418
|
-
};
|
|
5419
|
-
return next.next = next;
|
|
4021
|
+
|
|
4022
|
+
var handleAttributeChanged = function handleAttributeChanged(e) {
|
|
4023
|
+
var object = e.target;
|
|
4024
|
+
if (object.nodeName === gLite.Shape.HTML) {
|
|
4025
|
+
var attrName = e.attrName;
|
|
4026
|
+
_this.updateAttribute(attrName, object);
|
|
5420
4027
|
}
|
|
5421
|
-
}
|
|
5422
|
-
return {
|
|
5423
|
-
next: doneResult
|
|
5424
4028
|
};
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
|
|
4029
|
+
var handleBoundsChanged = function handleBoundsChanged(e) {
|
|
4030
|
+
var object = e.target;
|
|
4031
|
+
if (object.nodeName === gLite.Shape.HTML) {
|
|
4032
|
+
var $el = _this.getOrCreateEl(object);
|
|
4033
|
+
setTransform(object, $el);
|
|
4034
|
+
}
|
|
5430
4035
|
};
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
var ctor = "function" == typeof genFun && genFun.constructor;
|
|
5440
|
-
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
|
|
5441
|
-
}, exports.mark = function (genFun) {
|
|
5442
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
|
|
5443
|
-
}, exports.awrap = function (arg) {
|
|
5444
|
-
return {
|
|
5445
|
-
__await: arg
|
|
4036
|
+
var handleCanvasResize = function handleCanvasResize() {
|
|
4037
|
+
if (_this.$camera) {
|
|
4038
|
+
var _this$context$config = _this.context.config,
|
|
4039
|
+
width = _this$context$config.width,
|
|
4040
|
+
height = _this$context$config.height;
|
|
4041
|
+
_this.$camera.style.width = (width || 0) + "px";
|
|
4042
|
+
_this.$camera.style.height = (height || 0) + "px";
|
|
4043
|
+
}
|
|
5446
4044
|
};
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
return result.done ? result.value : iter.next();
|
|
4045
|
+
renderingService.hooks.init.tap(HTMLRenderingPlugin.tag, function () {
|
|
4046
|
+
canvas.addEventListener(gLite.CanvasEvent.RESIZE, handleCanvasResize);
|
|
4047
|
+
canvas.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
|
|
4048
|
+
canvas.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
|
|
4049
|
+
canvas.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
4050
|
+
canvas.addEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
|
|
5454
4051
|
});
|
|
5455
|
-
|
|
5456
|
-
|
|
5457
|
-
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
|
|
5466
|
-
|
|
4052
|
+
renderingService.hooks.endFrame.tap(HTMLRenderingPlugin.tag, function () {
|
|
4053
|
+
if (_this.$camera && renderingContext.renderReasons.has(gLite.RenderReason.CAMERA_CHANGED)) {
|
|
4054
|
+
_this.$camera.style.transform = _this.joinTransformMatrix(camera.getOrthoMatrix());
|
|
4055
|
+
}
|
|
4056
|
+
});
|
|
4057
|
+
renderingService.hooks.destroy.tap(HTMLRenderingPlugin.tag, function () {
|
|
4058
|
+
// remove camera
|
|
4059
|
+
if (_this.$camera) {
|
|
4060
|
+
_this.$camera.remove();
|
|
4061
|
+
}
|
|
4062
|
+
canvas.removeEventListener(gLite.CanvasEvent.RESIZE, handleCanvasResize);
|
|
4063
|
+
canvas.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
|
|
4064
|
+
canvas.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
|
|
4065
|
+
canvas.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
4066
|
+
canvas.removeEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
|
|
4067
|
+
});
|
|
4068
|
+
};
|
|
4069
|
+
_proto.getId = function getId(object) {
|
|
4070
|
+
return object.id || HTML_PREFIX + object.entity;
|
|
4071
|
+
};
|
|
4072
|
+
_proto.createCamera = function createCamera(camera) {
|
|
4073
|
+
var _this$context$config2 = this.context.config,
|
|
4074
|
+
doc = _this$context$config2.document,
|
|
4075
|
+
width = _this$context$config2.width,
|
|
4076
|
+
height = _this$context$config2.height;
|
|
4077
|
+
var $canvas = this.context.contextService.getDomElement();
|
|
4078
|
+
var $container = $canvas.parentNode;
|
|
4079
|
+
if ($container) {
|
|
4080
|
+
var cameraId = CANVAS_CAMERA_ID;
|
|
4081
|
+
var $existedCamera = $container.querySelector('#' + cameraId);
|
|
4082
|
+
if (!$existedCamera) {
|
|
4083
|
+
var $camera = (doc || document).createElement('div');
|
|
4084
|
+
$existedCamera = $camera;
|
|
4085
|
+
$camera.id = cameraId;
|
|
4086
|
+
// use absolute position
|
|
4087
|
+
$camera.style.position = 'absolute';
|
|
4088
|
+
// account for DOM element's offset @see https://github.com/antvis/G/issues/1150
|
|
4089
|
+
$camera.style.left = ($canvas.offsetLeft || 0) + "px";
|
|
4090
|
+
$camera.style.top = ($canvas.offsetTop || 0) + "px";
|
|
4091
|
+
$camera.style.transformOrigin = 'left top';
|
|
4092
|
+
$camera.style.transform = this.joinTransformMatrix(camera.getOrthoMatrix());
|
|
4093
|
+
// HTML elements should not overflow with canvas @see https://github.com/antvis/G/issues/1163
|
|
4094
|
+
$camera.style.overflow = 'hidden';
|
|
4095
|
+
$camera.style.pointerEvents = 'none';
|
|
4096
|
+
$camera.style.width = (width || 0) + "px";
|
|
4097
|
+
$camera.style.height = (height || 0) + "px";
|
|
4098
|
+
$container.appendChild($camera);
|
|
4099
|
+
}
|
|
4100
|
+
return $existedCamera;
|
|
4101
|
+
}
|
|
4102
|
+
return null;
|
|
4103
|
+
};
|
|
4104
|
+
_proto.getOrCreateEl = function getOrCreateEl(object) {
|
|
4105
|
+
var doc = this.context.config.document;
|
|
4106
|
+
var existedId = this.getId(object);
|
|
4107
|
+
var $existedElement = this.$camera.querySelector('#' + existedId);
|
|
4108
|
+
if (!$existedElement) {
|
|
4109
|
+
$existedElement = (doc || document).createElement('div');
|
|
4110
|
+
object.parsedStyle.$el = $existedElement;
|
|
4111
|
+
$existedElement.id = existedId;
|
|
4112
|
+
if (object.name) {
|
|
4113
|
+
$existedElement.setAttribute('name', object.name);
|
|
5467
4114
|
}
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
}, exports.values = values, Context.prototype = {
|
|
5471
|
-
constructor: Context,
|
|
5472
|
-
reset: function reset(skipTempReset) {
|
|
5473
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
|
|
5474
|
-
},
|
|
5475
|
-
stop: function stop() {
|
|
5476
|
-
this.done = !0;
|
|
5477
|
-
var rootRecord = this.tryEntries[0].completion;
|
|
5478
|
-
if ("throw" === rootRecord.type) throw rootRecord.arg;
|
|
5479
|
-
return this.rval;
|
|
5480
|
-
},
|
|
5481
|
-
dispatchException: function dispatchException(exception) {
|
|
5482
|
-
if (this.done) throw exception;
|
|
5483
|
-
var context = this;
|
|
5484
|
-
function handle(loc, caught) {
|
|
5485
|
-
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
|
|
4115
|
+
if (object.className) {
|
|
4116
|
+
$existedElement.className = object.className;
|
|
5486
4117
|
}
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
4118
|
+
// use absolute position
|
|
4119
|
+
$existedElement.style.position = 'absolute';
|
|
4120
|
+
// @see https://github.com/antvis/G/issues/1150
|
|
4121
|
+
$existedElement.style.left = "0px";
|
|
4122
|
+
$existedElement.style.top = "0px";
|
|
4123
|
+
$existedElement.style['will-change'] = 'transform';
|
|
4124
|
+
$existedElement.style.transform = this.joinTransformMatrix(object.getWorldTransform());
|
|
4125
|
+
}
|
|
4126
|
+
return $existedElement;
|
|
4127
|
+
};
|
|
4128
|
+
_proto.updateAttribute = function updateAttribute(name, object) {
|
|
4129
|
+
var $el = this.getOrCreateEl(object);
|
|
4130
|
+
switch (name) {
|
|
4131
|
+
case 'innerHTML':
|
|
4132
|
+
var innerHTML = object.parsedStyle.innerHTML;
|
|
4133
|
+
if (isString(innerHTML)) {
|
|
4134
|
+
$el.innerHTML = innerHTML;
|
|
4135
|
+
} else {
|
|
4136
|
+
$el.innerHTML = '';
|
|
4137
|
+
$el.appendChild(innerHTML);
|
|
5503
4138
|
}
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
|
|
4139
|
+
break;
|
|
4140
|
+
case 'transformOrigin':
|
|
4141
|
+
var transformOrigin = object.parsedStyle.transformOrigin;
|
|
4142
|
+
$el.style['transform-origin'] = transformOrigin[0].value + " " + transformOrigin[1].value;
|
|
4143
|
+
break;
|
|
4144
|
+
case 'width':
|
|
4145
|
+
if (gLite.runtime.enableCSSParsing) {
|
|
4146
|
+
var width = object.computedStyleMap().get('width');
|
|
4147
|
+
$el.style.width = width.toString();
|
|
4148
|
+
} else {
|
|
4149
|
+
var _width = object.parsedStyle.width;
|
|
4150
|
+
$el.style.width = isNumber(_width) ? _width + "px" : _width.toString();
|
|
5512
4151
|
}
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
},
|
|
5522
|
-
finish: function finish(finallyLoc) {
|
|
5523
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
5524
|
-
var entry = this.tryEntries[i];
|
|
5525
|
-
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
|
|
5526
|
-
}
|
|
5527
|
-
},
|
|
5528
|
-
catch: function _catch(tryLoc) {
|
|
5529
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
5530
|
-
var entry = this.tryEntries[i];
|
|
5531
|
-
if (entry.tryLoc === tryLoc) {
|
|
5532
|
-
var record = entry.completion;
|
|
5533
|
-
if ("throw" === record.type) {
|
|
5534
|
-
var thrown = record.arg;
|
|
5535
|
-
resetTryEntry(entry);
|
|
5536
|
-
}
|
|
5537
|
-
return thrown;
|
|
4152
|
+
break;
|
|
4153
|
+
case 'height':
|
|
4154
|
+
if (gLite.runtime.enableCSSParsing) {
|
|
4155
|
+
var height = object.computedStyleMap().get('height');
|
|
4156
|
+
$el.style.height = height.toString();
|
|
4157
|
+
} else {
|
|
4158
|
+
var _height = object.parsedStyle.height;
|
|
4159
|
+
$el.style.height = isNumber(_height) ? _height + "px" : _height.toString();
|
|
5538
4160
|
}
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
4161
|
+
break;
|
|
4162
|
+
case 'zIndex':
|
|
4163
|
+
var zIndex = object.parsedStyle.zIndex;
|
|
4164
|
+
$el.style['z-index'] = "" + zIndex;
|
|
4165
|
+
break;
|
|
4166
|
+
case 'visibility':
|
|
4167
|
+
var visibility = object.parsedStyle.visibility;
|
|
4168
|
+
$el.style.visibility = visibility;
|
|
4169
|
+
break;
|
|
4170
|
+
case 'pointerEvents':
|
|
4171
|
+
var pointerEvents = object.parsedStyle.pointerEvents;
|
|
4172
|
+
$el.style.pointerEvents = pointerEvents;
|
|
4173
|
+
break;
|
|
4174
|
+
case 'opacity':
|
|
4175
|
+
var opacity = object.parsedStyle.opacity;
|
|
4176
|
+
$el.style.opacity = "" + opacity;
|
|
4177
|
+
break;
|
|
4178
|
+
case 'fill':
|
|
4179
|
+
var fill = object.parsedStyle.fill;
|
|
4180
|
+
var color = '';
|
|
4181
|
+
if (gLite.isCSSRGB(fill)) {
|
|
4182
|
+
if (fill.isNone) {
|
|
4183
|
+
color = 'transparent';
|
|
4184
|
+
} else {
|
|
4185
|
+
color = object.getAttribute('fill');
|
|
4186
|
+
}
|
|
4187
|
+
} else if (Array.isArray(fill)) {
|
|
4188
|
+
color = object.getAttribute('fill');
|
|
4189
|
+
} else if (gLite.isPattern(fill)) ;
|
|
4190
|
+
$el.style.background = color;
|
|
4191
|
+
break;
|
|
4192
|
+
case 'stroke':
|
|
4193
|
+
var stroke = object.parsedStyle.stroke;
|
|
4194
|
+
var borderColor = '';
|
|
4195
|
+
if (gLite.isCSSRGB(stroke)) {
|
|
4196
|
+
if (stroke.isNone) {
|
|
4197
|
+
borderColor = 'transparent';
|
|
4198
|
+
} else {
|
|
4199
|
+
borderColor = object.getAttribute('stroke');
|
|
4200
|
+
}
|
|
4201
|
+
} else if (Array.isArray(stroke)) {
|
|
4202
|
+
borderColor = object.getAttribute('stroke');
|
|
4203
|
+
} else if (gLite.isPattern(stroke)) ;
|
|
4204
|
+
$el.style['border-color'] = borderColor;
|
|
4205
|
+
$el.style['border-style'] = 'solid';
|
|
4206
|
+
break;
|
|
4207
|
+
case 'lineWidth':
|
|
4208
|
+
var lineWidth = object.parsedStyle.lineWidth;
|
|
4209
|
+
$el.style['border-width'] = (lineWidth || 0) + "px";
|
|
4210
|
+
break;
|
|
4211
|
+
case 'lineDash':
|
|
4212
|
+
$el.style['border-style'] = 'dashed';
|
|
4213
|
+
break;
|
|
4214
|
+
case 'filter':
|
|
4215
|
+
var filter = object.style.filter;
|
|
4216
|
+
$el.style.filter = filter;
|
|
4217
|
+
break;
|
|
5548
4218
|
}
|
|
5549
|
-
}
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
4219
|
+
};
|
|
4220
|
+
return HTMLRenderingPlugin;
|
|
4221
|
+
}();
|
|
4222
|
+
HTMLRenderingPlugin.tag = 'HTMLRendering';
|
|
4223
|
+
var Plugin$4 = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
4224
|
+
_inheritsLoose$5(Plugin, _AbstractRendererPlug);
|
|
4225
|
+
function Plugin() {
|
|
4226
|
+
var _this;
|
|
4227
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4228
|
+
args[_key] = arguments[_key];
|
|
4229
|
+
}
|
|
4230
|
+
_this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
|
|
4231
|
+
_this.name = 'html-renderer';
|
|
4232
|
+
return _this;
|
|
5563
4233
|
}
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
5567
|
-
var self = this,
|
|
5568
|
-
args = arguments;
|
|
5569
|
-
return new Promise(function (resolve, reject) {
|
|
5570
|
-
var gen = fn.apply(self, args);
|
|
5571
|
-
function _next(value) {
|
|
5572
|
-
asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "next", value);
|
|
5573
|
-
}
|
|
5574
|
-
function _throw(err) {
|
|
5575
|
-
asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "throw", err);
|
|
5576
|
-
}
|
|
5577
|
-
_next(undefined);
|
|
5578
|
-
});
|
|
4234
|
+
var _proto = Plugin.prototype;
|
|
4235
|
+
_proto.init = function init() {
|
|
4236
|
+
this.addRenderingPlugin(new HTMLRenderingPlugin());
|
|
5579
4237
|
};
|
|
5580
|
-
|
|
4238
|
+
_proto.destroy = function destroy() {
|
|
4239
|
+
this.removeAllRenderingPlugins();
|
|
4240
|
+
};
|
|
4241
|
+
return Plugin;
|
|
4242
|
+
}(gLite.AbstractRendererPlugin);
|
|
4243
|
+
|
|
4244
|
+
var index_esm$4 = /*#__PURE__*/Object.freeze({
|
|
4245
|
+
__proto__: null,
|
|
4246
|
+
Plugin: Plugin$4
|
|
4247
|
+
});
|
|
4248
|
+
|
|
5581
4249
|
function _inheritsLoose$6(subClass, superClass) {
|
|
5582
4250
|
subClass.prototype = Object.create(superClass.prototype);
|
|
5583
4251
|
subClass.prototype.constructor = subClass;
|
|
@@ -5734,6 +4402,7 @@
|
|
|
5734
4402
|
}
|
|
5735
4403
|
if (image) {
|
|
5736
4404
|
image.onload = function () {
|
|
4405
|
+
_this.imageCache[src] = image;
|
|
5737
4406
|
resolve(image);
|
|
5738
4407
|
};
|
|
5739
4408
|
image.onerror = function (ev) {
|
|
@@ -5741,7 +4410,6 @@
|
|
|
5741
4410
|
};
|
|
5742
4411
|
image.crossOrigin = 'Anonymous';
|
|
5743
4412
|
image.src = src;
|
|
5744
|
-
_this.imageCache[src] = image;
|
|
5745
4413
|
}
|
|
5746
4414
|
});
|
|
5747
4415
|
};
|
|
@@ -5901,18 +4569,10 @@
|
|
|
5901
4569
|
}
|
|
5902
4570
|
}
|
|
5903
4571
|
};
|
|
5904
|
-
renderingService.hooks.init.
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
canvas.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
|
|
5909
|
-
canvas.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
5910
|
-
case 2:
|
|
5911
|
-
case "end":
|
|
5912
|
-
return _context.stop();
|
|
5913
|
-
}
|
|
5914
|
-
}, _callee);
|
|
5915
|
-
})));
|
|
4572
|
+
renderingService.hooks.init.tap(LoadImagePlugin.tag, function () {
|
|
4573
|
+
canvas.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
|
|
4574
|
+
canvas.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
4575
|
+
});
|
|
5916
4576
|
renderingService.hooks.destroy.tap(LoadImagePlugin.tag, function () {
|
|
5917
4577
|
canvas.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
|
|
5918
4578
|
canvas.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
@@ -5962,46 +4622,33 @@
|
|
|
5962
4622
|
this.canvasConfig = context.config;
|
|
5963
4623
|
}
|
|
5964
4624
|
var _proto = Canvas2DContextService.prototype;
|
|
5965
|
-
_proto.init =
|
|
5966
|
-
var
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
this.$container.appendChild($canvas);
|
|
5986
|
-
if (!this.$container.style.position) {
|
|
5987
|
-
this.$container.style.position = 'relative';
|
|
5988
|
-
}
|
|
5989
|
-
this.$canvas = $canvas;
|
|
5990
|
-
}
|
|
5991
|
-
}
|
|
5992
|
-
this.context = this.$canvas.getContext('2d');
|
|
5993
|
-
this.resize(this.canvasConfig.width, this.canvasConfig.height);
|
|
5994
|
-
case 4:
|
|
5995
|
-
case "end":
|
|
5996
|
-
return _context.stop();
|
|
4625
|
+
_proto.init = function init() {
|
|
4626
|
+
var _this$canvasConfig = this.canvasConfig,
|
|
4627
|
+
container = _this$canvasConfig.container,
|
|
4628
|
+
canvas = _this$canvasConfig.canvas;
|
|
4629
|
+
if (canvas) {
|
|
4630
|
+
this.$canvas = canvas;
|
|
4631
|
+
if (container && canvas.parentElement !== container) {
|
|
4632
|
+
container.appendChild(canvas);
|
|
4633
|
+
}
|
|
4634
|
+
this.$container = canvas.parentElement;
|
|
4635
|
+
this.canvasConfig.container = this.$container;
|
|
4636
|
+
} else if (container) {
|
|
4637
|
+
// create container
|
|
4638
|
+
this.$container = isString(container) ? document.getElementById(container) : container;
|
|
4639
|
+
if (this.$container) {
|
|
4640
|
+
// create canvas
|
|
4641
|
+
var $canvas = document.createElement('canvas');
|
|
4642
|
+
this.$container.appendChild($canvas);
|
|
4643
|
+
if (!this.$container.style.position) {
|
|
4644
|
+
this.$container.style.position = 'relative';
|
|
5997
4645
|
}
|
|
5998
|
-
|
|
5999
|
-
|
|
6000
|
-
function init() {
|
|
6001
|
-
return _init.apply(this, arguments);
|
|
4646
|
+
this.$canvas = $canvas;
|
|
4647
|
+
}
|
|
6002
4648
|
}
|
|
6003
|
-
|
|
6004
|
-
|
|
4649
|
+
this.context = this.$canvas.getContext('2d');
|
|
4650
|
+
this.resize(this.canvasConfig.width, this.canvasConfig.height);
|
|
4651
|
+
};
|
|
6005
4652
|
_proto.getContext = function getContext() {
|
|
6006
4653
|
return this.context;
|
|
6007
4654
|
};
|
|
@@ -6050,21 +4697,21 @@
|
|
|
6050
4697
|
}
|
|
6051
4698
|
};
|
|
6052
4699
|
_proto.toDataURL = /*#__PURE__*/function () {
|
|
6053
|
-
var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4700
|
+
var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
|
|
6054
4701
|
var _options, type, encoderOptions;
|
|
6055
|
-
return _regeneratorRuntime().wrap(function
|
|
6056
|
-
while (1) switch (
|
|
4702
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
4703
|
+
while (1) switch (_context.prev = _context.next) {
|
|
6057
4704
|
case 0:
|
|
6058
4705
|
if (options === void 0) {
|
|
6059
4706
|
options = {};
|
|
6060
4707
|
}
|
|
6061
4708
|
_options = options, type = _options.type, encoderOptions = _options.encoderOptions;
|
|
6062
|
-
return
|
|
4709
|
+
return _context.abrupt("return", this.context.canvas.toDataURL(type, encoderOptions));
|
|
6063
4710
|
case 3:
|
|
6064
4711
|
case "end":
|
|
6065
|
-
return
|
|
4712
|
+
return _context.stop();
|
|
6066
4713
|
}
|
|
6067
|
-
},
|
|
4714
|
+
}, _callee, this);
|
|
6068
4715
|
}));
|
|
6069
4716
|
function toDataURL(_x) {
|
|
6070
4717
|
return _toDataURL.apply(this, arguments);
|