@antv/g-canvas 1.9.45 → 1.9.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -2852,522 +2852,183 @@
2852
2852
  Plugin: Plugin$1
2853
2853
  });
2854
2854
 
2855
- function _regeneratorRuntime$2() {
2856
- _regeneratorRuntime$2 = function _regeneratorRuntime() {
2857
- return exports;
2855
+ function _extends() {
2856
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
2857
+ for (var i = 1; i < arguments.length; i++) {
2858
+ var source = arguments[i];
2859
+ for (var key in source) {
2860
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
2861
+ target[key] = source[key];
2862
+ }
2863
+ }
2864
+ }
2865
+ return target;
2858
2866
  };
2859
- var exports = {},
2860
- Op = Object.prototype,
2861
- hasOwn = Op.hasOwnProperty,
2862
- defineProperty = Object.defineProperty || function (obj, key, desc) {
2863
- obj[key] = desc.value;
2864
- },
2865
- $Symbol = "function" == typeof Symbol ? Symbol : {},
2866
- iteratorSymbol = $Symbol.iterator || "@@iterator",
2867
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
2868
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
2869
- function define(obj, key, value) {
2870
- return Object.defineProperty(obj, key, {
2871
- value: value,
2872
- enumerable: !0,
2873
- configurable: !0,
2874
- writable: !0
2875
- }), obj[key];
2867
+ return _extends.apply(this, arguments);
2868
+ }
2869
+ function _inheritsLoose$3(subClass, superClass) {
2870
+ subClass.prototype = Object.create(superClass.prototype);
2871
+ subClass.prototype.constructor = subClass;
2872
+ _setPrototypeOf$3(subClass, superClass);
2873
+ }
2874
+ function _setPrototypeOf$3(o, p) {
2875
+ _setPrototypeOf$3 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
2876
+ o.__proto__ = p;
2877
+ return o;
2878
+ };
2879
+ return _setPrototypeOf$3(o, p);
2880
+ }
2881
+
2882
+ /**
2883
+ * support 2 modes in rendering:
2884
+ * * immediate
2885
+ * * delayed: render at the end of frame with dirty-rectangle
2886
+ */
2887
+ var CanvasRendererPlugin = /*#__PURE__*/function () {
2888
+ function CanvasRendererPlugin(canvasRendererPluginOptions) {
2889
+ this.canvasRendererPluginOptions = void 0;
2890
+ this.context = void 0;
2891
+ this.pathGeneratorFactory = void 0;
2892
+ /**
2893
+ * RBush used in dirty rectangle rendering
2894
+ */
2895
+ this.rBush = void 0;
2896
+ this.removedRBushNodeAABBs = [];
2897
+ this.renderQueue = [];
2898
+ /**
2899
+ * This stack is only used by clipPath for now.
2900
+ */
2901
+ this.restoreStack = [];
2902
+ this.clearFullScreen = false;
2903
+ /**
2904
+ * view projection matrix
2905
+ */
2906
+ this.vpMatrix = create();
2907
+ this.dprMatrix = create();
2908
+ this.tmpMat4 = create();
2909
+ this.vec3a = create$1();
2910
+ this.vec3b = create$1();
2911
+ this.vec3c = create$1();
2912
+ this.vec3d = create$1();
2913
+ this.canvasRendererPluginOptions = canvasRendererPluginOptions;
2876
2914
  }
2877
- try {
2878
- define({}, "");
2879
- } catch (err) {
2880
- define = function define(obj, key, value) {
2881
- return obj[key] = value;
2915
+ var _proto = CanvasRendererPlugin.prototype;
2916
+ _proto.apply = function apply(context, runtime) {
2917
+ var _this = this;
2918
+ this.context = context;
2919
+ var config = context.config,
2920
+ camera = context.camera,
2921
+ renderingService = context.renderingService,
2922
+ renderingContext = context.renderingContext,
2923
+ rBushRoot = context.rBushRoot,
2924
+ pathGeneratorFactory = context.pathGeneratorFactory;
2925
+ this.rBush = rBushRoot;
2926
+ this.pathGeneratorFactory = pathGeneratorFactory;
2927
+ var contextService = context.contextService;
2928
+ var canvas = renderingContext.root.ownerDocument.defaultView;
2929
+ var handleUnmounted = function handleUnmounted(e) {
2930
+ var object = e.target;
2931
+ // remove r-bush node
2932
+ // @ts-ignore
2933
+ var rBushNode = object.rBushNode;
2934
+ if (rBushNode.aabb) {
2935
+ // save removed aabbs for dirty-rectangle rendering later
2936
+ _this.removedRBushNodeAABBs.push(rBushNode.aabb);
2937
+ }
2882
2938
  };
2883
- }
2884
- function wrap(innerFn, outerFn, self, tryLocsList) {
2885
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
2886
- generator = Object.create(protoGenerator.prototype),
2887
- context = new Context(tryLocsList || []);
2888
- return defineProperty(generator, "_invoke", {
2889
- value: makeInvokeMethod(innerFn, self, context)
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
- });
2939
+ var handleCulled = function handleCulled(e) {
2940
+ var object = e.target;
2941
+ // @ts-ignore
2942
+ var rBushNode = object.rBushNode;
2943
+ if (rBushNode.aabb) {
2944
+ // save removed aabbs for dirty-rectangle rendering later
2945
+ _this.removedRBushNodeAABBs.push(rBushNode.aabb);
2940
2946
  }
2941
- reject(record.arg);
2942
- }
2943
- var previousPromise;
2944
- defineProperty(this, "_invoke", {
2945
- value: function value(method, arg) {
2946
- function callInvokeWithMethodAndArg() {
2947
- return new PromiseImpl(function (resolve, reject) {
2948
- invoke(method, arg, resolve, reject);
2949
- });
2947
+ };
2948
+ renderingService.hooks.init.tap(CanvasRendererPlugin.tag, function () {
2949
+ canvas.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
2950
+ canvas.addEventListener(gLite.ElementEvent.CULLED, handleCulled);
2951
+ // clear fullscreen
2952
+ var dpr = contextService.getDPR();
2953
+ var width = config.width,
2954
+ height = config.height;
2955
+ var context = contextService.getContext();
2956
+ _this.clearRect(context, 0, 0, width * dpr, height * dpr, config.background);
2957
+ });
2958
+ renderingService.hooks.destroy.tap(CanvasRendererPlugin.tag, function () {
2959
+ canvas.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
2960
+ canvas.removeEventListener(gLite.ElementEvent.CULLED, handleCulled);
2961
+ // this.renderQueue = [];
2962
+ // this.removedRBushNodeAABBs = [];
2963
+ // this.restoreStack = [];
2964
+ });
2965
+
2966
+ renderingService.hooks.beginFrame.tap(CanvasRendererPlugin.tag, function () {
2967
+ var context = contextService.getContext();
2968
+ var dpr = contextService.getDPR();
2969
+ var width = config.width,
2970
+ height = config.height;
2971
+ var _this$canvasRendererP = _this.canvasRendererPluginOptions,
2972
+ dirtyObjectNumThreshold = _this$canvasRendererP.dirtyObjectNumThreshold,
2973
+ dirtyObjectRatioThreshold = _this$canvasRendererP.dirtyObjectRatioThreshold;
2974
+ // some heuristic conditions such as 80% object changed
2975
+ var _renderingService$get = renderingService.getStats(),
2976
+ total = _renderingService$get.total,
2977
+ rendered = _renderingService$get.rendered;
2978
+ var ratio = rendered / total;
2979
+ _this.clearFullScreen = renderingService.disableDirtyRectangleRendering() || rendered > dirtyObjectNumThreshold && ratio > dirtyObjectRatioThreshold;
2980
+ if (context) {
2981
+ context.resetTransform ? context.resetTransform() : context.setTransform(1, 0, 0, 1, 0, 0);
2982
+ if (_this.clearFullScreen) {
2983
+ _this.clearRect(context, 0, 0, width * dpr, height * dpr, config.background);
2950
2984
  }
2951
- return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
2952
2985
  }
2953
2986
  });
2954
- }
2955
- function makeInvokeMethod(innerFn, self, context) {
2956
- var state = "suspendedStart";
2957
- return function (method, arg) {
2958
- if ("executing" === state) throw new Error("Generator is already running");
2959
- if ("completed" === state) {
2960
- if ("throw" === method) throw arg;
2961
- return doneResult();
2962
- }
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);
2987
+ var renderByZIndex = function renderByZIndex(object, context) {
2988
+ if (object.isVisible() && !object.isCulled()) {
2989
+ _this.renderDisplayObject(object, context, _this.context, _this.restoreStack, runtime);
2990
+ // if (object.renderable.) {
2991
+ // if we did a full screen rendering last frame
2992
+ _this.saveDirtyAABB(object);
2993
+ // }
2986
2994
  }
2995
+
2996
+ var sorted = object.sortable.sorted || object.childNodes;
2997
+ // should account for z-index
2998
+ sorted.forEach(function (child) {
2999
+ renderByZIndex(child, context);
3000
+ });
2987
3001
  };
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;
3002
+ // render at the end of frame
3003
+ renderingService.hooks.endFrame.tap(CanvasRendererPlugin.tag, function () {
3004
+ var context = contextService.getContext();
3005
+ // clear & clip dirty rectangle
3006
+ var dpr = contextService.getDPR();
3007
+ fromScaling(_this.dprMatrix, [dpr, dpr, 1]);
3008
+ multiply(_this.vpMatrix, _this.dprMatrix, camera.getOrthoMatrix());
3009
+ // if (this.clearFullScreen) {
3010
+ if (_this.clearFullScreen) {
3011
+ // console.log('canvas renderer fcp...');
3012
+ renderByZIndex(renderingContext.root, context);
3013
+ } else {
3014
+ // console.log('canvas renderer next...');
3015
+ // merge removed AABB
3016
+ var dirtyRenderBounds = _this.safeMergeAABB.apply(_this, [_this.mergeDirtyAABBs(_this.renderQueue)].concat(_this.removedRBushNodeAABBs.map(function (_ref) {
3017
+ var minX = _ref.minX,
3018
+ minY = _ref.minY,
3019
+ maxX = _ref.maxX,
3020
+ maxY = _ref.maxY;
3021
+ var aabb = new gLite.AABB();
3022
+ aabb.setMinMax(
3023
+ // vec3.fromValues(minX, minY, 0),
3024
+ // vec3.fromValues(maxX, maxY, 0),
3025
+ [minX, minY, 0], [maxX, maxY, 0]);
3026
+ return aabb;
3027
+ })));
3028
+ _this.removedRBushNodeAABBs = [];
3029
+ if (gLite.AABB.isEmpty(dirtyRenderBounds)) {
3030
+ _this.renderQueue = [];
3031
+ return;
3371
3032
  }
3372
3033
  var dirtyRect = _this.convertAABB2Rect(dirtyRenderBounds);
3373
3034
  var x = dirtyRect.x,
@@ -3404,1837 +3065,859 @@
3404
3065
  width: iwidth,
3405
3066
  height: iheight
3406
3067
  }
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
-
4094
- function _regeneratorRuntime$3() {
4095
- _regeneratorRuntime$3 = function _regeneratorRuntime() {
4096
- return exports;
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);
4161
- });
4162
- });
4163
- }
4164
- function AsyncIterator(generator, PromiseImpl) {
4165
- function invoke(method, arg, resolve, reject) {
4166
- var record = tryCatch(generator[method], generator, arg);
4167
- if ("throw" !== record.type) {
4168
- var result = record.arg,
4169
- value = result.value;
4170
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
4171
- invoke("next", value, resolve, reject);
4172
- }, function (err) {
4173
- invoke("throw", err, resolve, reject);
4174
- }) : PromiseImpl.resolve(value).then(function (unwrapped) {
4175
- result.value = unwrapped, resolve(result);
4176
- }, function (error) {
4177
- return invoke("throw", error, resolve, reject);
4178
- });
4179
- }
4180
- reject(record.arg);
4181
- }
4182
- var previousPromise;
4183
- defineProperty(this, "_invoke", {
4184
- value: function value(method, arg) {
4185
- function callInvokeWithMethodAndArg() {
4186
- return new PromiseImpl(function (resolve, reject) {
4187
- invoke(method, arg, resolve, reject);
4188
- });
3068
+ }));
4189
3069
  }
4190
- return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
4191
- }
4192
- });
4193
- }
4194
- function makeInvokeMethod(innerFn, self, context) {
4195
- var state = "suspendedStart";
4196
- return function (method, arg) {
4197
- if ("executing" === state) throw new Error("Generator is already running");
4198
- if ("completed" === state) {
4199
- if ("throw" === method) throw arg;
4200
- return doneResult();
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;
3070
+ // search objects intersect with dirty rectangle
3071
+ var dirtyObjects = _this.searchDirtyObjects(dirtyRenderBounds);
3072
+ // do rendering
3073
+ dirtyObjects
3074
+ // sort by z-index
3075
+ .sort(function (a, b) {
3076
+ return a.sortable.renderOrder - b.sortable.renderOrder;
3077
+ }).forEach(function (object) {
3078
+ // culled object should not be rendered
3079
+ if (object && object.isVisible() && !object.isCulled()) {
3080
+ _this.renderDisplayObject(object, context, _this.context, _this.restoreStack, runtime);
4209
3081
  }
4210
- }
4211
- if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
4212
- if ("suspendedStart" === state) throw state = "completed", context.arg;
4213
- context.dispatchException(context.arg);
4214
- } else "return" === context.method && context.abrupt("return", context.arg);
4215
- state = "executing";
4216
- var record = tryCatch(innerFn, self, context);
4217
- if ("normal" === record.type) {
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;
3082
+ });
3083
+ context.restore();
3084
+ // save dirty AABBs in last frame
3085
+ _this.renderQueue.forEach(function (object) {
3086
+ _this.saveDirtyAABB(object);
3087
+ });
3088
+ // clear queue
3089
+ _this.renderQueue = [];
4264
3090
  }
4265
- }
4266
- return {
4267
- next: doneResult
4268
- };
4269
- }
4270
- function doneResult() {
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();
3091
+ // pop restore stack, eg. root -> parent -> child
3092
+ _this.restoreStack.forEach(function () {
3093
+ context.restore();
3094
+ });
3095
+ // clear restore stack
3096
+ _this.restoreStack = [];
4298
3097
  });
