@gesslar/toolkit 3.26.0 → 3.27.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/package.json +1 -1
- package/src/node/lib/Font.js +51 -16
- package/types/node/lib/Font.d.ts +14 -1
- package/types/node/lib/Font.d.ts.map +1 -1
package/package.json
CHANGED
package/src/node/lib/Font.js
CHANGED
|
@@ -10,6 +10,10 @@ import child_process from "node:child_process"
|
|
|
10
10
|
import DirectoryObject from "./DirectoryObject.js"
|
|
11
11
|
import FS from "./FileSystem.js"
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* @import {FileObject} from "./FileObject.js"
|
|
15
|
+
*/
|
|
16
|
+
|
|
13
17
|
const execFile = promisify(child_process.execFile)
|
|
14
18
|
|
|
15
19
|
/**
|
|
@@ -29,6 +33,8 @@ const execFile = promisify(child_process.execFile)
|
|
|
29
33
|
* console.log(fonts) // ["FiraCode", "JetBrainsMono", ...]
|
|
30
34
|
*/
|
|
31
35
|
export default class Font {
|
|
36
|
+
static #cache = new Map()
|
|
37
|
+
|
|
32
38
|
/**
|
|
33
39
|
* Finds all Nerd Fonts installed on the system.
|
|
34
40
|
* Detects the current platform and uses platform-specific methods
|
|
@@ -40,17 +46,20 @@ export default class Font {
|
|
|
40
46
|
* console.log(nerdFonts) // ["FiraCode Nerd Font", "JetBrains Mono NF", ...]
|
|
41
47
|
*/
|
|
42
48
|
static async findNerdFonts() {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
if(!this.#cache.has("nerdFonts")) {
|
|
50
|
+
const platform = os.platform()
|
|
51
|
+
|
|
52
|
+
if(platform === "win32")
|
|
53
|
+
this.#cache.set("nerdFonts", this.#findNerdFontsWindows())
|
|
54
|
+
else if(platform === "darwin")
|
|
55
|
+
this.#cache.set("nerdFonts", this.#findNerdFontsMac())
|
|
56
|
+
else if(platform === "linux")
|
|
57
|
+
this.#cache.set("nerdFonts", this.#findNerdFontsLinux())
|
|
58
|
+
else
|
|
59
|
+
this.#cache.set("nerdFonts", [])
|
|
53
60
|
}
|
|
61
|
+
|
|
62
|
+
return this.#cache.get("nerdFonts")
|
|
54
63
|
}
|
|
55
64
|
|
|
56
65
|
/**
|
|
@@ -113,12 +122,17 @@ export default class Font {
|
|
|
113
122
|
*/
|
|
114
123
|
static async #findNerdFontsWindows() {
|
|
115
124
|
const fontDirs = [
|
|
116
|
-
new DirectoryObject(FS.resolvePath(
|
|
125
|
+
new DirectoryObject(FS.resolvePath(
|
|
126
|
+
process.env.WINDIR || "C:/Windows",
|
|
127
|
+
"/Fonts"
|
|
128
|
+
))
|
|
117
129
|
]
|
|
118
130
|
|
|
119
|
-
if(process.env.LOCALAPPDATA)
|
|
120
|
-
fontDirs.push(new DirectoryObject(FS.resolvePath(
|
|
121
|
-
|
|
131
|
+
if(process.env.LOCALAPPDATA)
|
|
132
|
+
fontDirs.push(new DirectoryObject(FS.resolvePath(
|
|
133
|
+
process.env.LOCALAPPDATA,
|
|
134
|
+
"Microsoft/Windows/Fonts"
|
|
135
|
+
)))
|
|
122
136
|
|
|
123
137
|
const fontFiles = []
|
|
124
138
|
|
|
@@ -135,7 +149,9 @@ export default class Font {
|
|
|
135
149
|
}
|
|
136
150
|
}
|
|
137
151
|
|
|
138
|
-
|
|
152
|
+
this.#cache.set("nerdFonts", this.#identifyNerdFonts(fontFiles))
|
|
153
|
+
|
|
154
|
+
return this.#cache.get("nerdFonts")
|
|
139
155
|
}
|
|
140
156
|
|
|
141
157
|
/**
|
|
@@ -208,7 +224,7 @@ export default class Font {
|
|
|
208
224
|
/**
|
|
209
225
|
* Identifies Nerd Fonts from a list of font file objects.
|
|
210
226
|
*
|
|
211
|
-
* @param {Array<
|
|
227
|
+
* @param {Array<FileObject>} fileObjects - Array of FileObject instances representing font files.
|
|
212
228
|
* @returns {Array<string>} Sorted array of unique Nerd Font family names.
|
|
213
229
|
* @private
|
|
214
230
|
*/
|
|
@@ -225,4 +241,23 @@ export default class Font {
|
|
|
225
241
|
|
|
226
242
|
return Array.from(nerdFonts).sort()
|
|
227
243
|
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Gets spinner animation frames appropriate for the current font environment.
|
|
247
|
+
* Returns Unicode braille characters if Nerd Fonts are available,
|
|
248
|
+
* otherwise returns ASCII fallback characters.
|
|
249
|
+
*
|
|
250
|
+
* @returns {Promise<Array<string>>} Promise resolving to array of spinner frame characters.
|
|
251
|
+
* @example
|
|
252
|
+
* const frames = await Font.spinFrames
|
|
253
|
+
* // With Nerd Fonts: ["⠋", "⠙", "⠹", ...]
|
|
254
|
+
* // Without: ["|", "/", "-", "\\"]
|
|
255
|
+
*/
|
|
256
|
+
static get spinFrames() {
|
|
257
|
+
return this.hasNerdFonts().then(has =>
|
|
258
|
+
has
|
|
259
|
+
? ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
|
|
260
|
+
: ["|", "/", "-", "\\"]
|
|
261
|
+
)
|
|
262
|
+
}
|
|
228
263
|
}
|
package/types/node/lib/Font.d.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* console.log(fonts) // ["FiraCode", "JetBrainsMono", ...]
|
|
16
16
|
*/
|
|
17
17
|
export default class Font {
|
|
18
|
+
static "__#private@#cache": Map<any, any>;
|
|
18
19
|
/**
|
|
19
20
|
* Finds all Nerd Fonts installed on the system.
|
|
20
21
|
* Detects the current platform and uses platform-specific methods
|
|
@@ -91,10 +92,22 @@ export default class Font {
|
|
|
91
92
|
/**
|
|
92
93
|
* Identifies Nerd Fonts from a list of font file objects.
|
|
93
94
|
*
|
|
94
|
-
* @param {Array<
|
|
95
|
+
* @param {Array<FileObject>} fileObjects - Array of FileObject instances representing font files.
|
|
95
96
|
* @returns {Array<string>} Sorted array of unique Nerd Font family names.
|
|
96
97
|
* @private
|
|
97
98
|
*/
|
|
98
99
|
private static "__#private@#identifyNerdFonts";
|
|
100
|
+
/**
|
|
101
|
+
* Gets spinner animation frames appropriate for the current font environment.
|
|
102
|
+
* Returns Unicode braille characters if Nerd Fonts are available,
|
|
103
|
+
* otherwise returns ASCII fallback characters.
|
|
104
|
+
*
|
|
105
|
+
* @returns {Promise<Array<string>>} Promise resolving to array of spinner frame characters.
|
|
106
|
+
* @example
|
|
107
|
+
* const frames = await Font.spinFrames
|
|
108
|
+
* // With Nerd Fonts: ["⠋", "⠙", "⠹", ...]
|
|
109
|
+
* // Without: ["|", "/", "-", "\\"]
|
|
110
|
+
*/
|
|
111
|
+
static get spinFrames(): Promise<Array<string>>;
|
|
99
112
|
}
|
|
100
113
|
//# sourceMappingURL=Font.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Font.d.ts","sourceRoot":"","sources":["../../../src/node/lib/Font.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Font.d.ts","sourceRoot":"","sources":["../../../src/node/lib/Font.js"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;;;GAeG;AACH;IACE,0CAAyB;IAEzB;;;;;;;;;OASG;IACH,wBALa,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAoBlC;IAED;;;;;;;;OAQG;IACH,uBANa,OAAO,CAAC,OAAO,CAAC,CAQ5B;IAED;;;;;;;;OAQG;IACH,8BALa,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAUlC;IAED;;;;;;OAMG;IACH,yCAEC;IAED;;;;;;;OAOG;IACH,4CAEC;IAED;;;;;OAKG;IACH,kDAgCC;IAED;;;;;OAKG;IACH,8CAyBC;IAED;;;;;OAKG;IACH,gDAoBC;IAED,wEAAwE;IACxE,gCADW,KAAK,CAAC,MAAM,CAAC,CACoB;IAE5C,8EAA8E;IAC9E,qCADW,KAAK,CAAC,MAAM,CAAC,CAC0B;IAElD;;;;;;OAMG;IACH,+CAYC;IAED;;;;;;;;;;OAUG;IACH,yBANa,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAYlC;CACF"}
|