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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
experimental: expand scroll and offset shorthands (#3596)
Bogdan Chadkinf9d94f8d4541
diff --git a/packages/css-data/src/shorthands.test.ts b/packages/css-data/src/shorthands.test.tsindex 145bdfba4b..cf653ec1fb 100644--- a/packages/css-data/src/shorthands.test.ts+++ b/packages/css-data/src/shorthands.test.ts@@ -789,14 +789,92 @@ test("expand overflow", () => {]);});+test("expand offset", () => {+ expect(+ expandShorthands([["offset", `path("M 100 100 L 300 100 L 200 300 z")`]])+ ).toEqual([+ ["offset-position", "normal"],+ ["offset-path", 'path("M 100 100 L 300 100 L 200 300 z")'],+ ["offset-distance", "0"],+ ["offset-rotate", "auto"],+ ["offset-anchor", "auto"],+ ]);+ expect(+ expandShorthands([["offset", `url(arc.svg) 30deg / 50px 100px`]])+ ).toEqual([+ ["offset-position", "normal"],+ ["offset-path", "url(arc.svg)"],+ ["offset-distance", "0"],+ ["offset-rotate", "30deg"],+ ["offset-anchor", "50px 100px"],+ ]);+ expect(expandShorthands([["offset", `url(circle.svg) 40%`]])).toEqual([+ ["offset-position", "normal"],+ ["offset-path", "url(circle.svg)"],+ ["offset-distance", "40%"],+ ["offset-rotate", "auto"],+ ["offset-anchor", "auto"],+ ]);+});++test("expand scroll-timeline", () => {+ expect(expandShorthands([["scroll-timeline", `none`]])).toEqual([+ ["scroll-timeline-name", "none"],+ ["scroll-timeline-axis", "block"],+ ]);+ expect(expandShorthands([["scroll-timeline", `none inline`]])).toEqual([+ ["scroll-timeline-name", "none"],+ ["scroll-timeline-axis", "inline"],+ ]);+ expect(+ expandShorthands([["scroll-timeline", `--custom_name_for_timeline inline`]])+ ).toEqual([+ ["scroll-timeline-name", "--custom_name_for_timeline"],+ ["scroll-timeline-axis", "inline"],+ ]);+ expect(+ expandShorthands([["scroll-timeline", `none inline, --custom y`]])+ ).toEqual([+ ["scroll-timeline-name", "none,--custom"],+ ["scroll-timeline-axis", "inline,y"],+ ]);+});++test("expand scroll-margin/scroll-padding", () => {+ expect(expandShorthands([["scroll-margin", "10px"]])).toEqual([+ ["scroll-margin-top", "10px"],+ ["scroll-margin-right", "10px"],+ ["scroll-margin-bottom", "10px"],+ ["scroll-margin-left", "10px"],+ ]);+ expect(expandShorthands([["scroll-margin-block", "10px"]])).toEqual([+ ["scroll-margin-block-start", "10px"],+ ["scroll-margin-block-end", "10px"],+ ]);+ expect(expandShorthands([["scroll-margin-inline", "10px"]])).toEqual([+ ["scroll-margin-inline-start", "10px"],+ ["scroll-margin-inline-end", "10px"],+ ]);+ expect(expandShorthands([["scroll-padding", "10px"]])).toEqual([+ ["scroll-padding-top", "10px"],+ ["scroll-padding-right", "10px"],+ ["scroll-padding-bottom", "10px"],+ ["scroll-padding-left", "10px"],+ ]);+ expect(expandShorthands([["scroll-padding-block", "10px"]])).toEqual([+ ["scroll-padding-block-start", "10px"],+ ["scroll-padding-block-end", "10px"],+ ]);+ expect(expandShorthands([["scroll-padding-inline", "10px"]])).toEqual([+ ["scroll-padding-inline-start", "10px"],+ ["scroll-padding-inline-end", "10px"],+ ]);+});+test.todo("container");test.todo("contain-intrinsic-size");test.todo("grid");test.todo("grid-template");-test.todo("offset");-test.todo("scroll-margin");-test.todo("scroll-padding");-test.todo("scroll-timeline");test.todo("white-space - not a shorthand in webflow");test.todo("text-wrap - not a shorthand in webflow");diff --git a/packages/css-data/src/shorthands.ts b/packages/css-data/src/shorthands.tsindex e36dddf026..9f6dd68513 100644--- a/packages/css-data/src/shorthands.ts+++ b/packages/css-data/src/shorthands.ts@@ -172,23 +172,6 @@ const expandLogical = function* (getProperty: GetProperty, value: CssNode) {const expandEdges = function* (property: string, value: CssNode) {switch (property) {- case "margin":- case "padding":- yield* expandBox((edge) => `${property}-${edge}`, value);- break;- case "margin-inline":- case "padding-inline":- case "margin-block":- case "padding-block":- yield* expandLogical((edge) => `${property}-${edge}`, value);- break;- case "inset":- yield* expandBox((edge) => edge, value);- break;- case "inset-inline":- case "inset-block":- yield* expandLogical((edge) => `${property}-${edge}`, value);- break;case "border-width":case "border-style":case "border-color": {@@ -709,6 +692,59 @@ const expandMaskBorder = function* (value: CssNode) {yield ["mask-border-mode", mode ?? createInitialNode()] as const;};+/**+ *+ * offset = [+ * <'offset-position'>?+ * [ <'offset-path'> [ <'offset-distance'> || <'offset-rotate'> ]? ]?+ * ]!+ * [ / <'offset-anchor'> ]?+ *+ */+const expandOffset = function* (value: CssNode) {+ const [config, anchor] = splitByOperator(value, "/");+ const [position, path, distance, rotate] = parseUnordered(+ [+ `<'offset-position'>`,+ `<'offset-path'>`,+ `<'offset-distance'>`,+ `<'offset-rotate'>`,+ ],+ config ?? createIdentifier("none")+ );+ yield ["offset-position", position ?? createIdentifier("normal")] as const;+ yield ["offset-path", path ?? createIdentifier("none")] as const;+ yield ["offset-distance", distance ?? createNumber("0")] as const;+ yield ["offset-rotate", rotate ?? createIdentifier("auto")] as const;+ yield ["offset-anchor", anchor ?? createIdentifier("auto")] as const;+};++/**+ *+ * scroll-timeline = [ <'scroll-timeline-name'> <'scroll-timeline-axis'>? ]#+ *+ */+const expandScrollTimeline = function* (value: CssNode) {+ const list = splitByOperator(value, ",");+ const names: CssNode[] = [];+ const axises: CssNode[] = [];+ for (const singleTimeline of list) {+ const [name, axis] = getValueList(+ singleTimeline ?? createIdentifier("none")+ );+ names.push(name);+ axises.push(axis ?? createIdentifier("block"));+ }+ yield [+ "scroll-timeline-name",+ createValueNode(joinByOperator(names, ",")),+ ] as const;+ yield [+ "scroll-timeline-axis",+ createValueNode(joinByOperator(axises, ",")),+ ] as const;+};+const expandShorthand = function* (property: string, value: CssNode) {switch (property) {case "font":@@ -764,6 +800,27 @@ const expandShorthand = function* (property: string, value: CssNode) {yield* expandMaskBorder(value);break;+ case "margin":+ case "padding":+ yield* expandBox((edge) => `${property}-${edge}`, value);+ break;++ case "margin-inline":+ case "margin-block":+ case "padding-inline":+ case "padding-block":+ yield* expandLogical((edge) => `${property}-${edge}`, value);+ break;++ case "inset":+ yield* expandBox((edge) => edge, value);+ break;++ case "inset-inline":+ case "inset-block":+ yield* expandLogical((edge) => `${property}-${edge}`, value);+ break;+case "gap":case "grid-gap": {const [rowGap, columnGap] = getValueList(value);@@ -892,6 +949,26 @@ const expandShorthand = function* (property: string, value: CssNode) {yield* expandTransition(value);break;+ case "offset":+ yield* expandOffset(value);+ break;++ case "scroll-timeline":+ yield* expandScrollTimeline(value);+ break;++ case "scroll-margin":+ case "scroll-padding":+ yield* expandBox((edge) => `${property}-${edge}`, value);+ break;++ case "scroll-margin-inline":+ case "scroll-margin-block":+ case "scroll-padding-inline":+ case "scroll-padding-block":+ yield* expandLogical((edge) => `${property}-${edge}`, value);+ break;+case "overflow": {const [x, y] = getValueList(value);yield ["overflow-x", x] as const;