Socket
Socket
Sign inDemoInstall

@pixi/canvas-renderer

Package Overview
Dependencies
Maintainers
1
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pixi/canvas-renderer - npm Package Compare versions

Comparing version 5.2.1 to 5.2.2

135

dist/canvas-renderer.js
/*!
* @pixi/canvas-renderer - v5.2.1
* Compiled Tue, 28 Jan 2020 23:33:11 UTC
* @pixi/canvas-renderer - v5.2.2
* Compiled Tue, 21 Apr 2020 03:53:51 UTC
*

@@ -48,3 +48,2 @@ * @pixi/canvas-renderer is licensed under the MIT License.

var context = renderer.context;
var resolution = renderer.resolution;

@@ -58,10 +57,3 @@ context.beginPath();

this.renderer.context.setTransform(
transform.a * resolution,
transform.b * resolution,
transform.c * resolution,
transform.d * resolution,
transform.tx * resolution,
transform.ty * resolution
);
this.renderer.setContextTransform(transform);

@@ -358,2 +350,4 @@ this.renderGraphicsShape(shape);

var tempMatrix = new math.Matrix();
/**

@@ -442,2 +436,9 @@ * The CanvasRenderer draws the scene and all its content onto a 2d canvas.

/**
* Projection transform, passed in render() stored here
* @type {null}
* @private
*/
this._projTransform = null;
this.renderingToScreen = false;

@@ -515,2 +516,4 @@

this._projTransform = transform || null;
if (!renderTexture)

@@ -525,29 +528,6 @@ {

var cacheParent = displayObject.parent;
var tempWt = this._tempDisplayObjectParent.transform.worldTransform;
if (transform)
{
transform.copyTo(tempWt);
// Canvas Renderer doesn't use "context.translate"
// nor does it store current translation in projectionSystem
// we re-calculate all matrices,
// its not like CanvasRenderer can survive more than 1000 elements
displayObject.transform._parentID = -1;
}
else
{
// in this case matrix cache in displayObject works like expected
tempWt.identity();
}
displayObject.parent = this._tempDisplayObjectParent;
displayObject.updateTransform();
displayObject.parent = cacheParent;
if (transform)
{
// Clear the matrix cache one more time,
// we dont have our computations to affect standard "transform=null" case
displayObject.transform._parentID = -1;
}
// displayObject.hitArea = //TODO add a temp hit area

@@ -591,2 +571,3 @@ }

this.resolution = rootResolution;
this._projTransform = null;

@@ -597,2 +578,49 @@ this.emit('postrender');

