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