quickwin 1.0.1 → 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.
- package/README.en.md +204 -204
- package/README.md +203 -203
- package/examples/PdfCanvas.tsx +83 -83
- package/examples/exec_server.js +25 -3
- package/examples/exec_server.ts +35 -17
- package/examples/pdf_preview2.ts +375 -375
- package/examples/pdf_viewer.tsx +279 -279
- package/examples/test_gallery.tsx +285 -285
- package/examples/test_react_lazy.tsx +63 -63
- package/examples/test_react_listbox.tsx +71 -71
- package/examples/test_root_window.tsx +41 -41
- package/examples/test_tab.tsx +75 -75
- package/examples/tray_demo.tsx +81 -81
- package/lib/assert.ts +6 -6
- package/lib/cache-utils.ts +40 -40
- package/lib/dumpRects.ts +25 -25
- package/lib/fetch.ts +502 -502
- package/lib/http-common.ts +399 -399
- package/lib/http-server.ts +424 -424
- package/lib/polyfill.ts +171 -171
- package/lib/react-qw/components/index.ts +17 -17
- package/lib/react-qw/index.ts +90 -90
- package/lib/react-qw/jsx.d.ts +34 -34
- package/lib/react-qw/layout.ts +111 -111
- package/lib/react-qw/props.ts +36 -36
- package/lib/react-qw/reconciler.ts +373 -373
- package/lib/stream.ts +21 -21
- package/lib/text-codec.ts +171 -171
- package/lib/text-measure.ts +54 -54
- package/lib/url.ts +201 -201
- package/lib/vendor/web-streams/ponyfill.d.mts +829 -829
- package/lib/vendor/web-streams/ponyfill.mjs +8 -8
- package/lib/websocket.js +8 -0
- package/lib/websocket.ts +563 -555
- package/package.json +50 -44
- package/qwin-nowasm-x86.exe +0 -0
- package/qwin-nowasm.exe +0 -0
- package/qwin-x86.exe +0 -0
- package/qwin.exe +0 -0
- package/test/run.ts +96 -96
- package/test/test_basic.ts +9 -9
- package/test/test_basic_fetch.ts +33 -33
- package/test/test_brotli.ts +52 -52
- package/test/test_fetch_cache.ts +187 -187
- package/test/test_ffi.ts +174 -174
- package/test/test_frame_encoding.ts +132 -132
- package/test/test_helper.ts +80 -80
- package/test/test_http_import.ts +74 -74
- package/test/test_http_server.ts +136 -136
- package/test/test_import_dir.ts +5 -5
- package/test/test_ipv6.ts +129 -129
- package/test/test_meta_url.ts +4 -4
- package/test/test_mupdf_render.ts +74 -74
- package/test/test_mupdf_twice.ts +81 -81
- package/test/test_mupdf_wasm.ts +30 -30
- package/test/test_net_event.ts +55 -55
- package/test/test_net_fetch.ts +238 -238
- package/test/test_net_websocket.ts +164 -164
- package/test/test_polyfill.ts +159 -159
- package/test/test_url.ts +183 -183
- package/test/test_wasm_basic.ts +73 -73
- package/test/test_wasm_import_global.ts +45 -45
- package/test/test_wasm_sjlj.ts +125 -125
- package/test/test_wasm_types.ts +124 -124
- package/test/test_worker.ts +24 -24
- package/test/test_worker_fetch.ts +27 -27
- package/test/test_worker_net.ts +54 -54
- package/test/test_worker_wasm_concurrent.ts +45 -45
- package/test/worker_fetch.ts +13 -13
- package/test/worker_helper.ts +1 -1
- package/test/worker_http.ts +20 -20
- package/test/worker_import_lib.ts +13 -13
- package/test/worker_module.ts +17 -17
- package/test/worker_wasm_concurrent.ts +22 -22
- package/tsconfig.json +27 -27
- package/vendor/mupdf-wasm/mupdf-wasm.d.ts +571 -571
- package/vendor/mupdf-wasm/mupdf-wasm.js +2749 -2749
- package/vendor/mupdf-wasm/mupdf.d.ts +939 -939
- package/vendor/mupdf-wasm/mupdf.js +3317 -3317
package/test/test_ipv6.ts
CHANGED
|
@@ -1,129 +1,129 @@
|
|
|
1
|
-
import * as sock from 'sock'
|
|
2
|
-
import * as std from 'std'
|
|
3
|
-
import * as os from 'os'
|
|
4
|
-
import '../lib/fetch.js'
|
|
5
|
-
import '../lib/websocket.js'
|
|
6
|
-
import { Tester } from './test_helper.js'
|
|
7
|
-
|
|
8
|
-
const HTTP_PORT = 18923
|
|
9
|
-
const HTTPS_PORT = 18924
|
|
10
|
-
|
|
11
|
-
export const suite = {
|
|
12
|
-
name: 'ipv6',
|
|
13
|
-
run: async (t: Tester) => {
|
|
14
|
-
function assert(name: string, ok: boolean): void {
|
|
15
|
-
if (ok) { t.ok++; std.printf(' PASS: %s\n', name) }
|
|
16
|
-
else { t.fail++; std.printf(' FAIL: %s\n', name) }
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// ── 1. sock.resolve ──
|
|
20
|
-
t.section('sock.resolve ::1')
|
|
21
|
-
{
|
|
22
|
-
const ip = sock.resolve('::1')
|
|
23
|
-
assert('resolve ::1 returns ::1', ip === '::1')
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// ── 2. Raw socket IPv6 ──
|
|
27
|
-
t.section('raw socket ::1 HTTP GET')
|
|
28
|
-
await new Promise<void>((resolve, reject) => {
|
|
29
|
-
const s = sock.socket()
|
|
30
|
-
if (s === null || s < 0) { t.fail++; reject(new Error('socket() failed')); return }
|
|
31
|
-
|
|
32
|
-
let connected = false, gotData = false
|
|
33
|
-
|
|
34
|
-
sock.set_on_event(s, (event: { lNetworkEvents: number; iErrorCode: number[] }) => {
|
|
35
|
-
if (event.lNetworkEvents & sock.FdEvent.FD_CONNECT) {
|
|
36
|
-
if (event.iErrorCode[0] === 0) {
|
|
37
|
-
connected = true; t.ok++
|
|
38
|
-
const req = "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"
|
|
39
|
-
const buf = new ArrayBuffer(req.length)
|
|
40
|
-
const v = new Uint8Array(buf)
|
|
41
|
-
for (let i = 0; i < req.length; i++) v[i] = req.charCodeAt(i)
|
|
42
|
-
sock.send(s, buf)
|
|
43
|
-
} else {
|
|
44
|
-
sock.closesocket(s)
|
|
45
|
-
reject(new Error('connect error: ' + event.iErrorCode[0]))
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (event.lNetworkEvents & sock.FdEvent.FD_READ && connected && !gotData) {
|
|
49
|
-
const data = sock.recv(s, 4096)
|
|
50
|
-
if (data && data.byteLength > 0) { gotData = true; t.ok++ }
|
|
51
|
-
}
|
|
52
|
-
if (event.lNetworkEvents & sock.FdEvent.FD_CLOSE) {
|
|
53
|
-
sock.closesocket(s)
|
|
54
|
-
if (gotData && connected) resolve()
|
|
55
|
-
else reject(new Error('test incomplete'))
|
|
56
|
-
}
|
|
57
|
-
})
|
|
58
|
-
sock.connect(s, '::1', HTTP_PORT)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
// ── 3. fetch HTTP IPv6 ──
|
|
62
|
-
t.section('fetch http://[::1]')
|
|
63
|
-
{
|
|
64
|
-
const r = await fetch(`http://[::1]:${HTTP_PORT}/`, { timeout: 5000 })
|
|
65
|
-
assert('fetch IPv6 HTTP status 200', r.status === 200)
|
|
66
|
-
const body = await r.text()
|
|
67
|
-
assert('fetch IPv6 HTTP body', body === 'hello from test server')
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// ── 4. fetch HTTPS IPv6 ──
|
|
71
|
-
t.section('fetch https://[::1]')
|
|
72
|
-
{
|
|
73
|
-
const r = await fetch(`https://[::1]:${HTTPS_PORT}/`, { timeout: 5000 })
|
|
74
|
-
assert('fetch IPv6 HTTPS status 200', r.status === 200)
|
|
75
|
-
const body = await r.text()
|
|
76
|
-
assert('fetch IPv6 HTTPS body', body === 'hello from test server')
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// ── 5. WebSocket IPv6 ──
|
|
80
|
-
t.section('ws://[::1] echo')
|
|
81
|
-
await new Promise<void>((resolve, reject) => {
|
|
82
|
-
const ws = new WebSocket(`ws://[::1]:${HTTP_PORT}/`)
|
|
83
|
-
const timeoutId = os.setTimeout(() => reject(new Error('WS IPv6 timeout')), 10000)
|
|
84
|
-
|
|
85
|
-
ws.onopen = () => {
|
|
86
|
-
t.ok++
|
|
87
|
-
ws.send('hello ipv6')
|
|
88
|
-
}
|
|
89
|
-
ws.onmessage = (evt) => {
|
|
90
|
-
t.ok++
|
|
91
|
-
assert('WS IPv6 echo matches', evt.data === 'hello ipv6')
|
|
92
|
-
ws.close()
|
|
93
|
-
}
|
|
94
|
-
ws.onclose = () => {
|
|
95
|
-
os.clearTimeout(timeoutId)
|
|
96
|
-
resolve()
|
|
97
|
-
}
|
|
98
|
-
ws.onerror = () => {
|
|
99
|
-
os.clearTimeout(timeoutId)
|
|
100
|
-
reject(new Error('WS IPv6 error'))
|
|
101
|
-
}
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
// ── 6. WebSocket WSS IPv6 ──
|
|
105
|
-
t.section('wss://[::1] echo')
|
|
106
|
-
await new Promise<void>((resolve, reject) => {
|
|
107
|
-
const ws = new WebSocket(`wss://[::1]:${HTTPS_PORT}/`)
|
|
108
|
-
const timeoutId = os.setTimeout(() => reject(new Error('WSS IPv6 timeout')), 10000)
|
|
109
|
-
|
|
110
|
-
ws.onopen = () => {
|
|
111
|
-
t.ok++
|
|
112
|
-
ws.send('hello wss ipv6')
|
|
113
|
-
}
|
|
114
|
-
ws.onmessage = (evt) => {
|
|
115
|
-
t.ok++
|
|
116
|
-
assert('WSS IPv6 echo matches', evt.data === 'hello wss ipv6')
|
|
117
|
-
ws.close()
|
|
118
|
-
}
|
|
119
|
-
ws.onclose = () => {
|
|
120
|
-
os.clearTimeout(timeoutId)
|
|
121
|
-
resolve()
|
|
122
|
-
}
|
|
123
|
-
ws.onerror = () => {
|
|
124
|
-
os.clearTimeout(timeoutId)
|
|
125
|
-
reject(new Error('WSS IPv6 error'))
|
|
126
|
-
}
|
|
127
|
-
})
|
|
128
|
-
}
|
|
129
|
-
}
|
|
1
|
+
import * as sock from 'sock'
|
|
2
|
+
import * as std from 'std'
|
|
3
|
+
import * as os from 'os'
|
|
4
|
+
import '../lib/fetch.js'
|
|
5
|
+
import '../lib/websocket.js'
|
|
6
|
+
import { Tester } from './test_helper.js'
|
|
7
|
+
|
|
8
|
+
const HTTP_PORT = 18923
|
|
9
|
+
const HTTPS_PORT = 18924
|
|
10
|
+
|
|
11
|
+
export const suite = {
|
|
12
|
+
name: 'ipv6',
|
|
13
|
+
run: async (t: Tester) => {
|
|
14
|
+
function assert(name: string, ok: boolean): void {
|
|
15
|
+
if (ok) { t.ok++; std.printf(' PASS: %s\n', name) }
|
|
16
|
+
else { t.fail++; std.printf(' FAIL: %s\n', name) }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// ── 1. sock.resolve ──
|
|
20
|
+
t.section('sock.resolve ::1')
|
|
21
|
+
{
|
|
22
|
+
const ip = sock.resolve('::1')
|
|
23
|
+
assert('resolve ::1 returns ::1', ip === '::1')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// ── 2. Raw socket IPv6 ──
|
|
27
|
+
t.section('raw socket ::1 HTTP GET')
|
|
28
|
+
await new Promise<void>((resolve, reject) => {
|
|
29
|
+
const s = sock.socket()
|
|
30
|
+
if (s === null || s < 0) { t.fail++; reject(new Error('socket() failed')); return }
|
|
31
|
+
|
|
32
|
+
let connected = false, gotData = false
|
|
33
|
+
|
|
34
|
+
sock.set_on_event(s, (event: { lNetworkEvents: number; iErrorCode: number[] }) => {
|
|
35
|
+
if (event.lNetworkEvents & sock.FdEvent.FD_CONNECT) {
|
|
36
|
+
if (event.iErrorCode[0] === 0) {
|
|
37
|
+
connected = true; t.ok++
|
|
38
|
+
const req = "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"
|
|
39
|
+
const buf = new ArrayBuffer(req.length)
|
|
40
|
+
const v = new Uint8Array(buf)
|
|
41
|
+
for (let i = 0; i < req.length; i++) v[i] = req.charCodeAt(i)
|
|
42
|
+
sock.send(s, buf)
|
|
43
|
+
} else {
|
|
44
|
+
sock.closesocket(s)
|
|
45
|
+
reject(new Error('connect error: ' + event.iErrorCode[0]))
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (event.lNetworkEvents & sock.FdEvent.FD_READ && connected && !gotData) {
|
|
49
|
+
const data = sock.recv(s, 4096)
|
|
50
|
+
if (data && data.byteLength > 0) { gotData = true; t.ok++ }
|
|
51
|
+
}
|
|
52
|
+
if (event.lNetworkEvents & sock.FdEvent.FD_CLOSE) {
|
|
53
|
+
sock.closesocket(s)
|
|
54
|
+
if (gotData && connected) resolve()
|
|
55
|
+
else reject(new Error('test incomplete'))
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
sock.connect(s, '::1', HTTP_PORT)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
// ── 3. fetch HTTP IPv6 ──
|
|
62
|
+
t.section('fetch http://[::1]')
|
|
63
|
+
{
|
|
64
|
+
const r = await fetch(`http://[::1]:${HTTP_PORT}/`, { timeout: 5000 })
|
|
65
|
+
assert('fetch IPv6 HTTP status 200', r.status === 200)
|
|
66
|
+
const body = await r.text()
|
|
67
|
+
assert('fetch IPv6 HTTP body', body === 'hello from test server')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ── 4. fetch HTTPS IPv6 ──
|
|
71
|
+
t.section('fetch https://[::1]')
|
|
72
|
+
{
|
|
73
|
+
const r = await fetch(`https://[::1]:${HTTPS_PORT}/`, { timeout: 5000 })
|
|
74
|
+
assert('fetch IPv6 HTTPS status 200', r.status === 200)
|
|
75
|
+
const body = await r.text()
|
|
76
|
+
assert('fetch IPv6 HTTPS body', body === 'hello from test server')
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ── 5. WebSocket IPv6 ──
|
|
80
|
+
t.section('ws://[::1] echo')
|
|
81
|
+
await new Promise<void>((resolve, reject) => {
|
|
82
|
+
const ws = new WebSocket(`ws://[::1]:${HTTP_PORT}/`)
|
|
83
|
+
const timeoutId = os.setTimeout(() => reject(new Error('WS IPv6 timeout')), 10000)
|
|
84
|
+
|
|
85
|
+
ws.onopen = () => {
|
|
86
|
+
t.ok++
|
|
87
|
+
ws.send('hello ipv6')
|
|
88
|
+
}
|
|
89
|
+
ws.onmessage = (evt) => {
|
|
90
|
+
t.ok++
|
|
91
|
+
assert('WS IPv6 echo matches', evt.data === 'hello ipv6')
|
|
92
|
+
ws.close()
|
|
93
|
+
}
|
|
94
|
+
ws.onclose = () => {
|
|
95
|
+
os.clearTimeout(timeoutId)
|
|
96
|
+
resolve()
|
|
97
|
+
}
|
|
98
|
+
ws.onerror = () => {
|
|
99
|
+
os.clearTimeout(timeoutId)
|
|
100
|
+
reject(new Error('WS IPv6 error'))
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
// ── 6. WebSocket WSS IPv6 ──
|
|
105
|
+
t.section('wss://[::1] echo')
|
|
106
|
+
await new Promise<void>((resolve, reject) => {
|
|
107
|
+
const ws = new WebSocket(`wss://[::1]:${HTTPS_PORT}/`)
|
|
108
|
+
const timeoutId = os.setTimeout(() => reject(new Error('WSS IPv6 timeout')), 10000)
|
|
109
|
+
|
|
110
|
+
ws.onopen = () => {
|
|
111
|
+
t.ok++
|
|
112
|
+
ws.send('hello wss ipv6')
|
|
113
|
+
}
|
|
114
|
+
ws.onmessage = (evt) => {
|
|
115
|
+
t.ok++
|
|
116
|
+
assert('WSS IPv6 echo matches', evt.data === 'hello wss ipv6')
|
|
117
|
+
ws.close()
|
|
118
|
+
}
|
|
119
|
+
ws.onclose = () => {
|
|
120
|
+
os.clearTimeout(timeoutId)
|
|
121
|
+
resolve()
|
|
122
|
+
}
|
|
123
|
+
ws.onerror = () => {
|
|
124
|
+
os.clearTimeout(timeoutId)
|
|
125
|
+
reject(new Error('WSS IPv6 error'))
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
}
|
package/test/test_meta_url.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as os from 'os'
|
|
2
|
-
|
|
3
|
-
const parent = os.Worker.parent
|
|
4
|
-
parent.postMessage({ type: 'url', url: import.meta.url })
|
|
1
|
+
import * as os from 'os'
|
|
2
|
+
|
|
3
|
+
const parent = os.Worker.parent
|
|
4
|
+
parent.postMessage({ type: 'url', url: import.meta.url })
|
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
import * as std from 'std'
|
|
2
|
-
import { Tester } from './test_helper.js'
|
|
3
|
-
import '../lib/polyfill.js'
|
|
4
|
-
|
|
5
|
-
function loadWasmBytes(path: string): ArrayBuffer {
|
|
6
|
-
const fp = std.open(path, 'rb')
|
|
7
|
-
if (!fp) throw new Error('Cannot open: ' + path)
|
|
8
|
-
fp.seek(0, 2)
|
|
9
|
-
const size = fp.tell()
|
|
10
|
-
fp.seek(0, 0)
|
|
11
|
-
const buffer = new ArrayBuffer(size)
|
|
12
|
-
fp.read(buffer, 0, size)
|
|
13
|
-
fp.close()
|
|
14
|
-
return buffer
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function setupMupdfModule(wasmPath: string) {
|
|
18
|
-
const wasmBinary = loadWasmBytes(wasmPath)
|
|
19
|
-
;(globalThis as any)["$libmupdf_wasm_Module"] = {
|
|
20
|
-
wasmBinary,
|
|
21
|
-
locateFile: (p: string) => p
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const suite = {
|
|
26
|
-
name: 'mupdf-render',
|
|
27
|
-
run: async (t: Tester): Promise<void> => {
|
|
28
|
-
try {
|
|
29
|
-
setupMupdfModule('./vendor/mupdf-wasm/mupdf-wasm.wasm')
|
|
30
|
-
|
|
31
|
-
const mupdf: typeof import('../vendor/mupdf-wasm/mupdf.js') = await import('../vendor/mupdf-wasm/mupdf.js')
|
|
32
|
-
|
|
33
|
-
const fp = std.open('./example.pdf', 'rb')
|
|
34
|
-
if (!fp) { console.log('SKIP: no example.pdf'); return }
|
|
35
|
-
fp.seek(0, 2)
|
|
36
|
-
const size = fp.tell()
|
|
37
|
-
fp.seek(0, 0)
|
|
38
|
-
const buf = new ArrayBuffer(size)
|
|
39
|
-
fp.read(buf, 0, size)
|
|
40
|
-
fp.close()
|
|
41
|
-
console.log('pdf size:', size)
|
|
42
|
-
|
|
43
|
-
const doc = mupdf.Document.openDocument(new Uint8Array(buf), "application/pdf")
|
|
44
|
-
console.log('pages:', doc.countPages())
|
|
45
|
-
|
|
46
|
-
const page = doc.loadPage(0)
|
|
47
|
-
const bounds = page.getBounds()
|
|
48
|
-
if (bounds && bounds.length === 4)
|
|
49
|
-
console.log('page size:', bounds[2] - bounds[0], 'x', bounds[3] - bounds[1])
|
|
50
|
-
|
|
51
|
-
const pixmap = page.toPixmap(mupdf.Matrix.scale(2, 2), mupdf.ColorSpace.DeviceRGB, false)
|
|
52
|
-
if (pixmap) {
|
|
53
|
-
console.log('pixmap:', pixmap.getWidth(), 'x', pixmap.getHeight())
|
|
54
|
-
const png = pixmap.asPNG()
|
|
55
|
-
console.log('png size:', png.byteLength)
|
|
56
|
-
const out = std.open('./output.png', 'wb')
|
|
57
|
-
if (out) {
|
|
58
|
-
const pngBuf = new ArrayBuffer(png.byteLength)
|
|
59
|
-
new Uint8Array(pngBuf).set(png)
|
|
60
|
-
out.write(pngBuf, 0, png.byteLength)
|
|
61
|
-
out.close()
|
|
62
|
-
}
|
|
63
|
-
console.log('saved to output.png')
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
doc.destroy()
|
|
67
|
-
console.log('done')
|
|
68
|
-
t.ok++
|
|
69
|
-
} catch (error) {
|
|
70
|
-
console.log('ERROR:', error)
|
|
71
|
-
t.fail++
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
1
|
+
import * as std from 'std'
|
|
2
|
+
import { Tester } from './test_helper.js'
|
|
3
|
+
import '../lib/polyfill.js'
|
|
4
|
+
|
|
5
|
+
function loadWasmBytes(path: string): ArrayBuffer {
|
|
6
|
+
const fp = std.open(path, 'rb')
|
|
7
|
+
if (!fp) throw new Error('Cannot open: ' + path)
|
|
8
|
+
fp.seek(0, 2)
|
|
9
|
+
const size = fp.tell()
|
|
10
|
+
fp.seek(0, 0)
|
|
11
|
+
const buffer = new ArrayBuffer(size)
|
|
12
|
+
fp.read(buffer, 0, size)
|
|
13
|
+
fp.close()
|
|
14
|
+
return buffer
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function setupMupdfModule(wasmPath: string) {
|
|
18
|
+
const wasmBinary = loadWasmBytes(wasmPath)
|
|
19
|
+
;(globalThis as any)["$libmupdf_wasm_Module"] = {
|
|
20
|
+
wasmBinary,
|
|
21
|
+
locateFile: (p: string) => p
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const suite = {
|
|
26
|
+
name: 'mupdf-render',
|
|
27
|
+
run: async (t: Tester): Promise<void> => {
|
|
28
|
+
try {
|
|
29
|
+
setupMupdfModule('./vendor/mupdf-wasm/mupdf-wasm.wasm')
|
|
30
|
+
|
|
31
|
+
const mupdf: typeof import('../vendor/mupdf-wasm/mupdf.js') = await import('../vendor/mupdf-wasm/mupdf.js')
|
|
32
|
+
|
|
33
|
+
const fp = std.open('./example.pdf', 'rb')
|
|
34
|
+
if (!fp) { console.log('SKIP: no example.pdf'); return }
|
|
35
|
+
fp.seek(0, 2)
|
|
36
|
+
const size = fp.tell()
|
|
37
|
+
fp.seek(0, 0)
|
|
38
|
+
const buf = new ArrayBuffer(size)
|
|
39
|
+
fp.read(buf, 0, size)
|
|
40
|
+
fp.close()
|
|
41
|
+
console.log('pdf size:', size)
|
|
42
|
+
|
|
43
|
+
const doc = mupdf.Document.openDocument(new Uint8Array(buf), "application/pdf")
|
|
44
|
+
console.log('pages:', doc.countPages())
|
|
45
|
+
|
|
46
|
+
const page = doc.loadPage(0)
|
|
47
|
+
const bounds = page.getBounds()
|
|
48
|
+
if (bounds && bounds.length === 4)
|
|
49
|
+
console.log('page size:', bounds[2] - bounds[0], 'x', bounds[3] - bounds[1])
|
|
50
|
+
|
|
51
|
+
const pixmap = page.toPixmap(mupdf.Matrix.scale(2, 2), mupdf.ColorSpace.DeviceRGB, false)
|
|
52
|
+
if (pixmap) {
|
|
53
|
+
console.log('pixmap:', pixmap.getWidth(), 'x', pixmap.getHeight())
|
|
54
|
+
const png = pixmap.asPNG()
|
|
55
|
+
console.log('png size:', png.byteLength)
|
|
56
|
+
const out = std.open('./output.png', 'wb')
|
|
57
|
+
if (out) {
|
|
58
|
+
const pngBuf = new ArrayBuffer(png.byteLength)
|
|
59
|
+
new Uint8Array(pngBuf).set(png)
|
|
60
|
+
out.write(pngBuf, 0, png.byteLength)
|
|
61
|
+
out.close()
|
|
62
|
+
}
|
|
63
|
+
console.log('saved to output.png')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
doc.destroy()
|
|
67
|
+
console.log('done')
|
|
68
|
+
t.ok++
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.log('ERROR:', error)
|
|
71
|
+
t.fail++
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
package/test/test_mupdf_twice.ts
CHANGED
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
import '../lib/polyfill.js'
|
|
2
|
-
import * as std from 'std'
|
|
3
|
-
import { Tester } from './test_helper.js'
|
|
4
|
-
|
|
5
|
-
function loadWasmBytes(path: string): ArrayBuffer {
|
|
6
|
-
const fp = std.open(path, 'rb')
|
|
7
|
-
if (!fp) throw new Error('Cannot open: ' + path)
|
|
8
|
-
fp.seek(0, 2)
|
|
9
|
-
const size = fp.tell()
|
|
10
|
-
fp.seek(0, 0)
|
|
11
|
-
const buffer = new ArrayBuffer(size)
|
|
12
|
-
fp.read(buffer, 0, size)
|
|
13
|
-
fp.close()
|
|
14
|
-
return buffer
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const suite = {
|
|
18
|
-
name: 'mupdf-twice',
|
|
19
|
-
run: async (t: Tester): Promise<void> => {
|
|
20
|
-
try {
|
|
21
|
-
console.log(' Loading WASM binary...')
|
|
22
|
-
const wasmBinary = loadWasmBytes('./vendor/mupdf-wasm/mupdf-wasm.wasm')
|
|
23
|
-
console.log(' WASM binary loaded, size:', wasmBinary.byteLength)
|
|
24
|
-
|
|
25
|
-
;(globalThis as any)["$libmupdf_wasm_Module"] = {
|
|
26
|
-
wasmBinary,
|
|
27
|
-
locateFile: (p: string) => p
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
console.log(' Importing mupdf module...')
|
|
31
|
-
const mupdf: typeof import('../vendor/mupdf-wasm/mupdf.js') = await import('../vendor/mupdf-wasm/mupdf.js')
|
|
32
|
-
console.log(' mupdf module imported ok')
|
|
33
|
-
|
|
34
|
-
const fp = std.open('./example.pdf', 'rb')
|
|
35
|
-
if (!fp) { console.log('SKIP: no example.pdf'); return }
|
|
36
|
-
fp.seek(0, 2)
|
|
37
|
-
const size = fp.tell()
|
|
38
|
-
fp.seek(0, 0)
|
|
39
|
-
const pdfBuf = new ArrayBuffer(size)
|
|
40
|
-
fp.read(pdfBuf, 0, size)
|
|
41
|
-
fp.close()
|
|
42
|
-
console.log(' PDF loaded, size:', size)
|
|
43
|
-
|
|
44
|
-
t.section('Test 1: two toPixmap on same page (no destroy)')
|
|
45
|
-
try {
|
|
46
|
-
const doc = mupdf.Document.openDocument(new Uint8Array(pdfBuf), "application/pdf")
|
|
47
|
-
const page = doc.loadPage(0)
|
|
48
|
-
|
|
49
|
-
console.log(' 1: toPixmap #1...')
|
|
50
|
-
const pm1 = page.toPixmap(mupdf.Matrix.scale(1, 1), mupdf.ColorSpace.DeviceRGB, false)
|
|
51
|
-
console.log(' 1: toPixmap #1 done:', pm1.getWidth(), 'x', pm1.getHeight())
|
|
52
|
-
t.check('toPixmap #1 ok', true, pm1 !== null)
|
|
53
|
-
|
|
54
|
-
console.log(' 1: toPixmap #2...')
|
|
55
|
-
const pm2 = page.toPixmap(mupdf.Matrix.scale(1, 1), mupdf.ColorSpace.DeviceRGB, false)
|
|
56
|
-
console.log(' 1: toPixmap #2 done:', pm2.getWidth(), 'x', pm2.getHeight())
|
|
57
|
-
t.check('toPixmap #2 ok', true, pm2 !== null)
|
|
58
|
-
} catch (e: unknown) {
|
|
59
|
-
console.log(' 1: ERROR:', e instanceof Error ? e.message : String(e))
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
t.section('Test 2: second openDocument + toPixmap (no destroy of first)')
|
|
63
|
-
try {
|
|
64
|
-
console.log(' 2: openDocument #2...')
|
|
65
|
-
const doc2 = mupdf.Document.openDocument(new Uint8Array(pdfBuf), "application/pdf")
|
|
66
|
-
console.log(' 2: loadPage #2...')
|
|
67
|
-
const page2 = doc2.loadPage(0)
|
|
68
|
-
console.log(' 2: toPixmap #3...')
|
|
69
|
-
const pm3 = page2.toPixmap(mupdf.Matrix.scale(1, 1), mupdf.ColorSpace.DeviceRGB, false)
|
|
70
|
-
console.log(' 2: toPixmap #3 done:', pm3.getWidth(), 'x', pm3.getHeight())
|
|
71
|
-
t.check('toPixmap #3 ok', true, pm3 !== null)
|
|
72
|
-
} catch (e: unknown) {
|
|
73
|
-
console.log(' 2: ERROR:', e instanceof Error ? e.message : String(e))
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
console.log('All mupdf-twice tests done')
|
|
77
|
-
} catch (e: unknown) {
|
|
78
|
-
console.log('TOP-LEVEL ERROR:', e instanceof Error ? e.message : String(e))
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
1
|
+
import '../lib/polyfill.js'
|
|
2
|
+
import * as std from 'std'
|
|
3
|
+
import { Tester } from './test_helper.js'
|
|
4
|
+
|
|
5
|
+
function loadWasmBytes(path: string): ArrayBuffer {
|
|
6
|
+
const fp = std.open(path, 'rb')
|
|
7
|
+
if (!fp) throw new Error('Cannot open: ' + path)
|
|
8
|
+
fp.seek(0, 2)
|
|
9
|
+
const size = fp.tell()
|
|
10
|
+
fp.seek(0, 0)
|
|
11
|
+
const buffer = new ArrayBuffer(size)
|
|
12
|
+
fp.read(buffer, 0, size)
|
|
13
|
+
fp.close()
|
|
14
|
+
return buffer
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const suite = {
|
|
18
|
+
name: 'mupdf-twice',
|
|
19
|
+
run: async (t: Tester): Promise<void> => {
|
|
20
|
+
try {
|
|
21
|
+
console.log(' Loading WASM binary...')
|
|
22
|
+
const wasmBinary = loadWasmBytes('./vendor/mupdf-wasm/mupdf-wasm.wasm')
|
|
23
|
+
console.log(' WASM binary loaded, size:', wasmBinary.byteLength)
|
|
24
|
+
|
|
25
|
+
;(globalThis as any)["$libmupdf_wasm_Module"] = {
|
|
26
|
+
wasmBinary,
|
|
27
|
+
locateFile: (p: string) => p
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
console.log(' Importing mupdf module...')
|
|
31
|
+
const mupdf: typeof import('../vendor/mupdf-wasm/mupdf.js') = await import('../vendor/mupdf-wasm/mupdf.js')
|
|
32
|
+
console.log(' mupdf module imported ok')
|
|
33
|
+
|
|
34
|
+
const fp = std.open('./example.pdf', 'rb')
|
|
35
|
+
if (!fp) { console.log('SKIP: no example.pdf'); return }
|
|
36
|
+
fp.seek(0, 2)
|
|
37
|
+
const size = fp.tell()
|
|
38
|
+
fp.seek(0, 0)
|
|
39
|
+
const pdfBuf = new ArrayBuffer(size)
|
|
40
|
+
fp.read(pdfBuf, 0, size)
|
|
41
|
+
fp.close()
|
|
42
|
+
console.log(' PDF loaded, size:', size)
|
|
43
|
+
|
|
44
|
+
t.section('Test 1: two toPixmap on same page (no destroy)')
|
|
45
|
+
try {
|
|
46
|
+
const doc = mupdf.Document.openDocument(new Uint8Array(pdfBuf), "application/pdf")
|
|
47
|
+
const page = doc.loadPage(0)
|
|
48
|
+
|
|
49
|
+
console.log(' 1: toPixmap #1...')
|
|
50
|
+
const pm1 = page.toPixmap(mupdf.Matrix.scale(1, 1), mupdf.ColorSpace.DeviceRGB, false)
|
|
51
|
+
console.log(' 1: toPixmap #1 done:', pm1.getWidth(), 'x', pm1.getHeight())
|
|
52
|
+
t.check('toPixmap #1 ok', true, pm1 !== null)
|
|
53
|
+
|
|
54
|
+
console.log(' 1: toPixmap #2...')
|
|
55
|
+
const pm2 = page.toPixmap(mupdf.Matrix.scale(1, 1), mupdf.ColorSpace.DeviceRGB, false)
|
|
56
|
+
console.log(' 1: toPixmap #2 done:', pm2.getWidth(), 'x', pm2.getHeight())
|
|
57
|
+
t.check('toPixmap #2 ok', true, pm2 !== null)
|
|
58
|
+
} catch (e: unknown) {
|
|
59
|
+
console.log(' 1: ERROR:', e instanceof Error ? e.message : String(e))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
t.section('Test 2: second openDocument + toPixmap (no destroy of first)')
|
|
63
|
+
try {
|
|
64
|
+
console.log(' 2: openDocument #2...')
|
|
65
|
+
const doc2 = mupdf.Document.openDocument(new Uint8Array(pdfBuf), "application/pdf")
|
|
66
|
+
console.log(' 2: loadPage #2...')
|
|
67
|
+
const page2 = doc2.loadPage(0)
|
|
68
|
+
console.log(' 2: toPixmap #3...')
|
|
69
|
+
const pm3 = page2.toPixmap(mupdf.Matrix.scale(1, 1), mupdf.ColorSpace.DeviceRGB, false)
|
|
70
|
+
console.log(' 2: toPixmap #3 done:', pm3.getWidth(), 'x', pm3.getHeight())
|
|
71
|
+
t.check('toPixmap #3 ok', true, pm3 !== null)
|
|
72
|
+
} catch (e: unknown) {
|
|
73
|
+
console.log(' 2: ERROR:', e instanceof Error ? e.message : String(e))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
console.log('All mupdf-twice tests done')
|
|
77
|
+
} catch (e: unknown) {
|
|
78
|
+
console.log('TOP-LEVEL ERROR:', e instanceof Error ? e.message : String(e))
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
package/test/test_mupdf_wasm.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { Tester, readWasmFile } from './test_helper.js'
|
|
2
|
-
|
|
3
|
-
export const suite = {
|
|
4
|
-
name: 'vendor/mupdf-wasm',
|
|
5
|
-
run: (t: Tester) => {
|
|
6
|
-
t.section('validate binary')
|
|
7
|
-
const buf = readWasmFile('../vendor/mupdf-wasm/mupdf-wasm.wasm')
|
|
8
|
-
if (!buf) { t.fail++; return }
|
|
9
|
-
t.check('file size > 0', true, buf.byteLength > 0)
|
|
10
|
-
const header = new Uint8Array(buf)
|
|
11
|
-
t.check('magic', true, header[0] === 0x00 && header[1] === 0x61 && header[2] === 0x73 && header[3] === 0x6d)
|
|
12
|
-
t.check('version 1', true, header[4] === 0x01 && header[5] === 0x00 && header[6] === 0x00 && header[7] === 0x00)
|
|
13
|
-
t.check('WebAssembly.validate', true, WebAssembly.validate(buf))
|
|
14
|
-
|
|
15
|
-
t.section('Module')
|
|
16
|
-
var mod: WebAssembly.Module | null = null
|
|
17
|
-
try {
|
|
18
|
-
mod = new WebAssembly.Module(buf)
|
|
19
|
-
t.ok++
|
|
20
|
-
} catch (e) { t.fail++ }
|
|
21
|
-
|
|
22
|
-
t.section('imports/exports')
|
|
23
|
-
if (mod) {
|
|
24
|
-
const exps = WebAssembly.Module.exports(mod)
|
|
25
|
-
t.check('exports > 0', true, exps.length > 0)
|
|
26
|
-
const imps = WebAssembly.Module.imports(mod)
|
|
27
|
-
t.check('imports', imps.length, imps.length)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
1
|
+
import { Tester, readWasmFile } from './test_helper.js'
|
|
2
|
+
|
|
3
|
+
export const suite = {
|
|
4
|
+
name: 'vendor/mupdf-wasm',
|
|
5
|
+
run: (t: Tester) => {
|
|
6
|
+
t.section('validate binary')
|
|
7
|
+
const buf = readWasmFile('../vendor/mupdf-wasm/mupdf-wasm.wasm')
|
|
8
|
+
if (!buf) { t.fail++; return }
|
|
9
|
+
t.check('file size > 0', true, buf.byteLength > 0)
|
|
10
|
+
const header = new Uint8Array(buf)
|
|
11
|
+
t.check('magic', true, header[0] === 0x00 && header[1] === 0x61 && header[2] === 0x73 && header[3] === 0x6d)
|
|
12
|
+
t.check('version 1', true, header[4] === 0x01 && header[5] === 0x00 && header[6] === 0x00 && header[7] === 0x00)
|
|
13
|
+
t.check('WebAssembly.validate', true, WebAssembly.validate(buf))
|
|
14
|
+
|
|
15
|
+
t.section('Module')
|
|
16
|
+
var mod: WebAssembly.Module | null = null
|
|
17
|
+
try {
|
|
18
|
+
mod = new WebAssembly.Module(buf)
|
|
19
|
+
t.ok++
|
|
20
|
+
} catch (e) { t.fail++ }
|
|
21
|
+
|
|
22
|
+
t.section('imports/exports')
|
|
23
|
+
if (mod) {
|
|
24
|
+
const exps = WebAssembly.Module.exports(mod)
|
|
25
|
+
t.check('exports > 0', true, exps.length > 0)
|
|
26
|
+
const imps = WebAssembly.Module.imports(mod)
|
|
27
|
+
t.check('imports', imps.length, imps.length)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|