@gjsify/node-gi 0.13.0 → 0.20.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/README.md +818 -5
- package/binding.gyp +55 -19
- package/cairo.d.ts +187 -0
- package/cairo.js +570 -0
- package/gettext.d.ts +65 -0
- package/gettext.js +128 -0
- package/gi.d.ts +178 -0
- package/gi.js +2018 -23
- package/globals.d.ts +7 -33
- package/globals.js +40 -51
- package/gtk-runtime.d.ts +17 -0
- package/gtk-runtime.js +245 -0
- package/index.d.ts +306 -12
- package/index.js +447 -14
- package/overrides/_signals.js +167 -0
- package/overrides/gio-dbus.js +749 -0
- package/overrides/mainloop.js +60 -0
- package/package.json +45 -4
- package/src/addon.cc +98 -2074
- package/src/cairo.cc +926 -0
- package/src/calls.cc +1425 -0
- package/src/class.cc +1170 -0
- package/src/common.h +624 -0
- package/src/loop.cc +766 -0
- package/src/marshal.cc +1738 -0
- package/src/object.cc +814 -0
- package/src/private.cc +351 -0
- package/src/repo.cc +297 -0
- package/src/signals.cc +535 -0
- package/src/template.cc +116 -0
- package/src/toggle.cc +718 -0
- package/src/variant.cc +587 -0
- package/system.d.ts +49 -0
- package/system.js +116 -0
package/gettext.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// @gjsify/node-gi/gettext — the GJS `Gettext` module on Node.
|
|
3
|
+
//
|
|
4
|
+
// GJS exposes a built-in `gettext` module (`import Gettext from 'gettext'` /
|
|
5
|
+
// `imports.gettext`) — a convenience layer over GLib's gettext family. On Node
|
|
6
|
+
// we provide a no-translation passthrough: every lookup returns the untranslated
|
|
7
|
+
// msgid, which is exactly the correct fallback when no message catalog is bound
|
|
8
|
+
// (GLib's gettext degrades to the same passthrough with no catalog). This keeps
|
|
9
|
+
// GJS source that calls `Gettext.gettext(...)` at module load working unchanged
|
|
10
|
+
// on Node without pulling in a real gettext binding.
|
|
11
|
+
//
|
|
12
|
+
// This is the single source of truth for the Gettext surface: the legacy
|
|
13
|
+
// `imports.gettext` exposed by `@gjsify/node-gi/globals` re-uses this module's
|
|
14
|
+
// default export. The gjsify `--app node` build aliases the bare `gettext`
|
|
15
|
+
// specifier to this module (kept external — `ALIASES_GJS_FOR_NODE`).
|
|
16
|
+
//
|
|
17
|
+
// Reference: GJS's `gettext` module (refs/gjs/modules/esm/gettext.js +
|
|
18
|
+
// modules/core/_gettext.js). Signatures mirror that surface.
|
|
19
|
+
|
|
20
|
+
/** Look up `msgid` in the default domain. Passthrough — returns `msgid`. */
|
|
21
|
+
export function gettext(msgid) {
|
|
22
|
+
return msgid;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Look up `msgid` in `domain`. Passthrough — returns `msgid`. */
|
|
26
|
+
export function dgettext(_domain, msgid) {
|
|
27
|
+
return msgid;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Look up `msgid` in `domain`/`category`. Passthrough — returns `msgid`. */
|
|
31
|
+
export function dcgettext(_domain, msgid, _category) {
|
|
32
|
+
return msgid;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Plural lookup in the default domain. Passthrough — singular for n===1, else plural. */
|
|
36
|
+
export function ngettext(msgid1, msgid2, n) {
|
|
37
|
+
return n === 1 ? msgid1 : msgid2;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Plural lookup in `domain`. Passthrough — singular for n===1, else plural. */
|
|
41
|
+
export function dngettext(_domain, msgid1, msgid2, n) {
|
|
42
|
+
return n === 1 ? msgid1 : msgid2;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Context lookup in the default domain. Passthrough — returns `msgid`. */
|
|
46
|
+
export function pgettext(_context, msgid) {
|
|
47
|
+
return msgid;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Context lookup in `domain`. Passthrough — returns `msgid`. */
|
|
51
|
+
export function dpgettext(_domain, _context, msgid) {
|
|
52
|
+
return msgid;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Create gettext bindings bound to a particular translation domain. Mirrors
|
|
57
|
+
* GJS's `Gettext.domain()` — returns an object with `gettext`/`ngettext`/
|
|
58
|
+
* `pgettext` bound to `domainName` (passthrough here).
|
|
59
|
+
*/
|
|
60
|
+
export function domain(_domainName) {
|
|
61
|
+
return {
|
|
62
|
+
gettext(msgid) {
|
|
63
|
+
return msgid;
|
|
64
|
+
},
|
|
65
|
+
ngettext(msgid1, msgid2, n) {
|
|
66
|
+
return n === 1 ? msgid1 : msgid2;
|
|
67
|
+
},
|
|
68
|
+
pgettext(_context, msgid) {
|
|
69
|
+
return msgid;
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Set the locale for `category`. No-op on Node — returns null. */
|
|
75
|
+
export function setlocale(_category, _locale) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Set the default text domain. No-op on Node — returns null. */
|
|
80
|
+
export function textdomain(_domainName) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Bind a text domain to a directory. No-op on Node — returns null. */
|
|
85
|
+
export function bindtextdomain(_domainName, _dirName) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Set the output codeset for a text domain. No-op on Node — returns null. */
|
|
90
|
+
export function bindtextdomainCodeset(_domainName, _codeset) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The `LocaleCategory` enum — the standard POSIX locale category constants GJS
|
|
96
|
+
* surfaces via `GjsPrivate.LocaleCategory`.
|
|
97
|
+
*/
|
|
98
|
+
export const LocaleCategory = {
|
|
99
|
+
CTYPE: 0,
|
|
100
|
+
NUMERIC: 1,
|
|
101
|
+
TIME: 2,
|
|
102
|
+
COLLATE: 3,
|
|
103
|
+
MONETARY: 4,
|
|
104
|
+
MESSAGES: 5,
|
|
105
|
+
ALL: 6,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The GJS `Gettext` module as a default export — the object shape
|
|
110
|
+
* `import Gettext from 'gettext'` returns.
|
|
111
|
+
*/
|
|
112
|
+
const Gettext = {
|
|
113
|
+
gettext,
|
|
114
|
+
dgettext,
|
|
115
|
+
dcgettext,
|
|
116
|
+
ngettext,
|
|
117
|
+
dngettext,
|
|
118
|
+
pgettext,
|
|
119
|
+
dpgettext,
|
|
120
|
+
domain,
|
|
121
|
+
setlocale,
|
|
122
|
+
textdomain,
|
|
123
|
+
bindtextdomain,
|
|
124
|
+
bindtextdomainCodeset,
|
|
125
|
+
LocaleCategory,
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export default Gettext;
|
package/gi.d.ts
CHANGED
|
@@ -10,12 +10,190 @@
|
|
|
10
10
|
/** A GJS-shaped namespace object (members resolved dynamically). */
|
|
11
11
|
export type GiNamespace = Record<string, unknown>;
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* A plain descriptor produced by a `GObject.ParamSpec.*` factory and consumed by
|
|
15
|
+
* the {@link GObjectNamespace.registerClass} decorator (mapped to the native
|
|
16
|
+
* property spec). Not used directly.
|
|
17
|
+
*/
|
|
18
|
+
export interface ParamSpecDescriptor {
|
|
19
|
+
$paramSpec: true;
|
|
20
|
+
type: 'string' | 'boolean' | 'int' | 'uint' | 'int64' | 'uint64' | 'double' | 'float' | 'object' | 'boxed';
|
|
21
|
+
name: string;
|
|
22
|
+
nick?: string;
|
|
23
|
+
blurb?: string;
|
|
24
|
+
flags?: number;
|
|
25
|
+
default?: string | number | boolean;
|
|
26
|
+
minimum?: number;
|
|
27
|
+
maximum?: number;
|
|
28
|
+
/** For `object`/`boxed`: the value GType handle (resolved from a class ctor's `$gtype`). */
|
|
29
|
+
gtype?: unknown;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The `GObject.ParamSpec.*` factories surfaced on the GObject namespace. */
|
|
33
|
+
export interface ParamSpecFactories {
|
|
34
|
+
string(name: string, nick: string, blurb: string, flags: number, defaultValue?: string): ParamSpecDescriptor;
|
|
35
|
+
boolean(name: string, nick: string, blurb: string, flags: number, defaultValue?: boolean): ParamSpecDescriptor;
|
|
36
|
+
int(name: string, nick: string, blurb: string, flags: number, minimum: number, maximum: number, defaultValue?: number): ParamSpecDescriptor;
|
|
37
|
+
uint(name: string, nick: string, blurb: string, flags: number, minimum: number, maximum: number, defaultValue?: number): ParamSpecDescriptor;
|
|
38
|
+
int64(name: string, nick: string, blurb: string, flags: number, minimum: number, maximum: number, defaultValue?: number): ParamSpecDescriptor;
|
|
39
|
+
uint64(name: string, nick: string, blurb: string, flags: number, minimum: number, maximum: number, defaultValue?: number): ParamSpecDescriptor;
|
|
40
|
+
double(name: string, nick: string, blurb: string, flags: number, minimum: number, maximum: number, defaultValue?: number): ParamSpecDescriptor;
|
|
41
|
+
float(name: string, nick: string, blurb: string, flags: number, minimum: number, maximum: number, defaultValue?: number): ParamSpecDescriptor;
|
|
42
|
+
/** A GObject-typed property; `gtype` is a class ctor (its `$gtype` is read) or a GType handle. */
|
|
43
|
+
object(name: string, nick: string, blurb: string, flags: number, gtype: unknown): ParamSpecDescriptor;
|
|
44
|
+
/** A boxed-typed property; `gtype` is a boxed class ctor (its `$gtype` is read) or a GType handle. */
|
|
45
|
+
boxed(name: string, nick: string, blurb: string, flags: number, gtype: unknown): ParamSpecDescriptor;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** A `meta.Signals` entry for {@link GObjectNamespace.registerClass}. */
|
|
49
|
+
export interface SignalDeclaration {
|
|
50
|
+
/** Parameter types in the node-gi vocabulary (e.g. `'int'`, `'string'`, `'object'`). */
|
|
51
|
+
param_types?: string[];
|
|
52
|
+
/** Return type (default `'void'`). */
|
|
53
|
+
return_type?: string;
|
|
54
|
+
/** `GSignalFlags` bitfield (default `RUN_LAST`). */
|
|
55
|
+
flags?: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The class-registration metadata accepted by {@link GObjectNamespace.registerClass}. */
|
|
59
|
+
export interface RegisterClassMeta {
|
|
60
|
+
GTypeName?: string;
|
|
61
|
+
Properties?: Record<string, ParamSpecDescriptor>;
|
|
62
|
+
Signals?: Record<string, SignalDeclaration>;
|
|
63
|
+
/**
|
|
64
|
+
* A Gtk.Widget composite template: inline UI-XML (`Uint8Array`/Buffer or string)
|
|
65
|
+
* or a `"resource:///…"` path string. Installed on the subclass in `class_init`;
|
|
66
|
+
* `gtk_widget_init_template` runs at construction. (Gtk.Widget subclasses only.)
|
|
67
|
+
*/
|
|
68
|
+
Template?: Uint8Array | string;
|
|
69
|
+
/** Template child ids exposed publicly on the instance as `this.<name>`. */
|
|
70
|
+
Children?: string[];
|
|
71
|
+
/** Template child ids exposed privately on the instance as `this._<name>`. */
|
|
72
|
+
InternalChildren?: string[];
|
|
73
|
+
/** `gtk_widget_class_set_css_name` for the subclass (Gtk.Widget subclasses only). */
|
|
74
|
+
CssName?: string;
|
|
75
|
+
[key: string]: unknown;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The extra statics the `GObject` namespace carries on top of its introspected
|
|
80
|
+
* members (reached via `requireGi('GObject')`) — the GJS-shaped class-registration
|
|
81
|
+
* surface.
|
|
82
|
+
*/
|
|
83
|
+
export interface GObjectNamespace extends GiNamespace {
|
|
84
|
+
/**
|
|
85
|
+
* Register a GObject subclass declared as a JS class. Supports both
|
|
86
|
+
* `registerClass(class)` and `registerClass(meta, class)`. Returns a
|
|
87
|
+
* constructor whose `new`-ed instances are usable as GObjects (property get/set,
|
|
88
|
+
* `.connect/.emit/.disconnect`) and expose the user class's own prototype
|
|
89
|
+
* methods. `vfunc_<name>` prototype methods override the parent GObject vfuncs.
|
|
90
|
+
*/
|
|
91
|
+
registerClass(klass: Function): Function;
|
|
92
|
+
registerClass(meta: RegisterClassMeta, klass: Function): Function;
|
|
93
|
+
ParamSpec: ParamSpecFactories;
|
|
94
|
+
/**
|
|
95
|
+
* The FULL introspected `GParamFlags` bitfield (READABLE/WRITABLE/READWRITE/
|
|
96
|
+
* CONSTRUCT/CONSTRUCT_ONLY/LAX_VALIDATION/STATIC_*/EXPLICIT_NOTIFY/DEPRECATED/
|
|
97
|
+
* …) — the named members below are the common convenience bits; the index
|
|
98
|
+
* signature covers the remaining introspected members.
|
|
99
|
+
*/
|
|
100
|
+
ParamFlags: {
|
|
101
|
+
READABLE: number;
|
|
102
|
+
WRITABLE: number;
|
|
103
|
+
READWRITE: number;
|
|
104
|
+
CONSTRUCT: number;
|
|
105
|
+
CONSTRUCT_ONLY: number;
|
|
106
|
+
[member: string]: number;
|
|
107
|
+
};
|
|
108
|
+
/** The FULL introspected `GSignalFlags` bitfield (RUN_FIRST/RUN_LAST/RUN_CLEANUP/NO_RECURSE/DETAILED/ACTION/NO_HOOKS/MUST_COLLECT/DEPRECATED/…). */
|
|
109
|
+
SignalFlags: { RUN_FIRST: number; RUN_LAST: number; RUN_CLEANUP: number; [member: string]: number };
|
|
110
|
+
/**
|
|
111
|
+
* `GObject.Value` — `new GObject.Value()` / `new GObject.Value(gtype, value)`
|
|
112
|
+
* build a GValue; the boxed instance exposes `.init(gtype)`/`.set_*`/`.get_*`/
|
|
113
|
+
* `.copy`/`.unset`; static `type_compatible`/`type_transformable` route to the
|
|
114
|
+
* engine. `value instanceof GObject.Value` recognises a wrapped GValue.
|
|
115
|
+
*/
|
|
116
|
+
Value: { new (): unknown; new (gtype: unknown, value: unknown): unknown; [staticMethod: string]: unknown };
|
|
117
|
+
/** gjs's fake enum for signal accumulators. */
|
|
118
|
+
AccumulatorType: { NONE: number; FIRST_WINS: number; TRUE_HANDLED: number };
|
|
119
|
+
/** Block every handler on `instance` connected with `fn`; returns the count matched. */
|
|
120
|
+
signal_handlers_block_by_func(instance: unknown, fn: Function): number;
|
|
121
|
+
/** Unblock every handler on `instance` connected with `fn`; returns the count matched. */
|
|
122
|
+
signal_handlers_unblock_by_func(instance: unknown, fn: Function): number;
|
|
123
|
+
/** Disconnect every handler on `instance` connected with `fn`; returns the count matched. */
|
|
124
|
+
signal_handlers_disconnect_by_func(instance: unknown, fn: Function): number;
|
|
125
|
+
/** Connect `handler` to `object`'s `name` signal via the instance's own `.connect`. */
|
|
126
|
+
signal_connect(object: unknown, name: string, handler: Function): number;
|
|
127
|
+
/** Connect `handler` in the after-phase via the instance's own `.connect_after`. */
|
|
128
|
+
signal_connect_after(object: unknown, name: string, handler: Function): number;
|
|
129
|
+
/** Emit `name` on `object` via the instance's own `.emit`. */
|
|
130
|
+
signal_emit_by_name(object: unknown, ...nameAndArgs: unknown[]): unknown;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A GJS-shaped GLib.Variant instance (reached via `new GLib.Variant(sig, value)`
|
|
135
|
+
* or returned/unpacked from the engine). Mirrors the GJS GLib.Variant override.
|
|
136
|
+
*/
|
|
137
|
+
export interface Variant {
|
|
138
|
+
/** Single-level unpack: container children stay {@link Variant}s. */
|
|
139
|
+
unpack(): unknown;
|
|
140
|
+
/**
|
|
141
|
+
* Deep unpack: container children are unpacked to JS, but a nested `v`
|
|
142
|
+
* (variant) value — e.g. an `a{sv}` value — STAYS a {@link Variant}.
|
|
143
|
+
*/
|
|
144
|
+
deepUnpack(): unknown;
|
|
145
|
+
/** Backwards-compatible alias of {@link Variant.deepUnpack}. */
|
|
146
|
+
deep_unpack(): unknown;
|
|
147
|
+
/** Fully recursive unpack to plain JS (nested `v` variants are unwrapped). */
|
|
148
|
+
recursiveUnpack(): unknown;
|
|
149
|
+
/** The GVariant type string (e.g. `"a{sv}"`). */
|
|
150
|
+
get_type_string(): string;
|
|
151
|
+
toString(): string;
|
|
152
|
+
/** Other GVariant methods (n_children, get_child_value, print, …). */
|
|
153
|
+
[method: string]: unknown;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* `GLib.Variant` as a class-like constructor surfaced on the GLib namespace.
|
|
158
|
+
* The deprecated `GLib.Variant.new(sig, value)` alias is reached via the static
|
|
159
|
+
* index signature.
|
|
160
|
+
*/
|
|
161
|
+
export interface VariantConstructor {
|
|
162
|
+
new (signature: string, value?: unknown): Variant;
|
|
163
|
+
[staticMethod: string]: unknown;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* The extra statics the `GLib` namespace carries on top of its introspected
|
|
168
|
+
* members (reached via `requireGi('GLib')`) — the GJS-shaped `GLib.Variant`
|
|
169
|
+
* ergonomics replace the introspected struct-based Variant.
|
|
170
|
+
*/
|
|
171
|
+
export interface GLibNamespace extends GiNamespace {
|
|
172
|
+
Variant: VariantConstructor;
|
|
173
|
+
/**
|
|
174
|
+
* Pack `fields` (string / Uint8Array / {@link Variant} values) into an `a{sv}` and
|
|
175
|
+
* hand it to `g_log_variant` — gjs's `GLib.log_structured`.
|
|
176
|
+
*/
|
|
177
|
+
log_structured(logDomain: string, logLevel: number, fields: Record<string, unknown>): void;
|
|
178
|
+
/** One-shot `idle_add` — the callback runs once, then the source is removed. */
|
|
179
|
+
idle_add_once(priority: number, callback: () => void): number;
|
|
180
|
+
/** One-shot `timeout_add` — the callback runs once, then the source is removed. */
|
|
181
|
+
timeout_add_once(priority: number, interval: number, callback: () => void): number;
|
|
182
|
+
/** One-shot `timeout_add_seconds` — the callback runs once, then the source is removed. */
|
|
183
|
+
timeout_add_seconds_once(priority: number, interval: number, callback: () => void): number;
|
|
184
|
+
}
|
|
185
|
+
|
|
13
186
|
/**
|
|
14
187
|
* Require a GObject-Introspection namespace and return a GJS-shaped namespace
|
|
15
188
|
* object. The Node twin of `import Ns from 'gi://Ns?version=X'` /
|
|
16
189
|
* `imports.gi.Ns`. Members are resolved lazily from introspection: namespace
|
|
17
190
|
* functions become callables, GObject types become constructors whose instances
|
|
18
191
|
* expose `.method(...)`, `.prop` get/set and `.connect()/.emit()/.disconnect()`.
|
|
192
|
+
*
|
|
193
|
+
* The `GObject` namespace additionally carries the GJS runtime statics
|
|
194
|
+
* (`registerClass`, `ParamSpec`, `ParamFlags`, `SignalFlags`) — see
|
|
195
|
+
* {@link GObjectNamespace}. The `GLib` namespace carries the GJS-shaped
|
|
196
|
+
* `GLib.Variant` ergonomics — see {@link GLibNamespace}.
|
|
19
197
|
*/
|
|
20
198
|
export function requireGi(namespace: string, version?: string): GiNamespace;
|
|
21
199
|
|