koishi-plugin-csss 1.1.4 → 1.2.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.
package/lib/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export interface Config {
8
8
  showVAC: boolean;
9
9
  showPassword: boolean;
10
10
  generateImage: boolean;
11
+ imageWidth: number;
11
12
  imageHeight: number;
12
13
  fontSize: number;
13
14
  fontFamily: string;
package/lib/index.js CHANGED
@@ -36,6 +36,7 @@ var Config = import_koishi.Schema.object({
36
36
  showVAC: import_koishi.Schema.boolean().default(true).description("是否显示VAC状态"),
37
37
  showPassword: import_koishi.Schema.boolean().default(true).description("是否显示密码保护信息"),
38
38
  generateImage: import_koishi.Schema.boolean().default(true).description("是否生成图片横幅(影响cs和csss命令)"),
39
+ imageWidth: import_koishi.Schema.number().min(600).max(2e3).default(1200).description("图片宽度(像素)"),
39
40
  imageHeight: import_koishi.Schema.number().min(200).max(2500).default(500).description("图片最小高度(像素),实际高度会根据内容自适应"),
40
41
  fontSize: import_koishi.Schema.number().min(12).max(48).default(24).description("字体大小"),
41
42
  fontFamily: import_koishi.Schema.string().default("Microsoft YaHei, sans-serif").description("字体家族"),
@@ -369,13 +370,23 @@ ${textMessage}`;
369
370
  __name(formatPlayers, "formatPlayers");
370
371
  const imageUtils = {
371
372
  calculateServerNameFontSize(ctx2, name2, maxWidth, baseFontSize) {
372
- let fontSize = baseFontSize * 1.5;
373
- while (fontSize > baseFontSize * 0.8) {
374
- ctx2.font = `bold ${fontSize}px ${config.fontFamily}`;
375
- if (ctx2.measureText(name2).width <= maxWidth) break;
376
- fontSize -= 1;
373
+ try {
374
+ if (!ctx2 || typeof ctx2.measureText !== "function") {
375
+ console.warn("Canvas context not available, returning default font size");
376
+ return baseFontSize * 1.5;
377
+ }
378
+ let fontSize = baseFontSize * 1.5;
379
+ while (fontSize > baseFontSize * 0.8) {
380
+ ctx2.font = `bold ${fontSize}px ${config.fontFamily}`;
381
+ const measurement = ctx2.measureText(name2);
382
+ if (measurement && measurement.width <= maxWidth) break;
383
+ fontSize -= 1;
384
+ }
385
+ return fontSize;
386
+ } catch (error) {
387
+ console.error("Error in calculateServerNameFontSize:", error);
388
+ return baseFontSize * 1.5;
377
389
  }
378
- return fontSize;
379
390
  },
380
391
  calculatePlayerListParams(playerCount) {
381
392
  const shouldEnlarge = playerCount > 0 && playerCount < 10;
@@ -533,7 +544,7 @@ ${textMessage}`;
533
544
  __name(calculateImageHeight, "calculateImageHeight");
534
545
  async function generateServerImage(data, host, port) {
535
546
  const { result } = data;
536
- const width = 1200;
547
+ const width = config.imageWidth;
537
548
  const height = calculateImageHeight(data);
538
549
  const canvas = await ctx.canvas.createCanvas(width, height);
539
550
  const ctx2d = canvas.getContext("2d");
@@ -586,8 +597,8 @@ ${textMessage}`;
586
597
  const failed = results.length - successful;
587
598
  const baseHeight = 200;
588
599
  const serverHeight = 100;
600
+ const width = config.imageWidth;
589
601
  const height = baseHeight + results.length * serverHeight;
590
- const width = 1200;
591
602
  const canvas = await ctx.canvas.createCanvas(width, height);
592
603
  const ctx2d = canvas.getContext("2d");
593
604
  imageUtils.drawBackground(ctx2d, width, height);
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.4",
4
+ "version": "1.2.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [