quickwin 1.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 (175) hide show
  1. package/README.en.md +197 -0
  2. package/README.md +196 -0
  3. package/examples/PdfCanvas.js +67 -0
  4. package/examples/PdfCanvas.tsx +83 -0
  5. package/examples/pdf_preview2.js +431 -0
  6. package/examples/pdf_preview2.ts +375 -0
  7. package/examples/pdf_viewer.js +17623 -0
  8. package/examples/pdf_viewer.tsx +279 -0
  9. package/examples/test_gallery.js +17452 -0
  10. package/examples/test_gallery.tsx +285 -0
  11. package/examples/test_react_lazy.js +17336 -0
  12. package/examples/test_react_lazy.tsx +63 -0
  13. package/examples/test_react_listbox.js +17339 -0
  14. package/examples/test_react_listbox.tsx +71 -0
  15. package/examples/test_root_window.js +17313 -0
  16. package/examples/test_root_window.tsx +41 -0
  17. package/examples/test_tab.js +17339 -0
  18. package/examples/test_tab.tsx +75 -0
  19. package/examples/tray_demo.js +79 -0
  20. package/examples/tray_demo.tsx +81 -0
  21. package/lib/assert.js +8 -0
  22. package/lib/assert.ts +7 -0
  23. package/lib/cache-utils.js +43 -0
  24. package/lib/cache-utils.ts +40 -0
  25. package/lib/dumpRects.js +25 -0
  26. package/lib/dumpRects.ts +25 -0
  27. package/lib/fetch.js +490 -0
  28. package/lib/fetch.ts +502 -0
  29. package/lib/http-common.js +342 -0
  30. package/lib/http-common.ts +399 -0
  31. package/lib/http-server.js +416 -0
  32. package/lib/http-server.ts +424 -0
  33. package/lib/polyfill.js +156 -0
  34. package/lib/polyfill.ts +171 -0
  35. package/lib/react-qw/components/Button.js +8 -0
  36. package/lib/react-qw/components/CheckBox.js +31 -0
  37. package/lib/react-qw/components/ComboBox.js +42 -0
  38. package/lib/react-qw/components/DateTimePicker.js +96 -0
  39. package/lib/react-qw/components/Input.js +50 -0
  40. package/lib/react-qw/components/Link.js +43 -0
  41. package/lib/react-qw/components/ListBox.js +48 -0
  42. package/lib/react-qw/components/ListView.js +328 -0
  43. package/lib/react-qw/components/PathPicker.js +136 -0
  44. package/lib/react-qw/components/ProgressBar.js +22 -0
  45. package/lib/react-qw/components/RadioButton.js +31 -0
  46. package/lib/react-qw/components/ScrollView.js +139 -0
  47. package/lib/react-qw/components/Slider.js +45 -0
  48. package/lib/react-qw/components/Tab.js +61 -0
  49. package/lib/react-qw/components/Tooltip.js +55 -0
  50. package/lib/react-qw/components/TreeView.js +130 -0
  51. package/lib/react-qw/components/index.js +16 -0
  52. package/lib/react-qw/components/index.ts +17 -0
  53. package/lib/react-qw/index.js +73 -0
  54. package/lib/react-qw/index.ts +90 -0
  55. package/lib/react-qw/jsx.d.ts +34 -0
  56. package/lib/react-qw/layout.js +82 -0
  57. package/lib/react-qw/layout.ts +111 -0
  58. package/lib/react-qw/props.js +27 -0
  59. package/lib/react-qw/props.ts +36 -0
  60. package/lib/react-qw/reconciler.js +333 -0
  61. package/lib/react-qw/reconciler.ts +373 -0
  62. package/lib/stream.js +2 -0
  63. package/lib/stream.ts +22 -0
  64. package/lib/text-codec.js +197 -0
  65. package/lib/text-codec.ts +171 -0
  66. package/lib/text-measure.js +52 -0
  67. package/lib/text-measure.ts +54 -0
  68. package/lib/url.js +278 -0
  69. package/lib/url.ts +201 -0
  70. package/lib/vendor/web-streams/ponyfill.d.mts +829 -0
  71. package/lib/vendor/web-streams/ponyfill.mjs +8 -0
  72. package/lib/websocket.js +541 -0
  73. package/lib/websocket.ts +555 -0
  74. package/package.json +44 -0
  75. package/quickwin.d.ts +594 -0
  76. package/quickwin_const.d.ts +900 -0
  77. package/qwin-nowasm.exe +0 -0
  78. package/qwin.exe +0 -0
  79. package/test/add.wasm +0 -0
  80. package/test/complex.wasm +0 -0
  81. package/test/complex_imports.wasm +0 -0
  82. package/test/debug/http_server_e2e.js +31 -0
  83. package/test/debug/minwasm.js +52 -0
  84. package/test/debug/mupdf_debug.js +104 -0
  85. package/test/debug/wasm.js +122 -0
  86. package/test/debug/wasm_export_debug.js +64 -0
  87. package/test/debug/wasm_names.js +46 -0
  88. package/test/global_imports.wasm +0 -0
  89. package/test/import_func.wasm +0 -0
  90. package/test/imports.wasm +0 -0
  91. package/test/run.js +91 -0
  92. package/test/run.ts +96 -0
  93. package/test/sjlj.wasm +0 -0
  94. package/test/test_basic.js +7 -0
  95. package/test/test_basic.ts +9 -0
  96. package/test/test_basic_fetch.js +34 -0
  97. package/test/test_basic_fetch.ts +33 -0
  98. package/test/test_brotli.js +48 -0
  99. package/test/test_brotli.ts +52 -0
  100. package/test/test_fetch_cache.js +169 -0
  101. package/test/test_fetch_cache.ts +187 -0
  102. package/test/test_ffi.js +157 -0
  103. package/test/test_ffi.ts +174 -0
  104. package/test/test_frame_encoding.js +128 -0
  105. package/test/test_frame_encoding.ts +132 -0
  106. package/test/test_helper.js +84 -0
  107. package/test/test_helper.ts +80 -0
  108. package/test/test_http_import.js +78 -0
  109. package/test/test_http_import.ts +74 -0
  110. package/test/test_http_server.js +142 -0
  111. package/test/test_http_server.ts +136 -0
  112. package/test/test_import_dir.js +4 -0
  113. package/test/test_import_dir.ts +5 -0
  114. package/test/test_ipv6.js +134 -0
  115. package/test/test_ipv6.ts +129 -0
  116. package/test/test_jsx.js +1314 -0
  117. package/test/test_meta_url.js +3 -0
  118. package/test/test_meta_url.ts +4 -0
  119. package/test/test_mupdf_render.js +69 -0
  120. package/test/test_mupdf_render.ts +74 -0
  121. package/test/test_mupdf_twice.js +77 -0
  122. package/test/test_mupdf_twice.ts +81 -0
  123. package/test/test_mupdf_wasm.js +33 -0
  124. package/test/test_mupdf_wasm.ts +30 -0
  125. package/test/test_net_event.js +57 -0
  126. package/test/test_net_event.ts +55 -0
  127. package/test/test_net_fetch.js +259 -0
  128. package/test/test_net_fetch.ts +238 -0
  129. package/test/test_net_websocket.js +180 -0
  130. package/test/test_net_websocket.ts +164 -0
  131. package/test/test_polyfill.js +144 -0
  132. package/test/test_polyfill.ts +159 -0
  133. package/test/test_react_complex.js +17440 -0
  134. package/test/test_react_counter.js +17331 -0
  135. package/test/test_react_flex.js +17643 -0
  136. package/test/test_react_hidden.js +17336 -0
  137. package/test/test_react_listview_link.js +17371 -0
  138. package/test/test_react_render.js +17326 -0
  139. package/test/test_url.js +173 -0
  140. package/test/test_url.ts +183 -0
  141. package/test/test_wasm_basic.js +85 -0
  142. package/test/test_wasm_basic.ts +73 -0
  143. package/test/test_wasm_import_global.js +41 -0
  144. package/test/test_wasm_import_global.ts +45 -0
  145. package/test/test_wasm_sjlj.js +145 -0
  146. package/test/test_wasm_sjlj.ts +125 -0
  147. package/test/test_wasm_types.js +97 -0
  148. package/test/test_wasm_types.ts +124 -0
  149. package/test/test_worker.js +21 -0
  150. package/test/test_worker.ts +24 -0
  151. package/test/test_worker_fetch.js +26 -0
  152. package/test/test_worker_fetch.ts +27 -0
  153. package/test/test_worker_net.js +51 -0
  154. package/test/test_worker_net.ts +54 -0
  155. package/test/test_worker_wasm_concurrent.js +44 -0
  156. package/test/test_worker_wasm_concurrent.ts +45 -0
  157. package/test/types.wasm +0 -0
  158. package/test/worker_fetch.js +13 -0
  159. package/test/worker_fetch.ts +13 -0
  160. package/test/worker_helper.js +1 -0
  161. package/test/worker_helper.ts +1 -0
  162. package/test/worker_http.js +18 -0
  163. package/test/worker_http.ts +20 -0
  164. package/test/worker_import_lib.js +12 -0
  165. package/test/worker_import_lib.ts +13 -0
  166. package/test/worker_module.js +16 -0
  167. package/test/worker_module.ts +17 -0
  168. package/test/worker_wasm_concurrent.js +22 -0
  169. package/test/worker_wasm_concurrent.ts +22 -0
  170. package/tsconfig.json +27 -0
  171. package/vendor/mupdf-wasm/mupdf-wasm.d.ts +571 -0
  172. package/vendor/mupdf-wasm/mupdf-wasm.js +2749 -0
  173. package/vendor/mupdf-wasm/mupdf-wasm.wasm +0 -0
  174. package/vendor/mupdf-wasm/mupdf.d.ts +939 -0
  175. package/vendor/mupdf-wasm/mupdf.js +3317 -0
