@open-feishu-card/renderer 0.2.4 → 0.2.6

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/all.css CHANGED
@@ -324,6 +324,9 @@
324
324
  /* ---- 布局:column_set / column ---- */
325
325
  .universal-card-column-set { display: flex; }
326
326
  .universal-card-column { box-sizing: border-box; overflow-wrap: anywhere; }
327
+ /* 真机:有背景才挂 --bg。column_set 额外 4px 内边距;column 只圆角、不加默认 padding。 */
328
+ .universal-card-column-set--bg { padding: 4px; border-radius: 6px; }
329
+ .universal-card-column--bg { border-radius: 6px; }
327
330
  /* 列内纵向间距唯一来源是 column 组件输出的 flex row-gap(默认 8px,可被 vertical_spacing 覆盖)。
328
331
  这里不再给相邻子元素设 margin-top——否则与 row-gap 叠加,间距翻倍。 */
329
332
 
package/dist/index.cjs CHANGED
@@ -1140,6 +1140,9 @@ var BASE_STYLES_CSS = `/**
1140
1140
  /* ---- \u5E03\u5C40\uFF1Acolumn_set / column ---- */
1141
1141
  .universal-card-column-set { display: flex; }
1142
1142
  .universal-card-column { box-sizing: border-box; overflow-wrap: anywhere; }
1143
+ /* \u771F\u673A\uFF1A\u6709\u80CC\u666F\u624D\u6302 --bg\u3002column_set \u989D\u5916 4px \u5185\u8FB9\u8DDD\uFF1Bcolumn \u53EA\u5706\u89D2\u3001\u4E0D\u52A0\u9ED8\u8BA4 padding\u3002 */
1144
+ .universal-card-column-set--bg { padding: 4px; border-radius: 6px; }
1145
+ .universal-card-column--bg { border-radius: 6px; }
1143
1146
  /* \u5217\u5185\u7EB5\u5411\u95F4\u8DDD\u552F\u4E00\u6765\u6E90\u662F column \u7EC4\u4EF6\u8F93\u51FA\u7684 flex row-gap\uFF08\u9ED8\u8BA4 8px\uFF0C\u53EF\u88AB vertical_spacing \u8986\u76D6\uFF09\u3002
1144
1147
  \u8FD9\u91CC\u4E0D\u518D\u7ED9\u76F8\u90BB\u5B50\u5143\u7D20\u8BBE margin-top\u2014\u2014\u5426\u5219\u4E0E row-gap \u53E0\u52A0\uFF0C\u95F4\u8DDD\u7FFB\u500D\u3002 */
1145
1148
 
@@ -5319,6 +5322,23 @@ function resolveChartBoxStyle(p, spec) {
5319
5322
  else style.aspectRatio = "16 / 9";
5320
5323
  return style;
5321
5324
  }
5325
+ function renderHeaderTextLeaf(node, ctx, className) {
5326
+ if (!node) return null;
5327
+ const tag = node.tag;
5328
+ const p = node.property || {};
5329
+ const isMd = tag === "markdown" || tag === "lark_md";
5330
+ if (isMd) {
5331
+ let elements = Array.isArray(p.elements) ? p.elements : [];
5332
+ if (elements.length === 0 && typeof p.content === "string" && p.content) {
5333
+ elements = parseMarkdown(p.content);
5334
+ }
5335
+ if (elements.length === 0) return null;
5336
+ return h("div", { className }, renderElements(elements, ctx));
5337
+ }
5338
+ const content = typeof p.content === "string" ? p.content : "";
5339
+ if (!content) return null;
5340
+ return h("div", { className }, content);
5341
+ }
5322
5342
  function registerBuiltins() {
5323
5343
  if (registered) return;
5324
5344
  registered = true;
@@ -5337,8 +5357,6 @@ function registerBuiltins() {
5337
5357
  const p = el.property || {};
5338
5358
  const tplKey = p.template || "default";
5339
5359
  const tpl = HEADER_TEMPLATE[tplKey] || HEADER_TEMPLATE.default;
5340
- const title = p.title?.property?.content ?? "";
5341
- const subtitle = p.subtitle?.property?.content ?? "";
5342
5360
  const tags = p.text_tag_list || p.textTagList;
5343
5361
  const tagVNodes = Array.isArray(tags) && tags.length ? renderElements(tags, ctx) : [];
5344
5362
  const iconRaw = p.udIcon || p.icon;
@@ -5350,14 +5368,16 @@ function registerBuiltins() {
5350
5368
  const inner = renderIcon(iconEl, ctx);
5351
5369
  if (inner) iconVNode = h("div", { className: `${CLS}-header__icon` }, inner);
5352
5370
  }
5371
+ const titleVNode = renderHeaderTextLeaf(p.title, ctx, `${CLS}-header__text-title`) ?? h("div", { className: `${CLS}-header__text-title` });
5372
+ const subtitleVNode = renderHeaderTextLeaf(p.subtitle, ctx, `${CLS}-header__text-subtitle`);
5353
5373
  const textChildren = [
5354
5374
  h(
5355
5375
  "div",
5356
5376
  { className: `${CLS}-header__text-title-wrapper` },
5357
- h("div", { className: `${CLS}-header__text-title` }, String(title)),
5377
+ titleVNode,
5358
5378
  tagVNodes.length ? h("div", { className: `${CLS}-header__tags` }, tagVNodes) : null
5359
5379
  ),
5360
- subtitle ? h("div", { className: `${CLS}-header__text-subtitle` }, String(subtitle)) : null
5380
+ subtitleVNode
5361
5381
  ];
5362
5382
  return h(
5363
5383
  "div",
@@ -5493,15 +5513,13 @@ function registerBuiltins() {
5493
5513
  const vGap = p.verticalSpacingValue?.value ?? p.vertical_spacing;
5494
5514
  style.rowGap = (vGap != null ? spacingToPx(vGap) : 8) + "px";
5495
5515
  const bg = bgStyleToColor(p.backgroundStyle ?? p.background_style);
5496
- if (bg) {
5497
- style.background = bg;
5498
- style.borderRadius = "6px";
5499
- }
5516
+ if (bg) style.background = bg;
5500
5517
  const pad = boxToStyle(p.padding);
5501
5518
  if (pad) style.padding = pad;
5502
5519
  const mg = boxToStyle(p.margin);
5503
5520
  if (mg) style.margin = mg;
5504
- return h("div", { className: `${CLS}-column`, style }, renderElements(p.elements, ctx));
5521
+ const cls = `${CLS}-column` + (bg ? ` ${CLS}-column--bg` : "");
5522
+ return h("div", { className: cls, style }, renderElements(p.elements, ctx));
5505
5523
  });
5506
5524
  registerComponent("img", (el, ctx) => {
5507
5525
  const p = el.property || {};
package/dist/index.js CHANGED
@@ -1139,6 +1139,9 @@ var BASE_STYLES_CSS = `/**
1139
1139
  /* ---- \u5E03\u5C40\uFF1Acolumn_set / column ---- */
