@tamagui/static 2.0.0-rc.8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/dist/check-dep-versions.cjs +201 -96
  2. package/dist/checkDeps.cjs +250 -46
  3. package/dist/constants.cjs +32 -30
  4. package/dist/exports.cjs +20 -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 +187 -101
  9. package/dist/extractor/bundleConfig.cjs +568 -168
  10. package/dist/extractor/concatClassName.cjs +73 -32
  11. package/dist/extractor/createEvaluator.cjs +54 -41
  12. package/dist/extractor/createExtractor.cjs +1405 -574
  13. package/dist/extractor/createLogger.cjs +30 -25
  14. package/dist/extractor/detectModuleFormat.cjs +55 -0
  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 +60 -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 +337 -229
  23. package/dist/extractor/extractToNative.cjs +248 -154
  24. package/dist/extractor/findTopmostFunction.cjs +22 -13
  25. package/dist/extractor/generatedUid.cjs +39 -28
  26. package/dist/extractor/getPrefixLogs.cjs +12 -10
  27. package/dist/extractor/getPropValueFromAttributes.cjs +52 -34
  28. package/dist/extractor/getSourceModule.cjs +73 -37
  29. package/dist/extractor/getStaticBindingsForScope.cjs +131 -68
  30. package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.cjs +20 -14
  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/loadTamagui.cjs +151 -105
  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/watchTamaguiConfig.cjs +35 -23
  44. package/dist/getPragmaOptions.cjs +34 -19
  45. package/dist/helpers/memoize.cjs +24 -16
  46. package/dist/helpers/requireTamaguiCore.cjs +22 -15
  47. package/dist/index.cjs +26 -24
  48. package/dist/registerRequire.cjs +168 -65
  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 +27 -24
  53. package/src/checkDeps.ts +305 -68
  54. package/src/exports.ts +2 -0
  55. package/src/extractor/babelParse.ts +1 -0
  56. package/src/extractor/bundle.ts +172 -40
  57. package/src/extractor/bundleConfig.ts +459 -65
  58. package/src/extractor/concatClassName.ts +37 -20
  59. package/src/extractor/createExtractor.ts +300 -30
  60. package/src/extractor/detectModuleFormat.ts +42 -0
  61. package/src/extractor/esbuildTsconfigPaths.ts +6 -1
  62. package/src/extractor/extractToClassNames.ts +15 -9
  63. package/src/extractor/extractToNative.ts +66 -33
  64. package/src/extractor/hasTopLevelAwait.ts +28 -0
  65. package/src/extractor/loadTamagui.ts +5 -4
  66. package/src/registerRequire.ts +102 -9
  67. package/types/checkDeps.d.ts.map +1 -1
  68. package/types/exports.d.ts +2 -0
  69. package/types/exports.d.ts.map +1 -1
  70. package/types/extractor/babelParse.d.ts.map +1 -1
  71. package/types/extractor/bundle.d.ts +83 -1
  72. package/types/extractor/bundle.d.ts.map +1 -1
  73. package/types/extractor/bundleConfig.d.ts +15 -2
  74. package/types/extractor/bundleConfig.d.ts.map +1 -1
  75. package/types/extractor/createExtractor.d.ts.map +1 -1
  76. package/types/extractor/detectModuleFormat.d.ts +5 -0
  77. package/types/extractor/detectModuleFormat.d.ts.map +1 -0
  78. package/types/extractor/esbuildTsconfigPaths.d.ts +8 -0
  79. package/types/extractor/esbuildTsconfigPaths.d.ts.map +1 -1
  80. package/types/extractor/extractToClassNames.d.ts.map +1 -1
  81. package/types/extractor/extractToNative.d.ts.map +1 -1
  82. package/types/extractor/hasTopLevelAwait.d.ts +2 -0
  83. package/types/extractor/hasTopLevelAwait.d.ts.map +1 -0
  84. package/types/extractor/loadTamagui.d.ts +1 -1
  85. package/types/extractor/loadTamagui.d.ts.map +1 -1
  86. package/types/registerRequire.d.ts.map +1 -1
  87. package/dist/check-dep-versions.js +0 -389
  88. package/dist/check-dep-versions.js.map +0 -6
  89. package/dist/checkDeps.js +0 -60
  90. package/dist/checkDeps.js.map +0 -6
  91. package/dist/constants.js +0 -34
  92. package/dist/constants.js.map +0 -6
  93. package/dist/exports.js +0 -34
  94. package/dist/exports.js.map +0 -6
  95. package/dist/extractor/accessSafe.js +0 -47
  96. package/dist/extractor/accessSafe.js.map +0 -6
  97. package/dist/extractor/babelParse.js +0 -59
  98. package/dist/extractor/babelParse.js.map +0 -6
  99. package/dist/extractor/buildClassName.js +0 -72
  100. package/dist/extractor/buildClassName.js.map +0 -6
  101. package/dist/extractor/bundle.js +0 -135
  102. package/dist/extractor/bundle.js.map +0 -6
  103. package/dist/extractor/bundleConfig.js +0 -352
  104. package/dist/extractor/bundleConfig.js.map +0 -6
  105. package/dist/extractor/concatClassName.js +0 -69
  106. package/dist/extractor/concatClassName.js.map +0 -6
  107. package/dist/extractor/createEvaluator.js +0 -66
  108. package/dist/extractor/createEvaluator.js.map +0 -6
  109. package/dist/extractor/createExtractor.js +0 -1212
  110. package/dist/extractor/createExtractor.js.map +0 -6
  111. package/dist/extractor/createLogger.js +0 -32
  112. package/dist/extractor/createLogger.js.map +0 -6
  113. package/dist/extractor/ensureImportingConcat.js +0 -50
  114. package/dist/extractor/ensureImportingConcat.js.map +0 -6
  115. package/dist/extractor/errors.js +0 -22
  116. package/dist/extractor/errors.js.map +0 -6
  117. package/dist/extractor/esbuildAliasPlugin.js +0 -36
  118. package/dist/extractor/esbuildAliasPlugin.js.map +0 -6
  119. package/dist/extractor/esbuildTsconfigPaths.js +0 -79
  120. package/dist/extractor/esbuildTsconfigPaths.js.map +0 -6
  121. package/dist/extractor/evaluateAstNode.js +0 -99
  122. package/dist/extractor/evaluateAstNode.js.map +0 -6
  123. package/dist/extractor/extractHelpers.js +0 -108
  124. package/dist/extractor/extractHelpers.js.map +0 -6
  125. package/dist/extractor/extractMediaStyle.js +0 -123
  126. package/dist/extractor/extractMediaStyle.js.map +0 -6
  127. package/dist/extractor/extractToClassNames.js +0 -351
  128. package/dist/extractor/extractToClassNames.js.map +0 -6
  129. package/dist/extractor/extractToNative.js +0 -286
  130. package/dist/extractor/extractToNative.js.map +0 -6
  131. package/dist/extractor/findTopmostFunction.js +0 -32
  132. package/dist/extractor/findTopmostFunction.js.map +0 -6
  133. package/dist/extractor/generatedUid.js +0 -42
  134. package/dist/extractor/generatedUid.js.map +0 -6
  135. package/dist/extractor/getPrefixLogs.js +0 -24
  136. package/dist/extractor/getPrefixLogs.js.map +0 -6
  137. package/dist/extractor/getPropValueFromAttributes.js +0 -65
  138. package/dist/extractor/getPropValueFromAttributes.js.map +0 -6
  139. package/dist/extractor/getSourceModule.js +0 -62
  140. package/dist/extractor/getSourceModule.js.map +0 -6
  141. package/dist/extractor/getStaticBindingsForScope.js +0 -145
  142. package/dist/extractor/getStaticBindingsForScope.js.map +0 -6
  143. package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.js +0 -32
  144. package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.js.map +0 -6
  145. package/dist/extractor/hoistClassNames.js +0 -63
  146. package/dist/extractor/hoistClassNames.js.map +0 -6
  147. package/dist/extractor/literalToAst.js +0 -90
  148. package/dist/extractor/literalToAst.js.map +0 -6
  149. package/dist/extractor/loadFile.js +0 -14
  150. package/dist/extractor/loadFile.js.map +0 -6
  151. package/dist/extractor/loadTamagui.js +0 -306
  152. package/dist/extractor/loadTamagui.js.map +0 -6
  153. package/dist/extractor/logLines.js +0 -30
  154. package/dist/extractor/logLines.js.map +0 -6
  155. package/dist/extractor/normalizeTernaries.js +0 -61
  156. package/dist/extractor/normalizeTernaries.js.map +0 -6
  157. package/dist/extractor/propsToFontFamilyCache.js +0 -33
  158. package/dist/extractor/propsToFontFamilyCache.js.map +0 -6
  159. package/dist/extractor/regenerateConfig.js +0 -123
  160. package/dist/extractor/regenerateConfig.js.map +0 -6
  161. package/dist/extractor/removeUnusedHooks.js +0 -72
  162. package/dist/extractor/removeUnusedHooks.js.map +0 -6
  163. package/dist/extractor/timer.js +0 -38
  164. package/dist/extractor/timer.js.map +0 -6
  165. package/dist/extractor/validHTMLAttributes.js +0 -72
  166. package/dist/extractor/validHTMLAttributes.js.map +0 -6
  167. package/dist/extractor/watchTamaguiConfig.js +0 -57
  168. package/dist/extractor/watchTamaguiConfig.js.map +0 -6
  169. package/dist/getPragmaOptions.js +0 -50
  170. package/dist/getPragmaOptions.js.map +0 -6
  171. package/dist/helpers/memoize.js +0 -33
  172. package/dist/helpers/memoize.js.map +0 -6
  173. package/dist/helpers/requireTamaguiCore.js +0 -30
  174. package/dist/helpers/requireTamaguiCore.js.map +0 -6
  175. package/dist/index.js +0 -30
  176. package/dist/index.js.map +0 -6
  177. package/dist/registerRequire.js +0 -100
  178. package/dist/registerRequire.js.map +0 -6
  179. package/dist/server.js +0 -58
  180. package/dist/server.js.map +0 -6
  181. package/dist/setup.js +0 -1
  182. package/dist/setup.js.map +0 -6
  183. package/dist/types.js +0 -14
  184. package/dist/types.js.map +0 -6
  185. package/dist/worker.js +0 -72
  186. package/dist/worker.js.map +0 -6
