quickwin 1.0.2 → 1.1.1

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 (78) hide show
  1. package/README.en.md +204 -204
  2. package/README.md +203 -203
  3. package/examples/PdfCanvas.tsx +83 -83
  4. package/examples/exec_server.ts +35 -35
  5. package/examples/pdf_preview2.ts +375 -375
  6. package/examples/pdf_viewer.tsx +279 -279
  7. package/examples/test_gallery.tsx +285 -285
  8. package/examples/test_react_lazy.tsx +63 -63
  9. package/examples/test_react_listbox.tsx +71 -71
  10. package/examples/test_root_window.tsx +41 -41
  11. package/examples/test_tab.tsx +75 -75
  12. package/examples/tray_demo.tsx +81 -81
  13. package/lib/assert.ts +6 -6
  14. package/lib/cache-utils.ts +40 -40
  15. package/lib/dumpRects.ts +25 -25
  16. package/lib/fetch.ts +502 -502
  17. package/lib/http-common.ts +399 -399
  18. package/lib/http-server.ts +424 -424
  19. package/lib/polyfill.ts +171 -171
  20. package/lib/react-qw/components/index.ts +17 -17
  21. package/lib/react-qw/index.ts +90 -90
  22. package/lib/react-qw/jsx.d.ts +34 -34
  23. package/lib/react-qw/layout.ts +111 -111
  24. package/lib/react-qw/props.ts +36 -36
  25. package/lib/react-qw/reconciler.ts +373 -373
  26. package/lib/stream.ts +21 -21
  27. package/lib/text-codec.ts +171 -171
  28. package/lib/text-measure.ts +54 -54
  29. package/lib/url.ts +201 -201
  30. package/lib/vendor/web-streams/ponyfill.d.mts +829 -829
  31. package/lib/vendor/web-streams/ponyfill.mjs +8 -8
  32. package/lib/websocket.js +8 -0
  33. package/lib/websocket.ts +563 -555
  34. package/package.json +50 -44
  35. package/qwin-nowasm-x86.exe +0 -0
  36. package/qwin-nowasm.exe +0 -0
  37. package/qwin-x86.exe +0 -0
  38. package/qwin.exe +0 -0
  39. package/test/run.ts +96 -96
  40. package/test/test_basic.ts +9 -9
  41. package/test/test_basic_fetch.ts +33 -33
  42. package/test/test_brotli.ts +52 -52
  43. package/test/test_fetch_cache.ts +187 -187
  44. package/test/test_ffi.ts +174 -174
  45. package/test/test_frame_encoding.ts +132 -132
  46. package/test/test_helper.ts +80 -80
  47. package/test/test_http_import.ts +74 -74
  48. package/test/test_http_server.ts +136 -136
  49. package/test/test_import_dir.ts +5 -5
  50. package/test/test_ipv6.ts +129 -129
  51. package/test/test_meta_url.ts +4 -4
  52. package/test/test_mupdf_render.ts +74 -74
  53. package/test/test_mupdf_twice.ts +81 -81
  54. package/test/test_mupdf_wasm.ts +30 -30
  55. package/test/test_net_event.ts +55 -55
  56. package/test/test_net_fetch.ts +238 -238
  57. package/test/test_net_websocket.ts +164 -164
  58. package/test/test_polyfill.ts +159 -159
  59. package/test/test_url.ts +183 -183
  60. package/test/test_wasm_basic.ts +73 -73
  61. package/test/test_wasm_import_global.ts +45 -45
  62. package/test/test_wasm_sjlj.ts +125 -125
  63. package/test/test_wasm_types.ts +124 -124
  64. package/test/test_worker.ts +24 -24
  65. package/test/test_worker_fetch.ts +27 -27
  66. package/test/test_worker_net.ts +54 -54
  67. package/test/test_worker_wasm_concurrent.ts +45 -45
  68. package/test/worker_fetch.ts +13 -13
  69. package/test/worker_helper.ts +1 -1
  70. package/test/worker_http.ts +20 -20
  71. package/test/worker_import_lib.ts +13 -13
  72. package/test/worker_module.ts +17 -17
  73. package/test/worker_wasm_concurrent.ts +22 -22
  74. package/tsconfig.json +27 -27
  75. package/vendor/mupdf-wasm/mupdf-wasm.d.ts +571 -571
  76. package/vendor/mupdf-wasm/mupdf-wasm.js +2749 -2749
  77. package/vendor/mupdf-wasm/mupdf.d.ts +939 -939
  78. package/vendor/mupdf-wasm/mupdf.js +3317 -3317
