quickwin 1.3.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/README.en.md +1 -2
  2. package/README.md +19 -23
  3. package/examples/PdfCanvas.js +8 -37
  4. package/examples/PdfCanvas.tsx +11 -41
  5. package/examples/exec_server.js +20054 -1423
  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 +1318 -1178
  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 +1313 -1074
  16. package/examples/test_react_lazy.js +1284 -1056
  17. package/examples/test_react_listbox.js +1283 -1055
  18. package/examples/test_root_window.js +1279 -1051
  19. package/examples/test_tab.js +1284 -1056
  20. package/lib/abort.js +70 -0
  21. package/lib/abort.ts +69 -0
  22. package/lib/certs.js +214 -0
  23. package/lib/certs.ts +224 -0
  24. package/lib/exec-log.js +15 -0
  25. package/lib/exec-log.ts +30 -0
  26. package/lib/fetch.js +37 -4
  27. package/lib/fetch.ts +35 -4
  28. package/lib/ffi/bind.js +352 -0
  29. package/lib/ffi/bind.ts +442 -0
  30. package/lib/ffi/ctype.js +168 -0
  31. package/lib/ffi/ctype.ts +331 -0
  32. package/lib/ffi/index.js +6 -0
  33. package/lib/ffi/index.ts +6 -0
  34. package/lib/ffi/struct.js +412 -0
  35. package/lib/ffi/struct.ts +664 -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 +49 -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 +4 -2
  51. package/lib/react-qw/index.ts +4 -2
  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 +18 -23
  59. package/lib/text-measure.ts +20 -25
  60. package/lib/websocket.js +12 -2
  61. package/lib/websocket.ts +15 -2
  62. package/lib/windows/comctl32.js +18 -0
  63. package/lib/windows/comctl32.ts +20 -0
  64. package/lib/windows/comdlg32.js +7 -0
  65. package/lib/windows/comdlg32.ts +9 -0
  66. package/lib/windows/gdi32.js +90 -0
  67. package/lib/windows/gdi32.ts +97 -0
  68. package/lib/windows/kernel32.js +66 -0
  69. package/lib/windows/kernel32.ts +76 -0
  70. package/lib/windows/ntdll.js +8 -0
  71. package/lib/windows/ntdll.ts +10 -0
  72. package/lib/windows/ole32.js +7 -0
  73. package/lib/windows/ole32.ts +9 -0
  74. package/lib/windows/shell32.js +11 -0
  75. package/lib/windows/shell32.ts +14 -0
  76. package/lib/windows/structs.js +384 -0
  77. package/lib/windows/structs.ts +422 -0
  78. package/lib/windows/user32.js +469 -0
  79. package/lib/windows/user32.ts +502 -0
  80. package/package.json +1 -1
  81. package/quickwin.d.ts +22 -37
  82. package/quickwin_const.d.ts +1 -0
  83. package/qwin-nowasm-x86.exe +0 -0
  84. package/qwin-nowasm.exe +0 -0
  85. package/qwin-x86.exe +0 -0
  86. package/qwin.exe +0 -0
  87. package/test/bench_ffi_callraw.js +236 -0
  88. package/test/bench_ffi_callraw.ts +236 -0
  89. package/test/bench_ffi_overhead.js +139 -0
  90. package/test/bench_ffi_overhead.ts +141 -0
  91. package/test/bench_sendmessage.js +104 -0
  92. package/test/bench_sendmessage.ts +100 -0
  93. package/test/bench_sendmessage_nonnull.js +187 -0
  94. package/test/bench_sendmessage_nonnull.ts +188 -0
  95. package/test/run.js +12 -4
  96. package/test/run.ts +13 -5
  97. package/test/test_basic_fetch.js +8 -0
  98. package/test/test_basic_fetch.ts +9 -0
  99. package/test/test_ffi.js +25 -43
  100. package/test/test_ffi.ts +33 -52
  101. package/test/test_ffi_abi.js +235 -0
  102. package/test/test_ffi_abi.ts +218 -0
  103. package/test/test_ffi_bind.js +538 -8
  104. package/test/test_ffi_bind.ts +559 -8
  105. package/test/test_ffi_struct.js +632 -88
  106. package/test/test_ffi_struct.ts +666 -91
  107. package/test/test_ffi_struct_layout.js +495 -0
  108. package/test/test_ffi_struct_layout.ts +543 -0
  109. package/test/test_ffi_user32.js +103 -0
  110. package/test/test_ffi_user32.ts +113 -0
  111. package/test/test_ffi_windows.js +101 -0
  112. package/test/test_ffi_windows.ts +113 -0
  113. package/test/test_helper.js +8 -1
  114. package/test/test_helper.ts +9 -1
  115. package/test/test_http_import.js +18 -0
  116. package/test/test_http_import.ts +19 -0
  117. package/test/test_http_server.js +73 -1
  118. package/test/test_http_server.ts +75 -1
  119. package/test/test_ipv6.js +2 -2
  120. package/test/test_ipv6.ts +2 -2
  121. package/test/test_net_fetch.js +70 -8
  122. package/test/test_net_fetch.ts +69 -7
  123. package/test/test_net_websocket.js +1 -1
  124. package/test/test_net_websocket.ts +1 -1
  125. package/test/test_react_complex.js +1294 -1066
  126. package/test/test_react_counter.js +1284 -1056
  127. package/test/test_react_flex.js +1304 -1069
  128. package/test/test_react_hidden.js +1287 -1059
  129. package/test/test_react_listview_link.js +1284 -1056
  130. package/test/test_react_notify.js +18534 -0
  131. package/test/test_react_render.js +1284 -1056
  132. package/test/test_wolfssl_read.js +3 -2
  133. package/test/test_wolfssl_read.ts +3 -1
  134. package/test/test_worker_net.js +35 -17
  135. package/test/test_worker_net.ts +27 -15
  136. package/tsconfig.json +1 -1
  137. package/examples/exec_server.ts +0 -80
  138. package/lib/ffi-bind.js +0 -85
  139. package/lib/ffi-bind.ts +0 -170
  140. package/lib/ffi-struct.js +0 -224
  141. package/lib/ffi-struct.ts +0 -239
  142. package/lib/win-common-structs.js +0 -39
  143. 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
  }
