@webstudio-is/css-engine 0.123.0 → 0.124.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
@@ -88,13 +88,18 @@ var toProperty = (property) => {
88
88
  // src/core/rules.ts
89
89
  var StylePropertyMap = class {
90
90
  #styleMap = /* @__PURE__ */ new Map();
91
- #isDirty = false;
91
+ #isDirty = true;
92
92
  #string = "";
93
93
  #indent = 0;
94
94
  #transformValue;
95
- onChange;
96
- constructor(transformValue) {
95
+ #onChange;
96
+ constructor(style, transformValue, onChange) {
97
97
  this.#transformValue = transformValue;
98
+ this.#onChange = onChange;
99
+ let property;
100
+ for (property in style) {
101
+ this.#styleMap.set(property, style[property]);
102
+ }
98
103
  }
99
104
  setTransformer(transformValue) {
100
105
  this.#transformValue = transformValue;
@@ -102,7 +107,10 @@ var StylePropertyMap = class {
102
107
  set(property, value) {
103
108
  this.#styleMap.set(property, value);
104
109
  this.#isDirty = true;
105
- this.onChange?.();
110
+ this.#onChange?.();
111
+ }
112
+ get(property) {
113
+ return this.#styleMap.get(property);
106
114
  }
107
115
  has(property) {
108
116
  return this.#styleMap.has(property);
@@ -116,12 +124,12 @@ var StylePropertyMap = class {
116
124
  delete(property) {
117
125
  this.#styleMap.delete(property);
118
126
  this.#isDirty = true;
119
- this.onChange?.();
127
+ this.#onChange?.();
120
128
  }
121
129
  clear() {
122
130
  this.#styleMap.clear();
123
131
  this.#isDirty = true;
124
- this.onChange?.();
132
+ this.#onChange?.();
125
133
  }
126
134
  toString({ indent = 0 } = {}) {
127
135
  if (this.#isDirty === false && indent === this.#indent) {
@@ -149,19 +157,10 @@ var StylePropertyMap = class {
149
157
  var StyleRule = class {
150
158
  styleMap;
151
159
  selectorText;
152
- onChange;
153
- constructor(selectorText, style, transformValue) {
154
- this.styleMap = new StylePropertyMap(transformValue);
160
+ constructor(selectorText, style, transformValue, onChange) {
155
161
  this.selectorText = selectorText;
156
- let property;
157
- for (property in style) {
158
- this.styleMap.set(property, style[property]);
159
- }
160
- this.styleMap.onChange = this.#onChange;
162
+ this.styleMap = style instanceof StylePropertyMap ? style : new StylePropertyMap(style, transformValue, onChange);
161
163
  }
162
- #onChange = () => {
163
- this.onChange?.();
164
- };
165
164
  get cssText() {
166
165
  return this.toString();
167
166
  }
@@ -176,25 +175,29 @@ ${spaces}}`;
176
175
  };
177
176
  var MediaRule = class {
178
177
  options;
179
- rules = [];
178
+ rules;
180
179
  #mediaType;
181
180
  constructor(options = {}) {
182
181
  this.options = options;
182
+ this.rules = /* @__PURE__ */ new Map();
183
183
  this.#mediaType = options.mediaType ?? "all";
184
184
  }
185
185
  insertRule(rule) {
186
- this.rules.push(rule);
186
+ this.rules.set(
187
+ "selectorText" in rule ? rule.selectorText : rule.cssText,
188
+ rule
189
+ );
187
190
  return rule;
188
191
  }
189
192
  get cssText() {
190
193
  return this.toString();
191
194
  }
192
195
  toString() {
193
- if (this.rules.length === 0) {
196
+ if (this.rules.size === 0) {
194
197
  return "";
195
198
  }
196
199
  const rules = [];
197
- for (const rule of this.rules) {
200
+ for (const rule of this.rules.values()) {
198
201
  rules.push(rule.toString({ indent: 2 }));
199
202
  }
200
203
  let conditionText = "";
@@ -214,9 +217,10 @@ ${rules.join(
214
217
  };
215
218
  var PlaintextRule = class {
216
219
  cssText;
217
- styleMap = new StylePropertyMap();
220
+ styleMap;
218
221
  constructor(cssText) {
219
222
  this.cssText = cssText;
223
+ this.styleMap = new StylePropertyMap({});
220
224
  }
221
225
  toString() {
222
226
  return this.cssText;
@@ -306,31 +310,13 @@ var StyleElement = class {
306
310
  // src/core/style-sheet.ts
307
311
  var StyleSheet = class {
308
312
  #cssText = "";
309
- #element;
310
- constructor(element) {
311
- this.#element = element;
312
- }
313
- replaceSync(cssText) {
314
- if (cssText !== this.#cssText) {
315
- this.#cssText = cssText;
316
- this.#element.render(cssText);
317
- }
318
- }
319
- };
320
-
321
- // src/core/css-engine.ts
322
- var defaultMediaRuleId = "__default-media-rule__";
323
- var CssEngine = class {
324
- #element;
325
313
  #mediaRules = /* @__PURE__ */ new Map();
326
314
  #plainRules = /* @__PURE__ */ new Map();
327
315
  #fontFaceRules = [];
328
- #sheet;
329
316
  #isDirty = false;
330
- #cssText = "";
331
- constructor({ name }) {
332
- this.#element = new StyleElement(name);
333
- this.#sheet = new StyleSheet(this.#element);
317
+ #element;
318
+ constructor(element) {
319
+ this.#element = element;
334
320
  }
335
321
  addMediaRule(id, options) {
336
322
  let mediaRule = this.#mediaRules.get(id);
@@ -344,18 +330,10 @@ var CssEngine = class {
344
330
  mediaRule.options = options;
345
331
  this.#isDirty = true;
346
332
  }
347
- return mediaRule;
348
- }
349
- addStyleRule(selectorText, rule, transformValue) {
350
- const mediaRule = this.addMediaRule(rule.breakpoint || defaultMediaRuleId);
351
- this.#isDirty = true;
352
- const styleRule = new StyleRule(selectorText, rule.style, transformValue);
353
- styleRule.onChange = this.#onChangeRule;
354
333
  if (mediaRule === void 0) {
355
334
  throw new Error("No media rule found");
356
335
  }
357
- mediaRule.insertRule(styleRule);
358
- return styleRule;
336
+ return mediaRule;
359
337
  }
360
338
  addPlaintextRule(cssText) {
361
339
  const rule = this.#plainRules.get(cssText);
@@ -369,25 +347,9 @@ var CssEngine = class {
369
347
  this.#isDirty = true;
370
348
  return this.#fontFaceRules.push(new FontFaceRule(options));
371
349
  }
372
- clear() {
373
- this.#mediaRules.clear();
374
- this.#plainRules.clear();
375
- this.#fontFaceRules = [];
350
+ markAsDirty() {
376
351
  this.#isDirty = true;
377
352
  }
378
- render() {
379
- this.#element.mount();
380
- this.#sheet.replaceSync(this.cssText);
381
- }
382
- unmount() {
383
- this.#element.unmount();
384
- }
385
- setAttribute(name, value) {
386
- this.#element.setAttribute(name, value);
387
- }
388
- getAttribute(name) {
389
- return this.#element.getAttribute(name);
390
- }
391
353
  get cssText() {
392
354
  if (this.#isDirty === false) {
393
355
  return this.#cssText;
@@ -410,14 +372,92 @@ var CssEngine = class {
410
372
  this.#cssText = css.join("\n");
411
373
  return this.#cssText;
412
374
  }
413
- #onChangeRule = () => {
375
+ clear() {
376
+ this.#mediaRules.clear();
377
+ this.#plainRules.clear();
378
+ this.#fontFaceRules = [];
414
379
  this.#isDirty = true;
380
+ }
381
+ render() {
382
+ this.#element.mount();
383
+ this.#element.render(this.cssText);
384
+ }
385
+ unmount() {
386
+ this.#element.unmount();
387
+ }
388
+ setAttribute(name, value) {
389
+ this.#element.setAttribute(name, value);
390
+ }
391
+ getAttribute(name) {
392
+ return this.#element.getAttribute(name);
393
+ }
394
+ };
395
+
396
+ // src/core/style-sheet-regular.ts
397
+ var defaultMediaRuleId = "__default-media-rule__";
398
+ var StyleSheetRegular = class extends StyleSheet {
399
+ addStyleRule(rule, selectorText, transformValue) {
400
+ const mediaRule = this.addMediaRule(rule.breakpoint || defaultMediaRuleId);
401
+ this.markAsDirty();
402
+ const styleRule = new StyleRule(
403
+ selectorText,
404
+ rule.style,
405
+ transformValue,
406
+ this.#onChangeRule
407
+ );
408
+ mediaRule.insertRule(styleRule);
409
+ return styleRule;
410
+ }
411
+ #onChangeRule = () => {
412
+ this.markAsDirty();
415
413
  };
416
414
  };
417
415
 
418
- // src/core/create-css-engine.ts
419
- var createCssEngine = (options = {}) => {
420
- return new CssEngine(options);
416
+ // src/core/style-sheet-atomic.ts
417
+ import hash from "@emotion/hash";
418
+ var defaultMediaRuleId2 = "__default-media-rule__";
419
+ var StyleSheetAtomic = class extends StyleSheet {
420
+ addStyleRule({ style, breakpoint }, selectorSuffix = "", transformValue) {
421
+ const mediaRule = this.addMediaRule(breakpoint || defaultMediaRuleId2);
422
+ const styleRules = [];
423
+ const classes = [];
424
+ let property;
425
+ for (property in style) {
426
+ const stylePropertyMap = new StylePropertyMap(
427
+ { [property]: style[property] },
428
+ transformValue
429
+ );
430
+ const className = `c${hash(
431
+ stylePropertyMap + selectorSuffix + breakpoint
432
+ )}`;
433
+ classes.push(className);
434
+ const newStyleRule = new StyleRule(
435
+ `.${className}${selectorSuffix}`,
436
+ stylePropertyMap,
437
+ transformValue,
438
+ this.#onChangeRule
439
+ );
440
+ styleRules.push(newStyleRule);
441
+ if (mediaRule.rules.has(newStyleRule.selectorText) === false) {
442
+ mediaRule.insertRule(newStyleRule);
443
+ this.markAsDirty();
444
+ }
445
+ }
446
+ return { styleRules, classes };
447
+ }
448
+ #onChangeRule = () => {
449
+ this.markAsDirty();
450
+ };
451
+ };
452
+
453
+ // src/core/create-style-sheet.ts
454
+ var createRegularStyleSheet = (options) => {
455
+ const element = new StyleElement(options?.name);
456
+ return new StyleSheetRegular(element);
457
+ };
458
+ var createAtomicStyleSheet = (options) => {
459
+ const element = new StyleElement(options?.name);
460
+ return new StyleSheetAtomic(element);
421
461
  };
422
462
 
423
463
  // src/core/match-media.ts
@@ -541,7 +581,6 @@ var StyleValue = z.union([
541
581
  ]);
542
582
  var Style = z.record(z.string(), StyleValue);
543
583
  export {
544
- CssEngine,
545
584
  ImageValue,
546
585
  InvalidValue,
547
586
  KeywordValue,
@@ -552,7 +591,8 @@ export {
552
591
  UnitValue,
553
592
  UnparsedValue,
554
593
  compareMedia,
555
- createCssEngine,
594
+ createAtomicStyleSheet,
595
+ createRegularStyleSheet,
556
596
  equalMedia,
557
597
  findApplicableMedia,
558
598
  isValidStaticStyleValue,
@@ -0,0 +1,8 @@
1
+ import { StyleSheetRegular } from "./style-sheet-regular";
2
+ import { StyleSheetAtomic } from "./style-sheet-atomic";
3
+ export declare const createRegularStyleSheet: (options?: {
4
+ name?: string;
5
+ }) => StyleSheetRegular;
6
+ export declare const createAtomicStyleSheet: (options?: {
7
+ name?: string;
8
+ }) => StyleSheetAtomic;
@@ -1,6 +1,7 @@
1
- export { CssEngine } from "./css-engine";
2
1
  export type { AnyRule, StyleRule, MediaRule, PlaintextRule, FontFaceRule, } from "./rules";
3
- export * from "./create-css-engine";
2
+ export type { StyleSheetRegular } from "./style-sheet-regular";
3
+ export type { StyleSheetAtomic } from "./style-sheet-atomic";
4
+ export * from "./create-style-sheet";
4
5
  export * from "./to-value";
5
6
  export * from "./to-property";
6
7
  export * from "./match-media";
@@ -1,11 +1,219 @@
1
1
  import type { Style, StyleProperty, StyleValue } from "../schema";
2
2
  import { type TransformValue } from "./to-value";
3
- declare class StylePropertyMap {
3
+ export declare class StylePropertyMap {
4
4
  #private;
5
- onChange?: () => void;
6
- constructor(transformValue?: TransformValue);
5
+ constructor(style: Style, transformValue?: TransformValue, onChange?: () => void);
7
6
  setTransformer(transformValue: TransformValue): void;
8
7
  set(property: StyleProperty, value?: StyleValue): void;
8
+ get(property: StyleProperty): {
9
+ type: "unit";
10
+ value: number;
11
+ unit: "number" | "%" | "deg" | "grad" | "rad" | "turn" | "db" | "fr" | "hz" | "khz" | "cm" | "mm" | "q" | "in" | "pt" | "pc" | "px" | "em" | "rem" | "ex" | "rex" | "cap" | "rcap" | "ch" | "rch" | "ic" | "ric" | "lh" | "rlh" | "vw" | "svw" | "lvw" | "dvw" | "vh" | "svh" | "lvh" | "dvh" | "vi" | "svi" | "lvi" | "dvi" | "vb" | "svb" | "lvb" | "dvb" | "vmin" | "svmin" | "lvmin" | "dvmin" | "vmax" | "svmax" | "lvmax" | "dvmax" | "cqw" | "cqh" | "cqi" | "cqb" | "cqmin" | "cqmax" | "dpi" | "dpcm" | "dppx" | "x" | "st" | "s" | "ms";
12
+ } | {
13
+ type: "keyword";
14
+ value: string;
15
+ } | {
16
+ type: "unparsed";
17
+ value: string;
18
+ hidden?: boolean | undefined;
19
+ } | {
20
+ type: "fontFamily";
21
+ value: string[];
22
+ } | {
23
+ type: "rgb";
24
+ r: number;
25
+ g: number;
26
+ b: number;
27
+ alpha: number;
28
+ } | {
29
+ type: "image";
30
+ value: {
31
+ type: "asset";
32
+ value: string;
33
+ } | {
34
+ type: "url";
35
+ url: string;
36
+ };
37
+ hidden?: boolean | undefined;
38
+ } | {
39
+ type: "invalid";
40
+ value: string;
41
+ } | {
42
+ type: "unset";
43
+ value: "";
44
+ } | {
45
+ type: "tuple";
46
+ value: ({
47
+ type: "unit";
48
+ value: number;
49
+ unit: "number" | "%" | "deg" | "grad" | "rad" | "turn" | "db" | "fr" | "hz" | "khz" | "cm" | "mm" | "q" | "in" | "pt" | "pc" | "px" | "em" | "rem" | "ex" | "rex" | "cap" | "rcap" | "ch" | "rch" | "ic" | "ric" | "lh" | "rlh" | "vw" | "svw" | "lvw" | "dvw" | "vh" | "svh" | "lvh" | "dvh" | "vi" | "svi" | "lvi" | "dvi" | "vb" | "svb" | "lvb" | "dvb" | "vmin" | "svmin" | "lvmin" | "dvmin" | "vmax" | "svmax" | "lvmax" | "dvmax" | "cqw" | "cqh" | "cqi" | "cqb" | "cqmin" | "cqmax" | "dpi" | "dpcm" | "dppx" | "x" | "st" | "s" | "ms";
50
+ } | {
51
+ type: "keyword";
52
+ value: string;
53
+ } | {
54
+ type: "unparsed";
55
+ value: string;
56
+ hidden?: boolean | undefined;
57
+ } | {
58
+ type: "rgb";
59
+ r: number;
60
+ g: number;
61
+ b: number;
62
+ alpha: number;
63
+ })[];
64
+ hidden?: boolean | undefined;
65
+ } | {
66
+ type: "layers";
67
+ value: ({
68
+ type: "unit";
69
+ value: number;
70
+ unit: "number" | "%" | "deg" | "grad" | "rad" | "turn" | "db" | "fr" | "hz" | "khz" | "cm" | "mm" | "q" | "in" | "pt" | "pc" | "px" | "em" | "rem" | "ex" | "rex" | "cap" | "rcap" | "ch" | "rch" | "ic" | "ric" | "lh" | "rlh" | "vw" | "svw" | "lvw" | "dvw" | "vh" | "svh" | "lvh" | "dvh" | "vi" | "svi" | "lvi" | "dvi" | "vb" | "svb" | "lvb" | "dvb" | "vmin" | "svmin" | "lvmin" | "dvmin" | "vmax" | "svmax" | "lvmax" | "dvmax" | "cqw" | "cqh" | "cqi" | "cqb" | "cqmin" | "cqmax" | "dpi" | "dpcm" | "dppx" | "x" | "st" | "s" | "ms";
71
+ } | {
72
+ type: "keyword";
73
+ value: string;
74
+ } | {
75
+ type: "unparsed";
76
+ value: string;
77
+ hidden?: boolean | undefined;
78
+ } | {
79
+ type: "image";
80
+ value: {
81
+ type: "asset";
82
+ value: string;
83
+ } | {
84
+ type: "url";
85
+ url: string;
86
+ };
87
+ hidden?: boolean | undefined;
88
+ } | {
89
+ type: "invalid";
90
+ value: string;
91
+ } | {
92
+ type: "tuple";
93
+ value: ({
94
+ type: "unit";
95
+ value: number;
96
+ unit: "number" | "%" | "deg" | "grad" | "rad" | "turn" | "db" | "fr" | "hz" | "khz" | "cm" | "mm" | "q" | "in" | "pt" | "pc" | "px" | "em" | "rem" | "ex" | "rex" | "cap" | "rcap" | "ch" | "rch" | "ic" | "ric" | "lh" | "rlh" | "vw" | "svw" | "lvw" | "dvw" | "vh" | "svh" | "lvh" | "dvh" | "vi" | "svi" | "lvi" | "dvi" | "vb" | "svb" | "lvb" | "dvb" | "vmin" | "svmin" | "lvmin" | "dvmin" | "vmax" | "svmax" | "lvmax" | "dvmax" | "cqw" | "cqh" | "cqi" | "cqb" | "cqmin" | "cqmax" | "dpi" | "dpcm" | "dppx" | "x" | "st" | "s" | "ms";
97
+ } | {
98
+ type: "keyword";
99
+ value: string;
100
+ } | {
101
+ type: "unparsed";
102
+ value: string;
103
+ hidden?: boolean | undefined;
104
+ } | {
105
+ type: "rgb";
106
+ r: number;
107
+ g: number;
108
+ b: number;
109
+ alpha: number;
110
+ })[];
111
+ hidden?: boolean | undefined;
112
+ })[];
113
+ } | {
114
+ type: "var";
115
+ value: string;
116
+ fallbacks: ({
117
+ type: "unit";
118
+ value: number;
119
+ unit: "number" | "%" | "deg" | "grad" | "rad" | "turn" | "db" | "fr" | "hz" | "khz" | "cm" | "mm" | "q" | "in" | "pt" | "pc" | "px" | "em" | "rem" | "ex" | "rex" | "cap" | "rcap" | "ch" | "rch" | "ic" | "ric" | "lh" | "rlh" | "vw" | "svw" | "lvw" | "dvw" | "vh" | "svh" | "lvh" | "dvh" | "vi" | "svi" | "lvi" | "dvi" | "vb" | "svb" | "lvb" | "dvb" | "vmin" | "svmin" | "lvmin" | "dvmin" | "vmax" | "svmax" | "lvmax" | "dvmax" | "cqw" | "cqh" | "cqi" | "cqb" | "cqmin" | "cqmax" | "dpi" | "dpcm" | "dppx" | "x" | "st" | "s" | "ms";
120
+ } | {
121
+ type: "keyword";
122
+ value: string;
123
+ } | {
124
+ type: "unparsed";
125
+ value: string;
126
+ hidden?: boolean | undefined;
127
+ } | {
128
+ type: "fontFamily";
129
+ value: string[];
130
+ } | {
131
+ type: "rgb";
132
+ r: number;
133
+ g: number;
134
+ b: number;
135
+ alpha: number;
136
+ } | {
137
+ type: "image";
138
+ value: {
139
+ type: "asset";
140
+ value: string;
141
+ } | {
142
+ type: "url";
143
+ url: string;
144
+ };
145
+ hidden?: boolean | undefined;
146
+ } | {
147
+ type: "tuple";
148
+ value: ({
149
+ type: "unit";
150
+ value: number;
151
+ unit: "number" | "%" | "deg" | "grad" | "rad" | "turn" | "db" | "fr" | "hz" | "khz" | "cm" | "mm" | "q" | "in" | "pt" | "pc" | "px" | "em" | "rem" | "ex" | "rex" | "cap" | "rcap" | "ch" | "rch" | "ic" | "ric" | "lh" | "rlh" | "vw" | "svw" | "lvw" | "dvw" | "vh" | "svh" | "lvh" | "dvh" | "vi" | "svi" | "lvi" | "dvi" | "vb" | "svb" | "lvb" | "dvb" | "vmin" | "svmin" | "lvmin" | "dvmin" | "vmax" | "svmax" | "lvmax" | "dvmax" | "cqw" | "cqh" | "cqi" | "cqb" | "cqmin" | "cqmax" | "dpi" | "dpcm" | "dppx" | "x" | "st" | "s" | "ms";
152
+ } | {
153
+ type: "keyword";
154
+ value: string;
155
+ } | {
156
+ type: "unparsed";
157
+ value: string;
158
+ hidden?: boolean | undefined;
159
+ } | {
160
+ type: "rgb";
161
+ r: number;
162
+ g: number;
163
+ b: number;
164
+ alpha: number;
165
+ })[];
166
+ hidden?: boolean | undefined;
167
+ } | {
168
+ type: "layers";
169
+ value: ({
170
+ type: "unit";
171
+ value: number;
172
+ unit: "number" | "%" | "deg" | "grad" | "rad" | "turn" | "db" | "fr" | "hz" | "khz" | "cm" | "mm" | "q" | "in" | "pt" | "pc" | "px" | "em" | "rem" | "ex" | "rex" | "cap" | "rcap" | "ch" | "rch" | "ic" | "ric" | "lh" | "rlh" | "vw" | "svw" | "lvw" | "dvw" | "vh" | "svh" | "lvh" | "dvh" | "vi" | "svi" | "lvi" | "dvi" | "vb" | "svb" | "lvb" | "dvb" | "vmin" | "svmin" | "lvmin" | "dvmin" | "vmax" | "svmax" | "lvmax" | "dvmax" | "cqw" | "cqh" | "cqi" | "cqb" | "cqmin" | "cqmax" | "dpi" | "dpcm" | "dppx" | "x" | "st" | "s" | "ms";
173
+ } | {
174
+ type: "keyword";
175
+ value: string;
176
+ } | {
177
+ type: "unparsed";
178
+ value: string;
179
+ hidden?: boolean | undefined;
180
+ } | {
181
+ type: "image";
182
+ value: {
183
+ type: "asset";
184
+ value: string;
185
+ } | {
186
+ type: "url";
187
+ url: string;
188
+ };
189
+ hidden?: boolean | undefined;
190
+ } | {
191
+ type: "invalid";
192
+ value: string;
193
+ } | {
194
+ type: "tuple";
195
+ value: ({
196
+ type: "unit";
197
+ value: number;
198
+ unit: "number" | "%" | "deg" | "grad" | "rad" | "turn" | "db" | "fr" | "hz" | "khz" | "cm" | "mm" | "q" | "in" | "pt" | "pc" | "px" | "em" | "rem" | "ex" | "rex" | "cap" | "rcap" | "ch" | "rch" | "ic" | "ric" | "lh" | "rlh" | "vw" | "svw" | "lvw" | "dvw" | "vh" | "svh" | "lvh" | "dvh" | "vi" | "svi" | "lvi" | "dvi" | "vb" | "svb" | "lvb" | "dvb" | "vmin" | "svmin" | "lvmin" | "dvmin" | "vmax" | "svmax" | "lvmax" | "dvmax" | "cqw" | "cqh" | "cqi" | "cqb" | "cqmin" | "cqmax" | "dpi" | "dpcm" | "dppx" | "x" | "st" | "s" | "ms";
199
+ } | {
200
+ type: "keyword";
201
+ value: string;
202
+ } | {
203
+ type: "unparsed";
204
+ value: string;
205
+ hidden?: boolean | undefined;
206
+ } | {
207
+ type: "rgb";
208
+ r: number;
209
+ g: number;
210
+ b: number;
211
+ alpha: number;
212
+ })[];
213
+ hidden?: boolean | undefined;
214
+ })[];
215
+ })[];
216
+ } | undefined;
9
217
  has(property: StyleProperty): boolean;
10
218
  get size(): number;
11
219
  keys(): IterableIterator<StyleProperty>;
@@ -16,11 +224,9 @@ declare class StylePropertyMap {
16
224
  }): string;
17
225
  }
18
226
  export declare class StyleRule {
19
- #private;
20
227
  styleMap: StylePropertyMap;
21
228
  selectorText: string;
22
- onChange?: () => void;
23
- constructor(selectorText: string, style: Style, transformValue?: TransformValue);
229
+ constructor(selectorText: string, style: StylePropertyMap | Style, transformValue?: TransformValue, onChange?: () => void);
24
230
  get cssText(): string;
25
231
  toString(options?: {
26
232
  indent: number;
@@ -34,7 +240,7 @@ export type MediaRuleOptions = {
34
240
  export declare class MediaRule {
35
241
  #private;
36
242
  options: MediaRuleOptions;
37
- rules: Array<StyleRule | PlaintextRule>;
243
+ rules: Map<string, StyleRule | PlaintextRule>;
38
244
  constructor(options?: MediaRuleOptions);
39
245
  insertRule(rule: StyleRule | PlaintextRule): StyleRule | PlaintextRule;
40
246
  get cssText(): string;
@@ -60,4 +266,3 @@ export declare class FontFaceRule {
60
266
  toString(): string;
61
267
  }
62
268
  export type AnyRule = StyleRule | MediaRule | PlaintextRule | FontFaceRule;
63
- export {};
@@ -0,0 +1,10 @@
1
+ import { StyleRule } from "./rules";
2
+ import type { TransformValue } from "./to-value";
3
+ import { StyleSheet, type CssRule } from "./style-sheet";
4
+ export declare class StyleSheetAtomic extends StyleSheet {
5
+ #private;
6
+ addStyleRule({ style, breakpoint }: CssRule, selectorSuffix?: string, transformValue?: TransformValue): {
7
+ styleRules: StyleRule[];
8
+ classes: string[];
9
+ };
10
+ }
@@ -0,0 +1,7 @@
1
+ import { StyleRule } from "./rules";
2
+ import type { TransformValue } from "./to-value";
3
+ import { StyleSheet, type CssRule } from "./style-sheet";
4
+ export declare class StyleSheetRegular extends StyleSheet {
5
+ #private;
6
+ addStyleRule(rule: CssRule, selectorText: string, transformValue?: TransformValue): StyleRule;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,21 @@
1
- import type { StyleElement } from "./style-element";
1
+ import type { Style } from "../schema";
2
+ import { MediaRule, PlaintextRule, type FontFaceOptions, type MediaRuleOptions } from "./rules";
3
+ import { StyleElement } from "./style-element";
4
+ export type CssRule = {
5
+ style: Style;
6
+ breakpoint?: string;
7
+ };
2
8
  export declare class StyleSheet {
3
9
  #private;
4
10
  constructor(element: StyleElement);
5
- replaceSync(cssText: string): void;
11
+ addMediaRule(id: string, options?: MediaRuleOptions): MediaRule;
12
+ addPlaintextRule(cssText: string): PlaintextRule | Map<string, PlaintextRule>;
13
+ addFontFaceRule(options: FontFaceOptions): number;
14
+ markAsDirty(): void;
15
+ get cssText(): string;
16
+ clear(): void;
17
+ render(): void;
18
+ unmount(): void;
19
+ setAttribute(name: string, value: string): void;
20
+ getAttribute(name: string): string | null | undefined;
6
21
  }
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@webstudio-is/css-engine",
3
- "version": "0.123.0",
3
+ "version": "0.124.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
+ "@emotion/hash": "^0.9.1",
9
10
  "hyphenate-style-name": "^1.0.4",
10
- "@webstudio-is/error-utils": "0.123.0",
11
- "@webstudio-is/fonts": "0.123.0"
11
+ "@webstudio-is/error-utils": "0.124.0",
12
+ "@webstudio-is/fonts": "0.124.0"
12
13
  },
13
14
  "devDependencies": {
14
15
  "@jest/globals": "^29.7.0",
@@ -19,8 +20,8 @@
19
20
  "react-dom": "^18.2.0",
20
21
  "typescript": "5.2.2",
21
22
  "@webstudio-is/jest-config": "1.0.7",
22
- "@webstudio-is/tsconfig": "1.0.7",
23
- "@webstudio-is/storybook-config": "0.0.0"
23
+ "@webstudio-is/storybook-config": "0.0.0",
24
+ "@webstudio-is/tsconfig": "1.0.7"
24
25
  },
25
26
  "exports": {
26
27
  "webstudio": "./src/index.ts",
@@ -1,2 +0,0 @@
1
- import { CssEngine, type CssEngineOptions } from "./css-engine";
2
- export declare const createCssEngine: (options?: CssEngineOptions) => CssEngine;
@@ -1,25 +0,0 @@
1
- import type { Style } from "../schema";
2
- import { MediaRule, PlaintextRule, StyleRule, type FontFaceOptions, type MediaRuleOptions } from "./rules";
3
- import type { TransformValue } from "./to-value";
4
- type CssRule = {
5
- style: Style;
6
- breakpoint?: string;
7
- };
8
- export type CssEngineOptions = {
9
- name?: string;
10
- };
11
- export declare class CssEngine {
12
- #private;
13
- constructor({ name }: CssEngineOptions);
14
- addMediaRule(id: string, options?: MediaRuleOptions): MediaRule;
15
- addStyleRule(selectorText: string, rule: CssRule, transformValue?: TransformValue): StyleRule;
16
- addPlaintextRule(cssText: string): PlaintextRule | Map<string, PlaintextRule>;
17
- addFontFaceRule(options: FontFaceOptions): number;
18
- clear(): void;
19
- render(): void;
20
- unmount(): void;
21
- setAttribute(name: string, value: string): void;
22
- getAttribute(name: string): string | null | undefined;
23
- get cssText(): string;
24
- }
25
- export {};