@publish.os/nextjs 0.0.1-alpha.91 → 0.0.1-alpha.92

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.
Files changed (153) hide show
  1. package/compiler-assets/nextjs/defaults/group/index.tsx +16 -11
  2. package/compiler-assets/nextjs/defaults/group/layout.tsx +6 -2
  3. package/compiler-assets/nextjs/defaults/group/page.tsx +7 -6
  4. package/compiler-assets/nextjs/defaults/project/next.config.mjs +2 -1
  5. package/compiler-assets/nextjs/defaults/root/index.tsx +16 -11
  6. package/compiler-assets/nextjs/defaults/root/layout.tsx +7 -3
  7. package/compiler-assets/nextjs/shims/agent-user-agents.ts +65 -0
  8. package/compiler-assets/nextjs/shims/document.tsx +9 -1
  9. package/compiler-assets/nextjs/shims/generated-leaf-page.tsx +3 -0
  10. package/compiler-assets/nextjs/shims/proxy.ts +156 -54
  11. package/dist/{build-operation-5QMLXF7N.js → build-operation-CJDUL4OW.js} +5 -5
  12. package/dist/{chunk-GBPLER5H.js → chunk-3T4HVDSC.js} +2 -2
  13. package/dist/{chunk-UYGCOWRF.js → chunk-DX7PXFCM.js} +860 -50
  14. package/dist/{chunk-F3AGNDF4.js → chunk-DZ3VWEV5.js} +860 -575
  15. package/dist/{chunk-OXOFRXEI.js → chunk-NHSLTARU.js} +1284 -1164
  16. package/dist/{chunk-ORIUWJBQ.js → chunk-SBMDONTV.js} +3 -2
  17. package/dist/compiler.js +42 -23
  18. package/dist/components/blocks/agent-actions.d.ts +7 -7
  19. package/dist/components/blocks/agent-actions.js +1 -32
  20. package/dist/components/blocks/toc.d.ts +7 -7
  21. package/dist/components/ui/button.d.ts +1 -2
  22. package/dist/{compose-CVBJRAF6.js → compose-44GJSMXD.js} +2 -2
  23. package/dist/config/createNextConfig.js +2 -0
  24. package/dist/{dev-operation-OSHHWRWK.js → dev-operation-WNECBHZ5.js} +17 -7
  25. package/dist/{ide-support-CU6Z5PVR.js → ide-support-TG74L4FF.js} +3 -3
  26. package/dist/index.d.ts +143 -126
  27. package/dist/index.js +25 -0
  28. package/dist/kernel/components/blocks/AgentActions.d.ts +7 -7
  29. package/dist/kernel/components/blocks/AgentActions.js +1 -32
  30. package/dist/kernel/components/blocks/agent-actions.d.ts +1 -2
  31. package/dist/kernel/components/blocks/agent-actions.js +1 -32
  32. package/dist/kernel/components/blocks/animated-icon-swap.d.ts +2 -2
  33. package/dist/kernel/components/blocks/color-palette.d.ts +2 -2
  34. package/dist/kernel/components/blocks/logo-block.d.ts +2 -2
  35. package/dist/kernel/components/blocks/nav-breadcrumb.d.ts +6 -5
  36. package/dist/kernel/components/blocks/nav-breadcrumb.js +19 -13
  37. package/dist/kernel/components/blocks/navbar.d.ts +5 -4
  38. package/dist/kernel/components/blocks/navbar.js +62 -42
  39. package/dist/kernel/components/blocks/navigation-progress.d.ts +2 -2
  40. package/dist/kernel/components/blocks/next-prev.d.ts +4 -4
  41. package/dist/kernel/components/blocks/next-prev.js +29 -6
  42. package/dist/kernel/components/blocks/page-list.d.ts +4 -4
  43. package/dist/kernel/components/blocks/page-list.js +30 -7
  44. package/dist/kernel/components/blocks/search.d.ts +9 -15
  45. package/dist/kernel/components/blocks/sidebar-node.d.ts +3 -5
  46. package/dist/kernel/components/blocks/sidebar-node.js +12 -2
  47. package/dist/kernel/components/blocks/sidebar.d.ts +6 -7
  48. package/dist/kernel/components/blocks/sidebar.js +132 -26
  49. package/dist/kernel/components/blocks/theme-toggle.d.ts +3 -4
  50. package/dist/kernel/components/blocks/toc-client.d.ts +7 -7
  51. package/dist/kernel/components/blocks/toc.d.ts +3 -3
  52. package/dist/kernel/components/mdx/components/blockquote.d.ts +2 -2
  53. package/dist/kernel/components/mdx/components/callout.d.ts +3 -3
  54. package/dist/kernel/components/mdx/components/code-block.d.ts +2 -2
  55. package/dist/kernel/components/mdx/components/copy-code-button.d.ts +2 -2
  56. package/dist/kernel/components/mdx/components/figure-caption.d.ts +2 -2
  57. package/dist/kernel/components/mdx/components/figure.d.ts +3 -3
  58. package/dist/kernel/components/mdx/components/footnotes.d.ts +2 -2
  59. package/dist/kernel/components/mdx/components/heading-copy-link.d.ts +2 -2
  60. package/dist/kernel/components/mdx/components/heading.d.ts +2 -2
  61. package/dist/kernel/components/mdx/components/hr.d.ts +4 -4
  62. package/dist/kernel/components/mdx/components/image-zoom.d.ts +3 -3
  63. package/dist/kernel/components/mdx/components/image-zoom.js +3 -2
  64. package/dist/kernel/components/mdx/components/image.d.ts +2 -2
  65. package/dist/kernel/components/mdx/components/image.js +1 -1
  66. package/dist/kernel/components/mdx/components/inline-code.d.ts +2 -2
  67. package/dist/kernel/components/mdx/components/kbd.d.ts +3 -3
  68. package/dist/kernel/components/mdx/components/link.d.ts +3 -3
  69. package/dist/kernel/components/mdx/components/paragraph.d.ts +2 -2
  70. package/dist/kernel/components/mdx/components/strikethrough.d.ts +2 -2
  71. package/dist/kernel/components/mdx/components/table.d.ts +7 -7
  72. package/dist/kernel/components/mdx/components/task-list.d.ts +3 -3
  73. package/dist/kernel/components/mdx/components/video-player.d.ts +2 -2
  74. package/dist/kernel/components/mdx/components/video.d.ts +2 -3
  75. package/dist/kernel/components/mdx/error-boundary.d.ts +2 -3
  76. package/dist/kernel/components/mdx/error-fallback.d.ts +2 -2
  77. package/dist/kernel/components/mdx/mdx.d.ts +42 -11
  78. package/dist/kernel/components/mdx/mdx.js +1 -1
  79. package/dist/kernel/components/next-image.d.ts +3 -3
  80. package/dist/kernel/components/ui/accordion.d.ts +7 -7
  81. package/dist/kernel/components/ui/breadcrumb-trail.d.ts +2 -3
  82. package/dist/kernel/components/ui/breadcrumb.d.ts +13 -13
  83. package/dist/kernel/components/ui/button-group.d.ts +5 -5
  84. package/dist/kernel/components/ui/button.d.ts +3 -3
  85. package/dist/kernel/components/ui/card.d.ts +7 -7
  86. package/dist/kernel/components/ui/dialog.d.ts +10 -10
  87. package/dist/kernel/components/ui/drawer.d.ts +12 -12
  88. package/dist/kernel/components/ui/kbd.d.ts +3 -3
  89. package/dist/kernel/components/ui/link.d.ts +3 -3
  90. package/dist/kernel/components/ui/menu.d.ts +22 -22
  91. package/dist/kernel/components/ui/mod-key.d.ts +2 -3
  92. package/dist/kernel/components/ui/navigation-menu.d.ts +15 -15
  93. package/dist/kernel/components/ui/popover.d.ts +11 -11
  94. package/dist/kernel/components/ui/progress.d.ts +7 -7
  95. package/dist/kernel/components/ui/scroll-area.d.ts +1 -2
  96. package/dist/kernel/components/ui/select.d.ts +16 -16
  97. package/dist/kernel/components/ui/separator.d.ts +3 -3
  98. package/dist/kernel/components/ui/table.d.ts +7 -7
  99. package/dist/kernel/components/ui/tabs.d.ts +12 -12
  100. package/dist/kernel/components/ui/tag.d.ts +3 -3
  101. package/dist/kernel/components/ui/text.d.ts +4 -4
  102. package/dist/kernel/components/ui/toast.d.ts +11 -11
  103. package/dist/kernel/components/ui/tooltip.d.ts +9 -9
  104. package/dist/kernel/defaults.registry.d.ts +2 -2
  105. package/dist/kernel/defaults.registry.js +2 -2
  106. package/dist/kernel/routes/agent/markdown.d.ts +4 -0
  107. package/dist/kernel/routes/agent/markdown.js +11 -7
  108. package/dist/kernel/routes/layouts/group.d.ts +1 -1
  109. package/dist/kernel/routes/metadata/feed.d.ts +1 -2
  110. package/dist/kernel/routes/metadata/feed.js +34 -29
  111. package/dist/kernel/routes/metadata/llms.d.ts +3 -31
  112. package/dist/kernel/routes/metadata/llms.js +2 -200
  113. package/dist/kernel/routes/metadata/robots.d.ts +5 -3
  114. package/dist/kernel/routes/metadata/robots.js +4 -25
  115. package/dist/kernel/routes/metadata/sitemap.d.ts +15 -1
  116. package/dist/kernel/routes/metadata/sitemap.js +200 -112
  117. package/dist/kernel/routes/not-found.js +1 -1
  118. package/dist/kernel/routes/pages/group.d.ts +3 -3
  119. package/dist/kernel/routes/pages/group.js +10 -4
  120. package/dist/kernel/routes/pages/leaf.d.ts +9 -4
  121. package/dist/kernel/routes/pages/leaf.js +16 -8
  122. package/dist/kernel/routes/pages/root.d.ts +3 -3
  123. package/dist/kernel/routes/pages/root.js +20 -5
  124. package/dist/keyboard-shortcuts.d.ts +2 -2
  125. package/dist/manifest-types-CcVPH_jh.d.ts +83 -0
  126. package/dist/resolvers/manifest-resolver.d.ts +2 -2
  127. package/dist/resolvers/manifest-resolver.js +65 -35
  128. package/dist/search.d.ts +2 -9
  129. package/dist/search.js +2 -7
  130. package/dist/sidebar-types-CMrMM0Nj.d.ts +105 -0
  131. package/dist/theme-scope.d.ts +2 -2
  132. package/dist/types-BbqmOzLC.d.ts +168 -0
  133. package/dist/types-TjH1ek0X.d.ts +22 -0
  134. package/dist/types.d.ts +116 -91
  135. package/dist/{validate-local-source-SV44DBQT.js → validate-local-source-EN2GW4FR.js} +3 -3
  136. package/dist/{validate-publish-os-source-NZJF3TB2.js → validate-publish-os-source-OEWQDB7B.js} +2 -2
  137. package/init/seed/minimal/publish.os/blog/index.tsx +25 -22
  138. package/init/seed/minimal/publish.os/blog/page.tsx +31 -16
  139. package/init/seed/minimal/publish.os/components/blog/copy-link.tsx +1 -1
  140. package/init/seed/minimal/publish.os/components/blog/frontmatter.ts +41 -0
  141. package/init/seed/minimal/publish.os/publish.os.config.json +13 -2
  142. package/init/seed/minimal/seed.json +1 -0
  143. package/init/seed/scratch/publish.os/publish.os.config.json +1 -1
  144. package/package.json +4 -4
  145. package/release/app/phosphor/package.json +1 -1
  146. package/release/app/phosphor/pnpm-lock.yaml.template +53 -127
  147. package/release/compiler/pnpm-lock.yaml.template +49 -123
  148. package/release/release.json +4 -4
  149. package/dist/sidebar-types-DKpR27II.d.ts +0 -25
  150. package/dist/types-CJWRG05y.d.ts +0 -76
  151. package/dist/types-CUtrppxt.d.ts +0 -69
  152. package/dist/types-J2w_puPF.d.ts +0 -128
  153. package/dist/{button-BdCScEKi.d.ts → button-D6Xp2HBm.d.ts} +1 -1
