@firecrawl/anydoc-wasm 0.1.4
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 +21 -0
- package/README.md +51 -0
- package/anydoc_wasm.d.ts +276 -0
- package/anydoc_wasm.js +406 -0
- package/anydoc_wasm_bg.wasm +0 -0
- package/package.json +21 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sideguide Technologies Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# @firecrawl/anydoc-wasm
|
|
2
|
+
|
|
3
|
+
WebAssembly bindings for [anydoc](../README.md), plus the source of the demo page at [firecrawl.github.io/anydoc](https://firecrawl.github.io/anydoc/).
|
|
4
|
+
|
|
5
|
+
The API mirrors the Rust library, minus the path-based `to_markdown`: wasm has no filesystem, so conversion always starts from bytes.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @firecrawl/anydoc-wasm
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import init, { formatFromBytes, toMarkdownBytes, toDocument } from '@firecrawl/anydoc-wasm';
|
|
13
|
+
|
|
14
|
+
await init();
|
|
15
|
+
|
|
16
|
+
// With the format detected from the content:
|
|
17
|
+
const markdown = toMarkdownBytes(bytes);
|
|
18
|
+
|
|
19
|
+
// Or name it, which signature-less formats (CSV) need:
|
|
20
|
+
const fromCsv = toMarkdownBytes(bytes, 'csv');
|
|
21
|
+
|
|
22
|
+
// Or stop at the document model, which also carries embedded assets:
|
|
23
|
+
const document = toDocument(bytes);
|
|
24
|
+
|
|
25
|
+
// Format detection on its own:
|
|
26
|
+
formatFromBytes(bytes); // 'docx', or undefined when nothing matches
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The package is built with `wasm-pack --target web`: it loads with a plain `<script type="module">` and with bundlers that handle the `new URL(..., import.meta.url)` asset pattern (Vite, webpack 5, Rollup). In Node, pass the module bytes to `initSync` instead of calling `init` (see [`test.mjs`](test.mjs)).
|
|
30
|
+
|
|
31
|
+
Calls are synchronous: wasm runs single-threaded on the calling thread, so convert on a worker if the main thread must stay responsive.
|
|
32
|
+
|
|
33
|
+
## Building
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
wasm-pack build wasm --release --target web --scope firecrawl
|
|
37
|
+
node --test wasm/test.mjs
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
This produces the npm package in `wasm/pkg/`: the module, the JS glue, and TypeScript definitions. Publishing runs from [`../.github/workflows/release.yml`](../.github/workflows/release.yml) on release tags.
|
|
41
|
+
|
|
42
|
+
## Demo page
|
|
43
|
+
|
|
44
|
+
`www/` holds the static demo site, which imports the module from `www/pkg/`. Build into that directory, then serve `www/`:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
wasm-pack build wasm --release --target web --no-pack --out-dir www/pkg
|
|
48
|
+
python -m http.server -d wasm/www
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
[`../.github/workflows/pages.yml`](../.github/workflows/pages.yml) builds and deploys the same layout to GitHub Pages on every push to main.
|
package/anydoc_wasm.d.ts
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Input format, named after the extension that identifies it. Container
|
|
5
|
+
* variants that share a parser (`.docm`, `.xlsm`, `.ppsx`, ...) map onto
|
|
6
|
+
* these.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export type Format = "doc" | "docx" | "odt" | "pdf" | "ppt" | "pptx" | "rtf" | "epub" | "xlsx" | "ods" | "odp" | "csv";
|
|
10
|
+
|
|
11
|
+
export interface Document {
|
|
12
|
+
blocks: Array<Block>
|
|
13
|
+
/**
|
|
14
|
+
* Footnote and endnote bodies, referenced from text by a `noteRef`
|
|
15
|
+
* inline.
|
|
16
|
+
*/
|
|
17
|
+
notes: Array<Note>
|
|
18
|
+
assets: Array<Asset>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type BlockKind =
|
|
22
|
+
| 'heading'
|
|
23
|
+
| 'paragraph'
|
|
24
|
+
| 'list'
|
|
25
|
+
| 'table'
|
|
26
|
+
| 'blockQuote'
|
|
27
|
+
| 'codeBlock'
|
|
28
|
+
| 'rule'
|
|
29
|
+
|
|
30
|
+
export interface Block {
|
|
31
|
+
kind: BlockKind
|
|
32
|
+
/** heading: 1-6. */
|
|
33
|
+
level?: number
|
|
34
|
+
/** heading: stable anchor id when the document targets this heading. */
|
|
35
|
+
anchor?: string
|
|
36
|
+
/** heading, paragraph. */
|
|
37
|
+
content?: Array<Inline>
|
|
38
|
+
list?: List
|
|
39
|
+
table?: Table
|
|
40
|
+
/** blockQuote. */
|
|
41
|
+
blocks?: Array<Block>
|
|
42
|
+
/** codeBlock. */
|
|
43
|
+
lang?: string
|
|
44
|
+
/** codeBlock. */
|
|
45
|
+
text?: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type InlineKind =
|
|
49
|
+
| 'text'
|
|
50
|
+
| 'link'
|
|
51
|
+
| 'image'
|
|
52
|
+
/** Zero-width marker for an internal link target at this position. */
|
|
53
|
+
| 'anchor'
|
|
54
|
+
| 'noteRef'
|
|
55
|
+
| 'lineBreak'
|
|
56
|
+
|
|
57
|
+
export interface Inline {
|
|
58
|
+
kind: InlineKind
|
|
59
|
+
/** text. */
|
|
60
|
+
text?: string
|
|
61
|
+
/** text. */
|
|
62
|
+
style?: Style
|
|
63
|
+
/** link. */
|
|
64
|
+
content?: Array<Inline>
|
|
65
|
+
/** link. */
|
|
66
|
+
target?: LinkTarget
|
|
67
|
+
/** image. */
|
|
68
|
+
alt?: string
|
|
69
|
+
/** image. */
|
|
70
|
+
source?: ImageSource
|
|
71
|
+
/** anchor: the anchor id. */
|
|
72
|
+
anchor?: string
|
|
73
|
+
/** noteRef: the id of the note in `Document.notes`. */
|
|
74
|
+
noteId?: string
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Fully resolved character style. */
|
|
78
|
+
export interface Style {
|
|
79
|
+
bold: boolean
|
|
80
|
+
italic: boolean
|
|
81
|
+
strike: boolean
|
|
82
|
+
code: boolean
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type LinkTargetKind =
|
|
86
|
+
/** Absolute URL with a scheme. */
|
|
87
|
+
| 'external'
|
|
88
|
+
/** Scheme-less relative reference, preserved as written. */
|
|
89
|
+
| 'relative'
|
|
90
|
+
/** Internal target: a heading anchor or an `anchor` inline. */
|
|
91
|
+
| 'anchor'
|
|
92
|
+
|
|
93
|
+
export interface LinkTarget {
|
|
94
|
+
kind: LinkTargetKind
|
|
95
|
+
/** The URL, relative reference, or anchor id. */
|
|
96
|
+
value: string
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export type ImageSourceKind =
|
|
100
|
+
/** Absolute URL with a scheme. */
|
|
101
|
+
| 'external'
|
|
102
|
+
/** Embedded image, carried in `Document.assets`. */
|
|
103
|
+
| 'asset'
|
|
104
|
+
/**
|
|
105
|
+
* No usable source: the image's part is missing or unreadable and it has
|
|
106
|
+
* no URL. Only the alt text remains.
|
|
107
|
+
*/
|
|
108
|
+
| 'unavailable'
|
|
109
|
+
|
|
110
|
+
export interface ImageSource {
|
|
111
|
+
kind: ImageSourceKind
|
|
112
|
+
/** external. */
|
|
113
|
+
url?: string
|
|
114
|
+
/** asset: index into `Document.assets`. */
|
|
115
|
+
assetId?: number
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** The marker family a list uses in the source document. */
|
|
119
|
+
export type MarkerKind =
|
|
120
|
+
| 'bullet'
|
|
121
|
+
| 'decimal'
|
|
122
|
+
| 'lowerAlpha'
|
|
123
|
+
| 'upperAlpha'
|
|
124
|
+
| 'lowerRoman'
|
|
125
|
+
| 'upperRoman'
|
|
126
|
+
|
|
127
|
+
export interface List {
|
|
128
|
+
marker: MarkerKind
|
|
129
|
+
/** Ordinal the first item counts from. */
|
|
130
|
+
start: number
|
|
131
|
+
items: Array<ListItem>
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface ListItem {
|
|
135
|
+
blocks: Array<Block>
|
|
136
|
+
/** Task-list state, when the item carries a checkbox. */
|
|
137
|
+
checked?: boolean
|
|
138
|
+
/**
|
|
139
|
+
* Literal marker text that overrides the list marker when the source
|
|
140
|
+
* number text cannot be reproduced from the marker and position alone
|
|
141
|
+
* (composite number text such as `1-a)`).
|
|
142
|
+
*/
|
|
143
|
+
markerLabel?: string
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export type TableKind =
|
|
147
|
+
/** A real data table. */
|
|
148
|
+
| 'data'
|
|
149
|
+
/** Layout scaffolding (text boxes, positioning tables). */
|
|
150
|
+
| 'layout'
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Canonical table grid: every logical grid position appears exactly once.
|
|
154
|
+
* Content and spans live on the origin slot, and each position a span covers
|
|
155
|
+
* holds a `covered` slot pointing back at that origin.
|
|
156
|
+
*/
|
|
157
|
+
export interface Table {
|
|
158
|
+
grid: Array<Array<CellSlot>>
|
|
159
|
+
/** Number of leading rows that are header rows (0 = no header). */
|
|
160
|
+
headerRows: number
|
|
161
|
+
kind: TableKind
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export type CellSlotKind = 'origin' | 'covered'
|
|
165
|
+
|
|
166
|
+
export interface CellSlot {
|
|
167
|
+
kind: CellSlotKind
|
|
168
|
+
/** origin. */
|
|
169
|
+
cell?: Cell
|
|
170
|
+
/** covered: row of the origin this position belongs to. */
|
|
171
|
+
originRow?: number
|
|
172
|
+
/** covered: column of the origin this position belongs to. */
|
|
173
|
+
originCol?: number
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface Cell {
|
|
177
|
+
blocks: Array<Block>
|
|
178
|
+
colSpan: number
|
|
179
|
+
rowSpan: number
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export type NoteKind = 'footnote' | 'endnote'
|
|
183
|
+
|
|
184
|
+
export interface Note {
|
|
185
|
+
id: string
|
|
186
|
+
kind: NoteKind
|
|
187
|
+
blocks: Array<Block>
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* An embedded binary asset (image, object payload). Bytes are always
|
|
192
|
+
* retained, so a document stays self-contained.
|
|
193
|
+
*/
|
|
194
|
+
export interface Asset {
|
|
195
|
+
/** Index into `Document.assets`, as referenced by an image source. */
|
|
196
|
+
id: number
|
|
197
|
+
/** MIME type, e.g. `image/png`. */
|
|
198
|
+
mediaType: string
|
|
199
|
+
/** Package part or stream the asset came from, for provenance. */
|
|
200
|
+
originPart: string
|
|
201
|
+
data: Uint8Array
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Detect the format from the content itself: the signature and identity each
|
|
208
|
+
* container specification designates (PDF header, RTF open group, OLE stream
|
|
209
|
+
* names, ZIP package mimetype/content types). Plain-text formats (CSV) carry
|
|
210
|
+
* no signature and return `undefined`; so does anything unrecognized.
|
|
211
|
+
*/
|
|
212
|
+
export function formatFromBytes(bytes: Uint8Array): Format | undefined;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The format an extension names, with or without a leading dot.
|
|
216
|
+
*/
|
|
217
|
+
export function formatFromExtension(extension: string): Format | undefined;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* The format a path's (or file name's) extension names.
|
|
221
|
+
*/
|
|
222
|
+
export function formatFromPath(path: string): Format | undefined;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Parse an in-memory document into the document model, which also carries
|
|
226
|
+
* the embedded assets. Without a format, it is detected from the content.
|
|
227
|
+
*
|
|
228
|
+
* Unsupported for `pdf`: PDF conversion produces Markdown directly and has
|
|
229
|
+
* no document-model form; use `toMarkdownBytes`.
|
|
230
|
+
*/
|
|
231
|
+
export function toDocument(bytes: Uint8Array, format?: Format | null): Document;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Convert an in-memory document to Markdown. Without a format, it is
|
|
235
|
+
* detected from the content, which signature-less formats (CSV) have to name
|
|
236
|
+
* explicitly.
|
|
237
|
+
*/
|
|
238
|
+
export function toMarkdownBytes(bytes: Uint8Array, format?: Format | null): string;
|
|
239
|
+
|
|
240
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
241
|
+
|
|
242
|
+
export interface InitOutput {
|
|
243
|
+
readonly memory: WebAssembly.Memory;
|
|
244
|
+
readonly formatFromBytes: (a: number, b: number) => number;
|
|
245
|
+
readonly formatFromExtension: (a: number, b: number) => number;
|
|
246
|
+
readonly formatFromPath: (a: number, b: number) => number;
|
|
247
|
+
readonly toDocument: (a: number, b: number, c: number, d: number) => void;
|
|
248
|
+
readonly toMarkdownBytes: (a: number, b: number, c: number, d: number) => void;
|
|
249
|
+
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
250
|
+
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
251
|
+
readonly __wbindgen_export3: (a: number) => void;
|
|
252
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
253
|
+
readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
260
|
+
* a precompiled `WebAssembly.Module`.
|
|
261
|
+
*
|
|
262
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
263
|
+
*
|
|
264
|
+
* @returns {InitOutput}
|
|
265
|
+
*/
|
|
266
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
270
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
271
|
+
*
|
|
272
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
273
|
+
*
|
|
274
|
+
* @returns {Promise<InitOutput>}
|
|
275
|
+
*/
|
|
276
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/anydoc_wasm.js
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
/* @ts-self-types="./anydoc_wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Detect the format from the content itself: the signature and identity each
|
|
5
|
+
* container specification designates (PDF header, RTF open group, OLE stream
|
|
6
|
+
* names, ZIP package mimetype/content types). Plain-text formats (CSV) carry
|
|
7
|
+
* no signature and return `undefined`; so does anything unrecognized.
|
|
8
|
+
* @param {Uint8Array} bytes
|
|
9
|
+
* @returns {Format | undefined}
|
|
10
|
+
*/
|
|
11
|
+
export function formatFromBytes(bytes) {
|
|
12
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_export);
|
|
13
|
+
const len0 = WASM_VECTOR_LEN;
|
|
14
|
+
const ret = wasm.formatFromBytes(ptr0, len0);
|
|
15
|
+
return __wbindgen_enum_Format[ret];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The format an extension names, with or without a leading dot.
|
|
20
|
+
* @param {string} extension
|
|
21
|
+
* @returns {Format | undefined}
|
|
22
|
+
*/
|
|
23
|
+
export function formatFromExtension(extension) {
|
|
24
|
+
const ptr0 = passStringToWasm0(extension, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
25
|
+
const len0 = WASM_VECTOR_LEN;
|
|
26
|
+
const ret = wasm.formatFromExtension(ptr0, len0);
|
|
27
|
+
return __wbindgen_enum_Format[ret];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The format a path's (or file name's) extension names.
|
|
32
|
+
* @param {string} path
|
|
33
|
+
* @returns {Format | undefined}
|
|
34
|
+
*/
|
|
35
|
+
export function formatFromPath(path) {
|
|
36
|
+
const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
37
|
+
const len0 = WASM_VECTOR_LEN;
|
|
38
|
+
const ret = wasm.formatFromPath(ptr0, len0);
|
|
39
|
+
return __wbindgen_enum_Format[ret];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Parse an in-memory document into the document model, which also carries
|
|
44
|
+
* the embedded assets. Without a format, it is detected from the content.
|
|
45
|
+
*
|
|
46
|
+
* Unsupported for `pdf`: PDF conversion produces Markdown directly and has
|
|
47
|
+
* no document-model form; use `toMarkdownBytes`.
|
|
48
|
+
* @param {Uint8Array} bytes
|
|
49
|
+
* @param {Format | null} [format]
|
|
50
|
+
* @returns {Document}
|
|
51
|
+
*/
|
|
52
|
+
export function toDocument(bytes, format) {
|
|
53
|
+
try {
|
|
54
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
55
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_export);
|
|
56
|
+
const len0 = WASM_VECTOR_LEN;
|
|
57
|
+
wasm.toDocument(retptr, ptr0, len0, isLikeNone(format) ? 13 : ((__wbindgen_enum_Format.indexOf(format) + 1 || 13) - 1));
|
|
58
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
59
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
60
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
61
|
+
if (r2) {
|
|
62
|
+
throw takeObject(r1);
|
|
63
|
+
}
|
|
64
|
+
return takeObject(r0);
|
|
65
|
+
} finally {
|
|
66
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Convert an in-memory document to Markdown. Without a format, it is
|
|
72
|
+
* detected from the content, which signature-less formats (CSV) have to name
|
|
73
|
+
* explicitly.
|
|
74
|
+
* @param {Uint8Array} bytes
|
|
75
|
+
* @param {Format | null} [format]
|
|
76
|
+
* @returns {string}
|
|
77
|
+
*/
|
|
78
|
+
export function toMarkdownBytes(bytes, format) {
|
|
79
|
+
let deferred3_0;
|
|
80
|
+
let deferred3_1;
|
|
81
|
+
try {
|
|
82
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
83
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_export);
|
|
84
|
+
const len0 = WASM_VECTOR_LEN;
|
|
85
|
+
wasm.toMarkdownBytes(retptr, ptr0, len0, isLikeNone(format) ? 13 : ((__wbindgen_enum_Format.indexOf(format) + 1 || 13) - 1));
|
|
86
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
87
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
88
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
89
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
90
|
+
var ptr2 = r0;
|
|
91
|
+
var len2 = r1;
|
|
92
|
+
if (r3) {
|
|
93
|
+
ptr2 = 0; len2 = 0;
|
|
94
|
+
throw takeObject(r2);
|
|
95
|
+
}
|
|
96
|
+
deferred3_0 = ptr2;
|
|
97
|
+
deferred3_1 = len2;
|
|
98
|
+
return getStringFromWasm0(ptr2, len2);
|
|
99
|
+
} finally {
|
|
100
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
101
|
+
wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function __wbg_get_imports() {
|
|
105
|
+
const import0 = {
|
|
106
|
+
__proto__: null,
|
|
107
|
+
__wbg_Error_92b29b0548f8b746: function(arg0, arg1) {
|
|
108
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
109
|
+
return addHeapObject(ret);
|
|
110
|
+
},
|
|
111
|
+
__wbg_String_8564e559799eccda: function(arg0, arg1) {
|
|
112
|
+
const ret = String(getObject(arg1));
|
|
113
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
114
|
+
const len1 = WASM_VECTOR_LEN;
|
|
115
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
116
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
117
|
+
},
|
|
118
|
+
__wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
|
|
119
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
120
|
+
},
|
|
121
|
+
__wbg_from_13e323c65fc8f464: function(arg0) {
|
|
122
|
+
const ret = Array.from(getObject(arg0));
|
|
123
|
+
return addHeapObject(ret);
|
|
124
|
+
},
|
|
125
|
+
__wbg_getRandomValues_cc7f052a444bb2ce: function() { return handleError(function (arg0, arg1) {
|
|
126
|
+
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
127
|
+
}, arguments); },
|
|
128
|
+
__wbg_new_32b398fb48b6d94a: function() {
|
|
129
|
+
const ret = new Array();
|
|
130
|
+
return addHeapObject(ret);
|
|
131
|
+
},
|
|
132
|
+
__wbg_new_cd45aabdf6073e84: function(arg0) {
|
|
133
|
+
const ret = new Uint8Array(getObject(arg0));
|
|
134
|
+
return addHeapObject(ret);
|
|
135
|
+
},
|
|
136
|
+
__wbg_new_da52cf8fe3429cb2: function() {
|
|
137
|
+
const ret = new Object();
|
|
138
|
+
return addHeapObject(ret);
|
|
139
|
+
},
|
|
140
|
+
__wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
|
|
141
|
+
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
|
|
142
|
+
},
|
|
143
|
+
__wbg_set_8a16b38e4805b298: function(arg0, arg1, arg2) {
|
|
144
|
+
getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
|
|
145
|
+
},
|
|
146
|
+
__wbindgen_cast_0000000000000001: function(arg0) {
|
|
147
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
148
|
+
const ret = arg0;
|
|
149
|
+
return addHeapObject(ret);
|
|
150
|
+
},
|
|
151
|
+
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
152
|
+
// Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
|
|
153
|
+
const ret = getArrayU8FromWasm0(arg0, arg1);
|
|
154
|
+
return addHeapObject(ret);
|
|
155
|
+
},
|
|
156
|
+
__wbindgen_cast_0000000000000003: function(arg0, arg1) {
|
|
157
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
158
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
159
|
+
return addHeapObject(ret);
|
|
160
|
+
},
|
|
161
|
+
__wbindgen_object_clone_ref: function(arg0) {
|
|
162
|
+
const ret = getObject(arg0);
|
|
163
|
+
return addHeapObject(ret);
|
|
164
|
+
},
|
|
165
|
+
__wbindgen_object_drop_ref: function(arg0) {
|
|
166
|
+
takeObject(arg0);
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
return {
|
|
170
|
+
__proto__: null,
|
|
171
|
+
"./anydoc_wasm_bg.js": import0,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const __wbindgen_enum_Format = ["doc", "docx", "odt", "pdf", "ppt", "pptx", "rtf", "epub", "xlsx", "ods", "odp", "csv"];
|
|
176
|
+
|
|
177
|
+
function addHeapObject(obj) {
|
|
178
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
179
|
+
const idx = heap_next;
|
|
180
|
+
heap_next = heap[idx];
|
|
181
|
+
|
|
182
|
+
heap[idx] = obj;
|
|
183
|
+
return idx;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function dropObject(idx) {
|
|
187
|
+
if (idx < 1028) return;
|
|
188
|
+
heap[idx] = heap_next;
|
|
189
|
+
heap_next = idx;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
193
|
+
ptr = ptr >>> 0;
|
|
194
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
let cachedDataViewMemory0 = null;
|
|
198
|
+
function getDataViewMemory0() {
|
|
199
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
200
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
201
|
+
}
|
|
202
|
+
return cachedDataViewMemory0;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function getStringFromWasm0(ptr, len) {
|
|
206
|
+
return decodeText(ptr >>> 0, len);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
let cachedUint8ArrayMemory0 = null;
|
|
210
|
+
function getUint8ArrayMemory0() {
|
|
211
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
212
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
213
|
+
}
|
|
214
|
+
return cachedUint8ArrayMemory0;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function getObject(idx) { return heap[idx]; }
|
|
218
|
+
|
|
219
|
+
function handleError(f, args) {
|
|
220
|
+
try {
|
|
221
|
+
return f.apply(this, args);
|
|
222
|
+
} catch (e) {
|
|
223
|
+
wasm.__wbindgen_export3(addHeapObject(e));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
let heap = new Array(1024).fill(undefined);
|
|
228
|
+
heap.push(undefined, null, true, false);
|
|
229
|
+
|
|
230
|
+
let heap_next = heap.length;
|
|
231
|
+
|
|
232
|
+
function isLikeNone(x) {
|
|
233
|
+
return x === undefined || x === null;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
237
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
238
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
239
|
+
WASM_VECTOR_LEN = arg.length;
|
|
240
|
+
return ptr;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
244
|
+
if (realloc === undefined) {
|
|
245
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
246
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
247
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
248
|
+
WASM_VECTOR_LEN = buf.length;
|
|
249
|
+
return ptr;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
let len = arg.length;
|
|
253
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
254
|
+
|
|
255
|
+
const mem = getUint8ArrayMemory0();
|
|
256
|
+
|
|
257
|
+
let offset = 0;
|
|
258
|
+
|
|
259
|
+
for (; offset < len; offset++) {
|
|
260
|
+
const code = arg.charCodeAt(offset);
|
|
261
|
+
if (code > 0x7F) break;
|
|
262
|
+
mem[ptr + offset] = code;
|
|
263
|
+
}
|
|
264
|
+
if (offset !== len) {
|
|
265
|
+
if (offset !== 0) {
|
|
266
|
+
arg = arg.slice(offset);
|
|
267
|
+
}
|
|
268
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
269
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
270
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
271
|
+
|
|
272
|
+
offset += ret.written;
|
|
273
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
WASM_VECTOR_LEN = offset;
|
|
277
|
+
return ptr;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function takeObject(idx) {
|
|
281
|
+
const ret = getObject(idx);
|
|
282
|
+
dropObject(idx);
|
|
283
|
+
return ret;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
287
|
+
cachedTextDecoder.decode();
|
|
288
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
289
|
+
let numBytesDecoded = 0;
|
|
290
|
+
function decodeText(ptr, len) {
|
|
291
|
+
numBytesDecoded += len;
|
|
292
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
293
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
294
|
+
cachedTextDecoder.decode();
|
|
295
|
+
numBytesDecoded = len;
|
|
296
|
+
}
|
|
297
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const cachedTextEncoder = new TextEncoder();
|
|
301
|
+
|
|
302
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
303
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
304
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
305
|
+
view.set(buf);
|
|
306
|
+
return {
|
|
307
|
+
read: arg.length,
|
|
308
|
+
written: buf.length
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
let WASM_VECTOR_LEN = 0;
|
|
314
|
+
|
|
315
|
+
let wasmModule, wasmInstance, wasm;
|
|
316
|
+
function __wbg_finalize_init(instance, module) {
|
|
317
|
+
wasmInstance = instance;
|
|
318
|
+
wasm = instance.exports;
|
|
319
|
+
wasmModule = module;
|
|
320
|
+
cachedDataViewMemory0 = null;
|
|
321
|
+
cachedUint8ArrayMemory0 = null;
|
|
322
|
+
return wasm;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
async function __wbg_load(module, imports) {
|
|
326
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
327
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
328
|
+
try {
|
|
329
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
330
|
+
} catch (e) {
|
|
331
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
332
|
+
|
|
333
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
334
|
+
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);
|
|
335
|
+
|
|
336
|
+
} else { throw e; }
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const bytes = await module.arrayBuffer();
|
|
341
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
342
|
+
} else {
|
|
343
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
344
|
+
|
|
345
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
346
|
+
return { instance, module };
|
|
347
|
+
} else {
|
|
348
|
+
return instance;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function expectedResponseType(type) {
|
|
353
|
+
switch (type) {
|
|
354
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
355
|
+
}
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function initSync(module) {
|
|
361
|
+
if (wasm !== undefined) return wasm;
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
if (module !== undefined) {
|
|
365
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
366
|
+
({module} = module)
|
|
367
|
+
} else {
|
|
368
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const imports = __wbg_get_imports();
|
|
373
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
374
|
+
module = new WebAssembly.Module(module);
|
|
375
|
+
}
|
|
376
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
377
|
+
return __wbg_finalize_init(instance, module);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
async function __wbg_init(module_or_path) {
|
|
381
|
+
if (wasm !== undefined) return wasm;
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
if (module_or_path !== undefined) {
|
|
385
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
386
|
+
({module_or_path} = module_or_path)
|
|
387
|
+
} else {
|
|
388
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (module_or_path === undefined) {
|
|
393
|
+
module_or_path = new URL('anydoc_wasm_bg.wasm', import.meta.url);
|
|
394
|
+
}
|
|
395
|
+
const imports = __wbg_get_imports();
|
|
396
|
+
|
|
397
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
398
|
+
module_or_path = fetch(module_or_path);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
402
|
+
|
|
403
|
+
return __wbg_finalize_init(instance, module);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@firecrawl/anydoc-wasm",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "WebAssembly bindings for anydoc: convert documents (doc, docx, odt, rtf, epub, pdf, presentations, spreadsheets, csv) to GitHub-Flavored Markdown in the browser",
|
|
5
|
+
"version": "0.1.4",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/firecrawl/anydoc"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"anydoc_wasm_bg.wasm",
|
|
13
|
+
"anydoc_wasm.js",
|
|
14
|
+
"anydoc_wasm.d.ts"
|
|
15
|
+
],
|
|
16
|
+
"main": "anydoc_wasm.js",
|
|
17
|
+
"types": "anydoc_wasm.d.ts",
|
|
18
|
+
"sideEffects": [
|
|
19
|
+
"./snippets/*"
|
|
20
|
+
]
|
|
21
|
+
}
|