@@ -15355,146 +15355,167 @@ var require_constants = __commonJS({
15355
15355
 
15356
15356
  // _build/examples/pdf_viewer.js
15357
15357
  var import_jsx_runtime17 = __toESM(require_jsx_runtime(), 1);
15358
- var import_react19 = __toESM(require_react(), 1);
15359
- import "../lib/polyfill.js";
15360
- import * as std from "std";
15361
- import * as gui19 from "gui";
15362
- import * as win5 from "win";
15363
- import * as ffi13 from "ffi";
15364
-
15365
- // _build/lib/react-qw/index.js
15366
- import * as gui18 from "gui";
15367
15358
 
15368
- // _build/lib/react-qw/reconciler.js
15369
- var import_react_reconciler = __toESM(require_react_reconciler(), 1);
15370
- var import_react = __toESM(require_react(), 1);
15371
- var import_constants = __toESM(require_constants(), 1);
15372
- import * as gui3 from "gui";
15359
+ // _build/lib/ffi/ctype.js
15360
+ import { bufferPtr } from "ffi";
15373
15361
  import * as os from "os";
15374
-
15375
- // _build/lib/react-qw/props.js
15376
- import * as gui from "gui";
15377
- function applyProps(instance, newProps, _oldProps) {
15378
- const hwnd = instance.hwnd;
15379
- instance.props = newProps;
15380
- const textVal = "text" in newProps ? newProps.text : typeof newProps.children === "string" ? newProps.children : typeof newProps.children === "number" ? String(newProps.children) : void 0;
15381
- if (textVal !== void 0) {
15382
- let cursor = -1;
15383
- if (instance.type === "EDIT") {
15384
- const sel = gui.SendMessage(hwnd, 176, 0, 0);
15385
- cursor = sel >>> 16;
15386
- }
15387
- gui.SetWindowText(hwnd, textVal);
15388
- if (instance.type === "EDIT" && cursor >= 0) {
15389
- gui.SendMessage(hwnd, 177, cursor, cursor);
15390
- }
15391
- }
15392
- if ("disabled" in newProps) {
15393
- gui.EnableWindow(hwnd, !newProps.disabled);
15394
- }
15395
- if ("hidden" in newProps) {
15396
- gui.ShowWindow(
15397
- hwnd,
15398
- newProps.hidden ? 0 : 5
15399
- /* gui.ShowWindowCmd.SHOW */
15400
- );
15362
+ var C_BASIC_TYPE = [
15363
+ "void",
15364
+ "u8",
15365
+ "i8",
15366
+ "u16",
15367
+ "i16",
15368
+ "u32",
15369
+ "i32",
15370
+ "u64",
15371
+ "i64",
15372
+ "f32",
15373
+ "f64",
15374
+ "ptr"
15375
+ ];
15376
+ var PTR_TOKEN_RE = /^<([^<>\s]*)>ptr(!|@[A-Za-z_]\w*)?$/;
15377
+ function isCPtrToken(t) {
15378
+ return PTR_TOKEN_RE.test(t);
15379
+ }
15380
+ function ptrName(t) {
15381
+ const m = PTR_TOKEN_RE.exec(t);
15382
+ return m?.[1] || "";
15383
+ }
15384
+ var cTokenToType = (t) => {
15385
+ if (isCPtrToken(t))
15386
+ return "ptr";
15387
+ else
15388
+ return t;
15389
+ };
15390
+ var PTR_SIZE = os.arch === "x64" ? 8 : 4;
15391
+ var SizeAlign = {
15392
+ u8: 1,
15393
+ i8: 1,
15394
+ u16: 2,
15395
+ i16: 2,
15396
+ u32: 4,
15397
+ i32: 4,
15398
+ u64: 8,
15399
+ i64: 8,
15400
+ f32: 4,
15401
+ f64: 8
15402
+ };
15403
+ var NULL = 0;
15404
+ function normToken(t) {
15405
+ if (isCPtrToken(t)) {
15406
+ const m = PTR_TOKEN_RE.exec(t);
15407
+ return m?.[2]?.startsWith("@") ? `<${m[1]}>ptr` : t;
15401
15408
  }
15402
- if ("visible" in newProps) {
15403
- gui.ShowWindow(
15404
- hwnd,
15405
- newProps.visible ? 5 : 0
15406
- /* gui.ShowWindowCmd.HIDE */
15407
- );
15409
+ const at = t.indexOf("@");
15410
+ const base = at >= 0 ? t.slice(0, at) : t;
15411
+ const suffixOk = at < 0 || /^[A-Za-z_]\w*$/.test(t.slice(at + 1));
15412
+ if (suffixOk && base !== "ptr" && C_BASIC_TYPE.includes(base))
15413
+ return base;
15414
+ throw new Error("Unknown token: " + t);
15415
+ }
15416
+ function readScalar(dv, off, k) {
15417
+ switch (k) {
15418
+ case "u8":
15419
+ return dv.getUint8(off);
15420
+ case "i8":
15421
+ return dv.getInt8(off);
15422
+ case "u16":
15423
+ return dv.getUint16(off, true);
15424
+ case "i16":
15425
+ return dv.getInt16(off, true);
15426
+ case "u32":
15427
+ return dv.getUint32(off, true);
15428
+ case "i32":
15429
+ return dv.getInt32(off, true);
15430
+ case "u64":
15431
+ return dv.getBigUint64(off, true);
15432
+ case "i64":
15433
+ return dv.getBigInt64(off, true);
15434
+ case "f32":
15435
+ return dv.getFloat32(off, true);
15436
+ case "f64":
15437
+ return dv.getFloat64(off, true);
15438
+ case "ptr": {
15439
+ return PTR_SIZE === 8 ? Number(dv.getBigInt64(off, true)) : dv.getInt32(off, true);
15440
+ }
15408
15441
  }
15409
15442
  }
15410
-
15411
- // _build/lib/react-qw/layout.js
15412
- var DEFAULT_W = 100;
15413
- var DEFAULT_H = 30;
15414
- function calculateFlexLayout(flex, parentW, parentH, children) {
15415
- const dir = flex.flexDirection || "column";
15416
- const gap = flex.gap ?? 0;
15417
- const justify = flex.justifyContent || "flex-start";
15418
- const align = flex.alignItems || "stretch";
15419
- const isRow = dir === "row";
15420
- const n = children.length;
15421
- const mainSize = isRow ? "w" : "h";
15422
- const crossSize = isRow ? "h" : "w";
15423
- const mainPos = isRow ? "x" : "y";
15424
- const crossPos = isRow ? "y" : "x";
15425
- const mainDim = isRow ? "width" : "height";
15426
- const crossDim = isRow ? "height" : "width";
15427
- const pt = flex.paddingTop ?? flex.padding ?? 0;
15428
- const pr = flex.paddingRight ?? flex.padding ?? 0;
15429
- const pb = flex.paddingBottom ?? flex.padding ?? 0;
15430
- const pl = flex.paddingLeft ?? flex.padding ?? 0;
15431
- const mainPadding = isRow ? pl + pr : pt + pb;
15432
- const crossPadding = isRow ? pt + pb : pl + pr;
15433
- const parentMain = (isRow ? parentW : parentH) - mainPadding;
15434
- const parentCross = (isRow ? parentH : parentW) - crossPadding;
15435
- const sizes = children.map((c) => ({
15436
- w: typeof c.style.width === "number" ? c.style.width : DEFAULT_W,
15437
- h: typeof c.style.height === "number" ? c.style.height : DEFAULT_H
15438
- }));
15439
- const flexGrows = children.map((c) => c.style.flexGrow ?? 0);
15440
- const totalGrow = flexGrows.reduce((s, g) => s + g, 0);
15441
- const baseMain = sizes.reduce((s, c) => s + c[mainSize], 0);
15442
- let freeGrow = parentMain - baseMain - Math.max(0, n - 1) * gap;
15443
- if (totalGrow > 0 && freeGrow > 0) {
15444
- for (let i = 0; i < n; i++) {
15445
- sizes[i][mainSize] += freeGrow * flexGrows[i] / totalGrow;
15443
+ function writeScalar(dv, off, { k, v }) {
15444
+ switch (k) {
15445
+ case "u8":
15446
+ dv.setUint8(off, Number(v));
15447
+ break;
15448
+ case "i8":
15449
+ dv.setInt8(off, Number(v));
15450
+ break;
15451
+ case "u16":
15452
+ dv.setUint16(off, Number(v), true);
15453
+ break;
15454
+ case "i16":
15455
+ dv.setInt16(off, Number(v), true);
15456
+ break;
15457
+ case "u32":
15458
+ dv.setUint32(off, v >>> 0, true);
15459
+ break;
15460
+ case "i32":
15461
+ dv.setUint32(off, v >>> 0, true);
15462
+ break;
15463
+ case "u64":
15464
+ dv.setBigUint64(off, v, true);
15465
+ break;
15466
+ case "i64":
15467
+ dv.setBigInt64(off, v, true);
15468
+ break;
15469
+ case "f32":
15470
+ dv.setFloat32(off, v, true);
15471
+ break;
15472
+ case "f64":
15473
+ dv.setFloat64(off, v, true);
15474
+ break;
15475
+ case "ptr": {
15476
+ if (v == null) {
15477
+ throw new Error("ffi: got null/undefined for a ptr slot; pass the imported NULL constant for empty");
15478
+ }
15479
+ if (PTR_SIZE === 8)
15480
+ dv.setBigUint64(off, BigInt.asUintN(64, BigInt(v)), true);
15481
+ else
15482
+ dv.setUint32(off, v >>> 0, true);
15483
+ break;
15446
15484
  }
15447
15485
  }
15448
- const totalMain = sizes.reduce((s, c) => s + c[mainSize], 0);
15449
- const free = parentMain - totalMain - Math.max(0, n - 1) * gap;
15450
- let offset = 0, extraGap = 0;
15451
- if (justify === "flex-end")
15452
- offset = free;
15453
- else if (justify === "center")
15454
- offset = Math.max(0, free / 2);
15455
- else if (justify === "space-between" && n > 1)
15456
- extraGap = free / (n - 1);
15457
- else if (justify === "space-around") {
15458
- extraGap = free / n;
15459
- offset = extraGap / 2;
15460
- } else if (justify === "space-evenly") {
15461
- extraGap = free / (n + 1);
15462
- offset = extraGap;
15486
+ }
15487
+ function writeSlot(dv, off, e) {
15488
+ const { k, v } = e;
15489
+ if (k === "u8" || k === "i8" || k === "u16" || k === "i16") {
15490
+ dv.setUint32(off, Number(v) >>> 0, true);
15491
+ return;
15463
15492
  }
15464
- let cursor = offset;
15465
- return sizes.map((sz, i) => {
15466
- const childCrossBase = sz[crossSize];
15467
- const childAlign = children[i].style.alignSelf ?? "auto";
15468
- const effectiveAlign = childAlign === "auto" ? align : childAlign;
15469
- let childMain = sz[mainSize];
15470
- let childCross = childCrossBase;
15471
- const res = { x: 0, y: 0, width: 0, height: 0 };
15472
- res[mainPos] = cursor;
15473
- res[crossPos] = 0;
15474
- res[mainDim] = childMain;
15475
- res[crossDim] = childCross;
15476
- if (effectiveAlign === "stretch") {
15477
- const hasExplicitCross = typeof children[i].style[crossDim] === "number";
15478
- if (!hasExplicitCross) {
15479
- res[crossDim] = parentCross;
15480
- res[crossPos] = 0;
15481
- }
15482
- } else if (effectiveAlign === "flex-end") {
15483
- res[crossPos] = parentCross - childCross;
15484
- } else if (effectiveAlign === "center") {
15485
- res[crossPos] = Math.max(0, (parentCross - childCross) / 2);
15486
- }
15487
- cursor += childMain + gap + extraGap;
15488
- return res;
15489
- });
15493
+ writeScalar(dv, off, e);
15490
15494
  }
15495
+ var PtrArrayBuffer = class extends ArrayBuffer {
15496
+ ptr;
15497
+ constructor(byteLength) {
15498
+ super(byteLength);
15499
+ this.ptr = bufferPtr(this);
15500
+ }
15501
+ };
15491
15502
 
15492
- // _build/lib/text-measure.js
15493
- import * as ffi2 from "ffi";
15494
- import * as gui2 from "gui";
15503
+ // _build/examples/pdf_viewer.js
15504
+ var import_react19 = __toESM(require_react(), 1);
15505
+ import "../lib/polyfill.js";
15506
+ import * as std2 from "std";
15507
+ import * as gui18 from "gui";
15508
+
15509
+ // _build/lib/react-qw/index.js
15510
+ import * as gui17 from "gui";
15511
+
15512
+ // _build/lib/windows/user32.js
15513
+ import * as os3 from "os";
15495
15514
 
15496
- // _build/lib/ffi-bind.js
15515
+ // _build/lib/ffi/bind.js
15497
15516
  import * as ffi from "ffi";
15517
+ import * as os2 from "os";
15518
+ import * as std from "std";
15498
15519
  import * as win from "win";
15499
15520
 
15500
15521
  // _build/lib/text-codec.js
@@ -15517,62 +15538,62 @@ function _normalizeLabel(label) {
15517
15538
  function _decodeUTF8(buf, fatal) {
15518
15539
  let out = "";
15519
15540
  for (let i = 0; i < buf.length; ) {
15520
- const b = buf[i++];
15521
- if (b < 128) {
15522
- out += String.fromCharCode(b);
15541
+ const b6 = buf[i++];
15542
+ if (b6 < 128) {
15543
+ out += String.fromCharCode(b6);
15523
15544
  continue;
15524
15545
  }
15525
- if (b < 192) {
15546
+ if (b6 < 192) {
15526
15547
  out += fatal ? (() => {
15527
15548
  throw new TypeError("unexpected continuation byte");
15528
15549
  })() : "\uFFFD";
15529
15550
  continue;
15530
15551
  }
15531
15552
  let c, min;
15532
- if (b < 224) {
15553
+ if (b6 < 224) {
15533
15554
  if (i >= buf.length) {
15534
15555
  out += fatal ? (() => {
15535
15556
  throw new TypeError("incomplete utf-8");
15536
15557
  })() : "\uFFFD";
15537
15558
  break;
15538
15559
  }
15539
- const b2 = buf[i++];
15540
- if ((b2 & 192) !== 128) {
15560
+ const b22 = buf[i++];
15561
+ if ((b22 & 192) !== 128) {
15541
15562
  out += "\uFFFD";
15542
15563
  continue;
15543
15564
  }
15544
- c = (b & 31) << 6 | b2 & 63;
15565
+ c = (b6 & 31) << 6 | b22 & 63;
15545
15566
  min = 128;
15546
- } else if (b < 240) {
15567
+ } else if (b6 < 240) {
15547
15568
  if (i + 1 >= buf.length) {
15548
15569
  out += fatal ? (() => {
15549
15570
  throw new TypeError("incomplete utf-8");
15550
15571
  })() : "\uFFFD";
15551
15572
  break;
15552
15573
  }
15553
- const b2 = buf[i++];
15554
- const b3 = buf[i++];
15555
- if ((b2 & 192) !== 128 || (b3 & 192) !== 128) {
15574
+ const b22 = buf[i++];
15575
+ const b32 = buf[i++];
15576
+ if ((b22 & 192) !== 128 || (b32 & 192) !== 128) {
15556
15577
  out += "\uFFFD";
15557
15578
  continue;
15558
15579
  }
15559
- c = (b & 15) << 12 | (b2 & 63) << 6 | b3 & 63;
15580
+ c = (b6 & 15) << 12 | (b22 & 63) << 6 | b32 & 63;
15560
15581
  min = 2048;
15561
- } else if (b < 248) {
15582
+ } else if (b6 < 248) {
15562
15583
  if (i + 2 >= buf.length) {
15563
15584
  out += fatal ? (() => {
15564
15585
  throw new TypeError("incomplete utf-8");
15565
15586
  })() : "\uFFFD";
15566
15587
  break;
15567
15588
  }
15568
- const b2 = buf[i++];
15569
- const b3 = buf[i++];
15570
- const b4 = buf[i++];
15571
- if ((b2 & 192) !== 128 || (b3 & 192) !== 128 || (b4 & 192) !== 128) {
15589
+ const b22 = buf[i++];
15590
+ const b32 = buf[i++];
15591
+ const b42 = buf[i++];
15592
+ if ((b22 & 192) !== 128 || (b32 & 192) !== 128 || (b42 & 192) !== 128) {
15572
15593
  out += "\uFFFD";
15573
15594
  continue;
15574
15595
  }
15575
- c = (b & 7) << 18 | (b2 & 63) << 12 | (b3 & 63) << 6 | b4 & 63;
15596
+ c = (b6 & 7) << 18 | (b22 & 63) << 12 | (b32 & 63) << 6 | b42 & 63;
15576
15597
  min = 65536;
15577
15598
  } else {
15578
15599
  out += fatal ? (() => {
@@ -15710,66 +15731,7 @@ if (typeof globalThis.TextEncoder === "undefined") {
15710
15731
  globalThis.TextEncoder = TextEncoderImpl;
15711
15732
  }
15712
15733
 
15713
- // _build/lib/ffi-bind.js
15714
- var KIND_TO_FFI = {
15715
- void: ffi.FFI_TYPE_VOID,
15716
- u8: ffi.FFI_TYPE_UINT8,
15717
- i8: ffi.FFI_TYPE_SINT8,
15718
- u16: ffi.FFI_TYPE_UINT16,
15719
- i16: ffi.FFI_TYPE_SINT16,
15720
- u32: ffi.FFI_TYPE_UINT32,
15721
- i32: ffi.FFI_TYPE_SINT32,
15722
- u64: ffi.FFI_TYPE_UINT64,
15723
- i64: ffi.FFI_TYPE_SINT64,
15724
- f32: ffi.FFI_TYPE_FLOAT,
15725
- f64: ffi.FFI_TYPE_DOUBLE,
15726
- ptr: ffi.FFI_TYPE_POINTER,
15727
- wstr: ffi.FFI_TYPE_POINTER
15728
- };
15729
- var C_ALIAS = {
15730
- int: "i32",
15731
- long: "i32",
15732
- short: "i16",
15733
- char: "i8",
15734
- float: "f32",
15735
- double: "f64",
15736
- DWORD: "u32",
15737
- UINT: "u32",
15738
- ULONG: "u32",
15739
- LONG: "i32",
15740
- BOOL: "i32",
15741
- HRESULT: "i32",
15742
- SHORT: "i16",
15743
- USHORT: "u16",
15744
- BYTE: "u8",
15745
- LONG_PTR: "ptr",
15746
- ULONG_PTR: "ptr",
15747
- INT_PTR: "ptr",
15748
- UINT_PTR: "ptr",
15749
- DWORD_PTR: "ptr",
15750
- SIZE_T: "ptr",
15751
- WPARAM: "ptr",
15752
- LPARAM: "ptr",
15753
- HANDLE: "ptr",
15754
- HWND: "ptr",
15755
- HDC: "ptr",
15756
- HMODULE: "ptr",
15757
- HFONT: "ptr",
15758
- HBRUSH: "ptr",
15759
- HICON: "ptr",
15760
- HBITMAP: "ptr",
15761
- LPVOID: "ptr",
15762
- LPCVOID: "ptr",
15763
- LPCWSTR: "ptr",
15764
- PCWSTR: "ptr",
15765
- LPWSTR: "ptr"
15766
- };
15767
- function normKind(t) {
15768
- const k = C_ALIAS[t] ?? t;
15769
- if (!(k in KIND_TO_FFI))
15770
- throw new Error(`ffi-bind: invalid kind "${t}"`);
15771
- return k;
15772
- }
15734
+ // _build/lib/ffi/bind.js
15773
15735
  var _dllCache = /* @__PURE__ */ new Map();
15774
15736
  function loadDll(dll) {
15775
15737
  const cached = _dllCache.get(dll);
@@ -15783,77 +15745,937 @@ function loadDll(dll) {
15783
15745
  }
15784
15746
  function parseSig(sig) {
15785
15747
  const parts = sig.split(" -> ");
15786
- const ret = parts[1];
15787
- if (ret === void 0 || parts.length > 2) {
15748
+ if (parts.length !== 2) {
15788
15749
  throw new Error(`ffi-bind: invalid signature "${sig}" (expected "arg1 arg2 -> ret")`);
15789
15750
  }
15790
- const retK = normKind(ret);
15791
- if (retK === "wstr")
15792
- throw new Error('ffi-bind: "wstr" cannot be a return type');
15793
- const tokens = (parts[0] ?? "") === "" ? [] : parts[0].split(" ");
15794
- const args = tokens.map((t) => normKind(t));
15795
- return { args, ret: retK };
15751
+ const rawArgs = parts[0].split(" ").filter((t) => t !== "");
15752
+ const argTokens = [];
15753
+ for (const raw of rawArgs) {
15754
+ const tok = normToken(raw);
15755
+ if (tok === "void") {
15756
+ throw new Error("Void can not in args");
15757
+ }
15758
+ argTokens.push(tok);
15759
+ }
15760
+ return {
15761
+ argTokens,
15762
+ retToken: normToken(parts[1]),
15763
+ sig
15764
+ };
15765
+ }
15766
+ function makeFn(proc, sig, encoders, decoders) {
15767
+ const ps = parseSig(sig);
15768
+ return (...a) => callPacked(proc, ps, a, encoders, decoders);
15769
+ }
15770
+ var IA32_ARG_SIZE = {
15771
+ u8: 4,
15772
+ i8: 4,
15773
+ u16: 4,
15774
+ i16: 4,
15775
+ u32: 4,
15776
+ i32: 4,
15777
+ u64: 8,
15778
+ i64: 8,
15779
+ f32: 4,
15780
+ f64: 8,
15781
+ ptr: PTR_SIZE
15782
+ };
15783
+ var X64_MIN_SLOTS = 4;
15784
+ function callPacked(proc, { argTokens, retToken, sig }, args, encoders, decoders) {
15785
+ const is64 = os2.arch === "x64";
15786
+ const getWidth = (t, is642) => {
15787
+ if (is642)
15788
+ return 8;
15789
+ if (isCPtrToken(t))
15790
+ return PTR_SIZE;
15791
+ return IA32_ARG_SIZE[t];
15792
+ };
15793
+ let total = 0;
15794
+ for (const t of argTokens)
15795
+ total += getWidth(t, is64);
15796
+ if (is64 && argTokens.length < X64_MIN_SLOTS)
15797
+ total = X64_MIN_SLOTS * 8;
15798
+ const argFrame = new ArrayBuffer(total);
15799
+ const dv = new DataView(argFrame);
15800
+ const held = [];
15801
+ let off = 0;
15802
+ for (let i = 0; i < argTokens.length; i++) {
15803
+ const argToken = argTokens[i];
15804
+ const nonnull = argToken.endsWith("!");
15805
+ const arg = args[i];
15806
+ if (isCPtrToken(argToken)) {
15807
+ const name = ptrName(argToken);
15808
+ if (typeof arg === "number") {
15809
+ if (nonnull && arg === 0)
15810
+ throw new Error(`ffi-bind: ${sig}: arg#${i + 1} <${name}>ptr! got 0 (null pointer forbidden here; the token marks this position non-null)`);
15811
+ writeSlot(dv, off, { k: "ptr", v: arg });
15812
+ } else {
15813
+ if (arg === null || arg === void 0) {
15814
+ throw new Error(`ffi-bind: <${name}>ptr got ${String(arg)}; pass the imported NULL constant for an empty pointer`);
15815
+ }
15816
+ const codec = encoders[name];
15817
+ if (!codec) {
15818
+ 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"})`);
15819
+ }
15820
+ if (!codec.encode) {
15821
+ throw new Error(`ffi-bind: <${name}>ptr has no encoder (out-only codec)`);
15822
+ }
15823
+ const buf = codec.encode(arg);
15824
+ held.push(buf);
15825
+ const p = buf.ptr;
15826
+ if (typeof p !== "number")
15827
+ throw new Error("ffi-bind: codec.encode must return a PtrArrayBuffer, got plain ArrayBuffer");
15828
+ if (nonnull && p === 0)
15829
+ throw new Error(`ffi-bind: ${sig}: arg#${i + 1} <${name}>ptr! encode produced 0 (null pointer forbidden here)`);
15830
+ writeSlot(dv, off, { k: "ptr", v: p });
15831
+ }
15832
+ } else {
15833
+ writeSlot(dv, off, { k: argToken, v: arg });
15834
+ }
15835
+ off += getWidth(argToken, is64);
15836
+ }
15837
+ const retBuf = new ArrayBuffer(8);
15838
+ const retIsFp = retToken === "f32" || retToken === "f64";
15839
+ ffi.ffiCall(proc, argFrame, retBuf, retIsFp ? 1 : 0);
15840
+ const raw = readRet(cTokenToType(retToken), retBuf);
15841
+ if (retToken.endsWith("!") && raw === 0)
15842
+ throw new Error(`ffi-bind: ${sig}: return ${retToken} got 0 (the token promises C never returns null here)`);
15843
+ if (isCPtrToken(retToken) && raw !== 0) {
15844
+ const name = ptrName(retToken);
15845
+ if (name !== "") {
15846
+ const codec = decoders[name];
15847
+ if (codec?.decode)
15848
+ return codec.decode(raw);
15849
+ }
15850
+ }
15851
+ return raw;
15852
+ }
15853
+ function readRet(ret, retBuf) {
15854
+ if (ret === "void")
15855
+ return void 0;
15856
+ return readScalar(new DataView(retBuf), 0, ret);
15857
+ }
15858
+ var WCHAR = {
15859
+ encode: (v) => {
15860
+ const u8 = new TextEncoder("utf-16le").encode(v + "\0");
15861
+ const out = new PtrArrayBuffer(u8.byteLength);
15862
+ new Uint8Array(out).set(u8);
15863
+ return out;
15864
+ },
15865
+ decode: (p) => {
15866
+ if (typeof p === "number") {
15867
+ let s2 = "";
15868
+ let addr = p;
15869
+ const start = addr;
15870
+ for (; ; ) {
15871
+ const lo = ffi.readByte(addr);
15872
+ const hi = ffi.readByte(addr + 1);
15873
+ if (lo === 0 && hi === 0)
15874
+ return s2;
15875
+ s2 += String.fromCharCode(lo | hi << 8);
15876
+ addr += 2;
15877
+ if (addr - start > 1 << 21) {
15878
+ throw new Error("ffi-bind: WCHAR decode exceeded 4MiB without NUL");
15879
+ }
15880
+ }
15881
+ }
15882
+ const u8 = new Uint8Array(p);
15883
+ const limit = u8.length & ~1;
15884
+ let s = "";
15885
+ for (let i = 0; i < limit; i += 2) {
15886
+ const c = u8[i] | u8[i + 1] << 8;
15887
+ if (c === 0)
15888
+ return s;
15889
+ s += String.fromCharCode(c);
15890
+ }
15891
+ return s;
15892
+ },
15893
+ alloc: (size = 256) => new PtrArrayBuffer(size * 2)
15894
+ };
15895
+ var BYTE = {
15896
+ encode: (v) => {
15897
+ if (!(v instanceof PtrArrayBuffer))
15898
+ throw new Error("ffi-bind: <BYTE>ptr wants a PtrArrayBuffer (new PtrArrayBuffer(n) / BYTE.alloc / struct.encode), not a plain ArrayBuffer");
15899
+ return v;
15900
+ },
15901
+ alloc: (byteLen) => new PtrArrayBuffer(byteLen)
15902
+ };
15903
+ var builtinCodecs = { WCHAR, BYTE };
15904
+ function bind(dll, name, sig, encoders, decoders) {
15905
+ const proc = win.GetProcAddress(loadDll(dll), name);
15906
+ if (!proc)
15907
+ throw new Error(`ffi-bind: proc "${name}" not found in ${dll}`);
15908
+ const effDec = decoders ?? encoders;
15909
+ return makeFn(proc, sig, { ...builtinCodecs, ...encoders }, { ...builtinCodecs, ...effDec ?? {} });
15910
+ }
15911
+ var leakRegistry = new FinalizationRegistry((held) => {
15912
+ std.printf('[ffi] closure leaked (GCed without dispose): sig="%s" ptr=0x%x\n', held.sig, held.ptr);
15913
+ });
15914
+
15915
+ // _build/lib/ffi/struct.js
15916
+ import * as ffi2 from "ffi";
15917
+ function alignUp(v, a) {
15918
+ return v + a - 1 & ~(a - 1);
15919
+ }
15920
+ var isCNumberToken = (t) => SizeAlign[t] !== void 0;
15921
+ function lower(v) {
15922
+ if (typeof v === "string") {
15923
+ const st = /^(u8|u16)\[(\d+)\]@(utf-8|utf-16le)$/.exec(v);
15924
+ if (st) {
15925
+ const length = Number(st[2]);
15926
+ if (!Number.isInteger(length) || length < 1)
15927
+ throw new Error(`ffi-struct: string length must be an integer >= 1, got ${length}`);
15928
+ const s2 = st[1] === "u8" ? 1 : 2;
15929
+ return { size: s2 * length, align: s2, type: { tag: "string", encoding: st[3] } };
15930
+ }
15931
+ const a = /^([^\[\]]+)\[(\d+)\]$/.exec(v);
15932
+ if (a) {
15933
+ const length = Number(a[2]);
15934
+ if (!Number.isInteger(length) || length < 1)
15935
+ throw new Error(`ffi-struct: array length must be an integer >= 1, got ${length}`);
15936
+ const el = lower(a[1]);
15937
+ if (el.type.tag === "bitfield")
15938
+ throw new Error("ffi-struct: bitfields cannot be array elements");
15939
+ return {
15940
+ size: el.size * length,
15941
+ align: el.align,
15942
+ type: { tag: "array", elementType: el.type, elementSize: el.size }
15943
+ };
15944
+ }
15945
+ const b6 = /^([A-Za-z_]\w*):(\d+)$/.exec(v);
15946
+ if (b6) {
15947
+ const rawUnit = b6[1];
15948
+ const unit = normToken(rawUnit);
15949
+ if (!isCNumberToken(unit) || unit === "f32" || unit === "f64")
15950
+ throw new Error(`ffi-struct: bitfield unit must be an integer type, got "${rawUnit}"`);
15951
+ const width = Number(b6[2]);
15952
+ const s2 = SizeAlign[unit];
15953
+ const cap = s2 * 8;
15954
+ if (!Number.isInteger(width) || width < 1)
15955
+ throw new Error(`ffi-struct: bitfield width must be an integer >= 1, got ${width}`);
15956
+ if (width > cap)
15957
+ throw new Error(`ffi-struct: bitfield width ${width} exceeds unit width ${cap}`);
15958
+ return { size: s2, align: s2, type: { tag: "bitfield", unit, bit: 0, width } };
15959
+ }
15960
+ const k = normToken(v);
15961
+ if (isCPtrToken(k))
15962
+ return { size: PTR_SIZE, align: PTR_SIZE, type: { tag: "basic", kind: "ptr" } };
15963
+ if (!isCNumberToken(k))
15964
+ throw new Error(`ffi-struct: unknown kind "${v}"`);
15965
+ const s = SizeAlign[k];
15966
+ return { size: s, align: s, type: { tag: "basic", kind: k } };
15967
+ }
15968
+ if (v && typeof v === "object") {
15969
+ const o = v;
15970
+ const tag = o["#"];
15971
+ if (tag === void 0)
15972
+ throw new Error(`ffi-struct: nested object value requires a '#' key ('struct' | 'union' | 'array')`);
15973
+ if (tag === "array" && "#pack" in o)
15974
+ throw new Error(`ffi-struct: '#pack' is only allowed on struct/union, got '${tag}'`);
15975
+ if (tag === "array") {
15976
+ const length = o["length"];
15977
+ if (!Number.isInteger(length) || length < 1)
15978
+ throw new Error(`ffi-struct: array length must be an integer >= 1, got ${String(length)}`);
15979
+ const el = lower(o["element"]);
15980
+ if (el.type.tag === "bitfield")
15981
+ throw new Error("ffi-struct: bitfields cannot be array elements");
15982
+ return {
15983
+ size: el.size * length,
15984
+ align: el.align,
15985
+ type: { tag: "array", elementType: el.type, elementSize: el.size }
15986
+ };
15987
+ }
15988
+ if (tag === "struct" || tag === "union") {
15989
+ const l = computeStructLayout(v);
15990
+ return { size: l.size, align: l.maxEffectiveAlign, type: { tag, fields: l.fields } };
15991
+ }
15992
+ throw new Error(`ffi-struct: unknown '#' declaration ${JSON.stringify(String(tag))}`);
15993
+ }
15994
+ throw new Error(`ffi-struct: invalid member value: ${String(v)}`);
15796
15995
  }
15797
- function makeFn(proc, sig) {
15798
- const { args, ret } = parseSig(sig);
15799
- const argTypes = args.map((k) => KIND_TO_FFI[k]);
15800
- const retType = KIND_TO_FFI[ret];
15801
- return (...a) => {
15802
- const vals = args.map((k, i) => k === "wstr" ? new TextEncoder("utf-16le").encode(String(a[i]) + "\0").buffer : a[i]);
15803
- return ffi.ffiCall(proc, argTypes, vals, retType);
15996
+ function computeStructLayout(t) {
15997
+ const isStruct = t["#"] === "struct";
15998
+ const pack = t["#pack"] ?? 8;
15999
+ let maxEffectiveAlign = 1;
16000
+ let maxMemberSize = 0;
16001
+ const fields = [];
16002
+ let cursor = 0;
16003
+ let unitBase = -1;
16004
+ let unitBits = 0;
16005
+ let unitSize = 0;
16006
+ const flushUnit = () => {
16007
+ if (unitBase < 0)
16008
+ return;
16009
+ cursor = alignUp(unitBase + Math.ceil(unitBits / 8), unitSize);
16010
+ unitBase = -1;
16011
+ };
16012
+ for (const [rawName, v] of Object.entries(t)) {
16013
+ if (rawName.startsWith("#"))
16014
+ continue;
16015
+ const m = /^([^@]+)@(\d+)$/.exec(rawName);
16016
+ const name = m ? m[1] : rawName;
16017
+ const alignas = m ? Number(m[2]) : 0;
16018
+ const { size, align: natural, type } = lower(v);
16019
+ const nonnull = typeof v === "string" && v.endsWith("!");
16020
+ let align = natural;
16021
+ if (pack > 0)
16022
+ align = Math.min(pack, align);
16023
+ if (alignas)
16024
+ align = Math.max(align, alignas);
16025
+ if (type.tag === "bitfield") {
16026
+ if (name.startsWith("$"))
16027
+ throw new Error("ffi-struct: bitfield members must be named");
16028
+ if (!isStruct) {
16029
+ fields.push({ name, offset: 0, size, type: { ...type, bit: 0 } });
16030
+ maxEffectiveAlign = Math.max(maxEffectiveAlign, align);
16031
+ maxMemberSize = Math.max(maxMemberSize, size);
16032
+ continue;
16033
+ }
16034
+ const width = type.width;
16035
+ if (unitBase < 0 || size !== unitSize || unitBits + width > unitSize * 8) {
16036
+ if (unitBase >= 0)
16037
+ flushUnit();
16038
+ const offset2 = alignUp(cursor, align);
16039
+ unitBase = offset2;
16040
+ unitBits = 0;
16041
+ unitSize = size;
16042
+ }
16043
+ fields.push({
16044
+ name,
16045
+ offset: unitBase,
16046
+ // 单元基址(不是位域自己的地址)
16047
+ size,
16048
+ type: { ...type, bit: unitBits }
16049
+ });
16050
+ unitBits += width;
16051
+ maxEffectiveAlign = Math.max(maxEffectiveAlign, align);
16052
+ maxMemberSize = Math.max(maxMemberSize, size);
16053
+ continue;
16054
+ }
16055
+ flushUnit();
16056
+ const offset = alignUp(cursor, align);
16057
+ if (!name.startsWith("$")) {
16058
+ fields.push({ name, offset, size, type, ...nonnull ? { nonnull: true } : {} });
16059
+ } else {
16060
+ if (type.tag !== "struct" && type.tag !== "union")
16061
+ throw new Error(`ffi-struct: anonymous member "${name}" must be a struct/union`);
16062
+ for (const cf of type.fields)
16063
+ fields.push({ ...cf, offset: cf.offset + offset });
16064
+ }
16065
+ if (isStruct)
16066
+ cursor = offset + size;
16067
+ maxEffectiveAlign = Math.max(maxEffectiveAlign, align);
16068
+ maxMemberSize = Math.max(maxMemberSize, size);
16069
+ }
16070
+ flushUnit();
16071
+ return {
16072
+ size: isStruct ? alignUp(cursor, maxEffectiveAlign) : alignUp(maxMemberSize, maxEffectiveAlign),
16073
+ maxEffectiveAlign,
16074
+ fields
15804
16075
  };
15805
16076
  }
15806
- function bindLib(dll, map) {
16077
+ function readUnitRaw(dv, off, unit) {
16078
+ const s = SizeAlign[unit];
16079
+ if (s === 1)
16080
+ return BigInt(dv.getUint8(off));
16081
+ if (s === 2)
16082
+ return BigInt(dv.getUint16(off, true));
16083
+ if (s === 4)
16084
+ return BigInt(dv.getUint32(off, true));
16085
+ return dv.getBigUint64(off, true);
16086
+ }
16087
+ function writeUnitRaw(dv, off, unit, v) {
16088
+ const s = SizeAlign[unit];
16089
+ if (s === 1) {
16090
+ dv.setUint8(off, Number(v & 0xffn));
16091
+ return;
16092
+ }
16093
+ if (s === 2) {
16094
+ dv.setUint16(off, Number(v & 0xffffn), true);
16095
+ return;
16096
+ }
16097
+ if (s === 4) {
16098
+ dv.setUint32(off, Number(v & 0xffffffffn), true);
16099
+ return;
16100
+ }
16101
+ dv.setBigUint64(off, v & 0xffffffffffffffffn, true);
16102
+ }
16103
+ function readBitfield(dv, off, t) {
16104
+ const w = BigInt(t.width);
16105
+ let v = readUnitRaw(dv, off, t.unit) >> BigInt(t.bit) & (1n << w) - 1n;
16106
+ if (t.unit[0] === "i" && v & 1n << w - 1n)
16107
+ v -= 1n << w;
16108
+ if (t.width > 53)
16109
+ return v;
16110
+ return Number(v);
16111
+ }
16112
+ function writeBitfield(dv, off, t, val) {
16113
+ const w = BigInt(t.width);
16114
+ const bit = BigInt(t.bit);
16115
+ const widthMask = (1n << w) - 1n;
16116
+ const posMask = widthMask << bit;
16117
+ const raw = readUnitRaw(dv, off, t.unit);
16118
+ const bits = (typeof val === "bigint" ? val : BigInt(Math.trunc(val))) & widthMask;
16119
+ writeUnitRaw(dv, off, t.unit, raw & ~posMask | bits << bit);
16120
+ }
16121
+ var stringEncoders = {
16122
+ "utf-8": new TextEncoder("utf-8"),
16123
+ "utf-16le": new TextEncoder("utf-16le")
16124
+ };
16125
+ var stringDecoders = {
16126
+ "utf-8": new TextDecoder("utf-8", { ignoreBOM: true }),
16127
+ "utf-16le": new TextDecoder("utf-16le", { ignoreBOM: true })
16128
+ };
16129
+ function readString(dv, off, size, enc) {
16130
+ const bytes = new Uint8Array(dv.buffer, dv.byteOffset + off, size);
16131
+ const unit = enc === "utf-16le" ? 2 : 1;
16132
+ let end = size;
16133
+ for (let i = 0; i + unit <= size; i += unit) {
16134
+ if (bytes[i] === 0 && (unit === 1 || bytes[i + 1] === 0)) {
16135
+ end = i;
16136
+ break;
16137
+ }
16138
+ }
16139
+ return stringDecoders[enc].decode(bytes.subarray(0, end));
16140
+ }
16141
+ function writeString(dv, off, size, enc, v) {
16142
+ const bytes = new Uint8Array(dv.buffer, dv.byteOffset + off, size);
16143
+ bytes.fill(0);
16144
+ const unit = enc === "utf-16le" ? 2 : 1;
16145
+ const cap = size - unit;
16146
+ if (cap <= 0)
16147
+ return;
16148
+ const src = stringEncoders[enc].encode(String(v ?? ""));
16149
+ bytes.set(src.subarray(0, Math.min(src.length, cap)));
16150
+ }
16151
+ function readArray(dv, off, size, t) {
16152
+ const count = t.elementSize > 0 ? size / t.elementSize : 0;
16153
+ const out = [];
16154
+ for (let i = 0; i < count; i++)
16155
+ out.push(readElement(dv, off + i * t.elementSize, t.elementType, t.elementSize));
16156
+ return out;
16157
+ }
16158
+ function writeArray(dv, off, size, t, v) {
16159
+ const count = t.elementSize > 0 ? size / t.elementSize : 0;
16160
+ const list = v ?? [];
16161
+ for (let i = 0; i < count; i++)
16162
+ writeElement(dv, off + i * t.elementSize, t.elementType, t.elementSize, list[i]);
16163
+ }
16164
+ function readElement(dv, off, t, size) {
16165
+ switch (t.tag) {
16166
+ case "basic":
16167
+ return readScalar(dv, off, t.kind);
16168
+ case "bitfield":
16169
+ return readBitfield(dv, off, t);
16170
+ case "string":
16171
+ return readString(dv, off, size, t.encoding);
16172
+ case "struct":
16173
+ case "union":
16174
+ return doDecode(dv, off, t.fields);
16175
+ case "array":
16176
+ return readArray(dv, off, size, t);
16177
+ }
16178
+ }
16179
+ function writeElement(dv, off, t, size, val) {
16180
+ switch (t.tag) {
16181
+ // TODO: remove this any
16182
+ case "basic":
16183
+ writeScalar(dv, off, { k: t.kind, v: val });
16184
+ break;
16185
+ // 直传(不 Number()):writeBitfield 的 val 是 number | bigint,
16186
+ // 64 位单元走 bigint,先 Number() 会把 >2^53 的位域值截断。
16187
+ case "bitfield":
16188
+ writeBitfield(dv, off, t, val ?? 0);
16189
+ break;
16190
+ case "string":
16191
+ writeString(dv, off, size, t.encoding, val);
16192
+ break;
16193
+ case "struct":
16194
+ case "union":
16195
+ doEncode(dv, off, t.fields, val ?? {});
16196
+ break;
16197
+ case "array":
16198
+ writeArray(dv, off, size, t, val);
16199
+ break;
16200
+ }
16201
+ }
16202
+ function doDecode(dv, base, fields) {
15807
16203
  const out = {};
15808
- const h = loadDll(dll);
15809
- for (const [name, sig] of Object.entries(map)) {
15810
- const proc = win.GetProcAddress(h, name);
15811
- if (!proc)
15812
- throw new Error(`ffi-bind: proc "${name}" not found in ${dll}`);
15813
- out[name] = makeFn(proc, sig);
16204
+ for (const f of fields) {
16205
+ const v = readElement(dv, base + f.offset, f.type, f.size);
16206
+ if (f.nonnull && v === 0)
16207
+ throw new Error(`ffi-struct: decode: '!' field "${f.name}" got 0 (C did not fill it, or decode was called on an unfilled slot)`);
16208
+ out[f.name] = v;
15814
16209
  }
15815
16210
  return out;
15816
16211
  }
16212
+ function doEncode(dv, base, fields, v) {
16213
+ for (const f of fields) {
16214
+ if (v[f.name] === void 0)
16215
+ continue;
16216
+ writeElement(dv, base + f.offset, f.type, f.size, v[f.name]);
16217
+ }
16218
+ }
16219
+ function createStruct(t) {
16220
+ const { fields, size, maxEffectiveAlign } = computeStructLayout(t);
16221
+ return {
16222
+ __struct: t,
16223
+ size,
16224
+ structAlign: maxEffectiveAlign,
16225
+ decode: (p) => {
16226
+ if (typeof p === "number") {
16227
+ const buf = new ArrayBuffer(size);
16228
+ const u8 = new Uint8Array(buf);
16229
+ for (let i = 0; i < size; i++)
16230
+ u8[i] = ffi2.readByte(p + i);
16231
+ return doDecode(new DataView(buf), 0, fields);
16232
+ }
16233
+ return doDecode(new DataView(p), 0, fields);
16234
+ },
16235
+ alloc: (() => new PtrArrayBuffer(size)),
16236
+ encode: ((v, buf) => {
16237
+ if (v === void 0 || v === null)
16238
+ throw new Error(`ffi-struct: encode(v) requires an argument; use alloc() for a zeroed out-param slot`);
16239
+ const out = buf ?? new PtrArrayBuffer(size);
16240
+ doEncode(new DataView(out), 0, fields, v);
16241
+ return out;
16242
+ }),
16243
+ offsetOf: (name) => {
16244
+ for (const f of fields)
16245
+ if (f.name === name)
16246
+ return f.offset;
16247
+ throw new Error(`ffi-struct: no field "${name}"`);
16248
+ }
16249
+ };
16250
+ }
16251
+ function buildDecl(kind, member, pack) {
16252
+ const decl = { "#": kind };
16253
+ if (pack !== void 0)
16254
+ decl["#pack"] = pack;
16255
+ for (const [k, v] of Object.entries(member))
16256
+ if (!k.startsWith("#"))
16257
+ decl[k] = v;
16258
+ return decl;
16259
+ }
16260
+ function struct(a, b6, c) {
16261
+ const isNamed = typeof a === "string";
16262
+ const raw = isNamed ? b6 : a;
16263
+ const opts = isNamed ? c : b6;
16264
+ return createStruct(buildDecl("struct", raw, opts?.pack));
16265
+ }
16266
+
16267
+ // _build/lib/windows/structs.js
16268
+ var RECT = /* @__PURE__ */ struct("RECT", {
16269
+ left: "i32",
16270
+ top: "i32",
16271
+ right: "i32",
16272
+ bottom: "i32"
16273
+ });
16274
+ var POINT = /* @__PURE__ */ struct("POINT", {
16275
+ x: "i32",
16276
+ y: "i32"
16277
+ });
16278
+ var SIZE = /* @__PURE__ */ struct("SIZE", {
16279
+ cx: "i32",
16280
+ cy: "i32"
16281
+ });
16282
+ var LOGFONTW = /* @__PURE__ */ struct("LOGFONTW", {
16283
+ lfHeight: "i32",
16284
+ lfWidth: "i32",
16285
+ lfEscapement: "i32",
16286
+ lfOrientation: "i32",
16287
+ lfWeight: "i32",
16288
+ lfItalic: "u8",
16289
+ lfUnderline: "u8",
16290
+ lfStrikeOut: "u8",
16291
+ lfCharSet: "u8",
16292
+ lfOutPrecision: "u8",
16293
+ lfClipPrecision: "u8",
16294
+ lfQuality: "u8",
16295
+ lfPitchAndFamily: "u8",
16296
+ lfFaceName: "u16[32]@utf-16le"
16297
+ });
16298
+ var BITMAPINFOHEADER = /* @__PURE__ */ struct("BITMAPINFOHEADER", {
16299
+ biSize: "u32",
16300
+ biWidth: "i32",
16301
+ biHeight: "i32",
16302
+ biPlanes: "u16",
16303
+ biBitCount: "u16",
16304
+ biCompression: "u32",
16305
+ biSizeImage: "u32",
16306
+ biXPelsPerMeter: "i32",
16307
+ biYPelsPerMeter: "i32",
16308
+ biClrUsed: "u32",
16309
+ biClrImportant: "u32"
16310
+ });
16311
+ var OPENFILENAMEW = /* @__PURE__ */ struct("OPENFILENAMEW", {
16312
+ lStructSize: "u32",
16313
+ hwndOwner: "<HWND>ptr",
16314
+ hInstance: "<HMODULE>ptr",
16315
+ lpstrFilter: "<>ptr",
16316
+ lpstrCustomFilter: "<>ptr",
16317
+ nMaxCustFilter: "u32",
16318
+ nFilterIndex: "u32",
16319
+ lpstrFile: "<>ptr",
16320
+ nMaxFile: "u32",
16321
+ lpstrFileTitle: "<>ptr",
16322
+ nMaxFileTitle: "u32",
16323
+ lpstrInitialDir: "<>ptr",
16324
+ lpstrTitle: "<>ptr",
16325
+ Flags: "u32",
16326
+ nFileOffset: "u16",
16327
+ nFileExtension: "u16",
16328
+ lpstrDefExt: "<>ptr",
16329
+ lCustData: "<>ptr",
16330
+ lpfnHook: "<>ptr",
16331
+ lpTemplateName: "<>ptr",
16332
+ pvReserved: "<>ptr",
16333
+ dwReserved: "u32",
16334
+ FlagsEx: "u32"
16335
+ });
16336
+ var BROWSEINFOW = /* @__PURE__ */ struct("BROWSEINFOW", {
16337
+ hwndOwner: "<HWND>ptr",
16338
+ pidlRoot: "<>ptr",
16339
+ pszDisplayName: "<>ptr",
16340
+ lpszTitle: "<>ptr",
16341
+ ulFlags: "u32",
16342
+ lpfn: "<>ptr",
16343
+ lParam: "<>ptr",
16344
+ iImage: "i32"
16345
+ });
16346
+ var NMHDR = /* @__PURE__ */ struct("NMHDR", {
16347
+ hwndFrom: "<HWND>ptr",
16348
+ idFrom: "<>ptr",
16349
+ code: "i32"
16350
+ });
16351
+ var SYSTEMTIME = /* @__PURE__ */ struct("SYSTEMTIME", {
16352
+ wYear: "u16",
16353
+ wMonth: "u16",
16354
+ wDayOfWeek: "u16",
16355
+ wDay: "u16",
16356
+ wHour: "u16",
16357
+ wMinute: "u16",
16358
+ wSecond: "u16",
16359
+ wMilliseconds: "u16"
16360
+ });
16361
+ var NMDATETIMECHANGE = /* @__PURE__ */ struct("NMDATETIMECHANGE", {
16362
+ hdr: NMHDR.__struct,
16363
+ dwFlags: "u32",
16364
+ st: SYSTEMTIME.__struct
16365
+ });
16366
+ var LITEM = /* @__PURE__ */ struct("LITEM", {
16367
+ mask: "u32",
16368
+ iLink: "i32",
16369
+ state: "u32",
16370
+ stateMask: "u32",
16371
+ szID: "u16[48]@utf-16le",
16372
+ szUrl: "u16[2084]@utf-16le"
16373
+ });
16374
+ var NMLINK = /* @__PURE__ */ struct("NMLINK", {
16375
+ hdr: NMHDR.__struct,
16376
+ item: LITEM.__struct
16377
+ });
16378
+ var NMCUSTOMDRAW = /* @__PURE__ */ struct("NMCUSTOMDRAW", {
16379
+ hdr: NMHDR.__struct,
16380
+ dwDrawStage: "u32",
16381
+ hdc: "<HDC>ptr",
16382
+ rc: "i32[4]",
16383
+ dwItemSpec: "<>ptr",
16384
+ uItemState: "u32",
16385
+ lItemlParam: "<>ptr"
16386
+ });
16387
+ var NMLVCUSTOMDRAW = /* @__PURE__ */ struct("NMLVCUSTOMDRAW", {
16388
+ hdr: NMHDR.__struct,
16389
+ dwDrawStage: "u32",
16390
+ hdc: "<HDC>ptr",
16391
+ rc: "i32[4]",
16392
+ dwItemSpec: "<>ptr",
16393
+ uItemState: "u32",
16394
+ lItemlParam: "<>ptr",
16395
+ clrText: "u32",
16396
+ clrTextBk: "u32",
16397
+ iSubItem: "i32",
16398
+ dwItemType: "u32"
16399
+ });
16400
+ var NMLISTVIEW = /* @__PURE__ */ struct("NMLISTVIEW", {
16401
+ hdr: NMHDR.__struct,
16402
+ iItem: "i32",
16403
+ iSubItem: "i32",
16404
+ uNewState: "u32",
16405
+ uOldState: "u32",
16406
+ uChanged: "u32",
16407
+ ptAction: "i32[2]",
16408
+ lParam: "<>ptr"
16409
+ });
16410
+ var TCITEMW = /* @__PURE__ */ struct("TCITEMW", {
16411
+ mask: "u32",
16412
+ dwState: "u32",
16413
+ dwStateMask: "u32",
16414
+ pszText: "<>ptr",
16415
+ cchTextMax: "i32",
16416
+ iImage: "i32",
16417
+ lParam: "<>ptr"
16418
+ });
16419
+ var TVITEM = /* @__PURE__ */ struct("TVITEM", {
16420
+ mask: "u32",
16421
+ hItem: "<>ptr",
16422
+ state: "u32",
16423
+ stateMask: "u32",
16424
+ pszText: "<>ptr",
16425
+ cchTextMax: "i32",
16426
+ iImage: "i32",
16427
+ iSelectedImage: "i32",
16428
+ cChildren: "i32",
16429
+ lParam: "<>ptr"
16430
+ });
16431
+ var TVINSERTSTRUCT = /* @__PURE__ */ struct("TVINSERTSTRUCT", {
16432
+ hParent: "<>ptr",
16433
+ hInsertAfter: "<>ptr",
16434
+ item: TVITEM.__struct
16435
+ });
16436
+ var LVHITTESTINFO = /* @__PURE__ */ struct("LVHITTESTINFO", {
16437
+ pt: "i32[2]",
16438
+ flags: "u32",
16439
+ iItem: "i32",
16440
+ iSubItem: "i32",
16441
+ iGroup: "i32"
16442
+ });
16443
+ var LVITEMW = /* @__PURE__ */ struct("LVITEMW", {
16444
+ mask: "u32",
16445
+ iItem: "i32",
16446
+ iSubItem: "i32",
16447
+ state: "u32",
16448
+ stateMask: "u32",
16449
+ pszText: "<>ptr",
16450
+ cchTextMax: "i32",
16451
+ iImage: "i32",
16452
+ lParam: "<>ptr",
16453
+ iIndent: "i32",
16454
+ iGroupId: "i32",
16455
+ cColumns: "u32",
16456
+ puColumns: "<>ptr",
16457
+ piColFmt: "<>ptr",
16458
+ iGroup: "i32"
16459
+ });
16460
+ var LVCOLUMNW = /* @__PURE__ */ struct("LVCOLUMNW", {
16461
+ mask: "u32",
16462
+ fmt: "i32",
16463
+ cx: "i32",
16464
+ pszText: "<>ptr",
16465
+ cchTextMax: "i32",
16466
+ iSubItem: "i32",
16467
+ iImage: "i32",
16468
+ iOrder: "i32",
16469
+ cxMin: "i32",
16470
+ cxDefault: "i32",
16471
+ cxIdeal: "i32"
16472
+ });
16473
+ var MSG = /* @__PURE__ */ struct("MSG", {
16474
+ hwnd: "<HWND>ptr",
16475
+ message: "u32",
16476
+ wParam: "<>ptr",
16477
+ lParam: "<>ptr",
16478
+ time: "u32",
16479
+ pt: POINT.__struct
16480
+ });
16481
+ var PAINTSTRUCT = /* @__PURE__ */ struct("PAINTSTRUCT", {
16482
+ hdc: "<HDC>ptr",
16483
+ fErase: "i32",
16484
+ rcPaint: RECT.__struct,
16485
+ fRestore: "i32",
16486
+ fIncUpdate: "i32",
16487
+ rgbReserved: "u8[32]"
16488
+ });
16489
+
16490
+ // _build/lib/windows/user32.js
16491
+ var b = (name, sig, encoders) => bind("user32.dll", name, sig, encoders);
16492
+ var _bProbe = b("GetDesktopWindow", " -> <HWND>ptr");
16493
+ var LONG_PTR_SYM = os3.arch === "x64" ? "PtrW" : "W";
16494
+ var SetWindowPos = /* @__PURE__ */ b("SetWindowPos", "<HWND>ptr <>ptr@SetWindowPosHwnd i32 i32 i32 i32 u32 -> i32");
16495
+ var SetWindowText = /* @__PURE__ */ b("SetWindowTextW", "<HWND>ptr <WCHAR>ptr -> i32");
16496
+ var GetWindowLongPtr = /* @__PURE__ */ b("GetWindowLong" + LONG_PTR_SYM, "<HWND>ptr i32@Gwlp -> <>ptr");
16497
+ var SetWindowLongPtr = /* @__PURE__ */ b("SetWindowLong" + LONG_PTR_SYM, "<HWND>ptr i32@Gwlp <>ptr -> <>ptr");
16498
+ var EnableWindow = /* @__PURE__ */ b("EnableWindow", "<HWND>ptr i32 -> i32");
16499
+ var SetParent = /* @__PURE__ */ b("SetParent", "<HWND>ptr <HWND>ptr -> <HWND>ptr");
16500
+ var DefWindowProc = /* @__PURE__ */ b("DefWindowProcW", "<HWND>ptr u32@AnyMsg <>ptr <>ptr -> <>ptr");
16501
+ var CallWindowProc = /* @__PURE__ */ b("CallWindowProcW", "<>ptr <HWND>ptr u32@AnyMsg <>ptr <>ptr -> <>ptr");
16502
+ var GetDC = /* @__PURE__ */ b("GetDC", "<HWND>ptr -> <HDC>ptr");
16503
+ var ReleaseDC = /* @__PURE__ */ b("ReleaseDC", "<HWND>ptr <HDC>ptr! -> i32");
16504
+ var DrawText = /* @__PURE__ */ b("DrawTextW", "<HDC>ptr! <WCHAR>ptr i32 <RECT>ptr i32 -> i32");
16505
+ var InvalidateRect = /* @__PURE__ */ b("InvalidateRect", "<HWND>ptr <RECT>ptr i32 -> i32", { RECT });
16506
+ var SetCursor = /* @__PURE__ */ b("SetCursor", "<HCURSOR>ptr -> <HCURSOR>ptr");
16507
+ var LoadCursor = /* @__PURE__ */ b("LoadCursorW", "<HMODULE>ptr <>ptr -> <HCURSOR>ptr");
16508
+ var GetCursorPos = /* @__PURE__ */ b("GetCursorPos", "<POINT>ptr -> i32");
16509
+ var ScreenToClient = /* @__PURE__ */ b("ScreenToClient", "<HWND>ptr <POINT>ptr -> i32");
16510
+ var ShowScrollBar = /* @__PURE__ */ b("ShowScrollBar", "<HWND>ptr u32 i32 -> i32");
16511
+ var GetSystemMetrics = /* @__PURE__ */ b("GetSystemMetrics", "i32 -> i32");
16512
+
16513
+ // _build/lib/react-qw/reconciler.js
16514
+ var import_react_reconciler = __toESM(require_react_reconciler(), 1);
16515
+ var import_react = __toESM(require_react(), 1);
16516
+ var import_constants = __toESM(require_constants(), 1);
16517
+ import * as gui3 from "gui";
16518
+ import * as os4 from "os";
16519
+
16520
+ // _build/lib/windows/gdi32.js
16521
+ var b2 = (name, sig, encoders) => bind("gdi32.dll", name, sig, encoders);
16522
+ var DeleteObject = /* @__PURE__ */ b2("DeleteObject", "<>ptr -> i32");
16523
+ var GetDeviceCaps = /* @__PURE__ */ b2("GetDeviceCaps", "<HDC>ptr! i32@DeviceCap -> i32");
16524
+ var CreateFontIndirect = /* @__PURE__ */ b2("CreateFontIndirectW", "<LOGFONTW>ptr -> <>ptr", { LOGFONTW });
16525
+ var SelectObject = /* @__PURE__ */ b2("SelectObject", "<HDC>ptr! <>ptr -> <>ptr");
16526
+ var GetObject = /* @__PURE__ */ b2("GetObjectW", "<>ptr i32 <BYTE>ptr -> i32");
16527
+ var SetDIBitsToDevice = /* @__PURE__ */ b2("SetDIBitsToDevice", "<HDC>ptr! i32 i32 u32 u32 i32 i32 u32 u32 <BYTE>ptr <BYTE>ptr u32 -> i32");
16528
+
16529
+ // _build/lib/react-qw/props.js
16530
+ import * as gui from "gui";
16531
+ function applyProps(instance, newProps, _oldProps) {
16532
+ const hwnd = instance.hwnd;
16533
+ instance.props = newProps;
16534
+ if (hwnd === null)
16535
+ return;
16536
+ const textVal = "text" in newProps ? newProps.text : typeof newProps.children === "string" ? newProps.children : typeof newProps.children === "number" ? String(newProps.children) : void 0;
16537
+ if (textVal !== void 0) {
16538
+ let cursor = -1;
16539
+ if (instance.type === "EDIT") {
16540
+ const sel = gui.SendMessage(hwnd, 176, 0, 0);
16541
+ cursor = sel >>> 16;
16542
+ }
16543
+ SetWindowText(hwnd, textVal);
16544
+ if (instance.type === "EDIT" && cursor >= 0) {
16545
+ gui.SendMessage(hwnd, 177, cursor, cursor);
16546
+ }
16547
+ }
16548
+ if ("disabled" in newProps) {
16549
+ EnableWindow(hwnd, !newProps.disabled ? 1 : 0);
16550
+ }
16551
+ if ("hidden" in newProps) {
16552
+ gui.ShowWindow(
16553
+ hwnd,
16554
+ newProps.hidden ? 0 : 5
16555
+ /* gui.ShowWindowCmd.SHOW */
16556
+ );
16557
+ }
16558
+ if ("visible" in newProps) {
16559
+ gui.ShowWindow(
16560
+ hwnd,
16561
+ newProps.visible ? 5 : 0
16562
+ /* gui.ShowWindowCmd.HIDE */
16563
+ );
16564
+ }
16565
+ }
16566
+
16567
+ // _build/lib/react-qw/layout.js
16568
+ var DEFAULT_W = 100;
16569
+ var DEFAULT_H = 30;
16570
+ function calculateFlexLayout(flex, parentW, parentH, children) {
16571
+ const dir = flex.flexDirection || "column";
16572
+ const gap = flex.gap ?? 0;
16573
+ const justify = flex.justifyContent || "flex-start";
16574
+ const align = flex.alignItems || "stretch";
16575
+ const isRow = dir === "row";
16576
+ const n = children.length;
16577
+ const mainSize = isRow ? "w" : "h";
16578
+ const crossSize = isRow ? "h" : "w";
16579
+ const mainPos = isRow ? "x" : "y";
16580
+ const crossPos = isRow ? "y" : "x";
16581
+ const mainDim = isRow ? "width" : "height";
16582
+ const crossDim = isRow ? "height" : "width";
16583
+ const pt = flex.paddingTop ?? flex.padding ?? 0;
16584
+ const pr = flex.paddingRight ?? flex.padding ?? 0;
16585
+ const pb = flex.paddingBottom ?? flex.padding ?? 0;
16586
+ const pl = flex.paddingLeft ?? flex.padding ?? 0;
16587
+ const mainPadding = isRow ? pl + pr : pt + pb;
16588
+ const crossPadding = isRow ? pt + pb : pl + pr;
16589
+ const parentMain = (isRow ? parentW : parentH) - mainPadding;
16590
+ const parentCross = (isRow ? parentH : parentW) - crossPadding;
16591
+ const sizes = children.map((c) => ({
16592
+ w: typeof c.style.width === "number" ? c.style.width : DEFAULT_W,
16593
+ h: typeof c.style.height === "number" ? c.style.height : DEFAULT_H
16594
+ }));
16595
+ const flexGrows = children.map((c) => c.style.flexGrow ?? 0);
16596
+ const totalGrow = flexGrows.reduce((s, g) => s + g, 0);
16597
+ const baseMain = sizes.reduce((s, c) => s + c[mainSize], 0);
16598
+ let freeGrow = parentMain - baseMain - Math.max(0, n - 1) * gap;
16599
+ if (totalGrow > 0 && freeGrow > 0) {
16600
+ for (let i = 0; i < n; i++) {
16601
+ sizes[i][mainSize] += freeGrow * flexGrows[i] / totalGrow;
16602
+ }
16603
+ }
16604
+ const totalMain = sizes.reduce((s, c) => s + c[mainSize], 0);
16605
+ const free = parentMain - totalMain - Math.max(0, n - 1) * gap;
16606
+ let offset = 0, extraGap = 0;
16607
+ if (justify === "flex-end")
16608
+ offset = free;
16609
+ else if (justify === "center")
16610
+ offset = Math.max(0, free / 2);
16611
+ else if (justify === "space-between" && n > 1)
16612
+ extraGap = free / (n - 1);
16613
+ else if (justify === "space-around") {
16614
+ extraGap = free / n;
16615
+ offset = extraGap / 2;
16616
+ } else if (justify === "space-evenly") {
16617
+ extraGap = free / (n + 1);
16618
+ offset = extraGap;
16619
+ }
16620
+ let cursor = offset;
16621
+ return sizes.map((sz, i) => {
16622
+ const childCrossBase = sz[crossSize];
16623
+ const childAlign = children[i].style.alignSelf ?? "auto";
16624
+ const effectiveAlign = childAlign === "auto" ? align : childAlign;
16625
+ let childMain = sz[mainSize];
16626
+ let childCross = childCrossBase;
16627
+ const res = { x: 0, y: 0, width: 0, height: 0 };
16628
+ res[mainPos] = cursor;
16629
+ res[crossPos] = 0;
16630
+ res[mainDim] = childMain;
16631
+ res[crossDim] = childCross;
16632
+ if (effectiveAlign === "stretch") {
16633
+ const hasExplicitCross = typeof children[i].style[crossDim] === "number";
16634
+ if (!hasExplicitCross) {
16635
+ res[crossDim] = parentCross;
16636
+ res[crossPos] = 0;
16637
+ }
16638
+ } else if (effectiveAlign === "flex-end") {
16639
+ res[crossPos] = parentCross - childCross;
16640
+ } else if (effectiveAlign === "center") {
16641
+ res[crossPos] = Math.max(0, (parentCross - childCross) / 2);
16642
+ }
16643
+ cursor += childMain + gap + extraGap;
16644
+ return res;
16645
+ });
16646
+ }
15817
16647
 
15818
16648
  // _build/lib/text-measure.js
15819
- var user32 = bindLib("user32.dll", {
15820
- DrawTextW: "ptr wstr i32 ptr i32 -> i32",
15821
- GetDC: "ptr -> ptr",
15822
- ReleaseDC: "ptr ptr -> i32"
15823
- });
15824
- var gdi32 = bindLib("gdi32.dll", {
15825
- SelectObject: "ptr ptr -> ptr"
15826
- });
16649
+ import * as gui2 from "gui";
15827
16650
  function measureText(hdc, text, maxWidth) {
15828
- const rect = new ArrayBuffer(16);
15829
- const dv = new DataView(rect);
15830
- dv.setInt32(8, maxWidth, true);
15831
- user32.DrawTextW(
16651
+ const r = RECT.encode({ right: maxWidth });
16652
+ DrawText(
15832
16653
  hdc,
15833
16654
  text,
15834
16655
  -1,
15835
- rect,
16656
+ r.ptr,
15836
16657
  1024
15837
16658
  /* gui.DrawTextFlag.CALCRECT */
15838
16659
  );
15839
- return { width: dv.getInt32(8, true), height: dv.getInt32(12, true) };
16660
+ const { right, bottom } = RECT.decode(r);
16661
+ return { width: right, height: bottom };
15840
16662
  }
15841
16663
  function getButtonIdealSize(hwnd) {
15842
- const size = new ArrayBuffer(8);
15843
- gui2.SendMessage(hwnd, 5633, 0, ffi2.bufferPtr(size));
15844
- const dv = new DataView(size);
15845
- return { width: dv.getInt32(0, true), height: dv.getInt32(4, true) };
16664
+ const size = SIZE.alloc();
16665
+ gui2.SendMessage(hwnd, 5633, 0, size.ptr);
16666
+ const { cx, cy } = SIZE.decode(size);
16667
+ return { width: cx, height: cy };
15846
16668
  }
15847
16669
  function measureTextForHwnd(hwnd, text) {
15848
- const hdc = user32.GetDC(hwnd);
16670
+ const hdc = GetDC(hwnd);
15849
16671
  if (!hdc)
15850
16672
  return { width: 0, height: 0 };
15851
16673
  const hFont = gui2.SendMessage(hwnd, 49, 0, 0);
15852
- const oldFont = hFont ? gdi32.SelectObject(hdc, hFont) : 0;
16674
+ const oldFont = hFont ? SelectObject(hdc, hFont) : 0;
15853
16675
  const result = measureText(hdc, text, 0);
15854
16676
  if (hFont)
15855
- gdi32.SelectObject(hdc, oldFont);
15856
- user32.ReleaseDC(hwnd, hdc);
16677
+ SelectObject(hdc, oldFont);
16678
+ ReleaseDC(hwnd, hdc);
15857
16679
  const wr = gui2.GetWindowRect(hwnd);
15858
16680
  const cr = gui2.GetClientRect(hwnd);
15859
16681
  if (wr && cr) {
@@ -15865,14 +16687,20 @@ function measureTextForHwnd(hwnd, text) {
15865
16687
 
15866
16688
  // _build/lib/react-qw/reconciler.js
15867
16689
  var dpiFont = gui3.CreateSystemDpiFont();
15868
- var scaleFactor = gui3.GetScaleFactor();
16690
+ var scaleFactor = (() => {
16691
+ const hdc = GetDC(NULL);
16692
+ const dpi = hdc ? GetDeviceCaps(hdc, 88) : 96;
16693
+ if (hdc)
16694
+ ReleaseDC(NULL, hdc);
16695
+ return dpi / 96;
16696
+ })();
15869
16697
  var DELAYED_CONTROLS = /* @__PURE__ */ new Set(["SysListView32", "SysTreeView32", "LISTBOX", "COMBOBOX", "msctls_trackbar32", "SysDateTimePick32", "SysLink"]);
15870
16698
  function isDelayedControl(winClass) {
15871
16699
  return DELAYED_CONTROLS.has(winClass);
15872
16700
  }
15873
16701
  function setupWindowProc(instance, hwnd) {
15874
16702
  instance.hwnd = hwnd;
15875
- const oldProc = gui3.GetWindowLongPtr(
16703
+ const oldProc = GetWindowLongPtr(
15876
16704
  hwnd,
15877
16705
  -4
15878
16706
  /* gui.Gwlp.WNDPROC */
@@ -15881,11 +16709,11 @@ function setupWindowProc(instance, hwnd) {
15881
16709
  gui3.SetWindowProc(hwnd, (hwnd2, msg, wParam, lParam) => {
15882
16710
  const ev = instance.props.onEvent;
15883
16711
  if (!ev)
15884
- return gui3.CallWindowProc(oldProc, hwnd2, msg, wParam, lParam);
16712
+ return CallWindowProc(oldProc, hwnd2, msg, wParam, lParam);
15885
16713
  if (typeof ev === "object") {
15886
- return ev.fn({ hwnd: hwnd2, msg, wParam, lParam, callOldWndProc: () => gui3.CallWindowProc(oldProc, hwnd2, msg, wParam, lParam) });
16714
+ return ev.fn({ hwnd: hwnd2, msg, wParam, lParam, callOldWndProc: () => CallWindowProc(oldProc, hwnd2, msg, wParam, lParam) });
15887
16715
  }
15888
- const result = gui3.CallWindowProc(oldProc, hwnd2, msg, wParam, lParam);
16716
+ const result = CallWindowProc(oldProc, hwnd2, msg, wParam, lParam);
15889
16717
  const override = ev({ hwnd: hwnd2, msg, wParam, lParam });
15890
16718
  return typeof override === "number" && Number.isInteger(override) ? override : result;
15891
16719
  });
@@ -15955,7 +16783,7 @@ function runFlexLayout(inst) {
15955
16783
  if (lr && lr.x === r.x && lr.y === r.y && lr.w === r.width && lr.h === r.height)
15956
16784
  continue;
15957
16785
  console.log("flex: set", child.type, child.hwnd, "to", r.x, r.y, r.width, r.height);
15958
- gui3.SetWindowPos(
16786
+ SetWindowPos(
15959
16787
  child.hwnd,
15960
16788
  0,
15961
16789
  (r.x + pl) * scaleFactor,
@@ -15965,7 +16793,7 @@ function runFlexLayout(inst) {
15965
16793
  64
15966
16794
  /* gui.SetWindowPosFlag.SWP_SHOWWINDOW */
15967
16795
  );
15968
- gui3.InvalidateRect(child.hwnd, null, true);
16796
+ InvalidateRect(child.hwnd, NULL, 1);
15969
16797
  child.lastRect = { x: r.x, y: r.y, w: r.width, h: r.height };
15970
16798
  }
15971
16799
  for (const c of children)
@@ -16011,7 +16839,7 @@ var hostConfig = {
16011
16839
  if (child.hwnd === null) {
16012
16840
  ensureChildWindow(child, parent.hwnd);
16013
16841
  } else {
16014
- gui3.SetParent(child.hwnd, parent.hwnd);
16842
+ SetParent(child.hwnd, parent.hwnd ?? NULL);
16015
16843
  }
16016
16844
  if (false)
16017
16845
  console.log("[reconciler] appendInitialChild parent:", parent.hwnd, "child:", child.hwnd);
@@ -16021,7 +16849,7 @@ var hostConfig = {
16021
16849
  if (child.hwnd === null) {
16022
16850
  ensureChildWindow(child, parent.hwnd);
16023
16851
  } else {
16024
- gui3.SetParent(child.hwnd, parent.hwnd);
16852
+ SetParent(child.hwnd, parent.hwnd ?? NULL);
16025
16853
  }
16026
16854
  if (false)
16027
16855
  console.log("[reconciler] appendChild parent:", parent.hwnd, "child:", child.hwnd);
@@ -16031,7 +16859,7 @@ var hostConfig = {
16031
16859
  if (child.hwnd === null) {
16032
16860
  ensureChildWindow(child, container);
16033
16861
  } else {
16034
- gui3.SetParent(child.hwnd, container);
16862
+ SetParent(child.hwnd, container);
16035
16863
  }
16036
16864
  const rootInst = instancesByHwnd.get(container);
16037
16865
  if (rootInst)
@@ -16043,7 +16871,7 @@ var hostConfig = {
16043
16871
  if (child.hwnd === null) {
16044
16872
  ensureChildWindow(child, parent.hwnd);
16045
16873
  } else {
16046
- gui3.SetParent(child.hwnd, parent.hwnd);
16874
+ SetParent(child.hwnd, parent.hwnd ?? NULL);
16047
16875
  }
16048
16876
  if (false)
16049
16877
  console.log("[reconciler] insertBefore parent:", parent.hwnd, "child:", child.hwnd, "before:", beforeChild.hwnd);
@@ -16055,7 +16883,7 @@ var hostConfig = {
16055
16883
  if (child.hwnd === null) {
16056
16884
  ensureChildWindow(child, container);
16057
16885
  } else {
16058
- gui3.SetParent(child.hwnd, container);
16886
+ SetParent(child.hwnd, container);
16059
16887
  }
16060
16888
  const rootInst = instancesByHwnd.get(container);
16061
16889
  if (!rootInst)
@@ -16112,7 +16940,7 @@ var hostConfig = {
16112
16940
  resetTextContent(_instance) {
16113
16941
  },
16114
16942
  commitTextUpdate(instance, _oldText, newText) {
16115
- gui3.SetWindowText(instance.hwnd, newText);
16943
+ SetWindowText(instance.hwnd, newText);
16116
16944
  },
16117
16945
  hideInstance(instance) {
16118
16946
  if (instance.hwnd !== null)
@@ -16166,10 +16994,10 @@ var hostConfig = {
16166
16994
  clearContainer(_container) {
16167
16995
  },
16168
16996
  scheduleTimeout(fn, delay) {
16169
- return os.setTimeout(fn, delay);
16997
+ return os4.setTimeout(fn, delay);
16170
16998
  },
16171
16999
  cancelTimeout(id) {
16172
- os.clearTimeout?.(id);
17000
+ os4.clearTimeout?.(id);
16173
17001
  },
16174
17002
  noTimeout: -1,
16175
17003
  supportsMutation: true,
@@ -16336,298 +17164,23 @@ var ComboBox = (0, import_react4.forwardRef)(({ items, selectedIndex: controlled
16336
17164
  var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
16337
17165
  var import_react5 = __toESM(require_react(), 1);
16338
17166
  import * as gui6 from "gui";
16339
- import * as ffi4 from "ffi";
16340
-
16341
- // _build/lib/ffi-struct.js
16342
- import * as os2 from "os";
16343
- var PTR = os2.arch === "x64" ? 8 : 4;
16344
- var AS = {
16345
- u8: [1, 1],
16346
- i8: [1, 1],
16347
- u16: [2, 2],
16348
- i16: [2, 2],
16349
- u32: [4, 4],
16350
- i32: [4, 4],
16351
- u64: [8, 8],
16352
- i64: [8, 8],
16353
- f32: [4, 4],
16354
- f64: [8, 8],
16355
- ptr: [PTR, PTR],
16356
- wstr: [2, 2]
16357
- // 仅定长数组元素用(wchar)
16358
- };
16359
- function alignUp(v, a) {
16360
- return v + a - 1 & ~(a - 1);
16361
- }
16362
- function parseField(f) {
16363
- const arr = /^(.+)\[(\d+)\]$/.exec(f);
16364
- if (arr) {
16365
- const b2 = normKind(arr[1]);
16366
- if (b2 === "void")
16367
- throw new Error(`ffi-struct: "void" cannot be an array base`);
16368
- return { base: b2, count: Number(arr[2]) };
16369
- }
16370
- const b = normKind(f);
16371
- if (b === "void" || b === "wstr")
16372
- throw new Error(`ffi-struct: invalid scalar field type "${f}"`);
16373
- return { base: b, count: 1 };
16374
- }
16375
- function layout(def) {
16376
- const fields = [];
16377
- let cursor = 0;
16378
- let maxAlign = 1;
16379
- for (const key of Object.keys(def)) {
16380
- const v = def[key];
16381
- let a;
16382
- let w;
16383
- if (typeof v === "string") {
16384
- const { base, count } = parseField(v);
16385
- const [align, elem] = AS[base];
16386
- a = align;
16387
- w = count >= 1 ? elem * count : elem;
16388
- fields.push({ name: key, base, count, offset: 0 });
16389
- } else {
16390
- const child = v;
16391
- a = child.structAlign;
16392
- w = child.size;
16393
- fields.push({ name: key, base: "u8", count: 0, offset: 0, child });
16394
- }
16395
- const off = alignUp(cursor, a);
16396
- const f = fields[fields.length - 1];
16397
- f.offset = off;
16398
- cursor = off + w;
16399
- if (a > maxAlign)
16400
- maxAlign = a;
16401
- }
16402
- return { fields, size: alignUp(cursor, maxAlign), structAlign: maxAlign };
16403
- }
16404
- var _layoutCache = /* @__PURE__ */ new WeakMap();
16405
- function buildLayout(def) {
16406
- let hit = _layoutCache.get(def);
16407
- if (hit)
16408
- return hit;
16409
- hit = layout(def);
16410
- _layoutCache.set(def, hit);
16411
- return hit;
16412
- }
16413
- function readScalar(dv, off, k) {
16414
- switch (k) {
16415
- case "u8":
16416
- return dv.getUint8(off);
16417
- case "i8":
16418
- return dv.getInt8(off);
16419
- case "u16":
16420
- return dv.getUint16(off, true);
16421
- case "i16":
16422
- return dv.getInt16(off, true);
16423
- case "u32":
16424
- return dv.getUint32(off, true);
16425
- case "i32":
16426
- return dv.getInt32(off, true);
16427
- case "u64":
16428
- return Number(dv.getBigUint64(off, true));
16429
- case "i64":
16430
- return Number(dv.getBigInt64(off, true));
16431
- case "f32":
16432
- return dv.getFloat32(off, true);
16433
- case "f64":
16434
- return dv.getFloat64(off, true);
16435
- case "ptr":
16436
- return readPtr(dv, off);
16437
- case "wstr":
16438
- return dv.getUint16(off, true);
16439
- }
16440
- }
16441
- function readPtr(dv, off) {
16442
- if (PTR === 8)
16443
- return Number(dv.getBigUint64(off, true));
16444
- return dv.getUint32(off, true);
16445
- }
16446
- function writeScalar(dv, off, k, val) {
16447
- switch (k) {
16448
- case "u8":
16449
- dv.setUint8(off, val);
16450
- break;
16451
- case "i8":
16452
- dv.setInt8(off, val);
16453
- break;
16454
- case "u16":
16455
- dv.setUint16(off, val, true);
16456
- break;
16457
- case "i16":
16458
- dv.setInt16(off, val, true);
16459
- break;
16460
- case "u32":
16461
- dv.setUint32(off, val >>> 0, true);
16462
- break;
16463
- case "i32":
16464
- dv.setInt32(off, val | 0, true);
16465
- break;
16466
- case "u64":
16467
- dv.setBigUint64(off, BigInt(Math.trunc(val)), true);
16468
- break;
16469
- case "i64":
16470
- dv.setBigInt64(off, BigInt(Math.trunc(val)), true);
16471
- break;
16472
- case "f32":
16473
- dv.setFloat32(off, val, true);
16474
- break;
16475
- case "f64":
16476
- dv.setFloat64(off, val, true);
16477
- break;
16478
- case "ptr":
16479
- writePtr(dv, off, val);
16480
- break;
16481
- case "wstr":
16482
- dv.setUint16(off, val, true);
16483
- break;
16484
- }
16485
- }
16486
- function writePtr(dv, off, val) {
16487
- if (PTR === 8)
16488
- dv.setBigUint64(off, BigInt(Math.trunc(val)), true);
16489
- else
16490
- dv.setUint32(off, val >>> 0, true);
16491
- }
16492
- function readField(dv, base, f) {
16493
- const off = base + f.offset;
16494
- if (f.child)
16495
- return readInto(f.child, dv.buffer, off);
16496
- if (f.count > 1) {
16497
- if (f.base === "wstr") {
16498
- const arr = new Uint16Array(dv.buffer, dv.byteOffset + off, f.count);
16499
- let end = 0;
16500
- while (end < arr.length && arr[end] !== 0)
16501
- end++;
16502
- let s = "";
16503
- for (let i = 0; i < end; i++)
16504
- s += String.fromCharCode(arr[i]);
16505
- return s;
16506
- }
16507
- const out = [];
16508
- const step = AS[f.base][1];
16509
- for (let i = 0; i < f.count; i++)
16510
- out.push(readScalar(dv, off + i * step, f.base));
16511
- return out;
16512
- }
16513
- return readScalar(dv, off, f.base);
16514
- }
16515
- function writeField(dv, base, f, v) {
16516
- const off = base + f.offset;
16517
- if (f.child) {
16518
- writeInto(f.child, v, dv.buffer, off);
16519
- return;
16520
- }
16521
- if (f.count > 1) {
16522
- if (f.base === "wstr") {
16523
- const s = String(v ?? "");
16524
- const arr = new Uint16Array(dv.buffer, dv.byteOffset + off, f.count);
16525
- for (let i = 0; i < arr.length; i++)
16526
- arr[i] = 0;
16527
- const n = Math.min(s.length, f.count - 1);
16528
- for (let i = 0; i < n; i++)
16529
- arr[i] = s.charCodeAt(i);
16530
- return;
16531
- }
16532
- const step = AS[f.base][1];
16533
- const list = v ?? [];
16534
- for (let i = 0; i < f.count; i++)
16535
- writeScalar(dv, off + i * step, f.base, list[i] ?? 0);
16536
- return;
16537
- }
16538
- writeScalar(dv, off, f.base, Number(v));
16539
- }
16540
- function doSize(def) {
16541
- return buildLayout(def).size;
16542
- }
16543
- function readInto(child, buf, offset) {
16544
- const r = child;
16545
- return r.read(buf, offset);
16546
- }
16547
- function doRead(_def, fields, buf, offset) {
16548
- const out = {};
16549
- const dv = new DataView(buf);
16550
- for (const f of fields)
16551
- out[f.name] = readField(dv, offset, f);
16552
- return out;
16553
- }
16554
- function doWrite(def, fields, v, buf, offset = 0) {
16555
- buf = buf ?? new ArrayBuffer(doSize(def));
16556
- const dv = new DataView(buf);
16557
- for (const f of fields)
16558
- writeField(dv, offset, f, v[f.name]);
16559
- return buf;
16560
- }
16561
- function writeInto(child, v, buf, offset) {
16562
- const w = child;
16563
- w.write(v, buf, offset);
16564
- }
16565
- function struct(def) {
16566
- const { fields, size, structAlign } = buildLayout(def);
16567
- return {
16568
- __fields: def,
16569
- size,
16570
- structAlign,
16571
- read: (buf, offset = 0) => doRead(def, fields, buf, offset),
16572
- write: (v, buf, offset = 0) => doWrite(def, fields, v, buf, offset),
16573
- offsetOf: (name) => {
16574
- for (const f of fields)
16575
- if (f.name === name)
16576
- return f.offset;
16577
- throw new Error(`ffi-struct: no field "${String(name)}"`);
16578
- }
16579
- };
16580
- }
16581
17167
 
16582
17168
  // _build/lib/react-qw/nmhdr.js
16583
- import * as os3 from "os";
16584
- import * as ffi3 from "ffi";
16585
- var IS64 = os3.arch === "x64";
16586
- var PTR_SIZE = IS64 ? 8 : 4;
16587
- var NMHDR = struct({ hwndFrom: "ptr", idFrom: "ptr", code: "i32" });
16588
- var NMHDR_SIZE = NMHDR.size;
16589
- var NMHDR_CODE = NMHDR.offsetOf("code");
16590
- function readI32At(ptr, offset) {
16591
- return ffi3.readByte(ptr + offset) | ffi3.readByte(ptr + offset + 1) << 8 | ffi3.readByte(ptr + offset + 2) << 16 | ffi3.readByte(ptr + offset + 3) << 24;
16592
- }
16593
- function readU16At(ptr, offset) {
16594
- return ffi3.readByte(ptr + offset) | ffi3.readByte(ptr + offset + 1) << 8;
16595
- }
16596
17169
  function nmCode(lParam) {
16597
- return readI32At(lParam, NMHDR_CODE);
17170
+ return NMHDR.decode(lParam).code;
16598
17171
  }
16599
17172
 
16600
17173
  // _build/lib/react-qw/components/DateTimePicker.js
16601
- var SYSTEMTIME = struct({
16602
- wYear: "u16",
16603
- wMonth: "u16",
16604
- wDayOfWeek: "u16",
16605
- wDay: "u16",
16606
- wHour: "u16",
16607
- wMinute: "u16",
16608
- wSecond: "u16",
16609
- wMilliseconds: "u16"
16610
- });
16611
- var NMDATETIMECHANGE = struct({
16612
- hdr: NMHDR,
16613
- dwFlags: "u32",
16614
- st: SYSTEMTIME
16615
- });
16616
- function bufPtr(buf) {
16617
- return ffi4.bufferPtr(buf);
16618
- }
16619
17174
  function dateToSysTimeBuf(d) {
16620
- const buf = new ArrayBuffer(16);
16621
- const dv = new DataView(buf);
16622
- dv.setUint16(0, d.getFullYear(), true);
16623
- dv.setUint16(2, d.getMonth() + 1, true);
16624
- dv.setUint16(4, 0, true);
16625
- dv.setUint16(6, d.getDate(), true);
16626
- dv.setUint16(8, d.getHours(), true);
16627
- dv.setUint16(10, d.getMinutes(), true);
16628
- dv.setUint16(12, d.getSeconds(), true);
16629
- dv.setUint16(14, d.getMilliseconds(), true);
16630
- return buf;
17175
+ return SYSTEMTIME.encode({
17176
+ wYear: d.getFullYear(),
17177
+ wMonth: d.getMonth() + 1,
17178
+ wDay: d.getDate(),
17179
+ wHour: d.getHours(),
17180
+ wMinute: d.getMinutes(),
17181
+ wSecond: d.getSeconds(),
17182
+ wMilliseconds: d.getMilliseconds()
17183
+ });
16631
17184
  }
16632
17185
  var DateTimePicker = (0, import_react5.forwardRef)(function DateTimePicker2({ value, onChange, defaultValue, format = "short", allowNone, updown, style }, ref) {
16633
17186
  const [internalDate, setInternalDate] = (0, import_react5.useState)(defaultValue ?? null);
@@ -16652,7 +17205,7 @@ var DateTimePicker = (0, import_react5.forwardRef)(function DateTimePicker2({ va
16652
17205
  const d = effectiveDate;
16653
17206
  if (d) {
16654
17207
  const buf = dateToSysTimeBuf(d);
16655
- gui6.SendMessage(h, 4098, 0, bufPtr(buf));
17208
+ gui6.SendMessage(h, 4098, 0, buf.ptr);
16656
17209
  } else {
16657
17210
  gui6.SendMessage(h, 4098, 1, 0);
16658
17211
  }
@@ -16661,7 +17214,7 @@ var DateTimePicker = (0, import_react5.forwardRef)(function DateTimePicker2({ va
16661
17214
  const h = dpRef.current;
16662
17215
  if (!h)
16663
17216
  return;
16664
- gui6.InvalidateRect(h, null, true);
17217
+ InvalidateRect(h, NULL, 1);
16665
17218
  const cr = gui6.GetClientRect(h);
16666
17219
  if (cr) {
16667
17220
  const w = cr.right - cr.left;
@@ -16673,20 +17226,13 @@ var DateTimePicker = (0, import_react5.forwardRef)(function DateTimePicker2({ va
16673
17226
  if (e.msg === 78) {
16674
17227
  const code = nmCode(e.lParam);
16675
17228
  if (code === -759) {
16676
- const st = NMDATETIMECHANGE.offsetOf("st");
16677
- const dwFlags = readI32At(e.lParam, NMDATETIMECHANGE.offsetOf("dwFlags"));
17229
+ const { dwFlags, st } = NMDATETIMECHANGE.decode(e.lParam);
16678
17230
  if (dwFlags === 1) {
16679
17231
  if (!isControlled)
16680
17232
  setInternalDate(null);
16681
17233
  onChangeRef.current?.(null);
16682
17234
  } else {
16683
- const year = readU16At(e.lParam, st + 0);
16684
- const month = readU16At(e.lParam, st + 2);
16685
- const day = readU16At(e.lParam, st + 6);
16686
- const hour = readU16At(e.lParam, st + 8);
16687
- const min = readU16At(e.lParam, st + 10);
16688
- const sec = readU16At(e.lParam, st + 12);
16689
- const d = new Date(year, month - 1, day, hour, min, sec);
17235
+ const d = new Date(st.wYear, st.wMonth - 1, st.wDay, st.wHour, st.wMinute, st.wSecond);
16690
17236
  if (!isControlled)
16691
17237
  setInternalDate(d);
16692
17238
  onChangeRef.current?.(d);
@@ -16702,14 +17248,6 @@ var DateTimePicker = (0, import_react5.forwardRef)(function DateTimePicker2({ va
16702
17248
  var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
16703
17249
  var import_react6 = __toESM(require_react(), 1);
16704
17250
  import * as gui7 from "gui";
16705
- import * as ffi5 from "ffi";
16706
- function textToUtf16(s) {
16707
- const buf = new ArrayBuffer((s.length + 1) * 2);
16708
- const dv = new DataView(buf);
16709
- for (let i = 0; i < s.length; i++)
16710
- dv.setUint16(i * 2, s.charCodeAt(i), true);
16711
- return buf;
16712
- }
16713
17251
  var Input = (0, import_react6.forwardRef)(({ value: controlledValue, defaultValue = "", onChange, placeholder, password, multiline, readonly, number, disabled, style }, ref) => {
16714
17252
  const [internalValue, setInternalValue] = (0, import_react6.useState)(defaultValue);
16715
17253
  const isControlled = controlledValue !== void 0;
@@ -16728,8 +17266,8 @@ var Input = (0, import_react6.forwardRef)(({ value: controlledValue, defaultValu
16728
17266
  const h = inputRef.current;
16729
17267
  if (!h || !placeholder)
16730
17268
  return;
16731
- const buf = textToUtf16(placeholder);
16732
- gui7.SendMessage(h, 5377, 1, ffi5.bufferPtr(buf));
17269
+ const buf = WCHAR.encode(placeholder);
17270
+ gui7.SendMessage(h, 5377, 1, buf.ptr);
16733
17271
  }, [placeholder]);
16734
17272
  return (0, import_jsx_runtime5.jsx)("w", { type: "EDIT", text: displayValue, ws, style, disabled, ref: (h) => {
16735
17273
  inputRef.current = h;
@@ -16753,20 +17291,6 @@ var Input = (0, import_react6.forwardRef)(({ value: controlledValue, defaultValu
16753
17291
  // _build/lib/react-qw/components/Link.js
16754
17292
  var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
16755
17293
  var import_react7 = __toESM(require_react(), 1);
16756
- import * as gui8 from "gui";
16757
- import * as ffi6 from "ffi";
16758
- function readUtf16(ptr, offset, maxWords) {
16759
- const chars = [];
16760
- for (let i = 0; i < maxWords; i++) {
16761
- const lo = ffi6.readByte(ptr + offset + i * 2);
16762
- const hi = ffi6.readByte(ptr + offset + i * 2 + 1);
16763
- const code = hi << 8 | lo;
16764
- if (code === 0)
16765
- break;
16766
- chars.push(String.fromCharCode(code));
16767
- }
16768
- return chars.join("");
16769
- }
16770
17294
  var Link = (0, import_react7.forwardRef)(function Link2({ href, children, onClick, style }, ref) {
16771
17295
  const displayText = children != null ? String(children) : href ?? "";
16772
17296
  const linkText = href ? `<A HREF="${href}">${displayText}</A>` : displayText;
@@ -16777,14 +17301,13 @@ var Link = (0, import_react7.forwardRef)(function Link2({ href, children, onClic
16777
17301
  const h = linkRef.current;
16778
17302
  if (!h)
16779
17303
  return;
16780
- gui8.InvalidateRect(h, null, true);
17304
+ InvalidateRect(h, NULL, 1);
16781
17305
  }, [linkText]);
16782
17306
  return (0, import_jsx_runtime6.jsx)("w", { type: "STATIC", ws: 268435456 | 33554432, style: { ...style, flexDirection: "column", alignItems: "stretch" }, ref, onEvent: (e) => {
16783
17307
  if (e.msg === 78) {
16784
17308
  const code = nmCode(e.lParam);
16785
17309
  if (code === -2 || code === -4) {
16786
- const url = readUtf16(e.lParam, NMHDR_SIZE + 112, 2048);
16787
- onClickRef.current?.(url);
17310
+ onClickRef.current?.(NMLINK.decode(e.lParam).item.szUrl);
16788
17311
  }
16789
17312
  }
16790
17313
  }, children: (0, import_jsx_runtime6.jsx)("w", { type: "SysLink", ws: 268435456 | 65536, text: linkText, style: { flexGrow: 1 }, ref: (h) => {
@@ -16795,7 +17318,7 @@ var Link = (0, import_react7.forwardRef)(function Link2({ href, children, onClic
16795
17318
  // _build/lib/react-qw/components/ListBox.js
16796
17319
  var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
16797
17320
  var import_react8 = __toESM(require_react(), 1);
16798
- import * as gui9 from "gui";
17321
+ import * as gui8 from "gui";
16799
17322
  var ListBox = (0, import_react8.forwardRef)(({ items, selectedIndex: controlledIndex, defaultSelectedIndex = -1, onChange, style, sort, scrollToBottom }, ref) => {
16800
17323
  const [internalIndex, setInternalIndex] = (0, import_react8.useState)(defaultSelectedIndex);
16801
17324
  const isControlled = controlledIndex !== void 0;
@@ -16807,18 +17330,18 @@ var ListBox = (0, import_react8.forwardRef)(({ items, selectedIndex: controlledI
16807
17330
  const h = lbRef.current;
16808
17331
  if (!h)
16809
17332
  return;
16810
- gui9.SendMessage(h, 388, 0, 0);
17333
+ gui8.SendMessage(h, 388, 0, 0);
16811
17334
  for (const item of items)
16812
- gui9.SendMessage(h, 384, 0, item);
17335
+ gui8.SendMessage(h, 384, 0, item);
16813
17336
  if (sel >= 0 && sel < items.length)
16814
- gui9.SendMessage(h, 390, sel, 0);
17337
+ gui8.SendMessage(h, 390, sel, 0);
16815
17338
  if (scrollToBottom && items.length > 0)
16816
- gui9.SendMessage(h, 407, items.length - 1, 0);
17339
+ gui8.SendMessage(h, 407, items.length - 1, 0);
16817
17340
  }, [items]);
16818
17341
  (0, import_react8.useEffect)(() => {
16819
17342
  const h = lbRef.current;
16820
17343
  if (h)
16821
- gui9.SendMessage(h, 390, sel, 0);
17344
+ gui8.SendMessage(h, 390, sel, 0);
16822
17345
  }, [sel]);
16823
17346
  return (0, import_jsx_runtime7.jsx)("w", { type: "STATIC", ws: 268435456 | 33554432, style: { ...style, flexDirection: "column", alignItems: "stretch" }, onEvent: (e) => {
16824
17347
  if (e.msg !== 273)
@@ -16828,7 +17351,7 @@ var ListBox = (0, import_react8.forwardRef)(({ items, selectedIndex: controlledI
16828
17351
  const h = lbRef.current;
16829
17352
  if (!h)
16830
17353
  return;
16831
- const newSel = gui9.SendMessage(h, 392, 0, 0);
17354
+ const newSel = gui8.SendMessage(h, 392, 0, 0);
16832
17355
  if (newSel !== sel && newSel >= 0) {
16833
17356
  if (!isControlled)
16834
17357
  setInternalIndex(newSel);
@@ -16843,138 +17366,18 @@ var ListBox = (0, import_react8.forwardRef)(({ items, selectedIndex: controlledI
16843
17366
  // _build/lib/react-qw/components/ListView.js
16844
17367
  var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1);
16845
17368
  var import_react9 = __toESM(require_react(), 1);
16846
- import * as gui10 from "gui";
16847
- import * as ffi7 from "ffi";
16848
- import * as win2 from "win";
16849
- function textToUtf162(s) {
16850
- const buf = new ArrayBuffer((s.length + 1) * 2);
16851
- const dv = new DataView(buf);
16852
- for (let i = 0; i < s.length; i++)
16853
- dv.setUint16(i * 2, s.charCodeAt(i), true);
16854
- return buf;
16855
- }
16856
- function readI32(ptr, offset) {
16857
- return ffi7.readByte(ptr + offset) | ffi7.readByte(ptr + offset + 1) << 8 | ffi7.readByte(ptr + offset + 2) << 16 | ffi7.readByte(ptr + offset + 3) << 24;
16858
- }
16859
- function readU32(ptr, offset) {
16860
- return ffi7.readByte(ptr + offset) | ffi7.readByte(ptr + offset + 1) << 8 | ffi7.readByte(ptr + offset + 2) << 16 | ffi7.readByte(ptr + offset + 3) << 24 >>> 0;
16861
- }
16862
- function readU64(ptr, offset) {
16863
- const lo = readU32(ptr, offset);
16864
- const hi = readU32(ptr, offset + 4);
16865
- return lo + hi * 4294967296;
16866
- }
17369
+ import * as gui9 from "gui";
17370
+ import * as ffi3 from "ffi";
16867
17371
  function writeU32(ptr, offset, v) {
16868
- ffi7.writeByte(ptr + offset, v & 255);
16869
- ffi7.writeByte(ptr + offset + 1, v >> 8 & 255);
16870
- ffi7.writeByte(ptr + offset + 2, v >> 16 & 255);
16871
- ffi7.writeByte(ptr + offset + 3, v >> 24 & 255);
16872
- }
16873
- function bufPtr2(buf) {
16874
- return ffi7.bufferPtr(buf);
17372
+ ffi3.writeByte(ptr + offset, v & 255);
17373
+ ffi3.writeByte(ptr + offset + 1, v >> 8 & 255);
17374
+ ffi3.writeByte(ptr + offset + 2, v >> 16 & 255);
17375
+ ffi3.writeByte(ptr + offset + 3, v >> 24 & 255);
16875
17376
  }
16876
17377
  var LV_WS = 268435456 | 8388608 | 2097152 | 1048576 | 1 | 4;
16877
- var NMCUSTOMDRAW = struct({
16878
- hdr: NMHDR,
16879
- dwDrawStage: "u32",
16880
- hdc: "ptr",
16881
- rc: "i32[4]",
16882
- dwItemSpec: "ptr",
16883
- uItemState: "u32",
16884
- lItemlParam: "ptr"
16885
- });
16886
- var NMLVCUSTOMDRAW = struct({
16887
- hdr: NMHDR,
16888
- dwDrawStage: "u32",
16889
- hdc: "ptr",
16890
- rc: "i32[4]",
16891
- dwItemSpec: "ptr",
16892
- uItemState: "u32",
16893
- lItemlParam: "ptr",
16894
- clrText: "u32",
16895
- clrTextBk: "u32",
16896
- iSubItem: "i32",
16897
- dwItemType: "u32"
16898
- });
16899
- var NMLISTVIEW = struct({
16900
- hdr: NMHDR,
16901
- iItem: "i32",
16902
- iSubItem: "i32",
16903
- uNewState: "u32",
16904
- uOldState: "u32",
16905
- uChanged: "u32",
16906
- ptAction: "i32[2]",
16907
- lParam: "ptr"
16908
- });
16909
- var CD_STAGE = NMCUSTOMDRAW.offsetOf("dwDrawStage");
16910
- var CD_HDC = NMCUSTOMDRAW.offsetOf("hdc");
16911
- var CD_ITEM = NMCUSTOMDRAW.offsetOf("dwItemSpec");
16912
17378
  var CD_CLRTEXT = NMLVCUSTOMDRAW.offsetOf("clrText");
16913
17379
  var CD_CLRTEXTBK = NMLVCUSTOMDRAW.offsetOf("clrTextBk");
16914
- var CD_SUBITEM = NMLVCUSTOMDRAW.offsetOf("iSubItem");
16915
- var NMIA_ITEM = NMLISTVIEW.offsetOf("iItem");
16916
- var NMIA_SUBITEM = NMLISTVIEW.offsetOf("iSubItem");
16917
- var NMLV_UNEW = NMLISTVIEW.offsetOf("uNewState");
16918
- var NMLV_UOLD = NMLISTVIEW.offsetOf("uOldState");
16919
- var LVITEMW = struct({
16920
- mask: "u32",
16921
- iItem: "i32",
16922
- iSubItem: "i32",
16923
- state: "u32",
16924
- stateMask: "u32",
16925
- pszText: "ptr",
16926
- cchTextMax: "i32",
16927
- iImage: "i32",
16928
- lParam: "ptr",
16929
- iIndent: "i32",
16930
- iGroupId: "i32",
16931
- cColumns: "u32",
16932
- puColumns: "ptr",
16933
- piColFmt: "ptr",
16934
- iGroup: "i32"
16935
- });
16936
- var LVCOLUMNW = struct({
16937
- mask: "u32",
16938
- fmt: "i32",
16939
- cx: "i32",
16940
- pszText: "ptr",
16941
- cchTextMax: "i32",
16942
- iSubItem: "i32",
16943
- iImage: "i32",
16944
- iOrder: "i32",
16945
- cxMin: "i32",
16946
- cxDefault: "i32",
16947
- cxIdeal: "i32"
16948
- });
16949
17380
  var fontCache = /* @__PURE__ */ new Map();
16950
- var gdi322 = null;
16951
- var createFontIndirectW = null;
16952
- var selectObjectFn = null;
16953
- var getObjectW = null;
16954
- function ensureGdi() {
16955
- if (gdi322 !== null)
16956
- return;
16957
- gdi322 = win2.LoadLibrary("gdi32.dll");
16958
- if (!gdi322)
16959
- return;
16960
- createFontIndirectW = win2.GetProcAddress(gdi322, "CreateFontIndirectW");
16961
- selectObjectFn = win2.GetProcAddress(gdi322, "SelectObject");
16962
- getObjectW = win2.GetProcAddress(gdi322, "GetObjectW");
16963
- }
16964
- var user322 = null;
16965
- var loadCursorW = null;
16966
- var setCursorFn = null;
16967
- var screenToClient = null;
16968
- function ensureUser32() {
16969
- if (user322 !== null)
16970
- return;
16971
- user322 = win2.LoadLibrary("user32.dll");
16972
- if (!user322)
16973
- return;
16974
- loadCursorW = win2.GetProcAddress(user322, "LoadCursorW");
16975
- setCursorFn = win2.GetProcAddress(user322, "SetCursor");
16976
- screenToClient = win2.GetProcAddress(user322, "ScreenToClient");
16977
- }
16978
17381
  function getCellFont(hwnd, style) {
16979
17382
  const key = (style.bold ? "b" : "") + (style.italic ? "i" : "") + (style.underline ? "u" : "");
16980
17383
  if (key === "")
@@ -16982,39 +17385,37 @@ function getCellFont(hwnd, style) {
16982
17385
  const cached = fontCache.get(key);
16983
17386
  if (cached !== void 0)
16984
17387
  return cached === 0 ? null : cached;
16985
- ensureGdi();
16986
- if (!createFontIndirectW || !getObjectW || !hwnd)
17388
+ if (!hwnd)
16987
17389
  return null;
16988
- const lf = new ArrayBuffer(92);
16989
- const dv = new DataView(lf);
16990
- const cur = gui10.SendMessage(hwnd, 49, 0, 0);
17390
+ let base = { lfHeight: -13 };
17391
+ const cur = gui9.SendMessage(hwnd, 49, 0, 0);
16991
17392
  if (cur) {
16992
- const got = ffi7.ffiCall(getObjectW, [ffi7.FFI_TYPE_POINTER, ffi7.FFI_TYPE_SINT32, ffi7.FFI_TYPE_POINTER], [cur, 92, lf], ffi7.FFI_TYPE_SINT32);
16993
- if (!got)
17393
+ const lf = LOGFONTW.alloc();
17394
+ if (!GetObject(cur, LOGFONTW.size, lf))
16994
17395
  return null;
16995
- } else {
16996
- dv.setInt32(0, -13, true);
17396
+ base = LOGFONTW.decode(lf);
16997
17397
  }
16998
- if (style.bold)
16999
- dv.setInt32(16, 700, true);
17000
- if (style.italic)
17001
- dv.setUint8(20, 1);
17002
- if (style.underline)
17003
- dv.setUint8(21, 1);
17004
- const h = ffi7.ffiCall(createFontIndirectW, [ffi7.FFI_TYPE_POINTER], [lf], ffi7.FFI_TYPE_POINTER);
17398
+ const h = CreateFontIndirect({
17399
+ ...base,
17400
+ ...style.bold ? {
17401
+ lfWeight: 700
17402
+ /* gui.FontWeight.BOLD */
17403
+ } : {},
17404
+ ...style.italic ? { lfItalic: 1 } : {},
17405
+ ...style.underline ? { lfUnderline: 1 } : {}
17406
+ });
17005
17407
  fontCache.set(key, h ? h : 0);
17006
17408
  return h ? h : null;
17007
17409
  }
17008
17410
  function handleCustomDraw(lParam, columns, data, hwnd) {
17009
- const stage = readU32(lParam, CD_STAGE);
17411
+ const { dwDrawStage: stage } = NMCUSTOMDRAW.decode(lParam);
17010
17412
  if (stage === 1)
17011
17413
  return 32;
17012
17414
  if (stage === 65537)
17013
17415
  return 32;
17014
17416
  if (stage === 196609) {
17015
- const colIndex = readI32(lParam, CD_SUBITEM);
17016
- const row = readI32(lParam, CD_ITEM);
17017
- const style = resolveCellStyle(columns, data, row, colIndex);
17417
+ const cd = NMLVCUSTOMDRAW.decode(lParam);
17418
+ const style = resolveCellStyle(columns, data, cd.dwItemSpec, cd.iSubItem);
17018
17419
  if (!style)
17019
17420
  return 0;
17020
17421
  if (style.color !== void 0)
@@ -17022,12 +17423,9 @@ function handleCustomDraw(lParam, columns, data, hwnd) {
17022
17423
  if (style.background !== void 0)
17023
17424
  writeU32(lParam, CD_CLRTEXTBK, style.background);
17024
17425
  const hfont = getCellFont(hwnd, style);
17025
- if (hfont && selectObjectFn) {
17026
- const hdc = PTR_SIZE === 8 ? readU64(lParam, CD_HDC) : readU32(lParam, CD_HDC);
17027
- if (hdc) {
17028
- ffi7.ffiCall(selectObjectFn, [ffi7.FFI_TYPE_POINTER, ffi7.FFI_TYPE_POINTER], [hdc, hfont], ffi7.FFI_TYPE_POINTER);
17029
- return 2;
17030
- }
17426
+ if (hfont && cd.hdc) {
17427
+ SelectObject(cd.hdc, hfont);
17428
+ return 2;
17031
17429
  }
17032
17430
  }
17033
17431
  return 0;
@@ -17058,14 +17456,14 @@ function resolveCellStyle(columns, data, row, colIndex) {
17058
17456
  return style || void 0;
17059
17457
  }
17060
17458
  function makeLVItem(i, sub, text, image) {
17061
- const textBuf = textToUtf162(text);
17062
- const b = LVITEMW.write({
17459
+ const textBuf = WCHAR.encode(text);
17460
+ const b6 = LVITEMW.encode({
17063
17461
  mask: 1 | (image !== void 0 ? 2 : 0),
17064
17462
  iItem: i,
17065
17463
  iSubItem: sub,
17066
17464
  state: 0,
17067
17465
  stateMask: 0,
17068
- pszText: bufPtr2(textBuf),
17466
+ pszText: textBuf.ptr,
17069
17467
  cchTextMax: 0,
17070
17468
  iImage: image ?? 0,
17071
17469
  lParam: 0,
@@ -17076,8 +17474,8 @@ function makeLVItem(i, sub, text, image) {
17076
17474
  piColFmt: 0,
17077
17475
  iGroup: 0
17078
17476
  });
17079
- b.__textBuf = textBuf;
17080
- return b;
17477
+ b6.__textBuf = textBuf;
17478
+ return b6;
17081
17479
  }
17082
17480
  var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, data, style, icons, iconSize, getIcon }, ref) {
17083
17481
  const lvRef = (0, import_react9.useRef)(null);
@@ -17089,36 +17487,36 @@ var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, d
17089
17487
  const il = iconListRef.current;
17090
17488
  iconListRef.current = 0;
17091
17489
  if (il) {
17092
- gui10.SendMessage(h, 4099, 1, 0);
17093
- gui10.ImageListDestroy(il);
17490
+ gui9.SendMessage(h, 4099, 1, 0);
17491
+ gui9.ImageListDestroy(il);
17094
17492
  }
17095
17493
  if (!icons || icons.length === 0)
17096
17494
  return;
17097
17495
  const size = iconSize ?? 32;
17098
- const img = gui10.ImageListCreate(size, size, 32, icons.length, 1);
17496
+ const img = gui9.ImageListCreate(size, size, 32, icons.length, 1);
17099
17497
  if (!img)
17100
17498
  return;
17101
17499
  for (const p of icons) {
17102
- const hbm = gui10.CreateBitmapFromPixels(size, size, p);
17500
+ const hbm = gui9.CreateBitmapFromPixels(size, size, p);
17103
17501
  if (hbm) {
17104
- gui10.ImageListAdd(img, hbm);
17105
- gui10.DeleteObject(hbm);
17502
+ gui9.ImageListAdd(img, hbm);
17503
+ DeleteObject(hbm);
17106
17504
  }
17107
17505
  }
17108
- gui10.SendMessage(h, 4099, 1, img);
17506
+ gui9.SendMessage(h, 4099, 1, img);
17109
17507
  iconListRef.current = img;
17110
17508
  }, [icons, iconSize]);
17111
17509
  (0, import_react9.useEffect)(() => {
17112
17510
  const h = lvRef.current;
17113
17511
  if (!h)
17114
17512
  return;
17115
- const hdr = gui10.SendMessage(h, 4127, 0, 0);
17513
+ const hdr = gui9.SendMessage(h, 4127, 0, 0);
17116
17514
  if (hdr) {
17117
- let n2 = gui10.SendMessage(hdr, 4608, 0, 0);
17515
+ let n2 = gui9.SendMessage(hdr, 4608, 0, 0);
17118
17516
  for (let k = n2 - 1; k >= 0; k--)
17119
- gui10.SendMessage(h, 4124, k, 0);
17517
+ gui9.SendMessage(h, 4124, k, 0);
17120
17518
  }
17121
- gui10.SendMessage(
17519
+ gui9.SendMessage(
17122
17520
  h,
17123
17521
  4150,
17124
17522
  0,
@@ -17127,12 +17525,12 @@ var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, d
17127
17525
  );
17128
17526
  const n = columns.length;
17129
17527
  for (let j = 0; j < n; j++) {
17130
- const titleBuf = textToUtf162(columns[j].name);
17131
- const lvc = LVCOLUMNW.write({
17528
+ const titleBuf = WCHAR.encode(columns[j].name);
17529
+ const lvc = LVCOLUMNW.encode({
17132
17530
  mask: 4 | 2 | 1,
17133
17531
  fmt: alignToFmt(columns[j].align),
17134
17532
  cx: columns[j].width ?? 100,
17135
- pszText: bufPtr2(titleBuf),
17533
+ pszText: titleBuf.ptr,
17136
17534
  cchTextMax: 0,
17137
17535
  iSubItem: j,
17138
17536
  iImage: 0,
@@ -17142,28 +17540,28 @@ var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, d
17142
17540
  cxIdeal: 0
17143
17541
  });
17144
17542
  lvc.__titleBuf = titleBuf;
17145
- gui10.SendMessage(h, 4193, j, bufPtr2(lvc));
17543
+ gui9.SendMessage(h, 4193, j, lvc.ptr);
17146
17544
  }
17147
17545
  }, [columns]);
17148
17546
  (0, import_react9.useEffect)(() => {
17149
17547
  const h = lvRef.current;
17150
17548
  if (!h)
17151
17549
  return;
17152
- gui10.SendMessage(h, 4105, 0, 0);
17550
+ gui9.SendMessage(h, 4105, 0, 0);
17153
17551
  const nCols = columns.length;
17154
17552
  for (let i = 0; i < data.length; i++) {
17155
17553
  const record = data[i];
17156
17554
  const img = getIcon ? getIcon(record, i) : void 0;
17157
17555
  const itemBuf = makeLVItem(i, 0, cellText(record, columns[0], i), img);
17158
- gui10.SendMessage(h, 4173, 0, bufPtr2(itemBuf));
17556
+ gui9.SendMessage(h, 4173, 0, itemBuf.ptr);
17159
17557
  for (let j = 1; j < nCols; j++) {
17160
17558
  const subBuf = makeLVItem(i, j, cellText(record, columns[j], i));
17161
- gui10.SendMessage(h, 4172, 0, bufPtr2(subBuf));
17559
+ gui9.SendMessage(h, 4172, 0, subBuf.ptr);
17162
17560
  }
17163
17561
  }
17164
17562
  for (let j = 0; j < columns.length; j++) {
17165
17563
  if (columns[j].width == null) {
17166
- gui10.SendMessage(
17564
+ gui9.SendMessage(
17167
17565
  h,
17168
17566
  4126,
17169
17567
  j,
@@ -17180,14 +17578,12 @@ var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, d
17180
17578
  return handleCustomDraw(e.lParam, columns, data, lvRef.current);
17181
17579
  }
17182
17580
  if (code === -100) {
17183
- const uNewState = readU32(e.lParam, NMLV_UNEW);
17184
- const uOldState = readU32(e.lParam, NMLV_UOLD);
17581
+ const { uNewState, uOldState } = NMLISTVIEW.decode(e.lParam);
17185
17582
  if ((uNewState & 2) !== (uOldState & 2))
17186
17583
  return 1;
17187
17584
  }
17188
17585
  if (code === -2) {
17189
- const iItem = readI32(e.lParam, NMIA_ITEM);
17190
- const iSubItem = readI32(e.lParam, NMIA_SUBITEM);
17586
+ const { iItem, iSubItem } = NMLISTVIEW.decode(e.lParam);
17191
17587
  const col = columns[iSubItem];
17192
17588
  const record = data[iItem];
17193
17589
  if (col?.onCellClick && record !== void 0)
@@ -17205,33 +17601,20 @@ var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, d
17205
17601
  const h = lvRef.current;
17206
17602
  if (!h)
17207
17603
  return;
17208
- ensureUser32();
17209
- if (!loadCursorW || !setCursorFn || !screenToClient)
17210
- return;
17211
- const sp = gui10.GetCursorPos();
17212
- if (!sp)
17604
+ const pt = POINT.alloc();
17605
+ if (!GetCursorPos(pt.ptr))
17213
17606
  return;
17214
- const sbuf = new ArrayBuffer(8);
17215
- const sdv = new DataView(sbuf);
17216
- sdv.setInt32(0, sp[0], true);
17217
- sdv.setInt32(4, sp[1], true);
17218
- ffi7.ffiCall(screenToClient, [ffi7.FFI_TYPE_POINTER, ffi7.FFI_TYPE_POINTER], [h, sbuf], ffi7.FFI_TYPE_SINT32);
17219
- const lvhi = new ArrayBuffer(24);
17220
- const lvd = new DataView(lvhi);
17221
- lvd.setInt32(0, sdv.getInt32(0, true), true);
17222
- lvd.setInt32(4, sdv.getInt32(4, true), true);
17223
- lvd.setInt32(12, -1, true);
17224
- lvd.setInt32(16, -1, true);
17225
- const lvhiPtr = bufPtr2(lvhi);
17226
- gui10.SendMessage(h, 4153, 0, lvhiPtr);
17227
- const iItem = readI32(lvhiPtr, 12);
17228
- const iSubItem = readI32(lvhiPtr, 16);
17607
+ ScreenToClient(h, pt.ptr);
17608
+ const { x: sx, y: sy } = POINT.decode(pt);
17609
+ const hit = LVHITTESTINFO.encode({ pt: [sx, sy], iItem: -1, iSubItem: -1 });
17610
+ gui9.SendMessage(h, 4153, 0, hit.ptr);
17611
+ const { iItem, iSubItem } = LVHITTESTINFO.decode(hit);
17229
17612
  const style2 = resolveCellStyle(columns, data, iItem, iSubItem);
17230
17613
  if (!style2 || style2.cursor === void 0)
17231
17614
  return;
17232
- const hc = ffi7.ffiCall(loadCursorW, [ffi7.FFI_TYPE_POINTER, ffi7.FFI_TYPE_POINTER], [0, style2.cursor], ffi7.FFI_TYPE_POINTER);
17615
+ const hc = LoadCursor(NULL, style2.cursor);
17233
17616
  if (hc) {
17234
- ffi7.ffiCall(setCursorFn, [ffi7.FFI_TYPE_POINTER], [hc], ffi7.FFI_TYPE_POINTER);
17617
+ SetCursor(hc);
17235
17618
  return 1;
17236
17619
  }
17237
17620
  return;
@@ -17241,7 +17624,7 @@ var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, d
17241
17624
  // _build/lib/react-qw/components/ProgressBar.js
17242
17625
  var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1);
17243
17626
  var import_react10 = __toESM(require_react(), 1);
17244
- import * as gui11 from "gui";
17627
+ import * as gui10 from "gui";
17245
17628
  var ProgressBar = (0, import_react10.forwardRef)(({ value = 0, max = 100, style, smooth }, ref) => {
17246
17629
  const pbRef = (0, import_react10.useRef)(null);
17247
17630
  const ws = 268435456 | 8388608 | (smooth ? 1 : 0);
@@ -17249,8 +17632,8 @@ var ProgressBar = (0, import_react10.forwardRef)(({ value = 0, max = 100, style,
17249
17632
  const h = pbRef.current;
17250
17633
  if (!h)
17251
17634
  return;
17252
- gui11.SendMessage(h, 1030, 0, max);
17253
- gui11.SendMessage(h, 1026, Math.min(value, max), 0);
17635
+ gui10.SendMessage(h, 1030, 0, max);
17636
+ gui10.SendMessage(h, 1026, Math.min(value, max), 0);
17254
17637
  }, [value, max]);
17255
17638
  return (0, import_jsx_runtime9.jsx)("w", { type: "msctls_progress32", ws, style, ref: (h) => {
17256
17639
  pbRef.current = h;
@@ -17264,7 +17647,7 @@ var ProgressBar = (0, import_react10.forwardRef)(({ value = 0, max = 100, style,
17264
17647
  // _build/lib/react-qw/components/RadioButton.js
17265
17648
  var import_jsx_runtime10 = __toESM(require_jsx_runtime(), 1);
17266
17649
  var import_react11 = __toESM(require_react(), 1);
17267
- import * as gui12 from "gui";
17650
+ import * as gui11 from "gui";
17268
17651
  var RadioButton = (0, import_react11.forwardRef)(({ checked: controlledChecked, defaultChecked = false, onChange, label, style, disabled }, ref) => {
17269
17652
  const [internalChecked, setInternalChecked] = (0, import_react11.useState)(defaultChecked);
17270
17653
  const isControlled = controlledChecked !== void 0;
@@ -17274,7 +17657,7 @@ var RadioButton = (0, import_react11.forwardRef)(({ checked: controlledChecked,
17274
17657
  const h = rbRef.current;
17275
17658
  if (!h)
17276
17659
  return;
17277
- gui12.SendMessage(h, 241, displayChecked ? 1 : 0, 0);
17660
+ gui11.SendMessage(h, 241, displayChecked ? 1 : 0, 0);
17278
17661
  }, [displayChecked]);
17279
17662
  return (0, import_jsx_runtime10.jsx)("w", { type: "BUTTON", text: label ?? "", ws: 268435456 | 9, style, disabled, ref: (h) => {
17280
17663
  rbRef.current = h;
@@ -17284,7 +17667,7 @@ var RadioButton = (0, import_react11.forwardRef)(({ checked: controlledChecked,
17284
17667
  ref.current = h;
17285
17668
  }, onEvent: (e) => {
17286
17669
  if (e.msg === 514) {
17287
- const newChecked = gui12.SendMessage(e.hwnd, 240, 0, 0) !== 0;
17670
+ const newChecked = gui11.SendMessage(e.hwnd, 240, 0, 0) !== 0;
17288
17671
  if (newChecked !== displayChecked) {
17289
17672
  if (!isControlled)
17290
17673
  setInternalChecked(newChecked);
@@ -17297,24 +17680,27 @@ var RadioButton = (0, import_react11.forwardRef)(({ checked: controlledChecked,
17297
17680
  // _build/lib/react-qw/components/ScrollView.js
17298
17681
  var import_jsx_runtime11 = __toESM(require_jsx_runtime(), 1);
17299
17682
  var import_react12 = __toESM(require_react(), 1);
17300
- import * as gui13 from "gui";
17683
+ import * as gui12 from "gui";
17301
17684
  var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth, contentHeight }, ref) => {
17302
17685
  const svRef = (0, import_react12.useRef)(null);
17303
17686
  const contentRef = (0, import_react12.useRef)(null);
17304
17687
  const scrollXRef = (0, import_react12.useRef)(0);
17305
17688
  const scrollYRef = (0, import_react12.useRef)(0);
17306
17689
  function updateScroll(sv, content) {
17307
- const svRect = gui13.GetClientRect(sv);
17690
+ const svRect = gui12.GetClientRect(sv);
17308
17691
  if (!svRect)
17309
17692
  return;
17310
17693
  const svW = svRect.right - svRect.left;
17311
17694
  const svH = svRect.bottom - svRect.top;
17312
- const scale = gui13.GetScaleFactor();
17695
+ const hdc = GetDC(NULL);
17696
+ const scale = hdc ? GetDeviceCaps(hdc, 88) / 96 : 1;
17697
+ if (hdc)
17698
+ ReleaseDC(NULL, hdc);
17313
17699
  const natW = Math.round((contentWidth ?? svW / scale) * scale);
17314
17700
  const natH = Math.round((contentHeight ?? svH / scale) * scale);
17315
17701
  scrollXRef.current = Math.max(0, Math.min(scrollXRef.current, natW - svW));
17316
17702
  scrollYRef.current = Math.max(0, Math.min(scrollYRef.current, natH - svH));
17317
- gui13.SetWindowPos(
17703
+ SetWindowPos(
17318
17704
  content,
17319
17705
  0,
17320
17706
  -scrollXRef.current,
@@ -17326,18 +17712,18 @@ var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth
17326
17712
  );
17327
17713
  forceFlexLayout(content);
17328
17714
  if (natW > svW) {
17329
- gui13.SetScrollInfo(sv, 0, { min: 0, max: natW - 1, page: svW, pos: scrollXRef.current }, true);
17330
- gui13.ShowScrollBar(sv, 0, true);
17715
+ gui12.SetScrollInfo(sv, 0, { min: 0, max: natW - 1, page: svW, pos: scrollXRef.current }, true);
17716
+ ShowScrollBar(sv, 0, 1);
17331
17717
  } else {
17332
17718
  scrollXRef.current = 0;
17333
- gui13.ShowScrollBar(sv, 0, false);
17719
+ ShowScrollBar(sv, 0, 0);
17334
17720
  }
17335
17721
  if (natH > svH) {
17336
- gui13.SetScrollInfo(sv, 1, { min: 0, max: natH - 1, page: svH, pos: scrollYRef.current }, true);
17337
- gui13.ShowScrollBar(sv, 1, true);
17722
+ gui12.SetScrollInfo(sv, 1, { min: 0, max: natH - 1, page: svH, pos: scrollYRef.current }, true);
17723
+ ShowScrollBar(sv, 1, 1);
17338
17724
  } else {
17339
17725
  scrollYRef.current = 0;
17340
- gui13.ShowScrollBar(sv, 1, false);
17726
+ ShowScrollBar(sv, 1, 0);
17341
17727
  }
17342
17728
  }
17343
17729
  (0, import_react12.useLayoutEffect)(() => {
@@ -17353,7 +17739,7 @@ var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth
17353
17739
  } else {
17354
17740
  scrollXRef.current = newPos;
17355
17741
  }
17356
- gui13.SetWindowPos(
17742
+ SetWindowPos(
17357
17743
  content,
17358
17744
  0,
17359
17745
  -scrollXRef.current,
@@ -17363,14 +17749,14 @@ var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth
17363
17749
  1 | 4
17364
17750
  /* gui.SetWindowPosFlag.SWP_NOZORDER */
17365
17751
  );
17366
- gui13.SetScrollInfo(sv, bar, { pos: newPos }, true);
17752
+ gui12.SetScrollInfo(sv, bar, { pos: newPos }, true);
17367
17753
  }
17368
17754
  function handleScroll(e, bar) {
17369
17755
  const sv = svRef.current;
17370
17756
  const content = contentRef.current;
17371
17757
  if (!sv || !content)
17372
17758
  return;
17373
- const info = gui13.GetScrollInfo(sv, bar);
17759
+ const info = gui12.GetScrollInfo(sv, bar);
17374
17760
  const maxPos = info.max - info.page + 1;
17375
17761
  const code = e.wParam & 65535;
17376
17762
  const ref_ = bar === 1 ? scrollYRef : scrollXRef;
@@ -17404,7 +17790,7 @@ var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth
17404
17790
  if (!isHorz && contentHeight === void 0)
17405
17791
  return;
17406
17792
  const bar = isHorz ? 0 : 1;
17407
- const info = gui13.GetScrollInfo(sv, bar);
17793
+ const info = gui12.GetScrollInfo(sv, bar);
17408
17794
  const maxPos = info.max - info.page + 1;
17409
17795
  const ref_ = isHorz ? scrollXRef : scrollYRef;
17410
17796
  let newPos = ref_.current + dy;
@@ -17421,7 +17807,7 @@ var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth
17421
17807
  }, onEvent: {
17422
17808
  fn: (e) => {
17423
17809
  if (e.msg === 132 || e.msg === 161) {
17424
- return gui13.DefWindowProc(e.hwnd, e.msg, e.wParam, e.lParam);
17810
+ return DefWindowProc(e.hwnd, e.msg, e.wParam, e.lParam);
17425
17811
  }
17426
17812
  if (e.msg === 277) {
17427
17813
  handleScroll(
@@ -17453,7 +17839,7 @@ var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth
17453
17839
  // _build/lib/react-qw/components/Slider.js
17454
17840
  var import_jsx_runtime12 = __toESM(require_jsx_runtime(), 1);
17455
17841
  var import_react13 = __toESM(require_react(), 1);
17456
- import * as gui14 from "gui";
17842
+ import * as gui13 from "gui";
17457
17843
  var Slider = (0, import_react13.forwardRef)(({ value, onChange, min = 0, max = 100, vertical = false, disabled, style }, ref) => {
17458
17844
  const wrapperRef = (0, import_react13.useRef)(null);
17459
17845
  const sliderRef = (0, import_react13.useRef)(null);
@@ -17462,14 +17848,14 @@ var Slider = (0, import_react13.forwardRef)(({ value, onChange, min = 0, max = 1
17462
17848
  if (!h)
17463
17849
  return;
17464
17850
  const lParam = min & 65535 | (max & 65535) << 16;
17465
- gui14.SendMessage(h, 1030, 0, lParam);
17466
- gui14.SendMessage(h, 1029, 1, value);
17851
+ gui13.SendMessage(h, 1030, 0, lParam);
17852
+ gui13.SendMessage(h, 1029, 1, value);
17467
17853
  }, [min, max]);
17468
17854
  (0, import_react13.useEffect)(() => {
17469
17855
  const h = sliderRef.current;
17470
17856
  if (!h)
17471
17857
  return;
17472
- gui14.SendMessage(h, 1029, 1, value);
17858
+ gui13.SendMessage(h, 1029, 1, value);
17473
17859
  }, [value]);
17474
17860
  const tbStyle = 268435456 | 65536 | 1 | (vertical ? 2 : 0);
17475
17861
  return (0, import_jsx_runtime12.jsx)("w", { type: "STATIC", ws: 268435456 | 33554432, style, ref: (h) => {
@@ -17480,13 +17866,13 @@ var Slider = (0, import_react13.forwardRef)(({ value, onChange, min = 0, max = 1
17480
17866
  ref.current = h;
17481
17867
  }, onEvent: (e) => {
17482
17868
  if (e.msg === 132 || e.msg === 161) {
17483
- return gui14.DefWindowProc(e.hwnd, e.msg, e.wParam, e.lParam);
17869
+ return DefWindowProc(e.hwnd, e.msg, e.wParam, e.lParam);
17484
17870
  }
17485
17871
  if (e.msg === 276 || e.msg === 277) {
17486
17872
  const h = sliderRef.current;
17487
17873
  if (!h)
17488
17874
  return 0;
17489
- const pos = gui14.SendMessage(h, 1024, 0, 0);
17875
+ const pos = gui13.SendMessage(h, 1024, 0, 0);
17490
17876
  onChange?.(pos);
17491
17877
  return 0;
17492
17878
  }
@@ -17499,24 +17885,7 @@ var Slider = (0, import_react13.forwardRef)(({ value, onChange, min = 0, max = 1
17499
17885
  // _build/lib/react-qw/components/Tab.js
17500
17886
  var import_jsx_runtime13 = __toESM(require_jsx_runtime(), 1);
17501
17887
  var import_react14 = __toESM(require_react(), 1);
17502
- import * as gui15 from "gui";
17503
- import * as ffi8 from "ffi";
17504
- var TCITEMW = struct({
17505
- mask: "u32",
17506
- dwState: "u32",
17507
- dwStateMask: "u32",
17508
- pszText: "ptr",
17509
- cchTextMax: "i32",
17510
- iImage: "i32",
17511
- lParam: "ptr"
17512
- });
17513
- function textToUtf163(s) {
17514
- const buf = new ArrayBuffer((s.length + 1) * 2);
17515
- const dv = new DataView(buf);
17516
- for (let i = 0; i < s.length; i++)
17517
- dv.setUint16(i * 2, s.charCodeAt(i), true);
17518
- return buf;
17519
- }
17888
+ import * as gui14 from "gui";
17520
17889
  var Tab = (0, import_react14.forwardRef)(({ tabs, selectedIndex: controlledIndex, defaultSelectedIndex = 0, onChange, style }, ref) => {
17521
17890
  const [internalIndex, setInternalIndex] = (0, import_react14.useState)(defaultSelectedIndex);
17522
17891
  const isControlled = controlledIndex !== void 0;
@@ -17526,27 +17895,27 @@ var Tab = (0, import_react14.forwardRef)(({ tabs, selectedIndex: controlledIndex
17526
17895
  const h = tabHwnd.current;
17527
17896
  if (!h)
17528
17897
  return;
17529
- gui15.SendMessage(h, 4873, 0, 0);
17898
+ gui14.SendMessage(h, 4873, 0, 0);
17530
17899
  for (let i = 0; i < tabs.length; i++) {
17531
- const titleBuf = textToUtf163(tabs[i].title);
17532
- const tci = TCITEMW.write({
17900
+ const titleBuf = WCHAR.encode(tabs[i].title);
17901
+ const tci = TCITEMW.encode({
17533
17902
  mask: 1,
17534
17903
  dwState: 0,
17535
17904
  dwStateMask: 0,
17536
- pszText: ffi8.bufferPtr(titleBuf),
17905
+ pszText: titleBuf.ptr,
17537
17906
  cchTextMax: tabs[i].title.length + 1,
17538
17907
  iImage: 0,
17539
17908
  lParam: 0
17540
17909
  });
17541
- const tciPtr = ffi8.bufferPtr(tci);
17542
- gui15.SendMessage(h, 4926, i, tciPtr);
17910
+ const tciPtr = tci.ptr;
17911
+ gui14.SendMessage(h, 4926, i, tciPtr);
17543
17912
  }
17544
- gui15.SendMessage(h, 4876, sel, 0);
17913
+ gui14.SendMessage(h, 4876, sel, 0);
17545
17914
  }, [tabs]);
17546
17915
  (0, import_react14.useEffect)(() => {
17547
17916
  const h = tabHwnd.current;
17548
17917
  if (h)
17549
- gui15.SendMessage(h, 4876, sel, 0);
17918
+ gui14.SendMessage(h, 4876, sel, 0);
17550
17919
  }, [sel]);
17551
17920
  return (0, import_jsx_runtime13.jsxs)("w", { type: "STATIC", ws: 268435456 | 33554432, style: { ...style, flexDirection: "column", alignItems: "stretch" }, ref, onEvent: (e) => {
17552
17921
  if (e.msg === 78) {
@@ -17555,7 +17924,7 @@ var Tab = (0, import_react14.forwardRef)(({ tabs, selectedIndex: controlledIndex
17555
17924
  return;
17556
17925
  const code = nmCode(e.lParam);
17557
17926
  if (code === -552 || code === -2) {
17558
- const newSel = gui15.SendMessage(h, 4875, 0, 0);
17927
+ const newSel = gui14.SendMessage(h, 4875, 0, 0);
17559
17928
  if (newSel !== sel) {
17560
17929
  if (!isControlled)
17561
17930
  setInternalIndex(newSel);
@@ -17568,54 +17937,17 @@ var Tab = (0, import_react14.forwardRef)(({ tabs, selectedIndex: controlledIndex
17568
17937
 
17569
17938
  // _build/lib/react-qw/components/Tooltip.js
17570
17939
  var import_react15 = __toESM(require_react(), 1);
17571
- import * as gui16 from "gui";
17572
- import * as ffi9 from "ffi";
17573
- var TTTOOLINFOW = struct({
17574
- cbSize: "u32",
17575
- uFlags: "u32",
17576
- hwnd: "ptr",
17577
- uId: "ptr",
17578
- rect: "i32[4]",
17579
- hinst: "ptr",
17580
- lpszText: "ptr",
17581
- lParam: "ptr",
17582
- lpReserved: "ptr"
17583
- // WinXP+ 追加字段(系统 sizeof 含之)
17584
- });
17940
+ import * as gui15 from "gui";
17585
17941
 
17586
17942
  // _build/lib/react-qw/components/TreeView.js
17587
17943
  var import_jsx_runtime14 = __toESM(require_jsx_runtime(), 1);
17588
17944
  var import_react16 = __toESM(require_react(), 1);
17589
- import * as gui17 from "gui";
17590
- import * as ffi10 from "ffi";
17591
- var TVITEM = struct({
17592
- mask: "u32",
17593
- hItem: "ptr",
17594
- state: "u32",
17595
- stateMask: "u32",
17596
- pszText: "ptr",
17597
- cchTextMax: "i32",
17598
- iImage: "i32",
17599
- iSelectedImage: "i32",
17600
- cChildren: "i32",
17601
- lParam: "ptr"
17602
- });
17603
- var TVINSERTSTRUCT = struct({ hParent: "ptr", hInsertAfter: "ptr", item: TVITEM });
17604
- function textToUtf164(s) {
17605
- const buf = new ArrayBuffer((s.length + 1) * 2);
17606
- const dv = new DataView(buf);
17607
- for (let i = 0; i < s.length; i++)
17608
- dv.setUint16(i * 2, s.charCodeAt(i), true);
17609
- return buf;
17610
- }
17611
- function bufPtr3(buf) {
17612
- return ffi10.bufferPtr(buf);
17613
- }
17945
+ import * as gui16 from "gui";
17614
17946
  function buildTvItem(textPtr, cChildren) {
17615
17947
  let mask = 1;
17616
17948
  if (cChildren > 0)
17617
17949
  mask |= 64;
17618
- return TVITEM.write({
17950
+ return TVITEM.encode({
17619
17951
  mask,
17620
17952
  hItem: 0,
17621
17953
  state: 0,
@@ -17631,24 +17963,24 @@ function buildTvItem(textPtr, cChildren) {
17631
17963
  function insertItems(hTree, nodes, parentHandle, hItemMap, keyMap) {
17632
17964
  for (const node of nodes) {
17633
17965
  const cChildren = node.children && node.children.length > 0 ? 1 : 0;
17634
- const textBuf = textToUtf164(node.label);
17635
- const itemBuf = buildTvItem(bufPtr3(textBuf), cChildren);
17636
- const item = TVITEM.read(itemBuf);
17637
- const tvins = TVINSERTSTRUCT.write({ hParent: parentHandle, hInsertAfter: -65536, item });
17638
- const hItem = gui17.SendMessage(hTree, 4402, 0, bufPtr3(tvins));
17966
+ const textBuf = WCHAR.encode(node.label);
17967
+ const itemBuf = buildTvItem(textBuf.ptr, cChildren);
17968
+ const item = TVITEM.decode(itemBuf);
17969
+ const tvins = TVINSERTSTRUCT.encode({ hParent: parentHandle, hInsertAfter: -65536, item });
17970
+ const hItem = gui16.SendMessage(hTree, 4402, 0, tvins.ptr);
17639
17971
  hItemMap.set(hItem, node);
17640
17972
  if (node.key)
17641
17973
  keyMap.set(node.key, hItem);
17642
17974
  if (node.children && node.children.length > 0) {
17643
17975
  insertItems(hTree, node.children, hItem, hItemMap, keyMap);
17644
- gui17.SendMessage(hTree, 4354, 2, hItem);
17976
+ gui16.SendMessage(hTree, 4354, 2, hItem);
17645
17977
  }
17646
17978
  }
17647
17979
  }
17648
17980
  function deleteAllItems(hTree) {
17649
- const n = gui17.SendMessage(hTree, 4357, 0, 0);
17981
+ const n = gui16.SendMessage(hTree, 4357, 0, 0);
17650
17982
  if (n > 0)
17651
- gui17.SendMessage(
17983
+ gui16.SendMessage(
17652
17984
  hTree,
17653
17985
  4353,
17654
17986
  1,
@@ -17680,7 +18012,7 @@ var TreeView = (0, import_react16.forwardRef)(function TreeViewInner({ data, onS
17680
18012
  const h = tvRef.current;
17681
18013
  if (!h)
17682
18014
  return;
17683
- gui17.SendMessage(
18015
+ gui16.SendMessage(
17684
18016
  h,
17685
18017
  4396,
17686
18018
  0,
@@ -17696,7 +18028,7 @@ var TreeView = (0, import_react16.forwardRef)(function TreeViewInner({ data, onS
17696
18028
  return;
17697
18029
  const hItem = keyMapRef.current.get(selKey);
17698
18030
  if (hItem !== void 0)
17699
- gui17.SendMessage(h, 4363, 9, hItem);
18031
+ gui16.SendMessage(h, 4363, 9, hItem);
17700
18032
  }, [selKey]);
17701
18033
  return (0, import_jsx_runtime14.jsx)("w", { type: "STATIC", ws: 268435456 | 33554432, style: { ...style, flexDirection: "column", alignItems: "stretch" }, ref, onEvent: (e) => {
17702
18034
  if (e.msg === 78) {
@@ -17705,7 +18037,7 @@ var TreeView = (0, import_react16.forwardRef)(function TreeViewInner({ data, onS
17705
18037
  const h = tvRef.current;
17706
18038
  if (!h)
17707
18039
  return;
17708
- const hCaret = gui17.SendMessage(h, 4362, 9, 0);
18040
+ const hCaret = gui16.SendMessage(h, 4362, 9, 0);
17709
18041
  const node = hItemMapRef.current.get(hCaret) ?? null;
17710
18042
  const key = node?.key ?? null;
17711
18043
  if (!isControlled)
@@ -17721,153 +18053,63 @@ var TreeView = (0, import_react16.forwardRef)(function TreeViewInner({ data, onS
17721
18053
  // _build/lib/react-qw/components/PathPicker.js
17722
18054
  var import_jsx_runtime15 = __toESM(require_jsx_runtime(), 1);
17723
18055
  var import_react17 = __toESM(require_react(), 1);
17724
- import * as ffi11 from "ffi";
17725
- import * as win3 from "win";
17726
18056
 
17727
- // _build/lib/win-common-structs.js
17728
- var OPENFILENAMEW = struct({
17729
- lStructSize: "u32",
17730
- hwndOwner: "ptr",
17731
- hInstance: "ptr",
17732
- lpstrFilter: "ptr",
17733
- lpstrCustomFilter: "ptr",
17734
- nMaxCustFilter: "u32",
17735
- nFilterIndex: "u32",
17736
- lpstrFile: "ptr",
17737
- nMaxFile: "u32",
17738
- lpstrFileTitle: "ptr",
17739
- nMaxFileTitle: "u32",
17740
- lpstrInitialDir: "ptr",
17741
- lpstrTitle: "ptr",
17742
- Flags: "u32",
17743
- nFileOffset: "u16",
17744
- nFileExtension: "u16",
17745
- lpstrDefExt: "ptr",
17746
- lCustData: "ptr",
17747
- lpfnHook: "ptr",
17748
- lpTemplateName: "ptr",
17749
- pvReserved: "ptr",
17750
- dwReserved: "u32",
17751
- FlagsEx: "u32"
17752
- });
17753
- var BROWSEINFOW = struct({
17754
- hwndOwner: "ptr",
17755
- pidlRoot: "ptr",
17756
- pszDisplayName: "ptr",
17757
- lpszTitle: "ptr",
17758
- ulFlags: "u32",
17759
- lpfn: "ptr",
17760
- lParam: "ptr",
17761
- iImage: "i32"
17762
- });
18057
+ // _build/lib/windows/comdlg32.js
18058
+ var b3 = (name, sig) => bind("comdlg32.dll", name, sig);
18059
+ var GetOpenFileName = /* @__PURE__ */ b3("GetOpenFileNameW", "<BYTE>ptr -> u32");
18060
+
18061
+ // _build/lib/windows/shell32.js
18062
+ var b4 = (name, sig) => bind("shell32.dll", name, sig);
18063
+ var SHBrowseForFolder = /* @__PURE__ */ b4("SHBrowseForFolderW", "<BYTE>ptr -> <>ptr");
18064
+ var SHGetPathFromIDList = /* @__PURE__ */ b4("SHGetPathFromIDListW", "<>ptr <BYTE>ptr -> u32");
18065
+
18066
+ // _build/lib/windows/ole32.js
18067
+ var b5 = (name, sig) => bind("ole32.dll", name, sig);
18068
+ var CoTaskMemFree = /* @__PURE__ */ b5("CoTaskMemFree", "<>ptr -> void");
17763
18069
 
17764
18070
  // _build/lib/react-qw/components/PathPicker.js
17765
- var FFI_PTR = ffi11.FFI_TYPE_POINTER;
17766
- var FFI_U32 = ffi11.FFI_TYPE_UINT32;
17767
- var _GetOpenFileNameW = 0;
17768
- var _SHBrowseForFolderW = 0;
17769
- var _SHGetPathFromIDListW = 0;
17770
- var _CoTaskMemFree = 0;
17771
- function ensureDlls() {
17772
- if (_GetOpenFileNameW)
17773
- return true;
17774
- const comdlg32 = win3.LoadLibrary("comdlg32.dll");
17775
- const shell32 = win3.LoadLibrary("shell32.dll");
17776
- const ole32 = win3.LoadLibrary("ole32.dll");
17777
- if (!comdlg32 || !shell32 || !ole32)
17778
- return false;
17779
- const load = (lib, name) => win3.GetProcAddress(lib, name) || 0;
17780
- _GetOpenFileNameW = load(comdlg32, "GetOpenFileNameW");
17781
- _SHBrowseForFolderW = load(shell32, "SHBrowseForFolderW");
17782
- _SHGetPathFromIDListW = load(shell32, "SHGetPathFromIDListW");
17783
- _CoTaskMemFree = load(ole32, "CoTaskMemFree");
17784
- return !!_GetOpenFileNameW && !!_SHBrowseForFolderW && !!_SHGetPathFromIDListW && !!_CoTaskMemFree;
17785
- }
17786
- function strToWide(s) {
17787
- return new TextEncoder("utf-16le").encode(s + "\0").buffer;
17788
- }
17789
- var _decoder = new TextDecoder("utf-16le");
17790
- function wideToStr(buf, offset = 0) {
17791
- const str = _decoder.decode(new Uint8Array(buf, offset));
17792
- const nullIdx = str.indexOf("\0");
17793
- return nullIdx >= 0 ? str.substring(0, nullIdx) : str;
17794
- }
17795
18071
  function openFileDialog(owner, filter, title, multiple) {
17796
- if (!ensureDlls())
17797
- return null;
17798
- const fileBuf = new ArrayBuffer(260 * 2);
17799
- const filterWide = strToWide(filter);
17800
- const titleWide = title ? strToWide(title) : null;
18072
+ const fileBuf = WCHAR.alloc(260);
18073
+ const filterWide = WCHAR.encode(filter);
18074
+ const titleWide = title ? WCHAR.encode(title) : null;
17801
18075
  let flags = 4096 | 2048 | 8;
17802
18076
  if (multiple)
17803
18077
  flags |= 512;
17804
18078
  flags |= 524288;
17805
- const ofn = OPENFILENAMEW.write({
18079
+ const ofn = OPENFILENAMEW.encode({
17806
18080
  lStructSize: OPENFILENAMEW.size,
17807
18081
  hwndOwner: owner,
17808
- hInstance: 0,
17809
- lpstrFilter: ffi11.bufferPtr(filterWide),
17810
- lpstrCustomFilter: 0,
17811
- nMaxCustFilter: 0,
17812
- nFilterIndex: 0,
17813
- lpstrFile: ffi11.bufferPtr(fileBuf),
18082
+ lpstrFilter: filterWide.ptr,
18083
+ lpstrFile: fileBuf.ptr,
17814
18084
  nMaxFile: 260,
17815
- lpstrFileTitle: 0,
17816
- nMaxFileTitle: 0,
17817
- lpstrInitialDir: 0,
17818
- lpstrTitle: titleWide ? ffi11.bufferPtr(titleWide) : 0,
17819
- Flags: flags,
17820
- nFileOffset: 0,
17821
- nFileExtension: 0,
17822
- lpstrDefExt: 0,
17823
- lCustData: 0,
17824
- lpfnHook: 0,
17825
- lpTemplateName: 0,
17826
- pvReserved: 0,
17827
- dwReserved: 0,
17828
- FlagsEx: 0
18085
+ lpstrTitle: titleWide?.ptr ?? 0,
18086
+ Flags: flags
17829
18087
  });
17830
- const ret = ffi11.ffiCall(_GetOpenFileNameW, [FFI_PTR], [ofn], FFI_U32);
18088
+ const ret = GetOpenFileName(ofn);
17831
18089
  if (!ret)
17832
18090
  return null;
17833
18091
  if (!multiple) {
17834
- return wideToStr(fileBuf);
18092
+ return WCHAR.decode(fileBuf);
17835
18093
  }
17836
- const dir = wideToStr(fileBuf);
17837
- let pos = (dir.length + 1) * 2;
17838
- const files = [];
17839
- while (pos < fileBuf.byteLength) {
17840
- const f = wideToStr(fileBuf, pos);
17841
- if (f.length === 0)
17842
- break;
17843
- files.push(dir + "\\" + f);
17844
- pos += (f.length + 1) * 2;
17845
- }
17846
- if (files.length === 0)
17847
- return [dir];
17848
- return files;
18094
+ const strs = new TextDecoder("utf-16le").decode(new Uint8Array(fileBuf)).split("\0");
18095
+ const dir = strs[0] ?? "";
18096
+ const files = strs.slice(1).filter((f) => f.length > 0).map((f) => dir + "\\" + f);
18097
+ return files.length > 0 ? files : [dir];
17849
18098
  }
17850
18099
  function openFolderDialog(owner, title) {
17851
- if (!ensureDlls())
17852
- return null;
17853
- const titleWide = title ? strToWide(title) : null;
17854
- const bi = BROWSEINFOW.write({
18100
+ const titleWide = title ? WCHAR.encode(title) : null;
18101
+ const bi = BROWSEINFOW.encode({
17855
18102
  hwndOwner: owner,
17856
- pidlRoot: 0,
17857
- pszDisplayName: 0,
17858
- lpszTitle: titleWide ? ffi11.bufferPtr(titleWide) : 0,
17859
- ulFlags: 65,
17860
- lpfn: 0,
17861
- lParam: 0,
17862
- iImage: 0
18103
+ lpszTitle: titleWide?.ptr ?? 0,
18104
+ ulFlags: 65
17863
18105
  });
17864
- const pidl = ffi11.ffiCall(_SHBrowseForFolderW, [FFI_PTR], [bi], FFI_PTR);
18106
+ const pidl = SHBrowseForFolder(bi);
17865
18107
  if (!pidl)
17866
18108
  return null;
17867
- const pathBuf = new ArrayBuffer(260 * 2);
17868
- const ok = ffi11.ffiCall(_SHGetPathFromIDListW, [ffi11.FFI_TYPE_POINTER, FFI_PTR], [pidl, pathBuf], FFI_U32);
17869
- ffi11.ffiCall(_CoTaskMemFree, [ffi11.FFI_TYPE_POINTER], [pidl], ffi11.FFI_TYPE_VOID);
17870
- return ok ? wideToStr(pathBuf) : null;
18109
+ const pathBuf = WCHAR.alloc(260);
18110
+ const ok = SHGetPathFromIDList(pidl, pathBuf);
18111
+ CoTaskMemFree(pidl);
18112
+ return ok ? WCHAR.decode(pathBuf) : null;
17871
18113
  }
17872
18114
  var PathPicker = (0, import_react17.forwardRef)((props, ref) => {
17873
18115
  const { type = "file", filter = "All Files\0*.*\0\0", title, disabled, style } = props;
@@ -17918,7 +18160,7 @@ var rootMap = /* @__PURE__ */ new Map();
17918
18160
  function ensureDefaultClass() {
17919
18161
  if (defaultClassRegistered)
17920
18162
  return DEFAULT_CLASS;
17921
- gui18.RegisterClass(DEFAULT_CLASS, (hwnd, msg, wParam, lParam) => {
18163
+ gui17.RegisterClass(DEFAULT_CLASS, (hwnd, msg, wParam, lParam) => {
17922
18164
  const entry = rootMap.get(hwnd);
17923
18165
  if (msg === 2 && entry) {
17924
18166
  rootMap.delete(hwnd);
@@ -17931,7 +18173,7 @@ function ensureDefaultClass() {
17931
18173
  return result;
17932
18174
  if (msg === 5)
17933
18175
  forceFlexLayout(hwnd);
17934
- return gui18.DefWindowProc(hwnd, msg, wParam, lParam);
18176
+ return DefWindowProc(hwnd, msg, wParam, lParam);
17935
18177
  });
17936
18178
  defaultClassRegistered = true;
17937
18179
  return DEFAULT_CLASS;
@@ -17944,15 +18186,15 @@ function createRoot(container) {
17944
18186
  const ws = (cfg.ws ?? 0) | 13565952;
17945
18187
  const w = (cfg.width ?? 800) * scaleFactor;
17946
18188
  const h = (cfg.height ?? 600) * scaleFactor;
17947
- const [sw, sh] = gui18.GetScreenSize();
18189
+ const [sw, sh] = [GetSystemMetrics(0), GetSystemMetrics(1)];
17948
18190
  const x = cfg.x === void 0 ? (sw - w) / 2 | 0 : cfg.x === -2147483648 ? -2147483648 : cfg.x * scaleFactor;
17949
18191
  const y = cfg.y === void 0 ? (sh - h) / 2 | 0 : cfg.y === -2147483648 ? -2147483648 : cfg.y * scaleFactor;
17950
- const hwin = gui18.CreateWindow(className, cfg.text || "", ws, x, y, w, h, null, null);
18192
+ const hwin = gui17.CreateWindow(className, cfg.text || "", ws, x, y, w, h, null, null);
17951
18193
  if (!hwin)
17952
18194
  throw new Error("CreateWindow failed");
17953
18195
  hwnd = hwin;
17954
18196
  if (!cfg.noShowWindow)
17955
- gui18.ShowWindow(hwnd);
18197
+ gui17.ShowWindow(hwnd);
17956
18198
  } else {
17957
18199
  hwnd = container;
17958
18200
  }
@@ -17982,33 +18224,8 @@ function render(element, containerOrConfig, _callback) {
17982
18224
  // _build/examples/PdfCanvas.js
17983
18225
  var import_jsx_runtime16 = __toESM(require_jsx_runtime(), 1);
17984
18226
  var import_react18 = __toESM(require_react(), 1);
17985
- import * as win4 from "win";
17986
- import * as ffi12 from "ffi";
17987
- var _user32 = win4.LoadLibrary("user32.dll");
17988
- var _gdi32 = win4.LoadLibrary("gdi32.dll");
17989
- if (!_user32 || !_gdi32)
17990
- throw new Error("Failed to load user32/gdi32");
17991
- function loadProc(lib, name) {
17992
- const ptr = win4.GetProcAddress(lib, name);
17993
- if (!ptr)
17994
- throw new Error("Failed to load " + name);
17995
- return ptr;
17996
- }
17997
- var GetDC_ = loadProc(_user32, "GetDC");
17998
- var ReleaseDC_ = loadProc(_user32, "ReleaseDC");
17999
- var SetDIBitsToDevice_ = loadProc(_gdi32, "SetDIBitsToDevice");
18000
- var FFI_PTR2 = ffi12.FFI_TYPE_POINTER;
18001
- var FFI_U322 = ffi12.FFI_TYPE_UINT32;
18002
- var FFI_S32 = ffi12.FFI_TYPE_SINT32;
18003
18227
  function makeBitmapInfo(w, h) {
18004
- const bmi = new ArrayBuffer(40);
18005
- const bv = new DataView(bmi);
18006
- bv.setUint32(0, 40, true);
18007
- bv.setInt32(4, w, true);
18008
- bv.setInt32(8, -h, true);
18009
- bv.setUint16(12, 1, true);
18010
- bv.setUint16(14, 24, true);
18011
- return bmi;
18228
+ return BITMAPINFOHEADER.encode({ biSize: BITMAPINFOHEADER.size, biWidth: w, biHeight: -h, biPlanes: 1, biBitCount: 24 });
18012
18229
  }
18013
18230
  var PdfCanvas = (0, import_react18.forwardRef)(({ pixmap, style }, ref) => {
18014
18231
  const canvasRef = (0, import_react18.useRef)(null);
@@ -18028,37 +18245,11 @@ var PdfCanvas = (0, import_react18.forwardRef)(({ pixmap, style }, ref) => {
18028
18245
  const pm = pixmapRef.current;
18029
18246
  if (!pm)
18030
18247
  return 0;
18031
- const hdc = ffi12.ffiCall(GetDC_, [ffi12.FFI_TYPE_POINTER], [hwnd], ffi12.FFI_TYPE_POINTER);
18248
+ const hdc = GetDC(hwnd);
18032
18249
  if (hdc) {
18033
18250
  const bmi = makeBitmapInfo(pm.w, pm.h);
18034
- ffi12.ffiCall(SetDIBitsToDevice_, [
18035
- ffi12.FFI_TYPE_POINTER,
18036
- FFI_S32,
18037
- FFI_S32,
18038
- FFI_U322,
18039
- FFI_U322,
18040
- FFI_S32,
18041
- FFI_S32,
18042
- FFI_U322,
18043
- FFI_U322,
18044
- FFI_PTR2,
18045
- FFI_PTR2,
18046
- FFI_U322
18047
- ], [
18048
- hdc,
18049
- 0,
18050
- 0,
18051
- pm.w,
18052
- pm.h,
18053
- 0,
18054
- 0,
18055
- 0,
18056
- pm.h,
18057
- pm.data,
18058
- bmi,
18059
- 0
18060
- ], FFI_S32);
18061
- ffi12.ffiCall(ReleaseDC_, [ffi12.FFI_TYPE_POINTER, ffi12.FFI_TYPE_POINTER], [hwnd, hdc], FFI_S32);
18251
+ SetDIBitsToDevice(hdc, 0, 0, pm.w, pm.h, 0, 0, 0, pm.h, pm.data, bmi, 0);
18252
+ ReleaseDC(hwnd, hdc);
18062
18253
  }
18063
18254
  return 0;
18064
18255
  }
@@ -18067,80 +18258,29 @@ var PdfCanvas = (0, import_react18.forwardRef)(({ pixmap, style }, ref) => {
18067
18258
  });
18068
18259
 
18069
18260
  // _build/examples/pdf_viewer.js
18070
- var _user322 = win5.LoadLibrary("user32.dll");
18071
- var _gdi322 = win5.LoadLibrary("gdi32.dll");
18072
- var _comdlg32 = win5.LoadLibrary("comdlg32.dll");
18073
- if (!_user322 || !_gdi322 || !_comdlg32) {
18074
- gui19.MessageBox("Failed to load system libraries");
18075
- std.exit(0);
18076
- }
18077
- function loadProc2(lib, name) {
18078
- const ptr = win5.GetProcAddress(lib, name);
18079
- if (!ptr)
18080
- throw new Error("Failed to load " + name);
18081
- return ptr;
18082
- }
18083
- var GetOpenFileNameW_ = loadProc2(_comdlg32, "GetOpenFileNameW");
18084
- var FFI_PTR3 = ffi13.FFI_TYPE_POINTER;
18085
- var FFI_U323 = ffi13.FFI_TYPE_UINT32;
18086
- function strToWide2(str) {
18087
- const buf = new ArrayBuffer((str.length + 1) * 2);
18088
- const dv = new DataView(buf);
18089
- for (let i = 0; i < str.length; i++)
18090
- dv.setUint16(i * 2, str.charCodeAt(i), true);
18091
- return buf;
18092
- }
18093
- function wideToStr2(buf) {
18094
- const dv = new DataView(buf);
18095
- const chars = [];
18096
- for (let i = 0; i < buf.byteLength; i += 2) {
18097
- const c = dv.getUint16(i, true);
18098
- if (c === 0)
18099
- break;
18100
- chars.push(c);
18101
- }
18102
- return String.fromCharCode(...chars);
18103
- }
18104
18261
  function openPdfFileDialog(owner) {
18105
- const fileBuf = new ArrayBuffer(260 * 2);
18106
- const filterWide = strToWide2("PDF Files\0*.pdf\0All Files\0*.*\0\0");
18107
- const ofn = OPENFILENAMEW.write({
18262
+ const fileBuf = WCHAR.alloc(260);
18263
+ const filterWide = WCHAR.encode("PDF Files\0*.pdf\0All Files\0*.*\0\0");
18264
+ const ofn = OPENFILENAMEW.encode({
18108
18265
  lStructSize: OPENFILENAMEW.size,
18109
18266
  hwndOwner: owner,
18110
- hInstance: 0,
18111
- lpstrFilter: ffi13.bufferPtr(filterWide),
18112
- lpstrCustomFilter: 0,
18113
- nMaxCustFilter: 0,
18114
- nFilterIndex: 0,
18115
- lpstrFile: ffi13.bufferPtr(fileBuf),
18267
+ lpstrFilter: filterWide.ptr,
18268
+ lpstrFile: fileBuf.ptr,
18116
18269
  nMaxFile: 260,
18117
- lpstrFileTitle: 0,
18118
- nMaxFileTitle: 0,
18119
- lpstrInitialDir: 0,
18120
- lpstrTitle: 0,
18121
- Flags: 4096 | 2048 | 4,
18122
- nFileOffset: 0,
18123
- nFileExtension: 0,
18124
- lpstrDefExt: 0,
18125
- lCustData: 0,
18126
- lpfnHook: 0,
18127
- lpTemplateName: 0,
18128
- pvReserved: 0,
18129
- dwReserved: 0,
18130
- FlagsEx: 0
18270
+ Flags: 4096 | 2048 | 4
18131
18271
  });
18132
18272
  ofn.__keep = [fileBuf, filterWide];
18133
- const ret = ffi13.ffiCall(GetOpenFileNameW_, [FFI_PTR3], [ofn], FFI_U323);
18273
+ const ret = GetOpenFileName(ofn);
18134
18274
  if (!ret)
18135
18275
  return null;
18136
- const path = wideToStr2(fileBuf);
18276
+ const path = WCHAR.decode(fileBuf);
18137
18277
  return path.length > 0 ? path : null;
18138
18278
  }
18139
18279
  async function loadMupdf() {
18140
18280
  const wasmPath = "./vendor/mupdf-wasm/mupdf-wasm.wasm";
18141
- const fp = std.open(wasmPath, "rb");
18281
+ const fp = std2.open(wasmPath, "rb");
18142
18282
  if (!fp) {
18143
- std.printf("Error: cannot open %s\n", wasmPath);
18283
+ std2.printf("Error: cannot open %s\n", wasmPath);
18144
18284
  return null;
18145
18285
  }
18146
18286
  fp.seek(0, 2);
@@ -18156,7 +18296,7 @@ async function loadMupdf() {
18156
18296
  try {
18157
18297
  return await import("../vendor/mupdf-wasm/mupdf.js");
18158
18298
  } catch (e) {
18159
- std.printf("Error: mupdf load failed: %s\n", String(e));
18299
+ std2.printf("Error: mupdf load failed: %s\n", String(e));
18160
18300
  return null;
18161
18301
  }
18162
18302
  }
@@ -18174,9 +18314,9 @@ function renderPdfPage(mupdf, filePath, pageIndex) {
18174
18314
  cachedDoc = null;
18175
18315
  cachedPath = "";
18176
18316
  cachedTotalPages = 0;
18177
- const fp = std.open(filePath, "rb");
18317
+ const fp = std2.open(filePath, "rb");
18178
18318
  if (!fp) {
18179
- std.printf("Error: cannot open %s\n", filePath);
18319
+ std2.printf("Error: cannot open %s\n", filePath);
18180
18320
  return null;
18181
18321
  }
18182
18322
  let buf = null;
@@ -18196,7 +18336,7 @@ function renderPdfPage(mupdf, filePath, pageIndex) {
18196
18336
  cachedTotalPages = cachedDoc.countPages();
18197
18337
  cachedPath = filePath;
18198
18338
  } catch (e) {
18199
- std.printf("Error opening document: %s\n", String(e));
18339
+ std2.printf("Error opening document: %s\n", String(e));
18200
18340
  return null;
18201
18341
  }
18202
18342
  }
@@ -18218,7 +18358,7 @@ function renderPdfPage(mupdf, filePath, pageIndex) {
18218
18358
  const h = pixmap.getHeight();
18219
18359
  const dibStride = Math.floor((w * 3 + 3) / 4) * 4;
18220
18360
  const dibSize = h * dibStride;
18221
- const dibBuffer = new ArrayBuffer(dibSize);
18361
+ const dibBuffer = new PtrArrayBuffer(dibSize);
18222
18362
  const dib = new Uint8Array(dibBuffer);
18223
18363
  for (let y = 0; y < h; y++) {
18224
18364
  const srcOff = y * srcStride;
@@ -18233,7 +18373,7 @@ function renderPdfPage(mupdf, filePath, pageIndex) {
18233
18373
  }
18234
18374
  return { data: dibBuffer, w, h, totalPages: cachedTotalPages };
18235
18375
  } catch (e) {
18236
- std.printf("Error rendering: %s\n", String(e));
18376
+ std2.printf("Error rendering: %s\n", String(e));
18237
18377
  if (cachedDoc) {
18238
18378
  try {
18239
18379
  cachedDoc.destroy();
@@ -18271,7 +18411,7 @@ function App({ mupdf, mainHwnd: hwnd }) {
18271
18411
  setCurrentPage(page);
18272
18412
  setTotalPages(result.totalPages);
18273
18413
  } else {
18274
- gui19.MessageBox("Failed to render PDF page");
18414
+ gui18.MessageBox("Failed to render PDF page");
18275
18415
  }
18276
18416
  }
18277
18417
  function handleOpen() {
@@ -18294,14 +18434,14 @@ function App({ mupdf, mainHwnd: hwnd }) {
18294
18434
  async function main() {
18295
18435
  const mupdf = await loadMupdf();
18296
18436
  if (!mupdf) {
18297
- gui19.MessageBox("Loading mupdf WASM failed.\nEnsure vendor/mupdf-wasm/ is present.");
18437
+ gui18.MessageBox("Loading mupdf WASM failed.\nEnsure vendor/mupdf-wasm/ is present.");
18298
18438
  return;
18299
18439
  }
18300
- gui19.RegisterClass("PdfViewerWin");
18301
- const hwnd = gui19.CreateWindow("PdfViewerWin", "PDF Viewer", 13565952, 100, 100, 1200, 800, null, null);
18440
+ gui18.RegisterClass("PdfViewerWin");
18441
+ const hwnd = gui18.CreateWindow("PdfViewerWin", "PDF Viewer", 13565952, 100, 100, 1200, 800, null, null);
18302
18442
  if (hwnd) {
18303
18443
  render((0, import_jsx_runtime17.jsx)(App, { mupdf, mainHwnd: hwnd }), hwnd);
18304
- setTimeout(() => gui19.ShowWindow(hwnd), 0);
18444
+ setTimeout(() => gui18.ShowWindow(hwnd), 0);
18305
18445
  }
18306
18446
  }
18307
18447
  main();