polotno-node 2.10.9 → 2.11.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 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,17 @@ 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
+ });
238
+ ```
239
+
240
+ ### `attrs.textSplitAllowed`
241
+
242
+ Additinal options to overflow behaviour. Default is `false`. It means the render will make sure no words are rendered into several lines. If you set it to `true`, the render will split words into several lines if needed without reducing font size.
243
+
244
+ ```js
245
+ const url = await instance.jsonToPDFDataURL(json, {
246
+ textSplitAllowed: true,
237
247
  });
238
248
  ```
239
249
 
@@ -249,8 +259,8 @@ Run any Polotno store API directly inside web-page context.
249
259
  const url = await instance.run(async (json) => {
250
260
  // you can use global "config" object that has some functions from "polotno/config" module
251
261
  window.config.addGlobalFont({
252
- name: "MyCustomFont",
253
- url: "https://example.com/font.otf",
262
+ name: 'MyCustomFont',
263
+ url: 'https://example.com/font.otf',
254
264
  });
255
265
 
256
266
  // you can use global "store" object
@@ -289,11 +299,11 @@ npm install fluent-ffmpeg axios
289
299
  ```
290
300
 
291
301
  ```js
292
- import { createInstance } from "polotno-node";
293
- import { jsonToVideo } from "polotno-node/video-parallel";
302
+ import { createInstance } from 'polotno-node';
303
+ import { jsonToVideo } from 'polotno-node/video-parallel';
294
304
 
295
305
  // load sample json
296
- const json = JSON.parse(fs.readFileSync("./test-data/video.json"));
306
+ const json = JSON.parse(fs.readFileSync('./test-data/video.json'));
297
307
 
298
308
  await jsonToVideo(
299
309
  // first argument is a function that returns an instance
@@ -301,11 +311,11 @@ await jsonToVideo(
301
311
  // or it can be a single instance (useful for cloud functions)
302
312
  () =>
303
313
  createInstance({
304
- key: "...key...",
314
+ key: '...key...',
305
315
  }),
306
316
  json,
307
317
  {
308
- out: "out.mp4", // output file name
318
+ out: 'out.mp4', // output file name
309
319
  parallel: 4, // number of parallel rendering processes
310
320
  fps: 15, // frames per second
311
321
  keepInstance: false, // keep instance open after rendering, make sure to use true if use just one instance
@@ -324,11 +334,11 @@ Pass `url` option to `createInstance` function with public url of your client ed
324
334
  **Note: you will have to maintain the last version of your client editor by yourself. Better to keep using the last **
325
335
 
326
336
  ```js
327
- const { createInstance } = require("polotno-node");
337
+ const { createInstance } = require('polotno-node');
328
338
 
329
339
  const instance = await createInstance({
330
- key: "KEY",
331
- url: "https://yourappdomain.com/client",
340
+ key: 'KEY',
341
+ url: 'https://yourappdomain.com/client',
332
342
  });
333
343
  ```
334
344
 
@@ -353,15 +363,15 @@ You can speed up your function execution a lot, if instead of using full browser
353
363
  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
364
 
355
365
  ```js
356
- const { createInstance } = require("polotno-node/instance");
357
- const puppeteer = require("puppeteer");
366
+ const { createInstance } = require('polotno-node/instance');
367
+ const puppeteer = require('puppeteer');
358
368
 
359
369
  const instance = await createInstance({
360
- key: "nFA5H9elEytDyPyvKL7T",
370
+ key: 'nFA5H9elEytDyPyvKL7T',
361
371
  browser: await puppeteer.connect({
362
- browserWSEndpoint: "wss://chrome.browserless.io?token=API_KEY",
372
+ browserWSEndpoint: 'wss://chrome.browserless.io?token=API_KEY',
363
373
  }),
364
- url: "https://yourappdomain.com/client", // see "Your own client" section
374
+ url: 'https://yourappdomain.com/client', // see "Your own client" section
365
375
  });
366
376
  ```
367
377
 
@@ -374,33 +384,33 @@ npm install @sparticuz/chromium-min
374
384
  ```
375
385
 
376
386
  ```js
377
- const { createInstance } = require("polotno-node/instance");
378
- const chromium = require("@sparticuz/chromium-min");
379
- const puppeteer = require("puppeteer-core");
387
+ const { createInstance } = require('polotno-node/instance');
388
+ const chromium = require('@sparticuz/chromium-min');
389
+ const puppeteer = require('puppeteer-core');
380
390
 
381
391
  const makeInstance = async () => {
382
392
  const browser = await puppeteer.launch({
383
393
  args: [
384
394
  ...chromium.args,
385
- "--no-sandbox",
386
- "--hide-scrollbars",
387
- "--disable-web-security",
388
- "--allow-file-access-from-files",
395
+ '--no-sandbox',
396
+ '--hide-scrollbars',
397
+ '--disable-web-security',
398
+ '--allow-file-access-from-files',
389
399
  // more info about --disable-dev-shm-usage
390
400
  // https://github.com/puppeteer/puppeteer/issues/1175#issuecomment-369728215
391
401
  // https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#tips
392
- "--disable-dev-shm-usage",
402
+ '--disable-dev-shm-usage',
393
403
  ],
394
404
  defaultViewport: chromium.defaultViewport,
395
405
  executablePath: await chromium.executablePath(
396
- "https://github.com/Sparticuz/chromium/releases/download/v110.0.1/chromium-v110.0.1-pack.tar"
406
+ 'https://github.com/Sparticuz/chromium/releases/download/v110.0.1/chromium-v110.0.1-pack.tar'
397
407
  ),
398
408
  headless: chromium.headless,
399
409
  ignoreHTTPSErrors: true,
400
410
  });
401
411
 
402
412
  return await createInstance({
403
- key: "your-key",
413
+ key: 'your-key',
404
414
  browser,
405
415
  });
406
416
  };