@hanzogui/static 3.0.6 → 4.4.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 (76) hide show
  1. package/dist/check-dep-versions.cjs +201 -96
  2. package/dist/checkDeps.cjs +163 -92
  3. package/dist/constants.cjs +32 -30
  4. package/dist/exports.cjs +15 -13
  5. package/dist/extractor/accessSafe.cjs +25 -23
  6. package/dist/extractor/babelParse.cjs +30 -28
  7. package/dist/extractor/buildClassName.cjs +59 -35
  8. package/dist/extractor/bundle.cjs +163 -105
  9. package/dist/extractor/bundleConfig.cjs +467 -264
  10. package/dist/extractor/concatClassName.cjs +41 -29
  11. package/dist/extractor/createEvaluator.cjs +54 -41
  12. package/dist/extractor/createExtractor.cjs +1338 -661
  13. package/dist/extractor/createLogger.cjs +30 -25
  14. package/dist/extractor/detectModuleFormat.cjs +22 -16
  15. package/dist/extractor/ensureImportingConcat.cjs +31 -25
  16. package/dist/extractor/errors.cjs +12 -10
  17. package/dist/extractor/esbuildAliasPlugin.cjs +28 -16
  18. package/dist/extractor/esbuildTsconfigPaths.cjs +58 -36
  19. package/dist/extractor/evaluateAstNode.cjs +104 -59
  20. package/dist/extractor/extractHelpers.cjs +130 -67
  21. package/dist/extractor/extractMediaStyle.cjs +110 -69
  22. package/dist/extractor/extractToClassNames.cjs +336 -230
  23. package/dist/extractor/extractToNative.cjs +244 -149
  24. package/dist/extractor/findTopmostFunction.cjs +22 -13
  25. package/dist/extractor/generatedUid.cjs +39 -28
  26. package/dist/extractor/getGuiConfigPathFromOptionsConfig.cjs +20 -14
  27. package/dist/extractor/getPrefixLogs.cjs +12 -10
  28. package/dist/extractor/getPropValueFromAttributes.cjs +52 -34
  29. package/dist/extractor/getSourceModule.cjs +73 -37
  30. package/dist/extractor/getStaticBindingsForScope.cjs +131 -68
  31. package/dist/extractor/hasTopLevelAwait.cjs +62 -0
  32. package/dist/extractor/hoistClassNames.cjs +46 -32
  33. package/dist/extractor/literalToAst.cjs +67 -42
  34. package/dist/extractor/loadFile.cjs +9 -3
  35. package/dist/extractor/loadGui.cjs +198 -109
  36. package/dist/extractor/logLines.cjs +27 -19
  37. package/dist/extractor/normalizeTernaries.cjs +66 -44
  38. package/dist/extractor/propsToFontFamilyCache.cjs +15 -11
  39. package/dist/extractor/regenerateConfig.cjs +109 -81
  40. package/dist/extractor/removeUnusedHooks.cjs +73 -41
  41. package/dist/extractor/timer.cjs +23 -14
  42. package/dist/extractor/validHTMLAttributes.cjs +61 -59
  43. package/dist/extractor/watchGuiConfig.cjs +35 -23
  44. package/dist/getPragmaOptions.cjs +34 -19
  45. package/dist/helpers/memoize.cjs +24 -16
  46. package/dist/helpers/requireGuiCore.cjs +22 -15
  47. package/dist/index.cjs +26 -24
  48. package/dist/registerRequire.cjs +170 -77
  49. package/dist/server.cjs +35 -28
  50. package/dist/types.cjs +7 -5
  51. package/dist/worker.cjs +62 -40
  52. package/package.json +15 -15
  53. package/src/checkDeps.ts +1 -1
  54. package/src/extractor/babelParse.ts +1 -0
  55. package/src/extractor/bundle.ts +6 -6
  56. package/src/extractor/bundleConfig.ts +10 -10
  57. package/src/extractor/createExtractor.ts +28 -13
  58. package/src/extractor/createLogger.ts +1 -3
  59. package/src/extractor/extractToNative.ts +35 -9
  60. package/src/extractor/hasTopLevelAwait.ts +28 -0
  61. package/src/extractor/loadGui.ts +4 -4
  62. package/src/extractor/regenerateConfig.ts +2 -2
  63. package/src/getPragmaOptions.ts +2 -2
  64. package/src/helpers/requireGuiCore.ts +6 -6
  65. package/src/registerRequire.ts +52 -5
  66. package/src/worker.ts +1 -1
  67. package/types/extractor/babelParse.d.ts.map +1 -1
  68. package/types/extractor/bundle.d.ts.map +1 -1
  69. package/types/extractor/bundleConfig.d.ts.map +1 -1
  70. package/types/extractor/createExtractor.d.ts.map +1 -1
  71. package/types/extractor/createLogger.d.ts.map +1 -1
  72. package/types/extractor/extractToNative.d.ts.map +1 -1
  73. package/types/extractor/hasTopLevelAwait.d.ts +2 -0
  74. package/types/extractor/hasTopLevelAwait.d.ts.map +1 -0
  75. package/types/registerRequire.d.ts.map +1 -1
  76. package/types/worker.d.ts +1 -1
