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,360 @@
1
+ import { parseSync, printSync } from "@swc/core";
2
+
3
+ //#region src/compile/classname.ts
4
+ const tokenPrefix = "$$.token.";
5
+ const rewriteClassNameTokens = (input) => {
6
+ if (!input.includes(tokenPrefix) && !input.includes("{")) return input;
7
+ return splitSelectors(input).flatMap((selector) => rewriteSelector(selector, { expandSingleGroup: false })).join(" ");
8
+ };
9
+ const rewriteClassNameTokensInText = (source, options = {}) => {
10
+ return rewriteQuotedSegments(source, ({ value, hasTemplateExpression }) => {
11
+ if (hasTemplateExpression) return null;
12
+ return rewriteClassNameTokensWithMap(value, options.mapToken);
13
+ });
14
+ };
15
+ const rewriteClassNameTokensInSource = (source, options) => {
16
+ const ext = options.filename.split(".").pop() ?? "";
17
+ const isTs = ext === "ts" || ext === "tsx";
18
+ const isJsx = [
19
+ "jsx",
20
+ "tsx",
21
+ "js",
22
+ "mjs",
23
+ "cjs"
24
+ ].includes(ext);
25
+ const classNameProp = options.classNameProp ?? "className";
26
+ const mapToken = options.mapToken;
27
+ const parsed = parseSync(source, {
28
+ syntax: isTs ? "typescript" : "ecmascript",
29
+ tsx: isTs && isJsx,
30
+ jsx: !isTs && isJsx
31
+ });
32
+ const visit = (node, context = {}) => {
33
+ if (!node || typeof node !== "object") return;
34
+ if (Array.isArray(node)) {
35
+ node.forEach((child) => visit(child, context));
36
+ return;
37
+ }
38
+ const current = node;
39
+ if (current.type === "JSXElement") rewriteClassNameTokensInElement(current, classNameProp, mapToken);
40
+ if (current.type === "CallExpression") rewriteClassNameTokensInCall(current, mapToken);
41
+ if (!context.inModuleSpecifier) {
42
+ if (current.type === "StringLiteral") {
43
+ const literal = current;
44
+ updateStringLiteral(literal, rewriteClassNameTokensWithMap(literal.value, mapToken));
45
+ }
46
+ if (current.type === "TemplateLiteral" && Array.isArray(current.expressions) && current.expressions.length === 0 && Array.isArray(current.quasis) && current.quasis.length) {
47
+ const firstQuasi = current.quasis[0];
48
+ if (firstQuasi) {
49
+ const rewritten = rewriteClassNameTokensWithMap(firstQuasi.cooked ?? "", mapToken);
50
+ firstQuasi.cooked = rewritten;
51
+ firstQuasi.raw = rewritten;
52
+ }
53
+ }
54
+ }
55
+ for (const key of Object.keys(current)) {
56
+ const nextContext = (current.type === "ImportDeclaration" || current.type === "ExportAllDeclaration" || current.type === "ExportNamedDeclaration") && key === "source" ? {
57
+ ...context,
58
+ inModuleSpecifier: true
59
+ } : context;
60
+ visit(current[key], nextContext);
61
+ }
62
+ };
63
+ visit(parsed);
64
+ return printSync(parsed).code;
65
+ };
66
+ const rewriteClassNameTokensInCall = (expr, mapToken) => {
67
+ const callee = expr.callee;
68
+ if (callee.type !== "Identifier" || callee.value !== "$$") return;
69
+ if (expr.arguments.length !== 1) return;
70
+ const arg = expr.arguments[0].expression;
71
+ rewriteStringExpression(arg, mapToken);
72
+ };
73
+ const rewriteStringExpression = (expression, mapToken) => {
74
+ if (!expression) return;
75
+ if (expression.type === "StringLiteral") {
76
+ updateStringLiteral(expression, rewriteClassNameTokensWithMap(expression.value, mapToken));
77
+ return;
78
+ }
79
+ if (expression.type === "TemplateLiteral" && expression.expressions.length === 0 && expression.quasis.length) {
80
+ const firstQuasi = expression.quasis[0];
81
+ if (!firstQuasi) return;
82
+ const rewritten = rewriteClassNameTokensWithMap(firstQuasi.cooked ?? "", mapToken);
83
+ firstQuasi.cooked = rewritten;
84
+ firstQuasi.raw = rewritten;
85
+ }
86
+ };
87
+ const rewriteClassNameTokensInElement = (element, classNameProp = "className", mapToken) => {
88
+ const attributes = element.opening.attributes;
89
+ for (const attr of attributes) {
90
+ if (attr.type !== "JSXAttribute") continue;
91
+ if (!isClassAttribute(attr, classNameProp)) continue;
92
+ if (!attr.value) continue;
93
+ if (attr.value.type === "StringLiteral") {
94
+ updateStringLiteral(attr.value, rewriteClassNameTokensWithMap(attr.value.value, mapToken));
95
+ continue;
96
+ }
97
+ if (attr.value.type === "JSXExpressionContainer") {
98
+ const expression = attr.value.expression;
99
+ rewriteStringExpression(expression, mapToken);
100
+ }
101
+ }
102
+ };
103
+ const isClassAttribute = (attr, classNameProp) => {
104
+ return attr.name.type === "Identifier" && attr.name.value === classNameProp;
105
+ };
106
+ const rewriteSelector = (selector, options) => {
107
+ const grouped = parseGroupedSelector(selector);
108
+ if (grouped) {
109
+ const nextEntries = grouped.entries.map((entry$1) => ({
110
+ name: entry$1.name,
111
+ rawValue: rewriteTokenValue(entry$1.rawValue)
112
+ }));
113
+ if (nextEntries.length > 1 || options.expandSingleGroup) return [...nextEntries].sort((a, b) => a.name.localeCompare(b.name)).map((entry$1) => `${grouped.prefix}:${entry$1.name}:${entry$1.rawValue}`);
114
+ const [entry] = nextEntries;
115
+ return [`${grouped.prefix}:{${entry.name}:${entry.rawValue}}`];
116
+ }
117
+ const fragments = splitFragments(selector);
118
+ if (fragments.length < 2) return [selector];
119
+ const rawValue = fragments.at(-1) ?? "";
120
+ const nextValue = rewriteTokenValue(rawValue);
121
+ if (nextValue === rawValue) return [selector];
122
+ return [`${fragments.slice(0, -1).join(":")}:${nextValue}`];
123
+ };
124
+ const rewriteClassNameTokensWithMap = (input, mapToken) => {
125
+ if (!mapToken) return rewriteClassNameTokens(input);
126
+ const selectors = splitSelectors(input).flatMap((selector) => rewriteSelector(selector, { expandSingleGroup: true }));
127
+ let didChange = selectors.join(" ") !== input;
128
+ const mapped = selectors.map((selector) => {
129
+ if (!mapToken) return selector;
130
+ const next = mapToken(selector);
131
+ if (next && next !== selector) {
132
+ didChange = true;
133
+ return next;
134
+ }
135
+ return selector;
136
+ });
137
+ if (!didChange) return input;
138
+ return mapped.join(" ");
139
+ };
140
+ const rewriteTokenValue = (rawValue) => {
141
+ if (!rawValue.startsWith(tokenPrefix)) return rawValue;
142
+ const fragments = rawValue.slice(9).split(".").filter(Boolean);
143
+ if (fragments.length < 2) return rawValue;
144
+ return fragments.slice(1).join(".");
145
+ };
146
+ const updateStringLiteral = (literal, nextValue) => {
147
+ literal.value = nextValue;
148
+ literal.raw = JSON.stringify(nextValue);
149
+ };
150
+ const splitSelectors = (input) => splitOutside(input, " ");
151
+ const splitFragments = (selector) => splitOutside(selector, ":");
152
+ const splitGroupedEntries = (body) => splitOutside(body, ";");
153
+ const splitGroupedEntry = (entry) => splitOnceOutside(entry, ":");
154
+ const parseGroupedSelector = (selector) => {
155
+ if (!selector.endsWith("}")) return null;
156
+ const groupStart = findGroupStart(selector);
157
+ if (groupStart === -1) return null;
158
+ const prefix = selector.slice(0, groupStart);
159
+ const entries = splitGroupedEntries(selector.slice(groupStart + 2, -1)).map((entry) => entry.trim()).filter((entry) => Boolean(entry)).map((entry) => {
160
+ const parts = splitGroupedEntry(entry);
161
+ if (!parts) return null;
162
+ const [name, rawValue] = parts;
163
+ return {
164
+ name: name.trim(),
165
+ rawValue: rawValue.trim()
166
+ };
167
+ }).filter((entry) => Boolean(entry));
168
+ if (!entries.length) return null;
169
+ return {
170
+ prefix,
171
+ entries
172
+ };
173
+ };
174
+ const splitOutside = (input, delimiter) => {
175
+ const results = [];
176
+ let current = "";
177
+ let braceDepth = 0;
178
+ let bracketDepth = 0;
179
+ for (const char of input) {
180
+ if (char === "{") braceDepth += 1;
181
+ if (char === "}") braceDepth = Math.max(0, braceDepth - 1);
182
+ if (char === "[") bracketDepth += 1;
183
+ if (char === "]") bracketDepth = Math.max(0, bracketDepth - 1);
184
+ if (char === delimiter && braceDepth === 0 && bracketDepth === 0) {
185
+ if (current) results.push(current);
186
+ current = "";
187
+ continue;
188
+ }
189
+ current += char;
190
+ }
191
+ if (current) results.push(current);
192
+ return results;
193
+ };
194
+ const splitOnceOutside = (input, delimiter) => {
195
+ let braceDepth = 0;
196
+ let bracketDepth = 0;
197
+ for (let i = 0; i < input.length; i += 1) {
198
+ const char = input[i];
199
+ if (char === "{") braceDepth += 1;
200
+ if (char === "}") braceDepth = Math.max(0, braceDepth - 1);
201
+ if (char === "[") bracketDepth += 1;
202
+ if (char === "]") bracketDepth = Math.max(0, bracketDepth - 1);
203
+ if (char === delimiter && braceDepth === 0 && bracketDepth === 0) return [input.slice(0, i), input.slice(i + 1)];
204
+ }
205
+ return null;
206
+ };
207
+ const findGroupStart = (selector) => {
208
+ let bracketDepth = 0;
209
+ for (let i = 0; i < selector.length - 1; i += 1) {
210
+ const char = selector[i];
211
+ if (char === "[") bracketDepth += 1;
212
+ if (char === "]") bracketDepth = Math.max(0, bracketDepth - 1);
213
+ if (bracketDepth === 0 && selector[i] === ":" && selector[i + 1] === "{") return i;
214
+ }
215
+ return -1;
216
+ };
217
+ const stripImportantSuffix = (fragment) => {
218
+ return fragment && fragment.endsWith("!") ? fragment.slice(0, -1) : fragment;
219
+ };
220
+ const getChildSelector = (fragment) => {
221
+ if (!fragment || !fragment.startsWith("[") || !fragment.endsWith("]")) return null;
222
+ return fragment.slice(1, -1);
223
+ };
224
+ const isSingleWordToken = (token) => /^[a-zA-Z]+$/.test(token);
225
+ const isBossSelectorToken = (selector, api) => {
226
+ if (isSingleWordToken(selector)) return false;
227
+ if (parseGroupedSelector(selector)) return true;
228
+ const rawFragments = splitFragments(selector);
229
+ if (!rawFragments.length) return false;
230
+ const resolveDescriptor = (fragment) => {
231
+ if (getChildSelector(fragment)) return api.dictionary.resolve("child");
232
+ return api.dictionary.resolve(fragment);
233
+ };
234
+ const firstDescriptor = resolveDescriptor(stripImportantSuffix(rawFragments[0])).descriptor;
235
+ if (!firstDescriptor) return false;
236
+ if (rawFragments.length === 1) return firstDescriptor.single === true;
237
+ const path = [];
238
+ for (const [index, fragment] of Object.entries(rawFragments)) {
239
+ const isLast = rawFragments.length === +index + 1;
240
+ if (path.length && isLast) continue;
241
+ const cleanedFragment = stripImportantSuffix(fragment);
242
+ const childSelector = getChildSelector(cleanedFragment);
243
+ if (childSelector) path.push("child", childSelector);
244
+ else path.push(cleanedFragment);
245
+ }
246
+ if (!path.length) return false;
247
+ const lastProp = path.at(-1);
248
+ const lastDescriptor = lastProp ? resolveDescriptor(lastProp).descriptor : null;
249
+ return Boolean(lastDescriptor?.isCSSProp);
250
+ };
251
+ const collectBossClassTokensInSource = (source, options) => {
252
+ const ext = options.filename.split(".").pop() ?? "";
253
+ const isTs = ext === "ts" || ext === "tsx";
254
+ const isJsx = [
255
+ "jsx",
256
+ "tsx",
257
+ "js",
258
+ "mjs",
259
+ "cjs"
260
+ ].includes(ext);
261
+ const parsed = parseSync(source, {
262
+ syntax: isTs ? "typescript" : "ecmascript",
263
+ tsx: isTs && isJsx,
264
+ jsx: !isTs && isJsx
265
+ });
266
+ const tokens = /* @__PURE__ */ new Set();
267
+ const visit = (node, context = {}) => {
268
+ if (!node || typeof node !== "object") return;
269
+ if (Array.isArray(node)) {
270
+ node.forEach((child) => visit(child, context));
271
+ return;
272
+ }
273
+ const current = node;
274
+ if (!context.inModuleSpecifier) {
275
+ if (current.type === "StringLiteral") splitSelectors(current.value).flatMap((selector) => rewriteSelector(selector, { expandSingleGroup: true })).forEach((selector) => {
276
+ if (isBossSelectorToken(selector, options.api)) tokens.add(selector);
277
+ });
278
+ if (current.type === "TemplateLiteral" && Array.isArray(current.expressions) && current.expressions.length === 0 && Array.isArray(current.quasis) && current.quasis.length) {
279
+ const firstQuasi = current.quasis[0];
280
+ if (firstQuasi?.cooked != null) splitSelectors(firstQuasi.cooked).flatMap((selector) => rewriteSelector(selector, { expandSingleGroup: true })).forEach((selector) => {
281
+ if (isBossSelectorToken(selector, options.api)) tokens.add(selector);
282
+ });
283
+ }
284
+ }
285
+ for (const key of Object.keys(current)) {
286
+ const nextContext = (current.type === "ImportDeclaration" || current.type === "ExportAllDeclaration" || current.type === "ExportNamedDeclaration") && key === "source" ? {
287
+ ...context,
288
+ inModuleSpecifier: true
289
+ } : context;
290
+ visit(current[key], nextContext);
291
+ }
292
+ };
293
+ visit(parsed);
294
+ return tokens;
295
+ };
296
+ const collectBossClassTokensInText = (source, options) => {
297
+ const tokens = /* @__PURE__ */ new Set();
298
+ rewriteQuotedSegments(source, ({ value, hasTemplateExpression }) => {
299
+ if (hasTemplateExpression) return null;
300
+ splitSelectors(value).flatMap((selector) => rewriteSelector(selector, { expandSingleGroup: true })).forEach((selector) => {
301
+ if (isBossSelectorToken(selector, options.api)) tokens.add(selector);
302
+ });
303
+ return null;
304
+ });
305
+ return tokens;
306
+ };
307
+ const rewriteQuotedSegments = (input, rewrite) => {
308
+ let output = "";
309
+ let index = 0;
310
+ const length = input.length;
311
+ while (index < length) {
312
+ const char = input[index];
313
+ if (char !== "\"" && char !== "'" && char !== "`") {
314
+ output += char;
315
+ index += 1;
316
+ continue;
317
+ }
318
+ const quote = char;
319
+ const start = index;
320
+ index += 1;
321
+ let value = "";
322
+ let escaped = false;
323
+ let hasTemplateExpression = false;
324
+ while (index < length) {
325
+ const current = input[index];
326
+ if (escaped) {
327
+ value += current;
328
+ escaped = false;
329
+ index += 1;
330
+ continue;
331
+ }
332
+ if (current === "\\") {
333
+ value += current;
334
+ escaped = true;
335
+ index += 1;
336
+ continue;
337
+ }
338
+ if (quote === "`" && current === "$" && input[index + 1] === "{") hasTemplateExpression = true;
339
+ if (current === quote) break;
340
+ value += current;
341
+ index += 1;
342
+ }
343
+ if (index >= length) {
344
+ output += input.slice(start);
345
+ break;
346
+ }
347
+ const replacement = rewrite({
348
+ value,
349
+ quote,
350
+ hasTemplateExpression
351
+ });
352
+ if (replacement === null) output += quote + value + quote;
353
+ else output += quote + replacement + quote;
354
+ index += 1;
355
+ }
356
+ return output;
357
+ };
358
+
359
+ //#endregion
360
+ export { collectBossClassTokensInSource, collectBossClassTokensInText, rewriteClassNameTokensInElement, rewriteClassNameTokensInSource, rewriteClassNameTokensInText, rewriteClassNameTokensWithMap };
@@ -0,0 +1,238 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_api_server = require('../api/server.cjs');
3
+ const require_file = require('../shared/file.cjs');
4
+ const require_boundaries = require('../shared/boundaries.cjs');
5
+ const require_session = require('../tasks/session.cjs');
6
+ const require_framework = require('../shared/framework.cjs');
7
+ const require_classname = require('./classname.cjs');
8
+ const require_classname_strategy = require('./classname-strategy.cjs');
9
+ const require_prepared = require('./prepared.cjs');
10
+ const require_transform = require('./transform.cjs');
11
+ let node_fs_promises = require("node:fs/promises");
12
+ node_fs_promises = require_rolldown_runtime.__toESM(node_fs_promises);
13
+ let node_path = require("node:path");
14
+ node_path = require_rolldown_runtime.__toESM(node_path);
15
+ let lightningcss = require("lightningcss");
16
+
17
+ //#region src/compile/index.ts
18
+ const supportedExtensions = new Set([
19
+ ".js",
20
+ ".jsx",
21
+ ".ts",
22
+ ".tsx",
23
+ ".mjs",
24
+ ".cjs"
25
+ ]);
26
+ async function compileProject(options) {
27
+ const { config, prod } = options;
28
+ const compileConfig = {
29
+ stats: "quick",
30
+ ...config.compile ?? {}
31
+ };
32
+ const content = config.content;
33
+ const baseDir = process.cwd();
34
+ if (!content) throw new Error("compile: config.content is required");
35
+ const root = baseDir;
36
+ const tempOutDir = compileConfig.tempOutDir;
37
+ if (!prod && !tempOutDir) throw new Error("compile.tempOutDir is required when not running in prod mode.");
38
+ const outputRoot = prod ? root : node_path.default.resolve(root, tempOutDir);
39
+ const inputPaths = (await require_file.resolveContentPaths(content)).sort();
40
+ const sourceCache = /* @__PURE__ */ new Map();
41
+ const preparedByFile = /* @__PURE__ */ new Map();
42
+ const preparedRegistry = /* @__PURE__ */ new Map();
43
+ const preparedUsages = [];
44
+ const api = await require_api_server.createApi(config, true);
45
+ api.baseDir = baseDir;
46
+ const classNameStrategy = compileConfig.classNameStrategy ?? false;
47
+ const classNameMapper = classNameStrategy ? require_classname_strategy.createClassNameMapper({
48
+ strategy: classNameStrategy,
49
+ prefix: api.selectorPrefix ?? ""
50
+ }) : null;
51
+ if (classNameMapper) {
52
+ const baseContextToClassName = api.contextToClassName;
53
+ api.contextToClassName = (name, value, contexts, escape = true, _prefix = "") => {
54
+ const raw = baseContextToClassName(name, value, contexts, false, "");
55
+ const mapped = classNameMapper.getOrCreate(raw);
56
+ if (!escape) return mapped;
57
+ return api.camelCaseToDash(api.escapeClassName(mapped));
58
+ };
59
+ const baseClassTokenToSelector = api.classTokenToSelector;
60
+ api.classTokenToSelector = (token) => baseClassTokenToSelector(classNameMapper.getOrCreate(token));
61
+ }
62
+ const sessionStart = await require_session.resolveSessionPayload(baseDir, config, "compile", "start");
63
+ await require_session.emitSession(api, sessionStart);
64
+ await require_session.emitSession(api, {
65
+ ...sessionStart,
66
+ phase: "run"
67
+ });
68
+ const statsMode = compileConfig.stats ?? "quick";
69
+ const start = process.hrtime.bigint();
70
+ const fileResults = [];
71
+ for (const inputPath of inputPaths) {
72
+ if (!(await node_fs_promises.default.stat(inputPath).catch(() => null))?.isFile()) continue;
73
+ const ext = node_path.default.extname(inputPath);
74
+ const source = await node_fs_promises.default.readFile(inputPath, "utf8");
75
+ sourceCache.set(inputPath, source);
76
+ if (classNameMapper) (supportedExtensions.has(ext) ? require_classname.collectBossClassTokensInSource(source, {
77
+ filename: inputPath,
78
+ api
79
+ }) : require_classname.collectBossClassTokensInText(source, { api })).forEach((token) => classNameMapper.getOrCreate(token));
80
+ if (!supportedExtensions.has(ext)) continue;
81
+ const scan = require_prepared.scanPrepared(source, {
82
+ isTs: ext === ".ts" || ext === ".tsx",
83
+ isJsx: ext === ".jsx" || ext === ".tsx" || ext === ".js" || ext === ".mjs" || ext === ".cjs"
84
+ });
85
+ if (scan.definitions.length) {
86
+ const local = /* @__PURE__ */ new Map();
87
+ for (const definition of scan.definitions) {
88
+ local.set(definition.name, {
89
+ definition: definition.definition,
90
+ inlineable: definition.inlineable
91
+ });
92
+ preparedRegistry.set(definition.name, {
93
+ definition: definition.definition,
94
+ inlineable: definition.inlineable
95
+ });
96
+ }
97
+ preparedByFile.set(inputPath, local);
98
+ }
99
+ if (scan.usages.length) for (const usage of scan.usages) preparedUsages.push({
100
+ ...usage,
101
+ file: inputPath
102
+ });
103
+ }
104
+ const preparedGlobal = /* @__PURE__ */ new Map();
105
+ for (const [name, entry] of preparedRegistry.entries()) if (entry.inlineable) preparedGlobal.set(name, entry.definition);
106
+ const preparedRuntime = /* @__PURE__ */ new Set();
107
+ for (const usage of preparedUsages) {
108
+ if (!compileConfig.spread && usage.hasSpread) {
109
+ preparedRuntime.add(usage.name);
110
+ continue;
111
+ }
112
+ if (preparedByFile.get(usage.file)?.get(usage.name)) continue;
113
+ if (preparedRegistry.get(usage.name)?.inlineable) continue;
114
+ preparedRuntime.add(usage.name);
115
+ }
116
+ const processFile = async (inputPath) => {
117
+ if (!(await node_fs_promises.default.stat(inputPath).catch(() => null))?.isFile()) return;
118
+ const ext = node_path.default.extname(inputPath);
119
+ const relativePath = node_path.default.relative(root, inputPath);
120
+ const outputPath = prod ? inputPath : node_path.default.join(outputRoot, relativePath);
121
+ await node_fs_promises.default.mkdir(node_path.default.dirname(outputPath), { recursive: true });
122
+ const source = sourceCache.get(inputPath) ?? await node_fs_promises.default.readFile(inputPath, "utf8");
123
+ if (!supportedExtensions.has(ext)) {
124
+ const parseContent = require_classname.rewriteClassNameTokensInText(source, { mapToken: classNameMapper ? () => void 0 : void 0 });
125
+ await api.trigger("onParse", {
126
+ content: parseContent,
127
+ path: inputPath
128
+ }, (plugin) => plugin.name === "classname");
129
+ if (!prod) if (classNameMapper) {
130
+ const rewritten = require_classname.rewriteClassNameTokensInText(source, { mapToken: (token) => classNameMapper.get(token) });
131
+ await node_fs_promises.default.writeFile(outputPath, rewritten, "utf8");
132
+ } else await node_fs_promises.default.copyFile(inputPath, outputPath);
133
+ fileResults.push({
134
+ file: inputPath,
135
+ processed: false,
136
+ copied: !prod,
137
+ needsRuntime: false,
138
+ needsValueHelper: false,
139
+ replacedElements: 0
140
+ });
141
+ return;
142
+ }
143
+ const classNameSource = require_classname.rewriteClassNameTokensInSource(source, {
144
+ filename: inputPath,
145
+ classNameProp: require_framework.getClassNameProp(api.framework),
146
+ mapToken: classNameMapper ? () => void 0 : void 0
147
+ });
148
+ await api.trigger("onParse", {
149
+ content: classNameSource,
150
+ path: inputPath
151
+ }, (plugin) => plugin.name === "classname");
152
+ const transformed = await require_transform.transformSource(source, {
153
+ api,
154
+ compile: compileConfig,
155
+ filename: inputPath,
156
+ preparedGlobal,
157
+ preparedLocal: new Map(Array.from(preparedByFile.get(inputPath)?.entries() ?? []).map(([key, value]) => [key, value.definition])),
158
+ preparedRuntime,
159
+ classNameMapper
160
+ });
161
+ fileResults.push({
162
+ file: inputPath,
163
+ processed: true,
164
+ copied: false,
165
+ needsRuntime: transformed.needsRuntime,
166
+ needsValueHelper: transformed.needsValueHelper,
167
+ replacedElements: transformed.replacedElements
168
+ });
169
+ await node_fs_promises.default.writeFile(outputPath, transformed.code, "utf8");
170
+ };
171
+ if (classNameStrategy === "shortest" || classNameStrategy === "unicode") for (const inputPath of inputPaths) await processFile(inputPath);
172
+ else await Promise.all(inputPaths.map(processFile));
173
+ let cssBytes = 0;
174
+ let cssWritten = false;
175
+ let stylesheetPath = null;
176
+ if (!prod && api.css.text.trim()) {
177
+ const resolvedStylesheetPath = config.stylesheetPath ?? node_path.default.join(root, config.configDir ?? ".bo$$", "styles.css");
178
+ const outputs = (await require_boundaries.resolveBoundaryOutputs(api, {
179
+ rootDir: root,
180
+ stylesheetPath: resolvedStylesheetPath,
181
+ boundaries: config.css?.boundaries
182
+ })).outputs.map((output) => {
183
+ const relative = node_path.default.relative(root, output.path);
184
+ return {
185
+ path: node_path.default.join(outputRoot, relative),
186
+ text: output.text
187
+ };
188
+ });
189
+ const globalOutputPath = node_path.default.resolve(node_path.default.join(outputRoot, node_path.default.relative(root, resolvedStylesheetPath)));
190
+ const outputSizes = /* @__PURE__ */ new Map();
191
+ for (const output of outputs) {
192
+ const minified = (0, lightningcss.transform)({
193
+ code: Buffer.from(output.text),
194
+ filename: output.path,
195
+ minify: true
196
+ });
197
+ await node_fs_promises.default.mkdir(node_path.default.dirname(output.path), { recursive: true });
198
+ await node_fs_promises.default.writeFile(output.path, minified.code.toString(), "utf8");
199
+ outputSizes.set(node_path.default.resolve(output.path), minified.code.length);
200
+ }
201
+ const globalOutput = outputs.find((output) => node_path.default.resolve(output.path) === globalOutputPath);
202
+ cssBytes = globalOutput ? outputSizes.get(node_path.default.resolve(globalOutput.path)) ?? 0 : 0;
203
+ cssWritten = true;
204
+ stylesheetPath = globalOutput?.path ?? globalOutputPath;
205
+ }
206
+ const durationMs = Number(process.hrtime.bigint() - start) / 1e6;
207
+ const runtimeFiles = fileResults.filter((result$1) => result$1.needsRuntime).map((result$1) => result$1.file);
208
+ const valueHelperFiles = fileResults.filter((result$1) => result$1.needsValueHelper).map((result$1) => result$1.file);
209
+ const filesProcessed = fileResults.filter((result$1) => result$1.processed).length;
210
+ const filesCopied = fileResults.filter((result$1) => result$1.copied).length;
211
+ const filesTotal = fileResults.length;
212
+ const filesSkipped = filesTotal - filesProcessed - filesCopied;
213
+ const elementsReplaced = fileResults.reduce((total, result$1) => total + result$1.replacedElements, 0);
214
+ const result = {
215
+ statsMode,
216
+ stats: {
217
+ outputMode: prod ? "prod" : "temp",
218
+ outputDir: outputRoot,
219
+ runtimeFree: runtimeFiles.length === 0,
220
+ runtimeFiles: runtimeFiles.map((file) => node_path.default.relative(root, file)),
221
+ valueHelperFiles: valueHelperFiles.map((file) => node_path.default.relative(root, file)),
222
+ filesProcessed,
223
+ filesCopied,
224
+ filesSkipped,
225
+ filesTotal,
226
+ elementsReplaced,
227
+ durationMs,
228
+ cssBytes,
229
+ cssWritten,
230
+ stylesheetPath
231
+ }
232
+ };
233
+ await require_session.emitSession(api, await require_session.resolveSessionPayload(baseDir, config, "compile", "stop"));
234
+ return result;
235
+ }
236
+
237
+ //#endregion
238
+ exports.compileProject = compileProject;