Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

feat: support -webkit-line-clamp (#3640)

Bogdan Chadkina7676c504291
diff --git a/packages/css-data/bin/mdn-data.ts b/packages/css-data/bin/mdn-data.ts
index 79b7876c01..2c937808d1 100755
--- a/packages/css-data/bin/mdn-data.ts
+++ b/packages/css-data/bin/mdn-data.ts
@@ -17,6 +17,18 @@ import type {
} from "@webstudio-is/css-engine";
import * as customData from "../src/custom-data";
+/**
+ * Store prefixed properties without change
+ * and convert to camel case only unprefixed properties
+ * @todo stop converting to camel case and use hyphenated format
+ */
+const normalizePropertyName = (property: string) => {
+ if (property.startsWith("-")) {
+ return property;
+ }
+ return camelCase(property);
+};
+
const units: Record<customData.UnitGroup, Array<string>> = {
number: [],
// consider % as unit
@@ -228,15 +240,11 @@ type FilteredProperties = { [property in Property]: Value };
const experimentalProperties = [
"appearance",
"aspect-ratio",
- // not standard and not implemented without prefix
- // @todo get rid once the issue with types in radix sdk is resolved
- "line-clamp",
- // used in normalize
"text-size-adjust",
+ "-webkit-line-clamp",
];
const unsupportedProperties = [
- "-webkit-line-clamp",
"--*",
// shorthand properties
"all",
@@ -278,7 +286,9 @@ const filteredProperties: FilteredProperties = (() => {
return result;
})();
-const propertiesData = { ...customData.propertiesData };
+const propertiesData = {
+ ...customData.propertiesData,
+};
let property: Property;
for (property in filteredProperties) {
@@ -314,7 +324,7 @@ for (property in filteredProperties) {
);
}
- propertiesData[camelCase(property)] = {
+ propertiesData[normalizePropertyName(property)] = {
unitGroups: Array.from(unitGroups),
inherited: config.inherited,
initial: parseInitialValue(property, config.initial, unitGroups),
@@ -379,7 +389,7 @@ const keywordValues = (() => {
}
if (keywords.size !== 0) {
- const key = camelCase(property);
+ const key = normalizePropertyName(property);
result[key] = [...(result[key] ?? []), ...keywords];
}
}
diff --git a/packages/css-data/src/__generated__/animatable-properties.ts b/packages/css-data/src/__generated__/animatable-properties.ts
index 5f1aa82c9a..6af90b197a 100644
--- a/packages/css-data/src/__generated__/animatable-properties.ts
+++ b/packages/css-data/src/__generated__/animatable-properties.ts
@@ -84,7 +84,6 @@ export const animatableProperties = [
"inset-inline-start",
"left",
"letter-spacing",
- "line-clamp",
"line-height",
"margin-block-end",
"margin-block-start",
diff --git a/packages/css-data/src/__generated__/keyword-values.ts b/packages/css-data/src/__generated__/keyword-values.ts
index 94ab987995..06f8d6dbec 100644
--- a/packages/css-data/src/__generated__/keyword-values.ts
+++ b/packages/css-data/src/__generated__/keyword-values.ts
@@ -2,6 +2,7 @@
export const keywordValues = {
WebkitFontSmoothing: ["auto", "none", "antialiased", "subpixel-antialiased"],
MozOsxFontSmoothing: ["auto", "grayscale"],
+ "-webkit-box-orient": ["horizontal", "vertical"],
listStyleType: [
"disc",
"circle",
@@ -15,6 +16,7 @@ export const keywordValues = {
"inherit",
"unset",
],
+ "-webkit-line-clamp": ["none", "initial", "inherit", "unset"],
accentColor: [
"auto",
"transparent",
@@ -3485,7 +3487,6 @@ export const keywordValues = {
"inherit",
"unset",
],
- lineClamp: ["none", "initial", "inherit", "unset"],
lineHeight: ["normal", "initial", "inherit", "unset"],
listStyleImage: ["none", "initial", "inherit", "unset"],
listStylePosition: ["inside", "outside", "initial", "inherit", "unset"],
diff --git a/packages/css-data/src/__generated__/properties.ts b/packages/css-data/src/__generated__/properties.ts
index 786ab8c359..92e643c86e 100644
--- a/packages/css-data/src/__generated__/properties.ts
+++ b/packages/css-data/src/__generated__/properties.ts
@@ -18,6 +18,24 @@ export const properties = {
},
types: [],
},
+ "-webkit-box-orient": {
+ unitGroups: [],
+ inherited: false,
+ initial: {
+ type: "keyword",
+ value: "horizontal",
+ },
+ types: [],
+ },
+ "-webkit-line-clamp": {
+ unitGroups: ["number"],
+ inherited: false,
+ initial: {
+ type: "keyword",
+ value: "none",
+ },
+ types: ["integer"],
+ },
accentColor: {
unitGroups: [],
inherited: true,
@@ -1541,15 +1559,6 @@ export const properties = {
},
types: [],
},
- lineClamp: {
- unitGroups: ["number"],
- inherited: false,
- initial: {
- type: "keyword",
- value: "none",
- },
- types: ["integer"],
- },
lineHeight: {
unitGroups: ["number", "length", "percentage"],
inherited: true,
diff --git a/packages/css-data/src/custom-data.ts b/packages/css-data/src/custom-data.ts
index 8f95a9f128..ea55014b39 100644
--- a/packages/css-data/src/custom-data.ts
+++ b/packages/css-data/src/custom-data.ts
@@ -70,6 +70,14 @@ propertiesData.MozOsxFontSmoothing = {
};
keywordValues.MozOsxFontSmoothing = ["auto", "grayscale"];
+propertiesData["-webkit-box-orient"] = {
+ unitGroups: [],
+ inherited: false,
+ initial: { type: "keyword", value: "horizontal" },
+ types: [],
+};
+keywordValues["-webkit-box-orient"] = ["horizontal", "vertical"];
+
keywordValues.listStyleType = [
"disc",
"circle",
diff --git a/packages/css-data/src/parse-css-value.ts b/packages/css-data/src/parse-css-value.ts
index c36b78d825..34952438df 100644
--- a/packages/css-data/src/parse-css-value.ts
+++ b/packages/css-data/src/parse-css-value.ts
@@ -16,7 +16,6 @@ import {
parseShadow,
parseTransitionLonghandProperty,
} from "./property-parsers";
-import { camelCase } from "change-case";
export const cssTryParseValue = (input: string) => {
try {
@@ -156,8 +155,7 @@ export const parseCssValue = (
}
if (first?.type === "Identifier") {
- const values =
- keywordValues[camelCase(property) as keyof typeof keywordValues];
+ const values = keywordValues[property as keyof typeof keywordValues];
if (values === undefined) {
return {
type: "invalid",
diff --git a/packages/css-data/src/parse-css.test.ts b/packages/css-data/src/parse-css.test.ts
index dfea896b55..add723437c 100644
--- a/packages/css-data/src/parse-css.test.ts
+++ b/packages/css-data/src/parse-css.test.ts
@@ -675,18 +675,18 @@ describe("Parse CSS", () => {
// @todo parser is wrong here, it should be keyword horizontal
expect(parseCss(`a { -webkit-box-orient: horizontal; }`))
.toMatchInlineSnapshot(`
- {
- "a": [
- {
- "property": "WebkitBoxOrient",
- "value": {
- "type": "invalid",
- "value": "",
- },
- },
- ],
- }
- `);
+{
+ "a": [
+ {
+ "property": "-webkit-box-orient",
+ "value": {
+ "type": "keyword",
+ "value": "horizontal",
+ },
+ },
+ ],
+}
+`);
});
test("parse child combinator", () => {
diff --git a/packages/css-data/src/parse-css.ts b/packages/css-data/src/parse-css.ts
index 5b1a645128..e632b369d2 100644
--- a/packages/css-data/src/parse-css.ts
+++ b/packages/css-data/src/parse-css.ts
@@ -12,6 +12,25 @@ import { camelCase } from "change-case";
import { expandShorthands } from "./shorthands";
import { parseBackground } from "./property-parsers";
+/**
+ * Store prefixed properties without change
+ * and convert to camel case only unprefixed properties
+ * @todo stop converting to camel case and use hyphenated format
+ */
+export const normalizePropertyName = (property: string) => {
+ // these are manually added with pascal case
+ if (property === "-webkit-font-smoothing") {
+ return "WebkitFontSmoothing";
+ }
+ if (property === "-moz-osx-font-smoothing") {
+ return "MozOsxFontSmoothing";
+ }
+ if (property.startsWith("-")) {
+ return property;
+ }
+ return camelCase(property);
+};
+
// @todo we don't parse correctly most of them if not all
const prefixedProperties = [
"-webkit-box-orient",
@@ -31,14 +50,6 @@ const unprefixProperty = (property: string) => {
return property.replace(prefixRegex, "");
};
-const camelCaseProperty = (property: string) => {
- let camelcased = camelCase(property);
- if (property[0] === "-") {
- camelcased = camelcased[0].toLocaleUpperCase() + camelcased.slice(1);
- }
- return camelcased;
-};
-
type Selector = string;
export type Styles = Record<Selector, Array<EmbedTemplateStyleDecl>>;
@@ -46,7 +57,7 @@ export type Styles = Record<Selector, Array<EmbedTemplateStyleDecl>>;
type Longhand = keyof typeof toLonghand;
const parseCssValue = (
- property: Longhand | StyleProperty,
+ property: string,
value: string
): Map<StyleProperty, StyleValue> => {
const unwrap = toLonghand[property as Longhand];
@@ -88,22 +99,23 @@ const parseCssValue = (
const expanded = new Map(expandShorthands([[property, value]]));
const final = new Map();
for (const [property, value] of expanded) {
+ const normalizedProperty = normalizePropertyName(property);
if (value === "") {
// Keep the browser behavior when property is defined with an empty value e.g. `color:;`
// It may override some existing value and effectively set it to "unset";
- final.set(property, { type: "keyword", value: "unset" });
+ final.set(normalizedProperty, { type: "keyword", value: "unset" });
continue;
}
// @todo https://github.com/webstudio-is/webstudio/issues/3399
if (value.startsWith("var(")) {
- final.set(property, { type: "keyword", value: "unset" });
+ final.set(normalizedProperty, { type: "keyword", value: "unset" });
continue;
}
final.set(
- property,
- parseCssValueLonghand(property as StyleProperty, value)
+ normalizedProperty,
+ parseCssValueLonghand(normalizedProperty as StyleProperty, value)
);
}
return final;
@@ -239,7 +251,7 @@ export const parseCss = (css: string) => {
const stringValue = csstree.generate(node.value);
const parsedCss = parseCssValue(
- unprefixProperty(node.property) as Longhand | StyleProperty,
+ unprefixProperty(node.property),
stringValue
);
@@ -252,7 +264,7 @@ export const parseCss = (css: string) => {
declarations = styles[selector] = [];
}
const styleDecl: EmbedTemplateStyleDecl = {
- property: camelCaseProperty(
+ property: normalizePropertyName(
unprefixProperty(property)
) as StyleProperty,
value,
diff --git a/packages/css-engine/src/__generated__/types.ts b/packages/css-engine/src/__generated__/types.ts
index 64e37c6e22..fc4e3c5053 100644
--- a/packages/css-engine/src/__generated__/types.ts
+++ b/packages/css-engine/src/__generated__/types.ts
@@ -1,6 +1,8 @@
export type Property =
| "WebkitFontSmoothing"
| "MozOsxFontSmoothing"
+ | "-webkit-box-orient"
+ | "-webkit-line-clamp"
| "accentColor"
| "alignContent"
| "alignItems"
@@ -167,7 +169,6 @@ export type Property =
| "left"
| "letterSpacing"
| "lineBreak"
- | "lineClamp"
| "lineHeight"
| "listStyleImage"
| "listStylePosition"
diff --git a/packages/sdk-components-react-radix/scripts/generate-tailwind-theme.ts b/packages/sdk-components-react-radix/scripts/generate-tailwind-theme.ts
index 7dc71368e7..b38d0c0ce8 100644
--- a/packages/sdk-components-react-radix/scripts/generate-tailwind-theme.ts
+++ b/packages/sdk-components-react-radix/scripts/generate-tailwind-theme.ts
@@ -135,7 +135,7 @@ const generatedThemeData: GeneratedThemeItem[] = [
},
{
name: "lineClamp",
- values: parsePropertyValues("lineClamp", theme.lineClamp),
+ values: parsePropertyValues("-webkit-line-clamp", theme.lineClamp),
},
{
name: "textUnderlineOffset",