polotno-node 2.10.5 → 2.10.6

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 CHANGED
@@ -15,8 +15,8 @@ npm install polotno-node
15
15
  ```
16
16
 
17
17
  ```js
18
- const fs = require('fs');
19
- const { createInstance } = require('polotno-node');
18
+ const fs = require("fs");
19
+ const { createInstance } = require("polotno-node");
20
20
 
21
21
  async function run() {
22
22
  // create working instance
@@ -24,14 +24,14 @@ async function run() {
24
24
  // this is a demo key just for that project
25
25
  // (!) please don't use it in your projects
26
26
  // to create your own API key please go here: https://polotno.dev/cabinet
27
- key: 'nFA5H9elEytDyPyvKL7T',
27
+ key: "nFA5H9elEytDyPyvKL7T",
28
28
  });
29
29
 
30
30
  // load sample json
31
- const json = JSON.parse(fs.readFileSync('polotno.json'));
31
+ const json = JSON.parse(fs.readFileSync("polotno.json"));
32
32
 
33
33
  const imageBase64 = await instance.jsonToImageBase64(json);
34
- fs.writeFileSync('out.png', imageBase64, 'base64');
34
+ fs.writeFileSync("out.png", imageBase64, "base64");
35
35
 
36
36
  // close instance
37
37
  instance.close();
@@ -47,12 +47,12 @@ run();
47
47
  Create working instance of Polotno Node.
48
48
 
49
49
  ```js
50
- const { createInstance } = require('polotno-node');
50
+ const { createInstance } = require("polotno-node");
51
51
  const instance = await createInstance({
52
52
  // this is a demo key just for that project
53
53
  // (!) please don't use it in your projects
54
54
  // to create your own API key please go here: https://polotno.dev/cabinet
55
- key: 'nFA5H9elEytDyPyvKL7T',
55
+ key: "nFA5H9elEytDyPyvKL7T",
56
56
  // useParallelPages - use parallel pages to speed up rendering
57
57
  // you can use false only for sequential calls
58
58
  // it may break rendering if you call many parallel requests
@@ -61,7 +61,7 @@ const instance = await createInstance({
61
61
  // url - url of the Polotno Client Editor
62
62
  // client editor is just simple public html page that have `store` as global variable
63
63
  // by default it will run local build
64
- url: 'https://yourappdomain.com/client',
64
+ url: "https://yourappdomain.com/client",
65
65
  // browser - puppeteer browser instance
66
66
  // by default it will use chrome-aws-lambda
67
67
  // useful to set your own rendering props or use browserless
@@ -74,7 +74,7 @@ const instance = await createInstance({
74
74
  Export json into data URL.
75
75
 
76
76
  ```js
77
- const json = JSON.parse(fs.readFileSync('polotno.json'));
77
+ const json = JSON.parse(fs.readFileSync("polotno.json"));
78
78
 
79
79
  // by default it will export first page only
80
80
  const url = await instance.jsonToDataURL(json);
@@ -95,13 +95,13 @@ for (const page of json.pages) {
95
95
  Export json into base64 string of image.
96
96
 
97
97
  ```js
98
- const json = JSON.parse(fs.readFileSync('polotno.json'));
98
+ const json = JSON.parse(fs.readFileSync("polotno.json"));
99
99
 
100
100
  // by default it will export first page only
101
101
  const imageBase64 = await instance.jsonToImageBase64(json, {
102
- mimeType: 'image/png',
102
+ mimeType: "image/png",
103
103
  }); // also 'image/jpeg' is supported
104
- fs.writeFileSync('out.png', imageBase64, 'base64');
104
+ fs.writeFileSync("out.png", imageBase64, "base64");
105
105
 
106
106
  // export many pages:
107
107
  for (const page of json.pages) {
@@ -118,11 +118,11 @@ for (const page of json.pages) {
118
118
  Export json into base64 string of pdf file.
119
119
 
120
120
  ```js
121
- const json = JSON.parse(fs.readFileSync('polotno.json'));
121
+ const json = JSON.parse(fs.readFileSync("polotno.json"));
122
122
 
123
123
  // it will export all pages in the JSON
124
124
  const pdfBase64 = await instance.jsonToPDFBase64(json);
125
- fs.writeFileSync('out.pdf', pdfBase64, 'base64');
125
+ fs.writeFileSync("out.pdf", pdfBase64, "base64");
126
126
  ```
127
127
 
128
128
  ### `instance.jsonToPDFDataURL(json, attrs)`
@@ -130,7 +130,7 @@ fs.writeFileSync('out.pdf', pdfBase64, 'base64');
130
130
  Export json into data url of pdf file.
131
131
 
132
132
  ```js
133
- const json = JSON.parse(fs.readFileSync('polotno.json'));
133
+ const json = JSON.parse(fs.readFileSync("polotno.json"));
134
134
 
135
135
  const url = await instance.jsonToPDFDataURL(json);
136
136
  res.json({ url });
@@ -141,7 +141,7 @@ res.json({ url });
141
141
  Export json into data url of GIF file with animations
142
142
 
143
143
  ```js
144
- const json = JSON.parse(fs.readFileSync('polotno.json'));
144
+ const json = JSON.parse(fs.readFileSync("polotno.json"));
145
145
 
146
146
  const url = await instance.jsonToGIFDataURL(json);
147
147
  res.json({ url });
@@ -152,10 +152,10 @@ res.json({ url });
152
152
  Export json into data url of GIF file with animations
153
153
 
154
154
  ```js
155
- const json = JSON.parse(fs.readFileSync('polotno.json'));
155
+ const json = JSON.parse(fs.readFileSync("polotno.json"));
156
156
 
157
157
  const base64 = await instance.jsonToGIFBase64(json);
158
- fs.writeFileSync('out.gif', base64, 'base64');
158
+ fs.writeFileSync("out.gif", base64, "base64");
159
159
  ```
160
160
 
161
161
  ### `attrs` usage
@@ -233,7 +233,7 @@ Control behavior of text on its overflow. Default is `change-font-size`. It mean
233
233
 
234
234
  ```js
235
235
  const url = await instance.jsonToPDFDataURL(json, {
236
- textOverflow: 'resize',
236
+ textOverflow: "resize",
237
237
  });
238
238
  ```
239
239
 
@@ -249,8 +249,8 @@ Run any Polotno store API directly inside web-page context.
249
249
  const url = await instance.run(async (json) => {
250
250
  // you can use global "config" object that has some functions from "polotno/config" module
251
251
  window.config.addGlobalFont({
252
- name: 'MyCustomFont',
253
- url: 'https://example.com/font.otf',
252
+ name: "MyCustomFont",
253
+ url: "https://example.com/font.otf",
254
254
  });
255
255
 
256
256
  // you can use global "store" object
@@ -279,7 +279,7 @@ const url = await instance.run(async (json) => {
279
279
 
280
280
  ## Video export
281
281
 
282
- **This part is currently under development and API will change.**
282
+ **Video export is deprecated on this package and not supported anymore.**
283
283
 
284
284
  You may need to have ffmpeg available in your system to make it work.
285
285
  Also you need to manually dependencies:
@@ -289,11 +289,11 @@ npm install fluent-ffmpeg axios
289
289
  ```
290
290
 
291
291
  ```js
292
- import { createInstance } from 'polotno-node';
293
- import { jsonToVideo } from 'polotno-node/video-parallel';
292
+ import { createInstance } from "polotno-node";
293
+ import { jsonToVideo } from "polotno-node/video-parallel";
294
294
 
295
295
  // load sample json
296
- const json = JSON.parse(fs.readFileSync('./test-data/video.json'));
296
+ const json = JSON.parse(fs.readFileSync("./test-data/video.json"));
297
297
 
298
298
  await jsonToVideo(
299
299
  // first argument is a function that returns an instance
@@ -301,11 +301,11 @@ await jsonToVideo(
301
301
  // or it can be a single instance (useful for cloud functions)
302
302
  () =>
303
303
  createInstance({
304
- key: '...key...',
304
+ key: "...key...",
305
305
  }),
306
306
  json,
307
307
  {
308
- out: 'out.mp4', // output file name
308
+ out: "out.mp4", // output file name
309
309
  parallel: 4, // number of parallel rendering processes
310
310
  fps: 15, // frames per second
311
311
  keepInstance: false, // keep instance open after rendering, make sure to use true if use just one instance
@@ -324,11 +324,11 @@ Pass `url` option to `createInstance` function with public url of your client ed
324
324
  **Note: you will have to maintain the last version of your client editor by yourself. Better to keep using the last **
325
325
 
326
326
  ```js
327
- const { createInstance } = require('polotno-node');
327
+ const { createInstance } = require("polotno-node");
328
328
 
329
329
  const instance = await createInstance({
330
- key: 'KEY',
331
- url: 'https://yourappdomain.com/client',
330
+ key: "KEY",
331
+ url: "https://yourappdomain.com/client",
332
332
  });
333
333
  ```
334
334
 
@@ -353,15 +353,15 @@ You can speed up your function execution a lot, if instead of using full browser
353
353
  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.
354
354
 
355
355
  ```js
356
- const { createInstance } = require('polotno-node/instance');
357
- const puppeteer = require('puppeteer');
356
+ const { createInstance } = require("polotno-node/instance");
357
+ const puppeteer = require("puppeteer");
358
358
 
359
359
  const instance = await createInstance({
360
- key: 'nFA5H9elEytDyPyvKL7T',
360
+ key: "nFA5H9elEytDyPyvKL7T",
361
361
  browser: await puppeteer.connect({
362
- browserWSEndpoint: 'wss://chrome.browserless.io?token=API_KEY',
362
+ browserWSEndpoint: "wss://chrome.browserless.io?token=API_KEY",
363
363
  }),
364
- url: 'https://yourappdomain.com/client', // see "Your own client" section
364
+ url: "https://yourappdomain.com/client", // see "Your own client" section
365
365
  });
366
366
  ```
367
367
 
@@ -374,33 +374,33 @@ npm install @sparticuz/chromium-min
374
374
  ```
375
375
 
376
376
  ```js
377
- const { createInstance } = require('polotno-node/instance');
378
- const chromium = require('@sparticuz/chromium-min');
379
- const puppeteer = require('puppeteer-core');
377
+ const { createInstance } = require("polotno-node/instance");
378
+ const chromium = require("@sparticuz/chromium-min");
379
+ const puppeteer = require("puppeteer-core");
380
380
 
381
381
  const makeInstance = async () => {
382
382
  const browser = await puppeteer.launch({
383
383
  args: [
384
384
  ...chromium.args,
385
- '--no-sandbox',
386
- '--hide-scrollbars',
387
- '--disable-web-security',
388
- '--allow-file-access-from-files',
385
+ "--no-sandbox",
386
+ "--hide-scrollbars",
387
+ "--disable-web-security",
388
+ "--allow-file-access-from-files",
389
389
  // more info about --disable-dev-shm-usage
390
390
  // https://github.com/puppeteer/puppeteer/issues/1175#issuecomment-369728215
391
391
  // https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#tips
392
- '--disable-dev-shm-usage',
392
+ "--disable-dev-shm-usage",
393
393
  ],
394
394
  defaultViewport: chromium.defaultViewport,
395
395
  executablePath: await chromium.executablePath(
396
- 'https://github.com/Sparticuz/chromium/releases/download/v110.0.1/chromium-v110.0.1-pack.tar'
396
+ "https://github.com/Sparticuz/chromium/releases/download/v110.0.1/chromium-v110.0.1-pack.tar"
397
397
  ),
398
398
  headless: chromium.headless,
399
399
  ignoreHTTPSErrors: true,
400
400
  });
401
401
 
402
402
  return await createInstance({
403
- key: 'your-key',
403
+ key: "your-key",
404
404
  browser,
405
405
  });
406
406
  };