quickwin 1.0.2 → 1.1.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 (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
package/lib/url.ts CHANGED
@@ -1,201 +1,201 @@
1
- export {} // make this a module so declare global works
2
-
3
- declare global {
4
- interface URLSearchParams extends URLSearchParamsImpl {}
5
- var URLSearchParams: typeof URLSearchParamsImpl
6
- interface URL extends URLImpl {}
7
- var URL: typeof URLImpl
8
- }
9
-
10
- function _encode(s: string): string { return encodeURIComponent(s) }
11
- function _decode(s: string): string {
12
- try { return decodeURIComponent(s.replace(/\+/g, ' ')) }
13
- catch { return s }
14
- }
15
-
16
- function _normalizePath(path: string): string {
17
- if (!path) return '/'
18
- const parts = path.split('/')
19
- const out: string[] = []
20
- let hasRoot = path[0] === '/'
21
- if (hasRoot) out.push('')
22
- for (const p of parts) {
23
- if (p === '' || p === '.') continue
24
- if (p === '..') {
25
- const last = out[out.length - 1]
26
- if (last !== undefined && last !== '') out.pop()
27
- } else {
28
- out.push(p)
29
- }
30
- }
31
- if (path.endsWith('/') && out[out.length - 1] !== '') out.push('')
32
- const result = out.join('/')
33
- if (hasRoot && !result.startsWith('/')) return '/' + result
34
- return result || '/'
35
- }
36
-
37
- function _parseURL(url: string): { scheme: string; user: string; pass: string; host: string; port: string; path: string; query: string; fragment: string } {
38
- const r = { scheme: '', user: '', pass: '', host: '', port: '', path: '/', query: '', fragment: '' }
39
- const fi = url.indexOf('#')
40
- if (fi >= 0) { r.fragment = url.slice(fi + 1); url = url.slice(0, fi) }
41
- const qi = url.indexOf('?')
42
- if (qi >= 0) { r.query = url.slice(qi + 1); url = url.slice(0, qi) }
43
- const sm = url.match(/^([a-zA-Z][a-zA-Z0-9+\-.]*):(.*)$/)
44
- if (sm) { r.scheme = sm[1]!.toLowerCase(); url = sm[2]! }
45
- if (url.startsWith('//')) {
46
- url = url.slice(2)
47
- const si = url.indexOf('/')
48
- let auth: string
49
- if (si < 0) { auth = url; url = '' } else { auth = url.slice(0, si); url = url.slice(si) }
50
- const ai = auth.lastIndexOf('@')
51
- if (ai >= 0) {
52
- const ui = auth.slice(0, ai); auth = auth.slice(ai + 1)
53
- const ci = ui.indexOf(':')
54
- if (ci >= 0) { r.user = _decode(ui.slice(0, ci)); r.pass = _decode(ui.slice(ci + 1)) }
55
- else r.user = _decode(ui)
56
- }
57
- if (auth.startsWith('[')) {
58
- const cb = auth.indexOf(']')
59
- r.host = auth.slice(1, cb).toLowerCase()
60
- const pp = auth.slice(cb + 1)
61
- if (pp.startsWith(':')) r.port = pp.slice(1)
62
- } else {
63
- const ci = auth.lastIndexOf(':')
64
- if (ci >= 0 && ci === auth.lastIndexOf(':')) { r.host = auth.slice(0, ci).toLowerCase(); r.port = auth.slice(ci + 1) }
65
- else r.host = auth.toLowerCase()
66
- }
67
- }
68
- r.path = url
69
- if (r.host && !r.path.startsWith('/')) r.path = '/' + r.path
70
- return r
71
- }
72
-
73
- class URLSearchParamsImpl {
74
- private _list: [string, string][] = []
75
-
76
- constructor(init?: string | [string, string][] | Record<string, string>) {
77
- if (typeof init === 'string') {
78
- const s = init.startsWith('?') ? init.slice(1) : init
79
- if (!s) return
80
- for (const p of s.split('&')) {
81
- const eq = p.indexOf('=')
82
- if (eq < 0) { this._list.push([_decode(p), '']); continue }
83
- this._list.push([_decode(p.slice(0, eq)), _decode(p.slice(eq + 1))])
84
- }
85
- } else if (init) {
86
- if (Array.isArray(init)) for (const [k, v] of init) this._list.push([String(k), String(v)])
87
- else for (const k of Object.keys(init)) this._list.push([k, String(init[k])])
88
- }
89
- }
90
-
91
- append(key: string, value: string): void { this._list.push([key, value]) }
92
- delete(key: string): void { this._list = this._list.filter(([k]) => k !== key) }
93
- get(key: string): string | null { for (const [k, v] of this._list) if (k === key) return v; return null }
94
- getAll(key: string): string[] { return this._list.filter(([k]) => k === key).map(([, v]) => v) }
95
- has(key: string): boolean { return this._list.some(([k]) => k === key) }
96
- set(key: string, value: string): void {
97
- let f = false
98
- for (let i = 0; i < this._list.length; i++) {
99
- if (this._list[i]![0] === key) { if (!f) { this._list[i]![1] = value; f = true } else { this._list.splice(i, 1); i-- } }
100
- }
101
- if (!f) this._list.push([key, value])
102
- }
103
- sort(): void { this._list.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0) }
104
- forEach(fn: (v: string, k: string) => void): void { for (const [k, v] of this._list) fn(v, k) }
105
-
106
- *keys(): IterableIterator<string> { for (const [k] of this._list) yield k }
107
- *values(): IterableIterator<string> { for (const [, v] of this._list) yield v }
108
- *entries(): IterableIterator<[string, string]> { for (const item of this._list) yield [item[0], item[1]] }
109
- *[Symbol.iterator](): IterableIterator<[string, string]> { for (const item of this._list) yield item }
110
-
111
- toString(): string { return this._list.map(([k, v]) => _encode(k) + '=' + _encode(v)).join('&') }
112
- get size(): number { return this._list.length }
113
- }
114
-
115
- if (typeof globalThis.URLSearchParams === 'undefined') {
116
- globalThis.URLSearchParams = URLSearchParamsImpl
117
- }
118
-
119
- class URLImpl {
120
- private _scheme = ''
121
- private _username = ''
122
- private _password = ''
123
- private _hostname = ''
124
- private _port = ''
125
- private _pathname = '/'
126
- private _query = ''
127
- private _fragment = ''
128
- private _searchParams: URLSearchParams = new URLSearchParamsImpl()
129
-
130
- constructor(url: string, base?: string) {
131
- let p = _parseURL(url)
132
- if (p.scheme) { this._apply(p); return }
133
- if (base === undefined) throw new TypeError('Invalid URL')
134
-
135
- const b = new URLImpl(base)
136
- if (p.host) { p.scheme = b._scheme; this._apply(p); return }
137
- if (!p.path && !p.query) {
138
- this._apply({
139
- scheme: b._scheme, user: b._username, pass: b._password,
140
- host: b._hostname, port: b._port,
141
- path: b._pathname, query: b._query, fragment: p.fragment || ''
142
- }); return
143
- }
144
- p.scheme = b._scheme; if (!p.user) p.user = b._username; if (!p.pass) p.pass = b._password
145
- if (!p.host) p.host = b._hostname; if (!p.port) p.port = b._port; if (!p.fragment) p.fragment = ''
146
- if (p.path && !p.path.startsWith('/')) {
147
- const bd = b._pathname.substring(0, b._pathname.lastIndexOf('/') + 1)
148
- p.path = _normalizePath(bd + p.path)
149
- } else if (!p.path) { p.path = b._pathname; if (!p.query) p.query = b._query }
150
- this._apply(p)
151
- }
152
-
153
- private _apply(p: { scheme: string; user: string; pass: string; host: string; port: string; path: string; query: string; fragment: string }): void {
154
- this._scheme = p.scheme; this._username = p.user; this._password = p.pass
155
- this._hostname = p.host; this._port = p.port
156
- this._pathname = _normalizePath(p.path || '/')
157
- this._query = p.query; this._fragment = p.fragment
158
- this._searchParams = new URLSearchParamsImpl(this._query)
159
- }
160
-
161
- get href(): string { return this.toString() }
162
- get protocol(): string { return this._scheme + ':' }
163
- get hostname(): string { return this._hostname }
164
- get port(): string { return this._port }
165
- get pathname(): string { return this._pathname }
166
- get search(): string { return this._query ? '?' + this._query : '' }
167
- get hash(): string { return this._fragment ? '#' + this._fragment : '' }
168
- get host(): string {
169
- const h = this._hostname
170
- const ipv6 = h.includes(':')
171
- return (ipv6 ? '[' + h + ']' : h) + (this._port ? ':' + this._port : '')
172
- }
173
- get origin(): string {
174
- const h = this._hostname
175
- const ipv6 = h.includes(':')
176
- return this._scheme + '://' + (ipv6 ? '[' + h + ']' : h) + (this._port ? ':' + this._port : '')
177
- }
178
- get username(): string { return this._username }
179
- get password(): string { return this._password }
180
- get searchParams(): URLSearchParams { return this._searchParams }
181
-
182
- toString(): string {
183
- let s = this._scheme + ':'
184
- const special = ['http', 'https', 'ws', 'wss', 'ftp', 'file']
185
- if (this._hostname || (special.includes(this._scheme) && this._pathname.startsWith('/'))) {
186
- s += '//'
187
- if (this._username) { s += _encode(this._username); if (this._password) s += ':' + _encode(this._password); s += '@' }
188
- s += this._hostname.includes(':') ? '[' + this._hostname + ']' : this._hostname
189
- if (this._port) s += ':' + this._port
190
- }
191
- s += this._pathname
192
- if (this._query) s += '?' + this._query
193
- if (this._fragment) s += '#' + this._fragment
194
- return s
195
- }
196
-
197
- toJSON(): string { return this.toString() }
198
- }
199
- if (typeof globalThis.URL === 'undefined') {
200
- globalThis.URL = URLImpl
201
- }
1
+ export {} // make this a module so declare global works
2
+
3
+ declare global {
4
+ interface URLSearchParams extends URLSearchParamsImpl {}
5
+ var URLSearchParams: typeof URLSearchParamsImpl
6
+ interface URL extends URLImpl {}
7
+ var URL: typeof URLImpl
8
+ }
9
+
10
+ function _encode(s: string): string { return encodeURIComponent(s) }
11
+ function _decode(s: string): string {
12
+ try { return decodeURIComponent(s.replace(/\+/g, ' ')) }
13
+ catch { return s }
14
+ }
15
+
16
+ function _normalizePath(path: string): string {
17
+ if (!path) return '/'
18
+ const parts = path.split('/')
19
+ const out: string[] = []
20
+ let hasRoot = path[0] === '/'
21
+ if (hasRoot) out.push('')
22
+ for (const p of parts) {
23
+ if (p === '' || p === '.') continue
24
+ if (p === '..') {
25
+ const last = out[out.length - 1]
26
+ if (last !== undefined && last !== '') out.pop()
27
+ } else {
28
+ out.push(p)
29
+ }
30
+ }
31
+ if (path.endsWith('/') && out[out.length - 1] !== '') out.push('')
32
+ const result = out.join('/')
33
+ if (hasRoot && !result.startsWith('/')) return '/' + result
34
+ return result || '/'
35
+ }
36
+
37
+ function _parseURL(url: string): { scheme: string; user: string; pass: string; host: string; port: string; path: string; query: string; fragment: string } {
38
+ const r = { scheme: '', user: '', pass: '', host: '', port: '', path: '/', query: '', fragment: '' }
39
+ const fi = url.indexOf('#')
40
+ if (fi >= 0) { r.fragment = url.slice(fi + 1); url = url.slice(0, fi) }
41
+ const qi = url.indexOf('?')
42
+ if (qi >= 0) { r.query = url.slice(qi + 1); url = url.slice(0, qi) }
43
+ const sm = url.match(/^([a-zA-Z][a-zA-Z0-9+\-.]*):(.*)$/)
44
+ if (sm) { r.scheme = sm[1]!.toLowerCase(); url = sm[2]! }
45
+ if (url.startsWith('//')) {
46
+ url = url.slice(2)
47
+ const si = url.indexOf('/')
48
+ let auth: string
49
+ if (si < 0) { auth = url; url = '' } else { auth = url.slice(0, si); url = url.slice(si) }
50
+ const ai = auth.lastIndexOf('@')
51
+ if (ai >= 0) {
52
+ const ui = auth.slice(0, ai); auth = auth.slice(ai + 1)
53
+ const ci = ui.indexOf(':')
54
+ if (ci >= 0) { r.user = _decode(ui.slice(0, ci)); r.pass = _decode(ui.slice(ci + 1)) }
55
+ else r.user = _decode(ui)
56
+ }
57
+ if (auth.startsWith('[')) {
58
+ const cb = auth.indexOf(']')
59
+ r.host = auth.slice(1, cb).toLowerCase()
60
+ const pp = auth.slice(cb + 1)
61
+ if (pp.startsWith(':')) r.port = pp.slice(1)
62
+ } else {
63
+ const ci = auth.lastIndexOf(':')
64
+ if (ci >= 0 && ci === auth.lastIndexOf(':')) { r.host = auth.slice(0, ci).toLowerCase(); r.port = auth.slice(ci + 1) }
65
+ else r.host = auth.toLowerCase()
66
+ }
67
+ }
68
+ r.path = url
69
+ if (r.host && !r.path.startsWith('/')) r.path = '/' + r.path
70
+ return r
71
+ }
72
+
73
+ class URLSearchParamsImpl {
74
+ private _list: [string, string][] = []
75
+
76
+ constructor(init?: string | [string, string][] | Record<string, string>) {
77
+ if (typeof init === 'string') {
78
+ const s = init.startsWith('?') ? init.slice(1) : init
79
+ if (!s) return
80
+ for (const p of s.split('&')) {
81
+ const eq = p.indexOf('=')
82
+ if (eq < 0) { this._list.push([_decode(p), '']); continue }
83
+ this._list.push([_decode(p.slice(0, eq)), _decode(p.slice(eq + 1))])
84
+ }
85
+ } else if (init) {
86
+ if (Array.isArray(init)) for (const [k, v] of init) this._list.push([String(k), String(v)])
87
+ else for (const k of Object.keys(init)) this._list.push([k, String(init[k])])
88
+ }
89
+ }
90
+
91
+ append(key: string, value: string): void { this._list.push([key, value]) }
92
+ delete(key: string): void { this._list = this._list.filter(([k]) => k !== key) }
93
+ get(key: string): string | null { for (const [k, v] of this._list) if (k === key) return v; return null }
94
+ getAll(key: string): string[] { return this._list.filter(([k]) => k === key).map(([, v]) => v) }
95
+ has(key: string): boolean { return this._list.some(([k]) => k === key) }
96
+ set(key: string, value: string): void {
97
+ let f = false
98
+ for (let i = 0; i < this._list.length; i++) {
99
+ if (this._list[i]![0] === key) { if (!f) { this._list[i]![1] = value; f = true } else { this._list.splice(i, 1); i-- } }
100
+ }
101
+ if (!f) this._list.push([key, value])
102
+ }
103
+ sort(): void { this._list.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0) }
104
+ forEach(fn: (v: string, k: string) => void): void { for (const [k, v] of this._list) fn(v, k) }
105
+
106
+ *keys(): IterableIterator<string> { for (const [k] of this._list) yield k }
107
+ *values(): IterableIterator<string> { for (const [, v] of this._list) yield v }
108
+ *entries(): IterableIterator<[string, string]> { for (const item of this._list) yield [item[0], item[1]] }
109
+ *[Symbol.iterator](): IterableIterator<[string, string]> { for (const item of this._list) yield item }
110
+
111
+ toString(): string { return this._list.map(([k, v]) => _encode(k) + '=' + _encode(v)).join('&') }
112
+ get size(): number { return this._list.length }
113
+ }
114
+
115
+ if (typeof globalThis.URLSearchParams === 'undefined') {
116
+ globalThis.URLSearchParams = URLSearchParamsImpl
117
+ }
118
+
119
+ class URLImpl {
120
+ private _scheme = ''
121
+ private _username = ''
122
+ private _password = ''
123
+ private _hostname = ''
124
+ private _port = ''
125
+ private _pathname = '/'
126
+ private _query = ''
127
+ private _fragment = ''
128
+ private _searchParams: URLSearchParams = new URLSearchParamsImpl()
129
+
130
+ constructor(url: string, base?: string) {
131
+ let p = _parseURL(url)
132
+ if (p.scheme) { this._apply(p); return }
133
+ if (base === undefined) throw new TypeError('Invalid URL')
134
+
135
+ const b = new URLImpl(base)
136
+ if (p.host) { p.scheme = b._scheme; this._apply(p); return }
137
+ if (!p.path && !p.query) {
138
+ this._apply({
139
+ scheme: b._scheme, user: b._username, pass: b._password,
140
+ host: b._hostname, port: b._port,
141
+ path: b._pathname, query: b._query, fragment: p.fragment || ''
142
+ }); return
143
+ }
144
+ p.scheme = b._scheme; if (!p.user) p.user = b._username; if (!p.pass) p.pass = b._password
145
+ if (!p.host) p.host = b._hostname; if (!p.port) p.port = b._port; if (!p.fragment) p.fragment = ''
146
+ if (p.path && !p.path.startsWith('/')) {
147
+ const bd = b._pathname.substring(0, b._pathname.lastIndexOf('/') + 1)
148
+ p.path = _normalizePath(bd + p.path)
149
+ } else if (!p.path) { p.path = b._pathname; if (!p.query) p.query = b._query }
150
+ this._apply(p)
151
+ }
152
+
153
+ private _apply(p: { scheme: string; user: string; pass: string; host: string; port: string; path: string; query: string; fragment: string }): void {
154
+ this._scheme = p.scheme; this._username = p.user; this._password = p.pass
155
+ this._hostname = p.host; this._port = p.port
156
+ this._pathname = _normalizePath(p.path || '/')
157
+ this._query = p.query; this._fragment = p.fragment
158
+ this._searchParams = new URLSearchParamsImpl(this._query)
159
+ }
160
+
161
+ get href(): string { return this.toString() }
162
+ get protocol(): string { return this._scheme + ':' }
163
+ get hostname(): string { return this._hostname }
164
+ get port(): string { return this._port }
165
+ get pathname(): string { return this._pathname }
166
+ get search(): string { return this._query ? '?' + this._query : '' }
167
+ get hash(): string { return this._fragment ? '#' + this._fragment : '' }
168
+ get host(): string {
169
+ const h = this._hostname
170
+ const ipv6 = h.includes(':')
171
+ return (ipv6 ? '[' + h + ']' : h) + (this._port ? ':' + this._port : '')
172
+ }
173
+ get origin(): string {
174
+ const h = this._hostname
175
+ const ipv6 = h.includes(':')
176
+ return this._scheme + '://' + (ipv6 ? '[' + h + ']' : h) + (this._port ? ':' + this._port : '')
177
+ }
178
+ get username(): string { return this._username }
179
+ get password(): string { return this._password }
180
+ get searchParams(): URLSearchParams { return this._searchParams }
181
+
182
+ toString(): string {
183
+ let s = this._scheme + ':'
184
+ const special = ['http', 'https', 'ws', 'wss', 'ftp', 'file']
185
+ if (this._hostname || (special.includes(this._scheme) && this._pathname.startsWith('/'))) {
186
+ s += '//'
187
+ if (this._username) { s += _encode(this._username); if (this._password) s += ':' + _encode(this._password); s += '@' }
188
+ s += this._hostname.includes(':') ? '[' + this._hostname + ']' : this._hostname
189
+ if (this._port) s += ':' + this._port
190
+ }
191
+ s += this._pathname
192
+ if (this._query) s += '?' + this._query
193
+ if (this._fragment) s += '#' + this._fragment
194
+ return s
195
+ }
196
+
197
+ toJSON(): string { return this.toString() }
198
+ }
199
+ if (typeof globalThis.URL === 'undefined') {
200
+ globalThis.URL = URLImpl
201
+ }