@navita/engine 0.0.13 → 0.1.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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var helpers_hypenateProperty = require('./hypenateProperty.cjs');
3
+ var helpers_hyphenateProperty = require('./hyphenateProperty.cjs');
4
4
 
5
5
  // https://github.com/styletron/styletron/blob/b552ddc5050a8cc5eec84a46a299d937d3bb0112/packages/styletron-engine-atomic/src/css.ts#L36
6
6
  function declarationsToBlock(style) {
@@ -8,7 +8,7 @@ function declarationsToBlock(style) {
8
8
  for(const prop in style){
9
9
  const val = style[prop];
10
10
  if (typeof val === "string" || typeof val === "number") {
11
- css += `${helpers_hypenateProperty.hyphenateProperty(prop)}:${val};`;
11
+ css += `${helpers_hyphenateProperty.hyphenateProperty(prop)}:${val};`;
12
12
  }
13
13
  }
14
14
  return css.slice(0, -1);
@@ -1,4 +1,4 @@
1
- import { hyphenateProperty } from './hypenateProperty.mjs';
1
+ import { hyphenateProperty } from './hyphenateProperty.mjs';
2
2
 
3
3
  // https://github.com/styletron/styletron/blob/b552ddc5050a8cc5eec84a46a299d937d3bb0112/packages/styletron-engine-atomic/src/css.ts#L36
4
4
  function declarationsToBlock(style) {
@@ -1,10 +1,15 @@
1
1
  'use strict';
2
2
 
3
+ // Modified from
3
4
  // https://github.com/styletron/styletron/blob/b552ddc5050a8cc5eec84a46a299d937d3bb0112/packages/styletron-engine-atomic/src/hyphenate-style-name.ts
4
5
  const uppercasePattern = /[A-Z]/g;
5
6
  const msPattern = /^ms-/;
7
+ const cssVarPattern = /^--/;
6
8
  const cache = {};
7
9
  function hyphenateProperty(property) {
10
+ if (cssVarPattern.test(property)) {
11
+ return property;
12
+ }
8
13
  return property in cache ? cache[property] : cache[property] = property.replace(uppercasePattern, "-$&").toLowerCase().replace(msPattern, "-ms-");
9
14
  }
10
15
 
@@ -1,8 +1,13 @@
1
+ // Modified from
1
2
  // https://github.com/styletron/styletron/blob/b552ddc5050a8cc5eec84a46a299d937d3bb0112/packages/styletron-engine-atomic/src/hyphenate-style-name.ts
2
3
  const uppercasePattern = /[A-Z]/g;
3
4
  const msPattern = /^ms-/;
5
+ const cssVarPattern = /^--/;
4
6
  const cache = {};
5
7
  function hyphenateProperty(property) {
8
+ if (cssVarPattern.test(property)) {
9
+ return property;
10
+ }
6
11
  return property in cache ? cache[property] : cache[property] = property.replace(uppercasePattern, "-$&").toLowerCase().replace(msPattern, "-ms-");
7
12
  }
8
13
 
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ function isContainerQuery(property) {
4
+ return property.startsWith("@container");
5
+ }
6
+
7
+ exports.isContainerQuery = isContainerQuery;
@@ -0,0 +1,5 @@
1
+ function isContainerQuery(property) {
2
+ return property.startsWith("@container");
3
+ }
4
+
5
+ export { isContainerQuery };
@@ -2,7 +2,7 @@
2
2
 
3
3
  const cssVarRegex = /(?<!var\()(\s*)(--[a-zA-Z0-9_-]+)/g;
4
4
  function normalizeCSSVarsValue(value) {
5
- if (value.startsWith('--') || value.includes(' --') || value.includes(',--')) {
5
+ if (value.includes('--')) {
6
6
  return value.replace(cssVarRegex, "$1var($2)");
7
7
  }
8
8
  return value;
@@ -1,6 +1,6 @@
1
1
  const cssVarRegex = /(?<!var\()(\s*)(--[a-zA-Z0-9_-]+)/g;
2
2
  function normalizeCSSVarsValue(value) {
3
- if (value.startsWith('--') || value.includes(' --') || value.includes(',--')) {
3
+ if (value.includes('--')) {
4
4
  return value.replace(cssVarRegex, "$1var($2)");
5
5
  }
6
6
  return value;
@@ -1,17 +1,26 @@
1
1
  'use strict';
2
2
 
3
+ const lowPriorityProperties = [
4
+ 'all'
5
+ ];
3
6
  function splitStyleBlocks(blocks) {
4
7
  const atRules = [];
5
8
  const rules = [];
9
+ const lowPrioRules = [];
6
10
  for (const block of blocks){
7
11
  if (block.media || block.support) {
8
12
  atRules.push(block);
9
- } else {
10
- rules.push(block);
13
+ continue;
11
14
  }
15
+ if (lowPriorityProperties.includes(block.property.toLowerCase())) {
16
+ lowPrioRules.push(block);
17
+ continue;
18
+ }
19
+ rules.push(block);
12
20
  }
13
21
  return {
14
22
  atRules,
23
+ lowPrioRules,
15
24
  rules
16
25
  };
17
26
  }
@@ -1,15 +1,24 @@
1
+ const lowPriorityProperties = [
2
+ 'all'
3
+ ];
1
4
  function splitStyleBlocks(blocks) {
2
5
  const atRules = [];
3
6
  const rules = [];
7
+ const lowPrioRules = [];
4
8
  for (const block of blocks){
5
9
  if (block.media || block.support) {
6
10
  atRules.push(block);
7
- } else {
8
- rules.push(block);
11
+ continue;
9
12
  }
13
+ if (lowPriorityProperties.includes(block.property.toLowerCase())) {
14
+ lowPrioRules.push(block);
15
+ continue;
16
+ }
17
+ rules.push(block);
10
18
  }
11
19
  return {
12
20
  atRules,
21
+ lowPrioRules,
13
22
  rules
14
23
  };
15
24
  }
package/index.cjs CHANGED
@@ -13,6 +13,7 @@ var printers_printKeyFrames = require('./printers/printKeyFrames.cjs');
13
13
  var printers_printSourceMap = require('./printers/printSourceMap.cjs');
14
14
  var printers_printStyleBlocks = require('./printers/printStyleBlocks.cjs');
15
15
  var printers_sortAtRules = require('./printers/sortAtRules.cjs');
16
+ var processKeyframes = require('./processKeyframes.cjs');
16
17
  var processStyles = require('./processStyles.cjs');
17
18
  var wrappers_classList = require('./wrappers/classList.cjs');
18
19
  var wrappers_static = require('./wrappers/static.cjs');
@@ -80,7 +81,7 @@ class Engine {
80
81
  addKeyframes(keyframes) {
81
82
  const { id } = this.caches.keyframes.getOrStore({
82
83
  type: "keyframes",
83
- rule: keyframes
84
+ rule: processKeyframes.processKeyframes(keyframes)
84
85
  });
85
86
  this.addUsedIds("keyframes", [
86
87
  id
@@ -105,6 +106,14 @@ class Engine {
105
106
  };
106
107
  return extraClass;
107
108
  }
109
+ clearSourceMapReferences(filePath) {
110
+ const newFilePath = path.relative(this.options.context || process.cwd(), filePath);
111
+ this.sourceMapReferences[newFilePath] = [];
112
+ }
113
+ clearCache(filePath) {
114
+ this.clearUsedIds(filePath);
115
+ this.clearSourceMapReferences(filePath);
116
+ }
108
117
  generateIdentifier(value) {
109
118
  if (typeof value === 'undefined') {
110
119
  let identifier = hash((this.identifierCount++).toString(36));
@@ -126,20 +135,29 @@ class Engine {
126
135
  const { filePaths , usedIds , opinionatedLayers =false } = options || {};
127
136
  // We prioritize ids over filePaths. If neither are provided, we use all the used filePaths.
128
137
  const { keyframes: keyframesCache , fontFace: fontFaceCache , static: staticCache , rule: ruleCache } = usedIds ?? this.getUsedCacheIds(filePaths ?? Object.keys(this.usedIds));
129
- const { atRules , rules } = helpers_splitStyleBlocks.splitStyleBlocks(this.caches.rule.items(ruleCache));
138
+ const { atRules , lowPrioRules , rules } = helpers_splitStyleBlocks.splitStyleBlocks(this.caches.rule.items(ruleCache));
130
139
  const keyFrameCss = printers_printKeyFrames.printKeyFrames(this.caches.keyframes.items(keyframesCache));
131
140
  const fontFaceCss = printers_printFontFaces.printFontFaces(this.caches.fontFace.items(fontFaceCache));
132
141
  const staticCss = printers_printStyleBlocks.printStyleBlocks(this.caches.static.items(staticCache));
133
142
  const atRulesCss = printers_printStyleBlocks.printStyleBlocks(printers_sortAtRules.sortAtRules(atRules));
143
+ const lowPrioRulesCss = printers_printStyleBlocks.printStyleBlocks(lowPrioRules);
134
144
  const rulesCss = printers_printStyleBlocks.printStyleBlocks(rules);
135
145
  if (opinionatedLayers) {
136
- const result = `${keyFrameCss}${fontFaceCss}` + (staticCss.length > 0 ? `@layer static{${staticCss}}` : '') + (rulesCss.length > 0 ? `@layer rules{${rulesCss}}` : '') + (atRulesCss.length > 0 ? `@layer at{${atRulesCss}}` : '');
146
+ const result = `${keyFrameCss}${fontFaceCss}` + (staticCss.length > 0 ? `@layer s{${staticCss}}` : '') + (lowPrioRulesCss.length > 0 ? `@layer lpr{${lowPrioRulesCss}}` : '') + (rulesCss.length > 0 ? `@layer r{${rulesCss}}` : '') + (atRulesCss.length > 0 ? `@layer at{${atRulesCss}}` : '');
137
147
  if (result.length > 0) {
138
- return `@layer static,rules,at;${result}`;
148
+ // s - static
149
+ // lpr - low priority rules
150
+ // r - rules
151
+ // at - at rules
152
+ return `@layer s,lpr,r,at;${result}`;
139
153
  }
140
154
  return '';
141
155
  }
142
- return printers_printSourceMap.printSourceMap(this.sourceMapReferences, keyFrameCss + fontFaceCss + staticCss + rulesCss + atRulesCss);
156
+ const content = keyFrameCss + fontFaceCss + staticCss + lowPrioRulesCss + rulesCss + atRulesCss;
157
+ if (this.options.enableSourceMaps) {
158
+ return printers_printSourceMap.printSourceMap(this.sourceMapReferences, content);
159
+ }
160
+ return content;
143
161
  }
144
162
  serialize() {
145
163
  const { caches , usedIds , identifierCount , sourceMapReferences } = this;
package/index.d.ts CHANGED
@@ -35,6 +35,8 @@ declare class Engine {
35
35
  line: number;
36
36
  column: number;
37
37
  }): string | false;
38
+ private clearSourceMapReferences;
39
+ clearCache(filePath: string): void;
38
40
  generateIdentifier(value: unknown): string;
39
41
  renderCssToString(options?: {
40
42
  filePaths?: string[];
package/index.mjs CHANGED
@@ -11,6 +11,7 @@ import { printKeyFrames } from './printers/printKeyFrames.mjs';
11
11
  import { printSourceMap } from './printers/printSourceMap.mjs';
12
12
  import { printStyleBlocks } from './printers/printStyleBlocks.mjs';
13
13
  import { sortAtRules } from './printers/sortAtRules.mjs';
14
+ import { processKeyframes } from './processKeyframes.mjs';
14
15
  import { processStyles } from './processStyles.mjs';
15
16
  import { ClassList } from './wrappers/classList.mjs';
16
17
  import { Static } from './wrappers/static.mjs';
@@ -78,7 +79,7 @@ class Engine {
78
79
  addKeyframes(keyframes) {
79
80
  const { id } = this.caches.keyframes.getOrStore({
80
81
  type: "keyframes",
81
- rule: keyframes
82
+ rule: processKeyframes(keyframes)
82
83
  });
83
84
  this.addUsedIds("keyframes", [
84
85
  id
@@ -103,6 +104,14 @@ class Engine {
103
104
  };
104
105
  return extraClass;
105
106
  }
107
+ clearSourceMapReferences(filePath) {
108
+ const newFilePath = path.relative(this.options.context || process.cwd(), filePath);
109
+ this.sourceMapReferences[newFilePath] = [];
110
+ }
111
+ clearCache(filePath) {
112
+ this.clearUsedIds(filePath);
113
+ this.clearSourceMapReferences(filePath);
114
+ }
106
115
  generateIdentifier(value) {
107
116
  if (typeof value === 'undefined') {
108
117
  let identifier = hash((this.identifierCount++).toString(36));
@@ -124,20 +133,29 @@ class Engine {
124
133
  const { filePaths , usedIds , opinionatedLayers =false } = options || {};
125
134
  // We prioritize ids over filePaths. If neither are provided, we use all the used filePaths.
126
135
  const { keyframes: keyframesCache , fontFace: fontFaceCache , static: staticCache , rule: ruleCache } = usedIds ?? this.getUsedCacheIds(filePaths ?? Object.keys(this.usedIds));
127
- const { atRules , rules } = splitStyleBlocks(this.caches.rule.items(ruleCache));
136
+ const { atRules , lowPrioRules , rules } = splitStyleBlocks(this.caches.rule.items(ruleCache));
128
137
  const keyFrameCss = printKeyFrames(this.caches.keyframes.items(keyframesCache));
129
138
  const fontFaceCss = printFontFaces(this.caches.fontFace.items(fontFaceCache));
130
139
  const staticCss = printStyleBlocks(this.caches.static.items(staticCache));
131
140
  const atRulesCss = printStyleBlocks(sortAtRules(atRules));
141
+ const lowPrioRulesCss = printStyleBlocks(lowPrioRules);
132
142
  const rulesCss = printStyleBlocks(rules);
133
143
  if (opinionatedLayers) {
134
- const result = `${keyFrameCss}${fontFaceCss}` + (staticCss.length > 0 ? `@layer static{${staticCss}}` : '') + (rulesCss.length > 0 ? `@layer rules{${rulesCss}}` : '') + (atRulesCss.length > 0 ? `@layer at{${atRulesCss}}` : '');
144
+ const result = `${keyFrameCss}${fontFaceCss}` + (staticCss.length > 0 ? `@layer s{${staticCss}}` : '') + (lowPrioRulesCss.length > 0 ? `@layer lpr{${lowPrioRulesCss}}` : '') + (rulesCss.length > 0 ? `@layer r{${rulesCss}}` : '') + (atRulesCss.length > 0 ? `@layer at{${atRulesCss}}` : '');
135
145
  if (result.length > 0) {
136
- return `@layer static,rules,at;${result}`;
146
+ // s - static
147
+ // lpr - low priority rules
148
+ // r - rules
149
+ // at - at rules
150
+ return `@layer s,lpr,r,at;${result}`;
137
151
  }
138
152
  return '';
139
153
  }
140
- return printSourceMap(this.sourceMapReferences, keyFrameCss + fontFaceCss + staticCss + rulesCss + atRulesCss);
154
+ const content = keyFrameCss + fontFaceCss + staticCss + lowPrioRulesCss + rulesCss + atRulesCss;
155
+ if (this.options.enableSourceMaps) {
156
+ return printSourceMap(this.sourceMapReferences, content);
157
+ }
158
+ return content;
141
159
  }
142
160
  serialize() {
143
161
  const { caches , usedIds , identifierCount , sourceMapReferences } = this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navita/engine",
3
- "version": "0.0.13",
3
+ "version": "0.1.1",
4
4
  "description": "Navitas CSS-in-JS engine",
5
5
  "keywords": [
6
6
  "css-in-js",
@@ -6,7 +6,13 @@ function printStyleBlocks(blocks) {
6
6
  let stylesheet = '';
7
7
  let previousStyle;
8
8
  for (const style of blocks){
9
- if (style.type === 'static' && previousStyle && (previousStyle.selector !== style.selector || previousStyle.pseudo !== style.pseudo || previousStyle.media !== style.media || previousStyle.support !== style.support)) {
9
+ if (style.type === 'static' && previousStyle && (previousStyle.selector !== style.selector || previousStyle.pseudo !== style.pseudo || previousStyle.media !== style.media || previousStyle.support !== style.support || previousStyle.container !== style.container)) {
10
+ stylesheet += '}';
11
+ }
12
+ // Close container queries:
13
+ // 1. When the current style is not a container query, and the previous style was container query
14
+ // 2. When the current style is a container query and the previous style was a container query with a different container query
15
+ if (previousStyle && previousStyle.container && (!style.container || style.container !== previousStyle.container)) {
10
16
  stylesheet += '}';
11
17
  }
12
18
  // Close support queries:
@@ -29,10 +35,14 @@ function printStyleBlocks(blocks) {
29
35
  if (style.support && previousStyle?.support !== style.support) {
30
36
  stylesheet += `@supports ${style.support}{`;
31
37
  }
38
+ // Only add container queries if the previous style was not the same container query
39
+ if (style.container && previousStyle?.container !== style.container) {
40
+ stylesheet += `@container ${style.container}{`;
41
+ }
32
42
  if (style.type === 'rule') {
33
43
  const className = `.${style.id}`.repeat(helpers_getPropertyPriority.getPropertyPriority(style.property));
34
44
  stylesheet += `${className}${style.pseudo}{`;
35
- } else if (style.type === 'static' && (previousStyle?.selector !== style.selector || previousStyle?.pseudo !== style.pseudo || previousStyle?.media !== style.media || previousStyle?.support !== style.support)) {
45
+ } else if (style.type === 'static' && (previousStyle?.selector !== style.selector || previousStyle?.pseudo !== style.pseudo || previousStyle?.media !== style.media || previousStyle?.support !== style.support || previousStyle?.container !== style.container)) {
36
46
  // If static, we don't add pseudo selectors currently
37
47
  stylesheet += `${style.selector}${style.pseudo}{`;
38
48
  }
@@ -45,6 +55,9 @@ function printStyleBlocks(blocks) {
45
55
  }
46
56
  previousStyle = style;
47
57
  }
58
+ if (previousStyle?.container) {
59
+ stylesheet += '}';
60
+ }
48
61
  if (previousStyle?.support) {
49
62
  stylesheet += '}';
50
63
  }
@@ -4,7 +4,13 @@ function printStyleBlocks(blocks) {
4
4
  let stylesheet = '';
5
5
  let previousStyle;
6
6
  for (const style of blocks){
7
- if (style.type === 'static' && previousStyle && (previousStyle.selector !== style.selector || previousStyle.pseudo !== style.pseudo || previousStyle.media !== style.media || previousStyle.support !== style.support)) {
7
+ if (style.type === 'static' && previousStyle && (previousStyle.selector !== style.selector || previousStyle.pseudo !== style.pseudo || previousStyle.media !== style.media || previousStyle.support !== style.support || previousStyle.container !== style.container)) {
8
+ stylesheet += '}';
9
+ }
10
+ // Close container queries:
11
+ // 1. When the current style is not a container query, and the previous style was container query
12
+ // 2. When the current style is a container query and the previous style was a container query with a different container query
13
+ if (previousStyle && previousStyle.container && (!style.container || style.container !== previousStyle.container)) {
8
14
  stylesheet += '}';
9
15
  }
10
16
  // Close support queries:
@@ -27,10 +33,14 @@ function printStyleBlocks(blocks) {
27
33
  if (style.support && previousStyle?.support !== style.support) {
28
34
  stylesheet += `@supports ${style.support}{`;
29
35
  }
36
+ // Only add container queries if the previous style was not the same container query
37
+ if (style.container && previousStyle?.container !== style.container) {
38
+ stylesheet += `@container ${style.container}{`;
39
+ }
30
40
  if (style.type === 'rule') {
31
41
  const className = `.${style.id}`.repeat(getPropertyPriority(style.property));
32
42
  stylesheet += `${className}${style.pseudo}{`;
33
- } else if (style.type === 'static' && (previousStyle?.selector !== style.selector || previousStyle?.pseudo !== style.pseudo || previousStyle?.media !== style.media || previousStyle?.support !== style.support)) {
43
+ } else if (style.type === 'static' && (previousStyle?.selector !== style.selector || previousStyle?.pseudo !== style.pseudo || previousStyle?.media !== style.media || previousStyle?.support !== style.support || previousStyle?.container !== style.container)) {
34
44
  // If static, we don't add pseudo selectors currently
35
45
  stylesheet += `${style.selector}${style.pseudo}{`;
36
46
  }
@@ -43,6 +53,9 @@ function printStyleBlocks(blocks) {
43
53
  }
44
54
  previousStyle = style;
45
55
  }
56
+ if (previousStyle?.container) {
57
+ stylesheet += '}';
58
+ }
46
59
  if (previousStyle?.support) {
47
60
  stylesheet += '}';
48
61
  }
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ var helpers_isObject = require('./helpers/isObject.cjs');
4
+ var helpers_transformContentProperty = require('./helpers/transformContentProperty.cjs');
5
+
6
+ const transformValuePropertyMap = {
7
+ content: helpers_transformContentProperty.transformContentProperty
8
+ };
9
+ function processKeyframes(keyframes) {
10
+ const newKeyframes = {};
11
+ for (const [key, value] of Object.entries(keyframes)){
12
+ if (helpers_isObject.isObject(value)) {
13
+ newKeyframes[key] = processKeyframes(value);
14
+ continue;
15
+ }
16
+ let newValue = value;
17
+ if (transformValuePropertyMap[key]) {
18
+ newValue = transformValuePropertyMap[key](newValue);
19
+ }
20
+ newKeyframes[key] = newValue;
21
+ }
22
+ return newKeyframes;
23
+ }
24
+
25
+ exports.processKeyframes = processKeyframes;
@@ -0,0 +1,23 @@
1
+ import { isObject } from './helpers/isObject.mjs';
2
+ import { transformContentProperty } from './helpers/transformContentProperty.mjs';
3
+
4
+ const transformValuePropertyMap = {
5
+ content: transformContentProperty
6
+ };
7
+ function processKeyframes(keyframes) {
8
+ const newKeyframes = {};
9
+ for (const [key, value] of Object.entries(keyframes)){
10
+ if (isObject(value)) {
11
+ newKeyframes[key] = processKeyframes(value);
12
+ continue;
13
+ }
14
+ let newValue = value;
15
+ if (transformValuePropertyMap[key]) {
16
+ newValue = transformValuePropertyMap[key](newValue);
17
+ }
18
+ newKeyframes[key] = newValue;
19
+ }
20
+ return newKeyframes;
21
+ }
22
+
23
+ export { processKeyframes };
package/processStyles.cjs CHANGED
@@ -1,22 +1,23 @@
1
1
  'use strict';
2
2
 
3
3
  var helpers_generateCombinedAtRules = require('./helpers/generateCombinedAtRules.cjs');
4
- var helpers_hypenateProperty = require('./helpers/hypenateProperty.cjs');
4
+ var helpers_hyphenateProperty = require('./helpers/hyphenateProperty.cjs');
5
+ var helpers_isContainerQuery = require('./helpers/isContainerQuery.cjs');
5
6
  var helpers_isMediaQuery = require('./helpers/isMediaQuery.cjs');
6
7
  var helpers_isNestedSelector = require('./helpers/isNestedSelector.cjs');
7
8
  var helpers_isObject = require('./helpers/isObject.cjs');
8
9
  var helpers_isSupportsQuery = require('./helpers/isSupportsQuery.cjs');
9
10
  var helpers_normalizeCSSVarsProperty = require('./helpers/normalizeCSSVarsProperty.cjs');
11
+ var helpers_normalizeCSSVarsValue = require('./helpers/normalizeCSSVarsValue.cjs');
10
12
  var helpers_normalizeNestedProperty = require('./helpers/normalizeNestedProperty.cjs');
11
13
  var helpers_pixelifyProperties = require('./helpers/pixelifyProperties.cjs');
12
14
  var helpers_transformContentProperty = require('./helpers/transformContentProperty.cjs');
13
- var helpers_normalizeCSSVarsValue = require('./helpers/normalizeCSSVarsValue.cjs');
14
15
 
15
16
  const transformValuePropertyMap = {
16
17
  content: helpers_transformContentProperty.transformContentProperty
17
18
  };
18
19
  function processStyles({ cache , type }) {
19
- return function process({ styles , pseudo ="" , media ="" , support ="" , selector ="" }) {
20
+ return function process({ styles , pseudo ="" , media ="" , support ="" , container ="" , selector ="" }) {
20
21
  const result = [];
21
22
  for (const [property, value] of Object.entries(styles)){
22
23
  if (helpers_isObject.isObject(value)) {
@@ -27,18 +28,36 @@ function processStyles({ cache , type }) {
27
28
  pseudo,
28
29
  media: combinedMedia,
29
30
  support,
31
+ container,
30
32
  selector
31
33
  }));
32
- } else if (helpers_isSupportsQuery.isSupportsQuery(property)) {
34
+ continue;
35
+ }
36
+ if (helpers_isSupportsQuery.isSupportsQuery(property)) {
33
37
  const combinedSupport = helpers_generateCombinedAtRules.generateCombinedAtRules(support, property.slice(9).trim());
34
38
  result.push(...process({
35
39
  styles: value,
36
40
  pseudo,
37
41
  media,
38
42
  support: combinedSupport,
43
+ container,
44
+ selector
45
+ }));
46
+ continue;
47
+ }
48
+ if (helpers_isContainerQuery.isContainerQuery(property)) {
49
+ const combinedContainer = helpers_generateCombinedAtRules.generateCombinedAtRules(container, property.slice(10).trim());
50
+ result.push(...process({
51
+ styles: value,
52
+ pseudo,
53
+ media,
54
+ support,
55
+ container: combinedContainer,
39
56
  selector
40
57
  }));
41
- } else if (helpers_isNestedSelector.isNestedSelector(property)) {
58
+ continue;
59
+ }
60
+ if (helpers_isNestedSelector.isNestedSelector(property)) {
42
61
  // This is only allowed in simple pseudos currently.
43
62
  const copies = property.split(',').map((p)=>p.trim());
44
63
  for (const copy of copies){
@@ -47,37 +66,39 @@ function processStyles({ cache , type }) {
47
66
  pseudo: pseudo + helpers_normalizeNestedProperty.normalizeNestedProperty(copy),
48
67
  media,
49
68
  support,
69
+ container,
50
70
  selector
51
71
  }));
52
72
  }
53
- } else {
54
- console.warn("Unknown property", property);
55
- }
56
- } else {
57
- let newProperty = helpers_normalizeCSSVarsProperty.normalizeCSSVarsProperty(property);
58
- let newValue = value;
59
- if (typeof value === "string") {
60
- newValue = value.trim().replace(/;[\n\s]*$/, "");
61
- newValue = helpers_normalizeCSSVarsValue.normalizeCSSVarsValue(newValue);
62
- }
63
- if (typeof value === "number") {
64
- newValue = helpers_pixelifyProperties.pixelifyProperties(newProperty, value);
73
+ continue;
65
74
  }
66
- if (transformValuePropertyMap[newProperty]) {
67
- newValue = transformValuePropertyMap[newProperty](value);
68
- }
69
- newProperty = helpers_hypenateProperty.hyphenateProperty(newProperty);
70
- // Remove trailing semicolon and new lines with regex
71
- result.push(cache.getOrStore({
72
- type,
73
- selector,
74
- property: newProperty,
75
- value: newValue,
76
- pseudo,
77
- media,
78
- support
79
- }));
75
+ console.warn("Unknown property", property);
76
+ continue;
77
+ }
78
+ let newProperty = helpers_normalizeCSSVarsProperty.normalizeCSSVarsProperty(property);
79
+ let newValue = value;
80
+ if (typeof value === "string") {
81
+ newValue = value.trim().replace(/;[\n\s]*$/, "");
82
+ newValue = helpers_normalizeCSSVarsValue.normalizeCSSVarsValue(newValue);
83
+ }
84
+ if (typeof value === "number") {
85
+ newValue = helpers_pixelifyProperties.pixelifyProperties(newProperty, value);
86
+ }
87
+ if (transformValuePropertyMap[newProperty]) {
88
+ newValue = transformValuePropertyMap[newProperty](value);
80
89
  }
90
+ newProperty = helpers_hyphenateProperty.hyphenateProperty(newProperty);
91
+ // Remove trailing semicolon and new lines with regex
92
+ result.push(cache.getOrStore({
93
+ type,
94
+ selector,
95
+ property: newProperty,
96
+ value: newValue,
97
+ pseudo,
98
+ media,
99
+ support,
100
+ container
101
+ }));
81
102
  }
82
103
  return result;
83
104
  };
package/processStyles.mjs CHANGED
@@ -1,20 +1,21 @@
1
1
  import { generateCombinedAtRules } from './helpers/generateCombinedAtRules.mjs';
2
- import { hyphenateProperty } from './helpers/hypenateProperty.mjs';
2
+ import { hyphenateProperty } from './helpers/hyphenateProperty.mjs';
3
+ import { isContainerQuery } from './helpers/isContainerQuery.mjs';
3
4
  import { isMediaQuery } from './helpers/isMediaQuery.mjs';
4
5
  import { isNestedSelector } from './helpers/isNestedSelector.mjs';
5
6
  import { isObject } from './helpers/isObject.mjs';
6
7
  import { isSupportsQuery } from './helpers/isSupportsQuery.mjs';
7
8
  import { normalizeCSSVarsProperty } from './helpers/normalizeCSSVarsProperty.mjs';
9
+ import { normalizeCSSVarsValue } from './helpers/normalizeCSSVarsValue.mjs';
8
10
  import { normalizeNestedProperty } from './helpers/normalizeNestedProperty.mjs';
9
11
  import { pixelifyProperties } from './helpers/pixelifyProperties.mjs';
10
12
  import { transformContentProperty } from './helpers/transformContentProperty.mjs';
11
- import { normalizeCSSVarsValue } from './helpers/normalizeCSSVarsValue.mjs';
12
13
 
13
14
  const transformValuePropertyMap = {
14
15
  content: transformContentProperty
15
16
  };
16
17
  function processStyles({ cache , type }) {
17
- return function process({ styles , pseudo ="" , media ="" , support ="" , selector ="" }) {
18
+ return function process({ styles , pseudo ="" , media ="" , support ="" , container ="" , selector ="" }) {
18
19
  const result = [];
19
20
  for (const [property, value] of Object.entries(styles)){
20
21
  if (isObject(value)) {
@@ -25,18 +26,36 @@ function processStyles({ cache , type }) {
25
26
  pseudo,
26
27
  media: combinedMedia,
27
28
  support,
29
+ container,
28
30
  selector
29
31
  }));
30
- } else if (isSupportsQuery(property)) {
32
+ continue;
33
+ }
34
+ if (isSupportsQuery(property)) {
31
35
  const combinedSupport = generateCombinedAtRules(support, property.slice(9).trim());
32
36
  result.push(...process({
33
37
  styles: value,
34
38
  pseudo,
35
39
  media,
36
40
  support: combinedSupport,
41
+ container,
42
+ selector
43
+ }));
44
+ continue;
45
+ }
46
+ if (isContainerQuery(property)) {
47
+ const combinedContainer = generateCombinedAtRules(container, property.slice(10).trim());
48
+ result.push(...process({
49
+ styles: value,
50
+ pseudo,
51
+ media,
52
+ support,
53
+ container: combinedContainer,
37
54
  selector
38
55
  }));
39
- } else if (isNestedSelector(property)) {
56
+ continue;
57
+ }
58
+ if (isNestedSelector(property)) {
40
59
  // This is only allowed in simple pseudos currently.
41
60
  const copies = property.split(',').map((p)=>p.trim());
42
61
  for (const copy of copies){
@@ -45,37 +64,39 @@ function processStyles({ cache , type }) {
45
64
  pseudo: pseudo + normalizeNestedProperty(copy),
46
65
  media,
47
66
  support,
67
+ container,
48
68
  selector
49
69
  }));
50
70
  }
51
- } else {
52
- console.warn("Unknown property", property);
53
- }
54
- } else {
55
- let newProperty = normalizeCSSVarsProperty(property);
56
- let newValue = value;
57
- if (typeof value === "string") {
58
- newValue = value.trim().replace(/;[\n\s]*$/, "");
59
- newValue = normalizeCSSVarsValue(newValue);
60
- }
61
- if (typeof value === "number") {
62
- newValue = pixelifyProperties(newProperty, value);
71
+ continue;
63
72
  }
64
- if (transformValuePropertyMap[newProperty]) {
65
- newValue = transformValuePropertyMap[newProperty](value);
66
- }
67
- newProperty = hyphenateProperty(newProperty);
68
- // Remove trailing semicolon and new lines with regex
69
- result.push(cache.getOrStore({
70
- type,
71
- selector,
72
- property: newProperty,
73
- value: newValue,
74
- pseudo,
75
- media,
76
- support
77
- }));
73
+ console.warn("Unknown property", property);
74
+ continue;
75
+ }
76
+ let newProperty = normalizeCSSVarsProperty(property);
77
+ let newValue = value;
78
+ if (typeof value === "string") {
79
+ newValue = value.trim().replace(/;[\n\s]*$/, "");
80
+ newValue = normalizeCSSVarsValue(newValue);
81
+ }
82
+ if (typeof value === "number") {
83
+ newValue = pixelifyProperties(newProperty, value);
84
+ }
85
+ if (transformValuePropertyMap[newProperty]) {
86
+ newValue = transformValuePropertyMap[newProperty](value);
78
87
  }
88
+ newProperty = hyphenateProperty(newProperty);
89
+ // Remove trailing semicolon and new lines with regex
90
+ result.push(cache.getOrStore({
91
+ type,
92
+ selector,
93
+ property: newProperty,
94
+ value: newValue,
95
+ pseudo,
96
+ media,
97
+ support,
98
+ container
99
+ }));
79
100
  }
80
101
  return result;
81
102
  };