@open-feishu-card/adapter 0.3.11 → 0.3.13

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.
@@ -1 +1 @@
1
- {"version":3,"file":"dsl-to-raw.d.ts","sourceRoot":"","sources":["../src/dsl-to-raw.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAgC,QAAQ,EAAE,MAAM,YAAY,CAAC;AAwCzE,gCAAgC;AAChC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,QAAQ,CAW/C"}
1
+ {"version":3,"file":"dsl-to-raw.d.ts","sourceRoot":"","sources":["../src/dsl-to-raw.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAgC,QAAQ,EAAE,MAAM,YAAY,CAAC;AAmDzE,gCAAgC;AAChC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,QAAQ,CAW/C"}
package/dist/index.cjs CHANGED
@@ -698,6 +698,9 @@ var KEY_RENAME = {
698
698
  tag_style: "tagStyle",
699
699
  scale_type: "scaleType",
700
700
  drop_invalid_user_id: "dropInvalidUserID",
701
+ // avatar
702
+ custom_size: "customSize",
703
+ custom_size2: "customSize2",
701
704
  // video / audio
702
705
  file_key: "fileID",
703
706
  audio_id: "audioID",
@@ -706,7 +709,15 @@ var KEY_RENAME = {
706
709
  enable_download: "enableDownload",
707
710
  fill_color: "fillColor"
708
711
  };
709
- var TEXT_LEAF_KEYS = /* @__PURE__ */ new Set(["title", "subtitle", "alt", "hover_tips", "placeholder"]);
712
+ var TEXT_LEAF_KEYS = /* @__PURE__ */ new Set([
713
+ "title",
714
+ "subtitle",
715
+ "alt",
716
+ "hover_tips",
717
+ "placeholder",
718
+ "notation",
719
+ "disabled_tips"
720
+ ]);
710
721
  function dslToRaw(dsl) {
711
722
  const root = isRecord2(dsl) ? dsl : {};
712
723
  const card = unwrapCard(root);
@@ -767,6 +778,12 @@ function convertEl(el, colors) {
767
778
  }
768
779
  return { tag: "person_v1", property };
769
780
  }
781
+ if (tag === "avatar") {
782
+ return { tag: "avatar", property: buildProperty(el, "avatar", colors) };
783
+ }
784
+ if (tag === "picker_date") {
785
+ return { tag: "date_picker", property: buildProperty(el, "date_picker", colors) };
786
+ }
770
787
  if (tag === "markdown" || tag === "lark_md") {
771
788
  const property = buildProperty(el, "markdown", colors);
772
789
  const fontColor = typeof el.font_color === "string" ? el.font_color : void 0;
@@ -982,7 +999,11 @@ function behaviorsToActions(behaviors) {
982
999
  for (const b of behaviors) {
983
1000
  if (!isRecord2(b)) continue;
984
1001
  const type = typeof b.type === "string" ? b.type : "open_url";
985
- out.push({ type, action: { url: normalizeUrl(b.default_url) } });
1002
+ const action = { url: normalizeUrl(b.default_url) };
1003
+ if (typeof b.pc_url === "string" && b.pc_url) action.pcURL = b.pc_url;
1004
+ if (typeof b.ios_url === "string" && b.ios_url) action.iosURL = b.ios_url;
1005
+ if (typeof b.android_url === "string" && b.android_url) action.androidURL = b.android_url;
1006
+ out.push({ type, action });
986
1007
  }
987
1008
  return out;
988
1009
  }
@@ -1642,6 +1663,23 @@ function unwrap(node, ctx) {
1642
1663
  if (typeof property.style === "string") out.style = property.style;
1643
1664
  if (isRecord3(property.margin) && hasSide(property.margin)) out.margin = formatBox(property.margin);
1644
1665
  else if (typeof property.margin === "string") out.margin = property.margin;
1666
+ if (property.notation != null && isRecord3(property.notation)) {
1667
+ const n = convertHeaderText(property.notation, ctx);
1668
+ if (n) out.notation = n;
1669
+ }
1670
+ return out;
1671
+ }
1672
+ if (tag === "avatar") {
1673
+ const out = { tag: "avatar" };
1674
+ if (typeof property.userID === "string") out.user_id = property.userID;
1675
+ else if (typeof property.user_id === "string") out.user_id = property.user_id;
1676
+ if (typeof property.size === "string") out.size = property.size;
1677
+ if (typeof property.customSize === "number") out.custom_size = property.customSize;
1678
+ else if (typeof property.custom_size === "number") out.custom_size = property.custom_size;
1679
+ if (typeof property.customSize2 === "number") out.custom_size2 = property.customSize2;
1680
+ else if (typeof property.custom_size2 === "number") out.custom_size2 = property.custom_size2;
1681
+ if (isRecord3(property.margin) && hasSide(property.margin)) out.margin = formatBox(property.margin);
1682
+ else if (typeof property.margin === "string") out.margin = property.margin;
1645
1683
  return out;
1646
1684
  }
1647
1685
  if (tag === "person_list") {
@@ -1650,6 +1688,9 @@ function unwrap(node, ctx) {
1650
1688
  if (typeof property.showAvatar === "boolean") out.show_avatar = property.showAvatar;
1651
1689
  if (typeof property.showName === "boolean") out.show_name = property.showName;
1652
1690
  if (typeof property.lines === "number") out.lines = property.lines;
1691
+ if (typeof property.mode === "string") out.mode = property.mode;
1692
+ if (typeof property.style === "string") out.style = property.style;
1693
+ if (typeof property.count === "number") out.count = property.count;
1653
1694
  if (typeof property.dropInvalidUserID === "boolean") out.drop_invalid_user_id = property.dropInvalidUserID;
1654
1695
  else if (typeof property.drop_invalid_user_id === "boolean") out.drop_invalid_user_id = property.drop_invalid_user_id;
1655
1696
  if (isRecord3(property.margin) && hasSide(property.margin)) out.margin = formatBox(property.margin);
@@ -1702,6 +1743,47 @@ function unwrap(node, ctx) {
1702
1743
  return tag ? { tag, ...converted } : converted;
1703
1744
  }
1704
1745
  var DROP = /* @__PURE__ */ Symbol("drop");
1746
+ function projectOpenUrlFields(actionInner) {
1747
+ let bag;
1748
+ let defaultUrl;
1749
+ if (typeof actionInner.url === "string") {
1750
+ defaultUrl = actionInner.url;
1751
+ bag = actionInner;
1752
+ } else if (isRecord3(actionInner.url)) {
1753
+ bag = actionInner.url;
1754
+ defaultUrl = typeof bag.url === "string" ? bag.url : void 0;
1755
+ } else if (isRecord3(actionInner.multiURL)) {
1756
+ bag = actionInner.multiURL;
1757
+ defaultUrl = typeof bag.url === "string" ? bag.url : void 0;
1758
+ } else if (isRecord3(actionInner.multi_url)) {
1759
+ bag = actionInner.multi_url;
1760
+ defaultUrl = typeof bag.url === "string" ? bag.url : void 0;
1761
+ }
1762
+ if (!defaultUrl) return void 0;
1763
+ const pick = (...keys) => {
1764
+ if (!bag) return void 0;
1765
+ for (const k of keys) {
1766
+ const v = bag[k];
1767
+ if (typeof v === "string" && v.length > 0) return v;
1768
+ }
1769
+ return void 0;
1770
+ };
1771
+ const out = { default_url: defaultUrl };
1772
+ const pc = pick("pcURL", "pc_url");
1773
+ const ios = pick("iosURL", "ios_url");
1774
+ const android = pick("androidURL", "android_url");
1775
+ if (pc) out.pc_url = pc;
1776
+ if (ios) out.ios_url = ios;
1777
+ if (android) out.android_url = android;
1778
+ return out;
1779
+ }
1780
+ function openUrlFieldsToMultiUrl(fields) {
1781
+ const multi = { url: fields.default_url };
1782
+ if (fields.pc_url) multi.pc_url = fields.pc_url;
1783
+ if (fields.ios_url) multi.ios_url = fields.ios_url;
1784
+ if (fields.android_url) multi.android_url = fields.android_url;
1785
+ return multi;
1786
+ }
1705
1787
  function convertProperty(property, ownerTag, ctx) {
1706
1788
  const out = {};
1707
1789
  const siblings = {
@@ -1844,15 +1926,17 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
1844
1926
  if (!isRecord3(a)) continue;
1845
1927
  const inner = isRecord3(a.action) ? a.action : {};
1846
1928
  const t = typeof a.type === "string" ? a.type : void 0;
1847
- if (t === "open_url" && typeof inner.url === "string") openUrls.push(inner.url);
1929
+ if (t !== "open_url") continue;
1930
+ const fields = projectOpenUrlFields(inner);
1931
+ if (fields) openUrls.push(fields);
1848
1932
  }
1849
1933
  if (openUrls.length === 0) return DROP;
1850
1934
  if (siblings.buttonActionType === "link") {
1851
- return ["multi_url", { url: openUrls[0] }];
1935
+ return ["multi_url", openUrlFieldsToMultiUrl(openUrls[0])];
1852
1936
  }
1853
1937
  return [
1854
1938
  "behaviors",
1855
- openUrls.map((url) => ({ type: "open_url", default_url: url }))
1939
+ openUrls.map((fields) => ({ type: "open_url", ...fields }))
1856
1940
  ];
1857
1941
  }
1858
1942
  if (ownerTag === "interactive_container" && key === "actions" && Array.isArray(rawValue)) {
@@ -1860,8 +1944,9 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
1860
1944
  if (!isRecord3(a)) return void 0;
1861
1945
  const inner = isRecord3(a.action) ? a.action : {};
1862
1946
  const t = typeof a.type === "string" ? a.type : void 0;
1863
- if (t === "open_url" && typeof inner.url === "string") {
1864
- return { type: "open_url", default_url: inner.url };
1947
+ if (t === "open_url") {
1948
+ const fields = projectOpenUrlFields(inner);
1949
+ return fields ? { type: "open_url", ...fields } : void 0;
1865
1950
  }
1866
1951
  if (t === "callback") {
1867
1952
  return { type: "callback", value: inner.value ?? {} };
package/dist/index.js CHANGED
@@ -696,6 +696,9 @@ var KEY_RENAME = {
696
696
  tag_style: "tagStyle",
697
697
  scale_type: "scaleType",
698
698
  drop_invalid_user_id: "dropInvalidUserID",
699
+ // avatar
700
+ custom_size: "customSize",
701
+ custom_size2: "customSize2",
699
702
  // video / audio
700
703
  file_key: "fileID",
701
704
  audio_id: "audioID",
@@ -704,7 +707,15 @@ var KEY_RENAME = {
704
707
  enable_download: "enableDownload",
705
708
  fill_color: "fillColor"
706
709
  };
707
- var TEXT_LEAF_KEYS = /* @__PURE__ */ new Set(["title", "subtitle", "alt", "hover_tips", "placeholder"]);
710
+ var TEXT_LEAF_KEYS = /* @__PURE__ */ new Set([
711
+ "title",
712
+ "subtitle",
713
+ "alt",
714
+ "hover_tips",
715
+ "placeholder",
716
+ "notation",
717
+ "disabled_tips"
718
+ ]);
708
719
  function dslToRaw(dsl) {
709
720
  const root = isRecord2(dsl) ? dsl : {};
710
721
  const card = unwrapCard(root);
@@ -765,6 +776,12 @@ function convertEl(el, colors) {
765
776
  }
766
777
  return { tag: "person_v1", property };
767
778
  }
779
+ if (tag === "avatar") {
780
+ return { tag: "avatar", property: buildProperty(el, "avatar", colors) };
781
+ }
782
+ if (tag === "picker_date") {
783
+ return { tag: "date_picker", property: buildProperty(el, "date_picker", colors) };
784
+ }
768
785
  if (tag === "markdown" || tag === "lark_md") {
769
786
  const property = buildProperty(el, "markdown", colors);
770
787
  const fontColor = typeof el.font_color === "string" ? el.font_color : void 0;
@@ -980,7 +997,11 @@ function behaviorsToActions(behaviors) {
980
997
  for (const b of behaviors) {
981
998
  if (!isRecord2(b)) continue;
982
999
  const type = typeof b.type === "string" ? b.type : "open_url";
983
- out.push({ type, action: { url: normalizeUrl(b.default_url) } });
1000
+ const action = { url: normalizeUrl(b.default_url) };
1001
+ if (typeof b.pc_url === "string" && b.pc_url) action.pcURL = b.pc_url;
1002
+ if (typeof b.ios_url === "string" && b.ios_url) action.iosURL = b.ios_url;
1003
+ if (typeof b.android_url === "string" && b.android_url) action.androidURL = b.android_url;
1004
+ out.push({ type, action });
984
1005
  }
985
1006
  return out;
986
1007
  }
@@ -1640,6 +1661,23 @@ function unwrap(node, ctx) {
1640
1661
  if (typeof property.style === "string") out.style = property.style;
1641
1662
  if (isRecord3(property.margin) && hasSide(property.margin)) out.margin = formatBox(property.margin);
1642
1663
  else if (typeof property.margin === "string") out.margin = property.margin;
1664
+ if (property.notation != null && isRecord3(property.notation)) {
1665
+ const n = convertHeaderText(property.notation, ctx);
1666
+ if (n) out.notation = n;
1667
+ }
1668
+ return out;
1669
+ }
1670
+ if (tag === "avatar") {
1671
+ const out = { tag: "avatar" };
1672
+ if (typeof property.userID === "string") out.user_id = property.userID;
1673
+ else if (typeof property.user_id === "string") out.user_id = property.user_id;
1674
+ if (typeof property.size === "string") out.size = property.size;
1675
+ if (typeof property.customSize === "number") out.custom_size = property.customSize;
1676
+ else if (typeof property.custom_size === "number") out.custom_size = property.custom_size;
1677
+ if (typeof property.customSize2 === "number") out.custom_size2 = property.customSize2;
1678
+ else if (typeof property.custom_size2 === "number") out.custom_size2 = property.custom_size2;
1679
+ if (isRecord3(property.margin) && hasSide(property.margin)) out.margin = formatBox(property.margin);
1680
+ else if (typeof property.margin === "string") out.margin = property.margin;
1643
1681
  return out;
1644
1682
  }
1645
1683
  if (tag === "person_list") {
@@ -1648,6 +1686,9 @@ function unwrap(node, ctx) {
1648
1686
  if (typeof property.showAvatar === "boolean") out.show_avatar = property.showAvatar;
1649
1687
  if (typeof property.showName === "boolean") out.show_name = property.showName;
1650
1688
  if (typeof property.lines === "number") out.lines = property.lines;
1689
+ if (typeof property.mode === "string") out.mode = property.mode;
1690
+ if (typeof property.style === "string") out.style = property.style;
1691
+ if (typeof property.count === "number") out.count = property.count;
1651
1692
  if (typeof property.dropInvalidUserID === "boolean") out.drop_invalid_user_id = property.dropInvalidUserID;
1652
1693
  else if (typeof property.drop_invalid_user_id === "boolean") out.drop_invalid_user_id = property.drop_invalid_user_id;
1653
1694
  if (isRecord3(property.margin) && hasSide(property.margin)) out.margin = formatBox(property.margin);
@@ -1700,6 +1741,47 @@ function unwrap(node, ctx) {
1700
1741
  return tag ? { tag, ...converted } : converted;
1701
1742
  }
1702
1743
  var DROP = /* @__PURE__ */ Symbol("drop");
1744
+ function projectOpenUrlFields(actionInner) {
1745
+ let bag;
1746
+ let defaultUrl;
1747
+ if (typeof actionInner.url === "string") {
1748
+ defaultUrl = actionInner.url;
1749
+ bag = actionInner;
1750
+ } else if (isRecord3(actionInner.url)) {
1751
+ bag = actionInner.url;
1752
+ defaultUrl = typeof bag.url === "string" ? bag.url : void 0;
1753
+ } else if (isRecord3(actionInner.multiURL)) {
1754
+ bag = actionInner.multiURL;
1755
+ defaultUrl = typeof bag.url === "string" ? bag.url : void 0;
1756
+ } else if (isRecord3(actionInner.multi_url)) {
1757
+ bag = actionInner.multi_url;
1758
+ defaultUrl = typeof bag.url === "string" ? bag.url : void 0;
1759
+ }
1760
+ if (!defaultUrl) return void 0;
1761
+ const pick = (...keys) => {
1762
+ if (!bag) return void 0;
1763
+ for (const k of keys) {
1764
+ const v = bag[k];
1765
+ if (typeof v === "string" && v.length > 0) return v;
1766
+ }
1767
+ return void 0;
1768
+ };
1769
+ const out = { default_url: defaultUrl };
1770
+ const pc = pick("pcURL", "pc_url");
1771
+ const ios = pick("iosURL", "ios_url");
1772
+ const android = pick("androidURL", "android_url");
1773
+ if (pc) out.pc_url = pc;
1774
+ if (ios) out.ios_url = ios;
1775
+ if (android) out.android_url = android;
1776
+ return out;
1777
+ }
1778
+ function openUrlFieldsToMultiUrl(fields) {
1779
+ const multi = { url: fields.default_url };
1780
+ if (fields.pc_url) multi.pc_url = fields.pc_url;
1781
+ if (fields.ios_url) multi.ios_url = fields.ios_url;
1782
+ if (fields.android_url) multi.android_url = fields.android_url;
1783
+ return multi;
1784
+ }
1703
1785
  function convertProperty(property, ownerTag, ctx) {
1704
1786
  const out = {};
1705
1787
  const siblings = {
@@ -1842,15 +1924,17 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
1842
1924
  if (!isRecord3(a)) continue;
1843
1925
  const inner = isRecord3(a.action) ? a.action : {};
1844
1926
  const t = typeof a.type === "string" ? a.type : void 0;
1845
- if (t === "open_url" && typeof inner.url === "string") openUrls.push(inner.url);
1927
+ if (t !== "open_url") continue;
1928
+ const fields = projectOpenUrlFields(inner);
1929
+ if (fields) openUrls.push(fields);
1846
1930
  }
1847
1931
  if (openUrls.length === 0) return DROP;
1848
1932
  if (siblings.buttonActionType === "link") {
1849
- return ["multi_url", { url: openUrls[0] }];
1933
+ return ["multi_url", openUrlFieldsToMultiUrl(openUrls[0])];
1850
1934
  }
1851
1935
  return [
1852
1936
  "behaviors",
1853
- openUrls.map((url) => ({ type: "open_url", default_url: url }))
1937
+ openUrls.map((fields) => ({ type: "open_url", ...fields }))
1854
1938
  ];
1855
1939
  }
1856
1940
  if (ownerTag === "interactive_container" && key === "actions" && Array.isArray(rawValue)) {
@@ -1858,8 +1942,9 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
1858
1942
  if (!isRecord3(a)) return void 0;
1859
1943
  const inner = isRecord3(a.action) ? a.action : {};
1860
1944
  const t = typeof a.type === "string" ? a.type : void 0;
1861
- if (t === "open_url" && typeof inner.url === "string") {
1862
- return { type: "open_url", default_url: inner.url };
1945
+ if (t === "open_url") {
1946
+ const fields = projectOpenUrlFields(inner);
1947
+ return fields ? { type: "open_url", ...fields } : void 0;
1863
1948
  }
1864
1949
  if (t === "callback") {
1865
1950
  return { type: "callback", value: inner.value ?? {} };
@@ -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;AAylDD;;;;;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;AAorDD;;;;;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.11",
3
+ "version": "0.3.13",
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.4"
25
+ "@open-feishu-card/schema": "0.1.5"
26
26
  },
27
27
  "license": "MIT",
28
28
  "publishConfig": {