@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 extractToNative_exports = {};
33
35
  __export(extractToNative_exports, {
34
36
  extractToNative: () => extractToNative,
@@ -36,48 +38,53 @@ __export(extractToNative_exports, {
36
38
  getBabelPlugin: () => getBabelPlugin
37
39
  });
38
40
  module.exports = __toCommonJS(extractToNative_exports);
39
- var import_core = require("@babel/core"),
40
- import_generator = __toESM(require("@babel/generator")),
41
- import_helper_plugin_utils = require("@babel/helper-plugin-utils"),
42
- import_parser = require("@babel/parser"),
43
- import_template = __toESM(require("@babel/template")),
44
- t = __toESM(require("@babel/types")),
45
- import_node_path = require("node:path"),
46
- import_getPragmaOptions = require("../getPragmaOptions.cjs"),
47
- import_createExtractor = require("./createExtractor.cjs"),
48
- import_createLogger = require("./createLogger.cjs"),
49
- import_extractHelpers = require("./extractHelpers.cjs"),
50
- import_literalToAst = require("./literalToAst.cjs"),
51
- import_loadGui = require("./loadGui.cjs");
41
+ var import_core = require("@babel/core");
42
+ var import_generator = __toESM(require("@babel/generator"));
43
+ var import_helper_plugin_utils = require("@babel/helper-plugin-utils");
44
+ var import_parser = require("@babel/parser");
45
+ var import_template = __toESM(require("@babel/template"));
46
+ var t = __toESM(require("@babel/types"));
47
+ var import_node_path = require("node:path");
48
+ var import_getPragmaOptions = require("../getPragmaOptions.cjs");
49
+ var import_createExtractor = require("./createExtractor.cjs");
50
+ var import_createLogger = require("./createLogger.cjs");
51
+ var import_extractHelpers = require("./extractHelpers.cjs");
52
+ var import_literalToAst = require("./literalToAst.cjs");
53
+ var import_loadGui = require("./loadGui.cjs");
52
54
  const importNativeView = (0, import_template.default)(`
53
55
  const __ReactNativeView = require('react-native').View;
54
56
  const __ReactNativeText = require('react-native').Text;
55
- `),
56
- importStyleSheet = (0, import_template.default)(`
57
+ `);
58
+ const importStyleSheet = (0, import_template.default)(`
57
59
  const __ReactNativeStyleSheet = require('react-native').StyleSheet;
58
- `),
59
- importWithStyle = import_template.default.ast("import { _withStableStyle } from '@hanzogui/core';"),
60
- extractor = (0, import_createExtractor.createExtractor)({
61
- platform: "native"
62
- });
60
+ `);
61
+ const importWithStyle = import_template.default.ast(`import { _withStableStyle } from '@hanzogui/core';`);
62
+ const extractor = (0, import_createExtractor.createExtractor)({
63
+ platform: "native"
64
+ });
63
65
  let guiBuildOptionsLoaded;
64
66
  function extractToNative(sourceFileName, sourceCode, options) {
65
67
  const ast = (0, import_parser.parse)(sourceCode, {
66
- sourceType: "module",
67
- plugins: ["jsx", "typescript"]
68
- }),
69
- babelPlugin = getBabelPlugin(),
70
- out = (0, import_core.transformFromAstSync)(ast, sourceCode, {
71
- plugins: [[babelPlugin, options]],
72
- configFile: !1,
73
- sourceFileName,
74
- filename: sourceFileName
75
- });
76
- if (!out) throw new Error("No output returned");
68
+ sourceType: "module",
69
+ plugins: ["jsx", "typescript"]
70
+ });
71
+ const babelPlugin = getBabelPlugin();
72
+ const out = (0, import_core.transformFromAstSync)(ast, sourceCode, {
73
+ plugins: [[babelPlugin, options]],
74
+ configFile: false,
75
+ sourceFileName,
76
+ filename: sourceFileName
77
+ });
78
+ if (!out) {
79
+ throw new Error(`No output returned`);
80
+ }
77
81
  return out;
78
82
  }
79
83
  function getBabelPlugin() {
80
- return (0, import_helper_plugin_utils.declare)((api, options) => (api.assertVersion(7), getBabelParseDefinition(options)));
84
+ return (0, import_helper_plugin_utils.declare)((api, options) => {
85
+ api.assertVersion(7);
86
+ return getBabelParseDefinition(options);
87
+ });
81
88
  }
82
89
  function getBabelParseDefinition(options) {
83
90
  return {
@@ -86,46 +93,59 @@ function getBabelParseDefinition(options) {
86
93
  Program: {
87
94
  enter(root) {
88
95
  let sourcePath = this.file.opts.filename;
89
- if (sourcePath?.includes("node_modules") || !sourcePath?.endsWith(".jsx") && !sourcePath?.endsWith(".tsx")) return;
90
- process.env.SOURCE_ROOT?.endsWith("ios") && (sourcePath = sourcePath.replace("/ios", ""));
91
- let hasImportedView = !1,
92
- hasImportedViewWrapper = !1,
93
- wrapperCount = 0;
94
- const sheetStyles = {},
95
- sheetIdentifier = root.scope.generateUidIdentifier("sheet"),
96
- firstCommentContents =
97
- // join because you can join together multiple pragmas
98
- root.node.body[0]?.leadingComments?.map(comment => comment?.value || " ").join(" ") ?? "",
99
- firstComment = firstCommentContents ? `//${firstCommentContents}` : "",
100
- {
101
- shouldPrintDebug,
102
- shouldDisable
103
- } = (0, import_getPragmaOptions.getPragmaOptions)({
104
- source: firstComment,
105
- path: sourcePath
106
- });
107
- if (shouldDisable) return;
108
- !options.config && !options.components && (guiBuildOptionsLoaded ||= (0, import_loadGui.loadGuiBuildConfigSync)({}));
96
+ if (sourcePath?.includes("node_modules")) {
97
+ return;
98
+ }
99
+ if (!sourcePath?.endsWith(".jsx") && !sourcePath?.endsWith(".tsx")) {
100
+ return;
101
+ }
102
+ if (process.env.SOURCE_ROOT?.endsWith("ios")) {
103
+ sourcePath = sourcePath.replace("/ios", "");
104
+ }
105
+ let hasImportedView = false;
106
+ let hasImportedViewWrapper = false;
107
+ let wrapperCount = 0;
108
+ const sheetStyles = {};
109
+ const sheetIdentifier = root.scope.generateUidIdentifier("sheet");
110
+ const firstCommentContents =
111
+ // join because you can join together multiple pragmas
112
+ root.node.body[0]?.leadingComments?.map(comment => comment?.value || " ").join(" ") ?? "";
113
+ const firstComment = firstCommentContents ? `//${firstCommentContents}` : "";
114
+ const {
115
+ shouldPrintDebug,
116
+ shouldDisable
117
+ } = (0, import_getPragmaOptions.getPragmaOptions)({
118
+ source: firstComment,
119
+ path: sourcePath
120
+ });
121
+ if (shouldDisable) {
122
+ return;
123
+ }
124
+ if (!options.config && !options.components) {
125
+ guiBuildOptionsLoaded ||= (0, import_loadGui.loadGuiBuildConfigSync)({});
126
+ }
109
127
  const finalOptions = {
110
- // @ts-ignore just in case they leave it out
111
- platform: "native",
112
- ...guiBuildOptionsLoaded,
113
- ...options
114
- },
115
- printLog = (0, import_createLogger.createLogger)(sourcePath, finalOptions);
128
+ // @ts-ignore just in case they leave it out
129
+ platform: "native",
130
+ ...guiBuildOptionsLoaded,
131
+ ...options
132
+ };
133
+ const printLog = (0, import_createLogger.createLogger)(sourcePath, finalOptions);
116
134
  function addSheetStyle(style, node) {
117
- let key = `${`${Object.keys(sheetStyles).length}`}`;
135
+ const styleIndex = `${Object.keys(sheetStyles).length}`;
136
+ let key = `${styleIndex}`;
118
137
  if (process.env.NODE_ENV === "development") {
119
138
  const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
120
139
  key += `:${(0, import_node_path.basename)(sourcePath)}:${lineNumbers}`;
121
140
  }
122
- return sheetStyles[key] = style, readStyleExpr(key);
141
+ sheetStyles[key] = style;
142
+ return readStyleExpr(key);
123
143
  }
124
144
  function readStyleExpr(key) {
125
- return (0, import_template.default)("SHEET['KEY']")({
145
+ return (0, import_template.default)(`SHEET['KEY']`)({
126
146
  SHEET: sheetIdentifier.name,
127
147
  KEY: key
128
- }).expression;
148
+ })["expression"];
129
149
  }
130
150
  let res;
131
151
  try {
@@ -137,7 +157,7 @@ function getBabelParseDefinition(options) {
137
157
  shouldPrintDebug,
138
158
  ...finalOptions,
139
159
  // disable extracting variables as no native concept of them (only theme values)
140
- disableExtractVariables: !1,
160
+ disableExtractVariables: false,
141
161
  sourcePath,
142
162
  // disabling flattening for now
143
163
  // it's flattening a plain <Paragraph>hello</Paragraph> which breaks things because themes
@@ -147,16 +167,20 @@ function getBabelParseDefinition(options) {
147
167
  getFlattenedNode({
148
168
  isTextView
149
169
  }) {
150
- return hasImportedView || (hasImportedView = !0, root.unshiftContainer("body", importNativeView())), isTextView ? "__ReactNativeText" : "__ReactNativeView";
170
+ if (!hasImportedView) {
171
+ hasImportedView = true;
172
+ root.unshiftContainer("body", importNativeView());
173
+ }
174
+ return isTextView ? "__ReactNativeText" : "__ReactNativeView";
151
175
  },
152
176
  onExtractTag(props) {
153
177
  assertValidTag(props.node);
154
- const stylesExpr = t.arrayExpression([]),
155
- hocStylesExpr = t.arrayExpression([]),
156
- expressions = [],
157
- finalAttrs = [],
158
- themeKeysUsed = /* @__PURE__ */new Set();
159
- function getStyleExpression(style) {
178
+ const stylesExpr = t.arrayExpression([]);
179
+ const hocStylesExpr = t.arrayExpression([]);
180
+ const expressions = [];
181
+ const finalAttrs = [];
182
+ const themeKeysUsed = /* @__PURE__ */new Set();
183
+ function getStyleExpression(style, forTernary = false) {
160
184
  if (!style) return;
161
185
  const {
162
186
  plain,
@@ -164,100 +188,171 @@ function getBabelParseDefinition(options) {
164
188
  } = splitThemeStyles(style);
165
189
  let themeExpr = null;
166
190
  if (themed) {
167
- for (const key in themed) themeKeysUsed.add(themed[key].split("$")[1]);
191
+ for (const key in themed) {
192
+ themeKeysUsed.add(themed[key].split("$")[1]);
193
+ }
168
194
  themeExpr = getThemedStyleExpression(themed);
169
195
  }
170
- const ident = addSheetStyle(plain, props.node);
171
- return themeExpr ? (addStyleExpression(ident), addStyleExpression(ident, !0), themeExpr) : ident;
196
+ const hasPlainKeys = Object.keys(plain).length > 0;
197
+ const ident = hasPlainKeys ? addSheetStyle(plain, props.node) : null;
198
+ if (themeExpr) {
199
+ if (forTernary) {
200
+ if (ident) {
201
+ return t.arrayExpression([ident, themeExpr]);
202
+ }
203
+ return themeExpr;
204
+ }
205
+ if (ident) {
206
+ addStyleExpression(ident);
207
+ addStyleExpression(ident, true);
208
+ }
209
+ return themeExpr;
210
+ }
211
+ return ident;
172
212
  }
173
- function addStyleExpression(expr, HOC = !1) {
174
- Array.isArray(expr) ? (HOC ? hocStylesExpr : stylesExpr).elements.push(...expr) : (HOC ? hocStylesExpr : stylesExpr).elements.push(expr);
213
+ function addStyleExpression(expr, HOC = false) {
214
+ if (Array.isArray(expr)) {
215
+ ;
216
+ (HOC ? hocStylesExpr : stylesExpr).elements.push(...expr);
217
+ } else {
218
+ ;
219
+ (HOC ? hocStylesExpr : stylesExpr).elements.push(expr);
220
+ }
175
221
  }
176
222
  function getThemedStyleExpression(styles) {
177
223
  const themedStylesAst = (0, import_literalToAst.literalToAst)(styles);
178
- return themedStylesAst.properties.forEach(_ => {
224
+ themedStylesAst.properties.forEach(_ => {
179
225
  const prop = _;
180
226
  if (prop.value.type === "StringLiteral") {
181
- const propVal = prop.value.value.slice(1),
182
- isComputed = !t.isValidIdentifier(propVal);
227
+ const propVal = prop.value.value.slice(1);
228
+ const isComputed = !t.isValidIdentifier(propVal);
183
229
  prop.value = t.callExpression(t.memberExpression(t.memberExpression(t.identifier("theme"), isComputed ? t.stringLiteral(propVal) : t.identifier(propVal), isComputed), t.identifier("get")), []);
184
230
  }
185
- }), themedStylesAst;
231
+ });
232
+ return themedStylesAst;
186
233
  }
187
- let hasDynamicStyle = !1;
188
- for (const attr of props.attrs) switch (attr.type) {
189
- case "style":
190
- {
191
- let styleExpr = getStyleExpression(attr.value);
192
- addStyleExpression(styleExpr), addStyleExpression(styleExpr, !0);
193
- break;
194
- }
195
- case "ternary":
196
- {
197
- const {
234
+ let hasDynamicStyle = false;
235
+ let hasMediaKeys = false;
236
+ for (const attr of props.attrs) {
237
+ switch (attr.type) {
238
+ case "style":
239
+ {
240
+ let styleExpr = getStyleExpression(attr.value);
241
+ addStyleExpression(styleExpr);
242
+ addStyleExpression(styleExpr, true);
243
+ break;
244
+ }
245
+ case "ternary":
246
+ {
247
+ const {
198
248
  consequent,
199
249
  alternate
200
- } = attr.value,
201
- consExpr = getStyleExpression(consequent),
202
- altExpr = getStyleExpression(alternate);
203
- expressions.push(attr.value.test), addStyleExpression(t.conditionalExpression(t.identifier(`_expressions[${expressions.length - 1}]`), consExpr || t.nullLiteral(), altExpr || t.nullLiteral()), !0);
204
- const styleExpr = t.conditionalExpression(attr.value.test, consExpr || t.nullLiteral(), altExpr || t.nullLiteral());
205
- addStyleExpression(styleExpr);
206
- break;
207
- }
208
- case "attr":
209
- {
210
- t.isJSXSpreadAttribute(attr.value) && (0, import_extractHelpers.isSimpleSpread)(attr.value) && (stylesExpr.elements.push(t.memberExpression(attr.value.argument, t.identifier("style"))), hocStylesExpr.elements.push(t.memberExpression(attr.value.argument, t.identifier("style")))), finalAttrs.push(attr.value);
211
- break;
212
- }
250
+ } = attr.value;
251
+ const consExpr = getStyleExpression(consequent, true);
252
+ const altExpr = getStyleExpression(alternate, true);
253
+ if (attr.value.inlineMediaQuery) {
254
+ hasMediaKeys = true;
255
+ }
256
+ expressions.push(attr.value.test);
257
+ addStyleExpression(t.conditionalExpression(t.identifier(`_expressions[${expressions.length - 1}]`), consExpr || t.nullLiteral(), altExpr || t.nullLiteral()), true);
258
+ const styleExpr = t.conditionalExpression(attr.value.test, consExpr || t.nullLiteral(), altExpr || t.nullLiteral());
259
+ addStyleExpression(styleExpr);
260
+ break;
261
+ }
262
+ case "attr":
263
+ {
264
+ if (t.isJSXSpreadAttribute(attr.value)) {
265
+ if ((0, import_extractHelpers.isSimpleSpread)(attr.value)) {
266
+ stylesExpr.elements.push(t.memberExpression(attr.value.argument, t.identifier("style")));
267
+ hocStylesExpr.elements.push(t.memberExpression(attr.value.argument, t.identifier("style")));
268
+ }
269
+ }
270
+ finalAttrs.push(attr.value);
271
+ break;
272
+ }
273
+ }
213
274
  }
214
- if (props.node.attributes = finalAttrs, themeKeysUsed.size || hocStylesExpr.elements.length > 1 || hasDynamicStyle) {
215
- hasImportedViewWrapper || (root.unshiftContainer("body", importWithStyle), hasImportedViewWrapper = !0);
216
- const name = props.flatNodeName || props.node.name.name,
217
- wrapperName = `_${name.replace(/^_+/, "")}Styled${wrapperCount++}`,
218
- WrapperIdentifier = t.identifier(wrapperName),
219
- WrapperJSXIdentifier = t.jsxIdentifier(wrapperName);
275
+ props.node.attributes = finalAttrs;
276
+ if (themeKeysUsed.size || hocStylesExpr.elements.length > 1 || hasDynamicStyle) {
277
+ if (!hasImportedViewWrapper) {
278
+ root.unshiftContainer("body", importWithStyle);
279
+ hasImportedViewWrapper = true;
280
+ }
281
+ const name = props.flatNodeName || props.node.name["name"];
282
+ const wrapperName = `_${name.replace(/^_+/, "")}Styled${wrapperCount++}`;
283
+ const WrapperIdentifier = t.identifier(wrapperName);
284
+ const WrapperJSXIdentifier = t.jsxIdentifier(wrapperName);
285
+ const hasThemeKeysFlag = themeKeysUsed.size > 0;
220
286
  root.pushContainer("body", t.variableDeclaration("const", [t.variableDeclarator(WrapperIdentifier, t.callExpression(t.identifier("_withStableStyle"), [t.identifier(name), t.arrowFunctionExpression([t.identifier("theme"), t.identifier("_expressions")],
221
287
  // return styles directly - no useMemo, theme changes must trigger style recalc
222
- t.arrayExpression([...hocStylesExpr.elements]))]))])), props.node.name = WrapperJSXIdentifier, props.jsxPath.node.openingElement.name = WrapperJSXIdentifier, props.jsxPath.node.closingElement && (props.jsxPath.node.closingElement.name = t.jsxIdentifier(wrapperName)), expressions.length && props.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("_expressions"), t.jsxExpressionContainer(t.arrayExpression(expressions))));
223
- } else props.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("style"), t.jsxExpressionContainer(stylesExpr.elements.length === 1 ? stylesExpr.elements[0] : stylesExpr)));
288
+ t.arrayExpression([...hocStylesExpr.elements])), t.booleanLiteral(hasThemeKeysFlag), t.booleanLiteral(hasMediaKeys)]))]));
289
+ props.node.name = WrapperJSXIdentifier;
290
+ props.jsxPath.node.openingElement.name = WrapperJSXIdentifier;
291
+ if (props.jsxPath.node.closingElement) {
292
+ props.jsxPath.node.closingElement.name = t.jsxIdentifier(wrapperName);
293
+ }
294
+ if (expressions.length) {
295
+ const safeExpressions = expressions.map(expr => t.isStringLiteral(expr) ? expr : t.unaryExpression("!", t.unaryExpression("!", expr)));
296
+ props.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("_expressions"), t.jsxExpressionContainer(t.arrayExpression(safeExpressions))));
297
+ }
298
+ } else {
299
+ props.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("style"), t.jsxExpressionContainer(stylesExpr.elements.length === 1 ? stylesExpr.elements[0] : stylesExpr)));
300
+ }
224
301
  }
