@barocss/browser 0.10.1 → 0.10.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.
package/dist/index.cjs CHANGED
@@ -1,15 +1,16 @@
1
1
  Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@barocss/kit");var t=class{insertSorted(t,n,r){let i=t.keys??=[],a=(0,e.upperBound)(i,r),o=t.styleElement.sheet;o&&o.cssRules.length===i.length?(o.insertRule(this.escapeCssRule(n),a),t.styles.splice(a,0,n)):(t.styles.splice(a,0,n),t.styleElement.textContent=t.styles.join(`
2
2
  `)+`
3
- `),i.splice(a,0,r)}constructor(t,n=50,r=`barocss-style-partition-`,i=t=>(0,e.parseClassName)(t).utility?.category,a=``){this.partitions=[],this.categoryPartitions=new Map,this.partitionCounter=0,this.maxRulesPerPartition=50,this.classToPartitionMap=new Map,this.classToCategoryPartitionMap=new Map,this.styleIdPrefix=`barocss-style-partition-`,this.nonce=a,this.insertionPoint=t,this.maxRulesPerPartition=n,this.styleIdPrefix=r,this.getCategory=i,this.initializeDefaultPartition()}createStyleElement(){let e=document.createElement(`style`);return this.nonce&&e.setAttribute(`nonce`,this.nonce),e}initializeDefaultPartition(){this.createNewPartition()}createNewCategoryPartition(e,t=!1){let n={id:this.styleIdPrefix+`-${e}`,styles:[],styleElement:this.createStyleElement()};n.styleElement.id=n.id,n.styleElement.setAttribute(`data-barocss`,`partition`),n.styleElement.setAttribute(`data-category`,e);let r=this.insertionPoint.ownerDocument?.head;return t&&r?r.insertBefore(n.styleElement,r.firstChild):this.insertionPoint.appendChild(n.styleElement),this.categoryPartitions.set(e,n),n}createNewPartition(){let e={id:this.styleIdPrefix+`-${this.partitionCounter++}`,styles:[],styleElement:this.createStyleElement()};return this.partitions.push(e),e.styleElement.id=e.id,e.styleElement.setAttribute(`data-barocss`,`partition`),e.styleElement.setAttribute(`data-partition-index`,this.partitionCounter.toString()),this.insertionPoint.appendChild(e.styleElement),e}hasRule(e){return this.classToPartitionMap.has(e)}hasCategoryRule(e,t){return this.classToCategoryPartitionMap.get(e)===t}setRuleCache(e,t){this.classToPartitionMap.set(e,t)}setCategoryRuleCache(e,t){this.classToCategoryPartitionMap.set(e,t)}get currentPartition(){return this.partitions[this.partitions.length-1]}getCategoryPartition(e){return this.categoryPartitions.get(e)}hasDetachedPartitions(){return[...this.partitions,...this.categoryPartitions.values()].some(e=>!e.styleElement.isConnected)}escapeCssRule(e){return e.replace(/\\\//g,`\\/`)}addRule(t){if(this.hasRule(t))return!1;let n=(0,e.ruleSortKey)(t),r=this.partitions.findIndex(t=>{let r=t.keys;return!!r&&r.length>0&&(0,e.compareKeys)(r[r.length-1],n)>0});r===-1&&(this.currentPartition.styles.length>=this.maxRulesPerPartition&&this.createNewPartition(),r=this.partitions.length-1);let i=this.partitions[r];try{return this.insertSorted(i,t,n),this.setRuleCache(t,r),!0}catch(n){return(0,e.isDebug)()&&console.warn(`[StylePartitionManager] Failed to insert rule: ${t}`,n),!1}}addCategoryRule(t,n){if(this.hasCategoryRule(t,n))return!1;let r=this.getCategoryPartition(n);r||=this.createNewCategoryPartition(n);try{this.insertSorted(r,t,(0,e.ruleSortKey)(t))}catch(r){return(0,e.isDebug)()&&console.warn(`[StylePartitionManager] Failed to insert rule in category: ${n} ${t}`,r),!1}return this.setCategoryRuleCache(t,n),!0}addRootRules(t){let n=this.getCategoryPartition(`root`);n||=this.createNewCategoryPartition(`root`);try{let e=n.styleElement.sheet;for(let r of t)e?e.insertRule(this.escapeCssRule(r),e.cssRules.length):n.styleElement.textContent+=r+`
3
+ `),i.splice(a,0,r)}constructor(t,n=50,r=`barocss-style-partition-`,i=t=>(0,e.parseClassName)(t).utility?.category,a=``){this.partitions=[],this.categoryPartitions=new Map,this.partitionCounter=0,this.maxRulesPerPartition=50,this.classToPartitionMap=new Map,this.classToCategoryPartitionMap=new Map,this.styleIdPrefix=`barocss-style-partition-`,this.nonce=a,this.insertionPoint=t,this.maxRulesPerPartition=n,this.styleIdPrefix=r,this.getCategory=i,this.initializeDefaultPartition()}createStyleElement(){let e=document.createElement(`style`);return this.nonce&&e.setAttribute(`nonce`,this.nonce),e}initializeDefaultPartition(){this.createNewPartition()}createNewCategoryPartition(e,t=!1){let n={id:this.styleIdPrefix+`-${e}`,styles:[],styleElement:this.createStyleElement()};n.styleElement.id=n.id,n.styleElement.setAttribute(`data-barocss`,`partition`),n.styleElement.setAttribute(`data-category`,e);let r=this.insertionPoint.ownerDocument?.head;return t&&r?r.insertBefore(n.styleElement,r.firstChild):this.insertionPoint.appendChild(n.styleElement),this.categoryPartitions.set(e,n),n}createNewPartition(){let e=this.partitions[this.partitions.length-1],t={id:this.styleIdPrefix+`-${this.partitionCounter++}`,styles:[],styleElement:this.createStyleElement()};this.partitions.push(t),t.styleElement.id=t.id,t.styleElement.setAttribute(`data-barocss`,`partition`),t.styleElement.setAttribute(`data-partition-index`,this.partitionCounter.toString());let n=e?.styleElement.parentNode;return n?n.insertBefore(t.styleElement,e.styleElement.nextSibling):this.insertionPoint.appendChild(t.styleElement),t}hasRule(e){return this.classToPartitionMap.has(e)}hasCategoryRule(e,t){return this.classToCategoryPartitionMap.get(e)===t}setRuleCache(e,t){this.classToPartitionMap.set(e,t)}setCategoryRuleCache(e,t){this.classToCategoryPartitionMap.set(e,t)}get currentPartition(){return this.partitions[this.partitions.length-1]}getCategoryPartition(e){return this.categoryPartitions.get(e)}hasDetachedPartitions(){return[...this.partitions,...this.categoryPartitions.values()].some(e=>!e.styleElement.isConnected)}escapeCssRule(e){return e.replace(/\\\//g,`\\/`)}addRule(t){if(this.hasRule(t))return!1;let n=(0,e.ruleSortKey)(t),r=this.partitions.findIndex(t=>{let r=t.keys;return!!r&&r.length>0&&(0,e.compareKeys)(r[r.length-1],n)>0});r===-1&&(this.currentPartition.styles.length>=this.maxRulesPerPartition&&this.createNewPartition(),r=this.partitions.length-1);let i=this.partitions[r];try{return this.insertSorted(i,t,n),this.setRuleCache(t,r),!0}catch(n){return(0,e.isDebug)()&&console.warn(`[StylePartitionManager] Failed to insert rule: ${t}`,n),!1}}addCategoryRule(t,n){if(this.hasCategoryRule(t,n))return!1;let r=this.getCategoryPartition(n);r||=this.createNewCategoryPartition(n);try{this.insertSorted(r,t,(0,e.ruleSortKey)(t))}catch(r){return(0,e.isDebug)()&&console.warn(`[StylePartitionManager] Failed to insert rule in category: ${n} ${t}`,r),!1}return this.setCategoryRuleCache(t,n),!0}addRootRules(t){let n=this.getCategoryPartition(`root`);n||=this.createNewCategoryPartition(`root`);try{let e=n.styleElement.sheet;for(let r of t)e?e.insertRule(this.escapeCssRule(r),e.cssRules.length):n.styleElement.textContent+=r+`
4
4
  `}catch(n){return(0,e.isDebug)()&&console.warn(`[StylePartitionManager] Failed to insert rule in category: root ${t.join(`
5
5
  `)}`,n),{success:0,failed:t.length}}return{success:t.length,failed:0}}addRules(e){let t=0,n=0;for(let r of e){let e=this.getCategory(r.cls);if(e)for(let t of r.cssList)this.addCategoryRule(t,e);else for(let e of r.cssList)this.addRule(e)?t++:n++}return{success:t,failed:n}}removeRule(e,t){let n;if(t){if(this.classToCategoryPartitionMap.get(e)!==t)return!1;n=this.categoryPartitions.get(t)}else{let t=this.classToPartitionMap.get(e);n=t===void 0?void 0:this.partitions[t]}if(!n)return!1;let r=n.styles.indexOf(e);if(r===-1)return!1;let i=n.styleElement.sheet,a=!!i&&i.cssRules.length===n.styles.length;return n.styles.splice(r,1),n.keys?.splice(r,1),a&&i?i.deleteRule(r):n.styleElement.textContent=n.styles.length?n.styles.join(`
6
6
  `)+`
