@gtkx/runtime 1.0.0 → 1.2.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 +1 -1
- package/dist/application-class.d.ts +5 -0
- package/dist/application-class.d.ts.map +1 -1
- package/dist/application-class.js +11 -1
- package/dist/application-class.js.map +1 -1
- package/dist/callback.d.ts +2 -2
- package/dist/callback.d.ts.map +1 -1
- package/dist/callback.js +51 -54
- package/dist/callback.js.map +1 -1
- package/dist/closure.js +1 -1
- package/dist/closure.js.map +1 -1
- package/dist/default-application.d.ts +4 -0
- package/dist/default-application.d.ts.map +1 -0
- package/dist/default-application.js +17 -0
- package/dist/default-application.js.map +1 -0
- package/dist/descriptors.d.ts +34 -9
- package/dist/descriptors.d.ts.map +1 -1
- package/dist/descriptors.js +42 -17
- package/dist/descriptors.js.map +1 -1
- package/dist/exit-hook.js +13 -0
- package/dist/exit-hook.js.map +1 -1
- package/dist/fn.d.ts +5 -0
- package/dist/fn.d.ts.map +1 -1
- package/dist/fn.js +11 -13
- package/dist/fn.js.map +1 -1
- package/dist/folded-lengths.d.ts +16 -0
- package/dist/folded-lengths.d.ts.map +1 -0
- package/dist/folded-lengths.js +38 -0
- package/dist/folded-lengths.js.map +1 -0
- package/dist/internal.d.ts +1 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -0
- package/dist/internal.js.map +1 -1
- package/dist/library.d.ts +2 -1
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +2 -1
- package/dist/library.js.map +1 -1
- package/dist/lifecycle.d.ts +16 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +44 -14
- package/dist/lifecycle.js.map +1 -1
- package/dist/listeners.d.ts.map +1 -1
- package/dist/listeners.js +16 -4
- package/dist/listeners.js.map +1 -1
- package/dist/native-value.js +2 -2
- package/dist/native-value.js.map +1 -1
- package/dist/object.d.ts +7 -2
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +7 -2
- package/dist/object.js.map +1 -1
- package/dist/param-spec.d.ts.map +1 -1
- package/dist/param-spec.js +18 -20
- package/dist/param-spec.js.map +1 -1
- package/dist/properties.d.ts +2 -1
- package/dist/properties.d.ts.map +1 -1
- package/dist/properties.js +13 -9
- package/dist/properties.js.map +1 -1
- package/dist/register-class.d.ts +33 -3
- package/dist/register-class.d.ts.map +1 -1
- package/dist/register-class.js +21 -7
- package/dist/register-class.js.map +1 -1
- package/dist/registry.d.ts +14 -4
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +24 -15
- package/dist/registry.js.map +1 -1
- package/dist/signal.d.ts +2 -2
- package/dist/signal.d.ts.map +1 -1
- package/dist/signal.js +22 -18
- package/dist/signal.js.map +1 -1
- package/dist/t.d.ts +3 -1
- package/dist/t.d.ts.map +1 -1
- package/dist/t.js +1 -0
- package/dist/t.js.map +1 -1
- package/dist/tuple.d.ts +6 -3
- package/dist/tuple.d.ts.map +1 -1
- package/dist/tuple.js +9 -7
- package/dist/tuple.js.map +1 -1
- package/dist/value.d.ts +3 -1
- package/dist/value.d.ts.map +1 -1
- package/dist/value.js +64 -18
- package/dist/value.js.map +1 -1
- package/dist/vfunc-call.d.ts.map +1 -1
- package/dist/vfunc-call.js +5 -1
- package/dist/vfunc-call.js.map +1 -1
- package/dist/vfunc.d.ts.map +1 -1
- package/dist/vfunc.js +9 -3
- package/dist/vfunc.js.map +1 -1
- package/package.json +14 -4
- package/src/application-class.ts +12 -2
- package/src/callback.ts +70 -66
- package/src/closure.ts +1 -1
- package/src/default-application.ts +21 -0
- package/src/descriptors.ts +98 -29
- package/src/exit-hook.ts +18 -0
- package/src/fn.ts +23 -13
- package/src/folded-lengths.ts +64 -0
- package/src/internal.ts +1 -0
- package/src/library.ts +2 -1
- package/src/lifecycle.ts +60 -14
- package/src/listeners.ts +22 -5
- package/src/native-value.ts +2 -2
- package/src/object.ts +7 -2
- package/src/param-spec.ts +21 -22
- package/src/properties.ts +23 -9
- package/src/register-class.ts +66 -11
- package/src/registry.ts +43 -20
- package/src/signal.ts +32 -28
- package/src/t.ts +4 -1
- package/src/tuple.ts +18 -12
- package/src/value.ts +94 -19
- package/src/vfunc-call.ts +5 -1
- package/src/vfunc.ts +10 -3
package/dist/registry.js
CHANGED
|
@@ -172,19 +172,15 @@ function resolveComposedClass(runtimeType) {
|
|
|
172
172
|
return composed;
|
|
173
173
|
}
|
|
174
174
|
function wrapObject(value) {
|
|
175
|
-
|
|
176
|
-
return null;
|
|
177
|
-
}
|
|
178
|
-
return getOrCreateWrapper(value);
|
|
175
|
+
return value == null ? null : getOrCreateWrapper(value);
|
|
179
176
|
}
|
|
180
|
-
function
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
177
|
+
function wrapCallScopedObject(value) {
|
|
178
|
+
return value == null ? null : wrapperFor(value, bindCallScopedWrapper);
|
|
179
|
+
}
|
|
180
|
+
function existingWrapperFor(handle) {
|
|
181
|
+
return handleMap.has(handle) ? handle : getWrapper(handle);
|
|
182
|
+
}
|
|
183
|
+
function createWrapper(handle) {
|
|
188
184
|
const runtimeType = getType(handle);
|
|
189
185
|
if (runtimeType === TYPE_INVALID) {
|
|
190
186
|
throw new Error("Cannot resolve runtime GLib type from handle");
|
|
@@ -193,10 +189,20 @@ function getOrCreateWrapper(handle) {
|
|
|
193
189
|
if (!cls) {
|
|
194
190
|
throw new Error(`Expected registered GLib type, got type ${String(runtimeType)}`);
|
|
195
191
|
}
|
|
196
|
-
|
|
197
|
-
|
|
192
|
+
return Object.create(cls.prototype);
|
|
193
|
+
}
|
|
194
|
+
function wrapperFor(handle, bind) {
|
|
195
|
+
const existing = existingWrapperFor(handle);
|
|
196
|
+
if (existing) {
|
|
197
|
+
return existing;
|
|
198
|
+
}
|
|
199
|
+
const instance = createWrapper(handle);
|
|
200
|
+
bind(handle, instance);
|
|
198
201
|
return instance;
|
|
199
202
|
}
|
|
203
|
+
function getOrCreateWrapper(handle) {
|
|
204
|
+
return wrapperFor(handle, registerWrapper);
|
|
205
|
+
}
|
|
200
206
|
function instanceClassName(instance) {
|
|
201
207
|
return instance.constructor?.name ?? "object";
|
|
202
208
|
}
|
|
@@ -212,6 +218,9 @@ function getHandle(instance) {
|
|
|
212
218
|
function setHandle(instance, handle) {
|
|
213
219
|
handleMap.set(instance, handle);
|
|
214
220
|
}
|
|
221
|
+
function bindCallScopedWrapper(handle, instance) {
|
|
222
|
+
setHandle(instance, handle);
|
|
223
|
+
}
|
|
215
224
|
function registerWrapper(handle, instance) {
|
|
216
225
|
setHandle(instance, handle);
|
|
217
226
|
setWrapper(handle, instance);
|
|
@@ -228,5 +237,5 @@ function getInterfaceVfuncRegistry(type) {
|
|
|
228
237
|
function getInterfaceProperties(type) {
|
|
229
238
|
return interfaceLayoutRegistry.get(type)?.properties;
|
|
230
239
|
}
|
|
231
|
-
export { getClassType, getInstanceType, markDerivedClass, registerClassType, registerWrapperClass, registerInterface, wrapHandle, getWrapperClass, resolveWrapperClass, getHandle, setHandle, getVfuncRegistry, getInterfaceMixin, getInterfaceProperties, getInterfaceVfuncRegistry, instanceClassName, registerWrapper, resolveWrapperType, wrapObject, };
|
|
240
|
+
export { getClassType, getInstanceType, markDerivedClass, registerClassType, registerWrapperClass, registerInterface, wrapHandle, getWrapperClass, resolveWrapperClass, getHandle, setHandle, getVfuncRegistry, getInterfaceMixin, getInterfaceProperties, getInterfaceVfuncRegistry, instanceClassName, registerWrapper, resolveWrapperType, wrapCallScopedObject, wrapObject, };
|
|
232
241
|
//# sourceMappingURL=registry.js.map
|
package/dist/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,OAAO,EACP,UAAU,EAGV,UAAU,GACb,MAAM,cAAc,CAAC;AACtB,OAAO,EAAiB,cAAc,EAAE,MAAM,aAAa,CAAC;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IAC3C,OAAO,uBAAuB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;AACrD,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAY;IACxC,OAAO,uBAAuB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC;AACzD,CAAC;AAED,OAAO,EACH,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,mBAAmB,EACnB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,yBAAyB,EACzB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,UAAU,GAIb,CAAC","sourcesContent":["import {\n type ExternalObject,\n getType,\n getWrapper,\n type Handle,\n type RegisterClassVfunc as NativeRegisterClassVfunc,\n setWrapper,\n} from \"@gtkx/native\";\nimport { type AnyClass, walkClassChain } from \"@gtkx/utils\";\nimport type { Mixin, MixinReceiver } from \"./mixin.js\";\nimport { TYPE_INVALID, type TypedClass, typeInterfaces, typeIsA, typeName, typeParent } from \"./type.js\";\n\n/**\n * Static side of class `C` with its construct signature preserved but the member\n * named `K` (default `\"new\"`) removed.\n */\ntype StaticBase<C, K extends PropertyKey = \"new\"> = Omit<C, K> &\n (C extends new (...args: infer A) => infer R ? new (...args: A) => R : never);\n\n/** One overridable vtable slot: where it sits in the vtable struct and how it is marshalled. */\ntype VfuncDescriptor = {\n /** GIR name of the type struct holding the slot, without its namespace, such as `WidgetClass`. */\n className: string;\n /** Name of the slot's field in that struct. */\n vfuncName: string;\n /** Byte offset of the slot within the struct. */\n byteOffset: number;\n /**\n * Byte size of an interface's vtable struct, used to bounds-check `VfuncDescriptor.byteOffset`.\n * A class struct is bounds-checked against the size `g_type_query` reports for it, so a slot in\n * one carries no size of its own.\n */\n vtableSize?: number;\n /** Descriptor for each argument the slot receives, starting with the instance. */\n argDescriptors: NativeRegisterClassVfunc[\"argDescriptors\"];\n /** Descriptor for the value the slot returns. */\n returnDescriptor: NativeRegisterClassVfunc[\"returnDescriptor\"];\n /**\n * The slot takes a trailing `GError**` that `VfuncDescriptor.argDescriptors` leaves out, the\n * way GIR leaves it out of a callable's parameters. A call through the slot has to append it\n * or it passes one argument fewer than the implementation reads.\n */\n canThrow?: boolean;\n};\n\n/**\n * The vtable slots a wrapper class or interface exposes, keyed by the JavaScript method name that\n * overrides each one.\n */\ntype VfuncRegistry = Record<string, VfuncDescriptor>;\n\n/**\n * How one property an interface declares reaches the vtable, given as the interface's own accessor\n * members. A direction introspection does not route through a vtable slot is left out, and the\n * property owns that direction's state itself.\n */\ntype InterfaceProperty = {\n /** Member reading the slot the property's value comes from, such as `getEnabled`. */\n getter?: string;\n /** Member writing the slot the property's value goes to, such as `setActionName`. */\n setter?: string;\n};\n\n/**\n * What an interface's vtable struct looks like, for the classes that adopt the interface.\n * `g_type_query` reports no size for an interface, so each slot's generated metadata carries the\n * struct's byte size to bounds-check the slot's offset; an interface introspection describes no\n * vtable for simply contributes no slots.\n */\ntype InterfaceLayout = {\n /** The slots the struct declares, keyed by the JavaScript method name that fills each one. */\n vfuncs?: VfuncRegistry;\n /**\n * The properties a vtable slot backs, keyed by canonical property name, so a class adopting the\n * interface answers `g_object_get` and `g_object_set` with what the slot holds.\n */\n properties?: Record<string, InterfaceProperty>;\n};\n\nconst classRegistry: Map<bigint, AnyClass> = new Map();\nconst interfaceMixinRegistry: Map<bigint, Mixin> = new Map();\nconst composedClassRegistry: Map<bigint, AnyClass> = new Map();\nconst handleMap: WeakMap<object, ExternalObject<Handle>> = new WeakMap();\nconst vfuncRegistry: WeakMap<object, VfuncRegistry> = new WeakMap();\nconst interfaceLayoutRegistry: Map<bigint, InterfaceLayout> = new Map();\nconst wrapperClasses: WeakSet<AnyClass> = new WeakSet();\nconst derivedClasses: WeakSet<AnyClass> = new WeakSet();\n\nfunction setClassType(cls: AnyClass, type: bigint): void {\n (cls.prototype as { [K in keyof TypedClass]: TypedClass[K] }).__type__ = type;\n}\n\n/**\n * Returns the GType a class was registered under, or the invalid type when it carries none. The tag is\n * read off the class's own prototype, so a subclass that never went through `registerClass` reports the\n * invalid type rather than inheriting the one its parent was registered with.\n */\nfunction getClassType(cls: AnyClass | undefined): bigint {\n const proto: object | undefined = cls?.prototype;\n\n if (proto === undefined || !Object.hasOwn(proto, \"__type__\")) {\n return TYPE_INVALID;\n }\n\n return (proto as TypedClass).__type__;\n}\n\n/**\n * Returns the GType the given instance's handle carries, or the invalid type when it has no handle.\n * This is the object's own type rather than the type of the class it was wrapped as, and the two differ\n * for an object GTK created itself, such as the row widget inside a `Gtk.ListView`, which GTKX wraps as\n * the nearest registered ancestor.\n */\nfunction getInstanceType(instance: object): bigint {\n const handle = handleMap.get(instance);\n\n return handle === undefined ? TYPE_INVALID : getType(handle);\n}\n\nfunction registerClassType(cls: AnyClass, type: bigint): void {\n if (type === TYPE_INVALID) {\n return;\n }\n\n classRegistry.set(type, cls);\n setClassType(cls, type);\n}\n\n/**\n * Registers a wrapper class as the JS representation of a GType, optionally\n * installing a registry of virtual functions.\n * @param cls Wrapper class to associate with the type.\n * @param type GType the class wraps.\n * @param vfuncs Vtable slots the class exposes, so `registerClass` can bind the ones a subclass\n * overrides.\n */\nfunction registerWrapperClass(cls: AnyClass, type: bigint, vfuncs?: VfuncRegistry): void {\n registerClassType(cls, type);\n\n if (type !== TYPE_INVALID) {\n wrapperClasses.add(cls);\n }\n\n if (vfuncs) {\n registerVfuncRegistry(cls, vfuncs);\n }\n}\n\nfunction markDerivedClass(cls: AnyClass): void {\n derivedClasses.add(cls);\n}\n\nfunction resolveAncestorType(ancestor: AnyClass): bigint | undefined {\n if (derivedClasses.has(ancestor) || !wrapperClasses.has(ancestor)) {\n return undefined;\n }\n\n return getClassType(ancestor);\n}\n\nfunction resolveWrapperType(instance: object): bigint {\n const cls = instance.constructor as AnyClass | undefined;\n\n if (cls === undefined) {\n return TYPE_INVALID;\n }\n\n return walkClassChain(cls, (ancestor) => resolveAncestorType(ancestor)) ?? TYPE_INVALID;\n}\n\n/**\n * Registers a GInterface, associating its GType with a mixin used to compose the\n * interface onto wrapper classes and, when introspection describes its vtable, that layout.\n * @param cls Class carrying the interface's GType tag.\n * @param type GType of the interface.\n * @param mixin Mixin that applies the interface to a wrapper class.\n * @param layout The interface's vtable struct, so `registerClass` can bind the slots an\n * implementing class overrides and take over the ones it leaves alone.\n */\nfunction registerInterface(cls: AnyClass, type: bigint, mixin: Mixin, layout?: InterfaceLayout): void {\n if (type === TYPE_INVALID) {\n return;\n }\n\n setClassType(cls, type);\n interfaceMixinRegistry.set(type, mixin);\n\n if (layout) {\n interfaceLayoutRegistry.set(type, layout);\n }\n}\n\n/**\n * Wraps a native handle in a JS wrapper instance. With no class, resolves and\n * reuses the wrapper for the handle's runtime GType (composing interface mixins),\n * and hands back an instance that already carries a handle unchanged; with an\n * explicit class, creates a bare instance backed by the handle. Returns null for\n * a null or undefined handle.\n * @param handle Native handle to wrap.\n * @param cls Wrapper class to instantiate, or omitted to resolve it from the runtime type.\n */\nfunction wrapHandle(handle: null | undefined, cls?: AnyClass): null;\nfunction wrapHandle<T extends object>(handle: ExternalObject<Handle>, cls: AnyClass<T>): T;\n\nfunction wrapHandle<T extends object>(\n handle: ExternalObject<Handle> | null | undefined,\n cls: AnyClass<T>,\n): T | null;\n\nfunction wrapHandle(handle: ExternalObject<Handle>, cls?: AnyClass): TypedClass;\nfunction wrapHandle(handle: ExternalObject<Handle> | null | undefined, cls?: AnyClass): TypedClass | null;\n\nfunction wrapHandle(handle: ExternalObject<Handle> | null | undefined, cls?: AnyClass): object | null {\n if (handle === null || handle === undefined) {\n return null;\n }\n\n if (cls === undefined) {\n return getOrCreateWrapper(handle);\n }\n\n const instance: object = Object.create(cls.prototype) as object;\n setHandle(instance, handle);\n\n return instance;\n}\n\n/**\n * Returns the wrapper class registered for a GType, walking up to ancestor types,\n * and throws if none is registered.\n */\nfunction getWrapperClass(type: bigint): AnyClass {\n const cls = resolveWrapperClass(type);\n\n if (!cls) {\n throw new Error(`No registered wrapper class for type '${typeName(type) ?? String(type)}'`);\n }\n\n return cls;\n}\n\nfunction resolveWrapperClass(type: bigint): AnyClass | null {\n let currentType = type;\n\n while (currentType !== TYPE_INVALID) {\n const cls = classRegistry.get(currentType);\n\n if (cls) {\n return cls;\n }\n\n currentType = typeParent(currentType);\n }\n\n return null;\n}\n\nfunction getInterfaceMixin(type: bigint): Mixin | undefined {\n return interfaceMixinRegistry.get(type);\n}\n\nfunction applyInterfaceMixin(cls: AnyClass, type: bigint, baseType: bigint, applied: Set<bigint>): AnyClass {\n if (applied.has(type) || typeIsA(baseType, type)) {\n return cls;\n }\n\n const mixin = getInterfaceMixin(type);\n\n if (mixin === undefined) {\n return cls;\n }\n\n applied.add(type);\n\n return mixin(cls as AnyClass<MixinReceiver>);\n}\n\nfunction createComposedClass(base: AnyClass, runtimeType: bigint): AnyClass {\n const baseType = getClassType(base);\n const applied: Set<bigint> = new Set();\n let cls: AnyClass = base;\n\n for (const type of typeInterfaces(runtimeType)) {\n cls = applyInterfaceMixin(cls, type, baseType, applied);\n }\n\n return applied.size === 0 ? base : cls;\n}\n\nfunction resolveComposedClass(runtimeType: bigint): AnyClass | null {\n const exact = classRegistry.get(runtimeType);\n\n if (exact) {\n return exact;\n }\n\n const cached = composedClassRegistry.get(runtimeType);\n\n if (cached) {\n return cached;\n }\n\n const base = resolveWrapperClass(runtimeType);\n\n if (base === null) {\n return null;\n }\n\n const composed = createComposedClass(base, runtimeType);\n\n if (composed === base) {\n return base;\n }\n\n setClassType(composed, runtimeType);\n wrapperClasses.add(composed);\n composedClassRegistry.set(runtimeType, composed);\n\n return composed;\n}\n\nfunction wrapObject(value: unknown): object | null {\n if (value == null) {\n return null;\n }\n\n return getOrCreateWrapper(value as ExternalObject<Handle>);\n}\n\nfunction getOrCreateWrapper(handle: ExternalObject<Handle>): object {\n if (handleMap.has(handle)) {\n return handle;\n }\n\n const existing = getWrapper(handle);\n\n if (existing) {\n return existing;\n }\n\n const runtimeType: bigint = getType(handle);\n\n if (runtimeType === TYPE_INVALID) {\n throw new Error(\"Cannot resolve runtime GLib type from handle\");\n }\n\n const cls = resolveComposedClass(runtimeType);\n\n if (!cls) {\n throw new Error(`Expected registered GLib type, got type ${String(runtimeType)}`);\n }\n\n const instance: object = Object.create(cls.prototype) as object;\n registerWrapper(handle, instance);\n\n return instance;\n}\n\nfunction instanceClassName(instance: object): string {\n return (instance as { constructor?: { name?: string } }).constructor?.name ?? \"object\";\n}\n\n/** Returns the native handle bound to a wrapper instance, throwing if none is set. */\nfunction getHandle(instance: object): ExternalObject<Handle> {\n const handle = handleMap.get(instance);\n\n if (handle === undefined) {\n throw new Error(`No native handle associated with ${instanceClassName(instance)}`);\n }\n\n return handle;\n}\n\n/** Associates a native handle with a wrapper instance. */\nfunction setHandle(instance: object, handle: ExternalObject<Handle>): void {\n handleMap.set(instance, handle);\n}\n\nfunction registerWrapper(handle: ExternalObject<Handle>, instance: object): void {\n setHandle(instance, handle);\n setWrapper(handle, instance);\n}\n\nfunction registerVfuncRegistry(cls: object, registry: VfuncRegistry): void {\n vfuncRegistry.set(cls, registry);\n}\n\nfunction getVfuncRegistry(cls: object): VfuncRegistry | undefined {\n return vfuncRegistry.get(cls);\n}\n\nfunction getInterfaceVfuncRegistry(type: bigint): VfuncRegistry | undefined {\n return interfaceLayoutRegistry.get(type)?.vfuncs;\n}\n\nfunction getInterfaceProperties(type: bigint): Record<string, InterfaceProperty> | undefined {\n return interfaceLayoutRegistry.get(type)?.properties;\n}\n\nexport {\n getClassType,\n getInstanceType,\n markDerivedClass,\n registerClassType,\n registerWrapperClass,\n registerInterface,\n wrapHandle,\n getWrapperClass,\n resolveWrapperClass,\n getHandle,\n setHandle,\n getVfuncRegistry,\n getInterfaceMixin,\n getInterfaceProperties,\n getInterfaceVfuncRegistry,\n instanceClassName,\n registerWrapper,\n resolveWrapperType,\n wrapObject,\n type InterfaceProperty,\n type Static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n type ExternalObject,\n getType,\n getWrapper,\n type Handle,\n type RegisterClassVfunc as NativeRegisterClassVfunc,\n setWrapper,\n} from \"@gtkx/native\";\nimport { type AnyClass, walkClassChain } from \"@gtkx/utils\";\nimport type { Mixin, MixinReceiver } from \"./mixin.js\";\nimport { TYPE_INVALID, type TypedClass, typeInterfaces, typeIsA, typeName, typeParent } from \"./type.js\";\n\n/**\n * Static side of class `C` with its construct signature preserved but the members named `K`\n * removed. A generated class lists every static it declares itself, so a static it narrows never\n * has to stay assignable to the one it shadows. The signature is kept abstract so an abstract `C`\n * survives it: a subclass extends the result, and only the subclass's own declarations decide\n * which statics reach it.\n */\ntype StaticBase<C, K extends PropertyKey> = Omit<C, K> &\n (C extends abstract new (...args: infer A) => infer R ? abstract new (...args: A) => R : never);\n\n/** One overridable vtable slot: where it sits in the vtable struct and how it is marshalled. */\ntype VfuncDescriptor = {\n /** GIR name of the type struct holding the slot, without its namespace, such as `WidgetClass`. */\n className: string;\n /** Name of the slot's field in that struct. */\n vfuncName: string;\n /** Byte offset of the slot within the struct. */\n byteOffset: number;\n /**\n * Byte size of an interface's vtable struct, used to bounds-check `VfuncDescriptor.byteOffset`.\n * A class struct is bounds-checked against the size `g_type_query` reports for it, so a slot in\n * one carries no size of its own.\n */\n vtableSize?: number;\n /** Descriptor for each argument the slot receives, starting with the instance. */\n argDescriptors: NativeRegisterClassVfunc[\"argDescriptors\"];\n /** Descriptor for the value the slot returns. */\n returnDescriptor: NativeRegisterClassVfunc[\"returnDescriptor\"];\n /**\n * GIR marks the slot's return value as one the bindings do not surface, so a call through the\n * slot drops it and an implementation of the slot reports success in its place, while\n * `VfuncDescriptor.returnDescriptor` keeps the C type the slot is called against either way.\n */\n isReturnSkipped?: boolean;\n /**\n * The slot takes a trailing `GError**` that `VfuncDescriptor.argDescriptors` leaves out, the\n * way GIR leaves it out of a callable's parameters. A call through the slot has to append it\n * or it passes one argument fewer than the implementation reads.\n */\n canThrow?: boolean;\n};\n\n/**\n * The vtable slots a wrapper class or interface exposes, keyed by the JavaScript method name that\n * overrides each one.\n */\ntype VfuncRegistry = Record<string, VfuncDescriptor>;\ntype WrapperBinding = (handle: ExternalObject<Handle>, instance: object) => void;\n\n/**\n * How one property an interface declares reaches the vtable, given as the interface's own accessor\n * members. A direction introspection does not route through a vtable slot is left out, and the\n * property owns that direction's state itself.\n */\ntype InterfaceProperty = {\n /** Member reading the slot the property's value comes from, such as `getEnabled`. */\n getter?: string;\n /** Member writing the slot the property's value goes to, such as `setActionName`. */\n setter?: string;\n};\n\n/**\n * What an interface's vtable struct looks like, for the classes that adopt the interface.\n * `g_type_query` reports no size for an interface, so each slot's generated metadata carries the\n * struct's byte size to bounds-check the slot's offset; an interface introspection describes no\n * vtable for simply contributes no slots.\n */\ntype InterfaceLayout = {\n /** The slots the struct declares, keyed by the JavaScript method name that fills each one. */\n vfuncs?: VfuncRegistry;\n /**\n * The properties a vtable slot backs, keyed by canonical property name, so a class adopting the\n * interface answers `g_object_get` and `g_object_set` with what the slot holds.\n */\n properties?: Record<string, InterfaceProperty>;\n};\n\nconst classRegistry: Map<bigint, AnyClass> = new Map();\nconst interfaceMixinRegistry: Map<bigint, Mixin> = new Map();\nconst composedClassRegistry: Map<bigint, AnyClass> = new Map();\nconst handleMap: WeakMap<object, ExternalObject<Handle>> = new WeakMap();\nconst vfuncRegistry: WeakMap<object, VfuncRegistry> = new WeakMap();\nconst interfaceLayoutRegistry: Map<bigint, InterfaceLayout> = new Map();\nconst wrapperClasses: WeakSet<AnyClass> = new WeakSet();\nconst derivedClasses: WeakSet<AnyClass> = new WeakSet();\n\nfunction setClassType(cls: AnyClass, type: bigint): void {\n (cls.prototype as { [K in keyof TypedClass]: TypedClass[K] }).__type__ = type;\n}\n\n/**\n * Returns the GType a class was registered under, or the invalid type when it carries none. The tag is\n * read off the class's own prototype, so a subclass that never went through `registerClass` reports the\n * invalid type rather than inheriting the one its parent was registered with.\n */\nfunction getClassType(cls: AnyClass | undefined): bigint {\n const proto: object | undefined = cls?.prototype;\n\n if (proto === undefined || !Object.hasOwn(proto, \"__type__\")) {\n return TYPE_INVALID;\n }\n\n return (proto as TypedClass).__type__;\n}\n\n/**\n * Returns the GType the given instance's handle carries, or the invalid type when it has no handle.\n * This is the object's own type rather than the type of the class it was wrapped as, and the two differ\n * for an object GTK created itself, such as the row widget inside a `Gtk.ListView`, which GTKX wraps as\n * the nearest registered ancestor.\n */\nfunction getInstanceType(instance: object): bigint {\n const handle = handleMap.get(instance);\n\n return handle === undefined ? TYPE_INVALID : getType(handle);\n}\n\nfunction registerClassType(cls: AnyClass, type: bigint): void {\n if (type === TYPE_INVALID) {\n return;\n }\n\n classRegistry.set(type, cls);\n setClassType(cls, type);\n}\n\n/**\n * Registers a wrapper class as the JS representation of a GType, optionally\n * installing a registry of virtual functions.\n * @param cls Wrapper class to associate with the type.\n * @param type GType the class wraps.\n * @param vfuncs Vtable slots the class exposes, so `registerClass` can bind the ones a subclass\n * overrides.\n */\nfunction registerWrapperClass(cls: AnyClass, type: bigint, vfuncs?: VfuncRegistry): void {\n registerClassType(cls, type);\n\n if (type !== TYPE_INVALID) {\n wrapperClasses.add(cls);\n }\n\n if (vfuncs) {\n registerVfuncRegistry(cls, vfuncs);\n }\n}\n\nfunction markDerivedClass(cls: AnyClass): void {\n derivedClasses.add(cls);\n}\n\nfunction resolveAncestorType(ancestor: AnyClass): bigint | undefined {\n if (derivedClasses.has(ancestor) || !wrapperClasses.has(ancestor)) {\n return undefined;\n }\n\n return getClassType(ancestor);\n}\n\nfunction resolveWrapperType(instance: object): bigint {\n const cls = instance.constructor as AnyClass | undefined;\n\n if (cls === undefined) {\n return TYPE_INVALID;\n }\n\n return walkClassChain(cls, (ancestor) => resolveAncestorType(ancestor)) ?? TYPE_INVALID;\n}\n\n/**\n * Registers a GInterface, associating its GType with a mixin used to compose the\n * interface onto wrapper classes and, when introspection describes its vtable, that layout.\n * @param cls Class carrying the interface's GType tag.\n * @param type GType of the interface.\n * @param mixin Mixin that applies the interface to a wrapper class.\n * @param layout The interface's vtable struct, so `registerClass` can bind the slots an\n * implementing class overrides and take over the ones it leaves alone.\n */\nfunction registerInterface(cls: AnyClass, type: bigint, mixin: Mixin, layout?: InterfaceLayout): void {\n if (type === TYPE_INVALID) {\n return;\n }\n\n setClassType(cls, type);\n interfaceMixinRegistry.set(type, mixin);\n\n if (layout) {\n interfaceLayoutRegistry.set(type, layout);\n }\n}\n\n/**\n * Wraps a native handle in a JS wrapper instance. With no class, resolves and\n * reuses the wrapper for the handle's runtime GType (composing interface mixins),\n * and hands back an instance that already carries a handle unchanged; with an\n * explicit class, creates a bare instance backed by the handle. Returns null for\n * a null or undefined handle.\n * @param handle Native handle to wrap.\n * @param cls Wrapper class to instantiate, or omitted to resolve it from the runtime type.\n */\nfunction wrapHandle(handle: null | undefined, cls?: AnyClass): null;\nfunction wrapHandle<T extends object>(handle: ExternalObject<Handle>, cls: AnyClass<T>): T;\n\nfunction wrapHandle<T extends object>(\n handle: ExternalObject<Handle> | null | undefined,\n cls: AnyClass<T>,\n): T | null;\n\nfunction wrapHandle(handle: ExternalObject<Handle>, cls?: AnyClass): TypedClass;\nfunction wrapHandle(handle: ExternalObject<Handle> | null | undefined, cls?: AnyClass): TypedClass | null;\n\nfunction wrapHandle(handle: ExternalObject<Handle> | null | undefined, cls?: AnyClass): object | null {\n if (handle === null || handle === undefined) {\n return null;\n }\n\n if (cls === undefined) {\n return getOrCreateWrapper(handle);\n }\n\n const instance: object = Object.create(cls.prototype) as object;\n setHandle(instance, handle);\n\n return instance;\n}\n\n/**\n * Returns the wrapper class registered for a GType, walking up to ancestor types,\n * and throws if none is registered.\n */\nfunction getWrapperClass(type: bigint): AnyClass {\n const cls = resolveWrapperClass(type);\n\n if (!cls) {\n throw new Error(`No registered wrapper class for type '${typeName(type) ?? String(type)}'`);\n }\n\n return cls;\n}\n\nfunction resolveWrapperClass(type: bigint): AnyClass | null {\n let currentType = type;\n\n while (currentType !== TYPE_INVALID) {\n const cls = classRegistry.get(currentType);\n\n if (cls) {\n return cls;\n }\n\n currentType = typeParent(currentType);\n }\n\n return null;\n}\n\nfunction getInterfaceMixin(type: bigint): Mixin | undefined {\n return interfaceMixinRegistry.get(type);\n}\n\nfunction applyInterfaceMixin(cls: AnyClass, type: bigint, baseType: bigint, applied: Set<bigint>): AnyClass {\n if (applied.has(type) || typeIsA(baseType, type)) {\n return cls;\n }\n\n const mixin = getInterfaceMixin(type);\n\n if (mixin === undefined) {\n return cls;\n }\n\n applied.add(type);\n\n return mixin(cls as AnyClass<MixinReceiver>);\n}\n\nfunction createComposedClass(base: AnyClass, runtimeType: bigint): AnyClass {\n const baseType = getClassType(base);\n const applied: Set<bigint> = new Set();\n let cls: AnyClass = base;\n\n for (const type of typeInterfaces(runtimeType)) {\n cls = applyInterfaceMixin(cls, type, baseType, applied);\n }\n\n return applied.size === 0 ? base : cls;\n}\n\nfunction resolveComposedClass(runtimeType: bigint): AnyClass | null {\n const exact = classRegistry.get(runtimeType);\n\n if (exact) {\n return exact;\n }\n\n const cached = composedClassRegistry.get(runtimeType);\n\n if (cached) {\n return cached;\n }\n\n const base = resolveWrapperClass(runtimeType);\n\n if (base === null) {\n return null;\n }\n\n const composed = createComposedClass(base, runtimeType);\n\n if (composed === base) {\n return base;\n }\n\n setClassType(composed, runtimeType);\n wrapperClasses.add(composed);\n composedClassRegistry.set(runtimeType, composed);\n\n return composed;\n}\n\nfunction wrapObject(value: unknown): object | null {\n return value == null ? null : getOrCreateWrapper(value as ExternalObject<Handle>);\n}\n\nfunction wrapCallScopedObject(value: unknown): object | null {\n return value == null ? null : wrapperFor(value as ExternalObject<Handle>, bindCallScopedWrapper);\n}\n\nfunction existingWrapperFor(handle: ExternalObject<Handle>): object | null {\n return handleMap.has(handle) ? handle : getWrapper(handle);\n}\n\nfunction createWrapper(handle: ExternalObject<Handle>): object {\n const runtimeType: bigint = getType(handle);\n\n if (runtimeType === TYPE_INVALID) {\n throw new Error(\"Cannot resolve runtime GLib type from handle\");\n }\n\n const cls = resolveComposedClass(runtimeType);\n\n if (!cls) {\n throw new Error(`Expected registered GLib type, got type ${String(runtimeType)}`);\n }\n\n return Object.create(cls.prototype) as object;\n}\n\nfunction wrapperFor(handle: ExternalObject<Handle>, bind: WrapperBinding): object {\n const existing = existingWrapperFor(handle);\n\n if (existing) {\n return existing;\n }\n\n const instance = createWrapper(handle);\n bind(handle, instance);\n\n return instance;\n}\n\nfunction getOrCreateWrapper(handle: ExternalObject<Handle>): object {\n return wrapperFor(handle, registerWrapper);\n}\n\nfunction instanceClassName(instance: object): string {\n return (instance as { constructor?: { name?: string } }).constructor?.name ?? \"object\";\n}\n\n/** Returns the native handle bound to a wrapper instance, throwing if none is set. */\nfunction getHandle(instance: object): ExternalObject<Handle> {\n const handle = handleMap.get(instance);\n\n if (handle === undefined) {\n throw new Error(`No native handle associated with ${instanceClassName(instance)}`);\n }\n\n return handle;\n}\n\n/** Associates a native handle with a wrapper instance. */\nfunction setHandle(instance: object, handle: ExternalObject<Handle>): void {\n handleMap.set(instance, handle);\n}\n\nfunction bindCallScopedWrapper(handle: ExternalObject<Handle>, instance: object): void {\n setHandle(instance, handle);\n}\n\nfunction registerWrapper(handle: ExternalObject<Handle>, instance: object): void {\n setHandle(instance, handle);\n setWrapper(handle, instance);\n}\n\nfunction registerVfuncRegistry(cls: object, registry: VfuncRegistry): void {\n vfuncRegistry.set(cls, registry);\n}\n\nfunction getVfuncRegistry(cls: object): VfuncRegistry | undefined {\n return vfuncRegistry.get(cls);\n}\n\nfunction getInterfaceVfuncRegistry(type: bigint): VfuncRegistry | undefined {\n return interfaceLayoutRegistry.get(type)?.vfuncs;\n}\n\nfunction getInterfaceProperties(type: bigint): Record<string, InterfaceProperty> | undefined {\n return interfaceLayoutRegistry.get(type)?.properties;\n}\n\nexport {\n getClassType,\n getInstanceType,\n markDerivedClass,\n registerClassType,\n registerWrapperClass,\n registerInterface,\n wrapHandle,\n getWrapperClass,\n resolveWrapperClass,\n getHandle,\n setHandle,\n getVfuncRegistry,\n getInterfaceMixin,\n getInterfaceProperties,\n getInterfaceVfuncRegistry,\n instanceClassName,\n registerWrapper,\n resolveWrapperType,\n wrapCallScopedObject,\n wrapObject,\n type InterfaceProperty,\n type StaticBase,\n type VfuncDescriptor,\n};\n"]}
|
package/dist/signal.d.ts
CHANGED
|
@@ -47,8 +47,8 @@ declare function connectSignal(instance: object, signal: string, spec: SignalCon
|
|
|
47
47
|
* @param instance Emitter to emit the signal on.
|
|
48
48
|
* @param signal Signal name, optionally including a `::detail` suffix.
|
|
49
49
|
* @param args Arguments to pass, including output and inout arguments.
|
|
50
|
-
* @param
|
|
50
|
+
* @param returns Descriptor for the signal's return value, omitted when it returns void.
|
|
51
51
|
*/
|
|
52
|
-
declare function emitSignal(instance: object, signal: string, args: EmitArg[],
|
|
52
|
+
declare function emitSignal(instance: object, signal: string, args: EmitArg[], returns?: Descriptor): unknown;
|
|
53
53
|
export { getSignalBaseName, connectSignal, disconnectSignal, emitSignal, hasSignalListener, isSignalHandlerConnected, untrackConnection, type SignalHandler, };
|
|
54
54
|
//# sourceMappingURL=signal.d.ts.map
|
package/dist/signal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../src/signal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA0B,MAAM,cAAc,CAAC;AAEvE,OAAO,EAAE,KAAK,GAAG,EAAiD,MAAM,UAAU,CAAC;AAGnF,OAAO,EAIH,KAAK,kBAAkB,EAM1B,MAAM,kBAAkB,CAAC;AAc1B,mEAAmE;AACnE,KAAK,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AAErD,2EAA2E;AAC3E,KAAK,iBAAiB,GAAG;IACrB;;;OAGG;IACH,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,4FAA4F;IAC5F,OAAO,EAAE,aAAa,CAAC;IACvB,yFAAyF;IACz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iBAAiB,GAAG,MAAM,CASxF;AAqCD;;;;;;;GAOG;AACH,iBAAS,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAepG;AAED,OAAO,EACH,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,EACjB,KAAK,aAAa,GACrB,CAAC"}
|
package/dist/signal.js
CHANGED
|
@@ -99,7 +99,7 @@ function connectBind(type, signal, callback) {
|
|
|
99
99
|
*/
|
|
100
100
|
function connectSignal(instance, signal, spec) {
|
|
101
101
|
const { callback, handler, isAfter } = spec;
|
|
102
|
-
const wrapped = wrapCallback(handler, callback, "
|
|
102
|
+
const wrapped = wrapCallback(handler, callback, "signal");
|
|
103
103
|
const type = instance.__type__;
|
|
104
104
|
const connect = connectBind(type, signal, callback);
|
|
105
105
|
const handlerId = connect(getHandle(instance), signal, wrapped, isAfter ? 1 : 0);
|
|
@@ -119,33 +119,37 @@ const createEmitValue = (arg) => {
|
|
|
119
119
|
}
|
|
120
120
|
return isInoutArg(arg) ? outValueForDescriptor(arg.type, arg.value) : outValueForDescriptor(arg.type);
|
|
121
121
|
};
|
|
122
|
+
const collectEmitValues = (instance, args) => {
|
|
123
|
+
const collected = { values: [toValue(objectT("full"), instance)], reads: [] };
|
|
124
|
+
for (const arg of args) {
|
|
125
|
+
const { value, read } = createEmitValue(arg);
|
|
126
|
+
collected.values.push(value);
|
|
127
|
+
if (read) {
|
|
128
|
+
collected.reads.push(read);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return collected;
|
|
132
|
+
};
|
|
133
|
+
const readEmitOutputs = (reads) => reads.map((read) => read());
|
|
122
134
|
/**
|
|
123
135
|
* Emits a signal on an instance with the given arguments and returns its result
|
|
124
136
|
* combined with any output-argument values.
|
|
125
137
|
* @param instance Emitter to emit the signal on.
|
|
126
138
|
* @param signal Signal name, optionally including a `::detail` suffix.
|
|
127
139
|
* @param args Arguments to pass, including output and inout arguments.
|
|
128
|
-
* @param
|
|
140
|
+
* @param returns Descriptor for the signal's return value, omitted when it returns void.
|
|
129
141
|
*/
|
|
130
|
-
function emitSignal(instance, signal, args,
|
|
142
|
+
function emitSignal(instance, signal, args, returns) {
|
|
131
143
|
const signalId = getSignalId(instance, signal);
|
|
132
144
|
const detail = getSignalDetailQuark(signal);
|
|
133
|
-
const values =
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
values.push(value);
|
|
138
|
-
if (read) {
|
|
139
|
-
reads.push(read);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if (returnDescriptor !== undefined) {
|
|
143
|
-
const returnValue = newValueForDescriptor(returnDescriptor);
|
|
144
|
-
gSignalEmitv(values, signalId, detail, returnValue);
|
|
145
|
-
return packTupleResult(reads.map((read) => read()), fromValue(returnValue), true);
|
|
145
|
+
const { values, reads } = collectEmitValues(instance, args);
|
|
146
|
+
if (returns === undefined) {
|
|
147
|
+
gSignalEmitv(values, signalId, detail, undefined);
|
|
148
|
+
return packTupleResult(readEmitOutputs(reads), undefined, false);
|
|
146
149
|
}
|
|
147
|
-
|
|
148
|
-
|
|
150
|
+
const returnValue = newValueForDescriptor(returns);
|
|
151
|
+
gSignalEmitv(values, signalId, detail, returnValue);
|
|
152
|
+
return packTupleResult(readEmitOutputs(reads), fromValue(returnValue), true);
|
|
149
153
|
}
|
|
150
154
|
export { getSignalBaseName, connectSignal, disconnectSignal, emitSignal, hasSignalListener, isSignalHandlerConnected, untrackConnection, };
|
|
151
155
|
//# sourceMappingURL=signal.js.map
|
package/dist/signal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signal.js","sourceRoot":"","sources":["../src/signal.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,oBAAoB,EAAE,UAAU,EAAE,WAAW,E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CAAC;IAED,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IAElD,OAAO,eAAe,CAClB,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,EAC3B,SAAS,EACT,KAAK,CACR,CAAC;AACN,CAAC;AAED,OAAO,EACH,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,GAEpB,CAAC","sourcesContent":["import type { Descriptor, ExternalObject, Handle } from \"@gtkx/native\";\nimport type { TypedClass } from \"./type.js\";\nimport { type Arg, isCallerAllocatedArg, isInoutArg, isOutputArg } from \"./arg.js\";\nimport { bind, createBindCache } from \"./bind.js\";\nimport { wrapCallback } from \"./callback.js\";\nimport {\n arrayT,\n biguint64T,\n booleanT,\n type CallbackDescriptor,\n objectT,\n stringT,\n uint32T,\n uint64T,\n voidT,\n} from \"./descriptors.js\";\nimport { LIB, VALUE_SIZE, VALUE_T } from \"./library.js\";\nimport { getHandle } from \"./registry.js\";\nimport { packTupleResult } from \"./tuple.js\";\nimport {\n fromValue,\n getBoxedValue,\n inoutValueForBoxedDescriptor,\n newValueForDescriptor,\n outValueForBoxedDescriptor,\n outValueForDescriptor,\n toValue,\n} from \"./value.js\";\n\n/** Function invoked when a connected GObject signal is emitted. */\ntype SignalHandler = (...args: unknown[]) => unknown;\n\n/** The marshalling and handler that make up a single signal connection. */\ntype SignalConnectSpec = {\n /**\n * Marshalling for the emission, whose `argDescriptors` lead with the emitter and include the\n * closure's user data slot.\n */\n callback: CallbackDescriptor;\n /** Called on each emission with the signal's own arguments, without the leading emitter. */\n handler: SignalHandler;\n /** When true, run the handler after the class's default handler instead of before it. */\n isAfter: boolean;\n};\n\n/** One argument of a signal emission: how to marshal it, plus the value to marshal. */\ntype EmitArg = Arg & {\n /**\n * The value to pass for an input or inout argument, or the caller-allocated storage to fill for\n * a caller-allocated output argument; omitted for a plain output argument.\n */\n value?: unknown;\n};\n\nconst connectCache = createBindCache();\nconst connectionTable: WeakMap<object, Map<string, Set<number>>> = new WeakMap();\nconst gQuarkFromString = bind(LIB, \"g_quark_from_string\", [stringT(\"borrowed\")], uint32T);\nconst gSignalLookup = bind(LIB, \"g_signal_lookup\", [stringT(\"borrowed\"), biguint64T], uint32T);\n\nconst gSignalEmitv = bind(\n LIB,\n \"g_signal_emitv\",\n [arrayT(VALUE_T, \"array\", \"borrowed\", { elementSize: VALUE_SIZE }), uint32T, uint32T, VALUE_T],\n voidT,\n);\n\nconst gSignalHandlerIsConnected = bind(\n LIB,\n \"g_signal_handler_is_connected\",\n [objectT(\"borrowed\"), uint64T],\n booleanT,\n);\n\nconst gSignalHandlerDisconnect = bind(LIB, \"g_signal_handler_disconnect\", [objectT(\"borrowed\"), uint64T], voidT);\n\n/** Returns the signal name without its detail suffix (the part after `::`). */\nconst getSignalBaseName = (signal: string): string => {\n const detailIndex = signal.indexOf(\"::\");\n\n return detailIndex === -1 ? signal : signal.slice(0, detailIndex);\n};\n\nfunction getSignalDetailQuark(signal: string): number {\n const detailIndex = signal.indexOf(\"::\");\n\n if (detailIndex === -1) {\n return 0;\n }\n\n return gQuarkFromString(signal.slice(detailIndex + 2)) as number;\n}\n\nconst isSignalHandlerConnected = (instance: object, handlerId: number): boolean =>\n gSignalHandlerIsConnected(getHandle(instance), handlerId) as boolean;\n\nconst trackConnection = (instance: object, signal: string, handlerId: number): void => {\n let bySignal = connectionTable.get(instance);\n\n if (!bySignal) {\n bySignal = new Map();\n connectionTable.set(instance, bySignal);\n }\n\n let handlerIds = bySignal.get(signal);\n\n if (!handlerIds) {\n handlerIds = new Set();\n bySignal.set(signal, handlerIds);\n }\n\n handlerIds.add(handlerId);\n};\n\nconst untrackConnection = (instance: object, handlerId: number): void => {\n const bySignal = connectionTable.get(instance);\n\n if (bySignal === undefined) {\n return;\n }\n\n for (const [name, handlerIds] of bySignal) {\n handlerIds.delete(handlerId);\n\n if (handlerIds.size === 0) {\n bySignal.delete(name);\n }\n }\n};\n\n/**\n * Disconnects the handler an instance connected under the given id, and forgets the connection.\n * @param instance Emitter the handler was connected to.\n * @param handlerId Id {@link connectSignal} returned for the handler.\n */\nconst disconnectSignal = (instance: object, handlerId: number): void => {\n untrackConnection(instance, handlerId);\n gSignalHandlerDisconnect(getHandle(instance), handlerId);\n};\n\nconst hasLiveConnection = (instance: object, handlerIds: Set<number>): boolean => {\n let isLive = false;\n\n for (const handlerId of handlerIds) {\n if (isSignalHandlerConnected(instance, handlerId)) {\n isLive = true;\n } else {\n handlerIds.delete(handlerId);\n }\n }\n\n return isLive;\n};\n\nfunction hasSignalListener(instance: object, signals?: string[]): boolean {\n const bySignal = connectionTable.get(instance);\n\n if (!bySignal) {\n return false;\n }\n\n const names =\n signals === undefined ? bySignal.keys().toArray() : signals.map((signal) => getSignalBaseName(signal));\n\n return names.some((name) => {\n const handlerIds = bySignal.get(name);\n\n return handlerIds !== undefined && hasLiveConnection(instance, handlerIds);\n });\n}\n\nconst getSignalId = (instance: object, signal: string): number => {\n const type: bigint = (instance as TypedClass).__type__;\n\n return gSignalLookup(getSignalBaseName(signal), type) as number;\n};\n\nfunction connectBind(type: bigint, signal: string, callback: CallbackDescriptor): (...values: unknown[]) => unknown {\n const key = `${String(type)}\\0${getSignalBaseName(signal)}`;\n\n return connectCache(\n key,\n LIB,\n \"g_signal_connect_data\",\n [objectT(\"borrowed\"), stringT(\"borrowed\"), callback, uint32T],\n uint64T,\n );\n}\n\n/**\n * Connects a handler to a GObject signal on an instance and returns the handler id.\n * @param instance Emitter to connect to.\n * @param signal Signal name, optionally including a `::detail` suffix.\n * @param spec Callback descriptor, handler function, and whether to run after the default handler.\n */\nfunction connectSignal(instance: object, signal: string, spec: SignalConnectSpec): number {\n const { callback, handler, isAfter } = spec;\n const wrapped = wrapCallback(handler, callback, \"emitter\");\n const type: bigint = (instance as TypedClass).__type__;\n const connect = connectBind(type, signal, callback);\n const handlerId = connect(getHandle(instance), signal, wrapped, isAfter ? 1 : 0) as number;\n trackConnection(instance, getSignalBaseName(signal), handlerId);\n\n return handlerId;\n}\n\nconst createEmitValue = (arg: EmitArg): { value: ExternalObject<Handle>; read?: () => unknown } => {\n if (!isOutputArg(arg)) {\n return { value: toValue(arg.type, arg.value) };\n }\n\n if (isCallerAllocatedArg(arg)) {\n if (isInoutArg(arg)) {\n return { value: inoutValueForBoxedDescriptor(arg.type, arg.value as object) };\n }\n\n const value = outValueForBoxedDescriptor(arg.type, arg.value as object);\n\n return { value, read: () => getBoxedValue(value) };\n }\n\n return isInoutArg(arg) ? outValueForDescriptor(arg.type, arg.value) : outValueForDescriptor(arg.type);\n};\n\n/**\n * Emits a signal on an instance with the given arguments and returns its result\n * combined with any output-argument values.\n * @param instance Emitter to emit the signal on.\n * @param signal Signal name, optionally including a `::detail` suffix.\n * @param args Arguments to pass, including output and inout arguments.\n * @param returnDescriptor Descriptor for the signal's return value, omitted when it returns void.\n */\nfunction emitSignal(instance: object, signal: string, args: EmitArg[], returnDescriptor?: Descriptor): unknown {\n const signalId = getSignalId(instance, signal);\n const detail = getSignalDetailQuark(signal);\n const values: ExternalObject<Handle>[] = [toValue(objectT(\"full\"), instance)];\n const reads: (() => unknown)[] = [];\n\n for (const arg of args) {\n const { value, read } = createEmitValue(arg);\n values.push(value);\n\n if (read) {\n reads.push(read);\n }\n }\n\n if (returnDescriptor !== undefined) {\n const returnValue = newValueForDescriptor(returnDescriptor);\n gSignalEmitv(values, signalId, detail, returnValue);\n\n return packTupleResult(\n reads.map((read) => read()),\n fromValue(returnValue),\n true,\n );\n }\n\n gSignalEmitv(values, signalId, detail, undefined);\n\n return packTupleResult(\n reads.map((read) => read()),\n undefined,\n false,\n );\n}\n\nexport {\n getSignalBaseName,\n connectSignal,\n disconnectSignal,\n emitSignal,\n hasSignalListener,\n isSignalHandlerConnected,\n untrackConnection,\n type SignalHandler,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"signal.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,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,iBAAiB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAE5D,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QACxB,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QAElD,OAAO,eAAe,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IACrE,CAAC;IAED,MAAM,WAAW,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IACnD,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IAEpD,OAAO,eAAe,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,CAAC;AACjF,CAAC;AAED,OAAO,EACH,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,GAEpB,CAAC","sourcesContent":["import type { Descriptor, ExternalObject, Handle } from \"@gtkx/native\";\nimport type { TypedClass } from \"./type.js\";\nimport { type Arg, isCallerAllocatedArg, isInoutArg, isOutputArg } from \"./arg.js\";\nimport { bind, createBindCache } from \"./bind.js\";\nimport { wrapCallback } from \"./callback.js\";\nimport {\n arrayT,\n biguint64T,\n booleanT,\n type CallbackDescriptor,\n objectT,\n stringT,\n uint32T,\n uint64T,\n voidT,\n} from \"./descriptors.js\";\nimport { LIB, VALUE_SIZE, VALUE_T } from \"./library.js\";\nimport { getHandle } from \"./registry.js\";\nimport { packTupleResult } from \"./tuple.js\";\nimport {\n fromValue,\n getBoxedValue,\n inoutValueForBoxedDescriptor,\n newValueForDescriptor,\n outValueForBoxedDescriptor,\n outValueForDescriptor,\n toValue,\n} from \"./value.js\";\n\n/** Function invoked when a connected GObject signal is emitted. */\ntype SignalHandler = (...args: unknown[]) => unknown;\n\n/** The marshalling and handler that make up a single signal connection. */\ntype SignalConnectSpec = {\n /**\n * Marshalling for the emission, whose `argDescriptors` lead with the emitter and include the\n * closure's user data slot.\n */\n callback: CallbackDescriptor;\n /** Called on each emission with the signal's own arguments, without the leading emitter. */\n handler: SignalHandler;\n /** When true, run the handler after the class's default handler instead of before it. */\n isAfter: boolean;\n};\n\ntype EmitValues = {\n values: ExternalObject<Handle>[];\n reads: (() => unknown)[];\n};\n\n/** One argument of a signal emission: how to marshal it, plus the value to marshal. */\ntype EmitArg = Arg & {\n /**\n * The value to pass for an input or inout argument, or the caller-allocated storage to fill for\n * a caller-allocated output argument; omitted for a plain output argument.\n */\n value?: unknown;\n};\n\nconst connectCache = createBindCache();\nconst connectionTable: WeakMap<object, Map<string, Set<number>>> = new WeakMap();\nconst gQuarkFromString = bind(LIB, \"g_quark_from_string\", [stringT(\"borrowed\")], uint32T);\nconst gSignalLookup = bind(LIB, \"g_signal_lookup\", [stringT(\"borrowed\"), biguint64T], uint32T);\n\nconst gSignalEmitv = bind(\n LIB,\n \"g_signal_emitv\",\n [arrayT(VALUE_T, \"array\", \"borrowed\", { elementSize: VALUE_SIZE }), uint32T, uint32T, VALUE_T],\n voidT,\n);\n\nconst gSignalHandlerIsConnected = bind(\n LIB,\n \"g_signal_handler_is_connected\",\n [objectT(\"borrowed\"), uint64T],\n booleanT,\n);\n\nconst gSignalHandlerDisconnect = bind(LIB, \"g_signal_handler_disconnect\", [objectT(\"borrowed\"), uint64T], voidT);\n\n/** Returns the signal name without its detail suffix (the part after `::`). */\nconst getSignalBaseName = (signal: string): string => {\n const detailIndex = signal.indexOf(\"::\");\n\n return detailIndex === -1 ? signal : signal.slice(0, detailIndex);\n};\n\nfunction getSignalDetailQuark(signal: string): number {\n const detailIndex = signal.indexOf(\"::\");\n\n if (detailIndex === -1) {\n return 0;\n }\n\n return gQuarkFromString(signal.slice(detailIndex + 2)) as number;\n}\n\nconst isSignalHandlerConnected = (instance: object, handlerId: number): boolean =>\n gSignalHandlerIsConnected(getHandle(instance), handlerId) as boolean;\n\nconst trackConnection = (instance: object, signal: string, handlerId: number): void => {\n let bySignal = connectionTable.get(instance);\n\n if (!bySignal) {\n bySignal = new Map();\n connectionTable.set(instance, bySignal);\n }\n\n let handlerIds = bySignal.get(signal);\n\n if (!handlerIds) {\n handlerIds = new Set();\n bySignal.set(signal, handlerIds);\n }\n\n handlerIds.add(handlerId);\n};\n\nconst untrackConnection = (instance: object, handlerId: number): void => {\n const bySignal = connectionTable.get(instance);\n\n if (bySignal === undefined) {\n return;\n }\n\n for (const [name, handlerIds] of bySignal) {\n handlerIds.delete(handlerId);\n\n if (handlerIds.size === 0) {\n bySignal.delete(name);\n }\n }\n};\n\n/**\n * Disconnects the handler an instance connected under the given id, and forgets the connection.\n * @param instance Emitter the handler was connected to.\n * @param handlerId Id {@link connectSignal} returned for the handler.\n */\nconst disconnectSignal = (instance: object, handlerId: number): void => {\n untrackConnection(instance, handlerId);\n gSignalHandlerDisconnect(getHandle(instance), handlerId);\n};\n\nconst hasLiveConnection = (instance: object, handlerIds: Set<number>): boolean => {\n let isLive = false;\n\n for (const handlerId of handlerIds) {\n if (isSignalHandlerConnected(instance, handlerId)) {\n isLive = true;\n } else {\n handlerIds.delete(handlerId);\n }\n }\n\n return isLive;\n};\n\nfunction hasSignalListener(instance: object, signals?: string[]): boolean {\n const bySignal = connectionTable.get(instance);\n\n if (!bySignal) {\n return false;\n }\n\n const names =\n signals === undefined ? bySignal.keys().toArray() : signals.map((signal) => getSignalBaseName(signal));\n\n return names.some((name) => {\n const handlerIds = bySignal.get(name);\n\n return handlerIds !== undefined && hasLiveConnection(instance, handlerIds);\n });\n}\n\nconst getSignalId = (instance: object, signal: string): number => {\n const type: bigint = (instance as TypedClass).__type__;\n\n return gSignalLookup(getSignalBaseName(signal), type) as number;\n};\n\nfunction connectBind(type: bigint, signal: string, callback: CallbackDescriptor): (...values: unknown[]) => unknown {\n const key = `${String(type)}\\0${getSignalBaseName(signal)}`;\n\n return connectCache(\n key,\n LIB,\n \"g_signal_connect_data\",\n [objectT(\"borrowed\"), stringT(\"borrowed\"), callback, uint32T],\n uint64T,\n );\n}\n\n/**\n * Connects a handler to a GObject signal on an instance and returns the handler id.\n * @param instance Emitter to connect to.\n * @param signal Signal name, optionally including a `::detail` suffix.\n * @param spec Callback descriptor, handler function, and whether to run after the default handler.\n */\nfunction connectSignal(instance: object, signal: string, spec: SignalConnectSpec): number {\n const { callback, handler, isAfter } = spec;\n const wrapped = wrapCallback(handler, callback, \"signal\");\n const type: bigint = (instance as TypedClass).__type__;\n const connect = connectBind(type, signal, callback);\n const handlerId = connect(getHandle(instance), signal, wrapped, isAfter ? 1 : 0) as number;\n trackConnection(instance, getSignalBaseName(signal), handlerId);\n\n return handlerId;\n}\n\nconst createEmitValue = (arg: EmitArg): { value: ExternalObject<Handle>; read?: () => unknown } => {\n if (!isOutputArg(arg)) {\n return { value: toValue(arg.type, arg.value) };\n }\n\n if (isCallerAllocatedArg(arg)) {\n if (isInoutArg(arg)) {\n return { value: inoutValueForBoxedDescriptor(arg.type, arg.value as object) };\n }\n\n const value = outValueForBoxedDescriptor(arg.type, arg.value as object);\n\n return { value, read: () => getBoxedValue(value) };\n }\n\n return isInoutArg(arg) ? outValueForDescriptor(arg.type, arg.value) : outValueForDescriptor(arg.type);\n};\n\nconst collectEmitValues = (instance: object, args: EmitArg[]): EmitValues => {\n const collected: EmitValues = { values: [toValue(objectT(\"full\"), instance)], reads: [] };\n\n for (const arg of args) {\n const { value, read } = createEmitValue(arg);\n collected.values.push(value);\n\n if (read) {\n collected.reads.push(read);\n }\n }\n\n return collected;\n};\n\nconst readEmitOutputs = (reads: (() => unknown)[]): unknown[] => reads.map((read) => read());\n\n/**\n * Emits a signal on an instance with the given arguments and returns its result\n * combined with any output-argument values.\n * @param instance Emitter to emit the signal on.\n * @param signal Signal name, optionally including a `::detail` suffix.\n * @param args Arguments to pass, including output and inout arguments.\n * @param returns Descriptor for the signal's return value, omitted when it returns void.\n */\nfunction emitSignal(instance: object, signal: string, args: EmitArg[], returns?: Descriptor): unknown {\n const signalId = getSignalId(instance, signal);\n const detail = getSignalDetailQuark(signal);\n const { values, reads } = collectEmitValues(instance, args);\n\n if (returns === undefined) {\n gSignalEmitv(values, signalId, detail, undefined);\n\n return packTupleResult(readEmitOutputs(reads), undefined, false);\n }\n\n const returnValue = newValueForDescriptor(returns);\n gSignalEmitv(values, signalId, detail, returnValue);\n\n return packTupleResult(readEmitOutputs(reads), fromValue(returnValue), true);\n}\n\nexport {\n getSignalBaseName,\n connectSignal,\n disconnectSignal,\n emitSignal,\n hasSignalListener,\n isSignalHandlerConnected,\n untrackConnection,\n type SignalHandler,\n};\n"]}
|
package/dist/t.d.ts
CHANGED
|
@@ -68,7 +68,7 @@ type T = {
|
|
|
68
68
|
slist: typeof helpers.slistT;
|
|
69
69
|
/** Builds a descriptor for a `GPtrArray` of items. */
|
|
70
70
|
ptrArray: typeof helpers.ptrArrayT;
|
|
71
|
-
/** Builds a descriptor for a `GArray` of items
|
|
71
|
+
/** Builds a descriptor for a `GArray` of items. */
|
|
72
72
|
gArray: typeof helpers.gArrayT;
|
|
73
73
|
/** Builds a descriptor for a `GByteArray`. */
|
|
74
74
|
byteArray: typeof helpers.byteArrayT;
|
|
@@ -76,6 +76,8 @@ type T = {
|
|
|
76
76
|
sizedArray: typeof helpers.sizedArrayT;
|
|
77
77
|
/** Builds a descriptor for a C array of a fixed length. */
|
|
78
78
|
fixedArray: typeof helpers.fixedArrayT;
|
|
79
|
+
/** Builds a descriptor for an out pointer into the buffer another argument supplied. */
|
|
80
|
+
cursorArray: typeof helpers.cursorArrayT;
|
|
79
81
|
/** Builds a descriptor for a function pointer, marshalling a JavaScript function into a native closure. */
|
|
80
82
|
callback: typeof helpers.callbackT;
|
|
81
83
|
/**
|
package/dist/t.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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EF,OAAO,EAAE,CAAC,EAAE,CAAC"}
|
package/dist/t.js
CHANGED
package/dist/t.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"t.js","sourceRoot":"","sources":["../src/t.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"t.js","sourceRoot":"","sources":["../src/t.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAwF7B;;;;GAIG;AACH,MAAM,CAAC,GAAM;IACT,IAAI;IACJ,IAAI,EAAE,OAAO,CAAC,KAAK;IACnB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,QAAQ,EAAE,OAAO,CAAC,SAAS;IAC3B,SAAS,EAAE,OAAO,CAAC,UAAU;IAC7B,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,OAAO,EAAE,OAAO,CAAC,QAAQ;IACzB,OAAO,EAAE,OAAO,CAAC,QAAQ;IACzB,OAAO,EAAE,OAAO,CAAC,QAAQ;IACzB,IAAI,EAAE,OAAO,CAAC,KAAK;IACnB,OAAO,EAAE,OAAO,CAAC,QAAQ;IACzB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,WAAW,EAAE,OAAO,CAAC,YAAY;IACjC,GAAG,EAAE,OAAO,CAAC,IAAI;IACjB,SAAS,EAAE,OAAO,CAAC,UAAU;IAC7B,IAAI,EAAE,OAAO,CAAC,KAAK;IACnB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,IAAI,EAAE,OAAO,CAAC,KAAK;IACnB,KAAK,EAAE,OAAO,CAAC,MAAM;IACrB,QAAQ,EAAE,OAAO,CAAC,SAAS;IAC3B,MAAM,EAAE,OAAO,CAAC,OAAO;IACvB,SAAS,EAAE,OAAO,CAAC,UAAU;IAC7B,UAAU,EAAE,OAAO,CAAC,WAAW;IAC/B,UAAU,EAAE,OAAO,CAAC,WAAW;IAC/B,WAAW,EAAE,OAAO,CAAC,YAAY;IACjC,QAAQ,EAAE,OAAO,CAAC,SAAS;IAC3B,EAAE;CACL,CAAC;AAEF,OAAO,EAAE,CAAC,EAAE,CAAC","sourcesContent":["import { bind } from \"./bind.js\";\nimport * as helpers from \"./descriptors.js\";\nimport { fn } from \"./fn.js\";\n\n/** The descriptor factories and function binders exposed as {@link t}. */\ntype T = {\n /** Binds a symbol in a shared library to a callable that marshals its arguments and return value. */\n bind: typeof bind;\n /** Descriptor for a `gint8`, marshalled as a number. */\n int8: typeof helpers.int8T;\n /** Descriptor for a `guint8`, marshalled as a number. */\n uint8: typeof helpers.uint8T;\n /** Descriptor for a `gint16`, marshalled as a number. */\n int16: typeof helpers.int16T;\n /** Descriptor for a `guint16`, marshalled as a number. */\n uint16: typeof helpers.uint16T;\n /** Descriptor for a `gint32`, marshalled as a number. */\n int32: typeof helpers.int32T;\n /** Descriptor for a `guint32`, marshalled as a number. */\n uint32: typeof helpers.uint32T;\n /** Descriptor for a `gint64`, marshalled as a number and rejected outside the 2^53 safe range. */\n int64: typeof helpers.int64T;\n /** Descriptor for a `guint64`, marshalled as a number and rejected outside the 2^53 safe range. */\n uint64: typeof helpers.uint64T;\n /** Descriptor for a `gint64`, marshalled as a bigint so the full 64-bit range survives. */\n bigint64: typeof helpers.bigint64T;\n /** Descriptor for a `guint64`, marshalled as a bigint so the full 64-bit range survives. */\n biguint64: typeof helpers.biguint64T;\n /** Descriptor for a `GType`, marshalled as a bigint and recognized as a GType by GValue conversion. */\n gtype: typeof helpers.gtypeT;\n /** Descriptor for a `gfloat`. */\n float32: typeof helpers.float32T;\n /** Descriptor for a `gdouble`. */\n float64: typeof helpers.float64T;\n /** Descriptor for a `gboolean`, marshalled as a JavaScript boolean. */\n boolean: typeof helpers.booleanT;\n /** Descriptor for the absence of a value, used as the return descriptor of a `void` function. */\n void: typeof helpers.voidT;\n /** Descriptor for a `gunichar`, marshalled as a single-character string or a codepoint number. */\n unichar: typeof helpers.unicharT;\n /** Descriptor for an opaque `gpointer` argument, taken from a typed array's memory or a numeric address. */\n buffer: typeof helpers.bufferT;\n /**\n * Builds a descriptor for a C string, whose optional length sizes the caller-allocated buffer\n * used when the string is passed by reference.\n */\n string: typeof helpers.stringT;\n /** Builds a descriptor for a `GObject`, wrapped in the class registered for its runtime GType. */\n object: typeof helpers.objectT;\n /** Builds a descriptor for a `GBoxed` value of the named type. */\n boxed: typeof helpers.boxedT;\n /** Builds a descriptor for a plain C struct. */\n struct: typeof helpers.structT;\n /** Builds a descriptor for a fundamental type whose lifetime is managed by named ref and unref functions. */\n fundamental: typeof helpers.fundamentalT;\n /** Wraps a descriptor in a pointer to it, for an output or inout argument. */\n ref: typeof helpers.refT;\n /** Builds a descriptor for a `GHashTable`, marshalled as an array of key/value pairs. */\n hashTable: typeof helpers.hashTableT;\n /** Builds a descriptor for an enumeration, resolving its GType from the named `get_type` function. */\n enum: typeof helpers.enumT;\n /** Builds a descriptor for a flags type, resolving its GType from the named `get_type` function. */\n flags: typeof helpers.flagsT;\n /** Builds a descriptor for an array of items in one of the supported container layouts. */\n array: typeof helpers.arrayT;\n /** Builds a descriptor for a `GList` of items. */\n list: typeof helpers.listT;\n /** Builds a descriptor for a `GSList` of items. */\n slist: typeof helpers.slistT;\n /** Builds a descriptor for a `GPtrArray` of items. */\n ptrArray: typeof helpers.ptrArrayT;\n /** Builds a descriptor for a `GArray` of items. */\n gArray: typeof helpers.gArrayT;\n /** Builds a descriptor for a `GByteArray`. */\n byteArray: typeof helpers.byteArrayT;\n /** Builds a descriptor for a C array whose length is carried by another argument. */\n sizedArray: typeof helpers.sizedArrayT;\n /** Builds a descriptor for a C array of a fixed length. */\n fixedArray: typeof helpers.fixedArrayT;\n /** Builds a descriptor for an out pointer into the buffer another argument supplied. */\n cursorArray: typeof helpers.cursorArrayT;\n /** Builds a descriptor for a function pointer, marshalling a JavaScript function into a native closure. */\n callback: typeof helpers.callbackT;\n /**\n * Binds a native function, wiring up argument directions, `GError` checking, and packing output\n * arguments into the result.\n */\n fn: typeof fn;\n};\n\n/**\n * Type descriptor builder: a collection of factory helpers that describe C types for\n * FFI marshalling, plus `bind` to bind a native function and `fn` to describe a\n * function signature.\n */\nconst t: T = {\n bind,\n int8: helpers.int8T,\n uint8: helpers.uint8T,\n int16: helpers.int16T,\n uint16: helpers.uint16T,\n int32: helpers.int32T,\n uint32: helpers.uint32T,\n int64: helpers.int64T,\n uint64: helpers.uint64T,\n bigint64: helpers.bigint64T,\n biguint64: helpers.biguint64T,\n gtype: helpers.gtypeT,\n float32: helpers.float32T,\n float64: helpers.float64T,\n boolean: helpers.booleanT,\n void: helpers.voidT,\n unichar: helpers.unicharT,\n buffer: helpers.bufferT,\n string: helpers.stringT,\n object: helpers.objectT,\n boxed: helpers.boxedT,\n struct: helpers.structT,\n fundamental: helpers.fundamentalT,\n ref: helpers.refT,\n hashTable: helpers.hashTableT,\n enum: helpers.enumT,\n flags: helpers.flagsT,\n array: helpers.arrayT,\n list: helpers.listT,\n slist: helpers.slistT,\n ptrArray: helpers.ptrArrayT,\n gArray: helpers.gArrayT,\n byteArray: helpers.byteArrayT,\n sizedArray: helpers.sizedArrayT,\n fixedArray: helpers.fixedArrayT,\n cursorArray: helpers.cursorArrayT,\n callback: helpers.callbackT,\n fn,\n};\n\nexport { t };\n"]}
|
package/dist/tuple.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { Descriptor } from "@gtkx/native";
|
|
2
|
+
type SplitResult = {
|
|
3
3
|
primary: unknown;
|
|
4
4
|
outValues: unknown[];
|
|
5
5
|
};
|
|
6
|
-
|
|
6
|
+
declare const hasSurfacedPrimary: (returnDescriptor: Descriptor, isReturnSkipped: boolean | undefined) => boolean;
|
|
7
|
+
declare const packTupleResult: (outs: unknown[], primary: unknown, hasPrimary: boolean) => unknown;
|
|
8
|
+
declare const splitTupleResult: (result: unknown, hasPrimary: boolean, outCount: number) => SplitResult;
|
|
9
|
+
export { hasSurfacedPrimary, packTupleResult, splitTupleResult };
|
|
7
10
|
//# sourceMappingURL=tuple.d.ts.map
|
package/dist/tuple.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tuple.d.ts","sourceRoot":"","sources":["../src/tuple.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,eAAe,GAAI,MAAM,OAAO,EAAE,EAAE,SAAS,OAAO,EAAE,YAAY,OAAO,KAAG,OAcjF,CAAC;
|
|
1
|
+
{"version":3,"file":"tuple.d.ts","sourceRoot":"","sources":["../src/tuple.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,KAAK,WAAW,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,OAAO,EAAE,CAAA;CAAE,CAAC;AAE9D,QAAA,MAAM,kBAAkB,GAAI,kBAAkB,UAAU,EAAE,iBAAiB,OAAO,GAAG,SAAS,KAAG,OACjC,CAAC;AAEjE,QAAA,MAAM,eAAe,GAAI,MAAM,OAAO,EAAE,EAAE,SAAS,OAAO,EAAE,YAAY,OAAO,KAAG,OAcjF,CAAC;AAkBF,QAAA,MAAM,gBAAgB,GAAI,QAAQ,OAAO,EAAE,YAAY,OAAO,EAAE,UAAU,MAAM,KAAG,WACK,CAAC;AAEzF,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,CAAC"}
|
package/dist/tuple.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const hasSurfacedPrimary = (returnDescriptor, isReturnSkipped) => returnDescriptor.kind !== "void" && isReturnSkipped !== true;
|
|
1
2
|
const packTupleResult = (outs, primary, hasPrimary) => {
|
|
2
3
|
if (hasPrimary) {
|
|
3
4
|
return outs.length === 0 ? primary : [primary, ...outs];
|
|
@@ -10,17 +11,18 @@ const packTupleResult = (outs, primary, hasPrimary) => {
|
|
|
10
11
|
}
|
|
11
12
|
return outs;
|
|
12
13
|
};
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
return { primary: result[0], outValues: result.slice(1) };
|
|
17
|
-
}
|
|
18
|
-
return { primary: result, outValues: [] };
|
|
14
|
+
const splitPrimaryResult = (result, outCount) => {
|
|
15
|
+
if (outCount > 0 && Array.isArray(result)) {
|
|
16
|
+
return { primary: result[0], outValues: result.slice(1) };
|
|
19
17
|
}
|
|
18
|
+
return { primary: result, outValues: [] };
|
|
19
|
+
};
|
|
20
|
+
const splitOutResult = (result, outCount) => {
|
|
20
21
|
if (outCount === 1) {
|
|
21
22
|
return { primary: undefined, outValues: [result] };
|
|
22
23
|
}
|
|
23
24
|
return { primary: undefined, outValues: Array.isArray(result) ? result : [] };
|
|
24
25
|
};
|
|
25
|
-
|
|
26
|
+
const splitTupleResult = (result, hasPrimary, outCount) => hasPrimary ? splitPrimaryResult(result, outCount) : splitOutResult(result, outCount);
|
|
27
|
+
export { hasSurfacedPrimary, packTupleResult, splitTupleResult };
|
|
26
28
|
//# sourceMappingURL=tuple.js.map
|
package/dist/tuple.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tuple.js","sourceRoot":"","sources":["../src/tuple.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tuple.js","sourceRoot":"","sources":["../src/tuple.ts"],"names":[],"mappings":"AAIA,MAAM,kBAAkB,GAAG,CAAC,gBAA4B,EAAE,eAAoC,EAAW,EAAE,CACvG,gBAAgB,CAAC,IAAI,KAAK,MAAM,IAAI,eAAe,KAAK,IAAI,CAAC;AAEjE,MAAM,eAAe,GAAG,CAAC,IAAe,EAAE,OAAgB,EAAE,UAAmB,EAAW,EAAE;IACxF,IAAI,UAAU,EAAE,CAAC;QACb,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IAC5D,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,MAAe,EAAE,QAAgB,EAAe,EAAE;IAC1E,IAAI,QAAQ,GAAG,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACxC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9D,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;AAC9C,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,MAAe,EAAE,QAAgB,EAAe,EAAE;IACtE,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACjB,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;IACvD,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AAClF,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,MAAe,EAAE,UAAmB,EAAE,QAAgB,EAAe,EAAE,CAC7F,UAAU,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAEzF,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["import type { Descriptor } from \"@gtkx/native\";\n\ntype SplitResult = { primary: unknown; outValues: unknown[] };\n\nconst hasSurfacedPrimary = (returnDescriptor: Descriptor, isReturnSkipped: boolean | undefined): boolean =>\n returnDescriptor.kind !== \"void\" && isReturnSkipped !== true;\n\nconst packTupleResult = (outs: unknown[], primary: unknown, hasPrimary: boolean): unknown => {\n if (hasPrimary) {\n return outs.length === 0 ? primary : [primary, ...outs];\n }\n\n if (outs.length === 0) {\n return undefined;\n }\n\n if (outs.length === 1) {\n return outs[0];\n }\n\n return outs;\n};\n\nconst splitPrimaryResult = (result: unknown, outCount: number): SplitResult => {\n if (outCount > 0 && Array.isArray(result)) {\n return { primary: result[0], outValues: result.slice(1) };\n }\n\n return { primary: result, outValues: [] };\n};\n\nconst splitOutResult = (result: unknown, outCount: number): SplitResult => {\n if (outCount === 1) {\n return { primary: undefined, outValues: [result] };\n }\n\n return { primary: undefined, outValues: Array.isArray(result) ? result : [] };\n};\n\nconst splitTupleResult = (result: unknown, hasPrimary: boolean, outCount: number): SplitResult =>\n hasPrimary ? splitPrimaryResult(result, outCount) : splitOutResult(result, outCount);\n\nexport { hasSurfacedPrimary, packTupleResult, splitTupleResult };\n"]}
|
package/dist/value.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ type ValueType = {
|
|
|
4
4
|
get: (value: ExternalObject<Handle>) => unknown;
|
|
5
5
|
};
|
|
6
6
|
type ValueWriter = ValueType["set"];
|
|
7
|
+
type ValueNarrower = (jsValue: unknown) => unknown;
|
|
7
8
|
declare function getValueType(value: ExternalObject<Handle>): bigint;
|
|
8
9
|
declare function copyValue(dest: ExternalObject<Handle>, src: ExternalObject<Handle>): void;
|
|
9
10
|
declare const newValueForType: (type: bigint) => ExternalObject<Handle>;
|
|
@@ -14,6 +15,7 @@ declare const newValueForType: (type: bigint) => ExternalObject<Handle>;
|
|
|
14
15
|
declare function getBoxedValue(value: ExternalObject<Handle>): object | null;
|
|
15
16
|
/** Stores a boxed object, or null, into a GValue that holds a boxed type. */
|
|
16
17
|
declare function setBoxedValue(value: ExternalObject<Handle>, boxed: object | null): void;
|
|
18
|
+
declare function valueNarrowerFor(type: bigint): ValueNarrower;
|
|
17
19
|
declare function valueWriterFor(type: bigint): ValueWriter;
|
|
18
20
|
declare function intoValue(value: ExternalObject<Handle>, jsValue: unknown): void;
|
|
19
21
|
declare function toValue(descriptor: Descriptor, value: unknown): ExternalObject<Handle>;
|
|
@@ -25,5 +27,5 @@ declare function outValueForDescriptor(descriptor: Descriptor, initial?: unknown
|
|
|
25
27
|
};
|
|
26
28
|
declare function outValueForBoxedDescriptor(descriptor: Descriptor, boxed: object): ExternalObject<Handle>;
|
|
27
29
|
declare function inoutValueForBoxedDescriptor(descriptor: Descriptor, boxed: object): ExternalObject<Handle>;
|
|
28
|
-
export { getValueType, intoValue, copyValue, getBoxedValue, setBoxedValue, toValue, fromValue, newValueForDescriptor, newValueForType, outValueForDescriptor, outValueForBoxedDescriptor, inoutValueForBoxedDescriptor, type ValueWriter, valueWriterFor, };
|
|
30
|
+
export { getValueType, intoValue, copyValue, getBoxedValue, setBoxedValue, toValue, fromValue, newValueForDescriptor, newValueForType, outValueForDescriptor, outValueForBoxedDescriptor, inoutValueForBoxedDescriptor, type ValueNarrower, valueNarrowerFor, type ValueWriter, valueWriterFor, };
|
|
29
31
|
//# sourceMappingURL=value.d.ts.map
|
package/dist/value.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"value.d.ts","sourceRoot":"","sources":["../src/value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,UAAU,EAAE,KAAK,cAAc,EAAW,KAAK,MAAM,EAAe,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"value.d.ts","sourceRoot":"","sources":["../src/value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,UAAU,EAAE,KAAK,cAAc,EAAW,KAAK,MAAM,EAAe,MAAM,cAAc,CAAC;AA2D9G,KAAK,SAAS,GAAG;IACb,GAAG,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,OAAO,KAAK,IAAI,CAAC;IACnE,GAAG,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC;CACnD,CAAC;AAGF,KAAK,WAAW,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;AACpC,KAAK,aAAa,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;AAoLnD,iBAAS,YAAY,CAAC,KAAK,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,MAAM,CAE3D;AAED,iBAAS,SAAS,CAAC,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,IAAI,CAMlF;AAED,QAAA,MAAM,eAAe,GAAI,MAAM,MAAM,KAAG,cAAc,CAAC,MAAM,CA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