@girs/gjs 4.0.0-beta.3 → 4.0.0-beta.35

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/gjs.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- /*
1
+ /**
2
2
  * Type Definitions for Gjs (https://gjs.guide/)
3
3
  *
4
4
  * These type definitions are automatically generated, do not edit them by hand.
5
5
  * If you found a bug fix it in ts-for-gir itself or create a bug report on https://github.com/gjsify/ts-for-gir
6
6
  */
7
- import './ambient.d.ts';
8
7
 
9
8
  import type GObject from '@girs/gobject-2.0';
10
9
  import type GLib from '@girs/glib-2.0';
10
+
11
11
  import gettext from './gettext.js';
12
12
  import system from './system.js';
13
13
  import cairo from './cairo.js';
@@ -20,98 +20,315 @@ declare namespace package {
20
20
  * and all the other have their values derived from them.
21
21
  */
22
22
  interface PackageInitParams {
23
- name: string
24
- version: string
25
- prefix: string
26
- libdir: string
23
+ /** The base name of the entry point (eg. org.foo.Bar.App) */
24
+ name: string;
25
+ /** The version of the package */
26
+ version: string;
27
+ /** The prefix of the package */
28
+ prefix: string;
29
+ /**
30
+ * The final datadir and libdir when installed;
31
+ * usually, these would be prefix + '/share' and
32
+ * and prefix + '/lib' (or '/lib64')
33
+ */
34
+ libdir: string;
35
+ /**
36
+ * The final datadir and libdir when installed;
37
+ * usually, these would be prefix + '/share' and
38
+ * and prefix + '/lib' (or '/lib64')
39
+ */
40
+ datadir?: string;
27
41
  }
28
42
 
29
- export const name: string | undefined
30
- export const version: string | undefined
31
- export const prefix: string | undefined
32
- export const datadir: string | undefined
33
- export const libdir: string | undefined
34
- export const pkgdatadir: string | undefined
35
- export const pkglibdir: string | undefined
36
- export const moduledir: string | undefined
37
- export const localedir: string | undefined
38
-
39
- export function init(params: PackageInitParams): void
40
- export function run(module: { main: (argv: string[]) => void }): void
41
- /** shortcut to init+run */
42
- export function start(params: PackageInitParams): void
43
- export function require(libs: Record<string, string>): void
44
- export function requireSymbol(lib: string, ver: string, symbol: string): void
45
- export function checkSymbol(lib: string, ver: string, symbol: string): void
46
- export function initGettext(): void
47
- /** @deprecated Use JS string interpolation */
48
- export function initFormat(): void
49
- export function initSubmodule(module: string): void
43
+ /**
44
+ * The base name of the entry point (eg. org.foo.Bar.App)
45
+ *
46
+ * Note: Run `pkg.init()` before accessing this property.
47
+ */
48
+ export const name: string;
49
+ /**
50
+ * The version of the package
51
+ *
52
+ * Note: Run `pkg.init()` before accessing this property.
53
+ */
54
+ export const version: string;
55
+ /**
56
+ * The prefix of the package
57
+ *
58
+ * Note: Run `pkg.init()` before accessing this property.
59
+ */
60
+ export const prefix: string;
61
+ /**
62
+ * The final datadir when installed; usually, these would be prefix + '/share'
63
+ *
64
+ * Note: Run `pkg.init()` before accessing this property.
65
+ */
66
+ export const datadir: string;
67
+ /**
68
+ * The final libdir when installed; usually, these would be prefix + '/lib' (or '/lib64')
69
+ *
70
+ * Note: Run `pkg.init()` before accessing this property.
71
+ */
72
+ export const libdir: string;
73
+ /**
74
+ * The final pkglibdir when installed; usually, this would be prefix + '/lib' (or '/lib64')
75
+ *
76
+ * Note: Run `pkg.init()` before accessing this property.
77
+ */
78
+ export const pkglibdir: string;
79
+ /**
80
+ * The final moduledir when installed; usually, this would be prefix + '/lib' (or '/lib64')
81
+ *
82
+ * Note: Run `pkg.init()` before accessing this property.
83
+ */
84
+ export const moduledir: string;
85
+ /**
86
+ * The directory containing gettext translation files; this will be datadir + '/locale' when installed and './po' in the source tree
87
+ *
88
+ * Note: Run `pkg.init()` before accessing this property.
89
+ */
90
+ export const localedir: string;
91
+
92
+ /**
93
+ * Initialize directories and global variables. Must be called
94
+ * before any of other API in Package is used.
95
+ * `params` must be an object with at least the following keys:
96
+ * - name: the package name ($(PACKAGE_NAME) in autotools,
97
+ * eg. org.foo.Bar)
98
+ * - version: the package version
99
+ * - prefix: the installation prefix
100
+ *
101
+ * init() will take care to check if the program is running from
102
+ * the source directory or not, by looking for a 'src' directory.
103
+ *
104
+ * At the end, the global variable 'pkg' will contain the
105
+ * Package module (imports.package). Additionally, the following
106
+ * module variables will be available:
107
+ * - name: the base name of the entry point (eg. org.foo.Bar.App)
108
+ * - version: same as in @params
109
+ * - prefix: the installation prefix (as passed in @params)
110
+ * - datadir, libdir: the final datadir and libdir when installed;
111
+ * usually, these would be prefix + '/share' and
112
+ * and prefix + '/lib' (or '/lib64')
113
+ * - pkgdatadir: the directory to look for private data files, such as
114
+ * images, stylesheets and UI definitions;
115
+ * this will be datadir + name when installed and
116
+ * './data' when running from the source tree
117
+ * - pkglibdir: the directory to look for private typelibs and C
118
+ * libraries;
119
+ * this will be libdir + name when installed and
120
+ * './lib' when running from the source tree
121
+ * - moduledir: the directory to look for JS modules;
122
+ * this will be pkglibdir when installed and
123
+ * './src' when running from the source tree
124
+ * - localedir: the directory containing gettext translation files;
125
+ * this will be datadir + '/locale' when installed
126
+ * and './po' in the source tree
127
+ *
128
+ * All paths are absolute and will not end with '/'.
129
+ *
130
+ * As a side effect, init() calls GLib.set_prgname().
131
+ *
132
+ * @param {object} params package parameters
133
+ */
134
+ export function init(params: PackageInitParams): void;
135
+ /**
136
+ * This is the function to use if you want to have multiple
137
+ * entry points in one package.
138
+ * You must define a main(ARGV) function inside the passed
139
+ * in module, and then the launcher would be
140
+ *
141
+ * imports.package.init(...);
142
+ * imports.package.run(imports.entrypoint);
143
+ *
144
+ * @param module the module to run
145
+ * @returns the exit code of the module's main() function
146
+ */
147
+ export function run(module: { main: (argv: string[]) => void }): number | undefined;
148
+ /**
149
+ * This is a convenience function if your package has a
150
+ * single entry point.
151
+ * You must define a main(ARGV) function inside a main.js
152
+ * module in moduledir.
153
+ *
154
+ * @param params see init()
155
+ */
156
+ export function start(params: PackageInitParams): void;
157
+ /**
158
+ * Mark a dependency on a specific version of one or more
159
+ * external GI typelibs.
160
+ * `libs` must be an object whose keys are a typelib name,
161
+ * and values are the respective version. The empty string
162
+ * indicates any version.
163
+ * @param deps The external dependencies to import
164
+ */
165
+ export function require(deps: Record<string, string>): void;
166
+ /**
167
+ * As checkSymbol(), but exit with an error if the
168
+ * dependency cannot be satisfied.
169
+ *
170
+ * @param lib an external dependency to import
171
+ * @param ver version of the dependency
172
+ * @param symbol symbol to check for
173
+ */
174
+ export function requireSymbol(lib: string, ver?: string, symbol?: string): void;
175
+ /**
176
+ * Check whether an external GI typelib can be imported
177
+ * and provides @symbol.
178
+ *
179
+ * Symbols may refer to
180
+ * - global functions ('main_quit')
181
+ * - classes ('Window')
182
+ * - class / instance methods ('IconTheme.get_default' / 'IconTheme.has_icon')
183
+ * - GObject properties ('Window.default_height')
184
+ *
185
+ * @param lib an external dependency to import
186
+ * @param ver version of the dependency
187
+ * @param symbol symbol to check for
188
+ * @returns true if `lib` can be imported and provides `symbol`, false
189
+ * otherwise
190
+ */
191
+ export function checkSymbol(lib: string, ver: string, symbol: string): boolean;
192
+ /**
193
+ * Initialize `gettext`.
194
+ * After calling this method `globalThis._`, `globalThis.C_` and `globalThis.N_` will be available.
195
+ */
196
+ export function initGettext(): void;
197
+ /**
198
+ * Initializes string formatting capabilities by adding a format() method to String.prototype.
199
+ *
200
+ * After calling this method, you can use a printf-style string formatting by calling
201
+ * the format() method on any string:
202
+ *
203
+ * @example
204
+ * ```ts
205
+ * pkg.initFormat();
206
+ *
207
+ * // Now you can use format() on any string
208
+ * const name = "User";
209
+ * const count = 5;
210
+ * const formatted = "Hello %s, you have %d items".format(name, count);
211
+ * // formatted = "Hello User, you have 5 items"
212
+ *
213
+ * // Format numbers with precision
214
+ * const price = 10.5;
215
+ * const priceStr = "Price: $%.2f".format(price);
216
+ * // priceStr = "Price: $10.50"
217
+ *
218
+ * // Pad with zeros
219
+ * const id = 42;
220
+ * const idStr = "ID: %05d".format(id);
221
+ * // idStr = "ID: 00042"
222
+ * ```
223
+ */
224
+ export function initFormat(): void;
225
+ /**
226
+ * As checkSymbol(), but exit with an error if the
227
+ * dependency cannot be satisfied.
228
+ *
229
+ * @param lib an external dependency to import
230
+ * @param ver version of the dependency
231
+ * @param symbol symbol to check for
232
+ */
233
+ export function initSubmodule(lib: string, ver?: string, symbol?: string): void;
234
+ /**
235
+ * Load and register a GResource named @name. @name is optional and defaults to ${package-name}
236
+ * @param name The name of the GResource to load
237
+ */
238
+ export function loadResource(name?: string): void;
50
239
  }