@@ -1,187 +1,187 @@
1
- import '../lib/fetch.js'
2
- import * as std from 'std'
3
- import * as os from 'os'
4
- import { Tester } from './test_helper.js'
5
- import { parseIni, toIni } from '../lib/cache-utils.js'
6
-
7
- function getCacheDir(): string {
8
- const url = import.meta.url
9
- let path = url.slice(7)
10
- if (path.length >= 3 && path[1] === ':') path = path.slice(1)
11
- const idx = path.lastIndexOf('/')
12
- if (idx < 0) return '_cache'
13
- const buildDir = path.slice(0, idx)
14
- const idx2 = buildDir.lastIndexOf('/')
15
- if (idx2 < 0) return '_cache'
16
- return buildDir.slice(0, idx2 + 1) + '_cache'
17
- }
18
-
19
- export const suite = {
20
- name: 'fetch-cache',
21
- run: async (t: Tester) => {
22
- function assert(name: string, ok: boolean): void {
23
- if (ok) { t.ok++; std.printf(' PASS: %s\n', name) }
24
- else { t.fail++; std.printf(' FAIL: %s\n', name) }
25
- }
26
-
27
- const cacheDir = getCacheDir()
28
- const trackedUrls: string[] = []
29
-
30
- t.section('__httpCache__ API exists')
31
- assert('__httpCache__ is defined', typeof __httpCache__ !== 'undefined')
32
- if (!__httpCache__) return
33
-
34
- assert('readMeta is function', typeof __httpCache__.readMeta === 'function')
35
- assert('readBody is function', typeof __httpCache__.readBody === 'function')
36
- assert('writeBodyOnly is function', typeof __httpCache__.writeBodyOnly === 'function')
37
- assert('writeMeta is function', typeof __httpCache__.writeMeta === 'function')
38
- assert('cacheKey is function', typeof __httpCache__.cacheKey === 'function')
39
-
40
- t.section('writeBodyOnly + writeMeta + readMeta + readBody')
41
- const fakeUrl = 'https://test.local/cache-test'
42
- trackedUrls.push(fakeUrl)
43
- const testBody = 'hello cache test!'
44
- __httpCache__.writeBodyOnly(fakeUrl, testBody)
45
- __httpCache__.writeMeta(fakeUrl, toIni(
46
- {},
47
- {
48
- url: fakeUrl,
49
- storedAt: String(Math.floor(Date.now() / 1000)),
50
- maxAge: '60',
51
- status: '200',
52
- statusText: 'OK',
53
- }
54
- ))
55
-
56
- const metaStr = __httpCache__.readMeta(fakeUrl)
57
- assert('meta written', metaStr !== null)
58
- if (metaStr) {
59
- const ini = parseIni(metaStr)
60
- assert('meta has storedAt', typeof ini.meta.storedAt === 'string' && ini.meta.storedAt.length > 0)
61
- assert('meta has maxAge', ini.meta.maxAge === '60')
62
- }
63
-
64
- const fullMeta = toIni(
65
- { 'content-type': 'text/plain' },
66
- {
67
- url: fakeUrl,
68
- storedAt: String(Math.floor(Date.now() / 1000)),
69
- maxAge: '60',
70
- status: '200',
71
- statusText: 'OK',
72
- }
73
- )
74
- __httpCache__.writeMeta(fakeUrl, fullMeta)
75
-
76
- const metaStr2 = __httpCache__.readMeta(fakeUrl)
77
- assert('meta overwritten', metaStr2 !== null)
78
- if (metaStr2) {
79
- const ini2 = parseIni(metaStr2)
80
- assert('meta has status', ini2.meta.status === '200')
81
- assert('meta has headers', ini2.headers['content-type'] === 'text/plain')
82
- }
83
-
84
- const bodyAb = __httpCache__.readBody(fakeUrl)
85
- assert('body read as ArrayBuffer', bodyAb !== null)
86
- if (bodyAb) {
87
- const view = new Uint8Array(bodyAb)
88
- let str = ''
89
- for (let i = 0; i < view.length; i++) str += String.fromCharCode(view[i]!)
90
- assert('body content correct', str === testBody)
91
- }
92
-
93
- t.section('cacheKey')
94
- const key = __httpCache__.cacheKey('https://example.com/test.js')
95
- assert('cacheKey returns 16 hex chars', /^[0-9a-f]{16}$/.test(key))
96
-
97
- t.section('lastAccess via readMeta/writeMeta')
98
- const laUrl = 'https://test.local/lastaccess-test'
99
- trackedUrls.push(laUrl)
100
- __httpCache__.writeBodyOnly(laUrl, 'test')
101
- __httpCache__.writeMeta(laUrl, toIni({}, {
102
- url: laUrl,
103
- storedAt: String(Math.floor(Date.now() / 1000)),
104
- maxAge: '300',
105
- status: '200',
106
- statusText: 'OK',
107
- }))
108
- const beforeMeta = __httpCache__.readMeta(laUrl)
109
- if (beforeMeta) {
110
- const ini0 = parseIni(beforeMeta)
111
- assert('no lastAccess before update', ini0.meta.lastAccess === undefined)
112
- }
113
- const now = Math.floor(Date.now() / 1000)
114
- const laMeta = parseIni(__httpCache__.readMeta(laUrl) || '')
115
- laMeta.meta.lastAccess = String(now)
116
- __httpCache__.writeMeta(laUrl, toIni(laMeta.headers, laMeta.meta))
117
- const afterMeta = __httpCache__.readMeta(laUrl)
118
- if (afterMeta) {
119
- const ini1 = parseIni(afterMeta)
120
- assert('lastAccess present after update', typeof ini1.meta.lastAccess === 'string' && ini1.meta.lastAccess.length > 0)
121
- assert('lastAccess is numeric', /^\d+$/.test(ini1.meta.lastAccess!))
122
- assert('meta preserved after lastAccess', ini1.meta.maxAge === '300')
123
- assert('no headers leaked', Object.keys(ini1.headers).length === 0)
124
- }
125
-
126
- t.section('fetch with caching')
127
- const cacheTestUrl = 'http://localhost:18923/cache/60'
128
- trackedUrls.push(cacheTestUrl)
129
-
130
- const resp1 = await fetch(cacheTestUrl)
131
- assert('first fetch ok', resp1.ok)
132
- const body1 = await resp1.text()
133
- assert('first fetch body non-empty', body1.length > 0)
134
-
135
- const cachedMeta = __httpCache__.readMeta(cacheTestUrl)
136
- assert('cached meta exists', cachedMeta !== null)
137
- if (cachedMeta) {
138
- const ini = parseIni(cachedMeta)
139
- assert('cached status = 200', ini.meta.status === '200')
140
- assert('cached maxAge = 60', ini.meta.maxAge === '60')
141
- }
142
-
143
- const cachedBody = __httpCache__.readBody(cacheTestUrl)
144
- assert('cached body exists', cachedBody !== null)
145
- if (cachedBody) {
146
- assert('cached body matches', cachedBody.byteLength > 0)
147
- }
148
-
149
- t.section('second fetch hits cache')
150
- const resp2 = await fetch(cacheTestUrl)
151
- assert('second fetch ok', resp2.ok)
152
- const body2 = await resp2.text()
153
- assert('second fetch body same length', body2.length === body1.length)
154
-
155
- const afterFetchMeta = __httpCache__.readMeta(cacheTestUrl)
156
- if (afterFetchMeta) {
157
- const iniLA = parseIni(afterFetchMeta)
158
- assert('lastAccess set after fetch cache hit', typeof iniLA.meta.lastAccess === 'string' && iniLA.meta.lastAccess.length > 0)
159
- }
160
-
161
- t.section('timing: network vs cache')
162
- const timingUrl = 'http://localhost:18923/cache/60?t=' + String(Date.now())
163
- trackedUrls.push(timingUrl)
164
-
165
- const rNet = await fetch(timingUrl)
166
- assert('network fetch ok', rNet.ok)
167
- const bodyNet = await rNet.text()
168
- assert('network body non-empty', bodyNet.length > 0)
169
-
170
- const t2 = Date.now()
171
- const rCache = await fetch(timingUrl)
172
- const t3 = Date.now()
173
- const timeCache = t3 - t2
174
- assert('cache fetch ok', rCache.ok)
175
- const bodyCache = await rCache.text()
176
- assert('cache body same length', bodyCache.length === bodyNet.length)
177
- assert('cache non-negative time (' + timeCache + 'ms)', timeCache >= 0)
178
-
179
- t.section('cleanup')
180
- for (const url of trackedUrls) {
181
- const key = __httpCache__.cacheKey(url)
182
- os.remove(cacheDir + '/' + key + '.meta')
183
- os.remove(cacheDir + '/' + key + '.body')
184
- assert('no meta leftover for ' + key, __httpCache__.readMeta(url) === null)
185
- }
186
- }
187
- }
1
+ import '../lib/fetch.js'
2
+ import * as std from 'std'
3
+ import * as os from 'os'
4
+ import { Tester } from './test_helper.js'
5
+ import { parseIni, toIni } from '../lib/cache-utils.js'
6
+
7
+ function getCacheDir(): string {
8
+ const url = import.meta.url
9
+ let path = url.slice(7)
10
+ if (path.length >= 3 && path[1] === ':') path = path.slice(1)
11
+ const idx = path.lastIndexOf('/')
12
+ if (idx < 0) return '_cache'
13
+ const buildDir = path.slice(0, idx)
14
+ const idx2 = buildDir.lastIndexOf('/')
15
+ if (idx2 < 0) return '_cache'
16
+ return buildDir.slice(0, idx2 + 1) + '_cache'
17
+ }
18
+
19
+ export const suite = {
20
+ name: 'fetch-cache',
21
+ run: async (t: Tester) => {
22
+ function assert(name: string, ok: boolean): void {
23
+ if (ok) { t.ok++; std.printf(' PASS: %s\n', name) }
24
+ else { t.fail++; std.printf(' FAIL: %s\n', name) }
25
+ }
26
+
27
+ const cacheDir = getCacheDir()
28
+ const trackedUrls: string[] = []
29
+
30
+ t.section('__httpCache__ API exists')
31
+ assert('__httpCache__ is defined', typeof __httpCache__ !== 'undefined')
32
+ if (!__httpCache__) return
33
+
34
+ assert('readMeta is function', typeof __httpCache__.readMeta === 'function')
35
+ assert('readBody is function', typeof __httpCache__.readBody === 'function')
36
+ assert('writeBodyOnly is function', typeof __httpCache__.writeBodyOnly === 'function')
37
+ assert('writeMeta is function', typeof __httpCache__.writeMeta === 'function')
38
+ assert('cacheKey is function', typeof __httpCache__.cacheKey === 'function')
39
+
40
+ t.section('writeBodyOnly + writeMeta + readMeta + readBody')
41
+ const fakeUrl = 'https://test.local/cache-test'
42
+ trackedUrls.push(fakeUrl)
43
+ const testBody = 'hello cache test!'
44
+ __httpCache__.writeBodyOnly(fakeUrl, testBody)
45
+ __httpCache__.writeMeta(fakeUrl, toIni(
46
+ {},
47
+ {
48
+ url: fakeUrl,
49
+ storedAt: String(Math.floor(Date.now() / 1000)),
50
+ maxAge: '60',
51
+ status: '200',
52
+ statusText: 'OK',
53
+ }
54
+ ))
55
+
56
+ const metaStr = __httpCache__.readMeta(fakeUrl)
57
+ assert('meta written', metaStr !== null)
58
+ if (metaStr) {
59
+ const ini = parseIni(metaStr)
60
+ assert('meta has storedAt', typeof ini.meta.storedAt === 'string' && ini.meta.storedAt.length > 0)
61
+ assert('meta has maxAge', ini.meta.maxAge === '60')
62
+ }
63
+
64
+ const fullMeta = toIni(
65
+ { 'content-type': 'text/plain' },
66
+ {
67
+ url: fakeUrl,
68
+ storedAt: String(Math.floor(Date.now() / 1000)),
69
+ maxAge: '60',
70
+ status: '200',
71
+ statusText: 'OK',
72
+ }
73
+ )
74
+ __httpCache__.writeMeta(fakeUrl, fullMeta)
75
+
76
+ const metaStr2 = __httpCache__.readMeta(fakeUrl)
77
+ assert('meta overwritten', metaStr2 !== null)
78
+ if (metaStr2) {
79
+ const ini2 = parseIni(metaStr2)
80
+ assert('meta has status', ini2.meta.status === '200')
81
+ assert('meta has headers', ini2.headers['content-type'] === 'text/plain')
82
+ }
83
+
84
+ const bodyAb = __httpCache__.readBody(fakeUrl)
85
+ assert('body read as ArrayBuffer', bodyAb !== null)
86
+ if (bodyAb) {
87
+ const view = new Uint8Array(bodyAb)
88
+ let str = ''
89
+ for (let i = 0; i < view.length; i++) str += String.fromCharCode(view[i]!)
90
+ assert('body content correct', str === testBody)
91
+ }
92
+
93
+ t.section('cacheKey')
94
+ const key = __httpCache__.cacheKey('https://example.com/test.js')
95
+ assert('cacheKey returns 16 hex chars', /^[0-9a-f]{16}$/.test(key))
96
+
97
+ t.section('lastAccess via readMeta/writeMeta')
98
+ const laUrl = 'https://test.local/lastaccess-test'
99
+ trackedUrls.push(laUrl)
100
+ __httpCache__.writeBodyOnly(laUrl, 'test')
101
+ __httpCache__.writeMeta(laUrl, toIni({}, {
102
+ url: laUrl,
103
+ storedAt: String(Math.floor(Date.now() / 1000)),
104
+ maxAge: '300',
105
+ status: '200',
106
+ statusText: 'OK',
107
+ }))
108
+ const beforeMeta = __httpCache__.readMeta(laUrl)
109
+ if (beforeMeta) {
110
+ const ini0 = parseIni(beforeMeta)
111
+ assert('no lastAccess before update', ini0.meta.lastAccess === undefined)
112
+ }
113
+ const now = Math.floor(Date.now() / 1000)
114
+ const laMeta = parseIni(__httpCache__.readMeta(laUrl) || '')
115
+ laMeta.meta.lastAccess = String(now)
116
+ __httpCache__.writeMeta(laUrl, toIni(laMeta.headers, laMeta.meta))
117
+ const afterMeta = __httpCache__.readMeta(laUrl)
118
+ if (afterMeta) {
119
+ const ini1 = parseIni(afterMeta)
120
+ assert('lastAccess present after update', typeof ini1.meta.lastAccess === 'string' && ini1.meta.lastAccess.length > 0)
121
+ assert('lastAccess is numeric', /^\d+$/.test(ini1.meta.lastAccess!))
122
+ assert('meta preserved after lastAccess', ini1.meta.maxAge === '300')
123
+ assert('no headers leaked', Object.keys(ini1.headers).length === 0)
124
+ }
125
+
126
+ t.section('fetch with caching')
127
+ const cacheTestUrl = 'http://localhost:18923/cache/60'
128
+ trackedUrls.push(cacheTestUrl)
129
+
130
+ const resp1 = await fetch(cacheTestUrl)
131
+ assert('first fetch ok', resp1.ok)
132
+ const body1 = await resp1.text()
133
+ assert('first fetch body non-empty', body1.length > 0)
134
+
135
+ const cachedMeta = __httpCache__.readMeta(cacheTestUrl)
136
+ assert('cached meta exists', cachedMeta !== null)
137
+ if (cachedMeta) {
138
+ const ini = parseIni(cachedMeta)
139
+ assert('cached status = 200', ini.meta.status === '200')
140
+ assert('cached maxAge = 60', ini.meta.maxAge === '60')
141
+ }
142
+
143
+ const cachedBody = __httpCache__.readBody(cacheTestUrl)
144
+ assert('cached body exists', cachedBody !== null)
145
+ if (cachedBody) {
146
+ assert('cached body matches', cachedBody.byteLength > 0)
147
+ }
148
+
149
+ t.section('second fetch hits cache')
150
+ const resp2 = await fetch(cacheTestUrl)
151
+ assert('second fetch ok', resp2.ok)
152
+ const body2 = await resp2.text()
153
+ assert('second fetch body same length', body2.length === body1.length)
154
+
155
+ const afterFetchMeta = __httpCache__.readMeta(cacheTestUrl)
156
+ if (afterFetchMeta) {
157
+ const iniLA = parseIni(afterFetchMeta)
158
+ assert('lastAccess set after fetch cache hit', typeof iniLA.meta.lastAccess === 'string' && iniLA.meta.lastAccess.length > 0)
159
+ }
160
+
161
+ t.section('timing: network vs cache')
162
+ const timingUrl = 'http://localhost:18923/cache/60?t=' + String(Date.now())
163
+ trackedUrls.push(timingUrl)
164
+
165
+ const rNet = await fetch(timingUrl)
166
+ assert('network fetch ok', rNet.ok)
167
+ const bodyNet = await rNet.text()
168
+ assert('network body non-empty', bodyNet.length > 0)
169
+
170
+ const t2 = Date.now()
171
+ const rCache = await fetch(timingUrl)
172
+ const t3 = Date.now()
173
+ const timeCache = t3 - t2
174
+ assert('cache fetch ok', rCache.ok)
175
+ const bodyCache = await rCache.text()
176
+ assert('cache body same length', bodyCache.length === bodyNet.length)
177
+ assert('cache non-negative time (' + timeCache + 'ms)', timeCache >= 0)
178
+
179
+ t.section('cleanup')
180
+ for (const url of trackedUrls) {
181
+ const key = __httpCache__.cacheKey(url)
182
+ os.remove(cacheDir + '/' + key + '.meta')
183
+ os.remove(cacheDir + '/' + key + '.body')
184
+ assert('no meta leftover for ' + key, __httpCache__.readMeta(url) === null)
185
+ }
186
+ }
187
+ }