quickwin 1.2.1 → 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 (137) hide show
  1. package/README.en.md +3 -3
  2. package/README.md +21 -24
  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 +31 -73
  10. package/examples/pdf_preview2.ts +33 -76
  11. package/examples/pdf_viewer.js +1496 -616
  12. package/examples/pdf_viewer.tsx +23 -64
  13. package/examples/setres.js +22 -47
  14. package/examples/setres.ts +23 -57
  15. package/examples/test_gallery.js +1491 -525
  16. package/examples/test_react_lazy.js +1455 -500
  17. package/examples/test_react_listbox.js +1454 -499
  18. package/examples/test_root_window.js +1450 -495
  19. package/examples/test_tab.js +1455 -500
  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 +20 -33
  41. package/lib/react-qw/components/Input.js +3 -10
  42. package/lib/react-qw/components/Link.js +7 -22
  43. package/lib/react-qw/components/ListView.js +80 -141
  44. package/lib/react-qw/components/PathPicker.js +36 -80
  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 +15 -20
  48. package/lib/react-qw/components/Tooltip.js +21 -20
  49. package/lib/react-qw/components/TreeView.js +14 -47
  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 +5 -0
  53. package/lib/react-qw/nmhdr.ts +7 -0
  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 -35
  59. package/lib/text-measure.ts +20 -37
  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 -33
  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 +14 -4
  96. package/test/run.ts +15 -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 +33 -47
  100. package/test/test_ffi.ts +41 -60
  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 +572 -0
  104. package/test/test_ffi_bind.ts +597 -0
  105. package/test/test_ffi_struct.js +745 -0
  106. package/test/test_ffi_struct.ts +798 -0
  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 +1465 -510
  126. package/test/test_react_counter.js +1455 -500
  127. package/test/test_react_flex.js +1475 -513
  128. package/test/test_react_hidden.js +1458 -503
  129. package/test/test_react_listview_link.js +1455 -500
  130. package/test/test_react_notify.js +18534 -0
  131. package/test/test_react_render.js +1455 -500
  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
@@ -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,28 +15355,1184 @@ 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
+
15359
+ // _build/lib/ffi/ctype.js
15360
+ import { bufferPtr } from "ffi";
15361
+ import * as os from "os";
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;
15408
+ }
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
+ }
15441
+ }
15442
+ }
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;
15484
+ }
15485
+ }
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;
15492
+ }
15493
+ writeScalar(dv, off, e);
15494
+ }
15495
+ var PtrArrayBuffer = class extends ArrayBuffer {
15496
+ ptr;
15497
+ constructor(byteLength) {
15498
+ super(byteLength);
15499
+ this.ptr = bufferPtr(this);
15500
+ }
15501
+ };
15502
+
15503
+ // _build/examples/pdf_viewer.js
15358
15504
  var import_react19 = __toESM(require_react(), 1);
15359
15505
  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 ffi11 from "ffi";
15506
+ import * as std2 from "std";
15507
+ import * as gui18 from "gui";
15364
15508
 
15365
15509
  // _build/lib/react-qw/index.js
