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,54 @@
1
+ import { Tester } from './test_helper.js'
2
+ import * as os from 'os'
3
+
4
+ export const suite = {
5
+ name: 'worker-http',
6
+ run: async (t: Tester) => {
7
+ t.section('import-inside')
8
+ let worker1: any
9
+ const { data: r1 } = await new Promise<any>((resolve, reject) => {
10
+ worker1 = new os.Worker('./worker_http.js')
11
+ const timer = os.setTimeout(() => reject(new Error('timeout')), 15000)
12
+ worker1.onmessage = (e: any) => {
13
+ os.clearTimeout(timer)
14
+ resolve({ worker: worker1, data: e.data })
15
+ }
16
+ worker1.postMessage({ type: 'start' })
17
+ })
18
+ t.check('message type', 'result', r1.type)
19
+ t.checkTrue('isArray([])', r1.isArrayWorks)
20
+ t.checkTrue('isArray({}) rejects', r1.isArrayRejects)
21
+
22
+ worker1.postMessage({ type: 'done' })
23
+ worker1.onmessage = null
24
+
25
+ t.section('http-entry')
26
+ try {
27
+ new os.Worker('https://esm.sh/isarray')
28
+ await new Promise<void>(resolve => os.setTimeout(() => resolve(), 3000))
29
+ t.checkTrue('worker created with http url', true)
30
+ } catch (e) {
31
+ t.checkTrue('worker creation failed: ' + e, false)
32
+ }
33
+
34
+ t.section('npm-package')
35
+ let worker3: any
36
+ try {
37
+ const { data: r3 } = await new Promise<any>((resolve, reject) => {
38
+ worker3 = new os.Worker('https://cdn.jsdelivr.net/npm/quickwin/test/worker_module.js')
39
+ const timer = os.setTimeout(() => reject(new Error('timeout')), 15000)
40
+ worker3.onmessage = (e: any) => {
41
+ os.clearTimeout(timer)
42
+ resolve({ worker: worker3, data: e.data })
43
+ }
44
+ worker3.postMessage({ type: 'start' })
45
+ })
46
+ t.check('npm worker message type', 'result', r3.type)
47
+ t.check('npm worker imported value', 42, r3.value)
48
+ worker3.postMessage({ type: 'done' })
49
+ worker3.onmessage = null
50
+ } catch (e) {
51
+ t.checkTrue('npm worker failed: ' + e, false)
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,44 @@
1
+ import { readWasmFile } from './test_helper.js';
2
+ import * as os from 'os';
3
+ export const suite = {
4
+ name: 'worker-wasm',
5
+ run: async (t) => {
6
+ const wasmBuf = readWasmFile('./add.wasm');
7
+ if (!wasmBuf) {
8
+ t.fail++;
9
+ return;
10
+ }
11
+ const complexBuf = readWasmFile('./complex.wasm');
12
+ if (!complexBuf) {
13
+ t.fail++;
14
+ return;
15
+ }
16
+ t.section('concurrent');
17
+ const worker = new os.Worker('./worker_wasm_concurrent.js');
18
+ const workerResult = new Promise((resolve, reject) => {
19
+ const timer = os.setTimeout(() => reject(new Error('worker timeout')), 5000);
20
+ worker.onmessage = (e) => {
21
+ os.clearTimeout(timer);
22
+ resolve(e.data);
23
+ };
24
+ worker.postMessage({
25
+ type: 'start',
26
+ wasmBuf,
27
+ calls: [['add', [1, 2]], ['add', [10, 20]]]
28
+ });
29
+ });
30
+ const mainMod = new WebAssembly.Module(wasmBuf);
31
+ const mainInst = new WebAssembly.Instance(mainMod);
32
+ const mainExp = mainInst.exports;
33
+ const mainR1 = mainExp.add(1, 2);
34
+ const mainR2 = mainExp.add(10, 20);
35
+ const wr = await workerResult;
36
+ t.check('main add(1, 2)', 3, mainR1);
37
+ t.check('main add(10, 20)', 30, mainR2);
38
+ t.check('worker ok', true, wr.ok);
39
+ t.check('worker add(1, 2)', 3, wr.results[0]);
40
+ t.check('worker add(10, 20)', 30, wr.results[1]);
41
+ worker.postMessage({ type: 'done' });
42
+ worker.onmessage = null;
43
+ }
44
+ };
@@ -0,0 +1,45 @@
1
+ import { Tester, readWasmFile } from './test_helper.js'
2
+ import * as os from 'os'
3
+
4
+ export const suite = {
5
+ name: 'worker-wasm',
6
+ run: async (t: Tester) => {
7
+ const wasmBuf = readWasmFile('./add.wasm')
8
+ if (!wasmBuf) { t.fail++; return }
9
+
10
+ const complexBuf = readWasmFile('./complex.wasm')
11
+ if (!complexBuf) { t.fail++; return }
12
+
13
+ t.section('concurrent')
14
+
15
+ const worker = new os.Worker('./worker_wasm_concurrent.js')
16
+ const workerResult = new Promise<any>((resolve, reject) => {
17
+ const timer = os.setTimeout(() => reject(new Error('worker timeout')), 5000)
18
+ worker.onmessage = (e: any) => {
19
+ os.clearTimeout(timer)
20
+ resolve(e.data)
21
+ }
22
+ worker.postMessage({
23
+ type: 'start',
24
+ wasmBuf,
25
+ calls: [['add', [1, 2]], ['add', [10, 20]]]
26
+ })
27
+ })
28
+
29
+ const mainMod = new WebAssembly.Module(wasmBuf)
30
+ const mainInst = new WebAssembly.Instance<{ add: (a: number, b: number) => number }>(mainMod)
31
+ const mainExp = mainInst.exports
32
+ const mainR1 = mainExp.add(1, 2)
33
+ const mainR2 = mainExp.add(10, 20)
34
+
35
+ const wr = await workerResult
36
+ t.check('main add(1, 2)', 3, mainR1)
37
+ t.check('main add(10, 20)', 30, mainR2)
38
+ t.check('worker ok', true, wr.ok)
39
+ t.check('worker add(1, 2)', 3, wr.results[0])
40
+ t.check('worker add(10, 20)', 30, wr.results[1])
41
+
42
+ worker.postMessage({ type: 'done' })
43
+ worker.onmessage = null
44
+ }
45
+ }
Binary file
@@ -0,0 +1,13 @@
1
+ import '../lib/fetch.js';
2
+ import * as os from 'os';
3
+ const parent = os.Worker.parent;
4
+ parent.onmessage = (e) => {
5
+ if (e.data.type === 'start') {
6
+ fetch('http://localhost:18923/')
7
+ .then(r => parent.postMessage({ type: 'result', ok: r.ok, status: r.status }))
8
+ .catch(err => parent.postMessage({ type: 'error', msg: String(err) }));
9
+ }
10
+ else if (e.data.type === 'done') {
11
+ parent.onmessage = null;
12
+ }
13
+ };
@@ -0,0 +1,13 @@
1
+ import '../lib/fetch.js'
2
+ import * as os from 'os'
3
+ const parent = os.Worker.parent
4
+
5
+ parent.onmessage = (e: any) => {
6
+ if (e.data.type === 'start') {
7
+ fetch('http://localhost:18923/')
8
+ .then(r => parent.postMessage({ type: 'result', ok: r.ok, status: r.status }))
9
+ .catch(err => parent.postMessage({ type: 'error', msg: String(err) }))
10
+ } else if (e.data.type === 'done') {
11
+ parent.onmessage = null
12
+ }
13
+ }
@@ -0,0 +1 @@
1
+ export const value = 42;
@@ -0,0 +1 @@
1
+ export const value = 42
@@ -0,0 +1,18 @@
1
+ import * as os from 'os';
2
+ // Use variable to bypass compiler's static module resolution
3
+ const url = 'https://esm.sh/' + 'isarray';
4
+ const { default: isArray } = await import(url);
5
+ const parent = os.Worker.parent;
6
+ parent.onmessage = (e) => {
7
+ const d = e.data;
8
+ if (d.type === 'start') {
9
+ parent.postMessage({
10
+ type: 'result',
11
+ isArrayWorks: isArray([]) === true,
12
+ isArrayRejects: isArray({}) === false,
13
+ });
14
+ }
15
+ else if (d.type === 'done') {
16
+ parent.onmessage = null;
17
+ }
18
+ };
@@ -0,0 +1,20 @@
1
+ import * as os from 'os'
2
+
3
+ // Use variable to bypass compiler's static module resolution
4
+ const url = 'https://esm.sh/' + 'isarray'
5
+ const { default: isArray } = await import(url)
6
+
7
+ const parent = os.Worker.parent
8
+
9
+ parent.onmessage = (e) => {
10
+ const d = e.data as { type: string; [key: string]: unknown }
11
+ if (d.type === 'start') {
12
+ parent.postMessage({
13
+ type: 'result',
14
+ isArrayWorks: isArray([]) === true,
15
+ isArrayRejects: isArray({}) === false,
16
+ })
17
+ } else if (d.type === 'done') {
18
+ parent.onmessage = null
19
+ }
20
+ }
@@ -0,0 +1,12 @@
1
+ import * as os from 'os';
2
+ import { value } from './worker_helper.js';
3
+ const parent = os.Worker.parent;
4
+ parent.onmessage = (e) => {
5
+ const d = e.data;
6
+ if (d.type === 'start') {
7
+ parent.postMessage({ type: 'result', value });
8
+ }
9
+ else if (d.type === 'done') {
10
+ parent.onmessage = null;
11
+ }
12
+ };
@@ -0,0 +1,13 @@
1
+ import * as os from 'os'
2
+ import { value } from './worker_helper.js'
3
+
4
+ const parent = os.Worker.parent
5
+
6
+ parent.onmessage = (e) => {
7
+ const d = e.data as { type: string }
8
+ if (d.type === 'start') {
9
+ parent.postMessage({ type: 'result', value })
10
+ } else if (d.type === 'done') {
11
+ parent.onmessage = null
12
+ }
13
+ }
@@ -0,0 +1,16 @@
1
+ import * as os from 'os';
2
+ import { value } from './worker_helper.js';
3
+ const parent = os.Worker.parent;
4
+ // @ts-ignore
5
+ // console.log('Hello from worker', globalThis)
6
+ parent.onmessage = (e) => {
7
+ console.log(e);
8
+ const d = e.data;
9
+ if (d.type === 'start') {
10
+ console.log(d.type);
11
+ parent.postMessage({ type: 'result', value });
12
+ }
13
+ else if (d.type === 'done') {
14
+ parent.onmessage = null;
15
+ }
16
+ };
@@ -0,0 +1,17 @@
1
+ import * as os from 'os'
2
+ import { value } from './worker_helper.js'
3
+
4
+ const parent = os.Worker.parent
5
+ // @ts-ignore
6
+ // console.log('Hello from worker', globalThis)
7
+
8
+ parent.onmessage = (e) => {
9
+ console.log(e)
10
+ const d = e.data as { type: string }
11
+ if (d.type === 'start') {
12
+ console.log(d.type)
13
+ parent.postMessage({ type: 'result', value })
14
+ } else if (d.type === 'done') {
15
+ parent.onmessage = null
16
+ }
17
+ }
@@ -0,0 +1,22 @@
1
+ import * as os from 'os';
2
+ const parent = os.Worker.parent;
3
+ parent.onmessage = (e) => {
4
+ const d = e.data;
5
+ if (d.type === 'start') {
6
+ try {
7
+ const mod = new WebAssembly.Module(d.wasmBuf);
8
+ const inst = new WebAssembly.Instance(mod, d.imports || {});
9
+ const results = [];
10
+ for (const [name, args] of d.calls) {
11
+ results.push(inst.exports[name](...args));
12
+ }
13
+ parent.postMessage({ ok: true, results });
14
+ }
15
+ catch (err) {
16
+ parent.postMessage({ ok: false, error: String(err) });
17
+ }
18
+ }
19
+ else if (d.type === 'done') {
20
+ parent.onmessage = null;
21
+ }
22
+ };
@@ -0,0 +1,22 @@
1
+ import * as os from 'os'
2
+
3
+ const parent = os.Worker.parent
4
+
5
+ parent.onmessage = (e) => {
6
+ const d = e.data as { type: string; wasmBuf: ArrayBuffer; imports?: Record<string, unknown>; calls: [string, unknown[]][] }
7
+ if (d.type === 'start') {
8
+ try {
9
+ const mod = new WebAssembly.Module(d.wasmBuf)
10
+ const inst = new WebAssembly.Instance(mod, d.imports || {})
11
+ const results: number[] = []
12
+ for (const [name, args] of d.calls) {
13
+ results.push((inst.exports[name] as Function)(...args))
14
+ }
15
+ parent.postMessage({ ok: true, results })
16
+ } catch (err) {
17
+ parent.postMessage({ ok: false, error: String(err) })
18
+ }
19
+ } else if (d.type === 'done') {
20
+ parent.onmessage = null
21
+ }
22
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "compilerOptions": {
3
+ // "incremental": true,
4
+ "target": "es2022",
5
+ "module": "esnext",
6
+ "strict": true,
7
+ "noImplicitAny": true,
8
+ "noFallthroughCasesInSwitch": true,
9
+ "noImplicitReturns": true,
10
+ "noUncheckedIndexedAccess": true,
11
+ "noImplicitOverride": true,
12
+ "noUncheckedSideEffectImports": true,
13
+ "noUnusedLocals": true,
14
+ "noUnusedParameters": true,
15
+ "esModuleInterop": true,
16
+ // "skipLibCheck": true,
17
+ "allowJs": false,
18
+ "lib": ["ES2020"],
19
+ "types": ["./quickwin.d.ts"],
20
+ "rootDir": ".",
21
+ "outDir": "_build",
22
+ "jsx": "react-jsx",
23
+ "jsxImportSource": "react",
24
+ },
25
+ "include": ["test/**/*.ts", "test/**/*.tsx", "examples/**/*.ts", "examples/**/*.tsx", "main.ts", "quickwin.d.ts", "lib/**/*.ts", "lib/**/*.tsx "],
26
+ "exclude": []
27
+ }