@open-feishu-card/adapter 0.3.20 → 0.4.1

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
@@ -938,6 +938,64 @@ function buildProperty(el, tag, colors) {
938
938
  }
939
939
  }
940
940
  }
941
+ if (tag === "img_combination") {
942
+ if (k === "combination_mode") {
943
+ property.combinationMode = v;
944
+ continue;
945
+ }
946
+ if (k === "img_list" && Array.isArray(v)) {
947
+ property.imgList = v.map((item) => {
948
+ if (!isRecord2(item)) return item;
949
+ const key = item.img_key ?? item.imgKey ?? item.img_id ?? item.imgId;
950
+ return compactRecord({
951
+ imageID: typeof key === "string" ? key : void 0,
952
+ transparent: typeof item.transparent === "boolean" ? item.transparent : void 0
953
+ });
954
+ });
955
+ continue;
956
+ }
957
+ if (k === "combination_transparent") {
958
+ property.transparent = v;
959
+ continue;
960
+ }
961
+ }
962
+ if (tag === "select_img") {
963
+ if (k === "options" && Array.isArray(v)) {
964
+ property.options = v.map((item) => {
965
+ if (!isRecord2(item)) return item;
966
+ const key = item.img_key ?? item.imgKey ?? item.img_id ?? item.imgId;
967
+ return compactRecord({
968
+ imageID: typeof key === "string" ? key : void 0,
969
+ value: item.value,
970
+ disabled: item.disabled,
971
+ disabled_tips: item.disabled_tips !== void 0 ? wrapTextLeaf(item.disabled_tips) : void 0,
972
+ hover_tips: item.hover_tips !== void 0 ? wrapTextLeaf(item.hover_tips) : void 0,
973
+ transparent: item.transparent
974
+ });
975
+ });
976
+ continue;
977
+ }
978
+ if (k === "multi_select") {
979
+ property.multiSelect = v;
980
+ continue;
981
+ }
982
+ if (k === "selected_values") {
983
+ property.selectedValues = v;
984
+ continue;
985
+ }
986
+ if (k === "can_preview") {
987
+ property.canPreview = v;
988
+ continue;
989
+ }
990
+ if (k === "aspect_ratio") {
991
+ property.aspectRatio = v;
992
+ continue;
993
+ }
994
+ if (k === "disabled_tips") {
995
+ property.disabledTips = wrapTextLeaf(v);
996
+ continue;
997
+ }
998
+ }
941
999
  if (TEXT_LEAF_KEYS.has(k)) {
942
1000
  property[renameKey(k)] = wrapTextLeaf(v);
943
1001
  continue;
@@ -1067,6 +1125,12 @@ function pxValue(s) {
1067
1125
  const n = Number(s);
1068
1126
  return Number.isFinite(n) ? n : null;
1069
1127
  }
1128
+ function compactRecord(obj) {
1129
+ for (const key of Object.keys(obj)) {
1130
+ if (obj[key] === void 0) delete obj[key];
1131
+ }
1132
+ return obj;
1133
+ }
1070
1134
  function isRecord2(v) {
1071
1135
  return typeof v === "object" && v !== null && !Array.isArray(v);
1072
1136
  }
@@ -1715,6 +1779,47 @@ function unwrapInner(node, ctx) {
1715
1779
  }
1716
1780
  return out;
1717
1781
  }