225
302
  });
226
303
  } catch (err) {
227
304
  if (err instanceof Error) {
228
305
  let message = `${shouldPrintDebug === "verbose" ? err : err.message}`;
229
- message.includes("Unexpected return value from visitor method") && (message = "Unexpected return value from visitor method"), console.warn("Error in Hanzo GUI parse, skipping", message, err.stack);
306
+ if (message.includes("Unexpected return value from visitor method")) {
307
+ message = "Unexpected return value from visitor method";
308
+ }
309
+ console.warn("Error in GUI parse, skipping", message, err.stack);
230
310
  return;
231
311
  }
232
312
  }
233
313
  if (!Object.keys(sheetStyles).length) {
234
- shouldPrintDebug && console.info("END no styles"), res && printLog(res);
314
+ if (shouldPrintDebug) {
315
+ console.info("END no styles");
316
+ }
317
+ if (res) printLog(res);
235
318
  return;
236
319
  }
237
- const sheetObject = (0, import_literalToAst.literalToAst)(sheetStyles),
238
- sheetOuter = (0, import_template.default)("const SHEET = __ReactNativeStyleSheet.create(null)")({
239
- SHEET: sheetIdentifier.name
240
- });
241
- sheetOuter.declarations[0].init.arguments[0] = sheetObject, root.unshiftContainer("body", sheetOuter), root.unshiftContainer("body", importStyleSheet()), shouldPrintDebug && (console.info(`
242
- -------- output code -------
243
- `), console.info((0, import_generator.default)(root.parent).code.split(`
244
- `).filter(x => !x.startsWith("//")).join(`
245
- `))), res && printLog(res);
320
+ const sheetObject = (0, import_literalToAst.literalToAst)(sheetStyles);
321
+ const sheetOuter = (0, import_template.default)("const SHEET = __ReactNativeStyleSheet.create(null)")({
322
+ SHEET: sheetIdentifier.name
323
+ });
324
+ sheetOuter.declarations[0].init.arguments[0] = sheetObject;
325
+ root.unshiftContainer("body", sheetOuter);
326
+ root.unshiftContainer("body", importStyleSheet());
327
+ if (shouldPrintDebug) {
328
+ console.info("\n -------- output code ------- \n");
329
+ console.info((0, import_generator.default)(root.parent).code.split("\n").filter(x => !x.startsWith("//")).join("\n"));
330
+ }
331
+ if (res) printLog(res);
246
332
  }
