polotno-node 2.7.0 → 2.7.2

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/index.html CHANGED
@@ -8,7 +8,7 @@
8
8
  }
9
9
  </style>
10
10
  <meta name="viewport" content="width=device-width, initial-scale=1" />
11
- <script type="module" crossorigin src="./assets/index-13b6e0f3.js"></script>
11
+ <script type="module" crossorigin src="./assets/index-db239b7c.js"></script>
12
12
  </head>
13
13
  <body>
14
14
  <div id="root"></div>
package/index.js CHANGED
@@ -49,7 +49,7 @@ const minimal_args = [
49
49
  '--use-mock-keychain',
50
50
  ];
51
51
 
52
- const createBrowser = async ({ browserArgs }) => {
52
+ async function createBrowser({ browserArgs = [], ...rest } = {}) {
53
53
  return puppeteer.launch({
54
54
  args: [
55
55
  ...chrome.args,
@@ -69,8 +69,11 @@ const createBrowser = async ({ browserArgs }) => {
69
69
  executablePath:
70
70
  isMacOs || isWindows ? undefined : await chrome.executablePath(),
71
71
  ignoreHTTPSErrors: true,
72
+ ...rest,
72
73
  });
73
- };
74
+ }
75
+
76
+ module.exports.createBrowser = createBrowser;
74
77
 
75
78
  module.exports.createInstance = async ({
76
79
  key,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polotno-node",
3
- "version": "2.7.0",
3
+ "version": "2.7.2",
4
4
  "description": "Polotno workflow from NodeJS",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -27,7 +27,7 @@
27
27
  "gifencoder": "^2.0.1",
28
28
  "pixelmatch": "^5.3.0",
29
29
  "pngjs": "^7.0.0",
30
- "polotno": "^2.0.5",
30
+ "polotno": "^2.1.1",
31
31
  "react": "^18.2.0",
32
32
  "react-dom": "^18.2.0",
33
33
  "vite": "^4.5.0"
@@ -37,7 +37,8 @@
37
37
  "dependencies": {
38
38
  "@sparticuz/chromium": "118.0.0",
39
39
  "puppeteer": "^20.9.0",
40
- "puppeteer-core": "^20.9.0"
40
+ "puppeteer-core": "^20.9.0",
41
+ "tmp": "^0.2.1"
41
42
  },
42
43
  "bugs": {
43
44
  "url": "https://github.com/polotno-project/polotno-node/issues"
package/video-parallel.js CHANGED
@@ -3,6 +3,10 @@ const ffmpeg = require('fluent-ffmpeg');
3
3
  const axios = require('axios');
4
4
  const path = require('path');
5
5
 
6
+ const tmp = require('tmp');
7
+
8
+ tmp.setGracefulCleanup();
9
+
6
10
  const downloadVideo = async (url, destination) => {
7
11
  const response = await axios({
8
12
  method: 'GET',
@@ -51,12 +55,14 @@ const fileToDataUrl = (filename) => {
51
55
  const videoToDataURL = async (url) => {
52
56
  console.log('downloading', url);
53
57
  const filename = Math.random().toString(36).substring(7);
54
- const destination = path.join('./tmp', filename + '.mp4');
58
+ const tempFolder = tmp.dirSync();
59
+ const destination = path.join(tempFolder.name, filename + '.mp4');
55
60
  await downloadVideo(url, destination);
56
61
  const webmFile = destination.replace('.mp4', '.webm');
57
62
  console.log('converting to webm', url);
58
63
  await convertToWebM(destination, webmFile);
59
64
  const dataUrl = await fileToDataUrl(webmFile);
65
+ fs.rmSync(tempFolder.name, { recursive: true });
60
66
  return dataUrl;
61
67
  };
62
68
 
@@ -71,11 +77,7 @@ module.exports.jsonToVideo = async function jsonToVideo(
71
77
  json,
72
78
  attrs
73
79
  ) {
74
- try {
75
- fs.rmSync('./tmp', { recursive: true });
76
- } catch (e) {}
77
-
78
- fs.mkdirSync('./tmp', { recursive: true });
80
+ const tempFolder = tmp.dirSync();
79
81
 
80
82
  for (const page of json.pages) {
81
83
  for (const el of page.children) {
@@ -124,6 +126,10 @@ module.exports.jsonToVideo = async function jsonToVideo(
124
126
  const page = await instance.createPage();
125
127
  await page.evaluate(async (json) => {
126
128
  store.loadJSON(json);
129
+ await store.waitLoading();
130
+ await new Promise((resolve) => {
131
+ setTimeout(resolve, 100);
132
+ });
127
133
  }, json);
128
134
 
129
135
  let lastPageIndex = -1;
@@ -165,7 +171,6 @@ module.exports.jsonToVideo = async function jsonToVideo(
165
171
  );
166
172
  });
167
173
  const url = await store.toDataURL({
168
- pixelRatio: 0.5,
169
174
  ...attrs,
170
175
  pageId: currentPage?.id,
171
176
  });
@@ -175,9 +180,8 @@ module.exports.jsonToVideo = async function jsonToVideo(
175
180
  attrs || {},
176
181
  currentTime
177
182
  );
178
- fs.mkdirSync('./tmp', { recursive: true });
179
183
  fs.writeFileSync(
180
- `./tmp/${frameIndex}.png`,
184
+ `${tempFolder.name}/${frameIndex}.png`,
181
185
  dataURL.split(',')[1],
182
186
  'base64'
183
187
  );
@@ -236,19 +240,19 @@ module.exports.jsonToVideo = async function jsonToVideo(
236
240
  // fs.writeFileSync(`./tmp/${i}.png`, dataURL.split(',')[1], 'base64');
237
241
  // }
238
242
 
239
- console.log('\nRendering video');
243
+ const format = attrs.out.split('.').pop() || 'mp4';
240
244
 
241
245
  await new Promise((resolve, reject) => {
242
246
  ffmpeg()
243
- .input(`./tmp/%d.png`) // Make sure your images are named with numbers, e.g. 1.jpg, 2.jpg, etc.
247
+ .input(`${tempFolder.name}/%d.png`) // Make sure your images are named with numbers, e.g. 1.jpg, 2.jpg, etc.
244
248
  .inputFPS(fps)
245
- .videoCodec('libx264')
246
- .outputOptions('-pix_fmt yuv420p')
247
- .format('mp4')
249
+ // .videoCodec('libx265')
250
+ .outputOptions('-pix_fmt yuva420p')
251
+ .format(format)
248
252
  .on('end', () => resolve())
249
253
  .on('error', (err) => reject(err))
250
254
  .save(attrs.out);
251
255
  });
252
256
 
253
- fs.rmSync('./tmp', { recursive: true });
257
+ fs.rmSync(tempFolder.name, { recursive: true });
254
258
  };