ewvjs 1.0.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.
Files changed (89) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +168 -0
  3. package/bin/ewvjs-cli.js +318 -0
  4. package/dist/index.d.ts +10 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +76 -0
  7. package/dist/js/api.js +256 -0
  8. package/dist/platforms/windows.d.ts +5 -0
  9. package/dist/platforms/windows.d.ts.map +1 -0
  10. package/dist/platforms/windows.js +143 -0
  11. package/dist/types.d.ts +42 -0
  12. package/dist/types.d.ts.map +1 -0
  13. package/dist/types.js +2 -0
  14. package/dist/utils.d.ts +9 -0
  15. package/dist/utils.d.ts.map +1 -0
  16. package/dist/utils.js +22 -0
  17. package/dist/webview.d.ts +20 -0
  18. package/dist/webview.d.ts.map +1 -0
  19. package/dist/webview.js +92 -0
  20. package/dist/window.d.ts +55 -0
  21. package/dist/window.d.ts.map +1 -0
  22. package/dist/window.js +307 -0
  23. package/lib/assets.js +129 -0
  24. package/lib/icon.js +150 -0
  25. package/lib/packager.js +347 -0
  26. package/native/Microsoft.Web.WebView2.Core.dll +0 -0
  27. package/native/Microsoft.Web.WebView2.WinForms.dll +0 -0
  28. package/native/Microsoft.Web.WebView2.Wpf.dll +0 -0
  29. package/native/WebView.cjs +26 -0
  30. package/native/WebView.d.ts +8 -0
  31. package/native/WebView.deps.json +260 -0
  32. package/native/WebView.dll +0 -0
  33. package/native/WebView.mjs +31 -0
  34. package/native/import.cjs +3 -0
  35. package/native/node_modules/node-api-dotnet/README.md +80 -0
  36. package/native/node_modules/node-api-dotnet/index.d.ts +98 -0
  37. package/native/node_modules/node-api-dotnet/index.js +2 -0
  38. package/native/node_modules/node-api-dotnet/init.js +80 -0
  39. package/native/node_modules/node-api-dotnet/linux-arm64/Microsoft.JavaScript.NodeApi.node +0 -0
  40. package/native/node_modules/node-api-dotnet/linux-x64/Microsoft.JavaScript.NodeApi.node +0 -0
  41. package/native/node_modules/node-api-dotnet/net10.0/Microsoft.JavaScript.NodeApi.DotNetHost.dll +0 -0
  42. package/native/node_modules/node-api-dotnet/net10.0/Microsoft.JavaScript.NodeApi.dll +0 -0
  43. package/native/node_modules/node-api-dotnet/net10.0/Microsoft.JavaScript.NodeApi.runtimeconfig.json +14 -0
  44. package/native/node_modules/node-api-dotnet/net10.0.js +2 -0
  45. package/native/node_modules/node-api-dotnet/net472/Microsoft.Bcl.AsyncInterfaces.dll +0 -0
  46. package/native/node_modules/node-api-dotnet/net472/Microsoft.JavaScript.NodeApi.DotNetHost.dll +0 -0
  47. package/native/node_modules/node-api-dotnet/net472/Microsoft.JavaScript.NodeApi.dll +0 -0
  48. package/native/node_modules/node-api-dotnet/net472/Microsoft.JavaScript.NodeApi.runtimeconfig.json +9 -0
  49. package/native/node_modules/node-api-dotnet/net472/System.Memory.dll +0 -0
  50. package/native/node_modules/node-api-dotnet/net472/System.Runtime.CompilerServices.Unsafe.dll +0 -0
  51. package/native/node_modules/node-api-dotnet/net472/System.Threading.Tasks.Extensions.dll +0 -0
  52. package/native/node_modules/node-api-dotnet/net472.d.ts +2 -0
  53. package/native/node_modules/node-api-dotnet/net472.js +2 -0
  54. package/native/node_modules/node-api-dotnet/net8.0/Microsoft.JavaScript.NodeApi.DotNetHost.dll +0 -0
  55. package/native/node_modules/node-api-dotnet/net8.0/Microsoft.JavaScript.NodeApi.dll +0 -0
  56. package/native/node_modules/node-api-dotnet/net8.0/Microsoft.JavaScript.NodeApi.runtimeconfig.json +14 -0
  57. package/native/node_modules/node-api-dotnet/net8.0.d.ts +2 -0
  58. package/native/node_modules/node-api-dotnet/net8.0.js +2 -0
  59. package/native/node_modules/node-api-dotnet/net9.0/Microsoft.JavaScript.NodeApi.DotNetHost.dll +0 -0
  60. package/native/node_modules/node-api-dotnet/net9.0/Microsoft.JavaScript.NodeApi.dll +0 -0
  61. package/native/node_modules/node-api-dotnet/net9.0/Microsoft.JavaScript.NodeApi.runtimeconfig.json +14 -0
  62. package/native/node_modules/node-api-dotnet/net9.0.d.ts +2 -0
  63. package/native/node_modules/node-api-dotnet/net9.0.js +2 -0
  64. package/native/node_modules/node-api-dotnet/osx-arm64/Microsoft.JavaScript.NodeApi.node +0 -0
  65. package/native/node_modules/node-api-dotnet/osx-x64/Microsoft.JavaScript.NodeApi.node +0 -0
  66. package/native/node_modules/node-api-dotnet/package.json +27 -0
  67. package/native/node_modules/node-api-dotnet/win-arm64/Microsoft.JavaScript.NodeApi.node +0 -0
  68. package/native/node_modules/node-api-dotnet/win-x64/Microsoft.JavaScript.NodeApi.node +0 -0
  69. package/native/runtimes/win-arm64/native/WebView2Loader.dll +0 -0
  70. package/native/runtimes/win-x64/native/WebView2Loader.dll +0 -0
  71. package/native/runtimes/win-x86/native/WebView2Loader.dll +0 -0
  72. package/package.json +57 -0
  73. package/src/README.md +125 -0
  74. package/src/csharp/bin/Release/net10.0-windows/Microsoft.Web.WebView2.Core.dll +0 -0
  75. package/src/csharp/bin/Release/net10.0-windows/Microsoft.Web.WebView2.Core.xml +6817 -0
  76. package/src/csharp/bin/Release/net10.0-windows/Microsoft.Web.WebView2.WinForms.dll +0 -0
  77. package/src/csharp/bin/Release/net10.0-windows/Microsoft.Web.WebView2.WinForms.xml +510 -0
  78. package/src/csharp/bin/Release/net10.0-windows/Microsoft.Web.WebView2.Wpf.dll +0 -0
  79. package/src/csharp/bin/Release/net10.0-windows/Microsoft.Web.WebView2.Wpf.xml +1902 -0
  80. package/src/csharp/bin/Release/net10.0-windows/WebView.cjs +26 -0
  81. package/src/csharp/bin/Release/net10.0-windows/WebView.d.ts +8 -0
  82. package/src/csharp/bin/Release/net10.0-windows/WebView.deps.json +260 -0
  83. package/src/csharp/bin/Release/net10.0-windows/WebView.dll +0 -0
  84. package/src/csharp/bin/Release/net10.0-windows/WebView.mjs +31 -0
  85. package/src/csharp/bin/Release/net10.0-windows/WebView.pdb +0 -0
  86. package/src/csharp/bin/Release/net10.0-windows/import.cjs +3 -0
  87. package/src/csharp/bin/Release/net10.0-windows/runtimes/win-arm64/native/WebView2Loader.dll +0 -0
  88. package/src/csharp/bin/Release/net10.0-windows/runtimes/win-x64/native/WebView2Loader.dll +0 -0
  89. package/src/csharp/bin/Release/net10.0-windows/runtimes/win-x86/native/WebView2Loader.dll +0 -0
