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
refactor: add repeated style utils (#4086)
Bogdan Chadkine6b1d55e291a
diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsxindex f9d4524fcb..87c62dd655 100644--- a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx@@ -2,11 +2,6 @@ import { useState } from "react";import {toValue,type InvalidValue,- type LayersValue,- type TupleValue,- type KeywordValue,- type UnitValue,- type StyleProperty,type StyleValue,type TupleValueItem,} from "@webstudio-is/css-engine";@@ -22,12 +17,7 @@ import {Grid,} from "@webstudio-is/design-system";import { InfoCircleIcon } from "@webstudio-is/icons";-import {- parseCssValue,- properties,- propertyDescriptions,- type ExtractedTransitionProperties,-} from "@webstudio-is/css-data";+import { properties, propertyDescriptions } from "@webstudio-is/css-data";import type { StyleUpdateOptions } from "../../shared/use-style-data";import { type IntermediateStyleValue } from "../../shared/css-value-input";import { CssValueInputContainer } from "../../shared/css-value-input";@@ -35,13 +25,8 @@ import { parseCssFragment } from "../../shared/parse-css-fragment";import { PropertyInlineLabel } from "../../property-label";import { TransitionProperty } from "./transition-property";import { TransitionTiming } from "./transition-timing";-import { editTransitionLayer } from "./transition-utils";import { useComputedStyles } from "../../shared/model";--// We are allowing users to add/edit layers as shorthand from the style-panel-// So, we need to use the shorthand property to validate the layer too.-// We removed transition from properties list to drop support from advanced tab and so the typecasting.-const shortHandTransitionProperty = "transition" as StyleProperty;+import { editRepeatedStyleItem } from "../../shared/repeated-style";const getLayer = (value: undefined | StyleValue, index: number) =>value?.type === "layers" ? value.value[index] : undefined;@@ -94,72 +79,41 @@ export const TransitionContent = ({ index }: { index: number }) => {if (intermediateValue === undefined) {return;}-- const parsed = parseCssFragment(intermediateValue.value, "transition");- const tuple: TupleValue = {- type: "tuple",- value: [- getLayer(parsed.get("transitionProperty"), 0),- getLayer(parsed.get("transitionDuration"), 0),- getLayer(parsed.get("transitionTimingFunction"), 0),- getLayer(parsed.get("transitionDelay"), 0),- // @todo getLayer(parsed.get("transitionBehavior"), 0),- ].filter(Boolean) as TupleValueItem[],- };- if (tuple.value.length === 0) {- setIntermediateValue({- type: "invalid",- value: intermediateValue.value,- });- }- const layers: LayersValue = {- type: "layers",- value: [tuple],- };-- editTransitionLayer({- index,- layers,- options: { isEphemeral: false },+ editRepeatedStyleItem(styles,- });+ index,+ parseCssFragment(intermediateValue.value, "transition")+ );};const handlePropertyUpdate = (- params: ExtractedTransitionProperties,+ params: {+ property?: StyleValue;+ timing?: StyleValue;+ delay?: StyleValue;+ duration?: StyleValue;+ },options: StyleUpdateOptions = { isEphemeral: false }) => {- const value: Array<UnitValue | KeywordValue> = Object.values({- ...{ property, duration, delay, timing: timingFunction },- ...params,- }).filter<UnitValue | KeywordValue>(- (item): item is UnitValue | KeywordValue => item != null- );- const layerTuple: TupleValue = { type: "tuple", value };- const layerValue = parseCssValue(- shortHandTransitionProperty,- toValue(layerTuple)- );-- if (layerValue.type === "invalid") {- setIntermediateValue({- type: "invalid",- value: toValue(layerTuple),- });- return;- }-+ const shorthand = toValue({+ type: "tuple",+ value: [+ params.property ?? property,+ params.duration ?? duration,+ params.delay ?? delay,+ params.timing ?? timingFunction,+ ].filter((item): item is TupleValueItem => item !== undefined),+ });setIntermediateValue({type: "intermediate",- value: toValue(layerTuple),+ value: shorthand,});-- editTransitionLayer({- index,- layers: { type: "layers", value: [layerTuple] },- options,+ editRepeatedStyleItem(styles,- });+ index,+ parseCssFragment(shorthand, "transition"),+ options+ );};return (diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsx b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsxindex 34e10cda51..aded273f2d 100644--- a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsx+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsx@@ -28,12 +28,7 @@ import {type UnparsedValue,} from "@webstudio-is/css-engine";import { setUnion } from "~/shared/shim";-import {- $selectedInstanceSelector,- $selectedOrLastStyleSourceSelector,-} from "~/shared/nano-states";-import { getComputedStyleDecl } from "~/shared/style-object-model";-import { $definedProperties, $model } from "../../shared/model";+import { $definedProperties } from "../../shared/model";type AnimatableProperties = (typeof animatableProperties)[number];type NameAndLabel = { name: string; label?: string };@@ -44,32 +39,18 @@ type TransitionPropertyProps = {const commonPropertiesSet = new Set(commonTransitionProperties);+/**+ * animatable and inherited properties+ * on current breakpoints across all states+ */const $animatableDefinedProperties = computed(- [- $definedProperties,- $model,- $selectedInstanceSelector,- $selectedOrLastStyleSourceSelector,- ],- (definedProperties, model, instanceSelector, styleSourceSelector) => {+ [$definedProperties],+ (definedProperties) => {const animatableProperties = new Set<string>();for (const property of definedProperties) {const hyphenatedProperty = hyphenateProperty(property);if (isAnimatableProperty(hyphenatedProperty)) {- const styleDecl = getComputedStyleDecl({- model,- instanceSelector,- styleSourceId: styleSourceSelector?.styleSourceId,- state: styleSourceSelector?.state,- property,- });- if (- styleDecl.source.name === "remote" ||- styleDecl.source.name === "local" ||- styleDecl.source.name === "overwritten"- ) {- animatableProperties.add(hyphenatedProperty);- }+ animatableProperties.add(hyphenatedProperty);}}return animatableProperties;diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-utils.ts b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-utils.tsindex b8ae72ac58..b7ca0c9e89 100644--- a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-utils.ts+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-utils.ts@@ -1,20 +1,4 @@-import {- FunctionValue,- UnparsedValue,- type KeywordValue,- type LayersValue,- type UnitValue,-} from "@webstudio-is/css-engine";-import {- extractTransitionProperties,- properties,- transitionLongHandProperties,-} from "@webstudio-is/css-data";-import {- createBatchUpdate,- type StyleUpdateOptions,-} from "../../shared/use-style-data";-import type { ComputedStyleDecl } from "~/shared/style-object-model";+import { transitionLongHandProperties } from "@webstudio-is/css-data";export type TransitionProperty = (typeof transitionLongHandProperties)[number];@@ -85,100 +69,3 @@ export const findTimingFunctionFromValue = ((key: TimingFunctions) => timingFunctions[key] === cleanedFuncValue);};--const getTransitionProperties = (- styles: ComputedStyleDecl[]-): Record<TransitionProperty, LayersValue> => {- const properties: Record<TransitionProperty, LayersValue> = {- transitionProperty: { type: "layers", value: [] },- transitionTimingFunction: { type: "layers", value: [] },- transitionDelay: { type: "layers", value: [] },- transitionDuration: { type: "layers", value: [] },- transitionBehavior: { type: "layers", value: [] },- };- for (const styleDecl of styles) {- if (styleDecl.cascadedValue.type === "layers") {- properties[styleDecl.property as TransitionProperty] =- styleDecl.cascadedValue;- }- }-- return properties;-};--// @todo support editing transition-behavior-export const editTransitionLayer = (props: {- index: number;- layers: LayersValue;- options: StyleUpdateOptions;- styles: ComputedStyleDecl[];-}) => {- const { index, layers, options } = props;- const batch = createBatchUpdate();-- const newTransitionProperties: Array<KeywordValue | UnparsedValue> = [];- const newTransitionDurations: UnitValue[] = [];- const newTransitionDelays: UnitValue[] = [];- const newTransitionTimingFunctions: Array<KeywordValue | FunctionValue> = [];-- for (const layer of layers.value) {- if (layer.type !== "tuple") {- continue;- }-- const {- property,- duration = properties.transitionDuration.initial,- timing = properties.transitionTimingFunction.initial,- delay = properties.transitionDelay.initial,- } = extractTransitionProperties(layer);-- // transition-property can't be undefined- if (property === undefined) {- return;- }-- newTransitionProperties.push(property);- newTransitionDurations.push(duration);- newTransitionDelays.push(delay);- newTransitionTimingFunctions.push(timing);- }-- const existingTransitionProperties = getTransitionProperties(props.styles);- const {- transitionProperty,- transitionDelay,- transitionDuration,- transitionTimingFunction,- } = existingTransitionProperties;-- const newProperty = [...transitionProperty.value];- newProperty.splice(index, 1, ...newTransitionProperties);- batch.setProperty("transitionProperty")({- type: "layers",- value: newProperty,- });-- const newDuration = [...transitionDuration.value];- newDuration.splice(index, 1, ...newTransitionDurations);- batch.setProperty("transitionDuration")({- type: "layers",- value: newDuration,- });-- const newTiming = [...transitionTimingFunction.value];- newTiming.splice(index, 1, ...newTransitionTimingFunctions);- batch.setProperty("transitionTimingFunction")({- type: "layers",- value: newTiming,- });-- const newDelay = [...transitionDelay.value];- newDelay.splice(index, 1, ...newTransitionDelays);- batch.setProperty("transitionDelay")({- type: "layers",- value: newDelay,- });-- batch.publish(options);-};diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsx b/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsxindex d77bcf619f..e48e596044 100644--- a/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsx+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsx@@ -17,15 +17,18 @@ import { humanizeString } from "~/shared/string-utils";import { repeatUntil } from "~/shared/array-utils";import type { ComputedStyleDecl } from "~/shared/style-object-model";import { getDots } from "../../shared/style-section";-import { RepeatedStyle } from "../../shared/repeated-style";+import {+ addRepeatedStyleItem,+ RepeatedStyle,+} from "../../shared/repeated-style";import { PropertySectionLabel } from "../../property-label";import { useComputedStyles } from "../../shared/model";-import { createBatchUpdate } from "../../shared/use-style-data";import {findTimingFunctionFromValue,type TransitionProperty,} from "./transition-utils";import { TransitionContent } from "./transition-content";+import { parseCssFragment } from "../../shared/parse-css-fragment";export { transitionLongHandProperties as properties };@@ -35,14 +38,12 @@ const getTransitionLayers = (styles: ComputedStyleDecl[],property: TransitionProperty) => {- const transitionPropertyValue = styles.find(- (styleDecl) => styleDecl.property === "transitionProperty"- )?.cascadedValue;+ const transitionPropertyValue = styles[0].cascadedValue;const currentPropertyValue = styles.find((styleDecl) => styleDecl.property === property)?.cascadedValue;const transitionPropertiesCount =- transitionPropertyValue?.type === "layers"+ transitionPropertyValue.type === "layers"? transitionPropertyValue.value.length: 0;const definedLayers: LayerValueItem[] =@@ -79,14 +80,6 @@ const getLayerLabel = ({return `${property}: ${duration} ${humanizedTimingFunction} ${delay}`;};-const defaultTransitionLayers: Record<TransitionProperty, LayerValueItem> = {- transitionProperty: { type: "unparsed", value: "opacity" },- transitionDuration: { type: "unit", value: 200, unit: "ms" },- transitionTimingFunction: { type: "keyword", value: "ease" },- transitionDelay: { type: "unit", value: 0, unit: "ms" },- transitionBehavior: { type: "keyword", value: "normal" },-};-export const Section = () => {const [isOpen, setIsOpen] = useState(true);@@ -121,17 +114,13 @@ export const Section = () => {prefix={<PlusIcon />}onClick={() => {setIsOpen(true);- const batch = createBatchUpdate();- for (const property of transitionLongHandProperties) {- batch.setProperty(property)({- type: "layers",- value: [- ...getTransitionLayers(styles, property),- defaultTransitionLayers[property],- ],- });- }- batch.publish();+ addRepeatedStyleItem(+ styles,+ parseCssFragment(+ "opacity 200ms ease 0ms normal",+ "transition"+ )+ );}}/></Tooltip>diff --git a/apps/builder/app/builder/features/style-panel/shared/model.tsx b/apps/builder/app/builder/features/style-panel/shared/model.tsxindex 5e3949aa6e..f798d02d69 100644--- a/apps/builder/app/builder/features/style-panel/shared/model.tsx+++ b/apps/builder/app/builder/features/style-panel/shared/model.tsx@@ -1,6 +1,7 @@import { useMemo } from "react";import { computed } from "nanostores";import { useStore } from "@nanostores/react";+import { properties } from "@webstudio-is/css-data";import {compareMedia,type StyleProperty,@@ -96,20 +97,32 @@ export const $definedProperties = computed(if (instanceSelector === undefined) {return definedProperties;}- const matchingStyleSources = new Set();+ const inheritedStyleSources = new Set();+ const instanceStyleSources = new Set();const matchingBreakpoints = new Set(matchingBreakpointsArray);for (const instanceId of instanceSelector) {const styleSources = styleSourceSelections.get(instanceId)?.values;if (styleSources) {for (const styleSourceId of styleSources) {- matchingStyleSources.add(styleSourceId);+ if (instanceId === instanceSelector[0]) {+ instanceStyleSources.add(styleSourceId);+ } else {+ inheritedStyleSources.add(styleSourceId);+ }}}}for (const styleDecl of styles.values()) {if (matchingBreakpoints.has(styleDecl.breakpointId) &&- matchingStyleSources.has(styleDecl.styleSourceId)+ instanceStyleSources.has(styleDecl.styleSourceId)+ ) {+ definedProperties.add(styleDecl.property);+ }+ if (+ matchingBreakpoints.has(styleDecl.breakpointId) &&+ inheritedStyleSources.has(styleDecl.styleSourceId) &&+ properties[styleDecl.property as keyof typeof properties].inherited) {definedProperties.add(styleDecl.property);}@@ -118,11 +131,7 @@ export const $definedProperties = computed(});-/**- * Do not use directly- * only transition property is permitted- */-export const $model = computed(+const $model = computed([$styles,$styleSourceSelections,diff --git a/apps/builder/app/builder/features/style-panel/shared/repeated-style.tsx b/apps/builder/app/builder/features/style-panel/shared/repeated-style.tsxindex 404994fb2a..3cb442c8e7 100644--- a/apps/builder/app/builder/features/style-panel/shared/repeated-style.tsx+++ b/apps/builder/app/builder/features/style-panel/shared/repeated-style.tsx@@ -22,33 +22,87 @@ import {import { FloatingPanel } from "~/builder/shared/floating-panel";import { repeatUntil } from "~/shared/array-utils";import type { ComputedStyleDecl } from "~/shared/style-object-model";-import { createBatchUpdate } from "./use-style-data";+import { createBatchUpdate, type StyleUpdateOptions } from "./use-style-data";import { ColorThumb } from "./color-thumb";+const normalizeStyleValue = (+ value: undefined | StyleValue,+ primaryValue: StyleValue+): LayersValue => {+ const primaryLayersCount =+ primaryValue.type === "layers" ? primaryValue.value.length : 0;+ const layers = value?.type === "layers" ? value.value : [];+ const normalizedLayers: LayersValue = {+ type: "layers",+ value: repeatUntil(layers, primaryLayersCount),+ };+ return normalizedLayers;+};++export const addRepeatedStyleItem = (+ styles: ComputedStyleDecl[],+ newItems: Map<StyleProperty, StyleValue>+) => {+ const batch = createBatchUpdate();+ const currentStyles = new Map(+ styles.map((styleDecl) => [styleDecl.property, styleDecl.cascadedValue])+ );+ const primaryValue = styles[0].cascadedValue;+ for (const [property, value] of newItems) {+ const currentValue = currentStyles.get(property);+ const normalizedValue = normalizeStyleValue(currentValue, primaryValue);+ const newLayers = value.type === "layers" ? value.value : [];+ batch.setProperty(property)({+ type: "layers",+ value: [...normalizedValue.value, ...newLayers],+ });+ }+ batch.publish();+};++export const editRepeatedStyleItem = (+ styles: ComputedStyleDecl[],+ index: number,+ newItems: Map<StyleProperty, StyleValue>,+ options?: StyleUpdateOptions+) => {+ const batch = createBatchUpdate();+ const currentStyles = new Map(+ styles.map((styleDecl) => [styleDecl.property, styleDecl.cascadedValue])+ );+ const primaryValue = styles[0].cascadedValue;+ for (const [property, value] of newItems) {+ const currentValue = currentStyles.get(property);+ const normalizedValue = normalizeStyleValue(currentValue, primaryValue);+ const newLayers = value.type === "layers" ? value.value : [];+ normalizedValue.value.splice(index, 1, ...newLayers);+ batch.setProperty(property)({+ type: "layers",+ value: normalizedValue.value,+ });+ }+ batch.publish(options);+};+const createLayersTransformer =(styles: ComputedStyleDecl[]) =>- (transform: (value: LayersValue) => Partial<LayersValue>) => {+ (+ transform: (property: string, value: LayersValue) => Partial<LayersValue>+ ) => {const batch = createBatchUpdate();const primaryValue = styles[0].cascadedValue;- const primaryLayersCount =- primaryValue?.type === "layers" ? primaryValue.value.length : 0;for (const styleDecl of styles) {const value = styleDecl.cascadedValue;- if (value?.type === "layers") {- const normalizedLayers: LayersValue = {- type: "layers",- value: repeatUntil(value.value, primaryLayersCount),- };- const newLayers: LayersValue = {- ...normalizedLayers,- ...transform(normalizedLayers),- };- // delete empty layers- if (newLayers.value.length === 0) {- batch.deleteProperty(styleDecl.property as StyleProperty);- } else {- batch.setProperty(styleDecl.property as StyleProperty)(newLayers);- }+ const normalizedValue = normalizeStyleValue(value, primaryValue);+ const newLayers: LayersValue = {+ ...normalizedValue,+ ...transform(styleDecl.property, normalizedValue),+ };+ // delete empty layers+ if (newLayers.value.length === 0) {+ batch.deleteProperty(styleDecl.property as StyleProperty);+ } else {+ batch.setProperty(styleDecl.property as StyleProperty)(newLayers);}}batch.publish();@@ -107,7 +161,9 @@ export const RepeatedStyle = (props: {const { dragItemId, placementIndicator, sortableRefCallback } = useSortable({items: sortableItems,onSort: (newIndex, oldIndex) =>- transformLayers((value) => swapLayers(value, oldIndex, newIndex)),+ transformLayers((_property, value) =>+ swapLayers(value, oldIndex, newIndex)+ ),});if (primaryValues.length === 0) {@@ -145,7 +201,9 @@ export const RepeatedStyle = (props: {disabled={false}tabIndex={-1}onPressedChange={() =>- transformLayers((value) => hideLayer(value, index))+ transformLayers((_property, value) =>+ hideLayer(value, index)+ )}icon={primaryValue.hidden ? (@@ -160,7 +218,9 @@ export const RepeatedStyle = (props: {tabIndex={-1}icon={<SubtractIcon />}onClick={() =>- transformLayers((value) => deleteLayer(value, index))+ transformLayers((_property, value) =>+ deleteLayer(value, index)+ )}/></>diff --git a/packages/css-data/src/property-parsers/index.ts b/packages/css-data/src/property-parsers/index.tsindex 1e3946dc7c..29a95a0959 100644--- a/packages/css-data/src/property-parsers/index.ts+++ b/packages/css-data/src/property-parsers/index.ts@@ -1,3 +1,2 @@export * from "./transition";-export * from "./transition-property-extractor";export * from "./shadow-properties-extractor";diff --git a/packages/css-data/src/property-parsers/transition-property-extractor.test.ts b/packages/css-data/src/property-parsers/transition-property-extractor.test.tsdeleted file mode 100644index 361dfcee07..0000000000--- a/packages/css-data/src/property-parsers/transition-property-extractor.test.ts+++ /dev/null@@ -1,397 +0,0 @@-import { describe, expect, test } from "@jest/globals";-import { extractTransitionProperties } from "./transition-property-extractor";--describe("extractTransitionProperties", () => {- test("parses and extracts values from opacity 200ms ease 50ms", () => {- const result = extractTransitionProperties({- type: "tuple",- value: [- {- type: "keyword",- value: "opacity",- },- {- type: "unit",- value: 200,- unit: "ms",- },- {- type: "keyword",- value: "ease",- },- {- type: "unit",- value: 50,- unit: "ms",- },- ],- });-- expect(result).toEqual({- property: { type: "keyword", value: "opacity" },- duration: { type: "unit", value: 200, unit: "ms" },- timing: { type: "keyword", value: "ease" },- delay: { type: "unit", value: 50, unit: "ms" },- });- expect(result).toMatchInlineSnapshot(`-{- "delay": {- "type": "unit",- "unit": "ms",- "value": 50,- },- "duration": {- "type": "unit",- "unit": "ms",- "value": 200,- },- "property": {- "type": "keyword",- "value": "opacity",- },- "timing": {- "type": "keyword",- "value": "ease",- },-}-`);- });-- test("parses and extracts values from opacity 200ms ease", () => {- const result = extractTransitionProperties({- type: "tuple",- value: [- {- type: "keyword",- value: "opacity",- },- {- type: "unit",- value: 200,- unit: "ms",- },- {- type: "keyword",- value: "ease",- },- ],- });-- expect(result).toEqual({- property: { type: "keyword", value: "opacity" },- duration: { type: "unit", value: 200, unit: "ms" },- timing: { type: "keyword", value: "ease" },- delay: undefined,- });- expect(result).toMatchInlineSnapshot(`-{- "delay": undefined,- "duration": {- "type": "unit",- "unit": "ms",- "value": 200,- },- "property": {- "type": "keyword",- "value": "opacity",- },- "timing": {- "type": "keyword",- "value": "ease",- },-}-`);- });-- test("parses and extracts values from opacity 200ms 10ms", () => {- const result = extractTransitionProperties({- type: "tuple",- value: [- {- type: "keyword",- value: "opacity",- },- {- type: "unit",- value: 200,- unit: "ms",- },- {- type: "unit",- value: 10,- unit: "ms",- },- ],- });-- expect(result).toEqual({- property: { type: "keyword", value: "opacity" },- duration: { type: "unit", value: 200, unit: "ms" },- timing: undefined,- delay: { type: "unit", value: 10, unit: "ms" },- });- expect(result).toMatchInlineSnapshot(`-{- "delay": {- "type": "unit",- "unit": "ms",- "value": 10,- },- "duration": {- "type": "unit",- "unit": "ms",- "value": 200,- },- "property": {- "type": "keyword",- "value": "opacity",- },- "timing": undefined,-}-`);- });-- test("parses and extracts values from opacity 200ms", () => {- const result = extractTransitionProperties({- type: "tuple",- value: [- {- type: "keyword",- value: "opacity",- },- {- type: "unit",- value: 200,- unit: "ms",- },- ],- });-- expect(result).toEqual({- property: { type: "keyword", value: "opacity" },- duration: { type: "unit", value: 200, unit: "ms" },- timing: undefined,- delay: undefined,- });- expect(result).toMatchInlineSnapshot(`-{- "delay": undefined,- "duration": {- "type": "unit",- "unit": "ms",- "value": 200,- },- "property": {- "type": "keyword",- "value": "opacity",- },- "timing": undefined,-}-`);- });-- test("parses and extracts values from ease 10ms", () => {- const result = extractTransitionProperties({- type: "tuple",- value: [- {- type: "keyword",- value: "ease",- },- {- type: "unit",- value: 10,- unit: "ms",- },- ],- });- expect(result).toEqual({- property: undefined,- duration: { type: "unit", value: 10, unit: "ms" },- timing: { type: "keyword", value: "ease" },- delay: undefined,- });- });-- test("parses and extracts values from opacity ease", () => {- const result = extractTransitionProperties({- type: "tuple",- value: [- {- type: "keyword",- value: "opacity",- },- {- type: "keyword",- value: "ease",- },- ],- });-- expect(result).toEqual({- property: { type: "keyword", value: "opacity" },- duration: undefined,- timing: { type: "keyword", value: "ease" },- delay: undefined,- });- expect(result).toMatchInlineSnapshot;- });-- test("parses and extracts values from opacity ease 50ms", () => {- const result = extractTransitionProperties({- type: "tuple",- value: [- {- type: "keyword",- value: "opacity",- },- {- type: "keyword",- value: "ease",- },- {- type: "unit",- value: 50,- unit: "ms",- },- ],- });-- expect(result).toEqual({- property: { type: "keyword", value: "opacity" },- duration: { type: "unit", value: 50, unit: "ms" },- timing: { type: "keyword", value: "ease" },- delay: undefined,- });- expect(result).toMatchInlineSnapshot(`-{- "delay": undefined,- "duration": {- "type": "unit",- "unit": "ms",- "value": 50,- },- "property": {- "type": "keyword",- "value": "opacity",- },- "timing": {- "type": "keyword",- "value": "ease",- },-}-`);- });-- test("parses and extracts values from transform 0.6s cubic-bezier(0.36, 0, 0.66, -0.56)", () => {- const result = extractTransitionProperties({- type: "tuple",- value: [- {- type: "keyword",- value: "transform",- },- {- type: "unit",- value: 0.6,- unit: "s",- },- {- type: "keyword",- value: "cubic-bezier(0.36, 0, 0.66, -0.56)",- },- ],- });-- expect(result).toEqual({- property: { type: "keyword", value: "transform" },- duration: { type: "unit", value: 0.6, unit: "s" },- timing: { type: "keyword", value: "cubic-bezier(0.36, 0, 0.66, -0.56)" },- delay: undefined,- });- expect(result).toMatchInlineSnapshot(`-{- "delay": undefined,- "duration": {- "type": "unit",- "unit": "s",- "value": 0.6,- },- "property": {- "type": "keyword",- "value": "transform",- },- "timing": {- "type": "keyword",- "value": "cubic-bezier(0.36, 0, 0.66, -0.56)",- },-}-`);- });-- test("parses and throws error for non-animatable 'custom-property ease'", () => {- const result = extractTransitionProperties({- type: "tuple",- value: [- {- type: "keyword",- value: "custom-property",- },- {- type: "keyword",- value: "ease",- },- ],- });-- expect(result).toEqual({- property: undefined,- duration: undefined,- timing: { type: "keyword", value: "ease" },- delay: undefined,- });-- expect(result).toMatchInlineSnapshot(`-{- "delay": undefined,- "duration": undefined,- "property": undefined,- "timing": {- "type": "keyword",- "value": "ease",- },-}-`);- });-- test("parses and extracts values from custom-property ease", () => {- const result = extractTransitionProperties({- type: "tuple",- value: [- {- type: "keyword",- value: "ease",- },- ],- });-- expect(result).toEqual({- property: undefined,- duration: undefined,- timing: { type: "keyword", value: "ease" },- delay: undefined,- });-- expect(result).toMatchInlineSnapshot(`-{- "delay": undefined,- "duration": undefined,- "property": undefined,- "timing": {- "type": "keyword",- "value": "ease",- },-}-`);- });-});diff --git a/packages/css-data/src/property-parsers/transition-property-extractor.ts b/packages/css-data/src/property-parsers/transition-property-extractor.tsdeleted file mode 100644index e1ecd784f5..0000000000--- a/packages/css-data/src/property-parsers/transition-property-extractor.ts+++ /dev/null@@ -1,69 +0,0 @@-import {- FunctionValue,- toValue,- UnparsedValue,- type KeywordValue,- type TupleValue,- type UnitValue,-} from "@webstudio-is/css-engine";-import { isAnimatableProperty } from "..";--export const isTimingFunction = (name: string) => {- const allowedNames = [- "ease-in",- "ease-out",- "ease-in-out",- "linear",- "cubic-bezier",- "steps",- ];-- return allowedNames.includes(name);-};--export type ExtractedTransitionProperties = {- property?: KeywordValue | UnparsedValue;- timing?: KeywordValue | FunctionValue;- delay?: UnitValue;- duration?: UnitValue;-};--export const extractTransitionProperties = (- transition: TupleValue-): ExtractedTransitionProperties => {- let property: KeywordValue | UnparsedValue | undefined;- let timing: KeywordValue | FunctionValue | undefined;-- const unitValues: UnitValue[] = [];-- for (const item of transition.value) {- if (- (item.type === "keyword" || item.type === "unparsed") &&- isAnimatableProperty(toValue(item)) === true- ) {- property = item;- }-- if (item.type === "keyword" && isAnimatableProperty(item.value) === false) {- timing = item;- }-- if (item.type === "function") {- timing = item;- }-- if (item.type === "unit") {- unitValues.push(item);- }- }-- const duration: UnitValue | undefined = unitValues[0] ?? undefined;- const delay: UnitValue | undefined = unitValues[1] ?? undefined;-- return {- property,- duration,- timing,- delay,- };-};diff --git a/packages/css-data/src/property-parsers/transition.ts b/packages/css-data/src/property-parsers/transition.tsindex b4dcda6e6e..fd9ac18c82 100644--- a/packages/css-data/src/property-parsers/transition.ts+++ b/packages/css-data/src/property-parsers/transition.ts@@ -1,10 +1,4 @@-import type {- KeywordValue,- LayerValueItem,- UnitValue,- FunctionValue,- StyleProperty,-} from "@webstudio-is/css-engine";+import type { StyleProperty } from "@webstudio-is/css-engine";import { animatableProperties } from "../__generated__/animatable-properties";type AnimatableProperty = (typeof animatableProperties)[number];@@ -40,14 +34,3 @@ export const isAnimatableProperty = ((item) => item === property);};--export const isValidTransitionValue = (- value: LayerValueItem-): value is KeywordValue | UnitValue | FunctionValue => {- return (- value.type === "keyword" ||- value.type === "unit" ||- value.type === "function" ||- value.type === "unparsed"- );-};