@antv/g-plugin-canvas-renderer
Advanced tools
Comparing version 1.6.1 to 1.6.2
@@ -1387,4 +1387,21 @@ import { Syringe, isString, inject, singleton, isNil, UnitType, Shape, isPattern, GradientType, CanvasConfig, DefaultCamera, Camera, ContextService, RenderingContext, DisplayObjectPool, RBushRoot, RBush, RenderingPluginContribution, ElementEvent, AABB, CustomEvent, CanvasEvent, Module, AbstractRendererPlugin } from '@antv/g'; | ||
} | ||
}); // render at the end of frame | ||
}); | ||
var renderByZIndex = function renderByZIndex(object) { | ||
if (object.isVisible() && !object.isCulled()) { | ||
_this.renderDisplayObject(object, renderingService); // if we did a full screen rendering last frame | ||
_this.saveDirtyAABB(object); | ||
} // should account for z-index | ||
if (object.sortable.sorted && object.sortable.sorted.length) { | ||
object.sortable.sorted.forEach(function (child) { | ||
renderByZIndex(child); | ||
}); | ||
} | ||
}; // render at the end of frame | ||
renderingService.hooks.endFrame.tap(CanvasRendererPlugin_1.tag, function () { | ||
@@ -1397,10 +1414,3 @@ var context = _this.contextService.getContext(); // clear & clip dirty rectangle | ||
if (_this.clearFullScreen) { | ||
_this.renderingContext.root.forEach(function (object) { | ||
if (object.isVisible() && !object.isCulled()) { | ||
_this.renderDisplayObject(object, renderingService); // if we did a full screen rendering last frame | ||
_this.saveDirtyAABB(object); | ||
} | ||
}); | ||
renderByZIndex(_this.renderingContext.root); | ||
} else { | ||
@@ -1407,0 +1417,0 @@ // merge removed AABB |
@@ -1391,4 +1391,21 @@ 'use strict'; | ||
} | ||
}); // render at the end of frame | ||
}); | ||
var renderByZIndex = function renderByZIndex(object) { | ||
if (object.isVisible() && !object.isCulled()) { | ||
_this.renderDisplayObject(object, renderingService); // if we did a full screen rendering last frame | ||
_this.saveDirtyAABB(object); | ||
} // should account for z-index | ||
if (object.sortable.sorted && object.sortable.sorted.length) { | ||
object.sortable.sorted.forEach(function (child) { | ||
renderByZIndex(child); | ||
}); | ||
} | ||
}; // render at the end of frame | ||
renderingService.hooks.endFrame.tap(CanvasRendererPlugin_1.tag, function () { | ||
@@ -1401,10 +1418,3 @@ var context = _this.contextService.getContext(); // clear & clip dirty rectangle | ||
if (_this.clearFullScreen) { | ||
_this.renderingContext.root.forEach(function (object) { | ||
if (object.isVisible() && !object.isCulled()) { | ||
_this.renderDisplayObject(object, renderingService); // if we did a full screen rendering last frame | ||
_this.saveDirtyAABB(object); | ||
} | ||
}); | ||
renderByZIndex(_this.renderingContext.root); | ||
} else { | ||
@@ -1411,0 +1421,0 @@ // merge removed AABB |
@@ -5,2 +5,2 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@antv/g")):"function"==typeof define&&define.amd?define(["exports","@antv/g"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).G=e.G||{},e.G.CanvasRenderer={}),e.window.G)}(this,(function(e,t){"use strict";function r(){ | ||
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ | ||
F=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",o=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function s(e,t,r,n){var i=Object.create((t&&t.prototype instanceof h?t:h).prototype),o=new E(n||[]);return i._invoke=function(e,t,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return P()}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var c=x(a,r);if(c){if(c===u)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var s=l(e,t,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===u)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.arg)}}}(e,r,o),i}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=s;var u={};function h(){}function d(){}function f(){}var p={};c(p,i,(function(){return this}));var v=Object.getPrototypeOf,y=v&&v(v(C([])));y&&y!==t&&r.call(y,i)&&(p=y);var g=f.prototype=h.prototype=Object.create(p);function m(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function w(e,t){function n(i,o,a,c){var s=l(e[i],e,o);if("throw"!==s.type){var u=s.arg,h=u.value;return h&&"object"==typeof h&&r.call(h,"__await")?t.resolve(h.__await).then((function(e){n("next",e,a,c)}),(function(e){n("throw",e,a,c)})):t.resolve(h).then((function(e){u.value=e,a(u)}),(function(e){return n("throw",e,a,c)}))}c(s.arg)}var i;this._invoke=function(e,r){function o(){return new t((function(t,i){n(e,r,t,i)}))}return i=i?i.then(o,o):o()}}function x(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,x(e,t),"throw"===t.method))return u;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return u}var n=l(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,u;var i=n.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,u):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,u)}function b(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function R(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(b,this),this.reset(!0)}function C(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,o=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return o.next=o}}return{next:P}}function P(){return{value:void 0,done:!0}}return d.prototype=f,c(g,"constructor",f),c(f,"constructor",d),d.displayName=c(f,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,f):(e.__proto__=f,c(e,a,"GeneratorFunction")),e.prototype=Object.create(g),e},e.awrap=function(e){return{__await:e}},m(w.prototype),c(w.prototype,o,(function(){return this})),e.AsyncIterator=w,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var a=new w(s(t,r,n,i),o);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},m(g),c(g,a,"Generator"),c(g,i,(function(){return this})),c(g,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=C,E.prototype={constructor:E,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(R),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return a.type="throw",a.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return n("end");if(this.prev>=o.tryLoc){var c=r.call(o,"catchLoc"),s=r.call(o,"finallyLoc");if(c&&s){if(o.catchLoc>this.prev)return n(o.catchLoc,!0);if(o.finallyLoc>this.prev)return n(o.finallyLoc)}else if(c){if(o.catchLoc>this.prev)return n(o.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(o.finallyLoc>this.prev)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(this.prev>=i.tryLoc&&r.call(i,"finallyLoc")&&i.finallyLoc>this.prev){var o=i;break}}o&&("break"===e||"continue"===e)&&t>=o.tryLoc&&o.finallyLoc>=t&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,u):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),u},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),R(r),u}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;R(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:C(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),u}},e}function _(e,t,r,n,i,o,a){try{var c=e[o](a),s=c.value}catch(e){return void r(e)}c.done?t(s):Promise.resolve(s).then(n,i)}function D(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){_(o,n,i,a,c,"next",e)}function c(e){_(o,n,i,a,c,"throw",e)}a(void 0)}))}}var V,Y,X=function(){function e(){this.imageCache={},this.gradientCache={},this.patternCache={},this.canvasConfig=void 0}var r=e.prototype;return r.getImageSync=function(e,t){return this.imageCache[e]||this.getOrCreateImage(e).then((function(){t&&t()})),this.imageCache[e]},r.getOrCreateImage=function(e){var r=this;if(this.imageCache[e])return Promise.resolve(this.imageCache[e]);var n=this.canvasConfig.createImage;return new Promise((function(i,o){var a;n?a=n(e):t.isBrowser&&(a=new window.Image),a&&(a.onload=function(){i(a)},a.onerror=function(e){o(e)},a.crossOrigin="Anonymous",a.src=e,r.imageCache[e]=a)}))},r.getOrCreatePatternSync=function(e,r,n){var i=this.generatePatternKey(e);if(i&&this.patternCache[i])return this.patternCache[i];var o,a=e.image,c=e.repetition,s=(o=t.isString(a)?this.getImageSync(a,n):a)&&r.createPattern(o,c);return i&&s&&(this.patternCache[i]=s),s},r.getOrCreateGradient=function(e,r){var n=this.generateGradientKey(e),i=e.type,o=e.steps,a=e.width,c=e.height,s=e.cx,l=e.cy;if(this.gradientCache[n])return this.gradientCache[n];var u=null;if(i===t.GradientType.LinearGradient){var h=t.computeLinearGradient(a,c,e.angle);u=r.createLinearGradient(h.x1,h.y1,h.x2,h.y2)}else if(i===t.GradientType.RadialGradient){var d=t.computeRadialGradient(a,c,s,l),f=d.x,p=d.y;u=r.createRadialGradient(f,p,0,f,p,d.r)}return u&&(o.forEach((function(e){var t;null===(t=u)||void 0===t||t.addColorStop(e[0],e[1])})),this.gradientCache[n]=u),this.gradientCache[n]},r.generateGradientKey=function(e){return"gradient-"+e.type+"-"+(e.angle||0)+"-"+(e.cx||0)+"-"+(e.cy||0)+"-"+e.width+"-"+e.height+"-"+e.steps.map((function(e){return e.join("")})).join("-")},r.generatePatternKey=function(e){var r=e.image,n=e.repetition;if(t.isString(r))return"pattern-"+r+"-"+n},e}();s([t.inject(t.CanvasConfig),l("design:type",Object)],X.prototype,"canvasConfig",void 0),X=s([t.singleton()],X);var U=(V=function(){function e(){this.imagePool=void 0,this.renderingContext=void 0}return e.prototype.apply=function(e){var r=this,n=function(n){var i=n.target;if(i.nodeName===t.Shape.IMAGE){var o=i.attributes.img;t.isString(o)&&r.imagePool.getImageSync(o,(function(){i.renderable.dirty=!0,e.dirtify()}))}},i=function(n){var i=n.target,o=n.newValue;i.nodeName===t.Shape.IMAGE&&"img"===n.attrName&&t.isString(o)&&r.imagePool.getOrCreateImage(o).then((function(){i.renderable.dirty=!0,e.dirtify()}))};e.hooks.init.tapPromise(Y.tag,D(F().mark((function e(){return F().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r.renderingContext.root.addEventListener(t.ElementEvent.MOUNTED,n),r.renderingContext.root.addEventListener(t.ElementEvent.ATTR_MODIFIED,i);case 2:case"end":return e.stop()}}),e)})))),e.hooks.destroy.tap(Y.tag,(function(){r.renderingContext.root.removeEventListener(t.ElementEvent.MOUNTED,n),r.renderingContext.root.removeEventListener(t.ElementEvent.ATTR_MODIFIED,i)}))},e}(),V.tag="LoadImage",Y=V);s([t.inject(X),l("design:type",X)],U.prototype,"imagePool",void 0),s([t.inject(t.RenderingContext),l("design:type",Object)],U.prototype,"renderingContext",void 0),U=Y=s([t.singleton({contrib:t.RenderingPluginContribution})],U);t.Module((function(e){e(X),e(U)}));e.ImageRenderer=function(){function e(){this.imagePool=void 0}return e.prototype.render=function(e,r){var n,i=r.img,o=r.width.value,a=r.height.value;if(t.isString(i)?n=this.imagePool.getImageSync(i):(o||(o=i.width),a||(a=i.height),n=i),n)try{e.drawImage(n,0,0,o,a)}catch(e){}},e}(),s([t.inject(X),l("design:type",X)],e.ImageRenderer.prototype,"imagePool",void 0),e.ImageRenderer=s([t.singleton({token:G})],e.ImageRenderer),e.TextRenderer=function(){function e(){}var r=e.prototype;return r.render=function(e,r,n){var i=r.lineWidth,o=r.textAlign,a=r.textBaseline,c=r.lineJoin,s=r.miterLimit,l=r.letterSpacing,u=r.stroke,h=r.fill,d=r.fillOpacity,f=r.strokeOpacity,p=r.opacity,v=r.metrics,y=r.dx,g=r.dy,m=v.lines,w=v.height,x=v.lineHeight,b=v.lineMetrics;e.font=v.font,e.lineWidth=i.value,e.textAlign=o.value,e.textBaseline=a.value,e.lineJoin=c.value,t.isNil(s)||(e.miterLimit=s.value);var R=0;"middle"===a.value?R=-w/2-x/2:"bottom"===a.value||"alphabetic"===a.value||"ideographic"===a.value?R=-w:"top"!==a.value&&"hanging"!==a.value||(R=-x);var E=0;y&&y.unit===t.UnitType.kPixels&&(E+=y.value),g&&g.unit===t.UnitType.kPixels&&(R+=g.value);for(var C=0;m.length>C;C++){var P=i.value/2+E;R+=x,!t.isNil(u)&&!u.isNone&&i&&i.value&&this.drawLetterSpacing(e,m[C],b[C],o.value,P,R,l.value,d.value,f.value,p.value,!0),t.isNil(h)||this.drawLetterSpacing(e,m[C],b[C],o.value,P,R,l.value,d.value,f.value,p.value)}},r.drawLetterSpacing=function(e,t,r,n,i,o,a,c,s,l,u){if(void 0===u&&(u=!1),0!==a){var h=e.textAlign;e.textAlign="left";var d=i;"center"===n?d=i-r.width/2:"right"!==n&&"end"!==n||(d=i-r.width);for(var f=Array.from(t),p=e.measureText(t).width,v=0,y=0;f.length>y;++y){var g=f[y];u?this.strokeText(e,g,d,o,s):this.fillText(e,g,d,o,c,l),d+=p-(v=e.measureText(t.substring(y+1)).width)+a,p=v}e.textAlign=h}else u?this.strokeText(e,t,i,o,s):this.fillText(e,t,i,o,c,l)},r.fillText=function(e,r,n,i,o,a){var c,s=!t.isNil(o)&&1!==o;s&&(c=e.globalAlpha,e.globalAlpha=o*a),e.fillText(r,n,i),s&&(e.globalAlpha=c)},r.strokeText=function(e,r,n,i,o){var a,c=!t.isNil(o)&&1!==o;c&&(a=e.globalAlpha,e.globalAlpha=o),e.strokeText(r,n,i),c&&(e.globalAlpha=a)},e}(),e.TextRenderer=s([t.singleton({token:I})],e.TextRenderer);var W=function(){function e(){this.imagePool=void 0}var r=e.prototype;return r.render=function(e,r,n,i){var o=r.fill,a=r.opacity,c=r.fillOpacity,s=r.stroke,l=r.strokeOpacity,u=r.lineWidth,h=r.lineCap,d=r.lineJoin,f=r.shadowType,p=r.shadowColor,v=r.shadowBlur,y=r.filter,g=r.miterLimit,m=!t.isNil(o)&&!o.isNone,w=!t.isNil(s)&&!s.isNone&&u&&u.value>0,x=0===o.alpha,b=!t.isNil(y),R=!t.isNil(p)&&(null==v?void 0:v.value)>0,E=n.nodeName,C="inner"===(null==f?void 0:f.value),P=w&&R&&(E===t.Shape.PATH||E===t.Shape.LINE||E===t.Shape.POLYLINE||x||C);m&&(e.globalAlpha=a.value*c.value,P||this.setShadowAndFilter(n,e,R),this.fill(e,n,o,i),P||this.clearShadowAndFilter(e,b,R)),w&&(e.globalAlpha=a.value*l.value,e.lineWidth=u.value,t.isNil(g)||(e.miterLimit=g.value),t.isNil(h)||(e.lineCap=h.value),t.isNil(d)||(e.lineJoin=d.value),P&&(C&&(e.globalCompositeOperation="source-atop"),this.setShadowAndFilter(n,e,!0),C&&(this.stroke(e,n,s,i),e.globalCompositeOperation="source-over",this.clearShadowAndFilter(e,b,!0))),this.stroke(e,n,s,i))},r.clearShadowAndFilter=function(e,r,n){if(n&&(e.shadowColor="transparent",e.shadowBlur=0),r){var i=e.filter;!t.isNil(i)&&i.indexOf("drop-shadow")>-1&&(e.filter=i.replace(/drop-shadow\([^)]*\)/,"").trim()||"none")}},r.setShadowAndFilter=function(e,r,n){var i=e.parsedStyle,o=i.shadowColor,a=i.shadowBlur,c=i.shadowOffsetX,s=i.shadowOffsetY;t.isNil(i.filter)||(r.filter=e.style.filter),n&&(r.shadowColor=o.toString(),r.shadowBlur=a&&a.value||0,r.shadowOffsetX=c&&c.value||0,r.shadowOffsetY=s&&s.value||0)},r.fill=function(e,r,n,i){var o=this;Array.isArray(n)?n.forEach((function(t){e.fillStyle=o.getColor(t,r,e),e.fill()})):(t.isPattern(n)&&(e.fillStyle=this.getPattern(n,r,e,i)),e.fill())},r.stroke=function(e,r,n,i){var o=this;Array.isArray(n)?n.forEach((function(t){e.strokeStyle=o.getColor(t,r,e),e.stroke()})):(t.isPattern(n)&&(e.strokeStyle=this.getPattern(n,r,e,i)),e.stroke())},r.getPattern=function(e,t,r,n){return this.imagePool.getOrCreatePatternSync(e,r,(function(){t.renderable.dirty=!0,n.dirtify()}))},r.getColor=function(e,r,n){var i;if(e.type===t.GradientType.LinearGradient||e.type===t.GradientType.RadialGradient){var a=r.getGeometryBounds();i=this.imagePool.getOrCreateGradient(o({type:e.type},e.value,{width:a&&2*a.halfExtents[0]||1,height:a&&2*a.halfExtents[1]||1}),n)}return i},e}();s([t.inject(X),l("design:type",X)],W.prototype,"imagePool",void 0),W=s([t.singleton()],W),e.RectRenderer=function(e){function t(){return e.apply(this,arguments)||this}return a(t,e),t}(W),e.RectRenderer=s([t.singleton({token:A})],e.RectRenderer),e.CircleRenderer=function(e){function t(){return e.apply(this,arguments)||this}return a(t,e),t}(W),e.CircleRenderer=s([t.singleton({token:T})],e.CircleRenderer),e.EllipseRenderer=function(e){function t(){return e.apply(this,arguments)||this}return a(t,e),t}(W),e.EllipseRenderer=s([t.singleton({token:k})],e.EllipseRenderer),e.LineRenderer=function(e){function t(){return e.apply(this,arguments)||this}return a(t,e),t}(W),e.LineRenderer=s([t.singleton({token:M})],e.LineRenderer),e.PolylineRenderer=function(e){function t(){return e.apply(this,arguments)||this}return a(t,e),t}(W),e.PolylineRenderer=s([t.singleton({token:N})],e.PolylineRenderer),e.PolygonRenderer=function(e){function t(){return e.apply(this,arguments)||this}return a(t,e),t}(W),e.PolygonRenderer=s([t.singleton({token:j})],e.PolygonRenderer),e.PathRenderer=function(e){function t(){return e.apply(this,arguments)||this}return a(t,e),t}(W),e.PathRenderer=s([t.singleton({token:B})],e.PathRenderer);var Q,H,J=t.Syringe.defineToken("CanvasRendererPluginOptions"),K=(Q=function(){function e(){this.canvasConfig=void 0,this.camera=void 0,this.contextService=void 0,this.renderingContext=void 0,this.pathGeneratorFactory=void 0,this.pathGeneratorFactoryCache={},this.styleRendererFactory=void 0,this.styleRendererFactoryCache={},this.displayObjectPool=void 0,this.canvasRendererPluginOptions=void 0,this.rBush=void 0,this.removedRBushNodeAABBs=[],this.renderQueue=[],this.restoreStack=[],this.clearFullScreen=!1,this.vpMatrix=x(),this.dprMatrix=x(),this.tmpMat4=x(),this.tmpVec3=C()}var n=e.prototype;return n.apply=function(e){var n=this,o=this.renderingContext.root.ownerDocument.defaultView,a=function(e){var t=e.target.rBushNode;t.aabb&&n.removedRBushNodeAABBs.push(t.aabb)},c=function(e){var t=e.target.rBushNode;t.aabb&&n.removedRBushNodeAABBs.push(t.aabb)};e.hooks.init.tapPromise(H.tag,i(r().mark((function e(){var i,o,s,l,u;return r().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n.renderingContext.root.addEventListener(t.ElementEvent.UNMOUNTED,a),n.renderingContext.root.addEventListener(t.ElementEvent.CULLED,c),i=n.contextService.getDPR(),s=(o=n.canvasConfig).width,l=o.height,u=n.contextService.getContext(),n.clearRect(u,0,0,s*i,l*i),r=n.dprMatrix,h=P(i,i,1),r[0]=h[0],r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=h[1],r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=h[2],r[11]=0,r[12]=0,r[13]=0,r[14]=0,r[15]=1;case 7:case"end":return e.stop()}var r,h}),e)})))),e.hooks.destroy.tap(H.tag,(function(){n.renderingContext.root.removeEventListener(t.ElementEvent.UNMOUNTED,a),n.renderingContext.root.removeEventListener(t.ElementEvent.CULLED,c)})),e.hooks.beginFrame.tap(H.tag,(function(){var t=n.contextService.getContext(),r=n.contextService.getDPR(),i=n.canvasConfig,o=i.width,a=i.height,c=n.canvasRendererPluginOptions,s=c.dirtyObjectNumThreshold,l=c.dirtyObjectRatioThreshold,u=e.getStats(),h=u.rendered,d=h/u.total;n.clearFullScreen=e.disableDirtyRectangleRendering()||h>s&&d>l,t&&(t.resetTransform(),n.clearFullScreen&&n.clearRect(t,0,0,o*r,a*r))})),e.hooks.endFrame.tap(H.tag,(function(){var r=n.contextService.getContext();if(R(n.vpMatrix,n.dprMatrix,n.camera.getOrthoMatrix()),n.clearFullScreen)n.renderingContext.root.forEach((function(t){t.isVisible()&&!t.isCulled()&&(n.renderDisplayObject(t,e),n.saveDirtyAABB(t))}));else{var i=n.safeMergeAABB.apply(n,[n.mergeDirtyAABBs(n.renderQueue)].concat(n.removedRBushNodeAABBs.map((function(e){var r=e.minX,n=e.minY,i=e.maxX,o=e.maxY,a=new t.AABB;return a.setMinMax(P(r,n,0),P(i,o,0)),a}))));if(n.removedRBushNodeAABBs=[],t.AABB.isEmpty(i))return void(n.renderQueue=[]);var a=n.convertAABB2Rect(i),c=a.x,s=a.y,l=a.width,u=a.height,h=S(n.tmpVec3,P(c,s,0),n.vpMatrix),d=S(C(),P(c+l,s+u,0),n.vpMatrix),f=Math.floor(h[0]),p=Math.floor(h[1]),v=Math.ceil(d[0]-h[0]),y=Math.ceil(d[1]-h[1]);r.save(),n.clearRect(r,f,p,v,y),r.beginPath(),r.rect(f,p,v,y),r.clip(),r.setTransform(n.vpMatrix[0],n.vpMatrix[1],n.vpMatrix[4],n.vpMatrix[5],n.vpMatrix[12],n.vpMatrix[13]),n.canvasConfig.renderer.getConfig().enableDirtyRectangleRenderingDebug&&o.dispatchEvent(new t.CustomEvent(t.CanvasEvent.DIRTY_RECTANGLE,{dirtyRect:a})),n.searchDirtyObjects(i).sort((function(e,t){return e.sortable.renderOrder-t.sortable.renderOrder})).forEach((function(t){t&&t.isVisible()&&!t.isCulled()&&n.renderDisplayObject(t,e)})),r.restore(),n.renderQueue.forEach((function(e){n.saveDirtyAABB(e)})),n.renderQueue=[]}n.restoreStack.forEach((function(){r.restore()})),n.restoreStack=[]})),e.hooks.render.tap(H.tag,(function(e){n.clearFullScreen||n.renderQueue.push(e)}))},n.clearRect=function(e,t,r,n,i){e.clearRect(t,r,n,i);var o=this.canvasConfig.background;o&&(e.fillStyle=o,e.fillRect(t,r,n,i))},n.renderDisplayObject=function(e,r){for(var n=this.contextService.getContext(),i=this.restoreStack[this.restoreStack.length-1];i&&e.parentNode!==i;)n.restore(),this.restoreStack.pop(),i=this.restoreStack[this.restoreStack.length-1];var o=e.nodeName;void 0===this.styleRendererFactoryCache[o]&&(this.styleRendererFactoryCache[o]=this.styleRendererFactory(o));var a=this.styleRendererFactoryCache[o];void 0===this.pathGeneratorFactoryCache[o]&&(this.pathGeneratorFactoryCache[o]=this.pathGeneratorFactory(o));var c=this.pathGeneratorFactoryCache[o],s=e.parsedStyle.clipPath;if(s){this.applyWorldTransform(n,s,e.getWorldTransform()),void 0===this.pathGeneratorFactoryCache[s.nodeName]&&(this.pathGeneratorFactoryCache[s.nodeName]=this.pathGeneratorFactory(s.nodeName));var l=this.pathGeneratorFactoryCache[s.nodeName];l&&(n.save(),this.restoreStack.push(e),n.beginPath(),l(n,s.parsedStyle),n.closePath(),n.clip())}a&&(this.applyWorldTransform(n,e),n.save(),this.applyAttributesToContext(n,e)),c&&(n.beginPath(),c(n,e.parsedStyle),e.nodeName!==t.Shape.LINE&&e.nodeName!==t.Shape.PATH&&e.nodeName!==t.Shape.POLYLINE&&n.closePath()),a&&(a.render(n,e.parsedStyle,e,r),n.restore()),e.renderable.dirty=!1},n.convertAABB2Rect=function(e){var t=e.getMin(),r=e.getMax(),n=Math.floor(t[0]),i=Math.floor(t[1]);return{x:n,y:i,width:Math.ceil(r[0])-n,height:Math.ceil(r[1])-i}},n.mergeDirtyAABBs=function(e){var r=new t.AABB;return e.forEach((function(e){var t=e.getRenderBounds();r.add(t);var n=e.renderable.dirtyRenderBounds;n&&r.add(n)})),r},n.searchDirtyObjects=function(e){var t=this,r=e.getMin(),n=r[0],i=r[1],o=e.getMax();return this.rBush.search({minX:n,minY:i,maxX:o[0],maxY:o[1]}).map((function(e){return t.displayObjectPool.getByEntity(e.id)}))},n.saveDirtyAABB=function(e){var r=e.renderable;r.dirtyRenderBounds||(r.dirtyRenderBounds=new t.AABB);var n=e.getRenderBounds();n&&r.dirtyRenderBounds.update(n.center,n.halfExtents)},n.applyAttributesToContext=function(e,r){var n=r.parsedStyle,i=n.stroke,o=n.fill,a=n.opacity,c=n.lineDash,s=n.lineDashOffset;c&&Array.isArray(c)&&e.setLineDash(c.map((function(e){return e.value}))),t.isNil(s)||(e.lineDashOffset=s.value),t.isNil(a)||(e.globalAlpha*=a.value),t.isNil(i)||Array.isArray(i)||i.isNone||(e.strokeStyle=r.attributes.stroke),t.isNil(o)||Array.isArray(o)||o.isNone||(e.fillStyle=r.attributes.fill)},n.applyWorldTransform=function(e,t,r){var n=0,i=0,o=(t.parsedStyle||{}).anchor,a=o&&o[0].value||0,c=o&&o[1].value||0;if(0!==a||0!==c){var s=t.getGeometryBounds();n=-a*(s&&2*s.halfExtents[0]||0),i=-c*(s&&2*s.halfExtents[1]||0)}r?(b(this.tmpMat4,t.getLocalTransform()),this.tmpVec3[0]=n,this.tmpVec3[1]=i,this.tmpVec3[2]=0,E(this.tmpMat4,this.tmpMat4,this.tmpVec3),R(this.tmpMat4,r,this.tmpMat4),R(this.tmpMat4,this.vpMatrix,this.tmpMat4)):(b(this.tmpMat4,t.getWorldTransform()),this.tmpVec3[0]=n,this.tmpVec3[1]=i,this.tmpVec3[2]=0,E(this.tmpMat4,this.tmpMat4,this.tmpVec3),R(this.tmpMat4,this.vpMatrix,this.tmpMat4)),e.setTransform(this.tmpMat4[0],this.tmpMat4[1],this.tmpMat4[4],this.tmpMat4[5],this.tmpMat4[12],this.tmpMat4[13])},n.safeMergeAABB=function(){for(var e=new t.AABB,r=arguments.length,n=new Array(r),i=0;r>i;i++)n[i]=arguments[i];return n.forEach((function(t){e.add(t)})),e},e}(),Q.tag="CanvasRenderer",H=Q);s([t.inject(t.CanvasConfig),l("design:type",Object)],K.prototype,"canvasConfig",void 0),s([t.inject(t.DefaultCamera),l("design:type",t.Camera)],K.prototype,"camera",void 0),s([t.inject(t.ContextService),l("design:type",Object)],K.prototype,"contextService",void 0),s([t.inject(t.RenderingContext),l("design:type",Object)],K.prototype,"renderingContext",void 0),s([t.inject(u),l("design:type",Function)],K.prototype,"pathGeneratorFactory",void 0),s([t.inject(O),l("design:type",Function)],K.prototype,"styleRendererFactory",void 0),s([t.inject(t.DisplayObjectPool),l("design:type",t.DisplayObjectPool)],K.prototype,"displayObjectPool",void 0),s([t.inject(J),l("design:type",Object)],K.prototype,"canvasRendererPluginOptions",void 0),s([t.inject(t.RBushRoot),l("design:type",t.RBush)],K.prototype,"rBush",void 0),K=H=s([t.singleton({contrib:t.RenderingPluginContribution})],K);var q=t.Module((function(r){var n;r(e.CircleRenderer),r(e.EllipseRenderer),r(e.RectRenderer),r(e.ImageRenderer),r(e.TextRenderer),r(e.LineRenderer),r(e.PolylineRenderer),r(e.PolygonRenderer),r(e.PathRenderer);var i=((n={})[t.Shape.CIRCLE]=T,n[t.Shape.ELLIPSE]=k,n[t.Shape.RECT]=A,n[t.Shape.IMAGE]=G,n[t.Shape.TEXT]=I,n[t.Shape.LINE]=M,n[t.Shape.POLYLINE]=N,n[t.Shape.POLYGON]=j,n[t.Shape.PATH]=B,n);r({token:O,useFactory:function(e){return function(t){var r=i[t];return r&&e.container.isBound(r)?e.container.get(r):null}}}),r(K)})),z=function(e){function t(t){var r;return void 0===t&&(t={}),(r=e.call(this)||this).options=void 0,r.name="canvas-renderer",r.options=t,r}a(t,e);var r=t.prototype;return r.init=function(){this.container.register(J,{useValue:o({dirtyObjectNumThreshold:500,dirtyObjectRatioThreshold:.8},this.options)}),this.container.load(q,!0)},r.destroy=function(){this.container.unload(q),this.container.remove(J)},t}(t.AbstractRendererPlugin);e.CircleRendererContribution=T,e.EllipseRendererContribution=k,e.ImageRendererContribution=G,e.LineRendererContribution=M,e.PathRendererContribution=B,e.Plugin=z,e.PolygonRendererContribution=j,e.PolylineRendererContribution=N,e.RectRendererContribution=A,e.StyleRendererFactory=O,e.TextRendererContribution=I,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
F=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",o=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function s(e,t,r,n){var i=Object.create((t&&t.prototype instanceof h?t:h).prototype),o=new E(n||[]);return i._invoke=function(e,t,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return P()}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var c=x(a,r);if(c){if(c===u)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var s=l(e,t,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===u)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.arg)}}}(e,r,o),i}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=s;var u={};function h(){}function d(){}function f(){}var p={};c(p,i,(function(){return this}));var v=Object.getPrototypeOf,y=v&&v(v(C([])));y&&y!==t&&r.call(y,i)&&(p=y);var g=f.prototype=h.prototype=Object.create(p);function m(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function w(e,t){function n(i,o,a,c){var s=l(e[i],e,o);if("throw"!==s.type){var u=s.arg,h=u.value;return h&&"object"==typeof h&&r.call(h,"__await")?t.resolve(h.__await).then((function(e){n("next",e,a,c)}),(function(e){n("throw",e,a,c)})):t.resolve(h).then((function(e){u.value=e,a(u)}),(function(e){return n("throw",e,a,c)}))}c(s.arg)}var i;this._invoke=function(e,r){function o(){return new t((function(t,i){n(e,r,t,i)}))}return i=i?i.then(o,o):o()}}function x(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,x(e,t),"throw"===t.method))return u;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return u}var n=l(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,u;var i=n.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,u):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,u)}function b(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function R(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(b,this),this.reset(!0)}function C(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,o=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return o.next=o}}return{next:P}}function P(){return{value:void 0,done:!0}}return d.prototype=f,c(g,"constructor",f),c(f,"constructor",d),d.displayName=c(f,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,f):(e.__proto__=f,c(e,a,"GeneratorFunction")),e.prototype=Object.create(g),e},e.awrap=function(e){return{__await:e}},m(w.prototype),c(w.prototype,o,(function(){return this})),e.AsyncIterator=w,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var a=new w(s(t,r,n,i),o);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},m(g),c(g,a,"Generator"),c(g,i,(function(){return this})),c(g,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=C,E.prototype={constructor:E,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(R),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return a.type="throw",a.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return n("end");if(this.prev>=o.tryLoc){var c=r.call(o,"catchLoc"),s=r.call(o,"finallyLoc");if(c&&s){if(o.catchLoc>this.prev)return n(o.catchLoc,!0);if(o.finallyLoc>this.prev)return n(o.finallyLoc)}else if(c){if(o.catchLoc>this.prev)return n(o.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(o.finallyLoc>this.prev)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(this.prev>=i.tryLoc&&r.call(i,"finallyLoc")&&i.finallyLoc>this.prev){var o=i;break}}o&&("break"===e||"continue"===e)&&t>=o.tryLoc&&o.finallyLoc>=t&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,u):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),u},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),R(r),u}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;R(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:C(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),u}},e}function _(e,t,r,n,i,o,a){try{var c=e[o](a),s=c.value}catch(e){return void r(e)}c.done?t(s):Promise.resolve(s).then(n,i)}function D(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){_(o,n,i,a,c,"next",e)}function c(e){_(o,n,i,a,c,"throw",e)}a(void 0)}))}}var V,Y,X=function(){function e(){this.imageCache={},this.gradientCache={},this.patternCache={},this.canvasConfig=void 0}var r=e.prototype;return r.getImageSync=function(e,t){return this.imageCache[e]||this.getOrCreateImage(e).then((function(){t&&t()})),this.imageCache[e]},r.getOrCreateImage=function(e){var r=this;if(this.imageCache[e])return Promise.resolve(this.imageCache[e]);var n=this.canvasConfig.createImage;return new Promise((function(i,o){var a;n?a=n(e):t.isBrowser&&(a=new window.Image),a&&(a.onload=function(){i(a)},a.onerror=function(e){o(e)},a.crossOrigin="Anonymous",a.src=e,r.imageCache[e]=a)}))},r.getOrCreatePatternSync=function(e,r,n){var i=this.generatePatternKey(e);if(i&&this.patternCache[i])return this.patternCache[i];var o,a=e.image,c=e.repetition,s=(o=t.isString(a)?this.getImageSync(a,n):a)&&r.createPattern(o,c);return i&&s&&(this.patternCache[i]=s),s},r.getOrCreateGradient=function(e,r){var n=this.generateGradientKey(e),i=e.type,o=e.steps,a=e.width,c=e.height,s=e.cx,l=e.cy;if(this.gradientCache[n])return this.gradientCache[n];var u=null;if(i===t.GradientType.LinearGradient){var h=t.computeLinearGradient(a,c,e.angle);u=r.createLinearGradient(h.x1,h.y1,h.x2,h.y2)}else if(i===t.GradientType.RadialGradient){var d=t.computeRadialGradient(a,c,s,l),f=d.x,p=d.y;u=r.createRadialGradient(f,p,0,f,p,d.r)}return u&&(o.forEach((function(e){var t;null===(t=u)||void 0===t||t.addColorStop(e[0],e[1])})),this.gradientCache[n]=u),this.gradientCache[n]},r.generateGradientKey=function(e){return"gradient-"+e.type+"-"+(e.angle||0)+"-"+(e.cx||0)+"-"+(e.cy||0)+"-"+e.width+"-"+e.height+"-"+e.steps.map((function(e){return e.join("")})).join("-")},r.generatePatternKey=function(e){var r=e.image,n=e.repetition;if(t.isString(r))return"pattern-"+r+"-"+n},e}();s([t.inject(t.CanvasConfig),l("design:type",Object)],X.prototype,"canvasConfig",void 0),X=s([t.singleton()],X);var U=(V=function(){function e(){this.imagePool=void 0,this.renderingContext=void 0}return e.prototype.apply=function(e){var r=this,n=function(n){var i=n.target;if(i.nodeName===t.Shape.IMAGE){var o=i.attributes.img;t.isString(o)&&r.imagePool.getImageSync(o,(function(){i.renderable.dirty=!0,e.dirtify()}))}},i=function(n){var i=n.target,o=n.newValue;i.nodeName===t.Shape.IMAGE&&"img"===n.attrName&&t.isString(o)&&r.imagePool.getOrCreateImage(o).then((function(){i.renderable.dirty=!0,e.dirtify()}))};e.hooks.init.tapPromise(Y.tag,D(F().mark((function e(){return F().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r.renderingContext.root.addEventListener(t.ElementEvent.MOUNTED,n),r.renderingContext.root.addEventListener(t.ElementEvent.ATTR_MODIFIED,i);case 2:case"end":return e.stop()}}),e)})))),e.hooks.destroy.tap(Y.tag,(function(){r.renderingContext.root.removeEventListener(t.ElementEvent.MOUNTED,n),r.renderingContext.root.removeEventListener(t.ElementEvent.ATTR_MODIFIED,i)}))},e}(),V.tag="LoadImage",Y=V);s([t.inject(X),l("design:type",X)],U.prototype,"imagePool",void 0),s([t.inject(t.RenderingContext),l("design:type",Object)],U.prototype,"renderingContext",void 0),U=Y=s([t.singleton({contrib:t.RenderingPluginContribution})],U);t.Module((function(e){e(X),e(U)}));e.ImageRenderer=function(){function e(){this.imagePool=void 0}return e.prototype.render=function(e,r){var n,i=r.img,o=r.width.value,a=r.height.value;if(t.isString(i)?n=this.imagePool.getImageSync(i):(o||(o=i.width),a||(a=i.height),n=i),n)try{e.drawImage(n,0,0,o,a)}catch(e){}},e}(),s([t.inject(X),l("design:type",X)],e.ImageRenderer.prototype,"imagePool",void 0),e.ImageRenderer=s([t.singleton({token:G})],e.ImageRenderer),e.TextRenderer=function(){function e(){}var r=e.prototype;return r.render=function(e,r,n){var i=r.lineWidth,o=r.textAlign,a=r.textBaseline,c=r.lineJoin,s=r.miterLimit,l=r.letterSpacing,u=r.stroke,h=r.fill,d=r.fillOpacity,f=r.strokeOpacity,p=r.opacity,v=r.metrics,y=r.dx,g=r.dy,m=v.lines,w=v.height,x=v.lineHeight,b=v.lineMetrics;e.font=v.font,e.lineWidth=i.value,e.textAlign=o.value,e.textBaseline=a.value,e.lineJoin=c.value,t.isNil(s)||(e.miterLimit=s.value);var R=0;"middle"===a.value?R=-w/2-x/2:"bottom"===a.value||"alphabetic"===a.value||"ideographic"===a.value?R=-w:"top"!==a.value&&"hanging"!==a.value||(R=-x);var E=0;y&&y.unit===t.UnitType.kPixels&&(E+=y.value),g&&g.unit===t.UnitType.kPixels&&(R+=g.value);for(var C=0;m.length>C;C++){var P=i.value/2+E;R+=x,!t.isNil(u)&&!u.isNone&&i&&i.value&&this.drawLetterSpacing(e,m[C],b[C],o.value,P,R,l.value,d.value,f.value,p.value,!0),t.isNil(h)||this.drawLetterSpacing(e,m[C],b[C],o.value,P,R,l.value,d.value,f.value,p.value)}},r.drawLetterSpacing=function(e,t,r,n,i,o,a,c,s,l,u){if(void 0===u&&(u=!1),0!==a){var h=e.textAlign;e.textAlign="left";var d=i;"center"===n?d=i-r.width/2:"right"!==n&&"end"!==n||(d=i-r.width);for(var f=Array.from(t),p=e.measureText(t).width,v=0,y=0;f.length>y;++y){var g=f[y];u?this.strokeText(e,g,d,o,s):this.fillText(e,g,d,o,c,l),d+=p-(v=e.measureText(t.substring(y+1)).width)+a,p=v}e.textAlign=h}else u?this.strokeText(e,t,i,o,s):this.fillText(e,t,i,o,c,l)},r.fillText=function(e,r,n,i,o,a){var c,s=!t.isNil(o)&&1!==o;s&&(c=e.globalAlpha,e.globalAlpha=o*a),e.fillText(r,n,i),s&&(e.globalAlpha=c)},r.strokeText=function(e,r,n,i,o){var a,c=!t.isNil(o)&&1!==o;c&&(a=e.globalAlpha,e.globalAlpha=o),e.strokeText(r,n,i),c&&(e.globalAlpha=a)},e}(),e.TextRenderer=s([t.singleton({token:I})],e.TextRenderer);var W=function(){function e(){this.imagePool=void 0}var r=e.prototype;return r.render=function(e,r,n,i){var o=r.fill,a=r.opacity,c=r.fillOpacity,s=r.stroke,l=r.strokeOpacity,u=r.lineWidth,h=r.lineCap,d=r.lineJoin,f=r.shadowType,p=r.shadowColor,v=r.shadowBlur,y=r.filter,g=r.miterLimit,m=!t.isNil(o)&&!o.isNone,w=!t.isNil(s)&&!s.isNone&&u&&u.value>0,x=0===o.alpha,b=!t.isNil(y),R=!t.isNil(p)&&(null==v?void 0:v.value)>0,E=n.nodeName,C="inner"===(null==f?void 0:f.value),P=w&&R&&(E===t.Shape.PATH||E===t.Shape.LINE||E===t.Shape.POLYLINE||x||C);m&&(e.globalAlpha=a.value*c.value,P||this.setShadowAndFilter(n,e,R),this.fill(e,n,o,i),P||this.clearShadowAndFilter(e,b,R)),w&&(e.globalAlpha=a.value*l.value,e.lineWidth=u.value,t.isNil(g)||(e.miterLimit=g.value),t.isNil(h)||(e.lineCap=h.value),t.isNil(d)||(e.lineJoin=d.value),P&&(C&&(e.globalCompositeOperation="source-atop"),this.setShadowAndFilter(n,e,!0),C&&(this.stroke(e,n,s,i),e.globalCompositeOperation="source-over",this.clearShadowAndFilter(e,b,!0))),this.stroke(e,n,s,i))},r.clearShadowAndFilter=function(e,r,n){if(n&&(e.shadowColor="transparent",e.shadowBlur=0),r){var i=e.filter;!t.isNil(i)&&i.indexOf("drop-shadow")>-1&&(e.filter=i.replace(/drop-shadow\([^)]*\)/,"").trim()||"none")}},r.setShadowAndFilter=function(e,r,n){var i=e.parsedStyle,o=i.shadowColor,a=i.shadowBlur,c=i.shadowOffsetX,s=i.shadowOffsetY;t.isNil(i.filter)||(r.filter=e.style.filter),n&&(r.shadowColor=o.toString(),r.shadowBlur=a&&a.value||0,r.shadowOffsetX=c&&c.value||0,r.shadowOffsetY=s&&s.value||0)},r.fill=function(e,r,n,i){var o=this;Array.isArray(n)?n.forEach((function(t){e.fillStyle=o.getColor(t,r,e),e.fill()})):(t.isPattern(n)&&(e.fillStyle=this.getPattern(n,r,e,i)),e.fill())},r.stroke=function(e,r,n,i){var o=this;Array.isArray(n)?n.forEach((function(t){e.strokeStyle=o.getColor(t,r,e),e.stroke()})):(t.isPattern(n)&&(e.strokeStyle=this.getPattern(n,r,e,i)),e.stroke())},r.getPattern=function(e,t,r,n){return this.imagePool.getOrCreatePatternSync(e,r,(function(){t.renderable.dirty=!0,n.dirtify()}))},r.getColor=function(e,r,n){var i;if(e.type===t.GradientType.LinearGradient||e.type===t.GradientType.RadialGradient){var a=r.getGeometryBounds();i=this.imagePool.getOrCreateGradient(o({type:e.type},e.value,{width:a&&2*a.halfExtents[0]||1,height:a&&2*a.halfExtents[1]||1}),n)}return i},e}();s([t.inject(X),l("design:type",X)],W.prototype,"imagePool",void 0),W=s([t.singleton()],W),e.RectRenderer=function(e){function t(){return e.apply(this,arguments)||this}return a(t,e),t}(W),e.RectRenderer=s([t.singleton({token:A})],e.RectRenderer),e.CircleRenderer=function(e){function t(){return e.apply(this,arguments)||this}return a(t,e),t}(W),e.CircleRenderer=s([t.singleton({token:T})],e.CircleRenderer),e.EllipseRenderer=function(e){function t(){return e.apply(this,arguments)||this}return a(t,e),t}(W),e.EllipseRenderer=s([t.singleton({token:k})],e.EllipseRenderer),e.LineRenderer=function(e){function t(){return e.apply(this,arguments)||this}return a(t,e),t}(W),e.LineRenderer=s([t.singleton({token:M})],e.LineRenderer),e.PolylineRenderer=function(e){function t(){return e.apply(this,arguments)||this}return a(t,e),t}(W),e.PolylineRenderer=s([t.singleton({token:N})],e.PolylineRenderer),e.PolygonRenderer=function(e){function t(){return e.apply(this,arguments)||this}return a(t,e),t}(W),e.PolygonRenderer=s([t.singleton({token:j})],e.PolygonRenderer),e.PathRenderer=function(e){function t(){return e.apply(this,arguments)||this}return a(t,e),t}(W),e.PathRenderer=s([t.singleton({token:B})],e.PathRenderer);var Q,H,J=t.Syringe.defineToken("CanvasRendererPluginOptions"),K=(Q=function(){function e(){this.canvasConfig=void 0,this.camera=void 0,this.contextService=void 0,this.renderingContext=void 0,this.pathGeneratorFactory=void 0,this.pathGeneratorFactoryCache={},this.styleRendererFactory=void 0,this.styleRendererFactoryCache={},this.displayObjectPool=void 0,this.canvasRendererPluginOptions=void 0,this.rBush=void 0,this.removedRBushNodeAABBs=[],this.renderQueue=[],this.restoreStack=[],this.clearFullScreen=!1,this.vpMatrix=x(),this.dprMatrix=x(),this.tmpMat4=x(),this.tmpVec3=C()}var n=e.prototype;return n.apply=function(e){var n=this,o=this.renderingContext.root.ownerDocument.defaultView,a=function(e){var t=e.target.rBushNode;t.aabb&&n.removedRBushNodeAABBs.push(t.aabb)},c=function(e){var t=e.target.rBushNode;t.aabb&&n.removedRBushNodeAABBs.push(t.aabb)};e.hooks.init.tapPromise(H.tag,i(r().mark((function e(){var i,o,s,l,u;return r().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n.renderingContext.root.addEventListener(t.ElementEvent.UNMOUNTED,a),n.renderingContext.root.addEventListener(t.ElementEvent.CULLED,c),i=n.contextService.getDPR(),s=(o=n.canvasConfig).width,l=o.height,u=n.contextService.getContext(),n.clearRect(u,0,0,s*i,l*i),r=n.dprMatrix,h=P(i,i,1),r[0]=h[0],r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=h[1],r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=h[2],r[11]=0,r[12]=0,r[13]=0,r[14]=0,r[15]=1;case 7:case"end":return e.stop()}var r,h}),e)})))),e.hooks.destroy.tap(H.tag,(function(){n.renderingContext.root.removeEventListener(t.ElementEvent.UNMOUNTED,a),n.renderingContext.root.removeEventListener(t.ElementEvent.CULLED,c)})),e.hooks.beginFrame.tap(H.tag,(function(){var t=n.contextService.getContext(),r=n.contextService.getDPR(),i=n.canvasConfig,o=i.width,a=i.height,c=n.canvasRendererPluginOptions,s=c.dirtyObjectNumThreshold,l=c.dirtyObjectRatioThreshold,u=e.getStats(),h=u.rendered,d=h/u.total;n.clearFullScreen=e.disableDirtyRectangleRendering()||h>s&&d>l,t&&(t.resetTransform(),n.clearFullScreen&&n.clearRect(t,0,0,o*r,a*r))}));var s=function t(r){r.isVisible()&&!r.isCulled()&&(n.renderDisplayObject(r,e),n.saveDirtyAABB(r)),r.sortable.sorted&&r.sortable.sorted.length&&r.sortable.sorted.forEach((function(e){t(e)}))};e.hooks.endFrame.tap(H.tag,(function(){var r=n.contextService.getContext();if(R(n.vpMatrix,n.dprMatrix,n.camera.getOrthoMatrix()),n.clearFullScreen)s(n.renderingContext.root);else{var i=n.safeMergeAABB.apply(n,[n.mergeDirtyAABBs(n.renderQueue)].concat(n.removedRBushNodeAABBs.map((function(e){var r=e.minX,n=e.minY,i=e.maxX,o=e.maxY,a=new t.AABB;return a.setMinMax(P(r,n,0),P(i,o,0)),a}))));if(n.removedRBushNodeAABBs=[],t.AABB.isEmpty(i))return void(n.renderQueue=[]);var a=n.convertAABB2Rect(i),c=a.x,l=a.y,u=a.width,h=a.height,d=S(n.tmpVec3,P(c,l,0),n.vpMatrix),f=S(C(),P(c+u,l+h,0),n.vpMatrix),p=Math.floor(d[0]),v=Math.floor(d[1]),y=Math.ceil(f[0]-d[0]),g=Math.ceil(f[1]-d[1]);r.save(),n.clearRect(r,p,v,y,g),r.beginPath(),r.rect(p,v,y,g),r.clip(),r.setTransform(n.vpMatrix[0],n.vpMatrix[1],n.vpMatrix[4],n.vpMatrix[5],n.vpMatrix[12],n.vpMatrix[13]),n.canvasConfig.renderer.getConfig().enableDirtyRectangleRenderingDebug&&o.dispatchEvent(new t.CustomEvent(t.CanvasEvent.DIRTY_RECTANGLE,{dirtyRect:a})),n.searchDirtyObjects(i).sort((function(e,t){return e.sortable.renderOrder-t.sortable.renderOrder})).forEach((function(t){t&&t.isVisible()&&!t.isCulled()&&n.renderDisplayObject(t,e)})),r.restore(),n.renderQueue.forEach((function(e){n.saveDirtyAABB(e)})),n.renderQueue=[]}n.restoreStack.forEach((function(){r.restore()})),n.restoreStack=[]})),e.hooks.render.tap(H.tag,(function(e){n.clearFullScreen||n.renderQueue.push(e)}))},n.clearRect=function(e,t,r,n,i){e.clearRect(t,r,n,i);var o=this.canvasConfig.background;o&&(e.fillStyle=o,e.fillRect(t,r,n,i))},n.renderDisplayObject=function(e,r){for(var n=this.contextService.getContext(),i=this.restoreStack[this.restoreStack.length-1];i&&e.parentNode!==i;)n.restore(),this.restoreStack.pop(),i=this.restoreStack[this.restoreStack.length-1];var o=e.nodeName;void 0===this.styleRendererFactoryCache[o]&&(this.styleRendererFactoryCache[o]=this.styleRendererFactory(o));var a=this.styleRendererFactoryCache[o];void 0===this.pathGeneratorFactoryCache[o]&&(this.pathGeneratorFactoryCache[o]=this.pathGeneratorFactory(o));var c=this.pathGeneratorFactoryCache[o],s=e.parsedStyle.clipPath;if(s){this.applyWorldTransform(n,s,e.getWorldTransform()),void 0===this.pathGeneratorFactoryCache[s.nodeName]&&(this.pathGeneratorFactoryCache[s.nodeName]=this.pathGeneratorFactory(s.nodeName));var l=this.pathGeneratorFactoryCache[s.nodeName];l&&(n.save(),this.restoreStack.push(e),n.beginPath(),l(n,s.parsedStyle),n.closePath(),n.clip())}a&&(this.applyWorldTransform(n,e),n.save(),this.applyAttributesToContext(n,e)),c&&(n.beginPath(),c(n,e.parsedStyle),e.nodeName!==t.Shape.LINE&&e.nodeName!==t.Shape.PATH&&e.nodeName!==t.Shape.POLYLINE&&n.closePath()),a&&(a.render(n,e.parsedStyle,e,r),n.restore()),e.renderable.dirty=!1},n.convertAABB2Rect=function(e){var t=e.getMin(),r=e.getMax(),n=Math.floor(t[0]),i=Math.floor(t[1]);return{x:n,y:i,width:Math.ceil(r[0])-n,height:Math.ceil(r[1])-i}},n.mergeDirtyAABBs=function(e){var r=new t.AABB;return e.forEach((function(e){var t=e.getRenderBounds();r.add(t);var n=e.renderable.dirtyRenderBounds;n&&r.add(n)})),r},n.searchDirtyObjects=function(e){var t=this,r=e.getMin(),n=r[0],i=r[1],o=e.getMax();return this.rBush.search({minX:n,minY:i,maxX:o[0],maxY:o[1]}).map((function(e){return t.displayObjectPool.getByEntity(e.id)}))},n.saveDirtyAABB=function(e){var r=e.renderable;r.dirtyRenderBounds||(r.dirtyRenderBounds=new t.AABB);var n=e.getRenderBounds();n&&r.dirtyRenderBounds.update(n.center,n.halfExtents)},n.applyAttributesToContext=function(e,r){var n=r.parsedStyle,i=n.stroke,o=n.fill,a=n.opacity,c=n.lineDash,s=n.lineDashOffset;c&&Array.isArray(c)&&e.setLineDash(c.map((function(e){return e.value}))),t.isNil(s)||(e.lineDashOffset=s.value),t.isNil(a)||(e.globalAlpha*=a.value),t.isNil(i)||Array.isArray(i)||i.isNone||(e.strokeStyle=r.attributes.stroke),t.isNil(o)||Array.isArray(o)||o.isNone||(e.fillStyle=r.attributes.fill)},n.applyWorldTransform=function(e,t,r){var n=0,i=0,o=(t.parsedStyle||{}).anchor,a=o&&o[0].value||0,c=o&&o[1].value||0;if(0!==a||0!==c){var s=t.getGeometryBounds();n=-a*(s&&2*s.halfExtents[0]||0),i=-c*(s&&2*s.halfExtents[1]||0)}r?(b(this.tmpMat4,t.getLocalTransform()),this.tmpVec3[0]=n,this.tmpVec3[1]=i,this.tmpVec3[2]=0,E(this.tmpMat4,this.tmpMat4,this.tmpVec3),R(this.tmpMat4,r,this.tmpMat4),R(this.tmpMat4,this.vpMatrix,this.tmpMat4)):(b(this.tmpMat4,t.getWorldTransform()),this.tmpVec3[0]=n,this.tmpVec3[1]=i,this.tmpVec3[2]=0,E(this.tmpMat4,this.tmpMat4,this.tmpVec3),R(this.tmpMat4,this.vpMatrix,this.tmpMat4)),e.setTransform(this.tmpMat4[0],this.tmpMat4[1],this.tmpMat4[4],this.tmpMat4[5],this.tmpMat4[12],this.tmpMat4[13])},n.safeMergeAABB=function(){for(var e=new t.AABB,r=arguments.length,n=new Array(r),i=0;r>i;i++)n[i]=arguments[i];return n.forEach((function(t){e.add(t)})),e},e}(),Q.tag="CanvasRenderer",H=Q);s([t.inject(t.CanvasConfig),l("design:type",Object)],K.prototype,"canvasConfig",void 0),s([t.inject(t.DefaultCamera),l("design:type",t.Camera)],K.prototype,"camera",void 0),s([t.inject(t.ContextService),l("design:type",Object)],K.prototype,"contextService",void 0),s([t.inject(t.RenderingContext),l("design:type",Object)],K.prototype,"renderingContext",void 0),s([t.inject(u),l("design:type",Function)],K.prototype,"pathGeneratorFactory",void 0),s([t.inject(O),l("design:type",Function)],K.prototype,"styleRendererFactory",void 0),s([t.inject(t.DisplayObjectPool),l("design:type",t.DisplayObjectPool)],K.prototype,"displayObjectPool",void 0),s([t.inject(J),l("design:type",Object)],K.prototype,"canvasRendererPluginOptions",void 0),s([t.inject(t.RBushRoot),l("design:type",t.RBush)],K.prototype,"rBush",void 0),K=H=s([t.singleton({contrib:t.RenderingPluginContribution})],K);var q=t.Module((function(r){var n;r(e.CircleRenderer),r(e.EllipseRenderer),r(e.RectRenderer),r(e.ImageRenderer),r(e.TextRenderer),r(e.LineRenderer),r(e.PolylineRenderer),r(e.PolygonRenderer),r(e.PathRenderer);var i=((n={})[t.Shape.CIRCLE]=T,n[t.Shape.ELLIPSE]=k,n[t.Shape.RECT]=A,n[t.Shape.IMAGE]=G,n[t.Shape.TEXT]=I,n[t.Shape.LINE]=M,n[t.Shape.POLYLINE]=N,n[t.Shape.POLYGON]=j,n[t.Shape.PATH]=B,n);r({token:O,useFactory:function(e){return function(t){var r=i[t];return r&&e.container.isBound(r)?e.container.get(r):null}}}),r(K)})),z=function(e){function t(t){var r;return void 0===t&&(t={}),(r=e.call(this)||this).options=void 0,r.name="canvas-renderer",r.options=t,r}a(t,e);var r=t.prototype;return r.init=function(){this.container.register(J,{useValue:o({dirtyObjectNumThreshold:500,dirtyObjectRatioThreshold:.8},this.options)}),this.container.load(q,!0)},r.destroy=function(){this.container.unload(q),this.container.remove(J)},t}(t.AbstractRendererPlugin);e.CircleRendererContribution=T,e.EllipseRendererContribution=k,e.ImageRendererContribution=G,e.LineRendererContribution=M,e.PathRendererContribution=B,e.Plugin=z,e.PolygonRendererContribution=j,e.PolylineRendererContribution=N,e.RectRendererContribution=A,e.StyleRendererFactory=O,e.TextRendererContribution=I,Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "@antv/g-plugin-canvas-renderer", | ||
"version": "1.6.1", | ||
"version": "1.6.2", | ||
"description": "A G plugin of renderer implementation with Canvas2D API", | ||
@@ -30,5 +30,5 @@ "keywords": [ | ||
"dependencies": { | ||
"@antv/g-math": "^1.6.0", | ||
"@antv/g-plugin-canvas-path-generator": "^1.0.1", | ||
"@antv/g-plugin-image-loader": "^1.0.1", | ||
"@antv/g-math": "^1.6.1", | ||
"@antv/g-plugin-canvas-path-generator": "^1.0.2", | ||
"@antv/g-plugin-image-loader": "^1.0.2", | ||
"tslib": "^2.3.1" | ||
@@ -45,3 +45,3 @@ }, | ||
}, | ||
"gitHead": "200fd2696d8e94946e7ad095288dffd437e37334" | ||
"gitHead": "cc3e4646317ec49518138205c8d53daa6f3f1229" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
266854
5636