flux-md 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +72 -0
- package/LICENSE +21 -0
- package/README.md +398 -0
- package/package.json +50 -0
- package/src/client.ts +315 -0
- package/src/hi.ts +244 -0
- package/src/html-to-react.ts +282 -0
- package/src/index.ts +33 -0
- package/src/react.tsx +223 -0
- package/src/renderers/CodeBlock.tsx +62 -0
- package/src/renderers/Math.tsx +26 -0
- package/src/renderers/Mermaid.tsx +26 -0
- package/src/types.ts +130 -0
- package/src/wasm/flux_md_core.d.ts +94 -0
- package/src/wasm/flux_md_core.js +399 -0
- package/src/wasm/flux_md_core_bg.wasm +0 -0
- package/src/wasm/flux_md_core_bg.wasm.d.ts +18 -0
- package/src/wasm/package.json +17 -0
- package/src/worker.ts +151 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export type BlockKindTag =
|
|
2
|
+
| "Paragraph"
|
|
3
|
+
| "Heading"
|
|
4
|
+
| "CodeBlock"
|
|
5
|
+
| "MathBlock"
|
|
6
|
+
| "Mermaid"
|
|
7
|
+
| "List"
|
|
8
|
+
| "Blockquote"
|
|
9
|
+
| "Alert"
|
|
10
|
+
| "Table"
|
|
11
|
+
| "Rule"
|
|
12
|
+
| "Html";
|
|
13
|
+
|
|
14
|
+
export interface BlockKind {
|
|
15
|
+
type: BlockKindTag;
|
|
16
|
+
data?: unknown;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface Block {
|
|
20
|
+
id: number;
|
|
21
|
+
kind: BlockKind;
|
|
22
|
+
start: number;
|
|
23
|
+
end: number;
|
|
24
|
+
html: string;
|
|
25
|
+
open: boolean;
|
|
26
|
+
speculative: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface Patch {
|
|
30
|
+
newly_committed: Block[];
|
|
31
|
+
active: Block[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
import type { ComponentType } from "react";
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Override map for {@link FluxMarkdown}. Keys are either lowercase HTML tag
|
|
38
|
+
* names (`table`, `a`, `code`, `h1`… — react-markdown style, applied inside a
|
|
39
|
+
* block's HTML) or capitalized block-kind names ({@link BlockKindTag}, e.g.
|
|
40
|
+
* `CodeBlock`, `Table` — replace the whole block renderer). Values are a React
|
|
41
|
+
* component or an HTML tag string.
|
|
42
|
+
*
|
|
43
|
+
* Tag-level components receive the element's parsed attributes (with
|
|
44
|
+
* `class`→`className`, `style` as an object) plus `children`. Block-kind
|
|
45
|
+
* components receive {@link BlockComponentProps}. There is no `node` prop.
|
|
46
|
+
*/
|
|
47
|
+
export type Components = Record<string, ComponentType<any> | string>;
|
|
48
|
+
|
|
49
|
+
/** Props passed to a block-kind override (e.g. `components.CodeBlock`). */
|
|
50
|
+
export interface BlockComponentProps {
|
|
51
|
+
/** The full parsed block, including `kind` (with `kind.data`) and offsets. */
|
|
52
|
+
block: Block;
|
|
53
|
+
/** Rendered, XSS-safe HTML for this block. */
|
|
54
|
+
html: string;
|
|
55
|
+
/** True while the block is still streaming (its HTML may still change). */
|
|
56
|
+
open: boolean;
|
|
57
|
+
/** True if the block was closed speculatively and may yet be revised. */
|
|
58
|
+
speculative: boolean;
|
|
59
|
+
/** Decoded source text — present for `CodeBlock` / `MathBlock`. */
|
|
60
|
+
text?: string;
|
|
61
|
+
/** Info-string language — present for `CodeBlock` (from `kind.data.lang`). */
|
|
62
|
+
language?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Per-stream parser configuration. Omitted fields use the library defaults
|
|
67
|
+
* (autolinks + alerts on, raw HTML escaped, footnotes off) — so the default
|
|
68
|
+
* `new FluxClient()` behaves exactly as before. Config is applied when the
|
|
69
|
+
* stream's parser is created and is **immutable** for that stream's lifetime
|
|
70
|
+
* (a `reset()` keeps it; use a new client for different flags).
|
|
71
|
+
*/
|
|
72
|
+
export interface ParserConfig {
|
|
73
|
+
/** GFM extended autolinks (bare www./http(s)://ftp:// + emails). Default true. */
|
|
74
|
+
gfmAutolinks?: boolean;
|
|
75
|
+
/** GitHub alerts (`> [!NOTE]` → callouts). Default true. */
|
|
76
|
+
gfmAlerts?: boolean;
|
|
77
|
+
/** GFM footnotes (`[^1]` + `[^1]:` → footnote section). Default false. */
|
|
78
|
+
gfmFootnotes?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Math: `$…$` / `\(…\)` inline and `$$…$$` / `\[…\]` display. Default false
|
|
81
|
+
* (so `$` in prose / currency stays literal). Emits KaTeX-ready markup
|
|
82
|
+
* (`<span class="math math-inline">` / `<div class="math math-display">`)
|
|
83
|
+
* carrying the LaTeX — bring your own KaTeX pass (flux-md stays zero-dep).
|
|
84
|
+
*/
|
|
85
|
+
gfmMath?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Emit `dir="auto"` on block-level text elements (`p`, `h1`–`h6`,
|
|
88
|
+
* `blockquote`, `ul`/`ol`/`li`, `table`) so the browser detects each block's
|
|
89
|
+
* direction independently — correct for documents mixing English with
|
|
90
|
+
* Arabic/Hebrew. Default false; code blocks always stay LTR. Recommended for
|
|
91
|
+
* apps that render RTL or mixed-direction content.
|
|
92
|
+
*/
|
|
93
|
+
dirAuto?: boolean;
|
|
94
|
+
/** Pass raw HTML through unescaped. Default false. **Never enable for untrusted input.** */
|
|
95
|
+
unsafeHtml?: boolean;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Each message carries a `streamId` so one worker can multiplex many parsers
|
|
99
|
+
// (the worker pool). `ready` is the exception — it's worker-level (WASM loaded),
|
|
100
|
+
// not stream-level. The first message for a stream may carry `config`, applied
|
|
101
|
+
// when that stream's parser is created.
|
|
102
|
+
export type ToWorker =
|
|
103
|
+
| { type: "append"; streamId: number; chunk: string; config?: ParserConfig }
|
|
104
|
+
| { type: "finalize"; streamId: number; config?: ParserConfig }
|
|
105
|
+
| { type: "reset"; streamId: number }
|
|
106
|
+
| { type: "dispose"; streamId: number };
|
|
107
|
+
|
|
108
|
+
export type FromWorker =
|
|
109
|
+
| { type: "ready" }
|
|
110
|
+
| {
|
|
111
|
+
type: "patch";
|
|
112
|
+
streamId: number;
|
|
113
|
+
patch: Patch;
|
|
114
|
+
appendedBytes: number;
|
|
115
|
+
parseMicros: number;
|
|
116
|
+
retainedBytes: number;
|
|
117
|
+
wasmMemoryBytes: number;
|
|
118
|
+
}
|
|
119
|
+
| { type: "error"; streamId: number; message: string };
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Minimal structural interface satisfied by the DOM `Worker`. Injectable so the
|
|
123
|
+
* pool's routing/lifecycle logic can be unit-tested with a fake worker — no
|
|
124
|
+
* real Worker or WASM required.
|
|
125
|
+
*/
|
|
126
|
+
export interface WorkerLike {
|
|
127
|
+
postMessage(msg: ToWorker): void;
|
|
128
|
+
addEventListener(type: "message", listener: (ev: { data: FromWorker }) => void): void;
|
|
129
|
+
terminate(): void;
|
|
130
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export class FluxParser {
|
|
5
|
+
free(): void;
|
|
6
|
+
[Symbol.dispose](): void;
|
|
7
|
+
append(chunk: string): any;
|
|
8
|
+
bufferLen(): number;
|
|
9
|
+
finalize(): any;
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Total bytes the parser is retaining: source buffer + all rendered
|
|
13
|
+
* HTML for committed and active blocks. Use to compare per-parser
|
|
14
|
+
* memory cost against alternatives.
|
|
15
|
+
*/
|
|
16
|
+
retainedBytes(): number;
|
|
17
|
+
/**
|
|
18
|
+
* Emit `dir="auto"` on block-level text elements so the browser detects
|
|
19
|
+
* each block's direction (LTR/RTL) independently — correct rendering for
|
|
20
|
+
* documents that mix English with Arabic/Hebrew. Off by default; code
|
|
21
|
+
* blocks never get it (code is always LTR).
|
|
22
|
+
*/
|
|
23
|
+
setDirAuto(on: boolean): void;
|
|
24
|
+
/**
|
|
25
|
+
* Enable GitHub alerts (`> [!NOTE]` blockquotes render as styled callouts
|
|
26
|
+
* with GitHub-compatible class names). Off by default.
|
|
27
|
+
*/
|
|
28
|
+
setGfmAlerts(on: boolean): void;
|
|
29
|
+
/**
|
|
30
|
+
* Enable GFM extended autolinks (bare www./http(s)://ftp:// URLs and email
|
|
31
|
+
* addresses become links). Useful for LLM output, which is full of them.
|
|
32
|
+
*/
|
|
33
|
+
setGfmAutolinks(on: boolean): void;
|
|
34
|
+
/**
|
|
35
|
+
* Enable GFM footnotes (`[^1]` references + `[^1]:` definitions → a
|
|
36
|
+
* footnote section emitted at finalize). Off by default.
|
|
37
|
+
*/
|
|
38
|
+
setGfmFootnotes(on: boolean): void;
|
|
39
|
+
/**
|
|
40
|
+
* Enable math: `$…$` / `\(…\)` inline and `$$…$$` / `\[…\]` display math.
|
|
41
|
+
* Off by default (so `$` in prose / currency stays literal). The emitted
|
|
42
|
+
* HTML carries the LaTeX in `<span class="math math-inline">` /
|
|
43
|
+
* `<div class="math math-display">` for a KaTeX pass on the JS side.
|
|
44
|
+
*/
|
|
45
|
+
setGfmMath(on: boolean): void;
|
|
46
|
+
/**
|
|
47
|
+
* Enable or disable raw-HTML pass-through. Default off. Do not enable
|
|
48
|
+
* when rendering untrusted input — bypasses XSS protection.
|
|
49
|
+
*/
|
|
50
|
+
setUnsafeHtml(on: boolean): void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
54
|
+
|
|
55
|
+
export interface InitOutput {
|
|
56
|
+
readonly memory: WebAssembly.Memory;
|
|
57
|
+
readonly __wbg_fluxparser_free: (a: number, b: number) => void;
|
|
58
|
+
readonly fluxparser_append: (a: number, b: number, c: number, d: number) => void;
|
|
59
|
+
readonly fluxparser_bufferLen: (a: number) => number;
|
|
60
|
+
readonly fluxparser_finalize: (a: number, b: number) => void;
|
|
61
|
+
readonly fluxparser_new: () => number;
|
|
62
|
+
readonly fluxparser_retainedBytes: (a: number) => number;
|
|
63
|
+
readonly fluxparser_setDirAuto: (a: number, b: number) => void;
|
|
64
|
+
readonly fluxparser_setGfmAlerts: (a: number, b: number) => void;
|
|
65
|
+
readonly fluxparser_setGfmAutolinks: (a: number, b: number) => void;
|
|
66
|
+
readonly fluxparser_setGfmFootnotes: (a: number, b: number) => void;
|
|
67
|
+
readonly fluxparser_setGfmMath: (a: number, b: number) => void;
|
|
68
|
+
readonly fluxparser_setUnsafeHtml: (a: number, b: number) => void;
|
|
69
|
+
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
70
|
+
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
71
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
78
|
+
* a precompiled `WebAssembly.Module`.
|
|
79
|
+
*
|
|
80
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
81
|
+
*
|
|
82
|
+
* @returns {InitOutput}
|
|
83
|
+
*/
|
|
84
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
88
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
89
|
+
*
|
|
90
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
91
|
+
*
|
|
92
|
+
* @returns {Promise<InitOutput>}
|
|
93
|
+
*/
|
|
94
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
/* @ts-self-types="./flux_md_core.d.ts" */
|
|
2
|
+
|
|
3
|
+
export class FluxParser {
|
|
4
|
+
__destroy_into_raw() {
|
|
5
|
+
const ptr = this.__wbg_ptr;
|
|
6
|
+
this.__wbg_ptr = 0;
|
|
7
|
+
FluxParserFinalization.unregister(this);
|
|
8
|
+
return ptr;
|
|
9
|
+
}
|
|
10
|
+
free() {
|
|
11
|
+
const ptr = this.__destroy_into_raw();
|
|
12
|
+
wasm.__wbg_fluxparser_free(ptr, 0);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @param {string} chunk
|
|
16
|
+
* @returns {any}
|
|
17
|
+
*/
|
|
18
|
+
append(chunk) {
|
|
19
|
+
try {
|
|
20
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
21
|
+
const ptr0 = passStringToWasm0(chunk, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
22
|
+
const len0 = WASM_VECTOR_LEN;
|
|
23
|
+
wasm.fluxparser_append(retptr, this.__wbg_ptr, ptr0, len0);
|
|
24
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
25
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
26
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
27
|
+
if (r2) {
|
|
28
|
+
throw takeObject(r1);
|
|
29
|
+
}
|
|
30
|
+
return takeObject(r0);
|
|
31
|
+
} finally {
|
|
32
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @returns {number}
|
|
37
|
+
*/
|
|
38
|
+
bufferLen() {
|
|
39
|
+
const ret = wasm.fluxparser_bufferLen(this.__wbg_ptr);
|
|
40
|
+
return ret >>> 0;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* @returns {any}
|
|
44
|
+
*/
|
|
45
|
+
finalize() {
|
|
46
|
+
try {
|
|
47
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
48
|
+
wasm.fluxparser_finalize(retptr, this.__wbg_ptr);
|
|
49
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
50
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
51
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
52
|
+
if (r2) {
|
|
53
|
+
throw takeObject(r1);
|
|
54
|
+
}
|
|
55
|
+
return takeObject(r0);
|
|
56
|
+
} finally {
|
|
57
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
constructor() {
|
|
61
|
+
const ret = wasm.fluxparser_new();
|
|
62
|
+
this.__wbg_ptr = ret;
|
|
63
|
+
FluxParserFinalization.register(this, this.__wbg_ptr, this);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Total bytes the parser is retaining: source buffer + all rendered
|
|
68
|
+
* HTML for committed and active blocks. Use to compare per-parser
|
|
69
|
+
* memory cost against alternatives.
|
|
70
|
+
* @returns {number}
|
|
71
|
+
*/
|
|
72
|
+
retainedBytes() {
|
|
73
|
+
const ret = wasm.fluxparser_retainedBytes(this.__wbg_ptr);
|
|
74
|
+
return ret >>> 0;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Emit `dir="auto"` on block-level text elements so the browser detects
|
|
78
|
+
* each block's direction (LTR/RTL) independently — correct rendering for
|
|
79
|
+
* documents that mix English with Arabic/Hebrew. Off by default; code
|
|
80
|
+
* blocks never get it (code is always LTR).
|
|
81
|
+
* @param {boolean} on
|
|
82
|
+
*/
|
|
83
|
+
setDirAuto(on) {
|
|
84
|
+
wasm.fluxparser_setDirAuto(this.__wbg_ptr, on);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Enable GitHub alerts (`> [!NOTE]` blockquotes render as styled callouts
|
|
88
|
+
* with GitHub-compatible class names). Off by default.
|
|
89
|
+
* @param {boolean} on
|
|
90
|
+
*/
|
|
91
|
+
setGfmAlerts(on) {
|
|
92
|
+
wasm.fluxparser_setGfmAlerts(this.__wbg_ptr, on);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Enable GFM extended autolinks (bare www./http(s)://ftp:// URLs and email
|
|
96
|
+
* addresses become links). Useful for LLM output, which is full of them.
|
|
97
|
+
* @param {boolean} on
|
|
98
|
+
*/
|
|
99
|
+
setGfmAutolinks(on) {
|
|
100
|
+
wasm.fluxparser_setGfmAutolinks(this.__wbg_ptr, on);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Enable GFM footnotes (`[^1]` references + `[^1]:` definitions → a
|
|
104
|
+
* footnote section emitted at finalize). Off by default.
|
|
105
|
+
* @param {boolean} on
|
|
106
|
+
*/
|
|
107
|
+
setGfmFootnotes(on) {
|
|
108
|
+
wasm.fluxparser_setGfmFootnotes(this.__wbg_ptr, on);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Enable math: `$…$` / `\(…\)` inline and `$$…$$` / `\[…\]` display math.
|
|
112
|
+
* Off by default (so `$` in prose / currency stays literal). The emitted
|
|
113
|
+
* HTML carries the LaTeX in `<span class="math math-inline">` /
|
|
114
|
+
* `<div class="math math-display">` for a KaTeX pass on the JS side.
|
|
115
|
+
* @param {boolean} on
|
|
116
|
+
*/
|
|
117
|
+
setGfmMath(on) {
|
|
118
|
+
wasm.fluxparser_setGfmMath(this.__wbg_ptr, on);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Enable or disable raw-HTML pass-through. Default off. Do not enable
|
|
122
|
+
* when rendering untrusted input — bypasses XSS protection.
|
|
123
|
+
* @param {boolean} on
|
|
124
|
+
*/
|
|
125
|
+
setUnsafeHtml(on) {
|
|
126
|
+
wasm.fluxparser_setUnsafeHtml(this.__wbg_ptr, on);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (Symbol.dispose) FluxParser.prototype[Symbol.dispose] = FluxParser.prototype.free;
|
|
130
|
+
function __wbg_get_imports() {
|
|
131
|
+
const import0 = {
|
|
132
|
+
__proto__: null,
|
|
133
|
+
__wbg_Error_ef53bc310eb298a0: function(arg0, arg1) {
|
|
134
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
135
|
+
return addHeapObject(ret);
|
|
136
|
+
},
|
|
137
|
+
__wbg_String_8564e559799eccda: function(arg0, arg1) {
|
|
138
|
+
const ret = String(getObject(arg1));
|
|
139
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
140
|
+
const len1 = WASM_VECTOR_LEN;
|
|
141
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
142
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
143
|
+
},
|
|
144
|
+
__wbg___wbindgen_throw_1506f2235d1bdba0: function(arg0, arg1) {
|
|
145
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
146
|
+
},
|
|
147
|
+
__wbg_new_ce1ab61c1c2b300d: function() {
|
|
148
|
+
const ret = new Object();
|
|
149
|
+
return addHeapObject(ret);
|
|
150
|
+
},
|
|
151
|
+
__wbg_new_d90091b82fdf5b91: function() {
|
|
152
|
+
const ret = new Array();
|
|
153
|
+
return addHeapObject(ret);
|
|
154
|
+
},
|
|
155
|
+
__wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
|
|
156
|
+
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
|
|
157
|
+
},
|
|
158
|
+
__wbg_set_dca99999bba88a9a: function(arg0, arg1, arg2) {
|
|
159
|
+
getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
|
|
160
|
+
},
|
|
161
|
+
__wbindgen_cast_0000000000000001: function(arg0) {
|
|
162
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
163
|
+
const ret = arg0;
|
|
164
|
+
return addHeapObject(ret);
|
|
165
|
+
},
|
|
166
|
+
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
167
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
168
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
169
|
+
return addHeapObject(ret);
|
|
170
|
+
},
|
|
171
|
+
__wbindgen_cast_0000000000000003: function(arg0) {
|
|
172
|
+
// Cast intrinsic for `U64 -> Externref`.
|
|
173
|
+
const ret = BigInt.asUintN(64, arg0);
|
|
174
|
+
return addHeapObject(ret);
|
|
175
|
+
},
|
|
176
|
+
__wbindgen_object_clone_ref: function(arg0) {
|
|
177
|
+
const ret = getObject(arg0);
|
|
178
|
+
return addHeapObject(ret);
|
|
179
|
+
},
|
|
180
|
+
__wbindgen_object_drop_ref: function(arg0) {
|
|
181
|
+
takeObject(arg0);
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
return {
|
|
185
|
+
__proto__: null,
|
|
186
|
+
"./flux_md_core_bg.js": import0,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const FluxParserFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
191
|
+
? { register: () => {}, unregister: () => {} }
|
|
192
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_fluxparser_free(ptr, 1));
|
|
193
|
+
|
|
194
|
+
function addHeapObject(obj) {
|
|
195
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
196
|
+
const idx = heap_next;
|
|
197
|
+
heap_next = heap[idx];
|
|
198
|
+
|
|
199
|
+
heap[idx] = obj;
|
|
200
|
+
return idx;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function dropObject(idx) {
|
|
204
|
+
if (idx < 1028) return;
|
|
205
|
+
heap[idx] = heap_next;
|
|
206
|
+
heap_next = idx;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
let cachedDataViewMemory0 = null;
|
|
210
|
+
function getDataViewMemory0() {
|
|
211
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
212
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
213
|
+
}
|
|
214
|
+
return cachedDataViewMemory0;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function getStringFromWasm0(ptr, len) {
|
|
218
|
+
return decodeText(ptr >>> 0, len);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
let cachedUint8ArrayMemory0 = null;
|
|
222
|
+
function getUint8ArrayMemory0() {
|
|
223
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
224
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
225
|
+
}
|
|
226
|
+
return cachedUint8ArrayMemory0;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function getObject(idx) { return heap[idx]; }
|
|
230
|
+
|
|
231
|
+
let heap = new Array(1024).fill(undefined);
|
|
232
|
+
heap.push(undefined, null, true, false);
|
|
233
|
+
|
|
234
|
+
let heap_next = heap.length;
|
|
235
|
+
|
|
236
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
237
|
+
if (realloc === undefined) {
|
|
238
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
239
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
240
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
241
|
+
WASM_VECTOR_LEN = buf.length;
|
|
242
|
+
return ptr;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
let len = arg.length;
|
|
246
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
247
|
+
|
|
248
|
+
const mem = getUint8ArrayMemory0();
|
|
249
|
+
|
|
250
|
+
let offset = 0;
|
|
251
|
+
|
|
252
|
+
for (; offset < len; offset++) {
|
|
253
|
+
const code = arg.charCodeAt(offset);
|
|
254
|
+
if (code > 0x7F) break;
|
|
255
|
+
mem[ptr + offset] = code;
|
|
256
|
+
}
|
|
257
|
+
if (offset !== len) {
|
|
258
|
+
if (offset !== 0) {
|
|
259
|
+
arg = arg.slice(offset);
|
|
260
|
+
}
|
|
261
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
262
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
263
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
264
|
+
|
|
265
|
+
offset += ret.written;
|
|
266
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
WASM_VECTOR_LEN = offset;
|
|
270
|
+
return ptr;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function takeObject(idx) {
|
|
274
|
+
const ret = getObject(idx);
|
|
275
|
+
dropObject(idx);
|
|
276
|
+
return ret;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
280
|
+
cachedTextDecoder.decode();
|
|
281
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
282
|
+
let numBytesDecoded = 0;
|
|
283
|
+
function decodeText(ptr, len) {
|
|
284
|
+
numBytesDecoded += len;
|
|
285
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
286
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
287
|
+
cachedTextDecoder.decode();
|
|
288
|
+
numBytesDecoded = len;
|
|
289
|
+
}
|
|
290
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const cachedTextEncoder = new TextEncoder();
|
|
294
|
+
|
|
295
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
296
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
297
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
298
|
+
view.set(buf);
|
|
299
|
+
return {
|
|
300
|
+
read: arg.length,
|
|
301
|
+
written: buf.length
|
|
302
|
+
};
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
let WASM_VECTOR_LEN = 0;
|
|
307
|
+
|
|
308
|
+
let wasmModule, wasmInstance, wasm;
|
|
309
|
+
function __wbg_finalize_init(instance, module) {
|
|
310
|
+
wasmInstance = instance;
|
|
311
|
+
wasm = instance.exports;
|
|
312
|
+
wasmModule = module;
|
|
313
|
+
cachedDataViewMemory0 = null;
|
|
314
|
+
cachedUint8ArrayMemory0 = null;
|
|
315
|
+
return wasm;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
async function __wbg_load(module, imports) {
|
|
319
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
320
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
321
|
+
try {
|
|
322
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
323
|
+
} catch (e) {
|
|
324
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
325
|
+
|
|
326
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
327
|
+
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);
|
|
328
|
+
|
|
329
|
+
} else { throw e; }
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const bytes = await module.arrayBuffer();
|
|
334
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
335
|
+
} else {
|
|
336
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
337
|
+
|
|
338
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
339
|
+
return { instance, module };
|
|
340
|
+
} else {
|
|
341
|
+
return instance;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function expectedResponseType(type) {
|
|
346
|
+
switch (type) {
|
|
347
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
348
|
+
}
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function initSync(module) {
|
|
354
|
+
if (wasm !== undefined) return wasm;
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
if (module !== undefined) {
|
|
358
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
359
|
+
({module} = module)
|
|
360
|
+
} else {
|
|
361
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const imports = __wbg_get_imports();
|
|
366
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
367
|
+
module = new WebAssembly.Module(module);
|
|
368
|
+
}
|
|
369
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
370
|
+
return __wbg_finalize_init(instance, module);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
async function __wbg_init(module_or_path) {
|
|
374
|
+
if (wasm !== undefined) return wasm;
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
if (module_or_path !== undefined) {
|
|
378
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
379
|
+
({module_or_path} = module_or_path)
|
|
380
|
+
} else {
|
|
381
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (module_or_path === undefined) {
|
|
386
|
+
module_or_path = new URL('flux_md_core_bg.wasm', import.meta.url);
|
|
387
|
+
}
|
|
388
|
+
const imports = __wbg_get_imports();
|
|
389
|
+
|
|
390
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
391
|
+
module_or_path = fetch(module_or_path);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
395
|
+
|
|
396
|
+
return __wbg_finalize_init(instance, module);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_fluxparser_free: (a: number, b: number) => void;
|
|
5
|
+
export const fluxparser_append: (a: number, b: number, c: number, d: number) => void;
|
|
6
|
+
export const fluxparser_bufferLen: (a: number) => number;
|
|
7
|
+
export const fluxparser_finalize: (a: number, b: number) => void;
|
|
8
|
+
export const fluxparser_new: () => number;
|
|
9
|
+
export const fluxparser_retainedBytes: (a: number) => number;
|
|
10
|
+
export const fluxparser_setDirAuto: (a: number, b: number) => void;
|
|
11
|
+
export const fluxparser_setGfmAlerts: (a: number, b: number) => void;
|
|
12
|
+
export const fluxparser_setGfmAutolinks: (a: number, b: number) => void;
|
|
13
|
+
export const fluxparser_setGfmFootnotes: (a: number, b: number) => void;
|
|
14
|
+
export const fluxparser_setGfmMath: (a: number, b: number) => void;
|
|
15
|
+
export const fluxparser_setUnsafeHtml: (a: number, b: number) => void;
|
|
16
|
+
export const __wbindgen_export: (a: number, b: number) => number;
|
|
17
|
+
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
18
|
+
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "flux-md-core",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "Incremental, streaming-aware markdown parser with speculative closure",
|
|
5
|
+
"version": "0.1.0",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"files": [
|
|
8
|
+
"flux_md_core_bg.wasm",
|
|
9
|
+
"flux_md_core.js",
|
|
10
|
+
"flux_md_core.d.ts"
|
|
11
|
+
],
|
|
12
|
+
"main": "flux_md_core.js",
|
|
13
|
+
"types": "flux_md_core.d.ts",
|
|
14
|
+
"sideEffects": [
|
|
15
|
+
"./snippets/*"
|
|
16
|
+
]
|
|
17
|
+
}
|