@@ -2,54 +2,56 @@ 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 extractToClassNames_exports = {};
33
35
  __export(extractToClassNames_exports, {
34
36
  extractToClassNames: () => extractToClassNames
35
37
  });
36
38
  module.exports = __toCommonJS(extractToClassNames_exports);
37
- var import_generator = __toESM(require("@babel/generator")),
38
- t = __toESM(require("@babel/types")),
39
- import_web = require("@tamagui/web"),
40
- path = __toESM(require("node:path")),
41
- util = __toESM(require("node:util")),
42
- import_requireTamaguiCore = require("../helpers/requireTamaguiCore.cjs"),
43
- import_babelParse = require("./babelParse.cjs"),
44
- import_createLogger = require("./createLogger.cjs"),
45
- import_extractMediaStyle = require("./extractMediaStyle.cjs"),
46
- import_normalizeTernaries = require("./normalizeTernaries.cjs"),
47
- import_propsToFontFamilyCache = require("./propsToFontFamilyCache.cjs"),
48
- import_timer = require("./timer.cjs"),
49
- import_errors = require("./errors.cjs"),
50
- import_concatClassName = require("./concatClassName.cjs");
51
- const remove = () => {},
52
- spaceString = t.stringLiteral(" ");
39
+ var import_generator = __toESM(require("@babel/generator"));
40
+ var t = __toESM(require("@babel/types"));
41
+ var import_web = require("@tamagui/web");
42
+ var path = __toESM(require("node:path"));
43
+ var util = __toESM(require("node:util"));
44
+ var import_requireTamaguiCore = require("../helpers/requireTamaguiCore.cjs");
45
+ var import_babelParse = require("./babelParse.cjs");
46
+ var import_createLogger = require("./createLogger.cjs");
47
+ var import_extractMediaStyle = require("./extractMediaStyle.cjs");
48
+ var import_normalizeTernaries = require("./normalizeTernaries.cjs");
49
+ var import_propsToFontFamilyCache = require("./propsToFontFamilyCache.cjs");
50
+ var import_timer = require("./timer.cjs");
51
+ var import_errors = require("./errors.cjs");
52
+ var import_concatClassName = require("./concatClassName.cjs");
53
+ const remove = () => {};
54
+ const spaceString = t.stringLiteral(" ");
53
55
  async function extractToClassNames({
54
56
  extractor,
55
57
  source,
@@ -57,158 +59,238 @@ async function extractToClassNames({
57
59
  options,
58
60
  shouldPrintDebug
59
61
  }) {
60
- const tm = (0, import_timer.timer)(),
61
- {
62
- getCSSStylesAtomic,
63
- createMediaStyle
64
- } = (0, import_requireTamaguiCore.requireTamaguiCore)("web");
65
- if (sourcePath.includes("node_modules")) return null;
66
- if (shouldPrintDebug && console.warn(`--- ${sourcePath} ---
62
+ const tm = (0, import_timer.timer)();
63
+ const {
64
+ getCSSStylesAtomic,
65
+ createMediaStyle
66
+ } = (0, import_requireTamaguiCore.requireTamaguiCore)("web");
67
+ if (sourcePath.includes("node_modules")) {
68
+ return null;
69
+ }
70
+ if (shouldPrintDebug) {
71
+ console.warn(`--- ${sourcePath} ---
67
72
 
68
- `), typeof source != "string") throw new Error("`source` must be a string of javascript");
69
- if (!path.isAbsolute(sourcePath)) throw new Error("`sourcePath` must be an absolute path to a .js file, got: " + sourcePath);
70
- /.[tj]sx?$/i.test(sourcePath || "") || console.warn(`${sourcePath.slice(0, 100)} - bad filename.`), !options.disableExtraction && !options._disableLoadTamagui && (await extractor.loadTamagui(options));
73
+ `);
74
+ }
75
+ if (typeof source !== "string") {
76
+ throw new Error("`source` must be a string of javascript");
77
+ }
78
+ if (!path.isAbsolute(sourcePath)) {
79
+ throw new Error("`sourcePath` must be an absolute path to a .js file, got: " + sourcePath);
80
+ }
81
+ if (!/.[tj]sx?$/i.test(sourcePath || "")) {
82
+ console.warn(`${sourcePath.slice(0, 100)} - bad filename.`);
83
+ }
84
+ if (!options.disableExtraction && !options["_disableLoadTamagui"]) {
85
+ await extractor.loadTamagui(options);
86
+ }
71
87
  const printLog = (0, import_createLogger.createLogger)(sourcePath, options);
72
88
  let ast;
73
89
  try {
74
90
  ast = (0, import_babelParse.babelParse)(source, sourcePath);
75
91
  } catch (err) {
76
- throw console.error("babel parse error:", sourcePath.slice(0, 100)), err;
92
+ console.error("babel parse error:", sourcePath.slice(0, 100));
93
+ throw err;
77
94
  }
78
- tm.mark("babel-parse", shouldPrintDebug === "verbose");
79
- const cssMap = /* @__PURE__ */new Map(),
80
- tamaguiConfig = extractor.getTamagui(),
81
- res = await extractor.parse(ast, {
82
- shouldPrintDebug,
83
- ...options,
84
- platform: "web",
85
- sourcePath,
86
- extractStyledDefinitions: !0,
87
- onStyledDefinitionRule(identifier, rules) {
88
- const css = rules.join(";");
89
- shouldPrintDebug && console.info(`adding styled() rule: .${identifier} ${css}`), cssMap.set(`.${identifier}`, {
90
- css,
91
- commentTexts: []
92
- });
93
- },
94
- getFlattenedNode: ({
95
- tag
96
- }) => tag,
97
- onExtractTag: ({
98
- parserProps,
99
- attrs,
100
- node,
101
- attemptEval,
102
- jsxPath,
103
- originalNodeName,
104
- filePath,
105
- lineNumbers,
106
- staticConfig
107
- }) => {
108
- if (staticConfig.acceptsClassName === !1) throw new import_errors.BailOptimizationError();
109
- const finalAttrs = [];
110
- let mergeForwardBaseStyle = null,
111
- attrClassName = null,
112
- baseFontFamily = "",
113
- mediaStylesSeen = 1;
114
- const comment = util.format("/* %s:%s (%s) */", filePath, lineNumbers, originalNodeName);
115
- function addStyle(style) {
116
- const identifier = style[import_web.StyleObjectIdentifier],
117
- rules = style[import_web.StyleObjectRules],
118
- selector = `.${identifier}`;
119
- return cssMap.has(selector) ? cssMap.get(selector).commentTexts.push(comment) : rules.length && cssMap.set(selector, {
120
- css: rules.join(`
121
- `),
95
+ tm.mark(`babel-parse`, shouldPrintDebug === "verbose");
96
+ const cssMap = /* @__PURE__ */new Map();
97
+ const tamaguiConfig = extractor.getTamagui();
98
+ const res = await extractor.parse(ast, {
99
+ shouldPrintDebug,
100
+ ...options,
101
+ platform: "web",
102
+ sourcePath,
103
+ extractStyledDefinitions: true,
104
+ onStyledDefinitionRule(identifier, rules) {
105
+ const css = rules.join("\n");
106
+ if (shouldPrintDebug) {
107
+ console.info(`adding styled() rule: .${identifier} ${css}`);
108
+ }
109
+ cssMap.set(`.${identifier}`, {
110
+ css,
111
+ commentTexts: []
112
+ });
113
+ },
114
+ getFlattenedNode: ({
115
+ tag
116
+ }) => {
117
+ return tag;
118
+ },
119
+ onExtractTag: ({
120
+ parserProps,
121
+ attrs,
122
+ node,
123
+ attemptEval,
124
+ jsxPath,
125
+ originalNodeName,
126
+ filePath,
127
+ lineNumbers,
128
+ staticConfig
129
+ }) => {
130
+ if (staticConfig.acceptsClassName === false) {
131
+ throw new import_errors.BailOptimizationError();
132
+ }
133
+ const finalAttrs = [];
134
+ let mergeForwardBaseStyle = null;
135
+ let attrClassName = null;
136
+ let baseFontFamily = "";
137
+ let mediaStylesSeen = 1;
138
+ const comment = util.format("/* %s:%s (%s) */", filePath, lineNumbers, originalNodeName);
139
+ function addStyle(style) {
140
+ const identifier = style[import_web.StyleObjectIdentifier];
141
+ const rules = style[import_web.StyleObjectRules];
142
+ const selector = `.${identifier}`;
143
+ if (cssMap.has(selector)) {
144
+ const val = cssMap.get(selector);
145
+ val.commentTexts.push(comment);
146
+ } else if (rules.length) {
147
+ cssMap.set(selector, {
148
+ css: rules.join("\n"),
122
149
  commentTexts: [comment]
123
- }), identifier;
150
+ });
124
151
  }
125
- function addStyles(style) {
126
- const cssStyles = getCSSStylesAtomic(style),
127
- classNames = [];
128
- for (const style2 of cssStyles) {
129
- const mediaName = style2[0].slice(1);
130
- if (mediaName.startsWith("group-")) throw new import_errors.BailOptimizationError();
131
- const mediaTypeMatch = mediaName.match(/^(theme|platform)-/);
132
- if (mediaTypeMatch) {
133
- const mediaType = mediaTypeMatch[1],
134
- mediaStyle = createMediaStyle(style2, mediaName, extractor.getTamagui().media, mediaType, !1, mediaStylesSeen),
135
- identifier2 = addStyle(mediaStyle);
136
- classNames.push(identifier2);
137
- continue;
138
- }
139
- if (mediaName in tamaguiConfig.media) {
140
- const mediaStyle = createMediaStyle(style2, mediaName, extractor.getTamagui().media, !0, !1, mediaStylesSeen),
141
- identifier2 = addStyle(mediaStyle);
142
- classNames.push(identifier2);
143
- continue;
144
- }
145
- const identifier = addStyle(style2);
146
- classNames.push(identifier);
152
+ return identifier;
153
+ }
154
+ function addStyles(style) {
155
+ const cssStyles = getCSSStylesAtomic(style);
156
+ const classNames = [];
157
+ for (const style2 of cssStyles) {
158
+ const property = style2[0];
159
+ const mediaName = property.slice(1);
160
+ if (mediaName.startsWith("group-")) {
161
+ throw new import_errors.BailOptimizationError();
162
+ }
163
+ const mediaTypeMatch = mediaName.match(/^(theme|platform)-/);
164
+ if (mediaTypeMatch) {
165
+ const mediaType = mediaTypeMatch[1];
166
+ const mediaStyle = createMediaStyle(style2, mediaName, extractor.getTamagui().media, mediaType, false, mediaStylesSeen);
167
+ const identifier2 = addStyle(mediaStyle);
168
+ classNames.push(identifier2);
169
+ continue;
147
170
  }
148
- return classNames;
171
+ if (mediaName in tamaguiConfig.media) {
172
+ const mediaStyle = createMediaStyle(style2, mediaName, extractor.getTamagui().media, true, false, mediaStylesSeen);
173
+ const identifier2 = addStyle(mediaStyle);
174
+ classNames.push(identifier2);
175
+ continue;
176
+ }
177
+ const identifier = addStyle(style2);
178
+ classNames.push(identifier);
149
179
  }
150
- const onlyTernaries = attrs.flatMap(attr => {
151
- if (attr.type === "attr") {
152
- const value = attr.value;
153
- if (t.isJSXSpreadAttribute(value)) return console.error("Should never happen"), [];
154
- if (value.name.name === "className") {
155
- let inner = value.value;
156
- t.isJSXExpressionContainer(inner) && (inner = inner.expression);
157
- try {
158
- const evaluatedValue = inner ? attemptEval(inner) : null;
159
- typeof evaluatedValue == "string" && (attrClassName = t.stringLiteral(evaluatedValue));
160
- } catch {
161
- inner && (attrClassName ||= inner);
162
- }
163
- return [];
180
+ return classNames;
181
+ }
182
+ const onlyTernaries = attrs.flatMap(attr => {
183
+ if (attr.type === "attr") {
184
+ const value = attr.value;
185
+ if (t.isJSXSpreadAttribute(value)) {
186
+ console.error(`Should never happen`);
187
+ return [];
188
+ }
189
+ if (value.name.name === "className") {
190
+ let inner = value.value;
191
+ if (t.isJSXExpressionContainer(inner)) {
192
+ inner = inner.expression;
193
+ }
194
+ try {
195
+ const evaluatedValue = inner ? attemptEval(inner) : null;
196
+ if (typeof evaluatedValue === "string") {
197
+ attrClassName = t.stringLiteral(evaluatedValue);
198
+ }
199
+ } catch (e) {
200
+ if (inner) {
201
+ attrClassName ||= inner;
164
202
  }
165
- return finalAttrs.push(value), [];
166
203
  }
167
- if (attr.type === "style") return mergeForwardBaseStyle = (0, import_web.mergeProps)(mergeForwardBaseStyle || {}, attr.value), baseFontFamily = (0, import_propsToFontFamilyCache.getFontFamilyNameFromProps)(attr.value) || "", [];
168
- let ternary = attr.value;
169
- if (ternary.inlineMediaQuery) {
170
- const mediaExtraction = (0, import_extractMediaStyle.extractMediaStyle)(parserProps, attr.value, jsxPath, extractor.getTamagui(), sourcePath || "", mediaStylesSeen++, shouldPrintDebug);
171
- if (mediaExtraction) if (mediaExtraction.mediaStyles && (mergeForwardBaseStyle = (0, import_web.mergeProps)(mergeForwardBaseStyle || {}, {
204
+ return [];
205
+ }
206
+ finalAttrs.push(value);
207
+ return [];
208
+ }
209
+ if (attr.type === "style") {
210
+ mergeForwardBaseStyle = (0, import_web.mergeProps)(mergeForwardBaseStyle || {}, attr.value);
211
+ baseFontFamily = (0, import_propsToFontFamilyCache.getFontFamilyNameFromProps)(attr.value) || "";
212
+ return [];
213
+ }
214
+ let ternary = attr.value;
215
+ if (ternary.inlineMediaQuery) {
216
+ const mediaExtraction = (0, import_extractMediaStyle.extractMediaStyle)(parserProps, attr.value, jsxPath, extractor.getTamagui(), sourcePath || "", mediaStylesSeen++, shouldPrintDebug);
217
+ if (mediaExtraction) {
218
+ if (mediaExtraction.mediaStyles) {
219
+ mergeForwardBaseStyle = (0, import_web.mergeProps)(mergeForwardBaseStyle || {}, {
172
220
  [`$${ternary.inlineMediaQuery}`]: attr.value.consequent
173
- })), mediaExtraction.ternaryWithoutMedia) ternary = mediaExtraction.ternaryWithoutMedia;else return [];
221
+ });
174
222
  }
175
- let mergedAlternate, mergedConsequent;
176
- return ternary.alternate && Object.keys(ternary.alternate).length && (mergedAlternate = (0, import_web.mergeProps)(mergeForwardBaseStyle || {}, ternary.alternate || {}), (0, import_propsToFontFamilyCache.forwardFontFamilyName)(ternary.alternate, mergedAlternate, baseFontFamily)), ternary.consequent && Object.keys(ternary.consequent).length && (mergedConsequent = (0, import_web.mergeProps)(mergeForwardBaseStyle || {}, ternary.consequent || {}), (0, import_propsToFontFamilyCache.forwardFontFamilyName)(ternary.consequent, mergedConsequent, baseFontFamily)), {
177
- ...ternary,
178
- alternate: mergedAlternate,
179
- consequent: mergedConsequent
180
- };
181
- }),
182
- hasTernaries = !!onlyTernaries.length,
183
- baseClassNames = mergeForwardBaseStyle ? addStyles(mergeForwardBaseStyle) : null;
184
- let baseClassNameStr = baseClassNames ? baseClassNames.join(" ") : "";
185
- baseFontFamily && (baseClassNameStr = `font_${baseFontFamily}${baseClassNameStr ? ` ${baseClassNameStr}` : ""}`);
186
- let base = staticConfig.componentName ? t.stringLiteral(`is_${staticConfig.componentName}${baseClassNameStr ? ` ${baseClassNameStr}` : ""}`) : t.stringLiteral(baseClassNameStr || "");
187
- attrClassName = attrClassName;
188
- const baseClassNameExpression = attrClassName ? t.isStringLiteral(attrClassName) ? t.stringLiteral(base.value ? `${base.value} ${attrClassName.value}` : attrClassName.value) : t.binaryExpression("+", t.binaryExpression("+", attrClassName, spaceString), base) : base,
189
- expandedTernaries = [];
190
- if (onlyTernaries.length) {
191
- const normalizedTernaries = (0, import_normalizeTernaries.normalizeTernaries)(onlyTernaries);
192
- for (const ternary of normalizedTernaries) {
193
- if (!expandedTernaries.length) {
194
- expandTernary(ternary);
195
- continue;
223
+ if (mediaExtraction.ternaryWithoutMedia) {
224
+ ternary = mediaExtraction.ternaryWithoutMedia;
225
+ } else {
226
+ return [];
196
227
  }
197
- const prevTernaries = [...expandedTernaries];
198
- for (const prev of prevTernaries) expandTernary(ternary, prev);
199
228
  }
200
229
  }
201
- function expandTernary(ternary, prev) {
202
- if (ternary.consequent && Object.keys(ternary.consequent).length) {
203
- const fontFamily = (0, import_propsToFontFamilyCache.getFontFamilyNameFromProps)(ternary.consequent);
230
+ let mergedAlternate;
231
+ let mergedConsequent;
232
+ if (ternary.alternate && Object.keys(ternary.alternate).length) {
233
+ mergedAlternate = (0, import_web.mergeProps)(mergeForwardBaseStyle || {}, ternary.alternate || {});
234
+ (0, import_propsToFontFamilyCache.forwardFontFamilyName)(ternary.alternate, mergedAlternate, baseFontFamily);
235
+ }
236
+ if (ternary.consequent && Object.keys(ternary.consequent).length) {
237
+ mergedConsequent = (0, import_web.mergeProps)(mergeForwardBaseStyle || {}, ternary.consequent || {});
238
+ (0, import_propsToFontFamilyCache.forwardFontFamilyName)(ternary.consequent, mergedConsequent, baseFontFamily);
239
+ }
240
+ return {
241
+ ...ternary,
242
+ alternate: mergedAlternate,
243
+ consequent: mergedConsequent
244
+ };
245
+ });
246
+ const hasTernaries = Boolean(onlyTernaries.length);
247
+ const baseClassNames = mergeForwardBaseStyle ? addStyles(mergeForwardBaseStyle) : null;
248
+ let baseClassNameStr = !baseClassNames ? "" : baseClassNames.join(" ");
249
+ if (baseFontFamily) {
250
+ baseClassNameStr = `font_${baseFontFamily}${baseClassNameStr ? ` ${baseClassNameStr}` : ""}`;
251
+ }
252
+ const baseTypeClass = staticConfig.isText ? "is_Text" : "is_View";
253
+ baseClassNameStr = `${baseTypeClass}${baseClassNameStr ? ` ${baseClassNameStr}` : ""}`;
254
+ const componentNameFinal = staticConfig.componentName;
255
+ let base = componentNameFinal && componentNameFinal !== "Text" ? t.stringLiteral(`is_${componentNameFinal}${baseClassNameStr ? ` ${baseClassNameStr}` : ""}`) : t.stringLiteral(baseClassNameStr || "");
256
+ attrClassName = attrClassName;
257
+ const baseClassNameExpression = (() => {
258
+ if (attrClassName) {
259
+ if (t.isStringLiteral(attrClassName)) {
260
+ return t.stringLiteral(base.value ? `${base.value} ${attrClassName.value}` : attrClassName.value);
261
+ } else {
262
+ return t.binaryExpression("+", t.binaryExpression("+", attrClassName, spaceString), base);
263
+ }
264
+ }
265
+ return base;
266
+ })();
267
+ const expandedTernaries = [];
268
+ if (onlyTernaries.length) {
269
+ const normalizedTernaries = (0, import_normalizeTernaries.normalizeTernaries)(onlyTernaries);
270
+ for (const ternary of normalizedTernaries) {
271
+ if (!expandedTernaries.length) {
272
+ expandTernary(ternary);
273
+ continue;
274
+ }
275
+ const prevTernaries = [...expandedTernaries];
276
+ for (const prev of prevTernaries) {
277
+ expandTernary(ternary, prev);
278
+ }
279
+ }
280
+ }
281
+ function expandTernary(ternary, prev) {
282
+ if (ternary.consequent && Object.keys(ternary.consequent).length) {
283
+ const fontFamily = (0, import_propsToFontFamilyCache.getFontFamilyNameFromProps)(ternary.consequent);
284
+ expandedTernaries.push({
285
+ fontFamily,
286
+ // prevTest && test: merge consequent
287
+ test: prev ? t.logicalExpression("&&", prev.test, ternary.test) : ternary.test,
288
+ consequent: prev ? (0, import_web.mergeProps)(prev.consequent, ternary.consequent) : ternary.consequent,
289
+ remove,
290
+ alternate: null
291
+ });
292
+ if (prev) {
204
293
  expandedTernaries.push({
205
- fontFamily,
206
- // prevTest && test: merge consequent
207
- test: prev ? t.logicalExpression("&&", prev.test, ternary.test) : ternary.test,
208
- consequent: prev ? (0, import_web.mergeProps)(prev.consequent, ternary.consequent) : ternary.consequent,
209
- remove,
210
- alternate: null
211
- }), prev && expandedTernaries.push({
212
294
  fontFamily,
213
295
  // !prevTest && test: just consequent
214
296
  test: t.logicalExpression("&&", t.unaryExpression("!", prev.test), ternary.test),
@@ -217,17 +299,20 @@ async function extractToClassNames({
217
299
  remove
218
300
  });
219
301
  }
220
- if (ternary.alternate && Object.keys(ternary.alternate).length) {
221
- const fontFamily = (0, import_propsToFontFamilyCache.getFontFamilyNameFromProps)(ternary.alternate),
222
- negated = t.unaryExpression("!", ternary.test);
302
+ }
303
+ if (ternary.alternate && Object.keys(ternary.alternate).length) {
304
+ const fontFamily = (0, import_propsToFontFamilyCache.getFontFamilyNameFromProps)(ternary.alternate);
305
+ const negated = t.unaryExpression("!", ternary.test);
306
+ expandedTernaries.push({
307
+ fontFamily,
308
+ // prevTest && !test: merge alternate
309
+ test: prev ? t.logicalExpression("&&", prev.test, negated) : negated,
310
+ consequent: prev ? (0, import_web.mergeProps)(prev.alternate, ternary.alternate) : ternary.alternate,
311
+ remove,
312
+ alternate: null
313
+ });
314
+ if (prev) {
223
315
  expandedTernaries.push({
224
- fontFamily,
225
- // prevTest && !test: merge alternate
226
- test: prev ? t.logicalExpression("&&", prev.test, negated) : negated,
227
- consequent: prev ? (0, import_web.mergeProps)(prev.alternate, ternary.alternate) : ternary.alternate,
228
- remove,
229
- alternate: null
230
- }), prev && expandedTernaries.push({
231
316
  fontFamily,
232
317
  test: t.logicalExpression("&&", t.unaryExpression("!", prev.test), ternary.test),
233
318
  consequent: ternary.alternate,
@@ -236,49 +321,65 @@ async function extractToClassNames({
236
321
  });
237
322
  }
238
323
  }
239
- let ternaryClassNameExpr = null;
240
- if (hasTernaries) for (const ternary of expandedTernaries) {
324
+ }
325
+ let ternaryClassNameExpr = null;
326
+ if (hasTernaries) {
327
+ for (const ternary of expandedTernaries) {
241
328
  if (!ternary.consequent) continue;
242
329
  const classNames = addStyles(ternary.consequent);
243
- ternary.fontFamily && classNames.unshift(`font_${ternary.fontFamily}`);
244
- const baseString = t.isStringLiteral(baseClassNameExpression) ? baseClassNameExpression.value : "",
245
- fullClassNameWithDups = (baseString ? `${baseString} ` : "") + classNames.join(" "),
246
- fullClassName = (0, import_concatClassName.concatClassName)(fullClassNameWithDups),
247
- classNameLiteral = t.stringLiteral(fullClassName);
248
- ternaryClassNameExpr ? ternaryClassNameExpr = t.conditionalExpression(ternary.test, classNameLiteral, ternaryClassNameExpr) : ternaryClassNameExpr = t.conditionalExpression(ternary.test, classNameLiteral, baseClassNameExpression);
330
+ if (ternary.fontFamily) {
331
+ classNames.unshift(`font_${ternary.fontFamily}`);
332
+ }
333
+ const baseString = t.isStringLiteral(baseClassNameExpression) ? baseClassNameExpression.value : "";
334
+ const fullClassNameWithDups = (baseString ? `${baseString} ` : "") + classNames.join(" ");
335
+ const fullClassName = (0, import_concatClassName.concatClassName)(fullClassNameWithDups);
336
+ const classNameLiteral = t.stringLiteral(fullClassName);
337
+ if (!ternaryClassNameExpr) {
338
+ ternaryClassNameExpr = t.conditionalExpression(ternary.test, classNameLiteral, baseClassNameExpression);
339
+ } else {
340
+ ternaryClassNameExpr = t.conditionalExpression(ternary.test, classNameLiteral, ternaryClassNameExpr);
341
+ }
249
342
  }
250
- let finalExpression = ternaryClassNameExpr || baseClassNameExpression || null;
251
- if (shouldPrintDebug && (console.info("attrs", JSON.stringify(attrs, null, 2)), console.info("expandedTernaries", JSON.stringify(expandedTernaries, null, 2)), console.info("finalExpression", JSON.stringify(finalExpression, null, 2)), console.info({
343
+ }
344
+ let finalExpression = ternaryClassNameExpr || baseClassNameExpression || null;
345
+ if (shouldPrintDebug) {
346
+ console.info("attrs", JSON.stringify(attrs, null, 2));
347
+ console.info("expandedTernaries", JSON.stringify(expandedTernaries, null, 2));
348
+ console.info("finalExpression", JSON.stringify(finalExpression, null, 2));
349
+ console.info({
252
350
  hasTernaries,
253
351
  baseClassNameExpression
254
- })), finalExpression) {
255
- finalExpression = hoistClassNames(jsxPath, finalExpression);
256
- const classNameProp = t.jsxAttribute(t.jsxIdentifier("className"), t.jsxExpressionContainer(finalExpression));
257
- finalAttrs.unshift(classNameProp);
258
- }
259
- node.attributes = finalAttrs;
352
+ });
260
353
  }
261
- });
262
- if (!res || !res.modified && !res.optimized && !res.flattened && !res.styled) return shouldPrintDebug && console.info("no res or none modified", res), null;
263
- const styles = Array.from(cssMap.values()).map(x => x.css).join(`
264
- `).trim(),
265
- result = (0, import_generator.default)(ast, {
266
- concise: !1,
267
- filename: sourcePath,
268
- // this makes the debug output terrible, and i think sourcemap works already
269
- retainLines: !1,
270
- sourceFileName: sourcePath,
271
- sourceMaps: !0
272
- }, source);
273
- return shouldPrintDebug && (console.info(`
274
- -------- output code -------
275
-
276
- `, result.code.split(`
277
- `).filter(x => !x.startsWith("//")).join(`
278
- `)), console.info(`
279
- -------- output style --------
280
-
281
- `, styles)), printLog(res), {
354
+ if (finalExpression) {
355
+ finalExpression = hoistClassNames(jsxPath, finalExpression);
356
+ const classNameProp = t.jsxAttribute(t.jsxIdentifier("className"), t.jsxExpressionContainer(finalExpression));
357
+ finalAttrs.unshift(classNameProp);
358
+ }
359
+ node.attributes = finalAttrs;
360
+ }
361
+ });
362
+ if (!res || !res.modified && !res.optimized && !res.flattened && !res.styled) {
363
+ if (shouldPrintDebug) {
364
+ console.info("no res or none modified", res);
365
+ }
366
+ return null;
367
+ }
368
+ const styles = Array.from(cssMap.values()).map(x => x.css).join("\n").trim();
369
+ const result = (0, import_generator.default)(ast, {
370
+ concise: false,
371
+ filename: sourcePath,
372
+ // this makes the debug output terrible, and i think sourcemap works already
373
+ retainLines: false,
374
+ sourceFileName: sourcePath,
375
+ sourceMaps: true
376
+ }, source);
377
+ if (shouldPrintDebug) {
378
+ console.info("\n -------- output code ------- \n\n", result.code.split("\n").filter(x => !x.startsWith("//")).join("\n"));
379
+ console.info("\n -------- output style -------- \n\n", styles);
380
+ }
381
+ printLog(res);
382
+ return {
282
383
  ast,
283
384
  styles,
284
385
  js: result.code,
@@ -292,28 +393,35 @@ async function extractToClassNames({
292
393
  };
293
394
  }
294
395
  function hoistClassNames(path2, expr) {
295
- if (t.isStringLiteral(expr)) return hoistClassName(path2, expr.value);
396
+ if (t.isStringLiteral(expr)) {
397
+ return hoistClassName(path2, expr.value);
398
+ }
296
399
  if (t.isLogicalExpression(expr)) {
297
- const left = t.isStringLiteral(expr.left) ? hoistClassName(path2, expr.left.value) : expr.left,
298
- right = t.isStringLiteral(expr.right) ? hoistClassName(path2, expr.right.value) : hoistClassNames(path2, expr.right);
400
+ const left = t.isStringLiteral(expr.left) ? hoistClassName(path2, expr.left.value) : expr.left;
401
+ const right = t.isStringLiteral(expr.right) ? hoistClassName(path2, expr.right.value) : hoistClassNames(path2, expr.right);
299
402
  return t.logicalExpression(expr.operator, left, right);
300
403
  }
301
404
  if (t.isConditionalExpression(expr)) {
302
- const cons = t.isStringLiteral(expr.consequent) ? hoistClassName(path2, expr.consequent.value) : hoistClassNames(path2, expr.consequent),
303
- alt = t.isStringLiteral(expr.alternate) ? hoistClassName(path2, expr.alternate.value) : hoistClassNames(path2, expr.alternate);
405
+ const cons = t.isStringLiteral(expr.consequent) ? hoistClassName(path2, expr.consequent.value) : hoistClassNames(path2, expr.consequent);
406
+ const alt = t.isStringLiteral(expr.alternate) ? hoistClassName(path2, expr.alternate.value) : hoistClassNames(path2, expr.alternate);
304
407
  return t.conditionalExpression(expr.test, cons, alt);
305
408
  }
306
409
  return expr;
307
410
  }
308
411
  function hoistClassName(path2, str) {
309
- const uid = path2.scope.generateUidIdentifier("cn"),
310
- parent = path2.findParent(path3 => path3.isProgram());
311
- if (!parent) throw new Error("no program?");
412
+ const uid = path2.scope.generateUidIdentifier("cn");
413
+ const parent = path2.findParent(path3 => path3.isProgram());
414
+ if (!parent) throw new Error(`no program?`);
312
415
  const variable = t.variableDeclaration("const", [t.variableDeclarator(uid, t.stringLiteral(cleanupClassName(str)))]);
313
- return parent.unshiftContainer("body", variable), uid;
416
+ parent.unshiftContainer("body", variable);
417
+ return uid;
314
418
  }
315
419
  function cleanupClassName(inStr) {
316
420
  const out = /* @__PURE__ */new Set();
317
- for (const part of inStr.split(" ")) part !== " " && part !== "font_" && out.add(part);
318
- return [...out].join(" ") + " ";
421
+ for (const part of inStr.split(" ")) {
422
+ if (!part || part === " ") continue;
423
+ if (part === "font_") continue;
424
+ out.add(part);
425
+ }
426
+ return [...out].join(" ");
319
427
  }