1140
1140
  .universal-card-column-set { display: flex; }
1141
1141
  .universal-card-column { box-sizing: border-box; overflow-wrap: anywhere; }
1142
+ /* \u771F\u673A\uFF1A\u6709\u80CC\u666F\u624D\u6302 --bg\u3002column_set \u989D\u5916 4px \u5185\u8FB9\u8DDD\uFF1Bcolumn \u53EA\u5706\u89D2\u3001\u4E0D\u52A0\u9ED8\u8BA4 padding\u3002 */
1143
+ .universal-card-column-set--bg { padding: 4px; border-radius: 6px; }
1144
+ .universal-card-column--bg { border-radius: 6px; }
1142
1145
  /* \u5217\u5185\u7EB5\u5411\u95F4\u8DDD\u552F\u4E00\u6765\u6E90\u662F column \u7EC4\u4EF6\u8F93\u51FA\u7684 flex row-gap\uFF08\u9ED8\u8BA4 8px\uFF0C\u53EF\u88AB vertical_spacing \u8986\u76D6\uFF09\u3002
1143
1146
  \u8FD9\u91CC\u4E0D\u518D\u7ED9\u76F8\u90BB\u5B50\u5143\u7D20\u8BBE margin-top\u2014\u2014\u5426\u5219\u4E0E row-gap \u53E0\u52A0\uFF0C\u95F4\u8DDD\u7FFB\u500D\u3002 */
1144
1147
 
@@ -5318,6 +5321,23 @@ function resolveChartBoxStyle(p, spec) {
5318
5321
  else style.aspectRatio = "16 / 9";
5319
5322
  return style;
5320
5323
  }
