clearway-wasm 0.0.0-stage → 0.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.md +36 -2
- package/clearway_wasm.d.ts +18 -0
- package/clearway_wasm.js +9 -0
- package/clearway_wasm_bg.js +202 -0
- package/clearway_wasm_bg.wasm +0 -0
- package/package.json +21 -4
package/README.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
-
#
|
|
1
|
+
# clearway-wasm
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Universal WebAssembly bindings for [`clearway`](https://github.com/TheGreatAxios/clearway) using `wasm-bindgen`.
|
|
4
|
+
|
|
5
|
+
Works in browsers, Chrome extensions, Cloudflare Workers, Node, Bun, and Deno.
|
|
6
|
+
|
|
7
|
+
## Build
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
# Bundlers (Vite, webpack, esbuild, Cloudflare Workers)
|
|
11
|
+
wasm-pack build --target bundler
|
|
12
|
+
|
|
13
|
+
# Node / Bun
|
|
14
|
+
wasm-pack build --target nodejs
|
|
15
|
+
|
|
16
|
+
# Direct browser ES modules
|
|
17
|
+
wasm-pack build --target web
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import init, { audit_html, audit_document, builtin_rules } from "./pkg/clearway_wasm.js";
|
|
24
|
+
|
|
25
|
+
// Required for `--target web` (omit for `--target bundler` or `--target nodejs`)
|
|
26
|
+
await init();
|
|
27
|
+
|
|
28
|
+
const report = JSON.parse(audit_html('<html lang="en"><head><title>Hi</title></head><body><main><h1>Hi</h1></main></body></html>'));
|
|
29
|
+
console.log(report.summary);
|
|
30
|
+
|
|
31
|
+
const rules = JSON.parse(builtin_rules());
|
|
32
|
+
console.log(`${rules.length} rules`);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
Dual-licensed under MIT (../LICENSE-MIT) or Apache-2.0 (../LICENSE-APACHE), at your option.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Audits a JSON-serialized browser-agnostic `Document` IR and returns the
|
|
6
|
+
* `AuditReport` serialized as JSON.
|
|
7
|
+
*/
|
|
8
|
+
export function audit_document(doc_json: string, options_json?: string | null): string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Parses an HTML5 string and returns the `AuditReport` serialized as JSON.
|
|
12
|
+
*/
|
|
13
|
+
export function audit_html(html: string, options_json?: string | null): string;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Returns metadata for all 113 built-in rules serialized as a JSON array.
|
|
17
|
+
*/
|
|
18
|
+
export function builtin_rules(): string;
|
package/clearway_wasm.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* @ts-self-types="./clearway_wasm.d.ts" */
|
|
2
|
+
import * as wasm from "./clearway_wasm_bg.wasm";
|
|
3
|
+
import { __wbg_set_wasm } from "./clearway_wasm_bg.js";
|
|
4
|
+
|
|
5
|
+
__wbg_set_wasm(wasm);
|
|
6
|
+
wasm.__wbindgen_start();
|
|
7
|
+
export {
|
|
8
|
+
audit_document, audit_html, builtin_rules
|
|
9
|
+
} from "./clearway_wasm_bg.js";
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audits a JSON-serialized browser-agnostic `Document` IR and returns the
|
|
3
|
+
* `AuditReport` serialized as JSON.
|
|
4
|
+
* @param {string} doc_json
|
|
5
|
+
* @param {string | null} [options_json]
|
|
6
|
+
* @returns {string}
|
|
7
|
+
*/
|
|
8
|
+
export function audit_document(doc_json, options_json) {
|
|
9
|
+
let deferred4_0;
|
|
10
|
+
let deferred4_1;
|
|
11
|
+
try {
|
|
12
|
+
let ptr0, len0, ptr1, len1;
|
|
13
|
+
try {
|
|
14
|
+
ptr0 = passStringToWasm0(doc_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
15
|
+
len0 = WASM_VECTOR_LEN;
|
|
16
|
+
ptr1 = isLikeNone(options_json) ? 0 : passStringToWasm0(options_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
17
|
+
len1 = WASM_VECTOR_LEN;
|
|
18
|
+
} catch (e) {
|
|
19
|
+
if (ptr1) { wasm.__wbindgen_free(ptr1, len1 * 1, 1); }
|
|
20
|
+
if (ptr0) { wasm.__wbindgen_free(ptr0, len0 * 1, 1); }
|
|
21
|
+
throw e;
|
|
22
|
+
}
|
|
23
|
+
const ret = wasm.audit_document(ptr0, len0, ptr1, len1);
|
|
24
|
+
var ptr3 = ret[0];
|
|
25
|
+
var len3 = ret[1];
|
|
26
|
+
if (ret[3]) {
|
|
27
|
+
ptr3 = 0; len3 = 0;
|
|
28
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
29
|
+
}
|
|
30
|
+
deferred4_0 = ptr3;
|
|
31
|
+
deferred4_1 = len3;
|
|
32
|
+
return getStringFromWasm0(ptr3, len3);
|
|
33
|
+
} finally {
|
|
34
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Parses an HTML5 string and returns the `AuditReport` serialized as JSON.
|
|
40
|
+
* @param {string} html
|
|
41
|
+
* @param {string | null} [options_json]
|
|
42
|
+
* @returns {string}
|
|
43
|
+
*/
|
|
44
|
+
export function audit_html(html, options_json) {
|
|
45
|
+
let deferred4_0;
|
|
46
|
+
let deferred4_1;
|
|
47
|
+
try {
|
|
48
|
+
let ptr0, len0, ptr1, len1;
|
|
49
|
+
try {
|
|
50
|
+
ptr0 = passStringToWasm0(html, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
51
|
+
len0 = WASM_VECTOR_LEN;
|
|
52
|
+
ptr1 = isLikeNone(options_json) ? 0 : passStringToWasm0(options_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
53
|
+
len1 = WASM_VECTOR_LEN;
|
|
54
|
+
} catch (e) {
|
|
55
|
+
if (ptr1) { wasm.__wbindgen_free(ptr1, len1 * 1, 1); }
|
|
56
|
+
if (ptr0) { wasm.__wbindgen_free(ptr0, len0 * 1, 1); }
|
|
57
|
+
throw e;
|
|
58
|
+
}
|
|
59
|
+
const ret = wasm.audit_html(ptr0, len0, ptr1, len1);
|
|
60
|
+
var ptr3 = ret[0];
|
|
61
|
+
var len3 = ret[1];
|
|
62
|
+
if (ret[3]) {
|
|
63
|
+
ptr3 = 0; len3 = 0;
|
|
64
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
65
|
+
}
|
|
66
|
+
deferred4_0 = ptr3;
|
|
67
|
+
deferred4_1 = len3;
|
|
68
|
+
return getStringFromWasm0(ptr3, len3);
|
|
69
|
+
} finally {
|
|
70
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Returns metadata for all 113 built-in rules serialized as a JSON array.
|
|
76
|
+
* @returns {string}
|
|
77
|
+
*/
|
|
78
|
+
export function builtin_rules() {
|
|
79
|
+
let deferred2_0;
|
|
80
|
+
let deferred2_1;
|
|
81
|
+
try {
|
|
82
|
+
const ret = wasm.builtin_rules();
|
|
83
|
+
var ptr1 = ret[0];
|
|
84
|
+
var len1 = ret[1];
|
|
85
|
+
if (ret[3]) {
|
|
86
|
+
ptr1 = 0; len1 = 0;
|
|
87
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
88
|
+
}
|
|
89
|
+
deferred2_0 = ptr1;
|
|
90
|
+
deferred2_1 = len1;
|
|
91
|
+
return getStringFromWasm0(ptr1, len1);
|
|
92
|
+
} finally {
|
|
93
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
export function __wbindgen_generic_0000000000000001(arg0, arg1) {
|
|
97
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
98
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
99
|
+
return ret;
|
|
100
|
+
}
|
|
101
|
+
export function __wbindgen_init_externref_table() {
|
|
102
|
+
const table = wasm.__wbindgen_externrefs;
|
|
103
|
+
table.set(0, undefined);
|
|
104
|
+
table.set(1024, undefined);
|
|
105
|
+
table.set(1025, null);
|
|
106
|
+
table.set(1026, true);
|
|
107
|
+
table.set(1027, false);
|
|
108
|
+
}
|
|
109
|
+
function getStringFromWasm0(ptr, len) {
|
|
110
|
+
ptr = ptr >>> 0;
|
|
111
|
+
return decodeText(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let cachedUint8ArrayMemory0 = null;
|
|
115
|
+
function getUint8ArrayMemory0() {
|
|
116
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
117
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
118
|
+
}
|
|
119
|
+
return cachedUint8ArrayMemory0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function isLikeNone(x) {
|
|
123
|
+
return x === undefined || x === null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
127
|
+
if (realloc === undefined) {
|
|
128
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
129
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
130
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
131
|
+
WASM_VECTOR_LEN = buf.length;
|
|
132
|
+
return ptr;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
let len = arg.length;
|
|
136
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
137
|
+
|
|
138
|
+
const mem = getUint8ArrayMemory0();
|
|
139
|
+
|
|
140
|
+
let offset = 0;
|
|
141
|
+
|
|
142
|
+
for (; offset < len; offset++) {
|
|
143
|
+
const code = arg.charCodeAt(offset);
|
|
144
|
+
if (code > 0x7F) break;
|
|
145
|
+
mem[ptr + offset] = code;
|
|
146
|
+
}
|
|
147
|
+
if (offset !== len) {
|
|
148
|
+
if (offset !== 0) {
|
|
149
|
+
arg = arg.slice(offset);
|
|
150
|
+
}
|
|
151
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
152
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
153
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
154
|
+
|
|
155
|
+
offset += ret.written;
|
|
156
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
WASM_VECTOR_LEN = offset;
|
|
160
|
+
return ptr;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function takeFromExternrefTable0(idx) {
|
|
164
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
165
|
+
wasm.__externref_table_dealloc(idx);
|
|
166
|
+
return value;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
|
|
170
|
+
cachedTextDecoder.decode();
|
|
171
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
172
|
+
let numBytesDecoded = 0;
|
|
173
|
+
function decodeText(bytes) {
|
|
174
|
+
numBytesDecoded += bytes.length;
|
|
175
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
176
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
|
|
177
|
+
cachedTextDecoder.decode();
|
|
178
|
+
numBytesDecoded = bytes.length;
|
|
179
|
+
}
|
|
180
|
+
return cachedTextDecoder.decode(bytes);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const cachedTextEncoder = new TextEncoder();
|
|
184
|
+
|
|
185
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
186
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
187
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
188
|
+
view.set(buf);
|
|
189
|
+
return {
|
|
190
|
+
read: arg.length,
|
|
191
|
+
written: buf.length
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
let WASM_VECTOR_LEN = 0;
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
let wasm;
|
|
200
|
+
export function __wbg_set_wasm(val) {
|
|
201
|
+
wasm = val;
|
|
202
|
+
}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clearway-wasm",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "WebAssembly bindings for clearway, a fast pure-Rust accessibility engine.",
|
|
5
|
+
"version": "0.1.0",
|
|
6
|
+
"license": "MIT OR Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/TheGreatAxios/clearway"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"clearway_wasm_bg.wasm",
|
|
13
|
+
"clearway_wasm.js",
|
|
14
|
+
"clearway_wasm_bg.js",
|
|
15
|
+
"clearway_wasm.d.ts"
|
|
16
|
+
],
|
|
17
|
+
"main": "clearway_wasm.js",
|
|
18
|
+
"types": "clearway_wasm.d.ts",
|
|
19
|
+
"sideEffects": [
|
|
20
|
+
"./clearway_wasm.js",
|
|
21
|
+
"./snippets/*"
|
|
22
|
+
]
|
|
23
|
+
}
|