@hanzogui/static 8.3.0 → 8.3.2

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 (377) hide show
  1. package/dist/cjs/check-dep-versions.js +438 -0
  2. package/dist/cjs/check-dep-versions.js.map +1 -0
  3. package/dist/cjs/checkDeps.js +343 -0
  4. package/dist/cjs/checkDeps.js.map +1 -0
  5. package/dist/cjs/constants.js +13 -0
  6. package/dist/cjs/constants.js.map +1 -0
  7. package/dist/cjs/exports.js +27 -0
  8. package/dist/cjs/exports.js.map +1 -0
  9. package/dist/cjs/extractor/accessSafe.js +17 -0
  10. package/dist/cjs/extractor/accessSafe.js.map +1 -0
  11. package/dist/cjs/extractor/babelParse.js +27 -0
  12. package/dist/cjs/extractor/babelParse.js.map +1 -0
  13. package/dist/cjs/extractor/buildClassName.js +65 -0
  14. package/dist/cjs/extractor/buildClassName.js.map +1 -0
  15. package/dist/cjs/extractor/bundle.js +257 -0
  16. package/dist/cjs/extractor/bundle.js.map +1 -0
  17. package/dist/cjs/extractor/bundleConfig.js +794 -0
  18. package/dist/cjs/extractor/bundleConfig.js.map +1 -0
  19. package/dist/cjs/extractor/concatClassName.js +101 -0
  20. package/dist/cjs/extractor/concatClassName.js.map +1 -0
  21. package/dist/cjs/extractor/createEvaluator.js +56 -0
  22. package/dist/cjs/extractor/createEvaluator.js.map +1 -0
  23. package/dist/cjs/extractor/createExtractor.js +2285 -0
  24. package/dist/cjs/extractor/createExtractor.js.map +1 -0
  25. package/dist/cjs/extractor/createLogger.js +34 -0
  26. package/dist/cjs/extractor/createLogger.js.map +1 -0
  27. package/dist/cjs/extractor/detectModuleFormat.js +41 -0
  28. package/dist/cjs/extractor/detectModuleFormat.js.map +1 -0
  29. package/dist/cjs/extractor/ensureImportingConcat.js +23 -0
  30. package/dist/cjs/extractor/ensureImportingConcat.js.map +1 -0
  31. package/dist/cjs/extractor/errors.js +7 -0
  32. package/dist/cjs/extractor/errors.js.map +1 -0
  33. package/dist/cjs/extractor/esbuildAliasPlugin.js +43 -0
  34. package/dist/cjs/extractor/esbuildAliasPlugin.js.map +1 -0
  35. package/dist/cjs/extractor/esbuildTsconfigPaths.js +68 -0
  36. package/dist/cjs/extractor/esbuildTsconfigPaths.js.map +1 -0
  37. package/dist/cjs/extractor/evaluateAstNode.js +107 -0
  38. package/dist/cjs/extractor/evaluateAstNode.js.map +1 -0
  39. package/dist/cjs/extractor/extractHelpers.js +183 -0
  40. package/dist/cjs/extractor/extractHelpers.js.map +1 -0
  41. package/dist/cjs/extractor/extractMediaStyle.js +143 -0
  42. package/dist/cjs/extractor/extractMediaStyle.js.map +1 -0
  43. package/dist/cjs/extractor/extractToClassNames.js +541 -0
  44. package/dist/cjs/extractor/extractToClassNames.js.map +1 -0
  45. package/dist/cjs/extractor/extractToNative.js +404 -0
  46. package/dist/cjs/extractor/extractToNative.js.map +1 -0
  47. package/dist/cjs/extractor/extractablePath.js +89 -0
  48. package/dist/cjs/extractor/extractablePath.js.map +1 -0
  49. package/dist/cjs/extractor/findTopmostFunction.js +17 -0
  50. package/dist/cjs/extractor/findTopmostFunction.js.map +1 -0
  51. package/dist/cjs/extractor/generatedUid.js +35 -0
  52. package/dist/cjs/extractor/generatedUid.js.map +1 -0
  53. package/dist/cjs/extractor/getGuiConfigPathFromOptionsConfig.js +21 -0
  54. package/dist/cjs/extractor/getGuiConfigPathFromOptionsConfig.js.map +1 -0
  55. package/dist/cjs/extractor/getPrefixLogs.js +9 -0
  56. package/dist/cjs/extractor/getPrefixLogs.js.map +1 -0
  57. package/dist/cjs/extractor/getPropValueFromAttributes.js +75 -0
  58. package/dist/cjs/extractor/getPropValueFromAttributes.js.map +1 -0
  59. package/dist/cjs/extractor/getSourceModule.js +81 -0
  60. package/dist/cjs/extractor/getSourceModule.js.map +1 -0
  61. package/dist/cjs/extractor/getStaticBindingsForScope.js +212 -0
  62. package/dist/cjs/extractor/getStaticBindingsForScope.js.map +1 -0
  63. package/dist/cjs/extractor/hasTopLevelAwait.js +29 -0
  64. package/dist/cjs/extractor/hasTopLevelAwait.js.map +1 -0
  65. package/dist/cjs/extractor/hoistClassNames.js +47 -0
  66. package/dist/cjs/extractor/hoistClassNames.js.map +1 -0
  67. package/dist/cjs/extractor/literalToAst.js +83 -0
  68. package/dist/cjs/extractor/literalToAst.js.map +1 -0
  69. package/dist/cjs/extractor/loadFile.js +24 -0
  70. package/dist/cjs/extractor/loadFile.js.map +1 -0
  71. package/dist/cjs/extractor/loadGui.js +414 -0
  72. package/dist/cjs/extractor/loadGui.js.map +1 -0
  73. package/dist/cjs/extractor/logLines.js +20 -0
  74. package/dist/cjs/extractor/logLines.js.map +1 -0
  75. package/dist/cjs/extractor/normalizeTernaries.js +60 -0
  76. package/dist/cjs/extractor/normalizeTernaries.js.map +1 -0
  77. package/dist/cjs/extractor/propsToFontFamilyCache.js +20 -0
  78. package/dist/cjs/extractor/propsToFontFamilyCache.js.map +1 -0
  79. package/dist/cjs/extractor/regenerateConfig.js +151 -0
  80. package/dist/cjs/extractor/regenerateConfig.js.map +1 -0
  81. package/dist/cjs/extractor/removeUnusedHooks.js +84 -0
  82. package/dist/cjs/extractor/removeUnusedHooks.js.map +1 -0
  83. package/dist/cjs/extractor/timer.js +30 -0
  84. package/dist/cjs/extractor/timer.js.map +1 -0
  85. package/dist/cjs/extractor/validHTMLAttributes.js +56 -0
  86. package/dist/cjs/extractor/validHTMLAttributes.js.map +1 -0
  87. package/dist/cjs/extractor/watchGuiConfig.js +56 -0
  88. package/dist/cjs/extractor/watchGuiConfig.js.map +1 -0
  89. package/dist/cjs/getPragmaOptions.js +52 -0
  90. package/dist/cjs/getPragmaOptions.js.map +1 -0
  91. package/dist/cjs/helpers/memoize.js +24 -0
  92. package/dist/cjs/helpers/memoize.js.map +1 -0
  93. package/dist/cjs/helpers/nativeEntry.js +87 -0
  94. package/dist/cjs/helpers/nativeEntry.js.map +1 -0
  95. package/dist/cjs/helpers/requireGuiCore.js +25 -0
  96. package/dist/cjs/helpers/requireGuiCore.js.map +1 -0
  97. package/dist/cjs/here.js +8 -0
  98. package/dist/cjs/here.js.map +1 -0
  99. package/dist/cjs/index.js +8 -0
  100. package/dist/cjs/index.js.map +1 -0
  101. package/dist/cjs/package.json +1 -0
  102. package/dist/cjs/registerRequire.js +263 -0
  103. package/dist/cjs/registerRequire.js.map +1 -0
  104. package/dist/cjs/server.js +41 -0
  105. package/dist/cjs/server.js.map +1 -0
  106. package/dist/cjs/setup.js +2 -0
  107. package/dist/cjs/setup.js.map +1 -0
  108. package/dist/cjs/types.js +3 -0
  109. package/dist/cjs/types.js.map +1 -0
  110. package/dist/cjs/worker.js +95 -0
  111. package/dist/cjs/worker.js.map +1 -0
  112. package/dist/esm/check-dep-versions.js +433 -0
  113. package/dist/esm/check-dep-versions.js.map +1 -0
  114. package/dist/esm/checkDeps.js +339 -0
  115. package/dist/esm/checkDeps.js.map +1 -0
  116. package/dist/esm/constants.js +9 -0
  117. package/dist/esm/constants.js.map +1 -0
  118. package/dist/esm/exports.js +18 -0
  119. package/dist/esm/exports.js.map +1 -0
  120. package/dist/esm/extractor/accessSafe.js +13 -0
  121. package/dist/esm/extractor/accessSafe.js.map +1 -0
  122. package/dist/esm/extractor/babelParse.js +22 -0
  123. package/dist/esm/extractor/babelParse.js.map +1 -0
  124. package/dist/esm/extractor/buildClassName.js +59 -0
  125. package/dist/esm/extractor/buildClassName.js.map +1 -0
  126. package/dist/esm/extractor/bundle.js +252 -0
  127. package/dist/esm/extractor/bundle.js.map +1 -0
  128. package/dist/esm/extractor/bundleConfig.js +781 -0
  129. package/dist/esm/extractor/bundleConfig.js.map +1 -0
  130. package/dist/esm/extractor/concatClassName.js +98 -0
  131. package/dist/esm/extractor/concatClassName.js.map +1 -0
  132. package/dist/esm/extractor/createEvaluator.js +51 -0
  133. package/dist/esm/extractor/createEvaluator.js.map +1 -0
  134. package/dist/esm/extractor/createExtractor.js +2281 -0
  135. package/dist/esm/extractor/createExtractor.js.map +1 -0
  136. package/dist/esm/extractor/createLogger.js +31 -0
  137. package/dist/esm/extractor/createLogger.js.map +1 -0
  138. package/dist/esm/extractor/detectModuleFormat.js +37 -0
  139. package/dist/esm/extractor/detectModuleFormat.js.map +1 -0
  140. package/dist/esm/extractor/ensureImportingConcat.js +19 -0
  141. package/dist/esm/extractor/ensureImportingConcat.js.map +1 -0
  142. package/dist/esm/extractor/errors.js +3 -0
  143. package/dist/esm/extractor/errors.js.map +1 -0
  144. package/dist/esm/extractor/esbuildAliasPlugin.js +39 -0
  145. package/dist/esm/extractor/esbuildAliasPlugin.js.map +1 -0
  146. package/dist/esm/extractor/esbuildTsconfigPaths.js +63 -0
  147. package/dist/esm/extractor/esbuildTsconfigPaths.js.map +1 -0
  148. package/dist/esm/extractor/evaluateAstNode.js +103 -0
  149. package/dist/esm/extractor/evaluateAstNode.js.map +1 -0
  150. package/dist/esm/extractor/extractHelpers.js +166 -0
  151. package/dist/esm/extractor/extractHelpers.js.map +1 -0
  152. package/dist/esm/extractor/extractMediaStyle.js +138 -0
  153. package/dist/esm/extractor/extractMediaStyle.js.map +1 -0
  154. package/dist/esm/extractor/extractToClassNames.js +537 -0
  155. package/dist/esm/extractor/extractToClassNames.js.map +1 -0
  156. package/dist/esm/extractor/extractToNative.js +398 -0
  157. package/dist/esm/extractor/extractToNative.js.map +1 -0
  158. package/dist/esm/extractor/extractablePath.js +84 -0
  159. package/dist/esm/extractor/extractablePath.js.map +1 -0
  160. package/dist/esm/extractor/findTopmostFunction.js +14 -0
  161. package/dist/esm/extractor/findTopmostFunction.js.map +1 -0
  162. package/dist/esm/extractor/generatedUid.js +31 -0
  163. package/dist/esm/extractor/generatedUid.js.map +1 -0
  164. package/dist/esm/extractor/getGuiConfigPathFromOptionsConfig.js +18 -0
  165. package/dist/esm/extractor/getGuiConfigPathFromOptionsConfig.js.map +1 -0
  166. package/dist/esm/extractor/getPrefixLogs.js +6 -0
  167. package/dist/esm/extractor/getPrefixLogs.js.map +1 -0
  168. package/dist/esm/extractor/getPropValueFromAttributes.js +71 -0
  169. package/dist/esm/extractor/getPropValueFromAttributes.js.map +1 -0
  170. package/dist/esm/extractor/getSourceModule.js +77 -0
  171. package/dist/esm/extractor/getSourceModule.js.map +1 -0
  172. package/dist/esm/extractor/getStaticBindingsForScope.js +207 -0
  173. package/dist/esm/extractor/getStaticBindingsForScope.js.map +1 -0
  174. package/dist/esm/extractor/hasTopLevelAwait.js +25 -0
  175. package/dist/esm/extractor/hasTopLevelAwait.js.map +1 -0
  176. package/dist/esm/extractor/hoistClassNames.js +43 -0
  177. package/dist/esm/extractor/hoistClassNames.js.map +1 -0
  178. package/dist/esm/extractor/literalToAst.js +78 -0
  179. package/dist/esm/extractor/literalToAst.js.map +1 -0
  180. package/dist/esm/extractor/loadFile.js +22 -0
  181. package/dist/esm/extractor/loadFile.js.map +1 -0
  182. package/dist/esm/extractor/loadGui.js +402 -0
  183. package/dist/esm/extractor/loadGui.js.map +1 -0
  184. package/dist/esm/extractor/logLines.js +16 -0
  185. package/dist/esm/extractor/logLines.js.map +1 -0
  186. package/dist/esm/extractor/normalizeTernaries.js +56 -0
  187. package/dist/esm/extractor/normalizeTernaries.js.map +1 -0
  188. package/dist/esm/extractor/propsToFontFamilyCache.js +15 -0
  189. package/dist/esm/extractor/propsToFontFamilyCache.js.map +1 -0
  190. package/dist/esm/extractor/regenerateConfig.js +145 -0
  191. package/dist/esm/extractor/regenerateConfig.js.map +1 -0
  192. package/dist/esm/extractor/removeUnusedHooks.js +80 -0
  193. package/dist/esm/extractor/removeUnusedHooks.js.map +1 -0
  194. package/dist/esm/extractor/timer.js +26 -0
  195. package/dist/esm/extractor/timer.js.map +1 -0
  196. package/dist/esm/extractor/validHTMLAttributes.js +53 -0
  197. package/dist/esm/extractor/validHTMLAttributes.js.map +1 -0
  198. package/dist/esm/extractor/watchGuiConfig.js +53 -0
  199. package/dist/esm/extractor/watchGuiConfig.js.map +1 -0
  200. package/dist/esm/getPragmaOptions.js +49 -0
  201. package/dist/esm/getPragmaOptions.js.map +1 -0
  202. package/dist/esm/helpers/memoize.js +21 -0
  203. package/dist/esm/helpers/memoize.js.map +1 -0
  204. package/dist/esm/helpers/nativeEntry.js +82 -0
  205. package/dist/esm/helpers/nativeEntry.js.map +1 -0
  206. package/dist/esm/helpers/requireGuiCore.js +22 -0
  207. package/dist/esm/helpers/requireGuiCore.js.map +1 -0
  208. package/dist/esm/here.js +7 -0
  209. package/dist/esm/here.js.map +1 -0
  210. package/dist/esm/index.js +5 -0
  211. package/dist/esm/index.js.map +1 -0
  212. package/dist/esm/registerRequire.js +256 -0
  213. package/dist/esm/registerRequire.js.map +1 -0
  214. package/dist/esm/server.js +37 -0
  215. package/dist/esm/server.js.map +1 -0
  216. package/dist/esm/setup.js +2 -0
  217. package/dist/esm/setup.js.map +1 -0
  218. package/dist/esm/types.js +2 -0
  219. package/dist/esm/types.js.map +1 -0
  220. package/dist/esm/worker.js +92 -0
  221. package/dist/esm/worker.js.map +1 -0
  222. package/package.json +77 -56
  223. package/src/check-dep-versions.ts +2 -1
  224. package/src/checkDeps.ts +1 -1
  225. package/src/exports.ts +17 -17
  226. package/src/extractor/babelParse.ts +2 -11
  227. package/src/extractor/buildClassName.ts +1 -1
  228. package/src/extractor/bundle.ts +13 -9
  229. package/src/extractor/bundleConfig.ts +25 -21
  230. package/src/extractor/createEvaluator.ts +3 -3
  231. package/src/extractor/createExtractor.ts +59 -77
  232. package/src/extractor/createLogger.ts +2 -2
  233. package/src/extractor/esbuildTsconfigPaths.ts +55 -120
  234. package/src/extractor/evaluateAstNode.ts +2 -2
  235. package/src/extractor/extractHelpers.ts +3 -3
  236. package/src/extractor/extractMediaStyle.ts +3 -3
  237. package/src/extractor/extractToClassNames.ts +12 -12
  238. package/src/extractor/extractToNative.ts +20 -22
  239. package/src/extractor/findTopmostFunction.ts +5 -13
  240. package/src/extractor/getGuiConfigPathFromOptionsConfig.ts +1 -1
  241. package/src/extractor/getPrefixLogs.ts +1 -1
  242. package/src/extractor/getPropValueFromAttributes.ts +2 -2
  243. package/src/extractor/getStaticBindingsForScope.ts +6 -6
  244. package/src/extractor/hasTopLevelAwait.ts +1 -1
  245. package/src/extractor/literalToAst.ts +2 -2
  246. package/src/extractor/loadFile.ts +6 -1
  247. package/src/extractor/loadGui.ts +16 -12
  248. package/src/extractor/normalizeTernaries.ts +3 -3
  249. package/src/extractor/regenerateConfig.ts +10 -6
  250. package/src/extractor/watchGuiConfig.ts +7 -3
  251. package/src/helpers/nativeEntry.ts +92 -0
  252. package/src/helpers/requireGuiCore.ts +8 -3
  253. package/src/here.cjs.ts +6 -0
  254. package/src/here.ts +8 -0
  255. package/src/index.ts +2 -2
  256. package/src/registerRequire.ts +30 -14
  257. package/src/server.ts +1 -1
  258. package/src/types.ts +1 -1
  259. package/src/worker.ts +7 -7
  260. package/types/check-dep-versions.d.ts.map +1 -1
  261. package/types/constants.d.ts +1 -1
  262. package/types/constants.d.ts.map +1 -1
  263. package/types/exports.d.ts +17 -17
  264. package/types/exports.d.ts.map +1 -1
  265. package/types/extractor/babelParse.d.ts.map +1 -1
  266. package/types/extractor/buildClassName.d.ts +1 -1
  267. package/types/extractor/buildClassName.d.ts.map +1 -1
  268. package/types/extractor/bundle.d.ts +66 -66
  269. package/types/extractor/bundle.d.ts.map +1 -1
  270. package/types/extractor/bundleConfig.d.ts +2 -2
  271. package/types/extractor/bundleConfig.d.ts.map +1 -1
  272. package/types/extractor/createEvaluator.d.ts +1 -1
  273. package/types/extractor/createEvaluator.d.ts.map +1 -1
  274. package/types/extractor/createExtractor.d.ts +4 -4
  275. package/types/extractor/createExtractor.d.ts.map +1 -1
  276. package/types/extractor/createLogger.d.ts +1 -1
  277. package/types/extractor/createLogger.d.ts.map +1 -1
  278. package/types/extractor/esbuildAliasPlugin.d.ts.map +1 -1
  279. package/types/extractor/esbuildTsconfigPaths.d.ts +4 -9
  280. package/types/extractor/esbuildTsconfigPaths.d.ts.map +1 -1
  281. package/types/extractor/extractHelpers.d.ts +1 -1
  282. package/types/extractor/extractHelpers.d.ts.map +1 -1
  283. package/types/extractor/extractMediaStyle.d.ts +2 -3
  284. package/types/extractor/extractMediaStyle.d.ts.map +1 -1
  285. package/types/extractor/extractToClassNames.d.ts +2 -2
  286. package/types/extractor/extractToClassNames.d.ts.map +1 -1
  287. package/types/extractor/extractToNative.d.ts +4 -4
  288. package/types/extractor/extractToNative.d.ts.map +1 -1
  289. package/types/extractor/findTopmostFunction.d.ts +1 -1
  290. package/types/extractor/findTopmostFunction.d.ts.map +1 -1
  291. package/types/extractor/getGuiConfigPathFromOptionsConfig.d.ts +1 -1
  292. package/types/extractor/getGuiConfigPathFromOptionsConfig.d.ts.map +1 -1
  293. package/types/extractor/getPrefixLogs.d.ts +1 -1
  294. package/types/extractor/getPrefixLogs.d.ts.map +1 -1
  295. package/types/extractor/loadFile.d.ts +1 -0
  296. package/types/extractor/loadGui.d.ts +1 -1
  297. package/types/extractor/loadGui.d.ts.map +1 -1
  298. package/types/extractor/logLines.d.ts.map +1 -1
  299. package/types/extractor/normalizeTernaries.d.ts +1 -1
  300. package/types/extractor/normalizeTernaries.d.ts.map +1 -1
  301. package/types/extractor/regenerateConfig.d.ts +1 -1
  302. package/types/extractor/regenerateConfig.d.ts.map +1 -1
  303. package/types/extractor/timer.d.ts.map +1 -1
  304. package/types/extractor/validHTMLAttributes.d.ts.map +1 -1
  305. package/types/extractor/watchGuiConfig.d.ts.map +1 -1
  306. package/types/getPragmaOptions.d.ts +1 -1
  307. package/types/helpers/memoize.d.ts +1 -1
  308. package/types/helpers/memoize.d.ts.map +1 -1
  309. package/types/helpers/nativeEntry.d.ts +16 -0
  310. package/types/helpers/nativeEntry.d.ts.map +1 -0
  311. package/types/helpers/requireGuiCore.d.ts +1 -1
  312. package/types/helpers/requireGuiCore.d.ts.map +1 -1
  313. package/types/here.d.ts +3 -0
  314. package/types/here.d.ts.map +1 -0
  315. package/types/index.d.ts +2 -2
  316. package/types/index.d.ts.map +1 -1
  317. package/types/registerRequire.d.ts +1 -1
  318. package/types/registerRequire.d.ts.map +1 -1
  319. package/types/server.d.ts +1 -1
  320. package/types/server.d.ts.map +1 -1
  321. package/types/types.d.ts +1 -1
  322. package/types/types.d.ts.map +1 -1
  323. package/types/worker.d.ts +4 -4
  324. package/types/worker.d.ts.map +1 -1
  325. package/dist/check-dep-versions.cjs +0 -372
  326. package/dist/checkDeps.cjs +0 -271
  327. package/dist/constants.cjs +0 -51
  328. package/dist/exports.cjs +0 -49
  329. package/dist/extractor/accessSafe.cjs +0 -48
  330. package/dist/extractor/babelParse.cjs +0 -56
  331. package/dist/extractor/buildClassName.cjs +0 -86
  332. package/dist/extractor/bundle.cjs +0 -234
  333. package/dist/extractor/bundleConfig.cjs +0 -729
  334. package/dist/extractor/concatClassName.cjs +0 -121
  335. package/dist/extractor/createEvaluator.cjs +0 -88
  336. package/dist/extractor/createExtractor.cjs +0 -1935
  337. package/dist/extractor/createLogger.cjs +0 -50
  338. package/dist/extractor/detectModuleFormat.cjs +0 -55
  339. package/dist/extractor/ensureImportingConcat.cjs +0 -54
  340. package/dist/extractor/errors.cjs +0 -28
  341. package/dist/extractor/esbuildAliasPlugin.cjs +0 -56
  342. package/dist/extractor/esbuildTsconfigPaths.cjs +0 -126
  343. package/dist/extractor/evaluateAstNode.cjs +0 -128
  344. package/dist/extractor/extractHelpers.cjs +0 -182
  345. package/dist/extractor/extractMediaStyle.cjs +0 -169
  346. package/dist/extractor/extractToClassNames.cjs +0 -476
  347. package/dist/extractor/extractToNative.cjs +0 -369
  348. package/dist/extractor/extractablePath.cjs +0 -51
  349. package/dist/extractor/findTopmostFunction.cjs +0 -43
  350. package/dist/extractor/generatedUid.cjs +0 -58
  351. package/dist/extractor/getGuiConfigPathFromOptionsConfig.cjs +0 -41
  352. package/dist/extractor/getPrefixLogs.cjs +0 -31
  353. package/dist/extractor/getPropValueFromAttributes.cjs +0 -85
  354. package/dist/extractor/getSourceModule.cjs +0 -100
  355. package/dist/extractor/getStaticBindingsForScope.cjs +0 -213
  356. package/dist/extractor/hasTopLevelAwait.cjs +0 -62
  357. package/dist/extractor/hoistClassNames.cjs +0 -76
  358. package/dist/extractor/literalToAst.cjs +0 -109
  359. package/dist/extractor/loadFile.cjs +0 -17
  360. package/dist/extractor/loadGui.cjs +0 -373
  361. package/dist/extractor/logLines.cjs +0 -43
  362. package/dist/extractor/normalizeTernaries.cjs +0 -95
  363. package/dist/extractor/propsToFontFamilyCache.cjs +0 -42
  364. package/dist/extractor/regenerateConfig.cjs +0 -178
  365. package/dist/extractor/removeUnusedHooks.cjs +0 -108
  366. package/dist/extractor/timer.cjs +0 -52
  367. package/dist/extractor/validHTMLAttributes.cjs +0 -79
  368. package/dist/extractor/watchGuiConfig.cjs +0 -70
  369. package/dist/getPragmaOptions.cjs +0 -73
  370. package/dist/helpers/memoize.cjs +0 -45
  371. package/dist/helpers/requireGuiCore.cjs +0 -40
  372. package/dist/index.cjs +0 -42
  373. package/dist/registerRequire.cjs +0 -209
  374. package/dist/server.cjs +0 -82
  375. package/dist/setup.cjs +0 -0
  376. package/dist/types.cjs +0 -18
  377. package/dist/worker.cjs +0 -111
