@hanzogui/static 7.3.0 → 8.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 (59) hide show
  1. package/dist/check-dep-versions.cjs +1 -1
  2. package/dist/checkDeps.cjs +10 -10
  3. package/dist/constants.cjs +2 -2
  4. package/dist/exports.cjs +2 -0
  5. package/dist/extractor/bundle.cjs +14 -4
  6. package/dist/extractor/bundleConfig.cjs +40 -27
  7. package/dist/extractor/concatClassName.cjs +40 -11
  8. package/dist/extractor/createExtractor.cjs +137 -30
  9. package/dist/extractor/extractHelpers.cjs +1 -1
  10. package/dist/extractor/extractMediaStyle.cjs +5 -5
  11. package/dist/extractor/extractToClassNames.cjs +52 -4
  12. package/dist/extractor/extractToNative.cjs +16 -8
  13. package/dist/extractor/getPrefixLogs.cjs +1 -1
  14. package/dist/extractor/getStaticBindingsForScope.cjs +2 -2
  15. package/dist/extractor/loadGui.cjs +52 -46
  16. package/dist/extractor/regenerateConfig.cjs +17 -17
  17. package/dist/extractor/watchGuiConfig.cjs +9 -9
  18. package/dist/getPragmaOptions.cjs +4 -4
  19. package/dist/registerRequire.cjs +17 -16
  20. package/package.json +22 -24
  21. package/src/check-dep-versions.ts +1 -1
  22. package/src/checkDeps.ts +25 -25
  23. package/src/constants.ts +2 -2
  24. package/src/exports.ts +1 -0
  25. package/src/extractor/bundle.ts +35 -6
  26. package/src/extractor/bundleConfig.ts +48 -28
  27. package/src/extractor/concatClassName.ts +37 -20
  28. package/src/extractor/createExtractor.ts +256 -36
  29. package/src/extractor/extractHelpers.ts +2 -2
  30. package/src/extractor/extractMediaStyle.ts +5 -5
  31. package/src/extractor/extractToClassNames.ts +109 -7
  32. package/src/extractor/extractToNative.ts +27 -10
  33. package/src/extractor/getPrefixLogs.ts +1 -1
  34. package/src/extractor/getStaticBindingsForScope.ts +2 -2
  35. package/src/extractor/loadGui.ts +66 -51
  36. package/src/extractor/regenerateConfig.ts +17 -17
  37. package/src/extractor/watchGuiConfig.ts +14 -9
  38. package/src/getPragmaOptions.ts +4 -4
  39. package/src/registerRequire.ts +32 -19
  40. package/types/constants.d.ts.map +1 -1
  41. package/types/exports.d.ts +1 -0
  42. package/types/exports.d.ts.map +1 -1
  43. package/types/extractor/bundle.d.ts.map +1 -1
  44. package/types/extractor/bundleConfig.d.ts +1 -1
  45. package/types/extractor/bundleConfig.d.ts.map +1 -1
  46. package/types/extractor/createExtractor.d.ts.map +1 -1
  47. package/types/extractor/extractMediaStyle.d.ts +1 -1
  48. package/types/extractor/extractMediaStyle.d.ts.map +1 -1
  49. package/types/extractor/extractToClassNames.d.ts.map +1 -1
  50. package/types/extractor/extractToNative.d.ts.map +1 -1
  51. package/types/extractor/loadGui.d.ts +5 -5
  52. package/types/extractor/loadGui.d.ts.map +1 -1
  53. package/types/extractor/regenerateConfig.d.ts +3 -3
  54. package/types/extractor/regenerateConfig.d.ts.map +1 -1
  55. package/types/extractor/watchGuiConfig.d.ts +1 -1
  56. package/types/extractor/watchGuiConfig.d.ts.map +1 -1
  57. package/types/registerRequire.d.ts +1 -1
  58. package/types/registerRequire.d.ts.map +1 -1
  59. package/LICENSE +0 -42
@@ -71,6 +71,33 @@ let hasLoggedBaseInfo = false;
71
71
  function isFullyDisabled(props) {
72
72
  return props.disableExtraction && props.disableDebugAttr;
73
73
  }
