ewvjs 1.0.9 → 1.0.10

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 (50) hide show
  1. package/README.md +3 -3
  2. package/dist/index.d.ts +5 -5
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +11 -52
  5. package/dist/platforms/windows.d.ts.map +1 -1
  6. package/dist/platforms/windows.js +9 -41
  7. package/dist/types.js +1 -2
  8. package/dist/utils.d.ts.map +1 -1
  9. package/dist/utils.js +44 -10
  10. package/dist/webview.d.ts +6 -2
  11. package/dist/webview.d.ts.map +1 -1
  12. package/dist/webview.js +139 -47
  13. package/dist/window.d.ts +7 -13
  14. package/dist/window.d.ts.map +1 -1
  15. package/dist/window.js +187 -250
  16. package/native/Microsoft.Bcl.AsyncInterfaces.dll +0 -0
  17. package/native/Microsoft.Web.WebView2.WinForms.dll +0 -0
  18. package/native/Microsoft.Web.WebView2.Wpf.dll +0 -0
  19. package/native/System.Buffers.dll +0 -0
  20. package/native/System.Collections.Immutable.dll +0 -0
  21. package/native/System.Memory.dll +0 -0
  22. package/native/System.Numerics.Vectors.dll +0 -0
  23. package/native/System.Reflection.Metadata.dll +0 -0
  24. package/native/System.Reflection.MetadataLoadContext.dll +0 -0
  25. package/native/System.Runtime.CompilerServices.Unsafe.dll +0 -0
  26. package/native/System.Text.Encoding.CodePages.dll +0 -0
  27. package/native/System.Text.Encodings.Web.dll +0 -0
  28. package/native/System.Text.Json.dll +0 -0
  29. package/native/System.Threading.Tasks.Extensions.dll +0 -0
  30. package/native/System.ValueTuple.dll +0 -0
  31. package/native/WebView.cjs +1 -1
  32. package/native/WebView.deps.json +117 -101
  33. package/native/WebView.dll +0 -0
  34. package/native/WebView.mjs +1 -1
  35. package/native/node_modules/node-api-dotnet/net472/Microsoft.Bcl.AsyncInterfaces.dll +0 -0
  36. package/native/node_modules/node-api-dotnet/net472/Microsoft.JavaScript.NodeApi.DotNetHost.dll +0 -0
  37. package/native/node_modules/node-api-dotnet/net472/Microsoft.JavaScript.NodeApi.dll +0 -0
  38. package/native/node_modules/node-api-dotnet/{net9.0 → net472}/Microsoft.JavaScript.NodeApi.runtimeconfig.json +1 -6
  39. package/native/node_modules/node-api-dotnet/net472/System.Memory.dll +0 -0
  40. package/native/node_modules/node-api-dotnet/net472/System.Runtime.CompilerServices.Unsafe.dll +0 -0
  41. package/native/node_modules/node-api-dotnet/net472/System.Threading.Tasks.Extensions.dll +0 -0
  42. package/native/node_modules/node-api-dotnet/net472.js +2 -0
  43. package/package.json +56 -54
  44. package/native/node_modules/node-api-dotnet/net10.0/Microsoft.JavaScript.NodeApi.DotNetHost.dll +0 -0
  45. package/native/node_modules/node-api-dotnet/net10.0/Microsoft.JavaScript.NodeApi.dll +0 -0
  46. package/native/node_modules/node-api-dotnet/net10.0/Microsoft.JavaScript.NodeApi.runtimeconfig.json +0 -14
  47. package/native/node_modules/node-api-dotnet/net10.0.js +0 -2
  48. package/native/node_modules/node-api-dotnet/net9.0/Microsoft.JavaScript.NodeApi.DotNetHost.dll +0 -0
  49. package/native/node_modules/node-api-dotnet/net9.0/Microsoft.JavaScript.NodeApi.dll +0 -0
  50. package/native/node_modules/node-api-dotnet/net9.0.js +0 -2
package/README.md CHANGED
@@ -138,13 +138,14 @@ Once a window is created, you can control it using the returned `Window` instanc
138
138
  * **State**: `maximize()`, `minimize()`, `restore()`, `hide()`, `focus()`, `show()`
139
139
  * **Size & Position**:
140
140
  * `getSize()`, `setSize(w, h)`, `resize(w, h)`
