@open-feishu-card/adapter 0.3.8 → 0.3.9

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/index.cjs CHANGED
@@ -1034,12 +1034,45 @@ function readCustomBackgroundStyle(node) {
1034
1034
  function readCustomBorderColor(node) {
1035
1035
  return readThemeColorPair(node.custom_border_color ?? node.customBorderColor);
1036
1036
  }
1037
+ function seedRegistryFromConfigStyle(dsl, colorEntries, bgKeyToAlias, textKeyToAlias) {
1038
+ let bgSeq = 0;
1039
+ let textSeq = 0;
1040
+ const config = dsl.config;
1041
+ if (!config || typeof config !== "object") return { bgSeq, textSeq };
1042
+ const style = config.style;
1043
+ if (!style || typeof style !== "object") return { bgSeq, textSeq };
1044
+ const colors = style.color;
1045
+ if (!colors || typeof colors !== "object") return { bgSeq, textSeq };
1046
+ for (const [alias, entry] of Object.entries(colors)) {
1047
+ if (!entry || typeof entry !== "object") continue;
1048
+ const pair = entry;
1049
+ if (typeof pair.light_mode !== "string" || typeof pair.dark_mode !== "string") continue;
1050
+ const themePair = { light_mode: pair.light_mode, dark_mode: pair.dark_mode };
1051
+ colorEntries[alias] = themePair;
1052
+ const key = colorEntryKey(themePair);
1053
+ if (alias.startsWith("cus-text")) {
1054
+ textKeyToAlias.set(key, alias);
1055
+ const n = /^cus-text-(\d+)$/.exec(alias);
1056
+ if (n) textSeq = Math.max(textSeq, Number(n[1]) + 1);
1057
+ } else {
1058
+ bgKeyToAlias.set(key, alias);
1059
+ const n = /^cus-bg-(\d+)$/.exec(alias);
1060
+ if (n) bgSeq = Math.max(bgSeq, Number(n[1]) + 1);
1061
+ }
1062
+ }
1063
+ return { bgSeq, textSeq };
1064
+ }
1037
1065
  function normalizeStoredCardColors(dsl, preRegistered) {
1038
1066
  const colorEntries = { ...preRegistered?.entries ?? {} };
1039
1067
  const bgKeyToAlias = new Map(preRegistered?.bgKeyToAlias ?? []);
1040
1068
  const textKeyToAlias = new Map(preRegistered?.textKeyToAlias ?? []);
1041
1069
  let bgSeq = preRegistered?.bgSeq ?? 0;
1042
1070
  let textSeq = preRegistered?.textSeq ?? 0;
1071
+ if (!preRegistered) {
1072
+ const seeded = seedRegistryFromConfigStyle(dsl, colorEntries, bgKeyToAlias, textKeyToAlias);
1073
+ bgSeq = Math.max(bgSeq, seeded.bgSeq);
1074
+ textSeq = Math.max(textSeq, seeded.textSeq);
1075
+ }
1043
1076
  const ensureAlias = (prefix, entry) => {
1044
1077
  const map = prefix === "cus-bg" ? bgKeyToAlias : textKeyToAlias;
1045
1078
  const existing2 = map.get(colorEntryKey(entry));
@@ -1064,6 +1097,11 @@ function normalizeStoredCardColors(dsl, preRegistered) {
1064
1097
  }
1065
1098
  }
1066
1099
  if (obj.tag === "interactive_container") {
1100
+ const customBg = readCustomBackgroundStyle(obj);
1101
+ if (customBg) {
1102
+ obj.background_style = ensureAlias("cus-bg", customBg);
1103
+ delete obj.custom_background_style;
1104
+ }
1067
1105
  const border = readCustomBorderColor(obj);
1068
1106
  if (border) {
1069
1107
  obj.border_color = ensureAlias("cus-bg", border);
package/dist/index.js CHANGED
@@ -1032,12 +1032,45 @@ function readCustomBackgroundStyle(node) {
1032
1032
  function readCustomBorderColor(node) {
1033
1033
  return readThemeColorPair(node.custom_border_color ?? node.customBorderColor);
1034
1034
  }
1035
+ function seedRegistryFromConfigStyle(dsl, colorEntries, bgKeyToAlias, textKeyToAlias) {
1036
+ let bgSeq = 0;
1037
+ let textSeq = 0;
1038
+ const config = dsl.config;
1039
+ if (!config || typeof config !== "object") return { bgSeq, textSeq };
1040
+ const style = config.style;
1041
+ if (!style || typeof style !== "object") return { bgSeq, textSeq };
1042
+ const colors = style.color;
1043
+ if (!colors || typeof colors !== "object") return { bgSeq, textSeq };
1044
+ for (const [alias, entry] of Object.entries(colors)) {
1045
+ if (!entry || typeof entry !== "object") continue;
1046
+ const pair = entry;
1047
+ if (typeof pair.light_mode !== "string" || typeof pair.dark_mode !== "string") continue;
1048
+ const themePair = { light_mode: pair.light_mode, dark_mode: pair.dark_mode };
1049
+ colorEntries[alias] = themePair;
1050
+ const key = colorEntryKey(themePair);
1051
+ if (alias.startsWith("cus-text")) {
1052
+ textKeyToAlias.set(key, alias);
1053
+ const n = /^cus-text-(\d+)$/.exec(alias);
1054
+ if (n) textSeq = Math.max(textSeq, Number(n[1]) + 1);
1055
+ } else {
1056
+ bgKeyToAlias.set(key, alias);
1057
+ const n = /^cus-bg-(\d+)$/.exec(alias);
1058
+ if (n) bgSeq = Math.max(bgSeq, Number(n[1]) + 1);
1059
+ }
1060
+ }
1061
+ return { bgSeq, textSeq };
1062
+ }
1035
1063
  function normalizeStoredCardColors(dsl, preRegistered) {
1036
1064
  const colorEntries = { ...preRegistered?.entries ?? {} };
1037
1065
  const bgKeyToAlias = new Map(preRegistered?.bgKeyToAlias ?? []);
1038
1066
  const textKeyToAlias = new Map(preRegistered?.textKeyToAlias ?? []);
1039
1067
  let bgSeq = preRegistered?.bgSeq ?? 0;
1040
1068
  let textSeq = preRegistered?.textSeq ?? 0;
1069
+ if (!preRegistered) {
1070
+ const seeded = seedRegistryFromConfigStyle(dsl, colorEntries, bgKeyToAlias, textKeyToAlias);
1071
+ bgSeq = Math.max(bgSeq, seeded.bgSeq);
1072
+ textSeq = Math.max(textSeq, seeded.textSeq);
1073
+ }
1041
1074
  const ensureAlias = (prefix, entry) => {
1042
1075
  const map = prefix === "cus-bg" ? bgKeyToAlias : textKeyToAlias;
1043
1076
  const existing2 = map.get(colorEntryKey(entry));
@@ -1062,6 +1095,11 @@ function normalizeStoredCardColors(dsl, preRegistered) {
1062
1095
  }
1063
1096
  }
1064
1097
  if (obj.tag === "interactive_container") {
1098
+ const customBg = readCustomBackgroundStyle(obj);
1099
+ if (customBg) {
1100
+ obj.background_style = ensureAlias("cus-bg", customBg);
1101
+ delete obj.custom_background_style;
1102
+ }
1065
1103
  const border = readCustomBorderColor(obj);
1066
1104
  if (border) {
1067
1105
  obj.border_color = ensureAlias("cus-bg", border);
@@ -1 +1 @@
1
- {"version":3,"file":"normalize-stored-colors.d.ts","sourceRoot":"","sources":["../src/normalize-stored-colors.ts"],"names":[],"mappings":"AAEA;;;;GAIG;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,CAAC;IAC1C,sDAAsD;IACtD,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,wBAAgB,mBAAmB,IAAI,aAAa,CAEnD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAE7D;AAED,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,aAAa,EACvB,KAAK,EAAE,gBAAgB,EACvB,MAAM,EAAE,QAAQ,GAAG,UAAU,GAC5B,MAAM,CAWR;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAgB9D;AA0BD;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,aAAa,CAAC,EAAE,aAAa,GAC5B,IAAI,CAoHN"}
1
+ {"version":3,"file":"normalize-stored-colors.d.ts","sourceRoot":"","sources":["../src/normalize-stored-colors.ts"],"names":[],"mappings":"AAEA;;;;GAIG;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,CAAC;IAC1C,sDAAsD;IACtD,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,wBAAgB,mBAAmB,IAAI,aAAa,CAEnD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAE7D;AAED,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,aAAa,EACvB,KAAK,EAAE,gBAAgB,EACvB,MAAM,EAAE,QAAQ,GAAG,UAAU,GAC5B,MAAM,CAWR;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAgB9D;AA8DD;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,aAAa,CAAC,EAAE,aAAa,GAC5B,IAAI,CA+HN"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-feishu-card/adapter",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "description": "公开 DSL 与飞书内部 RAW JSON 的双向适配器;raw→DSL 对齐 feishu-raw-card-to-dsl",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",