7
7
  `:``,t?this.classToCategoryPartitionMap.delete(e):this.classToPartitionMap.delete(e),!0}get ruleCount(){return this.classToPartitionMap.size+this.classToCategoryPartitionMap.size}findRulePartition(e){let t=this.classToPartitionMap.get(e);if(t!==void 0&&this.partitions[t])return this.partitions[t];let n=this.classToCategoryPartitionMap.get(e);return n===void 0?null:this.categoryPartitions.get(n)||null}updateRuleContent(t,n,r=!1){let i=this.getCategoryPartition(t);if(i)i.styleElement.textContent=n;else{let i=this.createNewCategoryPartition(t,r);(0,e.isDebug)()&&console.log(`[StylePartitionManager] Created new partition for category: ${t}`),i.styleElement.textContent=n}}cleanup(){this.partitions.forEach(e=>{e.styleElement.parentNode&&e.styleElement.parentNode.removeChild(e.styleElement)}),this.categoryPartitions.forEach(e=>{e.styleElement.parentNode&&e.styleElement.parentNode.removeChild(e.styleElement)}),this.partitions=[],this.categoryPartitions.clear(),this.partitionCounter=0,this.classToPartitionMap.clear(),this.classToCategoryPartitionMap.clear()}},n=/[ \t\n\f\r]+/;function r(e){return e?typeof e==`object`&&typeof e.baseVal==`string`?e.baseVal:e.toString():``}function i(e){return e?r(e).split(n).filter(Boolean):[]}var a=class{constructor(t,n,r=t=>(0,e.parseClassName)(t).utility?.category){this.observer=null,this.gc=null,this.incrementalParser=t,this.BrowserRuntime=n,this.getCategory=r}setGc(e){this.gc=e}setParser(e){this.incrementalParser=e}observe(e=document.body,t){return typeof window>`u`?new MutationObserver(()=>{}):(this.observer&&this.observer.disconnect(),this.gc?.setRoot(e),this.observer=new MutationObserver(t=>{let n=new Set,r=this.gc;if(t.forEach(t=>{if(r&&(t.type===`attributes`?r.reconcile(t.target):t.type===`childList`&&(t.removedNodes.forEach(e=>r.reconcileTree(e)),t.addedNodes.forEach(e=>r.reconcileTree(e)))),t.type===`attributes`&&t.attributeName===`class`&&e.contains(t.target)){let e=t.target;e.className&&i(e.className).forEach(e=>{this.incrementalParser.isProcessed(e)||n.add(e)})}t.type===`childList`&&t.addedNodes.forEach(t=>{if(t.nodeType===Node.ELEMENT_NODE&&e.contains(t)){let e=t;this.processElement(e,n),e.querySelectorAll(`[class]`).forEach(e=>{this.processElement(e,n)})}})}),n.size>0){let e=Array.from(n),t=this.incrementalParser.processClasses(e);this.BrowserRuntime?.applyParseResults(t)}else this.BrowserRuntime?.applyParseResults([]);r?.afterBatch()}),this.observer.observe(e,{attributes:!0,subtree:!0,attributeFilter:[`class`],childList:!0}),t?.scan&&this.scanExistingClasses(e,t),this.observer)}scanExistingClasses(e,t){let n=new Set,r=e.className;r&&i(r).forEach(e=>{this.incrementalParser.isProcessed(e)||n.add(e)});let a=e.querySelectorAll(`[class]`);for(let e of a)if(e.className){let t=i(e.className);for(let e of t)this.incrementalParser.isProcessed(e)||n.add(e)}if(n.size>0){let e=Array.from(n),r=this.incrementalParser.processClasses(e),i=r.filter(e=>this.getCategory(e.cls)===`layout`),a=r.filter(e=>this.getCategory(e.cls)!==`layout`);this.BrowserRuntime?.applyParseResults(i),t?.onReady?.(),this.BrowserRuntime?.applyParseResults(a)}else t?.onReady?.()}processElement(e,t){e.className&&i(e.className).forEach(e=>{this.incrementalParser.isProcessed(e)||t.add(e)})}disconnect(){this.observer&&=(this.observer.disconnect(),null)}};function o(e){return e.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g,(e,t,n)=>t?String.fromCodePoint(parseInt(t,16)):n)}var s=/^\s*(?::(?:where|is)\(\s*)?\.((?:\\[0-9a-fA-F]{1,6}\s?|\\.|[\w-]|[^\x00-\x7F])+)/;function c(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}function l(e,t=new Set){for(let n of Array.from(e)){if(n.type===7&&typeof n.name==`string`){t.add(n.name);continue}let e=n.cssRules;e&&e.length&&l(e,t)}return t}function u(e,t=new Set){for(let n of Array.from(e)){let e=n.selectorText;if(typeof e==`string`)for(let n of c(e)){let e=s.exec(n);e&&t.add(o(e[1]))}let r=n.cssRules;r&&r.length&&u(r,t)}return t}var d=class{constructor(e,t,n,r=()=>Date.now()){this.host=e,this.graceMs=t,this.maxRules=n,this.now=r,this.counts=new Map,this.counted=new WeakMap,this.candidates=new Map,this.timer=null,this.root=null}setRoot(e){this.counts.clear(),this.counted=new WeakMap,this.candidates.clear(),this.cancel(),this.root=e,e.nodeType===1?this.reconcileTree(e):e.querySelectorAll(`[class]`).forEach(e=>this.reconcile(e))}count(e){return this.counts.get(e)??0}reconcileTree(e){if(e.nodeType!==1)return;let t=e;this.reconcile(t),t.querySelectorAll(`[class]`).forEach(e=>this.reconcile(e))}reconcile(e){let t=this.root,n=t&&t.contains(e)?Array.from(new Set(i(e.getAttribute(`class`)))):[],r=this.counted.get(e);if(!r&&n.length===0)return;let a=new Set(r??[]),o=new Set(n);for(let e of o){if(a.has(e))continue;let t=(this.counts.get(e)??0)+1;this.counts.set(e,t),this.candidates.delete(e)}for(let e of a){if(o.has(e))continue;let t=(this.counts.get(e)??0)-1;t>0?this.counts.set(e,t):(this.counts.delete(e),this.candidates.delete(e),this.candidates.set(e,this.now()))}n.length?this.counted.set(e,n):this.counted.delete(e)}afterBatch(){this.candidates.size!==0&&(this.host.cachedCount()>this.maxRules?this.schedule(0):this.schedule(this.graceMs))}schedule(e){if(this.timer!==null){if(e>0)return;clearTimeout(this.timer)}this.timer=setTimeout(()=>{this.timer=null,this.sweep()},e)}sweep(){let e=this.now(),t=Math.max(0,this.host.cachedCount()-this.maxRules),n=[],r=0;for(let[i,a]of this.candidates){let o=e-a>=this.graceMs;!o&&r>=t||(this.candidates.delete(i),!(this.count(i)>0||this.inDom(i)||this.host.isPermanent(i))&&(n.push(i),o||r++))}n.length&&this.host.reclaim(n),this.candidates.size&&this.schedule(this.graceMs)}inDom(e){let t=this.root;if(!t)return!1;if(t.nodeType!==1)return Array.from(t.querySelectorAll(`[class]`)).some(t=>t.classList.contains(e));let n=t.ownerDocument??document;return t.classList.contains(e)||n.documentElement.classList.contains(e)||n.getElementsByClassName(e).length>0}cancel(){this.timer!==null&&clearTimeout(this.timer),this.timer=null}stats(){return{trackedClasses:this.counts.size,candidates:this.candidates.size}}};function f(e){let t=[],n=e.replace(/\/\*[\s\S]*?\*\//g,``);return n=n.replace(/(?<=^|[{};])(\s*)([^{};@\s][^{};]*?)\{([^{}]*)\}/g,(e,n,r,i)=>{let a=r.split(`,`).map(e=>e.trim()).filter(Boolean);if(a.includes(`body`))for(let e of i.split(`;`).map(e=>e.trim()).filter(Boolean))/^(min-height|scroll-behavior)\s*:/.test(e)||t.push(e);let o=Array.from(new Set(a.filter(e=>e!==`body`).map(e=>e===`html`||e===`:root`?`:host`:e)));return o.length===0?``:`${n}${o.join(`, `)} {${i}}`}),t.length&&(n+=`\n@layer base {\n:host {\n ${t.join(`;
8
- `)};\n}\n}\n`),n}function p(e){return JSON.stringify(e,(e,t)=>typeof t==`function`?`fn:${String(t)}`:t instanceof RegExp?`re:${t}`:t)??``}function m(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function h(e=`shadow`){try{let t=e===`document`?typeof Document<`u`?Document.prototype:void 0:typeof ShadowRoot<`u`?ShadowRoot.prototype:void 0;return!!t&&`adoptedStyleSheets`in t&&typeof CSSStyleSheet==`function`&&typeof new CSSStyleSheet().replaceSync==`function`}catch{return!1}}var g=e=>e.replace(/\\\//g,`\\/`),_=class{constructor(t,n,r=t,i={}){this.results=new Map,this.generations=0,this.prologueSheet=null,this.rulesSheet=null,this.prologue={preflight:``,vars:``},this.segments=new Map([[`root`,{rules:[],keys:[]}],[``,{rules:[],keys:[]}]]),this.refs=new Map,this.attached=[],this.key=t,this.fullKey=r,this.context=i.context??(0,e.createContext)(n),this.constructable=h(i.target??`shadow`),this.constructable&&(this.prologueSheet=new CSSStyleSheet,this.rulesSheet=new CSSStyleSheet)}get rootCount(){return this.attached.length}get ruleCount(){return this.refs.size}attach(e,t=``){if(this.attached.some(t=>t.root===e))return;if(this.prologueSheet&&this.rulesSheet){let t=[this.prologueSheet,this.rulesSheet];e.adoptedStyleSheets=[...e.adoptedStyleSheets.filter(e=>!t.includes(e)),...t],this.attached.push({root:e});return}if(e.nodeType!==11)throw Error(`[BrowserRuntime] constructable sheets are not supported for the document`);let n=e.ownerDocument??document,r=n.createElement(`style`),i=n.createElement(`style`);t&&(r.setAttribute(`nonce`,t),i.setAttribute(`nonce`,t)),r.setAttribute(`data-barocss`,`root-prologue`),i.setAttribute(`data-barocss`,`root`),r.textContent=this.prologueText(),i.textContent=this.allRules().join(`
9
- `),e.insertBefore(i,e.firstChild),e.insertBefore(r,i),this.attached.push({root:e,styles:[r,i]})}detach(e){let t=this.attached.findIndex(t=>t.root===e);if(t===-1)return;let[n]=this.attached.splice(t,1);n.styles?n.styles.forEach(e=>e.remove()):e.adoptedStyleSheets&&=e.adoptedStyleSheets.filter(e=>e!==this.prologueSheet&&e!==this.rulesSheet)}setPrologue(e,t){if(this.prologue[e]===t)return;this.prologue[e]=t;let n=this.prologueText();this.prologueSheet&&this.prologueSheet.replaceSync(n);for(let e of this.attached)e.styles&&(e.styles[0].textContent=n)}prologueText(){return[this.prologue.preflight,this.prologue.vars].filter(Boolean).join(`
8
+ `)};\n}\n}\n`),n}function p(e){return JSON.stringify(e,(e,t)=>typeof t==`function`?`fn:${String(t)}`:t instanceof RegExp?`re:${t}`:t)??``}function m(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function h(e=`shadow`){try{let t=e===`document`?typeof Document<`u`?Document.prototype:void 0:typeof ShadowRoot<`u`?ShadowRoot.prototype:void 0;return!!t&&`adoptedStyleSheets`in t&&typeof CSSStyleSheet==`function`&&typeof new CSSStyleSheet().replaceSync==`function`}catch{return!1}}var g=e=>e.replace(/\\\//g,`\\/`),_=/^\s*@property\s/,v=null;function y(t,n,r={}){let i=n.filter(e=>_.test(e));if(i.length===0)return!0;try{if(!t)return!1;if(!v||v.doc!==t||v.style&&!v.style.isConnected){let e={doc:t,rules:new Set};if(r.constructable&&h(`document`))e.sheet=new CSSStyleSheet,t.adoptedStyleSheets=[...t.adoptedStyleSheets,e.sheet];else{let n=t.head??t.documentElement;if(!n)return!1;let i=t.createElement(`style`);i.setAttribute(`data-barocss`,`document-properties`),r.nonce&&i.setAttribute(`nonce`,r.nonce),n.appendChild(i),e.style=i}v=e}let e=v;for(let t of i){if(e.rules.has(t))continue;let n=e.sheet??e.style?.sheet??null;n?n.insertRule(g(t),n.cssRules.length):e.style&&(e.style.textContent+=`${t}\n`),e.rules.add(t)}return!0}catch(t){return(0,e.isDebug)()&&console.warn(`[BrowserRuntime] could not register @property rules in the document; using :host initial values`,t),!1}}function b(e){let t=[];for(let n of e){let e=/^\s*@property\s+(--[\w-]+)/.exec(n)?.[1],r=/initial-value\s*:\s*([^;}]*)/.exec(n)?.[1]?.trim();e&&r&&t.push(`${e}: ${r}`)}return t.length===0?``:`@layer properties {\n:host, *, ::before, ::after, ::backdrop {\n ${t.join(`;
9
+ `)};\n}\n}`}var x=class{constructor(t,n,r=t,i={}){this.results=new Map,this.generations=0,this.prologueSheet=null,this.rulesSheet=null,this.prologue={props:``,preflight:``,vars:``},this.fallbackProps=new Set,this.segments=new Map([[`root`,{rules:[],keys:[]}],[``,{rules:[],keys:[]}]]),this.refs=new Map,this.attached=[],this.key=t,this.fullKey=r,this.context=i.context??(0,e.createContext)(n),this.constructable=h(i.target??`shadow`),this.constructable&&(this.prologueSheet=new CSSStyleSheet,this.rulesSheet=new CSSStyleSheet)}get rootCount(){return this.attached.length}get ruleCount(){return this.refs.size}attach(e,t=``){if(this.attached.some(t=>t.root===e))return;if(this.prologueSheet&&this.rulesSheet){let t=[this.prologueSheet,this.rulesSheet];e.adoptedStyleSheets=[...e.adoptedStyleSheets.filter(e=>!t.includes(e)),...t],this.attached.push({root:e});return}if(e.nodeType!==11)throw Error(`[BrowserRuntime] constructable sheets are not supported for the document`);let n=e.ownerDocument??document,r=n.createElement(`style`),i=n.createElement(`style`);t&&(r.setAttribute(`nonce`,t),i.setAttribute(`nonce`,t)),r.setAttribute(`data-barocss`,`root-prologue`),i.setAttribute(`data-barocss`,`root`),r.textContent=this.prologueText(),i.textContent=this.allRules().join(`
10
+ `),e.insertBefore(i,e.firstChild),e.insertBefore(r,i),this.attached.push({root:e,styles:[r,i]})}detach(e){let t=this.attached.findIndex(t=>t.root===e);if(t===-1)return;let[n]=this.attached.splice(t,1);n.styles?n.styles.forEach(e=>e.remove()):e.adoptedStyleSheets&&=e.adoptedStyleSheets.filter(e=>e!==this.prologueSheet&&e!==this.rulesSheet)}addPropertyFallback(e){let t=this.fallbackProps.size;for(let t of e)_.test(t)&&this.fallbackProps.add(t);this.fallbackProps.size!==t&&this.setPrologue(`props`,b(Array.from(this.fallbackProps)))}setPrologue(e,t){if(this.prologue[e]===t)return;this.prologue[e]=t;let n=this.prologueText();this.prologueSheet&&this.prologueSheet.replaceSync(n);for(let e of this.attached)e.styles&&(e.styles[0].textContent=n)}prologueText(){return[this.prologue.props,this.prologue.preflight,this.prologue.vars].filter(Boolean).join(`
10
11
  `)}allRules(){return Array.from(this.segments.values()).flatMap(e=>e.rules)}offset(e){let t=0;for(let n of this.segments.values()){if(n===e)return t;t+=n.rules.length}return t}retain(t,n){let r=this.refs.get(t);if(r!==void 0)return this.refs.set(t,r+1),!0;let i=this.segments.get(n);i||(i={rules:[],keys:[]},this.segments.set(n,i));let a=n===`root`,o=(0,e.ruleSortKey)(t),s=a?i.rules.length:(0,e.upperBound)(i.keys,o),c=this.offset(i)+s;try{this.insertAt(t,c)}catch(n){return(0,e.isDebug)()&&console.warn(`[BrowserRuntime] Failed to insert rule into shadow root sheet: ${t}`,n),!1}return i.rules.splice(s,0,t),i.keys.splice(s,0,o),this.refs.set(t,1),!0}release(e){let t=this.refs.get(e);if(t!==void 0){if(t>1){this.refs.set(e,t-1);return}this.refs.delete(e);for(let t of this.segments.values()){let n=t.rules.indexOf(e);if(n===-1)continue;let r=this.offset(t)+n;t.rules.splice(n,1),t.keys.splice(n,1),this.deleteAt(r);return}}}insertAt(e,t){let n=g(e);if(this.rulesSheet){this.rulesSheet.insertRule(n,t);return}let r=this.allRules().length;for(let i of this.attached){let a=i.styles[1],o=a.sheet;if(o&&o.cssRules.length===r)o.insertRule(n,t);else{let n=this.allRules();n.splice(t,0,e),a.textContent=n.join(`
11
12
  `)}}}deleteAt(e){if(this.rulesSheet){this.rulesSheet.deleteRule(e);return}let t=this.allRules().length;for(let n of this.attached){let r=n.styles[1],i=r.sheet;i&&i.cssRules.length===t+1?i.deleteRule(e):r.textContent=this.allRules().join(`
12
13
  `)}}cssText(){return[this.prologueText(),...this.allRules()].join(`
13
- `)}},v=new Map;function y(e,t=m){let n=p(e),r=v.get(n);return r||(r=new _(t(n),e,n),v.set(n,r)),r}function b(e){e.rootCount===0&&v.get(e.fullKey)===e&&v.delete(e.fullKey)}var x=class extends e.IncrementalParser{constructor(e){super(e.context),this.shared=e}processClass(e){if(this.isProcessed(e))return null;let t=this.shared.results.get(e);if(t)return this.markProcessed(e),t;let n=super.processClass(e);return n&&(this.shared.results.set(e,n),this.shared.generations++),n}},S=class{constructor(t,n,r=t=>(0,e.parseClassName)(t).utility?.category,i={}){this.shared=t,this.root=n,this.getCategory=r,this.owned=new Set,this.scopePreflight=n.nodeType===11,t.attach(n,i.nonce)}hasDetachedPartitions(){return!1}updateRuleContent(e,t){e===`preflight`?this.shared.setPrologue(`preflight`,this.scopePreflight?f(t):t):e===`css-vars`&&this.shared.setPrologue(`vars`,t)}take(e,t){return this.owned.has(e)||!this.shared.retain(e,t)?!1:(this.owned.add(e),!0)}addRule(e){return this.take(e,``)}addCategoryRule(e,t){return this.take(e,`c:${t}`)}addRootRules(e){let t=0;for(let n of e)this.take(n,`root`)&&t++;return{success:t,failed:e.length-t}}addRules(e){let t=0,n=0;for(let r of e){let e=this.getCategory(r.cls);for(let i of r.cssList)(e?this.addCategoryRule(i,e):this.addRule(i))?t++:n++}return{success:t,failed:n}}removeRule(e,t){return this.owned.delete(e)?(this.shared.release(e),!0):!1}get ruleCount(){return this.owned.size}cleanup(){this.owned.forEach(e=>this.shared.release(e)),this.owned.clear(),this.shared.detach(this.root),b(this.shared)}},C=`style[data-barocss-ssr]`,w=`@layer theme, base, components, utilities;`,T=class{constructor(t={}){this.cache=new Map,this.rootCache=new Set,this.shadowRoot=null,this.isDestroyed=!1,this.existing=null,this.existingKeyframes=new Set,this.existingSheetCount=-1,this.pinned=new Set,this.gc=null,this.reclaimedCount=0,this.ssrRules=[],this.ssrClasses=new Set,this.observedOnce=!1,this.getCategory=t=>(0,e.parseClassName)(t,this.context).utility?.category;let n={};this.options={config:t.config||n,styleId:t.styleId||`barocss-runtime`,insertionPoint:t.insertionPoint||`head`,maxRulesPerPartition:t.maxRulesPerPartition||50,skipExisting:t.skipExisting??!1,gc:t.gc??!0,gcGraceMs:t.gcGraceMs??3e3,maxRules:t.maxRules??1/0,nonce:t.nonce??``,constructable:t.constructable??!1};let r=t.root;if(r&&r.nodeType===11&&(this.shadowRoot=r),this.shadowRoot){let e=y(this.options.config);this.context=e.context,this.incrementalParser=new x(e)}else this.context=(0,e.createContext)(this.options.config),this.incrementalParser=new e.IncrementalParser(this.context);this.changeDetector=new a(this.incrementalParser,this,this.getCategory),this.stylePartitionManager=this.createStyles(),this.options.gc&&(this.gc=new d({reclaim:e=>this.reclaim(e),isPermanent:e=>this.isPermanent(e),cachedCount:()=>this.cache.size},this.options.gcGraceMs,this.options.maxRules),this.changeDetector.setGc(this.gc)),this.init(),this.shadowRoot&&this.observe(this.shadowRoot,{scan:!0})}createStyles(){if(this.shadowRoot){let e=this.incrementalParser.shared,t=y(this.options.config);return t!==e&&(e=t,this.context=e.context,this.incrementalParser=new x(e),this.changeDetector?.setParser(this.incrementalParser)),new S(e,this.shadowRoot,this.getCategory,{nonce:this.options.nonce})}return this.options.constructable&&typeof document<`u`&&h(`document`)?new S(new _(`document`,this.options.config,`document`,{context:this.context,target:`document`}),document,this.getCategory):new t(this.getInsertionPoint(),this.options.maxRulesPerPartition,`${this.options.styleId}-partition`,this.getCategory,this.options.nonce)}debugLog(t,n,r){(0,e.isDebug)()&&(console[t]||console.log)(`[BrowserRuntime:${t.toUpperCase()}] ${n}`,r||``)}init(){this.debugLog(`debug`,`init`),this.injectPreflightCSS(),this.ensureCssVars(),this.adoptSsrSheets()}adoptSsrSheets(){if(typeof document>`u`||this.shadowRoot)return;let e=[];if(document.head){for(let t of Array.from(document.head.querySelectorAll(`${C}:not([data-barocss-adopted])`))){let n=t.sheet;if(!n)continue;t.setAttribute(`data-barocss-adopted`,``);let r=[];for(let e=n.cssRules.length-1;e>=0;e--){let t=n.cssRules[e],i=u([t]);i.size!==0&&(i.forEach(e=>this.ssrClasses.add(e)),r.unshift({css:t.cssText,cls:i.values().next().value}),n.deleteRule(e))}e.push(...r)}e.length!==0&&(this.ssrRules.push(...e),this.insertSsrRules(e))}}insertSsrRules(e){for(let{css:t,cls:n}of e){let e=this.getCategory(n);e?this.stylePartitionManager.addCategoryRule(t,e):this.stylePartitionManager.addRule(t)}}injectPreflightCSS(){let e=this.options.config.preflight??!0;if(e){let t=this.context.getPreflightCSS(e);this.stylePartitionManager.updateRuleContent(`preflight`,`${w}\n@layer base {\n${t}\n}`,!0)}}ensureCssVars(){if(this.isDestroyed)return;let e=this.context.themeToCssVars?this.context.themeToCssVars():`:root { /* CSS Variables will be generated here */ }`;this.stylePartitionManager.updateRuleContent(`css-vars`,e)}getInsertionPoint(){if(typeof this.options.insertionPoint!=`string`)return this.options.insertionPoint;switch(this.options.insertionPoint){case`body`:return document.body||document.head;default:return document.head}}addClass(e){if(this.isDestroyed)return;let t=this.normalizeClasses(e).filter(Boolean);t.forEach(e=>this.pinned.add(e)),this.processClasses(t)}processClasses(e){this.processClassesIncremental(e)}processClassesIncremental(e){let t=typeof window<`u`,n=this.incrementalParser.processClasses(e);this.debugLog(`debug`,`results`,{results:n,classList:e}),this.applyParseResults(n,{isBrowser:t})}applyParseResults(e,t){if(this.isDestroyed)return;if(!this.shadowRoot&&this.getInsertionPoint().isConnected&&this.stylePartitionManager.hasDetachedPartitions()){let t=Array.from(this.cache.values());this.reset(),e=[...t,...e],e.forEach(e=>this.incrementalParser.markProcessed(e.cls))}if(this.ssrClasses.size>0&&(e=e.filter(e=>!this.ssrClasses.has(e.cls))),this.options.skipExisting&&e.length>0&&typeof document<`u`){let t=this.getExistingClasses();e=e.filter(e=>!t.has(e.cls))}if(e.length===0)return;let n=[],r=[],i=this.options.skipExisting&&typeof document<`u`?(this.getExistingClasses(),this.existingKeyframes):null;for(let t of e)if(t.css&&Array.isArray(t.cssList)&&(n.push(t),this.cache.set(t.cls,t)),t.rootCss&&Array.isArray(t.rootCssList))for(let e of t.rootCssList){if(i?.size){let t=/^\s*@keyframes\s+([^\s{]+)/.exec(e)?.[1];if(t&&i.has(t))continue}this.rootCache.has(e)||(this.rootCache.add(e),r.push(e))}r.length>0&&this.stylePartitionManager.addRootRules(r.filter(Boolean)),n.length>0&&this.stylePartitionManager.addRules(n),this.debugLog(`info`,`Applied ${e.length} parser results`,{cssRuleCount:n.length,rootCssCount:r.length})}isPermanent(e){return this.pinned.has(e)||this.ssrClasses.has(e)?!0:this.shadowRoot?!1:typeof document>`u`||this.getExistingClasses().has(e)}reclaim(e){if(this.isDestroyed)return;let t=e.filter(e=>this.cache.has(e));if(t.length===0)return;let n=t.map(e=>this.cache.get(e));t.forEach(e=>{this.cache.delete(e),this.incrementalParser.unmarkProcessed(e)});let r=new Set;for(let e of this.cache.values())e.cssList.forEach(e=>r.add(e));for(let e of n){let t=this.getCategory(e.cls);for(let n of e.cssList)r.has(n)||this.stylePartitionManager.removeRule(n,t)}this.reclaimedCount+=t.length}getExistingClasses(){let e=new Set(Array.from(document.querySelectorAll(`style[data-barocss]`),e=>e.sheet)),t=Array.from(document.styleSheets).filter(t=>{if(e.has(t))return!1;let n=t.ownerNode;return!(n&&typeof n.hasAttribute==`function`&&(n.hasAttribute(`data-barocss`)||(n.id||``).startsWith(this.options.styleId)))});if(this.existing&&t.length===this.existingSheetCount)return this.existing;let n=new Set,r=new Set;for(let e of t){let t;try{t=e.cssRules}catch{continue}u(t,n),l(t,r)}return this.existingKeyframes=r,this.existing=n,this.existingSheetCount=t.length,n}observe(e=this.shadowRoot??document.body,t){return this.observedOnce||(this.observedOnce=!0,this.adoptSsrSheets()),this.changeDetector.observe(e,t)}normalizeClasses(e){return(Array.isArray(e)?e:[e]).flatMap(i)}has(e){return this.cache.has(e)}getCss(e){return this.cache.get(e)?.cssList.join(`
14
+ `)}},S=new Map;function C(e,t=m){let n=p(e),r=S.get(n);return r||(r=new x(t(n),e,n),S.set(n,r)),r}function w(e){e.rootCount===0&&S.get(e.fullKey)===e&&S.delete(e.fullKey)}var T=class extends e.IncrementalParser{constructor(e){super(e.context),this.shared=e}processClass(e){if(this.isProcessed(e))return null;let t=this.shared.results.get(e);if(t)return this.markProcessed(e),t;let n=super.processClass(e);return n&&(this.shared.results.set(e,n),this.shared.generations++),n}},E=class{constructor(t,n,r=t=>(0,e.parseClassName)(t).utility?.category,i={}){this.shared=t,this.root=n,this.getCategory=r,this.opts=i,this.owned=new Set,this.scopePreflight=n.nodeType===11,t.attach(n,i.nonce)}hasDetachedPartitions(){return!1}updateRuleContent(e,t){e===`preflight`?this.shared.setPrologue(`preflight`,this.scopePreflight?f(t):t):e===`css-vars`&&this.shared.setPrologue(`vars`,t)}take(e,t){return this.owned.has(e)||(this.root.nodeType===11&&_.test(e)&&(y(this.root.ownerDocument??(typeof document<`u`?document:null),[e],this.opts)||this.shared.addPropertyFallback([e])),!this.shared.retain(e,t))?!1:(this.owned.add(e),!0)}addRule(e){return this.take(e,``)}addCategoryRule(e,t){return this.take(e,`c:${t}`)}addRootRules(e){let t=0;for(let n of e)this.take(n,`root`)&&t++;return{success:t,failed:e.length-t}}addRules(e){let t=0,n=0;for(let r of e){let e=this.getCategory(r.cls);for(let i of r.cssList)(e?this.addCategoryRule(i,e):this.addRule(i))?t++:n++}return{success:t,failed:n}}removeRule(e,t){return this.owned.delete(e)?(this.shared.release(e),!0):!1}get ruleCount(){return this.owned.size}cleanup(){this.owned.forEach(e=>this.shared.release(e)),this.owned.clear(),this.shared.detach(this.root),w(this.shared)}},D=`style[data-barocss-ssr]`,O=`@layer theme, base, components, utilities;`,k=class{constructor(t={}){this.cache=new Map,this.rootCache=new Set,this.shadowRoot=null,this.isDestroyed=!1,this.existing=null,this.existingKeyframes=new Set,this.existingSheetCount=-1,this.pinned=new Set,this.gc=null,this.reclaimedCount=0,this.ssrRules=[],this.ssrClasses=new Set,this.observedOnce=!1,this.getCategory=t=>(0,e.parseClassName)(t,this.context).utility?.category;let n={};this.options={config:t.config||n,styleId:t.styleId||`barocss-runtime`,insertionPoint:t.insertionPoint||`head`,maxRulesPerPartition:t.maxRulesPerPartition||50,skipExisting:t.skipExisting??!1,gc:t.gc??!0,gcGraceMs:t.gcGraceMs??3e3,maxRules:t.maxRules??1/0,nonce:t.nonce??``,constructable:t.constructable??!1};let r=t.root;if(r&&r.nodeType===11&&(this.shadowRoot=r),this.shadowRoot){let e=C(this.options.config);this.context=e.context,this.incrementalParser=new T(e)}else this.context=(0,e.createContext)(this.options.config),this.incrementalParser=new e.IncrementalParser(this.context);this.changeDetector=new a(this.incrementalParser,this,this.getCategory),this.stylePartitionManager=this.createStyles(),this.options.gc&&(this.gc=new d({reclaim:e=>this.reclaim(e),isPermanent:e=>this.isPermanent(e),cachedCount:()=>this.cache.size},this.options.gcGraceMs,this.options.maxRules),this.changeDetector.setGc(this.gc)),this.init(),this.shadowRoot&&this.observe(this.shadowRoot,{scan:!0})}createStyles(){if(this.shadowRoot){let e=this.incrementalParser.shared,t=C(this.options.config);return t!==e&&(e=t,this.context=e.context,this.incrementalParser=new T(e),this.changeDetector?.setParser(this.incrementalParser)),new E(e,this.shadowRoot,this.getCategory,{nonce:this.options.nonce,constructable:this.options.constructable})}return this.options.constructable&&typeof document<`u`&&h(`document`)?new E(new x(`document`,this.options.config,`document`,{context:this.context,target:`document`}),document,this.getCategory):new t(this.getInsertionPoint(),this.options.maxRulesPerPartition,`${this.options.styleId}-partition`,this.getCategory,this.options.nonce)}debugLog(t,n,r){(0,e.isDebug)()&&(console[t]||console.log)(`[BrowserRuntime:${t.toUpperCase()}] ${n}`,r||``)}init(){this.debugLog(`debug`,`init`),this.injectPreflightCSS(),this.ensureCssVars(),this.adoptSsrSheets()}adoptSsrSheets(){if(typeof document>`u`||this.shadowRoot)return;let e=[];if(document.head){for(let t of Array.from(document.head.querySelectorAll(`${D}:not([data-barocss-adopted])`))){let n=t.sheet;if(!n)continue;t.setAttribute(`data-barocss-adopted`,``);let r=[];for(let e=n.cssRules.length-1;e>=0;e--){let t=n.cssRules[e],i=u([t]);i.size!==0&&(i.forEach(e=>this.ssrClasses.add(e)),r.unshift({css:t.cssText,cls:i.values().next().value}),n.deleteRule(e))}e.push(...r)}e.length!==0&&(this.ssrRules.push(...e),this.insertSsrRules(e))}}insertSsrRules(e){for(let{css:t,cls:n}of e){let e=this.getCategory(n);e?this.stylePartitionManager.addCategoryRule(t,e):this.stylePartitionManager.addRule(t)}}injectPreflightCSS(){let e=this.options.config.preflight??!0;if(e){let t=this.context.getPreflightCSS(e);this.stylePartitionManager.updateRuleContent(`preflight`,`${O}\n@layer base {\n${t}\n}`,!0)}}ensureCssVars(){if(this.isDestroyed)return;let e=this.context.themeToCssVars?this.context.themeToCssVars():`:root { /* CSS Variables will be generated here */ }`;this.stylePartitionManager.updateRuleContent(`css-vars`,e)}getInsertionPoint(){if(typeof this.options.insertionPoint!=`string`)return this.options.insertionPoint;switch(this.options.insertionPoint){case`body`:return document.body||document.head;default:return document.head}}addClass(e){if(this.isDestroyed)return;let t=this.normalizeClasses(e).filter(Boolean);t.forEach(e=>this.pinned.add(e)),this.processClasses(t)}processClasses(e){this.processClassesIncremental(e)}processClassesIncremental(e){let t=typeof window<`u`,n=this.incrementalParser.processClasses(e);this.debugLog(`debug`,`results`,{results:n,classList:e}),this.applyParseResults(n,{isBrowser:t})}applyParseResults(e,t){if(this.isDestroyed)return;if(!this.shadowRoot&&this.getInsertionPoint().isConnected&&this.stylePartitionManager.hasDetachedPartitions()){let t=Array.from(this.cache.values());this.reset(),e=[...t,...e],e.forEach(e=>this.incrementalParser.markProcessed(e.cls))}if(this.ssrClasses.size>0&&(e=e.filter(e=>!this.ssrClasses.has(e.cls))),this.options.skipExisting&&e.length>0&&typeof document<`u`){let t=this.getExistingClasses();e=e.filter(e=>!t.has(e.cls))}if(e.length===0)return;let n=[],r=[],i=this.options.skipExisting&&typeof document<`u`?(this.getExistingClasses(),this.existingKeyframes):null;for(let t of e)if(t.css&&Array.isArray(t.cssList)&&(n.push(t),this.cache.set(t.cls,t)),t.rootCss&&Array.isArray(t.rootCssList))for(let e of t.rootCssList){if(i?.size){let t=/^\s*@keyframes\s+([^\s{]+)/.exec(e)?.[1];if(t&&i.has(t))continue}this.rootCache.has(e)||(this.rootCache.add(e),r.push(e))}r.length>0&&this.stylePartitionManager.addRootRules(r.filter(Boolean)),n.length>0&&this.stylePartitionManager.addRules(n),this.debugLog(`info`,`Applied ${e.length} parser results`,{cssRuleCount:n.length,rootCssCount:r.length})}isPermanent(e){return this.pinned.has(e)||this.ssrClasses.has(e)?!0:this.shadowRoot?!1:typeof document>`u`||this.getExistingClasses().has(e)}reclaim(e){if(this.isDestroyed)return;let t=e.filter(e=>this.cache.has(e));if(t.length===0)return;let n=t.map(e=>this.cache.get(e));t.forEach(e=>{this.cache.delete(e),this.incrementalParser.unmarkProcessed(e)});let r=new Set;for(let e of this.cache.values())e.cssList.forEach(e=>r.add(e));for(let e of n){let t=this.getCategory(e.cls);for(let n of e.cssList)r.has(n)||this.stylePartitionManager.removeRule(n,t)}this.reclaimedCount+=t.length}getExistingClasses(){let e=new Set(Array.from(document.querySelectorAll(`style[data-barocss]`),e=>e.sheet)),t=Array.from(document.styleSheets).filter(t=>{if(e.has(t))return!1;let n=t.ownerNode;return!(n&&typeof n.hasAttribute==`function`&&(n.hasAttribute(`data-barocss`)||(n.id||``).startsWith(this.options.styleId)))});if(this.existing&&t.length===this.existingSheetCount)return this.existing;let n=new Set,r=new Set;for(let e of t){let t;try{t=e.cssRules}catch{continue}u(t,n),l(t,r)}return this.existingKeyframes=r,this.existing=n,this.existingSheetCount=t.length,n}observe(e=this.shadowRoot??document.body,t){return this.observedOnce||(this.observedOnce=!0,this.adoptSsrSheets()),this.changeDetector.observe(e,t)}normalizeClasses(e){return(Array.isArray(e)?e:[e]).flatMap(i)}has(e){return this.cache.has(e)}getCss(e){return this.cache.get(e)?.cssList.join(`
14
15
  `)}getAllCss(){return[...this.rootCache,...Array.from(this.cache.values()).flatMap(e=>e.cssList)].join(`
15
- `)}getClasses(){return Array.from(this.cache.keys())}getCacheStats(){let e=this.incrementalParser.getStats();return{runtime:{cachedClasses:this.cache.size,rootCacheSize:this.rootCache.size,ruleCount:this.stylePartitionManager.ruleCount,reclaimedClasses:this.reclaimedCount,gc:this.gc?.stats()??null},ast:e.cacheStats.ast,incremental:e}}clearCaches(){this.isDestroyed||(this.cache.clear(),this.rootCache.clear(),(0,e.clearAstCache)(this.context),this.incrementalParser.clearProcessed(),this.stylePartitionManager.cleanup(),this.stylePartitionManager=this.createStyles(),this.injectPreflightCSS(),this.ensureCssVars(),this.insertSsrRules(this.ssrRules))}reset(){this.isDestroyed||(this.cache.clear(),this.rootCache.clear(),this.incrementalParser.clearProcessed(),this.stylePartitionManager.cleanup(),this.stylePartitionManager=this.createStyles(),this.injectPreflightCSS(),this.ensureCssVars(),this.insertSsrRules(this.ssrRules))}updateConfig(t){if(this.isDestroyed)return;let n=Array.from(this.cache.keys());if(this.options.config=t,this.shadowRoot){this.stylePartitionManager.cleanup();let e=y(t);this.context=e.context,this.incrementalParser=new x(e)}else this.context=(0,e.createContext)(t),this.incrementalParser=new e.IncrementalParser(this.context);this.changeDetector.setParser(this.incrementalParser),this.reset(),n.length>0&&this.addClass(n)}removeClass(e){if(this.isDestroyed)return;let t=new Set(this.normalizeClasses(e)),n=Array.from(this.cache.values()).filter(e=>!t.has(e.cls));n.length!==this.cache.size&&(this.reset(),n.forEach(e=>this.incrementalParser.markProcessed(e.cls)),this.applyParseResults(n))}destroy(){this.isDestroyed||=(this.changeDetector.disconnect(),this.gc?.cancel(),this.stylePartitionManager.cleanup(),this.cache.clear(),this.rootCache.clear(),!0)}getStats(){return{cachedClasses:this.cache.size,styleElementId:this.options.styleId,isDestroyed:this.isDestroyed,config:this.options.config,cacheStats:this.getCacheStats(),adopted:!this.shadowRoot&&this.stylePartitionManager instanceof S,sharedSheet:this.shadowRoot&&this.stylePartitionManager instanceof S?{roots:this.stylePartitionManager.shared.rootCount,rules:this.stylePartitionManager.shared.ruleCount,generations:this.stylePartitionManager.shared.generations,constructable:this.stylePartitionManager.shared.constructable}:null}}},E=null,D,O=``,k=!1,A=!1;function j(e={}){if(!E||E.getStats().isDestroyed?(E=new T(e),D=e.config,O=e.nonce??``,k=e.constructable??!1,A=!1):e.config&&e.config!==D&&(E.updateConfig(e.config),D=e.config),!A){let t=e.nonce!==void 0&&e.nonce!==O,n=e.constructable!==void 0&&e.constructable!==k;if(t||n){A=!0;let e=[t&&`nonce (runtime has ${O?`a different nonce`:`none`})`,n&&`constructable (runtime has ${k})`].filter(Boolean).join(` and `);console.warn(`[BaroCSS] runtime already created with a different ${e}; the new value is ignored. Pass nonce/constructable on the first getRuntime/baroStart call.`)}}return E}function M({loadingClassName:e=`baro-boot`,...t}={}){if(t.root&&t.root.nodeType===11)return new T(t);if(!document.body){document.addEventListener(`DOMContentLoaded`,()=>M({loadingClassName:e,...t}),{once:!0});return}let n=`${e}-doing`,r=`${e}-done`;try{document.body.classList.add(n),j(t).observe(document.body,{scan:!0,onReady:()=>{document.body.classList.remove(n),document.body.classList.add(r)}})}catch(e){document.body?.classList.remove(n),console.error(`BaroCSS boot failed:`,e)}}var N=M;function P(e){if(!e||typeof e!=`object`||Array.isArray(e))return[];let t=e.elements;if(!t||typeof t!=`object`||Array.isArray(t))return[];let n=new Set;for(let e of Object.keys(t)){let r=t[e];if(!r||typeof r!=`object`||Array.isArray(r))continue;let a=r.props;if(!a||typeof a!=`object`||Array.isArray(a))continue;let o=a.className;if(typeof o==`string`)for(let e of i(o))e&&n.add(e)}return Array.from(n)}function F(e,t){let n=P(e);n.length>0&&t.addClass(n)}var I={colors:Object.fromEntries(`background.foreground.card.card-foreground.popover.popover-foreground.primary.primary-foreground.secondary.secondary-foreground.muted.muted-foreground.accent.accent-foreground.destructive.border.input.ring.chart-1.chart-2.chart-3.chart-4.chart-5.sidebar.sidebar-foreground.sidebar-primary.sidebar-primary-foreground.sidebar-accent.sidebar-accent-foreground.sidebar-border.sidebar-ring`.split(`.`).map(e=>[e,`var(--${e})`])),borderRadius:{sm:`calc(var(--radius) - 4px)`,md:`calc(var(--radius) - 2px)`,lg:`var(--radius)`,xl:`calc(var(--radius) + 4px)`}};exports.BrowserRuntime=T,exports.ChangeDetector=a,exports.LAYER_ORDER=w,exports.SSR_STYLE_SELECTOR=C,exports.StylePartitionManager=t,exports.baroBoot=M,exports.baroStart=N,exports.collectJsonRenderClassNames=P,exports.getRuntime=j,exports.normalizeClassName=r,exports.normalizeClassNameList=i,exports.preloadJsonRenderClasses=F,exports.shadcnTheme=I;
16
+ `)}getClasses(){return Array.from(this.cache.keys())}getCacheStats(){let e=this.incrementalParser.getStats();return{runtime:{cachedClasses:this.cache.size,rootCacheSize:this.rootCache.size,ruleCount:this.stylePartitionManager.ruleCount,reclaimedClasses:this.reclaimedCount,gc:this.gc?.stats()??null},ast:e.cacheStats.ast,incremental:e}}clearCaches(){this.isDestroyed||(this.cache.clear(),this.rootCache.clear(),(0,e.clearAstCache)(this.context),this.incrementalParser.clearProcessed(),this.stylePartitionManager.cleanup(),this.stylePartitionManager=this.createStyles(),this.injectPreflightCSS(),this.ensureCssVars(),this.insertSsrRules(this.ssrRules))}reset(){this.isDestroyed||(this.cache.clear(),this.rootCache.clear(),this.incrementalParser.clearProcessed(),this.stylePartitionManager.cleanup(),this.stylePartitionManager=this.createStyles(),this.injectPreflightCSS(),this.ensureCssVars(),this.insertSsrRules(this.ssrRules))}updateConfig(t){if(this.isDestroyed)return;let n=Array.from(this.cache.keys());if(this.options.config=t,this.shadowRoot){this.stylePartitionManager.cleanup();let e=C(t);this.context=e.context,this.incrementalParser=new T(e)}else this.context=(0,e.createContext)(t),this.incrementalParser=new e.IncrementalParser(this.context);this.changeDetector.setParser(this.incrementalParser),this.reset(),n.length>0&&this.addClass(n)}removeClass(e){if(this.isDestroyed)return;let t=new Set(this.normalizeClasses(e)),n=Array.from(this.cache.values()).filter(e=>!t.has(e.cls));n.length!==this.cache.size&&(this.reset(),n.forEach(e=>this.incrementalParser.markProcessed(e.cls)),this.applyParseResults(n))}destroy(){this.isDestroyed||=(this.changeDetector.disconnect(),this.gc?.cancel(),this.stylePartitionManager.cleanup(),this.cache.clear(),this.rootCache.clear(),!0)}getStats(){return{cachedClasses:this.cache.size,styleElementId:this.options.styleId,isDestroyed:this.isDestroyed,config:this.options.config,cacheStats:this.getCacheStats(),adopted:!this.shadowRoot&&this.stylePartitionManager instanceof E,sharedSheet:this.shadowRoot&&this.stylePartitionManager instanceof E?{roots:this.stylePartitionManager.shared.rootCount,rules:this.stylePartitionManager.shared.ruleCount,generations:this.stylePartitionManager.shared.generations,constructable:this.stylePartitionManager.shared.constructable}:null}}},A=null,j,M=``,N=!1,P=!1;function F(e={}){if(!A||A.getStats().isDestroyed?(A=new k(e),j=e.config,M=e.nonce??``,N=e.constructable??!1,P=!1):e.config&&e.config!==j&&(A.updateConfig(e.config),j=e.config),!P){let t=e.nonce!==void 0&&e.nonce!==M,n=e.constructable!==void 0&&e.constructable!==N;if(t||n){P=!0;let e=[t&&`nonce (runtime has ${M?`a different nonce`:`none`})`,n&&`constructable (runtime has ${N})`].filter(Boolean).join(` and `);console.warn(`[BaroCSS] runtime already created with a different ${e}; the new value is ignored. Pass nonce/constructable on the first getRuntime/baroStart call.`)}}return A}function I({loadingClassName:e=`baro-boot`,...t}={}){if(t.root&&t.root.nodeType===11)return new k(t);if(!document.body){document.addEventListener(`DOMContentLoaded`,()=>I({loadingClassName:e,...t}),{once:!0});return}let n=`${e}-doing`,r=`${e}-done`;try{document.body.classList.add(n),F(t).observe(document.body,{scan:!0,onReady:()=>{document.body.classList.remove(n),document.body.classList.add(r)}})}catch(e){document.body?.classList.remove(n),console.error(`BaroCSS boot failed:`,e)}}var L=I;function R(e){if(!e||typeof e!=`object`||Array.isArray(e))return[];let t=e.elements;if(!t||typeof t!=`object`||Array.isArray(t))return[];let n=new Set;for(let e of Object.keys(t)){let r=t[e];if(!r||typeof r!=`object`||Array.isArray(r))continue;let a=r.props;if(!a||typeof a!=`object`||Array.isArray(a))continue;let o=a.className;if(typeof o==`string`)for(let e of i(o))e&&n.add(e)}return Array.from(n)}function z(e,t){let n=R(e);n.length>0&&t.addClass(n)}var B={colors:Object.fromEntries(`background.foreground.card.card-foreground.popover.popover-foreground.primary.primary-foreground.secondary.secondary-foreground.muted.muted-foreground.accent.accent-foreground.destructive.border.input.ring.chart-1.chart-2.chart-3.chart-4.chart-5.sidebar.sidebar-foreground.sidebar-primary.sidebar-primary-foreground.sidebar-accent.sidebar-accent-foreground.sidebar-border.sidebar-ring`.split(`.`).map(e=>[e,`var(--${e})`])),borderRadius:{sm:`calc(var(--radius) - 4px)`,md:`calc(var(--radius) - 2px)`,lg:`var(--radius)`,xl:`calc(var(--radius) + 4px)`}};exports.BrowserRuntime=k,exports.ChangeDetector=a,exports.LAYER_ORDER=O,exports.SSR_STYLE_SELECTOR=D,exports.StylePartitionManager=t,exports.baroBoot=I,exports.baroStart=L,exports.collectJsonRenderClassNames=R,exports.getRuntime=F,exports.normalizeClassName=r,exports.normalizeClassNameList=i,exports.preloadJsonRenderClasses=z,exports.shadcnTheme=B;
package/dist/index.d.cts CHANGED
@@ -240,6 +240,7 @@ export declare interface BrowserRuntimeOptions {
240
240
  * so no nonce is needed. The adopted sheets come after every document sheet in cascade order (preflight stays
241
241
  * in `@layer base`). Where `document.adoptedStyleSheets` is unsupported it falls back to `<style>` elements
242
242
  * (with `nonce` when set). `insertionPoint`, `styleId` and `maxRulesPerPartition` are ignored when adopted.
243
+ * #384: with a shadow `root` it only makes the document-level `@property` sheet an adopted sheet.
243
244
  * Default: false.
244
245
  */
245
246
  constructable?: boolean;
package/dist/index.d.ts CHANGED
@@ -240,6 +240,7 @@ export declare interface BrowserRuntimeOptions {
240
240
  * so no nonce is needed. The adopted sheets come after every document sheet in cascade order (preflight stays
241
241
  * in `@layer base`). Where `document.adoptedStyleSheets` is unsupported it falls back to `<style>` elements
242
242
  * (with `nonce` when set). `insertionPoint`, `styleId` and `maxRulesPerPartition` are ignored when adopted.
243
+ * #384: with a shadow `root` it only makes the document-level `@property` sheet an adopted sheet.
243
244
  * Default: false.
244
245
  */
245
246
  constructable?: boolean;
package/dist/index.es.js CHANGED
@@ -26,12 +26,14 @@ var c = class {
26
26
  return t && r ? r.insertBefore(n.styleElement, r.firstChild) : this.insertionPoint.appendChild(n.styleElement), this.categoryPartitions.set(e, n), n;
27
27
  }
28
28
  createNewPartition() {
29
- let e = {
29
+ let e = this.partitions[this.partitions.length - 1], t = {
30
30
  id: this.styleIdPrefix + `-${this.partitionCounter++}`,
31
31
  styles: [],
32
32
  styleElement: this.createStyleElement()
33
33
  };
34
- return this.partitions.push(e), e.styleElement.id = e.id, e.styleElement.setAttribute("data-barocss", "partition"), e.styleElement.setAttribute("data-partition-index", this.partitionCounter.toString()), this.insertionPoint.appendChild(e.styleElement), e;
34
+ this.partitions.push(t), t.styleElement.id = t.id, t.styleElement.setAttribute("data-barocss", "partition"), t.styleElement.setAttribute("data-partition-index", this.partitionCounter.toString());
35
+ let n = e?.styleElement.parentNode;
36
+ return n ? n.insertBefore(t.styleElement, e.styleElement.nextSibling) : this.insertionPoint.appendChild(t.styleElement), t;
35
37
  }
36
38
  hasRule(e) {
37
39
  return this.classToPartitionMap.has(e);
@@ -357,12 +359,52 @@ function S(e = "shadow") {
357
359
  return !1;
358
360
  }
359
361
  }
360
- var C = (e) => e.replace(/\\\//g, "\\/"), w = class {
362
+ var C = (e) => e.replace(/\\\//g, "\\/"), w = /^\s*@property\s/, T = null;
363
+ function E(e, t, n = {}) {
364
+ let r = t.filter((e) => w.test(e));
365
+ if (r.length === 0) return !0;
366
+ try {
367
+ if (!e) return !1;
368
+ if (!T || T.doc !== e || T.style && !T.style.isConnected) {
369
+ let t = {
370
+ doc: e,
371
+ rules: /* @__PURE__ */ new Set()
372
+ };
373
+ if (n.constructable && S("document")) t.sheet = new CSSStyleSheet(), e.adoptedStyleSheets = [...e.adoptedStyleSheets, t.sheet];
374
+ else {
375
+ let r = e.head ?? e.documentElement;
376
+ if (!r) return !1;
377
+ let i = e.createElement("style");
378
+ i.setAttribute("data-barocss", "document-properties"), n.nonce && i.setAttribute("nonce", n.nonce), r.appendChild(i), t.style = i;
379
+ }
380
+ T = t;
381
+ }
382
+ let t = T;
383
+ for (let e of r) {
384
+ if (t.rules.has(e)) continue;
385
+ let n = t.sheet ?? t.style?.sheet ?? null;
386
+ n ? n.insertRule(C(e), n.cssRules.length) : t.style && (t.style.textContent += `${e}\n`), t.rules.add(e);
387
+ }
388
+ return !0;
389
+ } catch (e) {
390
+ return i() && console.warn("[BrowserRuntime] could not register @property rules in the document; using :host initial values", e), !1;
391
+ }
392
+ }
393
+ function D(e) {
394
+ let t = [];
395
+ for (let n of e) {
396
+ let e = /^\s*@property\s+(--[\w-]+)/.exec(n)?.[1], r = /initial-value\s*:\s*([^;}]*)/.exec(n)?.[1]?.trim();
397
+ e && r && t.push(`${e}: ${r}`);
398
+ }
399
+ return t.length === 0 ? "" : `@layer properties {\n:host, *, ::before, ::after, ::backdrop {\n ${t.join(";\n ")};\n}\n}`;
400
+ }
401
+ var O = class {
361
402
  constructor(e, t, n = e, i = {}) {
362
403
  this.results = /* @__PURE__ */ new Map(), this.generations = 0, this.prologueSheet = null, this.rulesSheet = null, this.prologue = {
404
+ props: "",
363
405
  preflight: "",
364
406
  vars: ""
365
- }, this.segments = /* @__PURE__ */ new Map([["root", {
407
+ }, this.fallbackProps = /* @__PURE__ */ new Set(), this.segments = /* @__PURE__ */ new Map([["root", {
366
408
  rules: [],
367
409
  keys: []
368
410
  }], ["", {
@@ -396,6 +438,11 @@ var C = (e) => e.replace(/\\\//g, "\\/"), w = class {
396
438
  let [n] = this.attached.splice(t, 1);
397
439
  n.styles ? n.styles.forEach((e) => e.remove()) : e.adoptedStyleSheets &&= e.adoptedStyleSheets.filter((e) => e !== this.prologueSheet && e !== this.rulesSheet);
398
440
  }
441
+ addPropertyFallback(e) {
442
+ let t = this.fallbackProps.size;
443
+ for (let t of e) w.test(t) && this.fallbackProps.add(t);
444
+ this.fallbackProps.size !== t && this.setPrologue("props", D(Array.from(this.fallbackProps)));
445
+ }
399
446
  setPrologue(e, t) {
400
447
  if (this.prologue[e] === t) return;
401
448
  this.prologue[e] = t;
@@ -404,7 +451,11 @@ var C = (e) => e.replace(/\\\//g, "\\/"), w = class {
404
451
  for (let e of this.attached) e.styles && (e.styles[0].textContent = n);
405
452
  }
406
453
  prologueText() {
407
- return [this.prologue.preflight, this.prologue.vars].filter(Boolean).join("\n");
454
+ return [
455
+ this.prologue.props,
456
+ this.prologue.preflight,
457
+ this.prologue.vars
458
+ ].filter(Boolean).join("\n");
408
459
  }
409
460
  allRules() {
410
461
  return Array.from(this.segments.values()).flatMap((e) => e.rules);
@@ -480,15 +531,15 @@ var C = (e) => e.replace(/\\\//g, "\\/"), w = class {
480
531
  cssText() {
481
532
  return [this.prologueText(), ...this.allRules()].join("\n");
482
533
  }
483
- }, T = /* @__PURE__ */ new Map();
484
- function E(e, t = x) {
485
- let n = b(e), r = T.get(n);
486
- return r || (r = new w(t(n), e, n), T.set(n, r)), r;
534
+ }, k = /* @__PURE__ */ new Map();
535
+ function A(e, t = x) {
536
+ let n = b(e), r = k.get(n);
537
+ return r || (r = new O(t(n), e, n), k.set(n, r)), r;
487
538
  }
488
- function D(e) {
489
- e.rootCount === 0 && T.get(e.fullKey) === e && T.delete(e.fullKey);
539
+ function j(e) {
540
+ e.rootCount === 0 && k.get(e.fullKey) === e && k.delete(e.fullKey);
490
541
  }
491
- var O = class extends e {
542
+ var M = class extends e {
492
543
  constructor(e) {
493
544
  super(e.context), this.shared = e;
494
545
  }
@@ -499,9 +550,9 @@ var O = class extends e {
499
550
  let n = super.processClass(e);
500
551
  return n && (this.shared.results.set(e, n), this.shared.generations++), n;
501
552
  }
502
- }, k = class {
553
+ }, N = class {
503
554
  constructor(e, t, n = (e) => a(e).utility?.category, r = {}) {
504
- this.shared = e, this.root = t, this.getCategory = n, this.owned = /* @__PURE__ */ new Set(), this.scopePreflight = t.nodeType === 11, e.attach(t, r.nonce);
555
+ this.shared = e, this.root = t, this.getCategory = n, this.opts = r, this.owned = /* @__PURE__ */ new Set(), this.scopePreflight = t.nodeType === 11, e.attach(t, r.nonce);
505
556
  }
506
557
  hasDetachedPartitions() {
507
558
  return !1;
@@ -510,7 +561,7 @@ var O = class extends e {
510
561
  e === "preflight" ? this.shared.setPrologue("preflight", this.scopePreflight ? y(t) : t) : e === "css-vars" && this.shared.setPrologue("vars", t);
511
562
  }
512
563
  take(e, t) {
513
- return this.owned.has(e) || !this.shared.retain(e, t) ? !1 : (this.owned.add(e), !0);
564
+ return this.owned.has(e) || (this.root.nodeType === 11 && w.test(e) && (E(this.root.ownerDocument ?? (typeof document < "u" ? document : null), [e], this.opts) || this.shared.addPropertyFallback([e])), !this.shared.retain(e, t)) ? !1 : (this.owned.add(e), !0);
514
565
  }
515
566
  addRule(e) {
516
567
  return this.take(e, "");
@@ -544,9 +595,9 @@ var O = class extends e {
544
595
  return this.owned.size;
545
596
  }
546
597
  cleanup() {
547
- this.owned.forEach((e) => this.shared.release(e)), this.owned.clear(), this.shared.detach(this.root), D(this.shared);
598
+ this.owned.forEach((e) => this.shared.release(e)), this.owned.clear(), this.shared.detach(this.root), j(this.shared);
548
599
  }
549
- }, A = "style[data-barocss-ssr]", j = "@layer theme, base, components, utilities;", M = class {
600
+ }, P = "style[data-barocss-ssr]", F = "@layer theme, base, components, utilities;", I = class {
550
601
  constructor(t = {}) {
551
602
  this.cache = /* @__PURE__ */ new Map(), this.rootCache = /* @__PURE__ */ new Set(), this.shadowRoot = null, this.isDestroyed = !1, this.existing = null, this.existingKeyframes = /* @__PURE__ */ new Set(), this.existingSheetCount = -1, this.pinned = /* @__PURE__ */ new Set(), this.gc = null, this.reclaimedCount = 0, this.ssrRules = [], this.ssrClasses = /* @__PURE__ */ new Set(), this.observedOnce = !1, this.getCategory = (e) => a(e, this.context).utility?.category;
552
603
  let n = {};
@@ -564,8 +615,8 @@ var O = class extends e {
564
615
  };
565
616
  let i = t.root;
566
617
  if (i && i.nodeType === 11 && (this.shadowRoot = i), this.shadowRoot) {
567
- let e = E(this.options.config);
568
- this.context = e.context, this.incrementalParser = new O(e);
618
+ let e = A(this.options.config);
619
+ this.context = e.context, this.incrementalParser = new M(e);
569
620
  } else this.context = r(this.options.config), this.incrementalParser = new e(this.context);
570
621
  this.changeDetector = new f(this.incrementalParser, this, this.getCategory), this.stylePartitionManager = this.createStyles(), this.options.gc && (this.gc = new v({
571
622
  reclaim: (e) => this.reclaim(e),
@@ -575,10 +626,13 @@ var O = class extends e {
575
626
  }
576
627
  createStyles() {
577
628
  if (this.shadowRoot) {
578
- let e = this.incrementalParser.shared, t = E(this.options.config);
579
- return t !== e && (e = t, this.context = e.context, this.incrementalParser = new O(e), this.changeDetector?.setParser(this.incrementalParser)), new k(e, this.shadowRoot, this.getCategory, { nonce: this.options.nonce });
629
+ let e = this.incrementalParser.shared, t = A(this.options.config);
630
+ return t !== e && (e = t, this.context = e.context, this.incrementalParser = new M(e), this.changeDetector?.setParser(this.incrementalParser)), new N(e, this.shadowRoot, this.getCategory, {
631
+ nonce: this.options.nonce,
632
+ constructable: this.options.constructable
633
+ });
580
634
  }
581
- return this.options.constructable && typeof document < "u" && S("document") ? new k(new w("document", this.options.config, "document", {
635
+ return this.options.constructable && typeof document < "u" && S("document") ? new N(new O("document", this.options.config, "document", {
582
636
  context: this.context,
583
637
  target: "document"
584
638
  }), document, this.getCategory) : new c(this.getInsertionPoint(), this.options.maxRulesPerPartition, `${this.options.styleId}-partition`, this.getCategory, this.options.nonce);
@@ -593,7 +647,7 @@ var O = class extends e {
593
647
  if (typeof document > "u" || this.shadowRoot) return;
594
648
  let e = [];
595
649
  if (document.head) {
596
- for (let t of Array.from(document.head.querySelectorAll(`${A}:not([data-barocss-adopted])`))) {
650
+ for (let t of Array.from(document.head.querySelectorAll(`${P}:not([data-barocss-adopted])`))) {
597
651
  let n = t.sheet;
598
652
  if (!n) continue;
599
653
  t.setAttribute("data-barocss-adopted", "");
@@ -620,7 +674,7 @@ var O = class extends e {
620
674
  let e = this.options.config.preflight ?? !0;
621
675
  if (e) {
622
676
  let t = this.context.getPreflightCSS(e);
623
- this.stylePartitionManager.updateRuleContent("preflight", `${j}\n@layer base {\n${t}\n}`, !0);
677
+ this.stylePartitionManager.updateRuleContent("preflight", `${F}\n@layer base {\n${t}\n}`, !0);
624
678
  }
625
679
  }
626
680
  ensureCssVars() {
@@ -755,8 +809,8 @@ var O = class extends e {
755
809
  let n = Array.from(this.cache.keys());
756
810
  if (this.options.config = t, this.shadowRoot) {
757
811
  this.stylePartitionManager.cleanup();
758
- let e = E(t);
759
- this.context = e.context, this.incrementalParser = new O(e);
812
+ let e = A(t);
813
+ this.context = e.context, this.incrementalParser = new M(e);
760
814
  } else this.context = r(t), this.incrementalParser = new e(this.context);
761
815
  this.changeDetector.setParser(this.incrementalParser), this.reset(), n.length > 0 && this.addClass(n);
762
816
  }
@@ -775,8 +829,8 @@ var O = class extends e {
775
829
  isDestroyed: this.isDestroyed,
776
830
  config: this.options.config,
777
831
  cacheStats: this.getCacheStats(),
778
- adopted: !this.shadowRoot && this.stylePartitionManager instanceof k,
779
- sharedSheet: this.shadowRoot && this.stylePartitionManager instanceof k ? {
832
+ adopted: !this.shadowRoot && this.stylePartitionManager instanceof N,
833
+ sharedSheet: this.shadowRoot && this.stylePartitionManager instanceof N ? {
780
834
  roots: this.stylePartitionManager.shared.rootCount,
781
835
  rules: this.stylePartitionManager.shared.ruleCount,
782
836
  generations: this.stylePartitionManager.shared.generations,
@@ -784,22 +838,22 @@ var O = class extends e {
784
838
  } : null
785
839
  };
786
840
  }
787
- }, N = null, P, F = "", I = !1, L = !1;
788
- function R(e = {}) {
789
- if (!N || N.getStats().isDestroyed ? (N = new M(e), P = e.config, F = e.nonce ?? "", I = e.constructable ?? !1, L = !1) : e.config && e.config !== P && (N.updateConfig(e.config), P = e.config), !L) {
790
- let t = e.nonce !== void 0 && e.nonce !== F, n = e.constructable !== void 0 && e.constructable !== I;
841
+ }, L = null, R, z = "", B = !1, V = !1;
842
+ function H(e = {}) {
843
+ if (!L || L.getStats().isDestroyed ? (L = new I(e), R = e.config, z = e.nonce ?? "", B = e.constructable ?? !1, V = !1) : e.config && e.config !== R && (L.updateConfig(e.config), R = e.config), !V) {
844
+ let t = e.nonce !== void 0 && e.nonce !== z, n = e.constructable !== void 0 && e.constructable !== B;
791
845
  if (t || n) {
792
- L = !0;
793
- let e = [t && `nonce (runtime has ${F ? "a different nonce" : "none"})`, n && `constructable (runtime has ${I})`].filter(Boolean).join(" and ");
846
+ V = !0;
847
+ let e = [t && `nonce (runtime has ${z ? "a different nonce" : "none"})`, n && `constructable (runtime has ${B})`].filter(Boolean).join(" and ");
794
848
  console.warn(`[BaroCSS] runtime already created with a different ${e}; the new value is ignored. Pass nonce/constructable on the first getRuntime/baroStart call.`);
795
849
  }
796
850
  }
797
- return N;
851
+ return L;
798
852
  }
799
- function z({ loadingClassName: e = "baro-boot", ...t } = {}) {
800
- if (t.root && t.root.nodeType === 11) return new M(t);
853
+ function U({ loadingClassName: e = "baro-boot", ...t } = {}) {
854
+ if (t.root && t.root.nodeType === 11) return new I(t);
801
855
  if (!document.body) {
802
- document.addEventListener("DOMContentLoaded", () => z({
856
+ document.addEventListener("DOMContentLoaded", () => U({
803
857
  loadingClassName: e,
804
858
  ...t
805
859
  }), { once: !0 });
@@ -807,7 +861,7 @@ function z({ loadingClassName: e = "baro-boot", ...t } = {}) {
807
861
  }
808
862
  let n = `${e}-doing`, r = `${e}-done`;
809
863
  try {
810
- document.body.classList.add(n), R(t).observe(document.body, {
864
+ document.body.classList.add(n), H(t).observe(document.body, {
811
865
  scan: !0,
812
866
  onReady: () => {
813
867
  document.body.classList.remove(n), document.body.classList.add(r);
@@ -817,10 +871,10 @@ function z({ loadingClassName: e = "baro-boot", ...t } = {}) {
817
871
  document.body?.classList.remove(n), console.error("BaroCSS boot failed:", e);
818
872
  }
819
873
  }
820
- var B = z;
874
+ var W = U;
821
875
  //#endregion
822
876
  //#region src/json-render-preload.ts
823
- function V(e) {
877
+ function G(e) {
824
878
  if (!e || typeof e != "object" || Array.isArray(e)) return [];
825
879
  let t = e.elements;
826
880
  if (!t || typeof t != "object" || Array.isArray(t)) return [];
@@ -835,11 +889,11 @@ function V(e) {
835
889
  }
836
890
  return Array.from(n);
837
891
  }
838
- function H(e, t) {
839
- let n = V(e);
892
+ function K(e, t) {
893
+ let n = G(e);
840
894
  n.length > 0 && t.addClass(n);
841
895
  }
842
- var U = {
896
+ var q = {
843
897
  colors: Object.fromEntries((/* @__PURE__ */ "background.foreground.card.card-foreground.popover.popover-foreground.primary.primary-foreground.secondary.secondary-foreground.muted.muted-foreground.accent.accent-foreground.destructive.border.input.ring.chart-1.chart-2.chart-3.chart-4.chart-5.sidebar.sidebar-foreground.sidebar-primary.sidebar-primary-foreground.sidebar-accent.sidebar-accent-foreground.sidebar-border.sidebar-ring".split(".")).map((e) => [e, `var(--${e})`])),
844
898
  borderRadius: {
845
899
  sm: "calc(var(--radius) - 4px)",
@@ -849,4 +903,4 @@ var U = {
849
903
  }
850
904
  };
851
905
  //#endregion
852
- export { M as BrowserRuntime, f as ChangeDetector, j as LAYER_ORDER, A as SSR_STYLE_SELECTOR, c as StylePartitionManager, z as baroBoot, B as baroStart, V as collectJsonRenderClassNames, R as getRuntime, u as normalizeClassName, d as normalizeClassNameList, H as preloadJsonRenderClasses, U as shadcnTheme };
906
+ export { I as BrowserRuntime, f as ChangeDetector, F as LAYER_ORDER, P as SSR_STYLE_SELECTOR, c as StylePartitionManager, U as baroBoot, W as baroStart, G as collectJsonRenderClassNames, H as getRuntime, u as normalizeClassName, d as normalizeClassNameList, K as preloadJsonRenderClasses, q as shadcnTheme };
package/dist/index.umd.js CHANGED
@@ -1,15 +1,16 @@
1
1
  (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@barocss/kit")):typeof define==`function`&&define.amd?define([`exports`,`@barocss/kit`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.BaroCSSBrowser={},e.BaroCSSKit))})(this,function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n=class{insertSorted(e,n,r){let i=e.keys??=[],a=(0,t.upperBound)(i,r),o=e.styleElement.sheet;o&&o.cssRules.length===i.length?(o.insertRule(this.escapeCssRule(n),a),e.styles.splice(a,0,n)):(e.styles.splice(a,0,n),e.styleElement.textContent=e.styles.join(`
2
2
  `)+`
3
- `),i.splice(a,0,r)}constructor(e,n=50,r=`barocss-style-partition-`,i=e=>(0,t.parseClassName)(e).utility?.category,a=``){this.partitions=[],this.categoryPartitions=new Map,this.partitionCounter=0,this.maxRulesPerPartition=50,this.classToPartitionMap=new Map,this.classToCategoryPartitionMap=new Map,this.styleIdPrefix=`barocss-style-partition-`,this.nonce=a,this.insertionPoint=e,this.maxRulesPerPartition=n,this.styleIdPrefix=r,this.getCategory=i,this.initializeDefaultPartition()}createStyleElement(){let e=document.createElement(`style`);return this.nonce&&e.setAttribute(`nonce`,this.nonce),e}initializeDefaultPartition(){this.createNewPartition()}createNewCategoryPartition(e,t=!1){let n={id:this.styleIdPrefix+`-${e}`,styles:[],styleElement:this.createStyleElement()};n.styleElement.id=n.id,n.styleElement.setAttribute(`data-barocss`,`partition`),n.styleElement.setAttribute(`data-category`,e);let r=this.insertionPoint.ownerDocument?.head;return t&&r?r.insertBefore(n.styleElement,r.firstChild):this.insertionPoint.appendChild(n.styleElement),this.categoryPartitions.set(e,n),n}createNewPartition(){let e={id:this.styleIdPrefix+`-${this.partitionCounter++}`,styles:[],styleElement:this.createStyleElement()};return this.partitions.push(e),e.styleElement.id=e.id,e.styleElement.setAttribute(`data-barocss`,`partition`),e.styleElement.setAttribute(`data-partition-index`,this.partitionCounter.toString()),this.insertionPoint.appendChild(e.styleElement),e}hasRule(e){return this.classToPartitionMap.has(e)}hasCategoryRule(e,t){return this.classToCategoryPartitionMap.get(e)===t}setRuleCache(e,t){this.classToPartitionMap.set(e,t)}setCategoryRuleCache(e,t){this.classToCategoryPartitionMap.set(e,t)}get currentPartition(){return this.partitions[this.partitions.length-1]}getCategoryPartition(e){return this.categoryPartitions.get(e)}hasDetachedPartitions(){return[...this.partitions,...this.categoryPartitions.values()].some(e=>!e.styleElement.isConnected)}escapeCssRule(e){return e.replace(/\\\//g,`\\/`)}addRule(e){if(this.hasRule(e))return!1;let n=(0,t.ruleSortKey)(e),r=this.partitions.findIndex(e=>{let r=e.keys;return!!r&&r.length>0&&(0,t.compareKeys)(r[r.length-1],n)>0});r===-1&&(this.currentPartition.styles.length>=this.maxRulesPerPartition&&this.createNewPartition(),r=this.partitions.length-1);let i=this.partitions[r];try{return this.insertSorted(i,e,n),this.setRuleCache(e,r),!0}catch(n){return(0,t.isDebug)()&&console.warn(`[StylePartitionManager] Failed to insert rule: ${e}`,n),!1}}addCategoryRule(e,n){if(this.hasCategoryRule(e,n))return!1;let r=this.getCategoryPartition(n);r||=this.createNewCategoryPartition(n);try{this.insertSorted(r,e,(0,t.ruleSortKey)(e))}catch(r){return(0,t.isDebug)()&&console.warn(`[StylePartitionManager] Failed to insert rule in category: ${n} ${e}`,r),!1}return this.setCategoryRuleCache(e,n),!0}addRootRules(e){let n=this.getCategoryPartition(`root`);n||=this.createNewCategoryPartition(`root`);try{let t=n.styleElement.sheet;for(let r of e)t?t.insertRule(this.escapeCssRule(r),t.cssRules.length):n.styleElement.textContent+=r+`
3
+ `),i.splice(a,0,r)}constructor(e,n=50,r=`barocss-style-partition-`,i=e=>(0,t.parseClassName)(e).utility?.category,a=``){this.partitions=[],this.categoryPartitions=new Map,this.partitionCounter=0,this.maxRulesPerPartition=50,this.classToPartitionMap=new Map,this.classToCategoryPartitionMap=new Map,this.styleIdPrefix=`barocss-style-partition-`,this.nonce=a,this.insertionPoint=e,this.maxRulesPerPartition=n,this.styleIdPrefix=r,this.getCategory=i,this.initializeDefaultPartition()}createStyleElement(){let e=document.createElement(`style`);return this.nonce&&e.setAttribute(`nonce`,this.nonce),e}initializeDefaultPartition(){this.createNewPartition()}createNewCategoryPartition(e,t=!1){let n={id:this.styleIdPrefix+`-${e}`,styles:[],styleElement:this.createStyleElement()};n.styleElement.id=n.id,n.styleElement.setAttribute(`data-barocss`,`partition`),n.styleElement.setAttribute(`data-category`,e);let r=this.insertionPoint.ownerDocument?.head;return t&&r?r.insertBefore(n.styleElement,r.firstChild):this.insertionPoint.appendChild(n.styleElement),this.categoryPartitions.set(e,n),n}createNewPartition(){let e=this.partitions[this.partitions.length-1],t={id:this.styleIdPrefix+`-${this.partitionCounter++}`,styles:[],styleElement:this.createStyleElement()};this.partitions.push(t),t.styleElement.id=t.id,t.styleElement.setAttribute(`data-barocss`,`partition`),t.styleElement.setAttribute(`data-partition-index`,this.partitionCounter.toString());let n=e?.styleElement.parentNode;return n?n.insertBefore(t.styleElement,e.styleElement.nextSibling):this.insertionPoint.appendChild(t.styleElement),t}hasRule(e){return this.classToPartitionMap.has(e)}hasCategoryRule(e,t){return this.classToCategoryPartitionMap.get(e)===t}setRuleCache(e,t){this.classToPartitionMap.set(e,t)}setCategoryRuleCache(e,t){this.classToCategoryPartitionMap.set(e,t)}get currentPartition(){return this.partitions[this.partitions.length-1]}getCategoryPartition(e){return this.categoryPartitions.get(e)}hasDetachedPartitions(){return[...this.partitions,...this.categoryPartitions.values()].some(e=>!e.styleElement.isConnected)}escapeCssRule(e){return e.replace(/\\\//g,`\\/`)}addRule(e){if(this.hasRule(e))return!1;let n=(0,t.ruleSortKey)(e),r=this.partitions.findIndex(e=>{let r=e.keys;return!!r&&r.length>0&&(0,t.compareKeys)(r[r.length-1],n)>0});r===-1&&(this.currentPartition.styles.length>=this.maxRulesPerPartition&&this.createNewPartition(),r=this.partitions.length-1);let i=this.partitions[r];try{return this.insertSorted(i,e,n),this.setRuleCache(e,r),!0}catch(n){return(0,t.isDebug)()&&console.warn(`[StylePartitionManager] Failed to insert rule: ${e}`,n),!1}}addCategoryRule(e,n){if(this.hasCategoryRule(e,n))return!1;let r=this.getCategoryPartition(n);r||=this.createNewCategoryPartition(n);try{this.insertSorted(r,e,(0,t.ruleSortKey)(e))}catch(r){return(0,t.isDebug)()&&console.warn(`[StylePartitionManager] Failed to insert rule in category: ${n} ${e}`,r),!1}return this.setCategoryRuleCache(e,n),!0}addRootRules(e){let n=this.getCategoryPartition(`root`);n||=this.createNewCategoryPartition(`root`);try{let t=n.styleElement.sheet;for(let r of e)t?t.insertRule(this.escapeCssRule(r),t.cssRules.length):n.styleElement.textContent+=r+`
4
4
  `}catch(n){return(0,t.isDebug)()&&console.warn(`[StylePartitionManager] Failed to insert rule in category: root ${e.join(`
5
5
  `)}`,n),{success:0,failed:e.length}}return{success:e.length,failed:0}}addRules(e){let t=0,n=0;for(let r of e){let e=this.getCategory(r.cls);if(e)for(let t of r.cssList)this.addCategoryRule(t,e);else for(let e of r.cssList)this.addRule(e)?t++:n++}return{success:t,failed:n}}removeRule(e,t){let n;if(t){if(this.classToCategoryPartitionMap.get(e)!==t)return!1;n=this.categoryPartitions.get(t)}else{let t=this.classToPartitionMap.get(e);n=t===void 0?void 0:this.partitions[t]}if(!n)return!1;let r=n.styles.indexOf(e);if(r===-1)return!1;let i=n.styleElement.sheet,a=!!i&&i.cssRules.length===n.styles.length;return n.styles.splice(r,1),n.keys?.splice(r,1),a&&i?i.deleteRule(r):n.styleElement.textContent=n.styles.length?n.styles.join(`
6
6
  `)+`
7
7
  `:``,t?this.classToCategoryPartitionMap.delete(e):this.classToPartitionMap.delete(e),!0}get ruleCount(){return this.classToPartitionMap.size+this.classToCategoryPartitionMap.size}findRulePartition(e){let t=this.classToPartitionMap.get(e);if(t!==void 0&&this.partitions[t])return this.partitions[t];let n=this.classToCategoryPartitionMap.get(e);return n===void 0?null:this.categoryPartitions.get(n)||null}updateRuleContent(e,n,r=!1){let i=this.getCategoryPartition(e);if(i)i.styleElement.textContent=n;else{let i=this.createNewCategoryPartition(e,r);(0,t.isDebug)()&&console.log(`[StylePartitionManager] Created new partition for category: ${e}`),i.styleElement.textContent=n}}cleanup(){this.partitions.forEach(e=>{e.styleElement.parentNode&&e.styleElement.parentNode.removeChild(e.styleElement)}),this.categoryPartitions.forEach(e=>{e.styleElement.parentNode&&e.styleElement.parentNode.removeChild(e.styleElement)}),this.partitions=[],this.categoryPartitions.clear(),this.partitionCounter=0,this.classToPartitionMap.clear(),this.classToCategoryPartitionMap.clear()}},r=/[ \t\n\f\r]+/;function i(e){return e?typeof e==`object`&&typeof e.baseVal==`string`?e.baseVal:e.toString():``}function a(e){return e?i(e).split(r).filter(Boolean):[]}var o=class{constructor(e,n,r=e=>(0,t.parseClassName)(e).utility?.category){this.observer=null,this.gc=null,this.incrementalParser=e,this.BrowserRuntime=n,this.getCategory=r}setGc(e){this.gc=e}setParser(e){this.incrementalParser=e}observe(e=document.body,t){return typeof window>`u`?new MutationObserver(()=>{}):(this.observer&&this.observer.disconnect(),this.gc?.setRoot(e),this.observer=new MutationObserver(t=>{let n=new Set,r=this.gc;if(t.forEach(t=>{if(r&&(t.type===`attributes`?r.reconcile(t.target):t.type===`childList`&&(t.removedNodes.forEach(e=>r.reconcileTree(e)),t.addedNodes.forEach(e=>r.reconcileTree(e)))),t.type===`attributes`&&t.attributeName===`class`&&e.contains(t.target)){let e=t.target;e.className&&a(e.className).forEach(e=>{this.incrementalParser.isProcessed(e)||n.add(e)})}t.type===`childList`&&t.addedNodes.forEach(t=>{if(t.nodeType===Node.ELEMENT_NODE&&e.contains(t)){let e=t;this.processElement(e,n),e.querySelectorAll(`[class]`).forEach(e=>{this.processElement(e,n)})}})}),n.size>0){let e=Array.from(n),t=this.incrementalParser.processClasses(e);this.BrowserRuntime?.applyParseResults(t)}else this.BrowserRuntime?.applyParseResults([]);r?.afterBatch()}),this.observer.observe(e,{attributes:!0,subtree:!0,attributeFilter:[`class`],childList:!0}),t?.scan&&this.scanExistingClasses(e,t),this.observer)}scanExistingClasses(e,t){let n=new Set,r=e.className;r&&a(r).forEach(e=>{this.incrementalParser.isProcessed(e)||n.add(e)});let i=e.querySelectorAll(`[class]`);for(let e of i)if(e.className){let t=a(e.className);for(let e of t)this.incrementalParser.isProcessed(e)||n.add(e)}if(n.size>0){let e=Array.from(n),r=this.incrementalParser.processClasses(e),i=r.filter(e=>this.getCategory(e.cls)===`layout`),a=r.filter(e=>this.getCategory(e.cls)!==`layout`);this.BrowserRuntime?.applyParseResults(i),t?.onReady?.(),this.BrowserRuntime?.applyParseResults(a)}else t?.onReady?.()}processElement(e,t){e.className&&a(e.className).forEach(e=>{this.incrementalParser.isProcessed(e)||t.add(e)})}disconnect(){this.observer&&=(this.observer.disconnect(),null)}};function s(e){return e.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g,(e,t,n)=>t?String.fromCodePoint(parseInt(t,16)):n)}var c=/^\s*(?::(?:where|is)\(\s*)?\.((?:\\[0-9a-fA-F]{1,6}\s?|\\.|[\w-]|[^\x00-\x7F])+)/;function l(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}function u(e,t=new Set){for(let n of Array.from(e)){if(n.type===7&&typeof n.name==`string`){t.add(n.name);continue}let e=n.cssRules;e&&e.length&&u(e,t)}return t}function d(e,t=new Set){for(let n of Array.from(e)){let e=n.selectorText;if(typeof e==`string`)for(let n of l(e)){let e=c.exec(n);e&&t.add(s(e[1]))}let r=n.cssRules;r&&r.length&&d(r,t)}return t}var f=class{constructor(e,t,n,r=()=>Date.now()){this.host=e,this.graceMs=t,this.maxRules=n,this.now=r,this.counts=new Map,this.counted=new WeakMap,this.candidates=new Map,this.timer=null,this.root=null}setRoot(e){this.counts.clear(),this.counted=new WeakMap,this.candidates.clear(),this.cancel(),this.root=e,e.nodeType===1?this.reconcileTree(e):e.querySelectorAll(`[class]`).forEach(e=>this.reconcile(e))}count(e){return this.counts.get(e)??0}reconcileTree(e){if(e.nodeType!==1)return;let t=e;this.reconcile(t),t.querySelectorAll(`[class]`).forEach(e=>this.reconcile(e))}reconcile(e){let t=this.root,n=t&&t.contains(e)?Array.from(new Set(a(e.getAttribute(`class`)))):[],r=this.counted.get(e);if(!r&&n.length===0)return;let i=new Set(r??[]),o=new Set(n);for(let e of o){if(i.has(e))continue;let t=(this.counts.get(e)??0)+1;this.counts.set(e,t),this.candidates.delete(e)}for(let e of i){if(o.has(e))continue;let t=(this.counts.get(e)??0)-1;t>0?this.counts.set(e,t):(this.counts.delete(e),this.candidates.delete(e),this.candidates.set(e,this.now()))}n.length?this.counted.set(e,n):this.counted.delete(e)}afterBatch(){this.candidates.size!==0&&(this.host.cachedCount()>this.maxRules?this.schedule(0):this.schedule(this.graceMs))}schedule(e){if(this.timer!==null){if(e>0)return;clearTimeout(this.timer)}this.timer=setTimeout(()=>{this.timer=null,this.sweep()},e)}sweep(){let e=this.now(),t=Math.max(0,this.host.cachedCount()-this.maxRules),n=[],r=0;for(let[i,a]of this.candidates){let o=e-a>=this.graceMs;!o&&r>=t||(this.candidates.delete(i),!(this.count(i)>0||this.inDom(i)||this.host.isPermanent(i))&&(n.push(i),o||r++))}n.length&&this.host.reclaim(n),this.candidates.size&&this.schedule(this.graceMs)}inDom(e){let t=this.root;if(!t)return!1;if(t.nodeType!==1)return Array.from(t.querySelectorAll(`[class]`)).some(t=>t.classList.contains(e));let n=t.ownerDocument??document;return t.classList.contains(e)||n.documentElement.classList.contains(e)||n.getElementsByClassName(e).length>0}cancel(){this.timer!==null&&clearTimeout(this.timer),this.timer=null}stats(){return{trackedClasses:this.counts.size,candidates:this.candidates.size}}};function p(e){let t=[],n=e.replace(/\/\*[\s\S]*?\*\//g,``);return n=n.replace(/(?<=^|[{};])(\s*)([^{};@\s][^{};]*?)\{([^{}]*)\}/g,(e,n,r,i)=>{let a=r.split(`,`).map(e=>e.trim()).filter(Boolean);if(a.includes(`body`))for(let e of i.split(`;`).map(e=>e.trim()).filter(Boolean))/^(min-height|scroll-behavior)\s*:/.test(e)||t.push(e);let o=Array.from(new Set(a.filter(e=>e!==`body`).map(e=>e===`html`||e===`:root`?`:host`:e)));return o.length===0?``:`${n}${o.join(`, `)} {${i}}`}),t.length&&(n+=`\n@layer base {\n:host {\n ${t.join(`;
8
- `)};\n}\n}\n`),n}function m(e){return JSON.stringify(e,(e,t)=>typeof t==`function`?`fn:${String(t)}`:t instanceof RegExp?`re:${t}`:t)??``}function h(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function g(e=`shadow`){try{let t=e===`document`?typeof Document<`u`?Document.prototype:void 0:typeof ShadowRoot<`u`?ShadowRoot.prototype:void 0;return!!t&&`adoptedStyleSheets`in t&&typeof CSSStyleSheet==`function`&&typeof new CSSStyleSheet().replaceSync==`function`}catch{return!1}}var _=e=>e.replace(/\\\//g,`\\/`),v=class{constructor(e,n,r=e,i={}){this.results=new Map,this.generations=0,this.prologueSheet=null,this.rulesSheet=null,this.prologue={preflight:``,vars:``},this.segments=new Map([[`root`,{rules:[],keys:[]}],[``,{rules:[],keys:[]}]]),this.refs=new Map,this.attached=[],this.key=e,this.fullKey=r,this.context=i.context??(0,t.createContext)(n),this.constructable=g(i.target??`shadow`),this.constructable&&(this.prologueSheet=new CSSStyleSheet,this.rulesSheet=new CSSStyleSheet)}get rootCount(){return this.attached.length}get ruleCount(){return this.refs.size}attach(e,t=``){if(this.attached.some(t=>t.root===e))return;if(this.prologueSheet&&this.rulesSheet){let t=[this.prologueSheet,this.rulesSheet];e.adoptedStyleSheets=[...e.adoptedStyleSheets.filter(e=>!t.includes(e)),...t],this.attached.push({root:e});return}if(e.nodeType!==11)throw Error(`[BrowserRuntime] constructable sheets are not supported for the document`);let n=e.ownerDocument??document,r=n.createElement(`style`),i=n.createElement(`style`);t&&(r.setAttribute(`nonce`,t),i.setAttribute(`nonce`,t)),r.setAttribute(`data-barocss`,`root-prologue`),i.setAttribute(`data-barocss`,`root`),r.textContent=this.prologueText(),i.textContent=this.allRules().join(`
9
- `),e.insertBefore(i,e.firstChild),e.insertBefore(r,i),this.attached.push({root:e,styles:[r,i]})}detach(e){let t=this.attached.findIndex(t=>t.root===e);if(t===-1)return;let[n]=this.attached.splice(t,1);n.styles?n.styles.forEach(e=>e.remove()):e.adoptedStyleSheets&&=e.adoptedStyleSheets.filter(e=>e!==this.prologueSheet&&e!==this.rulesSheet)}setPrologue(e,t){if(this.prologue[e]===t)return;this.prologue[e]=t;let n=this.prologueText();this.prologueSheet&&this.prologueSheet.replaceSync(n);for(let e of this.attached)e.styles&&(e.styles[0].textContent=n)}prologueText(){return[this.prologue.preflight,this.prologue.vars].filter(Boolean).join(`
8
+ `)};\n}\n}\n`),n}function m(e){return JSON.stringify(e,(e,t)=>typeof t==`function`?`fn:${String(t)}`:t instanceof RegExp?`re:${t}`:t)??``}function h(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function g(e=`shadow`){try{let t=e===`document`?typeof Document<`u`?Document.prototype:void 0:typeof ShadowRoot<`u`?ShadowRoot.prototype:void 0;return!!t&&`adoptedStyleSheets`in t&&typeof CSSStyleSheet==`function`&&typeof new CSSStyleSheet().replaceSync==`function`}catch{return!1}}var _=e=>e.replace(/\\\//g,`\\/`),v=/^\s*@property\s/,y=null;function b(e,n,r={}){let i=n.filter(e=>v.test(e));if(i.length===0)return!0;try{if(!e)return!1;if(!y||y.doc!==e||y.style&&!y.style.isConnected){let t={doc:e,rules:new Set};if(r.constructable&&g(`document`))t.sheet=new CSSStyleSheet,e.adoptedStyleSheets=[...e.adoptedStyleSheets,t.sheet];else{let n=e.head??e.documentElement;if(!n)return!1;let i=e.createElement(`style`);i.setAttribute(`data-barocss`,`document-properties`),r.nonce&&i.setAttribute(`nonce`,r.nonce),n.appendChild(i),t.style=i}y=t}let t=y;for(let e of i){if(t.rules.has(e))continue;let n=t.sheet??t.style?.sheet??null;n?n.insertRule(_(e),n.cssRules.length):t.style&&(t.style.textContent+=`${e}\n`),t.rules.add(e)}return!0}catch(e){return(0,t.isDebug)()&&console.warn(`[BrowserRuntime] could not register @property rules in the document; using :host initial values`,e),!1}}function x(e){let t=[];for(let n of e){let e=/^\s*@property\s+(--[\w-]+)/.exec(n)?.[1],r=/initial-value\s*:\s*([^;}]*)/.exec(n)?.[1]?.trim();e&&r&&t.push(`${e}: ${r}`)}return t.length===0?``:`@layer properties {\n:host, *, ::before, ::after, ::backdrop {\n ${t.join(`;
9
+ `)};\n}\n}`}var S=class{constructor(e,n,r=e,i={}){this.results=new Map,this.generations=0,this.prologueSheet=null,this.rulesSheet=null,this.prologue={props:``,preflight:``,vars:``},this.fallbackProps=new Set,this.segments=new Map([[`root`,{rules:[],keys:[]}],[``,{rules:[],keys:[]}]]),this.refs=new Map,this.attached=[],this.key=e,this.fullKey=r,this.context=i.context??(0,t.createContext)(n),this.constructable=g(i.target??`shadow`),this.constructable&&(this.prologueSheet=new CSSStyleSheet,this.rulesSheet=new CSSStyleSheet)}get rootCount(){return this.attached.length}get ruleCount(){return this.refs.size}attach(e,t=``){if(this.attached.some(t=>t.root===e))return;if(this.prologueSheet&&this.rulesSheet){let t=[this.prologueSheet,this.rulesSheet];e.adoptedStyleSheets=[...e.adoptedStyleSheets.filter(e=>!t.includes(e)),...t],this.attached.push({root:e});return}if(e.nodeType!==11)throw Error(`[BrowserRuntime] constructable sheets are not supported for the document`);let n=e.ownerDocument??document,r=n.createElement(`style`),i=n.createElement(`style`);t&&(r.setAttribute(`nonce`,t),i.setAttribute(`nonce`,t)),r.setAttribute(`data-barocss`,`root-prologue`),i.setAttribute(`data-barocss`,`root`),r.textContent=this.prologueText(),i.textContent=this.allRules().join(`
10
+ `),e.insertBefore(i,e.firstChild),e.insertBefore(r,i),this.attached.push({root:e,styles:[r,i]})}detach(e){let t=this.attached.findIndex(t=>t.root===e);if(t===-1)return;let[n]=this.attached.splice(t,1);n.styles?n.styles.forEach(e=>e.remove()):e.adoptedStyleSheets&&=e.adoptedStyleSheets.filter(e=>e!==this.prologueSheet&&e!==this.rulesSheet)}addPropertyFallback(e){let t=this.fallbackProps.size;for(let t of e)v.test(t)&&this.fallbackProps.add(t);this.fallbackProps.size!==t&&this.setPrologue(`props`,x(Array.from(this.fallbackProps)))}setPrologue(e,t){if(this.prologue[e]===t)return;this.prologue[e]=t;let n=this.prologueText();this.prologueSheet&&this.prologueSheet.replaceSync(n);for(let e of this.attached)e.styles&&(e.styles[0].textContent=n)}prologueText(){return[this.prologue.props,this.prologue.preflight,this.prologue.vars].filter(Boolean).join(`
10
11
  `)}allRules(){return Array.from(this.segments.values()).flatMap(e=>e.rules)}offset(e){let t=0;for(let n of this.segments.values()){if(n===e)return t;t+=n.rules.length}return t}retain(e,n){let r=this.refs.get(e);if(r!==void 0)return this.refs.set(e,r+1),!0;let i=this.segments.get(n);i||(i={rules:[],keys:[]},this.segments.set(n,i));let a=n===`root`,o=(0,t.ruleSortKey)(e),s=a?i.rules.length:(0,t.upperBound)(i.keys,o),c=this.offset(i)+s;try{this.insertAt(e,c)}catch(n){return(0,t.isDebug)()&&console.warn(`[BrowserRuntime] Failed to insert rule into shadow root sheet: ${e}`,n),!1}return i.rules.splice(s,0,e),i.keys.splice(s,0,o),this.refs.set(e,1),!0}release(e){let t=this.refs.get(e);if(t!==void 0){if(t>1){this.refs.set(e,t-1);return}this.refs.delete(e);for(let t of this.segments.values()){let n=t.rules.indexOf(e);if(n===-1)continue;let r=this.offset(t)+n;t.rules.splice(n,1),t.keys.splice(n,1),this.deleteAt(r);return}}}insertAt(e,t){let n=_(e);if(this.rulesSheet){this.rulesSheet.insertRule(n,t);return}let r=this.allRules().length;for(let i of this.attached){let a=i.styles[1],o=a.sheet;if(o&&o.cssRules.length===r)o.insertRule(n,t);else{let n=this.allRules();n.splice(t,0,e),a.textContent=n.join(`
11
12
  `)}}}deleteAt(e){if(this.rulesSheet){this.rulesSheet.deleteRule(e);return}let t=this.allRules().length;for(let n of this.attached){let r=n.styles[1],i=r.sheet;i&&i.cssRules.length===t+1?i.deleteRule(e):r.textContent=this.allRules().join(`
12
13
  `)}}cssText(){return[this.prologueText(),...this.allRules()].join(`
13
- `)}},y=new Map;function b(e,t=h){let n=m(e),r=y.get(n);return r||(r=new v(t(n),e,n),y.set(n,r)),r}function x(e){e.rootCount===0&&y.get(e.fullKey)===e&&y.delete(e.fullKey)}var S=class extends t.IncrementalParser{constructor(e){super(e.context),this.shared=e}processClass(e){if(this.isProcessed(e))return null;let t=this.shared.results.get(e);if(t)return this.markProcessed(e),t;let n=super.processClass(e);return n&&(this.shared.results.set(e,n),this.shared.generations++),n}},C=class{constructor(e,n,r=e=>(0,t.parseClassName)(e).utility?.category,i={}){this.shared=e,this.root=n,this.getCategory=r,this.owned=new Set,this.scopePreflight=n.nodeType===11,e.attach(n,i.nonce)}hasDetachedPartitions(){return!1}updateRuleContent(e,t){e===`preflight`?this.shared.setPrologue(`preflight`,this.scopePreflight?p(t):t):e===`css-vars`&&this.shared.setPrologue(`vars`,t)}take(e,t){return this.owned.has(e)||!this.shared.retain(e,t)?!1:(this.owned.add(e),!0)}addRule(e){return this.take(e,``)}addCategoryRule(e,t){return this.take(e,`c:${t}`)}addRootRules(e){let t=0;for(let n of e)this.take(n,`root`)&&t++;return{success:t,failed:e.length-t}}addRules(e){let t=0,n=0;for(let r of e){let e=this.getCategory(r.cls);for(let i of r.cssList)(e?this.addCategoryRule(i,e):this.addRule(i))?t++:n++}return{success:t,failed:n}}removeRule(e,t){return this.owned.delete(e)?(this.shared.release(e),!0):!1}get ruleCount(){return this.owned.size}cleanup(){this.owned.forEach(e=>this.shared.release(e)),this.owned.clear(),this.shared.detach(this.root),x(this.shared)}},w=`style[data-barocss-ssr]`,T=`@layer theme, base, components, utilities;`,E=class{constructor(e={}){this.cache=new Map,this.rootCache=new Set,this.shadowRoot=null,this.isDestroyed=!1,this.existing=null,this.existingKeyframes=new Set,this.existingSheetCount=-1,this.pinned=new Set,this.gc=null,this.reclaimedCount=0,this.ssrRules=[],this.ssrClasses=new Set,this.observedOnce=!1,this.getCategory=e=>(0,t.parseClassName)(e,this.context).utility?.category;let n={};this.options={config:e.config||n,styleId:e.styleId||`barocss-runtime`,insertionPoint:e.insertionPoint||`head`,maxRulesPerPartition:e.maxRulesPerPartition||50,skipExisting:e.skipExisting??!1,gc:e.gc??!0,gcGraceMs:e.gcGraceMs??3e3,maxRules:e.maxRules??1/0,nonce:e.nonce??``,constructable:e.constructable??!1};let r=e.root;if(r&&r.nodeType===11&&(this.shadowRoot=r),this.shadowRoot){let e=b(this.options.config);this.context=e.context,this.incrementalParser=new S(e)}else this.context=(0,t.createContext)(this.options.config),this.incrementalParser=new t.IncrementalParser(this.context);this.changeDetector=new o(this.incrementalParser,this,this.getCategory),this.stylePartitionManager=this.createStyles(),this.options.gc&&(this.gc=new f({reclaim:e=>this.reclaim(e),isPermanent:e=>this.isPermanent(e),cachedCount:()=>this.cache.size},this.options.gcGraceMs,this.options.maxRules),this.changeDetector.setGc(this.gc)),this.init(),this.shadowRoot&&this.observe(this.shadowRoot,{scan:!0})}createStyles(){if(this.shadowRoot){let e=this.incrementalParser.shared,t=b(this.options.config);return t!==e&&(e=t,this.context=e.context,this.incrementalParser=new S(e),this.changeDetector?.setParser(this.incrementalParser)),new C(e,this.shadowRoot,this.getCategory,{nonce:this.options.nonce})}return this.options.constructable&&typeof document<`u`&&g(`document`)?new C(new v(`document`,this.options.config,`document`,{context:this.context,target:`document`}),document,this.getCategory):new n(this.getInsertionPoint(),this.options.maxRulesPerPartition,`${this.options.styleId}-partition`,this.getCategory,this.options.nonce)}debugLog(e,n,r){(0,t.isDebug)()&&(console[e]||console.log)(`[BrowserRuntime:${e.toUpperCase()}] ${n}`,r||``)}init(){this.debugLog(`debug`,`init`),this.injectPreflightCSS(),this.ensureCssVars(),this.adoptSsrSheets()}adoptSsrSheets(){if(typeof document>`u`||this.shadowRoot)return;let e=[];if(document.head){for(let t of Array.from(document.head.querySelectorAll(`${w}:not([data-barocss-adopted])`))){let n=t.sheet;if(!n)continue;t.setAttribute(`data-barocss-adopted`,``);let r=[];for(let e=n.cssRules.length-1;e>=0;e--){let t=n.cssRules[e],i=d([t]);i.size!==0&&(i.forEach(e=>this.ssrClasses.add(e)),r.unshift({css:t.cssText,cls:i.values().next().value}),n.deleteRule(e))}e.push(...r)}e.length!==0&&(this.ssrRules.push(...e),this.insertSsrRules(e))}}insertSsrRules(e){for(let{css:t,cls:n}of e){let e=this.getCategory(n);e?this.stylePartitionManager.addCategoryRule(t,e):this.stylePartitionManager.addRule(t)}}injectPreflightCSS(){let e=this.options.config.preflight??!0;if(e){let t=this.context.getPreflightCSS(e);this.stylePartitionManager.updateRuleContent(`preflight`,`${T}\n@layer base {\n${t}\n}`,!0)}}ensureCssVars(){if(this.isDestroyed)return;let e=this.context.themeToCssVars?this.context.themeToCssVars():`:root { /* CSS Variables will be generated here */ }`;this.stylePartitionManager.updateRuleContent(`css-vars`,e)}getInsertionPoint(){if(typeof this.options.insertionPoint!=`string`)return this.options.insertionPoint;switch(this.options.insertionPoint){case`body`:return document.body||document.head;default:return document.head}}addClass(e){if(this.isDestroyed)return;let t=this.normalizeClasses(e).filter(Boolean);t.forEach(e=>this.pinned.add(e)),this.processClasses(t)}processClasses(e){this.processClassesIncremental(e)}processClassesIncremental(e){let t=typeof window<`u`,n=this.incrementalParser.processClasses(e);this.debugLog(`debug`,`results`,{results:n,classList:e}),this.applyParseResults(n,{isBrowser:t})}applyParseResults(e,t){if(this.isDestroyed)return;if(!this.shadowRoot&&this.getInsertionPoint().isConnected&&this.stylePartitionManager.hasDetachedPartitions()){let t=Array.from(this.cache.values());this.reset(),e=[...t,...e],e.forEach(e=>this.incrementalParser.markProcessed(e.cls))}if(this.ssrClasses.size>0&&(e=e.filter(e=>!this.ssrClasses.has(e.cls))),this.options.skipExisting&&e.length>0&&typeof document<`u`){let t=this.getExistingClasses();e=e.filter(e=>!t.has(e.cls))}if(e.length===0)return;let n=[],r=[],i=this.options.skipExisting&&typeof document<`u`?(this.getExistingClasses(),this.existingKeyframes):null;for(let t of e)if(t.css&&Array.isArray(t.cssList)&&(n.push(t),this.cache.set(t.cls,t)),t.rootCss&&Array.isArray(t.rootCssList))for(let e of t.rootCssList){if(i?.size){let t=/^\s*@keyframes\s+([^\s{]+)/.exec(e)?.[1];if(t&&i.has(t))continue}this.rootCache.has(e)||(this.rootCache.add(e),r.push(e))}r.length>0&&this.stylePartitionManager.addRootRules(r.filter(Boolean)),n.length>0&&this.stylePartitionManager.addRules(n),this.debugLog(`info`,`Applied ${e.length} parser results`,{cssRuleCount:n.length,rootCssCount:r.length})}isPermanent(e){return this.pinned.has(e)||this.ssrClasses.has(e)?!0:this.shadowRoot?!1:typeof document>`u`||this.getExistingClasses().has(e)}reclaim(e){if(this.isDestroyed)return;let t=e.filter(e=>this.cache.has(e));if(t.length===0)return;let n=t.map(e=>this.cache.get(e));t.forEach(e=>{this.cache.delete(e),this.incrementalParser.unmarkProcessed(e)});let r=new Set;for(let e of this.cache.values())e.cssList.forEach(e=>r.add(e));for(let e of n){let t=this.getCategory(e.cls);for(let n of e.cssList)r.has(n)||this.stylePartitionManager.removeRule(n,t)}this.reclaimedCount+=t.length}getExistingClasses(){let e=new Set(Array.from(document.querySelectorAll(`style[data-barocss]`),e=>e.sheet)),t=Array.from(document.styleSheets).filter(t=>{if(e.has(t))return!1;let n=t.ownerNode;return!(n&&typeof n.hasAttribute==`function`&&(n.hasAttribute(`data-barocss`)||(n.id||``).startsWith(this.options.styleId)))});if(this.existing&&t.length===this.existingSheetCount)return this.existing;let n=new Set,r=new Set;for(let e of t){let t;try{t=e.cssRules}catch{continue}d(t,n),u(t,r)}return this.existingKeyframes=r,this.existing=n,this.existingSheetCount=t.length,n}observe(e=this.shadowRoot??document.body,t){return this.observedOnce||(this.observedOnce=!0,this.adoptSsrSheets()),this.changeDetector.observe(e,t)}normalizeClasses(e){return(Array.isArray(e)?e:[e]).flatMap(a)}has(e){return this.cache.has(e)}getCss(e){return this.cache.get(e)?.cssList.join(`
14
+ `)}},C=new Map;function w(e,t=h){let n=m(e),r=C.get(n);return r||(r=new S(t(n),e,n),C.set(n,r)),r}function T(e){e.rootCount===0&&C.get(e.fullKey)===e&&C.delete(e.fullKey)}var E=class extends t.IncrementalParser{constructor(e){super(e.context),this.shared=e}processClass(e){if(this.isProcessed(e))return null;let t=this.shared.results.get(e);if(t)return this.markProcessed(e),t;let n=super.processClass(e);return n&&(this.shared.results.set(e,n),this.shared.generations++),n}},D=class{constructor(e,n,r=e=>(0,t.parseClassName)(e).utility?.category,i={}){this.shared=e,this.root=n,this.getCategory=r,this.opts=i,this.owned=new Set,this.scopePreflight=n.nodeType===11,e.attach(n,i.nonce)}hasDetachedPartitions(){return!1}updateRuleContent(e,t){e===`preflight`?this.shared.setPrologue(`preflight`,this.scopePreflight?p(t):t):e===`css-vars`&&this.shared.setPrologue(`vars`,t)}take(e,t){return this.owned.has(e)||(this.root.nodeType===11&&v.test(e)&&(b(this.root.ownerDocument??(typeof document<`u`?document:null),[e],this.opts)||this.shared.addPropertyFallback([e])),!this.shared.retain(e,t))?!1:(this.owned.add(e),!0)}addRule(e){return this.take(e,``)}addCategoryRule(e,t){return this.take(e,`c:${t}`)}addRootRules(e){let t=0;for(let n of e)this.take(n,`root`)&&t++;return{success:t,failed:e.length-t}}addRules(e){let t=0,n=0;for(let r of e){let e=this.getCategory(r.cls);for(let i of r.cssList)(e?this.addCategoryRule(i,e):this.addRule(i))?t++:n++}return{success:t,failed:n}}removeRule(e,t){return this.owned.delete(e)?(this.shared.release(e),!0):!1}get ruleCount(){return this.owned.size}cleanup(){this.owned.forEach(e=>this.shared.release(e)),this.owned.clear(),this.shared.detach(this.root),T(this.shared)}},O=`style[data-barocss-ssr]`,k=`@layer theme, base, components, utilities;`,A=class{constructor(e={}){this.cache=new Map,this.rootCache=new Set,this.shadowRoot=null,this.isDestroyed=!1,this.existing=null,this.existingKeyframes=new Set,this.existingSheetCount=-1,this.pinned=new Set,this.gc=null,this.reclaimedCount=0,this.ssrRules=[],this.ssrClasses=new Set,this.observedOnce=!1,this.getCategory=e=>(0,t.parseClassName)(e,this.context).utility?.category;let n={};this.options={config:e.config||n,styleId:e.styleId||`barocss-runtime`,insertionPoint:e.insertionPoint||`head`,maxRulesPerPartition:e.maxRulesPerPartition||50,skipExisting:e.skipExisting??!1,gc:e.gc??!0,gcGraceMs:e.gcGraceMs??3e3,maxRules:e.maxRules??1/0,nonce:e.nonce??``,constructable:e.constructable??!1};let r=e.root;if(r&&r.nodeType===11&&(this.shadowRoot=r),this.shadowRoot){let e=w(this.options.config);this.context=e.context,this.incrementalParser=new E(e)}else this.context=(0,t.createContext)(this.options.config),this.incrementalParser=new t.IncrementalParser(this.context);this.changeDetector=new o(this.incrementalParser,this,this.getCategory),this.stylePartitionManager=this.createStyles(),this.options.gc&&(this.gc=new f({reclaim:e=>this.reclaim(e),isPermanent:e=>this.isPermanent(e),cachedCount:()=>this.cache.size},this.options.gcGraceMs,this.options.maxRules),this.changeDetector.setGc(this.gc)),this.init(),this.shadowRoot&&this.observe(this.shadowRoot,{scan:!0})}createStyles(){if(this.shadowRoot){let e=this.incrementalParser.shared,t=w(this.options.config);return t!==e&&(e=t,this.context=e.context,this.incrementalParser=new E(e),this.changeDetector?.setParser(this.incrementalParser)),new D(e,this.shadowRoot,this.getCategory,{nonce:this.options.nonce,constructable:this.options.constructable})}return this.options.constructable&&typeof document<`u`&&g(`document`)?new D(new S(`document`,this.options.config,`document`,{context:this.context,target:`document`}),document,this.getCategory):new n(this.getInsertionPoint(),this.options.maxRulesPerPartition,`${this.options.styleId}-partition`,this.getCategory,this.options.nonce)}debugLog(e,n,r){(0,t.isDebug)()&&(console[e]||console.log)(`[BrowserRuntime:${e.toUpperCase()}] ${n}`,r||``)}init(){this.debugLog(`debug`,`init`),this.injectPreflightCSS(),this.ensureCssVars(),this.adoptSsrSheets()}adoptSsrSheets(){if(typeof document>`u`||this.shadowRoot)return;let e=[];if(document.head){for(let t of Array.from(document.head.querySelectorAll(`${O}:not([data-barocss-adopted])`))){let n=t.sheet;if(!n)continue;t.setAttribute(`data-barocss-adopted`,``);let r=[];for(let e=n.cssRules.length-1;e>=0;e--){let t=n.cssRules[e],i=d([t]);i.size!==0&&(i.forEach(e=>this.ssrClasses.add(e)),r.unshift({css:t.cssText,cls:i.values().next().value}),n.deleteRule(e))}e.push(...r)}e.length!==0&&(this.ssrRules.push(...e),this.insertSsrRules(e))}}insertSsrRules(e){for(let{css:t,cls:n}of e){let e=this.getCategory(n);e?this.stylePartitionManager.addCategoryRule(t,e):this.stylePartitionManager.addRule(t)}}injectPreflightCSS(){let e=this.options.config.preflight??!0;if(e){let t=this.context.getPreflightCSS(e);this.stylePartitionManager.updateRuleContent(`preflight`,`${k}\n@layer base {\n${t}\n}`,!0)}}ensureCssVars(){if(this.isDestroyed)return;let e=this.context.themeToCssVars?this.context.themeToCssVars():`:root { /* CSS Variables will be generated here */ }`;this.stylePartitionManager.updateRuleContent(`css-vars`,e)}getInsertionPoint(){if(typeof this.options.insertionPoint!=`string`)return this.options.insertionPoint;switch(this.options.insertionPoint){case`body`:return document.body||document.head;default:return document.head}}addClass(e){if(this.isDestroyed)return;let t=this.normalizeClasses(e).filter(Boolean);t.forEach(e=>this.pinned.add(e)),this.processClasses(t)}processClasses(e){this.processClassesIncremental(e)}processClassesIncremental(e){let t=typeof window<`u`,n=this.incrementalParser.processClasses(e);this.debugLog(`debug`,`results`,{results:n,classList:e}),this.applyParseResults(n,{isBrowser:t})}applyParseResults(e,t){if(this.isDestroyed)return;if(!this.shadowRoot&&this.getInsertionPoint().isConnected&&this.stylePartitionManager.hasDetachedPartitions()){let t=Array.from(this.cache.values());this.reset(),e=[...t,...e],e.forEach(e=>this.incrementalParser.markProcessed(e.cls))}if(this.ssrClasses.size>0&&(e=e.filter(e=>!this.ssrClasses.has(e.cls))),this.options.skipExisting&&e.length>0&&typeof document<`u`){let t=this.getExistingClasses();e=e.filter(e=>!t.has(e.cls))}if(e.length===0)return;let n=[],r=[],i=this.options.skipExisting&&typeof document<`u`?(this.getExistingClasses(),this.existingKeyframes):null;for(let t of e)if(t.css&&Array.isArray(t.cssList)&&(n.push(t),this.cache.set(t.cls,t)),t.rootCss&&Array.isArray(t.rootCssList))for(let e of t.rootCssList){if(i?.size){let t=/^\s*@keyframes\s+([^\s{]+)/.exec(e)?.[1];if(t&&i.has(t))continue}this.rootCache.has(e)||(this.rootCache.add(e),r.push(e))}r.length>0&&this.stylePartitionManager.addRootRules(r.filter(Boolean)),n.length>0&&this.stylePartitionManager.addRules(n),this.debugLog(`info`,`Applied ${e.length} parser results`,{cssRuleCount:n.length,rootCssCount:r.length})}isPermanent(e){return this.pinned.has(e)||this.ssrClasses.has(e)?!0:this.shadowRoot?!1:typeof document>`u`||this.getExistingClasses().has(e)}reclaim(e){if(this.isDestroyed)return;let t=e.filter(e=>this.cache.has(e));if(t.length===0)return;let n=t.map(e=>this.cache.get(e));t.forEach(e=>{this.cache.delete(e),this.incrementalParser.unmarkProcessed(e)});let r=new Set;for(let e of this.cache.values())e.cssList.forEach(e=>r.add(e));for(let e of n){let t=this.getCategory(e.cls);for(let n of e.cssList)r.has(n)||this.stylePartitionManager.removeRule(n,t)}this.reclaimedCount+=t.length}getExistingClasses(){let e=new Set(Array.from(document.querySelectorAll(`style[data-barocss]`),e=>e.sheet)),t=Array.from(document.styleSheets).filter(t=>{if(e.has(t))return!1;let n=t.ownerNode;return!(n&&typeof n.hasAttribute==`function`&&(n.hasAttribute(`data-barocss`)||(n.id||``).startsWith(this.options.styleId)))});if(this.existing&&t.length===this.existingSheetCount)return this.existing;let n=new Set,r=new Set;for(let e of t){let t;try{t=e.cssRules}catch{continue}d(t,n),u(t,r)}return this.existingKeyframes=r,this.existing=n,this.existingSheetCount=t.length,n}observe(e=this.shadowRoot??document.body,t){return this.observedOnce||(this.observedOnce=!0,this.adoptSsrSheets()),this.changeDetector.observe(e,t)}normalizeClasses(e){return(Array.isArray(e)?e:[e]).flatMap(a)}has(e){return this.cache.has(e)}getCss(e){return this.cache.get(e)?.cssList.join(`
14
15
  `)}getAllCss(){return[...this.rootCache,...Array.from(this.cache.values()).flatMap(e=>e.cssList)].join(`
15
- `)}getClasses(){return Array.from(this.cache.keys())}getCacheStats(){let e=this.incrementalParser.getStats();return{runtime:{cachedClasses:this.cache.size,rootCacheSize:this.rootCache.size,ruleCount:this.stylePartitionManager.ruleCount,reclaimedClasses:this.reclaimedCount,gc:this.gc?.stats()??null},ast:e.cacheStats.ast,incremental:e}}clearCaches(){this.isDestroyed||(this.cache.clear(),this.rootCache.clear(),(0,t.clearAstCache)(this.context),this.incrementalParser.clearProcessed(),this.stylePartitionManager.cleanup(),this.stylePartitionManager=this.createStyles(),this.injectPreflightCSS(),this.ensureCssVars(),this.insertSsrRules(this.ssrRules))}reset(){this.isDestroyed||(this.cache.clear(),this.rootCache.clear(),this.incrementalParser.clearProcessed(),this.stylePartitionManager.cleanup(),this.stylePartitionManager=this.createStyles(),this.injectPreflightCSS(),this.ensureCssVars(),this.insertSsrRules(this.ssrRules))}updateConfig(e){if(this.isDestroyed)return;let n=Array.from(this.cache.keys());if(this.options.config=e,this.shadowRoot){this.stylePartitionManager.cleanup();let t=b(e);this.context=t.context,this.incrementalParser=new S(t)}else this.context=(0,t.createContext)(e),this.incrementalParser=new t.IncrementalParser(this.context);this.changeDetector.setParser(this.incrementalParser),this.reset(),n.length>0&&this.addClass(n)}removeClass(e){if(this.isDestroyed)return;let t=new Set(this.normalizeClasses(e)),n=Array.from(this.cache.values()).filter(e=>!t.has(e.cls));n.length!==this.cache.size&&(this.reset(),n.forEach(e=>this.incrementalParser.markProcessed(e.cls)),this.applyParseResults(n))}destroy(){this.isDestroyed||=(this.changeDetector.disconnect(),this.gc?.cancel(),this.stylePartitionManager.cleanup(),this.cache.clear(),this.rootCache.clear(),!0)}getStats(){return{cachedClasses:this.cache.size,styleElementId:this.options.styleId,isDestroyed:this.isDestroyed,config:this.options.config,cacheStats:this.getCacheStats(),adopted:!this.shadowRoot&&this.stylePartitionManager instanceof C,sharedSheet:this.shadowRoot&&this.stylePartitionManager instanceof C?{roots:this.stylePartitionManager.shared.rootCount,rules:this.stylePartitionManager.shared.ruleCount,generations:this.stylePartitionManager.shared.generations,constructable:this.stylePartitionManager.shared.constructable}:null}}},D=null,O,k=``,A=!1,j=!1;function M(e={}){if(!D||D.getStats().isDestroyed?(D=new E(e),O=e.config,k=e.nonce??``,A=e.constructable??!1,j=!1):e.config&&e.config!==O&&(D.updateConfig(e.config),O=e.config),!j){let t=e.nonce!==void 0&&e.nonce!==k,n=e.constructable!==void 0&&e.constructable!==A;if(t||n){j=!0;let e=[t&&`nonce (runtime has ${k?`a different nonce`:`none`})`,n&&`constructable (runtime has ${A})`].filter(Boolean).join(` and `);console.warn(`[BaroCSS] runtime already created with a different ${e}; the new value is ignored. Pass nonce/constructable on the first getRuntime/baroStart call.`)}}return D}function N({loadingClassName:e=`baro-boot`,...t}={}){if(t.root&&t.root.nodeType===11)return new E(t);if(!document.body){document.addEventListener(`DOMContentLoaded`,()=>N({loadingClassName:e,...t}),{once:!0});return}let n=`${e}-doing`,r=`${e}-done`;try{document.body.classList.add(n),M(t).observe(document.body,{scan:!0,onReady:()=>{document.body.classList.remove(n),document.body.classList.add(r)}})}catch(e){document.body?.classList.remove(n),console.error(`BaroCSS boot failed:`,e)}}var P=N;function F(e){if(!e||typeof e!=`object`||Array.isArray(e))return[];let t=e.elements;if(!t||typeof t!=`object`||Array.isArray(t))return[];let n=new Set;for(let e of Object.keys(t)){let r=t[e];if(!r||typeof r!=`object`||Array.isArray(r))continue;let i=r.props;if(!i||typeof i!=`object`||Array.isArray(i))continue;let o=i.className;if(typeof o==`string`)for(let e of a(o))e&&n.add(e)}return Array.from(n)}function I(e,t){let n=F(e);n.length>0&&t.addClass(n)}var L={colors:Object.fromEntries(`background.foreground.card.card-foreground.popover.popover-foreground.primary.primary-foreground.secondary.secondary-foreground.muted.muted-foreground.accent.accent-foreground.destructive.border.input.ring.chart-1.chart-2.chart-3.chart-4.chart-5.sidebar.sidebar-foreground.sidebar-primary.sidebar-primary-foreground.sidebar-accent.sidebar-accent-foreground.sidebar-border.sidebar-ring`.split(`.`).map(e=>[e,`var(--${e})`])),borderRadius:{sm:`calc(var(--radius) - 4px)`,md:`calc(var(--radius) - 2px)`,lg:`var(--radius)`,xl:`calc(var(--radius) + 4px)`}};e.BrowserRuntime=E,e.ChangeDetector=o,e.LAYER_ORDER=T,e.SSR_STYLE_SELECTOR=w,e.StylePartitionManager=n,e.baroBoot=N,e.baroStart=P,e.collectJsonRenderClassNames=F,e.getRuntime=M,e.normalizeClassName=i,e.normalizeClassNameList=a,e.preloadJsonRenderClasses=I,e.shadcnTheme=L});
16
+ `)}getClasses(){return Array.from(this.cache.keys())}getCacheStats(){let e=this.incrementalParser.getStats();return{runtime:{cachedClasses:this.cache.size,rootCacheSize:this.rootCache.size,ruleCount:this.stylePartitionManager.ruleCount,reclaimedClasses:this.reclaimedCount,gc:this.gc?.stats()??null},ast:e.cacheStats.ast,incremental:e}}clearCaches(){this.isDestroyed||(this.cache.clear(),this.rootCache.clear(),(0,t.clearAstCache)(this.context),this.incrementalParser.clearProcessed(),this.stylePartitionManager.cleanup(),this.stylePartitionManager=this.createStyles(),this.injectPreflightCSS(),this.ensureCssVars(),this.insertSsrRules(this.ssrRules))}reset(){this.isDestroyed||(this.cache.clear(),this.rootCache.clear(),this.incrementalParser.clearProcessed(),this.stylePartitionManager.cleanup(),this.stylePartitionManager=this.createStyles(),this.injectPreflightCSS(),this.ensureCssVars(),this.insertSsrRules(this.ssrRules))}updateConfig(e){if(this.isDestroyed)return;let n=Array.from(this.cache.keys());if(this.options.config=e,this.shadowRoot){this.stylePartitionManager.cleanup();let t=w(e);this.context=t.context,this.incrementalParser=new E(t)}else this.context=(0,t.createContext)(e),this.incrementalParser=new t.IncrementalParser(this.context);this.changeDetector.setParser(this.incrementalParser),this.reset(),n.length>0&&this.addClass(n)}removeClass(e){if(this.isDestroyed)return;let t=new Set(this.normalizeClasses(e)),n=Array.from(this.cache.values()).filter(e=>!t.has(e.cls));n.length!==this.cache.size&&(this.reset(),n.forEach(e=>this.incrementalParser.markProcessed(e.cls)),this.applyParseResults(n))}destroy(){this.isDestroyed||=(this.changeDetector.disconnect(),this.gc?.cancel(),this.stylePartitionManager.cleanup(),this.cache.clear(),this.rootCache.clear(),!0)}getStats(){return{cachedClasses:this.cache.size,styleElementId:this.options.styleId,isDestroyed:this.isDestroyed,config:this.options.config,cacheStats:this.getCacheStats(),adopted:!this.shadowRoot&&this.stylePartitionManager instanceof D,sharedSheet:this.shadowRoot&&this.stylePartitionManager instanceof D?{roots:this.stylePartitionManager.shared.rootCount,rules:this.stylePartitionManager.shared.ruleCount,generations:this.stylePartitionManager.shared.generations,constructable:this.stylePartitionManager.shared.constructable}:null}}},j=null,M,N=``,P=!1,F=!1;function I(e={}){if(!j||j.getStats().isDestroyed?(j=new A(e),M=e.config,N=e.nonce??``,P=e.constructable??!1,F=!1):e.config&&e.config!==M&&(j.updateConfig(e.config),M=e.config),!F){let t=e.nonce!==void 0&&e.nonce!==N,n=e.constructable!==void 0&&e.constructable!==P;if(t||n){F=!0;let e=[t&&`nonce (runtime has ${N?`a different nonce`:`none`})`,n&&`constructable (runtime has ${P})`].filter(Boolean).join(` and `);console.warn(`[BaroCSS] runtime already created with a different ${e}; the new value is ignored. Pass nonce/constructable on the first getRuntime/baroStart call.`)}}return j}function L({loadingClassName:e=`baro-boot`,...t}={}){if(t.root&&t.root.nodeType===11)return new A(t);if(!document.body){document.addEventListener(`DOMContentLoaded`,()=>L({loadingClassName:e,...t}),{once:!0});return}let n=`${e}-doing`,r=`${e}-done`;try{document.body.classList.add(n),I(t).observe(document.body,{scan:!0,onReady:()=>{document.body.classList.remove(n),document.body.classList.add(r)}})}catch(e){document.body?.classList.remove(n),console.error(`BaroCSS boot failed:`,e)}}var R=L;function z(e){if(!e||typeof e!=`object`||Array.isArray(e))return[];let t=e.elements;if(!t||typeof t!=`object`||Array.isArray(t))return[];let n=new Set;for(let e of Object.keys(t)){let r=t[e];if(!r||typeof r!=`object`||Array.isArray(r))continue;let i=r.props;if(!i||typeof i!=`object`||Array.isArray(i))continue;let o=i.className;if(typeof o==`string`)for(let e of a(o))e&&n.add(e)}return Array.from(n)}function B(e,t){let n=z(e);n.length>0&&t.addClass(n)}var V={colors:Object.fromEntries(`background.foreground.card.card-foreground.popover.popover-foreground.primary.primary-foreground.secondary.secondary-foreground.muted.muted-foreground.accent.accent-foreground.destructive.border.input.ring.chart-1.chart-2.chart-3.chart-4.chart-5.sidebar.sidebar-foreground.sidebar-primary.sidebar-primary-foreground.sidebar-accent.sidebar-accent-foreground.sidebar-border.sidebar-ring`.split(`.`).map(e=>[e,`var(--${e})`])),borderRadius:{sm:`calc(var(--radius) - 4px)`,md:`calc(var(--radius) - 2px)`,lg:`var(--radius)`,xl:`calc(var(--radius) + 4px)`}};e.BrowserRuntime=A,e.ChangeDetector=o,e.LAYER_ORDER=k,e.SSR_STYLE_SELECTOR=O,e.StylePartitionManager=n,e.baroBoot=L,e.baroStart=R,e.collectJsonRenderClassNames=z,e.getRuntime=I,e.normalizeClassName=i,e.normalizeClassNameList=a,e.preloadJsonRenderClasses=B,e.shadcnTheme=V});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barocss/browser",
3
- "version": "0.10.1",
3
+ "version": "0.10.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/barocss/barocss.git",
@@ -30,7 +30,7 @@
30
30
  "access": "public"
31
31
  },
32
32
  "dependencies": {
33
- "@barocss/kit": "0.10.1"
33
+ "@barocss/kit": "0.10.3"
34
34
  },
35
35
  "devDependencies": {
36
36
  "jsdom": "^26.1.0",