@digipair/skill-canvas 0.45.1 → 0.45.2

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.
package/index.cjs.js CHANGED
@@ -3,7 +3,6 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var engine = require('@digipair/engine');
6
- var canvas$1 = require('canvas');
7
6
 
8
7
  function _extends() {
9
8
  _extends = Object.assign || function assign(target) {
@@ -24,7 +23,15 @@ let CanvasService = class CanvasService {
24
23
  }
25
24
  async canvas(params, _pinsSettingsList, context) {
26
25
  const { width, height, execute } = params;
27
- const instance = canvas$1.createCanvas(width, height);
26
+ const { createCanvas } = typeof window === 'undefined' ? require('canvas') : {
27
+ createCanvas: (width, height)=>{
28
+ const canvas = document.createElement('canvas');
29
+ canvas.width = width;
30
+ canvas.height = height;
31
+ return canvas;
32
+ }
33
+ };
34
+ const instance = createCanvas(width, height);
28
35
  const ctx = instance.getContext('2d');
29
36
  await engine.executePinsList(execute, _extends({}, context, {
30
37
  canvas: {
@@ -35,8 +42,15 @@ let CanvasService = class CanvasService {
35
42
  }
36
43
  async loadImage(params, _pinsSettingsList, _context) {
37
44
  const { image } = params;
38
- const buffer = this.base64ToImage(image);
39
- return canvas$1.loadImage(buffer);
45
+ const { loadImageCanvas } = typeof window === 'undefined' ? require('canvas') : {
46
+ loadImageCanvas: (src)=>new Promise((resolve, reject)=>{
47
+ const img = new Image();
48
+ img.onload = ()=>resolve(img);
49
+ img.onerror = (err)=>reject(err);
50
+ img.src = src;
51
+ })
52
+ };
53
+ return loadImageCanvas(typeof window === 'undefined' ? this.base64ToImage(image) : image);
40
54
  }
41
55
  async drawImage(params, _pinsSettingsList, context) {
42
56
  const { image, x, y, width, height } = params;
package/index.esm.js CHANGED
@@ -1,5 +1,3 @@
1
- import { createCanvas, loadImage as loadImage$1 } from 'canvas';
2
-
3
1
  function _extends() {
4
2
  _extends = Object.assign || function assign(target) {
5
3
  for(var i = 1; i < arguments.length; i++){
@@ -23901,14 +23899,14 @@ function indent(str, spaces) {
23901
23899
  var match = parseIdentifier(input, i1, namePart) || namePart && parseAdditionalSymbol(input, i1) || maybeSpace && parseSpaces(input, i1);
23902
23900
  // match is required
23903
23901
  if (!match) {
23904
- return nextMatch = nextMatch1, i = i1, tokens = tokens1, {
23902
+ return i = i1, nextMatch = nextMatch1, tokens = tokens1, {
23905
23903
  v: nextMatch1
23906
23904
  };
23907
23905
  }
23908
23906
  var token = match.token, offset = match.offset;
23909
23907
  i1 += offset;
23910
23908
  if (token === " ") {
23911
- return nextMatch = nextMatch1, i = i1, tokens = tokens1, "continue";
23909
+ return i = i1, nextMatch = nextMatch1, tokens = tokens1, "continue";
23912
23910
  }
23913
23911
  tokens1 = _to_consumable_array$1(tokens1).concat([
23914
23912
  token
@@ -23927,7 +23925,7 @@ function indent(str, spaces) {
23927
23925
  if (contextKeys.some(function(el) {
23928
23926
  return el.startsWith(name);
23929
23927
  })) {
23930
- return nextMatch = nextMatch1, i = i1, tokens = tokens1, "continue";
23928
+ return i = i1, nextMatch = nextMatch1, tokens = tokens1, "continue";
23931
23929
  }
23932
23930
  if (dateTimeIdentifiers.some(function(el) {
23933
23931
  return el === name;
@@ -23946,9 +23944,9 @@ function indent(str, spaces) {
23946
23944
  if (dateTimeIdentifiers.some(function(el) {
23947
23945
  return el.startsWith(name);
23948
23946
  })) {
23949
- return nextMatch = nextMatch1, i = i1, tokens = tokens1, "continue";
23947
+ return i = i1, nextMatch = nextMatch1, tokens = tokens1, "continue";
23950
23948
  }
23951
- return nextMatch = nextMatch1, i = i1, tokens = tokens1, {
23949
+ return i = i1, nextMatch = nextMatch1, tokens = tokens1, {
23952
23950
  v: nextMatch1
23953
23951
  };
23954
23952
  };
@@ -27963,6 +27961,14 @@ let CanvasService = class CanvasService {
27963
27961
  }
27964
27962
  async canvas(params, _pinsSettingsList, context) {
27965
27963
  const { width, height, execute } = params;
27964
+ const { createCanvas } = typeof window === 'undefined' ? require('canvas') : {
27965
+ createCanvas: (width, height)=>{
27966
+ const canvas = document.createElement('canvas');
27967
+ canvas.width = width;
27968
+ canvas.height = height;
27969
+ return canvas;
27970
+ }
27971
+ };
27966
27972
  const instance = createCanvas(width, height);
27967
27973
  const ctx = instance.getContext('2d');
27968
27974
  await executePinsList(execute, _extends({}, context, {
@@ -27974,8 +27980,15 @@ let CanvasService = class CanvasService {
27974
27980
  }
27975
27981
  async loadImage(params, _pinsSettingsList, _context) {
27976
27982
  const { image } = params;
27977
- const buffer = this.base64ToImage(image);
27978
- return loadImage$1(buffer);
27983
+ const { loadImageCanvas } = typeof window === 'undefined' ? require('canvas') : {
27984
+ loadImageCanvas: (src)=>new Promise((resolve, reject)=>{
27985
+ const img = new Image();
27986
+ img.onload = ()=>resolve(img);
27987
+ img.onerror = (err)=>reject(err);
27988
+ img.src = src;
27989
+ })
27990
+ };
27991
+ return loadImageCanvas(typeof window === 'undefined' ? this.base64ToImage(image) : image);
27979
27992
  }
27980
27993
  async drawImage(params, _pinsSettingsList, context) {
27981
27994
  const { image, x, y, width, height } = params;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digipair/skill-canvas",
3
- "version": "0.45.1",
3
+ "version": "0.45.2",
4
4
  "dependencies": {
5
5
  "canvas": "^2.11.2"
6
6
  },
@@ -1,6 +1,6 @@
1
1
  import { PinsSettings } from '@digipair/engine';
2
- export declare const canvas: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<string>;
3
- export declare const loadImage: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<import("canvas").Image>;
2
+ export declare const canvas: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
3
+ export declare const loadImage: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
4
4
  export declare const drawImage: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<void>;
5
5
  export declare const strokeRect: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<void>;
6
6
  export declare const fillRect: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<void>;