@barocss/server 0.8.2 → 0.10.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/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @barocss/server
2
2
 
3
+ > **Rendering untrusted class strings (AI output, CMS, users)?** See the [security guide](../../apps/barocss-docs/docs/guide/security.md).
4
+
3
5
  [![npm version](https://img.shields.io/npm/v/@barocss/server.svg)](https://www.npmjs.com/package/@barocss/server)
4
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
7
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
@@ -95,8 +97,8 @@ const config = {
95
97
  theme: { extend: { // your own theme: literal values, not var(--build-vars)
96
98
  colors: { brand: '#2563eb' },
97
99
  spacing: { gutter: '1.5rem' }, // named spacing: p-gutter
98
- borderRadius: { lg: '0.75rem' }, // override existing keys; new radius/font names go in utilities
99
- fontFamily: { sans: ['Inter', 'sans-serif'] },
100
+ borderRadius: { lg: '0.75rem', card: '1.25rem' }, // override rounded-lg; new keys work too: rounded-card
101
+ fontFamily: { sans: ['Inter', 'sans-serif'], display: ['Fraunces', 'serif'] }, // font-display
100
102
  } },
101
103
  utilities: { 'max-w-app': { 'max-width': '48rem', 'margin-inline': 'auto' } }, // static @utility rules; `@utility name-*` unsupported
102
104
  };
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@barocss/kit");var t=`data-barocss-ssr`,n={amp:`&`,lt:`<`,gt:`>`,quot:`"`,apos:`'`,nbsp:`\xA0`,colon:`:`,sol:`/`,lsqb:`[`,rsqb:`]`,num:`#`,percnt:`%`,lpar:`(`,rpar:`)`,comma:`,`,period:`.`,excl:`!`,tab:` `,newline:`
2
- `};function r(e){return e.includes(`&`)?e.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi,(e,t)=>{if(t[0]===`#`){let n=t[1]===`x`||t[1]===`X`?parseInt(t.slice(2),16):parseInt(t.slice(1),10);return n>0&&n<=1114111?String.fromCodePoint(n):e}return n[t.toLowerCase()]??e}):e}var i=/<[a-zA-Z][^\s/>]*/g,a=/\s+([^\s"'>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?|\s*\//y,o=/\s*>/y;function s(e){let t=e.toLowerCase(),n=/<!--|<(script|style)\b/g,r=``,i=0,a;for(;a=n.exec(t);){r+=e.slice(i,a.index)+` `;let o;if(a[1]){let e=t.indexOf(`</`+a[1],a.index+a[0].length);o=e<0?-1:t.indexOf(`>`,e),o>=0&&(o+=1)}else{let e=t.indexOf(`-->`,a.index+4);o=e<0?-1:e+3}if(o<0)return r;i=n.lastIndex=o}return r+e.slice(i)}function c(e){let t=s(e),n=new Set;for(i.lastIndex=0;i.exec(t);){let e=i.lastIndex,s,c=[];for(a.lastIndex=e;(s=a.exec(t))&&s[0];a.lastIndex=e)e=a.lastIndex,s[1]?.toLowerCase()===`class`&&c.push(s[2]??s[3]??s[4]??``);if(o.lastIndex=e,!o.test(t)){i.lastIndex=e;continue}i.lastIndex=o.lastIndex;for(let e of c)for(let t of r(e).split(/\s+/))t&&n.add(t)}return[...n]}function l(e){return e.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g,(e,t,n)=>t?String.fromCodePoint(parseInt(t,16)):n)}function u(e){let t=[],n=0,r=0;for(let i=0;i<e.length;i++){let a=e[i];a===`\\`?i++:a===`(`||a===`[`?n++:a===`)`||a===`]`?n--:a===`,`&&n===0&&(t.push(e.slice(r,i)),r=i+1)}return t.push(e.slice(r)),t}var d=/^\s*(?::(?:where|is)\(\s*)?\.((?:\\[0-9a-fA-F]{1,6}\s?|\\.|[\w-]|[^\x00-\x7F])+)/,f=/(^|[\s,(]):(root|host)\b/;function p(e){let t={classes:new Set,vars:new Set,properties:new Set,keyframes:new Set,layerStatement:!1},n=[],r=``,i=e=>{if(n.some(e=>f.test(e)))for(let n of e.matchAll(/(?:^|;)\s*(--[\w-]+)\s*:/g))t.vars.add(n[1])};for(let a=0;a<e.length;a++){let o=e[a];if(o===`/`&&e[a+1]===`*`){let t=e.indexOf(`*/`,a+2);a=t<0?e.length:t+1;continue}if(o===`"`||o===`'`){let t=a+1;for(;t<e.length&&e[t]!==o;)t+=e[t]===`\\`?2:1;r+=e.slice(a,t+1),a=t;continue}if(o===`\\`){r+=e.slice(a,a+2),a++;continue}if(o===`{`){let e=r.lastIndexOf(`;`);e>=0&&i(r.slice(0,e+1));let a=r.slice(e+1).trim();r=``,n.push(a);let o=/^@([\w-]+)\s*([\s\S]*)$/.exec(a);if(o){let e=o[1].toLowerCase();e===`property`?t.properties.add(o[2].trim()):e.endsWith(`keyframes`)&&t.keyframes.add(o[2].trim().replace(/^["']|["']$/g,``))}else if(!a.startsWith(`&`))for(let e of u(a)){let n=d.exec(e);n&&t.classes.add(l(n[1]))}continue}if(o===`}`){i(r),r=``,n.pop();continue}if(o===`;`&&n.length===0){/^\s*@layer\b/.test(r)&&(t.layerStatement=!0),r=``;continue}r+=o}return t}function m(e,n={}){return`<style ${t}${n.nonce?` nonce="${n.nonce.replace(/[&"<>]/g,e=>`&#${e.charCodeAt(0)};`)}"`:``}>${e.replace(/<\/(style)/gi,`<\\/$1`)}</style>`}var h=e=>[...e.matchAll(/var\((--[\w-]+)/g)].map(e=>e[1]),g=class{constructor(e={},t={}){this.classCache=new Map,this.themeDefs=null,this.skipCache=new Map,this.cacheSize=Math.max(0,t.cacheSize??1e4),this.setConfig(e)}setConfig(t){this.context=(0,e.createContext)(t),this.classCache.clear(),this.themeDefs=null}parseClass(t){return(0,e.parseClassToAst)(t,this.context)}generateCss(e){return this.sheet(e.split(/\s+/).filter(Boolean))}generateCssForHtml(e,t={}){let n=typeof e==`string`?c(e):[...new Set(e.flatMap(e=>e.split(/\s+/)).filter(Boolean))],r=t.skip;if(r===void 0)return this.sheet(n);if(typeof r==`string`){let e=this.skipDefs(r);return this.sheet(n.filter(t=>!e.classes.has(t)),e)}let i=r instanceof Set?r:new Set(r);return this.sheet(n.filter(e=>!i.has(e)))}skipDefs(e){let t=this.skipCache.get(e);return t||(this.skipCache.size>=4&&this.skipCache.delete(this.skipCache.keys().next().value),this.skipCache.set(e,t=p(e))),t}sheet(e,t){let n=e.map(e=>this.entryFor(e)),r=this.uniqueRoots(n.flatMap(e=>e.roots));t&&(r=r.filter(({css:e,dedupeKey:n})=>{if(n.startsWith(`--`))return!t.properties.has(n);let r=/^\s*@(?:-[\w]+-)?keyframes\s+([^\s{]+)/.exec(e)?.[1];return!r||!t.keyframes.has(r)}));let i=this.sortRules(n.filter(e=>e.css)),a=[...r.flatMap(e=>e.refs),...i.flatMap(e=>e.refs)],o=this.themeVarsBlock(a,t?.vars);return[...o?[o]:[],...r.map(e=>e.css),...i.map(e=>e.css)].join(`
3
- `)}entryFor(t){let n=this.classCache.get(t);if(n)return this.classCache.delete(t),this.classCache.set(t,n),n;let r={css:``,key:null,refs:[],roots:[]},i=[];try{i=(0,e.generateCssRules)(t,this.context)}catch(n){(0,e.isDebug)()&&console.warn(`[barocss/server] class generation failed:`,t,n)}for(let{css:e,rootCssList:t}of i){e&&(r.css=e);for(let e of t){if(!e)continue;let t=/^\s*@property\s+(--[\w-]+)/.exec(e)?.[1]??e;r.roots.push({css:e,dedupeKey:t,refs:h(e)})}}return r.css&&(r.key=(0,e.ruleSortKey)(r.css),r.refs=h(r.css)),this.cacheSize>0&&(this.classCache.size>=this.cacheSize&&this.classCache.delete(this.classCache.keys().next().value),this.classCache.set(t,r)),r}generateCssForClasses(e){return e.map(e=>({className:e,css:this.generateCss(e)}))}uniqueRoots(e){let t=new Set;return e.filter(({dedupeKey:e})=>!t.has(e)&&!!t.add(e))}sortRules(t){return t.map((e,t)=>({entry:e,i:t})).sort((t,n)=>(0,e.compareKeys)(t.entry.key,n.entry.key)||t.i-n.i).map(({entry:e})=>e)}themeVarsBlock(e,t){let n=e;if(n.length===0)return``;let r=this.themeDefs;if(!r){r=this.themeDefs=new Map;for(let e of this.context.themeToCssVars().matchAll(/^\s*(--[\w-]+):\s*(.+);$/gm))r.set(e[1],e[2])}let i=new Map;for(;n.length;){let e=n.pop(),a=r.get(e);a===void 0||i.has(e)||t?.has(e)||(i.set(e,a),n.push(...h(a)))}return i.size===0?``:`:root,:host {
2
+ `};function r(e){return e.includes(`&`)?e.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi,(e,t)=>{if(t[0]===`#`){let n=t[1]===`x`||t[1]===`X`?parseInt(t.slice(2),16):parseInt(t.slice(1),10);return n>0&&n<=1114111?String.fromCodePoint(n):e}return n[t.toLowerCase()]??e}):e}var i=/[ \t\n\f\r]+/,a=/<[a-zA-Z][^\s/>]*/g,o=/\s+([^\s"'>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?|\s*\//y,s=/\s*>/y;function c(e){let t=e.toLowerCase(),n=/<!--|<(script|style)\b/g,r=``,i=0,a;for(;a=n.exec(t);){r+=e.slice(i,a.index)+` `;let o;if(a[1]){let e=t.indexOf(`</`+a[1],a.index+a[0].length);o=e<0?-1:t.indexOf(`>`,e),o>=0&&(o+=1)}else{let e=t.indexOf(`-->`,a.index+4);o=e<0?-1:e+3}if(o<0)return r;i=n.lastIndex=o}return r+e.slice(i)}function l(e){let t=c(e),n=new Set;for(a.lastIndex=0;a.exec(t);){let e=a.lastIndex,c,l=[];for(o.lastIndex=e;(c=o.exec(t))&&c[0];o.lastIndex=e)e=o.lastIndex,c[1]?.toLowerCase()===`class`&&l.push(c[2]??c[3]??c[4]??``);if(s.lastIndex=e,!s.test(t)){a.lastIndex=e;continue}a.lastIndex=s.lastIndex;for(let e of l)for(let t of r(e).split(i))t&&n.add(t)}return[...n]}function u(e){return e.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g,(e,t,n)=>t?String.fromCodePoint(parseInt(t,16)):n)}function d(e){let t=[],n=0,r=0;for(let i=0;i<e.length;i++){let a=e[i];a===`\\`?i++:a===`(`||a===`[`?n++:a===`)`||a===`]`?n--:a===`,`&&n===0&&(t.push(e.slice(r,i)),r=i+1)}return t.push(e.slice(r)),t}var f=/^\s*(?::(?:where|is)\(\s*)?\.((?:\\[0-9a-fA-F]{1,6}\s?|\\.|[\w-]|[^\x00-\x7F])+)/,p=/(^|[\s,(]):(root|host)\b/;function m(e){let t={classes:new Set,vars:new Set,properties:new Set,keyframes:new Set,layerStatement:!1},n=[],r=``,i=e=>{if(n.some(e=>p.test(e)))for(let n of e.matchAll(/(?:^|;)\s*(--[\w-]+)\s*:/g))t.vars.add(n[1])};for(let a=0;a<e.length;a++){let o=e[a];if(o===`/`&&e[a+1]===`*`){let t=e.indexOf(`*/`,a+2);a=t<0?e.length:t+1;continue}if(o===`"`||o===`'`){let t=a+1;for(;t<e.length&&e[t]!==o;)t+=e[t]===`\\`?2:1;r+=e.slice(a,t+1),a=t;continue}if(o===`\\`){r+=e.slice(a,a+2),a++;continue}if(o===`{`){let e=r.lastIndexOf(`;`);e>=0&&i(r.slice(0,e+1));let a=r.slice(e+1).trim();r=``,n.push(a);let o=/^@([\w-]+)\s*([\s\S]*)$/.exec(a);if(o){let e=o[1].toLowerCase();e===`property`?t.properties.add(o[2].trim()):e.endsWith(`keyframes`)&&t.keyframes.add(o[2].trim().replace(/^["']|["']$/g,``))}else if(!a.startsWith(`&`))for(let e of d(a)){let n=f.exec(e);n&&t.classes.add(u(n[1]))}continue}if(o===`}`){i(r),r=``,n.pop();continue}if(o===`;`&&n.length===0){/^\s*@layer\b/.test(r)&&(t.layerStatement=!0),r=``;continue}r+=o}return t}function h(e,n={}){return`<style ${t}${n.nonce?` nonce="${n.nonce.replace(/[&"<>]/g,e=>`&#${e.charCodeAt(0)};`)}"`:``}>${e.replace(/<\/(style)/gi,`<\\/$1`)}</style>`}var g=e=>[...e.matchAll(/var\((--[\w-]+)/g)].map(e=>e[1]),_=class{constructor(e={},t={}){this.classCache=new Map,this.themeDefs=null,this.skipCache=new Map,this.cacheSize=Math.max(0,t.cacheSize??1e4),this.setConfig(e)}setConfig(t){this.context=(0,e.createContext)(t),this.classCache.clear(),this.themeDefs=null}parseClass(t){return(0,e.parseClassToAst)(t,this.context)}generateCss(e){return this.sheet(e.split(i).filter(Boolean))}generateCssForHtml(e,t={}){let n=typeof e==`string`?l(e):[...new Set(e.flatMap(e=>e.split(i)).filter(Boolean))],r=t.skip;if(r===void 0)return this.sheet(n);if(typeof r==`string`){let e=this.skipDefs(r);return this.sheet(n.filter(t=>!e.classes.has(t)),e)}let a=r instanceof Set?r:new Set(r);return this.sheet(n.filter(e=>!a.has(e)))}skipDefs(e){let t=this.skipCache.get(e);return t||(this.skipCache.size>=4&&this.skipCache.delete(this.skipCache.keys().next().value),this.skipCache.set(e,t=m(e))),t}sheet(e,t){let n=e.map(e=>this.entryFor(e)),r=this.uniqueRoots(n.flatMap(e=>e.roots));t&&(r=r.filter(({css:e,dedupeKey:n})=>{if(n.startsWith(`--`))return!t.properties.has(n);let r=/^\s*@(?:-[\w]+-)?keyframes\s+([^\s{]+)/.exec(e)?.[1];return!r||!t.keyframes.has(r)}));let i=this.sortRules(n.filter(e=>e.css)),a=[...r.flatMap(e=>e.refs),...i.flatMap(e=>e.refs)],o=this.themeVarsBlock(a,t?.vars);return[...o?[o]:[],...r.map(e=>e.css),...i.map(e=>e.css)].join(`
3
+ `)}entryFor(t){let n=this.classCache.get(t);if(n)return this.classCache.delete(t),this.classCache.set(t,n),n;let r={css:``,key:null,refs:[],roots:[]},i=[];try{i=(0,e.generateCssRules)(t,this.context)}catch(n){(0,e.isDebug)()&&console.warn(`[barocss/server] class generation failed:`,t,n)}for(let{css:e,rootCssList:t}of i){e&&(r.css=e);for(let e of t){if(!e)continue;let t=/^\s*@property\s+(--[\w-]+)/.exec(e)?.[1]??e;r.roots.push({css:e,dedupeKey:t,refs:g(e)})}}return r.css&&(r.key=(0,e.ruleSortKey)(r.css),r.refs=g(r.css)),this.cacheSize>0&&(this.classCache.size>=this.cacheSize&&this.classCache.delete(this.classCache.keys().next().value),this.classCache.set(t,r)),r}generateCssForClasses(e){return e.map(e=>({className:e,css:this.generateCss(e)}))}uniqueRoots(e){let t=new Set;return e.filter(({dedupeKey:e})=>!t.has(e)&&!!t.add(e))}sortRules(t){return t.map((e,t)=>({entry:e,i:t})).sort((t,n)=>(0,e.compareKeys)(t.entry.key,n.entry.key)||t.i-n.i).map(({entry:e})=>e)}themeVarsBlock(e,t){let n=e;if(n.length===0)return``;let r=this.themeDefs;if(!r){r=this.themeDefs=new Map;for(let e of this.context.themeToCssVars().matchAll(/^\s*(--[\w-]+):\s*(.+);$/gm))r.set(e[1],e[2])}let i=new Map;for(;n.length;){let e=n.pop(),a=r.get(e);a===void 0||i.has(e)||t?.has(e)||(i.set(e,a),n.push(...g(a)))}return i.size===0?``:`:root,:host {
4
4
  `+[...i].map(([e,t])=>` ${e}: ${t};`).join(`
5
5
  `)+`
6
- }`}};exports.SSR_STYLE_ATTRIBUTE=t,exports.ServerRuntime=g,exports.ssrStyleTag=m;
6
+ }`}};exports.SSR_STYLE_ATTRIBUTE=t,exports.ServerRuntime=_,exports.ssrStyleTag=h;
package/dist/index.d.cts CHANGED
@@ -40,7 +40,8 @@ export declare class ServerRuntime {
40
40
  * page's build CSS already provides. `htmlOrClasses` is HTML (classes are read from `class`
41
41
  * attributes; `<script>`/`<style>` contents and comments ignored) or a class list. Stateless per
42
42
  * call: it returns this request's delta, never classes emitted for earlier requests. Wrap the result
43
- * with `ssrStyleTag()` so `@barocss/browser` adopts it.
43
+ * with `ssrStyleTag()` so `@barocss/browser` adopts it; under a strict CSP pass the response nonce,
44
+ * `ssrStyleTag(css, { nonce })` (#347), and give the browser runtime the same `nonce`.
44
45
  */
45
46
  generateCssForHtml(htmlOrClasses: string | string[], opts?: GenerateCssForHtmlOptions): string;
46
47
  /** Parsed build CSS, memoised by text (a server passes the same build CSS on every request). */
package/dist/index.d.ts CHANGED
@@ -40,7 +40,8 @@ export declare class ServerRuntime {
40
40
  * page's build CSS already provides. `htmlOrClasses` is HTML (classes are read from `class`
41
41
  * attributes; `<script>`/`<style>` contents and comments ignored) or a class list. Stateless per
42
42
  * call: it returns this request's delta, never classes emitted for earlier requests. Wrap the result
43
- * with `ssrStyleTag()` so `@barocss/browser` adopts it.
43
+ * with `ssrStyleTag()` so `@barocss/browser` adopts it; under a strict CSP pass the response nonce,
44
+ * `ssrStyleTag(css, { nonce })` (#347), and give the browser runtime the same `nonce`.
44
45
  */
45
46
  generateCssForHtml(htmlOrClasses: string | string[], opts?: GenerateCssForHtmlOptions): string;
46
47
  /** Parsed build CSS, memoised by text (a server passes the same build CSS on every request). */
package/dist/index.es.js CHANGED
@@ -30,8 +30,8 @@ function c(e) {
30
30
  return s[t.toLowerCase()] ?? e;
31
31
  }) : e;
32
32
  }
33
- var l = /<[a-zA-Z][^\s/>]*/g, u = /\s+([^\s"'>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?|\s*\//y, d = /\s*>/y;
34
- function f(e) {
33
+ var l = /[ \t\n\f\r]+/, u = /<[a-zA-Z][^\s/>]*/g, d = /\s+([^\s"'>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?|\s*\//y, f = /\s*>/y;
34
+ function p(e) {
35
35
  let t = e.toLowerCase(), n = /<!--|<(script|style)\b/g, r = "", i = 0, a;
36
36
  for (; a = n.exec(t);) {
37
37
  r += e.slice(i, a.index) + " ";
@@ -48,24 +48,24 @@ function f(e) {
48
48
  }
49
49
  return r + e.slice(i);
50
50
  }
51
- function p(e) {
52
- let t = f(e), n = /* @__PURE__ */ new Set();
53
- for (l.lastIndex = 0; l.exec(t);) {
54
- let e = l.lastIndex, r, i = [];
55
- for (u.lastIndex = e; (r = u.exec(t)) && r[0]; u.lastIndex = e) e = u.lastIndex, r[1]?.toLowerCase() === "class" && i.push(r[2] ?? r[3] ?? r[4] ?? "");
56
- if (d.lastIndex = e, !d.test(t)) {
57
- l.lastIndex = e;
51
+ function m(e) {
52
+ let t = p(e), n = /* @__PURE__ */ new Set();
53
+ for (u.lastIndex = 0; u.exec(t);) {
54
+ let e = u.lastIndex, r, i = [];
55
+ for (d.lastIndex = e; (r = d.exec(t)) && r[0]; d.lastIndex = e) e = d.lastIndex, r[1]?.toLowerCase() === "class" && i.push(r[2] ?? r[3] ?? r[4] ?? "");
56
+ if (f.lastIndex = e, !f.test(t)) {
57
+ u.lastIndex = e;
58
58
  continue;
59
59
  }
60
- l.lastIndex = d.lastIndex;
61
- for (let e of i) for (let t of c(e).split(/\s+/)) t && n.add(t);
60
+ u.lastIndex = f.lastIndex;
61
+ for (let e of i) for (let t of c(e).split(l)) t && n.add(t);
62
62
  }
63
63
  return [...n];
64
64
  }
65
- function m(e) {
65
+ function h(e) {
66
66
  return e.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g, (e, t, n) => t ? String.fromCodePoint(parseInt(t, 16)) : n);
67
67
  }
68
- function h(e) {
68
+ function g(e) {
69
69
  let t = [], n = 0, r = 0;
70
70
  for (let i = 0; i < e.length; i++) {
71
71
  let a = e[i];
@@ -73,8 +73,8 @@ function h(e) {
73
73
  }
74
74
  return t.push(e.slice(r)), t;
75
75
  }
76
- var g = /^\s*(?::(?:where|is)\(\s*)?\.((?:\\[0-9a-fA-F]{1,6}\s?|\\.|[\w-]|[^\x00-\x7F])+)/, _ = /(^|[\s,(]):(root|host)\b/;
77
- function v(e) {
76
+ var _ = /^\s*(?::(?:where|is)\(\s*)?\.((?:\\[0-9a-fA-F]{1,6}\s?|\\.|[\w-]|[^\x00-\x7F])+)/, v = /(^|[\s,(]):(root|host)\b/;
77
+ function y(e) {
78
78
  let t = {
79
79
  classes: /* @__PURE__ */ new Set(),
80
80
  vars: /* @__PURE__ */ new Set(),
@@ -82,7 +82,7 @@ function v(e) {
82
82
  keyframes: /* @__PURE__ */ new Set(),
83
83
  layerStatement: !1
84
84
  }, n = [], r = "", i = (e) => {
85
- if (n.some((e) => _.test(e))) for (let n of e.matchAll(/(?:^|;)\s*(--[\w-]+)\s*:/g)) t.vars.add(n[1]);
85
+ if (n.some((e) => v.test(e))) for (let n of e.matchAll(/(?:^|;)\s*(--[\w-]+)\s*:/g)) t.vars.add(n[1]);
86
86
  };
87
87
  for (let a = 0; a < e.length; a++) {
88
88
  let o = e[a];
@@ -110,9 +110,9 @@ function v(e) {
110
110
  if (o) {
111
111
  let e = o[1].toLowerCase();
112
112
  e === "property" ? t.properties.add(o[2].trim()) : e.endsWith("keyframes") && t.keyframes.add(o[2].trim().replace(/^["']|["']$/g, ""));
113
- } else if (!a.startsWith("&")) for (let e of h(a)) {
114
- let n = g.exec(e);
115
- n && t.classes.add(m(n[1]));
113
+ } else if (!a.startsWith("&")) for (let e of g(a)) {
114
+ let n = _.exec(e);
115
+ n && t.classes.add(h(n[1]));
116
116
  }
117
117
  continue;
118
118
  }
@@ -128,12 +128,12 @@ function v(e) {
128
128
  }
129
129
  return t;
130
130
  }
131
- function y(e, t = {}) {
131
+ function b(e, t = {}) {
132
132
  return `<style ${o}${t.nonce ? ` nonce="${t.nonce.replace(/[&"<>]/g, (e) => `&#${e.charCodeAt(0)};`)}"` : ""}>${e.replace(/<\/(style)/gi, "<\\/$1")}</style>`;
133
133
  }
134
134
  //#endregion
135
135
  //#region src/index.ts
136
- var b = (e) => [...e.matchAll(/var\((--[\w-]+)/g)].map((e) => e[1]), x = class {
136
+ var x = (e) => [...e.matchAll(/var\((--[\w-]+)/g)].map((e) => e[1]), S = class {
137
137
  constructor(e = {}, t = {}) {
138
138
  this.classCache = /* @__PURE__ */ new Map(), this.themeDefs = null, this.skipCache = /* @__PURE__ */ new Map(), this.cacheSize = Math.max(0, t.cacheSize ?? 1e4), this.setConfig(e);
139
139
  }
@@ -144,10 +144,10 @@ var b = (e) => [...e.matchAll(/var\((--[\w-]+)/g)].map((e) => e[1]), x = class {
144
144
  return i(e, this.context);
145
145
  }
146
146
  generateCss(e) {
147
- return this.sheet(e.split(/\s+/).filter(Boolean));
147
+ return this.sheet(e.split(l).filter(Boolean));
148
148
  }
149
149
  generateCssForHtml(e, t = {}) {
150
- let n = typeof e == "string" ? p(e) : [...new Set(e.flatMap((e) => e.split(/\s+/)).filter(Boolean))], r = t.skip;
150
+ let n = typeof e == "string" ? m(e) : [...new Set(e.flatMap((e) => e.split(l)).filter(Boolean))], r = t.skip;
151
151
  if (r === void 0) return this.sheet(n);
152
152
  if (typeof r == "string") {
153
153
  let e = this.skipDefs(r);
@@ -158,7 +158,7 @@ var b = (e) => [...e.matchAll(/var\((--[\w-]+)/g)].map((e) => e[1]), x = class {
158
158
  }
159
159
  skipDefs(e) {
160
160
  let t = this.skipCache.get(e);
161
- return t || (this.skipCache.size >= 4 && this.skipCache.delete(this.skipCache.keys().next().value), this.skipCache.set(e, t = v(e))), t;
161
+ return t || (this.skipCache.size >= 4 && this.skipCache.delete(this.skipCache.keys().next().value), this.skipCache.set(e, t = y(e))), t;
162
162
  }
163
163
  sheet(e, t) {
164
164
  let n = e.map((e) => this.entryFor(e)), r = this.uniqueRoots(n.flatMap((e) => e.roots));
@@ -196,11 +196,11 @@ var b = (e) => [...e.matchAll(/var\((--[\w-]+)/g)].map((e) => e[1]), x = class {
196
196
  i.roots.push({
197
197
  css: e,
198
198
  dedupeKey: t,
199
- refs: b(e)
199
+ refs: x(e)
200
200
  });
201
201
  }
202
202
  }
203
- return i.css && (i.key = a(i.css), i.refs = b(i.css)), this.cacheSize > 0 && (this.classCache.size >= this.cacheSize && this.classCache.delete(this.classCache.keys().next().value), this.classCache.set(e, i)), i;
203
+ return i.css && (i.key = a(i.css), i.refs = x(i.css)), this.cacheSize > 0 && (this.classCache.size >= this.cacheSize && this.classCache.delete(this.classCache.keys().next().value), this.classCache.set(e, i)), i;
204
204
  }
205
205
  generateCssForClasses(e) {
206
206
  return e.map((e) => ({
@@ -229,10 +229,10 @@ var b = (e) => [...e.matchAll(/var\((--[\w-]+)/g)].map((e) => e[1]), x = class {
229
229
  let i = /* @__PURE__ */ new Map();
230
230
  for (; n.length;) {
231
231
  let e = n.pop(), a = r.get(e);
232
- a === void 0 || i.has(e) || t?.has(e) || (i.set(e, a), n.push(...b(a)));
232
+ a === void 0 || i.has(e) || t?.has(e) || (i.set(e, a), n.push(...x(a)));
233
233
  }
234
234
  return i.size === 0 ? "" : ":root,:host {\n" + [...i].map(([e, t]) => ` ${e}: ${t};`).join("\n") + "\n}";
235
235
  }
236
236
  };
237
237
  //#endregion
238
- export { o as SSR_STYLE_ATTRIBUTE, x as ServerRuntime, y as ssrStyleTag };
238
+ export { o as SSR_STYLE_ATTRIBUTE, S as ServerRuntime, b as ssrStyleTag };
package/dist/ssr.d.cts CHANGED
@@ -7,6 +7,7 @@
7
7
  export declare const SSR_STYLE_ATTRIBUTE = "data-barocss-ssr";
8
8
  /** Decode the HTML character references an attribute value may contain. */
9
9
  export declare function decodeHtmlEntities(s: string): string;
10
+ export declare const CLASS_SEPARATOR: RegExp;
10
11
  /**
11
12
  * Class names from every `class` attribute in `html`, first-seen order, deduplicated. Handles double,
12
13
  * single and unquoted values, any whitespace and character references; ignores comments and the
package/dist/ssr.d.ts CHANGED
@@ -7,6 +7,7 @@
7
7
  export declare const SSR_STYLE_ATTRIBUTE = "data-barocss-ssr";
8
8
  /** Decode the HTML character references an attribute value may contain. */
9
9
  export declare function decodeHtmlEntities(s: string): string;
10
+ export declare const CLASS_SEPARATOR: RegExp;
10
11
  /**
11
12
  * Class names from every `class` attribute in `html`, first-seen order, deduplicated. Handles double,
12
13
  * single and unquoted values, any whitespace and character references; ignores comments and the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barocss/server",
3
- "version": "0.8.2",
3
+ "version": "0.10.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/barocss/barocss.git",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "jsdom": "^26.1.0",
34
- "@barocss/kit": "0.8.2"
34
+ "@barocss/kit": "0.10.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "vite": "^8.3.1",