polotno-node 3.0.0 → 3.0.1
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/LICENSE.md +10 -0
- package/README.md +22 -30
- package/dist/assets/{html2canvas-CfrNTgDn.js → html2canvas-BeKaVBkZ.js} +1 -1
- package/dist/assets/index-DFqP22V0.js +540 -0
- package/dist/assets/{index.es-C7BBG6KT.js → index.es-DwOGAynS.js} +1 -1
- package/dist/assets/{jspdf.es.min-D1g0nHTs.js → jspdf.es.min-BBVOPmzA.js} +4 -4
- package/dist/assets/lib-CuK_SezV.js +65 -0
- package/dist/index.html +1 -1
- package/lib/font-cache.d.ts +3 -0
- package/lib/font-cache.js +99 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +121 -0
- package/lib/instance.d.ts +41 -0
- package/lib/instance.js +740 -0
- package/lib/types.d.ts +76 -0
- package/lib/types.js +1 -0
- package/package.json +36 -20
- package/dist/assets/index-oYy3TsOk.js +0 -464
- package/dist/assets/lib-U0NRl5MI.js +0 -65
- package/font-cache.js +0 -109
- package/index.d.ts +0 -147
- package/index.js +0 -161
- package/instance.js +0 -863
package/index.js
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
let puppeteer = require('puppeteer-core');
|
|
2
|
-
const sparticuz = require('@sparticuz/chromium');
|
|
3
|
-
// TODO: that is a weird hack, but it works
|
|
4
|
-
const chrome = sparticuz.default || sparticuz;
|
|
5
|
-
const os = require('os');
|
|
6
|
-
const isMacOs = os.platform() === 'darwin';
|
|
7
|
-
const isWindows = os.platform() === 'win32' || os.platform() === 'win64';
|
|
8
|
-
|
|
9
|
-
// load full puppeteer on non linux platforms
|
|
10
|
-
if (isMacOs || isWindows) {
|
|
11
|
-
puppeteer = require('puppeteer');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const { createInstance } = require('./instance');
|
|
15
|
-
|
|
16
|
-
const args = [
|
|
17
|
-
'about:blank',
|
|
18
|
-
'--disable-web-security',
|
|
19
|
-
'--allow-file-access-from-files',
|
|
20
|
-
'--allow-pre-commit-input',
|
|
21
|
-
'--autoplay-policy=user-gesture-required',
|
|
22
|
-
'--disable-background-networking',
|
|
23
|
-
'--disable-background-timer-throttling',
|
|
24
|
-
'--disable-backgrounding-occluded-windows',
|
|
25
|
-
'--disable-breakpad',
|
|
26
|
-
'--disable-component-extensions-with-background-pages',
|
|
27
|
-
'--disable-client-side-phishing-detection',
|
|
28
|
-
'--disable-component-update',
|
|
29
|
-
'--disable-default-apps',
|
|
30
|
-
'--disable-dev-shm-usage',
|
|
31
|
-
'--proxy-server=direct://',
|
|
32
|
-
'--proxy-bypass-list=*',
|
|
33
|
-
'--disable-domain-reliability',
|
|
34
|
-
'--disable-features=AudioServiceOutOfProcess,IsolateOrigins,site-per-process,Translate,BackForwardCache,AvoidUnnecessaryBeforeUnloadCheckSync,IntensiveWakeUpThrottling',
|
|
35
|
-
'--disable-extensions',
|
|
36
|
-
'--disable-hang-monitor',
|
|
37
|
-
'--disable-ipc-flooding-protection',
|
|
38
|
-
'--disable-notifications',
|
|
39
|
-
'--disable-offer-store-unmasked-wallet-cards',
|
|
40
|
-
'--disable-popup-blocking',
|
|
41
|
-
'--disable-print-preview',
|
|
42
|
-
'--disable-site-isolation-trials',
|
|
43
|
-
'--disable-prompt-on-repost',
|
|
44
|
-
'--disable-renderer-backgrounding',
|
|
45
|
-
'--disable-setuid-sandbox',
|
|
46
|
-
'--disable-speech-api',
|
|
47
|
-
'--disable-sync',
|
|
48
|
-
// Use srgb for identical output across Linux/macOS/Windows and to match how CSS colors/images are defined/assumed on the web.
|
|
49
|
-
'--force-color-profile=srgb',
|
|
50
|
-
'--hide-scrollbars',
|
|
51
|
-
'--metrics-recording-only',
|
|
52
|
-
'--mute-audio',
|
|
53
|
-
'--no-default-browser-check',
|
|
54
|
-
'--no-first-run',
|
|
55
|
-
'--enable-automation',
|
|
56
|
-
'--no-pings',
|
|
57
|
-
'--no-sandbox',
|
|
58
|
-
'--no-zygote',
|
|
59
|
-
'--password-store=basic',
|
|
60
|
-
'--allow-running-insecure-content',
|
|
61
|
-
|
|
62
|
-
// Disable accessibility features to reduce resource usage and improve performance.
|
|
63
|
-
'--disable-renderer-accessibility',
|
|
64
|
-
// stable locale → font fallback/hyphenation
|
|
65
|
-
'--lang=en-US',
|
|
66
|
-
// this line breaks the rendering on most of OS
|
|
67
|
-
// it doesn't allow creating of pages
|
|
68
|
-
//'--use-gl=swiftshader',
|
|
69
|
-
'--disable-gpu',
|
|
70
|
-
'--use-mock-keychain',
|
|
71
|
-
'--enable-blink-features=IdleDetection',
|
|
72
|
-
'--intensive-wake-up-throttling-policy=0',
|
|
73
|
-
'--font-render-hinting=none',
|
|
74
|
-
'--ignore-gpu-blocklist',
|
|
75
|
-
// don't use this flag, because it makes renderign less accurate
|
|
76
|
-
// see https://community.polotno.com/c/ask/the-ability-to-exclude-args-from-minimal_args-in-polotno-node
|
|
77
|
-
// '--disable-font-subpixel-positioning',
|
|
78
|
-
'--text-rendering=geometricprecision',
|
|
79
|
-
].filter(Boolean);
|
|
80
|
-
|
|
81
|
-
module.exports.args = args;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Merges browser arguments intelligently, handling duplicates and conflicts.
|
|
85
|
-
* Later arguments take precedence over earlier ones.
|
|
86
|
-
* @param {...string[]} argArrays - Arrays of browser arguments to merge
|
|
87
|
-
* @returns {string[]} Merged array of arguments
|
|
88
|
-
*/
|
|
89
|
-
function mergeArgs(...argArrays) {
|
|
90
|
-
const argMap = new Map();
|
|
91
|
-
const warnings = [];
|
|
92
|
-
|
|
93
|
-
for (const argArray of argArrays) {
|
|
94
|
-
for (const arg of argArray) {
|
|
95
|
-
// Extract the flag name (before '=' if present)
|
|
96
|
-
const flagMatch = arg.match(/^(--[^=]+)/);
|
|
97
|
-
const flagName = flagMatch ? flagMatch[1] : arg;
|
|
98
|
-
|
|
99
|
-
if (argMap.has(flagName)) {
|
|
100
|
-
const existingArg = argMap.get(flagName);
|
|
101
|
-
if (existingArg !== arg) {
|
|
102
|
-
warnings.push(
|
|
103
|
-
`Duplicate/conflicting flag detected: "${flagName}". Using: "${arg}" (overriding: "${existingArg}")`
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
argMap.set(flagName, arg);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Log warnings if any duplicates/conflicts were found
|
|
113
|
-
if (warnings.length > 0) {
|
|
114
|
-
// console.warn('Browser arguments merged with conflicts:');
|
|
115
|
-
// warnings.forEach((warning) => console.warn(` - ${warning}`));
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return Array.from(argMap.values());
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const browserProps = {
|
|
122
|
-
headless: 'new',
|
|
123
|
-
// make large timeout, because some renders may take a lot of time
|
|
124
|
-
// like large PDF or video render
|
|
125
|
-
protocolTimeout: 60 * 60 * 1000,
|
|
126
|
-
ignoreHTTPSErrors: true,
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
async function createBrowser({ browserArgs = [], ...rest } = {}) {
|
|
130
|
-
return puppeteer.launch({
|
|
131
|
-
args: mergeArgs(isWindows ? [] : chrome.args, args, browserArgs),
|
|
132
|
-
defaultViewport: chrome.defaultViewport,
|
|
133
|
-
|
|
134
|
-
executablePath:
|
|
135
|
-
isMacOs || isWindows ? undefined : await chrome.executablePath(),
|
|
136
|
-
...browserProps,
|
|
137
|
-
...rest,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
module.exports.createBrowser = createBrowser;
|
|
142
|
-
|
|
143
|
-
module.exports.createInstance = async ({
|
|
144
|
-
key,
|
|
145
|
-
url,
|
|
146
|
-
useParallelPages,
|
|
147
|
-
browserArgs = [],
|
|
148
|
-
browser,
|
|
149
|
-
requestInterceptor,
|
|
150
|
-
useFontCache,
|
|
151
|
-
} = {}) => {
|
|
152
|
-
return await createInstance({
|
|
153
|
-
browser: browser || (await createBrowser({ browserArgs })),
|
|
154
|
-
key,
|
|
155
|
-
url,
|
|
156
|
-
useParallelPages,
|
|
157
|
-
browserArgs,
|
|
158
|
-
requestInterceptor,
|
|
159
|
-
useFontCache,
|
|
160
|
-
});
|
|
161
|
-
};
|