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

@pixi/canvas-extract

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-extract - npm Package Compare versions

Comparing version 6.5.3 to 7.0.0-alpha

global.d.ts

227

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

@@ -13,143 +13,92 @@ * @pixi/canvas-extract is licensed under the MIT License.

var core = require('@pixi/core');
var utils = require('@pixi/utils');
var math = require('@pixi/math');
var TEMP_RECT = new math.Rectangle();
/**
* The extract manager provides functionality to export content from the renderers.
*
* An instance of this class is automatically created by default, and can be found at `renderer.plugins.extract`
* @class
* @memberof PIXI
*/
var CanvasExtract = /** @class */ (function () {
/**
* @param renderer - A reference to the current renderer
*/
function CanvasExtract(renderer) {
this.renderer = renderer;
const TEMP_RECT = new core.Rectangle();
class CanvasExtract {
constructor(renderer) {
this.renderer = renderer;
}
image(target, format, quality) {
const image = new Image();
image.src = this.base64(target, format, quality);
return image;
}
base64(target, format, quality) {
return this.canvas(target).toDataURL(format, quality);
}
canvas(target, frame) {
const renderer = this.renderer;
let context;
let resolution;
let renderTexture;
if (target) {
if (target instanceof core.RenderTexture) {
renderTexture = target;
} else {
renderTexture = renderer.generateTexture(target);
}
}
/**
* Will return a HTML Image of the target
* @param target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @param format - Image format, e.g. "image/jpeg" or "image/webp".
* @param quality - JPEG or Webp compression from 0 to 1. Default is 0.92.
* @returns HTML Image of the target
*/
CanvasExtract.prototype.image = function (target, format, quality) {
var image = new Image();
image.src = this.base64(target, format, quality);
return image;
};
/**
* Will return a base64 encoded string of this target. It works by calling
* `CanvasExtract.getCanvas` and then running toDataURL on that.
* @param target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @param format - Image format, e.g. "image/jpeg" or "image/webp".
* @param quality - JPEG or Webp compression from 0 to 1. Default is 0.92.
* @returns A base64 encoded string of the texture.
*/
CanvasExtract.prototype.base64 = function (target, format, quality) {
return this.canvas(target).toDataURL(format, quality);
};
/**
* Creates a Canvas element, renders this target to it and then returns it.
* @param target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @param frame - The frame the extraction is restricted to.
* @returns A Canvas element with the texture rendered on.
*/
CanvasExtract.prototype.canvas = function (target, frame) {
var renderer = this.renderer;
var context;
var resolution;
var renderTexture;
if (target) {
if (target instanceof core.RenderTexture) {
renderTexture = target;
}
else {
renderTexture = renderer.generateTexture(target);
}
}
if (renderTexture) {
context = renderTexture.baseTexture._canvasRenderTarget.context;
resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
frame = frame !== null && frame !== void 0 ? frame : renderTexture.frame;
}
else {
context = renderer.rootContext;
resolution = renderer.resolution;
if (!frame) {
frame = TEMP_RECT;
frame.width = renderer.width;
frame.height = renderer.height;
}
}
var x = Math.round(frame.x * resolution);
var y = Math.round(frame.y * resolution);
var width = Math.round(frame.width * resolution);
var height = Math.round(frame.height * resolution);
var canvasBuffer = new utils.CanvasRenderTarget(width, height, 1);
var canvasData = context.getImageData(x, y, width, height);
canvasBuffer.context.putImageData(canvasData, 0, 0);
// send the canvas back..
return canvasBuffer.canvas;
};
/**
* Will return a one-dimensional array containing the pixel data of the entire texture in RGBA
* order, with integer values between 0 and 255 (included).
* @param target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @param frame - The frame the extraction is restricted to.
* @returns One-dimensional array containing the pixel data of the entire texture
*/
CanvasExtract.prototype.pixels = function (target, frame) {
var renderer = this.renderer;
var context;
var resolution;
var renderTexture;
if (target) {
if (target instanceof core.RenderTexture) {
renderTexture = target;
}
else {
renderTexture = renderer.generateTexture(target);
}
}
if (renderTexture) {
context = renderTexture.baseTexture._canvasRenderTarget.context;
resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
frame = frame !== null && frame !== void 0 ? frame : renderTexture.frame;
}
else {
context = renderer.rootContext;
resolution = renderer.resolution;
if (!frame) {
frame = TEMP_RECT;
frame.width = renderer.width;
frame.height = renderer.height;
}
}
var x = Math.round(frame.x * resolution);
var y = Math.round(frame.y * resolution);
var width = Math.round(frame.width * resolution);
var height = Math.round(frame.height * resolution);
return context.getImageData(x, y, width, height).data;
};
/** Destroys the extract */
CanvasExtract.prototype.destroy = function () {
this.renderer = null;
};
/** @ignore */
CanvasExtract.extension = {
name: 'extract',
type: core.ExtensionType.CanvasRendererPlugin,
};
return CanvasExtract;
}());
if (renderTexture) {
context = renderTexture.baseTexture._canvasRenderTarget.context;
resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
frame = frame ?? renderTexture.frame;
} else {
context = renderer.canvasContext.rootContext;
resolution = renderer._view.resolution;
if (!frame) {
frame = TEMP_RECT;
frame.width = renderer.width;
frame.height = renderer.height;
}
}
const x = Math.round(frame.x * resolution);
const y = Math.round(frame.y * resolution);
const width = Math.round(frame.width * resolution);
const height = Math.round(frame.height * resolution);
const canvasBuffer = new core.utils.CanvasRenderTarget(width, height, 1);
const canvasData = context.getImageData(x, y, width, height);
canvasBuffer.context.putImageData(canvasData, 0, 0);
return canvasBuffer.canvas;
}
pixels(target, frame) {
const renderer = this.renderer;
let context;
let resolution;
let renderTexture;
if (target) {
if (target instanceof core.RenderTexture) {
renderTexture = target;
} else {
renderTexture = renderer.generateTexture(target);
}
}
if (renderTexture) {
context = renderTexture.baseTexture._canvasRenderTarget.context;
resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
frame = frame ?? renderTexture.frame;
} else {
context = renderer.canvasContext.rootContext;
resolution = renderer.resolution;
if (!frame) {
frame = TEMP_RECT;
frame.width = renderer.width;
frame.height = renderer.height;
}
}
const x = Math.round(frame.x * resolution);
const y = Math.round(frame.y * resolution);
const width = Math.round(frame.width * resolution);
const height = Math.round(frame.height * resolution);
return context.getImageData(x, y, width, height).data;
}
destroy() {
this.renderer = null;
}
}
CanvasExtract.extension = {
name: "extract",
type: core.ExtensionType.CanvasRendererSystem
};
core.extensions.add(CanvasExtract);
exports.CanvasExtract = CanvasExtract;
//# sourceMappingURL=canvas-extract.js.map

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

/*!
* @pixi/canvas-extract - v6.5.3
* Compiled Fri, 09 Sep 2022 13:55:20 UTC
"use strict";/*!
* @pixi/canvas-extract - v7.0.0-alpha
* Compiled Fri, 09 Sep 2022 16:09:18 UTC
*
* @pixi/canvas-extract is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@pixi/core"),t=require("@pixi/utils"),r=new(require("@pixi/math").Rectangle),n=function(){function n(e){this.renderer=e}return n.prototype.image=function(e,t,r){var n=new Image;return n.src=this.base64(e,t,r),n},n.prototype.base64=function(e,t,r){return this.canvas(e).toDataURL(t,r)},n.prototype.canvas=function(n,a){var o,i,u,s=this.renderer;n&&(u=n instanceof e.RenderTexture?n:s.generateTexture(n)),u?(o=u.baseTexture._canvasRenderTarget.context,i=u.baseTexture._canvasRenderTarget.resolution,a=null!=a?a:u.frame):(o=s.rootContext,i=s.resolution,a||((a=r).width=s.width,a.height=s.height));var h=Math.round(a.x*i),d=Math.round(a.y*i),c=Math.round(a.width*i),x=Math.round(a.height*i),g=new t.CanvasRenderTarget(c,x,1),p=o.getImageData(h,d,c,x);return g.context.putImageData(p,0,0),g.canvas},n.prototype.pixels=function(t,n){var a,o,i,u=this.renderer;t&&(i=t instanceof e.RenderTexture?t:u.generateTexture(t)),i?(a=i.baseTexture._canvasRenderTarget.context,o=i.baseTexture._canvasRenderTarget.resolution,n=null!=n?n:i.frame):(a=u.rootContext,o=u.resolution,n||((n=r).width=u.width,n.height=u.height));var s=Math.round(n.x*o),h=Math.round(n.y*o),d=Math.round(n.width*o),c=Math.round(n.height*o);return a.getImageData(s,h,d,c).data},n.prototype.destroy=function(){this.renderer=null},n.extension={name:"extract",type:e.ExtensionType.CanvasRendererPlugin},n}();exports.CanvasExtract=n;
*/Object.defineProperty(exports,"__esModule",{value:!0});var o=require("@pixi/core");const g=new o.Rectangle;class h{constructor(t){this.renderer=t}image(t,e,a){const s=new Image;return s.src=this.base64(t,e,a),s}base64(t,e,a){return this.canvas(t).toDataURL(e,a)}canvas(t,e){const a=this.renderer;let s,r,n;t&&(t instanceof o.RenderTexture?n=t:n=a.generateTexture(t)),n?(s=n.baseTexture._canvasRenderTarget.context,r=n.baseTexture._canvasRenderTarget.resolution,e=e??n.frame):(s=a.canvasContext.rootContext,r=a._view.resolution,e||(e=g,e.width=a.width,e.height=a.height));const d=Math.round(e.x*r),u=Math.round(e.y*r),i=Math.round(e.width*r),c=Math.round(e.height*r),x=new o.utils.CanvasRenderTarget(i,c,1),v=s.getImageData(d,u,i,c);return x.context.putImageData(v,0,0),x.canvas}pixels(t,e){const a=this.renderer;let s,r,n;t&&(t instanceof o.RenderTexture?n=t:n=a.generateTexture(t)),n?(s=n.baseTexture._canvasRenderTarget.context,r=n.baseTexture._canvasRenderTarget.resolution,e=e??n.frame):(s=a.canvasContext.rootContext,r=a.resolution,e||(e=g,e.width=a.width,e.height=a.height));const d=Math.round(e.x*r),u=Math.round(e.y*r),i=Math.round(e.width*r),c=Math.round(e.height*r);return s.getImageData(d,u,i,c).data}destroy(){this.renderer=null}}h.extension={name:"extract",type:o.ExtensionType.CanvasRendererSystem},o.extensions.add(h),exports.CanvasExtract=h;
//# sourceMappingURL=canvas-extract.min.js.map

@@ -0,5 +1,8 @@

/// <reference path="./global.d.ts" />
import type { CanvasRenderer } from '@pixi/canvas-renderer';
import type { DisplayObject } from '@pixi/display';
import type { ExtensionMetadata } from '@pixi/core';
import { Rectangle } from '@pixi/math';
import type { ISystem } from '@pixi/core';
import { Rectangle } from '@pixi/core';
import { RenderTexture } from '@pixi/core';

@@ -14,3 +17,3 @@

*/
export declare class CanvasExtract {
export declare class CanvasExtract implements ISystem {
/** @ignore */

@@ -17,0 +20,0 @@ static extension: ExtensionMetadata;

{
"name": "@pixi/canvas-extract",
"version": "6.5.3",
"version": "7.0.0-alpha",
"main": "dist/cjs/canvas-extract.js",
"module": "dist/esm/canvas-extract.mjs",
"bundle": "dist/browser/canvas-extract.js",
"types": "index.d.ts",

@@ -36,14 +35,11 @@ "exports": {

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

@@ -12,6 +12,3 @@ # @pixi/canvas-extract

```js
import { extensions } from '@pixi/core';
import { CanvasExtract } from '@pixi/canvas-extract';
extensions.add(CanvasExtract);
import '@pixi/canvas-extract';
```

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