@webstudio-is/css-engine 0.151.0 → 0.167.0

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/lib/index.js CHANGED
@@ -87,12 +87,12 @@ var toValue = (styleValue, transformValue) => {
87
87
  };
88
88
 
89
89
  // src/core/to-property.ts
90
- import hyphenate from "hyphenate-style-name";
90
+ var hyphenateProperty = (property) => property.replace(/[A-Z]/g, (match) => "-" + match.toLowerCase());
91
91
  var toProperty = (property) => {
92
92
  if (property === "backgroundClip") {
93
93
  return "-webkit-background-clip";
94
94
  }
95
- return hyphenate(property);
95
+ return hyphenateProperty(property);
96
96
  };
97
97
 
98
98
  // src/core/rules.ts
@@ -130,19 +130,28 @@ var MixinRule = class {
130
130
  };
131
131
  var NestingRule = class {
132
132
  #selector;
133
+ #descendantSuffix;
133
134
  #mixinRules = /* @__PURE__ */ new Map();
134
135
  #mixins = /* @__PURE__ */ new Set();
135
136
  // use map to avoid duplicated properties
136
137
  #declarations = /* @__PURE__ */ new Map();
137
138
  // cached generated rule by breakpoint
138
139
  #cache = /* @__PURE__ */ new Map();
139
- constructor(selector, mixinRules) {
140
+ constructor(mixinRules, selector, descendantSuffix) {
140
141
  this.#selector = selector;
142
+ this.#descendantSuffix = descendantSuffix;
141
143
  this.#mixinRules = mixinRules;
142
144
  }
143
145
  getSelector() {
144
146
  return this.#selector;
145
147
  }
148
+ setSelector(selector) {
149
+ this.#selector = selector;
150
+ this.#cache.clear();
151
+ }
152
+ getDescendantSuffix() {
153
+ return this.#descendantSuffix;
154
+ }
146
155
  addMixin(mixin) {
147
156
  this.#mixins.add(mixin);
148
157
  this.#cache.clear();
@@ -197,7 +206,7 @@ var NestingRule = class {
197
206
  continue;
198
207
  }
199
208
  const { selector: nestedSelector, property, value } = declaration;
200
- const selector = `${this.#selector}${nestedSelector}`;
209
+ const selector = this.#selector + this.#descendantSuffix + nestedSelector;
201
210
  const lines = linesBySelector.get(selector) ?? "";
202
211
  const propertyString = toProperty(property);
203
212
  const valueString = toValue(value, transformValue);
@@ -506,11 +515,12 @@ var StyleSheet = class {
506
515
  }
507
516
  return rule;
508
517
  }
509
- addNestingRule(selector) {
510
- let rule = this.nestingRules.get(selector);
518
+ addNestingRule(selector, descendantSuffix = "") {
519
+ const key = selector + descendantSuffix;
520
+ let rule = this.nestingRules.get(key);
511
521
  if (rule === void 0) {
512
- rule = new NestingRule(selector, this.#mixinRules);
513
- this.nestingRules.set(selector, rule);
522
+ rule = new NestingRule(this.#mixinRules, selector, descendantSuffix);
523
+ this.nestingRules.set(key, rule);
514
524
  }
515
525
  return rule;
516
526
  }
@@ -618,22 +628,30 @@ var generateAtomic = (sheet, options) => {
618
628
  const atomicRules = /* @__PURE__ */ new Map();
619
629
  const classesMap = /* @__PURE__ */ new Map();
620
630
  for (const rule of sheet.nestingRules.values()) {
631
+ const descendantSuffix = rule.getDescendantSuffix();
621
632
  const groupKey = getKey(rule);
622
- const classList = [];
633
+ let classList = classesMap.get(groupKey);
634
+ if (classList === void 0) {
635
+ classList = [];
636
+ classesMap.set(groupKey, classList);
637
+ }
623
638
  for (const declaration of rule.getDeclarations()) {
624
639
  const atomicHash = hash(
625
- declaration.breakpoint + declaration.selector + declaration.property + toValue(declaration.value, transformValue)
640
+ descendantSuffix + declaration.breakpoint + declaration.selector + declaration.property + toValue(declaration.value, transformValue)
626
641
  );
627
642
  const className = `c${atomicHash}`;
628
643
  let atomicRule = atomicRules.get(atomicHash);
629
644
  if (atomicRule === void 0) {
630
- atomicRule = new NestingRule(`.${className}`, /* @__PURE__ */ new Map());
645
+ atomicRule = new NestingRule(
646
+ /* @__PURE__ */ new Map(),
647
+ `.${className}`,
648
+ descendantSuffix
649
+ );
631
650
  atomicRule.setDeclaration(declaration);
632
651
  atomicRules.set(atomicHash, atomicRule);
633
652
  }
634
653
  classList.push(className);
635
654
  }
636
- classesMap.set(groupKey, classList);
637
655
  }
638
656
  const cssText = sheet.generateWith({
639
657
  nestingRules: Array.from(atomicRules.values()),
@@ -769,8 +787,8 @@ export {
769
787
  equalMedia,
770
788
  findApplicableMedia,
771
789
  generateAtomic,
790
+ hyphenateProperty,
772
791
  isValidStaticStyleValue,
773
792
  matchMedia,
774
- toProperty,
775
793
  toValue
776
794
  };
@@ -2,7 +2,7 @@ export type { NestingRule, StyleRule, MediaRule, PlaintextRule, FontFaceRule, }
2
2
  export type { StyleSheetRegular } from "./style-sheet-regular";
3
3
  export * from "./create-style-sheet";
4
4
  export * from "./to-value";
5
- export * from "./to-property";
5
+ export { hyphenateProperty } from "./to-property";
6
6
  export * from "./match-media";
7
7
  export * from "./equal-media";
8
8
  export * from "./compare-media";
@@ -44,8 +44,10 @@ export declare class MixinRule {
44
44
  */
45
45
  export declare class NestingRule {
46
46
  #private;
47
- constructor(selector: string, mixinRules: Map<string, MixinRule>);
47
+ constructor(mixinRules: Map<string, MixinRule>, selector: string, descendantSuffix: string);
48
48
  getSelector(): string;
49
+ setSelector(selector: string): void;
50
+ getDescendantSuffix(): string;
49
51
  addMixin(mixin: string): void;
50
52
  applyMixins(mixins: string[]): void;
51
53
  setDeclaration(declaration: Declaration): void;
@@ -14,7 +14,7 @@ export declare class StyleSheet {
14
14
  addMediaRule(id: string, options?: MediaRuleOptions): MediaRule;
15
15
  addPlaintextRule(cssText: string): PlaintextRule | Map<string, PlaintextRule>;
16
16
  addMixinRule(name: string): MixinRule;
17
- addNestingRule(selector: string): NestingRule;
17
+ addNestingRule(selector: string, descendantSuffix?: string): NestingRule;
18
18
  addFontFaceRule(options: FontFaceOptions): number;
19
19
  generateWith({ nestingRules, transformValue, }: {
20
20
  nestingRules: NestingRule[];
@@ -1,2 +1,6 @@
1
1
  import type { StyleProperty } from "../schema";
2
+ /**
3
+ * Hyphenates a camelcased CSS property name
4
+ */
5
+ export declare const hyphenateProperty: (property: string) => string;
2
6
  export declare const toProperty: (property: StyleProperty) => string;
package/package.json CHANGED
@@ -1,37 +1,30 @@
1
1
  {
2
2
  "name": "@webstudio-is/css-engine",
3
- "version": "0.151.0",
3
+ "version": "0.167.0",
4
4
  "description": "CSS Renderer for Webstudio",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
7
7
  "type": "module",
8
8
  "dependencies": {
9
9
  "@emotion/hash": "^0.9.1",
10
- "hyphenate-style-name": "^1.0.4",
11
10
  "zod": "^3.22.4",
12
- "@webstudio-is/fonts": "0.151.0",
13
- "@webstudio-is/error-utils": "0.151.0"
11
+ "@webstudio-is/error-utils": "0.167.0",
12
+ "@webstudio-is/fonts": "0.167.0"
14
13
  },
15
14
  "devDependencies": {
16
15
  "@jest/globals": "^29.7.0",
17
- "@storybook/addon-essentials": "^7.4.0",
18
- "@storybook/addon-links": "^7.4.0",
19
- "@storybook/react": "^7.4.0",
20
- "@types/hyphenate-style-name": "^1.0.0",
21
16
  "@types/react": "^18.2.70",
22
17
  "@types/react-dom": "^18.2.25",
23
18
  "react": "18.3.0-canary-14898b6a9-20240318",
24
19
  "react-dom": "18.3.0-canary-14898b6a9-20240318",
25
20
  "typescript": "5.4.5",
26
21
  "@webstudio-is/jest-config": "1.0.7",
27
- "@webstudio-is/storybook-config": "0.0.0",
28
22
  "@webstudio-is/tsconfig": "1.0.7"
29
23
  },
30
24
  "exports": {
31
25
  "webstudio": "./src/index.ts",
32
26
  "types": "./lib/types/index.d.ts",
33
- "import": "./lib/index.js",
34
- "require": "./lib/index.js"
27
+ "import": "./lib/index.js"
35
28
  },
36
29
  "files": [
37
30
  "lib/*",
@@ -46,8 +39,6 @@
46
39
  "dev": "rm -rf lib && esbuild 'src/**/*.ts' 'src/**/*.tsx' --outdir=lib --watch",
47
40
  "build": "rm -rf lib && esbuild src/index.ts --outdir=lib --bundle --format=esm --packages=external",
48
41
  "dts": "tsc --project tsconfig.dts.json",
49
- "test": "NODE_OPTIONS=--experimental-vm-modules jest",
50
- "storybook:dev": "storybook dev -p 6006",
51
- "storybook:build": "storybook build"
42
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest"
52
43
  }
53
44
  }