4299
- }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
4300
- return this;
4301
- }), define(Gp, "toString", function () {
4302
- return "[object Generator]";
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
- }
3098
+ renderingService.hooks.render.tap(CanvasRendererPlugin.tag, function (object) {
3099
+ if (!_this.clearFullScreen) {
3100
+ // render at the end of frame
3101
+ _this.renderQueue.push(object);
4357
3102
  }
4358
- finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
4359
- var record = finallyEntry ? finallyEntry.completion : {};
4360
- return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
4361
- },
4362
- complete: function complete(record, afterLoc) {
4363
- if ("throw" === record.type) throw record.arg;
4364
- 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;
4365
- },
4366
- finish: function finish(finallyLoc) {
4367
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
4368
- var entry = this.tryEntries[i];
4369
- if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
3103
+ });
3104
+ };
3105
+ _proto.clearRect = function clearRect(context, x, y, width, height, background) {
3106
+ // clearRect is faster than fillRect @see https://stackoverflow.com/a/30830253
3107
+ context.clearRect(x, y, width, height);
3108
+ if (background) {
3109
+ context.fillStyle = background;
3110
+ context.fillRect(x, y, width, height);
3111
+ }
3112
+ };
3113
+ _proto.renderDisplayObject = function renderDisplayObject(object, context, canvasContext, restoreStack, runtime) {
3114
+ var nodeName = object.nodeName;
3115
+ // console.log('canvas render:', object);
3116
+ // restore to its ancestor
3117
+ var parent = restoreStack[restoreStack.length - 1];
3118
+ if (parent && !(object.compareDocumentPosition(parent) & Node.DOCUMENT_POSITION_CONTAINS)) {
3119
+ context.restore();
3120
+ restoreStack.pop();
3121
+ }
3122
+ // @ts-ignore
3123
+ var styleRenderer = this.context.styleRendererFactory[nodeName];
3124
+ var generatePath = this.pathGeneratorFactory[nodeName];
3125
+ // clip path
3126
+ var clipPath = object.parsedStyle.clipPath;
3127
+ if (clipPath) {
3128
+ this.applyWorldTransform(context, clipPath);
3129
+ // generate path in local space
3130
+ var _generatePath = this.pathGeneratorFactory[clipPath.nodeName];
3131
+ if (_generatePath) {
3132
+ context.save();
3133
+ // save clip
3134
+ restoreStack.push(object);
3135
+ context.beginPath();
3136
+ _generatePath(context, clipPath.parsedStyle);
3137
+ context.closePath();
3138
+ context.clip();
4370
3139
  }
4371
- },
4372
- catch: function _catch(tryLoc) {
4373
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
4374
- var entry = this.tryEntries[i];
4375
- if (entry.tryLoc === tryLoc) {
4376
- var record = entry.completion;
4377
- if ("throw" === record.type) {
4378
- var thrown = record.arg;
4379
- resetTryEntry(entry);
4380
- }
4381
- return thrown;
4382
- }
3140
+ }
3141
+ // fill & stroke
3142
+ if (styleRenderer) {
3143
+ this.applyWorldTransform(context, object);
3144
+ context.save();
3145
+ // apply attributes to context
3146
+ this.applyAttributesToContext(context, object);
3147
+ }
3148
+ if (generatePath) {
3149
+ context.beginPath();
3150
+ generatePath(context, object.parsedStyle);
3151
+ if (object.nodeName !== gLite.Shape.LINE && object.nodeName !== gLite.Shape.PATH && object.nodeName !== gLite.Shape.POLYLINE) {
3152
+ context.closePath();
4383
3153
  }
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
3154
  }
4393
- }, exports;
4394
- }
4395
- function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
4396
- try {
4397
- var info = gen[key](arg);
4398
- var value = info.value;
4399
- } catch (error) {
4400
- reject(error);
4401
- return;
4402
- }
4403
- if (info.done) {
4404
- resolve(value);
4405
- } else {
4406
- Promise.resolve(value).then(_next, _throw);
3155
+ // fill & stroke
3156
+ if (styleRenderer) {
3157
+ styleRenderer.render(context, object.parsedStyle, object, canvasContext, this, runtime);
3158
+ // restore applied attributes, eg. shadowBlur shadowColor...
3159
+ context.restore();
3160
+ }
3161
+ // finish rendering, clear dirty flag
3162
+ object.renderable.dirty = false;
3163
+ };
3164
+ _proto.convertAABB2Rect = function convertAABB2Rect(aabb) {
3165
+ var min = aabb.getMin();
3166
+ var max = aabb.getMax();
3167
+ // expand the rectangle a bit to avoid artifacts
3168
+ // @see https://www.yuque.com/antv/ou292n/bi8nix#ExvCu
3169
+ var minX = Math.floor(min[0]);
3170
+ var minY = Math.floor(min[1]);
3171
+ var maxX = Math.ceil(max[0]);
3172
+ var maxY = Math.ceil(max[1]);
3173
+ var width = maxX - minX;
3174
+ var height = maxY - minY;
3175
+ return {
3176
+ x: minX,
3177
+ y: minY,
3178
+ width: width,
3179
+ height: height
3180
+ };
4407
3181
  }
