@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/src/core/to-value.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import type { StyleValue } from "@webstudio-is/css-data";
|
|
2
|
-
import { captureError } from "@webstudio-is/error-utils";
|
|
3
|
-
import { DEFAULT_FONT_FALLBACK, SYSTEM_FONTS } from "@webstudio-is/fonts";
|
|
4
|
-
|
|
5
|
-
export type TransformValue = (styleValue: StyleValue) => undefined | StyleValue;
|
|
6
|
-
|
|
7
|
-
const fallbackTransform: TransformValue = (styleValue) => {
|
|
8
|
-
if (styleValue.type === "fontFamily") {
|
|
9
|
-
const firstFontFamily = styleValue.value[0];
|
|
10
|
-
const fallbacks = SYSTEM_FONTS.get(firstFontFamily);
|
|
11
|
-
const fontFamily: string[] = [...styleValue.value];
|
|
12
|
-
if (Array.isArray(fallbacks)) {
|
|
13
|
-
fontFamily.push(...fallbacks);
|
|
14
|
-
} else {
|
|
15
|
-
fontFamily.push(DEFAULT_FONT_FALLBACK);
|
|
16
|
-
}
|
|
17
|
-
return {
|
|
18
|
-
type: "fontFamily",
|
|
19
|
-
value: fontFamily,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const toValue = (
|
|
25
|
-
styleValue: undefined | StyleValue,
|
|
26
|
-
transformValue?: TransformValue
|
|
27
|
-
): string => {
|
|
28
|
-
if (styleValue === undefined) {
|
|
29
|
-
return "";
|
|
30
|
-
}
|
|
31
|
-
const transformedValue =
|
|
32
|
-
transformValue?.(styleValue) ?? fallbackTransform(styleValue);
|
|
33
|
-
const value = transformedValue ?? styleValue;
|
|
34
|
-
if (value.type === "unit") {
|
|
35
|
-
return value.value + (value.unit === "number" ? "" : value.unit);
|
|
36
|
-
}
|
|
37
|
-
if (value.type === "fontFamily") {
|
|
38
|
-
return value.value.join(", ");
|
|
39
|
-
}
|
|
40
|
-
if (value.type === "var") {
|
|
41
|
-
const fallbacks = [];
|
|
42
|
-
for (const fallback of value.fallbacks) {
|
|
43
|
-
fallbacks.push(toValue(fallback, transformValue));
|
|
44
|
-
}
|
|
45
|
-
const fallbacksString =
|
|
46
|
-
fallbacks.length > 0 ? `, ${fallbacks.join(", ")}` : "";
|
|
47
|
-
return `var(--${value.value}${fallbacksString})`;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (value.type === "keyword") {
|
|
51
|
-
return value.value;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (value.type === "invalid") {
|
|
55
|
-
return value.value;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (value.type === "unset") {
|
|
59
|
-
return value.value;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (value.type === "rgb") {
|
|
63
|
-
return `rgba(${value.r}, ${value.g}, ${value.b}, ${value.alpha})`;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (value.type === "image") {
|
|
67
|
-
if (value.hidden || value.value.type !== "url") {
|
|
68
|
-
// We assume that property is background-image and use this to hide background layers
|
|
69
|
-
// In the future we might want to have a more generic way to hide values
|
|
70
|
-
// i.e. have knowledge about property-name, as none is property specific
|
|
71
|
-
return "none";
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// @todo image-set
|
|
75
|
-
return `url(${value.value.url})`;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (value.type === "unparsed") {
|
|
79
|
-
if (value.hidden) {
|
|
80
|
-
// We assume that property is background-image and use this to hide background layers
|
|
81
|
-
// In the future we might want to have a more generic way to hide values
|
|
82
|
-
// i.e. have knowledge about property-name, as none is property specific
|
|
83
|
-
return "none";
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return value.value;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (value.type === "layers") {
|
|
90
|
-
const valueString = value.value
|
|
91
|
-
.filter(
|
|
92
|
-
(layer) =>
|
|
93
|
-
"hidden" in layer === false ||
|
|
94
|
-
("hidden" in layer && layer.hidden === false)
|
|
95
|
-
)
|
|
96
|
-
.map((layer) => {
|
|
97
|
-
return toValue(layer, transformValue);
|
|
98
|
-
})
|
|
99
|
-
.join(", ");
|
|
100
|
-
return valueString === "" ? "none" : valueString;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (value.type === "tuple") {
|
|
104
|
-
return value.value.map((value) => toValue(value, transformValue)).join(" ");
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return captureError(new Error("Unknown value type"), value);
|
|
108
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./core";
|