@antv/g-plugin-canvas-renderer
Advanced tools
Comparing version 1.9.13 to 1.9.14
@@ -78,9 +78,8 @@ import { __spreadArray, __read, __assign, __extends } from 'tslib'; | ||
renderingService.hooks.beginFrame.tap(CanvasRendererPlugin.tag, function () { | ||
var _a, _b; | ||
var context = contextService.getContext(); | ||
var dpr = contextService.getDPR(); | ||
var width = config.width, height = config.height; | ||
var dirtyObjectNumThreshold = (_a = _this.canvasRendererPluginOptions, _a.dirtyObjectNumThreshold), dirtyObjectRatioThreshold = _a.dirtyObjectRatioThreshold; | ||
var _a = _this.canvasRendererPluginOptions, dirtyObjectNumThreshold = _a.dirtyObjectNumThreshold, dirtyObjectRatioThreshold = _a.dirtyObjectRatioThreshold; | ||
// some heuristic conditions such as 80% object changed | ||
var total = (_b = renderingService.getStats(), _b.total), rendered = _b.rendered; | ||
var _b = renderingService.getStats(), total = _b.total, rendered = _b.rendered; | ||
var ratio = rendered / total; | ||
@@ -277,6 +276,7 @@ _this.clearFullScreen = | ||
// @see https://www.yuque.com/antv/ou292n/bi8nix#ExvCu | ||
var minX = Math.floor(min[0]); | ||
var minY = Math.floor(min[1]); | ||
var maxX = Math.ceil(max[0]); | ||
var maxY = Math.ceil(max[1]); | ||
var padding = 2; | ||
var minX = Math.floor(min[0]) - padding; | ||
var minY = Math.floor(min[1]) - padding; | ||
var maxX = Math.ceil(max[0]) + padding; | ||
var maxY = Math.ceil(max[1]) + padding; | ||
var width = maxX - minX; | ||
@@ -306,6 +306,5 @@ var height = maxY - minY; | ||
CanvasRendererPlugin.prototype.searchDirtyObjects = function (dirtyRectangle) { | ||
var _a, _b; | ||
// search in r-tree, get all affected nodes | ||
var minX = (_a = __read(dirtyRectangle.getMin(), 2), _a[0]), minY = _a[1]; | ||
var maxX = (_b = __read(dirtyRectangle.getMax(), 2), _b[0]), maxY = _b[1]; | ||
var _a = __read(dirtyRectangle.getMin(), 2), minX = _a[0], minY = _a[1]; | ||
var _b = __read(dirtyRectangle.getMax(), 2), maxX = _b[0], maxY = _b[1]; | ||
var rBushNodes = this.rBush.search({ | ||
@@ -337,4 +336,3 @@ minX: minX, | ||
CanvasRendererPlugin.prototype.applyAttributesToContext = function (context, object) { | ||
var _a; | ||
var stroke = (_a = object.parsedStyle, _a.stroke), fill = _a.fill, opacity = _a.opacity, lineDash = _a.lineDash, lineDashOffset = _a.lineDashOffset; | ||
var _a = object.parsedStyle, stroke = _a.stroke, fill = _a.fill, opacity = _a.opacity, lineDash = _a.lineDash, lineDashOffset = _a.lineDashOffset; | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash | ||
@@ -341,0 +339,0 @@ if (lineDash) { |
@@ -80,9 +80,8 @@ 'use strict'; | ||
renderingService.hooks.beginFrame.tap(CanvasRendererPlugin.tag, function () { | ||
var _a, _b; | ||
var context = contextService.getContext(); | ||
var dpr = contextService.getDPR(); | ||
var width = config.width, height = config.height; | ||
var dirtyObjectNumThreshold = (_a = _this.canvasRendererPluginOptions, _a.dirtyObjectNumThreshold), dirtyObjectRatioThreshold = _a.dirtyObjectRatioThreshold; | ||
var _a = _this.canvasRendererPluginOptions, dirtyObjectNumThreshold = _a.dirtyObjectNumThreshold, dirtyObjectRatioThreshold = _a.dirtyObjectRatioThreshold; | ||
// some heuristic conditions such as 80% object changed | ||
var total = (_b = renderingService.getStats(), _b.total), rendered = _b.rendered; | ||
var _b = renderingService.getStats(), total = _b.total, rendered = _b.rendered; | ||
var ratio = rendered / total; | ||
@@ -279,6 +278,7 @@ _this.clearFullScreen = | ||
// @see https://www.yuque.com/antv/ou292n/bi8nix#ExvCu | ||
var minX = Math.floor(min[0]); | ||
var minY = Math.floor(min[1]); | ||
var maxX = Math.ceil(max[0]); | ||
var maxY = Math.ceil(max[1]); | ||
var padding = 2; | ||
var minX = Math.floor(min[0]) - padding; | ||
var minY = Math.floor(min[1]) - padding; | ||
var maxX = Math.ceil(max[0]) + padding; | ||
var maxY = Math.ceil(max[1]) + padding; | ||
var width = maxX - minX; | ||
@@ -308,6 +308,5 @@ var height = maxY - minY; | ||
CanvasRendererPlugin.prototype.searchDirtyObjects = function (dirtyRectangle) { | ||
var _a, _b; | ||
// search in r-tree, get all affected nodes | ||
var minX = (_a = tslib.__read(dirtyRectangle.getMin(), 2), _a[0]), minY = _a[1]; | ||
var maxX = (_b = tslib.__read(dirtyRectangle.getMax(), 2), _b[0]), maxY = _b[1]; | ||
var _a = tslib.__read(dirtyRectangle.getMin(), 2), minX = _a[0], minY = _a[1]; | ||
var _b = tslib.__read(dirtyRectangle.getMax(), 2), maxX = _b[0], maxY = _b[1]; | ||
var rBushNodes = this.rBush.search({ | ||
@@ -339,4 +338,3 @@ minX: minX, | ||
CanvasRendererPlugin.prototype.applyAttributesToContext = function (context, object) { | ||
var _a; | ||
var stroke = (_a = object.parsedStyle, _a.stroke), fill = _a.fill, opacity = _a.opacity, lineDash = _a.lineDash, lineDashOffset = _a.lineDashOffset; | ||
var _a = object.parsedStyle, stroke = _a.stroke, fill = _a.fill, opacity = _a.opacity, lineDash = _a.lineDash, lineDashOffset = _a.lineDashOffset; | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash | ||
@@ -343,0 +341,0 @@ if (lineDash) { |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/g-lite")):"function"==typeof define&&define.amd?define(["exports","@antv/g-lite"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).G=t.G||{},t.G.CanvasRenderer={}),t.window.G)}(this,(function(t,e){"use strict";var r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},r(t,e)};function n(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+e+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var i=function(){return i=Object.assign||function(t){for(var e,r=1,n=arguments.length;n>r;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},i.apply(this,arguments)};function a(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,a=r.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(n=a.next()).done;)o.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=a.return)&&r.call(a)}finally{if(i)throw i.error}}return o}var o="undefined"!=typeof Float32Array?Float32Array:Array;function s(){var t=new o(16);return o!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function l(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function h(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],l=e[5],h=e[6],c=e[7],p=e[8],d=e[9],u=e[10],f=e[11],y=e[12],v=e[13],g=e[14],m=e[15],A=r[0],x=r[1],b=r[2],S=r[3];return t[0]=A*n+x*s+b*p+S*y,t[1]=A*i+x*l+b*d+S*v,t[2]=A*a+x*h+b*u+S*g,t[3]=A*o+x*c+b*f+S*m,t[4]=(A=r[4])*n+(x=r[5])*s+(b=r[6])*p+(S=r[7])*y,t[5]=A*i+x*l+b*d+S*v,t[6]=A*a+x*h+b*u+S*g,t[7]=A*o+x*c+b*f+S*m,t[8]=(A=r[8])*n+(x=r[9])*s+(b=r[10])*p+(S=r[11])*y,t[9]=A*i+x*l+b*d+S*v,t[10]=A*a+x*h+b*u+S*g,t[11]=A*o+x*c+b*f+S*m,t[12]=(A=r[12])*n+(x=r[13])*s+(b=r[14])*p+(S=r[15])*y,t[13]=A*i+x*l+b*d+S*v,t[14]=A*a+x*h+b*u+S*g,t[15]=A*o+x*c+b*f+S*m,t}function c(t,e,r){var n,i,a,o,s,l,h,c,p,d,u,f,y=r[0],v=r[1],g=r[2];return e===t?(t[12]=e[0]*y+e[4]*v+e[8]*g+e[12],t[13]=e[1]*y+e[5]*v+e[9]*g+e[13],t[14]=e[2]*y+e[6]*v+e[10]*g+e[14],t[15]=e[3]*y+e[7]*v+e[11]*g+e[15]):(i=e[1],a=e[2],o=e[3],s=e[4],l=e[5],h=e[6],c=e[7],p=e[8],d=e[9],u=e[10],f=e[11],t[0]=n=e[0],t[1]=i,t[2]=a,t[3]=o,t[4]=s,t[5]=l,t[6]=h,t[7]=c,t[8]=p,t[9]=d,t[10]=u,t[11]=f,t[12]=n*y+s*v+p*g+e[12],t[13]=i*y+l*v+d*g+e[13],t[14]=a*y+h*v+u*g+e[14],t[15]=o*y+c*v+f*g+e[15]),t}function p(){var t=new o(3);return o!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function d(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[3]*n+r[7]*i+r[11]*a+r[15];return t[0]=(r[0]*n+r[4]*i+r[8]*a+r[12])/(o=o||1),t[1]=(r[1]*n+r[5]*i+r[9]*a+r[13])/o,t[2]=(r[2]*n+r[6]*i+r[10]*a+r[14])/o,t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)}),p();var u=function(t){return null==t},f={}.toString,y=function(t,e){return f.call(t)==="[object "+e+"]"},v=function(){function t(t){this.canvasRendererPluginOptions=t,this.removedRBushNodeAABBs=[],this.renderQueue=[],this.restoreStack=[],this.clearFullScreen=!1,this.vpMatrix=s(),this.dprMatrix=s(),this.tmpMat4=s(),this.vec3a=p(),this.vec3b=p(),this.vec3c=p(),this.vec3d=p()}return t.prototype.apply=function(r,n){var i=this;this.context=r;var o=r.config,s=r.camera,l=r.renderingService,c=r.renderingContext,p=r.pathGeneratorFactory;this.rBush=r.rBushRoot,this.pathGeneratorFactory=p;var u=r.contextService,f=c.root.ownerDocument.defaultView,y=function(t){var e=t.target.rBushNode;e.aabb&&i.removedRBushNodeAABBs.push(e.aabb)},v=function(t){var e=t.target.rBushNode;e.aabb&&i.removedRBushNodeAABBs.push(e.aabb)};l.hooks.init.tap(t.tag,(function(){f.addEventListener(e.ElementEvent.UNMOUNTED,y),f.addEventListener(e.ElementEvent.CULLED,v);var t=u.getDPR(),r=o.width,n=o.height,a=u.getContext();i.clearRect(a,0,0,r*t,n*t,o.background)})),l.hooks.destroy.tap(t.tag,(function(){f.removeEventListener(e.ElementEvent.UNMOUNTED,y),f.removeEventListener(e.ElementEvent.CULLED,v),i.renderQueue=[],i.removedRBushNodeAABBs=[],i.restoreStack=[]})),l.hooks.beginFrame.tap(t.tag,(function(){var t,e,r=u.getContext(),n=u.getDPR(),a=o.width,s=o.height,h=(t=i.canvasRendererPluginOptions).dirtyObjectNumThreshold,c=t.dirtyObjectRatioThreshold,p=(e=l.getStats()).total,d=e.rendered,f=d/p;i.clearFullScreen=l.disableDirtyRectangleRendering()||d>h&&f>c,r&&(r.resetTransform?r.resetTransform():r.setTransform(1,0,0,1,0,0),i.clearFullScreen&&i.clearRect(r,0,0,a*n,s*n,o.background))}));var g=function(t,e){t.isVisible()&&!t.isCulled()&&(i.renderDisplayObject(t,e,i.context,i.restoreStack,n),i.saveDirtyAABB(t)),(t.sortable.sorted||t.childNodes).forEach((function(t){g(t,e)}))};l.hooks.endFrame.tap(t.tag,(function(){var t,r,l=u.getContext(),p=u.getDPR();if((t=i.dprMatrix)[0]=(r=[p,p,1])[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=r[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=r[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,h(i.vpMatrix,i.dprMatrix,s.getOrthoMatrix()),i.clearFullScreen)g(c.root,l);else{var y=i.safeMergeAABB.apply(i,function(t,e,r){if(r||2===arguments.length)for(var n,i=0,a=e.length;a>i;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}([i.mergeDirtyAABBs(i.renderQueue)],a(i.removedRBushNodeAABBs.map((function(t){var r=t.minX,n=t.minY,i=t.maxX,a=t.maxY,o=new e.AABB;return o.setMinMax([r,n,0],[i,a,0]),o}))),!1));if(i.removedRBushNodeAABBs=[],e.AABB.isEmpty(y))return void(i.renderQueue=[]);var v=i.convertAABB2Rect(y),m=v.x,A=v.y,x=v.width,b=v.height,S=d(i.vec3a,[m,A,0],i.vpMatrix),B=d(i.vec3b,[m+x,A,0],i.vpMatrix),M=d(i.vec3c,[m,A+b,0],i.vpMatrix),w=d(i.vec3d,[m+x,A+b,0],i.vpMatrix),R=Math.min(S[0],B[0],w[0],M[0]),E=Math.min(S[1],B[1],w[1],M[1]),O=Math.max(S[0],B[0],w[0],M[0]),C=Math.max(S[1],B[1],w[1],M[1]),T=Math.floor(R),P=Math.floor(E),N=Math.ceil(O-R),L=Math.ceil(C-E);l.save(),i.clearRect(l,T,P,N,L,o.background),l.beginPath(),l.rect(T,P,N,L),l.clip(),l.setTransform(i.vpMatrix[0],i.vpMatrix[1],i.vpMatrix[4],i.vpMatrix[5],i.vpMatrix[12],i.vpMatrix[13]),o.renderer.getConfig().enableDirtyRectangleRenderingDebug&&f.dispatchEvent(new e.CustomEvent(e.CanvasEvent.DIRTY_RECTANGLE,{dirtyRect:{x:T,y:P,width:N,height:L}})),i.searchDirtyObjects(y).sort((function(t,e){return t.sortable.renderOrder-e.sortable.renderOrder})).forEach((function(t){t&&t.isVisible()&&!t.isCulled()&&i.renderDisplayObject(t,l,i.context,i.restoreStack,n)})),l.restore(),i.renderQueue.forEach((function(t){i.saveDirtyAABB(t)})),i.renderQueue=[]}i.restoreStack.forEach((function(){l.restore()})),i.restoreStack=[]})),l.hooks.render.tap(t.tag,(function(t){i.clearFullScreen||i.renderQueue.push(t)}))},t.prototype.clearRect=function(t,e,r,n,i,a){t.clearRect(e,r,n,i),a&&(t.fillStyle=a,t.fillRect(e,r,n,i))},t.prototype.renderDisplayObject=function(t,r,n,i,a){var o=t.nodeName,s=i[i.length-1];!s||t.compareDocumentPosition(s)&Node.DOCUMENT_POSITION_CONTAINS||(r.restore(),i.pop());var l=this.context.styleRendererFactory[o],h=this.pathGeneratorFactory[o],c=t.parsedStyle.clipPath;if(c){this.applyWorldTransform(r,c);var p=this.pathGeneratorFactory[c.nodeName];p&&(r.save(),i.push(t),r.beginPath(),p(r,c.parsedStyle),r.closePath(),r.clip())}l&&(this.applyWorldTransform(r,t),r.save(),this.applyAttributesToContext(r,t)),h&&(r.beginPath(),h(r,t.parsedStyle),t.nodeName!==e.Shape.LINE&&t.nodeName!==e.Shape.PATH&&t.nodeName!==e.Shape.POLYLINE&&r.closePath()),l&&(l.render(r,t.parsedStyle,t,n,this,a),r.restore()),t.renderable.dirty=!1},t.prototype.convertAABB2Rect=function(t){var e=t.getMin(),r=t.getMax(),n=Math.floor(e[0]),i=Math.floor(e[1]);return{x:n,y:i,width:Math.ceil(r[0])-n,height:Math.ceil(r[1])-i}},t.prototype.mergeDirtyAABBs=function(t){var r=new e.AABB;return t.forEach((function(t){var e=t.getRenderBounds();r.add(e);var n=t.renderable.dirtyRenderBounds;n&&r.add(n)})),r},t.prototype.searchDirtyObjects=function(t){var e,r,n=(e=a(t.getMin(),2))[0],i=e[1],o=(r=a(t.getMax(),2))[0];return this.rBush.search({minX:n,minY:i,maxX:o,maxY:r[1]}).map((function(t){return t.displayObject}))},t.prototype.saveDirtyAABB=function(t){var r=t.renderable;r.dirtyRenderBounds||(r.dirtyRenderBounds=new e.AABB);var n=t.getRenderBounds();n&&r.dirtyRenderBounds.update(n.center,n.halfExtents)},t.prototype.applyAttributesToContext=function(t,e){var r,n=(r=e.parsedStyle).stroke,i=r.fill,a=r.opacity,o=r.lineDash,s=r.lineDashOffset;o&&t.setLineDash(o),u(s)||(t.lineDashOffset=s),u(a)||(t.globalAlpha*=a),u(n)||Array.isArray(n)||n.isNone||(t.strokeStyle=e.attributes.stroke),u(i)||Array.isArray(i)||i.isNone||(t.fillStyle=e.attributes.fill)},t.prototype.applyWorldTransform=function(t,e,r){var n=0,i=0,a=(e.parsedStyle||{}).anchor,o=a&&a[0]||0,s=a&&a[1]||0;if(0!==o||0!==s){var p=e.geometry.contentBounds;n=-o*(p&&2*p.halfExtents[0]||0),i=-s*(p&&2*p.halfExtents[1]||0)}r?(l(this.tmpMat4,e.getLocalTransform()),this.vec3a[0]=n,this.vec3a[1]=i,this.vec3a[2]=0,c(this.tmpMat4,this.tmpMat4,this.vec3a),h(this.tmpMat4,r,this.tmpMat4),h(this.tmpMat4,this.vpMatrix,this.tmpMat4)):(l(this.tmpMat4,e.getWorldTransform()),this.vec3a[0]=n,this.vec3a[1]=i,this.vec3a[2]=0,c(this.tmpMat4,this.tmpMat4,this.vec3a),h(this.tmpMat4,this.vpMatrix,this.tmpMat4)),t.setTransform(this.tmpMat4[0],this.tmpMat4[1],this.tmpMat4[4],this.tmpMat4[5],this.tmpMat4[12],this.tmpMat4[13])},t.prototype.safeMergeAABB=function(){for(var t=[],r=0;arguments.length>r;r++)t[r]=arguments[r];var n=new e.AABB;return t.forEach((function(t){n.add(t)})),n},t.tag="CanvasRenderer",t}(),g=function(){function t(t){this.imagePool=t}return t.prototype.render=function(t,r,n,i,a,o){var s=r.fill,l=r.fillRule,h=r.opacity,c=r.fillOpacity,p=r.stroke,d=r.strokeOpacity,f=r.lineWidth,y=r.lineCap,v=r.lineJoin,g=r.shadowType,A=r.shadowColor,x=r.shadowBlur,b=r.filter,S=r.miterLimit,B=!u(s)&&!s.isNone,M=!u(p)&&!p.isNone&&f>0,w=0===s.alpha,R=!(!b||!b.length),E=!u(A)&&x>0,O=n.nodeName,C="inner"===g,T=M&&E&&(O===e.Shape.PATH||O===e.Shape.LINE||O===e.Shape.POLYLINE||w||C);B&&(t.globalAlpha=h*c,T||m(n,t,E),this.fill(t,n,s,l,i,a,o),T||this.clearShadowAndFilter(t,R,E)),M&&(t.globalAlpha=h*d,t.lineWidth=f,u(S)||(t.miterLimit=S),u(y)||(t.lineCap=y),u(v)||(t.lineJoin=v),T&&(C&&(t.globalCompositeOperation="source-atop"),m(n,t,!0),C&&(this.stroke(t,n,p,i,a,o),t.globalCompositeOperation="source-over",this.clearShadowAndFilter(t,R,!0))),this.stroke(t,n,p,i,a,o))},t.prototype.clearShadowAndFilter=function(t,e,r){if(r&&(t.shadowColor="transparent",t.shadowBlur=0),e){var n=t.filter;!u(n)&&n.indexOf("drop-shadow")>-1&&(t.filter=n.replace(/drop-shadow\([^)]*\)/,"").trim()||"none")}},t.prototype.fill=function(t,r,n,i,a,o,s){var l=this;Array.isArray(n)?n.forEach((function(e){t.fillStyle=l.getColor(e,r,t),i?t.fill(i):t.fill()})):(e.isPattern(n)&&(t.fillStyle=this.getPattern(n,r,t,a,o,s)),i?t.fill(i):t.fill())},t.prototype.stroke=function(t,r,n,i,a,o){var s=this;Array.isArray(n)?n.forEach((function(e){t.strokeStyle=s.getColor(e,r,t),t.stroke()})):(e.isPattern(n)&&(t.strokeStyle=this.getPattern(n,r,t,i,a,o)),t.stroke())},t.prototype.getPattern=function(t,e,r,n,i,a){var o,s;if("rect"===t.image.nodeName){var l=t.image.parsedStyle,h=l.width,c=l.height;s=n.contextService.getDPR();var p=n.config.offscreenCanvas;(o=a.offscreenCanvasCreator.getOrCreateCanvas(p)).width=h*s,o.height=c*s;var d=a.offscreenCanvasCreator.getOrCreateContext(p),u=[];t.image.forEach((function(t){i.renderDisplayObject(t,d,n,u,a)})),u.forEach((function(){d.restore()}))}return this.imagePool.getOrCreatePatternSync(t,r,o,s,(function(){e.renderable.dirty=!0,n.renderingService.dirtify()}))},t.prototype.getColor=function(t,r,n){var a;if(t.type===e.GradientType.LinearGradient||t.type===e.GradientType.RadialGradient){var o=r.getGeometryBounds(),s=o&&2*o.halfExtents[0]||1,l=o&&2*o.halfExtents[1]||1;a=this.imagePool.getOrCreateGradient(i(i({type:t.type},t.value),{width:s,height:l}),n)}return a},t}();function m(t,e,r){var n=t.parsedStyle,i=n.filter,a=n.shadowColor,o=n.shadowBlur,s=n.shadowOffsetX,l=n.shadowOffsetY;i&&i.length&&(e.filter=t.style.filter),r&&(e.shadowColor=""+a,e.shadowBlur=o||0,e.shadowOffsetX=s||0,e.shadowOffsetY=l||0)}var A=function(){function t(t){this.imagePool=t}return t.prototype.render=function(t,e,r){var n,i=e.img,a=e.shadowColor,o=e.shadowBlur,s=e.width,l=e.height;if(y(i,"String")?n=this.imagePool.getImageSync(i):(s||(s=i.width),l||(l=i.height),n=i),n){m(r,t,!u(a)&&o>0);try{t.drawImage(n,0,0,s,l)}catch(t){}}},t}(),x=function(){function t(){}return t.prototype.render=function(t,e,r,n,i,a){var o=e.lineWidth,s=e.textAlign,l=e.textBaseline,h=e.lineJoin,c=e.miterLimit,p=e.letterSpacing,d=e.stroke,f=e.fill,y=e.fillOpacity,v=e.strokeOpacity,g=e.opacity,A=e.metrics,x=e.dx,b=e.dy,S=e.shadowColor,B=e.shadowBlur,M=A.lines,w=A.height,R=A.lineHeight,E=A.lineMetrics;t.font=A.font,t.lineWidth=o,t.textAlign="middle"===s?"center":s;var O=l;a.enableCSSParsing||"alphabetic"!==O||(O="bottom"),t.lineJoin=h,u(c)||(t.miterLimit=c);var C=0;"middle"===l?C=-w/2-R/2:"bottom"===l||"alphabetic"===l||"ideographic"===l?C=-w:"top"!==l&&"hanging"!==l||(C=-R);var T=x||0;C+=b||0,1===M.length&&("bottom"===O?(O="middle",C-=.5*w):"top"===O&&(O="middle",C+=.5*w)),t.textBaseline=O,m(r,t,!u(S)&&B>0);for(var P=0;M.length>P;P++){var N=o/2+T;C+=R,u(d)||d.isNone||!o||this.drawLetterSpacing(t,M[P],E[P],s,N,C,p,y,v,g,!0),u(f)||this.drawLetterSpacing(t,M[P],E[P],s,N,C,p,y,v,g)}},t.prototype.drawLetterSpacing=function(t,e,r,n,i,a,o,s,l,h,c){if(void 0===c&&(c=!1),0!==o){var p=t.textAlign;t.textAlign="left";var d=i;"center"===n||"middle"===n?d=i-r.width/2:"right"!==n&&"end"!==n||(d=i-r.width);for(var u=Array.from(e),f=t.measureText(e).width,y=0,v=0;u.length>v;++v){var g=u[v];c?this.strokeText(t,g,d,a,l):this.fillText(t,g,d,a,s,h),d+=f-(y=t.measureText(e.substring(v+1)).width)+o,f=y}t.textAlign=p}else c?this.strokeText(t,e,i,a,l):this.fillText(t,e,i,a,s,h)},t.prototype.fillText=function(t,e,r,n,i,a){var o,s=!u(i)&&1!==i;s&&(o=t.globalAlpha,t.globalAlpha=i*a),t.fillText(e,r,n),s&&(t.globalAlpha=o)},t.prototype.strokeText=function(t,e,r,n,i){var a,o=!u(i)&&1!==i;o&&(a=t.globalAlpha,t.globalAlpha=i),t.strokeText(e,r,n),o&&(t.globalAlpha=a)},t}(),b=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e}(g),S=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e}(g),B=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e}(g),M=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e}(g),w=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e}(g),R=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e}(g),E=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e}(g),O=function(t){function r(e){void 0===e&&(e={});var r=t.call(this)||this;return r.options=e,r.name="canvas-renderer",r}return n(r,t),r.prototype.init=function(){var t,r=i({dirtyObjectNumThreshold:500,dirtyObjectRatioThreshold:.8},this.options),n=this.context.imagePool,a=new g(n),o=((t={})[e.Shape.CIRCLE]=a,t[e.Shape.ELLIPSE]=a,t[e.Shape.RECT]=a,t[e.Shape.IMAGE]=new A(n),t[e.Shape.TEXT]=new x,t[e.Shape.LINE]=a,t[e.Shape.POLYLINE]=a,t[e.Shape.POLYGON]=a,t[e.Shape.PATH]=a,t[e.Shape.GROUP]=void 0,t[e.Shape.HTML]=void 0,t[e.Shape.MESH]=void 0,t);this.context.defaultStyleRendererFactory=o,this.context.styleRendererFactory=o,this.addRenderingPlugin(new v(r))},r.prototype.destroy=function(){this.removeAllRenderingPlugins(),delete this.context.defaultStyleRendererFactory,delete this.context.styleRendererFactory},r}(e.AbstractRendererPlugin);t.CircleRenderer=S,t.EllipseRenderer=B,t.ImageRenderer=A,t.LineRenderer=M,t.PathRenderer=E,t.Plugin=O,t.PolygonRenderer=R,t.PolylineRenderer=w,t.RectRenderer=b,t.TextRenderer=x})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/g-lite")):"function"==typeof define&&define.amd?define(["exports","@antv/g-lite"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).G=t.G||{},t.G.CanvasRenderer={}),t.window.G)}(this,(function(t,e){"use strict";var r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},r(t,e)};function n(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+e+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var i=function(){return i=Object.assign||function(t){for(var e,r=1,n=arguments.length;n>r;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},i.apply(this,arguments)};function a(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,a=r.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(n=a.next()).done;)o.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=a.return)&&r.call(a)}finally{if(i)throw i.error}}return o}var o="undefined"!=typeof Float32Array?Float32Array:Array;function s(){var t=new o(16);return o!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function l(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function h(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],l=e[5],h=e[6],c=e[7],p=e[8],d=e[9],u=e[10],f=e[11],y=e[12],v=e[13],g=e[14],m=e[15],A=r[0],x=r[1],b=r[2],S=r[3];return t[0]=A*n+x*s+b*p+S*y,t[1]=A*i+x*l+b*d+S*v,t[2]=A*a+x*h+b*u+S*g,t[3]=A*o+x*c+b*f+S*m,t[4]=(A=r[4])*n+(x=r[5])*s+(b=r[6])*p+(S=r[7])*y,t[5]=A*i+x*l+b*d+S*v,t[6]=A*a+x*h+b*u+S*g,t[7]=A*o+x*c+b*f+S*m,t[8]=(A=r[8])*n+(x=r[9])*s+(b=r[10])*p+(S=r[11])*y,t[9]=A*i+x*l+b*d+S*v,t[10]=A*a+x*h+b*u+S*g,t[11]=A*o+x*c+b*f+S*m,t[12]=(A=r[12])*n+(x=r[13])*s+(b=r[14])*p+(S=r[15])*y,t[13]=A*i+x*l+b*d+S*v,t[14]=A*a+x*h+b*u+S*g,t[15]=A*o+x*c+b*f+S*m,t}function c(t,e,r){var n,i,a,o,s,l,h,c,p,d,u,f,y=r[0],v=r[1],g=r[2];return e===t?(t[12]=e[0]*y+e[4]*v+e[8]*g+e[12],t[13]=e[1]*y+e[5]*v+e[9]*g+e[13],t[14]=e[2]*y+e[6]*v+e[10]*g+e[14],t[15]=e[3]*y+e[7]*v+e[11]*g+e[15]):(i=e[1],a=e[2],o=e[3],s=e[4],l=e[5],h=e[6],c=e[7],p=e[8],d=e[9],u=e[10],f=e[11],t[0]=n=e[0],t[1]=i,t[2]=a,t[3]=o,t[4]=s,t[5]=l,t[6]=h,t[7]=c,t[8]=p,t[9]=d,t[10]=u,t[11]=f,t[12]=n*y+s*v+p*g+e[12],t[13]=i*y+l*v+d*g+e[13],t[14]=a*y+h*v+u*g+e[14],t[15]=o*y+c*v+f*g+e[15]),t}function p(){var t=new o(3);return o!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function d(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[3]*n+r[7]*i+r[11]*a+r[15];return t[0]=(r[0]*n+r[4]*i+r[8]*a+r[12])/(o=o||1),t[1]=(r[1]*n+r[5]*i+r[9]*a+r[13])/o,t[2]=(r[2]*n+r[6]*i+r[10]*a+r[14])/o,t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)}),p();var u=function(t){return null==t},f={}.toString,y=function(t,e){return f.call(t)==="[object "+e+"]"},v=function(){function t(t){this.canvasRendererPluginOptions=t,this.removedRBushNodeAABBs=[],this.renderQueue=[],this.restoreStack=[],this.clearFullScreen=!1,this.vpMatrix=s(),this.dprMatrix=s(),this.tmpMat4=s(),this.vec3a=p(),this.vec3b=p(),this.vec3c=p(),this.vec3d=p()}return t.prototype.apply=function(r,n){var i=this;this.context=r;var o=r.config,s=r.camera,l=r.renderingService,c=r.renderingContext,p=r.pathGeneratorFactory;this.rBush=r.rBushRoot,this.pathGeneratorFactory=p;var u=r.contextService,f=c.root.ownerDocument.defaultView,y=function(t){var e=t.target.rBushNode;e.aabb&&i.removedRBushNodeAABBs.push(e.aabb)},v=function(t){var e=t.target.rBushNode;e.aabb&&i.removedRBushNodeAABBs.push(e.aabb)};l.hooks.init.tap(t.tag,(function(){f.addEventListener(e.ElementEvent.UNMOUNTED,y),f.addEventListener(e.ElementEvent.CULLED,v);var t=u.getDPR(),r=o.width,n=o.height,a=u.getContext();i.clearRect(a,0,0,r*t,n*t,o.background)})),l.hooks.destroy.tap(t.tag,(function(){f.removeEventListener(e.ElementEvent.UNMOUNTED,y),f.removeEventListener(e.ElementEvent.CULLED,v),i.renderQueue=[],i.removedRBushNodeAABBs=[],i.restoreStack=[]})),l.hooks.beginFrame.tap(t.tag,(function(){var t=u.getContext(),e=u.getDPR(),r=o.width,n=o.height,a=i.canvasRendererPluginOptions,s=a.dirtyObjectNumThreshold,h=a.dirtyObjectRatioThreshold,c=l.getStats(),p=c.rendered,d=p/c.total;i.clearFullScreen=l.disableDirtyRectangleRendering()||p>s&&d>h,t&&(t.resetTransform?t.resetTransform():t.setTransform(1,0,0,1,0,0),i.clearFullScreen&&i.clearRect(t,0,0,r*e,n*e,o.background))}));var g=function(t,e){t.isVisible()&&!t.isCulled()&&(i.renderDisplayObject(t,e,i.context,i.restoreStack,n),i.saveDirtyAABB(t)),(t.sortable.sorted||t.childNodes).forEach((function(t){g(t,e)}))};l.hooks.endFrame.tap(t.tag,(function(){var t,r,l=u.getContext(),p=u.getDPR();if((t=i.dprMatrix)[0]=(r=[p,p,1])[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=r[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=r[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,h(i.vpMatrix,i.dprMatrix,s.getOrthoMatrix()),i.clearFullScreen)g(c.root,l);else{var y=i.safeMergeAABB.apply(i,function(t,e,r){if(r||2===arguments.length)for(var n,i=0,a=e.length;a>i;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}([i.mergeDirtyAABBs(i.renderQueue)],a(i.removedRBushNodeAABBs.map((function(t){var r=t.minX,n=t.minY,i=t.maxX,a=t.maxY,o=new e.AABB;return o.setMinMax([r,n,0],[i,a,0]),o}))),!1));if(i.removedRBushNodeAABBs=[],e.AABB.isEmpty(y))return void(i.renderQueue=[]);var v=i.convertAABB2Rect(y),m=v.x,A=v.y,x=v.width,b=v.height,S=d(i.vec3a,[m,A,0],i.vpMatrix),B=d(i.vec3b,[m+x,A,0],i.vpMatrix),M=d(i.vec3c,[m,A+b,0],i.vpMatrix),w=d(i.vec3d,[m+x,A+b,0],i.vpMatrix),R=Math.min(S[0],B[0],w[0],M[0]),E=Math.min(S[1],B[1],w[1],M[1]),O=Math.max(S[0],B[0],w[0],M[0]),C=Math.max(S[1],B[1],w[1],M[1]),T=Math.floor(R),P=Math.floor(E),N=Math.ceil(O-R),L=Math.ceil(C-E);l.save(),i.clearRect(l,T,P,N,L,o.background),l.beginPath(),l.rect(T,P,N,L),l.clip(),l.setTransform(i.vpMatrix[0],i.vpMatrix[1],i.vpMatrix[4],i.vpMatrix[5],i.vpMatrix[12],i.vpMatrix[13]),o.renderer.getConfig().enableDirtyRectangleRenderingDebug&&f.dispatchEvent(new e.CustomEvent(e.CanvasEvent.DIRTY_RECTANGLE,{dirtyRect:{x:T,y:P,width:N,height:L}})),i.searchDirtyObjects(y).sort((function(t,e){return t.sortable.renderOrder-e.sortable.renderOrder})).forEach((function(t){t&&t.isVisible()&&!t.isCulled()&&i.renderDisplayObject(t,l,i.context,i.restoreStack,n)})),l.restore(),i.renderQueue.forEach((function(t){i.saveDirtyAABB(t)})),i.renderQueue=[]}i.restoreStack.forEach((function(){l.restore()})),i.restoreStack=[]})),l.hooks.render.tap(t.tag,(function(t){i.clearFullScreen||i.renderQueue.push(t)}))},t.prototype.clearRect=function(t,e,r,n,i,a){t.clearRect(e,r,n,i),a&&(t.fillStyle=a,t.fillRect(e,r,n,i))},t.prototype.renderDisplayObject=function(t,r,n,i,a){var o=t.nodeName,s=i[i.length-1];!s||t.compareDocumentPosition(s)&Node.DOCUMENT_POSITION_CONTAINS||(r.restore(),i.pop());var l=this.context.styleRendererFactory[o],h=this.pathGeneratorFactory[o],c=t.parsedStyle.clipPath;if(c){this.applyWorldTransform(r,c);var p=this.pathGeneratorFactory[c.nodeName];p&&(r.save(),i.push(t),r.beginPath(),p(r,c.parsedStyle),r.closePath(),r.clip())}l&&(this.applyWorldTransform(r,t),r.save(),this.applyAttributesToContext(r,t)),h&&(r.beginPath(),h(r,t.parsedStyle),t.nodeName!==e.Shape.LINE&&t.nodeName!==e.Shape.PATH&&t.nodeName!==e.Shape.POLYLINE&&r.closePath()),l&&(l.render(r,t.parsedStyle,t,n,this,a),r.restore()),t.renderable.dirty=!1},t.prototype.convertAABB2Rect=function(t){var e=t.getMin(),r=t.getMax(),n=Math.floor(e[0])-2,i=Math.floor(e[1])-2;return{x:n,y:i,width:Math.ceil(r[0])+2-n,height:Math.ceil(r[1])+2-i}},t.prototype.mergeDirtyAABBs=function(t){var r=new e.AABB;return t.forEach((function(t){var e=t.getRenderBounds();r.add(e);var n=t.renderable.dirtyRenderBounds;n&&r.add(n)})),r},t.prototype.searchDirtyObjects=function(t){var e=a(t.getMin(),2),r=e[0],n=e[1],i=a(t.getMax(),2);return this.rBush.search({minX:r,minY:n,maxX:i[0],maxY:i[1]}).map((function(t){return t.displayObject}))},t.prototype.saveDirtyAABB=function(t){var r=t.renderable;r.dirtyRenderBounds||(r.dirtyRenderBounds=new e.AABB);var n=t.getRenderBounds();n&&r.dirtyRenderBounds.update(n.center,n.halfExtents)},t.prototype.applyAttributesToContext=function(t,e){var r=e.parsedStyle,n=r.stroke,i=r.fill,a=r.opacity,o=r.lineDash,s=r.lineDashOffset;o&&t.setLineDash(o),u(s)||(t.lineDashOffset=s),u(a)||(t.globalAlpha*=a),u(n)||Array.isArray(n)||n.isNone||(t.strokeStyle=e.attributes.stroke),u(i)||Array.isArray(i)||i.isNone||(t.fillStyle=e.attributes.fill)},t.prototype.applyWorldTransform=function(t,e,r){var n=0,i=0,a=(e.parsedStyle||{}).anchor,o=a&&a[0]||0,s=a&&a[1]||0;if(0!==o||0!==s){var p=e.geometry.contentBounds;n=-o*(p&&2*p.halfExtents[0]||0),i=-s*(p&&2*p.halfExtents[1]||0)}r?(l(this.tmpMat4,e.getLocalTransform()),this.vec3a[0]=n,this.vec3a[1]=i,this.vec3a[2]=0,c(this.tmpMat4,this.tmpMat4,this.vec3a),h(this.tmpMat4,r,this.tmpMat4),h(this.tmpMat4,this.vpMatrix,this.tmpMat4)):(l(this.tmpMat4,e.getWorldTransform()),this.vec3a[0]=n,this.vec3a[1]=i,this.vec3a[2]=0,c(this.tmpMat4,this.tmpMat4,this.vec3a),h(this.tmpMat4,this.vpMatrix,this.tmpMat4)),t.setTransform(this.tmpMat4[0],this.tmpMat4[1],this.tmpMat4[4],this.tmpMat4[5],this.tmpMat4[12],this.tmpMat4[13])},t.prototype.safeMergeAABB=function(){for(var t=[],r=0;arguments.length>r;r++)t[r]=arguments[r];var n=new e.AABB;return t.forEach((function(t){n.add(t)})),n},t.tag="CanvasRenderer",t}(),g=function(){function t(t){this.imagePool=t}return t.prototype.render=function(t,r,n,i,a,o){var s=r.fill,l=r.fillRule,h=r.opacity,c=r.fillOpacity,p=r.stroke,d=r.strokeOpacity,f=r.lineWidth,y=r.lineCap,v=r.lineJoin,g=r.shadowType,A=r.shadowColor,x=r.shadowBlur,b=r.filter,S=r.miterLimit,B=!u(s)&&!s.isNone,M=!u(p)&&!p.isNone&&f>0,w=0===s.alpha,R=!(!b||!b.length),E=!u(A)&&x>0,O=n.nodeName,C="inner"===g,T=M&&E&&(O===e.Shape.PATH||O===e.Shape.LINE||O===e.Shape.POLYLINE||w||C);B&&(t.globalAlpha=h*c,T||m(n,t,E),this.fill(t,n,s,l,i,a,o),T||this.clearShadowAndFilter(t,R,E)),M&&(t.globalAlpha=h*d,t.lineWidth=f,u(S)||(t.miterLimit=S),u(y)||(t.lineCap=y),u(v)||(t.lineJoin=v),T&&(C&&(t.globalCompositeOperation="source-atop"),m(n,t,!0),C&&(this.stroke(t,n,p,i,a,o),t.globalCompositeOperation="source-over",this.clearShadowAndFilter(t,R,!0))),this.stroke(t,n,p,i,a,o))},t.prototype.clearShadowAndFilter=function(t,e,r){if(r&&(t.shadowColor="transparent",t.shadowBlur=0),e){var n=t.filter;!u(n)&&n.indexOf("drop-shadow")>-1&&(t.filter=n.replace(/drop-shadow\([^)]*\)/,"").trim()||"none")}},t.prototype.fill=function(t,r,n,i,a,o,s){var l=this;Array.isArray(n)?n.forEach((function(e){t.fillStyle=l.getColor(e,r,t),i?t.fill(i):t.fill()})):(e.isPattern(n)&&(t.fillStyle=this.getPattern(n,r,t,a,o,s)),i?t.fill(i):t.fill())},t.prototype.stroke=function(t,r,n,i,a,o){var s=this;Array.isArray(n)?n.forEach((function(e){t.strokeStyle=s.getColor(e,r,t),t.stroke()})):(e.isPattern(n)&&(t.strokeStyle=this.getPattern(n,r,t,i,a,o)),t.stroke())},t.prototype.getPattern=function(t,e,r,n,i,a){var o,s;if("rect"===t.image.nodeName){var l=t.image.parsedStyle,h=l.width,c=l.height;s=n.contextService.getDPR();var p=n.config.offscreenCanvas;(o=a.offscreenCanvasCreator.getOrCreateCanvas(p)).width=h*s,o.height=c*s;var d=a.offscreenCanvasCreator.getOrCreateContext(p),u=[];t.image.forEach((function(t){i.renderDisplayObject(t,d,n,u,a)})),u.forEach((function(){d.restore()}))}return this.imagePool.getOrCreatePatternSync(t,r,o,s,(function(){e.renderable.dirty=!0,n.renderingService.dirtify()}))},t.prototype.getColor=function(t,r,n){var a;if(t.type===e.GradientType.LinearGradient||t.type===e.GradientType.RadialGradient){var o=r.getGeometryBounds(),s=o&&2*o.halfExtents[0]||1,l=o&&2*o.halfExtents[1]||1;a=this.imagePool.getOrCreateGradient(i(i({type:t.type},t.value),{width:s,height:l}),n)}return a},t}();function m(t,e,r){var n=t.parsedStyle,i=n.filter,a=n.shadowColor,o=n.shadowBlur,s=n.shadowOffsetX,l=n.shadowOffsetY;i&&i.length&&(e.filter=t.style.filter),r&&(e.shadowColor=""+a,e.shadowBlur=o||0,e.shadowOffsetX=s||0,e.shadowOffsetY=l||0)}var A=function(){function t(t){this.imagePool=t}return t.prototype.render=function(t,e,r){var n,i=e.img,a=e.shadowColor,o=e.shadowBlur,s=e.width,l=e.height;if(y(i,"String")?n=this.imagePool.getImageSync(i):(s||(s=i.width),l||(l=i.height),n=i),n){m(r,t,!u(a)&&o>0);try{t.drawImage(n,0,0,s,l)}catch(t){}}},t}(),x=function(){function t(){}return t.prototype.render=function(t,e,r,n,i,a){var o=e.lineWidth,s=e.textAlign,l=e.textBaseline,h=e.lineJoin,c=e.miterLimit,p=e.letterSpacing,d=e.stroke,f=e.fill,y=e.fillOpacity,v=e.strokeOpacity,g=e.opacity,A=e.metrics,x=e.dx,b=e.dy,S=e.shadowColor,B=e.shadowBlur,M=A.lines,w=A.height,R=A.lineHeight,E=A.lineMetrics;t.font=A.font,t.lineWidth=o,t.textAlign="middle"===s?"center":s;var O=l;a.enableCSSParsing||"alphabetic"!==O||(O="bottom"),t.lineJoin=h,u(c)||(t.miterLimit=c);var C=0;"middle"===l?C=-w/2-R/2:"bottom"===l||"alphabetic"===l||"ideographic"===l?C=-w:"top"!==l&&"hanging"!==l||(C=-R);var T=x||0;C+=b||0,1===M.length&&("bottom"===O?(O="middle",C-=.5*w):"top"===O&&(O="middle",C+=.5*w)),t.textBaseline=O,m(r,t,!u(S)&&B>0);for(var P=0;M.length>P;P++){var N=o/2+T;C+=R,u(d)||d.isNone||!o||this.drawLetterSpacing(t,M[P],E[P],s,N,C,p,y,v,g,!0),u(f)||this.drawLetterSpacing(t,M[P],E[P],s,N,C,p,y,v,g)}},t.prototype.drawLetterSpacing=function(t,e,r,n,i,a,o,s,l,h,c){if(void 0===c&&(c=!1),0!==o){var p=t.textAlign;t.textAlign="left";var d=i;"center"===n||"middle"===n?d=i-r.width/2:"right"!==n&&"end"!==n||(d=i-r.width);for(var u=Array.from(e),f=t.measureText(e).width,y=0,v=0;u.length>v;++v){var g=u[v];c?this.strokeText(t,g,d,a,l):this.fillText(t,g,d,a,s,h),d+=f-(y=t.measureText(e.substring(v+1)).width)+o,f=y}t.textAlign=p}else c?this.strokeText(t,e,i,a,l):this.fillText(t,e,i,a,s,h)},t.prototype.fillText=function(t,e,r,n,i,a){var o,s=!u(i)&&1!==i;s&&(o=t.globalAlpha,t.globalAlpha=i*a),t.fillText(e,r,n),s&&(t.globalAlpha=o)},t.prototype.strokeText=function(t,e,r,n,i){var a,o=!u(i)&&1!==i;o&&(a=t.globalAlpha,t.globalAlpha=i),t.strokeText(e,r,n),o&&(t.globalAlpha=a)},t}(),b=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e}(g),S=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e}(g),B=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e}(g),M=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e}(g),w=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e}(g),R=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e}(g),E=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e}(g),O=function(t){function r(e){void 0===e&&(e={});var r=t.call(this)||this;return r.options=e,r.name="canvas-renderer",r}return n(r,t),r.prototype.init=function(){var t,r=i({dirtyObjectNumThreshold:500,dirtyObjectRatioThreshold:.8},this.options),n=this.context.imagePool,a=new g(n),o=((t={})[e.Shape.CIRCLE]=a,t[e.Shape.ELLIPSE]=a,t[e.Shape.RECT]=a,t[e.Shape.IMAGE]=new A(n),t[e.Shape.TEXT]=new x,t[e.Shape.LINE]=a,t[e.Shape.POLYLINE]=a,t[e.Shape.POLYGON]=a,t[e.Shape.PATH]=a,t[e.Shape.GROUP]=void 0,t[e.Shape.HTML]=void 0,t[e.Shape.MESH]=void 0,t);this.context.defaultStyleRendererFactory=o,this.context.styleRendererFactory=o,this.addRenderingPlugin(new v(r))},r.prototype.destroy=function(){this.removeAllRenderingPlugins(),delete this.context.defaultStyleRendererFactory,delete this.context.styleRendererFactory},r}(e.AbstractRendererPlugin);t.CircleRenderer=S,t.EllipseRenderer=B,t.ImageRenderer=A,t.LineRenderer=M,t.PathRenderer=E,t.Plugin=O,t.PolygonRenderer=R,t.PolylineRenderer=w,t.RectRenderer=b,t.TextRenderer=x})); | ||
//# sourceMappingURL=index.umd.min.js.map |
{ | ||
"name": "@antv/g-plugin-canvas-renderer", | ||
"version": "1.9.13", | ||
"version": "1.9.14", | ||
"description": "A G plugin of renderer implementation with Canvas2D API", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
409765
1840