gnim 1.0.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/LICENSE +21 -0
- package/README.md +44 -0
- package/dist/dbus.d.ts +141 -0
- package/dist/dbus.js +609 -0
- package/dist/fetch.d.ts +87 -0
- package/dist/fetch.js +303 -0
- package/dist/gnome/jsx-runtime.d.ts +5 -0
- package/dist/gnome/jsx-runtime.js +98 -0
- package/dist/gnome/signalTracker.d.ts +6 -0
- package/dist/gnome/signalTracker.js +5 -0
- package/dist/gobject.d.ts +161 -0
- package/dist/gobject.js +252 -0
- package/dist/gtk3/jsx-runtime.d.ts +5 -0
- package/dist/gtk3/jsx-runtime.js +143 -0
- package/dist/gtk3/style.d.ts +4 -0
- package/dist/gtk3/style.js +25 -0
- package/dist/gtk4/jsx-runtime.d.ts +5 -0
- package/dist/gtk4/jsx-runtime.js +143 -0
- package/dist/gtk4/style.d.ts +4 -0
- package/dist/gtk4/style.js +25 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +74 -0
- package/dist/jsx/For.d.ts +25 -0
- package/dist/jsx/For.js +66 -0
- package/dist/jsx/Fragment.d.ts +28 -0
- package/dist/jsx/Fragment.js +76 -0
- package/dist/jsx/This.d.ts +28 -0
- package/dist/jsx/This.js +64 -0
- package/dist/jsx/With.d.ts +17 -0
- package/dist/jsx/With.js +34 -0
- package/dist/jsx/env.d.ts +20 -0
- package/dist/jsx/env.js +14 -0
- package/dist/jsx/index.d.ts +7 -0
- package/dist/jsx/index.js +7 -0
- package/dist/jsx/jsx.d.ts +83 -0
- package/dist/jsx/jsx.js +121 -0
- package/dist/jsx/scope.d.ts +99 -0
- package/dist/jsx/scope.js +159 -0
- package/dist/jsx/state.d.ts +117 -0
- package/dist/jsx/state.js +238 -0
- package/dist/util.d.ts +12 -0
- package/dist/util.js +65 -0
- package/package.json +103 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Aylur
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Gnim
|
|
2
|
+
|
|
3
|
+
Library which brings JSX and reactivity to GNOME JavaScript.
|
|
4
|
+
|
|
5
|
+
If you are not already familiar with GJS and GObject, you should read
|
|
6
|
+
[gjs.guide](https://gjs.guide/) first.
|
|
7
|
+
|
|
8
|
+
This library provides:
|
|
9
|
+
|
|
10
|
+
- [JSX and reactivity](https://aylur.github.io/gnim/jsx) for both Gtk
|
|
11
|
+
Applications and Gnome extensions
|
|
12
|
+
- [GObject decorators](https://aylur.github.io/gnim/gobject) for a convenient
|
|
13
|
+
and type safe way for subclassing GObjects
|
|
14
|
+
- [DBus decorators](https://aylur.github.io/gnim/dbus) for a convenient and type
|
|
15
|
+
safe way for implementing DBus services and proxies.
|
|
16
|
+
|
|
17
|
+
## Obligatory Counter Example
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
function Counter() {
|
|
21
|
+
const [counter, setCounter] = createState(0)
|
|
22
|
+
|
|
23
|
+
function increment() {
|
|
24
|
+
setCounter((v) => v + 1)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<Gtk.Box spacing={8}>
|
|
29
|
+
<Gtk.Label label={counter((c) => c.toString())} />
|
|
30
|
+
<Gtk.Button onClicked={increment}>Increment</Gtk.Button>
|
|
31
|
+
</Gtk.Box>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Example apps using Gnim
|
|
37
|
+
|
|
38
|
+
- [icon-theme-browser](https://github.com/Aylur/icon-theme-browser)
|
|
39
|
+
|
|
40
|
+
## Credits
|
|
41
|
+
|
|
42
|
+
- [JU12000](https://github.com/JU12000) for suggesting the name Gnim
|
|
43
|
+
- [Azazel-Woodwind](https://github.com/Azazel-Woodwind) for a lot of early
|
|
44
|
+
testing
|
package/dist/dbus.d.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A {@link Service} currently only allows interfacing with a single interface of a remote object.
|
|
3
|
+
* In the future I want to come up with an API to be able to create Service objects for multiple
|
|
4
|
+
* interfaces of an object at the same time. Example usage would be for example combining
|
|
5
|
+
* "org.mpris.MediaPlayer2" and "org.mpris.MediaPlayer2.Player" into a single object.
|
|
6
|
+
*/
|
|
7
|
+
import Gio from "gi://Gio";
|
|
8
|
+
import GLib from "gi://GLib";
|
|
9
|
+
import GObject from "gi://GObject";
|
|
10
|
+
declare const info: unique symbol;
|
|
11
|
+
declare const internals: unique symbol;
|
|
12
|
+
declare const remoteMethod: unique symbol;
|
|
13
|
+
declare const remoteMethodAsync: unique symbol;
|
|
14
|
+
declare const remotePropertySet: unique symbol;
|
|
15
|
+
/**
|
|
16
|
+
* Base type for DBus services and proxies. Interface name is set with
|
|
17
|
+
* the {@link iface} decorator which also register it as a GObject type.
|
|
18
|
+
*/
|
|
19
|
+
export declare class Service extends GObject.Object {
|
|
20
|
+
#private;
|
|
21
|
+
static [info]?: Gio.DBusInterfaceInfo;
|
|
22
|
+
[internals]: {
|
|
23
|
+
dbusObject?: Gio.DBusExportedObject;
|
|
24
|
+
proxy?: Gio.DBusProxy;
|
|
25
|
+
priv: Record<string | symbol, unknown>;
|
|
26
|
+
onStop: Set<() => void>;
|
|
27
|
+
};
|
|
28
|
+
constructor();
|
|
29
|
+
notify(propertyName: Extract<keyof this, string> | (string & {})): void;
|
|
30
|
+
emit(name: string, ...params: unknown[]): void;
|
|
31
|
+
serve({ busType, name, objectPath, flags, timeout, }?: {
|
|
32
|
+
busType?: Gio.BusType;
|
|
33
|
+
name?: string;
|
|
34
|
+
objectPath?: string;
|
|
35
|
+
flags?: Gio.BusNameOwnerFlags;
|
|
36
|
+
timeout?: number;
|
|
37
|
+
}): Promise<this>;
|
|
38
|
+
[remoteMethod](methodName: string, args: unknown[]): GLib.Variant;
|
|
39
|
+
[remoteMethodAsync](methodName: string, args: unknown[]): Promise<GLib.Variant>;
|
|
40
|
+
[remotePropertySet](name: string, value: unknown): void;
|
|
41
|
+
proxy({ bus, name, objectPath, flags, timeout, }?: {
|
|
42
|
+
bus?: Gio.DBusConnection;
|
|
43
|
+
name?: string;
|
|
44
|
+
objectPath?: string;
|
|
45
|
+
flags?: Gio.DBusProxyFlags;
|
|
46
|
+
timeout?: number;
|
|
47
|
+
}): Promise<this>;
|
|
48
|
+
stop(): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Registers a {@link Service} as a dbus interface.
|
|
52
|
+
*
|
|
53
|
+
* @param name Interface name of the object. For example "org.gnome.Shell.SearchProvider2"
|
|
54
|
+
* @param gobjectMetaInfo optional properties to pass to {@link GObject.registerClass}
|
|
55
|
+
*/
|
|
56
|
+
export declare function iface(name: string, gobjectMetaInfo?: GObject.MetaInfo<never, Array<{
|
|
57
|
+
$gtype: GObject.GType;
|
|
58
|
+
}>, never>): (cls: {
|
|
59
|
+
new (...args: any[]): Service;
|
|
60
|
+
}, ctx: ClassDecoratorContext) => void;
|
|
61
|
+
type DBusType = string | {
|
|
62
|
+
type: string;
|
|
63
|
+
name: string;
|
|
64
|
+
};
|
|
65
|
+
type InferVariantTuple<NestedVariant extends string> = NestedVariant extends string ? Array<any> : never;
|
|
66
|
+
/**
|
|
67
|
+
* Infer the runtime JavaScript type of a Variant type
|
|
68
|
+
*/
|
|
69
|
+
export type InferVariantType<T extends string> = T extends "v" ? Variant<any> : T extends "b" ? boolean : T extends "y" | "n" | "q" | "i" | "u" | "x" | "t" | "h" | "d" ? number : T extends "s" | "g" ? string : T extends "o" ? `/${string}` : T extends `a{${infer K}${infer S}}` ? S extends string ? K extends string ? Record<Extract<InferVariantType<K>, string | number>, InferVariantType<S>> : never : never : T extends `a${infer S}` ? S extends string ? Array<InferVariantType<S>> : never : T extends `(${infer S})` ? S extends string ? InferVariantTuple<S> : never : never;
|
|
70
|
+
type InferVariantTypes<T extends Array<DBusType>> = {
|
|
71
|
+
[K in keyof T]: T[K] extends string ? InferVariantType<T[K]> : T[K] extends {
|
|
72
|
+
type: infer S;
|
|
73
|
+
} ? S extends string ? InferVariantType<S> : never : unknown;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Registers a method.
|
|
77
|
+
* You should prefer using {@link methodAsync} when proxying, due to IO blocking.
|
|
78
|
+
* Note that this is functionally the same as {@link methodAsync} on exported objects.
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function method<const InArgs extends Array<DBusType>, const OutArgs extends Array<DBusType>>(inArgs: InArgs, outArgs: OutArgs): (method: (this: Service, ...args: InferVariantTypes<InArgs>) => InferVariantTypes<OutArgs>, ctx: ClassMethodDecoratorContext<Service, typeof method>) => void;
|
|
82
|
+
/**
|
|
83
|
+
* Registers a method.
|
|
84
|
+
* You should prefer using {@link methodAsync} when proxying, due to IO blocking.
|
|
85
|
+
* Note that this is functionally the same as {@link methodAsync} on exported objects.
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare function method<const InArgs extends Array<DBusType>>(...inArgs: InArgs): (method: (this: Service, ...args: InferVariantTypes<InArgs>) => void, ctx: ClassMethodDecoratorContext<Service, typeof method>) => void;
|
|
89
|
+
/**
|
|
90
|
+
* Registers a method.
|
|
91
|
+
* You should prefer using this over {@link method} when proxying, since this does not block IO.
|
|
92
|
+
* Note that this is functionally the same as {@link method} on exported objects.
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function methodAsync<const InArgs extends Array<DBusType>, const OutArgs extends Array<DBusType>>(inArgs: InArgs, outArgs: OutArgs): (method: (this: Service, ...args: InferVariantTypes<InArgs>) => Promise<InferVariantTypes<OutArgs>>, ctx: ClassMethodDecoratorContext<Service, typeof method>) => void;
|
|
96
|
+
/**
|
|
97
|
+
* Registers a method.
|
|
98
|
+
* You should prefer using this over {@link method} when proxying, since this does not block IO.
|
|
99
|
+
* Note that this is functionally the same as {@link method} on exported objects.
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare function methodAsync<const InArgs extends Array<DBusType>>(...inArgs: InArgs): (method: (this: Service, ...args: InferVariantTypes<InArgs>) => Promise<void>, ctx: ClassMethodDecoratorContext<Service, typeof method>) => void;
|
|
103
|
+
/**
|
|
104
|
+
* Registers a read-write property. When a new value is assigned the notify signal
|
|
105
|
+
* is automatically emitted on the local and exported object.
|
|
106
|
+
*
|
|
107
|
+
* Note that new values are checked by reference so assigning the same object will
|
|
108
|
+
* not emit the notify signal.
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export declare function property<T extends string>(type: T): (_: void, ctx: ClassFieldDecoratorContext<Service, InferVariantType<T>>) => (this: Service, init: InferVariantType<T>) => InferVariantType<T>;
|
|
112
|
+
/**
|
|
113
|
+
* Registers a read-only property. Can be used in conjuction with {@link setter} to define
|
|
114
|
+
* read-write properties as accessors.
|
|
115
|
+
*
|
|
116
|
+
* Note that you will need to explicitly emit the notify signal.
|
|
117
|
+
*/
|
|
118
|
+
export declare function getter<T extends string>(type: T): (getter: (this: Service) => InferVariantType<T>, ctx: ClassGetterDecoratorContext<Service, InferVariantType<T>>) => (this: Service) => InferVariantType<T>;
|
|
119
|
+
/**
|
|
120
|
+
* Registers a write-only property. Can be used in conjuction with {@link getter} to define
|
|
121
|
+
* read-write properties as accessors.
|
|
122
|
+
*
|
|
123
|
+
* Note that you will need to explicitly emit the notify signal.
|
|
124
|
+
*/
|
|
125
|
+
export declare function setter<T extends string>(type: T): (setter: (this: Service, value: InferVariantType<T>) => void, ctx: ClassSetterDecoratorContext<Service, InferVariantType<T>>) => (this: Service, value: InferVariantType<T>) => void;
|
|
126
|
+
/**
|
|
127
|
+
* Registers a signal which when invoked will emit the signal
|
|
128
|
+
* on the local object and the exported object.
|
|
129
|
+
*
|
|
130
|
+
* Note that its not possible to emit signals on remote objects through proxies.
|
|
131
|
+
*/
|
|
132
|
+
export declare function signal<const Params extends Array<DBusType>>(...params: Params): (method: (this: Service, ...params: InferVariantTypes<Params>) => void, ctx: ClassMethodDecoratorContext<Service, typeof method>) => typeof method;
|
|
133
|
+
declare class GLibVariant<T extends string = any> extends GLib.Variant<T> {
|
|
134
|
+
static new<T extends string>(signature: T, value: InferVariantType<T>): GLib.Variant<T>;
|
|
135
|
+
constructor(signature: T, value: InferVariantType<T>);
|
|
136
|
+
deepUnpack<V = InferVariantType<T>>(): V;
|
|
137
|
+
deep_unpack<V = InferVariantType<T>>(): V;
|
|
138
|
+
}
|
|
139
|
+
export declare const Variant: typeof GLibVariant;
|
|
140
|
+
export type Variant<T extends string = any> = GLibVariant<T>;
|
|
141
|
+
export {};
|