/**
* sets matrix of context
* called only from render() methods
* takes care about resolution
* @param {PIXI.Matrix} transform world matrix of current element
* @param {boolean} [roundPixels] whether to round (tx,ty) coords
* @param {number} [localResolution] If specified, used instead of `renderer.resolution` for local scaling
*/
CanvasRenderer.prototype.setContextTransform = function setContextTransform (transform, roundPixels, localResolution)
{
var mat = transform;
var proj = this._projTransform;
var resolution = this.resolution;
localResolution = localResolution || resolution;
if (proj)
{
mat = tempMatrix;
mat.copyFrom(transform);
mat.prepend(proj);
}
if (roundPixels)
{
this.context.setTransform(
mat.a * localResolution,
mat.b * localResolution,
mat.c * localResolution,
mat.d * localResolution,
(mat.tx * resolution) | 0,
(mat.ty * resolution) | 0
);
}
else
{
this.context.setTransform(
mat.a * localResolution,
mat.b * localResolution,
mat.c * localResolution,
mat.d * localResolution,
mat.tx * resolution,
mat.ty * resolution
);
}
};
/**
* Clear the canvas of renderer.

@@ -767,3 +795,3 @@ *

{
canvas = canvasUtils.canvas || document.createElement('canvas');
canvas = document.createElement('canvas');
}

@@ -787,4 +815,2 @@

texture.tintCache[stringColor] = canvas;
// if we are not converting the texture to an image then we need to lose the reference to the canvas
canvasUtils.canvas = null;
}

@@ -796,2 +822,35 @@

/**
* Basically this method just needs a sprite and a color and tints the sprite with the given color.
*
* @memberof PIXI.canvasUtils
* @param {PIXI.Sprite} sprite - the sprite to tint
* @param {number} color - the color to use to tint the sprite with
* @return {HTMLCanvasElement} The tinted canvas
*/
getTintedPattern: function (texture, color) {
color = canvasUtils.roundColor(color);
var stringColor = "#" + ((("00000" + ((color | 0).toString(16)))).substr(-6));
texture.patternCache = texture.patternCache || {};
var pattern = texture.patternCache[stringColor];
if (pattern && pattern.tintId === texture._updateID)
{
return pattern;
}
if (!canvasUtils.canvas)
{
canvasUtils.canvas = document.createElement('canvas');
}
canvasUtils.tintMethod(texture, color, canvasUtils.canvas);
pattern = canvasUtils.canvas.getContext('2d').createPattern(canvasUtils.canvas, 'repeat');
pattern.tintId = texture._updateID;
texture.patternCache[stringColor] = pattern;
return pattern;
},
/**
* Tint a texture using the 'multiply' operation.

@@ -1047,3 +1106,3 @@ *

return resource ? (resource.bitmap || resource.source) : this.source;
return resource ? (resource.bitmap || resource.source) : null;
};

@@ -1050,0 +1109,0 @@

/*!
* @pixi/canvas-renderer - v5.2.1
* Compiled Tue, 28 Jan 2020 23:33:11 UTC
* @pixi/canvas-renderer - v5.2.2
* Compiled Tue, 21 Apr 2020 03:53:51 UTC
*

@@ -8,3 +8,3 @@ * @pixi/canvas-renderer is licensed under the MIT License.

*/
this.PIXI=this.PIXI||{};var _pixi_canvas_renderer=function(e,t,r,o,i,n){"use strict";var a=function(e){this.renderer=e,this._foundShapes=[]};function s(e){var t=document.createElement("canvas");t.width=6,t.height=1;var r=t.getContext("2d");return r.fillStyle=e,r.fillRect(0,0,6,1),t}function h(){if("undefined"==typeof document)return!1;var e=s("#ff00ff"),t=s("#ffff00"),r=document.createElement("canvas");r.width=6,r.height=1;var o=r.getContext("2d");o.globalCompositeOperation="multiply",o.drawImage(e,0,0),o.drawImage(t,2,0);var i=o.getImageData(2,0,1,1);if(!i)return!1;var n=i.data;return 255===n[0]&&0===n[1]&&0===n[2]}a.prototype.pushMask=function(e){var t=this.renderer,r=e.isMaskData?e.maskObject:e;t.context.save();var o=this._foundShapes;if(this.recursiveFindShapes(r,o),o.length>0){var i=t.context,n=t.resolution;i.beginPath();for(var a=0;a<o.length;a++){var s=o[a],h=s.transform.worldTransform;this.renderer.context.setTransform(h.a*n,h.b*n,h.c*n,h.d*n,h.tx*n,h.ty*n),this.renderGraphicsShape(s)}o.length=0,i.clip()}},a.prototype.recursiveFindShapes=function(e,t){e.geometry&&e.geometry.graphicsData&&t.push(e);var r=e.children;if(r)for(var o=0;o<r.length;o++)this.recursiveFindShapes(r[o],t)},a.prototype.renderGraphicsShape=function(e){e.finishPoly();var t=this.renderer.context,r=e.geometry.graphicsData,i=r.length;if(0!==i)for(var n=0;n<i;n++){var a=r[n],s=a.shape;if(a.type===o.SHAPES.POLY){var h=s.points;t.moveTo(h[0],h[1]);for(var l=1;l<h.length/2;l++)t.lineTo(h[2*l],h[2*l+1]);h[0]===h[h.length-2]&&h[1]===h[h.length-1]&&t.closePath()}else if(a.type===o.SHAPES.RECT)t.rect(s.x,s.y,s.width,s.height),t.closePath();else if(a.type===o.SHAPES.CIRC)t.arc(s.x,s.y,s.radius,0,2*Math.PI),t.closePath();else if(a.type===o.SHAPES.ELIP){var c=2*s.width,E=2*s.height,d=s.x-c/2,D=s.y-E/2,u=c/2*.5522848,g=E/2*.5522848,p=d+c,S=D+E,_=d+c/2,v=D+E/2;t.moveTo(d,v),t.bezierCurveTo(d,v-g,_-u,D,_,D),t.bezierCurveTo(_+u,D,p,v-g,p,v),t.bezierCurveTo(p,v+g,_+u,S,_,S),t.bezierCurveTo(_-u,S,d,v+g,d,v),t.closePath()}else if(a.type===o.SHAPES.RREC){var O=s.x,M=s.y,m=s.width,N=s.height,L=s.radius,f=Math.min(m,N)/2|0;L=L>f?f:L,t.moveTo(O,M+L),t.lineTo(O,M+N-L),t.quadraticCurveTo(O,M+N,O+L,M+N),t.lineTo(O+m-L,M+N),t.quadraticCurveTo(O+m,M+N,O+m,M+N-L),t.lineTo(O+m,M+L),t.quadraticCurveTo(O+m,M,O+m-L,M),t.lineTo(O+L,M),t.quadraticCurveTo(O,M,O,M+L),t.closePath()}}},a.prototype.popMask=function(e){e.context.restore(),e.invalidateBlendMode()},a.prototype.destroy=function(){};var l=function(e){function o(t,n,s){var l;e.call(this,"Canvas",t,n,s),this.type=i.RENDERER_TYPE.CANVAS,this.rootContext=this.view.getContext("2d",{alpha:this.transparent}),this.context=this.rootContext,this.refresh=!0,this.maskManager=new a(this),this.smoothProperty="imageSmoothingEnabled",this.rootContext.imageSmoothingEnabled||(this.rootContext.webkitImageSmoothingEnabled?this.smoothProperty="webkitImageSmoothingEnabled":this.rootContext.mozImageSmoothingEnabled?this.smoothProperty="mozImageSmoothingEnabled":this.rootContext.oImageSmoothingEnabled?this.smoothProperty="oImageSmoothingEnabled":this.rootContext.msImageSmoothingEnabled&&(this.smoothProperty="msImageSmoothingEnabled")),this.initPlugins(o.__plugins),this.blendModes=(void 0===l&&(l=[]),h()?(l[i.BLEND_MODES.NORMAL]="source-over",l[i.BLEND_MODES.ADD]="lighter",l[i.BLEND_MODES.MULTIPLY]="multiply",l[i.BLEND_MODES.SCREEN]="screen",l[i.BLEND_MODES.OVERLAY]="overlay",l[i.BLEND_MODES.DARKEN]="darken",l[i.BLEND_MODES.LIGHTEN]="lighten",l[i.BLEND_MODES.COLOR_DODGE]="color-dodge",l[i.BLEND_MODES.COLOR_BURN]="color-burn",l[i.BLEND_MODES.HARD_LIGHT]="hard-light",l[i.BLEND_MODES.SOFT_LIGHT]="soft-light",l[i.BLEND_MODES.DIFFERENCE]="difference",l[i.BLEND_MODES.EXCLUSION]="exclusion",l[i.BLEND_MODES.HUE]="hue",l[i.BLEND_MODES.SATURATION]="saturate",l[i.BLEND_MODES.COLOR]="color",l[i.BLEND_MODES.LUMINOSITY]="luminosity"):(l[i.BLEND_MODES.NORMAL]="source-over",l[i.BLEND_MODES.ADD]="lighter",l[i.BLEND_MODES.MULTIPLY]="source-over",l[i.BLEND_MODES.SCREEN]="source-over",l[i.BLEND_MODES.OVERLAY]="source-over",l[i.BLEND_MODES.DARKEN]="source-over",l[i.BLEND_MODES.LIGHTEN]="source-over",l[i.BLEND_MODES.COLOR_DODGE]="source-over",l[i.BLEND_MODES.COLOR_BURN]="source-over",l[i.BLEND_MODES.HARD_LIGHT]="source-over",l[i.BLEND_MODES.SOFT_LIGHT]="source-over",l[i.BLEND_MODES.DIFFERENCE]="source-over",l[i.BLEND_MODES.EXCLUSION]="source-over",l[i.BLEND_MODES.HUE]="source-over",l[i.BLEND_MODES.SATURATION]="source-over",l[i.BLEND_MODES.COLOR]="source-over",l[i.BLEND_MODES.LUMINOSITY]="source-over"),l[i.BLEND_MODES.NORMAL_NPM]=l[i.BLEND_MODES.NORMAL],l[i.BLEND_MODES.ADD_NPM]=l[i.BLEND_MODES.ADD],l[i.BLEND_MODES.SCREEN_NPM]=l[i.BLEND_MODES.SCREEN],l[i.BLEND_MODES.SRC_IN]="source-in",l[i.BLEND_MODES.SRC_OUT]="source-out",l[i.BLEND_MODES.SRC_ATOP]="source-atop",l[i.BLEND_MODES.DST_OVER]="destination-over",l[i.BLEND_MODES.DST_IN]="destination-in",l[i.BLEND_MODES.DST_OUT]="destination-out",l[i.BLEND_MODES.DST_ATOP]="destination-atop",l[i.BLEND_MODES.XOR]="xor",l[i.BLEND_MODES.SUBTRACT]="source-over",l),this._activeBlendMode=null,this._outerBlend=!1,this.renderingToScreen=!1,r.sayHello("Canvas"),this.resize(this.options.width,this.options.height)}return e&&(o.__proto__=e),o.prototype=Object.create(e&&e.prototype),o.prototype.constructor=o,o.prototype.render=function(e,o,n,a,s){if(this.view){this.renderingToScreen=!o,this.emit("prerender");var h=this.resolution;o?((o=o.baseTexture||o)._canvasRenderTarget||(o._canvasRenderTarget=new r.CanvasRenderTarget(o.width,o.height,o.resolution),o.resource=new t.resources.CanvasResource(o._canvasRenderTarget.canvas),o.valid=!0),this.context=o._canvasRenderTarget.context,this.resolution=o._canvasRenderTarget.resolution):this.context=this.rootContext;var l=this.context;if(o||(this._lastObjectRendered=e),!s){var c=e.parent,E=this._tempDisplayObjectParent.transform.worldTransform;a?(a.copyTo(E),e.transform._parentID=-1):E.identity(),e.parent=this._tempDisplayObjectParent,e.updateTransform(),e.parent=c,a&&(e.transform._parentID=-1)}l.save(),l.setTransform(1,0,0,1,0,0),l.globalAlpha=1,this._activeBlendMode=i.BLEND_MODES.NORMAL,this._outerBlend=!1,l.globalCompositeOperation=this.blendModes[i.BLEND_MODES.NORMAL],(void 0!==n?n:this.clearBeforeRender)&&this.renderingToScreen&&(this.transparent?l.clearRect(0,0,this.width,this.height):(l.fillStyle=this._backgroundColorString,l.fillRect(0,0,this.width,this.height)));var d=this.context;this.context=l,e.renderCanvas(this),this.context=d,l.restore(),this.resolution=h,this.emit("postrender")}},o.prototype.clear=function(e){var t=this.context;e=e||this._backgroundColorString,!this.transparent&&e?(t.fillStyle=e,t.fillRect(0,0,this.width,this.height)):t.clearRect(0,0,this.width,this.height)},o.prototype.setBlendMode=function(e,t){var r=e===i.BLEND_MODES.SRC_IN||e===i.BLEND_MODES.SRC_OUT||e===i.BLEND_MODES.DST_IN||e===i.BLEND_MODES.DST_ATOP;!t&&r&&(e=i.BLEND_MODES.NORMAL),this._activeBlendMode!==e&&(this._activeBlendMode=e,this._outerBlend=r,this.context.globalCompositeOperation=this.blendModes[e])},o.prototype.destroy=function(t){e.prototype.destroy.call(this,t),this.context=null,this.refresh=!0,this.maskManager.destroy(),this.maskManager=null,this.smoothProperty=null},o.prototype.resize=function(t,r){e.prototype.resize.call(this,t,r),this.smoothProperty&&(this.rootContext[this.smoothProperty]=n.settings.SCALE_MODE===i.SCALE_MODES.LINEAR)},o.prototype.invalidateBlendMode=function(){this._activeBlendMode=this.blendModes.indexOf(this.context.globalCompositeOperation)},o.registerPlugin=function(e,t){o.__plugins=o.__plugins||{},o.__plugins[e]=t},o}(t.AbstractRenderer),c={getTintedCanvas:function(e,t){var r=e.texture,o="#"+("00000"+(0|(t=c.roundColor(t))).toString(16)).substr(-6);r.tintCache=r.tintCache||{};var i,n=r.tintCache[o];if(n){if(n.tintId===r._updateID)return r.tintCache[o];i=r.tintCache[o]}else i=c.canvas||document.createElement("canvas");if(c.tintMethod(r,t,i),i.tintId=r._updateID,c.convertTintToImage){var a=new Image;a.src=i.toDataURL(),r.tintCache[o]=a}else r.tintCache[o]=i,c.canvas=null;return i},tintWithMultiply:function(e,t,r){var o=r.getContext("2d"),i=e._frame.clone(),n=e.baseTexture.resolution;i.x*=n,i.y*=n,i.width*=n,i.height*=n,r.width=Math.ceil(i.width),r.height=Math.ceil(i.height),o.save(),o.fillStyle="#"+("00000"+(0|t).toString(16)).substr(-6),o.fillRect(0,0,i.width,i.height),o.globalCompositeOperation="multiply";var a=e.baseTexture.getDrawableSource();o.drawImage(a,i.x,i.y,i.width,i.height,0,0,i.width,i.height),o.globalCompositeOperation="destination-atop",o.drawImage(a,i.x,i.y,i.width,i.height,0,0,i.width,i.height),o.restore()},tintWithOverlay:function(e,t,r){var o=r.getContext("2d"),i=e._frame.clone(),n=e.baseTexture.resolution;i.x*=n,i.y*=n,i.width*=n,i.height*=n,r.width=Math.ceil(i.width),r.height=Math.ceil(i.height),o.save(),o.globalCompositeOperation="copy",o.fillStyle="#"+("00000"+(0|t).toString(16)).substr(-6),o.fillRect(0,0,i.width,i.height),o.globalCompositeOperation="destination-atop",o.drawImage(e.baseTexture.getDrawableSource(),i.x,i.y,i.width,i.height,0,0,i.width,i.height),o.restore()},tintWithPerPixel:function(e,t,o){var i=o.getContext("2d"),n=e._frame.clone(),a=e.baseTexture.resolution;n.x*=a,n.y*=a,n.width*=a,n.height*=a,o.width=Math.ceil(n.width),o.height=Math.ceil(n.height),i.save(),i.globalCompositeOperation="copy",i.drawImage(e.baseTexture.getDrawableSource(),n.x,n.y,n.width,n.height,0,0,n.width,n.height),i.restore();for(var s=r.hex2rgb(t),h=s[0],l=s[1],c=s[2],E=i.getImageData(0,0,n.width,n.height),d=E.data,D=0;D<d.length;D+=4)d[D+0]*=h,d[D+1]*=l,d[D+2]*=c;i.putImageData(E,0,0)},roundColor:function(e){var t=c.cacheStepsPerColorChannel,o=r.hex2rgb(e);return o[0]=Math.min(255,o[0]/t*t),o[1]=Math.min(255,o[1]/t*t),o[2]=Math.min(255,o[2]/t*t),r.rgb2hex(o)},cacheStepsPerColorChannel:8,convertTintToImage:!1,canUseMultiply:h(),tintMethod:function(){}};c.tintMethod=c.canUseMultiply?c.tintWithMultiply:c.tintWithPerPixel;var E=t.Renderer.create;return t.Renderer.create=function(e){if(!(e&&e.forceCanvas))try{return E(e)}catch(e){}return new l(e)},t.BaseTexture.prototype.getDrawableSource=function(){var e=this.resource;return e?e.bitmap||e.source:this.source},e.CanvasRenderer=l,e.canUseNewCanvasBlendModes=h,e.canvasUtils=c,e}({},PIXI,PIXI.utils,PIXI,PIXI,PIXI);Object.assign(this.PIXI,_pixi_canvas_renderer);
this.PIXI=this.PIXI||{};var _pixi_canvas_renderer=function(t,e,r,o,i,n){"use strict";var a=function(t){this.renderer=t,this._foundShapes=[]};function s(t){var e=document.createElement("canvas");e.width=6,e.height=1;var r=e.getContext("2d");return r.fillStyle=t,r.fillRect(0,0,6,1),e}function h(){if("undefined"==typeof document)return!1;var t=s("#ff00ff"),e=s("#ffff00"),r=document.createElement("canvas");r.width=6,r.height=1;var o=r.getContext("2d");o.globalCompositeOperation="multiply",o.drawImage(t,0,0),o.drawImage(e,2,0);var i=o.getImageData(2,0,1,1);if(!i)return!1;var n=i.data;return 255===n[0]&&0===n[1]&&0===n[2]}a.prototype.pushMask=function(t){var e=this.renderer,r=t.isMaskData?t.maskObject:t;e.context.save();var o=this._foundShapes;if(this.recursiveFindShapes(r,o),o.length>0){var i=e.context;i.beginPath();for(var n=0;n<o.length;n++){var a=o[n],s=a.transform.worldTransform;this.renderer.setContextTransform(s),this.renderGraphicsShape(a)}o.length=0,i.clip()}},a.prototype.recursiveFindShapes=function(t,e){t.geometry&&t.geometry.graphicsData&&e.push(t);var r=t.children;if(r)for(var o=0;o<r.length;o++)this.recursiveFindShapes(r[o],e)},a.prototype.renderGraphicsShape=function(t){t.finishPoly();var e=this.renderer.context,r=t.geometry.graphicsData,i=r.length;if(0!==i)for(var n=0;n<i;n++){var a=r[n],s=a.shape;if(a.type===o.SHAPES.POLY){var h=s.points;e.moveTo(h[0],h[1]);for(var l=1;l<h.length/2;l++)e.lineTo(h[2*l],h[2*l+1]);h[0]===h[h.length-2]&&h[1]===h[h.length-1]&&e.closePath()}else if(a.type===o.SHAPES.RECT)e.rect(s.x,s.y,s.width,s.height),e.closePath();else if(a.type===o.SHAPES.CIRC)e.arc(s.x,s.y,s.radius,0,2*Math.PI),e.closePath();else if(a.type===o.SHAPES.ELIP){var c=2*s.width,d=2*s.height,E=s.x-c/2,u=s.y-d/2,D=c/2*.5522848,p=d/2*.5522848,g=E+c,S=u+d,_=E+c/2,v=u+d/2;e.moveTo(E,v),e.bezierCurveTo(E,v-p,_-D,u,_,u),e.bezierCurveTo(_+D,u,g,v-p,g,v),e.bezierCurveTo(g,v+p,_+D,S,_,S),e.bezierCurveTo(_-D,S,E,v+p,E,v),e.closePath()}else if(a.type===o.SHAPES.RREC){var O=s.x,M=s.y,m=s.width,f=s.height,N=s.radius,C=Math.min(m,f)/2|0;N=N>C?C:N,e.moveTo(O,M+N),e.lineTo(O,M+f-N),e.quadraticCurveTo(O,M+f,O+N,M+f),e.lineTo(O+m-N,M+f),e.quadraticCurveTo(O+m,M+f,O+m,M+f-N),e.lineTo(O+m,M+N),e.quadraticCurveTo(O+m,M,O+m-N,M),e.lineTo(O+N,M),e.quadraticCurveTo(O,M,O,M+N),e.closePath()}}},a.prototype.popMask=function(t){t.context.restore(),t.invalidateBlendMode()},a.prototype.destroy=function(){};var l=new o.Matrix,c=function(t){function o(e,n,s){var l;t.call(this,"Canvas",e,n,s),this.type=i.RENDERER_TYPE.CANVAS,this.rootContext=this.view.getContext("2d",{alpha:this.transparent}),this.context=this.rootContext,this.refresh=!0,this.maskManager=new a(this),this.smoothProperty="imageSmoothingEnabled",this.rootContext.imageSmoothingEnabled||(this.rootContext.webkitImageSmoothingEnabled?this.smoothProperty="webkitImageSmoothingEnabled":this.rootContext.mozImageSmoothingEnabled?this.smoothProperty="mozImageSmoothingEnabled":this.rootContext.oImageSmoothingEnabled?this.smoothProperty="oImageSmoothingEnabled":this.rootContext.msImageSmoothingEnabled&&(this.smoothProperty="msImageSmoothingEnabled")),this.initPlugins(o.__plugins),this.blendModes=(void 0===l&&(l=[]),h()?(l[i.BLEND_MODES.NORMAL]="source-over",l[i.BLEND_MODES.ADD]="lighter",l[i.BLEND_MODES.MULTIPLY]="multiply",l[i.BLEND_MODES.SCREEN]="screen",l[i.BLEND_MODES.OVERLAY]="overlay",l[i.BLEND_MODES.DARKEN]="darken",l[i.BLEND_MODES.LIGHTEN]="lighten",l[i.BLEND_MODES.COLOR_DODGE]="color-dodge",l[i.BLEND_MODES.COLOR_BURN]="color-burn",l[i.BLEND_MODES.HARD_LIGHT]="hard-light",l[i.BLEND_MODES.SOFT_LIGHT]="soft-light",l[i.BLEND_MODES.DIFFERENCE]="difference",l[i.BLEND_MODES.EXCLUSION]="exclusion",l[i.BLEND_MODES.HUE]="hue",l[i.BLEND_MODES.SATURATION]="saturate",l[i.BLEND_MODES.COLOR]="color",l[i.BLEND_MODES.LUMINOSITY]="luminosity"):(l[i.BLEND_MODES.NORMAL]="source-over",l[i.BLEND_MODES.ADD]="lighter",l[i.BLEND_MODES.MULTIPLY]="source-over",l[i.BLEND_MODES.SCREEN]="source-over",l[i.BLEND_MODES.OVERLAY]="source-over",l[i.BLEND_MODES.DARKEN]="source-over",l[i.BLEND_MODES.LIGHTEN]="source-over",l[i.BLEND_MODES.COLOR_DODGE]="source-over",l[i.BLEND_MODES.COLOR_BURN]="source-over",l[i.BLEND_MODES.HARD_LIGHT]="source-over",l[i.BLEND_MODES.SOFT_LIGHT]="source-over",l[i.BLEND_MODES.DIFFERENCE]="source-over",l[i.BLEND_MODES.EXCLUSION]="source-over",l[i.BLEND_MODES.HUE]="source-over",l[i.BLEND_MODES.SATURATION]="source-over",l[i.BLEND_MODES.COLOR]="source-over",l[i.BLEND_MODES.LUMINOSITY]="source-over"),l[i.BLEND_MODES.NORMAL_NPM]=l[i.BLEND_MODES.NORMAL],l[i.BLEND_MODES.ADD_NPM]=l[i.BLEND_MODES.ADD],l[i.BLEND_MODES.SCREEN_NPM]=l[i.BLEND_MODES.SCREEN],l[i.BLEND_MODES.SRC_IN]="source-in",l[i.BLEND_MODES.SRC_OUT]="source-out",l[i.BLEND_MODES.SRC_ATOP]="source-atop",l[i.BLEND_MODES.DST_OVER]="destination-over",l[i.BLEND_MODES.DST_IN]="destination-in",l[i.BLEND_MODES.DST_OUT]="destination-out",l[i.BLEND_MODES.DST_ATOP]="destination-atop",l[i.BLEND_MODES.XOR]="xor",l[i.BLEND_MODES.SUBTRACT]="source-over",l),this._activeBlendMode=null,this._outerBlend=!1,this._projTransform=null,this.renderingToScreen=!1,r.sayHello("Canvas"),this.resize(this.options.width,this.options.height)}return t&&(o.__proto__=t),o.prototype=Object.create(t&&t.prototype),o.prototype.constructor=o,o.prototype.render=function(t,o,n,a,s){if(this.view){this.renderingToScreen=!o,this.emit("prerender");var h=this.resolution;o?((o=o.baseTexture||o)._canvasRenderTarget||(o._canvasRenderTarget=new r.CanvasRenderTarget(o.width,o.height,o.resolution),o.resource=new e.resources.CanvasResource(o._canvasRenderTarget.canvas),o.valid=!0),this.context=o._canvasRenderTarget.context,this.resolution=o._canvasRenderTarget.resolution):this.context=this.rootContext;var l=this.context;if(this._projTransform=a||null,o||(this._lastObjectRendered=t),!s){var c=t.parent;t.parent=this._tempDisplayObjectParent,t.updateTransform(),t.parent=c}l.save(),l.setTransform(1,0,0,1,0,0),l.globalAlpha=1,this._activeBlendMode=i.BLEND_MODES.NORMAL,this._outerBlend=!1,l.globalCompositeOperation=this.blendModes[i.BLEND_MODES.NORMAL],(void 0!==n?n:this.clearBeforeRender)&&this.renderingToScreen&&(this.transparent?l.clearRect(0,0,this.width,this.height):(l.fillStyle=this._backgroundColorString,l.fillRect(0,0,this.width,this.height)));var d=this.context;this.context=l,t.renderCanvas(this),this.context=d,l.restore(),this.resolution=h,this._projTransform=null,this.emit("postrender")}},o.prototype.setContextTransform=function(t,e,r){var o=t,i=this._projTransform,n=this.resolution;r=r||n,i&&((o=l).copyFrom(t),o.prepend(i)),e?this.context.setTransform(o.a*r,o.b*r,o.c*r,o.d*r,o.tx*n|0,o.ty*n|0):this.context.setTransform(o.a*r,o.b*r,o.c*r,o.d*r,o.tx*n,o.ty*n)},o.prototype.clear=function(t){var e=this.context;t=t||this._backgroundColorString,!this.transparent&&t?(e.fillStyle=t,e.fillRect(0,0,this.width,this.height)):e.clearRect(0,0,this.width,this.height)},o.prototype.setBlendMode=function(t,e){var r=t===i.BLEND_MODES.SRC_IN||t===i.BLEND_MODES.SRC_OUT||t===i.BLEND_MODES.DST_IN||t===i.BLEND_MODES.DST_ATOP;!e&&r&&(t=i.BLEND_MODES.NORMAL),this._activeBlendMode!==t&&(this._activeBlendMode=t,this._outerBlend=r,this.context.globalCompositeOperation=this.blendModes[t])},o.prototype.destroy=function(e){t.prototype.destroy.call(this,e),this.context=null,this.refresh=!0,this.maskManager.destroy(),this.maskManager=null,this.smoothProperty=null},o.prototype.resize=function(e,r){t.prototype.resize.call(this,e,r),this.smoothProperty&&(this.rootContext[this.smoothProperty]=n.settings.SCALE_MODE===i.SCALE_MODES.LINEAR)},o.prototype.invalidateBlendMode=function(){this._activeBlendMode=this.blendModes.indexOf(this.context.globalCompositeOperation)},o.registerPlugin=function(t,e){o.__plugins=o.__plugins||{},o.__plugins[t]=e},o}(e.AbstractRenderer),d={getTintedCanvas:function(t,e){var r=t.texture,o="#"+("00000"+(0|(e=d.roundColor(e))).toString(16)).substr(-6);r.tintCache=r.tintCache||{};var i,n=r.tintCache[o];if(n){if(n.tintId===r._updateID)return r.tintCache[o];i=r.tintCache[o]}else i=document.createElement("canvas");if(d.tintMethod(r,e,i),i.tintId=r._updateID,d.convertTintToImage){var a=new Image;a.src=i.toDataURL(),r.tintCache[o]=a}else r.tintCache[o]=i;return i},getTintedPattern:function(t,e){var r="#"+("00000"+(0|(e=d.roundColor(e))).toString(16)).substr(-6);t.patternCache=t.patternCache||{};var o=t.patternCache[r];return o&&o.tintId===t._updateID?o:(d.canvas||(d.canvas=document.createElement("canvas")),d.tintMethod(t,e,d.canvas),(o=d.canvas.getContext("2d").createPattern(d.canvas,"repeat")).tintId=t._updateID,t.patternCache[r]=o,o)},tintWithMultiply:function(t,e,r){var o=r.getContext("2d"),i=t._frame.clone(),n=t.baseTexture.resolution;i.x*=n,i.y*=n,i.width*=n,i.height*=n,r.width=Math.ceil(i.width),r.height=Math.ceil(i.height),o.save(),o.fillStyle="#"+("00000"+(0|e).toString(16)).substr(-6),o.fillRect(0,0,i.width,i.height),o.globalCompositeOperation="multiply";var a=t.baseTexture.getDrawableSource();o.drawImage(a,i.x,i.y,i.width,i.height,0,0,i.width,i.height),o.globalCompositeOperation="destination-atop",o.drawImage(a,i.x,i.y,i.width,i.height,0,0,i.width,i.height),o.restore()},tintWithOverlay:function(t,e,r){var o=r.getContext("2d"),i=t._frame.clone(),n=t.baseTexture.resolution;i.x*=n,i.y*=n,i.width*=n,i.height*=n,r.width=Math.ceil(i.width),r.height=Math.ceil(i.height),o.save(),o.globalCompositeOperation="copy",o.fillStyle="#"+("00000"+(0|e).toString(16)).substr(-6),o.fillRect(0,0,i.width,i.height),o.globalCompositeOperation="destination-atop",o.drawImage(t.baseTexture.getDrawableSource(),i.x,i.y,i.width,i.height,0,0,i.width,i.height),o.restore()},tintWithPerPixel:function(t,e,o){var i=o.getContext("2d"),n=t._frame.clone(),a=t.baseTexture.resolution;n.x*=a,n.y*=a,n.width*=a,n.height*=a,o.width=Math.ceil(n.width),o.height=Math.ceil(n.height),i.save(),i.globalCompositeOperation="copy",i.drawImage(t.baseTexture.getDrawableSource(),n.x,n.y,n.width,n.height,0,0,n.width,n.height),i.restore();for(var s=r.hex2rgb(e),h=s[0],l=s[1],c=s[2],d=i.getImageData(0,0,n.width,n.height),E=d.data,u=0;u<E.length;u+=4)E[u+0]*=h,E[u+1]*=l,E[u+2]*=c;i.putImageData(d,0,0)},roundColor:function(t){var e=d.cacheStepsPerColorChannel,o=r.hex2rgb(t);return o[0]=Math.min(255,o[0]/e*e),o[1]=Math.min(255,o[1]/e*e),o[2]=Math.min(255,o[2]/e*e),r.rgb2hex(o)},cacheStepsPerColorChannel:8,convertTintToImage:!1,canUseMultiply:h(),tintMethod:function(){}};d.tintMethod=d.canUseMultiply?d.tintWithMultiply:d.tintWithPerPixel;var E=e.Renderer.create;return e.Renderer.create=function(t){if(!(t&&t.forceCanvas))try{return E(t)}catch(t){}return new c(t)},e.BaseTexture.prototype.getDrawableSource=function(){var t=this.resource;return t?t.bitmap||t.source:null},t.CanvasRenderer=c,t.canUseNewCanvasBlendModes=h,t.canvasUtils=d,t}({},PIXI,PIXI.utils,PIXI,PIXI,PIXI);Object.assign(this.PIXI,_pixi_canvas_renderer);
//# sourceMappingURL=canvas-renderer.min.js.map
/*!
* @pixi/canvas-renderer - v5.2.1
* Compiled Tue, 28 Jan 2020 23:33:11 UTC
* @pixi/canvas-renderer - v5.2.2
* Compiled Tue, 21 Apr 2020 03:53:51 UTC
*

@@ -10,3 +10,3 @@ * @pixi/canvas-renderer is licensed under the MIT License.

import { CanvasRenderTarget, sayHello, hex2rgb, rgb2hex } from '@pixi/utils';
import { SHAPES } from '@pixi/math';
import { SHAPES, Matrix } from '@pixi/math';
import { BLEND_MODES, SCALE_MODES, RENDERER_TYPE } from '@pixi/constants';

@@ -51,3 +51,2 @@ import { settings } from '@pixi/settings';

var context = renderer.context;
var resolution = renderer.resolution;

@@ -61,10 +60,3 @@ context.beginPath();

this.renderer.context.setTransform(
transform.a * resolution,
transform.b * resolution,
transform.c * resolution,
transform.d * resolution,
transform.tx * resolution,
transform.ty * resolution
);
this.renderer.setContextTransform(transform);

@@ -361,2 +353,4 @@ this.renderGraphicsShape(shape);

var tempMatrix = new Matrix();
/**

@@ -445,2 +439,9 @@ * The CanvasRenderer draws the scene and all its content onto a 2d canvas.

/**
* Projection transform, passed in render() stored here
* @type {null}
* @private
*/
this._projTransform = null;
this.renderingToScreen = false;