141
- * `getMinSize()`, `setMinSize(w, h)`, `set_min_size(w, h)`
141
+ * `getMinSize()`, `setMinSize(w, h)`
142
142
  * `getPosition()`, `setPosition(x, y)`, `move(x, y)`
143
143
  * **Interaction**:
144
144
  * `setTitle(title)`
145
+ * `showTitlebar()`, `hideTitlebar()`
145
146
  * `evaluate(script)`: Execute JavaScript in the WebView.
146
147
  * `setIcon(path)`
147
- * **Cookies**: `get_cookies()`, `set_cookie(...)`, `clear_cookies()`
148
+ * **Cookies**: `getCookies()`, `setCookie(name, value, domain, path)`, `clearCookies()`
148
149
 
149
150
  ### Custom Context Menus
150
151
 
@@ -274,7 +275,6 @@ The packaged application will be created in the `dist/` directory with:
274
275
  **Notes:**
275
276
  * Icon file must be in `.ico` format
276
277
  * Additional modules should be listed without spaces: `axios,lodash,express`
277
- * The `--compress` option requires UPX to be installed and available in PATH
278
278
  * Default target `node18-win-x64` works with Node.js 18+ on 64-bit Windows
279
279
 
280
280
  ### Getting Help
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- export * from './types';
2
- export { WebView } from './webview';
3
- export { Window } from './window';
4
- import { WebView } from './webview';
1
+ export * from './types.js';
2
+ export { WebView } from './webview.js';
3
+ export { Window } from './window.js';
4
+ import { WebView } from './webview.js';
5
5
  declare const ewvjs: WebView;
6
6
  export default ewvjs;
7
- export declare const create_window: (title: string, url_or_html?: string, options?: Partial<import("./types").WindowOptions>) => import("./window").Window;
7
+ export declare const create_window: (title: string, url_or_html?: string, options?: Partial<import("./types.js").WindowOptions>) => import("./window.js").Window;
8
8
  export declare const start: () => Promise<void>;
9
9
  export declare const expose: (name: string, func: Function) => void;
10
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA2BA,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,QAAA,MAAM,KAAK,SAAgB,CAAC;AAC5B,eAAe,KAAK,CAAC;AAGrB,eAAO,MAAM,aAAa,wHAAkC,CAAC;AAC7D,eAAO,MAAM,KAAK,qBAA0B,CAAC;AAC7C,eAAO,MAAM,MAAM,wCAA2B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA2BA,cAAc,YAAY,CAAC;AAG3B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,QAAA,MAAM,KAAK,SAAgB,CAAC;AAC5B,eAAe,KAAK,CAAC;AAGrB,eAAO,MAAM,aAAa,8HAAkC,CAAC;AAC7D,eAAO,MAAM,KAAK,qBAA0B,CAAC;AAC7C,eAAO,MAAM,MAAM,wCAA2B,CAAC"}
package/dist/index.js CHANGED
@@ -1,45 +1,6 @@
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
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.expose = exports.start = exports.create_window = exports.Window = exports.WebView = void 0;
40
1
  // Setup module resolution for node-api-dotnet BEFORE any imports
41
- const path = __importStar(require("path"));
42
- const fs = __importStar(require("fs"));
2
+ import * as path from 'path';
3
+ import * as fs from 'fs';
43
4
  const isPkg = typeof process.pkg !== 'undefined';
44
5
  if (isPkg) {
45
6
  const execDir = path.dirname(process.execPath);
@@ -60,17 +21,15 @@ if (isPkg) {
60
21
  }
61
22
  }
62
23
  // Export types
63
- __exportStar(require("./types"), exports);
24
+ export * from './types.js';
64
25
  // Export classes
65
- var webview_1 = require("./webview");
66
- Object.defineProperty(exports, "WebView", { enumerable: true, get: function () { return webview_1.WebView; } });
67
- var window_1 = require("./window");
68
- Object.defineProperty(exports, "Window", { enumerable: true, get: function () { return window_1.Window; } });
26
+ export { WebView } from './webview.js';
27
+ export { Window } from './window.js';
69
28
  // Create and export singleton instance
70
- const webview_2 = require("./webview");
71
- const ewvjs = new webview_2.WebView();
72
- exports.default = ewvjs;
29
+ import { WebView } from './webview.js';
30
+ const ewvjs = new WebView();
31
+ export default ewvjs;
73
32
  // Export convenience functions
