polotno-node 1.0.0 → 2.0.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/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.a5a7eab1.js"></script> </body></html>
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.f7f82675.js"></script> </body></html>
package/instance.js CHANGED
@@ -53,10 +53,22 @@ module.exports.jsonToPDFDataURL = async (page, json, attrs) => {
53
53
  );
54
54
  };
55
55
 
56
+ module.exports.jsonToBlob = async (page, json, attrs) => {
57
+ return page.evaluate(
58
+ async (json, attrs) => {
59
+ store.loadJSON(json);
60
+ await store.waitLoading();
61
+ return await store.toBlob(attrs);
62
+ },
63
+ json,
64
+ attrs || {}
65
+ );
66
+ };
67
+
56
68
  module.exports.createInstance = async ({
57
69
  key,
58
70
  url,
59
- useParallelPages,
71
+ useParallelPages = true,
60
72
  browser,
61
73
  } = {}) => {
62
74
  const visitPage = url || `${DEFAULT_CLIENT}?key=${key}`;
@@ -69,11 +81,18 @@ module.exports.createInstance = async ({
69
81
  ? await module.exports.createPage(browser, visitPage)
70
82
  : firstPage;
71
83
 
72
- const result = await page.evaluate(func, ...args);
73
- if (useParallelPages) {
74
- page.close();
84
+ try {
85
+ const result = await page.evaluate(func, ...args);
86
+ if (useParallelPages) {
87
+ page.close();
88
+ }
89
+ return result;
90
+ } catch (e) {
91
+ if (useParallelPages) {
92
+ page.close();
93
+ }
94
+ throw e;
75
95
  }
76
- return result;
77
96
  };
78
97
 
79
98
  const jsonToDataURL = async (json, attrs) => {
@@ -107,6 +126,18 @@ module.exports.createInstance = async ({
107
126
  );
108
127
  };
109
128
 
129
+ const jsonToBlob = async (json, attrs) => {
130
+ return await run(
131
+ async (json, attrs) => {
132
+ store.loadJSON(json);
133
+ await store.waitLoading();
134
+ return await store.toBlob(attrs);
135
+ },
136
+ json,
137
+ attrs || {}
138
+ );
139
+ };
140
+
110
141
  const jsonToPDFBase64 = async (json, attrs) => {
111
142
  const url = await jsonToPDFDataURL(json, attrs);
112
143
  return url.split('base64,')[1];
@@ -115,10 +146,12 @@ module.exports.createInstance = async ({
115
146
  return {
116
147
  close: async () => await browser.close(),
117
148
  firstPage,
149
+ browser,
118
150
  run,
119
151
  jsonToDataURL,
120
152
  jsonToImageBase64,
121
153
  jsonToPDFDataURL,
122
154
  jsonToPDFBase64,
155
+ jsonToBlob,
123
156
  };
124
157
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polotno-node",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "Polotno workflow from NodeJS",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -15,7 +15,7 @@
15
15
  ],
16
16
  "devDependencies": {
17
17
  "parcel-bundler": "^1.12.4",
18
- "polotno": "^1.2.0",
18
+ "polotno": "^1.4.0",
19
19
  "react": "^18.2.0",
20
20
  "react-dom": "^18.2.0"
21
21
  },