@hanzogui/static 2.0.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.
Files changed (207) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/check-dep-versions.cjs +267 -0
  4. package/dist/checkDeps.cjs +200 -0
  5. package/dist/constants.cjs +49 -0
  6. package/dist/exports.cjs +44 -0
  7. package/dist/extractor/accessSafe.cjs +46 -0
  8. package/dist/extractor/babelParse.cjs +54 -0
  9. package/dist/extractor/buildClassName.cjs +62 -0
  10. package/dist/extractor/bundle.cjs +185 -0
  11. package/dist/extractor/bundleConfig.cjs +513 -0
  12. package/dist/extractor/concatClassName.cjs +80 -0
  13. package/dist/extractor/createEvaluator.cjs +75 -0
  14. package/dist/extractor/createExtractor.cjs +1150 -0
  15. package/dist/extractor/createLogger.cjs +45 -0
  16. package/dist/extractor/detectModuleFormat.cjs +49 -0
  17. package/dist/extractor/ensureImportingConcat.cjs +48 -0
  18. package/dist/extractor/errors.cjs +26 -0
  19. package/dist/extractor/esbuildAliasPlugin.cjs +44 -0
  20. package/dist/extractor/esbuildTsconfigPaths.cjs +86 -0
  21. package/dist/extractor/evaluateAstNode.cjs +83 -0
  22. package/dist/extractor/extractHelpers.cjs +119 -0
  23. package/dist/extractor/extractMediaStyle.cjs +128 -0
  24. package/dist/extractor/extractToClassNames.cjs +321 -0
  25. package/dist/extractor/extractToNative.cjs +266 -0
  26. package/dist/extractor/findTopmostFunction.cjs +34 -0
  27. package/dist/extractor/generatedUid.cjs +47 -0
  28. package/dist/extractor/getGuiConfigPathFromOptionsConfig.cjs +35 -0
  29. package/dist/extractor/getPrefixLogs.cjs +29 -0
  30. package/dist/extractor/getPropValueFromAttributes.cjs +67 -0
  31. package/dist/extractor/getSourceModule.cjs +64 -0
  32. package/dist/extractor/getStaticBindingsForScope.cjs +150 -0
  33. package/dist/extractor/hoistClassNames.cjs +62 -0
  34. package/dist/extractor/literalToAst.cjs +84 -0
  35. package/dist/extractor/loadFile.cjs +11 -0
  36. package/dist/extractor/loadGui.cjs +322 -0
  37. package/dist/extractor/logLines.cjs +35 -0
  38. package/dist/extractor/normalizeTernaries.cjs +73 -0
  39. package/dist/extractor/propsToFontFamilyCache.cjs +38 -0
  40. package/dist/extractor/regenerateConfig.cjs +150 -0
  41. package/dist/extractor/removeUnusedHooks.cjs +76 -0
  42. package/dist/extractor/timer.cjs +43 -0
  43. package/dist/extractor/validHTMLAttributes.cjs +77 -0
  44. package/dist/extractor/watchGuiConfig.cjs +58 -0
  45. package/dist/getPragmaOptions.cjs +58 -0
  46. package/dist/helpers/memoize.cjs +37 -0
  47. package/dist/helpers/requireGuiCore.cjs +33 -0
  48. package/dist/index.cjs +40 -0
  49. package/dist/registerRequire.cjs +115 -0
  50. package/dist/server.cjs +75 -0
  51. package/dist/setup.cjs +0 -0
  52. package/dist/types.cjs +16 -0
  53. package/dist/worker.cjs +89 -0
  54. package/package.json +101 -0
  55. package/src/check-dep-versions.ts +738 -0
  56. package/src/checkDeps.ts +371 -0
  57. package/src/constants.ts +14 -0
  58. package/src/exports.ts +15 -0
  59. package/src/extractor/accessSafe.ts +22 -0
  60. package/src/extractor/babelParse.ts +37 -0
  61. package/src/extractor/buildClassName.ts +76 -0
  62. package/src/extractor/bundle.ts +277 -0
  63. package/src/extractor/bundleConfig.ts +958 -0
  64. package/src/extractor/concatClassName.ts +105 -0
  65. package/src/extractor/createEvaluator.ts +82 -0
  66. package/src/extractor/createExtractor.ts +2665 -0
  67. package/src/extractor/createLogger.ts +41 -0
  68. package/src/extractor/detectModuleFormat.ts +42 -0
  69. package/src/extractor/ensureImportingConcat.ts +36 -0
  70. package/src/extractor/errors.ts +1 -0
  71. package/src/extractor/esbuildAliasPlugin.ts +40 -0
  72. package/src/extractor/esbuildTsconfigPaths.ts +103 -0
  73. package/src/extractor/evaluateAstNode.ts +136 -0
  74. package/src/extractor/extractHelpers.ts +211 -0
  75. package/src/extractor/extractMediaStyle.ts +194 -0
  76. package/src/extractor/extractToClassNames.ts +631 -0
  77. package/src/extractor/extractToNative.ts +463 -0
  78. package/src/extractor/findTopmostFunction.ts +24 -0
  79. package/src/extractor/generatedUid.ts +41 -0
  80. package/src/extractor/getGuiConfigPathFromOptionsConfig.ts +24 -0
  81. package/src/extractor/getPrefixLogs.ts +9 -0
  82. package/src/extractor/getPropValueFromAttributes.ts +95 -0
  83. package/src/extractor/getSourceModule.ts +96 -0
  84. package/src/extractor/getStaticBindingsForScope.ts +237 -0
  85. package/src/extractor/hoistClassNames.ts +52 -0
  86. package/src/extractor/literalToAst.ts +85 -0
  87. package/src/extractor/loadFile.ts +17 -0
  88. package/src/extractor/loadGui.ts +487 -0
  89. package/src/extractor/logLines.ts +16 -0
  90. package/src/extractor/normalizeTernaries.ts +75 -0
  91. package/src/extractor/propsToFontFamilyCache.ts +18 -0
  92. package/src/extractor/regenerateConfig.ts +186 -0
  93. package/src/extractor/removeUnusedHooks.ts +83 -0
  94. package/src/extractor/timer.ts +25 -0
  95. package/src/extractor/validHTMLAttributes.ts +52 -0
  96. package/src/extractor/watchGuiConfig.ts +57 -0
  97. package/src/getPragmaOptions.ts +57 -0
  98. package/src/helpers/memoize.ts +24 -0
  99. package/src/helpers/requireGuiCore.ts +28 -0
  100. package/src/index.ts +4 -0
  101. package/src/registerRequire.ts +236 -0
  102. package/src/server.ts +43 -0
  103. package/src/setup.ts +0 -0
  104. package/src/types.ts +109 -0
  105. package/src/worker.ts +142 -0
  106. package/types/check-dep-versions.d.ts +37 -0
  107. package/types/check-dep-versions.d.ts.map +1 -0
  108. package/types/checkDeps.d.ts +19 -0
  109. package/types/checkDeps.d.ts.map +1 -0
  110. package/types/constants.d.ts +6 -0
  111. package/types/constants.d.ts.map +1 -0
  112. package/types/exports.d.ts +16 -0
  113. package/types/exports.d.ts.map +1 -0
  114. package/types/extractor/accessSafe.d.ts +3 -0
  115. package/types/extractor/accessSafe.d.ts.map +1 -0
  116. package/types/extractor/babelParse.d.ts +5 -0
  117. package/types/extractor/babelParse.d.ts.map +1 -0
  118. package/types/extractor/buildClassName.d.ts +7 -0
  119. package/types/extractor/buildClassName.d.ts.map +1 -0
  120. package/types/extractor/bundle.d.ts +121 -0
  121. package/types/extractor/bundle.d.ts.map +1 -0
  122. package/types/extractor/bundleConfig.d.ts +49 -0
  123. package/types/extractor/bundleConfig.d.ts.map +1 -0
  124. package/types/extractor/concatClassName.d.ts +8 -0
  125. package/types/extractor/concatClassName.d.ts.map +1 -0
  126. package/types/extractor/createEvaluator.d.ts +12 -0
  127. package/types/extractor/createEvaluator.d.ts.map +1 -0
  128. package/types/extractor/createExtractor.d.ts +32 -0
  129. package/types/extractor/createExtractor.d.ts.map +1 -0
  130. package/types/extractor/createLogger.d.ts +3 -0
  131. package/types/extractor/createLogger.d.ts.map +1 -0
  132. package/types/extractor/detectModuleFormat.d.ts +5 -0
  133. package/types/extractor/detectModuleFormat.d.ts.map +1 -0
  134. package/types/extractor/ensureImportingConcat.d.ts +4 -0
  135. package/types/extractor/ensureImportingConcat.d.ts.map +1 -0
  136. package/types/extractor/errors.d.ts +3 -0
  137. package/types/extractor/errors.d.ts.map +1 -0
  138. package/types/extractor/esbuildAliasPlugin.d.ts +18 -0
  139. package/types/extractor/esbuildAliasPlugin.d.ts.map +1 -0
  140. package/types/extractor/esbuildTsconfigPaths.d.ts +11 -0
  141. package/types/extractor/esbuildTsconfigPaths.d.ts.map +1 -0
  142. package/types/extractor/evaluateAstNode.d.ts +3 -0
  143. package/types/extractor/evaluateAstNode.d.ts.map +1 -0
  144. package/types/extractor/extractHelpers.d.ts +28 -0
  145. package/types/extractor/extractHelpers.d.ts.map +1 -0
  146. package/types/extractor/extractMediaStyle.d.ts +11 -0
  147. package/types/extractor/extractMediaStyle.d.ts.map +1 -0
  148. package/types/extractor/extractToClassNames.d.ts +25 -0
  149. package/types/extractor/extractToClassNames.d.ts.map +1 -0
  150. package/types/extractor/extractToNative.d.ts +13 -0
  151. package/types/extractor/extractToNative.d.ts.map +1 -0
  152. package/types/extractor/findTopmostFunction.d.ts +4 -0
  153. package/types/extractor/findTopmostFunction.d.ts.map +1 -0
  154. package/types/extractor/generatedUid.d.ts +5 -0
  155. package/types/extractor/generatedUid.d.ts.map +1 -0
  156. package/types/extractor/getGuiConfigPathFromOptionsConfig.d.ts +3 -0
  157. package/types/extractor/getGuiConfigPathFromOptionsConfig.d.ts.map +1 -0
  158. package/types/extractor/getPrefixLogs.d.ts +3 -0
  159. package/types/extractor/getPrefixLogs.d.ts.map +1 -0
  160. package/types/extractor/getPropValueFromAttributes.d.ts +19 -0
  161. package/types/extractor/getPropValueFromAttributes.d.ts.map +1 -0
  162. package/types/extractor/getSourceModule.d.ts +16 -0
  163. package/types/extractor/getSourceModule.d.ts.map +1 -0
  164. package/types/extractor/getStaticBindingsForScope.d.ts +5 -0
  165. package/types/extractor/getStaticBindingsForScope.d.ts.map +1 -0
  166. package/types/extractor/hoistClassNames.d.ts +6 -0
  167. package/types/extractor/hoistClassNames.d.ts.map +1 -0
  168. package/types/extractor/literalToAst.d.ts +4 -0
  169. package/types/extractor/literalToAst.d.ts.map +1 -0
  170. package/types/extractor/loadFile.d.ts +1 -0
  171. package/types/extractor/loadFile.d.ts.map +1 -0
  172. package/types/extractor/loadGui.d.ts +22 -0
  173. package/types/extractor/loadGui.d.ts.map +1 -0
  174. package/types/extractor/logLines.d.ts +2 -0
  175. package/types/extractor/logLines.d.ts.map +1 -0
  176. package/types/extractor/normalizeTernaries.d.ts +3 -0
  177. package/types/extractor/normalizeTernaries.d.ts.map +1 -0
  178. package/types/extractor/propsToFontFamilyCache.d.ts +4 -0
  179. package/types/extractor/propsToFontFamilyCache.d.ts.map +1 -0
  180. package/types/extractor/regenerateConfig.d.ts +9 -0
  181. package/types/extractor/regenerateConfig.d.ts.map +1 -0
  182. package/types/extractor/removeUnusedHooks.d.ts +3 -0
  183. package/types/extractor/removeUnusedHooks.d.ts.map +1 -0
  184. package/types/extractor/timer.d.ts +5 -0
  185. package/types/extractor/timer.d.ts.map +1 -0
  186. package/types/extractor/validHTMLAttributes.d.ts +52 -0
  187. package/types/extractor/validHTMLAttributes.d.ts.map +1 -0
  188. package/types/extractor/watchGuiConfig.d.ts +5 -0
  189. package/types/extractor/watchGuiConfig.d.ts.map +1 -0
  190. package/types/getPragmaOptions.d.ts +8 -0
  191. package/types/getPragmaOptions.d.ts.map +1 -0
  192. package/types/helpers/memoize.d.ts +8 -0
  193. package/types/helpers/memoize.d.ts.map +1 -0
  194. package/types/helpers/requireGuiCore.d.ts +3 -0
  195. package/types/helpers/requireGuiCore.d.ts.map +1 -0
  196. package/types/index.d.ts +4 -0
  197. package/types/index.d.ts.map +1 -0
  198. package/types/registerRequire.d.ts +10 -0
  199. package/types/registerRequire.d.ts.map +1 -0
  200. package/types/server.d.ts +3 -0
  201. package/types/server.d.ts.map +1 -0
  202. package/types/setup.d.ts +1 -0
  203. package/types/setup.d.ts.map +1 -0
  204. package/types/types.d.ts +92 -0
  205. package/types/types.d.ts.map +1 -0
  206. package/types/worker.d.ts +46 -0
  207. package/types/worker.d.ts.map +1 -0
