@webstudio-is/css-engine 0.91.0 → 0.93.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/__generated__/types.js +1 -0
- package/lib/core/compare-media.js +2 -4
- package/{src/core/compare-media.test.ts → lib/core/compare-media.test.js} +7 -9
- package/lib/core/create-css-engine.js +2 -4
- package/lib/core/css-engine.js +2 -4
- package/lib/core/css-engine.stories.js +48 -0
- package/{src/core/css-engine.test.ts → lib/core/css-engine.test.js} +51 -88
- package/lib/core/equal-media.js +2 -4
- package/{src/core/equal-media.test.ts → lib/core/equal-media.test.js} +1 -3
- package/lib/core/find-applicable-media.js +2 -4
- package/{src/core/find-applicable-media.test.ts → lib/core/find-applicable-media.test.js} +7 -8
- package/lib/core/index.js +2 -4
- package/lib/core/match-media.js +2 -4
- package/{src/core/match-media.test.ts → lib/core/match-media.test.js} +1 -3
- package/lib/core/rules.js +5 -10
- package/lib/core/style-element.js +2 -4
- package/lib/core/style-sheet.js +2 -4
- package/lib/core/to-property.js +2 -4
- package/{src/core/to-property.test.ts → lib/core/to-property.test.js} +1 -1
- package/lib/core/to-value.js +2 -4
- package/{src/core/to-value.test.ts → lib/core/to-value.test.js} +21 -32
- package/lib/index.js +2 -0
- package/lib/schema.js +98 -0
- package/lib/types/__generated__/types.d.ts +2 -0
- package/lib/types/core/css-engine.d.ts +1 -1
- package/lib/types/core/rules.d.ts +2 -2
- package/lib/types/core/to-property.d.ts +1 -1
- package/lib/types/core/to-value.d.ts +1 -1
- package/lib/types/index.d.ts +2 -0
- package/lib/types/schema.d.ts +3233 -0
- package/package.json +12 -15
- package/lib/cjs/core/compare-media.js +0 -38
- package/lib/cjs/core/create-css-engine.js +0 -27
- package/lib/cjs/core/css-engine.js +0 -122
- package/lib/cjs/core/equal-media.js +0 -26
- package/lib/cjs/core/find-applicable-media.js +0 -33
- package/lib/cjs/core/index.js +0 -32
- package/lib/cjs/core/match-media.js +0 -28
- package/lib/cjs/core/rules.js +0 -187
- package/lib/cjs/core/style-element.js +0 -61
- package/lib/cjs/core/style-sheet.js +0 -36
- package/lib/cjs/core/to-property.js +0 -40
- package/lib/cjs/core/to-value.js +0 -98
- package/lib/cjs/index.js +0 -18
- package/lib/cjs/package.json +0 -1
- package/src/core/compare-media.ts +0 -30
- package/src/core/create-css-engine.ts +0 -5
- package/src/core/css-engine.stories.tsx +0 -48
- package/src/core/css-engine.ts +0 -128
- package/src/core/equal-media.ts +0 -5
- package/src/core/find-applicable-media.ts +0 -20
- package/src/core/index.ts +0 -15
- package/src/core/match-media.ts +0 -8
- package/src/core/rules.ts +0 -182
- package/src/core/style-element.ts +0 -38
- package/src/core/style-sheet.ts +0 -15
- package/src/core/to-property.ts +0 -12
- package/src/core/to-value.ts +0 -108
- package/src/index.ts +0 -1
package/package.json
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/css-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.93.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
9
|
"hyphenate-style-name": "^1.0.4",
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"@webstudio-is/css-data": "^0.91.0",
|
|
13
|
-
"@webstudio-is/error-utils": "^0.91.0",
|
|
14
|
-
"@webstudio-is/fonts": "^0.91.0"
|
|
10
|
+
"@webstudio-is/error-utils": "^0.93.0",
|
|
11
|
+
"@webstudio-is/fonts": "^0.93.0"
|
|
15
12
|
},
|
|
16
13
|
"devDependencies": {
|
|
17
|
-
"@jest/globals": "^29.6.
|
|
14
|
+
"@jest/globals": "^29.6.4",
|
|
18
15
|
"@types/hyphenate-style-name": "^1.0.0",
|
|
19
|
-
"@types/react": "^18.2.
|
|
16
|
+
"@types/react": "^18.2.21",
|
|
20
17
|
"@types/react-dom": "^18.2.7",
|
|
21
|
-
"jest": "^29.6.
|
|
22
|
-
"
|
|
18
|
+
"jest": "^29.6.4",
|
|
19
|
+
"react": "^18.2.0",
|
|
20
|
+
"react-dom": "^18.2.0",
|
|
21
|
+
"typescript": "5.2.2",
|
|
23
22
|
"@webstudio-is/jest-config": "^1.0.7",
|
|
24
|
-
"@webstudio-is/scripts": "^0.0.0",
|
|
25
23
|
"@webstudio-is/storybook-config": "^0.0.0",
|
|
26
24
|
"@webstudio-is/tsconfig": "^1.0.7"
|
|
27
25
|
},
|
|
@@ -32,8 +30,7 @@
|
|
|
32
30
|
},
|
|
33
31
|
"files": [
|
|
34
32
|
"lib/*",
|
|
35
|
-
"
|
|
36
|
-
"!*.test.*"
|
|
33
|
+
"!*.{test,stories}.*"
|
|
37
34
|
],
|
|
38
35
|
"license": "AGPL-3.0-or-later",
|
|
39
36
|
"private": false,
|
|
@@ -41,8 +38,8 @@
|
|
|
41
38
|
"scripts": {
|
|
42
39
|
"typecheck": "tsc",
|
|
43
40
|
"checks": "pnpm typecheck && pnpm test",
|
|
44
|
-
"dev": "build
|
|
45
|
-
"build": "
|
|
41
|
+
"dev": "pnpm build --watch",
|
|
42
|
+
"build": "rm -rf lib && esbuild 'src/**/*.ts' 'src/**/*.tsx' --outdir=lib",
|
|
46
43
|
"dts": "tsc --project tsconfig.dts.json",
|
|
47
44
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
48
45
|
"storybook:dev": "storybook dev -p 6006",
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var compare_media_exports = {};
|
|
20
|
-
__export(compare_media_exports, {
|
|
21
|
-
compareMedia: () => compareMedia
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(compare_media_exports);
|
|
24
|
-
const compareMedia = (optionA, optionB) => {
|
|
25
|
-
if (optionA.minWidth === void 0 && optionA.maxWidth === void 0) {
|
|
26
|
-
return -1;
|
|
27
|
-
}
|
|
28
|
-
if (optionB.minWidth === void 0 && optionB.maxWidth === void 0) {
|
|
29
|
-
return 1;
|
|
30
|
-
}
|
|
31
|
-
if (optionA.minWidth !== void 0 && optionB.minWidth !== void 0) {
|
|
32
|
-
return optionA.minWidth - optionB.minWidth;
|
|
33
|
-
}
|
|
34
|
-
if (optionA.maxWidth !== void 0 && optionB.maxWidth !== void 0) {
|
|
35
|
-
return optionB.maxWidth - optionA.maxWidth;
|
|
36
|
-
}
|
|
37
|
-
return "minWidth" in optionA ? 1 : -1;
|
|
38
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var create_css_engine_exports = {};
|
|
20
|
-
__export(create_css_engine_exports, {
|
|
21
|
-
createCssEngine: () => createCssEngine
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(create_css_engine_exports);
|
|
24
|
-
var import_css_engine = require("./css-engine");
|
|
25
|
-
const createCssEngine = (options = {}) => {
|
|
26
|
-
return new import_css_engine.CssEngine(options);
|
|
27
|
-
};
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var css_engine_exports = {};
|
|
20
|
-
__export(css_engine_exports, {
|
|
21
|
-
CssEngine: () => CssEngine
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(css_engine_exports);
|
|
24
|
-
var import_rules = require("./rules");
|
|
25
|
-
var import_compare_media = require("./compare-media");
|
|
26
|
-
var import_style_element = require("./style-element");
|
|
27
|
-
var import_style_sheet = require("./style-sheet");
|
|
28
|
-
const defaultMediaRuleId = "__default-media-rule__";
|
|
29
|
-
class CssEngine {
|
|
30
|
-
#element;
|
|
31
|
-
#mediaRules = /* @__PURE__ */ new Map();
|
|
32
|
-
#plainRules = /* @__PURE__ */ new Map();
|
|
33
|
-
#fontFaceRules = [];
|
|
34
|
-
#sheet;
|
|
35
|
-
#isDirty = false;
|
|
36
|
-
#cssText = "";
|
|
37
|
-
constructor({ name }) {
|
|
38
|
-
this.#element = new import_style_element.StyleElement(name);
|
|
39
|
-
this.#sheet = new import_style_sheet.StyleSheet(this.#element);
|
|
40
|
-
}
|
|
41
|
-
addMediaRule(id, options) {
|
|
42
|
-
let mediaRule = this.#mediaRules.get(id);
|
|
43
|
-
if (mediaRule === void 0) {
|
|
44
|
-
mediaRule = new import_rules.MediaRule(options);
|
|
45
|
-
this.#mediaRules.set(id, mediaRule);
|
|
46
|
-
this.#isDirty = true;
|
|
47
|
-
return mediaRule;
|
|
48
|
-
}
|
|
49
|
-
if (options) {
|
|
50
|
-
mediaRule.options = options;
|
|
51
|
-
this.#isDirty = true;
|
|
52
|
-
}
|
|
53
|
-
return mediaRule;
|
|
54
|
-
}
|
|
55
|
-
addStyleRule(selectorText, rule, transformValue) {
|
|
56
|
-
const mediaRule = this.addMediaRule(rule.breakpoint || defaultMediaRuleId);
|
|
57
|
-
this.#isDirty = true;
|
|
58
|
-
const styleRule = new import_rules.StyleRule(selectorText, rule.style, transformValue);
|
|
59
|
-
styleRule.onChange = this.#onChangeRule;
|
|
60
|
-
if (mediaRule === void 0) {
|
|
61
|
-
throw new Error("No media rule found");
|
|
62
|
-
}
|
|
63
|
-
mediaRule.insertRule(styleRule);
|
|
64
|
-
return styleRule;
|
|
65
|
-
}
|
|
66
|
-
addPlaintextRule(cssText) {
|
|
67
|
-
const rule = this.#plainRules.get(cssText);
|
|
68
|
-
if (rule !== void 0) {
|
|
69
|
-
return rule;
|
|
70
|
-
}
|
|
71
|
-
this.#isDirty = true;
|
|
72
|
-
return this.#plainRules.set(cssText, new import_rules.PlaintextRule(cssText));
|
|
73
|
-
}
|
|
74
|
-
addFontFaceRule(options) {
|
|
75
|
-
this.#isDirty = true;
|
|
76
|
-
return this.#fontFaceRules.push(new import_rules.FontFaceRule(options));
|
|
77
|
-
}
|
|
78
|
-
clear() {
|
|
79
|
-
this.#mediaRules.clear();
|
|
80
|
-
this.#plainRules.clear();
|
|
81
|
-
this.#fontFaceRules = [];
|
|
82
|
-
this.#isDirty = true;
|
|
83
|
-
}
|
|
84
|
-
render() {
|
|
85
|
-
this.#element.mount();
|
|
86
|
-
this.#sheet.replaceSync(this.cssText);
|
|
87
|
-
}
|
|
88
|
-
unmount() {
|
|
89
|
-
this.#element.unmount();
|
|
90
|
-
}
|
|
91
|
-
setAttribute(name, value) {
|
|
92
|
-
this.#element.setAttribute(name, value);
|
|
93
|
-
}
|
|
94
|
-
getAttribute(name) {
|
|
95
|
-
return this.#element.getAttribute(name);
|
|
96
|
-
}
|
|
97
|
-
get cssText() {
|
|
98
|
-
if (this.#isDirty === false) {
|
|
99
|
-
return this.#cssText;
|
|
100
|
-
}
|
|
101
|
-
this.#isDirty = false;
|
|
102
|
-
const css = [];
|
|
103
|
-
css.push(...this.#fontFaceRules.map((rule) => rule.cssText));
|
|
104
|
-
for (const plaintextRule of this.#plainRules.values()) {
|
|
105
|
-
css.push(plaintextRule.cssText);
|
|
106
|
-
}
|
|
107
|
-
const sortedMediaRules = Array.from(this.#mediaRules.values()).sort(
|
|
108
|
-
(ruleA, ruleB) => (0, import_compare_media.compareMedia)(ruleA.options, ruleB.options)
|
|
109
|
-
);
|
|
110
|
-
for (const mediaRule of sortedMediaRules) {
|
|
111
|
-
const { cssText } = mediaRule;
|
|
112
|
-
if (cssText !== "") {
|
|
113
|
-
css.push(cssText);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
this.#cssText = css.join("\n");
|
|
117
|
-
return this.#cssText;
|
|
118
|
-
}
|
|
119
|
-
#onChangeRule = () => {
|
|
120
|
-
this.#isDirty = true;
|
|
121
|
-
};
|
|
122
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var equal_media_exports = {};
|
|
20
|
-
__export(equal_media_exports, {
|
|
21
|
-
equalMedia: () => equalMedia
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(equal_media_exports);
|
|
24
|
-
const equalMedia = (left, right) => {
|
|
25
|
-
return left.minWidth === right.minWidth && left.maxWidth === right.maxWidth;
|
|
26
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var find_applicable_media_exports = {};
|
|
20
|
-
__export(find_applicable_media_exports, {
|
|
21
|
-
findApplicableMedia: () => findApplicableMedia
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(find_applicable_media_exports);
|
|
24
|
-
var import_compare_media = require("./compare-media");
|
|
25
|
-
var import_match_media = require("./match-media");
|
|
26
|
-
const findApplicableMedia = (media, width) => {
|
|
27
|
-
const sortedMedia = [...media].sort(import_compare_media.compareMedia).reverse();
|
|
28
|
-
for (const options of sortedMedia) {
|
|
29
|
-
if ((0, import_match_media.matchMedia)(options, width)) {
|
|
30
|
-
return options;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
package/lib/cjs/core/index.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var core_exports = {};
|
|
21
|
-
__export(core_exports, {
|
|
22
|
-
CssEngine: () => import_css_engine.CssEngine
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(core_exports);
|
|
25
|
-
var import_css_engine = require("./css-engine");
|
|
26
|
-
__reExport(core_exports, require("./create-css-engine"), module.exports);
|
|
27
|
-
__reExport(core_exports, require("./to-value"), module.exports);
|
|
28
|
-
__reExport(core_exports, require("./to-property"), module.exports);
|
|
29
|
-
__reExport(core_exports, require("./match-media"), module.exports);
|
|
30
|
-
__reExport(core_exports, require("./equal-media"), module.exports);
|
|
31
|
-
__reExport(core_exports, require("./compare-media"), module.exports);
|
|
32
|
-
__reExport(core_exports, require("./find-applicable-media"), module.exports);
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var match_media_exports = {};
|
|
20
|
-
__export(match_media_exports, {
|
|
21
|
-
matchMedia: () => matchMedia
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(match_media_exports);
|
|
24
|
-
const matchMedia = (options, width) => {
|
|
25
|
-
const minWidth = options.minWidth ?? Number.MIN_SAFE_INTEGER;
|
|
26
|
-
const maxWidth = options.maxWidth ?? Number.MAX_SAFE_INTEGER;
|
|
27
|
-
return width >= minWidth && width <= maxWidth;
|
|
28
|
-
};
|
package/lib/cjs/core/rules.js
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var rules_exports = {};
|
|
20
|
-
__export(rules_exports, {
|
|
21
|
-
FontFaceRule: () => FontFaceRule,
|
|
22
|
-
MediaRule: () => MediaRule,
|
|
23
|
-
PlaintextRule: () => PlaintextRule,
|
|
24
|
-
StyleRule: () => StyleRule
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(rules_exports);
|
|
27
|
-
var import_to_value = require("./to-value");
|
|
28
|
-
var import_to_property = require("./to-property");
|
|
29
|
-
class StylePropertyMap {
|
|
30
|
-
#styleMap = /* @__PURE__ */ new Map();
|
|
31
|
-
#isDirty = false;
|
|
32
|
-
#string = "";
|
|
33
|
-
#indent = 0;
|
|
34
|
-
#transformValue;
|
|
35
|
-
onChange;
|
|
36
|
-
constructor(transformValue) {
|
|
37
|
-
this.#transformValue = transformValue;
|
|
38
|
-
}
|
|
39
|
-
setTransformer(transformValue) {
|
|
40
|
-
this.#transformValue = transformValue;
|
|
41
|
-
}
|
|
42
|
-
set(property, value) {
|
|
43
|
-
this.#styleMap.set(property, value);
|
|
44
|
-
this.#isDirty = true;
|
|
45
|
-
this.onChange?.();
|
|
46
|
-
}
|
|
47
|
-
has(property) {
|
|
48
|
-
return this.#styleMap.has(property);
|
|
49
|
-
}
|
|
50
|
-
get size() {
|
|
51
|
-
return this.#styleMap.size;
|
|
52
|
-
}
|
|
53
|
-
keys() {
|
|
54
|
-
return this.#styleMap.keys();
|
|
55
|
-
}
|
|
56
|
-
delete(property) {
|
|
57
|
-
this.#styleMap.delete(property);
|
|
58
|
-
this.#isDirty = true;
|
|
59
|
-
this.onChange?.();
|
|
60
|
-
}
|
|
61
|
-
clear() {
|
|
62
|
-
this.#styleMap.clear();
|
|
63
|
-
this.#isDirty = true;
|
|
64
|
-
this.onChange?.();
|
|
65
|
-
}
|
|
66
|
-
toString({ indent = 0 } = {}) {
|
|
67
|
-
if (this.#isDirty === false && indent === this.#indent) {
|
|
68
|
-
return this.#string;
|
|
69
|
-
}
|
|
70
|
-
this.#indent = indent;
|
|
71
|
-
const block = [];
|
|
72
|
-
const spaces = " ".repeat(indent);
|
|
73
|
-
for (const [property, value] of this.#styleMap) {
|
|
74
|
-
if (value === void 0) {
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
block.push(
|
|
78
|
-
`${spaces}${(0, import_to_property.toProperty)(property)}: ${(0, import_to_value.toValue)(
|
|
79
|
-
value,
|
|
80
|
-
this.#transformValue
|
|
81
|
-
)}`
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
this.#string = block.join(";\n");
|
|
85
|
-
this.#isDirty = false;
|
|
86
|
-
return this.#string;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
class StyleRule {
|
|
90
|
-
styleMap;
|
|
91
|
-
selectorText;
|
|
92
|
-
onChange;
|
|
93
|
-
constructor(selectorText, style, transformValue) {
|
|
94
|
-
this.styleMap = new StylePropertyMap(transformValue);
|
|
95
|
-
this.selectorText = selectorText;
|
|
96
|
-
let property;
|
|
97
|
-
for (property in style) {
|
|
98
|
-
this.styleMap.set(property, style[property]);
|
|
99
|
-
}
|
|
100
|
-
this.styleMap.onChange = this.#onChange;
|
|
101
|
-
}
|
|
102
|
-
#onChange = () => {
|
|
103
|
-
this.onChange?.();
|
|
104
|
-
};
|
|
105
|
-
get cssText() {
|
|
106
|
-
return this.toString();
|
|
107
|
-
}
|
|
108
|
-
toString(options = { indent: 0 }) {
|
|
109
|
-
const spaces = " ".repeat(options.indent);
|
|
110
|
-
return `${spaces}${this.selectorText} {
|
|
111
|
-
${this.styleMap.toString({
|
|
112
|
-
indent: options.indent + 2
|
|
113
|
-
})}
|
|
114
|
-
${spaces}}`;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
class MediaRule {
|
|
118
|
-
options;
|
|
119
|
-
rules = [];
|
|
120
|
-
#mediaType;
|
|
121
|
-
constructor(options = {}) {
|
|
122
|
-
this.options = options;
|
|
123
|
-
this.#mediaType = options.mediaType ?? "all";
|
|
124
|
-
}
|
|
125
|
-
insertRule(rule) {
|
|
126
|
-
this.rules.push(rule);
|
|
127
|
-
return rule;
|
|
128
|
-
}
|
|
129
|
-
get cssText() {
|
|
130
|
-
return this.toString();
|
|
131
|
-
}
|
|
132
|
-
toString() {
|
|
133
|
-
if (this.rules.length === 0) {
|
|
134
|
-
return "";
|
|
135
|
-
}
|
|
136
|
-
const rules = [];
|
|
137
|
-
for (const rule of this.rules) {
|
|
138
|
-
rules.push(rule.toString({ indent: 2 }));
|
|
139
|
-
}
|
|
140
|
-
let conditionText = "";
|
|
141
|
-
const { minWidth, maxWidth } = this.options;
|
|
142
|
-
if (minWidth !== void 0) {
|
|
143
|
-
conditionText = ` and (min-width: ${minWidth}px)`;
|
|
144
|
-
}
|
|
145
|
-
if (maxWidth !== void 0) {
|
|
146
|
-
conditionText += ` and (max-width: ${maxWidth}px)`;
|
|
147
|
-
}
|
|
148
|
-
return `@media ${this.#mediaType}${conditionText} {
|
|
149
|
-
${rules.join(
|
|
150
|
-
"\n"
|
|
151
|
-
)}
|
|
152
|
-
}`;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
class PlaintextRule {
|
|
156
|
-
cssText;
|
|
157
|
-
styleMap = new StylePropertyMap();
|
|
158
|
-
constructor(cssText) {
|
|
159
|
-
this.cssText = cssText;
|
|
160
|
-
}
|
|
161
|
-
toString() {
|
|
162
|
-
return this.cssText;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
class FontFaceRule {
|
|
166
|
-
options;
|
|
167
|
-
constructor(options) {
|
|
168
|
-
this.options = options;
|
|
169
|
-
}
|
|
170
|
-
get cssText() {
|
|
171
|
-
return this.toString();
|
|
172
|
-
}
|
|
173
|
-
toString() {
|
|
174
|
-
const decls = [];
|
|
175
|
-
const { fontFamily, fontStyle, fontWeight, fontDisplay, src } = this.options;
|
|
176
|
-
decls.push(
|
|
177
|
-
`font-family: ${/\s/.test(fontFamily) ? `"${fontFamily}"` : fontFamily}`
|
|
178
|
-
);
|
|
179
|
-
decls.push(`font-style: ${fontStyle}`);
|
|
180
|
-
decls.push(`font-weight: ${fontWeight}`);
|
|
181
|
-
decls.push(`font-display: ${fontDisplay}`);
|
|
182
|
-
decls.push(`src: ${src}`);
|
|
183
|
-
return `@font-face {
|
|
184
|
-
${decls.join("; ")};
|
|
185
|
-
}`;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var style_element_exports = {};
|
|
20
|
-
__export(style_element_exports, {
|
|
21
|
-
StyleElement: () => StyleElement
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(style_element_exports);
|
|
24
|
-
class StyleElement {
|
|
25
|
-
#element;
|
|
26
|
-
#name;
|
|
27
|
-
constructor(name = "") {
|
|
28
|
-
this.#name = name;
|
|
29
|
-
}
|
|
30
|
-
get isMounted() {
|
|
31
|
-
return this.#element?.parentElement != null;
|
|
32
|
-
}
|
|
33
|
-
mount() {
|
|
34
|
-
if (this.isMounted === false) {
|
|
35
|
-
this.#element = document.createElement("style");
|
|
36
|
-
this.#element.setAttribute("data-webstudio", this.#name);
|
|
37
|
-
document.head.appendChild(this.#element);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
unmount() {
|
|
41
|
-
if (this.isMounted) {
|
|
42
|
-
this.#element?.parentElement?.removeChild(this.#element);
|
|
43
|
-
this.#element = void 0;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
render(cssText) {
|
|
47
|
-
if (this.#element) {
|
|
48
|
-
this.#element.textContent = cssText;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
setAttribute(name, value) {
|
|
52
|
-
if (this.#element) {
|
|
53
|
-
this.#element.setAttribute(name, value);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
getAttribute(name) {
|
|
57
|
-
if (this.#element) {
|
|
58
|
-
return this.#element.getAttribute(name);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var style_sheet_exports = {};
|
|
20
|
-
__export(style_sheet_exports, {
|
|
21
|
-
StyleSheet: () => StyleSheet
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(style_sheet_exports);
|
|
24
|
-
class StyleSheet {
|
|
25
|
-
#cssText = "";
|
|
26
|
-
#element;
|
|
27
|
-
constructor(element) {
|
|
28
|
-
this.#element = element;
|
|
29
|
-
}
|
|
30
|
-
replaceSync(cssText) {
|
|
31
|
-
if (cssText !== this.#cssText) {
|
|
32
|
-
this.#cssText = cssText;
|
|
33
|
-
this.#element.render(cssText);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|