@@ -89,27 +89,123 @@ import ts2 from "typescript";
89
89
  import { unified } from "unified";
90
90
 
91
91
  // src/lib/compiler/source/frontmatter.ts
92
- import matter from "gray-matter";
93
- var DATA_LANGUAGES = /* @__PURE__ */ new Set(["json", "yaml", "yml"]), FRONTMATTER_DELIMITER = "---", UnsupportedFrontmatterLanguageError = class extends Error {
94
- constructor(language) {
95
- super(`Unsupported frontmatter language "${language}". Use YAML or JSON.`);
96
- this.language = language;
97
- this.name = "UnsupportedFrontmatterLanguageError";
92
+ import { isAlias, isMap, isScalar, isSeq, parseDocument } from "yaml";
93
+ function decimalValue(value) {
94
+ let match = /^([+-]?)(\d*)(?:\.(\d*))?(?:e([+-]?\d+))?$/i.exec(value);
95
+ if (!match || !(match[2] || match[3])) return;
96
+ let digits = `${match[2]}${match[3] ?? ""}`.replace(/^0+/, "");
97
+ if (!digits) return "0";
98
+ let trimmed = digits.replace(/0+$/, ""), exponent = BigInt(match[4] ?? "0") - BigInt((match[3] ?? "").length) + BigInt(digits.length - trimmed.length);
99
+ return `${match[1] === "-" ? "-" : ""}${trimmed}e${exponent}`;
100
+ }
101
+ function numberIsExact(source, value) {
102
+ if (!Number.isFinite(value)) return !1;
103
+ if (/^[-+]?0[ox]/i.test(source))
104
+ try {
105
+ return Number.isInteger(value) && BigInt(source.replace(/^\+/, "")) === BigInt(value);
106
+ } catch {
107
+ return !1;
108
+ }
109
+ return decimalValue(source) === decimalValue(String(value));
110
+ }
111
+ var FrontmatterParseError = class extends Error {
112
+ constructor(message, line, column, field) {
113
+ super(`${message} at line ${line}, column ${column}.`);
114
+ this.line = line;
115
+ this.column = column;
116
+ this.field = field;
117
+ this.name = "FrontmatterParseError";
98
118
  }
99
- language;
119
+ line;
120
+ column;
121
+ field;
100
122
  };
101
- function frontmatterLanguage(source) {
102
- if (!matter.test(source) || source[FRONTMATTER_DELIMITER.length] === FRONTMATTER_DELIMITER.at(-1))
103
- return;
104
- let lineEnd = source.indexOf(`
105
- `, FRONTMATTER_DELIMITER.length), headerEnd = lineEnd === -1 ? source.length : lineEnd;
106
- return source.slice(FRONTMATTER_DELIMITER.length, headerEnd).replace(/\r$/, "").trim();
107
- }
108
123
  function parseSourceFrontmatter(source) {
109
- let inspected = source.charCodeAt(0) === 65279 ? source.slice(1) : source, marker = frontmatterLanguage(inspected), language = marker?.toLowerCase();
110
- if (marker && language && (!DATA_LANGUAGES.has(language) || language === "json" && marker !== "json"))
111
- throw new UnsupportedFrontmatterLanguageError(marker);
112
- return matter(source, { language: "yaml" });
124
+ let firstLine = /^(?:\uFEFF)?---(?:\r?\n|$)/.exec(source);
125
+ if (!firstLine) return { data: {}, content: source };
126
+ let offset = firstLine[0].length, fence, end = -1, bodyStart = -1;
127
+ for (; offset < source.length; ) {
128
+ let next = source.indexOf(`
129
+ `, offset), lineEnd = next < 0 ? source.length : next, line = source.slice(offset, lineEnd).replace(/\r$/, ""), marker = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(line);
130
+ if (marker) {
131
+ let run = marker[1] ?? "";
132
+ fence ? run.charAt(0) === fence.character && run.length >= fence.length && !(marker[2] ?? "").trim() && (fence = void 0) : fence = { character: run.charAt(0), length: run.length };
133
+ } else if (!fence && line === "---") {
134
+ end = offset, bodyStart = next < 0 ? source.length : next + 1;
135
+ break;
136
+ }
137
+ offset = next < 0 ? source.length : next + 1;
138
+ }
139
+ if (end < 0) return { data: {}, content: source };
140
+ let frontmatterOffset = firstLine[0].length;
141
+ function fail(message, offset2 = 0, field) {
142
+ let absoluteOffset = Math.min(frontmatterOffset + offset2, source.length), before = source.slice(0, absoluteOffset), line = before.split(`
143
+ `).length, column = absoluteOffset - before.lastIndexOf(`
144
+ `);
145
+ throw new FrontmatterParseError(message, line, column, field);
146
+ }
147
+ let doc = parseDocument(source.slice(firstLine[0].length, end), {
148
+ schema: "core",
149
+ uniqueKeys: !0
150
+ }), yamlError = doc.errors[0] ?? doc.warnings[0];
151
+ if (yamlError) {
152
+ let message = yamlError.message.replace(
153
+ / at line \d+, column \d+:[\s\S]*$/,
154
+ ""
155
+ );
156
+ fail(message, yamlError.pos[0]);
157
+ }
158
+ doc.contents && !isMap(doc.contents) && fail(
159
+ "Frontmatter must be a mapping with string keys",
160
+ doc.contents.range?.[0]
161
+ );
162
+ let visits = 0, active = /* @__PURE__ */ new Set();
163
+ function validate(node, field) {
164
+ if (node) {
165
+ if (++visits > 1e4 && fail("Frontmatter alias expansion exceeds the limit"), isAlias(node)) {
166
+ let target = node.resolve(doc);
167
+ target || fail(`Invalid alias in ${field}`, node.range?.[0], field), active.has(target) && fail(`Cyclic alias in ${field}`, node.range?.[0], field), validate(target, field);
168
+ return;
169
+ }
170
+ if (!(!isScalar(node) && !isMap(node) && !isSeq(node))) {
171
+ if (node.tag && ![
172
+ "tag:yaml.org,2002:str",
173
+ "tag:yaml.org,2002:int",
174
+ "tag:yaml.org,2002:float",
175
+ "tag:yaml.org,2002:bool",
176
+ "tag:yaml.org,2002:null",
177
+ "tag:yaml.org,2002:map",
178
+ "tag:yaml.org,2002:seq"
179
+ ].includes(node.tag) && fail(`Unsupported YAML tag in ${field}`, node.range?.[0], field), isScalar(node)) {
180
+ typeof node.value == "number" && !numberIsExact(node.source ?? String(node.value), node.value) && fail(
181
+ `Invalid number in ${field}; quote the value to preserve its exact digits`,
182
+ node.range?.[0],
183
+ field
184
+ );
185
+ return;
186
+ }
187
+ if (active.add(node), isMap(node))
188
+ for (let pair of node.items)
189
+ (!isScalar(pair.key) || typeof pair.key.value != "string") && fail(
190
+ `Frontmatter keys in ${field} must be strings`,
191
+ isScalar(pair.key) || isMap(pair.key) || isSeq(pair.key) || isAlias(pair.key) ? pair.key.range?.[0] : void 0,
192
+ field
193
+ ), validate(
194
+ pair.value,
195
+ field === "frontmatter" ? pair.key.value : `${field}.${pair.key.value}`
196
+ );
197
+ else
198
+ for (let item of node.items) validate(item, field);
199
+ active.delete(node);
200
+ }
201
+ }
202
+ }
203
+ validate(doc.contents, "frontmatter");
204
+ let data = doc.toJS({ maxAliasCount: 100 });
205
+ return {
206
+ data: data ? JSON.parse(JSON.stringify(data)) : {},
207
+ content: source.slice(bodyStart)
208
+ };
113
209
  }
114
210
 
115
211
  // src/lib/compiler/source/mdx-icon-imports.ts
@@ -187,7 +283,7 @@ async function validateMdxIconImports(source) {
187
283
  return imports;
188
284
  }
189
285
 
190
- // src/lib/compiler/source/config/root-content-group.ts
286
+ // src/lib/shared/root-content-group.ts
191
287
  var ROOT_CONTENT_GROUP_KEY = "__root", ROOT_CONTENT_GROUP_TITLE = "Root";
192
288
 
193
289
  // src/lib/compiler/source/assert-source-dependency.ts
@@ -1478,31 +1574,16 @@ export type MediaAssetManifestEntry = MediaManifest["assets"][keyof MediaManifes
1478
1574
  }
1479
1575
 
1480
1576
  // src/lib/compiler/source/routing/slug-path.ts
1481
- var SLUG_SEGMENT_RE = /^[a-z0-9]+(?:[.-][a-z0-9]+)*$/;
1577
+ var SLUG_SEGMENT_RE = /^[\p{L}\p{N}][\p{L}\p{M}\p{N}]*(?:[.-][\p{L}\p{N}][\p{L}\p{M}\p{N}]*)*$/u;
1482
1578
  function issue(code, message, details) {
1483
1579
  return details ? { code, message, details } : { code, message };
1484
1580
  }
1485
- function isLowerAlpha(code) {
1486
- return code >= 97 && code <= 122;
1487
- }
1488
- function isUpperAlpha(code) {
1489
- return code >= 65 && code <= 90;
1490
- }
1491
- function isDigit(code) {
1492
- return code >= 48 && code <= 57;
1493
- }
1494
- function isAsciiAlphaNumeric(code) {
1495
- return isLowerAlpha(code) || isUpperAlpha(code) || isDigit(code);
1496
- }
1497
1581
  function isWhitespace(code) {
1498
1582
  return code === 32 || code === 9 || code === 10 || code === 11 || code === 12 || code === 13 || code === 160;
1499
1583
  }
1500
1584
  function isUnsafeInvisible(code) {
1501
1585
  return code <= 31 || code >= 127 && code <= 159 || code >= 8203 && code <= 8207 || code >= 8232 && code <= 8239 || code >= 8288 && code <= 8303 || code === 65279;
1502
1586
  }
1503
- function isCombiningMark(code) {
1504
- return code >= 768 && code <= 879 || code >= 6832 && code <= 6911 || code >= 7616 && code <= 7679 || code >= 8400 && code <= 8447 || code >= 65056 && code <= 65071;
1505
- }
1506
1587
  function hasPercentEscape(value) {
1507
1588
  return /%[0-9a-fA-F]{2}/.test(value);
1508
1589
  }
@@ -1514,15 +1595,10 @@ function queueSeparator(current, next) {
1514
1595
  }
1515
1596
  function normalizeSegmentValue(input) {
1516
1597
  let output = [], pendingSeparator, sanitized = !1;
1517
- for (let char of input.normalize("NFKD")) {
1598
+ for (let char of input.normalize("NFC").toLowerCase().normalize("NFC")) {
1518
1599
  let code = char.codePointAt(0) ?? 0;
1519
- if (isCombiningMark(code)) {
1520
- sanitized = !0;
1521
- continue;
1522
- }
1523
- if (isAsciiAlphaNumeric(code)) {
1524
- let lower = isUpperAlpha(code) ? char.toLowerCase() : char;
1525
- pendingSeparator = appendNormalizedChar(output, lower, pendingSeparator), sanitized = sanitized || lower !== char;
1600
+ if (/^[\p{L}\p{M}\p{N}]$/u.test(char)) {
1601
+ pendingSeparator = appendNormalizedChar(output, char, pendingSeparator);
1526
1602
  continue;
1527
1603
  }
1528
1604
  if (char === "." || char === "-") {
@@ -1548,7 +1624,7 @@ function validateSegment(slug, options) {
1548
1624
  isValid: !1
1549
1625
  } : SLUG_SEGMENT_RE.test(slug) ? { isValid: !0 } : {
1550
1626
  code: "SLUG_PATTERN_INVALID",
1551
- error: 'URL path can only include lowercase letters, numbers, and single "." or "-" separators',
1627
+ error: 'URL path can only include lowercase letters, marks, numbers, and single "." or "-" separators',
1552
1628
  isValid: !1
1553
1629
  } : {
1554
1630
  code: "SLUG_EMPTY",
@@ -1557,7 +1633,7 @@ function validateSegment(slug, options) {
1557
1633
  };
1558
1634
  }
1559
1635
  function normalizeSlugSegmentInternal(input, options = {}) {
1560
- let maxSegmentLength = options.maxSegmentLength ?? 100, warnings = [], errors = [], trimmed = input.normalize("NFKC").trim(), rawLower = trimmed.toLowerCase();
1636
+ let maxSegmentLength = options.maxSegmentLength ?? 100, warnings = [], errors = [], trimmed = input.normalize("NFC").trim(), rawLower = trimmed.toLowerCase();
1561
1637
  hasPercentEscape(trimmed) && errors.push(
1562
1638
  issue(
1563
1639
  "PATH_PERCENT_ESCAPE_INVALID",
@@ -1576,7 +1652,7 @@ function normalizeSlugSegmentInternal(input, options = {}) {
1576
1652
  )
1577
1653
  );
1578
1654
  let normalized = normalizeSegmentValue(trimmed), value = normalized.value;
1579
- value.length > maxSegmentLength && (errors.push(
1655
+ value.length > maxSegmentLength && errors.push(
1580
1656
  issue(
1581
1657
  "SLUG_SEGMENT_TOO_LONG",
1582
1658
  `Path segments must be ${maxSegmentLength} characters or less`,
@@ -1585,7 +1661,7 @@ function normalizeSlugSegmentInternal(input, options = {}) {
1585
1661
  segment: input
1586
1662
  }
1587
1663
  )
1588
- ), value = value.slice(0, maxSegmentLength)), (normalized.sanitized || value !== trimmed) && warnings.push(
1664
+ ), (normalized.sanitized || value !== trimmed) && warnings.push(
1589
1665
  issue("PATH_SEGMENT_NORMALIZED", "Path segment was normalized", {
1590
1666
  from: input,
1591
1667
  to: value
@@ -1606,7 +1682,7 @@ function normalizeSlugSegmentInternal(input, options = {}) {
1606
1682
  };
1607
1683
  }
1608
1684
  function normalizePathParts(input, options = {}) {
1609
- let warnings = [], errors = [], maxPathLength = options.maxPathLength ?? 512, trimmed = input.normalize("NFKC").trim();
1685
+ let warnings = [], errors = [], maxPathLength = options.maxPathLength ?? 512, trimmed = input.normalize("NFC").trim();
1610
1686
  (/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(trimmed) || /^\/\/[^/]/.test(trimmed)) && errors.push(
1611
1687
  issue(
1612
1688
  "PATH_PROTOCOL_INVALID",
@@ -1653,6 +1729,12 @@ function normalizePathParts(input, options = {}) {
1653
1729
  value: input
1654
1730
  }
1655
1731
  )
1732
+ ), encodeURI(value).length > 2044 && errors.push(
1733
+ issue(
1734
+ "PATH_ENCODED_TOO_LONG",
1735
+ "Encoded path must leave room for the Markdown route within 2048 characters.",
1736
+ { value: input }
1737
+ )
1656
1738
  ), { errors, value, warnings };
1657
1739
  }
1658
1740
  function normalizeSlugPath(input, options = {}) {
@@ -1677,8 +1759,734 @@ function joinUrlPath(parentPath, childPath) {
1677
1759
  return normalizeUrlPath(`${parent}/${childPath}`).value;
1678
1760
  }
1679
1761
 
1762
+ // src/lib/runtime/metadata/authored-date.ts
1763
+ function authoredDate(value) {
1764
+ if (typeof value != "string" || !/^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2}))?$/.test(
1765
+ value
1766
+ ))
1767
+ return;
1768
+ let day = value.slice(0, 10), midnight = /* @__PURE__ */ new Date(`${day}T00:00:00.000Z`);
1769
+ if (!(!Number.isFinite(midnight.getTime()) || midnight.toISOString().slice(0, 10) !== day))
1770
+ return Number.isFinite(Date.parse(value)) ? value : void 0;
1771
+ }
1772
+
1773
+ // src/lib/assets/map-source-asset-url.ts
1774
+ var SOURCE_ASSET_PATH = "/assets/";
1775
+ function hasUnsafeControlCharacters2(value) {
1776
+ for (let character of value) {
1777
+ let code = character.codePointAt(0) ?? 0;
1778
+ if (code <= 31 || code >= 127 && code <= 159) return !0;
1779
+ }
1780
+ return !1;
1781
+ }
1782
+ function assertSafeAssetPath(path) {
1783
+ if (path.includes("\\") || hasUnsafeControlCharacters2(path))
1784
+ throw new TypeError("Local asset URLs must use safe path segments.");
1785
+ for (let segment of path.split("/")) {
1786
+ if (!segment)
1787
+ throw new TypeError("Local asset URLs must use safe path segments.");
1788
+ let decoded;
1789
+ try {
1790
+ decoded = decodeURIComponent(segment);
1791
+ } catch {
1792
+ throw new TypeError("Local asset URLs must use valid URL encoding.");
1793
+ }
1794
+ if (decoded === "." || decoded === ".." || decoded.includes("/") || decoded.includes("\\") || hasUnsafeControlCharacters2(decoded))
1795
+ throw new TypeError("Local asset URLs must use safe path segments.");
1796
+ }
1797
+ }
1798
+ function mapSourceAssetUrl(value) {
1799
+ if (typeof value != "string" || !value.startsWith(SOURCE_ASSET_PATH))
1800
+ return value;
1801
+ let suffixIndex = value.search(/[?#]/u), pathname = suffixIndex < 0 ? value : value.slice(0, suffixIndex), suffix = suffixIndex < 0 ? "" : value.slice(suffixIndex), path = pathname.slice(SOURCE_ASSET_PATH.length);
1802
+ return assertSafeAssetPath(path), `${SOURCE_ASSET_PREFIX}/${path}${suffix}`;
1803
+ }
1804
+
1805
+ // src/lib/compiler/markdown/convert-mdx-to-markdown.ts
1806
+ import remarkGfm from "remark-gfm";
1807
+ import remarkMdx2 from "remark-mdx";
1808
+ import remarkParse2 from "remark-parse";
1809
+ import remarkStringify from "remark-stringify";
1810
+ import { unified as unified2 } from "unified";
1811
+
1812
+ // src/lib/compiler/markdown/utils.ts
1813
+ function text(value) {
1814
+ return { type: "text", value };
1815
+ }
1816
+ function paragraph(children) {
1817
+ if (children.length !== 0)
1818
+ return { type: "paragraph", children };
1819
+ }
1820
+ function paragraphBlock(children) {
1821
+ let node = paragraph(children);
1822
+ return node ? [node] : [];
1823
+ }
1824
+ function strongLabel(value) {
1825
+ return { type: "strong", children: [text(value)] };
1826
+ }
1827
+ function inlineCode(value) {
1828
+ return { type: "inlineCode", value };
1829
+ }
1830
+ function normalizeComponentName(name) {
1831
+ return (name ?? "").trim().toLowerCase();
1832
+ }
1833
+ function addDiagnostic(context, diagnostic) {
1834
+ context.collectDiagnostics && context.diagnostics.push(diagnostic);
1835
+ }
1836
+ function getAttribute(node, name, context) {
1837
+ let attribute = node.attributes?.find(
1838
+ (candidate) => candidate.name === name
1839
+ );
1840
+ if (attribute) {
1841
+ if (attribute.value === null || attribute.value === void 0) return "true";
1842
+ if (typeof attribute.value == "string") return attribute.value;
1843
+ if (attribute.value.type === "mdxJsxAttributeValueExpression")
1844
+ return decodeExpressionValue(attribute.value.value, name, context);
1845
+ addDiagnostic(context, {
1846
+ code: "mdx-invalid-attribute",
1847
+ componentName: node.name ?? void 0,
1848
+ message: `Unsupported MDX attribute value for "${name}".`
1849
+ });
1850
+ }
1851
+ }
1852
+ function firstAttribute(node, names, context) {
1853
+ for (let name of names) {
1854
+ let value = getAttribute(node, name, context);
1855
+ if (value?.trim()) return value.trim();
1856
+ }
1857
+ }
1858
+ function decodeExpressionValue(value, attributeName, context) {
1859
+ let trimmed = value.trim();
1860
+ if (trimmed) {
1861
+ if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'"))
1862
+ try {
1863
+ return JSON.parse(
1864
+ trimmed.startsWith("'") ? `"${trimmed.slice(1, -1).replace(/"/g, '\\"')}"` : trimmed
1865
+ );
1866
+ } catch {
1867
+ return trimmed.slice(1, -1);
1868
+ }
1869
+ return trimmed.startsWith("`") && trimmed.endsWith("`") ? trimmed.slice(1, -1).replace(/\\`/g, "`").replace(/\\n/g, `
1870
+ `).replace(/\\t/g, " ") : (addDiagnostic(context, {
1871
+ code: "mdx-invalid-attribute",
1872
+ message: `MDX expression attribute "${attributeName}" was converted to literal text.`
1873
+ }), trimmed);
1874
+ }
1875
+ }
1876
+ function extractText(nodes) {
1877
+ return nodes.map((node) => {
1878
+ if (node.type === "break") return `
1879
+ `;
1880
+ if (node.type === "html" || node.type === "yaml") return "";
1881
+ if ("value" in node && typeof node.value == "string")
1882
+ return node.type === "code" ? `${node.value}
1883
+ ` : node.value;
1884
+ if ("alt" in node && typeof node.alt == "string") return node.alt;
1885
+ if ("children" in node && Array.isArray(node.children)) {
1886
+ let value = extractText(node.children);
1887
+ return [
1888
+ "emphasis",
1889
+ "strong",
1890
+ "delete",
1891
+ "link",
1892
+ "linkReference"
1893
+ ].includes(node.type) ? value : `${value}
1894
+ `;
1895
+ }
1896
+ return "";
1897
+ }).join("").trim();
1898
+ }
1899
+ function asPhrasing(nodes) {
1900
+ return nodes.flatMap((node) => {
1901
+ if (node.type === "paragraph") return node.children;
1902
+ if (node.type === "text" || node.type === "emphasis" || node.type === "strong" || node.type === "delete" || node.type === "inlineCode" || node.type === "break" || node.type === "link" || node.type === "image" || node.type === "html" || node.type === "footnoteReference")
1903
+ return [node];
1904
+ let label = extractText([node]);
1905
+ return label ? [text(label)] : [];
1906
+ });
1907
+ }
1908
+ function isBlockNode(node) {
1909
+ return node.type === "paragraph" || node.type === "heading" || node.type === "thematicBreak" || node.type === "blockquote" || node.type === "list" || node.type === "code" || node.type === "html" || node.type === "yaml" || node.type === "definition" || node.type === "footnoteDefinition" || node.type === "table";
1910
+ }
1911
+ function asBlocks(nodes) {
1912
+ let blocks = [], pendingPhrasing = [];
1913
+ for (let node of nodes)
1914
+ if (isBlockNode(node)) {
1915
+ let pendingParagraph2 = paragraph(pendingPhrasing);
1916
+ pendingParagraph2 && blocks.push(pendingParagraph2), pendingPhrasing = [], blocks.push(node);
1917
+ } else
1918
+ pendingPhrasing.push(node);
1919
+ let pendingParagraph = paragraph(pendingPhrasing);
1920
+ return pendingParagraph && blocks.push(pendingParagraph), blocks;
1921
+ }
1922
+ function handlerDiagnostic(node, context) {
1923
+ addDiagnostic(context, {
1924
+ code: "mdx-component-converted",
1925
+ componentName: node.name ?? void 0,
1926
+ message: `Converted MDX component "${node.name ?? "unknown"}" to Markdown.`
1927
+ });
1928
+ }
1929
+
1930
+ // src/lib/compiler/markdown/handlers/callout.ts
1931
+ function calloutHandler(node, context, kind) {
1932
+ handlerDiagnostic(node, context);
1933
+ let title = firstAttribute(node, ["title", "label", "type"], context);
1934
+ if (kind === "inline") {
1935
+ let children2 = context.transformChildrenAsPhrasing(node, context);
1936
+ return [
1937
+ ...title ? [strongLabel(`${title}:`), text(" ")] : [],
1938
+ ...children2
1939
+ ];
1940
+ }
1941
+ let children = [];
1942
+ return title && children.push({ type: "paragraph", children: [strongLabel(title)] }), children.push(
1943
+ ...context.transformChildrenAsBlocks(node, context)
1944
+ ), children.length > 0 ? [{ type: "blockquote", children }] : [];
1945
+ }
1946
+
1947
+ // src/lib/compiler/markdown/handlers/code-block.ts
1948
+ function codeBlockHandler(node, context) {
1949
+ handlerDiagnostic(node, context);
1950
+ let code = firstAttribute(node, ["code", "value"], context), language = firstAttribute(node, ["language", "lang"], context), title = firstAttribute(node, ["title"], context);
1951
+ return code !== void 0 ? [{
1952
+ type: "code",
1953
+ lang: language,
1954
+ meta: title === void 0 ? void 0 : `title="${title.replaceAll('"', "&quot;")}"`,
1955
+ value: code
1956
+ }] : context.transformChildrenAsBlocks(node, context);
1957
+ }
1958
+ function tabHandler(node, context) {
1959
+ handlerDiagnostic(node, context);
1960
+ let label = firstAttribute(
1961
+ node,
1962
+ ["title", "label", "value", "name"],
1963
+ context
1964
+ ), children = context.transformChildrenAsBlocks(node, context);
1965
+ return label ? [
1966
+ { type: "paragraph", children: [strongLabel(`Tab: ${label}`)] },
1967
+ ...children
1968
+ ] : children;
1969
+ }
1970
+
1971
+ // src/lib/compiler/markdown/handlers/html.ts
1972
+ function inlineHtmlHandler(node, context) {
1973
+ handlerDiagnostic(node, context);
1974
+ let children = context.transformChildrenAsPhrasing(node, context);
1975
+ switch (normalizeComponentName(node.name)) {
1976
+ case "strong":
1977
+ case "b":
1978
+ return [{ type: "strong", children }];
1979
+ case "em":
1980
+ case "i":
1981
+ return [{ type: "emphasis", children }];
1982
+ case "code":
1983
+ return [{ type: "inlineCode", value: extractText(children) }];
1984
+ case "br":
1985
+ return [{ type: "break" }];
1986
+ default:
1987
+ return children;
1988
+ }
1989
+ }
1990
+ function blockquoteHtmlHandler(node, context) {
1991
+ return handlerDiagnostic(node, context), [
1992
+ {
1993
+ type: "blockquote",
1994
+ children: node.type === "mdxJsxTextElement" ? paragraphBlock(context.transformChildrenAsPhrasing(node, context)) : context.transformChildrenAsBlocks(node, context)
1995
+ }
1996
+ ];
1997
+ }
1998
+ function paragraphHtmlHandler(node, context) {
1999
+ return handlerDiagnostic(node, context), paragraphBlock(context.transformChildrenAsPhrasing(node, context));
2000
+ }
2001
+ function preformattedText(node, context) {
2002
+ if (node.type === "mdxTextExpression" || node.type === "mdxFlowExpression") {
2003
+ let statement = node.data?.estree?.body?.[0], expression = statement?.type === "ExpressionStatement" ? statement.expression : void 0;
2004
+ return expression?.type === "Literal" && typeof expression.value == "string" ? expression.value : expression?.type === "TemplateLiteral" && expression.expressions?.length === 0 ? expression.quasis?.[0]?.value.cooked ?? "" : (addDiagnostic(context, {
2005
+ code: "mdx-expression-dropped",
2006
+ message: "Dropped non-literal MDX expression from preformatted Markdown output."
2007
+ }), "");
2008
+ }
2009
+ return typeof node.value == "string" ? node.value : (node.children ?? []).map((child, index) => (index > 0 && child.type === "paragraph" ? `
2010
+
2011
+ ` : "") + preformattedText(child, context)).join("");
2012
+ }
2013
+ function preHtmlHandler(node, context) {
2014
+ handlerDiagnostic(node, context);
2015
+ let code = node.children?.find((child) => child.name === "code");
2016
+ return [
2017
+ { type: "code", lang: code ? firstAttribute(code, ["className", "class"], context)?.match(
2018
+ /(?:^|\s)language-([^\s]+)/
2019
+ )?.[1] : void 0, value: preformattedText(node, context) }
2020
+ ];
2021
+ }
2022
+
2023
+ // src/lib/compiler/markdown/handlers/inline.ts
2024
+ function iconHandler(node, context) {
2025
+ handlerDiagnostic(node, context);
2026
+ let label = firstAttribute(
2027
+ node,
2028
+ ["aria-label", "label", "title", "alt"],
2029
+ context
2030
+ );
2031
+ return label ? [text(label)] : [];
2032
+ }
2033
+ function linkHandler(node, context) {
2034
+ let href = firstAttribute(node, ["href", "to", "url"], context);
2035
+ if (!href) return context.transformChildrenAsPhrasing(node, context);
2036
+ handlerDiagnostic(node, context);
2037
+ let children = context.transformChildrenAsPhrasing(node, context);
2038
+ return [{
2039
+ type: "link",
2040
+ url: context.resolveMediaUrl(href),
2041
+ children: children.length > 0 ? children : [text(href)]
2042
+ }];
2043
+ }
2044
+ function kbdHandler(node, context) {
2045
+ handlerDiagnostic(node, context);
2046
+ let label = extractText(context.transformChildrenAsPhrasing(node, context)) || firstAttribute(node, ["children", "label"], context);
2047
+ return label ? [inlineCode(label)] : [];
2048
+ }
2049
+ function inlineComponentHandlers() {
2050
+ return [
2051
+ {
2052
+ componentNames: ["icon"],
2053
+ transform: iconHandler
2054
+ },
2055
+ {
2056
+ componentNames: ["a", "link"],
2057
+ transform: linkHandler
2058
+ },
2059
+ {
2060
+ componentNames: ["kbd"],
2061
+ transform: kbdHandler
2062
+ }
2063
+ ];
2064
+ }
2065
+
2066
+ // src/lib/compiler/markdown/handlers/media.ts
2067
+ function imageHandler(node, context, kind) {
2068
+ let src = firstAttribute(node, ["src", "href"], context);
2069
+ if (!src) return [];
2070
+ handlerDiagnostic(node, context);
2071
+ let caption = firstAttribute(node, ["caption"], context), image = {
2072
+ type: "image",
2073
+ url: context.resolveMediaUrl(src),
2074
+ alt: getAttribute(node, "alt", context) ?? firstAttribute(node, ["title", "aria-label"], context) ?? "",
2075
+ title: firstAttribute(node, ["title"], context)
2076
+ };
2077
+ return kind === "inline" ? [image, ...caption ? [text(` ${caption}`)] : []] : [
2078
+ ...paragraphBlock([image]),
2079
+ ...caption ? paragraphBlock([text(caption)]) : []
2080
+ ];
2081
+ }
2082
+ function figureCaptionHandler(node, context) {
2083
+ return handlerDiagnostic(node, context), node.type === "mdxJsxTextElement" ? paragraphBlock(context.transformChildrenAsPhrasing(node, context)) : context.transformChildrenAsBlocks(node, context);
2084
+ }
2085
+ function isCaption(node) {
2086
+ return ["figcaption", "figurecaption", "figure.caption"].includes(
2087
+ normalizeComponentName(node.name)
2088
+ );
2089
+ }
2090
+ function hasDirectCaption(node) {
2091
+ return (node.children ?? []).some(
2092
+ (child) => isCaption(child) || (child.type === "paragraph" || child.type.startsWith("mdxJsx") && child.name === null) && hasDirectCaption(child)
2093
+ );
2094
+ }
2095
+ function figureHandler(node, context) {
2096
+ handlerDiagnostic(node, context);
2097
+ let children = context.transformChildrenAsBlocks(node, context);
2098
+ if (hasDirectCaption(node)) return children;
2099
+ let caption = firstAttribute(node, ["caption"], context);
2100
+ return [...children, ...caption ? paragraphBlock([text(caption)]) : []];
2101
+ }
2102
+ function videoHandler(node, context, kind) {
2103
+ let src = firstAttribute(node, ["src", "url", "href"], context);
2104
+ if (!src) return context.transformChildrenAsBlocks(node, context);
2105
+ handlerDiagnostic(node, context);
2106
+ let label = firstAttribute(node, ["title", "alt", "aria-label"], context) ?? "Video", link = {
2107
+ type: "link",
2108
+ url: context.resolveMediaUrl(src),
2109
+ children: [text(label)]
2110
+ }, children = [text("Video: "), link], caption = firstAttribute(node, ["caption"], context);
2111
+ return kind === "inline" ? [...children, ...caption ? [text(` ${caption}`)] : []] : [
2112
+ ...paragraphBlock(children),
2113
+ ...caption ? paragraphBlock([text(caption)]) : []
2114
+ ];
2115
+ }
2116
+
2117
+ // src/lib/compiler/markdown/handlers/passthrough.ts
2118
+ function passthroughBlockHandler(node, context) {
2119
+ return handlerDiagnostic(node, context), context.transformChildrenAsBlocks(node, context);
2120
+ }
2121
+ function detailsHandler(node, context) {
2122
+ handlerDiagnostic(node, context);
2123
+ let summary = firstAttribute(node, ["summary", "title", "label"], context) ?? "Details";
2124
+ return [
2125
+ { type: "paragraph", children: [strongLabel(summary)] },
2126
+ ...context.transformChildrenAsBlocks(node, context)
2127
+ ];
2128
+ }
2129
+
2130
+ // src/lib/compiler/markdown/handlers/registry.ts
2131
+ var defaultHandlers = [
2132
+ {
2133
+ componentNames: ["image", "img", "picture"],
2134
+ transform: imageHandler
2135
+ },
2136
+ ...inlineComponentHandlers(),
2137
+ {
2138
+ componentNames: ["callout", "admonition", "note", "warning"],
2139
+ transform: calloutHandler
2140
+ },
2141
+ {
2142
+ componentNames: ["codeblock"],
2143
+ transform: codeBlockHandler
2144
+ },
2145
+ {
2146
+ componentNames: ["strong", "b", "em", "i", "code", "span", "br"],
2147
+ transform: inlineHtmlHandler
2148
+ },
2149
+ {
2150
+ componentNames: ["pre"],
2151
+ transform: preHtmlHandler
2152
+ },
2153
+ {
2154
+ componentNames: ["blockquote"],
2155
+ transform: blockquoteHtmlHandler
2156
+ },
2157
+ {
2158
+ componentNames: ["p"],
2159
+ transform: paragraphHtmlHandler
2160
+ },
2161
+ {
2162
+ componentNames: ["div"],
2163
+ transform: passthroughBlockHandler
2164
+ },
2165
+ {
2166
+ componentNames: [
2167
+ "codetab",
2168
+ "codetabs",
2169
+ "tab",
2170
+ "tabpanel",
2171
+ "tabs",
2172
+ "tabscontent"
2173
+ ],
2174
+ transform: tabHandler
2175
+ },
2176
+ {
2177
+ componentNames: ["figure"],
2178
+ transform: figureHandler
2179
+ },
2180
+ {
2181
+ componentNames: ["figcaption", "figurecaption", "figure.caption"],
2182
+ transform: figureCaptionHandler
2183
+ },
2184
+ {
2185
+ componentNames: ["video", "videoiframe", "iframe"],
2186
+ transform: videoHandler
2187
+ },
2188
+ {
2189
+ componentNames: ["details", "accordion", "summary"],
2190
+ transform: detailsHandler
2191
+ },
2192
+ {
2193
+ componentNames: ["step", "steps"],
2194
+ transform: passthroughBlockHandler
2195
+ }
2196
+ ], handlersByName = new Map(
2197
+ defaultHandlers.flatMap(
2198
+ (handler) => handler.componentNames.map((name) => [name, handler])
2199
+ )
2200
+ );
2201
+
2202
+ // src/lib/compiler/markdown/convert-mdx-to-markdown.ts
2203
+ var processor = unified2().use(remarkParse2).use(remarkMdx2).use(remarkGfm).use(remarkStringify, {
2204
+ bullet: "-",
2205
+ fences: !0,
2206
+ incrementListMarker: !0,
2207
+ listItemIndent: "one",
2208
+ rule: "-"
2209
+ });
2210
+ function stripHtmlComments(source) {
2211
+ return source.replace(/<!--[\s\S]*?-->/g, "");
2212
+ }
2213
+ function stripTopLevelImports(source) {
2214
+ return source.split(`
2215
+ `).filter((line) => !/^\s*(?:import|export)\s/.test(line)).join(`
2216
+ `).trim();
2217
+ }
2218
+ function parseSource(source, context) {
2219
+ try {
2220
+ return processor.parse(source);
2221
+ } catch (error) {
2222
+ let withoutComments = stripHtmlComments(source);
2223
+ if (withoutComments !== source)
2224
+ try {
2225
+ return processor.parse(withoutComments);
2226
+ } catch {
2227
+ }
2228
+ addDiagnostic(context, {
2229
+ code: "mdx-parse-failed",
2230
+ message: error instanceof Error ? error.message : "Failed to parse MDX for Markdown output."
2231
+ });
2232
+ return;
2233
+ }
2234
+ }
2235
+ function transformChildrenAsBlocks(node, context) {
2236
+ return (node.children ?? []).flatMap(
2237
+ (child) => transformBlockNode(child, context)
2238
+ );
2239
+ }
2240
+ function transformChildrenAsPhrasing(node, context) {
2241
+ return (node.children ?? []).flatMap(
2242
+ (child) => transformInlineNode(child, context)
2243
+ );
2244
+ }
2245
+ function transformMdxElement(node, context, kind) {
2246
+ if (node.name === null)
2247
+ return kind === "block" ? transformChildrenAsBlocks(node, context) : transformChildrenAsPhrasing(node, context);
2248
+ if (node.name && context.importedIcons.has(node.name)) {
2249
+ let label = firstAttribute(node, ["aria-hidden"], context) === "true" ? "" : firstAttribute(node, ["aria-label", "title"], context), children2 = label ? [{ type: "text", value: label }] : [];
2250
+ return kind === "block" ? paragraphBlock(children2) : children2;
2251
+ }
2252
+ let componentName = normalizeComponentName(node.name), handler = handlersByName.get(componentName);
2253
+ if (handler) {
2254
+ let result = handler.transform(node, context, kind);
2255
+ return kind === "block" ? asBlocks(result) : asPhrasing(result);
2256
+ }
2257
+ if (addDiagnostic(context, {
2258
+ code: "mdx-component-unknown",
2259
+ componentName: node.name ?? void 0,
2260
+ message: `Unknown MDX component "${node.name ?? "unknown"}".`
2261
+ }), context.unknownComponentMode === "error")
2262
+ throw new Error(`Unknown MDX component "${node.name ?? "unknown"}".`);
2263
+ if (context.unknownComponentMode === "html") {
2264
+ let html = htmlFallback(node);
2265
+ return html ? [{ type: "html", value: html }] : [];
2266
+ }
2267
+ let children = kind === "inline" ? transformChildrenAsPhrasing(node, context) : transformChildrenAsBlocks(node, context);
2268
+ return kind === "block" ? asBlocks(children) : asPhrasing(children);
2269
+ }
2270
+ function htmlFallback(node) {
2271
+ if (!node.name) return;
2272
+ let attrs = (node.attributes ?? []).map((attr) => {
2273
+ if (attr.value === null || attr.value === void 0) return attr.name;
2274
+ if (typeof attr.value == "string")
2275
+ return `${attr.name}="${attr.value.replace(/"/g, "&quot;")}"`;
2276
+ }).filter((value) => !!value).join(" ");
2277
+ return `<${node.name}${attrs ? ` ${attrs}` : ""} />`;
2278
+ }
2279
+ function transformInlineNode(node, context) {
2280
+ if (node.type === "mdxJsxTextElement")
2281
+ return asPhrasing(transformMdxElement(node, context, "inline"));
2282
+ if (node.type === "mdxTextExpression")
2283
+ return addDiagnostic(context, {
2284
+ code: "mdx-expression-dropped",
2285
+ message: "Dropped inline MDX expression from Markdown output."
2286
+ }), [];
2287
+ switch (node.type) {
2288
+ case "text":
2289
+ case "inlineCode":
2290
+ case "break":
2291
+ case "footnoteReference":
2292
+ return [node];
2293
+ case "emphasis":
2294
+ return [{
2295
+ ...node,
2296
+ children: transformChildrenAsPhrasing(node, context)
2297
+ }];
2298
+ case "strong":
2299
+ return [{
2300
+ ...node,
2301
+ children: transformChildrenAsPhrasing(node, context)
2302
+ }];
2303
+ case "delete":
2304
+ return [{
2305
+ ...node,
2306
+ children: transformChildrenAsPhrasing(node, context)
2307
+ }];
2308
+ case "link":
2309
+ return [{
2310
+ ...node,
2311
+ url: context.resolveMediaUrl(node.url),
2312
+ children: transformChildrenAsPhrasing(node, context)
2313
+ }];
2314
+ case "image":
2315
+ return [
2316
+ {
2317
+ ...node,
2318
+ url: context.resolveMediaUrl(node.url)
2319
+ }
2320
+ ];
2321
+ case "linkReference":
2322
+ case "imageReference":
2323
+ return [node];
2324
+ case "html":
2325
+ return [node];
2326
+ default:
2327
+ return [];
2328
+ }
2329
+ }
2330
+ function transformListItem(node, context) {
2331
+ return {
2332
+ ...node,
2333
+ children: transformChildrenAsBlocks(node, context)
2334
+ };
2335
+ }
2336
+ function transformTableCell(node, context) {
2337
+ return {
2338
+ ...node,
2339
+ children: transformChildrenAsPhrasing(node, context)
2340
+ };
2341
+ }
2342
+ function transformTableRow(node, context) {
2343
+ return {
2344
+ ...node,
2345
+ children: (node.children ?? []).map(
2346
+ (child) => transformTableCell(child, context)
2347
+ )
2348
+ };
2349
+ }
2350
+ function isFigureBlock(node) {
2351
+ if (node.type !== "mdxJsxTextElement" && node.type !== "mdxJsxFlowElement")
2352
+ return !1;
2353
+ if (node.name === null) return (node.children ?? []).some(isFigureBlock);
2354
+ let name = normalizeComponentName(node.name);
2355
+ return [
2356
+ "figure",
2357
+ "figcaption",
2358
+ "figurecaption",
2359
+ "figure.caption",
2360
+ "pre",
2361
+ "blockquote"
2362
+ ].includes(name) || ["image", "img", "video", "videoiframe", "iframe"].includes(name) && (node.attributes ?? []).some((attribute) => attribute.name === "caption");
2363
+ }
2364
+ function transformBlockNode(node, context) {
2365
+ if (node.type === "mdxjsEsm")
2366
+ return addDiagnostic(context, {
2367
+ code: "mdx-esm-dropped",
2368
+ message: "Dropped MDX import/export from Markdown output."
2369
+ }), [];
2370
+ if (node.type === "mdxFlowExpression")
2371
+ return addDiagnostic(context, {
2372
+ code: "mdx-expression-dropped",
2373
+ message: "Dropped flow MDX expression from Markdown output."
2374
+ }), [];
2375
+ if (node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement")
2376
+ return transformMdxElement(node, context, "block");
2377
+ switch (node.type) {
2378
+ case "paragraph": {
2379
+ if ((node.children ?? []).some(isFigureBlock)) {
2380
+ let blocks = [], pending = [], flushPhrasing = () => {
2381
+ let children = transformChildrenAsPhrasing(
2382
+ { type: "paragraph", children: pending },
2383
+ context
2384
+ );
2385
+ children.some(
2386
+ (child) => child.type !== "text" || child.value.trim()
2387
+ ) && blocks.push(...paragraphBlock(children)), pending = [];
2388
+ };
2389
+ for (let child of node.children ?? [])
2390
+ isFigureBlock(child) ? (flushPhrasing(), blocks.push(...transformBlockNode(child, context))) : pending.push(child);
2391
+ return flushPhrasing(), blocks;
2392
+ }
2393
+ let paragraphNode = paragraph(
2394
+ transformChildrenAsPhrasing(node, context)
2395
+ );
2396
+ return paragraphNode ? [paragraphNode] : [];
2397
+ }
2398
+ case "heading":
2399
+ return [{
2400
+ ...node,
2401
+ children: transformChildrenAsPhrasing(node, context)
2402
+ }];
2403
+ case "blockquote":
2404
+ return [
2405
+ {
2406
+ ...node,
2407
+ children: transformChildrenAsBlocks(node, context)
2408
+ }
2409
+ ];
2410
+ case "list":
2411
+ return [{
2412
+ ...node,
2413
+ children: (node.children ?? []).map(
2414
+ (child) => transformListItem(child, context)
2415
+ )
2416
+ }];
2417
+ case "table":
2418
+ return [{
2419
+ ...node,
2420
+ children: (node.children ?? []).map(
2421
+ (child) => transformTableRow(child, context)
2422
+ )
2423
+ }];
2424
+ case "text":
2425
+ case "inlineCode":
2426
+ case "break":
2427
+ case "emphasis":
2428
+ case "strong":
2429
+ case "delete":
2430
+ case "link":
2431
+ case "image":
2432
+ case "footnoteReference":
2433
+ return paragraphBlock(transformInlineNode(node, context));
2434
+ case "code":
2435
+ case "thematicBreak":
2436
+ case "html":
2437
+ case "yaml":
2438
+ case "footnoteDefinition":
2439
+ return [node];
2440
+ case "definition":
2441
+ return [
2442
+ {
2443
+ ...node,
2444
+ url: context.resolveMediaUrl(node.url)
2445
+ }
2446
+ ];
2447
+ default:
2448
+ return [];
2449
+ }
2450
+ }
2451
+ function convertMdxToMarkdown(options) {
2452
+ let context = {
2453
+ importedIcons: /* @__PURE__ */ new Set(),
2454
+ collectDiagnostics: options.collectDiagnostics ?? !0,
2455
+ diagnostics: [],
2456
+ resolveMediaUrl: (url) => String(mapSourceAssetUrl(url)),
2457
+ transformChildrenAsBlocks,
2458
+ transformChildrenAsPhrasing,
2459
+ unknownComponentMode: options.unknownComponentMode ?? "children"
2460
+ }, parsed = parseSource(options.source, context);
2461
+ if (!parsed)
2462
+ return {
2463
+ diagnostics: context.diagnostics,
2464
+ markdown: stripTopLevelImports(options.source),
2465
+ text: ""
2466
+ };
2467
+ for (let node of parsed.children)
2468
+ if (node.type === "mdxjsEsm") {
2469
+ for (let statement of node.data?.estree?.body ?? [])
2470
+ if (!(statement.type !== "ImportDeclaration" || statement.source.value !== mdxIconPackage))
2471
+ for (let specifier of statement.specifiers)
2472
+ specifier.type === "ImportSpecifier" && context.importedIcons.add(specifier.local.name);
2473
+ }
2474
+ let transformed = {
2475
+ type: "root",
2476
+ children: parsed.children.flatMap(
2477
+ (child) => transformBlockNode(child, context)
2478
+ )
2479
+ }, markdown = String(processor.stringify(transformed)).trim();
2480
+ return {
2481
+ diagnostics: context.diagnostics,
2482
+ markdown,
2483
+ text: extractText(transformed.children)
2484
+ };
2485
+ }
2486
+
1680
2487
  export {
1681
- UnsupportedFrontmatterLanguageError,
2488
+ mapSourceAssetUrl,
2489
+ FrontmatterParseError,
1682
2490
  parseSourceFrontmatter,
1683
2491
  groupedMdxExports,
1684
2492
  replacedMdxSourceFiles,
@@ -1689,6 +2497,7 @@ export {
1689
2497
  MdxIconImportError,
1690
2498
  readMdxIconImports,
1691
2499
  validateMdxIconImports,
2500
+ convertMdxToMarkdown,
1692
2501
  ROOT_CONTENT_GROUP_KEY,
1693
2502
  ROOT_CONTENT_GROUP_TITLE,
1694
2503
  assertSourceDependency,
@@ -1705,5 +2514,6 @@ export {
1705
2514
  mediaManifestModule,
1706
2515
  normalizeSlugPath,
1707
2516
  normalizeUrlPath,
1708
- joinUrlPath
2517
+ joinUrlPath,
2518
+ authoredDate
1709
2519
  };