koishi-plugin-fimtale-api 0.0.98 → 1.0.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.
Files changed (2) hide show
  1. package/lib/index.js +26 -33
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -78,7 +78,7 @@ function apply(ctx, config) {
78
78
  }, "generateGradient");
79
79
  const cleanContent = /* @__PURE__ */ __name((html) => {
80
80
  if (!html) return "";
81
- return html.replace(/style="[^"]*"/gi, "").replace(/<p[^>]*>\s*(&nbsp;|<br\s*\/?>|\s)*\s*<\/p>/gi, "").replace(/(<br\s*\/?>\s*){2,}/gi, "<br>").trim();
81
+ return html.replace(/style\s*=\s*['"][^'"]*['"]/gi, "").replace(/<p[^>]*>\s*(?:<br\s*\/?>|&nbsp;|&#160;|\s| )*\s*<\/p>/gi, "").replace(/(<br\s*\/?>\s*){2,}/gi, "<br>").replace(/<\/p>\s*<br\s*\/?>\s*<p/gi, "</p><p>").replace(/<p[^>]*>\s*<br\s*\/?>/gi, "<p>").replace(/<br\s*\/?>\s*<\/p>/gi, "</p>").replace(/(?:<br\s*\/?>|&nbsp;|\s)+$/gi, "").trim();
82
82
  }, "cleanContent");
83
83
  const fontStack = '"Noto Sans SC", "Microsoft YaHei", "PingFang SC", sans-serif';
84
84
  const fontSerif = '"Noto Serif SC", "Source Han Serif SC", "SimSun", serif';
@@ -231,10 +231,8 @@ function apply(ctx, config) {
231
231
  <style>
232
232
  body { margin: 0; padding: 0; font-family: ${fontStack}; background: transparent; }
233
233
  .card { width: 620px; height: 360px; background: #fff; border-radius: 16px; box-shadow: 0 10px 30px rgba(0,0,0,0.15); display: flex; overflow: hidden; }
234
-
235
234
  .cover { width: 220px; height: 100%; ${bgStyle} background-size: cover; background-position: center; position: relative; flex-shrink: 0; }
236
235
  .id-tag { position: absolute; top: 12px; left: 12px; background: rgba(0,0,0,0.6); color: #fff; padding: 4px 10px; border-radius: 6px; font-size: 13px; font-weight: bold; backdrop-filter: blur(4px); font-family: monospace; }
237
-
238
236
  .info { flex: 1; padding: 24px; display: flex; flex-direction: column; overflow: hidden; position: relative; }
239
237
 
240
238
  .header-group { flex-shrink: 0; margin-bottom: 10px; }
@@ -255,29 +253,17 @@ function apply(ctx, config) {
255
253
  .tag { background: #eff2f5; color: #5c6b7f; padding: 3px 9px; border-radius: 4px; font-size: 11px; font-weight: 500; }
256
254
  .tag-imp { background: #e3f2fd; color: #1565c0; }
257
255
 
258
- /* 修复:使用 Flex 自动填充剩余空间,并增加底部 padding 防止截断 */
259
- .summary-box {
260
- flex: 1;
261
- position: relative;
262
- overflow: hidden;
263
- min-height: 0;
264
- }
256
+ .summary-box { flex: 1; position: relative; overflow: hidden; min-height: 0; }
265
257
  .summary {
266
258
  font-size: 13px; color: #666; line-height: 1.6;
267
- display: -webkit-box;
268
- -webkit-line-clamp: 4;
269
- -webkit-box-orient: vertical;
270
- overflow: hidden;
271
- padding-bottom: 3px; /* 关键修复:防止下行字母(如g,j,p,q,y)被切掉 */
259
+ display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
260
+ padding-bottom: 3px;
272
261
  }
273
262
 
274
263
  .footer {
275
- border-top: 1px solid #eee;
276
- padding-top: 14px;
264
+ border-top: 1px solid #eee; padding-top: 14px;
277
265
  display: flex; justify-content: space-between;
278
- font-size: 12px; color: #888;
279
- margin-top: auto; /* 确保页脚始终在底部 */
280
- flex-shrink: 0;
266
+ font-size: 12px; color: #888; margin-top: auto; flex-shrink: 0;
281
267
  }
282
268
  .stat b { color: #555; font-weight: bold; margin-right: 2px;}
283
269
  </style>
@@ -401,40 +387,46 @@ function apply(ctx, config) {
401
387
  font-size: 12px; color: #aaa; background: #f6f4ec; z-index: 5;
402
388
  }
403
389
 
404
- /* 视口容器:用于隐藏溢出的页面 */
390
+ /* 视口容器:限定只显示一页内容 */
405
391
  #viewport {
406
392
  position: absolute;
407
393
  top: ${marginTop}px;
408
- left: ${paddingX}px; /* 左边距 */
409
- width: ${contentWidth}px; /* 限制视口只显示一页内容的宽度 */
394
+ left: ${paddingX}px;
395
+ width: ${contentWidth}px;
410
396
  height: ${optimalContentHeight}px;
411
- overflow: hidden; /* 关键:隐藏其他页 */
397
+ overflow: hidden;
412
398
  }
413
399
 
414
- /* 内容长条:实际上是超宽的 */
400
+ /* 长条容器:包含所有列 */
415
401
  #content-scroller {
416
402
  height: 100%;
417
- width: 100%; /* 这里的 100% 是相对于 viewport 的 contentWidth */
403
+ width: 100%;
418
404
 
419
405
  /* CSS Columns 布局 */
420
406
  column-width: ${contentWidth}px;
421
407
  column-gap: ${columnGap}px;
422
408
  column-fill: auto;
423
409
 
424
- padding: ${paddingY}px 0; /* 左右不需要 padding,因为 viewport 已经定了位置 */
410
+ padding: ${paddingY}px 0;
425
411
  box-sizing: border-box;
426
412
 
427
413
  font-size: ${config.fontSize}px;
428
414
  line-height: ${lineHeightRatio};
429
415
  text-align: justify;
430
416
 
431
- /* 关键:使用 transform 移动,初始位置为 0 */
432
417
  transform: translateX(0);
433
418
  transition: none;
434
419
  }
435
420
 
436
- p { margin: 0 0 0.8em 0; text-indent: 2em; }
437
- img { max-width: 100%; height: auto; display: block; margin: 10px auto; border-radius: 6px; }
421
+ /* 段落间距优化:0.4em 是一个平衡点,紧凑但区分清晰 */
422
+ p {
423
+ margin: 0 0 0.4em 0;
424
+ text-indent: 2em;
425
+ }
426
+ /* 防止最后一段下边距导致额外分页 */
427
+ p:last-child { margin-bottom: 0; }
428
+
429
+ img { max-width: 100%; height: auto; display: block; margin: 10px auto; border-radius: 6px; box-shadow: 0 2px 6px rgba(0,0,0,0.1); }
438
430
  h1, h2, h3 { font-size: 1.1em; margin: 0.8em 0; color: #5d4037; text-indent: 0; font-weight: bold; break-after: avoid; break-inside: avoid; }
439
431
  </style>
440
432
  </head>
@@ -459,14 +451,15 @@ function apply(ctx, config) {
459
451
  await page.setViewport({ width: config.deviceWidth, height: config.deviceHeight, deviceScaleFactor: 2 });
460
452
  const scrollWidth = await page.$eval("#content-scroller", (el) => el.scrollWidth);
461
453
  const step = contentWidth + columnGap;
462
- const totalPages = Math.ceil((scrollWidth + columnGap) / step) || 1;
454
+ const totalPages = Math.floor((scrollWidth + columnGap - 10) / step) + 1;
455
+ const finalPages = Math.max(1, totalPages);
463
456
  const imgs = [];
464
- for (let i = 0; i < totalPages; i++) {
457
+ for (let i = 0; i < finalPages; i++) {
465
458
  await page.evaluate((idx, stepPx, curr, total) => {
466
459
  const offset = -(idx * stepPx);
467
460
  document.getElementById("content-scroller").style.transform = `translateX(${offset}px)`;
468
461
  document.getElementById("page-indicator").innerText = `- ${curr} / ${total} -`;
469
- }, i, step, i + 1, totalPages);
462
+ }, i, step, i + 1, finalPages);
470
463
  const img = await page.screenshot({ type: "jpeg", quality: 80 });
471
464
  imgs.push(img);
472
465
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-fimtale-api",
3
3
  "description": "Koishi插件,从fimtale搜索/订阅/随机获取小说/解析链接等",
4
- "version": "0.0.98",
4
+ "version": "1.0.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [