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/README.md CHANGED
@@ -37,6 +37,33 @@ run();
37
37
 
38
38
  ## API
39
39
 
40
+ ### `createInstance(options)`
41
+
42
+ Create working instance of Polotno Node.
43
+
44
+ ```js
45
+ const { createInstance } = require('polotno-node');
46
+ const instance = await createInstance({
47
+ // this is a demo key just for that project
48
+ // (!) please don't use it in your projects
49
+ // to create your own API key please go here: https://polotno.dev/cabinet
50
+ key: 'nFA5H9elEytDyPyvKL7T',
51
+ // useParallelPages - use parallel pages to speed up rendering
52
+ // you can use false only for sequential calls
53
+ // it may break rendering if you call many parallel requests
54
+ // default is true
55
+ useParallelPages: false,
56
+ // url - url of the Polotno Client Editor
57
+ // client editor is just simple public html page that have `store` as global variable
58
+ // by default it will run local build
59
+ url: 'https://yourappdomain.com/client',
60
+ // browser - puppeteer browser instance
61
+ // by default it will use chrome-aws-lambda
62
+ // useful to set your own rendering props or use browserless
63
+ browser: browser,
64
+ });
65
+ ```
66
+
40
67
  ### `instance.jsonToDataURL(json, attrs)`
41
68
 
42
69
  Export json into data URL.
@@ -50,7 +77,10 @@ res.json({ url });
50
77
 
51
78
  // export many pages:
52
79
  for (const page of json.pages) {
53
- const url = await instance.jsonToDataURL(json, { pageId: page.id });
80
+ const url = await instance.jsonToDataURL(
81
+ { ...json, pages: [page] }, // for optimization, we can modify JSON to include only one page
82
+ { pageId: page.id }
83
+ );
54
84
  // do something with url
55
85
  }
56
86
  ```
@@ -70,9 +100,10 @@ fs.writeFileSync('out.png', imageBase64, 'base64');
70
100
 
71
101
  // export many pages:
72
102
  for (const page of json.pages) {
73
- const imageBase64 = await instance.jsonToImageBase64(json, {
74
- pageId: page.id,
75
- });
103
+ const imageBase64 = await instance.jsonToImageBase64(
104
+ { ...json, pages: [page] }, // for optimization, we can modify JSON to include only one page
105
+ { pageId: page.id }
106
+ );
76
107
  // do something with base64
77
108
  }
78
109
  ```