@webstudio-is/css-engine 0.81.0 → 0.83.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.
@@ -16,24 +16,6 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var __accessCheck = (obj, member, msg) => {
20
- if (!member.has(obj))
21
- throw TypeError("Cannot " + msg);
22
- };
23
- var __privateGet = (obj, member, getter) => {
24
- __accessCheck(obj, member, "read from private field");
25
- return getter ? getter.call(obj) : member.get(obj);
26
- };
27
- var __privateAdd = (obj, member, value) => {
28
- if (member.has(obj))
29
- throw TypeError("Cannot add the same private member more than once");
30
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
31
- };
32
- var __privateSet = (obj, member, value, setter) => {
33
- __accessCheck(obj, member, "write to private field");
34
- setter ? setter.call(obj, value) : member.set(obj, value);
35
- return value;
36
- };
37
19
  var css_engine_exports = {};
38
20
  __export(css_engine_exports, {
39
21
  CssEngine: () => CssEngine
@@ -43,42 +25,38 @@ var import_rules = require("./rules");
43
25
  var import_compare_media = require("./compare-media");
44
26
  var import_style_element = require("./style-element");
45
27
  var import_style_sheet = require("./style-sheet");
46
- var _element, _mediaRules, _plainRules, _fontFaceRules, _sheet, _isDirty, _cssText, _onChangeRule;
47
28
  const defaultMediaRuleId = "__default-media-rule__";
48
29
  class CssEngine {
30
+ #element;
31
+ #mediaRules = /* @__PURE__ */ new Map();
32
+ #plainRules = /* @__PURE__ */ new Map();
33
+ #fontFaceRules = [];
34
+ #sheet;
35
+ #isDirty = false;
36
+ #cssText = "";
49
37
  constructor({ name }) {
50
- __privateAdd(this, _element, void 0);
51
- __privateAdd(this, _mediaRules, /* @__PURE__ */ new Map());
52
- __privateAdd(this, _plainRules, /* @__PURE__ */ new Map());
53
- __privateAdd(this, _fontFaceRules, []);
54
- __privateAdd(this, _sheet, void 0);
55
- __privateAdd(this, _isDirty, false);
56
- __privateAdd(this, _cssText, "");
57
- __privateAdd(this, _onChangeRule, () => {
58
- __privateSet(this, _isDirty, true);
59
- });
60
- __privateSet(this, _element, new import_style_element.StyleElement(name));
61
- __privateSet(this, _sheet, new import_style_sheet.StyleSheet(__privateGet(this, _element)));
38
+ this.#element = new import_style_element.StyleElement(name);
39
+ this.#sheet = new import_style_sheet.StyleSheet(this.#element);
62
40
  }
63
41
  addMediaRule(id, options) {
64
- let mediaRule = __privateGet(this, _mediaRules).get(id);
42
+ let mediaRule = this.#mediaRules.get(id);
65
43
  if (mediaRule === void 0) {
66
44
  mediaRule = new import_rules.MediaRule(options);
67
- __privateGet(this, _mediaRules).set(id, mediaRule);
68
- __privateSet(this, _isDirty, true);
45
+ this.#mediaRules.set(id, mediaRule);
46
+ this.#isDirty = true;
69
47
  return mediaRule;
70
48
  }
71
49
  if (options) {
72
50
  mediaRule.options = options;
73
- __privateSet(this, _isDirty, true);
51
+ this.#isDirty = true;
74
52
  }
75
53
  return mediaRule;
76
54
  }
77
55
  addStyleRule(selectorText, rule, transformValue) {
78
56
  const mediaRule = this.addMediaRule(rule.breakpoint || defaultMediaRuleId);
79
- __privateSet(this, _isDirty, true);
57
+ this.#isDirty = true;
80
58
  const styleRule = new import_rules.StyleRule(selectorText, rule.style, transformValue);
81
- styleRule.onChange = __privateGet(this, _onChangeRule);
59
+ styleRule.onChange = this.#onChangeRule;
82
60
  if (mediaRule === void 0) {
83
61
  throw new Error("No media rule found");
84
62
  }
@@ -86,47 +64,47 @@ class CssEngine {
86
64
  return styleRule;
87
65
  }
88
66
  addPlaintextRule(cssText) {
89
- const rule = __privateGet(this, _plainRules).get(cssText);
67
+ const rule = this.#plainRules.get(cssText);
90
68
  if (rule !== void 0) {
91
69
  return rule;
92
70
  }
93
- __privateSet(this, _isDirty, true);
94
- return __privateGet(this, _plainRules).set(cssText, new import_rules.PlaintextRule(cssText));
71
+ this.#isDirty = true;
72
+ return this.#plainRules.set(cssText, new import_rules.PlaintextRule(cssText));
95
73
  }
96
74
  addFontFaceRule(options) {
97
- __privateSet(this, _isDirty, true);
98
- return __privateGet(this, _fontFaceRules).push(new import_rules.FontFaceRule(options));
75
+ this.#isDirty = true;
76
+ return this.#fontFaceRules.push(new import_rules.FontFaceRule(options));
99
77
  }
100
78
  clear() {
101
- __privateGet(this, _mediaRules).clear();
102
- __privateGet(this, _plainRules).clear();
103
- __privateSet(this, _fontFaceRules, []);
104
- __privateSet(this, _isDirty, true);
79
+ this.#mediaRules.clear();
80
+ this.#plainRules.clear();
81
+ this.#fontFaceRules = [];
82
+ this.#isDirty = true;
105
83
  }
106
84
  render() {
107
- __privateGet(this, _element).mount();
108
- __privateGet(this, _sheet).replaceSync(this.cssText);
85
+ this.#element.mount();
86
+ this.#sheet.replaceSync(this.cssText);
109
87
  }
110
88
  unmount() {
111
- __privateGet(this, _element).unmount();
89
+ this.#element.unmount();
112
90
  }
113
91
  setAttribute(name, value) {
114
- __privateGet(this, _element).setAttribute(name, value);
92
+ this.#element.setAttribute(name, value);
115
93
  }
116
94
  getAttribute(name) {
117
- return __privateGet(this, _element).getAttribute(name);
95
+ return this.#element.getAttribute(name);
118
96
  }
119
97
  get cssText() {
120
- if (__privateGet(this, _isDirty) === false) {
121
- return __privateGet(this, _cssText);
98
+ if (this.#isDirty === false) {
99
+ return this.#cssText;
122
100
  }
123
- __privateSet(this, _isDirty, false);
101
+ this.#isDirty = false;
124
102
  const css = [];
125
- css.push(...__privateGet(this, _fontFaceRules).map((rule) => rule.cssText));
126
- for (const plaintextRule of __privateGet(this, _plainRules).values()) {
103
+ css.push(...this.#fontFaceRules.map((rule) => rule.cssText));
104
+ for (const plaintextRule of this.#plainRules.values()) {
127
105
  css.push(plaintextRule.cssText);
128
106
  }
129
- const sortedMediaRules = Array.from(__privateGet(this, _mediaRules).values()).sort(
107
+ const sortedMediaRules = Array.from(this.#mediaRules.values()).sort(
130
108
  (ruleA, ruleB) => (0, import_compare_media.compareMedia)(ruleA.options, ruleB.options)
131
109
  );
132
110
  for (const mediaRule of sortedMediaRules) {
@@ -135,15 +113,10 @@ class CssEngine {
135
113
  css.push(cssText);
136
114
  }
137
115
  }
138
- __privateSet(this, _cssText, css.join("\n"));
139
- return __privateGet(this, _cssText);
116
+ this.#cssText = css.join("\n");
117
+ return this.#cssText;
140
118
  }
119
+ #onChangeRule = () => {
120
+ this.#isDirty = true;
121
+ };
141
122
  }
142
- _element = new WeakMap();
143
- _mediaRules = new WeakMap();
144
- _plainRules = new WeakMap();
145
- _fontFaceRules = new WeakMap();
146
- _sheet = new WeakMap();
147
- _isDirty = new WeakMap();
148
- _cssText = new WeakMap();
149
- _onChangeRule = new WeakMap();
@@ -16,24 +16,6 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var __accessCheck = (obj, member, msg) => {
20
- if (!member.has(obj))
21
- throw TypeError("Cannot " + msg);
22
- };
23
- var __privateGet = (obj, member, getter) => {
24
- __accessCheck(obj, member, "read from private field");
25
- return getter ? getter.call(obj) : member.get(obj);
26
- };
27
- var __privateAdd = (obj, member, value) => {
28
- if (member.has(obj))
29
- throw TypeError("Cannot add the same private member more than once");
30
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
31
- };
32
- var __privateSet = (obj, member, value, setter) => {
33
- __accessCheck(obj, member, "write to private field");
34
- setter ? setter.call(obj, value) : member.set(obj, value);
35
- return value;
36
- };
37
19
  var rules_exports = {};
38
20
  __export(rules_exports, {
39
21
  FontFaceRule: () => FontFaceRule,
@@ -44,81 +26,82 @@ __export(rules_exports, {
44
26
  module.exports = __toCommonJS(rules_exports);
45
27
  var import_to_value = require("./to-value");
46
28
  var import_to_property = require("./to-property");
47
- var _styleMap, _isDirty, _string, _indent, _transformValue, _onChange, _mediaType;
48
29
  class StylePropertyMap {
30
+ #styleMap = /* @__PURE__ */ new Map();
31
+ #isDirty = false;
32
+ #string = "";
33
+ #indent = 0;
34
+ #transformValue;
35
+ onChange;
49
36
  constructor(transformValue) {
50
- __privateAdd(this, _styleMap, /* @__PURE__ */ new Map());
51
- __privateAdd(this, _isDirty, false);
52
- __privateAdd(this, _string, "");
53
- __privateAdd(this, _indent, 0);
54
- __privateAdd(this, _transformValue, void 0);
55
- __privateSet(this, _transformValue, transformValue);
37
+ this.#transformValue = transformValue;
56
38
  }
57
39
  setTransformer(transformValue) {
58
- __privateSet(this, _transformValue, transformValue);
40
+ this.#transformValue = transformValue;
59
41
  }
60
42
  set(property, value) {
61
- __privateGet(this, _styleMap).set(property, value);
62
- __privateSet(this, _isDirty, true);
43
+ this.#styleMap.set(property, value);
44
+ this.#isDirty = true;
63
45
  this.onChange?.();
64
46
  }
65
47
  has(property) {
66
- return __privateGet(this, _styleMap).has(property);
48
+ return this.#styleMap.has(property);
49
+ }
50
+ get size() {
51
+ return this.#styleMap.size;
67
52
  }
68
53
  keys() {
69
- return __privateGet(this, _styleMap).keys();
54
+ return this.#styleMap.keys();
70
55
  }
71
56
  delete(property) {
72
- __privateGet(this, _styleMap).delete(property);
73
- __privateSet(this, _isDirty, true);
57
+ this.#styleMap.delete(property);
58
+ this.#isDirty = true;
74
59
  this.onChange?.();
75
60
  }
76
61
  clear() {
77
- __privateGet(this, _styleMap).clear();
78
- __privateSet(this, _isDirty, true);
62
+ this.#styleMap.clear();
63
+ this.#isDirty = true;
79
64
  this.onChange?.();
80
65
  }
81
66
  toString({ indent = 0 } = {}) {
82
- if (__privateGet(this, _isDirty) === false && indent === __privateGet(this, _indent)) {
83
- return __privateGet(this, _string);
67
+ if (this.#isDirty === false && indent === this.#indent) {
68
+ return this.#string;
84
69
  }
85
- __privateSet(this, _indent, indent);
70
+ this.#indent = indent;
86
71
  const block = [];
87
72
  const spaces = " ".repeat(indent);
88
- for (const [property, value] of __privateGet(this, _styleMap)) {
73
+ for (const [property, value] of this.#styleMap) {
89
74
  if (value === void 0) {
90
75
  continue;
91
76
  }
92
77
  block.push(
93
78
  `${spaces}${(0, import_to_property.toProperty)(property)}: ${(0, import_to_value.toValue)(
94
79
  value,
95
- __privateGet(this, _transformValue)
80
+ this.#transformValue
96
81
  )}`
97
82
  );
98
83
  }
99
- __privateSet(this, _string, block.join(";\n"));
100
- __privateSet(this, _isDirty, false);
101
- return __privateGet(this, _string);
84
+ this.#string = block.join(";\n");
85
+ this.#isDirty = false;
86
+ return this.#string;
102
87
  }
103
88
  }
104
- _styleMap = new WeakMap();
105
- _isDirty = new WeakMap();
106
- _string = new WeakMap();
107
- _indent = new WeakMap();
108
- _transformValue = new WeakMap();
109
89
  class StyleRule {
90
+ styleMap;
91
+ selectorText;
92
+ onChange;
110
93
  constructor(selectorText, style, transformValue) {
111
- __privateAdd(this, _onChange, () => {
112
- this.onChange?.();
113
- });
114
94
  this.styleMap = new StylePropertyMap(transformValue);
115
95
  this.selectorText = selectorText;
116
96
  let property;
117
97
  for (property in style) {
118
98
  this.styleMap.set(property, style[property]);
119
99
  }
120
- this.styleMap.onChange = __privateGet(this, _onChange);
100
+ this.styleMap.onChange = this.#onChange;
121
101
  }
102
+ #onChange = () => {
103
+ this.onChange?.();
104
+ };
122
105
  get cssText() {
123
106
  return this.toString();
124
107
  }
@@ -131,13 +114,13 @@ ${this.styleMap.toString({
131
114
  ${spaces}}`;
132
115
  }
133
116
  }
134
- _onChange = new WeakMap();
135
117
  class MediaRule {
118
+ options;
119
+ rules = [];
120
+ #mediaType;
136
121
  constructor(options = {}) {
137
- this.rules = [];
138
- __privateAdd(this, _mediaType, void 0);
139
122
  this.options = options;
140
- __privateSet(this, _mediaType, options.mediaType ?? "all");
123
+ this.#mediaType = options.mediaType ?? "all";
141
124
  }
142
125
  insertRule(rule) {
143
126
  this.rules.push(rule);
@@ -162,17 +145,17 @@ class MediaRule {
162
145
  if (maxWidth !== void 0) {
163
146
  conditionText += ` and (max-width: ${maxWidth}px)`;
164
147
  }
165
- return `@media ${__privateGet(this, _mediaType)}${conditionText} {
148
+ return `@media ${this.#mediaType}${conditionText} {
166
149
  ${rules.join(
167
150
  "\n"
168
151
  )}
169
152
  }`;
170
153
  }
171
154
  }
172
- _mediaType = new WeakMap();
173
155
  class PlaintextRule {
156
+ cssText;
157
+ styleMap = new StylePropertyMap();
174
158
  constructor(cssText) {
175
- this.styleMap = new StylePropertyMap();
176
159
  this.cssText = cssText;
177
160
  }
178
161
  toString() {
@@ -180,6 +163,7 @@ class PlaintextRule {
180
163
  }
181
164
  }
182
165
  class FontFaceRule {
166
+ options;
183
167
  constructor(options) {
184
168
  this.options = options;
185
169
  }
@@ -16,67 +16,46 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var __accessCheck = (obj, member, msg) => {
20
- if (!member.has(obj))
21
- throw TypeError("Cannot " + msg);
22
- };
23
- var __privateGet = (obj, member, getter) => {
24
- __accessCheck(obj, member, "read from private field");
25
- return getter ? getter.call(obj) : member.get(obj);
26
- };
27
- var __privateAdd = (obj, member, value) => {
28
- if (member.has(obj))
29
- throw TypeError("Cannot add the same private member more than once");
30
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
31
- };
32
- var __privateSet = (obj, member, value, setter) => {
33
- __accessCheck(obj, member, "write to private field");
34
- setter ? setter.call(obj, value) : member.set(obj, value);
35
- return value;
36
- };
37
19
  var style_element_exports = {};
38
20
  __export(style_element_exports, {
39
21
  StyleElement: () => StyleElement
40
22
  });
41
23
  module.exports = __toCommonJS(style_element_exports);
42
- var _element, _name;
43
24
  class StyleElement {
25
+ #element;
26
+ #name;
44
27
  constructor(name = "") {
45
- __privateAdd(this, _element, void 0);
46
- __privateAdd(this, _name, void 0);
47
- __privateSet(this, _name, name);
28
+ this.#name = name;
48
29
  }
49
30
  get isMounted() {
50
- return __privateGet(this, _element)?.parentElement != null;
31
+ return this.#element?.parentElement != null;
51
32
  }
52
33
  mount() {
53
34
  if (this.isMounted === false) {
54
- __privateSet(this, _element, document.createElement("style"));
55
- __privateGet(this, _element).setAttribute("data-webstudio", __privateGet(this, _name));
56
- document.head.appendChild(__privateGet(this, _element));
35
+ this.#element = document.createElement("style");
36
+ this.#element.setAttribute("data-webstudio", this.#name);
37
+ document.head.appendChild(this.#element);
57
38
  }
58
39
  }
59
40
  unmount() {
60
41
  if (this.isMounted) {
61
- __privateGet(this, _element)?.parentElement?.removeChild(__privateGet(this, _element));
62
- __privateSet(this, _element, void 0);
42
+ this.#element?.parentElement?.removeChild(this.#element);
43
+ this.#element = void 0;
63
44
  }
64
45
  }
65
46
  render(cssText) {
66
- if (__privateGet(this, _element)) {
67
- __privateGet(this, _element).textContent = cssText;
47
+ if (this.#element) {
48
+ this.#element.textContent = cssText;
68
49
  }
69
50
  }
70
51
  setAttribute(name, value) {
71
- if (__privateGet(this, _element)) {
72
- __privateGet(this, _element).setAttribute(name, value);
52
+ if (this.#element) {
53
+ this.#element.setAttribute(name, value);
73
54
  }
74
55
  }
75
56
  getAttribute(name) {
76
- if (__privateGet(this, _element)) {
77
- return __privateGet(this, _element).getAttribute(name);
57
+ if (this.#element) {
58
+ return this.#element.getAttribute(name);
78
59
  }
79
60
  }
80
61
  }
81
- _element = new WeakMap();
82
- _name = new WeakMap();
@@ -16,42 +16,21 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var __accessCheck = (obj, member, msg) => {
20
- if (!member.has(obj))
21
- throw TypeError("Cannot " + msg);
22
- };
23
- var __privateGet = (obj, member, getter) => {
24
- __accessCheck(obj, member, "read from private field");
25
- return getter ? getter.call(obj) : member.get(obj);
26
- };
27
- var __privateAdd = (obj, member, value) => {
28
- if (member.has(obj))
29
- throw TypeError("Cannot add the same private member more than once");
30
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
31
- };
32
- var __privateSet = (obj, member, value, setter) => {
33
- __accessCheck(obj, member, "write to private field");
34
- setter ? setter.call(obj, value) : member.set(obj, value);
35
- return value;
36
- };
37
19
  var style_sheet_exports = {};
38
20
  __export(style_sheet_exports, {
39
21
  StyleSheet: () => StyleSheet
40
22
  });
41
23
  module.exports = __toCommonJS(style_sheet_exports);
42
- var _cssText, _element;
43
24
  class StyleSheet {
25
+ #cssText = "";
26
+ #element;
44
27
  constructor(element) {
45
- __privateAdd(this, _cssText, "");
46
- __privateAdd(this, _element, void 0);
47
- __privateSet(this, _element, element);
28
+ this.#element = element;
48
29
  }
49
30
  replaceSync(cssText) {
50
- if (cssText !== __privateGet(this, _cssText)) {
51
- __privateSet(this, _cssText, cssText);
52
- __privateGet(this, _element).render(cssText);
31
+ if (cssText !== this.#cssText) {
32
+ this.#cssText = cssText;
33
+ this.#element.render(cssText);
53
34
  }
54
35
  }
55
36
  }
56
- _cssText = new WeakMap();
57
- _element = new WeakMap();
@@ -21,10 +21,8 @@ __export(to_value_exports, {
21
21
  toValue: () => toValue
22
22
  });
23
23
  module.exports = __toCommonJS(to_value_exports);
24
+ var import_error_utils = require("@webstudio-is/error-utils");
24
25
  var import_fonts = require("@webstudio-is/fonts");
25
- const assertUnreachable = (_arg, errorMessage) => {
26
- throw new Error(errorMessage);
27
- };
28
26
  const fallbackTransform = (styleValue) => {
29
27
  if (styleValue.type === "fontFamily") {
30
28
  const firstFontFamily = styleValue.value[0];
@@ -96,6 +94,5 @@ const toValue = (styleValue, transformValue) => {
96
94
  if (value.type === "tuple") {
97
95
  return value.value.map((value2) => toValue(value2, transformValue)).join(" ");
98
96
  }
99
- assertUnreachable(value, `Unknown value type`);
100
- throw new Error("Unknown value type");
97
+ return (0, import_error_utils.captureError)(new Error("Unknown value type"), value);
101
98
  };
@@ -1,22 +1,3 @@
1
- var __accessCheck = (obj, member, msg) => {
2
- if (!member.has(obj))
3
- throw TypeError("Cannot " + msg);
4
- };
5
- var __privateGet = (obj, member, getter) => {
6
- __accessCheck(obj, member, "read from private field");
7
- return getter ? getter.call(obj) : member.get(obj);
8
- };
9
- var __privateAdd = (obj, member, value) => {
10
- if (member.has(obj))
11
- throw TypeError("Cannot add the same private member more than once");
12
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
- };
14
- var __privateSet = (obj, member, value, setter) => {
15
- __accessCheck(obj, member, "write to private field");
16
- setter ? setter.call(obj, value) : member.set(obj, value);
17
- return value;
18
- };
19
- var _element, _mediaRules, _plainRules, _fontFaceRules, _sheet, _isDirty, _cssText, _onChangeRule;
20
1
  import {
21
2
  FontFaceRule,
22
3
  MediaRule,
@@ -28,39 +9,36 @@ import { StyleElement } from "./style-element";
28
9
  import { StyleSheet } from "./style-sheet";
29
10
  const defaultMediaRuleId = "__default-media-rule__";
30
11
  class CssEngine {
12
+ #element;
13
+ #mediaRules = /* @__PURE__ */ new Map();
14
+ #plainRules = /* @__PURE__ */ new Map();
15
+ #fontFaceRules = [];
16
+ #sheet;
17
+ #isDirty = false;
18
+ #cssText = "";
31
19
  constructor({ name }) {
32
- __privateAdd(this, _element, void 0);
33
- __privateAdd(this, _mediaRules, /* @__PURE__ */ new Map());
34
- __privateAdd(this, _plainRules, /* @__PURE__ */ new Map());
35
- __privateAdd(this, _fontFaceRules, []);
36
- __privateAdd(this, _sheet, void 0);
37
- __privateAdd(this, _isDirty, false);
38
- __privateAdd(this, _cssText, "");
39
- __privateAdd(this, _onChangeRule, () => {
40
- __privateSet(this, _isDirty, true);
41
- });
42
- __privateSet(this, _element, new StyleElement(name));
43
- __privateSet(this, _sheet, new StyleSheet(__privateGet(this, _element)));
20
+ this.#element = new StyleElement(name);
21
+ this.#sheet = new StyleSheet(this.#element);
44
22
  }
45
23
  addMediaRule(id, options) {
46
- let mediaRule = __privateGet(this, _mediaRules).get(id);
24
+ let mediaRule = this.#mediaRules.get(id);
47
25
  if (mediaRule === void 0) {
48
26
  mediaRule = new MediaRule(options);
49
- __privateGet(this, _mediaRules).set(id, mediaRule);
50
- __privateSet(this, _isDirty, true);
27
+ this.#mediaRules.set(id, mediaRule);
28
+ this.#isDirty = true;
51
29
  return mediaRule;
52
30
  }
53
31
  if (options) {
54
32
  mediaRule.options = options;
55
- __privateSet(this, _isDirty, true);
33
+ this.#isDirty = true;
56
34
  }
57
35
  return mediaRule;
58
36
  }
59
37
  addStyleRule(selectorText, rule, transformValue) {
60
38
  const mediaRule = this.addMediaRule(rule.breakpoint || defaultMediaRuleId);
61
- __privateSet(this, _isDirty, true);
39
+ this.#isDirty = true;
62
40
  const styleRule = new StyleRule(selectorText, rule.style, transformValue);
63
- styleRule.onChange = __privateGet(this, _onChangeRule);
41
+ styleRule.onChange = this.#onChangeRule;
64
42
  if (mediaRule === void 0) {
65
43
  throw new Error("No media rule found");
66
44
  }
@@ -68,47 +46,47 @@ class CssEngine {
68
46
  return styleRule;
69
47
  }
70
48
  addPlaintextRule(cssText) {
71
- const rule = __privateGet(this, _plainRules).get(cssText);
49
+ const rule = this.#plainRules.get(cssText);
72
50
  if (rule !== void 0) {
73
51
  return rule;
74
52
  }
75
- __privateSet(this, _isDirty, true);
76
- return __privateGet(this, _plainRules).set(cssText, new PlaintextRule(cssText));
53
+ this.#isDirty = true;
54
+ return this.#plainRules.set(cssText, new PlaintextRule(cssText));
77
55
  }
78
56
  addFontFaceRule(options) {
79
- __privateSet(this, _isDirty, true);
80
- return __privateGet(this, _fontFaceRules).push(new FontFaceRule(options));
57
+ this.#isDirty = true;
58
+ return this.#fontFaceRules.push(new FontFaceRule(options));
81
59
  }
82
60
  clear() {
83
- __privateGet(this, _mediaRules).clear();
84
- __privateGet(this, _plainRules).clear();
85
- __privateSet(this, _fontFaceRules, []);
86
- __privateSet(this, _isDirty, true);
61
+ this.#mediaRules.clear();
62
+ this.#plainRules.clear();
63
+ this.#fontFaceRules = [];
64
+ this.#isDirty = true;
87
65
  }
88
66
  render() {
89
- __privateGet(this, _element).mount();
90
- __privateGet(this, _sheet).replaceSync(this.cssText);
67
+ this.#element.mount();
68
+ this.#sheet.replaceSync(this.cssText);
91
69
  }
92
70
  unmount() {
93
- __privateGet(this, _element).unmount();
71
+ this.#element.unmount();
94
72
  }
95
73
  setAttribute(name, value) {
96
- __privateGet(this, _element).setAttribute(name, value);
74
+ this.#element.setAttribute(name, value);
97
75
  }
98
76
  getAttribute(name) {
99
- return __privateGet(this, _element).getAttribute(name);
77
+ return this.#element.getAttribute(name);
100
78
  }
101
79
  get cssText() {
102
- if (__privateGet(this, _isDirty) === false) {
103
- return __privateGet(this, _cssText);
80
+ if (this.#isDirty === false) {
81
+ return this.#cssText;
104
82
  }
105
- __privateSet(this, _isDirty, false);
83
+ this.#isDirty = false;
106
84
  const css = [];
107
- css.push(...__privateGet(this, _fontFaceRules).map((rule) => rule.cssText));
108
- for (const plaintextRule of __privateGet(this, _plainRules).values()) {
85
+ css.push(...this.#fontFaceRules.map((rule) => rule.cssText));
86
+ for (const plaintextRule of this.#plainRules.values()) {
109
87
  css.push(plaintextRule.cssText);
110
88
  }
111
- const sortedMediaRules = Array.from(__privateGet(this, _mediaRules).values()).sort(
89
+ const sortedMediaRules = Array.from(this.#mediaRules.values()).sort(
112
90
  (ruleA, ruleB) => compareMedia(ruleA.options, ruleB.options)
113
91
  );
114
92
  for (const mediaRule of sortedMediaRules) {
@@ -117,18 +95,13 @@ class CssEngine {
117
95
  css.push(cssText);
118
96
  }
119
97
  }
120
- __privateSet(this, _cssText, css.join("\n"));
121
- return __privateGet(this, _cssText);
98
+ this.#cssText = css.join("\n");
99
+ return this.#cssText;
122
100
  }
101
+ #onChangeRule = () => {
102
+ this.#isDirty = true;
103
+ };
123
104
  }
124
- _element = new WeakMap();
125
- _mediaRules = new WeakMap();
126
- _plainRules = new WeakMap();
127
- _fontFaceRules = new WeakMap();
128
- _sheet = new WeakMap();
129
- _isDirty = new WeakMap();
130
- _cssText = new WeakMap();
131
- _onChangeRule = new WeakMap();
132
105
  export {
133
106
  CssEngine
134
107
  };