@@ -518,2 +519,4 @@

this._projTransform = transform || null;
if (!renderTexture)

@@ -528,29 +531,6 @@ {

var cacheParent = displayObject.parent;
var tempWt = this._tempDisplayObjectParent.transform.worldTransform;
if (transform)
{
transform.copyTo(tempWt);
// Canvas Renderer doesn't use "context.translate"
// nor does it store current translation in projectionSystem
// we re-calculate all matrices,
// its not like CanvasRenderer can survive more than 1000 elements
displayObject.transform._parentID = -1;
}
else
{
// in this case matrix cache in displayObject works like expected
tempWt.identity();
}
displayObject.parent = this._tempDisplayObjectParent;
displayObject.updateTransform();
displayObject.parent = cacheParent;
if (transform)
{
// Clear the matrix cache one more time,
// we dont have our computations to affect standard "transform=null" case
displayObject.transform._parentID = -1;
}
// displayObject.hitArea = //TODO add a temp hit area

@@ -594,2 +574,3 @@ }

this.resolution = rootResolution;
this._projTransform = null;

@@ -600,2 +581,49 @@ this.emit('postrender');

/**
* sets matrix of context
* called only from render() methods
* takes care about resolution
* @param {PIXI.Matrix} transform world matrix of current element
* @param {boolean} [roundPixels] whether to round (tx,ty) coords
* @param {number} [localResolution] If specified, used instead of `renderer.resolution` for local scaling
*/
CanvasRenderer.prototype.setContextTransform = function setContextTransform (transform, roundPixels, localResolution)
{
var mat = transform;
var proj = this._projTransform;
var resolution = this.resolution;
localResolution = localResolution || resolution;
if (proj)
{
mat = tempMatrix;
mat.copyFrom(transform);
mat.prepend(proj);
}
if (roundPixels)
{
this.context.setTransform(
mat.a * localResolution,
mat.b * localResolution,
mat.c * localResolution,
mat.d * localResolution,
(mat.tx * resolution) | 0,
(mat.ty * resolution) | 0
);
}
else
{
this.context.setTransform(
mat.a * localResolution,
mat.b * localResolution,
mat.c * localResolution,
mat.d * localResolution,
mat.tx * resolution,
mat.ty * resolution
);
}
};
/**
* Clear the canvas of renderer.

@@ -770,3 +798,3 @@ *

{
canvas = canvasUtils.canvas || document.createElement('canvas');
canvas = document.createElement('canvas');
}

@@ -790,4 +818,2 @@

texture.tintCache[stringColor] = canvas;
// if we are not converting the texture to an image then we need to lose the reference to the canvas
canvasUtils.canvas = null;
}

@@ -799,2 +825,35 @@

/**
* Basically this method just needs a sprite and a color and tints the sprite with the given color.
*
* @memberof PIXI.canvasUtils
* @param {PIXI.Sprite} sprite - the sprite to tint
* @param {number} color - the color to use to tint the sprite with
* @return {HTMLCanvasElement} The tinted canvas
*/
getTintedPattern: function (texture, color) {
color = canvasUtils.roundColor(color);
var stringColor = "#" + ((("00000" + ((color | 0).toString(16)))).substr(-6));
texture.patternCache = texture.patternCache || {};
var pattern = texture.patternCache[stringColor];
if (pattern && pattern.tintId === texture._updateID)
{
return pattern;
}
if (!canvasUtils.canvas)
{
canvasUtils.canvas = document.createElement('canvas');
}
canvasUtils.tintMethod(texture, color, canvasUtils.canvas);
pattern = canvasUtils.canvas.getContext('2d').createPattern(canvasUtils.canvas, 'repeat');
pattern.tintId = texture._updateID;
texture.patternCache[stringColor] = pattern;
return pattern;
},
/**
* Tint a texture using the 'multiply' operation.

@@ -1050,3 +1109,3 @@ *

return resource ? (resource.bitmap || resource.source) : this.source;
return resource ? (resource.bitmap || resource.source) : null;
};

@@ -1053,0 +1112,0 @@

/*!
* @pixi/canvas-renderer - v5.2.1
* Compiled Tue, 28 Jan 2020 23:33:11 UTC
* @pixi/canvas-renderer - v5.2.2
* Compiled Tue, 21 Apr 2020 03:53:51 UTC
*

@@ -54,3 +54,2 @@ * @pixi/canvas-renderer is licensed under the MIT License.

var context = renderer.context;
var resolution = renderer.resolution;

@@ -64,10 +63,3 @@ context.beginPath();

this.renderer.context.setTransform(
transform.a * resolution,
transform.b * resolution,
transform.c * resolution,
transform.d * resolution,
transform.tx * resolution,
transform.ty * resolution
);
this.renderer.setContextTransform(transform);

@@ -364,2 +356,4 @@ this.renderGraphicsShape(shape);

var tempMatrix = new math.Matrix();
/**

@@ -448,2 +442,9 @@ * The CanvasRenderer draws the scene and all its content onto a 2d canvas.

/**
* Projection transform, passed in render() stored here
* @type {null}
* @private
*/
this._projTransform = null;
this.renderingToScreen = false;

