polotno-node 0.1.15 → 0.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/README.md +1 -1
- package/dist/{client.15ee498b.js → client.beff6260.js} +30 -989
- package/dist/client.html +1 -1
- package/index.js +34 -13
- package/package.json +3 -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.beff6260.js"></script> </body></html>
|
package/index.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
+
const chrome = require('chrome-aws-lambda');
|
|
1
2
|
const puppeteer = require('puppeteer');
|
|
2
3
|
const path = require('path');
|
|
3
4
|
|
|
4
|
-
const
|
|
5
|
-
const puppeteer = require('puppeteer');
|
|
6
|
-
return await puppeteer.launch({});
|
|
7
|
-
};
|
|
5
|
+
const DEFAULT_CLIENT = `file:${path.join(__dirname, 'dist', 'client.html')}`;
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
key,
|
|
11
|
-
launch = defaultLaunch,
|
|
12
|
-
} = {}) => {
|
|
13
|
-
const browser = await launch();
|
|
7
|
+
const getNewPage = async (browser, url) => {
|
|
14
8
|
const page = await browser.newPage();
|
|
15
9
|
|
|
16
10
|
page.on('console', (msg) => {
|
|
@@ -27,12 +21,39 @@ module.exports.createInstance = async ({
|
|
|
27
21
|
});
|
|
28
22
|
});
|
|
29
23
|
|
|
30
|
-
await page.goto(
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
await page.goto(url);
|
|
25
|
+
|
|
26
|
+
return page;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
module.exports.createInstance = async ({ key, url, useParallelPages } = {}) => {
|
|
30
|
+
const browser = await puppeteer.launch({
|
|
31
|
+
args: [
|
|
32
|
+
...chrome.args,
|
|
33
|
+
'--no-sandbox',
|
|
34
|
+
'--hide-scrollbars',
|
|
35
|
+
'--disable-web-security',
|
|
36
|
+
'--allow-file-access-from-files',
|
|
37
|
+
],
|
|
38
|
+
defaultViewport: chrome.defaultViewport,
|
|
39
|
+
executablePath: await chrome.executablePath,
|
|
40
|
+
headless: true,
|
|
41
|
+
ignoreHTTPSErrors: true,
|
|
42
|
+
});
|
|
43
|
+
const visitPage = url || `${DEFAULT_CLIENT}?key=${key}`;
|
|
44
|
+
|
|
45
|
+
const firstPage = await getNewPage(browser, visitPage);
|
|
33
46
|
|
|
34
47
|
const run = async (func, ...args) => {
|
|
35
|
-
|
|
48
|
+
const page = useParallelPages
|
|
49
|
+
? await getNewPage(browser, visitPage)
|
|
50
|
+
: firstPage;
|
|
51
|
+
|
|
52
|
+
const result = await page.evaluate(func, ...args);
|
|
53
|
+
if (useParallelPages) {
|
|
54
|
+
page.close();
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
36
57
|
};
|
|
37
58
|
|
|
38
59
|
const jsonToDataURL = async (json, attrs) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polotno-node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Polotno workflow from NodeJS",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,13 +14,14 @@
|
|
|
14
14
|
],
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"parcel-bundler": "^1.12.4",
|
|
17
|
-
"polotno": "^0.34.
|
|
17
|
+
"polotno": "^0.34.7",
|
|
18
18
|
"react": "^17.0.2",
|
|
19
19
|
"react-dom": "^17.0.2"
|
|
20
20
|
},
|
|
21
21
|
"author": "Anton Lavrenov",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
+
"chrome-aws-lambda": "^10.1.0",
|
|
24
25
|
"puppeteer": "^10.4.0"
|
|
25
26
|
}
|
|
26
27
|
}
|