@webstudio-is/css-engine 0.3.0 → 0.4.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.
Files changed (52) hide show
  1. package/lib/cjs/core/create-css-engine.cjs +27 -0
  2. package/lib/cjs/core/css-engine.cjs +134 -0
  3. package/lib/cjs/core/index.cjs +27 -0
  4. package/lib/cjs/core/rules.cjs +168 -0
  5. package/lib/cjs/core/style-element.cjs +69 -0
  6. package/lib/cjs/core/style-sheet.cjs +57 -0
  7. package/lib/cjs/core/to-value.cjs +55 -0
  8. package/lib/cjs/index.cjs +18 -0
  9. package/lib/core/create-css-engine.js +5 -2
  10. package/lib/core/css-engine.js +107 -85
  11. package/lib/core/index.js +4 -1
  12. package/lib/core/rules.js +125 -95
  13. package/lib/core/style-element.js +43 -33
  14. package/lib/core/style-sheet.js +33 -22
  15. package/lib/core/to-value.js +28 -24
  16. package/package.json +7 -14
  17. package/src/core/create-css-engine.ts +5 -0
  18. package/src/core/css-engine.stories.tsx +48 -0
  19. package/src/core/css-engine.test.ts +206 -0
  20. package/src/core/css-engine.ts +98 -0
  21. package/src/core/index.ts +10 -0
  22. package/src/core/rules.ts +132 -0
  23. package/src/core/style-element.ts +24 -0
  24. package/src/core/style-sheet.ts +15 -0
  25. package/src/core/to-value.test.ts +66 -0
  26. package/src/core/to-value.ts +43 -0
  27. package/src/index.ts +1 -0
  28. package/lib/core/create-css-engine.d.ts +0 -3
  29. package/lib/core/create-css-engine.d.ts.map +0 -1
  30. package/lib/core/css-engine.d.ts +0 -15
  31. package/lib/core/css-engine.d.ts.map +0 -1
  32. package/lib/core/css-engine.stories.d.ts +0 -7
  33. package/lib/core/css-engine.stories.d.ts.map +0 -1
  34. package/lib/core/css-engine.stories.js +0 -31
  35. package/lib/core/css-engine.test.d.ts +0 -2
  36. package/lib/core/css-engine.test.d.ts.map +0 -1
  37. package/lib/core/css-engine.test.js +0 -182
  38. package/lib/core/index.d.ts +0 -5
  39. package/lib/core/index.d.ts.map +0 -1
  40. package/lib/core/rules.d.ts +0 -48
  41. package/lib/core/rules.d.ts.map +0 -1
  42. package/lib/core/style-element.d.ts +0 -8
  43. package/lib/core/style-element.d.ts.map +0 -1
  44. package/lib/core/style-sheet.d.ts +0 -7
  45. package/lib/core/style-sheet.d.ts.map +0 -1
  46. package/lib/core/to-value.d.ts +0 -7
  47. package/lib/core/to-value.d.ts.map +0 -1
  48. package/lib/core/to-value.test.d.ts +0 -2
  49. package/lib/core/to-value.test.d.ts.map +0 -1
  50. package/lib/core/to-value.test.js +0 -55
  51. package/lib/index.d.ts +0 -2
  52. package/lib/index.d.ts.map +0 -1
@@ -1,97 +1,119 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
1
+ var __accessCheck = (obj, member, msg) => {
2
+ if (!member.has(obj))
3
+ throw TypeError("Cannot " + msg);
6
4
  };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ var __privateGet = (obj, member, getter) => {
6
+ __accessCheck(obj, member, "read from private field");
7
+ return getter ? getter.call(obj) : member.get(obj);
11
8
  };
12
- var _CssEngine_element, _CssEngine_mediaRules, _CssEngine_plainRules, _CssEngine_fontFaceRules, _CssEngine_sheet, _CssEngine_isDirty, _CssEngine_cssText, _CssEngine_onChangeRule;
13
- import { FontFaceRule, MediaRule, PlaintextRule, StyleRule, } from "./rules";
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
+ import {
21
+ FontFaceRule,
22
+ MediaRule,
23
+ PlaintextRule,
24
+ StyleRule
25
+ } from "./rules";
14
26
  import { StyleElement } from "./style-element";
