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.

experimental: support last shorthands (#3657)

Bogdan Chadkin373eacaf7c47
diff --git a/apps/builder/app/shared/copy-paste/plugin-webflow/__generated__/style-presets.ts b/apps/builder/app/shared/copy-paste/plugin-webflow/__generated__/style-presets.ts
index 0986c529e0..b6cdaba570 100644
--- a/apps/builder/app/shared/copy-paste/plugin-webflow/__generated__/style-presets.ts
+++ b/apps/builder/app/shared/copy-paste/plugin-webflow/__generated__/style-presets.ts
@@ -918,13 +918,6 @@ export const styles = {
value: 1,
},
},
- {
- property: "all",
- value: {
- type: "keyword",
- value: "inherit",
- },
- },
],
code: [
{
diff --git a/packages/css-data/src/shorthands.test.ts b/packages/css-data/src/shorthands.test.ts
index ddf4d02393..4cad0abc49 100644
--- a/packages/css-data/src/shorthands.test.ts
+++ b/packages/css-data/src/shorthands.test.ts
@@ -1,6 +1,15 @@
import { expect, test } from "@jest/globals";
import { expandShorthands } from "./shorthands";
+test("ignore all shorthand to not bloat webstudio data", () => {
+ expect(
+ expandShorthands([
+ ["all", "initial"],
+ ["color", "red"],
+ ])
+ ).toEqual([["color", "red"]]);
+});
+
test("expand border", () => {
expect(expandShorthands([["border", "1px solid red"]])).toEqual([
["border-top-width", "1px"],
@@ -768,6 +777,52 @@ test("expand animation with css-wide keywords", () => {
]);
});
+test("expand animation-range", () => {
+ expect(expandShorthands([["animation-range", "normal"]])).toEqual([
+ ["animation-range-start", "normal"],
+ ["animation-range-end", "normal"],
+ ]);
+ expect(expandShorthands([["animation-range", "100px"]])).toEqual([
+ ["animation-range-start", "100px"],
+ ["animation-range-end", "normal"],
+ ]);
+ expect(expandShorthands([["animation-range", "entry 10% exit"]])).toEqual([
+ ["animation-range-start", "entry 10%"],
+ ["animation-range-end", "exit"],
+ ]);
+ expect(expandShorthands([["animation-range", "100px, 200px 50px"]])).toEqual([
+ ["animation-range-start", "100px,200px"],
+ ["animation-range-end", "normal,50px"],
+ ]);
+});
+
+test("expand view-timeline", () => {
+ expect(expandShorthands([["view-timeline", `none`]])).toEqual([
+ ["view-timeline-name", "none"],
+ ["view-timeline-axis", "block"],
+ ["view-timeline-inset", "auto"],
+ ]);
+ expect(expandShorthands([["view-timeline", `none inline 200px`]])).toEqual([
+ ["view-timeline-name", "none"],
+ ["view-timeline-axis", "inline"],
+ ["view-timeline-inset", "200px"],
+ ]);
+ expect(
+ expandShorthands([["view-timeline", `--custom_name_for_timeline inline`]])
+ ).toEqual([
+ ["view-timeline-name", "--custom_name_for_timeline"],
+ ["view-timeline-axis", "inline"],
+ ["view-timeline-inset", "auto"],
+ ]);
+ expect(
+ expandShorthands([["view-timeline", `none inline, --custom y`]])
+ ).toEqual([
+ ["view-timeline-name", "none,--custom"],
+ ["view-timeline-axis", "inline,y"],
+ ["view-timeline-inset", "auto,auto"],
+ ]);
+});
+
test("expand transition", () => {
expect(
expandShorthands([["transition", `margin-right 4s ease-in-out 1s`]])
@@ -1349,14 +1404,47 @@ test("expand background", () => {
]);
});
-test.todo("all - can negatively affect build size");
-// https://developer.mozilla.org/en-US/docs/Web/CSS/animation-range
-test.todo("animation-range");
-// https://developer.mozilla.org/en-US/docs/Web/CSS/view-timeline
-test.todo("view-timeline");
-// https://www.w3.org/TR/css-anchor-position-1/#position-try-prop
-test.todo("position-try - not used in webflow");
-// https://www.w3.org/TR/css-ui-4/
-test.todo("caret - caret-color & caret-shape");
-// https://developer.mozilla.org/en-US/docs/Web/CSS/overscroll-behavior
-test.todo("overscroll-behavior");
+test("expand caret", () => {
+ expect(expandShorthands([["caret", "red"]])).toEqual([
+ ["caret-color", "red"],
+ ["caret-shape", "auto"],
+ ]);
+ expect(expandShorthands([["caret", "block"]])).toEqual([
+ ["caret-color", "auto"],
+ ["caret-shape", "block"],
+ ]);
+ expect(expandShorthands([["caret", "block red"]])).toEqual([
+ ["caret-color", "red"],
+ ["caret-shape", "block"],
+ ]);
+});
+
+test("expand overscroll-behavior", () => {
+ expect(expandShorthands([["overscroll-behavior", "auto"]])).toEqual([
+ ["overscroll-behavior-x", "auto"],
+ ["overscroll-behavior-y", "auto"],
+ ]);
+ expect(expandShorthands([["overscroll-behavior", "contain"]])).toEqual([
+ ["overscroll-behavior-x", "contain"],
+ ["overscroll-behavior-y", "contain"],
+ ]);
+ expect(expandShorthands([["overscroll-behavior", "contain none"]])).toEqual([
+ ["overscroll-behavior-x", "contain"],
+ ["overscroll-behavior-y", "none"],
+ ]);
+});
+
+test("expand position-try", () => {
+ expect(expandShorthands([["position-try", "none"]])).toEqual([
+ ["position-try-order", "normal"],
+ ["position-try-options", "none"],
+ ]);
+ expect(expandShorthands([["position-try", "most-width none"]])).toEqual([
+ ["position-try-order", "most-width"],
+ ["position-try-options", "none"],
+ ]);
+ expect(expandShorthands([["position-try", "--dashed-ident"]])).toEqual([
+ ["position-try-order", "normal"],
+ ["position-try-options", "--dashed-ident"],
+ ]);
+});
diff --git a/packages/css-data/src/shorthands.ts b/packages/css-data/src/shorthands.ts
index 00f9c4f556..df4cbeabe4 100644
--- a/packages/css-data/src/shorthands.ts
+++ b/packages/css-data/src/shorthands.ts
@@ -477,6 +477,35 @@ const expandAnimation = function* (value: CssNode) {
yield ["animation-range-end", createIdentifier("normal")] as const;
};
+/**
+ *
+ * animation-range = [ <'animation-range-start'> <'animation-range-end'>? ]#
+ *
+ * <animation-range-start> =
+ * [ normal | <length-percentage> | <timeline-range-name> <length-percentage>? ]#
+ *
+ * <animation-range-end> =
+ * [ normal | <length-percentage> | <timeline-range-name> <length-percentage>? ]#
+ *
+ */
+const expandAnimationRange = function* (value: CssNode) {
+ const [start, end] = parseRepeated(value, (single) => {
+ const [start, end] = parseUnordered(
+ [
+ `normal | <length-percentage> | <ident> <length-percentage>?`,
+ `normal | <length-percentage> | <ident> <length-percentage>?`,
+ ],
+ single
+ );
+ return [
+ start ?? createIdentifier("normal"),
+ end ?? createIdentifier("normal"),
+ ];
+ });
+ yield ["animation-range-start", start] as const;
+ yield ["animation-range-end", end] as const;
+};
+
/**
*
* transition = <single-transition>#
@@ -676,6 +705,39 @@ const expandScrollTimeline = function* (value: CssNode) {
yield ["scroll-timeline-axis", axis] as const;
};
+/**
+ *
+ * view-timeline =
+ * [ <'view-timeline-name'> [ <'view-timeline-axis'> || <'view-timeline-inset'> ]? ]#
+ *
+ * <view-timeline-name> = [ none | <dashed-ident> ]#
+ *
+ * <view-timeline-axis> = [ block | inline | x | y ]#
+ *
+ * <view-timeline-inset> = [ [ auto | <length-percentage> ]{1,2} ]#
+ *
+ */
+const expandViewTimeline = function* (value: CssNode) {
+ const [name, axis, inset] = parseRepeated(value, (single) => {
+ const [name, axis, inset] = parseUnordered(
+ [
+ `none | <custom-ident>`,
+ `block | inline | x | y`,
+ `[ auto | <length-percentage> ]{1,2}`,
+ ],
+ single
+ );
+ return [
+ name ?? createIdentifier("none"),
+ axis ?? createIdentifier("block"),
+ inset ?? createIdentifier("auto"),
+ ];
+ });
+ yield ["view-timeline-name", name] as const;
+ yield ["view-timeline-axis", axis] as const;
+ yield ["view-timeline-inset", inset] as const;
+};
+
/**
*
* grid-template =
@@ -939,6 +1001,10 @@ const expandBackground = function* (value: CssNode) {
const expandShorthand = function* (property: string, value: CssNode) {
switch (property) {
+ // ignore "all" to avoid bloating styles with huge amount of longhand properties
+ case "all":
+ break;
+
case "font":
yield* expandFont(value);
break;
@@ -1184,6 +1250,10 @@ const expandShorthand = function* (property: string, value: CssNode) {
yield* expandAnimation(value);
break;
+ case "animation-range":
+ yield* expandAnimationRange(value);
+ break;
+
case "transition":
yield* expandTransition(value);
break;
@@ -1196,6 +1266,10 @@ const expandShorthand = function* (property: string, value: CssNode) {
yield* expandScrollTimeline(value);
break;
+ case "view-timeline":
+ yield* expandViewTimeline(value);
+ break;
+
case "scroll-margin":
case "scroll-padding":
yield* expandBox((edge) => `${property}-${edge}`, value);
@@ -1260,6 +1334,16 @@ const expandShorthand = function* (property: string, value: CssNode) {
break;
}
+ case "caret": {
+ const [color, shape] = parseUnordered(
+ [`<'caret-color'>`, `<'caret-shape'>`],
+ value
+ );
+ yield ["caret-color", color ?? createIdentifier("auto")] as const;
+ yield ["caret-shape", shape ?? createIdentifier("auto")] as const;
+ break;
+ }
+
case "background-position":
yield* expandBackgroundPosition(value);
break;
@@ -1268,6 +1352,32 @@ const expandShorthand = function* (property: string, value: CssNode) {
yield* expandBackground(value);
break;
+ case "overscroll-behavior": {
+ const [x, y] = getValueList(value);
+ yield ["overscroll-behavior-x", x] as const;
+ yield ["overscroll-behavior-y", y ?? x] as const;
+ break;
+ }
+
+ case "position-try": {
+ const [order, options] = parseUnordered(
+ [
+ `normal | most-width | most-height | most-block-size | most-inline-size`,
+ `none | [ [<custom-ident> || flip-block || flip-inline || flip-start] | inset-area( <'inset-area'> ) ]#`,
+ ],
+ value
+ );
+ yield [
+ "position-try-order",
+ order ?? createIdentifier("normal"),
+ ] as const;
+ yield [
+ "position-try-options",
+ options ?? createIdentifier("none"),
+ ] as const;
+ break;
+ }
+
default:
yield [property, value] as const;
}