@multiplatform.one/vite-plugin-gnome 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2021 [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # @multiplatform.one/vite-plugin-gnome
2
+
3
+ Vite plugin that makes Tamagui render under
4
+ [react-gnome](https://github.com/bitspur/react-gnome) (GTK4 / GJS /
5
+ libadwaita). Real Tamagui (`@tamagui/core/native`) assumes a
6
+ react-native-web-lite runtime; under GJS none of that holds, so this
7
+ package patches the bundler's view of the upstream packages instead of
8
+ reimplementing them.
9
+
10
+ Pairs with `@react-gnome/vite-plugin`, which carries the GENERIC
11
+ react-gnome-under-GJS settings (react-native → @react-gnome aliases,
12
+ react-native-first resolve conditions, GJS `define` shims, React
13
+ dedupe, the polyfills-first contract). This package carries only the
14
+ Tamagui-specific parts.
15
+
16
+ ## Exports
17
+
18
+ | export | what it is |
19
+ | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
20
+ | `tamaguiPlugin` | per-source `transform` (lazy-init/StyleSheet/Platform fixes, hover + animation gates, sheet/portal native-build fixes) + post-bundle `generateBundle` (duplicate-`init_esm$1` dedupe) |
21
+ | `tamaguiAliases(options)` | `@tamagui/core` + `@tamagui/web` → `@tamagui/core/native`, `tamagui` meta-package → your lean barrel, optional lucide shim (string finds) |
22
+ | `tamaguiLinkedAliases(options)` | same entries as exact-match regexes — for alias lists that mix in absolute-path replacements (pnpm `link:` consumers) |
23
+ | `tamaguiPatchAnchors` | every regex the patches anchor on, exported for the anchor-verification test |
24
+
25
+ ## Usage
26
+
27
+ ```ts
28
+ import { gnomeAliases, gnomeConditions, gnomeDefine } from "@react-gnome/vite-plugin";
29
+ import { tamaguiAliases, tamaguiPlugin } from "@multiplatform.one/vite-plugin-gnome";
30
+ import { resolve } from "node:path";
31
+
32
+ export default defineConfig({
33
+ plugins: [react(), tamaguiPlugin],
34
+ resolve: {
35
+ conditions: [...gnomeConditions],
36
+ alias: [
37
+ ...gnomeAliases(reactGnomePackagesDir),
38
+ ...tamaguiAliases({
39
+ tamaguiBarrel: resolve(import.meta.dirname, "src/tamagui-barrel.ts"),
40
+ }),
41
+ ],
42
+ },
43
+ define: gnomeDefine("production"),
44
+ });
45
+ ```
46
+
47
+ ## The anchor-verification test
48
+
49
+ The patches are FRAGILE BY DESIGN: each one anchors on a regex over the
50
+ `@tamagui/*` dist files. A Tamagui version bump that reshapes those
51
+ files makes a patch silently no-op in the build — the breakage only
52
+ surfaces as runtime failures under GJS. `tests/anchors.test.ts` asserts
53
+ every anchor still matches the pinned `@tamagui/*` devDependencies:
54
+
55
+ ```sh
56
+ pnpm --filter @multiplatform.one/vite-plugin-gnome test
57
+ ```
58
+
59
+ **When bumping Tamagui:** bump the `@tamagui/core` / `@tamagui/sheet` /
60
+ `@tamagui/portal` devDependencies here in lockstep with the app, run
61
+ the test, and re-derive any anchor it reports as lost.
package/lib/index.cjs ADDED
@@ -0,0 +1,222 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ //#region src/index.ts
4
+ const sheetPatch = {
5
+ name: "sheet-animated-view-relative-position",
6
+ module: "@tamagui/sheet",
7
+ precondition: "forcedContentHeight",
8
+ find: /(style:\s*\[\s*\{\s*\n?\s*)position:\s*['"]absolute['"](,\s*\n?\s*zIndex,\s*\n?\s*width:\s*['"]100%['"],\s*\n?\s*height:\s*forcedContentHeight)/g,
9
+ replace: "$1position: \"relative\"$2"
10
+ };
11
+ const portalPatch = {
12
+ name: "portal-needs-repropagation-on-gnome",
13
+ module: "@tamagui/portal",
14
+ precondition: "needsPortalRepropagation",
15
+ find: /return isAndroid \|\| isIos;/,
16
+ replace: "return true; /* react-gnome: Gorhom portal loses context on every native platform */"
17
+ };
18
+ const corePrecondition = "console.warn(\"no-op native\")";
19
+ const corePatches = [
20
+ {
21
+ name: "core-noop-native-stub",
22
+ module: "@tamagui/core",
23
+ precondition: corePrecondition,
24
+ find: /function\s*\(\s*\)\s*\{\s*console\.warn\("no-op native"\);?\s*\}/g,
25
+ replace: "function(input) { return input && typeof input === 'object' ? Object.entries(input) : []; }"
26
+ },
27
+ {
28
+ name: "core-pass-down-prop-reorder",
29
+ module: "@tamagui/core",
30
+ precondition: corePrecondition,
31
+ find: /\} else viewProps\[key\] = val;/,
32
+ replace: "} else { delete viewProps[key]; viewProps[key] = val; }"
33
+ },
34
+ {
35
+ name: "core-text-ancestor-context",
36
+ module: "@tamagui/core",
37
+ precondition: corePrecondition,
38
+ find: /native\.unstable_TextAncestorContext/g,
39
+ replace: "(native.unstable_TextAncestorContext || native.TextAncestorContext)"
40
+ },
41
+ {
42
+ name: "core-init-platform-chain",
43
+ module: "@tamagui/core",
44
+ precondition: corePrecondition,
45
+ find: /var\s+init_Platform\s*=\s*__esmMin\(\(\(\)\s*=>\s*\{\s*init_esm\$1\(\);\s*\}\)\);/,
46
+ replace: "var init_Platform = __esmMin((() => { init_esm$1(); init_Platform$1(); }));"
47
+ },
48
+ {
49
+ name: "core-stylesheet-declaration-shims",
50
+ module: "@tamagui/core",
51
+ precondition: corePrecondition,
52
+ find: /function StyleSheet\(styles, options\) \{\}/g,
53
+ replace: "function StyleSheet(styles, options) {} StyleSheet.create = (s) => s; StyleSheet.compose = (a, b) => [a, b]; StyleSheet.flatten = (s) => Array.isArray(s) ? Object.assign({}, ...s.filter(Boolean)) : (s || {}); StyleSheet.hairlineWidth = 1; StyleSheet.absoluteFill = { position: 'absolute', left: 0, right: 0, top: 0, bottom: 0 }; StyleSheet.absoluteFillObject = StyleSheet.absoluteFill;"
54
+ },
55
+ {
56
+ name: "core-runtime-animation-prop-gate",
57
+ module: "@tamagui/core",
58
+ precondition: corePrecondition,
59
+ find: /var hasAnimationProp = Boolean\(!isHOC && "transition" in props \|\| props\.style && hasAnimatedStyleValue\(props\.style\)\);/,
60
+ replace: "var hasAnimationProp = Boolean(!isHOC && (\"transition\" in props || \"animation\" in props) || props.style && hasAnimatedStyleValue(props.style));"
61
+ },
62
+ {
63
+ name: "core-attach-hover-on-desktop",
64
+ module: "@tamagui/core",
65
+ precondition: corePrecondition,
66
+ find: /var attachHover = false;/g,
67
+ replace: "var attachHover = Boolean(needsHoverState || onHoverIn || onHoverOut || onMouseEnter || onMouseLeave);"
68
+ },
69
+ {
70
+ name: "core-forward-hover-handlers",
71
+ module: "@tamagui/core",
72
+ precondition: corePrecondition,
73
+ find: /if \(events\.onBlur\) viewProps\["onBlur"\] = events\.onBlur;/,
74
+ replace: "if (events.onBlur) viewProps[\"onBlur\"] = events.onBlur; if (events.onMouseEnter) viewProps[\"onMouseEnter\"] = events.onMouseEnter; if (events.onMouseLeave) viewProps[\"onMouseLeave\"] = events.onMouseLeave;"
75
+ },
76
+ {
77
+ name: "core-use-did-finish-ssr",
78
+ module: "@tamagui/core",
79
+ precondition: corePrecondition,
80
+ find: /function useDidFinishSSR\(\)\s*\{\s*react\.useContext\(ClientOnlyContext\);\s*return true;\s*\}/g,
81
+ replace: "function useDidFinishSSR() { return true; }"
82
+ },
83
+ {
84
+ name: "core-use-is-client-only",
85
+ module: "@tamagui/core",
86
+ precondition: corePrecondition,
87
+ find: /var useIsClientOnly;\s*var (init_index_native\$\d+)/g,
88
+ replace: "var useIsClientOnly = () => false; var $1"
89
+ },
90
+ {
91
+ name: "core-use-isomorphic-insertion-effect",
92
+ module: "@tamagui/core",
93
+ precondition: corePrecondition,
94
+ find: /var useIsomorphicInsertionEffect;/g,
95
+ replace: "var useIsomorphicInsertionEffect = (react.useInsertionEffect || react.useLayoutEffect);"
96
+ }
97
+ ];
98
+ const initEsmVendorSignature = {
99
+ name: "core-init-esm-vendor-signature",
100
+ module: "@tamagui/core",
101
+ precondition: "init_AssetRegistry();",
102
+ find: /var\s+init_esm\$1\s*=\s*__esmMin\(\(\(\)\s*=>\s*\{\s*init_AssetRegistry\(\);/
103
+ };
104
+ /**
105
+ * Every source pattern the patch set anchors on, in apply order. The
106
+ * package's anchor-verification test asserts each one still matches
107
+ * the pinned @tamagui/* dist files — the loud-failure guard for
108
+ * Tamagui version bumps.
109
+ */
110
+ const tamaguiPatchAnchors = [
111
+ sheetPatch,
112
+ portalPatch,
113
+ ...corePatches,
114
+ initEsmVendorSignature
115
+ ];
116
+ const tamaguiPlugin = {
117
+ name: "rgn-tamagui-noop-fix",
118
+ enforce: "post",
119
+ transform(code, id) {
120
+ if (id.includes(sheetPatch.module) && code.includes(sheetPatch.precondition)) {
121
+ const out = code.replace(sheetPatch.find, sheetPatch.replace);
122
+ if (out !== code) return out;
123
+ }
124
+ if (id.includes(portalPatch.module) && code.includes(portalPatch.precondition)) {
125
+ const out = code.replace(portalPatch.find, portalPatch.replace);
126
+ if (out !== code) return out;
127
+ }
128
+ if (!id.includes("@tamagui/core") && !id.includes("@tamagui/web")) return;
129
+ if (!code.includes(corePrecondition)) return;
130
+ let out = code;
131
+ for (const patch of corePatches) out = out.replace(patch.find, patch.replace);
132
+ return out;
133
+ },
134
+ generateBundle(_opts, bundle) {
135
+ for (const fileName of Object.keys(bundle)) {
136
+ const c = bundle[fileName];
137
+ if (c.type !== "chunk") continue;
138
+ let src = c.code;
139
+ const m = src.match(initEsmVendorSignature.find);
140
+ if (!m || m.index === void 0) continue;
141
+ const firstDeclIdx = m.index;
142
+ const bodyStart = src.indexOf("{", firstDeclIdx + 29);
143
+ let depth = 1;
144
+ let i = bodyStart + 1;
145
+ for (; i < src.length && depth > 0; i++) if (src[i] === "{") depth++;
146
+ else if (src[i] === "}") depth--;
147
+ const firstEnd = src.indexOf("));", i) + 3;
148
+ const renamed = src.slice(firstDeclIdx, firstEnd).replace("var init_esm$1 = __esmMin", "var init_esm$1_vendor = __esmMin");
149
+ const secondDeclStart = src.indexOf("var init_esm$1 = __esmMin", firstEnd);
150
+ if (secondDeclStart < 0) continue;
151
+ const between = src.slice(firstEnd, secondDeclStart).replace(/init_esm\$1\(\)/g, "init_esm$1_vendor()");
152
+ const sBody = src.indexOf("{", secondDeclStart + 29);
153
+ let d2 = 1;
154
+ let j = sBody + 1;
155
+ for (; j < src.length && d2 > 0; j++) if (src[j] === "{") d2++;
156
+ else if (src[j] === "}") d2--;
157
+ const secondDeclEnd = src.indexOf("));", j) + 3;
158
+ const secondPatched = src.slice(secondDeclStart, secondDeclEnd).replace("init_esm$1();", "init_esm$1_vendor();");
159
+ src = src.slice(0, firstDeclIdx) + renamed + between + secondPatched + src.slice(secondDeclEnd);
160
+ c.code = src;
161
+ }
162
+ }
163
+ };
164
+ /**
165
+ * Tamagui-specific resolver aliases for consumers whose @tamagui/*
166
+ * packages resolve by bare name (string finds keep @rollup/plugin-alias
167
+ * prefix semantics). Funnels `@tamagui/core` / `@tamagui/web` both into
168
+ * the single `@tamagui/core/native` module so the TamaguiProvider's
169
+ * config registry and high-level component lookups land in one place.
170
+ */
171
+ function tamaguiAliases(options) {
172
+ return [
173
+ ...options.lucideIcons ? [{
174
+ find: "@tamagui/lucide-icons-2",
175
+ replacement: options.lucideIcons
176
+ }] : [],
177
+ {
178
+ find: "@tamagui/core",
179
+ replacement: "@tamagui/core/native"
180
+ },
181
+ {
182
+ find: "@tamagui/web",
183
+ replacement: "@tamagui/core/native"
184
+ },
185
+ {
186
+ find: "tamagui",
187
+ replacement: options.tamaguiBarrel
188
+ }
189
+ ];
190
+ }
191
+ /**
192
+ * Same aliases with exact-match regexes — for consumers whose alias
193
+ * list mixes in absolute-path replacements (e.g. apps pulling
194
+ * @react-gnome in over pnpm `link:`), where a plain string prefix
195
+ * alias could re-mangle other entries' replacements.
196
+ */
197
+ function tamaguiLinkedAliases(options) {
198
+ return [
199
+ ...options.lucideIcons ? [{
200
+ find: /^@tamagui\/lucide-icons-2$/,
201
+ replacement: options.lucideIcons
202
+ }] : [],
203
+ {
204
+ find: /^@tamagui\/core$/,
205
+ replacement: "@tamagui/core/native"
206
+ },
207
+ {
208
+ find: /^@tamagui\/web$/,
209
+ replacement: "@tamagui/core/native"
210
+ },
211
+ {
212
+ find: /^tamagui$/,
213
+ replacement: options.tamaguiBarrel
214
+ }
215
+ ];
216
+ }
217
+
218
+ //#endregion
219
+ exports.tamaguiAliases = tamaguiAliases;
220
+ exports.tamaguiLinkedAliases = tamaguiLinkedAliases;
221
+ exports.tamaguiPatchAnchors = tamaguiPatchAnchors;
222
+ exports.tamaguiPlugin = tamaguiPlugin;
package/lib/index.mjs ADDED
@@ -0,0 +1,217 @@
1
+ //#region src/index.ts
2
+ const sheetPatch = {
3
+ name: "sheet-animated-view-relative-position",
4
+ module: "@tamagui/sheet",
5
+ precondition: "forcedContentHeight",
6
+ find: /(style:\s*\[\s*\{\s*\n?\s*)position:\s*['"]absolute['"](,\s*\n?\s*zIndex,\s*\n?\s*width:\s*['"]100%['"],\s*\n?\s*height:\s*forcedContentHeight)/g,
7
+ replace: "$1position: \"relative\"$2"
8
+ };
9
+ const portalPatch = {
10
+ name: "portal-needs-repropagation-on-gnome",
11
+ module: "@tamagui/portal",
12
+ precondition: "needsPortalRepropagation",
13
+ find: /return isAndroid \|\| isIos;/,
14
+ replace: "return true; /* react-gnome: Gorhom portal loses context on every native platform */"
15
+ };
16
+ const corePrecondition = "console.warn(\"no-op native\")";
17
+ const corePatches = [
18
+ {
19
+ name: "core-noop-native-stub",
20
+ module: "@tamagui/core",
21
+ precondition: corePrecondition,
22
+ find: /function\s*\(\s*\)\s*\{\s*console\.warn\("no-op native"\);?\s*\}/g,
23
+ replace: "function(input) { return input && typeof input === 'object' ? Object.entries(input) : []; }"
24
+ },
25
+ {
26
+ name: "core-pass-down-prop-reorder",
27
+ module: "@tamagui/core",
28
+ precondition: corePrecondition,
29
+ find: /\} else viewProps\[key\] = val;/,
30
+ replace: "} else { delete viewProps[key]; viewProps[key] = val; }"
31
+ },
32
+ {
33
+ name: "core-text-ancestor-context",
34
+ module: "@tamagui/core",
35
+ precondition: corePrecondition,
36
+ find: /native\.unstable_TextAncestorContext/g,
37
+ replace: "(native.unstable_TextAncestorContext || native.TextAncestorContext)"
38
+ },
39
+ {
40
+ name: "core-init-platform-chain",
41
+ module: "@tamagui/core",
42
+ precondition: corePrecondition,
43
+ find: /var\s+init_Platform\s*=\s*__esmMin\(\(\(\)\s*=>\s*\{\s*init_esm\$1\(\);\s*\}\)\);/,
44
+ replace: "var init_Platform = __esmMin((() => { init_esm$1(); init_Platform$1(); }));"
45
+ },
46
+ {
47
+ name: "core-stylesheet-declaration-shims",
48
+ module: "@tamagui/core",
49
+ precondition: corePrecondition,
50
+ find: /function StyleSheet\(styles, options\) \{\}/g,
51
+ replace: "function StyleSheet(styles, options) {} StyleSheet.create = (s) => s; StyleSheet.compose = (a, b) => [a, b]; StyleSheet.flatten = (s) => Array.isArray(s) ? Object.assign({}, ...s.filter(Boolean)) : (s || {}); StyleSheet.hairlineWidth = 1; StyleSheet.absoluteFill = { position: 'absolute', left: 0, right: 0, top: 0, bottom: 0 }; StyleSheet.absoluteFillObject = StyleSheet.absoluteFill;"
52
+ },
53
+ {
54
+ name: "core-runtime-animation-prop-gate",
55
+ module: "@tamagui/core",
56
+ precondition: corePrecondition,
57
+ find: /var hasAnimationProp = Boolean\(!isHOC && "transition" in props \|\| props\.style && hasAnimatedStyleValue\(props\.style\)\);/,
58
+ replace: "var hasAnimationProp = Boolean(!isHOC && (\"transition\" in props || \"animation\" in props) || props.style && hasAnimatedStyleValue(props.style));"
59
+ },
60
+ {
61
+ name: "core-attach-hover-on-desktop",
62
+ module: "@tamagui/core",
63
+ precondition: corePrecondition,
64
+ find: /var attachHover = false;/g,
65
+ replace: "var attachHover = Boolean(needsHoverState || onHoverIn || onHoverOut || onMouseEnter || onMouseLeave);"
66
+ },
67
+ {
68
+ name: "core-forward-hover-handlers",
69
+ module: "@tamagui/core",
70
+ precondition: corePrecondition,
71
+ find: /if \(events\.onBlur\) viewProps\["onBlur"\] = events\.onBlur;/,
72
+ replace: "if (events.onBlur) viewProps[\"onBlur\"] = events.onBlur; if (events.onMouseEnter) viewProps[\"onMouseEnter\"] = events.onMouseEnter; if (events.onMouseLeave) viewProps[\"onMouseLeave\"] = events.onMouseLeave;"
73
+ },
74
+ {
75
+ name: "core-use-did-finish-ssr",
76
+ module: "@tamagui/core",
77
+ precondition: corePrecondition,
78
+ find: /function useDidFinishSSR\(\)\s*\{\s*react\.useContext\(ClientOnlyContext\);\s*return true;\s*\}/g,
79
+ replace: "function useDidFinishSSR() { return true; }"
80
+ },
81
+ {
82
+ name: "core-use-is-client-only",
83
+ module: "@tamagui/core",
84
+ precondition: corePrecondition,
85
+ find: /var useIsClientOnly;\s*var (init_index_native\$\d+)/g,
86
+ replace: "var useIsClientOnly = () => false; var $1"
87
+ },
88
+ {
89
+ name: "core-use-isomorphic-insertion-effect",
90
+ module: "@tamagui/core",
91
+ precondition: corePrecondition,
92
+ find: /var useIsomorphicInsertionEffect;/g,
93
+ replace: "var useIsomorphicInsertionEffect = (react.useInsertionEffect || react.useLayoutEffect);"
94
+ }
95
+ ];
96
+ const initEsmVendorSignature = {
97
+ name: "core-init-esm-vendor-signature",
98
+ module: "@tamagui/core",
99
+ precondition: "init_AssetRegistry();",
100
+ find: /var\s+init_esm\$1\s*=\s*__esmMin\(\(\(\)\s*=>\s*\{\s*init_AssetRegistry\(\);/
101
+ };
102
+ /**
103
+ * Every source pattern the patch set anchors on, in apply order. The
104
+ * package's anchor-verification test asserts each one still matches
105
+ * the pinned @tamagui/* dist files — the loud-failure guard for
106
+ * Tamagui version bumps.
107
+ */
108
+ const tamaguiPatchAnchors = [
109
+ sheetPatch,
110
+ portalPatch,
111
+ ...corePatches,
112
+ initEsmVendorSignature
113
+ ];
114
+ const tamaguiPlugin = {
115
+ name: "rgn-tamagui-noop-fix",
116
+ enforce: "post",
117
+ transform(code, id) {
118
+ if (id.includes(sheetPatch.module) && code.includes(sheetPatch.precondition)) {
119
+ const out = code.replace(sheetPatch.find, sheetPatch.replace);
120
+ if (out !== code) return out;
121
+ }
122
+ if (id.includes(portalPatch.module) && code.includes(portalPatch.precondition)) {
123
+ const out = code.replace(portalPatch.find, portalPatch.replace);
124
+ if (out !== code) return out;
125
+ }
126
+ if (!id.includes("@tamagui/core") && !id.includes("@tamagui/web")) return;
127
+ if (!code.includes(corePrecondition)) return;
128
+ let out = code;
129
+ for (const patch of corePatches) out = out.replace(patch.find, patch.replace);
130
+ return out;
131
+ },
132
+ generateBundle(_opts, bundle) {
133
+ for (const fileName of Object.keys(bundle)) {
134
+ const c = bundle[fileName];
135
+ if (c.type !== "chunk") continue;
136
+ let src = c.code;
137
+ const m = src.match(initEsmVendorSignature.find);
138
+ if (!m || m.index === void 0) continue;
139
+ const firstDeclIdx = m.index;
140
+ const bodyStart = src.indexOf("{", firstDeclIdx + 29);
141
+ let depth = 1;
142
+ let i = bodyStart + 1;
143
+ for (; i < src.length && depth > 0; i++) if (src[i] === "{") depth++;
144
+ else if (src[i] === "}") depth--;
145
+ const firstEnd = src.indexOf("));", i) + 3;
146
+ const renamed = src.slice(firstDeclIdx, firstEnd).replace("var init_esm$1 = __esmMin", "var init_esm$1_vendor = __esmMin");
147
+ const secondDeclStart = src.indexOf("var init_esm$1 = __esmMin", firstEnd);
148
+ if (secondDeclStart < 0) continue;
149
+ const between = src.slice(firstEnd, secondDeclStart).replace(/init_esm\$1\(\)/g, "init_esm$1_vendor()");
150
+ const sBody = src.indexOf("{", secondDeclStart + 29);
151
+ let d2 = 1;
152
+ let j = sBody + 1;
153
+ for (; j < src.length && d2 > 0; j++) if (src[j] === "{") d2++;
154
+ else if (src[j] === "}") d2--;
155
+ const secondDeclEnd = src.indexOf("));", j) + 3;
156
+ const secondPatched = src.slice(secondDeclStart, secondDeclEnd).replace("init_esm$1();", "init_esm$1_vendor();");
157
+ src = src.slice(0, firstDeclIdx) + renamed + between + secondPatched + src.slice(secondDeclEnd);
158
+ c.code = src;
159
+ }
160
+ }
161
+ };
162
+ /**
163
+ * Tamagui-specific resolver aliases for consumers whose @tamagui/*
164
+ * packages resolve by bare name (string finds keep @rollup/plugin-alias
165
+ * prefix semantics). Funnels `@tamagui/core` / `@tamagui/web` both into
166
+ * the single `@tamagui/core/native` module so the TamaguiProvider's
167
+ * config registry and high-level component lookups land in one place.
168
+ */
169
+ function tamaguiAliases(options) {
170
+ return [
171
+ ...options.lucideIcons ? [{
172
+ find: "@tamagui/lucide-icons-2",
173
+ replacement: options.lucideIcons
174
+ }] : [],
175
+ {
176
+ find: "@tamagui/core",
177
+ replacement: "@tamagui/core/native"
178
+ },
179
+ {
180
+ find: "@tamagui/web",
181
+ replacement: "@tamagui/core/native"
182
+ },
183
+ {
184
+ find: "tamagui",
185
+ replacement: options.tamaguiBarrel
186
+ }
187
+ ];
188
+ }
189
+ /**
190
+ * Same aliases with exact-match regexes — for consumers whose alias
191
+ * list mixes in absolute-path replacements (e.g. apps pulling
192
+ * @react-gnome in over pnpm `link:`), where a plain string prefix
193
+ * alias could re-mangle other entries' replacements.
194
+ */
195
+ function tamaguiLinkedAliases(options) {
196
+ return [
197
+ ...options.lucideIcons ? [{
198
+ find: /^@tamagui\/lucide-icons-2$/,
199
+ replacement: options.lucideIcons
200
+ }] : [],
201
+ {
202
+ find: /^@tamagui\/core$/,
203
+ replacement: "@tamagui/core/native"
204
+ },
205
+ {
206
+ find: /^@tamagui\/web$/,
207
+ replacement: "@tamagui/core/native"
208
+ },
209
+ {
210
+ find: /^tamagui$/,
211
+ replacement: options.tamaguiBarrel
212
+ }
213
+ ];
214
+ }
215
+
216
+ //#endregion
217
+ export { tamaguiAliases, tamaguiLinkedAliases, tamaguiPatchAnchors, tamaguiPlugin };
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@multiplatform.one/vite-plugin-gnome",
3
+ "version": "6.2.0",
4
+ "description": "Vite plugin that makes Tamagui render under react-gnome (GTK4/GJS) — bundle patches for @tamagui/core's native lazy-init chains, the sheet/portal native builds, the hover/animation gates, plus the Tamagui-specific resolver aliases. Pairs with @react-gnome/vite-plugin (generic GJS aliases/conditions/define).",
5
+ "keywords": [
6
+ "gjs",
7
+ "gnome",
8
+ "gtk4",
9
+ "multiplatform.one",
10
+ "react-gnome",
11
+ "tamagui",
12
+ "vite-plugin"
13
+ ],
14
+ "homepage": "https://multiplatform.one",
15
+ "bugs": {
16
+ "url": "https://gitlab.com/bitspur/multiplatform.one/multiplatform.one/issues",
17
+ "email": "support@risserlabs.com"
18
+ },
19
+ "license": "Apache-2.0",
20
+ "author": "BitSpur <support@risserlabs.com> (https://risserlabs.com)",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://gitlab.com/bitspur/frappe/multiplatform.one.git",
24
+ "directory": "public/vite-plugin-gnome"
25
+ },
26
+ "source": "src/index.ts",
27
+ "files": [
28
+ "lib",
29
+ "types",
30
+ "src",
31
+ "!types/.tsbuildinfo"
32
+ ],
33
+ "type": "module",
34
+ "sideEffects": false,
35
+ "main": "lib/index.cjs",
36
+ "module": "lib/index.mjs",
37
+ "types": "types/index.d.ts",
38
+ "exports": {
39
+ ".": {
40
+ "source": "./src/index.ts",
41
+ "types": "./types/index.d.ts",
42
+ "import": "./lib/index.mjs",
43
+ "require": "./lib/index.cjs"
44
+ },
45
+ "./package.json": "./package.json"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "devDependencies": {
51
+ "@tamagui/core": "2.0.0-rc.41",
52
+ "@tamagui/portal": "2.0.0-rc.41",
53
+ "@tamagui/sheet": "2.0.0-rc.41",
54
+ "@types/node": "^25.6.0",
55
+ "typescript": "~5.9.3",
56
+ "vite": "^8.0.0",
57
+ "vitest": "^4.1.5"
58
+ },
59
+ "peerDependencies": {
60
+ "vite": ">=5"
61
+ },
62
+ "scripts": {
63
+ "typecheck": "tsc --noEmit",
64
+ "build": "rm -rf lib types 2>/dev/null && tsc -b --emitDeclarationOnly && tsdown",
65
+ "test": "vitest run"
66
+ }
67
+ }
package/src/index.ts ADDED
@@ -0,0 +1,440 @@
1
+ // Tamagui-under-react-gnome patch set for the GNOME (GTK4/GJS) target.
2
+ //
3
+ // Real Tamagui (`@tamagui/core/native`) assumes a react-native-web-lite
4
+ // runtime: Platform / StyleSheet / NativeAnimatedHelper / forwardedProps
5
+ // initialized in a specific order under a real React Native env. Under
6
+ // GJS none of that holds, so the upstream packages fail at module init
7
+ // or first render. Rather than reimplement Tamagui's components we
8
+ // patch the bundler's view of them.
9
+ //
10
+ // Exported pieces:
11
+ // - tamaguiPlugin: per-source `transform` (no-op stub fix, Platform
12
+ // and StyleSheet shims) + post-bundle `generateBundle` (resolves
13
+ // the duplicate-`init_esm$1` collision between Tamagui's vendored
14
+ // RN-Web-Lite init chain and real RN's index init chain).
15
+ // - tamaguiAliases(options) / tamaguiLinkedAliases(options): the
16
+ // Tamagui-specific resolver aliases — funnel `@tamagui/core` /
17
+ // `@tamagui/web` into the single `@tamagui/core/native` module and
18
+ // map the `tamagui` meta-package onto a consumer-provided lean
19
+ // barrel. The generic react-gnome aliases (react-native →
20
+ // @react-gnome/react-native, conditions, define, …) live in
21
+ // @react-gnome/vite-plugin and compose with these.
22
+ // - tamaguiPatchAnchors: every regex the transform/generateBundle
23
+ // anchors on, exported so the package's anchor-verification test
24
+ // fails LOUDLY when a Tamagui version bump reshapes the dist files
25
+ // and a patch would silently stop firing.
26
+ //
27
+ // IMPORTANT version note: every anchor below is verified against the
28
+ // pinned @tamagui/* devDependencies by tests/anchors.test.ts. If
29
+ // Tamagui is bumped, that test is the tripwire — a patch whose anchor
30
+ // no longer matches no-ops silently in the build and only manifests as
31
+ // runtime breakage under GJS.
32
+
33
+ import type { Plugin } from "vite";
34
+
35
+ /** One Vite `resolve.alias` entry (the array form Vite accepts). */
36
+ export interface TamaguiAliasEntry {
37
+ find: string | RegExp;
38
+ replacement: string;
39
+ }
40
+
41
+ /**
42
+ * A source pattern one of the bundle patches anchors on. `find` must
43
+ * keep matching the dist files of `module` for the patch to fire;
44
+ * `replace` is the rewrite (absent for the bundle-level dedupe
45
+ * signature, whose rewrite is procedural).
46
+ */
47
+ export interface TamaguiPatchAnchor {
48
+ name: string;
49
+ module: "@tamagui/core" | "@tamagui/sheet" | "@tamagui/portal";
50
+ /** transform only runs on files containing this substring */
51
+ precondition: string;
52
+ find: RegExp;
53
+ replace?: string;
54
+ }
55
+
56
+ interface TamaguiPatch extends TamaguiPatchAnchor {
57
+ replace: string;
58
+ }
59
+
60
+ // @tamagui/sheet: rewrite the AnimatedView's `position: 'absolute'`
61
+ // to `position: 'relative'`. Yoga treats abs-positioned children as
62
+ // out-of-flow → parent reports 0 height → GTK's allocation-based
63
+ // hit-test can't reach the Cancel/Submit buttons even though
64
+ // they paint at non-zero positions. Relative lets the sheet flow
65
+ // in-place with real height; visually it sits at the bottom of
66
+ // the parent stack (where un-animated translateY would leave it
67
+ // anyway), and the drag/animation logic still runs at the JS
68
+ // layer above. Anchored on the AnimatedView style block's
69
+ // distinctive shape (zIndex + width + forcedContentHeight) so
70
+ // we don't touch other position:absolute usage.
71
+ const sheetPatch: TamaguiPatch = {
72
+ name: "sheet-animated-view-relative-position",
73
+ module: "@tamagui/sheet",
74
+ precondition: "forcedContentHeight",
75
+ find: /(style:\s*\[\s*\{\s*\n?\s*)position:\s*['"]absolute['"](,\s*\n?\s*zIndex,\s*\n?\s*width:\s*['"]100%['"],\s*\n?\s*height:\s*forcedContentHeight)/g,
76
+ replace: '$1position: "relative"$2',
77
+ };
78
+
79
+ // @tamagui/portal: make `needsPortalRepropagation()` return true on GNOME.
80
+ // Tamagui's native portal is the Gorhom state-based portal, which lifts
81
+ // children into PortalProvider's React subtree — so portaled content (e.g.
82
+ // Popover.Content) loses every ancestor context, including Popper's scoped
83
+ // `refs` context. Tamagui restores it via RepropagateParentContexts ONLY
84
+ // when needsPortalRepropagation() is true, but the gate reads
85
+ // `return isAndroid || isIos` — react-gnome's Platform.OS is "gnome", so it
86
+ // returns false and the portaled Popover.Content reads an empty Popper
87
+ // context → `refs` undefined → hard render crash. After the isWeb +
88
+ // isTeleportEnabled checks above it, the remaining case is "native,
89
+ // non-teleport" which ALWAYS loses context with the Gorhom portal, so the
90
+ // correct answer is unconditional true (ios/android already returned true).
91
+ const portalPatch: TamaguiPatch = {
92
+ name: "portal-needs-repropagation-on-gnome",
93
+ module: "@tamagui/portal",
94
+ precondition: "needsPortalRepropagation",
95
+ find: /return isAndroid \|\| isIos;/,
96
+ replace: "return true; /* react-gnome: Gorhom portal loses context on every native platform */",
97
+ };
98
+
99
+ // Every @tamagui/core (and @tamagui/web, which consumers alias into
100
+ // core/native) patch is gated on this marker — it only exists in the
101
+ // native build where the broken no-op stubs live.
102
+ const corePrecondition = 'console.warn("no-op native")';
103
+
104
+ const corePatches: TamaguiPatch[] = [
105
+ // The native build stubs several helpers as warn-only no-ops; the
106
+ // first caller is Object.entries-shaped, so give it that behavior.
107
+ {
108
+ name: "core-noop-native-stub",
109
+ module: "@tamagui/core",
110
+ precondition: corePrecondition,
111
+ find: /function\s*\(\s*\)\s*\{\s*console\.warn\("no-op native"\);?\s*\}/g,
112
+ replace:
113
+ "function(input) { return input && typeof input === 'object' ? Object.entries(input) : []; }",
114
+ },
115
+ // getSplitStyles' passDownProp (the HOC pass-down path, e.g. TextArea =
116
+ // styled(Input)) assigns `viewProps[key] = val` — which KEEPS the key's
117
+ // ORIGINAL insertion position when the key was already passed down once.
118
+ // TextArea's `unstyled:false` default variant expands `height:"auto"`
119
+ // BEFORE the user's props are reached, pinning `height` ahead of `size`
120
+ // in the pass-down object; the inner Input pass then merges in iteration
121
+ // order at equal importance, so the `size` variant's computed height
122
+ // (rows × lineHeight, e.g. 69) overrides an EXPLICIT `height={180}` that
123
+ // came later in source order (web resolves the same control to 180).
124
+ // Delete-then-assign moves a re-passed prop to the END, mirroring
125
+ // source-prop order — the same move-to-end the media/pseudo branch of
126
+ // passDownProp already does.
127
+ {
128
+ name: "core-pass-down-prop-reorder",
129
+ module: "@tamagui/core",
130
+ precondition: corePrecondition,
131
+ find: /\} else viewProps\[key\] = val;/,
132
+ replace: "} else { delete viewProps[key]; viewProps[key] = val; }",
133
+ },
134
+ // Tamagui's vendored react-native-web exports `TextAncestorContext`
135
+ // (no unstable_ prefix). Tamagui's own getBaseViews reads it as
136
+ // `native.unstable_TextAncestorContext` → undefined → optimized
137
+ // native view path skipped → fallback emits `<div>` everywhere.
138
+ // Patch the read to use the unprefixed name.
139
+ {
140
+ name: "core-text-ancestor-context",
141
+ module: "@tamagui/core",
142
+ precondition: corePrecondition,
143
+ find: /native\.unstable_TextAncestorContext/g,
144
+ replace: "(native.unstable_TextAncestorContext || native.TextAncestorContext)",
145
+ },
146
+ // @tamagui/core/native.cjs bakes in two copies of Platform from
147
+ // its vendored react-native-web-internals: `Platform` (initialized
148
+ // by `init_Platform` — which only calls init_esm$1() and DOESN'T
149
+ // assign the global) and `Platform$1` (initialized by
150
+ // `init_Platform$1` which DOES assign Platform = { OS: "web", ...
151
+ // }). When NativeAnimatedHelper inits, it calls init_Platform()
152
+ // and then reads Platform.OS → undefined → throws. Patch the
153
+ // broken init_Platform so it also calls init_Platform$1().
154
+ {
155
+ name: "core-init-platform-chain",
156
+ module: "@tamagui/core",
157
+ precondition: corePrecondition,
158
+ find: /var\s+init_Platform\s*=\s*__esmMin\(\(\(\)\s*=>\s*\{\s*init_esm\$1\(\);\s*\}\)\);/,
159
+ replace: "var init_Platform = __esmMin((() => { init_esm$1(); init_Platform$1(); }));",
160
+ },
161
+ // The vendored RN-Web bundle declares StyleSheet as a bare function
162
+ // and only attaches `.create / .compose / .flatten / ...` inside its
163
+ // `init_StyleSheet` __esmMin. Tamagui's `init_VirtualizedList*` chain
164
+ // calls StyleSheet.create at module-init time before init_StyleSheet
165
+ // is reachable through the (now-conflated) init_esm$1 — because two
166
+ // init_esm$1 functions land in the same JS scope and the second one
167
+ // wins, so the StyleSheet init never fires. Attach the minimum
168
+ // shims directly on the declaration so the create-call works
169
+ // regardless of init order.
170
+ {
171
+ name: "core-stylesheet-declaration-shims",
172
+ module: "@tamagui/core",
173
+ precondition: corePrecondition,
174
+ find: /function StyleSheet\(styles, options\) \{\}/g,
175
+ replace:
176
+ "function StyleSheet(styles, options) {} " +
177
+ "StyleSheet.create = (s) => s; " +
178
+ "StyleSheet.compose = (a, b) => [a, b]; " +
179
+ "StyleSheet.flatten = (s) => Array.isArray(s) ? Object.assign({}, ...s.filter(Boolean)) : (s || {}); " +
180
+ "StyleSheet.hairlineWidth = 1; " +
181
+ "StyleSheet.absoluteFill = { position: 'absolute', left: 0, right: 0, top: 0, bottom: 0 }; " +
182
+ "StyleSheet.absoluteFillObject = StyleSheet.absoluteFill;",
183
+ },
184
+ // Tamagui v2's animation gate at @tamagui/core/native:hasAnimationProp
185
+ // only fires when EITHER a compile-time `transition` prop is emitted
186
+ // OR a style value carries an `_animation` sentinel. The runtime
187
+ // `animation="bouncy"` prop is ignored entirely — that translation
188
+ // lives in `@tamagui/babel-plugin` (Metro) / `@tamagui/vite-plugin`
189
+ // (Vite/web), neither of which targets our GJS env. Open the gate at
190
+ // the source: rewrite the assignment so it ALSO fires whenever
191
+ // `"animation" in props`. With that, useAnimations gets invoked with
192
+ // each prop change and the @react-gnome/tamagui driver's per-key
193
+ // AnimatedValue / forceUpdate loop drives the component layer.
194
+ {
195
+ name: "core-runtime-animation-prop-gate",
196
+ module: "@tamagui/core",
197
+ precondition: corePrecondition,
198
+ find: /var hasAnimationProp = Boolean\(!isHOC && "transition" in props \|\| props\.style && hasAnimatedStyleValue\(props\.style\)\);/,
199
+ replace:
200
+ 'var hasAnimationProp = Boolean(!isHOC && ("transition" in props || "animation" in props) || props.style && hasAnimatedStyleValue(props.style));',
201
+ },
202
+ // The NATIVE build hard-codes `attachHover = false` (touch platforms have
203
+ // no hover), so the events object never includes the onMouseEnter/
204
+ // onMouseLeave handlers that drive the hoverStyle state machine and call
205
+ // user onHoverIn/onHoverOut. GNOME is a pointer desktop — compute it the
206
+ // way the WEB build does (hover style present, or any hover/mouse handler
207
+ // passed). `needsHoverState` is declared on the preceding line of the
208
+ // same function, and the emitted onMouseEnter/onMouseLeave land on the
209
+ // host element where the renderer's maybeWireHoverHandler maps them to a
210
+ // Gtk.EventControllerMotion.
211
+ {
212
+ name: "core-attach-hover-on-desktop",
213
+ module: "@tamagui/core",
214
+ precondition: corePrecondition,
215
+ find: /var attachHover = false;/g,
216
+ replace:
217
+ "var attachHover = Boolean(needsHoverState || onHoverIn || onHoverOut || onMouseEnter || onMouseLeave);",
218
+ },
219
+ // …and useEvents (native) forwards ONLY focus/blur + the press family to
220
+ // the host — the hover handlers above would dead-end there. Forward them
221
+ // the same way focus/blur go through; the renderer's maybeWireHoverHandler
222
+ // turns them into a Gtk.EventControllerMotion on the widget.
223
+ {
224
+ name: "core-forward-hover-handlers",
225
+ module: "@tamagui/core",
226
+ precondition: corePrecondition,
227
+ find: /if \(events\.onBlur\) viewProps\["onBlur"\] = events\.onBlur;/,
228
+ replace:
229
+ 'if (events.onBlur) viewProps["onBlur"] = events.onBlur;' +
230
+ ' if (events.onMouseEnter) viewProps["onMouseEnter"] = events.onMouseEnter;' +
231
+ ' if (events.onMouseLeave) viewProps["onMouseLeave"] = events.onMouseLeave;',
232
+ },
233
+ // Tamagui's vendored useDidFinishSSR (multiple copies across the
234
+ // bundle from the meta-package + nested @tamagui/* deps) calls
235
+ // `react.useContext(ClientOnlyContext)` and then returns true
236
+ // unconditionally. The useContext is a leftover from a code path
237
+ // that branched on the value, but the lazy init pattern leaves
238
+ // ClientOnlyContext declared-but-undefined when an early caller
239
+ // (any styled component during initial render) hits it before
240
+ // init_ClientOnly_native runs. The useContext throws "Context is
241
+ // undefined". Since the return value is hard-coded `true`, the
242
+ // useContext call has no behavioral purpose — strip it.
243
+ {
244
+ name: "core-use-did-finish-ssr",
245
+ module: "@tamagui/core",
246
+ precondition: corePrecondition,
247
+ find: /function useDidFinishSSR\(\)\s*\{\s*react\.useContext\(ClientOnlyContext\);\s*return true;\s*\}/g,
248
+ replace: "function useDidFinishSSR() { return true; }",
249
+ },
250
+ // Same family — useIsClientOnly is `var`-declared and only
251
+ // assigned inside an __esmMin init. Stub it at declaration so
252
+ // callers hitting it before init runs get a real function.
253
+ {
254
+ name: "core-use-is-client-only",
255
+ module: "@tamagui/core",
256
+ precondition: corePrecondition,
257
+ find: /var useIsClientOnly;\s*var (init_index_native\$\d+)/g,
258
+ replace: "var useIsClientOnly = () => false; var $1",
259
+ },
260
+ // useIsomorphicInsertionEffect: same lazy-init bug. Pre-assign at
261
+ // declaration time. `react` is already in scope by the time any
262
+ // module body runs since the runtime imports it eagerly at the
263
+ // bundle top.
264
+ {
265
+ name: "core-use-isomorphic-insertion-effect",
266
+ module: "@tamagui/core",
267
+ precondition: corePrecondition,
268
+ find: /var useIsomorphicInsertionEffect;/g,
269
+ replace:
270
+ "var useIsomorphicInsertionEffect = (react.useInsertionEffect || react.useLayoutEffect);",
271
+ },
272
+ ];
273
+
274
+ // generateBundle's entry anchor: the first `var init_esm$1 = __esmMin`
275
+ // declaration whose body starts with init_AssetRegistry() — the
276
+ // distinctive signature of Tamagui's vendored RN-Web-Lite index init
277
+ // (vs real RN's index init). The rewrite is procedural (rename + caller
278
+ // re-pointing below), so this anchor carries no `replace`.
279
+ const initEsmVendorSignature: TamaguiPatchAnchor = {
280
+ name: "core-init-esm-vendor-signature",
281
+ module: "@tamagui/core",
282
+ precondition: "init_AssetRegistry();",
283
+ find: /var\s+init_esm\$1\s*=\s*__esmMin\(\(\(\)\s*=>\s*\{\s*init_AssetRegistry\(\);/,
284
+ };
285
+
286
+ /**
287
+ * Every source pattern the patch set anchors on, in apply order. The
288
+ * package's anchor-verification test asserts each one still matches
289
+ * the pinned @tamagui/* dist files — the loud-failure guard for
290
+ * Tamagui version bumps.
291
+ */
292
+ export const tamaguiPatchAnchors: readonly TamaguiPatchAnchor[] = [
293
+ sheetPatch,
294
+ portalPatch,
295
+ ...corePatches,
296
+ initEsmVendorSignature,
297
+ ];
298
+
299
+ export const tamaguiPlugin: Plugin = {
300
+ name: "rgn-tamagui-noop-fix",
301
+ enforce: "post",
302
+ transform(code, id) {
303
+ if (id.includes(sheetPatch.module) && code.includes(sheetPatch.precondition)) {
304
+ const out = code.replace(sheetPatch.find, sheetPatch.replace);
305
+ if (out !== code) return out;
306
+ }
307
+ if (id.includes(portalPatch.module) && code.includes(portalPatch.precondition)) {
308
+ const out = code.replace(portalPatch.find, portalPatch.replace);
309
+ if (out !== code) return out;
310
+ }
311
+ if (!id.includes("@tamagui/core") && !id.includes("@tamagui/web")) return;
312
+ if (!code.includes(corePrecondition)) return;
313
+ let out = code;
314
+ for (const patch of corePatches) {
315
+ out = out.replace(patch.find, patch.replace);
316
+ }
317
+ return out;
318
+ },
319
+ // The final bundle ends up with TWO `var init_esm$1 = __esmMin(...)`
320
+ // declarations in the SAME scope — one from tamagui's vendored
321
+ // react-native-web-lite index (runs init_StyleSheet, init_TextInput,
322
+ // init_forwardedProps, etc.) and one from real RN's index.js (runs
323
+ // init_Animated, init_NativeModules, etc.). They come from
324
+ // different source files so a per-file transform can't see both;
325
+ // the conflict only manifests in the bundled output. Rewrite the
326
+ // bundle here in generateBundle so both inits actually fire.
327
+ generateBundle(_opts, bundle) {
328
+ for (const fileName of Object.keys(bundle)) {
329
+ const c = bundle[fileName];
330
+ if (c.type !== "chunk") continue;
331
+ let src = c.code;
332
+ // Find the first `var init_esm$1 = __esmMin` declaration. The
333
+ // RN-Web vendor's chain starts with init_AssetRegistry +
334
+ // init_forwardedProps (distinctive signature). Match that to be
335
+ // sure we're renaming the vendor one, not the real-RN one.
336
+ const m = src.match(initEsmVendorSignature.find);
337
+ if (!m || m.index === undefined) continue;
338
+ const firstDeclIdx = m.index;
339
+ // Bracket-balance scan from the lambda body's opening `{` to
340
+ // find the matching `}));`.
341
+ const bodyStart = src.indexOf("{", firstDeclIdx + "var init_esm$1 = __esmMin((()".length);
342
+ let depth = 1;
343
+ let i = bodyStart + 1;
344
+ for (; i < src.length && depth > 0; i++) {
345
+ if (src[i] === "{") depth++;
346
+ else if (src[i] === "}") depth--;
347
+ }
348
+ const firstEnd = src.indexOf("));", i) + 3;
349
+ const renamed = src
350
+ .slice(firstDeclIdx, firstEnd)
351
+ .replace("var init_esm$1 = __esmMin", "var init_esm$1_vendor = __esmMin");
352
+ const secondDeclStart = src.indexOf("var init_esm$1 = __esmMin", firstEnd);
353
+ if (secondDeclStart < 0) continue;
354
+ // Rewrite every `init_esm$1()` call between firstEnd and
355
+ // secondDeclStart to call the renamed vendor init.
356
+ const between = src
357
+ .slice(firstEnd, secondDeclStart)
358
+ .replace(/init_esm\$1\(\)/g, "init_esm$1_vendor()");
359
+ // Inside the second decl's body, the first `init_esm$1();` call
360
+ // was meant to recurse into the vendor — point it at the rename.
361
+ const sBody = src.indexOf("{", secondDeclStart + "var init_esm$1 = __esmMin((()".length);
362
+ let d2 = 1;
363
+ let j = sBody + 1;
364
+ for (; j < src.length && d2 > 0; j++) {
365
+ if (src[j] === "{") d2++;
366
+ else if (src[j] === "}") d2--;
367
+ }
368
+ const secondDeclEnd = src.indexOf("));", j) + 3;
369
+ const secondPatched = src
370
+ .slice(secondDeclStart, secondDeclEnd)
371
+ .replace("init_esm$1();", "init_esm$1_vendor();");
372
+ src =
373
+ src.slice(0, firstDeclIdx) + renamed + between + secondPatched + src.slice(secondDeclEnd);
374
+ c.code = src;
375
+ }
376
+ },
377
+ };
378
+
379
+ /** Consumer-provided targets for the Tamagui-specific aliases. */
380
+ export interface TamaguiAliasOptions {
381
+ /**
382
+ * Absolute path to the consumer's lean `tamagui` meta-package barrel
383
+ * — a module re-exporting only the granular @tamagui/* packages its
384
+ * graph needs. The full meta-barrel drags web-only components (and
385
+ * real-RN Flow sources the bundler can't parse) into the GJS bundle.
386
+ */
387
+ tamaguiBarrel: string;
388
+ /**
389
+ * Optional absolute path to a lean `@tamagui/lucide-icons-2` shim
390
+ * re-exporting only the used icons from per-icon deep paths (the
391
+ * full barrel pulls ~1500 icons → ~6MB → overflows the GJS parser).
392
+ * The shim's deep-path icons resolve onward to react-native-svg →
393
+ * the @react-gnome GTK SVG impl.
394
+ */
395
+ lucideIcons?: string;
396
+ }
397
+
398
+ // NOTE deliberately NO alias for @tamagui/tooltip: its NATIVE build is an
399
+ // intentional null stub (touch platforms have no hover — Content renders
400
+ // nothing, TooltipGroup renders nothing). We match React Native exactly
401
+ // rather than pulling the WEB build into this native runtime (tried: it
402
+ // works visually but drags DOM assumptions — document-level dismiss
403
+ // listeners on a stubbed documentElement — into the bundle). A future
404
+ // GNOME-native tooltip belongs in a shim built on the hover controllers +
405
+ // GnomeFloatingProvider, not on borrowed web code.
406
+
407
+ /**
408
+ * Tamagui-specific resolver aliases for consumers whose @tamagui/*
409
+ * packages resolve by bare name (string finds keep @rollup/plugin-alias
410
+ * prefix semantics). Funnels `@tamagui/core` / `@tamagui/web` both into
411
+ * the single `@tamagui/core/native` module so the TamaguiProvider's
412
+ * config registry and high-level component lookups land in one place.
413
+ */
414
+ export function tamaguiAliases(options: TamaguiAliasOptions): TamaguiAliasEntry[] {
415
+ return [
416
+ ...(options.lucideIcons
417
+ ? [{ find: "@tamagui/lucide-icons-2", replacement: options.lucideIcons }]
418
+ : []),
419
+ { find: "@tamagui/core", replacement: "@tamagui/core/native" },
420
+ { find: "@tamagui/web", replacement: "@tamagui/core/native" },
421
+ { find: "tamagui", replacement: options.tamaguiBarrel },
422
+ ];
423
+ }
424
+
425
+ /**
426
+ * Same aliases with exact-match regexes — for consumers whose alias
427
+ * list mixes in absolute-path replacements (e.g. apps pulling
428
+ * @react-gnome in over pnpm `link:`), where a plain string prefix
429
+ * alias could re-mangle other entries' replacements.
430
+ */
431
+ export function tamaguiLinkedAliases(options: TamaguiAliasOptions): TamaguiAliasEntry[] {
432
+ return [
433
+ ...(options.lucideIcons
434
+ ? [{ find: /^@tamagui\/lucide-icons-2$/, replacement: options.lucideIcons }]
435
+ : []),
436
+ { find: /^@tamagui\/core$/, replacement: "@tamagui/core/native" },
437
+ { find: /^@tamagui\/web$/, replacement: "@tamagui/core/native" },
438
+ { find: /^tamagui$/, replacement: options.tamaguiBarrel },
439
+ ];
440
+ }
@@ -0,0 +1,62 @@
1
+ import type { Plugin } from "vite";
2
+ /** One Vite `resolve.alias` entry (the array form Vite accepts). */
3
+ export interface TamaguiAliasEntry {
4
+ find: string | RegExp;
5
+ replacement: string;
6
+ }
7
+ /**
8
+ * A source pattern one of the bundle patches anchors on. `find` must
9
+ * keep matching the dist files of `module` for the patch to fire;
10
+ * `replace` is the rewrite (absent for the bundle-level dedupe
11
+ * signature, whose rewrite is procedural).
12
+ */
13
+ export interface TamaguiPatchAnchor {
14
+ name: string;
15
+ module: "@tamagui/core" | "@tamagui/sheet" | "@tamagui/portal";
16
+ /** transform only runs on files containing this substring */
17
+ precondition: string;
18
+ find: RegExp;
19
+ replace?: string;
20
+ }
21
+ /**
22
+ * Every source pattern the patch set anchors on, in apply order. The
23
+ * package's anchor-verification test asserts each one still matches
24
+ * the pinned @tamagui/* dist files — the loud-failure guard for
25
+ * Tamagui version bumps.
26
+ */
27
+ export declare const tamaguiPatchAnchors: readonly TamaguiPatchAnchor[];
28
+ export declare const tamaguiPlugin: Plugin;
29
+ /** Consumer-provided targets for the Tamagui-specific aliases. */
30
+ export interface TamaguiAliasOptions {
31
+ /**
32
+ * Absolute path to the consumer's lean `tamagui` meta-package barrel
33
+ * — a module re-exporting only the granular @tamagui/* packages its
34
+ * graph needs. The full meta-barrel drags web-only components (and
35
+ * real-RN Flow sources the bundler can't parse) into the GJS bundle.
36
+ */
37
+ tamaguiBarrel: string;
38
+ /**
39
+ * Optional absolute path to a lean `@tamagui/lucide-icons-2` shim
40
+ * re-exporting only the used icons from per-icon deep paths (the
41
+ * full barrel pulls ~1500 icons → ~6MB → overflows the GJS parser).
42
+ * The shim's deep-path icons resolve onward to react-native-svg →
43
+ * the @react-gnome GTK SVG impl.
44
+ */
45
+ lucideIcons?: string;
46
+ }
47
+ /**
48
+ * Tamagui-specific resolver aliases for consumers whose @tamagui/*
49
+ * packages resolve by bare name (string finds keep @rollup/plugin-alias
50
+ * prefix semantics). Funnels `@tamagui/core` / `@tamagui/web` both into
51
+ * the single `@tamagui/core/native` module so the TamaguiProvider's
52
+ * config registry and high-level component lookups land in one place.
53
+ */
54
+ export declare function tamaguiAliases(options: TamaguiAliasOptions): TamaguiAliasEntry[];
55
+ /**
56
+ * Same aliases with exact-match regexes — for consumers whose alias
57
+ * list mixes in absolute-path replacements (e.g. apps pulling
58
+ * @react-gnome in over pnpm `link:`), where a plain string prefix
59
+ * alias could re-mangle other entries' replacements.
60
+ */
61
+ export declare function tamaguiLinkedAliases(options: TamaguiAliasOptions): TamaguiAliasEntry[];
62
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,oEAAoE;AACpE,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,eAAe,GAAG,gBAAgB,GAAG,iBAAiB,CAAC;IAC/D,6DAA6D;IAC7D,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAwOD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,kBAAkB,EAK5D,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,MA8E3B,CAAC;AAEF,kEAAkE;AAClE,MAAM,WAAW,mBAAmB;IAClC;;;;;OAKG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAWD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,mBAAmB,GAAG,iBAAiB,EAAE,CAShF;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,mBAAmB,GAAG,iBAAiB,EAAE,CAStF"}