@gtkx/runtime 1.6.0 → 2.0.0-beta.10

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.
Files changed (124) hide show
  1. package/README.md +47 -44
  2. package/dist/application-class.d.ts +1 -1
  3. package/dist/application-class.d.ts.map +1 -1
  4. package/dist/application-class.js +1 -2
  5. package/dist/application-class.js.map +1 -1
  6. package/dist/arg.d.ts +4 -1
  7. package/dist/arg.d.ts.map +1 -1
  8. package/dist/arg.js.map +1 -1
  9. package/dist/bind.d.ts.map +1 -1
  10. package/dist/bind.js +1 -9
  11. package/dist/bind.js.map +1 -1
  12. package/dist/callback.d.ts +6 -1
  13. package/dist/callback.d.ts.map +1 -1
  14. package/dist/callback.js +33 -21
  15. package/dist/callback.js.map +1 -1
  16. package/dist/closure.d.ts +3 -1
  17. package/dist/closure.d.ts.map +1 -1
  18. package/dist/closure.js +17 -6
  19. package/dist/closure.js.map +1 -1
  20. package/dist/descriptors.d.ts +24 -52
  21. package/dist/descriptors.d.ts.map +1 -1
  22. package/dist/descriptors.js +58 -28
  23. package/dist/descriptors.js.map +1 -1
  24. package/dist/fn.d.ts.map +1 -1
  25. package/dist/fn.js +23 -9
  26. package/dist/fn.js.map +1 -1
  27. package/dist/folded-lengths.d.ts +2 -1
  28. package/dist/folded-lengths.d.ts.map +1 -1
  29. package/dist/folded-lengths.js +17 -7
  30. package/dist/folded-lengths.js.map +1 -1
  31. package/dist/index.d.ts +3 -25
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +3 -25
  34. package/dist/index.js.map +1 -1
  35. package/dist/internal.d.ts +19 -2
  36. package/dist/internal.d.ts.map +1 -1
  37. package/dist/internal.js +15 -2
  38. package/dist/internal.js.map +1 -1
  39. package/dist/lifecycle.js +1 -1
  40. package/dist/lifecycle.js.map +1 -1
  41. package/dist/listeners.d.ts +3 -13
  42. package/dist/listeners.d.ts.map +1 -1
  43. package/dist/listeners.js +12 -12
  44. package/dist/listeners.js.map +1 -1
  45. package/dist/mixin.d.ts +5 -3
  46. package/dist/mixin.d.ts.map +1 -1
  47. package/dist/mixin.js +36 -9
  48. package/dist/mixin.js.map +1 -1
  49. package/dist/native-value.d.ts +9 -1
  50. package/dist/native-value.d.ts.map +1 -1
  51. package/dist/native-value.js +20 -3
  52. package/dist/native-value.js.map +1 -1
  53. package/dist/object.d.ts +14 -3
  54. package/dist/object.d.ts.map +1 -1
  55. package/dist/object.js +20 -27
  56. package/dist/object.js.map +1 -1
  57. package/dist/properties.d.ts +5 -3
  58. package/dist/properties.d.ts.map +1 -1
  59. package/dist/properties.js +67 -23
  60. package/dist/properties.js.map +1 -1
  61. package/dist/property-brand.d.ts +5 -0
  62. package/dist/property-brand.d.ts.map +1 -0
  63. package/dist/property-brand.js +5 -0
  64. package/dist/property-brand.js.map +1 -0
  65. package/dist/register-class.d.ts +142 -264
  66. package/dist/register-class.d.ts.map +1 -1
  67. package/dist/register-class.js +19 -37
  68. package/dist/register-class.js.map +1 -1
  69. package/dist/registry.d.ts +1 -1
  70. package/dist/registry.d.ts.map +1 -1
  71. package/dist/registry.js +4 -4
  72. package/dist/registry.js.map +1 -1
  73. package/dist/signal-brand.d.ts +12 -0
  74. package/dist/signal-brand.d.ts.map +1 -0
  75. package/dist/signal-brand.js +6 -0
  76. package/dist/signal-brand.js.map +1 -0
  77. package/dist/signal.d.ts +39 -2
  78. package/dist/signal.d.ts.map +1 -1
  79. package/dist/signal.js +84 -27
  80. package/dist/signal.js.map +1 -1
  81. package/dist/t.d.ts +5 -21
  82. package/dist/t.d.ts.map +1 -1
  83. package/dist/t.js +1 -5
  84. package/dist/t.js.map +1 -1
  85. package/dist/type.d.ts.map +1 -1
  86. package/dist/type.js +8 -2
  87. package/dist/type.js.map +1 -1
  88. package/dist/value.d.ts +2 -1
  89. package/dist/value.d.ts.map +1 -1
  90. package/dist/value.js +35 -8
  91. package/dist/value.js.map +1 -1
  92. package/dist/variant.d.ts +2 -6
  93. package/dist/variant.d.ts.map +1 -1
  94. package/dist/variant.js.map +1 -1
  95. package/dist/vfunc-call.d.ts.map +1 -1
  96. package/dist/vfunc-call.js +2 -11
  97. package/dist/vfunc-call.js.map +1 -1
  98. package/package.json +12 -6
  99. package/src/application-class.ts +2 -2
  100. package/src/arg.ts +4 -1
  101. package/src/bind.ts +1 -12
  102. package/src/callback.ts +53 -29
  103. package/src/closure.ts +31 -6
  104. package/src/descriptors.ts +102 -59
  105. package/src/fn.ts +31 -10
  106. package/src/folded-lengths.ts +23 -10
  107. package/src/index.ts +4 -26
  108. package/src/internal.ts +44 -2
  109. package/src/lifecycle.ts +1 -1
  110. package/src/listeners.ts +21 -26
  111. package/src/mixin.ts +55 -9
  112. package/src/native-value.ts +24 -3
  113. package/src/object.ts +57 -7
  114. package/src/properties.ts +90 -26
  115. package/src/property-brand.ts +5 -0
  116. package/src/register-class.ts +338 -341
  117. package/src/registry.ts +4 -4
  118. package/src/signal-brand.ts +29 -0
  119. package/src/signal.ts +185 -39
  120. package/src/t.ts +5 -21
  121. package/src/type.ts +10 -2
  122. package/src/value.ts +49 -6
  123. package/src/variant.ts +2 -6
  124. package/src/vfunc-call.ts +3 -16
package/README.md CHANGED
@@ -5,15 +5,15 @@
5
5
  <h1 align="center">GTKX</h1>
6
6
 
7
7
  <p align="center">
8
- The React framework for Linux, built on GTK.<br />
9
- Write native GTK4 desktop applications with React and TypeScript.
10
- Real GTK widgets, the GNOME stack, and standard web tooling.
8
+ The React framework for Linux.<br />
9
+ Write native GNOME applications with React and TypeScript.
10
+ Real Adwaita and GTK4 widgets with standard web tooling.
11
11
  </p>
12
12
 
13
13
  <p align="center">
14
14
  <a href="https://www.npmjs.com/package/create-gtkx"><img src="https://img.shields.io/npm/v/create-gtkx?color=cb3837&logo=npm&label=create-gtkx" alt="npm version" /></a>
15
15
  <a href="https://www.npmjs.com/package/create-gtkx"><img src="https://img.shields.io/npm/dm/create-gtkx?color=cb3837&logo=npm&label=downloads" alt="npm downloads" /></a>
16
- <img src="https://img.shields.io/badge/node-%E2%89%A524-339933?logo=node.js&logoColor=white" alt="Node >= 24" />
16
+ <img src="https://img.shields.io/badge/node-%E2%89%A526.7-339933?logo=node.js&logoColor=white" alt="Node >= 26.7" />
17
17
  <a href="https://github.com/gtkx-org/gtkx/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MPL--2.0-blue.svg" alt="License: MPL-2.0" /></a>
18
18
  <a href="https://github.com/gtkx-org/gtkx/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/gtkx-org/gtkx/ci.yml?branch=main&logo=github&label=CI" alt="CI status" /></a>
19
19
  <img src="https://img.shields.io/badge/TypeScript-strict-3178c6?logo=typescript&logoColor=white" alt="TypeScript" />
@@ -38,11 +38,12 @@
38
38
 
39
39
  ## Demo
40
40
 
41
- The intrinsic elements in this snippet render GTK4 widgets, and ordinary React hooks and events drive them:
41
+ This app starts with an Adwaita application shell, renders native GTK4 widgets inside it, and uses ordinary React hooks and events:
42
42
 
