koishi-plugin-ll-mc 3.1.0 → 3.1.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.
Files changed (2) hide show
  1. package/lib/index.js +39 -32
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -2519,39 +2519,33 @@ ${targetUserRecord[0].username}
2519
2519
  }[ch]));
2520
2520
  }
2521
2521
  __name(escapeHtml, "escapeHtml");
2522
- const LEADERBOARD_ROW_PALETTES = [
2523
- { bar: "#C8B8AE", fill: "#A26D51", text: "#5D3F2E" },
2524
- { bar: "#C4C4C4", fill: "#8E908D", text: "#4A4B49" },
2525
- { bar: "#F8BBD0", fill: "#F06292", text: "#374151" },
2526
- { bar: "#D1C4E9", fill: "#9575CD", text: "#374151" },
2527
- { bar: "#FFCDD2", fill: "#E57373", text: "#374151" },
2528
- { bar: "#CFD8DC", fill: "#90A4AE", text: "#374151" },
2529
- { bar: "#D7CCC8", fill: "#A1887F", text: "#374151" },
2530
- { bar: "#FFE0B2", fill: "#FFB74D", text: "#374151" },
2531
- { bar: "#BDBDBD", fill: "#757575", text: "#374151" },
2532
- { bar: "#C5E1A5", fill: "#AED581", text: "#374151" },
2533
- { bar: "#FFECB3", fill: "#FFD54F", text: "#374151" },
2534
- { bar: "#B2DFDB", fill: "#80CBC4", text: "#374151" },
2535
- { bar: "#BBDEFB", fill: "#90CAF9", text: "#374151" },
2536
- { bar: "#E1BEE7", fill: "#CE93D8", text: "#374151" },
2537
- { bar: "#FFCCBC", fill: "#FFAB91", text: "#374151" },
2538
- { bar: "#F0F4C3", fill: "#E6EE9C", text: "#374151" },
2539
- { bar: "#BCAAA4", fill: "#A1887F", text: "#374151" },
2540
- { bar: "#EEEEEE", fill: "#BDBDBD", text: "#374151" },
2541
- { bar: "#CFD8DC", fill: "#90A4AE", text: "#374151" }
2522
+ const BAR_LIGHT_TRACK = "#F3F4F6";
2523
+ const BAR_FILL_COLORS = [
2524
+ "#F472B6", // pink
2525
+ "#A78BFA", // violet
2526
+ "#60A5FA", // blue
2527
+ "#34D399", // emerald
2528
+ "#FBBF24", // amber
2529
+ "#F87171", // red
2530
+ "#22D3EE", // cyan
2531
+ "#A3E635", // lime
2532
+ "#FB923C", // orange
2533
+ "#818CF8" // indigo
2542
2534
  ];
2543
- function buildLeaderboardRow(item, index) {
2544
- const pal = LEADERBOARD_ROW_PALETTES[index % LEADERBOARD_ROW_PALETTES.length];
2535
+ function buildLeaderboardRow(item, index, maxCount) {
2545
2536
  const isHero = index === 0;
2546
- const width = item.count > 0 ? Math.max(item.percentage, 1) : 1;
2537
+ const fillColor = BAR_FILL_COLORS[((index - 1) % BAR_FILL_COLORS.length + BAR_FILL_COLORS.length) % BAR_FILL_COLORS.length];
2538
+ // 发言(数据)部分相对第一名缩放,确保柱子占比直观;0 发言使用极细条
2539
+ const width = item.count > 0 ? Math.max((item.count / maxCount) * 100, 2) : 1;
2547
2540
  const avatar = escapeHtml(item.avatar || "");
2548
2541
  const name = escapeHtml(item.name || "");
2549
2542
  const count = item.count;
2550
- const barBg = isHero ? "#F3F4F6" : pal.bar;
2543
+ // 柱子总背景固定为浅色,发言部分单独用颜色区分,这样更显眼
2544
+ const barBg = BAR_LIGHT_TRACK;
2551
2545
  const fill = isHero
2552
2546
  ? 'linear-gradient(to right, #6366F1, #A855F7, #EC4899)'
2553
- : pal.fill;
2554
- const textColor = isHero ? "#FFFFFF" : pal.text;
2547
+ : fillColor;
2548
+ const textColor = isHero ? "#FFFFFF" : "#1F2937";
2555
2549
  const star = isHero
2556
2550
  ? `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="row-star"><path fill-rule="evenodd" d="M10.788 3.21c.448-1.077 1.976-1.077 2.424 0l2.082 5.007 5.404.433c1.164.093 1.636 1.545.749 2.305l-4.117 3.527 1.257 5.273c.271 1.136-.964 2.033-1.96 1.425L12 18.354 7.373 21.18c-.996.608-2.231-.29-1.96-1.425l1.257-5.273-4.117-3.527c-.887-.76-.415-2.212.749-2.305l5.404-.433 2.082-5.006z" clip-rule="evenodd"/></svg>`
2557
2551
  : "";
@@ -2567,8 +2561,9 @@ ${targetUserRecord[0].username}
2567
2561
  </div>`;
2568
2562
  }
2569
2563
  __name(buildLeaderboardRow, "buildLeaderboardRow");
2570
- function buildLeaderboardHtml(title, date, items) {
2571
- const rows = items.map(buildLeaderboardRow).join("\n");
2564
+ function buildLeaderboardHtml(title, date, items, backgroundCss) {
2565
+ const maxCount = Math.max(1, ...items.map((item) => item.count || 0));
2566
+ const rows = items.map((item, index) => buildLeaderboardRow(item, index, maxCount)).join("\n");
2572
2567
  return `<!DOCTYPE html>
2573
2568
  <html lang="zh-CN">
2574
2569
  <head>
@@ -2578,11 +2573,15 @@ ${targetUserRecord[0].username}
2578
2573
  * { box-sizing: border-box; margin: 0; padding: 0; }
2579
2574
  html, body {
2580
2575
  width: 900px;
2576
+ }
2577
+ html {
2581
2578
  background-color: #F5F7FA;
2579
+ }
2580
+ body {
2581
+ padding: 16px;
2582
2582
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
2583
2583
  -webkit-font-smoothing: antialiased;
2584
2584
  }
2585
- body { padding: 16px; }
2586
2585
  .card {
2587
2586
  width: 100%;
2588
2587
  max-width: 868px;
@@ -2609,6 +2608,7 @@ ${targetUserRecord[0].username}
2609
2608
  .row-star { width: 16px; height: 16px; color: #FCD34D; flex-shrink: 0; }
2610
2609
  .row-count { font-size: 18px; font-weight: 700; }
2611
2610
  </style>
2611
+ ${backgroundCss ? `<style>${backgroundCss}</style>` : ""}
2612
2612
  </head>
2613
2613
  <body>
2614
2614
  <div class="card">
@@ -2624,11 +2624,11 @@ ${rows}
2624
2624
  </html>`;
2625
2625
  }
2626
2626
  __name(buildLeaderboardHtml, "buildLeaderboardHtml");
2627
- async function renderLeaderboardTemplate(ctx, title, date, items) {
2627
+ async function renderLeaderboardTemplate(ctx, title, date, items, backgroundCss) {
2628
2628
  if (typeof ctx.puppeteer?.page !== "function") return null;
2629
2629
  let page;
2630
2630
  try {
2631
- const html = buildLeaderboardHtml(title, date, items);
2631
+ const html = buildLeaderboardHtml(title, date, items, backgroundCss);
2632
2632
  page = await ctx.puppeteer.page();
2633
2633
  await page.setViewport({ width: 900, height: 400, deviceScaleFactor: 2 });
2634
2634
  try {
@@ -2665,11 +2665,18 @@ ${rows}
2665
2665
  rank: index + 1,
2666
2666
  name: item.name.replace(/^★/, "")
2667
2667
  }));
2668
+ let templateBackgroundCss = "";
2669
+ if (config.backgroundType === "css" && config.backgroundValue) {
2670
+ templateBackgroundCss = config.backgroundValue;
2671
+ } else if (config.backgroundType === "api" && config.apiBackgroundConfig?.apiUrl) {
2672
+ templateBackgroundCss = await _prepareBackgroundStyle(config);
2673
+ }
2668
2674
  const dataUri = await renderLeaderboardTemplate(
2669
2675
  ctx,
2670
2676
  rankTitle,
2671
2677
  rankTimeTitle,
2672
- templateItems
2678
+ templateItems,
2679
+ templateBackgroundCss
2673
2680
  );
2674
2681
  if (dataUri) {
2675
2682
  return import_koishi.h.image(dataUri);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-ll-mc",
3
3
  "description": "消息数量统计插件(基于 koishi-plugin-message-counter 重做,官方QQ机器人兼容)",
4
- "version": "3.1.0",
4
+ "version": "3.1.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [