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

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.
@@ -1,7 +1,7 @@
1
1
  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
- import { StaticCanvas } from 'fabric/node';
4
+ import { JSDOM } from 'jsdom';
5
5
 
6
6
  const PIXELS_PER_MM$2 = 3.937;
7
7
  class MillimeterDimensions {
@@ -3736,11 +3736,16 @@ class SelectionData {
3736
3736
 
3737
3737
  class HeadlessInteractiveCanvas extends AbstractInteractiveCanvas {
3738
3738
  constructor() {
3739
- //super(fabric, new StaticCanvas(null as any, {width: 640, height: 480}) as unknown as Canvas, 0);
3740
- const isNode = typeof window === "undefined";
3741
- const canvas = isNode
3742
- ? new StaticCanvas(null, { width: 640, height: 480 })
3743
- : new fabric.StaticCanvas(undefined, { width: 640, height: 480 });
3739
+ if (typeof window === "undefined") {
3740
+ const { window } = new JSDOM('<!DOCTYPE html><html><body></body></html>');
3741
+ global.window = window;
3742
+ global.document = window.document;
3743
+ global.HTMLElement = window.HTMLElement;
3744
+ global.HTMLCanvasElement = window.HTMLCanvasElement;
3745
+ global.requestAnimationFrame = (callback) => setTimeout(() => callback(Date.now()), 16);
3746
+ global.cancelAnimationFrame = (id) => clearTimeout(id);
3747
+ }
3748
+ const canvas = new fabric.StaticCanvas(undefined, { width: 640, height: 480 });
3744
3749
  super(fabric, canvas, 0);
3745
3750
  this.headless = true;
3746
3751
  }
@@ -3,7 +3,7 @@
3
3
  var _ = require('lodash');
4
4
  var rxjs = require('rxjs');
5
5
  var fabric = require('fabric');
6
- var node = require('fabric/node');
6
+ var jsdom = require('jsdom');
7
7
 
8
8
  function _interopNamespaceDefault(e) {
9
9
  var n = Object.create(null);
@@ -3757,11 +3757,16 @@ class SelectionData {
3757
3757
 
3758
3758
  class HeadlessInteractiveCanvas extends AbstractInteractiveCanvas {
3759
3759
  constructor() {
3760
- //super(fabric, new StaticCanvas(null as any, {width: 640, height: 480}) as unknown as Canvas, 0);
3761
- const isNode = typeof window === "undefined";
3762
- const canvas = isNode
3763
- ? new node.StaticCanvas(null, { width: 640, height: 480 })
3764
- : new fabric__namespace.StaticCanvas(undefined, { width: 640, height: 480 });
3760
+ if (typeof window === "undefined") {
3761
+ const { window } = new jsdom.JSDOM('<!DOCTYPE html><html><body></body></html>');
3762
+ global.window = window;
3763
+ global.document = window.document;
3764
+ global.HTMLElement = window.HTMLElement;
3765
+ global.HTMLCanvasElement = window.HTMLCanvasElement;
3766
+ global.requestAnimationFrame = (callback) => setTimeout(() => callback(Date.now()), 16);
3767
+ global.cancelAnimationFrame = (id) => clearTimeout(id);
3768
+ }
3769
+ const canvas = new fabric__namespace.StaticCanvas(undefined, { width: 640, height: 480 });
3765
3770
  super(fabric__namespace, canvas, 0);
3766
3771
  this.headless = true;
3767
3772
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leapfrog/interactive-canvas",
3
- "version": "2.0.22-beta-2",
3
+ "version": "2.0.22-beta-3",
4
4
  "description": "Leapfrog interactive canvas",
5
5
  "files": [
6
6
  "dist"
@@ -14,11 +14,13 @@
14
14
  "prepublishOnly": "npm run build"
15
15
  },
16
16
  "devDependencies": {
17
+ "@types/jsdom": "^28.0.3",
17
18
  "@types/lodash": "^4.17.23",
18
19
  "typescript": "^6.0.3"
19
20
  },
20
21
  "dependencies": {
21
22
  "fabric": "^7.2.0",
23
+ "jsdom": "^29.0.2",
22
24
  "lodash": "^4.18.1",
23
25
  "rollup": "^4.60.3",
24
26
  "rollup-plugin-typescript2": "^0.37.0",