@gtkx/runtime 0.0.1 → 1.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +373 -0
- package/README.md +171 -3
- package/dist/arg.d.ts +13 -0
- package/dist/arg.d.ts.map +1 -0
- package/dist/arg.js +6 -0
- package/dist/arg.js.map +1 -0
- package/dist/bind.d.ts +5 -0
- package/dist/bind.d.ts.map +1 -0
- package/dist/bind.js +19 -0
- package/dist/bind.js.map +1 -0
- package/dist/callback.d.ts +13 -0
- package/dist/callback.d.ts.map +1 -0
- package/dist/callback.js +86 -0
- package/dist/callback.js.map +1 -0
- package/dist/descriptors.d.ts +158 -0
- package/dist/descriptors.d.ts.map +1 -0
- package/dist/descriptors.js +135 -0
- package/dist/descriptors.js.map +1 -0
- package/dist/error.d.ts +24 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +33 -0
- package/dist/error.js.map +1 -0
- package/dist/exit-hook.d.ts +2 -0
- package/dist/exit-hook.d.ts.map +1 -0
- package/dist/exit-hook.js +3 -0
- package/dist/exit-hook.js.map +1 -0
- package/dist/fn.d.ts +10 -0
- package/dist/fn.d.ts.map +1 -0
- package/dist/fn.js +90 -0
- package/dist/fn.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +5 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +5 -0
- package/dist/internal.js.map +1 -0
- package/dist/library.d.ts +8 -0
- package/dist/library.d.ts.map +1 -0
- package/dist/library.js +14 -0
- package/dist/library.js.map +1 -0
- package/dist/lifecycle.d.ts +42 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +70 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/listeners.d.ts +36 -0
- package/dist/listeners.d.ts.map +1 -0
- package/dist/listeners.js +85 -0
- package/dist/listeners.js.map +1 -0
- package/dist/mixin.d.ts +13 -0
- package/dist/mixin.d.ts.map +1 -0
- package/dist/mixin.js +49 -0
- package/dist/mixin.js.map +1 -0
- package/dist/native-value.d.ts +13 -0
- package/dist/native-value.d.ts.map +1 -0
- package/dist/native-value.js +105 -0
- package/dist/native-value.js.map +1 -0
- package/dist/object.d.ts +32 -0
- package/dist/object.d.ts.map +1 -0
- package/dist/object.js +66 -0
- package/dist/object.js.map +1 -0
- package/dist/promisify.d.ts +21 -0
- package/dist/promisify.d.ts.map +1 -0
- package/dist/promisify.js +39 -0
- package/dist/promisify.js.map +1 -0
- package/dist/properties.d.ts +14 -0
- package/dist/properties.d.ts.map +1 -0
- package/dist/properties.js +79 -0
- package/dist/properties.js.map +1 -0
- package/dist/register-class.d.ts +25 -0
- package/dist/register-class.d.ts.map +1 -0
- package/dist/register-class.js +178 -0
- package/dist/register-class.js.map +1 -0
- package/dist/registry.d.ts +69 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +186 -0
- package/dist/registry.js.map +1 -0
- package/dist/signal.d.ts +35 -0
- package/dist/signal.d.ts.map +1 -0
- package/dist/signal.js +95 -0
- package/dist/signal.js.map +1 -0
- package/dist/t.d.ts +50 -0
- package/dist/t.d.ts.map +1 -0
- package/dist/t.js +49 -0
- package/dist/t.js.map +1 -0
- package/dist/tuple.d.ts +7 -0
- package/dist/tuple.d.ts.map +1 -0
- package/dist/tuple.js +26 -0
- package/dist/tuple.js.map +1 -0
- package/dist/type.d.ts +88 -0
- package/dist/type.d.ts.map +1 -0
- package/dist/type.js +194 -0
- package/dist/type.js.map +1 -0
- package/dist/value.d.ts +29 -0
- package/dist/value.d.ts.map +1 -0
- package/dist/value.js +292 -0
- package/dist/value.js.map +1 -0
- package/package.json +54 -13
- package/src/arg.ts +15 -0
- package/src/bind.ts +31 -0
- package/src/callback.ts +149 -0
- package/src/descriptors.ts +350 -0
- package/src/error.ts +58 -0
- package/src/exit-hook.ts +3 -0
- package/src/fn.ts +139 -0
- package/src/index.ts +59 -0
- package/src/internal.ts +12 -0
- package/src/library.ts +17 -0
- package/src/lifecycle.ts +101 -0
- package/src/listeners.ts +112 -0
- package/src/mixin.ts +73 -0
- package/src/native-value.ts +135 -0
- package/src/object.ts +95 -0
- package/src/promisify.ts +67 -0
- package/src/properties.ts +115 -0
- package/src/register-class.ts +305 -0
- package/src/registry.ts +311 -0
- package/src/signal.ts +192 -0
- package/src/t.ts +90 -0
- package/src/tuple.ts +37 -0
- package/src/type.ts +290 -0
- package/src/value.ts +430 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-class.js","sourceRoot":"","sources":["../src/register-class.ts"],"names":[],"mappings":"AACA,OAAO,EACH,aAAa,IAAI,mBAAmB,GAGvC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAiB,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EACH,cAAc,EACd,eAAe,EACf,eAAe,EAGf,kBAAkB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACH,YAAY,EACZ,yBAAyB,EACzB,gBAAgB,EAChB,iBAAiB,GAEpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAmBzD,MAAM,4BAA4B,GAAgB,IAAI,GAAG,CAAC,CAAC,aAAa,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC;AACzG,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B;;;;;;;;;GASG;AACH,SAAS,aAAa,CAAqB,KAAQ,EAAE,UAAgC,EAAE;IACnF,MAAM,UAAU,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAE5C,IAAI,UAAU,KAAK,YAAY,EAAE,CAAC;QAC9B,MAAM,IAAI,SAAS,CAAC,kBAAkB,KAAK,CAAC,IAAI,yCAAyC,CAAC,CAA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,OAAO,GAA+B,EAAE,CAAC;IAE/C,IAAI,aAAa,EAAE,CAAC;QAChB,OAAO,CAAC,UAAU,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,cAAc,EAAE,CAAC;QACjB,OAAO,CAAC,MAAM,GAAG,CAAC,GAAG,WAAW,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,aAAa,EAAE,CAAC;QAChB,OAAO,CAAC,UAAU,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YACrD,IAAI,EAAE,OAAO,CAAC,KAAK;YACnB,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;SAC9B,CAAC,CAAC,CAAC;IACR,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,CAAC","sourcesContent":["import type { Descriptor } from \"@gtkx/native\";\nimport {\n registerClass as nativeRegisterClass,\n type RegisterClassOptions as NativeRegisterClassOptions,\n type RegisterClassVfunc as NativeRegisterClassVfunc,\n} from \"@gtkx/native\";\nimport { type AnyClass, getParentClass, walkClassChain } from \"@gtkx/utils\";\nimport { wrapCallback } from \"./callback.js\";\nimport {\n buildAccessors,\n makeGetProperty,\n makeSetProperty,\n type PropertyAccessor,\n type PropertySpec,\n toNativeProperties,\n} from \"./properties.js\";\nimport {\n getClassType,\n getInterfaceVfuncRegistry,\n getVfuncRegistry,\n registerClassType,\n type VfuncDescriptor,\n} from \"./registry.js\";\nimport { TYPE_INVALID, typeInterfaces } from \"./type.js\";\n\ntype RegisterClassOptions = {\n typeName?: string;\n /**\n * Properties to install on the new type, keyed by canonical property name. Each value is the\n * `GObject.ParamSpec` describing it, for example `GObject.paramSpecString(...)`. Accessors are\n * generated on the prototype for the dashed, underscored and camelCased spellings of the name\n * unless the class already defines one, and writing through them emits `notify`.\n */\n properties?: Record<string, PropertySpec>;\n};\n\ntype VfuncFn = NativeRegisterClassVfunc[\"fn\"];\ntype DiscoveredVfunc<K extends \"class\" | \"interface\"> = VfuncDescriptor<K> & { methodName: string; fn: VfuncFn };\ntype DiscoveredClassVfunc = DiscoveredVfunc<\"class\">;\ntype DiscoveredInterfaceVfunc = DiscoveredVfunc<\"interface\">;\ntype InterfaceVfuncBinding = { gtype: bigint; vtableSize: number; vfuncs: DiscoveredInterfaceVfunc[] };\n\nconst UNSUPPORTED_CONSTRUCT_VFUNCS: Set<string> = new Set([\"constructed\", \"setProperty\", \"getProperty\"]);\nconst VALUE_ARG_INDEX = 2;\n\n/**\n * Registers a subclass of a wrapper class as a new GType, wiring up any class and\n * inherited-interface virtual functions it overrides. Throws if the class does not\n * extend a registered wrapper class, has no derivable type name, or overrides an\n * unsupported construct-time vtable slot.\n *\n * @param klass The subclass to register.\n * @param options Registration options, such as an explicit type name.\n * @returns The same class, now registered.\n */\nfunction registerClass<T extends AnyClass>(klass: T, options: RegisterClassOptions = {}): T {\n const parentType = resolveParentType(klass);\n\n if (parentType === TYPE_INVALID) {\n throw new TypeError(`registerClass: ${klass.name} must extend a registered wrapper class`);\n }\n\n const name = options.typeName ?? klass.name;\n\n if (!name) {\n throw new Error(\"registerClass: cannot derive a GType name (anonymous class with no typeName option)\");\n }\n\n const properties = options.properties ?? {};\n const accessors = buildAccessors(klass, properties);\n const classVfuncs = [...discoverClassVfuncs(klass), ...propertyVfuncs(klass, accessors)];\n const claimedMethodNames = new Set(classVfuncs.map((vfunc) => vfunc.methodName));\n const interfaceBindings = discoverInheritedInterfaceVfuncs(klass, parentType, claimedMethodNames);\n const nativeOptions = toNativeOptions(classVfuncs, interfaceBindings, properties);\n const newType: bigint = nativeRegisterClass(name, parentType, nativeOptions);\n registerClassType(klass, newType);\n\n return klass;\n}\n\nfunction resolveParentType(klass: AnyClass): bigint {\n return (\n walkClassChain(getParentClass(klass), (cls) => {\n const gtype = getClassType(cls);\n\n return gtype === TYPE_INVALID ? undefined : gtype;\n }) ?? TYPE_INVALID\n );\n}\n\nfunction ownInstanceMethodNames(klass: AnyClass): string[] {\n const proto = (klass as { prototype?: object }).prototype;\n\n if (!proto) {\n return [];\n }\n\n return Object.getOwnPropertyNames(proto).filter((name) => {\n if (name === \"constructor\") {\n return false;\n }\n\n return typeof Object.getOwnPropertyDescriptor(proto, name)?.value === \"function\";\n });\n}\n\nfunction buildDiscoveredVfunc<K extends \"class\" | \"interface\">(\n proto: Record<string, VfuncFn>,\n methodName: string,\n resolveDescriptor: (methodName: string) => VfuncDescriptor<K> | undefined,\n skip: Set<string> | undefined,\n): DiscoveredVfunc<K> | undefined {\n if (skip?.has(methodName)) {\n return undefined;\n }\n\n const descriptor = resolveDescriptor(methodName);\n\n if (!descriptor) {\n return undefined;\n }\n\n const fn = proto[methodName];\n\n if (!fn) {\n return undefined;\n }\n\n return {\n ...descriptor,\n methodName,\n fn: wrapVfunc(fn, descriptor.argDescriptors, descriptor.returnDescriptor),\n };\n}\n\nfunction collectDiscoveredVfuncs<K extends \"class\" | \"interface\">(\n klass: AnyClass,\n resolveDescriptor: (methodName: string) => VfuncDescriptor<K> | undefined,\n skip?: Set<string>,\n): DiscoveredVfunc<K>[] {\n const proto = (klass as { prototype: Record<string, VfuncFn> }).prototype;\n const result: DiscoveredVfunc<K>[] = [];\n\n for (const methodName of ownInstanceMethodNames(klass)) {\n const discovered = buildDiscoveredVfunc(proto, methodName, resolveDescriptor, skip);\n\n if (discovered) {\n result.push(discovered);\n }\n }\n\n return result;\n}\n\nfunction discoverClassVfuncs(klass: AnyClass): DiscoveredClassVfunc[] {\n return collectDiscoveredVfuncs(klass, (methodName) => {\n const descriptor = findClassVfuncDescriptor(klass, methodName);\n\n if (descriptor && UNSUPPORTED_CONSTRUCT_VFUNCS.has(methodName)) {\n throw new Error(\n `registerClass: overriding the GObject construct-time vtable slot '${methodName}' is not ` +\n \"supported; run construct-time initialization in the subclass constructor, after \" +\n \"super(...), instead\",\n );\n }\n\n return descriptor ?? undefined;\n });\n}\n\nfunction wrapVfunc(\n fn: VfuncFn,\n argDescriptors: NativeRegisterClassVfunc[\"argDescriptors\"],\n returnDescriptor: NativeRegisterClassVfunc[\"returnDescriptor\"],\n): VfuncFn {\n return wrapCallback(fn as (...args: unknown[]) => unknown, { argDescriptors, returnDescriptor }, \"this\");\n}\n\nfunction discoverInheritedInterfaceVfuncs(\n klass: AnyClass,\n parentGtype: bigint,\n claimedMethodNames: Set<string>,\n): InterfaceVfuncBinding[] {\n const bindings: InterfaceVfuncBinding[] = [];\n\n for (const interfaceGtype of typeInterfaces(parentGtype)) {\n const [first, ...rest] = discoverInterfaceVfuncs(klass, interfaceGtype, claimedMethodNames);\n\n if (first !== undefined) {\n bindings.push({ gtype: interfaceGtype, vtableSize: first.vtableSize, vfuncs: [first, ...rest] });\n }\n }\n\n return bindings;\n}\n\nfunction discoverInterfaceVfuncs(\n klass: AnyClass,\n interfaceGtype: bigint,\n claimedMethodNames: Set<string>,\n): DiscoveredInterfaceVfunc[] {\n const vfuncRegistry = getInterfaceVfuncRegistry(interfaceGtype);\n\n if (!vfuncRegistry) {\n return [];\n }\n\n return collectDiscoveredVfuncs(\n klass,\n (methodName) => {\n const entry = vfuncRegistry[methodName];\n\n return entry?.kind === \"interface\" ? entry : undefined;\n },\n claimedMethodNames,\n );\n}\n\nfunction findClassVfuncDescriptor(klass: AnyClass, methodName: string): VfuncDescriptor<\"class\"> | null {\n return (\n walkClassChain(getParentClass(klass), (cls) => {\n const entry = getVfuncRegistry(cls)?.[methodName];\n\n return entry?.kind === \"class\" ? entry : undefined;\n }) ?? null\n );\n}\n\nfunction propertyVfuncs(klass: AnyClass, accessors: PropertyAccessor[]): DiscoveredClassVfunc[] {\n if (accessors.length === 0) {\n return [];\n }\n\n return [\n buildPropertyVfunc(klass, \"getProperty\", makeGetProperty(accessors), true),\n buildPropertyVfunc(klass, \"setProperty\", makeSetProperty(accessors), false),\n ];\n}\n\n// `get_property` fills a GValue the caller owns, so the marshalled copy handed to JavaScript has to\n// be written back into it; `set_property` only reads its GValue and needs no copy back.\nfunction markValueCallerAllocated(argDescriptors: Descriptor[]): Descriptor[] {\n return argDescriptors.map((arg, index) =>\n index === VALUE_ARG_INDEX ? { ...arg, callerAllocated: true } : arg);\n}\n\nfunction buildPropertyVfunc(\n klass: AnyClass,\n methodName: string,\n fn: VfuncFn,\n isValueOut: boolean,\n): DiscoveredClassVfunc {\n const descriptor = findClassVfuncDescriptor(klass, methodName);\n\n if (!descriptor) {\n throw new Error(`registerClass: the parent class exposes no '${methodName}' vtable slot`);\n }\n\n const argDescriptors = isValueOut\n ? markValueCallerAllocated(descriptor.argDescriptors)\n : descriptor.argDescriptors;\n\n return {\n ...descriptor,\n methodName,\n argDescriptors,\n fn: wrapVfunc(fn, argDescriptors, descriptor.returnDescriptor),\n };\n}\n\nfunction toNativeOptions(\n classVfuncs: DiscoveredClassVfunc[],\n interfaceBindings: InterfaceVfuncBinding[],\n properties: Record<string, PropertySpec>,\n): NativeRegisterClassOptions | undefined {\n const hasInterfaces = interfaceBindings.length > 0;\n const hasClassVfuncs = classVfuncs.length > 0;\n const hasProperties = Object.keys(properties).length > 0;\n\n if (!hasClassVfuncs && !hasInterfaces && !hasProperties) {\n return undefined;\n }\n\n const options: NativeRegisterClassOptions = {};\n\n if (hasProperties) {\n options.properties = toNativeProperties(properties);\n }\n\n if (hasClassVfuncs) {\n options.vfuncs = [...classVfuncs];\n }\n\n if (hasInterfaces) {\n options.interfaces = interfaceBindings.map((binding) => ({\n type: binding.gtype,\n vtableSize: binding.vtableSize,\n vfuncs: [...binding.vfuncs],\n }));\n }\n\n return options;\n}\n\nexport { registerClass };\n"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { AnyClass } from "@gtkx/utils";
|
|
2
|
+
import { type ExternalObject, type Handle, type RegisterClassVfunc as NativeRegisterClassVfunc } from "@gtkx/native";
|
|
3
|
+
import type { Mixin } from "./mixin.js";
|
|
4
|
+
import { type TypedClass } from "./type.js";
|
|
5
|
+
/**
|
|
6
|
+
* Static side of class `C` with its construct signature preserved but the member
|
|
7
|
+
* named `K` (default `"new"`) removed.
|
|
8
|
+
*/
|
|
9
|
+
type StaticBase<C, K extends PropertyKey = "new"> = Omit<C, K> & (C extends new (...args: infer A) => infer R ? new (...args: A) => R : never);
|
|
10
|
+
type VfuncDescriptor<K extends "class" | "interface"> = {
|
|
11
|
+
kind: K;
|
|
12
|
+
className: string;
|
|
13
|
+
vfuncName: string;
|
|
14
|
+
byteOffset: number;
|
|
15
|
+
vtableSize: number;
|
|
16
|
+
argDescriptors: NativeRegisterClassVfunc["argDescriptors"];
|
|
17
|
+
returnDescriptor: NativeRegisterClassVfunc["returnDescriptor"];
|
|
18
|
+
};
|
|
19
|
+
type VfuncRegistry = Record<string, VfuncDescriptor<"class"> | VfuncDescriptor<"interface">>;
|
|
20
|
+
declare function getClassType(cls: AnyClass): bigint;
|
|
21
|
+
/** Returns the GType tag of the given wrapper instance. */
|
|
22
|
+
declare function getInstanceType(instance: object): bigint;
|
|
23
|
+
declare function registerClassType(cls: AnyClass, type: bigint): void;
|
|
24
|
+
/**
|
|
25
|
+
* Registers a wrapper class as the JS representation of a GType, optionally
|
|
26
|
+
* installing a registry of virtual functions.
|
|
27
|
+
* @param cls Wrapper class to associate with the type.
|
|
28
|
+
* @param type GType the class wraps.
|
|
29
|
+
* @param vfuncs Virtual functions the class overrides.
|
|
30
|
+
*/
|
|
31
|
+
declare function registerWrapperClass(cls: AnyClass, type: bigint, vfuncs?: VfuncRegistry): void;
|
|
32
|
+
/**
|
|
33
|
+
* Registers a GInterface, associating its GType with a mixin used to compose the
|
|
34
|
+
* interface onto wrapper classes and an optional virtual function registry.
|
|
35
|
+
* @param cls Class carrying the interface's GType tag.
|
|
36
|
+
* @param type GType of the interface.
|
|
37
|
+
* @param mixin Mixin that applies the interface to a wrapper class.
|
|
38
|
+
* @param vfuncs Virtual functions the interface exposes.
|
|
39
|
+
*/
|
|
40
|
+
declare function registerInterface(cls: AnyClass, type: bigint, mixin: Mixin, vfuncs?: VfuncRegistry): void;
|
|
41
|
+
/**
|
|
42
|
+
* Wraps a native handle in a JS wrapper instance. With no class, resolves and
|
|
43
|
+
* reuses the wrapper for the handle's runtime GType (composing interface mixins);
|
|
44
|
+
* with an explicit class, creates a bare instance backed by the handle. Returns
|
|
45
|
+
* null for a null or undefined handle.
|
|
46
|
+
* @param handle Native handle to wrap.
|
|
47
|
+
* @param cls Wrapper class to instantiate, or omitted to resolve it from the runtime type.
|
|
48
|
+
*/
|
|
49
|
+
declare function wrapHandle(handle: null | undefined, cls?: AnyClass): null;
|
|
50
|
+
declare function wrapHandle<T extends object>(handle: ExternalObject<Handle>, cls: AnyClass<T>): T;
|
|
51
|
+
declare function wrapHandle<T extends object>(handle: ExternalObject<Handle> | null | undefined, cls: AnyClass<T>): T | null;
|
|
52
|
+
declare function wrapHandle(handle: ExternalObject<Handle>, cls?: AnyClass): TypedClass;
|
|
53
|
+
declare function wrapHandle(handle: ExternalObject<Handle> | null | undefined, cls?: AnyClass): TypedClass | null;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the wrapper class registered for a GType, walking up to ancestor types,
|
|
56
|
+
* and throws if none is registered.
|
|
57
|
+
*/
|
|
58
|
+
declare function getWrapperClass(type: bigint): AnyClass;
|
|
59
|
+
declare function resolveWrapperClass(type: bigint): AnyClass | null;
|
|
60
|
+
/** Returns the native handle bound to a wrapper instance, throwing if none is set. */
|
|
61
|
+
declare function getHandle(instance: object): ExternalObject<Handle>;
|
|
62
|
+
/** Returns the native handle bound to an instance, or undefined when there is none or the instance is null. */
|
|
63
|
+
declare function tryGetHandle(instance: object | null | undefined): ExternalObject<Handle> | undefined;
|
|
64
|
+
/** Associates a native handle with a wrapper instance. */
|
|
65
|
+
declare function setHandle(instance: object, handle: ExternalObject<Handle>): void;
|
|
66
|
+
declare function getVfuncRegistry(cls: object): VfuncRegistry | undefined;
|
|
67
|
+
declare function getInterfaceVfuncRegistry(type: bigint): VfuncRegistry | undefined;
|
|
68
|
+
export { getClassType, getInstanceType, registerClassType, registerWrapperClass, registerInterface, wrapHandle, getWrapperClass, resolveWrapperClass, getHandle, tryGetHandle, setHandle, getVfuncRegistry, getInterfaceVfuncRegistry, type StaticBase, type VfuncDescriptor, type VfuncRegistry, };
|
|
69
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EACH,KAAK,cAAc,EAGnB,KAAK,MAAM,EACX,KAAK,kBAAkB,IAAI,wBAAwB,EAEtD,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,KAAK,EAAiB,MAAM,YAAY,CAAC;AACvD,OAAO,EAAgB,KAAK,UAAU,EAAiD,MAAM,WAAW,CAAC;AAEzG;;;GAGG;AACH,KAAK,UAAU,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,GAAG,KAAK,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAC1D,CAAC,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,MAAM,CAAC,GAAG,KAAK,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC;AAElF,KAAK,eAAe,CAAC,CAAC,SAAS,OAAO,GAAG,WAAW,IAAI;IACpD,IAAI,EAAE,CAAC,CAAC;IACR,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,wBAAwB,CAAC,gBAAgB,CAAC,CAAC;IAC3D,gBAAgB,EAAE,wBAAwB,CAAC,kBAAkB,CAAC,CAAC;CAClE,CAAC;AAEF,KAAK,aAAa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c,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,EAAE,GAAG,CAAC,EAAE,QAAQ,GAAG,UAAU,GAAG,IAAI,CAAC;AAiB1G;;;GAGG;AACH,iBAAS,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAQ/C;AAED,iBAAS,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAc1D;AAsFD,sFAAsF;AACtF,iBAAS,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC,CAS3D;AAED,+GAA+G;AAC/G,iBAAS,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,cAAc,CAAC,MAAM,CAAC,GAAG,SAAS,CAE7F;AAED,0DAA0D;AAC1D,iBAAS,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,IAAI,CAEzE;AAWD,iBAAS,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAEhE;AAUD,iBAAS,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAE1E;AAED,OAAO,EACH,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,mBAAmB,EACnB,SAAS,EACT,YAAY,EACZ,SAAS,EACT,gBAAgB,EAChB,yBAAyB,EACzB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,aAAa,GACrB,CAAC"}
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { getType, getWrapper, setWrapper, } from "@gtkx/native";
|
|
2
|
+
import { TYPE_INVALID, typeInterfaces, typeIsA, typeName, typeParent } from "./type.js";
|
|
3
|
+
const classRegistry = new Map();
|
|
4
|
+
const interfaceMixinRegistry = new Map();
|
|
5
|
+
const composedClassRegistry = new Map();
|
|
6
|
+
const handleMap = new WeakMap();
|
|
7
|
+
const vfuncRegistry = new WeakMap();
|
|
8
|
+
const interfaceVfuncRegistry = new Map();
|
|
9
|
+
function setClassType(cls, type) {
|
|
10
|
+
cls.prototype.__type__ = type;
|
|
11
|
+
}
|
|
12
|
+
function getClassType(cls) {
|
|
13
|
+
const proto = cls.prototype;
|
|
14
|
+
return Object.hasOwn(proto, "__type__") ? proto.__type__ : TYPE_INVALID;
|
|
15
|
+
}
|
|
16
|
+
/** Returns the GType tag of the given wrapper instance. */
|
|
17
|
+
function getInstanceType(instance) {
|
|
18
|
+
return getClassType(instance.constructor);
|
|
19
|
+
}
|
|
20
|
+
function registerClassType(cls, type) {
|
|
21
|
+
if (type === TYPE_INVALID) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
classRegistry.set(type, cls);
|
|
25
|
+
setClassType(cls, type);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Registers a wrapper class as the JS representation of a GType, optionally
|
|
29
|
+
* installing a registry of virtual functions.
|
|
30
|
+
* @param cls Wrapper class to associate with the type.
|
|
31
|
+
* @param type GType the class wraps.
|
|
32
|
+
* @param vfuncs Virtual functions the class overrides.
|
|
33
|
+
*/
|
|
34
|
+
function registerWrapperClass(cls, type, vfuncs) {
|
|
35
|
+
registerClassType(cls, type);
|
|
36
|
+
if (vfuncs) {
|
|
37
|
+
registerVfuncRegistry(cls, vfuncs);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Registers a GInterface, associating its GType with a mixin used to compose the
|
|
42
|
+
* interface onto wrapper classes and an optional virtual function registry.
|
|
43
|
+
* @param cls Class carrying the interface's GType tag.
|
|
44
|
+
* @param type GType of the interface.
|
|
45
|
+
* @param mixin Mixin that applies the interface to a wrapper class.
|
|
46
|
+
* @param vfuncs Virtual functions the interface exposes.
|
|
47
|
+
*/
|
|
48
|
+
function registerInterface(cls, type, mixin, vfuncs) {
|
|
49
|
+
if (type === TYPE_INVALID) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
setClassType(cls, type);
|
|
53
|
+
interfaceMixinRegistry.set(type, mixin);
|
|
54
|
+
if (vfuncs) {
|
|
55
|
+
registerInterfaceVfuncRegistry(type, vfuncs);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function wrapHandle(handle, cls) {
|
|
59
|
+
if (handle === null || handle === undefined) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
if (cls === undefined) {
|
|
63
|
+
return getOrCreateWrapper(handle);
|
|
64
|
+
}
|
|
65
|
+
const instance = Object.create(cls.prototype);
|
|
66
|
+
setHandle(instance, handle);
|
|
67
|
+
return instance;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Returns the wrapper class registered for a GType, walking up to ancestor types,
|
|
71
|
+
* and throws if none is registered.
|
|
72
|
+
*/
|
|
73
|
+
function getWrapperClass(type) {
|
|
74
|
+
const cls = resolveWrapperClass(type);
|
|
75
|
+
if (!cls) {
|
|
76
|
+
throw new Error(`No registered wrapper class for type '${typeName(type) ?? String(type)}'`);
|
|
77
|
+
}
|
|
78
|
+
return cls;
|
|
79
|
+
}
|
|
80
|
+
function resolveWrapperClass(type) {
|
|
81
|
+
let currentType = type;
|
|
82
|
+
while (currentType !== TYPE_INVALID) {
|
|
83
|
+
const cls = classRegistry.get(currentType);
|
|
84
|
+
if (cls) {
|
|
85
|
+
return cls;
|
|
86
|
+
}
|
|
87
|
+
currentType = typeParent(currentType);
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
function applyInterfaceMixin(cls, type, baseType, applied) {
|
|
92
|
+
if (applied.has(type) || typeIsA(baseType, type)) {
|
|
93
|
+
return cls;
|
|
94
|
+
}
|
|
95
|
+
const mixin = interfaceMixinRegistry.get(type);
|
|
96
|
+
if (mixin === undefined) {
|
|
97
|
+
return cls;
|
|
98
|
+
}
|
|
99
|
+
applied.add(type);
|
|
100
|
+
return mixin(cls);
|
|
101
|
+
}
|
|
102
|
+
function createComposedClass(base, runtimeType) {
|
|
103
|
+
const baseType = getClassType(base);
|
|
104
|
+
const applied = new Set();
|
|
105
|
+
let cls = base;
|
|
106
|
+
for (const type of typeInterfaces(runtimeType)) {
|
|
107
|
+
cls = applyInterfaceMixin(cls, type, baseType, applied);
|
|
108
|
+
}
|
|
109
|
+
return applied.size === 0 ? base : cls;
|
|
110
|
+
}
|
|
111
|
+
function resolveComposedClass(runtimeType) {
|
|
112
|
+
const exact = classRegistry.get(runtimeType);
|
|
113
|
+
if (exact) {
|
|
114
|
+
return exact;
|
|
115
|
+
}
|
|
116
|
+
const cached = composedClassRegistry.get(runtimeType);
|
|
117
|
+
if (cached) {
|
|
118
|
+
return cached;
|
|
119
|
+
}
|
|
120
|
+
const base = resolveWrapperClass(runtimeType);
|
|
121
|
+
if (base === null) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
const composed = createComposedClass(base, runtimeType);
|
|
125
|
+
if (composed === base) {
|
|
126
|
+
return base;
|
|
127
|
+
}
|
|
128
|
+
setClassType(composed, runtimeType);
|
|
129
|
+
composedClassRegistry.set(runtimeType, composed);
|
|
130
|
+
return composed;
|
|
131
|
+
}
|
|
132
|
+
function getOrCreateWrapper(handle) {
|
|
133
|
+
const existing = getWrapper(handle);
|
|
134
|
+
if (existing) {
|
|
135
|
+
return existing;
|
|
136
|
+
}
|
|
137
|
+
const runtimeType = getType(handle);
|
|
138
|
+
if (runtimeType === TYPE_INVALID) {
|
|
139
|
+
throw new Error("Cannot resolve runtime GLib type from handle");
|
|
140
|
+
}
|
|
141
|
+
const cls = resolveComposedClass(runtimeType);
|
|
142
|
+
if (!cls) {
|
|
143
|
+
throw new Error(`Expected registered GLib type, got type ${String(runtimeType)}`);
|
|
144
|
+
}
|
|
145
|
+
const instance = Object.create(cls.prototype);
|
|
146
|
+
registerWrapper(handle, instance);
|
|
147
|
+
return instance;
|
|
148
|
+
}
|
|
149
|
+
/** Returns the native handle bound to a wrapper instance, throwing if none is set. */
|
|
150
|
+
function getHandle(instance) {
|
|
151
|
+
const handle = handleMap.get(instance);
|
|
152
|
+
if (handle === undefined) {
|
|
153
|
+
const name = instance.constructor?.name ?? "object";
|
|
154
|
+
throw new Error(`No native handle associated with ${name}`);
|
|
155
|
+
}
|
|
156
|
+
return handle;
|
|
157
|
+
}
|
|
158
|
+
/** Returns the native handle bound to an instance, or undefined when there is none or the instance is null. */
|
|
159
|
+
function tryGetHandle(instance) {
|
|
160
|
+
return instance == null ? undefined : handleMap.get(instance);
|
|
161
|
+
}
|
|
162
|
+
/** Associates a native handle with a wrapper instance. */
|
|
163
|
+
function setHandle(instance, handle) {
|
|
164
|
+
handleMap.set(instance, handle);
|
|
165
|
+
}
|
|
166
|
+
function registerWrapper(handle, instance) {
|
|
167
|
+
setHandle(instance, handle);
|
|
168
|
+
setWrapper(handle, instance);
|
|
169
|
+
}
|
|
170
|
+
function registerVfuncRegistry(cls, registry) {
|
|
171
|
+
vfuncRegistry.set(cls, registry);
|
|
172
|
+
}
|
|
173
|
+
function getVfuncRegistry(cls) {
|
|
174
|
+
return vfuncRegistry.get(cls);
|
|
175
|
+
}
|
|
176
|
+
function registerInterfaceVfuncRegistry(type, registry) {
|
|
177
|
+
if (type === TYPE_INVALID) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
interfaceVfuncRegistry.set(type, registry);
|
|
181
|
+
}
|
|
182
|
+
function getInterfaceVfuncRegistry(type) {
|
|
183
|
+
return interfaceVfuncRegistry.get(type);
|
|
184
|
+
}
|
|
185
|
+
export { getClassType, getInstanceType, registerClassType, registerWrapperClass, registerInterface, wrapHandle, getWrapperClass, resolveWrapperClass, getHandle, tryGetHandle, setHandle, getVfuncRegistry, getInterfaceVfuncRegistry, };
|
|
186
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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C,CAAC;AAClC,CAAC;AAED,SAAS,8BAA8B,CAAC,IAAY,EAAE,QAAuB;IACzE,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;QACxB,OAAO;IACX,CAAC;IAED,sBAAsB,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC/C,CAAC;AAED,SAAS,yBAAyB,CAAC,IAAY;IAC3C,OAAO,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED,OAAO,EACH,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,mBAAmB,EACnB,SAAS,EACT,YAAY,EACZ,SAAS,EACT,gBAAgB,EAChB,yBAAyB,GAI5B,CAAC","sourcesContent":["import type { AnyClass } from \"@gtkx/utils\";\nimport {\n type ExternalObject,\n getType,\n getWrapper,\n type Handle,\n type RegisterClassVfunc as NativeRegisterClassVfunc,\n setWrapper,\n} from \"@gtkx/native\";\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\ntype VfuncDescriptor<K extends \"class\" | \"interface\"> = {\n kind: K;\n className: string;\n vfuncName: string;\n byteOffset: number;\n vtableSize: number;\n argDescriptors: NativeRegisterClassVfunc[\"argDescriptors\"];\n returnDescriptor: NativeRegisterClassVfunc[\"returnDescriptor\"];\n};\n\ntype VfuncRegistry = Record<string, VfuncDescriptor<\"class\"> | VfuncDescriptor<\"interface\">>;\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 interfaceVfuncRegistry: Map<bigint, VfuncRegistry> = new Map();\n\nfunction setClassType(cls: AnyClass, type: bigint): void {\n (cls.prototype as { [K in keyof TypedClass]: TypedClass[K] }).__type__ = type;\n}\n\nfunction getClassType(cls: AnyClass): bigint {\n const proto: object = cls.prototype;\n\n return Object.hasOwn(proto, \"__type__\") ? (proto as TypedClass).__type__ : TYPE_INVALID;\n}\n\n/** Returns the GType tag of the given wrapper instance. */\nfunction getInstanceType(instance: object): bigint {\n return getClassType(instance.constructor as AnyClass);\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 Virtual functions the class overrides.\n */\nfunction registerWrapperClass(cls: AnyClass, type: bigint, vfuncs?: VfuncRegistry): void {\n registerClassType(cls, type);\n\n if (vfuncs) {\n registerVfuncRegistry(cls, vfuncs);\n }\n}\n\n/**\n * Registers a GInterface, associating its GType with a mixin used to compose the\n * interface onto wrapper classes and an optional virtual function registry.\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 vfuncs Virtual functions the interface exposes.\n */\nfunction registerInterface(cls: AnyClass, type: bigint, mixin: Mixin, vfuncs?: VfuncRegistry): void {\n if (type === TYPE_INVALID) {\n return;\n }\n\n setClassType(cls, type);\n interfaceMixinRegistry.set(type, mixin);\n\n if (vfuncs) {\n registerInterfaceVfuncRegistry(type, vfuncs);\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 * with an explicit class, creates a bare instance backed by the handle. Returns\n * null for 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 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 = interfaceMixinRegistry.get(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 composedClassRegistry.set(runtimeType, composed);\n\n return composed;\n}\n\nfunction getOrCreateWrapper(handle: ExternalObject<Handle>): object {\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\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 const name = (instance as { constructor?: { name?: string } }).constructor?.name ?? \"object\";\n throw new Error(`No native handle associated with ${name}`);\n }\n\n return handle;\n}\n\n/** Returns the native handle bound to an instance, or undefined when there is none or the instance is null. */\nfunction tryGetHandle(instance: object | null | undefined): ExternalObject<Handle> | undefined {\n return instance == null ? undefined : handleMap.get(instance);\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 registerInterfaceVfuncRegistry(type: bigint, registry: VfuncRegistry): void {\n if (type === TYPE_INVALID) {\n return;\n }\n\n interfaceVfuncRegistry.set(type, registry);\n}\n\nfunction getInterfaceVfuncRegistry(type: bigint): VfuncRegistry | undefined {\n return interfaceVfuncRegistry.get(type);\n}\n\nexport {\n getClassType,\n getInstanceType,\n registerClassType,\n registerWrapperClass,\n registerInterface,\n wrapHandle,\n getWrapperClass,\n resolveWrapperClass,\n getHandle,\n tryGetHandle,\n setHandle,\n getVfuncRegistry,\n getInterfaceVfuncRegistry,\n type StaticBase,\n type VfuncDescriptor,\n type VfuncRegistry,\n};\n"]}
|
package/dist/signal.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Descriptor } from "@gtkx/native";
|
|
2
|
+
import { type Arg } from "./arg.js";
|
|
3
|
+
import { type CallbackDescriptor } from "./descriptors.js";
|
|
4
|
+
/** Function invoked when a connected GObject signal is emitted. */
|
|
5
|
+
type SignalHandler = (...args: unknown[]) => unknown;
|
|
6
|
+
type SignalConnectSpec = {
|
|
7
|
+
callback: CallbackDescriptor;
|
|
8
|
+
handler: SignalHandler;
|
|
9
|
+
after: boolean;
|
|
10
|
+
};
|
|
11
|
+
type EmitArg = Arg & {
|
|
12
|
+
value?: unknown;
|
|
13
|
+
};
|
|
14
|
+
/** Returns the signal name without its detail suffix (the part after `::`). */
|
|
15
|
+
declare const getSignalBaseName: (signal: string) => string;
|
|
16
|
+
declare const isSignalHandlerConnected: (instance: object, handlerId: number) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Connects a handler to a GObject signal on an instance and returns the handler id.
|
|
19
|
+
* @param instance Emitter to connect to.
|
|
20
|
+
* @param signal Signal name, optionally including a `::detail` suffix.
|
|
21
|
+
* @param spec Callback descriptor, handler function, and whether to run after the default handler.
|
|
22
|
+
*/
|
|
23
|
+
declare function connectSignal(instance: object, signal: string, spec: SignalConnectSpec): number;
|
|
24
|
+
declare function blockMatchedSignalHandlers(instance: object, signal: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Emits a signal on an instance with the given arguments and returns its result
|
|
27
|
+
* combined with any output-argument values.
|
|
28
|
+
* @param instance Emitter to emit the signal on.
|
|
29
|
+
* @param signal Signal name, optionally including a `::detail` suffix.
|
|
30
|
+
* @param args Arguments to pass, including output and inout arguments.
|
|
31
|
+
* @param returnDescriptor Descriptor for the signal's return value, omitted when it returns void.
|
|
32
|
+
*/
|
|
33
|
+
declare function emitSignal(instance: object, signal: string, args: EmitArg[], returnDescriptor?: Descriptor): unknown;
|
|
34
|
+
export { getSignalBaseName, connectSignal, blockMatchedSignalHandlers, emitSignal, isSignalHandlerConnected, type SignalHandler, };
|
|
35
|
+
//# sourceMappingURL=signal.d.ts.map
|
|
@@ -0,0 +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,KAAK,iBAAiB,GAAG;IACrB,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,OAAO,EAAE,aAAa,CAAC;IACvB,KAAK,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,KAAK,OAAO,GAAG,GAAG,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AA2BzC,+EAA+E;AAC/E,QAAA,MAAM,iBAAiB,GAAI,QAAQ,MAAM,KAAG,MAI3C,CAAC;AAYF,QAAA,MAAM,wBAAwB,GAAI,UAAU,MAAM,EAAE,WAAW,MAAM,KAAG,OACA,CAAC;AAoBzE;;;;;GAKG;AACH,iBAAS,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,GAAG,MAAM,CAOxF;AAED,iBAAS,0BAA0B,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAG1E;AAoBD;;;;;;;GAOG;AACH,iBAAS,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,gBAAgB,CAAC,EAAE,UAAU,GAAG,OAAO,CAiC7G;AAED,OAAO,EACH,iBAAiB,EACjB,aAAa,EACb,0BAA0B,EAC1B,UAAU,EACV,wBAAwB,EACxB,KAAK,aAAa,GACrB,CAAC"}
|
package/dist/signal.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { isCallerAllocatedArg, isInoutArg, isOutputArg } from "./arg.js";
|
|
2
|
+
import { bind, createBindCache } from "./bind.js";
|
|
3
|
+
import { wrapCallback } from "./callback.js";
|
|
4
|
+
import { arrayT, biguint64T, booleanT, objectT, stringT, uint32T, uint64T, voidT, } from "./descriptors.js";
|
|
5
|
+
import { LIB, VALUE_SIZE, VALUE_T } from "./library.js";
|
|
6
|
+
import { getHandle } from "./registry.js";
|
|
7
|
+
import { packTupleResult } from "./tuple.js";
|
|
8
|
+
import { fromValue, getBoxedValue, inoutValueForBoxedDescriptor, newValueForDescriptor, outValueForBoxedDescriptor, outValueForDescriptor, toValue, } from "./value.js";
|
|
9
|
+
const connectCache = createBindCache();
|
|
10
|
+
const gQuarkFromString = bind(LIB, "g_quark_from_string", [stringT("borrowed")], uint32T);
|
|
11
|
+
const gSignalLookup = bind(LIB, "g_signal_lookup", [stringT("borrowed"), biguint64T], uint32T);
|
|
12
|
+
const gSignalEmitv = bind(LIB, "g_signal_emitv", [arrayT(VALUE_T, "array", "borrowed", { elementSize: VALUE_SIZE }), uint32T, uint32T, VALUE_T], voidT);
|
|
13
|
+
const gSignalHandlersBlockMatched = bind(LIB, "g_signal_handlers_block_matched", [objectT("borrowed"), uint32T, uint32T, uint32T, objectT("borrowed"), objectT("borrowed"), objectT("borrowed")], uint32T);
|
|
14
|
+
const gSignalHandlerIsConnected = bind(LIB, "g_signal_handler_is_connected", [objectT("borrowed"), uint64T], booleanT);
|
|
15
|
+
/** Returns the signal name without its detail suffix (the part after `::`). */
|
|
16
|
+
const getSignalBaseName = (signal) => {
|
|
17
|
+
const detailIndex = signal.indexOf("::");
|
|
18
|
+
return detailIndex === -1 ? signal : signal.slice(0, detailIndex);
|
|
19
|
+
};
|
|
20
|
+
function getSignalDetailQuark(signal) {
|
|
21
|
+
const detailIndex = signal.indexOf("::");
|
|
22
|
+
if (detailIndex === -1) {
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
return gQuarkFromString(signal.slice(detailIndex + 2));
|
|
26
|
+
}
|
|
27
|
+
const isSignalHandlerConnected = (instance, handlerId) => gSignalHandlerIsConnected(getHandle(instance), handlerId);
|
|
28
|
+
const getSignalId = (instance, signal) => {
|
|
29
|
+
const type = instance.__type__;
|
|
30
|
+
return gSignalLookup(getSignalBaseName(signal), type);
|
|
31
|
+
};
|
|
32
|
+
function connectBind(type, signal, callback) {
|
|
33
|
+
const key = `${String(type)}\0${getSignalBaseName(signal)}`;
|
|
34
|
+
return connectCache(key, LIB, "g_signal_connect_data", [objectT("borrowed"), stringT("borrowed"), callback, uint32T], uint64T);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Connects a handler to a GObject signal on an instance and returns the handler id.
|
|
38
|
+
* @param instance Emitter to connect to.
|
|
39
|
+
* @param signal Signal name, optionally including a `::detail` suffix.
|
|
40
|
+
* @param spec Callback descriptor, handler function, and whether to run after the default handler.
|
|
41
|
+
*/
|
|
42
|
+
function connectSignal(instance, signal, spec) {
|
|
43
|
+
const { callback, handler, after } = spec;
|
|
44
|
+
const wrapped = wrapCallback(handler, callback, "emitter");
|
|
45
|
+
const type = instance.__type__;
|
|
46
|
+
const connect = connectBind(type, signal, callback);
|
|
47
|
+
return connect(getHandle(instance), signal, wrapped, after ? 1 : 0);
|
|
48
|
+
}
|
|
49
|
+
function blockMatchedSignalHandlers(instance, signal) {
|
|
50
|
+
const signalId = getSignalId(instance, signal);
|
|
51
|
+
gSignalHandlersBlockMatched(getHandle(instance), 1, signalId, 0, undefined, undefined, undefined);
|
|
52
|
+
}
|
|
53
|
+
const createEmitValue = (arg) => {
|
|
54
|
+
if (!isOutputArg(arg)) {
|
|
55
|
+
return { value: toValue(arg.type, arg.value) };
|
|
56
|
+
}
|
|
57
|
+
if (isCallerAllocatedArg(arg)) {
|
|
58
|
+
if (isInoutArg(arg)) {
|
|
59
|
+
return { value: inoutValueForBoxedDescriptor(arg.type, arg.value) };
|
|
60
|
+
}
|
|
61
|
+
const value = outValueForBoxedDescriptor(arg.type, arg.value);
|
|
62
|
+
return { value, read: () => getBoxedValue(value) };
|
|
63
|
+
}
|
|
64
|
+
return isInoutArg(arg) ? outValueForDescriptor(arg.type, arg.value) : outValueForDescriptor(arg.type);
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Emits a signal on an instance with the given arguments and returns its result
|
|
68
|
+
* combined with any output-argument values.
|
|
69
|
+
* @param instance Emitter to emit the signal on.
|
|
70
|
+
* @param signal Signal name, optionally including a `::detail` suffix.
|
|
71
|
+
* @param args Arguments to pass, including output and inout arguments.
|
|
72
|
+
* @param returnDescriptor Descriptor for the signal's return value, omitted when it returns void.
|
|
73
|
+
*/
|
|
74
|
+
function emitSignal(instance, signal, args, returnDescriptor) {
|
|
75
|
+
const signalId = getSignalId(instance, signal);
|
|
76
|
+
const detail = getSignalDetailQuark(signal);
|
|
77
|
+
const values = [toValue(objectT("full"), instance)];
|
|
78
|
+
const reads = [];
|
|
79
|
+
for (const arg of args) {
|
|
80
|
+
const { value, read } = createEmitValue(arg);
|
|
81
|
+
values.push(value);
|
|
82
|
+
if (read) {
|
|
83
|
+
reads.push(read);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (returnDescriptor !== undefined) {
|
|
87
|
+
const returnValue = newValueForDescriptor(returnDescriptor);
|
|
88
|
+
gSignalEmitv(values, signalId, detail, returnValue);
|
|
89
|
+
return packTupleResult(reads.map((read) => read()), fromValue(returnValue), true);
|
|
90
|
+
}
|
|
91
|
+
gSignalEmitv(values, signalId, detail, undefined);
|
|
92
|
+
return packTupleResult(reads.map((read) => read()), undefined, false);
|
|
93
|
+
}
|
|
94
|
+
export { getSignalBaseName, connectSignal, blockMatchedSignalHandlers, emitSignal, isSignalHandlerConnected, };
|
|
95
|
+
//# sourceMappingURL=signal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal.js","sourceRoot":"","sources":["../src/signal.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,oBAAoB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACnF,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EACH,MAAM,EACN,UAAU,EACV,QAAQ,EAER,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,KAAK,GACR,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EACH,SAAS,EACT,aAAa,EACb,4BAA4B,EAC5B,qBAAqB,EACrB,0BAA0B,EAC1B,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AAI,EAAE,CAAC,EAC3B,SAAS,EACT,KAAK,CACR,CAAC;AACN,CAAC;AAED,OAAO,EACH,iBAAiB,EACjB,aAAa,EACb,0BAA0B,EAC1B,UAAU,EACV,wBAAwB,GAE3B,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\ntype SignalConnectSpec = {\n callback: CallbackDescriptor;\n handler: SignalHandler;\n after: boolean;\n};\n\ntype EmitArg = Arg & { value?: unknown };\n\nconst connectCache = createBindCache();\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 gSignalHandlersBlockMatched = bind(\n LIB,\n \"g_signal_handlers_block_matched\",\n [objectT(\"borrowed\"), uint32T, uint32T, uint32T, objectT(\"borrowed\"), objectT(\"borrowed\"), objectT(\"borrowed\")],\n uint32T,\n);\n\nconst gSignalHandlerIsConnected = bind(\n LIB,\n \"g_signal_handler_is_connected\",\n [objectT(\"borrowed\"), uint64T],\n booleanT,\n);\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 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, after } = spec;\n const wrapped = wrapCallback(handler, callback, \"emitter\");\n const type: bigint = (instance as TypedClass).__type__;\n const connect = connectBind(type, signal, callback);\n\n return connect(getHandle(instance), signal, wrapped, after ? 1 : 0) as number;\n}\n\nfunction blockMatchedSignalHandlers(instance: object, signal: string): void {\n const signalId = getSignalId(instance, signal);\n gSignalHandlersBlockMatched(getHandle(instance), 1, signalId, 0, undefined, undefined, undefined);\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 blockMatchedSignalHandlers,\n emitSignal,\n isSignalHandlerConnected,\n type SignalHandler,\n};\n"]}
|
package/dist/t.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { bind } from "./bind.js";
|
|
2
|
+
import * as helpers from "./descriptors.js";
|
|
3
|
+
import { fn } from "./fn.js";
|
|
4
|
+
type T = {
|
|
5
|
+
bind: typeof bind;
|
|
6
|
+
int8: typeof helpers.int8T;
|
|
7
|
+
uint8: typeof helpers.uint8T;
|
|
8
|
+
int16: typeof helpers.int16T;
|
|
9
|
+
uint16: typeof helpers.uint16T;
|
|
10
|
+
int32: typeof helpers.int32T;
|
|
11
|
+
uint32: typeof helpers.uint32T;
|
|
12
|
+
int64: typeof helpers.int64T;
|
|
13
|
+
uint64: typeof helpers.uint64T;
|
|
14
|
+
bigint64: typeof helpers.bigint64T;
|
|
15
|
+
biguint64: typeof helpers.biguint64T;
|
|
16
|
+
gtype: typeof helpers.gtypeT;
|
|
17
|
+
float32: typeof helpers.float32T;
|
|
18
|
+
float64: typeof helpers.float64T;
|
|
19
|
+
boolean: typeof helpers.booleanT;
|
|
20
|
+
void: typeof helpers.voidT;
|
|
21
|
+
unichar: typeof helpers.unicharT;
|
|
22
|
+
buffer: typeof helpers.bufferT;
|
|
23
|
+
string: typeof helpers.stringT;
|
|
24
|
+
object: typeof helpers.objectT;
|
|
25
|
+
boxed: typeof helpers.boxedT;
|
|
26
|
+
struct: typeof helpers.structT;
|
|
27
|
+
fundamental: typeof helpers.fundamentalT;
|
|
28
|
+
ref: typeof helpers.refT;
|
|
29
|
+
hashTable: typeof helpers.hashTableT;
|
|
30
|
+
enum: typeof helpers.enumT;
|
|
31
|
+
flags: typeof helpers.flagsT;
|
|
32
|
+
array: typeof helpers.arrayT;
|
|
33
|
+
list: typeof helpers.listT;
|
|
34
|
+
slist: typeof helpers.slistT;
|
|
35
|
+
ptrArray: typeof helpers.ptrArrayT;
|
|
36
|
+
gArray: typeof helpers.gArrayT;
|
|
37
|
+
byteArray: typeof helpers.byteArrayT;
|
|
38
|
+
sizedArray: typeof helpers.sizedArrayT;
|
|
39
|
+
fixedArray: typeof helpers.fixedArrayT;
|
|
40
|
+
callback: typeof helpers.callbackT;
|
|
41
|
+
fn: typeof fn;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Type descriptor builder: a collection of factory helpers that describe C types for
|
|
45
|
+
* FFI marshalling, plus `bind` to bind a native function and `fn` to describe a
|
|
46
|
+
* function signature.
|
|
47
|
+
*/
|
|
48
|
+
declare const t: T;
|
|
49
|
+
export { t };
|
|
50
|
+
//# sourceMappingURL=t.d.ts.map
|
package/dist/t.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"t.d.ts","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;AAE7B,KAAK,CAAC,GAAG;IACL,IAAI,EAAE,OAAO,IAAI,CAAC;IAClB,IAAI,EAAE,OAAO,OAAO,CAAC,KAAK,CAAC;IAC3B,KAAK,EAAE,OAAO,OAAO,CAAC,MAAM,CAAC;IAC7B,KAAK,EAAE,OAAO,OAAO,CAAC,MAAM,CAAC;IAC7B,MAAM,EAAE,OAAO,OAAO,CAAC,OAAO,CAAC;IAC/B,KAAK,EAAE,OAAO,OAAO,CAAC,MAAM,CAAC;IAC7B,MAAM,EAAE,OAAO,OAAO,CAAC,OAAO,CAAC;IAC/B,KAAK,EAAE,OAAO,OAAO,CAAC,MAAM,CAAC;IAC7B,MAAM,EAAE,OAAO,OAAO,CAAC,OAAO,CAAC;IAC/B,QAAQ,EAAE,OAAO,OAAO,CAAC,SAAS,CAAC;IACnC,SAAS,EAAE,OAAO,OAAO,CAAC,UAAU,CAAC;IACrC,KAAK,EAAE,OAAO,OAAO,CAAC,MAAM,CAAC;IAC7B,OAAO,EAAE,OAAO,OAAO,CAAC,QAAQ,CAAC;IACjC,OAAO,EAAE,OAAO,OAAO,CAAC,QAAQ,CAAC;IACjC,OAAO,EAAE,OAAO,OAAO,CAAC,QAAQ,CAAC;IACjC,IAAI,EAAE,OAAO,OAAO,CAAC,KAAK,CAAC;IAC3B,OAAO,EAA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"./fn.js";
|
|
4
|
+
/**
|
|
5
|
+
* Type descriptor builder: a collection of factory helpers that describe C types for
|
|
6
|
+
* FFI marshalling, plus `bind` to bind a native function and `fn` to describe a
|
|
7
|
+
* function signature.
|
|
8
|
+
*/
|
|
9
|
+
const t = {
|
|
10
|
+
bind,
|
|
11
|
+
int8: helpers.int8T,
|
|
12
|
+
uint8: helpers.uint8T,
|
|
13
|
+
int16: helpers.int16T,
|
|
14
|
+
uint16: helpers.uint16T,
|
|
15
|
+
int32: helpers.int32T,
|
|
16
|
+
uint32: helpers.uint32T,
|
|
17
|
+
int64: helpers.int64T,
|
|
18
|
+
uint64: helpers.uint64T,
|
|
19
|
+
bigint64: helpers.bigint64T,
|
|
20
|
+
biguint64: helpers.biguint64T,
|
|
21
|
+
gtype: helpers.gtypeT,
|
|
22
|
+
float32: helpers.float32T,
|
|
23
|
+
float64: helpers.float64T,
|
|
24
|
+
boolean: helpers.booleanT,
|
|
25
|
+
void: helpers.voidT,
|
|
26
|
+
unichar: helpers.unicharT,
|
|
27
|
+
buffer: helpers.bufferT,
|
|
28
|
+
string: helpers.stringT,
|
|
29
|
+
object: helpers.objectT,
|
|
30
|
+
boxed: helpers.boxedT,
|
|
31
|
+
struct: helpers.structT,
|
|
32
|
+
fundamental: helpers.fundamentalT,
|
|
33
|
+
ref: helpers.refT,
|
|
34
|
+
hashTable: helpers.hashTableT,
|
|
35
|
+
enum: helpers.enumT,
|
|
36
|
+
flags: helpers.flagsT,
|
|
37
|
+
array: helpers.arrayT,
|
|
38
|
+
list: helpers.listT,
|
|
39
|
+
slist: helpers.slistT,
|
|
40
|
+
ptrArray: helpers.ptrArrayT,
|
|
41
|
+
gArray: helpers.gArrayT,
|
|
42
|
+
byteArray: helpers.byteArrayT,
|
|
43
|
+
sizedArray: helpers.sizedArrayT,
|
|
44
|
+
fixedArray: helpers.fixedArrayT,
|
|
45
|
+
callback: helpers.callbackT,
|
|
46
|
+
fn,
|
|
47
|
+
};
|
|
48
|
+
export {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AE,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,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\ntype T = {\n bind: typeof bind;\n int8: typeof helpers.int8T;\n uint8: typeof helpers.uint8T;\n int16: typeof helpers.int16T;\n uint16: typeof helpers.uint16T;\n int32: typeof helpers.int32T;\n uint32: typeof helpers.uint32T;\n int64: typeof helpers.int64T;\n uint64: typeof helpers.uint64T;\n bigint64: typeof helpers.bigint64T;\n biguint64: typeof helpers.biguint64T;\n gtype: typeof helpers.gtypeT;\n float32: typeof helpers.float32T;\n float64: typeof helpers.float64T;\n boolean: typeof helpers.booleanT;\n void: typeof helpers.voidT;\n unichar: typeof helpers.unicharT;\n buffer: typeof helpers.bufferT;\n string: typeof helpers.stringT;\n object: typeof helpers.objectT;\n boxed: typeof helpers.boxedT;\n struct: typeof helpers.structT;\n fundamental: typeof helpers.fundamentalT;\n ref: typeof helpers.refT;\n hashTable: typeof helpers.hashTableT;\n enum: typeof helpers.enumT;\n flags: typeof helpers.flagsT;\n array: typeof helpers.arrayT;\n list: typeof helpers.listT;\n slist: typeof helpers.slistT;\n ptrArray: typeof helpers.ptrArrayT;\n gArray: typeof helpers.gArrayT;\n byteArray: typeof helpers.byteArrayT;\n sizedArray: typeof helpers.sizedArrayT;\n fixedArray: typeof helpers.fixedArrayT;\n callback: typeof helpers.callbackT;\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 callback: helpers.callbackT,\n fn,\n};\n\nexport { t };\n"]}
|
package/dist/tuple.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare const packTupleResult: (outs: unknown[], primary: unknown, hasPrimary: boolean) => unknown;
|
|
2
|
+
declare const splitTupleResult: (result: unknown, hasPrimary: boolean, outCount: number) => {
|
|
3
|
+
primary: unknown;
|
|
4
|
+
outValues: unknown[];
|
|
5
|
+
};
|
|
6
|
+
export { packTupleResult, splitTupleResult };
|
|
7
|
+
//# sourceMappingURL=tuple.d.ts.map
|
|
@@ -0,0 +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;AAEF,QAAA,MAAM,gBAAgB,GAClB,QAAQ,OAAO,EACf,YAAY,OAAO,EACnB,UAAU,MAAM,KACjB;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,OAAO,EAAE,CAAA;CAc1C,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,CAAC"}
|