@@ -521,2 +522,4 @@

this._projTransform = transform || null;
if (!renderTexture)

@@ -531,29 +534,6 @@ {

var cacheParent = displayObject.parent;
var tempWt = this._tempDisplayObjectParent.transform.worldTransform;
if (transform)
{
transform.copyTo(tempWt);
// Canvas Renderer doesn't use "context.translate"
// nor does it store current translation in projectionSystem
// we re-calculate all matrices,
// its not like CanvasRenderer can survive more than 1000 elements
displayObject.transform._parentID = -1;
}
else
{
// in this case matrix cache in displayObject works like expected
tempWt.identity();
}
displayObject.parent = this._tempDisplayObjectParent;
displayObject.updateTransform();
displayObject.parent = cacheParent;
if (transform)
{
// Clear the matrix cache one more time,
// we dont have our computations to affect standard "transform=null" case
displayObject.transform._parentID = -1;
}
// displayObject.hitArea = //TODO add a temp hit area

@@ -597,2 +577,3 @@ }

this.resolution = rootResolution;
this._projTransform = null;

@@ -603,2 +584,49 @@ this.emit('postrender');

/**
* sets matrix of context
* called only from render() methods
* takes care about resolution
* @param {PIXI.Matrix} transform world matrix of current element
* @param {boolean} [roundPixels] whether to round (tx,ty) coords
* @param {number} [localResolution] If specified, used instead of `renderer.resolution` for local scaling
*/
CanvasRenderer.prototype.setContextTransform = function setContextTransform (transform, roundPixels, localResolution)
{
var mat = transform;
var proj = this._projTransform;
var resolution = this.resolution;
localResolution = localResolution || resolution;
if (proj)
{
mat = tempMatrix;
mat.copyFrom(transform);
mat.prepend(proj);
}
if (roundPixels)
{
this.context.setTransform(
mat.a * localResolution,
mat.b * localResolution,
mat.c * localResolution,
mat.d * localResolution,
(mat.tx * resolution) | 0,
(mat.ty * resolution) | 0
);
}
else
{
this.context.setTransform(
mat.a * localResolution,
mat.b * localResolution,
mat.c * localResolution,
mat.d * localResolution,
mat.tx * resolution,
mat.ty * resolution
);
}
};
/**
* Clear the canvas of renderer.

@@ -773,3 +801,3 @@ *

{
canvas = canvasUtils.canvas || document.createElement('canvas');
canvas = document.createElement('canvas');
}

@@ -793,4 +821,2 @@

texture.tintCache[stringColor] = canvas;
// if we are not converting the texture to an image then we need to lose the reference to the canvas
canvasUtils.canvas = null;
}

@@ -802,2 +828,35 @@

/**
* Basically this method just needs a sprite and a color and tints the sprite with the given color.
*
* @memberof PIXI.canvasUtils
* @param {PIXI.Sprite} sprite - the sprite to tint
* @param {number} color - the color to use to tint the sprite with
* @return {HTMLCanvasElement} The tinted canvas
*/
getTintedPattern: function (texture, color) {
color = canvasUtils.roundColor(color);
var stringColor = "#" + ((("00000" + ((color | 0).toString(16)))).substr(-6));
texture.patternCache = texture.patternCache || {};
var pattern = texture.patternCache[stringColor];
if (pattern && pattern.tintId === texture._updateID)
{
return pattern;
}
if (!canvasUtils.canvas)
{
canvasUtils.canvas = document.createElement('canvas');
}
canvasUtils.tintMethod(texture, color, canvasUtils.canvas);
pattern = canvasUtils.canvas.getContext('2d').createPattern(canvasUtils.canvas, 'repeat');
pattern.tintId = texture._updateID;
texture.patternCache[stringColor] = pattern;
return pattern;
},
/**
* Tint a texture using the 'multiply' operation.

@@ -1053,3 +1112,3 @@ *

return resource ? (resource.bitmap || resource.source) : this.source;
return resource ? (resource.bitmap || resource.source) : null;
};

@@ -1056,0 +1115,0 @@

{
"name": "@pixi/canvas-renderer",
"version": "5.2.1",
"version": "5.2.2",
"main": "lib/canvas-renderer.js",

@@ -27,14 +27,14 @@ "module": "lib/canvas-renderer.es.js",

"dependencies": {
"@pixi/constants": "5.2.1",
"@pixi/core": "5.2.1",
"@pixi/math": "5.2.1",
"@pixi/settings": "5.2.1",
"@pixi/utils": "5.2.1"
"@pixi/constants": "5.2.2",
"@pixi/core": "5.2.2",
"@pixi/math": "5.2.2",
"@pixi/settings": "5.2.2",
"@pixi/utils": "5.2.2"
},
"devDependencies": {
"@pixi/display": "5.2.1",
"@pixi/graphics": "5.2.1",
"@pixi/sprite": "5.2.1"
"@pixi/display": "5.2.2",
"@pixi/graphics": "5.2.2",
"@pixi/sprite": "5.2.2"
},
"gitHead": "b56b4fca1c169f0e6d2a0472251ba1f7399bb4a3"
"gitHead": "c163c466c20f2286b6e41ab90d68a03aad2051d4"
}

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc