@open-feishu-card/renderer 0.1.1 → 0.2.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/all.css +410 -5
- package/dist/index.cjs +1478 -619
- package/dist/index.d.cts +119 -11
- package/dist/index.d.ts +119 -11
- package/dist/index.js +1472 -620
- package/dist/styles.css +410 -5
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -91,6 +91,25 @@ interface ElementProperty {
|
|
|
91
91
|
scaleType?: string;
|
|
92
92
|
mode?: string;
|
|
93
93
|
corner_radius?: number | string;
|
|
94
|
+
/** 媒体文件 key(视频/音频) */
|
|
95
|
+
fileID?: string;
|
|
96
|
+
file_key?: string;
|
|
97
|
+
/** 视频封面图 key / 局部 imageID */
|
|
98
|
+
coverImageID?: string;
|
|
99
|
+
image_key?: string;
|
|
100
|
+
cover_image_key?: string;
|
|
101
|
+
/** 是否显示时长(视频角标 / 音频时间) */
|
|
102
|
+
showTime?: boolean;
|
|
103
|
+
show_time?: boolean;
|
|
104
|
+
/** 视频是否允许下载(透传,预览期仅影响 controlslist) */
|
|
105
|
+
enableDownload?: boolean;
|
|
106
|
+
enable_download?: boolean;
|
|
107
|
+
/** 音频实例 id(卡片更新时保持播放状态) */
|
|
108
|
+
audioID?: string;
|
|
109
|
+
audio_id?: string;
|
|
110
|
+
/** 是否显示进度条(音频) */
|
|
111
|
+
showProgressBar?: boolean;
|
|
112
|
+
show_progress_bar?: boolean;
|
|
94
113
|
type?: string;
|
|
95
114
|
text?: CardElement;
|
|
96
115
|
disabled?: boolean;
|
|
@@ -263,6 +282,13 @@ interface RenderOptions {
|
|
|
263
282
|
resolveImage?: (property: ElementProperty) => string | null | undefined;
|
|
264
283
|
/** 图片地址前缀:最终 src = imageBaseURL + imageID */
|
|
265
284
|
imageBaseURL?: string;
|
|
285
|
+
/**
|
|
286
|
+
* 自定义音视频地址解析:返回最终可播放 src。
|
|
287
|
+
* 真机走鉴权下载;同步渲染无 token 时需 caller 注入,否则 video/audio 只出壳/封面。
|
|
288
|
+
*/
|
|
289
|
+
resolveMedia?: (property: ElementProperty, kind: 'video' | 'audio') => string | null | undefined;
|
|
290
|
+
/** 音视频地址前缀:最终 src = mediaBaseURL + fileID */
|
|
291
|
+
mediaBaseURL?: string;
|
|
266
292
|
/**
|
|
267
293
|
* 人员表(open_id -> { content 姓名, avatar_key 头像 })。
|
|
268
294
|
* person_v1 / person_list 元素只带 ID,姓名/头像在此反查。
|
|
@@ -281,8 +307,9 @@ interface RenderOptions {
|
|
|
281
307
|
resolvePersonAvatar?: (person: PersonInfo) => string | null | undefined;
|
|
282
308
|
}
|
|
283
309
|
/**
|
|
284
|
-
* 人员信息:person_v1 / person_list 元素只带 ID,姓名与头像 key 在这里。
|
|
285
|
-
* 取自飞书消息 content 的 json_attachment.persons(按 open_id「ou_
|
|
310
|
+
* 人员信息:person_v1 / person_list / at 元素只带 ID,姓名与头像 key 在这里。
|
|
311
|
+
* 取自飞书消息 content 的 json_attachment.persons(按 open_id「ou_...」索引);
|
|
312
|
+
* fetchCardMessage 还会把信封 mentions 与 at_users 合并进来(含 @_user_N 别名键)。
|
|
286
313
|
* avatar_key 是公开可访问的头像图 key(无需鉴权,见 PERSON_AVATAR_BASE)。
|
|
287
314
|
*/
|
|
288
315
|
interface PersonInfo {
|
|
@@ -293,10 +320,42 @@ interface PersonInfo {
|
|
|
293
320
|
/** 头像图 key(形如 v3_00te_...),拼 avatarBaseURL 取图 */
|
|
294
321
|
avatar_key?: string;
|
|
295
322
|
}
|
|
323
|
+
/**
|
|
324
|
+
* 消息信封上的 @ 提及(data.items[0].mentions),不在 body.content 内。
|
|
325
|
+
* 带 `user_id_type=open_id` 拉取时 id 为 open_id(ou_...)。
|
|
326
|
+
*/
|
|
327
|
+
interface MessageMention {
|
|
328
|
+
/** 用户 ID(open_id / user_id,取决于请求的 user_id_type) */
|
|
329
|
+
id: string;
|
|
330
|
+
id_type?: string;
|
|
331
|
+
/** 提及占位键,如 "@_user_1"(部分 RAW at.userID 用此键) */
|
|
332
|
+
key?: string;
|
|
333
|
+
/** 显示名 */
|
|
334
|
+
name?: string;
|
|
335
|
+
tenant_key?: string;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* json_attachment.at_users 单条:与信封 mentions 互补,供 @ 渲染补全姓名。
|
|
339
|
+
* key / mention_key 形如 "@_user_1"。
|
|
340
|
+
*/
|
|
341
|
+
interface AtUserInfo {
|
|
342
|
+
content?: string;
|
|
343
|
+
name?: string;
|
|
344
|
+
person_id?: string;
|
|
345
|
+
id?: string;
|
|
346
|
+
open_id?: string;
|
|
347
|
+
key?: string;
|
|
348
|
+
mention_key?: string;
|
|
349
|
+
avatar_key?: string;
|
|
350
|
+
}
|
|
296
351
|
/**
|
|
297
352
|
* 消息附件表:把卡片里 img 元素的局部序号(property.imageID,如 "19")
|
|
298
353
|
* 映射到飞书图床真实 key(origin_key,形如 img_v3_...)。
|
|
299
354
|
* 取自飞书消息 content 的 json_attachment 字段。
|
|
355
|
+
*
|
|
356
|
+
* - persons:人员姓名/头像(open_id → PersonInfo)
|
|
357
|
+
* - at_users:content 内的 @ 用户表(仍在 attachment;信封 mentions 见 MessageMention)
|
|
358
|
+
* - images / videos / audios:媒体资源索引
|
|
300
359
|
*/
|
|
301
360
|
interface JsonAttachment {
|
|
302
361
|
images?: Record<string, {
|
|
@@ -304,6 +363,20 @@ interface JsonAttachment {
|
|
|
304
363
|
}>;
|
|
305
364
|
/** 人员表:open_id(ou_...) -> { content 姓名, avatar_key 头像 } */
|
|
306
365
|
persons?: Record<string, PersonInfo>;
|
|
366
|
+
/**
|
|
367
|
+
* @ 提及用户表(仍在 body.content.json_attachment 内)。
|
|
368
|
+
* 可为 open_id / @_user_N 索引的对象,或数组。
|
|
369
|
+
* fetchCardMessage 会把它与信封 mentions 一并合并进 persons。
|
|
370
|
+
*/
|
|
371
|
+
at_users?: Record<string, AtUserInfo> | AtUserInfo[];
|
|
372
|
+
/** 视频附件表:fileID -> { key }(真机仅索引,可播放 URL 仍需鉴权下载) */
|
|
373
|
+
videos?: Record<string, {
|
|
374
|
+
key?: string;
|
|
375
|
+
}>;
|
|
376
|
+
/** 音频附件表:fileID -> { key } */
|
|
377
|
+
audios?: Record<string, {
|
|
378
|
+
key?: string;
|
|
379
|
+
}>;
|
|
307
380
|
}
|
|
308
381
|
/**
|
|
309
382
|
* 异步渲染选项:在同步 RenderOptions 基础上,支持用 access token 自动拉取图片。
|
|
@@ -397,7 +470,7 @@ declare function h(tag: string, props?: VNodeProps | null, ...children: Array<VN
|
|
|
397
470
|
/**
|
|
398
471
|
* 飞书 Universal Card header 高光纹理(半透明白 PNG,1200x280)。
|
|
399
472
|
* 从网页版飞书原版资源提取并内联为 base64 data URI,使本包零外部资源依赖。
|
|
400
|
-
* - HEADER_BG_LIGHT:
|
|
473
|
+
* - HEADER_BG_LIGHT: 亮色主题(飞书 aac0718d1d.png,通用强高光;灰 header 亦用此图以贴近真机观感)
|
|
401
474
|
* - HEADER_BG_DARK : 暗色主题 (原 c16649b557.png)
|
|
402
475
|
*/
|
|
403
476
|
declare const HEADER_BG_LIGHT: string;
|
|
@@ -469,6 +542,29 @@ declare function feishuChartHydrateScript(opts?: {
|
|
|
469
542
|
*/
|
|
470
543
|
declare function feishuChartHydrateJs(vchartGlobal?: string): string;
|
|
471
544
|
|
|
545
|
+
/**
|
|
546
|
+
* 音频(audio)运行期水合:绑定播放/暂停、进度条与时长,切换播放钮图标。
|
|
547
|
+
*
|
|
548
|
+
* 渲染期只输出静态壳 + 隐藏 <audio>;真机交互靠本模块在浏览器里接线。
|
|
549
|
+
* - 浏览器:renderCard 后自动 hydrate;也可手动 hydrateFeishuAudios(root)
|
|
550
|
+
* - SSR:页面塞入 feishuAudioHydrateScript()
|
|
551
|
+
*/
|
|
552
|
+
/** 已水合标记(避免重复绑事件) */
|
|
553
|
+
declare const AUDIO_HYDRATED_ATTR = "data-feishu-audio-hydrated";
|
|
554
|
+
/** 对齐真机 PlayRoundFilled(顶层 audio 默认) */
|
|
555
|
+
declare const AUDIO_PLAY_ICON_SVG: string;
|
|
556
|
+
/** 对齐飞书网页版 PauseRoundFilled(圆底 + 圆角双竖条) */
|
|
557
|
+
declare const AUDIO_PAUSE_ICON_SVG: string;
|
|
558
|
+
/**
|
|
559
|
+
* 扫描 root 下音频壳并绑定交互(幂等)。
|
|
560
|
+
* @returns 成功水合的数量
|
|
561
|
+
*/
|
|
562
|
+
declare function hydrateFeishuAudios(root?: ParentNode | null): number;
|
|
563
|
+
/** SSR:返回自执行 <script>,DOM ready 后自动水合全部音频 */
|
|
564
|
+
declare function feishuAudioHydrateScript(): string;
|
|
565
|
+
/** SSR:hydrate 脚本正文(不含 <script> 包裹) */
|
|
566
|
+
declare function feishuAudioHydrateJs(): string;
|
|
567
|
+
|
|
472
568
|
/**
|
|
473
569
|
* 渲染常量。颜色/字号等规则均从网页版飞书引擎 (be8b738f.js) 与
|
|
474
570
|
* edbaaa5b.css 中逆向抽取,详见 README 的「渲染规则」一节。
|
|
@@ -489,18 +585,30 @@ declare const CHART_PALETTE: string[];
|
|
|
489
585
|
* 预取成 data URI,再通过生成好的 resolveImage 钩子喂进去。
|
|
490
586
|
*/
|
|
491
587
|
|
|
588
|
+
/** fetchCardMessage 的解包结果 */
|
|
589
|
+
interface FetchedCardMessage {
|
|
590
|
+
json_card: JsonCard;
|
|
591
|
+
json_attachment?: JsonAttachment;
|
|
592
|
+
messageId: string;
|
|
593
|
+
/** 消息信封上的 @ 列表(data.items[0].mentions,非 body.content 内) */
|
|
594
|
+
mentions?: MessageMention[];
|
|
595
|
+
}
|
|
492
596
|
/** ArrayBuffer -> base64(Node 用 Buffer,浏览器用 btoa;保持零依赖、双端可用) */
|
|
493
597
|
declare function arrayBufferToBase64(buf: ArrayBuffer): string;
|
|
494
598
|
/**
|
|
495
|
-
*
|
|
496
|
-
*
|
|
599
|
+
* 把信封 mentions 与 json_attachment.at_users 合并进 persons,
|
|
600
|
+
* 供 at / person_v1 直接查姓名(无需业务侧再传 options.persons)。
|
|
601
|
+
* 若有 @_user_N 之类的 key/mention_key,同时写一份别名键。
|
|
602
|
+
*/
|
|
603
|
+
declare function mergeMentionsIntoPersons(attachment: JsonAttachment | undefined, mentions?: MessageMention[]): JsonAttachment | undefined;
|
|
604
|
+
/**
|
|
605
|
+
* 拉取单条卡片消息并解包成 { json_card, json_attachment, messageId, mentions }。
|
|
606
|
+
* 必须带 card_msg_content_type=raw_card_content,否则拿不到 json_card;
|
|
607
|
+
* 同时带 user_id_type=open_id,使信封 mentions[].id 为 open_id。
|
|
497
608
|
* 注意接口里的 json_card 是被字符串化的 JSON(双重编码),需再解一层。
|
|
609
|
+
* mentions 来自消息信封(data.items[0].mentions),会与 at_users 一并合并进 persons。
|
|
498
610
|
*/
|
|
499
|
-
declare function fetchCardMessage(messageId: string, options: AsyncRenderOptions): Promise<
|
|
500
|
-
json_card: JsonCard;
|
|
501
|
-
json_attachment?: JsonAttachment;
|
|
502
|
-
messageId: string;
|
|
503
|
-
}>;
|
|
611
|
+
declare function fetchCardMessage(messageId: string, options: AsyncRenderOptions): Promise<FetchedCardMessage>;
|
|
504
612
|
/**
|
|
505
613
|
* 拉取单张图片二进制,转成 base64 data URI。
|
|
506
614
|
* 端点:GET /messages/{messageId}/resources/{origin_key}?type=image
|
|
@@ -543,4 +651,4 @@ declare function renderDslToString(dsl: unknown, options?: RenderOptions): strin
|
|
|
543
651
|
/** 输入公开 DSL,渲染为真实 DOM 节点(浏览器)。= renderCard(dslToRaw(dsl)) */
|
|
544
652
|
declare function renderDsl(dsl: unknown, options?: RenderOptions): Node;
|
|
545
653
|
|
|
546
|
-
export { ALL_CSS, type AsyncRenderOptions, type BoxSpacing, CHART_HYDRATED_ATTR, CHART_PALETTE, CHART_SPEC_ATTR, type CardElement, type CardInput, type CardMessageInput, type ComponentFn, EMOJI_KEY_TO_NAME, EMOJI_SPRITE_CSS, type ElementProperty, HEADER_BG_DARK, HEADER_BG_LIGHT, type HeaderTemplate, ICON_CODEPOINTS, ICON_FONT_CSS, type JsonAttachment, type JsonCard, type LinkURL, type ListItem, type NamedColor, type PersonInfo, type RenderContext, type RenderOptions, type SizeName, type TableColumn, type TableHeaderStyle, type TextAlign, type TextAttribute, type TextStyle, type VNode, type VNodeChild, type VNodeProps, arrayBufferToBase64, feishuCardStyleTag, feishuChartHydrateJs, feishuChartHydrateScript, fetchCardMessage, fetchImageDataUri, getComponent, h, hydrateFeishuCharts, parseInline, parseMarkdown, prefetchImages, registerComponent, renderCard, renderCardAsync, renderCardToString, renderCardToStringAsync, renderDsl, renderDslToString, renderFeishuChart };
|
|
654
|
+
export { ALL_CSS, AUDIO_HYDRATED_ATTR, AUDIO_PAUSE_ICON_SVG, AUDIO_PLAY_ICON_SVG, type AsyncRenderOptions, type AtUserInfo, type BoxSpacing, CHART_HYDRATED_ATTR, CHART_PALETTE, CHART_SPEC_ATTR, type CardElement, type CardInput, type CardMessageInput, type ComponentFn, EMOJI_KEY_TO_NAME, EMOJI_SPRITE_CSS, type ElementProperty, type FetchedCardMessage, HEADER_BG_DARK, HEADER_BG_LIGHT, type HeaderTemplate, ICON_CODEPOINTS, ICON_FONT_CSS, type JsonAttachment, type JsonCard, type LinkURL, type ListItem, type MessageMention, type NamedColor, type PersonInfo, type RenderContext, type RenderOptions, type SizeName, type TableColumn, type TableHeaderStyle, type TextAlign, type TextAttribute, type TextStyle, type VNode, type VNodeChild, type VNodeProps, arrayBufferToBase64, feishuAudioHydrateJs, feishuAudioHydrateScript, feishuCardStyleTag, feishuChartHydrateJs, feishuChartHydrateScript, fetchCardMessage, fetchImageDataUri, getComponent, h, hydrateFeishuAudios, hydrateFeishuCharts, mergeMentionsIntoPersons, parseInline, parseMarkdown, prefetchImages, registerComponent, renderCard, renderCardAsync, renderCardToString, renderCardToStringAsync, renderDsl, renderDslToString, renderFeishuChart };
|
package/dist/index.d.ts
CHANGED
|
@@ -91,6 +91,25 @@ interface ElementProperty {
|
|
|
91
91
|
scaleType?: string;
|
|
92
92
|
mode?: string;
|
|
93
93
|
corner_radius?: number | string;
|
|
94
|
+
/** 媒体文件 key(视频/音频) */
|
|
95
|
+
fileID?: string;
|
|
96
|
+
file_key?: string;
|
|
97
|
+
/** 视频封面图 key / 局部 imageID */
|
|
98
|
+
coverImageID?: string;
|
|
99
|
+
image_key?: string;
|
|
100
|
+
cover_image_key?: string;
|
|
101
|
+
/** 是否显示时长(视频角标 / 音频时间) */
|
|
102
|
+
showTime?: boolean;
|
|
103
|
+
show_time?: boolean;
|
|
104
|
+
/** 视频是否允许下载(透传,预览期仅影响 controlslist) */
|
|
105
|
+
enableDownload?: boolean;
|
|
106
|
+
enable_download?: boolean;
|
|
107
|
+
/** 音频实例 id(卡片更新时保持播放状态) */
|
|
108
|
+
audioID?: string;
|
|
109
|
+
audio_id?: string;
|
|
110
|
+
/** 是否显示进度条(音频) */
|
|
111
|
+
showProgressBar?: boolean;
|
|
112
|
+
show_progress_bar?: boolean;
|
|
94
113
|
type?: string;
|
|
95
114
|
text?: CardElement;
|
|
96
115
|
disabled?: boolean;
|
|
@@ -263,6 +282,13 @@ interface RenderOptions {
|
|
|
263
282
|
resolveImage?: (property: ElementProperty) => string | null | undefined;
|
|
264
283
|
/** 图片地址前缀:最终 src = imageBaseURL + imageID */
|
|
265
284
|
imageBaseURL?: string;
|
|
285
|
+
/**
|
|
286
|
+
* 自定义音视频地址解析:返回最终可播放 src。
|
|
287
|
+
* 真机走鉴权下载;同步渲染无 token 时需 caller 注入,否则 video/audio 只出壳/封面。
|
|
288
|
+
*/
|
|
289
|
+
resolveMedia?: (property: ElementProperty, kind: 'video' | 'audio') => string | null | undefined;
|
|
290
|
+
/** 音视频地址前缀:最终 src = mediaBaseURL + fileID */
|
|
291
|
+
mediaBaseURL?: string;
|
|
266
292
|
/**
|
|
267
293
|
* 人员表(open_id -> { content 姓名, avatar_key 头像 })。
|
|
268
294
|
* person_v1 / person_list 元素只带 ID,姓名/头像在此反查。
|
|
@@ -281,8 +307,9 @@ interface RenderOptions {
|
|
|
281
307
|
resolvePersonAvatar?: (person: PersonInfo) => string | null | undefined;
|
|
282
308
|
}
|
|
283
309
|
/**
|
|
284
|
-
* 人员信息:person_v1 / person_list 元素只带 ID,姓名与头像 key 在这里。
|
|
285
|
-
* 取自飞书消息 content 的 json_attachment.persons(按 open_id「ou_
|
|
310
|
+
* 人员信息:person_v1 / person_list / at 元素只带 ID,姓名与头像 key 在这里。
|
|
311
|
+
* 取自飞书消息 content 的 json_attachment.persons(按 open_id「ou_...」索引);
|
|
312
|
+
* fetchCardMessage 还会把信封 mentions 与 at_users 合并进来(含 @_user_N 别名键)。
|
|
286
313
|
* avatar_key 是公开可访问的头像图 key(无需鉴权,见 PERSON_AVATAR_BASE)。
|
|
287
314
|
*/
|
|
288
315
|
interface PersonInfo {
|
|
@@ -293,10 +320,42 @@ interface PersonInfo {
|
|
|
293
320
|
/** 头像图 key(形如 v3_00te_...),拼 avatarBaseURL 取图 */
|
|
294
321
|
avatar_key?: string;
|
|
295
322
|
}
|
|
323
|
+
/**
|
|
324
|
+
* 消息信封上的 @ 提及(data.items[0].mentions),不在 body.content 内。
|
|
325
|
+
* 带 `user_id_type=open_id` 拉取时 id 为 open_id(ou_...)。
|
|
326
|
+
*/
|
|
327
|
+
interface MessageMention {
|
|
328
|
+
/** 用户 ID(open_id / user_id,取决于请求的 user_id_type) */
|
|
329
|
+
id: string;
|
|
330
|
+
id_type?: string;
|
|
331
|
+
/** 提及占位键,如 "@_user_1"(部分 RAW at.userID 用此键) */
|
|
332
|
+
key?: string;
|
|
333
|
+
/** 显示名 */
|
|
334
|
+
name?: string;
|
|
335
|
+
tenant_key?: string;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* json_attachment.at_users 单条:与信封 mentions 互补,供 @ 渲染补全姓名。
|
|
339
|
+
* key / mention_key 形如 "@_user_1"。
|
|
340
|
+
*/
|
|
341
|
+
interface AtUserInfo {
|
|
342
|
+
content?: string;
|
|
343
|
+
name?: string;
|
|
344
|
+
person_id?: string;
|
|
345
|
+
id?: string;
|
|
346
|
+
open_id?: string;
|
|
347
|
+
key?: string;
|
|
348
|
+
mention_key?: string;
|
|
349
|
+
avatar_key?: string;
|
|
350
|
+
}
|
|
296
351
|
/**
|
|
297
352
|
* 消息附件表:把卡片里 img 元素的局部序号(property.imageID,如 "19")
|
|
298
353
|
* 映射到飞书图床真实 key(origin_key,形如 img_v3_...)。
|
|
299
354
|
* 取自飞书消息 content 的 json_attachment 字段。
|
|
355
|
+
*
|
|
356
|
+
* - persons:人员姓名/头像(open_id → PersonInfo)
|
|
357
|
+
* - at_users:content 内的 @ 用户表(仍在 attachment;信封 mentions 见 MessageMention)
|
|
358
|
+
* - images / videos / audios:媒体资源索引
|
|
300
359
|
*/
|
|
301
360
|
interface JsonAttachment {
|
|
302
361
|
images?: Record<string, {
|
|
@@ -304,6 +363,20 @@ interface JsonAttachment {
|
|
|
304
363
|
}>;
|
|
305
364
|
/** 人员表:open_id(ou_...) -> { content 姓名, avatar_key 头像 } */
|
|
306
365
|
persons?: Record<string, PersonInfo>;
|
|
366
|
+
/**
|
|
367
|
+
* @ 提及用户表(仍在 body.content.json_attachment 内)。
|
|
368
|
+
* 可为 open_id / @_user_N 索引的对象,或数组。
|
|
369
|
+
* fetchCardMessage 会把它与信封 mentions 一并合并进 persons。
|
|
370
|
+
*/
|
|
371
|
+
at_users?: Record<string, AtUserInfo> | AtUserInfo[];
|
|
372
|
+
/** 视频附件表:fileID -> { key }(真机仅索引,可播放 URL 仍需鉴权下载) */
|
|
373
|
+
videos?: Record<string, {
|
|
374
|
+
key?: string;
|
|
375
|
+
}>;
|
|
376
|
+
/** 音频附件表:fileID -> { key } */
|
|
377
|
+
audios?: Record<string, {
|
|
378
|
+
key?: string;
|
|
379
|
+
}>;
|
|
307
380
|
}
|
|
308
381
|
/**
|
|
309
382
|
* 异步渲染选项:在同步 RenderOptions 基础上,支持用 access token 自动拉取图片。
|
|
@@ -397,7 +470,7 @@ declare function h(tag: string, props?: VNodeProps | null, ...children: Array<VN
|
|
|
397
470
|
/**
|
|
398
471
|
* 飞书 Universal Card header 高光纹理(半透明白 PNG,1200x280)。
|
|
399
472
|
* 从网页版飞书原版资源提取并内联为 base64 data URI,使本包零外部资源依赖。
|
|
400
|
-
* - HEADER_BG_LIGHT:
|
|
473
|
+
* - HEADER_BG_LIGHT: 亮色主题(飞书 aac0718d1d.png,通用强高光;灰 header 亦用此图以贴近真机观感)
|
|
401
474
|
* - HEADER_BG_DARK : 暗色主题 (原 c16649b557.png)
|
|
402
475
|
*/
|
|
403
476
|
declare const HEADER_BG_LIGHT: string;
|
|
@@ -469,6 +542,29 @@ declare function feishuChartHydrateScript(opts?: {
|
|
|
469
542
|
*/
|
|
470
543
|
declare function feishuChartHydrateJs(vchartGlobal?: string): string;
|
|
471
544
|
|
|
545
|
+
/**
|
|
546
|
+
* 音频(audio)运行期水合:绑定播放/暂停、进度条与时长,切换播放钮图标。
|
|
547
|
+
*
|
|
548
|
+
* 渲染期只输出静态壳 + 隐藏 <audio>;真机交互靠本模块在浏览器里接线。
|
|
549
|
+
* - 浏览器:renderCard 后自动 hydrate;也可手动 hydrateFeishuAudios(root)
|
|
550
|
+
* - SSR:页面塞入 feishuAudioHydrateScript()
|
|
551
|
+
*/
|
|
552
|
+
/** 已水合标记(避免重复绑事件) */
|
|
553
|
+
declare const AUDIO_HYDRATED_ATTR = "data-feishu-audio-hydrated";
|
|
554
|
+
/** 对齐真机 PlayRoundFilled(顶层 audio 默认) */
|
|
555
|
+
declare const AUDIO_PLAY_ICON_SVG: string;
|
|
556
|
+
/** 对齐飞书网页版 PauseRoundFilled(圆底 + 圆角双竖条) */
|
|
557
|
+
declare const AUDIO_PAUSE_ICON_SVG: string;
|
|
558
|
+
/**
|
|
559
|
+
* 扫描 root 下音频壳并绑定交互(幂等)。
|
|
560
|
+
* @returns 成功水合的数量
|
|
561
|
+
*/
|
|
562
|
+
declare function hydrateFeishuAudios(root?: ParentNode | null): number;
|
|
563
|
+
/** SSR:返回自执行 <script>,DOM ready 后自动水合全部音频 */
|
|
564
|
+
declare function feishuAudioHydrateScript(): string;
|
|
565
|
+
/** SSR:hydrate 脚本正文(不含 <script> 包裹) */
|
|
566
|
+
declare function feishuAudioHydrateJs(): string;
|
|
567
|
+
|
|
472
568
|
/**
|
|
473
569
|
* 渲染常量。颜色/字号等规则均从网页版飞书引擎 (be8b738f.js) 与
|
|
474
570
|
* edbaaa5b.css 中逆向抽取,详见 README 的「渲染规则」一节。
|
|
@@ -489,18 +585,30 @@ declare const CHART_PALETTE: string[];
|
|
|
489
585
|
* 预取成 data URI,再通过生成好的 resolveImage 钩子喂进去。
|
|
490
586
|
*/
|
|
491
587
|
|
|
588
|
+
/** fetchCardMessage 的解包结果 */
|
|
589
|
+
interface FetchedCardMessage {
|
|
590
|
+
json_card: JsonCard;
|
|
591
|
+
json_attachment?: JsonAttachment;
|
|
592
|
+
messageId: string;
|
|
593
|
+
/** 消息信封上的 @ 列表(data.items[0].mentions,非 body.content 内) */
|
|
594
|
+
mentions?: MessageMention[];
|
|
595
|
+
}
|
|
492
596
|
/** ArrayBuffer -> base64(Node 用 Buffer,浏览器用 btoa;保持零依赖、双端可用) */
|
|
493
597
|
declare function arrayBufferToBase64(buf: ArrayBuffer): string;
|
|
494
598
|
/**
|
|
495
|
-
*
|
|
496
|
-
*
|
|
599
|
+
* 把信封 mentions 与 json_attachment.at_users 合并进 persons,
|
|
600
|
+
* 供 at / person_v1 直接查姓名(无需业务侧再传 options.persons)。
|
|
601
|
+
* 若有 @_user_N 之类的 key/mention_key,同时写一份别名键。
|
|
602
|
+
*/
|
|
603
|
+
declare function mergeMentionsIntoPersons(attachment: JsonAttachment | undefined, mentions?: MessageMention[]): JsonAttachment | undefined;
|
|
604
|
+
/**
|
|
605
|
+
* 拉取单条卡片消息并解包成 { json_card, json_attachment, messageId, mentions }。
|
|
606
|
+
* 必须带 card_msg_content_type=raw_card_content,否则拿不到 json_card;
|
|
607
|
+
* 同时带 user_id_type=open_id,使信封 mentions[].id 为 open_id。
|
|
497
608
|
* 注意接口里的 json_card 是被字符串化的 JSON(双重编码),需再解一层。
|
|
609
|
+
* mentions 来自消息信封(data.items[0].mentions),会与 at_users 一并合并进 persons。
|
|
498
610
|
*/
|
|
499
|
-
declare function fetchCardMessage(messageId: string, options: AsyncRenderOptions): Promise<
|
|
500
|
-
json_card: JsonCard;
|
|
501
|
-
json_attachment?: JsonAttachment;
|
|
502
|
-
messageId: string;
|
|
503
|
-
}>;
|
|
611
|
+
declare function fetchCardMessage(messageId: string, options: AsyncRenderOptions): Promise<FetchedCardMessage>;
|
|
504
612
|
/**
|
|
505
613
|
* 拉取单张图片二进制,转成 base64 data URI。
|
|
506
614
|
* 端点:GET /messages/{messageId}/resources/{origin_key}?type=image
|
|
@@ -543,4 +651,4 @@ declare function renderDslToString(dsl: unknown, options?: RenderOptions): strin
|
|
|
543
651
|
/** 输入公开 DSL,渲染为真实 DOM 节点(浏览器)。= renderCard(dslToRaw(dsl)) */
|
|
544
652
|
declare function renderDsl(dsl: unknown, options?: RenderOptions): Node;
|
|
545
653
|
|
|
546
|
-
export { ALL_CSS, type AsyncRenderOptions, type BoxSpacing, CHART_HYDRATED_ATTR, CHART_PALETTE, CHART_SPEC_ATTR, type CardElement, type CardInput, type CardMessageInput, type ComponentFn, EMOJI_KEY_TO_NAME, EMOJI_SPRITE_CSS, type ElementProperty, HEADER_BG_DARK, HEADER_BG_LIGHT, type HeaderTemplate, ICON_CODEPOINTS, ICON_FONT_CSS, type JsonAttachment, type JsonCard, type LinkURL, type ListItem, type NamedColor, type PersonInfo, type RenderContext, type RenderOptions, type SizeName, type TableColumn, type TableHeaderStyle, type TextAlign, type TextAttribute, type TextStyle, type VNode, type VNodeChild, type VNodeProps, arrayBufferToBase64, feishuCardStyleTag, feishuChartHydrateJs, feishuChartHydrateScript, fetchCardMessage, fetchImageDataUri, getComponent, h, hydrateFeishuCharts, parseInline, parseMarkdown, prefetchImages, registerComponent, renderCard, renderCardAsync, renderCardToString, renderCardToStringAsync, renderDsl, renderDslToString, renderFeishuChart };
|
|
654
|
+
export { ALL_CSS, AUDIO_HYDRATED_ATTR, AUDIO_PAUSE_ICON_SVG, AUDIO_PLAY_ICON_SVG, type AsyncRenderOptions, type AtUserInfo, type BoxSpacing, CHART_HYDRATED_ATTR, CHART_PALETTE, CHART_SPEC_ATTR, type CardElement, type CardInput, type CardMessageInput, type ComponentFn, EMOJI_KEY_TO_NAME, EMOJI_SPRITE_CSS, type ElementProperty, type FetchedCardMessage, HEADER_BG_DARK, HEADER_BG_LIGHT, type HeaderTemplate, ICON_CODEPOINTS, ICON_FONT_CSS, type JsonAttachment, type JsonCard, type LinkURL, type ListItem, type MessageMention, type NamedColor, type PersonInfo, type RenderContext, type RenderOptions, type SizeName, type TableColumn, type TableHeaderStyle, type TextAlign, type TextAttribute, type TextStyle, type VNode, type VNodeChild, type VNodeProps, arrayBufferToBase64, feishuAudioHydrateJs, feishuAudioHydrateScript, feishuCardStyleTag, feishuChartHydrateJs, feishuChartHydrateScript, fetchCardMessage, fetchImageDataUri, getComponent, h, hydrateFeishuAudios, hydrateFeishuCharts, mergeMentionsIntoPersons, parseInline, parseMarkdown, prefetchImages, registerComponent, renderCard, renderCardAsync, renderCardToString, renderCardToStringAsync, renderDsl, renderDslToString, renderFeishuChart };
|