51
240
 
52
241
  declare namespace byteArray {
53
242
  export class ByteArray {
54
- static get(target: any, property: string, receiver: any): any
55
- static set(target: any, property: string, value: any, receiver: any): boolean
243
+ static get(target: any, property: string, receiver: any): any;
244
+ static set(target: any, property: string, value: any, receiver: any): boolean;
56
245
 
57
- length: number
58
- protected _array: Uint8Array
246
+ length: number;
247
+ protected _array: Uint8Array;
59
248
 
60
- constructor(x: Uint8Array | number)
61
- toString(encoding?: TextDecoderEncoding): string
62
- fromString(input: string, encoding?: TextDecoderEncoding): ByteArray
63
- toGBytes(): GLib.Bytes
249
+ constructor(x: Uint8Array | number);
250
+ toString(encoding?: TextDecoderEncoding): string;
251
+ fromString(input: string, encoding?: TextDecoderEncoding): ByteArray;
252
+ toGBytes(): GLib.Bytes;
64
253
  }
65
254
 
66
255
  /** @deprecated Use {@link TextEncoder.encode} instead */
67
- export function fromString(input: string, encoding?: TextDecoderEncoding): Uint8Array
256
+ export function fromString(input: string, encoding?: TextDecoderEncoding): Uint8Array;
68
257
 
69
258
  /** @deprecated Use {@link GLib.Bytes.toArray} instead */
70
- export function fromGBytes(input: GLib.Bytes): Uint8Array
259
+ export function fromGBytes(input: GLib.Bytes): Uint8Array;
71
260
 
72
261
  /** @deprecated Use {@link TextDecoder.decode} instead */
73
- export function toString(x: Uint8Array, encoding?: TextDecoderEncoding): string
262
+ export function toString(x: Uint8Array, encoding?: TextDecoderEncoding): string;
74
263
 
75
264
  /** @deprecated Use {@link GLib.Bytes new GLib.Bytes() } instead */
76
- export function toGBytes(x: Uint8Array): GLib.Bytes
265
+ export function toGBytes(x: Uint8Array): GLib.Bytes;
77
266
 
78
267
  /** @deprecated Use {@link ByteArray new ByteArray()} instead */
79
- export function fromArray(array: Iterable<number>): ByteArray
268
+ export function fromArray(array: Iterable<number>): ByteArray;
80
269
  }
