koishi-plugin-group-analysis-mx 1.3.0 → 1.3.2
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/service/renderer.js +22 -3
- package/package.json +1 -1
package/lib/service/renderer.js
CHANGED
|
@@ -78,9 +78,14 @@ class RendererService extends koishi_1.Service {
|
|
|
78
78
|
return html;
|
|
79
79
|
const emojiCss = this.buildEmojiFontCss();
|
|
80
80
|
const style = `<style>${emojiCss}html,body{font-family:-apple-system,'Segoe UI','Segoe UI Emoji','Noto Color Emoji','NotoEmoji','Apple Color Emoji','Microsoft YaHei','Hiragino Sans GB',sans-serif !important;}</style>`;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
let out = html.includes('</head>')
|
|
82
|
+
? html.replace('</head>', style + '</head>')
|
|
83
|
+
: html;
|
|
84
|
+
// 预加载 span:@font-face 默认懒加载,用隐藏的 emoji 文本强制 Chromium 加载 NotoEmoji 字体,避免截图时字体未就绪
|
|
85
|
+
const preload = `<span style="font-family:'NotoEmoji';position:absolute;left:-9999px;top:-9999px;opacity:0;font-size:40px;pointer-events:none;">😊📺🎥🤣😀</span>`;
|
|
86
|
+
if (out.includes('<body>'))
|
|
87
|
+
out = out.replace('<body>', '<body>' + preload);
|
|
88
|
+
return out;
|
|
84
89
|
}
|
|
85
90
|
/**
|
|
86
91
|
* 生成引用同层 fonts/NotoEmoji.ttf 的 @font-face(单文件 ttf,Chromium 稳定加载)。
|
|
@@ -155,6 +160,17 @@ class RendererService extends koishi_1.Service {
|
|
|
155
160
|
? path_1.default.resolve(this.templateDir, 'original', skin, 'emptyHtml.html')
|
|
156
161
|
: path_1.default.resolve(this.templateDir, skin, 'emptyHtml.html');
|
|
157
162
|
}
|
|
163
|
+
/** 确保用于建立 file:// base 的空 HTML 占位存在(不依赖 init 顺序)。 */
|
|
164
|
+
async ensureEmptyHtml() {
|
|
165
|
+
const p = this.emptyHtmlPath();
|
|
166
|
+
try {
|
|
167
|
+
await fs_1.promises.access(p);
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
await fs_1.promises.mkdir(path_1.default.dirname(p), { recursive: true });
|
|
171
|
+
await fs_1.promises.writeFile(p, '');
|
|
172
|
+
}
|
|
173
|
+
}
|
|
158
174
|
async renderGroupAnalysisToPdf(data) {
|
|
159
175
|
let theme = this.config.theme;
|
|
160
176
|
if (theme === 'auto') {
|
|
@@ -241,6 +257,7 @@ class RendererService extends koishi_1.Service {
|
|
|
241
257
|
this.ctx.logger.info('HTML 模板填充完成,正在调用 Puppeteer 进行渲染...');
|
|
242
258
|
const page = await this.ctx.puppeteer.page();
|
|
243
259
|
// 先 goto 空 HTML 建立 file:// base,再 setContent 注入内容(@font-face 相对字体才能被加载)
|
|
260
|
+
await this.ensureEmptyHtml();
|
|
244
261
|
await page.goto('file://' + this.emptyHtmlPath(), {
|
|
245
262
|
waitUntil: 'domcontentloaded'
|
|
246
263
|
});
|
|
@@ -316,6 +333,7 @@ class RendererService extends koishi_1.Service {
|
|
|
316
333
|
this.ctx.logger.info(`原项目皮肤 ${skin} HTML 生成完成,正在调用 Puppeteer 渲染...`);
|
|
317
334
|
const page = await this.ctx.puppeteer.page();
|
|
318
335
|
await page.setViewport({ width: 1080, height: 1920, deviceScaleFactor: 2 });
|
|
336
|
+
await this.ensureEmptyHtml();
|
|
319
337
|
await page.goto('file://' + this.emptyHtmlPath(), {
|
|
320
338
|
waitUntil: 'domcontentloaded'
|
|
321
339
|
});
|
|
@@ -535,6 +553,7 @@ class RendererService extends koishi_1.Service {
|
|
|
535
553
|
this.ctx.logger.info('用户画像 HTML 模板填充完成,正在调用 Puppeteer 进行渲染...');
|
|
536
554
|
const page = await this.ctx.puppeteer.page();
|
|
537
555
|
// 先 goto 空 HTML 建立 file:// base,再 setContent 注入内容(@font-face 相对字体才能被加载)
|
|
556
|
+
await this.ensureEmptyHtml();
|
|
538
557
|
await page.goto('file://' + this.emptyHtmlPath(), {
|
|
539
558
|
waitUntil: 'domcontentloaded'
|
|
540
559
|
});
|
package/package.json
CHANGED