Socket
Socket
Sign inDemoInstall

@pixi/canvas-renderer

Package Overview
Dependencies
Maintainers
3
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 7.0.0-beta.3 to 7.0.0-beta.4

6

dist/cjs/canvas-renderer.js
/*!
* @pixi/canvas-renderer - v7.0.0-beta.3
* Compiled Thu, 13 Oct 2022 15:35:43 UTC
* @pixi/canvas-renderer - v7.0.0-beta.4
* Compiled Thu, 20 Oct 2022 19:45:44 UTC
*

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

let pattern = texture.patternCache[stringColor];
if (pattern && pattern.tintId === texture._updateID) {
if (pattern?.tintId === texture._updateID) {
return pattern;

@@ -627,0 +627,0 @@ }

"use strict";/*!
* @pixi/canvas-renderer - v7.0.0-beta.3
* Compiled Thu, 13 Oct 2022 15:35:43 UTC
* @pixi/canvas-renderer - v7.0.0-beta.4
* Compiled Thu, 20 Oct 2022 19:45:44 UTC
*
* @pixi/canvas-renderer is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/Object.defineProperty(exports,"__esModule",{value:!0});var r=require("@pixi/core");const{deprecation:b}=r.utils,x=class extends r.SystemManager{constructor(e){super(),this.rendererLogId="Canvas",e=Object.assign({},r.settings.RENDER_OPTIONS,e);const o={runners:["init","destroy","contextChange","reset","update","postrender","prerender","resize"],systems:x.__systems,priority:["textureGenerator","background","_view","_plugin","startup","mask","canvasContext","objectRenderer"]};this.setup(o);const n={hello:e.hello,_plugin:x.__plugins,background:{alpha:e.backgroundAlpha,color:e.background??e.backgroundColor,clearBeforeRender:e.clearBeforeRender},_view:{height:e.height,width:e.width,autoDensity:e.autoDensity,resolution:e.resolution}};this.startup.run(n)}static test(){return!0}generateTexture(e,o){return this.textureGenerator.generateTexture(e,o)}reset(){}render(e,o){this.objectRenderer.render(e,o)}clear(){this.canvasContext.clear()}destroy(e){this.runners.destroy.items.reverse(),this.emitWithCustomOptions(this.runners.destroy,{_view:e}),super.destroy()}get plugins(){return this._plugin.plugins}resize(e,o){this._view.resizeView(e,o)}get width(){return this._view.element.width}get height(){return this._view.element.height}get resolution(){return this._view.resolution}get autoDensity(){return this._view.autoDensity}get view(){return this._view.element}get screen(){return this._view.screen}get lastObjectRendered(){return this.objectRenderer.lastObjectRendered}get renderingToScreen(){return this.objectRenderer.renderingToScreen}get clearBeforeRender(){return this.background.clearBeforeRender}get blendModes(){return this.canvasContext.blendModes}get maskManager(){return b("7.0.0","renderer.maskManager has been deprecated, please use renderer.mask instead"),this.mask}get refresh(){return!0}get rootContext(){return this.canvasContext.rootContext}get context(){return this.canvasContext.activeContext}get smoothProperty(){return this.canvasContext.smoothProperty}setBlendMode(e,o){this.canvasContext.setBlendMode(e,o)}invalidateBlendMode(){this.canvasContext.invalidateBlendMode()}setContextTransform(e,o,n){this.canvasContext.setContextTransform(e,o,n)}get backgroundColor(){return this.background.color}set backgroundColor(e){this.background.color=e}get backgroundAlpha(){return this.background.color}set backgroundAlpha(e){this.background.alpha=e}get preserveDrawingBuffer(){return!1}get useContextAlpha(){return!1}};let S=x;S.extension={type:r.ExtensionType.Renderer,priority:0},S.__plugins={},S.__systems={},r.extensions.handleByMap(r.ExtensionType.CanvasRendererPlugin,S.__plugins),r.extensions.handleByMap(r.ExtensionType.CanvasRendererSystem,S.__systems),r.extensions.add(S);class M{constructor(o){this._foundShapes=[],this.renderer=o}pushMask(o){const n=this.renderer,s=o.maskObject||o;n.canvasContext.activeContext.save();const t=this._foundShapes;if(this.recursiveFindShapes(s,t),t.length>0){const i=n.canvasContext.activeContext;i.beginPath();for(let u=0;u<t.length;u++){const c=t[u],a=c.transform.worldTransform;this.renderer.canvasContext.setContextTransform(a),this.renderGraphicsShape(c)}t.length=0,i.clip()}}recursiveFindShapes(o,n){o.geometry&&o.geometry.graphicsData&&n.push(o);const{children:s}=o;if(s)for(let t=0;t<s.length;t++)this.recursiveFindShapes(s[t],n)}renderGraphicsShape(o){o.finishPoly();const n=this.renderer.canvasContext.activeContext,s=o.geometry.graphicsData,t=s.length;if(t!==0)for(let i=0;i<t;i++){const u=s[i],c=u.shape;if(c.type===r.SHAPES.POLY){let a=c.points;const d=u.holes;let h,g,l,v;n.moveTo(a[0],a[1]);for(let E=1;E<a.length/2;E++)n.lineTo(a[E*2],a[E*2+1]);if(d.length>0){h=0,l=a[0],v=a[1];for(let E=2;E+2<a.length;E+=2)h+=(a[E]-l)*(a[E+3]-v)-(a[E+2]-l)*(a[E+1]-v);for(let E=0;E<d.length;E++)if(a=d[E].shape.points,!!a){g=0,l=a[0],v=a[1];for(let p=2;p+2<a.length;p+=2)g+=(a[p]-l)*(a[p+3]-v)-(a[p+2]-l)*(a[p+1]-v);if(g*h<0){n.moveTo(a[0],a[1]);for(let p=2;p<a.length;p+=2)n.lineTo(a[p],a[p+1])}else{n.moveTo(a[a.length-2],a[a.length-1]);for(let p=a.length-4;p>=0;p-=2)n.lineTo(a[p],a[p+1])}d[E].shape.closeStroke&&n.closePath()}}a[0]===a[a.length-2]&&a[1]===a[a.length-1]&&n.closePath()}else if(c.type===r.SHAPES.RECT)n.rect(c.x,c.y,c.width,c.height),n.closePath();else if(c.type===r.SHAPES.CIRC)n.arc(c.x,c.y,c.radius,0,2*Math.PI),n.closePath();else if(c.type===r.SHAPES.ELIP){const a=c.width*2,d=c.height*2,h=c.x-a/2,g=c.y-d/2,l=.5522848,v=a/2*l,E=d/2*l,p=h+a,m=g+d,_=h+a/2,C=g+d/2;n.moveTo(h,C),n.bezierCurveTo(h,C-E,_-v,g,_,g),n.bezierCurveTo(_+v,g,p,C-E,p,C),n.bezierCurveTo(p,C+E,_+v,m,_,m),n.bezierCurveTo(_-v,m,h,C+E,h,C),n.closePath()}else if(c.type===r.SHAPES.RREC){const a=c.x,d=c.y,h=c.width,g=c.height;let l=c.radius;const v=Math.min(h,g)/2;l=l>v?v:l,n.moveTo(a,d+l),n.lineTo(a,d+g-l),n.quadraticCurveTo(a,d+g,a+l,d+g),n.lineTo(a+h-l,d+g),n.quadraticCurveTo(a+h,d+g,a+h,d+g-l),n.lineTo(a+h,d+l),n.quadraticCurveTo(a+h,d,a+h-l,d),n.lineTo(a+l,d),n.quadraticCurveTo(a,d,a,d+l),n.closePath()}}}popMask(o){o.canvasContext.activeContext.restore(),o.canvasContext.invalidateBlendMode()}destroy(){}}M.extension={type:r.ExtensionType.CanvasRendererSystem,name:"mask"},r.extensions.add(M);class O{constructor(o){this.renderer=o}render(o,n){const s=this.renderer;if(!s.view)return;const t=s.canvasContext;let i,u,c,a;n&&(i=n.renderTexture,u=n.clear,c=n.transform,a=n.skipUpdateTransform),this.renderingToScreen=!i,s.emit("prerender");const d=s.resolution;i?(i=i.castToBaseTexture(),i._canvasRenderTarget||(i._canvasRenderTarget=new r.utils.CanvasRenderTarget(i.width,i.height,i.resolution),i.resource=new r.CanvasResource(i._canvasRenderTarget.canvas),i.valid=!0),t.activeContext=i._canvasRenderTarget.context,s.canvasContext.activeResolution=i._canvasRenderTarget.resolution):(t.activeContext=t.rootContext,t.activeResolution=d);const h=t.activeContext;if(t._projTransform=c||null,i||(this.lastObjectRendered=o),!a){const l=o.enableTempParent();o.updateTransform(),o.disableTempParent(l)}if(h.save(),h.setTransform(1,0,0,1,0,0),h.globalAlpha=1,t._activeBlendMode=r.BLEND_MODES.NORMAL,t._outerBlend=!1,h.globalCompositeOperation=t.blendModes[r.BLEND_MODES.NORMAL],u??s.background.clearBeforeRender)if(this.renderingToScreen){h.clearRect(0,0,s.width,s.height);const l=s.background;l.alpha>0&&(h.globalAlpha=l.alpha,h.fillStyle=l.colorString,h.fillRect(0,0,s.width,s.height),h.globalAlpha=1)}else{i=i,i._canvasRenderTarget.clear();const l=i.clearColor;l[3]>0&&(h.globalAlpha=l[3]??1,h.fillStyle=r.utils.hex2string(r.utils.rgb2hex(l)),h.fillRect(0,0,i.realWidth,i.realHeight),h.globalAlpha=1)}const g=t.activeContext;t.activeContext=h,o.renderCanvas(s),t.activeContext=g,h.restore(),t.activeResolution=d,t._projTransform=null,s.emit("postrender")}destroy(){this.lastObjectRendered=null,this.render=null}}O.extension={type:r.ExtensionType.CanvasRendererSystem,name:"objectRenderer"},r.extensions.add(O);function R(e){const o=r.settings.ADAPTER.createCanvas(6,1),n=o.getContext("2d");return n.fillStyle=e,n.fillRect(0,0,6,1),o}function T(){if(typeof document>"u")return!1;const e=R("#ff00ff"),o=R("#ffff00"),n=r.settings.ADAPTER.createCanvas(6,1).getContext("2d");n.globalCompositeOperation="multiply",n.drawImage(e,0,0),n.drawImage(o,2,0);const s=n.getImageData(2,0,1,1);if(!s)return!1;const t=s.data;return t[0]===255&&t[1]===0&&t[2]===0}function f(e=[]){return T()?(e[r.BLEND_MODES.NORMAL]="source-over",e[r.BLEND_MODES.ADD]="lighter",e[r.BLEND_MODES.MULTIPLY]="multiply",e[r.BLEND_MODES.SCREEN]="screen",e[r.BLEND_MODES.OVERLAY]="overlay",e[r.BLEND_MODES.DARKEN]="darken",e[r.BLEND_MODES.LIGHTEN]="lighten",e[r.BLEND_MODES.COLOR_DODGE]="color-dodge",e[r.BLEND_MODES.COLOR_BURN]="color-burn",e[r.BLEND_MODES.HARD_LIGHT]="hard-light",e[r.BLEND_MODES.SOFT_LIGHT]="soft-light",e[r.BLEND_MODES.DIFFERENCE]="difference",e[r.BLEND_MODES.EXCLUSION]="exclusion",e[r.BLEND_MODES.HUE]="hue",e[r.BLEND_MODES.SATURATION]="saturation",e[r.BLEND_MODES.COLOR]="color",e[r.BLEND_MODES.LUMINOSITY]="luminosity"):(e[r.BLEND_MODES.NORMAL]="source-over",e[r.BLEND_MODES.ADD]="lighter",e[r.BLEND_MODES.MULTIPLY]="source-over",e[r.BLEND_MODES.SCREEN]="source-over",e[r.BLEND_MODES.OVERLAY]="source-over",e[r.BLEND_MODES.DARKEN]="source-over",e[r.BLEND_MODES.LIGHTEN]="source-over",e[r.BLEND_MODES.COLOR_DODGE]="source-over",e[r.BLEND_MODES.COLOR_BURN]="source-over",e[r.BLEND_MODES.HARD_LIGHT]="source-over",e[r.BLEND_MODES.SOFT_LIGHT]="source-over",e[r.BLEND_MODES.DIFFERENCE]="source-over",e[r.BLEND_MODES.EXCLUSION]="source-over",e[r.BLEND_MODES.HUE]="source-over",e[r.BLEND_MODES.SATURATION]="source-over",e[r.BLEND_MODES.COLOR]="source-over",e[r.BLEND_MODES.LUMINOSITY]="source-over"),e[r.BLEND_MODES.NORMAL_NPM]=e[r.BLEND_MODES.NORMAL],e[r.BLEND_MODES.ADD_NPM]=e[r.BLEND_MODES.ADD],e[r.BLEND_MODES.SCREEN_NPM]=e[r.BLEND_MODES.SCREEN],e[r.BLEND_MODES.SRC_IN]="source-in",e[r.BLEND_MODES.SRC_OUT]="source-out",e[r.BLEND_MODES.SRC_ATOP]="source-atop",e[r.BLEND_MODES.DST_OVER]="destination-over",e[r.BLEND_MODES.DST_IN]="destination-in",e[r.BLEND_MODES.DST_OUT]="destination-out",e[r.BLEND_MODES.DST_ATOP]="destination-atop",e[r.BLEND_MODES.XOR]="xor",e[r.BLEND_MODES.SUBTRACT]="source-over",e}const L=new r.Matrix;class y{constructor(o){this.activeResolution=1,this.smoothProperty="imageSmoothingEnabled",this.blendModes=f(),this._activeBlendMode=null,this._projTransform=null,this._outerBlend=!1,this.renderer=o}init(){const o=this.renderer.background.alpha<1;if(this.rootContext=this.renderer.view.getContext("2d",{alpha:o}),this.activeContext=this.rootContext,!this.rootContext.imageSmoothingEnabled){const n=this.rootContext;n.webkitImageSmoothingEnabled?this.smoothProperty="webkitImageSmoothingEnabled":n.mozImageSmoothingEnabled?this.smoothProperty="mozImageSmoothingEnabled":n.oImageSmoothingEnabled?this.smoothProperty="oImageSmoothingEnabled":n.msImageSmoothingEnabled&&(this.smoothProperty="msImageSmoothingEnabled")}}setContextTransform(o,n,s){let t=o;const i=this._projTransform,u=this.activeResolution;s=s||u,i&&(t=L,t.copyFrom(o),t.prepend(i)),n?this.activeContext.setTransform(t.a*s,t.b*s,t.c*s,t.d*s,t.tx*u|0,t.ty*u|0):this.activeContext.setTransform(t.a*s,t.b*s,t.c*s,t.d*s,t.tx*u,t.ty*u)}clear(o,n){const{activeContext:s,renderer:t}=this;o=o??this.renderer.background.colorString,s.clearRect(0,0,t.width,t.height),o&&(s.globalAlpha=n??this.renderer.background.alpha,s.fillStyle=o,s.fillRect(0,0,t.width,t.height),s.globalAlpha=1)}setBlendMode(o,n){const s=o===r.BLEND_MODES.SRC_IN||o===r.BLEND_MODES.SRC_OUT||o===r.BLEND_MODES.DST_IN||o===r.BLEND_MODES.DST_ATOP;!n&&s&&(o=r.BLEND_MODES.NORMAL),this._activeBlendMode!==o&&(this._activeBlendMode=o,this._outerBlend=s,this.activeContext.globalCompositeOperation=this.blendModes[o])}resize(){this.smoothProperty&&(this.rootContext[this.smoothProperty]=r.settings.SCALE_MODE===r.SCALE_MODES.LINEAR)}invalidateBlendMode(){this._activeBlendMode=this.blendModes.indexOf(this.activeContext.globalCompositeOperation)}destroy(){this.renderer=null,this.rootContext=null,this.activeContext=null,this.smoothProperty=null}}y.extension={type:r.ExtensionType.CanvasRendererSystem,name:"canvasContext"},r.extensions.add(y);const D={canvas:null,getTintedCanvas:(e,o)=>{const n=e.texture;o=D.roundColor(o);const s=`#${`00000${(o|0).toString(16)}`.slice(-6)}`;n.tintCache=n.tintCache||{};const t=n.tintCache[s];let i;if(t){if(t.tintId===n._updateID)return n.tintCache[s];i=n.tintCache[s]}else i=r.settings.ADAPTER.createCanvas();if(D.tintMethod(n,o,i),i.tintId=n._updateID,D.convertTintToImage&&i.toDataURL!==void 0){const u=new Image;u.src=i.toDataURL(),n.tintCache[s]=u}else n.tintCache[s]=i;return i},getTintedPattern:(e,o)=>{o=D.roundColor(o);const n=`#${`00000${(o|0).toString(16)}`.slice(-6)}`;e.patternCache=e.patternCache||{};let s=e.patternCache[n];return s&&s.tintId===e._updateID||(D.canvas||(D.canvas=r.settings.ADAPTER.createCanvas()),D.tintMethod(e,o,D.canvas),s=D.canvas.getContext("2d").createPattern(D.canvas,"repeat"),s.tintId=e._updateID,e.patternCache[n]=s),s},tintWithMultiply:(e,o,n)=>{const s=n.getContext("2d"),t=e._frame.clone(),i=e.baseTexture.resolution;t.x*=i,t.y*=i,t.width*=i,t.height*=i,n.width=Math.ceil(t.width),n.height=Math.ceil(t.height),s.save(),s.fillStyle=`#${`00000${(o|0).toString(16)}`.slice(-6)}`,s.fillRect(0,0,t.width,t.height),s.globalCompositeOperation="multiply";const u=e.baseTexture.getDrawableSource();s.drawImage(u,t.x,t.y,t.width,t.height,0,0,t.width,t.height),s.globalCompositeOperation="destination-atop",s.drawImage(u,t.x,t.y,t.width,t.height,0,0,t.width,t.height),s.restore()},tintWithOverlay:(e,o,n)=>{const s=n.getContext("2d"),t=e._frame.clone(),i=e.baseTexture.resolution;t.x*=i,t.y*=i,t.width*=i,t.height*=i,n.width=Math.ceil(t.width),n.height=Math.ceil(t.height),s.save(),s.globalCompositeOperation="copy",s.fillStyle=`#${`00000${(o|0).toString(16)}`.slice(-6)}`,s.fillRect(0,0,t.width,t.height),s.globalCompositeOperation="destination-atop",s.drawImage(e.baseTexture.getDrawableSource(),t.x,t.y,t.width,t.height,0,0,t.width,t.height),s.restore()},tintWithPerPixel:(e,o,n)=>{const s=n.getContext("2d"),t=e._frame.clone(),i=e.baseTexture.resolution;t.x*=i,t.y*=i,t.width*=i,t.height*=i,n.width=Math.ceil(t.width),n.height=Math.ceil(t.height),s.save(),s.globalCompositeOperation="copy",s.drawImage(e.baseTexture.getDrawableSource(),t.x,t.y,t.width,t.height,0,0,t.width,t.height),s.restore();const u=r.utils.hex2rgb(o),c=u[0],a=u[1],d=u[2],h=s.getImageData(0,0,t.width,t.height),g=h.data;for(let l=0;l<g.length;l+=4)g[l+0]*=c,g[l+1]*=a,g[l+2]*=d;s.putImageData(h,0,0)},roundColor:e=>{const o=D.cacheStepsPerColorChannel,n=r.utils.hex2rgb(e);return n[0]=Math.min(255,n[0]/o*o),n[1]=Math.min(255,n[1]/o*o),n[2]=Math.min(255,n[2]/o*o),r.utils.rgb2hex(n)},cacheStepsPerColorChannel:8,convertTintToImage:!1,canUseMultiply:T(),tintMethod:null};D.tintMethod=D.canUseMultiply?D.tintWithMultiply:D.tintWithPerPixel,r.BaseTexture.prototype.getDrawableSource=function(){const e=this.resource;return e?e.bitmap||e.source:null},r.BaseRenderTexture.prototype._canvasRenderTarget=null,r.Texture.prototype.patternCache=null,r.Texture.prototype.tintCache=null,exports.CanvasContextSystem=y,exports.CanvasMaskSystem=M,exports.CanvasObjectRendererSystem=O,exports.CanvasRenderer=S,exports.canUseNewCanvasBlendModes=T,exports.canvasUtils=D;
*/Object.defineProperty(exports,"__esModule",{value:!0});var r=require("@pixi/core");const{deprecation:b}=r.utils,x=class extends r.SystemManager{constructor(e){super(),this.rendererLogId="Canvas",e=Object.assign({},r.settings.RENDER_OPTIONS,e);const o={runners:["init","destroy","contextChange","reset","update","postrender","prerender","resize"],systems:x.__systems,priority:["textureGenerator","background","_view","_plugin","startup","mask","canvasContext","objectRenderer"]};this.setup(o);const n={hello:e.hello,_plugin:x.__plugins,background:{alpha:e.backgroundAlpha,color:e.background??e.backgroundColor,clearBeforeRender:e.clearBeforeRender},_view:{height:e.height,width:e.width,autoDensity:e.autoDensity,resolution:e.resolution}};this.startup.run(n)}static test(){return!0}generateTexture(e,o){return this.textureGenerator.generateTexture(e,o)}reset(){}render(e,o){this.objectRenderer.render(e,o)}clear(){this.canvasContext.clear()}destroy(e){this.runners.destroy.items.reverse(),this.emitWithCustomOptions(this.runners.destroy,{_view:e}),super.destroy()}get plugins(){return this._plugin.plugins}resize(e,o){this._view.resizeView(e,o)}get width(){return this._view.element.width}get height(){return this._view.element.height}get resolution(){return this._view.resolution}get autoDensity(){return this._view.autoDensity}get view(){return this._view.element}get screen(){return this._view.screen}get lastObjectRendered(){return this.objectRenderer.lastObjectRendered}get renderingToScreen(){return this.objectRenderer.renderingToScreen}get clearBeforeRender(){return this.background.clearBeforeRender}get blendModes(){return this.canvasContext.blendModes}get maskManager(){return b("7.0.0","renderer.maskManager has been deprecated, please use renderer.mask instead"),this.mask}get refresh(){return!0}get rootContext(){return this.canvasContext.rootContext}get context(){return this.canvasContext.activeContext}get smoothProperty(){return this.canvasContext.smoothProperty}setBlendMode(e,o){this.canvasContext.setBlendMode(e,o)}invalidateBlendMode(){this.canvasContext.invalidateBlendMode()}setContextTransform(e,o,n){this.canvasContext.setContextTransform(e,o,n)}get backgroundColor(){return this.background.color}set backgroundColor(e){this.background.color=e}get backgroundAlpha(){return this.background.color}set backgroundAlpha(e){this.background.alpha=e}get preserveDrawingBuffer(){return!1}get useContextAlpha(){return!1}};let S=x;S.extension={type:r.ExtensionType.Renderer,priority:0},S.__plugins={},S.__systems={},r.extensions.handleByMap(r.ExtensionType.CanvasRendererPlugin,S.__plugins),r.extensions.handleByMap(r.ExtensionType.CanvasRendererSystem,S.__systems),r.extensions.add(S);class M{constructor(o){this._foundShapes=[],this.renderer=o}pushMask(o){const n=this.renderer,s=o.maskObject||o;n.canvasContext.activeContext.save();const t=this._foundShapes;if(this.recursiveFindShapes(s,t),t.length>0){const i=n.canvasContext.activeContext;i.beginPath();for(let u=0;u<t.length;u++){const c=t[u],a=c.transform.worldTransform;this.renderer.canvasContext.setContextTransform(a),this.renderGraphicsShape(c)}t.length=0,i.clip()}}recursiveFindShapes(o,n){o.geometry&&o.geometry.graphicsData&&n.push(o);const{children:s}=o;if(s)for(let t=0;t<s.length;t++)this.recursiveFindShapes(s[t],n)}renderGraphicsShape(o){o.finishPoly();const n=this.renderer.canvasContext.activeContext,s=o.geometry.graphicsData,t=s.length;if(t!==0)for(let i=0;i<t;i++){const u=s[i],c=u.shape;if(c.type===r.SHAPES.POLY){let a=c.points;const d=u.holes;let h,g,l,v;n.moveTo(a[0],a[1]);for(let E=1;E<a.length/2;E++)n.lineTo(a[E*2],a[E*2+1]);if(d.length>0){h=0,l=a[0],v=a[1];for(let E=2;E+2<a.length;E+=2)h+=(a[E]-l)*(a[E+3]-v)-(a[E+2]-l)*(a[E+1]-v);for(let E=0;E<d.length;E++)if(a=d[E].shape.points,!!a){g=0,l=a[0],v=a[1];for(let p=2;p+2<a.length;p+=2)g+=(a[p]-l)*(a[p+3]-v)-(a[p+2]-l)*(a[p+1]-v);if(g*h<0){n.moveTo(a[0],a[1]);for(let p=2;p<a.length;p+=2)n.lineTo(a[p],a[p+1])}else{n.moveTo(a[a.length-2],a[a.length-1]);for(let p=a.length-4;p>=0;p-=2)n.lineTo(a[p],a[p+1])}d[E].shape.closeStroke&&n.closePath()}}a[0]===a[a.length-2]&&a[1]===a[a.length-1]&&n.closePath()}else if(c.type===r.SHAPES.RECT)n.rect(c.x,c.y,c.width,c.height),n.closePath();else if(c.type===r.SHAPES.CIRC)n.arc(c.x,c.y,c.radius,0,2*Math.PI),n.closePath();else if(c.type===r.SHAPES.ELIP){const a=c.width*2,d=c.height*2,h=c.x-a/2,g=c.y-d/2,l=.5522848,v=a/2*l,E=d/2*l,p=h+a,m=g+d,_=h+a/2,C=g+d/2;n.moveTo(h,C),n.bezierCurveTo(h,C-E,_-v,g,_,g),n.bezierCurveTo(_+v,g,p,C-E,p,C),n.bezierCurveTo(p,C+E,_+v,m,_,m),n.bezierCurveTo(_-v,m,h,C+E,h,C),n.closePath()}else if(c.type===r.SHAPES.RREC){const a=c.x,d=c.y,h=c.width,g=c.height;let l=c.radius;const v=Math.min(h,g)/2;l=l>v?v:l,n.moveTo(a,d+l),n.lineTo(a,d+g-l),n.quadraticCurveTo(a,d+g,a+l,d+g),n.lineTo(a+h-l,d+g),n.quadraticCurveTo(a+h,d+g,a+h,d+g-l),n.lineTo(a+h,d+l),n.quadraticCurveTo(a+h,d,a+h-l,d),n.lineTo(a+l,d),n.quadraticCurveTo(a,d,a,d+l),n.closePath()}}}popMask(o){o.canvasContext.activeContext.restore(),o.canvasContext.invalidateBlendMode()}destroy(){}}M.extension={type:r.ExtensionType.CanvasRendererSystem,name:"mask"},r.extensions.add(M);class O{constructor(o){this.renderer=o}render(o,n){const s=this.renderer;if(!s.view)return;const t=s.canvasContext;let i,u,c,a;n&&(i=n.renderTexture,u=n.clear,c=n.transform,a=n.skipUpdateTransform),this.renderingToScreen=!i,s.emit("prerender");const d=s.resolution;i?(i=i.castToBaseTexture(),i._canvasRenderTarget||(i._canvasRenderTarget=new r.utils.CanvasRenderTarget(i.width,i.height,i.resolution),i.resource=new r.CanvasResource(i._canvasRenderTarget.canvas),i.valid=!0),t.activeContext=i._canvasRenderTarget.context,s.canvasContext.activeResolution=i._canvasRenderTarget.resolution):(t.activeContext=t.rootContext,t.activeResolution=d);const h=t.activeContext;if(t._projTransform=c||null,i||(this.lastObjectRendered=o),!a){const l=o.enableTempParent();o.updateTransform(),o.disableTempParent(l)}if(h.save(),h.setTransform(1,0,0,1,0,0),h.globalAlpha=1,t._activeBlendMode=r.BLEND_MODES.NORMAL,t._outerBlend=!1,h.globalCompositeOperation=t.blendModes[r.BLEND_MODES.NORMAL],u??s.background.clearBeforeRender)if(this.renderingToScreen){h.clearRect(0,0,s.width,s.height);const l=s.background;l.alpha>0&&(h.globalAlpha=l.alpha,h.fillStyle=l.colorString,h.fillRect(0,0,s.width,s.height),h.globalAlpha=1)}else{i=i,i._canvasRenderTarget.clear();const l=i.clearColor;l[3]>0&&(h.globalAlpha=l[3]??1,h.fillStyle=r.utils.hex2string(r.utils.rgb2hex(l)),h.fillRect(0,0,i.realWidth,i.realHeight),h.globalAlpha=1)}const g=t.activeContext;t.activeContext=h,o.renderCanvas(s),t.activeContext=g,h.restore(),t.activeResolution=d,t._projTransform=null,s.emit("postrender")}destroy(){this.lastObjectRendered=null,this.render=null}}O.extension={type:r.ExtensionType.CanvasRendererSystem,name:"objectRenderer"},r.extensions.add(O);function R(e){const o=r.settings.ADAPTER.createCanvas(6,1),n=o.getContext("2d");return n.fillStyle=e,n.fillRect(0,0,6,1),o}function T(){if(typeof document>"u")return!1;const e=R("#ff00ff"),o=R("#ffff00"),n=r.settings.ADAPTER.createCanvas(6,1).getContext("2d");n.globalCompositeOperation="multiply",n.drawImage(e,0,0),n.drawImage(o,2,0);const s=n.getImageData(2,0,1,1);if(!s)return!1;const t=s.data;return t[0]===255&&t[1]===0&&t[2]===0}function f(e=[]){return T()?(e[r.BLEND_MODES.NORMAL]="source-over",e[r.BLEND_MODES.ADD]="lighter",e[r.BLEND_MODES.MULTIPLY]="multiply",e[r.BLEND_MODES.SCREEN]="screen",e[r.BLEND_MODES.OVERLAY]="overlay",e[r.BLEND_MODES.DARKEN]="darken",e[r.BLEND_MODES.LIGHTEN]="lighten",e[r.BLEND_MODES.COLOR_DODGE]="color-dodge",e[r.BLEND_MODES.COLOR_BURN]="color-burn",e[r.BLEND_MODES.HARD_LIGHT]="hard-light",e[r.BLEND_MODES.SOFT_LIGHT]="soft-light",e[r.BLEND_MODES.DIFFERENCE]="difference",e[r.BLEND_MODES.EXCLUSION]="exclusion",e[r.BLEND_MODES.HUE]="hue",e[r.BLEND_MODES.SATURATION]="saturation",e[r.BLEND_MODES.COLOR]="color",e[r.BLEND_MODES.LUMINOSITY]="luminosity"):(e[r.BLEND_MODES.NORMAL]="source-over",e[r.BLEND_MODES.ADD]="lighter",e[r.BLEND_MODES.MULTIPLY]="source-over",e[r.BLEND_MODES.SCREEN]="source-over",e[r.BLEND_MODES.OVERLAY]="source-over",e[r.BLEND_MODES.DARKEN]="source-over",e[r.BLEND_MODES.LIGHTEN]="source-over",e[r.BLEND_MODES.COLOR_DODGE]="source-over",e[r.BLEND_MODES.COLOR_BURN]="source-over",e[r.BLEND_MODES.HARD_LIGHT]="source-over",e[r.BLEND_MODES.SOFT_LIGHT]="source-over",e[r.BLEND_MODES.DIFFERENCE]="source-over",e[r.BLEND_MODES.EXCLUSION]="source-over",e[r.BLEND_MODES.HUE]="source-over",e[r.BLEND_MODES.SATURATION]="source-over",e[r.BLEND_MODES.COLOR]="source-over",e[r.BLEND_MODES.LUMINOSITY]="source-over"),e[r.BLEND_MODES.NORMAL_NPM]=e[r.BLEND_MODES.NORMAL],e[r.BLEND_MODES.ADD_NPM]=e[r.BLEND_MODES.ADD],e[r.BLEND_MODES.SCREEN_NPM]=e[r.BLEND_MODES.SCREEN],e[r.BLEND_MODES.SRC_IN]="source-in",e[r.BLEND_MODES.SRC_OUT]="source-out",e[r.BLEND_MODES.SRC_ATOP]="source-atop",e[r.BLEND_MODES.DST_OVER]="destination-over",e[r.BLEND_MODES.DST_IN]="destination-in",e[r.BLEND_MODES.DST_OUT]="destination-out",e[r.BLEND_MODES.DST_ATOP]="destination-atop",e[r.BLEND_MODES.XOR]="xor",e[r.BLEND_MODES.SUBTRACT]="source-over",e}const L=new r.Matrix;class y{constructor(o){this.activeResolution=1,this.smoothProperty="imageSmoothingEnabled",this.blendModes=f(),this._activeBlendMode=null,this._projTransform=null,this._outerBlend=!1,this.renderer=o}init(){const o=this.renderer.background.alpha<1;if(this.rootContext=this.renderer.view.getContext("2d",{alpha:o}),this.activeContext=this.rootContext,!this.rootContext.imageSmoothingEnabled){const n=this.rootContext;n.webkitImageSmoothingEnabled?this.smoothProperty="webkitImageSmoothingEnabled":n.mozImageSmoothingEnabled?this.smoothProperty="mozImageSmoothingEnabled":n.oImageSmoothingEnabled?this.smoothProperty="oImageSmoothingEnabled":n.msImageSmoothingEnabled&&(this.smoothProperty="msImageSmoothingEnabled")}}setContextTransform(o,n,s){let t=o;const i=this._projTransform,u=this.activeResolution;s=s||u,i&&(t=L,t.copyFrom(o),t.prepend(i)),n?this.activeContext.setTransform(t.a*s,t.b*s,t.c*s,t.d*s,t.tx*u|0,t.ty*u|0):this.activeContext.setTransform(t.a*s,t.b*s,t.c*s,t.d*s,t.tx*u,t.ty*u)}clear(o,n){const{activeContext:s,renderer:t}=this;o=o??this.renderer.background.colorString,s.clearRect(0,0,t.width,t.height),o&&(s.globalAlpha=n??this.renderer.background.alpha,s.fillStyle=o,s.fillRect(0,0,t.width,t.height),s.globalAlpha=1)}setBlendMode(o,n){const s=o===r.BLEND_MODES.SRC_IN||o===r.BLEND_MODES.SRC_OUT||o===r.BLEND_MODES.DST_IN||o===r.BLEND_MODES.DST_ATOP;!n&&s&&(o=r.BLEND_MODES.NORMAL),this._activeBlendMode!==o&&(this._activeBlendMode=o,this._outerBlend=s,this.activeContext.globalCompositeOperation=this.blendModes[o])}resize(){this.smoothProperty&&(this.rootContext[this.smoothProperty]=r.settings.SCALE_MODE===r.SCALE_MODES.LINEAR)}invalidateBlendMode(){this._activeBlendMode=this.blendModes.indexOf(this.activeContext.globalCompositeOperation)}destroy(){this.renderer=null,this.rootContext=null,this.activeContext=null,this.smoothProperty=null}}y.extension={type:r.ExtensionType.CanvasRendererSystem,name:"canvasContext"},r.extensions.add(y);const D={canvas:null,getTintedCanvas:(e,o)=>{const n=e.texture;o=D.roundColor(o);const s=`#${`00000${(o|0).toString(16)}`.slice(-6)}`;n.tintCache=n.tintCache||{};const t=n.tintCache[s];let i;if(t){if(t.tintId===n._updateID)return n.tintCache[s];i=n.tintCache[s]}else i=r.settings.ADAPTER.createCanvas();if(D.tintMethod(n,o,i),i.tintId=n._updateID,D.convertTintToImage&&i.toDataURL!==void 0){const u=new Image;u.src=i.toDataURL(),n.tintCache[s]=u}else n.tintCache[s]=i;return i},getTintedPattern:(e,o)=>{o=D.roundColor(o);const n=`#${`00000${(o|0).toString(16)}`.slice(-6)}`;e.patternCache=e.patternCache||{};let s=e.patternCache[n];return s?.tintId===e._updateID||(D.canvas||(D.canvas=r.settings.ADAPTER.createCanvas()),D.tintMethod(e,o,D.canvas),s=D.canvas.getContext("2d").createPattern(D.canvas,"repeat"),s.tintId=e._updateID,e.patternCache[n]=s),s},tintWithMultiply:(e,o,n)=>{const s=n.getContext("2d"),t=e._frame.clone(),i=e.baseTexture.resolution;t.x*=i,t.y*=i,t.width*=i,t.height*=i,n.width=Math.ceil(t.width),n.height=Math.ceil(t.height),s.save(),s.fillStyle=`#${`00000${(o|0).toString(16)}`.slice(-6)}`,s.fillRect(0,0,t.width,t.height),s.globalCompositeOperation="multiply";const u=e.baseTexture.getDrawableSource();s.drawImage(u,t.x,t.y,t.width,t.height,0,0,t.width,t.height),s.globalCompositeOperation="destination-atop",s.drawImage(u,t.x,t.y,t.width,t.height,0,0,t.width,t.height),s.restore()},tintWithOverlay:(e,o,n)=>{const s=n.getContext("2d"),t=e._frame.clone(),i=e.baseTexture.resolution;t.x*=i,t.y*=i,t.width*=i,t.height*=i,n.width=Math.ceil(t.width),n.height=Math.ceil(t.height),s.save(),s.globalCompositeOperation="copy",s.fillStyle=`#${`00000${(o|0).toString(16)}`.slice(-6)}`,s.fillRect(0,0,t.width,t.height),s.globalCompositeOperation="destination-atop",s.drawImage(e.baseTexture.getDrawableSource(),t.x,t.y,t.width,t.height,0,0,t.width,t.height),s.restore()},tintWithPerPixel:(e,o,n)=>{const s=n.getContext("2d"),t=e._frame.clone(),i=e.baseTexture.resolution;t.x*=i,t.y*=i,t.width*=i,t.height*=i,n.width=Math.ceil(t.width),n.height=Math.ceil(t.height),s.save(),s.globalCompositeOperation="copy",s.drawImage(e.baseTexture.getDrawableSource(),t.x,t.y,t.width,t.height,0,0,t.width,t.height),s.restore();const u=r.utils.hex2rgb(o),c=u[0],a=u[1],d=u[2],h=s.getImageData(0,0,t.width,t.height),g=h.data;for(let l=0;l<g.length;l+=4)g[l+0]*=c,g[l+1]*=a,g[l+2]*=d;s.putImageData(h,0,0)},roundColor:e=>{const o=D.cacheStepsPerColorChannel,n=r.utils.hex2rgb(e);return n[0]=Math.min(255,n[0]/o*o),n[1]=Math.min(255,n[1]/o*o),n[2]=Math.min(255,n[2]/o*o),r.utils.rgb2hex(n)},cacheStepsPerColorChannel:8,convertTintToImage:!1,canUseMultiply:T(),tintMethod:null};D.tintMethod=D.canUseMultiply?D.tintWithMultiply:D.tintWithPerPixel,r.BaseTexture.prototype.getDrawableSource=function(){const e=this.resource;return e?e.bitmap||e.source:null},r.BaseRenderTexture.prototype._canvasRenderTarget=null,r.Texture.prototype.patternCache=null,r.Texture.prototype.tintCache=null,exports.CanvasContextSystem=y,exports.CanvasMaskSystem=M,exports.CanvasObjectRendererSystem=O,exports.CanvasRenderer=S,exports.canUseNewCanvasBlendModes=T,exports.canvasUtils=D;
//# sourceMappingURL=canvas-renderer.min.js.map
{
"name": "@pixi/canvas-renderer",
"version": "7.0.0-beta.3",
"version": "7.0.0-beta.4",
"main": "dist/cjs/canvas-renderer.js",

@@ -41,3 +41,3 @@ "module": "dist/esm/canvas-renderer.mjs",

],
"gitHead": "8055ae1c16d4c0f8dabda86cafd8e68c356450e8"
"gitHead": "a4581e4a49d23afc98fcf726765c9d54e51c3c39"
}

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

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