@webstudio-is/css-engine 0.206.0 → 0.207.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/index.js CHANGED
@@ -249,7 +249,6 @@ var StyleValue = z.union([
249
249
  UnsetValue,
250
250
  VarValue
251
251
  ]);
252
- var Style = z.record(z.string(), StyleValue);
253
252
 
254
253
  // src/css.ts
255
254
  var cssWideKeywords = /* @__PURE__ */ new Set([
package/lib/runtime.js ADDED
@@ -0,0 +1,98 @@
1
+ // src/core/to-value.ts
2
+ import { DEFAULT_FONT_FALLBACK, SYSTEM_FONTS } from "@webstudio-is/fonts";
3
+ var fallbackTransform = (styleValue) => {
4
+ if (styleValue.type !== "fontFamily") {
5
+ return;
6
+ }
7
+ let { value } = styleValue;
8
+ if (value.length === 0) {
9
+ value = [DEFAULT_FONT_FALLBACK];
10
+ }
11
+ if (value.length === 1) {
12
+ const stack = SYSTEM_FONTS.get(value[0])?.stack;
13
+ value = stack ?? [value[0], DEFAULT_FONT_FALLBACK];
14
+ }
15
+ return {
16
+ type: "fontFamily",
17
+ value: Array.from(new Set(value))
18
+ };
19
+ };
20
+ var sanitizeCssUrl = (str) => JSON.stringify(str);
21
+ var toValue = (styleValue, transformValue) => {
22
+ if (styleValue === void 0) {
23
+ return "";
24
+ }
25
+ const transformedValue = transformValue?.(styleValue) ?? fallbackTransform(styleValue);
26
+ const value = transformedValue ?? styleValue;
27
+ if (value.type === "unit") {
28
+ return value.value + (value.unit === "number" ? "" : value.unit);
29
+ }
30
+ if (value.type === "fontFamily") {
31
+ const families = [];
32
+ for (const family of value.value) {
33
+ families.push(family.includes(" ") ? `"${family}"` : family);
34
+ }
35
+ return families.join(", ");
36
+ }
37
+ if (value.type === "var") {
38
+ if (value.hidden) {
39
+ return "";
40
+ }
41
+ let fallbacksString = "";
42
+ if (value.fallback) {
43
+ fallbacksString = `, ${toValue(value.fallback, transformValue)}`;
44
+ }
45
+ return `var(--${value.value}${fallbacksString})`;
46
+ }
47
+ if (value.type === "keyword") {
48
+ if (value.hidden === true) {
49
+ return "";
50
+ }
51
+ return value.value;
52
+ }
53
+ if (value.type === "invalid") {
54
+ return value.value;
55
+ }
56
+ if (value.type === "unset") {
57
+ return value.value;
58
+ }
59
+ if (value.type === "rgb") {
60
+ return `rgba(${value.r}, ${value.g}, ${value.b}, ${value.alpha})`;
61
+ }
62
+ if (value.type === "image") {
63
+ if (value.hidden || value.value.type !== "url") {
64
+ return "none";
65
+ }
66
+ return `url(${sanitizeCssUrl(value.value.url)})`;
67
+ }
68
+ if (value.type === "unparsed") {
69
+ if (value.hidden === true) {
70
+ return "none";
71
+ }
72
+ return value.value;
73
+ }
74
+ if (value.type === "layers") {
75
+ const valueString = value.value.filter((layer) => layer.hidden !== true).map((layer) => toValue(layer, transformValue)).join(", ");
76
+ return valueString === "" ? "none" : valueString;
77
+ }
78
+ if (value.type === "tuple") {
79
+ if (value.hidden === true) {
80
+ return "none";
81
+ }
82
+ return value.value.filter((value2) => value2.hidden !== true).map((value2) => toValue(value2, transformValue)).join(" ");
83
+ }
84
+ if (value.type === "function") {
85
+ if (value.hidden === true) {
86
+ return "";
87
+ }
88
+ return `${value.name}(${toValue(value.args, transformValue)})`;
89
+ }
90
+ if (value.type === "guaranteedInvalid") {
91
+ return "";
92
+ }
93
+ value;
94
+ return "";
95
+ };
96
+ export {
97
+ toValue
98
+ };
@@ -2,3 +2,4 @@ export * from "./core/index";
2
2
  export * from "./schema";
3
3
  export * from "./css";
4
4
  export type { Unit as __Unit } from "./__generated__/types";
5
+ export type { HyphenatedProperty as __HyphenatedProperty } from "./__generated__/types";
@@ -0,0 +1 @@
1
+ export { toValue } from "./core/to-value";
@@ -3923,9 +3923,4 @@ export declare const StyleValue: z.ZodUnion<[z.ZodObject<{
3923
3923
  hidden?: boolean | undefined;
3924
3924
  }>]>;
3925
3925
  export type StyleValue = z.infer<typeof StyleValue>;
3926
- export type Style = {
3927
- [property in StyleProperty]?: StyleValue;
3928
- } & {
3929
- [property: CustomProperty]: StyleValue;
3930
- };
3931
3926
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/css-engine",
3
- "version": "0.206.0",
3
+ "version": "0.207.0",
4
4
  "description": "CSS Renderer for Webstudio",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -8,20 +8,27 @@
8
8
  "dependencies": {
9
9
  "@emotion/hash": "^0.9.2",
10
10
  "zod": "^3.22.4",
11
- "@webstudio-is/fonts": "0.206.0"
11
+ "@webstudio-is/fonts": "0.207.0"
12
12
  },
13
13
  "devDependencies": {
14
14
  "@types/react": "^18.2.70",
15
15
  "@types/react-dom": "^18.2.25",
16
16
  "react": "18.3.0-canary-14898b6a9-20240318",
17
17
  "react-dom": "18.3.0-canary-14898b6a9-20240318",
18
- "vitest": "^3.0.4",
18
+ "vitest": "^3.0.8",
19
19
  "@webstudio-is/tsconfig": "1.0.7"
20
20
  },
21
21
  "exports": {
22
- "webstudio": "./src/index.ts",
23
- "types": "./lib/types/index.d.ts",
24
- "import": "./lib/index.js"
22
+ ".": {
23
+ "webstudio": "./src/index.ts",
24
+ "types": "./lib/types/index.d.ts",
25
+ "import": "./lib/index.js"
26
+ },
27
+ "./runtime": {
28
+ "webstudio": "./src/runtime.ts",
29
+ "types": "./lib/types/runtime.d.ts",
30
+ "import": "./lib/runtime.js"
31
+ }
25
32
  },
26
33
  "files": [
27
34
  "lib/*",
@@ -32,7 +39,7 @@
32
39
  "sideEffects": false,
33
40
  "scripts": {
34
41
  "typecheck": "tsc",
35
- "build": "rm -rf lib && esbuild src/index.ts --outdir=lib --bundle --format=esm --packages=external",
42
+ "build": "rm -rf lib && esbuild src/index.ts --outdir=lib --bundle --format=esm --packages=external && esbuild src/runtime.ts --outdir=lib --bundle --format=esm --packages=external",
36
43
  "dts": "tsc --project tsconfig.dts.json",
37
44
  "test": "vitest run"
38
45
  }