@open-feishu-card/adapter 0.3.4 → 0.3.5

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.
@@ -4,7 +4,7 @@
4
4
  * textStyle.customColor / textStyle.custom_color → inline text color
5
5
  *
6
6
  * Public DSL stores custom colors in config.style.color (cus-accent / cus-bg-N …)
7
- * and references them via markdown.font_color / background_style — not inline #hex.
7
+ * and references them via <font color> in markdown content / background_style — not inline #hex.
8
8
  */
9
9
  import type { CustomColorEntry } from './normalize-stored-colors.js';
10
10
  export type ThemeColorPair = {
package/dist/index.cjs CHANGED
@@ -941,7 +941,7 @@ function normalizeStoredCardColors(dsl, preRegistered) {
941
941
  }
942
942
  }
943
943
  if (obj.tag === "markdown" && typeof obj.content === "string") {
944
- normalizeMarkdownInlineHexColors(obj, ensureAlias);
944
+ normalizeMarkdownInlineHexColors(obj, ensureAlias, !!preRegistered);
945
945
  }
946
946
  for (const value of Object.values(obj)) walk(value);
947
947
  };
@@ -976,22 +976,24 @@ function normalizeStoredCardColors(dsl, preRegistered) {
976
976
  const existing = style.color && typeof style.color === "object" ? style.color : {};
977
977
  style.color = { ...colorEntries, ...existing };
978
978
  if (!colorEntries["cus-accent"]) return;
979
- const applyDefaultFontColors = (node) => {
980
- if (Array.isArray(node)) {
981
- for (const child of node) applyDefaultFontColors(child);
982
- return;
983
- }
984
- if (!node || typeof node !== "object") return;
985
- const obj = node;
986
- if (obj.tag === "markdown" && obj.font_color === void 0) {
987
- const size = obj.text_size;
988
- const content = typeof obj.content === "string" ? obj.content : "";
989
- if (size === "small") obj.font_color = "cus-muted";
990
- else if (size === "heading" || content.includes("**")) obj.font_color = "cus-accent";
991
- }
992
- for (const value of Object.values(obj)) applyDefaultFontColors(value);
993
- };
994
- applyDefaultFontColors(dsl.body);
979
+ if (!preRegistered) {
980
+ const applyDefaultFontColors = (node) => {
981
+ if (Array.isArray(node)) {
982
+ for (const child of node) applyDefaultFontColors(child);
983
+ return;
984
+ }
985
+ if (!node || typeof node !== "object") return;
986
+ const obj = node;
987
+ if (obj.tag === "markdown" && obj.font_color === void 0) {
988
+ const size = obj.text_size;
989
+ const content = typeof obj.content === "string" ? obj.content : "";
990
+ if (size === "small") obj.font_color = "cus-muted";
991
+ else if (size === "heading" || content.includes("**")) obj.font_color = "cus-accent";
992
+ }
993
+ for (const value of Object.values(obj)) applyDefaultFontColors(value);
994
+ };
995
+ applyDefaultFontColors(dsl.body);
996
+ }
995
997
  }
996
998
  function unifyMatchingAlias(entries, fromPrefix, to) {
997
999
  const renames = /* @__PURE__ */ new Map();
@@ -1035,7 +1037,7 @@ function remapColorReferences(node, aliasRenames) {
1035
1037
  };
1036
1038
  walk(node);
1037
1039
  }
