@illusions-lab/mdi 2.0.10 → 2.0.12

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.
@@ -3,7 +3,9 @@ import {
3
3
  parseMdiSyntaxJson,
4
4
  renderHtml as renderHtmlFromRust,
5
5
  renderEpub as renderEpubFromRust,
6
+ renderEpubWithProfile as renderEpubWithProfileFromRust,
6
7
  renderDocx as renderDocxFromRust,
8
+ renderDocxWithProfile as renderDocxWithProfileFromRust,
7
9
  renderText as renderTextFromRust,
8
10
  renderTextFormat as renderTextFormatFromRust,
9
11
  serializeMdi as serializeMdiFromRust
@@ -61,30 +63,22 @@ function renderDocxWithDiagnostics(source, profile) {
61
63
  async function renderEpubWithProfile(source, options = {}) {
62
64
  assertSource(source);
63
65
  assertEpubOptions(options);
64
- const { mdiToEpub } = await import("@illusions-lab/mdi-to-epub");
65
66
  const normalized = normalizeEpubOptions(options);
66
67
  requireLayoutSystem(normalized.profile);
67
- return mdiToEpub(toPublicationMdast(parse(source).document), normalized);
68
+ const cover = normalized.cover;
69
+ return renderEpubWithProfileFromRust(
70
+ source,
71
+ JSON.stringify(normalized.profile),
72
+ cover?.data ?? new Uint8Array(),
73
+ cover?.mediaType
74
+ );
68
75
  }
69
76
  async function renderDocxWithProfile(source, profile = {}) {
70
77
  assertSource(source);
71
78
  assertPlainObject(profile, "profile");
72
- prepareNodeDocxImport();
73
- const { mdiToDocx } = await import("@illusions-lab/mdi-to-docx");
74
79
  const normalized = normalizeDocxProfile(profile);
75
80
  requireLayoutSystem(normalized);
76
- return mdiToDocx(toPublicationMdast(parse(source).document), normalized);
77
- }
78
- function prepareNodeDocxImport() {
79
- const nodeProcess = globalThis.process;
80
- if (nodeProcess?.release?.name === "node" && !nodeProcess.execArgv?.some((argument) => argument.startsWith("--localstorage-file="))) {
81
- const descriptor = Object.getOwnPropertyDescriptor(globalThis, "localStorage");
82
- if (descriptor?.configurable && descriptor.get)
83
- Object.defineProperty(globalThis, "localStorage", {
84
- value: void 0,
85
- configurable: true
86
- });
87
- }
81
+ return renderDocxWithProfileFromRust(source, JSON.stringify(normalized));
88
82
  }
89
83
  function toPublicationMdast(document) {
90
84
  const children = document.children.map(toPublicationMdastNode);
package/dist/index.cjs CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
@@ -103,30 +93,22 @@ function renderDocxWithDiagnostics(source, profile) {
103
93
  async function renderEpubWithProfile(source, options = {}) {
104
94
  assertSource(source);
105
95
  assertEpubOptions(options);
106
- const { mdiToEpub } = await import("@illusions-lab/mdi-to-epub");
107
96
  const normalized = normalizeEpubOptions(options);
108
97
  (0, import_mdi_export_profile.requireLayoutSystem)(normalized.profile);
109
- return mdiToEpub(toPublicationMdast(parse(source).document), normalized);
98
+ const cover = normalized.cover;
99
+ return (0, import_mdi_core.renderEpubWithProfile)(
100
+ source,
101
+ JSON.stringify(normalized.profile),
102
+ cover?.data ?? new Uint8Array(),
103
+ cover?.mediaType
104
+ );
110
105
  }
111
106
  async function renderDocxWithProfile(source, profile = {}) {
112
107
  assertSource(source);
113
108
  assertPlainObject(profile, "profile");
114
- prepareNodeDocxImport();
115
- const { mdiToDocx } = await import("@illusions-lab/mdi-to-docx");
116
109
  const normalized = normalizeDocxProfile(profile);
117
110
  (0, import_mdi_export_profile.requireLayoutSystem)(normalized);
118
- return mdiToDocx(toPublicationMdast(parse(source).document), normalized);
119
- }
120
- function prepareNodeDocxImport() {
121
- const nodeProcess = globalThis.process;
122
- if (nodeProcess?.release?.name === "node" && !nodeProcess.execArgv?.some((argument) => argument.startsWith("--localstorage-file="))) {
123
- const descriptor = Object.getOwnPropertyDescriptor(globalThis, "localStorage");
124
- if (descriptor?.configurable && descriptor.get)
125
- Object.defineProperty(globalThis, "localStorage", {
126
- value: void 0,
127
- configurable: true
128
- });
129
- }
111
+ return (0, import_mdi_core.renderDocxWithProfile)(source, JSON.stringify(normalized));
130
112
  }
131
113
  function toPublicationMdast(document) {
132
114
  const children = document.children.map(toPublicationMdastNode);
package/dist/index.d.cts CHANGED
@@ -113,6 +113,21 @@ interface MdiDocument {
113
113
  frontmatter?: MdiFrontmatter;
114
114
  children: MdiNode[];
115
115
  }
116
+ /** Resolved front matter attached to mdast publication-adapter roots. */
117
+ interface MdiPublicationFrontmatter {
118
+ mdi: string;
119
+ title?: string;
120
+ author?: string;
121
+ lang: string;
122
+ date?: string;
123
+ writingMode: "horizontal" | "vertical";
124
+ pageProgression: "ltr" | "rtl";
125
+ }
126
+ interface MdiPublicationRoot extends Root {
127
+ data?: Root["data"] & {
128
+ frontmatter?: MdiPublicationFrontmatter;
129
+ };
130
+ }
116
131
  /** A source-backed heading available to host navigation and chapter UIs. */
117
132
  interface MdiHeading {
118
133
  depth: 1 | 2 | 3 | 4 | 5 | 6;
@@ -214,7 +229,7 @@ declare function renderDocxWithProfile(source: string, profile?: MdiDocxExportPr
214
229
  * Convert a Rust-owned MDI document IR into mdast for publication adapters.
215
230
  * This performs no parsing and preserves the adapter node conventions.
216
231
  */
217
- declare function toPublicationMdast(document: MdiDocument): Root;
232
+ declare function toPublicationMdast(document: MdiDocument): MdiPublicationRoot;
218
233
  /** Parse and normalize complete `.mdi` source with Rust's serializer. */
219
234
  declare function serializeMdi(source: string): string;
220
235
  /** Render complete `.mdi` source to deterministic plain text in Rust. */
@@ -229,4 +244,4 @@ declare function renderTextFormatWithDiagnostics(source: string, format: MdiText
229
244
  /** @deprecated Use {@link parse}; it now parses the complete document. */
230
245
  declare const parseMdiSyntax: typeof parse;
231
246
 
232
- export { MDI_IR_VERSION, MDI_SPEC_VERSION, type MdiDiagnostic, type MdiDocument, type MdiDocxExportProfile, type MdiEpubExportOptions, type MdiFrontmatter, type MdiHeading, type MdiHtmlRenderOptions, type MdiNode, type MdiParserCapabilities, type MdiRenderResult, type MdiRubyReading, type MdiSourceSpan, type MdiSyntaxDocument, type MdiSyntaxParseResult, type MdiTextFormat, parse, parseMdiSyntax, prepareRender, renderDocx, renderDocxWithDiagnostics, renderDocxWithProfile, renderEpub, renderEpubWithDiagnostics, renderEpubWithProfile, renderHtml, renderHtmlWithDiagnostics, renderText, renderTextFormat, renderTextFormatWithDiagnostics, renderTextWithDiagnostics, serializeMdi, toPublicationMdast };
247
+ export { MDI_IR_VERSION, MDI_SPEC_VERSION, type MdiDiagnostic, type MdiDocument, type MdiDocxExportProfile, type MdiEpubExportOptions, type MdiFrontmatter, type MdiHeading, type MdiHtmlRenderOptions, type MdiNode, type MdiParserCapabilities, type MdiPublicationFrontmatter, type MdiPublicationRoot, type MdiRenderResult, type MdiRubyReading, type MdiSourceSpan, type MdiSyntaxDocument, type MdiSyntaxParseResult, type MdiTextFormat, parse, parseMdiSyntax, prepareRender, renderDocx, renderDocxWithDiagnostics, renderDocxWithProfile, renderEpub, renderEpubWithDiagnostics, renderEpubWithProfile, renderHtml, renderHtmlWithDiagnostics, renderText, renderTextFormat, renderTextFormatWithDiagnostics, renderTextWithDiagnostics, serializeMdi, toPublicationMdast };
package/dist/index.d.ts CHANGED
@@ -113,6 +113,21 @@ interface MdiDocument {
113
113
  frontmatter?: MdiFrontmatter;
114
114
  children: MdiNode[];
115
115
  }
116
+ /** Resolved front matter attached to mdast publication-adapter roots. */
117
+ interface MdiPublicationFrontmatter {
118
+ mdi: string;
119
+ title?: string;
120
+ author?: string;
121
+ lang: string;
122
+ date?: string;
123
+ writingMode: "horizontal" | "vertical";
124
+ pageProgression: "ltr" | "rtl";
125
+ }
126
+ interface MdiPublicationRoot extends Root {
127
+ data?: Root["data"] & {
128
+ frontmatter?: MdiPublicationFrontmatter;
129
+ };
130
+ }
116
131
  /** A source-backed heading available to host navigation and chapter UIs. */
117
132
  interface MdiHeading {
118
133
  depth: 1 | 2 | 3 | 4 | 5 | 6;
@@ -214,7 +229,7 @@ declare function renderDocxWithProfile(source: string, profile?: MdiDocxExportPr
214
229
  * Convert a Rust-owned MDI document IR into mdast for publication adapters.
215
230
  * This performs no parsing and preserves the adapter node conventions.
216
231
  */
217
- declare function toPublicationMdast(document: MdiDocument): Root;
232
+ declare function toPublicationMdast(document: MdiDocument): MdiPublicationRoot;
218
233
  /** Parse and normalize complete `.mdi` source with Rust's serializer. */
219
234
  declare function serializeMdi(source: string): string;
220
235
  /** Render complete `.mdi` source to deterministic plain text in Rust. */
@@ -229,4 +244,4 @@ declare function renderTextFormatWithDiagnostics(source: string, format: MdiText
229
244
  /** @deprecated Use {@link parse}; it now parses the complete document. */
230
245
  declare const parseMdiSyntax: typeof parse;
231
246
 
232
- export { MDI_IR_VERSION, MDI_SPEC_VERSION, type MdiDiagnostic, type MdiDocument, type MdiDocxExportProfile, type MdiEpubExportOptions, type MdiFrontmatter, type MdiHeading, type MdiHtmlRenderOptions, type MdiNode, type MdiParserCapabilities, type MdiRenderResult, type MdiRubyReading, type MdiSourceSpan, type MdiSyntaxDocument, type MdiSyntaxParseResult, type MdiTextFormat, parse, parseMdiSyntax, prepareRender, renderDocx, renderDocxWithDiagnostics, renderDocxWithProfile, renderEpub, renderEpubWithDiagnostics, renderEpubWithProfile, renderHtml, renderHtmlWithDiagnostics, renderText, renderTextFormat, renderTextFormatWithDiagnostics, renderTextWithDiagnostics, serializeMdi, toPublicationMdast };
247
+ export { MDI_IR_VERSION, MDI_SPEC_VERSION, type MdiDiagnostic, type MdiDocument, type MdiDocxExportProfile, type MdiEpubExportOptions, type MdiFrontmatter, type MdiHeading, type MdiHtmlRenderOptions, type MdiNode, type MdiParserCapabilities, type MdiPublicationFrontmatter, type MdiPublicationRoot, type MdiRenderResult, type MdiRubyReading, type MdiSourceSpan, type MdiSyntaxDocument, type MdiSyntaxParseResult, type MdiTextFormat, parse, parseMdiSyntax, prepareRender, renderDocx, renderDocxWithDiagnostics, renderDocxWithProfile, renderEpub, renderEpubWithDiagnostics, renderEpubWithProfile, renderHtml, renderHtmlWithDiagnostics, renderText, renderTextFormat, renderTextFormatWithDiagnostics, renderTextWithDiagnostics, serializeMdi, toPublicationMdast };
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  renderTextWithDiagnostics,
19
19
  serializeMdi,
20
20
  toPublicationMdast
21
- } from "./chunk-FA5R33XH.js";
21
+ } from "./chunk-BF7UFCZO.js";
22
22
  export {
23
23
  MDI_IR_VERSION,
24
24
  MDI_SPEC_VERSION,
package/dist/node.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  parse,
3
3
  renderHtml
4
- } from "./chunk-FA5R33XH.js";
4
+ } from "./chunk-BF7UFCZO.js";
5
5
 
6
6
  // src/node.ts
7
7
  import {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@illusions-lab/mdi",
3
- "version": "2.0.10",
3
+ "version": "2.0.12",
4
4
  "description": "Thin JavaScript binding for the Rust-authoritative MDI parser",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -32,10 +32,9 @@
32
32
  "typecheck": "tsc --noEmit"
33
33
  },
34
34
  "dependencies": {
35
- "@illusions-lab/mdi-core": "^2.0.10",
36
- "@illusions-lab/mdi-export-profile": "^2.0.16",
37
- "@illusions-lab/mdi-to-docx": "^2.0.24",
38
- "@illusions-lab/mdi-to-epub": "^2.0.26",
35
+ "@illusions-lab/mdi-core": "^2.0.12",
36
+ "@illusions-lab/mdi-export-profile": "^2.0.17",
37
+ "@illusions-lab/mdi-to-epub": "^2.0.27",
39
38
  "@types/mdast": "^4.0.0",
40
39
  "yaml": "^2.0.0"
41
40
  },