koishi-plugin-csss 1.1.5 → 1.2.1

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 +20 -9
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -39,12 +39,13 @@ var Config = import_koishi.Schema.object({
39
39
  imageWidth: import_koishi.Schema.number().min(600).max(2e3).default(1200).description("图片宽度(像素)"),
40
40
  imageHeight: import_koishi.Schema.number().min(200).max(2500).default(500).description("图片最小高度(像素),实际高度会根据内容自适应"),
41
41
  fontSize: import_koishi.Schema.number().min(12).max(48).default(24).description("字体大小"),
42
- fontFamily: import_koishi.Schema.string().default("Microsoft YaHei, sans-serif").description("字体家族"),
42
+ fontFamily: import_koishi.Schema.string().default('"JetBrains Mono", monospace').description("字体家族"),
43
43
  serverList: import_koishi.Schema.array(import_koishi.Schema.string()).role("table").description("批量查询服务器列表(格式: 地址:端口,每行一个)").default([
44
44
  "edgebug.cn:27015",
45
45
  "edgebug.cn:27016",
46
46
  "edgebug.cn:27017",
47
- "edgebug.cn:27018"
47
+ "edgebug.cn:27018",
48
+ "edgebug.cn:27019"
48
49
  ]),
49
50
  batchTimeout: import_koishi.Schema.number().min(1e3).max(6e4).default(15e3).description("批量查询总超时时间(毫秒)"),
50
51
  // 定时任务配置
@@ -370,13 +371,23 @@ ${textMessage}`;
370
371
  __name(formatPlayers, "formatPlayers");
371
372
  const imageUtils = {
372
373
  calculateServerNameFontSize(ctx2, name2, maxWidth, baseFontSize) {
373
- let fontSize = baseFontSize * 1.5;
374
- while (fontSize > baseFontSize * 0.8) {
375
- ctx2.font = `bold ${fontSize}px ${config.fontFamily}`;
376
- if (ctx2.measureText(name2).width <= maxWidth) break;
377
- fontSize -= 1;
374
+ try {
375
+ if (!ctx2 || typeof ctx2.measureText !== "function") {
376
+ console.warn("Canvas context not available, returning default font size");
377
+ return baseFontSize * 1.5;
378
+ }
379
+ let fontSize = baseFontSize * 1.5;
380
+ while (fontSize > baseFontSize * 0.8) {
381
+ ctx2.font = `bold ${fontSize}px ${config.fontFamily}`;
382
+ const measurement = ctx2.measureText(name2);
383
+ if (measurement && measurement.width <= maxWidth) break;
384
+ fontSize -= 1;
385
+ }
386
+ return fontSize;
387
+ } catch (error) {
388
+ console.error("Error in calculateServerNameFontSize:", error);
389
+ return baseFontSize * 1.5;
378
390
  }
379
- return fontSize;
380
391
  },
381
392
  calculatePlayerListParams(playerCount) {
382
393
  const shouldEnlarge = playerCount > 0 && playerCount < 10;
@@ -544,7 +555,7 @@ ${textMessage}`;
544
555
  if (result.name) {
545
556
  const cleanName = utils.cleanName(result.name);
546
557
  const fontSize = imageUtils.calculateServerNameFontSize(ctx2d, cleanName, width - 160, config.fontSize);
547
- imageUtils.drawTitle(ctx2d, cleanName, width / 2, titleY + 50, fontSize * 0.8, config.fontFamily, COLORS.highlight);
558
+ imageUtils.drawTitle(ctx2d, cleanName, width / 2, titleY + 50, fontSize * 1.8, config.fontFamily, COLORS.highlight);
548
559
  }
549
560
  imageUtils.drawDivider(ctx2d, 80, titleY + 80, width - 80, titleY + 80, COLORS.border, 2);
550
561
  let y = titleY + 120;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-csss",
3
3
  "description": "Check the status of the CS server",
4
- "version": "1.1.5",
4
+ "version": "1.2.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [