@mdzip/core-js 1.2.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.
@@ -0,0 +1,866 @@
1
+ type MdzCoreZipAsyncKind = 'text' | 'base64' | 'arraybuffer';
2
+ /**
3
+ * Binary input accepted for opening an existing `.mdz` archive.
4
+ */
5
+ export type MdzCoreArchiveBinary = Blob | ArrayBuffer | Uint8Array;
6
+ /**
7
+ * Content input accepted when mutating archive entries.
8
+ *
9
+ * String values are written as UTF-8 text; binary values are written as raw bytes.
10
+ */
11
+ export type MdzArchiveMutationInput = File | Blob | ArrayBuffer | Uint8Array | string;
12
+ interface ZipEntry {
13
+ name: string;
14
+ dir: boolean;
15
+ async(kind: MdzCoreZipAsyncKind): Promise<string | ArrayBuffer>;
16
+ }
17
+ interface ZipLike {
18
+ files: Record<string, ZipEntry>;
19
+ }
20
+ interface ZipFactoryLike {
21
+ loadAsync(data: MdzCoreArchiveBinary): Promise<ZipLike>;
22
+ }
23
+ interface ZipWriterLike {
24
+ file(path: string, data: string | ArrayBuffer | Uint8Array): void;
25
+ generateAsync(options: {
26
+ type: 'blob';
27
+ compression: 'DEFLATE';
28
+ compressionOptions: {
29
+ level: number;
30
+ };
31
+ }): Promise<Blob>;
32
+ }
33
+ interface ZipWriterFactoryLike {
34
+ create(): ZipWriterLike;
35
+ }
36
+ /**
37
+ * Author/contact metadata used by manifest fields.
38
+ */
39
+ export interface MdzManifestAuthor {
40
+ /** Human-readable display name. */
41
+ name?: string;
42
+ /** Optional contact email address. */
43
+ email?: string;
44
+ /** Optional author profile/home URL. */
45
+ url?: string;
46
+ }
47
+ /**
48
+ * Identity metadata used by timestamp `by` blocks.
49
+ */
50
+ export interface MdzManifestBy {
51
+ /** Display name for creator/modifier attribution. */
52
+ name?: string;
53
+ /** Optional contact email address. */
54
+ email?: string;
55
+ /** Optional profile/home URL. */
56
+ url?: string;
57
+ }
58
+ /**
59
+ * Object-form timestamp metadata used by draft 1.0.x manifests.
60
+ */
61
+ export interface MdzManifestTimestampObject {
62
+ /** ISO-8601 timestamp value. */
63
+ when: string;
64
+ /** Optional identity metadata for who performed the action. */
65
+ by?: MdzManifestBy;
66
+ }
67
+ /**
68
+ * Specification compatibility metadata for the archive manifest.
69
+ */
70
+ export interface MdzManifestSpec {
71
+ /** Spec identifier (for example `mdzip-spec`). */
72
+ name?: string;
73
+ /** Target spec version string (semver). */
74
+ version?: string;
75
+ }
76
+ /**
77
+ * Producer metadata node describing an app/core identity.
78
+ */
79
+ export interface MdzManifestProducerNode {
80
+ /** Producer display name. */
81
+ name?: string;
82
+ /** Producer version string. */
83
+ version?: string;
84
+ /** Producer homepage/repository URL. */
85
+ url?: string;
86
+ }
87
+ /**
88
+ * Producer metadata grouping for application and reusable core.
89
+ */
90
+ export interface MdzManifestProducer {
91
+ /** Top-level application/tool metadata. */
92
+ application?: MdzManifestProducerNode;
93
+ /** Reusable core/runtime metadata used by the producer app. */
94
+ core?: MdzManifestProducerNode;
95
+ }
96
+ /**
97
+ * Optional file-map entry used when source files are remapped during packaging.
98
+ */
99
+ export interface MdzManifestFileMapEntry {
100
+ /** Final archive-relative path after normalization/sanitization. */
101
+ path: string;
102
+ /** Original source-relative path before remapping. */
103
+ originalPath: string;
104
+ /** Human-friendly title derived from file name/source. */
105
+ title: string;
106
+ }
107
+ /**
108
+ * Supported archive interpretation modes defined by the spec.
109
+ */
110
+ export type MdzManifestMode = 'document' | 'project';
111
+ /**
112
+ * Parsed shape of `manifest.json` as supported by this library.
113
+ *
114
+ * Includes current fields plus legacy draft compatibility fields.
115
+ */
116
+ export interface MdzManifest {
117
+ /** Legacy pre-`spec.version` manifest version field. */
118
+ mdz?: string;
119
+ /** Specification compatibility metadata. */
120
+ spec?: MdzManifestSpec;
121
+ /** Producer provenance metadata. */
122
+ producer?: MdzManifestProducer;
123
+ /** Primary author attribution metadata. */
124
+ author?: MdzManifestAuthor;
125
+ /** Human-readable document title. */
126
+ title?: string;
127
+ /** Archive interpretation mode. */
128
+ mode?: MdzManifestMode;
129
+ /** Primary Markdown entry path, archive-relative. */
130
+ entryPoint?: string | null;
131
+ /** Natural language tag (for example `en`, `fr-CA`). */
132
+ language?: string | null;
133
+ /** Legacy plural author field retained for compatibility. */
134
+ authors?: MdzManifestAuthor[] | null;
135
+ /** Short document summary/description. */
136
+ description?: string | null;
137
+ /** Document version (not spec version). */
138
+ version?: string | null;
139
+ /** Creation timestamp (string or draft object form). */
140
+ created?: string | MdzManifestTimestampObject;
141
+ /** Last-modified timestamp (string or draft object form). */
142
+ modified?: string | MdzManifestTimestampObject;
143
+ /** SPDX ID or license URL. */
144
+ license?: string;
145
+ /** Keyword list used for cataloging/search. */
146
+ keywords?: string[];
147
+ /** Archive-relative cover asset path. */
148
+ cover?: string;
149
+ /** Optional file-map metadata generated during packing. */
150
+ files?: MdzManifestFileMapEntry[];
151
+ }
152
+ /**
153
+ * Packaging options used by {@link MdzPackagerCore.buildArchive}.
154
+ */
155
+ export interface MdzPackOptions {
156
+ /** Generate `index.md` when no unambiguous entry point exists. */
157
+ createIndex: boolean;
158
+ /** Enable path sanitization and include manifest file-map metadata. */
159
+ mapFiles: boolean;
160
+ /** Glob filters that determine which input files are included. */
161
+ filters: string[];
162
+ /** Optional manifest title override. */
163
+ title?: string | null;
164
+ /** Optional archive interpretation mode. */
165
+ mode?: MdzManifestMode | null;
166
+ /** Optional manifest entry point override. */
167
+ entryPoint?: string | null;
168
+ /** Optional language tag override. */
169
+ language?: string | null;
170
+ /** Optional single-author display name. */
171
+ author?: string | null;
172
+ /** Optional manifest description override. */
173
+ description?: string | null;
174
+ /** Optional document version field value. */
175
+ docVersion?: string | null;
176
+ }
177
+ /**
178
+ * Single source file candidate for packaging.
179
+ */
180
+ export interface MdzPackInputFile {
181
+ /** Source-relative path used as the archive path candidate. */
182
+ path: string;
183
+ /** Browser `File` source for binary/text loading. */
184
+ file?: File;
185
+ /** Direct binary source when not providing `file`. */
186
+ data?: ArrayBuffer | Uint8Array | Blob;
187
+ /** Direct text source when not providing `file`. */
188
+ text?: string;
189
+ }
190
+ /**
191
+ * Internal/returned representation of a file selected for archive output.
192
+ */
193
+ export interface MdzSelectedFile {
194
+ /** Final archive-relative output path. */
195
+ archivePath: string;
196
+ /** Original source path before remapping/sanitization. */
197
+ originalPath: string;
198
+ /** Original `File` input when provided. */
199
+ file?: File;
200
+ /** In-memory binary content when provided/generated. */
201
+ data?: ArrayBuffer | Uint8Array | Blob;
202
+ /** In-memory text content when provided/generated. */
203
+ text?: string;
204
+ }
205
+ /**
206
+ * Non-fatal packaging warnings and counters produced during archive build.
207
+ */
208
+ export interface MdzPackWarnings {
209
+ /** Count of source paths that failed strict archive path validation. */
210
+ invalidPathCount: number;
211
+ /** Count of paths that were sanitized and remapped. */
212
+ sanitizedPathCount: number;
213
+ /** Breakdown of skipped files by reason key. */
214
+ skippedByReason: Record<string, number>;
215
+ /** Advisory packaging warnings for callers to surface to users. */
216
+ messages?: string[];
217
+ /** True when no entry point could be resolved at build completion. */
218
+ unresolvedEntry: boolean;
219
+ }
220
+ /**
221
+ * Result object returned by archive build operations.
222
+ */
223
+ export interface MdzPackBuildResult {
224
+ /** Final archive blob payload. */
225
+ blob: Blob;
226
+ /** Manifest written to archive, when present. */
227
+ manifest: MdzManifest | null;
228
+ /** Resolved primary entry path (or `null`). */
229
+ resolvedEntryPoint: string | null;
230
+ /** All file paths written into the archive. */
231
+ archivePaths: string[];
232
+ /** Detailed selection list for included/generated files. */
233
+ selected: MdzSelectedFile[];
234
+ /** Packaging warnings/counters. */
235
+ warnings: MdzPackWarnings;
236
+ }
237
+ /**
238
+ * Conformance validation summary for an archive.
239
+ */
240
+ export interface MdzValidationResult {
241
+ /** True when no validation errors were found. */
242
+ isValid: boolean;
243
+ /** Fatal/non-conformant issues discovered during validation. */
244
+ errors: string[];
245
+ /** Non-fatal advisory findings discovered during validation. */
246
+ warnings: string[];
247
+ }
248
+ /**
249
+ * Compact validation state for UI save/status indicators.
250
+ */
251
+ export type MdzValidationStatus = 'valid' | 'warning' | 'error';
252
+ /**
253
+ * Result object returned by archive mutation operations.
254
+ */
255
+ export interface MdzArchiveMutationResult {
256
+ /** New archive blob generated after mutation. */
257
+ blob: Blob;
258
+ /** Parsed manifest after mutation, when present. */
259
+ manifest: MdzManifest | null;
260
+ /** Resolved primary entry path after mutation, if any. */
261
+ resolvedEntryPoint: string | null;
262
+ /** Archive file paths present after mutation. */
263
+ archivePaths: string[];
264
+ }
265
+ /**
266
+ * Controls archive path/entry listing output.
267
+ */
268
+ export interface MdzArchiveListOptions {
269
+ /** Include directory entries. Defaults to `false`. */
270
+ includeDirectories?: boolean;
271
+ /** Normalize paths via `normalizePath`. Defaults to `true`. */
272
+ normalize?: boolean;
273
+ /** Sort output paths case-insensitively. Defaults to `true`. */
274
+ sort?: boolean;
275
+ }
276
+ /**
277
+ * Metadata for one archive entry returned by `listEntries`.
278
+ */
279
+ export interface MdzArchiveEntryInfo {
280
+ /** Archive-relative path. */
281
+ path: string;
282
+ /** True when entry extension is Markdown. */
283
+ isMarkdown: boolean;
284
+ /** True when entry extension is known image type. */
285
+ isImage: boolean;
286
+ /** True when entry is a directory. */
287
+ isDirectory: boolean;
288
+ }
289
+ /**
290
+ * Optional controls for orphaned-asset analysis.
291
+ */
292
+ export interface MdzOrphanedAssetsOptions {
293
+ /**
294
+ * Markdown scan mode.
295
+ * - `entrypoint`: scan only the resolved/selected entry point (default)
296
+ * - `all-markdown`: scan all Markdown files in archive
297
+ */
298
+ scanMode?: 'entrypoint' | 'all-markdown';
299
+ /** Optional explicit markdown entry path to scan for `entrypoint` mode. */
300
+ entryPoint?: string;
301
+ }
302
+ /**
303
+ * One unresolved or ignored image reference observed during scan.
304
+ */
305
+ export interface MdzOrphanedAssetReferenceIssue {
306
+ /** Markdown file where the reference was found. */
307
+ sourcePath: string;
308
+ /** Raw reference value from Markdown. */
309
+ reference: string;
310
+ /** Normalized reason for why the reference was not counted. */
311
+ reason: 'unsupported-scheme' | 'invalid-path' | 'not-found' | 'not-asset';
312
+ }
313
+ /**
314
+ * Result for orphaned image analysis.
315
+ */
316
+ export interface MdzOrphanedAssetsResult {
317
+ /** Markdown files scanned for references. */
318
+ scannedMarkdownPaths: string[];
319
+ /** All image-asset paths in archive considered by v1 analysis. */
320
+ assetPaths: string[];
321
+ /** Asset paths referenced by scanned markdown and/or manifest cover. */
322
+ referencedAssetPaths: string[];
323
+ /** Asset paths not referenced by scanned markdown/cover. */
324
+ orphanedAssetPaths: string[];
325
+ /** References that could not be counted as valid image asset references. */
326
+ unresolvedReferences: MdzOrphanedAssetReferenceIssue[];
327
+ }
328
+ /**
329
+ * Asset classification used by normalized workspace models.
330
+ */
331
+ export type MdzWorkspaceAssetKind = 'image' | 'audio' | 'video' | 'font' | 'data' | 'other';
332
+ /**
333
+ * Options for opening an archive as an app-friendly workspace.
334
+ */
335
+ export interface MdzOpenWorkspaceOptions {
336
+ /** Include orphaned image analysis in the returned workspace. Defaults to `false`. */
337
+ includeOrphanedAssetAnalysis?: boolean;
338
+ /** Scan mode used when orphaned analysis is enabled. Defaults to `entrypoint`. */
339
+ orphanedAssetScanMode?: 'entrypoint' | 'all-markdown';
340
+ /** Include lazy `readBytes` and `readDataUri` functions on assets. Defaults to `true`. */
341
+ includeLazyAssetReaders?: boolean;
342
+ }
343
+ /**
344
+ * One Markdown document in an opened workspace.
345
+ */
346
+ export interface MdzWorkspaceDocument {
347
+ /** Archive-relative document path. */
348
+ path: string;
349
+ /** Human-readable title for app navigation. */
350
+ title: string;
351
+ /** UTF-8 Markdown source text. */
352
+ text: string;
353
+ /** True when this document is the resolved archive entry point. */
354
+ isEntryPoint: boolean;
355
+ }
356
+ /**
357
+ * One non-Markdown, non-manifest asset in an opened workspace.
358
+ */
359
+ export interface MdzWorkspaceAsset {
360
+ /** Archive-relative asset path. */
361
+ path: string;
362
+ /** Base file name. */
363
+ fileName: string;
364
+ /** Asset byte length. */
365
+ byteSize: number;
366
+ /** Inferred MIME type. */
367
+ mimeType: string;
368
+ /** Broad asset kind inferred from MIME type/extension. */
369
+ kind: MdzWorkspaceAssetKind;
370
+ /** True when common browser preview surfaces can display the asset. */
371
+ isPreviewable: boolean;
372
+ /** Optional in-memory bytes used by buildWorkspace/import flows. */
373
+ bytes?: ArrayBuffer | Uint8Array | Blob;
374
+ /** Lazy byte reader for archives opened through `openWorkspace`. */
375
+ readBytes?: () => Promise<Uint8Array>;
376
+ /** Lazy data-URI reader for previewable assets. */
377
+ readDataUri?: () => Promise<string>;
378
+ }
379
+ /**
380
+ * Normalized archive workspace for app shells and editor hosts.
381
+ */
382
+ export interface MdzWorkspace {
383
+ /** Manifest title, or `null` when unavailable. */
384
+ title: string | null;
385
+ /** Resolved archive interpretation mode. */
386
+ mode: MdzManifestMode;
387
+ /** Parsed manifest when present and valid. */
388
+ manifest: MdzManifest | null;
389
+ /** Resolved primary Markdown entry path, or `null` when unresolved. */
390
+ entryPoint: string | null;
391
+ /** All Markdown documents in archive path order. */
392
+ documents: MdzWorkspaceDocument[];
393
+ /** All non-Markdown, non-manifest assets in archive path order. */
394
+ assets: MdzWorkspaceAsset[];
395
+ /** Archive validation summary. */
396
+ validation: MdzValidationResult;
397
+ /** Optional orphaned image analysis. */
398
+ orphanedAssets?: MdzOrphanedAssetsResult;
399
+ }
400
+ /**
401
+ * App-safe manifest metadata fields.
402
+ */
403
+ export interface MdzManifestEditableMetadata {
404
+ title?: string | null;
405
+ author?: MdzManifestAuthor | string | null;
406
+ description?: string | null;
407
+ keywords?: string[] | null;
408
+ language?: string | null;
409
+ license?: string | null;
410
+ version?: string | null;
411
+ cover?: string | null;
412
+ }
413
+ /**
414
+ * Spec-managed manifest fields apps should normally avoid free-form editing.
415
+ */
416
+ export interface MdzManifestReservedFields {
417
+ spec?: MdzManifestSpec;
418
+ producer?: MdzManifestProducer;
419
+ created?: string | MdzManifestTimestampObject;
420
+ modified?: string | MdzManifestTimestampObject;
421
+ entryPoint?: string | null;
422
+ mode?: MdzManifestMode;
423
+ files?: MdzManifestFileMapEntry[];
424
+ }
425
+ /**
426
+ * Options for canonical manifest creation and updates.
427
+ */
428
+ export interface MdzManifestUpdateOptions {
429
+ /** Set `created` when creating a new manifest. Defaults to `true`. */
430
+ setCreatedIfMissing?: boolean;
431
+ /** Refresh `modified`. Defaults to `true`. */
432
+ refreshModified?: boolean;
433
+ }
434
+ /**
435
+ * Options for building an archive from a normalized workspace.
436
+ */
437
+ export interface MdzBuildWorkspaceOptions {
438
+ /** Fallback root/source label. Defaults to workspace title or `MDZip Workspace`. */
439
+ rootName?: string;
440
+ /** Optional manifest metadata updates applied before packaging. */
441
+ metadata?: MdzManifestEditableMetadata;
442
+ /** Optional title override. */
443
+ title?: string | null;
444
+ /** Optional mode override. */
445
+ mode?: MdzManifestMode | null;
446
+ /** Optional entry point override. */
447
+ entryPoint?: string | null;
448
+ }
449
+ /**
450
+ * Generic archive path tree node for navigation UIs.
451
+ */
452
+ export interface MdzPathTreeNode {
453
+ /** Node display name. */
454
+ name: string;
455
+ /** Archive-relative path. */
456
+ path: string;
457
+ /** True for inferred folder nodes. */
458
+ isDirectory: boolean;
459
+ /** Child nodes for directory entries. */
460
+ children: MdzPathTreeNode[];
461
+ }
462
+ /**
463
+ * Extension-to-MIME map for common image assets in MDZip archives.
464
+ */
465
+ export declare const MDZ_IMAGE_MIME_TYPES: Record<string, string>;
466
+ /**
467
+ * Core archive reader/validator/mutator for `.mdz` files.
468
+ */
469
+ export declare class MdzArchiveCore {
470
+ private readonly zip;
471
+ /**
472
+ * Public image MIME map for consumers.
473
+ */
474
+ static readonly IMAGE_MIME_TYPES: Record<string, string>;
475
+ private static readonly SUPPORTED_MDZ_MAJOR;
476
+ private static readonly SUPPORTED_MODES;
477
+ private static readonly SEMVER_RE;
478
+ private static readonly MARKDOWN_IMAGE_REF_RE;
479
+ private static readonly entriesCache;
480
+ private static readonly manifestCache;
481
+ /**
482
+ * Creates an archive wrapper around a previously loaded ZIP object.
483
+ *
484
+ * @param zip - Loaded zip-like structure containing archive entries.
485
+ */
486
+ constructor(zip: ZipLike);
487
+ /**
488
+ * Opens archive binary data and returns a core archive instance.
489
+ *
490
+ * @param input - Raw archive bytes.
491
+ * @param zipFactory - Optional custom zip loader.
492
+ */
493
+ static open(input: MdzCoreArchiveBinary, zipFactory?: ZipFactoryLike): Promise<MdzArchiveCore>;
494
+ /**
495
+ * Convenience helper to open and validate an archive in one call.
496
+ *
497
+ * @param input - Raw archive bytes.
498
+ * @param zipFactory - Optional custom zip loader.
499
+ */
500
+ static validate(input: MdzCoreArchiveBinary, zipFactory?: ZipFactoryLike): Promise<MdzValidationResult>;
501
+ /**
502
+ * Adds or replaces an archive entry and returns a newly generated archive blob.
503
+ *
504
+ * Also validates entry-point integrity and refreshes manifest metadata when present.
505
+ *
506
+ * @param input - Existing archive bytes.
507
+ * @param archiveEntryPath - Archive-relative destination path.
508
+ * @param content - New entry content.
509
+ */
510
+ static addFile(input: MdzCoreArchiveBinary, archiveEntryPath: string, content: MdzArchiveMutationInput): Promise<MdzArchiveMutationResult>;
511
+ /**
512
+ * Removes an archive entry and returns a newly generated archive blob.
513
+ *
514
+ * Also validates entry-point integrity and refreshes manifest metadata when present.
515
+ *
516
+ * @param input - Existing archive bytes.
517
+ * @param archiveEntryPath - Archive-relative path to remove.
518
+ */
519
+ static removeFile(input: MdzCoreArchiveBinary, archiveEntryPath: string): Promise<MdzArchiveMutationResult>;
520
+ /**
521
+ * Removes multiple archive entries in one mutation operation.
522
+ *
523
+ * @param input - Existing archive bytes.
524
+ * @param archiveEntryPaths - Archive-relative paths to remove.
525
+ */
526
+ static removeFiles(input: MdzCoreArchiveBinary, archiveEntryPaths: string[]): Promise<MdzArchiveMutationResult>;
527
+ /**
528
+ * Finds orphaned image assets in an archive.
529
+ *
530
+ * @param input - Existing archive bytes.
531
+ * @param options - Scan options.
532
+ */
533
+ static findOrphanedAssets(input: MdzCoreArchiveBinary, options?: MdzOrphanedAssetsOptions): Promise<MdzOrphanedAssetsResult>;
534
+ /**
535
+ * Opens archive binary data and returns an app-friendly normalized workspace model.
536
+ *
537
+ * @param input - Raw archive bytes.
538
+ * @param options - Workspace open controls.
539
+ * @param zipFactory - Optional custom zip loader.
540
+ */
541
+ static openWorkspace(input: MdzCoreArchiveBinary, options?: MdzOpenWorkspaceOptions, zipFactory?: ZipFactoryLike): Promise<MdzWorkspace>;
542
+ private static getDefaultZipFactory;
543
+ private static loadZip;
544
+ /**
545
+ * Normalizes path separators and strips leading slashes.
546
+ *
547
+ * @param path - Any input path.
548
+ */
549
+ static normalizePath(path: string): string;
550
+ /**
551
+ * Returns true if the provided path looks like a Markdown document path.
552
+ *
553
+ * @param path - Archive-relative path.
554
+ */
555
+ static isMarkdownFile(path: string): boolean;
556
+ /**
557
+ * Infers a MIME type from an archive path.
558
+ *
559
+ * @param path - Archive-relative path.
560
+ * @param fallbackMime - MIME type used when extension is unknown.
561
+ */
562
+ static inferMimeType(path: string, fallbackMime?: string): string;
563
+ /**
564
+ * Classifies an asset using path extension and MIME type.
565
+ *
566
+ * @param path - Archive-relative path.
567
+ * @param mimeType - Optional known MIME type.
568
+ */
569
+ static classifyAssetKind(path: string, mimeType?: string): MdzWorkspaceAssetKind;
570
+ /**
571
+ * Returns true when common browser surfaces can preview this asset.
572
+ *
573
+ * @param path - Archive-relative path.
574
+ * @param mimeType - Optional known MIME type.
575
+ */
576
+ static isPreviewableAsset(path: string, mimeType?: string): boolean;
577
+ /**
578
+ * Converts validation details into a compact status.
579
+ *
580
+ * @param result - Validation result.
581
+ */
582
+ static getValidationStatus(result: MdzValidationResult): MdzValidationStatus;
583
+ /**
584
+ * Returns a case-insensitive, normalized archive path sort.
585
+ *
586
+ * @param paths - Archive-relative paths.
587
+ */
588
+ static sortArchivePaths(paths: string[]): string[];
589
+ /**
590
+ * Returns the archive-relative directory name for a path.
591
+ *
592
+ * @param path - Archive-relative path.
593
+ */
594
+ static dirname(path: string): string;
595
+ /**
596
+ * Returns the final path segment for an archive-relative path.
597
+ *
598
+ * @param path - Archive-relative path.
599
+ */
600
+ static basename(path: string): string;
601
+ /**
602
+ * Builds a generic inferred folder tree from archive-relative paths.
603
+ *
604
+ * @param paths - Archive-relative paths.
605
+ */
606
+ static buildPathTree(paths: string[]): MdzPathTreeNode[];
607
+ /**
608
+ * Validates archive path constraints.
609
+ *
610
+ * @param path - Archive-relative path.
611
+ * @returns `null` when valid, otherwise a short reason string.
612
+ */
613
+ static validateArchivePath(path: string): string | null;
614
+ private static dirOf;
615
+ /**
616
+ * Resolves a relative Markdown link target against an archive base path.
617
+ *
618
+ * Query/hash fragments are stripped and traversal beyond archive root is rejected.
619
+ *
620
+ * @param base - Referencing file path.
621
+ * @param relative - Relative target path from markdown/link source.
622
+ */
623
+ static resolvePath(base: string, relative: string): string;
624
+ /**
625
+ * Finds an archive entry by path (case-insensitive fallback).
626
+ *
627
+ * @param path - Archive-relative path.
628
+ */
629
+ findEntry(path: string): ZipEntry | null;
630
+ /**
631
+ * Lists archive paths.
632
+ *
633
+ * @param options - Listing controls.
634
+ */
635
+ listPaths(options?: MdzArchiveListOptions): string[];
636
+ /**
637
+ * Lists archive entries with basic type metadata.
638
+ *
639
+ * @param options - Listing controls.
640
+ */
641
+ listEntries(options?: MdzArchiveListOptions): MdzArchiveEntryInfo[];
642
+ /**
643
+ * Returns true if an entry path exists (file or directory).
644
+ *
645
+ * @param path - Archive-relative path.
646
+ */
647
+ hasEntry(path: string): boolean;
648
+ /**
649
+ * Reads UTF-8 text content from an entry.
650
+ *
651
+ * @param path - Archive-relative file path.
652
+ */
653
+ readText(path: string): Promise<string>;
654
+ /**
655
+ * Reads raw bytes from an entry.
656
+ *
657
+ * @param path - Archive-relative file path.
658
+ */
659
+ readBytes(path: string): Promise<Uint8Array>;
660
+ /**
661
+ * Reads entry content as raw base64 (no data URI prefix).
662
+ *
663
+ * @param path - Archive-relative file path.
664
+ */
665
+ readBase64(path: string): Promise<string>;
666
+ /**
667
+ * Reads entry content and returns a data URI string.
668
+ *
669
+ * @param path - Archive-relative file path.
670
+ * @param fallbackMime - Optional fallback MIME when extension is unknown.
671
+ */
672
+ readDataUri(path: string, fallbackMime?: string): Promise<string>;
673
+ /**
674
+ * Finds orphaned image assets from markdown references.
675
+ *
676
+ * @param options - Scan options.
677
+ */
678
+ findOrphanedAssets(options?: MdzOrphanedAssetsOptions): Promise<MdzOrphanedAssetsResult>;
679
+ /**
680
+ * Returns a normalized app/editor workspace model for this archive.
681
+ *
682
+ * @param options - Workspace open controls.
683
+ */
684
+ openWorkspace(options?: MdzOpenWorkspaceOptions): Promise<MdzWorkspace>;
685
+ static validateManifest(manifest: unknown): asserts manifest is MdzManifest;
686
+ /**
687
+ * Parses and validates `manifest.json` if present.
688
+ *
689
+ * Missing or invalid cover references are normalized away in returned data.
690
+ */
691
+ readManifest(): Promise<MdzManifest | null>;
692
+ /**
693
+ * Resolves archive interpretation mode using manifest data or the spec default.
694
+ */
695
+ resolveMode(): Promise<MdzManifestMode>;
696
+ /**
697
+ * Validates archive conformance and returns errors/warnings.
698
+ */
699
+ validate(): Promise<MdzValidationResult>;
700
+ /**
701
+ * Resolves the primary markdown entry point for rendering.
702
+ *
703
+ * @throws When no unambiguous entry point can be determined.
704
+ */
705
+ resolveEntryPoint(): Promise<string>;
706
+ private static getArchivePaths;
707
+ private static getArchiveEntries;
708
+ private findEntryWithDirectoryFallback;
709
+ private getFileEntryOrThrow;
710
+ private static getPathExtension;
711
+ private static isImagePath;
712
+ private static getDocumentTitle;
713
+ private static extractMarkdownImageReferences;
714
+ private static cleanMarkdownLinkTarget;
715
+ private static hasUriScheme;
716
+ private static resolveAssetPathCase;
717
+ private static removeEntryIgnoreCase;
718
+ private static isTextFile;
719
+ private static normaliseLf;
720
+ private static readExistingManifestObject;
721
+ private static parseManifestObjectContent;
722
+ private static ensureManifestSpecObject;
723
+ private static stampManifestObject;
724
+ private static ensureCreatableEntryPoint;
725
+ private static readMutationInputAsText;
726
+ private static readMutationInputAsBinary;
727
+ private static writeZipEntry;
728
+ private static finalizeMutation;
729
+ }
730
+ /**
731
+ * Packaging helpers for creating `.mdz` archives from source files.
732
+ */
733
+ export declare class MdzPackagerCore {
734
+ /**
735
+ * Default include globs for markdown and common image assets.
736
+ */
737
+ static readonly DEFAULT_FILTERS: string[];
738
+ /**
739
+ * Normalizes input file paths for archive packaging.
740
+ *
741
+ * @param path - Source file path.
742
+ */
743
+ static normalizePath(path: string): string;
744
+ /**
745
+ * Validates archive path constraints.
746
+ *
747
+ * @param path - Archive-relative path.
748
+ */
749
+ static validateArchivePath(path: string): string | null;
750
+ /**
751
+ * Sanitizes one archive path segment by replacing forbidden characters.
752
+ *
753
+ * @param segment - Single path segment.
754
+ */
755
+ static sanitisePathSegment(segment: string): string;
756
+ /**
757
+ * Sanitizes a full archive path by normalizing each path segment.
758
+ *
759
+ * @param path - Candidate archive path.
760
+ */
761
+ static sanitiseArchivePath(path: string): string;
762
+ /**
763
+ * Ensures archive path uniqueness by appending `-2`, `-3`, etc when needed.
764
+ *
765
+ * @param candidate - Desired archive path.
766
+ * @param usedPaths - Case-insensitive set of already-used paths.
767
+ */
768
+ static makeUniqueArchivePath(candidate: string, usedPaths: Set<string>): string;
769
+ /**
770
+ * Tests whether a path matches a glob pattern supporting `*`, `?`, and `**`.
771
+ *
772
+ * @param path - Archive-relative path.
773
+ * @param pattern - Glob pattern.
774
+ */
775
+ static globMatch(path: string, pattern: string): boolean;
776
+ /**
777
+ * Returns true if a path matches at least one filter pattern.
778
+ *
779
+ * @param path - Archive-relative path.
780
+ * @param filters - Glob filter list.
781
+ */
782
+ static matchesAnyFilter(path: string, filters: string[]): boolean;
783
+ /**
784
+ * Builds a generated manifest from packaging options, or `null` when none is needed.
785
+ *
786
+ * @param rootName - Root/source label for fallback title.
787
+ * @param options - Packaging options.
788
+ */
789
+ static buildManifestFromOptions(rootName: string, options: MdzPackOptions): MdzManifest | null;
790
+ /**
791
+ * Resolves entry point using manifest override, `index.md`, or single-root-markdown fallback.
792
+ *
793
+ * @param archivePaths - Archive file paths.
794
+ * @param manifest - Optional manifest with `entryPoint`.
795
+ */
796
+ static resolveEntryPoint(archivePaths: string[], manifest?: Pick<MdzManifest, 'entryPoint'> | null): string | null;
797
+ /**
798
+ * Generates a simple index markdown page for archives without a clear entry point.
799
+ *
800
+ * @param markdownPaths - Markdown files to list.
801
+ * @param title - Optional heading title.
802
+ */
803
+ static buildGeneratedIndex(markdownPaths: string[], title?: string | null): string;
804
+ /**
805
+ * Creates a canonical MDZip manifest from app-safe metadata.
806
+ *
807
+ * @param metadata - Editable manifest fields.
808
+ */
809
+ static createManifest(metadata?: MdzManifestEditableMetadata & Pick<MdzManifest, 'mode' | 'entryPoint'>): MdzManifest;
810
+ /**
811
+ * Updates a manifest while preserving spec-managed fields unless explicitly changed elsewhere.
812
+ *
813
+ * @param manifest - Existing manifest, or `null` to create one.
814
+ * @param updates - Editable metadata updates.
815
+ * @param options - Timestamp controls.
816
+ */
817
+ static updateManifest(manifest: MdzManifest | null, updates?: MdzManifestEditableMetadata & Partial<Pick<MdzManifest, 'mode' | 'entryPoint'>>, options?: MdzManifestUpdateOptions): MdzManifest;
818
+ /**
819
+ * Splits a manifest into spec-managed fields and ordinary editable metadata.
820
+ *
821
+ * @param manifest - Manifest to split.
822
+ */
823
+ static splitManifestMetadata(manifest: MdzManifest): {
824
+ reserved: MdzManifestReservedFields;
825
+ editable: MdzManifestEditableMetadata;
826
+ };
827
+ /**
828
+ * Creates a workspace asset from a browser `File`/`Blob` or raw bytes.
829
+ *
830
+ * @param source - Asset source.
831
+ * @param targetPath - Optional archive path override.
832
+ */
833
+ static createWorkspaceAssetFromFile(source: File | Blob | ArrayBuffer | Uint8Array, targetPath?: string): Promise<MdzWorkspaceAsset>;
834
+ /**
835
+ * Exports a workspace asset as a browser-safe `Blob`.
836
+ *
837
+ * @param asset - Workspace asset.
838
+ */
839
+ static exportWorkspaceAsset(asset: MdzWorkspaceAsset): Promise<Blob>;
840
+ /**
841
+ * Builds an `.mdz` archive from a normalized workspace.
842
+ *
843
+ * @param workspace - Workspace model.
844
+ * @param options - Build controls and metadata overrides.
845
+ * @param zipWriterFactory - Optional custom zip writer.
846
+ */
847
+ static buildWorkspace(workspace: MdzWorkspace, options?: MdzBuildWorkspaceOptions, zipWriterFactory?: ZipWriterFactoryLike): Promise<MdzPackBuildResult>;
848
+ private static normalizeLf;
849
+ private static isTextFile;
850
+ private static readProvidedManifest;
851
+ private static ensureCanonicalManifest;
852
+ private static readBinarySource;
853
+ private static readWorkspaceAssetBytes;
854
+ /**
855
+ * Builds an `.mdz` archive from input files and packaging options.
856
+ *
857
+ * @param files - Source file candidates.
858
+ * @param rootName - Root/source label for generated metadata.
859
+ * @param options - Packaging options.
860
+ * @param zipWriterFactory - Optional custom zip writer.
861
+ */
862
+ static buildArchive(files: MdzPackInputFile[], rootName: string, options: MdzPackOptions, zipWriterFactory?: ZipWriterFactoryLike): Promise<MdzPackBuildResult>;
863
+ private static getDefaultZipWriterFactory;
864
+ }
865
+ export {};
866
+ //# sourceMappingURL=mdz-core.d.ts.map