package/dist/js/api.js ADDED
@@ -0,0 +1,256 @@
1
+ window.ewvjs = {
2
+ token: '%(token)s',
3
+ platform: 'edgechromium',
4
+ api: {},
5
+ _eventHandlers: {},
6
+ _returnValuesCallbacks: {},
7
+
8
+ _hookDrag: function () {
9
+ window.addEventListener('mousedown', function (e) {
10
+ if (e.target.classList.contains('ewvjs-drag-region') || e.target.closest('.ewvjs-drag-region')) {
11
+ if (e.button === 0) { // Left click
12
+ window.chrome.webview.postMessage("drag");
13
+ }
14
+ }
15
+ });
16
+ },
17
+
18
+ _createApi: function (funcList) {
19
+ function sanitize_params(params) {
20
+ var reservedWords = [
21
+ 'case',
22
+ 'catch',
23
+ 'const',
24
+ 'debugger',
25
+ 'default',
26
+ 'delete',
27
+ 'do',
28
+ 'export',
29
+ 'extends',
30
+ 'false',
31
+ 'function',
32
+ 'instanceof',
33
+ 'let',
34
+ 'new',
35
+ 'null',
36
+ 'super',
37
+ 'switch',
38
+ 'this',
39
+ 'throw',
40
+ 'true',
41
+ 'typeof',
42
+ 'var',
43
+ 'void',
44
+ ];
45
+
46
+ for (var i = 0; i < params.length; i++) {
47
+ var param = params[i];
48
+ if (reservedWords.indexOf(param) !== -1) {
49
+ params[i] = param + '_';
50
+ }
51
+ }
52
+
53
+ return params;
54
+ }
55
+
56
+ for (var i = 0; i < funcList.length; i++) {
57
+ var element = funcList[i];
58
+ var funcName = element.func;
59
+ var params = element.params;
60
+
61
+ var funcHierarchy = funcName.split('.');
62
+ var functionName = funcHierarchy.pop();
63
+ var nestedObject = funcHierarchy.reduce(function (obj, prop) {
64
+ if (!obj[prop]) {
65
+ obj[prop] = {};
66
+ }
67
+ return obj[prop];
68
+ }, window.ewvjs.api);
69
+
70
+ var funcBody =
71
+ 'var __id = (Math.random() + "").substring(2);' +
72
+ 'var promise = new Promise(function(resolve, reject) {' +
73
+ ' window.ewvjs._checkValue("' +
74
+ funcName +
75
+ '", resolve, reject, __id);' +
76
+ '});' +
77
+ 'window.ewvjs._jsApiCallback("' +
78
+ funcName +
79
+ '", Array.prototype.slice.call(arguments), __id);' +
80
+ 'return promise;';
81
+
82
+ nestedObject[functionName] = new Function(
83
+ sanitize_params(params),
84
+ funcBody
85
+ );
86
+ window.ewvjs._returnValuesCallbacks[funcName] = {};
87
+ }
88
+ },
89
+
90
+ _jsApiCallback: function (funcName, params, id) {
91
+ if (
92
+ params.event instanceof Event &&
93
+ params.event.type === 'drop' &&
94
+ params.event.dataTransfer.files
95
+ ) {
96
+ chrome.webview.postMessageWithAdditionalObjects(
97
+ 'FilesDropped',
98
+ params.event.dataTransfer.files
99
+ );
100
+ }
101
+ return window.chrome.webview.postMessage([
102
+ funcName,
103
+ window.ewvjs.stringify(params),
104
+ id,
105
+ ]);
106
+ },
107
+
108
+ _checkValue: function (funcName, resolve, reject, id) {
109
+ window.ewvjs._returnValuesCallbacks[funcName][id] = function (returnObj) {
110
+ var value = returnObj.value;
111
+ var isError = returnObj.isError;
112
+
113
+ delete window.ewvjs._returnValuesCallbacks[funcName][id];
114
+
115
+ if (isError) {
116
+ var pyError = JSON.parse(value);
117
+ var error = new Error(pyError.message);
118
+ error.name = pyError.name;
119
+ error.stack = pyError.stack;
120
+
121
+ reject(error);
122
+ } else {
123
+ resolve(JSON.parse(value));
124
+ }
125
+ };
126
+ },
127
+ _asyncCallback: function (result, id) {
128
+ window.ewvjs._jsApiCallback('ewvjsAsyncCallback', result, id);
129
+ },
130
+ _isPromise: function (obj) {
131
+ return (
132
+ !!obj &&
133
+ (typeof obj === 'object' || typeof obj === 'function') &&
134
+ typeof obj.then === 'function'
135
+ );
136
+ },
137
+
138
+ stringify: function stringify(obj, timing) {
139
+ function tryConvertToArray(obj) {
140
+ try {
141
+ return Array.prototype.slice.call(obj);
142
+ } catch (e) {
143
+ return obj;
144
+ }
145
+ }
146
+
147
+ function isArrayLike(a) {
148
+ return (
149
+ a &&
150
+ typeof a.length === 'number' &&
151
+ typeof a !== 'string' &&
152
+ (Array.isArray(a) ||
153
+ (typeof a === 'object' &&
154
+ a.length >= 0 &&
155
+ (a.length === 0 || (a.length - 1) in a)))
156
+ );
157
+ }
158
+
159
+ function serialize(obj, ancestors) {
160
+ try {
161
+ if (obj instanceof Window) return 'Window';
162
+ if (obj instanceof Node) {
163
+ return 'Node';
164
+ }
165
+
166
+ var boundSerialize = serialize.bind(obj);
167
+
168
+ if (typeof obj !== 'object' || obj === null) {
169
+ return obj;
170
+ }
171
+
172
+ while (
173
+ ancestors.length > 0 &&
174
+ ancestors[ancestors.length - 1] !== this
175
+ ) {
176
+ ancestors.pop();
177
+ }
178
+
179
+ if (ancestors.indexOf(obj) > -1) {
180
+ return '[Circular Reference]';
181
+ }
182
+ ancestors.push(obj);
183
+
184
+ if (isArrayLike(obj)) {
185
+ obj = tryConvertToArray(obj);
186
+ }
187
+
188
+ if (Array.isArray(obj)) {
189
+ var arr = obj.map(function (value) {
190
+ return boundSerialize(value, ancestors);
191
+ });
192
+ return arr;
193
+ }
194
+
195
+ var newObj = {};
196
+ for (var key in obj) {
197
+ if (typeof obj === 'function') {
198
+ continue;
199
+ }
200
+ newObj[key] = boundSerialize(obj[key], ancestors);
201
+ }
202
+ return newObj;
203
+ } catch (e) {
204
+ console.error(e);
205
+ return e.toString();
206
+ }
207
+ }
208
+
209
+ var startTime = +new Date();
210
+
211
+ var _serialize = serialize.bind(null);
212
+ var finalObj = _serialize(obj, []);
213
+ var result = JSON.stringify(finalObj);
214
+
215
+ var endTime = +new Date();
216
+ if (timing) {
217
+ console.log('Serialization time: ' + (endTime - startTime) / 1000 + 's');
218
+ }
219
+ return result;
220
+ },
221
+
222
+ _loadCss: function (css) {
223
+ var interval = setInterval(function () {
224
+ if (document.readyState === 'complete') {
225
+ clearInterval(interval);
226
+
227
+ var cssElement = document.createElement('style');
228
+ cssElement.type = 'text/css';
229
+ cssElement.innerHTML = css;
230
+ document.head.appendChild(cssElement);
231
+ }
232
+ }, 10);
233
+ },
234
+ };
235
+
236
+ window.ewvjs._hookConsole = function () {
237
+ var console = window.console;
238
+ if (!console) return;
239
+ function intercept(method) {
240
+ var original = console[method];
241
+ console[method] = function () {
242
+ var args = Array.prototype.slice.call(arguments);
243
+ window.chrome.webview.postMessage([
244
+ "console",
245
+ JSON.stringify(args),
246
+ "0"
247
+ ]);
248
+ original.apply(console, arguments);
249
+ };
250
+ }
251
+ var methods = ['log', 'warn', 'error'];
252
+ for (var i = 0; i < methods.length; i++) intercept(methods[i]);
253
+ };
254
+
255
+ window.ewvjs._hookConsole();
256
+ window.ewvjs._hookDrag();
@@ -0,0 +1,5 @@
1
+ export declare class WindowsPlatform {
2
+ constructor();
3
+ createWindow(options: any): any;
4
+ }
5
+ //# sourceMappingURL=windows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"windows.d.ts","sourceRoot":"","sources":["../../src/platforms/windows.ts"],"names":[],"mappings":"AAIA,qBAAa,eAAe;;IAKxB,YAAY,CAAC,OAAO,EAAE,GAAG;CA6G5B"}
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.WindowsPlatform = void 0;
37
+ const path = __importStar(require("path"));
38
+ const fs = __importStar(require("fs"));
39
+ const Module = __importStar(require("module"));
40
+ class WindowsPlatform {
41
+ constructor() {
42
+ }
43
+ createWindow(options) {
44
+ // Detect if running as packaged executable (pkg) or in development
45
+ const isPkg = typeof process.pkg !== 'undefined';
46
+ let dllDir;
47
+ let apiPath;
48
+ if (isPkg) {
49
+ // When packaged with pkg, native DLLs are next to the executable
50
+ const execDir = path.dirname(process.execPath);
51
+ dllDir = path.join(execDir, 'native');
52
+ // api.js is bundled in the snapshot, use snapshot path
53
+ apiPath = path.resolve(__dirname, '../js/api.js');
54
+ }
55
+ else {
56
+ // Development mode: use relative paths from compiled location
57
+ dllDir = path.resolve(__dirname, '../../native');
58
+ apiPath = path.resolve(__dirname, '../js/api.js');
59
+ }
60
+ // Ensure WebView2Loader.dll and others are found
61
+ const arch = process.arch;
62
+ const winArch = arch === 'ia32' ? 'win-x86' : `win-${arch}`;
63
+ const runtimePath = path.join(dllDir, 'runtimes', winArch, 'native');
64
+ process.env.PATH = `${dllDir};${runtimePath};${process.env.PATH}`;
65
+ // Set up module resolution for node-api-dotnet BEFORE requiring WebView.cjs
66
+ const nodeModulesPath = path.join(dllDir, 'node_modules');
67
+ if (fs.existsSync(nodeModulesPath)) {
68
+ const existingNodePath = process.env.NODE_PATH || '';
69
+ process.env.NODE_PATH = existingNodePath
70
+ ? `${nodeModulesPath};${existingNodePath}`
71
+ : nodeModulesPath;
72
+ // Add to global module paths so it's available for all requires
73
+ const ModuleConstructor = Module;
74
+ if (ModuleConstructor.globalPaths && Array.isArray(ModuleConstructor.globalPaths)) {
75
+ if (!ModuleConstructor.globalPaths.includes(nodeModulesPath)) {
76
+ ModuleConstructor.globalPaths.unshift(nodeModulesPath);
77
+ }
78
+ }
79
+ }
80
+ // Load the node-api-dotnet module
81
+ let EwvjsInterop;
82
+ try {
83
+ const nativeModule = require(path.join(dllDir, 'WebView.cjs'));
84
+ EwvjsInterop = nativeModule.EwvjsInterop;
85
+ }
86
+ catch (e) {
87
+ console.error("Failed to load native module from " + dllDir, e);
88
+ throw e;
89
+ }
90
+ // Prepare initScript
91
+ const token = Math.random().toString(36).substring(2, 15);
92
+ let apiScript = fs.readFileSync(apiPath, 'utf8');
93
+ apiScript = apiScript.replace('%(token)s', token);
94
+ options.initScript = apiScript;
95
+ // Handle messages from WebView
96
+ // options.onMessage will be called by C#
97
+ // We must keep the Node process alive while the window is open, similar to how edge-js performed.
98
+ const keepAlive = setInterval(() => { }, 5000);
99
+ options.onMessage = (message, callback) => {
100
+ // Check for close message to clear keepAlive
101
+ // Message from C# on close is explicit string: "[\"closed\", \"\"]"
102
+ if (message === '["closed", ""]' || (Array.isArray(message) && message[0] === 'closed')) {
103
+ clearInterval(keepAlive);
104
+ }
105
+ if (typeof message === 'string') {
106
+ try {
107
+ message = JSON.parse(message);
108
+ }
109
+ catch (e) {
110
+ // Ignore parsing error, maybe it's just a string message
111
+ }
112
+ }
113
+ if (options.jsCallback) {
114
+ // Call jsCallback and handle the result
115
+ const result = options.jsCallback(message);
116
+ // If there's a callback (for messages that expect responses like context menu)
117
+ if (callback) {
118
+ if (result && typeof result.then === 'function') {
119
+ // Handle promise
120
+ result.then((res) => {
121
+ // Serialize result to JSON string for C#
122
+ const jsonResult = res ? JSON.stringify(res) : null;
123
+ callback(null, jsonResult);
124
+ }, (err) => callback(err, null));
125
+ }
126
+ else {
127
+ // Handle synchronous result
128
+ const jsonResult = result ? JSON.stringify(result) : null;
129
+ callback(null, jsonResult);
130
+ }
131
+ }
132
+ }
133
+ };
134
+ try {
135
+ return EwvjsInterop.invoke(options);
136
+ }
137
+ catch (e) {
138
+ console.error("TS: Invoke failed:", e);
139
+ throw e;
140
+ }
141
+ }
142
+ }
143
+ exports.WindowsPlatform = WindowsPlatform;
@@ -0,0 +1,42 @@
1
+ export interface ContextMenuItem {
2
+ label?: string;
3
+ id?: string;
4
+ type?: 'normal' | 'separator' | 'checkbox' | 'submenu';
5
+ checked?: boolean;
6
+ enabled?: boolean;
7
+ submenu?: ContextMenuItem[];
8
+ click?: () => void;
9
+ }
10
+ export interface WindowOptions {
11
+ title?: string;
12
+ url?: string;
13
+ html?: string;
14
+ width?: number;
15
+ height?: number;
16
+ x?: number;
17
+ y?: number;
18
+ resizable?: boolean;
19
+ fullscreen?: boolean;
20
+ hidden?: boolean;
21
+ frameless?: boolean;
22
+ focus?: boolean;
23
+ minimized?: boolean;
24
+ maximized?: boolean;
25
+ on_top?: boolean;
26
+ confirm_close?: boolean;
27
+ background_color?: string;
28
+ transparent?: boolean;
29
+ vibrancy?: boolean;
30
+ dark_mode?: boolean;
31
+ title_bar?: boolean;
32
+ icon?: string;
33
+ session?: {
34
+ persist?: boolean;
35
+ path?: string;
36
+ envname?: string;
37
+ };
38
+ additional_args?: string;
39
+ jsCallback?: (message: any) => void;
40
+ debug?: boolean;
41
+ }
42
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAA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ACzB,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;IACpC,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Extracts parameter names from a function
3
+ */
4
+ export declare function getParamNames(func: Function): string[];
5
+ /**
6
+ * Generates a random ID for menu items
7
+ */
8
+ export declare function generateId(): string;
9
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,EAAE,CAOtD;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAEnC"}
package/dist/utils.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getParamNames = getParamNames;
4
+ exports.generateId = generateId;
5
+ /**
6
+ * Extracts parameter names from a function
7
+ */
8
+ function getParamNames(func) {
9
+ const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
10
+ const ARGUMENT_NAMES = /([^\s,]+)/g;
11
+ const fnStr = func.toString().replace(STRIP_COMMENTS, '');
12
+ const result = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(ARGUMENT_NAMES);
13
+ if (result === null)
14
+ return [];
15
+ return Array.from(result);
16
+ }
17
+ /**
18
+ * Generates a random ID for menu items
19
+ */
20
+ function generateId() {
21
+ return `menu_item_${Math.random().toString(36).substr(2, 9)}`;
22
+ }
@@ -0,0 +1,20 @@
1
+ import { Window } from './window';
2
+ import { WindowOptions } from './types';
3
+ export declare class WebView {
4
+ platform: any;
5
+ exposed_functions: {
6
+ [key: string]: Function;
7
+ };
8
+ private _windows;
9
+ private _startPromise;
10
+ private _resolveStart;
11
+ private _heartbeat;
12
+ constructor();
13
+ create_window(title: string, url_or_html?: string, options?: Partial<WindowOptions>): Window;
14
+ start(): Promise<void>;
15
+ private _cleanup;
16
+ expose(name: string, func: Function): void;
17
+ _handle_message(message: any): Promise<void>;
18
+ private _buildWindowOptions;
19
+ }
20
+ //# sourceMappingURL=webview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webview.d.ts","sourceRoot":"","sources":["../src/webview.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,qBAAa,OAAO;IAChB,QAAQ,EAAE,GAAG,CAAC;IACd,iBAAiB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;KAAE,CAAM;IACpD,OAAO,CAAC,QAAQ,CAA0B;IAC1C,OAAO,CAAC,aAAa,CAA8B;IACnD,OAAO,CAAC,aAAa,CAA6B;IAClD,OAAO,CAAC,UAAU,CAA+B;;IAUjD,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,GAAE,MAAW,EAAE,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM,GAAG,MAAM;IAgB9F,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAa5B,OAAO,CAAC,QAAQ;IAgBhB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,IAAI;IAIpC,eAAe,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,OAAO,CAAC,mBAAmB;CA2B9B"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.WebView = void 0;
13
+ const windows_1 = require("./platforms/windows");
14
+ const window_1 = require("./window");
15
+ class WebView {
16
+ constructor() {
17
+ this.exposed_functions = {};
18
+ this._windows = new Set();
19
+ this._startPromise = null;
20
+ this._resolveStart = null;
21
+ this._heartbeat = null;
22
+ if (process.platform === 'win32') {
23
+ this.platform = new windows_1.WindowsPlatform();
24
+ }
25
+ else {
26
+ throw new Error('Platform not supported: ' + process.platform);
27
+ }
28
+ }
29
+ create_window(title, url_or_html = '', options = {}) {
30
+ const opts = this._buildWindowOptions(title, url_or_html, options);
31
+ const window = new window_1.Window(this.platform, opts, this.exposed_functions);
32
+ this._windows.add(window);
33
+ window.closed.then(() => {
34
+ this._windows.delete(window);
35
+ if (this._windows.size === 0) {
36
+ this._cleanup();
37
+ }
38
+ });
39
+ return window;
40
+ }
41
+ start() {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ if (this._windows.size === 0)
44
+ return;
45
+ // Keep process alive while windows are open
46
+ this._heartbeat = setInterval(() => { }, 1000);
47
+ this._startPromise = new Promise((resolve) => {
48
+ this._resolveStart = resolve;
49
+ });
50
+ return this._startPromise;
51
+ });
52
+ }
53
+ _cleanup() {
54
+ if (this._heartbeat) {
55
+ clearInterval(this._heartbeat);
56
+ this._heartbeat = null;
57
+ }
58
+ if (this._resolveStart) {
59
+ this._resolveStart();
60
+ this._resolveStart = null;
61
+ }
62
+ // Force exit after a short delay to ensure cleanup completes
63
+ setTimeout(() => {
64
+ process.exit(0);
65
+ }, 100);
66
+ }
67
+ expose(name, func) {
68
+ this.exposed_functions[name] = func;
69
+ }
70
+ _handle_message(message) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ if (!message)
73
+ return;
74
+ });
75
+ }
76
+ _buildWindowOptions(title, url_or_html, options) {
77
+ var _a, _b, _c;
78
+ const opts = Object.assign({ title: title, width: options.width || 800, height: options.height || 600, resizable: options.resizable !== undefined ? options.resizable : true, session: {
79
+ persist: ((_a = options.session) === null || _a === void 0 ? void 0 : _a.persist) !== undefined ? options.session.persist : true,
80
+ path: (_b = options.session) === null || _b === void 0 ? void 0 : _b.path,
81
+ envname: (_c = options.session) === null || _c === void 0 ? void 0 : _c.envname
82
+ }, jsCallback: this._handle_message.bind(this) }, options);
83
+ if (url_or_html.startsWith('http') || url_or_html.startsWith('data:')) {
84
+ opts.url = url_or_html;
85
+ }
86
+ else {
87
+ opts.html = url_or_html;
88
+ }
89
+ return opts;
90
+ }
91
+ }
92
+ exports.WebView = WebView;
@@ -0,0 +1,55 @@
1
+ import { ContextMenuItem, WindowOptions } from './types';
2
+ export declare class Window {
3
+ platform: any;
4
+ options: WindowOptions;
5
+ private controller;
6
+ private _closedPromise;
7
+ private _resolveClosed;
8
+ private _menuCallbacks;
9
+ private _exposedFunctions;
10
+ on_context_menu: (items: any[]) => ContextMenuItem[] | null | Promise<ContextMenuItem[] | null>;
11
+ constructor(platform: any, options: WindowOptions, exposedFunctions: {
12
+ [key: string]: Function;
13
+ });
14
+ get closed(): Promise<void>;
15
+ run(): Promise<any>;
16
+ private _call;
17
+ evaluate_js(script: string): Promise<any>;
18
+ evaluate(script: string): Promise<any>;
19
+ close(): Promise<any>;
20
+ destroy(): Promise<any>;
21
+ maximize(): Promise<any>;
22
+ restore(): Promise<any>;
23
+ minimize(): Promise<any>;
24
+ focus(): Promise<any>;
25
+ blur(): Promise<any>;
26
+ show(): Promise<any>;
27
+ hide(): Promise<any>;
28
+ getSize(): Promise<any>;
29
+ setSize(width: number, height: number): Promise<any>;
30
+ resize(width: number, height: number): Promise<any>;
31
+ getPosition(): Promise<any>;
32
+ setPosition(x: number, y: number): Promise<any>;
33
+ move(x: number, y: number): Promise<any>;
34
+ get_position(): Promise<any>;
35
+ set_position(x: number, y: number): Promise<any>;
36
+ get_width(): Promise<number>;
37
+ get_height(): Promise<number>;
38
+ setTitle(title: string): Promise<any>;
39
+ set_title(title: string): Promise<any>;
40
+ show_titlebar(): Promise<any>;
41
+ hide_titlebar(): Promise<any>;
42
+ setIcon(iconPath: string): Promise<any>;
43
+ get_cookies(): Promise<any>;
44
+ set_cookie(name: string, value: string, domain?: string, path?: string): Promise<any>;
45
+ clear_cookies(): Promise<any>;
46
+ private _on_message;
47
+ private _parseParams;
48
+ private _handleMenuClick;
49
+ private _handleContextMenu;
50
+ private _handleExposedFunction;
51
+ private _sendSuccessResponse;
52
+ private _sendErrorResponse;
53
+ private _processMenu;
54
+ }
55
+ //# sourceMappingURL=window.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"window.d.ts","sourceRoot":"","sources":["../src/window.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGzD,qBAAa,MAAM;IACf,QAAQ,EAAE,GAAG,CAAC;IACd,OAAO,EAAE,aAAa,CAAC;IAEvB,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,cAAc,CAAsC;IAC5D,OAAO,CAAC,iBAAiB,CAA8B;IAEvD,eAAe,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,eAAe,EAAE,GAAG,IAAI,GAAG,OAAO,CAAC,eAAe,EAAE,GAAG,IAAI,CAAC,CAAc;gBAEjG,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;KAAE;IAiBhG,IAAI,MAAM,kBAET;IAEK,GAAG;YAkBK,KAAK;I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