4408
- }
4409
- function _asyncToGenerator$3(fn) {
4410
- return function () {
4411
- var self = this,
4412
- args = arguments;
4413
- return new Promise(function (resolve, reject) {
4414
- var gen = fn.apply(self, args);
4415
- function _next(value) {
4416
- asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
4417
- }
4418
- function _throw(err) {
4419
- asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
3182
+ /**
3183
+ * TODO: merge dirty rectangles with some strategies.
3184
+ * For now, we just simply merge all the rectangles into one.
3185
+ * @see https://idom.me/articles/841.html
3186
+ */;
3187
+ _proto.mergeDirtyAABBs = function mergeDirtyAABBs(dirtyObjects) {
3188
+ // merge into a big AABB
3189
+ // TODO: skip descendant if ancestor is caculated, but compareNodePosition is really slow
3190
+ var aabb = new gLite.AABB();
3191
+ dirtyObjects.forEach(function (object) {
3192
+ var renderBounds = object.getRenderBounds();
3193
+ aabb.add(renderBounds);
3194
+ var dirtyRenderBounds = object.renderable.dirtyRenderBounds;
3195
+ if (dirtyRenderBounds) {
3196
+ aabb.add(dirtyRenderBounds);
4420
3197
  }
4421
- _next(undefined);
4422
3198
  });
3199
+ return aabb;
4423
3200
  };
4424
- }
4425
- function _inheritsLoose$4(subClass, superClass) {
4426
- subClass.prototype = Object.create(superClass.prototype);
4427
- subClass.prototype.constructor = subClass;
4428
- _setPrototypeOf$4(subClass, superClass);
4429
- }
4430
- function _setPrototypeOf$4(o, p) {
4431
- _setPrototypeOf$4 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
4432
- o.__proto__ = p;
4433
- return o;
3201
+ _proto.searchDirtyObjects = function searchDirtyObjects(dirtyRectangle) {
3202
+ // search in r-tree, get all affected nodes
3203
+ var _dirtyRectangle$getMi = dirtyRectangle.getMin(),
3204
+ minX = _dirtyRectangle$getMi[0],
3205
+ minY = _dirtyRectangle$getMi[1];
3206
+ var _dirtyRectangle$getMa = dirtyRectangle.getMax(),
3207
+ maxX = _dirtyRectangle$getMa[0],
3208
+ maxY = _dirtyRectangle$getMa[1];
3209
+ var rBushNodes = this.rBush.search({
3210
+ minX: minX,
3211
+ minY: minY,
3212
+ maxX: maxX,
3213
+ maxY: maxY
3214
+ });
3215
+ return rBushNodes.map(function (_ref2) {
3216
+ var displayObject = _ref2.displayObject;
3217
+ return displayObject;
3218
+ });
4434
3219
  };
4435
- return _setPrototypeOf$4(o, p);
4436
- }
4437
-
4438
- // const MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
4439
- /**
4440
- * listen to mouse/touch/pointer events on DOM wrapper, trigger pointer events
4441
- */
4442
- var DOMInteractionPlugin = /*#__PURE__*/function () {
4443
- function DOMInteractionPlugin() {
4444
- this.context = void 0;
3220
+ _proto.saveDirtyAABB = function saveDirtyAABB(object) {
3221
+ var renderable = object.renderable;
3222
+ if (!renderable.dirtyRenderBounds) {
3223
+ renderable.dirtyRenderBounds = new gLite.AABB();
3224
+ }
3225
+ var renderBounds = object.getRenderBounds();
3226
+ if (renderBounds) {
3227
+ // save last dirty aabb
3228
+ renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
3229
+ }
4445
3230
  }
4446
- var _proto = DOMInteractionPlugin.prototype;
4447
- _proto.apply = function apply(context, runtime) {
4448
- var _this = this;
4449
- var renderingService = context.renderingService,
4450
- renderingContext = context.renderingContext,
4451
- config = context.config;
4452
- this.context = context;
4453
- var canvas = renderingContext.root.ownerDocument.defaultView;
4454
- // const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
4455
- var onPointerMove = function onPointerMove(ev) {
4456
- renderingService.hooks.pointerMove.call(ev);
4457
- };
4458
- var onPointerUp = function onPointerUp(ev) {
4459
- renderingService.hooks.pointerUp.call(ev);
4460
- };
4461
- var onPointerDown = function onPointerDown(ev) {
4462
- renderingService.hooks.pointerDown.call(ev);
4463
- };
4464
- var onPointerOver = function onPointerOver(ev) {
4465
- renderingService.hooks.pointerOver.call(ev);
4466
- };
4467
- var onPointerOut = function onPointerOut(ev) {
4468
- renderingService.hooks.pointerOut.call(ev);
4469
- };
4470
- var onPointerCancel = function onPointerCancel(ev) {
4471
- renderingService.hooks.pointerCancel.call(ev);
4472
- };
4473
- var onPointerWheel = function onPointerWheel(ev) {
4474
- renderingService.hooks.pointerWheel.call(ev);
4475
- };
4476
- var onClick = function onClick(ev) {
4477
- renderingService.hooks.click.call(ev);
4478
- };
4479
- var addPointerEventListener = function addPointerEventListener($el) {
4480
- runtime.globalThis.document.addEventListener('pointermove', onPointerMove, true);
4481
- $el.addEventListener('pointerdown', onPointerDown, true);
4482
- $el.addEventListener('pointerleave', onPointerOut, true);
4483
- $el.addEventListener('pointerover', onPointerOver, true);
4484
- runtime.globalThis.addEventListener('pointerup', onPointerUp, true);
4485
- runtime.globalThis.addEventListener('pointercancel', onPointerCancel, true);
4486
- };
4487
- var addTouchEventListener = function addTouchEventListener($el) {
4488
- $el.addEventListener('touchstart', onPointerDown, true);
4489
- $el.addEventListener('touchend', onPointerUp, true);
4490
- $el.addEventListener('touchmove', onPointerMove, true);
4491
- $el.addEventListener('touchcancel', onPointerCancel, true);
4492
- };
4493
- var addMouseEventListener = function addMouseEventListener($el) {
4494
- runtime.globalThis.document.addEventListener('mousemove', onPointerMove, true);
4495
- $el.addEventListener('mousedown', onPointerDown, true);
4496
- $el.addEventListener('mouseout', onPointerOut, true);
4497
- $el.addEventListener('mouseover', onPointerOver, true);
4498
- runtime.globalThis.addEventListener('mouseup', onPointerUp, true);
4499
- };
4500
- var removePointerEventListener = function removePointerEventListener($el) {
4501
- runtime.globalThis.document.removeEventListener('pointermove', onPointerMove, true);
4502
- $el.removeEventListener('pointerdown', onPointerDown, true);
4503
- $el.removeEventListener('pointerleave', onPointerOut, true);
4504
- $el.removeEventListener('pointerover', onPointerOver, true);
4505
- runtime.globalThis.removeEventListener('pointerup', onPointerUp, true);
4506
- };
4507
- var removeTouchEventListener = function removeTouchEventListener($el) {
4508
- $el.removeEventListener('touchstart', onPointerDown, true);
4509
- $el.removeEventListener('touchend', onPointerUp, true);
4510
- $el.removeEventListener('touchmove', onPointerMove, true);
4511
- $el.removeEventListener('touchcancel', onPointerCancel, true);
4512
- };
4513
- var removeMouseEventListener = function removeMouseEventListener($el) {
4514
- runtime.globalThis.document.removeEventListener('mousemove', onPointerMove, true);
4515
- $el.removeEventListener('mousedown', onPointerDown, true);
4516
- $el.removeEventListener('mouseout', onPointerOut, true);
4517
- $el.removeEventListener('mouseover', onPointerOver, true);
4518
- runtime.globalThis.removeEventListener('mouseup', onPointerUp, true);
4519
- };
4520
- renderingService.hooks.init.tapPromise(DOMInteractionPlugin.tag, /*#__PURE__*/_asyncToGenerator$3( /*#__PURE__*/_regeneratorRuntime$3().mark(function _callee() {
4521
- var $el;
4522
- return _regeneratorRuntime$3().wrap(function _callee$(_context) {
4523
- while (1) switch (_context.prev = _context.next) {
4524
- case 0:
4525
- $el = _this.context.contextService.getDomElement(); // @ts-ignore
4526
- if (runtime.globalThis.navigator.msPointerEnabled) {
4527
- // @ts-ignore
4528
- $el.style.msContentZooming = 'none';
4529
- // @ts-ignore
4530
- $el.style.msTouchAction = 'none';
4531
- } else if (canvas.supportsPointerEvents) {
4532
- $el.style.touchAction = 'none';
4533
- }
4534
- if (canvas.supportsPointerEvents) {
4535
- addPointerEventListener($el);
4536
- } else {
4537
- addMouseEventListener($el);
4538
- }
4539
- if (canvas.supportsTouchEvents) {
4540
- addTouchEventListener($el);
4541
- }
4542
- if (config.useNativeClickEvent) {
4543
- $el.addEventListener('click', onClick, true);
4544
- }
4545
- // use passive event listeners
4546
- // @see https://zhuanlan.zhihu.com/p/24555031
4547
- $el.addEventListener('wheel', onPointerWheel, {
4548
- passive: true,
4549
- capture: true
4550
- });
4551
- case 6:
4552
- case "end":
4553
- return _context.stop();
4554
- }
4555
- }, _callee);
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 = '';
3231
+ /**
3232
+ * TODO: batch the same global attributes
3233
+ */;
3234
+ _proto.applyAttributesToContext = function applyAttributesToContext(context, object) {
3235
+ var _object$parsedStyle = object.parsedStyle,
3236
+ stroke = _object$parsedStyle.stroke,
3237
+ fill = _object$parsedStyle.fill,
3238
+ opacity = _object$parsedStyle.opacity,
3239
+ lineDash = _object$parsedStyle.lineDash,
3240
+ lineDashOffset = _object$parsedStyle.lineDashOffset;
3241
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash
3242
+ if (lineDash) {
3243
+ context.setLineDash(lineDash);
3244
+ }
3245
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
3246
+ if (!isNil(lineDashOffset)) {
3247
+ context.lineDashOffset = lineDashOffset;
3248
+ }
3249
+ if (!isNil(opacity)) {
3250
+ context.globalAlpha *= opacity;
3251
+ }
3252
+ if (!isNil(stroke) && !Array.isArray(stroke) && !stroke.isNone) {
3253
+ context.strokeStyle = object.attributes.stroke;
3254
+ }
3255
+ if (!isNil(fill) && !Array.isArray(fill) && !fill.isNone) {
3256
+ context.fillStyle = object.attributes.fill;
3257
+ }
3258
+ };
3259
+ _proto.applyWorldTransform = function applyWorldTransform(context, object, matrix) {
3260
+ var tx = 0;
3261
+ var ty = 0;
3262
+ var _ref3 = object.parsedStyle || {},
3263
+ anchor = _ref3.anchor;
3264
+ var anchorX = anchor && anchor[0] || 0;
3265
+ var anchorY = anchor && anchor[1] || 0;
3266
+ if (anchorX !== 0 || anchorY !== 0) {
3267
+ // const bounds = object.getGeometryBounds();
3268
+ var bounds = object.geometry.contentBounds;
3269
+ var width = bounds && bounds.halfExtents[0] * 2 || 0;
3270
+ var height = bounds && bounds.halfExtents[1] * 2 || 0;
3271
+ tx = -(anchorX * width);
3272
+ ty = -(anchorY * height);
3273
+ }
3274
+ // apply clip shape's RTS
3275
+ if (matrix) {
3276
+ copy(this.tmpMat4, object.getLocalTransform());
3277
+ this.vec3a[0] = tx;
3278
+ this.vec3a[1] = ty;
3279
+ this.vec3a[2] = 0;
3280
+ translate(this.tmpMat4, this.tmpMat4, this.vec3a);
3281
+ multiply(this.tmpMat4, matrix, this.tmpMat4);
3282
+ multiply(this.tmpMat4, this.vpMatrix, this.tmpMat4);
3283
+ } else {
3284
+ // apply RTS transformation in world space
3285
+ copy(this.tmpMat4, object.getWorldTransform());
3286
+ this.vec3a[0] = tx;
3287
+ this.vec3a[1] = ty;
3288
+ this.vec3a[2] = 0;
3289
+ translate(this.tmpMat4, this.tmpMat4, this.vec3a);
3290
+ multiply(this.tmpMat4, this.vpMatrix, this.tmpMat4);
3291
+ }
3292
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
3293
+ context.setTransform(this.tmpMat4[0], this.tmpMat4[1], this.tmpMat4[4], this.tmpMat4[5], this.tmpMat4[12], this.tmpMat4[13]);
3294
+ };
3295
+ _proto.safeMergeAABB = function safeMergeAABB() {
3296
+ var merged = new gLite.AABB();
3297
+ for (var _len = arguments.length, aabbs = new Array(_len), _key = 0; _key < _len; _key++) {
3298
+ aabbs[_key] = arguments[_key];
3299
+ }
3300
+ aabbs.forEach(function (aabb) {
3301
+ merged.add(aabb);
3302
+ });
3303
+ return merged;
3304
+ };
3305
+ return CanvasRendererPlugin;
3306
+ }();
3307
+ CanvasRendererPlugin.tag = 'CanvasRenderer';
3308
+ var DefaultRenderer = /*#__PURE__*/function () {
3309
+ function DefaultRenderer(imagePool) {
3310
+ this.imagePool = void 0;
3311
+ this.imagePool = imagePool;
3312
+ }
3313
+ var _proto = DefaultRenderer.prototype;
3314
+ _proto.render = function render(context, parsedStyle, object, canvasContext, plugin, runtime) {
3315
+ var fill = parsedStyle.fill,
3316
+ fillRule = parsedStyle.fillRule,
3317
+ opacity = parsedStyle.opacity,
3318
+ fillOpacity = parsedStyle.fillOpacity,
3319
+ stroke = parsedStyle.stroke,
3320
+ strokeOpacity = parsedStyle.strokeOpacity,
3321
+ lineWidth = parsedStyle.lineWidth,
3322
+ lineCap = parsedStyle.lineCap,
3323
+ lineJoin = parsedStyle.lineJoin,
3324
+ shadowType = parsedStyle.shadowType,
3325
+ shadowColor = parsedStyle.shadowColor,
3326
+ shadowBlur = parsedStyle.shadowBlur,
3327
+ filter = parsedStyle.filter,
3328
+ miterLimit = parsedStyle.miterLimit;
3329
+ var hasFill = !isNil(fill) && !fill.isNone;
3330
+ var hasStroke = !isNil(stroke) && !stroke.isNone && lineWidth > 0;
3331
+ var isFillTransparent = fill.alpha === 0;
3332
+ var hasFilter = !!(filter && filter.length);
3333
+ var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
3334
+ var nodeName = object.nodeName;
3335
+ var isInnerShadow = shadowType === 'inner';
3336
+ var shouldDrawShadowWithStroke = hasStroke && hasShadow && (nodeName === gLite.Shape.PATH || nodeName === gLite.Shape.LINE || nodeName === gLite.Shape.POLYLINE || isFillTransparent || isInnerShadow);
3337
+ if (hasFill) {
3338
+ context.globalAlpha = opacity * fillOpacity;
3339
+ if (!shouldDrawShadowWithStroke) {
3340
+ setShadowAndFilter(object, context, hasShadow);
4567
3341
  }
4568
- if (canvas.supportsPointerEvents) {
4569
- removePointerEventListener($el);
4570
- } else {
4571
- removeMouseEventListener($el);
3342
+ this.fill(context, object, fill, fillRule, canvasContext, plugin, runtime);
3343
+ if (!shouldDrawShadowWithStroke) {
3344
+ this.clearShadowAndFilter(context, hasFilter, hasShadow);
4572
3345
  }
4573
- if (canvas.supportsTouchEvents) {
4574
- removeTouchEventListener($el);
3346
+ }
3347
+ if (hasStroke) {
3348
+ context.globalAlpha = opacity * strokeOpacity;
3349
+ context.lineWidth = lineWidth;
3350
+ if (!isNil(miterLimit)) {
3351
+ context.miterLimit = miterLimit;
4575
3352
  }
4576
- if (config.useNativeClickEvent) {
4577
- $el.removeEventListener('click', onClick, true);
3353
+ if (!isNil(lineCap)) {
3354
+ context.lineCap = lineCap;
4578
3355
  }
4579
- $el.removeEventListener('wheel', onPointerWheel, true);
4580
- });
4581
- };
4582
- return DOMInteractionPlugin;
4583
- }();
4584
- DOMInteractionPlugin.tag = 'DOMInteraction';
4585
- var Plugin$3 = /*#__PURE__*/function (_AbstractRendererPlug) {
4586
- _inheritsLoose$4(Plugin, _AbstractRendererPlug);
4587
- function Plugin() {
4588
- var _this;
4589
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
4590
- args[_key] = arguments[_key];
3356
+ if (!isNil(lineJoin)) {
3357
+ context.lineJoin = lineJoin;
3358
+ }
3359
+ if (shouldDrawShadowWithStroke) {
3360
+ if (isInnerShadow) {
3361
+ context.globalCompositeOperation = 'source-atop';
3362
+ }
3363
+ setShadowAndFilter(object, context, true);
3364
+ if (isInnerShadow) {
3365
+ this.stroke(context, object, stroke, canvasContext, plugin, runtime);
3366
+ context.globalCompositeOperation = 'source-over';
3367
+ this.clearShadowAndFilter(context, hasFilter, true);
3368
+ }
3369
+ }
3370
+ this.stroke(context, object, stroke, canvasContext, plugin, runtime);
4591
3371
  }
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
3372
  };
4600
- _proto.destroy = function destroy() {
4601
- this.removeAllRenderingPlugins();
3373
+ _proto.clearShadowAndFilter = function clearShadowAndFilter(context, hasFilter, hasShadow) {
3374
+ if (hasShadow) {
3375
+ context.shadowColor = 'transparent';
3376
+ context.shadowBlur = 0;
3377
+ }
3378
+ if (hasFilter) {
3379
+ // save drop-shadow filter
3380
+ var oldFilter = context.filter;
3381
+ if (!isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
3382
+ context.filter = oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || 'none';
3383
+ }
3384
+ }
4602
3385
  };
4603
- return Plugin;
4604
- }(gLite.AbstractRendererPlugin);
4605
-
4606
- var index_esm$3 = /*#__PURE__*/Object.freeze({
4607
- __proto__: null,
4608
- Plugin: Plugin$3
4609
- });
4610
-
4611
- function _regeneratorRuntime$4() {
4612
- _regeneratorRuntime$4 = function _regeneratorRuntime() {
4613
- return exports;
3386
+ _proto.fill = function fill(context, object, _fill, fillRule, canvasContext, plugin, runtime) {
3387
+ var _this = this;
3388
+ if (Array.isArray(_fill)) {
3389
+ _fill.forEach(function (gradient) {
3390
+ context.fillStyle = _this.getColor(gradient, object, context);
3391
+ fillRule ? context.fill(fillRule) : context.fill();
3392
+ });
3393
+ } else {
3394
+ if (gLite.isPattern(_fill)) {
3395
+ context.fillStyle = this.getPattern(_fill, object, context, canvasContext, plugin, runtime);
3396
+ }
3397
+ fillRule ? context.fill(fillRule) : context.fill();
3398
+ }
4614
3399
  };
4615
- var exports = {},
4616
- Op = Object.prototype,
4617
- hasOwn = Op.hasOwnProperty,
4618
- defineProperty = Object.defineProperty || function (obj, key, desc) {
4619
- obj[key] = desc.value;
4620
- },
4621
- $Symbol = "function" == typeof Symbol ? Symbol : {},
4622
- iteratorSymbol = $Symbol.iterator || "@@iterator",
4623
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
4624
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
4625
- function define(obj, key, value) {
4626
- return Object.defineProperty(obj, key, {
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
- };
3400
+ _proto.stroke = function stroke(context, object, _stroke, canvasContext, plugin, runtime) {
3401
+ var _this2 = this;
3402
+ if (Array.isArray(_stroke)) {
3403
+ _stroke.forEach(function (gradient) {
3404
+ context.strokeStyle = _this2.getColor(gradient, object, context);
3405
+ context.stroke();
3406
+ });
3407
+ } else {
3408
+ if (gLite.isPattern(_stroke)) {
3409
+ context.strokeStyle = this.getPattern(_stroke, object, context, canvasContext, plugin, runtime);
3410
+ }
3411
+ context.stroke();
4659
3412
  }
4660
- }
4661
- exports.wrap = wrap;
4662
- var ContinueSentinel = {};
4663
- function Generator() {}
4664
- function GeneratorFunction() {}
4665
- function GeneratorFunctionPrototype() {}
4666
- var IteratorPrototype = {};
4667
- define(IteratorPrototype, iteratorSymbol, function () {
4668
- return this;
4669
- });
4670
- var getProto = Object.getPrototypeOf,
4671
- NativeIteratorPrototype = getProto && getProto(getProto(values([])));
4672
- NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
4673
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
4674
- function defineIteratorMethods(prototype) {
4675
- ["next", "throw", "return"].forEach(function (method) {
4676
- define(prototype, method, function (arg) {
4677
- return this._invoke(method, arg);
3413
+ };
3414
+ _proto.getPattern = function getPattern(pattern, object, context, canvasContext, plugin, runtime) {
3415
+ var $offscreenCanvas;
3416
+ var dpr;
3417
+ if (pattern.image.nodeName === 'rect') {
3418
+ var _pattern$image$parsed = pattern.image.parsedStyle,
3419
+ width = _pattern$image$parsed.width,
3420
+ height = _pattern$image$parsed.height;
3421
+ dpr = canvasContext.contextService.getDPR();
3422
+ var offscreenCanvas = canvasContext.config.offscreenCanvas;
3423
+ $offscreenCanvas = runtime.offscreenCanvas.getOrCreateCanvas(offscreenCanvas);
3424
+ $offscreenCanvas.width = width * dpr;
3425
+ $offscreenCanvas.height = height * dpr;
3426
+ var offscreenCanvasContext = runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas);
3427
+ var restoreStack = [];
3428
+ // offscreenCanvasContext.scale(1 / dpr, 1 / dpr);
3429
+ pattern.image.forEach(function (object) {
3430
+ plugin.renderDisplayObject(object, offscreenCanvasContext, canvasContext, restoreStack, runtime);
3431
+ });
3432
+ restoreStack.forEach(function () {
3433
+ offscreenCanvasContext.restore();
4678
3434
  });
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
3435
  }
4699
- var previousPromise;
4700
- defineProperty(this, "_invoke", {
4701
- value: function value(method, arg) {
4702
- function callInvokeWithMethodAndArg() {
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
- }
3436
+ var canvasPattern = this.imagePool.getOrCreatePatternSync(pattern, context, $offscreenCanvas, dpr, function () {
3437
+ // set dirty rectangle flag
3438
+ object.renderable.dirty = true;
3439
+ canvasContext.renderingService.dirtify();
4709
3440
  });
3441
+ return canvasPattern;
3442
+ };
3443
+ _proto.getColor = function getColor(parsedColor, object, context) {
3444
+ var color;
3445
+ if (parsedColor.type === gLite.GradientType.LinearGradient || parsedColor.type === gLite.GradientType.RadialGradient) {
3446
+ var bounds = object.getGeometryBounds();
3447
+ var width = bounds && bounds.halfExtents[0] * 2 || 1;
3448
+ var height = bounds && bounds.halfExtents[1] * 2 || 1;
3449
+ color = this.imagePool.getOrCreateGradient(_extends({
3450
+ type: parsedColor.type
3451
+ }, parsedColor.value, {
3452
+ width: width,
3453
+ height: height
3454
+ }), context);
3455
+ }
3456
+ return color;
3457
+ };
3458
+ return DefaultRenderer;
3459
+ }();
3460
+ /**
3461
+ * apply before fill and stroke but only once
3462
+ */
3463
+ function setShadowAndFilter(object, context, hasShadow) {
3464
+ var _object$parsedStyle = object.parsedStyle,
3465
+ filter = _object$parsedStyle.filter,
3466
+ shadowColor = _object$parsedStyle.shadowColor,
3467
+ shadowBlur = _object$parsedStyle.shadowBlur,
3468
+ shadowOffsetX = _object$parsedStyle.shadowOffsetX,
3469
+ shadowOffsetY = _object$parsedStyle.shadowOffsetY;
3470
+ if (filter && filter.length) {
3471
+ // use raw filter string
3472
+ context.filter = object.style.filter;
4710
3473
  }
4711
- function makeInvokeMethod(innerFn, self, context) {
4712
- var state = "suspendedStart";
4713
- return function (method, arg) {
4714
- if ("executing" === state) throw new Error("Generator is already running");
4715
- if ("completed" === state) {
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;
3474
+ if (hasShadow) {
3475
+ context.shadowColor = shadowColor.toString();
3476
+ context.shadowBlur = shadowBlur || 0;
3477
+ context.shadowOffsetX = shadowOffsetX || 0;
3478
+ context.shadowOffsetY = shadowOffsetY || 0;
4763
3479
  }
4764
- function Context(tryLocsList) {
4765
- this.tryEntries = [{
4766
- tryLoc: "root"
4767
- }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
3480
+ }
3481
+ var ImageRenderer = /*#__PURE__*/function () {
3482
+ function ImageRenderer(imagePool) {
3483
+ this.imagePool = void 0;
3484
+ this.imagePool = imagePool;
4768
3485
  }
4769
- function values(iterable) {
4770
- if (iterable) {
4771
- var iteratorMethod = iterable[iteratorSymbol];
4772
- if (iteratorMethod) return iteratorMethod.call(iterable);
4773
- if ("function" == typeof iterable.next) return iterable;
4774
- if (!isNaN(iterable.length)) {
4775
- var i = -1,
4776
- next = function next() {
4777
- for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
4778
- return next.value = undefined, next.done = !0, next;
4779
- };
4780
- return next.next = next;
4781
- }
3486
+ var _proto = ImageRenderer.prototype;
3487
+ _proto.render = function render(context, parsedStyle, object) {
3488
+ var width = parsedStyle.width,
3489
+ height = parsedStyle.height,
3490
+ img = parsedStyle.img,
3491
+ shadowColor = parsedStyle.shadowColor,
3492
+ shadowBlur = parsedStyle.shadowBlur;
3493
+ var image;
3494
+ var iw = width;
3495
+ var ih = height;
3496
+ if (isString(img)) {
3497
+ // image has been loaded in `mounted` hook
3498
+ image = this.imagePool.getImageSync(img);
3499
+ } else {
3500
+ iw || (iw = img.width);
3501
+ ih || (ih = img.height);
3502
+ image = img;
4782
3503
  }
4783
- return {
4784
- next: doneResult
4785
- };
4786
- }
4787
- function doneResult() {
4788
- return {
4789
- value: undefined,
4790
- done: !0
4791
- };
4792
- }
4793
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
4794
- value: GeneratorFunctionPrototype,
4795
- configurable: !0
4796
- }), defineProperty(GeneratorFunctionPrototype, "constructor", {
4797
- value: GeneratorFunction,
4798
- configurable: !0
4799
- }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
4800
- var ctor = "function" == typeof genFun && genFun.constructor;
4801
- return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
4802
- }, exports.mark = function (genFun) {
4803
- return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
4804
- }, exports.awrap = function (arg) {
4805
- return {
4806
- __await: arg
4807
- };
4808
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
4809
- return this;
4810
- }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
4811
- void 0 === PromiseImpl && (PromiseImpl = Promise);
4812
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
4813
- return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
4814
- return result.done ? result.value : iter.next();
4815
- });
4816
- }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
4817
- return this;
4818
- }), define(Gp, "toString", function () {
4819
- return "[object Generator]";
4820
- }), exports.keys = function (val) {
4821
- var object = Object(val),
4822
- keys = [];
4823
- for (var key in object) keys.push(key);
4824
- return keys.reverse(), function next() {
4825
- for (; keys.length;) {
4826
- var key = keys.pop();
4827
- if (key in object) return next.value = key, next.done = !1, next;
4828
- }
4829
- return next.done = !0, next;
4830
- };
4831
- }, exports.values = values, Context.prototype = {
4832
- constructor: Context,
4833
- reset: function reset(skipTempReset) {
4834
- 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);
4835
- },
4836
- stop: function stop() {
4837
- this.done = !0;
4838
- var rootRecord = this.tryEntries[0].completion;
4839
- if ("throw" === rootRecord.type) throw rootRecord.arg;
4840
- return this.rval;
4841
- },
4842
- dispatchException: function dispatchException(exception) {
4843
- if (this.done) throw exception;
4844
- var context = this;
4845
- function handle(loc, caught) {
4846
- return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
3504
+ if (image) {
3505
+ var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
3506
+ setShadowAndFilter(object, context, hasShadow);
3507
+ // node-canvas will throw the following err:
3508
+ // Error: Image given has not completed loading
3509
+ try {
3510
+ context.drawImage(image, 0, 0, iw, ih);
3511
+ } catch (e) {}
3512
+ }
3513
+ };
3514
+ return ImageRenderer;
3515
+ }();
3516
+ var TextRenderer = /*#__PURE__*/function () {
3517
+ function TextRenderer() {}
3518
+ var _proto = TextRenderer.prototype;
3519
+ _proto.render = function render(context, parsedStyle, object) {
3520
+ var lineWidth = parsedStyle.lineWidth,
3521
+ textAlign = parsedStyle.textAlign,
3522
+ textBaseline = parsedStyle.textBaseline,
3523
+ lineJoin = parsedStyle.lineJoin,
3524
+ miterLimit = parsedStyle.miterLimit,
3525
+ letterSpacing = parsedStyle.letterSpacing,
3526
+ stroke = parsedStyle.stroke,
3527
+ fill = parsedStyle.fill,
3528
+ fillOpacity = parsedStyle.fillOpacity,
3529
+ strokeOpacity = parsedStyle.strokeOpacity,
3530
+ opacity = parsedStyle.opacity,
3531
+ metrics = parsedStyle.metrics,
3532
+ dx = parsedStyle.dx,
3533
+ dy = parsedStyle.dy,
3534
+ shadowColor = parsedStyle.shadowColor,
3535
+ shadowBlur = parsedStyle.shadowBlur;
3536
+ var font = metrics.font,
3537
+ lines = metrics.lines,
3538
+ height = metrics.height,
3539
+ lineHeight = metrics.lineHeight,
3540
+ lineMetrics = metrics.lineMetrics;
3541
+ context.font = font;
3542
+ context.lineWidth = lineWidth;
3543
+ context.textAlign = textAlign === 'middle' ? 'center' : textAlign;
3544
+ var formattedTextBaseline = textBaseline;
3545
+ if (
3546
+ // formattedTextBaseline === 'bottom' ||
3547
+ !gLite.runtime.enableCSSParsing && formattedTextBaseline === 'alphabetic') {
3548
+ formattedTextBaseline = 'bottom';
3549
+ }
3550
+ context.lineJoin = lineJoin;
3551
+ if (!isNil(miterLimit)) {
3552
+ context.miterLimit = miterLimit;
3553
+ }
3554
+ var linePositionY = 0;
3555
+ // handle vertical text baseline
3556
+ if (textBaseline === 'middle') {
3557
+ linePositionY = -height / 2 - lineHeight / 2;
3558
+ } else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
3559
+ linePositionY = -height;
3560
+ } else if (textBaseline === 'top' || textBaseline === 'hanging') {
3561
+ linePositionY = -lineHeight;
3562
+ }
3563
+ // account for dx & dy
3564
+ var offsetX = dx || 0;
3565
+ linePositionY += dy || 0;
3566
+ if (lines.length === 1) {
3567
+ if (formattedTextBaseline === 'bottom') {
3568
+ formattedTextBaseline = 'middle';
3569
+ linePositionY -= 0.5 * height;
3570
+ } else if (formattedTextBaseline === 'top') {
3571
+ formattedTextBaseline = 'middle';
3572
+ linePositionY += 0.5 * height;
4847
3573
  }
4848
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
4849
- var entry = this.tryEntries[i],
4850
- record = entry.completion;
4851
- if ("root" === entry.tryLoc) return handle("end");
4852
- if (entry.tryLoc <= this.prev) {
4853
- var hasCatch = hasOwn.call(entry, "catchLoc"),
4854
- hasFinally = hasOwn.call(entry, "finallyLoc");
4855
- if (hasCatch && hasFinally) {
4856
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
4857
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
4858
- } else if (hasCatch) {
4859
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
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
- }
3574
+ }
3575
+ context.textBaseline = formattedTextBaseline;
3576
+ var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
3577
+ setShadowAndFilter(object, context, hasShadow);
3578
+ // draw lines line by line
3579
+ for (var i = 0; i < lines.length; i++) {
3580
+ var linePositionX = lineWidth / 2 + offsetX;
3581
+ linePositionY += lineHeight;
3582
+ // no need to re-position X, cause we already set text align
3583
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
3584
+ if (!isNil(stroke) && !stroke.isNone && lineWidth) {
3585
+ this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign, linePositionX, linePositionY, letterSpacing, fillOpacity, strokeOpacity, opacity, true);
4865
3586
  }
4866
- },
4867
- abrupt: function abrupt(type, arg) {
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
- }
3587
+ if (!isNil(fill)) {
3588
+ this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign, linePositionX, linePositionY, letterSpacing, fillOpacity, strokeOpacity, opacity);
4874
3589
  }
4875
- finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
4876
- var record = finallyEntry ? finallyEntry.completion : {};
4877
- return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
4878
- },
4879
- complete: function complete(record, afterLoc) {
4880
- if ("throw" === record.type) throw record.arg;
4881
- 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;
4882
- },
4883
- finish: function finish(finallyLoc) {
4884
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
4885
- var entry = this.tryEntries[i];
4886
- if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
3590
+ }
3591
+ };
3592
+ _proto.drawLetterSpacing = function drawLetterSpacing(context, text, lineMetrics, textAlign, x, y, letterSpacing, fillOpacity, strokeOpacity, opacity, isStroke) {
3593
+ if (isStroke === void 0) {
3594
+ isStroke = false;
3595
+ }
3596
+ // letterSpacing of 0 means normal, render all texts directly
3597
+ if (letterSpacing === 0) {
3598
+ if (isStroke) {
3599
+ this.strokeText(context, text, x, y, strokeOpacity);
3600
+ } else {
3601
+ this.fillText(context, text, x, y, fillOpacity, opacity);
4887
3602
  }
4888
- },
4889
- catch: function _catch(tryLoc) {
4890
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
4891
- var entry = this.tryEntries[i];
4892
- if (entry.tryLoc === tryLoc) {
4893
- var record = entry.completion;
4894
- if ("throw" === record.type) {
4895
- var thrown = record.arg;
4896
- resetTryEntry(entry);
4897
- }
4898
- return thrown;
4899
- }
3603
+ return;
3604
+ }
3605
+ // draw text using left align
3606
+ var currentTextAlign = context.textAlign;
3607
+ context.textAlign = 'left';
3608
+ var currentPosition = x;
3609
+ if (textAlign === 'center' || textAlign === 'middle') {
3610
+ currentPosition = x - lineMetrics.width / 2;
3611
+ } else if (textAlign === 'right' || textAlign === 'end') {
3612
+ currentPosition = x - lineMetrics.width;
3613
+ }
3614
+ var stringArray = Array.from(text);
3615
+ var previousWidth = context.measureText(text).width;
3616
+ var currentWidth = 0;
3617
+ for (var i = 0; i < stringArray.length; ++i) {
3618
+ var currentChar = stringArray[i];
3619
+ if (isStroke) {
3620
+ this.strokeText(context, currentChar, currentPosition, y, strokeOpacity);
3621
+ } else {
3622
+ this.fillText(context, currentChar, currentPosition, y, fillOpacity, opacity);
4900
3623
  }
4901
- throw new Error("illegal catch attempt");
4902
- },
4903
- delegateYield: function delegateYield(iterable, resultName, nextLoc) {
4904
- return this.delegate = {
4905
- iterator: values(iterable),
4906
- resultName: resultName,
4907
- nextLoc: nextLoc
4908
- }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
3624
+ currentWidth = context.measureText(text.substring(i + 1)).width;
3625
+ currentPosition += previousWidth - currentWidth + letterSpacing;
3626
+ previousWidth = currentWidth;
4909
3627
  }
4910
- }, exports;
4911
- }
4912
- function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
4913
- try {
4914
- var info = gen[key](arg);
4915
- var value = info.value;
4916
- } catch (error) {
4917
- reject(error);
4918
- return;
3628
+ context.textAlign = currentTextAlign;
3629
+ };
3630
+ _proto.fillText = function fillText(context, text, x, y, fillOpacity, opacity) {
3631
+ var currentGlobalAlpha;
3632
+ var applyOpacity = !isNil(fillOpacity) && fillOpacity !== 1;
3633
+ if (applyOpacity) {
3634
+ currentGlobalAlpha = context.globalAlpha;
3635
+ context.globalAlpha = fillOpacity * opacity;
3636
+ }
3637
+ context.fillText(text, x, y);
3638
+ if (applyOpacity) {
3639
+ context.globalAlpha = currentGlobalAlpha;
3640
+ }
3641
+ };
3642
+ _proto.strokeText = function strokeText(context, text, x, y, strokeOpacity) {
3643
+ var currentGlobalAlpha;
3644
+ var applyOpacity = !isNil(strokeOpacity) && strokeOpacity !== 1;
3645
+ if (applyOpacity) {
3646
+ currentGlobalAlpha = context.globalAlpha;
3647
+ context.globalAlpha = strokeOpacity;
3648
+ }
3649
+ context.strokeText(text, x, y);
3650
+ if (applyOpacity) {
3651
+ context.globalAlpha = currentGlobalAlpha;
3652
+ }
3653
+ };
3654
+ return TextRenderer;
3655
+ }();
3656
+ var RectRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3657
+ _inheritsLoose$3(RectRenderer, _DefaultRenderer);
3658
+ function RectRenderer() {
3659
+ return _DefaultRenderer.apply(this, arguments) || this;
4919
3660
  }
4920
- if (info.done) {
4921
- resolve(value);
4922
- } else {
4923
- Promise.resolve(value).then(_next, _throw);
3661
+ return RectRenderer;
3662
+ }(DefaultRenderer);
3663
+ var CircleRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3664
+ _inheritsLoose$3(CircleRenderer, _DefaultRenderer);
3665
+ function CircleRenderer() {
3666
+ return _DefaultRenderer.apply(this, arguments) || this;
4924
3667
  }
4925
- }
4926
- function _asyncToGenerator$4(fn) {
4927
- return function () {
4928
- var self = this,
4929
- args = arguments;
4930
- return new Promise(function (resolve, reject) {
4931
- var gen = fn.apply(self, args);
4932
- function _next(value) {
4933
- asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "next", value);
4934
- }
4935
- function _throw(err) {
4936
- asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "throw", err);
4937
- }
4938
- _next(undefined);
4939
- });
3668
+ return CircleRenderer;
3669
+ }(DefaultRenderer);
3670
+ var EllipseRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3671
+ _inheritsLoose$3(EllipseRenderer, _DefaultRenderer);
3672
+ function EllipseRenderer() {
3673
+ return _DefaultRenderer.apply(this, arguments) || this;
3674
+ }
3675
+ return EllipseRenderer;
3676
+ }(DefaultRenderer);
3677
+ var LineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3678
+ _inheritsLoose$3(LineRenderer, _DefaultRenderer);
3679
+ function LineRenderer() {
3680
+ return _DefaultRenderer.apply(this, arguments) || this;
3681
+ }
3682
+ return LineRenderer;
3683
+ }(DefaultRenderer);
3684
+ var PolylineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3685
+ _inheritsLoose$3(PolylineRenderer, _DefaultRenderer);
3686
+ function PolylineRenderer() {
3687
+ return _DefaultRenderer.apply(this, arguments) || this;
3688
+ }
3689
+ return PolylineRenderer;
3690
+ }(DefaultRenderer);
3691
+ var PolygonRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3692
+ _inheritsLoose$3(PolygonRenderer, _DefaultRenderer);
3693
+ function PolygonRenderer() {
3694
+ return _DefaultRenderer.apply(this, arguments) || this;
3695
+ }
3696
+ return PolygonRenderer;
3697
+ }(DefaultRenderer);
3698
+ var PathRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3699
+ _inheritsLoose$3(PathRenderer, _DefaultRenderer);
3700
+ function PathRenderer() {
3701
+ return _DefaultRenderer.apply(this, arguments) || this;
3702
+ }
3703
+ return PathRenderer;
3704
+ }(DefaultRenderer);
3705
+ var Plugin$2 = /*#__PURE__*/function (_AbstractRendererPlug) {
3706
+ _inheritsLoose$3(Plugin, _AbstractRendererPlug);
3707
+ function Plugin(options) {
3708
+ var _this;
3709
+ if (options === void 0) {
3710
+ options = {};
3711
+ }
3712
+ _this = _AbstractRendererPlug.call(this) || this;
3713
+ _this.options = void 0;
3714
+ _this.name = 'canvas-renderer';
3715
+ _this.options = options;
3716
+ return _this;
3717
+ }
3718
+ var _proto = Plugin.prototype;
3719
+ _proto.init = function init() {
3720
+ var _defaultStyleRenderer;
3721
+ var canvasRendererPluginOptions = _extends({
3722
+ dirtyObjectNumThreshold: 500,
3723
+ dirtyObjectRatioThreshold: 0.8
3724
+ }, this.options);
3725
+ // @ts-ignore
3726
+ var imagePool = this.context.imagePool;
3727
+ var defaultRenderer = new DefaultRenderer(imagePool);
3728
+ 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);
3729
+ this.context.defaultStyleRendererFactory = defaultStyleRendererFactory;
3730
+ this.context.styleRendererFactory = defaultStyleRendererFactory;
3731
+ this.addRenderingPlugin(new CanvasRendererPlugin(canvasRendererPluginOptions));
4940
3732
  };
4941
- }
4942
- function _inheritsLoose$5(subClass, superClass) {
3733
+ _proto.destroy = function destroy() {
3734
+ this.removeAllRenderingPlugins();
3735
+ delete this.context.defaultStyleRendererFactory;
3736
+ delete this.context.styleRendererFactory;
3737
+ };
3738
+ return Plugin;
3739
+ }(gLite.AbstractRendererPlugin);
3740
+
3741
+ var index_esm$2 = /*#__PURE__*/Object.freeze({
3742
+ __proto__: null,
3743
+ CircleRenderer: CircleRenderer,
3744
+ EllipseRenderer: EllipseRenderer,
3745
+ ImageRenderer: ImageRenderer,
3746
+ LineRenderer: LineRenderer,
3747
+ PathRenderer: PathRenderer,
3748
+ Plugin: Plugin$2,
3749
+ PolygonRenderer: PolygonRenderer,
3750
+ PolylineRenderer: PolylineRenderer,
3751
+ RectRenderer: RectRenderer,
3752
+ TextRenderer: TextRenderer
3753
+ });
3754
+
3755
+ function _inheritsLoose$4(subClass, superClass) {
4943
3756
  subClass.prototype = Object.create(superClass.prototype);
4944
3757
  subClass.prototype.constructor = subClass;
4945
- _setPrototypeOf$5(subClass, superClass);
3758
+ _setPrototypeOf$4(subClass, superClass);
4946
3759
  }
4947
- function _setPrototypeOf$5(o, p) {
4948
- _setPrototypeOf$5 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
3760
+ function _setPrototypeOf$4(o, p) {
3761
+ _setPrototypeOf$4 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
4949
3762
  o.__proto__ = p;
4950
3763
  return o;
4951
3764
  };
4952
- return _setPrototypeOf$5(o, p);
3765
+ return _setPrototypeOf$4(o, p);
4953
3766
  }
4954
- var HTML_PREFIX = 'g-html-';
4955
- var CANVAS_CAMERA_ID = 'g-canvas-camera';
4956
- var HTMLRenderingPlugin = /*#__PURE__*/function () {
4957
- function HTMLRenderingPlugin() {
3767
+
3768
+ // const MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
3769
+ /**
3770
+ * listen to mouse/touch/pointer events on DOM wrapper, trigger pointer events
3771
+ */
3772
+ var DOMInteractionPlugin = /*#__PURE__*/function () {
3773
+ function DOMInteractionPlugin() {
4958
3774
  this.context = void 0;
4959
- /**
4960
- * wrapper for camera
4961
- */
4962
- this.$camera = void 0;
4963
3775
  }
4964
- var _proto = HTMLRenderingPlugin.prototype;
4965
- _proto.joinTransformMatrix = function joinTransformMatrix(matrix) {
4966
- return "matrix(" + [matrix[0], matrix[1], matrix[4], matrix[5], matrix[12], matrix[13]].join(',') + ")";
4967
- };
4968
- _proto.apply = function apply(context) {
3776
+ var _proto = DOMInteractionPlugin.prototype;
3777
+ _proto.apply = function apply(context, runtime) {
4969
3778
  var _this = this;
4970
- var camera = context.camera,
3779
+ var renderingService = context.renderingService,
4971
3780
  renderingContext = context.renderingContext,
4972
- renderingService = context.renderingService;
3781
+ config = context.config;
4973
3782
  this.context = context;
4974
3783
  var canvas = renderingContext.root.ownerDocument.defaultView;
4975
- var setTransform = function setTransform(object, $el) {
4976
- $el.style.transform = _this.joinTransformMatrix(object.getWorldTransform());
3784
+ // const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
3785
+ var onPointerMove = function onPointerMove(ev) {
3786
+ renderingService.hooks.pointerMove.call(ev);
4977
3787
  };
4978
- var handleMounted = function handleMounted(e) {
4979
- var object = e.target;
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
- }
3788
+ var onPointerUp = function onPointerUp(ev) {
3789
+ renderingService.hooks.pointerUp.call(ev);
4998
3790
  };
4999
- var handleUnmounted = function handleUnmounted(e) {
5000
- var object = e.target;
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
- }
3791
+ var onPointerDown = function onPointerDown(ev) {
3792
+ renderingService.hooks.pointerDown.call(ev);
5013
3793
  };
5014
-
5015
- var handleAttributeChanged = function handleAttributeChanged(e) {
5016
- var object = e.target;
5017
- if (object.nodeName === gLite.Shape.HTML) {
5018
- var attrName = e.attrName;
5019
- _this.updateAttribute(attrName, object);
5020
- }
3794
+ var onPointerOver = function onPointerOver(ev) {
3795
+ renderingService.hooks.pointerOver.call(ev);
5021
3796
  };
5022
- var handleBoundsChanged = function handleBoundsChanged(e) {
5023
- var object = e.target;
5024
- if (object.nodeName === gLite.Shape.HTML) {
5025
- var $el = _this.getOrCreateEl(object);
5026
- setTransform(object, $el);
5027
- }
3797
+ var onPointerOut = function onPointerOut(ev) {
3798
+ renderingService.hooks.pointerOut.call(ev);
5028
3799
  };
5029
- var handleCanvasResize = function handleCanvasResize() {
5030
- if (_this.$camera) {
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
- }
3800
+ var onPointerCancel = function onPointerCancel(ev) {
3801
+ renderingService.hooks.pointerCancel.call(ev);
5037
3802
  };
5038
- renderingService.hooks.init.tapPromise(HTMLRenderingPlugin.tag, /*#__PURE__*/_asyncToGenerator$4( /*#__PURE__*/_regeneratorRuntime$4().mark(function _callee() {
5039
- return _regeneratorRuntime$4().wrap(function _callee$(_context) {
5040
- while (1) switch (_context.prev = _context.next) {
5041
- case 0:
5042
- canvas.addEventListener(gLite.CanvasEvent.RESIZE, handleCanvasResize);
5043
- canvas.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
5044
- canvas.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
5045
- canvas.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
5046
- canvas.addEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
5047
- case 5:
5048
- case "end":
5049
- return _context.stop();
5050
- }
5051
- }, _callee);
5052
- })));
5053
- renderingService.hooks.endFrame.tap(HTMLRenderingPlugin.tag, function () {
5054
- if (_this.$camera && renderingContext.renderReasons.has(gLite.RenderReason.CAMERA_CHANGED)) {
5055
- _this.$camera.style.transform = _this.joinTransformMatrix(camera.getOrthoMatrix());
3803
+ var onPointerWheel = function onPointerWheel(ev) {
3804
+ renderingService.hooks.pointerWheel.call(ev);
3805
+ };
3806
+ var onClick = function onClick(ev) {
3807
+ renderingService.hooks.click.call(ev);
3808
+ };
3809
+ var addPointerEventListener = function addPointerEventListener($el) {
3810
+ runtime.globalThis.document.addEventListener('pointermove', onPointerMove, true);
3811
+ $el.addEventListener('pointerdown', onPointerDown, true);
3812
+ $el.addEventListener('pointerleave', onPointerOut, true);
3813
+ $el.addEventListener('pointerover', onPointerOver, true);
3814
+ runtime.globalThis.addEventListener('pointerup', onPointerUp, true);
3815
+ runtime.globalThis.addEventListener('pointercancel', onPointerCancel, true);
3816
+ };
3817
+ var addTouchEventListener = function addTouchEventListener($el) {
3818
+ $el.addEventListener('touchstart', onPointerDown, true);
3819
+ $el.addEventListener('touchend', onPointerUp, true);
3820
+ $el.addEventListener('touchmove', onPointerMove, true);
3821
+ $el.addEventListener('touchcancel', onPointerCancel, true);
3822
+ };
3823
+ var addMouseEventListener = function addMouseEventListener($el) {
3824
+ runtime.globalThis.document.addEventListener('mousemove', onPointerMove, true);
3825
+ $el.addEventListener('mousedown', onPointerDown, true);
3826
+ $el.addEventListener('mouseout', onPointerOut, true);
3827
+ $el.addEventListener('mouseover', onPointerOver, true);
3828
+ runtime.globalThis.addEventListener('mouseup', onPointerUp, true);
3829
+ };
3830
+ var removePointerEventListener = function removePointerEventListener($el) {
3831
+ runtime.globalThis.document.removeEventListener('pointermove', onPointerMove, true);
3832
+ $el.removeEventListener('pointerdown', onPointerDown, true);
3833
+ $el.removeEventListener('pointerleave', onPointerOut, true);
3834
+ $el.removeEventListener('pointerover', onPointerOver, true);
3835
+ runtime.globalThis.removeEventListener('pointerup', onPointerUp, true);
3836
+ };
3837
+ var removeTouchEventListener = function removeTouchEventListener($el) {
3838
+ $el.removeEventListener('touchstart', onPointerDown, true);
3839
+ $el.removeEventListener('touchend', onPointerUp, true);
3840
+ $el.removeEventListener('touchmove', onPointerMove, true);
3841
+ $el.removeEventListener('touchcancel', onPointerCancel, true);
3842
+ };
3843
+ var removeMouseEventListener = function removeMouseEventListener($el) {
3844
+ runtime.globalThis.document.removeEventListener('mousemove', onPointerMove, true);
3845
+ $el.removeEventListener('mousedown', onPointerDown, true);
3846
+ $el.removeEventListener('mouseout', onPointerOut, true);
3847
+ $el.removeEventListener('mouseover', onPointerOver, true);
3848
+ runtime.globalThis.removeEventListener('mouseup', onPointerUp, true);
3849
+ };
3850
+ renderingService.hooks.init.tap(DOMInteractionPlugin.tag, function () {
3851
+ var $el = _this.context.contextService.getDomElement();
3852
+ // @ts-ignore
3853
+ if (runtime.globalThis.navigator.msPointerEnabled) {
3854
+ // @ts-ignore
3855
+ $el.style.msContentZooming = 'none';
3856
+ // @ts-ignore
3857
+ $el.style.msTouchAction = 'none';
3858
+ } else if (canvas.supportsPointerEvents) {
3859
+ $el.style.touchAction = 'none';
5056
3860
  }
5057
- });
5058
- renderingService.hooks.destroy.tap(HTMLRenderingPlugin.tag, function () {
5059
- // remove camera
5060
- if (_this.$camera) {
5061
- _this.$camera.remove();
3861
+ if (canvas.supportsPointerEvents) {
3862
+ addPointerEventListener($el);
3863
+ } else {
3864
+ addMouseEventListener($el);
5062
3865
  }
5063
- canvas.removeEventListener(gLite.CanvasEvent.RESIZE, handleCanvasResize);
5064
- canvas.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
5065
- canvas.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
5066
- canvas.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
5067
- canvas.removeEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
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);
3866
+ if (canvas.supportsTouchEvents) {
3867
+ addTouchEventListener($el);
3868
+ }
3869
+ if (config.useNativeClickEvent) {
3870
+ $el.addEventListener('click', onClick, true);
5100
3871
  }
5101
- return $existedCamera;
5102
- }
5103
- return null;
5104
- };
5105
- _proto.getOrCreateEl = function getOrCreateEl(object) {
5106
- var doc = this.context.config.document;
5107
- var existedId = this.getId(object);
5108
- var $existedElement = this.$camera.querySelector('#' + existedId);
5109
- if (!$existedElement) {
5110
- $existedElement = (doc || document).createElement('div');
5111
- object.parsedStyle.$el = $existedElement;
5112
- $existedElement.id = existedId;
5113
- if (object.name) {
5114
- $existedElement.setAttribute('name', object.name);
3872
+ // use passive event listeners
3873
+ // @see https://zhuanlan.zhihu.com/p/24555031
3874
+ $el.addEventListener('wheel', onPointerWheel, {
3875
+ passive: true,
3876
+ capture: true
3877
+ });
3878
+ });
3879
+ renderingService.hooks.destroy.tap(DOMInteractionPlugin.tag, function () {
3880
+ var $el = _this.context.contextService.getDomElement();
3881
+ // @ts-ignore
3882
+ if (runtime.globalThis.navigator.msPointerEnabled) {
3883
+ // @ts-ignore
3884
+ $el.style.msContentZooming = '';
3885
+ // @ts-ignore
3886
+ $el.style.msTouchAction = '';
3887
+ } else if (canvas.supportsPointerEvents) {
3888
+ $el.style.touchAction = '';
5115
3889
  }
5116
- if (object.className) {
5117
- $existedElement.className = object.className;
3890
+ if (canvas.supportsPointerEvents) {
3891
+ removePointerEventListener($el);
3892
+ } else {
3893
+ removeMouseEventListener($el);
5118
3894
  }
5119
- // use absolute position
5120
- $existedElement.style.position = 'absolute';
5121
- // @see https://github.com/antvis/G/issues/1150
5122
- $existedElement.style.left = "0px";
5123
- $existedElement.style.top = "0px";
5124
- $existedElement.style['will-change'] = 'transform';
5125
- $existedElement.style.transform = this.joinTransformMatrix(object.getWorldTransform());
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
- }
3895
+ if (canvas.supportsTouchEvents) {
3896
+ removeTouchEventListener($el);
3897
+ }
3898
+ if (config.useNativeClickEvent) {
3899
+ $el.removeEventListener('click', onClick, true);
3900
+ }
3901
+ $el.removeEventListener('wheel', onPointerWheel, true);
3902
+ });
5220
3903
  };
5221
- return HTMLRenderingPlugin;
3904
+ return DOMInteractionPlugin;
5222
3905
  }();
5223
- HTMLRenderingPlugin.tag = 'HTMLRendering';
5224
- var Plugin$4 = /*#__PURE__*/function (_AbstractRendererPlug) {
5225
- _inheritsLoose$5(Plugin, _AbstractRendererPlug);
3906
+ DOMInteractionPlugin.tag = 'DOMInteraction';
3907
+ var Plugin$3 = /*#__PURE__*/function (_AbstractRendererPlug) {
3908
+ _inheritsLoose$4(Plugin, _AbstractRendererPlug);
5226
3909
  function Plugin() {
5227
3910
  var _this;
5228
3911
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
5229
3912
  args[_key] = arguments[_key];
5230
3913
  }
5231
3914
  _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
5232
- _this.name = 'html-renderer';
3915
+ _this.name = 'dom-interaction';
5233
3916
  return _this;
5234
3917
  }
5235
3918
  var _proto = Plugin.prototype;
5236
3919
  _proto.init = function init() {
5237
- this.addRenderingPlugin(new HTMLRenderingPlugin());
3920
+ this.addRenderingPlugin(new DOMInteractionPlugin());
5238
3921
  };
5239
3922
  _proto.destroy = function destroy() {
5240
3923
  this.removeAllRenderingPlugins();
@@ -5242,342 +3925,311 @@
5242
3925
  return Plugin;
5243
3926
  }(gLite.AbstractRendererPlugin);
5244
3927
 
5245
- var index_esm$4 = /*#__PURE__*/Object.freeze({
5246
- __proto__: null,
5247
- Plugin: Plugin$4
5248
- });
5249
-
5250
- function _regeneratorRuntime$5() {
5251
- _regeneratorRuntime$5 = function _regeneratorRuntime() {
5252
- return exports;
5253
- };
5254
- var exports = {},
5255
- Op = Object.prototype,
5256
- hasOwn = Op.hasOwnProperty,
5257
- defineProperty = Object.defineProperty || function (obj, key, desc) {
5258
- obj[key] = desc.value;
5259
- },
5260
- $Symbol = "function" == typeof Symbol ? Symbol : {},
5261
- iteratorSymbol = $Symbol.iterator || "@@iterator",
5262
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
5263
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
5264
- function define(obj, key, value) {
5265
- return Object.defineProperty(obj, key, {
5266
- value: value,
5267
- enumerable: !0,
5268
- configurable: !0,
5269
- writable: !0
5270
- }), obj[key];
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
- });
3928
+ var index_esm$3 = /*#__PURE__*/Object.freeze({
3929
+ __proto__: null,
3930
+ Plugin: Plugin$3
3931
+ });
3932
+
3933
+ function _inheritsLoose$5(subClass, superClass) {
3934
+ subClass.prototype = Object.create(superClass.prototype);
3935
+ subClass.prototype.constructor = subClass;
3936
+ _setPrototypeOf$5(subClass, superClass);
3937
+ }
3938
+ function _setPrototypeOf$5(o, p) {
3939
+ _setPrototypeOf$5 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
3940
+ o.__proto__ = p;
3941
+ return o;
3942
+ };
3943
+ return _setPrototypeOf$5(o, p);
3944
+ }
3945
+ var HTML_PREFIX = 'g-html-';
3946
+ var CANVAS_CAMERA_ID = 'g-canvas-camera';
3947
+ var HTMLRenderingPlugin = /*#__PURE__*/function () {
3948
+ function HTMLRenderingPlugin() {
3949
+ this.context = void 0;
3950
+ /**
3951
+ * wrapper for camera
3952
+ */
3953
+ this.$camera = void 0;
5349
3954
  }
5350
- function makeInvokeMethod(innerFn, self, context) {
5351
- var state = "suspendedStart";
5352
- return function (method, arg) {
5353
- if ("executing" === state) throw new Error("Generator is already running");
5354
- if ("completed" === state) {
5355
- if ("throw" === method) throw arg;
5356
- return doneResult();
5357
- }
5358
- for (context.method = method, context.arg = arg;;) {
5359
- var delegate = context.delegate;
5360
- if (delegate) {
5361
- var delegateResult = maybeInvokeDelegate(delegate, context);
5362
- if (delegateResult) {
5363
- if (delegateResult === ContinueSentinel) continue;
5364
- return delegateResult;
5365
- }
5366
- }
5367
- if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
5368
- if ("suspendedStart" === state) throw state = "completed", context.arg;
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
- };
3955
+ var _proto = HTMLRenderingPlugin.prototype;
3956
+ _proto.joinTransformMatrix = function joinTransformMatrix(matrix) {
3957
+ return "matrix(" + [matrix[0], matrix[1], matrix[4], matrix[5], matrix[12], matrix[13]].join(',') + ")";
3958
+ };
3959
+ _proto.apply = function apply(context) {
3960
+ var _this = this;
3961
+ var camera = context.camera,
3962
+ renderingContext = context.renderingContext,
3963
+ renderingService = context.renderingService;
3964
+ this.context = context;
3965
+ var canvas = renderingContext.root.ownerDocument.defaultView;
3966
+ var setTransform = function setTransform(object, $el) {
3967
+ $el.style.transform = _this.joinTransformMatrix(object.getWorldTransform());
3968
+ };
3969
+ var handleMounted = function handleMounted(e) {
3970
+ var object = e.target;
3971
+ if (object.nodeName === gLite.Shape.HTML) {
3972
+ if (!_this.$camera) {
3973
+ _this.$camera = _this.createCamera(camera);
5379
3974
  }
5380
- "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
3975
+ // create DOM element
3976
+ var $el = _this.getOrCreateEl(object);
3977
+ _this.$camera.appendChild($el);
3978
+ // apply documentElement's style
3979
+ var attributes = object.ownerDocument.documentElement.attributes;
3980
+ Object.keys(attributes).forEach(function (name) {
3981
+ $el.style[name] = attributes[name];
3982
+ });
3983
+ Object.keys(object.attributes).forEach(function (name) {
3984
+ _this.updateAttribute(name, object);
3985
+ });
3986
+ setTransform(object, $el);
3987
+ gLite.runtime.nativeHTMLMap.set($el, object);
5381
3988
  }
5382
3989
  };
5383
- }
5384
- function maybeInvokeDelegate(delegate, context) {
5385
- var methodName = context.method,
5386
- method = delegate.iterator[methodName];
5387
- 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;
5388
- var record = tryCatch(method, delegate.iterator, context.arg);
5389
- if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
5390
- var info = record.arg;
5391
- 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);
5392
- }
5393
- function pushTryEntry(locs) {
5394
- var entry = {
5395
- tryLoc: locs[0]
3990
+ var handleUnmounted = function handleUnmounted(e) {
3991
+ var object = e.target;
3992
+ if (object.nodeName === gLite.Shape.HTML && _this.$camera) {
3993
+ var $el = _this.getOrCreateEl(object);
3994
+ if ($el) {
3995
+ $el.remove();
3996
+ gLite.runtime.nativeHTMLMap.delete($el);
3997
+ }
3998
+ // const existedId = this.getId(object);
3999
+ // const $existedElement: HTMLElement | null = this.$camera.querySelector('#' + existedId);
4000
+ // if ($existedElement) {
4001
+ // this.$camera.removeChild($existedElement);
4002
+ // }
4003
+ }
5396
4004
  };
5397
- 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
5398
- }
5399
- function resetTryEntry(entry) {
5400
- var record = entry.completion || {};
5401
- record.type = "normal", delete record.arg, entry.completion = record;
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;
4005
+
4006
+ var handleAttributeChanged = function handleAttributeChanged(e) {
4007
+ var object = e.target;
4008
+ if (object.nodeName === gLite.Shape.HTML) {
4009
+ var attrName = e.attrName;
4010
+ _this.updateAttribute(attrName, object);
5420
4011
  }
5421
- }
5422
- return {
5423
- next: doneResult
5424
4012
  };
5425
- }
5426
- function doneResult() {
5427
- return {
5428
- value: undefined,
5429
- done: !0
4013
+ var handleBoundsChanged = function handleBoundsChanged(e) {
4014
+ var object = e.target;
4015
+ if (object.nodeName === gLite.Shape.HTML) {
4016
+ var $el = _this.getOrCreateEl(object);
4017
+ setTransform(object, $el);
4018
+ }
5430
4019
  };
5431
- }
5432
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
5433
- value: GeneratorFunctionPrototype,
5434
- configurable: !0
5435
- }), defineProperty(GeneratorFunctionPrototype, "constructor", {
5436
- value: GeneratorFunction,
5437
- configurable: !0
5438
- }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
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
4020
+ var handleCanvasResize = function handleCanvasResize() {
4021
+ if (_this.$camera) {
4022
+ var _this$context$config = _this.context.config,
4023
+ width = _this$context$config.width,
4024
+ height = _this$context$config.height;
4025
+ _this.$camera.style.width = (width || 0) + "px";
4026
+ _this.$camera.style.height = (height || 0) + "px";
4027
+ }
5446
4028
  };
5447
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
5448
- return this;
5449
- }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
5450
- void 0 === PromiseImpl && (PromiseImpl = Promise);
5451
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
5452
- return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
5453
- return result.done ? result.value : iter.next();
4029
+ renderingService.hooks.init.tap(HTMLRenderingPlugin.tag, function () {
4030
+ canvas.addEventListener(gLite.CanvasEvent.RESIZE, handleCanvasResize);
4031
+ canvas.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
4032
+ canvas.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
4033
+ canvas.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
4034
+ canvas.addEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
5454
4035
  });
5455
- }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
5456
- return this;
5457
- }), define(Gp, "toString", function () {
5458
- return "[object Generator]";
5459
- }), exports.keys = function (val) {
5460
- var object = Object(val),
5461
- keys = [];
5462
- for (var key in object) keys.push(key);
5463
- return keys.reverse(), function next() {
5464
- for (; keys.length;) {
5465
- var key = keys.pop();
5466
- if (key in object) return next.value = key, next.done = !1, next;
4036
+ renderingService.hooks.endFrame.tap(HTMLRenderingPlugin.tag, function () {
4037
+ if (_this.$camera && renderingContext.renderReasons.has(gLite.RenderReason.CAMERA_CHANGED)) {
4038
+ _this.$camera.style.transform = _this.joinTransformMatrix(camera.getOrthoMatrix());
4039
+ }
4040
+ });
4041
+ renderingService.hooks.destroy.tap(HTMLRenderingPlugin.tag, function () {
4042
+ // remove camera
4043
+ if (_this.$camera) {
4044
+ _this.$camera.remove();
4045
+ }
4046
+ canvas.removeEventListener(gLite.CanvasEvent.RESIZE, handleCanvasResize);
4047
+ canvas.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
4048
+ canvas.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
4049
+ canvas.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
4050
+ canvas.removeEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
4051
+ });
4052
+ };
4053
+ _proto.getId = function getId(object) {
4054
+ return object.id || HTML_PREFIX + object.entity;
4055
+ };
4056
+ _proto.createCamera = function createCamera(camera) {
4057
+ var _this$context$config2 = this.context.config,
4058
+ doc = _this$context$config2.document,
4059
+ width = _this$context$config2.width,
4060
+ height = _this$context$config2.height;
4061
+ var $canvas = this.context.contextService.getDomElement();
4062
+ var $container = $canvas.parentNode;
4063
+ if ($container) {
4064
+ var cameraId = CANVAS_CAMERA_ID;
4065
+ var $existedCamera = $container.querySelector('#' + cameraId);
4066
+ if (!$existedCamera) {
4067
+ var $camera = (doc || document).createElement('div');
4068
+ $existedCamera = $camera;
4069
+ $camera.id = cameraId;
4070
+ // use absolute position
4071
+ $camera.style.position = 'absolute';
4072
+ // account for DOM element's offset @see https://github.com/antvis/G/issues/1150
4073
+ $camera.style.left = ($canvas.offsetLeft || 0) + "px";
4074
+ $camera.style.top = ($canvas.offsetTop || 0) + "px";
4075
+ $camera.style.transformOrigin = 'left top';
4076
+ $camera.style.transform = this.joinTransformMatrix(camera.getOrthoMatrix());
4077
+ // HTML elements should not overflow with canvas @see https://github.com/antvis/G/issues/1163
4078
+ $camera.style.overflow = 'hidden';
4079
+ $camera.style.pointerEvents = 'none';
4080
+ $camera.style.width = (width || 0) + "px";
4081
+ $camera.style.height = (height || 0) + "px";
4082
+ $container.appendChild($camera);
4083
+ }
4084
+ return $existedCamera;
4085
+ }
4086
+ return null;
4087
+ };
4088
+ _proto.getOrCreateEl = function getOrCreateEl(object) {
4089
+ var doc = this.context.config.document;
4090
+ var existedId = this.getId(object);
4091
+ var $existedElement = this.$camera.querySelector('#' + existedId);
4092
+ if (!$existedElement) {
4093
+ $existedElement = (doc || document).createElement('div');
4094
+ object.parsedStyle.$el = $existedElement;
4095
+ $existedElement.id = existedId;
4096
+ if (object.name) {
4097
+ $existedElement.setAttribute('name', object.name);
5467
4098
  }
5468
- return next.done = !0, next;
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;
4099
+ if (object.className) {
4100
+ $existedElement.className = object.className;
5486
4101
  }
5487
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
5488
- var entry = this.tryEntries[i],
5489
- record = entry.completion;
5490
- if ("root" === entry.tryLoc) return handle("end");
5491
- if (entry.tryLoc <= this.prev) {
5492
- var hasCatch = hasOwn.call(entry, "catchLoc"),
5493
- hasFinally = hasOwn.call(entry, "finallyLoc");
5494
- if (hasCatch && hasFinally) {
5495
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
5496
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
5497
- } else if (hasCatch) {
5498
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
5499
- } else {
5500
- if (!hasFinally) throw new Error("try statement without catch or finally");
5501
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
5502
- }
4102
+ // use absolute position
4103
+ $existedElement.style.position = 'absolute';
4104
+ // @see https://github.com/antvis/G/issues/1150
4105
+ $existedElement.style.left = "0px";
4106
+ $existedElement.style.top = "0px";
4107
+ $existedElement.style['will-change'] = 'transform';
4108
+ $existedElement.style.transform = this.joinTransformMatrix(object.getWorldTransform());
4109
+ }
4110
+ return $existedElement;
4111
+ };
4112
+ _proto.updateAttribute = function updateAttribute(name, object) {
4113
+ var $el = this.getOrCreateEl(object);
4114
+ switch (name) {
4115
+ case 'innerHTML':
4116
+ var innerHTML = object.parsedStyle.innerHTML;
4117
+ if (isString(innerHTML)) {
4118
+ $el.innerHTML = innerHTML;
4119
+ } else {
4120
+ $el.innerHTML = '';
4121
+ $el.appendChild(innerHTML);
5503
4122
  }
5504
- }
5505
- },
5506
- abrupt: function abrupt(type, arg) {
5507
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
5508
- var entry = this.tryEntries[i];
5509
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
5510
- var finallyEntry = entry;
5511
- break;
4123
+ break;
4124
+ case 'transformOrigin':
4125
+ var transformOrigin = object.parsedStyle.transformOrigin;
4126
+ $el.style['transform-origin'] = transformOrigin[0].value + " " + transformOrigin[1].value;
4127
+ break;
4128
+ case 'width':
4129
+ if (gLite.runtime.enableCSSParsing) {
4130
+ var width = object.computedStyleMap().get('width');
4131
+ $el.style.width = width.toString();
4132
+ } else {
4133
+ var _width = object.parsedStyle.width;
4134
+ $el.style.width = isNumber(_width) ? _width + "px" : _width.toString();
5512
4135
  }
5513
- }
5514
- finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
5515
- var record = finallyEntry ? finallyEntry.completion : {};
5516
- return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
5517
- },
5518
- complete: function complete(record, afterLoc) {
5519
- if ("throw" === record.type) throw record.arg;
5520
- 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;
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;
4136
+ break;
4137
+ case 'height':
4138
+ if (gLite.runtime.enableCSSParsing) {
4139
+ var height = object.computedStyleMap().get('height');
4140
+ $el.style.height = height.toString();
4141
+ } else {
4142
+ var _height = object.parsedStyle.height;
4143
+ $el.style.height = isNumber(_height) ? _height + "px" : _height.toString();
5538
4144
  }
5539
- }
5540
- throw new Error("illegal catch attempt");
5541
- },
5542
- delegateYield: function delegateYield(iterable, resultName, nextLoc) {
5543
- return this.delegate = {
5544
- iterator: values(iterable),
5545
- resultName: resultName,
5546
- nextLoc: nextLoc
5547
- }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
4145
+ break;
4146
+ case 'zIndex':
4147
+ var zIndex = object.parsedStyle.zIndex;
4148
+ $el.style['z-index'] = "" + zIndex;
4149
+ break;
4150
+ case 'visibility':
4151
+ var visibility = object.parsedStyle.visibility;
4152
+ $el.style.visibility = visibility;
4153
+ break;
4154
+ case 'pointerEvents':
4155
+ var pointerEvents = object.parsedStyle.pointerEvents;
4156
+ $el.style.pointerEvents = pointerEvents;
4157
+ break;
4158
+ case 'opacity':
4159
+ var opacity = object.parsedStyle.opacity;
4160
+ $el.style.opacity = "" + opacity;
4161
+ break;
4162
+ case 'fill':
4163
+ var fill = object.parsedStyle.fill;
4164
+ var color = '';
4165
+ if (gLite.isCSSRGB(fill)) {
4166
+ if (fill.isNone) {
4167
+ color = 'transparent';
4168
+ } else {
4169
+ color = object.getAttribute('fill');
4170
+ }
4171
+ } else if (Array.isArray(fill)) {
4172
+ color = object.getAttribute('fill');
4173
+ } else if (gLite.isPattern(fill)) ;
4174
+ $el.style.background = color;
4175
+ break;
4176
+ case 'stroke':
4177
+ var stroke = object.parsedStyle.stroke;
4178
+ var borderColor = '';
4179
+ if (gLite.isCSSRGB(stroke)) {
4180
+ if (stroke.isNone) {
4181
+ borderColor = 'transparent';
4182
+ } else {
4183
+ borderColor = object.getAttribute('stroke');
4184
+ }
4185
+ } else if (Array.isArray(stroke)) {
4186
+ borderColor = object.getAttribute('stroke');
4187
+ } else if (gLite.isPattern(stroke)) ;
4188
+ $el.style['border-color'] = borderColor;
4189
+ $el.style['border-style'] = 'solid';
4190
+ break;
4191
+ case 'lineWidth':
4192
+ var lineWidth = object.parsedStyle.lineWidth;
4193
+ $el.style['border-width'] = (lineWidth || 0) + "px";
4194
+ break;
4195
+ case 'lineDash':
4196
+ $el.style['border-style'] = 'dashed';
4197
+ break;
4198
+ case 'filter':
4199
+ var filter = object.style.filter;
4200
+ $el.style.filter = filter;
4201
+ break;
5548
4202
  }
5549
- }, exports;
5550
- }
5551
- function asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, key, arg) {
5552
- try {
5553
- var info = gen[key](arg);
5554
- var value = info.value;
5555
- } catch (error) {
5556
- reject(error);
5557
- return;
5558
- }
5559
- if (info.done) {
5560
- resolve(value);
5561
- } else {
5562
- Promise.resolve(value).then(_next, _throw);
4203
+ };
4204
+ return HTMLRenderingPlugin;
4205
+ }();
4206
+ HTMLRenderingPlugin.tag = 'HTMLRendering';
4207
+ var Plugin$4 = /*#__PURE__*/function (_AbstractRendererPlug) {
4208
+ _inheritsLoose$5(Plugin, _AbstractRendererPlug);
4209
+ function Plugin() {
4210
+ var _this;
4211
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
4212
+ args[_key] = arguments[_key];
4213
+ }
4214
+ _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
4215
+ _this.name = 'html-renderer';
4216
+ return _this;
5563
4217
  }
5564
- }
5565
- function _asyncToGenerator$5(fn) {
5566
- return function () {
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
- });
4218
+ var _proto = Plugin.prototype;
4219
+ _proto.init = function init() {
4220
+ this.addRenderingPlugin(new HTMLRenderingPlugin());
5579
4221
  };
5580
- }
4222
+ _proto.destroy = function destroy() {
4223
+ this.removeAllRenderingPlugins();
4224
+ };
4225
+ return Plugin;
4226
+ }(gLite.AbstractRendererPlugin);
4227
+
4228
+ var index_esm$4 = /*#__PURE__*/Object.freeze({
4229
+ __proto__: null,
4230
+ Plugin: Plugin$4
4231
+ });
4232
+
5581
4233
  function _inheritsLoose$6(subClass, superClass) {
5582
4234
  subClass.prototype = Object.create(superClass.prototype);
5583
4235
  subClass.prototype.constructor = subClass;
@@ -5901,18 +4553,10 @@
5901
4553
  }
5902
4554
  }
5903
4555
  };
5904
- renderingService.hooks.init.tapPromise(LoadImagePlugin.tag, /*#__PURE__*/_asyncToGenerator$5( /*#__PURE__*/_regeneratorRuntime$5().mark(function _callee() {
5905
- return _regeneratorRuntime$5().wrap(function _callee$(_context) {
5906
- while (1) switch (_context.prev = _context.next) {
5907
- case 0:
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
- })));
4556
+ renderingService.hooks.init.tap(LoadImagePlugin.tag, function () {
4557
+ canvas.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
4558
+ canvas.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
4559
+ });
5916
4560
  renderingService.hooks.destroy.tap(LoadImagePlugin.tag, function () {
5917
4561
  canvas.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
5918
4562
  canvas.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
@@ -5962,46 +4606,33 @@
5962
4606
  this.canvasConfig = context.config;
5963
4607
  }
5964
4608
  var _proto = Canvas2DContextService.prototype;
5965
- _proto.init = /*#__PURE__*/function () {
5966
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
5967
- var _this$canvasConfig, container, canvas, $canvas;
5968
- return _regeneratorRuntime().wrap(function _callee$(_context) {
5969
- while (1) switch (_context.prev = _context.next) {
5970
- case 0:
5971
- _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas;
5972
- if (canvas) {
5973
- this.$canvas = canvas;
5974
- if (container && canvas.parentElement !== container) {
5975
- container.appendChild(canvas);
5976
- }
5977
- this.$container = canvas.parentElement;
5978
- this.canvasConfig.container = this.$container;
5979
- } else if (container) {
5980
- // create container
5981
- this.$container = isString(container) ? document.getElementById(container) : container;
5982
- if (this.$container) {
5983
- // create canvas
5984
- $canvas = document.createElement('canvas');
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();
4609
+ _proto.init = function init() {
4610
+ var _this$canvasConfig = this.canvasConfig,
4611
+ container = _this$canvasConfig.container,
4612
+ canvas = _this$canvasConfig.canvas;
4613
+ if (canvas) {
4614
+ this.$canvas = canvas;
4615
+ if (container && canvas.parentElement !== container) {
4616
+ container.appendChild(canvas);
4617
+ }
4618
+ this.$container = canvas.parentElement;
4619
+ this.canvasConfig.container = this.$container;
4620
+ } else if (container) {
4621
+ // create container
4622
+ this.$container = isString(container) ? document.getElementById(container) : container;
4623
+ if (this.$container) {
4624
+ // create canvas
4625
+ var $canvas = document.createElement('canvas');
4626
+ this.$container.appendChild($canvas);
4627
+ if (!this.$container.style.position) {
4628
+ this.$container.style.position = 'relative';
5997
4629
  }
5998
- }, _callee, this);
5999
- }));
6000
- function init() {
6001
- return _init.apply(this, arguments);
4630
+ this.$canvas = $canvas;
4631
+ }
6002
4632
  }
6003
- return init;
6004
- }();
4633
+ this.context = this.$canvas.getContext('2d');
4634
+ this.resize(this.canvasConfig.width, this.canvasConfig.height);
4635
+ };
6005
4636
  _proto.getContext = function getContext() {
6006
4637
  return this.context;
6007
4638
  };
@@ -6050,21 +4681,21 @@
6050
4681
  }
6051
4682
  };
6052
4683
  _proto.toDataURL = /*#__PURE__*/function () {
6053
- var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
4684
+ var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
6054
4685
  var _options, type, encoderOptions;
6055
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
6056
- while (1) switch (_context2.prev = _context2.next) {
4686
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
4687
+ while (1) switch (_context.prev = _context.next) {
6057
4688
  case 0:
6058
4689
  if (options === void 0) {
6059
4690
  options = {};
6060
4691
  }
6061
4692
  _options = options, type = _options.type, encoderOptions = _options.encoderOptions;
6062
- return _context2.abrupt("return", this.context.canvas.toDataURL(type, encoderOptions));
4693
+ return _context.abrupt("return", this.context.canvas.toDataURL(type, encoderOptions));
6063
4694
  case 3:
6064
4695
  case "end":
6065
- return _context2.stop();
4696
+ return _context.stop();
6066
4697
  }
6067
- }, _callee2, this);
4698
+ }, _callee, this);
6068
4699
  }));
6069
4700
  function toDataURL(_x) {
6070
4701
  return _toDataURL.apply(this, arguments);