@@ -0,0 +1,373 @@
1
+ import ReactReconciler from 'react-reconciler'
2
+ import { createContext } from 'react'
3
+ import { DefaultEventPriority, NoEventPriority } from 'react-reconciler/constants'
4
+ import * as gui from 'gui'
5
+ import * as os from 'os'
6
+ import { applyProps } from './props.js'
7
+ import { calculateFlexLayout, type FlexStyle } from './layout.js'
8
+ import { getButtonIdealSize, measureTextForHwnd } from '../text-measure.js'
9
+ import type { WIntrinsicProps } from './jsx.js'
10
+
11
+ // DEBUG 由 esbuild --define 在 bundle 时替换(见 build.ts),生产环境为 false
12
+ declare const DEBUG: boolean
13
+
14
+ const dpiFont = gui.CreateSystemDpiFont()
15
+ export const scaleFactor = gui.GetScaleFactor()
16
+
17
+ type Container = gui.HWND
18
+ export type Props = WIntrinsicProps
19
+
20
+ export interface Instance {
21
+ hwnd: gui.HWND | null
22
+ type: string
23
+ props: Props
24
+ children: Instance[]
25
+ lastRect?: { x: number; y: number; w: number; h: number }
26
+ }
27
+
28
+ const DELAYED_CONTROLS = new Set(['SysListView32', 'SysTreeView32', 'LISTBOX', 'COMBOBOX', 'msctls_trackbar32', 'SysDateTimePick32', 'SysLink'])
29
+
30
+ function isDelayedControl(winClass: string): boolean {
31
+ return DELAYED_CONTROLS.has(winClass)
32
+ }
33
+
34
+ function setupWindowProc(instance: Instance, hwnd: gui.HWND) {
35
+ instance.hwnd = hwnd
36
+ const oldProc = gui.GetWindowLongPtr(hwnd, gui.Gwlp.WNDPROC)
37
+ instancesByHwnd.set(hwnd, instance)
38
+ gui.SetWindowProc(hwnd, (hwnd: gui.HWND, msg: number, wParam: number, lParam: number) => {
39
+ const ev = instance.props.onEvent
40
+ if (!ev) return gui.CallWindowProc(oldProc, hwnd, msg, wParam, lParam)
41
+ if (typeof ev === 'object') {
42
+ return ev.fn({ hwnd, msg, wParam, lParam, callOldWndProc: () => gui.CallWindowProc(oldProc, hwnd, msg, wParam, lParam) })
43
+ }
44
+ const result = gui.CallWindowProc(oldProc, hwnd, msg, wParam, lParam)
45
+ const override = ev({ hwnd, msg, wParam, lParam })
46
+ return typeof override === 'number' && Number.isInteger(override) ? override : result
47
+ })
48
+ }
49
+
50
+ function ensureChildWindow(child: Instance, parentHwnd: gui.HWND): gui.HWND {
51
+ if (child.hwnd !== null) return child.hwnd
52
+ const sty = child.props.style || {}
53
+ const ws = ((child.props.ws ?? 0) | gui.WindowStyle.CHILD) & ~gui.WindowStyle.VISIBLE
54
+ const hwnd = gui.CreateWindow(
55
+ child.type, child.props.text || '', ws,
56
+ 0, 0,
57
+ (typeof sty.width === 'number' ? sty.width : 100) * scaleFactor, (typeof sty.height === 'number' ? sty.height : 30) * scaleFactor,
58
+ parentHwnd, null
59
+ )!
60
+ if (dpiFont) gui.SendMessage(hwnd, gui.WmMsg.SETFONT, dpiFont, 1)
61
+ setupWindowProc(child, hwnd)
62
+ return hwnd
63
+ }
64
+
65
+ type HostContext = Record<string, never>
66
+
67
+ export const instancesByHwnd = new Map<gui.HWND, Instance>()
68
+
69
+ function runFlexLayout(inst: Instance) {
70
+ const children = inst.children
71
+ if (children.length === 0) return
72
+ const s = inst.props.style
73
+ const flex: FlexStyle = s || {}
74
+ const visible = children.filter(c => !c.props.hidden)
75
+ if (visible.length === 0) return
76
+ const rect = gui.GetClientRect(inst.hwnd!)
77
+ if (!rect) { console.log('flex: no rect for', inst.hwnd, inst.type); return }
78
+ const pw = (rect.right - rect.left) / scaleFactor
79
+ const ph = (rect.bottom - rect.top) / scaleFactor
80
+ if (pw <= 0 || ph <= 0) { console.log('flex: zero size for', inst.hwnd, inst.type, pw, ph); return }
81
+ const autoSizes = new Map<Instance, { w: number; h: number }>()
82
+ for (const child of visible) {
83
+ const sty = child.props.style || {}
84
+ if (!child.hwnd) continue
85
+ if (child.type === 'BUTTON' && (sty.width === 'auto' || sty.height === 'auto')) {
86
+ const ideal = getButtonIdealSize(child.hwnd)
87
+ autoSizes.set(child, { w: ideal.width / scaleFactor, h: ideal.height / scaleFactor })
88
+ } else if (child.type === 'STATIC' && (sty.width === 'auto' || sty.height === 'auto') && child.props.text) {
89
+ const measured = measureTextForHwnd(child.hwnd, child.props.text!)
90
+ autoSizes.set(child, { w: measured.width / scaleFactor, h: measured.height / scaleFactor })
91
+ }
92
+ }
93
+ const results = calculateFlexLayout(flex, pw, ph, visible.map(c => {
94
+ const sty = c.props.style || {}
95
+ const auto = autoSizes.get(c)
96
+ return {
97
+ style: {
98
+ ...sty,
99
+ width: auto ? (sty.width === 'auto' ? auto.w : sty.width) : sty.width,
100
+ height: auto ? (sty.height === 'auto' ? auto.h : sty.height) : sty.height,
101
+ }
102
+ }
103
+ }))
104
+ const pl = flex.paddingLeft ?? flex.padding ?? 0
105
+ const pt = flex.paddingTop ?? flex.padding ?? 0
106
+ for (let i = 0; i < results.length; i++) {
107
+ const r = results[i]!
108
+ const child = visible[i]!
109
+ const lr = child.lastRect
110
+ if (lr && lr.x === r.x && lr.y === r.y && lr.w === r.width && lr.h === r.height) continue
111
+ console.log('flex: set', child.type, child.hwnd, 'to', r.x, r.y, r.width, r.height)
112
+ gui.SetWindowPos(child.hwnd!, gui.SetWindowPosHwnd.TOP, (r.x + pl) * scaleFactor, (r.y + pt) * scaleFactor, r.width * scaleFactor, r.height * scaleFactor, gui.SetWindowPosFlag.SWP_SHOWWINDOW)
113
+ gui.InvalidateRect(child.hwnd!, null, true)
114
+ child.lastRect = { x: r.x, y: r.y, w: r.width, h: r.height }
115
+ }
116
+ for (const c of children) runFlexLayout(c)
117
+ }
118
+
119
+ export function forceFlexLayout(hwnd: gui.HWND): void {
120
+ const inst = instancesByHwnd.get(hwnd)
121
+ if (inst) runFlexLayout(inst)
122
+ }
123
+
124
+ /**
125
+ * 扩展 HostConfig 类型定义
126
+ *
127
+ * @types/react-reconciler 的 HostConfig 存在以下问题:
128
+ * 1. 缺少 rendererPackageName/rendererVersion 属性
129
+ *
130
+ * 解决方案:扩展补充缺失定义
131
+ */
132
+ type QuickWinHostConfig = ReactReconciler.HostConfig<
133
+ string, Props, Container, Instance, Instance,
134
+ never, never, never, gui.HWND,
135
+ HostContext, never, number, -1, null
136
+ > & {
137
+ // rendererPackageName/rendererVersion(原类型定义中缺失)
138
+ rendererPackageName: string
139
+ rendererVersion: string
140
+ }
141
+
142
+ let currentUpdatePriority = NoEventPriority
143
+
144
+ const hostConfig: QuickWinHostConfig = {
145
+ // Core methods
146
+ createInstance(type: string, props: Props, rootContainer: Container) {
147
+ if (DEBUG) console.log('[reconciler] createInstance called:', type, 'class=' + props.type)
148
+ const winClass = props.type
149
+ if (isDelayedControl(winClass)) {
150
+ if (DEBUG) console.log('[reconciler] delayed control, skipping CreateWindow:', winClass)
151
+ return { hwnd: null, type: winClass, props, children: [] }
152
+ }
153
+ if (winClass === 'STATIC' && props.text !== undefined && props.children !== undefined && props.children !== null) {
154
+ throw new Error('[STATIC] text and children are mutually exclusive')
155
+ }
156
+ const sty = props.style || {}
157
+ // reconciler 创建的都是子窗口,确保 WS_CHILD 避免定位异常;创建时不带 WS_VISIBLE 防止 (0,0) 闪烁
158
+ const ws = ((props.ws ?? 0) | gui.WindowStyle.CHILD) & ~gui.WindowStyle.VISIBLE
159
+ if (DEBUG) console.log('[reconciler] CreateWindow args:', winClass, props.text ?? '', ws, 0, 0, sty.width ?? 100, sty.height ?? 30, rootContainer)
160
+ const hwnd = gui.CreateWindow(
161
+ winClass, props.text ?? '', ws,
162
+ 0, 0,
163
+ (typeof sty.width === 'number' ? sty.width : 100) * scaleFactor, (typeof sty.height === 'number' ? sty.height : 30) * scaleFactor,
164
+ rootContainer, null
165
+ )!
166
+ if (dpiFont) gui.SendMessage(hwnd, gui.WmMsg.SETFONT, dpiFont, 1)
167
+ if (DEBUG) console.log('[reconciler] createInstance hwnd result:', hwnd, 'null?', hwnd === null)
168
+ const instance: Instance = { hwnd, type: winClass, props, children: [] }
169
+ setupWindowProc(instance, hwnd)
170
+ return instance
171
+ },
172
+
173
+ createTextInstance(_text: string, _rootContainer: Container) {
174
+ throw new Error('should never be called (shouldSetTextContent=true)')
175
+ },
176
+
177
+ appendInitialChild(parent: Instance, child: Instance) {
178
+ if (child.hwnd === null) {
179
+ ensureChildWindow(child, parent.hwnd!)
180
+ } else {
181
+ gui.SetParent(child.hwnd, parent.hwnd)
182
+ }
183
+ if (DEBUG) console.log('[reconciler] appendInitialChild parent:', parent.hwnd, 'child:', child.hwnd)
184
+ parent.children.push(child)
185
+ },
186
+
187
+ appendChild(parent: Instance, child: Instance) {
188
+ if (child.hwnd === null) {
189
+ ensureChildWindow(child, parent.hwnd!)
190
+ } else {
191
+ gui.SetParent(child.hwnd, parent.hwnd)
192
+ }
193
+ if (DEBUG) console.log('[reconciler] appendChild parent:', parent.hwnd, 'child:', child.hwnd)
194
+ parent.children.push(child)
195
+ },
196
+
197
+ appendChildToContainer(container: Container, child: Instance) {
198
+ if (child.hwnd === null) {
199
+ ensureChildWindow(child, container)
200
+ } else {
201
+ gui.SetParent(child.hwnd, container)
202
+ }
203
+ const rootInst = instancesByHwnd.get(container)
204
+ if (rootInst) rootInst.children.push(child)
205
+ if (DEBUG) console.log('[reconciler] appendChildToContainer container:', container, 'child hwnd:', child.hwnd)
206
+ },
207
+
208
+ insertBefore(parent: Instance, child: Instance, beforeChild: Instance) {
209
+ if (child.hwnd === null) {
210
+ ensureChildWindow(child, parent.hwnd!)
211
+ } else {
212
+ gui.SetParent(child.hwnd, parent.hwnd)
213
+ }
214
+ if (DEBUG) console.log('[reconciler] insertBefore parent:', parent.hwnd, 'child:', child.hwnd, 'before:', beforeChild.hwnd)
215
+ const idx = parent.children.indexOf(beforeChild)
216
+ if (idx >= 0) parent.children.splice(idx, 0, child)
217
+ },
218
+
219
+ insertInContainerBefore(container: Container, child: Instance, _before: Instance) {
220
+ if (child.hwnd === null) {
221
+ ensureChildWindow(child, container)
222
+ } else {
223
+ gui.SetParent(child.hwnd, container)
224
+ }
225
+ const rootInst = instancesByHwnd.get(container)
226
+ if (!rootInst) throw new Error('insertInContainerBefore: no root instance for container')
227
+ const idx = rootInst.children.indexOf(_before)
228
+ if (idx >= 0) rootInst.children.splice(idx, 0, child)
229
+ else rootInst.children.push(child)
230
+ if (DEBUG) console.log('[reconciler] insertInContainerBefore container:', container, 'child hwnd:', child.hwnd)
231
+ },
232
+
233
+ removeChild(parent: Instance, child: Instance) {
234
+ if (DEBUG) console.log('[reconciler] removeChild parent:', parent.hwnd, 'child:', child.hwnd, 'type:', child.type)
235
+ if (child.hwnd !== null) gui.DestroyWindow(child.hwnd)
236
+ const idx = parent.children.indexOf(child)
237
+ if (idx >= 0) parent.children.splice(idx, 1)
238
+ },
239
+
240
+ removeChildFromContainer(container: Container, child: Instance) {
241
+ if (child.hwnd === null) return
242
+ if (DEBUG) console.log('[reconciler] removeChildFromContainer container:', container, 'child hwnd:', child.hwnd)
243
+ gui.DestroyWindow(child.hwnd)
244
+ const rootInst = instancesByHwnd.get(container)
245
+ if (rootInst) {
246
+ const idx = rootInst.children.indexOf(child)
247
+ if (idx >= 0) rootInst.children.splice(idx, 1)
248
+ }
249
+ },
250
+
251
+ commitUpdate(instance: Instance, _type: string, oldProps: Props, newProps: Props, _internalHandle: unknown) {
252
+ applyProps(instance, newProps, oldProps)
253
+ },
254
+
255
+ commitMount(_instance: Instance, _type: string, _props: Props, _internal: unknown) { },
256
+
257
+ finalizeInitialChildren(instance: Instance, type: string, props: Props) {
258
+ if (DEBUG) console.log('[reconciler] finalizeInitialChildren instance:', instance.hwnd, 'props:', JSON.stringify(props))
259
+ applyProps(instance, props, { type })
260
+ return false
261
+ },
262
+
263
+ resetAfterCommit(containerInfo: Container) {
264
+ if (DEBUG) console.log('[reconciler] resetAfterCommit')
265
+ const rootInst = instancesByHwnd.get(containerInfo)
266
+ if (!rootInst) throw new Error('resetAfterCommit: no root instance for container')
267
+ runFlexLayout(rootInst)
268
+ },
269
+
270
+ resetTextContent(_instance: Instance) { },
271
+
272
+ commitTextUpdate(instance: Instance, _oldText: string, newText: string) {
273
+ gui.SetWindowText(instance.hwnd!, newText)
274
+ },
275
+
276
+ hideInstance(instance: Instance) {
277
+ if (instance.hwnd !== null) gui.ShowWindow(instance.hwnd, gui.ShowWindowCmd.HIDE)
278
+ },
279
+
280
+ hideTextInstance(instance: Instance) {
281
+ if (instance.hwnd !== null) gui.ShowWindow(instance.hwnd, gui.ShowWindowCmd.HIDE)
282
+ },
283
+
284
+ unhideInstance(instance: Instance, _props: Props) {
285
+ if (instance.hwnd !== null) gui.ShowWindow(instance.hwnd, gui.ShowWindowCmd.SHOW)
286
+ },
287
+
288
+ unhideTextInstance(instance: Instance, _text: string) {
289
+ if (instance.hwnd !== null) gui.ShowWindow(instance.hwnd, gui.ShowWindowCmd.SHOW)
290
+ },
291
+
292
+ shouldSetTextContent(_type: string, props: Props) {
293
+ return typeof props.children === 'string' || typeof props.children === 'number'
294
+ },
295
+
296
+ getPublicInstance(instance: Instance) {
297
+ return instance.hwnd!
298
+ },
299
+
300
+ getRootHostContext(_rootContainer: Container) {
301
+ return {}
302
+ },
303
+
304
+ getChildHostContext(_parentContext: HostContext, _type: string) {
305
+ return {}
306
+ },
307
+
308
+ prepareForCommit(_containerInfo: Container) {
309
+ return null
310
+ },
311
+
312
+ preparePortalMount(_containerInfo: Container) { },
313
+
314
+ clearContainer(_container: Container) {
315
+ // 不需要清理,React reconciler 会通过 removeChildFromContainer 来移除子节点
316
+ },
317
+
318
+ scheduleTimeout(fn: () => void, delay: number) {
319
+ return os.setTimeout(fn, delay)
320
+ },
321
+
322
+ cancelTimeout(id: os.TimerId) {
323
+ os.clearTimeout?.(id)
324
+ },
325
+
326
+ noTimeout: -1,
327
+
328
+ supportsMutation: true,
329
+ supportsPersistence: false,
330
+ supportsHydration: false,
331
+ isPrimaryRenderer: true,
332
+ supportsMicrotasks: false,
333
+
334
+ setCurrentUpdatePriority(p: number) { currentUpdatePriority = p },
335
+ getCurrentUpdatePriority() { return currentUpdatePriority },
336
+ resolveUpdatePriority() { return DefaultEventPriority },
337
+
338
+ resolveEventType() { return null },
339
+ resolveEventTimeStamp() { return Date.now() },
340
+ trackSchedulerEvent() { },
341
+
342
+ shouldAttemptEagerTransition() { return false },
343
+ detachDeletedInstance(instance: Instance) {
344
+ if (DEBUG) console.log('[reconciler] detachDeletedInstance hwnd:', instance.hwnd, 'type:', instance.type)
345
+ if (instance.hwnd !== null) instancesByHwnd.delete(instance.hwnd)
346
+ },
347
+
348
+ // 添加必需方法
349
+ getInstanceFromNode(_node: unknown) { return null },
350
+ beforeActiveInstanceBlur() { },
351
+ afterActiveInstanceBlur() { },
352
+ prepareScopeUpdate(_scopeInstance: unknown, _instance: unknown) { },
353
+ getInstanceFromScope(_scopeInstance: unknown) { return null },
354
+
355
+ // Suspense/Concurrent Mode 支持
356
+ maySuspendCommit() { return false },
357
+ requestPostPaintCallback() { },
358
+ preloadInstance() { return true },
359
+ startSuspendingCommit() { },
360
+ suspendInstance() { },
361
+ waitForCommitToBeReady() { return null },
362
+
363
+ rendererVersion: '0.1.0',
364
+ rendererPackageName: 'react-qw',
365
+ NotPendingTransition: null,
366
+ // @types/react.Context<T> 与 @types/react-reconciler.ReactContext<T> 是同一运行时对象
367
+ // 的两个不兼容类型定义(ReactContext 多 _currentValue 等字段),此 cast 不可避免
368
+ HostTransitionContext: createContext(null) as unknown as ReactReconciler.ReactContext<null>,
369
+ resetFormInstance(_form: never) { },
370
+ }
371
+
372
+ const reconciler = ReactReconciler(hostConfig)
373
+ export default reconciler
package/lib/stream.js ADDED
@@ -0,0 +1,2 @@
1
+ import { ReadableStream as ReadableStreamImpl, } from './vendor/web-streams/ponyfill.mjs';
2
+ globalThis.ReadableStream = ReadableStreamImpl;
package/lib/stream.ts ADDED
@@ -0,0 +1,22 @@
1
+ export {}
2
+
3
+ import {
4
+ ReadableStream as ReadableStreamImpl,
5
+ ReadableStreamDefaultController as ReadableStreamDefaultControllerImpl,
6
+ ReadableStreamDefaultReader as ReadableStreamDefaultReaderImpl,
7
+ } from './vendor/web-streams/ponyfill.mjs'
8
+
9
+ declare global {
10
+ type ReadableStreamReadResult<R = any> =
11
+ | { done: false; value: R }
12
+ | { done: true; value?: undefined }
13
+
14
+ interface ReadableStreamReader<R = any> extends ReadableStreamDefaultReaderImpl<R> {}
15
+ interface ReadableStreamDefaultReader<R = any> extends ReadableStreamDefaultReaderImpl<R> {}
16
+ interface ReadableStream<R = any> extends ReadableStreamImpl<R> {}
17
+ interface ReadableStreamDefaultController<R = any> extends ReadableStreamDefaultControllerImpl<R> {}
18
+
19
+ var ReadableStream: typeof ReadableStreamImpl
20
+ }
21
+
22
+ globalThis.ReadableStream = ReadableStreamImpl
@@ -0,0 +1,197 @@
1
+ const _labelMap = {
2
+ 'utf-8': 'utf-8',
3
+ 'utf8': 'utf-8',
4
+ 'unicode-1-1-utf-8': 'utf-8',
5
+ 'utf-16': 'utf-16le',
6
+ 'utf-16le': 'utf-16le',
7
+ 'utf-16be': 'utf-16be',
8
+ };
9
+ function _normalizeLabel(label) {
10
+ if (!label)
11
+ return 'utf-8';
12
+ const result = _labelMap[label.trim().toLowerCase()];
13
+ if (result)
14
+ return result;
15
+ throw new RangeError(`The encoding label "${label}" is not supported`);
16
+ }
17
+ function _decodeUTF8(buf, fatal) {
18
+ let out = '';
19
+ for (let i = 0; i < buf.length;) {
20
+ const b = buf[i++];
21
+ if (b < 0x80) {
22
+ out += String.fromCharCode(b);
23
+ continue;
24
+ }
25
+ if (b < 0xC0) {
26
+ out += fatal ? (() => { throw new TypeError('unexpected continuation byte'); })() : '\uFFFD';
27
+ continue;
28
+ }
29
+ let c, min;
30
+ if (b < 0xE0) {
31
+ if (i >= buf.length) {
32
+ out += fatal ? (() => { throw new TypeError('incomplete utf-8'); })() : '\uFFFD';
33
+ break;
34
+ }
35
+ const b2 = buf[i++];
36
+ if ((b2 & 0xC0) !== 0x80) {
37
+ out += '\uFFFD';
38
+ continue;
39
+ }
40
+ c = ((b & 0x1F) << 6) | (b2 & 0x3F);
41
+ min = 0x80;
42
+ }
43
+ else if (b < 0xF0) {
44
+ if (i + 1 >= buf.length) {
45
+ out += fatal ? (() => { throw new TypeError('incomplete utf-8'); })() : '\uFFFD';
46
+ break;
47
+ }
48
+ const b2 = buf[i++];
49
+ const b3 = buf[i++];
50
+ if (((b2 & 0xC0) !== 0x80) || ((b3 & 0xC0) !== 0x80)) {
51
+ out += '\uFFFD';
52
+ continue;
53
+ }
54
+ c = ((b & 0x0F) << 12) | ((b2 & 0x3F) << 6) | (b3 & 0x3F);
55
+ min = 0x800;
56
+ }
57
+ else if (b < 0xF8) {
58
+ if (i + 2 >= buf.length) {
59
+ out += fatal ? (() => { throw new TypeError('incomplete utf-8'); })() : '\uFFFD';
60
+ break;
61
+ }
62
+ const b2 = buf[i++];
63
+ const b3 = buf[i++];
64
+ const b4 = buf[i++];
65
+ if (((b2 & 0xC0) !== 0x80) || ((b3 & 0xC0) !== 0x80) || ((b4 & 0xC0) !== 0x80)) {
66
+ out += '\uFFFD';
67
+ continue;
68
+ }
69
+ c = ((b & 0x07) << 18) | ((b2 & 0x3F) << 12) | ((b3 & 0x3F) << 6) | (b4 & 0x3F);
70
+ min = 0x10000;
71
+ }
72
+ else {
73
+ out += fatal ? (() => { throw new TypeError('invalid utf-8 start'); })() : '\uFFFD';
74
+ continue;
75
+ }
76
+ if (c < min || (c >= 0xD800 && c <= 0xDFFF) || c > 0x10FFFF) {
77
+ out += fatal ? (() => { throw new TypeError('invalid utf-8 codepoint'); })() : '\uFFFD';
78
+ continue;
79
+ }
80
+ if (c <= 0xFFFF)
81
+ out += String.fromCharCode(c);
82
+ else {
83
+ c -= 0x10000;
84
+ out += String.fromCharCode(0xD800 | (c >> 10), 0xDC00 | (c & 0x3FF));
85
+ }
86
+ }
87
+ return out;
88
+ }
89
+ function _decodeUTF16(buf, le, fatal) {
90
+ const dv = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
91
+ let out = '';
92
+ for (let i = 0; i + 1 < buf.length; i += 2) {
93
+ let c = dv.getUint16(i, le);
94
+ if (c >= 0xD800 && c <= 0xDBFF) {
95
+ i += 2;
96
+ if (i + 1 >= buf.length) {
97
+ out += fatal ? (() => { throw new TypeError('truncated surrogate pair'); })() : '\uFFFD';
98
+ break;
99
+ }
100
+ const c2 = dv.getUint16(i, le);
101
+ if (c2 >= 0xDC00 && c2 <= 0xDFFF) {
102
+ out += String.fromCharCode(c, c2);
103
+ }
104
+ else {
105
+ out += fatal ? (() => { throw new TypeError('invalid surrogate pair'); })() : '\uFFFD';
106
+ i -= 2;
107
+ }
108
+ }
109
+ else if (c >= 0xDC00 && c <= 0xDFFF) {
110
+ out += fatal ? (() => { throw new TypeError('unexpected trailing surrogate'); })() : '\uFFFD';
111
+ }
112
+ else {
113
+ out += String.fromCharCode(c);
114
+ }
115
+ }
116
+ return out;
117
+ }
118
+ class TextDecoderImpl {
119
+ _encoding;
120
+ _fatal;
121
+ _ignoreBOM;
122
+ constructor(label, options) {
123
+ this._encoding = _normalizeLabel(label);
124
+ this._fatal = options?.fatal ?? false;
125
+ this._ignoreBOM = options?.ignoreBOM ?? false;
126
+ }
127
+ get encoding() { return this._encoding; }
128
+ get fatal() { return this._fatal; }
129
+ get ignoreBOM() { return this._ignoreBOM; }
130
+ decode(buffer) {
131
+ if (!buffer)
132
+ return '';
133
+ const arr = buffer instanceof Uint8Array ? buffer
134
+ : buffer instanceof ArrayBuffer ? new Uint8Array(buffer)
135
+ : new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
136
+ if (this._encoding === 'utf-8') {
137
+ return _decodeUTF8(arr, this._fatal);
138
+ }
139
+ const le = this._encoding === 'utf-16le';
140
+ let offset = 0;
141
+ if (arr.length >= 2 && !this._ignoreBOM) {
142
+ const bomLo = le ? arr[0] : arr[1];
143
+ const bomHi = le ? arr[1] : arr[0];
144
+ const bom = (bomHi << 8) | bomLo;
145
+ if (bom === 0xFEFF || bom === 0xFFFE) {
146
+ offset = 2;
147
+ }
148
+ }
149
+ return _decodeUTF16(arr.slice(offset), le, this._fatal);
150
+ }
151
+ }
152
+ class TextEncoderImpl {
153
+ _encoding;
154
+ constructor(label) {
155
+ this._encoding = _normalizeLabel(label);
156
+ }
157
+ get encoding() { return this._encoding; }
158
+ encode(input) {
159
+ if (!input)
160
+ return new Uint8Array(0);
161
+ if (this._encoding === 'utf-8') {
162
+ const bytes = [];
163
+ for (let i = 0; i < input.length; i++) {
164
+ let c = input.charCodeAt(i);
165
+ if (c < 0x80) {
166
+ bytes.push(c);
167
+ }
168
+ else if (c < 0x800) {
169
+ bytes.push(0xC0 | (c >> 6), 0x80 | (c & 0x3F));
170
+ }
171
+ else if (c < 0xD800 || c >= 0xE000) {
172
+ bytes.push(0xE0 | (c >> 12), 0x80 | ((c >> 6) & 0x3F), 0x80 | (c & 0x3F));
173
+ }
174
+ else {
175
+ i++;
176
+ const c2 = input.charCodeAt(i);
177
+ c = 0x10000 + ((c & 0x3FF) << 10) | (c2 & 0x3FF);
178
+ bytes.push(0xF0 | (c >> 18), 0x80 | ((c >> 12) & 0x3F), 0x80 | ((c >> 6) & 0x3F), 0x80 | (c & 0x3F));
179
+ }
180
+ }
181
+ return new Uint8Array(bytes);
182
+ }
183
+ const le = this._encoding === 'utf-16le';
184
+ const buf = new ArrayBuffer(input.length * 2);
185
+ const dv = new DataView(buf);
186
+ for (let i = 0; i < input.length; i++)
187
+ dv.setUint16(i * 2, input.charCodeAt(i), le);
188
+ return new Uint8Array(buf);
189
+ }
190
+ }
191
+ if (typeof globalThis.TextDecoder === 'undefined') {
192
+ globalThis.TextDecoder = TextDecoderImpl;
193
+ }
194
+ if (typeof globalThis.TextEncoder === 'undefined') {
195
+ globalThis.TextEncoder = TextEncoderImpl;
196
+ }
197
+ export {};