@particle-academy/last-word 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,326 @@
1
+ /**
2
+ * Public document types — the LastWord JSON document model. Inputs are loose
3
+ * agent JSON, so most fields are optional and extra keys are tolerated; the
4
+ * Validator is the gate. Mirrors PHP `particle-academy/last-word`.
5
+ */
6
+ type BlockType = "heading" | "paragraph" | "list" | "table" | "code" | "quote" | "image" | "pageBreak" | "hr";
7
+ type Align = "left" | "center" | "right" | "justify";
8
+ /** Inline text span. Only `text` is required; all flags optional. */
9
+ interface Run {
10
+ text: string;
11
+ bold?: boolean;
12
+ italic?: boolean;
13
+ underline?: boolean;
14
+ strike?: boolean;
15
+ code?: boolean;
16
+ link?: string;
17
+ /** #RRGGBB */
18
+ color?: string;
19
+ /** #RRGGBB */
20
+ highlight?: string;
21
+ [key: string]: unknown;
22
+ }
23
+ interface ListItem {
24
+ runs: Run[];
25
+ children?: ListItem[];
26
+ [key: string]: unknown;
27
+ }
28
+ interface HeadingBlock {
29
+ type: "heading";
30
+ level: 1 | 2 | 3 | 4 | 5 | 6;
31
+ runs: Run[];
32
+ }
33
+ interface ParagraphBlock {
34
+ type: "paragraph";
35
+ runs: Run[];
36
+ align?: Align;
37
+ }
38
+ interface ListBlock {
39
+ type: "list";
40
+ ordered?: boolean;
41
+ items: ListItem[];
42
+ }
43
+ interface TableCell {
44
+ blocks: Block[];
45
+ [key: string]: unknown;
46
+ }
47
+ interface TableRow {
48
+ header?: boolean;
49
+ cells: TableCell[];
50
+ [key: string]: unknown;
51
+ }
52
+ interface TableBlock {
53
+ type: "table";
54
+ rows: TableRow[];
55
+ }
56
+ interface CodeBlock {
57
+ type: "code";
58
+ language?: string;
59
+ text: string;
60
+ }
61
+ interface QuoteBlock {
62
+ type: "quote";
63
+ blocks: Block[];
64
+ }
65
+ interface ImageBlock {
66
+ type: "image";
67
+ /** data:image/png;base64,… or data:image/jpeg;base64,… */
68
+ src: string;
69
+ widthPx?: number;
70
+ heightPx?: number;
71
+ alt?: string;
72
+ }
73
+ interface PageBreakBlock {
74
+ type: "pageBreak";
75
+ }
76
+ interface HrBlock {
77
+ type: "hr";
78
+ }
79
+ type Block = HeadingBlock | ParagraphBlock | ListBlock | TableBlock | CodeBlock | QuoteBlock | ImageBlock | PageBreakBlock | HrBlock;
80
+ interface Doc {
81
+ title?: string;
82
+ blocks: Block[];
83
+ [key: string]: unknown;
84
+ }
85
+ /** Structured validation error. Empty array = valid. */
86
+ interface ValidationError {
87
+ path: string;
88
+ message: string;
89
+ }
90
+ interface RepairResult {
91
+ ok: boolean;
92
+ schema: Doc;
93
+ errors: ValidationError[];
94
+ }
95
+ interface WriteResult {
96
+ path: string;
97
+ bytes: number;
98
+ blocks: number;
99
+ }
100
+
101
+ /**
102
+ * Agent — the structured-tool surface for LastWord. Mirrors PHP `Agent`.
103
+ * Universal methods are synchronous; file-touching methods (`write`) are async
104
+ * and Node-only (browsers have no sync FS).
105
+ */
106
+
107
+ /** Feature-parity baseline with PHP last-word; bumped independently on npm. */
108
+ declare const VERSION = "0.1.0";
109
+ type Any$2 = any;
110
+ declare const Agent: {
111
+ /** Validate a doc without writing. Empty array = valid. */
112
+ validate(doc: Any$2): ValidationError[];
113
+ /**
114
+ * Validate + apply heuristic repairs (coerce strings to runs, clamp heading
115
+ * levels, drop unknown block types with the error retained, default missing
116
+ * blocks to []). Returns `{ ok, schema, errors }` where `ok` is true when
117
+ * the repaired doc validates clean; `errors` retains anything the repair
118
+ * dropped plus any remaining validation errors.
119
+ */
120
+ validateAndRepair(doc: Any$2): RepairResult;
121
+ /** DOCX bytes for a doc (no temp file). Universal. Throws SchemaException if invalid. */
122
+ toBytes(doc: Any$2): Uint8Array;
123
+ /** Write a doc to disk as a .docx file (Node only). Throws SchemaException if invalid. */
124
+ write(doc: Any$2, path: string): Promise<WriteResult>;
125
+ /** Read .docx bytes back into the Doc model. Universal. */
126
+ read(input: Uint8Array | ArrayBuffer): Doc;
127
+ /** Alias for {@see read}. */
128
+ fromBytes(input: Uint8Array | ArrayBuffer): Doc;
129
+ /** Doc → GFM markdown (the Editor bridge). */
130
+ toMarkdown(doc: Any$2): string;
131
+ /** GFM markdown → Doc (the Editor bridge). */
132
+ fromMarkdown(markdown: string): Doc;
133
+ /** Plain-text summary of a doc: title, block counts by type, word count. */
134
+ describe(doc: Any$2): string;
135
+ /** JSON Schema export for LLM tool-use registration. */
136
+ jsonSchema(): Record<string, unknown>;
137
+ version(): string;
138
+ };
139
+
140
+ /** Thrown by Agent.write/toBytes when the schema is invalid. Mirrors PHP `SchemaException`. */
141
+ declare class SchemaException extends Error {
142
+ readonly errors: ValidationError[];
143
+ constructor(message: string, errors: ValidationError[]);
144
+ }
145
+
146
+ type Any$1 = any;
147
+ /** Liberal schema validator. Mirrors PHP `Schema\Validator`. */
148
+ declare class Validator {
149
+ validate(doc: Any$1): ValidationError[];
150
+ validateBlock(block: Any$1, path: string): ValidationError[];
151
+ private validateRuns;
152
+ private validateRun;
153
+ private validateListItem;
154
+ }
155
+
156
+ type Any = any;
157
+ /**
158
+ * Heuristic doc repair. Mirrors PHP `Schema\Repairer`. Never mutates input.
159
+ *
160
+ * Heuristics:
161
+ * - missing / non-array `blocks` → `[]`
162
+ * - bare strings in `blocks` → paragraphs; `runs: "text"` → `[{ text }]`;
163
+ * string entries inside a runs array → `{ text }`
164
+ * - heading levels clamped to 1..6 (non-numeric → 1)
165
+ * - unknown block types dropped, with the error retained in `notes`
166
+ * - list items given as strings → `{ runs: [{ text }] }`
167
+ */
168
+ declare class Repairer {
169
+ /** Errors describing content the last `repair()` call had to drop. */
170
+ notes: ValidationError[];
171
+ repair(docInput: Any): Record<string, unknown>;
172
+ private repairBlocks;
173
+ private repairBlock;
174
+ private repairRuns;
175
+ private repairListItems;
176
+ private repairRows;
177
+ }
178
+
179
+ /**
180
+ * Schema constants describing the Doc shape. Mirrors PHP `Schema\Schema`.
181
+ */
182
+ declare const Schema: {
183
+ VERSION: string;
184
+ BLOCK_TYPES: readonly ["heading", "paragraph", "list", "table", "code", "quote", "image", "pageBreak", "hr"];
185
+ ALIGNMENTS: readonly ["left", "center", "right", "justify"];
186
+ MAX_HEADING_LEVEL: number;
187
+ docRequiredKeys(): string[];
188
+ jsonSchema(): Record<string, unknown>;
189
+ };
190
+
191
+ /**
192
+ * DocxWriter — Doc JSON model → .docx bytes (OOXML / WordprocessingML).
193
+ * Deterministic: no timestamps, fixed zip entry order, rel ids assigned in
194
+ * traversal order. Mirrors PHP `Writer\DocxWriter`.
195
+ */
196
+
197
+ /** EMUs per pixel at 96 dpi. */
198
+ declare const EMU_PER_PX = 9525;
199
+ /** Content width cap: 6.5in at 96 dpi. */
200
+ declare const MAX_WIDTH_PX = 624;
201
+ declare class DocxWriter {
202
+ private rels;
203
+ private hyperlinkIds;
204
+ private media;
205
+ private drawingId;
206
+ toBytes(doc: Doc): Uint8Array;
207
+ private renderBlocks;
208
+ private renderBlock;
209
+ private paragraph;
210
+ private pPr;
211
+ private renderRuns;
212
+ private renderRun;
213
+ private hyperlinkRel;
214
+ private renderList;
215
+ private renderTable;
216
+ private renderCode;
217
+ private renderQuote;
218
+ private renderImage;
219
+ private sectPr;
220
+ private contentTypesXml;
221
+ private packageRelsXml;
222
+ private coreXml;
223
+ private documentRelsXml;
224
+ private stylesXml;
225
+ private numberingXml;
226
+ }
227
+ /**
228
+ * Resolve the rendered pixel size of an image block: explicit px win, missing
229
+ * dimensions are derived from the intrinsic (sniffed) size keeping aspect,
230
+ * and everything is capped at 6.5in width.
231
+ */
232
+ declare function resolveImageSize(block: {
233
+ widthPx?: number;
234
+ heightPx?: number;
235
+ }, bytes: Uint8Array): {
236
+ width: number;
237
+ height: number;
238
+ };
239
+
240
+ /**
241
+ * DocxReader — .docx bytes → Doc JSON model. Handles this package's own
242
+ * writer output losslessly (round-trip) and tolerates Word-authored files:
243
+ * headings via pStyle Heading1-9 OR outlineLvl, numPr lists with ilvl nesting,
244
+ * hyperlinks via rels, images via blip r:embed, page breaks, bottom-border-only
245
+ * paragraphs → hr. Unknown constructs degrade to plain paragraphs, never throw.
246
+ * Mirrors PHP `Reader\DocxReader`.
247
+ */
248
+
249
+ declare class DocxReader {
250
+ private parts;
251
+ private rels;
252
+ private numOrdered;
253
+ read(bytes: Uint8Array): Doc;
254
+ private partText;
255
+ private readTitle;
256
+ private loadRels;
257
+ private loadNumbering;
258
+ private walkBody;
259
+ private parseSdt;
260
+ private classifyParagraph;
261
+ /** Concatenated visible text of a paragraph (tabs and soft breaks included). */
262
+ private plainText;
263
+ private parseRuns;
264
+ private runFrom;
265
+ private buildLists;
266
+ private parseTable;
267
+ private parseDrawing;
268
+ }
269
+ /** Merge adjacent runs whose properties are identical (writer normalization). */
270
+ declare function mergeRuns(runs: Run[]): Run[];
271
+
272
+ /**
273
+ * Doc → GFM markdown — the Editor bridge. Hand-rolled (no external markdown
274
+ * dependency), mirroring PHP `Markdown\MarkdownBridge::toMarkdown`.
275
+ *
276
+ * Lossy by design where GFM has no syntax: underline / color / highlight
277
+ * decorations, paragraph alignment, image pixel sizes, and page breaks are
278
+ * dropped. Everything else round-trips through `fromMarkdown`.
279
+ */
280
+
281
+ declare function toMarkdown(doc: Doc): string;
282
+
283
+ /**
284
+ * GFM markdown → Doc — the Editor bridge. Hand-rolled line-based block parser
285
+ * plus an inline tokenizer (bold/italic/strike/code/links with backslash
286
+ * escapes). No external markdown dependency. Mirrors PHP
287
+ * `Markdown\MarkdownBridge::fromMarkdown`.
288
+ */
289
+
290
+ declare function fromMarkdown(markdown: string): Doc;
291
+ declare function parseInline(text: string): Run[];
292
+
293
+ /**
294
+ * Intrinsic image dimension sniffing (PNG IHDR / JPEG SOF) + data-URL decode.
295
+ * Zero-dependency, isomorphic — used by the writer to size `wp:extent` when
296
+ * `widthPx` / `heightPx` are omitted.
297
+ */
298
+ interface ImageSize {
299
+ width: number;
300
+ height: number;
301
+ }
302
+ interface DecodedDataUrl {
303
+ mime: string;
304
+ bytes: Uint8Array;
305
+ }
306
+ /** Decode a `data:image/…;base64,…` URL. Returns null for anything else. */
307
+ declare function parseDataUrl(src: string): DecodedDataUrl | null;
308
+ /** PNG IHDR width/height, or null when the bytes are not a PNG. */
309
+ declare function pngSize(bytes: Uint8Array): ImageSize | null;
310
+ /**
311
+ * JPEG width/height from the first SOF frame header (SOF0-SOF3, SOF5-SOF7,
312
+ * SOF9-SOF11, SOF13-SOF15), or null when the bytes are not a JPEG.
313
+ */
314
+ declare function jpegSize(bytes: Uint8Array): ImageSize | null;
315
+ /** Sniff intrinsic pixel dimensions from PNG or JPEG bytes. */
316
+ declare function sniffImageSize(bytes: Uint8Array): ImageSize | null;
317
+
318
+ interface ZipFile {
319
+ name: string;
320
+ data: Uint8Array;
321
+ }
322
+ declare function zipSync(files: ZipFile[]): Uint8Array;
323
+
324
+ declare function unzipSync(data: Uint8Array): Record<string, Uint8Array>;
325
+
326
+ export { Agent, type Align, type Block, type BlockType, type CodeBlock, type Doc, DocxReader, DocxWriter, EMU_PER_PX, type HeadingBlock, type HrBlock, type ImageBlock, type ListBlock, type ListItem, MAX_WIDTH_PX, type PageBreakBlock, type ParagraphBlock, type QuoteBlock, type RepairResult, Repairer, type Run, Schema, SchemaException, type TableBlock, type TableCell, type TableRow, VERSION, type ValidationError, Validator, type WriteResult, type ZipFile, fromMarkdown, jpegSize, mergeRuns, parseDataUrl, parseInline, pngSize, resolveImageSize, sniffImageSize, toMarkdown, unzipSync, zipSync };
@@ -0,0 +1,326 @@
1
+ /**
2
+ * Public document types — the LastWord JSON document model. Inputs are loose
3
+ * agent JSON, so most fields are optional and extra keys are tolerated; the
4
+ * Validator is the gate. Mirrors PHP `particle-academy/last-word`.
5
+ */
6
+ type BlockType = "heading" | "paragraph" | "list" | "table" | "code" | "quote" | "image" | "pageBreak" | "hr";
7
+ type Align = "left" | "center" | "right" | "justify";
8
+ /** Inline text span. Only `text` is required; all flags optional. */
9
+ interface Run {
10
+ text: string;
11
+ bold?: boolean;
12
+ italic?: boolean;
13
+ underline?: boolean;
14
+ strike?: boolean;
15
+ code?: boolean;
16
+ link?: string;
17
+ /** #RRGGBB */
18
+ color?: string;
19
+ /** #RRGGBB */
20
+ highlight?: string;
21
+ [key: string]: unknown;
22
+ }
23
+ interface ListItem {
24
+ runs: Run[];
25
+ children?: ListItem[];
26
+ [key: string]: unknown;
27
+ }
28
+ interface HeadingBlock {
29
+ type: "heading";
30
+ level: 1 | 2 | 3 | 4 | 5 | 6;
31
+ runs: Run[];
32
+ }
33
+ interface ParagraphBlock {
34
+ type: "paragraph";
35
+ runs: Run[];
36
+ align?: Align;
37
+ }
38
+ interface ListBlock {
39
+ type: "list";
40
+ ordered?: boolean;
41
+ items: ListItem[];
42
+ }
43
+ interface TableCell {
44
+ blocks: Block[];
45
+ [key: string]: unknown;
46
+ }
47
+ interface TableRow {
48
+ header?: boolean;
49
+ cells: TableCell[];
50
+ [key: string]: unknown;
51
+ }
52
+ interface TableBlock {
53
+ type: "table";
54
+ rows: TableRow[];
55
+ }
56
+ interface CodeBlock {
57
+ type: "code";
58
+ language?: string;
59
+ text: string;
60
+ }
61
+ interface QuoteBlock {
62
+ type: "quote";
63
+ blocks: Block[];
64
+ }
65
+ interface ImageBlock {
66
+ type: "image";
67
+ /** data:image/png;base64,… or data:image/jpeg;base64,… */
68
+ src: string;
69
+ widthPx?: number;
70
+ heightPx?: number;
71
+ alt?: string;
72
+ }
73
+ interface PageBreakBlock {
74
+ type: "pageBreak";
75
+ }
76
+ interface HrBlock {
77
+ type: "hr";
78
+ }
79
+ type Block = HeadingBlock | ParagraphBlock | ListBlock | TableBlock | CodeBlock | QuoteBlock | ImageBlock | PageBreakBlock | HrBlock;
80
+ interface Doc {
81
+ title?: string;
82
+ blocks: Block[];
83
+ [key: string]: unknown;
84
+ }
85
+ /** Structured validation error. Empty array = valid. */
86
+ interface ValidationError {
87
+ path: string;
88
+ message: string;
89
+ }
90
+ interface RepairResult {
91
+ ok: boolean;
92
+ schema: Doc;
93
+ errors: ValidationError[];
94
+ }
95
+ interface WriteResult {
96
+ path: string;
97
+ bytes: number;
98
+ blocks: number;
99
+ }
100
+
101
+ /**
102
+ * Agent — the structured-tool surface for LastWord. Mirrors PHP `Agent`.
103
+ * Universal methods are synchronous; file-touching methods (`write`) are async
104
+ * and Node-only (browsers have no sync FS).
105
+ */
106
+
107
+ /** Feature-parity baseline with PHP last-word; bumped independently on npm. */
108
+ declare const VERSION = "0.1.0";
109
+ type Any$2 = any;
110
+ declare const Agent: {
111
+ /** Validate a doc without writing. Empty array = valid. */
112
+ validate(doc: Any$2): ValidationError[];
113
+ /**
114
+ * Validate + apply heuristic repairs (coerce strings to runs, clamp heading
115
+ * levels, drop unknown block types with the error retained, default missing
116
+ * blocks to []). Returns `{ ok, schema, errors }` where `ok` is true when
117
+ * the repaired doc validates clean; `errors` retains anything the repair
118
+ * dropped plus any remaining validation errors.
119
+ */
120
+ validateAndRepair(doc: Any$2): RepairResult;
121
+ /** DOCX bytes for a doc (no temp file). Universal. Throws SchemaException if invalid. */
122
+ toBytes(doc: Any$2): Uint8Array;
123
+ /** Write a doc to disk as a .docx file (Node only). Throws SchemaException if invalid. */
124
+ write(doc: Any$2, path: string): Promise<WriteResult>;
125
+ /** Read .docx bytes back into the Doc model. Universal. */
126
+ read(input: Uint8Array | ArrayBuffer): Doc;
127
+ /** Alias for {@see read}. */
128
+ fromBytes(input: Uint8Array | ArrayBuffer): Doc;
129
+ /** Doc → GFM markdown (the Editor bridge). */
130
+ toMarkdown(doc: Any$2): string;
131
+ /** GFM markdown → Doc (the Editor bridge). */
132
+ fromMarkdown(markdown: string): Doc;
133
+ /** Plain-text summary of a doc: title, block counts by type, word count. */
134
+ describe(doc: Any$2): string;
135
+ /** JSON Schema export for LLM tool-use registration. */
136
+ jsonSchema(): Record<string, unknown>;
137
+ version(): string;
138
+ };
139
+
140
+ /** Thrown by Agent.write/toBytes when the schema is invalid. Mirrors PHP `SchemaException`. */
141
+ declare class SchemaException extends Error {
142
+ readonly errors: ValidationError[];
143
+ constructor(message: string, errors: ValidationError[]);
144
+ }
145
+
146
+ type Any$1 = any;
147
+ /** Liberal schema validator. Mirrors PHP `Schema\Validator`. */
148
+ declare class Validator {
149
+ validate(doc: Any$1): ValidationError[];
150
+ validateBlock(block: Any$1, path: string): ValidationError[];
151
+ private validateRuns;
152
+ private validateRun;
153
+ private validateListItem;
154
+ }
155
+
156
+ type Any = any;
157
+ /**
158
+ * Heuristic doc repair. Mirrors PHP `Schema\Repairer`. Never mutates input.
159
+ *
160
+ * Heuristics:
161
+ * - missing / non-array `blocks` → `[]`
162
+ * - bare strings in `blocks` → paragraphs; `runs: "text"` → `[{ text }]`;
163
+ * string entries inside a runs array → `{ text }`
164
+ * - heading levels clamped to 1..6 (non-numeric → 1)
165
+ * - unknown block types dropped, with the error retained in `notes`
166
+ * - list items given as strings → `{ runs: [{ text }] }`
167
+ */
168
+ declare class Repairer {
169
+ /** Errors describing content the last `repair()` call had to drop. */
170
+ notes: ValidationError[];
171
+ repair(docInput: Any): Record<string, unknown>;
172
+ private repairBlocks;
173
+ private repairBlock;
174
+ private repairRuns;
175
+ private repairListItems;
176
+ private repairRows;
177
+ }
178
+
179
+ /**
180
+ * Schema constants describing the Doc shape. Mirrors PHP `Schema\Schema`.
181
+ */
182
+ declare const Schema: {
183
+ VERSION: string;
184
+ BLOCK_TYPES: readonly ["heading", "paragraph", "list", "table", "code", "quote", "image", "pageBreak", "hr"];
185
+ ALIGNMENTS: readonly ["left", "center", "right", "justify"];
186
+ MAX_HEADING_LEVEL: number;
187
+ docRequiredKeys(): string[];
188
+ jsonSchema(): Record<string, unknown>;
189
+ };
190
+
191
+ /**
192
+ * DocxWriter — Doc JSON model → .docx bytes (OOXML / WordprocessingML).
193
+ * Deterministic: no timestamps, fixed zip entry order, rel ids assigned in
194
+ * traversal order. Mirrors PHP `Writer\DocxWriter`.
195
+ */
196
+
197
+ /** EMUs per pixel at 96 dpi. */
198
+ declare const EMU_PER_PX = 9525;
199
+ /** Content width cap: 6.5in at 96 dpi. */
200
+ declare const MAX_WIDTH_PX = 624;
201
+ declare class DocxWriter {
202
+ private rels;
203
+ private hyperlinkIds;
204
+ private media;
205
+ private drawingId;
206
+ toBytes(doc: Doc): Uint8Array;
207
+ private renderBlocks;
208
+ private renderBlock;
209
+ private paragraph;
210
+ private pPr;
211
+ private renderRuns;
212
+ private renderRun;
213
+ private hyperlinkRel;
214
+ private renderList;
215
+ private renderTable;
216
+ private renderCode;
217
+ private renderQuote;
218
+ private renderImage;
219
+ private sectPr;
220
+ private contentTypesXml;
221
+ private packageRelsXml;
222
+ private coreXml;
223
+ private documentRelsXml;
224
+ private stylesXml;
225
+ private numberingXml;
226
+ }
227
+ /**
228
+ * Resolve the rendered pixel size of an image block: explicit px win, missing
229
+ * dimensions are derived from the intrinsic (sniffed) size keeping aspect,
230
+ * and everything is capped at 6.5in width.
231
+ */
232
+ declare function resolveImageSize(block: {
233
+ widthPx?: number;
234
+ heightPx?: number;
235
+ }, bytes: Uint8Array): {
236
+ width: number;
237
+ height: number;
238
+ };
239
+
240
+ /**
241
+ * DocxReader — .docx bytes → Doc JSON model. Handles this package's own
242
+ * writer output losslessly (round-trip) and tolerates Word-authored files:
243
+ * headings via pStyle Heading1-9 OR outlineLvl, numPr lists with ilvl nesting,
244
+ * hyperlinks via rels, images via blip r:embed, page breaks, bottom-border-only
245
+ * paragraphs → hr. Unknown constructs degrade to plain paragraphs, never throw.
246
+ * Mirrors PHP `Reader\DocxReader`.
247
+ */
248
+
249
+ declare class DocxReader {
250
+ private parts;
251
+ private rels;
252
+ private numOrdered;
253
+ read(bytes: Uint8Array): Doc;
254
+ private partText;
255
+ private readTitle;
256
+ private loadRels;
257
+ private loadNumbering;
258
+ private walkBody;
259
+ private parseSdt;
260
+ private classifyParagraph;
261
+ /** Concatenated visible text of a paragraph (tabs and soft breaks included). */
262
+ private plainText;
263
+ private parseRuns;
264
+ private runFrom;
265
+ private buildLists;
266
+ private parseTable;
267
+ private parseDrawing;
268
+ }
269
+ /** Merge adjacent runs whose properties are identical (writer normalization). */
270
+ declare function mergeRuns(runs: Run[]): Run[];
271
+
272
+ /**
273
+ * Doc → GFM markdown — the Editor bridge. Hand-rolled (no external markdown
274
+ * dependency), mirroring PHP `Markdown\MarkdownBridge::toMarkdown`.
275
+ *
276
+ * Lossy by design where GFM has no syntax: underline / color / highlight
277
+ * decorations, paragraph alignment, image pixel sizes, and page breaks are
278
+ * dropped. Everything else round-trips through `fromMarkdown`.
279
+ */
280
+
281
+ declare function toMarkdown(doc: Doc): string;
282
+
283
+ /**
284
+ * GFM markdown → Doc — the Editor bridge. Hand-rolled line-based block parser
285
+ * plus an inline tokenizer (bold/italic/strike/code/links with backslash
286
+ * escapes). No external markdown dependency. Mirrors PHP
287
+ * `Markdown\MarkdownBridge::fromMarkdown`.
288
+ */
289
+
290
+ declare function fromMarkdown(markdown: string): Doc;
291
+ declare function parseInline(text: string): Run[];
292
+
293
+ /**
294
+ * Intrinsic image dimension sniffing (PNG IHDR / JPEG SOF) + data-URL decode.
295
+ * Zero-dependency, isomorphic — used by the writer to size `wp:extent` when
296
+ * `widthPx` / `heightPx` are omitted.
297
+ */
298
+ interface ImageSize {
299
+ width: number;
300
+ height: number;
301
+ }
302
+ interface DecodedDataUrl {
303
+ mime: string;
304
+ bytes: Uint8Array;
305
+ }
306
+ /** Decode a `data:image/…;base64,…` URL. Returns null for anything else. */
307
+ declare function parseDataUrl(src: string): DecodedDataUrl | null;
308
+ /** PNG IHDR width/height, or null when the bytes are not a PNG. */
309
+ declare function pngSize(bytes: Uint8Array): ImageSize | null;
310
+ /**
311
+ * JPEG width/height from the first SOF frame header (SOF0-SOF3, SOF5-SOF7,
312
+ * SOF9-SOF11, SOF13-SOF15), or null when the bytes are not a JPEG.
313
+ */
314
+ declare function jpegSize(bytes: Uint8Array): ImageSize | null;
315
+ /** Sniff intrinsic pixel dimensions from PNG or JPEG bytes. */
316
+ declare function sniffImageSize(bytes: Uint8Array): ImageSize | null;
317
+
318
+ interface ZipFile {
319
+ name: string;
320
+ data: Uint8Array;
321
+ }
322
+ declare function zipSync(files: ZipFile[]): Uint8Array;
323
+
324
+ declare function unzipSync(data: Uint8Array): Record<string, Uint8Array>;
325
+
326
+ export { Agent, type Align, type Block, type BlockType, type CodeBlock, type Doc, DocxReader, DocxWriter, EMU_PER_PX, type HeadingBlock, type HrBlock, type ImageBlock, type ListBlock, type ListItem, MAX_WIDTH_PX, type PageBreakBlock, type ParagraphBlock, type QuoteBlock, type RepairResult, Repairer, type Run, Schema, SchemaException, type TableBlock, type TableCell, type TableRow, VERSION, type ValidationError, Validator, type WriteResult, type ZipFile, fromMarkdown, jpegSize, mergeRuns, parseDataUrl, parseInline, pngSize, resolveImageSize, sniffImageSize, toMarkdown, unzipSync, zipSync };