quickwin 3.0.0 → 3.0.2

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 (253) hide show
  1. package/README.en.md +3 -0
  2. package/README.md +2 -0
  3. package/lib/abort.d.ts +21 -0
  4. package/lib/assert.d.ts +2 -0
  5. package/lib/bitmap.d.ts +7 -0
  6. package/lib/cache-utils.d.ts +6 -0
  7. package/lib/certs.d.ts +1 -0
  8. package/lib/dpi.d.ts +9 -0
  9. package/lib/dumpRects.d.ts +2 -0
  10. package/lib/exec-log.d.ts +23 -0
  11. package/lib/fetch.d.ts +4 -0
  12. package/lib/ffi/bind.d.ts +70 -0
  13. package/lib/ffi/ctype.d.ts +117 -0
  14. package/lib/ffi/index.d.ts +2 -0
  15. package/lib/ffi/struct.d.ts +174 -0
  16. package/lib/http-common.d.ts +143 -0
  17. package/lib/http-server.d.ts +59 -0
  18. package/lib/polyfill.d.ts +22 -0
  19. package/lib/react-qw/components/Button.d.ts +9 -0
  20. package/lib/react-qw/components/CheckBox.d.ts +11 -0
  21. package/lib/react-qw/components/ComboBox.d.ts +11 -0
  22. package/lib/react-qw/components/DateTimePicker.d.ts +15 -0
  23. package/lib/react-qw/components/Input.d.ts +15 -0
  24. package/lib/react-qw/components/Link.d.ts +12 -0
  25. package/lib/react-qw/components/ListBox.d.ts +13 -0
  26. package/lib/react-qw/components/ListView.d.ts +37 -0
  27. package/lib/react-qw/components/PathPicker.d.ts +23 -0
  28. package/lib/react-qw/components/ProgressBar.d.ts +9 -0
  29. package/lib/react-qw/components/RadioButton.d.ts +11 -0
  30. package/lib/react-qw/components/ScrollView.d.ts +9 -0
  31. package/lib/react-qw/components/Slider.d.ts +12 -0
  32. package/lib/react-qw/components/Tab.d.ts +14 -0
  33. package/lib/react-qw/components/Tooltip.d.ts +7 -0
  34. package/lib/react-qw/components/TreeView.d.ts +18 -0
  35. package/lib/react-qw/components/index.d.ts +16 -0
  36. package/lib/react-qw/index.d.ts +24 -0
  37. package/lib/react-qw/layout.d.ts +29 -0
  38. package/lib/react-qw/nmhdr.d.ts +1 -0
  39. package/lib/react-qw/props.d.ts +2 -0
  40. package/lib/react-qw/reconciler.d.ts +21 -0
  41. package/lib/stream.d.ts +20 -0
  42. package/lib/text-codec.d.ts +39 -0
  43. package/lib/text-measure.d.ts +14 -0
  44. package/lib/url.d.ts +54 -0
  45. package/lib/websocket.d.ts +73 -0
  46. package/lib/windows/{advapi32.ts → advapi32.d.ts} +6 -21
  47. package/lib/windows/comctl32.d.ts +14 -0
  48. package/lib/windows/comdlg32.d.ts +4 -0
  49. package/lib/windows/{gdi32.ts → gdi32.d.ts} +161 -98
  50. package/lib/windows/{kernel32.ts → kernel32.d.ts} +138 -115
  51. package/lib/windows/{msimg32.ts → msimg32.d.ts} +11 -14
  52. package/lib/windows/ntdll.d.ts +5 -0
  53. package/lib/windows/ole32.d.ts +3 -0
  54. package/lib/windows/{psapi.ts → psapi.d.ts} +9 -18
  55. package/lib/windows/{shell32.ts → shell32.d.ts} +25 -24
  56. package/lib/windows/structs.d.ts +3141 -0
  57. package/lib/windows/{user32.ts → user32.d.ts} +196 -193
  58. package/lib/windows/version.d.ts +27 -0
  59. package/lib/windows/{winspool.ts → winspool.d.ts} +18 -32
  60. package/package.json +15 -8
  61. package/qwin-nowasm-x86.exe +0 -0
  62. package/qwin-nowasm.exe +0 -0
  63. package/qwin-x86.exe +0 -0
  64. package/qwin.exe +0 -0
  65. package/examples/PdfCanvas.js +0 -38
  66. package/examples/PdfCanvas.tsx +0 -54
  67. package/examples/execd/main.js +0 -23379
  68. package/examples/execd/tray.js +0 -192
  69. package/examples/execd/worker.js +0 -122
  70. package/examples/pdf_preview2.js +0 -398
  71. package/examples/pdf_preview2.ts +0 -353
  72. package/examples/pdf_viewer.js +0 -22515
  73. package/examples/pdf_viewer.tsx +0 -228
  74. package/examples/test_gallery.js +0 -18692
  75. package/examples/test_gallery.tsx +0 -291
  76. package/examples/test_react_lazy.js +0 -18560
  77. package/examples/test_react_lazy.tsx +0 -65
  78. package/examples/test_react_listbox.js +0 -18562
  79. package/examples/test_react_listbox.tsx +0 -73
  80. package/examples/test_root_window.js +0 -18532
  81. package/examples/test_root_window.tsx +0 -41
  82. package/examples/test_tab.js +0 -18563
  83. package/examples/test_tab.tsx +0 -77
  84. package/examples/tray_demo.js +0 -86
  85. package/examples/tray_demo.tsx +0 -89
  86. package/lib/abort.ts +0 -69
  87. package/lib/assert.ts +0 -7
  88. package/lib/bitmap.ts +0 -39
  89. package/lib/cache-utils.ts +0 -40
  90. package/lib/certs.ts +0 -258
  91. package/lib/dpi.ts +0 -31
  92. package/lib/dumpRects.ts +0 -34
  93. package/lib/exec-log.ts +0 -30
  94. package/lib/fetch.ts +0 -589
  95. package/lib/ffi/bind.ts +0 -540
  96. package/lib/ffi/ctype.ts +0 -371
  97. package/lib/ffi/index.ts +0 -6
  98. package/lib/ffi/struct.ts +0 -780
  99. package/lib/http-common.ts +0 -441
  100. package/lib/http-server.ts +0 -604
  101. package/lib/polyfill.ts +0 -171
  102. package/lib/react-qw/components/index.ts +0 -17
  103. package/lib/react-qw/index.ts +0 -96
  104. package/lib/react-qw/layout.ts +0 -111
  105. package/lib/react-qw/nmhdr.ts +0 -7
  106. package/lib/react-qw/props.ts +0 -41
  107. package/lib/react-qw/reconciler.ts +0 -379
  108. package/lib/stream.ts +0 -22
  109. package/lib/text-codec.ts +0 -171
  110. package/lib/text-measure.ts +0 -44
  111. package/lib/url.ts +0 -201
  112. package/lib/websocket.ts +0 -600
  113. package/lib/windows/comctl32.ts +0 -20
  114. package/lib/windows/comdlg32.ts +0 -10
  115. package/lib/windows/ntdll.ts +0 -11
  116. package/lib/windows/ole32.ts +0 -9
  117. package/lib/windows/structs.ts +0 -807
  118. package/lib/windows/version.ts +0 -35
  119. package/test/add.wasm +0 -0
  120. package/test/bench_ffi_callraw.js +0 -235
  121. package/test/bench_ffi_callraw.ts +0 -235
  122. package/test/bench_ffi_overhead.js +0 -139
  123. package/test/bench_ffi_overhead.ts +0 -141
  124. package/test/bench_sendmessage.js +0 -104
  125. package/test/bench_sendmessage.ts +0 -100
  126. package/test/bench_sendmessage_nonnull.js +0 -187
  127. package/test/bench_sendmessage_nonnull.ts +0 -188
  128. package/test/complex.wasm +0 -0
  129. package/test/complex_imports.wasm +0 -0
  130. package/test/debug/http_server_e2e.js +0 -31
  131. package/test/debug/minwasm.js +0 -52
  132. package/test/debug/mupdf_debug.js +0 -86
  133. package/test/debug/wasm.js +0 -122
  134. package/test/debug/wasm_export_debug.js +0 -54
  135. package/test/debug/wasm_names.js +0 -36
  136. package/test/example.pdf +0 -0
  137. package/test/global_imports.wasm +0 -0
  138. package/test/import_func.wasm +0 -0
  139. package/test/imports.wasm +0 -0
  140. package/test/mupdf-cdn.js +0 -40
  141. package/test/mupdf-cdn.ts +0 -43
  142. package/test/run.js +0 -111
  143. package/test/run.ts +0 -116
  144. package/test/sjlj.wasm +0 -0
  145. package/test/test_basic.js +0 -7
  146. package/test/test_basic.ts +0 -9
  147. package/test/test_basic_fetch.js +0 -63
  148. package/test/test_basic_fetch.ts +0 -59
  149. package/test/test_brotli.js +0 -48
  150. package/test/test_brotli.ts +0 -52
  151. package/test/test_fetch_cache.js +0 -169
  152. package/test/test_fetch_cache.ts +0 -187
  153. package/test/test_ffi.js +0 -157
  154. package/test/test_ffi.ts +0 -170
  155. package/test/test_ffi_abi.js +0 -290
  156. package/test/test_ffi_abi.ts +0 -274
  157. package/test/test_ffi_array.js +0 -116
  158. package/test/test_ffi_array.ts +0 -141
  159. package/test/test_ffi_bind.js +0 -656
  160. package/test/test_ffi_bind.ts +0 -670
  161. package/test/test_ffi_struct.js +0 -779
  162. package/test/test_ffi_struct.ts +0 -828
  163. package/test/test_ffi_struct_layout.js +0 -495
  164. package/test/test_ffi_struct_layout.ts +0 -543
  165. package/test/test_ffi_user32.js +0 -103
  166. package/test/test_ffi_user32.ts +0 -113
  167. package/test/test_ffi_windows.js +0 -172
  168. package/test/test_ffi_windows.ts +0 -187
  169. package/test/test_files.js +0 -102
  170. package/test/test_files.ts +0 -121
  171. package/test/test_frame_encoding.js +0 -128
  172. package/test/test_frame_encoding.ts +0 -132
  173. package/test/test_gdi_draw.js +0 -681
  174. package/test/test_gdi_draw.ts +0 -725
  175. package/test/test_helper.js +0 -91
  176. package/test/test_helper.ts +0 -88
  177. package/test/test_http_import.js +0 -96
  178. package/test/test_http_import.ts +0 -93
  179. package/test/test_http_server.js +0 -214
  180. package/test/test_http_server.ts +0 -211
  181. package/test/test_import_dir.js +0 -4
  182. package/test/test_import_dir.ts +0 -5
  183. package/test/test_ipv6.js +0 -134
  184. package/test/test_ipv6.ts +0 -130
  185. package/test/test_jsx.js +0 -1314
  186. package/test/test_meta_url.js +0 -3
  187. package/test/test_meta_url.ts +0 -4
  188. package/test/test_mupdf_render.js +0 -51
  189. package/test/test_mupdf_render.ts +0 -55
  190. package/test/test_mupdf_twice.js +0 -62
  191. package/test/test_mupdf_twice.ts +0 -65
  192. package/test/test_mupdf_wasm.js +0 -39
  193. package/test/test_mupdf_wasm.ts +0 -32
  194. package/test/test_net_event.js +0 -57
  195. package/test/test_net_event.ts +0 -56
  196. package/test/test_net_fetch.js +0 -384
  197. package/test/test_net_fetch.ts +0 -373
  198. package/test/test_net_websocket.js +0 -180
  199. package/test/test_net_websocket.ts +0 -164
  200. package/test/test_polyfill.js +0 -144
  201. package/test/test_polyfill.ts +0 -159
  202. package/test/test_printer.js +0 -137
  203. package/test/test_printer.ts +0 -148
  204. package/test/test_proc.js +0 -141
  205. package/test/test_proc.ts +0 -163
  206. package/test/test_react_complex.js +0 -18678
  207. package/test/test_react_counter.js +0 -18555
  208. package/test/test_react_flex.js +0 -18871
  209. package/test/test_react_hidden.js +0 -18560
  210. package/test/test_react_listview_link.js +0 -18590
  211. package/test/test_react_notify.js +0 -18797
  212. package/test/test_react_render.js +0 -18550
  213. package/test/test_registry.js +0 -74
  214. package/test/test_registry.ts +0 -95
  215. package/test/test_sysinfo.js +0 -122
  216. package/test/test_sysinfo.ts +0 -141
  217. package/test/test_url.js +0 -173
  218. package/test/test_url.ts +0 -183
  219. package/test/test_wasm_basic.js +0 -85
  220. package/test/test_wasm_basic.ts +0 -73
  221. package/test/test_wasm_import_global.js +0 -41
  222. package/test/test_wasm_import_global.ts +0 -45
  223. package/test/test_wasm_sjlj.js +0 -145
  224. package/test/test_wasm_sjlj.ts +0 -125
  225. package/test/test_wasm_types.js +0 -97
  226. package/test/test_wasm_types.ts +0 -124
  227. package/test/test_wolfssl_read.js +0 -203
  228. package/test/test_wolfssl_read.ts +0 -184
  229. package/test/test_worker.js +0 -21
  230. package/test/test_worker.ts +0 -24
  231. package/test/test_worker_concurrent.js +0 -45
  232. package/test/test_worker_concurrent.ts +0 -56
  233. package/test/test_worker_data_url.js +0 -46
  234. package/test/test_worker_data_url.ts +0 -51
  235. package/test/test_worker_fetch.js +0 -26
  236. package/test/test_worker_fetch.ts +0 -27
  237. package/test/test_worker_net.js +0 -69
  238. package/test/test_worker_net.ts +0 -66
  239. package/test/test_worker_wasm_concurrent.js +0 -44
  240. package/test/test_worker_wasm_concurrent.ts +0 -45
  241. package/test/types.wasm +0 -0
  242. package/test/worker_fetch.js +0 -13
  243. package/test/worker_fetch.ts +0 -13
  244. package/test/worker_helper.js +0 -1
  245. package/test/worker_helper.ts +0 -1
  246. package/test/worker_http.js +0 -18
  247. package/test/worker_http.ts +0 -20
  248. package/test/worker_import_lib.js +0 -12
  249. package/test/worker_import_lib.ts +0 -13
  250. package/test/worker_module.js +0 -16
  251. package/test/worker_module.ts +0 -17
  252. package/test/worker_wasm_concurrent.js +0 -22
  253. package/test/worker_wasm_concurrent.ts +0 -22
