@barocss/browser 0.10.2 → 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,6 +1,6 @@
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
  `)+`
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);
package/dist/index.umd.js CHANGED
@@ -1,6 +1,6 @@
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
  `)+`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barocss/browser",
3
- "version": "0.10.2",
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.2"
33
+ "@barocss/kit": "0.10.3"
34
34
  },
35
35
  "devDependencies": {
36
36
  "jsdom": "^26.1.0",