quickwin 1.3.0 → 2.1.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 (167) hide show
  1. package/README.en.md +18 -24
  2. package/README.md +17 -23
  3. package/examples/PdfCanvas.js +8 -37
  4. package/examples/PdfCanvas.tsx +11 -41
  5. package/examples/exec_server.js +20155 -1420
  6. package/examples/exec_server.tsx +489 -0
  7. package/examples/exec_server_worker.js +383 -33
  8. package/examples/exec_server_worker.ts +408 -30
  9. package/examples/pdf_preview2.js +25 -82
  10. package/examples/pdf_preview2.ts +27 -84
  11. package/examples/pdf_viewer.js +1424 -1180
  12. package/examples/pdf_viewer.tsx +16 -67
  13. package/examples/setres.js +22 -47
  14. package/examples/setres.ts +23 -57
  15. package/examples/test_gallery.js +1418 -1075
  16. package/examples/test_react_lazy.js +1391 -1059
  17. package/examples/test_react_listbox.js +1390 -1058
  18. package/examples/test_root_window.js +1384 -1052
  19. package/examples/test_tab.js +1391 -1059
  20. package/lib/abort.js +70 -0
  21. package/lib/abort.ts +69 -0
  22. package/lib/certs.js +219 -0
  23. package/lib/certs.ts +229 -0
  24. package/lib/exec-log.js +15 -0
  25. package/lib/exec-log.ts +30 -0
  26. package/lib/fetch.js +88 -7
  27. package/lib/fetch.ts +73 -7
  28. package/lib/ffi/bind.js +441 -0
  29. package/lib/ffi/bind.ts +539 -0
  30. package/lib/ffi/ctype.js +194 -0
  31. package/lib/ffi/ctype.ts +369 -0
  32. package/lib/ffi/index.js +6 -0
  33. package/lib/ffi/index.ts +6 -0
  34. package/lib/ffi/struct.js +490 -0
  35. package/lib/ffi/struct.ts +753 -0
  36. package/lib/http-common.js +43 -5
  37. package/lib/http-common.ts +48 -6
  38. package/lib/http-server.js +187 -29
  39. package/lib/http-server.ts +177 -26
  40. package/lib/react-qw/components/DateTimePicker.js +18 -37
  41. package/lib/react-qw/components/Input.js +3 -10
  42. package/lib/react-qw/components/Link.js +6 -19
  43. package/lib/react-qw/components/ListView.js +50 -154
  44. package/lib/react-qw/components/PathPicker.js +28 -88
  45. package/lib/react-qw/components/ScrollView.js +15 -8
  46. package/lib/react-qw/components/Slider.js +2 -1
  47. package/lib/react-qw/components/Tab.js +6 -22
  48. package/lib/react-qw/components/Tooltip.js +10 -21
  49. package/lib/react-qw/components/TreeView.js +8 -31
  50. package/lib/react-qw/index.js +5 -3
  51. package/lib/react-qw/index.ts +8 -3
  52. package/lib/react-qw/nmhdr.js +3 -24
  53. package/lib/react-qw/nmhdr.ts +5 -30
  54. package/lib/react-qw/props.js +7 -2
  55. package/lib/react-qw/props.ts +7 -3
  56. package/lib/react-qw/reconciler.js +23 -13
  57. package/lib/react-qw/reconciler.ts +22 -13
  58. package/lib/text-measure.js +20 -23
  59. package/lib/text-measure.ts +22 -26
  60. package/lib/websocket.js +44 -4
  61. package/lib/websocket.ts +40 -4
  62. package/lib/windows/advapi32.js +53 -0
  63. package/lib/windows/advapi32.ts +64 -0
  64. package/lib/windows/comctl32.js +18 -0
  65. package/lib/windows/comctl32.ts +19 -0
  66. package/lib/windows/comdlg32.js +8 -0
  67. package/lib/windows/comdlg32.ts +10 -0
  68. package/lib/windows/gdi32.js +392 -0
  69. package/lib/windows/gdi32.ts +420 -0
  70. package/lib/windows/kernel32.js +262 -0
  71. package/lib/windows/kernel32.ts +291 -0
  72. package/lib/windows/msimg32.js +38 -0
  73. package/lib/windows/msimg32.ts +45 -0
  74. package/lib/windows/ntdll.js +9 -0
  75. package/lib/windows/ntdll.ts +11 -0
  76. package/lib/windows/ole32.js +7 -0
  77. package/lib/windows/ole32.ts +9 -0
  78. package/lib/windows/psapi.js +32 -0
  79. package/lib/windows/psapi.ts +37 -0
  80. package/lib/windows/shell32.js +13 -0
  81. package/lib/windows/shell32.ts +16 -0
  82. package/lib/windows/structs.js +519 -0
  83. package/lib/windows/structs.ts +566 -0
  84. package/lib/windows/user32.js +572 -0
  85. package/lib/windows/user32.ts +607 -0
  86. package/lib/windows/version.js +29 -0
  87. package/lib/windows/version.ts +35 -0
  88. package/lib/windows/winspool.js +71 -0
  89. package/lib/windows/winspool.ts +80 -0
  90. package/package.json +1 -1
  91. package/quickwin.d.ts +31 -40
  92. package/quickwin_const.d.ts +137 -0
  93. package/qwin-nowasm-x86.exe +0 -0
  94. package/qwin-nowasm.exe +0 -0
  95. package/qwin-x86.exe +0 -0
  96. package/qwin.exe +0 -0
  97. package/test/bench_ffi_callraw.js +236 -0
  98. package/test/bench_ffi_callraw.ts +236 -0
  99. package/test/bench_ffi_overhead.js +139 -0
  100. package/test/bench_ffi_overhead.ts +141 -0
  101. package/test/bench_sendmessage.js +104 -0
  102. package/test/bench_sendmessage.ts +100 -0
  103. package/test/bench_sendmessage_nonnull.js +187 -0
  104. package/test/bench_sendmessage_nonnull.ts +188 -0
  105. package/test/run.js +19 -4
  106. package/test/run.ts +20 -5
  107. package/test/test_basic_fetch.js +29 -0
  108. package/test/test_basic_fetch.ts +26 -0
  109. package/test/test_ffi.js +27 -45
  110. package/test/test_ffi.ts +35 -54
  111. package/test/test_ffi_abi.js +290 -0
  112. package/test/test_ffi_abi.ts +274 -0
  113. package/test/test_ffi_array.js +116 -0
  114. package/test/test_ffi_array.ts +141 -0
  115. package/test/test_ffi_bind.js +620 -8
  116. package/test/test_ffi_bind.ts +630 -8
  117. package/test/test_ffi_struct.js +632 -88
  118. package/test/test_ffi_struct.ts +666 -91
  119. package/test/test_ffi_struct_layout.js +495 -0
  120. package/test/test_ffi_struct_layout.ts +543 -0
  121. package/test/test_ffi_user32.js +103 -0
  122. package/test/test_ffi_user32.ts +113 -0
  123. package/test/test_ffi_windows.js +101 -0
  124. package/test/test_ffi_windows.ts +113 -0
  125. package/test/test_files.js +102 -0
  126. package/test/test_files.ts +121 -0
  127. package/test/test_gdi_draw.js +681 -0
  128. package/test/test_gdi_draw.ts +725 -0
  129. package/test/test_helper.js +8 -1
  130. package/test/test_helper.ts +9 -1
  131. package/test/test_http_import.js +18 -0
  132. package/test/test_http_import.ts +19 -0
  133. package/test/test_http_server.js +73 -1
  134. package/test/test_http_server.ts +75 -1
  135. package/test/test_ipv6.js +2 -2
  136. package/test/test_ipv6.ts +2 -2
  137. package/test/test_net_fetch.js +74 -11
  138. package/test/test_net_fetch.ts +73 -10
  139. package/test/test_net_websocket.js +1 -1
  140. package/test/test_net_websocket.ts +1 -1
  141. package/test/test_printer.js +137 -0
  142. package/test/test_printer.ts +148 -0
  143. package/test/test_proc.js +141 -0
  144. package/test/test_proc.ts +163 -0
  145. package/test/test_react_complex.js +1401 -1069
  146. package/test/test_react_counter.js +1391 -1059
  147. package/test/test_react_flex.js +1411 -1072
  148. package/test/test_react_hidden.js +1394 -1062
  149. package/test/test_react_listview_link.js +1391 -1059
  150. package/test/test_react_notify.js +18638 -0
  151. package/test/test_react_render.js +1391 -1059
  152. package/test/test_registry.js +74 -0
  153. package/test/test_registry.ts +95 -0
  154. package/test/test_sysinfo.js +122 -0
  155. package/test/test_sysinfo.ts +141 -0
  156. package/test/test_wolfssl_read.js +45 -43
  157. package/test/test_wolfssl_read.ts +42 -40
  158. package/test/test_worker_net.js +35 -17
  159. package/test/test_worker_net.ts +27 -15
  160. package/tsconfig.json +1 -1
  161. package/examples/exec_server.ts +0 -80
  162. package/lib/ffi-bind.js +0 -85
  163. package/lib/ffi-bind.ts +0 -170
  164. package/lib/ffi-struct.js +0 -224
  165. package/lib/ffi-struct.ts +0 -239
  166. package/lib/win-common-structs.js +0 -39
  167. package/lib/win-common-structs.ts +0 -41
@@ -1367,9 +1367,9 @@ var require_scheduler_development = __commonJS({
1367
1367
  }
1368
1368
  return first;
1369
1369
  }