81
270
 
82
271
  declare namespace lang {
83
272
  // TODO: There is a lot more in Lang
84
- export function Class(props: any): void
273
+ export function Class(props: any): void;
85
274
  }
86
275
 
87
276
  declare namespace format {
88
- export function vprintf(str: string, args: string[]): string
89
- export function printf(fmt: string, ...args: any[]): void
90
- // Following docs from gjs/modules/format.js
91
277
  /**
92
- * This function is intended to extend the String object and provide
93
- * an String.format API for string formatting.
94
- * It has to be set up using String.prototype.format = Format.format;
95
- * Usage:
96
- * "somestring %s %d".format('hello', 5);
97
- * It supports %s, %d, %x and %f, for %f it also support precisions like
98
- * "%.2f".format(1.526). All specifiers can be prefixed with a minimum
99
- * field width, e.g. "%5s".format("foo"). Unless the width is prefixed
100
- * with '0', the formatted string will be padded with spaces.
278
+ * Formats a string using printf-style format specifiers.
279
+ *
280
+ * @param str The format string
281
+ * @param args The arguments to be formatted
282
+ * @returns The formatted string
283
+ */
284
+ export function vprintf(str: string, args: (string | number | boolean | null | undefined)[]): string;
285
+
286
+ /**
287
+ * Prints a formatted string to the console.
288
+ * Similar to C's printf function.
289
+ *
290
+ * @param fmt The format string
291
+ * @param args The arguments to be formatted
292
+ */
293
+ export function printf(fmt: string, ...args: (string | number | boolean | null | undefined)[]): void;
294
+
295
+ /**
296
+ * Formats a string with the given arguments.
297
+ * This is the implementation that backs String.prototype.format
298
+ * when pkg.initFormat() is called.
299
+ *
300
+ * Supported format specifiers:
301
+ * - %s: Formats as a string
302
+ * - %d: Formats as an integer
303
+ * - %x: Formats as a hexadecimal number
304
+ * - %f: Formats as a floating point number, optionally with precision (e.g. %.2f)
305
+ *
306
+ * All specifiers can be prefixed with a minimum field width, e.g. "%5s" will pad with spaces.
307
+ * If the width is prefixed with '0', it will pad with zeroes instead of spaces.
308
+ *
309
+ * @example
310
+ * ```ts
311
+ * format.format("Hello %s, you have %d items", "User", 5);
312
+ * // Returns: "Hello User, you have 5 items"
313
+ * ```
314
+ *
315
+ * @param fmt The format string
316
+ * @param args The arguments to format the string with
317
+ * @returns The formatted string
101
318
  */
102
- export function format(fmt: string, ...args: any[]): string
319
+ export function format(fmt: string, ...args: (string | number | boolean | null | undefined)[]): string;
103
320
  }
104
321
 
105
322
  declare namespace mainloop {
106
- export function quit(name: string): void
107
- export function idle_source(handler: any, priority?: number): any
108
- export function idle_add(handler: any, priority?: number): any
109
- export function timeout_source(timeout: any, handler: any, priority?: number): any
110
- export function timeout_seconds_source(timeout: any, handler: any, priority?: number): any
111
- export function timeout_add(timeout: any, handler: any, priority?: number): any
112
- export function timeout_add_seconds(timeout: any, handler: any, priority?: number): any
113
- export function source_remove(id: any): any
114
- export function run(name: string): void
323
+ export function quit(name: string): void;
324
+ export function idle_source(handler: any, priority?: number): any;
325
+ export function idle_add(handler: any, priority?: number): any;
326
+ export function timeout_source(timeout: any, handler: any, priority?: number): any;
327
+ export function timeout_seconds_source(timeout: any, handler: any, priority?: number): any;
328
+ export function timeout_add(timeout: any, handler: any, priority?: number): any;
329
+ export function timeout_add_seconds(timeout: any, handler: any, priority?: number): any;
330
+ export function source_remove(id: any): any;
331
+ export function run(name: string): void;
115
332
  }
116
333
 
117
334
  /**
@@ -121,15 +338,15 @@ declare namespace mainloop {
121
338
  * @example
122
339
  * ```ts
123
340
  * const Signals = imports.signals;
124
- *
341
+ *
125
342
  * // Define an interface with the same name of your class to make the methods known
126
343
  * interface Events extends Signals.Methods {}
127
- *
344
+ *
128
345
  * class Events {}
129
346
  * Signals.addSignalMethods(Events.prototype);
130
- *
347
+ *
131
348
  * const events = new Events();
132
- *
349
+ *
133
350
  * // Typescript will not complain here
134
351
  * events.emit("test-signal", "test argument");
135
352
  * ```
@@ -138,13 +355,13 @@ export interface SignalMethods {
138
355
  /**
139
356
  * Connects a callback to a signal for an object. Pass the returned ID to
140
357
  * `disconnect()` to remove the handler.
141
- *
358
+ *
142
359
  * If `callback` returns `true`, emission will stop and no other handlers will be
143
360
  * invoked.
144
- *
361
+ *
145
362
  * > Warning: Unlike GObject signals, `this` within a signal callback will always
146
363
  * > refer to the global object (ie. `globalThis`).
147
- *
364
+ *
148
365
  * @param sigName A signal name
149
366
  * @param callback A callback function
150
367
  * @returns A handler ID
@@ -152,7 +369,7 @@ export interface SignalMethods {
152
369
  connect(sigName: string, callback: (self: any, ...args: any[]) => void): number;
153
370
  /**
154
371
  * Emits a signal for an object. Emission stops if a signal handler returns `true`.
155
- *
372
+ *
156
373
  * Unlike GObject signals, it is not necessary to declare signals or define their
157
374
  * signature. Simply call `emit()` with whatever signal name you wish, with
158
375
  * whatever arguments you wish.
@@ -168,7 +385,7 @@ export interface SignalMethods {
168
385
  /**
169
386
  * Disconnects all signal handlers for an object.
170
387
  */
171
- disconnectAll(): void
388
+ disconnectAll(): void;
172
389
  /**
173
390
  * Checks if a handler ID is connected.
174
391
  * @param id The ID of the handler to be disconnected
@@ -182,7 +399,6 @@ declare namespace signals {
182
399
  }
183
400
 
184
401
  declare global {
185
-
186
402
  // https://gitlab.gnome.org/GNOME/gjs/-/blob/1.73.2/modules/esm/_encoding/encodingMap.js#L7-232
187
403
  type TextDecoderEncoding =
188
404
  | 'unicode-1-1-utf-8'
@@ -404,56 +620,113 @@ declare global {
404
620
  | 'unicode'
405
621
  | 'unicodefeff'
406
622
  | 'utf-16'
407
- | 'utf-16le'
623
+ | 'utf-16le';
408
624
 
409
625
  interface GjsGiImports {
410
626
  // Will be extended by the import of more gir types
411
627
  versions: {
412
- [namespace: string]: string
413
- }
628
+ [namespace: string]: string;
629
+ };
414
630
  }
415
-
631
+
416
632
  interface GjsImports {
417
- gi: GjsGiImports
418
- lang: typeof lang
419
- system: typeof system
420
- signals: typeof signals
421
- package: typeof package
422
- mainloop: typeof mainloop
423
- searchPath: string[]
424
- gettext: typeof gettext
425
- byteArray: typeof byteArray
426
- format: typeof format
427
- cairo: typeof cairo
633
+ gi: GjsGiImports;
634
+ lang: typeof lang;
635
+ system: typeof system;
636
+ signals: typeof signals;
637
+ package: typeof package;
638
+ mainloop: typeof mainloop;
639
+ searchPath: string[];
640
+ gettext: typeof gettext;
641
+ byteArray: typeof byteArray;
642
+ format: typeof format;
643
+ cairo: typeof cairo;
428
644
  }
429
645
 
430
- function print(...args: any[]): void
431
- function printerr(...args: any[]): void
432
- function log(message: any): void
433
- function logError(exception: object, message?: any): void
434
- function logError(message?: any): void
646
+ // Overwrites, see https://gitlab.gnome.org/GNOME/gjs/-/blob/master/modules/script/package.js
647
+ /**
648
+ * Run `pkg.initGettext()` before using this.
649
+ * See {@link gettext.gettext}
650
+ */
651
+ const _: typeof gettext.gettext;
652
+ /**
653
+ * Run `pkg.initGettext()` before using this.
654
+ * See {@link gettext.pgettext}
655
+ */
656
+ const C_: typeof gettext.pgettext;
657
+ /**
658
+ * Run `pkg.initGettext()` before using this.
659
+ * Currently not implemented.
660
+ */
661
+ const N_: (x: string) => string;
662
+
663
+ function print(...args: any[]): void;
664
+ function printerr(...args: any[]): void;
665
+ function log(obj: object, others?: object[]): void;
666
+ function log(msg: string, substitutions?: any[]): void;
667
+ function logError(exception: object, message?: any): void;
668
+ function logError(message?: any): void;
435
669
 
436
- const pkg: typeof package
670
+ const pkg: typeof package;
437
671
 
438
672
  interface BooleanConstructor {
439
- $gtype: GObject.GType<boolean>
673
+ $gtype: GObject.GType<boolean>;
440
674
  }
441
675
 
442
676
  interface NumberConstructor {
443
- $gtype: GObject.GType<number>
677
+ $gtype: GObject.GType<number>;
444
678
  }
445
679
 
446
680
  interface StringConstructor {
447
- $gtype: GObject.GType<string>
681
+ $gtype: GObject.GType<string>;
448
682
  }
449
683
 
450
- const imports: GjsImports
684
+ interface StringConstructor {
685
+ $gtype: GObject.GType<string>;
686
+ }
451
687
 
452
- const ARGV: string[]
453
- }
688
+ interface ObjectConstructor {
689
+ $gtype: GObject.GType<Object>;
690
+ }
691
+
692
+ const imports: GjsImports;
454
693
 
455
- declare const _imports: GjsImports
456
- export default _imports
457
- export { _imports as imports }
694
+ const ARGV: string[];
458
695
 
696
+ interface String {
697
+ /**
698
+ * Formats a string with the given arguments.
699
+ * This method is made available by calling `pkg.initFormat()`.
700
+ *
701
+ * Supported format specifiers:
702
+ * - %s: Formats as a string
703
+ * - %d: Formats as an integer
704
+ * - %x: Formats as a hexadecimal number
705
+ * - %f: Formats as a floating point number, optionally with precision (e.g. %.2f)
706
+ *
707
+ * All specifiers can be prefixed with a minimum field width, e.g. "%5s" will pad with spaces.
708
+ * If the width is prefixed with '0', it will pad with zeroes instead of spaces.
709
+ *
710
+ * @example
711
+ * ```ts
712
+ * // After calling pkg.initFormat()
713
+ * "Hello %s, you have %d items".format("User", 5);
714
+ * // Returns: "Hello User, you have 5 items"
715
+ *
716
+ * "Price: $%.2f".format(10.5);
717
+ * // Returns: "Price: $10.50"
718
+ *
719
+ * "ID: %05d".format(42);
720
+ * // Returns: "ID: 00042"
721
+ * ```
722
+ *
723
+ * @param args The arguments to format the string with
724
+ * @returns The formatted string
725
+ */
726
+ format(...args: (string | number | boolean | null | undefined)[]): string;
727
+ }
728
+ }
459
729
 
730
+ declare const _imports: GjsImports;
731
+ export default _imports;
732
+ export { _imports as imports };
package/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Type Definitions for Gjs (https://gjs.guide/)
3
+ *
4
+ * These type definitions are automatically generated, do not edit them by hand.
5
+ * If you found a bug fix it in `ts-for-gir` or create a bug report on https://github.com/gjsify/ts-for-gir
6
+ *
7
+ * This template is used to generate the index.d.ts file of each GIR module like Gtk-4.0, GObject-2.0, ...
8
+ */
9
+
10
+ import './gjs-ambient.d.ts';
11
+
12
+ import gjs from './gjs.js';
13
+ export default gjs;
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+
2
+ // @ts-expect-error
3
+ import gjs from './gjs.js';
4
+ export default gjs;
5
+