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 font variant and synthesis shorthands (#3580)
Bogdan Chadkin126fe3d66ad1
diff --git a/packages/css-data/bin/mdn-data.ts b/packages/css-data/bin/mdn-data.tsindex d77ae6d0ab..b3f789d030 100755--- a/packages/css-data/bin/mdn-data.ts+++ b/packages/css-data/bin/mdn-data.ts@@ -235,9 +235,12 @@ const experimentalProperties = [];const unsupportedProperties = [- "all","-webkit-line-clamp","--*",+ // shorthand properties+ "all",+ "font-synthesis",+ "font-variant",// @todo for now webstudio supports only white-space// need to figure out how to make it future proof"white-space-collapse",diff --git a/packages/css-data/src/__generated__/keyword-values.ts b/packages/css-data/src/__generated__/keyword-values.tsindex 41a6591519..4a408c0a7f 100644--- a/packages/css-data/src/__generated__/keyword-values.ts+++ b/packages/css-data/src/__generated__/keyword-values.ts@@ -3240,58 +3240,9 @@ export const keywordValues = {"unset",],fontStyle: ["normal", "italic", "oblique", "initial", "inherit", "unset"],- fontSynthesis: [- "none",- "weight",- "style",- "small-caps",- "position",- "initial",- "inherit",- "unset",- ],fontSynthesisSmallCaps: ["auto", "none", "initial", "inherit", "unset"],fontSynthesisStyle: ["auto", "none", "initial", "inherit", "unset"],fontSynthesisWeight: ["auto", "none", "initial", "inherit", "unset"],- fontVariant: [- "normal",- "none",- "common-ligatures",- "no-common-ligatures",- "discretionary-ligatures",- "no-discretionary-ligatures",- "historical-ligatures",- "no-historical-ligatures",- "contextual",- "no-contextual",- "historical-forms",- "small-caps",- "all-small-caps",- "petite-caps",- "all-petite-caps",- "unicase",- "titling-caps",- "lining-nums",- "oldstyle-nums",- "proportional-nums",- "tabular-nums",- "diagonal-fractions",- "stacked-fractions",- "ordinal",- "slashed-zero",- "jis78",- "jis83",- "jis90",- "jis04",- "simplified",- "traditional",- "full-width",- "proportional-width",- "ruby",- "initial",- "inherit",- "unset",- ],fontVariantAlternates: ["normal","historical-forms",diff --git a/packages/css-data/src/__generated__/properties.ts b/packages/css-data/src/__generated__/properties.tsindex 8deab9d632..1b8ab4b15f 100644--- a/packages/css-data/src/__generated__/properties.ts+++ b/packages/css-data/src/__generated__/properties.ts@@ -1190,32 +1190,6 @@ export const properties = {},types: ["angle"],},- fontSynthesis: {- unitGroups: [],- inherited: true,- initial: {- type: "tuple",- value: [- {- type: "keyword",- value: "weight",- },- {- type: "keyword",- value: "style",- },- {- type: "keyword",- value: "small-caps",- },- {- type: "keyword",- value: "position",- },- ],- },- types: [],- },fontSynthesisSmallCaps: {unitGroups: [],inherited: true,@@ -1243,15 +1217,6 @@ export const properties = {},types: [],},- fontVariant: {- unitGroups: [],- inherited: true,- initial: {- type: "keyword",- value: "normal",- },- types: [],- },fontVariantAlternates: {unitGroups: [],inherited: true,diff --git a/packages/css-data/src/shorthands.test.ts b/packages/css-data/src/shorthands.test.tsindex 997195f3c6..328a892836 100644--- a/packages/css-data/src/shorthands.test.ts+++ b/packages/css-data/src/shorthands.test.ts@@ -386,7 +386,7 @@ test("expand font", () => {])).toEqual([["font-style", "italic"],- ["font-variant", "small-caps"],+ ["font-variant-caps", "small-caps"],["font-weight", "bold"],["font-width", "ultra-condensed"],["font-size", "1.2em"],@@ -397,7 +397,7 @@ test("expand font", () => {expandShorthands([["font", `1.2em/2 "Fira Sans", sans-serif`]])).toEqual([["font-style", "initial"],- ["font-variant", "initial"],+ ["font-variant-caps", "initial"],["font-weight", "initial"],["font-width", "initial"],["font-size", "1.2em"],@@ -406,6 +406,61 @@ test("expand font", () => {]);});+test("expand font-synthesis", () => {+ expect(expandShorthands([["font-synthesis", `none`]])).toEqual([+ ["font-synthesis-weight", "none"],+ ["font-synthesis-style", "none"],+ ["font-synthesis-small-caps", "none"],+ ["font-synthesis-position", "none"],+ ]);+ expect(expandShorthands([["font-synthesis", `style`]])).toEqual([+ ["font-synthesis-weight", "none"],+ ["font-synthesis-style", "auto"],+ ["font-synthesis-small-caps", "none"],+ ["font-synthesis-position", "none"],+ ]);+ expect(+ expandShorthands([["font-synthesis", `style small-caps weight position`]])+ ).toEqual([+ ["font-synthesis-weight", "auto"],+ ["font-synthesis-style", "auto"],+ ["font-synthesis-small-caps", "auto"],+ ["font-synthesis-position", "auto"],+ ]);+});++test("expand font-variant", () => {+ expect(expandShorthands([["font-variant", `normal`]])).toEqual([+ ["font-variant-ligatures", "normal"],+ ["font-variant-caps", "normal"],+ ["font-variant-alternates", "normal"],+ ["font-variant-numeric", "normal"],+ ["font-variant-east-asian", "normal"],+ ["font-variant-position", "normal"],+ ["font-variant-emoji", "normal"],+ ]);+ expect(expandShorthands([["font-variant", `none`]])).toEqual([+ ["font-variant-ligatures", "none"],+ ["font-variant-caps", "normal"],+ ["font-variant-alternates", "normal"],+ ["font-variant-numeric", "normal"],+ ["font-variant-east-asian", "normal"],+ ["font-variant-position", "normal"],+ ["font-variant-emoji", "normal"],+ ]);+ expect(+ expandShorthands([["font-variant", `common-ligatures small-caps`]])+ ).toEqual([+ ["font-variant-ligatures", "common-ligatures"],+ ["font-variant-caps", "small-caps"],+ ["font-variant-alternates", "normal"],+ ["font-variant-numeric", "normal"],+ ["font-variant-east-asian", "normal"],+ ["font-variant-position", "normal"],+ ["font-variant-emoji", "normal"],+ ]);+});+test("expand text-decoration", () => {expect(expandShorthands([["text-decoration", `underline`]])).toEqual([["text-decoration-line", "underline"],@@ -732,10 +787,6 @@ test.todo("scroll-margin");test.todo("scroll-padding");test.todo("scroll-timeline");-test.todo("font-synthesis - only shorthand is supported in webstudio");-test.todo(- "font-variant - both shorthand and longhands are supported in webstudio"-);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 4970a51a0d..7e44cb0002 100644--- a/packages/css-data/src/shorthands.ts+++ b/packages/css-data/src/shorthands.ts@@ -338,7 +338,7 @@ const expandFont = function* (value: CssNode) {}}yield ["font-style", fontStyle ?? createInitialNode()] as const;- yield ["font-variant", fontVariant ?? createInitialNode()] as const;+ yield ["font-variant-caps", fontVariant ?? createInitialNode()] as const;yield ["font-weight", fontWeight ?? createInitialNode()] as const;yield ["font-width", fontWidth ?? createInitialNode()] as const;yield ["font-size", fontSize] as const;@@ -346,6 +346,63 @@ const expandFont = function* (value: CssNode) {yield ["font-family", fontFamily] as const;};+/**+ *+ * font-synthesis = none | [ weight || style || small-caps || position ]+ *+ */+const expandFontSynthesis = function* (value: CssNode) {+ const [weight, style, smallCaps, position] = parseUnordered(+ ["weight", "style", "small-caps", "position"],+ value+ );+ const auto = createIdentifier("auto");+ const none = createIdentifier("none");+ yield ["font-synthesis-weight", weight ? auto : none] as const;+ yield ["font-synthesis-style", style ? auto : none] as const;+ yield ["font-synthesis-small-caps", smallCaps ? auto : none] as const;+ yield ["font-synthesis-position", position ? auto : none] as const;+};++/**+ *+ * font-variant =+ * normal |+ * none |+ * [+ * [ <common-lig-values> || <discretionary-lig-values> || <historical-lig-values> || <contextual-alt-values> ] ||+ * [ small-caps | all-small-caps | petite-caps | all-petite-caps | unicase | titling-caps ] ||+ * [ <numeric-figure-values> || <numeric-spacing-values> || <numeric-fraction-values> || ordinal || slashed-zero ] ||+ * [ <east-asian-variant-values> || <east-asian-width-values> || ruby ] ||+ * [ sub | super ] ||+ * [ text | emoji | unicode ]+ * ]+ *+ */+const expandFontVariant = function* (value: CssNode) {+ const [ligatures, caps, alternates, numeric, eastAsian, position, emoji] =+ parseUnordered(+ [+ "[ normal | none | <common-lig-values> || <discretionary-lig-values> || <historical-lig-values> || <contextual-alt-values> ]",+ "[ small-caps | all-small-caps | petite-caps | all-petite-caps | unicase | titling-caps ]",+ "[ stylistic( <feature-value-name> ) || historical-forms || styleset( <feature-value-name># ) || character-variant( <feature-value-name># ) || swash( <feature-value-name> ) || ornaments( <feature-value-name> ) || annotation( <feature-value-name> ) ]",+ "[ <numeric-figure-values> || <numeric-spacing-values> || <numeric-fraction-values> || ordinal || slashed-zero ]",+ "[ <east-asian-variant-values> || <east-asian-width-values> || ruby ]",+ "[ sub | super ]",+ "[ text | emoji | unicode ]",+ ],+ value+ );+ const normal = createIdentifier("normal");+ yield ["font-variant-ligatures", ligatures ?? normal] as const;+ yield ["font-variant-caps", caps ?? normal] as const;+ yield ["font-variant-alternates", alternates ?? normal] as const;+ yield ["font-variant-numeric", numeric ?? normal] as const;+ yield ["font-variant-east-asian", eastAsian ?? normal] as const;+ yield ["font-variant-position", position ?? normal] as const;+ yield ["font-variant-emoji", emoji ?? normal] as const;+};+const expandFlex = function* (value: CssNode) {const zero = createNumber("0");const one = createNumber("1");@@ -658,6 +715,14 @@ const expandShorthand = function* (property: string, value: CssNode) {yield* expandFont(value);break;+ case "font-synthesis":+ yield* expandFontSynthesis(value);+ break;++ case "font-variant":+ yield* expandFontVariant(value);+ break;+case "text-decoration": {const [line, style, color] = parseUnordered([diff --git a/packages/css-engine/src/__generated__/types.ts b/packages/css-engine/src/__generated__/types.tsindex f8840e0c73..a9e71b0b60 100644--- a/packages/css-engine/src/__generated__/types.ts+++ b/packages/css-engine/src/__generated__/types.ts@@ -128,11 +128,9 @@ export type Property =| "fontSizeAdjust"| "fontStretch"| "fontStyle"- | "fontSynthesis"| "fontSynthesisSmallCaps"| "fontSynthesisStyle"| "fontSynthesisWeight"- | "fontVariant"| "fontVariantAlternates"| "fontVariantCaps"| "fontVariantEastAsian"