74
- exports.create_window = ewvjs.create_window.bind(ewvjs);
75
- exports.start = ewvjs.start.bind(ewvjs);
76
- exports.expose = ewvjs.expose.bind(ewvjs);
33
+ export const create_window = ewvjs.create_window.bind(ewvjs);
34
+ export const start = ewvjs.start.bind(ewvjs);
35
+ export const expose = ewvjs.expose.bind(ewvjs);
@@ -1 +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"}
1
+ {"version":3,"file":"windows.d.ts","sourceRoot":"","sources":["../../src/platforms/windows.ts"],"names":[],"mappings":"AAUA,qBAAa,eAAe;;IAKxB,YAAY,CAAC,OAAO,EAAE,GAAG;CA6G5B"}
@@ -1,43 +1,12 @@
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 {
1
+ import * as path from 'path';
2
+ import * as fs from 'fs';
3
+ import * as Module from 'module';
4
+ import { fileURLToPath } from 'url';
5
+ import { createRequire } from 'module';
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+ const require = createRequire(import.meta.url);
9
+ export class WindowsPlatform {
41
10
  constructor() {
42
11
  }
43
12
  createWindow(options) {
@@ -140,4 +109,3 @@ class WindowsPlatform {
140
109
  }
141
110
  }
142
111
  }
143
- exports.WindowsPlatform = WindowsPlatform;
package/dist/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1 +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"}
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,CAiDtD;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAEnC"}
package/dist/utils.js CHANGED
@@ -1,22 +1,56 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getParamNames = getParamNames;
4
- exports.generateId = generateId;
5
1
  /**
6
2
  * Extracts parameter names from a function
7
3
  */
8
- function getParamNames(func) {
4
+ export function getParamNames(func) {
9
5
  const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
10
- const ARGUMENT_NAMES = /([^\s,]+)/g;
11
6
  const fnStr = func.toString().replace(STRIP_COMMENTS, '');
12
- const result = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(ARGUMENT_NAMES);
13
- if (result === null)
7
+ // Handle arrow functions: name => ... or (name) => ... or (a, b) => ...
8
+ // Handle regular functions: function name(a, b) { ... }
9
+ // Handle async functions: async (a, b) => ... or async function(a, b) { ... }
10
+ let paramsStr = '';
11
+ // Check for arrow function
12
+ const arrowIndex = fnStr.indexOf('=>');
13
+ if (arrowIndex !== -1) {
14
+ // Arrow function
15
+ const beforeArrow = fnStr.slice(0, arrowIndex).trim();
16
+ // Check if parameters are in parentheses
17
+ const lastOpenParen = beforeArrow.lastIndexOf('(');
18
+ if (lastOpenParen !== -1) {
19
+ // Parameters are like (a, b) or (a: string, b: number)
20
+ const lastCloseParen = beforeArrow.lastIndexOf(')');
21
+ paramsStr = beforeArrow.slice(lastOpenParen + 1, lastCloseParen);
22
+ }
23
+ else {
24
+ // Single parameter without parentheses: name => ...
25
+ // Remove 'async' if present
26
+ paramsStr = beforeArrow.replace(/^\s*async\s+/, '').trim();
27
+ }
28
+ }
29
+ else {
30
+ // Regular function
31
+ const openParen = fnStr.indexOf('(');
32
+ const closeParen = fnStr.indexOf(')', openParen);
33
+ if (openParen !== -1 && closeParen !== -1) {
34
+ paramsStr = fnStr.slice(openParen + 1, closeParen);
35
+ }
36
+ }
37
+ if (!paramsStr)
14
38
  return [];
15
- return Array.from(result);
39
+ // Split by comma and extract just the parameter names (strip types and default values)
40
+ return paramsStr.split(',').map(param => {
41
+ // Remove type annotations (everything after :)
42
+ // Remove default values (everything after =)
43
+ // Remove whitespace and rest/spread operators
44
+ return param
45
+ .replace(/\s*:.*?(?=,|$)/g, '') // Remove TypeScript types
46
+ .replace(/\s*=.*?(?=,|$)/g, '') // Remove default values
47
+ .replace(/\s+/g, '') // Remove whitespace
48
+ .replace(/^\.\.\./, ''); // Remove rest operator
49
+ }).filter(name => name.length > 0);
16
50
  }
17
51
  /**
18
52
  * Generates a random ID for menu items
19
53
  */
20
- function generateId() {
54
+ export function generateId() {
21
55
  return `menu_item_${Math.random().toString(36).substr(2, 9)}`;
22
56
  }
package/dist/webview.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Window } from './window';
2
- import { WindowOptions } from './types';
1
+ import { Window } from "./window.js";
2
+ import { WindowOptions } from "./types.js";
3
3
  export declare class WebView {
4
4
  platform: any;
5
5
  exposed_functions: {
@@ -10,12 +10,16 @@ export declare class WebView {
10
10
  private _resolveStart;
11
11
  private _heartbeat;
12
12
  private _resolveOnce;
13
+ private _httpServers;
13
14
  constructor();
14
15
  create_window(title: string, url_or_html?: string, options?: Partial<WindowOptions>): Window;
15
16
  start(): Promise<void>;
16
17
  private _cleanup;
17
18
  expose(name: string, func: Function): void;
18
19
  _handle_message(message: any): Promise<void>;
20
+ private _getMimeType;
21
+ private _findFreePort;
22
+ private _createHttpServer;
19
23
  private _buildWindowOptions;
20
24
  }
21
25
  //# sourceMappingURL=webview.d.ts.map
@@ -1 +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;IACjD,OAAO,CAAC,YAAY,CAAkB;;IAUtC,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;IAkBhB,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;CAgC9B"}
1
+ {"version":3,"file":"webview.d.ts","sourceRoot":"","sources":["../src/webview.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAW3C,qBAAa,OAAO;IACnB,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;IACjD,OAAO,CAAC,YAAY,CAAkB;IACtC,OAAO,CAAC,YAAY,CAAuC;;IAU3D,aAAa,CACZ,KAAK,EAAE,MAAM,EACb,WAAW,GAAE,MAAW,EACxB,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM,GAClC,MAAM;IAgBH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAa5B,OAAO,CAAC,QAAQ;IAyBhB,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,YAAY;IAKpB,OAAO,CAAC,aAAa;IA8BrB,OAAO,CAAC,iBAAiB;IA6DzB,OAAO,CAAC,mBAAmB;CAuC3B"}
package/dist/webview.js CHANGED
@@ -1,35 +1,33 @@
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 {
1
+ import { WindowsPlatform } from "./platforms/windows.js";
2
+ import { Window } from "./window.js";
3
+ import * as http from "http";
4
+ import * as fs from "fs";
5
+ import * as path from "path";
6
+ import mime from "mime-types";
7
+ import { execSync } from "child_process";
8
+ import { fileURLToPath } from 'url';
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+ export class WebView {
12
+ platform;
13
+ exposed_functions = {};
14
+ _windows = new Set();
15
+ _startPromise = null;
16
+ _resolveStart = null;
17
+ _heartbeat = null;
18
+ _resolveOnce = false;
19
+ _httpServers = new Map();
16
20
  constructor() {
17
- this.exposed_functions = {};
18
- this._windows = new Set();
19
- this._startPromise = null;
20
- this._resolveStart = null;
21
- this._heartbeat = null;
22
- this._resolveOnce = false;
23
- if (process.platform === 'win32') {
24
- this.platform = new windows_1.WindowsPlatform();
21
+ if (process.platform === "win32") {
22
+ this.platform = new WindowsPlatform();
25
23
  }
26
24
  else {
27
- throw new Error('Platform not supported: ' + process.platform);
25
+ throw new Error("Platform not supported: " + process.platform);
28
26
  }
29
27
  }
30
- create_window(title, url_or_html = '', options = {}) {
28
+ create_window(title, url_or_html = "", options = {}) {
31
29
  const opts = this._buildWindowOptions(title, url_or_html, options);
32
- const window = new window_1.Window(this.platform, opts, this.exposed_functions);
30
+ const window = new Window(this.platform, opts, this.exposed_functions);
33
31
  this._windows.add(window);
34
32
  window.closed.then(() => {
35
33
  this._windows.delete(window);
@@ -39,23 +37,26 @@ class WebView {
39
37
  });
40
38
  return window;
41
39
  }
42
- start() {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- if (this._windows.size === 0)
45
- return;
46
- // Keep process alive while windows are open
47
- this._heartbeat = setInterval(() => { }, 1000);
48
- this._startPromise = new Promise((resolve) => {
49
- this._resolveStart = resolve;
50
- });
51
- return this._startPromise;
40
+ async start() {
41
+ if (this._windows.size === 0)
42
+ return;
43
+ // Keep process alive while windows are open
44
+ this._heartbeat = setInterval(() => { }, 1000);
45
+ this._startPromise = new Promise((resolve) => {
46
+ this._resolveStart = resolve;
52
47
  });
48
+ return this._startPromise;
53
49
  }
54
50
  _cleanup() {
55
51
  if (this._heartbeat) {
56
52
  clearInterval(this._heartbeat);
57
53
  this._heartbeat = null;
58
54
  }
55
+ // Close all HTTP servers
56
+ for (const [_, server] of this._httpServers) {
57
+ server.close();
58
+ }
59
+ this._httpServers.clear();
59
60
  if (this._resolveStart) {
60
61
  this._resolveStart();
61
62
  this._resolveOnce = true;
@@ -71,19 +72,107 @@ class WebView {
71
72
  expose(name, func) {
72
73
  this.exposed_functions[name] = func;
73
74
  }
74
- _handle_message(message) {
75
- return __awaiter(this, void 0, void 0, function* () {
76
- if (!message)
77
- return;
75
+ async _handle_message(message) {
76
+ if (!message)
77
+ return;
78
+ }
79
+ _getMimeType(filePath) {
80
+ const ext = path.extname(filePath).toLowerCase();
81
+ return mime.lookup(ext) || "application/octet-stream";
82
+ }
83
+ _findFreePort() {
84
+ // Use execSync to find a free port synchronously
85
+ const script = `
86
+ import net from 'net';
87
+ const server = net.createServer();
88
+ server.listen(0, 'localhost', () => {
89
+ console.log(server.address().port);
90
+ server.close();
91
+ });
92
+ `;
93
+ try {
94
+ const output = execSync(`node --input-type=module -e "${script.replace(/"/g, '\\"').replace(/\n/g, " ")}"`, {
95
+ encoding: "utf-8",
96
+ timeout: 5000,
97
+ });
98
+ const port = parseInt(output.trim(), 10);
99
+ if (isNaN(port)) {
100
+ throw new Error("Failed to parse port");
101
+ }
102
+ return port;
103
+ }
104
+ catch (err) {
105
+ // Fallback to port range
106
+ return 3000 + Math.floor(Math.random() * 1000);
107
+ }
108
+ }
109
+ _createHttpServer(filePath) {
110
+ // Check if server already exists for this file
111
+ if (this._httpServers.has(filePath)) {
112
+ const existingPort = Array.from(this._httpServers.entries()).find(([path, _]) => path === filePath);
113
+ if (existingPort) {
114
+ const addr = existingPort[1].address();
115
+ if (addr && typeof addr === "object") {
116
+ return `http://localhost:${addr.port}`;
117
+ }
118
+ }
119
+ }
120
+ // Resolve relative paths from the main script's directory, not CWD
121
+ let absolutePath;
122
+ // In ESM, use process.argv[1] to get the main script path
123
+ let mainDir;
124
+ if (process.argv[1]) {
125
+ mainDir = path.dirname(process.argv[1]);
126
+ }
127
+ else {
128
+ mainDir = process.cwd();
129
+ }
130
+ absolutePath = path.resolve(mainDir, filePath);
131
+ console.log(`Serving ${absolutePath} at ${filePath}`);
132
+ const dir = path.dirname(absolutePath);
133
+ const fileName = path.basename(absolutePath);
134
+ // Find a free port first
135
+ const port = this._findFreePort();
136
+ const server = http.createServer((req, res) => {
137
+ const requestPath = req.url === "/" ? fileName : req.url.substring(1);
138
+ const fullPath = path.join(dir, requestPath);
139
+ fs.readFile(fullPath, (err, data) => {
140
+ if (err) {
141
+ res.writeHead(404);
142
+ res.end("File not found");
143
+ return;
144
+ }
145
+ const mimeType = this._getMimeType(fullPath);
146
+ if (mimeType) {
147
+ res.writeHead(200, { "Content-Type": mimeType });
148
+ }
149
+ else {
150
+ res.writeHead(200);
151
+ }
152
+ res.end(data);
153
+ });
78
154
  });
155
+ // Use the pre-allocated port
156
+ server.listen(port, "localhost");
157
+ this._httpServers.set(filePath, server);
158
+ return `http://localhost:${port}`;
79
159
  }
80
160
  _buildWindowOptions(title, url_or_html, options) {
81
- var _a, _b, _c;
82
- const opts = Object.assign({ title: title, width: options.width || 800, height: options.height || 600, resizable: options.resizable !== undefined ? options.resizable : true, session: {
83
- persist: ((_a = options.session) === null || _a === void 0 ? void 0 : _a.persist) !== undefined ? options.session.persist : true,
84
- path: (_b = options.session) === null || _b === void 0 ? void 0 : _b.path,
85
- envname: (_c = options.session) === null || _c === void 0 ? void 0 : _c.envname
86
- }, jsCallback: this._handle_message.bind(this) }, options);
161
+ const opts = {
162
+ title: title,
163
+ width: options.width || 800,
164
+ height: options.height || 600,
165
+ resizable: options.resizable !== undefined ? options.resizable : true,
166
+ session: {
167
+ persist: options.session?.persist !== undefined
168
+ ? options.session.persist
169
+ : true,
170
+ path: options.session?.path,
171
+ envname: options.session?.envname,
172
+ },
173
+ jsCallback: this._handle_message.bind(this),
174
+ ...options,
175
+ };
87
176
  const urlRegex = /^(http?|file?|data?):/i;
88
177
  const isUrl = urlRegex.test(url_or_html) ||
89
178
  /^localhost(:\d+)?$/i.test(url_or_html) ||
@@ -91,10 +180,13 @@ class WebView {
91
180
  if (isUrl) {
92
181
  opts.url = url_or_html;
93
182
  }
183
+ else if (url_or_html.toLowerCase().endsWith(".html")) {
184
+ // If it's an HTML file path, serve it via HTTP server
185
+ opts.url = this._createHttpServer(url_or_html);
186
+ }
94
187
  else {
95
188
  opts.html = url_or_html;
96
189
  }
97
190
  return opts;
98
191
  }
99
192
  }
100
- exports.WebView = WebView;
package/dist/window.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ContextMenuItem, WindowOptions } from './types';
1
+ import { ContextMenuItem, WindowOptions } from "./types.js";
2
2
  export declare class Window {
3
3
  platform: any;
4
4
  options: WindowOptions;
@@ -8,6 +8,7 @@ export declare class Window {
8
8
  private _menuCallbacks;
9
9
  private _exposedFunctions;
10
10
  private _isClosed;
11
+ private _pendingApiInjection;
11
12
  on_context_menu: (items: any[]) => ContextMenuItem[] | null | Promise<ContextMenuItem[] | null>;
12
13
  constructor(platform: any, options: WindowOptions, exposedFunctions: {
13
14
  [key: string]: Function;
@@ -16,7 +17,6 @@ export declare class Window {
16
17
  get is_closed(): boolean;
17
18
  run(): Promise<any>;
18
19
  private _call;
19
- evaluate_js(script: string): Promise<any>;
20
20
  evaluate(script: string): Promise<any>;
21
21
  close(): Promise<any>;
22
22
  destroy(): Promise<any>;
@@ -31,22 +31,16 @@ export declare class Window {
31
31
  resize(width: number, height: number): Promise<any>;
32
32
  getMinSize(): Promise<any>;
33
33
  setMinSize(width: number, height: number): Promise<any>;
34
- set_min_size(width: number, height: number): Promise<any>;
35
34
  getPosition(): Promise<any>;
36
35
  setPosition(x: number, y: number): Promise<any>;
37
36
  move(x: number, y: number): Promise<any>;
38
- get_position(): Promise<any>;
39
- set_position(x: number, y: number): Promise<any>;
40
- get_width(): Promise<number>;
41
- get_height(): Promise<number>;
42
37
  setTitle(title: string): Promise<any>;
43
- set_title(title: string): Promise<any>;
44
- show_titlebar(): Promise<any>;
45
- hide_titlebar(): Promise<any>;
38
+ showTitlebar(): Promise<any>;
39
+ hideTitlebar(): Promise<any>;
46
40
  setIcon(iconPath: string): Promise<any>;
47
- get_cookies(): Promise<any>;
48
- set_cookie(name: string, value: string, domain?: string, path?: string): Promise<any>;
49
- clear_cookies(): Promise<any>;
41
+ getCookies(): Promise<any>;
42
+ setCookie(name: string, value: string, domain?: string, path?: string): Promise<any>;
43
+ clearCookies(): Promise<any>;
50
44
  private _on_message;
51
45
  private _parseParams;
52
46
  private _handleMenuClick;
@@ -1 +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;IACvD,OAAO,CAAC,SAAS,CAAkB;IAEnC,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,CA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