oslllo-potrace 1.1.4 → 2.0.1

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/CHANGELOG.md CHANGED
@@ -5,6 +5,45 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ### [2.0.1](https://www.github.com/oslllo/potrace/compare/v2.0.0...v2.0.1) (2022-07-16)
9
+
10
+
11
+ ### Miscellaneous Chores
12
+
13
+ * release 2.0.1 ([5eb34e2](https://www.github.com/oslllo/potrace/commit/5eb34e201a74668698ea4b27251afec5fb69e215))
14
+
15
+ ## [2.0.0](https://www.github.com/oslllo/potrace/compare/v1.2.0...v2.0.0) (2021-12-31)
16
+
17
+
18
+ ### Features
19
+
20
+ * **deps:** Simplify dependencies, remove canvas/jsdom ([c013c58](https://www.github.com/oslllo/potrace/commit/c013c58e0fc11c1757fbcf3089e6b42d647fb6af))
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * **deps:** use svg2png-wasm-node-10 for compatibility ([655fe37](https://www.github.com/oslllo/potrace/commit/655fe37a80bc61b62ea0a21c4346dba353154842))
26
+ * **example:** add white background ([f3b3980](https://www.github.com/oslllo/potrace/commit/f3b3980298ffed0fcc6a9e4186ac7e6a2cb0627b))
27
+
28
+
29
+ ### Miscellaneous Chores
30
+
31
+ * release 2.0.0 ([6575466](https://www.github.com/oslllo/potrace/commit/6575466f0f4aeeaedb8302684c0d14903d26f350))
32
+
33
+ ## [1.2.0](https://www.github.com/oslllo/potrace/compare/v1.1.4...v1.2.0) (2021-12-30)
34
+
35
+
36
+ ### Features
37
+
38
+ * **potrace:** new Promise() is not needed with async function ([1adad10](https://www.github.com/oslllo/potrace/commit/1adad10ec6c0b6d19598d47faa36e64a574a756c))
39
+
40
+
41
+ ### Bug Fixes
42
+
43
+ * **src:** remove unused vars ([a00c02a](https://www.github.com/oslllo/potrace/commit/a00c02a982472ea78dd74fd20c6402e093775002))
44
+ * unhandled rejection in Loader.image() ([5edf4a7](https://www.github.com/oslllo/potrace/commit/5edf4a79ed971160578003dd9c236c0ac9accf98))
45
+ * unhandled rejection in Loader.image() ([0c3843f](https://www.github.com/oslllo/potrace/commit/0c3843f078a64570043f5a046844197c86a943af))
46
+
8
47
  ### [1.1.4](https://www.github.com/oslllo/potrace/compare/v1.1.3...v1.1.4) (2021-09-05)
9
48
 
10
49
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oslllo-potrace",
3
- "version": "1.1.4",
3
+ "version": "2.0.1",
4
4
  "description": "A \"1:1 output\" JavaScript port of Potrace JS for NodeJS.",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -39,17 +39,14 @@
39
39
  },
40
40
  "homepage": "https://github.com/oslllo/potrace#readme",
41
41
  "dependencies": {
42
- "canvas": "^2.8.0",
43
- "jimp": "^0.16.1",
44
- "jsdom": "^16.7.0",
45
- "oslllo-validator": "^2.0.1"
42
+ "jimp": "^0.16.1"
46
43
  },
47
44
  "devDependencies": {
48
- "chai": "^4.3.4",
45
+ "chai": "^4.3.6",
49
46
  "chai-as-promised": "^7.1.1",
50
- "fast-glob": "^3.2.7",
51
- "fs-extra": "^10.0.0",
52
- "mocha": "^8.4.0",
53
- "oslllo-svg2": "^0.3.0"
47
+ "fast-glob": "^3.2.11",
48
+ "fs-extra": "^10.1.0",
49
+ "mocha": "^9.2.2",
50
+ "svg2png-wasm-node-10": "^1.3.1"
54
51
  }
55
52
  }
@@ -3,14 +3,11 @@
3
3
  const Svg = require("./svg");
4
4
  const Loader = require("./loader");
5
5
  const Option = require("./option");
6
- const { JSDOM } = require("jsdom");
7
- const is = require("oslllo-validator");
8
- const EventEmitter = require("events");
9
6
  const Processor = require("./processor");
10
7
  const constants = require("./constants");
11
8
 
12
9
  const Potrace = function (image, options) {
13
- if (!is.instance(this, Potrace)) {
10
+ if (!(this instanceof Potrace)) {
14
11
  return new Potrace(image, options);
15
12
  }
16
13
  this.image = image;
@@ -18,30 +15,22 @@ const Potrace = function (image, options) {
18
15
  this.bitmap = undefined;
19
16
  this.pathlist = new Array();
20
17
  this.options = new Option(options);
21
- this.dom = new JSDOM("<!DOCTYPE html><html></html>", { resources: "usable" });
22
18
 
23
19
  return this;
24
20
  };
25
21
 
26
22
  Potrace.prototype = {
27
- trace: function () {
28
- return new Promise(async (resolve, reject) => {
29
- try {
30
- var info = this.options.all();
31
- var load = new Loader(this.dom);
32
- this.image = await load.image(this.image);
33
- this.canvas = load.canvas(this.image);
34
- this.bitmap = load.bitmap(this.canvas, info);
35
- this.bitmap.pathlist(this.pathlist);
36
- var process = new Processor(info, this.pathlist);
37
- process.init();
38
- var svg = new Svg(info, this.pathlist, this.bitmap);
39
- var traced = svg.get();
40
- resolve(traced);
41
- } catch (err) {
42
- reject(err);
43
- }
44
- });
23
+ trace: async function () {
24
+ var info = this.options.all();
25
+ var load = new Loader();
26
+ this.image = await load.image(this.image);
27
+ this.bitmap = load.bitmap(this.image, info);
28
+ this.bitmap.pathlist(this.pathlist);
29
+ var process = new Processor(info, this.pathlist);
30
+ process.init();
31
+ var svg = new Svg(info, this.pathlist, this.bitmap);
32
+ var traced = svg.get();
33
+ return traced;
45
34
  },
46
35
  };
47
36
 
package/src/loader.js CHANGED
@@ -2,61 +2,43 @@
2
2
 
3
3
  const jimp = require("jimp");
4
4
  const error = require("./error");
5
- const is = require("oslllo-validator");
6
5
  const Bitmap = require("./types/Bitmap");
7
6
 
8
- const Loader = function (dom) {
9
- this.document = dom.window.document;
7
+ const Loader = function () {
10
8
  };
11
9
 
12
10
  Loader.prototype = {
13
11
  image: function (image) {
14
- return new Promise(async (resolve, reject) => {
15
- if (!is.buffer(image) && !is.string(image)) {
16
- var err = error.invalidParameterError(
17
- "image",
18
- "buffer or path to image",
19
- image
20
- );
21
- return reject(err);
22
- }
23
- var element = this.document.createElement("img");
24
- image = await jimp.read(image);
25
- var base64 = await image.getBase64Async(jimp.AUTO);
26
- element.onload = () => {
27
- var data = {
28
- file: image,
29
- base64: base64,
30
- element: element,
31
- };
32
- resolve(data);
33
- };
34
- element.src = base64;
35
- });
36
- },
37
- canvas: function (image) {
38
- var { element } = image;
39
- var canvas = this.document.createElement("canvas");
40
- canvas.width = element.width;
41
- canvas.height = element.height;
42
- var ctx = canvas.getContext("2d");
43
- ctx.drawImage(element, 0, 0);
44
-
45
- return canvas;
12
+ const valid = image instanceof Buffer || typeof image === 'string'
13
+ if (!valid) {
14
+ var err = error.invalidParameterError(
15
+ "image",
16
+ "buffer or path to image",
17
+ image
18
+ );
19
+ throw err;
20
+ }
21
+ return jimp.read(image);
46
22
  },
47
- bitmap: function (canvas, info) {
48
- var ctx = canvas.getContext("2d");
49
- var bitmap = new Bitmap(canvas.width, canvas.height, info);
50
- var imageDataObject = ctx.getImageData(0, 0, bitmap.w, bitmap.h);
51
- var l = imageDataObject.data.length,
23
+ bitmap: function (image, info) {
24
+ var {
25
+ bitmap: {
26
+ data,
27
+ width,
28
+ height,
29
+ }
30
+ } = image;
31
+ var u8 = new Uint8ClampedArray(data.buffer)
32
+ var bitmap = new Bitmap(width, height, info);
33
+ var l = data.length,
52
34
  i,
53
35
  j,
54
36
  color;
55
37
  for (i = 0, j = 0; i < l; i += 4, j++) {
56
38
  color =
57
- 0.2126 * imageDataObject.data[i] +
58
- 0.7153 * imageDataObject.data[i + 1] +
59
- 0.0721 * imageDataObject.data[i + 2];
39
+ 0.2126 * data[i] +
40
+ 0.7153 * data[i + 1] +
41
+ 0.0721 * data[i + 2];
60
42
  bitmap.data[j] = color < 128 ? 1 : 0;
61
43
  }
62
44
 
package/src/option.js CHANGED
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
 
3
- const error = require("./error");
4
- const is = require("oslllo-validator");
5
3
  const constants = require("./constants");
6
4
 
7
- const Option = function (options = {}) {
5
+ const Option = function (options) {
8
6
  this.data = {
9
7
  turnpolicy: constants.TURNPOLICY_MINORITY,
10
8
  turdsize: 2,
@@ -13,13 +11,8 @@ const Option = function (options = {}) {
13
11
  opttolerance: 0.2,
14
12
  svgSize: 1,
15
13
  opt_type: undefined,
14
+ ...options,
16
15
  };
17
- if (!is.object(options)) {
18
- throw error.invalidParameterError("options", "object", options);
19
- }
20
- if (!is.empty(options)) {
21
- this.update(options);
22
- }
23
16
 
24
17
  return this;
25
18
  };
@@ -28,27 +21,6 @@ Option.prototype = {
28
21
  all: function () {
29
22
  return this.data;
30
23
  },
31
- get: function (option) {
32
- if (!is.defined(option) || !is.string(option)) {
33
- throw error.invalidParameterError("option", "string", option);
34
- }
35
- var options = Object.keys(this.data);
36
- if (!options.includes(option)) {
37
- throw error.invalidParameterError(
38
- "setting",
39
- `one of ${options.toString()}`,
40
- option
41
- );
42
- }
43
- return this.data[option];
44
- },
45
- update: function (options) {
46
- for (var key in options) {
47
- if (options.hasOwnProperty(key)) {
48
- this.data[key] = options[key];
49
- }
50
- }
51
- },
52
24
  };
53
25
 
54
26
  module.exports = Option;
package/src/processor.js CHANGED
@@ -3,10 +3,8 @@
3
3
  const Sum = require("./types/Sum");
4
4
  const Quad = require("./types/Quad");
5
5
  const Opti = require("./types/Opti");
6
- const Path = require("./types/Path");
7
6
  const Point = require("./types/Point");
8
7
  const Curve = require("./types/Curve");
9
- const Bitmap = require("./types/Bitmap");
10
8
 
11
9
  const Processor = function (info, pathlist) {
12
10
  this.info = info;