Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
add one rule
Oleg Isonenf3108b0f5765
diff --git a/packages/css-engine/src/style-sheet.test.ts b/packages/css-engine/src/style-sheet.test.tsindex 9fa9201023..2f6ec0c8e5 100644--- a/packages/css-engine/src/style-sheet.test.ts+++ b/packages/css-engine/src/style-sheet.test.ts@@ -42,6 +42,26 @@ describe("StyleSheet", () => {`);});+ test("add one rule", () => {+ const sheet = new StyleSheet();+ sheet.addBreakpoints([breakpoint0]);+ const rule = sheet.addRule({+ style: {+ ...style0,+ color: { type: "keyword", value: "red" },+ },+ breakpoint: "0",+ });+ expect(sheet.toString()).toMatchInlineSnapshot(`+ "@media (min-width: 0px) {+ .s0 { display: block; color: red }+ }"+ `);+ expect(rule.toString()).toMatchInlineSnapshot(+ `".s0 { display: block; color: red }"`+ );+ });+test("skip breakpoint without rules", () => {const sheet = new StyleSheet();sheet.addBreakpoints([breakpoint0]);diff --git a/packages/css-engine/src/style-sheet.ts b/packages/css-engine/src/style-sheet.tsindex f7804b1602..322d715ea3 100644--- a/packages/css-engine/src/style-sheet.ts+++ b/packages/css-engine/src/style-sheet.ts@@ -38,6 +38,7 @@ class MediaRule {}addRule(rule: StyleRule) {this.rules.push(rule);+ return rule;}toString() {if (this.rules.length === 0) return "";@@ -55,14 +56,16 @@ export class StyleSheet {this.mediaRules.set(breakpoint.id, new MediaRule(breakpoint));}}+ addRule(rule: CssRule) {+ const mediaRule = this.mediaRules.get(rule.breakpoint);+ if (mediaRule === undefined) {+ throw new Error(`Unknown breakpoint: ${rule.breakpoint}`);+ }+ return mediaRule.addRule(new StyleRule(rule.style));+ }addRules(rules: Array<CssRule>) {for (const rule of rules) {- const mediaRule = this.mediaRules.get(rule.breakpoint);- if (mediaRule === undefined) {- throw new Error(`Unknown breakpoint: ${rule.breakpoint}`);- }-- mediaRule.addRule(new StyleRule(rule.style));+ this.addRule(rule);}}mount() {