polotno-node 0.2.0 → 0.2.4
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/dist/{client.beff6260.js → client.3b178911.js} +153 -111
- package/dist/client.html +1 -1
- package/index.js +30 -13
- package/package.json +2 -2
package/dist/client.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<html><head><title>Canvas editor</title><style>body{padding:0;margin:0}</style><meta name="viewport" content="width=device-width, initial-scale=1"></head><body class="bp3-dark"> <div id="root"></div> <script src="client.
|
|
1
|
+
<html><head><title>Canvas editor</title><style>body{padding:0;margin:0}</style><meta name="viewport" content="width=device-width, initial-scale=1"></head><body class="bp3-dark"> <div id="root"></div> <script src="client.3b178911.js"></script> </body></html>
|
package/index.js
CHANGED
|
@@ -26,7 +26,12 @@ const getNewPage = async (browser, url) => {
|
|
|
26
26
|
return page;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
module.exports.createInstance = async ({
|
|
29
|
+
module.exports.createInstance = async ({
|
|
30
|
+
key,
|
|
31
|
+
url,
|
|
32
|
+
useParallelPages,
|
|
33
|
+
browserArgs = [],
|
|
34
|
+
} = {}) => {
|
|
30
35
|
const browser = await puppeteer.launch({
|
|
31
36
|
args: [
|
|
32
37
|
...chrome.args,
|
|
@@ -34,6 +39,11 @@ module.exports.createInstance = async ({ key, url, useParallelPages } = {}) => {
|
|
|
34
39
|
'--hide-scrollbars',
|
|
35
40
|
'--disable-web-security',
|
|
36
41
|
'--allow-file-access-from-files',
|
|
42
|
+
// more info about --disable-dev-shm-usage
|
|
43
|
+
// https://github.com/puppeteer/puppeteer/issues/1175#issuecomment-369728215
|
|
44
|
+
// https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#tips
|
|
45
|
+
'--disable-dev-shm-usage',
|
|
46
|
+
...browserArgs,
|
|
37
47
|
],
|
|
38
48
|
defaultViewport: chrome.defaultViewport,
|
|
39
49
|
executablePath: await chrome.executablePath,
|
|
@@ -75,22 +85,29 @@ module.exports.createInstance = async ({ key, url, useParallelPages } = {}) => {
|
|
|
75
85
|
return url.split('base64,')[1];
|
|
76
86
|
};
|
|
77
87
|
|
|
88
|
+
const jsonToPDFDataURL = async (json, attrs) => {
|
|
89
|
+
return await run(
|
|
90
|
+
async (json, attrs) => {
|
|
91
|
+
store.loadJSON(json);
|
|
92
|
+
await store.waitLoading();
|
|
93
|
+
return await store.toPDFDataURL(attrs);
|
|
94
|
+
},
|
|
95
|
+
json,
|
|
96
|
+
attrs || {}
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const jsonToPDFBase64 = async (json, attrs) => {
|
|
101
|
+
const url = await jsonToPDFDataURL(json, attrs);
|
|
102
|
+
return url.split('base64,')[1];
|
|
103
|
+
};
|
|
104
|
+
|
|
78
105
|
return {
|
|
79
106
|
close: async () => await browser.close(),
|
|
80
107
|
run,
|
|
81
108
|
jsonToDataURL,
|
|
82
109
|
jsonToImageBase64,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
async (json, attrs) => {
|
|
86
|
-
store.loadJSON(json);
|
|
87
|
-
await store.waitLoading();
|
|
88
|
-
const url = await store.toPDFDataURL(attrs);
|
|
89
|
-
return url.split('base64,')[1];
|
|
90
|
-
},
|
|
91
|
-
json,
|
|
92
|
-
attrs || {}
|
|
93
|
-
);
|
|
94
|
-
},
|
|
110
|
+
jsonToPDFDataURL,
|
|
111
|
+
jsonToPDFBase64,
|
|
95
112
|
};
|
|
96
113
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polotno-node",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Polotno workflow from NodeJS",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
],
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"parcel-bundler": "^1.12.4",
|
|
17
|
-
"polotno": "^0.
|
|
17
|
+
"polotno": "^0.38.2",
|
|
18
18
|
"react": "^17.0.2",
|
|
19
19
|
"react-dom": "^17.0.2"
|
|
20
20
|
},
|