@gtkx/gir 0.7.0 → 0.9.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 +4 -1
- package/src/types.ts +56 -32
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtkx/gir",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "GObject Introspection file parser for GTKX",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gtk",
|
|
@@ -29,6 +29,9 @@
|
|
|
29
29
|
"files": [
|
|
30
30
|
"src"
|
|
31
31
|
],
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"fast-xml-parser": "^5.3.3"
|
|
34
|
+
},
|
|
32
35
|
"scripts": {
|
|
33
36
|
"test": "vitest run"
|
|
34
37
|
}
|
package/src/types.ts
CHANGED
|
@@ -348,8 +348,8 @@ export type FfiTypeDescriptor = {
|
|
|
348
348
|
itemType?: FfiTypeDescriptor;
|
|
349
349
|
/** List type for arrays (glist, gslist) - indicates native GList/GSList iteration. */
|
|
350
350
|
listType?: "glist" | "gslist";
|
|
351
|
-
/** Trampoline type for callbacks
|
|
352
|
-
trampoline?: "asyncReady" | "destroy" | "
|
|
351
|
+
/** Trampoline type for callbacks. Default is "closure". */
|
|
352
|
+
trampoline?: "asyncReady" | "destroy" | "drawFunc" | "scaleFormatValueFunc";
|
|
353
353
|
/** Source type for asyncReady callback (the GObject source). */
|
|
354
354
|
sourceType?: FfiTypeDescriptor;
|
|
355
355
|
/** Result type for asyncReady callback (the GAsyncResult). */
|
|
@@ -648,15 +648,15 @@ const BASIC_TYPE_MAP = new Map<string, TypeMapping>([
|
|
|
648
648
|
["guchar", { ts: "number", ffi: { type: "int", size: 8, unsigned: true } }],
|
|
649
649
|
["gint", { ts: "number", ffi: { type: "int", size: 32, unsigned: false } }],
|
|
650
650
|
["guint", { ts: "number", ffi: { type: "int", size: 32, unsigned: true } }],
|
|
651
|
-
["gshort", { ts: "number", ffi: { type: "int", size:
|
|
652
|
-
["gushort", { ts: "number", ffi: { type: "int", size:
|
|
651
|
+
["gshort", { ts: "number", ffi: { type: "int", size: 16, unsigned: false } }],
|
|
652
|
+
["gushort", { ts: "number", ffi: { type: "int", size: 16, unsigned: true } }],
|
|
653
653
|
["glong", { ts: "number", ffi: { type: "int", size: 64, unsigned: false } }],
|
|
654
654
|
["gulong", { ts: "number", ffi: { type: "int", size: 64, unsigned: true } }],
|
|
655
655
|
["GType", { ts: "number", ffi: { type: "int", size: 64, unsigned: true } }],
|
|
656
656
|
["gint8", { ts: "number", ffi: { type: "int", size: 8, unsigned: false } }],
|
|
657
657
|
["guint8", { ts: "number", ffi: { type: "int", size: 8, unsigned: true } }],
|
|
658
|
-
["gint16", { ts: "number", ffi: { type: "int", size:
|
|
659
|
-
["guint16", { ts: "number", ffi: { type: "int", size:
|
|
658
|
+
["gint16", { ts: "number", ffi: { type: "int", size: 16, unsigned: false } }],
|
|
659
|
+
["guint16", { ts: "number", ffi: { type: "int", size: 16, unsigned: true } }],
|
|
660
660
|
["gint32", { ts: "number", ffi: { type: "int", size: 32, unsigned: false } }],
|
|
661
661
|
["guint32", { ts: "number", ffi: { type: "int", size: 32, unsigned: true } }],
|
|
662
662
|
["gint64", { ts: "number", ffi: { type: "int", size: 64, unsigned: false } }],
|
|
@@ -727,6 +727,7 @@ export class TypeMapper {
|
|
|
727
727
|
private recordNames: Set<string> = new Set();
|
|
728
728
|
private recordTransforms: Map<string, string> = new Map();
|
|
729
729
|
private recordGlibTypes: Map<string, string> = new Map();
|
|
730
|
+
private skippedClasses: Set<string> = new Set();
|
|
730
731
|
private onEnumUsed?: (enumName: string) => void;
|
|
731
732
|
private onRecordUsed?: (recordName: string) => void;
|
|
732
733
|
private onExternalTypeUsed?: (usage: ExternalTypeUsage) => void;
|
|
@@ -836,6 +837,14 @@ export class TypeMapper {
|
|
|
836
837
|
this.currentNamespace = currentNamespace;
|
|
837
838
|
}
|
|
838
839
|
|
|
840
|
+
registerSkippedClass(name: string): void {
|
|
841
|
+
this.skippedClasses.add(name);
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
clearSkippedClasses(): void {
|
|
845
|
+
this.skippedClasses.clear();
|
|
846
|
+
}
|
|
847
|
+
|
|
839
848
|
/**
|
|
840
849
|
* Maps a GIR type to TypeScript and FFI type descriptors.
|
|
841
850
|
* @param girType - The GIR type to map
|
|
@@ -897,6 +906,12 @@ export class TypeMapper {
|
|
|
897
906
|
if (isExternal) {
|
|
898
907
|
this.onExternalTypeUsed?.(externalType as ExternalTypeUsage);
|
|
899
908
|
} else if (registered.kind === "class" || registered.kind === "interface") {
|
|
909
|
+
if (this.skippedClasses.has(registered.name)) {
|
|
910
|
+
return {
|
|
911
|
+
ts: "unknown",
|
|
912
|
+
ffi: { type: "gobject", borrowed: isReturn },
|
|
913
|
+
};
|
|
914
|
+
}
|
|
900
915
|
this.onSameNamespaceClassUsed?.(registered.transformedName, registered.name);
|
|
901
916
|
} else if (registered.kind === "enum") {
|
|
902
917
|
this.onEnumUsed?.(registered.transformedName);
|
|
@@ -1044,6 +1059,12 @@ export class TypeMapper {
|
|
|
1044
1059
|
if (isExternal) {
|
|
1045
1060
|
this.onExternalTypeUsed?.(externalType as ExternalTypeUsage);
|
|
1046
1061
|
} else if (registered.kind === "class" || registered.kind === "interface") {
|
|
1062
|
+
if (this.skippedClasses.has(registered.name)) {
|
|
1063
|
+
return {
|
|
1064
|
+
ts: "unknown",
|
|
1065
|
+
ffi: { type: "gobject", borrowed: isReturn },
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1047
1068
|
this.onSameNamespaceClassUsed?.(registered.transformedName, registered.name);
|
|
1048
1069
|
}
|
|
1049
1070
|
if (registered.kind === "enum") {
|
|
@@ -1159,25 +1180,22 @@ export class TypeMapper {
|
|
|
1159
1180
|
};
|
|
1160
1181
|
}
|
|
1161
1182
|
|
|
1162
|
-
if (param.type.name === "GLib.SourceFunc" || param.type.name === "SourceFunc") {
|
|
1163
|
-
return {
|
|
1164
|
-
ts: "() => boolean",
|
|
1165
|
-
ffi: {
|
|
1166
|
-
type: "callback",
|
|
1167
|
-
trampoline: "sourceFunc",
|
|
1168
|
-
},
|
|
1169
|
-
};
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
1183
|
if (param.type.name === "Gtk.DrawingAreaDrawFunc" || param.type.name === "DrawingAreaDrawFunc") {
|
|
1184
|
+
this.onExternalTypeUsed?.({
|
|
1185
|
+
namespace: "Cairo",
|
|
1186
|
+
name: "Context",
|
|
1187
|
+
transformedName: "Context",
|
|
1188
|
+
kind: "record",
|
|
1189
|
+
});
|
|
1190
|
+
this.onSameNamespaceClassUsed?.("DrawingArea", "DrawingArea");
|
|
1173
1191
|
return {
|
|
1174
|
-
ts: "(self:
|
|
1192
|
+
ts: "(self: DrawingArea, cr: Cairo.Context, width: number, height: number) => void",
|
|
1175
1193
|
ffi: {
|
|
1176
1194
|
type: "callback",
|
|
1177
1195
|
trampoline: "drawFunc",
|
|
1178
1196
|
argTypes: [
|
|
1179
1197
|
{ type: "gobject", borrowed: true },
|
|
1180
|
-
{ type: "
|
|
1198
|
+
{ type: "boxed", borrowed: true, innerType: "CairoContext" },
|
|
1181
1199
|
{ type: "int", size: 32, unsigned: false },
|
|
1182
1200
|
{ type: "int", size: 32, unsigned: false },
|
|
1183
1201
|
],
|
|
@@ -1185,20 +1203,6 @@ export class TypeMapper {
|
|
|
1185
1203
|
};
|
|
1186
1204
|
}
|
|
1187
1205
|
|
|
1188
|
-
if (param.type.name === "GLib.CompareDataFunc" || param.type.name === "CompareDataFunc") {
|
|
1189
|
-
return {
|
|
1190
|
-
ts: "(a: unknown, b: unknown) => number",
|
|
1191
|
-
ffi: {
|
|
1192
|
-
type: "callback",
|
|
1193
|
-
trampoline: "compareDataFunc",
|
|
1194
|
-
argTypes: [
|
|
1195
|
-
{ type: "gobject", borrowed: true },
|
|
1196
|
-
{ type: "gobject", borrowed: true },
|
|
1197
|
-
],
|
|
1198
|
-
},
|
|
1199
|
-
};
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
1206
|
if (param.type.name === "GLib.Closure" || this.isCallback(param.type.name)) {
|
|
1203
1207
|
return {
|
|
1204
1208
|
ts: "(...args: unknown[]) => unknown",
|
|
@@ -1246,6 +1250,10 @@ export class TypeMapper {
|
|
|
1246
1250
|
"DrawingAreaDrawFunc",
|
|
1247
1251
|
"GLib.CompareDataFunc",
|
|
1248
1252
|
"CompareDataFunc",
|
|
1253
|
+
"GLib.SourceFunc",
|
|
1254
|
+
"SourceFunc",
|
|
1255
|
+
"Gtk.TickCallback",
|
|
1256
|
+
"TickCallback",
|
|
1249
1257
|
];
|
|
1250
1258
|
return allParams.some(
|
|
1251
1259
|
(p) => trampolineCallbacks.includes(p.type.name) && (p.closure === paramIndex || p.destroy === paramIndex),
|
|
@@ -1260,4 +1268,20 @@ export class TypeMapper {
|
|
|
1260
1268
|
isNullable(param: GirParameter): boolean {
|
|
1261
1269
|
return param.nullable === true || param.optional === true;
|
|
1262
1270
|
}
|
|
1271
|
+
|
|
1272
|
+
hasUnsupportedCallback(param: GirParameter): boolean {
|
|
1273
|
+
const supportedCallbacks = [
|
|
1274
|
+
"Gio.AsyncReadyCallback",
|
|
1275
|
+
"GLib.DestroyNotify",
|
|
1276
|
+
"DestroyNotify",
|
|
1277
|
+
"Gtk.DrawingAreaDrawFunc",
|
|
1278
|
+
"DrawingAreaDrawFunc",
|
|
1279
|
+
];
|
|
1280
|
+
|
|
1281
|
+
if (supportedCallbacks.includes(param.type.name)) {
|
|
1282
|
+
return false;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
return param.type.name === "GLib.Closure" || this.isCallback(param.type.name);
|
|
1286
|
+
}
|
|
1263
1287
|
}
|