@open-feishu-card/adapter 0.3.19 → 0.4.0

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
@@ -818,10 +818,12 @@ function convertEl(el, colors) {
818
818
  }
819
819
  }
820
820
  if (tag === "video") {
821
- const cover = el.image_key ?? el.cover_image_key ?? el.coverImageID;
821
+ const nestedCover = isRecord2(el.cover) ? el.cover.img_key : void 0;
822
+ const cover = nestedCover ?? el.image_key ?? el.cover_image_key ?? el.coverImageID;
822
823
  if (typeof cover === "string" && cover) property.coverImageID = cover;
823
824
  delete property.image_key;
824
825
  delete property.cover_image_key;
826
+ delete property.cover;
825
827
  }
826
828
  return withRawElementId(el, { tag, property });
827
829
  }
@@ -936,6 +938,64 @@ function buildProperty(el, tag, colors) {
936
938
  }
937
939
  }
938
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
+ }
939
999
  if (TEXT_LEAF_KEYS.has(k)) {
940
1000
  property[renameKey(k)] = wrapTextLeaf(v);
941
1001
  continue;
@@ -1065,6 +1125,12 @@ function pxValue(s) {
1065
1125
  const n = Number(s);
1066
1126
  return Number.isFinite(n) ? n : null;
1067
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
+ }
1068
1134
  function isRecord2(v) {
1069
1135
  return typeof v === "object" && v !== null && !Array.isArray(v);
1070
1136
  }
@@ -1713,6 +1779,47 @@ function unwrapInner(node, ctx) {
1713
1779
  }
1714
1780
  return out;
1715
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
+ }
1716
1823
  if (tag === "div" && isRecord3(property.text) && property.fields === void 0) {
1717
1824
  const text = property.text;
1718
1825
  const textTag = typeof text.tag === "string" ? text.tag : "";
@@ -2459,6 +2566,38 @@ function resolveAttachmentImgKey(rawValue, ctx) {
2459
2566
  if (id.startsWith("img_")) return id;
2460
2567
  return void 0;
2461
2568
  }
2569
+ function projectImageKey(item, ctx) {
2570
+ const direct = typeof item.img_key === "string" ? item.img_key : typeof item.imgKey === "string" ? item.imgKey : void 0;
2571
+ if (direct) return { img_key: direct };
2572
+ const id = item.imageID ?? item.image_id ?? item.imgId ?? item.img_id;
2573
+ const resolved = resolveAttachmentImgKey(id, ctx);
2574
+ if (resolved) return { img_key: resolved };
2575
+ if (typeof id === "string" || typeof id === "number") return { img_id: String(id) };
2576
+ return {};
2577
+ }
2578
+ function projectImgCombinationItem(item, ctx) {
2579
+ const out = projectImageKey(item, ctx);
2580
+ if (typeof item.transparent === "boolean") out.transparent = item.transparent;
2581
+ return Object.keys(out).length > 0 ? out : void 0;
2582
+ }
2583
+ function projectSelectImgOption(item, ctx) {
2584
+ const out = projectImageKey(item, ctx);
2585
+ if (typeof item.value === "string") out.value = item.value;
2586
+ if (typeof item.disabled === "boolean") out.disabled = item.disabled;
2587
+ const disabledTips = projectTipsText(item.disabled_tips ?? item.disabledTips);
2588
+ if (disabledTips) out.disabled_tips = disabledTips;
2589
+ const hoverTips = projectTipsText(item.hover_tips ?? item.hoverTips);
2590
+ if (hoverTips) out.hover_tips = hoverTips;
2591
+ if (typeof item.transparent === "boolean") out.transparent = item.transparent;
2592
+ return out;
2593
+ }
2594
+ function projectTipsText(value) {
2595
+ if (typeof value === "string") return { tag: "plain_text", content: value };
2596
+ if (!isRecord3(value)) return void 0;
2597
+ const property = isRecord3(value.property) ? value.property : value;
2598
+ const content = typeof property.content === "string" ? property.content : "";
2599
+ return { tag: "plain_text", content };
2600
+ }
2462
2601
  function normalizeVideoCover(rawValue, ctx) {
2463
2602
  if (typeof rawValue === "string" || typeof rawValue === "number") {
2464
2603
  const imgKey2 = resolveAttachmentImgKey(rawValue, ctx);
package/dist/index.js CHANGED
@@ -816,10 +816,12 @@ function convertEl(el, colors) {
816
816
  }
817
817
  }
818
818
  if (tag === "video") {
819
- const cover = el.image_key ?? el.cover_image_key ?? el.coverImageID;
819
+ const nestedCover = isRecord2(el.cover) ? el.cover.img_key : void 0;
820
+ const cover = nestedCover ?? el.image_key ?? el.cover_image_key ?? el.coverImageID;
820
821
  if (typeof cover === "string" && cover) property.coverImageID = cover;
821
822
  delete property.image_key;
822
823
  delete property.cover_image_key;
824
+ delete property.cover;
823
825
  }
824
826
  return withRawElementId(el, { tag, property });
825
827
  }
@@ -934,6 +936,64 @@ function buildProperty(el, tag, colors) {
934
936
  }
935
937
  }
936
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
+ }
937
997
  if (TEXT_LEAF_KEYS.has(k)) {
938
998
  property[renameKey(k)] = wrapTextLeaf(v);
939
999
  continue;
@@ -1063,6 +1123,12 @@ function pxValue(s) {
1063
1123
  const n = Number(s);
1064
1124
  return Number.isFinite(n) ? n : null;
1065
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
+ }
1066
1132
  function isRecord2(v) {
1067
1133
  return typeof v === "object" && v !== null && !Array.isArray(v);
1068
1134
  }
@@ -1711,6 +1777,47 @@ function unwrapInner(node, ctx) {
1711
1777
  }
1712
1778
  return out;
1713
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
+ }
1714
1821
  if (tag === "div" && isRecord3(property.text) && property.fields === void 0) {
1715
1822
  const text = property.text;
1716
1823
  const textTag = typeof text.tag === "string" ? text.tag : "";
@@ -2457,6 +2564,38 @@ function resolveAttachmentImgKey(rawValue, ctx) {
2457
2564
  if (id.startsWith("img_")) return id;
2458
2565
  return void 0;
2459
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
+ }
2460
2599
  function normalizeVideoCover(rawValue, ctx) {
2461
2600
  if (typeof rawValue === "string" || typeof rawValue === "number") {
2462
2601
  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;AAk/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.19",
3
+ "version": "0.4.0",
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.9"
25
+ "@open-feishu-card/schema": "0.2.0"
26
26
  },
27
27
  "license": "MIT",
28
28
  "publishConfig": {