43
43
  ```tsx
44
44
  import * as Gtk from "@gtkx/gi/gtk";
45
- import { GtkApplication, GtkApplicationWindow, GtkBox, GtkButton, GtkLabel } from "@gtkx/jsx/gtk";
45
+ import { AdwApplication, AdwApplicationWindow, AdwHeaderBar, AdwToolbarView } from "@gtkx/jsx/adw";
46
+ import { GtkBox, GtkButton, GtkLabel } from "@gtkx/jsx/gtk";
46
47
  import { createRoot, quit } from "@gtkx/react";
47
48
  import { useState } from "react";
48
49
 
@@ -50,38 +51,40 @@ const Counter = () => {
50
51
  const [count, setCount] = useState(0);
51
52
 
52
53
  return (
53
- <GtkApplicationWindow
54
+ <AdwApplicationWindow
54
55
  title="Hello GTKX"
55
56
  defaultWidth={400}
56
57
  defaultHeight={300}
57
58
  onCloseRequest={quit}
58
59
  >
59
- <GtkBox
60
- orientation={Gtk.Orientation.VERTICAL}
61
- spacing={20}
62
- marginTop={40}
63
- marginBottom={40}
64
- marginStart={40}
65
- marginEnd={40}
66
- valign={Gtk.Align.CENTER}
67
- halign={Gtk.Align.CENTER}
68
- >
69
- <GtkLabel cssClasses={["title-1"]}>Welcome to GTKX!</GtkLabel>
70
- <GtkLabel cssClasses={["title-2"]}>{`Count: ${count}`}</GtkLabel>
71
- <GtkButton
72
- label="Increment"
73
- onClicked={() => setCount((c) => c + 1)}
74
- cssClasses={["suggested-action", "pill"]}
75
- />
76
- </GtkBox>
77
- </GtkApplicationWindow>
60
+ <AdwToolbarView topBar={<AdwHeaderBar />}>
61
+ <GtkBox
62
+ orientation={Gtk.Orientation.VERTICAL}
63
+ spacing={20}
64
+ marginTop={40}
65
+ marginBottom={40}
66
+ marginStart={40}
67
+ marginEnd={40}
68
+ valign={Gtk.Align.CENTER}
69
+ halign={Gtk.Align.CENTER}
70
+ >
71
+ <GtkLabel cssClasses={["title-1"]}>Welcome to GTKX!</GtkLabel>
72
+ <GtkLabel cssClasses={["title-2"]}>{`Count: ${String(count)}`}</GtkLabel>
73
+ <GtkButton
74
+ label="Increment"
75
+ onClicked={() => setCount((c) => c + 1)}
76
+ cssClasses={["suggested-action", "pill"]}
77
+ />
78
+ </GtkBox>
79
+ </AdwToolbarView>
80
+ </AdwApplicationWindow>
78
81
  );
79
82
  };
80
83
 
81
84
  const App = () => (
82
- <GtkApplication>
85
+ <AdwApplication>
83
86
  <Counter />
84
- </GtkApplication>
87
+ </AdwApplication>
85
88
  );
86
89
 
87
90
  createRoot().render(<App />);
@@ -91,9 +94,9 @@ This is the [`hello-world`](https://github.com/gtkx-org/gtkx/tree/main/examples/
91
94
 
92
95
  ## Why GTKX
93
96
 
94
- ### A declarative layer for the GNOME stack
97
+ ### Adwaita-first application development
95
98
 
96
- GTK4 is mature, and GtkBuilder XML can lay out a static interface, but nothing re-renders that interface when your application state changes, and nothing hot-reloads it as you work. GTKX adds that missing layer, and the tooling around it, on top of the stack you already know:
99
+ GTKX uses Adwaita as the foundation for applications, windows, navigation, dialogs, and adaptive layouts, with the complete GTK4 toolkit underneath. It adds a declarative React layer and an integrated TypeScript toolchain to the GNOME platform:
97
100
 
98
101
  - a React reconciler that exposes every GObject as a JSX element,
99
102
  - a CLI for scaffolding, development, and production builds,
@@ -102,29 +105,29 @@ GTK4 is mature, and GtkBuilder XML can lay out a static interface, but nothing r
102
105
  - a Testing Library-style API for querying and driving your widgets in tests,
103
106
  - and a Model Context Protocol (MCP) server that exposes your live app to AI agents.
104
107
 
105
- ### The full GNOME API surface
108
+ ### Native GNOME widgets, without a compatibility layer
106
109
 
107
- React Native and similar frameworks hide the native toolkit so one API can run everywhere. GTKX exposes it: GTK4, Adwaita, and any other GObject-Introspection library on your system. Linux-only by design.
110
+ React Native and similar frameworks hide the native toolkit so one API can run everywhere. GTKX renders real Adwaita and GTK4 widgets and exposes any other GObject-Introspection library on your system. It is GNOME-native and Linux-only by design.
108
111
 
109
112
  ### Why Node.js, and why generated bindings
110
113
 
111
114
  GTKX runs on Node.js, which puts native modules, the npm ecosystem, and the tooling built for Node.js APIs within reach. GJS is GNOME's own runtime, built on SpiderMonkey rather than V8; node-gtk runs on Node.js but is lightly maintained, on the older nan/V8 ABI rather than N-API, and still centered on GTK3. The [Why GTKX guide](https://gtkx.dev/guide/why-gtkx) covers what running on Node.js means day to day.
112
115
 
113
- GTKX generates the TypeScript types and the native FFI calls from the same GObject-Introspection data, so the types cannot drift from the calls they back. Codegen covers the whole GTK4 and Adwaita surface.
116
+ GTKX generates the TypeScript types and native FFI calls from the same GObject-Introspection data, so the types cannot drift from the calls they back. `Adw-1` is the sole default GIR root; its GIR include pulls in `Gtk-4.0`, so codegen covers both complete API surfaces. Neither belongs in a GTKX 2 `libraries` list.
114
117
 
115
- At runtime, the native Rust core calls straight into the system GTK4, Adwaita, and GLib libraries through libffi, without loading libgirepository at all.
118
+ At runtime, the native Rust core calls straight into the system Adwaita, GTK4, and GLib libraries through libffi, without loading libgirepository at all.
116
119
 
117
120
  ## Quick start
118
121
 
119
- GTKX is Linux-only and needs Node.js 24 or later. See [Requirements](#requirements).
122
+ GTKX is Linux-only and needs Node.js 26.7 or later. See [Requirements](#requirements).
120
123
 
121
124
  Scaffold a new app with the `create-gtkx` initializer:
122
125
 
123
126
  ```sh
