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,113 @@
1
+ import { createApi } from "../api/server.mjs";
2
+ import { resolveContentPaths } from "../shared/file.mjs";
3
+ import { resolveBoundaryOutputs } from "../shared/boundaries.mjs";
4
+ import { emitSession, resolveSessionPayload } from "./session.mjs";
5
+ import { loadConfig } from "../api/config.mjs";
6
+ import { cache, setCache } from "../transform/cache.mjs";
7
+ import processFile from "../transform/processFile.mjs";
8
+ import path from "node:path";
9
+ import postcss from "postcss";
10
+
11
+ //#region src/tasks/postcss.ts
12
+ const configPromises = /* @__PURE__ */ new Map();
13
+ const apiCache = /* @__PURE__ */ new Map();
14
+ const knownFiles = /* @__PURE__ */ new Map();
15
+ const runQueues = /* @__PURE__ */ new Map();
16
+ const sessionStarted = /* @__PURE__ */ new Set();
17
+ const isTruthyEnv = (value) => Boolean(value) && value !== "0" && value !== "false";
18
+ const isTurbopackEnv = () => [
19
+ process.env.TURBOPACK,
20
+ process.env.__NEXT_TURBOPACK,
21
+ process.env.__NEXT_TURBOPACK__,
22
+ process.env.NEXT_TURBOPACK
23
+ ].some(isTruthyEnv);
24
+ const resolveConfig = (baseDir) => {
25
+ const key = baseDir ?? "__default__";
26
+ if (!configPromises.has(key)) configPromises.set(key, loadConfig(baseDir));
27
+ return configPromises.get(key);
28
+ };
29
+ const resolveApi = async (baseDir) => {
30
+ const key = baseDir ?? "__default__";
31
+ if (!apiCache.has(key)) apiCache.set(key, (async () => {
32
+ const api = await createApi(await resolveConfig(baseDir), true);
33
+ api.baseDir = baseDir ?? process.cwd();
34
+ return { api };
35
+ })());
36
+ return apiCache.get(key);
37
+ };
38
+ const runPostcss = async (root, result, options = {}) => {
39
+ const dirDependencies = options.dirDependencies ?? !isTurbopackEnv();
40
+ const baseDir = options.baseDir;
41
+ const { messages } = result;
42
+ const config = await resolveConfig(baseDir);
43
+ const { api } = await resolveApi(baseDir);
44
+ const { content, stylesheetPath } = api;
45
+ const queueKey = baseDir ?? "__default__";
46
+ const run = (runQueues.get(queueKey) ?? Promise.resolve()).catch(() => {}).then(async () => {
47
+ const inputFile = root.source?.input?.file;
48
+ const fromFile = result.opts?.from;
49
+ const filePath = typeof inputFile === "string" ? inputFile : typeof fromFile === "string" ? fromFile : void 0;
50
+ const resolvedFile = filePath ? path.resolve(filePath) : null;
51
+ const resolvedStylesheet = path.resolve(stylesheetPath);
52
+ if (resolvedFile && resolvedFile !== resolvedStylesheet && !resolvedFile.endsWith(".boss.css")) return;
53
+ if (!sessionStarted.has(queueKey)) {
54
+ sessionStarted.add(queueKey);
55
+ await emitSession(api, await resolveSessionPayload(baseDir ?? process.cwd(), config, "postcss", "start"));
56
+ }
57
+ await emitSession(api, await resolveSessionPayload(baseDir ?? process.cwd(), config, "postcss", "run"));
58
+ const resolvedPaths = (await resolveContentPaths(content)).map((entry) => path.resolve(entry));
59
+ const previousFiles = knownFiles.get(queueKey) ?? /* @__PURE__ */ new Set();
60
+ const nextFiles = new Set(resolvedPaths);
61
+ for (const file of previousFiles) if (!nextFiles.has(file)) {
62
+ api.css?.removeSource?.(file);
63
+ cache.delete(file);
64
+ }
65
+ knownFiles.set(queueKey, nextFiles);
66
+ const promises = [];
67
+ resolvedPaths.forEach((file) => {
68
+ if (setCache(file, { isFile: true })) messages.push({
69
+ type: "dependency",
70
+ file
71
+ });
72
+ if (dirDependencies) {
73
+ const dir = path.dirname(file);
74
+ if (!cache.has(dir)) {
75
+ messages.push({
76
+ type: "dir-dependency",
77
+ dir
78
+ });
79
+ setCache(dir, { isFile: false });
80
+ }
81
+ }
82
+ promises.push(processFile(file));
83
+ });
84
+ const processedFiles = await Promise.allSettled(promises);
85
+ const onParsePromises = [];
86
+ for (const settled of processedFiles) {
87
+ if (settled.status !== "fulfilled") continue;
88
+ const processed = settled.value;
89
+ const value = processed?.value;
90
+ if (!value || !processed?.changed) continue;
91
+ const changedPath = value.path ? path.resolve(value.path) : null;
92
+ if (changedPath) api.css?.removeSource?.(changedPath);
93
+ onParsePromises.push(api.trigger("onParse", value));
94
+ }
95
+ await Promise.allSettled(onParsePromises);
96
+ const boundaryResult = await resolveBoundaryOutputs(api, {
97
+ rootDir: baseDir ?? process.cwd(),
98
+ stylesheetPath,
99
+ boundaries: config.css?.boundaries
100
+ });
101
+ const outputText = new Map(boundaryResult.outputs.map((output) => [path.resolve(output.path), output.text])).get(resolvedFile ?? resolvedStylesheet);
102
+ if (outputText !== void 0) result.root = postcss.parse(outputText, result.opts);
103
+ if (api.strategy !== "classname-only") {
104
+ api.file.js.write();
105
+ if (api.file.native?.hasContent) api.file.native.write();
106
+ }
107
+ });
108
+ runQueues.set(queueKey, run);
109
+ await run;
110
+ };
111
+
112
+ //#endregion
113
+ export { runPostcss };
@@ -0,0 +1,46 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ let node_fs_promises = require("node:fs/promises");
3
+ node_fs_promises = require_rolldown_runtime.__toESM(node_fs_promises);
4
+ let node_path = require("node:path");
5
+ node_path = require_rolldown_runtime.__toESM(node_path);
6
+
7
+ //#region src/tasks/session.ts
8
+ const hasFile = async (filePath) => {
9
+ try {
10
+ await node_fs_promises.default.access(filePath);
11
+ return true;
12
+ } catch {
13
+ return false;
14
+ }
15
+ };
16
+ const resolveConfigPath = async (baseDir, configDir) => {
17
+ const primary = node_path.default.join(baseDir, configDir, "config.js");
18
+ if (await hasFile(primary)) return primary;
19
+ if (configDir === ".bo$$") {
20
+ const fallback = node_path.default.join(baseDir, "src", ".bo$$", "config.js");
21
+ if (await hasFile(fallback)) return fallback;
22
+ }
23
+ return null;
24
+ };
25
+ const resolveRuntimePath = (baseDir, config) => {
26
+ const runtimeDir = config.folder ?? config.configDir ?? ".bo$$";
27
+ const basePath = node_path.default.isAbsolute(runtimeDir) ? runtimeDir : node_path.default.join(baseDir, runtimeDir);
28
+ return node_path.default.join(basePath, "index.js");
29
+ };
30
+ const resolveSessionPayload = async (baseDir, config, kind, phase) => {
31
+ return {
32
+ phase,
33
+ kind,
34
+ baseDir,
35
+ configPath: await resolveConfigPath(baseDir, config.configDir ?? ".bo$$"),
36
+ runtimePath: resolveRuntimePath(baseDir, config)
37
+ };
38
+ };
39
+ const emitSession = async (api, payload) => {
40
+ if (!api?.trigger) return;
41
+ await api.trigger("onSession", payload);
42
+ };
43
+
44
+ //#endregion
45
+ exports.emitSession = emitSession;
46
+ exports.resolveSessionPayload = resolveSessionPayload;
@@ -0,0 +1,42 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+
4
+ //#region src/tasks/session.ts
5
+ const hasFile = async (filePath) => {
6
+ try {
7
+ await fs.access(filePath);
8
+ return true;
9
+ } catch {
10
+ return false;
11
+ }
12
+ };
13
+ const resolveConfigPath = async (baseDir, configDir) => {
14
+ const primary = path.join(baseDir, configDir, "config.js");
15
+ if (await hasFile(primary)) return primary;
16
+ if (configDir === ".bo$$") {
17
+ const fallback = path.join(baseDir, "src", ".bo$$", "config.js");
18
+ if (await hasFile(fallback)) return fallback;
19
+ }
20
+ return null;
21
+ };
22
+ const resolveRuntimePath = (baseDir, config) => {
23
+ const runtimeDir = config.folder ?? config.configDir ?? ".bo$$";
24
+ const basePath = path.isAbsolute(runtimeDir) ? runtimeDir : path.join(baseDir, runtimeDir);
25
+ return path.join(basePath, "index.js");
26
+ };
27
+ const resolveSessionPayload = async (baseDir, config, kind, phase) => {
28
+ return {
29
+ phase,
30
+ kind,
31
+ baseDir,
32
+ configPath: await resolveConfigPath(baseDir, config.configDir ?? ".bo$$"),
33
+ runtimePath: resolveRuntimePath(baseDir, config)
34
+ };
35
+ };
36
+ const emitSession = async (api, payload) => {
37
+ if (!api?.trigger) return;
38
+ await api.trigger("onSession", payload);
39
+ };
40
+
41
+ //#endregion
42
+ export { emitSession, resolveSessionPayload };
@@ -0,0 +1,102 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_api_server = require('../api/server.cjs');
3
+ const require_session = require('./session.cjs');
4
+ const require_build = require('./build.cjs');
5
+ let node_path = require("node:path");
6
+ node_path = require_rolldown_runtime.__toESM(node_path);
7
+ let _parcel_watcher = require("@parcel/watcher");
8
+ _parcel_watcher = require_rolldown_runtime.__toESM(_parcel_watcher);
9
+
10
+ //#region src/tasks/watch.ts
11
+ const DEFAULT_DEBOUNCE_MS = 80;
12
+ const runWatch = async (userConfig, options = {}) => {
13
+ const baseDir = options.baseDir ?? process.cwd();
14
+ const debounceMs = options.debounceMs ?? DEFAULT_DEBOUNCE_MS;
15
+ const { config: buildConfig, folderPath, stylesheetPath } = require_build.resolveBuildConfig(userConfig, baseDir);
16
+ if (!buildConfig.content) throw new Error("boss watch requires config.content in .bo$$/config.js or package.json.");
17
+ const api = await require_api_server.createApi(buildConfig, true);
18
+ api.baseDir = baseDir;
19
+ await require_session.emitSession(api, await require_session.resolveSessionPayload(baseDir, buildConfig, "watch", "start"));
20
+ const ignoredDirs = new Set([
21
+ node_path.default.resolve(baseDir, "node_modules"),
22
+ node_path.default.resolve(baseDir, ".git"),
23
+ node_path.default.resolve(baseDir, "dist"),
24
+ folderPath
25
+ ]);
26
+ if (buildConfig.configDir) ignoredDirs.add(node_path.default.resolve(baseDir, buildConfig.configDir));
27
+ if (buildConfig.compile?.tempOutDir) ignoredDirs.add(node_path.default.resolve(baseDir, buildConfig.compile.tempOutDir));
28
+ const ignoredFiles = /* @__PURE__ */ new Set();
29
+ let ignoredBoundaryFiles = /* @__PURE__ */ new Set();
30
+ if (stylesheetPath) ignoredFiles.add(node_path.default.resolve(stylesheetPath));
31
+ const ignoreGlobs = [
32
+ "**/node_modules/**",
33
+ "**/.git/**",
34
+ "**/dist/**"
35
+ ];
36
+ for (const dir of ignoredDirs) {
37
+ const relative = node_path.default.relative(baseDir, dir).replace(/\\/g, "/");
38
+ if (!relative || relative.startsWith("..")) continue;
39
+ ignoreGlobs.push(`${relative}/**`);
40
+ }
41
+ for (const file of ignoredFiles) {
42
+ const relative = node_path.default.relative(baseDir, file).replace(/\\/g, "/");
43
+ if (!relative || relative.startsWith("..")) continue;
44
+ ignoreGlobs.push(relative);
45
+ }
46
+ const shouldIgnore = (filePath) => {
47
+ const resolved = node_path.default.resolve(filePath);
48
+ if (ignoredFiles.has(resolved)) return true;
49
+ if (ignoredBoundaryFiles.has(resolved)) return true;
50
+ for (const dir of ignoredDirs) if (resolved === dir || resolved.startsWith(dir + node_path.default.sep)) return true;
51
+ return false;
52
+ };
53
+ let running = false;
54
+ let pending = false;
55
+ let timer = null;
56
+ const runOnce = async () => {
57
+ running = true;
58
+ try {
59
+ await require_session.emitSession(api, await require_session.resolveSessionPayload(baseDir, buildConfig, "watch", "run"));
60
+ const result = await require_build.runBuild(buildConfig, { baseDir });
61
+ ignoredBoundaryFiles = new Set((result.boundaryPaths ?? []).map((entry) => node_path.default.resolve(entry)));
62
+ options.onBuild?.(result);
63
+ } catch (error) {
64
+ const err = error instanceof Error ? error : /* @__PURE__ */ new Error("boss watch build failed.");
65
+ options.onError?.(err);
66
+ } finally {
67
+ running = false;
68
+ if (pending) {
69
+ pending = false;
70
+ scheduleBuild();
71
+ }
72
+ }
73
+ };
74
+ const scheduleBuild = () => {
75
+ pending = true;
76
+ if (running) return;
77
+ if (timer) return;
78
+ timer = setTimeout(() => {
79
+ timer = null;
80
+ if (!pending) return;
81
+ pending = false;
82
+ runOnce();
83
+ }, debounceMs);
84
+ };
85
+ scheduleBuild();
86
+ const subscription = await _parcel_watcher.default.subscribe(baseDir, (error, events) => {
87
+ if (error) {
88
+ options.onError?.(error);
89
+ return;
90
+ }
91
+ if (!events.some((event) => !shouldIgnore(event.path))) return;
92
+ scheduleBuild();
93
+ }, { ignore: ignoreGlobs });
94
+ options.onReady?.();
95
+ return { close: async () => {
96
+ await subscription.unsubscribe();
97
+ await require_session.emitSession(api, await require_session.resolveSessionPayload(baseDir, buildConfig, "watch", "stop"));
98
+ } };
99
+ };
100
+
101
+ //#endregion
102
+ exports.runWatch = runWatch;
@@ -0,0 +1,99 @@
1
+ import { createApi } from "../api/server.mjs";
2
+ import { emitSession, resolveSessionPayload } from "./session.mjs";
3
+ import { resolveBuildConfig, runBuild } from "./build.mjs";
4
+ import path from "node:path";
5
+ import watcher from "@parcel/watcher";
6
+
7
+ //#region src/tasks/watch.ts
8
+ const DEFAULT_DEBOUNCE_MS = 80;
9
+ const runWatch = async (userConfig, options = {}) => {
10
+ const baseDir = options.baseDir ?? process.cwd();
11
+ const debounceMs = options.debounceMs ?? DEFAULT_DEBOUNCE_MS;
12
+ const { config: buildConfig, folderPath, stylesheetPath } = resolveBuildConfig(userConfig, baseDir);
13
+ if (!buildConfig.content) throw new Error("boss watch requires config.content in .bo$$/config.js or package.json.");
14
+ const api = await createApi(buildConfig, true);
15
+ api.baseDir = baseDir;
16
+ await emitSession(api, await resolveSessionPayload(baseDir, buildConfig, "watch", "start"));
17
+ const ignoredDirs = new Set([
18
+ path.resolve(baseDir, "node_modules"),
19
+ path.resolve(baseDir, ".git"),
20
+ path.resolve(baseDir, "dist"),
21
+ folderPath
22
+ ]);
23
+ if (buildConfig.configDir) ignoredDirs.add(path.resolve(baseDir, buildConfig.configDir));
24
+ if (buildConfig.compile?.tempOutDir) ignoredDirs.add(path.resolve(baseDir, buildConfig.compile.tempOutDir));
25
+ const ignoredFiles = /* @__PURE__ */ new Set();
26
+ let ignoredBoundaryFiles = /* @__PURE__ */ new Set();
27
+ if (stylesheetPath) ignoredFiles.add(path.resolve(stylesheetPath));
28
+ const ignoreGlobs = [
29
+ "**/node_modules/**",
30
+ "**/.git/**",
31
+ "**/dist/**"
32
+ ];
33
+ for (const dir of ignoredDirs) {
34
+ const relative = path.relative(baseDir, dir).replace(/\\/g, "/");
35
+ if (!relative || relative.startsWith("..")) continue;
36
+ ignoreGlobs.push(`${relative}/**`);
37
+ }
38
+ for (const file of ignoredFiles) {
39
+ const relative = path.relative(baseDir, file).replace(/\\/g, "/");
40
+ if (!relative || relative.startsWith("..")) continue;
41
+ ignoreGlobs.push(relative);
42
+ }
43
+ const shouldIgnore = (filePath) => {
44
+ const resolved = path.resolve(filePath);
45
+ if (ignoredFiles.has(resolved)) return true;
46
+ if (ignoredBoundaryFiles.has(resolved)) return true;
47
+ for (const dir of ignoredDirs) if (resolved === dir || resolved.startsWith(dir + path.sep)) return true;
48
+ return false;
49
+ };
50
+ let running = false;
51
+ let pending = false;
52
+ let timer = null;
53
+ const runOnce = async () => {
54
+ running = true;
55
+ try {
56
+ await emitSession(api, await resolveSessionPayload(baseDir, buildConfig, "watch", "run"));
57
+ const result = await runBuild(buildConfig, { baseDir });
58
+ ignoredBoundaryFiles = new Set((result.boundaryPaths ?? []).map((entry) => path.resolve(entry)));
59
+ options.onBuild?.(result);
60
+ } catch (error) {
61
+ const err = error instanceof Error ? error : /* @__PURE__ */ new Error("boss watch build failed.");
62
+ options.onError?.(err);
63
+ } finally {
64
+ running = false;
65
+ if (pending) {
66
+ pending = false;
67
+ scheduleBuild();
68
+ }
69
+ }
70
+ };
71
+ const scheduleBuild = () => {
72
+ pending = true;
73
+ if (running) return;
74
+ if (timer) return;
75
+ timer = setTimeout(() => {
76
+ timer = null;
77
+ if (!pending) return;
78
+ pending = false;
79
+ runOnce();
80
+ }, debounceMs);
81
+ };
82
+ scheduleBuild();
83
+ const subscription = await watcher.subscribe(baseDir, (error, events) => {
84
+ if (error) {
85
+ options.onError?.(error);
86
+ return;
87
+ }
88
+ if (!events.some((event) => !shouldIgnore(event.path))) return;
89
+ scheduleBuild();
90
+ }, { ignore: ignoreGlobs });
91
+ options.onReady?.();
92
+ return { close: async () => {
93
+ await subscription.unsubscribe();
94
+ await emitSession(api, await resolveSessionPayload(baseDir, buildConfig, "watch", "stop"));
95
+ } };
96
+ };
97
+
98
+ //#endregion
99
+ export { runWatch };
@@ -0,0 +1,24 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ let node_fs = require("node:fs");
3
+ node_fs = require_rolldown_runtime.__toESM(node_fs);
4
+
5
+ //#region src/transform/cache.ts
6
+ const cache = /* @__PURE__ */ new Map();
7
+ const setCache = (path, data) => {
8
+ const cachedValue = cache.get(path);
9
+ const newValue = {
10
+ content: "",
11
+ css: "",
12
+ mtime: 0,
13
+ isFile: true,
14
+ path,
15
+ ...cachedValue,
16
+ ...data
17
+ };
18
+ cache.set(path, newValue);
19
+ return Boolean(cachedValue);
20
+ };
21
+
22
+ //#endregion
23
+ exports.cache = cache;
24
+ exports.setCache = setCache;
@@ -0,0 +1,21 @@
1
+ import fs from "node:fs";
2
+
3
+ //#region src/transform/cache.ts
4
+ const cache = /* @__PURE__ */ new Map();
5
+ const setCache = (path, data) => {
6
+ const cachedValue = cache.get(path);
7
+ const newValue = {
8
+ content: "",
9
+ css: "",
10
+ mtime: 0,
11
+ isFile: true,
12
+ path,
13
+ ...cachedValue,
14
+ ...data
15
+ };
16
+ cache.set(path, newValue);
17
+ return Boolean(cachedValue);
18
+ };
19
+
20
+ //#endregion
21
+ export { cache, setCache };
@@ -0,0 +1,26 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_cache = require('./cache.cjs');
3
+ let node_fs_promises = require("node:fs/promises");
4
+ node_fs_promises = require_rolldown_runtime.__toESM(node_fs_promises);
5
+
6
+ //#region src/transform/processFile.ts
7
+ async function processFile(path) {
8
+ const cachedValue = require_cache.cache.get(path);
9
+ const mtime = await node_fs_promises.default.stat(path).then((stats) => stats.mtimeMs);
10
+ let changed = false;
11
+ if (!cachedValue || cachedValue.mtime < mtime) {
12
+ require_cache.setCache(path, {
13
+ content: await node_fs_promises.default.readFile(path, "utf-8"),
14
+ mtime,
15
+ isFile: true
16
+ });
17
+ changed = true;
18
+ }
19
+ return {
20
+ value: require_cache.cache.get(path),
21
+ changed
22
+ };
23
+ }
24
+
25
+ //#endregion
26
+ exports.default = processFile;
@@ -0,0 +1,24 @@
1
+ import { cache, setCache } from "./cache.mjs";
2
+ import fs from "node:fs/promises";
3
+
4
+ //#region src/transform/processFile.ts
5
+ async function processFile(path) {
6
+ const cachedValue = cache.get(path);
7
+ const mtime = await fs.stat(path).then((stats) => stats.mtimeMs);
8
+ let changed = false;
9
+ if (!cachedValue || cachedValue.mtime < mtime) {
10
+ setCache(path, {
11
+ content: await fs.readFile(path, "utf-8"),
12
+ mtime,
13
+ isFile: true
14
+ });
15
+ changed = true;
16
+ }
17
+ return {
18
+ value: cache.get(path),
19
+ changed
20
+ };
21
+ }
22
+
23
+ //#endregion
24
+ export { processFile as default };
@@ -0,0 +1,65 @@
1
+ const require_vars = require('./vars.cjs');
2
+
3
+ //#region src/use/token/browser.ts
4
+ let currentApi = null;
5
+ const tokenVarsCache = /* @__PURE__ */ new WeakMap();
6
+ const getTokenVars = (api) => {
7
+ if (!api) return null;
8
+ const cached = tokenVarsCache.get(api);
9
+ if (cached) return cached;
10
+ const builder = require_vars.createTokenVars({
11
+ prefix: api.selectorPrefix ?? "",
12
+ toValue: (value, property) => {
13
+ const resolved = api.dictionary.toValue(value, property);
14
+ if (typeof resolved === "number" || typeof resolved === "string") return resolved;
15
+ if (resolved == null) return null;
16
+ return String(resolved);
17
+ }
18
+ });
19
+ tokenVarsCache.set(api, builder);
20
+ return builder;
21
+ };
22
+ const tokenVars = (input) => {
23
+ const builder = getTokenVars(currentApi);
24
+ return builder ? builder(input) : {};
25
+ };
26
+ const onInit = (api) => {
27
+ currentApi = api;
28
+ if (!api.tokenVars) api.tokenVars = tokenVars;
29
+ };
30
+ const create = (currentKey = "$$.token") => {
31
+ const baseFn = (() => currentKey);
32
+ return new Proxy(baseFn, { get(target, key) {
33
+ if (key === "IS_TOKEN_FN") return true;
34
+ return typeof key === "string" ? create(`${target()}.${key}`) : void 0;
35
+ } });
36
+ };
37
+ const tokenPaths = /* @__PURE__ */ new Set();
38
+ const isTokenFn = (value) => {
39
+ return typeof value === "function" && Boolean(value.IS_TOKEN_FN);
40
+ };
41
+ const onBrowserObjectStart = (api, { input }) => {
42
+ const isClassnameFirst = api.strategy === "classname-first";
43
+ const mutableInput = input;
44
+ for (const prop in mutableInput) {
45
+ const value = mutableInput[prop];
46
+ if (isTokenFn(value)) {
47
+ const path = value().replace("$$.token.", "");
48
+ if (isClassnameFirst) mutableInput[prop] = path.split(".").slice(1).join(".");
49
+ else mutableInput[prop] = `var(--${path.replace(/\./g, "-")})`;
50
+ } else if (tokenPaths.has(`${prop}.${mutableInput[prop]}`)) {
51
+ if (!isClassnameFirst) mutableInput[prop] = `var(--${prop}-${String(mutableInput[prop]).replace("$$.token.", "").replace(/\./g, "-")})`;
52
+ } else if (typeof value === "string" && value.startsWith("$$.token.")) {
53
+ const path = value.replace("$$.token.", "");
54
+ if (isClassnameFirst) mutableInput[prop] = path.split(".").slice(1).join(".");
55
+ else mutableInput[prop] = `var(--${path.replace(/\./g, "-")})`;
56
+ }
57
+ }
58
+ };
59
+
60
+ //#endregion
61
+ exports.create = create;
62
+ exports.onBrowserObjectStart = onBrowserObjectStart;
63
+ exports.onInit = onInit;
64
+ exports.tokenPaths = tokenPaths;
65
+ exports.tokenVars = tokenVars;
@@ -0,0 +1,61 @@
1
+ import { createTokenVars } from "./vars.mjs";
2
+
3
+ //#region src/use/token/browser.ts
4
+ let currentApi = null;
5
+ const tokenVarsCache = /* @__PURE__ */ new WeakMap();
6
+ const getTokenVars = (api) => {
7
+ if (!api) return null;
8
+ const cached = tokenVarsCache.get(api);
9
+ if (cached) return cached;
10
+ const builder = createTokenVars({
11
+ prefix: api.selectorPrefix ?? "",
12
+ toValue: (value, property) => {
13
+ const resolved = api.dictionary.toValue(value, property);
14
+ if (typeof resolved === "number" || typeof resolved === "string") return resolved;
15
+ if (resolved == null) return null;
16
+ return String(resolved);
17
+ }
18
+ });
19
+ tokenVarsCache.set(api, builder);
20
+ return builder;
21
+ };
22
+ const tokenVars = (input) => {
23
+ const builder = getTokenVars(currentApi);
24
+ return builder ? builder(input) : {};
25
+ };
26
+ const onInit = (api) => {
27
+ currentApi = api;
28
+ if (!api.tokenVars) api.tokenVars = tokenVars;
29
+ };
30
+ const create = (currentKey = "$$.token") => {
31
+ const baseFn = (() => currentKey);
32
+ return new Proxy(baseFn, { get(target, key) {
33
+ if (key === "IS_TOKEN_FN") return true;
34
+ return typeof key === "string" ? create(`${target()}.${key}`) : void 0;
35
+ } });
36
+ };
37
+ const tokenPaths = /* @__PURE__ */ new Set();
38
+ const isTokenFn = (value) => {
39
+ return typeof value === "function" && Boolean(value.IS_TOKEN_FN);
40
+ };
41
+ const onBrowserObjectStart = (api, { input }) => {
42
+ const isClassnameFirst = api.strategy === "classname-first";
43
+ const mutableInput = input;
44
+ for (const prop in mutableInput) {
45
+ const value = mutableInput[prop];
46
+ if (isTokenFn(value)) {
47
+ const path = value().replace("$$.token.", "");
48
+ if (isClassnameFirst) mutableInput[prop] = path.split(".").slice(1).join(".");
49
+ else mutableInput[prop] = `var(--${path.replace(/\./g, "-")})`;
50
+ } else if (tokenPaths.has(`${prop}.${mutableInput[prop]}`)) {
51
+ if (!isClassnameFirst) mutableInput[prop] = `var(--${prop}-${String(mutableInput[prop]).replace("$$.token.", "").replace(/\./g, "-")})`;
52
+ } else if (typeof value === "string" && value.startsWith("$$.token.")) {
53
+ const path = value.replace("$$.token.", "");
54
+ if (isClassnameFirst) mutableInput[prop] = path.split(".").slice(1).join(".");
55
+ else mutableInput[prop] = `var(--${path.replace(/\./g, "-")})`;
56
+ }
57
+ }
58
+ };
59
+
60
+ //#endregion
61
+ export { create, onBrowserObjectStart, onInit, tokenPaths, tokenVars };