package/lib/polyfill.ts DELETED
@@ -1,171 +0,0 @@
1
- import * as os from 'os'
2
- import './url.js'
3
- import './text-codec.js'
4
-
5
-
6
- declare global {
7
- interface Console {
8
- error: (...args: unknown[]) => void
9
- }
10
-
11
- var window: typeof globalThis
12
-
13
- type TimerId = os.TimerId
14
- function setTimeout<P extends unknown[]>(fn: (...argsf: P) => void, ms?: number, ...argsr: P): TimerId
15
- function clearTimeout(id: TimerId): void
16
-
17
- function btoa(data: string): string
18
- function atob(data: string): string
19
-
20
- interface SubtleCrypto {
21
- digest(algorithm: 'SHA-1', data: ArrayBuffer | Uint8Array): Promise<ArrayBuffer>
22
- }
23
-
24
- interface Crypto {
25
- getRandomValues<T extends ArrayBufferView>(array: T): T
26
- subtle: SubtleCrypto
27
- }
28
-
29
- var crypto: Crypto
30
- }
31
-
32
- // 1. window — triggers Emscripten browser path
33
- if (typeof globalThis.window === 'undefined')
34
- globalThis.window = globalThis
35
-
36
- // 2. setTimeout polyfill — bridge to os.setTimeout
37
- if (typeof globalThis.setTimeout === 'undefined') {
38
- globalThis.setTimeout = ((fn, ms, ...args) => {
39
- return os.setTimeout(() => fn(...args), ms ?? 0)
40
- }) satisfies typeof setTimeout
41
- }
42
-
43
- // 2b. clearTimeout polyfill — bridge to os.clearTimeout
44
- if (typeof globalThis.clearTimeout === 'undefined') {
45
- globalThis.clearTimeout = os.clearTimeout
46
- }
47
-
48
- // 3. console.error polyfill — QuickJS only has console.log
49
- if (typeof console.error === 'undefined') {
50
- console.error = (...args: unknown[]) => { console.log(...args) }
51
- }
52
-
53
-
54
- // ── SHA-1 ──
55
-
56
- function sha1Bytes(bytes: number[]): ArrayBuffer {
57
- const len = bytes.length
58
- const ml = len * 8
59
-
60
- bytes.push(0x80)
61
- while (bytes.length % 64 !== 56) { bytes.push(0) }
62
- bytes.push(0)
63
- bytes.push(0)
64
- bytes.push(0)
65
- bytes.push(0)
66
- bytes.push((ml >>> 24) & 0xFF)
67
- bytes.push((ml >>> 16) & 0xFF)
68
- bytes.push((ml >>> 8) & 0xFF)
69
- bytes.push(ml & 0xFF)
70
-
71
- let h0 = 0x67452301, h1 = 0xEFCDAB89
72
- let h2 = 0x98BADCFE, h3 = 0x10325476, h4 = 0xC3D2E1F0
73
- const rotl = (x: number, n: number): number => ((x << n) | (x >>> (32 - n))) >>> 0
74
-
75
- for (let i = 0; i < bytes.length; i += 64) {
76
- const w: number[] = []
77
- for (let t = 0; t < 16; t++) {
78
- w[t] = (bytes[i + 4 * t]! << 24) | (bytes[i + 4 * t + 1]! << 16) |
79
- (bytes[i + 4 * t + 2]! << 8) | bytes[i + 4 * t + 3]!
80
- }
81
- for (let t = 16; t < 80; t++) {
82
- w[t] = rotl(w[t - 3]! ^ w[t - 8]! ^ w[t - 14]! ^ w[t - 16]!, 1)
83
- }
84
-
85
- let a = h0, b = h1, c = h2, d = h3, e = h4
86
- for (let t = 0; t < 80; t++) {
87
- let f: number, k: number
88
- if (t < 20) { f = (b & c) | (~b & d); k = 0x5A827999 }
89
- else if (t < 40) { f = b ^ c ^ d; k = 0x6ED9EBA1 }
90
- else if (t < 60) { f = (b & c) | (b & d) | (c & d); k = 0x8F1BBCDC }
91
- else { f = b ^ c ^ d; k = 0xCA62C1D6 }
92
- const temp = (rotl(a, 5) + f + e + k + w[t]!) >>> 0
93
- e = d; d = c; c = rotl(b, 30); b = a; a = temp
94
- }
95
- h0 = (h0 + a) >>> 0; h1 = (h1 + b) >>> 0
96
- h2 = (h2 + c) >>> 0; h3 = (h3 + d) >>> 0; h4 = (h4 + e) >>> 0
97
- }
98
-
99
- const result = new Uint8Array(20)
100
- const w32 = (off: number, v: number) => {
101
- result[off] = (v >>> 24) & 0xFF; result[off + 1] = (v >>> 16) & 0xFF
102
- result[off + 2] = (v >>> 8) & 0xFF; result[off + 3] = v & 0xFF
103
- }
104
- w32(0, h0); w32(4, h1); w32(8, h2); w32(12, h3); w32(16, h4)
105
- return result.buffer
106
- }
107
-
108
- // ── Base64 ──
109
-
110
- const B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
111
-
112
- function b64Encode(data: Uint8Array): string {
113
- let r = ''
114
- for (let i = 0; i < data.length; i += 3) {
115
- const b0 = data[i]!, b1 = i + 1 < data.length ? data[i + 1]! : 0, b2 = i + 2 < data.length ? data[i + 2]! : 0
116
- r += B64[b0 >> 2]! + B64[((b0 & 3) << 4) | (b1 >> 4)]!
117
- r += i + 1 < data.length ? B64[((b1 & 15) << 2) | (b2 >> 6)]! : '='
118
- r += i + 2 < data.length ? B64[b2 & 63]! : '='
119
- }
120
- return r
121
- }
122
-
123
- function b64Decode(str: string): Uint8Array {
124
- str = str.replace(/[^A-Za-z0-9+/=]/g, '')
125
- const bytes: number[] = []
126
- for (let i = 0; i < str.length; i += 4) {
127
- const c0 = B64.indexOf(str[i]!), c1 = B64.indexOf(str[i + 1]!)
128
- const c2 = B64.indexOf(str[i + 2]!), c3 = B64.indexOf(str[i + 3]!)
129
- bytes.push((c0 << 2) | (c1 >> 4))
130
- if (c2 >= 0) bytes.push(((c1 & 15) << 4) | (c2 >> 2))
131
- if (c3 >= 0) bytes.push(((c2 & 3) << 6) | c3)
132
- }
133
- return new Uint8Array(bytes)
134
- }
135
-
136
- // ── btoa / atob ──
137
-
138
- if (typeof globalThis.btoa === 'undefined') {
139
- globalThis.btoa = (data: string): string => {
140
- const bytes = new Uint8Array(data.length)
141
- for (let i = 0; i < data.length; i++) bytes[i] = data.charCodeAt(i) & 0xFF
142
- return b64Encode(bytes)
143
- }
144
- }
145
-
146
- if (typeof globalThis.atob === 'undefined') {
147
- globalThis.atob = (data: string): string => {
148
- const bytes = b64Decode(data)
149
- let r = ''
150
- for (let i = 0; i < bytes.length; i++) r += String.fromCharCode(bytes[i]!)
151
- return r
152
- }
153
- }
154
-
155
- if (typeof globalThis.crypto === 'undefined') {
156
- globalThis.crypto = {
157
- getRandomValues: <T extends ArrayBufferView>(array: T): T => {
158
- const view = new Uint8Array(array.buffer, array.byteOffset, array.byteLength)
159
- for (let i = 0; i < view.length; i++) view[i] = (Math.random() * 256) | 0
160
- return array
161
- },
162
- subtle: {
163
- digest: (algorithm: string, data: ArrayBuffer | Uint8Array): Promise<ArrayBuffer> => {
164
- if (algorithm.toUpperCase() !== 'SHA-1')
165
- return Promise.reject(new Error('Digest: ' + algorithm + ' not supported'))
166
- const bytes = data instanceof Uint8Array ? Array.from(data) : Array.from(new Uint8Array(data))
167
- return Promise.resolve(sha1Bytes(bytes))
168
- }
169
- }
170
- }
171
- }
@@ -1,17 +0,0 @@
1
- export { Button, type ButtonProps } from './Button.js'
2
- export { CheckBox, type CheckBoxProps } from './CheckBox.js'
3
- export { ComboBox, type ComboBoxProps } from './ComboBox.js'
4
- export { DateTimePicker, type DateTimePickerProps } from './DateTimePicker.js'
5
- export { Input, type InputProps } from './Input.js'
6
- export { Link, type LinkProps } from './Link.js'
7
- export { ListBox, type ListBoxProps } from './ListBox.js'
8
- export { ListView, makeColorBlock, type ListViewProps, type Column, type CellStyle, type Align } from './ListView.js'
9
- export { ProgressBar, type ProgressBarProps } from './ProgressBar.js'
10
- export { RadioButton, type RadioButtonProps } from './RadioButton.js'
11
- export { ScrollView, type ScrollViewProps } from './ScrollView.js'
12
- export { Slider, type SliderProps } from './Slider.js'
13
- export { Tab, type TabProps } from './Tab.js'
14
- export { Tooltip, type TooltipProps } from './Tooltip.js'
15
- export { TreeView, type TreeViewProps, type TreeNode } from './TreeView.js'
16
- export { PathPicker, type PathPickerProps } from './PathPicker.js'
17
-
@@ -1,96 +0,0 @@
1
- import * as gui from 'gui'
2
- import React from 'react'
3
- import { DefWindowProc, GetSystemMetrics, ShowWindow, UpdateWindow } from '../windows/user32.js'
4
- import reconciler, { scaleFactor, instancesByHwnd, forceFlexLayout, type Instance } from './reconciler.js'
5
- import { CreatePos, ShowWindowCmd, SysMetrics, WindowStyle, WmMsg } from '../../constants'
6
-
7
- const noop = () => { }
8
-
9
- export interface RootWindowConfig {
10
- text?: string
11
- ws?: number
12
- x?: number
13
- y?: number
14
- width?: number
15
- height?: number
16
- noShowWindow?: boolean
17
- onEvent?: (e: { hwnd: gui.HWND; msg: number; wParam: number; lParam: number }) => number | void
18
- }
19
-
20
- let defaultClassRegistered = false
21
- const DEFAULT_CLASS = '_QuickWinDefault'
22
- const rootMap = new Map<gui.HWND, { root: ReturnType<typeof reconciler.createContainer>, onEvent?: RootWindowConfig['onEvent'] }>()
23
-
24
- function ensureDefaultClass() {
25
- if (defaultClassRegistered) return DEFAULT_CLASS
26
- gui.RegisterClass(DEFAULT_CLASS, (hwnd, msg, wParam, lParam) => {
27
- const entry = rootMap.get(hwnd)
28
- if (msg === WmMsg.DESTROY && entry) {
29
- rootMap.delete(hwnd)
30
- reconciler.updateContainer(null, entry.root, null, () => {
31
- instancesByHwnd.delete(hwnd)
32
- })
33
- }
34
- const result = entry?.onEvent?.({ hwnd, msg, wParam, lParam })
35
- if (typeof result === 'number') return result
36
- if (msg === WmMsg.SIZE) forceFlexLayout(hwnd)
37
- return DefWindowProc(hwnd, msg, wParam, lParam)
38
- })
39
- defaultClassRegistered = true
40
- return DEFAULT_CLASS
41
- }
42
-
43
- export function createRoot(container: gui.HWND | RootWindowConfig) {
44
- let hwnd: gui.HWND
45
- if (typeof container === 'object') {
46
- const cfg = container
47
- const className = ensureDefaultClass()
48
- const ws = (cfg.ws ?? 0) | WindowStyle.OVERLAPPEDWINDOW
49
- const w = (cfg.width ?? 800) * scaleFactor
50
- const h = (cfg.height ?? 600) * scaleFactor
51
- const [sw, sh] = [GetSystemMetrics(SysMetrics.CXSCREEN), GetSystemMetrics(SysMetrics.CYSCREEN)]
52
- const x = cfg.x === undefined ? ((sw - w) / 2) | 0
53
- : cfg.x === CreatePos.USEDEFAULT ? CreatePos.USEDEFAULT
54
- : cfg.x * scaleFactor
55
- const y = cfg.y === undefined ? ((sh - h) / 2) | 0
56
- : cfg.y === CreatePos.USEDEFAULT ? CreatePos.USEDEFAULT
57
- : cfg.y * scaleFactor
58
- const hwin = gui.CreateWindow(className, cfg.text || '', ws, x, y, w, h, null, null)
59
- if (!hwin) throw new Error('CreateWindow failed')
60
- hwnd = hwin
61
- // 启动首帧:ShowWindow 后立即 WM_PAINT,不留白(原 gui.ShowWindow 复合语义)
62
- if (!cfg.noShowWindow) { ShowWindow(hwnd, ShowWindowCmd.SHOWNORMAL); UpdateWindow(hwnd) }
63
- } else {
64
- hwnd = container
65
- }
66
- const root = reconciler.createContainer(
67
- hwnd, 0, null, false, null, '',
68
- (error, info) => console.log('[React uncaught]', error, error.stack, info.componentStack),
69
- (error, info) => console.log('[React caught]', error, error.stack, info.componentStack),
70
- (error, info) => console.log('[React recoverable]', error, error.stack, info.componentStack),
71
- noop,
72
- )
73
- const rootInst: Instance = { hwnd, type: '_root', props: { type: '_root', style: { flexDirection: 'column', alignItems: 'stretch' } }, children: [] }
74
- instancesByHwnd.set(hwnd, rootInst)
75
- if (typeof container === 'object')
76
- rootMap.set(hwnd, { root, onEvent: container.onEvent })
77
- return {
78
- hwnd,
79
- render(element: React.ReactNode) {
80
- reconciler.updateContainer(element, root, null, noop)
81
- },
82
- unmount() {
83
- reconciler.updateContainer(null, root, null, noop)
84
- }
85
- }
86
- }
87
-
88
- export * from './components/index.js'
89
-
90
- export function render(element: React.ReactNode, containerOrConfig?: gui.HWND | RootWindowConfig | null, _callback?: () => void) {
91
- if (containerOrConfig == null) {
92
- throw new Error('render() requires a window handle or RootWindowConfig as second argument')
93
- }
94
- const root = createRoot(containerOrConfig)
95
- root.render(element)
96
- }
@@ -1,111 +0,0 @@
1
- export type JustifyContent = 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around' | 'space-evenly'
2
-
3
- export interface FlexStyle {
4
- flexDirection?: 'row' | 'column'
5
- justifyContent?: JustifyContent
6
- alignItems?: 'flex-start' | 'flex-end' | 'center' | 'stretch'
7
- gap?: number
8
- padding?: number
9
- paddingTop?: number
10
- paddingRight?: number
11
- paddingBottom?: number
12
- paddingLeft?: number
13
- }
14
-
15
- interface ChildStyle {
16
- width?: number | 'auto'; height?: number | 'auto'
17
- flexGrow?: number
18
- alignSelf?: 'auto' | 'flex-start' | 'flex-end' | 'center' | 'stretch'
19
- }
20
-
21
- interface ChildInfo {
22
- style: ChildStyle
23
- }
24
-
25
- export interface LayoutResult {
26
- x: number; y: number; width: number; height: number
27
- }
28
-
29
- const DEFAULT_W = 100
30
- const DEFAULT_H = 30
31
-
32
- export function calculateFlexLayout(
33
- flex: FlexStyle,
34
- parentW: number,
35
- parentH: number,
36
- children: ChildInfo[]
37
- ): LayoutResult[] {
38
- const dir = flex.flexDirection || 'column'
39
- const gap = flex.gap ?? 0
40
- const justify = flex.justifyContent || 'flex-start'
41
- const align = flex.alignItems || 'stretch'
42
- const isRow = dir === 'row'
43
- const n = children.length
44
-
45
- const mainSize: 'w' | 'h' = isRow ? 'w' : 'h'
46
- const crossSize: 'w' | 'h' = isRow ? 'h' : 'w'
47
- const mainPos: 'x' | 'y' = isRow ? 'x' : 'y'
48
- const crossPos: 'x' | 'y' = isRow ? 'y' : 'x'
49
- const mainDim: 'width' | 'height' = isRow ? 'width' : 'height'
50
- const crossDim: 'width' | 'height' = isRow ? 'height' : 'width'
51
- const pt = flex.paddingTop ?? flex.padding ?? 0
52
- const pr = flex.paddingRight ?? flex.padding ?? 0
53
- const pb = flex.paddingBottom ?? flex.padding ?? 0
54
- const pl = flex.paddingLeft ?? flex.padding ?? 0
55
- const mainPadding = isRow ? pl + pr : pt + pb
56
- const crossPadding = isRow ? pt + pb : pl + pr
57
- const parentMain = (isRow ? parentW : parentH) - mainPadding
58
- const parentCross = (isRow ? parentH : parentW) - crossPadding
59
-
60
- const sizes = children.map(c => ({
61
- w: typeof c.style.width === 'number' ? c.style.width : DEFAULT_W,
62
- h: typeof c.style.height === 'number' ? c.style.height : DEFAULT_H,
63
- }))
64
-
65
- const flexGrows = children.map(c => c.style.flexGrow ?? 0)
66
- const totalGrow = flexGrows.reduce((s, g) => s + g, 0)
67
-
68
- const baseMain = sizes.reduce((s, c) => s + c[mainSize], 0)
69
- let freeGrow = parentMain - baseMain - Math.max(0, n - 1) * gap
70
- if (totalGrow > 0 && freeGrow > 0) {
71
- for (let i = 0; i < n; i++) {
72
- sizes[i]![mainSize] += freeGrow * flexGrows[i]! / totalGrow
73
- }
74
- }
75
-
76
- const totalMain = sizes.reduce((s, c) => s + c[mainSize], 0)
77
- const free = parentMain - totalMain - Math.max(0, n - 1) * gap
78
- let offset = 0, extraGap = 0
79
- if (justify === 'flex-end') offset = free
80
- else if (justify === 'center') offset = Math.max(0, free / 2)
81
- else if (justify === 'space-between' && n > 1) extraGap = free / (n - 1)
82
- else if (justify === 'space-around') { extraGap = free / n; offset = extraGap / 2 }
83
- else if (justify === 'space-evenly') { extraGap = free / (n + 1); offset = extraGap }
84
-
85
- let cursor = offset
86
- return sizes.map((sz, i) => {
87
- const childCrossBase = sz[crossSize]
88
- const childAlign = children[i]!.style.alignSelf ?? 'auto'
89
- const effectiveAlign = childAlign === 'auto' ? align : childAlign
90
- let childMain = sz[mainSize]
91
- let childCross = childCrossBase
92
- const res: LayoutResult = { x: 0, y: 0, width: 0, height: 0 }
93
- res[mainPos] = cursor
94
- res[crossPos] = 0
95
- res[mainDim] = childMain
96
- res[crossDim] = childCross
97
- if (effectiveAlign === 'stretch') {
98
- const hasExplicitCross = typeof children[i]!.style[crossDim] === 'number'
99
- if (!hasExplicitCross) {
100
- res[crossDim] = parentCross
101
- res[crossPos] = 0
102
- }
103
- } else if (effectiveAlign === 'flex-end') {
104
- res[crossPos] = parentCross - childCross
105
- } else if (effectiveAlign === 'center') {
106
- res[crossPos] = Math.max(0, (parentCross - childCross) / 2)
107
- }
108
- cursor += childMain + gap + extraGap
109
- return res
110
- })
111
- }
@@ -1,7 +0,0 @@
1
- import type { Ptr } from '../ffi/ctype.js'
2
- import { NMHDR } from '../windows/structs.js'
3
-
4
- // 读 NMHDR.code(WM_NOTIFY 通知码):lParam 是通知结构的原生指针,decode 直接从该地址读
5
- export function nmCode(lParam: number): number {
6
- return NMHDR.decode(lParam as Ptr<'NMHDR'>).code
7
- }
@@ -1,41 +0,0 @@
1
- import * as gui from 'gui'
2
- import { SetWindowText, EnableWindow, ShowWindow } from '../windows/user32.js'
3
- import type { Instance, Props } from './reconciler.js'
4
- import { EditMsg, ShowWindowCmd } from '../../constants'
5
-
6
- export function applyProps(
7
- instance: Instance,
8
- newProps: Props,
9
- _oldProps: Props,
10
- ) {
11
- const hwnd = instance.hwnd
12
- instance.props = newProps
13
- // 延迟控件(DELAYED_CONTROLS)建窗前 hwnd 为 null:窗口操作此刻全是 no-op
14
- // (text/ws/style 在 ensureChildWindow 建窗时应用),FFI 位不收 JS null——早退。
15
- if (hwnd === null) return
16
-
17
- const textVal = 'text' in newProps ? newProps.text : (
18
- typeof newProps.children === 'string' ? newProps.children :
19
- typeof newProps.children === 'number' ? String(newProps.children) : undefined
20
- )
21
- if (textVal !== undefined) {
22
- let cursor = -1
23
- if (instance.type === 'EDIT') {
24
- const sel = gui.SendMessage(hwnd, EditMsg.GETSEL, 0, 0)
25
- cursor = sel >>> 16
26
- }
27
- SetWindowText(hwnd, textVal)
28
- if (instance.type === 'EDIT' && cursor >= 0) {
29
- gui.SendMessage(hwnd, EditMsg.SETSEL, cursor, cursor)
30
- }
31
- }
32
- if ('disabled' in newProps) {
33
- EnableWindow(hwnd, !newProps.disabled ? 1 : 0)
34
- }
35
- if ('hidden' in newProps) {
36
- ShowWindow(hwnd, newProps.hidden ? ShowWindowCmd.HIDE : ShowWindowCmd.SHOW)
37
- }
38
- if ('visible' in newProps) {
39
- ShowWindow(hwnd, newProps.visible ? ShowWindowCmd.SHOW : ShowWindowCmd.HIDE)
40
- }
41
- }