5324
+ function renderHeaderTextLeaf(node, ctx, className) {
5325
+ if (!node) return null;
5326
+ const tag = node.tag;
5327
+ const p = node.property || {};
5328
+ const isMd = tag === "markdown" || tag === "lark_md";
5329
+ if (isMd) {
5330
+ let elements = Array.isArray(p.elements) ? p.elements : [];
5331
+ if (elements.length === 0 && typeof p.content === "string" && p.content) {
5332
+ elements = parseMarkdown(p.content);
5333
+ }
5334
+ if (elements.length === 0) return null;
5335
+ return h("div", { className }, renderElements(elements, ctx));
5336
+ }
5337
+ const content = typeof p.content === "string" ? p.content : "";
5338
+ if (!content) return null;
5339
+ return h("div", { className }, content);
5340
+ }
5321
5341
  function registerBuiltins() {
5322
5342
  if (registered) return;
5323
5343
  registered = true;
@@ -5336,8 +5356,6 @@ function registerBuiltins() {
5336
5356
  const p = el.property || {};
5337
5357
  const tplKey = p.template || "default";
5338
5358
  const tpl = HEADER_TEMPLATE[tplKey] || HEADER_TEMPLATE.default;
5339
- const title = p.title?.property?.content ?? "";
5340
- const subtitle = p.subtitle?.property?.content ?? "";
5341
5359
  const tags = p.text_tag_list || p.textTagList;
5342
5360
  const tagVNodes = Array.isArray(tags) && tags.length ? renderElements(tags, ctx) : [];
5343
5361
  const iconRaw = p.udIcon || p.icon;
@@ -5349,14 +5367,16 @@ function registerBuiltins() {
5349
5367
  const inner = renderIcon(iconEl, ctx);
5350
5368
  if (inner) iconVNode = h("div", { className: `${CLS}-header__icon` }, inner);
5351
5369
  }
5370
+ const titleVNode = renderHeaderTextLeaf(p.title, ctx, `${CLS}-header__text-title`) ?? h("div", { className: `${CLS}-header__text-title` });
5371
+ const subtitleVNode = renderHeaderTextLeaf(p.subtitle, ctx, `${CLS}-header__text-subtitle`);
5352
5372
  const textChildren = [
5353
5373
  h(
5354
5374
  "div",
5355
5375
  { className: `${CLS}-header__text-title-wrapper` },
5356
- h("div", { className: `${CLS}-header__text-title` }, String(title)),
5376
+ titleVNode,
5357
5377
  tagVNodes.length ? h("div", { className: `${CLS}-header__tags` }, tagVNodes) : null
5358
5378
  ),
5359
- subtitle ? h("div", { className: `${CLS}-header__text-subtitle` }, String(subtitle)) : null
5379
+ subtitleVNode
5360
5380
  ];
5361
5381
  return h(
5362
5382
  "div",
@@ -5492,15 +5512,13 @@ function registerBuiltins() {
5492
5512
  const vGap = p.verticalSpacingValue?.value ?? p.vertical_spacing;
5493
5513
  style.rowGap = (vGap != null ? spacingToPx(vGap) : 8) + "px";
5494
5514
  const bg = bgStyleToColor(p.backgroundStyle ?? p.background_style);
5495
- if (bg) {
5496
- style.background = bg;
5497
- style.borderRadius = "6px";
5498
- }
5515
+ if (bg) style.background = bg;
5499
5516
  const pad = boxToStyle(p.padding);
5500
5517
  if (pad) style.padding = pad;
5501
5518
  const mg = boxToStyle(p.margin);
5502
5519
  if (mg) style.margin = mg;
5503
- return h("div", { className: `${CLS}-column`, style }, renderElements(p.elements, ctx));
5520
+ const cls = `${CLS}-column` + (bg ? ` ${CLS}-column--bg` : "");
5521
+ return h("div", { className: cls, style }, renderElements(p.elements, ctx));
5504
5522
  });
5505
5523
  registerComponent("img", (el, ctx) => {
5506
5524
  const p = el.property || {};
package/dist/styles.css CHANGED
@@ -324,6 +324,9 @@
324
324
  /* ---- 布局:column_set / column ---- */
325
325
  .universal-card-column-set { display: flex; }
326
326
  .universal-card-column { box-sizing: border-box; overflow-wrap: anywhere; }
327
+ /* 真机:有背景才挂 --bg。column_set 额外 4px 内边距;column 只圆角、不加默认 padding。 */
328
+ .universal-card-column-set--bg { padding: 4px; border-radius: 6px; }
329
+ .universal-card-column--bg { border-radius: 6px; }
327
330
  /* 列内纵向间距唯一来源是 column 组件输出的 flex row-gap(默认 8px,可被 vertical_spacing 覆盖)。
328
331
  这里不再给相邻子元素设 margin-top——否则与 row-gap 叠加,间距翻倍。 */
329
332
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-feishu-card/renderer",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "零框架依赖的飞书卡片渲染引擎:Web / DOM / SSR,输入 RAW 或公开 DSL,输出真实 DOM 或 HTML 字符串",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -28,7 +28,7 @@
28
28
  "./dist/*.cjs"
29
29
  ],
30
30
  "dependencies": {
31
- "@open-feishu-card/adapter": "0.3.0"
31
+ "@open-feishu-card/adapter": "0.3.1"
32
32
  },
33
33
  "devDependencies": {
34
34
  "tsup": "^8.3.5",