@webstudio-is/css-engine 0.3.0 → 0.4.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/cjs/core/create-css-engine.cjs +27 -0
- package/lib/cjs/core/css-engine.cjs +132 -0
- package/lib/cjs/core/index.cjs +27 -0
- package/lib/cjs/core/rules.cjs +163 -0
- package/lib/cjs/core/style-element.cjs +69 -0
- package/lib/cjs/core/style-sheet.cjs +57 -0
- package/lib/cjs/core/to-value.cjs +54 -0
- package/lib/cjs/index.cjs +18 -0
- package/lib/core/create-css-engine.js +5 -2
- package/lib/core/css-engine.js +106 -86
- package/lib/core/index.js +4 -1
- package/lib/core/rules.js +123 -98
- package/lib/core/style-element.js +43 -33
- package/lib/core/style-sheet.js +33 -22
- package/lib/core/to-value.js +27 -24
- package/package.json +7 -14
- package/src/core/create-css-engine.ts +5 -0
- package/src/core/css-engine.stories.tsx +48 -0
- package/src/core/css-engine.test.ts +206 -0
- package/src/core/css-engine.ts +94 -0
- package/src/core/index.ts +10 -0
- package/src/core/rules.ts +122 -0
- package/src/core/style-element.ts +24 -0
- package/src/core/style-sheet.ts +15 -0
- package/src/core/to-value.test.ts +66 -0
- package/src/core/to-value.ts +41 -0
- package/src/index.ts +1 -0
- package/lib/core/create-css-engine.d.ts +0 -3
- package/lib/core/create-css-engine.d.ts.map +0 -1
- package/lib/core/css-engine.d.ts +0 -15
- package/lib/core/css-engine.d.ts.map +0 -1
- package/lib/core/css-engine.stories.d.ts +0 -7
- package/lib/core/css-engine.stories.d.ts.map +0 -1
- package/lib/core/css-engine.stories.js +0 -31
- package/lib/core/css-engine.test.d.ts +0 -2
- package/lib/core/css-engine.test.d.ts.map +0 -1
- package/lib/core/css-engine.test.js +0 -182
- package/lib/core/index.d.ts +0 -5
- package/lib/core/index.d.ts.map +0 -1
- package/lib/core/rules.d.ts +0 -48
- package/lib/core/rules.d.ts.map +0 -1
- package/lib/core/style-element.d.ts +0 -8
- package/lib/core/style-element.d.ts.map +0 -1
- package/lib/core/style-sheet.d.ts +0 -7
- package/lib/core/style-sheet.d.ts.map +0 -1
- package/lib/core/to-value.d.ts +0 -7
- package/lib/core/to-value.d.ts.map +0 -1
- package/lib/core/to-value.test.d.ts +0 -2
- package/lib/core/to-value.test.d.ts.map +0 -1
- package/lib/core/to-value.test.js +0 -55
- package/lib/index.d.ts +0 -2
- package/lib/index.d.ts.map +0 -1
package/lib/core/css-engine.js
CHANGED
|
@@ -1,97 +1,117 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
13
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
return mediaRule;
|
|
40
|
-
}
|
|
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;
|
|
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);
|
|
52
50
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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");
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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;
|
|
68
|
+
__privateSet(this, _isDirty, true);
|
|
69
|
+
return __privateGet(this, _plainRules).set(cssText, new PlaintextRule(cssText));
|
|
70
|
+
}
|
|
71
|
+
addFontFaceRule(options) {
|
|
72
|
+
__privateSet(this, _isDirty, true);
|
|
73
|
+
return __privateGet(this, _fontFaceRules).push(new FontFaceRule(options));
|
|
74
|
+
}
|
|
75
|
+
clear() {
|
|
76
|
+
__privateGet(this, _mediaRules).clear();
|
|
77
|
+
__privateGet(this, _plainRules).clear();
|
|
78
|
+
__privateSet(this, _fontFaceRules, []);
|
|
79
|
+
__privateSet(this, _isDirty, true);
|
|
80
|
+
}
|
|
81
|
+
render() {
|
|
82
|
+
__privateGet(this, _element).mount();
|
|
83
|
+
__privateGet(this, _sheet).replaceSync(this.cssText);
|
|
84
|
+
}
|
|
85
|
+
unmount() {
|
|
86
|
+
__privateGet(this, _element).unmount();
|
|
87
|
+
}
|
|
88
|
+
get cssText() {
|
|
89
|
+
if (__privateGet(this, _isDirty) === false) {
|
|
90
|
+
return __privateGet(this, _cssText);
|
|
63
91
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
92
|
+
__privateSet(this, _isDirty, false);
|
|
93
|
+
const css = [];
|
|
94
|
+
css.push(...__privateGet(this, _fontFaceRules).map((rule) => rule.cssText));
|
|
95
|
+
for (const plaintextRule of __privateGet(this, _plainRules).values()) {
|
|
96
|
+
css.push(plaintextRule.cssText);
|
|
69
97
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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");
|
|
98
|
+
for (const mediaRule of __privateGet(this, _mediaRules).values()) {
|
|
99
|
+
const { cssText } = mediaRule;
|
|
100
|
+
if (cssText !== "")
|
|
101
|
+
css.push(cssText);
|
|
95
102
|
}
|
|
103
|
+
__privateSet(this, _cssText, css.join("\n"));
|
|
104
|
+
return __privateGet(this, _cssText);
|
|
105
|
+
}
|
|
96
106
|
}
|
|
97
|
-
|
|
107
|
+
_element = new WeakMap();
|
|
108
|
+
_mediaRules = new WeakMap();
|
|
109
|
+
_plainRules = new WeakMap();
|
|
110
|
+
_fontFaceRules = new WeakMap();
|
|
111
|
+
_sheet = new WeakMap();
|
|
112
|
+
_isDirty = new WeakMap();
|
|
113
|
+
_cssText = new WeakMap();
|
|
114
|
+
_onChangeRule = new WeakMap();
|
|
115
|
+
export {
|
|
116
|
+
CssEngine
|
|
117
|
+
};
|
package/lib/core/index.js
CHANGED
package/lib/core/rules.js
CHANGED
|
@@ -1,112 +1,137 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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");
|
|
45
|
+
const block = [];
|
|
46
|
+
for (const [property, value] of __privateGet(this, _styleMap)) {
|
|
47
|
+
if (value === void 0)
|
|
48
|
+
continue;
|
|
49
|
+
block.push(`${hyphenate(property)}: ${toValue(value)}`);
|
|
44
50
|
}
|
|
51
|
+
__privateSet(this, _string, block.join("; "));
|
|
52
|
+
__privateSet(this, _isDirty, false);
|
|
53
|
+
return __privateGet(this, _string);
|
|
54
|
+
}
|
|
45
55
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
get cssText() {
|
|
61
|
-
return `${this.selectorText} { ${this.styleMap} }`;
|
|
56
|
+
_styleMap = new WeakMap();
|
|
57
|
+
_isDirty = new WeakMap();
|
|
58
|
+
_string = new WeakMap();
|
|
59
|
+
class StyleRule {
|
|
60
|
+
constructor(selectorText, style) {
|
|
61
|
+
__privateAdd(this, _onChange, () => {
|
|
62
|
+
this.onChange?.();
|
|
63
|
+
});
|
|
64
|
+
this.styleMap = new StylePropertyMap();
|
|
65
|
+
this.selectorText = selectorText;
|
|
66
|
+
let property;
|
|
67
|
+
for (property in style) {
|
|
68
|
+
this.styleMap.set(property, style[property]);
|
|
62
69
|
}
|
|
70
|
+
this.styleMap.onChange = __privateGet(this, _onChange);
|
|
71
|
+
}
|
|
72
|
+
get cssText() {
|
|
73
|
+
return `${this.selectorText} { ${this.styleMap} }`;
|
|
74
|
+
}
|
|
63
75
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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}`;
|
|
76
|
+
_onChange = new WeakMap();
|
|
77
|
+
class MediaRule {
|
|
78
|
+
constructor(options = {}) {
|
|
79
|
+
__privateAdd(this, _options, void 0);
|
|
80
|
+
this.rules = [];
|
|
81
|
+
__privateAdd(this, _mediaType, void 0);
|
|
82
|
+
__privateSet(this, _options, options);
|
|
83
|
+
__privateSet(this, _mediaType, options.mediaType ?? "all");
|
|
84
|
+
}
|
|
85
|
+
insertRule(rule) {
|
|
86
|
+
this.rules.push(rule);
|
|
87
|
+
return rule;
|
|
88
|
+
}
|
|
89
|
+
get cssText() {
|
|
90
|
+
if (this.rules.length === 0)
|
|
91
|
+
return "";
|
|
92
|
+
const rules = [];
|
|
93
|
+
for (const rule of this.rules) {
|
|
94
|
+
rules.push(` ${rule.cssText}`);
|
|
93
95
|
}
|
|
96
|
+
let conditionText = "";
|
|
97
|
+
const { minWidth, maxWidth } = __privateGet(this, _options);
|
|
98
|
+
if (minWidth !== void 0)
|
|
99
|
+
conditionText = `min-width: ${minWidth}px`;
|
|
100
|
+
if (maxWidth !== void 0)
|
|
101
|
+
conditionText = `max-width: ${maxWidth}px`;
|
|
102
|
+
if (conditionText)
|
|
103
|
+
conditionText = `and (${conditionText}) `;
|
|
104
|
+
return `@media ${__privateGet(this, _mediaType)} ${conditionText}{
|
|
105
|
+
${rules.join(
|
|
106
|
+
"\n"
|
|
107
|
+
)}
|
|
108
|
+
}`;
|
|
109
|
+
}
|
|
94
110
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
111
|
+
_options = new WeakMap();
|
|
112
|
+
_mediaType = new WeakMap();
|
|
113
|
+
class PlaintextRule {
|
|
114
|
+
constructor(cssText) {
|
|
115
|
+
this.styleMap = new StylePropertyMap();
|
|
116
|
+
this.cssText = cssText;
|
|
117
|
+
}
|
|
101
118
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
119
|
+
class FontFaceRule {
|
|
120
|
+
constructor(options) {
|
|
121
|
+
__privateAdd(this, _options2, void 0);
|
|
122
|
+
__privateSet(this, _options2, options);
|
|
123
|
+
}
|
|
124
|
+
get cssText() {
|
|
125
|
+
const { fontFamily, fontStyle, fontWeight, fontDisplay, src } = __privateGet(this, _options2);
|
|
126
|
+
return `@font-face {
|
|
127
|
+
font-family: ${fontFamily}; font-style: ${fontStyle}; font-weight: ${fontWeight}; font-display: ${fontDisplay}; src: ${src};
|
|
128
|
+
}`;
|
|
129
|
+
}
|
|
111
130
|
}
|
|
112
|
-
|
|
131
|
+
_options2 = new WeakMap();
|
|
132
|
+
export {
|
|
133
|
+
FontFaceRule,
|
|
134
|
+
MediaRule,
|
|
135
|
+
PlaintextRule,
|
|
136
|
+
StyleRule
|
|
137
|
+
};
|
|
@@ -1,39 +1,49 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
}
|
|
40
|
+
render(cssText) {
|
|
41
|
+
if (__privateGet(this, _element)) {
|
|
42
|
+
__privateGet(this, _element).textContent = cssText;
|
|
37
43
|
}
|
|
44
|
+
}
|
|
38
45
|
}
|
|
39
|
-
|
|
46
|
+
_element = new WeakMap();
|
|
47
|
+
export {
|
|
48
|
+
StyleElement
|
|
49
|
+
};
|
package/lib/core/style-sheet.js
CHANGED
|
@@ -1,26 +1,37 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
33
|
+
_cssText = new WeakMap();
|
|
34
|
+
_element = new WeakMap();
|
|
35
|
+
export {
|
|
36
|
+
StyleSheet
|
|
37
|
+
};
|