@leapfrog/interactive-canvas 2.0.22-beta-3 → 2.0.22-beta-5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -319,7 +319,7 @@ export declare abstract class AbstractInteractiveCanvas implements IInteractiveC
319
319
  * @override
320
320
  * @inheritDoc
321
321
  */
322
- createPNGStream(): any;
322
+ createPNGStream(multiplier?: number): any;
323
323
  /**
324
324
  * @override
325
325
  * @inheritDoc
@@ -2,6 +2,7 @@ import _, { round, each, values, reduce, clone, max, isEqual } from 'lodash';
2
2
  import { BehaviorSubject, Subject } from 'rxjs';
3
3
  import * as fabric from 'fabric';
4
4
  import { JSDOM } from 'jsdom';
5
+ import { createCanvas } from 'canvas';
5
6
 
6
7
  const PIXELS_PER_MM$2 = 3.937;
7
8
  class MillimeterDimensions {
@@ -3488,8 +3489,13 @@ class AbstractInteractiveCanvas {
3488
3489
  * @override
3489
3490
  * @inheritDoc
3490
3491
  */
3491
- createPNGStream() {
3492
- return this.fabricCanvas.createPNGStream();
3492
+ createPNGStream(multiplier) {
3493
+ const options = {
3494
+ format: "png",
3495
+ multiplier: multiplier || this.IMAGE_CAPTURE_COEFFICIENT,
3496
+ enableRetinaScaling: true
3497
+ };
3498
+ return this.fabricCanvas.toDataURL(options);
3493
3499
  }
3494
3500
  /**
3495
3501
  * @override
@@ -3736,16 +3742,25 @@ class SelectionData {
3736
3742
 
3737
3743
  class HeadlessInteractiveCanvas extends AbstractInteractiveCanvas {
3738
3744
  constructor() {
3745
+ let canvas;
3739
3746
  if (typeof window === "undefined") {
3740
3747
  const { window } = new JSDOM('<!DOCTYPE html><html><body></body></html>');
3741
3748
  global.window = window;
3742
3749
  global.document = window.document;
3743
3750
  global.HTMLElement = window.HTMLElement;
3744
3751
  global.HTMLCanvasElement = window.HTMLCanvasElement;
3745
- global.requestAnimationFrame = (callback) => setTimeout(() => callback(Date.now()), 16);
3746
- global.cancelAnimationFrame = (id) => clearTimeout(id);
3752
+ global.window.requestAnimationFrame = (callback) => {
3753
+ return setTimeout(() => callback(Date.now()), 16);
3754
+ };
3755
+ global.window.cancelAnimationFrame = (id) => {
3756
+ clearTimeout(id);
3757
+ };
3758
+ const nodeCanvas = createCanvas(640, 480);
3759
+ canvas = new fabric.StaticCanvas(nodeCanvas);
3760
+ }
3761
+ else {
3762
+ canvas = new fabric.StaticCanvas(undefined, { width: 640, height: 480 });
3747
3763
  }
3748
- const canvas = new fabric.StaticCanvas(undefined, { width: 640, height: 480 });
3749
3764
  super(fabric, canvas, 0);
3750
3765
  this.headless = true;
3751
3766
  }
@@ -4,6 +4,7 @@ var _ = require('lodash');
4
4
  var rxjs = require('rxjs');
5
5
  var fabric = require('fabric');
6
6
  var jsdom = require('jsdom');
7
+ var canvas = require('canvas');
7
8
 
8
9
  function _interopNamespaceDefault(e) {
9
10
  var n = Object.create(null);
@@ -3509,8 +3510,13 @@ class AbstractInteractiveCanvas {
3509
3510
  * @override
3510
3511
  * @inheritDoc
3511
3512
  */
3512
- createPNGStream() {
3513
- return this.fabricCanvas.createPNGStream();
3513
+ createPNGStream(multiplier) {
3514
+ const options = {
3515
+ format: "png",
3516
+ multiplier: multiplier || this.IMAGE_CAPTURE_COEFFICIENT,
3517
+ enableRetinaScaling: true
3518
+ };
3519
+ return this.fabricCanvas.toDataURL(options);
3514
3520
  }
3515
3521
  /**
3516
3522
  * @override
@@ -3757,17 +3763,26 @@ class SelectionData {
3757
3763
 
3758
3764
  class HeadlessInteractiveCanvas extends AbstractInteractiveCanvas {
3759
3765
  constructor() {
3766
+ let canvas$1;
3760
3767
  if (typeof window === "undefined") {
3761
3768
  const { window } = new jsdom.JSDOM('<!DOCTYPE html><html><body></body></html>');
3762
3769
  global.window = window;
3763
3770
  global.document = window.document;
3764
3771
  global.HTMLElement = window.HTMLElement;
3765
3772
  global.HTMLCanvasElement = window.HTMLCanvasElement;
3766
- global.requestAnimationFrame = (callback) => setTimeout(() => callback(Date.now()), 16);
3767
- global.cancelAnimationFrame = (id) => clearTimeout(id);
3773
+ global.window.requestAnimationFrame = (callback) => {
3774
+ return setTimeout(() => callback(Date.now()), 16);
3775
+ };
3776
+ global.window.cancelAnimationFrame = (id) => {
3777
+ clearTimeout(id);
3778
+ };
3779
+ const nodeCanvas = canvas.createCanvas(640, 480);
3780
+ canvas$1 = new fabric__namespace.StaticCanvas(nodeCanvas);
3781
+ }
3782
+ else {
3783
+ canvas$1 = new fabric__namespace.StaticCanvas(undefined, { width: 640, height: 480 });
3768
3784
  }
3769
- const canvas = new fabric__namespace.StaticCanvas(undefined, { width: 640, height: 480 });
3770
- super(fabric__namespace, canvas, 0);
3785
+ super(fabric__namespace, canvas$1, 0);
3771
3786
  this.headless = true;
3772
3787
  }
3773
3788
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leapfrog/interactive-canvas",
3
- "version": "2.0.22-beta-3",
3
+ "version": "2.0.22-beta-5",
4
4
  "description": "Leapfrog interactive canvas",
5
5
  "files": [
6
6
  "dist"
@@ -19,6 +19,7 @@
19
19
  "typescript": "^6.0.3"
20
20
  },
21
21
  "dependencies": {
22
+ "canvas": "^3.2.3",
22
23
  "fabric": "^7.2.0",
23
24
  "jsdom": "^29.0.2",
24
25
  "lodash": "^4.18.1",