@jxsuite/parser 0.28.2 → 0.28.4

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.
package/dist/markdown.js CHANGED
@@ -858,6 +858,33 @@ var init_unified = __esm(() => {
858
858
  init_lib3();
859
859
  });
860
860
 
861
+ // ../schema/src/guards.ts
862
+ function isJsonObject(value) {
863
+ return typeof value === "object" && value !== null && !Array.isArray(value);
864
+ }
865
+ function isRef(value) {
866
+ return isJsonObject(value) && typeof value.$ref === "string";
867
+ }
868
+ var SCHEMA_KEYWORDS;
869
+ var init_guards = __esm(() => {
870
+ SCHEMA_KEYWORDS = new Set([
871
+ "type",
872
+ "enum",
873
+ "minimum",
874
+ "maximum",
875
+ "minLength",
876
+ "maxLength",
877
+ "pattern",
878
+ "format",
879
+ "items",
880
+ "properties",
881
+ "required",
882
+ "description",
883
+ "title",
884
+ "$comment"
885
+ ]);
886
+ });
887
+
861
888
  // ../../node_modules/.bun/zwitch@2.0.4/node_modules/zwitch/index.js
862
889
  function zwitch(key, options) {
863
890
  const settings = options || {};
@@ -29587,29 +29614,33 @@ function convertHastChildren(children) {
29587
29614
  const result = [];
29588
29615
  for (const child of children) {
29589
29616
  const converted = convertHastNode(child);
29590
- if (converted != null)
29617
+ if (converted != null) {
29591
29618
  result.push(converted);
29619
+ }
29592
29620
  }
29593
29621
  return result;
29594
29622
  }
29595
29623
  function convertHastNode(node2) {
29596
29624
  if (node2.type === "text") {
29597
- if (whitespace(node2))
29625
+ if (whitespace(node2)) {
29598
29626
  return null;
29627
+ }
29599
29628
  return node2.value ?? null;
29600
29629
  }
29601
29630
  if (node2.type === "element") {
29602
29631
  const el = { tagName: node2.tagName };
29603
29632
  if (node2.properties && Object.keys(node2.properties).length > 0) {
29604
29633
  const { style: style2, attrs } = hastPropsToJx(node2.properties);
29605
- if (Object.keys(attrs).length > 0)
29634
+ if (Object.keys(attrs).length > 0) {
29606
29635
  el.attributes = attrs;
29607
- if (Object.keys(style2).length > 0)
29636
+ }
29637
+ if (Object.keys(style2).length > 0) {
29608
29638
  el.style = style2;
29639
+ }
29609
29640
  }
29610
29641
  const kids = node2.children ? convertHastChildren(node2.children) : [];
29611
29642
  if (kids.length === 1 && typeof kids[0] === "string") {
29612
- el.textContent = kids[0];
29643
+ [el.textContent] = kids;
29613
29644
  } else if (kids.length > 0) {
29614
29645
  el.children = kids;
29615
29646
  }
@@ -29621,8 +29652,9 @@ function hastPropsToJx(properties) {
29621
29652
  const attrs = {};
29622
29653
  const style2 = {};
29623
29654
  for (const [key, value] of Object.entries(properties)) {
29624
- if (value === false || value === undefined || value === null)
29655
+ if (value === false || value === undefined || value === null) {
29625
29656
  continue;
29657
+ }
29626
29658
  const info = find2(html5, key);
29627
29659
  const name = info.attribute;
29628
29660
  if (name === "style" && typeof value === "string") {
@@ -29637,17 +29669,19 @@ function hastPropsToJx(properties) {
29637
29669
  attrs[name] = String(value);
29638
29670
  }
29639
29671
  }
29640
- return { style: style2, attrs };
29672
+ return { attrs, style: style2 };
29641
29673
  }
29642
29674
  function parseInlineStyle(styleStr, out) {
29643
29675
  for (const decl of styleStr.split(";")) {
29644
29676
  const colon = decl.indexOf(":");
29645
- if (colon === -1)
29677
+ if (colon === -1) {
29646
29678
  continue;
29679
+ }
29647
29680
  const prop = decl.slice(0, colon).trim();
29648
29681
  const val = decl.slice(colon + 1).trim();
29649
- if (prop && val)
29682
+ if (prop && val) {
29650
29683
  out[prop] = val;
29684
+ }
29651
29685
  }
29652
29686
  }
29653
29687
  var init_html_to_jx = __esm(() => {
@@ -29657,6 +29691,9 @@ var init_html_to_jx = __esm(() => {
29657
29691
  });
29658
29692
 
29659
29693
  // src/serialize.ts
29694
+ function textOf(el) {
29695
+ return el && typeof el.textContent === "string" ? el.textContent : undefined;
29696
+ }
29660
29697
  function isInlineType(type) {
29661
29698
  return ["text", "emphasis", "strong", "delete", "inlineCode", "link", "image", "break"].includes(type);
29662
29699
  }
@@ -29668,29 +29705,32 @@ function codeLang(codeChild) {
29668
29705
  function mdastToJx(mdast) {
29669
29706
  if (mdast.type === "root") {
29670
29707
  return {
29671
- children: (mdast.children ?? []).filter((n) => n.type !== "yaml" && n.type !== "toml").flatMap(convertMdastNode).filter(Boolean)
29708
+ children: (mdast.children ?? []).filter((n) => n.type !== "yaml" && n.type !== "toml").flatMap((n) => convertMdastNode(n)).filter(Boolean)
29672
29709
  };
29673
29710
  }
29674
29711
  return convertMdastNode(mdast);
29675
29712
  }
29676
29713
  function convertMdastNode(node2) {
29677
- if (!node2)
29714
+ if (!node2) {
29678
29715
  return null;
29716
+ }
29679
29717
  if (node2.type === "containerDirective" || node2.type === "leafDirective" || node2.type === "textDirective") {
29680
29718
  return convertDirective(node2);
29681
29719
  }
29682
29720
  if (node2.type === "html") {
29683
- if (!node2.value)
29721
+ if (!node2.value) {
29684
29722
  return null;
29723
+ }
29685
29724
  const nodes = htmlToJx(node2.value);
29686
- return nodes.length === 1 ? nodes[0] : { tagName: "div", children: nodes };
29725
+ return nodes.length === 1 ? nodes[0] : { children: nodes, tagName: "div" };
29687
29726
  }
29688
29727
  const tagFn = MDAST_TAG_MAP[node2.type];
29689
- if (!tagFn)
29728
+ if (!tagFn) {
29690
29729
  return null;
29730
+ }
29691
29731
  const tag = tagFn(node2);
29692
29732
  const el = { tagName: tag };
29693
- const childNodes = () => (node2.children ?? []).flatMap(convertMdastNode).filter(Boolean);
29733
+ const childNodes = () => (node2.children ?? []).flatMap((n) => convertMdastNode(n)).filter(Boolean);
29694
29734
  const flattenOrChildren = () => {
29695
29735
  if (node2.children?.length === 1 && node2.children[0].type === "text") {
29696
29736
  el.textContent = node2.children[0].value ?? null;
@@ -29704,38 +29744,48 @@ function convertMdastNode(node2) {
29704
29744
  case "emphasis":
29705
29745
  case "strong":
29706
29746
  case "delete":
29707
- case "tableCell":
29747
+ case "tableCell": {
29708
29748
  flattenOrChildren();
29709
29749
  break;
29750
+ }
29710
29751
  case "text":
29711
- case "inlineCode":
29752
+ case "inlineCode": {
29712
29753
  el.textContent = node2.value ?? null;
29713
29754
  break;
29714
- case "link":
29755
+ }
29756
+ case "link": {
29715
29757
  el.attributes = { href: node2.url ?? "" };
29716
- if (node2.title)
29758
+ if (node2.title) {
29717
29759
  el.attributes.title = node2.title;
29760
+ }
29718
29761
  flattenOrChildren();
29719
29762
  break;
29720
- case "image":
29721
- el.attributes = { src: node2.url ?? "", alt: node2.alt ?? "" };
29722
- if (node2.title)
29763
+ }
29764
+ case "image": {
29765
+ el.attributes = { alt: node2.alt ?? "", src: node2.url ?? "" };
29766
+ if (node2.title) {
29723
29767
  el.attributes.title = node2.title;
29768
+ }
29724
29769
  break;
29770
+ }
29725
29771
  case "blockquote":
29726
29772
  case "listItem":
29727
- case "tableRow":
29728
- if (node2.children?.length)
29773
+ case "tableRow": {
29774
+ if (node2.children?.length) {
29729
29775
  el.children = childNodes();
29776
+ }
29730
29777
  break;
29731
- case "list":
29732
- if (node2.children?.length)
29778
+ }
29779
+ case "list": {
29780
+ if (node2.children?.length) {
29733
29781
  el.children = childNodes();
29782
+ }
29734
29783
  if (node2.start != null && node2.start !== 1) {
29735
29784
  el.attributes = { start: String(node2.start) };
29736
29785
  }
29737
29786
  break;
29738
- case "code":
29787
+ }
29788
+ case "code": {
29739
29789
  el.children = [
29740
29790
  {
29741
29791
  tagName: "code",
@@ -29744,19 +29794,24 @@ function convertMdastNode(node2) {
29744
29794
  }
29745
29795
  ];
29746
29796
  break;
29797
+ }
29747
29798
  case "thematicBreak":
29748
- case "break":
29799
+ case "break": {
29749
29800
  break;
29801
+ }
29750
29802
  case "table": {
29751
29803
  const rows = childNodes();
29752
- const thead = rows.length > 0 ? { tagName: "thead", children: [rows[0]] } : null;
29804
+ const thead = rows.length > 0 ? { children: [rows[0]], tagName: "thead" } : null;
29753
29805
  const tbody = rows.length > 1 ? {
29754
- tagName: "tbody",
29755
- children: rows.slice(1)
29806
+ children: rows.slice(1),
29807
+ tagName: "tbody"
29756
29808
  } : null;
29757
29809
  el.children = [thead, tbody].filter(Boolean);
29758
29810
  break;
29759
29811
  }
29812
+ default: {
29813
+ break;
29814
+ }
29760
29815
  }
29761
29816
  return el;
29762
29817
  }
@@ -29769,10 +29824,10 @@ function convertDirective(node2) {
29769
29824
  if (node2.children?.length === 1 && node2.children[0].type === "text") {
29770
29825
  el.textContent = node2.children[0].value ?? null;
29771
29826
  } else if (node2.children?.length) {
29772
- el.children = node2.children.flatMap(convertMdastNode).filter(Boolean);
29827
+ el.children = node2.children.flatMap((n) => convertMdastNode(n)).filter(Boolean);
29773
29828
  }
29774
29829
  } else if (node2.type === "containerDirective" && node2.children?.length) {
29775
- el.children = node2.children.flatMap(convertMdastNode).filter(Boolean);
29830
+ el.children = node2.children.flatMap((n) => convertMdastNode(n)).filter(Boolean);
29776
29831
  }
29777
29832
  return el;
29778
29833
  }
@@ -29780,17 +29835,19 @@ function jxToMdast(jx, opts = {}) {
29780
29835
  const allowlist = normalizeAllowlist(opts.allowlist);
29781
29836
  const childArray = Array.isArray(jx.children) ? jx.children : [];
29782
29837
  const children = childArray.map((child) => convertJxNode(child, true, allowlist)).filter(Boolean);
29783
- return { type: "root", children };
29838
+ return { children, type: "root" };
29784
29839
  }
29785
29840
  function normalizeAllowlist(allowlist) {
29786
- if (!allowlist)
29841
+ if (!allowlist) {
29787
29842
  return MD_ALL;
29843
+ }
29788
29844
  return allowlist instanceof Set ? allowlist : new Set(allowlist);
29789
29845
  }
29790
29846
  function hasJxProps(el) {
29791
29847
  for (const key of Object.keys(el)) {
29792
- if (key === "tagName" || key === "children" || key === "textContent" || key === "innerHTML" || key === "attributes")
29848
+ if (key === "tagName" || key === "children" || key === "textContent" || key === "innerHTML" || key === "attributes") {
29793
29849
  continue;
29850
+ }
29794
29851
  return true;
29795
29852
  }
29796
29853
  return false;
@@ -29799,121 +29856,144 @@ function convertJxNode(el, isBlock, allowlist) {
29799
29856
  if (typeof el === "string" || typeof el === "number") {
29800
29857
  return { type: "text", value: String(el) };
29801
29858
  }
29802
- if (!el || typeof el !== "object")
29859
+ if (!el || typeof el !== "object") {
29803
29860
  return null;
29861
+ }
29804
29862
  const tag = el.tagName ?? "div";
29805
29863
  if (!allowlist.has(tag) || hasJxProps(el)) {
29806
29864
  return convertToDirective(el, isBlock, allowlist);
29807
29865
  }
29808
29866
  const mdastType = TAG_MDAST_MAP[tag];
29809
- if (!mdastType)
29867
+ if (!mdastType) {
29810
29868
  return null;
29869
+ }
29811
29870
  const inline = (e) => {
29812
- if (e.textContent != null)
29871
+ if (e.textContent != null) {
29813
29872
  return [{ type: "text", value: String(e.textContent) }];
29873
+ }
29814
29874
  return (e.children ?? []).map((c) => convertJxNode(c, false, allowlist)).filter(Boolean);
29815
29875
  };
29816
29876
  const block = (e) => {
29817
29877
  if (e.textContent != null) {
29818
29878
  return [
29819
29879
  {
29820
- type: "paragraph",
29821
- children: [{ type: "text", value: String(e.textContent) }]
29880
+ children: [{ type: "text", value: String(e.textContent) }],
29881
+ type: "paragraph"
29822
29882
  }
29823
29883
  ];
29824
29884
  }
29825
29885
  return (e.children ?? []).map((c) => convertJxNode(c, true, allowlist)).filter(Boolean);
29826
29886
  };
29827
29887
  switch (mdastType) {
29828
- case "heading":
29888
+ case "heading": {
29829
29889
  return {
29830
- type: "heading",
29831
- depth: parseInt(tag.slice(1), 10),
29832
- children: inline(el)
29890
+ children: inline(el),
29891
+ depth: Number.parseInt(tag.slice(1), 10),
29892
+ type: "heading"
29833
29893
  };
29834
- case "paragraph":
29835
- return { type: "paragraph", children: inline(el) };
29836
- case "text":
29837
- return { type: "text", value: el.textContent ?? "" };
29894
+ }
29895
+ case "paragraph": {
29896
+ return { children: inline(el), type: "paragraph" };
29897
+ }
29898
+ case "text": {
29899
+ return { type: "text", value: textOf(el) ?? "" };
29900
+ }
29838
29901
  case "emphasis":
29839
29902
  case "strong":
29840
- case "delete":
29841
- return { type: mdastType, children: inline(el) };
29842
- case "inlineCode":
29843
- return { type: "inlineCode", value: el.textContent ?? "" };
29844
- case "link":
29903
+ case "delete": {
29904
+ return { children: inline(el), type: mdastType };
29905
+ }
29906
+ case "inlineCode": {
29907
+ return { type: "inlineCode", value: textOf(el) ?? "" };
29908
+ }
29909
+ case "link": {
29845
29910
  return {
29846
- type: "link",
29847
- url: el.attributes?.href ?? "",
29911
+ children: inline(el),
29848
29912
  title: el.attributes?.title ?? null,
29849
- children: inline(el)
29913
+ type: "link",
29914
+ url: el.attributes?.href ?? ""
29850
29915
  };
29851
- case "image":
29916
+ }
29917
+ case "image": {
29852
29918
  return {
29853
- type: "image",
29854
- url: el.attributes?.src ?? "",
29855
29919
  alt: el.attributes?.alt ?? "",
29856
- title: el.attributes?.title ?? null
29920
+ title: el.attributes?.title ?? null,
29921
+ type: "image",
29922
+ url: el.attributes?.src ?? ""
29857
29923
  };
29858
- case "blockquote":
29859
- return { type: "blockquote", children: block(el) };
29860
- case "list":
29924
+ }
29925
+ case "blockquote": {
29926
+ return { children: block(el), type: "blockquote" };
29927
+ }
29928
+ case "list": {
29861
29929
  return {
29862
- type: "list",
29930
+ children: (el.children ?? []).map((c) => convertJxNode(c, true, allowlist)).filter(Boolean),
29863
29931
  ordered: tag === "ol",
29864
- start: tag === "ol" ? parseInt(el.attributes?.start, 10) || 1 : null,
29865
29932
  spread: false,
29866
- children: (el.children ?? []).map((c) => convertJxNode(c, true, allowlist)).filter(Boolean)
29933
+ start: tag === "ol" ? Number.parseInt(el.attributes?.start, 10) || 1 : null,
29934
+ type: "list"
29867
29935
  };
29868
- case "listItem":
29869
- return { type: "listItem", spread: false, children: block(el) };
29936
+ }
29937
+ case "listItem": {
29938
+ return { children: block(el), spread: false, type: "listItem" };
29939
+ }
29870
29940
  case "code": {
29871
29941
  const codeChild = Array.isArray(el.children) ? el.children[0] : undefined;
29872
29942
  return {
29873
- type: "code",
29874
29943
  lang: codeLang(codeChild),
29875
- value: codeChild?.textContent ?? el.textContent ?? ""
29944
+ type: "code",
29945
+ value: textOf(codeChild) ?? textOf(el) ?? ""
29876
29946
  };
29877
29947
  }
29878
- case "thematicBreak":
29948
+ case "thematicBreak": {
29879
29949
  return { type: "thematicBreak" };
29880
- case "break":
29950
+ }
29951
+ case "break": {
29881
29952
  return { type: "break" };
29953
+ }
29882
29954
  case "table": {
29883
29955
  const rows = [];
29884
29956
  for (const section of el.children ?? []) {
29885
- if (typeof section === "string")
29957
+ if (typeof section === "string") {
29886
29958
  continue;
29959
+ }
29887
29960
  if (section.tagName === "thead" || section.tagName === "tbody") {
29888
29961
  for (const row of section.children ?? []) {
29889
29962
  const mdRow = convertJxNode(row, true, allowlist);
29890
29963
  if (mdRow) {
29891
29964
  if (section.tagName === "thead") {
29892
- for (const cell of mdRow.children ?? [])
29965
+ for (const cell of mdRow.children ?? []) {
29893
29966
  cell.isHeader = true;
29967
+ }
29894
29968
  }
29895
29969
  rows.push(mdRow);
29896
29970
  }
29897
29971
  }
29898
29972
  }
29899
29973
  }
29900
- return { type: "table", children: rows };
29974
+ return { children: rows, type: "table" };
29901
29975
  }
29902
- case "tableRow":
29976
+ case "tableRow": {
29903
29977
  return {
29904
- type: "tableRow",
29905
- children: (el.children ?? []).map((c) => convertJxNode(c, false, allowlist)).filter(Boolean)
29978
+ children: (el.children ?? []).map((c) => convertJxNode(c, false, allowlist)).filter(Boolean),
29979
+ type: "tableRow"
29906
29980
  };
29907
- case "tableCell":
29908
- return { type: "tableCell", children: inline(el) };
29981
+ }
29982
+ case "tableCell": {
29983
+ return { children: inline(el), type: "tableCell" };
29984
+ }
29985
+ default: {
29986
+ break;
29987
+ }
29909
29988
  }
29910
29989
  return null;
29911
29990
  }
29912
29991
  function collectDirectiveAttrs(el) {
29913
29992
  const propsObj = {};
29914
29993
  for (const [key, value] of Object.entries(el)) {
29915
- if (key === "tagName" || key === "textContent" || key === "innerHTML" || key === "attributes")
29994
+ if (key === "tagName" || key === "textContent" || key === "innerHTML" || key === "attributes") {
29916
29995
  continue;
29996
+ }
29917
29997
  if (key === "children") {
29918
29998
  if (value && typeof value === "object" && !Array.isArray(value)) {
29919
29999
  propsObj.children = value;
@@ -29934,10 +30014,10 @@ function convertToDirective(el, isBlock, allowlist) {
29934
30014
  const attrs = collectDirectiveAttrs(el);
29935
30015
  if (!isBlock) {
29936
30016
  return {
29937
- type: "textDirective",
29938
- name: tag,
29939
30017
  attributes: attrs,
29940
- children: el.textContent != null ? [{ type: "text", value: String(el.textContent) }] : (el.children ?? []).map((c) => convertJxNode(c, false, allowlist)).filter(Boolean)
30018
+ children: el.textContent != null ? [{ type: "text", value: String(el.textContent) }] : (el.children ?? []).map((c) => convertJxNode(c, false, allowlist)).filter(Boolean),
30019
+ name: tag,
30020
+ type: "textDirective"
29941
30021
  };
29942
30022
  }
29943
30023
  const rawChildren = el.children;
@@ -29945,31 +30025,31 @@ function convertToDirective(el, isBlock, allowlist) {
29945
30025
  const childArray = childrenIsObject ? undefined : rawChildren;
29946
30026
  if (!childArray?.length && el.textContent == null) {
29947
30027
  return {
29948
- type: "leafDirective",
29949
- name: tag,
29950
30028
  attributes: attrs,
29951
- children: []
30029
+ children: [],
30030
+ name: tag,
30031
+ type: "leafDirective"
29952
30032
  };
29953
30033
  }
29954
30034
  let directiveChildren;
29955
30035
  if (el.textContent != null) {
29956
30036
  directiveChildren = [
29957
30037
  {
29958
- type: "paragraph",
29959
- children: [{ type: "text", value: String(el.textContent) }]
30038
+ children: [{ type: "text", value: String(el.textContent) }],
30039
+ type: "paragraph"
29960
30040
  }
29961
30041
  ];
29962
30042
  } else if (INLINE_CONTENT_TAGS.has(tag)) {
29963
30043
  const inlineNodes = (el.children ?? []).map((c) => convertJxNode(c, false, allowlist)).filter(Boolean);
29964
- directiveChildren = inlineNodes.length > 0 ? [{ type: "paragraph", children: inlineNodes }] : [];
30044
+ directiveChildren = inlineNodes.length > 0 ? [{ children: inlineNodes, type: "paragraph" }] : [];
29965
30045
  } else {
29966
30046
  directiveChildren = (el.children ?? []).map((c) => convertJxNode(c, true, allowlist)).filter(Boolean);
29967
30047
  }
29968
30048
  return {
29969
- type: "containerDirective",
29970
- name: tag,
29971
30049
  attributes: attrs,
29972
- children: directiveChildren
30050
+ children: directiveChildren,
30051
+ name: tag,
30052
+ type: "containerDirective"
29973
30053
  };
29974
30054
  }
29975
30055
  function collapsePropsToAttrMap(propsObj) {
@@ -30013,8 +30093,9 @@ function nodeToMdast(node2, ctx, scope) {
30013
30093
  if (typeof node2 === "number") {
30014
30094
  return [{ type: "text", value: String(node2) }];
30015
30095
  }
30016
- if (!node2 || typeof node2 !== "object")
30096
+ if (!node2 || typeof node2 !== "object") {
30017
30097
  return [];
30098
+ }
30018
30099
  if (node2.$prototype === "Array") {
30019
30100
  return expandArray(node2, ctx, scope);
30020
30101
  }
@@ -30022,113 +30103,124 @@ function nodeToMdast(node2, ctx, scope) {
30022
30103
  const text3 = resolveText(node2.textContent, ctx, scope);
30023
30104
  if (typeof node2.innerHTML === "string" && node2.innerHTML.trim()) {
30024
30105
  const htmlNodes = htmlToMdast(node2.innerHTML);
30025
- if (htmlNodes.length > 0)
30106
+ if (htmlNodes.length > 0) {
30026
30107
  return htmlNodes;
30108
+ }
30027
30109
  }
30028
30110
  if (tag.includes("-")) {
30029
30111
  return inlineComponent(node2, tag, ctx);
30030
30112
  }
30031
30113
  if (WRAPPER_TAGS.has(tag)) {
30032
30114
  if (text3 != null) {
30033
- return text3.trim() ? [{ type: "paragraph", children: [{ type: "text", value: text3 }] }] : [];
30115
+ return text3.trim() ? [{ children: [{ type: "text", value: text3 }], type: "paragraph" }] : [];
30034
30116
  }
30035
30117
  return exportChildren(node2, ctx, scope);
30036
30118
  }
30037
30119
  const mdastType = TAG_MDAST_MAP[tag];
30038
30120
  if (!mdastType) {
30039
30121
  if (text3 != null) {
30040
- return text3.trim() ? [{ type: "paragraph", children: [{ type: "text", value: text3 }] }] : [];
30122
+ return text3.trim() ? [{ children: [{ type: "text", value: text3 }], type: "paragraph" }] : [];
30041
30123
  }
30042
30124
  return exportChildren(node2, ctx, scope);
30043
30125
  }
30044
30126
  switch (mdastType) {
30045
30127
  case "heading": {
30046
- const depth = parseInt(tag.slice(1), 10);
30128
+ const depth = Number.parseInt(tag.slice(1), 10);
30047
30129
  const children = text3 != null ? [{ type: "text", value: text3 }] : exportChildren(node2, ctx, scope);
30048
- return [{ type: "heading", depth, children }];
30130
+ return [{ children, depth, type: "heading" }];
30049
30131
  }
30050
30132
  case "paragraph": {
30051
30133
  const children = text3 != null ? [{ type: "text", value: text3 }] : exportChildren(node2, ctx, scope);
30052
- if (children.length === 0)
30134
+ if (children.length === 0) {
30053
30135
  return [];
30054
- return [{ type: "paragraph", children }];
30136
+ }
30137
+ return [{ children, type: "paragraph" }];
30055
30138
  }
30056
30139
  case "emphasis":
30057
30140
  case "strong":
30058
30141
  case "delete": {
30059
30142
  const children = text3 != null ? [{ type: "text", value: text3 }] : exportChildren(node2, ctx, scope);
30060
- return [{ type: mdastType, children }];
30143
+ return [{ children, type: mdastType }];
30061
30144
  }
30062
- case "inlineCode":
30145
+ case "inlineCode": {
30063
30146
  return [{ type: "inlineCode", value: text3 ?? "" }];
30147
+ }
30064
30148
  case "link": {
30065
30149
  const href = String(node2.attributes?.href ?? "");
30066
30150
  const title = node2.attributes?.title ?? null;
30067
30151
  const children = text3 != null ? [{ type: "text", value: text3 }] : exportChildren(node2, ctx, scope);
30068
- return [{ type: "link", url: href, title, children }];
30152
+ return [{ children, title, type: "link", url: href }];
30069
30153
  }
30070
30154
  case "image": {
30071
30155
  const src = String(node2.attributes?.src ?? "");
30072
30156
  const alt = String(node2.attributes?.alt ?? "");
30073
30157
  const title = node2.attributes?.title ?? null;
30074
- return [{ type: "image", url: src, alt, title }];
30158
+ return [{ alt, title, type: "image", url: src }];
30075
30159
  }
30076
30160
  case "blockquote": {
30077
30161
  const children = exportChildren(node2, ctx, scope);
30078
- const wrapped = children.map((c) => c.type === "text" ? { type: "paragraph", children: [c] } : c);
30079
- return [{ type: "blockquote", children: wrapped }];
30162
+ const wrapped = children.map((c) => c.type === "text" ? { children: [c], type: "paragraph" } : c);
30163
+ return [{ children: wrapped, type: "blockquote" }];
30080
30164
  }
30081
30165
  case "list": {
30082
30166
  const ordered = tag === "ol";
30083
30167
  const children = exportChildren(node2, ctx, scope);
30084
30168
  const items = children.filter((c) => c.type === "listItem");
30085
- if (items.length === 0)
30169
+ if (items.length === 0) {
30086
30170
  return [];
30087
- return [{ type: "list", ordered, spread: false, children: items }];
30171
+ }
30172
+ return [{ children: items, ordered, spread: false, type: "list" }];
30088
30173
  }
30089
30174
  case "listItem": {
30090
30175
  let children = exportChildren(node2, ctx, scope);
30091
30176
  if (children.length > 0 && children.every((c) => c.type === "text" || isInlineType(c.type))) {
30092
- children = [{ type: "paragraph", children }];
30177
+ children = [{ children, type: "paragraph" }];
30093
30178
  }
30094
- return [{ type: "listItem", spread: false, children }];
30179
+ return [{ children, spread: false, type: "listItem" }];
30095
30180
  }
30096
30181
  case "code": {
30097
30182
  const codeChild = Array.isArray(node2.children) ? node2.children.find((c) => c?.tagName === "code") : null;
30098
- const value = codeChild?.textContent ?? text3 ?? "";
30183
+ const value = textOf(codeChild) ?? text3 ?? "";
30099
30184
  return [
30100
30185
  {
30101
- type: "code",
30102
30186
  lang: codeLang(codeChild),
30187
+ type: "code",
30103
30188
  value
30104
30189
  }
30105
30190
  ];
30106
30191
  }
30107
- case "thematicBreak":
30192
+ case "thematicBreak": {
30108
30193
  return [{ type: "thematicBreak" }];
30109
- case "break":
30194
+ }
30195
+ case "break": {
30110
30196
  return [{ type: "break" }];
30197
+ }
30111
30198
  case "table": {
30112
30199
  const rows = exportChildren(node2, ctx, scope).filter((c) => c.type === "tableRow");
30113
- if (rows.length === 0)
30200
+ if (rows.length === 0) {
30114
30201
  return [];
30115
- return [{ type: "table", children: rows }];
30202
+ }
30203
+ return [{ children: rows, type: "table" }];
30116
30204
  }
30117
30205
  case "thead":
30118
- case "tbody":
30206
+ case "tbody": {
30119
30207
  return exportChildren(node2, ctx, scope);
30208
+ }
30120
30209
  case "tableRow": {
30121
30210
  const cells = exportChildren(node2, ctx, scope);
30122
30211
  return [
30123
30212
  {
30124
- type: "tableRow",
30125
- children: cells.filter((c) => c.type === "tableCell")
30213
+ children: cells.filter((c) => c.type === "tableCell"),
30214
+ type: "tableRow"
30126
30215
  }
30127
30216
  ];
30128
30217
  }
30129
30218
  case "tableCell": {
30130
30219
  const children = text3 != null ? [{ type: "text", value: text3 }] : exportChildren(node2, ctx, scope);
30131
- return [{ type: "tableCell", children }];
30220
+ return [{ children, type: "tableCell" }];
30221
+ }
30222
+ default: {
30223
+ break;
30132
30224
  }
30133
30225
  }
30134
30226
  return [];
@@ -30136,12 +30228,14 @@ function nodeToMdast(node2, ctx, scope) {
30136
30228
  function exportChildren(node2, ctx, scope) {
30137
30229
  if (node2.textContent != null) {
30138
30230
  const text3 = resolveText(node2.textContent, ctx, scope);
30139
- if (text3)
30231
+ if (text3) {
30140
30232
  return [{ type: "text", value: text3 }];
30233
+ }
30141
30234
  return [];
30142
30235
  }
30143
- if (!Array.isArray(node2.children))
30236
+ if (!Array.isArray(node2.children)) {
30144
30237
  return [];
30238
+ }
30145
30239
  return node2.children.flatMap((c) => nodeToMdast(c, ctx, scope));
30146
30240
  }
30147
30241
  function inlineComponent(node2, tag, ctx) {
@@ -30154,18 +30248,15 @@ function inlineComponent(node2, tag, ctx) {
30154
30248
  for (const [key, value] of Object.entries(props)) {
30155
30249
  if (key in stateDefs) {
30156
30250
  const existing = stateDefs[key];
30157
- if (existing && typeof existing === "object" && !Array.isArray(existing) && "default" in existing) {
30158
- stateDefs[key] = { ...existing, default: value };
30159
- } else {
30160
- stateDefs[key] = value;
30161
- }
30251
+ stateDefs[key] = existing && typeof existing === "object" && !Array.isArray(existing) && "default" in existing ? { ...existing, default: value } : value;
30162
30252
  } else {
30163
30253
  stateDefs[key] = value;
30164
30254
  }
30165
30255
  }
30166
30256
  const scope = ctx.buildScope?.(stateDefs) ?? null;
30167
- if (!Array.isArray(def.children))
30257
+ if (!Array.isArray(def.children)) {
30168
30258
  return [];
30259
+ }
30169
30260
  const resolved = deepResolve(def.children, scope ?? {}, ctx);
30170
30261
  const instanceChildren = node2.children;
30171
30262
  return resolved.flatMap((child) => {
@@ -30176,8 +30267,9 @@ function inlineComponent(node2, tag, ctx) {
30176
30267
  });
30177
30268
  }
30178
30269
  function deepResolve(nodes, scope, ctx) {
30179
- if (!Array.isArray(nodes))
30270
+ if (!Array.isArray(nodes)) {
30180
30271
  return [];
30272
+ }
30181
30273
  return nodes.map((node2) => resolveNode(node2, scope, ctx));
30182
30274
  }
30183
30275
  function resolveNode(node2, scope, ctx) {
@@ -30185,26 +30277,30 @@ function resolveNode(node2, scope, ctx) {
30185
30277
  const evaluated = ctx.evaluateTemplate?.(node2, scope);
30186
30278
  return evaluated !== undefined ? String(evaluated) : node2;
30187
30279
  }
30188
- if (!node2 || typeof node2 !== "object")
30280
+ if (!node2 || typeof node2 !== "object") {
30189
30281
  return node2;
30282
+ }
30190
30283
  const result = { ...node2 };
30191
30284
  if (typeof result.textContent === "string") {
30192
30285
  const evaluated = ctx.evaluateTemplate?.(result.textContent, scope);
30193
- if (evaluated !== undefined)
30286
+ if (evaluated !== undefined) {
30194
30287
  result.textContent = String(evaluated);
30288
+ }
30195
30289
  }
30196
30290
  if (typeof result.innerHTML === "string") {
30197
30291
  const evaluated = ctx.evaluateTemplate?.(result.innerHTML, scope);
30198
- if (evaluated !== undefined)
30292
+ if (evaluated !== undefined) {
30199
30293
  result.innerHTML = String(evaluated);
30294
+ }
30200
30295
  }
30201
30296
  if (result.attributes) {
30202
30297
  result.attributes = { ...result.attributes };
30203
30298
  for (const [k, v] of Object.entries(result.attributes)) {
30204
30299
  if (typeof v === "string") {
30205
30300
  const evaluated = ctx.evaluateTemplate?.(v, scope);
30206
- if (evaluated !== undefined)
30301
+ if (evaluated !== undefined) {
30207
30302
  result.attributes[k] = evaluated;
30303
+ }
30208
30304
  }
30209
30305
  }
30210
30306
  }
@@ -30214,25 +30310,31 @@ function resolveNode(node2, scope, ctx) {
30214
30310
  return result;
30215
30311
  }
30216
30312
  function expandArray(arrayDef, ctx, scope) {
30217
- const itemsRef = arrayDef.items?.$ref;
30218
- if (!itemsRef || !scope)
30313
+ const itemsValue = arrayDef.items;
30314
+ const itemsRef = isRef(itemsValue) ? itemsValue.$ref : undefined;
30315
+ if (!itemsRef || !scope) {
30219
30316
  return [];
30317
+ }
30220
30318
  const items = resolveRef(itemsRef, scope);
30221
- if (!Array.isArray(items))
30319
+ if (!Array.isArray(items)) {
30222
30320
  return [];
30321
+ }
30223
30322
  const mapTemplate = arrayDef.map;
30224
- if (!mapTemplate)
30323
+ if (!mapTemplate) {
30225
30324
  return [];
30325
+ }
30226
30326
  return items.flatMap((item) => {
30227
30327
  const resolved = resolveMapNode(mapTemplate, item);
30228
30328
  return nodeToMdast(resolved, ctx, scope);
30229
30329
  });
30230
30330
  }
30231
30331
  function resolveMapNode(node2, item) {
30232
- if (typeof node2 === "string")
30332
+ if (typeof node2 === "string") {
30233
30333
  return node2;
30234
- if (!node2 || typeof node2 !== "object")
30334
+ }
30335
+ if (!node2 || typeof node2 !== "object") {
30235
30336
  return node2;
30337
+ }
30236
30338
  const result = { ...node2 };
30237
30339
  for (const [key, value] of Object.entries(result)) {
30238
30340
  if (value && typeof value === "object" && value.$ref) {
@@ -30258,8 +30360,9 @@ function resolvePath(obj, path2) {
30258
30360
  const parts = path2.split(/[/.]/);
30259
30361
  let current = obj;
30260
30362
  for (const part of parts) {
30261
- if (current == null)
30363
+ if (current == null) {
30262
30364
  return;
30365
+ }
30263
30366
  current = current[part];
30264
30367
  }
30265
30368
  return current;
@@ -30271,13 +30374,15 @@ function resolveRef(ref, scope) {
30271
30374
  return resolvePath(scope, ref);
30272
30375
  }
30273
30376
  function resolveText(value, ctx, scope) {
30274
- if (value == null)
30377
+ if (value == null) {
30275
30378
  return null;
30379
+ }
30276
30380
  if (typeof value === "string") {
30277
30381
  if (scope) {
30278
30382
  const evaluated = ctx.evaluateTemplate?.(value, scope);
30279
- if (evaluated !== undefined)
30383
+ if (evaluated !== undefined) {
30280
30384
  return String(evaluated);
30385
+ }
30281
30386
  }
30282
30387
  return value;
30283
30388
  }
@@ -30288,11 +30393,13 @@ function htmlToMdast(html6) {
30288
30393
  const parts = splitHtmlBlocks(html6);
30289
30394
  for (const part of parts) {
30290
30395
  const trimmed = part.trim();
30291
- if (!trimmed)
30396
+ if (!trimmed) {
30292
30397
  continue;
30398
+ }
30293
30399
  const parsed = parseHtmlElement(trimmed);
30294
- if (parsed)
30400
+ if (parsed) {
30295
30401
  nodes.push(...parsed);
30402
+ }
30296
30403
  }
30297
30404
  return nodes;
30298
30405
  }
@@ -30305,32 +30412,35 @@ function splitHtmlBlocks(html6) {
30305
30412
  while ((m = pattern.exec(trimmed)) !== null) {
30306
30413
  if (m.index > lastIdx) {
30307
30414
  const between2 = trimmed.slice(lastIdx, m.index).trim();
30308
- if (between2)
30415
+ if (between2) {
30309
30416
  blocks.push(between2);
30417
+ }
30310
30418
  }
30311
30419
  blocks.push(m[0]);
30312
30420
  lastIdx = pattern.lastIndex;
30313
30421
  }
30314
30422
  if (lastIdx < trimmed.length) {
30315
30423
  const tail = trimmed.slice(lastIdx).trim();
30316
- if (tail)
30424
+ if (tail) {
30317
30425
  blocks.push(tail);
30426
+ }
30318
30427
  }
30319
30428
  return blocks;
30320
30429
  }
30321
30430
  function parseHtmlElement(html6) {
30322
30431
  const hMatch = html6.match(/^<(h[1-6])(?:\s[^>]*)?>(.+?)<\/\1>$/is);
30323
30432
  if (hMatch) {
30324
- const depth = parseInt(hMatch[1].slice(1), 10);
30433
+ const depth = Number.parseInt(hMatch[1].slice(1), 10);
30325
30434
  const children = parseInlineHtml(hMatch[2]);
30326
- return [{ type: "heading", depth, children }];
30435
+ return [{ children, depth, type: "heading" }];
30327
30436
  }
30328
30437
  const pMatch = html6.match(/^<p(?:\s[^>]*)?>(.+?)<\/p>$/is);
30329
30438
  if (pMatch) {
30330
30439
  const children = parseInlineHtml(pMatch[1]);
30331
- if (children.length === 0)
30440
+ if (children.length === 0) {
30332
30441
  return null;
30333
- return [{ type: "paragraph", children }];
30442
+ }
30443
+ return [{ children, type: "paragraph" }];
30334
30444
  }
30335
30445
  if (/^<hr\s*\/?>$/i.test(html6)) {
30336
30446
  return [{ type: "thematicBreak" }];
@@ -30339,27 +30449,29 @@ function parseHtmlElement(html6) {
30339
30449
  if (preMatch) {
30340
30450
  const lang = preMatch[1] ?? null;
30341
30451
  const value = decodeHtmlEntities(preMatch[2]);
30342
- return [{ type: "code", lang, value }];
30452
+ return [{ lang, type: "code", value }];
30343
30453
  }
30344
30454
  const bqMatch = html6.match(/^<blockquote(?:\s[^>]*)?>([^]*?)<\/blockquote>$/is);
30345
30455
  if (bqMatch) {
30346
30456
  const inner = htmlToMdast(bqMatch[1]);
30347
- const children = inner.map((c) => c.type === "text" ? { type: "paragraph", children: [c] } : c);
30348
- return [{ type: "blockquote", children }];
30457
+ const children = inner.map((c) => c.type === "text" ? { children: [c], type: "paragraph" } : c);
30458
+ return [{ children, type: "blockquote" }];
30349
30459
  }
30350
30460
  const ulMatch = html6.match(/^<ul(?:\s[^>]*)?>([^]*?)<\/ul>$/is);
30351
30461
  if (ulMatch) {
30352
30462
  const items = parseListItems(ulMatch[1]);
30353
- if (items.length === 0)
30463
+ if (items.length === 0) {
30354
30464
  return null;
30355
- return [{ type: "list", ordered: false, spread: false, children: items }];
30465
+ }
30466
+ return [{ children: items, ordered: false, spread: false, type: "list" }];
30356
30467
  }
30357
30468
  const olMatch = html6.match(/^<ol(?:\s[^>]*)?>([^]*?)<\/ol>$/is);
30358
30469
  if (olMatch) {
30359
30470
  const items = parseListItems(olMatch[1]);
30360
- if (items.length === 0)
30471
+ if (items.length === 0) {
30361
30472
  return null;
30362
- return [{ type: "list", ordered: true, spread: false, children: items }];
30473
+ }
30474
+ return [{ children: items, ordered: true, spread: false, type: "list" }];
30363
30475
  }
30364
30476
  const tableMatch = html6.match(/^<table(?:\s[^>]*)?>([^]*?)<\/table>$/is);
30365
30477
  if (tableMatch) {
@@ -30370,8 +30482,9 @@ function parseHtmlElement(html6) {
30370
30482
  return htmlToMdast(wrapperMatch[1]);
30371
30483
  }
30372
30484
  const text3 = stripHtmlTags(html6).trim();
30373
- if (text3)
30374
- return [{ type: "paragraph", children: parseInlineHtml(html6) }];
30485
+ if (text3) {
30486
+ return [{ children: parseInlineHtml(html6), type: "paragraph" }];
30487
+ }
30375
30488
  return null;
30376
30489
  }
30377
30490
  function parseInlineHtml(html6) {
@@ -30381,14 +30494,16 @@ function parseInlineHtml(html6) {
30381
30494
  const tagStart = html6.indexOf("<", pos);
30382
30495
  if (tagStart === -1) {
30383
30496
  const text3 = decodeHtmlEntities(html6.slice(pos));
30384
- if (text3.trim())
30497
+ if (text3.trim()) {
30385
30498
  nodes.push({ type: "text", value: text3 });
30499
+ }
30386
30500
  break;
30387
30501
  }
30388
30502
  if (tagStart > pos) {
30389
30503
  const text3 = decodeHtmlEntities(html6.slice(pos, tagStart));
30390
- if (text3.trim())
30504
+ if (text3.trim()) {
30391
30505
  nodes.push({ type: "text", value: text3 });
30506
+ }
30392
30507
  }
30393
30508
  const brMatch = html6.slice(tagStart).match(/^<br\s*\/?>/i);
30394
30509
  if (brMatch) {
@@ -30402,9 +30517,9 @@ function parseInlineHtml(html6) {
30402
30517
  const src = attrs.match(/src="([^"]*)"/)?.[1] ?? "";
30403
30518
  const alt = attrs.match(/alt="([^"]*)"/)?.[1] ?? "";
30404
30519
  nodes.push({
30520
+ alt: decodeHtmlEntities(alt),
30405
30521
  type: "image",
30406
- url: decodeHtmlEntities(src),
30407
- alt: decodeHtmlEntities(alt)
30522
+ url: decodeHtmlEntities(src)
30408
30523
  });
30409
30524
  pos = tagStart + imgMatch[0].length;
30410
30525
  continue;
@@ -30427,40 +30542,44 @@ function parseInlineHtml(html6) {
30427
30542
  const href = attrs.match(/href="([^"]*)"/)?.[1] ?? "";
30428
30543
  const title = attrs.match(/title="([^"]*)"/)?.[1] ?? null;
30429
30544
  const children = parseInlineHtml(inner);
30430
- if (children.length === 0)
30545
+ if (children.length === 0) {
30431
30546
  children.push({ type: "text", value: decodeHtmlEntities(inner) });
30547
+ }
30432
30548
  nodes.push({
30433
- type: "link",
30434
- url: decodeHtmlEntities(href),
30549
+ children,
30435
30550
  title,
30436
- children
30551
+ type: "link",
30552
+ url: decodeHtmlEntities(href)
30437
30553
  });
30438
30554
  break;
30439
30555
  }
30440
30556
  case "em":
30441
- case "i":
30442
- nodes.push({ type: "emphasis", children: parseInlineHtml(inner) });
30557
+ case "i": {
30558
+ nodes.push({ children: parseInlineHtml(inner), type: "emphasis" });
30443
30559
  break;
30560
+ }
30444
30561
  case "strong":
30445
- case "b":
30446
- nodes.push({ type: "strong", children: parseInlineHtml(inner) });
30562
+ case "b": {
30563
+ nodes.push({ children: parseInlineHtml(inner), type: "strong" });
30447
30564
  break;
30565
+ }
30448
30566
  case "del":
30449
- case "s":
30450
- nodes.push({ type: "delete", children: parseInlineHtml(inner) });
30567
+ case "s": {
30568
+ nodes.push({ children: parseInlineHtml(inner), type: "delete" });
30451
30569
  break;
30452
- case "code":
30570
+ }
30571
+ case "code": {
30453
30572
  nodes.push({ type: "inlineCode", value: decodeHtmlEntities(inner) });
30454
30573
  break;
30574
+ }
30575
+ default: {
30576
+ break;
30577
+ }
30455
30578
  }
30456
30579
  continue;
30457
30580
  }
30458
30581
  const skipMatch = html6.slice(tagStart).match(/^<[^>]*>/);
30459
- if (skipMatch) {
30460
- pos = tagStart + skipMatch[0].length;
30461
- } else {
30462
- pos = tagStart + 1;
30463
- }
30582
+ pos = skipMatch ? tagStart + skipMatch[0].length : tagStart + 1;
30464
30583
  }
30465
30584
  return nodes;
30466
30585
  }
@@ -30473,16 +30592,18 @@ function findMatchingClose(html6, start, tag) {
30473
30592
  while (depth > 0) {
30474
30593
  const openMatch = openRe.exec(html6);
30475
30594
  const closeMatch = closeRe.exec(html6);
30476
- if (!closeMatch)
30595
+ if (!closeMatch) {
30477
30596
  return -1;
30597
+ }
30478
30598
  if (openMatch && openMatch.index < closeMatch.index) {
30479
- depth++;
30599
+ depth += 1;
30480
30600
  openRe.lastIndex = openMatch.index + openMatch[0].length;
30481
30601
  closeRe.lastIndex = closeMatch.index;
30482
30602
  } else {
30483
- depth--;
30484
- if (depth === 0)
30603
+ depth -= 1;
30604
+ if (depth === 0) {
30485
30605
  return closeMatch.index;
30606
+ }
30486
30607
  }
30487
30608
  }
30488
30609
  return -1;
@@ -30493,8 +30614,8 @@ function parseListItems(html6) {
30493
30614
  let m;
30494
30615
  while ((m = liPattern.exec(html6)) !== null) {
30495
30616
  const inner = m[1].trim();
30496
- const innerNodes = /<(?:p|ul|ol|blockquote|pre)[\s>]/i.test(inner) ? htmlToMdast(inner) : [{ type: "paragraph", children: parseInlineHtml(inner) }];
30497
- items.push({ type: "listItem", spread: false, children: innerNodes });
30617
+ const innerNodes = /<(?:p|ul|ol|blockquote|pre)[\s>]/i.test(inner) ? htmlToMdast(inner) : [{ children: parseInlineHtml(inner), type: "paragraph" }];
30618
+ items.push({ children: innerNodes, spread: false, type: "listItem" });
30498
30619
  }
30499
30620
  return items;
30500
30621
  }
@@ -30507,20 +30628,22 @@ function parseHtmlTable(html6) {
30507
30628
  const cells = [];
30508
30629
  let c;
30509
30630
  while ((c = cellPattern.exec(m[1])) !== null) {
30510
- cells.push({ type: "tableCell", children: parseInlineHtml(c[1]) });
30631
+ cells.push({ children: parseInlineHtml(c[1]), type: "tableCell" });
30632
+ }
30633
+ if (cells.length > 0) {
30634
+ rows.push({ children: cells, type: "tableRow" });
30511
30635
  }
30512
- if (cells.length > 0)
30513
- rows.push({ type: "tableRow", children: cells });
30514
30636
  }
30515
- if (rows.length === 0)
30637
+ if (rows.length === 0) {
30516
30638
  return [];
30517
- return [{ type: "table", children: rows }];
30639
+ }
30640
+ return [{ children: rows, type: "table" }];
30518
30641
  }
30519
30642
  function stripHtmlTags(html6) {
30520
- return html6.replace(/<[^>]+>/g, "");
30643
+ return html6.replaceAll(/<[^>]+>/g, "");
30521
30644
  }
30522
30645
  function decodeHtmlEntities(str) {
30523
- return str.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&#36;/g, "$").replace(/&nbsp;/g, " ");
30646
+ return str.replaceAll("&amp;", "&").replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&quot;", '"').replaceAll("&#39;", "'").replaceAll("&#36;", "$").replaceAll("&nbsp;", " ");
30524
30647
  }
30525
30648
  function serializeJxMarkdown(doc, opts = {}) {
30526
30649
  const mode = opts.mode ?? "roundtrip";
@@ -30534,8 +30657,9 @@ function serializeRoundtrip(doc, opts) {
30534
30657
  if (opts.frontmatter !== false) {
30535
30658
  const frontmatter = {};
30536
30659
  for (const [key, value] of Object.entries(doc)) {
30537
- if (key === "children")
30660
+ if (key === "children") {
30538
30661
  continue;
30662
+ }
30539
30663
  frontmatter[key] = value;
30540
30664
  }
30541
30665
  if (Object.keys(frontmatter).length > 0) {
@@ -30550,10 +30674,10 @@ function serializeRoundtrip(doc, opts) {
30550
30674
  const md = unified().use(remarkGfm).use(remarkDirective).use(remarkStringify, { bullet: "-", emphasis: "*", strong: "*" }).stringify(mdast);
30551
30675
  lines.push(md);
30552
30676
  }
30553
- return lines.join(`
30554
- `).replace(/\n{3,}/g, `
30677
+ return `${lines.join(`
30678
+ `).replaceAll(/\n{3,}/g, `
30555
30679
 
30556
- `).trim() + `
30680
+ `).trim()}
30557
30681
  `;
30558
30682
  }
30559
30683
  function serializeExport(doc, opts) {
@@ -30561,9 +30685,9 @@ function serializeExport(doc, opts) {
30561
30685
  return "";
30562
30686
  }
30563
30687
  const ctx = {
30688
+ buildScope: opts.buildScope,
30564
30689
  componentDefs: opts.componentDefs ?? new Map,
30565
- evaluateTemplate: opts.evaluateTemplate,
30566
- buildScope: opts.buildScope
30690
+ evaluateTemplate: opts.evaluateTemplate
30567
30691
  };
30568
30692
  const scope = doc.state ? opts.buildScope?.(doc.state) ?? null : null;
30569
30693
  const mdastChildren = doc.children.flatMap((child) => nodeToMdast(child, ctx, scope));
@@ -30571,7 +30695,7 @@ function serializeExport(doc, opts) {
30571
30695
  let inlineBuf = [];
30572
30696
  const flushInline = () => {
30573
30697
  if (inlineBuf.length > 0) {
30574
- cleaned.push({ type: "paragraph", children: inlineBuf });
30698
+ cleaned.push({ children: inlineBuf, type: "paragraph" });
30575
30699
  inlineBuf = [];
30576
30700
  }
30577
30701
  };
@@ -30585,23 +30709,24 @@ function serializeExport(doc, opts) {
30585
30709
  }
30586
30710
  flushInline();
30587
30711
  const mdast = {
30588
- type: "root",
30589
- children: cleaned
30712
+ children: cleaned,
30713
+ type: "root"
30590
30714
  };
30591
30715
  const md = unified().use(remarkGfm).use(remarkStringify, {
30592
30716
  bullet: "-",
30593
30717
  emphasis: "*",
30594
- strong: "*",
30595
- setext: false
30718
+ setext: false,
30719
+ strong: "*"
30596
30720
  }).stringify(mdast);
30597
- return md.replace(/\n{3,}/g, `
30721
+ return `${md.replaceAll(/\n{3,}/g, `
30598
30722
 
30599
- `).trim() + `
30723
+ `).trim()}
30600
30724
  `;
30601
30725
  }
30602
30726
  var MD_ELEMENTS, MD_BLOCK, MD_INLINE, MD_ALL, MD_VOID, MD_TEXT_ONLY, TAG_MDAST_MAP, WRAPPER_TAGS, INLINE_CONTENT_TAGS, MDAST_TAG_MAP, CSS_PSEUDO_NAMES, JX_DOLLAR_KEYS, JX_ANNOTATION_KEYS;
30603
30727
  var init_serialize = __esm(() => {
30604
30728
  init_unified();
30729
+ init_guards();
30605
30730
  init_remark_stringify();
30606
30731
  init_remark_directive();
30607
30732
  init_remark_gfm();
@@ -30630,33 +30755,33 @@ var init_serialize = __esm(() => {
30630
30755
  "td"
30631
30756
  ],
30632
30757
  inline: ["em", "strong", "del", "code", "a", "img", "br"],
30633
- void: ["hr", "br", "img"],
30634
- textOnly: ["code"],
30635
30758
  nesting: {
30636
- _root: { block: true, inline: false, directive: true },
30637
- h1: { block: false, inline: true, directive: false },
30638
- h2: { block: false, inline: true, directive: false },
30639
- h3: { block: false, inline: true, directive: false },
30640
- h4: { block: false, inline: true, directive: false },
30641
- h5: { block: false, inline: true, directive: false },
30642
- h6: { block: false, inline: true, directive: false },
30643
- p: { block: false, inline: true, directive: true },
30644
- blockquote: { block: true, inline: false, directive: true },
30645
- ul: { only: ["li"] },
30759
+ _root: { block: true, directive: true, inline: false },
30760
+ a: { block: false, directive: false, inline: true },
30761
+ blockquote: { block: true, directive: true, inline: false },
30762
+ del: { block: false, directive: false, inline: true },
30763
+ em: { block: false, directive: false, inline: true },
30764
+ h1: { block: false, directive: false, inline: true },
30765
+ h2: { block: false, directive: false, inline: true },
30766
+ h3: { block: false, directive: false, inline: true },
30767
+ h4: { block: false, directive: false, inline: true },
30768
+ h5: { block: false, directive: false, inline: true },
30769
+ h6: { block: false, directive: false, inline: true },
30770
+ li: { block: true, directive: true, inline: true },
30646
30771
  ol: { only: ["li"] },
30647
- li: { block: true, inline: true, directive: true },
30772
+ p: { block: false, directive: true, inline: true },
30648
30773
  pre: { only: ["code"] },
30774
+ strong: { block: false, directive: false, inline: true },
30649
30775
  table: { only: ["thead", "tbody"] },
30650
- thead: { only: ["tr"] },
30651
30776
  tbody: { only: ["tr"] },
30777
+ td: { block: false, directive: false, inline: true },
30778
+ th: { block: false, directive: false, inline: true },
30779
+ thead: { only: ["tr"] },
30652
30780
  tr: { only: ["th", "td"] },
30653
- th: { block: false, inline: true, directive: false },
30654
- td: { block: false, inline: true, directive: false },
30655
- em: { block: false, inline: true, directive: false },
30656
- strong: { block: false, inline: true, directive: false },
30657
- del: { block: false, inline: true, directive: false },
30658
- a: { block: false, inline: true, directive: false }
30659
- }
30781
+ ul: { only: ["li"] }
30782
+ },
30783
+ textOnly: ["code"],
30784
+ void: ["hr", "br", "img"]
30660
30785
  };
30661
30786
  MD_BLOCK = new Set(MD_ELEMENTS.block);
30662
30787
  MD_INLINE = new Set(MD_ELEMENTS.inline);
@@ -30664,33 +30789,33 @@ var init_serialize = __esm(() => {
30664
30789
  MD_VOID = new Set(MD_ELEMENTS.void);
30665
30790
  MD_TEXT_ONLY = new Set(MD_ELEMENTS.textOnly);
30666
30791
  TAG_MDAST_MAP = {
30792
+ a: "link",
30793
+ blockquote: "blockquote",
30794
+ br: "break",
30795
+ code: "inlineCode",
30796
+ del: "delete",
30797
+ em: "emphasis",
30667
30798
  h1: "heading",
30668
30799
  h2: "heading",
30669
30800
  h3: "heading",
30670
30801
  h4: "heading",
30671
30802
  h5: "heading",
30672
30803
  h6: "heading",
30673
- p: "paragraph",
30674
- span: "text",
30675
- em: "emphasis",
30676
- strong: "strong",
30677
- del: "delete",
30678
- code: "inlineCode",
30679
- a: "link",
30804
+ hr: "thematicBreak",
30680
30805
  img: "image",
30681
- blockquote: "blockquote",
30682
- ul: "list",
30683
- ol: "list",
30684
30806
  li: "listItem",
30807
+ ol: "list",
30808
+ p: "paragraph",
30685
30809
  pre: "code",
30686
- hr: "thematicBreak",
30687
- br: "break",
30810
+ span: "text",
30811
+ strong: "strong",
30688
30812
  table: "table",
30689
- thead: "thead",
30690
30813
  tbody: "tbody",
30691
- tr: "tableRow",
30814
+ td: "tableCell",
30692
30815
  th: "tableCell",
30693
- td: "tableCell"
30816
+ thead: "thead",
30817
+ tr: "tableRow",
30818
+ ul: "list"
30694
30819
  };
30695
30820
  WRAPPER_TAGS = new Set([
30696
30821
  "div",
@@ -30722,24 +30847,24 @@ var init_serialize = __esm(() => {
30722
30847
  "th"
30723
30848
  ]);
30724
30849
  MDAST_TAG_MAP = {
30725
- heading: (n) => `h${n.depth}`,
30726
- paragraph: () => "p",
30727
- text: () => "span",
30728
- emphasis: () => "em",
30729
- strong: () => "strong",
30850
+ blockquote: () => "blockquote",
30851
+ break: () => "br",
30852
+ code: () => "pre",
30730
30853
  delete: () => "del",
30854
+ emphasis: () => "em",
30855
+ heading: (n) => `h${n.depth}`,
30856
+ image: () => "img",
30731
30857
  inlineCode: () => "code",
30732
30858
  link: () => "a",
30733
- image: () => "img",
30734
- blockquote: () => "blockquote",
30735
30859
  list: (n) => n.ordered ? "ol" : "ul",
30736
30860
  listItem: () => "li",
30737
- code: () => "pre",
30738
- thematicBreak: () => "hr",
30861
+ paragraph: () => "p",
30862
+ strong: () => "strong",
30739
30863
  table: () => "table",
30740
- tableRow: () => "tr",
30741
30864
  tableCell: (n) => n.isHeader ? "th" : "td",
30742
- break: () => "br"
30865
+ tableRow: () => "tr",
30866
+ text: () => "span",
30867
+ thematicBreak: () => "hr"
30743
30868
  };
30744
30869
  CSS_PSEUDO_NAMES = new Set([
30745
30870
  "hover",
@@ -40994,10 +41119,12 @@ var require_dist2 = __commonJS((exports, module) => {
40994
41119
 
40995
41120
  // src/transpile.ts
40996
41121
  function jxKey(key) {
40997
- if (JX_DOLLAR_KEYS2.has(key))
41122
+ if (JX_DOLLAR_KEYS2.has(key)) {
40998
41123
  return `$${key}`;
40999
- if (key.startsWith("--") && JX_ANNOTATION_KEYS2.has(key.slice(2)))
41124
+ }
41125
+ if (key.startsWith("--") && JX_ANNOTATION_KEYS2.has(key.slice(2))) {
41000
41126
  return `$${key.slice(2)}`;
41127
+ }
41001
41128
  return key;
41002
41129
  }
41003
41130
  function mdKey(key) {
@@ -41026,7 +41153,7 @@ function expandDotPaths(attrs) {
41026
41153
  }
41027
41154
  target = target[seg];
41028
41155
  }
41029
- target[jxKey(segments[segments.length - 1])] = value2;
41156
+ target[jxKey(segments.at(-1))] = value2;
41030
41157
  }
41031
41158
  return result;
41032
41159
  }
@@ -41076,8 +41203,9 @@ function collapseStylePaths(styleObj) {
41076
41203
  }
41077
41204
  function isJxMarkdown(source) {
41078
41205
  const fmMatch = source.match(/^---\r?\n([\s\S]*?)\r?\n---/);
41079
- if (!fmMatch)
41206
+ if (!fmMatch) {
41080
41207
  return false;
41208
+ }
41081
41209
  return /^tagName:\s*.+-.+/m.test(fmMatch[1]);
41082
41210
  }
41083
41211
  function routeAttributes(attrs) {
@@ -41094,13 +41222,15 @@ function routeAttributes(attrs) {
41094
41222
  props[key] = value2;
41095
41223
  }
41096
41224
  }
41097
- return { props, attributes: attributes4 };
41225
+ return { attributes: attributes4, props };
41098
41226
  }
41099
41227
  function mdastNodeToJx(node2) {
41100
- if (!node2 || typeof node2 !== "object")
41228
+ if (!node2 || typeof node2 !== "object") {
41101
41229
  return null;
41102
- if (node2.type === "yaml" || node2.type === "toml")
41230
+ }
41231
+ if (node2.type === "yaml" || node2.type === "toml") {
41103
41232
  return null;
41233
+ }
41104
41234
  if (node2.type === "containerDirective" || node2.type === "leafDirective" || node2.type === "textDirective") {
41105
41235
  return directiveToJx(node2);
41106
41236
  }
@@ -41108,13 +41238,15 @@ function mdastNodeToJx(node2) {
41108
41238
  return node2.value ?? null;
41109
41239
  }
41110
41240
  if (node2.type === "html") {
41111
- if (node2.value)
41241
+ if (node2.value) {
41112
41242
  return htmlToJx(node2.value);
41243
+ }
41113
41244
  return null;
41114
41245
  }
41115
41246
  const tagFn = JX_TAG_MAP[node2.type];
41116
- if (!tagFn)
41247
+ if (!tagFn) {
41117
41248
  return null;
41249
+ }
41118
41250
  const tag = tagFn(node2);
41119
41251
  const el = { tagName: tag };
41120
41252
  switch (node2.type) {
@@ -41129,34 +41261,48 @@ function mdastNodeToJx(node2) {
41129
41261
  case "tableCell": {
41130
41262
  const children = convertChildren(node2.children ?? []);
41131
41263
  if (children.length === 1 && typeof children[0] === "string") {
41132
- el.textContent = children[0];
41264
+ [el.textContent] = children;
41133
41265
  } else if (children.length > 0) {
41134
41266
  el.children = children;
41135
41267
  }
41136
41268
  break;
41137
41269
  }
41138
- case "inlineCode":
41270
+ case "inlineCode": {
41139
41271
  el.textContent = node2.value ?? null;
41140
41272
  break;
41141
- case "link":
41142
- el.attributes = { href: node2.url };
41143
- if (node2.title)
41144
- el.attributes.title = node2.title;
41273
+ }
41274
+ case "link": {
41275
+ {
41276
+ const linkAttrs = {
41277
+ href: node2.url ?? ""
41278
+ };
41279
+ if (node2.title) {
41280
+ linkAttrs.title = node2.title;
41281
+ }
41282
+ el.attributes = linkAttrs;
41283
+ }
41145
41284
  {
41146
41285
  const children = convertChildren(node2.children ?? []);
41147
41286
  if (children.length === 1 && typeof children[0] === "string") {
41148
- el.textContent = children[0];
41287
+ [el.textContent] = children;
41149
41288
  } else if (children.length > 0) {
41150
41289
  el.children = children;
41151
41290
  }
41152
41291
  }
41153
41292
  break;
41154
- case "image":
41155
- el.attributes = { src: node2.url, alt: node2.alt ?? "" };
41156
- if (node2.title)
41157
- el.attributes.title = node2.title;
41293
+ }
41294
+ case "image": {
41295
+ const imageAttrs = {
41296
+ alt: node2.alt ?? "",
41297
+ src: node2.url ?? ""
41298
+ };
41299
+ if (node2.title) {
41300
+ imageAttrs.title = node2.title;
41301
+ }
41302
+ el.attributes = imageAttrs;
41158
41303
  break;
41159
- case "list":
41304
+ }
41305
+ case "list": {
41160
41306
  if (node2.children && node2.children.length > 0) {
41161
41307
  el.children = convertChildren(node2.children);
41162
41308
  }
@@ -41164,7 +41310,8 @@ function mdastNodeToJx(node2) {
41164
41310
  el.attributes = { start: String(node2.start) };
41165
41311
  }
41166
41312
  break;
41167
- case "code":
41313
+ }
41314
+ case "code": {
41168
41315
  el.children = [
41169
41316
  {
41170
41317
  tagName: "code",
@@ -41173,16 +41320,21 @@ function mdastNodeToJx(node2) {
41173
41320
  }
41174
41321
  ];
41175
41322
  break;
41323
+ }
41176
41324
  case "thematicBreak":
41177
- case "break":
41325
+ case "break": {
41178
41326
  break;
41327
+ }
41179
41328
  case "table": {
41180
41329
  const rows = convertChildren(node2.children ?? []);
41181
- const thead = rows.length > 0 ? { tagName: "thead", children: [rows[0]] } : null;
41182
- const tbody = rows.length > 1 ? { tagName: "tbody", children: rows.slice(1) } : null;
41330
+ const thead = rows.length > 0 ? { children: [rows[0]], tagName: "thead" } : null;
41331
+ const tbody = rows.length > 1 ? { children: rows.slice(1), tagName: "tbody" } : null;
41183
41332
  el.children = [thead, tbody].filter(Boolean);
41184
41333
  break;
41185
41334
  }
41335
+ default: {
41336
+ break;
41337
+ }
41186
41338
  }
41187
41339
  return el;
41188
41340
  }
@@ -41198,8 +41350,9 @@ function directiveToJx(node2) {
41198
41350
  } else if (key === "props") {
41199
41351
  el.$props = value2;
41200
41352
  } else {
41201
- if (!el.attributes)
41353
+ if (!el.attributes) {
41202
41354
  el.attributes = {};
41355
+ }
41203
41356
  el.attributes[key] = value2;
41204
41357
  }
41205
41358
  }
@@ -41208,8 +41361,9 @@ function directiveToJx(node2) {
41208
41361
  if (key === "style" || key === "children" || key === "textContent" || key === "innerHTML" || key === "id" || key === "className" || key === "hidden" || key === "tabIndex" || key === "lang" || key === "dir" || key.startsWith("$") || key.startsWith("on")) {
41209
41362
  el[key] = value2;
41210
41363
  } else {
41211
- if (!el.attributes)
41364
+ if (!el.attributes) {
41212
41365
  el.attributes = {};
41366
+ }
41213
41367
  el.attributes[key] = value2;
41214
41368
  }
41215
41369
  }
@@ -41222,7 +41376,7 @@ function directiveToJx(node2) {
41222
41376
  if (node2.children && node2.children.length > 0) {
41223
41377
  const children = convertChildren(node2.children ?? []);
41224
41378
  if (children.length === 1 && typeof children[0] === "string") {
41225
- el.textContent = children[0];
41379
+ [el.textContent] = children;
41226
41380
  } else if (children.length > 0) {
41227
41381
  el.children = children;
41228
41382
  }
@@ -41239,25 +41393,29 @@ function directiveToJx(node2) {
41239
41393
  if (isPhrasingParent && child.type === "paragraph") {
41240
41394
  for (const inline of child.children ?? []) {
41241
41395
  const converted = mdastNodeToJx(inline);
41242
- if (converted == null)
41396
+ if (converted == null) {
41243
41397
  continue;
41244
- if (Array.isArray(converted))
41398
+ }
41399
+ if (Array.isArray(converted)) {
41245
41400
  jxChildren.push(...converted);
41246
- else
41401
+ } else {
41247
41402
  jxChildren.push(converted);
41403
+ }
41248
41404
  }
41249
41405
  } else {
41250
41406
  const converted = mdastNodeToJx(child);
41251
- if (converted == null)
41407
+ if (converted == null) {
41252
41408
  continue;
41253
- if (Array.isArray(converted))
41409
+ }
41410
+ if (Array.isArray(converted)) {
41254
41411
  jxChildren.push(...converted);
41255
- else
41412
+ } else {
41256
41413
  jxChildren.push(converted);
41414
+ }
41257
41415
  }
41258
41416
  }
41259
41417
  if (el.children && typeof el.children === "object" && !Array.isArray(el.children)) {} else if (jxChildren.length === 1 && typeof jxChildren[0] === "string") {
41260
- el.textContent = jxChildren[0];
41418
+ [el.textContent] = jxChildren;
41261
41419
  } else if (jxChildren.length > 0) {
41262
41420
  el.children = jxChildren;
41263
41421
  }
@@ -41265,9 +41423,10 @@ function directiveToJx(node2) {
41265
41423
  return el;
41266
41424
  }
41267
41425
  function convertChildren(children) {
41268
- if (!children)
41426
+ if (!children) {
41269
41427
  return [];
41270
- return children.flatMap(mdastNodeToJx).filter((c) => c != null);
41428
+ }
41429
+ return children.flatMap((n) => mdastNodeToJx(n)).filter((c) => c != null);
41271
41430
  }
41272
41431
  function transpileJxMarkdown(source) {
41273
41432
  const processor = unified().use(remarkParse).use(remarkFrontmatter, ["yaml"]).use(import_remark_parse_frontmatter.default).use(remarkGfm).use(remarkDirective);
@@ -41283,12 +41442,14 @@ function transpileJxMarkdown(source) {
41283
41442
  const children = [];
41284
41443
  for (const node2 of bodyNodes) {
41285
41444
  const converted = mdastNodeToJx(node2);
41286
- if (converted == null)
41445
+ if (converted == null) {
41287
41446
  continue;
41288
- if (Array.isArray(converted))
41447
+ }
41448
+ if (Array.isArray(converted)) {
41289
41449
  children.push(...converted);
41290
- else
41450
+ } else {
41291
41451
  children.push(converted);
41452
+ }
41292
41453
  }
41293
41454
  if (children.length > 0) {
41294
41455
  doc.children = children;
@@ -41364,23 +41525,23 @@ var init_transpile = __esm(() => {
41364
41525
  "dt"
41365
41526
  ]);
41366
41527
  JX_TAG_MAP = {
41367
- heading: (n) => `h${n.depth}`,
41368
- paragraph: () => "p",
41369
- emphasis: () => "em",
41370
- strong: () => "strong",
41528
+ blockquote: () => "blockquote",
41529
+ break: () => "br",
41530
+ code: () => "pre",
41371
41531
  delete: () => "del",
41532
+ emphasis: () => "em",
41533
+ heading: (n) => `h${n.depth}`,
41534
+ image: () => "img",
41372
41535
  inlineCode: () => "code",
41373
41536
  link: () => "a",
41374
- image: () => "img",
41375
- blockquote: () => "blockquote",
41376
41537
  list: (n) => n.ordered ? "ol" : "ul",
41377
41538
  listItem: () => "li",
41378
- code: () => "pre",
41379
- thematicBreak: () => "hr",
41380
- break: () => "br",
41539
+ paragraph: () => "p",
41540
+ strong: () => "strong",
41381
41541
  table: () => "table",
41542
+ tableCell: (n) => n.isHeader ? "th" : "td",
41382
41543
  tableRow: () => "tr",
41383
- tableCell: (n) => n.isHeader ? "th" : "td"
41544
+ thematicBreak: () => "hr"
41384
41545
  };
41385
41546
  });
41386
41547
 
@@ -44608,26 +44769,33 @@ function visit3(tree, typeOrVisitor, maybeVisitor) {
44608
44769
  const type = typeof typeOrVisitor === "string" ? typeOrVisitor : null;
44609
44770
  const visitor = type ? maybeVisitor : typeOrVisitor;
44610
44771
  function walk(node2) {
44611
- if (!node2 || typeof node2 !== "object")
44772
+ if (!node2 || typeof node2 !== "object") {
44612
44773
  return;
44613
- if (!type || node2.type === type)
44774
+ }
44775
+ if (!type || node2.type === type) {
44614
44776
  visitor(node2);
44777
+ }
44615
44778
  if (Array.isArray(node2.children)) {
44616
- for (const child of node2.children)
44779
+ for (const child of node2.children) {
44617
44780
  walk(child);
44781
+ }
44618
44782
  }
44619
44783
  }
44620
44784
  walk(tree);
44621
44785
  }
44622
44786
  function mdastToString(node2) {
44623
- if (!node2)
44787
+ if (!node2) {
44624
44788
  return "";
44625
- if (typeof node2 === "string")
44789
+ }
44790
+ if (typeof node2 === "string") {
44626
44791
  return node2;
44627
- if (node2.value)
44792
+ }
44793
+ if (node2.value) {
44628
44794
  return node2.value;
44629
- if (Array.isArray(node2.children))
44795
+ }
44796
+ if (Array.isArray(node2.children)) {
44630
44797
  return node2.children.map(mdastToString).join("");
44798
+ }
44631
44799
  return "";
44632
44800
  }
44633
44801
  function readingTime(text5) {
@@ -44638,19 +44806,21 @@ function extractToc(tree) {
44638
44806
  const entries = [];
44639
44807
  visit3(tree, "heading", (node2) => {
44640
44808
  const text5 = mdastToString(node2);
44641
- const id = text5.toLowerCase().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
44642
- entries.push({ depth: node2.depth, text: text5, id });
44809
+ const id = text5.toLowerCase().replaceAll(/[^\w\s-]/g, "").replaceAll(/\s+/g, "-").replaceAll(/-+/g, "-").replaceAll(/^-|-$/g, "");
44810
+ entries.push({ depth: node2.depth, id, text: text5 });
44643
44811
  });
44644
44812
  return entries;
44645
44813
  }
44646
44814
  function extractExcerpt(tree) {
44647
44815
  let firstParagraph = null;
44648
44816
  visit3(tree, "paragraph", (node2) => {
44649
- if (!firstParagraph)
44817
+ if (!firstParagraph) {
44650
44818
  firstParagraph = node2;
44819
+ }
44651
44820
  });
44652
- if (!firstParagraph)
44821
+ if (!firstParagraph) {
44653
44822
  return "";
44823
+ }
44654
44824
  return mdastToString(firstParagraph);
44655
44825
  }
44656
44826
  function processMarkdown(source, filePath, config = {}) {
@@ -44669,20 +44839,24 @@ function processMarkdown(source, filePath, config = {}) {
44669
44839
  const excerpt = extractExcerpt(tree);
44670
44840
  const slug = basename(filePath, extname(filePath));
44671
44841
  const bodyNodes = tree.children.filter((n7) => n7.type !== "yaml" && n7.type !== "toml");
44672
- const $children = bodyNodes.map(mdastNodeToJx).filter(Boolean);
44842
+ const $children = bodyNodes.map((n7) => mdastNodeToJx(n7)).filter(Boolean);
44673
44843
  return {
44674
- slug,
44675
- path: filePath,
44676
- frontmatter: frontmatter2,
44677
44844
  $children,
44678
44845
  $excerpt: excerpt,
44679
- $toc: toc,
44680
44846
  $readingTime: readingTime(plainText),
44681
- $wordCount: plainText.split(/\s+/).filter(Boolean).length
44847
+ $toc: toc,
44848
+ $wordCount: plainText.split(/\s+/).filter(Boolean).length,
44849
+ frontmatter: frontmatter2,
44850
+ path: filePath,
44851
+ slug
44682
44852
  };
44683
44853
  }
44684
44854
  function getNestedValue(obj, path2) {
44685
- return path2.split(".").reduce((o, k2) => o?.[k2], obj);
44855
+ let current = obj;
44856
+ for (const k2 of path2.split(".")) {
44857
+ current = current?.[k2];
44858
+ }
44859
+ return current;
44686
44860
  }
44687
44861
 
44688
44862
  class MarkdownCollection {
@@ -44704,20 +44878,22 @@ class MarkdownCollection {
44704
44878
  const pattern = resolved.split("\\").join("/");
44705
44879
  const files = ts(pattern, { absolute: true });
44706
44880
  const results = files.map((filePath) => {
44707
- const source = readFileSync(filePath, "utf-8");
44881
+ const source = readFileSync(filePath, "utf8");
44708
44882
  return processMarkdown(source, filePath, processorConfig);
44709
44883
  });
44710
44884
  let filtered = results;
44711
44885
  if (typeof filter === "function") {
44712
- filtered = results.filter(filter);
44886
+ filtered = results.filter((r) => filter(r));
44713
44887
  }
44714
44888
  filtered.sort((a, b) => {
44715
44889
  const aVal = getNestedValue(a, sortBy) ?? "";
44716
44890
  const bVal = getNestedValue(b, sortBy) ?? "";
44717
- if (aVal < bVal)
44891
+ if (aVal < bVal) {
44718
44892
  return sortOrder === "asc" ? -1 : 1;
44719
- if (aVal > bVal)
44893
+ }
44894
+ if (aVal > bVal) {
44720
44895
  return sortOrder === "asc" ? 1 : -1;
44896
+ }
44721
44897
  return 0;
44722
44898
  });
44723
44899
  if (limit && limit > 0) {
@@ -44768,7 +44944,7 @@ class Markdown {
44768
44944
  static async load(path2, options = {}) {
44769
44945
  const { processMarkdown: processMarkdown2 } = await Promise.resolve().then(() => (init_md(), exports_md));
44770
44946
  const { readFileSync: readFileSync2 } = await import("node:fs");
44771
- const source = readFileSync2(path2, "utf-8");
44947
+ const source = readFileSync2(path2, "utf8");
44772
44948
  const result = processMarkdown2(source, path2, {
44773
44949
  ...options.directives !== undefined && { directives: options.directives },
44774
44950
  ...options.directiveOptions !== undefined && {
@@ -44776,21 +44952,25 @@ class Markdown {
44776
44952
  }
44777
44953
  });
44778
44954
  const _meta = {};
44779
- if (result.$excerpt != null)
44955
+ if (result.$excerpt != null) {
44780
44956
  _meta.excerpt = result.$excerpt;
44781
- if (result.$toc != null)
44957
+ }
44958
+ if (result.$toc != null) {
44782
44959
  _meta.toc = result.$toc;
44783
- if (result.$readingTime != null)
44960
+ }
44961
+ if (result.$readingTime != null) {
44784
44962
  _meta.readingTime = result.$readingTime;
44785
- if (result.$wordCount != null)
44963
+ }
44964
+ if (result.$wordCount != null) {
44786
44965
  _meta.wordCount = result.$wordCount;
44966
+ }
44787
44967
  return [
44788
44968
  {
44789
- id: result.slug,
44790
- data: result.frontmatter,
44791
- body: source,
44792
44969
  $children: result.$children,
44793
- _meta
44970
+ _meta,
44971
+ body: source,
44972
+ data: result.frontmatter,
44973
+ id: result.slug
44794
44974
  }
44795
44975
  ];
44796
44976
  }
@@ -44800,7 +44980,7 @@ class Markdown {
44800
44980
  const { resolve } = await import("node:path");
44801
44981
  const { src, basePath, ...processorConfig } = this.config;
44802
44982
  const filePath = basePath ? resolve(basePath, src) : resolve(src);
44803
- const source = readFileSync2(filePath, "utf-8");
44983
+ const source = readFileSync2(filePath, "utf8");
44804
44984
  return processMarkdown2(source, filePath, processorConfig);
44805
44985
  }
44806
44986
  }