koishi-plugin-to-image-service-font-honor-sans-cn 0.0.3 → 0.0.6

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
@@ -2,9 +2,7 @@ import { Context, Schema, Service } from "koishi";
2
2
  declare class ToImageServiceFontHonorSansCn extends Service {
3
3
  private _ctx;
4
4
  constructor(ctx: Context, config: ToImageServiceFontHonorSansCn.Config);
5
- protected start(): Promise<void>;
6
- private initFonts;
7
- private fontNames;
5
+ start(): Promise<void>;
8
6
  }
9
7
  declare namespace ToImageServiceFontHonorSansCn {
10
8
  const inject: string[];
package/lib/index.js CHANGED
@@ -33,9 +33,8 @@ __export(src_exports, {
33
33
  default: () => src_default
34
34
  });
35
35
  module.exports = __toCommonJS(src_exports);
36
- var import_koishi = require("koishi");
37
- var import_promises = __toESM(require("node:fs/promises"));
38
36
  var import_node_path = __toESM(require("node:path"));
37
+ var import_koishi = require("koishi");
39
38
  var serviceName = "toImageServiceFontHonorSansCn";
40
39
  var ToImageServiceFontHonorSansCn = class extends import_koishi.Service {
41
40
  static {
@@ -47,35 +46,13 @@ var ToImageServiceFontHonorSansCn = class extends import_koishi.Service {
47
46
  this._ctx = ctx;
48
47
  }
49
48
  async start() {
50
- await this.initFonts();
51
- }
52
- async initFonts() {
53
- const fonts = [];
54
- for (let i = 0; i < this.fontNames.length; i++) {
55
- const fontName = this.fontNames[i];
56
- fonts.push({
57
- name: "HONOR Sans CN",
58
- weight: (i + 1) * 100,
59
- style: "normal",
60
- data: await import_promises.default.readFile(
61
- import_node_path.default.join(__dirname, `../fonts/HONORSansCN-${fontName}.ttf`)
62
- ),
63
- supports: ["satori"]
64
- });
65
- }
66
- this._ctx.toImageService.addFont(fonts);
49
+ const fonts = await this._ctx.toImageService.fontManagement.loadFontDir([
50
+ import_node_path.default.resolve(__dirname, "../fonts")
51
+ ]);
52
+ this._ctx.on("dispose", () => {
53
+ this._ctx.toImageService.fontManagement.removeFont(fonts);
54
+ });
67
55
  }
68
- fontNames = [
69
- "Thin",
70
- "ExtraLight",
71
- "Light",
72
- "Regular",
73
- "Medium",
74
- "DemiBold",
75
- "Bold",
76
- "ExtraBold",
77
- "Heavy"
78
- ];
79
56
  };
80
57
  ((ToImageServiceFontHonorSansCn2) => {
81
58
  ToImageServiceFontHonorSansCn2.inject = ["toImageService"];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-to-image-service-font-honor-sans-cn",
3
3
  "description": "Provide HONOR Sans CN fonts for the to-image-service",
4
- "version": "0.0.3",
4
+ "version": "0.0.6",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "scripts": {
@@ -39,7 +39,7 @@
39
39
  "koishi": "^4.18.5"
40
40
  },
41
41
  "devDependencies": {
42
- "koishi-plugin-to-image-service": "^0.0.3"
42
+ "koishi-plugin-to-image-service": "^1.0.1"
43
43
  },
44
44
  "koishi": {
45
45
  "service": {