oslllo-potrace 1.1.4 → 1.2.0
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 +14 -0
- package/package.json +1 -1
- package/src/constructor.js +12 -19
- package/src/loader.js +25 -23
- package/src/processor.js +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,20 @@ 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
|
+
## [1.2.0](https://www.github.com/oslllo/potrace/compare/v1.1.4...v1.2.0) (2021-12-30)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **potrace:** new Promise() is not needed with async function ([1adad10](https://www.github.com/oslllo/potrace/commit/1adad10ec6c0b6d19598d47faa36e64a574a756c))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* **src:** remove unused vars ([a00c02a](https://www.github.com/oslllo/potrace/commit/a00c02a982472ea78dd74fd20c6402e093775002))
|
|
19
|
+
* unhandled rejection in Loader.image() ([5edf4a7](https://www.github.com/oslllo/potrace/commit/5edf4a79ed971160578003dd9c236c0ac9accf98))
|
|
20
|
+
* unhandled rejection in Loader.image() ([0c3843f](https://www.github.com/oslllo/potrace/commit/0c3843f078a64570043f5a046844197c86a943af))
|
|
21
|
+
|
|
8
22
|
### [1.1.4](https://www.github.com/oslllo/potrace/compare/v1.1.3...v1.1.4) (2021-09-05)
|
|
9
23
|
|
|
10
24
|
|
package/package.json
CHANGED
package/src/constructor.js
CHANGED
|
@@ -5,7 +5,6 @@ const Loader = require("./loader");
|
|
|
5
5
|
const Option = require("./option");
|
|
6
6
|
const { JSDOM } = require("jsdom");
|
|
7
7
|
const is = require("oslllo-validator");
|
|
8
|
-
const EventEmitter = require("events");
|
|
9
8
|
const Processor = require("./processor");
|
|
10
9
|
const constants = require("./constants");
|
|
11
10
|
|
|
@@ -24,24 +23,18 @@ const Potrace = function (image, options) {
|
|
|
24
23
|
};
|
|
25
24
|
|
|
26
25
|
Potrace.prototype = {
|
|
27
|
-
trace: function () {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var traced = svg.get();
|
|
40
|
-
resolve(traced);
|
|
41
|
-
} catch (err) {
|
|
42
|
-
reject(err);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
26
|
+
trace: async function () {
|
|
27
|
+
var info = this.options.all();
|
|
28
|
+
var load = new Loader(this.dom);
|
|
29
|
+
this.image = await load.image(this.image);
|
|
30
|
+
this.canvas = load.canvas(this.image);
|
|
31
|
+
this.bitmap = load.bitmap(this.canvas, info);
|
|
32
|
+
this.bitmap.pathlist(this.pathlist);
|
|
33
|
+
var process = new Processor(info, this.pathlist);
|
|
34
|
+
process.init();
|
|
35
|
+
var svg = new Svg(info, this.pathlist, this.bitmap);
|
|
36
|
+
var traced = svg.get();
|
|
37
|
+
return traced;
|
|
45
38
|
},
|
|
46
39
|
};
|
|
47
40
|
|
package/src/loader.js
CHANGED
|
@@ -9,30 +9,32 @@ const Loader = function (dom) {
|
|
|
9
9
|
this.document = dom.window.document;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
+
const base64ToImage = (document, base64) => new Promise((resolve) => {
|
|
13
|
+
var element = document.createElement("img");
|
|
14
|
+
element.onload = () => {
|
|
15
|
+
resolve(element);
|
|
16
|
+
};
|
|
17
|
+
element.src = base64;
|
|
18
|
+
});
|
|
19
|
+
|
|
12
20
|
Loader.prototype = {
|
|
13
|
-
image: function (image) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
element: element,
|
|
31
|
-
};
|
|
32
|
-
resolve(data);
|
|
33
|
-
};
|
|
34
|
-
element.src = base64;
|
|
35
|
-
});
|
|
21
|
+
image: async function (image) {
|
|
22
|
+
if (!is.buffer(image) && !is.string(image)) {
|
|
23
|
+
var err = error.invalidParameterError(
|
|
24
|
+
"image",
|
|
25
|
+
"buffer or path to image",
|
|
26
|
+
image
|
|
27
|
+
);
|
|
28
|
+
throw err;
|
|
29
|
+
}
|
|
30
|
+
image = await jimp.read(image);
|
|
31
|
+
var base64 = await image.getBase64Async(jimp.AUTO);
|
|
32
|
+
var element = await base64ToImage(this.document, base64);
|
|
33
|
+
return {
|
|
34
|
+
file: image,
|
|
35
|
+
base64: base64,
|
|
36
|
+
element: element,
|
|
37
|
+
};;
|
|
36
38
|
},
|
|
37
39
|
canvas: function (image) {
|
|
38
40
|
var { element } = image;
|
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;
|