@@ -1,1935 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
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, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
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);
34
- var createExtractor_exports = {};
35
- __export(createExtractor_exports, {
36
- createExtractor: () => createExtractor
37
- });
38
- module.exports = __toCommonJS(createExtractor_exports);
39
- var import_traverse = __toESM(require("@babel/traverse"));
40
- var t = __toESM(require("@babel/types"));
41
- var import_cli_color = require("@hanzogui/cli-color");
42
- var reactNativeWebInternals = __toESM(require("@hanzogui/react-native-web-internals"));
43
- var import_web = require("@hanzogui/web");
44
- var import_node_fs = require("node:fs");
45
- var import_node_path = require("node:path");
46
- var import_typescript = require("typescript");
47
- var import_constants = require("../constants.cjs");
48
- var import_requireGuiCore = require("../helpers/requireGuiCore.cjs");
49
- var import_createEvaluator = require("./createEvaluator.cjs");
50
- var import_extractablePath = require("./extractablePath.cjs");
51
- var import_evaluateAstNode = require("./evaluateAstNode.cjs");
52
- var import_extractHelpers = require("./extractHelpers.cjs");
53
- var import_findTopmostFunction = require("./findTopmostFunction.cjs");
54
- var import_getStaticBindingsForScope = require("./getStaticBindingsForScope.cjs");
55
- var import_literalToAst = require("./literalToAst.cjs");
56
- var import_loadGui = require("./loadGui.cjs");
57
- var import_logLines = require("./logLines.cjs");
58
- var import_normalizeTernaries = require("./normalizeTernaries.cjs");
59
- var import_propsToFontFamilyCache = require("./propsToFontFamilyCache.cjs");
60
- var import_timer = require("./timer.cjs");
61
- var import_validHTMLAttributes = require("./validHTMLAttributes.cjs");
62
- var import_errors = require("./errors.cjs");
63
- var import_esbuildTsconfigPaths = require("./esbuildTsconfigPaths.cjs");
64
- const UNTOUCHED_PROPS = {
65
- key: true,
66
- style: true,
67
- className: true
68
- };
69
- const nativeOnlyPlatforms = /* @__PURE__ */new Set(["android", "ios", "tv", "androidtv", "tvos"]);
70
- const createTernary = x => x;
71
- let hasLoggedBaseInfo = false;
72
- function isFullyDisabled(props) {
73
- return props.disableExtraction && props.disableDebugAttr;
74
- }
75
- function hasUntilMeasuredAncestor(path, groupName) {
76
- let current = path.parentPath;
77
- while (current) {
78
- if (current.isJSXElement()) {
79
- const opening = current.node.openingElement;
80
- let foundGroup = false;
81
- let foundUntilMeasured = false;
82
- for (const attr of opening.attributes) {
83
- if (!t.isJSXAttribute(attr)) continue;
84
- if (!t.isJSXIdentifier(attr.name)) continue;
85
- const aName = attr.name.name;
86
- if (aName === "group") {
87
- if (t.isStringLiteral(attr.value) && attr.value.value === groupName) {
88
- foundGroup = true;
89
- } else if (t.isJSXExpressionContainer(attr.value) && t.isStringLiteral(attr.value.expression) && attr.value.expression.value === groupName) {
90
- foundGroup = true;
91
- }
92
- } else if (aName === "untilMeasured") {
93
- foundUntilMeasured = true;
94
- }
95
- }
96
- if (foundGroup && foundUntilMeasured) return true;
97
- }
98
- current = current.parentPath;
99
- }
100
- return false;
101
- }
102
- function createExtractor({
103
- logger = console,
104
- platform = "web"
105
- } = {
106
- logger: console
107
- }) {
108
- const INLINE_EXTRACTABLE = {
109
- ref: "ref",
110
- key: "key",
111
- ...(platform === "web" && {
112
- onPress: "onClick",
113
- onHoverIn: "onMouseEnter",
114
- onHoverOut: "onMouseLeave",
115
- onPressIn: "onMouseDown",
116
- onPressOut: "onMouseUp"
117
- }),
118
- ...(platform === "native" && {
119
- // native view props that should pass through without preventing flattening
120
- testID: "testID",
121
- nativeID: "nativeID",
122
- accessibilityLabel: "accessibilityLabel",
123
- accessibilityHint: "accessibilityHint",
124
- accessibilityRole: "accessibilityRole",
125
- accessibilityState: "accessibilityState",
126
- accessibilityValue: "accessibilityValue",
127
- accessibilityActions: "accessibilityActions",
128
- accessibilityLabelledBy: "accessibilityLabelledBy",
129
- accessibilityLiveRegion: "accessibilityLiveRegion",
130
- accessibilityElementsHidden: "accessibilityElementsHidden",
131
- accessibilityViewIsModal: "accessibilityViewIsModal",
132
- importantForAccessibility: "importantForAccessibility",
133
- collapsable: "collapsable",
134
- needsOffscreenAlphaCompositing: "needsOffscreenAlphaCompositing",
135
- removeClippedSubviews: "removeClippedSubviews",
136
- renderToHardwareTextureAndroid: "renderToHardwareTextureAndroid",
137
- shouldRasterizeIOS: "shouldRasterizeIOS",
138
- hitSlop: "hitSlop",
139
- pointerEvents: "pointerEvents"
140
- })
141
- };
142
- const componentState = {
143
- focus: false,
144
- focusVisible: false,
145
- focusWithin: false,
146
- hover: false,
147
- unmounted: true,
148
- press: false,
149
- pressIn: false,
150
- disabled: false
151
- };
152
- const styleProps = {
153
- resolveValues: platform === "native" ? "value" : "variable",
154
- noClass: false,
155
- isAnimated: false
156
- };
157
- const shouldAddDebugProp =
158
- // really basic disable this for next.js because it messes with ssr
159
- !process.env.npm_package_dependencies_next && platform !== "native" && process.env.IDENTIFY_TAGS !== "false" && (process.env.NODE_ENV === "development" || process.env.IDENTIFY_TAGS);
160
- let projectInfo = null;
161
- const dynamicComponentCache = /* @__PURE__ */new Map();
162
- const dynamicLoadingInProgress = /* @__PURE__ */new Set();
163
- let _compilerOptions = null;
164
- function getCompilerOptions() {
165
- if (!_compilerOptions) {
166
- try {
167
- _compilerOptions = (0, import_esbuildTsconfigPaths.loadCompilerOptionsFromTsconfig)();
168
- } catch {
169
- _compilerOptions = {};
170
- }
171
- }
172
- return _compilerOptions;
173
- }
174
- function resolveImportPath(fromFile, importPath) {
175
- if (importPath.startsWith(".")) {
176
- const dir = (0, import_node_path.dirname)(fromFile);
177
- const base = (0, import_node_path.resolve)(dir, importPath);
178
- const extensions = [".tsx", ".ts", ".jsx", ".js"];
179
- for (const ext of extensions) {
180
- const full = base + ext;
181
- if ((0, import_node_fs.existsSync)(full)) return full;
182
- }
183
- for (const ext of extensions) {
184
- const full = (0, import_node_path.resolve)(base, `index${ext}`);
185
- if ((0, import_node_fs.existsSync)(full)) return full;
186
- }
187
- return null;
188
- }
189
- const compilerOptions = getCompilerOptions();
190
- if (compilerOptions.paths) {
191
- try {
192
- const {
193
- resolvedModule
194
- } = (0, import_typescript.nodeModuleNameResolver)(importPath, fromFile, compilerOptions, import_typescript.sys);
195
- if (resolvedModule && !resolvedModule.resolvedFileName.endsWith(".d.ts") && !resolvedModule.isExternalLibraryImport) {
196
- return resolvedModule.resolvedFileName;
197
- }
198
- } catch {}
199
- }
200
- return null;
201
- }
202
- const styledCheckCache = /* @__PURE__ */new Map();
203
- function mightHaveStyledComponents(filePath) {
204
- const cached = styledCheckCache.get(filePath);
205
- if (cached !== void 0) return cached;
206
- try {
207
- const content = (0, import_node_fs.readFileSync)(filePath, "utf-8");
208
- const result = content.includes("styled(");
209
- styledCheckCache.set(filePath, result);
210
- return result;
211
- } catch {
212
- styledCheckCache.set(filePath, false);
213
- return false;
214
- }
215
- }
216
- function loadSync(props) {
217
- if (isFullyDisabled(props)) {
218
- return null;
219
- }
220
- return projectInfo ||= (0, import_loadGui.loadGuiSync)(props);
221
- }
222
- async function load(props) {
223
- if (isFullyDisabled(props)) {
224
- return null;
225
- }
226
- return projectInfo ||= await (0, import_loadGui.loadGui)(props);
227
- }
228
- return {
229
- options: {
230
- logger
231
- },
232
- cleanupBeforeExit: import_getStaticBindingsForScope.cleanupBeforeExit,
233
- loadGui: load,
234
- loadGuiSync: loadSync,
235
- getGui() {
236
- return projectInfo?.hanzoguiConfig;
237
- },
238
- parseSync: (f, props) => {
239
- globalThis.expo ||= {};
240
- const projectInfo2 = loadSync(props);
241
- return parseWithConfig(projectInfo2 || {}, f, props);
242
- },
243
- parse: async (f, props) => {
244
- globalThis.expo ||= {};
245
- const projectInfo2 = await load(props);
246
- return parseWithConfig(projectInfo2 || {}, f, props);
247
- }
248
- };
249
- function parseWithConfig({
250
- components,
251
- hanzoguiConfig
252
- }, fileOrPath, options) {
253
- const {
254
- config = "hanzogui.config.ts",
255
- importsWhitelist = ["constants.js"],
256
- evaluateVars = true,
257
- sourcePath = "",
258
- onExtractTag,
259
- onStyledDefinitionRule,
260
- getFlattenedNode,
261
- disable,
262
- disableExtraction,
263
- disableExtractVariables,
264
- disableDebugAttr,
265
- enableDynamicEvaluation = false,
266
- includeExtensions = [".ts", ".tsx", ".jsx"],
267
- extractStyledDefinitions = false,
268
- prefixLogs,
269
- excludeProps,
270
- platform: platform2,
271
- ...restProps
272
- } = options;
273
- if (sourcePath && dynamicComponentCache.has(sourcePath)) {
274
- dynamicComponentCache.delete(sourcePath);
275
- styledCheckCache.delete(sourcePath);
276
- }
277
- if (sourcePath.includes(".hanzogui-dynamic-eval")) {
278
- return null;
279
- }
280
- const {
281
- normalizeStyle,
282
- getSplitStyles,
283
- mediaQueryConfig,
284
- propMapper,
285
- proxyThemeVariables,
286
- getDefaultProps,
287
- pseudoDescriptors
288
- } = (0, import_requireGuiCore.requireGuiCore)(platform2);
289
- let shouldPrintDebug = options.shouldPrintDebug || false;
290
- if (disable === true || Array.isArray(disable) && disable.includes(sourcePath)) {
291
- return null;
292
- }
293
- if (!isFullyDisabled(options)) {
294
- if (!components) {
295
- throw new Error(`Must provide components`);
296
- }
297
- }
298
- if (sourcePath && includeExtensions && !(0, import_extractablePath.installedPackageOf)(sourcePath) && !includeExtensions.some(ext => sourcePath.endsWith(ext))) {
299
- if (shouldPrintDebug) {
300
- logger.info(`Ignoring file due to includeExtensions: ${sourcePath}, includeExtensions: ${includeExtensions.join(", ")}`);
301
- }
302
- return null;
303
- }
304
- function isValidStyleKey(name, staticConfig) {
305
- if (!projectInfo) {
306
- throw new Error(`Gui extractor not loaded yet`);
307
- }
308
- if (platform2 === "native" && name[0] === "$" && mediaQueryConfig[name.slice(1)]) {
309
- return false;
310
- }
311
- if (name[0] === "$") {
312
- const mediaName = name.slice(1);
313
- if (mediaName.startsWith("theme-") || mediaName.startsWith("platform-") || mediaName.startsWith("group-")) {
314
- return true;
315
- }
316
- if (mediaQueryConfig[mediaName]) {
317
- return true;
318
- }
319
- }
320
- return !!(staticConfig.validStyles?.[name] || pseudoDescriptors[name] ||
321
- // don't disable variants or else you lose many things flattening
322
- staticConfig.variants?.[name] || projectInfo?.hanzoguiConfig?.shorthands[name]);
323
- }
324
- function getGroupPseudo(name) {
325
- const [_, groupName, a, b, c] = name.split("-");
326
- if (!groupName) return;
327
- const m2 = a && b ? `${a}-${b}` : "";
328
- const media = m2 && mediaQueryConfig[m2] && m2 || a && mediaQueryConfig[a] && a;
329
- return media ? media === m2 ? c : b ? `${b}${c ? `-${c}` : ""}` : void 0 : a ? `${a}${b ? `-${b}` : ""}${c ? `-${c}` : ""}` : void 0;
330
- }
331
- const isTargetingHTML = platform2 === "web";
332
- const ogDebug = shouldPrintDebug;
333
- const tm = (0, import_timer.timer)();
334
- const propsWithFileInfo = {
335
- ...options,
336
- sourcePath,
337
- allLoadedComponents: components ? [...components] : []
338
- };
339
- if (!hasLoggedBaseInfo) {
340
- hasLoggedBaseInfo = true;
341
- if (shouldPrintDebug) {
342
- logger.info(["loaded components:", propsWithFileInfo.allLoadedComponents.map(comp => Object.keys(comp.nameToInfo).join(", ")).join(", ")].join(" "));
343
- }
344
- if (process.env.DEBUG?.startsWith("hanzogui")) {
345
- logger.info(["loaded:", propsWithFileInfo.allLoadedComponents.map(x => x.moduleName)].join("\n"));
346
- }
347
- }
348
- tm.mark("load-hanzogui", !!shouldPrintDebug);
349
- if (!isFullyDisabled(options)) {
350
- if (!hanzoguiConfig?.themes) {
351
- console.error(`\u26D4\uFE0F Error: Missing "themes" in your hanzogui.config file:
352
-
353
- You may not need the compiler! Remember you can run Gui with no configuration at all.
354
-
355
- You may have not "export default" your config (you can also "export const config").
356
-
357
- Or this may be due to duplicated dependency versions:
358
- - try out https://github.com/bmish/check-dependency-version-consistency to see if there are mis-matches.
359
- - or search your lockfile for mis-matches.
360
- `);
361
- console.info(` Got config:`, hanzoguiConfig);
362
- process.exit(0);
363
- }
364
- }
365
- const firstThemeName = Object.keys(hanzoguiConfig?.themes || {})[0];
366
- const firstTheme = hanzoguiConfig?.themes[firstThemeName] || {};
367
- if (!firstTheme || typeof firstTheme !== "object") {
368
- const err = `Missing theme ${firstThemeName}, an error occurred when importing your config`;
369
- console.info(err, `Got config:`, hanzoguiConfig);
370
- console.info(`Looking for theme:`, firstThemeName);
371
- throw new Error(err);
372
- }
373
- const proxiedTheme = proxyThemeVariables(firstTheme);
374
- const themeAccessListeners = /* @__PURE__ */new Set();
375
- const defaultTheme = new Proxy(proxiedTheme, {
376
- get(target, key) {
377
- if (Reflect.has(target, key)) {
378
- themeAccessListeners.forEach(cb => cb(String(key)));
379
- }
380
- return Reflect.get(target, key);
381
- }
382
- });
383
- const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
384
- if (!isFullyDisabled(options)) {
385
- if (Object.keys(components || []).length === 0) {
386
- console.warn(`Warning: Gui didn't find any valid components (DEBUG=hanzogui for more)`);
387
- if (process.env.DEBUG === "hanzogui") {
388
- console.info(`components`, Object.keys(components || []), components);
389
- }
390
- }
391
- }
392
- if (shouldPrintDebug === "verbose") {
393
- logger.info(`allLoadedComponent modules ${propsWithFileInfo.allLoadedComponents.map(k => k.moduleName).join(", ")}`);
394
- logger.info(`valid import paths: ${JSON.stringify((0, import_extractHelpers.getValidComponentsPaths)(propsWithFileInfo))}`);
395
- }
396
- let doesUseValidImport = false;
397
- let hasImportedTheme = false;
398
- const importDeclarations = [];
399
- for (const bodyPath of body) {
400
- if (bodyPath.type !== "ImportDeclaration") continue;
401
- const node = "node" in bodyPath ? bodyPath.node : bodyPath;
402
- const moduleName = node.source.value;
403
- const valid = (0, import_extractHelpers.isValidImport)(propsWithFileInfo, moduleName);
404
- if (valid) {
405
- importDeclarations.push(node);
406
- }
407
- if (shouldPrintDebug === "verbose") {
408
- logger.info(` - import via ${moduleName} ${valid}`);
409
- }
410
- if (extractStyledDefinitions && enableDynamicEvaluation) {
411
- if (node.specifiers.some(specifier => specifier.local.name === "styled")) {
412
- doesUseValidImport = true;
413
- }
414
- }
415
- if (valid) {
416
- const names = node.specifiers.map(specifier => specifier.local.name);
417
- const isValidComponent = names.some(name => Boolean((0, import_extractHelpers.isValidImport)(propsWithFileInfo, moduleName, name)));
418
- if (shouldPrintDebug === "verbose") {
419
- logger.info(` - import ${isValidComponent ? "\u2705" : "\u21E3"} - ${names.join(", ")} via package '${moduleName}' - (valid: ${JSON.stringify((0, import_extractHelpers.getValidComponentsPaths)(propsWithFileInfo))})`);
420
- }
421
- if (isValidComponent) {
422
- doesUseValidImport = true;
423
- if (!(extractStyledDefinitions && enableDynamicEvaluation)) break;
424
- }
425
- }
426
- }
427
- if (shouldPrintDebug) {
428
- logger.info(`${JSON.stringify({
429
- doesUseValidImport,
430
- hasImportedTheme
431
- }, null, 2)}
432
- `);
433
- }
434
- if (!doesUseValidImport && extractStyledDefinitions && enableDynamicEvaluation && sourcePath) {
435
- for (const bodyPath of body) {
436
- if (bodyPath.type !== "ImportDeclaration") continue;
437
- const node = "node" in bodyPath ? bodyPath.node : bodyPath;
438
- const moduleName = node.source.value;
439
- const resolved = resolveImportPath(sourcePath, moduleName);
440
- if (!resolved) continue;
441
- if (dynamicComponentCache.has(resolved)) {
442
- doesUseValidImport = true;
443
- break;
444
- }
445
- if (mightHaveStyledComponents(resolved)) {
446
- doesUseValidImport = true;
447
- break;
448
- }
449
- }
450
- }
451
- if (!doesUseValidImport) {
452
- return null;
453
- }
454
- function getValidImportedComponent(componentName) {
455
- const importDeclaration = importDeclarations.find(dec => dec.specifiers.some(spec => spec.local.name === componentName));
456
- if (!importDeclaration) {
457
- return null;
458
- }
459
- return (0, import_extractHelpers.getValidImport)(propsWithFileInfo, importDeclaration.source.value, componentName);
460
- }
461
- tm.mark("import-check", !!shouldPrintDebug);
462
- let couldntParse = false;
463
- const modifiedComponents = /* @__PURE__ */new Set();
464
- const bindingCache = {};
465
- const callTraverse = a => {
466
- return fileOrPath.type === "File" ? (0, import_traverse.default)(fileOrPath, a) : fileOrPath.traverse(a);
467
- };
468
- const shouldDisableExtraction = disableExtraction === true || Array.isArray(disableExtraction) && disableExtraction.includes(sourcePath);
469
- let programPath = null;
470
- const res = {
471
- styled: 0,
472
- flattened: 0,
473
- optimized: 0,
474
- modified: 0,
475
- found: 0
476
- };
477
- const version = `${Math.random()}`;
478
- callTraverse({
479
- // @ts-ignore
480
- Program: {
481
- enter(path) {
482
- programPath = path;
483
- }
484
- },
485
- // styled() calls
486
- CallExpression(path) {
487
- if (disable || shouldDisableExtraction || extractStyledDefinitions === false) {
488
- return;
489
- }
490
- if (!t.isIdentifier(path.node.callee) || path.node.callee.name !== "styled") {
491
- return;
492
- }
493
- const variableName = t.isVariableDeclarator(path.parent) && t.isIdentifier(path.parent.id) ? path.parent.id.name : "unknown";
494
- if (shouldPrintDebug) {
495
- logger.info(` [styled] Found styled(${variableName})`);
496
- }
497
- const parentNode = path.node.arguments[0];
498
- if (!t.isIdentifier(parentNode)) {
499
- return;
500
- }
501
- const parentName = parentNode.name;
502
- const definition = path.node.arguments[1];
503
- if (!parentName || !definition || !t.isObjectExpression(definition)) {
504
- return;
505
- }
506
- let Component = getValidImportedComponent(parentName) || getValidImportedComponent(variableName);
507
- if (!Component) {
508
- if (!enableDynamicEvaluation) {
509
- return;
510
- }
511
- try {
512
- if (shouldPrintDebug) {
513
- logger.info(`Unknown component: ${variableName} = styled(${parentName}) attempting dynamic load: ${sourcePath}`);
514
- }
515
- const out2 = (0, import_loadGui.loadGuiSync)({
516
- forceExports: true,
517
- components: [sourcePath],
518
- cacheKey: version
519
- });
520
- if (!out2?.components) {
521
- if (shouldPrintDebug) {
522
- logger.info(`Couldn't load, got ${out2}`);
523
- }
524
- return;
525
- }
526
- propsWithFileInfo.allLoadedComponents = [...propsWithFileInfo.allLoadedComponents, ...out2.components];
527
- Component = out2.components.flatMap(x => x.nameToInfo[variableName] ?? [])[0];
528
- if (!out2.cached) {
529
- const foundNames = out2.components?.map(x => Object.keys(x.nameToInfo).join(", ")).join(", ").trim();
530
- if (foundNames) {
531
- (0, import_cli_color.colorLog)(import_cli_color.Color.FgYellow, ` | Gui found dynamic components: ${foundNames}`);
532
- }
533
- }
534
- } catch (err) {
535
- if (shouldPrintDebug) {
536
- logger.info(`skip optimize styled(${variableName}), unable to pre-process (DEBUG=hanzogui for more)`);
537
- }
538
- }
539
- }
540
- if (!Component) {
541
- if (shouldPrintDebug) {
542
- logger.info(` No component found`);
543
- }
544
- return;
545
- }
546
- const componentSkipProps = /* @__PURE__ */new Set([...(Component.staticConfig.inlineWhenUnflattened || []), ...(Component.staticConfig.inlineProps || []),
547
- // for now skip variants, will return to them
548
- "variants", "defaultVariants",
549
- // skip fontFamily its basically a "variant", important for theme use to be value always
550
- "fontFamily", "name", "focusStyle", "focusVisibleStyle", "focusWithinStyle", "disabledStyle", "hoverStyle", "pressStyle"]);
551
- const skipped = /* @__PURE__ */new Set();
552
- const styles = {};
553
- const staticDefaultProps = {};
554
- const staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(path.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
555
- const attemptEval = !evaluateVars ? import_evaluateAstNode.evaluateAstNode : (0, import_createEvaluator.createEvaluator)({
556
- props: propsWithFileInfo,
557
- staticNamespace,
558
- sourcePath,
559
- shouldPrintDebug
560
- });
561
- const attemptEvalSafe = (0, import_createEvaluator.createSafeEvaluator)(attemptEval);
562
- for (const property of definition.properties) {
563
- if (t.isObjectProperty(property) && (t.isIdentifier(property.key) || t.isStringLiteral(property.key))) {
564
- const key = t.isIdentifier(property.key) ? property.key.name : property.key.value;
565
- const defaultPropValue = attemptEvalSafe(property.value);
566
- if (defaultPropValue !== import_constants.FAILED_EVAL) {
567
- staticDefaultProps[key] = defaultPropValue;
568
- }
569
- }
570
- if (!t.isObjectProperty(property) || !t.isIdentifier(property.key) || !isValidStyleKey(property.key.name, Component.staticConfig) ||
571
- // TODO make pseudos and variants work
572
- // skip pseudos
573
- pseudoDescriptors[property.key.name] ||
574
- // skip variants
575
- Component.staticConfig.variants?.[property.key.name] || componentSkipProps.has(property.key.name)) {
576
- skipped.add(property);
577
- continue;
578
- }
579
- const out2 = attemptEvalSafe(property.value);
580
- if (out2 === import_constants.FAILED_EVAL) {
581
- skipped.add(property);
582
- } else {
583
- styles[property.key.name] = out2;
584
- }
585
- }
586
- const out = getSplitStyles(styles, Component.staticConfig, defaultTheme, "", componentState, styleProps, void 0, void 0, void 0, void 0, false, shouldPrintDebug);
587
- const classNames = {
588
- ...out.classNames
589
- };
590
- if (shouldPrintDebug) {
591
- logger.info([`Extracted styled(${variableName})
592
- `, JSON.stringify(styles, null, 2), "\n classNames:", JSON.stringify(classNames, null, 2), "\n rulesToInsert:", out.rulesToInsert].join(" "));
593
- }
594
- if (out.rulesToInsert) {
595
- for (const key in out.rulesToInsert) {
596
- const styleObject = out.rulesToInsert[key];
597
- onStyledDefinitionRule?.(styleObject[import_web.StyleObjectIdentifier], styleObject[import_web.StyleObjectRules]);
598
- }
599
- }
600
- res.styled++;
601
- if (extractStyledDefinitions && enableDynamicEvaluation && Component) {
602
- const dynamicStaticConfig = {
603
- ...Component.staticConfig,
604
- defaultProps: {
605
- ...Component.staticConfig.defaultProps,
606
- ...staticDefaultProps
607
- }
608
- };
609
- propsWithFileInfo.allLoadedComponents.push({
610
- moduleName: "",
611
- nameToInfo: {
612
- [variableName]: {
613
- staticConfig: dynamicStaticConfig
614
- }
615
- }
616
- });
617
- if (sourcePath) {
618
- let existing = dynamicComponentCache.get(sourcePath);
619
- if (!existing) {
620
- existing = {
621
- moduleName: sourcePath,
622
- nameToInfo: {}
623
- };
624
- dynamicComponentCache.set(sourcePath, existing);
625
- }
626
- existing.nameToInfo[variableName] = {
627
- staticConfig: dynamicStaticConfig
628
- };
629
- }
630
- }
631
- if (shouldPrintDebug) {
632
- logger.info(`Extracted styled(${variableName})`);
633
- }
634
- },
635
- JSXElement(traversePath) {
636
- tm.mark("jsx-element", !!shouldPrintDebug);
637
- const node = traversePath.node.openingElement;
638
- const ogAttributes = node.attributes.map(attr => ({
639
- ...attr
640
- }));
641
- const componentName = (0, import_extractHelpers.findComponentName)(traversePath.scope);
642
- const closingElement = traversePath.node.closingElement;
643
- if (closingElement && t.isJSXMemberExpression(closingElement?.name) || !t.isJSXIdentifier(node.name)) {
644
- if (shouldPrintDebug) {
645
- logger.info(` skip non-identifier element`);
646
- }
647
- return;
648
- }
649
- const binding = traversePath.scope.getBinding(node.name.name);
650
- let moduleName = "";
651
- let dynamicComponent = null;
652
- if (binding) {
653
- if (t.isImportDeclaration(binding.path.parent)) {
654
- moduleName = binding.path.parent.source.value;
655
- if (!(0, import_extractHelpers.isValidImport)(propsWithFileInfo, moduleName, binding.identifier.name)) {
656
- if (enableDynamicEvaluation && sourcePath) {
657
- const resolved = resolveImportPath(sourcePath, moduleName);
658
- if (resolved) {
659
- const cached = dynamicComponentCache.get(resolved);
660
- if (cached?.nameToInfo[binding.identifier.name]) {
661
- dynamicComponent = cached.nameToInfo[binding.identifier.name];
662
- } else if (!dynamicLoadingInProgress.has(resolved) && mightHaveStyledComponents(resolved)) {
663
- dynamicLoadingInProgress.add(resolved);
664
- try {
665
- const out = (0, import_loadGui.loadGuiSync)({
666
- forceExports: true,
667
- components: [resolved]
668
- });
669
- if (out?.components) {
670
- for (const comp of out.components) {
671
- let existing = dynamicComponentCache.get(resolved);
672
- if (!existing) {
673
- existing = {
674
- moduleName: resolved,
675
- nameToInfo: {}
676
- };
677
- dynamicComponentCache.set(resolved, existing);
678
- }
679
- Object.assign(existing.nameToInfo, comp.nameToInfo);
680
- propsWithFileInfo.allLoadedComponents.push({
681
- moduleName: resolved,
682
- nameToInfo: comp.nameToInfo
683
- });
684
- }
685
- const cachedNow = dynamicComponentCache.get(resolved);
686
- if (cachedNow?.nameToInfo[binding.identifier.name]) {
687
- dynamicComponent = cachedNow.nameToInfo[binding.identifier.name];
688
- }
689
- }
690
- } catch (err) {
691
- if (shouldPrintDebug) {
692
- logger.info(` - Failed to dynamically load ${resolved}: ${err}`);
693
- }
694
- } finally {
695
- dynamicLoadingInProgress.delete(resolved);
696
- }
697
- }
698
- }
699
- }
700
- if (!dynamicComponent) {
701
- if (shouldPrintDebug) {
702
- logger.info(` - Binding in component ${componentName} not valid import: "${binding.identifier.name}" isn't in ${moduleName}
703
- `);
704
- }
705
- return;
706
- }
707
- }
708
- }
709
- }
710
- const component = dynamicComponent || (0, import_extractHelpers.getValidComponent)(propsWithFileInfo, moduleName, node.name.name);
711
- if (!component || !component.staticConfig) {
712
- if (shouldPrintDebug) {
713
- logger.info(`
714
- - No Gui conf for: ${node.name.name}
715
- `);
716
- }
717
- return;
718
- }
719
- const originalNodeName = node.name.name;
720
- res.found++;
721
- const filePath = `./${(0, import_node_path.relative)(process.cwd(), sourcePath)}`;
722
- const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
723
- const codePosition = `${filePath}:${lineNumbers}`;
724
- const debugPropValue = node.attributes.filter(n => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === "debug").map(n => {
725
- if (n.value === null) return true;
726
- if (t.isStringLiteral(n.value)) return n.value.value;
727
- return false;
728
- })[0];
729
- if (debugPropValue) {
730
- shouldPrintDebug = debugPropValue;
731
- }
732
- if (shouldPrintDebug) {
733
- logger.info(`\x1B[33m\x1B[0m ${componentName} | ${codePosition} -------------------`);
734
- logger.info(["\x1B[1m", "\x1B[32m", `<${originalNodeName} />`, disableDebugAttr ? "" : "\u{1F41B}"].join(" "));
735
- }
736
- if (platform2 !== "native") {
737
- if (shouldAddDebugProp && !disableDebugAttr) {
738
- res.modified++;
739
- node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(node.name.name)));
740
- if (componentName) {
741
- node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-in"), t.stringLiteral(componentName)));
742
- }
743
- node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-at"), t.stringLiteral(`${(0, import_node_path.basename)(filePath)}:${lineNumbers}`)));
744
- }
745
- }
746
- if (shouldDisableExtraction) {
747
- if (shouldPrintDebug === "verbose") {
748
- logger.info(` \u274C Extraction disabled: ${JSON.stringify(disableExtraction)}
749
- `);
750
- }
751
- return;
752
- }
753
- try {
754
- let evaluateAttribute = function (path) {
755
- const attribute = path.node;
756
- const attr = {
757
- type: "attr",
758
- value: attribute
759
- };
760
- if (t.isJSXSpreadAttribute(attribute)) {
761
- const arg = attribute.argument;
762
- const conditional = t.isConditionalExpression(arg) ?
763
- // <YStack {...isSmall ? { color: 'red } : { color: 'blue }}
764
- [arg.test, arg.consequent, arg.alternate] : t.isLogicalExpression(arg) && arg.operator === "&&" ?
765
- // <YStack {...isSmall && { color: 'red }}
766
- [arg.left, arg.right, null] : null;
767
- if (conditional) {
768
- const [test, alt, cons] = conditional;
769
- if (!test) throw new Error(`no test`);
770
- if ([alt, cons].some(side => side && !isStaticObject(side))) {
771
- if (shouldPrintDebug) {
772
- logger.info(`not extractable ${alt} ${cons}`);
773
- }
774
- return attr;
775
- }
776
- return [...(flattenNestedTernaries(test, alt) || []), ...(cons && flattenNestedTernaries(t.unaryExpression("!", test), cons) || [])].map(ternary => ({
777
- type: "ternary",
778
- value: ternary
779
- }));
780
- }
781
- }
782
- if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
783
- if (shouldPrintDebug) {
784
- logger.info(" ! inlining, spread attr");
785
- }
786
- inlined.set(`${Math.random()}`, "spread");
787
- return attr;
788
- }
789
- const name = attribute.name.name;
790
- if (name === "style") {
791
- shouldDeopt = true;
792
- return null;
793
- }
794
- if (excludeProps?.has(name)) {
795
- if (shouldPrintDebug) {
796
- logger.info([" excluding prop", name].join(" "));
797
- }
798
- return null;
799
- }
800
- if (inlineProps.has(name)) {
801
- inlined.set(name, name);
802
- if (shouldPrintDebug) {
803
- logger.info([" ! inlining, inline prop", name].join(" "));
804
- }
805
- return attr;
806
- }
807
- if (UNTOUCHED_PROPS[name]) {
808
- return attr;
809
- }
810
- if (INLINE_EXTRACTABLE[name]) {
811
- inlined.set(name, INLINE_EXTRACTABLE[name]);
812
- return attr;
813
- }
814
- if (name.startsWith("data-") || name.startsWith("aria-") || import_validHTMLAttributes.validHTMLAttributes[name]) {
815
- return attr;
816
- }
817
- if ((name === "enterStyle" || name === "exitStyle") && t.isJSXExpressionContainer(attribute?.value)) {
818
- shouldDeopt = true;
819
- return attr;
820
- }
821
- if (name[0] === "$" && t.isJSXExpressionContainer(attribute?.value)) {
822
- const shortname = name.slice(1);
823
- if (mediaQueryConfig[shortname]) {
824
- const expression = attribute.value.expression;
825
- if (!t.isJSXEmptyExpression(expression)) {
826
- const ternaries2 = flattenNestedTernaries(t.stringLiteral(shortname), expression, {
827
- inlineMediaQuery: shortname
828
- });
829
- if (ternaries2) {
830
- return ternaries2.map(value2 => ({
831
- type: "ternary",
832
- value: value2
833
- }));
834
- }
835
- }
836
- }
837
- }
838
- const [value, valuePath] = (() => {
839
- if (t.isJSXExpressionContainer(attribute?.value)) {
840
- return [attribute.value.expression, path.get("value")];
841
- }
842
- return [attribute.value, path.get("value")];
843
- })();
844
- if (deoptProps.has(name) || platform2 === "native" && name[0] === "$" && (name.startsWith("$theme-") || name.startsWith("$group-") && getGroupPseudo(name) !== "hover")) {
845
- inlined.set(name, true);
846
- return attr;
847
- }
848
- const remove = () => {
849
- Array.isArray(valuePath) ? valuePath.map(p => p.remove()) : valuePath.remove();
850
- };
851
- if (name === "ref") {
852
- if (shouldPrintDebug) {
853
- logger.info([" ! inlining, ref", name].join(" "));
854
- }
855
- inlined.set("ref", "ref");
856
- return attr;
857
- }
858
- if (name === "render") {
859
- if (!value || value.type !== "StringLiteral") {
860
- if (shouldPrintDebug) {
861
- logger.info(` ! deopt on render prop (not a string literal)`);
862
- }
863
- shouldDeopt = true;
864
- }
865
- return {
866
- type: "attr",
867
- value: path.node
868
- };
869
- }
870
- if (disableExtractVariables === true) {
871
- if (value) {
872
- if (value.type === "StringLiteral" && value.value[0] === "$") {
873
- if (shouldPrintDebug) {
874
- logger.info([` ! inlining, native disable extract: ${name} =`, value.value].join(" "));
875
- }
876
- inlined.set(name, true);
877
- return attr;
878
- }
879
- }
880
- }
881
- if (name === "theme") {
882
- inlined.set("theme", attr.value);
883
- return attr;
884
- }
885
- if (isTargetingHTML && name === "group" && t.isStringLiteral(value)) {
886
- return [];
887
- }
888
- const styleValue = attemptEvalSafe(value);
889
- if (name[0] === "$" && (name.startsWith("$theme-") || name.startsWith("$group-")) && styleValue && typeof styleValue === "object" && Object.keys(styleValue).some(k => k[0] === "$")) {
890
- if (shouldPrintDebug) {
891
- logger.info(` ! nested media-like key inside ${name}, deopt to runtime`);
892
- }
893
- inlined.set(name, true);
894
- return attr;
895
- }
896
- if (!variants[name] && !isValidStyleKey(name, staticConfig)) {
897
- let out = null;
898
- propMapper(name, styleValue, propMapperStyleState, false, (key, val) => {
899
- out ||= {};
900
- out[key] = val;
901
- });
902
- if (out) {
903
- if (isTargetingHTML) {
904
- out = reactNativeWebInternals.createDOMProps(isTextView ? "span" : "div", out);
905
- delete out.className;
906
- delete out.style;
907
- }
908
- }
909
- let didInline = false;
910
- const attributes = Object.keys(out).map(key => {
911
- const val = out[key];
912
- const isStyle = isValidStyleKey(key, staticConfig);
913
- if (isStyle) {
914
- return {
915
- type: "style",
916
- value: {
917
- [key]: styleValue
918
- },
919
- name: key,
920
- attr: path.node
921
- };
922
- }
923
- if (import_validHTMLAttributes.validHTMLAttributes[key] || key.startsWith("aria-") || key.startsWith("data-") ||
924
- // this is debug stuff added by vite / new jsx transform
925
- key === "__source" || key === "__self") {
926
- if (styleValue === import_constants.FAILED_EVAL && key !== name && t.isJSXAttribute(attr.value)) {
927
- return {
928
- type: "attr",
929
- value: t.jsxAttribute(t.jsxIdentifier(key), attr.value.value)
930
- };
931
- }
932
- return attr;
933
- }
934
- if (shouldPrintDebug) {
935
- logger.info(" ! inlining, non-static " + key);
936
- }
937
- didInline = true;
938
- inlined.set(key, val);
939
- return val;
940
- });
941
- if (didInline) {
942
- if (shouldPrintDebug) {
943
- logger.info(` bailing flattening due to attributes ${attributes.map(x => x.toString())}`);
944
- }
945
- return attr;
946
- }
947
- return attributes;
948
- }
949
- if (styleValue !== import_constants.FAILED_EVAL) {
950
- if (inlineWhenUnflattened.has(name)) {
951
- inlineWhenUnflattenedOGVals[name] = {
952
- styleValue,
953
- attr
954
- };
955
- }
956
- if (isValidStyleKey(name, staticConfig)) {
957
- if (name[0] === "$") {
958
- if (name.startsWith("$group-")) {
959
- const groupName = name.slice("$group-".length).split("-")[0];
960
- if (groupName && hasUntilMeasuredAncestor(path, groupName)) {
961
- if (shouldPrintDebug) {
962
- logger.info(` ! group="${groupName}" ancestor has untilMeasured, not flattening: ${name}`);
963
- }
964
- inlined.set(name, true);
965
- return attr;
966
- }
967
- }
968
- if (name.startsWith("$platform-")) {
969
- const platformName = name.slice(10);
970
- const isMatchingPlatform = platformName === platform2 || platformName === "native" && platform2 === "native" || platformName === "web" && platform2 === "web";
971
- if (isMatchingPlatform && typeof styleValue === "object") {
972
- if (shouldPrintDebug) {
973
- logger.info(` flattening $platform-${platformName}: ${JSON.stringify(styleValue)}`);
974
- }
975
- return Object.entries(styleValue).map(([key, val]) => ({
976
- type: "style",
977
- value: {
978
- [key]: val
979
- },
980
- name: key,
981
- attr: path.node
982
- }));
983
- } else {
984
- if (platform2 === "native" && nativeOnlyPlatforms.has(platformName)) {
985
- if (shouldPrintDebug) {
986
- logger.info(` ! keeping platform-specific style for runtime evaluation: ${name}`);
987
- }
988
- inlined.set(name, true);
989
- return attr;
990
- }
991
- if (shouldPrintDebug) {
992
- logger.info(` ! skipping non-matching platform style: ${name}`);
993
- }
994
- return [];
995
- }
996
- }
997
- }
998
- if (shouldPrintDebug) {
999
- logger.info(` style: ${name} = ${JSON.stringify(styleValue)}`);
1000
- }
1001
- if (!(name in defaultProps)) {
1002
- if (!hasSetOptimized) {
1003
- res.optimized++;
1004
- hasSetOptimized = true;
1005
- }
1006
- }
1007
- return {
1008
- type: "style",
1009
- value: {
1010
- [name]: styleValue
1011
- },
1012
- name,
1013
- attr: path.node
1014
- };
1015
- }
1016
- if (variants[name]) {
1017
- variantValues.set(name, styleValue);
1018
- }
1019
- inlined.set(name, true);
1020
- return attr;
1021
- }
1022
- if (t.isBinaryExpression(value)) {
1023
- if (shouldPrintDebug) {
1024
- logger.info(` binary expression ${name} = ${value}`);
1025
- }
1026
- const {
1027
- operator,
1028
- left,
1029
- right
1030
- } = value;
1031
- const lVal = attemptEvalSafe(left);
1032
- const rVal = attemptEvalSafe(right);
1033
- if (shouldPrintDebug) {
1034
- logger.info(` evalBinaryExpression lVal ${String(lVal)}, rVal ${String(rVal)}`);
1035
- }
1036
- if (lVal !== import_constants.FAILED_EVAL && t.isConditionalExpression(right)) {
1037
- const ternary = addBinaryConditional(operator, left, right);
1038
- if (ternary) return ternary;
1039
- }
1040
- if (rVal !== import_constants.FAILED_EVAL && t.isConditionalExpression(left)) {
1041
- const ternary = addBinaryConditional(operator, right, left);
1042
- if (ternary) return ternary;
1043
- }
1044
- if (shouldPrintDebug) {
1045
- logger.info(` evalBinaryExpression cant extract`);
1046
- }
1047
- inlined.set(name, true);
1048
- return attr;
1049
- }
1050
- const staticConditional = getStaticConditional(value);
1051
- if (staticConditional) {
1052
- if (shouldPrintDebug === "verbose") {
1053
- logger.info(` static conditional ${name} ${value}`);
1054
- }
1055
- return {
1056
- type: "ternary",
1057
- value: staticConditional
1058
- };
1059
- }
1060
- const staticLogical = getStaticLogical(value);
1061
- if (staticLogical) {
1062
- if (shouldPrintDebug === "verbose") {
1063
- logger.info(` static ternary ${name} = ${value}`);
1064
- }
1065
- return {
1066
- type: "ternary",
1067
- value: staticLogical
1068
- };
1069
- }
1070
- inlined.set(name, true);
1071
- if (shouldPrintDebug) {
1072
- logger.info(` ! inline no match ${name} ${value}`);
1073
- }
1074
- return attr;
1075
- function addBinaryConditional(operator, staticExpr, cond) {
1076
- if (getStaticConditional(cond)) {
1077
- const alt = attemptEval(t.binaryExpression(operator, staticExpr, cond.alternate));
1078
- const cons = attemptEval(t.binaryExpression(operator, staticExpr, cond.consequent));
1079
- if (shouldPrintDebug) {
1080
- logger.info([" binaryConditional", cond.test, cons, alt].join(" "));
1081
- }
1082
- return {
1083
- type: "ternary",
1084
- value: {
1085
- test: cond.test,
1086
- remove,
1087
- alternate: {
1088
- [name]: alt
1089
- },
1090
- consequent: {
1091
- [name]: cons
1092
- }
1093
- }
1094
- };
1095
- }
1096
- return null;
1097
- }
1098
- function getStaticConditional(value2) {
1099
- if (t.isConditionalExpression(value2)) {
1100
- try {
1101
- const aVal = attemptEval(value2.alternate);
1102
- const cVal = attemptEval(value2.consequent);
1103
- if (shouldPrintDebug) {
1104
- const type = value2.test.type;
1105
- logger.info([" static ternary", type, cVal, aVal].join(" "));
1106
- }
1107
- return {
1108
- test: value2.test,
1109
- remove,
1110
- consequent: {
1111
- [name]: cVal
1112
- },
1113
- alternate: {
1114
- [name]: aVal
1115
- }
1116
- };
1117
- } catch (err) {
1118
- if (shouldPrintDebug) {
1119
- logger.info([" cant eval ternary", err.message].join(" "));
1120
- }
1121
- }
1122
- }
1123
- return null;
1124
- }
1125
- function getStaticLogical(value2) {
1126
- if (t.isLogicalExpression(value2)) {
1127
- if (value2.operator === "&&") {
1128
- try {
1129
- const val = attemptEval(value2.right);
1130
- if (shouldPrintDebug) {
1131
- logger.info([" staticLogical", value2.left, name, val].join(" "));
1132
- }
1133
- return {
1134
- test: value2.left,
1135
- remove,
1136
- consequent: {
1137
- [name]: val
1138
- },
1139
- alternate: null
1140
- };
1141
- } catch (err) {
1142
- if (shouldPrintDebug) {
1143
- logger.info([" cant static eval logical", err].join(" "));
1144
- }
1145
- }
1146
- }
1147
- }
1148
- return null;
1149
- }
1150
- },
1151
- isStaticObject = function (obj) {
1152
- return t.isObjectExpression(obj) && obj.properties.every(prop => {
1153
- if (!t.isObjectProperty(prop)) {
1154
- return false;
1155
- }
1156
- const propName = prop.key["name"];
1157
- if (!isValidStyleKey(propName, staticConfig) && propName !== "render") {
1158
- if (shouldPrintDebug) {
1159
- logger.info([" not a valid style prop!", propName].join(" "));
1160
- }
1161
- return false;
1162
- }
1163
- return true;
1164
- });
1165
- },
1166
- flattenNestedTernaries = function (test, side, ternaryPartial = {}) {
1167
- if (!side) {
1168
- return null;
1169
- }
1170
- if (!isStaticObject(side)) {
1171
- throw new Error("not extractable");
1172
- }
1173
- return side.properties.flatMap(property => {
1174
- if (!t.isObjectProperty(property)) {
1175
- throw new Error("expected object property");
1176
- }
1177
- if (t.isConditionalExpression(property.value)) {
1178
- const [truthy, falsy] = [t.objectExpression([t.objectProperty(property.key, property.value.consequent)]), t.objectExpression([t.objectProperty(property.key, property.value.alternate)])].map(x => attemptEval(x));
1179
- return [createTernary({
1180
- remove() {},
1181
- ...ternaryPartial,
1182
- test: t.logicalExpression("&&", test, property.value.test),
1183
- consequent: truthy,
1184
- alternate: null
1185
- }), createTernary({
1186
- ...ternaryPartial,
1187
- test: t.logicalExpression("&&", test, t.unaryExpression("!", property.value.test)),
1188
- consequent: falsy,
1189
- alternate: null,
1190
- remove() {}
1191
- })];
1192
- }
1193
- const obj = t.objectExpression([t.objectProperty(property.key, property.value)]);
1194
- const consequent = attemptEval(obj);
1195
- return createTernary({
1196
- remove() {},
1197
- ...ternaryPartial,
1198
- test,
1199
- consequent,
1200
- alternate: null
1201
- });
1202
- });
1203
- },
1204
- mergeToEnd = function (obj, key, val) {
1205
- if (key in obj) {
1206
- delete obj[key];
1207
- }
1208
- obj[key] = val;
1209
- },
1210
- normalizeStyleWithoutVariants = function (style) {
1211
- let res2 = {};
1212
- for (const key in style) {
1213
- if (staticConfig.variants && key in staticConfig.variants) {
1214
- mergeToEnd(res2, key, style[key]);
1215
- } else {
1216
- const expanded = normalizeStyle({
1217
- [key]: style[key]
1218
- }, true);
1219
- for (const key2 in expanded) {
1220
- mergeToEnd(res2, key2, expanded[key2]);
1221
- }
1222
- }
1223
- }
1224
- return res2;
1225
- },
1226
- mergeStyles = function (prev2, next) {
1227
- for (const key in next) {
1228
- if (pseudoDescriptors[key]) {
1229
- prev2[key] = prev2[key] || {};
1230
- Object.assign(prev2[key], next[key]);
1231
- } else {
1232
- mergeToEnd(prev2, key, next[key]);
1233
- }
1234
- }
1235
- };
1236
- const {
1237
- staticConfig
1238
- } = component;
1239
- const defaultProps = {
1240
- ...getDefaultProps(staticConfig)
1241
- };
1242
- const variants = staticConfig.variants || {};
1243
- const isTextView = staticConfig.isText || false;
1244
- const validStyles = staticConfig?.validStyles ?? {};
1245
- let tagName = defaultProps.render ?? (isTextView ? "span" : "div");
1246
- traversePath.get("openingElement").get("attributes").forEach(path => {
1247
- const attr = path.node;
1248
- if (t.isJSXSpreadAttribute(attr)) return;
1249
- if (attr.name.name !== "render") return;
1250
- const val = attr.value;
1251
- if (!t.isStringLiteral(val)) return;
1252
- tagName = val.value;
1253
- });
1254
- if (shouldPrintDebug === "verbose") {
1255
- console.info(` Start tag ${tagName}`);
1256
- }
1257
- const flatNodeName = getFlattenedNode?.({
1258
- isTextView,
1259
- tag: tagName
1260
- });
1261
- const inlineProps = /* @__PURE__ */new Set([
1262
- // adding some always inline props
1263
- ...(restProps.inlineProps || []), ...(staticConfig.inlineProps || [])]);
1264
- const canFlattenTransition = isTargetingHTML && hanzoguiConfig?.animations.outputStyle === "css" && !hanzoguiConfig.animationDrivers;
1265
- const deoptProps = /* @__PURE__ */new Set([
1266
- // css-only transitions lower to ordinary css; every runtime driver
1267
- // needs the component preserved so it can respond to prop changes.
1268
- "animation", ...(canFlattenTransition ? [] : ["transition"]), "animateOnly", "animatePresence", "disableOptimization", ...(!isTargetingHTML ? [
1269
- // native has no css pseudo selectors; these are runtime-only on
1270
- // rn (event listeners + style merge in createComponent), and if
1271
- // we let them flatten into the stylesheet they get written
1272
- // under a literal key that rn treats as an unknown style prop.
1273
- // hover is intentionally excluded: it is no-op on native and
1274
- // should be dropped rather than preserved as runtime work.
1275
- "pressStyle", "focusStyle", "focusVisibleStyle", "focusWithinStyle", "disabledStyle"] : []),
1276
- // when using a non-CSS driver, de-opt on enterStyle/exitStyle
1277
- ...(hanzoguiConfig?.animations.isReactNative ? ["enterStyle", "exitStyle"] : [])]);
1278
- const inlineWhenUnflattened = new Set(staticConfig.inlineWhenUnflattened || []);
1279
- const staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
1280
- const attemptEval = !evaluateVars ? import_evaluateAstNode.evaluateAstNode : (0, import_createEvaluator.createEvaluator)({
1281
- props: propsWithFileInfo,
1282
- staticNamespace,
1283
- sourcePath,
1284
- traversePath,
1285
- shouldPrintDebug
1286
- });
1287
- const attemptEvalSafe = (0, import_createEvaluator.createSafeEvaluator)(attemptEval);
1288
- if (shouldPrintDebug) {
1289
- logger.info(` staticNamespace ${Object.keys(staticNamespace).join(", ")}`);
1290
- }
1291
- if (couldntParse) {
1292
- return;
1293
- }
1294
- tm.mark("jsx-element-flattened", !!shouldPrintDebug);
1295
- let attrs = [];
1296
- let shouldDeopt = false;
1297
- const inlined = /* @__PURE__ */new Map();
1298
- const variantValues = /* @__PURE__ */new Map();
1299
- let hasSetOptimized = false;
1300
- const inlineWhenUnflattenedOGVals = {};
1301
- const propMapperStyleState = {
1302
- staticConfig,
1303
- usedKeys: {},
1304
- classNames: {},
1305
- style: {},
1306
- theme: defaultTheme,
1307
- viewProps: defaultProps,
1308
- conf: hanzoguiConfig,
1309
- props: defaultProps,
1310
- componentState,
1311
- styleProps: {
1312
- ...styleProps,
1313
- resolveValues: "auto"
1314
- },
1315
- debug: shouldPrintDebug
1316
- };
1317
- attrs = traversePath.get("openingElement").get("attributes").flatMap(path => {
1318
- if (shouldDeopt) {
1319
- return;
1320
- }
1321
- try {
1322
- const res2 = evaluateAttribute(path);
1323
- if (!res2) {
1324
- path.remove();
1325
- }
1326
- return res2;
1327
- } catch (err) {
1328
- if (shouldPrintDebug) {
1329
- logger.info(["Recoverable error extracting attribute", err.message, shouldPrintDebug === "verbose" ? err.stack : ""].join(" "));
1330
- if (shouldPrintDebug === "verbose") {
1331
- logger.info(`node ${path.node?.type}`);
1332
- }
1333
- }
1334
- inlined.set(`${Math.random()}`, "spread");
1335
- return {
1336
- type: "attr",
1337
- value: path.node
1338
- };
1339
- }
1340
- }).flat(4).filter(import_extractHelpers.isPresent);
1341
- if (shouldPrintDebug) {
1342
- logger.info([" - attrs (before):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
1343
- }
1344
- if (couldntParse || shouldDeopt) {
1345
- if (shouldPrintDebug) {
1346
- logger.info([` avoid optimizing:`, {
1347
- couldntParse,
1348
- shouldDeopt
1349
- }].join(" "));
1350
- }
1351
- node.attributes = ogAttributes;
1352
- return;
1353
- }
1354
- const parentFn = (0, import_findTopmostFunction.findTopmostFunction)(traversePath);
1355
- if (parentFn) {
1356
- modifiedComponents.add(parentFn);
1357
- }
1358
- const hasSpread = attrs.some(x => x.type === "attr" && t.isJSXSpreadAttribute(x.value));
1359
- const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every(x => x.type === "JSXText"));
1360
- let themeVal = inlined.get("theme");
1361
- if (platform2 !== "native") {
1362
- inlined.delete("theme");
1363
- }
1364
- for (const [key] of inlined) {
1365
- const isStaticObjectVariant = staticConfig.variants?.[key] && variantValues.has(key);
1366
- if (INLINE_EXTRACTABLE[key] || isStaticObjectVariant) {
1367
- inlined.delete(key);
1368
- }
1369
- }
1370
- const canFlattenProps = inlined.size === 0;
1371
- let shouldFlatten = Boolean(flatNodeName && !shouldDeopt && canFlattenProps && !hasSpread && !staticConfig.isStyledHOC && !staticConfig.isHOC && !staticConfig.isReactNative && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true));
1372
- const usedThemeKeys = /* @__PURE__ */new Set();
1373
- themeAccessListeners.add(key => {
1374
- if (disableExtractVariables) {
1375
- usedThemeKeys.add(key);
1376
- shouldFlatten = false;
1377
- if (shouldPrintDebug === "verbose") {
1378
- logger.info([" ! accessing theme key, avoid flatten", key].join(" "));
1379
- }
1380
- }
1381
- });
1382
- if (!shouldFlatten) {
1383
- if (shouldPrintDebug) {
1384
- logger.info(`Deopting ${JSON.stringify({
1385
- shouldFlatten,
1386
- shouldDeopt,
1387
- canFlattenProps,
1388
- hasSpread,
1389
- neverFlatten: staticConfig.neverFlatten
1390
- })}`);
1391
- }
1392
- node.attributes = ogAttributes;
1393
- return;
1394
- }
1395
- let skipMap = false;
1396
- const defaultStyleAttrs = Object.keys(defaultProps).flatMap(key => {
1397
- if (skipMap) return [];
1398
- const value = defaultProps[key];
1399
- if (key === "theme" && !themeVal) {
1400
- if (platform2 === "native") {
1401
- shouldFlatten = false;
1402
- skipMap = true;
1403
- inlined.set("theme", {
1404
- value: t.stringLiteral(value)
1405
- });
1406
- }
1407
- themeVal = {
1408
- value: t.stringLiteral(value)
1409
- };
1410
- return [];
1411
- }
1412
- if (!isValidStyleKey(key, staticConfig)) {
1413
- return [];
1414
- }
1415
- const name = hanzoguiConfig?.shorthands[key] || key;
1416
- if (value === void 0) {
1417
- logger.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${key} ${value}`);
1418
- shouldDeopt = true;
1419
- return;
1420
- }
1421
- if (name[0] === "$" && mediaQueryConfig[name.slice(1)]) {
1422
- defaultProps[key] = void 0;
1423
- return evaluateAttribute({
1424
- node: t.jsxAttribute(t.jsxIdentifier(name), t.jsxExpressionContainer(t.objectExpression(Object.keys(value).filter(k => {
1425
- return typeof value[k] !== "undefined";
1426
- }).map(k => {
1427
- return t.objectProperty(t.identifier(k), (0, import_literalToAst.literalToAst)(value[k]));
1428
- }))))
1429
- });
1430
- }
1431
- const attr = {
1432
- type: "style",
1433
- name,
1434
- value: {
1435
- [name]: value
1436
- }
1437
- };
1438
- return attr;
1439
- });
1440
- if (!skipMap) {
1441
- if (defaultStyleAttrs.length) {
1442
- attrs = [...defaultStyleAttrs, ...attrs];
1443
- }
1444
- }
1445
- let ternaries = [];
1446
- attrs = attrs.reduce((out, cur) => {
1447
- const next = attrs[attrs.indexOf(cur) + 1];
1448
- if (cur.type === "ternary") {
1449
- ternaries.push(cur.value);
1450
- }
1451
- if ((!next || next.type !== "ternary") && ternaries.length) {
1452
- const normalized = (0, import_normalizeTernaries.normalizeTernaries)(ternaries).map(({
1453
- alternate,
1454
- consequent,
1455
- ...rest
1456
- }) => {
1457
- return {
1458
- type: "ternary",
1459
- value: {
1460
- ...rest,
1461
- alternate: alternate || null,
1462
- consequent: consequent || null
1463
- }
1464
- };
1465
- });
1466
- try {
1467
- return [...out, ...normalized];
1468
- } finally {
1469
- if (shouldPrintDebug) {
1470
- logger.info(` normalizeTernaries (${ternaries.length} => ${normalized.length})`);
1471
- }
1472
- ternaries = [];
1473
- }
1474
- }
1475
- if (cur.type === "ternary") {
1476
- return out;
1477
- }
1478
- out.push(cur);
1479
- return out;
1480
- }, []).flat();
1481
- if (themeVal) {
1482
- if (!programPath) {
1483
- console.warn(`No program path found, avoiding importing flattening / importing theme in ${sourcePath}`);
1484
- } else {
1485
- if (shouldPrintDebug) {
1486
- logger.info([" - wrapping theme", themeVal].join(" "));
1487
- }
1488
- attrs = attrs.filter(x => !(x.type === "attr" && t.isJSXAttribute(x.value) && x.value.name.name === "theme"));
1489
- if (!hasImportedTheme) {
1490
- hasImportedTheme = true;
1491
- programPath.node.body.push(t.importDeclaration([t.importSpecifier(t.identifier("_GuiTheme"), t.identifier("Theme"))], t.stringLiteral("@hanzogui/web")));
1492
- }
1493
- traversePath.replaceWith(t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier("_GuiTheme"), [t.jsxAttribute(t.jsxIdentifier("name"), themeVal.value)]), t.jsxClosingElement(t.jsxIdentifier("_GuiTheme")), [traversePath.node]));
1494
- }
1495
- }
1496
- if (shouldPrintDebug) {
1497
- logger.info([" - attrs (flattened): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
1498
- }
1499
- let foundStaticProps = {};
1500
- for (const key in attrs) {
1501
- const cur = attrs[key];
1502
- if (cur.type === "style") {
1503
- const expanded = normalizeStyleWithoutVariants(cur.value);
1504
- for (const key2 in expanded) {
1505
- mergeToEnd(foundStaticProps, key2, expanded[key2]);
1506
- }
1507
- continue;
1508
- }
1509
- if (cur.type === "attr") {
1510
- if (t.isJSXSpreadAttribute(cur.value)) {
1511
- continue;
1512
- }
1513
- if (!t.isJSXIdentifier(cur.value.name)) {
1514
- continue;
1515
- }
1516
- const key2 = cur.value.name.name;
1517
- const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
1518
- if (value !== import_constants.FAILED_EVAL) {
1519
- mergeToEnd(foundStaticProps, key2, value);
1520
- }
1521
- }
1522
- }
1523
- const completeProps = {};
1524
- for (const key in defaultProps) {
1525
- if (!(key in foundStaticProps)) {
1526
- completeProps[key] = defaultProps[key];
1527
- }
1528
- }
1529
- for (const key in foundStaticProps) {
1530
- completeProps[key] = foundStaticProps[key];
1531
- }
1532
- attrs = attrs.reduce((acc, cur) => {
1533
- if (!cur) return acc;
1534
- if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value)) {
1535
- if (shouldFlatten) {
1536
- const name = cur.value.name.name;
1537
- if (typeof name === "string") {
1538
- if (name === "render") {
1539
- return acc;
1540
- }
1541
- if (variants[name] && variantValues.has(name)) {
1542
- const styleState = {
1543
- ...propMapperStyleState,
1544
- props: completeProps
1545
- };
1546
- let out = {};
1547
- propMapper(name, variantValues.get(name), styleState, false, (key2, val) => {
1548
- out[key2] = val;
1549
- });
1550
- if (out && isTargetingHTML) {
1551
- const cn = out.className;
1552
- out = reactNativeWebInternals.createDOMProps(isTextView ? "span" : "div", out);
1553
- out.className = cn;
1554
- delete out.style;
1555
- }
1556
- if (shouldPrintDebug) {
1557
- logger.info([" - expanded variant", name, out].join(" "));
1558
- }
1559
- for (const key2 in out) {
1560
- const value2 = out[key2];
1561
- if (isValidStyleKey(key2, staticConfig)) {
1562
- acc.push({
1563
- type: "style",
1564
- value: {
1565
- [key2]: value2
1566
- },
1567
- name: key2,
1568
- attr: cur.value
1569
- });
1570
- } else {
1571
- acc.push({
1572
- type: "attr",
1573
- value: t.jsxAttribute(t.jsxIdentifier(key2), t.jsxExpressionContainer(typeof value2 === "string" ? t.stringLiteral(value2) : (0, import_literalToAst.literalToAst)(value2)))
1574
- });
1575
- }
1576
- }
1577
- }
1578
- }
1579
- }
1580
- }
1581
- if (cur.type !== "style") {
1582
- acc.push(cur);
1583
- return acc;
1584
- }
1585
- let key = Object.keys(cur.value)[0];
1586
- const value = cur.value[key];
1587
- const fullKey = hanzoguiConfig?.shorthands[key];
1588
- if (fullKey) {
1589
- cur.value = {
1590
- [fullKey]: value
1591
- };
1592
- key = fullKey;
1593
- }
1594
- if (disableExtractVariables) {
1595
- if (value[0] === "$" && (usedThemeKeys.has(key) || usedThemeKeys.has(fullKey))) {
1596
- if (shouldPrintDebug) {
1597
- logger.info([` keeping variable inline: ${key} =`, value].join(" "));
1598
- }
1599
- acc.push({
1600
- type: "attr",
1601
- value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.stringLiteral(value)))
1602
- });
1603
- return acc;
1604
- }
1605
- }
1606
- acc.push(cur);
1607
- return acc;
1608
- }, []);
1609
- tm.mark("jsx-element-expanded", !!shouldPrintDebug);
1610
- if (shouldPrintDebug) {
1611
- logger.info([" - attrs (expanded): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
1612
- }
1613
- let prev = null;
1614
- const getProps = (props, includeProps = false, debugName = "") => {
1615
- if (!props) {
1616
- if (shouldPrintDebug) logger.info([" getProps() no props"].join(" "));
1617
- return {};
1618
- }
1619
- if (excludeProps?.size) {
1620
- for (const key in props) {
1621
- if (excludeProps.has(key)) {
1622
- if (shouldPrintDebug) logger.info([" delete excluded", key].join(" "));
1623
- delete props[key];
1624
- }
1625
- }
1626
- }
1627
- const before = process.env.IS_STATIC;
1628
- process.env.IS_STATIC = "is_static";
1629
- try {
1630
- let extractedMediaLikeProps = null;
1631
- let propsForSplit = props;
1632
- for (const k in props) {
1633
- if (k[0] === "$" && (k.startsWith("$group-") || k.startsWith("$theme-"))) {
1634
- if (propsForSplit === props) {
1635
- propsForSplit = {
1636
- ...props
1637
- };
1638
- }
1639
- if (platform2 === "native" && k.startsWith("$group-") && getGroupPseudo(k) === "hover") {
1640
- delete propsForSplit[k];
1641
- continue;
1642
- }
1643
- extractedMediaLikeProps ||= {};
1644
- extractedMediaLikeProps[k] = propsForSplit[k];
1645
- delete propsForSplit[k];
1646
- }
1647
- }
1648
- const out = getSplitStyles(propsForSplit, staticConfig, defaultTheme, "", componentState, {
1649
- ...styleProps,
1650
- noClass: true,
1651
- fallbackProps: completeProps,
1652
- ...(platform2 === "native" && {
1653
- resolveValues: "except-theme"
1654
- })
1655
- }, void 0, void 0, void 0, void 0, false, debugPropValue || shouldPrintDebug);
1656
- if (extractedMediaLikeProps && platform2 !== "native") {
1657
- for (const k in extractedMediaLikeProps) {
1658
- const block = extractedMediaLikeProps[k];
1659
- if (!block || typeof block !== "object") continue;
1660
- const blockOut = getSplitStyles(block, staticConfig, defaultTheme, "", componentState, {
1661
- ...styleProps,
1662
- noClass: true,
1663
- fallbackProps: completeProps
1664
- }, void 0, void 0, void 0, void 0, false, debugPropValue || shouldPrintDebug);
1665
- if (blockOut) {
1666
- extractedMediaLikeProps[k] = {
1667
- ...blockOut.style,
1668
- ...blockOut.pseudos
1669
- };
1670
- }
1671
- }
1672
- }
1673
- let outProps = {
1674
- ...(includeProps ? out.viewProps : {}),
1675
- ...out.style,
1676
- ...out.pseudos,
1677
- ...extractedMediaLikeProps
1678
- };
1679
- for (const key in outProps) {
1680
- if (deoptProps.has(key)) {
1681
- shouldFlatten = false;
1682
- }
1683
- if (platform2 === "native" && key[0] === "$" && (key.startsWith("$theme-") || key.startsWith("$group-") && getGroupPseudo(key) !== "hover")) {
1684
- shouldFlatten = false;
1685
- }
1686
- }
1687
- if (shouldPrintDebug) {
1688
- logger.info(`(${debugName})`);
1689
- logger.info(`
1690
- getProps (props in): ${(0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(props))}`);
1691
- logger.info(`
1692
- getProps (outProps): ${(0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(outProps))}`);
1693
- }
1694
- if (out.fontFamily) {
1695
- (0, import_propsToFontFamilyCache.setPropsToFontFamily)(outProps, out.fontFamily);
1696
- if (shouldPrintDebug) {
1697
- logger.info(`
1698
- \u{1F4AC} new font fam: ${out.fontFamily}`);
1699
- }
1700
- }
1701
- return outProps;
1702
- } catch (err) {
1703
- logger.info(["error", err.message, err.stack].join(" "));
1704
- return {};
1705
- } finally {
1706
- process.env.IS_STATIC = before;
1707
- }
1708
- };
1709
- attrs.unshift({
1710
- type: "style",
1711
- value: defaultProps
1712
- });
1713
- attrs = attrs.reduce((acc, cur) => {
1714
- if (cur.type === "style") {
1715
- const keys = Object.keys(cur.value || {});
1716
- if (!keys.length) {
1717
- return acc;
1718
- }
1719
- const key = keys[0];
1720
- const value = cur.value[key];
1721
- const isMediaLikeKey = key[0] === "$" && (key.startsWith("$theme-") || key.startsWith("$platform-") || key.startsWith("$group-") || mediaQueryConfig[key.slice(1)]);
1722
- const shouldKeepOriginalAttr =
1723
- // !isStyleAndAttr[key] &&
1724
- !shouldFlatten &&
1725
- // de-opt if non-style
1726
- !validStyles[key] && !pseudoDescriptors[key] && !isMediaLikeKey && !(key.startsWith("data-") || key.startsWith("aria-"));
1727
- if (shouldKeepOriginalAttr) {
1728
- if (shouldPrintDebug) {
1729
- logger.info([" - keeping as non-style", key].join(" "));
1730
- }
1731
- prev = cur;
1732
- acc.push({
1733
- type: "attr",
1734
- value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(typeof value === "string" ? t.stringLiteral(value) : (0, import_literalToAst.literalToAst)(value)))
1735
- });
1736
- acc.push(cur);
1737
- return acc;
1738
- }
1739
- if (prev?.type === "style") {
1740
- mergeStyles(prev.value, cur.value);
1741
- return acc;
1742
- }
1743
- }
1744
- if (cur.type === "style") {
1745
- prev = cur;
1746
- }
1747
- acc.push(cur);
1748
- return acc;
1749
- }, []);
1750
- if (shouldPrintDebug) {
1751
- logger.info([" - attrs (combined \u{1F500}): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
1752
- }
1753
- let getStyleError = null;
1754
- for (const attr of attrs) {
1755
- try {
1756
- if (shouldPrintDebug) {
1757
- console.info(` Processing ${attr.type}:`);
1758
- }
1759
- switch (attr.type) {
1760
- case "ternary":
1761
- {
1762
- const a = getProps(attr.value.alternate, false, "ternary.alternate");
1763
- const c = getProps(attr.value.consequent, false, "ternary.consequent");
1764
- if (a) attr.value.alternate = a;
1765
- if (c) attr.value.consequent = c;
1766
- if (shouldPrintDebug) logger.info([" => tern ", (0, import_extractHelpers.attrStr)(attr)].join(" "));
1767
- continue;
1768
- }
1769
- case "style":
1770
- {
1771
- const styles = getProps(attr.value, false, "style");
1772
- if (styles) {
1773
- attr.value = styles;
1774
- }
1775
- if (shouldPrintDebug) logger.info([" * styles (in)", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(attr.value))].join(" "));
1776
- if (shouldPrintDebug) logger.info([" * styles (out)", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(styles))].join(" "));
1777
- continue;
1778
- }
1779
- case "attr":
1780
- {
1781
- if (shouldFlatten && t.isJSXAttribute(attr.value)) {
1782
- const key = attr.value.name.name;
1783
- if (key === "style" || key === "className" || key === "render") {
1784
- continue;
1785
- }
1786
- const value = attemptEvalSafe(attr.value.value || t.booleanLiteral(true));
1787
- if (value !== import_constants.FAILED_EVAL) {
1788
- const outProps = getProps({
1789
- [key]: value
1790
- }, true, `attr.${key}`);
1791
- const outKey = Object.keys(outProps)[0];
1792
- if (outKey) {
1793
- const outVal = outProps[outKey];
1794
- attr.value = t.jsxAttribute(t.jsxIdentifier(outKey), t.jsxExpressionContainer(typeof outVal === "string" ? t.stringLiteral(outVal) : (0, import_literalToAst.literalToAst)(outVal)));
1795
- }
1796
- }
1797
- }
1798
- }
1799
- }
1800
- } catch (err) {
1801
- getStyleError = err;
1802
- }
1803
- }
1804
- if (shouldPrintDebug) {
1805
- logger.info([" - attrs (ternaries/combined):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
1806
- }
1807
- tm.mark("jsx-element-styles", !!shouldPrintDebug);
1808
- if (getStyleError) {
1809
- logger.info([" \u26A0\uFE0F postprocessing error, deopt", getStyleError].join(" "));
1810
- node.attributes = ogAttributes;
1811
- return null;
1812
- }
1813
- const existingStyleKeys = /* @__PURE__ */new Set();
1814
- for (let i = attrs.length - 1; i >= 0; i--) {
1815
- const attr = attrs[i];
1816
- if (shouldFlatten) {
1817
- if (attr.type === "attr") {
1818
- if (t.isJSXAttribute(attr.value)) {
1819
- if (t.isJSXIdentifier(attr.value.name)) {
1820
- const name = attr.value.name.name;
1821
- if (INLINE_EXTRACTABLE[name]) {
1822
- attr.value.name.name = INLINE_EXTRACTABLE[name];
1823
- }
1824
- }
1825
- }
1826
- }
1827
- }
1828
- if (attr.type === "style") {
1829
- for (const key in attr.value) {
1830
- if (existingStyleKeys.has(key)) {
1831
- if (shouldPrintDebug) {
1832
- logger.info([` >> delete existing ${key}`].join(" "));
1833
- }
1834
- delete attr.value[key];
1835
- } else {
1836
- existingStyleKeys.add(key);
1837
- }
1838
- }
1839
- }
1840
- }
1841
- attrs = attrs.filter(Boolean);
1842
- if (!shouldFlatten) {
1843
- if (inlineWhenUnflattened.size) {
1844
- for (const [index, attr] of attrs.entries()) {
1845
- if (attr.type === "style") {
1846
- for (const key in attr.value) {
1847
- if (!inlineWhenUnflattened.has(key)) continue;
1848
- const val = inlineWhenUnflattenedOGVals[key];
1849
- if (val) {
1850
- delete attr.value[key];
1851
- attrs.splice(index - 1, 0, val.attr);
1852
- } else {
1853
- delete attr.value[key];
1854
- }
1855
- }
1856
- }
1857
- }
1858
- }
1859
- }
1860
- attrs = attrs.filter(x => {
1861
- if (x.type === "style" && Object.keys(x.value).length === 0) {
1862
- return false;
1863
- }
1864
- return true;
1865
- });
1866
- const isNativeNotFlat = !shouldFlatten && platform2 === "native";
1867
- if (isNativeNotFlat) {
1868
- if (shouldPrintDebug) {
1869
- logger.info(`Disabled flattening except for simple cases on native for now: ${JSON.stringify({
1870
- flatNode: flatNodeName,
1871
- shouldDeopt,
1872
- canFlattenProps,
1873
- hasSpread,
1874
- "staticConfig.isStyledHOC": staticConfig.isStyledHOC,
1875
- "!staticConfig.isHOC": !staticConfig.isHOC,
1876
- "staticConfig.isReactNative": staticConfig.isReactNative,
1877
- "staticConfig.neverFlatten": staticConfig.neverFlatten
1878
- }, null, 2)}`);
1879
- }
1880
- node.attributes = ogAttributes;
1881
- return null;
1882
- }
1883
- if (shouldPrintDebug) {
1884
- logger.info([` - inlined props (${inlined.size}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : ""].join(" "));
1885
- logger.info(` - attrs (end):
1886
- ${(0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))}`);
1887
- }
1888
- onExtractTag({
1889
- parserProps: propsWithFileInfo,
1890
- attrs,
1891
- node,
1892
- lineNumbers,
1893
- filePath,
1894
- config: hanzoguiConfig,
1895
- flatNodeName,
1896
- attemptEval,
1897
- jsxPath: traversePath,
1898
- originalNodeName,
1899
- programPath,
1900
- completeProps,
1901
- staticConfig
1902
- });
1903
- if (shouldFlatten) {
1904
- if (shouldPrintDebug) {
1905
- logger.info([" [\u2705] flattened", originalNodeName, flatNodeName].join(" "));
1906
- }
1907
- const currentName = node.name?.name;
1908
- if (!currentName || currentName === originalNodeName || currentName.startsWith("__ReactNative")) {
1909
- node.name.name = flatNodeName;
1910
- if (closingElement) {
1911
- closingElement.name.name = flatNodeName;
1912
- }
1913
- }
1914
- res.flattened++;
1915
- }
1916
- } catch (err) {
1917
- node.attributes = ogAttributes;
1918
- if (!(err instanceof import_errors.BailOptimizationError)) {
1919
- console.error(`@hanzogui/static error, reverting optimization. In ${filePath} ${lineNumbers} on ${originalNodeName}: ${err.message}. For stack trace set environment GUI_DEBUG=1`);
1920
- if (process.env.GUI_DEBUG === "1") {
1921
- console.error(err.stack);
1922
- }
1923
- }
1924
- } finally {
1925
- if (debugPropValue) {
1926
- shouldPrintDebug = ogDebug;
1927
- }
1928
- }
1929
- }
1930
- });
1931
- tm.mark("jsx-done", !!shouldPrintDebug);
1932
- tm.done(shouldPrintDebug === "verbose");
1933
- return res;
1934
- }
1935
- }