Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pixi/canvas-sprite-tiling

Package Overview
Dependencies
Maintainers
3
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pixi/canvas-sprite-tiling - npm Package Compare versions

Comparing version 6.5.3 to 7.0.0-alpha

192

dist/cjs/canvas-sprite-tiling.js
/*!
* @pixi/canvas-sprite-tiling - v6.5.3
* Compiled Fri, 09 Sep 2022 13:55:20 UTC
* @pixi/canvas-sprite-tiling - v7.0.0-alpha
* Compiled Fri, 09 Sep 2022 16:09:18 UTC
*

@@ -12,138 +12,62 @@ * @pixi/canvas-sprite-tiling is licensed under the MIT License.

var canvasRenderer = require('@pixi/canvas-renderer');
var utils = require('@pixi/utils');
var math = require('@pixi/math');
var core = require('@pixi/core');
var worldMatrix = new math.Matrix();
var patternMatrix = new math.Matrix();
var patternRect = [new math.Point(), new math.Point(), new math.Point(), new math.Point()];
/**
* Renders the object using the Canvas renderer
* @protected
* @function _renderCanvas
* @memberof PIXI.TilingSprite#
* @param {PIXI.CanvasRenderer} renderer - a reference to the canvas renderer
*/
const worldMatrix = new core.Matrix();
const patternMatrix = new core.Matrix();
const patternRect = [new core.Point(), new core.Point(), new core.Point(), new core.Point()];
spriteTiling.TilingSprite.prototype._renderCanvas = function _renderCanvas(renderer) {
var texture = this._texture;
if (!texture.baseTexture.valid) {
return;
const texture = this._texture;
if (!texture.baseTexture.valid) {
return;
}
const context = renderer.canvasContext.activeContext;
const transform = this.worldTransform;
const baseTexture = texture.baseTexture;
const source = baseTexture.getDrawableSource();
const baseTextureResolution = baseTexture.resolution;
if (this._textureID !== this._texture._updateID || this._cachedTint !== this.tint) {
this._textureID = this._texture._updateID;
const tempCanvas = new core.utils.CanvasRenderTarget(texture._frame.width, texture._frame.height, baseTextureResolution);
if (this.tint !== 16777215) {
this._tintedCanvas = canvasRenderer.canvasUtils.getTintedCanvas(this, this.tint);
tempCanvas.context.drawImage(this._tintedCanvas, 0, 0);
} else {
tempCanvas.context.drawImage(source, -texture._frame.x * baseTextureResolution, -texture._frame.y * baseTextureResolution);
}
var context = renderer.context;
var transform = this.worldTransform;
var baseTexture = texture.baseTexture;
var source = baseTexture.getDrawableSource();
var baseTextureResolution = baseTexture.resolution;
// create a nice shiny pattern!
if (this._textureID !== this._texture._updateID || this._cachedTint !== this.tint) {
this._textureID = this._texture._updateID;
// cut an object from a spritesheet..
var tempCanvas = new utils.CanvasRenderTarget(texture._frame.width, texture._frame.height, baseTextureResolution);
// Tint the tiling sprite
if (this.tint !== 0xFFFFFF) {
this._tintedCanvas = canvasRenderer.canvasUtils.getTintedCanvas(this, this.tint);
tempCanvas.context.drawImage(this._tintedCanvas, 0, 0);
}
else {
tempCanvas.context.drawImage(source, -texture._frame.x * baseTextureResolution, -texture._frame.y * baseTextureResolution);
}
this._cachedTint = this.tint;
this._canvasPattern = tempCanvas.context.createPattern(tempCanvas.canvas, 'repeat');
}
// set context state..
context.globalAlpha = this.worldAlpha;
renderer.setBlendMode(this.blendMode);
this.tileTransform.updateLocalTransform();
var lt = this.tileTransform.localTransform;
var W = this._width;
var H = this._height;
/*
* # Implementation Notes
*
* The tiling transform is not simply a transform on the tiling sprite's local space. If that
* were, the bounds of the tiling sprite would change. Rather the tile transform is a transform
* on the "pattern" coordinates each vertex is assigned.
*
* To implement the `tileTransform`, we issue drawing commands in the pattern's own space, which
* is defined as:
*
* Pattern_Space = Local_Space x inverse(tileTransform)
*
* In other words,
* Local_Space = Pattern_Space x tileTransform
*
* We draw the pattern in pattern space, because the space we draw in defines the pattern's coordinates.
* In other words, the pattern will always "originate" from (0, 0) in the space we draw in.
*
* This technique is equivalent to drawing a pattern texture, and then finding a quadrilateral that becomes
* the tiling sprite's local bounds under the tileTransform and mapping that onto the screen.
*
* ## uvRespectAnchor
*
* The preceding paragraph discusses the case without considering `uvRespectAnchor`. The `uvRespectAnchor` flags
* where the origin of the pattern space is. Assuming the tileTransform includes no translation, without
* loss of generality: If uvRespectAnchor = true, then
*
* Local Space (0, 0) <--> Pattern Space (0, 0) (where <--> means "maps to")
*
* Here the mapping is provided by trivially by the tileTransform (note tileTransform includes no translation. That
* means the invariant under all other transforms are the origins)
*
* Otherwise,
*
* Local Space (-localBounds.x, -localBounds.y) <--> Pattern Space (0, 0)
*
* Here the mapping is provided by the tileTransfrom PLUS some "shift". This shift is done POST-tileTransform. The shift
* is equal to the position of the top-left corner of the tiling sprite in its local space.
*
* Hence,
*
* Local_Space = Pattern_Space x tileTransform x shiftTransform
*/
// worldMatrix is used to convert from pattern space to world space.
//
// worldMatrix = tileTransform x shiftTransform x worldTransfrom
// = patternMatrix x worldTransform
worldMatrix.identity();
// patternMatrix is used to convert from pattern space to local space. The drawing commands are issued in pattern space
// and this matrix is used to inverse-map the local space vertices into it.
//
// patternMatrix = tileTransfrom x shiftTransform
patternMatrix.copyFrom(lt);
// Apply shiftTransform into patternMatrix. See $1.1
if (!this.uvRespectAnchor) {
patternMatrix.translate(-this.anchor.x * W, -this.anchor.y * H);
}
patternMatrix.scale(this.tileScale.x / baseTextureResolution, this.tileScale.y / baseTextureResolution);
worldMatrix.prepend(patternMatrix);
worldMatrix.prepend(transform);
renderer.setContextTransform(worldMatrix);
// Fill the pattern!
context.fillStyle = this._canvasPattern;
// The position in local space we are drawing the rectangle: (lx, ly, lx + W, ly + H)
var lx = this.anchor.x * -W;
var ly = this.anchor.y * -H;
// Set pattern rect in local space first.
patternRect[0].set(lx, ly);
patternRect[1].set(lx + W, ly);
patternRect[2].set(lx + W, ly + H);
patternRect[3].set(lx, ly + H);
// Map patternRect into pattern space.
for (var i = 0; i < 4; i++) {
patternMatrix.applyInverse(patternRect[i], patternRect[i]);
}
/*
* # Note about verification of theory
*
* As discussed in the implementation notes, you can verify that `patternRect[0]` will always be (0, 0) in case of
* `uvRespectAnchor` false and tileTransform having no translation. Indeed, because the pattern origin should map
* to the top-left corner of the tiling sprite in its local space.
*/
context.beginPath();
context.moveTo(patternRect[0].x, patternRect[0].y);
for (var i = 1; i < 4; i++) {
context.lineTo(patternRect[i].x, patternRect[i].y);
}
context.closePath();
context.fill();
this._cachedTint = this.tint;
this._canvasPattern = tempCanvas.context.createPattern(tempCanvas.canvas, "repeat");
}
context.globalAlpha = this.worldAlpha;
renderer.canvasContext.setBlendMode(this.blendMode);
this.tileTransform.updateLocalTransform();
const lt = this.tileTransform.localTransform;
const W = this._width;
const H = this._height;
worldMatrix.identity();
patternMatrix.copyFrom(lt);
if (!this.uvRespectAnchor) {
patternMatrix.translate(-this.anchor.x * W, -this.anchor.y * H);
}
patternMatrix.scale(this.tileScale.x / baseTextureResolution, this.tileScale.y / baseTextureResolution);
worldMatrix.prepend(patternMatrix);
worldMatrix.prepend(transform);
renderer.canvasContext.setContextTransform(worldMatrix);
context.fillStyle = this._canvasPattern;
const lx = this.anchor.x * -W;
const ly = this.anchor.y * -H;
patternRect[0].set(lx, ly);
patternRect[1].set(lx + W, ly);
patternRect[2].set(lx + W, ly + H);
patternRect[3].set(lx, ly + H);
for (let i = 0; i < 4; i++) {
patternMatrix.applyInverse(patternRect[i], patternRect[i]);
}
context.beginPath();
context.moveTo(patternRect[0].x, patternRect[0].y);
for (let i = 1; i < 4; i++) {
context.lineTo(patternRect[i].x, patternRect[i].y);
}
context.closePath();
context.fill();
};
//# sourceMappingURL=canvas-sprite-tiling.js.map

@@ -1,9 +0,8 @@

/*!
* @pixi/canvas-sprite-tiling - v6.5.3
* Compiled Fri, 09 Sep 2022 13:55:20 UTC
"use strict";/*!
* @pixi/canvas-sprite-tiling - v7.0.0-alpha
* Compiled Fri, 09 Sep 2022 16:09:18 UTC
*
* @pixi/canvas-sprite-tiling is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
"use strict";var t=require("@pixi/sprite-tiling"),e=require("@pixi/canvas-renderer"),i=require("@pixi/utils"),a=require("@pixi/math"),r=new a.Matrix,n=new a.Matrix,s=[new a.Point,new a.Point,new a.Point,new a.Point];t.TilingSprite.prototype._renderCanvas=function(t){var a=this._texture;if(a.baseTexture.valid){var h=t.context,o=this.worldTransform,l=a.baseTexture,c=l.getDrawableSource(),d=l.resolution;if(this._textureID!==this._texture._updateID||this._cachedTint!==this.tint){this._textureID=this._texture._updateID;var x=new i.CanvasRenderTarget(a._frame.width,a._frame.height,d);16777215!==this.tint?(this._tintedCanvas=e.canvasUtils.getTintedCanvas(this,this.tint),x.context.drawImage(this._tintedCanvas,0,0)):x.context.drawImage(c,-a._frame.x*d,-a._frame.y*d),this._cachedTint=this.tint,this._canvasPattern=x.context.createPattern(x.canvas,"repeat")}h.globalAlpha=this.worldAlpha,t.setBlendMode(this.blendMode),this.tileTransform.updateLocalTransform();var p=this.tileTransform.localTransform,v=this._width,u=this._height;r.identity(),n.copyFrom(p),this.uvRespectAnchor||n.translate(-this.anchor.x*v,-this.anchor.y*u),n.scale(this.tileScale.x/d,this.tileScale.y/d),r.prepend(n),r.prepend(o),t.setContextTransform(r),h.fillStyle=this._canvasPattern;var _=this.anchor.x*-v,f=this.anchor.y*-u;s[0].set(_,f),s[1].set(_+v,f),s[2].set(_+v,f+u),s[3].set(_,f+u);for(var m=0;m<4;m++)n.applyInverse(s[m],s[m]);h.beginPath(),h.moveTo(s[0].x,s[0].y);for(m=1;m<4;m++)h.lineTo(s[m].x,s[m].y);h.closePath(),h.fill()}};
*/var f=require("@pixi/sprite-tiling"),T=require("@pixi/canvas-renderer"),n=require("@pixi/core");const x=new n.Matrix,s=new n.Matrix,e=[new n.Point,new n.Point,new n.Point,new n.Point];f.TilingSprite.prototype._renderCanvas=function(d){const a=this._texture;if(!a.baseTexture.valid)return;const i=d.canvasContext.activeContext,v=this.worldTransform,p=a.baseTexture,u=p.getDrawableSource(),r=p.resolution;if(this._textureID!==this._texture._updateID||this._cachedTint!==this.tint){this._textureID=this._texture._updateID;const t=new n.utils.CanvasRenderTarget(a._frame.width,a._frame.height,r);this.tint!==16777215?(this._tintedCanvas=T.canvasUtils.getTintedCanvas(this,this.tint),t.context.drawImage(this._tintedCanvas,0,0)):t.context.drawImage(u,-a._frame.x*r,-a._frame.y*r),this._cachedTint=this.tint,this._canvasPattern=t.context.createPattern(t.canvas,"repeat")}i.globalAlpha=this.worldAlpha,d.canvasContext.setBlendMode(this.blendMode),this.tileTransform.updateLocalTransform();const _=this.tileTransform.localTransform,o=this._width,h=this._height;x.identity(),s.copyFrom(_),this.uvRespectAnchor||s.translate(-this.anchor.x*o,-this.anchor.y*h),s.scale(this.tileScale.x/r,this.tileScale.y/r),x.prepend(s),x.prepend(v),d.canvasContext.setContextTransform(x),i.fillStyle=this._canvasPattern;const c=this.anchor.x*-o,l=this.anchor.y*-h;e[0].set(c,l),e[1].set(c+o,l),e[2].set(c+o,l+h),e[3].set(c,l+h);for(let t=0;t<4;t++)s.applyInverse(e[t],e[t]);i.beginPath(),i.moveTo(e[0].x,e[0].y);for(let t=1;t<4;t++)i.lineTo(e[t].x,e[t].y);i.closePath(),i.fill()};
//# sourceMappingURL=canvas-sprite-tiling.min.js.map
{
"name": "@pixi/canvas-sprite-tiling",
"version": "6.5.3",
"version": "7.0.0-alpha",
"main": "dist/cjs/canvas-sprite-tiling.js",
"module": "dist/esm/canvas-sprite-tiling.mjs",
"bundle": "dist/browser/canvas-sprite-tiling.js",
"types": "index.d.ts",

@@ -20,3 +19,2 @@ "exports": {

},
"bundleNoExports": true,
"description": "Canvas mixin for the sprite-tiling package",

@@ -38,14 +36,12 @@ "author": "Mat Groves",

"files": [
"lib",
"dist",
"*.d.ts"
],
"peerDependencies": {
"@pixi/canvas-renderer": "6.5.3",
"@pixi/canvas-sprite": "6.5.3",
"@pixi/math": "6.5.3",
"@pixi/sprite-tiling": "6.5.3",
"@pixi/utils": "6.5.3"
},
"gitHead": "28e6b2841a65837a5e2873a3d5a9c27cabbe795a"
"pixiRequirements": [
"@pixi/canvas-renderer",
"@pixi/canvas-sprite",
"@pixi/core",
"@pixi/sprite-tiling"
],
"gitHead": "da993226df64b804a9c00ed9ee4d011191467b8a"
}

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