1370
- function compare(a, b) {
1371
- var diff = a.sortIndex - b.sortIndex;
1372
- return 0 !== diff ? diff : a.id - b.id;
1370
+ function compare(a, b6) {
1371
+ var diff = a.sortIndex - b6.sortIndex;
1372
+ return 0 !== diff ? diff : a.id - b6.id;
1373
1373
  }
1374
1374
  function advanceTimers(currentTime) {
1375
1375
  for (var timer = peek(timerQueue); null !== timer; ) {
@@ -1667,14 +1667,14 @@ var require_react_reconciler_development = __commonJS({
1667
1667
  throw Error("Unable to find node on an unmounted component.");
1668
1668
  return alternate !== fiber ? null : fiber;
1669
1669
  }
1670
- for (var a = fiber, b = alternate; ; ) {
1670
+ for (var a = fiber, b6 = alternate; ; ) {
1671
1671
  var parentA = a.return;
1672
1672
  if (null === parentA) break;
1673
1673
  var parentB = parentA.alternate;
1674
1674
  if (null === parentB) {
1675
- b = parentA.return;
1676
- if (null !== b) {
1677
- a = b;
1675
+ b6 = parentA.return;
1676
+ if (null !== b6) {
1677
+ a = b6;
1678
1678
  continue;
1679
1679
  }
1680
1680
  break;
@@ -1682,23 +1682,23 @@ var require_react_reconciler_development = __commonJS({
1682
1682
  if (parentA.child === parentB.child) {
1683
1683
  for (parentB = parentA.child; parentB; ) {
1684
1684
  if (parentB === a) return assertIsMounted(parentA), fiber;
1685
- if (parentB === b) return assertIsMounted(parentA), alternate;
1685
+ if (parentB === b6) return assertIsMounted(parentA), alternate;
1686
1686
  parentB = parentB.sibling;
1687
1687
  }
1688
1688
  throw Error("Unable to find node on an unmounted component.");
1689
1689
  }
1690
- if (a.return !== b.return) a = parentA, b = parentB;
1690
+ if (a.return !== b6.return) a = parentA, b6 = parentB;
1691
1691
  else {
1692
1692
  for (var didFindChild = false, _child = parentA.child; _child; ) {
1693
1693
  if (_child === a) {
1694
1694
  didFindChild = true;
1695
1695
  a = parentA;
1696
- b = parentB;
1696
+ b6 = parentB;
1697
1697
  break;
1698
1698
  }
1699
- if (_child === b) {
1699
+ if (_child === b6) {
1700
1700
  didFindChild = true;
1701
- b = parentA;
1701
+ b6 = parentA;
1702
1702
  a = parentB;
1703
1703
  break;
1704
1704
  }
@@ -1709,12 +1709,12 @@ var require_react_reconciler_development = __commonJS({
1709
1709
  if (_child === a) {
1710
1710
  didFindChild = true;
1711
1711
  a = parentB;
1712
- b = parentA;
1712
+ b6 = parentA;
1713
1713
  break;
1714
1714
  }
1715
- if (_child === b) {
1715
+ if (_child === b6) {
1716
1716
  didFindChild = true;
1717
- b = parentB;
1717
+ b6 = parentB;
1718
1718
  a = parentA;
1719
1719
  break;
1720
1720
  }
@@ -1726,7 +1726,7 @@ var require_react_reconciler_development = __commonJS({
1726
1726
  );
1727
1727
  }
1728
1728
  }
1729
- if (a.alternate !== b)
1729
+ if (a.alternate !== b6)
1730
1730
  throw Error(
1731
1731
  "Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue."
1732
1732
  );
@@ -15071,10 +15071,10 @@ var require_react_reconciler_development = __commonJS({
15071
15071
  setCurrentUpdatePriority(previousPriority), ReactSharedInternals.T = prevTransition;
15072
15072
  }
15073
15073
  };
15074
- exports2.discreteUpdates = function(fn, a, b, c, d) {
15074
+ exports2.discreteUpdates = function(fn, a, b6, c, d) {
15075
15075
  var prevTransition = ReactSharedInternals.T, previousPriority = getCurrentUpdatePriority();
15076
15076
  try {
15077
- return setCurrentUpdatePriority(2), ReactSharedInternals.T = null, fn(a, b, c, d);
15077
+ return setCurrentUpdatePriority(2), ReactSharedInternals.T = null, fn(a, b6, c, d);
15078
15078
  } finally {
15079
15079
  setCurrentUpdatePriority(previousPriority), ReactSharedInternals.T = prevTransition, executionContext === NoContext && (workInProgressRootRenderTargetTime = now$1() + RENDER_TIMEOUT_MS);
15080
15080
  }
@@ -15356,141 +15356,18 @@ var require_constants = __commonJS({
15356
15356
  // _build/test/test_react_render.js
15357
15357
  var import_jsx_runtime16 = __toESM(require_jsx_runtime(), 1);
15358
15358
  import "../lib/polyfill.js";
15359
- import * as gui19 from "gui";
15360
-
15361
- // _build/lib/react-qw/index.js
15362
15359
  import * as gui18 from "gui";
15363
15360
 
15364
- // _build/lib/react-qw/reconciler.js
15365
- var import_react_reconciler = __toESM(require_react_reconciler(), 1);
15366
- var import_react = __toESM(require_react(), 1);
15367
- var import_constants = __toESM(require_constants(), 1);
15368
- import * as gui3 from "gui";
15369
- import * as os from "os";
15370
-
15371
- // _build/lib/react-qw/props.js
15372
- import * as gui from "gui";
15373
- function applyProps(instance, newProps, _oldProps) {
15374
- const hwnd2 = instance.hwnd;
15375
- instance.props = newProps;
15376
- const textVal = "text" in newProps ? newProps.text : typeof newProps.children === "string" ? newProps.children : typeof newProps.children === "number" ? String(newProps.children) : void 0;
15377
- if (textVal !== void 0) {
15378
- let cursor = -1;
15379
- if (instance.type === "EDIT") {
15380
- const sel = gui.SendMessage(hwnd2, 176, 0, 0);
15381
- cursor = sel >>> 16;
15382
- }
15383
- gui.SetWindowText(hwnd2, textVal);
15384
- if (instance.type === "EDIT" && cursor >= 0) {
15385
- gui.SendMessage(hwnd2, 177, cursor, cursor);
15386
- }
15387
- }
15388
- if ("disabled" in newProps) {
15389
- gui.EnableWindow(hwnd2, !newProps.disabled);
15390
- }
15391
- if ("hidden" in newProps) {
15392
- gui.ShowWindow(
15393
- hwnd2,
15394
- newProps.hidden ? 0 : 5
15395
- /* gui.ShowWindowCmd.SHOW */
15396
- );
15397
- }
15398
- if ("visible" in newProps) {
15399
- gui.ShowWindow(
15400
- hwnd2,
15401
- newProps.visible ? 5 : 0
15402
- /* gui.ShowWindowCmd.HIDE */
15403
- );
15404
- }
15405
- }
15406
-
15407
- // _build/lib/react-qw/layout.js
15408
- var DEFAULT_W = 100;
15409
- var DEFAULT_H = 30;
15410
- function calculateFlexLayout(flex, parentW, parentH, children) {
15411
- const dir = flex.flexDirection || "column";
15412
- const gap = flex.gap ?? 0;
15413
- const justify = flex.justifyContent || "flex-start";
15414
- const align = flex.alignItems || "stretch";
15415
- const isRow = dir === "row";
15416
- const n = children.length;
15417
- const mainSize = isRow ? "w" : "h";
15418
- const crossSize = isRow ? "h" : "w";
15419
- const mainPos = isRow ? "x" : "y";
15420
- const crossPos = isRow ? "y" : "x";
15421
- const mainDim = isRow ? "width" : "height";
15422
- const crossDim = isRow ? "height" : "width";
15423
- const pt = flex.paddingTop ?? flex.padding ?? 0;
15424
- const pr = flex.paddingRight ?? flex.padding ?? 0;
15425
- const pb = flex.paddingBottom ?? flex.padding ?? 0;
15426
- const pl = flex.paddingLeft ?? flex.padding ?? 0;
15427
- const mainPadding = isRow ? pl + pr : pt + pb;
15428
- const crossPadding = isRow ? pt + pb : pl + pr;
15429
- const parentMain = (isRow ? parentW : parentH) - mainPadding;
15430
- const parentCross = (isRow ? parentH : parentW) - crossPadding;
15431
- const sizes = children.map((c) => ({
15432
- w: typeof c.style.width === "number" ? c.style.width : DEFAULT_W,
15433
- h: typeof c.style.height === "number" ? c.style.height : DEFAULT_H
15434
- }));
15435
- const flexGrows = children.map((c) => c.style.flexGrow ?? 0);
15436
- const totalGrow = flexGrows.reduce((s, g) => s + g, 0);
15437
- const baseMain = sizes.reduce((s, c) => s + c[mainSize], 0);
15438
- let freeGrow = parentMain - baseMain - Math.max(0, n - 1) * gap;
15439
- if (totalGrow > 0 && freeGrow > 0) {
15440
- for (let i = 0; i < n; i++) {
15441
- sizes[i][mainSize] += freeGrow * flexGrows[i] / totalGrow;
15442
- }
15443
- }
15444
- const totalMain = sizes.reduce((s, c) => s + c[mainSize], 0);
15445
- const free = parentMain - totalMain - Math.max(0, n - 1) * gap;
15446
- let offset = 0, extraGap = 0;
15447
- if (justify === "flex-end")
15448
- offset = free;
15449
- else if (justify === "center")
15450
- offset = Math.max(0, free / 2);
15451
- else if (justify === "space-between" && n > 1)
15452
- extraGap = free / (n - 1);
15453
- else if (justify === "space-around") {
15454
- extraGap = free / n;
15455
- offset = extraGap / 2;
15456
- } else if (justify === "space-evenly") {
15457
- extraGap = free / (n + 1);
15458
- offset = extraGap;
15459
- }
15460
- let cursor = offset;
15461
- return sizes.map((sz, i) => {
15462
- const childCrossBase = sz[crossSize];
15463
- const childAlign = children[i].style.alignSelf ?? "auto";
15464
- const effectiveAlign = childAlign === "auto" ? align : childAlign;
15465
- let childMain = sz[mainSize];
15466
- let childCross = childCrossBase;
15467
- const res = { x: 0, y: 0, width: 0, height: 0 };
15468
- res[mainPos] = cursor;
15469
- res[crossPos] = 0;
15470
- res[mainDim] = childMain;
15471
- res[crossDim] = childCross;
15472
- if (effectiveAlign === "stretch") {
15473
- const hasExplicitCross = typeof children[i].style[crossDim] === "number";
15474
- if (!hasExplicitCross) {
15475
- res[crossDim] = parentCross;
15476
- res[crossPos] = 0;
15477
- }
15478
- } else if (effectiveAlign === "flex-end") {
15479
- res[crossPos] = parentCross - childCross;
15480
- } else if (effectiveAlign === "center") {
15481
- res[crossPos] = Math.max(0, (parentCross - childCross) / 2);
15482
- }
15483
- cursor += childMain + gap + extraGap;
15484
- return res;
15485
- });
15486
- }
15361
+ // _build/lib/react-qw/index.js
15362
+ import * as gui17 from "gui";
15487
15363
 
15488
- // _build/lib/text-measure.js
15489
- import * as ffi2 from "ffi";
15490
- import * as gui2 from "gui";
15364
+ // _build/lib/windows/user32.js
15365
+ import * as os3 from "os";
15491
15366
 
15492
- // _build/lib/ffi-bind.js
15367
+ // _build/lib/ffi/bind.js
15493
15368
  import * as ffi from "ffi";
15369
+ import * as os2 from "os";
15370
+ import * as std from "std";
15494
15371
  import * as win from "win";
15495
15372
 
15496
15373
  // _build/lib/text-codec.js
@@ -15513,62 +15390,62 @@ function _normalizeLabel(label) {
15513
15390
  function _decodeUTF8(buf, fatal) {
15514
15391
  let out = "";
15515
15392
  for (let i = 0; i < buf.length; ) {
15516
- const b = buf[i++];
15517
- if (b < 128) {
15518
- out += String.fromCharCode(b);
15393
+ const b6 = buf[i++];
15394
+ if (b6 < 128) {
15395
+ out += String.fromCharCode(b6);
15519
15396
  continue;
15520
15397
  }
15521
- if (b < 192) {
15398
+ if (b6 < 192) {
15522
15399
  out += fatal ? (() => {
15523
15400
  throw new TypeError("unexpected continuation byte");
15524
15401
  })() : "\uFFFD";
15525
15402
  continue;
15526
15403
  }
15527
15404
  let c, min;
15528
- if (b < 224) {
15405
+ if (b6 < 224) {
15529
15406
  if (i >= buf.length) {
15530
15407
  out += fatal ? (() => {
15531
15408
  throw new TypeError("incomplete utf-8");
15532
15409
  })() : "\uFFFD";
15533
15410
  break;
15534
15411
  }
15535
- const b2 = buf[i++];
15536
- if ((b2 & 192) !== 128) {
15412
+ const b22 = buf[i++];
15413
+ if ((b22 & 192) !== 128) {
15537
15414
  out += "\uFFFD";
15538
15415
  continue;
15539
15416
  }
15540
- c = (b & 31) << 6 | b2 & 63;
15417
+ c = (b6 & 31) << 6 | b22 & 63;
15541
15418
  min = 128;
15542
- } else if (b < 240) {
15419
+ } else if (b6 < 240) {
15543
15420
  if (i + 1 >= buf.length) {
15544
15421
  out += fatal ? (() => {
15545
15422
  throw new TypeError("incomplete utf-8");
15546
15423
  })() : "\uFFFD";
15547
15424
  break;
15548
15425
  }
15549
- const b2 = buf[i++];
15550
- const b3 = buf[i++];
15551
- if ((b2 & 192) !== 128 || (b3 & 192) !== 128) {
15426
+ const b22 = buf[i++];
15427
+ const b32 = buf[i++];
15428
+ if ((b22 & 192) !== 128 || (b32 & 192) !== 128) {
15552
15429
  out += "\uFFFD";
15553
15430
  continue;
15554
15431
  }
15555
- c = (b & 15) << 12 | (b2 & 63) << 6 | b3 & 63;
15432
+ c = (b6 & 15) << 12 | (b22 & 63) << 6 | b32 & 63;
15556
15433
  min = 2048;
15557
- } else if (b < 248) {
15434
+ } else if (b6 < 248) {
15558
15435
  if (i + 2 >= buf.length) {
15559
15436
  out += fatal ? (() => {
15560
15437
  throw new TypeError("incomplete utf-8");
15561
15438
  })() : "\uFFFD";
15562
15439
  break;
15563
15440
  }
15564
- const b2 = buf[i++];
15565
- const b3 = buf[i++];
15566
- const b4 = buf[i++];
15567
- if ((b2 & 192) !== 128 || (b3 & 192) !== 128 || (b4 & 192) !== 128) {
15441
+ const b22 = buf[i++];
15442
+ const b32 = buf[i++];
15443
+ const b42 = buf[i++];
15444
+ if ((b22 & 192) !== 128 || (b32 & 192) !== 128 || (b42 & 192) !== 128) {
15568
15445
  out += "\uFFFD";
15569
15446
  continue;
15570
15447
  }
15571
- c = (b & 7) << 18 | (b2 & 63) << 12 | (b3 & 63) << 6 | b4 & 63;
15448
+ c = (b6 & 7) << 18 | (b22 & 63) << 12 | (b32 & 63) << 6 | b42 & 63;
15572
15449
  min = 65536;
15573
15450
  } else {
15574
15451
  out += fatal ? (() => {
@@ -15706,65 +15583,166 @@ if (typeof globalThis.TextEncoder === "undefined") {
15706
15583
  globalThis.TextEncoder = TextEncoderImpl;
15707
15584
  }
15708
15585
 
15709
- // _build/lib/ffi-bind.js
15710
- var KIND_TO_FFI = {
15711
- void: ffi.FFI_TYPE_VOID,
15712
- u8: ffi.FFI_TYPE_UINT8,
15713
- i8: ffi.FFI_TYPE_SINT8,
15714
- u16: ffi.FFI_TYPE_UINT16,
15715
- i16: ffi.FFI_TYPE_SINT16,
15716
- u32: ffi.FFI_TYPE_UINT32,
15717
- i32: ffi.FFI_TYPE_SINT32,
15718
- u64: ffi.FFI_TYPE_UINT64,
15719
- i64: ffi.FFI_TYPE_SINT64,
15720
- f32: ffi.FFI_TYPE_FLOAT,
15721
- f64: ffi.FFI_TYPE_DOUBLE,
15722
- ptr: ffi.FFI_TYPE_POINTER,
15723
- wstr: ffi.FFI_TYPE_POINTER
15586
+ // _build/lib/ffi/ctype.js
15587
+ import { bufferPtr } from "ffi";
15588
+ import * as os from "os";
15589
+ var C_BASIC_TYPE = [
15590
+ "void",
15591
+ "u8",
15592
+ "i8",
15593
+ "u16",
15594
+ "i16",
15595
+ "u32",
15596
+ "i32",
15597
+ "u64",
15598
+ "i64",
15599
+ "f32",
15600
+ "f64",
15601
+ "ptr"
15602
+ ];
15603
+ var PTR_TOKEN_RE = /^<([A-Za-z_]\w*|)>ptr(!|@[A-Za-z_]\w*)?$/;
15604
+ function isCPtrToken(t) {
15605
+ return PTR_TOKEN_RE.test(t);
15606
+ }
15607
+ var VAL_TOKEN_RE = /^<([A-Za-z_]\w*)>$/;
15608
+ function isCValToken(t) {
15609
+ return VAL_TOKEN_RE.test(t);
15610
+ }
15611
+ function valName(t) {
15612
+ const m = VAL_TOKEN_RE.exec(t);
15613
+ return m?.[1] || "";
15614
+ }
15615
+ function ptrName(t) {
15616
+ const m = PTR_TOKEN_RE.exec(t);
15617
+ return m?.[1] || "";
15618
+ }
15619
+ var cTokenToType = (t) => {
15620
+ if (isCPtrToken(t))
15621
+ return "ptr";
15622
+ if (isCValToken(t))
15623
+ throw new Error(`ffi: cTokenToType: by-value token "${t}" has no scalar slot type`);
15624
+ return t;
15625
+ };
15626
+ var PTR_SIZE = os.arch === "x64" ? 8 : 4;
15627
+ var SizeAlign = {
15628
+ u8: 1,
15629
+ i8: 1,
15630
+ u16: 2,
15631
+ i16: 2,
15632
+ u32: 4,
15633
+ i32: 4,
15634
+ u64: 8,
15635
+ i64: 8,
15636
+ f32: 4,
15637
+ f64: 8
15724
15638
  };
15725
- var C_ALIAS = {
15726
- int: "i32",
15727
- long: "i32",
15728
- short: "i16",
15729
- char: "i8",
15730
- float: "f32",
15731
- double: "f64",
15732
- DWORD: "u32",
15733
- UINT: "u32",
15734
- ULONG: "u32",
15735
- LONG: "i32",
15736
- BOOL: "i32",
15737
- HRESULT: "i32",
15738
- SHORT: "i16",
15739
- USHORT: "u16",
15740
- BYTE: "u8",
15741
- LONG_PTR: "ptr",
15742
- ULONG_PTR: "ptr",
15743
- INT_PTR: "ptr",
15744
- UINT_PTR: "ptr",
15745
- DWORD_PTR: "ptr",
15746
- SIZE_T: "ptr",
15747
- WPARAM: "ptr",
15748
- LPARAM: "ptr",
15749
- HANDLE: "ptr",
15750
- HWND: "ptr",
15751
- HDC: "ptr",
15752
- HMODULE: "ptr",
15753
- HFONT: "ptr",
15754
- HBRUSH: "ptr",
15755
- HICON: "ptr",
15756
- HBITMAP: "ptr",
15757
- LPVOID: "ptr",
15758
- LPCVOID: "ptr",
15759
- LPCWSTR: "ptr",
15760
- PCWSTR: "ptr",
15761
- LPWSTR: "ptr"
15639
+ var NULL = 0;
15640
+ function normToken(t) {
15641
+ if (isCPtrToken(t)) {
15642
+ const m = PTR_TOKEN_RE.exec(t);
15643
+ const name = m?.[1] || "";
15644
+ const mod = m?.[2];
15645
+ return mod?.startsWith("@") ? `<${name}>ptr` : t;
15646
+ }
15647
+ if (isCValToken(t))
15648
+ return t;
15649
+ const at = t.indexOf("@");
15650
+ const base = at >= 0 ? t.slice(0, at) : t;
15651
+ const suffixOk = at < 0 || /^[A-Za-z_]\w*$/.test(t.slice(at + 1));
15652
+ if (suffixOk && base !== "ptr" && C_BASIC_TYPE.includes(base))
15653
+ return base;
15654
+ throw new Error("Unknown token: " + t);
15655
+ }
15656
+ function readScalar(dv, off, k) {
15657
+ switch (k) {
15658
+ case "u8":
15659
+ return dv.getUint8(off);
15660
+ case "i8":
15661
+ return dv.getInt8(off);
15662
+ case "u16":
15663
+ return dv.getUint16(off, true);
15664
+ case "i16":
15665
+ return dv.getInt16(off, true);
15666
+ case "u32":
15667
+ return dv.getUint32(off, true);
15668
+ case "i32":
15669
+ return dv.getInt32(off, true);
15670
+ case "u64":
15671
+ return dv.getBigUint64(off, true);
15672
+ case "i64":
15673
+ return dv.getBigInt64(off, true);
15674
+ case "f32":
15675
+ return dv.getFloat32(off, true);
15676
+ case "f64":
15677
+ return dv.getFloat64(off, true);
15678
+ case "ptr": {
15679
+ return PTR_SIZE === 8 ? Number(dv.getBigInt64(off, true)) : dv.getInt32(off, true);
15680
+ }
15681
+ }
15682
+ }
15683
+ function writeScalar(dv, off, { k, v }) {
15684
+ switch (k) {
15685
+ case "u8":
15686
+ dv.setUint8(off, Number(v));
15687
+ break;
15688
+ case "i8":
15689
+ dv.setInt8(off, Number(v));
15690
+ break;
15691
+ case "u16":
15692
+ dv.setUint16(off, Number(v), true);
15693
+ break;
15694
+ case "i16":
15695
+ dv.setInt16(off, Number(v), true);
15696
+ break;
15697
+ case "u32":
15698
+ dv.setUint32(off, v >>> 0, true);
15699
+ break;
15700
+ case "i32":
15701
+ dv.setUint32(off, v >>> 0, true);
15702
+ break;
15703
+ case "u64":
15704
+ dv.setBigUint64(off, v, true);
15705
+ break;
15706
+ case "i64":
15707
+ dv.setBigInt64(off, v, true);
15708
+ break;
15709
+ case "f32":
15710
+ dv.setFloat32(off, v, true);
15711
+ break;
15712
+ case "f64":
15713
+ dv.setFloat64(off, v, true);
15714
+ break;
15715
+ case "ptr": {
15716
+ if (v == null) {
15717
+ throw new Error("ffi: got null/undefined for a ptr slot; pass the imported NULL constant for empty");
15718
+ }
15719
+ if (PTR_SIZE === 8)
15720
+ dv.setBigUint64(off, BigInt.asUintN(64, BigInt(v)), true);
15721
+ else
15722
+ dv.setUint32(off, v >>> 0, true);
15723
+ break;
15724
+ }
15725
+ }
15726
+ }
15727
+ function writeSlot(dv, off, e) {
15728
+ const { k, v } = e;
15729
+ if (k === "u8" || k === "i8" || k === "u16" || k === "i16") {
15730
+ dv.setUint32(off, Number(v) >>> 0, true);
15731
+ return;
15732
+ }
15733
+ writeScalar(dv, off, e);
15734
+ }
15735
+ var PtrArrayBuffer = class extends ArrayBuffer {
15736
+ ptr;
15737
+ constructor(byteLength) {
15738
+ super(byteLength);
15739
+ this.ptr = bufferPtr(this);
15740
+ }
15762
15741
  };
15763
- function normKind(t) {
15764
- const k = C_ALIAS[t] ?? t;
15765
- if (!(k in KIND_TO_FFI))
15766
- throw new Error(`ffi-bind: invalid kind "${t}"`);
15767
- return k;
15742
+
15743
+ // _build/lib/ffi/bind.js
15744
+ function valCodec(name, encoders) {
15745
+ return encoders[name];
15768
15746
  }
15769
15747
  var _dllCache = /* @__PURE__ */ new Map();
15770
15748
  function loadDll(dll) {
@@ -15779,77 +15757,1011 @@ function loadDll(dll) {
15779
15757
  }
15780
15758
  function parseSig(sig) {
15781
15759
  const parts = sig.split(" -> ");
15782
- const ret = parts[1];
15783
- if (ret === void 0 || parts.length > 2) {
15760
+ if (parts.length !== 2) {
15784
15761
  throw new Error(`ffi-bind: invalid signature "${sig}" (expected "arg1 arg2 -> ret")`);
15785
15762
  }
15786
- const retK = normKind(ret);
15787
- if (retK === "wstr")
15788
- throw new Error('ffi-bind: "wstr" cannot be a return type');
15789
- const tokens = (parts[0] ?? "") === "" ? [] : parts[0].split(" ");
15790
- const args = tokens.map((t) => normKind(t));
15791
- return { args, ret: retK };
15763
+ const rawArgs = parts[0].split(" ").filter((t) => t !== "");
15764
+ const argTokens = [];
15765
+ for (const raw of rawArgs) {
15766
+ const tok = normToken(raw);
15767
+ if (tok === "void") {
15768
+ throw new Error("Void can not in args");
15769
+ }
15770
+ argTokens.push(tok);
15771
+ }
15772
+ const retToken = normToken(parts[1]);
15773
+ if (isCValToken(retToken))
15774
+ throw new Error(`ffi-bind: "${sig}": by-value struct at the return position (<${valName(retToken)}>) is not supported \u2014 argument positions only; pass a struct out through an out-param slot instead (<N>ptr + caller buffer)`);
15775
+ return {
15776
+ argTokens,
15777
+ retToken,
15778
+ sig
15779
+ };
15780
+ }
15781
+ function makeFn(proc, sig, encoders, decoders) {
15782
+ const ps = parseSig(sig);
15783
+ for (const t of ps.argTokens) {
15784
+ if (!isCValToken(t))
15785
+ continue;
15786
+ const name = valName(t);
15787
+ const codec = valCodec(name, encoders);
15788
+ if (!codec || typeof codec.encode !== "function")
15789
+ throw new Error(`ffi-bind: ${sig}: by-value position <${name}> has no registered layout (available: ${Object.keys(encoders).join(", ") || "none"})`);
15790
+ if (typeof codec.size !== "number" || codec.size < 1)
15791
+ throw new Error(`ffi-bind: ${sig}: by-value position <${name}> requires a struct layout with size >= 1 (got ${codec.size}; non-struct codecs expose no size)`);
15792
+ }
15793
+ return (...a) => callPacked(proc, ps, a, encoders, decoders);
15792
15794
  }
15793
- function makeFn(proc, sig) {
15794
- const { args, ret } = parseSig(sig);
15795
- const argTypes = args.map((k) => KIND_TO_FFI[k]);
15796
- const retType = KIND_TO_FFI[ret];
15797
- return (...a) => {
15798
- const vals = args.map((k, i) => k === "wstr" ? new TextEncoder("utf-16le").encode(String(a[i]) + "\0").buffer : a[i]);
15799
- return ffi.ffiCall(proc, argTypes, vals, retType);
15795
+ var IA32_ARG_SIZE = {
15796
+ u8: 4,
15797
+ i8: 4,
15798
+ u16: 4,
15799
+ i16: 4,
15800
+ u32: 4,
15801
+ i32: 4,
15802
+ u64: 8,
15803
+ i64: 8,
15804
+ f32: 4,
15805
+ f64: 8,
15806
+ ptr: PTR_SIZE
15807
+ };
15808
+ var X64_MIN_SLOTS = 4;
15809
+ function callPacked(proc, { argTokens, retToken, sig }, args, encoders, decoders) {
15810
+ const is64 = os2.arch === "x64";
15811
+ const getWidth = (t, is642) => {
15812
+ if (isCValToken(t))
15813
+ throw new Error(`ffi-bind: getWidth: by-value token "${t}" (dispatched by widthOf)`);
15814
+ if (is642)
15815
+ return 8;
15816
+ if (isCPtrToken(t))
15817
+ return PTR_SIZE;
15818
+ return IA32_ARG_SIZE[t];
15819
+ };
15820
+ const widthOf = (t) => {
15821
+ if (isCValToken(t)) {
15822
+ if (is64)
15823
+ return 8;
15824
+ const layout = valCodec(valName(t), encoders);
15825
+ if (!layout)
15826
+ throw new Error(`ffi-bind: <${valName(t)}> by-value position has no registered layout`);
15827
+ const size = layout.size;
15828
+ return size % 4 === 0 ? size : size + 4 - size % 4;
15829
+ }
15830
+ return getWidth(t, is64);
15800
15831
  };
15832
+ let total = 0;
15833
+ for (const t of argTokens)
15834
+ total += widthOf(t);
15835
+ if (is64 && argTokens.length < X64_MIN_SLOTS)
15836
+ total = X64_MIN_SLOTS * 8;
15837
+ const argFrame = new ArrayBuffer(total);
15838
+ const dv = new DataView(argFrame);
15839
+ const held = [];
15840
+ let off = 0;
15841
+ for (let i = 0; i < argTokens.length; i++) {
15842
+ const argToken = argTokens[i];
15843
+ const nonnull = argToken.endsWith("!");
15844
+ const arg = args[i];
15845
+ if (isCPtrToken(argToken)) {
15846
+ const name = ptrName(argToken);
15847
+ if (typeof arg === "number") {
15848
+ if (nonnull && arg === 0)
15849
+ throw new Error(`ffi-bind: ${sig}: arg#${i + 1} <${name}>ptr! got 0 (null pointer forbidden here; the token marks this position non-null)`);
15850
+ writeSlot(dv, off, { k: "ptr", v: arg });
15851
+ } else {
15852
+ if (arg === null || arg === void 0) {
15853
+ throw new Error(`ffi-bind: <${name}>ptr got ${String(arg)}; pass the imported NULL constant for an empty pointer`);
15854
+ }
15855
+ const codec = encoders[name];
15856
+ if (!codec) {
15857
+ throw new Error(name === "" ? `ffi-bind: <>ptr expects number (NULL | Ptr), got ${typeof arg}; use <BYTE>ptr with a PtrArrayBuffer (new PtrArrayBuffer(n)), or ffi.bufferPtr(buf) for an address` : `ffi-bind: unknown layout "<${name}>ptr" (available: ${Object.keys(encoders).join(", ") || "none"})`);
15858
+ }
15859
+ if (!codec.encode) {
15860
+ throw new Error(`ffi-bind: <${name}>ptr has no encoder (out-only codec)`);
15861
+ }
15862
+ const buf = codec.encode(arg);
15863
+ held.push(buf);
15864
+ const p = buf.ptr;
15865
+ if (typeof p !== "number")
15866
+ throw new Error("ffi-bind: codec.encode must return a PtrArrayBuffer, got plain ArrayBuffer");
15867
+ if (nonnull && p === 0)
15868
+ throw new Error(`ffi-bind: ${sig}: arg#${i + 1} <${name}>ptr! encode produced 0 (null pointer forbidden here)`);
15869
+ writeSlot(dv, off, { k: "ptr", v: p });
15870
+ }
15871
+ } else if (isCValToken(argToken)) {
15872
+ const name = valName(argToken);
15873
+ const codec = valCodec(name, encoders);
15874
+ if (!codec)
15875
+ throw new Error(`ffi-bind: ${sig}: arg#${i + 1} <${name}> by-value position has no registered layout`);
15876
+ if (arg === null || arg === void 0)
15877
+ throw new Error(`ffi-bind: <${name}> value position got ${String(arg)}; pass a struct object (use <${name}>ptr to pass a pointer)`);
15878
+ const size = codec.size;
15879
+ if (!is64 || size <= 8 && (size & size - 1) === 0) {
15880
+ codec.encode(arg, argFrame, off);
15881
+ } else {
15882
+ const buf = new ArrayBuffer(size + 15);
15883
+ const base = ffi.bufferPtr(buf);
15884
+ const pad = (16 - base % 16) % 16;
15885
+ codec.encode(arg, buf, pad);
15886
+ held.push(buf);
15887
+ writeSlot(dv, off, { k: "ptr", v: base + pad });
15888
+ }
15889
+ } else {
15890
+ writeSlot(dv, off, { k: argToken, v: arg });
15891
+ }
15892
+ off += widthOf(argToken);
15893
+ }
15894
+ const retBuf = new ArrayBuffer(8);
15895
+ const retIsFp = retToken === "f32" || retToken === "f64";
15896
+ ffi.ffiCall(proc, argFrame, retBuf, retIsFp ? 1 : 0);
15897
+ const raw = readRet(cTokenToType(retToken), retBuf);
15898
+ if (retToken.endsWith("!") && raw === 0)
15899
+ throw new Error(`ffi-bind: ${sig}: return ${retToken} got 0 (the token promises C never returns null here)`);
15900
+ if (isCPtrToken(retToken) && raw !== 0) {
15901
+ const name = ptrName(retToken);
15902
+ if (name !== "") {
15903
+ const codec = decoders[name];
15904
+ if (codec?.decode)
15905
+ return codec.decode(raw);
15906
+ }
15907
+ }
15908
+ return raw;
15801
15909
  }
15802
- function bindLib(dll, map) {
15803
- const out = {};
15804
- const h = loadDll(dll);
15805
- for (const [name, sig] of Object.entries(map)) {
15806
- const proc = win.GetProcAddress(h, name);
15807
- if (!proc)
15808
- throw new Error(`ffi-bind: proc "${name}" not found in ${dll}`);
15809
- out[name] = makeFn(proc, sig);
15910
+ function readRet(ret, retBuf) {
15911
+ if (ret === "void")
15912
+ return void 0;
15913
+ return readScalar(new DataView(retBuf), 0, ret);
15914
+ }
15915
+ var WCHAR = {
15916
+ encode: (v) => {
15917
+ const u8 = new TextEncoder("utf-16le").encode(v + "\0");
15918
+ const out = new PtrArrayBuffer(u8.byteLength);
15919
+ new Uint8Array(out).set(u8);
15920
+ return out;
15921
+ },
15922
+ decode: (p) => {
15923
+ if (typeof p === "number") {
15924
+ let s2 = "";
15925
+ let addr = p;
15926
+ const start = addr;
15927
+ for (; ; ) {
15928
+ const lo = ffi.readByte(addr);
15929
+ const hi = ffi.readByte(addr + 1);
15930
+ if (lo === 0 && hi === 0)
15931
+ return s2;
15932
+ s2 += String.fromCharCode(lo | hi << 8);
15933
+ addr += 2;
15934
+ if (addr - start > 1 << 21) {
15935
+ throw new Error("ffi-bind: WCHAR decode exceeded 4MiB without NUL");
15936
+ }
15937
+ }
15938
+ }
15939
+ const u8 = new Uint8Array(p);
15940
+ const limit = u8.length & ~1;
15941
+ let s = "";
15942
+ for (let i = 0; i < limit; i += 2) {
15943
+ const c = u8[i] | u8[i + 1] << 8;
15944
+ if (c === 0)
15945
+ return s;
15946
+ s += String.fromCharCode(c);
15947
+ }
15948
+ return s;
15949
+ },
15950
+ alloc: (size = 256) => new PtrArrayBuffer(size * 2)
15951
+ };
15952
+ var BYTE = {
15953
+ encode: (v) => {
15954
+ if (!(v instanceof PtrArrayBuffer))
15955
+ throw new Error("ffi-bind: <BYTE>ptr wants a PtrArrayBuffer (new PtrArrayBuffer(n) / BYTE.alloc / struct.encode), not a plain ArrayBuffer");
15956
+ return v;
15957
+ },
15958
+ alloc: (byteLen) => new PtrArrayBuffer(byteLen)
15959
+ };
15960
+ var builtinCodecs = { WCHAR, BYTE };
15961
+ function bind(dll, name, sig, encoders, decoders) {
15962
+ const proc = win.GetProcAddress(loadDll(dll), name);
15963
+ if (!proc)
15964
+ throw new Error(`ffi-bind: proc "${name}" not found in ${dll}`);
15965
+ const effDec = decoders ?? encoders;
15966
+ return makeFn(proc, sig, { ...builtinCodecs, ...encoders }, { ...builtinCodecs, ...effDec ?? {} });
15967
+ }
15968
+ var leakRegistry = new FinalizationRegistry((held) => {
15969
+ std.printf('[ffi] closure leaked (GCed without dispose): sig="%s" ptr=0x%x\n', held.sig, held.ptr);
15970
+ });
15971
+
15972
+ // _build/lib/ffi/struct.js
15973
+ import * as ffi2 from "ffi";
15974
+ function alignUp(v, a) {
15975
+ return v + a - 1 & ~(a - 1);
15976
+ }
15977
+ var isCNumberToken = (t) => SizeAlign[t] !== void 0;
15978
+ function lower(v) {
15979
+ if (typeof v === "string") {
15980
+ const st = /^(u8|u16)\[(\d+)\]@(utf-8|utf-16le)$/.exec(v);
15981
+ if (st) {
15982
+ const length = Number(st[2]);
15983
+ if (!Number.isInteger(length) || length < 1)
15984
+ throw new Error(`ffi-struct: string length must be an integer >= 1, got ${length}`);
15985
+ const s2 = st[1] === "u8" ? 1 : 2;
15986
+ return { size: s2 * length, align: s2, type: { tag: "string", encoding: st[3] } };
15987
+ }
15988
+ const a = /^([^\[\]]+)\[(\d+)\]$/.exec(v);
15989
+ if (a) {
15990
+ const length = Number(a[2]);
15991
+ if (!Number.isInteger(length) || length < 1)
15992
+ throw new Error(`ffi-struct: array length must be an integer >= 1, got ${length}`);
15993
+ const el = lower(a[1]);
15994
+ if (el.type.tag === "bitfield")
15995
+ throw new Error("ffi-struct: bitfields cannot be array elements");
15996
+ return {
15997
+ size: el.size * length,
15998
+ align: el.align,
15999
+ type: { tag: "array", elementType: el.type, elementSize: el.size }
16000
+ };
16001
+ }
16002
+ const b6 = /^([A-Za-z_]\w*):(\d+)$/.exec(v);
16003
+ if (b6) {
16004
+ const rawUnit = b6[1];
16005
+ const unit = normToken(rawUnit);
16006
+ if (!isCNumberToken(unit) || unit === "f32" || unit === "f64")
16007
+ throw new Error(`ffi-struct: bitfield unit must be an integer type, got "${rawUnit}"`);
16008
+ const width = Number(b6[2]);
16009
+ const s2 = SizeAlign[unit];
16010
+ const cap = s2 * 8;
16011
+ if (!Number.isInteger(width) || width < 1)
16012
+ throw new Error(`ffi-struct: bitfield width must be an integer >= 1, got ${width}`);
16013
+ if (width > cap)
16014
+ throw new Error(`ffi-struct: bitfield width ${width} exceeds unit width ${cap}`);
16015
+ return { size: s2, align: s2, type: { tag: "bitfield", unit, bit: 0, width } };
16016
+ }
16017
+ const k = normToken(v);
16018
+ if (isCPtrToken(k))
16019
+ return { size: PTR_SIZE, align: PTR_SIZE, type: { tag: "basic", kind: "ptr" } };
16020
+ if (!isCNumberToken(k))
16021
+ throw new Error(`ffi-struct: unknown kind "${v}"`);
16022
+ const s = SizeAlign[k];
16023
+ return { size: s, align: s, type: { tag: "basic", kind: k } };
15810
16024
  }
15811
- return out;
16025
+ if (v && typeof v === "object") {
16026
+ const o = v;
16027
+ const tag = o["#"];
16028
+ if (tag === void 0)
16029
+ throw new Error(`ffi-struct: nested object value requires a '#' key ('struct' | 'union' | 'array')`);
16030
+ if (tag === "array" && "#pack" in o)
16031
+ throw new Error(`ffi-struct: '#pack' is only allowed on struct/union, got '${tag}'`);
16032
+ if (tag === "array") {
16033
+ const length = o["length"];
16034
+ if (!Number.isInteger(length) || length < 1)
16035
+ throw new Error(`ffi-struct: array length must be an integer >= 1, got ${String(length)}`);
16036
+ const el = lower(o["element"]);
16037
+ if (el.type.tag === "bitfield")
16038
+ throw new Error("ffi-struct: bitfields cannot be array elements");
16039
+ return {
16040
+ size: el.size * length,
16041
+ align: el.align,
16042
+ type: { tag: "array", elementType: el.type, elementSize: el.size }
16043
+ };
16044
+ }
16045
+ if (tag === "struct" || tag === "union") {
16046
+ const l = computeStructLayout(v);
16047
+ return { size: l.size, align: l.maxEffectiveAlign, type: { tag, fields: l.fields } };
16048
+ }
16049
+ throw new Error(`ffi-struct: unknown '#' declaration ${JSON.stringify(String(tag))}`);
16050
+ }
16051
+ throw new Error(`ffi-struct: invalid member value: ${String(v)}`);
16052
+ }
16053
+ function computeStructLayout(t) {
16054
+ const isStruct = t["#"] === "struct";
16055
+ const pack = t["#pack"] ?? 8;
16056
+ let maxEffectiveAlign = 1;
16057
+ let maxMemberSize = 0;
16058
+ const fields = [];
16059
+ let cursor = 0;
16060
+ let unitBase = -1;
16061
+ let unitBits = 0;
16062
+ let unitSize = 0;
16063
+ const flushUnit = () => {
16064
+ if (unitBase < 0)
16065
+ return;
16066
+ cursor = alignUp(unitBase + Math.ceil(unitBits / 8), unitSize);
16067
+ unitBase = -1;
16068
+ };
16069
+ for (const [rawName, v] of Object.entries(t)) {
16070
+ if (rawName.startsWith("#"))
16071
+ continue;
16072
+ const m = /^([^@]+)@(\d+)$/.exec(rawName);
16073
+ const name = m ? m[1] : rawName;
16074
+ const alignas = m ? Number(m[2]) : 0;
16075
+ const { size, align: natural, type } = lower(v);
16076
+ const nonnull = typeof v === "string" && v.endsWith("!");
16077
+ let align = natural;
16078
+ if (pack > 0)
16079
+ align = Math.min(pack, align);
16080
+ if (alignas)
16081
+ align = Math.max(align, alignas);
16082
+ if (type.tag === "bitfield") {
16083
+ if (name.startsWith("$"))
16084
+ throw new Error("ffi-struct: bitfield members must be named");
16085
+ if (!isStruct) {
16086
+ fields.push({ name, offset: 0, size, type: { ...type, bit: 0 } });
16087
+ maxEffectiveAlign = Math.max(maxEffectiveAlign, align);
16088
+ maxMemberSize = Math.max(maxMemberSize, size);
16089
+ continue;
16090
+ }
16091
+ const width = type.width;
16092
+ if (unitBase < 0 || size !== unitSize || unitBits + width > unitSize * 8) {
16093
+ if (unitBase >= 0)
16094
+ flushUnit();
16095
+ const offset2 = alignUp(cursor, align);
16096
+ unitBase = offset2;
16097
+ unitBits = 0;
16098
+ unitSize = size;
16099
+ }
16100
+ fields.push({
16101
+ name,
16102
+ offset: unitBase,
16103
+ // 单元基址(不是位域自己的地址)
16104
+ size,
16105
+ type: { ...type, bit: unitBits }
16106
+ });
16107
+ unitBits += width;
16108
+ maxEffectiveAlign = Math.max(maxEffectiveAlign, align);
16109
+ maxMemberSize = Math.max(maxMemberSize, size);
16110
+ continue;
16111
+ }
16112
+ flushUnit();
16113
+ const offset = alignUp(cursor, align);
16114
+ if (!name.startsWith("$")) {
16115
+ fields.push({ name, offset, size, type, ...nonnull ? { nonnull: true } : {} });
16116
+ } else {
16117
+ if (type.tag !== "struct" && type.tag !== "union")
16118
+ throw new Error(`ffi-struct: anonymous member "${name}" must be a struct/union`);
16119
+ for (const cf of type.fields)
16120
+ fields.push({ ...cf, offset: cf.offset + offset });
16121
+ }
16122
+ if (isStruct)
16123
+ cursor = offset + size;
16124
+ maxEffectiveAlign = Math.max(maxEffectiveAlign, align);
16125
+ maxMemberSize = Math.max(maxMemberSize, size);
16126
+ }
16127
+ flushUnit();
16128
+ return {
16129
+ size: isStruct ? alignUp(cursor, maxEffectiveAlign) : alignUp(maxMemberSize, maxEffectiveAlign),
16130
+ maxEffectiveAlign,
16131
+ fields
16132
+ };
16133
+ }
16134
+ function readUnitRaw(dv, off, unit) {
16135
+ const s = SizeAlign[unit];
16136
+ if (s === 1)
16137
+ return BigInt(dv.getUint8(off));
16138
+ if (s === 2)
16139
+ return BigInt(dv.getUint16(off, true));
16140
+ if (s === 4)
16141
+ return BigInt(dv.getUint32(off, true));
16142
+ return dv.getBigUint64(off, true);
16143
+ }
16144
+ function writeUnitRaw(dv, off, unit, v) {
16145
+ const s = SizeAlign[unit];
16146
+ if (s === 1) {
16147
+ dv.setUint8(off, Number(v & 0xffn));
16148
+ return;
16149
+ }
16150
+ if (s === 2) {
16151
+ dv.setUint16(off, Number(v & 0xffffn), true);
16152
+ return;
16153
+ }
16154
+ if (s === 4) {
16155
+ dv.setUint32(off, Number(v & 0xffffffffn), true);
16156
+ return;
16157
+ }
16158
+ dv.setBigUint64(off, v & 0xffffffffffffffffn, true);
16159
+ }
16160
+ function readBitfield(dv, off, t) {
16161
+ const w = BigInt(t.width);
16162
+ let v = readUnitRaw(dv, off, t.unit) >> BigInt(t.bit) & (1n << w) - 1n;
16163
+ if (t.unit[0] === "i" && v & 1n << w - 1n)
16164
+ v -= 1n << w;
16165
+ if (t.width > 53)
16166
+ return v;
16167
+ return Number(v);
16168
+ }
16169
+ function writeBitfield(dv, off, t, val) {
16170
+ const w = BigInt(t.width);
16171
+ const bit = BigInt(t.bit);
16172
+ const widthMask = (1n << w) - 1n;
16173
+ const posMask = widthMask << bit;
16174
+ const raw = readUnitRaw(dv, off, t.unit);
16175
+ const bits = (typeof val === "bigint" ? val : BigInt(Math.trunc(val))) & widthMask;
16176
+ writeUnitRaw(dv, off, t.unit, raw & ~posMask | bits << bit);
16177
+ }
16178
+ var stringEncoders = {
16179
+ "utf-8": new TextEncoder("utf-8"),
16180
+ "utf-16le": new TextEncoder("utf-16le")
16181
+ };
16182
+ var stringDecoders = {
16183
+ "utf-8": new TextDecoder("utf-8", { ignoreBOM: true }),
16184
+ "utf-16le": new TextDecoder("utf-16le", { ignoreBOM: true })
16185
+ };
16186
+ function readString(dv, off, size, enc) {
16187
+ const bytes = new Uint8Array(dv.buffer, dv.byteOffset + off, size);
16188
+ const unit = enc === "utf-16le" ? 2 : 1;
16189
+ let end = size;
16190
+ for (let i = 0; i + unit <= size; i += unit) {
16191
+ if (bytes[i] === 0 && (unit === 1 || bytes[i + 1] === 0)) {
16192
+ end = i;
16193
+ break;
16194
+ }
16195
+ }
16196
+ return stringDecoders[enc].decode(bytes.subarray(0, end));
16197
+ }
16198
+ function writeString(dv, off, size, enc, v) {
16199
+ const bytes = new Uint8Array(dv.buffer, dv.byteOffset + off, size);
16200
+ bytes.fill(0);
16201
+ const unit = enc === "utf-16le" ? 2 : 1;
16202
+ const cap = size - unit;
16203
+ if (cap <= 0)
16204
+ return;
16205
+ const src = stringEncoders[enc].encode(String(v ?? ""));
16206
+ bytes.set(src.subarray(0, Math.min(src.length, cap)));
16207
+ }
16208
+ function readArray(dv, off, size, t) {
16209
+ const count = t.elementSize > 0 ? size / t.elementSize : 0;
16210
+ const out = [];
16211
+ for (let i = 0; i < count; i++)
16212
+ out.push(readElement(dv, off + i * t.elementSize, t.elementType, t.elementSize));
16213
+ return out;
16214
+ }
16215
+ function writeArray(dv, off, size, t, v) {
16216
+ const count = t.elementSize > 0 ? size / t.elementSize : 0;
16217
+ const list = v ?? [];
16218
+ for (let i = 0; i < count; i++)
16219
+ writeElement(dv, off + i * t.elementSize, t.elementType, t.elementSize, list[i]);
16220
+ }
16221
+ function readElement(dv, off, t, size) {
16222
+ switch (t.tag) {
16223
+ case "basic":
16224
+ return readScalar(dv, off, t.kind);
16225
+ case "bitfield":
16226
+ return readBitfield(dv, off, t);
16227
+ case "string":
16228
+ return readString(dv, off, size, t.encoding);
16229
+ case "struct":
16230
+ case "union":
16231
+ return doDecode(dv, off, t.fields);
16232
+ case "array":
16233
+ return readArray(dv, off, size, t);
16234
+ }
16235
+ }
16236
+ function writeElement(dv, off, t, size, val) {
16237
+ switch (t.tag) {
16238
+ // TODO: remove this any
16239
+ case "basic":
16240
+ writeScalar(dv, off, { k: t.kind, v: val });
16241
+ break;
16242
+ // 直传(不 Number()):writeBitfield 的 val 是 number | bigint,
16243
+ // 64 位单元走 bigint,先 Number() 会把 >2^53 的位域值截断。
16244
+ case "bitfield":
16245
+ writeBitfield(dv, off, t, val ?? 0);
16246
+ break;
16247
+ case "string":
16248
+ writeString(dv, off, size, t.encoding, val);
16249
+ break;
16250
+ case "struct":
16251
+ case "union":
16252
+ doEncode(dv, off, t.fields, val ?? {});
16253
+ break;
16254
+ case "array":
16255
+ writeArray(dv, off, size, t, val);
16256
+ break;
16257
+ }
16258
+ }
16259
+ function doDecode(dv, base, fields) {
16260
+ const out = {};
16261
+ for (const f of fields) {
16262
+ const v = readElement(dv, base + f.offset, f.type, f.size);
16263
+ if (f.nonnull && v === 0)
16264
+ throw new Error(`ffi-struct: decode: '!' field "${f.name}" got 0 (C did not fill it, or decode was called on an unfilled slot)`);
16265
+ out[f.name] = v;
16266
+ }
16267
+ return out;
16268
+ }
16269
+ function doEncode(dv, base, fields, v) {
16270
+ for (const f of fields) {
16271
+ if (v[f.name] === void 0)
16272
+ continue;
16273
+ writeElement(dv, base + f.offset, f.type, f.size, v[f.name]);
16274
+ }
16275
+ }
16276
+ function createStruct(t) {
16277
+ const { fields, size, maxEffectiveAlign } = computeStructLayout(t);
16278
+ return {
16279
+ __struct: t,
16280
+ size,
16281
+ structAlign: maxEffectiveAlign,
16282
+ decode: (p) => {
16283
+ if (typeof p === "number")
16284
+ return doDecode(new DataView(ffi2.readBytes(p, size)), 0, fields);
16285
+ return doDecode(new DataView(p), 0, fields);
16286
+ },
16287
+ alloc: ((n) => {
16288
+ if (n !== void 0 && (!Number.isInteger(n) || n < 1))
16289
+ throw new Error(`ffi-struct: alloc(n) requires an integer n >= 1 (PAB(0) never escapes \u2014 pass NULL for an empty pointer position)`);
16290
+ return new PtrArrayBuffer(size * (n ?? 1));
16291
+ }),
16292
+ encode: ((v, buf, offset) => {
16293
+ if (v === void 0 || v === null)
16294
+ throw new Error(`ffi-struct: encode(v) requires an argument; use alloc() for a zeroed out-param slot`);
16295
+ const out = buf ?? new PtrArrayBuffer(size);
16296
+ doEncode(new DataView(out), offset ?? 0, fields, v);
16297
+ return out;
16298
+ }),
16299
+ offsetOf: (name) => {
16300
+ for (const f of fields)
16301
+ if (f.name === name)
16302
+ return f.offset;
16303
+ throw new Error(`ffi-struct: no field "${name}"`);
16304
+ }
16305
+ };
16306
+ }
16307
+ function buildDecl(kind, member, pack) {
16308
+ const decl = { "#": kind };
16309
+ if (pack !== void 0)
16310
+ decl["#pack"] = pack;
16311
+ for (const [k, v] of Object.entries(member))
16312
+ if (!k.startsWith("#"))
16313
+ decl[k] = v;
16314
+ return decl;
16315
+ }
16316
+ function structArray(def) {
16317
+ const { fields, size } = computeStructLayout(def.__struct);
16318
+ const readN = (dv, n) => {
16319
+ const out = [];
16320
+ for (let i = 0; i < n; i++)
16321
+ out.push(doDecode(dv, i * size, fields));
16322
+ return out;
16323
+ };
16324
+ return {
16325
+ encode: (els) => {
16326
+ if (!Array.isArray(els) || els.length === 0)
16327
+ throw new Error(`ffi-struct: structArray(def).encode(els) requires a non-empty element array (pass NULL for an empty pointer position)`);
16328
+ const out = def.alloc(els.length);
16329
+ for (let i = 0; i < els.length; i++)
16330
+ def.encode(els[i], out, i * def.size);
16331
+ return out;
16332
+ },
16333
+ decode: ((p, count) => {
16334
+ if (count !== void 0 && (!Number.isInteger(count) || count < 0))
16335
+ throw new Error(`ffi-struct: structArray.decode(p, count) requires a non-negative integer count, got ${count}`);
16336
+ if (typeof p === "number") {
16337
+ if (count === void 0)
16338
+ throw new Error(`ffi-struct: structArray.decode(address, count) requires an explicit count (a bare address carries no length)`);
16339
+ if (count === 0)
16340
+ return [];
16341
+ return readN(new DataView(ffi2.readBytes(p, count * size)), count);
16342
+ }
16343
+ let n;
16344
+ if (count !== void 0) {
16345
+ n = count;
16346
+ if (n * size > p.byteLength)
16347
+ throw new Error(`ffi-struct: structArray.decode: count ${n} \xD7 size ${size} = ${n * size} exceeds buffer byteLength ${p.byteLength}`);
16348
+ } else {
16349
+ if (p.byteLength % size !== 0)
16350
+ throw new Error(`ffi-struct: structArray.decode: byteLength ${p.byteLength} is not a multiple of size ${size} (mixed buffer? pass count explicitly)`);
16351
+ n = p.byteLength / size;
16352
+ }
16353
+ if (n === 0)
16354
+ return [];
16355
+ return readN(new DataView(p), n);
16356
+ })
16357
+ };
16358
+ }
16359
+ function struct(a, b6, c) {
16360
+ const isNamed = typeof a === "string";
16361
+ const raw = isNamed ? b6 : a;
16362
+ const opts = isNamed ? c : b6;
16363
+ return createStruct(buildDecl("struct", raw, opts?.pack));
16364
+ }
16365
+
16366
+ // _build/lib/windows/structs.js
16367
+ var RECT = /* @__PURE__ */ struct("RECT", {
16368
+ left: "i32",
16369
+ top: "i32",
16370
+ right: "i32",
16371
+ bottom: "i32"
16372
+ });
16373
+ var POINT = /* @__PURE__ */ struct("POINT", {
16374
+ x: "i32",
16375
+ y: "i32"
16376
+ });
16377
+ var SIZE = /* @__PURE__ */ struct("SIZE", {
16378
+ cx: "i32",
16379
+ cy: "i32"
16380
+ });
16381
+ var LOGFONTW = /* @__PURE__ */ struct("LOGFONTW", {
16382
+ lfHeight: "i32",
16383
+ lfWidth: "i32",
16384
+ lfEscapement: "i32",
16385
+ lfOrientation: "i32",
16386
+ lfWeight: "i32",
16387
+ lfItalic: "u8",
16388
+ lfUnderline: "u8",
16389
+ lfStrikeOut: "u8",
16390
+ lfCharSet: "u8",
16391
+ lfOutPrecision: "u8",
16392
+ lfClipPrecision: "u8",
16393
+ lfQuality: "u8",
16394
+ lfPitchAndFamily: "u8",
16395
+ lfFaceName: "u16[32]@utf-16le"
16396
+ });
16397
+ var OPENFILENAMEW = /* @__PURE__ */ struct("OPENFILENAMEW", {
16398
+ lStructSize: "u32",
16399
+ hwndOwner: "<HWND>ptr",
16400
+ hInstance: "<HMODULE>ptr",
16401
+ lpstrFilter: "<>ptr",
16402
+ lpstrCustomFilter: "<>ptr",
16403
+ nMaxCustFilter: "u32",
16404
+ nFilterIndex: "u32",
16405
+ lpstrFile: "<>ptr",
16406
+ nMaxFile: "u32",
16407
+ lpstrFileTitle: "<>ptr",
16408
+ nMaxFileTitle: "u32",
16409
+ lpstrInitialDir: "<>ptr",
16410
+ lpstrTitle: "<>ptr",
16411
+ Flags: "u32",
16412
+ nFileOffset: "u16",
16413
+ nFileExtension: "u16",
16414
+ lpstrDefExt: "<>ptr",
16415
+ lCustData: "<>ptr",
16416
+ lpfnHook: "<>ptr",
16417
+ lpTemplateName: "<>ptr",
16418
+ pvReserved: "<>ptr",
16419
+ dwReserved: "u32",
16420
+ FlagsEx: "u32"
16421
+ });
16422
+ var BROWSEINFOW = /* @__PURE__ */ struct("BROWSEINFOW", {
16423
+ hwndOwner: "<HWND>ptr",
16424
+ pidlRoot: "<>ptr",
16425
+ pszDisplayName: "<>ptr",
16426
+ lpszTitle: "<>ptr",
16427
+ ulFlags: "u32",
16428
+ lpfn: "<>ptr",
16429
+ lParam: "<>ptr",
16430
+ iImage: "i32"
16431
+ });
16432
+ var NMHDR = /* @__PURE__ */ struct("NMHDR", {
16433
+ hwndFrom: "<HWND>ptr",
16434
+ idFrom: "<>ptr",
16435
+ code: "i32"
16436
+ });
16437
+ var SYSTEMTIME = /* @__PURE__ */ struct("SYSTEMTIME", {
16438
+ wYear: "u16",
16439
+ wMonth: "u16",
16440
+ wDayOfWeek: "u16",
16441
+ wDay: "u16",
16442
+ wHour: "u16",
16443
+ wMinute: "u16",
16444
+ wSecond: "u16",
16445
+ wMilliseconds: "u16"
16446
+ });
16447
+ var NMDATETIMECHANGE = /* @__PURE__ */ struct("NMDATETIMECHANGE", {
16448
+ hdr: NMHDR.__struct,
16449
+ dwFlags: "u32",
16450
+ st: SYSTEMTIME.__struct
16451
+ });
16452
+ var LITEM = /* @__PURE__ */ struct("LITEM", {
16453
+ mask: "u32",
16454
+ iLink: "i32",
16455
+ state: "u32",
16456
+ stateMask: "u32",
16457
+ szID: "u16[48]@utf-16le",
16458
+ szUrl: "u16[2084]@utf-16le"
16459
+ });
16460
+ var NMLINK = /* @__PURE__ */ struct("NMLINK", {
16461
+ hdr: NMHDR.__struct,
16462
+ item: LITEM.__struct
16463
+ });
16464
+ var NMCUSTOMDRAW = /* @__PURE__ */ struct("NMCUSTOMDRAW", {
16465
+ hdr: NMHDR.__struct,
16466
+ dwDrawStage: "u32",
16467
+ hdc: "<HDC>ptr",
16468
+ rc: "i32[4]",
16469
+ dwItemSpec: "<>ptr",
16470
+ uItemState: "u32",
16471
+ lItemlParam: "<>ptr"
16472
+ });
16473
+ var NMLVCUSTOMDRAW = /* @__PURE__ */ struct("NMLVCUSTOMDRAW", {
16474
+ hdr: NMHDR.__struct,
16475
+ dwDrawStage: "u32",
16476
+ hdc: "<HDC>ptr",
16477
+ rc: "i32[4]",
16478
+ dwItemSpec: "<>ptr",
16479
+ uItemState: "u32",
16480
+ lItemlParam: "<>ptr",
16481
+ clrText: "u32",
16482
+ clrTextBk: "u32",
16483
+ iSubItem: "i32",
16484
+ dwItemType: "u32"
16485
+ });
16486
+ var NMLISTVIEW = /* @__PURE__ */ struct("NMLISTVIEW", {
16487
+ hdr: NMHDR.__struct,
16488
+ iItem: "i32",
16489
+ iSubItem: "i32",
16490
+ uNewState: "u32",
16491
+ uOldState: "u32",
16492
+ uChanged: "u32",
16493
+ ptAction: "i32[2]",
16494
+ lParam: "<>ptr"
16495
+ });
16496
+ var TCITEMW = /* @__PURE__ */ struct("TCITEMW", {
16497
+ mask: "u32",
16498
+ dwState: "u32",
16499
+ dwStateMask: "u32",
16500
+ pszText: "<>ptr",
16501
+ cchTextMax: "i32",
16502
+ iImage: "i32",
16503
+ lParam: "<>ptr"
16504
+ });
16505
+ var TVITEM = /* @__PURE__ */ struct("TVITEM", {
16506
+ mask: "u32",
16507
+ hItem: "<>ptr",
16508
+ state: "u32",
16509
+ stateMask: "u32",
16510
+ pszText: "<>ptr",
16511
+ cchTextMax: "i32",
16512
+ iImage: "i32",
16513
+ iSelectedImage: "i32",
16514
+ cChildren: "i32",
16515
+ lParam: "<>ptr"
16516
+ });
16517
+ var TVINSERTSTRUCT = /* @__PURE__ */ struct("TVINSERTSTRUCT", {
16518
+ hParent: "<>ptr",
16519
+ hInsertAfter: "<>ptr",
16520
+ item: TVITEM.__struct
16521
+ });
16522
+ var LVHITTESTINFO = /* @__PURE__ */ struct("LVHITTESTINFO", {
16523
+ pt: "i32[2]",
16524
+ flags: "u32",
16525
+ iItem: "i32",
16526
+ iSubItem: "i32",
16527
+ iGroup: "i32"
16528
+ });
16529
+ var LVITEMW = /* @__PURE__ */ struct("LVITEMW", {
16530
+ mask: "u32",
16531
+ iItem: "i32",
16532
+ iSubItem: "i32",
16533
+ state: "u32",
16534
+ stateMask: "u32",
16535
+ pszText: "<>ptr",
16536
+ cchTextMax: "i32",
16537
+ iImage: "i32",
16538
+ lParam: "<>ptr",
16539
+ iIndent: "i32",
16540
+ iGroupId: "i32",
16541
+ cColumns: "u32",
16542
+ puColumns: "<>ptr",
16543
+ piColFmt: "<>ptr",
16544
+ iGroup: "i32"
16545
+ });
16546
+ var LVCOLUMNW = /* @__PURE__ */ struct("LVCOLUMNW", {
16547
+ mask: "u32",
16548
+ fmt: "i32",
16549
+ cx: "i32",
16550
+ pszText: "<>ptr",
16551
+ cchTextMax: "i32",
16552
+ iSubItem: "i32",
16553
+ iImage: "i32",
16554
+ iOrder: "i32",
16555
+ cxMin: "i32",
16556
+ cxDefault: "i32",
16557
+ cxIdeal: "i32"
16558
+ });
16559
+ var MSG = /* @__PURE__ */ struct("MSG", {
16560
+ hwnd: "<HWND>ptr",
16561
+ message: "u32",
16562
+ wParam: "<>ptr",
16563
+ lParam: "<>ptr",
16564
+ time: "u32",
16565
+ pt: POINT.__struct
16566
+ });
16567
+ var PAINTSTRUCT = /* @__PURE__ */ struct("PAINTSTRUCT", {
16568
+ hdc: "<HDC>ptr",
16569
+ fErase: "i32",
16570
+ rcPaint: RECT.__struct,
16571
+ fRestore: "i32",
16572
+ fIncUpdate: "i32",
16573
+ rgbReserved: "u8[32]"
16574
+ });
16575
+
16576
+ // _build/lib/windows/user32.js
16577
+ var b = (name, sig, encoders) => bind("user32.dll", name, sig, encoders);
16578
+ var _bProbe = b("GetDesktopWindow", " -> <HWND>ptr");
16579
+ var LONG_PTR_SYM = os3.arch === "x64" ? "PtrW" : "W";
16580
+ var SetWindowPos = /* @__PURE__ */ b("SetWindowPos", "<HWND>ptr <>ptr@SetWindowPosHwnd i32 i32 i32 i32 u32 -> i32");
16581
+ var SetWindowText = /* @__PURE__ */ b("SetWindowTextW", "<HWND>ptr <WCHAR>ptr -> i32");
16582
+ var GetWindowLongPtr = /* @__PURE__ */ b("GetWindowLong" + LONG_PTR_SYM, "<HWND>ptr i32@Gwlp -> <>ptr");
16583
+ var SetWindowLongPtr = /* @__PURE__ */ b("SetWindowLong" + LONG_PTR_SYM, "<HWND>ptr i32@Gwlp <>ptr -> <>ptr");
16584
+ var EnableWindow = /* @__PURE__ */ b("EnableWindow", "<HWND>ptr i32 -> i32");
16585
+ var SetParent = /* @__PURE__ */ b("SetParent", "<HWND>ptr <HWND>ptr -> <HWND>ptr");
16586
+ var DefWindowProc = /* @__PURE__ */ b("DefWindowProcW", "<HWND>ptr u32@AnyMsg <>ptr <>ptr -> <>ptr");
16587
+ var CallWindowProc = /* @__PURE__ */ b("CallWindowProcW", "<>ptr <HWND>ptr u32@AnyMsg <>ptr <>ptr -> <>ptr");
16588
+ var GetDC = /* @__PURE__ */ b("GetDC", "<HWND>ptr -> <HDC>ptr");
16589
+ var ReleaseDC = /* @__PURE__ */ b("ReleaseDC", "<HWND>ptr <HDC>ptr! -> i32");
16590
+ var DrawText = /* @__PURE__ */ b("DrawTextW", "<HDC>ptr! <WCHAR>ptr i32 <RECT>ptr i32 -> i32");
16591
+ var InvalidateRect = /* @__PURE__ */ b("InvalidateRect", "<HWND>ptr <RECT>ptr i32 -> i32", { RECT });
16592
+ var SetCursor = /* @__PURE__ */ b("SetCursor", "<HCURSOR>ptr -> <HCURSOR>ptr");
16593
+ var LoadCursor = /* @__PURE__ */ b("LoadCursorW", "<HMODULE>ptr <>ptr -> <HCURSOR>ptr");
16594
+ var GetCursorPos = /* @__PURE__ */ b("GetCursorPos", "<POINT>ptr -> i32");
16595
+ var ScreenToClient = /* @__PURE__ */ b("ScreenToClient", "<HWND>ptr <POINT>ptr -> i32");
16596
+ var ShowScrollBar = /* @__PURE__ */ b("ShowScrollBar", "<HWND>ptr u32 i32 -> i32");
16597
+ var GetSystemMetrics = /* @__PURE__ */ b("GetSystemMetrics", "i32 -> i32");
16598
+
16599
+ // _build/lib/react-qw/reconciler.js
16600
+ var import_react_reconciler = __toESM(require_react_reconciler(), 1);
16601
+ var import_react = __toESM(require_react(), 1);
16602
+ var import_constants = __toESM(require_constants(), 1);
16603
+ import * as gui3 from "gui";
16604
+ import * as os4 from "os";
16605
+
16606
+ // _build/lib/windows/gdi32.js
16607
+ var b2 = (name, sig, encoders) => bind("gdi32.dll", name, sig, encoders);
16608
+ var POINTArr = structArray(POINT);
16609
+ var DeleteObject = /* @__PURE__ */ b2("DeleteObject", "<HGDIOBJ>ptr -> i32");
16610
+ var GetDeviceCaps = /* @__PURE__ */ b2("GetDeviceCaps", "<HDC>ptr! i32@DeviceCap -> i32");
16611
+ var CreateFontIndirect = /* @__PURE__ */ b2("CreateFontIndirectW", "<LOGFONTW>ptr -> <HGDIOBJ>ptr", { LOGFONTW });
16612
+ var SelectObject = /* @__PURE__ */ b2("SelectObject", "<HDC>ptr! <HGDIOBJ>ptr -> <HGDIOBJ>ptr");
16613
+ var GetObject = /* @__PURE__ */ b2("GetObjectW", "<HGDIOBJ>ptr i32 <BYTE>ptr -> i32");
16614
+
16615
+ // _build/lib/react-qw/props.js
16616
+ import * as gui from "gui";
16617
+ function applyProps(instance, newProps, _oldProps) {
16618
+ const hwnd2 = instance.hwnd;
16619
+ instance.props = newProps;
16620
+ if (hwnd2 === null)
16621
+ return;
16622
+ const textVal = "text" in newProps ? newProps.text : typeof newProps.children === "string" ? newProps.children : typeof newProps.children === "number" ? String(newProps.children) : void 0;
16623
+ if (textVal !== void 0) {
16624
+ let cursor = -1;
16625
+ if (instance.type === "EDIT") {
16626
+ const sel = gui.SendMessage(hwnd2, 176, 0, 0);
16627
+ cursor = sel >>> 16;
16628
+ }
16629
+ SetWindowText(hwnd2, textVal);
16630
+ if (instance.type === "EDIT" && cursor >= 0) {
16631
+ gui.SendMessage(hwnd2, 177, cursor, cursor);
16632
+ }
16633
+ }
16634
+ if ("disabled" in newProps) {
16635
+ EnableWindow(hwnd2, !newProps.disabled ? 1 : 0);
16636
+ }
16637
+ if ("hidden" in newProps) {
16638
+ gui.ShowWindow(
16639
+ hwnd2,
16640
+ newProps.hidden ? 0 : 5
16641
+ /* gui.ShowWindowCmd.SHOW */
16642
+ );
16643
+ }
16644
+ if ("visible" in newProps) {
16645
+ gui.ShowWindow(
16646
+ hwnd2,
16647
+ newProps.visible ? 5 : 0
16648
+ /* gui.ShowWindowCmd.HIDE */
16649
+ );
16650
+ }
16651
+ }
16652
+
16653
+ // _build/lib/react-qw/layout.js
16654
+ var DEFAULT_W = 100;
16655
+ var DEFAULT_H = 30;
16656
+ function calculateFlexLayout(flex, parentW, parentH, children) {
16657
+ const dir = flex.flexDirection || "column";
16658
+ const gap = flex.gap ?? 0;
16659
+ const justify = flex.justifyContent || "flex-start";
16660
+ const align = flex.alignItems || "stretch";
16661
+ const isRow = dir === "row";
16662
+ const n = children.length;
16663
+ const mainSize = isRow ? "w" : "h";
16664
+ const crossSize = isRow ? "h" : "w";
16665
+ const mainPos = isRow ? "x" : "y";
16666
+ const crossPos = isRow ? "y" : "x";
16667
+ const mainDim = isRow ? "width" : "height";
16668
+ const crossDim = isRow ? "height" : "width";
16669
+ const pt = flex.paddingTop ?? flex.padding ?? 0;
16670
+ const pr = flex.paddingRight ?? flex.padding ?? 0;
16671
+ const pb = flex.paddingBottom ?? flex.padding ?? 0;
16672
+ const pl = flex.paddingLeft ?? flex.padding ?? 0;
16673
+ const mainPadding = isRow ? pl + pr : pt + pb;
16674
+ const crossPadding = isRow ? pt + pb : pl + pr;
16675
+ const parentMain = (isRow ? parentW : parentH) - mainPadding;
16676
+ const parentCross = (isRow ? parentH : parentW) - crossPadding;
16677
+ const sizes = children.map((c) => ({
16678
+ w: typeof c.style.width === "number" ? c.style.width : DEFAULT_W,
16679
+ h: typeof c.style.height === "number" ? c.style.height : DEFAULT_H
16680
+ }));
16681
+ const flexGrows = children.map((c) => c.style.flexGrow ?? 0);
16682
+ const totalGrow = flexGrows.reduce((s, g) => s + g, 0);
16683
+ const baseMain = sizes.reduce((s, c) => s + c[mainSize], 0);
16684
+ let freeGrow = parentMain - baseMain - Math.max(0, n - 1) * gap;
16685
+ if (totalGrow > 0 && freeGrow > 0) {
16686
+ for (let i = 0; i < n; i++) {
16687
+ sizes[i][mainSize] += freeGrow * flexGrows[i] / totalGrow;
16688
+ }
16689
+ }
16690
+ const totalMain = sizes.reduce((s, c) => s + c[mainSize], 0);
16691
+ const free = parentMain - totalMain - Math.max(0, n - 1) * gap;
16692
+ let offset = 0, extraGap = 0;
16693
+ if (justify === "flex-end")
16694
+ offset = free;
16695
+ else if (justify === "center")
16696
+ offset = Math.max(0, free / 2);
16697
+ else if (justify === "space-between" && n > 1)
16698
+ extraGap = free / (n - 1);
16699
+ else if (justify === "space-around") {
16700
+ extraGap = free / n;
16701
+ offset = extraGap / 2;
16702
+ } else if (justify === "space-evenly") {
16703
+ extraGap = free / (n + 1);
16704
+ offset = extraGap;
16705
+ }
16706
+ let cursor = offset;
16707
+ return sizes.map((sz, i) => {
16708
+ const childCrossBase = sz[crossSize];
16709
+ const childAlign = children[i].style.alignSelf ?? "auto";
16710
+ const effectiveAlign = childAlign === "auto" ? align : childAlign;
16711
+ let childMain = sz[mainSize];
16712
+ let childCross = childCrossBase;
16713
+ const res = { x: 0, y: 0, width: 0, height: 0 };
16714
+ res[mainPos] = cursor;
16715
+ res[crossPos] = 0;
16716
+ res[mainDim] = childMain;
16717
+ res[crossDim] = childCross;
16718
+ if (effectiveAlign === "stretch") {
16719
+ const hasExplicitCross = typeof children[i].style[crossDim] === "number";
16720
+ if (!hasExplicitCross) {
16721
+ res[crossDim] = parentCross;
16722
+ res[crossPos] = 0;
16723
+ }
16724
+ } else if (effectiveAlign === "flex-end") {
16725
+ res[crossPos] = parentCross - childCross;
16726
+ } else if (effectiveAlign === "center") {
16727
+ res[crossPos] = Math.max(0, (parentCross - childCross) / 2);
16728
+ }
16729
+ cursor += childMain + gap + extraGap;
16730
+ return res;
16731
+ });
15812
16732
  }
15813
16733
 
15814
16734
  // _build/lib/text-measure.js
15815
- var user32 = bindLib("user32.dll", {
15816
- DrawTextW: "ptr wstr i32 ptr i32 -> i32",
15817
- GetDC: "ptr -> ptr",
15818
- ReleaseDC: "ptr ptr -> i32"
15819
- });
15820
- var gdi32 = bindLib("gdi32.dll", {
15821
- SelectObject: "ptr ptr -> ptr"
15822
- });
16735
+ import * as gui2 from "gui";
15823
16736
  function measureText(hdc, text, maxWidth) {
15824
- const rect = new ArrayBuffer(16);
15825
- const dv = new DataView(rect);
15826
- dv.setInt32(8, maxWidth, true);
15827
- user32.DrawTextW(
16737
+ const r = RECT.encode({ right: maxWidth });
16738
+ DrawText(
15828
16739
  hdc,
15829
16740
  text,
15830
16741
  -1,
15831
- rect,
16742
+ r.ptr,
15832
16743
  1024
15833
16744
  /* gui.DrawTextFlag.CALCRECT */
15834
16745
  );
15835
- return { width: dv.getInt32(8, true), height: dv.getInt32(12, true) };
16746
+ const { right, bottom } = RECT.decode(r);
16747
+ return { width: right, height: bottom };
15836
16748
  }
15837
16749
  function getButtonIdealSize(hwnd2) {
15838
- const size = new ArrayBuffer(8);
15839
- gui2.SendMessage(hwnd2, 5633, 0, ffi2.bufferPtr(size));
15840
- const dv = new DataView(size);
15841
- return { width: dv.getInt32(0, true), height: dv.getInt32(4, true) };
16750
+ const size = SIZE.alloc();
16751
+ gui2.SendMessage(hwnd2, 5633, 0, size.ptr);
16752
+ const { cx, cy } = SIZE.decode(size);
16753
+ return { width: cx, height: cy };
15842
16754
  }
15843
16755
  function measureTextForHwnd(hwnd2, text) {
15844
- const hdc = user32.GetDC(hwnd2);
16756
+ const hdc = GetDC(hwnd2);
15845
16757
  if (!hdc)
15846
16758
  return { width: 0, height: 0 };
15847
16759
  const hFont = gui2.SendMessage(hwnd2, 49, 0, 0);
15848
- const oldFont = hFont ? gdi32.SelectObject(hdc, hFont) : 0;
16760
+ const oldFont = hFont ? SelectObject(hdc, hFont) : NULL;
15849
16761
  const result = measureText(hdc, text, 0);
15850
16762
  if (hFont)
15851
- gdi32.SelectObject(hdc, oldFont);
15852
- user32.ReleaseDC(hwnd2, hdc);
16763
+ SelectObject(hdc, oldFont);
16764
+ ReleaseDC(hwnd2, hdc);
15853
16765
  const wr = gui2.GetWindowRect(hwnd2);
15854
16766
  const cr = gui2.GetClientRect(hwnd2);
15855
16767
  if (wr && cr) {
@@ -15861,14 +16773,20 @@ function measureTextForHwnd(hwnd2, text) {
15861
16773
 
15862
16774
  // _build/lib/react-qw/reconciler.js
15863
16775
  var dpiFont = gui3.CreateSystemDpiFont();
15864
- var scaleFactor = gui3.GetScaleFactor();
16776
+ var scaleFactor = (() => {
16777
+ const hdc = GetDC(NULL);
16778
+ const dpi = hdc ? GetDeviceCaps(hdc, 88) : 96;
16779
+ if (hdc)
16780
+ ReleaseDC(NULL, hdc);
16781
+ return dpi / 96;
16782
+ })();
15865
16783
  var DELAYED_CONTROLS = /* @__PURE__ */ new Set(["SysListView32", "SysTreeView32", "LISTBOX", "COMBOBOX", "msctls_trackbar32", "SysDateTimePick32", "SysLink"]);
15866
16784
  function isDelayedControl(winClass) {
15867
16785
  return DELAYED_CONTROLS.has(winClass);
15868
16786
  }
15869
16787
  function setupWindowProc(instance, hwnd2) {
15870
16788
  instance.hwnd = hwnd2;
15871
- const oldProc = gui3.GetWindowLongPtr(
16789
+ const oldProc = GetWindowLongPtr(
15872
16790
  hwnd2,
15873
16791
  -4
15874
16792
  /* gui.Gwlp.WNDPROC */
@@ -15877,11 +16795,11 @@ function setupWindowProc(instance, hwnd2) {
15877
16795
  gui3.SetWindowProc(hwnd2, (hwnd3, msg, wParam, lParam) => {
15878
16796
  const ev = instance.props.onEvent;
15879
16797
  if (!ev)
15880
- return gui3.CallWindowProc(oldProc, hwnd3, msg, wParam, lParam);
16798
+ return CallWindowProc(oldProc, hwnd3, msg, wParam, lParam);
15881
16799
  if (typeof ev === "object") {
15882
- return ev.fn({ hwnd: hwnd3, msg, wParam, lParam, callOldWndProc: () => gui3.CallWindowProc(oldProc, hwnd3, msg, wParam, lParam) });
16800
+ return ev.fn({ hwnd: hwnd3, msg, wParam, lParam, callOldWndProc: () => CallWindowProc(oldProc, hwnd3, msg, wParam, lParam) });
15883
16801
  }
15884
- const result = gui3.CallWindowProc(oldProc, hwnd3, msg, wParam, lParam);
16802
+ const result = CallWindowProc(oldProc, hwnd3, msg, wParam, lParam);
15885
16803
  const override = ev({ hwnd: hwnd3, msg, wParam, lParam });
15886
16804
  return typeof override === "number" && Number.isInteger(override) ? override : result;
15887
16805
  });
@@ -15951,7 +16869,7 @@ function runFlexLayout(inst) {
15951
16869
  if (lr && lr.x === r.x && lr.y === r.y && lr.w === r.width && lr.h === r.height)
15952
16870
  continue;
15953
16871
  console.log("flex: set", child.type, child.hwnd, "to", r.x, r.y, r.width, r.height);
15954
- gui3.SetWindowPos(
16872
+ SetWindowPos(
15955
16873
  child.hwnd,
15956
16874
  0,
15957
16875
  (r.x + pl) * scaleFactor,
@@ -15961,7 +16879,7 @@ function runFlexLayout(inst) {
15961
16879
  64
15962
16880
  /* gui.SetWindowPosFlag.SWP_SHOWWINDOW */
15963
16881
  );
15964
- gui3.InvalidateRect(child.hwnd, null, true);
16882
+ InvalidateRect(child.hwnd, NULL, 1);
15965
16883
  child.lastRect = { x: r.x, y: r.y, w: r.width, h: r.height };
15966
16884
  }
15967
16885
  for (const c of children)
@@ -16007,7 +16925,7 @@ var hostConfig = {
16007
16925
  if (child.hwnd === null) {
16008
16926
  ensureChildWindow(child, parent.hwnd);
16009
16927
  } else {
16010
- gui3.SetParent(child.hwnd, parent.hwnd);
16928
+ SetParent(child.hwnd, parent.hwnd ?? NULL);
16011
16929
  }
16012
16930
  if (false)
16013
16931
  console.log("[reconciler] appendInitialChild parent:", parent.hwnd, "child:", child.hwnd);
@@ -16017,7 +16935,7 @@ var hostConfig = {
16017
16935
  if (child.hwnd === null) {
16018
16936
  ensureChildWindow(child, parent.hwnd);
16019
16937
  } else {
16020
- gui3.SetParent(child.hwnd, parent.hwnd);
16938
+ SetParent(child.hwnd, parent.hwnd ?? NULL);
16021
16939
  }
16022
16940
  if (false)
16023
16941
  console.log("[reconciler] appendChild parent:", parent.hwnd, "child:", child.hwnd);
@@ -16027,7 +16945,7 @@ var hostConfig = {
16027
16945
  if (child.hwnd === null) {
16028
16946
  ensureChildWindow(child, container);
16029
16947
  } else {
16030
- gui3.SetParent(child.hwnd, container);
16948
+ SetParent(child.hwnd, container);
16031
16949
  }
16032
16950
  const rootInst = instancesByHwnd.get(container);
16033
16951
  if (rootInst)
@@ -16039,7 +16957,7 @@ var hostConfig = {
16039
16957
  if (child.hwnd === null) {
16040
16958
  ensureChildWindow(child, parent.hwnd);
16041
16959
  } else {
16042
- gui3.SetParent(child.hwnd, parent.hwnd);
16960
+ SetParent(child.hwnd, parent.hwnd ?? NULL);
16043
16961
  }
16044
16962
  if (false)
16045
16963
  console.log("[reconciler] insertBefore parent:", parent.hwnd, "child:", child.hwnd, "before:", beforeChild.hwnd);
@@ -16051,7 +16969,7 @@ var hostConfig = {
16051
16969
  if (child.hwnd === null) {
16052
16970
  ensureChildWindow(child, container);
16053
16971
  } else {
16054
- gui3.SetParent(child.hwnd, container);
16972
+ SetParent(child.hwnd, container);
16055
16973
  }
16056
16974
  const rootInst = instancesByHwnd.get(container);
16057
16975
  if (!rootInst)
@@ -16108,7 +17026,7 @@ var hostConfig = {
16108
17026
  resetTextContent(_instance) {
16109
17027
  },
16110
17028
  commitTextUpdate(instance, _oldText, newText) {
16111
- gui3.SetWindowText(instance.hwnd, newText);
17029
+ SetWindowText(instance.hwnd, newText);
16112
17030
  },
16113
17031
  hideInstance(instance) {
16114
17032
  if (instance.hwnd !== null)
@@ -16162,10 +17080,10 @@ var hostConfig = {
16162
17080
  clearContainer(_container) {
16163
17081
  },
16164
17082
  scheduleTimeout(fn, delay) {
16165
- return os.setTimeout(fn, delay);
17083
+ return os4.setTimeout(fn, delay);
16166
17084
  },
16167
17085
  cancelTimeout(id) {
16168
- os.clearTimeout?.(id);
17086
+ os4.clearTimeout?.(id);
16169
17087
  },
16170
17088
  noTimeout: -1,
16171
17089
  supportsMutation: true,
@@ -16332,298 +17250,23 @@ var ComboBox = (0, import_react4.forwardRef)(({ items, selectedIndex: controlled
16332
17250
  var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
16333
17251
  var import_react5 = __toESM(require_react(), 1);
16334
17252
  import * as gui6 from "gui";
16335
- import * as ffi4 from "ffi";
16336
-
16337
- // _build/lib/ffi-struct.js
16338
- import * as os2 from "os";
16339
- var PTR = os2.arch === "x64" ? 8 : 4;
16340
- var AS = {
16341
- u8: [1, 1],
16342
- i8: [1, 1],
16343
- u16: [2, 2],
16344
- i16: [2, 2],
16345
- u32: [4, 4],
16346
- i32: [4, 4],
16347
- u64: [8, 8],
16348
- i64: [8, 8],
16349
- f32: [4, 4],
16350
- f64: [8, 8],
16351
- ptr: [PTR, PTR],
16352
- wstr: [2, 2]
16353
- // 仅定长数组元素用(wchar)
16354
- };
16355
- function alignUp(v, a) {
16356
- return v + a - 1 & ~(a - 1);
16357
- }
16358
- function parseField(f) {
16359
- const arr = /^(.+)\[(\d+)\]$/.exec(f);
16360
- if (arr) {
16361
- const b2 = normKind(arr[1]);
16362
- if (b2 === "void")
16363
- throw new Error(`ffi-struct: "void" cannot be an array base`);
16364
- return { base: b2, count: Number(arr[2]) };
16365
- }
16366
- const b = normKind(f);
16367
- if (b === "void" || b === "wstr")
16368
- throw new Error(`ffi-struct: invalid scalar field type "${f}"`);
16369
- return { base: b, count: 1 };
16370
- }
16371
- function layout(def) {
16372
- const fields = [];
16373
- let cursor = 0;
16374
- let maxAlign = 1;
16375
- for (const key of Object.keys(def)) {
16376
- const v = def[key];
16377
- let a;
16378
- let w;
16379
- if (typeof v === "string") {
16380
- const { base, count } = parseField(v);
16381
- const [align, elem] = AS[base];
16382
- a = align;
16383
- w = count >= 1 ? elem * count : elem;
16384
- fields.push({ name: key, base, count, offset: 0 });
16385
- } else {
16386
- const child = v;
16387
- a = child.structAlign;
16388
- w = child.size;
16389
- fields.push({ name: key, base: "u8", count: 0, offset: 0, child });
16390
- }
16391
- const off = alignUp(cursor, a);
16392
- const f = fields[fields.length - 1];
16393
- f.offset = off;
16394
- cursor = off + w;
16395
- if (a > maxAlign)
16396
- maxAlign = a;
16397
- }
16398
- return { fields, size: alignUp(cursor, maxAlign), structAlign: maxAlign };
16399
- }
16400
- var _layoutCache = /* @__PURE__ */ new WeakMap();
16401
- function buildLayout(def) {
16402
- let hit = _layoutCache.get(def);
16403
- if (hit)
16404
- return hit;
16405
- hit = layout(def);
16406
- _layoutCache.set(def, hit);
16407
- return hit;
16408
- }
16409
- function readScalar(dv, off, k) {
16410
- switch (k) {
16411
- case "u8":
16412
- return dv.getUint8(off);
16413
- case "i8":
16414
- return dv.getInt8(off);
16415
- case "u16":
16416
- return dv.getUint16(off, true);
16417
- case "i16":
16418
- return dv.getInt16(off, true);
16419
- case "u32":
16420
- return dv.getUint32(off, true);
16421
- case "i32":
16422
- return dv.getInt32(off, true);
16423
- case "u64":
16424
- return Number(dv.getBigUint64(off, true));
16425
- case "i64":
16426
- return Number(dv.getBigInt64(off, true));
16427
- case "f32":
16428
- return dv.getFloat32(off, true);
16429
- case "f64":
16430
- return dv.getFloat64(off, true);
16431
- case "ptr":
16432
- return readPtr(dv, off);
16433
- case "wstr":
16434
- return dv.getUint16(off, true);
16435
- }
16436
- }
16437
- function readPtr(dv, off) {
16438
- if (PTR === 8)
16439
- return Number(dv.getBigUint64(off, true));
16440
- return dv.getUint32(off, true);
16441
- }
16442
- function writeScalar(dv, off, k, val) {
16443
- switch (k) {
16444
- case "u8":
16445
- dv.setUint8(off, val);
16446
- break;
16447
- case "i8":
16448
- dv.setInt8(off, val);
16449
- break;
16450
- case "u16":
16451
- dv.setUint16(off, val, true);
16452
- break;
16453
- case "i16":
16454
- dv.setInt16(off, val, true);
16455
- break;
16456
- case "u32":
16457
- dv.setUint32(off, val >>> 0, true);
16458
- break;
16459
- case "i32":
16460
- dv.setInt32(off, val | 0, true);
16461
- break;
16462
- case "u64":
16463
- dv.setBigUint64(off, BigInt(Math.trunc(val)), true);
16464
- break;
16465
- case "i64":
16466
- dv.setBigInt64(off, BigInt(Math.trunc(val)), true);
16467
- break;
16468
- case "f32":
16469
- dv.setFloat32(off, val, true);
16470
- break;
16471
- case "f64":
16472
- dv.setFloat64(off, val, true);
16473
- break;
16474
- case "ptr":
16475
- writePtr(dv, off, val);
16476
- break;
16477
- case "wstr":
16478
- dv.setUint16(off, val, true);
16479
- break;
16480
- }
16481
- }
16482
- function writePtr(dv, off, val) {
16483
- if (PTR === 8)
16484
- dv.setBigUint64(off, BigInt(Math.trunc(val)), true);
16485
- else
16486
- dv.setUint32(off, val >>> 0, true);
16487
- }
16488
- function readField(dv, base, f) {
16489
- const off = base + f.offset;
16490
- if (f.child)
16491
- return readInto(f.child, dv.buffer, off);
16492
- if (f.count > 1) {
16493
- if (f.base === "wstr") {
16494
- const arr = new Uint16Array(dv.buffer, dv.byteOffset + off, f.count);
16495
- let end = 0;
16496
- while (end < arr.length && arr[end] !== 0)
16497
- end++;
16498
- let s = "";
16499
- for (let i = 0; i < end; i++)
16500
- s += String.fromCharCode(arr[i]);
16501
- return s;
16502
- }
16503
- const out = [];
16504
- const step = AS[f.base][1];
16505
- for (let i = 0; i < f.count; i++)
16506
- out.push(readScalar(dv, off + i * step, f.base));
16507
- return out;
16508
- }
16509
- return readScalar(dv, off, f.base);
16510
- }
16511
- function writeField(dv, base, f, v) {
16512
- const off = base + f.offset;
16513
- if (f.child) {
16514
- writeInto(f.child, v, dv.buffer, off);
16515
- return;
16516
- }
16517
- if (f.count > 1) {
16518
- if (f.base === "wstr") {
16519
- const s = String(v ?? "");
16520
- const arr = new Uint16Array(dv.buffer, dv.byteOffset + off, f.count);
16521
- for (let i = 0; i < arr.length; i++)
16522
- arr[i] = 0;
16523
- const n = Math.min(s.length, f.count - 1);
16524
- for (let i = 0; i < n; i++)
16525
- arr[i] = s.charCodeAt(i);
16526
- return;
16527
- }
16528
- const step = AS[f.base][1];
16529
- const list = v ?? [];
16530
- for (let i = 0; i < f.count; i++)
16531
- writeScalar(dv, off + i * step, f.base, list[i] ?? 0);
16532
- return;
16533
- }
16534
- writeScalar(dv, off, f.base, Number(v));
16535
- }
16536
- function doSize(def) {
16537
- return buildLayout(def).size;
16538
- }
16539
- function readInto(child, buf, offset) {
16540
- const r = child;
16541
- return r.read(buf, offset);
16542
- }
16543
- function doRead(_def, fields, buf, offset) {
16544
- const out = {};
16545
- const dv = new DataView(buf);
16546
- for (const f of fields)
16547
- out[f.name] = readField(dv, offset, f);
16548
- return out;
16549
- }
16550
- function doWrite(def, fields, v, buf, offset = 0) {
16551
- buf = buf ?? new ArrayBuffer(doSize(def));
16552
- const dv = new DataView(buf);
16553
- for (const f of fields)
16554
- writeField(dv, offset, f, v[f.name]);
16555
- return buf;
16556
- }
16557
- function writeInto(child, v, buf, offset) {
16558
- const w = child;
16559
- w.write(v, buf, offset);
16560
- }
16561
- function struct(def) {
16562
- const { fields, size, structAlign } = buildLayout(def);
16563
- return {
16564
- __fields: def,
16565
- size,
16566
- structAlign,
16567
- read: (buf, offset = 0) => doRead(def, fields, buf, offset),
16568
- write: (v, buf, offset = 0) => doWrite(def, fields, v, buf, offset),
16569
- offsetOf: (name) => {
16570
- for (const f of fields)
16571
- if (f.name === name)
16572
- return f.offset;
16573
- throw new Error(`ffi-struct: no field "${String(name)}"`);
16574
- }
16575
- };
16576
- }
16577
17253
 
16578
17254
  // _build/lib/react-qw/nmhdr.js
16579
- import * as os3 from "os";
16580
- import * as ffi3 from "ffi";
16581
- var IS64 = os3.arch === "x64";
16582
- var PTR_SIZE = IS64 ? 8 : 4;
16583
- var NMHDR = struct({ hwndFrom: "ptr", idFrom: "ptr", code: "i32" });
16584
- var NMHDR_SIZE = NMHDR.size;
16585
- var NMHDR_CODE = NMHDR.offsetOf("code");
16586
- function readI32At(ptr, offset) {
16587
- return ffi3.readByte(ptr + offset) | ffi3.readByte(ptr + offset + 1) << 8 | ffi3.readByte(ptr + offset + 2) << 16 | ffi3.readByte(ptr + offset + 3) << 24;
16588
- }
16589
- function readU16At(ptr, offset) {
16590
- return ffi3.readByte(ptr + offset) | ffi3.readByte(ptr + offset + 1) << 8;
16591
- }
16592
17255
  function nmCode(lParam) {
16593
- return readI32At(lParam, NMHDR_CODE);
17256
+ return NMHDR.decode(lParam).code;
16594
17257
  }
16595
17258
 
16596
17259
  // _build/lib/react-qw/components/DateTimePicker.js
16597
- var SYSTEMTIME = struct({
16598
- wYear: "u16",
16599
- wMonth: "u16",
16600
- wDayOfWeek: "u16",
16601
- wDay: "u16",
16602
- wHour: "u16",
16603
- wMinute: "u16",
16604
- wSecond: "u16",
16605
- wMilliseconds: "u16"
16606
- });
16607
- var NMDATETIMECHANGE = struct({
16608
- hdr: NMHDR,
16609
- dwFlags: "u32",
16610
- st: SYSTEMTIME
16611
- });
16612
- function bufPtr(buf) {
16613
- return ffi4.bufferPtr(buf);
16614
- }
16615
17260
  function dateToSysTimeBuf(d) {
16616
- const buf = new ArrayBuffer(16);
16617
- const dv = new DataView(buf);
16618
- dv.setUint16(0, d.getFullYear(), true);
16619
- dv.setUint16(2, d.getMonth() + 1, true);
16620
- dv.setUint16(4, 0, true);
16621
- dv.setUint16(6, d.getDate(), true);
16622
- dv.setUint16(8, d.getHours(), true);
16623
- dv.setUint16(10, d.getMinutes(), true);
16624
- dv.setUint16(12, d.getSeconds(), true);
16625
- dv.setUint16(14, d.getMilliseconds(), true);
16626
- return buf;
17261
+ return SYSTEMTIME.encode({
17262
+ wYear: d.getFullYear(),
17263
+ wMonth: d.getMonth() + 1,
17264
+ wDay: d.getDate(),
17265
+ wHour: d.getHours(),
17266
+ wMinute: d.getMinutes(),
17267
+ wSecond: d.getSeconds(),
17268
+ wMilliseconds: d.getMilliseconds()
17269
+ });
16627
17270
  }
16628
17271
  var DateTimePicker = (0, import_react5.forwardRef)(function DateTimePicker2({ value, onChange, defaultValue, format = "short", allowNone, updown, style }, ref) {
16629
17272
  const [internalDate, setInternalDate] = (0, import_react5.useState)(defaultValue ?? null);
@@ -16648,7 +17291,7 @@ var DateTimePicker = (0, import_react5.forwardRef)(function DateTimePicker2({ va
16648
17291
  const d = effectiveDate;
16649
17292
  if (d) {
16650
17293
  const buf = dateToSysTimeBuf(d);
16651
- gui6.SendMessage(h, 4098, 0, bufPtr(buf));
17294
+ gui6.SendMessage(h, 4098, 0, buf.ptr);
16652
17295
  } else {
16653
17296
  gui6.SendMessage(h, 4098, 1, 0);
16654
17297
  }
@@ -16657,7 +17300,7 @@ var DateTimePicker = (0, import_react5.forwardRef)(function DateTimePicker2({ va
16657
17300
  const h = dpRef.current;
16658
17301
  if (!h)
16659
17302
  return;
16660
- gui6.InvalidateRect(h, null, true);
17303
+ InvalidateRect(h, NULL, 1);
16661
17304
  const cr = gui6.GetClientRect(h);
16662
17305
  if (cr) {
16663
17306
  const w = cr.right - cr.left;
@@ -16669,20 +17312,13 @@ var DateTimePicker = (0, import_react5.forwardRef)(function DateTimePicker2({ va
16669
17312
  if (e.msg === 78) {
16670
17313
  const code = nmCode(e.lParam);
16671
17314
  if (code === -759) {
16672
- const st = NMDATETIMECHANGE.offsetOf("st");
16673
- const dwFlags = readI32At(e.lParam, NMDATETIMECHANGE.offsetOf("dwFlags"));
17315
+ const { dwFlags, st } = NMDATETIMECHANGE.decode(e.lParam);
16674
17316
  if (dwFlags === 1) {
16675
17317
  if (!isControlled)
16676
17318
  setInternalDate(null);
16677
17319
  onChangeRef.current?.(null);
16678
17320
  } else {
16679
- const year = readU16At(e.lParam, st + 0);
16680
- const month = readU16At(e.lParam, st + 2);
16681
- const day = readU16At(e.lParam, st + 6);
16682
- const hour = readU16At(e.lParam, st + 8);
16683
- const min = readU16At(e.lParam, st + 10);
16684
- const sec = readU16At(e.lParam, st + 12);
16685
- const d = new Date(year, month - 1, day, hour, min, sec);
17321
+ const d = new Date(st.wYear, st.wMonth - 1, st.wDay, st.wHour, st.wMinute, st.wSecond);
16686
17322
  if (!isControlled)
16687
17323
  setInternalDate(d);
16688
17324
  onChangeRef.current?.(d);
@@ -16698,14 +17334,6 @@ var DateTimePicker = (0, import_react5.forwardRef)(function DateTimePicker2({ va
16698
17334
  var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
16699
17335
  var import_react6 = __toESM(require_react(), 1);
16700
17336
  import * as gui7 from "gui";
16701
- import * as ffi5 from "ffi";
16702
- function textToUtf16(s) {
16703
- const buf = new ArrayBuffer((s.length + 1) * 2);
16704
- const dv = new DataView(buf);
16705
- for (let i = 0; i < s.length; i++)
16706
- dv.setUint16(i * 2, s.charCodeAt(i), true);
16707
- return buf;
16708
- }
16709
17337
  var Input = (0, import_react6.forwardRef)(({ value: controlledValue, defaultValue = "", onChange, placeholder, password, multiline, readonly, number, disabled, style }, ref) => {
16710
17338
  const [internalValue, setInternalValue] = (0, import_react6.useState)(defaultValue);
16711
17339
  const isControlled = controlledValue !== void 0;
@@ -16724,8 +17352,8 @@ var Input = (0, import_react6.forwardRef)(({ value: controlledValue, defaultValu
16724
17352
  const h = inputRef.current;
16725
17353
  if (!h || !placeholder)
16726
17354
  return;
16727
- const buf = textToUtf16(placeholder);
16728
- gui7.SendMessage(h, 5377, 1, ffi5.bufferPtr(buf));
17355
+ const buf = WCHAR.encode(placeholder);
17356
+ gui7.SendMessage(h, 5377, 1, buf.ptr);
16729
17357
  }, [placeholder]);
16730
17358
  return (0, import_jsx_runtime5.jsx)("w", { type: "EDIT", text: displayValue, ws, style, disabled, ref: (h) => {
16731
17359
  inputRef.current = h;
@@ -16749,20 +17377,6 @@ var Input = (0, import_react6.forwardRef)(({ value: controlledValue, defaultValu
16749
17377
  // _build/lib/react-qw/components/Link.js
16750
17378
  var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
16751
17379
  var import_react7 = __toESM(require_react(), 1);
16752
- import * as gui8 from "gui";
16753
- import * as ffi6 from "ffi";
16754
- function readUtf16(ptr, offset, maxWords) {
16755
- const chars = [];
16756
- for (let i = 0; i < maxWords; i++) {
16757
- const lo = ffi6.readByte(ptr + offset + i * 2);
16758
- const hi = ffi6.readByte(ptr + offset + i * 2 + 1);
16759
- const code = hi << 8 | lo;
16760
- if (code === 0)
16761
- break;
16762
- chars.push(String.fromCharCode(code));
16763
- }
16764
- return chars.join("");
16765
- }
16766
17380
  var Link = (0, import_react7.forwardRef)(function Link2({ href, children, onClick, style }, ref) {
16767
17381
  const displayText = children != null ? String(children) : href ?? "";
16768
17382
  const linkText = href ? `<A HREF="${href}">${displayText}</A>` : displayText;
@@ -16773,14 +17387,13 @@ var Link = (0, import_react7.forwardRef)(function Link2({ href, children, onClic
16773
17387
  const h = linkRef.current;
16774
17388
  if (!h)
16775
17389
  return;
16776
- gui8.InvalidateRect(h, null, true);
17390
+ InvalidateRect(h, NULL, 1);
16777
17391
  }, [linkText]);
16778
17392
  return (0, import_jsx_runtime6.jsx)("w", { type: "STATIC", ws: 268435456 | 33554432, style: { ...style, flexDirection: "column", alignItems: "stretch" }, ref, onEvent: (e) => {
16779
17393
  if (e.msg === 78) {
16780
17394
  const code = nmCode(e.lParam);
16781
17395
  if (code === -2 || code === -4) {
16782
- const url = readUtf16(e.lParam, NMHDR_SIZE + 112, 2048);
16783
- onClickRef.current?.(url);
17396
+ onClickRef.current?.(NMLINK.decode(e.lParam).item.szUrl);
16784
17397
  }
16785
17398
  }
16786
17399
  }, children: (0, import_jsx_runtime6.jsx)("w", { type: "SysLink", ws: 268435456 | 65536, text: linkText, style: { flexGrow: 1 }, ref: (h) => {
@@ -16791,7 +17404,7 @@ var Link = (0, import_react7.forwardRef)(function Link2({ href, children, onClic
16791
17404
  // _build/lib/react-qw/components/ListBox.js
16792
17405
  var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
16793
17406
  var import_react8 = __toESM(require_react(), 1);
16794
- import * as gui9 from "gui";
17407
+ import * as gui8 from "gui";
16795
17408
  var ListBox = (0, import_react8.forwardRef)(({ items, selectedIndex: controlledIndex, defaultSelectedIndex = -1, onChange, style, sort, scrollToBottom }, ref) => {
16796
17409
  const [internalIndex, setInternalIndex] = (0, import_react8.useState)(defaultSelectedIndex);
16797
17410
  const isControlled = controlledIndex !== void 0;
@@ -16803,18 +17416,18 @@ var ListBox = (0, import_react8.forwardRef)(({ items, selectedIndex: controlledI
16803
17416
  const h = lbRef.current;
16804
17417
  if (!h)
16805
17418
  return;
16806
- gui9.SendMessage(h, 388, 0, 0);
17419
+ gui8.SendMessage(h, 388, 0, 0);
16807
17420
  for (const item of items)
16808
- gui9.SendMessage(h, 384, 0, item);
17421
+ gui8.SendMessage(h, 384, 0, item);
16809
17422
  if (sel >= 0 && sel < items.length)
16810
- gui9.SendMessage(h, 390, sel, 0);
17423
+ gui8.SendMessage(h, 390, sel, 0);
16811
17424
  if (scrollToBottom && items.length > 0)
16812
- gui9.SendMessage(h, 407, items.length - 1, 0);
17425
+ gui8.SendMessage(h, 407, items.length - 1, 0);
16813
17426
  }, [items]);
16814
17427
  (0, import_react8.useEffect)(() => {
16815
17428
  const h = lbRef.current;
16816
17429
  if (h)
16817
- gui9.SendMessage(h, 390, sel, 0);
17430
+ gui8.SendMessage(h, 390, sel, 0);
16818
17431
  }, [sel]);
16819
17432
  return (0, import_jsx_runtime7.jsx)("w", { type: "STATIC", ws: 268435456 | 33554432, style: { ...style, flexDirection: "column", alignItems: "stretch" }, onEvent: (e) => {
16820
17433
  if (e.msg !== 273)
@@ -16824,7 +17437,7 @@ var ListBox = (0, import_react8.forwardRef)(({ items, selectedIndex: controlledI
16824
17437
  const h = lbRef.current;
16825
17438
  if (!h)
16826
17439
  return;
16827
- const newSel = gui9.SendMessage(h, 392, 0, 0);
17440
+ const newSel = gui8.SendMessage(h, 392, 0, 0);
16828
17441
  if (newSel !== sel && newSel >= 0) {
16829
17442
  if (!isControlled)
16830
17443
  setInternalIndex(newSel);
@@ -16839,138 +17452,18 @@ var ListBox = (0, import_react8.forwardRef)(({ items, selectedIndex: controlledI
16839
17452
  // _build/lib/react-qw/components/ListView.js
16840
17453
  var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1);
16841
17454
  var import_react9 = __toESM(require_react(), 1);
16842
- import * as gui10 from "gui";
16843
- import * as ffi7 from "ffi";
16844
- import * as win2 from "win";
16845
- function textToUtf162(s) {
16846
- const buf = new ArrayBuffer((s.length + 1) * 2);
16847
- const dv = new DataView(buf);
16848
- for (let i = 0; i < s.length; i++)
16849
- dv.setUint16(i * 2, s.charCodeAt(i), true);
16850
- return buf;
16851
- }
16852
- function readI32(ptr, offset) {
16853
- return ffi7.readByte(ptr + offset) | ffi7.readByte(ptr + offset + 1) << 8 | ffi7.readByte(ptr + offset + 2) << 16 | ffi7.readByte(ptr + offset + 3) << 24;
16854
- }
16855
- function readU32(ptr, offset) {
16856
- return ffi7.readByte(ptr + offset) | ffi7.readByte(ptr + offset + 1) << 8 | ffi7.readByte(ptr + offset + 2) << 16 | ffi7.readByte(ptr + offset + 3) << 24 >>> 0;
16857
- }
16858
- function readU64(ptr, offset) {
16859
- const lo = readU32(ptr, offset);
16860
- const hi = readU32(ptr, offset + 4);
16861
- return lo + hi * 4294967296;
16862
- }
17455
+ import * as gui9 from "gui";
17456
+ import * as ffi3 from "ffi";
16863
17457
  function writeU32(ptr, offset, v) {
16864
- ffi7.writeByte(ptr + offset, v & 255);
16865
- ffi7.writeByte(ptr + offset + 1, v >> 8 & 255);
16866
- ffi7.writeByte(ptr + offset + 2, v >> 16 & 255);
16867
- ffi7.writeByte(ptr + offset + 3, v >> 24 & 255);
16868
- }
16869
- function bufPtr2(buf) {
16870
- return ffi7.bufferPtr(buf);
17458
+ ffi3.writeByte(ptr + offset, v & 255);
17459
+ ffi3.writeByte(ptr + offset + 1, v >> 8 & 255);
17460
+ ffi3.writeByte(ptr + offset + 2, v >> 16 & 255);
17461
+ ffi3.writeByte(ptr + offset + 3, v >> 24 & 255);
16871
17462
  }
16872
17463
  var LV_WS = 268435456 | 8388608 | 2097152 | 1048576 | 1 | 4;
16873
- var NMCUSTOMDRAW = struct({
16874
- hdr: NMHDR,
16875
- dwDrawStage: "u32",
16876
- hdc: "ptr",
16877
- rc: "i32[4]",
16878
- dwItemSpec: "ptr",
16879
- uItemState: "u32",
16880
- lItemlParam: "ptr"
16881
- });
16882
- var NMLVCUSTOMDRAW = struct({
16883
- hdr: NMHDR,
16884
- dwDrawStage: "u32",
16885
- hdc: "ptr",
16886
- rc: "i32[4]",
16887
- dwItemSpec: "ptr",
16888
- uItemState: "u32",
16889
- lItemlParam: "ptr",
16890
- clrText: "u32",
16891
- clrTextBk: "u32",
16892
- iSubItem: "i32",
16893
- dwItemType: "u32"
16894
- });
16895
- var NMLISTVIEW = struct({
16896
- hdr: NMHDR,
16897
- iItem: "i32",
16898
- iSubItem: "i32",
16899
- uNewState: "u32",
16900
- uOldState: "u32",
16901
- uChanged: "u32",
16902
- ptAction: "i32[2]",
16903
- lParam: "ptr"
16904
- });
16905
- var CD_STAGE = NMCUSTOMDRAW.offsetOf("dwDrawStage");
16906
- var CD_HDC = NMCUSTOMDRAW.offsetOf("hdc");
16907
- var CD_ITEM = NMCUSTOMDRAW.offsetOf("dwItemSpec");
16908
17464
  var CD_CLRTEXT = NMLVCUSTOMDRAW.offsetOf("clrText");
16909
17465
  var CD_CLRTEXTBK = NMLVCUSTOMDRAW.offsetOf("clrTextBk");
16910
- var CD_SUBITEM = NMLVCUSTOMDRAW.offsetOf("iSubItem");
16911
- var NMIA_ITEM = NMLISTVIEW.offsetOf("iItem");
16912
- var NMIA_SUBITEM = NMLISTVIEW.offsetOf("iSubItem");
16913
- var NMLV_UNEW = NMLISTVIEW.offsetOf("uNewState");
16914
- var NMLV_UOLD = NMLISTVIEW.offsetOf("uOldState");
16915
- var LVITEMW = struct({
16916
- mask: "u32",
16917
- iItem: "i32",
16918
- iSubItem: "i32",
16919
- state: "u32",
16920
- stateMask: "u32",
16921
- pszText: "ptr",
16922
- cchTextMax: "i32",
16923
- iImage: "i32",
16924
- lParam: "ptr",
16925
- iIndent: "i32",
16926
- iGroupId: "i32",
16927
- cColumns: "u32",
16928
- puColumns: "ptr",
16929
- piColFmt: "ptr",
16930
- iGroup: "i32"
16931
- });
16932
- var LVCOLUMNW = struct({
16933
- mask: "u32",
16934
- fmt: "i32",
16935
- cx: "i32",
16936
- pszText: "ptr",
16937
- cchTextMax: "i32",
16938
- iSubItem: "i32",
16939
- iImage: "i32",
16940
- iOrder: "i32",
16941
- cxMin: "i32",
16942
- cxDefault: "i32",
16943
- cxIdeal: "i32"
16944
- });
16945
17466
  var fontCache = /* @__PURE__ */ new Map();
16946
- var gdi322 = null;
16947
- var createFontIndirectW = null;
16948
- var selectObjectFn = null;
16949
- var getObjectW = null;
16950
- function ensureGdi() {
16951
- if (gdi322 !== null)
16952
- return;
16953
- gdi322 = win2.LoadLibrary("gdi32.dll");
16954
- if (!gdi322)
16955
- return;
16956
- createFontIndirectW = win2.GetProcAddress(gdi322, "CreateFontIndirectW");
16957
- selectObjectFn = win2.GetProcAddress(gdi322, "SelectObject");
16958
- getObjectW = win2.GetProcAddress(gdi322, "GetObjectW");
16959
- }
16960
- var user322 = null;
16961
- var loadCursorW = null;
16962
- var setCursorFn = null;
16963
- var screenToClient = null;
16964
- function ensureUser32() {
16965
- if (user322 !== null)
16966
- return;
16967
- user322 = win2.LoadLibrary("user32.dll");
16968
- if (!user322)
16969
- return;
16970
- loadCursorW = win2.GetProcAddress(user322, "LoadCursorW");
16971
- setCursorFn = win2.GetProcAddress(user322, "SetCursor");
16972
- screenToClient = win2.GetProcAddress(user322, "ScreenToClient");
16973
- }
16974
17467
  function getCellFont(hwnd2, style) {
16975
17468
  const key = (style.bold ? "b" : "") + (style.italic ? "i" : "") + (style.underline ? "u" : "");
16976
17469
  if (key === "")
@@ -16978,39 +17471,37 @@ function getCellFont(hwnd2, style) {
16978
17471
  const cached = fontCache.get(key);
16979
17472
  if (cached !== void 0)
16980
17473
  return cached === 0 ? null : cached;
16981
- ensureGdi();
16982
- if (!createFontIndirectW || !getObjectW || !hwnd2)
17474
+ if (!hwnd2)
16983
17475
  return null;
16984
- const lf = new ArrayBuffer(92);
16985
- const dv = new DataView(lf);
16986
- const cur = gui10.SendMessage(hwnd2, 49, 0, 0);
17476
+ let base = { lfHeight: -13 };
17477
+ const cur = gui9.SendMessage(hwnd2, 49, 0, 0);
16987
17478
  if (cur) {
16988
- const got = ffi7.ffiCall(getObjectW, [ffi7.FFI_TYPE_POINTER, ffi7.FFI_TYPE_SINT32, ffi7.FFI_TYPE_POINTER], [cur, 92, lf], ffi7.FFI_TYPE_SINT32);
16989
- if (!got)
17479
+ const lf = LOGFONTW.alloc();
17480
+ if (!GetObject(cur, LOGFONTW.size, lf))
16990
17481
  return null;
16991
- } else {
16992
- dv.setInt32(0, -13, true);
17482
+ base = LOGFONTW.decode(lf);
16993
17483
  }
16994
- if (style.bold)
16995
- dv.setInt32(16, 700, true);
16996
- if (style.italic)
16997
- dv.setUint8(20, 1);
16998
- if (style.underline)
16999
- dv.setUint8(21, 1);
17000
- const h = ffi7.ffiCall(createFontIndirectW, [ffi7.FFI_TYPE_POINTER], [lf], ffi7.FFI_TYPE_POINTER);
17484
+ const h = CreateFontIndirect({
17485
+ ...base,
17486
+ ...style.bold ? {
17487
+ lfWeight: 700
17488
+ /* gui.FontWeight.BOLD */
17489
+ } : {},
17490
+ ...style.italic ? { lfItalic: 1 } : {},
17491
+ ...style.underline ? { lfUnderline: 1 } : {}
17492
+ });
17001
17493
  fontCache.set(key, h ? h : 0);
17002
17494
  return h ? h : null;
17003
17495
  }
17004
17496
  function handleCustomDraw(lParam, columns, data, hwnd2) {
17005
- const stage = readU32(lParam, CD_STAGE);
17497
+ const { dwDrawStage: stage } = NMCUSTOMDRAW.decode(lParam);
17006
17498
  if (stage === 1)
17007
17499
  return 32;
17008
17500
  if (stage === 65537)
17009
17501
  return 32;
17010
17502
  if (stage === 196609) {
17011
- const colIndex = readI32(lParam, CD_SUBITEM);
17012
- const row = readI32(lParam, CD_ITEM);
17013
- const style = resolveCellStyle(columns, data, row, colIndex);
17503
+ const cd = NMLVCUSTOMDRAW.decode(lParam);
17504
+ const style = resolveCellStyle(columns, data, cd.dwItemSpec, cd.iSubItem);
17014
17505
  if (!style)
17015
17506
  return 0;
17016
17507
  if (style.color !== void 0)
@@ -17018,12 +17509,9 @@ function handleCustomDraw(lParam, columns, data, hwnd2) {
17018
17509
  if (style.background !== void 0)
17019
17510
  writeU32(lParam, CD_CLRTEXTBK, style.background);
17020
17511
  const hfont = getCellFont(hwnd2, style);
17021
- if (hfont && selectObjectFn) {
17022
- const hdc = PTR_SIZE === 8 ? readU64(lParam, CD_HDC) : readU32(lParam, CD_HDC);
17023
- if (hdc) {
17024
- ffi7.ffiCall(selectObjectFn, [ffi7.FFI_TYPE_POINTER, ffi7.FFI_TYPE_POINTER], [hdc, hfont], ffi7.FFI_TYPE_POINTER);
17025
- return 2;
17026
- }
17512
+ if (hfont && cd.hdc) {
17513
+ SelectObject(cd.hdc, hfont);
17514
+ return 2;
17027
17515
  }
17028
17516
  }
17029
17517
  return 0;
@@ -17054,14 +17542,14 @@ function resolveCellStyle(columns, data, row, colIndex) {
17054
17542
  return style || void 0;
17055
17543
  }
17056
17544
  function makeLVItem(i, sub, text, image) {
17057
- const textBuf = textToUtf162(text);
17058
- const b = LVITEMW.write({
17545
+ const textBuf = WCHAR.encode(text);
17546
+ const b6 = LVITEMW.encode({
17059
17547
  mask: 1 | (image !== void 0 ? 2 : 0),
17060
17548
  iItem: i,
17061
17549
  iSubItem: sub,
17062
17550
  state: 0,
17063
17551
  stateMask: 0,
17064
- pszText: bufPtr2(textBuf),
17552
+ pszText: textBuf.ptr,
17065
17553
  cchTextMax: 0,
17066
17554
  iImage: image ?? 0,
17067
17555
  lParam: 0,
@@ -17072,8 +17560,8 @@ function makeLVItem(i, sub, text, image) {
17072
17560
  piColFmt: 0,
17073
17561
  iGroup: 0
17074
17562
  });
17075
- b.__textBuf = textBuf;
17076
- return b;
17563
+ b6.__textBuf = textBuf;
17564
+ return b6;
17077
17565
  }
17078
17566
  var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, data, style, icons, iconSize, getIcon }, ref) {
17079
17567
  const lvRef = (0, import_react9.useRef)(null);
@@ -17085,36 +17573,36 @@ var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, d
17085
17573
  const il = iconListRef.current;
17086
17574
  iconListRef.current = 0;
17087
17575
  if (il) {
17088
- gui10.SendMessage(h, 4099, 1, 0);
17089
- gui10.ImageListDestroy(il);
17576
+ gui9.SendMessage(h, 4099, 1, 0);
17577
+ gui9.ImageListDestroy(il);
17090
17578
  }
17091
17579
  if (!icons || icons.length === 0)
17092
17580
  return;
17093
17581
  const size = iconSize ?? 32;
17094
- const img = gui10.ImageListCreate(size, size, 32, icons.length, 1);
17582
+ const img = gui9.ImageListCreate(size, size, 32, icons.length, 1);
17095
17583
  if (!img)
17096
17584
  return;
17097
17585
  for (const p of icons) {
17098
- const hbm = gui10.CreateBitmapFromPixels(size, size, p);
17586
+ const hbm = gui9.CreateBitmapFromPixels(size, size, p);
17099
17587
  if (hbm) {
17100
- gui10.ImageListAdd(img, hbm);
17101
- gui10.DeleteObject(hbm);
17588
+ gui9.ImageListAdd(img, hbm);
17589
+ DeleteObject(hbm);
17102
17590
  }
17103
17591
  }
17104
- gui10.SendMessage(h, 4099, 1, img);
17592
+ gui9.SendMessage(h, 4099, 1, img);
17105
17593
  iconListRef.current = img;
17106
17594
  }, [icons, iconSize]);
17107
17595
  (0, import_react9.useEffect)(() => {
17108
17596
  const h = lvRef.current;
17109
17597
  if (!h)
17110
17598
  return;
17111
- const hdr = gui10.SendMessage(h, 4127, 0, 0);
17599
+ const hdr = gui9.SendMessage(h, 4127, 0, 0);
17112
17600
  if (hdr) {
17113
- let n2 = gui10.SendMessage(hdr, 4608, 0, 0);
17601
+ let n2 = gui9.SendMessage(hdr, 4608, 0, 0);
17114
17602
  for (let k = n2 - 1; k >= 0; k--)
17115
- gui10.SendMessage(h, 4124, k, 0);
17603
+ gui9.SendMessage(h, 4124, k, 0);
17116
17604
  }
17117
- gui10.SendMessage(
17605
+ gui9.SendMessage(
17118
17606
  h,
17119
17607
  4150,
17120
17608
  0,
@@ -17123,12 +17611,12 @@ var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, d
17123
17611
  );
17124
17612
  const n = columns.length;
17125
17613
  for (let j = 0; j < n; j++) {
17126
- const titleBuf = textToUtf162(columns[j].name);
17127
- const lvc = LVCOLUMNW.write({
17614
+ const titleBuf = WCHAR.encode(columns[j].name);
17615
+ const lvc = LVCOLUMNW.encode({
17128
17616
  mask: 4 | 2 | 1,
17129
17617
  fmt: alignToFmt(columns[j].align),
17130
17618
  cx: columns[j].width ?? 100,
17131
- pszText: bufPtr2(titleBuf),
17619
+ pszText: titleBuf.ptr,
17132
17620
  cchTextMax: 0,
17133
17621
  iSubItem: j,
17134
17622
  iImage: 0,
@@ -17138,28 +17626,28 @@ var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, d
17138
17626
  cxIdeal: 0
17139
17627
  });
17140
17628
  lvc.__titleBuf = titleBuf;
17141
- gui10.SendMessage(h, 4193, j, bufPtr2(lvc));
17629
+ gui9.SendMessage(h, 4193, j, lvc.ptr);
17142
17630
  }
17143
17631
  }, [columns]);
17144
17632
  (0, import_react9.useEffect)(() => {
17145
17633
  const h = lvRef.current;
17146
17634
  if (!h)
17147
17635
  return;
17148
- gui10.SendMessage(h, 4105, 0, 0);
17636
+ gui9.SendMessage(h, 4105, 0, 0);
17149
17637
  const nCols = columns.length;
17150
17638
  for (let i = 0; i < data.length; i++) {
17151
17639
  const record = data[i];
17152
17640
  const img = getIcon ? getIcon(record, i) : void 0;
17153
17641
  const itemBuf = makeLVItem(i, 0, cellText(record, columns[0], i), img);
17154
- gui10.SendMessage(h, 4173, 0, bufPtr2(itemBuf));
17642
+ gui9.SendMessage(h, 4173, 0, itemBuf.ptr);
17155
17643
  for (let j = 1; j < nCols; j++) {
17156
17644
  const subBuf = makeLVItem(i, j, cellText(record, columns[j], i));
17157
- gui10.SendMessage(h, 4172, 0, bufPtr2(subBuf));
17645
+ gui9.SendMessage(h, 4172, 0, subBuf.ptr);
17158
17646
  }
17159
17647
  }
17160
17648
  for (let j = 0; j < columns.length; j++) {
17161
17649
  if (columns[j].width == null) {
17162
- gui10.SendMessage(
17650
+ gui9.SendMessage(
17163
17651
  h,
17164
17652
  4126,
17165
17653
  j,
@@ -17176,14 +17664,12 @@ var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, d
17176
17664
  return handleCustomDraw(e.lParam, columns, data, lvRef.current);
17177
17665
  }
17178
17666
  if (code === -100) {
17179
- const uNewState = readU32(e.lParam, NMLV_UNEW);
17180
- const uOldState = readU32(e.lParam, NMLV_UOLD);
17667
+ const { uNewState, uOldState } = NMLISTVIEW.decode(e.lParam);
17181
17668
  if ((uNewState & 2) !== (uOldState & 2))
17182
17669
  return 1;
17183
17670
  }
17184
17671
  if (code === -2) {
17185
- const iItem = readI32(e.lParam, NMIA_ITEM);
17186
- const iSubItem = readI32(e.lParam, NMIA_SUBITEM);
17672
+ const { iItem, iSubItem } = NMLISTVIEW.decode(e.lParam);
17187
17673
  const col = columns[iSubItem];
17188
17674
  const record = data[iItem];
17189
17675
  if (col?.onCellClick && record !== void 0)
@@ -17201,33 +17687,20 @@ var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, d
17201
17687
  const h = lvRef.current;
17202
17688
  if (!h)
17203
17689
  return;
17204
- ensureUser32();
17205
- if (!loadCursorW || !setCursorFn || !screenToClient)
17206
- return;
17207
- const sp = gui10.GetCursorPos();
17208
- if (!sp)
17690
+ const pt = POINT.alloc();
17691
+ if (!GetCursorPos(pt.ptr))
17209
17692
  return;
17210
- const sbuf = new ArrayBuffer(8);
17211
- const sdv = new DataView(sbuf);
17212
- sdv.setInt32(0, sp[0], true);
17213
- sdv.setInt32(4, sp[1], true);
17214
- ffi7.ffiCall(screenToClient, [ffi7.FFI_TYPE_POINTER, ffi7.FFI_TYPE_POINTER], [h, sbuf], ffi7.FFI_TYPE_SINT32);
17215
- const lvhi = new ArrayBuffer(24);
17216
- const lvd = new DataView(lvhi);
17217
- lvd.setInt32(0, sdv.getInt32(0, true), true);
17218
- lvd.setInt32(4, sdv.getInt32(4, true), true);
17219
- lvd.setInt32(12, -1, true);
17220
- lvd.setInt32(16, -1, true);
17221
- const lvhiPtr = bufPtr2(lvhi);
17222
- gui10.SendMessage(h, 4153, 0, lvhiPtr);
17223
- const iItem = readI32(lvhiPtr, 12);
17224
- const iSubItem = readI32(lvhiPtr, 16);
17693
+ ScreenToClient(h, pt.ptr);
17694
+ const { x: sx, y: sy } = POINT.decode(pt);
17695
+ const hit = LVHITTESTINFO.encode({ pt: [sx, sy], iItem: -1, iSubItem: -1 });
17696
+ gui9.SendMessage(h, 4153, 0, hit.ptr);
17697
+ const { iItem, iSubItem } = LVHITTESTINFO.decode(hit);
17225
17698
  const style2 = resolveCellStyle(columns, data, iItem, iSubItem);
17226
17699
  if (!style2 || style2.cursor === void 0)
17227
17700
  return;
17228
- const hc = ffi7.ffiCall(loadCursorW, [ffi7.FFI_TYPE_POINTER, ffi7.FFI_TYPE_POINTER], [0, style2.cursor], ffi7.FFI_TYPE_POINTER);
17701
+ const hc = LoadCursor(NULL, style2.cursor);
17229
17702
  if (hc) {
17230
- ffi7.ffiCall(setCursorFn, [ffi7.FFI_TYPE_POINTER], [hc], ffi7.FFI_TYPE_POINTER);
17703
+ SetCursor(hc);
17231
17704
  return 1;
17232
17705
  }
17233
17706
  return;
@@ -17237,7 +17710,7 @@ var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, d
17237
17710
  // _build/lib/react-qw/components/ProgressBar.js
17238
17711
  var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1);
17239
17712
  var import_react10 = __toESM(require_react(), 1);
17240
- import * as gui11 from "gui";
17713
+ import * as gui10 from "gui";
17241
17714
  var ProgressBar = (0, import_react10.forwardRef)(({ value = 0, max = 100, style, smooth }, ref) => {
17242
17715
  const pbRef = (0, import_react10.useRef)(null);
17243
17716
  const ws = 268435456 | 8388608 | (smooth ? 1 : 0);
@@ -17245,8 +17718,8 @@ var ProgressBar = (0, import_react10.forwardRef)(({ value = 0, max = 100, style,
17245
17718
  const h = pbRef.current;
17246
17719
  if (!h)
17247
17720
  return;
17248
- gui11.SendMessage(h, 1030, 0, max);
17249
- gui11.SendMessage(h, 1026, Math.min(value, max), 0);
17721
+ gui10.SendMessage(h, 1030, 0, max);
17722
+ gui10.SendMessage(h, 1026, Math.min(value, max), 0);
17250
17723
  }, [value, max]);
17251
17724
  return (0, import_jsx_runtime9.jsx)("w", { type: "msctls_progress32", ws, style, ref: (h) => {
17252
17725
  pbRef.current = h;
@@ -17260,7 +17733,7 @@ var ProgressBar = (0, import_react10.forwardRef)(({ value = 0, max = 100, style,
17260
17733
  // _build/lib/react-qw/components/RadioButton.js
17261
17734
  var import_jsx_runtime10 = __toESM(require_jsx_runtime(), 1);
17262
17735
  var import_react11 = __toESM(require_react(), 1);
17263
- import * as gui12 from "gui";
17736
+ import * as gui11 from "gui";
17264
17737
  var RadioButton = (0, import_react11.forwardRef)(({ checked: controlledChecked, defaultChecked = false, onChange, label, style, disabled }, ref) => {
17265
17738
  const [internalChecked, setInternalChecked] = (0, import_react11.useState)(defaultChecked);
17266
17739
  const isControlled = controlledChecked !== void 0;
@@ -17270,7 +17743,7 @@ var RadioButton = (0, import_react11.forwardRef)(({ checked: controlledChecked,
17270
17743
  const h = rbRef.current;
17271
17744
  if (!h)
17272
17745
  return;
17273
- gui12.SendMessage(h, 241, displayChecked ? 1 : 0, 0);
17746
+ gui11.SendMessage(h, 241, displayChecked ? 1 : 0, 0);
17274
17747
  }, [displayChecked]);
17275
17748
  return (0, import_jsx_runtime10.jsx)("w", { type: "BUTTON", text: label ?? "", ws: 268435456 | 9, style, disabled, ref: (h) => {
17276
17749
  rbRef.current = h;
@@ -17280,7 +17753,7 @@ var RadioButton = (0, import_react11.forwardRef)(({ checked: controlledChecked,
17280
17753
  ref.current = h;
17281
17754
  }, onEvent: (e) => {
17282
17755
  if (e.msg === 514) {
17283
- const newChecked = gui12.SendMessage(e.hwnd, 240, 0, 0) !== 0;
17756
+ const newChecked = gui11.SendMessage(e.hwnd, 240, 0, 0) !== 0;
17284
17757
  if (newChecked !== displayChecked) {
17285
17758
  if (!isControlled)
17286
17759
  setInternalChecked(newChecked);
@@ -17293,24 +17766,27 @@ var RadioButton = (0, import_react11.forwardRef)(({ checked: controlledChecked,
17293
17766
  // _build/lib/react-qw/components/ScrollView.js
17294
17767
  var import_jsx_runtime11 = __toESM(require_jsx_runtime(), 1);
17295
17768
  var import_react12 = __toESM(require_react(), 1);
17296
- import * as gui13 from "gui";
17769
+ import * as gui12 from "gui";
17297
17770
  var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth, contentHeight }, ref) => {
17298
17771
  const svRef = (0, import_react12.useRef)(null);
17299
17772
  const contentRef = (0, import_react12.useRef)(null);
17300
17773
  const scrollXRef = (0, import_react12.useRef)(0);
17301
17774
  const scrollYRef = (0, import_react12.useRef)(0);
17302
17775
  function updateScroll(sv, content) {
17303
- const svRect = gui13.GetClientRect(sv);
17776
+ const svRect = gui12.GetClientRect(sv);
17304
17777
  if (!svRect)
17305
17778
  return;
17306
17779
  const svW = svRect.right - svRect.left;
17307
17780
  const svH = svRect.bottom - svRect.top;
17308
- const scale = gui13.GetScaleFactor();
17781
+ const hdc = GetDC(NULL);
17782
+ const scale = hdc ? GetDeviceCaps(hdc, 88) / 96 : 1;
17783
+ if (hdc)
17784
+ ReleaseDC(NULL, hdc);
17309
17785
  const natW = Math.round((contentWidth ?? svW / scale) * scale);
17310
17786
  const natH = Math.round((contentHeight ?? svH / scale) * scale);
17311
17787
  scrollXRef.current = Math.max(0, Math.min(scrollXRef.current, natW - svW));
17312
17788
  scrollYRef.current = Math.max(0, Math.min(scrollYRef.current, natH - svH));
17313
- gui13.SetWindowPos(
17789
+ SetWindowPos(
17314
17790
  content,
17315
17791
  0,
17316
17792
  -scrollXRef.current,
@@ -17322,18 +17798,18 @@ var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth
17322
17798
  );
17323
17799
  forceFlexLayout(content);
17324
17800
  if (natW > svW) {
17325
- gui13.SetScrollInfo(sv, 0, { min: 0, max: natW - 1, page: svW, pos: scrollXRef.current }, true);
17326
- gui13.ShowScrollBar(sv, 0, true);
17801
+ gui12.SetScrollInfo(sv, 0, { min: 0, max: natW - 1, page: svW, pos: scrollXRef.current }, true);
17802
+ ShowScrollBar(sv, 0, 1);
17327
17803
  } else {
17328
17804
  scrollXRef.current = 0;
17329
- gui13.ShowScrollBar(sv, 0, false);
17805
+ ShowScrollBar(sv, 0, 0);
17330
17806
  }
17331
17807
  if (natH > svH) {
17332
- gui13.SetScrollInfo(sv, 1, { min: 0, max: natH - 1, page: svH, pos: scrollYRef.current }, true);
17333
- gui13.ShowScrollBar(sv, 1, true);
17808
+ gui12.SetScrollInfo(sv, 1, { min: 0, max: natH - 1, page: svH, pos: scrollYRef.current }, true);
17809
+ ShowScrollBar(sv, 1, 1);
17334
17810
  } else {
17335
17811
  scrollYRef.current = 0;
17336
- gui13.ShowScrollBar(sv, 1, false);
17812
+ ShowScrollBar(sv, 1, 0);
17337
17813
  }
17338
17814
  }
17339
17815
  (0, import_react12.useLayoutEffect)(() => {
@@ -17349,7 +17825,7 @@ var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth
17349
17825
  } else {
17350
17826
  scrollXRef.current = newPos;
17351
17827
  }
17352
- gui13.SetWindowPos(
17828
+ SetWindowPos(
17353
17829
  content,
17354
17830
  0,
17355
17831
  -scrollXRef.current,
@@ -17359,14 +17835,14 @@ var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth
17359
17835
  1 | 4
17360
17836
  /* gui.SetWindowPosFlag.SWP_NOZORDER */
17361
17837
  );
17362
- gui13.SetScrollInfo(sv, bar, { pos: newPos }, true);
17838
+ gui12.SetScrollInfo(sv, bar, { pos: newPos }, true);
17363
17839
  }
17364
17840
  function handleScroll(e, bar) {
17365
17841
  const sv = svRef.current;
17366
17842
  const content = contentRef.current;
17367
17843
  if (!sv || !content)
17368
17844
  return;
17369
- const info = gui13.GetScrollInfo(sv, bar);
17845
+ const info = gui12.GetScrollInfo(sv, bar);
17370
17846
  const maxPos = info.max - info.page + 1;
17371
17847
  const code = e.wParam & 65535;
17372
17848
  const ref_ = bar === 1 ? scrollYRef : scrollXRef;
@@ -17400,7 +17876,7 @@ var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth
17400
17876
  if (!isHorz && contentHeight === void 0)
17401
17877
  return;
17402
17878
  const bar = isHorz ? 0 : 1;
17403
- const info = gui13.GetScrollInfo(sv, bar);
17879
+ const info = gui12.GetScrollInfo(sv, bar);
17404
17880
  const maxPos = info.max - info.page + 1;
17405
17881
  const ref_ = isHorz ? scrollXRef : scrollYRef;
17406
17882
  let newPos = ref_.current + dy;
@@ -17417,7 +17893,7 @@ var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth
17417
17893
  }, onEvent: {
17418
17894
  fn: (e) => {
17419
17895
  if (e.msg === 132 || e.msg === 161) {
17420
- return gui13.DefWindowProc(e.hwnd, e.msg, e.wParam, e.lParam);
17896
+ return DefWindowProc(e.hwnd, e.msg, e.wParam, e.lParam);
17421
17897
  }
17422
17898
  if (e.msg === 277) {
17423
17899
  handleScroll(
@@ -17449,7 +17925,7 @@ var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth
17449
17925
  // _build/lib/react-qw/components/Slider.js
17450
17926
  var import_jsx_runtime12 = __toESM(require_jsx_runtime(), 1);
17451
17927
  var import_react13 = __toESM(require_react(), 1);
17452
- import * as gui14 from "gui";
17928
+ import * as gui13 from "gui";
17453
17929
  var Slider = (0, import_react13.forwardRef)(({ value, onChange, min = 0, max = 100, vertical = false, disabled, style }, ref) => {
17454
17930
  const wrapperRef = (0, import_react13.useRef)(null);
17455
17931
  const sliderRef = (0, import_react13.useRef)(null);
@@ -17458,14 +17934,14 @@ var Slider = (0, import_react13.forwardRef)(({ value, onChange, min = 0, max = 1
17458
17934
  if (!h)
17459
17935
  return;
17460
17936
  const lParam = min & 65535 | (max & 65535) << 16;
17461
- gui14.SendMessage(h, 1030, 0, lParam);
17462
- gui14.SendMessage(h, 1029, 1, value);
17937
+ gui13.SendMessage(h, 1030, 0, lParam);
17938
+ gui13.SendMessage(h, 1029, 1, value);
17463
17939
  }, [min, max]);
17464
17940
  (0, import_react13.useEffect)(() => {
17465
17941
  const h = sliderRef.current;
17466
17942
  if (!h)
17467
17943
  return;
17468
- gui14.SendMessage(h, 1029, 1, value);
17944
+ gui13.SendMessage(h, 1029, 1, value);
17469
17945
  }, [value]);
17470
17946
  const tbStyle = 268435456 | 65536 | 1 | (vertical ? 2 : 0);
17471
17947
  return (0, import_jsx_runtime12.jsx)("w", { type: "STATIC", ws: 268435456 | 33554432, style, ref: (h) => {
@@ -17476,13 +17952,13 @@ var Slider = (0, import_react13.forwardRef)(({ value, onChange, min = 0, max = 1
17476
17952
  ref.current = h;
17477
17953
  }, onEvent: (e) => {
17478
17954
  if (e.msg === 132 || e.msg === 161) {
17479
- return gui14.DefWindowProc(e.hwnd, e.msg, e.wParam, e.lParam);
17955
+ return DefWindowProc(e.hwnd, e.msg, e.wParam, e.lParam);
17480
17956
  }
17481
17957
  if (e.msg === 276 || e.msg === 277) {
17482
17958
  const h = sliderRef.current;
17483
17959
  if (!h)
17484
17960
  return 0;
17485
- const pos = gui14.SendMessage(h, 1024, 0, 0);
17961
+ const pos = gui13.SendMessage(h, 1024, 0, 0);
17486
17962
  onChange?.(pos);
17487
17963
  return 0;
17488
17964
  }
@@ -17495,24 +17971,7 @@ var Slider = (0, import_react13.forwardRef)(({ value, onChange, min = 0, max = 1
17495
17971
  // _build/lib/react-qw/components/Tab.js
17496
17972
  var import_jsx_runtime13 = __toESM(require_jsx_runtime(), 1);
17497
17973
  var import_react14 = __toESM(require_react(), 1);
17498
- import * as gui15 from "gui";
17499
- import * as ffi8 from "ffi";
17500
- var TCITEMW = struct({
17501
- mask: "u32",
17502
- dwState: "u32",
17503
- dwStateMask: "u32",
17504
- pszText: "ptr",
17505
- cchTextMax: "i32",
17506
- iImage: "i32",
17507
- lParam: "ptr"
17508
- });
17509
- function textToUtf163(s) {
17510
- const buf = new ArrayBuffer((s.length + 1) * 2);
17511
- const dv = new DataView(buf);
17512
- for (let i = 0; i < s.length; i++)
17513
- dv.setUint16(i * 2, s.charCodeAt(i), true);
17514
- return buf;
17515
- }
17974
+ import * as gui14 from "gui";
17516
17975
  var Tab = (0, import_react14.forwardRef)(({ tabs, selectedIndex: controlledIndex, defaultSelectedIndex = 0, onChange, style }, ref) => {
17517
17976
  const [internalIndex, setInternalIndex] = (0, import_react14.useState)(defaultSelectedIndex);
17518
17977
  const isControlled = controlledIndex !== void 0;
@@ -17522,27 +17981,27 @@ var Tab = (0, import_react14.forwardRef)(({ tabs, selectedIndex: controlledIndex
17522
17981
  const h = tabHwnd.current;
17523
17982
  if (!h)
17524
17983
  return;
17525
- gui15.SendMessage(h, 4873, 0, 0);
17984
+ gui14.SendMessage(h, 4873, 0, 0);
17526
17985
  for (let i = 0; i < tabs.length; i++) {
17527
- const titleBuf = textToUtf163(tabs[i].title);
17528
- const tci = TCITEMW.write({
17986
+ const titleBuf = WCHAR.encode(tabs[i].title);
17987
+ const tci = TCITEMW.encode({
17529
17988
  mask: 1,
17530
17989
  dwState: 0,
17531
17990
  dwStateMask: 0,
17532
- pszText: ffi8.bufferPtr(titleBuf),
17991
+ pszText: titleBuf.ptr,
17533
17992
  cchTextMax: tabs[i].title.length + 1,
17534
17993
  iImage: 0,
17535
17994
  lParam: 0
17536
17995
  });
17537
- const tciPtr = ffi8.bufferPtr(tci);
17538
- gui15.SendMessage(h, 4926, i, tciPtr);
17996
+ const tciPtr = tci.ptr;
17997
+ gui14.SendMessage(h, 4926, i, tciPtr);
17539
17998
  }
17540
- gui15.SendMessage(h, 4876, sel, 0);
17999
+ gui14.SendMessage(h, 4876, sel, 0);
17541
18000
  }, [tabs]);
17542
18001
  (0, import_react14.useEffect)(() => {
17543
18002
  const h = tabHwnd.current;
17544
18003
  if (h)
17545
- gui15.SendMessage(h, 4876, sel, 0);
18004
+ gui14.SendMessage(h, 4876, sel, 0);
17546
18005
  }, [sel]);
17547
18006
  return (0, import_jsx_runtime13.jsxs)("w", { type: "STATIC", ws: 268435456 | 33554432, style: { ...style, flexDirection: "column", alignItems: "stretch" }, ref, onEvent: (e) => {
17548
18007
  if (e.msg === 78) {
@@ -17551,7 +18010,7 @@ var Tab = (0, import_react14.forwardRef)(({ tabs, selectedIndex: controlledIndex
17551
18010
  return;
17552
18011
  const code = nmCode(e.lParam);
17553
18012
  if (code === -552 || code === -2) {
17554
- const newSel = gui15.SendMessage(h, 4875, 0, 0);
18013
+ const newSel = gui14.SendMessage(h, 4875, 0, 0);
17555
18014
  if (newSel !== sel) {
17556
18015
  if (!isControlled)
17557
18016
  setInternalIndex(newSel);
@@ -17564,54 +18023,17 @@ var Tab = (0, import_react14.forwardRef)(({ tabs, selectedIndex: controlledIndex
17564
18023
 
17565
18024
  // _build/lib/react-qw/components/Tooltip.js
17566
18025
  var import_react15 = __toESM(require_react(), 1);
17567
- import * as gui16 from "gui";
17568
- import * as ffi9 from "ffi";
17569
- var TTTOOLINFOW = struct({
17570
- cbSize: "u32",
17571
- uFlags: "u32",
17572
- hwnd: "ptr",
17573
- uId: "ptr",
17574
- rect: "i32[4]",
17575
- hinst: "ptr",
17576
- lpszText: "ptr",
17577
- lParam: "ptr",
17578
- lpReserved: "ptr"
17579
- // WinXP+ 追加字段(系统 sizeof 含之)
17580
- });
18026
+ import * as gui15 from "gui";
17581
18027
 
17582
18028
  // _build/lib/react-qw/components/TreeView.js
17583
18029
  var import_jsx_runtime14 = __toESM(require_jsx_runtime(), 1);
17584
18030
  var import_react16 = __toESM(require_react(), 1);
17585
- import * as gui17 from "gui";
17586
- import * as ffi10 from "ffi";
17587
- var TVITEM = struct({
17588
- mask: "u32",
17589
- hItem: "ptr",
17590
- state: "u32",
17591
- stateMask: "u32",
17592
- pszText: "ptr",
17593
- cchTextMax: "i32",
17594
- iImage: "i32",
17595
- iSelectedImage: "i32",
17596
- cChildren: "i32",
17597
- lParam: "ptr"
17598
- });
17599
- var TVINSERTSTRUCT = struct({ hParent: "ptr", hInsertAfter: "ptr", item: TVITEM });
17600
- function textToUtf164(s) {
17601
- const buf = new ArrayBuffer((s.length + 1) * 2);
17602
- const dv = new DataView(buf);
17603
- for (let i = 0; i < s.length; i++)
17604
- dv.setUint16(i * 2, s.charCodeAt(i), true);
17605
- return buf;
17606
- }
17607
- function bufPtr3(buf) {
17608
- return ffi10.bufferPtr(buf);
17609
- }
18031
+ import * as gui16 from "gui";
17610
18032
  function buildTvItem(textPtr, cChildren) {
17611
18033
  let mask = 1;
17612
18034
  if (cChildren > 0)
17613
18035
  mask |= 64;
17614
- return TVITEM.write({
18036
+ return TVITEM.encode({
17615
18037
  mask,
17616
18038
  hItem: 0,
17617
18039
  state: 0,
@@ -17627,24 +18049,24 @@ function buildTvItem(textPtr, cChildren) {
17627
18049
  function insertItems(hTree, nodes, parentHandle, hItemMap, keyMap) {
17628
18050
  for (const node of nodes) {
17629
18051
  const cChildren = node.children && node.children.length > 0 ? 1 : 0;
17630
- const textBuf = textToUtf164(node.label);
17631
- const itemBuf = buildTvItem(bufPtr3(textBuf), cChildren);
17632
- const item = TVITEM.read(itemBuf);
17633
- const tvins = TVINSERTSTRUCT.write({ hParent: parentHandle, hInsertAfter: -65536, item });
17634
- const hItem = gui17.SendMessage(hTree, 4402, 0, bufPtr3(tvins));
18052
+ const textBuf = WCHAR.encode(node.label);
18053
+ const itemBuf = buildTvItem(textBuf.ptr, cChildren);
18054
+ const item = TVITEM.decode(itemBuf);
18055
+ const tvins = TVINSERTSTRUCT.encode({ hParent: parentHandle, hInsertAfter: -65536, item });
18056
+ const hItem = gui16.SendMessage(hTree, 4402, 0, tvins.ptr);
17635
18057
  hItemMap.set(hItem, node);
17636
18058
  if (node.key)
17637
18059
  keyMap.set(node.key, hItem);
17638
18060
  if (node.children && node.children.length > 0) {
17639
18061
  insertItems(hTree, node.children, hItem, hItemMap, keyMap);
17640
- gui17.SendMessage(hTree, 4354, 2, hItem);
18062
+ gui16.SendMessage(hTree, 4354, 2, hItem);
17641
18063
  }
17642
18064
  }
17643
18065
  }
17644
18066
  function deleteAllItems(hTree) {
17645
- const n = gui17.SendMessage(hTree, 4357, 0, 0);
18067
+ const n = gui16.SendMessage(hTree, 4357, 0, 0);
17646
18068
  if (n > 0)
17647
- gui17.SendMessage(
18069
+ gui16.SendMessage(
17648
18070
  hTree,
17649
18071
  4353,
17650
18072
  1,
@@ -17676,7 +18098,7 @@ var TreeView = (0, import_react16.forwardRef)(function TreeViewInner({ data, onS
17676
18098
  const h = tvRef.current;
17677
18099
  if (!h)
17678
18100
  return;
17679
- gui17.SendMessage(
18101
+ gui16.SendMessage(
17680
18102
  h,
17681
18103
  4396,
17682
18104
  0,
@@ -17692,7 +18114,7 @@ var TreeView = (0, import_react16.forwardRef)(function TreeViewInner({ data, onS
17692
18114
  return;
17693
18115
  const hItem = keyMapRef.current.get(selKey);
17694
18116
  if (hItem !== void 0)
17695
- gui17.SendMessage(h, 4363, 9, hItem);
18117
+ gui16.SendMessage(h, 4363, 9, hItem);
17696
18118
  }, [selKey]);
17697
18119
  return (0, import_jsx_runtime14.jsx)("w", { type: "STATIC", ws: 268435456 | 33554432, style: { ...style, flexDirection: "column", alignItems: "stretch" }, ref, onEvent: (e) => {
17698
18120
  if (e.msg === 78) {
@@ -17701,7 +18123,7 @@ var TreeView = (0, import_react16.forwardRef)(function TreeViewInner({ data, onS
17701
18123
  const h = tvRef.current;
17702
18124
  if (!h)
17703
18125
  return;
17704
- const hCaret = gui17.SendMessage(h, 4362, 9, 0);
18126
+ const hCaret = gui16.SendMessage(h, 4362, 9, 0);
17705
18127
  const node = hItemMapRef.current.get(hCaret) ?? null;
17706
18128
  const key = node?.key ?? null;
17707
18129
  if (!isControlled)
@@ -17717,153 +18139,63 @@ var TreeView = (0, import_react16.forwardRef)(function TreeViewInner({ data, onS
17717
18139
  // _build/lib/react-qw/components/PathPicker.js
17718
18140
  var import_jsx_runtime15 = __toESM(require_jsx_runtime(), 1);
17719
18141
  var import_react17 = __toESM(require_react(), 1);
17720
- import * as ffi11 from "ffi";
17721
- import * as win3 from "win";
17722
18142
 
17723
- // _build/lib/win-common-structs.js
17724
- var OPENFILENAMEW = struct({
17725
- lStructSize: "u32",
17726
- hwndOwner: "ptr",
17727
- hInstance: "ptr",
17728
- lpstrFilter: "ptr",
17729
- lpstrCustomFilter: "ptr",
17730
- nMaxCustFilter: "u32",
17731
- nFilterIndex: "u32",
17732
- lpstrFile: "ptr",
17733
- nMaxFile: "u32",
17734
- lpstrFileTitle: "ptr",
17735
- nMaxFileTitle: "u32",
17736
- lpstrInitialDir: "ptr",
17737
- lpstrTitle: "ptr",
17738
- Flags: "u32",
17739
- nFileOffset: "u16",
17740
- nFileExtension: "u16",
17741
- lpstrDefExt: "ptr",
17742
- lCustData: "ptr",
17743
- lpfnHook: "ptr",
17744
- lpTemplateName: "ptr",
17745
- pvReserved: "ptr",
17746
- dwReserved: "u32",
17747
- FlagsEx: "u32"
17748
- });
17749
- var BROWSEINFOW = struct({
17750
- hwndOwner: "ptr",
17751
- pidlRoot: "ptr",
17752
- pszDisplayName: "ptr",
17753
- lpszTitle: "ptr",
17754
- ulFlags: "u32",
17755
- lpfn: "ptr",
17756
- lParam: "ptr",
17757
- iImage: "i32"
17758
- });
18143
+ // _build/lib/windows/comdlg32.js
18144
+ var b3 = (name, sig) => bind("comdlg32.dll", name, sig);
18145
+ var GetOpenFileName = /* @__PURE__ */ b3("GetOpenFileNameW", "<OPENFILENAMEW>ptr -> u32");
18146
+
18147
+ // _build/lib/windows/shell32.js
18148
+ var b4 = (name, sig) => bind("shell32.dll", name, sig);
18149
+ var SHBrowseForFolder = /* @__PURE__ */ b4("SHBrowseForFolderW", "<BROWSEINFOW>ptr -> <>ptr");
18150
+ var SHGetPathFromIDList = /* @__PURE__ */ b4("SHGetPathFromIDListW", "<>ptr <BYTE>ptr -> u32");
18151
+
18152
+ // _build/lib/windows/ole32.js
18153
+ var b5 = (name, sig) => bind("ole32.dll", name, sig);
18154
+ var CoTaskMemFree = /* @__PURE__ */ b5("CoTaskMemFree", "<>ptr -> void");
17759
18155
 
17760
18156
  // _build/lib/react-qw/components/PathPicker.js
17761
- var FFI_PTR = ffi11.FFI_TYPE_POINTER;
17762
- var FFI_U32 = ffi11.FFI_TYPE_UINT32;
17763
- var _GetOpenFileNameW = 0;
17764
- var _SHBrowseForFolderW = 0;
17765
- var _SHGetPathFromIDListW = 0;
17766
- var _CoTaskMemFree = 0;
17767
- function ensureDlls() {
17768
- if (_GetOpenFileNameW)
17769
- return true;
17770
- const comdlg32 = win3.LoadLibrary("comdlg32.dll");
17771
- const shell32 = win3.LoadLibrary("shell32.dll");
17772
- const ole32 = win3.LoadLibrary("ole32.dll");
17773
- if (!comdlg32 || !shell32 || !ole32)
17774
- return false;
17775
- const load = (lib, name) => win3.GetProcAddress(lib, name) || 0;
17776
- _GetOpenFileNameW = load(comdlg32, "GetOpenFileNameW");
17777
- _SHBrowseForFolderW = load(shell32, "SHBrowseForFolderW");
17778
- _SHGetPathFromIDListW = load(shell32, "SHGetPathFromIDListW");
17779
- _CoTaskMemFree = load(ole32, "CoTaskMemFree");
17780
- return !!_GetOpenFileNameW && !!_SHBrowseForFolderW && !!_SHGetPathFromIDListW && !!_CoTaskMemFree;
17781
- }
17782
- function strToWide(s) {
17783
- return new TextEncoder("utf-16le").encode(s + "\0").buffer;
17784
- }
17785
- var _decoder = new TextDecoder("utf-16le");
17786
- function wideToStr(buf, offset = 0) {
17787
- const str = _decoder.decode(new Uint8Array(buf, offset));
17788
- const nullIdx = str.indexOf("\0");
17789
- return nullIdx >= 0 ? str.substring(0, nullIdx) : str;
17790
- }
17791
18157
  function openFileDialog(owner, filter, title, multiple) {
17792
- if (!ensureDlls())
17793
- return null;
17794
- const fileBuf = new ArrayBuffer(260 * 2);
17795
- const filterWide = strToWide(filter);
17796
- const titleWide = title ? strToWide(title) : null;
18158
+ const fileBuf = WCHAR.alloc(260);
18159
+ const filterWide = WCHAR.encode(filter);
18160
+ const titleWide = title ? WCHAR.encode(title) : null;
17797
18161
  let flags = 4096 | 2048 | 8;
17798
18162
  if (multiple)
17799
18163
  flags |= 512;
17800
18164
  flags |= 524288;
17801
- const ofn = OPENFILENAMEW.write({
18165
+ const ofn = OPENFILENAMEW.encode({
17802
18166
  lStructSize: OPENFILENAMEW.size,
17803
18167
  hwndOwner: owner,
17804
- hInstance: 0,
17805
- lpstrFilter: ffi11.bufferPtr(filterWide),
17806
- lpstrCustomFilter: 0,
17807
- nMaxCustFilter: 0,
17808
- nFilterIndex: 0,
17809
- lpstrFile: ffi11.bufferPtr(fileBuf),
18168
+ lpstrFilter: filterWide.ptr,
18169
+ lpstrFile: fileBuf.ptr,
17810
18170
  nMaxFile: 260,
17811
- lpstrFileTitle: 0,
17812
- nMaxFileTitle: 0,
17813
- lpstrInitialDir: 0,
17814
- lpstrTitle: titleWide ? ffi11.bufferPtr(titleWide) : 0,
17815
- Flags: flags,
17816
- nFileOffset: 0,
17817
- nFileExtension: 0,
17818
- lpstrDefExt: 0,
17819
- lCustData: 0,
17820
- lpfnHook: 0,
17821
- lpTemplateName: 0,
17822
- pvReserved: 0,
17823
- dwReserved: 0,
17824
- FlagsEx: 0
18171
+ lpstrTitle: titleWide?.ptr ?? 0,
18172
+ Flags: flags
17825
18173
  });
17826
- const ret = ffi11.ffiCall(_GetOpenFileNameW, [FFI_PTR], [ofn], FFI_U32);
18174
+ const ret = GetOpenFileName(ofn.ptr);
17827
18175
  if (!ret)
17828
18176
  return null;
17829
18177
  if (!multiple) {
17830
- return wideToStr(fileBuf);
17831
- }
17832
- const dir = wideToStr(fileBuf);
17833
- let pos = (dir.length + 1) * 2;
17834
- const files = [];
17835
- while (pos < fileBuf.byteLength) {
17836
- const f = wideToStr(fileBuf, pos);
17837
- if (f.length === 0)
17838
- break;
17839
- files.push(dir + "\\" + f);
17840
- pos += (f.length + 1) * 2;
18178
+ return WCHAR.decode(fileBuf);
17841
18179
  }
17842
- if (files.length === 0)
17843
- return [dir];
17844
- return files;
18180
+ const strs = new TextDecoder("utf-16le").decode(new Uint8Array(fileBuf)).split("\0");
18181
+ const dir = strs[0] ?? "";
18182
+ const files = strs.slice(1).filter((f) => f.length > 0).map((f) => dir + "\\" + f);
18183
+ return files.length > 0 ? files : [dir];
17845
18184
  }
17846
18185
  function openFolderDialog(owner, title) {
17847
- if (!ensureDlls())
17848
- return null;
17849
- const titleWide = title ? strToWide(title) : null;
17850
- const bi = BROWSEINFOW.write({
18186
+ const titleWide = title ? WCHAR.encode(title) : null;
18187
+ const bi = BROWSEINFOW.encode({
17851
18188
  hwndOwner: owner,
17852
- pidlRoot: 0,
17853
- pszDisplayName: 0,
17854
- lpszTitle: titleWide ? ffi11.bufferPtr(titleWide) : 0,
17855
- ulFlags: 65,
17856
- lpfn: 0,
17857
- lParam: 0,
17858
- iImage: 0
18189
+ lpszTitle: titleWide?.ptr ?? 0,
18190
+ ulFlags: 65
17859
18191
  });
17860
- const pidl = ffi11.ffiCall(_SHBrowseForFolderW, [FFI_PTR], [bi], FFI_PTR);
18192
+ const pidl = SHBrowseForFolder(bi.ptr);
17861
18193
  if (!pidl)
17862
18194
  return null;
17863
- const pathBuf = new ArrayBuffer(260 * 2);
17864
- const ok = ffi11.ffiCall(_SHGetPathFromIDListW, [ffi11.FFI_TYPE_POINTER, FFI_PTR], [pidl, pathBuf], FFI_U32);
17865
- ffi11.ffiCall(_CoTaskMemFree, [ffi11.FFI_TYPE_POINTER], [pidl], ffi11.FFI_TYPE_VOID);
17866
- return ok ? wideToStr(pathBuf) : null;
18195
+ const pathBuf = WCHAR.alloc(260);
18196
+ const ok = SHGetPathFromIDList(pidl, pathBuf);
18197
+ CoTaskMemFree(pidl);
18198
+ return ok ? WCHAR.decode(pathBuf) : null;
17867
18199
  }
17868
18200
  var PathPicker = (0, import_react17.forwardRef)((props, ref) => {
17869
18201
  const { type = "file", filter = "All Files\0*.*\0\0", title, disabled, style } = props;
@@ -17914,7 +18246,7 @@ var rootMap = /* @__PURE__ */ new Map();
17914
18246
  function ensureDefaultClass() {
17915
18247
  if (defaultClassRegistered)
17916
18248
  return DEFAULT_CLASS;
17917
- gui18.RegisterClass(DEFAULT_CLASS, (hwnd2, msg, wParam, lParam) => {
18249
+ gui17.RegisterClass(DEFAULT_CLASS, (hwnd2, msg, wParam, lParam) => {
17918
18250
  const entry = rootMap.get(hwnd2);
17919
18251
  if (msg === 2 && entry) {
17920
18252
  rootMap.delete(hwnd2);
@@ -17927,7 +18259,7 @@ function ensureDefaultClass() {
17927
18259
  return result;
17928
18260
  if (msg === 5)
17929
18261
  forceFlexLayout(hwnd2);
17930
- return gui18.DefWindowProc(hwnd2, msg, wParam, lParam);
18262
+ return DefWindowProc(hwnd2, msg, wParam, lParam);
17931
18263
  });
17932
18264
  defaultClassRegistered = true;
17933
18265
  return DEFAULT_CLASS;
@@ -17940,19 +18272,19 @@ function createRoot(container) {
17940
18272
  const ws = (cfg.ws ?? 0) | 13565952;
17941
18273
  const w = (cfg.width ?? 800) * scaleFactor;
17942
18274
  const h = (cfg.height ?? 600) * scaleFactor;
17943
- const [sw, sh] = gui18.GetScreenSize();
18275
+ const [sw, sh] = [GetSystemMetrics(0), GetSystemMetrics(1)];
17944
18276
  const x = cfg.x === void 0 ? (sw - w) / 2 | 0 : cfg.x === -2147483648 ? -2147483648 : cfg.x * scaleFactor;
17945
18277
  const y = cfg.y === void 0 ? (sh - h) / 2 | 0 : cfg.y === -2147483648 ? -2147483648 : cfg.y * scaleFactor;
17946
- const hwin = gui18.CreateWindow(className, cfg.text || "", ws, x, y, w, h, null, null);
18278
+ const hwin = gui17.CreateWindow(className, cfg.text || "", ws, x, y, w, h, null, null);
17947
18279
  if (!hwin)
17948
18280
  throw new Error("CreateWindow failed");
17949
18281
  hwnd2 = hwin;
17950
18282
  if (!cfg.noShowWindow)
17951
- gui18.ShowWindow(hwnd2);
18283
+ gui17.ShowWindow(hwnd2);
17952
18284
  } else {
17953
18285
  hwnd2 = container;
17954
18286
  }
17955
- const root = reconciler_default.createContainer(hwnd2, 0, null, false, null, "", noop, noop, noop, noop);
18287
+ const root = reconciler_default.createContainer(hwnd2, 0, null, false, null, "", (error, info) => console.log("[React uncaught]", error, error.stack, info.componentStack), (error, info) => console.log("[React caught]", error, error.stack, info.componentStack), (error, info) => console.log("[React recoverable]", error, error.stack, info.componentStack), noop);
17956
18288
  const rootInst = { hwnd: hwnd2, type: "_root", props: { type: "_root", style: { flexDirection: "column", alignItems: "stretch" } }, children: [] };
17957
18289
  instancesByHwnd.set(hwnd2, rootInst);
17958
18290
  if (typeof container === "object")
@@ -17978,21 +18310,21 @@ function render(element, containerOrConfig, _callback) {
17978
18310
  // _build/test/test_react_render.js
17979
18311
  var WS_CHILD = 1073741824;
17980
18312
  var WS_VISIBLE = 268435456;
17981
- gui19.RegisterClass("ReactTest", (hwnd2, msg, wParam, lParam) => {
18313
+ gui18.RegisterClass("ReactTest", (hwnd2, msg, wParam, lParam) => {
17982
18314
  if (!hwnd2)
17983
- return gui19.DefWindowProc(hwnd2, msg, wParam, lParam);
18315
+ return gui18.DefWindowProc(hwnd2, msg, wParam, lParam);
17984
18316
  if (msg === 2) {
17985
- gui19.PostQuitMessage(0);
18317
+ gui18.PostQuitMessage(0);
17986
18318
  return 0;
17987
18319
  }
17988
- return gui19.DefWindowProc(hwnd2, msg, wParam, lParam);
18320
+ return gui18.DefWindowProc(hwnd2, msg, wParam, lParam);
17989
18321
  });
17990
18322
  function Greeting() {
17991
18323
  return (0, import_jsx_runtime16.jsx)("w", { type: "BUTTON", text: "Hello", ws: WS_CHILD | WS_VISIBLE, style: { width: 200, height: 30 } });
17992
18324
  }
17993
- var hwnd = gui19.CreateWindow("ReactTest", "React Test", 13565952, 200, 200, 500, 400, null, null);
18325
+ var hwnd = gui18.CreateWindow("ReactTest", "React Test", 13565952, 200, 200, 500, 400, null, null);
17994
18326
  if (hwnd) {
17995
- gui19.ShowWindow(hwnd);
18327
+ gui18.ShowWindow(hwnd);
17996
18328
  render((0, import_jsx_runtime16.jsx)(Greeting, {}), hwnd);
17997
18329
  }
17998
18330
  /*! Bundled license information: