update at 2025-10-09 16:23:27

This commit is contained in:
douboer
2025-10-09 16:23:27 +08:00
parent a71b4c4d4f
commit 002feedbe1
9 changed files with 17 additions and 1265 deletions

View File

@@ -17,6 +17,9 @@ import { sliceCurrentPage, sliceAllPages } from './slice';
const XHS_PREVIEW_DEFAULT_WIDTH = 540;
const XHS_PREVIEW_WIDTH_OPTIONS = [1080, 720, 540, 360];
const XHS_FONT_SIZE_MIN = 18;
const XHS_FONT_SIZE_MAX = 45;
const XHS_FONT_SIZE_DEFAULT = 36;
/**
* 小红书预览视图类
@@ -45,7 +48,7 @@ export class XiaohongshuPreview {
// 分页数据
pages: PageInfo[] = [];
currentPageIndex: number = 0;
currentFontSize: number = 16;
currentFontSize: number = XHS_FONT_SIZE_DEFAULT;
articleHTML: string = '';
// 回调函数
@@ -147,9 +150,14 @@ export class XiaohongshuPreview {
const decreaseBtn = fontSizeGroup.createEl('button', { text: '', cls: 'font-size-btn' });
decreaseBtn.onclick = () => this.changeFontSize(-1);
this.fontSizeInput = fontSizeGroup.createEl('input', {
this.fontSizeInput = fontSizeGroup.createEl('input', {
cls: 'font-size-input',
attr: { type: 'number', min: '12', max: '36', value: '16' }
attr: {
type: 'number',
min: String(XHS_FONT_SIZE_MIN),
max: String(XHS_FONT_SIZE_MAX),
value: String(XHS_FONT_SIZE_DEFAULT)
}
});
this.fontSizeInput.style.width = '50px';
this.fontSizeInput.style.textAlign = 'center';
@@ -363,7 +371,7 @@ export class XiaohongshuPreview {
* 切换字号(± 按钮)
*/
private async changeFontSize(delta: number): Promise<void> {
this.currentFontSize = Math.max(12, Math.min(36, this.currentFontSize + delta));
this.currentFontSize = Math.max(XHS_FONT_SIZE_MIN, Math.min(XHS_FONT_SIZE_MAX, this.currentFontSize + delta));
this.fontSizeInput.value = String(this.currentFontSize);
await this.repaginateAndRender();
}
@@ -373,9 +381,9 @@ export class XiaohongshuPreview {
*/
private async onFontSizeInputChanged(): Promise<void> {
const val = parseInt(this.fontSizeInput.value, 10);
if (isNaN(val) || val < 12 || val > 36) {
if (isNaN(val) || val < XHS_FONT_SIZE_MIN || val > XHS_FONT_SIZE_MAX) {
this.fontSizeInput.value = String(this.currentFontSize);
new Notice('字号范围: 12-36');
new Notice(`字号范围: ${XHS_FONT_SIZE_MIN}-${XHS_FONT_SIZE_MAX}`);
return;
}
this.currentFontSize = val;