1782
+ if (tag === "img_combination") {
1783
+ const converted2 = convertProperty(property, tag, ctx);
1784
+ const out = { tag };
1785
+ if (typeof converted2.combination_mode === "string") {
1786
+ out.combination_mode = converted2.combination_mode;
1787
+ }
1788
+ const rawList = Array.isArray(property.imgList) ? property.imgList : Array.isArray(property.img_list) ? property.img_list : void 0;
1789
+ if (rawList) {
1790
+ out.img_list = rawList.map((item) => isRecord3(item) ? projectImgCombinationItem(item, ctx) : void 0).filter((item) => item !== void 0);
1791
+ }
1792
+ const transparent = property.combinationTransparent ?? property.combination_transparent ?? property.transparent;
1793
+ if (typeof transparent === "boolean") out.combination_transparent = transparent;
1794
+ if (converted2.corner_radius !== void 0) {
1795
+ out.corner_radius = converted2.corner_radius;
1796
+ } else if (typeof property.cornerRadiusValue === "number") {
1797
+ out.corner_radius = `${property.cornerRadiusValue}px`;
1798
+ } else if (typeof property.corner_radius === "string") {
1799
+ out.corner_radius = property.corner_radius;
1800
+ }
1801
+ if (typeof converted2.img_list_length === "number") {
1802
+ out.img_list_length = converted2.img_list_length;
1803
+ }
1804
+ if (converted2.margin !== void 0) out.margin = converted2.margin;
1805
+ return out;
1806
+ }
1807
+ if (tag === "select_img") {
1808
+ const converted2 = convertProperty(property, tag, ctx);
1809
+ const out = { tag, ...converted2 };
1810
+ const rawOptions = Array.isArray(property.options) ? property.options : void 0;
1811
+ if (rawOptions) {
1812
+ out.options = rawOptions.map(
1813
+ (option) => isRecord3(option) ? projectSelectImgOption(option, ctx) : {}
1814
+ );
1815
+ }
1816
+ if (Array.isArray(property.actions)) {
1817
+ const behaviors = property.actions.map((a) => actionEntryToBehavior(a, tag, ctx)).filter((b) => b !== void 0);
1818
+ delete out.actions;
1819
+ if (behaviors.length > 0) out.behaviors = behaviors;
1820
+ }
1821
+ return out;
1822
+ }
1718
1823
  if (tag === "div" && isRecord3(property.text) && property.fields === void 0) {
1719
1824
  const text = property.text;
1720
1825
  const textTag = typeof text.tag === "string" ? text.tag : "";
@@ -1977,8 +2082,6 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
1977
2082
  if (ownerTag === "collapsible_panel" && key === "header" && isRecord3(rawValue)) {
1978
2083
  const cleaned = {};
1979
2084
  for (const [k, v] of Object.entries(rawValue)) {
1980
- const sk = snake(k);
1981
- if (sk === "position" || sk === "width" || sk === "vertical_align") continue;
1982
2085
  const sub = convertField(k, v, "collapsible_panel_header", ctx, siblings);
1983
2086
  if (sub === DROP) continue;
1984
2087
  const [subKey, subVal] = sub;
@@ -2461,6 +2564,38 @@ function resolveAttachmentImgKey(rawValue, ctx) {
2461
2564
  if (id.startsWith("img_")) return id;
2462
2565
  return void 0;
2463
2566
  }
2567
+ function projectImageKey(item, ctx) {
2568
+ const direct = typeof item.img_key === "string" ? item.img_key : typeof item.imgKey === "string" ? item.imgKey : void 0;
2569
+ if (direct) return { img_key: direct };
2570
+ const id = item.imageID ?? item.image_id ?? item.imgId ?? item.img_id;
2571
+ const resolved = resolveAttachmentImgKey(id, ctx);
2572
+ if (resolved) return { img_key: resolved };
2573
+ if (typeof id === "string" || typeof id === "number") return { img_id: String(id) };
2574
+ return {};
2575
+ }
2576
+ function projectImgCombinationItem(item, ctx) {
2577
+ const out = projectImageKey(item, ctx);
2578
+ if (typeof item.transparent === "boolean") out.transparent = item.transparent;
2579
+ return Object.keys(out).length > 0 ? out : void 0;
2580
+ }
2581
+ function projectSelectImgOption(item, ctx) {
2582
+ const out = projectImageKey(item, ctx);
2583
+ if (typeof item.value === "string") out.value = item.value;
2584
+ if (typeof item.disabled === "boolean") out.disabled = item.disabled;
2585
+ const disabledTips = projectTipsText(item.disabled_tips ?? item.disabledTips);
2586
+ if (disabledTips) out.disabled_tips = disabledTips;
2587
+ const hoverTips = projectTipsText(item.hover_tips ?? item.hoverTips);
2588
+ if (hoverTips) out.hover_tips = hoverTips;
2589
+ if (typeof item.transparent === "boolean") out.transparent = item.transparent;
2590
+ return out;
2591
+ }
2592
+ function projectTipsText(value) {
2593
+ if (typeof value === "string") return { tag: "plain_text", content: value };
2594
+ if (!isRecord3(value)) return void 0;
2595
+ const property = isRecord3(value.property) ? value.property : value;
2596
+ const content = typeof property.content === "string" ? property.content : "";
2597
+ return { tag: "plain_text", content };
2598
+ }
2464
2599
  function normalizeVideoCover(rawValue, ctx) {
2465
2600
  if (typeof rawValue === "string" || typeof rawValue === "number") {
2466
2601
  const imgKey2 = resolveAttachmentImgKey(rawValue, ctx);
package/dist/index.js CHANGED
@@ -936,6 +936,64 @@ function buildProperty(el, tag, colors) {
936
936
  }
937
937
  }
938
938
  }
939
+ if (tag === "img_combination") {
940
+ if (k === "combination_mode") {
941
+ property.combinationMode = v;
942
+ continue;
943
+ }
944
+ if (k === "img_list" && Array.isArray(v)) {
945
+ property.imgList = v.map((item) => {
946
+ if (!isRecord2(item)) return item;
947
+ const key = item.img_key ?? item.imgKey ?? item.img_id ?? item.imgId;
948
+ return compactRecord({
949
+ imageID: typeof key === "string" ? key : void 0,
950
+ transparent: typeof item.transparent === "boolean" ? item.transparent : void 0
951
+ });
952
+ });
953
+ continue;
954
+ }
955
+ if (k === "combination_transparent") {
956
+ property.transparent = v;
957
+ continue;
958
+ }
959
+ }
960
+ if (tag === "select_img") {
961
+ if (k === "options" && Array.isArray(v)) {
962
+ property.options = v.map((item) => {
963
+ if (!isRecord2(item)) return item;
964
+ const key = item.img_key ?? item.imgKey ?? item.img_id ?? item.imgId;
965
+ return compactRecord({
966
+ imageID: typeof key === "string" ? key : void 0,
967
+ value: item.value,
968
+ disabled: item.disabled,
969
+ disabled_tips: item.disabled_tips !== void 0 ? wrapTextLeaf(item.disabled_tips) : void 0,
970
+ hover_tips: item.hover_tips !== void 0 ? wrapTextLeaf(item.hover_tips) : void 0,
971
+ transparent: item.transparent
972
+ });
973
+ });
974
+ continue;
975
+ }
976
+ if (k === "multi_select") {
977
+ property.multiSelect = v;
978
+ continue;
979
+ }
980
+ if (k === "selected_values") {
981
+ property.selectedValues = v;
982
+ continue;
983
+ }
984
+ if (k === "can_preview") {
985
+ property.canPreview = v;
986
+ continue;
987
+ }
988
+ if (k === "aspect_ratio") {
989
+ property.aspectRatio = v;
990
+ continue;
991
+ }
992
+ if (k === "disabled_tips") {
993
+ property.disabledTips = wrapTextLeaf(v);
994
+ continue;
995
+ }
996
+ }
939
997
  if (TEXT_LEAF_KEYS.has(k)) {
940
998
  property[renameKey(k)] = wrapTextLeaf(v);
941
999
  continue;
@@ -1065,6 +1123,12 @@ function pxValue(s) {
1065
1123
  const n = Number(s);
1066
1124
  return Number.isFinite(n) ? n : null;
1067
1125
  }
1126
+ function compactRecord(obj) {
1127
+ for (const key of Object.keys(obj)) {
1128
+ if (obj[key] === void 0) delete obj[key];
1129
+ }
1130
+ return obj;
1131
+ }
1068
1132
  function isRecord2(v) {
1069
1133
  return typeof v === "object" && v !== null && !Array.isArray(v);
1070
1134
  }
@@ -1713,6 +1777,47 @@ function unwrapInner(node, ctx) {
1713
1777
  }
1714
1778
  return out;
1715
1779
  }
1780
+ if (tag === "img_combination") {
1781
+ const converted2 = convertProperty(property, tag, ctx);
1782
+ const out = { tag };
1783
+ if (typeof converted2.combination_mode === "string") {
1784
+ out.combination_mode = converted2.combination_mode;
1785
+ }
1786
+ const rawList = Array.isArray(property.imgList) ? property.imgList : Array.isArray(property.img_list) ? property.img_list : void 0;
1787
+ if (rawList) {
1788
+ out.img_list = rawList.map((item) => isRecord3(item) ? projectImgCombinationItem(item, ctx) : void 0).filter((item) => item !== void 0);
1789
+ }
1790
+ const transparent = property.combinationTransparent ?? property.combination_transparent ?? property.transparent;
1791
+ if (typeof transparent === "boolean") out.combination_transparent = transparent;
1792
+ if (converted2.corner_radius !== void 0) {
1793
+ out.corner_radius = converted2.corner_radius;
1794
+ } else if (typeof property.cornerRadiusValue === "number") {
1795
+ out.corner_radius = `${property.cornerRadiusValue}px`;
1796
+ } else if (typeof property.corner_radius === "string") {
1797
+ out.corner_radius = property.corner_radius;
1798
+ }
1799
+ if (typeof converted2.img_list_length === "number") {
1800
+ out.img_list_length = converted2.img_list_length;
1801
+ }
1802
+ if (converted2.margin !== void 0) out.margin = converted2.margin;
1803
+ return out;
1804
+ }
1805
+ if (tag === "select_img") {
1806
+ const converted2 = convertProperty(property, tag, ctx);
1807
+ const out = { tag, ...converted2 };
1808
+ const rawOptions = Array.isArray(property.options) ? property.options : void 0;
1809
+ if (rawOptions) {
1810
+ out.options = rawOptions.map(
1811
+ (option) => isRecord3(option) ? projectSelectImgOption(option, ctx) : {}
1812
+ );
1813
+ }
1814
+ if (Array.isArray(property.actions)) {
1815
+ const behaviors = property.actions.map((a) => actionEntryToBehavior(a, tag, ctx)).filter((b) => b !== void 0);
1816
+ delete out.actions;
1817
+ if (behaviors.length > 0) out.behaviors = behaviors;
1818
+ }
1819
+ return out;
1820
+ }
1716
1821
  if (tag === "div" && isRecord3(property.text) && property.fields === void 0) {
1717
1822
  const text = property.text;
1718
1823
  const textTag = typeof text.tag === "string" ? text.tag : "";
@@ -1975,8 +2080,6 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
1975
2080
  if (ownerTag === "collapsible_panel" && key === "header" && isRecord3(rawValue)) {
1976
2081
  const cleaned = {};
1977
2082
  for (const [k, v] of Object.entries(rawValue)) {
1978
- const sk = snake(k);
1979
- if (sk === "position" || sk === "width" || sk === "vertical_align") continue;
1980
2083
  const sub = convertField(k, v, "collapsible_panel_header", ctx, siblings);
1981
2084
  if (sub === DROP) continue;
1982
2085
  const [subKey, subVal] = sub;
@@ -2459,6 +2562,38 @@ function resolveAttachmentImgKey(rawValue, ctx) {
2459
2562
  if (id.startsWith("img_")) return id;
2460
2563
  return void 0;
2461
2564
  }
2565
+ function projectImageKey(item, ctx) {
2566
+ const direct = typeof item.img_key === "string" ? item.img_key : typeof item.imgKey === "string" ? item.imgKey : void 0;
2567
+ if (direct) return { img_key: direct };
2568
+ const id = item.imageID ?? item.image_id ?? item.imgId ?? item.img_id;
2569
+ const resolved = resolveAttachmentImgKey(id, ctx);
2570
+ if (resolved) return { img_key: resolved };
2571
+ if (typeof id === "string" || typeof id === "number") return { img_id: String(id) };
2572
+ return {};
2573
+ }
2574
+ function projectImgCombinationItem(item, ctx) {
2575
+ const out = projectImageKey(item, ctx);
2576
+ if (typeof item.transparent === "boolean") out.transparent = item.transparent;
2577
+ return Object.keys(out).length > 0 ? out : void 0;
2578
+ }
2579
+ function projectSelectImgOption(item, ctx) {
2580
+ const out = projectImageKey(item, ctx);
2581
+ if (typeof item.value === "string") out.value = item.value;
2582
+ if (typeof item.disabled === "boolean") out.disabled = item.disabled;
2583
+ const disabledTips = projectTipsText(item.disabled_tips ?? item.disabledTips);
2584
+ if (disabledTips) out.disabled_tips = disabledTips;
2585
+ const hoverTips = projectTipsText(item.hover_tips ?? item.hoverTips);
2586
+ if (hoverTips) out.hover_tips = hoverTips;
2587
+ if (typeof item.transparent === "boolean") out.transparent = item.transparent;
2588
+ return out;
2589
+ }
2590
+ function projectTipsText(value) {
2591
+ if (typeof value === "string") return { tag: "plain_text", content: value };
2592
+ if (!isRecord3(value)) return void 0;
2593
+ const property = isRecord3(value.property) ? value.property : value;
2594
+ const content = typeof property.content === "string" ? property.content : "";
2595
+ return { tag: "plain_text", content };
2596
+ }
2462
2597
  function normalizeVideoCover(rawValue, ctx) {
2463
2598
  if (typeof rawValue === "string" || typeof rawValue === "number") {
2464
2599
  const imgKey2 = resolveAttachmentImgKey(rawValue, ctx);
@@ -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,CAC1B,QAAQ,EAAE,OAAO,EACjB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAeT;AAED,4CAA4C;AAC5C,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,IAAI,EAAE,qBAAqB,GAAG,0BAA0B,GAAG,wBAAwB,CAAC;IACpF,cAAc;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAwB;AACxB,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,IAAI,CAAC;CAC7C;AA+2DD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CA+CzE;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,CAC1B,QAAQ,EAAE,OAAO,EACjB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAeT;AAED,4CAA4C;AAC5C,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,IAAI,EAAE,qBAAqB,GAAG,0BAA0B,GAAG,wBAAwB,CAAC;IACpF,cAAc;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAwB;AACxB,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,IAAI,CAAC;CAC7C;AA8+DD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CA+CzE;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.20",
3
+ "version": "0.4.1",
4
4
  "description": "公开 DSL 与飞书内部 RAW JSON 的双向适配器;raw→DSL 对齐 feishu-raw-card-to-dsl",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -22,7 +22,7 @@
22
22
  "tsx": "^4.19.3",
23
23
  "typescript": "^7.0.2",
24
24
  "vitest": "^2.1.9",
25
- "@open-feishu-card/schema": "0.1.10"
25
+ "@open-feishu-card/schema": "0.3.0"
26
26
  },
27
27
  "license": "MIT",
28
28
  "publishConfig": {