@pronto-tools-and-more/diff-process 8.18.0
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +23 -0
- package/src/diffProcessMain.js +3 -0
- package/src/parts/Callback/Callback.js +1 -0
- package/src/parts/Command/Command.js +9 -0
- package/src/parts/CommandMap/CommandMap.js +5 -0
- package/src/parts/CommandState/CommandState.js +17 -0
- package/src/parts/Diff/Diff.js +3 -0
- package/src/parts/HandleIpc/HandleIpc.js +10 -0
- package/src/parts/HandleMessage/HandleMessage.js +27 -0
- package/src/parts/Hash/Hash.js +10 -0
- package/src/parts/IpcChild/IpcChild.js +15 -0
- package/src/parts/IpcChildModule/IpcChildModule.js +25 -0
- package/src/parts/IpcChildType/IpcChildType.js +19 -0
- package/src/parts/JsonRpc/JsonRpc.js +1 -0
- package/src/parts/Listen/Listen.js +8 -0
- package/src/parts/Main/Main.js +8 -0
- package/src/parts/MurmurHash/MurmurHash.js +120 -0
package/package.json
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
{
|
2
|
+
"name": "@pronto-tools-and-more/diff-process",
|
3
|
+
"version": "8.18.0",
|
4
|
+
"description": "",
|
5
|
+
"main": "src/diffProcessMain.js",
|
6
|
+
"type": "module",
|
7
|
+
"scripts": {
|
8
|
+
"test": "node --unhandled-rejections=warn --experimental-vm-modules ./node_modules/jest/bin/jest.js --detectOpenHandles --forceExit",
|
9
|
+
"test:watch": "node --unhandled-rejections=warn --experimental-vm-modules ./node_modules/jest/bin/jest.js --watch",
|
10
|
+
"type-check": "tsc"
|
11
|
+
},
|
12
|
+
"keywords": [],
|
13
|
+
"author": "",
|
14
|
+
"license": "MIT",
|
15
|
+
"dependencies": {
|
16
|
+
"@lvce-editor/ipc": "^11.1.0",
|
17
|
+
"@lvce-editor/json-rpc": "^5.0.0"
|
18
|
+
},
|
19
|
+
"devDependencies": {
|
20
|
+
"@types/node": "^22.9.0",
|
21
|
+
"jest": "^29.7.0"
|
22
|
+
}
|
23
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export { resolve } from "@lvce-editor/json-rpc";
|
@@ -0,0 +1,17 @@
|
|
1
|
+
const state = {
|
2
|
+
commands: Object.create(null),
|
3
|
+
};
|
4
|
+
|
5
|
+
const registerCommand = (key, fn) => {
|
6
|
+
state.commands[key] = fn;
|
7
|
+
};
|
8
|
+
|
9
|
+
export const registerCommands = (commandMap) => {
|
10
|
+
for (const [key, value] of Object.entries(commandMap)) {
|
11
|
+
registerCommand(key, value);
|
12
|
+
}
|
13
|
+
};
|
14
|
+
|
15
|
+
export const getCommand = (key) => {
|
16
|
+
return state.commands[key];
|
17
|
+
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import * as HandleMessage from "../HandleMessage/HandleMessage.js";
|
2
|
+
|
3
|
+
export const handleIpc = (ipc) => {
|
4
|
+
if ("addEventListener" in ipc) {
|
5
|
+
ipc.addEventListener("message", HandleMessage.handleMessage);
|
6
|
+
} else if ("on" in ipc) {
|
7
|
+
// deprecated
|
8
|
+
ipc.on("message", HandleMessage.handleMessage);
|
9
|
+
}
|
10
|
+
};
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import * as Callback from "../Callback/Callback.js";
|
2
|
+
import * as Command from "../Command/Command.js";
|
3
|
+
import * as JsonRpc from "../JsonRpc/JsonRpc.js";
|
4
|
+
|
5
|
+
const prepare = (error) => {
|
6
|
+
return error;
|
7
|
+
};
|
8
|
+
|
9
|
+
const requiresSocket = (method) => {
|
10
|
+
return false;
|
11
|
+
};
|
12
|
+
|
13
|
+
const logError = (error, prettyError) => {
|
14
|
+
console.error(error);
|
15
|
+
};
|
16
|
+
|
17
|
+
export const handleMessage = (event) => {
|
18
|
+
return JsonRpc.handleJsonRpcMessage(
|
19
|
+
event.target,
|
20
|
+
event.data,
|
21
|
+
Command.execute,
|
22
|
+
Callback.resolve,
|
23
|
+
prepare,
|
24
|
+
logError,
|
25
|
+
requiresSocket,
|
26
|
+
);
|
27
|
+
};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import * as IpcChildModule from "../IpcChildModule/IpcChildModule.js";
|
2
|
+
|
3
|
+
export const listen = async ({ method, ...params }) => {
|
4
|
+
const module = await IpcChildModule.getModule(method);
|
5
|
+
// @ts-ignore
|
6
|
+
const rawIpc = await module.listen(params);
|
7
|
+
// @ts-ignore
|
8
|
+
if (module.signal) {
|
9
|
+
// @ts-ignore
|
10
|
+
module.signal(rawIpc);
|
11
|
+
}
|
12
|
+
// @ts-ignore
|
13
|
+
const ipc = module.wrap(rawIpc);
|
14
|
+
return ipc;
|
15
|
+
};
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import {
|
2
|
+
IpcChildWithElectronMessagePort,
|
3
|
+
IpcChildWithElectronUtilityProcess,
|
4
|
+
IpcChildWithNodeForkedProcess,
|
5
|
+
IpcChildWithNodeWorker,
|
6
|
+
IpcChildWithWebSocket,
|
7
|
+
} from "@lvce-editor/ipc";
|
8
|
+
import * as IpcChildType from "../IpcChildType/IpcChildType.js";
|
9
|
+
|
10
|
+
export const getModule = (method) => {
|
11
|
+
switch (method) {
|
12
|
+
case IpcChildType.NodeForkedProcess:
|
13
|
+
return IpcChildWithNodeForkedProcess;
|
14
|
+
case IpcChildType.NodeWorker:
|
15
|
+
return IpcChildWithNodeWorker;
|
16
|
+
case IpcChildType.ElectronUtilityProcess:
|
17
|
+
return IpcChildWithElectronUtilityProcess;
|
18
|
+
case IpcChildType.ElectronMessagePort:
|
19
|
+
return IpcChildWithElectronMessagePort;
|
20
|
+
case IpcChildType.WebSocket:
|
21
|
+
return IpcChildWithWebSocket;
|
22
|
+
default:
|
23
|
+
throw new Error("unexpected ipc type");
|
24
|
+
}
|
25
|
+
};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
export const NodeWorker = 1;
|
2
|
+
export const NodeForkedProcess = 2;
|
3
|
+
export const ElectronUtilityProcess = 3;
|
4
|
+
export const ElectronMessagePort = 4;
|
5
|
+
export const WebSocket = 6;
|
6
|
+
|
7
|
+
export const Auto = () => {
|
8
|
+
const { argv } = process;
|
9
|
+
if (argv.includes("--ipc-type=node-worker")) {
|
10
|
+
return NodeWorker;
|
11
|
+
}
|
12
|
+
if (argv.includes("--ipc-type=node-forked-process")) {
|
13
|
+
return NodeForkedProcess;
|
14
|
+
}
|
15
|
+
if (argv.includes("--ipc-type=electron-utility-process")) {
|
16
|
+
return ElectronUtilityProcess;
|
17
|
+
}
|
18
|
+
throw new Error(`[shared-process] unknown ipc type`);
|
19
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "@lvce-editor/json-rpc";
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import * as HandleIpc from "../HandleIpc/HandleIpc.js";
|
2
|
+
import * as IpcChild from "../IpcChild/IpcChild.js";
|
3
|
+
import * as IpcChildType from "../IpcChildType/IpcChildType.js";
|
4
|
+
|
5
|
+
export const listen = async () => {
|
6
|
+
const ipc = await IpcChild.listen({ method: IpcChildType.Auto() });
|
7
|
+
HandleIpc.handleIpc(ipc);
|
8
|
+
};
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import * as CommandMap from "../CommandMap/CommandMap.js";
|
2
|
+
import * as CommandState from "../CommandState/CommandState.js";
|
3
|
+
import * as Listen from "../Listen/Listen.js";
|
4
|
+
|
5
|
+
export const main = async () => {
|
6
|
+
CommandState.registerCommands(CommandMap.commandMap);
|
7
|
+
await Listen.listen();
|
8
|
+
};
|
@@ -0,0 +1,120 @@
|
|
1
|
+
/* Public Domain MurmurHash3 implementation. Altered to have AMD header and function wrapper. */
|
2
|
+
|
3
|
+
/*
|
4
|
+
* The MurmurHash3 algorithm was created by Austin Appleby. This JavaScript port was authored
|
5
|
+
* by Peter Zotov (based on Java port by Yonik Seeley) and is placed into the public domain.
|
6
|
+
* The author hereby disclaims copyright to this source code.
|
7
|
+
*
|
8
|
+
* This produces exactly the same hash values as the final C++ version of MurmurHash3 and
|
9
|
+
* is thus suitable for producing the same hash values across platforms.
|
10
|
+
*
|
11
|
+
* There are two versions of this hash implementation. First interprets the string as a
|
12
|
+
* sequence of bytes, ignoring most significant byte of each codepoint. The second one
|
13
|
+
* interprets the string as a UTF-16 codepoint sequence, and appends each 16-bit codepoint
|
14
|
+
* to the hash independently. The latter mode was not written to be compatible with
|
15
|
+
* any other implementation, but it should offer better performance for JavaScript-only
|
16
|
+
* applications.
|
17
|
+
*
|
18
|
+
* See http://github.com/whitequark/murmurhash3-js for future updates to this file.
|
19
|
+
*/
|
20
|
+
|
21
|
+
export const MurmurHash3 = {
|
22
|
+
mul32(m, n) {
|
23
|
+
const nlo = n & 0xffff;
|
24
|
+
const nhi = n - nlo;
|
25
|
+
return (((nhi * m) | 0) + ((nlo * m) | 0)) | 0;
|
26
|
+
},
|
27
|
+
|
28
|
+
hashBytes(data, len, seed) {
|
29
|
+
const c1 = 0xcc9e2d51;
|
30
|
+
const c2 = 0x1b873593;
|
31
|
+
|
32
|
+
let h1 = seed;
|
33
|
+
const roundedEnd = len & ~0x3;
|
34
|
+
|
35
|
+
for (let i = 0; i < roundedEnd; i += 4) {
|
36
|
+
var k1 =
|
37
|
+
(data.charCodeAt(i) & 0xff) |
|
38
|
+
((data.charCodeAt(i + 1) & 0xff) << 8) |
|
39
|
+
((data.charCodeAt(i + 2) & 0xff) << 16) |
|
40
|
+
((data.charCodeAt(i + 3) & 0xff) << 24);
|
41
|
+
|
42
|
+
k1 = this.mul32(k1, c1);
|
43
|
+
k1 = ((k1 & 0x1ffff) << 15) | (k1 >>> 17); // ROTL32(k1,15);
|
44
|
+
k1 = this.mul32(k1, c2);
|
45
|
+
|
46
|
+
h1 ^= k1;
|
47
|
+
h1 = ((h1 & 0x7ffff) << 13) | (h1 >>> 19); // ROTL32(h1,13);
|
48
|
+
h1 = (h1 * 5 + 0xe6546b64) | 0;
|
49
|
+
}
|
50
|
+
|
51
|
+
k1 = 0;
|
52
|
+
|
53
|
+
switch (len % 4) {
|
54
|
+
case 3:
|
55
|
+
k1 = (data.charCodeAt(roundedEnd + 2) & 0xff) << 16;
|
56
|
+
// Fallthrough
|
57
|
+
case 2:
|
58
|
+
k1 |= (data.charCodeAt(roundedEnd + 1) & 0xff) << 8;
|
59
|
+
// Fallthrough
|
60
|
+
case 1:
|
61
|
+
k1 |= data.charCodeAt(roundedEnd) & 0xff;
|
62
|
+
k1 = this.mul32(k1, c1);
|
63
|
+
k1 = ((k1 & 0x1ffff) << 15) | (k1 >>> 17); // ROTL32(k1,15);
|
64
|
+
k1 = this.mul32(k1, c2);
|
65
|
+
h1 ^= k1;
|
66
|
+
}
|
67
|
+
|
68
|
+
// Finalization
|
69
|
+
h1 ^= len;
|
70
|
+
|
71
|
+
// Fmix(h1);
|
72
|
+
h1 ^= h1 >>> 16;
|
73
|
+
h1 = this.mul32(h1, 0x85ebca6b);
|
74
|
+
h1 ^= h1 >>> 13;
|
75
|
+
h1 = this.mul32(h1, 0xc2b2ae35);
|
76
|
+
h1 ^= h1 >>> 16;
|
77
|
+
|
78
|
+
return h1;
|
79
|
+
},
|
80
|
+
|
81
|
+
hashString(data, len, seed) {
|
82
|
+
const c1 = 0xcc9e2d51;
|
83
|
+
const c2 = 0x1b873593;
|
84
|
+
|
85
|
+
let h1 = seed;
|
86
|
+
const roundedEnd = len & ~0x1;
|
87
|
+
|
88
|
+
for (let i = 0; i < roundedEnd; i += 2) {
|
89
|
+
var k1 = data.charCodeAt(i) | (data.charCodeAt(i + 1) << 16);
|
90
|
+
|
91
|
+
k1 = this.mul32(k1, c1);
|
92
|
+
k1 = ((k1 & 0x1ffff) << 15) | (k1 >>> 17); // ROTL32(k1,15);
|
93
|
+
k1 = this.mul32(k1, c2);
|
94
|
+
|
95
|
+
h1 ^= k1;
|
96
|
+
h1 = ((h1 & 0x7ffff) << 13) | (h1 >>> 19); // ROTL32(h1,13);
|
97
|
+
h1 = (h1 * 5 + 0xe6546b64) | 0;
|
98
|
+
}
|
99
|
+
|
100
|
+
if (len % 2 == 1) {
|
101
|
+
k1 = data.charCodeAt(roundedEnd);
|
102
|
+
k1 = this.mul32(k1, c1);
|
103
|
+
k1 = ((k1 & 0x1ffff) << 15) | (k1 >>> 17); // ROTL32(k1,15);
|
104
|
+
k1 = this.mul32(k1, c2);
|
105
|
+
h1 ^= k1;
|
106
|
+
}
|
107
|
+
|
108
|
+
// Finalization
|
109
|
+
h1 ^= len << 1;
|
110
|
+
|
111
|
+
// Fmix(h1);
|
112
|
+
h1 ^= h1 >>> 16;
|
113
|
+
h1 = this.mul32(h1, 0x85ebca6b);
|
114
|
+
h1 ^= h1 >>> 13;
|
115
|
+
h1 = this.mul32(h1, 0xc2b2ae35);
|
116
|
+
h1 ^= h1 >>> 16;
|
117
|
+
|
118
|
+
return h1;
|
119
|
+
},
|
120
|
+
};
|