css-in-js-engine-pb 0.1.4 → 0.1.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"insertWithBucket.d.ts","sourceRoot":"","sources":["../src/insertWithBucket.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAgB5C,wBAAgB,qBAAqB,CACjC,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,EAAE,WAAW,QAsBtB"}
1
+ {"version":3,"file":"insertWithBucket.d.ts","sourceRoot":"","sources":["../src/insertWithBucket.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AA6B5C,wBAAgB,qBAAqB,CACjC,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,EAAE,WAAW,QA+BtB"}
@@ -1,7 +1,7 @@
1
1
  import { insertRulesOnce } from './insertOnce';
2
2
  import { StyleBucket } from './StyleBucket';
3
3
  const bucketRules = new Map();
4
- const insertedBuckets = new Set();
4
+ const flushedBuckets = new Set();
5
5
  const ORDER = [
6
6
  StyleBucket.Reset,
7
7
  StyleBucket.Base,
@@ -12,9 +12,22 @@ const ORDER = [
12
12
  StyleBucket.Focus,
13
13
  StyleBucket.User,
14
14
  ];
15
+ function canFlush(bucket) {
16
+ const index = ORDER.indexOf(bucket);
17
+ if (index === -1)
18
+ return false;
19
+ // all earlier buckets must be flushed first
20
+ for (let i = 0; i < index; i++) {
21
+ if (!flushedBuckets.has(ORDER[i])) {
22
+ return false;
23
+ }
24
+ }
25
+ return true;
26
+ }
15
27
  export function insertRulesWithBucket(rules, bucket) {
16
28
  if (!rules.length)
17
29
  return;
30
+ // accumulate rules
18
31
  const existing = bucketRules.get(bucket);
19
32
  if (existing) {
20
33
  existing.push(...rules);
@@ -22,14 +35,22 @@ export function insertRulesWithBucket(rules, bucket) {
22
35
  else {
23
36
  bucketRules.set(bucket, [...rules]);
24
37
  }
25
- if (!insertedBuckets.has(bucket)) {
26
- insertedBuckets.add(bucket);
38
+ // try flushing as much as possible, in order
39
+ let progress = true;
40
+ while (progress) {
41
+ progress = false;
27
42
  for (const b of ORDER) {
43
+ if (flushedBuckets.has(b))
44
+ continue;
45
+ if (!canFlush(b))
46
+ continue;
28
47
  const r = bucketRules.get(b);
29
48
  if (r && r.length) {
30
49
  insertRulesOnce(r);
31
50
  bucketRules.set(b, []);
32
51
  }
52
+ flushedBuckets.add(b);
53
+ progress = true;
33
54
  }
34
55
  }
35
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "css-in-js-engine-pb",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "A lightweight atomic CSS-in-JS engine built on the native CSS cascade",
5
5
  "license": "MIT",
6
6
  "type": "module",