xbintsc 0.3.49 → 0.3.65

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 (51) hide show
  1. package/dist/src/driver/compiler.js +25 -1
  2. package/dist/src/driver/compiler.js.map +1 -1
  3. package/dist/src/driver/config.d.ts +7 -0
  4. package/dist/src/driver/config.js.map +1 -1
  5. package/dist/src/driver/win-entry.d.ts +21 -0
  6. package/dist/src/driver/win-entry.js +52 -0
  7. package/dist/src/driver/win-entry.js.map +1 -0
  8. package/dist/tests/e2e/gui-events.test.js +32 -0
  9. package/dist/tests/e2e/gui-events.test.js.map +1 -1
  10. package/dist/tests/e2e/gui-example-browser.test.d.ts +12 -0
  11. package/dist/tests/e2e/gui-example-browser.test.js +168 -0
  12. package/dist/tests/e2e/gui-example-browser.test.js.map +1 -0
  13. package/dist/tests/e2e/gui-example.test.d.ts +14 -0
  14. package/dist/tests/e2e/gui-example.test.js +76 -0
  15. package/dist/tests/e2e/gui-example.test.js.map +1 -0
  16. package/dist/tests/e2e/gui-helpers.d.ts +39 -4
  17. package/dist/tests/e2e/gui-helpers.js +38 -9
  18. package/dist/tests/e2e/gui-helpers.js.map +1 -1
  19. package/dist/tests/e2e/gui-layout.test.js +155 -0
  20. package/dist/tests/e2e/gui-layout.test.js.map +1 -1
  21. package/dist/tests/e2e/gui-lifecycle.test.js +10 -1
  22. package/dist/tests/e2e/gui-lifecycle.test.js.map +1 -1
  23. package/dist/tests/e2e/gui-paint.test.js +44 -4
  24. package/dist/tests/e2e/gui-paint.test.js.map +1 -1
  25. package/dist/tests/e2e/gui-script.test.js +8 -4
  26. package/dist/tests/e2e/gui-script.test.js.map +1 -1
  27. package/doc/gui.md +120 -9
  28. package/doc/xbintsc.config.schema.json +4 -0
  29. package/doc/zh-CN/gui.md +78 -7
  30. package/package.json +1 -1
  31. package/runtime/ext_gui/dom_api.cpp +19 -0
  32. package/runtime/ext_gui/dom_api_node.cpp +4 -1
  33. package/runtime/ext_gui/dom_api_node_read.cpp +12 -0
  34. package/runtime/ext_gui/gui.cpp +42 -2
  35. package/runtime/ext_gui/gui_engine.h +15 -0
  36. package/runtime/ext_gui/gui_events.cpp +13 -3
  37. package/runtime/ext_gui/layout.cpp +6 -0
  38. package/runtime/ext_gui/layout.h +4 -0
  39. package/runtime/ext_gui/layout_flex.cpp +13 -5
  40. package/runtime/ext_gui/layout_flow.cpp +134 -4
  41. package/runtime/ext_gui/layout_flow_internal.h +41 -2
  42. package/runtime/ext_gui/layout_inline.cpp +11 -3
  43. package/runtime/ext_gui/paint.cpp +6 -0
  44. package/runtime/ext_gui/script.cpp +12 -2
  45. package/runtime/ext_gui/text.cpp +14 -0
  46. package/runtime/ext_gui/window.cpp +44 -0
  47. package/runtime/rt.h +10 -0
  48. package/runtime/xt_io/console.inc +15 -3
  49. package/src/driver/compiler.ts +26 -1
  50. package/src/driver/config.ts +7 -0
  51. package/src/driver/win-entry.ts +59 -0
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Windows GUI-subsystem entry point.
3
+ *
4
+ * A program that links with the `gui` extension is built as a **Windows
5
+ * subsystem** executable (`/SUBSYSTEM:WINDOWS`), which is what keeps a console
6
+ * window from flashing up when it is launched. The MSVC C runtime then expects
7
+ * `WinMain` instead of `main`, and xbintsc's runtime always emits a C `main`
8
+ * (the program body plus teardown), so the driver links this tiny shim to
9
+ * bridge the two.
10
+ *
11
+ * It is compiled on demand and cached like the icon object; nothing here is
12
+ * platform-abstract — on every other platform the file is never used.
13
+ */
14
+
15
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
16
+ import { join } from "node:path";
17
+ import { hashParts } from "./cache.js";
18
+ import { compileC, type Runner } from "./toolchain.js";
19
+
20
+ /** The bridge source. `main` is the entry point the runtime emits. */
21
+ export const WINDOWS_ENTRY_SOURCE = `/* Generated by xbintsc - Windows GUI subsystem entry point. Do not edit. */
22
+ #ifndef UNICODE
23
+ #define UNICODE
24
+ #endif
25
+ #include <windows.h>
26
+
27
+ /* The xbintsc runtime defines the C program entry point; hand it the command
28
+ * line minus the argv[0] hole so it still sees its own arguments. */
29
+ int main(int argc, char **argv);
30
+
31
+ int WINAPI WinMain(HINSTANCE instance, HINSTANCE previous, LPSTR command_line, int show) {
32
+ (void)instance;
33
+ (void)previous;
34
+ (void)command_line;
35
+ (void)show;
36
+ return main(__argc, __argv);
37
+ }
38
+ `;
39
+
40
+ /**
41
+ * Compile the entry shim into an object file (cached by source + platform +
42
+ * toolchain) and return its path.
43
+ */
44
+ export function ensureWindowsEntryObject(
45
+ runner: Runner,
46
+ clang: string,
47
+ cacheDir: string,
48
+ env?: Record<string, string>,
49
+ ): string {
50
+ const key = hashParts(["win-gui-entry", process.platform, clang, WINDOWS_ENTRY_SOURCE]);
51
+ const sourcePath = join(cacheDir, `winentry-${key}.c`);
52
+ const objectPath = join(cacheDir, `winentry-${key}.o`);
53
+ if (!existsSync(objectPath)) {
54
+ mkdirSync(cacheDir, { recursive: true });
55
+ writeFileSync(sourcePath, WINDOWS_ENTRY_SOURCE);
56
+ compileC(runner, clang, sourcePath, objectPath, cacheDir, env);
57
+ }
58
+ return objectPath;
59
+ }