@@ -2,33 +2,35 @@ var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf,
6
- __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
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, {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
16
  get: () => from[key],
16
17
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
18
  });
18
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  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);
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
+ value: mod,
29
+ enumerable: true
30
+ }) : target, mod));
31
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: true
33
+ }), mod);
32
34
  var loadGui_exports = {};
33
35
  __export(loadGui_exports, {
34
36
  esbuildWatchFiles: () => esbuildWatchFiles,
@@ -41,17 +43,17 @@ __export(loadGui_exports, {
41
43
  resolveWebOrNativeSpecificEntry: () => resolveWebOrNativeSpecificEntry
42
44
  });
43
45
  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");
46
+ var import_node_path = require("node:path");
47
+ var import_cli_color = require("@hanzogui/cli-color");
48
+ var import_esbuild = __toESM(require("esbuild"));
49
+ var esbuildWasm = __toESM(require("esbuild-wasm"));
50
+ var fsExtra = __toESM(require("fs-extra"));
51
+ var import_constants = require("../constants.cjs");
52
+ var import_requireGuiCore = require("../helpers/requireGuiCore.cjs");
53
+ var import_registerRequire = require("../registerRequire.cjs");
54
+ var import_bundleConfig = require("./bundleConfig.cjs");
55
+ var import_getGuiConfigPathFromOptionsConfig = require("./getGuiConfigPathFromOptionsConfig.cjs");
56
+ var import_regenerateConfig = require("./regenerateConfig.cjs");
55
57
  const getFilledOptions = propsIn => ({
56
58
  // defaults
57
59
  platform: "web",
@@ -62,14 +64,20 @@ const getFilledOptions = propsIn => ({
62
64
  let isLoadingPromise;
63
65
  async function loadGui(propsIn) {
64
66
  if (isLoadingPromise) return await isLoadingPromise;
65
- let resolvePromise, rejectPromise;
67
+ let resolvePromise;
68
+ let rejectPromise;
66
69
  isLoadingPromise = new Promise((res, rej) => {
67
- resolvePromise = res, rejectPromise = rej;
70
+ resolvePromise = res;
71
+ rejectPromise = rej;
68
72
  });
69
73
  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;
74
+ const props = getFilledOptions(propsIn);
75
+ const bundleInfo = await (0, import_bundleConfig.getBundledConfig)(props);
76
+ if (!bundleInfo) {
77
+ console.warn(`No bundled config generated, maybe an error in bundling. Set DEBUG=hanzo-gui and re-run to get logs.`);
78
+ resolvePromise(null);
79
+ return null;
80
+ }
73
81
  await generateThemesAndLog(props);
74
82
  const maybeGuiConfig = bundleInfo.guiConfig;
75
83
  if (maybeGuiConfig && !maybeGuiConfig.parsed) {
@@ -78,53 +86,82 @@ async function loadGui(propsIn) {
78
86
  } = (0, import_requireGuiCore.requireGuiCore)(props.platform || "web");
79
87
  bundleInfo.guiConfig = createGui(bundleInfo.guiConfig);
80
88
  }
81
- return (0, import_bundleConfig.hasBundledConfigChanged)() ? (await (0, import_regenerateConfig.regenerateConfig)(props, bundleInfo), resolvePromise(bundleInfo), bundleInfo) : (resolvePromise(bundleInfo), bundleInfo);
89
+ if (!(0, import_bundleConfig.hasBundledConfigChanged)()) {
90
+ resolvePromise(bundleInfo);
91
+ return bundleInfo;
92
+ }
93
+ await (0, import_regenerateConfig.regenerateConfig)(props, bundleInfo);
94
+ resolvePromise(bundleInfo);
95
+ return bundleInfo;
82
96
  } catch (err) {
83
- throw rejectPromise(), err;
97
+ rejectPromise();
98
+ throw err;
84
99
  } finally {
85
100
  isLoadingPromise = null;
86
101
  }
87
102
  }
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)) {
103
+ let waiting = false;
104
+ const generateThemesAndLog = async (options, force = false) => {
105
+ if (waiting) return;
106
+ if (!options.themeBuilder) return;
107
+ try {
108
+ waiting = true;
109
+ await new Promise(res => setTimeout(res, 30));
110
+ const didGenerate = await (0, import_regenerateConfig.generateGuiThemes)(options, force);
111
+ if (didGenerate) {
112
+ const whitespaceBefore = ` `;
113
+ (0, import_cli_color.colorLog)(import_cli_color.Color.FgYellow, `${whitespaceBefore}\u27A1 [hanzo-gui] generated themes: ${(0, import_node_path.relative)(process.cwd(), options.themeBuilder.output)}`);
114
+ if (options.outputCSS) {
92
115
  const loadedConfig = (0, import_bundleConfig.getLoadedConfig)();
93
- loadedConfig && (await (0, import_bundleConfig.writeGuiCSS)(options.outputCSS, loadedConfig));
116
+ if (loadedConfig) {
117
+ await (0, import_bundleConfig.writeGuiCSS)(options.outputCSS, loadedConfig);
118
+ }
94
119
  }
95
- } finally {
96
- waiting = !1;
97
120
  }
98
- },
99
- last = {},
100
- lastVersion = {};
101
- let esbuildWasmInitialized = !1;
121
+ } finally {
122
+ waiting = false;
123
+ }
124
+ };
125
+ const last = {};
126
+ const lastVersion = {};
127
+ let esbuildWasmInitialized = false;
102
128
  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, {
129
+ const buildFilePath = guiOptions?.buildFile ?? "./gui.build.ts";
130
+ const absolutePath = buildFilePath[0] === "." ? (0, import_node_path.join)(process.cwd(), buildFilePath) : buildFilePath;
131
+ if (fsExtra.existsSync(absolutePath)) {
132
+ try {
133
+ const source = await fsExtra.readFile(absolutePath, "utf-8");
134
+ if (!esbuildWasmInitialized) {
135
+ await esbuildWasm.initialize({});
136
+ esbuildWasmInitialized = true;
137
+ }
138
+ const result = await esbuildWasm.transform(source, {
109
139
  loader: "ts",
110
140
  format: "cjs",
111
141
  target: "node18",
112
142
  sourcefile: absolutePath
113
- }),
114
- module2 = {
143
+ });
144
+ const module2 = {
115
145
  exports: {}
116
146
  };
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;
147
+ const fn = new Function("module", "exports", "require", "process", result.code);
148
+ fn(module2, module2.exports, require, process);
149
+ const out = module2.exports.default || module2.exports;
150
+ if (!out || typeof out !== "object") {
151
+ throw new Error(`No default export found in ${buildFilePath}: ${out}`);
152
+ }
153
+ guiOptions = {
154
+ ...guiOptions,
155
+ ...out
156
+ };
157
+ } catch (err) {
158
+ console.error(`[hanzo-gui] Error loading ${buildFilePath}:`, err);
159
+ throw err;
160
+ }
161
+ }
162
+ if (!guiOptions) {
163
+ throw new Error(`No hanzo-gui build options found either via input props or at gui.build.ts`);
126
164
  }
127
- if (!guiOptions) throw new Error("No hanzo-gui build options found either via input props or at gui.build.ts");
128
165
  return {
129
166
  config: "gui.config.ts",
130
167
  components: ["@hanzo/gui", "@hanzogui/core"],
@@ -137,7 +174,9 @@ function loadGuiBuildConfigSync(guiOptions) {
137
174
  const registered = (0, import_registerRequire.registerRequire)("web");
138
175
  try {
139
176
  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}`);
177
+ if (!out) {
178
+ throw new Error(`No default export found in ${buildFilePath}: ${out}`);
179
+ }
141
180
  guiOptions = {
142
181
  ...guiOptions,
143
182
  ...out
@@ -146,7 +185,9 @@ function loadGuiBuildConfigSync(guiOptions) {
146
185
  registered.unregister();
147
186
  }
148
187
  }
149
- if (!guiOptions) throw new Error("No hanzo-gui build options found either via input props or at gui.build.ts");
188
+ if (!guiOptions) {
189
+ throw new Error(`No hanzo-gui build options found either via input props or at gui.build.ts`);
190
+ }
150
191
  return {
151
192
  config: "gui.config.ts",
152
193
  components: ["@hanzo/gui", "@hanzogui/core"],
@@ -159,25 +200,33 @@ function loadGuiSync({
159
200
  ...propsIn
160
201
  }) {
161
202
  const key = JSON.stringify(propsIn);
162
- if (last[key] && !(0, import_bundleConfig.hasBundledConfigChanged)() && (!lastVersion[key] || lastVersion[key] === cacheKey)) return last[key];
203
+ if (last[key] && !(0, import_bundleConfig.hasBundledConfigChanged)()) {
204
+ if (!lastVersion[key] || lastVersion[key] === cacheKey) {
205
+ return last[key];
206
+ }
207
+ }
163
208
  lastVersion[key] = cacheKey || "";
164
209
  const props = getFilledOptions(propsIn);
165
- process.env.IS_STATIC = "is_static", process.env.HANZO_GUI_IS_SERVER = "true";
210
+ process.env.IS_STATIC = "is_static";
211
+ process.env.GUI_IS_SERVER = "true";
166
212
  const {
167
213
  unregister
168
214
  } = (0, import_registerRequire.registerRequire)(props.platform || "web", {
169
215
  proxyWormImports: !!forceExports
170
216
  });
171
217
  try {
172
- const devValueOG = globalThis.__DEV__;
173
- globalThis.__DEV__ = process.env.NODE_ENV === "development";
218
+ const devValueOG = globalThis["__DEV__"];
219
+ globalThis["__DEV__"] = process.env.NODE_ENV === "development";
174
220
  try {
175
221
  let guiConfig = null;
176
222
  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) {
223
+ const configPath = (0, import_getGuiConfigPathFromOptionsConfig.getGuiConfigPathFromOptionsConfig)(propsIn.config);
224
+ const exp = require(configPath);
225
+ if (!exp || exp._isProxyWorm) {
226
+ throw new Error(`Got a empty / proxied config!`);
227
+ }
228
+ guiConfig = exp["default"] || exp["config"] || exp;
229
+ if (!guiConfig || !guiConfig.parsed) {
181
230
  const confPath = require.resolve(configPath);
182
231
  throw new Error(`Can't find valid config in ${confPath}:
183
232
 
@@ -191,8 +240,14 @@ function loadGuiSync({
191
240
  }
192
241
  }
193
242
  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;
243
+ if (!components) {
244
+ throw new Error(`No components loaded`);
245
+ }
246
+ if (process.env.DEBUG === "@hanzo/gui") {
247
+ console.info(`components`, components);
248
+ }
249
+ process.env.IS_STATIC = void 0;
250
+ globalThis["__DEV__"] = devValueOG;
196
251
  const info = {
197
252
  components,
198
253
  guiConfig,
@@ -202,18 +257,34 @@ function loadGuiSync({
202
257
  const {
203
258
  outputCSS
204
259
  } = props;
205
- outputCSS && (0, import_bundleConfig.writeGuiCSS)(outputCSS, guiConfig), (0, import_regenerateConfig.regenerateConfigSync)(props, info);
260
+ if (outputCSS) {
261
+ (0, import_bundleConfig.writeGuiCSS)(outputCSS, guiConfig);
262
+ }
263
+ (0, import_regenerateConfig.regenerateConfigSync)(props, info);
206
264
  }
207
- return last[key] = {
265
+ last[key] = {
208
266
  ...info,
209
- cached: !0
210
- }, info;
267
+ cached: true
268
+ };
269
+ return info;
211
270
  } 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(`
271
+ if (err instanceof Error) {
272
+ if (!import_constants.SHOULD_DEBUG && !forceExports) {
273
+ console.warn(`Error loading gui.config.ts (set DEBUG=hanzo-gui to see full stack), running hanzo-gui without custom config`);
274
+ console.info(`
213
275
 
214
276
  ${err.message}
215
277
 
216
- `)) : import_constants.SHOULD_DEBUG && console.error(err) : console.error("Error loading gui.config.ts", err), {
278
+ `);
279
+ } else {
280
+ if (import_constants.SHOULD_DEBUG) {
281
+ console.error(err);
282
+ }
283
+ }
284
+ } else {
285
+ console.error(`Error loading gui.config.ts`, err);
286
+ }
287
+ return {
217
288
  components: [],
218
289
  guiConfig: null,
219
290
  nameToPaths: {}
@@ -234,7 +305,7 @@ async function getOptions({
234
305
  let pkgJson = {};
235
306
  try {
236
307
  pkgJson = await fsExtra.readJSON((0, import_node_path.join)(root, "package.json"));
237
- } catch {}
308
+ } catch (err) {}
238
309
  return {
239
310
  mode: process.env.NODE_ENV === "production" ? "production" : "development",
240
311
  root,
@@ -257,33 +328,44 @@ async function getOptions({
257
328
  };
258
329
  }
259
330
  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;
331
+ const workspaceRoot = (0, import_node_path.resolve)();
332
+ const resolved = require.resolve(entry, {
333
+ paths: [workspaceRoot]
334
+ });
335
+ const ext = (0, import_node_path.extname)(resolved);
336
+ const fileName = (0, import_node_path.basename)(resolved).replace(ext, "");
337
+ const specificExt = true ? "web" : "native";
338
+ const specificFile = (0, import_node_path.join)((0, import_node_path.dirname)(resolved), fileName + "." + specificExt + ext);
339
+ if (fsExtra.existsSync(specificFile)) {
340
+ return specificFile;
341
+ }
342
+ return entry;
268
343
  }
269
344
  const defaultPaths = ["gui.config.ts", (0, import_node_path.join)("src", "gui.config.ts")];
270
- let hasWarnedOnce = !1;
345
+ let hasWarnedOnce = false;
271
346
  async function getDefaultGuiConfigPath(root, configPath) {
272
347
  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}":
348
+ for (const path of searchPaths) {
349
+ if (await fsExtra.pathExists(path)) {
350
+ return path;
351
+ }
352
+ }
353
+ if (!hasWarnedOnce) {
354
+ hasWarnedOnce = true;
355
+ console.warn(`Warning: couldn't find gui.config.ts in the following paths given configuration "${configPath}":
275
356
  ${searchPaths.join(`
276
357
  `)}
277
- `));
358
+ `);
359
+ }
278
360
  }
279
361
  async function esbuildWatchFiles(entry, onChanged) {
280
- let hasRunOnce = !1;
362
+ let hasRunOnce = false;
281
363
  const context = await import_esbuild.default.context({
282
- bundle: !0,
364
+ bundle: true,
283
365
  entryPoints: [entry],
284
366
  resolveExtensions: [".ts", ".tsx", ".js", ".mjs"],
285
367
  logLevel: "silent",
286
- write: !1,
368
+ write: false,
287
369
  alias: {
288
370
  "@react-native/normalize-color": "@hanzogui/proxy-worm",
289
371
  "react-native-web": "@hanzogui/react-native-web-lite",
@@ -300,23 +382,30 @@ async function esbuildWatchFiles(entry, onChanged) {
300
382
  // },
301
383
  // },
302
384
  {
303
- name: "on-rebuild",
385
+ name: `on-rebuild`,
304
386
  setup({
305
387
  onEnd,
306
388
  onResolve
307
389
  }) {
390
+ let filter = /^[^./]|^\.[^./]|^\.\.[^/]/;
308
391
  onResolve({
309
- filter: /^[^./]|^\.[^./]|^\.\.[^/]/
392
+ filter
310
393
  }, args => ({
311
394
  path: args.path,
312
- external: !0
313
- })), onEnd(() => {
314
- hasRunOnce ? onChanged() : hasRunOnce = !0;
395
+ external: true
396
+ }));
397
+ onEnd(() => {
398
+ if (!hasRunOnce) {
399
+ hasRunOnce = true;
400
+ } else {
401
+ onChanged();
402
+ }
315
403
  });
316
404
  }
317
405
  }]
318
406
  });
319
- return context.watch(), () => {
407
+ void context.watch();
408
+ return () => {
320
409
  context.dispose();
321
410
  };
322
411
  }
@@ -3,33 +3,41 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
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, {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
14
  get: () => from[key],
14
15
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
16
  });
16
- return to;
17
- };
17
+ }
18
+ return to;
19
+ };
18
20
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
- value: !0
21
+ value: true
20
22
  }), mod);
21
23
  var logLines_exports = {};
22
24
  __export(logLines_exports, {
23
25
  logLines: () => logLines
24
26
  });
25
27
  module.exports = __toCommonJS(logLines_exports);
26
- const prefix = " ",
27
- logLines = (str, singleLine = !1) => {
28
- if (singleLine) return prefix + str.split(" ").join(`
28
+ const prefix = " ";
29
+ const logLines = (str, singleLine = false) => {
30
+ if (singleLine) {
31
+ return prefix + str.split(" ").join(`
29
32
  ${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
- };
33
+ }
34
+ const lines = [""];
35
+ const items = str.split(" ");
36
+ for (const item of items) {
37
+ if (item.length + lines[lines.length - 1].length > 85) {
38
+ lines.push("");
39
+ }
40
+ lines[lines.length - 1] += item + " ";
41
+ }
42
+ return lines.map((line, i) => prefix + (i == 0 ? "" : " ") + line.trim()).join("\n");
43
+ };
@@ -2,45 +2,50 @@ var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf,
6
- __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
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, {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
16
  get: () => from[key],
16
17
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
18
  });
18
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  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);
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
+ value: mod,
29
+ enumerable: true
30
+ }) : target, mod));
31
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: true
33
+ }), mod);
32
34
  var normalizeTernaries_exports = {};
33
35
  __export(normalizeTernaries_exports, {
34
36
  normalizeTernaries: () => normalizeTernaries
35
37
  });
36
38
  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");
39
+ var import_generator = __toESM(require("@babel/generator"));
40
+ var t = __toESM(require("@babel/types"));
41
+ var import_web = require("@hanzogui/web");
42
+ var import_invariant = __toESM(require("invariant"));
43
+ var import_propsToFontFamilyCache = require("./propsToFontFamilyCache.cjs");
42
44
  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 [];
45
+ (0, import_invariant.default)(Array.isArray(ternaries), "extractStaticTernaries expects param 1 to be an array of ternaries");
46
+ if (ternaries.length === 0) {
47
+ return [];
48
+ }
44
49
  const ternariesByKey = {};
45
50
  for (let idx = -1, len = ternaries.length; ++idx < len;) {
46
51
  const {
@@ -51,23 +56,40 @@ function normalizeTernaries(ternaries) {
51
56
  ...rest
52
57
  } = ternaries[idx];
53
58
  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);
59
+ if (t.isExpressionStatement(test)) {
60
+ ternaryTest = test.expression;
61
+ }
62
+ let shouldSwap = false;
63
+ if (t.isUnaryExpression(test) && test.operator === "!") {
64
+ ternaryTest = test.argument;
65
+ shouldSwap = true;
66
+ } else if (t.isBinaryExpression(test)) {
67
+ if (test.operator === "!==" || test.operator === "!=") {
68
+ ternaryTest = t.binaryExpression(test.operator.replace("!", "="), test.left, test.right);
69
+ shouldSwap = true;
70
+ }
71
+ }
57
72
  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);
73
+ if (!ternariesByKey[key]) {
74
+ ternariesByKey[key] = {
75
+ ...rest,
76
+ alternate: {},
77
+ consequent: {},
78
+ test: ternaryTest,
79
+ remove
80
+ };
81
+ }
82
+ const altStyle = (shouldSwap ? consequent : alternate) ?? {};
83
+ const consStyle = (shouldSwap ? alternate : consequent) ?? {};
84
+ const nextAlt = ternariesByKey[key].alternate;
85
+ ternariesByKey[key].alternate = (0, import_web.mergeProps)(altStyle, nextAlt);
86
+ (0, import_propsToFontFamilyCache.forwardFontFamilyName)(altStyle, ternariesByKey[key].alternate);
69
87
  const nextCons = ternariesByKey[key].consequent;
70
- ternariesByKey[key].consequent = (0, import_web.mergeProps)(consStyle, nextCons), (0, import_propsToFontFamilyCache.forwardFontFamilyName)(consStyle, ternariesByKey[key].consequent);
88
+ ternariesByKey[key].consequent = (0, import_web.mergeProps)(consStyle, nextCons);
89
+ (0, import_propsToFontFamilyCache.forwardFontFamilyName)(consStyle, ternariesByKey[key].consequent);
71
90
  }
72
- return Object.keys(ternariesByKey).map(key => ternariesByKey[key]);
91
+ const ternaryExpression = Object.keys(ternariesByKey).map(key => {
92
+ return ternariesByKey[key];
93
+ });
94
+ return ternaryExpression;
73
95
  }