@open-feishu-card/adapter 0.3.9 → 0.3.11

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,6 +1,9 @@
1
1
  /**
2
- * DSL config.style.color 中的 cus-* 别名在 dslToRaw 时展开为渲染器已支持的
2
+ * DSL config.style.color 中的自定义色别名在 dslToRaw 时展开为渲染器已支持的
3
3
  * customBackgroundStyle / textStyle.customColor(对齐飞书 RAW 真机字段)。
4
+ *
5
+ * 别名不限于编辑器默认的 cus-*:业务卡也常用 mm_* 等任意 token 名登记在
6
+ * config.style.color,真机按 registry 键查找;仅认 cus- 前缀会导致背景/描边丢失。
4
7
  */
5
8
  import type { CardElement, TextStyle } from './types.js';
6
9
  export type CustomColorEntry = {
@@ -9,15 +12,18 @@ export type CustomColorEntry = {
9
12
  };
10
13
  export type ColorRegistry = Record<string, CustomColorEntry>;
11
14
  export declare function readColorRegistry(card: Record<string, unknown>): ColorRegistry;
15
+ /** @deprecated 保留兼容;展开逻辑改为查 registry,不再依赖 cus- 前缀。 */
12
16
  export declare function isCustomColorAlias(value: unknown): value is string;
13
- /** column / column_set background_style cus-N → customBackgroundStyle */
17
+ /** 是否为 config.style.color 中已登记的别名(任意 token 名)。 */
18
+ export declare function isRegisteredColorAlias(value: unknown, registry: ColorRegistry): value is string;
19
+ /** column / column_set / interactive_container background_style → customBackgroundStyle */
14
20
  export declare function expandBackgroundStyleAlias(style: unknown, registry: ColorRegistry): {
15
21
  light_mode: string;
16
22
  dark_mode: string;
17
23
  } | undefined;
18
- /** textStyle.color cus-N → customColor(去掉 color,避免被当成命名色) */
24
+ /** textStyle.color 登记别名 → customColor(去掉 color,避免被当成命名色) */
19
25
  export declare function expandTextStyleColor(textStyle: TextStyle | undefined, registry: ColorRegistry): TextStyle | undefined;
20
- /** border_color / background_style 等 cus-N → customBackgroundStyle 形态(供 RAW 渲染器读取) */
26
+ /** border_color / background_style 等登记别名 → customBackgroundStyle 形态(供 RAW 渲染器读取) */
21
27
  export declare function expandColorAlias(style: unknown, registry: ColorRegistry): {
22
28
  light_mode: string;
23
29
  dark_mode: string;
@@ -1 +1 @@
1
- {"version":3,"file":"expand-dsl-colors.d.ts","sourceRoot":"","sources":["../src/expand-dsl-colors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEzD,MAAM,MAAM,gBAAgB,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AACzE,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAE7D,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,CAiB9E;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAElE;AAED,yEAAyE;AACzE,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,aAAa,GACtB;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAKvD;AAED,6DAA6D;AAC7D,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,SAAS,GAAG,SAAS,EAChC,QAAQ,EAAE,aAAa,GACtB,SAAS,GAAG,SAAS,CAWvB;AAED,sFAAsF;AACtF,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,aAAa,GACtB;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAEvD;AAED,0CAA0C;AAC1C,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,WAAW,EAAE,GAAG,SAAS,EACnC,QAAQ,EAAE,aAAa,GACtB,WAAW,EAAE,GAA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AE,MAAM,CAAA;CAAE,GAAG,SAAS,CAEvD;AAED,0CAA0C;AAC1C,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,WAAW,EAAE,GAAG,SAAS,EACnC,QAAQ,EAAE,aAAa,GACtB,WAAW,EAAE,GAAG,SAAS,CAG3B;AAuCD,4DAA4D;AAC5D,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAAG,SAAS,GAC5B,MAAM,CAGR"}
package/dist/index.cjs CHANGED
@@ -621,21 +621,19 @@ function readColorRegistry(card) {
621
621
  }
622
622
  return out;
623
623
  }
624
- function isCustomColorAlias(value) {
625
- return typeof value === "string" && value.startsWith("cus-");
624
+ function isRegisteredColorAlias(value, registry) {
625
+ return typeof value === "string" && !!value && Object.prototype.hasOwnProperty.call(registry, value);
626
626
  }
627
627
  function expandBackgroundStyleAlias(style, registry) {
628
- if (!isCustomColorAlias(style)) return void 0;
628
+ if (!isRegisteredColorAlias(style, registry)) return void 0;
629
629
  const entry = registry[style];
630
- if (!entry) return void 0;
631
630
  return { light_mode: entry.light_mode, dark_mode: entry.dark_mode };
632
631
  }
633
632
  function expandTextStyleColor(textStyle, registry) {
634
633
  if (!textStyle) return textStyle;
635
634
  const color = typeof textStyle.color === "string" ? textStyle.color.trim() : void 0;
636
- if (!isCustomColorAlias(color)) return textStyle;
635
+ if (!isRegisteredColorAlias(color, registry)) return textStyle;
637
636
  const entry = registry[color];
638
- if (!entry) return textStyle;
639
637
  const { color: _drop, ...rest } = textStyle;
640
638
  return {
641
639
  ...rest,
@@ -843,13 +841,27 @@ function buildProperty(el, tag, colors) {
843
841
  const property = {};
844
842
  for (const [k, v] of Object.entries(el)) {
845
843
  if (k === "tag" || k === "id") continue;
846
- if ((k === "background_style" || k === "backgroundStyle") && (tag === "column" || tag === "column_set")) {
844
+ if ((k === "background_style" || k === "backgroundStyle") && (tag === "column" || tag === "column_set" || tag === "interactive_container")) {
847
845
  const renamed = renameKey(k);
848
846
  property[renamed] = v;
849
847
  const expanded = expandBackgroundStyleAlias(v, colors);
850
848
  if (expanded) property.customBackgroundStyle = expanded;
851
849
  continue;
852
850
  }
851
+ if ((k === "background_color" || k === "backgroundColor") && tag === "collapsible_panel") {
852
+ const renamed = renameKey(k);
853
+ property[renamed] = v;
854
+ const expanded = expandBackgroundStyleAlias(v, colors);
855
+ if (expanded) property.customBackgroundStyle = expanded;
856
+ continue;
857
+ }
858
+ if (k === "border" && tag === "collapsible_panel" && isRecord2(v)) {
859
+ const border = { ...v };
860
+ const expanded = expandBackgroundStyleAlias(border.color, colors);
861
+ if (expanded) border.color = expanded.light_mode;
862
+ property.border = border;
863
+ continue;
864
+ }
853
865
  if ((k === "border_color" || k === "borderColor") && tag === "interactive_container") {
854
866
  const renamed = renameKey(k);
855
867
  property[renamed] = v;
@@ -869,6 +881,30 @@ function buildProperty(el, tag, colors) {
869
881
  continue;
870
882
  }
871
883
  }
884
+ if (tag === "interactive_container" && typeof v === "string") {
885
+ if (k === "width") {
886
+ if (v === "fill" || v === "auto" || v === "default") {
887
+ property.widthValue = { type: "builtin_interactive_container_width", value: v };
888
+ continue;
889
+ }
890
+ const px = pxValue(v);
891
+ if (px != null) {
892
+ property.widthValue = { type: "pixels", value: px };
893
+ continue;
894
+ }
895
+ }
896
+ if (k === "height") {
897
+ if (v === "auto" || v === "default") {
898
+ property.heightValue = { type: "builtin_interactive_container_height", value: v };
899
+ continue;
900
+ }
901
+ const px = pxValue(v);
902
+ if (px != null) {
903
+ property.heightValue = { type: "pixels", value: px };
904
+ continue;
905
+ }
906
+ }
907
+ }
872
908
  if (TEXT_LEAF_KEYS.has(k)) {
873
909
  property[renameKey(k)] = wrapTextLeaf(v);
874
910
  continue;
package/dist/index.js CHANGED
@@ -619,21 +619,19 @@ function readColorRegistry(card) {
619
619
  }
620
620
  return out;
621
621
  }
622
- function isCustomColorAlias(value) {
623
- return typeof value === "string" && value.startsWith("cus-");
622
+ function isRegisteredColorAlias(value, registry) {
623
+ return typeof value === "string" && !!value && Object.prototype.hasOwnProperty.call(registry, value);
624
624
  }
625
625
  function expandBackgroundStyleAlias(style, registry) {
626
- if (!isCustomColorAlias(style)) return void 0;
626
+ if (!isRegisteredColorAlias(style, registry)) return void 0;
627
627
  const entry = registry[style];
628
- if (!entry) return void 0;
629
628
  return { light_mode: entry.light_mode, dark_mode: entry.dark_mode };
630
629
  }
631
630
  function expandTextStyleColor(textStyle, registry) {
632
631
  if (!textStyle) return textStyle;
633
632
  const color = typeof textStyle.color === "string" ? textStyle.color.trim() : void 0;
634
- if (!isCustomColorAlias(color)) return textStyle;
633
+ if (!isRegisteredColorAlias(color, registry)) return textStyle;
635
634
  const entry = registry[color];
636
- if (!entry) return textStyle;
637
635
  const { color: _drop, ...rest } = textStyle;
638
636
  return {
639
637
  ...rest,
@@ -841,13 +839,27 @@ function buildProperty(el, tag, colors) {
841
839
  const property = {};
842
840
  for (const [k, v] of Object.entries(el)) {
843
841
  if (k === "tag" || k === "id") continue;
844
- if ((k === "background_style" || k === "backgroundStyle") && (tag === "column" || tag === "column_set")) {
842
+ if ((k === "background_style" || k === "backgroundStyle") && (tag === "column" || tag === "column_set" || tag === "interactive_container")) {
845
843
  const renamed = renameKey(k);
846
844
  property[renamed] = v;
847
845
  const expanded = expandBackgroundStyleAlias(v, colors);
848
846
  if (expanded) property.customBackgroundStyle = expanded;
849
847
  continue;
850
848
  }
849
+ if ((k === "background_color" || k === "backgroundColor") && tag === "collapsible_panel") {
850
+ const renamed = renameKey(k);
851
+ property[renamed] = v;
852
+ const expanded = expandBackgroundStyleAlias(v, colors);
853
+ if (expanded) property.customBackgroundStyle = expanded;
854
+ continue;
855
+ }
856
+ if (k === "border" && tag === "collapsible_panel" && isRecord2(v)) {
857
+ const border = { ...v };
858
+ const expanded = expandBackgroundStyleAlias(border.color, colors);
859
+ if (expanded) border.color = expanded.light_mode;
860
+ property.border = border;
861
+ continue;
862
+ }
851
863
  if ((k === "border_color" || k === "borderColor") && tag === "interactive_container") {
852
864
  const renamed = renameKey(k);
853
865
  property[renamed] = v;
@@ -867,6 +879,30 @@ function buildProperty(el, tag, colors) {
867
879
  continue;
868
880
  }
869
881
  }
882
+ if (tag === "interactive_container" && typeof v === "string") {
883
+ if (k === "width") {
884
+ if (v === "fill" || v === "auto" || v === "default") {
885
+ property.widthValue = { type: "builtin_interactive_container_width", value: v };
886
+ continue;
887
+ }
888
+ const px = pxValue(v);
889
+ if (px != null) {
890
+ property.widthValue = { type: "pixels", value: px };
891
+ continue;
892
+ }
893
+ }
894
+ if (k === "height") {
895
+ if (v === "auto" || v === "default") {
896
+ property.heightValue = { type: "builtin_interactive_container_height", value: v };
897
+ continue;
898
+ }
899
+ const px = pxValue(v);
900
+ if (px != null) {
901
+ property.heightValue = { type: "pixels", value: px };
902
+ continue;
903
+ }
904
+ }
905
+ }
870
906
  if (TEXT_LEAF_KEYS.has(k)) {
871
907
  property[renameKey(k)] = wrapTextLeaf(v);
872
908
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-feishu-card/adapter",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "description": "公开 DSL 与飞书内部 RAW JSON 的双向适配器;raw→DSL 对齐 feishu-raw-card-to-dsl",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",