@barocss/server 0.4.0 → 0.5.0

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.
package/dist/index.cjs CHANGED
@@ -1,2 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@barocss/kit");class n{constructor(e={}){this.context=s.createContext(e)}parseClass(e){return s.parseClassToAst(e,this.context)}generateCss(e){return s.generateCssRules(e,this.context).map(({css:t})=>t).filter(Boolean).join(`
2
- `)}generateCssForClasses(e){return e.map(t=>({className:t,css:this.generateCss(t)}))}}exports.ServerRuntime=n;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@barocss/kit");class l{constructor(s={}){this.context=a.createContext(s)}parseClass(s){return a.parseClassToAst(s,this.context)}generateCss(s){const r=a.generateCssRules(s,this.context),t=new Set(r.flatMap(({rootCssList:e})=>e).filter(Boolean)),c=r.map(({css:e})=>e).filter(Boolean),o=this.colorVarsBlock([...t,...c].join(`
2
+ `));return[...o?[o]:[],...t,...c].join(`
3
+ `)}colorVarsBlock(s){const r=e=>[...e.matchAll(/var\((--[\w-]*color-[\w-]+)/g)].map(n=>n[1]),t=r(s);if(t.length===0)return"";const c=new Map;for(const e of this.context.themeToCssVars().matchAll(/^\s*(--[\w-]+):\s*(.+);$/gm))c.set(e[1],e[2]);const o=new Map;for(;t.length;){const e=t.pop(),n=c.get(e);n===void 0||o.has(e)||(o.set(e,n),t.push(...r(n)))}return o.size===0?"":`:root,:host {
4
+ `+[...o].map(([e,n])=>` ${e}: ${n};`).join(`
5
+ `)+`
6
+ }`}generateCssForClasses(s){return s.map(t=>({className:t,css:this.generateCss(t)}))}}exports.ServerRuntime=l;
package/dist/index.d.ts CHANGED
@@ -16,6 +16,11 @@ export declare class ServerRuntime {
16
16
  * Generate CSS for a class name
17
17
  */
18
18
  generateCss(className: string): string;
19
+ /**
20
+ * #228: theme colours are emitted as var(--color-*). Define only the ones this output references
21
+ * (the full theme block is large), including --color-* vars those definitions reference in turn.
22
+ */
23
+ private colorVarsBlock;
19
24
  /**
20
25
  * Parse multiple classes and return their CSS
21
26
  */
package/dist/index.es.js CHANGED
@@ -1,31 +1,52 @@
1
- import { createContext as r, parseClassToAst as n, generateCssRules as o } from "@barocss/kit";
2
- class u {
1
+ import { createContext as c, parseClassToAst as l, generateCssRules as i } from "@barocss/kit";
2
+ class p {
3
3
  constructor(e = {}) {
4
- this.context = r(e);
4
+ this.context = c(e);
5
5
  }
6
6
  /**
7
7
  * Parse a class name and return its AST
8
8
  */
9
9
  parseClass(e) {
10
- return n(e, this.context);
10
+ return l(e, this.context);
11
11
  }
12
12
  /**
13
13
  * Generate CSS for a class name
14
14
  */
15
15
  generateCss(e) {
16
- return o(e, this.context).map(({ css: s }) => s).filter(Boolean).join(`
16
+ const r = i(e, this.context), t = new Set(r.flatMap(({ rootCssList: s }) => s).filter(Boolean)), a = r.map(({ css: s }) => s).filter(Boolean), o = this.colorVarsBlock([...t, ...a].join(`
17
+ `));
18
+ return [...o ? [o] : [], ...t, ...a].join(`
17
19
  `);
20
+ }
21
+ /**
22
+ * #228: theme colours are emitted as var(--color-*). Define only the ones this output references
23
+ * (the full theme block is large), including --color-* vars those definitions reference in turn.
24
+ */
25
+ colorVarsBlock(e) {
26
+ const r = (s) => [...s.matchAll(/var\((--[\w-]*color-[\w-]+)/g)].map((n) => n[1]), t = r(e);
27
+ if (t.length === 0) return "";
28
+ const a = /* @__PURE__ */ new Map();
29
+ for (const s of this.context.themeToCssVars().matchAll(/^\s*(--[\w-]+):\s*(.+);$/gm)) a.set(s[1], s[2]);
30
+ const o = /* @__PURE__ */ new Map();
31
+ for (; t.length; ) {
32
+ const s = t.pop(), n = a.get(s);
33
+ n === void 0 || o.has(s) || (o.set(s, n), t.push(...r(n)));
34
+ }
35
+ return o.size === 0 ? "" : `:root,:host {
36
+ ` + [...o].map(([s, n]) => ` ${s}: ${n};`).join(`
37
+ `) + `
38
+ }`;
18
39
  }
19
40
  /**
20
41
  * Parse multiple classes and return their CSS
21
42
  */
22
43
  generateCssForClasses(e) {
23
- return e.map((s) => ({
24
- className: s,
25
- css: this.generateCss(s)
44
+ return e.map((t) => ({
45
+ className: t,
46
+ css: this.generateCss(t)
26
47
  }));
27
48
  }
28
49
  }
29
50
  export {
30
- u as ServerRuntime
51
+ p as ServerRuntime
31
52
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barocss/server",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/barocss/barocss.git",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "jsdom": "^26.1.0",
29
- "@barocss/kit": "0.4.0"
29
+ "@barocss/kit": "0.5.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "vite": "^7.1.3",