@lvce-editor/renderer-process 30.40.0 → 30.41.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/dist/rendererProcessMain.js +1195 -1161
- package/package.json +1 -1
|
@@ -118,25 +118,25 @@ const confirm = message => {
|
|
|
118
118
|
return window.confirm(message);
|
|
119
119
|
};
|
|
120
120
|
|
|
121
|
-
const state$
|
|
121
|
+
const state$f = {
|
|
122
122
|
styleSheets: Object.create(null),
|
|
123
123
|
texts: Object.create(null)
|
|
124
124
|
};
|
|
125
125
|
const set$b = (id, sheet) => {
|
|
126
|
-
state$
|
|
126
|
+
state$f.styleSheets[id] = sheet;
|
|
127
127
|
};
|
|
128
128
|
const get$b = id => {
|
|
129
|
-
return state$
|
|
129
|
+
return state$f.styleSheets[id];
|
|
130
130
|
};
|
|
131
131
|
const setText$2 = (id, text) => {
|
|
132
|
-
state$
|
|
132
|
+
state$f.texts[id] = text;
|
|
133
133
|
};
|
|
134
134
|
const getText = id => {
|
|
135
|
-
return state$
|
|
135
|
+
return state$f.texts[id];
|
|
136
136
|
};
|
|
137
137
|
const remove$5 = id => {
|
|
138
|
-
delete state$
|
|
139
|
-
delete state$
|
|
138
|
+
delete state$f.styleSheets[id];
|
|
139
|
+
delete state$f.texts[id];
|
|
140
140
|
};
|
|
141
141
|
|
|
142
142
|
const addCssStyleSheet = (id, text) => {
|
|
@@ -331,7 +331,7 @@ const createIdGenerator = () => {
|
|
|
331
331
|
};
|
|
332
332
|
const create$J = createIdGenerator();
|
|
333
333
|
|
|
334
|
-
const state$
|
|
334
|
+
const state$e = Object.create(null);
|
|
335
335
|
const retainString = (item, index) => {
|
|
336
336
|
const value = new Promise(resolve => {
|
|
337
337
|
item.getAsString(resolve);
|
|
@@ -382,22 +382,22 @@ const retainItems = dataTransfer => {
|
|
|
382
382
|
};
|
|
383
383
|
const add$2 = dataTransfer => {
|
|
384
384
|
const id = create$J();
|
|
385
|
-
state$
|
|
385
|
+
state$e[id] = retainItems(dataTransfer);
|
|
386
386
|
return id;
|
|
387
387
|
};
|
|
388
388
|
const acquire$2 = id => {
|
|
389
|
-
const items = state$
|
|
389
|
+
const items = state$e[id];
|
|
390
390
|
if (!items) {
|
|
391
391
|
throw new Error(`Drop data not found: ${id}`);
|
|
392
392
|
}
|
|
393
|
-
delete state$
|
|
393
|
+
delete state$e[id];
|
|
394
394
|
return items;
|
|
395
395
|
};
|
|
396
396
|
|
|
397
|
-
const state$
|
|
397
|
+
const state$d = Object.create(null);
|
|
398
398
|
const acquire$1 = id => {
|
|
399
|
-
const promise = state$
|
|
400
|
-
delete state$
|
|
399
|
+
const promise = state$d[id];
|
|
400
|
+
delete state$d[id];
|
|
401
401
|
return promise;
|
|
402
402
|
};
|
|
403
403
|
const getFileHandles$1 = async ids => {
|
|
@@ -407,7 +407,7 @@ const getFileHandles$1 = async ids => {
|
|
|
407
407
|
};
|
|
408
408
|
const add$1 = promise => {
|
|
409
409
|
const id = create$J();
|
|
410
|
-
state$
|
|
410
|
+
state$d[id] = promise;
|
|
411
411
|
return id;
|
|
412
412
|
};
|
|
413
413
|
const addFileHandle$1 = fileHandle => {
|
|
@@ -609,14 +609,14 @@ const getEventListenerArgs = (params, event) => {
|
|
|
609
609
|
return serialized;
|
|
610
610
|
};
|
|
611
611
|
|
|
612
|
-
const state$
|
|
612
|
+
const state$c = {
|
|
613
613
|
ipc: undefined
|
|
614
614
|
};
|
|
615
615
|
const getIpc = () => {
|
|
616
|
-
return state$
|
|
616
|
+
return state$c.ipc;
|
|
617
617
|
};
|
|
618
618
|
const setIpc = value => {
|
|
619
|
-
state$
|
|
619
|
+
state$c.ipc = value;
|
|
620
620
|
};
|
|
621
621
|
|
|
622
622
|
const nameAnonymousFunction$1 = (fn, name) => {
|
|
@@ -2039,815 +2039,413 @@ const unregisterView = uid => {
|
|
|
2039
2039
|
viewRpcIds.delete(uid);
|
|
2040
2040
|
};
|
|
2041
2041
|
|
|
2042
|
-
const
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
a.download = fileName;
|
|
2046
|
-
a.click();
|
|
2047
|
-
};
|
|
2042
|
+
const Web = 1;
|
|
2043
|
+
const Electron$1 = 2;
|
|
2044
|
+
const Remote = 3;
|
|
2048
2045
|
|
|
2049
|
-
|
|
2050
|
-
|
|
2046
|
+
/**
|
|
2047
|
+
* @returns {number}
|
|
2048
|
+
*/
|
|
2049
|
+
const getPlatform = () => {
|
|
2050
|
+
// @ts-expect-error
|
|
2051
|
+
if (typeof PLATFORM !== 'undefined') {
|
|
2052
|
+
// @ts-expect-error
|
|
2053
|
+
return PLATFORM;
|
|
2054
|
+
}
|
|
2055
|
+
// @ts-ignore
|
|
2056
|
+
if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') {
|
|
2057
|
+
return Remote;
|
|
2058
|
+
}
|
|
2059
|
+
if (globalThis.isElectron) {
|
|
2060
|
+
return Electron$1;
|
|
2061
|
+
}
|
|
2062
|
+
if (typeof location !== 'undefined' && location.search === '?web') {
|
|
2063
|
+
return Web;
|
|
2064
|
+
}
|
|
2065
|
+
return Remote;
|
|
2051
2066
|
};
|
|
2067
|
+
const platform = getPlatform();
|
|
2052
2068
|
|
|
2053
|
-
const
|
|
2054
|
-
|
|
2055
|
-
|
|
2069
|
+
const getAssetDir = () => {
|
|
2070
|
+
// @ts-expect-error
|
|
2071
|
+
if (typeof ASSET_DIR !== 'undefined') {
|
|
2072
|
+
// @ts-expect-error
|
|
2073
|
+
return ASSET_DIR;
|
|
2056
2074
|
}
|
|
2057
|
-
if (
|
|
2058
|
-
|
|
2075
|
+
if (platform === Electron$1) {
|
|
2076
|
+
return '../../../../..';
|
|
2059
2077
|
}
|
|
2060
|
-
|
|
2061
|
-
return filePath;
|
|
2078
|
+
return '';
|
|
2062
2079
|
};
|
|
2080
|
+
const assetDir = getAssetDir();
|
|
2063
2081
|
|
|
2064
|
-
const
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
throw new TypeError('Invalid drop data options');
|
|
2082
|
+
const getConfiguredWorkerUrl = key => {
|
|
2083
|
+
if (typeof location === 'undefined' || typeof document === 'undefined') {
|
|
2084
|
+
return '';
|
|
2068
2085
|
}
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
}
|
|
2086
|
+
const configElement = document.getElementById('Config');
|
|
2087
|
+
if (!configElement) {
|
|
2088
|
+
return '';
|
|
2073
2089
|
}
|
|
2090
|
+
const text = configElement.textContent;
|
|
2091
|
+
if (!text) {
|
|
2092
|
+
return '';
|
|
2093
|
+
}
|
|
2094
|
+
const config = JSON.parse(text);
|
|
2095
|
+
return config[key] || '';
|
|
2074
2096
|
};
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
type: item.type,
|
|
2080
|
-
value: await item.value
|
|
2081
|
-
};
|
|
2097
|
+
|
|
2098
|
+
const getConfiguredDragAndDropWorkerUrl = () => {
|
|
2099
|
+
const workerUrls = getConfiguredWorkerUrl('workerUrls');
|
|
2100
|
+
return workerUrls?.['develop.dragAndDropWorkerPath'] || '';
|
|
2082
2101
|
};
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
return undefined;
|
|
2102
|
+
|
|
2103
|
+
const dragAndDropWorkerUrl = getConfiguredDragAndDropWorkerUrl() || `${assetDir}/packages/renderer-worker/node_modules/@lvce-editor/drag-and-drop-worker/dist/dragAndDropWorkerMain.js`;
|
|
2104
|
+
|
|
2105
|
+
const normalizeLine = line => {
|
|
2106
|
+
if (line.startsWith('Error: ')) {
|
|
2107
|
+
return line.slice('Error: '.length);
|
|
2090
2108
|
}
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
electronFilePath
|
|
2094
|
-
}),
|
|
2095
|
-
...(includeFile && item.file && {
|
|
2096
|
-
file: item.file
|
|
2097
|
-
}),
|
|
2098
|
-
...(fileSystemHandle && {
|
|
2099
|
-
fileSystemHandle
|
|
2100
|
-
}),
|
|
2101
|
-
index: item.index,
|
|
2102
|
-
kind: 'file',
|
|
2103
|
-
name: fileSystemHandle?.name || item.file?.name || '',
|
|
2104
|
-
type: item.type
|
|
2105
|
-
};
|
|
2106
|
-
};
|
|
2107
|
-
const get$6 = async (dropId, options) => {
|
|
2108
|
-
validateOptions(options);
|
|
2109
|
-
const retainedItems = acquire$2(dropId);
|
|
2110
|
-
const formats = new Set(options.formats);
|
|
2111
|
-
const items = [];
|
|
2112
|
-
for (const retainedItem of retainedItems) {
|
|
2113
|
-
if (retainedItem.kind === 'string') {
|
|
2114
|
-
if (formats.has('string')) {
|
|
2115
|
-
items.push(await resolveString(retainedItem));
|
|
2116
|
-
}
|
|
2117
|
-
continue;
|
|
2118
|
-
}
|
|
2119
|
-
const item = await resolveFile(retainedItem, formats, options.includeElectronFilePaths);
|
|
2120
|
-
if (item) {
|
|
2121
|
-
items.push(item);
|
|
2122
|
-
}
|
|
2109
|
+
if (line.startsWith('VError: ')) {
|
|
2110
|
+
return line.slice('VError: '.length);
|
|
2123
2111
|
}
|
|
2124
|
-
return
|
|
2112
|
+
return line;
|
|
2125
2113
|
};
|
|
2126
|
-
|
|
2127
|
-
const
|
|
2128
|
-
if (
|
|
2129
|
-
return
|
|
2114
|
+
const getCombinedMessage = (error, message) => {
|
|
2115
|
+
const stringifiedError = normalizeLine(`${error}`);
|
|
2116
|
+
if (message) {
|
|
2117
|
+
return `${message}: ${stringifiedError}`;
|
|
2130
2118
|
}
|
|
2131
|
-
|
|
2132
|
-
return candidate.kind === 'file' && typeof candidate.getFile === 'function';
|
|
2119
|
+
return stringifiedError;
|
|
2133
2120
|
};
|
|
2134
|
-
const
|
|
2135
|
-
|
|
2136
|
-
|
|
2121
|
+
const NewLine$3 = '\n';
|
|
2122
|
+
const getNewLineIndex$1 = (string, startIndex = undefined) => {
|
|
2123
|
+
return string.indexOf(NewLine$3, startIndex);
|
|
2124
|
+
};
|
|
2125
|
+
const mergeStacks$1 = (parent, child) => {
|
|
2126
|
+
if (!child) {
|
|
2127
|
+
return parent;
|
|
2137
2128
|
}
|
|
2138
|
-
|
|
2139
|
-
|
|
2129
|
+
const parentNewLineIndex = getNewLineIndex$1(parent);
|
|
2130
|
+
const childNewLineIndex = getNewLineIndex$1(child);
|
|
2131
|
+
if (childNewLineIndex === -1) {
|
|
2132
|
+
return parent;
|
|
2140
2133
|
}
|
|
2141
|
-
|
|
2142
|
-
|
|
2134
|
+
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
|
2135
|
+
const childRest = child.slice(childNewLineIndex);
|
|
2136
|
+
const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
|
|
2137
|
+
if (parentFirstLine.includes(childFirstLine)) {
|
|
2138
|
+
return parentFirstLine + childRest;
|
|
2143
2139
|
}
|
|
2144
|
-
return
|
|
2140
|
+
return child;
|
|
2145
2141
|
};
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2142
|
+
let VError$1 = class VError extends Error {
|
|
2143
|
+
constructor(error, message) {
|
|
2144
|
+
const combinedMessage = getCombinedMessage(error, message);
|
|
2145
|
+
super(combinedMessage);
|
|
2146
|
+
this.name = 'VError';
|
|
2147
|
+
if (error instanceof Error) {
|
|
2148
|
+
this.stack = mergeStacks$1(this.stack, error.stack);
|
|
2149
|
+
}
|
|
2150
|
+
if (error.codeFrame) {
|
|
2151
|
+
// @ts-ignore
|
|
2152
|
+
this.codeFrame = error.codeFrame;
|
|
2153
|
+
}
|
|
2154
|
+
if (error.code) {
|
|
2155
|
+
// @ts-ignore
|
|
2156
|
+
this.code = error.code;
|
|
2157
|
+
}
|
|
2153
2158
|
}
|
|
2154
|
-
const path = await getFilePathElectron(file);
|
|
2155
|
-
return {
|
|
2156
|
-
...item,
|
|
2157
|
-
path
|
|
2158
|
-
};
|
|
2159
|
-
};
|
|
2160
|
-
const get$5 = async ids => {
|
|
2161
|
-
const items = await getFileHandles$1(ids);
|
|
2162
|
-
return Promise.all(items.map(addElectronPath));
|
|
2163
2159
|
};
|
|
2164
2160
|
|
|
2165
|
-
const
|
|
2166
|
-
|
|
2167
|
-
return window.showDirectoryPicker(options);
|
|
2168
|
-
};
|
|
2169
|
-
const showFilePicker = options => {
|
|
2170
|
-
// @ts-expect-error
|
|
2171
|
-
return window.showOpenFilePicker(options);
|
|
2161
|
+
const isMessagePort$1 = value => {
|
|
2162
|
+
return value && value instanceof MessagePort;
|
|
2172
2163
|
};
|
|
2173
|
-
const
|
|
2174
|
-
|
|
2175
|
-
return window.showSaveFilePicker(options);
|
|
2164
|
+
const isMessagePortMain = value => {
|
|
2165
|
+
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
2176
2166
|
};
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
return handle.requestPermission(options);
|
|
2167
|
+
const isOffscreenCanvas = value => {
|
|
2168
|
+
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
2180
2169
|
};
|
|
2181
|
-
const
|
|
2182
|
-
return
|
|
2170
|
+
const isInstanceOf = (value, constructorName) => {
|
|
2171
|
+
return value?.constructor?.name === constructorName;
|
|
2183
2172
|
};
|
|
2184
|
-
const
|
|
2185
|
-
return
|
|
2173
|
+
const isSocket = value => {
|
|
2174
|
+
return isInstanceOf(value, 'Socket');
|
|
2186
2175
|
};
|
|
2187
|
-
|
|
2188
|
-
const
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
const titleBarRect = globalThis.navigator.windowControlsOverlay.getTitlebarAreaRect();
|
|
2194
|
-
return titleBarRect.height;
|
|
2176
|
+
const transferrables$1 = [isMessagePort$1, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
2177
|
+
const isTransferrable$1 = value => {
|
|
2178
|
+
for (const fn of transferrables$1) {
|
|
2179
|
+
if (fn(value)) {
|
|
2180
|
+
return true;
|
|
2181
|
+
}
|
|
2195
2182
|
}
|
|
2196
|
-
return
|
|
2197
|
-
};
|
|
2198
|
-
const getBounds = () => {
|
|
2199
|
-
return {
|
|
2200
|
-
titleBarHeight: getTitleBarHeight(),
|
|
2201
|
-
windowHeight: window.innerHeight,
|
|
2202
|
-
windowWidth: window.innerWidth
|
|
2203
|
-
};
|
|
2204
|
-
};
|
|
2205
|
-
|
|
2206
|
-
const getPathName = () => {
|
|
2207
|
-
return location.pathname;
|
|
2208
|
-
};
|
|
2209
|
-
const getHref = () => {
|
|
2210
|
-
return location.href;
|
|
2211
|
-
};
|
|
2212
|
-
const matchesPathName = (currentPathName, pathName) => {
|
|
2213
|
-
const resolvedPathName = new URL(pathName, getHref()).pathname;
|
|
2214
|
-
return currentPathName === resolvedPathName;
|
|
2183
|
+
return false;
|
|
2215
2184
|
};
|
|
2216
|
-
const
|
|
2217
|
-
|
|
2218
|
-
if (matchesPathName(currentPathName, pathName)) {
|
|
2185
|
+
const walkValue$1 = (value, transferrables, isTransferrable) => {
|
|
2186
|
+
if (!value) {
|
|
2219
2187
|
return;
|
|
2220
2188
|
}
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
// addEventListener('popstate', handlePopState)
|
|
2225
|
-
};
|
|
2226
|
-
|
|
2227
|
-
const shouldLaunchMultipleWorkers = true;
|
|
2228
|
-
|
|
2229
|
-
const getConfig = () => {
|
|
2230
|
-
const configElement = document.getElementById('Config');
|
|
2231
|
-
if (!configElement?.textContent) {
|
|
2232
|
-
return {};
|
|
2189
|
+
if (isTransferrable(value)) {
|
|
2190
|
+
transferrables.push(value);
|
|
2191
|
+
return;
|
|
2233
2192
|
}
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
const initData = {
|
|
2238
|
-
Config: {
|
|
2239
|
-
...getConfig(),
|
|
2240
|
-
shouldLaunchMultipleWorkers: shouldLaunchMultipleWorkers
|
|
2241
|
-
},
|
|
2242
|
-
Layout: {
|
|
2243
|
-
bounds: getBounds()
|
|
2244
|
-
},
|
|
2245
|
-
Location: {
|
|
2246
|
-
href: getHref()
|
|
2247
|
-
}
|
|
2248
|
-
};
|
|
2249
|
-
return initData;
|
|
2250
|
-
};
|
|
2251
|
-
|
|
2252
|
-
const MessagePort$1 = 1;
|
|
2253
|
-
const ModuleWorker = 2;
|
|
2254
|
-
const ReferencePort = 3;
|
|
2255
|
-
const ModuleWorkerWithMessagePort = 4;
|
|
2256
|
-
const Electron$1 = 5;
|
|
2257
|
-
|
|
2258
|
-
const Message$2 = 'message';
|
|
2259
|
-
const Error$3 = 'error';
|
|
2260
|
-
|
|
2261
|
-
const withResolvers = () => {
|
|
2262
|
-
return Promise.withResolvers();
|
|
2263
|
-
};
|
|
2264
|
-
|
|
2265
|
-
const getFirstEvent$1 = (eventTarget, eventMap) => {
|
|
2266
|
-
const {
|
|
2267
|
-
promise,
|
|
2268
|
-
resolve
|
|
2269
|
-
} = withResolvers();
|
|
2270
|
-
const listenerMap = Object.create(null);
|
|
2271
|
-
const cleanup = value => {
|
|
2272
|
-
for (const event of Object.keys(eventMap)) {
|
|
2273
|
-
eventTarget.removeEventListener(event, listenerMap[event]);
|
|
2193
|
+
if (Array.isArray(value)) {
|
|
2194
|
+
for (const item of value) {
|
|
2195
|
+
walkValue$1(item, transferrables, isTransferrable);
|
|
2274
2196
|
}
|
|
2275
|
-
|
|
2276
|
-
};
|
|
2277
|
-
for (const [event, type] of Object.entries(eventMap)) {
|
|
2278
|
-
const listener = event => {
|
|
2279
|
-
cleanup({
|
|
2280
|
-
event,
|
|
2281
|
-
type
|
|
2282
|
-
});
|
|
2283
|
-
};
|
|
2284
|
-
eventTarget.addEventListener(event, listener);
|
|
2285
|
-
listenerMap[event] = listener;
|
|
2197
|
+
return;
|
|
2286
2198
|
}
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
/**
|
|
2291
|
-
*
|
|
2292
|
-
* @param {Worker} worker
|
|
2293
|
-
* @returns
|
|
2294
|
-
*/
|
|
2295
|
-
const getFirstWorkerEvent$1 = worker => {
|
|
2296
|
-
return getFirstEvent$1(worker, {
|
|
2297
|
-
error: Error$3,
|
|
2298
|
-
message: Message$2
|
|
2299
|
-
});
|
|
2300
|
-
};
|
|
2301
|
-
|
|
2302
|
-
const transferrables$1 = [];
|
|
2303
|
-
if (typeof MessagePort !== 'undefined') {
|
|
2304
|
-
transferrables$1.push(MessagePort);
|
|
2305
|
-
}
|
|
2306
|
-
if (typeof OffscreenCanvas !== 'undefined') {
|
|
2307
|
-
transferrables$1.push(OffscreenCanvas);
|
|
2308
|
-
}
|
|
2309
|
-
|
|
2310
|
-
const isTransferrable$1 = value => {
|
|
2311
|
-
for (const fn of transferrables$1) {
|
|
2312
|
-
if (value instanceof fn) {
|
|
2313
|
-
return true;
|
|
2199
|
+
if (typeof value === 'object') {
|
|
2200
|
+
for (const property of Object.values(value)) {
|
|
2201
|
+
walkValue$1(property, transferrables, isTransferrable);
|
|
2314
2202
|
}
|
|
2315
2203
|
}
|
|
2316
|
-
return false;
|
|
2317
2204
|
};
|
|
2318
|
-
|
|
2319
|
-
const
|
|
2205
|
+
const getTransferrables = value => {
|
|
2206
|
+
const transferrables = [];
|
|
2207
|
+
walkValue$1(value, transferrables, isTransferrable$1);
|
|
2208
|
+
return transferrables;
|
|
2209
|
+
};
|
|
2210
|
+
const removeValues = (value, toRemove) => {
|
|
2320
2211
|
if (!value) {
|
|
2321
|
-
return;
|
|
2322
|
-
}
|
|
2323
|
-
if (isTransferrable$1(value)) {
|
|
2324
|
-
transferrables.push(value);
|
|
2212
|
+
return value;
|
|
2325
2213
|
}
|
|
2326
2214
|
if (Array.isArray(value)) {
|
|
2215
|
+
const newItems = [];
|
|
2327
2216
|
for (const item of value) {
|
|
2328
|
-
|
|
2217
|
+
if (!toRemove.includes(item)) {
|
|
2218
|
+
newItems.push(removeValues(item, toRemove));
|
|
2219
|
+
}
|
|
2329
2220
|
}
|
|
2330
|
-
return;
|
|
2221
|
+
return newItems;
|
|
2331
2222
|
}
|
|
2332
2223
|
if (typeof value === 'object') {
|
|
2333
|
-
|
|
2334
|
-
|
|
2224
|
+
const newObject = Object.create(null);
|
|
2225
|
+
for (const [key, property] of Object.entries(value)) {
|
|
2226
|
+
if (!toRemove.includes(property)) {
|
|
2227
|
+
newObject[key] = removeValues(property, toRemove);
|
|
2228
|
+
}
|
|
2335
2229
|
}
|
|
2230
|
+
return newObject;
|
|
2336
2231
|
}
|
|
2232
|
+
return value;
|
|
2337
2233
|
};
|
|
2338
2234
|
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2235
|
+
// workaround for electron not supporting transferrable objects
|
|
2236
|
+
// as parameters. If the transferrable object is a parameter, in electron
|
|
2237
|
+
// only an empty objected is received in the main process
|
|
2238
|
+
const fixElectronParameters = value => {
|
|
2239
|
+
const transfer = getTransferrables(value);
|
|
2240
|
+
const newValue = removeValues(value, transfer);
|
|
2241
|
+
return {
|
|
2242
|
+
newValue,
|
|
2243
|
+
transfer
|
|
2244
|
+
};
|
|
2343
2245
|
};
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2246
|
+
const attachEvents$8 = that => {
|
|
2247
|
+
const handleMessage = (...args) => {
|
|
2248
|
+
const data = that.getData(...args);
|
|
2249
|
+
that.dispatchEvent(new MessageEvent('message', {
|
|
2250
|
+
data
|
|
2251
|
+
}));
|
|
2252
|
+
};
|
|
2253
|
+
that.onMessage(handleMessage);
|
|
2254
|
+
const handleClose = event => {
|
|
2255
|
+
that.dispatchEvent(new Event('close'));
|
|
2256
|
+
};
|
|
2257
|
+
that.onClose(handleClose);
|
|
2258
|
+
};
|
|
2259
|
+
class Ipc extends EventTarget {
|
|
2260
|
+
constructor(rawIpc) {
|
|
2261
|
+
super();
|
|
2262
|
+
this._rawIpc = rawIpc;
|
|
2263
|
+
attachEvents$8(this);
|
|
2349
2264
|
}
|
|
2265
|
+
}
|
|
2266
|
+
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
2267
|
+
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
2268
|
+
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
|
2269
|
+
const NewLine$2 = '\n';
|
|
2270
|
+
const joinLines$2 = lines => {
|
|
2271
|
+
return lines.join(NewLine$2);
|
|
2350
2272
|
};
|
|
2351
|
-
|
|
2352
|
-
const
|
|
2353
|
-
|
|
2273
|
+
const RE_AT$1 = /^\s+at/;
|
|
2274
|
+
const RE_AT_PROMISE_INDEX$1 = /^\s*at async Promise.all \(index \d+\)$/;
|
|
2275
|
+
const isNormalStackLine$1 = line => {
|
|
2276
|
+
return RE_AT$1.test(line) && !RE_AT_PROMISE_INDEX$1.test(line);
|
|
2354
2277
|
};
|
|
2355
|
-
|
|
2356
|
-
const
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2278
|
+
const getDetails$1 = lines => {
|
|
2279
|
+
const index = lines.findIndex(isNormalStackLine$1);
|
|
2280
|
+
if (index === -1) {
|
|
2281
|
+
return {
|
|
2282
|
+
actualMessage: joinLines$2(lines),
|
|
2283
|
+
rest: []
|
|
2284
|
+
};
|
|
2285
|
+
}
|
|
2286
|
+
let lastIndex = index - 1;
|
|
2287
|
+
while (++lastIndex < lines.length) {
|
|
2288
|
+
if (!isNormalStackLine$1(lines[lastIndex])) {
|
|
2289
|
+
break;
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
return {
|
|
2293
|
+
actualMessage: lines[index - 1],
|
|
2294
|
+
rest: lines.slice(index, lastIndex)
|
|
2295
|
+
};
|
|
2360
2296
|
};
|
|
2361
|
-
|
|
2362
2297
|
const splitLines$2 = lines => {
|
|
2363
|
-
|
|
2364
|
-
return lines.split(NewLine$3);
|
|
2298
|
+
return lines.split(NewLine$2);
|
|
2365
2299
|
};
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
const stackLines = splitLines$2(this.stack);
|
|
2371
|
-
const relevantLines = stackLines.slice(1);
|
|
2372
|
-
const relevant = joinLines$2(relevantLines);
|
|
2373
|
-
this.stack = `${event.message}
|
|
2374
|
-
at Module (${event.filename}:${event.lineno}:${event.colno})
|
|
2375
|
-
${relevant}`;
|
|
2376
|
-
}
|
|
2300
|
+
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
|
|
2301
|
+
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
|
|
2302
|
+
const isMessageCodeBlockStartIndex = line => {
|
|
2303
|
+
return RE_MESSAGE_CODE_BLOCK_START.test(line);
|
|
2377
2304
|
};
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
const getWorkerDisplayName$1 = name => {
|
|
2382
|
-
if (name && name.endsWith('Worker')) {
|
|
2383
|
-
return name;
|
|
2384
|
-
}
|
|
2385
|
-
return `${name} worker`;
|
|
2305
|
+
const isMessageCodeBlockEndIndex = line => {
|
|
2306
|
+
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
|
2386
2307
|
};
|
|
2387
|
-
const
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
const
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
});
|
|
2395
|
-
// @ts-expect-error
|
|
2396
|
-
const {
|
|
2397
|
-
event,
|
|
2398
|
-
type
|
|
2399
|
-
} = await getFirstWorkerEvent$1(worker);
|
|
2400
|
-
switch (type) {
|
|
2401
|
-
case Message$2:
|
|
2402
|
-
if (event.data !== 'ready') {
|
|
2403
|
-
throw new IpcError$1('unexpected first message from worker');
|
|
2404
|
-
}
|
|
2405
|
-
break;
|
|
2406
|
-
case Error$3:
|
|
2407
|
-
if (isErrorEvent$1(event)) {
|
|
2408
|
-
throw new WorkerError$1(event);
|
|
2409
|
-
}
|
|
2410
|
-
const displayName = getWorkerDisplayName$1(name);
|
|
2411
|
-
throw new IpcError$1(`Failed to start ${displayName}`);
|
|
2412
|
-
}
|
|
2413
|
-
return worker;
|
|
2308
|
+
const getMessageCodeBlock = stderr => {
|
|
2309
|
+
const lines = splitLines$2(stderr);
|
|
2310
|
+
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
|
|
2311
|
+
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
|
2312
|
+
const relevantLines = lines.slice(startIndex, endIndex);
|
|
2313
|
+
const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
|
|
2314
|
+
return relevantMessage;
|
|
2414
2315
|
};
|
|
2415
|
-
const
|
|
2416
|
-
|
|
2417
|
-
if (event instanceof MessageEvent) {
|
|
2418
|
-
return event.data;
|
|
2419
|
-
}
|
|
2420
|
-
return event;
|
|
2316
|
+
const isModuleNotFoundMessage = line => {
|
|
2317
|
+
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
2421
2318
|
};
|
|
2422
|
-
const
|
|
2423
|
-
|
|
2424
|
-
const
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
if (listener) {
|
|
2430
|
-
handleMessage = event => {
|
|
2431
|
-
const data = getData$1(event);
|
|
2432
|
-
listener({
|
|
2433
|
-
data,
|
|
2434
|
-
target: wrapped
|
|
2435
|
-
});
|
|
2436
|
-
};
|
|
2437
|
-
} else {
|
|
2438
|
-
handleMessage = null;
|
|
2439
|
-
}
|
|
2440
|
-
worker.onmessage = handleMessage;
|
|
2441
|
-
},
|
|
2442
|
-
send(message) {
|
|
2443
|
-
worker.postMessage(message);
|
|
2444
|
-
},
|
|
2445
|
-
sendAndTransfer(message) {
|
|
2446
|
-
const transfer = getTransfer(message);
|
|
2447
|
-
worker.postMessage(message, transfer);
|
|
2448
|
-
}
|
|
2319
|
+
const getModuleNotFoundError = stderr => {
|
|
2320
|
+
const lines = splitLines$2(stderr);
|
|
2321
|
+
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
2322
|
+
const message = lines[messageIndex];
|
|
2323
|
+
return {
|
|
2324
|
+
code: ERR_MODULE_NOT_FOUND,
|
|
2325
|
+
message
|
|
2449
2326
|
};
|
|
2450
|
-
return wrapped;
|
|
2451
|
-
};
|
|
2452
|
-
|
|
2453
|
-
const IpcParentWithModuleWorker$2 = {
|
|
2454
|
-
__proto__: null,
|
|
2455
|
-
create: create$I,
|
|
2456
|
-
wrap
|
|
2457
|
-
};
|
|
2458
|
-
|
|
2459
|
-
const isMessagePort$1 = value => {
|
|
2460
|
-
return value instanceof MessagePort;
|
|
2461
2327
|
};
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
}) => {
|
|
2466
|
-
string(url);
|
|
2467
|
-
const portPromise = await new Promise(resolve => {
|
|
2468
|
-
Object.defineProperty(globalThis, 'acceptPort', {
|
|
2469
|
-
configurable: true,
|
|
2470
|
-
value: resolve
|
|
2471
|
-
});
|
|
2472
|
-
});
|
|
2473
|
-
await import(url);
|
|
2474
|
-
const port = await portPromise;
|
|
2475
|
-
delete globalThis.acceptPort;
|
|
2476
|
-
if (!port) {
|
|
2477
|
-
throw new IpcError$1('port must be defined');
|
|
2478
|
-
}
|
|
2479
|
-
if (!isMessagePort$1(port)) {
|
|
2480
|
-
throw new IpcError$1('port must be of type MessagePort');
|
|
2328
|
+
const isModuleNotFoundError = stderr => {
|
|
2329
|
+
if (!stderr) {
|
|
2330
|
+
return false;
|
|
2481
2331
|
}
|
|
2482
|
-
return
|
|
2483
|
-
};
|
|
2484
|
-
|
|
2485
|
-
const IpcParentWithMessagePort$2 = {
|
|
2486
|
-
__proto__: null,
|
|
2487
|
-
create: create$H
|
|
2488
|
-
};
|
|
2489
|
-
|
|
2490
|
-
const create$G = async url => {
|
|
2491
|
-
const referencePort = await new Promise(resolve => {
|
|
2492
|
-
Object.defineProperty(globalThis, 'acceptReferencePort', {
|
|
2493
|
-
configurable: true,
|
|
2494
|
-
value: resolve
|
|
2495
|
-
});
|
|
2496
|
-
import(url);
|
|
2497
|
-
});
|
|
2498
|
-
delete globalThis.acceptReferencePort;
|
|
2499
|
-
return referencePort;
|
|
2500
|
-
};
|
|
2501
|
-
|
|
2502
|
-
const IpcParentWithReferencePort = {
|
|
2503
|
-
__proto__: null,
|
|
2504
|
-
create: create$G
|
|
2332
|
+
return stderr.includes('ERR_MODULE_NOT_FOUND');
|
|
2505
2333
|
};
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
return line.slice('Error: '.length);
|
|
2510
|
-
}
|
|
2511
|
-
if (line.startsWith('VError: ')) {
|
|
2512
|
-
return line.slice('VError: '.length);
|
|
2334
|
+
const isModulesSyntaxError = stderr => {
|
|
2335
|
+
if (!stderr) {
|
|
2336
|
+
return false;
|
|
2513
2337
|
}
|
|
2514
|
-
return
|
|
2338
|
+
return stderr.includes('SyntaxError: Cannot use import statement outside a module');
|
|
2515
2339
|
};
|
|
2516
|
-
const
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
}
|
|
2521
|
-
return stringifiedError;
|
|
2340
|
+
const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
|
|
2341
|
+
const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
|
|
2342
|
+
const isUnhelpfulNativeModuleError = stderr => {
|
|
2343
|
+
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
|
|
2522
2344
|
};
|
|
2523
|
-
const
|
|
2524
|
-
const
|
|
2525
|
-
return
|
|
2345
|
+
const getNativeModuleErrorMessage = stderr => {
|
|
2346
|
+
const message = getMessageCodeBlock(stderr);
|
|
2347
|
+
return {
|
|
2348
|
+
code: E_INCOMPATIBLE_NATIVE_MODULE,
|
|
2349
|
+
message: `Incompatible native node module: ${message}`
|
|
2350
|
+
};
|
|
2526
2351
|
};
|
|
2527
|
-
const
|
|
2528
|
-
|
|
2529
|
-
|
|
2352
|
+
const getModuleSyntaxError = () => {
|
|
2353
|
+
return {
|
|
2354
|
+
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
|
|
2355
|
+
message: `ES Modules are not supported in electron`
|
|
2356
|
+
};
|
|
2357
|
+
};
|
|
2358
|
+
const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
2359
|
+
if (isUnhelpfulNativeModuleError(stderr)) {
|
|
2360
|
+
return getNativeModuleErrorMessage(stderr);
|
|
2530
2361
|
}
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
if (childNewLineIndex === -1) {
|
|
2534
|
-
return parent;
|
|
2362
|
+
if (isModulesSyntaxError(stderr)) {
|
|
2363
|
+
return getModuleSyntaxError();
|
|
2535
2364
|
}
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
|
|
2539
|
-
if (parentFirstLine.includes(childFirstLine)) {
|
|
2540
|
-
return parentFirstLine + childRest;
|
|
2365
|
+
if (isModuleNotFoundError(stderr)) {
|
|
2366
|
+
return getModuleNotFoundError(stderr);
|
|
2541
2367
|
}
|
|
2542
|
-
|
|
2368
|
+
const lines = splitLines$2(stderr);
|
|
2369
|
+
const {
|
|
2370
|
+
actualMessage,
|
|
2371
|
+
rest
|
|
2372
|
+
} = getDetails$1(lines);
|
|
2373
|
+
return {
|
|
2374
|
+
code: '',
|
|
2375
|
+
message: actualMessage,
|
|
2376
|
+
stack: rest
|
|
2377
|
+
};
|
|
2543
2378
|
};
|
|
2544
|
-
let
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
this.name = 'VError';
|
|
2549
|
-
if (error instanceof Error) {
|
|
2550
|
-
this.stack = mergeStacks$1(this.stack, error.stack);
|
|
2551
|
-
}
|
|
2552
|
-
if (error.codeFrame) {
|
|
2379
|
+
let IpcError$1 = class IpcError extends VError$1 {
|
|
2380
|
+
// @ts-ignore
|
|
2381
|
+
constructor(betterMessage, stdout = '', stderr = '') {
|
|
2382
|
+
if (stdout || stderr) {
|
|
2553
2383
|
// @ts-ignore
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2384
|
+
const {
|
|
2385
|
+
code,
|
|
2386
|
+
message,
|
|
2387
|
+
stack
|
|
2388
|
+
} = getHelpfulChildProcessError(stdout, stderr);
|
|
2389
|
+
const cause = new Error(message);
|
|
2557
2390
|
// @ts-ignore
|
|
2558
|
-
|
|
2391
|
+
cause.code = code;
|
|
2392
|
+
if (stack) {
|
|
2393
|
+
Object.defineProperty(cause, 'stack', {
|
|
2394
|
+
configurable: true,
|
|
2395
|
+
enumerable: false,
|
|
2396
|
+
value: stack,
|
|
2397
|
+
writable: true
|
|
2398
|
+
});
|
|
2399
|
+
}
|
|
2400
|
+
super(cause, betterMessage);
|
|
2401
|
+
} else {
|
|
2402
|
+
super(betterMessage);
|
|
2559
2403
|
}
|
|
2404
|
+
// @ts-ignore
|
|
2405
|
+
this.name = 'IpcError';
|
|
2406
|
+
// @ts-ignore
|
|
2407
|
+
this.stdout = stdout;
|
|
2408
|
+
// @ts-ignore
|
|
2409
|
+
this.stderr = stderr;
|
|
2560
2410
|
}
|
|
2561
2411
|
};
|
|
2562
|
-
|
|
2563
|
-
const
|
|
2564
|
-
return
|
|
2565
|
-
};
|
|
2566
|
-
const isMessagePortMain = value => {
|
|
2567
|
-
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
2568
|
-
};
|
|
2569
|
-
const isOffscreenCanvas = value => {
|
|
2570
|
-
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
2571
|
-
};
|
|
2572
|
-
const isInstanceOf = (value, constructorName) => {
|
|
2573
|
-
return value?.constructor?.name === constructorName;
|
|
2412
|
+
const readyMessage = 'ready';
|
|
2413
|
+
const getData$2 = event => {
|
|
2414
|
+
return event.data;
|
|
2574
2415
|
};
|
|
2575
|
-
const
|
|
2576
|
-
return
|
|
2416
|
+
const listen$9 = () => {
|
|
2417
|
+
return globalThis;
|
|
2577
2418
|
};
|
|
2578
|
-
const
|
|
2579
|
-
|
|
2580
|
-
for (const fn of transferrables) {
|
|
2581
|
-
if (fn(value)) {
|
|
2582
|
-
return true;
|
|
2583
|
-
}
|
|
2584
|
-
}
|
|
2585
|
-
return false;
|
|
2419
|
+
const signal$a = global => {
|
|
2420
|
+
global.postMessage(readyMessage);
|
|
2586
2421
|
};
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
return;
|
|
2422
|
+
class IpcChildWithElectronWindow extends Ipc {
|
|
2423
|
+
getData(event) {
|
|
2424
|
+
return getData$2(event);
|
|
2590
2425
|
}
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
return;
|
|
2426
|
+
send(message) {
|
|
2427
|
+
this._rawIpc.postMessage(message);
|
|
2594
2428
|
}
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2429
|
+
sendAndTransfer(message) {
|
|
2430
|
+
const {
|
|
2431
|
+
newValue,
|
|
2432
|
+
transfer
|
|
2433
|
+
} = fixElectronParameters(message);
|
|
2434
|
+
this._rawIpc.postMessage(newValue, location.origin, transfer);
|
|
2600
2435
|
}
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
walkValue(property, transferrables, isTransferrable);
|
|
2604
|
-
}
|
|
2436
|
+
dispose() {
|
|
2437
|
+
// ignore
|
|
2605
2438
|
}
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
const transferrables = [];
|
|
2609
|
-
walkValue(value, transferrables, isTransferrable);
|
|
2610
|
-
return transferrables;
|
|
2611
|
-
};
|
|
2612
|
-
const removeValues = (value, toRemove) => {
|
|
2613
|
-
if (!value) {
|
|
2614
|
-
return value;
|
|
2439
|
+
onClose(callback) {
|
|
2440
|
+
// ignore
|
|
2615
2441
|
}
|
|
2616
|
-
|
|
2617
|
-
const
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
return newItems;
|
|
2624
|
-
}
|
|
2625
|
-
if (typeof value === 'object') {
|
|
2626
|
-
const newObject = Object.create(null);
|
|
2627
|
-
for (const [key, property] of Object.entries(value)) {
|
|
2628
|
-
if (!toRemove.includes(property)) {
|
|
2629
|
-
newObject[key] = removeValues(property, toRemove);
|
|
2630
|
-
}
|
|
2631
|
-
}
|
|
2632
|
-
return newObject;
|
|
2633
|
-
}
|
|
2634
|
-
return value;
|
|
2635
|
-
};
|
|
2636
|
-
|
|
2637
|
-
// workaround for electron not supporting transferrable objects
|
|
2638
|
-
// as parameters. If the transferrable object is a parameter, in electron
|
|
2639
|
-
// only an empty objected is received in the main process
|
|
2640
|
-
const fixElectronParameters = value => {
|
|
2641
|
-
const transfer = getTransferrables(value);
|
|
2642
|
-
const newValue = removeValues(value, transfer);
|
|
2643
|
-
return {
|
|
2644
|
-
newValue,
|
|
2645
|
-
transfer
|
|
2646
|
-
};
|
|
2647
|
-
};
|
|
2648
|
-
const attachEvents$8 = that => {
|
|
2649
|
-
const handleMessage = (...args) => {
|
|
2650
|
-
const data = that.getData(...args);
|
|
2651
|
-
that.dispatchEvent(new MessageEvent('message', {
|
|
2652
|
-
data
|
|
2653
|
-
}));
|
|
2654
|
-
};
|
|
2655
|
-
that.onMessage(handleMessage);
|
|
2656
|
-
const handleClose = event => {
|
|
2657
|
-
that.dispatchEvent(new Event('close'));
|
|
2658
|
-
};
|
|
2659
|
-
that.onClose(handleClose);
|
|
2660
|
-
};
|
|
2661
|
-
class Ipc extends EventTarget {
|
|
2662
|
-
constructor(rawIpc) {
|
|
2663
|
-
super();
|
|
2664
|
-
this._rawIpc = rawIpc;
|
|
2665
|
-
attachEvents$8(this);
|
|
2666
|
-
}
|
|
2667
|
-
}
|
|
2668
|
-
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
2669
|
-
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
2670
|
-
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
|
2671
|
-
const NewLine$1 = '\n';
|
|
2672
|
-
const joinLines$1 = lines => {
|
|
2673
|
-
return lines.join(NewLine$1);
|
|
2674
|
-
};
|
|
2675
|
-
const RE_AT$1 = /^\s+at/;
|
|
2676
|
-
const RE_AT_PROMISE_INDEX$1 = /^\s*at async Promise.all \(index \d+\)$/;
|
|
2677
|
-
const isNormalStackLine$1 = line => {
|
|
2678
|
-
return RE_AT$1.test(line) && !RE_AT_PROMISE_INDEX$1.test(line);
|
|
2679
|
-
};
|
|
2680
|
-
const getDetails$1 = lines => {
|
|
2681
|
-
const index = lines.findIndex(isNormalStackLine$1);
|
|
2682
|
-
if (index === -1) {
|
|
2683
|
-
return {
|
|
2684
|
-
actualMessage: joinLines$1(lines),
|
|
2685
|
-
rest: []
|
|
2686
|
-
};
|
|
2687
|
-
}
|
|
2688
|
-
let lastIndex = index - 1;
|
|
2689
|
-
while (++lastIndex < lines.length) {
|
|
2690
|
-
if (!isNormalStackLine$1(lines[lastIndex])) {
|
|
2691
|
-
break;
|
|
2692
|
-
}
|
|
2693
|
-
}
|
|
2694
|
-
return {
|
|
2695
|
-
actualMessage: lines[index - 1],
|
|
2696
|
-
rest: lines.slice(index, lastIndex)
|
|
2697
|
-
};
|
|
2698
|
-
};
|
|
2699
|
-
const splitLines$1 = lines => {
|
|
2700
|
-
return lines.split(NewLine$1);
|
|
2701
|
-
};
|
|
2702
|
-
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
|
|
2703
|
-
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
|
|
2704
|
-
const isMessageCodeBlockStartIndex = line => {
|
|
2705
|
-
return RE_MESSAGE_CODE_BLOCK_START.test(line);
|
|
2706
|
-
};
|
|
2707
|
-
const isMessageCodeBlockEndIndex = line => {
|
|
2708
|
-
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
|
2709
|
-
};
|
|
2710
|
-
const getMessageCodeBlock = stderr => {
|
|
2711
|
-
const lines = splitLines$1(stderr);
|
|
2712
|
-
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
|
|
2713
|
-
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
|
2714
|
-
const relevantLines = lines.slice(startIndex, endIndex);
|
|
2715
|
-
const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
|
|
2716
|
-
return relevantMessage;
|
|
2717
|
-
};
|
|
2718
|
-
const isModuleNotFoundMessage = line => {
|
|
2719
|
-
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
2720
|
-
};
|
|
2721
|
-
const getModuleNotFoundError = stderr => {
|
|
2722
|
-
const lines = splitLines$1(stderr);
|
|
2723
|
-
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
2724
|
-
const message = lines[messageIndex];
|
|
2725
|
-
return {
|
|
2726
|
-
code: ERR_MODULE_NOT_FOUND,
|
|
2727
|
-
message
|
|
2728
|
-
};
|
|
2729
|
-
};
|
|
2730
|
-
const isModuleNotFoundError = stderr => {
|
|
2731
|
-
if (!stderr) {
|
|
2732
|
-
return false;
|
|
2733
|
-
}
|
|
2734
|
-
return stderr.includes('ERR_MODULE_NOT_FOUND');
|
|
2735
|
-
};
|
|
2736
|
-
const isModulesSyntaxError = stderr => {
|
|
2737
|
-
if (!stderr) {
|
|
2738
|
-
return false;
|
|
2739
|
-
}
|
|
2740
|
-
return stderr.includes('SyntaxError: Cannot use import statement outside a module');
|
|
2741
|
-
};
|
|
2742
|
-
const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
|
|
2743
|
-
const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
|
|
2744
|
-
const isUnhelpfulNativeModuleError = stderr => {
|
|
2745
|
-
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
|
|
2746
|
-
};
|
|
2747
|
-
const getNativeModuleErrorMessage = stderr => {
|
|
2748
|
-
const message = getMessageCodeBlock(stderr);
|
|
2749
|
-
return {
|
|
2750
|
-
code: E_INCOMPATIBLE_NATIVE_MODULE,
|
|
2751
|
-
message: `Incompatible native node module: ${message}`
|
|
2752
|
-
};
|
|
2753
|
-
};
|
|
2754
|
-
const getModuleSyntaxError = () => {
|
|
2755
|
-
return {
|
|
2756
|
-
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
|
|
2757
|
-
message: `ES Modules are not supported in electron`
|
|
2758
|
-
};
|
|
2759
|
-
};
|
|
2760
|
-
const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
2761
|
-
if (isUnhelpfulNativeModuleError(stderr)) {
|
|
2762
|
-
return getNativeModuleErrorMessage(stderr);
|
|
2763
|
-
}
|
|
2764
|
-
if (isModulesSyntaxError(stderr)) {
|
|
2765
|
-
return getModuleSyntaxError();
|
|
2766
|
-
}
|
|
2767
|
-
if (isModuleNotFoundError(stderr)) {
|
|
2768
|
-
return getModuleNotFoundError(stderr);
|
|
2769
|
-
}
|
|
2770
|
-
const lines = splitLines$1(stderr);
|
|
2771
|
-
const {
|
|
2772
|
-
actualMessage,
|
|
2773
|
-
rest
|
|
2774
|
-
} = getDetails$1(lines);
|
|
2775
|
-
return {
|
|
2776
|
-
code: '',
|
|
2777
|
-
message: actualMessage,
|
|
2778
|
-
stack: rest
|
|
2779
|
-
};
|
|
2780
|
-
};
|
|
2781
|
-
class IpcError extends VError$1 {
|
|
2782
|
-
// @ts-ignore
|
|
2783
|
-
constructor(betterMessage, stdout = '', stderr = '') {
|
|
2784
|
-
if (stdout || stderr) {
|
|
2785
|
-
// @ts-ignore
|
|
2786
|
-
const {
|
|
2787
|
-
code,
|
|
2788
|
-
message,
|
|
2789
|
-
stack
|
|
2790
|
-
} = getHelpfulChildProcessError(stdout, stderr);
|
|
2791
|
-
const cause = new Error(message);
|
|
2792
|
-
// @ts-ignore
|
|
2793
|
-
cause.code = code;
|
|
2794
|
-
if (stack) {
|
|
2795
|
-
Object.defineProperty(cause, 'stack', {
|
|
2796
|
-
configurable: true,
|
|
2797
|
-
enumerable: false,
|
|
2798
|
-
value: stack,
|
|
2799
|
-
writable: true
|
|
2800
|
-
});
|
|
2801
|
-
}
|
|
2802
|
-
super(cause, betterMessage);
|
|
2803
|
-
} else {
|
|
2804
|
-
super(betterMessage);
|
|
2805
|
-
}
|
|
2806
|
-
// @ts-ignore
|
|
2807
|
-
this.name = 'IpcError';
|
|
2808
|
-
// @ts-ignore
|
|
2809
|
-
this.stdout = stdout;
|
|
2810
|
-
// @ts-ignore
|
|
2811
|
-
this.stderr = stderr;
|
|
2812
|
-
}
|
|
2813
|
-
}
|
|
2814
|
-
const readyMessage = 'ready';
|
|
2815
|
-
const getData$2 = event => {
|
|
2816
|
-
return event.data;
|
|
2817
|
-
};
|
|
2818
|
-
const listen$9 = () => {
|
|
2819
|
-
return globalThis;
|
|
2820
|
-
};
|
|
2821
|
-
const signal$a = global => {
|
|
2822
|
-
global.postMessage(readyMessage);
|
|
2823
|
-
};
|
|
2824
|
-
class IpcChildWithElectronWindow extends Ipc {
|
|
2825
|
-
getData(event) {
|
|
2826
|
-
return getData$2(event);
|
|
2827
|
-
}
|
|
2828
|
-
send(message) {
|
|
2829
|
-
this._rawIpc.postMessage(message);
|
|
2830
|
-
}
|
|
2831
|
-
sendAndTransfer(message) {
|
|
2832
|
-
const {
|
|
2833
|
-
newValue,
|
|
2834
|
-
transfer
|
|
2835
|
-
} = fixElectronParameters(message);
|
|
2836
|
-
this._rawIpc.postMessage(newValue, location.origin, transfer);
|
|
2837
|
-
}
|
|
2838
|
-
dispose() {
|
|
2839
|
-
// ignore
|
|
2840
|
-
}
|
|
2841
|
-
onClose(callback) {
|
|
2842
|
-
// ignore
|
|
2843
|
-
}
|
|
2844
|
-
onMessage(callback) {
|
|
2845
|
-
const wrapped = event => {
|
|
2846
|
-
const {
|
|
2847
|
-
ports
|
|
2848
|
-
} = event;
|
|
2849
|
-
if (ports.length > 0) {
|
|
2850
|
-
return;
|
|
2442
|
+
onMessage(callback) {
|
|
2443
|
+
const wrapped = event => {
|
|
2444
|
+
const {
|
|
2445
|
+
ports
|
|
2446
|
+
} = event;
|
|
2447
|
+
if (ports.length > 0) {
|
|
2448
|
+
return;
|
|
2851
2449
|
}
|
|
2852
2450
|
callback(event);
|
|
2853
2451
|
this._rawIpc.removeEventListener('message', wrapped);
|
|
@@ -2878,7 +2476,7 @@ const removeListener = (emitter, type, callback) => {
|
|
|
2878
2476
|
emitter.off(type, callback);
|
|
2879
2477
|
}
|
|
2880
2478
|
};
|
|
2881
|
-
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
2479
|
+
const getFirstEvent$1 = (eventEmitter, eventMap) => {
|
|
2882
2480
|
const {
|
|
2883
2481
|
promise,
|
|
2884
2482
|
resolve
|
|
@@ -2907,13 +2505,13 @@ const create$5$1 = async ({
|
|
|
2907
2505
|
isMessagePortOpen,
|
|
2908
2506
|
messagePort
|
|
2909
2507
|
}) => {
|
|
2910
|
-
if (!isMessagePort(messagePort)) {
|
|
2911
|
-
throw new IpcError('port must be of type MessagePort');
|
|
2508
|
+
if (!isMessagePort$1(messagePort)) {
|
|
2509
|
+
throw new IpcError$1('port must be of type MessagePort');
|
|
2912
2510
|
}
|
|
2913
2511
|
if (isMessagePortOpen) {
|
|
2914
2512
|
return messagePort;
|
|
2915
2513
|
}
|
|
2916
|
-
const eventPromise = getFirstEvent(messagePort, {
|
|
2514
|
+
const eventPromise = getFirstEvent$1(messagePort, {
|
|
2917
2515
|
message: Message$1
|
|
2918
2516
|
});
|
|
2919
2517
|
messagePort.start();
|
|
@@ -2922,17 +2520,17 @@ const create$5$1 = async ({
|
|
|
2922
2520
|
type
|
|
2923
2521
|
} = await eventPromise;
|
|
2924
2522
|
if (type !== Message$1) {
|
|
2925
|
-
throw new IpcError('Failed to wait for ipc message');
|
|
2523
|
+
throw new IpcError$1('Failed to wait for ipc message');
|
|
2926
2524
|
}
|
|
2927
2525
|
if (event.data !== readyMessage) {
|
|
2928
|
-
throw new IpcError('unexpected first message');
|
|
2526
|
+
throw new IpcError$1('unexpected first message');
|
|
2929
2527
|
}
|
|
2930
2528
|
return messagePort;
|
|
2931
2529
|
};
|
|
2932
2530
|
const signal$1 = messagePort => {
|
|
2933
2531
|
messagePort.start();
|
|
2934
2532
|
};
|
|
2935
|
-
class IpcParentWithMessagePort extends Ipc {
|
|
2533
|
+
let IpcParentWithMessagePort$1 = class IpcParentWithMessagePort extends Ipc {
|
|
2936
2534
|
getData = getData$2;
|
|
2937
2535
|
send(message) {
|
|
2938
2536
|
this._rawIpc.postMessage(message);
|
|
@@ -2948,28 +2546,28 @@ class IpcParentWithMessagePort extends Ipc {
|
|
|
2948
2546
|
this._rawIpc.addEventListener('message', callback);
|
|
2949
2547
|
}
|
|
2950
2548
|
onClose(callback) {}
|
|
2951
|
-
}
|
|
2549
|
+
};
|
|
2952
2550
|
const wrap$5 = messagePort => {
|
|
2953
|
-
return new IpcParentWithMessagePort(messagePort);
|
|
2551
|
+
return new IpcParentWithMessagePort$1(messagePort);
|
|
2954
2552
|
};
|
|
2955
|
-
const IpcParentWithMessagePort$1 = {
|
|
2553
|
+
const IpcParentWithMessagePort$1$1 = {
|
|
2956
2554
|
__proto__: null,
|
|
2957
2555
|
create: create$5$1,
|
|
2958
2556
|
signal: signal$1,
|
|
2959
2557
|
wrap: wrap$5
|
|
2960
2558
|
};
|
|
2961
|
-
const Message = 'message';
|
|
2559
|
+
const Message$2 = 'message';
|
|
2962
2560
|
const Error$1$1 = 'error';
|
|
2963
|
-
const getFirstWorkerEvent = worker => {
|
|
2964
|
-
return getFirstEvent(worker, {
|
|
2561
|
+
const getFirstWorkerEvent$1 = worker => {
|
|
2562
|
+
return getFirstEvent$1(worker, {
|
|
2965
2563
|
error: Error$1$1,
|
|
2966
|
-
message: Message
|
|
2564
|
+
message: Message$2
|
|
2967
2565
|
});
|
|
2968
2566
|
};
|
|
2969
|
-
const isErrorEvent = event => {
|
|
2567
|
+
const isErrorEvent$1 = event => {
|
|
2970
2568
|
return event instanceof ErrorEvent;
|
|
2971
2569
|
};
|
|
2972
|
-
const getWorkerDisplayName = name => {
|
|
2570
|
+
const getWorkerDisplayName$1 = name => {
|
|
2973
2571
|
if (!name) {
|
|
2974
2572
|
return '<unknown> worker';
|
|
2975
2573
|
}
|
|
@@ -2981,42 +2579,42 @@ const getWorkerDisplayName = name => {
|
|
|
2981
2579
|
const tryToGetActualErrorMessage = async ({
|
|
2982
2580
|
name
|
|
2983
2581
|
}) => {
|
|
2984
|
-
const displayName = getWorkerDisplayName(name);
|
|
2582
|
+
const displayName = getWorkerDisplayName$1(name);
|
|
2985
2583
|
return `Failed to start ${displayName}: Worker Launch Error`;
|
|
2986
2584
|
};
|
|
2987
|
-
class WorkerError extends Error {
|
|
2585
|
+
let WorkerError$1 = class WorkerError extends Error {
|
|
2988
2586
|
constructor(event) {
|
|
2989
2587
|
super(event.message);
|
|
2990
|
-
const stackLines = splitLines$
|
|
2588
|
+
const stackLines = splitLines$2(this.stack || '');
|
|
2991
2589
|
const relevantLines = stackLines.slice(1);
|
|
2992
|
-
const relevant = joinLines$
|
|
2590
|
+
const relevant = joinLines$2(relevantLines);
|
|
2993
2591
|
this.stack = `${event.message}
|
|
2994
2592
|
at Module (${event.filename}:${event.lineno}:${event.colno})
|
|
2995
2593
|
${relevant}`;
|
|
2996
2594
|
}
|
|
2997
|
-
}
|
|
2998
|
-
const Module = 'module';
|
|
2595
|
+
};
|
|
2596
|
+
const Module$1 = 'module';
|
|
2999
2597
|
const create$4$1 = async ({
|
|
3000
2598
|
name,
|
|
3001
2599
|
url
|
|
3002
2600
|
}) => {
|
|
3003
2601
|
const worker = new Worker(url, {
|
|
3004
2602
|
name,
|
|
3005
|
-
type: Module
|
|
2603
|
+
type: Module$1
|
|
3006
2604
|
});
|
|
3007
2605
|
const {
|
|
3008
2606
|
event,
|
|
3009
2607
|
type
|
|
3010
|
-
} = await getFirstWorkerEvent(worker);
|
|
2608
|
+
} = await getFirstWorkerEvent$1(worker);
|
|
3011
2609
|
switch (type) {
|
|
3012
|
-
case Message:
|
|
2610
|
+
case Message$2:
|
|
3013
2611
|
if (event.data !== readyMessage) {
|
|
3014
|
-
throw new IpcError('unexpected first message from worker');
|
|
2612
|
+
throw new IpcError$1('unexpected first message from worker');
|
|
3015
2613
|
}
|
|
3016
2614
|
break;
|
|
3017
2615
|
case Error$1$1:
|
|
3018
|
-
if (isErrorEvent(event)) {
|
|
3019
|
-
throw new WorkerError(event);
|
|
2616
|
+
if (isErrorEvent$1(event)) {
|
|
2617
|
+
throw new WorkerError$1(event);
|
|
3020
2618
|
}
|
|
3021
2619
|
const actualErrorMessage = await tryToGetActualErrorMessage({
|
|
3022
2620
|
name
|
|
@@ -3025,16 +2623,16 @@ const create$4$1 = async ({
|
|
|
3025
2623
|
}
|
|
3026
2624
|
return worker;
|
|
3027
2625
|
};
|
|
3028
|
-
const getData = event => {
|
|
2626
|
+
const getData$1 = event => {
|
|
3029
2627
|
// TODO why are some events not instance of message event?
|
|
3030
2628
|
if (event instanceof MessageEvent) {
|
|
3031
2629
|
return event.data;
|
|
3032
2630
|
}
|
|
3033
2631
|
return event;
|
|
3034
2632
|
};
|
|
3035
|
-
class IpcParentWithModuleWorker extends Ipc {
|
|
2633
|
+
let IpcParentWithModuleWorker$1 = class IpcParentWithModuleWorker extends Ipc {
|
|
3036
2634
|
getData(event) {
|
|
3037
|
-
return getData(event);
|
|
2635
|
+
return getData$1(event);
|
|
3038
2636
|
}
|
|
3039
2637
|
send(message) {
|
|
3040
2638
|
this._rawIpc.postMessage(message);
|
|
@@ -3052,11 +2650,11 @@ class IpcParentWithModuleWorker extends Ipc {
|
|
|
3052
2650
|
onMessage(callback) {
|
|
3053
2651
|
this._rawIpc.addEventListener('message', callback);
|
|
3054
2652
|
}
|
|
3055
|
-
}
|
|
2653
|
+
};
|
|
3056
2654
|
const wrap$4 = worker => {
|
|
3057
|
-
return new IpcParentWithModuleWorker(worker);
|
|
2655
|
+
return new IpcParentWithModuleWorker$1(worker);
|
|
3058
2656
|
};
|
|
3059
|
-
const IpcParentWithModuleWorker$1 = {
|
|
2657
|
+
const IpcParentWithModuleWorker$1$1 = {
|
|
3060
2658
|
__proto__: null,
|
|
3061
2659
|
create: create$4$1,
|
|
3062
2660
|
wrap: wrap$4
|
|
@@ -3085,7 +2683,7 @@ const execute = (command, ...args) => {
|
|
|
3085
2683
|
|
|
3086
2684
|
const Two$1 = '2.0';
|
|
3087
2685
|
const callbacks = Object.create(null);
|
|
3088
|
-
const get$
|
|
2686
|
+
const get$6 = id => {
|
|
3089
2687
|
return callbacks[id];
|
|
3090
2688
|
};
|
|
3091
2689
|
const remove$4 = id => {
|
|
@@ -3097,7 +2695,7 @@ class JsonRpcError extends Error {
|
|
|
3097
2695
|
this.name = 'JsonRpcError';
|
|
3098
2696
|
}
|
|
3099
2697
|
}
|
|
3100
|
-
const NewLine = '\n';
|
|
2698
|
+
const NewLine$1 = '\n';
|
|
3101
2699
|
const DomException = 'DOMException';
|
|
3102
2700
|
const ReferenceError$1 = 'ReferenceError';
|
|
3103
2701
|
const SyntaxError$1 = 'SyntaxError';
|
|
@@ -3145,26 +2743,26 @@ const constructError = (message, type, name) => {
|
|
|
3145
2743
|
}
|
|
3146
2744
|
return new ErrorConstructor(message);
|
|
3147
2745
|
};
|
|
3148
|
-
const joinLines = lines => {
|
|
3149
|
-
return lines.join(NewLine);
|
|
2746
|
+
const joinLines$1 = lines => {
|
|
2747
|
+
return lines.join(NewLine$1);
|
|
3150
2748
|
};
|
|
3151
|
-
const splitLines = lines => {
|
|
3152
|
-
return lines.split(NewLine);
|
|
2749
|
+
const splitLines$1 = lines => {
|
|
2750
|
+
return lines.split(NewLine$1);
|
|
3153
2751
|
};
|
|
3154
2752
|
const getCurrentStack = () => {
|
|
3155
2753
|
const stackLinesToSkip = 3;
|
|
3156
|
-
const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
|
|
2754
|
+
const currentStack = joinLines$1(splitLines$1(new Error().stack || '').slice(stackLinesToSkip));
|
|
3157
2755
|
return currentStack;
|
|
3158
2756
|
};
|
|
3159
2757
|
const getNewLineIndex = (string, startIndex) => {
|
|
3160
2758
|
{
|
|
3161
|
-
return string.indexOf(NewLine);
|
|
2759
|
+
return string.indexOf(NewLine$1);
|
|
3162
2760
|
}
|
|
3163
2761
|
};
|
|
3164
2762
|
const getParentStack = error => {
|
|
3165
2763
|
let parentStack = error.stack || error.data || error.message || '';
|
|
3166
2764
|
if (parentStack.startsWith(' at')) {
|
|
3167
|
-
parentStack = error.message + NewLine + parentStack;
|
|
2765
|
+
parentStack = error.message + NewLine$1 + parentStack;
|
|
3168
2766
|
}
|
|
3169
2767
|
return parentStack;
|
|
3170
2768
|
};
|
|
@@ -3189,19 +2787,19 @@ const setStack = (error, stack) => {
|
|
|
3189
2787
|
};
|
|
3190
2788
|
const restoreExistingError = (error, currentStack) => {
|
|
3191
2789
|
if (typeof error.stack === 'string') {
|
|
3192
|
-
setStack(error, `${error.stack}${NewLine}${currentStack}`);
|
|
2790
|
+
setStack(error, `${error.stack}${NewLine$1}${currentStack}`);
|
|
3193
2791
|
}
|
|
3194
2792
|
return error;
|
|
3195
2793
|
};
|
|
3196
2794
|
const restoreMethodNotFoundError = (error, currentStack) => {
|
|
3197
2795
|
const restoredError = new JsonRpcError(error.message);
|
|
3198
2796
|
const parentStack = getParentStack(error);
|
|
3199
|
-
setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
|
|
2797
|
+
setStack(restoredError, `${parentStack}${NewLine$1}${currentStack}`);
|
|
3200
2798
|
return restoredError;
|
|
3201
2799
|
};
|
|
3202
2800
|
const restoreStackFromData = (restoredError, error, currentStack) => {
|
|
3203
2801
|
if (error.data.stack && error.data.type && error.message) {
|
|
3204
|
-
setStack(restoredError, `${error.data.type}: ${error.message}${NewLine}${error.data.stack}${NewLine}${currentStack}`);
|
|
2802
|
+
setStack(restoredError, `${error.data.type}: ${error.message}${NewLine$1}${error.data.stack}${NewLine$1}${currentStack}`);
|
|
3205
2803
|
return;
|
|
3206
2804
|
}
|
|
3207
2805
|
if (error.data.stack) {
|
|
@@ -3275,7 +2873,7 @@ const warn = (...args) => {
|
|
|
3275
2873
|
console.warn(...args);
|
|
3276
2874
|
};
|
|
3277
2875
|
const resolve = (id, response) => {
|
|
3278
|
-
const fn = get$
|
|
2876
|
+
const fn = get$6(id);
|
|
3279
2877
|
if (!fn) {
|
|
3280
2878
|
console.log(response);
|
|
3281
2879
|
warn(`callback ${id} may already be disposed`);
|
|
@@ -3303,345 +2901,870 @@ const getStack = prettyError => {
|
|
|
3303
2901
|
if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
|
|
3304
2902
|
return stackString.slice(newLineIndex + 1);
|
|
3305
2903
|
}
|
|
3306
|
-
return stackString;
|
|
2904
|
+
return stackString;
|
|
2905
|
+
};
|
|
2906
|
+
const getErrorProperty = (error, prettyError) => {
|
|
2907
|
+
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
2908
|
+
return {
|
|
2909
|
+
code: MethodNotFound,
|
|
2910
|
+
data: error.stack,
|
|
2911
|
+
message: error.message
|
|
2912
|
+
};
|
|
2913
|
+
}
|
|
2914
|
+
return {
|
|
2915
|
+
code: Custom,
|
|
2916
|
+
data: {
|
|
2917
|
+
code: prettyError.code,
|
|
2918
|
+
codeFrame: prettyError.codeFrame,
|
|
2919
|
+
name: prettyError.name,
|
|
2920
|
+
stack: getStack(prettyError),
|
|
2921
|
+
type: getErrorType(prettyError)
|
|
2922
|
+
},
|
|
2923
|
+
message: prettyError.message
|
|
2924
|
+
};
|
|
2925
|
+
};
|
|
2926
|
+
const create$1$1 = (id, error) => {
|
|
2927
|
+
return {
|
|
2928
|
+
error,
|
|
2929
|
+
id,
|
|
2930
|
+
jsonrpc: Two$1
|
|
2931
|
+
};
|
|
2932
|
+
};
|
|
2933
|
+
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
2934
|
+
const prettyError = preparePrettyError(error);
|
|
2935
|
+
logError(error, prettyError);
|
|
2936
|
+
const errorProperty = getErrorProperty(error, prettyError);
|
|
2937
|
+
return create$1$1(id, errorProperty);
|
|
2938
|
+
};
|
|
2939
|
+
const create$I = (message, result) => {
|
|
2940
|
+
return {
|
|
2941
|
+
id: message.id,
|
|
2942
|
+
jsonrpc: Two$1,
|
|
2943
|
+
result: result ?? null
|
|
2944
|
+
};
|
|
2945
|
+
};
|
|
2946
|
+
const getSuccessResponse = (message, result) => {
|
|
2947
|
+
const resultProperty = result ?? null;
|
|
2948
|
+
return create$I(message, resultProperty);
|
|
2949
|
+
};
|
|
2950
|
+
const getErrorResponseSimple = (id, error) => {
|
|
2951
|
+
return {
|
|
2952
|
+
error: {
|
|
2953
|
+
code: Custom,
|
|
2954
|
+
data: error,
|
|
2955
|
+
// @ts-ignore
|
|
2956
|
+
message: error.message
|
|
2957
|
+
},
|
|
2958
|
+
id,
|
|
2959
|
+
jsonrpc: Two$1
|
|
2960
|
+
};
|
|
2961
|
+
};
|
|
2962
|
+
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
2963
|
+
try {
|
|
2964
|
+
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
2965
|
+
return getSuccessResponse(message, result);
|
|
2966
|
+
} catch (error) {
|
|
2967
|
+
if (ipc.canUseSimpleErrorResponse) {
|
|
2968
|
+
return getErrorResponseSimple(message.id, error);
|
|
2969
|
+
}
|
|
2970
|
+
return getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
2971
|
+
}
|
|
2972
|
+
};
|
|
2973
|
+
const defaultPreparePrettyError = error => {
|
|
2974
|
+
return error;
|
|
2975
|
+
};
|
|
2976
|
+
const defaultLogError = () => {
|
|
2977
|
+
// ignore
|
|
2978
|
+
};
|
|
2979
|
+
const defaultRequiresSocket = () => {
|
|
2980
|
+
return false;
|
|
2981
|
+
};
|
|
2982
|
+
const defaultResolve = resolve;
|
|
2983
|
+
|
|
2984
|
+
// TODO maybe remove this in v6 or v7, only accept options object to simplify the code
|
|
2985
|
+
const normalizeParams = args => {
|
|
2986
|
+
if (args.length === 1) {
|
|
2987
|
+
const options = args[0];
|
|
2988
|
+
return {
|
|
2989
|
+
execute: options.execute,
|
|
2990
|
+
ipc: options.ipc,
|
|
2991
|
+
logError: options.logError || defaultLogError,
|
|
2992
|
+
message: options.message,
|
|
2993
|
+
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
2994
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket,
|
|
2995
|
+
resolve: options.resolve || defaultResolve
|
|
2996
|
+
};
|
|
2997
|
+
}
|
|
2998
|
+
return {
|
|
2999
|
+
execute: args[2],
|
|
3000
|
+
ipc: args[0],
|
|
3001
|
+
logError: args[5],
|
|
3002
|
+
message: args[1],
|
|
3003
|
+
preparePrettyError: args[4],
|
|
3004
|
+
requiresSocket: args[6],
|
|
3005
|
+
resolve: args[3]
|
|
3006
|
+
};
|
|
3007
|
+
};
|
|
3008
|
+
const handleJsonRpcMessage = async (...args) => {
|
|
3009
|
+
const options = normalizeParams(args);
|
|
3010
|
+
const {
|
|
3011
|
+
execute,
|
|
3012
|
+
ipc,
|
|
3013
|
+
logError,
|
|
3014
|
+
message,
|
|
3015
|
+
preparePrettyError,
|
|
3016
|
+
requiresSocket,
|
|
3017
|
+
resolve
|
|
3018
|
+
} = options;
|
|
3019
|
+
if ('id' in message) {
|
|
3020
|
+
if ('method' in message) {
|
|
3021
|
+
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
3022
|
+
try {
|
|
3023
|
+
ipc.send(response);
|
|
3024
|
+
} catch (error) {
|
|
3025
|
+
const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
3026
|
+
ipc.send(errorResponse);
|
|
3027
|
+
}
|
|
3028
|
+
return;
|
|
3029
|
+
}
|
|
3030
|
+
resolve(message.id, message);
|
|
3031
|
+
return;
|
|
3032
|
+
}
|
|
3033
|
+
if ('method' in message) {
|
|
3034
|
+
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
3035
|
+
return;
|
|
3036
|
+
}
|
|
3037
|
+
throw new JsonRpcError('unexpected message');
|
|
3038
|
+
};
|
|
3039
|
+
|
|
3040
|
+
const Two = '2.0';
|
|
3041
|
+
|
|
3042
|
+
const create$H = (method, params) => {
|
|
3043
|
+
return {
|
|
3044
|
+
jsonrpc: Two,
|
|
3045
|
+
method,
|
|
3046
|
+
params
|
|
3047
|
+
};
|
|
3048
|
+
};
|
|
3049
|
+
|
|
3050
|
+
const create$G = (id, method, params) => {
|
|
3051
|
+
const message = {
|
|
3052
|
+
id,
|
|
3053
|
+
jsonrpc: Two,
|
|
3054
|
+
method,
|
|
3055
|
+
params
|
|
3056
|
+
};
|
|
3057
|
+
return message;
|
|
3058
|
+
};
|
|
3059
|
+
|
|
3060
|
+
let id = 0;
|
|
3061
|
+
const create$F = () => {
|
|
3062
|
+
return ++id;
|
|
3063
|
+
};
|
|
3064
|
+
|
|
3065
|
+
const registerPromise = map => {
|
|
3066
|
+
const id = create$F();
|
|
3067
|
+
const {
|
|
3068
|
+
promise,
|
|
3069
|
+
resolve
|
|
3070
|
+
} = Promise.withResolvers();
|
|
3071
|
+
map[id] = resolve;
|
|
3072
|
+
return {
|
|
3073
|
+
id,
|
|
3074
|
+
promise
|
|
3075
|
+
};
|
|
3076
|
+
};
|
|
3077
|
+
|
|
3078
|
+
const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
|
|
3079
|
+
const {
|
|
3080
|
+
id,
|
|
3081
|
+
promise
|
|
3082
|
+
} = registerPromise(callbacks);
|
|
3083
|
+
const message = create$G(id, method, params);
|
|
3084
|
+
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
3085
|
+
ipc.sendAndTransfer(message);
|
|
3086
|
+
} else {
|
|
3087
|
+
ipc.send(message);
|
|
3088
|
+
}
|
|
3089
|
+
const responseMessage = await promise;
|
|
3090
|
+
return unwrapJsonRpcResult(responseMessage);
|
|
3091
|
+
};
|
|
3092
|
+
const createRpc = ipc => {
|
|
3093
|
+
const callbacks = Object.create(null);
|
|
3094
|
+
ipc._resolve = (id, response) => {
|
|
3095
|
+
const fn = callbacks[id];
|
|
3096
|
+
if (!fn) {
|
|
3097
|
+
console.warn(`callback ${id} may already be disposed`);
|
|
3098
|
+
return;
|
|
3099
|
+
}
|
|
3100
|
+
fn(response);
|
|
3101
|
+
delete callbacks[id];
|
|
3102
|
+
};
|
|
3103
|
+
const rpc = {
|
|
3104
|
+
async dispose() {
|
|
3105
|
+
await ipc?.dispose();
|
|
3106
|
+
},
|
|
3107
|
+
invoke(method, ...params) {
|
|
3108
|
+
return invokeHelper(callbacks, ipc, method, params, false);
|
|
3109
|
+
},
|
|
3110
|
+
invokeAndTransfer(method, ...params) {
|
|
3111
|
+
return invokeHelper(callbacks, ipc, method, params, true);
|
|
3112
|
+
},
|
|
3113
|
+
// @ts-ignore
|
|
3114
|
+
ipc,
|
|
3115
|
+
/**
|
|
3116
|
+
* @deprecated
|
|
3117
|
+
*/
|
|
3118
|
+
send(method, ...params) {
|
|
3119
|
+
const message = create$H(method, params);
|
|
3120
|
+
ipc.send(message);
|
|
3121
|
+
}
|
|
3122
|
+
};
|
|
3123
|
+
return rpc;
|
|
3124
|
+
};
|
|
3125
|
+
|
|
3126
|
+
const requiresSocket = () => {
|
|
3127
|
+
return false;
|
|
3128
|
+
};
|
|
3129
|
+
const preparePrettyError = error => {
|
|
3130
|
+
return error;
|
|
3131
|
+
};
|
|
3132
|
+
const logError$1 = () => {
|
|
3133
|
+
// handled by renderer worker
|
|
3134
|
+
};
|
|
3135
|
+
const handleMessage = event => {
|
|
3136
|
+
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
3137
|
+
const actualExecute = event?.target?.execute || execute;
|
|
3138
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError$1, actualRequiresSocket);
|
|
3139
|
+
};
|
|
3140
|
+
|
|
3141
|
+
const handleIpc = ipc => {
|
|
3142
|
+
if ('addEventListener' in ipc) {
|
|
3143
|
+
ipc.addEventListener('message', handleMessage);
|
|
3144
|
+
} else if ('on' in ipc) {
|
|
3145
|
+
// deprecated
|
|
3146
|
+
ipc.on('message', handleMessage);
|
|
3147
|
+
}
|
|
3148
|
+
};
|
|
3149
|
+
const unhandleIpc = ipc => {
|
|
3150
|
+
if ('removeEventListener' in ipc) {
|
|
3151
|
+
ipc.removeEventListener('message', handleMessage);
|
|
3152
|
+
} else {
|
|
3153
|
+
// deprecated
|
|
3154
|
+
ipc.onmessage = null;
|
|
3155
|
+
}
|
|
3156
|
+
};
|
|
3157
|
+
|
|
3158
|
+
const create$E = async ({
|
|
3159
|
+
commandMap,
|
|
3160
|
+
window
|
|
3161
|
+
}) => {
|
|
3162
|
+
// TODO create a commandMap per rpc instance
|
|
3163
|
+
register(commandMap);
|
|
3164
|
+
const ipc = IpcChildWithElectronWindow$1.wrap(window);
|
|
3165
|
+
handleIpc(ipc);
|
|
3166
|
+
const rpc = createRpc(ipc);
|
|
3167
|
+
return rpc;
|
|
3168
|
+
};
|
|
3169
|
+
|
|
3170
|
+
const create$D = async ({
|
|
3171
|
+
commandMap,
|
|
3172
|
+
isMessagePortOpen = true,
|
|
3173
|
+
messagePort
|
|
3174
|
+
}) => {
|
|
3175
|
+
// TODO create a commandMap per rpc instance
|
|
3176
|
+
register(commandMap);
|
|
3177
|
+
const rawIpc = await IpcParentWithMessagePort$1$1.create({
|
|
3178
|
+
isMessagePortOpen,
|
|
3179
|
+
messagePort
|
|
3180
|
+
});
|
|
3181
|
+
const ipc = IpcParentWithMessagePort$1$1.wrap(rawIpc);
|
|
3182
|
+
handleIpc(ipc);
|
|
3183
|
+
const rpc = createRpc(ipc);
|
|
3184
|
+
messagePort.start();
|
|
3185
|
+
return rpc;
|
|
3186
|
+
};
|
|
3187
|
+
|
|
3188
|
+
const isWorker = value => {
|
|
3189
|
+
return value instanceof Worker;
|
|
3190
|
+
};
|
|
3191
|
+
|
|
3192
|
+
const create$C = async ({
|
|
3193
|
+
commandMap,
|
|
3194
|
+
name,
|
|
3195
|
+
url
|
|
3196
|
+
}) => {
|
|
3197
|
+
// TODO create a commandMap per rpc instance
|
|
3198
|
+
register(commandMap);
|
|
3199
|
+
const worker = await IpcParentWithModuleWorker$1$1.create({
|
|
3200
|
+
name,
|
|
3201
|
+
url
|
|
3202
|
+
});
|
|
3203
|
+
if (!isWorker(worker)) {
|
|
3204
|
+
throw new Error(`worker must be of type Worker`);
|
|
3205
|
+
}
|
|
3206
|
+
const ipc = IpcParentWithModuleWorker$1$1.wrap(worker);
|
|
3207
|
+
handleIpc(ipc);
|
|
3208
|
+
const workerRpc = createRpc(ipc);
|
|
3209
|
+
return workerRpc;
|
|
3210
|
+
};
|
|
3211
|
+
|
|
3212
|
+
const create$B = async ({
|
|
3213
|
+
commandMap,
|
|
3214
|
+
name,
|
|
3215
|
+
port,
|
|
3216
|
+
url
|
|
3217
|
+
}) => {
|
|
3218
|
+
// TODO create a commandMap per rpc instance
|
|
3219
|
+
register(commandMap);
|
|
3220
|
+
const worker = await IpcParentWithModuleWorker$1$1.create({
|
|
3221
|
+
name,
|
|
3222
|
+
url
|
|
3223
|
+
});
|
|
3224
|
+
if (!isWorker(worker)) {
|
|
3225
|
+
throw new Error(`worker must be of type Worker`);
|
|
3226
|
+
}
|
|
3227
|
+
const ipc = IpcParentWithModuleWorker$1$1.wrap(worker);
|
|
3228
|
+
handleIpc(ipc);
|
|
3229
|
+
const workerRpc = createRpc(ipc);
|
|
3230
|
+
await workerRpc.invokeAndTransfer('initialize', 'message-port', port);
|
|
3231
|
+
unhandleIpc(ipc);
|
|
3232
|
+
return workerRpc;
|
|
3307
3233
|
};
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3234
|
+
|
|
3235
|
+
const create$A = async ({
|
|
3236
|
+
commandMap,
|
|
3237
|
+
messagePort
|
|
3238
|
+
}) => {
|
|
3239
|
+
return create$D({
|
|
3240
|
+
commandMap,
|
|
3241
|
+
messagePort
|
|
3242
|
+
});
|
|
3243
|
+
};
|
|
3244
|
+
|
|
3245
|
+
const commandMapRef = {};
|
|
3246
|
+
|
|
3247
|
+
const success = value => {
|
|
3316
3248
|
return {
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
code: prettyError.code,
|
|
3320
|
-
codeFrame: prettyError.codeFrame,
|
|
3321
|
-
name: prettyError.name,
|
|
3322
|
-
stack: getStack(prettyError),
|
|
3323
|
-
type: getErrorType(prettyError)
|
|
3324
|
-
},
|
|
3325
|
-
message: prettyError.message
|
|
3249
|
+
ok: true,
|
|
3250
|
+
value
|
|
3326
3251
|
};
|
|
3327
3252
|
};
|
|
3328
|
-
const
|
|
3253
|
+
const error = error => {
|
|
3329
3254
|
return {
|
|
3330
3255
|
error,
|
|
3331
|
-
|
|
3332
|
-
jsonrpc: Two$1
|
|
3256
|
+
ok: false
|
|
3333
3257
|
};
|
|
3334
3258
|
};
|
|
3335
|
-
const
|
|
3336
|
-
|
|
3337
|
-
logError(error, prettyError);
|
|
3338
|
-
const errorProperty = getErrorProperty(error, prettyError);
|
|
3339
|
-
return create$1$1(id, errorProperty);
|
|
3259
|
+
const isError = result => {
|
|
3260
|
+
return !result.ok;
|
|
3340
3261
|
};
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3262
|
+
|
|
3263
|
+
const launchWorker = async ({
|
|
3264
|
+
name,
|
|
3265
|
+
url
|
|
3266
|
+
}) => {
|
|
3267
|
+
try {
|
|
3268
|
+
const rpc = await create$C({
|
|
3269
|
+
commandMap: commandMapRef,
|
|
3270
|
+
name,
|
|
3271
|
+
url
|
|
3272
|
+
});
|
|
3273
|
+
return success(rpc);
|
|
3274
|
+
} catch (error$1) {
|
|
3275
|
+
return error(error$1);
|
|
3276
|
+
}
|
|
3347
3277
|
};
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
return
|
|
3278
|
+
|
|
3279
|
+
const launchDragAndDropWorker = async () => {
|
|
3280
|
+
return launchWorker({
|
|
3281
|
+
name: 'Drag And Drop Worker',
|
|
3282
|
+
url: dragAndDropWorkerUrl
|
|
3283
|
+
});
|
|
3351
3284
|
};
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
code: Custom,
|
|
3356
|
-
data: error,
|
|
3357
|
-
// @ts-ignore
|
|
3358
|
-
message: error.message
|
|
3359
|
-
},
|
|
3360
|
-
id,
|
|
3361
|
-
jsonrpc: Two$1
|
|
3362
|
-
};
|
|
3285
|
+
|
|
3286
|
+
const state$b = {
|
|
3287
|
+
rpc: undefined
|
|
3363
3288
|
};
|
|
3364
|
-
const
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
if (ipc.canUseSimpleErrorResponse) {
|
|
3370
|
-
return getErrorResponseSimple(message.id, error);
|
|
3371
|
-
}
|
|
3372
|
-
return getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
3289
|
+
const hydrate$4 = async () => {
|
|
3290
|
+
const result = await launchDragAndDropWorker();
|
|
3291
|
+
if (isError(result)) {
|
|
3292
|
+
state$b.rpc = undefined;
|
|
3293
|
+
return result;
|
|
3373
3294
|
}
|
|
3295
|
+
state$b.rpc = result.value;
|
|
3296
|
+
return success(undefined);
|
|
3374
3297
|
};
|
|
3375
|
-
const
|
|
3376
|
-
|
|
3298
|
+
const handleMessagePort$1 = async port => {
|
|
3299
|
+
if (!state$b.rpc) {
|
|
3300
|
+
throw new Error('Drag And Drop Worker is not initialized');
|
|
3301
|
+
}
|
|
3302
|
+
await state$b.rpc.invokeAndTransfer('DragAndDrop.handleMessagePort', port);
|
|
3377
3303
|
};
|
|
3378
|
-
|
|
3379
|
-
|
|
3304
|
+
|
|
3305
|
+
const downloadFile = (fileName, url) => {
|
|
3306
|
+
const a = document.createElement('a');
|
|
3307
|
+
a.href = url;
|
|
3308
|
+
a.download = fileName;
|
|
3309
|
+
a.click();
|
|
3380
3310
|
};
|
|
3381
|
-
|
|
3382
|
-
|
|
3311
|
+
|
|
3312
|
+
const isFile = value => {
|
|
3313
|
+
return value instanceof File;
|
|
3383
3314
|
};
|
|
3384
|
-
const defaultResolve = resolve;
|
|
3385
3315
|
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3316
|
+
const getFilePathElectron = async file => {
|
|
3317
|
+
if (!isFile(file)) {
|
|
3318
|
+
throw new TypeError(`file must be of type File`);
|
|
3319
|
+
}
|
|
3320
|
+
if (!globalThis.electronGlobals) {
|
|
3321
|
+
throw new Error(`electron globals are not available`);
|
|
3322
|
+
}
|
|
3323
|
+
const filePath = globalThis.electronGlobals.getPathForFile(file);
|
|
3324
|
+
return filePath;
|
|
3325
|
+
};
|
|
3326
|
+
|
|
3327
|
+
const validFormats = new Set(['file', 'fileSystemHandle', 'string']);
|
|
3328
|
+
const validateOptions = options => {
|
|
3329
|
+
if (!options || !Array.isArray(options.formats) || typeof options.includeElectronFilePaths !== 'boolean') {
|
|
3330
|
+
throw new TypeError('Invalid drop data options');
|
|
3331
|
+
}
|
|
3332
|
+
for (const format of options.formats) {
|
|
3333
|
+
if (!validFormats.has(format)) {
|
|
3334
|
+
throw new TypeError(`Invalid drop data format: ${format}`);
|
|
3335
|
+
}
|
|
3399
3336
|
}
|
|
3337
|
+
};
|
|
3338
|
+
const resolveString = async item => {
|
|
3400
3339
|
return {
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
preparePrettyError: args[4],
|
|
3406
|
-
requiresSocket: args[6],
|
|
3407
|
-
resolve: args[3]
|
|
3340
|
+
index: item.index,
|
|
3341
|
+
kind: 'string',
|
|
3342
|
+
type: item.type,
|
|
3343
|
+
value: await item.value
|
|
3408
3344
|
};
|
|
3409
3345
|
};
|
|
3410
|
-
const
|
|
3411
|
-
const
|
|
3412
|
-
const
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3346
|
+
const resolveFile = async (item, formats, includeElectronFilePaths) => {
|
|
3347
|
+
const includeFile = formats.has('file');
|
|
3348
|
+
const includeFileSystemHandle = formats.has('fileSystemHandle');
|
|
3349
|
+
const fileSystemHandle = includeFileSystemHandle ? await item.fileSystemHandle : undefined;
|
|
3350
|
+
const electronFilePath = includeElectronFilePaths && globalThis.electronGlobals && item.file ? await getFilePathElectron(item.file) : undefined;
|
|
3351
|
+
if ((!includeFile || !item.file) && !fileSystemHandle && electronFilePath === undefined) {
|
|
3352
|
+
return undefined;
|
|
3353
|
+
}
|
|
3354
|
+
return {
|
|
3355
|
+
...(electronFilePath !== undefined && {
|
|
3356
|
+
electronFilePath
|
|
3357
|
+
}),
|
|
3358
|
+
...(includeFile && item.file && {
|
|
3359
|
+
file: item.file
|
|
3360
|
+
}),
|
|
3361
|
+
...(fileSystemHandle && {
|
|
3362
|
+
fileSystemHandle
|
|
3363
|
+
}),
|
|
3364
|
+
index: item.index,
|
|
3365
|
+
kind: 'file',
|
|
3366
|
+
name: fileSystemHandle?.name || item.file?.name || '',
|
|
3367
|
+
type: item.type
|
|
3368
|
+
};
|
|
3369
|
+
};
|
|
3370
|
+
const get$5 = async (dropId, options) => {
|
|
3371
|
+
validateOptions(options);
|
|
3372
|
+
const retainedItems = acquire$2(dropId);
|
|
3373
|
+
const formats = new Set(options.formats);
|
|
3374
|
+
const items = [];
|
|
3375
|
+
for (const retainedItem of retainedItems) {
|
|
3376
|
+
if (retainedItem.kind === 'string') {
|
|
3377
|
+
if (formats.has('string')) {
|
|
3378
|
+
items.push(await resolveString(retainedItem));
|
|
3429
3379
|
}
|
|
3430
|
-
|
|
3380
|
+
continue;
|
|
3381
|
+
}
|
|
3382
|
+
const item = await resolveFile(retainedItem, formats, options.includeElectronFilePaths);
|
|
3383
|
+
if (item) {
|
|
3384
|
+
items.push(item);
|
|
3431
3385
|
}
|
|
3432
|
-
resolve(message.id, message);
|
|
3433
|
-
return;
|
|
3434
3386
|
}
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3387
|
+
return items;
|
|
3388
|
+
};
|
|
3389
|
+
|
|
3390
|
+
const isFileSystemFileHandle = value => {
|
|
3391
|
+
if (!value || typeof value !== 'object') {
|
|
3392
|
+
return false;
|
|
3393
|
+
}
|
|
3394
|
+
const candidate = value;
|
|
3395
|
+
return candidate.kind === 'file' && typeof candidate.getFile === 'function';
|
|
3396
|
+
};
|
|
3397
|
+
const getNativeFile = async item => {
|
|
3398
|
+
if (item.kind === 'file-legacy') {
|
|
3399
|
+
return item.value instanceof File ? item.value : undefined;
|
|
3400
|
+
}
|
|
3401
|
+
if (item.file instanceof File) {
|
|
3402
|
+
return item.file;
|
|
3403
|
+
}
|
|
3404
|
+
if (isFileSystemFileHandle(item.value)) {
|
|
3405
|
+
return item.value.getFile();
|
|
3406
|
+
}
|
|
3407
|
+
return undefined;
|
|
3408
|
+
};
|
|
3409
|
+
const addElectronPath = async item => {
|
|
3410
|
+
if (!globalThis.electronGlobals) {
|
|
3411
|
+
return item;
|
|
3412
|
+
}
|
|
3413
|
+
const file = await getNativeFile(item);
|
|
3414
|
+
if (!file) {
|
|
3415
|
+
return item;
|
|
3438
3416
|
}
|
|
3439
|
-
|
|
3440
|
-
};
|
|
3441
|
-
|
|
3442
|
-
const Two = '2.0';
|
|
3443
|
-
|
|
3444
|
-
const create$E = (method, params) => {
|
|
3417
|
+
const path = await getFilePathElectron(file);
|
|
3445
3418
|
return {
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
params
|
|
3419
|
+
...item,
|
|
3420
|
+
path
|
|
3449
3421
|
};
|
|
3450
3422
|
};
|
|
3423
|
+
const get$4 = async ids => {
|
|
3424
|
+
const items = await getFileHandles$1(ids);
|
|
3425
|
+
return Promise.all(items.map(addElectronPath));
|
|
3426
|
+
};
|
|
3451
3427
|
|
|
3452
|
-
const
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3428
|
+
const showDirectoryPicker = options => {
|
|
3429
|
+
// @ts-expect-error
|
|
3430
|
+
return window.showDirectoryPicker(options);
|
|
3431
|
+
};
|
|
3432
|
+
const showFilePicker = options => {
|
|
3433
|
+
// @ts-expect-error
|
|
3434
|
+
return window.showOpenFilePicker(options);
|
|
3435
|
+
};
|
|
3436
|
+
const showSaveFilePicker = options => {
|
|
3437
|
+
// @ts-expect-error
|
|
3438
|
+
return window.showSaveFilePicker(options);
|
|
3460
3439
|
};
|
|
3461
3440
|
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3441
|
+
const requestPermission = (handle, options) => {
|
|
3442
|
+
return handle.requestPermission(options);
|
|
3443
|
+
};
|
|
3444
|
+
const getFileHandles = ids => {
|
|
3445
|
+
return getFileHandles$1(ids);
|
|
3446
|
+
};
|
|
3447
|
+
const addFileHandle = fileHandle => {
|
|
3448
|
+
return addFileHandle$1(fileHandle);
|
|
3465
3449
|
};
|
|
3466
3450
|
|
|
3467
|
-
const
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3451
|
+
const getTitleBarHeight = () => {
|
|
3452
|
+
if (
|
|
3453
|
+
// @ts-expect-error
|
|
3454
|
+
globalThis.navigator.windowControlsOverlay?.getTitlebarAreaRect) {
|
|
3455
|
+
// @ts-expect-error
|
|
3456
|
+
const titleBarRect = globalThis.navigator.windowControlsOverlay.getTitlebarAreaRect();
|
|
3457
|
+
return titleBarRect.height;
|
|
3458
|
+
}
|
|
3459
|
+
return 0;
|
|
3460
|
+
};
|
|
3461
|
+
const getBounds = () => {
|
|
3474
3462
|
return {
|
|
3475
|
-
|
|
3476
|
-
|
|
3463
|
+
titleBarHeight: getTitleBarHeight(),
|
|
3464
|
+
windowHeight: window.innerHeight,
|
|
3465
|
+
windowWidth: window.innerWidth
|
|
3477
3466
|
};
|
|
3478
3467
|
};
|
|
3479
3468
|
|
|
3480
|
-
const
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3469
|
+
const getPathName = () => {
|
|
3470
|
+
return location.pathname;
|
|
3471
|
+
};
|
|
3472
|
+
const getHref = () => {
|
|
3473
|
+
return location.href;
|
|
3474
|
+
};
|
|
3475
|
+
const matchesPathName = (currentPathName, pathName) => {
|
|
3476
|
+
const resolvedPathName = new URL(pathName, getHref()).pathname;
|
|
3477
|
+
return currentPathName === resolvedPathName;
|
|
3478
|
+
};
|
|
3479
|
+
const setPathName = pathName => {
|
|
3480
|
+
const currentPathName = getPathName();
|
|
3481
|
+
if (matchesPathName(currentPathName, pathName)) {
|
|
3482
|
+
return;
|
|
3490
3483
|
}
|
|
3491
|
-
|
|
3492
|
-
return unwrapJsonRpcResult(responseMessage);
|
|
3484
|
+
history.pushState(null, '', pathName);
|
|
3493
3485
|
};
|
|
3494
|
-
const
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
}
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3486
|
+
const hydrate$3 = () => {
|
|
3487
|
+
// addEventListener('popstate', handlePopState)
|
|
3488
|
+
};
|
|
3489
|
+
|
|
3490
|
+
const shouldLaunchMultipleWorkers = true;
|
|
3491
|
+
|
|
3492
|
+
const getConfig = () => {
|
|
3493
|
+
const configElement = document.getElementById('Config');
|
|
3494
|
+
if (!configElement?.textContent) {
|
|
3495
|
+
return {};
|
|
3496
|
+
}
|
|
3497
|
+
return JSON.parse(configElement.textContent);
|
|
3498
|
+
};
|
|
3499
|
+
const getInitData = () => {
|
|
3500
|
+
const initData = {
|
|
3501
|
+
Config: {
|
|
3502
|
+
...getConfig(),
|
|
3503
|
+
shouldLaunchMultipleWorkers: shouldLaunchMultipleWorkers
|
|
3511
3504
|
},
|
|
3512
|
-
|
|
3513
|
-
|
|
3505
|
+
Layout: {
|
|
3506
|
+
bounds: getBounds()
|
|
3514
3507
|
},
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
/**
|
|
3518
|
-
* @deprecated
|
|
3519
|
-
*/
|
|
3520
|
-
send(method, ...params) {
|
|
3521
|
-
const message = create$E(method, params);
|
|
3522
|
-
ipc.send(message);
|
|
3508
|
+
Location: {
|
|
3509
|
+
href: getHref()
|
|
3523
3510
|
}
|
|
3524
3511
|
};
|
|
3525
|
-
return
|
|
3512
|
+
return initData;
|
|
3526
3513
|
};
|
|
3527
3514
|
|
|
3528
|
-
const
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
const
|
|
3532
|
-
|
|
3515
|
+
const MessagePort$1 = 1;
|
|
3516
|
+
const ModuleWorker = 2;
|
|
3517
|
+
const ReferencePort = 3;
|
|
3518
|
+
const ModuleWorkerWithMessagePort = 4;
|
|
3519
|
+
const Electron = 5;
|
|
3520
|
+
|
|
3521
|
+
const Message = 'message';
|
|
3522
|
+
const Error$3 = 'error';
|
|
3523
|
+
|
|
3524
|
+
const withResolvers = () => {
|
|
3525
|
+
return Promise.withResolvers();
|
|
3533
3526
|
};
|
|
3534
|
-
|
|
3535
|
-
|
|
3527
|
+
|
|
3528
|
+
const getFirstEvent = (eventTarget, eventMap) => {
|
|
3529
|
+
const {
|
|
3530
|
+
promise,
|
|
3531
|
+
resolve
|
|
3532
|
+
} = withResolvers();
|
|
3533
|
+
const listenerMap = Object.create(null);
|
|
3534
|
+
const cleanup = value => {
|
|
3535
|
+
for (const event of Object.keys(eventMap)) {
|
|
3536
|
+
eventTarget.removeEventListener(event, listenerMap[event]);
|
|
3537
|
+
}
|
|
3538
|
+
resolve(value);
|
|
3539
|
+
};
|
|
3540
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
3541
|
+
const listener = event => {
|
|
3542
|
+
cleanup({
|
|
3543
|
+
event,
|
|
3544
|
+
type
|
|
3545
|
+
});
|
|
3546
|
+
};
|
|
3547
|
+
eventTarget.addEventListener(event, listener);
|
|
3548
|
+
listenerMap[event] = listener;
|
|
3549
|
+
}
|
|
3550
|
+
return promise;
|
|
3536
3551
|
};
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3552
|
+
|
|
3553
|
+
/**
|
|
3554
|
+
*
|
|
3555
|
+
* @param {Worker} worker
|
|
3556
|
+
* @returns
|
|
3557
|
+
*/
|
|
3558
|
+
const getFirstWorkerEvent = worker => {
|
|
3559
|
+
return getFirstEvent(worker, {
|
|
3560
|
+
error: Error$3,
|
|
3561
|
+
message: Message
|
|
3562
|
+
});
|
|
3541
3563
|
};
|
|
3542
3564
|
|
|
3543
|
-
const
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3565
|
+
const transferrables = [];
|
|
3566
|
+
if (typeof MessagePort !== 'undefined') {
|
|
3567
|
+
transferrables.push(MessagePort);
|
|
3568
|
+
}
|
|
3569
|
+
if (typeof OffscreenCanvas !== 'undefined') {
|
|
3570
|
+
transferrables.push(OffscreenCanvas);
|
|
3571
|
+
}
|
|
3572
|
+
|
|
3573
|
+
const isTransferrable = value => {
|
|
3574
|
+
for (const fn of transferrables) {
|
|
3575
|
+
if (value instanceof fn) {
|
|
3576
|
+
return true;
|
|
3577
|
+
}
|
|
3549
3578
|
}
|
|
3579
|
+
return false;
|
|
3550
3580
|
};
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3581
|
+
|
|
3582
|
+
const walkValue = (value, transferrables) => {
|
|
3583
|
+
if (!value) {
|
|
3584
|
+
return;
|
|
3585
|
+
}
|
|
3586
|
+
if (isTransferrable(value)) {
|
|
3587
|
+
transferrables.push(value);
|
|
3588
|
+
}
|
|
3589
|
+
if (Array.isArray(value)) {
|
|
3590
|
+
for (const item of value) {
|
|
3591
|
+
walkValue(item, transferrables);
|
|
3592
|
+
}
|
|
3593
|
+
return;
|
|
3594
|
+
}
|
|
3595
|
+
if (typeof value === 'object') {
|
|
3596
|
+
for (const property of Object.values(value)) {
|
|
3597
|
+
walkValue(property, transferrables);
|
|
3598
|
+
}
|
|
3557
3599
|
}
|
|
3558
3600
|
};
|
|
3559
3601
|
|
|
3560
|
-
const
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3602
|
+
const getTransfer = value => {
|
|
3603
|
+
const transferrables = [];
|
|
3604
|
+
walkValue(value, transferrables);
|
|
3605
|
+
return transferrables;
|
|
3606
|
+
};
|
|
3607
|
+
|
|
3608
|
+
class IpcError extends Error {
|
|
3609
|
+
constructor(message) {
|
|
3610
|
+
super(message);
|
|
3611
|
+
this.name = 'IpcError';
|
|
3612
|
+
}
|
|
3613
|
+
}
|
|
3614
|
+
|
|
3615
|
+
const isErrorEvent = event => {
|
|
3616
|
+
return event instanceof ErrorEvent;
|
|
3570
3617
|
};
|
|
3571
3618
|
|
|
3572
|
-
const
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
}) => {
|
|
3577
|
-
// TODO create a commandMap per rpc instance
|
|
3578
|
-
register(commandMap);
|
|
3579
|
-
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
3580
|
-
isMessagePortOpen,
|
|
3581
|
-
messagePort
|
|
3582
|
-
});
|
|
3583
|
-
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
3584
|
-
handleIpc(ipc);
|
|
3585
|
-
const rpc = createRpc(ipc);
|
|
3586
|
-
messagePort.start();
|
|
3587
|
-
return rpc;
|
|
3619
|
+
const NewLine = '\n';
|
|
3620
|
+
|
|
3621
|
+
const joinLines = lines => {
|
|
3622
|
+
return lines.join(NewLine);
|
|
3588
3623
|
};
|
|
3589
3624
|
|
|
3590
|
-
const
|
|
3591
|
-
|
|
3625
|
+
const splitLines = lines => {
|
|
3626
|
+
string(lines);
|
|
3627
|
+
return lines.split(NewLine);
|
|
3592
3628
|
};
|
|
3593
3629
|
|
|
3630
|
+
class WorkerError extends Error {
|
|
3631
|
+
constructor(event) {
|
|
3632
|
+
super(event.message);
|
|
3633
|
+
const stackLines = splitLines(this.stack);
|
|
3634
|
+
const relevantLines = stackLines.slice(1);
|
|
3635
|
+
const relevant = joinLines(relevantLines);
|
|
3636
|
+
this.stack = `${event.message}
|
|
3637
|
+
at Module (${event.filename}:${event.lineno}:${event.colno})
|
|
3638
|
+
${relevant}`;
|
|
3639
|
+
}
|
|
3640
|
+
}
|
|
3641
|
+
|
|
3642
|
+
const Module = 'module';
|
|
3643
|
+
|
|
3644
|
+
const getWorkerDisplayName = name => {
|
|
3645
|
+
if (name && name.endsWith('Worker')) {
|
|
3646
|
+
return name;
|
|
3647
|
+
}
|
|
3648
|
+
return `${name} worker`;
|
|
3649
|
+
};
|
|
3594
3650
|
const create$z = async ({
|
|
3595
|
-
commandMap,
|
|
3596
3651
|
name,
|
|
3597
3652
|
url
|
|
3598
3653
|
}) => {
|
|
3599
|
-
|
|
3600
|
-
register(commandMap);
|
|
3601
|
-
const worker = await IpcParentWithModuleWorker$1.create({
|
|
3654
|
+
const worker = new Worker(url, {
|
|
3602
3655
|
name,
|
|
3603
|
-
|
|
3656
|
+
type: Module
|
|
3604
3657
|
});
|
|
3605
|
-
|
|
3606
|
-
|
|
3658
|
+
// @ts-expect-error
|
|
3659
|
+
const {
|
|
3660
|
+
event,
|
|
3661
|
+
type
|
|
3662
|
+
} = await getFirstWorkerEvent(worker);
|
|
3663
|
+
switch (type) {
|
|
3664
|
+
case Message:
|
|
3665
|
+
if (event.data !== 'ready') {
|
|
3666
|
+
throw new IpcError('unexpected first message from worker');
|
|
3667
|
+
}
|
|
3668
|
+
break;
|
|
3669
|
+
case Error$3:
|
|
3670
|
+
if (isErrorEvent(event)) {
|
|
3671
|
+
throw new WorkerError(event);
|
|
3672
|
+
}
|
|
3673
|
+
const displayName = getWorkerDisplayName(name);
|
|
3674
|
+
throw new IpcError(`Failed to start ${displayName}`);
|
|
3607
3675
|
}
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3676
|
+
return worker;
|
|
3677
|
+
};
|
|
3678
|
+
const getData = event => {
|
|
3679
|
+
// TODO why are some events not instance of message event?
|
|
3680
|
+
if (event instanceof MessageEvent) {
|
|
3681
|
+
return event.data;
|
|
3682
|
+
}
|
|
3683
|
+
return event;
|
|
3684
|
+
};
|
|
3685
|
+
const wrap = worker => {
|
|
3686
|
+
let handleMessage;
|
|
3687
|
+
const wrapped = {
|
|
3688
|
+
get onmessage() {
|
|
3689
|
+
return handleMessage;
|
|
3690
|
+
},
|
|
3691
|
+
set onmessage(listener) {
|
|
3692
|
+
if (listener) {
|
|
3693
|
+
handleMessage = event => {
|
|
3694
|
+
const data = getData(event);
|
|
3695
|
+
listener({
|
|
3696
|
+
data,
|
|
3697
|
+
target: wrapped
|
|
3698
|
+
});
|
|
3699
|
+
};
|
|
3700
|
+
} else {
|
|
3701
|
+
handleMessage = null;
|
|
3702
|
+
}
|
|
3703
|
+
worker.onmessage = handleMessage;
|
|
3704
|
+
},
|
|
3705
|
+
send(message) {
|
|
3706
|
+
worker.postMessage(message);
|
|
3707
|
+
},
|
|
3708
|
+
sendAndTransfer(message) {
|
|
3709
|
+
const transfer = getTransfer(message);
|
|
3710
|
+
worker.postMessage(message, transfer);
|
|
3711
|
+
}
|
|
3712
|
+
};
|
|
3713
|
+
return wrapped;
|
|
3714
|
+
};
|
|
3715
|
+
|
|
3716
|
+
const IpcParentWithModuleWorker = {
|
|
3717
|
+
__proto__: null,
|
|
3718
|
+
create: create$z,
|
|
3719
|
+
wrap
|
|
3720
|
+
};
|
|
3721
|
+
|
|
3722
|
+
const isMessagePort = value => {
|
|
3723
|
+
return value instanceof MessagePort;
|
|
3612
3724
|
};
|
|
3613
3725
|
|
|
3614
3726
|
const create$y = async ({
|
|
3615
|
-
commandMap,
|
|
3616
|
-
name,
|
|
3617
|
-
port,
|
|
3618
3727
|
url
|
|
3619
3728
|
}) => {
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3729
|
+
string(url);
|
|
3730
|
+
const portPromise = await new Promise(resolve => {
|
|
3731
|
+
Object.defineProperty(globalThis, 'acceptPort', {
|
|
3732
|
+
configurable: true,
|
|
3733
|
+
value: resolve
|
|
3734
|
+
});
|
|
3625
3735
|
});
|
|
3626
|
-
|
|
3627
|
-
|
|
3736
|
+
await import(url);
|
|
3737
|
+
const port = await portPromise;
|
|
3738
|
+
delete globalThis.acceptPort;
|
|
3739
|
+
if (!port) {
|
|
3740
|
+
throw new IpcError('port must be defined');
|
|
3628
3741
|
}
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
unhandleIpc(ipc);
|
|
3634
|
-
return workerRpc;
|
|
3742
|
+
if (!isMessagePort(port)) {
|
|
3743
|
+
throw new IpcError('port must be of type MessagePort');
|
|
3744
|
+
}
|
|
3745
|
+
return port;
|
|
3635
3746
|
};
|
|
3636
3747
|
|
|
3637
|
-
const
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
}
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3748
|
+
const IpcParentWithMessagePort = {
|
|
3749
|
+
__proto__: null,
|
|
3750
|
+
create: create$y
|
|
3751
|
+
};
|
|
3752
|
+
|
|
3753
|
+
const create$x = async url => {
|
|
3754
|
+
const referencePort = await new Promise(resolve => {
|
|
3755
|
+
Object.defineProperty(globalThis, 'acceptReferencePort', {
|
|
3756
|
+
configurable: true,
|
|
3757
|
+
value: resolve
|
|
3758
|
+
});
|
|
3759
|
+
import(url);
|
|
3644
3760
|
});
|
|
3761
|
+
delete globalThis.acceptReferencePort;
|
|
3762
|
+
return referencePort;
|
|
3763
|
+
};
|
|
3764
|
+
|
|
3765
|
+
const IpcParentWithReferencePort = {
|
|
3766
|
+
__proto__: null,
|
|
3767
|
+
create: create$x
|
|
3645
3768
|
};
|
|
3646
3769
|
|
|
3647
3770
|
const workers = Object.create(null);
|
|
@@ -3661,7 +3784,7 @@ const create$w = async ({
|
|
|
3661
3784
|
raw,
|
|
3662
3785
|
rpcId,
|
|
3663
3786
|
url
|
|
3664
|
-
}, createTransferredRpc = create$
|
|
3787
|
+
}, createTransferredRpc = create$B, createNativeRpc = create$C) => {
|
|
3665
3788
|
const rpc = await (rpcId === undefined ? createTransferredRpc({
|
|
3666
3789
|
commandMap: {},
|
|
3667
3790
|
name,
|
|
@@ -3688,34 +3811,7 @@ const IpcParentWithModuleWorkerWithMessagePort = {
|
|
|
3688
3811
|
create: create$w
|
|
3689
3812
|
};
|
|
3690
3813
|
|
|
3691
|
-
const
|
|
3692
|
-
const Electron = 2;
|
|
3693
|
-
const Remote = 3;
|
|
3694
|
-
|
|
3695
|
-
/**
|
|
3696
|
-
* @returns {number}
|
|
3697
|
-
*/
|
|
3698
|
-
const getPlatform = () => {
|
|
3699
|
-
// @ts-expect-error
|
|
3700
|
-
if (typeof PLATFORM !== 'undefined') {
|
|
3701
|
-
// @ts-expect-error
|
|
3702
|
-
return PLATFORM;
|
|
3703
|
-
}
|
|
3704
|
-
// @ts-ignore
|
|
3705
|
-
if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') {
|
|
3706
|
-
return Remote;
|
|
3707
|
-
}
|
|
3708
|
-
if (globalThis.isElectron) {
|
|
3709
|
-
return Electron;
|
|
3710
|
-
}
|
|
3711
|
-
if (typeof location !== 'undefined' && location.search === '?web') {
|
|
3712
|
-
return Web;
|
|
3713
|
-
}
|
|
3714
|
-
return Remote;
|
|
3715
|
-
};
|
|
3716
|
-
const platform = getPlatform();
|
|
3717
|
-
|
|
3718
|
-
const isElectron = platform === Electron;
|
|
3814
|
+
const isElectron = platform === Electron$1;
|
|
3719
3815
|
|
|
3720
3816
|
// TODO use handleIncomingIpc function
|
|
3721
3817
|
const create$v = async ({
|
|
@@ -3726,7 +3822,7 @@ const create$v = async ({
|
|
|
3726
3822
|
if (!isElectron) {
|
|
3727
3823
|
throw new Error('Electron api was requested but is not available');
|
|
3728
3824
|
}
|
|
3729
|
-
const rpc = await create$
|
|
3825
|
+
const rpc = await create$E({
|
|
3730
3826
|
commandMap: {},
|
|
3731
3827
|
window
|
|
3732
3828
|
});
|
|
@@ -3741,12 +3837,12 @@ const IpcParentWithElectron = {
|
|
|
3741
3837
|
|
|
3742
3838
|
const getModule = method => {
|
|
3743
3839
|
switch (method) {
|
|
3744
|
-
case Electron
|
|
3840
|
+
case Electron:
|
|
3745
3841
|
return IpcParentWithElectron;
|
|
3746
3842
|
case MessagePort$1:
|
|
3747
|
-
return IpcParentWithMessagePort
|
|
3843
|
+
return IpcParentWithMessagePort;
|
|
3748
3844
|
case ModuleWorker:
|
|
3749
|
-
return IpcParentWithModuleWorker
|
|
3845
|
+
return IpcParentWithModuleWorker;
|
|
3750
3846
|
case ModuleWorkerWithMessagePort:
|
|
3751
3847
|
return IpcParentWithModuleWorkerWithMessagePort;
|
|
3752
3848
|
case ReferencePort:
|
|
@@ -3770,69 +3866,6 @@ const has = name => {
|
|
|
3770
3866
|
return ipcs[name];
|
|
3771
3867
|
};
|
|
3772
3868
|
|
|
3773
|
-
const commandMapRef = {};
|
|
3774
|
-
|
|
3775
|
-
const success = value => {
|
|
3776
|
-
return {
|
|
3777
|
-
ok: true,
|
|
3778
|
-
value
|
|
3779
|
-
};
|
|
3780
|
-
};
|
|
3781
|
-
const error = error => {
|
|
3782
|
-
return {
|
|
3783
|
-
error,
|
|
3784
|
-
ok: false
|
|
3785
|
-
};
|
|
3786
|
-
};
|
|
3787
|
-
const isError = result => {
|
|
3788
|
-
return !result.ok;
|
|
3789
|
-
};
|
|
3790
|
-
|
|
3791
|
-
const launchWorker = async ({
|
|
3792
|
-
name,
|
|
3793
|
-
url
|
|
3794
|
-
}) => {
|
|
3795
|
-
try {
|
|
3796
|
-
const rpc = await create$z({
|
|
3797
|
-
commandMap: commandMapRef,
|
|
3798
|
-
name,
|
|
3799
|
-
url
|
|
3800
|
-
});
|
|
3801
|
-
return success(rpc);
|
|
3802
|
-
} catch (error$1) {
|
|
3803
|
-
return error(error$1);
|
|
3804
|
-
}
|
|
3805
|
-
};
|
|
3806
|
-
|
|
3807
|
-
const getAssetDir = () => {
|
|
3808
|
-
// @ts-expect-error
|
|
3809
|
-
if (typeof ASSET_DIR !== 'undefined') {
|
|
3810
|
-
// @ts-expect-error
|
|
3811
|
-
return ASSET_DIR;
|
|
3812
|
-
}
|
|
3813
|
-
if (platform === Electron) {
|
|
3814
|
-
return '../../../../..';
|
|
3815
|
-
}
|
|
3816
|
-
return '';
|
|
3817
|
-
};
|
|
3818
|
-
const assetDir = getAssetDir();
|
|
3819
|
-
|
|
3820
|
-
const getConfiguredWorkerUrl = key => {
|
|
3821
|
-
if (typeof location === 'undefined' || typeof document === 'undefined') {
|
|
3822
|
-
return '';
|
|
3823
|
-
}
|
|
3824
|
-
const configElement = document.getElementById('Config');
|
|
3825
|
-
if (!configElement) {
|
|
3826
|
-
return '';
|
|
3827
|
-
}
|
|
3828
|
-
const text = configElement.textContent;
|
|
3829
|
-
if (!text) {
|
|
3830
|
-
return '';
|
|
3831
|
-
}
|
|
3832
|
-
const config = JSON.parse(text);
|
|
3833
|
-
return config[key] || '';
|
|
3834
|
-
};
|
|
3835
|
-
|
|
3836
3869
|
const getConfiguredRendererWorkerUrl = () => {
|
|
3837
3870
|
return getConfiguredWorkerUrl('rendererWorkerUrl');
|
|
3838
3871
|
};
|
|
@@ -3841,7 +3874,7 @@ const rendererWorkerUrl = getConfiguredRendererWorkerUrl() || `${assetDir}/packa
|
|
|
3841
3874
|
|
|
3842
3875
|
const getName = platform => {
|
|
3843
3876
|
switch (platform) {
|
|
3844
|
-
case Electron:
|
|
3877
|
+
case Electron$1:
|
|
3845
3878
|
return 'Renderer Worker (Electron)';
|
|
3846
3879
|
case Web:
|
|
3847
3880
|
return 'Renderer Worker (Web)';
|
|
@@ -4684,7 +4717,7 @@ const openUrl = (url, useRedirect = false) => {
|
|
|
4684
4717
|
};
|
|
4685
4718
|
|
|
4686
4719
|
const isElectronUserAgentSpecificMemoryError = error => {
|
|
4687
|
-
if (platform !== Electron) {
|
|
4720
|
+
if (platform !== Electron$1) {
|
|
4688
4721
|
return;
|
|
4689
4722
|
}
|
|
4690
4723
|
return error.message === `Failed to execute 'measureUserAgentSpecificMemory' on 'Performance': performance.measureUserAgentSpecificMemory is not available.`;
|
|
@@ -9877,7 +9910,7 @@ const forwardRendererWorkerCommand = (method, ...params) => {
|
|
|
9877
9910
|
send$1(method, ...params);
|
|
9878
9911
|
};
|
|
9879
9912
|
const handleMessagePort = async (port, rpcId) => {
|
|
9880
|
-
const rpc = await create$
|
|
9913
|
+
const rpc = await create$A({
|
|
9881
9914
|
commandMap: {
|
|
9882
9915
|
'Viewlet.forwardRendererWorkerCommand': forwardRendererWorkerCommand,
|
|
9883
9916
|
'Viewlet.queueCommands': queueCommands
|
|
@@ -10157,8 +10190,9 @@ const commandMap = {
|
|
|
10157
10190
|
'DirectView.getFocusedUid': getFocusedViewUid,
|
|
10158
10191
|
'DirectView.getUid': getViewUid,
|
|
10159
10192
|
'Download.downloadFile': downloadFile,
|
|
10160
|
-
'
|
|
10161
|
-
'
|
|
10193
|
+
'DragAndDrop.handleMessagePort': handleMessagePort$1,
|
|
10194
|
+
'DropData.get': get$5,
|
|
10195
|
+
'FileHandles.get': get$4,
|
|
10162
10196
|
'FilePicker.showDirectoryPicker': showDirectoryPicker,
|
|
10163
10197
|
'FilePicker.showFilePicker': showFilePicker,
|
|
10164
10198
|
'FilePicker.showSaveFilePicker': showSaveFilePicker,
|
|
@@ -10330,7 +10364,7 @@ const mergeCustom = (custom, relevantStack) => {
|
|
|
10330
10364
|
};
|
|
10331
10365
|
const cleanStack = stack => {
|
|
10332
10366
|
string(stack);
|
|
10333
|
-
const lines = splitLines
|
|
10367
|
+
const lines = splitLines(stack);
|
|
10334
10368
|
const {
|
|
10335
10369
|
actualStack,
|
|
10336
10370
|
custom
|
|
@@ -10380,7 +10414,7 @@ const prepareErrorMessageWithCodeFrame = error => {
|
|
|
10380
10414
|
}
|
|
10381
10415
|
const message = getErrorMessage(error);
|
|
10382
10416
|
const lines = cleanStack(error.stack);
|
|
10383
|
-
const relevantStack = joinLines
|
|
10417
|
+
const relevantStack = joinLines(lines);
|
|
10384
10418
|
if (error.codeFrame) {
|
|
10385
10419
|
return {
|
|
10386
10420
|
_error: error,
|
|
@@ -10599,19 +10633,19 @@ const hydrate = async () => {
|
|
|
10599
10633
|
return success(undefined);
|
|
10600
10634
|
};
|
|
10601
10635
|
|
|
10602
|
-
const
|
|
10636
|
+
const requiredWorkerFns = [hydrate$2, hydrate$4];
|
|
10637
|
+
const additionalWorkerFns = [hydrate$1, hydrate];
|
|
10603
10638
|
const call = fn => {
|
|
10604
10639
|
return fn();
|
|
10605
10640
|
};
|
|
10606
10641
|
const launchWorkers = async () => {
|
|
10607
|
-
|
|
10608
|
-
|
|
10609
|
-
|
|
10610
|
-
|
|
10611
|
-
|
|
10612
|
-
}
|
|
10613
|
-
return success(undefined);
|
|
10642
|
+
const workerFns = [...requiredWorkerFns, ...additionalWorkerFns] ;
|
|
10643
|
+
const results = await Promise.all(workerFns.map(call));
|
|
10644
|
+
const firstError = results.find(isError);
|
|
10645
|
+
if (firstError) {
|
|
10646
|
+
return firstError;
|
|
10614
10647
|
}
|
|
10648
|
+
return success(undefined);
|
|
10615
10649
|
};
|
|
10616
10650
|
|
|
10617
10651
|
const handleFocusIn = event => {
|