@ts-for-gir/templates 4.0.0-beta.26
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 +24 -0
- package/templates/README-GJS.md +129 -0
- package/templates/README.md +88 -0
- package/templates/cogl-2-0.d.ts +1 -0
- package/templates/gi.d.ts +8 -0
- package/templates/gimp-3.0.d.ts +24 -0
- package/templates/gio-2.0.d.ts +37 -0
- package/templates/gjs/cairo-1.0.d.ts +0 -0
- package/templates/gjs/cairo.d.ts +855 -0
- package/templates/gjs/cairo.js +4 -0
- package/templates/gjs/console.d.ts +30 -0
- package/templates/gjs/console.js +4 -0
- package/templates/gjs/dom.d.ts +312 -0
- package/templates/gjs/dom.js +1 -0
- package/templates/gjs/gettext.d.ts +48 -0
- package/templates/gjs/gettext.js +4 -0
- package/templates/gjs/gjs-ambient.d.ts +26 -0
- package/templates/gjs/gjs-ambient.js +1 -0
- package/templates/gjs/gjs.d.ts +753 -0
- package/templates/gjs/gjs.js +4 -0
- package/templates/gjs/system.d.ts +187 -0
- package/templates/gjs/system.js +4 -0
- package/templates/glib-2.0.d.ts +1125 -0
- package/templates/gobject-2.0.d.ts +361 -0
- package/templates/granite-1.0.d.ts +8 -0
- package/templates/granite-7.0.d.ts +8 -0
- package/templates/gstbase-0.10.d.ts +6 -0
- package/templates/index-locally.d.ts +8 -0
- package/templates/index.d.ts +17 -0
- package/templates/index.js +4 -0
- package/templates/module-ambient.d.ts +18 -0
- package/templates/module-ambient.js +1 -0
- package/templates/module-import.d.ts +16 -0
- package/templates/module-import.js +2 -0
- package/templates/module.append.d.ts +17 -0
- package/templates/module.d.ts +53 -0
- package/templates/module.js +4 -0
- package/templates/package.json +95 -0
- package/templates/rygelserver-2.6.d.ts +4 -0
- package/templates/tsconfig.json +32 -0
- package/templates/typedoc.json +26 -0
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ts-for-gir/templates",
|
|
3
|
+
"version": "4.0.0-beta.26",
|
|
4
|
+
"description": "Templates for ts-for-gir",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "package.json",
|
|
7
|
+
"module": "package.json",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./package.json": "./package.json"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/gjsify/ts-for-gir.git"
|
|
14
|
+
},
|
|
15
|
+
"author": "Pascal Garber <pascal@artandcode.studio>",
|
|
16
|
+
"files": [
|
|
17
|
+
"templates"
|
|
18
|
+
],
|
|
19
|
+
"license": "Apache-2.0",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/gjsify/ts-for-gir/issues"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/gjsify/ts-for-gir#readme"
|
|
24
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
<%# This template is used for the README.md of @girs/gjs if the Option `package` is enabled %>
|
|
2
|
+
# <%- packageName %>
|
|
3
|
+
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
<%- PACKAGE_DESC %> using [<%- APP_NAME %>](<%- APP_SOURCE %>) v<%- APP_VERSION %>.
|
|
8
|
+
|
|
9
|
+
[GJS](https://gitlab.gnome.org/GNOME/gjs) is a JavaScript runtime for the GNOME ecosystem. Using GJS and the type definitions in this NPM package, you can build GTK applications in JavaScript or TypeScript with type checking, better autocompletion and inline documentations.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
To use this type definitions, install them with NPM:
|
|
14
|
+
```bash
|
|
15
|
+
npm install <%- npmScope %>/<%- importName %>
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
<%_ const pkg = await dep.get(packageName) _%>
|
|
19
|
+
<%_ if(!pkg){ _%>
|
|
20
|
+
<%_ return `Package with package name "${packageName}" not found!` _%>
|
|
21
|
+
<%_ } _%>
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
You can import this package into your project like this:
|
|
26
|
+
```ts
|
|
27
|
+
import <%- pkg.namespace %> from '<%- pkg.importPath %>';
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or if you prefer CommonJS, you can also use this:
|
|
31
|
+
```ts
|
|
32
|
+
const <%- pkg.namespace %> = require('<%- pkg.importPath %>');
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Global types
|
|
36
|
+
|
|
37
|
+
After the import, the global types of GJS are also available:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import '@girs/gjs';
|
|
41
|
+
|
|
42
|
+
print('Hello World from print');
|
|
43
|
+
|
|
44
|
+
const ByteArray = imports.byteArray;
|
|
45
|
+
|
|
46
|
+
// And so on...
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Global DOM types
|
|
50
|
+
|
|
51
|
+
Some types that conflict with the DOM are outsourced to allow frameworks like Gjsify to rebuild the DOM API without causing type conflicts.
|
|
52
|
+
But you can easily import them:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import '@girs/gjs/dom';
|
|
56
|
+
|
|
57
|
+
console.log('Hello World from console');
|
|
58
|
+
|
|
59
|
+
const encoder = new TextEncoder();
|
|
60
|
+
const encoded = encoder.encode('𝓽𝓮𝔁𝓽');
|
|
61
|
+
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
// ...
|
|
64
|
+
}, 1000);
|
|
65
|
+
|
|
66
|
+
// And so on...
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
To avoid a type conflict with the DOM types it is recommended to either modify your `tsconfig.json` or `jsconfig.json` file to exclude the DOM lib, or to enable the `noLib` property.
|
|
70
|
+
|
|
71
|
+
### Ambient Modules
|
|
72
|
+
|
|
73
|
+
You can import the built in [ambient modules](https://github.com/gjsify/ts-for-gir/tree/main/packages/cli#ambient-modules) of GJS.
|
|
74
|
+
For this you need to include the `<%- npmScope %>/<%- importName %>` or `<%- npmScope %>/<%- importName %>/ambient` in your `tsconfig` or entry point Typescript file:
|
|
75
|
+
|
|
76
|
+
`index.ts`:
|
|
77
|
+
```ts
|
|
78
|
+
import '<%- npmScope %>/<%- importName %>'
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`tsconfig.json`:
|
|
82
|
+
```json
|
|
83
|
+
{
|
|
84
|
+
"compilerOptions": {
|
|
85
|
+
...
|
|
86
|
+
},
|
|
87
|
+
"include": ["<%- npmScope %>/<%- importName %>"],
|
|
88
|
+
...
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Now you can import `gettext`, `system` and `cairo` in ESM style with Typescript support:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import gettext from 'gettext';
|
|
96
|
+
import system from 'system';
|
|
97
|
+
import cairo from 'cairo';
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### GIR modules
|
|
101
|
+
|
|
102
|
+
If you want to have types for [GObject Introspection](https://gi.readthedocs.io/en/latest/) modules, you have to add them to your dependencies and import them as well, see the description of these modules, e.g. [gtk-4.0](https://www.npmjs.com/package/@girs/gtk-4.0), [gio-2.0](https://www.npmjs.com/package/@girs/gio-2.0), [adw-1](https://www.npmjs.com/package/@girs/adw-1) and [much more](https://github.com/gjsify/types).
|
|
103
|
+
|
|
104
|
+
These types will then be available to you:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
import '@girs/gjs'
|
|
108
|
+
import '@girs/gjs/dom'
|
|
109
|
+
import '@girs/gio-2.0'
|
|
110
|
+
import '@girs/gtk-4.0'
|
|
111
|
+
import '@girs/adw-1'
|
|
112
|
+
|
|
113
|
+
import Gio from 'gi://Gio?version=2.0';
|
|
114
|
+
import Gtk from 'gi://Gtk?version=4.0';
|
|
115
|
+
import Adwaita from 'gi://adw?version=1';
|
|
116
|
+
|
|
117
|
+
const button = new Gtk.Button();
|
|
118
|
+
|
|
119
|
+
// ...
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Bundle
|
|
124
|
+
|
|
125
|
+
Depending on your project configuration, it is recommended to use a bundler like [esbuild](https://esbuild.github.io/). You can find examples using different bundlers [here](https://github.com/gjsify/ts-for-gir/tree/main/examples).
|
|
126
|
+
|
|
127
|
+
## Other packages
|
|
128
|
+
|
|
129
|
+
All existing pre-generated packages can be found on [gjsify/types](https://github.com/gjsify/types).
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<%# This template is used if the Option `package` is enabled %>
|
|
2
|
+
# <%- packageName %>
|
|
3
|
+
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
<%- PACKAGE_DESC %> using [<%- APP_NAME %>](<%- APP_SOURCE %>) v<%- APP_VERSION %>.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
To use this type definitions, install them with NPM:
|
|
13
|
+
```bash
|
|
14
|
+
npm install <%- npmScope %>/<%- importName %>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
<%_ const pkg = await dep.get(packageName) _%>
|
|
18
|
+
<%_ if(!pkg){ _%>
|
|
19
|
+
<%_ return `Package with package name "${packageName}" not found!` _%>
|
|
20
|
+
<%_ } _%>
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
You can import this package into your project like this:
|
|
24
|
+
```ts
|
|
25
|
+
import <%- pkg.namespace %> from '<%- pkg.importPath %>';
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Ambient Modules
|
|
29
|
+
|
|
30
|
+
You can also use [ambient modules](https://github.com/gjsify/ts-for-gir/tree/main/packages/cli#ambient-modules) to import this module like you would do this in JavaScript.
|
|
31
|
+
For this you need to include `<%- npmScope %>/<%- importName %>` or `<%- npmScope %>/<%- importName %>/ambient` in your `tsconfig` or entry point Typescript file:
|
|
32
|
+
|
|
33
|
+
`index.ts`:
|
|
34
|
+
```ts
|
|
35
|
+
import '<%- npmScope %>/<%- importName %>'
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`tsconfig.json`:
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"compilerOptions": {
|
|
42
|
+
...
|
|
43
|
+
},
|
|
44
|
+
"include": ["<%- npmScope %>/<%- importName %>"],
|
|
45
|
+
...
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Now you can import the ambient module with TypeScript support:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import <%= pkg.namespace %> from 'gi://<%= pkg.namespace %>?version=<%= pkg.version %>';
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Global import
|
|
56
|
+
|
|
57
|
+
You can also import the module with Typescript support using the global `imports.gi` object of GJS.
|
|
58
|
+
For this you need to include `<%- npmScope %>/<%- importName %>` or `<%- npmScope %>/<%- importName %>/import` in your `tsconfig` or entry point Typescript file:
|
|
59
|
+
|
|
60
|
+
`index.ts`:
|
|
61
|
+
```ts
|
|
62
|
+
import '<%- npmScope %>/<%- importName %>'
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`tsconfig.json`:
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"compilerOptions": {
|
|
69
|
+
...
|
|
70
|
+
},
|
|
71
|
+
"include": ["<%- npmScope %>/<%- importName %>"],
|
|
72
|
+
...
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Now you have also type support for this, too:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
const <%= pkg.namespace %> = imports.gi.<%= pkg.namespace %>;
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Bundle
|
|
83
|
+
|
|
84
|
+
Depending on your project configuration, it is recommended to use a bundler like [esbuild](https://esbuild.github.io/). You can find examples using different bundlers [here](https://github.com/gjsify/ts-for-gir/tree/main/examples).
|
|
85
|
+
|
|
86
|
+
## Other packages
|
|
87
|
+
|
|
88
|
+
All existing pre-generated packages can be found on [gjsify/types](https://github.com/gjsify/types).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// WORKAROUND: As long as ParamObject is not generated
|
|
3
|
+
export class ParamObject extends GObject.ParamSpec {}
|
|
4
|
+
|
|
5
|
+
export namespace ParamObject {
|
|
6
|
+
// Signal signatures
|
|
7
|
+
interface SignalSignatures extends GObject.ParamSpec.SignalSignatures {}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// WORKAROUND: As long as ParamItem is not generated
|
|
11
|
+
export class ParamItem extends GObject.ParamSpec {}
|
|
12
|
+
|
|
13
|
+
export namespace ParamItem {
|
|
14
|
+
// Signal signatures
|
|
15
|
+
interface SignalSignatures extends GObject.ParamSpec.SignalSignatures {}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// WORKAROUND: As long as ParamArray is not generated
|
|
19
|
+
export class ParamArray extends GObject.ParamSpec {}
|
|
20
|
+
|
|
21
|
+
export namespace ParamArray {
|
|
22
|
+
// Signal signatures
|
|
23
|
+
interface SignalSignatures extends GObject.ParamSpec.SignalSignatures {}
|
|
24
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* A convenient helper to create Promise wrappers for asynchronous functions in GJS.
|
|
4
|
+
*
|
|
5
|
+
* This utility replaces the original function on the class prototype with a Promise-based version,
|
|
6
|
+
* allowing the function to be called on any instance of the class, including subclasses.
|
|
7
|
+
* Simply pass the class prototype, the "async" function name, and the "finish" function name as arguments.
|
|
8
|
+
*
|
|
9
|
+
* The function can be used like any other Promise, without the need for a custom wrapper, by leaving out the callback argument.
|
|
10
|
+
* The original function will still be available, and can be used by passing the callback.
|
|
11
|
+
*
|
|
12
|
+
* @param proto - The class prototype that contains the asynchronous function.
|
|
13
|
+
* @param asyncFunc - The name of the asynchronous function.
|
|
14
|
+
* @param finishFunc - The name of the "finish" function that is used to retrieve the result of the asynchronous function.
|
|
15
|
+
*
|
|
16
|
+
* @version Gjs 1.54
|
|
17
|
+
* @see https://gjs.guide/guides/gjs/asynchronous-programming.html#promisify-helper
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```js
|
|
21
|
+
* import Gio from "gi://Gio?version=2.0";
|
|
22
|
+
*
|
|
23
|
+
* Gio._promisify(Gio.InputStream.prototype, 'read_bytes_async', 'read_bytes_finish');
|
|
24
|
+
*
|
|
25
|
+
* try {
|
|
26
|
+
* const inputStream = new Gio.UnixInputStream({fd: 0});
|
|
27
|
+
* const bytes = await inputStream.read_bytes_async(4096, GLib.PRIORITY_DEFAULT, null);
|
|
28
|
+
* } catch (e) {
|
|
29
|
+
* logError(e, 'Failed to read bytes');
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
export function _promisify(proto: any, asyncFunc: string, finishFunc?: string): void
|
|
35
|
+
|
|
36
|
+
/** Temporary Gio.File.prototype fix */
|
|
37
|
+
export const _LocalFilePrototype: typeof File.prototype
|
|
File without changes
|