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,369 @@
1
+ import { getClassNameProp } from "../shared/framework.mjs";
2
+ import { rewriteClassNameTokensInElement, rewriteClassNameTokensWithMap } from "./classname.mjs";
3
+ import { buildPreparedDefinition, transformJsxElement } from "./jsx.mjs";
4
+ import { extractCustomCssText } from "../shared/customCss.mjs";
5
+ import path from "node:path";
6
+ import { parseSync, printSync } from "@swc/core";
7
+
8
+ //#region src/compile/transform.ts
9
+ const jsxExtensions = new Set([
10
+ ".jsx",
11
+ ".tsx",
12
+ ".js",
13
+ ".mjs",
14
+ ".cjs"
15
+ ]);
16
+ const tsExtensions = new Set([".ts", ".tsx"]);
17
+ const fallbackSpan = {
18
+ start: 0,
19
+ end: 0,
20
+ ctxt: 0
21
+ };
22
+ const ensureSpan = (span) => {
23
+ if (!span) return fallbackSpan;
24
+ if (typeof span.ctxt === "number") return span;
25
+ return {
26
+ ...span,
27
+ ctxt: 0
28
+ };
29
+ };
30
+ const createVoidExpression = (span) => {
31
+ const safeSpan = ensureSpan(span);
32
+ return {
33
+ type: "UnaryExpression",
34
+ span: safeSpan,
35
+ operator: "void",
36
+ argument: {
37
+ type: "NumericLiteral",
38
+ span: safeSpan,
39
+ value: 0
40
+ }
41
+ };
42
+ };
43
+ async function transformSource(source, options) {
44
+ const ext = path.extname(options.filename);
45
+ const isTs = tsExtensions.has(ext);
46
+ const isJsx = jsxExtensions.has(ext);
47
+ const parsed = parseSync(source, {
48
+ syntax: isTs ? "typescript" : "ecmascript",
49
+ tsx: isTs && isJsx,
50
+ jsx: !isTs && isJsx
51
+ });
52
+ const state = {
53
+ api: options.api,
54
+ classNameProp: getClassNameProp(options.api.framework),
55
+ compile: options.compile,
56
+ filename: options.filename,
57
+ classNameMapper: options.classNameMapper ?? null,
58
+ needsRuntime: false,
59
+ needsValueHelper: false,
60
+ needsTokenVarsHelper: false,
61
+ replacedElements: 0,
62
+ preparedLocal: new Map(options.preparedLocal ?? []),
63
+ preparedGlobal: options.preparedGlobal ?? /* @__PURE__ */ new Map(),
64
+ preparedRuntime: options.preparedRuntime ?? /* @__PURE__ */ new Set(),
65
+ customCssBlocks: []
66
+ };
67
+ const transformed = await transformProgram(parsed, state);
68
+ normalizeSpans(transformed);
69
+ if (state.customCssBlocks.length) state.api.css?.syncCustomBlocks?.(state.filename, state.customCssBlocks);
70
+ return {
71
+ code: printSync(transformed).code,
72
+ needsRuntime: state.needsRuntime,
73
+ needsValueHelper: state.needsValueHelper,
74
+ replacedElements: state.replacedElements
75
+ };
76
+ }
77
+ const normalizeSpans = (node) => {
78
+ if (!node || typeof node !== "object") return;
79
+ if (Array.isArray(node)) {
80
+ node.forEach(normalizeSpans);
81
+ return;
82
+ }
83
+ const record = node;
84
+ if (typeof record.type === "string" && record.span && typeof record.ctxt !== "number") record.ctxt = 0;
85
+ for (const [key, value] of Object.entries(record)) {
86
+ if (key === "span" && value && typeof value === "object") {
87
+ const span = value;
88
+ if (typeof span.start === "number" && typeof span.end === "number" && typeof span.ctxt !== "number") span.ctxt = 0;
89
+ continue;
90
+ }
91
+ normalizeSpans(value);
92
+ }
93
+ };
94
+ const transformProgram = async (program, state) => {
95
+ const transformed = await transformNode(program, state);
96
+ const needsValueHelper = state.needsValueHelper && !hasValueHelper(transformed);
97
+ const needsTokenVarsHelper = state.needsTokenVarsHelper && !hasTokenVarsHelper(transformed);
98
+ if (needsValueHelper || needsTokenVarsHelper) {
99
+ const helper = createRuntimeHelpersProgram({
100
+ unit: state.api.unit ?? "px",
101
+ prefix: state.api.selectorPrefix ?? "",
102
+ needsValueHelper,
103
+ needsTokenVarsHelper
104
+ });
105
+ if ("body" in transformed) transformed.body = [...helper.body, ...transformed.body];
106
+ }
107
+ if (!state.needsRuntime && "body" in transformed) transformed.body = transformed.body.filter((node) => {
108
+ if (node.type !== "ImportDeclaration") return true;
109
+ const source = node.source.value;
110
+ return !isBossImport(source);
111
+ });
112
+ return transformed;
113
+ };
114
+ const transformNode = async (node, state, context = {}) => {
115
+ if (!node || typeof node !== "object") return node;
116
+ if (Array.isArray(node)) {
117
+ const mapped = [];
118
+ for (const child of node) {
119
+ const next = await transformNode(child, state, context);
120
+ if (next === null) continue;
121
+ mapped.push(next);
122
+ }
123
+ return mapped;
124
+ }
125
+ const current = node;
126
+ const mapToken = state.classNameMapper ? (token) => state.classNameMapper?.get(token) : void 0;
127
+ let keepPreparedMarker = false;
128
+ if (current.type === "ExpressionStatement") {
129
+ const expression = current.expression;
130
+ if (expression) {
131
+ const cssText = extractCustomCssText(expression, state.api);
132
+ if (cssText != null) {
133
+ const span = ensureSpan(expression.span);
134
+ state.customCssBlocks.push({
135
+ start: span.start,
136
+ end: span.end,
137
+ cssText
138
+ });
139
+ return null;
140
+ }
141
+ }
142
+ }
143
+ if (current.type === "CallExpression" || current.type === "TaggedTemplateExpression") {
144
+ const cssText = extractCustomCssText(current, state.api);
145
+ if (cssText != null) {
146
+ const span = ensureSpan(current.span);
147
+ state.customCssBlocks.push({
148
+ start: span.start,
149
+ end: span.end,
150
+ cssText
151
+ });
152
+ return createVoidExpression(span);
153
+ }
154
+ }
155
+ if (isPreparedAssignment(current)) {
156
+ const prepared = parsePreparedDefinition(current.expression);
157
+ if (prepared) {
158
+ state.preparedLocal.set(prepared.name, prepared.definition);
159
+ if (state.preparedRuntime.has(prepared.name)) {
160
+ state.needsRuntime = true;
161
+ keepPreparedMarker = true;
162
+ } else return null;
163
+ }
164
+ }
165
+ if (isPreparedAssignmentExpression(current)) {
166
+ const prepared = parsePreparedDefinition(current);
167
+ if (prepared) {
168
+ state.preparedLocal.set(prepared.name, prepared.definition);
169
+ state.needsRuntime = true;
170
+ keepPreparedMarker = true;
171
+ }
172
+ }
173
+ if (state.classNameMapper && !context.inModuleSpecifier) {
174
+ if (current.type === "StringLiteral") {
175
+ const literal = current;
176
+ const rewritten = rewriteClassNameTokensWithMap(literal.value, mapToken);
177
+ if (rewritten !== literal.value) {
178
+ literal.value = rewritten;
179
+ literal.raw = JSON.stringify(rewritten);
180
+ }
181
+ }
182
+ if (current.type === "TemplateLiteral" && Array.isArray(current.expressions) && current.expressions.length === 0 && Array.isArray(current.quasis) && current.quasis.length) {
183
+ const firstQuasi = current.quasis[0];
184
+ if (firstQuasi) {
185
+ const cooked = firstQuasi.cooked ?? "";
186
+ const rewritten = rewriteClassNameTokensWithMap(cooked, mapToken);
187
+ if (rewritten !== cooked) {
188
+ firstQuasi.cooked = rewritten;
189
+ firstQuasi.raw = rewritten;
190
+ }
191
+ }
192
+ }
193
+ }
194
+ const isBossElement = current.type === "JSXElement" && isBossJsxElement(current);
195
+ const isBossMarkerCall = (() => {
196
+ if (current.type !== "CallExpression") return false;
197
+ const call = current;
198
+ if (call.callee.type !== "MemberExpression") return false;
199
+ if (call.callee.object?.type !== "Identifier" || call.callee.object.value !== "$$") return false;
200
+ if (call.callee.property?.type !== "Identifier" || call.callee.property.value !== "$") return false;
201
+ return true;
202
+ })();
203
+ for (const key of Object.keys(current)) {
204
+ let childContext = context.inJsxChild && current.type !== "JSXElement" ? {
205
+ ...context,
206
+ inJsxChild: false
207
+ } : context;
208
+ if (isBossElement) childContext = {
209
+ ...childContext,
210
+ inBossElement: true
211
+ };
212
+ if (current.type === "JSXElement" && key === "children") childContext = {
213
+ ...childContext,
214
+ inJsxChild: true
215
+ };
216
+ if (keepPreparedMarker) {
217
+ if (current.type === "ExpressionStatement" && key === "expression") childContext = {
218
+ ...childContext,
219
+ keepBossMarker: true
220
+ };
221
+ if (current.type === "AssignmentExpression" && key === "right") childContext = {
222
+ ...childContext,
223
+ keepBossMarker: true
224
+ };
225
+ }
226
+ if (isBossMarkerCall && key === "callee") childContext = {
227
+ ...childContext,
228
+ inBossMarkerCall: true
229
+ };
230
+ if (current.type === "JSXAttribute" && key === "value") {
231
+ const attrName = getJsxAttributeName(current);
232
+ const isBossProp = Boolean(context.inBossElement && attrName && state.api.dictionary.resolve(attrName).descriptor);
233
+ childContext = {
234
+ ...childContext,
235
+ inBossPropValue: isBossProp
236
+ };
237
+ }
238
+ if (current.type === "CallExpression" && key === "arguments") {
239
+ const callee = current.callee;
240
+ const args = current.arguments;
241
+ if (callee.type === "MemberExpression" && callee.object?.type === "Identifier" && callee.object.value === "$$" && callee.property?.type === "Identifier" && callee.property.value === "$" && args.length === 1 && args[0].expression.type === "ObjectExpression") childContext = {
242
+ ...childContext,
243
+ inBossPropValue: true
244
+ };
245
+ }
246
+ if ((current.type === "ImportDeclaration" || current.type === "ExportAllDeclaration" || current.type === "ExportNamedDeclaration") && key === "source") childContext = {
247
+ ...childContext,
248
+ inModuleSpecifier: true
249
+ };
250
+ current[key] = await transformNode(current[key], state, childContext);
251
+ }
252
+ if (current.type === "JSXElement") {
253
+ const element = current;
254
+ rewriteClassNameTokensInElement(element, state.classNameProp, mapToken);
255
+ return transformJsxElement(element, state, context);
256
+ }
257
+ if (current.type === "CallExpression") {
258
+ const expr = current;
259
+ const callee = expr.callee;
260
+ const isBossMarker = callee.type === "MemberExpression" && callee.object?.type === "Identifier" && callee.object.value === "$$" && callee.property?.type === "Identifier" && callee.property.value === "$";
261
+ if (isBossMarker && context.keepBossMarker) return current;
262
+ if (isBossMarker && expr.arguments.length === 1 && expr.arguments[0].expression.type === "ObjectExpression") return expr.arguments[0].expression;
263
+ if (isBossMarker && expr.arguments.length === 1) {
264
+ const arg = expr.arguments[0].expression;
265
+ if (arg.type === "StringLiteral") {
266
+ const rewritten = rewriteClassNameTokensWithMap(arg.value, mapToken);
267
+ arg.value = rewritten;
268
+ arg.raw = JSON.stringify(rewritten);
269
+ } else if (arg.type === "TemplateLiteral" && arg.expressions.length === 0) {
270
+ const rewritten = rewriteClassNameTokensWithMap(arg.quasis[0].cooked ?? "", mapToken);
271
+ arg.quasis[0].cooked = rewritten;
272
+ arg.quasis[0].raw = rewritten;
273
+ }
274
+ return arg;
275
+ }
276
+ if (callee.type === "Identifier" && callee.value === "$$") state.needsRuntime = true;
277
+ }
278
+ if (current.type === "MemberExpression") {
279
+ if (context.inBossPropValue) return current;
280
+ if (context.inBossMarkerCall) return current;
281
+ const member = current;
282
+ if (member.object?.type === "Identifier" && member.object.value === "$$") state.needsRuntime = true;
283
+ }
284
+ return current;
285
+ };
286
+ const isBossJsxElement = (node) => {
287
+ const name = node.opening.name;
288
+ if (name.type === "Identifier" && name.value === "$$") return true;
289
+ if (name.type === "JSXMemberExpression" && name.object.type === "Identifier" && name.object.value === "$$") return true;
290
+ return false;
291
+ };
292
+ const getJsxAttributeName = (node) => {
293
+ if (node.name?.type === "Identifier") return node.name.value;
294
+ return null;
295
+ };
296
+ const createRuntimeHelpersProgram = ({ unit, prefix, needsValueHelper, needsTokenVarsHelper }) => {
297
+ const imports = [];
298
+ const lines = [];
299
+ if (needsValueHelper) {
300
+ imports.push("createBossValue");
301
+ lines.push(`const __bossValue = createBossValue(${JSON.stringify(unit)});`);
302
+ }
303
+ if (needsTokenVarsHelper) {
304
+ imports.push("createBossTokenVars");
305
+ lines.push(`const __bossTokenVars = createBossTokenVars(${JSON.stringify(unit)}, ${JSON.stringify(prefix)});`);
306
+ }
307
+ return parseSync(`import { ${imports.join(", ")} } from "boss-css/compile/runtime";
308
+ ${lines.join("\n")}`, { syntax: "ecmascript" });
309
+ };
310
+ const hasValueHelper = (program) => {
311
+ if (!("body" in program)) return false;
312
+ return program.body.some((node) => {
313
+ if (node.type !== "VariableDeclaration") return false;
314
+ return node.declarations.some((decl) => decl.id.type === "Identifier" && decl.id.value === "__bossValue");
315
+ });
316
+ };
317
+ const hasTokenVarsHelper = (program) => {
318
+ if (!("body" in program)) return false;
319
+ return program.body.some((node) => {
320
+ if (node.type !== "VariableDeclaration") return false;
321
+ return node.declarations.some((decl) => decl.id.type === "Identifier" && decl.id.value === "__bossTokenVars");
322
+ });
323
+ };
324
+ const isBossImport = (source) => {
325
+ if (source === "boss-css/compile/runtime") return false;
326
+ return source.includes(".bo$$/server") || source === "boss-css" || source.startsWith("boss-css/") || source === "boss-css/parser/jsx/runtime" || source === "boss-css/runtime" || source.startsWith("boss-css/runtime/") || source.startsWith("@boss-css/");
327
+ };
328
+ const isPreparedAssignmentExpression = (node) => {
329
+ if (node.type !== "AssignmentExpression") return false;
330
+ const assignment = node;
331
+ if (assignment.operator && assignment.operator !== "=") return false;
332
+ const left = assignment.left;
333
+ if (!left || left.type !== "MemberExpression") return false;
334
+ if (left.object?.type !== "Identifier" || left.object.value !== "$$") return false;
335
+ const property = left.property;
336
+ if (!property || property.type !== "Identifier") return false;
337
+ if (!property.value || !/^[A-Z]/.test(property.value)) return false;
338
+ return Boolean(assignment.right && getPreparedObjectExpression(assignment.right));
339
+ };
340
+ const isPreparedAssignment = (node) => {
341
+ if (node.type !== "ExpressionStatement") return false;
342
+ const statement = node;
343
+ return Boolean(statement.expression && isPreparedAssignmentExpression(statement.expression));
344
+ };
345
+ const parsePreparedDefinition = (expression) => {
346
+ const assignment = expression;
347
+ const name = assignment.left?.property?.value;
348
+ const objectExpression = assignment.right ? getPreparedObjectExpression(assignment.right) : null;
349
+ if (!name || !objectExpression) return null;
350
+ const definition = buildPreparedDefinition(objectExpression);
351
+ if (!definition) return null;
352
+ return {
353
+ name,
354
+ definition
355
+ };
356
+ };
357
+ const getPreparedObjectExpression = (expression) => {
358
+ if (expression.type === "CallExpression" && expression.arguments.length === 1) {
359
+ const callee = expression.callee;
360
+ if (callee.type === "MemberExpression" && callee.object?.type === "Identifier" && callee.object.value === "$$" && callee.property?.type === "Identifier" && callee.property.value === "$") {
361
+ const arg = expression.arguments[0].expression;
362
+ if (arg.type === "ObjectExpression") return arg;
363
+ }
364
+ }
365
+ return null;
366
+ };
367
+
368
+ //#endregion
369
+ export { transformSource };
@@ -0,0 +1,93 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_merge_index = require('../merge/index.cjs');
3
+ let css_variants = require("css-variants");
4
+
5
+ //#region src/cx/index.ts
6
+ const createBossClassNameResolver = (mergeConfig, resolver = css_variants.cx) => {
7
+ const merge$1 = require_merge_index.createBossMerge(mergeConfig);
8
+ return (...inputs) => {
9
+ return merge$1(resolver(...inputs));
10
+ };
11
+ };
12
+ const createBossCx = (config = {}) => {
13
+ const resolve = createBossClassNameResolver(config);
14
+ return (...inputs) => resolve(...inputs);
15
+ };
16
+ const cx = createBossCx();
17
+ const createBossCv = (mergeConfig = {}) => {
18
+ return (config) => {
19
+ const classNameResolver = createBossClassNameResolver(mergeConfig, config.classNameResolver ?? css_variants.cx);
20
+ return (0, css_variants.cv)({
21
+ ...config,
22
+ classNameResolver
23
+ });
24
+ };
25
+ };
26
+ const cv = createBossCv();
27
+ const createBossScv = (mergeConfig = {}) => {
28
+ return (config) => {
29
+ const classNameResolver = createBossClassNameResolver(mergeConfig, config.classNameResolver ?? css_variants.cx);
30
+ return (0, css_variants.scv)({
31
+ ...config,
32
+ classNameResolver
33
+ });
34
+ };
35
+ };
36
+ const scv = createBossScv();
37
+ const resolveVariantProps = (defaults, props, ignoredKeys) => {
38
+ const resolved = { ...defaults ?? {} };
39
+ if (!props) return resolved;
40
+ for (const [key, value] of Object.entries(props)) {
41
+ if (value === void 0 || ignoredKeys.has(key)) continue;
42
+ resolved[key] = value;
43
+ }
44
+ return resolved;
45
+ };
46
+ const createBossSv = () => {
47
+ return (config) => {
48
+ const { base, variants, compoundVariants, defaultVariants } = config;
49
+ if (!variants) return (props) => {
50
+ const parts = [base, props?.style].filter(Boolean);
51
+ return parts.length ? require_merge_index.merge(...parts) : {};
52
+ };
53
+ return (props) => {
54
+ const resolvedProps = resolveVariantProps(defaultVariants, props, new Set(["style"]));
55
+ const parts = [];
56
+ if (base) parts.push(base);
57
+ for (const [key, value] of Object.entries(resolvedProps)) {
58
+ const variant = variants[key]?.[value];
59
+ if (variant) parts.push(variant);
60
+ }
61
+ if (compoundVariants) for (const compound of compoundVariants) {
62
+ let matches = true;
63
+ for (const [key, value] of Object.entries(compound)) {
64
+ if (key === "style") continue;
65
+ const resolvedValue = resolvedProps[key];
66
+ if (Array.isArray(value)) {
67
+ if (!value.includes(resolvedValue)) {
68
+ matches = false;
69
+ break;
70
+ }
71
+ } else if (value !== resolvedValue) {
72
+ matches = false;
73
+ break;
74
+ }
75
+ }
76
+ if (matches && compound.style) parts.push(compound.style);
77
+ }
78
+ if (props?.style) parts.push(props.style);
79
+ return parts.length ? require_merge_index.merge(...parts) : {};
80
+ };
81
+ };
82
+ };
83
+ const sv = createBossSv();
84
+
85
+ //#endregion
86
+ exports.createBossCv = createBossCv;
87
+ exports.createBossCx = createBossCx;
88
+ exports.createBossScv = createBossScv;
89
+ exports.createBossSv = createBossSv;
90
+ exports.cv = cv;
91
+ exports.cx = cx;
92
+ exports.scv = scv;
93
+ exports.sv = sv;
@@ -0,0 +1,85 @@
1
+ import { createBossMerge, merge } from "../merge/index.mjs";
2
+ import { cv as cv$1, cx as cx$1, scv as scv$1 } from "css-variants";
3
+
4
+ //#region src/cx/index.ts
5
+ const createBossClassNameResolver = (mergeConfig, resolver = cx$1) => {
6
+ const merge$1 = createBossMerge(mergeConfig);
7
+ return (...inputs) => {
8
+ return merge$1(resolver(...inputs));
9
+ };
10
+ };
11
+ const createBossCx = (config = {}) => {
12
+ const resolve = createBossClassNameResolver(config);
13
+ return (...inputs) => resolve(...inputs);
14
+ };
15
+ const cx = createBossCx();
16
+ const createBossCv = (mergeConfig = {}) => {
17
+ return (config) => {
18
+ const classNameResolver = createBossClassNameResolver(mergeConfig, config.classNameResolver ?? cx$1);
19
+ return cv$1({
20
+ ...config,
21
+ classNameResolver
22
+ });
23
+ };
24
+ };
25
+ const cv = createBossCv();
26
+ const createBossScv = (mergeConfig = {}) => {
27
+ return (config) => {
28
+ const classNameResolver = createBossClassNameResolver(mergeConfig, config.classNameResolver ?? cx$1);
29
+ return scv$1({
30
+ ...config,
31
+ classNameResolver
32
+ });
33
+ };
34
+ };
35
+ const scv = createBossScv();
36
+ const resolveVariantProps = (defaults, props, ignoredKeys) => {
37
+ const resolved = { ...defaults ?? {} };
38
+ if (!props) return resolved;
39
+ for (const [key, value] of Object.entries(props)) {
40
+ if (value === void 0 || ignoredKeys.has(key)) continue;
41
+ resolved[key] = value;
42
+ }
43
+ return resolved;
44
+ };
45
+ const createBossSv = () => {
46
+ return (config) => {
47
+ const { base, variants, compoundVariants, defaultVariants } = config;
48
+ if (!variants) return (props) => {
49
+ const parts = [base, props?.style].filter(Boolean);
50
+ return parts.length ? merge(...parts) : {};
51
+ };
52
+ return (props) => {
53
+ const resolvedProps = resolveVariantProps(defaultVariants, props, new Set(["style"]));
54
+ const parts = [];
55
+ if (base) parts.push(base);
56
+ for (const [key, value] of Object.entries(resolvedProps)) {
57
+ const variant = variants[key]?.[value];
58
+ if (variant) parts.push(variant);
59
+ }
60
+ if (compoundVariants) for (const compound of compoundVariants) {
61
+ let matches = true;
62
+ for (const [key, value] of Object.entries(compound)) {
63
+ if (key === "style") continue;
64
+ const resolvedValue = resolvedProps[key];
65
+ if (Array.isArray(value)) {
66
+ if (!value.includes(resolvedValue)) {
67
+ matches = false;
68
+ break;
69
+ }
70
+ } else if (value !== resolvedValue) {
71
+ matches = false;
72
+ break;
73
+ }
74
+ }
75
+ if (matches && compound.style) parts.push(compound.style);
76
+ }
77
+ if (props?.style) parts.push(props.style);
78
+ return parts.length ? merge(...parts) : {};
79
+ };
80
+ };
81
+ };
82
+ const sv = createBossSv();
83
+
84
+ //#endregion
85
+ export { createBossCv, createBossCx, createBossScv, createBossSv, cv, cx, scv, sv };