@gesslar/toolkit 3.26.0 → 3.28.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 CHANGED
@@ -5,7 +5,7 @@
5
5
  "name": "gesslar",
6
6
  "url": "https://gesslar.dev"
7
7
  },
8
- "version": "3.26.0",
8
+ "version": "3.28.0",
9
9
  "license": "Unlicense",
10
10
  "homepage": "https://github.com/gesslar/toolkit#readme",
11
11
  "repository": {
@@ -8,6 +8,7 @@ export {Disposer as DisposerClass} from "./lib/Disposer.js"
8
8
  export {default as HTML} from "./lib/HTML.js"
9
9
  export {HTML as HTMLClass} from "./lib/HTML.js"
10
10
  export {default as Notify} from "./lib/Notify.js"
11
+ export {Notify as NotifyClass} from "./lib/Notify.js"
11
12
  export {default as Promised} from "./lib/Promised.js"
12
13
  export {default as Sass} from "./lib/Sass.js"
13
14
  export {default as Tantrum} from "./lib/Tantrum.js"
@@ -10,7 +10,7 @@
10
10
  * @property {boolean} [cancelable] - Whether the event can be canceled.
11
11
  * @property {boolean} [composed] - Whether the event can cross the shadow DOM boundary.
12
12
  */
13
- export default new class Notify {
13
+ export class Notify {
14
14
  /** @type {string} Display name for debugging. */
15
15
  name = "Notify"
16
16
 
@@ -87,3 +87,5 @@ export default new class Notify {
87
87
  return {detail}
88
88
  }
89
89
  }
90
+
91
+ export default new Notify()
package/src/node/index.js CHANGED
@@ -21,4 +21,5 @@ export {default as FileSystem} from "./lib/FileSystem.js"
21
21
  export {default as Font} from "./lib/Font.js"
22
22
  export {default as Glog} from "./lib/Glog.js"
23
23
  export {default as Notify} from "./lib/Notify.js"
24
+ export {Notify as NotifyClass} from "./lib/Notify.js"
24
25
  export {default as Term} from "./lib/Term.js"
@@ -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
- const platform = os.platform()
44
-
45
- if(platform === "win32") {
46
- return this.#findNerdFontsWindows()
47
- } else if(platform === "darwin") {
48
- return this.#findNerdFontsMac()
49
- } else if(platform === "linux") {
50
- return this.#findNerdFontsLinux()
51
- } else {
52
- return []
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(process.env.WINDIR || "C:/Windows", "/Fonts"))
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(process.env.LOCALAPPDATA, "Microsoft/Windows/Fonts")))
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
- return this.#identifyNerdFonts(fontFiles)
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<import("./FileObject.js").default>} fileObjects - Array of FileObject instances representing font files.
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
  }
@@ -19,7 +19,7 @@ import Util from "./Util.js"
19
19
  * Notify class provides a thin wrapper around EventEmitter for centralized
20
20
  * event handling in Node.js applications. Mirrors the browser Notify API.
21
21
  */