15
27
  import { StyleSheet } from "./style-sheet";
16
28
  const defaultMediaRuleId = "__default-media-rule__";
17
- export class CssEngine {
18
- constructor() {
19
- _CssEngine_element.set(this, void 0);
20
- _CssEngine_mediaRules.set(this, new Map());
21
- _CssEngine_plainRules.set(this, new Map());
22
- _CssEngine_fontFaceRules.set(this, []);
23
- _CssEngine_sheet.set(this, void 0);
24
- _CssEngine_isDirty.set(this, false);
25
- _CssEngine_cssText.set(this, "");
26
- _CssEngine_onChangeRule.set(this, () => {
27
- __classPrivateFieldSet(this, _CssEngine_isDirty, true, "f");
28
- });
29
- __classPrivateFieldSet(this, _CssEngine_element, new StyleElement(), "f");
30
- __classPrivateFieldSet(this, _CssEngine_sheet, new StyleSheet(__classPrivateFieldGet(this, _CssEngine_element, "f")), "f");
31
- }
32
- addMediaRule(id, options) {
33
- let mediaRule = __classPrivateFieldGet(this, _CssEngine_mediaRules, "f").get(id);
34
- if (mediaRule === undefined) {
35
- mediaRule = new MediaRule(options);
36
- __classPrivateFieldGet(this, _CssEngine_mediaRules, "f").set(id, mediaRule);
37
- __classPrivateFieldSet(this, _CssEngine_isDirty, true, "f");
38
- }
39
- return mediaRule;
29
+ class CssEngine {
30
+ constructor() {
31
+ __privateAdd(this, _element, void 0);
32
+ __privateAdd(this, _mediaRules, /* @__PURE__ */ new Map());
33
+ __privateAdd(this, _plainRules, /* @__PURE__ */ new Map());
34
+ __privateAdd(this, _fontFaceRules, []);
35
+ __privateAdd(this, _sheet, void 0);
36
+ __privateAdd(this, _isDirty, false);
37
+ __privateAdd(this, _cssText, "");
38
+ __privateAdd(this, _onChangeRule, () => {
39
+ __privateSet(this, _isDirty, true);
40
+ });
41
+ __privateSet(this, _element, new StyleElement());
42
+ __privateSet(this, _sheet, new StyleSheet(__privateGet(this, _element)));
43
+ }
44
+ addMediaRule(id, options) {
45
+ let mediaRule = __privateGet(this, _mediaRules).get(id);
46
+ if (mediaRule === void 0) {
47
+ mediaRule = new MediaRule(options);
48
+ __privateGet(this, _mediaRules).set(id, mediaRule);
49
+ __privateSet(this, _isDirty, true);
40
50
  }
41
- addStyleRule(selectorText, rule) {
42
- const mediaRule = this.addMediaRule(rule.breakpoint || defaultMediaRuleId);
43
- __classPrivateFieldSet(this, _CssEngine_isDirty, true, "f");
44
- const styleRule = new StyleRule(selectorText, rule.style);
45
- styleRule.onChange = __classPrivateFieldGet(this, _CssEngine_onChangeRule, "f");
46
- if (mediaRule === undefined) {
47
- // Should be impossible to reach.
48
- throw new Error("No media rule found");
49
- }
50
- mediaRule.insertRule(styleRule);
51
- return styleRule;
51
+ return mediaRule;
52
+ }
53
+ addStyleRule(selectorText, rule) {
54
+ const mediaRule = this.addMediaRule(rule.breakpoint || defaultMediaRuleId);
55
+ __privateSet(this, _isDirty, true);
56
+ const styleRule = new StyleRule(selectorText, rule.style);
57
+ styleRule.onChange = __privateGet(this, _onChangeRule);
58
+ if (mediaRule === void 0) {
59
+ throw new Error("No media rule found");
52
60
  }
53
- addPlaintextRule(cssText) {
54
- const rule = __classPrivateFieldGet(this, _CssEngine_plainRules, "f").get(cssText);
55
- if (rule !== undefined)
56
- return rule;
57
- __classPrivateFieldSet(this, _CssEngine_isDirty, true, "f");
58
- return __classPrivateFieldGet(this, _CssEngine_plainRules, "f").set(cssText, new PlaintextRule(cssText));
61
+ mediaRule.insertRule(styleRule);
62
+ return styleRule;
63
+ }
64
+ addPlaintextRule(cssText) {
65
+ const rule = __privateGet(this, _plainRules).get(cssText);
66
+ if (rule !== void 0) {
67
+ return rule;
59
68
  }
60
- addFontFaceRule(options) {
61
- __classPrivateFieldSet(this, _CssEngine_isDirty, true, "f");
62
- return __classPrivateFieldGet(this, _CssEngine_fontFaceRules, "f").push(new FontFaceRule(options));
69
+ __privateSet(this, _isDirty, true);
70
+ return __privateGet(this, _plainRules).set(cssText, new PlaintextRule(cssText));
71
+ }
72
+ addFontFaceRule(options) {
73
+ __privateSet(this, _isDirty, true);
74
+ return __privateGet(this, _fontFaceRules).push(new FontFaceRule(options));
75
+ }
76
+ clear() {
77
+ __privateGet(this, _mediaRules).clear();
78
+ __privateGet(this, _plainRules).clear();
79
+ __privateSet(this, _fontFaceRules, []);
80
+ __privateSet(this, _isDirty, true);
81
+ }
82
+ render() {
83
+ __privateGet(this, _element).mount();
84
+ __privateGet(this, _sheet).replaceSync(this.cssText);
85
+ }
86
+ unmount() {
87
+ __privateGet(this, _element).unmount();
88
+ }
89
+ get cssText() {
90
+ if (__privateGet(this, _isDirty) === false) {
91
+ return __privateGet(this, _cssText);
63
92
  }
64
- clear() {
65
- __classPrivateFieldGet(this, _CssEngine_mediaRules, "f").clear();
66
- __classPrivateFieldGet(this, _CssEngine_plainRules, "f").clear();
67
- __classPrivateFieldSet(this, _CssEngine_fontFaceRules, [], "f");
68
- __classPrivateFieldSet(this, _CssEngine_isDirty, true, "f");
93
+ __privateSet(this, _isDirty, false);
94
+ const css = [];
95
+ css.push(...__privateGet(this, _fontFaceRules).map((rule) => rule.cssText));
96
+ for (const plaintextRule of __privateGet(this, _plainRules).values()) {
97
+ css.push(plaintextRule.cssText);
69
98
  }
70
- render() {
71
- __classPrivateFieldGet(this, _CssEngine_element, "f").mount();
72
- // This isn't going to do anything if the `cssText` hasn't changed.
73
- __classPrivateFieldGet(this, _CssEngine_sheet, "f").replaceSync(this.cssText);
74
- }
75
- unmount() {
76
- __classPrivateFieldGet(this, _CssEngine_element, "f").unmount();
77
- }
78
- get cssText() {
79
- if (__classPrivateFieldGet(this, _CssEngine_isDirty, "f") === false) {
80
- return __classPrivateFieldGet(this, _CssEngine_cssText, "f");
81
- }
82
- __classPrivateFieldSet(this, _CssEngine_isDirty, false, "f");
83
- const css = [];
84
- css.push(...__classPrivateFieldGet(this, _CssEngine_fontFaceRules, "f").map((rule) => rule.cssText));
85
- for (const plaintextRule of __classPrivateFieldGet(this, _CssEngine_plainRules, "f").values()) {
86
- css.push(plaintextRule.cssText);
87
- }
88
- for (const mediaRule of __classPrivateFieldGet(this, _CssEngine_mediaRules, "f").values()) {
89
- const { cssText } = mediaRule;
90
- if (cssText !== "")
91
- css.push(cssText);
92
- }
93
- __classPrivateFieldSet(this, _CssEngine_cssText, css.join("\n"), "f");
94
- return __classPrivateFieldGet(this, _CssEngine_cssText, "f");
99
+ for (const mediaRule of __privateGet(this, _mediaRules).values()) {
100
+ const { cssText } = mediaRule;
101
+ if (cssText !== "") {
102
+ css.push(cssText);
103
+ }
95
104
  }
105
+ __privateSet(this, _cssText, css.join("\n"));
106
+ return __privateGet(this, _cssText);
107
+ }
96
108
  }
97
- _CssEngine_element = new WeakMap(), _CssEngine_mediaRules = new WeakMap(), _CssEngine_plainRules = new WeakMap(), _CssEngine_fontFaceRules = new WeakMap(), _CssEngine_sheet = new WeakMap(), _CssEngine_isDirty = new WeakMap(), _CssEngine_cssText = new WeakMap(), _CssEngine_onChangeRule = new WeakMap();
109
+ _element = new WeakMap();
110
+ _mediaRules = new WeakMap();
111
+ _plainRules = new WeakMap();
112
+ _fontFaceRules = new WeakMap();
113
+ _sheet = new WeakMap();
114
+ _isDirty = new WeakMap();
115
+ _cssText = new WeakMap();
116
+ _onChangeRule = new WeakMap();
117
+ export {
118
+ CssEngine
119
+ };
package/lib/core/index.js CHANGED
@@ -1,3 +1,6 @@
1
- export { CssEngine } from "./css-engine";
1
+ import { CssEngine } from "./css-engine";
2
2
  export * from "./create-css-engine";
3
3
  export * from "./to-value";
4
+ export {
5
+ CssEngine
6
+ };
package/lib/core/rules.js CHANGED
@@ -1,112 +1,142 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1
+ var __accessCheck = (obj, member, msg) => {
2
+ if (!member.has(obj))
3
+ throw TypeError("Cannot " + msg);
5
4
  };
6
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
- if (kind === "m") throw new TypeError("Private method is not writable");
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
5
+ var __privateGet = (obj, member, getter) => {
6
+ __accessCheck(obj, member, "read from private field");
7
+ return getter ? getter.call(obj) : member.get(obj);
11
8
  };
12
- var _StylePropertyMap_styleMap, _StylePropertyMap_isDirty, _StylePropertyMap_string, _StyleRule_onChange, _MediaRule_options, _MediaRule_mediaType, _FontFaceRule_options;
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 _styleMap, _isDirty, _string, _onChange, _options, _mediaType, _options2;
13
20
  import hyphenate from "hyphenate-style-name";
14
21
  import { toValue } from "./to-value";
15
22
  class StylePropertyMap {
16
- constructor() {
17
- _StylePropertyMap_styleMap.set(this, new Map());
18
- _StylePropertyMap_isDirty.set(this, false);
19
- _StylePropertyMap_string.set(this, "");
20
- }
21
- set(property, value) {
22
- __classPrivateFieldGet(this, _StylePropertyMap_styleMap, "f").set(property, value);
23
- __classPrivateFieldSet(this, _StylePropertyMap_isDirty, true, "f");
24
- this.onChange?.();
23
+ constructor() {
24
+ __privateAdd(this, _styleMap, /* @__PURE__ */ new Map());
25
+ __privateAdd(this, _isDirty, false);
26
+ __privateAdd(this, _string, "");
27
+ }
28
+ set(property, value) {
29
+ __privateGet(this, _styleMap).set(property, value);
30
+ __privateSet(this, _isDirty, true);
31
+ this.onChange?.();
32
+ }
33
+ has(property) {
34
+ return __privateGet(this, _styleMap).has(property);
35
+ }
36
+ clear() {
37
+ __privateGet(this, _styleMap).clear();
38
+ __privateSet(this, _isDirty, true);
39
+ this.onChange?.();
40
+ }
41
+ toString() {
42
+ if (__privateGet(this, _isDirty) === false) {
43
+ return __privateGet(this, _string);
25
44
  }
26
- clear() {
27
- __classPrivateFieldGet(this, _StylePropertyMap_styleMap, "f").clear();
28
- __classPrivateFieldSet(this, _StylePropertyMap_isDirty, true, "f");
29
- this.onChange?.();
45
+ const block = [];
46
+ for (const [property, value] of __privateGet(this, _styleMap)) {
47
+ if (value === void 0) {
48
+ continue;
49
+ }
50
+ block.push(`${hyphenate(property)}: ${toValue(value)}`);
30
51
  }
31
- toString() {
32
- if (__classPrivateFieldGet(this, _StylePropertyMap_isDirty, "f") === false) {
33
- return __classPrivateFieldGet(this, _StylePropertyMap_string, "f");
34
- }
35
- const block = [];
36
- for (const [property, value] of __classPrivateFieldGet(this, _StylePropertyMap_styleMap, "f")) {
37
- if (value === undefined)
38
- continue;
39
- block.push(`${hyphenate(property)}: ${toValue(value)}`);
40
- }
41
- __classPrivateFieldSet(this, _StylePropertyMap_string, block.join("; "), "f");
42
- __classPrivateFieldSet(this, _StylePropertyMap_isDirty, false, "f");
43
- return __classPrivateFieldGet(this, _StylePropertyMap_string, "f");
52
+ __privateSet(this, _string, block.join("; "));
53
+ __privateSet(this, _isDirty, false);
54
+ return __privateGet(this, _string);
55
+ }
56
+ }
57
+ _styleMap = new WeakMap();
58
+ _isDirty = new WeakMap();
59
+ _string = new WeakMap();
60
+ class StyleRule {
61
+ constructor(selectorText, style) {
62
+ __privateAdd(this, _onChange, () => {
63
+ this.onChange?.();
64
+ });
65
+ this.styleMap = new StylePropertyMap();
66
+ this.selectorText = selectorText;
67
+ let property;
68
+ for (property in style) {
69
+ this.styleMap.set(property, style[property]);
44
70
  }
71
+ this.styleMap.onChange = __privateGet(this, _onChange);
72
+ }
73
+ get cssText() {
74
+ return `${this.selectorText} { ${this.styleMap} }`;
75
+ }
45
76
  }
46
- _StylePropertyMap_styleMap = new WeakMap(), _StylePropertyMap_isDirty = new WeakMap(), _StylePropertyMap_string = new WeakMap();
47
- export class StyleRule {
48
- constructor(selectorText, style) {
49
- _StyleRule_onChange.set(this, () => {
50
- this.onChange?.();
51
- });
52
- this.styleMap = new StylePropertyMap();
53
- this.selectorText = selectorText;
54
- let property;
55
- for (property in style) {
56
- this.styleMap.set(property, style[property]);
57
- }
58
- this.styleMap.onChange = __classPrivateFieldGet(this, _StyleRule_onChange, "f");
77
+ _onChange = new WeakMap();
78
+ class MediaRule {
79
+ constructor(options = {}) {
80
+ __privateAdd(this, _options, void 0);
81
+ this.rules = [];
82
+ __privateAdd(this, _mediaType, void 0);
83
+ __privateSet(this, _options, options);
84
+ __privateSet(this, _mediaType, options.mediaType ?? "all");
85
+ }
86
+ insertRule(rule) {
87
+ this.rules.push(rule);
88
+ return rule;
89
+ }
90
+ get cssText() {
91
+ if (this.rules.length === 0) {
92
+ return "";
59
93
  }
60
- get cssText() {
61
- return `${this.selectorText} { ${this.styleMap} }`;
94
+ const rules = [];
95
+ for (const rule of this.rules) {
96
+ rules.push(` ${rule.cssText}`);
62
97
  }
63
- }
64
- _StyleRule_onChange = new WeakMap();
65
- export class MediaRule {
66
- constructor(options = {}) {
67
- _MediaRule_options.set(this, void 0);
68
- this.rules = [];
69
- _MediaRule_mediaType.set(this, void 0);
70
- __classPrivateFieldSet(this, _MediaRule_options, options, "f");
71
- __classPrivateFieldSet(this, _MediaRule_mediaType, options.mediaType ?? "all", "f");
98
+ let conditionText = "";
99
+ const { minWidth, maxWidth } = __privateGet(this, _options);
100
+ if (minWidth !== void 0) {
101
+ conditionText = `min-width: ${minWidth}px`;
72
102
  }
73
- insertRule(rule) {
74
- this.rules.push(rule);
75
- return rule;
103
+ if (maxWidth !== void 0) {
104
+ conditionText = `max-width: ${maxWidth}px`;
76
105
  }
77
- get cssText() {
78
- if (this.rules.length === 0)
79
- return "";
80
- const rules = [];
81
- for (const rule of this.rules) {
82
- rules.push(` ${rule.cssText}`);
83
- }
84
- let conditionText = "";
85
- const { minWidth, maxWidth } = __classPrivateFieldGet(this, _MediaRule_options, "f");
86
- if (minWidth !== undefined)
87
- conditionText = `min-width: ${minWidth}px`;
88
- if (maxWidth !== undefined)
89
- conditionText = `max-width: ${maxWidth}px`;
90
- if (conditionText)
91
- conditionText = `and (${conditionText}) `;
92
- return `@media ${__classPrivateFieldGet(this, _MediaRule_mediaType, "f")} ${conditionText}{\n${rules.join("\n")}\n}`;
106
+ if (conditionText) {
107
+ conditionText = `and (${conditionText}) `;
93
108
  }
109
+ return `@media ${__privateGet(this, _mediaType)} ${conditionText}{
110
+ ${rules.join(
111
+ "\n"
112
+ )}
113
+ }`;
114
+ }
94
115
  }
95
- _MediaRule_options = new WeakMap(), _MediaRule_mediaType = new WeakMap();
96
- export class PlaintextRule {
97
- constructor(cssText) {
98
- this.styleMap = new Map();
99
- this.cssText = cssText;
100
- }
116
+ _options = new WeakMap();
117
+ _mediaType = new WeakMap();
118
+ class PlaintextRule {
119
+ constructor(cssText) {
120
+ this.styleMap = new StylePropertyMap();
121
+ this.cssText = cssText;
122
+ }
101
123
  }
102
- export class FontFaceRule {
103
- constructor(options) {
104
- _FontFaceRule_options.set(this, void 0);
105
- __classPrivateFieldSet(this, _FontFaceRule_options, options, "f");
106
- }
107
- get cssText() {
108
- const { fontFamily, fontStyle, fontWeight, fontDisplay, src } = __classPrivateFieldGet(this, _FontFaceRule_options, "f");
109
- return `@font-face {\n font-family: ${fontFamily}; font-style: ${fontStyle}; font-weight: ${fontWeight}; font-display: ${fontDisplay}; src: ${src};\n}`;
110
- }
124
+ class FontFaceRule {
125
+ constructor(options) {
126
+ __privateAdd(this, _options2, void 0);
127
+ __privateSet(this, _options2, options);
128
+ }
129
+ get cssText() {
130
+ const { fontFamily, fontStyle, fontWeight, fontDisplay, src } = __privateGet(this, _options2);
131
+ return `@font-face {
132
+ font-family: ${fontFamily}; font-style: ${fontStyle}; font-weight: ${fontWeight}; font-display: ${fontDisplay}; src: ${src};
133
+ }`;
134
+ }
111
135
  }
112
- _FontFaceRule_options = new WeakMap();
136
+ _options2 = new WeakMap();
137
+ export {
138
+ FontFaceRule,
139
+ MediaRule,
140
+ PlaintextRule,
141
+ StyleRule
142
+ };
@@ -1,39 +1,49 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1
+ var __accessCheck = (obj, member, msg) => {
2
+ if (!member.has(obj))
3
+ throw TypeError("Cannot " + msg);
5
4
  };
6
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
- if (kind === "m") throw new TypeError("Private method is not writable");
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
5
+ var __privateGet = (obj, member, getter) => {
6
+ __accessCheck(obj, member, "read from private field");
7
+ return getter ? getter.call(obj) : member.get(obj);
11
8
  };
12
- var _StyleElement_element;
13
- export class StyleElement {
14
- constructor() {
15
- _StyleElement_element.set(this, void 0);
16
- }
17
- get isMounted() {
18
- return __classPrivateFieldGet(this, _StyleElement_element, "f")?.parentElement != null;
19
- }
20
- mount() {
21
- if (this.isMounted === false) {
22
- __classPrivateFieldSet(this, _StyleElement_element, document.createElement("style"), "f");
23
- __classPrivateFieldGet(this, _StyleElement_element, "f").setAttribute("data-webstudio", "");
24
- document.head.appendChild(__classPrivateFieldGet(this, _StyleElement_element, "f"));
25
- }
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;
20
+ class StyleElement {
21
+ constructor() {
22
+ __privateAdd(this, _element, void 0);
23
+ }
24
+ get isMounted() {
25
+ return __privateGet(this, _element)?.parentElement != null;
26
+ }
27
+ mount() {
28
+ if (this.isMounted === false) {
29
+ __privateSet(this, _element, document.createElement("style"));
30
+ __privateGet(this, _element).setAttribute("data-webstudio", "");
31
+ document.head.appendChild(__privateGet(this, _element));
26
32
  }
27
- unmount() {
28
- if (this.isMounted) {
29
- __classPrivateFieldGet(this, _StyleElement_element, "f")?.parentElement?.removeChild(__classPrivateFieldGet(this, _StyleElement_element, "f"));
30
- __classPrivateFieldSet(this, _StyleElement_element, undefined, "f");
31
- }
33
+ }
34
+ unmount() {
35
+ if (this.isMounted) {
36
+ __privateGet(this, _element)?.parentElement?.removeChild(__privateGet(this, _element));
37
+ __privateSet(this, _element, void 0);
32
38
  }
33
- render(cssText) {
34
- if (__classPrivateFieldGet(this, _StyleElement_element, "f")) {
35
- __classPrivateFieldGet(this, _StyleElement_element, "f").textContent = cssText;
36
- }
39
+ }
40
+ render(cssText) {
41
+ if (__privateGet(this, _element)) {
42
+ __privateGet(this, _element).textContent = cssText;
37
43
  }
44
+ }
38
45
  }
39
- _StyleElement_element = new WeakMap();
46
+ _element = new WeakMap();
47
+ export {
48
+ StyleElement
49
+ };
@@ -1,26 +1,37 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
1
+ var __accessCheck = (obj, member, msg) => {
2
+ if (!member.has(obj))
3
+ throw TypeError("Cannot " + msg);
6
4
  };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ var __privateGet = (obj, member, getter) => {
6
+ __accessCheck(obj, member, "read from private field");
7
+ return getter ? getter.call(obj) : member.get(obj);
11
8
  };
12
- var _StyleSheet_cssText, _StyleSheet_element;
13
- export class StyleSheet {
14
- constructor(element) {
15
- _StyleSheet_cssText.set(this, "");
16
- _StyleSheet_element.set(this, void 0);
17
- __classPrivateFieldSet(this, _StyleSheet_element, element, "f");
18
- }
19
- replaceSync(cssText) {
20
- if (cssText !== __classPrivateFieldGet(this, _StyleSheet_cssText, "f")) {
21
- __classPrivateFieldSet(this, _StyleSheet_cssText, cssText, "f");
22
- __classPrivateFieldGet(this, _StyleSheet_element, "f").render(cssText);
23
- }
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 _cssText, _element;
20
+ class StyleSheet {
21
+ constructor(element) {
22
+ __privateAdd(this, _cssText, "");
23
+ __privateAdd(this, _element, void 0);
24
+ __privateSet(this, _element, element);
25
+ }
26
+ replaceSync(cssText) {
27
+ if (cssText !== __privateGet(this, _cssText)) {
28
+ __privateSet(this, _cssText, cssText);
29
+ __privateGet(this, _element).render(cssText);
24
30
  }
31
+ }
25
32
  }
26
- _StyleSheet_cssText = new WeakMap(), _StyleSheet_element = new WeakMap();
33
+ _cssText = new WeakMap();
34
+ _element = new WeakMap();
35
+ export {
36
+ StyleSheet
37
+ };