accent-proust 0.10.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/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2026 AccentX
4
+
5
+ Portions of this software are derived from Markdoc
6
+ (https://github.com/markdoc/markdoc), which is:
7
+
8
+ Copyright (c) 2021- Stripe, Inc. (https://stripe.com)
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,228 @@
1
+ # accent-proust
2
+
3
+ [Markdoc](https://markdoc.dev) for the browser: parse, validate, transform,
4
+ render and format, compiled to WebAssembly from
5
+ [a Rust implementation](https://github.com/zoosky/accent-proust) of the
6
+ language.
7
+
8
+ Markdoc is CommonMark plus a tag syntax that turns documents into structured,
9
+ validatable content instead of pre-rendered HTML:
10
+
11
+ ```markdown
12
+ {% callout type="note" %}
13
+ Tags nest, take typed attributes, and are validated against a schema.
14
+ {% /callout %}
15
+ ```
16
+
17
+ ## Install
18
+
19
+ ```sh
20
+ npm install accent-proust
21
+ ```
22
+
23
+ ## Use
24
+
25
+ The module is ESM and initialises once, before any other call.
26
+
27
+ ### In a browser
28
+
29
+ `init()` with no argument resolves the `.wasm` beside the JavaScript, so Vite,
30
+ native `<script type="module">` and a CDN all work unchanged.
31
+
32
+ ```js
33
+ import init, { validate, renderHtml, transform, format } from "accent-proust";
34
+
35
+ await init();
36
+
37
+ const source = "# Title {% #intro %}\n";
38
+
39
+ renderHtml(source); // '<article><h1 id="intro">Title </h1></article>'
40
+ validate(source); // []
41
+ format(source); // '# Title {% #intro %}\n'
42
+ transform(source); // the renderable tree, below
43
+ ```
44
+
45
+ Pass an explicit location when your bundler does not rewrite the default one:
46
+
47
+ ```js
48
+ import init from "accent-proust";
49
+ import wasm from "accent-proust/accent_proust_wasm_bg.wasm?url";
50
+
51
+ await init({ module_or_path: wasm });
52
+ ```
53
+
54
+ ### In Node
55
+
56
+ **`init()` with no argument does not work in Node.** The default location is a
57
+ `file:` URL, and Node's `fetch` rejects those — you get `TypeError: fetch
58
+ failed`. Read the file and hand it over:
59
+
60
+ ```js
61
+ import { readFileSync } from "node:fs";
62
+ import { fileURLToPath } from "node:url";
63
+ import init, { renderHtml } from "accent-proust";
64
+
65
+ const wasm = fileURLToPath(
66
+ import.meta.resolve("accent-proust/accent_proust_wasm_bg.wasm")
67
+ );
68
+ await init({ module_or_path: readFileSync(wasm) });
69
+
70
+ renderHtml("# Title\n"); // '<article><h1>Title</h1></article>'
71
+ ```
72
+
73
+ This package ships the browser build only. A `nodejs` build, which would make
74
+ `init()` work unaided, is additive and not here yet.
75
+
76
+ ## The four entry points
77
+
78
+ Each takes the document source and parses from scratch. Nothing is cached
79
+ between calls and no value holds a reference into WebAssembly memory, so there
80
+ is nothing to free.
81
+
82
+ ### `renderHtml(source): string`
83
+
84
+ The whole pipeline. A document with validation errors still renders, because a
85
+ preview pane that blanks on the first mistake is worse than one that shows it.
86
+
87
+ ### `validate(source): ValidateError[]`
88
+
89
+ Diagnostics, empty when the document is clean. The `error.id` is Markdoc's own
90
+ id unchanged — it is what external tooling binds to.
91
+
92
+ ```js
93
+ validate("{% callout %}\n{% /callout %}\n");
94
+ // [{
95
+ // type: "tag",
96
+ // lines: [0, 1, 1, 2],
97
+ // location: { start: {...}, end: {...} },
98
+ // error: {
99
+ // id: "tag-undefined",
100
+ // level: "critical",
101
+ // message: "Undefined tag: 'callout'"
102
+ // }
103
+ // }]
104
+ ```
105
+
106
+ Positions are counted in **UTF-16 code units** -- what JavaScript means by a
107
+ string index, and what a CodeMirror position, a Monaco position and an LSP
108
+ `character` all are. The engine measures UTF-8 bytes internally and the
109
+ conversion happens before the value crosses the boundary, so a position can go
110
+ straight into an editor with no arithmetic:
111
+
112
+ ```js
113
+ const { start, end } = validate(source)[0].location;
114
+ view.dispatch({ selection: { anchor: start.offset, head: end.offset } });
115
+ ```
116
+
117
+ Each edge carries four fields. `line` is zero-based. `character` is code units
118
+ from the start of the line. `offset` is code units from the start of the
119
+ document, so it is usable as a position directly. `byteOffset` is the engine's
120
+ own unit, for a host that wants to index back into the source as bytes; it is
121
+ the only field that is not code units, and it is named so that it cannot be
122
+ mistaken for one.
123
+
124
+ ### `transform(source): RenderableTreeNode[]`
125
+
126
+ The renderable tree, for a host that owns its own markup. A tag is an object
127
+ carrying `$$mdtype: "Tag"`, exactly as `@markdoc/markdoc` produces, so a React
128
+ or Vue renderer written against Markdoc maps tag names onto components without
129
+ changes:
130
+
131
+ ```js
132
+ transform("# Title {% #intro %}\n");
133
+ // [{ $$mdtype: "Tag", name: "article", attributes: {}, children:
134
+ // [{ $$mdtype: "Tag", name: "h1", attributes: { id: "intro" },
135
+ // children: ["Title "] }] }]
136
+ ```
137
+
138
+ Anything that is not a tag is the scalar it renders to; a text node is a plain
139
+ string.
140
+
141
+ ### `format(source): string`
142
+
143
+ Canonical Markdoc source. `format(format(s)) === format(s)`, and a formatted
144
+ document parses to the document the original parsed to, so an editor can
145
+ rewrite a buffer in place without losing anything.
146
+
147
+ ## Your own tags
148
+
149
+ The four functions above use Markdoc's built-in configuration, so a tag your
150
+ host defines reports `tag-undefined`. Build a `Config` once and call the same
151
+ stages on it:
152
+
153
+ ```js
154
+ import init, { Config } from "accent-proust";
155
+ await init();
156
+
157
+ const config = new Config({
158
+ tags: {
159
+ callout: {
160
+ render: "Callout",
161
+ attributes: {
162
+ type: { type: "String", default: "note", matches: ["note", "warning"] },
163
+ title: { type: "String", required: true },
164
+ },
165
+ },
166
+ },
167
+ variables: { flags: { beta: true } },
168
+ });
169
+
170
+ config.validate(source); // knows `callout`, checks its attributes
171
+ config.renderHtml(source);
172
+ config.transform(source);
173
+ ```
174
+
175
+ Declarations merge over the built-ins, so `{% if %}` and `{% partial %}` keep
176
+ working. Construction does the parsing and checking once; the methods then cost
177
+ what the free functions cost, which is what an editor revalidating on every
178
+ keystroke needs. Call `config.free()` when you are done with it.
179
+
180
+ `nodes` takes the same shape as `tags`, keyed by Markdoc node type, so you can
181
+ change what a `heading` renders as.
182
+
183
+ ### What crosses, and what does not
184
+
185
+ A schema is data and crosses whole: `render`, `children`, `attributes`,
186
+ `slots`, `selfClosing`, `inline`, `description`, and on an attribute `type`,
187
+ `default`, `required`, `matches`, `render`, `errorLevel`.
188
+
189
+ Attribute types are written as the strings `"String"`, `"Number"`, `"Boolean"`,
190
+ `"Object"`, `"Array"`. Markdoc uses the JavaScript constructors, and a
191
+ constructor is a function. An array of them is a union.
192
+
193
+ A hook is code, and code does not cross: `transform`, `validate`, a custom
194
+ attribute type, a `RegExp` in `matches`, and host-defined `functions`. **So the
195
+ browser is never stricter than your server, only faster.** Keep the server as
196
+ the authority; this is an early warning.
197
+
198
+ Nothing is dropped in silence. A configuration carrying something that cannot
199
+ cross is refused, naming the path to it:
200
+
201
+ ```
202
+ config.tags.callout.attributes.type.type: unknown attribute type "Str";
203
+ expected String, Number, Boolean, Object, Array, or an array of those
204
+ ```
205
+
206
+ A schema that half arrives is worse than one that does not, because the missing
207
+ half is invisible until an author trips over it.
208
+
209
+ ## Not supported yet
210
+
211
+ Partials, and host-defined functions. A parsed partial borrows its source, so
212
+ holding both across the boundary needs a design this does not have. Both are
213
+ refused by name rather than ignored.
214
+
215
+ `parse` is not exposed either: the abstract syntax tree has no JavaScript shape
216
+ here yet. `validate` and `transform` cover what a preview and a custom renderer
217
+ need.
218
+
219
+ ## Differences from `@markdoc/markdoc`
220
+
221
+ The tag language and the validation error ids are the contract and are
222
+ reproduced exactly. CommonMark edge behaviour is not: Markdoc is built on
223
+ markdown-it and this is built on pulldown-cmark. Every deliberate difference is
224
+ recorded in [`DIVERGENCES.md`](https://github.com/zoosky/accent-proust/blob/main/DIVERGENCES.md).
225
+
226
+ ## License
227
+
228
+ MIT
@@ -0,0 +1,132 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * A host's schema configuration, built once and reused.
6
+ *
7
+ * Constructing this parses and checks the declarations; the stage methods on
8
+ * it then cost no more than the free functions do. That matters for the
9
+ * surface this exists for -- an editor revalidating on every keystroke should
10
+ * not re-read a schema registry each time.
11
+ *
12
+ * Call `free()` when done, as with any wasm-bindgen object.
13
+ */
14
+ export class Config {
15
+ free(): void;
16
+ [Symbol.dispose](): void;
17
+ /**
18
+ * Build a configuration from a host's declarations.
19
+ *
20
+ * Declarations merge over Markdoc's built-ins. `null` or `undefined`
21
+ * gives the built-ins alone, which is what the free functions use.
22
+ *
23
+ * # Errors
24
+ *
25
+ * Throws with the path to the first problem -- `config.tags.callout.
26
+ * attributes.type.type`, not "invalid schema". A configuration is a
27
+ * document a person wrote, so the path is the actionable half.
28
+ */
29
+ constructor(declarations: any);
30
+ /**
31
+ * Render a Markdoc document to HTML against this configuration.
32
+ *
33
+ * See [`render_html`], which this is the configured form of.
34
+ */
35
+ renderHtml(source: string): string;
36
+ /**
37
+ * Transform a Markdoc document into a renderable tree against this
38
+ * configuration.
39
+ *
40
+ * See [`transform`], which this is the configured form of.
41
+ */
42
+ transform(source: string): Array<any>;
43
+ /**
44
+ * Validate a Markdoc document against this configuration.
45
+ *
46
+ * See [`validate`], which this is the configured form of. A tag the
47
+ * configuration declares no longer reports `tag-undefined`; its attributes
48
+ * are checked against what it declares.
49
+ */
50
+ validate(source: string): Array<any>;
51
+ }
52
+
53
+ /**
54
+ * Format a Markdoc document as canonical Markdoc source.
55
+ *
56
+ * `format(format(s)) === format(s)`, and the document a formatted source
57
+ * parses to is the document the original parsed to, so an editor can rewrite
58
+ * a buffer in place without losing anything.
59
+ */
60
+ export function format(source: string): string;
61
+
62
+ /**
63
+ * Render a Markdoc document to HTML.
64
+ *
65
+ * This is the whole pipeline: parse, transform against the built-in
66
+ * configuration, then render. Validation errors do not stop it, because
67
+ * upstream renders a document that has them and a preview pane that blanks on
68
+ * the first mistake is worse than one that shows the mistake.
69
+ */
70
+ export function renderHtml(source: string): string;
71
+
72
+ /**
73
+ * Transform a Markdoc document into a renderable tree.
74
+ *
75
+ * Returns an array of upstream's `RenderableTreeNode`: a tag is an object
76
+ * carrying `$$mdtype: "Tag"`, and anything else is the scalar it renders to.
77
+ * Use this rather than [`render_html`] when the host owns the markup -- a
78
+ * React or Vue renderer maps tag names onto its own components from this tree.
79
+ */
80
+ export function transform(source: string): Array<any>;
81
+
82
+ /**
83
+ * Validate a Markdoc document.
84
+ *
85
+ * Returns an array of upstream's `ValidateError`, empty when the document is
86
+ * clean. The `error.id` of each is upstream's id unchanged: it is the field
87
+ * external tooling binds to, so it is the field this crate is least free to
88
+ * invent.
89
+ */
90
+ export function validate(source: string): Array<any>;
91
+
92
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
93
+
94
+ export interface InitOutput {
95
+ readonly memory: WebAssembly.Memory;
96
+ readonly __wbg_config_free: (a: number, b: number) => void;
97
+ readonly config_new: (a: number, b: number) => void;
98
+ readonly config_renderHtml: (a: number, b: number, c: number, d: number) => void;
99
+ readonly config_transform: (a: number, b: number, c: number) => number;
100
+ readonly config_validate: (a: number, b: number, c: number) => number;
101
+ readonly format: (a: number, b: number, c: number) => void;
102
+ readonly renderHtml: (a: number, b: number, c: number) => void;
103
+ readonly transform: (a: number, b: number) => number;
104
+ readonly validate: (a: number, b: number) => number;
105
+ readonly __wbindgen_export: (a: number, b: number) => number;
106
+ readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
107
+ readonly __wbindgen_export3: (a: number) => void;
108
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
109
+ readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
110
+ }
111
+
112
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
113
+
114
+ /**
115
+ * Instantiates the given `module`, which can either be bytes or
116
+ * a precompiled `WebAssembly.Module`.
117
+ *
118
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
119
+ *
120
+ * @returns {InitOutput}
121
+ */
122
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
123
+
124
+ /**
125
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
126
+ * for everything else, calls `WebAssembly.instantiate` directly.
127
+ *
128
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
129
+ *
130
+ * @returns {Promise<InitOutput>}
131
+ */
132
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,561 @@
1
+ /* @ts-self-types="./accent_proust_wasm.d.ts" */
2
+
3
+ /**
4
+ * A host's schema configuration, built once and reused.
5
+ *
6
+ * Constructing this parses and checks the declarations; the stage methods on
7
+ * it then cost no more than the free functions do. That matters for the
8
+ * surface this exists for -- an editor revalidating on every keystroke should
9
+ * not re-read a schema registry each time.
10
+ *
11
+ * Call `free()` when done, as with any wasm-bindgen object.
12
+ */
13
+ export class Config {
14
+ __destroy_into_raw() {
15
+ const ptr = this.__wbg_ptr;
16
+ this.__wbg_ptr = 0;
17
+ ConfigFinalization.unregister(this);
18
+ return ptr;
19
+ }
20
+ free() {
21
+ const ptr = this.__destroy_into_raw();
22
+ wasm.__wbg_config_free(ptr, 0);
23
+ }
24
+ /**
25
+ * Build a configuration from a host's declarations.
26
+ *
27
+ * Declarations merge over Markdoc's built-ins. `null` or `undefined`
28
+ * gives the built-ins alone, which is what the free functions use.
29
+ *
30
+ * # Errors
31
+ *
32
+ * Throws with the path to the first problem -- `config.tags.callout.
33
+ * attributes.type.type`, not "invalid schema". A configuration is a
34
+ * document a person wrote, so the path is the actionable half.
35
+ * @param {any} declarations
36
+ */
37
+ constructor(declarations) {
38
+ try {
39
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
40
+ wasm.config_new(retptr, addBorrowedObject(declarations));
41
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
42
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
43
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
44
+ if (r2) {
45
+ throw takeObject(r1);
46
+ }
47
+ this.__wbg_ptr = r0;
48
+ ConfigFinalization.register(this, this.__wbg_ptr, this);
49
+ return this;
50
+ } finally {
51
+ wasm.__wbindgen_add_to_stack_pointer(16);
52
+ heap[stack_pointer++] = undefined;
53
+ }
54
+ }
55
+ /**
56
+ * Render a Markdoc document to HTML against this configuration.
57
+ *
58
+ * See [`render_html`], which this is the configured form of.
59
+ * @param {string} source
60
+ * @returns {string}
61
+ */
62
+ renderHtml(source) {
63
+ let deferred2_0;
64
+ let deferred2_1;
65
+ try {
66
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
67
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
68
+ const len0 = WASM_VECTOR_LEN;
69
+ wasm.config_renderHtml(retptr, this.__wbg_ptr, ptr0, len0);
70
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
71
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
72
+ deferred2_0 = r0;
73
+ deferred2_1 = r1;
74
+ return getStringFromWasm0(r0, r1);
75
+ } finally {
76
+ wasm.__wbindgen_add_to_stack_pointer(16);
77
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
78
+ }
79
+ }
80
+ /**
81
+ * Transform a Markdoc document into a renderable tree against this
82
+ * configuration.
83
+ *
84
+ * See [`transform`], which this is the configured form of.
85
+ * @param {string} source
86
+ * @returns {Array<any>}
87
+ */
88
+ transform(source) {
89
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
90
+ const len0 = WASM_VECTOR_LEN;
91
+ const ret = wasm.config_transform(this.__wbg_ptr, ptr0, len0);
92
+ return takeObject(ret);
93
+ }
94
+ /**
95
+ * Validate a Markdoc document against this configuration.
96
+ *
97
+ * See [`validate`], which this is the configured form of. A tag the
98
+ * configuration declares no longer reports `tag-undefined`; its attributes
99
+ * are checked against what it declares.
100
+ * @param {string} source
101
+ * @returns {Array<any>}
102
+ */
103
+ validate(source) {
104
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
105
+ const len0 = WASM_VECTOR_LEN;
106
+ const ret = wasm.config_validate(this.__wbg_ptr, ptr0, len0);
107
+ return takeObject(ret);
108
+ }
109
+ }
110
+ if (Symbol.dispose) Config.prototype[Symbol.dispose] = Config.prototype.free;
111
+
112
+ /**
113
+ * Format a Markdoc document as canonical Markdoc source.
114
+ *
115
+ * `format(format(s)) === format(s)`, and the document a formatted source
116
+ * parses to is the document the original parsed to, so an editor can rewrite
117
+ * a buffer in place without losing anything.
118
+ * @param {string} source
119
+ * @returns {string}
120
+ */
121
+ export function format(source) {
122
+ let deferred2_0;
123
+ let deferred2_1;
124
+ try {
125
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
126
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
127
+ const len0 = WASM_VECTOR_LEN;
128
+ wasm.format(retptr, ptr0, len0);
129
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
130
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
131
+ deferred2_0 = r0;
132
+ deferred2_1 = r1;
133
+ return getStringFromWasm0(r0, r1);
134
+ } finally {
135
+ wasm.__wbindgen_add_to_stack_pointer(16);
136
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
137
+ }
138
+ }
139
+
140
+ /**
141
+ * Render a Markdoc document to HTML.
142
+ *
143
+ * This is the whole pipeline: parse, transform against the built-in
144
+ * configuration, then render. Validation errors do not stop it, because
145
+ * upstream renders a document that has them and a preview pane that blanks on
146
+ * the first mistake is worse than one that shows the mistake.
147
+ * @param {string} source
148
+ * @returns {string}
149
+ */
150
+ export function renderHtml(source) {
151
+ let deferred2_0;
152
+ let deferred2_1;
153
+ try {
154
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
155
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
156
+ const len0 = WASM_VECTOR_LEN;
157
+ wasm.renderHtml(retptr, ptr0, len0);
158
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
159
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
160
+ deferred2_0 = r0;
161
+ deferred2_1 = r1;
162
+ return getStringFromWasm0(r0, r1);
163
+ } finally {
164
+ wasm.__wbindgen_add_to_stack_pointer(16);
165
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
166
+ }
167
+ }
168
+
169
+ /**
170
+ * Transform a Markdoc document into a renderable tree.
171
+ *
172
+ * Returns an array of upstream's `RenderableTreeNode`: a tag is an object
173
+ * carrying `$$mdtype: "Tag"`, and anything else is the scalar it renders to.
174
+ * Use this rather than [`render_html`] when the host owns the markup -- a
175
+ * React or Vue renderer maps tag names onto its own components from this tree.
176
+ * @param {string} source
177
+ * @returns {Array<any>}
178
+ */
179
+ export function transform(source) {
180
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
181
+ const len0 = WASM_VECTOR_LEN;
182
+ const ret = wasm.transform(ptr0, len0);
183
+ return takeObject(ret);
184
+ }
185
+
186
+ /**
187
+ * Validate a Markdoc document.
188
+ *
189
+ * Returns an array of upstream's `ValidateError`, empty when the document is
190
+ * clean. The `error.id` of each is upstream's id unchanged: it is the field
191
+ * external tooling binds to, so it is the field this crate is least free to
192
+ * invent.
193
+ * @param {string} source
194
+ * @returns {Array<any>}
195
+ */
196
+ export function validate(source) {
197
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
198
+ const len0 = WASM_VECTOR_LEN;
199
+ const ret = wasm.validate(ptr0, len0);
200
+ return takeObject(ret);
201
+ }
202
+ function __wbg_get_imports() {
203
+ const import0 = {
204
+ __proto__: null,
205
+ __wbg___wbindgen_boolean_get_7a12af2b3f899c5a: function(arg0) {
206
+ const v = getObject(arg0);
207
+ const ret = typeof(v) === 'boolean' ? v : undefined;
208
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
209
+ },
210
+ __wbg___wbindgen_is_bigint_60fc0336cb14f5d7: function(arg0) {
211
+ const ret = typeof(getObject(arg0)) === 'bigint';
212
+ return ret;
213
+ },
214
+ __wbg___wbindgen_is_function_fcda5e3902d732fe: function(arg0) {
215
+ const ret = typeof(getObject(arg0)) === 'function';
216
+ return ret;
217
+ },
218
+ __wbg___wbindgen_is_null_5160b3e381865372: function(arg0) {
219
+ const ret = getObject(arg0) === null;
220
+ return ret;
221
+ },
222
+ __wbg___wbindgen_is_object_edb6b15aa3afe12e: function(arg0) {
223
+ const val = getObject(arg0);
224
+ const ret = typeof(val) === 'object' && val !== null;
225
+ return ret;
226
+ },
227
+ __wbg___wbindgen_is_symbol_d2cecf3ba20e3e5e: function(arg0) {
228
+ const ret = typeof(getObject(arg0)) === 'symbol';
229
+ return ret;
230
+ },
231
+ __wbg___wbindgen_is_undefined_8c687d0b90d5b524: function(arg0) {
232
+ const ret = getObject(arg0) === undefined;
233
+ return ret;
234
+ },
235
+ __wbg___wbindgen_number_get_1dc732b810cb937c: function(arg0, arg1) {
236
+ const obj = getObject(arg1);
237
+ const ret = typeof(obj) === 'number' ? obj : undefined;
238
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
239
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
240
+ },
241
+ __wbg___wbindgen_string_get_92ab86bb19cbc12f: function(arg0, arg1) {
242
+ const obj = getObject(arg1);
243
+ const ret = typeof(obj) === 'string' ? obj : undefined;
244
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
245
+ var len1 = WASM_VECTOR_LEN;
246
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
247
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
248
+ },
249
+ __wbg___wbindgen_throw_5d9e815e6fdf150f: function(arg0, arg1) {
250
+ throw new Error(getStringFromWasm0(arg0, arg1));
251
+ },
252
+ __wbg_from_a39669ce566077da: function(arg0) {
253
+ const ret = Array.from(getObject(arg0));
254
+ return addHeapObject(ret);
255
+ },
256
+ __wbg_getPrototypeOf_5c4b9dbbf25290de: function(arg0) {
257
+ const ret = Object.getPrototypeOf(getObject(arg0));
258
+ return addHeapObject(ret);
259
+ },
260
+ __wbg_get_989d0a1309644f2b: function() { return handleError(function (arg0, arg1) {
261
+ const ret = Reflect.get(getObject(arg0), getObject(arg1));
262
+ return addHeapObject(ret);
263
+ }, arguments); },
264
+ __wbg_get_b1f0ab13c737f856: function(arg0, arg1) {
265
+ const ret = getObject(arg0)[arg1 >>> 0];
266
+ return addHeapObject(ret);
267
+ },
268
+ __wbg_get_unchecked_363572bdd397d473: function(arg0, arg1) {
269
+ const ret = getObject(arg0)[arg1 >>> 0];
270
+ return addHeapObject(ret);
271
+ },
272
+ __wbg_isArray_5674713bb7b79043: function(arg0) {
273
+ const ret = Array.isArray(getObject(arg0));
274
+ return ret;
275
+ },
276
+ __wbg_keys_6efc298980178da1: function(arg0) {
277
+ const ret = Object.keys(getObject(arg0));
278
+ return addHeapObject(ret);
279
+ },
280
+ __wbg_length_4e1adc0d42e23620: function(arg0) {
281
+ const ret = getObject(arg0).length;
282
+ return ret;
283
+ },
284
+ __wbg_new_a32a1ab6c6655abe: function(arg0, arg1) {
285
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
286
+ return addHeapObject(ret);
287
+ },
288
+ __wbg_new_bebc3f4757acf305: function() {
289
+ const ret = new Object();
290
+ return addHeapObject(ret);
291
+ },
292
+ __wbg_new_ffa92086ea89f79c: function() {
293
+ const ret = new Array();
294
+ return addHeapObject(ret);
295
+ },
296
+ __wbg_push_bfdf956ba476f65b: function(arg0, arg1) {
297
+ const ret = getObject(arg0).push(getObject(arg1));
298
+ return ret;
299
+ },
300
+ __wbg_set_a377297433dfea63: function() { return handleError(function (arg0, arg1, arg2) {
301
+ const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
302
+ return ret;
303
+ }, arguments); },
304
+ __wbindgen_generic_0000000000000001: function(arg0) {
305
+ // Cast intrinsic for `F64 -> Externref`.
306
+ const ret = arg0;
307
+ return addHeapObject(ret);
308
+ },
309
+ __wbindgen_generic_0000000000000002: function(arg0, arg1) {
310
+ // Cast intrinsic for `Ref(String) -> Externref`.
311
+ const ret = getStringFromWasm0(arg0, arg1);
312
+ return addHeapObject(ret);
313
+ },
314
+ __wbindgen_object_clone_ref: function(arg0) {
315
+ const ret = getObject(arg0);
316
+ return addHeapObject(ret);
317
+ },
318
+ __wbindgen_object_drop_ref: function(arg0) {
319
+ takeObject(arg0);
320
+ },
321
+ };
322
+ return {
323
+ __proto__: null,
324
+ "./accent_proust_wasm_bg.js": import0,
325
+ };
326
+ }
327
+
328
+ const ConfigFinalization = (typeof FinalizationRegistry === 'undefined')
329
+ ? { register: () => {}, unregister: () => {} }
330
+ : new FinalizationRegistry(ptr => wasm.__wbg_config_free(ptr, 1));
331
+
332
+ function addHeapObject(obj) {
333
+ if (heap_next === heap.length) heap.push(heap.length + 1);
334
+ const idx = heap_next;
335
+ heap_next = heap[idx];
336
+
337
+ heap[idx] = obj;
338
+ return idx;
339
+ }
340
+
341
+ function addBorrowedObject(obj) {
342
+ if (stack_pointer == 1) throw new Error('out of js stack');
343
+ heap[--stack_pointer] = obj;
344
+ return stack_pointer;
345
+ }
346
+
347
+ function dropObject(idx) {
348
+ if (idx < 1028) return;
349
+ heap[idx] = heap_next;
350
+ heap_next = idx;
351
+ }
352
+
353
+ let cachedDataViewMemory0 = null;
354
+ function getDataViewMemory0() {
355
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
356
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
357
+ }
358
+ return cachedDataViewMemory0;
359
+ }
360
+
361
+ function getStringFromWasm0(ptr, len) {
362
+ return decodeText(ptr >>> 0, len);
363
+ }
364
+
365
+ let cachedUint8ArrayMemory0 = null;
366
+ function getUint8ArrayMemory0() {
367
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
368
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
369
+ }
370
+ return cachedUint8ArrayMemory0;
371
+ }
372
+
373
+ function getObject(idx) { return heap[idx]; }
374
+
375
+ function handleError(f, args) {
376
+ try {
377
+ return f.apply(this, args);
378
+ } catch (e) {
379
+ wasm.__wbindgen_export3(addHeapObject(e));
380
+ }
381
+ }
382
+
383
+ let heap = new Array(1024).fill(undefined);
384
+ heap.push(undefined, null, true, false);
385
+
386
+ let heap_next = heap.length;
387
+
388
+ function isLikeNone(x) {
389
+ return x === undefined || x === null;
390
+ }
391
+
392
+ function passStringToWasm0(arg, malloc, realloc) {
393
+ if (realloc === undefined) {
394
+ const buf = cachedTextEncoder.encode(arg);
395
+ const ptr = malloc(buf.length, 1) >>> 0;
396
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
397
+ WASM_VECTOR_LEN = buf.length;
398
+ return ptr;
399
+ }
400
+
401
+ let len = arg.length;
402
+ let ptr = malloc(len, 1) >>> 0;
403
+
404
+ const mem = getUint8ArrayMemory0();
405
+
406
+ let offset = 0;
407
+
408
+ for (; offset < len; offset++) {
409
+ const code = arg.charCodeAt(offset);
410
+ if (code > 0x7F) break;
411
+ mem[ptr + offset] = code;
412
+ }
413
+ if (offset !== len) {
414
+ if (offset !== 0) {
415
+ arg = arg.slice(offset);
416
+ }
417
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
418
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
419
+ const ret = cachedTextEncoder.encodeInto(arg, view);
420
+
421
+ offset += ret.written;
422
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
423
+ }
424
+
425
+ WASM_VECTOR_LEN = offset;
426
+ return ptr;
427
+ }
428
+
429
+ let stack_pointer = 1024;
430
+
431
+ function takeObject(idx) {
432
+ const ret = getObject(idx);
433
+ dropObject(idx);
434
+ return ret;
435
+ }
436
+
437
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
438
+ cachedTextDecoder.decode();
439
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
440
+ let numBytesDecoded = 0;
441
+ function decodeText(ptr, len) {
442
+ numBytesDecoded += len;
443
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
444
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
445
+ cachedTextDecoder.decode();
446
+ numBytesDecoded = len;
447
+ }
448
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
449
+ }
450
+
451
+ const cachedTextEncoder = new TextEncoder();
452
+
453
+ if (!('encodeInto' in cachedTextEncoder)) {
454
+ cachedTextEncoder.encodeInto = function (arg, view) {
455
+ const buf = cachedTextEncoder.encode(arg);
456
+ view.set(buf);
457
+ return {
458
+ read: arg.length,
459
+ written: buf.length
460
+ };
461
+ };
462
+ }
463
+
464
+ let WASM_VECTOR_LEN = 0;
465
+
466
+ let wasmModule, wasmInstance, wasm;
467
+ function __wbg_finalize_init(instance, module) {
468
+ wasmInstance = instance;
469
+ wasm = instance.exports;
470
+ wasmModule = module;
471
+ cachedDataViewMemory0 = null;
472
+ cachedUint8ArrayMemory0 = null;
473
+ return wasm;
474
+ }
475
+
476
+ async function __wbg_load(module, imports) {
477
+ if (typeof Response === 'function' && module instanceof Response) {
478
+ if (!module.ok) {
479
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
480
+ }
481
+
482
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
483
+ try {
484
+ return await WebAssembly.instantiateStreaming(module, imports);
485
+ } catch (e) {
486
+ const validResponse = expectedResponseType(module.type);
487
+
488
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
489
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
490
+
491
+ } else { throw e; }
492
+ }
493
+ }
494
+
495
+ const bytes = await module.arrayBuffer();
496
+ return await WebAssembly.instantiate(bytes, imports);
497
+ } else {
498
+ const instance = await WebAssembly.instantiate(module, imports);
499
+
500
+ if (instance instanceof WebAssembly.Instance) {
501
+ return { instance, module };
502
+ } else {
503
+ return instance;
504
+ }
505
+ }
506
+
507
+ function expectedResponseType(type) {
508
+ switch (type) {
509
+ case 'basic': case 'cors': case 'default': return true;
510
+ }
511
+ return false;
512
+ }
513
+ }
514
+
515
+ function initSync(module) {
516
+ if (wasm !== undefined) return wasm;
517
+
518
+
519
+ if (module !== undefined) {
520
+ if (Object.getPrototypeOf(module) === Object.prototype) {
521
+ ({module} = module)
522
+ } else {
523
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
524
+ }
525
+ }
526
+
527
+ const imports = __wbg_get_imports();
528
+ if (!(module instanceof WebAssembly.Module)) {
529
+ module = new WebAssembly.Module(module);
530
+ }
531
+ const instance = new WebAssembly.Instance(module, imports);
532
+ return __wbg_finalize_init(instance, module);
533
+ }
534
+
535
+ async function __wbg_init(module_or_path) {
536
+ if (wasm !== undefined) return wasm;
537
+
538
+
539
+ if (module_or_path !== undefined) {
540
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
541
+ ({module_or_path} = module_or_path)
542
+ } else {
543
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
544
+ }
545
+ }
546
+
547
+ if (module_or_path === undefined) {
548
+ module_or_path = new URL('accent_proust_wasm_bg.wasm', import.meta.url);
549
+ }
550
+ const imports = __wbg_get_imports();
551
+
552
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
553
+ module_or_path = fetch(module_or_path);
554
+ }
555
+
556
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
557
+
558
+ return __wbg_finalize_init(instance, module);
559
+ }
560
+
561
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,17 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_config_free: (a: number, b: number) => void;
5
+ export const config_new: (a: number, b: number) => void;
6
+ export const config_renderHtml: (a: number, b: number, c: number, d: number) => void;
7
+ export const config_transform: (a: number, b: number, c: number) => number;
8
+ export const config_validate: (a: number, b: number, c: number) => number;
9
+ export const format: (a: number, b: number, c: number) => void;
10
+ export const renderHtml: (a: number, b: number, c: number) => void;
11
+ export const transform: (a: number, b: number) => number;
12
+ export const validate: (a: number, b: number) => number;
13
+ export const __wbindgen_export: (a: number, b: number) => number;
14
+ export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
15
+ export const __wbindgen_export3: (a: number) => void;
16
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
17
+ export const __wbindgen_export4: (a: number, b: number, c: number) => void;
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "accent-proust",
3
+ "version": "0.10.0",
4
+ "description": "Markdoc for the browser: parse, validate, transform, render and format, compiled to WebAssembly from Rust.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/zoosky/accent-proust.git"
9
+ },
10
+ "homepage": "https://github.com/zoosky/accent-proust",
11
+ "keywords": [
12
+ "markdoc",
13
+ "markdown",
14
+ "commonmark",
15
+ "wasm",
16
+ "webassembly"
17
+ ],
18
+ "type": "module",
19
+ "module": "accent_proust_wasm.js",
20
+ "types": "accent_proust_wasm.d.ts",
21
+ "sideEffects": false,
22
+ "exports": {
23
+ ".": {
24
+ "types": "./accent_proust_wasm.d.ts",
25
+ "default": "./accent_proust_wasm.js"
26
+ },
27
+ "./accent_proust_wasm_bg.wasm": "./accent_proust_wasm_bg.wasm"
28
+ },
29
+ "files": [
30
+ "accent_proust_wasm.js",
31
+ "accent_proust_wasm.d.ts",
32
+ "accent_proust_wasm_bg.wasm",
33
+ "accent_proust_wasm_bg.wasm.d.ts",
34
+ "README.md",
35
+ "LICENSE"
36
+ ]
37
+ }