node-karin 0.8.6 → 0.8.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/lib/core/karin.d.ts +1 -1
- package/lib/event/message.handler.js +1 -1
- package/lib/render/app.d.ts +8 -2
- package/lib/render/app.js +24 -3
- package/lib/render/base.d.ts +2 -2
- package/lib/render/base.js +1 -2
- package/lib/render/client.d.ts +1 -1
- package/lib/render/client.js +1 -1
- package/lib/render/http.d.ts +1 -1
- package/lib/render/server.d.ts +3 -19
- package/lib/render/server.js +1 -17
- package/lib/types/element.d.ts +13 -3
- package/lib/types/render.d.ts +7 -1
- package/lib/utils/segment.d.ts +3 -3
- package/package.json +1 -1
package/lib/core/karin.d.ts
CHANGED
package/lib/render/app.d.ts
CHANGED
|
@@ -31,13 +31,19 @@ declare class Renderers {
|
|
|
31
31
|
/**
|
|
32
32
|
* 调用标准渲染器
|
|
33
33
|
*/
|
|
34
|
-
render(options:
|
|
34
|
+
render<T extends KarinRenderType>(options: T, id?: string): Promise<import("../types/index.js").RenderResult<T>>;
|
|
35
35
|
/**
|
|
36
36
|
* 快速渲染
|
|
37
37
|
* @param data html路径、http地址
|
|
38
38
|
* @returns 返回图片base64或数组
|
|
39
39
|
*/
|
|
40
|
-
renderHtml(data: string): Promise<string
|
|
40
|
+
renderHtml(data: string): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* 快速分片渲染
|
|
43
|
+
* @param data html路径、http地址
|
|
44
|
+
* @param multiPage 分片高度 自动计算传true
|
|
45
|
+
*/
|
|
46
|
+
renderMultiHtml(data: string, multiPage: number | true): Promise<Array<string>>;
|
|
41
47
|
}
|
|
42
48
|
/**
|
|
43
49
|
* 渲染器管理器
|
package/lib/render/app.js
CHANGED
|
@@ -69,7 +69,13 @@ class Renderers {
|
|
|
69
69
|
*/
|
|
70
70
|
async render (options, id) {
|
|
71
71
|
const res = this.App(id)
|
|
72
|
-
|
|
72
|
+
if (typeof options.multiPage === 'number' || options.multiPage === true) {
|
|
73
|
+
const result = await res.render(options)
|
|
74
|
+
return result
|
|
75
|
+
} else {
|
|
76
|
+
const result = await res.render(options)
|
|
77
|
+
return result
|
|
78
|
+
}
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
/**
|
|
@@ -78,10 +84,25 @@ class Renderers {
|
|
|
78
84
|
* @returns 返回图片base64或数组
|
|
79
85
|
*/
|
|
80
86
|
async renderHtml (data) {
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
return this.render({
|
|
88
|
+
file: data,
|
|
89
|
+
name: 'render',
|
|
90
|
+
pageGotoParams: {
|
|
91
|
+
waitUntil: 'networkidle2',
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 快速分片渲染
|
|
98
|
+
* @param data html路径、http地址
|
|
99
|
+
* @param multiPage 分片高度 自动计算传true
|
|
100
|
+
*/
|
|
101
|
+
async renderMultiHtml (data, multiPage) {
|
|
102
|
+
return await this.render({
|
|
83
103
|
file: data,
|
|
84
104
|
name: 'render',
|
|
105
|
+
multiPage,
|
|
85
106
|
pageGotoParams: {
|
|
86
107
|
waitUntil: 'networkidle2',
|
|
87
108
|
},
|
package/lib/render/base.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import chokidar from 'chokidar';
|
|
2
|
-
import { KarinRender, KarinRenderType } from '../types/render.js';
|
|
2
|
+
import { KarinRender, KarinRenderType, RenderResult } from '../types/render.js';
|
|
3
3
|
/**
|
|
4
4
|
* 渲染器基类 所有渲染器都应该继承这个类
|
|
5
5
|
*/
|
|
@@ -26,5 +26,5 @@ export declare class RenderBase implements KarinRender {
|
|
|
26
26
|
/**
|
|
27
27
|
* 渲染标准方法
|
|
28
28
|
*/
|
|
29
|
-
render(options:
|
|
29
|
+
render<T extends KarinRenderType>(options: T): Promise<RenderResult<T>>;
|
|
30
30
|
}
|
package/lib/render/base.js
CHANGED
package/lib/render/client.d.ts
CHANGED
package/lib/render/client.js
CHANGED
package/lib/render/http.d.ts
CHANGED
package/lib/render/server.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import WebSocket from 'ws';
|
|
2
2
|
import { RenderBase } from './base.js';
|
|
3
3
|
import { IncomingMessage } from 'http';
|
|
4
|
-
import { KarinRenderType } from '../types/index.js';
|
|
4
|
+
import { KarinRenderType, RenderResult } from '../types/index.js';
|
|
5
5
|
declare class Puppeteer extends RenderBase {
|
|
6
6
|
socket: WebSocket;
|
|
7
7
|
id: any;
|
|
@@ -13,25 +13,9 @@ declare class Puppeteer extends RenderBase {
|
|
|
13
13
|
server(socket: WebSocket, request: IncomingMessage): Promise<void>;
|
|
14
14
|
/**
|
|
15
15
|
* 渲染模板
|
|
16
|
-
* @param
|
|
17
|
-
* @param {string} options.file http地址或本地文件路径
|
|
18
|
-
* @param {string} [options.name] 模板名称
|
|
19
|
-
* @param {string} [options.fileID] art-template后的文件名
|
|
20
|
-
* @param {object} [options.data] 传递给模板的数据 template.render(data)
|
|
21
|
-
* @param {'png'|'jpeg'|'webp'} [options.type] 截图类型 默认'webp'
|
|
22
|
-
* @param {number} [options.quality] 截图质量 默认90 1-100
|
|
23
|
-
* @param {boolean} options.omitBackground 是否隐藏背景 默认false
|
|
24
|
-
* @param {object} [options.setViewport] 设置视窗大小和设备像素比 默认1920*1080、1
|
|
25
|
-
* @param {number} [options.setViewport.width] 视窗宽度
|
|
26
|
-
* @param {number} [options.setViewport.height] 视窗高度
|
|
27
|
-
* @param {string} [options.setViewport.deviceScaleFactor] 设备像素比
|
|
28
|
-
* @param {number|boolean} [options.multiPage] 分页截图 传递数字则视为视窗高度 返回数组
|
|
29
|
-
* @param {object} [options.pageGotoParams] 页面goto时的参数
|
|
30
|
-
* @param {number} [options.pageGotoParams.timeout] 页面加载超时时间
|
|
31
|
-
* @param {'load'|'domcontentloaded'|'networkidle0'|'networkidle2'} [options.pageGotoParams.waitUntil] 页面加载状态
|
|
32
|
-
* @returns {Promise<string|string[]>} 返回图片base64或数组
|
|
16
|
+
* @param options 模板参数
|
|
33
17
|
*/
|
|
34
|
-
render(options:
|
|
18
|
+
render<T extends KarinRenderType>(options: T): Promise<RenderResult<T>>;
|
|
35
19
|
}
|
|
36
20
|
export declare const RenderServer: {
|
|
37
21
|
type: string;
|
package/lib/render/server.js
CHANGED
|
@@ -62,23 +62,7 @@ class Puppeteer extends RenderBase {
|
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* 渲染模板
|
|
65
|
-
* @param
|
|
66
|
-
* @param {string} options.file http地址或本地文件路径
|
|
67
|
-
* @param {string} [options.name] 模板名称
|
|
68
|
-
* @param {string} [options.fileID] art-template后的文件名
|
|
69
|
-
* @param {object} [options.data] 传递给模板的数据 template.render(data)
|
|
70
|
-
* @param {'png'|'jpeg'|'webp'} [options.type] 截图类型 默认'webp'
|
|
71
|
-
* @param {number} [options.quality] 截图质量 默认90 1-100
|
|
72
|
-
* @param {boolean} options.omitBackground 是否隐藏背景 默认false
|
|
73
|
-
* @param {object} [options.setViewport] 设置视窗大小和设备像素比 默认1920*1080、1
|
|
74
|
-
* @param {number} [options.setViewport.width] 视窗宽度
|
|
75
|
-
* @param {number} [options.setViewport.height] 视窗高度
|
|
76
|
-
* @param {string} [options.setViewport.deviceScaleFactor] 设备像素比
|
|
77
|
-
* @param {number|boolean} [options.multiPage] 分页截图 传递数字则视为视窗高度 返回数组
|
|
78
|
-
* @param {object} [options.pageGotoParams] 页面goto时的参数
|
|
79
|
-
* @param {number} [options.pageGotoParams.timeout] 页面加载超时时间
|
|
80
|
-
* @param {'load'|'domcontentloaded'|'networkidle0'|'networkidle2'} [options.pageGotoParams.waitUntil] 页面加载状态
|
|
81
|
-
* @returns {Promise<string|string[]>} 返回图片base64或数组
|
|
65
|
+
* @param options 模板参数
|
|
82
66
|
*/
|
|
83
67
|
async render (options) {
|
|
84
68
|
/** 渲染模板 */
|
package/lib/types/element.d.ts
CHANGED
|
@@ -442,7 +442,7 @@ export interface FileElement extends Element {
|
|
|
442
442
|
/**
|
|
443
443
|
* - 原生 Markdown 元素
|
|
444
444
|
*/
|
|
445
|
-
export interface
|
|
445
|
+
export interface RawMarkdownElement extends Element {
|
|
446
446
|
type: 'markdown';
|
|
447
447
|
/**
|
|
448
448
|
* - 原生markdown内容
|
|
@@ -458,7 +458,7 @@ export interface ContentElement extends Element {
|
|
|
458
458
|
/**
|
|
459
459
|
* - 模板 Markdown 元素
|
|
460
460
|
*/
|
|
461
|
-
export interface
|
|
461
|
+
export interface TplMarkdownElement extends Element {
|
|
462
462
|
type: 'markdown_tpl';
|
|
463
463
|
/**
|
|
464
464
|
* - 模板ID
|
|
@@ -478,6 +478,16 @@ export interface TemplateElement extends Element {
|
|
|
478
478
|
values: Array<string>;
|
|
479
479
|
}>;
|
|
480
480
|
}
|
|
481
|
+
/**
|
|
482
|
+
* - Markdown 元素
|
|
483
|
+
*/
|
|
484
|
+
export interface MarkdownElement extends Element {
|
|
485
|
+
type: 'markdown';
|
|
486
|
+
/**
|
|
487
|
+
* - Markdown内容
|
|
488
|
+
*/
|
|
489
|
+
content: string;
|
|
490
|
+
}
|
|
481
491
|
/**
|
|
482
492
|
* - 按钮
|
|
483
493
|
*/
|
|
@@ -552,7 +562,7 @@ export interface LongMsgElement extends Element {
|
|
|
552
562
|
*/
|
|
553
563
|
id: string;
|
|
554
564
|
}
|
|
555
|
-
export type KarinElement = TextElement | AtElement | FaceElement | BubbleFaceElement | ReplyElement | ImageElement | VoiceElement | VideoElement | BasketballElement | DiceElement | RpsElement | PokeElement | MusicElement | WeatherElement | LocationElement | ShareElement | GiftElement | MarketFaceElement | ForwardElement | ContactElement | JsonElement | XmlElement | FileElement | ButtonElement | RowElement | RecordElement | LongMsgElement |
|
|
565
|
+
export type KarinElement = TextElement | AtElement | FaceElement | BubbleFaceElement | ReplyElement | ImageElement | VoiceElement | VideoElement | BasketballElement | DiceElement | RpsElement | PokeElement | MusicElement | WeatherElement | LocationElement | ShareElement | GiftElement | MarketFaceElement | ForwardElement | ContactElement | JsonElement | XmlElement | FileElement | ButtonElement | RowElement | RecordElement | LongMsgElement | TplMarkdownElement | RawMarkdownElement;
|
|
556
566
|
/**
|
|
557
567
|
* - 构建自定义转发节点 此元素仅可通过专用接口发送 不支持混合发送
|
|
558
568
|
*/
|
package/lib/types/render.d.ts
CHANGED
|
@@ -72,6 +72,12 @@ export interface KarinRenderType {
|
|
|
72
72
|
[key: string]: any;
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* 渲染结果
|
|
77
|
+
*/
|
|
78
|
+
export type RenderResult<T> = T extends {
|
|
79
|
+
multiPage: true | number;
|
|
80
|
+
} ? Array<string> : string;
|
|
75
81
|
/**
|
|
76
82
|
* 渲染基类
|
|
77
83
|
*/
|
|
@@ -98,7 +104,7 @@ export interface KarinRender {
|
|
|
98
104
|
* 渲染
|
|
99
105
|
* @param options - 标准渲染方法
|
|
100
106
|
*/
|
|
101
|
-
render: (options:
|
|
107
|
+
render: <T extends KarinRenderType>(options: T, id?: string) => Promise<RenderResult<T>>;
|
|
102
108
|
}
|
|
103
109
|
/**
|
|
104
110
|
* 渲染器管理
|
package/lib/utils/segment.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TextElement, AtElement, ImageElement, FaceElement, BubbleFaceElement, ReplyElement, VideoElement, BasketballElement, DiceElement, RpsElement, PokeElement, MusicElement, WeatherElement, LocationElement, ShareElement, GiftElement, MarketFaceElement, ForwardElement, ContactElement, JsonElement, XmlElement, FileElement, ButtonElement, CustomMusicElemen,
|
|
1
|
+
import { TextElement, AtElement, ImageElement, FaceElement, BubbleFaceElement, ReplyElement, VideoElement, BasketballElement, DiceElement, RpsElement, PokeElement, MusicElement, WeatherElement, LocationElement, ShareElement, GiftElement, MarketFaceElement, ForwardElement, ContactElement, JsonElement, XmlElement, FileElement, ButtonElement, CustomMusicElemen, TplMarkdownElement, RawMarkdownElement, NodeElement, KarinElement, LongMsgElement, RecordElement } from '../types/index.js';
|
|
2
2
|
export declare const segment: {
|
|
3
3
|
/**
|
|
4
4
|
* 纯文本
|
|
@@ -252,13 +252,13 @@ export declare const segment: {
|
|
|
252
252
|
* @param content - 原生markdown内容
|
|
253
253
|
* @param config - 未知的参数
|
|
254
254
|
*/
|
|
255
|
-
markdown(content:
|
|
255
|
+
markdown(content: RawMarkdownElement["content"], config?: RawMarkdownElement["config"]): RawMarkdownElement;
|
|
256
256
|
/**
|
|
257
257
|
* 构建模板Markdown
|
|
258
258
|
* @param custom_template_id - 模板ID
|
|
259
259
|
* @param params - 模板markdown参数
|
|
260
260
|
*/
|
|
261
|
-
markdown_tpl(custom_template_id:
|
|
261
|
+
markdown_tpl(custom_template_id: TplMarkdownElement["custom_template_id"], params: TplMarkdownElement["params"]): TplMarkdownElement;
|
|
262
262
|
/**
|
|
263
263
|
* 按钮
|
|
264
264
|
* @param data - 按钮数据
|