247
333
  }
248
334
  }
249
335
  };
250
336
  }
251
337
  function assertValidTag(node) {
252
- node.attributes.find(x => x.type === "JSXAttribute" && x.name.name === "style") && process.env.DEBUG?.startsWith("@hanzo/gui") && console.warn("\u26A0\uFE0F Cannot pass style attribute to extracted style");
338
+ if (node.attributes.find(x => x.type === "JSXAttribute" && x.name.name === "style")) {
339
+ if (process.env.DEBUG?.startsWith("@hanzo/gui")) {
340
+ console.warn("\u26A0\uFE0F Cannot pass style attribute to extracted style");
341
+ }
342
+ }
253
343
  }
254
344
  function splitThemeStyles(style) {
255
- const themed = {},
256
- plain = {};
257
- let noTheme = !0;
345
+ const themed = {};
346
+ const plain = {};
347
+ let noTheme = true;
258
348
  for (const key in style) {
259
349
  const val = style[key];
260
- val && val[0] === "$" ? (themed[key] = val, noTheme = !1) : plain[key] = val;
350
+ if (val && val[0] === "$") {
351
+ themed[key] = val;
352
+ noTheme = false;
353
+ } else {
354
+ plain[key] = val;
355
+ }
261
356
  }
262
357
  return {
263
358
  themed: noTheme ? null : themed,
@@ -3,20 +3,22 @@ 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 findTopmostFunction_exports = {};
22
24
  __export(findTopmostFunction_exports, {
@@ -26,9 +28,16 @@ module.exports = __toCommonJS(findTopmostFunction_exports);
26
28
  function findTopmostFunction(jsxPath) {
27
29
  const isFunction = path => path.isArrowFunctionExpression() || path.isFunctionDeclaration() || path.isFunctionExpression();
28
30
  let compFn = jsxPath.findParent(isFunction);
29
- for (; compFn;) {
31
+ while (compFn) {
30
32
  const parent = compFn.findParent(isFunction);
31
- if (parent) compFn = parent;else break;
33
+ if (parent) {
34
+ compFn = parent;
35
+ } else {
36
+ break;
37
+ }
38
+ }
39
+ if (!compFn) {
40
+ return null;
32
41
  }
33
- return compFn || null;
42
+ return compFn;
34
43
  }
@@ -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 generatedUid_exports = {};
33
35
  __export(generatedUid_exports, {
34
36
  generateUid: () => generateUid
@@ -36,12 +38,21 @@ __export(generatedUid_exports, {
36
38
  module.exports = __toCommonJS(generatedUid_exports);
37
39
  var t = __toESM(require("@babel/types"));
38
40
  function generateUid(scope, name) {
39
- if (typeof scope != "object") throw "generateUid expects a scope object as its first parameter";
40
- if (!(typeof name == "string" && name !== "")) throw "generateUid expects a valid name as its second parameter";
41
+ if (!(typeof scope === "object")) throw "generateUid expects a scope object as its first parameter";
42
+ if (!(typeof name === "string" && name !== "")) throw "generateUid expects a valid name as its second parameter";
41
43
  name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
42
- let uid,
43
- i = 0;
44
- do i > 1 ? uid = name + i : uid = name, i++; while (scope.hasLabel(uid) || scope.hasBinding(uid) || scope.hasGlobal(uid) || scope.hasReference(uid));
44
+ let uid;
45
+ let i = 0;
46
+ do {
47
+ if (i > 1) {
48
+ uid = name + i;
49
+ } else {
50
+ uid = name;
51
+ }
52
+ i++;
53
+ } while (scope.hasLabel(uid) || scope.hasBinding(uid) || scope.hasGlobal(uid) || scope.hasReference(uid));
45
54
  const program = scope.getProgramParent();
46
- return program.references[uid] = !0, program.uids[uid] = !0, uid;
55
+ program.references[uid] = true;
56
+ program.uids[uid] = true;
57
+ return uid;
47
58
  }