22
- export default new class Notify {
22
+ export class Notify {
23
23
  /** @type {string} Display name for debugging. */
24
24
  name = "Notify"
25
25
 
@@ -106,3 +106,5 @@ export default new class Notify {
106
106
  emitter.off(type, handler)
107
107
  }
108
108
  }
109
+
110
+ export default new Notify()
@@ -1,6 +1,5 @@
1
1
  export { default as Collection } from "./lib/Collection.js";
2
2
  export { default as Data } from "./lib/Data.js";
3
- export { default as Notify } from "./lib/Notify.js";
4
3
  export { default as Promised } from "./lib/Promised.js";
5
4
  export { default as Sass } from "./lib/Sass.js";
6
5
  export { default as Tantrum } from "./lib/Tantrum.js";
@@ -10,4 +9,5 @@ export { default as Util } from "./lib/Util.js";
10
9
  export { default as Valid } from "./lib/Valid.js";
11
10
  export { default as Disposer, Disposer as DisposerClass } from "./lib/Disposer.js";
12
11
  export { default as HTML, HTML as HTMLClass } from "./lib/HTML.js";
12
+ export { default as Notify, Notify as NotifyClass } from "./lib/Notify.js";
13
13
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,15 @@
1
- declare const _default: {
1
+ /**
2
+ * Thin wrapper around `window` event handling to centralize emit/on/off
3
+ * helpers. Used to dispatch simple CustomEvents and manage listeners in one
4
+ * place.
5
+ */
6
+ /**
7
+ * @typedef {object} NotifyEventOptions
8
+ * @property {boolean} [bubbles] - Whether the event bubbles up the DOM tree.
9
+ * @property {boolean} [cancelable] - Whether the event can be canceled.
10
+ * @property {boolean} [composed] - Whether the event can cross the shadow DOM boundary.
11
+ */
12
+ export class Notify {
2
13
  /** @type {string} Display name for debugging. */
3
14
  name: string;
4
15
  /**
@@ -29,7 +40,7 @@ declare const _default: {
29
40
  * @param {boolean | object} [options] - Options to pass to addEventListener.
30
41
  * @returns {() => void} Dispose function to unregister the handler.
31
42
  */
32
- on(type: string, handler: (evt: /*elided*/ any) => void, element?: HTMLElement | Window, options?: boolean | object): () => void;
43
+ on(type: string, handler: (evt: Notify) => void, element?: HTMLElement | Window, options?: boolean | object): () => void;
33
44
  /**
34
45
  * Removes a previously registered listener for the given event type.
35
46
  *
@@ -39,9 +50,10 @@ declare const _default: {
39
50
  * @param {boolean | object} [options] - Options to pass to removeEventListener.
40
51
  * @returns {void}
41
52
  */
42
- off(type: string, handler: (evt: /*elided*/ any) => void, element?: HTMLElement | Window, options?: boolean | object): void;
43
- "__#private@#buildEventInit"(detail: any, options: any): any;
44
- };
53
+ off(type: string, handler: (evt: Notify) => void, element?: HTMLElement | Window, options?: boolean | object): void;
54
+ #private;
55
+ }
56
+ declare const _default: Notify;
45
57
  export default _default;
46
58
  export type NotifyEventOptions = {
47
59
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Notify.d.ts","sourceRoot":"","sources":["../../../src/browser/lib/Notify.js"],"names":[],"mappings":";IAaE,iDAAiD;UAAtC,MAAM;IAGjB;;;;;;;OAOG;eAJQ,MAAM,YACN,OAAO,YACP,OAAO,GAAG,kBAAkB,GAC1B,IAAI;IAOjB;;;;;;;OAOG;kBAJQ,MAAM,YACN,OAAO,YACP,OAAO,GAAG,kBAAkB,GAC1B,OAAO;IASpB;;;;;;;;;OASG;aALQ,MAAM,WACN,CAAC,GAAG,gBAAQ,KAAK,IAAI,YACrB,WAAW,GAAG,MAAM,YACpB,OAAO,GAAG,MAAM,GACd,MAAM,IAAI;IAcvB;;;;;;;;OAQG;cALQ,MAAM,WACN,CAAC,GAAG,gBAAQ,KAAK,IAAI,YACrB,WAAW,GAAG,MAAM,YACpB,OAAO,GAAG,MAAM,GACd,IAAI;;;;;;;;cAjEL,OAAO;;;;iBACP,OAAO;;;;eACP,OAAO"}
1
+ {"version":3,"file":"Notify.d.ts","sourceRoot":"","sources":["../../../src/browser/lib/Notify.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AACH;IACE,iDAAiD;IACjD,MADW,MAAM,CACF;IAEf;;;;;;;OAOG;IACH,WALW,MAAM,YACN,OAAO,YACP,OAAO,GAAG,kBAAkB,GAC1B,IAAI,CAKhB;IAED;;;;;;;OAOG;IACH,cALW,MAAM,YACN,OAAO,YACP,OAAO,GAAG,kBAAkB,GAC1B,OAAO,CAOnB;IAED;;;;;;;;;OASG;IACH,SANW,MAAM,WACN,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,YACrB,WAAW,GAAG,MAAM,YACpB,OAAO,GAAG,MAAM,GACd,MAAM,IAAI,CAYtB;IAED;;;;;;;;OAQG;IACH,UANW,MAAM,WACN,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,YACrB,WAAW,GAAG,MAAM,YACpB,OAAO,GAAG,MAAM,GACd,IAAI,CAIhB;;CAWF;;;;;;;cAhFa,OAAO;;;;iBACP,OAAO;;;;eACP,OAAO"}
@@ -13,7 +13,7 @@ export { default as FileObject } from "./lib/FileObject.js";
13
13
  export { default as FileSystem } from "./lib/FileSystem.js";
14
14
  export { default as Font } from "./lib/Font.js";
15
15
  export { default as Glog } from "./lib/Glog.js";
16
- export { default as Notify } from "./lib/Notify.js";
17
16
  export { default as Term } from "./lib/Term.js";
18
17
  export { default as Disposer, Disposer as DisposerClass } from "../browser/lib/Disposer.js";
18
+ export { default as Notify, Notify as NotifyClass } from "./lib/Notify.js";
19
19
  //# sourceMappingURL=index.d.ts.map
@@ -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<import("./FileObject.js").default>} fileObjects - Array of FileObject instances representing font files.
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":"AAcA;;;;;;;;;;;;;;;GAeG;AACH;IACE;;;;;;;;;OASG;IACH,wBALa,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAiBlC;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,kDAyBC;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;CACF"}
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"}
@@ -1,8 +1,15 @@
1
- declare const _default: {
1
+ /**
2
+ * @typedef {object} NotifyEventOptions
3
+ * @property {boolean} [once] - Whether the listener should be invoked only once.
4
+ * @property {AbortSignal} [signal] - An AbortSignal to remove the listener.
5
+ */
6
+ /**
7
+ * Notify class provides a thin wrapper around EventEmitter for centralized
8
+ * event handling in Node.js applications. Mirrors the browser Notify API.
9
+ */
10
+ export class Notify {
2
11
  /** @type {string} Display name for debugging. */
3
12
  name: string;
4
- /** @type {EventEmitter} Internal event emitter */
5
- "__#private@#emitter": EventEmitter;
6
13
  /**
7
14
  * Emits an event without expecting a return value.
8
15
  *
@@ -49,7 +56,9 @@ declare const _default: {
49
56
  * @returns {void}
50
57
  */
51
58
  off(type: string, handler: (payload: unknown) => void, emitter?: EventEmitter): void;
52
- };
59
+ #private;
60
+ }
61
+ declare const _default: Notify;
53
62
  export default _default;
54
63
  export type NotifyEventOptions = {
55
64
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Notify.d.ts","sourceRoot":"","sources":["../../../src/node/lib/Notify.js"],"names":[],"mappings":";IAsBE,iDAAiD;UAAtC,MAAM;IAGjB,kDAAkD;2BAAvC,YAAY;IAGvB;;;;;;OAMG;eAHQ,MAAM,YACN,OAAO,GACL,IAAI;IAQjB;;;;;;;;OAQG;oBAHQ,MAAM,YACN,OAAO,GACL,OAAO,CAAC,IAAI,CAAC;IAQ1B;;;;;;;OAOG;kBAHQ,MAAM,YACN,OAAO,GACL,OAAO;IAUpB;;;;;;;;OAQG;aALQ,MAAM,WACN,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,YAC1B,YAAY,YACZ,kBAAkB,GAChB,MAAM,IAAI;IAevB;;;;;;;OAOG;cAJQ,MAAM,WACN,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,YAC1B,YAAY,GACV,IAAI;;;;;;;WAvFL,OAAO;;;;aACP,WAAW"}
1
+ {"version":3,"file":"Notify.d.ts","sourceRoot":"","sources":["../../../src/node/lib/Notify.js"],"names":[],"mappings":"AAWA;;;;GAIG;AAEH;;;GAGG;AACH;IACE,iDAAiD;IACjD,MADW,MAAM,CACF;IAKf;;;;;;OAMG;IACH,WAJW,MAAM,YACN,OAAO,GACL,IAAI,CAMhB;IAED;;;;;;;;OAQG;IACH,gBAJW,MAAM,YACN,OAAO,GACL,OAAO,CAAC,IAAI,CAAC,CAMzB;IAED;;;;;;;OAOG;IACH,cAJW,MAAM,YACN,OAAO,GACL,OAAO,CAQnB;IAED;;;;;;;;OAQG;IACH,SANW,MAAM,WACN,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,YAC1B,YAAY,YACZ,kBAAkB,GAChB,MAAM,IAAI,CAatB;IAED;;;;;;;OAOG;IACH,UALW,MAAM,WACN,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,YAC1B,YAAY,GACV,IAAI,CAMhB;;CACF;;;;;;;WA9Fa,OAAO;;;;aACP,WAAW"}