1038
- function normalizeMarkdownInlineHexColors(obj, ensureAlias) {
1040
+ function normalizeMarkdownInlineHexColors(obj, ensureAlias, keepFontTags = false) {
1039
1041
  const content = obj.content;
1040
1042
  const hexColor = (raw) => {
1041
1043
  const v = raw.trim();
@@ -1047,7 +1049,7 @@ function normalizeMarkdownInlineHexColors(obj, ensureAlias) {
1047
1049
  return void 0;
1048
1050
  };
1049
1051
  const single = content.match(/^<font color=['"]([^'"]+)['"]\s*>([\s\S]*)<\/font>$/);
1050
- if (single) {
1052
+ if (single && !keepFontTags) {
1051
1053
  const entry = hexColor(single[1]);
1052
1054
  if (entry) {
1053
1055
  const alias = ensureAlias("cus-text", entry);
@@ -1710,9 +1712,8 @@ function resolveAtUserId(prop, ctx) {
1710
1712
  function rebuildMarkdown(property, ctx) {
1711
1713
  const out = { tag: "markdown" };
1712
1714
  const elements = Array.isArray(property.elements) ? property.elements : [];
1713
- const { content, uniformFontColor } = renderChildren(elements, ctx);
1715
+ const { content } = renderChildren(elements, ctx);
1714
1716
  if (content) out.content = content;
1715
- if (uniformFontColor) out.font_color = uniformFontColor;
1716
1717
  for (const [rawKey, rawValue] of Object.entries(property)) {
1717
1718
  if (rawKey === "elements" || rawKey === "markdownElements" || rawKey === "originTag") continue;
1718
1719
  if (rawKey === "udIcon") continue;
@@ -1730,7 +1731,7 @@ function rebuildMarkdown(property, ctx) {
1730
1731
  }
1731
1732
  return out;
1732
1733
  }
1733
- function wrapEmphasis(text, bold, color, colorKind, inlineCustomFont = false) {
1734
+ function wrapEmphasis(text, bold, color) {
1734
1735
  if (!bold && !color) return text;
1735
1736
  const lead = text.match(/^\s*/)[0];
1736
1737
  const trail = text.match(/\s*$/)[0];
@@ -1738,10 +1739,7 @@ function wrapEmphasis(text, bold, color, colorKind, inlineCustomFont = false) {
1738
1739
  if (core.length === 0) return text;
1739
1740
  let wrapped = core;
1740
1741
  if (bold) wrapped = `**${wrapped}**`;
1741
- if (color) {
1742
- if (colorKind === "enum") wrapped = `<font color='${color}'>${wrapped}</font>`;
1743
- else if (colorKind === "custom" && inlineCustomFont) wrapped = `<font color='${color}'>${wrapped}</font>`;
1744
- }
1742
+ if (color) wrapped = `<font color='${color}'>${wrapped}</font>`;
1745
1743
  return lead + wrapped + trail;
1746
1744
  }
1747
1745
  function resolveInlineStyle(ts, ctx) {
@@ -1769,20 +1767,14 @@ function resolveInlineStyle(ts, ctx) {
1769
1767
  function renderChildren(children, ctx) {
1770
1768
  let out = "";
1771
1769
  let buffer = [];
1772
- let uniformFontColor;
1773
1770
  function flushBuffer() {
1774
1771
  if (buffer.length === 0) return;
1775
- const customColors = buffer.filter((s) => s.colorKind === "custom" && s.color).map((s) => s.color);
1776
- const hasEnumColor = buffer.some((s) => s.colorKind === "enum" && s.color);
1777
- const uniformCustom = customColors.length > 0 && !hasEnumColor && customColors.every((c) => c === customColors[0]) ? customColors[0] : void 0;
1778
- if (uniformCustom) uniformFontColor = uniformCustom;
1779
1772
  let group = [];
1780
1773
  function emitGroup() {
1781
1774
  if (group.length === 0) return;
1782
1775
  const inner = group.map((s) => s.content).join("");
1783
- const { bold, color, colorKind } = group[0];
1784
- const inlineCustomFont = colorKind === "custom" && !!color && color !== uniformCustom;
1785
- out += wrapEmphasis(inner, bold, color, colorKind, inlineCustomFont);
1776
+ const { bold, color } = group[0];
1777
+ out += wrapEmphasis(inner, bold, color);
1786
1778
  group = [];
1787
1779
  }
1788
1780
  for (const seg of buffer) {
@@ -1812,7 +1804,7 @@ function renderChildren(children, ctx) {
1812
1804
  out += childToMarkdown(child, ctx);
1813
1805
  }
1814
1806
  flushBuffer();
1815
- return { content: out, uniformFontColor };
1807
+ return { content: out };
1816
1808
  }
1817
1809
  function childToInlineSegment(child, ctx) {
1818
1810
  const tag = child.tag;
@@ -1878,8 +1870,8 @@ function childToMarkdown(child, ctx) {
1878
1870
  case "plain_text": {
1879
1871
  const content = typeof prop.content === "string" ? prop.content : "";
1880
1872
  const ts = isRecord2(prop.textStyle) ? prop.textStyle : void 0;
1881
- const { bold, color, colorKind } = resolveInlineStyle(ts, ctx);
1882
- return wrapEmphasis(content, bold, color, colorKind, colorKind === "custom");
1873
+ const { bold, color } = resolveInlineStyle(ts, ctx);
1874
+ return wrapEmphasis(content, bold, color);
1883
1875
  }
1884
1876
  case "br":
1885
1877
  return "\n";
package/dist/index.js CHANGED
@@ -939,7 +939,7 @@ function normalizeStoredCardColors(dsl, preRegistered) {
939
939
  }
940
940
  }
941
941
  if (obj.tag === "markdown" && typeof obj.content === "string") {
942
- normalizeMarkdownInlineHexColors(obj, ensureAlias);
942
+ normalizeMarkdownInlineHexColors(obj, ensureAlias, !!preRegistered);
943
943
  }
944
944
  for (const value of Object.values(obj)) walk(value);
945
945
  };
@@ -974,22 +974,24 @@ function normalizeStoredCardColors(dsl, preRegistered) {
974
974
  const existing = style.color && typeof style.color === "object" ? style.color : {};
975
975
  style.color = { ...colorEntries, ...existing };
976
976
  if (!colorEntries["cus-accent"]) return;
977
- const applyDefaultFontColors = (node) => {
978
- if (Array.isArray(node)) {
979
- for (const child of node) applyDefaultFontColors(child);
980
- return;
981
- }
982
- if (!node || typeof node !== "object") return;
983
- const obj = node;
984
- if (obj.tag === "markdown" && obj.font_color === void 0) {
985
- const size = obj.text_size;
986
- const content = typeof obj.content === "string" ? obj.content : "";
987
- if (size === "small") obj.font_color = "cus-muted";
988
- else if (size === "heading" || content.includes("**")) obj.font_color = "cus-accent";
989
- }
990
- for (const value of Object.values(obj)) applyDefaultFontColors(value);
991
- };
992
- applyDefaultFontColors(dsl.body);
977
+ if (!preRegistered) {
978
+ const applyDefaultFontColors = (node) => {
979
+ if (Array.isArray(node)) {
980
+ for (const child of node) applyDefaultFontColors(child);
981
+ return;
982
+ }
983
+ if (!node || typeof node !== "object") return;
984
+ const obj = node;
985
+ if (obj.tag === "markdown" && obj.font_color === void 0) {
986
+ const size = obj.text_size;
987
+ const content = typeof obj.content === "string" ? obj.content : "";
988
+ if (size === "small") obj.font_color = "cus-muted";
989
+ else if (size === "heading" || content.includes("**")) obj.font_color = "cus-accent";
990
+ }
991
+ for (const value of Object.values(obj)) applyDefaultFontColors(value);
992
+ };
993
+ applyDefaultFontColors(dsl.body);
994
+ }
993
995
  }
994
996
  function unifyMatchingAlias(entries, fromPrefix, to) {
995
997
  const renames = /* @__PURE__ */ new Map();
@@ -1033,7 +1035,7 @@ function remapColorReferences(node, aliasRenames) {
1033
1035
  };
1034
1036
  walk(node);
1035
1037
  }
1036
- function normalizeMarkdownInlineHexColors(obj, ensureAlias) {
1038
+ function normalizeMarkdownInlineHexColors(obj, ensureAlias, keepFontTags = false) {
1037
1039
  const content = obj.content;
1038
1040
  const hexColor = (raw) => {
1039
1041
  const v = raw.trim();
@@ -1045,7 +1047,7 @@ function normalizeMarkdownInlineHexColors(obj, ensureAlias) {
1045
1047
  return void 0;
1046
1048
  };
1047
1049
  const single = content.match(/^<font color=['"]([^'"]+)['"]\s*>([\s\S]*)<\/font>$/);
1048
- if (single) {
1050
+ if (single && !keepFontTags) {
1049
1051
  const entry = hexColor(single[1]);
1050
1052
  if (entry) {
1051
1053
  const alias = ensureAlias("cus-text", entry);
@@ -1708,9 +1710,8 @@ function resolveAtUserId(prop, ctx) {
1708
1710
  function rebuildMarkdown(property, ctx) {
1709
1711
  const out = { tag: "markdown" };
1710
1712
  const elements = Array.isArray(property.elements) ? property.elements : [];
1711
- const { content, uniformFontColor } = renderChildren(elements, ctx);
1713
+ const { content } = renderChildren(elements, ctx);
1712
1714
  if (content) out.content = content;
1713
- if (uniformFontColor) out.font_color = uniformFontColor;
1714
1715
  for (const [rawKey, rawValue] of Object.entries(property)) {
1715
1716
  if (rawKey === "elements" || rawKey === "markdownElements" || rawKey === "originTag") continue;
1716
1717
  if (rawKey === "udIcon") continue;
@@ -1728,7 +1729,7 @@ function rebuildMarkdown(property, ctx) {
1728
1729
  }
1729
1730
  return out;
1730
1731
  }
1731
- function wrapEmphasis(text, bold, color, colorKind, inlineCustomFont = false) {
1732
+ function wrapEmphasis(text, bold, color) {
1732
1733
  if (!bold && !color) return text;
1733
1734
  const lead = text.match(/^\s*/)[0];
1734
1735
  const trail = text.match(/\s*$/)[0];
@@ -1736,10 +1737,7 @@ function wrapEmphasis(text, bold, color, colorKind, inlineCustomFont = false) {
1736
1737
  if (core.length === 0) return text;
1737
1738
  let wrapped = core;
1738
1739
  if (bold) wrapped = `**${wrapped}**`;
1739
- if (color) {
1740
- if (colorKind === "enum") wrapped = `<font color='${color}'>${wrapped}</font>`;
1741
- else if (colorKind === "custom" && inlineCustomFont) wrapped = `<font color='${color}'>${wrapped}</font>`;
1742
- }
1740
+ if (color) wrapped = `<font color='${color}'>${wrapped}</font>`;
1743
1741
  return lead + wrapped + trail;
1744
1742
  }
1745
1743
  function resolveInlineStyle(ts, ctx) {
@@ -1767,20 +1765,14 @@ function resolveInlineStyle(ts, ctx) {
1767
1765
  function renderChildren(children, ctx) {
1768
1766
  let out = "";
1769
1767
  let buffer = [];
1770
- let uniformFontColor;
1771
1768
  function flushBuffer() {
1772
1769
  if (buffer.length === 0) return;
1773
- const customColors = buffer.filter((s) => s.colorKind === "custom" && s.color).map((s) => s.color);
1774
- const hasEnumColor = buffer.some((s) => s.colorKind === "enum" && s.color);
1775
- const uniformCustom = customColors.length > 0 && !hasEnumColor && customColors.every((c) => c === customColors[0]) ? customColors[0] : void 0;
1776
- if (uniformCustom) uniformFontColor = uniformCustom;
1777
1770
  let group = [];
1778
1771
  function emitGroup() {
1779
1772
  if (group.length === 0) return;
1780
1773
  const inner = group.map((s) => s.content).join("");
1781
- const { bold, color, colorKind } = group[0];
1782
- const inlineCustomFont = colorKind === "custom" && !!color && color !== uniformCustom;
1783
- out += wrapEmphasis(inner, bold, color, colorKind, inlineCustomFont);
1774
+ const { bold, color } = group[0];
1775
+ out += wrapEmphasis(inner, bold, color);
1784
1776
  group = [];
1785
1777
  }
1786
1778
  for (const seg of buffer) {
@@ -1810,7 +1802,7 @@ function renderChildren(children, ctx) {
1810
1802
  out += childToMarkdown(child, ctx);
1811
1803
  }
1812
1804
  flushBuffer();
1813
- return { content: out, uniformFontColor };
1805
+ return { content: out };
1814
1806
  }
1815
1807
  function childToInlineSegment(child, ctx) {
1816
1808
  const tag = child.tag;
@@ -1876,8 +1868,8 @@ function childToMarkdown(child, ctx) {
1876
1868
  case "plain_text": {
1877
1869
  const content = typeof prop.content === "string" ? prop.content : "";
1878
1870
  const ts = isRecord2(prop.textStyle) ? prop.textStyle : void 0;
1879
- const { bold, color, colorKind } = resolveInlineStyle(ts, ctx);
1880
- return wrapEmphasis(content, bold, color, colorKind, colorKind === "custom");
1871
+ const { bold, color } = resolveInlineStyle(ts, ctx);
1872
+ return wrapEmphasis(content, bold, color);
1881
1873
  }
1882
1874
  case "br":
1883
1875
  return "\n";
@@ -1 +1 @@
1
- {"version":3,"file":"normalize-stored-colors.d.ts","sourceRoot":"","sources":["../src/normalize-stored-colors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,gBAAgB,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzE,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,C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,GAAG,UAAU,GAC5B,MAAM,CAUR;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAgB9D;AAiBD;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,aAAa,CAAC,EAAE,aAAa,GAC5B,IAAI,CAmGN"}
@@ -1 +1 @@
1
- {"version":3,"file":"raw-to-dsl.d.ts","sourceRoot":"","sources":["../src/raw-to-dsl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAwBH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAIzD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAcvD;AAwkDD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CA8C9C;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAGnF"}
1
+ {"version":3,"file":"raw-to-dsl.d.ts","sourceRoot":"","sources":["../src/raw-to-dsl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAwBH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAIzD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAcvD;AAojDD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CA8C9C;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAGnF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-feishu-card/adapter",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "公开 DSL 与飞书内部 RAW JSON 的双向适配器;raw→DSL 对齐 feishu-raw-card-to-dsl",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",