@stll/docx-core
Advanced tools
Sorry, the diff of this file is not supported yet
| //#region src/generated/docx_kernel.d.ts | ||
| /* tslint:disable */ | ||
| /* eslint-disable */ | ||
| type DocxProjectionFormattingSpan = readonly [startUtf16: number, endUtf16: number, style: "bold" | "highlight"]; | ||
| type DocxProjectionStructure = readonly [] | readonly [type: "table", tableId: string, row: number, column: number]; | ||
| type DocxProjectionParagraph = readonly [ordinal: number, text: string, packageParagraphId: string | null, formatting: readonly DocxProjectionFormattingSpan[], structure: DocxProjectionStructure]; | ||
| type DocxProjectionFactSet<T> = readonly [status: "known", items: readonly T[]] | readonly [status: "unknown", reason: DocxProjectionUnknownReason]; | ||
| type DocxProjectionUnknownReason = "document-part-only" | "styles-part-unavailable" | "unsupported-styles" | "unsupported-numbering" | "incomplete-bookmark-ranges" | "unsupported-internal-references"; | ||
| type DocxProjectionIndentationFact = readonly [paragraphOrdinal: number, firstLineTwips: number | null, hangingTwips: number | null, leftTwips: number | null, rightTwips: number | null, startTwips: number | null, endTwips: number | null, firstLineCharsHundredths: number | null, hangingCharsHundredths: number | null, leftCharsHundredths: number | null, rightCharsHundredths: number | null, startCharsHundredths: number | null, endCharsHundredths: number | null]; | ||
| type DocxProjectionNumberingFact = readonly [paragraphOrdinal: number, parentParagraphOrdinal: number | null, childParagraphOrdinals: readonly number[]]; | ||
| type DocxProjectionBookmarkFact = readonly [paragraphOrdinal: number, bookmarkId: number, name: string, span: DocxProjectionStructuralSpan]; | ||
| type DocxProjectionReferenceFact = readonly [paragraphOrdinal: number, referenceId: string, role: "source" | "target", span: DocxProjectionStructuralSpan]; | ||
| type DocxProjectionStructuralSpan = readonly [startUtf8: number, endUtf8: number, startUtf16: number, endUtf16: number, coverage: "complete" | "continues-before" | "continues-after" | "continues-before-and-after"]; | ||
| type DocxProjectionStructuralFacts = readonly [indentation: DocxProjectionFactSet<DocxProjectionIndentationFact>, numberingHierarchy: DocxProjectionFactSet<DocxProjectionNumberingFact>, bookmarks: DocxProjectionFactSet<DocxProjectionBookmarkFact>, internalReferences: DocxProjectionFactSet<DocxProjectionReferenceFact>]; | ||
| type DocxProjectionRevisionUnsupportedReason = "incompatible-paragraph-merge" | "structural-table-revision" | "unsupported-revision-markup"; | ||
| type DocxProjectionRevisionStatus = readonly [status: "complete"] | readonly [status: "incomplete", reasons: readonly DocxProjectionRevisionUnsupportedReason[]]; | ||
| type DocxProjectionWire = readonly [schemaVersion: 2, paragraphs: readonly DocxProjectionParagraph[], structuralFacts: DocxProjectionStructuralFacts, revisionStatus: DocxProjectionRevisionStatus]; | ||
| //#endregion | ||
| //#region src/projection.d.ts | ||
| declare const DocxProjectionInitializationError_base: import("better-result").TaggedErrorClass<"DocxProjectionInitializationError", { | ||
| message: string; | ||
| cause: unknown; | ||
| }>; | ||
| declare class DocxProjectionInitializationError extends DocxProjectionInitializationError_base {} | ||
| declare const DocxProjectionError_base: import("better-result").TaggedErrorClass<"DocxProjectionError", { | ||
| message: string; | ||
| cause: unknown; | ||
| }>; | ||
| declare class DocxProjectionError extends DocxProjectionError_base {} | ||
| type DocxProjectionWasmSource = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; | ||
| type InitializeDocxProjectionOptions = { | ||
| /** | ||
| * Optional explicit WebAssembly source for runtimes that do not load assets | ||
| * by URL. Browsers normally omit this and use the package-relative asset. | ||
| */ | ||
| wasm?: DocxProjectionWasmSource; | ||
| }; | ||
| /** Loads and caches the single-threaded WebAssembly runtime. */ | ||
| declare const initializeDocxProjection: ({ wasm }?: InitializeDocxProjectionOptions) => Promise<void>; | ||
| /** | ||
| * Projects compressed DOCX bytes through the canonical Rust implementation. | ||
| * The TypeScript boundary initializes WebAssembly and preserves its versioned | ||
| * result; it does not contain an alternate OOXML parser. | ||
| */ | ||
| declare const projectCompressedDocx: (bytes: Uint8Array) => Promise<DocxProjectionWire>; | ||
| //#endregion | ||
| export { type DocxProjectionBookmarkFact, DocxProjectionError, type DocxProjectionFactSet, type DocxProjectionFormattingSpan, type DocxProjectionIndentationFact, DocxProjectionInitializationError, type DocxProjectionNumberingFact, type DocxProjectionParagraph, type DocxProjectionReferenceFact, type DocxProjectionRevisionStatus, type DocxProjectionRevisionUnsupportedReason, type DocxProjectionStructuralFacts, type DocxProjectionStructuralSpan, type DocxProjectionStructure, type DocxProjectionUnknownReason, DocxProjectionWasmSource, type DocxProjectionWire, InitializeDocxProjectionOptions, initializeDocxProjection, projectCompressedDocx }; |
| import { TaggedError } from "better-result"; | ||
| //#region src/generated/docx_kernel.js | ||
| /** | ||
| * Projects compressed DOCX bytes into a versioned host-independent snapshot. | ||
| * | ||
| * The ordinal is the paragraph's position in this immutable package snapshot. | ||
| * Package `w14:paraId` values are returned separately. Neither value is an | ||
| * application identity or a host navigation identity. A structural fact | ||
| * family is `unknown` when the package does not prove completeness; an empty | ||
| * `known` list is authoritative negative evidence. | ||
| * | ||
| * # Errors | ||
| * | ||
| * Returns a JavaScript `Error` when the package cannot be projected or a | ||
| * numeric wire value cannot be represented by the schema. | ||
| * @param {Uint8Array} bytes | ||
| * @returns {DocxProjectionWire} | ||
| */ | ||
| function projectCompressedDocx$1(bytes) { | ||
| try { | ||
| const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
| const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_export); | ||
| const len0 = WASM_VECTOR_LEN; | ||
| wasm.projectCompressedDocx(retptr, ptr0, len0); | ||
| var r0 = getDataViewMemory0().getInt32(retptr + 0, true); | ||
| var r1 = getDataViewMemory0().getInt32(retptr + 4, true); | ||
| if (getDataViewMemory0().getInt32(retptr + 8, true)) throw takeObject(r1); | ||
| return takeObject(r0); | ||
| } finally { | ||
| wasm.__wbindgen_add_to_stack_pointer(16); | ||
| } | ||
| } | ||
| function __wbg_get_imports() { | ||
| return { | ||
| __proto__: null, | ||
| "./docx_kernel_bg.js": { | ||
| __proto__: null, | ||
| __wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) { | ||
| throw new Error(getStringFromWasm0(arg0, arg1)); | ||
| }, | ||
| __wbg_new_32b398fb48b6d94a: function() { | ||
| return addHeapObject(new Array()); | ||
| }, | ||
| __wbg_new_b667d279fd5aa943: function(arg0, arg1) { | ||
| return addHeapObject(new Error(getStringFromWasm0(arg0, arg1))); | ||
| }, | ||
| __wbg_new_with_length_f8cbc3a5b9ff9368: function(arg0) { | ||
| return addHeapObject(new Array(arg0 >>> 0)); | ||
| }, | ||
| __wbg_push_d2ae3af0c1217ae6: function(arg0, arg1) { | ||
| return getObject(arg0).push(getObject(arg1)); | ||
| }, | ||
| __wbg_set_8a16b38e4805b298: function(arg0, arg1, arg2) { | ||
| getObject(arg0)[arg1 >>> 0] = takeObject(arg2); | ||
| }, | ||
| __wbindgen_cast_0000000000000001: function(arg0) { | ||
| return addHeapObject(arg0); | ||
| }, | ||
| __wbindgen_cast_0000000000000002: function(arg0, arg1) { | ||
| return addHeapObject(getStringFromWasm0(arg0, arg1)); | ||
| }, | ||
| __wbindgen_object_drop_ref: function(arg0) { | ||
| takeObject(arg0); | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| function addHeapObject(obj) { | ||
| if (heap_next === heap.length) heap.push(heap.length + 1); | ||
| const idx = heap_next; | ||
| heap_next = heap[idx]; | ||
| heap[idx] = obj; | ||
| return idx; | ||
| } | ||
| function dropObject(idx) { | ||
| if (idx < 1028) return; | ||
| heap[idx] = heap_next; | ||
| heap_next = idx; | ||
| } | ||
| let cachedDataViewMemory0 = null; | ||
| function getDataViewMemory0() { | ||
| if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) cachedDataViewMemory0 = new DataView(wasm.memory.buffer); | ||
| return cachedDataViewMemory0; | ||
| } | ||
| function getStringFromWasm0(ptr, len) { | ||
| return decodeText(ptr >>> 0, len); | ||
| } | ||
| let cachedUint8ArrayMemory0 = null; | ||
| function getUint8ArrayMemory0() { | ||
| if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); | ||
| return cachedUint8ArrayMemory0; | ||
| } | ||
| function getObject(idx) { | ||
| return heap[idx]; | ||
| } | ||
| let heap = new Array(1024).fill(void 0); | ||
| heap.push(void 0, null, true, false); | ||
| let heap_next = heap.length; | ||
| function passArray8ToWasm0(arg, malloc) { | ||
| const ptr = malloc(arg.length * 1, 1) >>> 0; | ||
| getUint8ArrayMemory0().set(arg, ptr / 1); | ||
| WASM_VECTOR_LEN = arg.length; | ||
| return ptr; | ||
| } | ||
| function takeObject(idx) { | ||
| const ret = getObject(idx); | ||
| dropObject(idx); | ||
| return ret; | ||
| } | ||
| let cachedTextDecoder = new TextDecoder("utf-8", { | ||
| ignoreBOM: true, | ||
| fatal: true | ||
| }); | ||
| cachedTextDecoder.decode(); | ||
| const MAX_SAFARI_DECODE_BYTES = 2146435072; | ||
| let numBytesDecoded = 0; | ||
| function decodeText(ptr, len) { | ||
| numBytesDecoded += len; | ||
| if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) { | ||
| cachedTextDecoder = new TextDecoder("utf-8", { | ||
| ignoreBOM: true, | ||
| fatal: true | ||
| }); | ||
| cachedTextDecoder.decode(); | ||
| numBytesDecoded = len; | ||
| } | ||
| return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); | ||
| } | ||
| let WASM_VECTOR_LEN = 0; | ||
| let wasm; | ||
| function __wbg_finalize_init(instance, module) { | ||
| wasm = instance.exports; | ||
| cachedDataViewMemory0 = null; | ||
| cachedUint8ArrayMemory0 = null; | ||
| return wasm; | ||
| } | ||
| async function __wbg_load(module, imports) { | ||
| if (typeof Response === "function" && module instanceof Response) { | ||
| if (typeof WebAssembly.instantiateStreaming === "function") try { | ||
| return await WebAssembly.instantiateStreaming(module, imports); | ||
| } catch (e) { | ||
| if (module.ok && expectedResponseType(module.type) && module.headers.get("Content-Type") !== "application/wasm") 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); | ||
| else throw e; | ||
| } | ||
| const bytes = await module.arrayBuffer(); | ||
| return await WebAssembly.instantiate(bytes, imports); | ||
| } else { | ||
| const instance = await WebAssembly.instantiate(module, imports); | ||
| if (instance instanceof WebAssembly.Instance) return { | ||
| instance, | ||
| module | ||
| }; | ||
| else return instance; | ||
| } | ||
| function expectedResponseType(type) { | ||
| switch (type) { | ||
| case "basic": | ||
| case "cors": | ||
| case "default": return true; | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
| async function __wbg_init(module_or_path) { | ||
| if (wasm !== void 0) return wasm; | ||
| if (module_or_path !== void 0) if (Object.getPrototypeOf(module_or_path) === Object.prototype) ({module_or_path} = module_or_path); | ||
| else console.warn("using deprecated parameters for the initialization function; pass a single object instead"); | ||
| if (module_or_path === void 0) module_or_path = new URL("./docx_kernel_bg.wasm", import.meta.url); | ||
| const imports = __wbg_get_imports(); | ||
| if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) module_or_path = fetch(module_or_path); | ||
| const { instance, module } = await __wbg_load(await module_or_path, imports); | ||
| return __wbg_finalize_init(instance, module); | ||
| } | ||
| //#endregion | ||
| //#region src/projection.ts | ||
| var DocxProjectionInitializationError = class extends TaggedError("DocxProjectionInitializationError")() {}; | ||
| var DocxProjectionError = class extends TaggedError("DocxProjectionError")() {}; | ||
| let initialization; | ||
| /** Loads and caches the single-threaded WebAssembly runtime. */ | ||
| const initializeDocxProjection = ({ wasm } = {}) => { | ||
| initialization ??= __wbg_init(wasm === void 0 ? void 0 : { module_or_path: wasm }).then(() => void 0).catch((cause) => { | ||
| initialization = void 0; | ||
| throw new DocxProjectionInitializationError({ | ||
| message: "Could not initialize the DOCX projection runtime", | ||
| cause | ||
| }); | ||
| }); | ||
| return initialization; | ||
| }; | ||
| /** | ||
| * Projects compressed DOCX bytes through the canonical Rust implementation. | ||
| * The TypeScript boundary initializes WebAssembly and preserves its versioned | ||
| * result; it does not contain an alternate OOXML parser. | ||
| */ | ||
| const projectCompressedDocx = async (bytes) => { | ||
| await initializeDocxProjection(); | ||
| try { | ||
| return projectCompressedDocx$1(bytes); | ||
| } catch (cause) { | ||
| throw new DocxProjectionError({ | ||
| message: "Could not project the DOCX package", | ||
| cause | ||
| }); | ||
| } | ||
| }; | ||
| //#endregion | ||
| export { DocxProjectionError, DocxProjectionInitializationError, initializeDocxProjection, projectCompressedDocx }; |
+8
-2
| { | ||
| "name": "@stll/docx-core", | ||
| "version": "0.5.2", | ||
| "description": "Typed OOXML/DOCX document model with parsing, validation, and serialization, plus a legal-source compiler that produces DOCX packages.", | ||
| "version": "0.6.0", | ||
| "description": "Typed OOXML/DOCX model, validation, serialization, legal-source compilation, and browser-native package projection.", | ||
| "keywords": [ | ||
@@ -42,2 +42,6 @@ "document-model", | ||
| "import": "./dist/model/document.js" | ||
| }, | ||
| "./projection": { | ||
| "types": "./dist/projection.d.ts", | ||
| "import": "./dist/projection.js" | ||
| } | ||
@@ -54,2 +58,4 @@ }, | ||
| "typecheck": "bun ../../scripts/tsc-native.ts --noEmit -p tsconfig.build.json", | ||
| "wasm:check": "bun ../../scripts/build-docx-kernel-wasm.ts --check", | ||
| "wasm:generate": "bun ../../scripts/build-docx-kernel-wasm.ts --write", | ||
| "format": "oxfmt .", | ||
@@ -56,0 +62,0 @@ "prepack": "bun run build" |
Network access
Supply chain riskThis module accesses the network.
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
378376
121.33%13
30%4740
5.71%