polotno-node 2.6.6 → 2.6.8
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/assets/{index-1a4d47fd.js → index-a7c43fcd.js} +53 -53
- package/dist/index.html +1 -1
- package/instance.js +14 -0
- package/package.json +5 -5
- package/video.js +18 -4
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-
|
|
11
|
+
<script type="module" crossorigin src="./assets/index-a7c43fcd.js"></script>
|
|
12
12
|
</head>
|
|
13
13
|
<body>
|
|
14
14
|
<div id="root"></div>
|
package/instance.js
CHANGED
|
@@ -73,6 +73,8 @@ module.exports.jsonToBlob = async (page, json, attrs) => {
|
|
|
73
73
|
);
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
+
const busyPages = [];
|
|
77
|
+
|
|
76
78
|
module.exports.createInstance = async ({
|
|
77
79
|
key,
|
|
78
80
|
url,
|
|
@@ -89,6 +91,14 @@ module.exports.createInstance = async ({
|
|
|
89
91
|
? await module.exports.createPage(browser, visitPage)
|
|
90
92
|
: firstPage;
|
|
91
93
|
|
|
94
|
+
if (busyPages.indexOf(page) >= 0) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
'Current rendering context is busy with another task. Please use `useParallelPages: true` option to run multiple tasks in parallel or make sure previous task is finished before starting a new one.'
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
busyPages.push(page);
|
|
101
|
+
|
|
92
102
|
try {
|
|
93
103
|
if (args[1]?.assetLoadTimeout) {
|
|
94
104
|
await page.evaluate((timeout) => {
|
|
@@ -135,11 +145,15 @@ module.exports.createInstance = async ({
|
|
|
135
145
|
throw new Error(error);
|
|
136
146
|
}
|
|
137
147
|
}
|
|
148
|
+
// remove busy page
|
|
149
|
+
busyPages.splice(busyPages.indexOf(page), 1);
|
|
138
150
|
if (useParallelPages) {
|
|
139
151
|
await page.close();
|
|
140
152
|
}
|
|
141
153
|
return result;
|
|
142
154
|
} catch (e) {
|
|
155
|
+
// remove busy page
|
|
156
|
+
busyPages.splice(busyPages.indexOf(page), 1);
|
|
143
157
|
if (useParallelPages) {
|
|
144
158
|
await page.close();
|
|
145
159
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polotno-node",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.8",
|
|
4
4
|
"description": "Polotno workflow from NodeJS",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,17 +26,17 @@
|
|
|
26
26
|
"gifencoder": "^2.0.1",
|
|
27
27
|
"pixelmatch": "^5.3.0",
|
|
28
28
|
"pngjs": "^7.0.0",
|
|
29
|
-
"polotno": "^2.0.
|
|
29
|
+
"polotno": "^2.0.5",
|
|
30
30
|
"react": "^18.2.0",
|
|
31
31
|
"react-dom": "^18.2.0",
|
|
32
|
-
"vite": "^4.
|
|
32
|
+
"vite": "^4.5.0"
|
|
33
33
|
},
|
|
34
34
|
"author": "Anton Lavrenov",
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@sparticuz/chromium": "117.0.0",
|
|
38
|
-
"puppeteer": "^21.
|
|
39
|
-
"puppeteer-core": "^21.
|
|
38
|
+
"puppeteer": "^21.4.0",
|
|
39
|
+
"puppeteer-core": "^21.4.0"
|
|
40
40
|
},
|
|
41
41
|
"bugs": {
|
|
42
42
|
"url": "https://github.com/polotno-project/polotno-node/issues"
|
package/video.js
CHANGED
|
@@ -63,7 +63,7 @@ const videoToDataURL = async (url) => {
|
|
|
63
63
|
function printProgress(progress) {
|
|
64
64
|
process.stdout.clearLine(0);
|
|
65
65
|
process.stdout.cursorTo(0);
|
|
66
|
-
process.stdout.write(progress + '%');
|
|
66
|
+
process.stdout.write('Rendering frame: ' + progress + '%');
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
module.exports.jsonToVideo = async function jsonToGifFile(page, json, attrs) {
|
|
@@ -85,6 +85,9 @@ module.exports.jsonToVideo = async function jsonToGifFile(page, json, attrs) {
|
|
|
85
85
|
async (json, attrs) => {
|
|
86
86
|
store.loadJSON(json);
|
|
87
87
|
await store.waitLoading();
|
|
88
|
+
// TODO: we need to active all pages first
|
|
89
|
+
// disable text fit, as it is already should be processed
|
|
90
|
+
window.config.unstable_setTextOverflow('resize');
|
|
88
91
|
},
|
|
89
92
|
json,
|
|
90
93
|
attrs || {}
|
|
@@ -100,10 +103,19 @@ module.exports.jsonToVideo = async function jsonToGifFile(page, json, attrs) {
|
|
|
100
103
|
// loop through the images and add each to the animation
|
|
101
104
|
const frames = Math.floor((duration / 1000) * fps);
|
|
102
105
|
for (let i = 0; i < frames; i++) {
|
|
103
|
-
|
|
106
|
+
let currentTime = i * timePerFrame;
|
|
107
|
+
if (i === 0) {
|
|
108
|
+
// offset the very first frame to enable animation start
|
|
109
|
+
currentTime = 1;
|
|
110
|
+
}
|
|
111
|
+
if (i === frames - 1) {
|
|
112
|
+
// offset the very last frame to enable animation end
|
|
113
|
+
currentTime = duration - 1;
|
|
114
|
+
}
|
|
115
|
+
|
|
104
116
|
const dataURL = await page.evaluate(
|
|
105
117
|
async (json, attrs, currentTime) => {
|
|
106
|
-
store.setCurrentTime(currentTime
|
|
118
|
+
store.setCurrentTime(currentTime);
|
|
107
119
|
const currentPage = store.pages.find((p) => {
|
|
108
120
|
return (
|
|
109
121
|
store.currentTime >= p.startTime &&
|
|
@@ -121,12 +133,14 @@ module.exports.jsonToVideo = async function jsonToGifFile(page, json, attrs) {
|
|
|
121
133
|
attrs || {},
|
|
122
134
|
currentTime
|
|
123
135
|
);
|
|
124
|
-
const progress = ((i / frames) * 100).toFixed(1);
|
|
136
|
+
const progress = ((i / (frames - 1)) * 100).toFixed(1);
|
|
125
137
|
printProgress(progress);
|
|
126
138
|
fs.mkdirSync('./tmp', { recursive: true });
|
|
127
139
|
fs.writeFileSync(`./tmp/${i}.png`, dataURL.split(',')[1], 'base64');
|
|
128
140
|
}
|
|
129
141
|
|
|
142
|
+
console.log('\nRendering video');
|
|
143
|
+
|
|
130
144
|
await new Promise((resolve, reject) => {
|
|
131
145
|
ffmpeg()
|
|
132
146
|
.input(`./tmp/%d.png`) // Make sure your images are named with numbers, e.g. 1.jpg, 2.jpg, etc.
|