boss-css 0.0.1 → 0.0.3

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 (268) hide show
  1. package/README.md +1 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +43 -0
  3. package/dist/_virtual/rolldown_runtime.mjs +20 -0
  4. package/dist/api/browser.cjs +54 -0
  5. package/dist/api/browser.mjs +48 -0
  6. package/dist/api/config.cjs +94 -0
  7. package/dist/api/config.mjs +91 -0
  8. package/dist/api/css.cjs +304 -0
  9. package/dist/api/css.mjs +303 -0
  10. package/dist/api/dictionary.cjs +218 -0
  11. package/dist/api/dictionary.mjs +215 -0
  12. package/dist/api/file/dts.cjs +21 -0
  13. package/dist/api/file/dts.mjs +21 -0
  14. package/dist/api/file/file.cjs +123 -0
  15. package/dist/api/file/file.mjs +120 -0
  16. package/dist/api/file/js.cjs +118 -0
  17. package/dist/api/file/js.mjs +116 -0
  18. package/dist/api/names.cjs +52 -0
  19. package/dist/api/names.mjs +46 -0
  20. package/dist/api/noopCss.cjs +37 -0
  21. package/dist/api/noopCss.mjs +36 -0
  22. package/dist/api/propTree.cjs +54 -0
  23. package/dist/api/propTree.mjs +48 -0
  24. package/dist/api/server.cjs +112 -0
  25. package/dist/api/server.mjs +106 -0
  26. package/dist/cli/build.cjs +1 -0
  27. package/dist/cli/build.mjs +3 -0
  28. package/dist/cli/index.cjs +30 -0
  29. package/dist/cli/index.mjs +29 -0
  30. package/dist/cli/tasks/build.cjs +24 -0
  31. package/dist/cli/tasks/build.mjs +23 -0
  32. package/dist/cli/tasks/choose.cjs +47 -0
  33. package/dist/cli/tasks/choose.mjs +46 -0
  34. package/dist/cli/tasks/compile.cjs +68 -0
  35. package/dist/cli/tasks/compile.mjs +67 -0
  36. package/dist/cli/tasks/dev.cjs +51 -0
  37. package/dist/cli/tasks/dev.mjs +48 -0
  38. package/dist/cli/tasks/init.cjs +1835 -0
  39. package/dist/cli/tasks/init.mjs +1831 -0
  40. package/dist/cli/tasks/watch.cjs +38 -0
  41. package/dist/cli/tasks/watch.mjs +37 -0
  42. package/dist/cli/templates/init.cjs +82 -0
  43. package/dist/cli/templates/init.mjs +78 -0
  44. package/dist/cli/types.cjs +13 -0
  45. package/dist/cli/types.mjs +13 -0
  46. package/dist/cli/utils.cjs +43 -0
  47. package/dist/cli/utils.mjs +41 -0
  48. package/dist/compile/classname-strategy.cjs +79 -0
  49. package/dist/compile/classname-strategy.mjs +77 -0
  50. package/dist/compile/classname.cjs +366 -0
  51. package/dist/compile/classname.mjs +360 -0
  52. package/dist/compile/index.cjs +238 -0
  53. package/dist/compile/index.mjs +235 -0
  54. package/dist/compile/jsx.cjs +803 -0
  55. package/dist/compile/jsx.mjs +800 -0
  56. package/dist/compile/prepared.cjs +88 -0
  57. package/dist/compile/prepared.mjs +87 -0
  58. package/dist/compile/runtime.cjs +33 -0
  59. package/dist/compile/runtime.mjs +32 -0
  60. package/dist/compile/transform.cjs +371 -0
  61. package/dist/compile/transform.mjs +369 -0
  62. package/dist/cx/index.cjs +93 -0
  63. package/dist/cx/index.mjs +85 -0
  64. package/dist/detect-fw/index.cjs +384 -0
  65. package/dist/detect-fw/index.mjs +379 -0
  66. package/dist/dev/client.cjs +39 -0
  67. package/dist/dev/client.mjs +38 -0
  68. package/dist/dev/plugin/browser.cjs +11 -0
  69. package/dist/dev/plugin/browser.mjs +9 -0
  70. package/dist/dev/plugin/server.cjs +86 -0
  71. package/dist/dev/plugin/server.mjs +78 -0
  72. package/dist/dev/port.cjs +46 -0
  73. package/dist/dev/port.mjs +43 -0
  74. package/dist/dev/runtime.cjs +28 -0
  75. package/dist/dev/runtime.mjs +29 -0
  76. package/dist/dev/server.cjs +808 -0
  77. package/dist/dev/server.mjs +805 -0
  78. package/dist/dev/shared.cjs +6 -0
  79. package/dist/dev/shared.mjs +5 -0
  80. package/dist/eslint-plugin/index.cjs +66 -0
  81. package/dist/eslint-plugin/index.mjs +66 -0
  82. package/dist/eslint-plugin/rules/classnames-only.cjs +68 -0
  83. package/dist/eslint-plugin/rules/classnames-only.mjs +68 -0
  84. package/dist/eslint-plugin/rules/format-classnames.cjs +137 -0
  85. package/dist/eslint-plugin/rules/format-classnames.mjs +136 -0
  86. package/dist/eslint-plugin/rules/no-unknown-classes.cjs +119 -0
  87. package/dist/eslint-plugin/rules/no-unknown-classes.mjs +119 -0
  88. package/dist/eslint-plugin/rules/prefer-classnames.cjs +69 -0
  89. package/dist/eslint-plugin/rules/prefer-classnames.mjs +69 -0
  90. package/dist/eslint-plugin/rules/prefer-token-values.cjs +197 -0
  91. package/dist/eslint-plugin/rules/prefer-token-values.mjs +197 -0
  92. package/dist/eslint-plugin/rules/props-only.cjs +115 -0
  93. package/dist/eslint-plugin/rules/props-only.mjs +115 -0
  94. package/dist/eslint-plugin/rules/redundant-cx.cjs +66 -0
  95. package/dist/eslint-plugin/rules/redundant-cx.mjs +66 -0
  96. package/dist/eslint-plugin/rules/require-prop-functions.cjs +130 -0
  97. package/dist/eslint-plugin/rules/require-prop-functions.mjs +130 -0
  98. package/dist/eslint-plugin/utils/api.cjs +30 -0
  99. package/dist/eslint-plugin/utils/api.mjs +29 -0
  100. package/dist/eslint-plugin/utils/ast.cjs +119 -0
  101. package/dist/eslint-plugin/utils/ast.mjs +112 -0
  102. package/dist/eslint-plugin/utils/boss-classes.cjs +185 -0
  103. package/dist/eslint-plugin/utils/boss-classes.mjs +175 -0
  104. package/dist/eslint-plugin/utils/defaults.cjs +99 -0
  105. package/dist/eslint-plugin/utils/defaults.mjs +93 -0
  106. package/dist/eslint-plugin/utils/format.cjs +20 -0
  107. package/dist/eslint-plugin/utils/format.mjs +19 -0
  108. package/dist/eslint-plugin/utils/order.cjs +76 -0
  109. package/dist/eslint-plugin/utils/order.mjs +76 -0
  110. package/dist/eslint-plugin/utils/property-order.cjs +449 -0
  111. package/dist/eslint-plugin/utils/property-order.mjs +448 -0
  112. package/dist/eslint-plugin/utils/static.cjs +36 -0
  113. package/dist/eslint-plugin/utils/static.mjs +35 -0
  114. package/dist/fontsource/directory.cjs +39588 -0
  115. package/dist/fontsource/directory.mjs +39587 -0
  116. package/dist/fontsource/server.cjs +291 -0
  117. package/dist/fontsource/server.mjs +282 -0
  118. package/dist/index.cjs +10 -0
  119. package/dist/index.mjs +6 -0
  120. package/dist/log/browser.cjs +28 -0
  121. package/dist/log/browser.mjs +28 -0
  122. package/dist/log/server.cjs +32 -0
  123. package/dist/log/server.mjs +30 -0
  124. package/dist/merge/index.cjs +590 -0
  125. package/dist/merge/index.mjs +586 -0
  126. package/dist/native/browser.cjs +78 -0
  127. package/dist/native/browser.mjs +77 -0
  128. package/dist/native/server.cjs +180 -0
  129. package/dist/native/server.mjs +176 -0
  130. package/dist/native/styleTypes.cjs +168 -0
  131. package/dist/native/styleTypes.mjs +164 -0
  132. package/dist/parser/classname/server.cjs +239 -0
  133. package/dist/parser/classname/server.mjs +232 -0
  134. package/dist/parser/jsx/browser.cjs +66 -0
  135. package/dist/parser/jsx/browser.mjs +63 -0
  136. package/dist/parser/jsx/extractCode.cjs +99 -0
  137. package/dist/parser/jsx/extractCode.mjs +98 -0
  138. package/dist/parser/jsx/extractPrepared.cjs +123 -0
  139. package/dist/parser/jsx/extractPrepared.mjs +122 -0
  140. package/dist/parser/jsx/extractProps.cjs +234 -0
  141. package/dist/parser/jsx/extractProps.mjs +232 -0
  142. package/dist/parser/jsx/isDOMProp.cjs +17 -0
  143. package/dist/parser/jsx/isDOMProp.mjs +15 -0
  144. package/dist/parser/jsx/native.cjs +110 -0
  145. package/dist/parser/jsx/native.mjs +108 -0
  146. package/dist/parser/jsx/runtime.cjs +4 -0
  147. package/dist/parser/jsx/runtime.mjs +3 -0
  148. package/dist/parser/jsx/server.cjs +278 -0
  149. package/dist/parser/jsx/server.mjs +268 -0
  150. package/dist/postcss/index.cjs +16 -0
  151. package/dist/postcss/index.mjs +16 -0
  152. package/dist/prop/at/runtime-only.cjs +90 -0
  153. package/dist/prop/at/runtime-only.mjs +88 -0
  154. package/dist/prop/at/server.cjs +282 -0
  155. package/dist/prop/at/server.mjs +268 -0
  156. package/dist/prop/at/shared.cjs +153 -0
  157. package/dist/prop/at/shared.mjs +144 -0
  158. package/dist/prop/bosswind/browser.cjs +18 -0
  159. package/dist/prop/bosswind/browser.mjs +16 -0
  160. package/dist/prop/bosswind/runtime-only.cjs +18 -0
  161. package/dist/prop/bosswind/runtime-only.mjs +16 -0
  162. package/dist/prop/bosswind/server.cjs +81 -0
  163. package/dist/prop/bosswind/server.mjs +72 -0
  164. package/dist/prop/bosswind/shared.cjs +861 -0
  165. package/dist/prop/bosswind/shared.mjs +855 -0
  166. package/dist/prop/bosswind/tailwind-theme.cjs +703 -0
  167. package/dist/prop/bosswind/tailwind-theme.mjs +702 -0
  168. package/dist/prop/child/runtime-only.cjs +18 -0
  169. package/dist/prop/child/runtime-only.mjs +15 -0
  170. package/dist/prop/child/server.cjs +81 -0
  171. package/dist/prop/child/server.mjs +72 -0
  172. package/dist/prop/css/getDtsTemplate.cjs +65 -0
  173. package/dist/prop/css/getDtsTemplate.mjs +63 -0
  174. package/dist/prop/css/runtime-only.cjs +14 -0
  175. package/dist/prop/css/runtime-only.mjs +13 -0
  176. package/dist/prop/css/server.cjs +99 -0
  177. package/dist/prop/css/server.mjs +90 -0
  178. package/dist/prop/pseudo/runtime-only.cjs +23 -0
  179. package/dist/prop/pseudo/runtime-only.mjs +21 -0
  180. package/dist/prop/pseudo/server.cjs +91 -0
  181. package/dist/prop/pseudo/server.mjs +82 -0
  182. package/dist/prop/pseudo/shared.cjs +61 -0
  183. package/dist/prop/pseudo/shared.mjs +60 -0
  184. package/dist/reset/server.cjs +34 -0
  185. package/dist/reset/server.mjs +26 -0
  186. package/dist/runtime/index.cjs +119 -0
  187. package/dist/runtime/index.mjs +118 -0
  188. package/dist/runtime/preact.cjs +4 -0
  189. package/dist/runtime/preact.mjs +3 -0
  190. package/dist/runtime/qwik.cjs +21 -0
  191. package/dist/runtime/qwik.mjs +18 -0
  192. package/dist/runtime/react.cjs +4 -0
  193. package/dist/runtime/react.mjs +3 -0
  194. package/dist/runtime/solid.cjs +15 -0
  195. package/dist/runtime/solid.mjs +14 -0
  196. package/dist/runtime/stencil.cjs +25 -0
  197. package/dist/runtime/stencil.mjs +21 -0
  198. package/dist/runtime/style.cjs +14 -0
  199. package/dist/runtime/style.mjs +13 -0
  200. package/dist/shared/boundaries.cjs +288 -0
  201. package/dist/shared/boundaries.mjs +285 -0
  202. package/dist/shared/customCss.cjs +212 -0
  203. package/dist/shared/customCss.mjs +211 -0
  204. package/dist/shared/debug.cjs +76 -0
  205. package/dist/shared/debug.mjs +74 -0
  206. package/dist/shared/file.cjs +21 -0
  207. package/dist/shared/file.mjs +19 -0
  208. package/dist/shared/framework.cjs +10 -0
  209. package/dist/shared/framework.mjs +9 -0
  210. package/dist/shared/json.cjs +58 -0
  211. package/dist/shared/json.mjs +57 -0
  212. package/dist/shared/types.cjs +11 -0
  213. package/dist/shared/types.mjs +10 -0
  214. package/dist/strategy/classic/runtime-only.cjs +190 -0
  215. package/dist/strategy/classic/runtime-only.mjs +186 -0
  216. package/dist/strategy/classname-first/runtime-only.cjs +138 -0
  217. package/dist/strategy/classname-first/runtime-only.mjs +134 -0
  218. package/dist/strategy/classname-first/server.cjs +139 -0
  219. package/dist/strategy/classname-first/server.mjs +133 -0
  220. package/dist/strategy/classname-only/server.cjs +43 -0
  221. package/dist/strategy/classname-only/server.mjs +35 -0
  222. package/dist/strategy/inline-first/browser.cjs +61 -0
  223. package/dist/strategy/inline-first/browser.mjs +58 -0
  224. package/dist/strategy/inline-first/runtime-only.cjs +159 -0
  225. package/dist/strategy/inline-first/runtime-only.mjs +155 -0
  226. package/dist/strategy/inline-first/server.cjs +92 -0
  227. package/dist/strategy/inline-first/server.mjs +83 -0
  228. package/dist/strategy/runtime/runtime-only.cjs +24 -0
  229. package/dist/strategy/runtime/runtime-only.mjs +22 -0
  230. package/dist/strategy/runtime/server.cjs +72 -0
  231. package/dist/strategy/runtime/server.mjs +63 -0
  232. package/dist/strategy/runtime-only/css.cjs +183 -0
  233. package/dist/strategy/runtime-only/css.mjs +181 -0
  234. package/dist/tasks/build.cjs +88 -0
  235. package/dist/tasks/build.mjs +84 -0
  236. package/dist/tasks/compile.cjs +12 -0
  237. package/dist/tasks/compile.mjs +12 -0
  238. package/dist/tasks/postcss.cjs +116 -0
  239. package/dist/tasks/postcss.mjs +113 -0
  240. package/dist/tasks/session.cjs +46 -0
  241. package/dist/tasks/session.mjs +42 -0
  242. package/dist/tasks/watch.cjs +102 -0
  243. package/dist/tasks/watch.mjs +99 -0
  244. package/dist/transform/cache.cjs +24 -0
  245. package/dist/transform/cache.mjs +21 -0
  246. package/dist/transform/processFile.cjs +26 -0
  247. package/dist/transform/processFile.mjs +24 -0
  248. package/dist/use/token/browser.cjs +65 -0
  249. package/dist/use/token/browser.mjs +61 -0
  250. package/dist/use/token/runtime-only.cjs +245 -0
  251. package/dist/use/token/runtime-only.mjs +239 -0
  252. package/dist/use/token/server.cjs +325 -0
  253. package/dist/use/token/server.mjs +313 -0
  254. package/dist/use/token/vars.cjs +47 -0
  255. package/dist/use/token/vars.mjs +46 -0
  256. package/package.json +300 -4
  257. package/src/api/config.d.ts +1 -0
  258. package/src/fontsource/types.d.ts +50 -0
  259. package/src/packages/document-create-element/createElement.browser.js +3 -0
  260. package/src/packages/document-create-element/createElement.js +7 -0
  261. package/src/packages/document-create-element/package.json +17 -0
  262. package/src/packages/is-css-prop/browser.js +13 -0
  263. package/src/packages/is-css-prop/index.js +13 -0
  264. package/src/packages/is-css-prop/package-lock.json +52 -0
  265. package/src/packages/is-css-prop/package.json +17 -0
  266. package/src/prop/css/csstype.json +4387 -0
  267. package/src/prop/css/package.json +3 -0
  268. package/src/reset/reset.css +259 -0
@@ -0,0 +1,803 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_vars = require('../use/token/vars.cjs');
3
+ let _swc_core = require("@swc/core");
4
+
5
+ //#region src/compile/jsx.ts
6
+ const preservedAttrs = new Set(["key", "ref"]);
7
+ const fallbackSpan = {
8
+ start: 0,
9
+ end: 0,
10
+ ctxt: 0
11
+ };
12
+ const ensureSpan = (span) => {
13
+ if (!span) return fallbackSpan;
14
+ return typeof span.ctxt === "number" ? span : {
15
+ ...span,
16
+ ctxt: 0
17
+ };
18
+ };
19
+ const getSpan = (node) => {
20
+ if (node && typeof node === "object" && "span" in node) return ensureSpan(node.span);
21
+ return fallbackSpan;
22
+ };
23
+ const createJsxAttribute = (name, value, span) => {
24
+ const safeSpan = ensureSpan(span);
25
+ return {
26
+ type: "JSXAttribute",
27
+ span: safeSpan,
28
+ name: {
29
+ type: "Identifier",
30
+ value: name,
31
+ span: safeSpan,
32
+ optional: false
33
+ },
34
+ value
35
+ };
36
+ };
37
+ const createJsxExpressionContainer = (expression, span) => {
38
+ return {
39
+ type: "JSXExpressionContainer",
40
+ span: ensureSpan(span),
41
+ expression
42
+ };
43
+ };
44
+ async function transformJsxElement(node, state, context) {
45
+ const opening = node.opening;
46
+ const name = opening.name;
47
+ const bossElement = getBossElement(name);
48
+ const classNameProp = state.classNameProp ?? "className";
49
+ if (!bossElement) return node;
50
+ let prepared = null;
51
+ if (bossElement.isPrepared) {
52
+ prepared = state.preparedLocal.get(bossElement.tagName) ?? state.preparedGlobal.get(bossElement.tagName) ?? null;
53
+ if (!prepared) {
54
+ state.needsRuntime = true;
55
+ return node;
56
+ }
57
+ }
58
+ if (opening.attributes.some((attr) => attr.type === "SpreadElement") && !state.compile.spread) {
59
+ state.needsRuntime = true;
60
+ return node;
61
+ }
62
+ const { tagName } = bossElement;
63
+ const fallbackTag = prepared ? "div" : tagName;
64
+ const { tag, asAttribute, asExpression } = resolveTagFromAs(opening.attributes, fallbackTag, prepared?.asExpression);
65
+ const { tree, passthroughAttributes, tokensProp } = buildPropTree(opening.attributes, asAttribute, state, classNameProp, prepared?.tree);
66
+ await state.api.trigger("onPropTree", {
67
+ input: state.api.propTreeToObject(tree),
68
+ tree,
69
+ preferVariables: true,
70
+ parser: "jsx",
71
+ file: { path: state.filename }
72
+ }, (plugin) => plugin.name === "token");
73
+ const cssTree = structuredClone(tree);
74
+ await state.api.trigger("onPropTree", {
75
+ input: state.api.propTreeToObject(cssTree),
76
+ tree: cssTree,
77
+ preferVariables: true,
78
+ parser: "jsx",
79
+ file: { path: state.filename }
80
+ });
81
+ const hasInlineFirst = state.api.plugins.some((plugin) => plugin.name === "inline-first");
82
+ const hasClassnameFirst = state.api.plugins.some((plugin) => plugin.name === "classname-first");
83
+ if (!hasInlineFirst && !hasClassnameFirst) throw new Error("compile: only inline-first or classname-first strategies are supported right now");
84
+ const { classNames, styleProps } = hasClassnameFirst ? buildClassnameFirstOutput(tree, tag, state) : buildInlineFirstOutput(tree, tag, state);
85
+ const classNameValue = Array.from(classNames).join(" ").trim();
86
+ const tagSpan = ensureSpan(opening.span);
87
+ const existingClassName = findAttribute(opening.attributes, classNameProp);
88
+ const existingStyle = findAttribute(opening.attributes, "style");
89
+ const tokensExpression = buildTokenVarsExpression(tokensProp, state, tagSpan);
90
+ const nextAttributes = [];
91
+ const passthroughSet = new Set(passthroughAttributes);
92
+ for (const attr of opening.attributes) {
93
+ if (attr.type === "SpreadElement") {
94
+ nextAttributes.push(attr);
95
+ continue;
96
+ }
97
+ if (attr.type !== "JSXAttribute") continue;
98
+ const attrName = attributeName(attr.name);
99
+ if (!attrName) continue;
100
+ if (attrName === "style" || attrName === "as") continue;
101
+ if (attrName === classNameProp) continue;
102
+ if (preservedAttrs.has(attrName) || passthroughSet.has(attr)) nextAttributes.push(attr);
103
+ }
104
+ const mergedClassName = mergeClassName(existingClassName, classNameValue, tagSpan, classNameProp);
105
+ if (mergedClassName) nextAttributes.push(mergedClassName);
106
+ const mergedStyle = mergeStyle(existingStyle, styleProps, tagSpan);
107
+ const finalStyle = tokensExpression ? appendStyle(mergedStyle, tokensExpression, tagSpan) : mergedStyle;
108
+ if (finalStyle) nextAttributes.push(finalStyle);
109
+ opening.attributes = nextAttributes;
110
+ opening.name = toJsxIdentifier(tag, tagSpan);
111
+ if (node.closing) node.closing.name = toJsxIdentifier(tag, ensureSpan(node.closing.span));
112
+ state.replacedElements += 1;
113
+ if (asExpression) return wrapDynamicAs(node, asExpression, tagSpan, context);
114
+ return node;
115
+ }
116
+ const getBossElement = (name) => {
117
+ if (name.type === "Identifier" && name.value === "$$") return {
118
+ tagName: "div",
119
+ isPrepared: false
120
+ };
121
+ if (name.type === "JSXMemberExpression" && name.object.type === "Identifier" && name.object.value === "$$") {
122
+ const tagName = name.property.value;
123
+ return {
124
+ tagName,
125
+ isPrepared: /^[A-Z]/.test(tagName)
126
+ };
127
+ }
128
+ return null;
129
+ };
130
+ const resolveTagFromAs = (attributes, fallback, preparedAs) => {
131
+ const asAttribute = findAttribute(attributes, "as");
132
+ if (!asAttribute && !preparedAs) return {
133
+ tag: fallback,
134
+ asAttribute: null,
135
+ asExpression: null
136
+ };
137
+ if (asAttribute) {
138
+ const attrValue = asAttribute.value;
139
+ if (!attrValue) return {
140
+ tag: fallback,
141
+ asAttribute,
142
+ asExpression: null
143
+ };
144
+ if (attrValue.type === "StringLiteral") return {
145
+ tag: attrValue.value,
146
+ asAttribute,
147
+ asExpression: null
148
+ };
149
+ if (attrValue.type === "JSXExpressionContainer") {
150
+ const expression = attrValue.expression;
151
+ if (expression.type === "StringLiteral") return {
152
+ tag: expression.value,
153
+ asAttribute,
154
+ asExpression: null
155
+ };
156
+ if (expression.type === "TemplateLiteral" && expression.expressions.length === 0) return {
157
+ tag: expression.quasis[0].cooked ?? "",
158
+ asAttribute,
159
+ asExpression: null
160
+ };
161
+ return {
162
+ tag: fallback,
163
+ asAttribute,
164
+ asExpression: expression
165
+ };
166
+ }
167
+ }
168
+ if (preparedAs) {
169
+ if (preparedAs.type === "StringLiteral") return {
170
+ tag: preparedAs.value,
171
+ asAttribute: null,
172
+ asExpression: null
173
+ };
174
+ if (preparedAs.type === "TemplateLiteral" && preparedAs.expressions.length === 0) return {
175
+ tag: preparedAs.quasis[0].cooked ?? "",
176
+ asAttribute: null,
177
+ asExpression: null
178
+ };
179
+ return {
180
+ tag: fallback,
181
+ asAttribute: null,
182
+ asExpression: preparedAs
183
+ };
184
+ }
185
+ return {
186
+ tag: fallback,
187
+ asAttribute: null,
188
+ asExpression: null
189
+ };
190
+ };
191
+ const buildPropTree = (attributes, asAttribute, state, classNameProp, baseTree) => {
192
+ const tree = baseTree ? structuredClone(baseTree) : {};
193
+ const passthroughAttributes = [];
194
+ let tokensProp = null;
195
+ for (const attr of attributes) {
196
+ if (attr.type !== "JSXAttribute") continue;
197
+ if (attr === asAttribute) continue;
198
+ const name = attributeName(attr.name);
199
+ if (!name) continue;
200
+ if (name === "style" || preservedAttrs.has(name) || name === classNameProp) continue;
201
+ if (name === "tokens") {
202
+ const parsed$1 = parseAttributeValue(attr.value);
203
+ if (parsed$1) tokensProp = tokensProp ? mergePropValues(tokensProp, parsed$1) : parsed$1;
204
+ continue;
205
+ }
206
+ if (!state.api.dictionary.resolve(name).descriptor) {
207
+ passthroughAttributes.push(attr);
208
+ continue;
209
+ }
210
+ const parsed = parseAttributeValue(attr.value);
211
+ if (!parsed) continue;
212
+ tree[name] = mergePropValues(tree[name], parsed);
213
+ }
214
+ return {
215
+ tree,
216
+ passthroughAttributes,
217
+ tokensProp
218
+ };
219
+ };
220
+ const parseAttributeValue = (value) => {
221
+ if (!value) return {
222
+ dynamic: false,
223
+ value: true
224
+ };
225
+ if (value.type === "StringLiteral") return {
226
+ dynamic: false,
227
+ value: value.value
228
+ };
229
+ if (value.type === "JSXExpressionContainer") return parseExpressionValue(value.expression);
230
+ return {
231
+ dynamic: true,
232
+ value: null
233
+ };
234
+ };
235
+ const mergePropValues = (base, next) => {
236
+ if (!base) return next;
237
+ const baseValue = base.value;
238
+ const nextValue = next.value;
239
+ const baseIsObject = isPropTreeValue(baseValue);
240
+ const nextIsObject = isPropTreeValue(nextValue);
241
+ if (baseIsObject && nextIsObject) return {
242
+ ...base,
243
+ ...next,
244
+ dynamic: base.dynamic || next.dynamic,
245
+ value: mergePropTrees(baseValue, nextValue)
246
+ };
247
+ return next;
248
+ };
249
+ const mergePropTrees = (base, next) => {
250
+ const merged = structuredClone(base);
251
+ for (const [key, value] of Object.entries(next)) merged[key] = mergePropValues(merged[key], value);
252
+ return merged;
253
+ };
254
+ const isPropTreeValue = (value) => {
255
+ return Boolean(value && typeof value === "object" && !Array.isArray(value));
256
+ };
257
+ const parseExpressionValue = (expression) => {
258
+ if (expression.type === "JSXEmptyExpression") return {
259
+ dynamic: true,
260
+ value: null
261
+ };
262
+ if (expression.type === "NumericLiteral") return {
263
+ dynamic: false,
264
+ value: expression.value
265
+ };
266
+ if (expression.type === "StringLiteral") return {
267
+ dynamic: false,
268
+ value: expression.value
269
+ };
270
+ if (expression.type === "BooleanLiteral") return {
271
+ dynamic: false,
272
+ value: expression.value
273
+ };
274
+ if (expression.type === "NullLiteral") return {
275
+ dynamic: false,
276
+ value: null
277
+ };
278
+ if (expression.type === "TemplateLiteral") {
279
+ if (expression.expressions.length === 0) return {
280
+ dynamic: false,
281
+ value: expression.quasis[0].cooked ?? ""
282
+ };
283
+ return {
284
+ dynamic: true,
285
+ value: null,
286
+ ast: structuredClone(expression),
287
+ code: printExpression(expression)
288
+ };
289
+ }
290
+ if (expression.type === "ArrowFunctionExpression" || expression.type === "FunctionExpression") return {
291
+ dynamic: true,
292
+ value: null,
293
+ ast: structuredClone(expression),
294
+ code: printExpression(expression),
295
+ isFn: true
296
+ };
297
+ if (expression.type === "ArrayExpression") {
298
+ const values = [];
299
+ let dynamic = false;
300
+ for (const entry of expression.elements) {
301
+ if (!entry) {
302
+ dynamic = true;
303
+ continue;
304
+ }
305
+ const parsed = parseExpressionValue(entry.expression);
306
+ dynamic = dynamic || parsed.dynamic;
307
+ values.push(parsed);
308
+ }
309
+ return {
310
+ dynamic,
311
+ value: values,
312
+ ast: dynamic ? structuredClone(expression) : void 0,
313
+ code: dynamic ? printExpression(expression) : void 0
314
+ };
315
+ }
316
+ if (expression.type === "ObjectExpression") {
317
+ const value = {};
318
+ let dynamic = false;
319
+ for (const prop of expression.properties) {
320
+ if (prop.type !== "KeyValueProperty") {
321
+ dynamic = true;
322
+ continue;
323
+ }
324
+ if (prop.key.type !== "Identifier" && prop.key.type !== "StringLiteral") {
325
+ dynamic = true;
326
+ continue;
327
+ }
328
+ const key = prop.key.type === "Identifier" ? prop.key.value : prop.key.value;
329
+ const parsed = parseExpressionValue(prop.value);
330
+ dynamic = dynamic || parsed.dynamic;
331
+ value[key] = parsed;
332
+ }
333
+ return {
334
+ dynamic,
335
+ value,
336
+ ast: dynamic ? structuredClone(expression) : void 0,
337
+ code: dynamic ? printExpression(expression) : void 0
338
+ };
339
+ }
340
+ return {
341
+ dynamic: true,
342
+ value: null,
343
+ ast: structuredClone(expression),
344
+ code: printExpression(expression)
345
+ };
346
+ };
347
+ const buildPreparedDefinition = (objectExpression) => {
348
+ const tree = {};
349
+ let asExpression = null;
350
+ const ignored = new Set([
351
+ "as",
352
+ "class",
353
+ "className",
354
+ "style",
355
+ "key",
356
+ "ref"
357
+ ]);
358
+ for (const prop of objectExpression.properties) {
359
+ if (prop.type !== "KeyValueProperty") continue;
360
+ if (prop.key.type !== "Identifier" && prop.key.type !== "StringLiteral") continue;
361
+ const key = prop.key.type === "Identifier" ? prop.key.value : prop.key.value;
362
+ if (ignored.has(key)) {
363
+ if (key === "as") asExpression = prop.value;
364
+ continue;
365
+ }
366
+ tree[key] = parseExpressionValue(prop.value);
367
+ }
368
+ return {
369
+ asExpression,
370
+ tree
371
+ };
372
+ };
373
+ const isPreparedDefinitionStatic = (definition) => {
374
+ if (!isStaticAsExpression(definition.asExpression)) return false;
375
+ return isPropTreeStatic(definition.tree);
376
+ };
377
+ const buildInlineFirstOutput = (tree, tag, state) => {
378
+ const classNames = /* @__PURE__ */ new Set();
379
+ const styleProps = /* @__PURE__ */ new Map();
380
+ const walk = (node, contexts) => {
381
+ for (const [name, prop] of Object.entries(node)) {
382
+ const value = prop.value;
383
+ if (value && typeof value === "object" && !Array.isArray(value)) {
384
+ walk(value, [...contexts, name]);
385
+ continue;
386
+ }
387
+ const resolved = state.api.dictionary.resolve(name);
388
+ const isCssProp = Boolean(resolved.descriptor?.isCSSProp);
389
+ if (!isCssProp) continue;
390
+ const shouldInline = contexts.length === 0 && isCssProp;
391
+ const propName = resolved.name;
392
+ const expr = propToExpression(prop, propName, state);
393
+ if (!expr) continue;
394
+ if (shouldInline) styleProps.set(propName, expr);
395
+ else {
396
+ classNames.add(state.api.contextToClassName(propName, null, contexts, false, state.api.selectorPrefix));
397
+ styleProps.set(state.api.contextToCSSVariable(propName, null, contexts, state.api.selectorPrefix), expr);
398
+ }
399
+ }
400
+ };
401
+ walk(tree, []);
402
+ return {
403
+ classNames,
404
+ styleProps
405
+ };
406
+ };
407
+ const buildClassnameFirstOutput = (tree, tag, state) => {
408
+ const classNames = /* @__PURE__ */ new Set();
409
+ const styleProps = /* @__PURE__ */ new Map();
410
+ const resolveSelectorValue = (prop) => {
411
+ if (prop.selectorValue !== void 0) return prop.selectorValue;
412
+ if (Array.isArray(prop.value)) return prop.value.map((entry) => entry.value);
413
+ return prop.value;
414
+ };
415
+ const walk = (node, contexts) => {
416
+ for (const [name, prop] of Object.entries(node)) {
417
+ const value = prop.value;
418
+ if (value && typeof value === "object" && !Array.isArray(value)) {
419
+ walk(value, [...contexts, name]);
420
+ continue;
421
+ }
422
+ const resolved = state.api.dictionary.resolve(name);
423
+ if (!Boolean(resolved.descriptor?.isCSSProp)) continue;
424
+ if (prop.dynamic && !prop.isFn) {
425
+ console.warn(`[boss-css] compile skipped dynamic prop "${name}" in ${state.filename}. Use ${name}={() => value} with classname-first.`);
426
+ continue;
427
+ }
428
+ const isDynamicFn = prop.dynamic && prop.isFn;
429
+ const selectorValue = isDynamicFn ? null : resolveSelectorValue(prop);
430
+ const propName = resolved.name;
431
+ classNames.add(state.api.contextToClassName(propName, selectorValue, contexts, false, state.api.selectorPrefix));
432
+ if (!isDynamicFn) continue;
433
+ const expr = propToDynamicExpression(prop, propName, state);
434
+ if (!expr) continue;
435
+ styleProps.set(state.api.contextToCSSVariable(propName, null, contexts, state.api.selectorPrefix), expr);
436
+ }
437
+ };
438
+ walk(tree, []);
439
+ return {
440
+ classNames,
441
+ styleProps
442
+ };
443
+ };
444
+ const propToExpression = (prop, name, state) => {
445
+ const span = getSpan(prop.ast);
446
+ if (prop.dynamic) {
447
+ if (!prop.ast) return null;
448
+ state.needsValueHelper = true;
449
+ return {
450
+ type: "CallExpression",
451
+ span,
452
+ callee: {
453
+ type: "Identifier",
454
+ value: "__bossValue",
455
+ optional: false,
456
+ span
457
+ },
458
+ arguments: [{ expression: prop.ast }]
459
+ };
460
+ }
461
+ return literalExpression(resolveStaticValue(prop.value, name, state), span);
462
+ };
463
+ const propToDynamicExpression = (prop, name, state) => {
464
+ if (!prop.ast) return null;
465
+ const span = getSpan(prop.ast);
466
+ const callTarget = prop.isFn && prop.ast ? {
467
+ type: "ParenthesisExpression",
468
+ span,
469
+ expression: prop.ast
470
+ } : prop.ast;
471
+ const resolvedExpression = prop.isFn ? {
472
+ type: "CallExpression",
473
+ span,
474
+ callee: callTarget,
475
+ arguments: []
476
+ } : prop.ast;
477
+ state.needsValueHelper = true;
478
+ return {
479
+ type: "CallExpression",
480
+ span,
481
+ callee: {
482
+ type: "Identifier",
483
+ value: "__bossValue",
484
+ optional: false,
485
+ span
486
+ },
487
+ arguments: [{ expression: resolvedExpression }]
488
+ };
489
+ };
490
+ const resolveStaticValue = (value, name, state) => {
491
+ if (Array.isArray(value)) return state.api.dictionary.toValue(value.map((entry) => entry.value), name);
492
+ return state.api.dictionary.toValue(value, name);
493
+ };
494
+ const literalExpression = (value, span) => {
495
+ const safeSpan = ensureSpan(span);
496
+ if (typeof value === "number") return {
497
+ type: "NumericLiteral",
498
+ value,
499
+ span: safeSpan
500
+ };
501
+ if (typeof value === "boolean") return {
502
+ type: "BooleanLiteral",
503
+ value,
504
+ span: safeSpan
505
+ };
506
+ if (value === null) return {
507
+ type: "NullLiteral",
508
+ span: safeSpan
509
+ };
510
+ return {
511
+ type: "StringLiteral",
512
+ value: String(value),
513
+ span: safeSpan
514
+ };
515
+ };
516
+ const mergeClassName = (existing, addition, span, classNameProp) => {
517
+ if (!addition && !existing) return null;
518
+ if (!addition) return existing;
519
+ const safeSpan = ensureSpan(span);
520
+ if (!existing) return createJsxAttribute(classNameProp, {
521
+ type: "StringLiteral",
522
+ value: addition,
523
+ span: safeSpan
524
+ }, safeSpan);
525
+ const value = existing.value;
526
+ if (!value) return {
527
+ ...existing,
528
+ value: {
529
+ type: "StringLiteral",
530
+ value: addition,
531
+ span: safeSpan
532
+ }
533
+ };
534
+ if (value.type === "StringLiteral") return {
535
+ ...existing,
536
+ value: {
537
+ type: "StringLiteral",
538
+ value: `${value.value} ${addition}`.trim(),
539
+ span: safeSpan
540
+ }
541
+ };
542
+ if (value.type === "JSXExpressionContainer") return {
543
+ ...existing,
544
+ value: createJsxExpressionContainer({
545
+ type: "BinaryExpression",
546
+ operator: "+",
547
+ span: safeSpan,
548
+ left: value.expression,
549
+ right: {
550
+ type: "StringLiteral",
551
+ value: ` ${addition}`,
552
+ span: safeSpan
553
+ }
554
+ }, safeSpan)
555
+ };
556
+ return existing;
557
+ };
558
+ const mergeStyle = (existing, styleProps, span) => {
559
+ if (!styleProps.size && !existing) return null;
560
+ if (!styleProps.size) return existing;
561
+ const safeSpan = ensureSpan(span);
562
+ const styleObject = toStyleObject(styleProps, safeSpan);
563
+ if (!existing) return createJsxAttribute("style", createJsxExpressionContainer(styleObject, safeSpan), safeSpan);
564
+ const value = existing.value;
565
+ if (value?.type === "JSXExpressionContainer" && value.expression.type === "ObjectExpression") return {
566
+ ...existing,
567
+ value: createJsxExpressionContainer(mergeObjectExpressions(value.expression, styleObject), safeSpan)
568
+ };
569
+ return {
570
+ ...existing,
571
+ value: createJsxExpressionContainer(createObjectAssignExpression(styleObject, valueExpression(value, safeSpan), safeSpan), safeSpan)
572
+ };
573
+ };
574
+ const appendStyle = (existing, extra, span) => {
575
+ const safeSpan = ensureSpan(span);
576
+ if (!existing) return createJsxAttribute("style", createJsxExpressionContainer(extra, safeSpan), safeSpan);
577
+ const value = existing.value;
578
+ if (value?.type === "JSXExpressionContainer") return {
579
+ ...existing,
580
+ value: createJsxExpressionContainer(mergeStyleExpressions(value.expression, extra, safeSpan), safeSpan)
581
+ };
582
+ return existing;
583
+ };
584
+ const mergeStyleExpressions = (base, extra, span) => {
585
+ if (base.type === "ObjectExpression" && extra.type === "ObjectExpression") return mergeObjectExpressions(base, extra);
586
+ return createObjectAssignExpression(base, extra, span);
587
+ };
588
+ const createObjectAssignExpression = (base, extra, span) => {
589
+ const safeSpan = ensureSpan(span);
590
+ return {
591
+ type: "CallExpression",
592
+ span: safeSpan,
593
+ callee: {
594
+ type: "MemberExpression",
595
+ span: safeSpan,
596
+ object: {
597
+ type: "Identifier",
598
+ value: "Object",
599
+ optional: false,
600
+ span: safeSpan
601
+ },
602
+ property: {
603
+ type: "Identifier",
604
+ value: "assign",
605
+ optional: false,
606
+ span: safeSpan
607
+ }
608
+ },
609
+ arguments: [{ expression: base }, { expression: extra }]
610
+ };
611
+ };
612
+ const toStyleObject = (styleProps, span) => {
613
+ const safeSpan = ensureSpan(span);
614
+ return {
615
+ type: "ObjectExpression",
616
+ span: safeSpan,
617
+ properties: Array.from(styleProps.entries()).map(([key, value]) => {
618
+ return {
619
+ type: "KeyValueProperty",
620
+ span: safeSpan,
621
+ key: /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) && !key.includes("-") ? {
622
+ type: "Identifier",
623
+ value: key,
624
+ optional: false,
625
+ span: safeSpan
626
+ } : {
627
+ type: "StringLiteral",
628
+ value: key,
629
+ span: safeSpan
630
+ },
631
+ value
632
+ };
633
+ })
634
+ };
635
+ };
636
+ const mergeObjectExpressions = (target, source) => {
637
+ target.properties = [...target.properties, ...source.properties];
638
+ return target;
639
+ };
640
+ const valueExpression = (value, span) => {
641
+ const safeSpan = ensureSpan(span);
642
+ if (value && value.type === "JSXExpressionContainer") return value.expression;
643
+ if (value && value.type === "StringLiteral") return {
644
+ type: "StringLiteral",
645
+ value: value.value,
646
+ span: safeSpan
647
+ };
648
+ return {
649
+ type: "ObjectExpression",
650
+ span: safeSpan,
651
+ properties: []
652
+ };
653
+ };
654
+ const attributeName = (name) => {
655
+ if (name.type === "Identifier") return name.value;
656
+ return null;
657
+ };
658
+ const findAttribute = (attributes, name) => {
659
+ for (const attr of attributes) {
660
+ if (attr.type !== "JSXAttribute") continue;
661
+ if (attributeName(attr.name) === name) return attr;
662
+ }
663
+ return null;
664
+ };
665
+ const toJsxIdentifier = (value, span) => {
666
+ return {
667
+ type: "Identifier",
668
+ value,
669
+ optional: false,
670
+ span: ensureSpan(span)
671
+ };
672
+ };
673
+ const printExpression = (expression) => {
674
+ const safeSpan = getSpan(expression);
675
+ return (0, _swc_core.printSync)({
676
+ type: "Module",
677
+ body: [{
678
+ type: "ExpressionStatement",
679
+ expression,
680
+ span: safeSpan
681
+ }],
682
+ interpreter: "",
683
+ span: safeSpan
684
+ }).code.replace(/^#!.*\n/, "").replace(/;\s*$/, "");
685
+ };
686
+ const isPropTreeStatic = (tree) => {
687
+ for (const prop of Object.values(tree)) {
688
+ if (prop.dynamic) return false;
689
+ const value = prop.value;
690
+ if (value && typeof value === "object" && !Array.isArray(value)) {
691
+ if (!isPropTreeStatic(value)) return false;
692
+ }
693
+ }
694
+ return true;
695
+ };
696
+ const isStaticAsExpression = (expression) => {
697
+ if (!expression) return true;
698
+ if (expression.type === "StringLiteral") return true;
699
+ return expression.type === "TemplateLiteral" && expression.expressions.length === 0;
700
+ };
701
+ const buildTokenVarsExpression = (tokensProp, state, span) => {
702
+ if (!tokensProp) return null;
703
+ if (tokensProp.dynamic) {
704
+ if (!tokensProp.ast) return null;
705
+ const safeSpan = getSpan(tokensProp.ast);
706
+ const argExpression = tokensProp.isFn ? {
707
+ type: "CallExpression",
708
+ span: safeSpan,
709
+ callee: {
710
+ type: "ParenthesisExpression",
711
+ span: safeSpan,
712
+ expression: tokensProp.ast
713
+ },
714
+ arguments: []
715
+ } : tokensProp.ast;
716
+ state.needsTokenVarsHelper = true;
717
+ return {
718
+ type: "CallExpression",
719
+ span: safeSpan,
720
+ callee: {
721
+ type: "Identifier",
722
+ value: "__bossTokenVars",
723
+ optional: false,
724
+ span: safeSpan
725
+ },
726
+ arguments: [{ expression: argExpression }]
727
+ };
728
+ }
729
+ const overrides = propValueToRaw(tokensProp);
730
+ if (!overrides || typeof overrides !== "object" || Array.isArray(overrides)) return null;
731
+ const tokenVars = require_vars.createTokenVars({
732
+ prefix: state.api.selectorPrefix ?? "",
733
+ toValue: (value, property) => state.api.dictionary.toValue(value, property)
734
+ })(overrides);
735
+ const entries = /* @__PURE__ */ new Map();
736
+ for (const [key, value] of Object.entries(tokenVars)) entries.set(key, literalExpression(value, ensureSpan(span)));
737
+ if (!entries.size) return null;
738
+ return toStyleObject(entries, ensureSpan(span));
739
+ };
740
+ const propValueToRaw = (prop) => {
741
+ const value = prop.value;
742
+ if (Array.isArray(value)) return value.map((entry) => propValueToRaw(entry));
743
+ if (value && typeof value === "object") return Object.entries(value).reduce((acc, [key, entry]) => {
744
+ acc[key] = propValueToRaw(entry);
745
+ return acc;
746
+ }, {});
747
+ return value;
748
+ };
749
+ const wrapDynamicAs = (node, asExpression, span, context) => {
750
+ const safeSpan = ensureSpan(span);
751
+ const componentIdentifier = {
752
+ type: "Identifier",
753
+ value: "__BossCmp",
754
+ optional: false,
755
+ span: safeSpan
756
+ };
757
+ const element = structuredClone(node);
758
+ element.opening.name = componentIdentifier;
759
+ if (element.closing) element.closing.name = componentIdentifier;
760
+ const iife = {
761
+ type: "CallExpression",
762
+ span: safeSpan,
763
+ callee: {
764
+ type: "FunctionExpression",
765
+ span: safeSpan,
766
+ identifier: void 0,
767
+ params: [],
768
+ body: {
769
+ type: "BlockStatement",
770
+ span: safeSpan,
771
+ stmts: [{
772
+ type: "VariableDeclaration",
773
+ span: safeSpan,
774
+ kind: "const",
775
+ declarations: [{
776
+ type: "VariableDeclarator",
777
+ span: safeSpan,
778
+ id: componentIdentifier,
779
+ init: asExpression
780
+ }]
781
+ }, {
782
+ type: "ReturnStatement",
783
+ span: safeSpan,
784
+ argument: element
785
+ }]
786
+ },
787
+ generator: false,
788
+ async: false
789
+ },
790
+ arguments: []
791
+ };
792
+ if (context.inJsxChild) return {
793
+ type: "JSXExpressionContainer",
794
+ span: safeSpan,
795
+ expression: iife
796
+ };
797
+ return iife;
798
+ };
799
+
800
+ //#endregion
801
+ exports.buildPreparedDefinition = buildPreparedDefinition;
802
+ exports.isPreparedDefinitionStatic = isPreparedDefinitionStatic;
803
+ exports.transformJsxElement = transformJsxElement;