@gtk-js/theme-whitesur 0.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # @gtk-js/theme-whitesur
2
+
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 0982123: Bump all packages past burned npm versions
8
+ - Updated dependencies [0982123]
9
+ - @gtk-js/gtk-css@0.1.1
10
+
11
+ ## 0.0.1
12
+
13
+ ### Patch Changes
14
+
15
+ - @gtk-js/gtk-css@0.2.0
package/build.ts ADDED
@@ -0,0 +1,112 @@
1
+ import { compileGtkCSS } from "@gtk-js/gtk-css/compile";
2
+ import { XMLParser } from "fast-xml-parser";
3
+ import { mkdirSync, readFileSync, unlinkSync, writeFileSync } from "fs";
4
+
5
+ const upstreamDir = new URL("../../upstream/whitesur-gtk-theme/src", import.meta.url).pathname;
6
+
7
+ const outDir = new URL("dist/", import.meta.url).pathname;
8
+ mkdirSync(outDir, { recursive: true });
9
+
10
+ const sassDir = `${upstreamDir}/sass`;
11
+
12
+ // Parse gtk.gresource.xml to build a map of virtual CSS url() paths → physical file paths.
13
+ // The gresource XML lists paths relative to gtk-4.0/, and make_gresource_xml.sh maps them:
14
+ // assets/ → src/assets/gtk/common-assets/assets/
15
+ // windows-assets/ → src/assets/gtk/windows-assets/titlebutton/
16
+ const gresourceXml = readFileSync(`${upstreamDir}/main/gtk-4.0/gtk.gresource.xml`, "utf8");
17
+ const parsed = new XMLParser({ isArray: () => true }).parse(gresourceXml);
18
+ const assetMap = new Map<string, string>();
19
+ const files: string[] = parsed?.gresources?.[0]?.gresource?.[0]?.file ?? [];
20
+ for (const virtualPath of files) {
21
+ if (!virtualPath.endsWith(".png")) continue;
22
+ const filename = virtualPath.split("/").pop()!;
23
+ let physicalPath: string;
24
+ if (virtualPath.startsWith("windows-assets/")) {
25
+ physicalPath = `${upstreamDir}/assets/gtk/windows-assets/titlebutton/${filename}`;
26
+ } else if (virtualPath.startsWith("assets/")) {
27
+ physicalPath = `${upstreamDir}/assets/gtk/common-assets/assets/${filename}`;
28
+ } else {
29
+ continue;
30
+ }
31
+ assetMap.set(virtualPath, physicalPath);
32
+ }
33
+
34
+ const accents = ["default"] as const;
35
+ const schemes = ["light", "dark"] as const;
36
+
37
+ const themeOptionsContent = `
38
+ $sidebar_size: 200px;
39
+ $nautilus_style: 'stable';
40
+ $panel_opacity: 0.15;
41
+ $showapps_button: 'bigsur';
42
+ $panel_size: 'default';
43
+ $font_size: 'normal';
44
+ $activities: 'default';
45
+ $panel_font: 'white';
46
+ $max_window_style: 'square';
47
+ $monterey: 'false';
48
+ $darker: 'false';
49
+ $scale: 'default';
50
+ $shell_version: 'old';
51
+ `;
52
+
53
+ /**
54
+ * Adjust .gtk-switch min-width to match native GTK layout manager.
55
+ *
56
+ * Native GTK computes: switch_width = 2 × slider_measured_width (content + margin).
57
+ * The upstream SCSS sets switch min-width to 32px, but the native layout manager
58
+ * computes 2 × (18px slider + 1px margin) = 38px.
59
+ */
60
+ function fixSwitchLayout(css: string): string {
61
+ return css.replace(/(\.gtk-switch\s*\{[^}]*?)min-width:\s*32px/, "$1min-width: 38px");
62
+ }
63
+
64
+ const results: Record<string, string> = {};
65
+
66
+ for (const scheme of schemes) {
67
+ const scssEntry = `${upstreamDir}/main/gtk-4.0/gtk-${scheme === "light" ? "Light" : "Dark"}.scss`;
68
+
69
+ for (const accent of accents) {
70
+ const themeValue = accent === "default" ? "default" : accent;
71
+
72
+ const gtkBaseContent = `
73
+ $laptop: 'true';
74
+ $trans: 'false';
75
+ $theme: '${themeValue}';
76
+ $scheme: 'standard';
77
+ $gnome_version: 'old';
78
+ $accent_type: 'fixed';
79
+ `;
80
+
81
+ writeFileSync(`${sassDir}/_theme-options-temp.scss`, themeOptionsContent);
82
+ writeFileSync(`${sassDir}/_gtk-base-temp.scss`, gtkBaseContent);
83
+
84
+ try {
85
+ let css = await compileGtkCSS(scssEntry, { scheme, assetMap });
86
+ css = fixSwitchLayout(css);
87
+ const key = `${scheme}_${accent}`;
88
+ results[key] = css;
89
+ process.stdout.write(` ${key}: ${css.length}b\n`);
90
+ } finally {
91
+ try {
92
+ unlinkSync(`${sassDir}/_theme-options-temp.scss`);
93
+ } catch {}
94
+ try {
95
+ unlinkSync(`${sassDir}/_gtk-base-temp.scss`);
96
+ } catch {}
97
+ }
98
+ }
99
+ }
100
+
101
+ // Write individual CSS files
102
+ for (const [key, css] of Object.entries(results)) {
103
+ writeFileSync(`${outDir}${key}.css`, css);
104
+ }
105
+
106
+ // Write JS index that exports all variants as named string constants
107
+ const indexLines = Object.keys(results).map(
108
+ (key) => `export { default as ${key} } from "./${key}.css" with { type: "text" };`,
109
+ );
110
+ writeFileSync(`${outDir}index.ts`, indexLines.join("\n") + "\n");
111
+
112
+ console.log(`Built ${Object.keys(results).length} WhiteSur variants.`);