15366
- import * as gui18 from "gui";
15510
+ import * as gui17 from "gui";
15511
+
15512
+ // _build/lib/windows/user32.js
15513
+ import * as os3 from "os";
15514
+
15515
+ // _build/lib/ffi/bind.js
15516
+ import * as ffi from "ffi";
15517
+ import * as os2 from "os";
15518
+ import * as std from "std";
15519
+ import * as win from "win";
15520
+
15521
+ // _build/lib/text-codec.js
15522
+ var _labelMap = {
15523
+ "utf-8": "utf-8",
15524
+ "utf8": "utf-8",
15525
+ "unicode-1-1-utf-8": "utf-8",
15526
+ "utf-16": "utf-16le",
15527
+ "utf-16le": "utf-16le",
15528
+ "utf-16be": "utf-16be"
15529
+ };
15530
+ function _normalizeLabel(label) {
15531
+ if (!label)
15532
+ return "utf-8";
15533
+ const result = _labelMap[label.trim().toLowerCase()];
15534
+ if (result)
15535
+ return result;
15536
+ throw new RangeError(`The encoding label "${label}" is not supported`);
15537
+ }
15538
+ function _decodeUTF8(buf, fatal) {
15539
+ let out = "";
15540
+ for (let i = 0; i < buf.length; ) {
15541
+ const b6 = buf[i++];
15542
+ if (b6 < 128) {
15543
+ out += String.fromCharCode(b6);
15544
+ continue;
15545
+ }
15546
+ if (b6 < 192) {
15547
+ out += fatal ? (() => {
15548
+ throw new TypeError("unexpected continuation byte");
15549
+ })() : "\uFFFD";
15550
+ continue;
15551
+ }
15552
+ let c, min;
15553
+ if (b6 < 224) {
15554
+ if (i >= buf.length) {
15555
+ out += fatal ? (() => {
15556
+ throw new TypeError("incomplete utf-8");
15557
+ })() : "\uFFFD";
15558
+ break;
15559
+ }
15560
+ const b22 = buf[i++];
15561
+ if ((b22 & 192) !== 128) {
15562
+ out += "\uFFFD";
15563
+ continue;
15564
+ }
15565
+ c = (b6 & 31) << 6 | b22 & 63;
15566
+ min = 128;
15567
+ } else if (b6 < 240) {
15568
+ if (i + 1 >= buf.length) {
15569
+ out += fatal ? (() => {
15570
+ throw new TypeError("incomplete utf-8");
15571
+ })() : "\uFFFD";
15572
+ break;
15573
+ }
15574
+ const b22 = buf[i++];
15575
+ const b32 = buf[i++];
15576
+ if ((b22 & 192) !== 128 || (b32 & 192) !== 128) {
15577
+ out += "\uFFFD";
15578
+ continue;
15579
+ }
15580
+ c = (b6 & 15) << 12 | (b22 & 63) << 6 | b32 & 63;
15581
+ min = 2048;
15582
+ } else if (b6 < 248) {
15583
+ if (i + 2 >= buf.length) {
15584
+ out += fatal ? (() => {
15585
+ throw new TypeError("incomplete utf-8");
15586
+ })() : "\uFFFD";
15587
+ break;
15588
+ }
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) {
15593
+ out += "\uFFFD";
15594
+ continue;
15595
+ }
15596
+ c = (b6 & 7) << 18 | (b22 & 63) << 12 | (b32 & 63) << 6 | b42 & 63;
15597
+ min = 65536;
15598
+ } else {
15599
+ out += fatal ? (() => {
15600
+ throw new TypeError("invalid utf-8 start");
15601
+ })() : "\uFFFD";
15602
+ continue;
15603
+ }
15604
+ if (c < min || c >= 55296 && c <= 57343 || c > 1114111) {
15605
+ out += fatal ? (() => {
15606
+ throw new TypeError("invalid utf-8 codepoint");
15607
+ })() : "\uFFFD";
15608
+ continue;
15609
+ }
15610
+ if (c <= 65535)
15611
+ out += String.fromCharCode(c);
15612
+ else {
15613
+ c -= 65536;
15614
+ out += String.fromCharCode(55296 | c >> 10, 56320 | c & 1023);
15615
+ }
15616
+ }
15617
+ return out;
15618
+ }
15619
+ function _decodeUTF16(buf, le, fatal) {
15620
+ const dv = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
15621
+ let out = "";
15622
+ for (let i = 0; i + 1 < buf.length; i += 2) {
15623
+ let c = dv.getUint16(i, le);
15624
+ if (c >= 55296 && c <= 56319) {
15625
+ i += 2;
15626
+ if (i + 1 >= buf.length) {
15627
+ out += fatal ? (() => {
15628
+ throw new TypeError("truncated surrogate pair");
15629
+ })() : "\uFFFD";
15630
+ break;
15631
+ }
15632
+ const c2 = dv.getUint16(i, le);
15633
+ if (c2 >= 56320 && c2 <= 57343) {
15634
+ out += String.fromCharCode(c, c2);
15635
+ } else {
15636
+ out += fatal ? (() => {
15637
+ throw new TypeError("invalid surrogate pair");
15638
+ })() : "\uFFFD";
15639
+ i -= 2;
15640
+ }
15641
+ } else if (c >= 56320 && c <= 57343) {
15642
+ out += fatal ? (() => {
15643
+ throw new TypeError("unexpected trailing surrogate");
15644
+ })() : "\uFFFD";
15645
+ } else {
15646
+ out += String.fromCharCode(c);
15647
+ }
15648
+ }
15649
+ return out;
15650
+ }
15651
+ var TextDecoderImpl = class {
15652
+ _encoding;
15653
+ _fatal;
15654
+ _ignoreBOM;
15655
+ constructor(label, options) {
15656
+ this._encoding = _normalizeLabel(label);
15657
+ this._fatal = options?.fatal ?? false;
15658
+ this._ignoreBOM = options?.ignoreBOM ?? false;
15659
+ }
15660
+ get encoding() {
15661
+ return this._encoding;
15662
+ }
15663
+ get fatal() {
15664
+ return this._fatal;
15665
+ }
15666
+ get ignoreBOM() {
15667
+ return this._ignoreBOM;
15668
+ }
15669
+ decode(buffer) {
15670
+ if (!buffer)
15671
+ return "";
15672
+ const arr = buffer instanceof Uint8Array ? buffer : buffer instanceof ArrayBuffer ? new Uint8Array(buffer) : new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
15673
+ if (this._encoding === "utf-8") {
15674
+ return _decodeUTF8(arr, this._fatal);
15675
+ }
15676
+ const le = this._encoding === "utf-16le";
15677
+ let offset = 0;
15678
+ if (arr.length >= 2 && !this._ignoreBOM) {
15679
+ const bomLo = le ? arr[0] : arr[1];
15680
+ const bomHi = le ? arr[1] : arr[0];
15681
+ const bom = bomHi << 8 | bomLo;
15682
+ if (bom === 65279 || bom === 65534) {
15683
+ offset = 2;
15684
+ }
15685
+ }
15686
+ return _decodeUTF16(arr.slice(offset), le, this._fatal);
15687
+ }
15688
+ };
15689
+ var TextEncoderImpl = class {
15690
+ _encoding;
15691
+ constructor(label) {
15692
+ this._encoding = _normalizeLabel(label);
15693
+ }
15694
+ get encoding() {
15695
+ return this._encoding;
15696
+ }
15697
+ encode(input) {
15698
+ if (!input)
15699
+ return new Uint8Array(0);
15700
+ if (this._encoding === "utf-8") {
15701
+ const bytes = [];
15702
+ for (let i = 0; i < input.length; i++) {
15703
+ let c = input.charCodeAt(i);
15704
+ if (c < 128) {
15705
+ bytes.push(c);
15706
+ } else if (c < 2048) {
15707
+ bytes.push(192 | c >> 6, 128 | c & 63);
15708
+ } else if (c < 55296 || c >= 57344) {
15709
+ bytes.push(224 | c >> 12, 128 | c >> 6 & 63, 128 | c & 63);
15710
+ } else {
15711
+ i++;
15712
+ const c2 = input.charCodeAt(i);
15713
+ c = 65536 + ((c & 1023) << 10) | c2 & 1023;
15714
+ bytes.push(240 | c >> 18, 128 | c >> 12 & 63, 128 | c >> 6 & 63, 128 | c & 63);
15715
+ }
15716
+ }
15717
+ return new Uint8Array(bytes);
15718
+ }
15719
+ const le = this._encoding === "utf-16le";
15720
+ const buf = new ArrayBuffer(input.length * 2);
15721
+ const dv = new DataView(buf);
15722
+ for (let i = 0; i < input.length; i++)
15723
+ dv.setUint16(i * 2, input.charCodeAt(i), le);
15724
+ return new Uint8Array(buf);
15725
+ }
15726
+ };
15727
+ if (typeof globalThis.TextDecoder === "undefined") {
15728
+ globalThis.TextDecoder = TextDecoderImpl;
15729
+ }
15730
+ if (typeof globalThis.TextEncoder === "undefined") {
15731
+ globalThis.TextEncoder = TextEncoderImpl;
15732
+ }
15733
+
15734
+ // _build/lib/ffi/bind.js
15735
+ var _dllCache = /* @__PURE__ */ new Map();
15736
+ function loadDll(dll) {
15737
+ const cached = _dllCache.get(dll);
15738
+ if (cached !== void 0)
15739
+ return cached;
15740
+ const loaded = win.LoadLibrary(dll);
15741
+ if (!loaded)
15742
+ throw new Error(`ffi-bind: LoadLibrary("${dll}") failed`);
15743
+ _dllCache.set(dll, loaded);
15744
+ return loaded;
15745
+ }
15746
+ function parseSig(sig) {
15747
+ const parts = sig.split(" -> ");
15748
+ if (parts.length !== 2) {
15749
+ throw new Error(`ffi-bind: invalid signature "${sig}" (expected "arg1 arg2 -> ret")`);
15750
+ }
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)}`);
15995
+ }
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
16075
+ };
16076
+ }
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) {
16203
+ const out = {};
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;
16209
+ }
16210
+ return out;
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");
15367
16512
 
15368
16513
  // _build/lib/react-qw/reconciler.js
15369
16514
  var import_react_reconciler = __toESM(require_react_reconciler(), 1);
15370
16515
  var import_react = __toESM(require_react(), 1);
15371
16516
  var import_constants = __toESM(require_constants(), 1);
15372
16517
  import * as gui3 from "gui";
15373
- import * as os2 from "os";
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");
15374
16528
 
15375
16529
  // _build/lib/react-qw/props.js
15376
16530
  import * as gui from "gui";
15377
16531
  function applyProps(instance, newProps, _oldProps) {
15378
16532
  const hwnd = instance.hwnd;
15379
16533
  instance.props = newProps;
16534
+ if (hwnd === null)
16535
+ return;
15380
16536
  const textVal = "text" in newProps ? newProps.text : typeof newProps.children === "string" ? newProps.children : typeof newProps.children === "number" ? String(newProps.children) : void 0;
15381
16537
  if (textVal !== void 0) {
15382
16538
  let cursor = -1;
@@ -15384,13 +16540,13 @@ function applyProps(instance, newProps, _oldProps) {
15384
16540
  const sel = gui.SendMessage(hwnd, 176, 0, 0);
15385
16541
  cursor = sel >>> 16;
15386
16542
  }
15387
- gui.SetWindowText(hwnd, textVal);
16543
+ SetWindowText(hwnd, textVal);
15388
16544
  if (instance.type === "EDIT" && cursor >= 0) {
15389
16545
  gui.SendMessage(hwnd, 177, cursor, cursor);
15390
16546
  }
15391
16547
  }
15392
16548
  if ("disabled" in newProps) {
15393
- gui.EnableWindow(hwnd, !newProps.disabled);
16549
+ EnableWindow(hwnd, !newProps.disabled ? 1 : 0);
15394
16550
  }
15395
16551
  if ("hidden" in newProps) {
15396
16552
  gui.ShowWindow(
@@ -15490,58 +16646,36 @@ function calculateFlexLayout(flex, parentW, parentH, children) {
15490
16646
  }
15491
16647
 
15492
16648
  // _build/lib/text-measure.js
15493
- import * as ffi from "ffi";
15494
- import * as os from "os";
15495
- import * as win from "win";
15496
16649
  import * as gui2 from "gui";
15497
- function loadProc(lib, name) {
15498
- const ptr = win.GetProcAddress(lib, name);
15499
- if (!ptr)
15500
- throw new Error(`Cannot load ${name}`);
15501
- return ptr;
15502
- }
15503
- var user32 = win.LoadLibrary("user32.dll");
15504
- var gdi32 = win.LoadLibrary("gdi32.dll");
15505
- if (!user32 || !gdi32)
15506
- throw new Error("Failed to load system DLLs");
15507
- var DrawTextW = loadProc(user32, "DrawTextW");
15508
- var GetDC = loadProc(user32, "GetDC");
15509
- var ReleaseDC = loadProc(user32, "ReleaseDC");
15510
- var SelectObject = loadProc(gdi32, "SelectObject");
15511
- var FFI_HND = os.arch === "ia32" ? ffi.FFI_TYPE_UINT32 : ffi.FFI_TYPE_UINT64;
15512
- var FFI_S32 = ffi.FFI_TYPE_SINT32;
15513
- var FFI_PTR = ffi.FFI_TYPE_POINTER;
15514
16650
  function measureText(hdc, text, maxWidth) {
15515
- const textBuf = new TextEncoder("utf-16le").encode(text + "\0").buffer;
15516
- const rect = new ArrayBuffer(16);
15517
- const dv = new DataView(rect);
15518
- dv.setInt32(8, maxWidth, true);
15519
- ffi.ffiCall(DrawTextW, [FFI_HND, FFI_PTR, FFI_S32, FFI_PTR, FFI_S32], [
16651
+ const r = RECT.encode({ right: maxWidth });
16652
+ DrawText(
15520
16653
  hdc,
15521
- textBuf,
16654
+ text,
15522
16655
  -1,
15523
- rect,
16656
+ r.ptr,
15524
16657
  1024
15525
16658
  /* gui.DrawTextFlag.CALCRECT */
15526
- ], FFI_S32);
15527
- return { width: dv.getInt32(8, true), height: dv.getInt32(12, true) };
16659
+ );
16660
+ const { right, bottom } = RECT.decode(r);
16661
+ return { width: right, height: bottom };
15528
16662
  }
15529
16663
  function getButtonIdealSize(hwnd) {
15530
- const size = new ArrayBuffer(8);
15531
- gui2.SendMessage(hwnd, 5633, 0, ffi.bufferPtr(size));
15532
- const dv = new DataView(size);
15533
- 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 };
15534
16668
  }
15535
16669
  function measureTextForHwnd(hwnd, text) {
15536
- const hdc = ffi.ffiCall(GetDC, [FFI_HND], [hwnd], FFI_HND);
16670
+ const hdc = GetDC(hwnd);
15537
16671
  if (!hdc)
15538
16672
  return { width: 0, height: 0 };
15539
16673
  const hFont = gui2.SendMessage(hwnd, 49, 0, 0);
15540
- const oldFont = hFont ? ffi.ffiCall(SelectObject, [FFI_HND, FFI_HND], [hdc, hFont], FFI_HND) : 0;
16674
+ const oldFont = hFont ? SelectObject(hdc, hFont) : 0;
15541
16675
  const result = measureText(hdc, text, 0);
15542
16676
  if (hFont)
15543
- ffi.ffiCall(SelectObject, [FFI_HND, FFI_HND], [hdc, oldFont], FFI_HND);
15544
- ffi.ffiCall(ReleaseDC, [FFI_HND, FFI_HND], [hwnd, hdc], FFI_S32);
16677
+ SelectObject(hdc, oldFont);
16678
+ ReleaseDC(hwnd, hdc);
15545
16679
  const wr = gui2.GetWindowRect(hwnd);
15546
16680
  const cr = gui2.GetClientRect(hwnd);
15547
16681
  if (wr && cr) {
@@ -15553,14 +16687,20 @@ function measureTextForHwnd(hwnd, text) {
15553
16687
 
15554
16688
  // _build/lib/react-qw/reconciler.js
15555
16689
  var dpiFont = gui3.CreateSystemDpiFont();
15556
- 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
+ })();
15557
16697
  var DELAYED_CONTROLS = /* @__PURE__ */ new Set(["SysListView32", "SysTreeView32", "LISTBOX", "COMBOBOX", "msctls_trackbar32", "SysDateTimePick32", "SysLink"]);
15558
16698
  function isDelayedControl(winClass) {
15559
16699
  return DELAYED_CONTROLS.has(winClass);
15560
16700
  }
15561
16701
  function setupWindowProc(instance, hwnd) {
15562
16702
  instance.hwnd = hwnd;
15563
- const oldProc = gui3.GetWindowLongPtr(
16703
+ const oldProc = GetWindowLongPtr(
15564
16704
  hwnd,
15565
16705
  -4
15566
16706
  /* gui.Gwlp.WNDPROC */
@@ -15569,11 +16709,11 @@ function setupWindowProc(instance, hwnd) {
15569
16709
  gui3.SetWindowProc(hwnd, (hwnd2, msg, wParam, lParam) => {
15570
16710
  const ev = instance.props.onEvent;
15571
16711
  if (!ev)
15572
- return gui3.CallWindowProc(oldProc, hwnd2, msg, wParam, lParam);
16712
+ return CallWindowProc(oldProc, hwnd2, msg, wParam, lParam);
15573
16713
  if (typeof ev === "object") {
15574
- 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) });
15575
16715
  }
15576
- const result = gui3.CallWindowProc(oldProc, hwnd2, msg, wParam, lParam);
16716
+ const result = CallWindowProc(oldProc, hwnd2, msg, wParam, lParam);
15577
16717
  const override = ev({ hwnd: hwnd2, msg, wParam, lParam });
15578
16718
  return typeof override === "number" && Number.isInteger(override) ? override : result;
15579
16719
  });
@@ -15643,7 +16783,7 @@ function runFlexLayout(inst) {
15643
16783
  if (lr && lr.x === r.x && lr.y === r.y && lr.w === r.width && lr.h === r.height)
15644
16784
  continue;
15645
16785
  console.log("flex: set", child.type, child.hwnd, "to", r.x, r.y, r.width, r.height);
15646
- gui3.SetWindowPos(
16786
+ SetWindowPos(
15647
16787
  child.hwnd,
15648
16788
  0,
15649
16789
  (r.x + pl) * scaleFactor,
@@ -15653,7 +16793,7 @@ function runFlexLayout(inst) {
15653
16793
  64
15654
16794
  /* gui.SetWindowPosFlag.SWP_SHOWWINDOW */
15655
16795
  );
15656
- gui3.InvalidateRect(child.hwnd, null, true);
16796
+ InvalidateRect(child.hwnd, NULL, 1);
15657
16797
  child.lastRect = { x: r.x, y: r.y, w: r.width, h: r.height };
15658
16798
  }
15659
16799
  for (const c of children)
@@ -15699,7 +16839,7 @@ var hostConfig = {
15699
16839
  if (child.hwnd === null) {
15700
16840
  ensureChildWindow(child, parent.hwnd);
15701
16841
  } else {
15702
- gui3.SetParent(child.hwnd, parent.hwnd);
16842
+ SetParent(child.hwnd, parent.hwnd ?? NULL);
15703
16843
  }
15704
16844
  if (false)
15705
16845
  console.log("[reconciler] appendInitialChild parent:", parent.hwnd, "child:", child.hwnd);
@@ -15709,7 +16849,7 @@ var hostConfig = {
15709
16849
  if (child.hwnd === null) {
15710
16850
  ensureChildWindow(child, parent.hwnd);
15711
16851
  } else {
15712
- gui3.SetParent(child.hwnd, parent.hwnd);
16852
+ SetParent(child.hwnd, parent.hwnd ?? NULL);
15713
16853
  }
15714
16854
  if (false)
15715
16855
  console.log("[reconciler] appendChild parent:", parent.hwnd, "child:", child.hwnd);
@@ -15719,7 +16859,7 @@ var hostConfig = {
15719
16859
  if (child.hwnd === null) {
15720
16860
  ensureChildWindow(child, container);
15721
16861
  } else {
15722
- gui3.SetParent(child.hwnd, container);
16862
+ SetParent(child.hwnd, container);
15723
16863
  }
15724
16864
  const rootInst = instancesByHwnd.get(container);
15725
16865
  if (rootInst)
@@ -15731,7 +16871,7 @@ var hostConfig = {
15731
16871
  if (child.hwnd === null) {
15732
16872
  ensureChildWindow(child, parent.hwnd);
15733
16873
  } else {
15734
- gui3.SetParent(child.hwnd, parent.hwnd);
16874
+ SetParent(child.hwnd, parent.hwnd ?? NULL);
15735
16875
  }
15736
16876
  if (false)
15737
16877
  console.log("[reconciler] insertBefore parent:", parent.hwnd, "child:", child.hwnd, "before:", beforeChild.hwnd);
@@ -15743,7 +16883,7 @@ var hostConfig = {
15743
16883
  if (child.hwnd === null) {
15744
16884
  ensureChildWindow(child, container);
15745
16885
  } else {
15746
- gui3.SetParent(child.hwnd, container);
16886
+ SetParent(child.hwnd, container);
15747
16887
  }
15748
16888
  const rootInst = instancesByHwnd.get(container);
15749
16889
  if (!rootInst)
@@ -15800,7 +16940,7 @@ var hostConfig = {
15800
16940
  resetTextContent(_instance) {
15801
16941
  },
15802
16942
  commitTextUpdate(instance, _oldText, newText) {
15803
- gui3.SetWindowText(instance.hwnd, newText);
16943
+ SetWindowText(instance.hwnd, newText);
15804
16944
  },
15805
16945
  hideInstance(instance) {
15806
16946
  if (instance.hwnd !== null)
@@ -15854,10 +16994,10 @@ var hostConfig = {
15854
16994
  clearContainer(_container) {
15855
16995
  },
15856
16996
  scheduleTimeout(fn, delay) {
15857
- return os2.setTimeout(fn, delay);
16997
+ return os4.setTimeout(fn, delay);
15858
16998
  },
15859
16999
  cancelTimeout(id) {
15860
- os2.clearTimeout?.(id);
17000
+ os4.clearTimeout?.(id);
15861
17001
  },
15862
17002
  noTimeout: -1,
15863
17003
  supportsMutation: true,
@@ -16024,28 +17164,23 @@ var ComboBox = (0, import_react4.forwardRef)(({ items, selectedIndex: controlled
16024
17164
  var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
16025
17165
  var import_react5 = __toESM(require_react(), 1);
16026
17166
  import * as gui6 from "gui";
16027
- import * as ffi2 from "ffi";
16028
- function readI16(ptr, offset) {
16029
- return ffi2.readByte(ptr + offset) | ffi2.readByte(ptr + offset + 1) << 8;
16030
- }
16031
- function readI32(ptr, offset) {
16032
- return ffi2.readByte(ptr + offset) | ffi2.readByte(ptr + offset + 1) << 8 | ffi2.readByte(ptr + offset + 2) << 16 | ffi2.readByte(ptr + offset + 3) << 24;
16033
- }
16034
- function bufPtr(buf) {
16035
- return ffi2.bufferPtr(buf);
17167
+
17168
+ // _build/lib/react-qw/nmhdr.js
17169
+ function nmCode(lParam) {
17170
+ return NMHDR.decode(lParam).code;
16036
17171
  }
17172
+
17173
+ // _build/lib/react-qw/components/DateTimePicker.js
16037
17174
  function dateToSysTimeBuf(d) {
16038
- const buf = new ArrayBuffer(16);
16039
- const dv = new DataView(buf);
16040
- dv.setUint16(0, d.getFullYear(), true);
16041
- dv.setUint16(2, d.getMonth() + 1, true);
16042
- dv.setUint16(4, 0, true);
16043
- dv.setUint16(6, d.getDate(), true);
16044
- dv.setUint16(8, d.getHours(), true);
16045
- dv.setUint16(10, d.getMinutes(), true);
16046
- dv.setUint16(12, d.getSeconds(), true);
16047
- dv.setUint16(14, d.getMilliseconds(), true);
16048
- 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
+ });
16049
17184
  }
16050
17185
  var DateTimePicker = (0, import_react5.forwardRef)(function DateTimePicker2({ value, onChange, defaultValue, format = "short", allowNone, updown, style }, ref) {
16051
17186
  const [internalDate, setInternalDate] = (0, import_react5.useState)(defaultValue ?? null);
@@ -16070,7 +17205,7 @@ var DateTimePicker = (0, import_react5.forwardRef)(function DateTimePicker2({ va
16070
17205
  const d = effectiveDate;
16071
17206
  if (d) {
16072
17207
  const buf = dateToSysTimeBuf(d);
16073
- gui6.SendMessage(h, 4098, 0, bufPtr(buf));
17208
+ gui6.SendMessage(h, 4098, 0, buf.ptr);
16074
17209
  } else {
16075
17210
  gui6.SendMessage(h, 4098, 1, 0);
16076
17211
  }
@@ -16079,7 +17214,7 @@ var DateTimePicker = (0, import_react5.forwardRef)(function DateTimePicker2({ va
16079
17214
  const h = dpRef.current;
16080
17215
  if (!h)
16081
17216
  return;
16082
- gui6.InvalidateRect(h, null, true);
17217
+ InvalidateRect(h, NULL, 1);
16083
17218
  const cr = gui6.GetClientRect(h);
16084
17219
  if (cr) {
16085
17220
  const w = cr.right - cr.left;
@@ -16089,21 +17224,15 @@ var DateTimePicker = (0, import_react5.forwardRef)(function DateTimePicker2({ va
16089
17224
  }, []);
16090
17225
  return (0, import_jsx_runtime4.jsx)("w", { type: "STATIC", ws: 268435456 | 33554432, style: { ...style, flexDirection: "column", alignItems: "stretch" }, ref, onEvent: (e) => {
16091
17226
  if (e.msg === 78) {
16092
- const code = readI32(e.lParam, 16);
17227
+ const code = nmCode(e.lParam);
16093
17228
  if (code === -759) {
16094
- const dwFlags = readI32(e.lParam, 24);
17229
+ const { dwFlags, st } = NMDATETIMECHANGE.decode(e.lParam);
16095
17230
  if (dwFlags === 1) {
16096
17231
  if (!isControlled)
16097
17232
  setInternalDate(null);
16098
17233
  onChangeRef.current?.(null);
16099
17234
  } else {
16100
- const year = readI16(e.lParam, 28);
16101
- const month = readI16(e.lParam, 30);
16102
- const day = readI16(e.lParam, 34);
16103
- const hour = readI16(e.lParam, 36);
16104
- const min = readI16(e.lParam, 38);
16105
- const sec = readI16(e.lParam, 40);
16106
- 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);
16107
17236
  if (!isControlled)
16108
17237
  setInternalDate(d);
16109
17238
  onChangeRef.current?.(d);
@@ -16119,14 +17248,6 @@ var DateTimePicker = (0, import_react5.forwardRef)(function DateTimePicker2({ va
16119
17248
  var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
16120
17249
  var import_react6 = __toESM(require_react(), 1);
16121
17250
  import * as gui7 from "gui";
16122
- import * as ffi3 from "ffi";
16123
- function textToUtf16(s) {
16124
- const buf = new ArrayBuffer((s.length + 1) * 2);
16125
- const dv = new DataView(buf);
16126
- for (let i = 0; i < s.length; i++)
16127
- dv.setUint16(i * 2, s.charCodeAt(i), true);
16128
- return buf;
16129
- }
16130
17251
  var Input = (0, import_react6.forwardRef)(({ value: controlledValue, defaultValue = "", onChange, placeholder, password, multiline, readonly, number, disabled, style }, ref) => {
16131
17252
  const [internalValue, setInternalValue] = (0, import_react6.useState)(defaultValue);
16132
17253
  const isControlled = controlledValue !== void 0;
@@ -16145,8 +17266,8 @@ var Input = (0, import_react6.forwardRef)(({ value: controlledValue, defaultValu
16145
17266
  const h = inputRef.current;
16146
17267
  if (!h || !placeholder)
16147
17268
  return;
16148
- const buf = textToUtf16(placeholder);
16149
- gui7.SendMessage(h, 5377, 1, ffi3.bufferPtr(buf));
17269
+ const buf = WCHAR.encode(placeholder);
17270
+ gui7.SendMessage(h, 5377, 1, buf.ptr);
16150
17271
  }, [placeholder]);
16151
17272
  return (0, import_jsx_runtime5.jsx)("w", { type: "EDIT", text: displayValue, ws, style, disabled, ref: (h) => {
16152
17273
  inputRef.current = h;
@@ -16170,23 +17291,6 @@ var Input = (0, import_react6.forwardRef)(({ value: controlledValue, defaultValu
16170
17291
  // _build/lib/react-qw/components/Link.js
16171
17292
  var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
16172
17293
  var import_react7 = __toESM(require_react(), 1);
16173
- import * as gui8 from "gui";
16174
- import * as ffi4 from "ffi";
16175
- function readI322(ptr, offset) {
16176
- return ffi4.readByte(ptr + offset) | ffi4.readByte(ptr + offset + 1) << 8 | ffi4.readByte(ptr + offset + 2) << 16 | ffi4.readByte(ptr + offset + 3) << 24;
16177
- }
16178
- function readUtf16(ptr, offset, maxWords) {
16179
- const chars = [];
16180
- for (let i = 0; i < maxWords; i++) {
16181
- const lo = ffi4.readByte(ptr + offset + i * 2);
16182
- const hi = ffi4.readByte(ptr + offset + i * 2 + 1);
16183
- const code = hi << 8 | lo;
16184
- if (code === 0)
16185
- break;
16186
- chars.push(String.fromCharCode(code));
16187
- }
16188
- return chars.join("");
16189
- }
16190
17294
  var Link = (0, import_react7.forwardRef)(function Link2({ href, children, onClick, style }, ref) {
16191
17295
  const displayText = children != null ? String(children) : href ?? "";
16192
17296
  const linkText = href ? `<A HREF="${href}">${displayText}</A>` : displayText;
@@ -16197,14 +17301,13 @@ var Link = (0, import_react7.forwardRef)(function Link2({ href, children, onClic
16197
17301
  const h = linkRef.current;
16198
17302
  if (!h)
16199
17303
  return;
16200
- gui8.InvalidateRect(h, null, true);
17304
+ InvalidateRect(h, NULL, 1);
16201
17305
  }, [linkText]);
16202
17306
  return (0, import_jsx_runtime6.jsx)("w", { type: "STATIC", ws: 268435456 | 33554432, style: { ...style, flexDirection: "column", alignItems: "stretch" }, ref, onEvent: (e) => {
16203
17307
  if (e.msg === 78) {
16204
- const code = readI322(e.lParam, 16);
17308
+ const code = nmCode(e.lParam);
16205
17309
  if (code === -2 || code === -4) {
16206
- const url = readUtf16(e.lParam, 136, 2048);
16207
- onClickRef.current?.(url);
17310
+ onClickRef.current?.(NMLINK.decode(e.lParam).item.szUrl);
16208
17311
  }
16209
17312
  }
16210
17313
  }, children: (0, import_jsx_runtime6.jsx)("w", { type: "SysLink", ws: 268435456 | 65536, text: linkText, style: { flexGrow: 1 }, ref: (h) => {
@@ -16215,7 +17318,7 @@ var Link = (0, import_react7.forwardRef)(function Link2({ href, children, onClic
16215
17318
  // _build/lib/react-qw/components/ListBox.js
16216
17319
  var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
16217
17320
  var import_react8 = __toESM(require_react(), 1);
16218
- import * as gui9 from "gui";
17321
+ import * as gui8 from "gui";
16219
17322
  var ListBox = (0, import_react8.forwardRef)(({ items, selectedIndex: controlledIndex, defaultSelectedIndex = -1, onChange, style, sort, scrollToBottom }, ref) => {
16220
17323
  const [internalIndex, setInternalIndex] = (0, import_react8.useState)(defaultSelectedIndex);
16221
17324
  const isControlled = controlledIndex !== void 0;
@@ -16227,18 +17330,18 @@ var ListBox = (0, import_react8.forwardRef)(({ items, selectedIndex: controlledI
16227
17330
  const h = lbRef.current;
16228
17331
  if (!h)
16229
17332
  return;
16230
- gui9.SendMessage(h, 388, 0, 0);
17333
+ gui8.SendMessage(h, 388, 0, 0);
16231
17334
  for (const item of items)
16232
- gui9.SendMessage(h, 384, 0, item);
17335
+ gui8.SendMessage(h, 384, 0, item);
16233
17336
  if (sel >= 0 && sel < items.length)
16234
- gui9.SendMessage(h, 390, sel, 0);
17337
+ gui8.SendMessage(h, 390, sel, 0);
16235
17338
  if (scrollToBottom && items.length > 0)
16236
- gui9.SendMessage(h, 407, items.length - 1, 0);
17339
+ gui8.SendMessage(h, 407, items.length - 1, 0);
16237
17340
  }, [items]);
16238
17341
  (0, import_react8.useEffect)(() => {
16239
17342
  const h = lbRef.current;
16240
17343
  if (h)
16241
- gui9.SendMessage(h, 390, sel, 0);
17344
+ gui8.SendMessage(h, 390, sel, 0);
16242
17345
  }, [sel]);
16243
17346
  return (0, import_jsx_runtime7.jsx)("w", { type: "STATIC", ws: 268435456 | 33554432, style: { ...style, flexDirection: "column", alignItems: "stretch" }, onEvent: (e) => {
16244
17347
  if (e.msg !== 273)
@@ -16248,7 +17351,7 @@ var ListBox = (0, import_react8.forwardRef)(({ items, selectedIndex: controlledI
16248
17351
  const h = lbRef.current;
16249
17352
  if (!h)
16250
17353
  return;
16251
- const newSel = gui9.SendMessage(h, 392, 0, 0);
17354
+ const newSel = gui8.SendMessage(h, 392, 0, 0);
16252
17355
  if (newSel !== sel && newSel >= 0) {
16253
17356
  if (!isControlled)
16254
17357
  setInternalIndex(newSel);
@@ -16263,75 +17366,18 @@ var ListBox = (0, import_react8.forwardRef)(({ items, selectedIndex: controlledI
16263
17366
  // _build/lib/react-qw/components/ListView.js
16264
17367
  var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1);
16265
17368
  var import_react9 = __toESM(require_react(), 1);
16266
- import * as gui10 from "gui";
16267
- import * as ffi5 from "ffi";
16268
- import * as win2 from "win";
16269
- function textToUtf162(s) {
16270
- const buf = new ArrayBuffer((s.length + 1) * 2);
16271
- const dv = new DataView(buf);
16272
- for (let i = 0; i < s.length; i++)
16273
- dv.setUint16(i * 2, s.charCodeAt(i), true);
16274
- return buf;
16275
- }
16276
- function readI323(ptr, offset) {
16277
- return ffi5.readByte(ptr + offset) | ffi5.readByte(ptr + offset + 1) << 8 | ffi5.readByte(ptr + offset + 2) << 16 | ffi5.readByte(ptr + offset + 3) << 24;
16278
- }
16279
- function readU32(ptr, offset) {
16280
- return ffi5.readByte(ptr + offset) | ffi5.readByte(ptr + offset + 1) << 8 | ffi5.readByte(ptr + offset + 2) << 16 | ffi5.readByte(ptr + offset + 3) << 24 >>> 0;
16281
- }
16282
- function readU64(ptr, offset) {
16283
- const lo = readU32(ptr, offset);
16284
- const hi = readU32(ptr, offset + 4);
16285
- return lo + hi * 4294967296;
16286
- }
17369
+ import * as gui9 from "gui";
17370
+ import * as ffi3 from "ffi";
16287
17371
  function writeU32(ptr, offset, v) {
16288
- ffi5.writeByte(ptr + offset, v & 255);
16289
- ffi5.writeByte(ptr + offset + 1, v >> 8 & 255);
16290
- ffi5.writeByte(ptr + offset + 2, v >> 16 & 255);
16291
- ffi5.writeByte(ptr + offset + 3, v >> 24 & 255);
16292
- }
16293
- function bufPtr2(buf) {
16294
- return ffi5.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);
16295
17376
  }
16296
17377
  var LV_WS = 268435456 | 8388608 | 2097152 | 1048576 | 1 | 4;
16297
- var CD_STAGE = 24;
16298
- var CD_HDC = 32;
16299
- var CD_ITEM = 56;
16300
- var CD_CLRTEXT = 80;
16301
- var CD_CLRTEXTBK = 84;
16302
- var CD_SUBITEM = 88;
16303
- var NMIA_ITEM = 24;
16304
- var NMIA_SUBITEM = 28;
16305
- var NM_CODE = 16;
17378
+ var CD_CLRTEXT = NMLVCUSTOMDRAW.offsetOf("clrText");
17379
+ var CD_CLRTEXTBK = NMLVCUSTOMDRAW.offsetOf("clrTextBk");
16306
17380
  var fontCache = /* @__PURE__ */ new Map();
16307
- var gdi322 = null;
16308
- var createFontIndirectW = null;
16309
- var selectObjectFn = null;
16310
- var getObjectW = null;
16311
- function ensureGdi() {
16312
- if (gdi322 !== null)
16313
- return;
16314
- gdi322 = win2.LoadLibrary("gdi32.dll");
16315
- if (!gdi322)
16316
- return;
16317
- createFontIndirectW = win2.GetProcAddress(gdi322, "CreateFontIndirectW");
16318
- selectObjectFn = win2.GetProcAddress(gdi322, "SelectObject");
16319
- getObjectW = win2.GetProcAddress(gdi322, "GetObjectW");
16320
- }
16321
- var user322 = null;
16322
- var loadCursorW = null;
16323
- var setCursorFn = null;
16324
- var screenToClient = null;
16325
- function ensureUser32() {
16326
- if (user322 !== null)
16327
- return;
16328
- user322 = win2.LoadLibrary("user32.dll");
16329
- if (!user322)
16330
- return;
16331
- loadCursorW = win2.GetProcAddress(user322, "LoadCursorW");
16332
- setCursorFn = win2.GetProcAddress(user322, "SetCursor");
16333
- screenToClient = win2.GetProcAddress(user322, "ScreenToClient");
16334
- }
16335
17381
  function getCellFont(hwnd, style) {
16336
17382
  const key = (style.bold ? "b" : "") + (style.italic ? "i" : "") + (style.underline ? "u" : "");
16337
17383
  if (key === "")
@@ -16339,39 +17385,37 @@ function getCellFont(hwnd, style) {
16339
17385
  const cached = fontCache.get(key);
16340
17386
  if (cached !== void 0)
16341
17387
  return cached === 0 ? null : cached;
16342
- ensureGdi();
16343
- if (!createFontIndirectW || !getObjectW || !hwnd)
17388
+ if (!hwnd)
16344
17389
  return null;
16345
- const lf = new ArrayBuffer(92);
16346
- const dv = new DataView(lf);
16347
- const cur = gui10.SendMessage(hwnd, 49, 0, 0);
17390
+ let base = { lfHeight: -13 };
17391
+ const cur = gui9.SendMessage(hwnd, 49, 0, 0);
16348
17392
  if (cur) {
16349
- const got = ffi5.ffiCall(getObjectW, [ffi5.FFI_TYPE_UINT64, ffi5.FFI_TYPE_SINT32, ffi5.FFI_TYPE_POINTER], [cur, 92, lf], ffi5.FFI_TYPE_SINT32);
16350
- if (!got)
17393
+ const lf = LOGFONTW.alloc();
17394
+ if (!GetObject(cur, LOGFONTW.size, lf))
16351
17395
  return null;
16352
- } else {
16353
- dv.setInt32(0, -13, true);
17396
+ base = LOGFONTW.decode(lf);
16354
17397
  }
16355
- if (style.bold)
16356
- dv.setInt32(16, 700, true);
16357
- if (style.italic)
16358
- dv.setUint8(20, 1);
16359
- if (style.underline)
16360
- dv.setUint8(21, 1);
16361
- const h = ffi5.ffiCall(createFontIndirectW, [ffi5.FFI_TYPE_POINTER], [lf], ffi5.FFI_TYPE_UINT64);
16362
- fontCache.set(key, h === 0 ? 0 : h);
16363
- return h === 0 ? null : h;
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
+ });
17407
+ fontCache.set(key, h ? h : 0);
17408
+ return h ? h : null;
16364
17409
  }
16365
17410
  function handleCustomDraw(lParam, columns, data, hwnd) {
16366
- const stage = readU32(lParam, CD_STAGE);
17411
+ const { dwDrawStage: stage } = NMCUSTOMDRAW.decode(lParam);
16367
17412
  if (stage === 1)
16368
17413
  return 32;
16369
17414
  if (stage === 65537)
16370
17415
  return 32;
16371
17416
  if (stage === 196609) {
16372
- const colIndex = readI323(lParam, CD_SUBITEM);
16373
- const row = readI323(lParam, CD_ITEM);
16374
- const style = resolveCellStyle(columns, data, row, colIndex);
17417
+ const cd = NMLVCUSTOMDRAW.decode(lParam);
17418
+ const style = resolveCellStyle(columns, data, cd.dwItemSpec, cd.iSubItem);
16375
17419
  if (!style)
16376
17420
  return 0;
16377
17421
  if (style.color !== void 0)
@@ -16379,12 +17423,9 @@ function handleCustomDraw(lParam, columns, data, hwnd) {
16379
17423
  if (style.background !== void 0)
16380
17424
  writeU32(lParam, CD_CLRTEXTBK, style.background);
16381
17425
  const hfont = getCellFont(hwnd, style);
16382
- if (hfont && selectObjectFn) {
16383
- const hdc = readU64(lParam, CD_HDC);
16384
- if (hdc) {
16385
- ffi5.ffiCall(selectObjectFn, [ffi5.FFI_TYPE_UINT64, ffi5.FFI_TYPE_UINT64], [hdc, hfont], ffi5.FFI_TYPE_UINT64);
16386
- return 2;
16387
- }
17426
+ if (hfont && cd.hdc) {
17427
+ SelectObject(cd.hdc, hfont);
17428
+ return 2;
16388
17429
  }
16389
17430
  }
16390
17431
  return 0;
@@ -16415,20 +17456,26 @@ function resolveCellStyle(columns, data, row, colIndex) {
16415
17456
  return style || void 0;
16416
17457
  }
16417
17458
  function makeLVItem(i, sub, text, image) {
16418
- const b = new ArrayBuffer(84);
16419
- const dv = new DataView(b);
16420
- dv.setInt32(4, i, true);
16421
- dv.setInt32(8, sub, true);
16422
- let mask = 1;
16423
- if (image !== void 0) {
16424
- mask |= 2;
16425
- dv.setInt32(36, image, true);
16426
- }
16427
- dv.setUint32(0, mask, true);
16428
- const textBuf = textToUtf162(text);
16429
- dv.setBigUint64(24, BigInt(bufPtr2(textBuf)), true);
16430
- b.__textBuf = textBuf;
16431
- return b;
17459
+ const textBuf = WCHAR.encode(text);
17460
+ const b6 = LVITEMW.encode({
17461
+ mask: 1 | (image !== void 0 ? 2 : 0),
17462
+ iItem: i,
17463
+ iSubItem: sub,
17464
+ state: 0,
17465
+ stateMask: 0,
17466
+ pszText: textBuf.ptr,
17467
+ cchTextMax: 0,
17468
+ iImage: image ?? 0,
17469
+ lParam: 0,
17470
+ iIndent: 0,
17471
+ iGroupId: 0,
17472
+ cColumns: 0,
17473
+ puColumns: 0,
17474
+ piColFmt: 0,
17475
+ iGroup: 0
17476
+ });
17477
+ b6.__textBuf = textBuf;
17478
+ return b6;
16432
17479
  }
16433
17480
  var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, data, style, icons, iconSize, getIcon }, ref) {
16434
17481
  const lvRef = (0, import_react9.useRef)(null);
@@ -16440,36 +17487,36 @@ var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, d
16440
17487
  const il = iconListRef.current;
16441
17488
  iconListRef.current = 0;
16442
17489
  if (il) {
16443
- gui10.SendMessage(h, 4099, 1, 0);
16444
- gui10.ImageListDestroy(il);
17490
+ gui9.SendMessage(h, 4099, 1, 0);
17491
+ gui9.ImageListDestroy(il);
16445
17492
  }
16446
17493
  if (!icons || icons.length === 0)
16447
17494
  return;
16448
17495
  const size = iconSize ?? 32;
16449
- const img = gui10.ImageListCreate(size, size, 32, icons.length, 1);
17496
+ const img = gui9.ImageListCreate(size, size, 32, icons.length, 1);
16450
17497
  if (!img)
16451
17498
  return;
16452
17499
  for (const p of icons) {
16453
- const hbm = gui10.CreateBitmapFromPixels(size, size, p);
17500
+ const hbm = gui9.CreateBitmapFromPixels(size, size, p);
16454
17501
  if (hbm) {
16455
- gui10.ImageListAdd(img, hbm);
16456
- gui10.DeleteObject(hbm);
17502
+ gui9.ImageListAdd(img, hbm);
17503
+ DeleteObject(hbm);
16457
17504
  }
16458
17505
  }
16459
- gui10.SendMessage(h, 4099, 1, img);
17506
+ gui9.SendMessage(h, 4099, 1, img);
16460
17507
  iconListRef.current = img;
16461
17508
  }, [icons, iconSize]);
16462
17509
  (0, import_react9.useEffect)(() => {
16463
17510
  const h = lvRef.current;
16464
17511
  if (!h)
16465
17512
  return;
16466
- const hdr = gui10.SendMessage(h, 4127, 0, 0);
17513
+ const hdr = gui9.SendMessage(h, 4127, 0, 0);
16467
17514
  if (hdr) {
16468
- let n2 = gui10.SendMessage(hdr, 4608, 0, 0);
17515
+ let n2 = gui9.SendMessage(hdr, 4608, 0, 0);
16469
17516
  for (let k = n2 - 1; k >= 0; k--)
16470
- gui10.SendMessage(h, 4124, k, 0);
17517
+ gui9.SendMessage(h, 4124, k, 0);
16471
17518
  }
16472
- gui10.SendMessage(
17519
+ gui9.SendMessage(
16473
17520
  h,
16474
17521
  4150,
16475
17522
  0,
@@ -16478,37 +17525,43 @@ var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, d
16478
17525
  );
16479
17526
  const n = columns.length;
16480
17527
  for (let j = 0; j < n; j++) {
16481
- const titleBuf = textToUtf162(columns[j].name);
16482
- const lvc = new ArrayBuffer(52);
16483
- const dv = new DataView(lvc);
16484
- dv.setUint32(0, 4 | 2 | 1, true);
16485
- dv.setInt32(4, alignToFmt(columns[j].align), true);
16486
- dv.setInt32(8, columns[j].width ?? 100, true);
16487
- dv.setBigUint64(16, BigInt(bufPtr2(titleBuf)), true);
16488
- dv.setInt32(28, j, true);
17528
+ const titleBuf = WCHAR.encode(columns[j].name);
17529
+ const lvc = LVCOLUMNW.encode({
17530
+ mask: 4 | 2 | 1,
17531
+ fmt: alignToFmt(columns[j].align),
17532
+ cx: columns[j].width ?? 100,
17533
+ pszText: titleBuf.ptr,
17534
+ cchTextMax: 0,
17535
+ iSubItem: j,
17536
+ iImage: 0,
17537
+ iOrder: 0,
17538
+ cxMin: 0,
17539
+ cxDefault: 0,
17540
+ cxIdeal: 0
17541
+ });
16489
17542
  lvc.__titleBuf = titleBuf;
16490
- gui10.SendMessage(h, 4193, j, bufPtr2(lvc));
17543
+ gui9.SendMessage(h, 4193, j, lvc.ptr);
16491
17544
  }
16492
17545
  }, [columns]);
16493
17546
  (0, import_react9.useEffect)(() => {
16494
17547
  const h = lvRef.current;
16495
17548
  if (!h)
16496
17549
  return;
16497
- gui10.SendMessage(h, 4105, 0, 0);
17550
+ gui9.SendMessage(h, 4105, 0, 0);
16498
17551
  const nCols = columns.length;
16499
17552
  for (let i = 0; i < data.length; i++) {
16500
17553
  const record = data[i];
16501
17554
  const img = getIcon ? getIcon(record, i) : void 0;
16502
17555
  const itemBuf = makeLVItem(i, 0, cellText(record, columns[0], i), img);
16503
- gui10.SendMessage(h, 4173, 0, bufPtr2(itemBuf));
17556
+ gui9.SendMessage(h, 4173, 0, itemBuf.ptr);
16504
17557
  for (let j = 1; j < nCols; j++) {
16505
17558
  const subBuf = makeLVItem(i, j, cellText(record, columns[j], i));
16506
- gui10.SendMessage(h, 4172, 0, bufPtr2(subBuf));
17559
+ gui9.SendMessage(h, 4172, 0, subBuf.ptr);
16507
17560
  }
16508
17561
  }
16509
17562
  for (let j = 0; j < columns.length; j++) {
16510
17563
  if (columns[j].width == null) {
16511
- gui10.SendMessage(
17564
+ gui9.SendMessage(
16512
17565
  h,
16513
17566
  4126,
16514
17567
  j,
@@ -16520,19 +17573,17 @@ var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, d
16520
17573
  }, [data, columns, getIcon]);
16521
17574
  return (0, import_jsx_runtime8.jsx)("w", { type: "STATIC", ws: 268435456 | 33554432, style: { ...style, flexDirection: "column", alignItems: "stretch" }, ref, onEvent: (e) => {
16522
17575
  if (e.msg === 78) {
16523
- const code = readI323(e.lParam, NM_CODE);
17576
+ const code = nmCode(e.lParam);
16524
17577
  if (code === -12) {
16525
17578
  return handleCustomDraw(e.lParam, columns, data, lvRef.current);
16526
17579
  }
16527
17580
  if (code === -100) {
16528
- const uNewState = readU32(e.lParam, 32);
16529
- const uOldState = readU32(e.lParam, 36);
17581
+ const { uNewState, uOldState } = NMLISTVIEW.decode(e.lParam);
16530
17582
  if ((uNewState & 2) !== (uOldState & 2))
16531
17583
  return 1;
16532
17584
  }
16533
17585
  if (code === -2) {
16534
- const iItem = readI323(e.lParam, NMIA_ITEM);
16535
- const iSubItem = readI323(e.lParam, NMIA_SUBITEM);
17586
+ const { iItem, iSubItem } = NMLISTVIEW.decode(e.lParam);
16536
17587
  const col = columns[iSubItem];
16537
17588
  const record = data[iItem];
16538
17589
  if (col?.onCellClick && record !== void 0)
@@ -16550,33 +17601,20 @@ var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, d
16550
17601
  const h = lvRef.current;
16551
17602
  if (!h)
16552
17603
  return;
16553
- ensureUser32();
16554
- if (!loadCursorW || !setCursorFn || !screenToClient)
16555
- return;
16556
- const sp = gui10.GetCursorPos();
16557
- if (!sp)
17604
+ const pt = POINT.alloc();
17605
+ if (!GetCursorPos(pt.ptr))
16558
17606
  return;
16559
- const sbuf = new ArrayBuffer(8);
16560
- const sdv = new DataView(sbuf);
16561
- sdv.setInt32(0, sp[0], true);
16562
- sdv.setInt32(4, sp[1], true);
16563
- ffi5.ffiCall(screenToClient, [ffi5.FFI_TYPE_UINT64, ffi5.FFI_TYPE_POINTER], [h, sbuf], ffi5.FFI_TYPE_SINT32);
16564
- const lvhi = new ArrayBuffer(24);
16565
- const lvd = new DataView(lvhi);
16566
- lvd.setInt32(0, sdv.getInt32(0, true), true);
16567
- lvd.setInt32(4, sdv.getInt32(4, true), true);
16568
- lvd.setInt32(12, -1, true);
16569
- lvd.setInt32(16, -1, true);
16570
- const lvhiPtr = bufPtr2(lvhi);
16571
- gui10.SendMessage(h, 4153, 0, lvhiPtr);
16572
- const iItem = readI323(lvhiPtr, 12);
16573
- const iSubItem = readI323(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);
16574
17612
  const style2 = resolveCellStyle(columns, data, iItem, iSubItem);
16575
17613
  if (!style2 || style2.cursor === void 0)
16576
17614
  return;
16577
- const hc = ffi5.ffiCall(loadCursorW, [ffi5.FFI_TYPE_UINT64, ffi5.FFI_TYPE_UINT64], [0, style2.cursor], ffi5.FFI_TYPE_UINT64);
17615
+ const hc = LoadCursor(NULL, style2.cursor);
16578
17616
  if (hc) {
16579
- ffi5.ffiCall(setCursorFn, [ffi5.FFI_TYPE_UINT64], [hc], ffi5.FFI_TYPE_UINT64);
17617
+ SetCursor(hc);
16580
17618
  return 1;
16581
17619
  }
16582
17620
  return;
@@ -16586,7 +17624,7 @@ var ListView = (0, import_react9.forwardRef)(function ListViewInner({ columns, d
16586
17624
  // _build/lib/react-qw/components/ProgressBar.js
16587
17625
  var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1);
16588
17626
  var import_react10 = __toESM(require_react(), 1);
16589
- import * as gui11 from "gui";
17627
+ import * as gui10 from "gui";
16590
17628
  var ProgressBar = (0, import_react10.forwardRef)(({ value = 0, max = 100, style, smooth }, ref) => {
16591
17629
  const pbRef = (0, import_react10.useRef)(null);
16592
17630
  const ws = 268435456 | 8388608 | (smooth ? 1 : 0);
@@ -16594,8 +17632,8 @@ var ProgressBar = (0, import_react10.forwardRef)(({ value = 0, max = 100, style,
16594
17632
  const h = pbRef.current;
16595
17633
  if (!h)
16596
17634
  return;
16597
- gui11.SendMessage(h, 1030, 0, max);
16598
- 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);
16599
17637
  }, [value, max]);
16600
17638
  return (0, import_jsx_runtime9.jsx)("w", { type: "msctls_progress32", ws, style, ref: (h) => {
16601
17639
  pbRef.current = h;
@@ -16609,7 +17647,7 @@ var ProgressBar = (0, import_react10.forwardRef)(({ value = 0, max = 100, style,
16609
17647
  // _build/lib/react-qw/components/RadioButton.js
16610
17648
  var import_jsx_runtime10 = __toESM(require_jsx_runtime(), 1);
16611
17649
  var import_react11 = __toESM(require_react(), 1);
16612
- import * as gui12 from "gui";
17650
+ import * as gui11 from "gui";
16613
17651
  var RadioButton = (0, import_react11.forwardRef)(({ checked: controlledChecked, defaultChecked = false, onChange, label, style, disabled }, ref) => {
16614
17652
  const [internalChecked, setInternalChecked] = (0, import_react11.useState)(defaultChecked);
16615
17653
  const isControlled = controlledChecked !== void 0;
@@ -16619,7 +17657,7 @@ var RadioButton = (0, import_react11.forwardRef)(({ checked: controlledChecked,
16619
17657
  const h = rbRef.current;
16620
17658
  if (!h)
16621
17659
  return;
16622
- gui12.SendMessage(h, 241, displayChecked ? 1 : 0, 0);
17660
+ gui11.SendMessage(h, 241, displayChecked ? 1 : 0, 0);
16623
17661
  }, [displayChecked]);
16624
17662
  return (0, import_jsx_runtime10.jsx)("w", { type: "BUTTON", text: label ?? "", ws: 268435456 | 9, style, disabled, ref: (h) => {
16625
17663
  rbRef.current = h;
@@ -16629,7 +17667,7 @@ var RadioButton = (0, import_react11.forwardRef)(({ checked: controlledChecked,
16629
17667
  ref.current = h;
16630
17668
  }, onEvent: (e) => {
16631
17669
  if (e.msg === 514) {
16632
- const newChecked = gui12.SendMessage(e.hwnd, 240, 0, 0) !== 0;
17670
+ const newChecked = gui11.SendMessage(e.hwnd, 240, 0, 0) !== 0;
16633
17671
  if (newChecked !== displayChecked) {
16634
17672
  if (!isControlled)
16635
17673
  setInternalChecked(newChecked);
@@ -16642,24 +17680,27 @@ var RadioButton = (0, import_react11.forwardRef)(({ checked: controlledChecked,
16642
17680
  // _build/lib/react-qw/components/ScrollView.js
16643
17681
  var import_jsx_runtime11 = __toESM(require_jsx_runtime(), 1);
16644
17682
  var import_react12 = __toESM(require_react(), 1);
16645
- import * as gui13 from "gui";
17683
+ import * as gui12 from "gui";
16646
17684
  var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth, contentHeight }, ref) => {
16647
17685
  const svRef = (0, import_react12.useRef)(null);
16648
17686
  const contentRef = (0, import_react12.useRef)(null);
16649
17687
  const scrollXRef = (0, import_react12.useRef)(0);
16650
17688
  const scrollYRef = (0, import_react12.useRef)(0);
16651
17689
  function updateScroll(sv, content) {
16652
- const svRect = gui13.GetClientRect(sv);
17690
+ const svRect = gui12.GetClientRect(sv);
16653
17691
  if (!svRect)
16654
17692
  return;
16655
17693
  const svW = svRect.right - svRect.left;
16656
17694
  const svH = svRect.bottom - svRect.top;
16657
- 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);
16658
17699
  const natW = Math.round((contentWidth ?? svW / scale) * scale);
16659
17700
  const natH = Math.round((contentHeight ?? svH / scale) * scale);
16660
17701
  scrollXRef.current = Math.max(0, Math.min(scrollXRef.current, natW - svW));
16661
17702
  scrollYRef.current = Math.max(0, Math.min(scrollYRef.current, natH - svH));
16662
- gui13.SetWindowPos(
17703
+ SetWindowPos(
16663
17704
  content,
16664
17705
  0,
16665
17706
  -scrollXRef.current,
@@ -16671,18 +17712,18 @@ var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth
16671
17712
  );
16672
17713
  forceFlexLayout(content);
16673
17714
  if (natW > svW) {
16674
- gui13.SetScrollInfo(sv, 0, { min: 0, max: natW - 1, page: svW, pos: scrollXRef.current }, true);
16675
- 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);
16676
17717
  } else {
16677
17718
  scrollXRef.current = 0;
16678
- gui13.ShowScrollBar(sv, 0, false);
17719
+ ShowScrollBar(sv, 0, 0);
16679
17720
  }
16680
17721
  if (natH > svH) {
16681
- gui13.SetScrollInfo(sv, 1, { min: 0, max: natH - 1, page: svH, pos: scrollYRef.current }, true);
16682
- 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);
16683
17724
  } else {
16684
17725
  scrollYRef.current = 0;
16685
- gui13.ShowScrollBar(sv, 1, false);
17726
+ ShowScrollBar(sv, 1, 0);
16686
17727
  }
16687
17728
  }
16688
17729
  (0, import_react12.useLayoutEffect)(() => {
@@ -16698,7 +17739,7 @@ var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth
16698
17739
  } else {
16699
17740
  scrollXRef.current = newPos;
16700
17741
  }
16701
- gui13.SetWindowPos(
17742
+ SetWindowPos(
16702
17743
  content,
16703
17744
  0,
16704
17745
  -scrollXRef.current,
@@ -16708,14 +17749,14 @@ var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth
16708
17749
  1 | 4
16709
17750
  /* gui.SetWindowPosFlag.SWP_NOZORDER */
16710
17751
  );
16711
- gui13.SetScrollInfo(sv, bar, { pos: newPos }, true);
17752
+ gui12.SetScrollInfo(sv, bar, { pos: newPos }, true);
16712
17753
  }
16713
17754
  function handleScroll(e, bar) {
16714
17755
  const sv = svRef.current;
16715
17756
  const content = contentRef.current;
16716
17757
  if (!sv || !content)
16717
17758
  return;
16718
- const info = gui13.GetScrollInfo(sv, bar);
17759
+ const info = gui12.GetScrollInfo(sv, bar);
16719
17760
  const maxPos = info.max - info.page + 1;
16720
17761
  const code = e.wParam & 65535;
16721
17762
  const ref_ = bar === 1 ? scrollYRef : scrollXRef;
@@ -16749,7 +17790,7 @@ var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth
16749
17790
  if (!isHorz && contentHeight === void 0)
16750
17791
  return;
16751
17792
  const bar = isHorz ? 0 : 1;
16752
- const info = gui13.GetScrollInfo(sv, bar);
17793
+ const info = gui12.GetScrollInfo(sv, bar);
16753
17794
  const maxPos = info.max - info.page + 1;
16754
17795
  const ref_ = isHorz ? scrollXRef : scrollYRef;
16755
17796
  let newPos = ref_.current + dy;
@@ -16766,7 +17807,7 @@ var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth
16766
17807
  }, onEvent: {
16767
17808
  fn: (e) => {
16768
17809
  if (e.msg === 132 || e.msg === 161) {
16769
- return gui13.DefWindowProc(e.hwnd, e.msg, e.wParam, e.lParam);
17810
+ return DefWindowProc(e.hwnd, e.msg, e.wParam, e.lParam);
16770
17811
  }
16771
17812
  if (e.msg === 277) {
16772
17813
  handleScroll(
@@ -16798,7 +17839,7 @@ var ScrollView = (0, import_react12.forwardRef)(({ children, style, contentWidth
16798
17839
  // _build/lib/react-qw/components/Slider.js
16799
17840
  var import_jsx_runtime12 = __toESM(require_jsx_runtime(), 1);
16800
17841
  var import_react13 = __toESM(require_react(), 1);
16801
- import * as gui14 from "gui";
17842
+ import * as gui13 from "gui";
16802
17843
  var Slider = (0, import_react13.forwardRef)(({ value, onChange, min = 0, max = 100, vertical = false, disabled, style }, ref) => {
16803
17844
  const wrapperRef = (0, import_react13.useRef)(null);
16804
17845
  const sliderRef = (0, import_react13.useRef)(null);
@@ -16807,14 +17848,14 @@ var Slider = (0, import_react13.forwardRef)(({ value, onChange, min = 0, max = 1
16807
17848
  if (!h)
16808
17849
  return;
16809
17850
  const lParam = min & 65535 | (max & 65535) << 16;
16810
- gui14.SendMessage(h, 1030, 0, lParam);
16811
- gui14.SendMessage(h, 1029, 1, value);
17851
+ gui13.SendMessage(h, 1030, 0, lParam);
17852
+ gui13.SendMessage(h, 1029, 1, value);
16812
17853
  }, [min, max]);
16813
17854
  (0, import_react13.useEffect)(() => {
16814
17855
  const h = sliderRef.current;
16815
17856
  if (!h)
16816
17857
  return;
16817
- gui14.SendMessage(h, 1029, 1, value);
17858
+ gui13.SendMessage(h, 1029, 1, value);
16818
17859
  }, [value]);
16819
17860
  const tbStyle = 268435456 | 65536 | 1 | (vertical ? 2 : 0);
16820
17861
  return (0, import_jsx_runtime12.jsx)("w", { type: "STATIC", ws: 268435456 | 33554432, style, ref: (h) => {
@@ -16825,13 +17866,13 @@ var Slider = (0, import_react13.forwardRef)(({ value, onChange, min = 0, max = 1
16825
17866
  ref.current = h;
16826
17867
  }, onEvent: (e) => {
16827
17868
  if (e.msg === 132 || e.msg === 161) {
16828
- return gui14.DefWindowProc(e.hwnd, e.msg, e.wParam, e.lParam);
17869
+ return DefWindowProc(e.hwnd, e.msg, e.wParam, e.lParam);
16829
17870
  }
16830
17871
  if (e.msg === 276 || e.msg === 277) {
16831
17872
  const h = sliderRef.current;
16832
17873
  if (!h)
16833
17874
  return 0;
16834
- const pos = gui14.SendMessage(h, 1024, 0, 0);
17875
+ const pos = gui13.SendMessage(h, 1024, 0, 0);
16835
17876
  onChange?.(pos);
16836
17877
  return 0;
16837
17878
  }
@@ -16844,18 +17885,7 @@ var Slider = (0, import_react13.forwardRef)(({ value, onChange, min = 0, max = 1
16844
17885
  // _build/lib/react-qw/components/Tab.js
16845
17886
  var import_jsx_runtime13 = __toESM(require_jsx_runtime(), 1);
16846
17887
  var import_react14 = __toESM(require_react(), 1);
16847
- import * as gui15 from "gui";
16848
- import * as ffi6 from "ffi";
16849
- function textToUtf163(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 readI324(ptr, offset) {
16857
- return ffi6.readByte(ptr + offset) | ffi6.readByte(ptr + offset + 1) << 8 | ffi6.readByte(ptr + offset + 2) << 16 | ffi6.readByte(ptr + offset + 3) << 24;
16858
- }
17888
+ import * as gui14 from "gui";
16859
17889
  var Tab = (0, import_react14.forwardRef)(({ tabs, selectedIndex: controlledIndex, defaultSelectedIndex = 0, onChange, style }, ref) => {
16860
17890
  const [internalIndex, setInternalIndex] = (0, import_react14.useState)(defaultSelectedIndex);
16861
17891
  const isControlled = controlledIndex !== void 0;
@@ -16865,32 +17895,36 @@ var Tab = (0, import_react14.forwardRef)(({ tabs, selectedIndex: controlledIndex
16865
17895
  const h = tabHwnd.current;
16866
17896
  if (!h)
16867
17897
  return;
16868
- gui15.SendMessage(h, 4873, 0, 0);
17898
+ gui14.SendMessage(h, 4873, 0, 0);
16869
17899
  for (let i = 0; i < tabs.length; i++) {
16870
- const titleBuf = textToUtf163(tabs[i].title);
16871
- const tci = new ArrayBuffer(40);
16872
- const dv = new DataView(tci);
16873
- dv.setUint32(0, 1, true);
16874
- dv.setBigUint64(16, BigInt(ffi6.bufferPtr(titleBuf)), true);
16875
- dv.setInt32(24, tabs[i].title.length + 1, true);
16876
- const tciPtr = ffi6.bufferPtr(tci);
16877
- gui15.SendMessage(h, 4926, i, tciPtr);
17900
+ const titleBuf = WCHAR.encode(tabs[i].title);
17901
+ const tci = TCITEMW.encode({
17902
+ mask: 1,
17903
+ dwState: 0,
17904
+ dwStateMask: 0,
17905
+ pszText: titleBuf.ptr,
17906
+ cchTextMax: tabs[i].title.length + 1,
17907
+ iImage: 0,
17908
+ lParam: 0
17909
+ });
17910
+ const tciPtr = tci.ptr;
17911
+ gui14.SendMessage(h, 4926, i, tciPtr);
16878
17912
  }
16879
- gui15.SendMessage(h, 4876, sel, 0);
17913
+ gui14.SendMessage(h, 4876, sel, 0);
16880
17914
  }, [tabs]);
16881
17915
  (0, import_react14.useEffect)(() => {
16882
17916
  const h = tabHwnd.current;
16883
17917
  if (h)
16884
- gui15.SendMessage(h, 4876, sel, 0);
17918
+ gui14.SendMessage(h, 4876, sel, 0);
16885
17919
  }, [sel]);
16886
17920
  return (0, import_jsx_runtime13.jsxs)("w", { type: "STATIC", ws: 268435456 | 33554432, style: { ...style, flexDirection: "column", alignItems: "stretch" }, ref, onEvent: (e) => {
16887
17921
  if (e.msg === 78) {
16888
17922
  const h = tabHwnd.current;
16889
17923
  if (!h)
16890
17924
  return;
16891
- const code = readI324(e.lParam, 16);
17925
+ const code = nmCode(e.lParam);
16892
17926
  if (code === -552 || code === -2) {
16893
- const newSel = gui15.SendMessage(h, 4875, 0, 0);
17927
+ const newSel = gui14.SendMessage(h, 4875, 0, 0);
16894
17928
  if (newSel !== sel) {
16895
17929
  if (!isControlled)
16896
17930
  setInternalIndex(newSel);
@@ -16903,79 +17937,50 @@ var Tab = (0, import_react14.forwardRef)(({ tabs, selectedIndex: controlledIndex
16903
17937
 
16904
17938
  // _build/lib/react-qw/components/Tooltip.js
16905
17939
  var import_react15 = __toESM(require_react(), 1);
16906
- import * as gui16 from "gui";
16907
- import * as ffi7 from "ffi";
17940
+ import * as gui15 from "gui";
16908
17941
 
16909
17942
  // _build/lib/react-qw/components/TreeView.js
16910
17943
  var import_jsx_runtime14 = __toESM(require_jsx_runtime(), 1);
16911
17944
  var import_react16 = __toESM(require_react(), 1);
16912
- import * as gui17 from "gui";
16913
- import * as ffi8 from "ffi";
16914
- function textToUtf164(s) {
16915
- const buf = new ArrayBuffer((s.length + 1) * 2);
16916
- const dv = new DataView(buf);
16917
- for (let i = 0; i < s.length; i++)
16918
- dv.setUint16(i * 2, s.charCodeAt(i), true);
16919
- return buf;
16920
- }
16921
- function readI325(ptr, offset) {
16922
- return ffi8.readByte(ptr + offset) | ffi8.readByte(ptr + offset + 1) << 8 | ffi8.readByte(ptr + offset + 2) << 16 | ffi8.readByte(ptr + offset + 3) << 24;
16923
- }
16924
- function bufPtr3(buf) {
16925
- return ffi8.bufferPtr(buf);
16926
- }
16927
- function setPtr(dv, offset, ptr) {
16928
- dv.setUint32(offset, ptr & 4294967295, true);
16929
- dv.setUint32(offset + 4, Math.floor(ptr / 4294967296), true);
16930
- }
17945
+ import * as gui16 from "gui";
16931
17946
  function buildTvItem(textPtr, cChildren) {
16932
17947
  let mask = 1;
16933
17948
  if (cChildren > 0)
16934
17949
  mask |= 64;
16935
- const buf = new ArrayBuffer(56);
16936
- const dv = new DataView(buf);
16937
- dv.setUint32(0, mask, true);
16938
- setPtr(dv, 8, 0);
16939
- dv.setUint32(16, 0, true);
16940
- dv.setUint32(20, 0, true);
16941
- setPtr(dv, 24, textPtr);
16942
- dv.setInt32(32, 260, true);
16943
- dv.setInt32(36, 0, true);
16944
- dv.setInt32(40, 0, true);
16945
- dv.setInt32(44, cChildren, true);
16946
- setPtr(dv, 48, 0);
16947
- return buf;
16948
- }
16949
- function buildTvInsertStruct(hParent, hInsertAfter, itemBuf) {
16950
- const buf = new ArrayBuffer(72);
16951
- const dv = new DataView(buf);
16952
- setPtr(dv, 0, hParent);
16953
- setPtr(dv, 8, hInsertAfter);
16954
- const src = new DataView(itemBuf);
16955
- for (let i = 0; i < 56; i += 4)
16956
- dv.setUint32(16 + i, src.getUint32(i, true), true);
16957
- return buf;
17950
+ return TVITEM.encode({
17951
+ mask,
17952
+ hItem: 0,
17953
+ state: 0,
17954
+ stateMask: 0,
17955
+ pszText: textPtr,
17956
+ cchTextMax: 260,
17957
+ iImage: 0,
17958
+ iSelectedImage: 0,
17959
+ cChildren,
17960
+ lParam: 0
17961
+ });
16958
17962
  }
16959
17963
  function insertItems(hTree, nodes, parentHandle, hItemMap, keyMap) {
16960
17964
  for (const node of nodes) {
16961
17965
  const cChildren = node.children && node.children.length > 0 ? 1 : 0;
16962
- const textBuf = textToUtf164(node.label);
16963
- const itemBuf = buildTvItem(bufPtr3(textBuf), cChildren);
16964
- const tvins = buildTvInsertStruct(parentHandle, -65536, itemBuf);
16965
- 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);
16966
17971
  hItemMap.set(hItem, node);
16967
17972
  if (node.key)
16968
17973
  keyMap.set(node.key, hItem);
16969
17974
  if (node.children && node.children.length > 0) {
16970
17975
  insertItems(hTree, node.children, hItem, hItemMap, keyMap);
16971
- gui17.SendMessage(hTree, 4354, 2, hItem);
17976
+ gui16.SendMessage(hTree, 4354, 2, hItem);
16972
17977
  }
16973
17978
  }
16974
17979
  }
16975
17980
  function deleteAllItems(hTree) {
16976
- const n = gui17.SendMessage(hTree, 4357, 0, 0);
17981
+ const n = gui16.SendMessage(hTree, 4357, 0, 0);
16977
17982
  if (n > 0)
16978
- gui17.SendMessage(
17983
+ gui16.SendMessage(
16979
17984
  hTree,
16980
17985
  4353,
16981
17986
  1,
@@ -17007,7 +18012,7 @@ var TreeView = (0, import_react16.forwardRef)(function TreeViewInner({ data, onS
17007
18012
  const h = tvRef.current;
17008
18013
  if (!h)
17009
18014
  return;
17010
- gui17.SendMessage(
18015
+ gui16.SendMessage(
17011
18016
  h,
17012
18017
  4396,
17013
18018
  0,
@@ -17023,16 +18028,16 @@ var TreeView = (0, import_react16.forwardRef)(function TreeViewInner({ data, onS
17023
18028
  return;
17024
18029
  const hItem = keyMapRef.current.get(selKey);
17025
18030
  if (hItem !== void 0)
17026
- gui17.SendMessage(h, 4363, 9, hItem);
18031
+ gui16.SendMessage(h, 4363, 9, hItem);
17027
18032
  }, [selKey]);
17028
18033
  return (0, import_jsx_runtime14.jsx)("w", { type: "STATIC", ws: 268435456 | 33554432, style: { ...style, flexDirection: "column", alignItems: "stretch" }, ref, onEvent: (e) => {
17029
18034
  if (e.msg === 78) {
17030
- const code = readI325(e.lParam, 16);
18035
+ const code = nmCode(e.lParam);
17031
18036
  if (code === -451) {
17032
18037
  const h = tvRef.current;
17033
18038
  if (!h)
17034
18039
  return;
17035
- const hCaret = gui17.SendMessage(h, 4362, 9, 0);
18040
+ const hCaret = gui16.SendMessage(h, 4362, 9, 0);
17036
18041
  const node = hItemMapRef.current.get(hCaret) ?? null;
17037
18042
  const key = node?.key ?? null;
17038
18043
  if (!isControlled)
@@ -17048,99 +18053,63 @@ var TreeView = (0, import_react16.forwardRef)(function TreeViewInner({ data, onS
17048
18053
  // _build/lib/react-qw/components/PathPicker.js
17049
18054
  var import_jsx_runtime15 = __toESM(require_jsx_runtime(), 1);
17050
18055
  var import_react17 = __toESM(require_react(), 1);
17051
- import * as ffi9 from "ffi";
17052
- import * as win3 from "win";
17053
- var FFI_PTR2 = ffi9.FFI_TYPE_POINTER;
17054
- var FFI_U32 = ffi9.FFI_TYPE_UINT32;
17055
- var _GetOpenFileNameW = 0;
17056
- var _SHBrowseForFolderW = 0;
17057
- var _SHGetPathFromIDListW = 0;
17058
- var _CoTaskMemFree = 0;
17059
- function ensureDlls() {
17060
- if (_GetOpenFileNameW)
17061
- return true;
17062
- const comdlg32 = win3.LoadLibrary("comdlg32.dll");
17063
- const shell32 = win3.LoadLibrary("shell32.dll");
17064
- const ole32 = win3.LoadLibrary("ole32.dll");
17065
- if (!comdlg32 || !shell32 || !ole32)
17066
- return false;
17067
- const load = (lib, name) => win3.GetProcAddress(lib, name) || 0;
17068
- _GetOpenFileNameW = load(comdlg32, "GetOpenFileNameW");
17069
- _SHBrowseForFolderW = load(shell32, "SHBrowseForFolderW");
17070
- _SHGetPathFromIDListW = load(shell32, "SHGetPathFromIDListW");
17071
- _CoTaskMemFree = load(ole32, "CoTaskMemFree");
17072
- return !!_GetOpenFileNameW && !!_SHBrowseForFolderW && !!_SHGetPathFromIDListW && !!_CoTaskMemFree;
17073
- }
17074
- function strToWide(s) {
17075
- return new TextEncoder("utf-16le").encode(s + "\0").buffer;
17076
- }
17077
- var _decoder = new TextDecoder("utf-16le");
17078
- function wideToStr(buf, offset = 0) {
17079
- const str = _decoder.decode(new Uint8Array(buf, offset));
17080
- const nullIdx = str.indexOf("\0");
17081
- return nullIdx >= 0 ? str.substring(0, nullIdx) : str;
17082
- }
17083
- function setPtr2(dv, off, ptr) {
17084
- dv.setUint32(off, ptr & 4294967295, true);
17085
- dv.setUint32(off + 4, Math.floor(ptr / 4294967296), true);
17086
- }
18056
+
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");
18069
+
18070
+ // _build/lib/react-qw/components/PathPicker.js
17087
18071
  function openFileDialog(owner, filter, title, multiple) {
17088
- if (!ensureDlls())
17089
- return null;
17090
- const structBuf = new ArrayBuffer(152);
17091
- const sv = new DataView(structBuf);
17092
- const fileBuf = new ArrayBuffer(260 * 2);
17093
- const filterWide = strToWide(filter);
17094
- const titleWide = title ? strToWide(title) : null;
17095
- sv.setUint32(0, 152, true);
17096
- setPtr2(sv, 8, owner);
17097
- setPtr2(sv, 24, ffi9.bufferPtr(filterWide));
17098
- setPtr2(sv, 48, ffi9.bufferPtr(fileBuf));
17099
- sv.setUint32(56, 260, true);
18072
+ const fileBuf = WCHAR.alloc(260);
18073
+ const filterWide = WCHAR.encode(filter);
18074
+ const titleWide = title ? WCHAR.encode(title) : null;
17100
18075
  let flags = 4096 | 2048 | 8;
17101
18076
  if (multiple)
17102
18077
  flags |= 512;
17103
18078
  flags |= 524288;
17104
- sv.setUint32(96, flags, true);
17105
- if (titleWide)
17106
- setPtr2(sv, 88, ffi9.bufferPtr(titleWide));
17107
- const ret = ffi9.ffiCall(_GetOpenFileNameW, [FFI_PTR2], [structBuf], FFI_U32);
18079
+ const ofn = OPENFILENAMEW.encode({
18080
+ lStructSize: OPENFILENAMEW.size,
18081
+ hwndOwner: owner,
18082
+ lpstrFilter: filterWide.ptr,
18083
+ lpstrFile: fileBuf.ptr,
18084
+ nMaxFile: 260,
18085
+ lpstrTitle: titleWide?.ptr ?? 0,
18086
+ Flags: flags
18087
+ });
18088
+ const ret = GetOpenFileName(ofn);
17108
18089
  if (!ret)
17109
18090
  return null;
17110
18091
  if (!multiple) {
17111
- return wideToStr(fileBuf);
18092
+ return WCHAR.decode(fileBuf);
17112
18093
  }
17113
- const dir = wideToStr(fileBuf);
17114
- let pos = (dir.length + 1) * 2;
17115
- const files = [];
17116
- while (pos < fileBuf.byteLength) {
17117
- const f = wideToStr(fileBuf, pos);
17118
- if (f.length === 0)
17119
- break;
17120
- files.push(dir + "\\" + f);
17121
- pos += (f.length + 1) * 2;
17122
- }
17123
- if (files.length === 0)
17124
- return [dir];
17125
- 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];
17126
18098
  }
17127
18099
  function openFolderDialog(owner, title) {
17128
- if (!ensureDlls())
17129
- return null;
17130
- const structBuf = new ArrayBuffer(64);
17131
- const sv = new DataView(structBuf);
17132
- const titleWide = title ? strToWide(title) : null;
17133
- setPtr2(sv, 0, owner);
17134
- if (titleWide)
17135
- setPtr2(sv, 24, ffi9.bufferPtr(titleWide));
17136
- sv.setUint32(32, 65, true);
17137
- const pidl = ffi9.ffiCall(_SHBrowseForFolderW, [FFI_PTR2], [structBuf], FFI_PTR2);
18100
+ const titleWide = title ? WCHAR.encode(title) : null;
18101
+ const bi = BROWSEINFOW.encode({
18102
+ hwndOwner: owner,
18103
+ lpszTitle: titleWide?.ptr ?? 0,
18104
+ ulFlags: 65
18105
+ });
18106
+ const pidl = SHBrowseForFolder(bi);
17138
18107
  if (!pidl)
17139
18108
  return null;
17140
- const pathBuf = new ArrayBuffer(260 * 2);
17141
- const ok = ffi9.ffiCall(_SHGetPathFromIDListW, [ffi9.FFI_TYPE_UINT64, FFI_PTR2], [pidl, pathBuf], FFI_U32);
17142
- ffi9.ffiCall(_CoTaskMemFree, [ffi9.FFI_TYPE_UINT64], [pidl], ffi9.FFI_TYPE_VOID);
17143
- 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;
17144
18113
  }
17145
18114
  var PathPicker = (0, import_react17.forwardRef)((props, ref) => {
17146
18115
  const { type = "file", filter = "All Files\0*.*\0\0", title, disabled, style } = props;
@@ -17191,7 +18160,7 @@ var rootMap = /* @__PURE__ */ new Map();
17191
18160
  function ensureDefaultClass() {
17192
18161
  if (defaultClassRegistered)
17193
18162
  return DEFAULT_CLASS;
17194
- gui18.RegisterClass(DEFAULT_CLASS, (hwnd, msg, wParam, lParam) => {
18163
+ gui17.RegisterClass(DEFAULT_CLASS, (hwnd, msg, wParam, lParam) => {
17195
18164
  const entry = rootMap.get(hwnd);
17196
18165
  if (msg === 2 && entry) {
17197
18166
  rootMap.delete(hwnd);
@@ -17204,7 +18173,7 @@ function ensureDefaultClass() {
17204
18173
  return result;
17205
18174
  if (msg === 5)
17206
18175
  forceFlexLayout(hwnd);
17207
- return gui18.DefWindowProc(hwnd, msg, wParam, lParam);
18176
+ return DefWindowProc(hwnd, msg, wParam, lParam);
17208
18177
  });
17209
18178
  defaultClassRegistered = true;
17210
18179
  return DEFAULT_CLASS;
@@ -17217,15 +18186,15 @@ function createRoot(container) {
17217
18186
  const ws = (cfg.ws ?? 0) | 13565952;
17218
18187
  const w = (cfg.width ?? 800) * scaleFactor;
17219
18188
  const h = (cfg.height ?? 600) * scaleFactor;
17220
- const [sw, sh] = gui18.GetScreenSize();
18189
+ const [sw, sh] = [GetSystemMetrics(0), GetSystemMetrics(1)];
17221
18190
  const x = cfg.x === void 0 ? (sw - w) / 2 | 0 : cfg.x === -2147483648 ? -2147483648 : cfg.x * scaleFactor;
17222
18191
  const y = cfg.y === void 0 ? (sh - h) / 2 | 0 : cfg.y === -2147483648 ? -2147483648 : cfg.y * scaleFactor;
17223
- 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);
17224
18193
  if (!hwin)
17225
18194
  throw new Error("CreateWindow failed");
17226
18195
  hwnd = hwin;
17227
18196
  if (!cfg.noShowWindow)
17228
- gui18.ShowWindow(hwnd);
18197
+ gui17.ShowWindow(hwnd);
17229
18198
  } else {
17230
18199
  hwnd = container;
17231
18200
  }
@@ -17255,33 +18224,8 @@ function render(element, containerOrConfig, _callback) {
17255
18224
  // _build/examples/PdfCanvas.js
17256
18225
  var import_jsx_runtime16 = __toESM(require_jsx_runtime(), 1);
17257
18226
  var import_react18 = __toESM(require_react(), 1);
17258
- import * as win4 from "win";
17259
- import * as ffi10 from "ffi";
17260
- var _user32 = win4.LoadLibrary("user32.dll");
17261
- var _gdi32 = win4.LoadLibrary("gdi32.dll");
17262
- if (!_user32 || !_gdi32)
17263
- throw new Error("Failed to load user32/gdi32");
17264
- function loadProc2(lib, name) {
17265
- const ptr = win4.GetProcAddress(lib, name);
17266
- if (!ptr)
17267
- throw new Error("Failed to load " + name);
17268
- return ptr;
17269
- }
17270
- var GetDC_ = loadProc2(_user32, "GetDC");
17271
- var ReleaseDC_ = loadProc2(_user32, "ReleaseDC");
17272
- var SetDIBitsToDevice_ = loadProc2(_gdi32, "SetDIBitsToDevice");
17273
- var FFI_PTR3 = ffi10.FFI_TYPE_POINTER;
17274
- var FFI_U322 = ffi10.FFI_TYPE_UINT32;
17275
- var FFI_S322 = ffi10.FFI_TYPE_SINT32;
17276
18227
  function makeBitmapInfo(w, h) {
17277
- const bmi = new ArrayBuffer(40);
17278
- const bv = new DataView(bmi);
17279
- bv.setUint32(0, 40, true);
17280
- bv.setInt32(4, w, true);
17281
- bv.setInt32(8, -h, true);
17282
- bv.setUint16(12, 1, true);
17283
- bv.setUint16(14, 24, true);
17284
- return bmi;
18228
+ return BITMAPINFOHEADER.encode({ biSize: BITMAPINFOHEADER.size, biWidth: w, biHeight: -h, biPlanes: 1, biBitCount: 24 });
17285
18229
  }
17286
18230
  var PdfCanvas = (0, import_react18.forwardRef)(({ pixmap, style }, ref) => {
17287
18231
  const canvasRef = (0, import_react18.useRef)(null);
@@ -17301,37 +18245,11 @@ var PdfCanvas = (0, import_react18.forwardRef)(({ pixmap, style }, ref) => {
17301
18245
  const pm = pixmapRef.current;
17302
18246
  if (!pm)
17303
18247
  return 0;
17304
- const hdc = ffi10.ffiCall(GetDC_, [ffi10.FFI_TYPE_UINT64], [hwnd], ffi10.FFI_TYPE_UINT64);
18248
+ const hdc = GetDC(hwnd);
17305
18249
  if (hdc) {
17306
18250
  const bmi = makeBitmapInfo(pm.w, pm.h);
17307
- ffi10.ffiCall(SetDIBitsToDevice_, [
17308
- ffi10.FFI_TYPE_UINT64,
17309
- FFI_S322,
17310
- FFI_S322,
17311
- FFI_U322,
17312
- FFI_U322,
17313
- FFI_S322,
17314
- FFI_S322,
17315
- FFI_U322,
17316
- FFI_U322,
17317
- FFI_PTR3,
17318
- FFI_PTR3,
17319
- FFI_U322
17320
- ], [
17321
- hdc,
17322
- 0,
17323
- 0,
17324
- pm.w,
17325
- pm.h,
17326
- 0,
17327
- 0,
17328
- 0,
17329
- pm.h,
17330
- pm.data,
17331
- bmi,
17332
- 0
17333
- ], FFI_S322);
17334
- ffi10.ffiCall(ReleaseDC_, [ffi10.FFI_TYPE_UINT64, ffi10.FFI_TYPE_UINT64], [hwnd, hdc], FFI_S322);
18251
+ SetDIBitsToDevice(hdc, 0, 0, pm.w, pm.h, 0, 0, 0, pm.h, pm.data, bmi, 0);
18252
+ ReleaseDC(hwnd, hdc);
17335
18253
  }
17336
18254
  return 0;
17337
18255
  }
@@ -17340,67 +18258,29 @@ var PdfCanvas = (0, import_react18.forwardRef)(({ pixmap, style }, ref) => {
17340
18258
  });
17341
18259
 
17342
18260
  // _build/examples/pdf_viewer.js
17343
- var _user322 = win5.LoadLibrary("user32.dll");
17344
- var _gdi322 = win5.LoadLibrary("gdi32.dll");
17345
- var _comdlg32 = win5.LoadLibrary("comdlg32.dll");
17346
- if (!_user322 || !_gdi322 || !_comdlg32) {
17347
- gui19.MessageBox("Failed to load system libraries");
17348
- std.exit(0);
17349
- }
17350
- function loadProc3(lib, name) {
17351
- const ptr = win5.GetProcAddress(lib, name);
17352
- if (!ptr)
17353
- throw new Error("Failed to load " + name);
17354
- return ptr;
17355
- }
17356
- var GetOpenFileNameW_ = loadProc3(_comdlg32, "GetOpenFileNameW");
17357
- var FFI_PTR4 = ffi11.FFI_TYPE_POINTER;
17358
- var FFI_U323 = ffi11.FFI_TYPE_UINT32;
17359
- function strToWide2(str) {
17360
- const buf = new ArrayBuffer((str.length + 1) * 2);
17361
- const dv = new DataView(buf);
17362
- for (let i = 0; i < str.length; i++)
17363
- dv.setUint16(i * 2, str.charCodeAt(i), true);
17364
- return buf;
17365
- }
17366
- function wideToStr2(buf) {
17367
- const dv = new DataView(buf);
17368
- const chars = [];
17369
- for (let i = 0; i < buf.byteLength; i += 2) {
17370
- const c = dv.getUint16(i, true);
17371
- if (c === 0)
17372
- break;
17373
- chars.push(c);
17374
- }
17375
- return String.fromCharCode(...chars);
17376
- }
17377
- function setPtr3(dv, off, ptr) {
17378
- dv.setUint32(off, ptr & 4294967295, true);
17379
- dv.setUint32(off + 4, Math.floor(ptr / 4294967296), true);
17380
- }
17381
18261
  function openPdfFileDialog(owner) {
17382
- const structBuf = new ArrayBuffer(152);
17383
- const sv = new DataView(structBuf);
17384
- const fileBuf = new ArrayBuffer(260 * 2);
17385
- const filterWide = strToWide2("PDF Files\0*.pdf\0All Files\0*.*\0\0");
17386
- sv.setUint32(0, 152, true);
17387
- sv.setUint32(8, owner & 4294967295, true);
17388
- sv.setUint32(12, Math.floor(owner / 4294967296), true);
17389
- setPtr3(sv, 24, ffi11.bufferPtr(filterWide));
17390
- setPtr3(sv, 48, ffi11.bufferPtr(fileBuf));
17391
- sv.setUint32(56, 260, true);
17392
- sv.setUint32(96, 4096 | 2048 | 4, true);
17393
- const ret = ffi11.ffiCall(GetOpenFileNameW_, [FFI_PTR4], [structBuf], FFI_U323);
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({
18265
+ lStructSize: OPENFILENAMEW.size,
18266
+ hwndOwner: owner,
18267
+ lpstrFilter: filterWide.ptr,
18268
+ lpstrFile: fileBuf.ptr,
18269
+ nMaxFile: 260,
18270
+ Flags: 4096 | 2048 | 4
18271
+ });
18272
+ ofn.__keep = [fileBuf, filterWide];
18273
+ const ret = GetOpenFileName(ofn);
17394
18274
  if (!ret)
17395
18275
  return null;
17396
- const path = wideToStr2(fileBuf);
18276
+ const path = WCHAR.decode(fileBuf);
17397
18277
  return path.length > 0 ? path : null;
17398
18278
  }
17399
18279
  async function loadMupdf() {
17400
18280
  const wasmPath = "./vendor/mupdf-wasm/mupdf-wasm.wasm";
17401
- const fp = std.open(wasmPath, "rb");
18281
+ const fp = std2.open(wasmPath, "rb");
17402
18282
  if (!fp) {
17403
- std.printf("Error: cannot open %s\n", wasmPath);
18283
+ std2.printf("Error: cannot open %s\n", wasmPath);
17404
18284
  return null;
17405
18285
  }
17406
18286
  fp.seek(0, 2);
@@ -17416,7 +18296,7 @@ async function loadMupdf() {
17416
18296
  try {
17417
18297
  return await import("../vendor/mupdf-wasm/mupdf.js");
17418
18298
  } catch (e) {
17419
- std.printf("Error: mupdf load failed: %s\n", String(e));
18299
+ std2.printf("Error: mupdf load failed: %s\n", String(e));
17420
18300
  return null;
17421
18301
  }
17422
18302
  }
@@ -17434,9 +18314,9 @@ function renderPdfPage(mupdf, filePath, pageIndex) {
17434
18314
  cachedDoc = null;
17435
18315
  cachedPath = "";
17436
18316
  cachedTotalPages = 0;
17437
- const fp = std.open(filePath, "rb");
18317
+ const fp = std2.open(filePath, "rb");
17438
18318
  if (!fp) {
17439
- std.printf("Error: cannot open %s\n", filePath);
18319
+ std2.printf("Error: cannot open %s\n", filePath);
17440
18320
  return null;
17441
18321
  }
17442
18322
  let buf = null;
@@ -17456,7 +18336,7 @@ function renderPdfPage(mupdf, filePath, pageIndex) {
17456
18336
  cachedTotalPages = cachedDoc.countPages();
17457
18337
  cachedPath = filePath;
17458
18338
  } catch (e) {
17459
- std.printf("Error opening document: %s\n", String(e));
18339
+ std2.printf("Error opening document: %s\n", String(e));
17460
18340
  return null;
17461
18341
  }
17462
18342
  }
@@ -17478,7 +18358,7 @@ function renderPdfPage(mupdf, filePath, pageIndex) {
17478
18358
  const h = pixmap.getHeight();
17479
18359
  const dibStride = Math.floor((w * 3 + 3) / 4) * 4;
17480
18360
  const dibSize = h * dibStride;
17481
- const dibBuffer = new ArrayBuffer(dibSize);
18361
+ const dibBuffer = new PtrArrayBuffer(dibSize);
17482
18362
  const dib = new Uint8Array(dibBuffer);
17483
18363
  for (let y = 0; y < h; y++) {
17484
18364
  const srcOff = y * srcStride;
@@ -17493,7 +18373,7 @@ function renderPdfPage(mupdf, filePath, pageIndex) {
17493
18373
  }
17494
18374
  return { data: dibBuffer, w, h, totalPages: cachedTotalPages };
17495
18375
  } catch (e) {
17496
- std.printf("Error rendering: %s\n", String(e));
18376
+ std2.printf("Error rendering: %s\n", String(e));
17497
18377
  if (cachedDoc) {
17498
18378
  try {
17499
18379
  cachedDoc.destroy();
@@ -17531,7 +18411,7 @@ function App({ mupdf, mainHwnd: hwnd }) {
17531
18411
  setCurrentPage(page);
17532
18412
  setTotalPages(result.totalPages);
17533
18413
  } else {
17534
- gui19.MessageBox("Failed to render PDF page");
18414
+ gui18.MessageBox("Failed to render PDF page");
17535
18415
  }
17536
18416
  }
17537
18417
  function handleOpen() {
@@ -17554,14 +18434,14 @@ function App({ mupdf, mainHwnd: hwnd }) {
17554
18434
  async function main() {
17555
18435
  const mupdf = await loadMupdf();
17556
18436
  if (!mupdf) {
17557
- 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.");
17558
18438
  return;
17559
18439
  }
17560
- gui19.RegisterClass("PdfViewerWin");
17561
- 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);
17562
18442
  if (hwnd) {
17563
18443
  render((0, import_jsx_runtime17.jsx)(App, { mupdf, mainHwnd: hwnd }), hwnd);
17564
- setTimeout(() => gui19.ShowWindow(hwnd), 0);
18444
+ setTimeout(() => gui18.ShowWindow(hwnd), 0);
17565
18445
  }
17566
18446
  }
17567
18447
  main();