124
- npm create gtkx
127
+ npm create gtkx@beta
125
128
  ```
126
129
 
127
- The same command works with other package managers: `pnpm create gtkx` or `yarn create gtkx`.
130
+ The same command works with other package managers: `pnpm create gtkx@beta` or `yarn create gtkx@beta`.
128
131
 
129
132
  Then run your new app:
130
133
 
@@ -145,8 +148,8 @@ The documentation at **[gtkx.dev](https://gtkx.dev)** includes a step-by-step tu
145
148
 
146
149
  GTKX is Linux-only. You need:
147
150
 
148
- - Linux with the GTK4 (4.20 or later) and GLib development libraries, plus Adwaita (1.8 or later) once your project binds `Adw-1`
149
- - Node.js 24 or later
151
+ - Linux with the Adwaita (1.8 or later), GTK4 (4.20 or later), and GLib development libraries
152
+ - Node.js 26.7 or later
150
153
 
151
154
  The `@gtkx/native` addon ships prebuilt for x64 and arm64 glibc Linux; other targets need to build it from the GTKX repository, which requires a Rust toolchain.
152
155
 
@@ -154,10 +157,10 @@ The `@gtkx/native` addon ships prebuilt for x64 and arm64 glibc Linux; other tar
154
157
 
155
158
  Explore the [example apps](https://github.com/gtkx-org/gtkx/tree/main/examples):
156
159
 
157
- - [`hello-world`](https://github.com/gtkx-org/gtkx/tree/main/examples/hello-world): the counter above.
158
- - [`gtk-demo`](https://github.com/gtkx-org/gtkx/tree/main/examples/gtk-demo): a React port of the official GTK4 widget showcase, covering lists, dialogs, gestures, CSS, and OpenGL.
159
- - [`browser`](https://github.com/gtkx-org/gtkx/tree/main/examples/browser): a WebKitWebView-based web browser.
160
- - [`animations`](https://github.com/gtkx-org/gtkx/tree/main/examples/animations): a tour of `@gtkx/animated`, React Spring animations driven by the GTK frame clock.
160
+ - [`hello-world`](https://github.com/gtkx-org/gtkx/tree/main/examples/hello-world): the Adwaita counter above.
161
+ - [`gtk-demo`](https://github.com/gtkx-org/gtkx/tree/main/examples/gtk-demo): the official GTK4 widget showcase in an Adwaita application shell, covering lists, dialogs, gestures, CSS, and OpenGL.
162
+ - [`browser`](https://github.com/gtkx-org/gtkx/tree/main/examples/browser): an Adwaita browser built around `WebKitWebView`.
163
+ - [`animations`](https://github.com/gtkx-org/gtkx/tree/main/examples/animations): an Adwaita showcase for `@gtkx/animated`, with React Spring animations driven by the GTK frame clock.
161
164
  - [`navigation`](https://github.com/gtkx-org/gtkx/tree/main/examples/navigation): a tour of `@gtkx/navigation`, React Navigation's stack, tab, and drawer navigators rendered with libadwaita.
162
165
  - [`tutorial`](https://github.com/gtkx-org/gtkx/tree/main/examples/tutorial): the Tasks app the documentation builds.
163
166
 
@@ -167,7 +170,7 @@ GTKX is stable and ready for production use.
167
170
 
168
171
  ## Contributing
169
172
 
170
- Contributions are welcome. See [CONTRIBUTING.md](https://github.com/gtkx-org/gtkx/blob/main/CONTRIBUTING.md), the [Code of Conduct](https://github.com/gtkx-org/gtkx/blob/main/CODE_OF_CONDUCT.md), and the [security policy](https://github.com/gtkx-org/gtkx/blob/main/SECURITY.md). Building the repo needs Node.js 24 or later, pnpm, and a Rust toolchain.
173
+ Contributions are welcome. See [CONTRIBUTING.md](https://github.com/gtkx-org/gtkx/blob/main/CONTRIBUTING.md), the [Code of Conduct](https://github.com/gtkx-org/gtkx/blob/main/CODE_OF_CONDUCT.md), and the [security policy](https://github.com/gtkx-org/gtkx/blob/main/SECURITY.md). Building the repo needs Node.js 26.7 or later, pnpm, and a Rust toolchain.
171
174
 
172
175
  ## License
173
176
 
@@ -1,4 +1,4 @@
1
- import { type AnyClass } from "@gtkx/utils";
1
+ import type { AnyClass } from "@gtkx/utils";
2
2
  type CommandLineResult = [boolean, string[], number];
3
3
  /**
4
4
  * The GIO application surface {@link createApplication} builds on, which `Gio.Application` and
@@ -1 +1 @@
1
- {"version":3,"file":"application-class.d.ts","sourceRoot":"","sources":["../src/application-class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAe,MAAM,aAAa,CAAC;AAOzD,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BAAsB,GAAG;IAC1B,kGAAkG;IAClG,IAAI,IAAI,IAAI,CAAC;CAChB,CAAC;AAEF,KAAK,2BAA2B,GAAG;IAC/B,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,iBAAiB,CAAC;CAC1D,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACvB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;CAC/B,CAAC;AAEF,8EAA8E;AAC9E,KAAK,gBAAgB,CAAC,CAAC,SAAS,sBAAsB,EAAE,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AA2CjG,QAAA,MAAM,oBAAoB,GAAI,aAAa,MAAM,KAAG,WAAW,IAAI,2BAQlE,CAAC;AAEF,QAAA,MAAM,kBAAkB,GAAI,aAAa,mBAAmB,KAAG,IAY9D,CAAC;AAKF;;;;;;;;;;;;;GAaG;AACH,QAAA,MAAM,iBAAiB,GAAI,CAAC,SAAS,sBAAsB,EAAE,CAAC,EAAE,MAAM,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,KAAG,CAKxG,CAAC;AAEF,OAAO,EACH,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,GACnC,CAAC"}
@@ -1,4 +1,3 @@
1
- import { getOrInsert } from "@gtkx/utils";
2
1
  import { releaseDefaultApplication } from "./default-application.js";
3
2
  import { registerClass } from "./register-class.js";
4
3
  import { getClassType } from "./registry.js";
@@ -54,7 +53,7 @@ const shutDownThroughRun = (application) => {
54
53
  shuttingDownApplications.delete(application);
55
54
  }
56
55
  };
57
- const deriveApplicationClass = (base) => getOrInsert(derivedClasses, base, () => buildApplicationClass(base));
56
+ const deriveApplicationClass = (base) => derivedClasses.getOrInsertComputed(base, () => buildApplicationClass(base));
58
57
  /**
59
58
  * Constructs an application GTKX can shut down. GLib parses an application's command line at most
60
59
  * once per instance and crashes on a second parse, so {@link runApplication} and
@@ -1 +1 @@
1
- {"version":3,"file":"application-class.js","sourceRoot":"","sources":["../src/application-class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAwB7C,MAAM,cAAc,GAAgC,IAAI,OAAO,EAAE,CAAC;AAClE,MAAM,yBAAyB,GAAkB,IAAI,GAAG,EAAE,CAAC;AAC3D,MAAM,gBAAgB,GAAoB,IAAI,OAAO,EAAE,CAAC;AACxD,MAAM,wBAAwB,GAAoB,IAAI,OAAO,EAAE,CAAC;AAEhE,MAAM,eAAe,GAAG,CAAC,IAAc,EAAU,EAAE,CAAC,OAAO,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;AAEvG,MAAM,qBAAqB,GAAG,CAAC,IAAsC,EAAoC,EAAE;IACvG,MAAM,kBAAmB,SAAQ,IAAI;QACjC,mBAAmB,CAAC,IAAc;YAC9B,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC;QAES,qBAAqB,CAAC,IAAc;YAC1C,IAAI,wBAAwB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrC,IAAI,CAAC,IAAI,EAAE,CAAC;gBAEZ,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YAC3B,CAAC;YAED,OAAO,UAAU,CAAC,kB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,CAAC,cAAc,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAgB,CAAC;AAExF;;;;;;;;;;;;;GAaG;AACH,MAAM,iBAAiB,GAAG,CAAsC,IAA4B,EAAE,KAAQ,EAAK,EAAE;IACzG,MAAM,WAAW,GAAG,KAAK,sBAAsB,CAAC,IAAI,CAAyB,EAAC,KAAK,CAAC,CAAC;IACrF,yBAAyB,CAAC,WAAW,CAAC,CAAC;IAEvC,OAAO,WAAW,CAAC;AACvB,CAAC,CAAC;AAEF,OAAO,EACH,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,GAIrB,CAAC","sourcesContent":["import { type AnyClass, getOrInsert } from \"@gtkx/utils\";\nimport { releaseDefaultApplication } from \"./default-application.js\";\nimport { registerClass } from \"./register-class.js\";\nimport { getClassType } from \"./registry.js\";\nimport { typeName } from \"./type.js\";\nimport { callParent } from \"./vfunc-call.js\";\n\ntype CommandLineResult = [boolean, string[], number];\n\n/**\n * The GIO application surface {@link createApplication} builds on, which `Gio.Application` and\n * every subclass of it satisfies structurally.\n */\ntype CommandLineApplication = {\n /** Marks the application as quitting, so GLib's own `run` returns without driving a main loop. */\n quit(): void;\n};\n\ntype LocalCommandLineApplication = {\n runLocalCommandLine(argv: string[]): CommandLineResult;\n};\n\ntype ShutdownApplication = {\n run(argv: string[]): number;\n};\n\n/** An application class together with the construct properties it accepts. */\ntype ApplicationClass<T extends CommandLineApplication, P> = AnyClass<T> & (new (props: P) => T);\n\nconst derivedClasses: WeakMap<AnyClass, AnyClass> = new WeakMap();\nconst derivedApplicationClasses: Set<AnyClass> = new Set();\nconst quitApplications: WeakSet<object> = new WeakSet();\nconst shuttingDownApplications: WeakSet<object> = new WeakSet();\n\nconst derivedTypeName = (base: AnyClass): string => `Gtkx${typeName(getClassType(base)) ?? base.name}`;\n\nconst buildApplicationClass = (base: AnyClass<CommandLineApplication>): AnyClass<CommandLineApplication> => {\n class DerivedApplication extends base {\n runLocalCommandLine(argv: string[]): CommandLineResult {\n return this.vfuncLocalCommandLine(argv);\n }\n\n protected vfuncLocalCommandLine(argv: string[]): CommandLineResult {\n if (shuttingDownApplications.has(this)) {\n this.quit();\n\n return [true, argv, 0];\n }\n\n return callParent(DerivedApplication, \"vfuncLocalCommandLine\", this, argv) as CommandLineResult;\n }\n\n protected vfuncNameLost(): boolean {\n quitApplications.add(this);\n\n return callParent(DerivedApplication, \"vfuncNameLost\", this) as boolean;\n }\n\n override quit(): void {\n quitApplications.add(this);\n super.quit();\n }\n }\n\n const derived = registerClass(DerivedApplication, { typeName: derivedTypeName(base) });\n derivedApplicationClasses.add(derived);\n\n return derived;\n};\n\nconst isDerivedApplication = (application: object): application is LocalCommandLineApplication => {\n for (const derived of derivedApplicationClasses) {\n if (application instanceof derived) {\n return true;\n }\n }\n\n return false;\n};\n\nconst shutDownThroughRun = (application: ShutdownApplication): void => {\n if (!isDerivedApplication(application) || quitApplications.has(application)) {\n return;\n }\n\n shuttingDownApplications.add(application);\n\n try {\n application.run([]);\n } finally {\n shuttingDownApplications.delete(application);\n }\n};\n\nconst deriveApplicationClass = <T extends CommandLineApplication>(base: AnyClass<T>): AnyClass<T> =>\n getOrInsert(derivedClasses, base, () => buildApplicationClass(base)) as AnyClass<T>;\n\n/**\n * Constructs an application GTKX can shut down. GLib parses an application's command line at most\n * once per instance and crashes on a second parse, so {@link runApplication} and\n * {@link quitApplication} only accept an application built here.\n *\n * Whatever `g_application_constructed` assigned to the process-wide default is handed straight back,\n * so merely building an application never makes it what `Gio.Application.getDefault()` returns.\n * {@link runApplication} is the only place that claims that default, which keeps it pointing at an\n * application GTKX has actually started rather than at one that is still unregistered.\n *\n * @param base The application class to construct, such as `Gtk.Application`.\n * @param props Construct properties, passed through unchanged.\n * @returns An instance of a class derived from `base`, registered once per base class as its own GType.\n */\nconst createApplication = <T extends CommandLineApplication, P>(base: ApplicationClass<T, P>, props: P): T => {\n const application = new (deriveApplicationClass(base) as new (props: P) => T)(props);\n releaseDefaultApplication(application);\n\n return application;\n};\n\nexport {\n createApplication,\n isDerivedApplication,\n shutDownThroughRun,\n type ApplicationClass,\n type CommandLineApplication,\n type LocalCommandLineApplication,\n};\n"]}
1
+ {"version":3,"file":"application-class.js","sourceRoot":"","sources":["../src/application-class.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAwB7C,MAAM,cAAc,GAAgC,IAAI,OAAO,EAAE,CAAC;AAClE,MAAM,yBAAyB,GAAkB,IAAI,GAAG,EAAE,CAAC;AAC3D,MAAM,gBAAgB,GAAoB,IAAI,OAAO,EAAE,CAAC;AACxD,MAAM,wBAAwB,GAAoB,IAAI,OAAO,EAAE,CAAC;AAEhE,MAAM,eAAe,GAAG,CAAC,IAAc,EAAU,EAAE,CAAC,OAAO,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;AAEvG,MAAM,qBAAqB,GAAG,CAAC,IAAsC,EAAoC,EAAE;IACvG,MAAM,kBAAmB,SAAQ,IAAI;QACjC,mBAAmB,CAAC,IAAc;YAC9B,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC;QAES,qBAAqB,CAAC,IAAc;YAC1C,IAAI,wBAAwB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrC,IAAI,CAAC,IAAI,EAAE,CAAC;gBAEZ,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YAC3B,CAAC;YAED,OAAO,UAAU,CAAC,kBAAkB,EAAE,uBAAuB,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,IAAI,EAAE,GAAG,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAgB,CAAC;AAE/F;;;;;;;;;;;;;GAaG;AACH,MAAM,iBAAiB,GAAG,CAAsC,IAA4B,EAAE,KAAQ,EAAK,EAAE;IACzG,MAAM,WAAW,GAAG,KAAK,sBAAsB,CAAC,IAAI,CAAyB,EAAC,KAAK,CAAC,CAAC;IACrF,yBAAyB,CAAC,WAAW,CAAC,CAAC;IAEvC,OAAO,WAAW,CAAC;AACvB,CAAC,CAAC;AAEF,OAAO,EACH,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,GAIrB,CAAC","sourcesContent":["import type { AnyClass } from \"@gtkx/utils\";\nimport { releaseDefaultApplication } from \"./default-application.js\";\nimport { registerClass } from \"./register-class.js\";\nimport { getClassType } from \"./registry.js\";\nimport { typeName } from \"./type.js\";\nimport { callParent } from \"./vfunc-call.js\";\n\ntype CommandLineResult = [boolean, string[], number];\n\n/**\n * The GIO application surface {@link createApplication} builds on, which `Gio.Application` and\n * every subclass of it satisfies structurally.\n */\ntype CommandLineApplication = {\n /** Marks the application as quitting, so GLib's own `run` returns without driving a main loop. */\n quit(): void;\n};\n\ntype LocalCommandLineApplication = {\n runLocalCommandLine(argv: string[]): CommandLineResult;\n};\n\ntype ShutdownApplication = {\n run(argv: string[]): number;\n};\n\n/** An application class together with the construct properties it accepts. */\ntype ApplicationClass<T extends CommandLineApplication, P> = AnyClass<T> & (new (props: P) => T);\n\nconst derivedClasses: WeakMap<AnyClass, AnyClass> = new WeakMap();\nconst derivedApplicationClasses: Set<AnyClass> = new Set();\nconst quitApplications: WeakSet<object> = new WeakSet();\nconst shuttingDownApplications: WeakSet<object> = new WeakSet();\n\nconst derivedTypeName = (base: AnyClass): string => `Gtkx${typeName(getClassType(base)) ?? base.name}`;\n\nconst buildApplicationClass = (base: AnyClass<CommandLineApplication>): AnyClass<CommandLineApplication> => {\n class DerivedApplication extends base {\n runLocalCommandLine(argv: string[]): CommandLineResult {\n return this.vfuncLocalCommandLine(argv);\n }\n\n protected vfuncLocalCommandLine(argv: string[]): CommandLineResult {\n if (shuttingDownApplications.has(this)) {\n this.quit();\n\n return [true, argv, 0];\n }\n\n return callParent(DerivedApplication, \"vfuncLocalCommandLine\", this, argv) as CommandLineResult;\n }\n\n protected vfuncNameLost(): boolean {\n quitApplications.add(this);\n\n return callParent(DerivedApplication, \"vfuncNameLost\", this) as boolean;\n }\n\n override quit(): void {\n quitApplications.add(this);\n super.quit();\n }\n }\n\n const derived = registerClass(DerivedApplication, { typeName: derivedTypeName(base) });\n derivedApplicationClasses.add(derived);\n\n return derived;\n};\n\nconst isDerivedApplication = (application: object): application is LocalCommandLineApplication => {\n for (const derived of derivedApplicationClasses) {\n if (application instanceof derived) {\n return true;\n }\n }\n\n return false;\n};\n\nconst shutDownThroughRun = (application: ShutdownApplication): void => {\n if (!isDerivedApplication(application) || quitApplications.has(application)) {\n return;\n }\n\n shuttingDownApplications.add(application);\n\n try {\n application.run([]);\n } finally {\n shuttingDownApplications.delete(application);\n }\n};\n\nconst deriveApplicationClass = <T extends CommandLineApplication>(base: AnyClass<T>): AnyClass<T> =>\n derivedClasses.getOrInsertComputed(base, () => buildApplicationClass(base)) as AnyClass<T>;\n\n/**\n * Constructs an application GTKX can shut down. GLib parses an application's command line at most\n * once per instance and crashes on a second parse, so {@link runApplication} and\n * {@link quitApplication} only accept an application built here.\n *\n * Whatever `g_application_constructed` assigned to the process-wide default is handed straight back,\n * so merely building an application never makes it what `Gio.Application.getDefault()` returns.\n * {@link runApplication} is the only place that claims that default, which keeps it pointing at an\n * application GTKX has actually started rather than at one that is still unregistered.\n *\n * @param base The application class to construct, such as `Gtk.Application`.\n * @param props Construct properties, passed through unchanged.\n * @returns An instance of a class derived from `base`, registered once per base class as its own GType.\n */\nconst createApplication = <T extends CommandLineApplication, P>(base: ApplicationClass<T, P>, props: P): T => {\n const application = new (deriveApplicationClass(base) as new (props: P) => T)(props);\n releaseDefaultApplication(application);\n\n return application;\n};\n\nexport {\n createApplication,\n isDerivedApplication,\n shutDownThroughRun,\n type ApplicationClass,\n type CommandLineApplication,\n type LocalCommandLineApplication,\n};\n"]}
package/dist/arg.d.ts CHANGED
@@ -11,7 +11,10 @@ type Arg = {
11
11
  isConsumed?: boolean;
12
12
  /** When true, the argument is a `GValue` the callee fills in, packed into the result as what it holds. */
13
13
  isUnpacked?: boolean;
14
- /** When true, the caller must provide the argument: `undefined` is rejected instead of reaching C as `NULL`. */
14
+ /**
15
+ * When true, the caller must provide the argument: `undefined` is rejected instead of reaching
16
+ * C as `NULL`, and so is `null` for a type that reaches C as a pointer.
17
+ */
15
18
  isRequired?: boolean;
16
19
  };
17
20
  declare const isOutputArg: (arg: Arg) => boolean;
package/dist/arg.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"arg.d.ts","sourceRoot":"","sources":["../src/arg.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,iGAAiG;AACjG,KAAK,GAAG,GAAG;IACP,kGAAkG;IAClG,IAAI,EAAE,UAAU,CAAC;IACjB,2EAA2E;IAC3E,SAAS,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC;IAC5B,wGAAwG;IACxG,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,wFAAwF;IACxF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,0GAA0G;IAC1G,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gHAAgH;IAChH,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,QAAA,MAAM,WAAW,GAAI,KAAK,GAAG,KAAG,OAAsC,CAAC;AACvE,QAAA,MAAM,UAAU,GAAI,KAAK,GAAG,KAAG,OAAoC,CAAC;AACpE,QAAA,MAAM,oBAAoB,GAAI,KAAK,GAAG,KAAG,OAAyC,CAAC;AACnF,QAAA,MAAM,aAAa,GAAI,KAAK,GAAG,KAAG,OAAkC,CA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C"}
package/dist/arg.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"arg.js","sourceRoot":"","sources":["../src/arg.ts"],"names":[],"mappings":"AAkBA,MAAM,WAAW,GAAG,CAAC,GAAQ,EAAW,EAAE,CAAC,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC;AACvE,MAAM,UAAU,GAAG,CAAC,GAAQ,EAAW,EAAE,CAAC,GAAG,CAAC,SAAS,KAAK,OAAO,CAAC;AACpE,MAAM,oBAAoB,GAAG,CAAC,GAAQ,EAAW,EAAE,CAAC,GAAG,CAAC,iBAAiB,KAAK,IAAI,CAAC;AACnF,MAAM,aAAa,GAAG,CAAC,GAAQ,EAAW,EAAE,CAAC,GAAG,CAAC,UAAU,KAAK,IAAI,CAAC;AACrE,MAAM,QAAQ,GAAG,CAAC,GAAQ,EAAW,EAAE,CAAC,GAAG,CAAC,SAAS,KAAK,SAAS,IAAI,GAAG,CAAC,iBAAiB,KAAK,IAAI,CAAC;AACtG,MAAM,gBAAgB,GAAG,CAAC,GAAQ,EAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;AAElF,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,oBAAoB,EAAE,QAAQ,EAAE,aAAa,EAAE,gBAAgB,EAAY,CAAC","sourcesContent":["import type { Descriptor } from \"@gtkx/native\";\n\n/** How one argument of a native call or signal emission is marshalled and which way it flows. */\ntype Arg = {\n /** Descriptor the value is marshalled with, wrapped in a pointer to it for an output argument. */\n type: Descriptor;\n /** Direction of an output argument, omitted for a plain input argument. */\n direction?: \"out\" | \"inout\";\n /** When true, the caller supplies the storage the callee writes into, rather than a pointer to fill. */\n isCallerAllocated?: boolean;\n /** When true, the argument is consumed internally and left out of the packed result. */\n isConsumed?: boolean;\n /** When true, the argument is a `GValue` the callee fills in, packed into the result as what it holds. */\n isUnpacked?: boolean;\n /** When true, the caller must provide the argument: `undefined` is rejected instead of reaching C as `NULL`. */\n isRequired?: boolean;\n};\n\nconst isOutputArg = (arg: Arg): boolean => arg.direction !== undefined;\nconst isInoutArg = (arg: Arg): boolean => arg.direction === \"inout\";\nconst isCallerAllocatedArg = (arg: Arg): boolean => arg.isCallerAllocated === true;\nconst isUnpackedArg = (arg: Arg): boolean => arg.isUnpacked === true;\nconst isRefArg = (arg: Arg): boolean => arg.direction !== undefined && arg.isCallerAllocated !== true;\nconst requiresInputArg = (arg: Arg): boolean => !isRefArg(arg) || isInoutArg(arg);\n\nexport { isOutputArg, isInoutArg, isCallerAllocatedArg, isRefArg, isUnpackedArg, requiresInputArg, type Arg };\n"]}
1
+ {"version":3,"file":"arg.js","sourceRoot":"","sources":["../src/arg.ts"],"names":[],"mappings":"AAqBA,MAAM,WAAW,GAAG,CAAC,GAAQ,EAAW,EAAE,CAAC,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC;AACvE,MAAM,UAAU,GAAG,CAAC,GAAQ,EAAW,EAAE,CAAC,GAAG,CAAC,SAAS,KAAK,OAAO,CAAC;AACpE,MAAM,oBAAoB,GAAG,CAAC,GAAQ,EAAW,EAAE,CAAC,GAAG,CAAC,iBAAiB,KAAK,IAAI,CAAC;AACnF,MAAM,aAAa,GAAG,CAAC,GAAQ,EAAW,EAAE,CAAC,GAAG,CAAC,UAAU,KAAK,IAAI,CAAC;AACrE,MAAM,QAAQ,GAAG,CAAC,GAAQ,EAAW,EAAE,CAAC,GAAG,CAAC,SAAS,KAAK,SAAS,IAAI,GAAG,CAAC,iBAAiB,KAAK,IAAI,CAAC;AACtG,MAAM,gBAAgB,GAAG,CAAC,GAAQ,EAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;AAElF,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,oBAAoB,EAAE,QAAQ,EAAE,aAAa,EAAE,gBAAgB,EAAY,CAAC","sourcesContent":["import type { Descriptor } from \"@gtkx/native\";\n\n/** How one argument of a native call or signal emission is marshalled and which way it flows. */\ntype Arg = {\n /** Descriptor the value is marshalled with, wrapped in a pointer to it for an output argument. */\n type: Descriptor;\n /** Direction of an output argument, omitted for a plain input argument. */\n direction?: \"out\" | \"inout\";\n /** When true, the caller supplies the storage the callee writes into, rather than a pointer to fill. */\n isCallerAllocated?: boolean;\n /** When true, the argument is consumed internally and left out of the packed result. */\n isConsumed?: boolean;\n /** When true, the argument is a `GValue` the callee fills in, packed into the result as what it holds. */\n isUnpacked?: boolean;\n /**\n * When true, the caller must provide the argument: `undefined` is rejected instead of reaching\n * C as `NULL`, and so is `null` for a type that reaches C as a pointer.\n */\n isRequired?: boolean;\n};\n\nconst isOutputArg = (arg: Arg): boolean => arg.direction !== undefined;\nconst isInoutArg = (arg: Arg): boolean => arg.direction === \"inout\";\nconst isCallerAllocatedArg = (arg: Arg): boolean => arg.isCallerAllocated === true;\nconst isUnpackedArg = (arg: Arg): boolean => arg.isUnpacked === true;\nconst isRefArg = (arg: Arg): boolean => arg.direction !== undefined && arg.isCallerAllocated !== true;\nconst requiresInputArg = (arg: Arg): boolean => !isRefArg(arg) || isInoutArg(arg);\n\nexport { isOutputArg, isInoutArg, isCallerAllocatedArg, isRefArg, isUnpackedArg, requiresInputArg, type Arg };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"bind.d.ts","sourceRoot":"","sources":["../src/bind.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,UAAU,EAAsB,MAAM,cAAc,CAAC;AAEzE;;;;;;;;;;GAUG;AACH,iBAAS,IAAI,CACT,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,UAAU,EAAE,EAC5B,gBAAgB,EAAE,UAAU,GAC7B,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,KAAK,OAAO,CAInC;AAED,iBAAS,eAAe,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,IAAI,CAAC,KAAK,UAAU,CAAC,OAAO,IAAI,CAAC,CAerG;AAED,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"bind.d.ts","sourceRoot":"","sources":["../src/bind.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,UAAU,EAAsB,MAAM,cAAc,CAAC;AAEzE;;;;;;;;;;GAUG;AACH,iBAAS,IAAI,CACT,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,UAAU,EAAE,EAC5B,gBAAgB,EAAE,UAAU,GAC7B,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,KAAK,OAAO,CAInC;AAED,iBAAS,eAAe,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,IAAI,CAAC,KAAK,UAAU,CAAC,OAAO,IAAI,CAAC,CAIrG;AAED,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC"}
package/dist/bind.js CHANGED
@@ -16,15 +16,7 @@ function bind(sharedLibrary, symbol, argDescriptors, returnDescriptor) {
16
16
  }
17
17
  function createBindCache() {
18
18
  const cache = new Map();
19
- return (key, ...args) => {
20
- const existing = cache.get(key);
21
- if (existing !== undefined) {
22
- return existing;
23
- }
24
- const bound = bind(...args);
25
- cache.set(key, bound);
26
- return bound;
27
- };
19
+ return (key, ...args) => cache.getOrInsertComputed(key, () => bind(...args));
28
20
  }
29
21
  export { bind, createBindCache };
30
22
  //# sourceMappingURL=bind.js.map
package/dist/bind.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bind.js","sourceRoot":"","sources":["../src/bind.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,IAAI,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAEzE;;;;;;;;;;GAUG;AACH,SAAS,IAAI,CACT,aAAqB,EACrB,MAAc,EACd,cAA4B,EAC5B,gBAA4B;IAE5B,MAAM,UAAU,GAAG,UAAU,CAAC,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,gBAAgB,CAAC,CAAC;IAEvF,OAAO,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,eAAe;IACpB,MAAM,KAAK,GAAyC,IAAI,GAAG,EAAE,CAAC;IAE9D,OAAO,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,EAAE;QACpB,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAEhC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO,QAAQ,CAAC;QACpB,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QAC5B,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAEtB,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC;AACN,CAAC;AAED,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import { call, type Descriptor, bind as nativeBind } from \"@gtkx/native\";\n\n/**\n * Precompiles a call to a C function, marshalling the values it is given through the argument\n * descriptors and the result through the return one. The symbol is resolved in the shared library\n * on the first call.\n *\n * @param sharedLibrary The shared library to resolve the symbol in.\n * @param symbol The name of the C function to bind.\n * @param argDescriptors Describe the C arguments, in declaration order.\n * @param returnDescriptor Describes the C return value.\n * @returns A function calling the bound symbol.\n */\nfunction bind(\n sharedLibrary: string,\n symbol: string,\n argDescriptors: Descriptor[],\n returnDescriptor: Descriptor,\n): (...values: unknown[]) => unknown {\n const descriptor = nativeBind(sharedLibrary, symbol, argDescriptors, returnDescriptor);\n\n return (...values) => call(descriptor, values);\n}\n\nfunction createBindCache(): (key: string, ...args: Parameters<typeof bind>) => ReturnType<typeof bind> {\n const cache: Map<string, ReturnType<typeof bind>> = new Map();\n\n return (key, ...args) => {\n const existing = cache.get(key);\n\n if (existing !== undefined) {\n return existing;\n }\n\n const bound = bind(...args);\n cache.set(key, bound);\n\n return bound;\n };\n}\n\nexport { bind, createBindCache };\n"]}
1
+ {"version":3,"file":"bind.js","sourceRoot":"","sources":["../src/bind.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,IAAI,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAEzE;;;;;;;;;;GAUG;AACH,SAAS,IAAI,CACT,aAAqB,EACrB,MAAc,EACd,cAA4B,EAC5B,gBAA4B;IAE5B,MAAM,UAAU,GAAG,UAAU,CAAC,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,gBAAgB,CAAC,CAAC;IAEvF,OAAO,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,eAAe;IACpB,MAAM,KAAK,GAAyC,IAAI,GAAG,EAAE,CAAC;IAE9D,OAAO,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AACjF,CAAC;AAED,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import { call, type Descriptor, bind as nativeBind } from \"@gtkx/native\";\n\n/**\n * Precompiles a call to a C function, marshalling the values it is given through the argument\n * descriptors and the result through the return one. The symbol is resolved in the shared library\n * on the first call.\n *\n * @param sharedLibrary The shared library to resolve the symbol in.\n * @param symbol The name of the C function to bind.\n * @param argDescriptors Describe the C arguments, in declaration order.\n * @param returnDescriptor Describes the C return value.\n * @returns A function calling the bound symbol.\n */\nfunction bind(\n sharedLibrary: string,\n symbol: string,\n argDescriptors: Descriptor[],\n returnDescriptor: Descriptor,\n): (...values: unknown[]) => unknown {\n const descriptor = nativeBind(sharedLibrary, symbol, argDescriptors, returnDescriptor);\n\n return (...values) => call(descriptor, values);\n}\n\nfunction createBindCache(): (key: string, ...args: Parameters<typeof bind>) => ReturnType<typeof bind> {\n const cache: Map<string, ReturnType<typeof bind>> = new Map();\n\n return (key, ...args) => cache.getOrInsertComputed(key, () => bind(...args));\n}\n\nexport { bind, createBindCache };\n"]}
@@ -9,6 +9,11 @@ type CallbackSpec = {
9
9
  };
10
10
  declare const isCallerAllocatedOut: (descriptor: Descriptor) => boolean;
11
11
  declare const wrapCallbackValue: (spec: CallbackDescriptor, callback: unknown) => unknown;
12
+ /** Thrown when a value passed where a callback, signal handler or vfunc is expected cannot be called. */
13
+ declare class CallbackMarshalError extends TypeError {
14
+ /** Name callers match on when the error is caught as a plain `TypeError`. */
15
+ name: string;
16
+ }
12
17
  declare function wrapCallback(fn: Callback, spec: CallbackSpec, kind: CallbackKind): Callback;
13
- export { isCallerAllocatedOut, wrapCallbackValue, wrapCallback };
18
+ export { CallbackMarshalError, isCallerAllocatedOut, wrapCallbackValue, wrapCallback };
14
19
  //# sourceMappingURL=callback.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"callback.d.ts","sourceRoot":"","sources":["../src/callback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAiB,MAAM,kBAAkB,CAAC;AAQ1E,KAAK,QAAQ,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AAChD,KAAK,YAAY,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAC;AAOpD,KAAK,YAAY,GAAG;IAChB,cAAc,EAAE,UAAU,EAAE,CAAC;IAC7B,gBAAgB,EAAE,UAAU,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAoCF,QAAA,MAAM,oBAAoB,GAAI,YAAY,UAAU,KAAG,OACmD,CAAC;AAmN3G,QAAA,MAAM,iBAAiB,GAAI,MAAM,kBAAkB,EAAE,UAAU,OAAO,KAAG,OACa,CAAC;AAEvF,iBAAS,YAAY,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,GAAG,QAAQ,CAkBpF;AAED,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"callback.d.ts","sourceRoot":"","sources":["../src/callback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAiB,MAAM,kBAAkB,CAAC;AAa1E,KAAK,QAAQ,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AAChD,KAAK,YAAY,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAC;AAcpD,KAAK,YAAY,GAAG;IAChB,cAAc,EAAE,UAAU,EAAE,CAAC;IAC7B,gBAAgB,EAAE,UAAU,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAqCF,QAAA,MAAM,oBAAoB,GAAI,YAAY,UAAU,KAAG,OACmD,CAAC;AAgN3G,QAAA,MAAM,iBAAiB,GAAI,MAAM,kBAAkB,EAAE,UAAU,OAAO,KAAG,OACa,CAAC;AAKvF,yGAAyG;AACzG,cAAM,oBAAqB,SAAQ,SAAS;IACxC,6EAA6E;IAC7D,IAAI,SAA0B;CACjD;AAED,iBAAS,YAAY,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,GAAG,QAAQ,CAuBpF;AAED,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAC"}
package/dist/callback.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import { copy } from "@gtkx/native";
2
- import { foldedLengthSources } from "./folded-lengths.js";
2
+ import { foldedLengthArgIndices, foldedLengthSources, } from "./folded-lengths.js";
3
3
  import { fromNative, toNative } from "./native-value.js";
4
- import { getHandle } from "./registry.js";
4
+ import { describeValueKind, getHandle } from "./registry.js";
5
5
  import { splitTupleResult } from "./tuple.js";
6
6
  import { copyValue } from "./value.js";
7
7
  import { popSeedFrame, pushSeedFrame } from "./vfunc-seeds.js";
8
8
  const CALLBACK_TRAITS = {
9
- callback: { isInstanceBound: false, hasInstanceArg: false, hasFoldedLengths: true },
10
- signal: { isInstanceBound: false, hasInstanceArg: true, hasFoldedLengths: false },
11
- vfunc: { isInstanceBound: true, hasInstanceArg: true, hasFoldedLengths: true },
9
+ callback: { isInstanceBound: false, hasInstanceArg: false, hasFoldedLengths: true, hasFoldedInputs: true },
10
+ signal: { isInstanceBound: false, hasInstanceArg: true, hasFoldedLengths: false, hasFoldedInputs: false },
11
+ vfunc: { isInstanceBound: true, hasInstanceArg: true, hasFoldedLengths: true, hasFoldedInputs: false },
12
12
  };
13
13
  const fillCallerAllocatedBuffer = (descriptor, target, source) => {
14
14
  if (descriptor.kind === "boxed" && descriptor.typeName === "GValue") {
@@ -23,7 +23,7 @@ const fillCallerAllocatedBuffer = (descriptor, target, source) => {
23
23
  };
24
24
  const isCallerAllocatedOut = (descriptor) => (descriptor.kind === "boxed" || descriptor.kind === "struct") && descriptor.isCallerAllocated === true;
25
25
  const collectRefArg = (descriptor, wrappedValue, inputs, out) => {
26
- if (descriptor.inout === true) {
26
+ if (descriptor.inout === true && !out.isFolded) {
27
27
  inputs.push(wrappedValue.value);
28
28
  }
29
29
  out.params.push({ value: wrappedValue, descriptor, argIndex: out.argIndex });
@@ -33,18 +33,21 @@ const collectCallbackArg = (descriptor, wrappedValue, inputs, out) => {
33
33
  collectRefArg(descriptor, wrappedValue, inputs, out);
34
34
  return;
35
35
  }
36
- inputs.push(wrappedValue);
36
+ if (!out.isFolded) {
37
+ inputs.push(wrappedValue);
38
+ }
37
39
  if (descriptor !== undefined && isCallerAllocatedOut(descriptor)) {
38
40
  out.params.push({ value: wrappedValue, descriptor, argIndex: out.argIndex });
39
41
  }
40
42
  };
41
- const partitionCallbackArgs = (effectiveTypes, wrapped, start) => {
43
+ const partitionCallbackArgs = (plan, wrapped) => {
42
44
  const inputs = [];
43
45
  const params = [];
44
- const collected = { params, argIndex: start };
45
- for (let i = start; i < effectiveTypes.length; i++) {
46
+ const collected = { params, argIndex: plan.start, isFolded: false };
47
+ for (let i = plan.start; i < plan.effectiveTypes.length; i++) {
46
48
  collected.argIndex = i;
47
- collectCallbackArg(effectiveTypes[i], wrapped[i], inputs, collected);
49
+ collected.isFolded = plan.foldedInputIndices.has(i);
50
+ collectCallbackArg(plan.effectiveTypes[i], wrapped[i], inputs, collected);
48
51
  }
49
52
  return { inputs, outParams: params };
50
53
  };
@@ -124,14 +127,13 @@ const wrapCallbackArgs = (effectiveTypes, rawArgs) => {
124
127
  }
125
128
  };
126
129
  const trimCallbackInputs = (plan, wrapped) => {
127
- const count = plan.effectiveTypes.length;
128
- if (wrapped.length > count) {
129
- wrapped.length = count;
130
- }
131
- for (let index = 0; index < plan.start; index++) {
132
- wrapped.shift();
130
+ const inputs = [];
131
+ for (let index = plan.start; index < plan.effectiveTypes.length; index++) {
132
+ if (!plan.foldedInputIndices.has(index)) {
133
+ inputs.push(wrapped[index]);
134
+ }
133
135
  }
134
- return wrapped;
136
+ return inputs;
135
137
  };
136
138
  const nativeReturn = (plan, primary) => toNative(plan.returnDescriptor, plan.hasPrimary ? primary : undefined);
137
139
  const runCallback = (plan, rawArgs) => {
@@ -141,7 +143,7 @@ const runCallback = (plan, rawArgs) => {
141
143
  if (!plan.hasOutParams) {
142
144
  return nativeReturn(plan, plan.fn.apply(thisArg, trimCallbackInputs(plan, rawArgs)));
143
145
  }
144
- const { inputs, outParams } = partitionCallbackArgs(effectiveTypes, rawArgs, plan.start);
146
+ const { inputs, outParams } = partitionCallbackArgs(plan, rawArgs);
145
147
  const result = applyCallback(plan, thisArg, inputs, outParams);
146
148
  if (outParams.length === 0) {
147
149
  return nativeReturn(plan, result);
@@ -160,9 +162,18 @@ const getEffectiveTypes = (spec) => {
160
162
  return spec.argDescriptors.filter((_, i) => i !== userDataIndex);
161
163
  };
162
164
  const wrapCallbackValue = (spec, callback) => callback == null ? callback : wrapCallback(callback, spec, "callback");
165
+ const planFoldedInputIndices = (spec, hasFoldedInputs) => hasFoldedInputs ? foldedLengthArgIndices(spec) : new Set();
166
+ /** Thrown when a value passed where a callback, signal handler or vfunc is expected cannot be called. */
167
+ class CallbackMarshalError extends TypeError {
168
+ /** Name callers match on when the error is caught as a plain `TypeError`. */
169
+ name = "CallbackMarshalError";
170
+ }
163
171
  function wrapCallback(fn, spec, kind) {
172
+ if (typeof fn !== "function") {
173
+ throw new CallbackMarshalError(`Cannot marshal ${describeValueKind(fn)} into a ${kind}`);
174
+ }
164
175
  const effectiveTypes = getEffectiveTypes(spec);
165
- const { isInstanceBound, hasInstanceArg, hasFoldedLengths } = CALLBACK_TRAITS[kind];
176
+ const { isInstanceBound, hasInstanceArg, hasFoldedLengths, hasFoldedInputs } = CALLBACK_TRAITS[kind];
166
177
  const start = hasInstanceArg ? 1 : 0;
167
178
  const plan = {
168
179
  fn,
@@ -174,8 +185,9 @@ function wrapCallback(fn, spec, kind) {
174
185
  lengthSources: planLengthSources(spec, hasFoldedLengths),
175
186
  hasOutParams: haveOutParamArgs(effectiveTypes, start),
176
187
  hasRefOutParams: haveRefOutParamArgs(effectiveTypes, start),
188
+ foldedInputIndices: planFoldedInputIndices(spec, hasFoldedInputs),
177
189
  };
178
190
  return (...rawArgs) => runCallback(plan, rawArgs);
179
191
  }
180
- export { isCallerAllocatedOut, wrapCallbackValue, wrapCallback };
192
+ export { CallbackMarshalError, isCallerAllocatedOut, wrapCallbackValue, wrapCallback };
181
193
  //# sourceMappingURL=callback.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"callback.js","sourceRoot":"","sources":["../src/callback.ts"],"names":[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CAAC,CAAC;AACrE,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,CAAC,IAAwB,EAAE,QAAiB,EAAW,EAAE,CAC/E,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,QAAoB,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;AAEvF,SAAS,YAAY,CAAC,EAAY,EAAE,IAAkB,EAAE,IAAkB;IACtE,MAAM,cAAc,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACpF,MAAM,KAAK,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAErC,MAAM,IAAI,GAAiB;QACvB,EAAE;QACF,cAAc;QACd,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;QACvC,UAAU,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,KAAK,MAAM;QACjD,KAAK;QACL,eAAe;QACf,aAAa,EAAE,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,CAAC;QACxD,YAAY,EAAE,gBAAgB,CAAC,cAAc,EAAE,KAAK,CAAC;QACrD,eAAe,EAAE,mBAAmB,CAAC,cAAc,EAAE,KAAK,CAAC;KAC9D,CAAC;IAEF,OAAO,CAAC,GAAG,OAAkB,EAAW,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC1E,CAAC;AAED,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { copy, type Descriptor } from \"@gtkx/native\";\nimport type { CallbackDescriptor, RefDescriptor } from \"./descriptors.js\";\nimport { foldedLengthSources, type LengthSource, type LengthSources } from \"./folded-lengths.js\";\nimport { fromNative, toNative } from \"./native-value.js\";\nimport { getHandle } from \"./registry.js\";\nimport { splitTupleResult } from \"./tuple.js\";\nimport { copyValue } from \"./value.js\";\nimport { popSeedFrame, pushSeedFrame, type RefSeeds } from \"./vfunc-seeds.js\";\n\ntype Callback = (...args: unknown[]) => unknown;\ntype CallbackKind = \"vfunc\" | \"signal\" | \"callback\";\ntype CallbackTraits = { isInstanceBound: boolean; hasInstanceArg: boolean; hasFoldedLengths: boolean };\ntype OutParam = { value: unknown; descriptor: Descriptor; argIndex: number };\ntype LengthLink = { target: OutParam; sources: LengthSource[] };\ntype OutParamGroups = { lengthLinks: LengthLink[]; valueParams: OutParam[] };\ntype OutValues = Map<number, unknown>;\n\ntype CallbackSpec = {\n argDescriptors: Descriptor[];\n returnDescriptor: Descriptor;\n userDataIndex?: number;\n};\n\ntype CallbackPlan = {\n fn: Callback;\n effectiveTypes: Descriptor[];\n returnDescriptor: Descriptor;\n hasPrimary: boolean;\n start: number;\n isInstanceBound: boolean;\n lengthSources: LengthSources;\n hasOutParams: boolean;\n hasRefOutParams: boolean;\n};\n\nconst CALLBACK_TRAITS: Record<CallbackKind, CallbackTraits> = {\n callback: { isInstanceBound: false, hasInstanceArg: false, hasFoldedLengths: true },\n signal: { isInstanceBound: false, hasInstanceArg: true, hasFoldedLengths: false },\n vfunc: { isInstanceBound: true, hasInstanceArg: true, hasFoldedLengths: true },\n};\n\nconst fillCallerAllocatedBuffer = (descriptor: Descriptor, target: object, source: object): void => {\n if (descriptor.kind === \"boxed\" && descriptor.typeName === \"GValue\") {\n copyValue(getHandle(target), getHandle(source));\n\n return;\n }\n\n if ((descriptor.kind === \"boxed\" || descriptor.kind === \"struct\") && descriptor.size !== undefined) {\n copy(getHandle(target), getHandle(source), descriptor.size);\n\n return;\n }\n\n throw new Error(`Cannot write caller-allocated ${descriptor.kind} out-parameter: no known byte size`);\n};\n\nconst isCallerAllocatedOut = (descriptor: Descriptor): boolean =>\n (descriptor.kind === \"boxed\" || descriptor.kind === \"struct\") && descriptor.isCallerAllocated === true;\n\nconst collectRefArg = (\n descriptor: RefDescriptor,\n wrappedValue: unknown,\n inputs: unknown[],\n out: { params: OutParam[]; argIndex: number },\n): void => {\n if (descriptor.inout === true) {\n inputs.push((wrappedValue as { value: unknown }).value);\n }\n\n out.params.push({ value: wrappedValue, descriptor, argIndex: out.argIndex });\n};\n\nconst collectCallbackArg = (\n descriptor: Descriptor | undefined,\n wrappedValue: unknown,\n inputs: unknown[],\n out: { params: OutParam[]; argIndex: number },\n): void => {\n if (descriptor?.kind === \"ref\") {\n collectRefArg(descriptor, wrappedValue, inputs, out);\n\n return;\n }\n\n inputs.push(wrappedValue);\n\n if (descriptor !== undefined && isCallerAllocatedOut(descriptor)) {\n out.params.push({ value: wrappedValue, descriptor, argIndex: out.argIndex });\n }\n};\n\nconst partitionCallbackArgs = (\n effectiveTypes: Descriptor[],\n wrapped: unknown[],\n start: number,\n): { inputs: unknown[]; outParams: OutParam[] } => {\n const inputs: unknown[] = [];\n const params: OutParam[] = [];\n const collected = { params, argIndex: start };\n\n for (let i = start; i < effectiveTypes.length; i++) {\n collected.argIndex = i;\n collectCallbackArg(effectiveTypes[i], wrapped[i], inputs, collected);\n }\n\n return { inputs, outParams: params };\n};\n\nconst hasOutParamArg = (descriptor: Descriptor | undefined): boolean =>\n descriptor !== undefined && (descriptor.kind === \"ref\" || isCallerAllocatedOut(descriptor));\n\nconst hasRefOutParamArg = (descriptor: Descriptor | undefined): boolean =>\n descriptor?.kind === \"ref\" && descriptor.inout !== true;\n\nconst haveOutParamArgs = (effectiveTypes: Descriptor[], start: number): boolean =>\n effectiveTypes.slice(start).some((descriptor) => hasOutParamArg(descriptor));\n\nconst haveRefOutParamArgs = (effectiveTypes: Descriptor[], start: number): boolean =>\n effectiveTypes.slice(start).some((descriptor) => hasRefOutParamArg(descriptor));\n\nconst groupOutParams = (outParams: OutParam[], lengthSources: LengthSources): OutParamGroups => {\n const groups: OutParamGroups = { lengthLinks: [], valueParams: [] };\n\n for (const outParam of outParams) {\n const sources = lengthSources.get(outParam.argIndex);\n\n if (sources === undefined) {\n groups.valueParams.push(outParam);\n } else {\n groups.lengthLinks.push({ target: outParam, sources });\n }\n }\n\n return groups;\n};\n\nconst getLength = (value: unknown): number => {\n const length = (value as { length?: unknown } | null | undefined)?.length;\n\n return typeof length === \"number\" ? length : 0;\n};\n\nconst lengthSourceValue = (source: LengthSource, outValues: OutValues, primary: unknown): unknown =>\n source.kind === \"return\" ? primary : outValues.get(source.argIndex);\n\nconst foldedLength = (sources: LengthSource[], outValues: OutValues, primary: unknown): number =>\n Math.min(...sources.map((source) => getLength(lengthSourceValue(source, outValues, primary))));\n\nconst resolveOutValues = (groups: OutParamGroups, values: unknown[], primary: unknown): OutValues => {\n const outValues: OutValues = new Map();\n\n for (const [position, outParam] of groups.valueParams.entries()) {\n outValues.set(outParam.argIndex, values[position]);\n }\n\n for (const link of groups.lengthLinks) {\n outValues.set(link.target.argIndex, foldedLength(link.sources, outValues, primary));\n }\n\n return outValues;\n};\n\nconst writeOutParams = (outParams: OutParam[], outValues: OutValues): void => {\n for (const outParam of outParams) {\n const { descriptor } = outParam;\n const outValue = outValues.get(outParam.argIndex);\n\n if (descriptor.kind === \"ref\") {\n (outParam.value as { value: unknown }).value = toNative(descriptor.innerDescriptor, outValue);\n } else if (outValue != null && outParam.value != null) {\n fillCallerAllocatedBuffer(descriptor, outParam.value, outValue);\n }\n }\n};\n\nconst collectRefSeeds = (outParams: OutParam[]): RefSeeds => {\n const seeds: RefSeeds = new Map();\n\n for (const outParam of outParams) {\n const seed = (outParam.value as { value?: unknown } | null)?.value;\n\n if (seed != null && hasRefOutParamArg(outParam.descriptor)) {\n seeds.set(outParam.argIndex, seed);\n }\n }\n\n return seeds;\n};\n\nconst applyCallback = (plan: CallbackPlan, thisArg: unknown, inputs: unknown[], outParams: OutParam[]): unknown => {\n if (!plan.hasRefOutParams) {\n return plan.fn.apply(thisArg, inputs);\n }\n\n pushSeedFrame({ argDescriptors: plan.effectiveTypes, instance: thisArg, seeds: collectRefSeeds(outParams) });\n\n try {\n return plan.fn.apply(thisArg, inputs);\n } finally {\n popSeedFrame();\n }\n};\n\nconst getThisArg = (isInstanceBound: boolean, wrapped: unknown[]): unknown =>\n isInstanceBound ? (wrapped[0] ?? null) : null;\n\nconst wrapCallbackArgs = (effectiveTypes: Descriptor[], rawArgs: unknown[]): void => {\n let index = 0;\n\n for (const descriptor of effectiveTypes) {\n rawArgs[index] = fromNative(descriptor, rawArgs[index]);\n index += 1;\n }\n};\n\nconst trimCallbackInputs = (plan: CallbackPlan, wrapped: unknown[]): unknown[] => {\n const count = plan.effectiveTypes.length;\n\n if (wrapped.length > count) {\n wrapped.length = count;\n }\n\n for (let index = 0; index < plan.start; index++) {\n wrapped.shift();\n }\n\n return wrapped;\n};\n\nconst nativeReturn = (plan: CallbackPlan, primary: unknown): unknown =>\n toNative(plan.returnDescriptor, plan.hasPrimary ? primary : undefined);\n\nconst runCallback = (plan: CallbackPlan, rawArgs: unknown[]): unknown => {\n const { effectiveTypes } = plan;\n wrapCallbackArgs(effectiveTypes, rawArgs);\n const thisArg = getThisArg(plan.isInstanceBound, rawArgs);\n\n if (!plan.hasOutParams) {\n return nativeReturn(plan, plan.fn.apply(thisArg, trimCallbackInputs(plan, rawArgs)));\n }\n\n const { inputs, outParams } = partitionCallbackArgs(effectiveTypes, rawArgs, plan.start);\n const result = applyCallback(plan, thisArg, inputs, outParams);\n\n if (outParams.length === 0) {\n return nativeReturn(plan, result);\n }\n\n const groups = groupOutParams(outParams, plan.lengthSources);\n const { primary, outValues } = splitTupleResult(result, plan.hasPrimary, groups.valueParams.length);\n writeOutParams(outParams, resolveOutValues(groups, outValues, primary));\n\n return nativeReturn(plan, primary);\n};\n\nconst planLengthSources = (spec: CallbackSpec, hasFoldedLengths: boolean): LengthSources =>\n hasFoldedLengths ? foldedLengthSources(spec) : new Map<number, LengthSource[]>();\n\nconst getEffectiveTypes = (spec: CallbackSpec): Descriptor[] => {\n const { userDataIndex } = spec;\n\n if (userDataIndex === undefined) {\n return spec.argDescriptors;\n }\n\n return spec.argDescriptors.filter((_, i) => i !== userDataIndex);\n};\n\nconst wrapCallbackValue = (spec: CallbackDescriptor, callback: unknown): unknown =>\n callback == null ? callback : wrapCallback(callback as Callback, spec, \"callback\");\n\nfunction wrapCallback(fn: Callback, spec: CallbackSpec, kind: CallbackKind): Callback {\n const effectiveTypes = getEffectiveTypes(spec);\n const { isInstanceBound, hasInstanceArg, hasFoldedLengths } = CALLBACK_TRAITS[kind];\n const start = hasInstanceArg ? 1 : 0;\n\n const plan: CallbackPlan = {\n fn,\n effectiveTypes,\n returnDescriptor: spec.returnDescriptor,\n hasPrimary: spec.returnDescriptor.kind !== \"void\",\n start,\n isInstanceBound,\n lengthSources: planLengthSources(spec, hasFoldedLengths),\n hasOutParams: haveOutParamArgs(effectiveTypes, start),\n hasRefOutParams: haveRefOutParamArgs(effectiveTypes, start),\n };\n\n return (...rawArgs: unknown[]): unknown => runCallback(plan, rawArgs);\n}\n\nexport { isCallerAllocatedOut, wrapCallbackValue, wrapCallback };\n"]}
1
+ {"version":3,"file":"callback.js","sourceRoot":"","sources":["../src/callback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,MAAM,cAAc,CAAC;AAErD,OAAO,EACH,sBAAsB,EACtB,mBAAmB,GAGtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAiB,MAAM,kBAAkB,CAAC;AAoC9E,MAAM,eAAe,GAAyC;IAC1D,QAAQ,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,gBAAgB,EAAE,IAAI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AO,CAAC,CAAC;AAC1E,CAAC;AAED,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { copy, type Descriptor } from \"@gtkx/native\";\nimport type { CallbackDescriptor, RefDescriptor } from \"./descriptors.js\";\nimport {\n foldedLengthArgIndices,\n foldedLengthSources,\n type LengthSource,\n type LengthSources,\n} from \"./folded-lengths.js\";\nimport { fromNative, toNative } from \"./native-value.js\";\nimport { describeValueKind, getHandle } from \"./registry.js\";\nimport { splitTupleResult } from \"./tuple.js\";\nimport { copyValue } from \"./value.js\";\nimport { popSeedFrame, pushSeedFrame, type RefSeeds } from \"./vfunc-seeds.js\";\n\ntype Callback = (...args: unknown[]) => unknown;\ntype CallbackKind = \"vfunc\" | \"signal\" | \"callback\";\ntype CallbackTraits = {\n isInstanceBound: boolean;\n hasInstanceArg: boolean;\n hasFoldedLengths: boolean;\n hasFoldedInputs: boolean;\n};\ntype OutParam = { value: unknown; descriptor: Descriptor; argIndex: number };\ntype CollectedArgs = { params: OutParam[]; argIndex: number; isFolded: boolean };\ntype PartitionedArgs = { inputs: unknown[]; outParams: OutParam[] };\ntype LengthLink = { target: OutParam; sources: LengthSource[] };\ntype OutParamGroups = { lengthLinks: LengthLink[]; valueParams: OutParam[] };\ntype OutValues = Map<number, unknown>;\n\ntype CallbackSpec = {\n argDescriptors: Descriptor[];\n returnDescriptor: Descriptor;\n userDataIndex?: number;\n};\n\ntype CallbackPlan = {\n fn: Callback;\n effectiveTypes: Descriptor[];\n returnDescriptor: Descriptor;\n hasPrimary: boolean;\n start: number;\n isInstanceBound: boolean;\n lengthSources: LengthSources;\n hasOutParams: boolean;\n hasRefOutParams: boolean;\n foldedInputIndices: ReadonlySet<number>;\n};\n\nconst CALLBACK_TRAITS: Record<CallbackKind, CallbackTraits> = {\n callback: { isInstanceBound: false, hasInstanceArg: false, hasFoldedLengths: true, hasFoldedInputs: true },\n signal: { isInstanceBound: false, hasInstanceArg: true, hasFoldedLengths: false, hasFoldedInputs: false },\n vfunc: { isInstanceBound: true, hasInstanceArg: true, hasFoldedLengths: true, hasFoldedInputs: false },\n};\n\nconst fillCallerAllocatedBuffer = (descriptor: Descriptor, target: object, source: object): void => {\n if (descriptor.kind === \"boxed\" && descriptor.typeName === \"GValue\") {\n copyValue(getHandle(target), getHandle(source));\n\n return;\n }\n\n if ((descriptor.kind === \"boxed\" || descriptor.kind === \"struct\") && descriptor.size !== undefined) {\n copy(getHandle(target), getHandle(source), descriptor.size);\n\n return;\n }\n\n throw new Error(`Cannot write caller-allocated ${descriptor.kind} out-parameter: no known byte size`);\n};\n\nconst isCallerAllocatedOut = (descriptor: Descriptor): boolean =>\n (descriptor.kind === \"boxed\" || descriptor.kind === \"struct\") && descriptor.isCallerAllocated === true;\n\nconst collectRefArg = (\n descriptor: RefDescriptor,\n wrappedValue: unknown,\n inputs: unknown[],\n out: CollectedArgs,\n): void => {\n if (descriptor.inout === true && !out.isFolded) {\n inputs.push((wrappedValue as { value: unknown }).value);\n }\n\n out.params.push({ value: wrappedValue, descriptor, argIndex: out.argIndex });\n};\n\nconst collectCallbackArg = (\n descriptor: Descriptor | undefined,\n wrappedValue: unknown,\n inputs: unknown[],\n out: CollectedArgs,\n): void => {\n if (descriptor?.kind === \"ref\") {\n collectRefArg(descriptor, wrappedValue, inputs, out);\n\n return;\n }\n\n if (!out.isFolded) {\n inputs.push(wrappedValue);\n }\n\n if (descriptor !== undefined && isCallerAllocatedOut(descriptor)) {\n out.params.push({ value: wrappedValue, descriptor, argIndex: out.argIndex });\n }\n};\n\nconst partitionCallbackArgs = (plan: CallbackPlan, wrapped: unknown[]): PartitionedArgs => {\n const inputs: unknown[] = [];\n const params: OutParam[] = [];\n const collected: CollectedArgs = { params, argIndex: plan.start, isFolded: false };\n\n for (let i = plan.start; i < plan.effectiveTypes.length; i++) {\n collected.argIndex = i;\n collected.isFolded = plan.foldedInputIndices.has(i);\n collectCallbackArg(plan.effectiveTypes[i], wrapped[i], inputs, collected);\n }\n\n return { inputs, outParams: params };\n};\n\nconst hasOutParamArg = (descriptor: Descriptor | undefined): boolean =>\n descriptor !== undefined && (descriptor.kind === \"ref\" || isCallerAllocatedOut(descriptor));\n\nconst hasRefOutParamArg = (descriptor: Descriptor | undefined): boolean =>\n descriptor?.kind === \"ref\" && descriptor.inout !== true;\n\nconst haveOutParamArgs = (effectiveTypes: Descriptor[], start: number): boolean =>\n effectiveTypes.slice(start).some((descriptor) => hasOutParamArg(descriptor));\n\nconst haveRefOutParamArgs = (effectiveTypes: Descriptor[], start: number): boolean =>\n effectiveTypes.slice(start).some((descriptor) => hasRefOutParamArg(descriptor));\n\nconst groupOutParams = (outParams: OutParam[], lengthSources: LengthSources): OutParamGroups => {\n const groups: OutParamGroups = { lengthLinks: [], valueParams: [] };\n\n for (const outParam of outParams) {\n const sources = lengthSources.get(outParam.argIndex);\n\n if (sources === undefined) {\n groups.valueParams.push(outParam);\n } else {\n groups.lengthLinks.push({ target: outParam, sources });\n }\n }\n\n return groups;\n};\n\nconst getLength = (value: unknown): number => {\n const length = (value as { length?: unknown } | null | undefined)?.length;\n\n return typeof length === \"number\" ? length : 0;\n};\n\nconst lengthSourceValue = (source: LengthSource, outValues: OutValues, primary: unknown): unknown =>\n source.kind === \"return\" ? primary : outValues.get(source.argIndex);\n\nconst foldedLength = (sources: LengthSource[], outValues: OutValues, primary: unknown): number =>\n Math.min(...sources.map((source) => getLength(lengthSourceValue(source, outValues, primary))));\n\nconst resolveOutValues = (groups: OutParamGroups, values: unknown[], primary: unknown): OutValues => {\n const outValues: OutValues = new Map();\n\n for (const [position, outParam] of groups.valueParams.entries()) {\n outValues.set(outParam.argIndex, values[position]);\n }\n\n for (const link of groups.lengthLinks) {\n outValues.set(link.target.argIndex, foldedLength(link.sources, outValues, primary));\n }\n\n return outValues;\n};\n\nconst writeOutParams = (outParams: OutParam[], outValues: OutValues): void => {\n for (const outParam of outParams) {\n const { descriptor } = outParam;\n const outValue = outValues.get(outParam.argIndex);\n\n if (descriptor.kind === \"ref\") {\n (outParam.value as { value: unknown }).value = toNative(descriptor.innerDescriptor, outValue);\n } else if (outValue != null && outParam.value != null) {\n fillCallerAllocatedBuffer(descriptor, outParam.value, outValue);\n }\n }\n};\n\nconst collectRefSeeds = (outParams: OutParam[]): RefSeeds => {\n const seeds: RefSeeds = new Map();\n\n for (const outParam of outParams) {\n const seed = (outParam.value as { value?: unknown } | null)?.value;\n\n if (seed != null && hasRefOutParamArg(outParam.descriptor)) {\n seeds.set(outParam.argIndex, seed);\n }\n }\n\n return seeds;\n};\n\nconst applyCallback = (plan: CallbackPlan, thisArg: unknown, inputs: unknown[], outParams: OutParam[]): unknown => {\n if (!plan.hasRefOutParams) {\n return plan.fn.apply(thisArg, inputs);\n }\n\n pushSeedFrame({ argDescriptors: plan.effectiveTypes, instance: thisArg, seeds: collectRefSeeds(outParams) });\n\n try {\n return plan.fn.apply(thisArg, inputs);\n } finally {\n popSeedFrame();\n }\n};\n\nconst getThisArg = (isInstanceBound: boolean, wrapped: unknown[]): unknown =>\n isInstanceBound ? (wrapped[0] ?? null) : null;\n\nconst wrapCallbackArgs = (effectiveTypes: Descriptor[], rawArgs: unknown[]): void => {\n let index = 0;\n\n for (const descriptor of effectiveTypes) {\n rawArgs[index] = fromNative(descriptor, rawArgs[index]);\n index += 1;\n }\n};\n\nconst trimCallbackInputs = (plan: CallbackPlan, wrapped: unknown[]): unknown[] => {\n const inputs: unknown[] = [];\n\n for (let index = plan.start; index < plan.effectiveTypes.length; index++) {\n if (!plan.foldedInputIndices.has(index)) {\n inputs.push(wrapped[index]);\n }\n }\n\n return inputs;\n};\n\nconst nativeReturn = (plan: CallbackPlan, primary: unknown): unknown =>\n toNative(plan.returnDescriptor, plan.hasPrimary ? primary : undefined);\n\nconst runCallback = (plan: CallbackPlan, rawArgs: unknown[]): unknown => {\n const { effectiveTypes } = plan;\n wrapCallbackArgs(effectiveTypes, rawArgs);\n const thisArg = getThisArg(plan.isInstanceBound, rawArgs);\n\n if (!plan.hasOutParams) {\n return nativeReturn(plan, plan.fn.apply(thisArg, trimCallbackInputs(plan, rawArgs)));\n }\n\n const { inputs, outParams } = partitionCallbackArgs(plan, rawArgs);\n const result = applyCallback(plan, thisArg, inputs, outParams);\n\n if (outParams.length === 0) {\n return nativeReturn(plan, result);\n }\n\n const groups = groupOutParams(outParams, plan.lengthSources);\n const { primary, outValues } = splitTupleResult(result, plan.hasPrimary, groups.valueParams.length);\n writeOutParams(outParams, resolveOutValues(groups, outValues, primary));\n\n return nativeReturn(plan, primary);\n};\n\nconst planLengthSources = (spec: CallbackSpec, hasFoldedLengths: boolean): LengthSources =>\n hasFoldedLengths ? foldedLengthSources(spec) : new Map<number, LengthSource[]>();\n\nconst getEffectiveTypes = (spec: CallbackSpec): Descriptor[] => {\n const { userDataIndex } = spec;\n\n if (userDataIndex === undefined) {\n return spec.argDescriptors;\n }\n\n return spec.argDescriptors.filter((_, i) => i !== userDataIndex);\n};\n\nconst wrapCallbackValue = (spec: CallbackDescriptor, callback: unknown): unknown =>\n callback == null ? callback : wrapCallback(callback as Callback, spec, \"callback\");\n\nconst planFoldedInputIndices = (spec: CallbackSpec, hasFoldedInputs: boolean): ReadonlySet<number> =>\n hasFoldedInputs ? foldedLengthArgIndices(spec) : new Set<number>();\n\n/** Thrown when a value passed where a callback, signal handler or vfunc is expected cannot be called. */\nclass CallbackMarshalError extends TypeError {\n /** Name callers match on when the error is caught as a plain `TypeError`. */\n public override name = \"CallbackMarshalError\";\n}\n\nfunction wrapCallback(fn: Callback, spec: CallbackSpec, kind: CallbackKind): Callback {\n if (typeof fn !== \"function\") {\n throw new CallbackMarshalError(`Cannot marshal ${describeValueKind(fn)} into a ${kind}`);\n }\n\n const effectiveTypes = getEffectiveTypes(spec);\n const { isInstanceBound, hasInstanceArg, hasFoldedLengths, hasFoldedInputs } = CALLBACK_TRAITS[kind];\n const start = hasInstanceArg ? 1 : 0;\n\n const plan: CallbackPlan = {\n fn,\n effectiveTypes,\n returnDescriptor: spec.returnDescriptor,\n hasPrimary: spec.returnDescriptor.kind !== \"void\",\n start,\n isInstanceBound,\n lengthSources: planLengthSources(spec, hasFoldedLengths),\n hasOutParams: haveOutParamArgs(effectiveTypes, start),\n hasRefOutParams: haveRefOutParamArgs(effectiveTypes, start),\n foldedInputIndices: planFoldedInputIndices(spec, hasFoldedInputs),\n };\n\n return (...rawArgs: unknown[]): unknown => runCallback(plan, rawArgs);\n}\n\nexport { CallbackMarshalError, isCallerAllocatedOut, wrapCallbackValue, wrapCallback };\n"]}
package/dist/closure.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type ExternalObject, type Handle } from "@gtkx/native";
2
+ import { type CallbackDescriptor } from "./descriptors.js";
2
3
  /**
3
4
  * Handler backing a `GClosure`. It receives the closure's parameters already converted from their
4
5
  * `GValue`s, and its result is written back into the closure's return `GValue` when it has one.
@@ -8,6 +9,7 @@ import { type ExternalObject, type Handle } from "@gtkx/native";
8
9
  * handler produces that parameter's value. It stops being valid once the handler returns.
9
10
  */
10
11
  type ClosureCallback = (...args: never[]) => unknown;
12
+ declare function newCCallbackClosure(key: string, callback: CallbackDescriptor, fn: unknown): ExternalObject<Handle>;
11
13
  /**
12
14
  * Marshals a value passed where a `GObject.Closure` is expected into a closure handle: a function
13
15
  * becomes a new `GClosure` dispatching into it, and an existing closure yields its own handle.
@@ -22,5 +24,5 @@ declare class ClosureMarshalError extends TypeError {
22
24
  /** Name callers match on when the error is caught as a plain `TypeError`. */
23
25
  name: string;
24
26
  }
25
- export { type ClosureCallback, ClosureMarshalError, toClosure, tryToClosure };
27
+ export { type ClosureCallback, ClosureMarshalError, newCCallbackClosure, toClosure, tryToClosure };
26
28
  //# sourceMappingURL=closure.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"closure.d.ts","sourceRoot":"","sources":["../src/closure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,MAAM,EAAQ,MAAM,c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