@@ -0,0 +1,322 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf,
6
+ __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: !0
11
+ });
12
+ },
13
+ __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: !0
28
+ }) : target, mod)),
29
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
+ value: !0
31
+ }), mod);
32
+ var loadGui_exports = {};
33
+ __export(loadGui_exports, {
34
+ esbuildWatchFiles: () => esbuildWatchFiles,
35
+ generateThemesAndLog: () => generateThemesAndLog,
36
+ getOptions: () => getOptions,
37
+ loadGui: () => loadGui,
38
+ loadGuiBuildConfigAsync: () => loadGuiBuildConfigAsync,
39
+ loadGuiBuildConfigSync: () => loadGuiBuildConfigSync,
40
+ loadGuiSync: () => loadGuiSync,
41
+ resolveWebOrNativeSpecificEntry: () => resolveWebOrNativeSpecificEntry
42
+ });
43
+ module.exports = __toCommonJS(loadGui_exports);
44
+ var import_node_path = require("node:path"),
45
+ import_cli_color = require("@hanzogui/cli-color"),
46
+ import_esbuild = __toESM(require("esbuild")),
47
+ esbuildWasm = __toESM(require("esbuild-wasm")),
48
+ fsExtra = __toESM(require("fs-extra")),
49
+ import_constants = require("../constants.cjs"),
50
+ import_requireGuiCore = require("../helpers/requireGuiCore.cjs"),
51
+ import_registerRequire = require("../registerRequire.cjs"),
52
+ import_bundleConfig = require("./bundleConfig.cjs"),
53
+ import_getGuiConfigPathFromOptionsConfig = require("./getGuiConfigPathFromOptionsConfig.cjs"),
54
+ import_regenerateConfig = require("./regenerateConfig.cjs");
55
+ const getFilledOptions = propsIn => ({
56
+ // defaults
57
+ platform: "web",
58
+ config: "gui.config.ts",
59
+ components: ["@hanzo/gui"],
60
+ ...propsIn
61
+ });
62
+ let isLoadingPromise;
63
+ async function loadGui(propsIn) {
64
+ if (isLoadingPromise) return await isLoadingPromise;
65
+ let resolvePromise, rejectPromise;
66
+ isLoadingPromise = new Promise((res, rej) => {
67
+ resolvePromise = res, rejectPromise = rej;
68
+ });
69
+ try {
70
+ const props = getFilledOptions(propsIn),
71
+ bundleInfo = await (0, import_bundleConfig.getBundledConfig)(props);
72
+ if (!bundleInfo) return console.warn("No bundled config generated, maybe an error in bundling. Set DEBUG=hanzo-gui and re-run to get logs."), resolvePromise(null), null;
73
+ await generateThemesAndLog(props);
74
+ const maybeGuiConfig = bundleInfo.guiConfig;
75
+ if (maybeGuiConfig && !maybeGuiConfig.parsed) {
76
+ const {
77
+ createGui
78
+ } = (0, import_requireGuiCore.requireGuiCore)(props.platform || "web");
79
+ bundleInfo.guiConfig = createGui(bundleInfo.guiConfig);
80
+ }
81
+ return (0, import_bundleConfig.hasBundledConfigChanged)() ? (await (0, import_regenerateConfig.regenerateConfig)(props, bundleInfo), resolvePromise(bundleInfo), bundleInfo) : (resolvePromise(bundleInfo), bundleInfo);
82
+ } catch (err) {
83
+ throw rejectPromise(), err;
84
+ } finally {
85
+ isLoadingPromise = null;
86
+ }
87
+ }
88
+ let waiting = !1;
89
+ const generateThemesAndLog = async (options, force = !1) => {
90
+ if (!waiting && options.themeBuilder) try {
91
+ if (waiting = !0, await new Promise(res => setTimeout(res, 30)), (await (0, import_regenerateConfig.generateGuiThemes)(options, force)) && ((0, import_cli_color.colorLog)(import_cli_color.Color.FgYellow, ` \u27A1 [hanzo-gui] generated themes: ${(0, import_node_path.relative)(process.cwd(), options.themeBuilder.output)}`), options.outputCSS)) {
92
+ const loadedConfig = (0, import_bundleConfig.getLoadedConfig)();
93
+ loadedConfig && (await (0, import_bundleConfig.writeGuiCSS)(options.outputCSS, loadedConfig));
94
+ }
95
+ } finally {
96
+ waiting = !1;
97
+ }
98
+ },
99
+ last = {},
100
+ lastVersion = {};
101
+ let esbuildWasmInitialized = !1;
102
+ async function loadGuiBuildConfigAsync(guiOptions) {
103
+ const buildFilePath = guiOptions?.buildFile ?? "./gui.build.ts",
104
+ absolutePath = buildFilePath[0] === "." ? (0, import_node_path.join)(process.cwd(), buildFilePath) : buildFilePath;
105
+ if (fsExtra.existsSync(absolutePath)) try {
106
+ const source = await fsExtra.readFile(absolutePath, "utf-8");
107
+ esbuildWasmInitialized || (await esbuildWasm.initialize({}), esbuildWasmInitialized = !0);
108
+ const result = await esbuildWasm.transform(source, {
109
+ loader: "ts",
110
+ format: "cjs",
111
+ target: "node18",
112
+ sourcefile: absolutePath
113
+ }),
114
+ module2 = {
115
+ exports: {}
116
+ };
117
+ new Function("module", "exports", "require", "process", result.code)(module2, module2.exports, require, process);
118
+ const out = module2.exports.default || module2.exports;
119
+ if (!out || typeof out != "object") throw new Error(`No default export found in ${buildFilePath}: ${out}`);
120
+ guiOptions = {
121
+ ...guiOptions,
122
+ ...out
123
+ };
124
+ } catch (err) {
125
+ throw console.error(`[hanzo-gui] Error loading ${buildFilePath}:`, err), err;
126
+ }
127
+ if (!guiOptions) throw new Error("No hanzo-gui build options found either via input props or at gui.build.ts");
128
+ return {
129
+ config: "gui.config.ts",
130
+ components: ["@hanzo/gui", "@hanzogui/core"],
131
+ ...guiOptions
132
+ };
133
+ }
134
+ function loadGuiBuildConfigSync(guiOptions) {
135
+ const buildFilePath = guiOptions?.buildFile ?? "./gui.build.ts";
136
+ if (fsExtra.existsSync(buildFilePath)) {
137
+ const registered = (0, import_registerRequire.registerRequire)("web");
138
+ try {
139
+ const out = (buildFilePath[0] === "." ? require((0, import_node_path.join)(process.cwd(), buildFilePath)) : require(buildFilePath)).default;
140
+ if (!out) throw new Error(`No default export found in ${buildFilePath}: ${out}`);
141
+ guiOptions = {
142
+ ...guiOptions,
143
+ ...out
144
+ };
145
+ } finally {
146
+ registered.unregister();
147
+ }
148
+ }
149
+ if (!guiOptions) throw new Error("No hanzo-gui build options found either via input props or at gui.build.ts");
150
+ return {
151
+ config: "gui.config.ts",
152
+ components: ["@hanzo/gui", "@hanzogui/core"],
153
+ ...guiOptions
154
+ };
155
+ }
156
+ function loadGuiSync({
157
+ forceExports,
158
+ cacheKey,
159
+ ...propsIn
160
+ }) {
161
+ const key = JSON.stringify(propsIn);
162
+ if (last[key] && !(0, import_bundleConfig.hasBundledConfigChanged)() && (!lastVersion[key] || lastVersion[key] === cacheKey)) return last[key];
163
+ lastVersion[key] = cacheKey || "";
164
+ const props = getFilledOptions(propsIn);
165
+ process.env.IS_STATIC = "is_static", process.env.HANZO_GUI_IS_SERVER = "true";
166
+ const {
167
+ unregister
168
+ } = (0, import_registerRequire.registerRequire)(props.platform || "web", {
169
+ proxyWormImports: !!forceExports
170
+ });
171
+ try {
172
+ const devValueOG = globalThis.__DEV__;
173
+ globalThis.__DEV__ = process.env.NODE_ENV === "development";
174
+ try {
175
+ let guiConfig = null;
176
+ if (propsIn.config) {
177
+ const configPath = (0, import_getGuiConfigPathFromOptionsConfig.getGuiConfigPathFromOptionsConfig)(propsIn.config),
178
+ exp = require(configPath);
179
+ if (!exp || exp._isProxyWorm) throw new Error("Got a empty / proxied config!");
180
+ if (guiConfig = exp.default || exp.config || exp, !guiConfig || !guiConfig.parsed) {
181
+ const confPath = require.resolve(configPath);
182
+ throw new Error(`Can't find valid config in ${confPath}:
183
+
184
+ Be sure you "export default" or "export const config" the config.`);
185
+ }
186
+ if (guiConfig) {
187
+ const {
188
+ createGui
189
+ } = (0, import_requireGuiCore.requireGuiCore)(props.platform || "web");
190
+ createGui(guiConfig);
191
+ }
192
+ }
193
+ const components = (0, import_bundleConfig.loadComponentsSync)(props, forceExports);
194
+ if (!components) throw new Error("No components loaded");
195
+ process.env.DEBUG === "@hanzo/gui" && console.info("components", components), process.env.IS_STATIC = void 0, globalThis.__DEV__ = devValueOG;
196
+ const info = {
197
+ components,
198
+ guiConfig,
199
+ nameToPaths: (0, import_registerRequire.getNameToPaths)()
200
+ };
201
+ if (guiConfig) {
202
+ const {
203
+ outputCSS
204
+ } = props;
205
+ outputCSS && (0, import_bundleConfig.writeGuiCSS)(outputCSS, guiConfig), (0, import_regenerateConfig.regenerateConfigSync)(props, info);
206
+ }
207
+ return last[key] = {
208
+ ...info,
209
+ cached: !0
210
+ }, info;
211
+ } catch (err) {
212
+ return err instanceof Error ? !import_constants.SHOULD_DEBUG && !forceExports ? (console.warn("Error loading gui.config.ts (set DEBUG=hanzo-gui to see full stack), running hanzo-gui without custom config"), console.info(`
213
+
214
+ ${err.message}
215
+
216
+ `)) : import_constants.SHOULD_DEBUG && console.error(err) : console.error("Error loading gui.config.ts", err), {
217
+ components: [],
218
+ guiConfig: null,
219
+ nameToPaths: {}
220
+ };
221
+ }
222
+ } finally {
223
+ unregister();
224
+ }
225
+ }
226
+ async function getOptions({
227
+ root = process.cwd(),
228
+ tsconfigPath = "tsconfig.json",
229
+ guiOptions,
230
+ host,
231
+ debug
232
+ } = {}) {
233
+ const dotDir = (0, import_node_path.join)(root, ".gui");
234
+ let pkgJson = {};
235
+ try {
236
+ pkgJson = await fsExtra.readJSON((0, import_node_path.join)(root, "package.json"));
237
+ } catch {}
238
+ return {
239
+ mode: process.env.NODE_ENV === "production" ? "production" : "development",
240
+ root,
241
+ host: host || "127.0.0.1",
242
+ pkgJson,
243
+ debug,
244
+ tsconfigPath,
245
+ guiOptions: {
246
+ platform: "web",
247
+ components: ["@hanzo/gui"],
248
+ ...guiOptions,
249
+ config: guiOptions?.config ?? (await getDefaultGuiConfigPath(root, guiOptions?.config))
250
+ },
251
+ paths: {
252
+ root,
253
+ dotDir,
254
+ conf: (0, import_node_path.join)(dotDir, "gui.config.json"),
255
+ types: (0, import_node_path.join)(dotDir, "types.json")
256
+ }
257
+ };
258
+ }
259
+ function resolveWebOrNativeSpecificEntry(entry) {
260
+ const workspaceRoot = (0, import_node_path.resolve)(),
261
+ resolved = require.resolve(entry, {
262
+ paths: [workspaceRoot]
263
+ }),
264
+ ext = (0, import_node_path.extname)(resolved),
265
+ fileName = (0, import_node_path.basename)(resolved).replace(ext, ""),
266
+ specificFile = (0, import_node_path.join)((0, import_node_path.dirname)(resolved), fileName + "." + "web" + ext);
267
+ return fsExtra.existsSync(specificFile) ? specificFile : entry;
268
+ }
269
+ const defaultPaths = ["gui.config.ts", (0, import_node_path.join)("src", "gui.config.ts")];
270
+ let hasWarnedOnce = !1;
271
+ async function getDefaultGuiConfigPath(root, configPath) {
272
+ const searchPaths = [...new Set([configPath, ...defaultPaths].filter(Boolean).map(p => (0, import_node_path.join)(root, p)))];
273
+ for (const path of searchPaths) if (await fsExtra.pathExists(path)) return path;
274
+ hasWarnedOnce || (hasWarnedOnce = !0, console.warn(`Warning: couldn't find gui.config.ts in the following paths given configuration "${configPath}":
275
+ ${searchPaths.join(`
276
+ `)}
277
+ `));
278
+ }
279
+ async function esbuildWatchFiles(entry, onChanged) {
280
+ let hasRunOnce = !1;
281
+ const context = await import_esbuild.default.context({
282
+ bundle: !0,
283
+ entryPoints: [entry],
284
+ resolveExtensions: [".ts", ".tsx", ".js", ".mjs"],
285
+ logLevel: "silent",
286
+ write: !1,
287
+ alias: {
288
+ "@react-native/normalize-color": "@hanzogui/proxy-worm",
289
+ "react-native-web": "@hanzogui/react-native-web-lite",
290
+ "react-native": "@hanzogui/proxy-worm"
291
+ },
292
+ plugins: [
293
+ // to log what its watching:
294
+ // {
295
+ // name: 'test',
296
+ // setup({ onResolve }) {
297
+ // onResolve({ filter: /.*/ }, (args) => {
298
+ // console.log('wtf', args.path)
299
+ // })
300
+ // },
301
+ // },
302
+ {
303
+ name: "on-rebuild",
304
+ setup({
305
+ onEnd,
306
+ onResolve
307
+ }) {
308
+ onResolve({
309
+ filter: /^[^./]|^\.[^./]|^\.\.[^/]/
310
+ }, args => ({
311
+ path: args.path,
312
+ external: !0
313
+ })), onEnd(() => {
314
+ hasRunOnce ? onChanged() : hasRunOnce = !0;
315
+ });
316
+ }
317
+ }]
318
+ });
319
+ return context.watch(), () => {
320
+ context.dispose();
321
+ };
322
+ }
@@ -0,0 +1,35 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: !0
9
+ });
10
+ },
11
+ __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ return to;
17
+ };
18
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
+ value: !0
20
+ }), mod);
21
+ var logLines_exports = {};
22
+ __export(logLines_exports, {
23
+ logLines: () => logLines
24
+ });
25
+ module.exports = __toCommonJS(logLines_exports);
26
+ const prefix = " ",
27
+ logLines = (str, singleLine = !1) => {
28
+ if (singleLine) return prefix + str.split(" ").join(`
29
+ ${prefix}`);
30
+ const lines = [""],
31
+ items = str.split(" ");
32
+ for (const item of items) item.length + lines[lines.length - 1].length > 85 && lines.push(""), lines[lines.length - 1] += item + " ";
33
+ return lines.map((line, i) => prefix + (i == 0 ? "" : " ") + line.trim()).join(`
34
+ `);
35
+ };
@@ -0,0 +1,73 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf,
6
+ __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: !0
11
+ });
12
+ },
13
+ __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: !0
28
+ }) : target, mod)),
29
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
+ value: !0
31
+ }), mod);
32
+ var normalizeTernaries_exports = {};
33
+ __export(normalizeTernaries_exports, {
34
+ normalizeTernaries: () => normalizeTernaries
35
+ });
36
+ module.exports = __toCommonJS(normalizeTernaries_exports);
37
+ var import_generator = __toESM(require("@babel/generator")),
38
+ t = __toESM(require("@babel/types")),
39
+ import_web = require("@hanzogui/web"),
40
+ import_invariant = __toESM(require("invariant")),
41
+ import_propsToFontFamilyCache = require("./propsToFontFamilyCache.cjs");
42
+ function normalizeTernaries(ternaries) {
43
+ if ((0, import_invariant.default)(Array.isArray(ternaries), "extractStaticTernaries expects param 1 to be an array of ternaries"), ternaries.length === 0) return [];
44
+ const ternariesByKey = {};
45
+ for (let idx = -1, len = ternaries.length; ++idx < len;) {
46
+ const {
47
+ test,
48
+ consequent,
49
+ alternate,
50
+ remove,
51
+ ...rest
52
+ } = ternaries[idx];
53
+ let ternaryTest = test;
54
+ t.isExpressionStatement(test) && (ternaryTest = test.expression);
55
+ let shouldSwap = !1;
56
+ t.isUnaryExpression(test) && test.operator === "!" ? (ternaryTest = test.argument, shouldSwap = !0) : t.isBinaryExpression(test) && (test.operator === "!==" || test.operator === "!=") && (ternaryTest = t.binaryExpression(test.operator.replace("!", "="), test.left, test.right), shouldSwap = !0);
57
+ const key = (0, import_generator.default)(ternaryTest).code;
58
+ ternariesByKey[key] || (ternariesByKey[key] = {
59
+ ...rest,
60
+ alternate: {},
61
+ consequent: {},
62
+ test: ternaryTest,
63
+ remove
64
+ });
65
+ const altStyle = (shouldSwap ? consequent : alternate) ?? {},
66
+ consStyle = (shouldSwap ? alternate : consequent) ?? {},
67
+ nextAlt = ternariesByKey[key].alternate;
68
+ ternariesByKey[key].alternate = (0, import_web.mergeProps)(altStyle, nextAlt), (0, import_propsToFontFamilyCache.forwardFontFamilyName)(altStyle, ternariesByKey[key].alternate);
69
+ const nextCons = ternariesByKey[key].consequent;
70
+ ternariesByKey[key].consequent = (0, import_web.mergeProps)(consStyle, nextCons), (0, import_propsToFontFamilyCache.forwardFontFamilyName)(consStyle, ternariesByKey[key].consequent);
71
+ }
72
+ return Object.keys(ternariesByKey).map(key => ternariesByKey[key]);
73
+ }
@@ -0,0 +1,38 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: !0
9
+ });
10
+ },
11
+ __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ return to;
17
+ };
18
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
+ value: !0
20
+ }), mod);
21
+ var propsToFontFamilyCache_exports = {};
22
+ __export(propsToFontFamilyCache_exports, {
23
+ forwardFontFamilyName: () => forwardFontFamilyName,
24
+ getFontFamilyNameFromProps: () => getFontFamilyNameFromProps,
25
+ setPropsToFontFamily: () => setPropsToFontFamily
26
+ });
27
+ module.exports = __toCommonJS(propsToFontFamilyCache_exports);
28
+ const cache = /* @__PURE__ */new WeakMap();
29
+ function setPropsToFontFamily(props, ff) {
30
+ cache.set(props, ff.replace("$", "").trim());
31
+ }
32
+ function getFontFamilyNameFromProps(props) {
33
+ return cache.get(props);
34
+ }
35
+ function forwardFontFamilyName(prev, next, fallback) {
36
+ const ff = getFontFamilyNameFromProps(prev) || fallback;
37
+ ff && setPropsToFontFamily(next, ff);
38
+ }
@@ -0,0 +1,150 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf,
6
+ __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: !0
11
+ });
12
+ },
13
+ __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: !0
28
+ }) : target, mod)),
29
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
+ value: !0
31
+ }), mod);
32
+ var regenerateConfig_exports = {};
33
+ __export(regenerateConfig_exports, {
34
+ generateGuiThemes: () => generateGuiThemes,
35
+ regenerateConfig: () => regenerateConfig,
36
+ regenerateConfigSync: () => regenerateConfigSync
37
+ });
38
+ module.exports = __toCommonJS(regenerateConfig_exports);
39
+ var import_node_path = require("node:path"),
40
+ import_generate_themes = require("@hanzogui/generate-themes"),
41
+ FS = __toESM(require("fs-extra")),
42
+ import_requireGuiCore = require("../helpers/requireGuiCore.cjs"),
43
+ import_bundleConfig = require("./bundleConfig.cjs");
44
+ const guiDir = (0, import_node_path.join)(process.cwd(), ".gui"),
45
+ confFile = (0, import_node_path.join)(guiDir, "gui.config.json");
46
+ async function regenerateConfig(guiOptions, configIn, rebuild = !1) {
47
+ try {
48
+ const config = configIn ?? (await (0, import_bundleConfig.getBundledConfig)(guiOptions, rebuild));
49
+ if (!config) return;
50
+ const out = transformConfig(config, guiOptions.platform || "web");
51
+ await FS.ensureDir((0, import_node_path.dirname)(confFile)), await FS.writeJSON(confFile, out, {
52
+ spaces: 2
53
+ });
54
+ } catch (err) {
55
+ (process.env.DEBUG?.includes("@hanzo/gui") || process.env.IS_HANZO_GUI_DEV) && console.warn("regenerateConfig error", err);
56
+ }
57
+ }
58
+ function regenerateConfigSync(_guiOptions, config) {
59
+ try {
60
+ FS.ensureDirSync((0, import_node_path.dirname)(confFile)), FS.writeJSONSync(confFile, transformConfig(config, _guiOptions.platform || "web"), {
61
+ spaces: 2
62
+ });
63
+ } catch (err) {
64
+ (process.env.DEBUG?.includes("@hanzo/gui") || process.env.IS_HANZO_GUI_DEV) && console.warn("regenerateConfig error", err);
65
+ }
66
+ }
67
+ async function generateGuiThemes(guiOptions, force = !1) {
68
+ if (!guiOptions.themeBuilder) return;
69
+ const {
70
+ input,
71
+ output
72
+ } = guiOptions.themeBuilder,
73
+ inPath = resolveRelativePath(input),
74
+ outPath = resolveRelativePath(output),
75
+ generatedOutput = await (0, import_generate_themes.generateThemes)(inPath),
76
+ hasChanged = force || (await (async () => {
77
+ try {
78
+ if (!generatedOutput) return !1;
79
+ const next = generatedOutput.generated,
80
+ current = await FS.readFile(outPath, "utf-8");
81
+ return next !== current;
82
+ } catch {}
83
+ return !0;
84
+ })());
85
+ return hasChanged && (await (0, import_generate_themes.writeGeneratedThemes)(guiDir, outPath, generatedOutput)), hasChanged;
86
+ }
87
+ const resolveRelativePath = inputPath => inputPath.startsWith(".") ? (0, import_node_path.join)(process.cwd(), inputPath) : require.resolve(inputPath);
88
+ function cloneDeepSafe(x, excludeKeys = {}) {
89
+ return x && (Array.isArray(x) ? x.map(_ => cloneDeepSafe(_)) : typeof x == "function" ? "Function" : typeof x != "object" ? x : "$$typeof" in x ? "Component" : Object.fromEntries(Object.entries(x).flatMap(([k, v]) => excludeKeys[k] ? [] : [[k, cloneDeepSafe(v)]])));
90
+ }
91
+ function transformConfig(config, platform) {
92
+ if (!config) return null;
93
+ const {
94
+ getVariableValue
95
+ } = (0, import_requireGuiCore.requireGuiCore)(platform),
96
+ next = cloneDeepSafe(config, {
97
+ validStyles: !0
98
+ }),
99
+ {
100
+ components,
101
+ nameToPaths,
102
+ guiConfig
103
+ } = next,
104
+ {
105
+ themes,
106
+ tokens
107
+ } = guiConfig;
108
+ for (const key in themes) {
109
+ const theme = themes[key];
110
+ theme.id = key;
111
+ for (const tkey in theme) theme[tkey] = getVariableValue(theme[tkey]);
112
+ }
113
+ for (const key in tokens) {
114
+ const token = {
115
+ ...tokens[key]
116
+ };
117
+ for (const tkey in token) token[tkey] = getVariableValue(token[tkey]);
118
+ }
119
+ for (const component of components) for (const _ in component.nameToInfo) {
120
+ const compDefinition = {
121
+ ...component.nameToInfo[_]
122
+ };
123
+ component.nameToInfo[_] = compDefinition;
124
+ const {
125
+ parentStaticConfig,
126
+ ...rest
127
+ } = compDefinition.staticConfig;
128
+ compDefinition.staticConfig = rest;
129
+ }
130
+ next.nameToPaths = {};
131
+ for (const key in nameToPaths) next.nameToPaths[key] = [...nameToPaths[key]];
132
+ const {
133
+ fontsParsed,
134
+ getCSS,
135
+ tokensParsed,
136
+ themeConfig,
137
+ shorthands: _shorthands,
138
+ userShorthands,
139
+ ...cleanedConfig
140
+ } = next.guiConfig;
141
+ return {
142
+ components,
143
+ nameToPaths,
144
+ guiConfig: {
145
+ ...cleanedConfig,
146
+ // Output userShorthands as shorthands (excludes built-ins)
147
+ shorthands: userShorthands
148
+ }
149
+ };
150
+ }