@barocss/browser 0.11.0 → 0.11.1
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/cdn/barocss.js +1 -1
- package/dist/cdn/barocss.js.map +1 -1
- package/dist/cdn/barocss.umd.cjs +1 -1
- package/dist/cdn/barocss.umd.cjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.es.js +22 -11
- package/dist/index.umd.js +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -16,4 +16,4 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
16
16
|
`)}}cssText(){return[this.prologueText(),...this.allRules()].join(`
|
|
17
17
|
`)}},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,n){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,n))?!1:(this.owned.add(e),!0)}addRule(e,t){return this.take(e,``,t)}addCategoryRule(e,t,n){return this.take(e,``,n)}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,r.cls):this.addRule(i,r.cls))?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,n):this.stylePartitionManager.addRule(t,n)}}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(`
|
|
18
18
|
`)}getAllCss(){return[...this.rootCache,...Array.from(this.cache.values()).flatMap(e=>e.cssList)].join(`
|
|
19
|
-
`)}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)
|
|
19
|
+
`)}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(e){return typeof e.getAnimations!=`function`||typeof CSSTransition>`u`?null:new Set(e.getAnimations())}function L(e,t){if(t)for(let n of e.getAnimations())n instanceof CSSTransition&&!t.has(n)&&n.finish()}function R({loadingClassName:e=`baro-boot`,...t}={}){if(t.root&&t.root.nodeType===11){let e=I(t.root),n=new k(t);return L(t.root,e),n}if(!document.body){document.addEventListener(`DOMContentLoaded`,()=>R({loadingClassName:e,...t}),{once:!0});return}let n=`${e}-doing`,r=`${e}-done`;try{document.body.classList.add(n);let e=F(t),i=I(document);e.observe(document.body,{scan:!0,onReady:()=>{document.body.classList.remove(n),document.body.classList.add(r)}}),L(document,i)}catch(e){document.body?.classList.remove(n),console.error(`BaroCSS boot failed:`,e)}}var z=R;function B(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 V(e,t){let n=B(e);n.length>0&&t.addClass(n)}var H={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=R,exports.baroStart=z,exports.collectJsonRenderClassNames=B,exports.getRuntime=F,exports.normalizeClassName=r,exports.normalizeClassNameList=i,exports.preloadJsonRenderClasses=V,exports.shadcnTheme=H;
|
package/dist/index.es.js
CHANGED
|
@@ -851,10 +851,19 @@ function H(e = {}) {
|
|
|
851
851
|
}
|
|
852
852
|
return L;
|
|
853
853
|
}
|
|
854
|
-
function U(
|
|
855
|
-
|
|
854
|
+
function U(e) {
|
|
855
|
+
return typeof e.getAnimations != "function" || typeof CSSTransition > "u" ? null : new Set(e.getAnimations());
|
|
856
|
+
}
|
|
857
|
+
function W(e, t) {
|
|
858
|
+
if (t) for (let n of e.getAnimations()) n instanceof CSSTransition && !t.has(n) && n.finish();
|
|
859
|
+
}
|
|
860
|
+
function G({ loadingClassName: e = "baro-boot", ...t } = {}) {
|
|
861
|
+
if (t.root && t.root.nodeType === 11) {
|
|
862
|
+
let e = U(t.root), n = new I(t);
|
|
863
|
+
return W(t.root, e), n;
|
|
864
|
+
}
|
|
856
865
|
if (!document.body) {
|
|
857
|
-
document.addEventListener("DOMContentLoaded", () =>
|
|
866
|
+
document.addEventListener("DOMContentLoaded", () => G({
|
|
858
867
|
loadingClassName: e,
|
|
859
868
|
...t
|
|
860
869
|
}), { once: !0 });
|
|
@@ -862,20 +871,22 @@ function U({ loadingClassName: e = "baro-boot", ...t } = {}) {
|
|
|
862
871
|
}
|
|
863
872
|
let n = `${e}-doing`, r = `${e}-done`;
|
|
864
873
|
try {
|
|
865
|
-
document.body.classList.add(n)
|
|
874
|
+
document.body.classList.add(n);
|
|
875
|
+
let e = H(t), i = U(document);
|
|
876
|
+
e.observe(document.body, {
|
|
866
877
|
scan: !0,
|
|
867
878
|
onReady: () => {
|
|
868
879
|
document.body.classList.remove(n), document.body.classList.add(r);
|
|
869
880
|
}
|
|
870
|
-
});
|
|
881
|
+
}), W(document, i);
|
|
871
882
|
} catch (e) {
|
|
872
883
|
document.body?.classList.remove(n), console.error("BaroCSS boot failed:", e);
|
|
873
884
|
}
|
|
874
885
|
}
|
|
875
|
-
var
|
|
886
|
+
var K = G;
|
|
876
887
|
//#endregion
|
|
877
888
|
//#region src/json-render-preload.ts
|
|
878
|
-
function
|
|
889
|
+
function q(e) {
|
|
879
890
|
if (!e || typeof e != "object" || Array.isArray(e)) return [];
|
|
880
891
|
let t = e.elements;
|
|
881
892
|
if (!t || typeof t != "object" || Array.isArray(t)) return [];
|
|
@@ -890,11 +901,11 @@ function G(e) {
|
|
|
890
901
|
}
|
|
891
902
|
return Array.from(n);
|
|
892
903
|
}
|
|
893
|
-
function
|
|
894
|
-
let n =
|
|
904
|
+
function J(e, t) {
|
|
905
|
+
let n = q(e);
|
|
895
906
|
n.length > 0 && t.addClass(n);
|
|
896
907
|
}
|
|
897
|
-
var
|
|
908
|
+
var Y = {
|
|
898
909
|
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})`])),
|
|
899
910
|
borderRadius: {
|
|
900
911
|
sm: "calc(var(--radius) - 4px)",
|
|
@@ -904,4 +915,4 @@ var q = {
|
|
|
904
915
|
}
|
|
905
916
|
};
|
|
906
917
|
//#endregion
|
|
907
|
-
export { I as BrowserRuntime, f as ChangeDetector, F as LAYER_ORDER, P as SSR_STYLE_SELECTOR, c as StylePartitionManager,
|
|
918
|
+
export { I as BrowserRuntime, f as ChangeDetector, F as LAYER_ORDER, P as SSR_STYLE_SELECTOR, c as StylePartitionManager, G as baroBoot, K as baroStart, q as collectJsonRenderClassNames, H as getRuntime, u as normalizeClassName, d as normalizeClassNameList, J as preloadJsonRenderClasses, Y as shadcnTheme };
|
package/dist/index.umd.js
CHANGED
|
@@ -16,4 +16,4 @@
|
|
|
16
16
|
`)}}cssText(){return[this.prologueText(),...this.allRules()].join(`
|
|
17
17
|
`)}},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,n){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,n))?!1:(this.owned.add(e),!0)}addRule(e,t){return this.take(e,``,t)}addCategoryRule(e,t,n){return this.take(e,``,n)}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,r.cls):this.addRule(i,r.cls))?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,n):this.stylePartitionManager.addRule(t,n)}}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(`
|
|
18
18
|
`)}getAllCss(){return[...this.rootCache,...Array.from(this.cache.values()).flatMap(e=>e.cssList)].join(`
|
|
19
|
-
`)}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)
|
|
19
|
+
`)}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(e){return typeof e.getAnimations!=`function`||typeof CSSTransition>`u`?null:new Set(e.getAnimations())}function R(e,t){if(t)for(let n of e.getAnimations())n instanceof CSSTransition&&!t.has(n)&&n.finish()}function z({loadingClassName:e=`baro-boot`,...t}={}){if(t.root&&t.root.nodeType===11){let e=L(t.root),n=new A(t);return R(t.root,e),n}if(!document.body){document.addEventListener(`DOMContentLoaded`,()=>z({loadingClassName:e,...t}),{once:!0});return}let n=`${e}-doing`,r=`${e}-done`;try{document.body.classList.add(n);let e=I(t),i=L(document);e.observe(document.body,{scan:!0,onReady:()=>{document.body.classList.remove(n),document.body.classList.add(r)}}),R(document,i)}catch(e){document.body?.classList.remove(n),console.error(`BaroCSS boot failed:`,e)}}var B=z;function V(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 H(e,t){let n=V(e);n.length>0&&t.addClass(n)}var U={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=z,e.baroStart=B,e.collectJsonRenderClassNames=V,e.getRuntime=I,e.normalizeClassName=i,e.normalizeClassNameList=a,e.preloadJsonRenderClasses=H,e.shadcnTheme=U});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barocss/browser",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.1",
|
|
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.11.
|
|
33
|
+
"@barocss/kit": "0.11.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"jsdom": "^26.1.0",
|