@gtkx/cli 0.21.0 → 1.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +173 -0
- package/bin/gtkx-dev-runner.js +9 -0
- package/dist/builder.d.ts +5 -52
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +24 -57
- package/dist/builder.js.map +1 -1
- package/dist/cli.d.ts +1 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +24 -122
- package/dist/cli.js.map +1 -1
- package/dist/codegen/freshness.d.ts +11 -0
- package/dist/codegen/freshness.d.ts.map +1 -0
- package/dist/codegen/freshness.js +45 -0
- package/dist/codegen/freshness.js.map +1 -0
- package/dist/codegen/report.d.ts +4 -0
- package/dist/codegen/report.d.ts.map +1 -0
- package/dist/codegen/report.js +18 -0
- package/dist/codegen/report.js.map +1 -0
- package/dist/codegen/run-codegen.d.ts +35 -0
- package/dist/codegen/run-codegen.d.ts.map +1 -0
- package/dist/codegen/run-codegen.js +162 -0
- package/dist/codegen/run-codegen.js.map +1 -0
- package/dist/codegen/store-resolver.d.ts +24 -0
- package/dist/codegen/store-resolver.d.ts.map +1 -0
- package/dist/codegen/store-resolver.js +72 -0
- package/dist/codegen/store-resolver.js.map +1 -0
- package/dist/commands/build.d.ts +10 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +34 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/codegen.d.ts +10 -0
- package/dist/commands/codegen.d.ts.map +1 -0
- package/dist/commands/codegen.js +42 -0
- package/dist/commands/codegen.js.map +1 -0
- package/dist/commands/dev.d.ts +6 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +22 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/docs.d.ts +20 -0
- package/dist/commands/docs.d.ts.map +1 -0
- package/dist/commands/docs.js +74 -0
- package/dist/commands/docs.js.map +1 -0
- package/dist/dev/icon-dir.d.ts +3 -0
- package/dist/dev/icon-dir.d.ts.map +1 -0
- package/dist/dev/icon-dir.js +16 -0
- package/dist/dev/icon-dir.js.map +1 -0
- package/dist/dev/refresh-tracker.d.ts +7 -0
- package/dist/dev/refresh-tracker.d.ts.map +1 -0
- package/dist/dev/refresh-tracker.js +19 -0
- package/dist/dev/refresh-tracker.js.map +1 -0
- package/dist/dev/runner-deps.d.ts +4 -0
- package/dist/dev/runner-deps.d.ts.map +1 -0
- package/dist/dev/runner-deps.js +55 -0
- package/dist/dev/runner-deps.js.map +1 -0
- package/dist/dev/runner-main.d.ts +3 -0
- package/dist/dev/runner-main.d.ts.map +1 -0
- package/dist/dev/runner-main.js +29 -0
- package/dist/dev/runner-main.js.map +1 -0
- package/dist/dev/runner.d.ts +24 -0
- package/dist/dev/runner.d.ts.map +1 -0
- package/dist/dev/runner.js +119 -0
- package/dist/dev/runner.js.map +1 -0
- package/dist/dev/schema-dir.d.ts +3 -0
- package/dist/dev/schema-dir.d.ts.map +1 -0
- package/dist/dev/schema-dir.js +12 -0
- package/dist/dev/schema-dir.js.map +1 -0
- package/dist/dev/supervisor.d.ts +18 -0
- package/dist/dev/supervisor.d.ts.map +1 -0
- package/dist/dev/supervisor.js +182 -0
- package/dist/dev/supervisor.js.map +1 -0
- package/dist/dev/vite-dev-server.d.ts +21 -0
- package/dist/dev/vite-dev-server.d.ts.map +1 -0
- package/dist/dev/vite-dev-server.js +13 -0
- package/dist/dev/vite-dev-server.js.map +1 -0
- package/dist/internal/banner.d.ts +4 -0
- package/dist/internal/banner.d.ts.map +1 -0
- package/dist/internal/banner.js +9 -0
- package/dist/internal/banner.js.map +1 -0
- package/dist/internal/data-dir.d.ts +4 -0
- package/dist/internal/data-dir.d.ts.map +1 -0
- package/dist/internal/data-dir.js +52 -0
- package/dist/internal/data-dir.js.map +1 -0
- package/dist/internal/entry-arg.d.ts +20 -0
- package/dist/internal/entry-arg.d.ts.map +1 -0
- package/dist/internal/entry-arg.js +36 -0
- package/dist/internal/entry-arg.js.map +1 -0
- package/dist/internal/errors.d.ts +5 -0
- package/dist/internal/errors.d.ts.map +1 -0
- package/dist/internal/errors.js +29 -0
- package/dist/internal/errors.js.map +1 -0
- package/dist/internal/list-files.d.ts +7 -0
- package/dist/internal/list-files.d.ts.map +1 -0
- package/dist/internal/list-files.js +15 -0
- package/dist/internal/list-files.js.map +1 -0
- package/dist/internal/resolve-cli-tool.d.ts +3 -0
- package/dist/internal/resolve-cli-tool.d.ts.map +1 -0
- package/dist/internal/resolve-cli-tool.js +27 -0
- package/dist/internal/resolve-cli-tool.js.map +1 -0
- package/dist/internal/staging-dir.d.ts +4 -0
- package/dist/internal/staging-dir.d.ts.map +1 -0
- package/dist/internal/staging-dir.js +17 -0
- package/dist/internal/staging-dir.js.map +1 -0
- package/dist/internal/xdg-data-dirs.d.ts +3 -0
- package/dist/internal/xdg-data-dirs.d.ts.map +1 -0
- package/dist/internal/xdg-data-dirs.js +10 -0
- package/dist/internal/xdg-data-dirs.js.map +1 -0
- package/dist/mcp/client.d.ts +28 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +182 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/handlers.d.ts +9 -0
- package/dist/mcp/handlers.d.ts.map +1 -0
- package/dist/mcp/handlers.js +147 -0
- package/dist/mcp/handlers.js.map +1 -0
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +34 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/serialize-widget.d.ts +10 -0
- package/dist/mcp/serialize-widget.d.ts.map +1 -0
- package/dist/mcp/serialize-widget.js +23 -0
- package/dist/mcp/serialize-widget.js.map +1 -0
- package/dist/mcp/testing-loader.d.ts +5 -0
- package/dist/mcp/testing-loader.d.ts.map +1 -0
- package/dist/mcp/testing-loader.js +47 -0
- package/dist/mcp/testing-loader.js.map +1 -0
- package/dist/mcp/widget-registry.d.ts +14 -0
- package/dist/mcp/widget-registry.d.ts.map +1 -0
- package/dist/mcp/widget-registry.js +39 -0
- package/dist/mcp/widget-registry.js.map +1 -0
- package/dist/refresh-globals.d.ts +2 -0
- package/dist/refresh-globals.d.ts.map +1 -0
- package/dist/refresh-globals.js +8 -0
- package/dist/refresh-globals.js.map +1 -0
- package/dist/refresh-runtime.d.ts +10 -26
- package/dist/refresh-runtime.d.ts.map +1 -1
- package/dist/refresh-runtime.js +26 -48
- package/dist/refresh-runtime.js.map +1 -1
- package/dist/settings/compile.d.ts +3 -0
- package/dist/settings/compile.d.ts.map +1 -0
- package/dist/settings/compile.js +21 -0
- package/dist/settings/compile.js.map +1 -0
- package/dist/settings/parser.d.ts +24 -0
- package/dist/settings/parser.d.ts.map +1 -0
- package/dist/settings/parser.js +121 -0
- package/dist/settings/parser.js.map +1 -0
- package/dist/settings/render.d.ts +5 -0
- package/dist/settings/render.d.ts.map +1 -0
- package/dist/settings/render.js +122 -0
- package/dist/settings/render.js.map +1 -0
- package/dist/settings/schema.d.ts +13 -0
- package/dist/settings/schema.d.ts.map +1 -0
- package/dist/settings/schema.js +121 -0
- package/dist/settings/schema.js.map +1 -0
- package/dist/vite-plugins/asset-extensions.d.ts +5 -0
- package/dist/vite-plugins/asset-extensions.d.ts.map +1 -0
- package/dist/vite-plugins/asset-extensions.js +28 -0
- package/dist/vite-plugins/asset-extensions.js.map +1 -0
- package/dist/vite-plugins/built-url.d.ts +4 -0
- package/dist/vite-plugins/built-url.d.ts.map +1 -0
- package/dist/vite-plugins/built-url.js +36 -0
- package/dist/vite-plugins/built-url.js.map +1 -0
- package/dist/vite-plugins/css.d.ts +4 -0
- package/dist/vite-plugins/css.d.ts.map +1 -0
- package/dist/vite-plugins/css.js +38 -0
- package/dist/vite-plugins/css.js.map +1 -0
- package/dist/vite-plugins/fast-refresh/refresh-filter.d.ts +8 -0
- package/dist/vite-plugins/fast-refresh/refresh-filter.d.ts.map +1 -0
- package/dist/vite-plugins/fast-refresh/refresh-filter.js +19 -0
- package/dist/vite-plugins/fast-refresh/refresh-filter.js.map +1 -0
- package/dist/vite-plugins/fast-refresh/swc-refresh.d.ts +6 -0
- package/dist/vite-plugins/fast-refresh/swc-refresh.d.ts.map +1 -0
- package/dist/vite-plugins/fast-refresh/swc-refresh.js +70 -0
- package/dist/vite-plugins/fast-refresh/swc-refresh.js.map +1 -0
- package/dist/vite-plugins/icons.d.ts +4 -0
- package/dist/vite-plugins/icons.d.ts.map +1 -0
- package/dist/vite-plugins/icons.js +51 -0
- package/dist/vite-plugins/icons.js.map +1 -0
- package/dist/vite-plugins/index.d.ts +4 -0
- package/dist/vite-plugins/index.d.ts.map +1 -0
- package/dist/vite-plugins/index.js +22 -0
- package/dist/vite-plugins/index.js.map +1 -0
- package/dist/vite-plugins/native.d.ts +4 -0
- package/dist/vite-plugins/native.d.ts.map +1 -0
- package/dist/vite-plugins/native.js +62 -0
- package/dist/vite-plugins/native.js.map +1 -0
- package/dist/vite-plugins/react-compiler.d.ts +5 -0
- package/dist/vite-plugins/react-compiler.d.ts.map +1 -0
- package/dist/vite-plugins/react-compiler.js +62 -0
- package/dist/vite-plugins/react-compiler.js.map +1 -0
- package/dist/vite-plugins/react-dom-prebundle.d.ts +4 -0
- package/dist/vite-plugins/react-dom-prebundle.d.ts.map +1 -0
- package/dist/vite-plugins/react-dom-prebundle.js +12 -0
- package/dist/vite-plugins/react-dom-prebundle.js.map +1 -0
- package/dist/vite-plugins/resource-init-module.d.ts +6 -0
- package/dist/vite-plugins/resource-init-module.d.ts.map +1 -0
- package/dist/vite-plugins/resource-init-module.js +51 -0
- package/dist/vite-plugins/resource-init-module.js.map +1 -0
- package/dist/vite-plugins/resource-shared.d.ts +8 -0
- package/dist/vite-plugins/resource-shared.d.ts.map +1 -0
- package/dist/vite-plugins/resource-shared.js +28 -0
- package/dist/vite-plugins/resource-shared.js.map +1 -0
- package/dist/vite-plugins/resources.d.ts +5 -0
- package/dist/vite-plugins/resources.d.ts.map +1 -0
- package/dist/vite-plugins/resources.js +260 -0
- package/dist/vite-plugins/resources.js.map +1 -0
- package/dist/vite-plugins/settings-worker-env.d.ts +4 -0
- package/dist/vite-plugins/settings-worker-env.d.ts.map +1 -0
- package/dist/vite-plugins/settings-worker-env.js +23 -0
- package/dist/vite-plugins/settings-worker-env.js.map +1 -0
- package/dist/vite-plugins/settings.d.ts +4 -0
- package/dist/vite-plugins/settings.d.ts.map +1 -0
- package/dist/vite-plugins/settings.js +214 -0
- package/dist/vite-plugins/settings.js.map +1 -0
- package/dist/vite-plugins/strip-query.d.ts +3 -0
- package/dist/vite-plugins/strip-query.d.ts.map +1 -0
- package/dist/vite-plugins/strip-query.js +6 -0
- package/dist/vite-plugins/strip-query.js.map +1 -0
- package/dist/vite-plugins/undeclared-library.d.ts +4 -0
- package/dist/vite-plugins/undeclared-library.d.ts.map +1 -0
- package/dist/vite-plugins/undeclared-library.js +50 -0
- package/dist/vite-plugins/undeclared-library.js.map +1 -0
- package/dist/vite-plugins/virtual-module.d.ts +22 -0
- package/dist/vite-plugins/virtual-module.d.ts.map +1 -0
- package/dist/vite-plugins/virtual-module.js +20 -0
- package/dist/vite-plugins/virtual-module.js.map +1 -0
- package/dist/vitest-plugin.d.ts +10 -0
- package/dist/vitest-plugin.d.ts.map +1 -0
- package/dist/vitest-plugin.js +12 -0
- package/dist/vitest-plugin.js.map +1 -0
- package/env.d.ts +91 -8
- package/package.json +30 -38
- package/src/babel-modules.d.ts +11 -0
- package/src/builder.ts +31 -86
- package/src/cli.ts +42 -0
- package/src/codegen/freshness.ts +65 -0
- package/src/codegen/report.ts +28 -0
- package/src/codegen/run-codegen.ts +260 -0
- package/src/codegen/store-resolver.ts +116 -0
- package/src/commands/build.ts +38 -0
- package/src/commands/codegen.ts +49 -0
- package/src/commands/dev.ts +24 -0
- package/src/commands/docs.ts +95 -0
- package/src/dev/icon-dir.ts +21 -0
- package/src/dev/refresh-tracker.ts +25 -0
- package/src/dev/runner-deps.ts +65 -0
- package/src/dev/runner-main.ts +34 -0
- package/src/dev/runner.ts +185 -0
- package/src/dev/schema-dir.ts +16 -0
- package/src/dev/supervisor.ts +276 -0
- package/src/dev/vite-dev-server.ts +36 -0
- package/src/internal/banner.ts +13 -0
- package/src/internal/data-dir.ts +70 -0
- package/src/internal/entry-arg.ts +46 -0
- package/src/internal/errors.ts +36 -0
- package/src/internal/list-files.ts +23 -0
- package/src/internal/resolve-cli-tool.ts +37 -0
- package/src/internal/staging-dir.ts +19 -0
- package/src/internal/xdg-data-dirs.ts +13 -0
- package/src/mcp/client.ts +235 -0
- package/src/mcp/handlers.ts +213 -0
- package/src/mcp/index.ts +46 -0
- package/src/mcp/serialize-widget.ts +41 -0
- package/src/mcp/testing-loader.ts +73 -0
- package/src/mcp/widget-registry.ts +49 -0
- package/src/refresh-globals.ts +10 -0
- package/src/refresh-runtime.ts +30 -55
- package/src/settings/compile.ts +22 -0
- package/src/settings/parser.ts +193 -0
- package/src/settings/render.ts +167 -0
- package/src/settings/schema.ts +169 -0
- package/src/vite-plugins/asset-extensions.ts +29 -0
- package/src/vite-plugins/built-url.ts +50 -0
- package/src/vite-plugins/css.ts +53 -0
- package/src/vite-plugins/fast-refresh/refresh-filter.ts +26 -0
- package/src/vite-plugins/fast-refresh/swc-refresh.ts +92 -0
- package/src/vite-plugins/icons.ts +74 -0
- package/src/vite-plugins/index.ts +25 -0
- package/src/vite-plugins/native.ts +83 -0
- package/src/vite-plugins/react-compiler.ts +84 -0
- package/src/vite-plugins/react-dom-prebundle.ts +17 -0
- package/src/vite-plugins/resource-init-module.ts +57 -0
- package/src/vite-plugins/resource-shared.ts +40 -0
- package/src/vite-plugins/resources.ts +366 -0
- package/src/vite-plugins/settings-worker-env.ts +30 -0
- package/src/vite-plugins/settings.ts +286 -0
- package/src/vite-plugins/strip-query.ts +7 -0
- package/src/vite-plugins/undeclared-library.ts +78 -0
- package/src/vite-plugins/virtual-module.ts +44 -0
- package/src/vitest-plugin.ts +13 -0
- package/dist/create.d.ts +0 -55
- package/dist/create.d.ts.map +0 -1
- package/dist/create.js +0 -236
- package/dist/create.js.map +0 -1
- package/dist/dev-server.d.ts +0 -37
- package/dist/dev-server.d.ts.map +0 -1
- package/dist/dev-server.js +0 -130
- package/dist/dev-server.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +0 -1
- package/dist/mcp-client.d.ts +0 -31
- package/dist/mcp-client.d.ts.map +0 -1
- package/dist/mcp-client.js +0 -430
- package/dist/mcp-client.js.map +0 -1
- package/dist/templates.d.ts +0 -9
- package/dist/templates.d.ts.map +0 -1
- package/dist/templates.js +0 -16
- package/dist/templates.js.map +0 -1
- package/dist/vite-plugin-gtkx-assets.d.ts +0 -20
- package/dist/vite-plugin-gtkx-assets.d.ts.map +0 -1
- package/dist/vite-plugin-gtkx-assets.js +0 -57
- package/dist/vite-plugin-gtkx-assets.js.map +0 -1
- package/dist/vite-plugin-gtkx-built-url.d.ts +0 -18
- package/dist/vite-plugin-gtkx-built-url.d.ts.map +0 -1
- package/dist/vite-plugin-gtkx-built-url.js +0 -43
- package/dist/vite-plugin-gtkx-built-url.js.map +0 -1
- package/dist/vite-plugin-gtkx-gsettings.d.ts +0 -28
- package/dist/vite-plugin-gtkx-gsettings.d.ts.map +0 -1
- package/dist/vite-plugin-gtkx-gsettings.js +0 -147
- package/dist/vite-plugin-gtkx-gsettings.js.map +0 -1
- package/dist/vite-plugin-gtkx-native.d.ts +0 -14
- package/dist/vite-plugin-gtkx-native.d.ts.map +0 -1
- package/dist/vite-plugin-gtkx-native.js +0 -53
- package/dist/vite-plugin-gtkx-native.js.map +0 -1
- package/dist/vite-plugin-gtkx-refresh.d.ts +0 -8
- package/dist/vite-plugin-gtkx-refresh.d.ts.map +0 -1
- package/dist/vite-plugin-gtkx-refresh.js +0 -37
- package/dist/vite-plugin-gtkx-refresh.js.map +0 -1
- package/dist/vite-plugin-swc-ssr-refresh.d.ts +0 -8
- package/dist/vite-plugin-swc-ssr-refresh.d.ts.map +0 -1
- package/dist/vite-plugin-swc-ssr-refresh.js +0 -46
- package/dist/vite-plugin-swc-ssr-refresh.js.map +0 -1
- package/src/cli.tsx +0 -154
- package/src/create.ts +0 -326
- package/src/dev-server.tsx +0 -162
- package/src/index.ts +0 -3
- package/src/mcp-client.ts +0 -518
- package/src/templates.ts +0 -26
- package/src/vite-plugin-gtkx-assets.ts +0 -69
- package/src/vite-plugin-gtkx-built-url.ts +0 -48
- package/src/vite-plugin-gtkx-gsettings.ts +0 -168
- package/src/vite-plugin-gtkx-native.ts +0 -64
- package/src/vite-plugin-gtkx-refresh.ts +0 -54
- package/src/vite-plugin-swc-ssr-refresh.ts +0 -61
- package/templates/claude/EXAMPLES.md.ejs +0 -744
- package/templates/claude/SKILL.md.ejs +0 -93
- package/templates/claude/WIDGETS.md.ejs +0 -820
- package/templates/config/vitest.config.ts.ejs +0 -11
- package/templates/gitignore.ejs +0 -4
- package/templates/package.json.ejs +0 -16
- package/templates/src/app.tsx.ejs +0 -32
- package/templates/src/dev.tsx.ejs +0 -5
- package/templates/src/gtkx-env.d.ts.ejs +0 -1
- package/templates/src/index.tsx.ejs +0 -5
- package/templates/tests/app.test.tsx.ejs +0 -16
- package/templates/tsconfig.json.ejs +0 -14
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
+
class WidgetRegistry {
|
|
3
|
+
idByWidget = new WeakMap();
|
|
4
|
+
nextId = 0;
|
|
5
|
+
widgetById = new Map();
|
|
6
|
+
toplevelWindows = [];
|
|
7
|
+
refresh() {
|
|
8
|
+
this.widgetById.clear();
|
|
9
|
+
this.toplevelWindows = Gtk.Window.listToplevels();
|
|
10
|
+
for (const window of this.toplevelWindows) {
|
|
11
|
+
this.register(window);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
toplevels() {
|
|
15
|
+
return this.toplevelWindows;
|
|
16
|
+
}
|
|
17
|
+
register(widget) {
|
|
18
|
+
const id = this.getOrCreateId(widget);
|
|
19
|
+
this.widgetById.set(id, widget);
|
|
20
|
+
let child = widget.getFirstChild();
|
|
21
|
+
while (child) {
|
|
22
|
+
this.register(child);
|
|
23
|
+
child = child.getNextSibling();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
getOrCreateId(widget) {
|
|
27
|
+
let id = this.idByWidget.get(widget);
|
|
28
|
+
if (!id) {
|
|
29
|
+
id = String(this.nextId++);
|
|
30
|
+
this.idByWidget.set(widget, id);
|
|
31
|
+
}
|
|
32
|
+
return id;
|
|
33
|
+
}
|
|
34
|
+
get(id) {
|
|
35
|
+
return this.widgetById.get(id);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export { WidgetRegistry };
|
|
39
|
+
//# sourceMappingURL=widget-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget-registry.js","sourceRoot":"","sources":["../../src/mcp/widget-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAEpC,MAAM,cAAc;IACR,UAAU,GAAgC,IAAI,OAAO,EAAE,CAAC;IACxD,MAAM,GAAG,CAAC,CAAC;IACX,UAAU,GAA4B,IAAI,GAAG,EAAE,CAAC;IAChD,eAAe,GAAiB,EAAE,CAAC;IAE3C,OAAO;QACH,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,eAAe,GAAG,GAAG,CAAC,MAAM,CAAC,aAAa,EAAkB,CAAC;QAElE,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACxC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC;IACL,CAAC;IAED,SAAS;QACL,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;IAED,QAAQ,CAAC,MAAkB;QACvB,MAAM,EAAE,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAChC,IAAI,KAAK,GAAG,MAAM,CAAC,aAAa,EAAE,CAAC;QAEnC,OAAO,KAAK,EAAE,CAAC;YACX,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACrB,KAAK,GAAG,KAAK,CAAC,cAAc,EAAE,CAAC;QACnC,CAAC;IACL,CAAC;IAED,aAAa,CAAC,MAAkB;QAC5B,IAAI,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAErC,IAAI,CAAC,EAAE,EAAE,CAAC;YACN,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YAC3B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACpC,CAAC;QAED,OAAO,EAAE,CAAC;IACd,CAAC;IAED,GAAG,CAAC,EAAU;QACV,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACnC,CAAC;CACJ;AAED,OAAO,EAAE,cAAc,EAAE,CAAC","sourcesContent":["import * as Gtk from \"@gtkx/gi/gtk\";\n\nclass WidgetRegistry {\n private idByWidget: WeakMap<Gtk.Widget, string> = new WeakMap();\n private nextId = 0;\n private widgetById: Map<string, Gtk.Widget> = new Map();\n private toplevelWindows: Gtk.Window[] = [];\n\n refresh(): void {\n this.widgetById.clear();\n this.toplevelWindows = Gtk.Window.listToplevels() as Gtk.Window[];\n\n for (const window of this.toplevelWindows) {\n this.register(window);\n }\n }\n\n toplevels(): Gtk.Window[] {\n return this.toplevelWindows;\n }\n\n register(widget: Gtk.Widget): void {\n const id = this.getOrCreateId(widget);\n this.widgetById.set(id, widget);\n let child = widget.getFirstChild();\n\n while (child) {\n this.register(child);\n child = child.getNextSibling();\n }\n }\n\n getOrCreateId(widget: Gtk.Widget): string {\n let id = this.idByWidget.get(widget);\n\n if (!id) {\n id = String(this.nextId++);\n this.idByWidget.set(widget, id);\n }\n\n return id;\n }\n\n get(id: string): Gtk.Widget | undefined {\n return this.widgetById.get(id);\n }\n}\n\nexport { WidgetRegistry };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh-globals.d.ts","sourceRoot":"","sources":["../src/refresh-globals.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import RefreshRuntime from "react-refresh/runtime";
|
|
2
|
+
const identity = (type) => type;
|
|
3
|
+
RefreshRuntime.injectIntoGlobalHook(globalThis);
|
|
4
|
+
Object.assign(globalThis, {
|
|
5
|
+
$RefreshReg$: () => undefined,
|
|
6
|
+
$RefreshSig$: () => identity,
|
|
7
|
+
});
|
|
8
|
+
//# sourceMappingURL=refresh-globals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh-globals.js","sourceRoot":"","sources":["../src/refresh-globals.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,uBAAuB,CAAC;AAEnD,MAAM,QAAQ,GAAG,CAAC,IAAa,EAAW,EAAE,CAAC,IAAI,CAAC;AAElD,cAAc,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;AAEhD,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE;IACtB,YAAY,EAAE,GAAS,EAAE,CAAC,SAAS;IACnC,YAAY,EAAE,GAAG,EAAE,CAAC,QAAQ;CAC/B,CAAC,CAAC","sourcesContent":["import RefreshRuntime from \"react-refresh/runtime\";\n\nconst identity = (type: unknown): unknown => type;\n\nRefreshRuntime.injectIntoGlobalHook(globalThis);\n\nObject.assign(globalThis, {\n $RefreshReg$: (): void => undefined,\n $RefreshSig$: () => identity,\n});\n"]}
|
|
@@ -1,37 +1,21 @@
|
|
|
1
1
|
import RefreshRuntime from "react-refresh/runtime";
|
|
2
|
+
import "./refresh-globals.js";
|
|
2
3
|
type ComponentType = (...args: unknown[]) => unknown;
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
+
* Builds the per-module `$RefreshReg$` and `$RefreshSig$` hooks that React Refresh
|
|
6
|
+
* transformed code expects, scoping every registered component to the given module.
|
|
5
7
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @param moduleId - Unique identifier for the module
|
|
10
|
-
* @returns Registration functions for the module
|
|
11
|
-
* @internal
|
|
8
|
+
* @param moduleId Identifier used to namespace registered component types so they are unique across modules.
|
|
9
|
+
* @returns An object with `$RefreshReg$` and `$RefreshSig$` to install as module-local globals.
|
|
12
10
|
*/
|
|
13
|
-
|
|
11
|
+
declare function createModuleRegistration(moduleId: string): {
|
|
14
12
|
$RefreshReg$: (type: ComponentType, id: string) => void;
|
|
15
13
|
$RefreshSig$: typeof RefreshRuntime.createSignatureFunctionForTransform;
|
|
16
14
|
};
|
|
15
|
+
declare function isRefreshBoundary(moduleExports: Record<string, unknown>): boolean;
|
|
17
16
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* A module is a refresh boundary if all its exports are React components,
|
|
21
|
-
* allowing for fast refresh without full page reload.
|
|
22
|
-
*
|
|
23
|
-
* @param moduleExports - The module's exports object
|
|
24
|
-
* @returns `true` if the module can be fast-refreshed
|
|
25
|
-
* @internal
|
|
26
|
-
*/
|
|
27
|
-
export declare function isReactRefreshBoundary(moduleExports: Record<string, unknown>): boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Triggers React Fast Refresh to re-render components.
|
|
30
|
-
*
|
|
31
|
-
* Called after module updates when all exports are React components.
|
|
32
|
-
*
|
|
33
|
-
* @internal
|
|
17
|
+
* Applies all pending React Refresh updates, re-rendering components whose modules have changed.
|
|
34
18
|
*/
|
|
35
|
-
|
|
36
|
-
export {};
|
|
19
|
+
declare function performRefresh(): void;
|
|
20
|
+
export { createModuleRegistration, isRefreshBoundary, performRefresh };
|
|
37
21
|
//# sourceMappingURL=refresh-runtime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refresh-runtime.d.ts","sourceRoot":"","sources":["../src/refresh-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"refresh-runtime.d.ts","sourceRoot":"","sources":["../src/refresh-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,uBAAuB,CAAC;AACnD,OAAO,sBAAsB,CAAC;AAE9B,KAAK,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AAErD;;;;;;GAMG;AACH,iBAAS,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG;IACjD,YAAY,EAAE,CAAC,IAAI,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACxD,YAAY,EAAE,OAAO,cAAc,CAAC,mCAAmC,CAAC;CAC3E,CAOA;AAsBD,iBAAS,iBAAiB,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAU1E;AAED;;GAEG;AACH,iBAAS,cAAc,IAAI,IAAI,CAE9B;AAED,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/refresh-runtime.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import RefreshRuntime from "react-refresh/runtime";
|
|
2
|
-
|
|
3
|
-
globalThis.$RefreshReg$ = () => { };
|
|
4
|
-
globalThis.$RefreshSig$ = () => (type) => type;
|
|
2
|
+
import "./refresh-globals.js";
|
|
5
3
|
/**
|
|
6
|
-
*
|
|
4
|
+
* Builds the per-module `$RefreshReg$` and `$RefreshSig$` hooks that React Refresh
|
|
5
|
+
* transformed code expects, scoping every registered component to the given module.
|
|
7
6
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @param moduleId - Unique identifier for the module
|
|
12
|
-
* @returns Registration functions for the module
|
|
13
|
-
* @internal
|
|
7
|
+
* @param moduleId Identifier used to namespace registered component types so they are unique across modules.
|
|
8
|
+
* @returns An object with `$RefreshReg$` and `$RefreshSig$` to install as module-local globals.
|
|
14
9
|
*/
|
|
15
|
-
|
|
10
|
+
function createModuleRegistration(moduleId) {
|
|
16
11
|
return {
|
|
17
12
|
$RefreshReg$: (type, id) => {
|
|
18
13
|
RefreshRuntime.register(type, `${moduleId} ${id}`);
|
|
@@ -20,53 +15,36 @@ export function createModuleRegistration(moduleId) {
|
|
|
20
15
|
$RefreshSig$: RefreshRuntime.createSignatureFunctionForTransform,
|
|
21
16
|
};
|
|
22
17
|
}
|
|
23
|
-
function isLikelyComponentType(value) {
|
|
24
|
-
if (typeof value !== "function") {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
const func = value;
|
|
28
|
-
if (func.$$typeof === Symbol.for("react.memo") || func.$$typeof === Symbol.for("react.forward_ref")) {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
const name = value.name;
|
|
32
|
-
if (typeof name === "string" && /^[A-Z]/.test(name)) {
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
18
|
/**
|
|
38
|
-
*
|
|
19
|
+
* Determines whether a module can act as a React Refresh boundary, meaning every one of
|
|
20
|
+
* its exports (ignoring `__esModule`) looks like a React component type.
|
|
39
21
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* @param moduleExports - The module's exports object
|
|
44
|
-
* @returns `true` if the module can be fast-refreshed
|
|
45
|
-
* @internal
|
|
22
|
+
* @param moduleExports The module's export object to inspect.
|
|
23
|
+
* @returns `true` when the module qualifies as a refresh boundary, `false` otherwise.
|
|
46
24
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
25
|
+
const isComponentExport = (key, value) => key === "__esModule" || RefreshRuntime.isLikelyComponentType(value);
|
|
26
|
+
const areAllExportsComponents = (moduleExports) => {
|
|
51
27
|
for (const key in moduleExports) {
|
|
52
|
-
if (key
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
const value = moduleExports[key];
|
|
56
|
-
if (!isLikelyComponentType(value)) {
|
|
28
|
+
if (!isComponentExport(key, moduleExports[key])) {
|
|
57
29
|
return false;
|
|
58
30
|
}
|
|
59
31
|
}
|
|
60
|
-
return
|
|
32
|
+
return true;
|
|
33
|
+
};
|
|
34
|
+
function isRefreshBoundary(moduleExports) {
|
|
35
|
+
if (RefreshRuntime.isLikelyComponentType(moduleExports)) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
if (!areAllExportsComponents(moduleExports)) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return Object.keys(moduleExports).some((k) => k !== "__esModule");
|
|
61
42
|
}
|
|
62
43
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* Called after module updates when all exports are React components.
|
|
66
|
-
*
|
|
67
|
-
* @internal
|
|
44
|
+
* Applies all pending React Refresh updates, re-rendering components whose modules have changed.
|
|
68
45
|
*/
|
|
69
|
-
|
|
46
|
+
function performRefresh() {
|
|
70
47
|
RefreshRuntime.performReactRefresh();
|
|
71
48
|
}
|
|
49
|
+
export { createModuleRegistration, isRefreshBoundary, performRefresh };
|
|
72
50
|
//# sourceMappingURL=refresh-runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refresh-runtime.js","sourceRoot":"","sources":["../src/refresh-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"refresh-runtime.js","sourceRoot":"","sources":["../src/refresh-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,uBAAuB,CAAC;AACnD,OAAO,sBAAsB,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import RefreshRuntime from \"react-refresh/runtime\";\nimport \"./refresh-globals.js\";\n\ntype ComponentType = (...args: unknown[]) => unknown;\n\n/**\n * Builds the per-module `$RefreshReg$` and `$RefreshSig$` hooks that React Refresh\n * transformed code expects, scoping every registered component to the given module.\n *\n * @param moduleId Identifier used to namespace registered component types so they are unique across modules.\n * @returns An object with `$RefreshReg$` and `$RefreshSig$` to install as module-local globals.\n */\nfunction createModuleRegistration(moduleId: string): {\n $RefreshReg$: (type: ComponentType, id: string) => void;\n $RefreshSig$: typeof RefreshRuntime.createSignatureFunctionForTransform;\n} {\n return {\n $RefreshReg$: (type: ComponentType, id: string) => {\n RefreshRuntime.register(type, `${moduleId} ${id}`);\n },\n $RefreshSig$: RefreshRuntime.createSignatureFunctionForTransform,\n };\n}\n\n/**\n * Determines whether a module can act as a React Refresh boundary, meaning every one of\n * its exports (ignoring `__esModule`) looks like a React component type.\n *\n * @param moduleExports The module's export object to inspect.\n * @returns `true` when the module qualifies as a refresh boundary, `false` otherwise.\n */\nconst isComponentExport = (key: string, value: unknown): boolean =>\n key === \"__esModule\" || RefreshRuntime.isLikelyComponentType(value);\n\nconst areAllExportsComponents = (moduleExports: Record<string, unknown>): boolean => {\n for (const key in moduleExports) {\n if (!isComponentExport(key, moduleExports[key])) {\n return false;\n }\n }\n\n return true;\n};\n\nfunction isRefreshBoundary(moduleExports: Record<string, unknown>): boolean {\n if (RefreshRuntime.isLikelyComponentType(moduleExports)) {\n return true;\n }\n\n if (!areAllExportsComponents(moduleExports)) {\n return false;\n }\n\n return Object.keys(moduleExports).some((k) => k !== \"__esModule\");\n}\n\n/**\n * Applies all pending React Refresh updates, re-rendering components whose modules have changed.\n */\nfunction performRefresh(): void {\n RefreshRuntime.performReactRefresh();\n}\n\nexport { createModuleRegistration, isRefreshBoundary, performRefresh };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/settings/compile.ts"],"names":[],"mappings":"AAOA,QAAA,MAAM,cAAc,GAAI,KAAK,MAAM,KAAG,IAYrC,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { formatChildProcessError } from "@gtkx/utils";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import { resolveCliTool } from "../internal/resolve-cli-tool.js";
|
|
4
|
+
const SCHEMA_COMPILER = "glib-compile-schemas";
|
|
5
|
+
const SCHEMA_COMPILE_TIMEOUT_MS = 30_000;
|
|
6
|
+
const compileSchemas = (dir) => {
|
|
7
|
+
try {
|
|
8
|
+
execFileSync(resolveCliTool(SCHEMA_COMPILER), ["--strict", dir], {
|
|
9
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
10
|
+
timeout: SCHEMA_COMPILE_TIMEOUT_MS,
|
|
11
|
+
encoding: "utf8",
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
const details = formatChildProcessError(error);
|
|
16
|
+
const suffix = details ? `:\n${details}` : "";
|
|
17
|
+
throw new Error(`glib-compile-schemas failed for ${dir}${suffix}`, { cause: error });
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export { compileSchemas };
|
|
21
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../../src/settings/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjE,MAAM,eAAe,GAAG,sBAAsB,CAAC;AAC/C,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAEzC,MAAM,cAAc,GAAG,CAAC,GAAW,EAAQ,EAAE;IACzC,IAAI,CAAC;QACD,YAAY,CAAC,cAAc,CAAC,eAAe,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC,EAAE;YAC7D,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;YACjC,OAAO,EAAE,yBAAyB;YAClC,QAAQ,EAAE,MAAM;SACnB,CAAC,CAAC;IACP,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,MAAM,OAAO,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;QAC/C,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,MAAM,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,mCAAmC,GAAG,GAAG,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACzF,CAAC;AACL,CAAC,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,CAAC","sourcesContent":["import { formatChildProcessError } from \"@gtkx/utils\";\nimport { execFileSync } from \"node:child_process\";\nimport { resolveCliTool } from \"../internal/resolve-cli-tool.js\";\n\nconst SCHEMA_COMPILER = \"glib-compile-schemas\";\nconst SCHEMA_COMPILE_TIMEOUT_MS = 30_000;\n\nconst compileSchemas = (dir: string): void => {\n try {\n execFileSync(resolveCliTool(SCHEMA_COMPILER), [\"--strict\", dir], {\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n timeout: SCHEMA_COMPILE_TIMEOUT_MS,\n encoding: \"utf8\",\n });\n } catch (error) {\n const details = formatChildProcessError(error);\n const suffix = details ? `:\\n${details}` : \"\";\n throw new Error(`glib-compile-schemas failed for ${dir}${suffix}`, { cause: error });\n }\n};\n\nexport { compileSchemas };\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type ParsedKey = {
|
|
2
|
+
name: string;
|
|
3
|
+
variantType: string | null;
|
|
4
|
+
enumId: string | null;
|
|
5
|
+
flagsId: string | null;
|
|
6
|
+
choices: string[];
|
|
7
|
+
summary: string | null;
|
|
8
|
+
};
|
|
9
|
+
type ParsedSchema = {
|
|
10
|
+
id: string;
|
|
11
|
+
path: string | null;
|
|
12
|
+
keys: ParsedKey[];
|
|
13
|
+
};
|
|
14
|
+
type ParsedSchemaFile = {
|
|
15
|
+
fileName: string;
|
|
16
|
+
schemas: ParsedSchema[];
|
|
17
|
+
enums: Map<string, string[]>;
|
|
18
|
+
flags: Map<string, string[]>;
|
|
19
|
+
};
|
|
20
|
+
declare const parseSchemaXml: (xml: string, fileName: string) => ParsedSchemaFile;
|
|
21
|
+
declare class SchemaParseError extends Error {
|
|
22
|
+
}
|
|
23
|
+
export { parseSchemaXml, SchemaParseError, type ParsedKey, type ParsedSchema, type ParsedSchemaFile };
|
|
24
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/settings/parser.ts"],"names":[],"mappings":"AAEA,KAAK,SAAS,GAAG;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,CAAC;AAEF,KAAK,YAAY,GAAG;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE,SAAS,EAAE,CAAC;CACrB,CAAC;AAEF,KAAK,gBAAgB,GAAG;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CAChC,CAAC;AA2IF,QAAA,MAAM,cAAc,GAAI,KAAK,MAAM,EAAE,UAAU,MAAM,KAAG,gBA2BvD,CAAC;AAEF,cAAM,gBAAiB,SAAQ,KAAK;CAAG;AAEvC,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,KAAK,SAAS,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { XMLParser } from "fast-xml-parser";
|
|
2
|
+
const MULTI_TAGS = new Set(["schema", "key", "enum", "flags", "value", "choice"]);
|
|
3
|
+
const PARSER = new XMLParser({
|
|
4
|
+
ignoreAttributes: false,
|
|
5
|
+
attributeNamePrefix: "@_",
|
|
6
|
+
parseAttributeValue: false,
|
|
7
|
+
parseTagValue: false,
|
|
8
|
+
trimValues: true,
|
|
9
|
+
isArray: (name) => MULTI_TAGS.has(name),
|
|
10
|
+
});
|
|
11
|
+
const isRawNode = (value) => typeof value === "object" && value !== null;
|
|
12
|
+
const attr = (node, name) => {
|
|
13
|
+
const value = node[`@_${name}`];
|
|
14
|
+
return typeof value === "string" ? value : null;
|
|
15
|
+
};
|
|
16
|
+
const text = (node, name) => {
|
|
17
|
+
const value = node[name];
|
|
18
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
19
|
+
};
|
|
20
|
+
const children = (node, name) => {
|
|
21
|
+
const value = node[name];
|
|
22
|
+
if (!Array.isArray(value)) {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
return value.filter(isRawNode);
|
|
26
|
+
};
|
|
27
|
+
const parseNicks = (definition) => children(definition, "value")
|
|
28
|
+
.map((value) => attr(value, "nick"))
|
|
29
|
+
.filter((nick) => nick !== null);
|
|
30
|
+
const parseDefinitions = (schemalist, tag) => {
|
|
31
|
+
const definitions = new Map();
|
|
32
|
+
for (const definition of children(schemalist, tag)) {
|
|
33
|
+
const id = attr(definition, "id");
|
|
34
|
+
if (id !== null) {
|
|
35
|
+
definitions.set(id, parseNicks(definition));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return definitions;
|
|
39
|
+
};
|
|
40
|
+
const parseChoices = (key) => {
|
|
41
|
+
const choices = key.choices;
|
|
42
|
+
if (!isRawNode(choices)) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
return children(choices, "choice")
|
|
46
|
+
.map((choice) => attr(choice, "value"))
|
|
47
|
+
.filter((value) => value !== null);
|
|
48
|
+
};
|
|
49
|
+
const parseKey = (key, fileName) => {
|
|
50
|
+
const name = attr(key, "name");
|
|
51
|
+
if (name === null) {
|
|
52
|
+
throw new SchemaParseError(`A <key> in ${fileName} has no name attribute`);
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
name,
|
|
56
|
+
variantType: attr(key, "type"),
|
|
57
|
+
enumId: attr(key, "enum"),
|
|
58
|
+
flagsId: attr(key, "flags"),
|
|
59
|
+
choices: parseChoices(key),
|
|
60
|
+
summary: text(key, "summary"),
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
const parseRawSchema = (schema, fileName) => {
|
|
64
|
+
const id = attr(schema, "id");
|
|
65
|
+
if (id === null) {
|
|
66
|
+
throw new SchemaParseError(`A <schema> in ${fileName} has no id attribute`);
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
id,
|
|
70
|
+
path: attr(schema, "path"),
|
|
71
|
+
extendsId: attr(schema, "extends"),
|
|
72
|
+
keys: children(schema, "key").map((key) => parseKey(key, fileName)),
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
const collectInheritedKeys = (context, current) => {
|
|
76
|
+
if (context.visited.has(current.id)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
context.visited.add(current.id);
|
|
80
|
+
const parent = current.extendsId === null ? undefined : context.byId.get(current.extendsId);
|
|
81
|
+
if (parent !== undefined) {
|
|
82
|
+
collectInheritedKeys(context, parent);
|
|
83
|
+
}
|
|
84
|
+
for (const key of current.keys) {
|
|
85
|
+
context.merged.set(key.name, key);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const mergeInheritedKeys = (schema, byId) => {
|
|
89
|
+
const context = { byId, merged: new Map(), visited: new Set() };
|
|
90
|
+
collectInheritedKeys(context, schema);
|
|
91
|
+
return context.merged.values().toArray();
|
|
92
|
+
};
|
|
93
|
+
const parseSchemaXml = (xml, fileName) => {
|
|
94
|
+
let document;
|
|
95
|
+
try {
|
|
96
|
+
document = PARSER.parse(xml);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
throw new SchemaParseError(`Failed to parse ${fileName} as XML: ${String(error)}`, { cause: error });
|
|
100
|
+
}
|
|
101
|
+
if (!isRawNode(document) || !("schemalist" in document)) {
|
|
102
|
+
throw new SchemaParseError(`${fileName} has no <schemalist> root element`);
|
|
103
|
+
}
|
|
104
|
+
const schemalist = isRawNode(document.schemalist) ? document.schemalist : {};
|
|
105
|
+
const rawSchemas = children(schemalist, "schema").map((schema) => parseRawSchema(schema, fileName));
|
|
106
|
+
const byId = new Map(rawSchemas.map((schema) => [schema.id, schema]));
|
|
107
|
+
return {
|
|
108
|
+
fileName,
|
|
109
|
+
schemas: rawSchemas.map((schema) => ({
|
|
110
|
+
id: schema.id,
|
|
111
|
+
path: schema.path,
|
|
112
|
+
keys: mergeInheritedKeys(schema, byId),
|
|
113
|
+
})),
|
|
114
|
+
enums: parseDefinitions(schemalist, "enum"),
|
|
115
|
+
flags: parseDefinitions(schemalist, "flags"),
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
class SchemaParseError extends Error {
|
|
119
|
+
}
|
|
120
|
+
export { parseSchemaXml, SchemaParseError };
|
|
121
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/settings/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;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C;IACzG,CAAC;IAED,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,YAAY,IAAI,QAAQ,CAAC,EAAE,CAAC;QACtD,MAAM,IAAI,gBAAgB,CAAC,GAAG,QAAQ,mCAAmC,CAAC,CAAC;IAC/E,CAAC;IAED,MAAM,UAAU,GAAG,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7E,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IACpG,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAEtE,OAAO;QACH,QAAQ;QACR,OAAO,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YACjC,EAAE,EAAE,MAAM,CAAC,EAAE;YACb,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,kBAAkB,CAAC,MAAM,EAAE,IAAI,CAAC;SACzC,CAAC,CAAC;QACH,KAAK,EAAE,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC;QAC3C,KAAK,EAAE,gBAAgB,CAAC,UAAU,EAAE,OAAO,CAAC;KAC/C,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,gBAAiB,SAAQ,KAAK;CAAG;AAEvC,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAA4D,CAAC","sourcesContent":["import { XMLParser } from \"fast-xml-parser\";\n\ntype ParsedKey = {\n name: string;\n variantType: string | null;\n enumId: string | null;\n flagsId: string | null;\n choices: string[];\n summary: string | null;\n};\n\ntype ParsedSchema = {\n id: string;\n path: string | null;\n keys: ParsedKey[];\n};\n\ntype ParsedSchemaFile = {\n fileName: string;\n schemas: ParsedSchema[];\n enums: Map<string, string[]>;\n flags: Map<string, string[]>;\n};\n\ntype RawNode = Record<string, unknown>;\n\ntype RawSchema = {\n id: string;\n path: string | null;\n extendsId: string | null;\n keys: ParsedKey[];\n};\n\ntype MergeContext = {\n byId: Map<string, RawSchema>;\n merged: Map<string, ParsedKey>;\n visited: Set<string>;\n};\n\nconst MULTI_TAGS: Set<string> = new Set([\"schema\", \"key\", \"enum\", \"flags\", \"value\", \"choice\"]);\n\nconst PARSER = new XMLParser({\n ignoreAttributes: false,\n attributeNamePrefix: \"@_\",\n parseAttributeValue: false,\n parseTagValue: false,\n trimValues: true,\n isArray: (name) => MULTI_TAGS.has(name),\n});\n\nconst isRawNode = (value: unknown): value is RawNode => typeof value === \"object\" && value !== null;\n\nconst attr = (node: RawNode, name: string): string | null => {\n const value = node[`@_${name}`];\n\n return typeof value === \"string\" ? value : null;\n};\n\nconst text = (node: RawNode, name: string): string | null => {\n const value = node[name];\n\n return typeof value === \"string\" && value.length > 0 ? value : null;\n};\n\nconst children = (node: RawNode, name: string): RawNode[] => {\n const value = node[name];\n\n if (!Array.isArray(value)) {\n return [];\n }\n\n return value.filter(isRawNode);\n};\n\nconst parseNicks = (definition: RawNode): string[] =>\n children(definition, \"value\")\n .map((value) => attr(value, \"nick\"))\n .filter((nick): nick is string => nick !== null);\n\nconst parseDefinitions = (schemalist: RawNode, tag: string): Map<string, string[]> => {\n const definitions: Map<string, string[]> = new Map();\n\n for (const definition of children(schemalist, tag)) {\n const id = attr(definition, \"id\");\n\n if (id !== null) {\n definitions.set(id, parseNicks(definition));\n }\n }\n\n return definitions;\n};\n\nconst parseChoices = (key: RawNode): string[] => {\n const choices = key.choices;\n\n if (!isRawNode(choices)) {\n return [];\n }\n\n return children(choices, \"choice\")\n .map((choice) => attr(choice, \"value\"))\n .filter((value): value is string => value !== null);\n};\n\nconst parseKey = (key: RawNode, fileName: string): ParsedKey => {\n const name = attr(key, \"name\");\n\n if (name === null) {\n throw new SchemaParseError(`A <key> in ${fileName} has no name attribute`);\n }\n\n return {\n name,\n variantType: attr(key, \"type\"),\n enumId: attr(key, \"enum\"),\n flagsId: attr(key, \"flags\"),\n choices: parseChoices(key),\n summary: text(key, \"summary\"),\n };\n};\n\nconst parseRawSchema = (schema: RawNode, fileName: string): RawSchema => {\n const id = attr(schema, \"id\");\n\n if (id === null) {\n throw new SchemaParseError(`A <schema> in ${fileName} has no id attribute`);\n }\n\n return {\n id,\n path: attr(schema, \"path\"),\n extendsId: attr(schema, \"extends\"),\n keys: children(schema, \"key\").map((key) => parseKey(key, fileName)),\n };\n};\n\nconst collectInheritedKeys = (context: MergeContext, current: RawSchema): void => {\n if (context.visited.has(current.id)) {\n return;\n }\n\n context.visited.add(current.id);\n const parent = current.extendsId === null ? undefined : context.byId.get(current.extendsId);\n\n if (parent !== undefined) {\n collectInheritedKeys(context, parent);\n }\n\n for (const key of current.keys) {\n context.merged.set(key.name, key);\n }\n};\n\nconst mergeInheritedKeys = (schema: RawSchema, byId: Map<string, RawSchema>): ParsedKey[] => {\n const context: MergeContext = { byId, merged: new Map(), visited: new Set() };\n collectInheritedKeys(context, schema);\n\n return context.merged.values().toArray();\n};\n\nconst parseSchemaXml = (xml: string, fileName: string): ParsedSchemaFile => {\n let document: unknown;\n\n try {\n document = PARSER.parse(xml);\n } catch (error) {\n throw new SchemaParseError(`Failed to parse ${fileName} as XML: ${String(error)}`, { cause: error });\n }\n\n if (!isRawNode(document) || !(\"schemalist\" in document)) {\n throw new SchemaParseError(`${fileName} has no <schemalist> root element`);\n }\n\n const schemalist = isRawNode(document.schemalist) ? document.schemalist : {};\n const rawSchemas = children(schemalist, \"schema\").map((schema) => parseRawSchema(schema, fileName));\n const byId = new Map(rawSchemas.map((schema) => [schema.id, schema]));\n\n return {\n fileName,\n schemas: rawSchemas.map((schema) => ({\n id: schema.id,\n path: schema.path,\n keys: mergeInheritedKeys(schema, byId),\n })),\n enums: parseDefinitions(schemalist, \"enum\"),\n flags: parseDefinitions(schemalist, \"flags\"),\n };\n};\n\nclass SchemaParseError extends Error {}\n\nexport { parseSchemaXml, SchemaParseError, type ParsedKey, type ParsedSchema, type ParsedSchemaFile };\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ParsedSchemaFile } from "./parser.js";
|
|
2
|
+
declare const renderRuntimeModule: (file: ParsedSchemaFile) => string;
|
|
3
|
+
declare const renderEnvModule: (files: ParsedSchemaFile[]) => string;
|
|
4
|
+
export { renderRuntimeModule, renderEnvModule };
|
|
5
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/settings/render.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA2B,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAoC7E,QAAA,MAAM,mBAAmB,GAAI,MAAM,gBAAgB,KAAG,MAyBrD,CAAC;AA8FF,QAAA,MAAM,eAAe,GAAI,OAAO,gBAAgB,EAAE,KAAG,MAQpD,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { upperFirst } from "@gtkx/utils";
|
|
2
|
+
const GTKX_ENV_MODULE_HEADER = `/**
|
|
3
|
+
* GSettings schema modules generated by GTKX from the project's
|
|
4
|
+
* \`.gschema.xml\` files. Regenerated by \`gtkx codegen\`, \`gtkx dev\`, and
|
|
5
|
+
* \`gtkx build\`; do not edit.
|
|
6
|
+
*/`;
|
|
7
|
+
const ENUM_KIND = "enum";
|
|
8
|
+
const FLAGS_KIND = "flags";
|
|
9
|
+
const toJsStringLiteral = (value) => JSON.stringify(value).replaceAll("\u{2028}", String.raw `\u2028`).replaceAll("\u{2029}", String.raw `\u2029`);
|
|
10
|
+
const getExportName = (schemaId) => schemaId.replaceAll(".", "_");
|
|
11
|
+
const runtimeKindForKey = (key) => {
|
|
12
|
+
if (key.enumId !== null) {
|
|
13
|
+
return ENUM_KIND;
|
|
14
|
+
}
|
|
15
|
+
if (key.flagsId !== null) {
|
|
16
|
+
return FLAGS_KIND;
|
|
17
|
+
}
|
|
18
|
+
return key.variantType ?? "";
|
|
19
|
+
};
|
|
20
|
+
const getRuntimeKeys = (schema) => {
|
|
21
|
+
const entries = schema.keys.map((key) => `${toJsStringLiteral(key.name)}: ${toJsStringLiteral(runtimeKindForKey(key))}`);
|
|
22
|
+
return `{ ${entries.join(", ")} }`;
|
|
23
|
+
};
|
|
24
|
+
const renderRuntimeModule = (file) => {
|
|
25
|
+
const lines = [];
|
|
26
|
+
for (const [index, schema] of file.schemas.entries()) {
|
|
27
|
+
const keysName = `keys_${String(index)}`;
|
|
28
|
+
const id = toJsStringLiteral(schema.id);
|
|
29
|
+
lines.push(`const ${keysName} = ${getRuntimeKeys(schema)};`);
|
|
30
|
+
if (schema.path === null) {
|
|
31
|
+
lines.push(`export const ${getExportName(schema.id)} = { id: ${id}, keys: ${keysName}, ` +
|
|
32
|
+
`at: (path) => ({ id: ${id}, path, keys: ${keysName} }) };`);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
lines.push(`export const ${getExportName(schema.id)} = { id: ${id}, path: null, keys: ${keysName} };`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const first = file.schemas[0];
|
|
39
|
+
if (first !== undefined) {
|
|
40
|
+
lines.push(`export default ${getExportName(first.id)};`);
|
|
41
|
+
}
|
|
42
|
+
return lines.join("\n");
|
|
43
|
+
};
|
|
44
|
+
const sanitizeSummary = (summary) => summary.replaceAll("*/", String.raw `*\/`);
|
|
45
|
+
const allocateInterfaceName = (schemaId, usedNames) => {
|
|
46
|
+
const base = `${schemaId
|
|
47
|
+
.split(/[^a-zA-Z0-9]+/)
|
|
48
|
+
.filter((part) => part.length > 0)
|
|
49
|
+
.map((part) => upperFirst(part))
|
|
50
|
+
.join("")}Keys`;
|
|
51
|
+
let name = base;
|
|
52
|
+
let suffix = 2;
|
|
53
|
+
while (usedNames.has(name)) {
|
|
54
|
+
name = `${base}${String(suffix)}`;
|
|
55
|
+
suffix += 1;
|
|
56
|
+
}
|
|
57
|
+
usedNames.add(name);
|
|
58
|
+
return name;
|
|
59
|
+
};
|
|
60
|
+
const renderKeysType = (name, schema) => {
|
|
61
|
+
const lines = [` type ${name} = {`];
|
|
62
|
+
for (const key of schema.keys) {
|
|
63
|
+
if (key.summary !== null) {
|
|
64
|
+
lines.push(` /** ${sanitizeSummary(key.summary)} */`);
|
|
65
|
+
}
|
|
66
|
+
lines.push(` ${toJsStringLiteral(key.name)}: ${toJsStringLiteral(runtimeKindForKey(key))};`);
|
|
67
|
+
}
|
|
68
|
+
lines.push(" };");
|
|
69
|
+
return lines;
|
|
70
|
+
};
|
|
71
|
+
const boundRefTypeLines = (interfaceName, indent) => [
|
|
72
|
+
`${indent}id: string;`,
|
|
73
|
+
`${indent}path: string | null;`,
|
|
74
|
+
`${indent}keys: ${interfaceName};`,
|
|
75
|
+
];
|
|
76
|
+
const renderSchemaConst = (schema, interfaceName) => {
|
|
77
|
+
const exportName = getExportName(schema.id);
|
|
78
|
+
if (schema.path !== null) {
|
|
79
|
+
return [
|
|
80
|
+
` const ${exportName}: {`,
|
|
81
|
+
` id: ${toJsStringLiteral(schema.id)};`,
|
|
82
|
+
...boundRefTypeLines(interfaceName, " ".repeat(8)).slice(1),
|
|
83
|
+
" };",
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
return [
|
|
87
|
+
` const ${exportName}: {`,
|
|
88
|
+
` id: ${JSON.stringify(schema.id)};`,
|
|
89
|
+
` keys: ${interfaceName};`,
|
|
90
|
+
" at(path: string): {",
|
|
91
|
+
...boundRefTypeLines(interfaceName, " ".repeat(12)),
|
|
92
|
+
" };",
|
|
93
|
+
" };",
|
|
94
|
+
];
|
|
95
|
+
};
|
|
96
|
+
const renderFileModule = (file, usedNames) => {
|
|
97
|
+
const lines = [`declare module "${file.fileName}" {`];
|
|
98
|
+
const exportNames = [];
|
|
99
|
+
for (const [index, schema] of file.schemas.entries()) {
|
|
100
|
+
if (index > 0) {
|
|
101
|
+
lines.push("");
|
|
102
|
+
}
|
|
103
|
+
const interfaceName = allocateInterfaceName(schema.id, usedNames);
|
|
104
|
+
lines.push(...renderKeysType(interfaceName, schema), "", ...renderSchemaConst(schema, interfaceName));
|
|
105
|
+
exportNames.push(getExportName(schema.id));
|
|
106
|
+
}
|
|
107
|
+
const [firstExport] = exportNames;
|
|
108
|
+
if (firstExport !== undefined) {
|
|
109
|
+
lines.push("", ` export { ${exportNames.join(", ")} };`, ` export default ${firstExport};`);
|
|
110
|
+
}
|
|
111
|
+
lines.push("}");
|
|
112
|
+
return lines;
|
|
113
|
+
};
|
|
114
|
+
const renderEnvModule = (files) => {
|
|
115
|
+
const usedNames = new Set();
|
|
116
|
+
const blocks = files
|
|
117
|
+
.filter((file) => file.schemas.length > 0)
|
|
118
|
+
.map((file) => renderFileModule(file, usedNames).join("\n"));
|
|
119
|
+
return `${[GTKX_ENV_MODULE_HEADER, ...blocks].join("\n\n")}\n`;
|
|
120
|
+
};
|
|
121
|
+
export { renderRuntimeModule, renderEnvModule };
|
|
122
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/settings/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,MAAM,sBAAsB,GAAG;;;;IAI3B,CAAC;AAEL,MAAM,SAAS,GAAG,MAAM,CAAC;AACzB,MAAM,UAAU,GAAG,OAAO,CAAC;AAE3B,MAAM,iBAAiB,GAAG,CAAC,KAAa,EAAU,EAAE,CAChD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,UA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C,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC;IAElC,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC5B,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,gBAAgB,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,sBAAsB,WAAW,GAAG,CAAC,CAAC;IACtG,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEhB,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,KAAyB,EAAU,EAAE;IAC1D,MAAM,SAAS,GAAgB,IAAI,GAAG,EAAE,CAAC;IAEzC,MAAM,MAAM,GAAG,KAAK;SACf,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;SACzC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAEjE,OAAO,GAAG,CAAC,sBAAsB,EAAE,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;AACnE,CAAC,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import { upperFirst } from \"@gtkx/utils\";\nimport type { ParsedKey, ParsedSchema, ParsedSchemaFile } from \"./parser.js\";\n\nconst GTKX_ENV_MODULE_HEADER = `/**\n * GSettings schema modules generated by GTKX from the project's\n * \\`.gschema.xml\\` files. Regenerated by \\`gtkx codegen\\`, \\`gtkx dev\\`, and\n * \\`gtkx build\\`; do not edit.\n */`;\n\nconst ENUM_KIND = \"enum\";\nconst FLAGS_KIND = \"flags\";\n\nconst toJsStringLiteral = (value: string): string =>\n JSON.stringify(value).replaceAll(\"\\u{2028}\", String.raw`\\u2028`).replaceAll(\"\\u{2029}\", String.raw`\\u2029`);\n\nconst getExportName = (schemaId: string): string => schemaId.replaceAll(\".\", \"_\");\n\nconst runtimeKindForKey = (key: ParsedKey): string => {\n if (key.enumId !== null) {\n return ENUM_KIND;\n }\n\n if (key.flagsId !== null) {\n return FLAGS_KIND;\n }\n\n return key.variantType ?? \"\";\n};\n\nconst getRuntimeKeys = (schema: ParsedSchema): string => {\n const entries = schema.keys.map(\n (key) => `${toJsStringLiteral(key.name)}: ${toJsStringLiteral(runtimeKindForKey(key))}`,\n );\n\n return `{ ${entries.join(\", \")} }`;\n};\n\nconst renderRuntimeModule = (file: ParsedSchemaFile): string => {\n const lines: string[] = [];\n\n for (const [index, schema] of file.schemas.entries()) {\n const keysName = `keys_${String(index)}`;\n const id = toJsStringLiteral(schema.id);\n lines.push(`const ${keysName} = ${getRuntimeKeys(schema)};`);\n\n if (schema.path === null) {\n lines.push(\n `export const ${getExportName(schema.id)} = { id: ${id}, keys: ${keysName}, ` +\n `at: (path) => ({ id: ${id}, path, keys: ${keysName} }) };`,\n );\n } else {\n lines.push(`export const ${getExportName(schema.id)} = { id: ${id}, path: null, keys: ${keysName} };`);\n }\n }\n\n const first = file.schemas[0];\n\n if (first !== undefined) {\n lines.push(`export default ${getExportName(first.id)};`);\n }\n\n return lines.join(\"\\n\");\n};\n\nconst sanitizeSummary = (summary: string): string => summary.replaceAll(\"*/\", String.raw`*\\/`);\n\nconst allocateInterfaceName = (schemaId: string, usedNames: Set<string>): string => {\n const base = `${schemaId\n .split(/[^a-zA-Z0-9]+/)\n .filter((part) => part.length > 0)\n .map((part) => upperFirst(part))\n .join(\"\")}Keys`;\n\n let name = base;\n let suffix = 2;\n\n while (usedNames.has(name)) {\n name = `${base}${String(suffix)}`;\n suffix += 1;\n }\n\n usedNames.add(name);\n\n return name;\n};\n\nconst renderKeysType = (name: string, schema: ParsedSchema): string[] => {\n const lines = [` type ${name} = {`];\n\n for (const key of schema.keys) {\n if (key.summary !== null) {\n lines.push(` /** ${sanitizeSummary(key.summary)} */`);\n }\n\n lines.push(` ${toJsStringLiteral(key.name)}: ${toJsStringLiteral(runtimeKindForKey(key))};`);\n }\n\n lines.push(\" };\");\n\n return lines;\n};\n\nconst boundRefTypeLines = (interfaceName: string, indent: string): string[] => [\n `${indent}id: string;`,\n `${indent}path: string | null;`,\n `${indent}keys: ${interfaceName};`,\n];\n\nconst renderSchemaConst = (schema: ParsedSchema, interfaceName: string): string[] => {\n const exportName = getExportName(schema.id);\n\n if (schema.path !== null) {\n return [\n ` const ${exportName}: {`,\n ` id: ${toJsStringLiteral(schema.id)};`,\n ...boundRefTypeLines(interfaceName, \" \".repeat(8)).slice(1),\n \" };\",\n ];\n }\n\n return [\n ` const ${exportName}: {`,\n ` id: ${JSON.stringify(schema.id)};`,\n ` keys: ${interfaceName};`,\n \" at(path: string): {\",\n ...boundRefTypeLines(interfaceName, \" \".repeat(12)),\n \" };\",\n \" };\",\n ];\n};\n\nconst renderFileModule = (file: ParsedSchemaFile, usedNames: Set<string>): string[] => {\n const lines = [`declare module \"${file.fileName}\" {`];\n const exportNames: string[] = [];\n\n for (const [index, schema] of file.schemas.entries()) {\n if (index > 0) {\n lines.push(\"\");\n }\n\n const interfaceName = allocateInterfaceName(schema.id, usedNames);\n lines.push(...renderKeysType(interfaceName, schema), \"\", ...renderSchemaConst(schema, interfaceName));\n exportNames.push(getExportName(schema.id));\n }\n\n const [firstExport] = exportNames;\n\n if (firstExport !== undefined) {\n lines.push(\"\", ` export { ${exportNames.join(\", \")} };`, ` export default ${firstExport};`);\n }\n\n lines.push(\"}\");\n\n return lines;\n};\n\nconst renderEnvModule = (files: ParsedSchemaFile[]): string => {\n const usedNames: Set<string> = new Set();\n\n const blocks = files\n .filter((file) => file.schemas.length > 0)\n .map((file) => renderFileModule(file, usedNames).join(\"\\n\"));\n\n return `${[GTKX_ENV_MODULE_HEADER, ...blocks].join(\"\\n\\n\")}\\n`;\n};\n\nexport { renderRuntimeModule, renderEnvModule };\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type SchemaEnvResult = {
|
|
2
|
+
path: string;
|
|
3
|
+
written: boolean;
|
|
4
|
+
};
|
|
5
|
+
declare const SCHEMA_SUFFIX = ".gschema.xml";
|
|
6
|
+
declare const prependSchemaDir: (dir: string, existing: string | undefined) => string;
|
|
7
|
+
declare const stageSchema: (dir: string, filePath: string) => void;
|
|
8
|
+
declare const findSchemaFiles: (dataDir: string) => string[];
|
|
9
|
+
declare const stageAndCompileProjectSchemas: (root: string, dataDir: string | null) => string | null;
|
|
10
|
+
declare const schemaEnvPath: (rootDir: string) => string;
|
|
11
|
+
declare const emitSchemaEnv: (rootDir: string, dataDir: string | null) => SchemaEnvResult;
|
|
12
|
+
export { SCHEMA_SUFFIX, prependSchemaDir, stageSchema, findSchemaFiles, stageAndCompileProjectSchemas, schemaEnvPath, emitSchemaEnv, };
|
|
13
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/settings/schema.ts"],"names":[],"mappings":"AAWA,KAAK,eAAe,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,QAAA,MAAM,aAAa,iBAAiB,CAAC;AAGrC,QAAA,MAAM,gBAAgB,GAAI,KAAK,MAAM,EAAE,UAAU,MAAM,GAAG,SAAS,KAAG,MAUrE,CAAC;AAKF,QAAA,MAAM,WAAW,GAAI,KAAK,MAAM,EAAE,UAAU,MAAM,KAAG,IAEpD,CAAC;AA6BF,QAAA,MAAM,eAAe,GAAI,SAAS,MAAM,KAAG,MAAM,EAKhD,CAAC;AAEF,QAAA,MAAM,6BAA6B,GAAI,MAAM,MAAM,EAAE,SAAS,MAAM,GAAG,IAAI,KAAG,MAAM,GAAG,IAwBtF,CAAC;AAEF,QAAA,MAAM,aAAa,GAAI,SAAS,MAAM,KAAG,MAA4D,CAAC;AAmDtG,QAAA,MAAM,aAAa,GAAI,SAAS,MAAM,EAAE,SAAS,MAAM,GAAG,IAAI,KAAG,eAShE,CAAC;AAEF,OAAO,EACH,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,6BAA6B,EAC7B,aAAa,EACb,aAAa,GAChB,CAAC"}
|