@gtkx/config 0.21.0 → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +137 -82
- package/dist/config.d.ts +76 -35
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +76 -83
- package/dist/config.js.map +1 -1
- package/dist/element-props.d.ts +180 -0
- package/dist/element-props.d.ts.map +1 -0
- package/dist/element-props.js +154 -0
- package/dist/element-props.js.map +1 -0
- package/dist/index.d.ts +3 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -8
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +3 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +3 -0
- package/dist/internal.js.map +1 -0
- package/dist/loader.d.ts +19 -15
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +25 -39
- package/dist/loader.js.map +1 -1
- package/dist/virtual.d.ts +2 -4
- package/dist/virtual.d.ts.map +1 -1
- package/dist/virtual.js +2 -14
- package/dist/virtual.js.map +1 -1
- package/dist/vite-plugin.d.ts +16 -0
- package/dist/vite-plugin.d.ts.map +1 -0
- package/dist/vite-plugin.js +32 -0
- package/dist/vite-plugin.js.map +1 -0
- package/env.d.ts +4 -22
- package/package.json +20 -7
- package/src/config.ts +134 -144
- package/src/element-props.ts +248 -0
- package/src/index.ts +14 -82
- package/src/internal.ts +2 -0
- package/src/loader.ts +36 -56
- package/src/virtual.ts +3 -32
- package/src/vite-plugin.ts +37 -0
- package/dist/bundled-modules.d.ts +0 -2
- package/dist/bundled-modules.d.ts.map +0 -1
- package/dist/bundled-modules.js +0 -2
- package/dist/bundled-modules.js.map +0 -1
- package/dist/data-dir.d.ts +0 -4
- package/dist/data-dir.d.ts.map +0 -1
- package/dist/data-dir.js +0 -37
- package/dist/data-dir.js.map +0 -1
- package/dist/plugin.d.ts +0 -9
- package/dist/plugin.d.ts.map +0 -1
- package/dist/plugin.js +0 -24
- package/dist/plugin.js.map +0 -1
- package/dist/runtime.d.ts +0 -22
- package/dist/runtime.d.ts.map +0 -1
- package/dist/runtime.js +0 -22
- package/dist/runtime.js.map +0 -1
- package/dist/table-rules-ir.d.ts +0 -36
- package/dist/table-rules-ir.d.ts.map +0 -1
- package/dist/table-rules-ir.js +0 -2
- package/dist/table-rules-ir.js.map +0 -1
- package/dist/table-schema.d.ts +0 -107
- package/dist/table-schema.d.ts.map +0 -1
- package/dist/table-schema.js +0 -199
- package/dist/table-schema.js.map +0 -1
- package/dist/validators.d.ts +0 -4
- package/dist/validators.d.ts.map +0 -1
- package/dist/validators.js +0 -10
- package/dist/validators.js.map +0 -1
- package/dist/wrapper-protocol.d.ts +0 -12
- package/dist/wrapper-protocol.d.ts.map +0 -1
- package/dist/wrapper-protocol.js +0 -12
- package/dist/wrapper-protocol.js.map +0 -1
- package/src/bundled-modules.ts +0 -1
- package/src/data-dir.ts +0 -39
- package/src/plugin.ts +0 -30
- package/src/table-rules-ir.ts +0 -42
- package/src/table-schema.ts +0 -342
- package/src/validators.ts +0 -15
- package/src/wrapper-protocol.ts +0 -21
package/README.md
CHANGED
|
@@ -1,118 +1,173 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="logo.svg" alt="
|
|
2
|
+
<img src="https://raw.githubusercontent.com/gtkx-org/gtkx/main/logo.svg" alt="GTKX" width="100" />
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
<h1 align="center">GTKX</h1>
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
<p align="center">
|
|
8
|
+
The React framework for Linux.<br />
|
|
9
|
+
Build GTK4 and Adwaita apps in TypeScript, with React components and hooks driving GNOME's own widgets. What you ship is a GNOME app.
|
|
10
|
+
</p>
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
<p align="center">
|
|
13
|
+
<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>
|
|
14
|
+
<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>
|
|
15
|
+
<img src="https://img.shields.io/badge/node-%E2%89%A524-339933?logo=node.js&logoColor=white" alt="Node >= 24" />
|
|
16
|
+
<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>
|
|
17
|
+
<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>
|
|
18
|
+
<img src="https://img.shields.io/badge/TypeScript-strict-3178c6?logo=typescript&logoColor=white" alt="TypeScript" />
|
|
19
|
+
</p>
|
|
12
20
|
|
|
13
|
-
|
|
21
|
+
<p align="center">
|
|
22
|
+
<a href="https://gtkx.dev">Homepage</a> ·
|
|
23
|
+
<a href="https://gtkx.dev/guide/why-gtkx">Documentation</a> ·
|
|
24
|
+
<a href="https://github.com/gtkx-org/gtkx/tree/main/examples">Examples</a> ·
|
|
25
|
+
<a href="https://github.com/gtkx-org/gtkx/blob/main/CONTRIBUTING.md">Contributing</a>
|
|
26
|
+
</p>
|
|
14
27
|
|
|
15
|
-
|
|
28
|
+
---
|
|
16
29
|
|
|
17
|
-
-
|
|
18
|
-
- **pnpm** — the workspace package manager, provisioned via Corepack from the `packageManager` field.
|
|
19
|
-
- **Rust toolchain** — 2024 edition with a C linker, plus the napi-rs CLI and Node N-API headers, to compile the native addon. A nightly toolchain is additionally required for the coverage, asan, and miri paths.
|
|
20
|
-
- **libffi** — for dynamic CIF construction and closures in the native addon.
|
|
21
|
-
- **GTK4 and libadwaita** development libraries, plus the broader GNOME library set the examples use (GtkSourceView, WebKitGTK, VTE, GStreamer, etc.), with `pkg-config`.
|
|
22
|
-
- **GLib/GObject** shared libraries present at build and run time; gtkx resolves GTK symbols dynamically by name.
|
|
23
|
-
- **GObject-Introspection** development data and system GIR files (read by codegen), plus `glib-compile-resources` and `glib-compile-schemas` for asset compilation.
|
|
24
|
-
- **A headless Wayland compositor** (Weston, or Sway when `GTKX_COMPOSITOR=sway`) and software GL/Vulkan rasterization to run GTK tests and benches without a GPU.
|
|
25
|
-
- **git**, for repository initialization during scaffolding.
|
|
30
|
+
GTKX generates fully typed bindings for the entire GTK4 and Adwaita surface directly from GObject-Introspection. On top of those bindings you get the React programming model: components and hooks driving GObject instances, with Fast Refresh while you develop.
|
|
26
31
|
|
|
27
|
-
|
|
32
|
+
<p align="center">
|
|
33
|
+
<img src="https://raw.githubusercontent.com/gtkx-org/gtkx/main/examples/tutorial/assets/screenshot.png" alt="The Tasks app: an Adwaita window with a sidebar of smart views and colored lists on the left, and a boxed task list on the right." />
|
|
34
|
+
</p>
|
|
28
35
|
|
|
29
|
-
|
|
36
|
+
<p align="center">
|
|
37
|
+
<em>The Tasks app you build in the <a href="https://gtkx.dev/tutorial/">tutorial</a>.</em>
|
|
38
|
+
</p>
|
|
30
39
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
## Demo
|
|
41
|
+
|
|
42
|
+
The intrinsic elements in this snippet render GTK4 widgets, and ordinary React hooks and events drive them:
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
import * as Gtk from "@gtkx/gi/gtk";
|
|
46
|
+
import { GtkApplication, GtkApplicationWindow, GtkBox, GtkButton, GtkLabel } from "@gtkx/jsx/gtk";
|
|
47
|
+
import { createRoot, quit } from "@gtkx/react";
|
|
48
|
+
import { useState } from "react";
|
|
49
|
+
|
|
50
|
+
const Counter = () => {
|
|
51
|
+
const [count, setCount] = useState(0);
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<GtkApplicationWindow
|
|
55
|
+
title="Hello GTKX"
|
|
56
|
+
defaultWidth={400}
|
|
57
|
+
defaultHeight={300}
|
|
58
|
+
onCloseRequest={quit}
|
|
59
|
+
>
|
|
60
|
+
<GtkBox
|
|
61
|
+
orientation={Gtk.Orientation.VERTICAL}
|
|
62
|
+
spacing={20}
|
|
63
|
+
marginTop={40}
|
|
64
|
+
marginBottom={40}
|
|
65
|
+
marginStart={40}
|
|
66
|
+
marginEnd={40}
|
|
67
|
+
valign={Gtk.Align.CENTER}
|
|
68
|
+
halign={Gtk.Align.CENTER}
|
|
69
|
+
>
|
|
70
|
+
<GtkLabel cssClasses={["title-1"]}>Welcome to GTKX!</GtkLabel>
|
|
71
|
+
<GtkLabel cssClasses={["title-2"]}>{`Count: ${count}`}</GtkLabel>
|
|
72
|
+
<GtkButton
|
|
73
|
+
label="Increment"
|
|
74
|
+
onClicked={() => setCount((c) => c + 1)}
|
|
75
|
+
cssClasses={["suggested-action", "pill"]}
|
|
76
|
+
/>
|
|
77
|
+
</GtkBox>
|
|
78
|
+
</GtkApplicationWindow>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const App = () => (
|
|
83
|
+
<GtkApplication>
|
|
84
|
+
<Counter />
|
|
85
|
+
</GtkApplication>
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
createRoot().render(<App />);
|
|
37
89
|
```
|
|
38
90
|
|
|
39
|
-
|
|
91
|
+
This is the [`hello-world`](https://github.com/gtkx-org/gtkx/tree/main/examples/hello-world) example, with `app.tsx` and `index.tsx` combined into a single snippet. `@gtkx/gi` and `@gtkx/jsx` are per-project bindings generated by the CLI, not packages you install from npm.
|
|
40
92
|
|
|
41
|
-
##
|
|
93
|
+
## Why GTKX
|
|
42
94
|
|
|
43
|
-
|
|
95
|
+
### A declarative layer for the GNOME stack
|
|
44
96
|
|
|
45
|
-
|
|
46
|
-
| --- | --- |
|
|
47
|
-
| `pnpm build` | Build all workspace packages (runs codegen + native-build first). |
|
|
48
|
-
| `pnpm --filter <pkg> dev` | Start a package/example dev server (hot-reloading `gtkx dev`); see [Running the examples](#running-the-examples). There is no root `dev` script. |
|
|
49
|
-
| `pnpm test` | Run the Vitest workspace plus per-package test scripts. |
|
|
50
|
-
| `pnpm typecheck` | Type-check every package via `tsc -b --emitDeclarationOnly` across the reference graph. |
|
|
51
|
-
| `pnpm lint` | Full quality gate: ts-reference drift check, biome, knip (default + production), dependency-cruiser, plus per-package lint (Rust fmt/clippy on native). |
|
|
52
|
-
| `pnpm codegen` | Generate/refresh the `.gtkx` GIR and JSX binding stores consumed by other packages. |
|
|
53
|
-
| `pnpm coverage` | Aggregated v8 lcov coverage (TS) plus native Rust coverage. |
|
|
54
|
-
| `pnpm sync:ts-refs` | Rewrite TypeScript project references from `package.json` deps and format them (add `--check` to fail on drift). |
|
|
55
|
-
| `pnpm asan` / `pnpm miri` / `pnpm bench` | Native AddressSanitizer suite, Miri marshalling subset, and CodSpeed benchmarks under the headless compositor. |
|
|
56
|
-
| `pnpm release` | Build, inject README into published packages, stage native artifacts, and publish to npm. |
|
|
57
|
-
| `pnpm publish-test` | Publish to an ephemeral Verdaccio registry, then scaffold, build, typecheck, and test a consumer app end-to-end. |
|
|
97
|
+
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:
|
|
58
98
|
|
|
59
|
-
|
|
99
|
+
- a React reconciler that exposes every GObject as a JSX element,
|
|
100
|
+
- a CLI for scaffolding, development, and production builds,
|
|
101
|
+
- a dev server with Fast Refresh that patches your running UI in place,
|
|
102
|
+
- CSS-in-JS styling and high-level list, grid, and dialog components,
|
|
103
|
+
- a Testing Library-style API for querying and driving your widgets in tests,
|
|
104
|
+
- and a Model Context Protocol (MCP) server that exposes your live app to AI agents.
|
|
60
105
|
|
|
61
|
-
|
|
62
|
-
pnpm --filter @gtkx/ffi test
|
|
63
|
-
pnpm --filter @gtkx/react test
|
|
64
|
-
pnpm --filter @gtkx/cli build
|
|
65
|
-
```
|
|
106
|
+
### The full GNOME API surface
|
|
66
107
|
|
|
67
|
-
|
|
108
|
+
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.
|
|
68
109
|
|
|
69
|
-
|
|
110
|
+
### Why Node.js, and why generated bindings
|
|
70
111
|
|
|
71
|
-
|
|
72
|
-
# Counter app demonstrating the basics
|
|
73
|
-
pnpm --filter hello-world dev
|
|
112
|
+
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 the comparison in full.
|
|
74
113
|
|
|
75
|
-
|
|
76
|
-
pnpm --filter tutorial dev
|
|
114
|
+
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.
|
|
77
115
|
|
|
78
|
-
|
|
79
|
-
pnpm --filter gtk-demo dev
|
|
80
|
-
pnpm --filter gtk-demo coverage
|
|
116
|
+
At runtime, the native Rust core calls straight into the system GTK4, Adwaita, and GLib libraries through libffi, without loading libgirepository at all.
|
|
81
117
|
|
|
82
|
-
|
|
83
|
-
pnpm --filter browser dev
|
|
84
|
-
```
|
|
118
|
+
## Quick start
|
|
85
119
|
|
|
86
|
-
|
|
120
|
+
GTKX is Linux-only and needs Node.js 24 or later. See [Requirements](#requirements).
|
|
121
|
+
|
|
122
|
+
Scaffold a new app with the `create-gtkx` initializer:
|
|
87
123
|
|
|
88
124
|
```sh
|
|
89
|
-
|
|
90
|
-
pnpm --filter hello-world start
|
|
125
|
+
npm create gtkx@rc
|
|
91
126
|
```
|
|
92
127
|
|
|
93
|
-
The
|
|
128
|
+
The same command works with other package managers: `pnpm create gtkx@rc` or `yarn create gtkx@rc`.
|
|
129
|
+
|
|
130
|
+
Then run your new app:
|
|
94
131
|
|
|
95
|
-
|
|
132
|
+
```sh
|
|
133
|
+
cd my-app
|
|
134
|
+
npm run dev
|
|
135
|
+
```
|
|
96
136
|
|
|
97
|
-
|
|
98
|
-
- **Generated packages are not hand-edited.** `@gtkx/gi`, `@gtkx/jsx`, and the generated `@gtkx/gl` sources come from `@gtkx/codegen`. Change the emitters or `gtkx.config.ts` and regenerate (`pnpm codegen`); the store swap is atomic, so partial writes never appear.
|
|
99
|
-
- **GTK tests/benches need a headless display.** Running native `test`/`coverage`/`asan` or the GTK suites outside the headless wrapper fails to initialize a display; the harness provisions a Wayland compositor with software rendering. Native tests run single-threaded because GTK requires a single owning thread.
|
|
100
|
-
- **The native runtime is single-use.** All GObject/GTK mutation runs only on the single `gtkx-glib` thread; native init is one-shot and quit is terminal, so a process cannot restart the runtime. Importing `@gtkx/ffi` starts the GLib main loop and registers a process exit handler.
|
|
101
|
-
- **Project references track deps.** TypeScript references are generated from `package.json` dependency fields by `sync-ts-references`; hand-editing them is reported as drift by the `--check` run in lint. Change deps, then run `pnpm sync:ts-refs`.
|
|
102
|
-
- **`@gtkx/testing` cleanup is not automatic.** Consumers must register `cleanup()` (the e2e setup wires it into `afterEach`/`afterAll`), or leaked windows persist across tests.
|
|
103
|
-
- **The dev loop restarts via exit code 75.** The dev supervisor and runner signal restart intent purely through process exit code 75; Fast Refresh applies only to SSR-transformed project files where every export looks like a React component, otherwise the whole process restarts.
|
|
137
|
+
To go further, follow the [tutorial](https://gtkx.dev/tutorial/).
|
|
104
138
|
|
|
105
139
|
## Documentation
|
|
106
140
|
|
|
107
|
-
|
|
141
|
+
The documentation at **[gtkx.dev](https://gtkx.dev)** includes a step-by-step tutorial that builds a complete GNOME app, from scaffolding to packaging and shipping, plus guides and a full API reference.
|
|
142
|
+
|
|
143
|
+
**[Read the docs →](https://gtkx.dev/guide/why-gtkx)**
|
|
144
|
+
|
|
145
|
+
## Requirements
|
|
146
|
+
|
|
147
|
+
GTKX is Linux-only. You need:
|
|
148
|
+
|
|
149
|
+
- Linux with the GTK4 (4.20 or later), Adwaita (1.8 or later), and GLib development libraries
|
|
150
|
+
- Node.js 24 or later
|
|
151
|
+
|
|
152
|
+
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.
|
|
153
|
+
|
|
154
|
+
## Examples
|
|
155
|
+
|
|
156
|
+
Explore the [example apps](https://github.com/gtkx-org/gtkx/tree/main/examples):
|
|
157
|
+
|
|
158
|
+
- [`hello-world`](https://github.com/gtkx-org/gtkx/tree/main/examples/hello-world): the counter above.
|
|
159
|
+
- [`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.
|
|
160
|
+
- [`browser`](https://github.com/gtkx-org/gtkx/tree/main/examples/browser): a WebKitWebView-based web browser.
|
|
161
|
+
- [`tutorial`](https://github.com/gtkx-org/gtkx/tree/main/examples/tutorial): the Tasks app the documentation builds.
|
|
162
|
+
|
|
163
|
+
## Status
|
|
164
|
+
|
|
165
|
+
GTKX 1.0 is at the release candidate stage.
|
|
166
|
+
|
|
167
|
+
## Contributing
|
|
168
|
+
|
|
169
|
+
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.
|
|
108
170
|
|
|
109
|
-
|
|
110
|
-
- [`docs/rendering.md`](docs/rendering.md) — the render and event pipeline.
|
|
111
|
-
- [`docs/codegen.md`](docs/codegen.md) — the GIR/Khronos code generator and the runtime contract.
|
|
112
|
-
- [`docs/cli.md`](docs/cli.md) — the CLI and project workflow.
|
|
113
|
-
- [`docs/styling.md`](docs/styling.md) — styling, animation, and GL.
|
|
114
|
-
- [`docs/mcp.md`](docs/mcp.md) — the MCP server.
|
|
115
|
-
- [`docs/testing.md`](docs/testing.md) — the testing architecture.
|
|
116
|
-
- [`docs/build-system.md`](docs/build-system.md) — the build system and quality tooling.
|
|
171
|
+
## License
|
|
117
172
|
|
|
118
|
-
|
|
173
|
+
GTKX is licensed under [MPL-2.0](https://github.com/gtkx-org/gtkx/blob/main/LICENSE).
|
package/dist/config.d.ts
CHANGED
|
@@ -1,45 +1,86 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type DefineConfig } from "c12";
|
|
2
|
+
import { z } from "zod";
|
|
2
3
|
export declare const LIBRARIES_WILDCARD = "*";
|
|
3
|
-
export declare const
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export type ReactCompilerCompilationMode = "infer" | "syntax" | "annotation" | "all";
|
|
11
|
-
export type ReactCompilerPanicThreshold = "none" | "critical_errors" | "all_errors";
|
|
12
|
-
export type ReactCompilerOptions = {
|
|
4
|
+
export declare const GIR_LIBRARY_PATTERN: RegExp;
|
|
5
|
+
export declare const isValidApplicationId: (applicationId: string) => boolean;
|
|
6
|
+
declare const COMPILATION_MODES: readonly ["infer", "syntax", "annotation", "all"];
|
|
7
|
+
declare const PANIC_THRESHOLDS: readonly ["none", "critical_errors", "all_errors"];
|
|
8
|
+
type ReactCompilerCompilationMode = (typeof COMPILATION_MODES)[number];
|
|
9
|
+
type ReactCompilerPanicThreshold = (typeof PANIC_THRESHOLDS)[number];
|
|
10
|
+
type ReactCompilerOptions = {
|
|
13
11
|
compilationMode?: ReactCompilerCompilationMode;
|
|
14
12
|
panicThreshold?: ReactCompilerPanicThreshold;
|
|
15
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* React Compiler options resolved for the build, with the compilation target
|
|
16
|
+
* fixed to React 19.
|
|
17
|
+
*/
|
|
16
18
|
export type ResolvedReactCompilerOptions = ReactCompilerOptions & {
|
|
17
19
|
target: "19";
|
|
18
20
|
};
|
|
19
|
-
export declare const resolveReactCompilerOptions: (setting:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
21
|
+
export declare const resolveReactCompilerOptions: (setting: Config["reactCompiler"]) => ResolvedReactCompilerOptions | null;
|
|
22
|
+
declare const configSchema: z.ZodObject<{
|
|
23
|
+
libraries: z.ZodOptional<z.ZodCustom<"*" | string[], "*" | string[]>>;
|
|
24
|
+
girPath: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
25
|
+
applicationId: z.ZodCustom<string, string>;
|
|
26
|
+
elementProps: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
27
|
+
kind: z.ZodLiteral<"container">;
|
|
28
|
+
prop: z.ZodString;
|
|
29
|
+
child: z.ZodString;
|
|
30
|
+
append: z.ZodOptional<z.ZodCustom<import("./element-props.js").Call, import("./element-props.js").Call>>;
|
|
31
|
+
remove: z.ZodOptional<z.ZodCustom<import("./element-props.js").Call, import("./element-props.js").Call>>;
|
|
32
|
+
insert: z.ZodOptional<z.ZodCustom<import("./element-props.js").Call, import("./element-props.js").Call>>;
|
|
33
|
+
reorder: z.ZodOptional<z.ZodCustom<import("./element-props.js").Call, import("./element-props.js").Call>>;
|
|
34
|
+
autowrap: z.ZodOptional<z.ZodString>;
|
|
35
|
+
adopt: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodString]>>;
|
|
36
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
37
|
+
kind: z.ZodLiteral<"value">;
|
|
38
|
+
prop: z.ZodString;
|
|
39
|
+
call: z.ZodCustom<import("./element-props.js").Call, import("./element-props.js").Call>;
|
|
40
|
+
after: z.ZodOptional<z.ZodString>;
|
|
41
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
42
|
+
kind: z.ZodLiteral<"controlled-text">;
|
|
43
|
+
prop: z.ZodString;
|
|
44
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
45
|
+
kind: z.ZodLiteral<"lazy">;
|
|
46
|
+
prop: z.ZodString;
|
|
47
|
+
lookup: z.ZodOptional<z.ZodString>;
|
|
48
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
49
|
+
kind: z.ZodLiteral<"list">;
|
|
50
|
+
prop: z.ZodString;
|
|
51
|
+
add: z.ZodUnion<readonly [z.ZodCustom<import("./element-props.js").Call, import("./element-props.js").Call>, z.ZodArray<z.ZodCustom<import("./element-props.js").Call, import("./element-props.js").Call>>]>;
|
|
52
|
+
remove: z.ZodOptional<z.ZodCustom<import("./element-props.js").Call, import("./element-props.js").Call>>;
|
|
53
|
+
clear: z.ZodOptional<z.ZodCustom<import("./element-props.js").Call, import("./element-props.js").Call>>;
|
|
54
|
+
}, z.core.$strict>], "kind">>>>;
|
|
55
|
+
reactCompiler: z.ZodOptional<z.ZodCustom<boolean | ReactCompilerOptions, boolean | ReactCompilerOptions>>;
|
|
56
|
+
codegen: z.ZodOptional<z.ZodBoolean>;
|
|
57
|
+
}, z.core.$strip>;
|
|
58
|
+
/**
|
|
59
|
+
* User-facing configuration for a GTKX project, as authored in `gtkx.config.ts`:
|
|
60
|
+
* the GIR libraries to bind, extra `.gir` search paths, the GApplication id,
|
|
61
|
+
* custom element prop mappings, and the React Compiler and codegen settings.
|
|
62
|
+
*/
|
|
63
|
+
export type Config = z.infer<typeof configSchema>;
|
|
64
|
+
export declare const validateConfig: (config: Config) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Identity helper that returns the given configuration typed as {@link Config},
|
|
67
|
+
* enabling editor autocompletion and type checking in `gtkx.config.ts`.
|
|
68
|
+
*/
|
|
69
|
+
export declare const defineConfig: DefineConfig<Config>;
|
|
70
|
+
/**
|
|
71
|
+
* Deep-merges two configurations, with `override` taking precedence over `base`.
|
|
72
|
+
* @param base The lower-priority configuration.
|
|
73
|
+
* @param override The higher-priority configuration whose values win on conflict.
|
|
74
|
+
*/
|
|
75
|
+
export declare const mergeConfig: (base: Config, override: Config) => Config;
|
|
76
|
+
/**
|
|
77
|
+
* Configuration reduced to the values needed at runtime: the GApplication
|
|
78
|
+
* identifier and the resolved React Compiler options (`null` when disabled).
|
|
79
|
+
*/
|
|
80
|
+
export type ResolvedConfig = {
|
|
81
|
+
applicationId: string;
|
|
42
82
|
reactCompiler: ResolvedReactCompilerOptions | null;
|
|
43
83
|
};
|
|
44
|
-
export declare const
|
|
84
|
+
export declare const resolveConfig: (config: Config) => ResolvedConfig;
|
|
85
|
+
export {};
|
|
45
86
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,KAAK,CAAC;AAE5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC,eAAO,MAAM,mBAAmB,EAAE,MAA+C,CAAC;AAKlF,eAAO,MAAM,oBAAoB,kBAAmB,MAAM,KAAG,OAK5D,CAAC;AAEF,QAAA,MAAM,iBAAiB,YAAI,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,CAAU,CAAC;AAE5E,QAAA,MAAM,gBAAgB,YAAI,MAAM,EAA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
|
|
4
|
+
import { configError, elementPropsSchema, isRecord, rawIssue } from "./element-props.js";
|
|
3
5
|
export const LIBRARIES_WILDCARD = "*";
|
|
4
|
-
export const
|
|
6
|
+
export const GIR_LIBRARY_PATTERN = /^[A-Za-z][A-Za-z0-9]*-\d+(?:\.\d+)*$/;
|
|
7
|
+
const APPLICATION_ID_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]*(\.[A-Za-z_][A-Za-z0-9_-]*)+$/;
|
|
8
|
+
const APPLICATION_ID_MAX_LENGTH = 255;
|
|
9
|
+
export const isValidApplicationId = (applicationId) => {
|
|
10
|
+
if (applicationId.length === 0 || applicationId.length > APPLICATION_ID_MAX_LENGTH) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return APPLICATION_ID_PATTERN.test(applicationId);
|
|
14
|
+
};
|
|
15
|
+
const COMPILATION_MODES = ["infer", "syntax", "annotation", "all"];
|
|
16
|
+
const PANIC_THRESHOLDS = ["none", "critical_errors", "all_errors"];
|
|
5
17
|
const REACT_COMPILER_TARGET = "19";
|
|
6
18
|
export const resolveReactCompilerOptions = (setting) => {
|
|
7
19
|
if (setting === false)
|
|
@@ -9,96 +21,77 @@ export const resolveReactCompilerOptions = (setting) => {
|
|
|
9
21
|
const overrides = setting === undefined || setting === true ? {} : setting;
|
|
10
22
|
return { ...overrides, target: REACT_COMPILER_TARGET };
|
|
11
23
|
};
|
|
12
|
-
const
|
|
13
|
-
|
|
24
|
+
const COMPILATION_MODE_SET = new Set(COMPILATION_MODES);
|
|
25
|
+
const PANIC_THRESHOLD_SET = new Set(PANIC_THRESHOLDS);
|
|
26
|
+
const librariesSchema = z.custom().check((ctx) => {
|
|
27
|
+
const value = ctx.value;
|
|
28
|
+
if (value === LIBRARIES_WILDCARD)
|
|
14
29
|
return;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
throw new Error('gtkx.config.ts: to generate every library, set `libraries: "*"` as a bare string, not an array entry');
|
|
18
|
-
}
|
|
19
|
-
throw new Error(`gtkx.config.ts: invalid library identifier "${String(library)}" — must be of the form "Name-Version" (e.g. "Gtk-4.0")`);
|
|
20
|
-
};
|
|
21
|
-
const validateLibraries = (libraries) => {
|
|
22
|
-
if (libraries === undefined || libraries === LIBRARIES_WILDCARD) {
|
|
30
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
31
|
+
ctx.issues.push(rawIssue(value, [], `must be "${LIBRARIES_WILDCARD}", a non-empty string array, or omitted`));
|
|
23
32
|
return;
|
|
24
33
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
value.forEach((entry, index) => {
|
|
35
|
+
if (typeof entry === "string" && GIR_LIBRARY_PATTERN.test(entry))
|
|
36
|
+
return;
|
|
37
|
+
if (entry === LIBRARIES_WILDCARD) {
|
|
38
|
+
ctx.issues.push(rawIssue(value, [index], `to generate every library, set \`libraries: "${LIBRARIES_WILDCARD}"\` as a bare string, not an array entry`, true));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
ctx.issues.push(rawIssue(value, [index], `invalid library identifier "${String(entry)}", must be of the form "Name-Version" (e.g. "Gtk-4.0")`, true));
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
const applicationIdSchema = z.custom().check((ctx) => {
|
|
45
|
+
const value = ctx.value;
|
|
46
|
+
if (typeof value !== "string" || !isValidApplicationId(value)) {
|
|
47
|
+
ctx.issues.push(rawIssue(value, [], `invalid \`applicationId\` "${String(value)}", must satisfy g_application_id_is_valid (e.g. "org.example.MyApp")`, true));
|
|
35
48
|
}
|
|
36
|
-
};
|
|
37
|
-
const
|
|
38
|
-
|
|
49
|
+
});
|
|
50
|
+
const reactCompilerSchema = z.custom().check((ctx) => {
|
|
51
|
+
const value = ctx.value;
|
|
52
|
+
if (typeof value === "boolean")
|
|
39
53
|
return;
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
`must satisfy g_application_id_is_valid (e.g. "org.example.MyApp")`);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
const REACT_COMPILER_COMPILATION_MODES = ["infer", "syntax", "annotation", "all"];
|
|
46
|
-
const REACT_COMPILER_PANIC_THRESHOLDS = ["none", "critical_errors", "all_errors"];
|
|
47
|
-
const validateReactCompilerEnum = (value, allowed, field) => {
|
|
48
|
-
if (value !== undefined && !allowed.includes(value)) {
|
|
49
|
-
throw new Error(`gtkx.config.ts: invalid \`reactCompiler.${field}\` "${String(value)}" — must be one of ${allowed.join(", ")}`);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
const validateReactCompiler = (reactCompiler) => {
|
|
53
|
-
if (reactCompiler === undefined || typeof reactCompiler === "boolean")
|
|
54
|
+
if (!isRecord(value)) {
|
|
55
|
+
ctx.issues.push(rawIssue(value, [], "must be a boolean or an options object"));
|
|
54
56
|
return;
|
|
55
|
-
if (typeof reactCompiler !== "object" || reactCompiler === null || Array.isArray(reactCompiler)) {
|
|
56
|
-
throw new Error("gtkx.config.ts: `reactCompiler` must be a boolean or an options object");
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
validateObjectPropRows(config.objectProps);
|
|
68
|
-
validateVirtualPropRows(config.virtualProps);
|
|
69
|
-
validateElementMap(config.elementMap);
|
|
70
|
-
validateReactCompiler(config.reactCompiler);
|
|
71
|
-
};
|
|
72
|
-
export function defineConfig(config) {
|
|
73
|
-
return config;
|
|
74
|
-
}
|
|
75
|
-
const isMergeableObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
76
|
-
const mergeConfigValue = (base, override) => {
|
|
77
|
-
if (override === undefined)
|
|
78
|
-
return base;
|
|
79
|
-
if (base === undefined)
|
|
80
|
-
return override;
|
|
81
|
-
if (Array.isArray(base) && Array.isArray(override))
|
|
82
|
-
return [...base, ...override];
|
|
83
|
-
if (isMergeableObject(base) && isMergeableObject(override)) {
|
|
84
|
-
const merged = { ...base };
|
|
85
|
-
for (const key of Object.keys(override)) {
|
|
86
|
-
merged[key] = mergeConfigValue(base[key], override[key]);
|
|
87
|
-
}
|
|
88
|
-
return merged;
|
|
58
|
+
const compilationMode = value.compilationMode;
|
|
59
|
+
if (compilationMode !== undefined &&
|
|
60
|
+
!(typeof compilationMode === "string" && COMPILATION_MODE_SET.has(compilationMode))) {
|
|
61
|
+
ctx.issues.push(rawIssue(value, [], `invalid \`reactCompiler.compilationMode\` "${String(compilationMode)}", must be one of ${COMPILATION_MODES.join(", ")}`, true));
|
|
62
|
+
}
|
|
63
|
+
const panicThreshold = value.panicThreshold;
|
|
64
|
+
if (panicThreshold !== undefined &&
|
|
65
|
+
!(typeof panicThreshold === "string" && PANIC_THRESHOLD_SET.has(panicThreshold))) {
|
|
66
|
+
ctx.issues.push(rawIssue(value, [], `invalid \`reactCompiler.panicThreshold\` "${String(panicThreshold)}", must be one of ${PANIC_THRESHOLDS.join(", ")}`, true));
|
|
89
67
|
}
|
|
90
|
-
|
|
68
|
+
});
|
|
69
|
+
const configSchema = z.object({
|
|
70
|
+
libraries: librariesSchema.optional(),
|
|
71
|
+
girPath: z.array(z.string(), { error: "must be an array of strings if provided" }).optional(),
|
|
72
|
+
applicationId: applicationIdSchema,
|
|
73
|
+
elementProps: elementPropsSchema.optional(),
|
|
74
|
+
reactCompiler: reactCompilerSchema.optional(),
|
|
75
|
+
codegen: z.boolean({ error: "must be a boolean" }).optional(),
|
|
76
|
+
});
|
|
77
|
+
export const validateConfig = (config) => {
|
|
78
|
+
const result = configSchema.safeParse(config);
|
|
79
|
+
if (!result.success)
|
|
80
|
+
throw configError(result.error);
|
|
91
81
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Identity helper that returns the given configuration typed as {@link Config},
|
|
84
|
+
* enabling editor autocompletion and type checking in `gtkx.config.ts`.
|
|
85
|
+
*/
|
|
86
|
+
export const defineConfig = createDefineConfig();
|
|
87
|
+
/**
|
|
88
|
+
* Deep-merges two configurations, with `override` taking precedence over `base`.
|
|
89
|
+
* @param base The lower-priority configuration.
|
|
90
|
+
* @param override The higher-priority configuration whose values win on conflict.
|
|
91
|
+
*/
|
|
92
|
+
export const mergeConfig = (base, override) => defu(override, base);
|
|
93
|
+
export const resolveConfig = (config) => ({
|
|
96
94
|
applicationId: config.applicationId,
|
|
97
|
-
containerProps: config.containerProps ?? {},
|
|
98
|
-
arrayProps: config.arrayProps ?? {},
|
|
99
|
-
objectProps: config.objectProps ?? {},
|
|
100
|
-
virtualProps: config.virtualProps ?? {},
|
|
101
|
-
elementMap: config.elementMap ?? [],
|
|
102
95
|
reactCompiler: resolveReactCompilerOptions(config.reactCompiler),
|
|
103
96
|
});
|
|
104
97
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAQH,qBAAqB,EACrB,yBAAyB,EACzB,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,GAC1B,MAAM,mBAAmB,CAAC;AAE3B,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAEtC,MAAM,CAAC,MAAM,qBAAqB,GAAW,sCAAsC,CAAC;AAyBpF,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAEnC,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACvC,OAAoC,EACD,EAAE;IACrC,IAAI,OAAO,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IACnC,MAAM,SAAS,GAAG,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,CAAC,CAAC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AC;AACL,CAAC,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1B,SAAS,EAAE,eAAe,CAAC,QAAQ,EAAE;IACrC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,yCAAyC,EAAE,CAAC,CAAC,QAAQ,EAAE;IAC7F,aAAa,EAAE,mBAAmB;IAClC,YAAY,EAAE,kBAAkB,CAAC,QAAQ,EAAE;IAC3C,aAAa,EAAE,mBAAmB,CAAC,QAAQ,EAAE;IAC7C,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,mBAAmB,EAAE,CAAC,CAAC,QAAQ,EAAE;CAChE,CAAC,CAAC;AASH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAc,EAAQ,EAAE;IACnD,MAAM,MAAM,GAAG,YAAY,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC9C,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,MAAM,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAyB,kBAAkB,EAAU,CAAC;AAE/E;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,QAAgB,EAAU,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAW5F,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAc,EAAkB,EAAE,CAAC,CAAC;IAC9D,aAAa,EAAE,MAAM,CAAC,aAAa;IACnC,aAAa,EAAE,2BAA2B,CAAC,MAAM,CAAC,aAAa,CAAC;CACnE,CAAC,CAAC","sourcesContent":["import { createDefineConfig, type DefineConfig } from \"c12\";\nimport { defu } from \"defu\";\nimport { z } from \"zod\";\nimport { configError, elementPropsSchema, isRecord, rawIssue } from \"./element-props.js\";\n\nexport const LIBRARIES_WILDCARD = \"*\";\n\nexport const GIR_LIBRARY_PATTERN: RegExp = /^[A-Za-z][A-Za-z0-9]*-\\d+(?:\\.\\d+)*$/;\n\nconst APPLICATION_ID_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]*(\\.[A-Za-z_][A-Za-z0-9_-]*)+$/;\nconst APPLICATION_ID_MAX_LENGTH = 255;\n\nexport const isValidApplicationId = (applicationId: string): boolean => {\n if (applicationId.length === 0 || applicationId.length > APPLICATION_ID_MAX_LENGTH) {\n return false;\n }\n return APPLICATION_ID_PATTERN.test(applicationId);\n};\n\nconst COMPILATION_MODES = [\"infer\", \"syntax\", \"annotation\", \"all\"] as const;\n\nconst PANIC_THRESHOLDS = [\"none\", \"critical_errors\", \"all_errors\"] as const;\n\ntype ReactCompilerCompilationMode = (typeof COMPILATION_MODES)[number];\n\ntype ReactCompilerPanicThreshold = (typeof PANIC_THRESHOLDS)[number];\n\ntype ReactCompilerOptions = {\n compilationMode?: ReactCompilerCompilationMode;\n panicThreshold?: ReactCompilerPanicThreshold;\n};\n\n/**\n * React Compiler options resolved for the build, with the compilation target\n * fixed to React 19.\n */\nexport type ResolvedReactCompilerOptions = ReactCompilerOptions & {\n target: \"19\";\n};\n\nconst REACT_COMPILER_TARGET = \"19\";\n\nexport const resolveReactCompilerOptions = (setting: Config[\"reactCompiler\"]): ResolvedReactCompilerOptions | null => {\n if (setting === false) return null;\n const overrides = setting === undefined || setting === true ? {} : setting;\n return { ...overrides, target: REACT_COMPILER_TARGET };\n};\n\nconst COMPILATION_MODE_SET: Set<string> = new Set(COMPILATION_MODES);\n\nconst PANIC_THRESHOLD_SET: Set<string> = new Set(PANIC_THRESHOLDS);\n\nconst librariesSchema = z.custom<typeof LIBRARIES_WILDCARD | string[]>().check((ctx) => {\n const value = ctx.value;\n if (value === LIBRARIES_WILDCARD) return;\n if (!Array.isArray(value) || value.length === 0) {\n ctx.issues.push(rawIssue(value, [], `must be \"${LIBRARIES_WILDCARD}\", a non-empty string array, or omitted`));\n return;\n }\n value.forEach((entry, index) => {\n if (typeof entry === \"string\" && GIR_LIBRARY_PATTERN.test(entry)) return;\n if (entry === LIBRARIES_WILDCARD) {\n ctx.issues.push(\n rawIssue(\n value,\n [index],\n `to generate every library, set \\`libraries: \"${LIBRARIES_WILDCARD}\"\\` as a bare string, not an array entry`,\n true,\n ),\n );\n return;\n }\n ctx.issues.push(\n rawIssue(\n value,\n [index],\n `invalid library identifier \"${String(entry)}\", must be of the form \"Name-Version\" (e.g. \"Gtk-4.0\")`,\n true,\n ),\n );\n });\n});\n\nconst applicationIdSchema = z.custom<string>().check((ctx) => {\n const value = ctx.value;\n if (typeof value !== \"string\" || !isValidApplicationId(value)) {\n ctx.issues.push(\n rawIssue(\n value,\n [],\n `invalid \\`applicationId\\` \"${String(value)}\", must satisfy g_application_id_is_valid (e.g. \"org.example.MyApp\")`,\n true,\n ),\n );\n }\n});\n\nconst reactCompilerSchema = z.custom<boolean | ReactCompilerOptions>().check((ctx) => {\n const value = ctx.value;\n if (typeof value === \"boolean\") return;\n if (!isRecord(value)) {\n ctx.issues.push(rawIssue(value, [], \"must be a boolean or an options object\"));\n return;\n }\n const compilationMode = value.compilationMode;\n if (\n compilationMode !== undefined &&\n !(typeof compilationMode === \"string\" && COMPILATION_MODE_SET.has(compilationMode))\n ) {\n ctx.issues.push(\n rawIssue(\n value,\n [],\n `invalid \\`reactCompiler.compilationMode\\` \"${String(compilationMode)}\", must be one of ${COMPILATION_MODES.join(\", \")}`,\n true,\n ),\n );\n }\n const panicThreshold = value.panicThreshold;\n if (\n panicThreshold !== undefined &&\n !(typeof panicThreshold === \"string\" && PANIC_THRESHOLD_SET.has(panicThreshold))\n ) {\n ctx.issues.push(\n rawIssue(\n value,\n [],\n `invalid \\`reactCompiler.panicThreshold\\` \"${String(panicThreshold)}\", must be one of ${PANIC_THRESHOLDS.join(\", \")}`,\n true,\n ),\n );\n }\n});\n\nconst configSchema = z.object({\n libraries: librariesSchema.optional(),\n girPath: z.array(z.string(), { error: \"must be an array of strings if provided\" }).optional(),\n applicationId: applicationIdSchema,\n elementProps: elementPropsSchema.optional(),\n reactCompiler: reactCompilerSchema.optional(),\n codegen: z.boolean({ error: \"must be a boolean\" }).optional(),\n});\n\n/**\n * User-facing configuration for a GTKX project, as authored in `gtkx.config.ts`:\n * the GIR libraries to bind, extra `.gir` search paths, the GApplication id,\n * custom element prop mappings, and the React Compiler and codegen settings.\n */\nexport type Config = z.infer<typeof configSchema>;\n\nexport const validateConfig = (config: Config): void => {\n const result = configSchema.safeParse(config);\n if (!result.success) throw configError(result.error);\n};\n\n/**\n * Identity helper that returns the given configuration typed as {@link Config},\n * enabling editor autocompletion and type checking in `gtkx.config.ts`.\n */\nexport const defineConfig: DefineConfig<Config> = createDefineConfig<Config>();\n\n/**\n * Deep-merges two configurations, with `override` taking precedence over `base`.\n * @param base The lower-priority configuration.\n * @param override The higher-priority configuration whose values win on conflict.\n */\nexport const mergeConfig = (base: Config, override: Config): Config => defu(override, base);\n\n/**\n * Configuration reduced to the values needed at runtime: the GApplication\n * identifier and the resolved React Compiler options (`null` when disabled).\n */\nexport type ResolvedConfig = {\n applicationId: string;\n reactCompiler: ResolvedReactCompilerOptions | null;\n};\n\nexport const resolveConfig = (config: Config): ResolvedConfig => ({\n applicationId: config.applicationId,\n reactCompiler: resolveReactCompilerOptions(config.reactCompiler),\n});\n"]}
|