@open-feishu-card/renderer 0.2.5 → 0.2.7

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
@@ -5322,6 +5322,23 @@ function resolveChartBoxStyle(p, spec) {
5322
5322
  else style.aspectRatio = "16 / 9";
5323
5323
  return style;
5324
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
+ }
5325
5342
  function registerBuiltins() {
5326
5343
  if (registered) return;
5327
5344
  registered = true;
@@ -5340,8 +5357,6 @@ function registerBuiltins() {
5340
5357
  const p = el.property || {};
5341
5358
  const tplKey = p.template || "default";
5342
5359
  const tpl = HEADER_TEMPLATE[tplKey] || HEADER_TEMPLATE.default;
5343
- const title = p.title?.property?.content ?? "";
5344
- const subtitle = p.subtitle?.property?.content ?? "";
5345
5360
  const tags = p.text_tag_list || p.textTagList;
5346
5361
  const tagVNodes = Array.isArray(tags) && tags.length ? renderElements(tags, ctx) : [];
5347
5362
  const iconRaw = p.udIcon || p.icon;
@@ -5353,14 +5368,16 @@ function registerBuiltins() {
5353
5368
  const inner = renderIcon(iconEl, ctx);
5354
5369
  if (inner) iconVNode = h("div", { className: `${CLS}-header__icon` }, inner);
5355
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`);
5356
5373
  const textChildren = [
5357
5374
  h(
5358
5375
  "div",
5359
5376
  { className: `${CLS}-header__text-title-wrapper` },
5360
- h("div", { className: `${CLS}-header__text-title` }, String(title)),
5377
+ titleVNode,
5361
5378
  tagVNodes.length ? h("div", { className: `${CLS}-header__tags` }, tagVNodes) : null
5362
5379
  ),
5363
- subtitle ? h("div", { className: `${CLS}-header__text-subtitle` }, String(subtitle)) : null
5380
+ subtitleVNode
5364
5381
  ];
5365
5382
  return h(
5366
5383
  "div",
package/dist/index.js CHANGED
@@ -5321,6 +5321,23 @@ function resolveChartBoxStyle(p, spec) {
5321
5321
  else style.aspectRatio = "16 / 9";
5322
5322
  return style;
5323
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
+ }
5324
5341
  function registerBuiltins() {
5325
5342
  if (registered) return;
5326
5343
  registered = true;
@@ -5339,8 +5356,6 @@ function registerBuiltins() {
5339
5356
  const p = el.property || {};
5340
5357
  const tplKey = p.template || "default";
5341
5358
  const tpl = HEADER_TEMPLATE[tplKey] || HEADER_TEMPLATE.default;
5342
- const title = p.title?.property?.content ?? "";
5343
- const subtitle = p.subtitle?.property?.content ?? "";
5344
5359
  const tags = p.text_tag_list || p.textTagList;
5345
5360
  const tagVNodes = Array.isArray(tags) && tags.length ? renderElements(tags, ctx) : [];
5346
5361
  const iconRaw = p.udIcon || p.icon;
@@ -5352,14 +5367,16 @@ function registerBuiltins() {
5352
5367
  const inner = renderIcon(iconEl, ctx);
5353
5368
  if (inner) iconVNode = h("div", { className: `${CLS}-header__icon` }, inner);
5354
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`);
5355
5372
  const textChildren = [
5356
5373
  h(
5357
5374
  "div",
5358
5375
  { className: `${CLS}-header__text-title-wrapper` },
5359
- h("div", { className: `${CLS}-header__text-title` }, String(title)),
5376
+ titleVNode,
5360
5377
  tagVNodes.length ? h("div", { className: `${CLS}-header__tags` }, tagVNodes) : null
5361
5378
  ),
5362
- subtitle ? h("div", { className: `${CLS}-header__text-subtitle` }, String(subtitle)) : null
5379
+ subtitleVNode
5363
5380
  ];
5364
5381
  return h(
5365
5382
  "div",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-feishu-card/renderer",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
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.2"
32
32
  },
33
33
  "devDependencies": {
34
34
  "tsup": "^8.3.5",