74
+ function hasUntilMeasuredAncestor(path, groupName) {
75
+ let current = path.parentPath;
76
+ while (current) {
77
+ if (current.isJSXElement()) {
78
+ const opening = current.node.openingElement;
79
+ let foundGroup = false;
80
+ let foundUntilMeasured = false;
81
+ for (const attr of opening.attributes) {
82
+ if (!t.isJSXAttribute(attr)) continue;
83
+ if (!t.isJSXIdentifier(attr.name)) continue;
84
+ const aName = attr.name.name;
85
+ if (aName === "group") {
86
+ if (t.isStringLiteral(attr.value) && attr.value.value === groupName) {
87
+ foundGroup = true;
88
+ } else if (t.isJSXExpressionContainer(attr.value) && t.isStringLiteral(attr.value.expression) && attr.value.expression.value === groupName) {
89
+ foundGroup = true;
90
+ }
91
+ } else if (aName === "untilMeasured") {
92
+ foundUntilMeasured = true;
93
+ }
94
+ }
95
+ if (foundGroup && foundUntilMeasured) return true;
96
+ }
97
+ current = current.parentPath;
98
+ }
99
+ return false;
100
+ }
74
101
  function createExtractor({
75
102
  logger = console,
76
103
  platform = "web"
@@ -205,7 +232,7 @@ function createExtractor({
205
232
  loadGui: load,
206
233
  loadGuiSync: loadSync,
207
234
  getGui() {
208
- return projectInfo?.guiConfig;
235
+ return projectInfo?.hanzoguiConfig;
209
236
  },
210
237
  parseSync: (f, props) => {
211
238
  globalThis.expo ||= {};
@@ -220,10 +247,10 @@ function createExtractor({
220
247
  };
221
248
  function parseWithConfig({
222
249
  components,
223
- guiConfig
250
+ hanzoguiConfig
224
251
  }, fileOrPath, options) {
225
252
  const {
226
- config = "gui.config.ts",
253
+ config = "hanzogui.config.ts",
227
254
  importsWhitelist = ["constants.js"],
228
255
  evaluateVars = true,
229
256
  sourcePath = "",
@@ -246,7 +273,7 @@ function createExtractor({
246
273
  dynamicComponentCache.delete(sourcePath);
247
274
  styledCheckCache.delete(sourcePath);
248
275
  }
249
- if (sourcePath.includes(".gui-dynamic-eval")) {
276
+ if (sourcePath.includes(".hanzogui-dynamic-eval")) {
250
277
  return null;
251
278
  }
252
279
  const {
@@ -291,7 +318,14 @@ function createExtractor({
291
318
  }
292
319
  return !!(staticConfig.validStyles?.[name] || pseudoDescriptors[name] ||
293
320
  // don't disable variants or else you lose many things flattening
294
- staticConfig.variants?.[name] || projectInfo?.guiConfig?.shorthands[name]);
321
+ staticConfig.variants?.[name] || projectInfo?.hanzoguiConfig?.shorthands[name]);
322
+ }
323
+ function getGroupPseudo(name) {
324
+ const [_, groupName, a, b, c] = name.split("-");
325
+ if (!groupName) return;
326
+ const m2 = a && b ? `${a}-${b}` : "";
327
+ const media = m2 && mediaQueryConfig[m2] && m2 || a && mediaQueryConfig[a] && a;
328
+ return media ? media === m2 ? c : b ? `${b}${c ? `-${c}` : ""}` : void 0 : a ? `${a}${b ? `-${b}` : ""}${c ? `-${c}` : ""}` : void 0;
295
329
  }
296
330
  const isTargetingHTML = platform2 === "web";
297
331
  const ogDebug = shouldPrintDebug;
@@ -306,14 +340,14 @@ function createExtractor({
306
340
  if (shouldPrintDebug) {
307
341
  logger.info(["loaded components:", propsWithFileInfo.allLoadedComponents.map(comp => Object.keys(comp.nameToInfo).join(", ")).join(", ")].join(" "));
308
342
  }
309
- if (process.env.DEBUG?.startsWith("gui")) {
343
+ if (process.env.DEBUG?.startsWith("hanzogui")) {
310
344
  logger.info(["loaded:", propsWithFileInfo.allLoadedComponents.map(x => x.moduleName)].join("\n"));
311
345
  }
312
346
  }
313
- tm.mark("load-gui", !!shouldPrintDebug);
347
+ tm.mark("load-hanzogui", !!shouldPrintDebug);
314
348
  if (!isFullyDisabled(options)) {
315
- if (!guiConfig?.themes) {
316
- console.error(`\u26D4\uFE0F Error: Missing "themes" in your gui.config file:
349
+ if (!hanzoguiConfig?.themes) {
350
+ console.error(`\u26D4\uFE0F Error: Missing "themes" in your hanzogui.config file:
317
351
 
318
352
  You may not need the compiler! Remember you can run Gui with no configuration at all.
319
353
 
@@ -323,15 +357,15 @@ function createExtractor({
323
357
  - try out https://github.com/bmish/check-dependency-version-consistency to see if there are mis-matches.
324
358
  - or search your lockfile for mis-matches.
325
359
  `);
326
- console.info(` Got config:`, guiConfig);
360
+ console.info(` Got config:`, hanzoguiConfig);
327
361
  process.exit(0);
328
362
  }
329
363
  }
330
- const firstThemeName = Object.keys(guiConfig?.themes || {})[0];
331
- const firstTheme = guiConfig?.themes[firstThemeName] || {};
364
+ const firstThemeName = Object.keys(hanzoguiConfig?.themes || {})[0];
365
+ const firstTheme = hanzoguiConfig?.themes[firstThemeName] || {};
332
366
  if (!firstTheme || typeof firstTheme !== "object") {
333
367
  const err = `Missing theme ${firstThemeName}, an error occurred when importing your config`;
334
- console.info(err, `Got config:`, guiConfig);
368
+ console.info(err, `Got config:`, hanzoguiConfig);
335
369
  console.info(`Looking for theme:`, firstThemeName);
336
370
  throw new Error(err);
337
371
  }
@@ -348,8 +382,8 @@ function createExtractor({
348
382
  const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
349
383
  if (!isFullyDisabled(options)) {
350
384
  if (Object.keys(components || []).length === 0) {
351
- console.warn(`Warning: Gui didn't find any valid components (DEBUG=gui for more)`);
352
- if (process.env.DEBUG === "gui") {
385
+ console.warn(`Warning: Gui didn't find any valid components (DEBUG=hanzogui for more)`);
386
+ if (process.env.DEBUG === "hanzogui") {
353
387
  console.info(`components`, Object.keys(components || []), components);
354
388
  }
355
389
  }
@@ -498,7 +532,7 @@ function createExtractor({
498
532
  }
499
533
  } catch (err) {
500
534
  if (shouldPrintDebug) {
501
- logger.info(`skip optimize styled(${variableName}), unable to pre-process (DEBUG=gui for more)`);
535
+ logger.info(`skip optimize styled(${variableName}), unable to pre-process (DEBUG=hanzogui for more)`);
502
536
  }
503
537
  }
504
538
  }
@@ -806,6 +840,10 @@ function createExtractor({
806
840
  }
807
841
  return [attribute.value, path.get("value")];
808
842
  })();
843
+ if (deoptProps.has(name) || platform2 === "native" && name[0] === "$" && (name.startsWith("$theme-") || name.startsWith("$group-") && getGroupPseudo(name) !== "hover")) {
844
+ inlined.set(name, true);
845
+ return attr;
846
+ }
809
847
  const remove = () => {
810
848
  Array.isArray(valuePath) ? valuePath.map(p => p.remove()) : valuePath.remove();
811
849
  };
@@ -843,7 +881,17 @@ function createExtractor({
843
881
  inlined.set("theme", attr.value);
844
882
  return attr;
845
883
  }
884
+ if (isTargetingHTML && name === "group" && t.isStringLiteral(value)) {
885
+ return [];
886
+ }
846
887
  const styleValue = attemptEvalSafe(value);
888
+ if (name[0] === "$" && (name.startsWith("$theme-") || name.startsWith("$group-")) && styleValue && typeof styleValue === "object" && Object.keys(styleValue).some(k => k[0] === "$")) {
889
+ if (shouldPrintDebug) {
890
+ logger.info(` ! nested media-like key inside ${name}, deopt to runtime`);
891
+ }
892
+ inlined.set(name, true);
893
+ return attr;
894
+ }
847
895
  if (!variants[name] && !isValidStyleKey(name, staticConfig)) {
848
896
  let out = null;
849
897
  propMapper(name, styleValue, propMapperStyleState, false, (key, val) => {
@@ -854,6 +902,7 @@ function createExtractor({
854
902
  if (isTargetingHTML) {
855
903
  out = reactNativeWebInternals.createDOMProps(isTextView ? "span" : "div", out);
856
904
  delete out.className;
905
+ delete out.style;
857
906
  }
858
907
  }
859
908
  let didInline = false;
@@ -873,6 +922,12 @@ function createExtractor({
873
922
  if (import_validHTMLAttributes.validHTMLAttributes[key] || key.startsWith("aria-") || key.startsWith("data-") ||
874
923
  // this is debug stuff added by vite / new jsx transform
875
924
  key === "__source" || key === "__self") {
925
+ if (styleValue === import_constants.FAILED_EVAL && key !== name && t.isJSXAttribute(attr.value)) {
926
+ return {
927
+ type: "attr",
928
+ value: t.jsxAttribute(t.jsxIdentifier(key), attr.value.value)
929
+ };
930
+ }
876
931
  return attr;
877
932
  }
878
933
  if (shouldPrintDebug) {
@@ -899,12 +954,15 @@ function createExtractor({
899
954
  }
900
955
  if (isValidStyleKey(name, staticConfig)) {
901
956
  if (name[0] === "$") {
902
- if (name.startsWith("$theme-") || name.startsWith("$group-")) {
903
- if (shouldPrintDebug) {
904
- logger.info(` ! not flattening media-like style: ${name}`);
957
+ if (name.startsWith("$group-")) {
958
+ const groupName = name.slice("$group-".length).split("-")[0];
959
+ if (groupName && hasUntilMeasuredAncestor(path, groupName)) {
960
+ if (shouldPrintDebug) {
961
+ logger.info(` ! group="${groupName}" ancestor has untilMeasured, not flattening: ${name}`);
962
+ }
963
+ inlined.set(name, true);
964
+ return attr;
905
965
  }
906
- inlined.set(name, true);
907
- return attr;
908
966
  }
909
967
  if (name.startsWith("$platform-")) {
910
968
  const platformName = name.slice(10);
@@ -1202,11 +1260,20 @@ function createExtractor({
1202
1260
  const inlineProps = /* @__PURE__ */new Set([
1203
1261
  // adding some always inline props
1204
1262
  ...(restProps.inlineProps || []), ...(staticConfig.inlineProps || [])]);
1263
+ const canFlattenTransition = isTargetingHTML && hanzoguiConfig?.animations.outputStyle === "css" && !hanzoguiConfig.animationDrivers;
1205
1264
  const deoptProps = /* @__PURE__ */new Set([
1206
- // always de-opt animation these
1207
- "animation", "animateOnly", "animatePresence", "disableOptimization", ...(!isTargetingHTML ? ["pressStyle", "focusStyle", "focusVisibleStyle", "focusWithinStyle", "disabledStyle"] : []),
1265
+ // css-only transitions lower to ordinary css; every runtime driver
1266
+ // needs the component preserved so it can respond to prop changes.
1267
+ "animation", ...(canFlattenTransition ? [] : ["transition"]), "animateOnly", "animatePresence", "disableOptimization", ...(!isTargetingHTML ? [
1268
+ // native has no css pseudo selectors; these are runtime-only on
1269
+ // rn (event listeners + style merge in createComponent), and if
1270
+ // we let them flatten into the stylesheet they get written
1271
+ // under a literal key that rn treats as an unknown style prop.
1272
+ // hover is intentionally excluded: it is no-op on native and
1273
+ // should be dropped rather than preserved as runtime work.
1274
+ "pressStyle", "focusStyle", "focusVisibleStyle", "focusWithinStyle", "disabledStyle"] : []),
1208
1275
  // when using a non-CSS driver, de-opt on enterStyle/exitStyle
1209
- ...(guiConfig?.animations.isReactNative ? ["enterStyle", "exitStyle"] : [])]);
1276
+ ...(hanzoguiConfig?.animations.isReactNative ? ["enterStyle", "exitStyle"] : [])]);
1210
1277
  const inlineWhenUnflattened = new Set(staticConfig.inlineWhenUnflattened || []);
1211
1278
  const staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
1212
1279
  const attemptEval = !evaluateVars ? import_evaluateAstNode.evaluateAstNode : (0, import_createEvaluator.createEvaluator)({
@@ -1237,7 +1304,7 @@ function createExtractor({
1237
1304
  style: {},
1238
1305
  theme: defaultTheme,
1239
1306
  viewProps: defaultProps,
1240
- conf: guiConfig,
1307
+ conf: hanzoguiConfig,
1241
1308
  props: defaultProps,
1242
1309
  componentState,
1243
1310
  styleProps: {
@@ -1344,7 +1411,7 @@ function createExtractor({
1344
1411
  if (!isValidStyleKey(key, staticConfig)) {
1345
1412
  return [];
1346
1413
  }
1347
- const name = guiConfig?.shorthands[key] || key;
1414
+ const name = hanzoguiConfig?.shorthands[key] || key;
1348
1415
  if (value === void 0) {
1349
1416
  logger.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${key} ${value}`);
1350
1417
  shouldDeopt = true;
@@ -1483,6 +1550,7 @@ function createExtractor({
1483
1550
  const cn = out.className;
1484
1551
  out = reactNativeWebInternals.createDOMProps(isTextView ? "span" : "div", out);
1485
1552
  out.className = cn;
1553
+ delete out.style;
1486
1554
  }
1487
1555
  if (shouldPrintDebug) {
1488
1556
  logger.info([" - expanded variant", name, out].join(" "));
@@ -1515,7 +1583,7 @@ function createExtractor({
1515
1583
  }
1516
1584
  let key = Object.keys(cur.value)[0];
1517
1585
  const value = cur.value[key];
1518
- const fullKey = guiConfig?.shorthands[key];
1586
+ const fullKey = hanzoguiConfig?.shorthands[key];
1519
1587
  if (fullKey) {
1520
1588
  cur.value = {
1521
1589
  [fullKey]: value
@@ -1558,7 +1626,25 @@ function createExtractor({
1558
1626
  const before = process.env.IS_STATIC;
1559
1627
  process.env.IS_STATIC = "is_static";
1560
1628
  try {
1561
- const out = getSplitStyles(props, staticConfig, defaultTheme, "", componentState, {
1629
+ let extractedMediaLikeProps = null;
1630
+ let propsForSplit = props;
1631
+ for (const k in props) {
1632
+ if (k[0] === "$" && (k.startsWith("$group-") || k.startsWith("$theme-"))) {
1633
+ if (propsForSplit === props) {
1634
+ propsForSplit = {
1635
+ ...props
1636
+ };
1637
+ }
1638
+ if (platform2 === "native" && k.startsWith("$group-") && getGroupPseudo(k) === "hover") {
1639
+ delete propsForSplit[k];
1640
+ continue;
1641
+ }
1642
+ extractedMediaLikeProps ||= {};
1643
+ extractedMediaLikeProps[k] = propsForSplit[k];
1644
+ delete propsForSplit[k];
1645
+ }
1646
+ }
1647
+ const out = getSplitStyles(propsForSplit, staticConfig, defaultTheme, "", componentState, {
1562
1648
  ...styleProps,
1563
1649
  noClass: true,
1564
1650
  fallbackProps: completeProps,
@@ -1566,15 +1652,36 @@ function createExtractor({
1566
1652
  resolveValues: "except-theme"
1567
1653
  })
1568
1654
  }, void 0, void 0, void 0, void 0, false, debugPropValue || shouldPrintDebug);
1655
+ if (extractedMediaLikeProps && platform2 !== "native") {
1656
+ for (const k in extractedMediaLikeProps) {
1657
+ const block = extractedMediaLikeProps[k];
1658
+ if (!block || typeof block !== "object") continue;
1659
+ const blockOut = getSplitStyles(block, staticConfig, defaultTheme, "", componentState, {
1660
+ ...styleProps,
1661
+ noClass: true,
1662
+ fallbackProps: completeProps
1663
+ }, void 0, void 0, void 0, void 0, false, debugPropValue || shouldPrintDebug);
1664
+ if (blockOut) {
1665
+ extractedMediaLikeProps[k] = {
1666
+ ...blockOut.style,
1667
+ ...blockOut.pseudos
1668
+ };
1669
+ }
1670
+ }
1671
+ }
1569
1672
  let outProps = {
1570
1673
  ...(includeProps ? out.viewProps : {}),
1571
1674
  ...out.style,
1572
- ...out.pseudos
1675
+ ...out.pseudos,
1676
+ ...extractedMediaLikeProps
1573
1677
  };
1574
1678
  for (const key in outProps) {
1575
1679
  if (deoptProps.has(key)) {
1576
1680
  shouldFlatten = false;
1577
1681
  }
1682
+ if (platform2 === "native" && key[0] === "$" && (key.startsWith("$theme-") || key.startsWith("$group-") && getGroupPseudo(key) !== "hover")) {
1683
+ shouldFlatten = false;
1684
+ }
1578
1685
  }
1579
1686
  if (shouldPrintDebug) {
1580
1687
  logger.info(`(${debugName})`);
@@ -1783,7 +1890,7 @@ function createExtractor({
1783
1890
  node,
1784
1891
  lineNumbers,
1785
1892
  filePath,
1786
- config: guiConfig,
1893
+ config: hanzoguiConfig,
1787
1894
  flatNodeName,
1788
1895
  attemptEval,
1789
1896
  jsxPath: traversePath,
@@ -171,7 +171,7 @@ const isValidImport = (props, moduleName, componentName) => {
171
171
  return Boolean(getValidImport(props, moduleName, componentName));
172
172
  };
173
173
  const getValidComponentPackages = (0, import_memoize.memoize)(props => {
174
- return [... /* @__PURE__ */new Set(["@hanzogui/core", "gui", ...(props.components || [])])];
174
+ return [... /* @__PURE__ */new Set(["@hanzogui/core", "hanzogui", ...(props.components || [])])];
175
175
  });
176
176
  const getValidComponentsPaths = (0, import_memoize.memoize)(props => {
177
177
  return getValidComponentPackages(props).flatMap(pkg => {
@@ -41,7 +41,7 @@ var t = __toESM(require("@babel/types"));
41
41
  var core = __toESM(require("@hanzogui/core"));
42
42
  var import_requireGuiCore = require("../helpers/requireGuiCore.cjs");
43
43
  var import_extractHelpers = require("./extractHelpers.cjs");
44
- function extractMediaStyle(props, ternary, jsxPath, guiConfig, sourcePath, importance = 0, shouldPrintDebug = false) {
44
+ function extractMediaStyle(props, ternary, jsxPath, hanzoguiConfig, sourcePath, importance = 0, shouldPrintDebug = false) {
45
45
  const {
46
46
  getCSSStylesAtomic
47
47
  } = (0, import_requireGuiCore.requireGuiCore)("web");
@@ -52,9 +52,9 @@ function extractMediaStyle(props, ternary, jsxPath, guiConfig, sourcePath, impor
52
52
  const {
53
53
  key
54
54
  } = mt;
55
- const mq = guiConfig.media[key];
55
+ const mq = hanzoguiConfig.media[key];
56
56
  if (!mq) {
57
- console.error(`Media query "${key}" not found: ${Object.keys(guiConfig.media)}`);
57
+ console.error(`Media query "${key}" not found: ${Object.keys(hanzoguiConfig.media)}`);
58
58
  return null;
59
59
  }
60
60
  const getStyleObj = (styleObj, negate = false) => {
@@ -68,7 +68,7 @@ function extractMediaStyle(props, ternary, jsxPath, guiConfig, sourcePath, impor
68
68
  console.info(" media query, no styles?");
69
69
  return null;
70
70
  }
71
- const mediaKeys = Object.keys(guiConfig.media);
71
+ const mediaKeys = Object.keys(hanzoguiConfig.media);
72
72
  const mediaKeyPrecendence = mediaKeys.reduce((acc, cur, i) => {
73
73
  acc[cur] = new Array(importance + 1).fill(":root").join("");
74
74
  return acc;
@@ -80,7 +80,7 @@ function extractMediaStyle(props, ternary, jsxPath, guiConfig, sourcePath, impor
80
80
  } of styleOpts) {
81
81
  const styles = getCSSStylesAtomic(styleObj);
82
82
  const singleMediaStyles = styles.map(style => {
83
- const mediaStyle = core.createMediaStyle(style, key, guiConfig.media, true, negate);
83
+ const mediaStyle = core.createMediaStyle(style, key, hanzoguiConfig.media, true, negate);
84
84
  const className = `.${mediaStyle[core.StyleObjectIdentifier]}`;
85
85
  return {
86
86
  ...mediaStyle,
@@ -94,7 +94,7 @@ async function extractToClassNames({
94
94
  }
95
95
  tm.mark(`babel-parse`, shouldPrintDebug === "verbose");
96
96
  const cssMap = /* @__PURE__ */new Map();
97
- const guiConfig = extractor.getGui();
97
+ const hanzoguiConfig = extractor.getGui();
98
98
  const res = await extractor.parse(ast, {
99
99
  shouldPrintDebug,
100
100
  ...options,
@@ -136,6 +136,41 @@ async function extractToClassNames({
136
136
  let baseFontFamily = "";
137
137
  let mediaStylesSeen = 1;
138
138
  const comment = util.format("/* %s:%s (%s) */", filePath, lineNumbers, originalNodeName);
139
+ let staticGroupName = null;
140
+ for (const attr of jsxPath.node.openingElement.attributes) {
141
+ if (!t.isJSXAttribute(attr) || !t.isJSXIdentifier(attr.name)) continue;
142
+ if (attr.name.name !== "group") continue;
143
+ if (t.isStringLiteral(attr.value)) {
144
+ staticGroupName = attr.value.value;
145
+ } else if (t.isJSXExpressionContainer(attr.value) && t.isStringLiteral(attr.value.expression)) {
146
+ staticGroupName = attr.value.expression.value;
147
+ }
148
+ break;
149
+ }
150
+ if (staticGroupName) {
151
+ const containerIdentifier = `t_group_${staticGroupName}`;
152
+ const containerType = hanzoguiConfig.settings?.webContainerType || "inline-size";
153
+ const containerSelector = `.${containerIdentifier}`;
154
+ if (!cssMap.has(containerSelector)) {
155
+ cssMap.set(containerSelector, {
156
+ css: `${containerSelector} { container-name: ${staticGroupName}; container-type: ${containerType}; }`,
157
+ commentTexts: [comment]
158
+ });
159
+ } else {
160
+ cssMap.get(containerSelector).commentTexts.push(comment);
161
+ }
162
+ }
163
+ const hasCSSOnlyAnimationDriver = hanzoguiConfig.animations.outputStyle === "css" && !hanzoguiConfig.animationDrivers;
164
+ let elementIsAnimated = false;
165
+ for (const attr of jsxPath.node.openingElement.attributes) {
166
+ if (!t.isJSXAttribute(attr) || !t.isJSXIdentifier(attr.name)) continue;
167
+ const n = attr.name.name;
168
+ if (n === "transition" && hasCSSOnlyAnimationDriver) continue;
169
+ if (n === "animation" || n === "transition" || n === "animateOnly" || n === "animatePresence" || n === "animatedBy" || n === "enterStyle" || n === "exitStyle") {
170
+ elementIsAnimated = true;
171
+ break;
172
+ }
173
+ }
139
174
  function addStyle(style) {
140
175
  const identifier = style[import_web.StyleObjectIdentifier];
141
176
  const rules = style[import_web.StyleObjectRules];
@@ -158,17 +193,27 @@ async function extractToClassNames({
158
193
  const property = style2[0];
159
194
  const mediaName = property.slice(1);
160
195
  if (mediaName.startsWith("group-")) {
161
- throw new import_errors.BailOptimizationError();
196
+ if (elementIsAnimated) {
197
+ throw new import_errors.BailOptimizationError();
198
+ }
199
+ const mediaStyle = createMediaStyle(style2, mediaName, extractor.getGui().media, "group", false, mediaStylesSeen);
200
+ const identifier2 = addStyle(mediaStyle);
201
+ classNames.push(identifier2);
202
+ continue;
162
203
  }
163
204
  const mediaTypeMatch = mediaName.match(/^(theme|platform)-/);
164
205
  if (mediaTypeMatch) {
165
206
  const mediaType = mediaTypeMatch[1];
166
- const mediaStyle = createMediaStyle(style2, mediaName, extractor.getGui().media, mediaType, false, mediaStylesSeen);
207
+ if (mediaType === "theme" && elementIsAnimated) {
208
+ throw new import_errors.BailOptimizationError();
209
+ }
210
+ const innerKey = mediaType === "theme" ? mediaName.slice("theme-".length) : mediaName;
211
+ const mediaStyle = createMediaStyle(style2, innerKey, extractor.getGui().media, mediaType, false, mediaStylesSeen);
167
212
  const identifier2 = addStyle(mediaStyle);
168
213
  classNames.push(identifier2);
169
214
  continue;
170
215
  }
171
- if (mediaName in guiConfig.media) {
216
+ if (mediaName in hanzoguiConfig.media) {
172
217
  const mediaStyle = createMediaStyle(style2, mediaName, extractor.getGui().media, true, false, mediaStylesSeen);
173
218
  const identifier2 = addStyle(mediaStyle);
174
219
  classNames.push(identifier2);
@@ -249,6 +294,9 @@ async function extractToClassNames({
249
294
  if (baseFontFamily) {
250
295
  baseClassNameStr = `font_${baseFontFamily}${baseClassNameStr ? ` ${baseClassNameStr}` : ""}`;
251
296
  }
297
+ if (staticGroupName) {
298
+ baseClassNameStr = `t_group_${staticGroupName}${baseClassNameStr ? ` ${baseClassNameStr}` : ""}`;
299
+ }
252
300
  const baseTypeClass = staticConfig.isText ? "is_Text" : "is_View";
253
301
  baseClassNameStr = `${baseTypeClass}${baseClassNameStr ? ` ${baseClassNameStr}` : ""}`;
254
302
  const componentNameFinal = staticConfig.componentName;
@@ -62,7 +62,7 @@ const importWithStyle = import_template.default.ast(`import { _withStableStyle }
62
62
  const extractor = (0, import_createExtractor.createExtractor)({
63
63
  platform: "native"
64
64
  });
65
- let guiBuildOptionsLoaded;
65
+ let hanzoguiBuildOptionsLoaded;
66
66
  function extractToNative(sourceFileName, sourceCode, options) {
67
67
  const ast = (0, import_parser.parse)(sourceCode, {
68
68
  sourceType: "module",
@@ -88,7 +88,7 @@ function getBabelPlugin() {
88
88
  }
89
89
  function getBabelParseDefinition(options) {
90
90
  return {
91
- name: "gui",
91
+ name: "hanzogui",
92
92
  visitor: {
93
93
  Program: {
94
94
  enter(root) {
@@ -122,12 +122,12 @@ function getBabelParseDefinition(options) {
122
122
  return;
123
123
  }
124
124
  if (!options.config && !options.components) {
125
- guiBuildOptionsLoaded ||= (0, import_loadGui.loadGuiBuildConfigSync)({});
125
+ hanzoguiBuildOptionsLoaded ||= (0, import_loadGui.loadGuiBuildConfigSync)({});
126
126
  }
127
127
  const finalOptions = {
128
128
  // @ts-ignore just in case they leave it out
129
129
  platform: "native",
130
- ...guiBuildOptionsLoaded,
130
+ ...hanzoguiBuildOptionsLoaded,
131
131
  ...options
132
132
  };
133
133
  const printLog = (0, import_createLogger.createLogger)(sourcePath, finalOptions);
@@ -178,6 +178,7 @@ function getBabelParseDefinition(options) {
178
178
  const stylesExpr = t.arrayExpression([]);
179
179
  const hocStylesExpr = t.arrayExpression([]);
180
180
  const expressions = [];
181
+ const mediaExpressionIndexes = /* @__PURE__ */new Set();
181
182
  const finalAttrs = [];
182
183
  const themeKeysUsed = /* @__PURE__ */new Set();
183
184
  function getStyleExpression(style, forTernary = false) {
@@ -253,7 +254,14 @@ function getBabelParseDefinition(options) {
253
254
  if (attr.value.inlineMediaQuery) {
254
255
  hasMediaKeys = true;
255
256
  }
256
- expressions.push(attr.value.test);
257
+ let expression = attr.value.test;
258
+ if (attr.value.inlineMediaQuery && t.isLogicalExpression(attr.value.test, {
259
+ operator: "&&"
260
+ }) && t.isStringLiteral(attr.value.test.left)) {
261
+ expression = t.arrayExpression([t.stringLiteral(attr.value.inlineMediaQuery), t.unaryExpression("!", t.unaryExpression("!", attr.value.test.right))]);
262
+ mediaExpressionIndexes.add(expressions.length);
263
+ }
264
+ expressions.push(expression);
257
265
  addStyleExpression(t.conditionalExpression(t.identifier(`_expressions[${expressions.length - 1}]`), consExpr || t.nullLiteral(), altExpr || t.nullLiteral()), true);
258
266
  const styleExpr = t.conditionalExpression(attr.value.test, consExpr || t.nullLiteral(), altExpr || t.nullLiteral());
259
267
  addStyleExpression(styleExpr);
@@ -273,7 +281,7 @@ function getBabelParseDefinition(options) {
273
281
  }
274
282
  }
275
283
  props.node.attributes = finalAttrs;
276
- if (themeKeysUsed.size || hocStylesExpr.elements.length > 1 || hasDynamicStyle) {
284
+ if (themeKeysUsed.size || hocStylesExpr.elements.length > 1 || hasDynamicStyle || hasMediaKeys) {
277
285
  if (!hasImportedViewWrapper) {
278
286
  root.unshiftContainer("body", importWithStyle);
279
287
  hasImportedViewWrapper = true;
@@ -292,7 +300,7 @@ function getBabelParseDefinition(options) {
292
300
  props.jsxPath.node.closingElement.name = t.jsxIdentifier(wrapperName);
293
301
  }
294
302
  if (expressions.length) {
295
- const safeExpressions = expressions.map(expr => t.isStringLiteral(expr) ? expr : t.unaryExpression("!", t.unaryExpression("!", expr)));
303
+ const safeExpressions = expressions.map((expr, index) => t.isStringLiteral(expr) || mediaExpressionIndexes.has(index) ? expr : t.unaryExpression("!", t.unaryExpression("!", expr)));
296
304
  props.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("_expressions"), t.jsxExpressionContainer(t.arrayExpression(safeExpressions))));
297
305
  }
298
306
  } else {
@@ -336,7 +344,7 @@ function getBabelParseDefinition(options) {
336
344
  }
337
345
  function assertValidTag(node) {
338
346
  if (node.attributes.find(x => x.type === "JSXAttribute" && x.name.name === "style")) {
339
- if (process.env.DEBUG?.startsWith("gui")) {
347
+ if (process.env.DEBUG?.startsWith("hanzogui")) {
340
348
  console.warn("\u26A0\uFE0F Cannot pass style attribute to extracted style");
341
349
  }
342
350
  }
@@ -27,5 +27,5 @@ __export(getPrefixLogs_exports, {
27
27
  module.exports = __toCommonJS(getPrefixLogs_exports);
28
28
  var import_cli_color = require("@hanzogui/cli-color");
29
29
  function getPrefixLogs(options) {
30
- return options?.prefixLogs ?? ` \u{1F425} [gui] ${(0, import_cli_color.colorString)(import_cli_color.Color.FgYellow, options?.platform || "web")}`;
30
+ return options?.prefixLogs ?? ` \u{1F425} [hanzogui] ${(0, import_cli_color.colorString)(import_cli_color.Color.FgYellow, options?.platform || "web")}`;
31
31
  }
@@ -141,8 +141,8 @@ async function getStaticBindingsForScope(scope, whitelist = [], sourcePath, bind
141
141
  }
142
142
  } catch (err) {
143
143
  if (shouldPrintDebug) {
144
- console.warn(` | Skipping partial evaluation of constant file: ${moduleName} (DEBUG=gui for more)`);
145
- } else if (process.env.DEBUG?.startsWith("gui")) {
144
+ console.warn(` | Skipping partial evaluation of constant file: ${moduleName} (DEBUG=hanzogui for more)`);
145
+ } else if (process.env.DEBUG?.startsWith("hanzogui")) {
146
146
  console.info(`Error in partial evaluation`, err.message, err.stack);
147
147
  }
148
148
  }