polotno-node 2.0.7 → 2.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 +91 -6
- package/dist/{client.51dfa0bd.js → client.3517c032.js} +486 -792
- package/dist/client.html +1 -1
- package/index.js +12 -4
- package/instance.js +18 -2
- package/package.json +10 -5
package/README.md
CHANGED
|
@@ -131,6 +131,34 @@ const url = await instance.jsonToPDFDataURL(json);
|
|
|
131
131
|
res.json({ url });
|
|
132
132
|
```
|
|
133
133
|
|
|
134
|
+
### `attrs` usage
|
|
135
|
+
|
|
136
|
+
**NOTE: all export API will pass `attrs` object into relevant export function from `store`.**
|
|
137
|
+
|
|
138
|
+
```js
|
|
139
|
+
const url = await instance.jsonToDataURL(json, { pixelRatio: 0.2 });
|
|
140
|
+
// under the hood it will call:
|
|
141
|
+
// const url = await store.toDataURL({ pixelRatio: 0.2 });
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### `attrs.assetLoadTimeout`
|
|
145
|
+
|
|
146
|
+
You can add `assetLoadTimeout` attribute to `attrs` object. It will be used to set timeout for loading assets (images, fonts, etc). By default it is 30000ms.
|
|
147
|
+
|
|
148
|
+
```js
|
|
149
|
+
const url = await instance.jsonToPDFDataURL(json, { assetLoadTimeout: 60000 });
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### `attrs.htmlTextRenderEnabled`
|
|
153
|
+
|
|
154
|
+
Enabled experimental HTML text rendering. By default it is `false`.
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
const url = await instance.jsonToPDFDataURL(json, {
|
|
158
|
+
htmlTextRenderEnabled: true,
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
134
162
|
### `instance.run()`
|
|
135
163
|
|
|
136
164
|
Run any Polotno store API directly inside web-page context.
|
|
@@ -190,9 +218,15 @@ const instance = await createInstance({
|
|
|
190
218
|
});
|
|
191
219
|
```
|
|
192
220
|
|
|
193
|
-
##
|
|
221
|
+
## Usage on the cloud
|
|
222
|
+
|
|
223
|
+
`polotno-node` should work by default on AWS Lambda. But in some cloud providers you may need to do extra steps to reduce function size.
|
|
224
|
+
|
|
225
|
+
### Browserless usage
|
|
194
226
|
|
|
195
|
-
|
|
227
|
+
You can speed up your function execution a lot, if instead of using full browser you will use [browserless.io](https://browserless.io/) service. It is a paid service not affiliated with Polotno.
|
|
228
|
+
|
|
229
|
+
Using browserless.io you can also make your function much smaller in size, so it will be possible to deploy to cloud provider with smaller limits, like Vercel.
|
|
196
230
|
|
|
197
231
|
```js
|
|
198
232
|
const { createInstance } = require('polotno-node/instance');
|
|
@@ -206,20 +240,71 @@ const instance = await createInstance({
|
|
|
206
240
|
});
|
|
207
241
|
```
|
|
208
242
|
|
|
243
|
+
### Minimal usage
|
|
244
|
+
|
|
245
|
+
Also you can use [@sparticuz/chromium-min](https://github.com/Sparticuz/chromium#-min-package) to reduce function size. Make sure it is caching chromium binary in your cloud provider. Looks like Vercel is NOT doing that!
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
npm install @sparticuz/chromium-min
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
```js
|
|
252
|
+
const { createInstance } = require('polotno-node/instance');
|
|
253
|
+
const chromium = require('@sparticuz/chromium-min');
|
|
254
|
+
const puppeteer = require('puppeteer-core');
|
|
255
|
+
|
|
256
|
+
const makeInstance = async () => {
|
|
257
|
+
const browser = await puppeteer.launch({
|
|
258
|
+
args: [
|
|
259
|
+
...chromium.args,
|
|
260
|
+
'--no-sandbox',
|
|
261
|
+
'--hide-scrollbars',
|
|
262
|
+
'--disable-web-security',
|
|
263
|
+
'--allow-file-access-from-files',
|
|
264
|
+
// more info about --disable-dev-shm-usage
|
|
265
|
+
// https://github.com/puppeteer/puppeteer/issues/1175#issuecomment-369728215
|
|
266
|
+
// https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#tips
|
|
267
|
+
'--disable-dev-shm-usage',
|
|
268
|
+
],
|
|
269
|
+
defaultViewport: chromium.defaultViewport,
|
|
270
|
+
executablePath: await chromium.executablePath(
|
|
271
|
+
'https://github.com/Sparticuz/chromium/releases/download/v110.0.1/chromium-v110.0.1-pack.tar'
|
|
272
|
+
),
|
|
273
|
+
headless: chromium.headless,
|
|
274
|
+
ignoreHTTPSErrors: true,
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
return await createInstance({
|
|
278
|
+
key: 'your-key',
|
|
279
|
+
browser,
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const instance = await makeInstance();
|
|
284
|
+
```
|
|
285
|
+
|
|
209
286
|
## Troubleshooting
|
|
210
287
|
|
|
211
288
|
If you have an error like this
|
|
212
289
|
|
|
213
290
|
```
|
|
214
|
-
|
|
291
|
+
|
|
292
|
+
Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: Evaluation failed: ReferenceError: store is not defined\n at **puppeteer_evaluation_script**:3:9"
|
|
293
|
+
|
|
215
294
|
```
|
|
216
295
|
|
|
217
296
|
It may mean that Polotno Client Editor was not loaded in `puppeteer` instance. It is possible that you are missing required files in `node_modules` folder. I got this error when I was trying to run `polotno-node` on Vercel. To fix the issue you need to add this config into `vercel.json`:
|
|
218
297
|
|
|
219
298
|
```
|
|
299
|
+
|
|
220
300
|
"functions": {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
301
|
+
"api/render.js": { // remember to replace this line with your function name
|
|
302
|
+
"includeFiles": "node_modules/polotno-node/\*\*"
|
|
303
|
+
},
|
|
224
304
|
}
|
|
305
|
+
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
```
|
|
309
|
+
|
|
225
310
|
```
|