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: Gradients UI (#5449)

Oleg Isonendc508445ce09
diff --git a/apps/builder/app/builder/features/style-panel/controls/color/color-control.tsx b/apps/builder/app/builder/features/style-panel/controls/color/color-control.tsx
index 1554817b69..32d6b0376f 100644
--- a/apps/builder/app/builder/features/style-panel/controls/color/color-control.tsx
+++ b/apps/builder/app/builder/features/style-panel/controls/color/color-control.tsx
@@ -1,6 +1,6 @@
import type { CssProperty } from "@webstudio-is/css-engine";
import { keywordValues } from "@webstudio-is/css-data";
-import { ColorPicker } from "../../shared/color-picker";
+import { ColorPickerControl } from "../../shared/color-picker";
import {
$availableColorVariables,
useComputedStyleDecl,
@@ -13,7 +13,7 @@ export const ColorControl = ({ property }: { property: CssProperty }) => {
const currentColor = computedStyleDecl.usedValue;
const setValue = setProperty(property);
return (
- <ColorPicker
+ <ColorPickerControl
property={property}
value={value}
currentColor={currentColor}
diff --git a/apps/builder/app/builder/features/style-panel/property-label.tsx b/apps/builder/app/builder/features/style-panel/property-label.tsx
index 4e15db2d53..751830eb68 100644
--- a/apps/builder/app/builder/features/style-panel/property-label.tsx
+++ b/apps/builder/app/builder/features/style-panel/property-label.tsx
@@ -230,10 +230,12 @@ export const PropertyLabel = ({
label,
description,
properties,
+ disabled,
}: {
label: string;
description?: string;
properties: [CssProperty, ...CssProperty[]];
+ disabled?: boolean;
}) => {
const styles = useComputedStyles(properties);
const styleValueSourceColor = getPriorityStyleValueSource(styles);
@@ -279,7 +281,7 @@ export const PropertyLabel = ({
}
>
<Flex shrink gap={1} align="center">
- <Label color={styleValueSourceColor} truncate>
+ <Label color={styleValueSourceColor} truncate disabled={disabled}>
{label}
</Label>
</Flex>
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-code-editor.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-code-editor.tsx
new file mode 100644
index 0000000000..6e0144508c
--- /dev/null
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-code-editor.tsx
@@ -0,0 +1,166 @@
+import type { InvalidValue, StyleValue } from "@webstudio-is/css-engine";
+import { useCallback, useEffect, useRef, useState } from "react";
+import {
+ CssFragmentEditor,
+ CssFragmentEditorContent,
+ getCodeEditorCssVars,
+ parseCssFragment,
+} from "../../shared/css-fragment";
+import { PropertyInlineLabel } from "../../property-label";
+import { toValue } from "@webstudio-is/css-engine";
+import { setProperty } from "../../shared/use-style-data";
+import {
+ editRepeatedStyleItem,
+ setRepeatedStyleItem,
+} from "../../shared/repeated-style";
+import { useComputedStyleDecl } from "../../shared/model";
+import { InputErrorsTooltip } from "@webstudio-is/design-system";
+
+type IntermediateValue = {
+ type: "intermediate";
+ value: string;
+};
+
+const isTransparent = (color: StyleValue) =>
+ color.type === "keyword" && color.value === "transparent";
+
+type BackgroundCodeEditorProps = {
+ index: number;
+ /**
+ * Optional custom validation and error handling
+ */
+ onValidate?: (
+ value: string,
+ parsed: Map<string, StyleValue>
+ ) => string[] | undefined;
+};
+
+export const BackgroundCodeEditor = ({
+ index,
+ onValidate,
+}: BackgroundCodeEditorProps) => {
+ const styleDecl = useComputedStyleDecl("background-image");
+ let styleValue = styleDecl.cascadedValue;
+ if (styleValue.type === "layers") {
+ styleValue = styleValue.value[index];
+ }
+
+ const [intermediateValue, setIntermediateValue] = useState<
+ IntermediateValue | InvalidValue | undefined
+ >(undefined);
+
+ const [errors, setErrors] = useState<string[]>([]);
+
+ // Reset intermediate value when styleValue changes (e.g., from UI updates)
+ useEffect(() => {
+ setIntermediateValue(undefined);
+ }, [styleValue]);
+
+ const textAreaValue = intermediateValue?.value ?? toValue(styleValue);
+
+ const handleChange = useCallback(
+ (value: string) => {
+ setIntermediateValue({
+ type: "intermediate",
+ value,
+ });
+
+ const parsed = parseCssFragment(value, [
+ "background-image",
+ "background",
+ ]);
+ const newValue = parsed.get("background-image");
+
+ if (newValue === undefined || newValue?.type === "invalid") {
+ setIntermediateValue({
+ type: "invalid",
+ value: value,
+ });
+ return;
+ }
+
+ // Run custom validation if provided
+ if (onValidate) {
+ const validationErrors = onValidate(value, parsed);
+ if (validationErrors && validationErrors.length > 0) {
+ setErrors(validationErrors);
+ setIntermediateValue({
+ type: "invalid",
+ value: value,
+ });
+ return;
+ }
+ setErrors([]);
+ }
+
+ setRepeatedStyleItem(styleDecl, index, newValue, { isEphemeral: true });
+ },
+ [index, onValidate, styleDecl]
+ );
+
+ const handleOnComplete = useCallback(() => {
+ if (intermediateValue === undefined) {
+ return;
+ }
+
+ const parsed = parseCssFragment(intermediateValue.value, [
+ "background-image",
+ "background",
+ ]);
+ const backgroundImage = parsed.get("background-image");
+ const backgroundColor = parsed.get("background-color");
+
+ if (backgroundColor?.type === "invalid" || backgroundImage === undefined) {
+ setIntermediateValue({ type: "invalid", value: intermediateValue.value });
+ if (styleValue) {
+ setRepeatedStyleItem(styleDecl, index, styleValue, {
+ isEphemeral: true,
+ });
+ }
+ return;
+ }
+ setIntermediateValue(undefined);
+ if (backgroundColor && isTransparent(backgroundColor) === false) {
+ setProperty("background-color")(backgroundColor);
+ }
+ editRepeatedStyleItem(
+ [styleDecl],
+ index,
+ new Map([["background-image", backgroundImage]])
+ );
+ }, [index, intermediateValue, styleDecl, styleValue]);
+
+ const handleOnCompleteRef = useRef(handleOnComplete);
+ useEffect(() => {
+ handleOnCompleteRef.current = handleOnComplete;
+ }, [handleOnComplete]);
+
+ useEffect(() => {
+ return () => {
+ handleOnCompleteRef.current();
+ };
+ }, []);
+
+ return (
+ <>
+ <PropertyInlineLabel
+ label="Code"
+ description="Paste a CSS gradient or image, for example: linear-gradient(...) or url('image.jpg'). If pasting from Figma, remove the 'background' property name."
+ />
+ <InputErrorsTooltip errors={errors}>
+ <CssFragmentEditor
+ css={getCodeEditorCssVars({ minHeight: "4lh", maxHeight: "4lh" })}
+ content={
+ <CssFragmentEditorContent
+ invalid={intermediateValue?.type === "invalid"}
+ autoFocus={styleValue.type === "var"}
+ value={textAreaValue ?? ""}
+ onChange={handleChange}
+ onChangeComplete={handleOnComplete}
+ />
+ }
+ />
+ </InputErrorsTooltip>
+ </>
+ );
+};
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.stories.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.stories.tsx
index d34a4df272..19711a4a0e 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.stories.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.stories.tsx
@@ -1,4 +1,4 @@
-import { useRef } from "react";
+import { useEffect, useRef } from "react";
import { getStyleDeclKey, type StyleDecl } from "@webstudio-is/sdk";
import {
FloatingPanel,
@@ -7,6 +7,7 @@ import {
import { createDefaultPages } from "@webstudio-is/project-build";
import {
$breakpoints,
+ $instances,
$pages,
$selectedBreakpointId,
$styles,
@@ -15,37 +16,56 @@ import {
import { registerContainers } from "~/shared/sync";
import { BackgroundContent } from "./background-content";
import { $awareness } from "~/shared/awareness";
-
-const backgroundImage: StyleDecl = {
- breakpointId: "base",
- styleSourceId: "local",
- property: "backgroundImage",
- value: {
- type: "layers",
- value: [{ type: "keyword", value: "none" }],
- },
-};
+import { useComputedStyleDecl } from "../../shared/model";
+import { setRepeatedStyleItem } from "../../shared/repeated-style";
+import { type StyleValue } from "@webstudio-is/css-engine";
registerContainers();
$breakpoints.set(new Map([["base", { id: "base", label: "" }]]));
$selectedBreakpointId.set("base");
-$styles.set(new Map([[getStyleDeclKey(backgroundImage), backgroundImage]]));
$styleSourceSelections.set(
new Map([["box", { instanceId: "box", values: ["local"] }]])
);
+$instances.set(
+ new Map([
+ ["box", { type: "instance", id: "box", component: "Box", children: [] }],
+ ])
+);
$pages.set(
createDefaultPages({
homePageId: "homePageId",
rootInstanceId: "box",
})
);
+
+const defaultBackgroundImage: StyleDecl = {
+ breakpointId: "base",
+ styleSourceId: "local",
+ property: "backgroundImage",
+ value: {
+ type: "layers",
+ value: [{ type: "keyword", value: "none" }],
+ },
+};
+
+$styles.set(
+ new Map([[getStyleDeclKey(defaultBackgroundImage), defaultBackgroundImage]])
+);
+
$awareness.set({
pageId: "homePageId",
instanceSelector: ["box"],
});
-export const BackgroundContentStory = () => {
+const BackgroundStory = ({ styleValue }: { styleValue: StyleValue }) => {
const elementRef = useRef<HTMLDivElement>(null);
+ const backgroundImage = useComputedStyleDecl("background-image");
+
+ useEffect(() => {
+ setRepeatedStyleItem(backgroundImage, 0, styleValue);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
return (
<>
<div ref={elementRef} style={{ marginLeft: "400px" }}></div>
@@ -63,7 +83,48 @@ export const BackgroundContentStory = () => {
);
};
+export const Image = () => {
+ const styleValue: StyleValue = { type: "keyword", value: "none" };
+ return <BackgroundStory styleValue={styleValue} />;
+};
+
+export const LinearGradient = () => {
+ const styleValue: StyleValue = {
+ type: "unparsed",
+ value:
+ "linear-gradient(135deg, rgba(255,126,95,1) 0%, rgba(254,180,123,1) 35%, rgba(134,168,231,1) 100%)",
+ };
+ return <BackgroundStory styleValue={styleValue} />;
+};
+
+export const ConicGradient = () => {
+ const styleValue: StyleValue = {
+ type: "unparsed",
+ value:
+ "conic-gradient(from 0deg at 50% 50%, rgba(255,126,95,1) 0deg, rgba(254,180,123,1) 120deg, rgba(134,168,231,1) 240deg, rgba(255,126,95,1) 360deg)",
+ };
+ return <BackgroundStory styleValue={styleValue} />;
+};
+
+export const RadialGradient = () => {
+ const styleValue: StyleValue = {
+ type: "unparsed",
+ value:
+ "radial-gradient(circle at 50% 50%, rgba(255,126,95,1) 0%, rgba(254,180,123,1) 50%, rgba(134,168,231,1) 100%)",
+ };
+ return <BackgroundStory styleValue={styleValue} />;
+};
+
+export const SolidColorGradient = () => {
+ const styleValue: StyleValue = {
+ type: "unparsed",
+ value:
+ "linear-gradient(0deg, rgba(56,189,248,1) 0%, rgba(56,189,248,1) 100%)",
+ };
+ return <BackgroundStory styleValue={styleValue} />;
+};
+
export default {
title: "Style Panel/Background",
- component: BackgroundContent,
+ component: Image,
};
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsx
index 17e9f85618..9937be0914 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsx
@@ -3,13 +3,17 @@
* as of now just implement feature parity with old backgrounds section
**/
-import { useRef, useState } from "react";
+import { type ReactNode, useCallback, useRef, useState } from "react";
import { propertyDescriptions } from "@webstudio-is/css-data";
import {
RepeatGridIcon,
RepeatColumnIcon,
RepeatRowIcon,
XSmallIcon,
+ ImageIcon,
+ GradientLinearIcon,
+ GradientConicIcon,
+ GradientRadialIcon,
} from "@webstudio-is/icons";
import { type StyleValue, toValue } from "@webstudio-is/css-engine";
import {
@@ -20,43 +24,185 @@ import {
ToggleGroupButton,
Separator,
styled,
- FloatingPanelProvider,
+ Box,
+ EnhancedTooltip,
+ ScrollArea,
} from "@webstudio-is/design-system";
-import { ImageControl, SelectControl } from "../../controls";
+import { SelectControl } from "../../controls";
+import { ToggleGroupTooltip } from "../../controls/toggle-group/toggle-group-control";
import { BackgroundSize } from "./background-size";
import { BackgroundGradient } from "./background-gradient";
import { BackgroundImage } from "./background-image";
import { BackgroundPosition } from "./background-position";
-import { PropertyInlineLabel } from "../../property-label";
-import { ToggleGroupTooltip } from "../../controls/toggle-group/toggle-group-control";
+import {
+ PropertyLabel,
+ PropertyValueTooltip,
+ PropertyInlineLabel,
+} from "../../property-label";
import { useComputedStyleDecl } from "../../shared/model";
import {
getRepeatedStyleItem,
setRepeatedStyleItem,
} from "../../shared/repeated-style";
+import type { ComputedStyleDecl } from "~/shared/style-object-model";
+import {
+ detectBackgroundType,
+ formatGradientForType,
+ getBackgroundStyleItem,
+ type BackgroundType,
+} from "./gradient-utils";
+import { CollapsibleSectionRoot } from "~/builder/shared/collapsible-section";
-const detectImageOrGradientToggle = (styleValue?: StyleValue) => {
- if (styleValue?.type === "image") {
- return "image";
- }
-
- if (styleValue?.type === "keyword") {
- // The only allowed keyword for backgroundImage is none
- return "image";
- }
+const ColorSwatchIcon = styled("div", {
+ width: theme.spacing[7],
+ height: theme.spacing[7],
+ borderRadius: theme.borderRadius[3],
+ backgroundColor: theme.colors.foregroundMain,
+ boxShadow: `inset 0 0 0 1px ${theme.colors.borderMain}`,
+});
- return "gradient";
+type BackgroundTypeOption = {
+ value: BackgroundType;
+ label: string;
+ description: string;
+ code: string;
+ icon: ReactNode;
+ autoFocus?: boolean;
};
-const isImageOrGradient = (value: string): value is "image" | "gradient" => {
- return value === "image" || value === "gradient";
+// looks like now when dialog is open first toggle group buttons need to have autoFocus
+// otherwise the following "Choose image" button is focused
+// https://github.com/radix-ui/primitives/pull/2027
+// https://github.com/radix-ui/primitives/issues/1910
+const backgroundTypeOptions: BackgroundTypeOption[] = [
+ {
+ value: "image",
+ label: "Image",
+ description:
+ "Use an image asset, remote URL, or data URI as the layer background.",
+ code: "background-image: url(...);",
+ icon: <ImageIcon />,
+ autoFocus: true,
+ },
+ {
+ value: "solid",
+ label: "Solid",
+ description:
+ "Use a single color layer while keeping control over stacking order.",
+ code: "background-image: linear-gradient(color, color);",
+ icon: <ColorSwatchIcon />,
+ },
+ {
+ value: "linearGradient",
+ label: "Linear gradient",
+ description:
+ "Blend multiple colors along a line to create smooth transitions.",
+ code: "background-image: linear-gradient(...);",
+ icon: <GradientLinearIcon />,
+ },
+ {
+ value: "radialGradient",
+ label: "Radial gradient",
+ description:
+ "Blend multiple colors in a circular pattern to create smooth transitions.",
+ code: "background-image: radial-gradient(...);",
+ icon: <GradientRadialIcon />,
+ },
+ {
+ value: "conicGradient",
+ label: "Conic gradient",
+ description:
+ "Spin colors around a center point for charts, dials, and spotlight effects.",
+ code: "background-image: conic-gradient(...);",
+ icon: <GradientConicIcon />,
+ },
+];
+
+type BackgroundTypeToggleProps = {
+ value: BackgroundType;
+ onChange: (value: BackgroundType) => void;
+ backgroundStyleItem: StyleValue | undefined;
+ styleDecl: ComputedStyleDecl;
+ index: number;
+ cachedValues: React.MutableRefObject<
+ Partial<Record<BackgroundType, StyleValue>>
+ >;
};
-const BackgroundSection = styled("div", { padding: theme.panel.padding });
+const BackgroundTypeToggle = ({
+ value,
+ onChange,
+ backgroundStyleItem,
+ styleDecl,
+ index,
+ cachedValues,
+}: BackgroundTypeToggleProps) => {
+ const handleValueChange = useCallback(
+ (nextValue: BackgroundType) => {
+ if (nextValue === value) {
+ return;
+ }
-const Spacer = styled("div", {
- height: theme.spacing[5],
-});
+ // Cache current value before switching
+ if (backgroundStyleItem !== undefined) {
+ cachedValues.current[value] = backgroundStyleItem;
+ }
+
+ onChange(nextValue);
+
+ // Check if we have a cached value for the new type
+ const cachedValue = cachedValues.current[nextValue];
+
+ if (nextValue === "image") {
+ // For image, restore cached value or set to none
+ if (cachedValue !== undefined) {
+ setRepeatedStyleItem(styleDecl, index, cachedValue);
+ } else {
+ setRepeatedStyleItem(styleDecl, index, {
+ type: "keyword",
+ value: "none",
+ });
+ }
+ } else {
+ // For gradients and solid color, restore cached or generate new
+ const gradientValue = cachedValue
+ ? cachedValue.type === "unparsed"
+ ? cachedValue.value
+ : formatGradientForType(cachedValue, nextValue)
+ : formatGradientForType(backgroundStyleItem, nextValue);
+
+ setRepeatedStyleItem(styleDecl, index, {
+ type: "unparsed",
+ value: gradientValue,
+ });
+ }
+ },
+ [backgroundStyleItem, index, onChange, styleDecl, value, cachedValues]
+ );
+
+ return (
+ <ToggleGroup
+ type="single"
+ value={value}
+ aria-label="Background type"
+ onValueChange={handleValueChange}
+ >
+ {backgroundTypeOptions.map(
+ ({ value: optionValue, label, icon, autoFocus }) => (
+ <EnhancedTooltip key={optionValue} content={label}>
+ <ToggleGroupButton
+ value={optionValue}
+ aria-label={label}
+ autoFocus={autoFocus}
+ >
+ <Flex css={{ px: theme.spacing[3] }}>{icon}</Flex>
+ </ToggleGroupButton>
+ </EnhancedTooltip>
+ )
+ )}
+ </ToggleGroup>
+ );
+};
const BackgroundRepeat = ({ index }: { index: number }) => {
const styleDecl = useComputedStyleDecl("background-repeat");
@@ -94,40 +240,56 @@ const BackgroundRepeat = ({ index }: { index: number }) => {
// onMouseEnter used to preserve default hovering behavior on tooltip.
const [activeTooltip, setActiveTooltip] = useState<undefined | string>();
return (
- <ToggleGroup
- type="single"
- value={toValue(value)}
- onValueChange={(value) => {
- setRepeatedStyleItem(styleDecl, index, { type: "keyword", value });
- }}
+ <PropertyValueTooltip
+ label="Repeat"
+ description={propertyDescriptions.backgroundRepeat}
+ properties={["background-repeat"]}
>
- {items.map((item) => (
- <ToggleGroupTooltip
- key={item.value}
- isOpen={item.value === activeTooltip}
- onOpenChange={(isOpen) =>
- setActiveTooltip(isOpen ? item.value : undefined)
- }
- isSelected={false}
- label="Background Repeat"
- code={`background-repeat: ${item.value};`}
- description={item.description}
- properties={["background-repeat"]}
- >
- <ToggleGroupButton
- value={item.value}
- onMouseEnter={() =>
- // reset only when highlighted is not active
- setActiveTooltip((prevValue) =>
- prevValue === item.value ? prevValue : undefined
- )
+ <ToggleGroup
+ type="single"
+ value={toValue(value)}
+ aria-label="Background repeat"
+ onValueChange={(value) => {
+ setRepeatedStyleItem(styleDecl, index, { type: "keyword", value });
+ }}
+ >
+ {items.map((item) => (
+ <ToggleGroupTooltip
+ key={item.value}
+ isOpen={item.value === activeTooltip}
+ onOpenChange={(isOpen) =>
+ setActiveTooltip(isOpen ? item.value : undefined)
}
+ isSelected={false}
+ label="Background Repeat"
+ code={`background-repeat: ${item.value};`}
+ description={item.description}
+ properties={["background-repeat"]}
>
- {item.child}
- </ToggleGroupButton>
- </ToggleGroupTooltip>
- ))}
- </ToggleGroup>
+ <ToggleGroupButton
+ value={item.value}
+ aria-label={
+ item.value === "no-repeat"
+ ? "Do not repeat background"
+ : item.value === "repeat"
+ ? "Repeat background"
+ : item.value === "repeat-y"
+ ? "Repeat background vertically"
+ : "Repeat background horizontally"
+ }
+ onMouseEnter={() =>
+ // reset only when highlighted is not active
+ setActiveTooltip((prevValue) =>
+ prevValue === item.value ? prevValue : undefined
+ )
+ }
+ >
+ {item.child}
+ </ToggleGroupButton>
+ </ToggleGroupTooltip>
+ ))}
+ </ToggleGroup>
+ </PropertyValueTooltip>
);
};
@@ -135,152 +297,147 @@ const BackgroundAttachment = ({ index }: { index: number }) => {
const styleDecl = useComputedStyleDecl("background-attachment");
const value = getRepeatedStyleItem(styleDecl, index);
return (
- <ToggleGroup
- type="single"
- value={toValue(value)}
- onValueChange={(value) => {
- setRepeatedStyleItem(styleDecl, index, { type: "keyword", value });
- }}
+ <PropertyValueTooltip
+ label="Attachment"
+ description={propertyDescriptions.backgroundAttachment}
+ properties={["background-attachment"]}
>
- <ToggleGroupButton value={"scroll"}>
- <Flex css={{ px: theme.spacing[3] }}>Scroll</Flex>
- </ToggleGroupButton>
- <ToggleGroupButton value={"fixed"}>
- <Flex css={{ px: theme.spacing[3] }}>Fixed</Flex>
- </ToggleGroupButton>
- </ToggleGroup>
+ <ToggleGroup
+ type="single"
+ value={toValue(value)}
+ aria-label="Background attachment"
+ onValueChange={(value) => {
+ setRepeatedStyleItem(styleDecl, index, { type: "keyword", value });
+ }}
+ >
+ <ToggleGroupButton value={"scroll"}>
+ <Flex css={{ px: theme.spacing[3] }}>Scroll</Flex>
+ </ToggleGroupButton>
+ <ToggleGroupButton value={"fixed"}>
+ <Flex css={{ px: theme.spacing[3] }}>Fixed</Flex>
+ </ToggleGroupButton>
+ </ToggleGroup>
+ </PropertyValueTooltip>
);
};
-export const BackgroundContent = ({ index }: { index: number }) => {
- const backgroundImage = useComputedStyleDecl("background-image");
-
- const elementRef = useRef<HTMLDivElement>(null);
- const [imageGradientToggle, setImageGradientToggle] = useState<
- "image" | "gradient"
- >(() =>
- detectImageOrGradientToggle(getRepeatedStyleItem(backgroundImage, index))
- );
-
+const OtherLayerProperties = ({ index }: { index: number }) => {
return (
- <>
- <BackgroundSection ref={elementRef}>
- <Flex justify="center">
- <ToggleGroup
- type="single"
- value={imageGradientToggle}
- onValueChange={(value) => {
- if (isImageOrGradient(value)) {
- setImageGradientToggle(value);
- }
- }}
- >
- {/* looks like now when dialog is open first toggle group buttons need to have autoFocus
- otherwise the following "Choose image" button is focused
- https://github.com/radix-ui/primitives/pull/2027
- https://github.com/radix-ui/primitives/issues/1910
- */}
- <ToggleGroupButton value={"image"} autoFocus={true}>
- <Flex css={{ px: theme.spacing[3] }}>Image</Flex>
- </ToggleGroupButton>
- <ToggleGroupButton value={"gradient"}>
- <Flex css={{ px: theme.spacing[3] }}>Gradient</Flex>
- </ToggleGroupButton>
- </ToggleGroup>
- </Flex>
- </BackgroundSection>
-
- <Separator css={{ gridColumn: "span 2" }} />
-
- <BackgroundSection>
- <Grid
- css={{ gridTemplateColumns: `1fr ${theme.spacing[23]}` }}
- align="center"
- gap={2}
- >
- {imageGradientToggle === "image" && (
- <>
- <Flex css={{ height: "100%" }} align="start">
- <PropertyInlineLabel
- label="Image"
- description={propertyDescriptions.backgroundImage}
- properties={["background-image"]}
- />
- </Flex>
- <FloatingPanelProvider container={elementRef}>
- <ImageControl property="background-image" index={index} />
- </FloatingPanelProvider>
- </>
- )}
+ <CollapsibleSectionRoot label={"More properties"} fullWidth={true}>
+ <Flex
+ gap="2"
+ direction="column"
+ css={{ paddingInline: theme.panel.paddingInline }}
+ >
+ <Grid columns={2} gap={2}>
+ <PropertyLabel
+ label="Blend mode"
+ description={propertyDescriptions.backgroundBlendMode}
+ properties={["background-blend-mode"]}
+ />
+ <SelectControl property="background-blend-mode" index={index} />
+ </Grid>
+ <BackgroundSize index={index} />
+ <BackgroundPosition index={index} />
+ <Grid columns={2} align="center" gap={2}>
+ <PropertyLabel
+ label="Repeat"
+ description={propertyDescriptions.backgroundRepeat}
+ properties={["background-repeat"]}
+ />
+ <BackgroundRepeat index={index} />
- <PropertyInlineLabel
+ <PropertyLabel
+ label="Attachment"
+ description={propertyDescriptions.backgroundAttachment}
+ properties={["background-attachment"]}
+ />
+ <BackgroundAttachment index={index} />
+ </Grid>
+ <Grid columns={2} align="center" gap={2}>
+ <PropertyLabel
label="Clip"
description={propertyDescriptions.backgroundClip}
properties={["background-clip"]}
/>
<SelectControl property="background-clip" index={index} />
- <PropertyInlineLabel
+ <PropertyLabel
label="Origin"
description={propertyDescriptions.backgroundOrigin}
properties={["background-origin"]}
/>
<SelectControl property="background-origin" index={index} />
</Grid>
+ </Flex>
+ </CollapsibleSectionRoot>
+ );
+};
- <Spacer />
+export const BackgroundContent = ({ index }: { index: number }) => {
+ const backgroundImage = useComputedStyleDecl("background-image");
+ const backgroundStyleItem = getBackgroundStyleItem(backgroundImage, index);
- <BackgroundSize index={index} />
+ const [backgroundType, setBackgroundType] = useState<BackgroundType>(() =>
+ detectBackgroundType(backgroundStyleItem)
+ );
- <Spacer />
+ // Cache background values for each type to preserve user's intermediate changes
+ const cachedValuesRef = useRef<Partial<Record<BackgroundType, StyleValue>>>(
+ {}
+ );
- <BackgroundPosition index={index} />
+ return (
+ <>
+ <Flex
+ align="center"
+ gap="2"
+ justify="between"
+ css={{ padding: theme.panel.padding }}
+ shrink={false}
+ >
+ <PropertyInlineLabel
+ label="Type"
+ description={propertyDescriptions.backgroundImage}
+ />
+ <BackgroundTypeToggle
+ value={backgroundType}
+ onChange={setBackgroundType}
+ backgroundStyleItem={backgroundStyleItem}
+ styleDecl={backgroundImage}
+ index={index}
+ cachedValues={cachedValuesRef}
+ />
+ </Flex>
+
+ <Separator />
- <Grid
- css={{
- gridTemplateColumns: `1fr ${theme.spacing[22]}`,
- mt: theme.spacing[5],
- }}
- align="center"
- gap={2}
- >
- {imageGradientToggle === "image" && (
- <>
- <PropertyInlineLabel
- label="Repeat"
- description={propertyDescriptions.backgroundRepeat}
- properties={["background-repeat"]}
- />
- <Flex css={{ justifySelf: "end" }}>
- <BackgroundRepeat index={index} />
- </Flex>
- </>
+ <ScrollArea>
+ <Box css={{ maxHeight: 500 }}>
+ {(backgroundType === "linearGradient" ||
+ backgroundType === "conicGradient" ||
+ backgroundType === "radialGradient" ||
+ backgroundType === "solid") && (
+ <BackgroundGradient
+ index={index}
+ type={
+ backgroundType === "conicGradient"
+ ? "conic"
+ : backgroundType === "radialGradient"
+ ? "radial"
+ : "linear"
+ }
+ variant={backgroundType === "solid" ? "solid" : "default"}
+ />
)}
- <PropertyInlineLabel
- label="Attachment"
- description={propertyDescriptions.backgroundAttachment}
- properties={["background-attachment"]}
- />
- <Flex css={{ justifySelf: "end" }}>
- <BackgroundAttachment index={index} />
- </Flex>
+ {backgroundType === "image" && <BackgroundImage index={index} />}
- <PropertyInlineLabel
- label="Blend mode"
- description={propertyDescriptions.backgroundBlendMode}
- properties={["background-blend-mode"]}
- />
- <SelectControl property="background-blend-mode" index={index} />
- </Grid>
- </BackgroundSection>
- <Separator css={{ gridColumn: "span 2" }} />
+ <Separator />
- {imageGradientToggle === "image" ? (
- <BackgroundImage index={index} />
- ) : (
- <BackgroundGradient index={index} />
- )}
+ <OtherLayerProperties index={index} />
+ </Box>
+ </ScrollArea>
</>
);
};
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-gradient.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-gradient.tsx
index 74d33ad9fb..f6cf85664b 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-gradient.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-gradient.tsx
@@ -1,156 +1,1245 @@
import {
toValue,
- type InvalidValue,
type StyleValue,
+ type UnitValue,
} from "@webstudio-is/css-engine";
-import { parseCssValue } from "@webstudio-is/css-data";
-import { Flex, Label, Text, theme, Tooltip } from "@webstudio-is/design-system";
-import { useEffect, useRef, useState } from "react";
-import { InfoCircleIcon } from "@webstudio-is/icons";
-import { setProperty } from "../../shared/use-style-data";
-import { useComputedStyleDecl } from "../../shared/model";
import {
- editRepeatedStyleItem,
- setRepeatedStyleItem,
-} from "../../shared/repeated-style";
+ parseLinearGradient,
+ parseConicGradient,
+ parseRadialGradient,
+ type ParsedGradient,
+ type ParsedLinearGradient,
+ type ParsedConicGradient,
+ type ParsedRadialGradient,
+ type GradientStop,
+ formatLinearGradient,
+} from "@webstudio-is/css-data";
import {
- parseCssFragment,
- CssFragmentEditor,
- CssFragmentEditorContent,
-} from "../../shared/css-fragment";
-
-type IntermediateValue = {
- type: "intermediate";
- value: string;
+ Flex,
+ theme,
+ Tooltip,
+ GradientPicker,
+ Grid,
+ Box,
+ IconButton,
+ Select,
+ Separator,
+ ToggleGroup,
+ ToggleGroupButton,
+} from "@webstudio-is/design-system";
+import { ColorPickerControl } from "../../shared/color-picker";
+import {
+ useCallback,
+ useEffect,
+ useMemo,
+ useState,
+ type Dispatch,
+ type SetStateAction,
+} from "react";
+import {
+ ArrowRightLeftIcon,
+ CircleIcon,
+ EllipseIcon,
+ MinusIcon,
+ PlusIcon,
+ RepeatGridIcon,
+ XSmallIcon,
+} from "@webstudio-is/icons";
+import { clamp } from "@react-aria/utils";
+import {
+ useComputedStyleDecl,
+ $availableUnitVariables,
+} from "../../shared/model";
+import { setRepeatedStyleItem } from "../../shared/repeated-style";
+import { useLocalValue } from "../../../settings-panel/shared";
+import { CssValueInputContainer } from "../../shared/css-value-input";
+import { PropertyInlineLabel } from "../../property-label";
+import {
+ angleUnitOptions,
+ clampStopIndex,
+ createDefaultGradient,
+ createSolidLinearGradient,
+ createPercentUnitValue,
+ ensureGradientHasStops,
+ fallbackStopColor,
+ formatGradientPositionValues,
+ formatGradientValue,
+ getDefaultAngle,
+ getPercentUnit,
+ gradientPositionXOptions,
+ gradientPositionYOptions,
+ isConicGradient,
+ isLinearGradient,
+ isRadialGradient,
+ normalizeGradientInput,
+ parseGradientPositionValues,
+ percentUnitOptions,
+ pruneHintOverrides,
+ removeHintOverride,
+ resolveAngleValue,
+ resolveGradientForPicker,
+ resolveReverseStops,
+ resolveStopHintUpdate,
+ resolveStopPositionUpdate,
+ setHintOverride,
+ styleValueToColor,
+} from "./gradient-utils";
+import { BackgroundPositionControl } from "./background-position";
+import { BackgroundCodeEditor } from "./background-code-editor";
+import type {
+ GradientType,
+ IntermediateColorValue,
+ PercentUnitValue,
+} from "./gradient-utils";
+
+const radialSizeOptions = [
+ "closest-side",
+ "closest-corner",
+ "farthest-side",
+ "farthest-corner",
+] as const;
+
+type RadialSizeOption = (typeof radialSizeOptions)[number];
+
+const radialSizeOptionsSet = new Set<RadialSizeOption>(radialSizeOptions);
+
+const defaultRadialSize: RadialSizeOption = "farthest-corner";
+const defaultRadialShape = "ellipse" as const;
+
+const leftToRightAngle = {
+ type: "unit",
+ unit: "deg",
+ value: 90,
+} satisfies UnitValue;
+
+const radialSizeDescriptions: Record<RadialSizeOption, string> = {
+ "closest-side": "Extends to the nearest edge of the container",
+ "closest-corner": "Extends to the nearest corner of the container",
+ "farthest-side": "Extends to the farthest edge of the container",
+ "farthest-corner": "Extends to the farthest corner of the container",
};
-const isTransparent = (color: StyleValue) =>
- color.type === "keyword" && color.value === "transparent";
+const radialShapeDescriptions = {
+ ellipse: "Use an ellipse ending shape (radial-gradient ellipse).",
+ circle: "Use a circle ending shape (radial-gradient circle).",
+} as const;
-export const BackgroundGradient = ({ index }: { index: number }) => {
+type GradientEditorApplyFn = (
+ nextGradient: ParsedGradient,
+ options?: { isEphemeral?: boolean }
+) => void;
+
+const getStopPosition = (stop: GradientStop): number =>
+ stop.position?.type === "unit" && stop.position.unit === "%"
+ ? stop.position.value
+ : 0;
+
+const reindexHintOverrides = (
+ overrides: Map<number, PercentUnitValue>,
+ deletedIndex: number
+): Map<number, PercentUnitValue> => {
+ const reindexed = new Map<number, PercentUnitValue>();
+ overrides.forEach((value, key) => {
+ if (key < deletedIndex) {
+ reindexed.set(key, value);
+ } else if (key > deletedIndex) {
+ reindexed.set(key - 1, value);
+ }
+ });
+ return reindexed;
+};
+
+const getAvailableUnitVariables = () => $availableUnitVariables.get();
+
+const clampPercentUnit = (value: PercentUnitValue): PercentUnitValue => ({
+ ...value,
+ value: clamp(value.value, 0, 100),
+});
+
+export const BackgroundGradient = ({
+ index,
+ type: gradientType = "linear",
+ variant = "default",
+}: {
+ index: number;
+ type?: GradientType;
+ variant?: "default" | "solid";
+}) => {
const styleDecl = useComputedStyleDecl("background-image");
let styleValue = styleDecl.cascadedValue;
if (styleValue.type === "layers") {
styleValue = styleValue.value[index];
}
- const [intermediateValue, setIntermediateValue] = useState<
- IntermediateValue | InvalidValue | undefined
- >(undefined);
+ const gradientString = toValue(styleValue);
+ const { normalizedGradientString, initialIsRepeating } =
+ normalizeGradientInput(gradientString, gradientType);
+
+ const parsedGradient = useMemo(() => {
+ if (gradientType === "linear") {
+ const parsed =
+ parseLinearGradient(normalizedGradientString) ??
+ createDefaultGradient("linear");
+ return ensureGradientHasStops(parsed);
+ }
+ if (gradientType === "conic") {
+ const parsed =
+ parseConicGradient(normalizedGradientString) ??
+ createDefaultGradient("conic");
+ return ensureGradientHasStops(parsed);
+ }
+ const parsed =
+ parseRadialGradient(normalizedGradientString) ??
+ createDefaultGradient("radial");
+ return ensureGradientHasStops(parsed);
+ }, [gradientType, normalizedGradientString]);
+
+ const handleGradientSave = useCallback(
+ (nextGradient: ParsedGradient) => {
+ const gradientValue = formatGradientValue(nextGradient);
+ const style: StyleValue = { type: "unparsed", value: gradientValue };
+ setRepeatedStyleItem(styleDecl, index, style);
+ },
+ [index, styleDecl]
+ );
- const textAreaValue = intermediateValue?.value ?? toValue(styleValue);
+ const {
+ value: gradient,
+ set: setLocalGradient,
+ save: saveLocalGradient,
+ } = useLocalValue<ParsedGradient>(parsedGradient, handleGradientSave, {
+ autoSave: false,
+ });
+ const [selectedStopIndex, setSelectedStopIndex] = useState(0);
+ const [hintOverrides, setHintOverrides] = useState(
+ () => new Map<number, PercentUnitValue>()
+ );
+ const [isRepeating, setIsRepeating] = useState(initialIsRepeating);
+ const isSolidVariant = variant === "solid";
- const handleChange = (value: string) => {
- setIntermediateValue({
- type: "intermediate",
- value,
+ useEffect(() => {
+ setSelectedStopIndex((currentIndex) =>
+ clampStopIndex(currentIndex, gradient)
+ );
+ }, [gradient]);
+
+ useEffect(() => {
+ setHintOverrides((previous) => {
+ return pruneHintOverrides(previous, gradient.stops.length);
});
+ }, [gradient]);
- // This doesn't have the same behavior as CssValueInput.
- // However, it's great to see the immediate results when making gradient changes,
- // especially until we have a better gradient tool.
- const newValue = parseCssValue("background-image", value);
+ useEffect(() => {
+ setIsRepeating(initialIsRepeating);
+ }, [initialIsRepeating]);
- if (newValue.type === "unparsed" || newValue.type === "var") {
- setRepeatedStyleItem(styleDecl, index, newValue, { isEphemeral: true });
- return;
- }
+ const applyGradient = useCallback(
+ (nextGradient: ParsedGradient, options?: { isEphemeral?: boolean }) => {
+ const isEphemeral = options?.isEphemeral === true;
+ setLocalGradient(nextGradient);
+ const gradientValue = formatGradientValue(nextGradient);
+ setRepeatedStyleItem(
+ styleDecl,
+ index,
+ { type: "unparsed", value: gradientValue },
+ { isEphemeral }
+ );
+ if (isEphemeral === false) {
+ saveLocalGradient();
+ }
+ },
+ [index, saveLocalGradient, setLocalGradient, styleDecl]
+ );
+
+ return (
+ <Flex direction="column" justify="center" gap="2" shrink={false}>
+ {isSolidVariant ? (
+ <Box css={{ padding: theme.panel.padding }}>
+ <SolidColorControls
+ gradient={gradient}
+ applyGradient={applyGradient}
+ />
+ </Box>
+ ) : (
+ <>
+ <GradientPickerSection
+ gradient={gradient}
+ gradientType={gradientType}
+ hintOverrides={hintOverrides}
+ setHintOverrides={setHintOverrides}
+ setSelectedStopIndex={setSelectedStopIndex}
+ applyGradient={applyGradient}
+ styleDecl={styleDecl}
+ index={index}
+ selectedStopIndex={selectedStopIndex}
+ />
+ <Separator />
+ <Box css={{ paddingInline: theme.panel.paddingInline }}>
+ <OtherGradientPropertiesSection
+ gradient={gradient}
+ applyGradient={applyGradient}
+ isRepeating={isRepeating}
+ setIsRepeating={setIsRepeating}
+ />
+ </Box>
+ <Box css={{ paddingInline: theme.panel.paddingInline }}>
+ <GradientPositionControls
+ gradient={gradient}
+ applyGradient={applyGradient}
+ />
+ </Box>
+ </>
+ )}
+ <Box
+ css={{
+ paddingInline: theme.panel.paddingInline,
+ paddingBottom: theme.panel.paddingBlock,
+ }}
+ >
+ <BackgroundCodeEditor index={index} />
+ </Box>
+ </Flex>
+ );
+};
+
+type GradientPickerSectionProps = {
+ gradient: ParsedGradient;
+ gradientType: GradientType;
+ hintOverrides: Map<number, PercentUnitValue>;
+ setHintOverrides: Dispatch<SetStateAction<Map<number, PercentUnitValue>>>;
+ setSelectedStopIndex: Dispatch<SetStateAction<number>>;
+ applyGradient: GradientEditorApplyFn;
+ styleDecl: ReturnType<typeof useComputedStyleDecl>;
+ index: number;
+ selectedStopIndex: number;
+};
- // Set backgroundImage at layer to none if it's invalid
- setRepeatedStyleItem(
- styleDecl,
- index,
- { type: "keyword", value: "none" },
- { isEphemeral: true }
+const GradientPickerSection = ({
+ gradient,
+ gradientType,
+ hintOverrides,
+ setHintOverrides,
+ setSelectedStopIndex,
+ applyGradient,
+ styleDecl,
+ index,
+ selectedStopIndex,
+}: GradientPickerSectionProps) => {
+ const parsedComputedGradient = useMemo(() => {
+ let computedStyleValue = styleDecl.computedValue;
+ if (computedStyleValue?.type === "layers") {
+ computedStyleValue = computedStyleValue.value[index];
+ }
+ const computedGradientString = toValue(computedStyleValue);
+ const { normalizedGradientString } = normalizeGradientInput(
+ computedGradientString,
+ gradientType
);
- };
- const handleOnComplete = () => {
- if (intermediateValue === undefined) {
+ if (gradientType === "linear") {
+ const parsed =
+ parseLinearGradient(normalizedGradientString) ??
+ createDefaultGradient("linear");
+ return ensureGradientHasStops(parsed);
+ }
+ if (gradientType === "conic") {
+ const parsed =
+ parseConicGradient(normalizedGradientString) ??
+ createDefaultGradient("conic");
+ return ensureGradientHasStops(parsed);
+ }
+ const parsed =
+ parseRadialGradient(normalizedGradientString) ??
+ createDefaultGradient("radial");
+ return ensureGradientHasStops(parsed);
+ }, [gradientType, index, styleDecl]);
+
+ const computedGradientForPicker = useMemo(() => {
+ if (parsedComputedGradient === undefined) {
return;
}
+ return resolveGradientForPicker(
+ parsedComputedGradient,
+ new Map<number, PercentUnitValue>()
+ );
+ }, [parsedComputedGradient]);
+
+ const [isInteracting, setIsInteracting] = useState(false);
+
+ const gradientForPicker = useMemo(() => {
+ const base = resolveGradientForPicker(gradient, hintOverrides);
+ if (isInteracting || computedGradientForPicker === undefined) {
+ return base;
+ }
- const parsed = parseCssFragment(intermediateValue.value, [
- "background-image",
- "background",
- ]);
- const backgroundImage = parsed.get("background-image");
- const backgroundColor = parsed.get("background-color");
-
- // set invalid state
- if (backgroundColor?.type === "invalid" || backgroundImage === undefined) {
- setIntermediateValue({ type: "invalid", value: intermediateValue.value });
- if (styleValue) {
- setRepeatedStyleItem(styleDecl, index, styleValue, {
- isEphemeral: true,
- });
+ const computedStops = computedGradientForPicker.stops;
+ const stops = base.stops.map((stop, index) => {
+ const computedStop = computedStops[index];
+ if (computedStop === undefined) {
+ return stop;
}
- return;
+ return {
+ ...stop,
+ color: computedStop.color ?? stop.color,
+ position: computedStop.position ?? stop.position,
+ hint: computedStop.hint ?? stop.hint,
+ } satisfies GradientStop;
+ });
+
+ if (isLinearGradient(base) && isLinearGradient(computedGradientForPicker)) {
+ return {
+ ...base,
+ angle: computedGradientForPicker.angle ?? base.angle,
+ sideOrCorner:
+ computedGradientForPicker.sideOrCorner ?? base.sideOrCorner,
+ stops,
+ } satisfies ParsedLinearGradient;
}
- setIntermediateValue(undefined);
- if (backgroundColor && isTransparent(backgroundColor) === false) {
- setProperty("background-color")(backgroundColor);
+
+ if (isConicGradient(base) && isConicGradient(computedGradientForPicker)) {
+ return {
+ ...base,
+ angle: computedGradientForPicker.angle ?? base.angle,
+ position: computedGradientForPicker.position ?? base.position,
+ stops,
+ } satisfies ParsedConicGradient;
}
- // insert all new layers at current position
- editRepeatedStyleItem(
- [styleDecl],
- index,
- new Map([["background-image", backgroundImage]])
- );
- };
- const handleOnCompleteRef = useRef(handleOnComplete);
- handleOnCompleteRef.current = handleOnComplete;
+ if (isRadialGradient(base) && isRadialGradient(computedGradientForPicker)) {
+ return {
+ ...base,
+ shape: computedGradientForPicker.shape ?? base.shape,
+ size: computedGradientForPicker.size ?? base.size,
+ position: computedGradientForPicker.position ?? base.position,
+ stops,
+ } satisfies ParsedRadialGradient;
+ }
+
+ return {
+ ...base,
+ stops,
+ } as ParsedGradient;
+ }, [computedGradientForPicker, gradient, hintOverrides, isInteracting]);
+
+ const handlePickerChange = useCallback(
+ (nextGradient: ParsedGradient) => {
+ setIsInteracting(true);
+ applyGradient(nextGradient, { isEphemeral: true });
+ },
+ [applyGradient]
+ );
+
+ const handlePickerChangeComplete = useCallback(
+ (nextGradient: ParsedGradient) => {
+ setIsInteracting(false);
+ applyGradient(nextGradient);
+ },
+ [applyGradient]
+ );
- // Blur wouldn't fire if user clicks outside of the FloatingPanel
useEffect(() => {
return () => {
- handleOnCompleteRef.current();
+ setIsInteracting(false);
};
}, []);
+ const handleThumbSelect = useCallback(
+ (index: number, _stop: GradientStop) => {
+ setSelectedStopIndex(index);
+ },
+ [setSelectedStopIndex]
+ );
+ const previewGradientForTrack = useMemo<ParsedLinearGradient>(() => {
+ const previewGradient: ParsedLinearGradient = {
+ type: "linear",
+ angle: leftToRightAngle,
+ stops: gradientForPicker.stops,
+ };
+ if (gradientForPicker.repeating) {
+ previewGradient.repeating = true;
+ }
+ return previewGradient;
+ }, [gradientForPicker]);
+
return (
<Flex
direction="column"
- css={{
- gridColumn: "span 2",
- px: theme.spacing[5],
- py: theme.spacing[5],
- gap: theme.spacing[3],
- }}
+ shrink={false}
+ gap="2"
+ css={{ padding: theme.panel.padding }}
>
- <Label>
- <Flex align="center" gap="1">
- Code
+ <GradientPicker
+ gradient={gradientForPicker}
+ backgroundImage={formatLinearGradient(previewGradientForTrack)}
+ type={gradientType}
+ onChange={handlePickerChange}
+ onChangeComplete={handlePickerChangeComplete}
+ onThumbSelect={handleThumbSelect}
+ selectedStopIndex={selectedStopIndex}
+ />
+ <GradientStopControls
+ gradient={gradient}
+ selectedStopIndex={selectedStopIndex}
+ setSelectedStopIndex={setSelectedStopIndex}
+ hintOverrides={hintOverrides}
+ setHintOverrides={setHintOverrides}
+ applyGradient={applyGradient}
+ />
+ </Flex>
+ );
+};
+
+type OtherGradientPropertiesSectionProps = {
+ gradient: ParsedGradient;
+ applyGradient: GradientEditorApplyFn;
+ isRepeating: boolean;
+ setIsRepeating: Dispatch<SetStateAction<boolean>>;
+};
+
+const OtherGradientPropertiesSection = ({
+ gradient,
+ applyGradient,
+ isRepeating,
+ setIsRepeating,
+}: OtherGradientPropertiesSectionProps) => {
+ const isLinear = isLinearGradient(gradient);
+ const isConic = isConicGradient(gradient);
+ const isRadial = isRadialGradient(gradient);
+ const supportsAngle = isLinear || isConic;
+ const angleValue = supportsAngle ? gradient.angle : undefined;
+ const defaultAngle = getDefaultAngle(gradient);
+
+ const gradientTypeName = isLinear
+ ? "linear-gradient"
+ : isConic
+ ? "conic-gradient"
+ : "radial-gradient";
+ const repeatingGradientTypeName = `repeating-${gradientTypeName}`;
+
+ // Radial gradient size and shape
+ useEffect(() => {
+ if (isRadial === false) {
+ return;
+ }
+ const updates: Partial<ParsedRadialGradient> = {};
+ if (gradient.size === undefined) {
+ updates.size = defaultRadialSize;
+ }
+ const normalizedShape = gradient.shape?.value.toLowerCase();
+ if (normalizedShape !== "circle" && normalizedShape !== "ellipse") {
+ updates.shape = { type: "keyword", value: defaultRadialShape };
+ }
+ if (Object.keys(updates).length > 0) {
+ applyGradient({ ...gradient, ...updates });
+ }
+ }, [applyGradient, gradient, isRadial]);
+
+ const currentRadialSize = isRadial ? gradient.size : undefined;
+ const isPresetRadialSize =
+ typeof currentRadialSize === "string" &&
+ radialSizeOptionsSet.has(currentRadialSize as RadialSizeOption);
+ const radialSizeValue = isRadial
+ ? isPresetRadialSize
+ ? (currentRadialSize as RadialSizeOption)
+ : defaultRadialSize
+ : undefined;
+ const radialShapeValue = (() => {
+ if (isRadial && gradient.shape) {
+ const normalized = gradient.shape.value.toLowerCase();
+ if (normalized === "circle" || normalized === "ellipse") {
+ return normalized;
+ }
+ }
+ return isRadial ? defaultRadialShape : undefined;
+ })();
+
+ const handleRepeatChange = useCallback(
+ (value: string) => {
+ if (value !== "repeat" && value !== "no-repeat") {
+ return;
+ }
+ const repeating = value === "repeat";
+ setIsRepeating(repeating);
+ applyGradient({ ...gradient, repeating });
+ },
+ [applyGradient, gradient, setIsRepeating]
+ );
+
+ const handleAngleUpdate = useCallback(
+ (styleValue: StyleValue, options?: { isEphemeral?: boolean }) => {
+ if (supportsAngle === false) {
+ return;
+ }
+ const angleValue = resolveAngleValue(styleValue);
+ if (angleValue === undefined) {
+ return;
+ }
+ if (isLinear) {
+ applyGradient(
+ {
+ ...(gradient as ParsedLinearGradient),
+ angle: angleValue,
+ sideOrCorner: undefined,
+ },
+ options
+ );
+ return;
+ }
+
+ applyGradient(
+ {
+ ...(gradient as ParsedConicGradient),
+ angle: angleValue,
+ },
+ options
+ );
+ },
+ [applyGradient, gradient, isLinear, supportsAngle]
+ );
+
+ const handleAngleDelete = useCallback(
+ (options?: { isEphemeral?: boolean }) => {
+ if (supportsAngle === false) {
+ return;
+ }
+ const nextGradient: ParsedGradient = {
+ ...gradient,
+ angle: undefined,
+ };
+ applyGradient(nextGradient, options);
+ },
+ [applyGradient, gradient, supportsAngle]
+ );
+
+ const handleRadialSizeChange = useCallback(
+ (nextSize?: RadialSizeOption) => {
+ if (isRadial === false) {
+ return;
+ }
+ const size = nextSize ?? defaultRadialSize;
+ applyGradient({ ...gradient, size });
+ },
+ [applyGradient, gradient, isRadial]
+ );
+
+ const handleEndingShapeChange = useCallback(
+ (nextShape?: string) => {
+ if (isRadial === false) {
+ return;
+ }
+ const shapeValue =
+ nextShape === "circle" || nextShape === "ellipse"
+ ? nextShape
+ : defaultRadialShape;
+ applyGradient({
+ ...gradient,
+ shape: { type: "keyword", value: shapeValue },
+ });
+ },
+ [applyGradient, gradient, isRadial]
+ );
+
+ return (
+ <Flex direction="column" gap="2">
+ <Grid gap="2" columns={isRadial ? 3 : supportsAngle ? 2 : 1}>
+ {supportsAngle && (
+ <Flex direction="column" gap="1">
+ <PropertyInlineLabel
+ label="Angle"
+ description="Direction of the gradient line. 0deg is up, 90deg is right, 180deg is down, 270deg is left."
+ />
+ <CssValueInputContainer
+ property="rotate"
+ styleSource="default"
+ getOptions={getAvailableUnitVariables}
+ value={angleValue ?? defaultAngle}
+ unitOptions={angleUnitOptions}
+ onUpdate={handleAngleUpdate}
+ onDelete={handleAngleDelete}
+ />
+ </Flex>
+ )}
+ {isRadial && (
+ <Flex direction="column" gap="1">
+ <PropertyInlineLabel
+ label="Size"
+ description="Radial gradient size determining how far the gradient extends from its center."
+ />
+ <Select
+ options={radialSizeOptions}
+ value={radialSizeValue}
+ fullWidth
+ onChange={(size) => handleRadialSizeChange(size)}
+ getDescription={(option) => radialSizeDescriptions[option]}
+ />
+ </Flex>
+ )}
+ {isRadial && (
+ <Flex direction="column" gap="1">
+ <PropertyInlineLabel
+ label="Shape"
+ description="Radial gradient ending shape."
+ />
+ <ToggleGroup
+ type="single"
+ value={radialShapeValue}
+ aria-label="Radial ending shape"
+ onValueChange={handleEndingShapeChange}
+ >
+ <Tooltip
+ variant="wrapped"
+ content={radialShapeDescriptions.ellipse}
+ >
+ <ToggleGroupButton value="ellipse" aria-label="Ellipse">
+ <EllipseIcon />
+ </ToggleGroupButton>
+ </Tooltip>
+ <Tooltip
+ variant="wrapped"
+ content={radialShapeDescriptions.circle}
+ >
+ <ToggleGroupButton value="circle" aria-label="Circle">
+ <CircleIcon />
+ </ToggleGroupButton>
+ </Tooltip>
+ </ToggleGroup>
+ </Flex>
+ )}
+ <Flex direction="column" gap="1">
+ <PropertyInlineLabel
+ label="Repeat"
+ description="Whether to repeat the gradient pattern."
+ />
+ <ToggleGroup
+ type="single"
+ value={isRepeating ? "repeat" : "no-repeat"}
+ aria-label="Gradient repeat"
+ onValueChange={handleRepeatChange}
+ >
+ <Tooltip
+ variant="wrapped"
+ content={`Render the gradient once (${gradientTypeName}).`}
+ >
+ <ToggleGroupButton value="no-repeat" aria-label="No repeat">
+ <XSmallIcon />
+ </ToggleGroupButton>
+ </Tooltip>
+ <Tooltip
+ variant="wrapped"
+ content={`Repeat the gradient pattern (${repeatingGradientTypeName}).`}
+ >
+ <ToggleGroupButton value="repeat" aria-label="Repeat">
+ <RepeatGridIcon />
+ </ToggleGroupButton>
+ </Tooltip>
+ </ToggleGroup>
+ </Flex>
+ </Grid>
+ </Flex>
+ );
+};
+
+type SolidColorControlsProps = {
+ gradient: ParsedGradient;
+ applyGradient: GradientEditorApplyFn;
+};
+
+const SolidColorControls = ({
+ gradient,
+ applyGradient,
+}: SolidColorControlsProps) => {
+ const solidColor: StyleValue = (gradient.stops[0]?.color ??
+ fallbackStopColor) as StyleValue;
+
+ const applySolidColorValue = useCallback(
+ (
+ styleValue: StyleValue | IntermediateColorValue | undefined,
+ options?: { isEphemeral?: boolean }
+ ) => {
+ const nextColor = styleValueToColor(styleValue);
+ if (nextColor === undefined) {
+ return;
+ }
+ const baseGradient = isLinearGradient(gradient) ? gradient : undefined;
+ const nextGradient = createSolidLinearGradient(nextColor, baseGradient);
+ applyGradient(nextGradient, options);
+ },
+ [applyGradient, gradient]
+ );
+
+ const handleColorChange = useCallback(
+ (styleValue: StyleValue | IntermediateColorValue | undefined) => {
+ applySolidColorValue(styleValue);
+ },
+ [applySolidColorValue]
+ );
+
+ const handleColorChangeComplete = useCallback(
+ (styleValue: StyleValue) => {
+ applySolidColorValue(styleValue, { isEphemeral: false });
+ },
+ [applySolidColorValue]
+ );
+
+ return (
+ <Grid gap="2" columns="3" align="end">
+ <PropertyInlineLabel
+ label="Color"
+ description="The solid color for this background layer. Renders as a linear gradient with the same color at 0% and 100%."
+ />
+ <Flex css={{ gridColumn: "span 2" }}>
+ <ColorPickerControl
+ property="color"
+ value={solidColor}
+ currentColor={solidColor}
+ onChange={handleColorChange}
+ onChangeComplete={handleColorChangeComplete}
+ onAbort={() => {}}
+ onReset={() => {}}
+ />
+ </Flex>
+ </Grid>
+ );
+};
+
+type GradientStopControlsProps = {
+ gradient: ParsedGradient;
+ selectedStopIndex: number;
+ setSelectedStopIndex: Dispatch<SetStateAction<number>>;
+ hintOverrides: Map<number, PercentUnitValue>;
+ setHintOverrides: Dispatch<SetStateAction<Map<number, PercentUnitValue>>>;
+ applyGradient: GradientEditorApplyFn;
+};
+
+const GradientStopControls = ({
+ gradient,
+ selectedStopIndex,
+ setSelectedStopIndex,
+ hintOverrides,
+ setHintOverrides,
+ applyGradient,
+}: GradientStopControlsProps) => {
+ const reverseDisabled = gradient.stops.length <= 1;
+
+ const handleReverseStops = useCallback(() => {
+ const resolution = resolveReverseStops(gradient, selectedStopIndex);
+ if (resolution.type === "none") {
+ return;
+ }
+ setSelectedStopIndex(resolution.selectedStopIndex);
+ applyGradient(resolution.gradient);
+ }, [applyGradient, gradient, selectedStopIndex, setSelectedStopIndex]);
+
+ const updateStop = useCallback(
+ (
+ stopIndex: number,
+ updater: (stop: GradientStop) => GradientStop,
+ options?: { isEphemeral?: boolean }
+ ) => {
+ const currentStop = gradient.stops[stopIndex];
+ if (currentStop === undefined) {
+ return;
+ }
+ const stops = gradient.stops.map((stop, index) =>
+ index === stopIndex ? updater(stop) : stop
+ );
+ const nextGradient = { ...gradient, stops };
+ applyGradient(nextGradient, options);
+ },
+ [applyGradient, gradient]
+ );
+
+ const handleAddStop = useCallback(() => {
+ applyGradient({
+ ...gradient,
+ stops: [
+ ...gradient.stops,
+ {
+ color: fallbackStopColor,
+ position: createPercentUnitValue(50),
+ },
+ ],
+ });
+ }, [applyGradient, gradient]);
+
+ const handleDeleteStop = useCallback(
+ (stopIndex: number) => {
+ if (gradient.stops.length <= 2) {
+ return;
+ }
+ applyGradient({
+ ...gradient,
+ stops: gradient.stops.filter((_, index) => index !== stopIndex),
+ });
+ setHintOverrides((previous) => reindexHintOverrides(previous, stopIndex));
+ },
+ [applyGradient, gradient, setHintOverrides]
+ );
+
+ return (
+ <Flex direction="column" gap="2">
+ <Flex align="center" justify="between">
+ <PropertyInlineLabel
+ label="Stops"
+ description="Gradient color stops and their positions along the gradient line."
+ />
+ <Flex gap="1">
<Tooltip
variant="wrapped"
- content={
- <Text>
- Paste a CSS gradient, for example:
- <br />
- <br />
- linear-gradient(...)
- <br />
- <br />
- If pasting from Figma, remove the "background" property name.
- </Text>
- }
+ content="Reverse the order of all gradient stops."
>
- <InfoCircleIcon />
+ <IconButton
+ aria-label="Reverse gradient stops"
+ onClick={handleReverseStops}
+ disabled={reverseDisabled}
+ >
+ <ArrowRightLeftIcon />
+ </IconButton>
+ </Tooltip>
+ <Tooltip content="Add gradient stop" variant="wrapped">
+ <IconButton aria-label="Add stop" onClick={handleAddStop}>
+ <PlusIcon />
+ </IconButton>
</Tooltip>
</Flex>
- </Label>
- <CssFragmentEditor
- content={
- <CssFragmentEditorContent
- invalid={intermediateValue?.type === "invalid"}
- autoFocus={styleValue.type === "var"}
- value={textAreaValue ?? ""}
- onChange={handleChange}
- onChangeComplete={handleOnComplete}
- />
- }
- />
+ </Flex>
+ {gradient.stops
+ .map((stop, originalIndex) => ({ stop, originalIndex }))
+ .sort((a, b) => getStopPosition(a.stop) - getStopPosition(b.stop))
+ .map(({ stop, originalIndex: stopIndex }) => {
+ const isSelected =
+ stopIndex === clampStopIndex(selectedStopIndex, gradient);
+ const stopPositionValue = stop.position;
+ const stopHintOverride = hintOverrides.get(stopIndex);
+ const stopHintValue = stop.hint ?? stopHintOverride;
+
+ const handleStopPositionUpdate = (
+ styleValue: StyleValue,
+ options?: { isEphemeral?: boolean }
+ ) => {
+ const resolution = resolveStopPositionUpdate(styleValue);
+ if (resolution.type === "none") {
+ return;
+ }
+
+ updateStop(
+ stopIndex,
+ (stop) => ({
+ ...stop,
+ position: resolution.position,
+ }),
+ options
+ );
+
+ if (!options?.isEphemeral && resolution.clearHintOverrides) {
+ setHintOverrides((previous) =>
+ removeHintOverride(previous, stopIndex)
+ );
+ }
+ };
+
+ const handleStopPositionDelete = (options?: {
+ isEphemeral?: boolean;
+ }) => {
+ updateStop(
+ stopIndex,
+ (stop) => {
+ const { position: _omit, ...rest } = stop;
+ return rest;
+ },
+ options
+ );
+ };
+
+ const handleStopHintUpdate = (
+ styleValue: StyleValue,
+ options?: { isEphemeral?: boolean }
+ ) => {
+ const resolution = resolveStopHintUpdate(styleValue, {
+ getPercentUnit,
+ clampPercentUnit,
+ });
+
+ if (resolution.type === "none") {
+ return;
+ }
+
+ updateStop(
+ stopIndex,
+ (stop) => ({
+ ...stop,
+ hint: resolution.hint,
+ }),
+ options
+ );
+
+ if (options?.isEphemeral) {
+ return;
+ }
+
+ if (resolution.clearOverride) {
+ setHintOverrides((previous) =>
+ removeHintOverride(previous, stopIndex)
+ );
+ return;
+ }
+
+ const override = resolution.override;
+ if (override !== undefined) {
+ setHintOverrides((previous) =>
+ setHintOverride(previous, stopIndex, override)
+ );
+ }
+ };
+
+ const handleStopHintDelete = (options?: {
+ isEphemeral?: boolean;
+ }) => {
+ updateStop(
+ stopIndex,
+ (stop) => {
+ const { hint: _omit, ...rest } = stop;
+ return { ...rest };
+ },
+ options
+ );
+ if (!options?.isEphemeral) {
+ setHintOverrides((previous) =>
+ removeHintOverride(previous, stopIndex)
+ );
+ }
+ };
+
+ const handleStopColorChange = (
+ styleValue: StyleValue | IntermediateColorValue | undefined
+ ) => {
+ const nextColor = styleValueToColor(styleValue);
+ if (nextColor === undefined) {
+ return;
+ }
+ updateStop(
+ stopIndex,
+ (stop) => ({
+ ...stop,
+ color: nextColor,
+ }),
+ { isEphemeral: true }
+ );
+ };
+
+ const handleStopColorChangeComplete = (styleValue: StyleValue) => {
+ const nextColor = styleValueToColor(styleValue);
+ if (nextColor === undefined) {
+ return;
+ }
+ updateStop(
+ stopIndex,
+ (stop) => ({
+ ...stop,
+ color: nextColor,
+ }),
+ { isEphemeral: false }
+ );
+ };
+
+ const stopColor = (stop.color ?? fallbackStopColor) as StyleValue;
+
+ return (
+ <Flex
+ key={stopIndex}
+ gap="1"
+ css={{
+ opacity: isSelected ? 1 : 0.6,
+ }}
+ onFocus={() => {
+ if (!isSelected) {
+ setSelectedStopIndex(stopIndex);
+ }
+ }}
+ >
+ <Grid
+ align="end"
+ gap="1"
+ css={{ gridTemplateColumns: "1fr 1fr 2fr" }}
+ >
+ <Tooltip
+ content="Position of this gradient stop along the gradient line."
+ variant="wrapped"
+ >
+ <Box>
+ <CssValueInputContainer
+ property={"background-position-x"}
+ styleSource="default"
+ getOptions={getAvailableUnitVariables}
+ value={stopPositionValue}
+ unitOptions={percentUnitOptions}
+ onUpdate={handleStopPositionUpdate}
+ onDelete={handleStopPositionDelete}
+ />
+ </Box>
+ </Tooltip>
+ <Tooltip
+ content="Midpoint position for color transition between this stop and the next."
+ variant="wrapped"
+ >
+ <Box>
+ <CssValueInputContainer
+ property={"background-position-x"}
+ styleSource="default"
+ getOptions={getAvailableUnitVariables}
+ value={stopHintValue}
+ unitOptions={percentUnitOptions}
+ onUpdate={handleStopHintUpdate}
+ onDelete={handleStopHintDelete}
+ />
+ </Box>
+ </Tooltip>
+ <Tooltip
+ content="Color of this gradient stop."
+ variant="wrapped"
+ >
+ <Box>
+ <ColorPickerControl
+ property="color"
+ value={stopColor}
+ currentColor={stopColor}
+ onChange={handleStopColorChange}
+ onChangeComplete={handleStopColorChangeComplete}
+ onAbort={() => {}}
+ onReset={() => {}}
+ />
+ </Box>
+ </Tooltip>
+ </Grid>
+ <Tooltip content="Delete stop" variant="wrapped">
+ <IconButton
+ aria-label="Delete stop"
+ onClick={() => handleDeleteStop(stopIndex)}
+ disabled={gradient.stops.length <= 2}
+ >
+ <MinusIcon />
+ </IconButton>
+ </Tooltip>
+ </Flex>
+ );
+ })}
</Flex>
);
};
+
+type GradientPositionControlsProps = {
+ gradient: ParsedGradient;
+ applyGradient: GradientEditorApplyFn;
+};
+
+const GradientPositionControls = ({
+ gradient,
+ applyGradient,
+}: GradientPositionControlsProps) => {
+ const supportsPosition =
+ isRadialGradient(gradient) || isConicGradient(gradient);
+
+ const gradientWithPosition = supportsPosition
+ ? (gradient as ParsedRadialGradient | ParsedConicGradient)
+ : undefined;
+
+ const positionValue = gradientWithPosition?.position;
+
+ // Parse position values directly without memoization to ensure the grid
+ // indicator updates immediately after position changes
+ const parsedValues = positionValue
+ ? parseGradientPositionValues(positionValue)
+ : { xValue: undefined, yValue: undefined };
+
+ // Extract single values from layers type if needed
+ const xValue =
+ parsedValues.xValue?.type === "layers"
+ ? parsedValues.xValue.value[0]
+ : parsedValues.xValue;
+ const yValue =
+ parsedValues.yValue?.type === "layers"
+ ? parsedValues.yValue.value[0]
+ : parsedValues.yValue;
+
+ const updatePosition = useCallback(
+ (
+ nextX: StyleValue | undefined,
+ nextY: StyleValue | undefined,
+ options?: { isEphemeral?: boolean }
+ ) => {
+ if (gradientWithPosition === undefined) {
+ return;
+ }
+ const position = formatGradientPositionValues(nextX, nextY);
+ applyGradient(
+ {
+ ...gradientWithPosition,
+ position,
+ },
+ options
+ );
+ },
+ [applyGradient, gradientWithPosition]
+ );
+
+ const handleAxisUpdate = useCallback(
+ (axis: "x" | "y") =>
+ (styleValue: StyleValue, options?: { isEphemeral?: boolean }) => {
+ updatePosition(
+ axis === "x" ? styleValue : xValue,
+ axis === "y" ? styleValue : yValue,
+ options
+ );
+ },
+ [updatePosition, xValue, yValue]
+ );
+
+ const handleAxisDelete = useCallback(
+ (axis: "x" | "y") => (options?: { isEphemeral?: boolean }) => {
+ updatePosition(
+ axis === "x" ? undefined : xValue,
+ axis === "y" ? undefined : yValue,
+ options
+ );
+ },
+ [updatePosition, xValue, yValue]
+ );
+
+ const handleGridSelect = useCallback(
+ ({ x, y }: { x: number; y: number }) => {
+ updatePosition(createPercentUnitValue(x), createPercentUnitValue(y));
+ },
+ [updatePosition]
+ );
+
+ if (supportsPosition === false || gradientWithPosition === undefined) {
+ return;
+ }
+
+ return (
+ <BackgroundPositionControl
+ label="Position"
+ xAxis={{
+ label: "Left",
+ description: "Left position offset",
+ property: "--gradient-position-x",
+ value: xValue,
+ getOptions: () => gradientPositionXOptions,
+ unitOptions: percentUnitOptions,
+ onUpdate: handleAxisUpdate("x"),
+ onDelete: handleAxisDelete("x"),
+ }}
+ yAxis={{
+ label: "Top",
+ description: "Top position offset",
+ property: "--gradient-position-y",
+ value: yValue,
+ getOptions: () => gradientPositionYOptions,
+ unitOptions: percentUnitOptions,
+ onUpdate: handleAxisUpdate("y"),
+ onDelete: handleAxisDelete("y"),
+ }}
+ onSelect={handleGridSelect}
+ />
+ );
+};
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-image.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-image.tsx
index fbd7832dff..ad4f3aa7b0 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-image.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-image.tsx
@@ -1,30 +1,17 @@
-import type { InvalidValue, StyleValue } from "@webstudio-is/css-engine";
+import type { StyleValue } from "@webstudio-is/css-engine";
import {
- TextArea,
- textVariants,
Flex,
theme,
- InputErrorsTooltip,
- Label,
- Tooltip,
- Text,
+ FloatingPanelProvider,
+ Grid,
+ Box,
} from "@webstudio-is/design-system";
-import { useRef, useState } from "react";
-import type {} from "../../controls";
+import { useRef, useCallback } from "react";
+import { ImageControl } from "../../controls";
+import { PropertyInlineLabel } from "../../property-label";
+import { propertyDescriptions } from "@webstudio-is/css-data";
+import { BackgroundCodeEditor } from "./background-code-editor";
import { $assets } from "~/shared/nano-states";
-import type { StyleUpdateOptions } from "../../shared/use-style-data";
-import { InfoCircleIcon } from "@webstudio-is/icons";
-import { parseCssFragment } from "../../shared/css-fragment";
-import { useComputedStyleDecl } from "../../shared/model";
-import {
- getRepeatedStyleItem,
- setRepeatedStyleItem,
-} from "../../shared/repeated-style";
-
-type IntermediateValue = {
- type: "intermediate";
- value: string;
-};
const isAbsoluteURL = (value: string) => {
try {
@@ -34,185 +21,64 @@ const isAbsoluteURL = (value: string) => {
}
};
-const getInitialErrors = (styleValue: StyleValue | undefined): string[] => {
- const assets = $assets.get();
- if (styleValue === undefined) {
- return [];
- }
- if (styleValue.type === "image") {
- if (styleValue.value.type === "asset") {
- const asset = assets.get(styleValue.value.value);
- if (asset === undefined || asset.type !== "image") {
- return [`Asset ${styleValue.value.value} is not found in project`];
- }
- }
- }
- return [];
-};
-
-const getInitialValue = (
- styleValue: StyleValue | undefined
-): IntermediateValue | InvalidValue | undefined => {
- const assets = $assets.get();
-
- if (styleValue === undefined) {
- return;
- }
+export const BackgroundImage = ({ index }: { index: number }) => {
+ const elementRef = useRef<HTMLDivElement>(null);
- if (styleValue.type === "keyword") {
- return {
- type: "intermediate",
- value: styleValue.value,
- };
- }
+ const handleValidate = useCallback(
+ (_value: string, parsed: Map<string, StyleValue>) => {
+ const newValue = parsed.get("background-image");
- let backgroundUrl;
- if (styleValue.type === "image") {
- if (styleValue.value.type === "asset") {
- const asset = assets.get(styleValue.value.value);
- if (asset === undefined || asset.type !== "image") {
- return {
- type: "invalid",
- value: styleValue.value.value,
- };
+ if (newValue === undefined || newValue?.type === "invalid") {
+ return undefined;
}
- backgroundUrl = `url(${asset.name})`;
- }
- if (styleValue.value.type === "url") {
- backgroundUrl = `url(${styleValue.value.url})`;
- }
+ const [layer] = newValue.type === "layers" ? newValue.value : [newValue];
- return backgroundUrl !== undefined
- ? { type: "intermediate", value: backgroundUrl }
- : undefined;
- }
-};
-
-export const BackgroundImage = ({ index }: { index: number }) => {
- const textAreaRef = useRef<HTMLTextAreaElement>(null);
-
- const styleDecl = useComputedStyleDecl("background-image");
- const styleValue = getRepeatedStyleItem(styleDecl, index);
- const [errors, setErrors] = useState<string[]>(() =>
- getInitialErrors(styleValue)
- );
- const [intermediateValue, setIntermediateValue] = useState<
- IntermediateValue | InvalidValue | undefined
- >(() => getInitialValue(styleValue));
-
- const handleChange = (value: string, options: StyleUpdateOptions) => {
- setIntermediateValue({
- type: "intermediate",
- value: value,
- });
-
- const parsed = parseCssFragment(value, ["background-image", "background"]);
- const newValue = parsed.get("background-image");
+ // Only validate image URLs, not keywords or other types
+ if (layer?.type !== "image" || layer.value.type !== "url") {
+ return undefined;
+ }
- if (newValue === undefined || newValue?.type === "invalid") {
- setIntermediateValue({
- type: "invalid",
- value: value,
- });
- return;
- }
+ const url = layer.value.url;
- const [layer] = newValue.type === "layers" ? newValue.value : [newValue];
- if (layer?.type === "keyword") {
- setIntermediateValue(undefined);
- setRepeatedStyleItem(styleDecl, index, layer, options);
- }
- if (layer?.type !== "image" || layer.value.type !== "url") {
- setIntermediateValue({
- type: "invalid",
- value: value,
- });
- return;
- }
- const url = layer.value.url;
+ // If it's an absolute URL, no validation needed
+ if (isAbsoluteURL(url)) {
+ return undefined;
+ }
- if (isAbsoluteURL(url) === true) {
- setRepeatedStyleItem(styleDecl, index, layer, options);
- } else {
+ // Check if the asset exists in the project
const usedAsset = Array.from($assets.get().values()).find(
(asset) => asset.type === "image" && asset.name === url
);
if (usedAsset === undefined) {
- setErrors([`Asset ${url} is not found in project `]);
- setIntermediateValue({
- type: "invalid",
- value: value,
- });
- return;
+ return [`Asset ${url} is not found in project`];
}
- setErrors([]);
- setRepeatedStyleItem(
- styleDecl,
- index,
- {
- type: "image",
- value: { type: "asset", value: usedAsset.id },
- },
- options
- );
- }
- };
+ return undefined;
+ },
+ []
+ );
return (
<Flex
direction="column"
- css={{
- gridColumn: "span 2",
- padding: theme.panel.padding,
- gap: theme.spacing[3],
- }}
+ gap={1}
+ css={{ padding: theme.panel.padding }}
+ ref={elementRef}
>
- <Label>
- <Flex align="center" gap="1">
- Code
- <Tooltip
- variant="wrapped"
- content={
- <Text>
- Paste a background-image CSS property value here. You can use
- the URL of an asset in your project or an external URL.
- <br /> <br />
- <Text variant="monoBold">url("image.jpg")</Text>
- </Text>
- }
- >
- <InfoCircleIcon />
- </Tooltip>
- </Flex>
- </Label>
-
- <InputErrorsTooltip errors={errors}>
- <TextArea
- ref={textAreaRef}
- css={{ ...textVariants.mono }}
- rows={2}
- autoGrow
- maxRows={4}
- name="description"
- color={intermediateValue?.type === "invalid" ? "error" : undefined}
- value={intermediateValue !== undefined ? intermediateValue.value : ""}
- onChange={(value) => handleChange(value, { isEphemeral: true })}
- onBlur={() => {
- if (intermediateValue !== undefined) {
- handleChange(intermediateValue.value, { isEphemeral: false });
- }
- }}
- onKeyDown={(event) => {
- if (event.key === "Enter" && intermediateValue !== undefined) {
- handleChange(intermediateValue.value, { isEphemeral: false });
- event.preventDefault();
- }
- }}
+ <Grid gap="2" columns="3" align="start">
+ <PropertyInlineLabel
+ label="Image"
+ description={propertyDescriptions.backgroundImage}
/>
- </InputErrorsTooltip>
+ <Box css={{ gridColumn: "span 2" }}>
+ <FloatingPanelProvider container={elementRef}>
+ <ImageControl property="background-image" index={index} />
+ </FloatingPanelProvider>
+ </Box>
+ </Grid>
+ <BackgroundCodeEditor index={index} onValidate={handleValidate} />
</Flex>
);
};
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-position.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-position.tsx
index f41ed1da9c..5e32206081 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-position.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-position.tsx
@@ -1,13 +1,20 @@
-import type { StyleValue } from "@webstudio-is/css-engine";
+import type {
+ CssProperty,
+ KeywordValue,
+ StyleValue,
+ VarValue,
+} from "@webstudio-is/css-engine";
import { propertyDescriptions } from "@webstudio-is/css-data";
import { Flex, Grid, PositionGrid } from "@webstudio-is/design-system";
import { CssValueInputContainer } from "../../shared/css-value-input";
-import { PropertyInlineLabel } from "../../property-label";
+import { PropertyInlineLabel, PropertyLabel } from "../../property-label";
import { useComputedStyles } from "../../shared/model";
import {
getRepeatedStyleItem,
setRepeatedStyleItem,
} from "../../shared/repeated-style";
+import type { UnitOption } from "../../shared/css-value-input/unit-select";
+import type { SetValue, StyleUpdateOptions } from "../../shared/use-style-data";
const keyworkToValue: Record<string, number> = {
left: 0,
@@ -17,7 +24,7 @@ const keyworkToValue: Record<string, number> = {
bottom: 100,
};
-const calculateBackgroundPosition = (value: undefined | StyleValue) => {
+export const calculateBackgroundPosition = (value: undefined | StyleValue) => {
if (value?.type === "unit") {
return value.value;
}
@@ -27,92 +34,188 @@ const calculateBackgroundPosition = (value: undefined | StyleValue) => {
return 0;
};
-export const BackgroundPosition = ({ index }: { index: number }) => {
- const [backgroundPositionX, backgroundPositionY] = useComputedStyles([
- "background-position-x",
- "background-position-y",
- ]);
- const xValue = getRepeatedStyleItem(backgroundPositionX, index);
- const yValue = getRepeatedStyleItem(backgroundPositionY, index);
- const x = calculateBackgroundPosition(xValue);
- const y = calculateBackgroundPosition(yValue);
+type AxisOption =
+ | KeywordValue
+ | VarValue
+ | (KeywordValue & { description?: string });
+
+type AxisControlProps = {
+ label: string;
+ description: string;
+ property: CssProperty;
+ properties?: [CssProperty, ...CssProperty[]];
+ value: StyleValue | undefined;
+ getOptions: () => Array<AxisOption>;
+ unitOptions?: UnitOption[];
+ onUpdate: SetValue;
+ onDelete: (options?: StyleUpdateOptions) => void;
+};
+
+export const BackgroundPositionControl = ({
+ label = "Position",
+ description = propertyDescriptions.backgroundPosition,
+ xAxis,
+ yAxis,
+ onSelect,
+}: {
+ label?: string;
+ description?: string;
+ xAxis: AxisControlProps;
+ yAxis: AxisControlProps;
+ onSelect: (position: { x: number; y: number }) => void;
+}) => {
+ const combinedProperties = (() => {
+ if (xAxis.properties && yAxis.properties) {
+ return [...xAxis.properties, ...yAxis.properties] as [
+ CssProperty,
+ ...CssProperty[],
+ ];
+ }
+ if (xAxis.properties) {
+ return xAxis.properties;
+ }
+ if (yAxis.properties) {
+ return yAxis.properties;
+ }
+ })();
return (
<Flex direction="column" gap="1">
- <PropertyInlineLabel
- label="Position"
- description={propertyDescriptions.backgroundPosition}
- properties={["background-position-x", "background-position-y"]}
- />
- <Flex gap="6">
+ {combinedProperties ? (
+ <PropertyLabel
+ label={label}
+ description={description}
+ properties={combinedProperties}
+ />
+ ) : (
+ <PropertyInlineLabel label={label} description={description} />
+ )}
+ <Grid gap="2" columns={2}>
<PositionGrid
- selectedPosition={{ x, y }}
- onSelect={({ x, y }) => {
- setRepeatedStyleItem(backgroundPositionX, index, {
- type: "unit",
- value: x,
- unit: "%",
- });
- setRepeatedStyleItem(backgroundPositionY, index, {
- type: "unit",
- value: y,
- unit: "%",
- });
+ selectedPosition={{
+ x: calculateBackgroundPosition(xAxis.value),
+ y: calculateBackgroundPosition(yAxis.value),
}}
+ onSelect={onSelect}
/>
<Grid
css={{ gridTemplateColumns: "max-content 1fr" }}
align="center"
gapX="2"
>
- <PropertyInlineLabel
- label="Left"
- description="Left position offset"
- properties={["background-position-x"]}
- />
+ {xAxis.properties ? (
+ <PropertyLabel
+ label={xAxis.label}
+ description={xAxis.description}
+ properties={xAxis.properties}
+ />
+ ) : (
+ <PropertyInlineLabel
+ label={xAxis.label}
+ description={xAxis.description}
+ />
+ )}
<CssValueInputContainer
- property="background-position-x"
+ property={xAxis.property}
styleSource="default"
- getOptions={() => [
- { type: "keyword", value: "center" },
- { type: "keyword", value: "left" },
- { type: "keyword", value: "right" },
- ]}
- value={xValue}
- onUpdate={(value, options) => {
- setRepeatedStyleItem(backgroundPositionX, index, value, options);
- }}
- onDelete={() => {
- if (xValue) {
- setRepeatedStyleItem(backgroundPositionX, index, xValue);
- }
- }}
- />
- <PropertyInlineLabel
- label="Top"
- description="Top position offset"
- properties={["background-position-y"]}
+ getOptions={xAxis.getOptions}
+ unitOptions={xAxis.unitOptions}
+ value={xAxis.value}
+ onUpdate={xAxis.onUpdate}
+ onDelete={xAxis.onDelete}
/>
+ {yAxis.properties ? (
+ <PropertyLabel
+ label={yAxis.label}
+ description={yAxis.description}
+ properties={yAxis.properties}
+ />
+ ) : (
+ <PropertyInlineLabel
+ label={yAxis.label}
+ description={yAxis.description}
+ />
+ )}
<CssValueInputContainer
- property="background-position-y"
+ property={yAxis.property}
styleSource="default"
- getOptions={() => [
- { type: "keyword", value: "center" },
- { type: "keyword", value: "top" },
- { type: "keyword", value: "bottom" },
- ]}
- value={yValue}
- onUpdate={(value, options) => {
- setRepeatedStyleItem(backgroundPositionY, index, value, options);
- }}
- onDelete={() => {
- if (yValue) {
- setRepeatedStyleItem(backgroundPositionY, index, yValue);
- }
- }}
+ getOptions={yAxis.getOptions}
+ unitOptions={yAxis.unitOptions}
+ value={yAxis.value}
+ onUpdate={yAxis.onUpdate}
+ onDelete={yAxis.onDelete}
/>
</Grid>
- </Flex>
+ </Grid>
</Flex>
);
};
+
+export const BackgroundPosition = ({ index }: { index: number }) => {
+ const [backgroundPositionX, backgroundPositionY] = useComputedStyles([
+ "background-position-x",
+ "background-position-y",
+ ]);
+ const xValue = getRepeatedStyleItem(backgroundPositionX, index);
+ const yValue = getRepeatedStyleItem(backgroundPositionY, index);
+ const setValueX: SetValue = (value, options) => {
+ setRepeatedStyleItem(backgroundPositionX, index, value, options);
+ };
+ const setValueY: SetValue = (value, options) => {
+ setRepeatedStyleItem(backgroundPositionY, index, value, options);
+ };
+ const resetValue = (
+ axisValue: StyleValue | undefined,
+ setValue: SetValue,
+ options?: StyleUpdateOptions
+ ) => {
+ if (axisValue) {
+ setValue(axisValue, options);
+ }
+ };
+
+ return (
+ <BackgroundPositionControl
+ xAxis={{
+ label: "Left",
+ description: "Left position offset",
+ property: "background-position-x",
+ properties: ["background-position-x"],
+ value: xValue,
+ getOptions: () => [
+ { type: "keyword", value: "center" },
+ { type: "keyword", value: "left" },
+ { type: "keyword", value: "right" },
+ ],
+ onUpdate: setValueX,
+ onDelete: (options) => resetValue(xValue, setValueX, options),
+ }}
+ yAxis={{
+ label: "Top",
+ description: "Top position offset",
+ property: "background-position-y",
+ properties: ["background-position-y"],
+ value: yValue,
+ getOptions: () => [
+ { type: "keyword", value: "center" },
+ { type: "keyword", value: "top" },
+ { type: "keyword", value: "bottom" },
+ ],
+ onUpdate: setValueY,
+ onDelete: (options) => resetValue(yValue, setValueY, options),
+ }}
+ onSelect={({ x, y }) => {
+ setRepeatedStyleItem(backgroundPositionX, index, {
+ type: "unit",
+ value: x,
+ unit: "%",
+ });
+ setRepeatedStyleItem(backgroundPositionY, index, {
+ type: "unit",
+ value: y,
+ unit: "%",
+ });
+ }}
+ />
+ );
+};
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-size.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-size.tsx
index bb2bf9f7e0..469e152a84 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-size.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-size.tsx
@@ -8,7 +8,7 @@ import {
} from "@webstudio-is/css-engine";
import { CssValueInputContainer } from "../../shared/css-value-input";
import type { SetValue } from "../../shared/use-style-data";
-import { PropertyInlineLabel } from "../../property-label";
+import { PropertyLabel } from "../../property-label";
import { useComputedStyleDecl } from "../../shared/model";
import {
getRepeatedStyleItem,
@@ -42,9 +42,8 @@ export const BackgroundSize = ({ index }: { index: number }) => {
const selectOptions = [...keywordValues[property], "custom"];
const selectValue =
- styleValue?.type === "keyword" ? toValue(styleValue) : "custom";
+ styleValue?.type === "keyword" ? toValue(styleValue) : "auto";
- const customSizeDisabled = styleValue?.type === "keyword";
const customSizeOptions = [autoKeyword];
const customSizeValue = toTuple(styleValue);
@@ -66,12 +65,8 @@ export const BackgroundSize = ({ index }: { index: number }) => {
return (
<>
- <Grid
- css={{ gridTemplateColumns: `1fr ${theme.spacing[23]}` }}
- align="center"
- gap={2}
- >
- <PropertyInlineLabel
+ <Grid columns={2} align="center" gap={2}>
+ <PropertyLabel
label="Size"
description={propertyDescriptions.backgroundSize}
properties={[property]}
@@ -115,47 +110,45 @@ export const BackgroundSize = ({ index }: { index: number }) => {
/>
</Grid>
- <Grid
- css={{ mt: theme.spacing[4] }}
- align="center"
- columns={2}
- gapX={2}
- gapY={1}
- >
- <PropertyInlineLabel
- properties={["background-size"]}
- label="Width"
- description="The width of the background image."
- disabled={customSizeDisabled}
- />
-
- <PropertyInlineLabel
- properties={["background-size"]}
- label="Height"
- description="The height of the background image."
- disabled={customSizeDisabled}
- />
-
- <CssValueInputContainer
- disabled={customSizeDisabled}
- property={property}
- styleSource="default"
- getOptions={() => customSizeOptions}
- value={customSizeValue.value[0]}
- onUpdate={setValueX}
- onDelete={() => {}}
- />
-
- <CssValueInputContainer
- disabled={customSizeDisabled}
- property={property}
- styleSource="default"
- getOptions={() => customSizeOptions}
- value={customSizeValue.value[1]}
- onUpdate={setValueY}
- onDelete={() => {}}
- />
- </Grid>
+ {selectValue === "custom" && (
+ <Grid
+ css={{ mt: theme.spacing[4] }}
+ align="center"
+ columns={2}
+ gapX={2}
+ gapY={1}
+ >
+ <PropertyLabel
+ properties={["background-size"]}
+ label="Width"
+ description="The width of the background image."
+ />
+
+ <PropertyLabel
+ properties={["background-size"]}
+ label="Height"
+ description="The height of the background image."
+ />
+
+ <CssValueInputContainer
+ property={property}
+ styleSource="default"
+ getOptions={() => customSizeOptions}
+ value={customSizeValue.value[0]}
+ onUpdate={setValueX}
+ onDelete={() => {}}
+ />
+
+ <CssValueInputContainer
+ property={property}
+ styleSource="default"
+ getOptions={() => customSizeOptions}
+ value={customSizeValue.value[1]}
+ onUpdate={setValueY}
+ onDelete={() => {}}
+ />
+ </Grid>
+ )}
</>
);
};
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-thumbnail.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-thumbnail.tsx
index f1c4031683..0070ee099e 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-thumbnail.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-thumbnail.tsx
@@ -11,8 +11,12 @@ import { $assets } from "~/shared/nano-states";
import brokenImage from "~/shared/images/broken-image-placeholder.svg";
import { humanizeString } from "~/shared/string-utils";
import { useComputedStyles } from "../../shared/model";
-import { getComputedRepeatedItem } from "../../shared/repeated-style";
+import {
+ getComputedRepeatedItem,
+ getRepeatedStyleItem,
+} from "../../shared/repeated-style";
import { formatAssetName } from "~/builder/shared/assets/asset-utils";
+import { parseAnyGradient, isSolidLinearGradient } from "./gradient-utils";
export const repeatedProperties = [
"background-image",
@@ -102,10 +106,15 @@ export const getBackgroundLabel = (
}
if (backgroundImageStyle?.type === "unparsed") {
- const gradientName = gradientNames.find((name) =>
- backgroundImageStyle.value.includes(name)
- );
+ const value = backgroundImageStyle.value;
+
+ // Check if it's a solid color gradient using cached parsing
+ const parsed = parseAnyGradient(value);
+ if (parsed?.type === "linear" && isSolidLinearGradient(parsed)) {
+ return "Solid";
+ }
+ const gradientName = gradientNames.find((name) => value.includes(name));
return gradientName ? humanizeString(gradientName) : "Gradient";
}
@@ -118,7 +127,13 @@ export const BackgroundThumbnail = ({ index }: { index: number }) => {
const assets = useStore($assets);
const styles = useComputedStyles(repeatedProperties);
const [backgroundImage] = styles;
- const backgroundImageValue = getComputedRepeatedItem(backgroundImage, index);
+ // Use cascaded value to check for assets (before they're resolved to URLs)
+ const backgroundImageValue = getRepeatedStyleItem(backgroundImage, index);
+ // Use computed value for rendering gradients and other styles
+ const computedBackgroundImageValue = getComputedRepeatedItem(
+ backgroundImage,
+ index
+ );
if (
backgroundImageValue?.type === "image" &&
@@ -126,7 +141,7 @@ export const BackgroundThumbnail = ({ index }: { index: number }) => {
) {
const asset = assets.get(backgroundImageValue.value.value);
if (asset === undefined) {
- return null;
+ return;
}
return (
<StyledWebstudioImage
@@ -154,7 +169,7 @@ export const BackgroundThumbnail = ({ index }: { index: number }) => {
);
}
- if (backgroundImageValue?.type === "unparsed") {
+ if (computedBackgroundImageValue?.type === "unparsed") {
const cssStyle: { [property in RepeatedProperty]?: string } = {};
for (const styleDecl of styles) {
const itemValue = getComputedRepeatedItem(styleDecl, index);
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/backgrounds.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/backgrounds.tsx
index 1a3375a68b..21a3519228 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/backgrounds.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/backgrounds.tsx
@@ -34,13 +34,16 @@ export const Section = () => {
description="Add one or more backgrounds to the instance such as a color, image, or gradient."
properties={properties}
onAdd={() => {
- addRepeatedStyleItem(styles, parseCssFragment("none", ["background"]));
+ addRepeatedStyleItem(
+ styles,
+ parseCssFragment("none", ["background-image"])
+ );
}}
collapsible
>
<Flex gap={1} direction="column">
<RepeatedStyle
- label="Backgrounds"
+ label="Background layer"
styles={styles}
floatingPanelOffset={{ alignmentAxis: -100 }}
getItemProps={(_index, primaryValue) => ({
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/gradient-utils.test.ts b/apps/builder/app/builder/features/style-panel/sections/backgrounds/gradient-utils.test.ts
new file mode 100644
index 0000000000..48852396e0
--- /dev/null
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/gradient-utils.test.ts
@@ -0,0 +1,1608 @@
+import { describe, expect, test } from "vitest";
+import {
+ toValue,
+ type KeywordValue,
+ type RgbValue,
+ type StyleValue,
+ type UnitValue,
+ type VarValue,
+} from "@webstudio-is/css-engine";
+import type {
+ GradientStop,
+ ParsedLinearGradient,
+ ParsedConicGradient,
+ ParsedRadialGradient,
+} from "@webstudio-is/css-data";
+import {
+ clampStopIndex,
+ createSolidLinearGradient,
+ detectBackgroundType,
+ ensureGradientHasStops,
+ fillMissingStopPositions,
+ isSolidLinearGradient,
+ normalizeGradientInput,
+ type PercentUnitValue,
+ pruneHintOverrides,
+ removeHintOverride,
+ resolveAngleValue,
+ resolveGradientForPicker,
+ resolveReverseStops,
+ resolveStopHintUpdate,
+ resolveStopPositionUpdate,
+ setHintOverride,
+ sideOrCornerToAngle,
+ styleValueToColor,
+ formatGradientForType,
+ formatGradientValue,
+ convertGradientToTarget,
+ type GradientType,
+} from "./gradient-utils";
+
+const createLinearGradient = (
+ overrides: Partial<ParsedLinearGradient> = {}
+): ParsedLinearGradient => ({
+ type: "linear",
+ stops: [],
+ ...overrides,
+});
+
+const createConicGradient = (
+ overrides: Partial<ParsedConicGradient> = {}
+): ParsedConicGradient => ({
+ type: "conic",
+ stops: [],
+ ...overrides,
+});
+
+const createRadialGradient = (
+ overrides: Partial<ParsedRadialGradient> = {}
+): ParsedRadialGradient => ({
+ type: "radial",
+ stops: [],
+ ...overrides,
+});
+
+describe("formatGradientValue", () => {
+ test("formats linear gradient", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ { color: { type: "rgb", r: 0, g: 0, b: 0, alpha: 1 } },
+ { color: { type: "rgb", r: 255, g: 255, b: 255, alpha: 1 } },
+ ],
+ });
+ expect(formatGradientValue(gradient)).toBe(
+ "linear-gradient(rgba(0, 0, 0, 1), rgba(255, 255, 255, 1))"
+ );
+ });
+
+ test("formats repeating linear gradient", () => {
+ const gradient = createLinearGradient({
+ repeating: true,
+ stops: [
+ { color: { type: "rgb", r: 0, g: 0, b: 0, alpha: 1 } },
+ { color: { type: "rgb", r: 255, g: 255, b: 255, alpha: 1 } },
+ ],
+ });
+ expect(formatGradientValue(gradient)).toBe(
+ "repeating-linear-gradient(rgba(0, 0, 0, 1), rgba(255, 255, 255, 1))"
+ );
+ });
+
+ test("formats conic gradient", () => {
+ const gradient = createConicGradient({
+ stops: [
+ { color: { type: "rgb", r: 0, g: 0, b: 0, alpha: 1 } },
+ { color: { type: "rgb", r: 255, g: 255, b: 255, alpha: 1 } },
+ ],
+ });
+ expect(formatGradientValue(gradient)).toBe(
+ "conic-gradient(rgba(0, 0, 0, 1), rgba(255, 255, 255, 1))"
+ );
+ });
+
+ test("formats repeating conic gradient", () => {
+ const gradient = createConicGradient({
+ repeating: true,
+ stops: [
+ { color: { type: "rgb", r: 0, g: 0, b: 0, alpha: 1 } },
+ { color: { type: "rgb", r: 255, g: 255, b: 255, alpha: 1 } },
+ ],
+ });
+ expect(formatGradientValue(gradient)).toBe(
+ "repeating-conic-gradient(rgba(0, 0, 0, 1), rgba(255, 255, 255, 1))"
+ );
+ });
+
+ test("formats radial gradient", () => {
+ const gradient = createRadialGradient({
+ shape: { type: "keyword", value: "circle" },
+ size: "closest-side",
+ position: "center",
+ stops: [
+ { color: { type: "rgb", r: 0, g: 0, b: 0, alpha: 1 } },
+ { color: { type: "rgb", r: 255, g: 255, b: 255, alpha: 1 } },
+ ],
+ });
+ expect(formatGradientValue(gradient)).toBe(
+ "radial-gradient(circle closest-side at center, rgba(0, 0, 0, 1), rgba(255, 255, 255, 1))"
+ );
+ });
+
+ test("formats repeating radial gradient", () => {
+ const gradient = createRadialGradient({
+ repeating: true,
+ shape: { type: "keyword", value: "circle" },
+ position: "center",
+ stops: [
+ { color: { type: "rgb", r: 0, g: 0, b: 0, alpha: 1 } },
+ { color: { type: "rgb", r: 255, g: 255, b: 255, alpha: 1 } },
+ ],
+ });
+ expect(formatGradientValue(gradient)).toBe(
+ "repeating-radial-gradient(circle at center, rgba(0, 0, 0, 1), rgba(255, 255, 255, 1))"
+ );
+ });
+});
+
+describe("formatGradientForType", () => {
+ const solidStyle: StyleValue = {
+ type: "unparsed",
+ value: "linear-gradient(red, red)",
+ };
+
+ test("formats solid color target", () => {
+ expect(formatGradientForType(solidStyle, "solid")).toBe(
+ "linear-gradient(rgba(255, 0, 0, 1) 0%, rgba(255, 0, 0, 1) 100%)"
+ );
+ });
+
+ test("formats linear target", () => {
+ expect(formatGradientForType(solidStyle, "linearGradient")).toBe(
+ "linear-gradient(rgba(255, 0, 0, 1), rgba(255, 0, 0, 1))"
+ );
+ });
+
+ test("formats conic target", () => {
+ expect(formatGradientForType(undefined, "conicGradient")).toBe(
+ "conic-gradient(rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0) 100%)"
+ );
+ });
+
+ test("formats radial target", () => {
+ const radialStyle: StyleValue = {
+ type: "unparsed",
+ value: "radial-gradient(circle at center, red, blue)",
+ };
+ expect(formatGradientForType(radialStyle, "radialGradient")).toBe(
+ "radial-gradient(circle at center, rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
+ );
+ });
+
+ test("preserves repeating linear gradients", () => {
+ const value: StyleValue = {
+ type: "unparsed",
+ value: "repeating-linear-gradient(red, blue)",
+ };
+ expect(formatGradientForType(value, "linearGradient")).toBe(
+ "repeating-linear-gradient(rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
+ );
+ });
+
+ test("preserves repeating conic gradients", () => {
+ const value: StyleValue = {
+ type: "unparsed",
+ value: "repeating-conic-gradient(red, blue)",
+ };
+ expect(formatGradientForType(value, "conicGradient")).toBe(
+ "repeating-conic-gradient(rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
+ );
+ });
+
+ test("preserves repeating radial gradients", () => {
+ const value: StyleValue = {
+ type: "unparsed",
+ value: "repeating-radial-gradient(circle, red, blue)",
+ };
+ expect(formatGradientForType(value, "radialGradient")).toBe(
+ "repeating-radial-gradient(circle, rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
+ );
+ });
+
+ test("converts conic gradient to radial target", () => {
+ const conicStyle: StyleValue = {
+ type: "unparsed",
+ value: "conic-gradient(red, blue)",
+ };
+ expect(formatGradientForType(conicStyle, "radialGradient")).toBe(
+ "radial-gradient(rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
+ );
+ });
+});
+
+describe("convertGradientToTarget", () => {
+ const gradientStrings: Record<GradientType, string> = {
+ linear: "linear-gradient(red 0%, blue 100%)",
+ conic: "conic-gradient(red 0%, blue 100%)",
+ radial: "radial-gradient(circle, red 0%, blue 100%)",
+ };
+ const expectedColors = ["rgba(255, 0, 0, 1)", "rgba(0, 0, 255, 1)"];
+ const gradientTypes: GradientType[] = ["linear", "conic", "radial"];
+
+ const getStopColors = (stops: GradientStop[]) =>
+ stops
+ .map((stop) => stop.color)
+ .filter(
+ (color): color is NonNullable<typeof color> => color !== undefined
+ )
+ .map((color) => toValue(color));
+
+ gradientTypes.forEach((sourceType) => {
+ gradientTypes.forEach((targetType) => {
+ test(`converts ${sourceType} gradient to ${targetType}`, () => {
+ const styleValue: StyleValue = {
+ type: "unparsed",
+ value: gradientStrings[sourceType],
+ };
+ const converted = convertGradientToTarget(styleValue, targetType);
+ expect(converted.type).toBe(targetType);
+ expect(converted.stops).toHaveLength(expectedColors.length);
+ expect(getStopColors(converted.stops)).toEqual(expectedColors);
+ });
+ });
+ });
+
+ test.each(gradientTypes)(
+ "creates default gradient when value missing for %s target",
+ (target) => {
+ const converted = convertGradientToTarget(undefined, target);
+ expect(converted.type).toBe(target);
+ expect(converted.stops.length).toBeGreaterThan(0);
+ }
+ );
+
+ test.each(gradientTypes)(
+ "preserves repeating flag when converting to %s",
+ (target) => {
+ const styleValue: StyleValue = {
+ type: "unparsed",
+ value: "repeating-linear-gradient(red 0%, blue 100%)",
+ };
+ const converted = convertGradientToTarget(styleValue, target);
+ expect(converted.repeating).toBe(true);
+ }
+ );
+
+ test.each(gradientTypes)(
+ "omits repeating flag when source is not repeating for %s target",
+ (target) => {
+ const styleValue: StyleValue = {
+ type: "unparsed",
+ value: "linear-gradient(red 0%, blue 100%)",
+ };
+ const converted = convertGradientToTarget(styleValue, target);
+ expect(converted.repeating).toBeUndefined();
+ }
+ );
+});
+describe("normalizeGradientInput", () => {
+ test("returns string unchanged when not repeating", () => {
+ const input = "linear-gradient(red, blue)";
+ expect(normalizeGradientInput(input, "linear")).toEqual({
+ normalizedGradientString: input,
+ initialIsRepeating: false,
+ });
+ });
+
+ test("normalizes repeating gradients", () => {
+ const input = " repeating-linear-gradient(red, blue)";
+ expect(normalizeGradientInput(input, "linear")).toEqual({
+ normalizedGradientString: " linear-gradient(red, blue)",
+ initialIsRepeating: true,
+ });
+ });
+
+ test("handles uppercase repeating gradients while preserving leading whitespace", () => {
+ const input = "\tRePeAtInG-Linear-GrAdIeNt(red, blue)";
+ expect(normalizeGradientInput(input, "linear")).toEqual({
+ normalizedGradientString: "\tlinear-gradient(red, blue)",
+ initialIsRepeating: true,
+ });
+ });
+
+ test("normalizes repeating conic gradients", () => {
+ const input = "repeating-conic-gradient(red, blue)";
+ expect(normalizeGradientInput(input, "conic")).toEqual({
+ normalizedGradientString: "conic-gradient(red, blue)",
+ initialIsRepeating: true,
+ });
+ });
+
+ test("normalizes repeating radial gradients", () => {
+ const input = " repeating-radial-gradient(red, blue)";
+ expect(normalizeGradientInput(input, "radial")).toEqual({
+ normalizedGradientString: " radial-gradient(red, blue)",
+ initialIsRepeating: true,
+ });
+ });
+});
+
+describe("sideOrCornerToAngle", () => {
+ test("returns angle for single direction", () => {
+ const keyword: KeywordValue = { type: "keyword", value: "to top" };
+ expect(sideOrCornerToAngle(keyword)).toBe(0);
+ });
+
+ test("returns angle for right side", () => {
+ const keyword: KeywordValue = { type: "keyword", value: "to right" };
+ expect(sideOrCornerToAngle(keyword)).toBe(90);
+ });
+
+ test("returns angle for bottom side", () => {
+ const keyword: KeywordValue = { type: "keyword", value: "to bottom" };
+ expect(sideOrCornerToAngle(keyword)).toBe(180);
+ });
+
+ test("returns angle for left side", () => {
+ const keyword: KeywordValue = { type: "keyword", value: "to left" };
+ expect(sideOrCornerToAngle(keyword)).toBe(270);
+ });
+
+ test("returns angle for corner", () => {
+ const keyword: KeywordValue = { type: "keyword", value: "to bottom right" };
+ expect(sideOrCornerToAngle(keyword)).toBe(135);
+ });
+
+ test("returns angle for top right corner", () => {
+ const keyword: KeywordValue = { type: "keyword", value: "to top right" };
+ expect(sideOrCornerToAngle(keyword)).toBe(45);
+ });
+
+ test("returns angle for top left corner", () => {
+ const keyword: KeywordValue = { type: "keyword", value: "to top left" };
+ expect(sideOrCornerToAngle(keyword)).toBe(315);
+ });
+
+ test("returns angle for bottom left corner", () => {
+ const keyword: KeywordValue = { type: "keyword", value: "to bottom left" };
+ expect(sideOrCornerToAngle(keyword)).toBe(225);
+ });
+
+ test("returns undefined for invalid input", () => {
+ const keyword: KeywordValue = { type: "keyword", value: "center" };
+ expect(sideOrCornerToAngle(keyword)).toBeUndefined();
+ });
+
+ test("returns undefined when side or corner missing", () => {
+ expect(sideOrCornerToAngle(undefined)).toBeUndefined();
+ });
+
+ test("returns undefined when no direction tokens provided", () => {
+ const keyword: KeywordValue = { type: "keyword", value: "to " };
+ expect(sideOrCornerToAngle(keyword)).toBeUndefined();
+ });
+
+ test("returns undefined for unrecognized corner combination", () => {
+ const keyword: KeywordValue = { type: "keyword", value: "to top bottom" };
+ expect(sideOrCornerToAngle(keyword)).toBeUndefined();
+ });
+});
+
+describe("resolveAngleValue", () => {
+ test("returns unit angles", () => {
+ const styleValue: StyleValue = { type: "unit", unit: "deg", value: 120 };
+ const result = resolveAngleValue(styleValue);
+ expect(result).toEqual({ type: "unit", unit: "deg", value: 120 });
+ expect(result).not.toBe(styleValue);
+ });
+
+ test("returns cloned var angles", () => {
+ const fallback: VarValue["fallback"] = {
+ type: "unit",
+ unit: "deg",
+ value: 45,
+ };
+ const styleValue: StyleValue = {
+ type: "var",
+ value: "angle",
+ fallback,
+ };
+ const result = resolveAngleValue(styleValue);
+ expect(result?.type).toBe("var");
+ if (result?.type !== "var") {
+ throw new Error("Expected var angle");
+ }
+ expect(result).not.toBe(styleValue);
+ expect(result.value).toBe("angle");
+ expect(result.fallback).toEqual(fallback);
+ expect(result.fallback).not.toBe(styleValue.fallback);
+ });
+
+ test("returns undefined for non-angle values", () => {
+ const styleValue: StyleValue = { type: "keyword", value: "auto" };
+ expect(resolveAngleValue(styleValue)).toBeUndefined();
+ });
+});
+
+describe("fillMissingStopPositions", () => {
+ test("returns original gradient when no stops present", () => {
+ const gradient = createLinearGradient();
+ expect(fillMissingStopPositions(gradient)).toBe(gradient);
+ });
+
+ test("returns original gradient when positions use non-percent units", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ { color: undefined, position: { type: "unit", unit: "px", value: 10 } },
+ { color: undefined },
+ ],
+ });
+
+ expect(fillMissingStopPositions(gradient)).toBe(gradient);
+ });
+
+ test("assigns zero to a single stop without position", () => {
+ const gradient = createLinearGradient({
+ stops: [{ color: undefined }],
+ });
+
+ const result = fillMissingStopPositions(gradient);
+ expect(result).not.toBe(gradient);
+ expect(result.stops[0]?.position).toEqual({
+ type: "unit",
+ unit: "%",
+ value: 0,
+ });
+ });
+
+ test("distributes positions evenly when all positions missing", () => {
+ const gradient = createLinearGradient({
+ stops: [{ color: undefined }, { color: undefined }, { color: undefined }],
+ });
+
+ const result = fillMissingStopPositions(gradient);
+ expect(result.stops.map((stop) => stop.position?.value)).toEqual([
+ 0, 50, 100,
+ ]);
+ });
+
+ test("fills missing positions proportionally", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ { color: undefined, position: { type: "unit", unit: "%", value: 0 } },
+ { color: undefined },
+ { color: undefined, position: { type: "unit", unit: "%", value: 100 } },
+ ],
+ });
+
+ const result = fillMissingStopPositions(gradient);
+ expect(result.stops[1]?.position).toEqual({
+ type: "unit",
+ unit: "%",
+ value: 50,
+ });
+ });
+
+ test("returns original gradient when positions use css variables", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: undefined,
+ position: {
+ type: "var",
+ value: "start",
+ fallback: { type: "unparsed", value: "10%" },
+ },
+ },
+ {
+ color: undefined,
+ position: { type: "unit", unit: "%", value: 100 },
+ },
+ ],
+ });
+
+ expect(fillMissingStopPositions(gradient)).toBe(gradient);
+ });
+
+ test("fills missing start and end positions when interior stops defined", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ { color: undefined },
+ { color: undefined, position: { type: "unit", unit: "%", value: 20 } },
+ { color: undefined },
+ { color: undefined, position: { type: "unit", unit: "%", value: 80 } },
+ { color: undefined },
+ ],
+ });
+
+ const result = fillMissingStopPositions(gradient);
+ expect(result.stops.map((stop) => stop.position?.value)).toEqual([
+ 0, 20, 50, 80, 100,
+ ]);
+ });
+
+ test("leaves gradients unchanged when positions are defined", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ { color: undefined, position: { type: "unit", unit: "%", value: 0 } },
+ { color: undefined, position: { type: "unit", unit: "%", value: 100 } },
+ ],
+ });
+
+ expect(fillMissingStopPositions(gradient)).toBe(gradient);
+ });
+});
+
+describe("ensureGradientHasStops", () => {
+ test("provides default stops when gradient is empty", () => {
+ const gradient = createLinearGradient();
+ const result = ensureGradientHasStops(gradient);
+ expect(result.stops).toHaveLength(2);
+ expect(result.stops[0]?.color).toEqual({
+ type: "rgb",
+ r: 0,
+ g: 0,
+ b: 0,
+ alpha: 1,
+ });
+ expect(result.stops[1]?.color).toEqual({
+ type: "rgb",
+ r: 0,
+ g: 0,
+ b: 0,
+ alpha: 0,
+ });
+ });
+
+ test("fills missing colors with fallback", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: undefined,
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ ],
+ });
+
+ const result = ensureGradientHasStops(gradient);
+ expect(result.stops[0]?.color).toEqual({
+ type: "rgb",
+ r: 0,
+ g: 0,
+ b: 0,
+ alpha: 1,
+ });
+ });
+
+ test("preserves existing stop colors", () => {
+ const stop: GradientStop = {
+ color: { type: "rgb", r: 10, g: 20, b: 30, alpha: 0.5 },
+ position: { type: "unit", unit: "%", value: 10 },
+ };
+ const gradient = createLinearGradient({
+ stops: [stop],
+ });
+
+ const result = ensureGradientHasStops(gradient);
+ expect(result).not.toBe(gradient);
+ expect(result.stops[0]).toBe(stop);
+ });
+});
+
+describe("clampStopIndex", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ { color: undefined, position: undefined },
+ { color: undefined, position: undefined },
+ ],
+ });
+
+ test("clamps to valid range", () => {
+ expect(clampStopIndex(-1, gradient)).toBe(0);
+ expect(clampStopIndex(1, gradient)).toBe(1);
+ expect(clampStopIndex(5, gradient)).toBe(1);
+ });
+
+ test("returns zero when gradient has no stops", () => {
+ const emptyGradient = createLinearGradient();
+ expect(clampStopIndex(3, emptyGradient)).toBe(0);
+ });
+});
+
+describe("styleValueToColor", () => {
+ type IntermediateColorValue = { type: "intermediate"; value: string };
+
+ test("returns undefined when style value missing", () => {
+ expect(styleValueToColor(undefined)).toBeUndefined();
+ });
+
+ test("returns rgb value when style already rgb", () => {
+ const style: RgbValue = { type: "rgb", r: 1, g: 2, b: 3, alpha: 0.5 };
+ expect(styleValueToColor(style)).toBe(style);
+ });
+
+ test("parses keyword colors", () => {
+ const style: StyleValue = { type: "keyword", value: "red" };
+ expect(styleValueToColor(style)).toEqual({ type: "keyword", value: "red" });
+ });
+
+ test("returns undefined when keyword is not recognized", () => {
+ const style: StyleValue = { type: "keyword", value: "not-a-color" };
+ expect(styleValueToColor(style)).toBeUndefined();
+ });
+
+ test("parses intermediate string colors", () => {
+ const style: IntermediateColorValue = {
+ type: "intermediate",
+ value: "#0000ff",
+ };
+ expect(styleValueToColor(style)).toEqual({
+ type: "rgb",
+ r: 0,
+ g: 0,
+ b: 255,
+ alpha: 1,
+ });
+ });
+
+ test("returns undefined when intermediate string is invalid", () => {
+ const style: IntermediateColorValue = {
+ type: "intermediate",
+ value: "#ggg",
+ };
+ expect(styleValueToColor(style)).toBeUndefined();
+ });
+
+ test("parses invalid style when value is valid color string", () => {
+ const style: StyleValue = { type: "invalid", value: "rgb(10 20 30)" };
+ expect(styleValueToColor(style)).toEqual({
+ type: "rgb",
+ r: 10,
+ g: 20,
+ b: 30,
+ alpha: 1,
+ });
+ });
+
+ test("returns undefined for invalid style when value is not a color", () => {
+ const style: StyleValue = { type: "invalid", value: "oops" };
+ expect(styleValueToColor(style)).toBeUndefined();
+ });
+
+ test("parses unparsed color strings", () => {
+ const style: StyleValue = {
+ type: "unparsed",
+ value: "hsl(180 100% 50%)",
+ };
+ expect(styleValueToColor(style)).toEqual({
+ type: "rgb",
+ r: 0,
+ g: 255,
+ b: 255,
+ alpha: 1,
+ });
+ });
+
+ test("returns var values", () => {
+ const variable: StyleValue = { type: "var", value: "--color" };
+ expect(styleValueToColor(variable)).toEqual(variable);
+ });
+
+ test("parses intermediate string var values", () => {
+ const style: IntermediateColorValue = {
+ type: "intermediate",
+ value: "var(--accent-color)",
+ };
+ expect(styleValueToColor(style)).toEqual({
+ type: "var",
+ value: "accent-color",
+ });
+ });
+
+ test("returns undefined for unsupported values", () => {
+ const style: StyleValue = { type: "unit", unit: "%", value: 25 };
+ expect(styleValueToColor(style)).toBeUndefined();
+ });
+});
+
+describe("resolveStopHintUpdate", () => {
+ test("returns cloned var hint and requests override clear", () => {
+ const fallback: StyleValue = { type: "unparsed", value: "20%" };
+ const styleValue: StyleValue = {
+ type: "var",
+ value: "hint",
+ fallback,
+ };
+
+ const result = resolveStopHintUpdate(styleValue, {
+ getPercentUnit: () => undefined,
+ clampPercentUnit: (value) => value,
+ });
+
+ expect(result.type).toBe("apply");
+ if (result.type !== "apply") {
+ throw new Error("Expected apply result");
+ }
+ expect(result).toEqual({
+ type: "apply",
+ hint: {
+ type: "var",
+ value: "hint",
+ fallback: { type: "unparsed", value: "20%" },
+ },
+ clearOverride: true,
+ });
+ expect(result.override).toBeUndefined();
+ if (result.hint?.type === "var") {
+ expect(result.hint).not.toBe(styleValue);
+ expect(result.hint.fallback).not.toBe(styleValue.fallback);
+ }
+ });
+
+ test("normalizes percent units and returns override", () => {
+ const styleValue: StyleValue = { type: "unit", unit: "%", value: 45 };
+ const normalized: PercentUnitValue = {
+ type: "unit",
+ unit: "%",
+ value: 50,
+ };
+
+ const result = resolveStopHintUpdate(styleValue, {
+ getPercentUnit: () => ({ type: "unit", unit: "%", value: 45 }),
+ clampPercentUnit: () => normalized,
+ });
+
+ expect(result.type).toBe("apply");
+ if (result.type !== "apply") {
+ throw new Error("Expected apply result");
+ }
+ expect(result).toEqual({
+ type: "apply",
+ hint: normalized,
+ override: normalized,
+ clearOverride: false,
+ });
+ });
+
+ test("returns none when value unsupported", () => {
+ const styleValue: StyleValue = { type: "keyword", value: "auto" };
+
+ const result = resolveStopHintUpdate(styleValue, {
+ getPercentUnit: () => undefined,
+ clampPercentUnit: (value) => value,
+ });
+
+ expect(result).toEqual({ type: "none" });
+ });
+});
+
+describe("resolveStopPositionUpdate", () => {
+ test("returns cloned var position and requests override clear", () => {
+ const fallback: StyleValue = { type: "unparsed", value: "30%" };
+ const styleValue: StyleValue = {
+ type: "var",
+ value: "pos",
+ fallback,
+ };
+
+ const result = resolveStopPositionUpdate(styleValue);
+
+ expect(result.type).toBe("apply");
+ if (result.type !== "apply") {
+ throw new Error("Expected apply result");
+ }
+ expect(result.clearHintOverrides).toBe(true);
+ expect(result.position).toEqual({
+ type: "var",
+ value: "pos",
+ fallback: { type: "unparsed", value: "30%" },
+ });
+ if (result.position?.type === "var") {
+ expect(result.position).not.toBe(styleValue);
+ expect(result.position.fallback).not.toBe(styleValue.fallback);
+ }
+ });
+
+ test("normalizes percent unit and requests override clear", () => {
+ const normalized: PercentUnitValue = {
+ type: "unit",
+ unit: "%",
+ value: 100,
+ };
+
+ const result = resolveStopPositionUpdate({
+ type: "unit",
+ unit: "%",
+ value: 120,
+ });
+
+ expect(result.type).toBe("apply");
+ if (result.type !== "apply") {
+ throw new Error("Expected apply result");
+ }
+ expect(result.position).toEqual(normalized);
+ expect(result.clearHintOverrides).toBe(true);
+ });
+
+ test("returns none when value unsupported", () => {
+ const result = resolveStopPositionUpdate({
+ type: "keyword",
+ value: "auto",
+ });
+
+ expect(result).toEqual({ type: "none" });
+ });
+});
+
+describe("resolveReverseStops", () => {
+ test("returns none when gradient has single stop", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: { type: "rgb", r: 0, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ ],
+ });
+
+ const result = resolveReverseStops(gradient, 0);
+ expect(result).toEqual({ type: "none" });
+ });
+
+ test("reverses stops and mirrors percent positions", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: { type: "rgb", r: 0, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ {
+ color: { type: "rgb", r: 255, g: 255, b: 255, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 40 },
+ },
+ {
+ color: { type: "rgb", r: 100, g: 100, b: 100, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 90 },
+ },
+ ],
+ });
+
+ const result = resolveReverseStops(gradient, 1);
+ expect(result.type).toBe("apply");
+ if (result.type !== "apply") {
+ throw new Error("Expected apply result");
+ }
+ expect(result.selectedStopIndex).toBe(1);
+ const positions = result.gradient.stops.map((stop) => stop.position);
+ expect(positions).toEqual([
+ { type: "unit", unit: "%", value: 10 },
+ { type: "unit", unit: "%", value: 60 },
+ { type: "unit", unit: "%", value: 100 },
+ ]);
+ });
+
+ test("preserves non-percent positions when reversing", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: undefined,
+ position: { type: "unit", unit: "px", value: 10 },
+ },
+ {
+ color: undefined,
+ position: { type: "var", value: "progress" },
+ },
+ ],
+ });
+
+ const result = resolveReverseStops(gradient, 0);
+ expect(result.type).toBe("apply");
+ if (result.type !== "apply") {
+ throw new Error("Expected apply result");
+ }
+ const [first, second] = result.gradient.stops;
+ expect(first.position).toEqual({ type: "var", value: "progress" });
+ expect(second.position).toEqual({ type: "unit", unit: "px", value: 10 });
+ });
+});
+
+describe("resolveGradientForPicker", () => {
+ test("fills missing stop positions without overrides", () => {
+ const gradient = createLinearGradient({
+ stops: [{ color: undefined }, { color: undefined }, { color: undefined }],
+ });
+
+ const result = resolveGradientForPicker(gradient, new Map());
+
+ expect(result.stops.map((stop) => stop.position?.value)).toEqual([
+ 0, 50, 100,
+ ]);
+ });
+
+ test("applies overrides when hints missing", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: undefined,
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ {
+ color: undefined,
+ position: { type: "unit", unit: "%", value: 50 },
+ },
+ ],
+ });
+
+ const overrides = new Map<number, PercentUnitValue>([
+ [1, { type: "unit", unit: "%", value: 25 }],
+ ]);
+
+ const result = resolveGradientForPicker(gradient, overrides);
+
+ expect(result.stops[1]?.hint).toEqual({
+ type: "unit",
+ unit: "%",
+ value: 25,
+ });
+ });
+
+ test("leaves existing hints untouched", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: undefined,
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ {
+ color: undefined,
+ position: { type: "unit", unit: "%", value: 100 },
+ hint: { type: "unit", unit: "%", value: 60 },
+ },
+ ],
+ });
+
+ const overrides = new Map<number, PercentUnitValue>([
+ [1, { type: "unit", unit: "%", value: 80 }],
+ ]);
+
+ const result = resolveGradientForPicker(gradient, overrides);
+
+ expect(result.stops[1]?.hint).toEqual({
+ type: "unit",
+ unit: "%",
+ value: 60,
+ });
+ });
+
+ test("resolves variable stop positions using fallback", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: undefined,
+ position: {
+ type: "var",
+ value: "--progress",
+ fallback: { type: "unit", unit: "%", value: 30 },
+ },
+ },
+ {
+ color: undefined,
+ position: { type: "unit", unit: "%", value: 100 },
+ },
+ ],
+ });
+
+ const result = resolveGradientForPicker(gradient, new Map());
+
+ expect(result.stops[0]?.position).toEqual({
+ type: "unit",
+ unit: "%",
+ value: 30,
+ });
+ });
+
+ test("falls back to inferred positions when variable has no fallback", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: undefined,
+ position: { type: "var", value: "--start" },
+ },
+ {
+ color: undefined,
+ },
+ ],
+ });
+
+ const result = resolveGradientForPicker(gradient, new Map());
+
+ expect(result.stops.map((stop) => stop.position?.value)).toEqual([0, 100]);
+ });
+
+ test("converts conic stop angles to percents", () => {
+ const gradient = createConicGradient({
+ stops: [
+ {
+ color: undefined,
+ position: { type: "unit", unit: "deg", value: 0 },
+ },
+ {
+ color: undefined,
+ position: { type: "unit", unit: "deg", value: 120 },
+ },
+ {
+ color: undefined,
+ position: { type: "unit", unit: "deg", value: 240 },
+ },
+ ],
+ });
+
+ const result = resolveGradientForPicker(gradient, new Map());
+
+ const stopPositions = result.stops.map((stop) => stop.position);
+ expect(stopPositions[0]).toEqual({
+ type: "unit",
+ unit: "%",
+ value: 0,
+ });
+ expect(stopPositions[1]).toEqual({
+ type: "unit",
+ unit: "%",
+ value: (120 / 360) * 100,
+ });
+ expect(stopPositions[2]).toEqual({
+ type: "unit",
+ unit: "%",
+ value: (240 / 360) * 100,
+ });
+ });
+
+ test("converts conic hints expressed in angles", () => {
+ const gradient = createConicGradient({
+ stops: [
+ {
+ color: undefined,
+ position: { type: "unit", unit: "%", value: 0 },
+ hint: { type: "unit", unit: "turn", value: 0.25 },
+ },
+ {
+ color: undefined,
+ position: { type: "unit", unit: "%", value: 100 },
+ },
+ ],
+ });
+
+ const result = resolveGradientForPicker(gradient, new Map());
+ const firstHint = result.stops[0]?.hint;
+ expect(firstHint).toEqual({
+ type: "unit",
+ unit: "%",
+ value: 25,
+ });
+ });
+});
+
+describe("hint override helpers", () => {
+ const makeOverride = (value: number): PercentUnitValue => ({
+ type: "unit",
+ unit: "%",
+ value,
+ });
+
+ test("removeHintOverride returns same map when index missing", () => {
+ const overrides = new Map<number, PercentUnitValue>();
+ const result = removeHintOverride(overrides, 1);
+ expect(result).toBe(overrides);
+ });
+
+ test("removeHintOverride removes matching index", () => {
+ const overrides = new Map<number, PercentUnitValue>([
+ [1, makeOverride(10)],
+ ]);
+ const result = removeHintOverride(overrides, 1);
+ expect(result).not.toBe(overrides);
+ expect(result.size).toBe(0);
+ });
+
+ test("setHintOverride adds new override without mutating original map", () => {
+ const overrides = new Map<number, PercentUnitValue>();
+ const override = makeOverride(40);
+ const result = setHintOverride(overrides, 2, override);
+ expect(result).not.toBe(overrides);
+ expect(result.get(2)).toBe(override);
+ expect(overrides.size).toBe(0);
+ });
+
+ test("setHintOverride returns same map when override unchanged", () => {
+ const override = makeOverride(60);
+ const overrides = new Map<number, PercentUnitValue>([[3, override]]);
+ const result = setHintOverride(overrides, 3, { ...override });
+ expect(result).toBe(overrides);
+ });
+
+ test("pruneHintOverrides removes indexes beyond stop count", () => {
+ const overrides = new Map<number, PercentUnitValue>([
+ [0, makeOverride(10)],
+ [5, makeOverride(90)],
+ ]);
+ const result = pruneHintOverrides(overrides, 2);
+ expect(result).not.toBe(overrides);
+ expect([...result.keys()]).toEqual([0]);
+ });
+
+ test("pruneHintOverrides returns same map when nothing pruned", () => {
+ const overrides = new Map<number, PercentUnitValue>([
+ [0, makeOverride(10)],
+ [1, makeOverride(20)],
+ ]);
+ const result = pruneHintOverrides(overrides, 3);
+ expect(result).toBe(overrides);
+ });
+});
+
+describe("createSolidLinearGradient", () => {
+ test("duplicates color stops at 0% and 100% while preserving base geometry", () => {
+ const color: GradientStop["color"] = {
+ type: "rgb",
+ r: 120,
+ g: 80,
+ b: 200,
+ alpha: 0.7,
+ } satisfies RgbValue;
+ const baseAngle = {
+ type: "unit",
+ unit: "deg",
+ value: 45,
+ } satisfies UnitValue;
+ const baseSide: KeywordValue = { type: "keyword", value: "to bottom" };
+ const baseGradient = createLinearGradient({
+ angle: baseAngle,
+ sideOrCorner: baseSide,
+ });
+
+ const result = createSolidLinearGradient(color, baseGradient);
+
+ expect(result.type).toBe("linear");
+ expect(result.angle).toBe(baseAngle);
+ expect(result.sideOrCorner).toBe(baseSide);
+ expect(result.stops).toHaveLength(2);
+
+ const [firstStop, secondStop] = result.stops;
+ expect(firstStop?.position).toEqual({
+ type: "unit",
+ unit: "%",
+ value: 0,
+ });
+ expect(secondStop?.position).toEqual({
+ type: "unit",
+ unit: "%",
+ value: 100,
+ });
+ expect(firstStop?.color).toEqual(color);
+ expect(secondStop?.color).toEqual(color);
+ expect(firstStop?.color).not.toBe(color);
+ expect(secondStop?.color).not.toBe(color);
+ });
+
+ test("clones var color fallbacks for each stop", () => {
+ const fallback: RgbValue = {
+ type: "rgb",
+ r: 10,
+ g: 40,
+ b: 90,
+ alpha: 1,
+ };
+ const color: VarValue = {
+ type: "var",
+ value: "--accent",
+ fallback,
+ };
+
+ const result = createSolidLinearGradient(color as GradientStop["color"]);
+ const [firstStop, secondStop] = result.stops;
+ const firstColor = firstStop?.color;
+ const secondColor = secondStop?.color;
+
+ expect(firstColor).toEqual(color);
+ expect(secondColor).toEqual(color);
+ expect(firstColor).not.toBe(color);
+ expect(secondColor).not.toBe(color);
+
+ if (firstColor?.type !== "var" || secondColor?.type !== "var") {
+ throw new Error("Expected var colors to be cloned");
+ }
+
+ expect(firstColor.fallback).toEqual(fallback);
+ expect(secondColor.fallback).toEqual(fallback);
+ expect(firstColor.fallback).not.toBe(fallback);
+ expect(secondColor.fallback).not.toBe(fallback);
+ expect(firstColor.fallback).not.toBe(secondColor.fallback);
+ });
+});
+
+describe("isSolidLinearGradient", () => {
+ test("returns true for valid solid gradient (2 stops, same color, 0% and 100%)", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 100 },
+ },
+ ],
+ });
+
+ expect(isSolidLinearGradient(gradient)).toBe(true);
+ });
+
+ test("returns false when gradient has only 1 stop", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ ],
+ });
+
+ expect(isSolidLinearGradient(gradient)).toBe(false);
+ });
+
+ test("returns false when gradient has 3 stops", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 50 },
+ },
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 100 },
+ },
+ ],
+ });
+
+ expect(isSolidLinearGradient(gradient)).toBe(false);
+ });
+
+ test("returns false when stops have different colors", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ {
+ color: { type: "rgb", r: 0, g: 0, b: 255, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 100 },
+ },
+ ],
+ });
+
+ expect(isSolidLinearGradient(gradient)).toBe(false);
+ });
+
+ test("returns false when first stop position is not 0%", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 10 },
+ },
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 100 },
+ },
+ ],
+ });
+
+ expect(isSolidLinearGradient(gradient)).toBe(false);
+ });
+
+ test("returns false when second stop position is not 100%", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 90 },
+ },
+ ],
+ });
+
+ expect(isSolidLinearGradient(gradient)).toBe(false);
+ });
+
+ test("returns true when first stop has no position (defaults to 0%)", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ },
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 100 },
+ },
+ ],
+ });
+
+ expect(isSolidLinearGradient(gradient)).toBe(true);
+ });
+
+ test("returns true when second stop has no position (defaults to 100%)", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ },
+ ],
+ });
+
+ expect(isSolidLinearGradient(gradient)).toBe(true);
+ });
+
+ test("returns false when positions use px unit instead of %", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "px", value: 0 },
+ },
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "px", value: 100 },
+ },
+ ],
+ });
+
+ expect(isSolidLinearGradient(gradient)).toBe(false);
+ });
+
+ test("returns false when first stop color is undefined", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 100 },
+ },
+ ],
+ });
+
+ expect(isSolidLinearGradient(gradient)).toBe(false);
+ });
+
+ test("returns false when second stop color is undefined", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ {
+ position: { type: "unit", unit: "%", value: 100 },
+ },
+ ],
+ });
+
+ expect(isSolidLinearGradient(gradient)).toBe(false);
+ });
+
+ test("returns true when colors match with different alpha values", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: { type: "rgb", r: 100, g: 150, b: 200, alpha: 0.5 },
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ {
+ color: { type: "rgb", r: 100, g: 150, b: 200, alpha: 0.5 },
+ position: { type: "unit", unit: "%", value: 100 },
+ },
+ ],
+ });
+
+ expect(isSolidLinearGradient(gradient)).toBe(true);
+ });
+
+ test("returns false when colors have same RGB but different alpha", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: { type: "rgb", r: 100, g: 150, b: 200, alpha: 0.5 },
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ {
+ color: { type: "rgb", r: 100, g: 150, b: 200, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 100 },
+ },
+ ],
+ });
+
+ expect(isSolidLinearGradient(gradient)).toBe(false);
+ });
+
+ test("returns true for keyword colors that match", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: { type: "keyword", value: "red" },
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ {
+ color: { type: "keyword", value: "red" },
+ position: { type: "unit", unit: "%", value: 100 },
+ },
+ ],
+ });
+
+ expect(isSolidLinearGradient(gradient)).toBe(true);
+ });
+
+ test("returns false when positions use var values", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: {
+ type: "var",
+ value: "--start",
+ fallback: { type: "unit", unit: "%", value: 0 },
+ },
+ },
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 100 },
+ },
+ ],
+ });
+
+ expect(isSolidLinearGradient(gradient)).toBe(false);
+ });
+
+ test("returns true when both positions are undefined (auto-assigned 0% and 100%)", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ },
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ },
+ ],
+ });
+
+ expect(isSolidLinearGradient(gradient)).toBe(true);
+ });
+
+ test("returns true when first position is undefined and second is 100%", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ },
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 100 },
+ },
+ ],
+ });
+
+ expect(isSolidLinearGradient(gradient)).toBe(true);
+ });
+
+ test("returns true when first position is 0% and second is undefined", () => {
+ const gradient = createLinearGradient({
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ },
+ ],
+ });
+
+ expect(isSolidLinearGradient(gradient)).toBe(true);
+ });
+});
+
+describe("detectBackgroundType", () => {
+ test("returns image when style value undefined", () => {
+ expect(detectBackgroundType(undefined)).toBe("image");
+ });
+
+ test("returns image for keyword none", () => {
+ const value: StyleValue = { type: "keyword", value: "none" };
+ expect(detectBackgroundType(value)).toBe("image");
+ });
+
+ test("returns image for url image value", () => {
+ const value: StyleValue = {
+ type: "image",
+ value: { type: "url", url: "https://example.com/image.png" },
+ };
+ expect(detectBackgroundType(value)).toBe("image");
+ });
+
+ test("returns linearGradient for linear gradient", () => {
+ const value: StyleValue = {
+ type: "unparsed",
+ value: "linear-gradient(red, blue)",
+ };
+ expect(detectBackgroundType(value)).toBe("linearGradient");
+ });
+
+ test("returns solid for uniform linear gradient with explicit positions", () => {
+ const value: StyleValue = {
+ type: "unparsed",
+ value: "linear-gradient(red 0%, red 100%)",
+ };
+ expect(detectBackgroundType(value)).toBe("solid");
+ });
+
+ test("returns solid for uniform gradient without explicit positions", () => {
+ const value: StyleValue = {
+ type: "unparsed",
+ value: "linear-gradient(red, red)",
+ };
+ expect(detectBackgroundType(value)).toBe("solid");
+ });
+
+ test("returns conicGradient for conic gradient", () => {
+ const value: StyleValue = {
+ type: "unparsed",
+ value: "conic-gradient(red, blue)",
+ };
+ expect(detectBackgroundType(value)).toBe("conicGradient");
+ });
+
+ test("returns conicGradient for conic gradients with from/at syntax", () => {
+ const value: StyleValue = {
+ type: "unparsed",
+ value:
+ "conic-gradient(from 0deg at 50% 50%, rgba(255,126,95,1) 0deg, rgba(254,180,123,1) 120deg, rgba(134,168,231,1) 240deg, rgba(255,126,95,1) 360deg)",
+ };
+ expect(detectBackgroundType(value)).toBe("conicGradient");
+ });
+
+ test("returns radialGradient for radial gradients", () => {
+ const value: StyleValue = {
+ type: "unparsed",
+ value: "radial-gradient(circle, red, blue)",
+ };
+ expect(detectBackgroundType(value)).toBe("radialGradient");
+ });
+
+ test("returns radialGradient for repeating radial gradients", () => {
+ const value: StyleValue = {
+ type: "unparsed",
+ value: "repeating-radial-gradient(circle, red, blue)",
+ };
+ expect(detectBackgroundType(value)).toBe("radialGradient");
+ });
+
+ test("returns image for unsupported gradient types", () => {
+ const value: StyleValue = {
+ type: "unparsed",
+ value: "unsupported-gradient(circle, red, blue)",
+ };
+ expect(detectBackgroundType(value)).toBe("image");
+ });
+});
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/gradient-utils.ts b/apps/builder/app/builder/features/style-panel/sections/backgrounds/gradient-utils.ts
new file mode 100644
index 0000000000..8241051bba
--- /dev/null
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/gradient-utils.ts
@@ -0,0 +1,1252 @@
+import { clamp } from "@react-aria/utils";
+import {
+ toValue,
+ type CssProperty,
+ type KeywordValue,
+ type RgbValue,
+ type StyleValue,
+ type Unit,
+ type UnitValue,
+ type VarFallback,
+ type VarValue,
+} from "@webstudio-is/css-engine";
+import {
+ parseCssValue,
+ parseLinearGradient,
+ parseConicGradient,
+ parseRadialGradient,
+ formatLinearGradient,
+ formatConicGradient,
+ formatRadialGradient,
+ expandShorthands,
+ type GradientStop,
+ type ParsedGradient,
+ type ParsedLinearGradient,
+ type ParsedConicGradient,
+ type ParsedRadialGradient,
+} from "@webstudio-is/css-data";
+import type { ComputedStyleDecl } from "~/shared/style-object-model";
+import { getRepeatedStyleItem } from "../../shared/repeated-style";
+import type { UnitOption } from "../../shared/css-value-input/unit-select";
+
+const backgroundPositionXLonghand: CssProperty = "background-position-x";
+const backgroundPositionYLonghand: CssProperty = "background-position-y";
+
+export type GradientType = "linear" | "conic" | "radial";
+export type PercentUnitValue = UnitValue & { unit: "%" };
+export type NormalizedGradient = {
+ normalizedGradientString: string;
+ initialIsRepeating: boolean;
+};
+export type IntermediateColorValue = {
+ type: "intermediate";
+ value: string;
+};
+
+const gradientFunctionNames: Record<
+ GradientType,
+ { base: string; repeating: string }
+> = {
+ linear: {
+ base: "linear-gradient",
+ repeating: "repeating-linear-gradient",
+ },
+ conic: {
+ base: "conic-gradient",
+ repeating: "repeating-conic-gradient",
+ },
+ radial: {
+ base: "radial-gradient",
+ repeating: "repeating-radial-gradient",
+ },
+};
+
+const startsWithGradientFunction = (value: string, type: GradientType) => {
+ const normalized = value.trim().toLowerCase();
+ const { base, repeating } = gradientFunctionNames[type];
+ return (
+ normalized.startsWith(`${base}(`) || normalized.startsWith(`${repeating}(`)
+ );
+};
+
+const angleUnitTokens = ["deg", "grad", "rad", "turn"] as const;
+type AngleUnit = (typeof angleUnitTokens)[number];
+const angleUnitSet = new Set<AngleUnit>(angleUnitTokens);
+const fullCircleDegrees = 360;
+
+export const angleUnitOptions = angleUnitTokens.map((unit) => ({
+ id: unit,
+ label: unit,
+ type: "unit" as const,
+}));
+
+export const percentUnitOptions: UnitOption[] = [
+ {
+ id: "%" as Unit,
+ label: "%",
+ type: "unit",
+ },
+];
+
+const createKeywordValue = (value: string): KeywordValue => ({
+ type: "keyword",
+ value,
+});
+
+const createCenterKeyword = () => createKeywordValue("center");
+
+export const gradientPositionXOptions: KeywordValue[] = [
+ createCenterKeyword(),
+ createKeywordValue("left"),
+ createKeywordValue("right"),
+];
+
+export const gradientPositionYOptions: KeywordValue[] = [
+ createCenterKeyword(),
+ createKeywordValue("top"),
+ createKeywordValue("bottom"),
+];
+
+const getAxisPositionValue = (
+ property: CssProperty,
+ value: string | undefined
+): StyleValue | undefined => {
+ if (value === undefined) {
+ return;
+ }
+ const parsed = parseCssValue(property, value);
+ if (parsed.type === "invalid") {
+ return;
+ }
+ return parsed;
+};
+
+export const parseGradientPositionValues = (position?: string) => {
+ if (position === undefined) {
+ return {
+ xValue: createCenterKeyword(),
+ yValue: createCenterKeyword(),
+ } as const;
+ }
+ try {
+ const longhands = expandShorthands([["background-position", position]]);
+ const [xLonghand, yLonghand] = longhands;
+ return {
+ // Use the real background-position longhand when parsing so we can reuse
+ // its CSS syntax rules, but assign the result to the gradient-specific
+ // custom property downstream.
+ xValue:
+ getAxisPositionValue(backgroundPositionXLonghand, xLonghand?.[1]) ??
+ createCenterKeyword(),
+ yValue:
+ getAxisPositionValue(backgroundPositionYLonghand, yLonghand?.[1]) ??
+ createCenterKeyword(),
+ } as const;
+ } catch {
+ return {
+ xValue: createCenterKeyword(),
+ yValue: createCenterKeyword(),
+ } as const;
+ }
+};
+
+export const formatGradientPositionValues = (
+ xValue?: StyleValue,
+ yValue?: StyleValue
+) => {
+ const x = toValue(xValue ?? createCenterKeyword());
+ const y = toValue(yValue ?? createCenterKeyword());
+ if (x === "center" && y === "center") {
+ return;
+ }
+ if (y === "center") {
+ return x;
+ }
+ return `${x} ${y}`;
+};
+
+export const createPercentUnitValue = (value: number): PercentUnitValue => ({
+ type: "unit",
+ unit: "%" as const,
+ value: clampPercentValue(value),
+});
+
+const isAngleUnit = (unit: string): unit is AngleUnit =>
+ angleUnitSet.has(unit as AngleUnit);
+
+const clampPercentValue = (value: number) => clamp(value, 0, 100);
+
+const angleUnitToDegrees = (value: UnitValue): number | undefined => {
+ switch (value.unit) {
+ case "deg":
+ return value.value;
+ case "grad":
+ return (value.value * 360) / 400;
+ case "rad":
+ return (value.value * 180) / Math.PI;
+ case "turn":
+ return value.value * 360;
+ default:
+ return;
+ }
+};
+
+const toPercentUnitValue = (value: UnitValue): PercentUnitValue | undefined => {
+ if (value.unit === "%") {
+ return {
+ type: "unit" as const,
+ unit: "%" as const,
+ value: clampPercentValue(value.value),
+ } satisfies PercentUnitValue;
+ }
+
+ if (isAngleUnit(value.unit) === false) {
+ return;
+ }
+
+ const degrees = angleUnitToDegrees(value);
+ if (degrees === undefined || Number.isFinite(degrees) === false) {
+ return;
+ }
+
+ const normalizedDegrees =
+ ((degrees % fullCircleDegrees) + fullCircleDegrees) % fullCircleDegrees;
+ const percentValue = clampPercentValue(
+ (normalizedDegrees / fullCircleDegrees) * 100
+ );
+
+ return {
+ type: "unit" as const,
+ unit: "%" as const,
+ value: percentValue,
+ } satisfies PercentUnitValue;
+};
+
+export const fallbackStopColor: RgbValue = {
+ type: "rgb",
+ r: 0,
+ g: 0,
+ b: 0,
+ alpha: 1,
+};
+
+export const createDefaultStops = (): GradientStop[] => [
+ {
+ color: { type: "rgb", r: 0, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ {
+ color: { type: "rgb", r: 0, g: 0, b: 0, alpha: 0 },
+ position: { type: "unit", unit: "%", value: 100 },
+ },
+];
+
+const createDefaultLinearGradient = (): ParsedLinearGradient => ({
+ type: "linear",
+ stops: createDefaultStops(),
+});
+
+const createDefaultConicGradient = (): ParsedConicGradient => ({
+ type: "conic",
+ stops: createDefaultStops(),
+});
+
+const createDefaultRadialGradient = (): ParsedRadialGradient => ({
+ type: "radial",
+ stops: createDefaultStops(),
+});
+
+type CreateDefaultGradient = {
+ (type: "linear"): ParsedLinearGradient;
+ (type: "conic"): ParsedConicGradient;
+ (type: "radial"): ParsedRadialGradient;
+ (type: GradientType): ParsedGradient;
+};
+
+export const createDefaultGradient = ((type: GradientType) => {
+ switch (type) {
+ case "linear":
+ return createDefaultLinearGradient();
+ case "conic":
+ return createDefaultConicGradient();
+ case "radial":
+ return createDefaultRadialGradient();
+ }
+}) as CreateDefaultGradient;
+
+export const isLinearGradient = (
+ gradient: ParsedGradient
+): gradient is ParsedLinearGradient => gradient.type === "linear";
+
+export const isConicGradient = (
+ gradient: ParsedGradient
+): gradient is ParsedConicGradient => gradient.type === "conic";
+
+export const isRadialGradient = (
+ gradient: ParsedGradient
+): gradient is ParsedRadialGradient => gradient.type === "radial";
+
+/**
+ * Get the default angle for a gradient according to CSS spec.
+ * - linear-gradient: 180deg (to bottom)
+ * - conic-gradient: 0deg (from top)
+ * - radial-gradient: undefined (no angle)
+ */
+export const getDefaultAngle = (
+ gradient: ParsedGradient
+): UnitValue | undefined => {
+ if (isLinearGradient(gradient)) {
+ return { type: "unit", unit: "deg", value: 180 };
+ }
+ if (isConicGradient(gradient)) {
+ return { type: "unit", unit: "deg", value: 0 };
+ }
+ return;
+};
+
+export const getPercentUnit = (
+ styleValue: StyleValue | undefined
+): PercentUnitValue | undefined => {
+ if (styleValue === undefined) {
+ return;
+ }
+
+ if (styleValue.type === "unit" && styleValue.unit === "%") {
+ return {
+ type: "unit" as const,
+ unit: "%" as const,
+ value: styleValue.value,
+ } satisfies PercentUnitValue;
+ }
+
+ if (styleValue.type === "layers") {
+ const firstLayer = styleValue.value[0];
+ if (firstLayer?.type === "unit" && firstLayer.unit === "%") {
+ return {
+ type: "unit" as const,
+ unit: "%" as const,
+ value: firstLayer.value,
+ } satisfies PercentUnitValue;
+ }
+ }
+};
+
+export const normalizeGradientInput = (
+ gradientString: string,
+ gradientType: GradientType
+): NormalizedGradient => {
+ const leadingWhitespaceMatch = gradientString.match(/^\s*/);
+ const leadingWhitespace = leadingWhitespaceMatch?.[0] ?? "";
+ const withoutLeading = gradientString.slice(leadingWhitespace.length);
+ const lowerCase = withoutLeading.toLowerCase();
+ const { base, repeating } = gradientFunctionNames[gradientType];
+
+ if (lowerCase.startsWith(repeating)) {
+ const suffix = withoutLeading.slice(repeating.length);
+ return {
+ normalizedGradientString: `${leadingWhitespace}${base}${suffix}`,
+ initialIsRepeating: true,
+ } satisfies NormalizedGradient;
+ }
+
+ return {
+ normalizedGradientString: gradientString,
+ initialIsRepeating: false,
+ } satisfies NormalizedGradient;
+};
+
+export const sideOrCornerToAngle = (
+ sideOrCorner: KeywordValue | undefined
+): number | undefined => {
+ if (sideOrCorner === undefined) {
+ return;
+ }
+ const normalized = sideOrCorner.value.trim().toLowerCase();
+ if (normalized.startsWith("to ") === false) {
+ return;
+ }
+ const tokens = normalized.slice(3).split(/\s+/).filter(Boolean);
+ if (tokens.length === 0) {
+ return;
+ }
+ const tokenSet = new Set(tokens);
+ const has = (token: string) => tokenSet.has(token);
+ if (tokenSet.size === 1) {
+ if (has("top")) {
+ return 0;
+ }
+ if (has("right")) {
+ return 90;
+ }
+ if (has("bottom")) {
+ return 180;
+ }
+ if (has("left")) {
+ return 270;
+ }
+ return;
+ }
+ if (tokenSet.size === 2) {
+ if (has("top") && has("right")) {
+ return 45;
+ }
+ if (has("bottom") && has("right")) {
+ return 135;
+ }
+ if (has("bottom") && has("left")) {
+ return 225;
+ }
+ if (has("top") && has("left")) {
+ return 315;
+ }
+ }
+};
+
+export const fillMissingStopPositions = <T extends ParsedGradient>(
+ gradient: T
+): T => {
+ const stops = gradient.stops;
+ if (stops.length === 0) {
+ return gradient;
+ }
+
+ const hasMissingPositions = stops.some((stop) => stop.position === undefined);
+ if (hasMissingPositions === false) {
+ return gradient;
+ }
+
+ const hasUnsupportedPosition = stops.some(
+ (stop) =>
+ stop.position !== undefined &&
+ (stop.position.type !== "unit" || stop.position.unit !== "%")
+ );
+ if (hasUnsupportedPosition) {
+ return gradient;
+ }
+
+ const totalStops = stops.length;
+ const values = stops.map((stop) =>
+ stop.position?.type === "unit" ? stop.position.value : undefined
+ );
+ const nextValues = [...values];
+ const definedCount = nextValues.filter(
+ (value): value is number => value !== undefined
+ ).length;
+
+ if (definedCount === 0) {
+ if (totalStops === 1) {
+ nextValues[0] = 0;
+ } else {
+ for (let index = 0; index < totalStops; index += 1) {
+ const value = (index / (totalStops - 1)) * 100;
+ nextValues[index] = clamp(value, 0, 100);
+ }
+ }
+ } else {
+ if (nextValues[0] === undefined) {
+ nextValues[0] = 0;
+ }
+ if (nextValues[totalStops - 1] === undefined) {
+ nextValues[totalStops - 1] = 100;
+ }
+
+ let start = 0;
+ while (start < totalStops) {
+ const startValue = nextValues[start];
+ if (startValue === undefined) {
+ start += 1;
+ continue;
+ }
+ let end = start + 1;
+ while (end < totalStops && nextValues[end] === undefined) {
+ end += 1;
+ }
+ if (end >= totalStops) {
+ break;
+ }
+ const endValue = nextValues[end];
+ if (endValue === undefined) {
+ break;
+ }
+ const span = end - start;
+ for (let offset = 1; offset < span; offset += 1) {
+ const interpolated =
+ startValue + ((endValue - startValue) * offset) / span;
+ nextValues[start + offset] = clamp(interpolated, 0, 100);
+ }
+ start = end;
+ }
+ }
+
+ const nextStops = stops.map((stop, index) => {
+ if (stop.position !== undefined) {
+ return stop;
+ }
+ const value = nextValues[index];
+ if (value === undefined) {
+ return stop;
+ }
+ return {
+ ...stop,
+ position: {
+ type: "unit" as const,
+ unit: "%" as const,
+ value,
+ },
+ };
+ });
+
+ return {
+ ...gradient,
+ stops: nextStops,
+ } as T;
+};
+
+const cloneVarValue = (value: VarValue): VarValue => ({
+ ...value,
+ fallback: value.fallback === undefined ? undefined : { ...value.fallback },
+});
+
+export const cloneVarFallback = (
+ fallback: VarFallback | undefined
+): VarFallback | undefined => {
+ if (fallback === undefined) {
+ return;
+ }
+
+ if (fallback.type === "rgb") {
+ return { ...fallback } satisfies VarFallback;
+ }
+
+ return { ...fallback } satisfies VarFallback;
+};
+
+const cloneGradientStopValue = <
+ Value extends GradientStop["position"] | GradientStop["hint"],
+>(
+ value: Value
+): Value => {
+ if (value === undefined) {
+ return value;
+ }
+
+ if (value.type === "var") {
+ const fallback = value.fallback;
+ return {
+ ...value,
+ fallback: fallback === undefined ? undefined : { ...fallback },
+ } as Value;
+ }
+
+ return { ...value } as Value;
+};
+
+const cloneGradientStopColor = (
+ color: GradientStop["color"] | undefined
+): GradientStop["color"] => {
+ if (color === undefined) {
+ return { ...fallbackStopColor } satisfies GradientStop["color"];
+ }
+ if (color.type === "var") {
+ return {
+ ...color,
+ fallback: cloneVarFallback(color.fallback),
+ } satisfies GradientStop["color"];
+ }
+ if (color.type === "rgb") {
+ return { ...color } satisfies GradientStop["color"];
+ }
+ return { ...color } satisfies GradientStop["color"];
+};
+
+const createSolidGradientStops = (color: GradientStop["color"]) => {
+ const firstColor = cloneGradientStopColor(color);
+ const secondColor = cloneGradientStopColor(color);
+ return [
+ {
+ color: firstColor,
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ {
+ color: secondColor,
+ position: { type: "unit", unit: "%", value: 100 },
+ },
+ ] satisfies GradientStop[];
+};
+
+export const createSolidLinearGradient = (
+ color: GradientStop["color"],
+ base?: ParsedLinearGradient
+): ParsedLinearGradient => {
+ const stops = createSolidGradientStops(color);
+ return {
+ type: "linear",
+ angle: base?.angle,
+ sideOrCorner: base?.sideOrCorner,
+ stops,
+ } satisfies ParsedLinearGradient;
+};
+
+type AngleUnitValue = UnitValue & { unit: AngleUnit };
+type AngleValue = AngleUnitValue | VarValue;
+
+const resolveAnglePrimitive = (
+ value: VarValue | UnitValue | undefined
+): AngleValue | undefined => {
+ if (value === undefined) {
+ return;
+ }
+
+ if (value.type === "var") {
+ return cloneVarValue(value);
+ }
+
+ if (value.type === "unit" && isAngleUnit(value.unit)) {
+ return {
+ ...value,
+ unit: value.unit,
+ } satisfies AngleUnitValue;
+ }
+
+ return;
+};
+
+export const resolveAngleValue = (
+ styleValue: StyleValue | undefined
+): AngleValue | undefined => {
+ if (styleValue === undefined) {
+ return;
+ }
+
+ if (styleValue.type === "tuple") {
+ const first = styleValue.value[0];
+ if (first?.type === "var" || first?.type === "unit") {
+ return resolveAnglePrimitive(first);
+ }
+ return;
+ }
+
+ if (styleValue.type === "layers") {
+ const firstLayer = styleValue.value[0];
+ if (firstLayer?.type === "var" || firstLayer?.type === "unit") {
+ return resolveAnglePrimitive(firstLayer);
+ }
+ return;
+ }
+
+ if (styleValue.type === "var" || styleValue.type === "unit") {
+ return resolveAnglePrimitive(styleValue);
+ }
+
+ return;
+};
+
+export const formatGradientValue = (gradient: ParsedGradient) => {
+ if (isLinearGradient(gradient)) {
+ return formatLinearGradient(gradient);
+ }
+ if (isConicGradient(gradient)) {
+ return formatConicGradient(gradient);
+ }
+ return formatRadialGradient(gradient);
+};
+
+const resolveVarPercentUnit = (
+ value: GradientStop["position"] | GradientStop["hint"]
+): PercentUnitValue | undefined => {
+ if (value?.type !== "var") {
+ return;
+ }
+ const fallback = value.fallback;
+ if (fallback?.type === "unit") {
+ const percentFallback = toPercentUnitValue(fallback);
+ if (percentFallback !== undefined) {
+ return percentFallback;
+ }
+ }
+};
+
+const normalizeStopsForPicker = <T extends ParsedGradient>(gradient: T): T => {
+ let changed = false;
+ const stops = gradient.stops.map((stop) => {
+ let nextPosition = stop.position;
+ let nextHint = stop.hint;
+ let stopChanged = false;
+
+ if (stop.position?.type === "var") {
+ nextPosition = resolveVarPercentUnit(stop.position);
+ stopChanged = true;
+ }
+
+ if (stop.hint?.type === "var") {
+ nextHint = resolveVarPercentUnit(stop.hint);
+ stopChanged = true;
+ }
+
+ if (stopChanged) {
+ changed = true;
+ return {
+ ...stop,
+ position: nextPosition,
+ hint: nextHint,
+ } satisfies GradientStop;
+ }
+
+ return stop;
+ });
+
+ if (changed === false) {
+ return gradient;
+ }
+
+ return {
+ ...gradient,
+ stops,
+ } as T;
+};
+
+const convertConicStopsToPercent = <T extends ParsedGradient>(
+ gradient: T
+): T => {
+ if (isConicGradient(gradient) === false) {
+ return gradient;
+ }
+
+ let changed = false;
+ const stops = gradient.stops.map((stop) => {
+ let nextPosition = stop.position;
+ let nextHint = stop.hint;
+ let stopChanged = false;
+
+ if (stop.position?.type === "unit") {
+ const percentPosition = toPercentUnitValue(stop.position);
+ if (
+ percentPosition !== undefined &&
+ (stop.position.unit !== percentPosition.unit ||
+ stop.position.value !== percentPosition.value)
+ ) {
+ nextPosition = percentPosition;
+ stopChanged = true;
+ }
+ }
+
+ if (stop.hint?.type === "unit") {
+ const percentHint = toPercentUnitValue(stop.hint);
+ if (
+ percentHint !== undefined &&
+ (stop.hint.unit !== percentHint.unit ||
+ stop.hint.value !== percentHint.value)
+ ) {
+ nextHint = percentHint;
+ stopChanged = true;
+ }
+ }
+
+ if (stopChanged) {
+ changed = true;
+ return {
+ ...stop,
+ position: nextPosition,
+ hint: nextHint,
+ } satisfies GradientStop;
+ }
+
+ return stop;
+ });
+
+ if (changed === false) {
+ return gradient;
+ }
+
+ return {
+ ...gradient,
+ stops,
+ } as T;
+};
+
+export const resolveGradientForPicker = <T extends ParsedGradient>(
+ gradient: T,
+ hintOverrides: ReadonlyMap<number, PercentUnitValue>
+): T => {
+ const withPercentualStops = convertConicStopsToPercent(gradient);
+ const normalized = normalizeStopsForPicker(withPercentualStops);
+ const filled = fillMissingStopPositions(normalized);
+ if (hintOverrides.size === 0) {
+ return filled;
+ }
+ let changed = false;
+ const stopsWithHints = filled.stops.map((stop, index) => {
+ if (stop.hint !== undefined) {
+ return stop;
+ }
+ const override = hintOverrides.get(index);
+ if (override === undefined) {
+ return stop;
+ }
+ changed = true;
+ return {
+ ...stop,
+ hint: override,
+ };
+ });
+ if (changed === false) {
+ return filled;
+ }
+ return {
+ ...filled,
+ stops: stopsWithHints,
+ } as T;
+};
+
+export const removeHintOverride = (
+ overrides: Map<number, PercentUnitValue>,
+ stopIndex: number
+): Map<number, PercentUnitValue> => {
+ if (overrides.has(stopIndex) === false) {
+ return overrides;
+ }
+ const next = new Map(overrides);
+ next.delete(stopIndex);
+ return next;
+};
+
+export const setHintOverride = (
+ overrides: Map<number, PercentUnitValue>,
+ stopIndex: number,
+ override: PercentUnitValue
+): Map<number, PercentUnitValue> => {
+ const existing = overrides.get(stopIndex);
+ if (existing !== undefined) {
+ if (existing === override) {
+ return overrides;
+ }
+ if (
+ existing.type === override.type &&
+ existing.unit === override.unit &&
+ existing.value === override.value
+ ) {
+ return overrides;
+ }
+ }
+ const next = new Map(overrides);
+ next.set(stopIndex, override);
+ return next;
+};
+
+export const pruneHintOverrides = (
+ overrides: Map<number, PercentUnitValue>,
+ stopCount: number
+): Map<number, PercentUnitValue> => {
+ if (overrides.size === 0) {
+ return overrides;
+ }
+ let changed = false;
+ const next = new Map(overrides);
+ for (const [index] of overrides) {
+ if (index >= stopCount) {
+ next.delete(index);
+ changed = true;
+ }
+ }
+ return changed ? next : overrides;
+};
+
+export type ReverseStopsResolution<T extends ParsedGradient> =
+ | {
+ type: "apply";
+ gradient: T;
+ selectedStopIndex: number;
+ }
+ | { type: "none" };
+
+export const resolveReverseStops = <T extends ParsedGradient>(
+ gradient: T,
+ selectedStopIndex: number
+): ReverseStopsResolution<T> => {
+ if (gradient.stops.length <= 1) {
+ return { type: "none" } satisfies ReverseStopsResolution<T>;
+ }
+ const stopIndex = clampStopIndex(selectedStopIndex, gradient);
+ const reversedStops = [...gradient.stops].reverse();
+ const nextStops = reversedStops.map((stop) => {
+ let position = stop.position;
+ if (position?.type === "unit" && position.unit === "%") {
+ position = {
+ ...position,
+ value: clamp(100 - position.value, 0, 100),
+ } as PercentUnitValue;
+ }
+ return { ...stop, position } satisfies GradientStop;
+ });
+ const nextGradient = { ...gradient, stops: nextStops } as T;
+ const nextSelectedIndex = gradient.stops.length - 1 - stopIndex;
+ return {
+ type: "apply",
+ gradient: nextGradient,
+ selectedStopIndex: nextSelectedIndex,
+ } satisfies ReverseStopsResolution<T>;
+};
+
+export type StopPositionUpdateResolution =
+ | {
+ type: "apply";
+ position: GradientStop["position"];
+ clearHintOverrides: boolean;
+ }
+ | { type: "none" };
+
+export const resolveStopPositionUpdate = (
+ styleValue: StyleValue
+): StopPositionUpdateResolution => {
+ if (styleValue.type === "var") {
+ return {
+ type: "apply",
+ position: cloneGradientStopValue(styleValue as GradientStop["position"]),
+ clearHintOverrides: true,
+ } satisfies StopPositionUpdateResolution;
+ }
+
+ const percentUnit = getPercentUnit(styleValue);
+ if (percentUnit === undefined) {
+ return { type: "none" } satisfies StopPositionUpdateResolution;
+ }
+
+ const normalized: PercentUnitValue = {
+ ...percentUnit,
+ value: clamp(percentUnit.value, 0, 100),
+ } satisfies PercentUnitValue;
+ return {
+ type: "apply",
+ position: normalized,
+ clearHintOverrides: true,
+ } satisfies StopPositionUpdateResolution;
+};
+
+type StopHintUpdateHelpers = {
+ getPercentUnit: (value: StyleValue) => PercentUnitValue | undefined;
+ clampPercentUnit: (value: PercentUnitValue) => PercentUnitValue;
+};
+
+export type StopHintUpdateResolution =
+ | {
+ type: "apply";
+ hint: GradientStop["hint"];
+ clearOverride: boolean;
+ override?: PercentUnitValue;
+ }
+ | { type: "none" };
+
+export const resolveStopHintUpdate = (
+ styleValue: StyleValue,
+ helpers: StopHintUpdateHelpers
+): StopHintUpdateResolution => {
+ if (styleValue.type === "var") {
+ return {
+ type: "apply",
+ hint: cloneGradientStopValue(styleValue as GradientStop["hint"]),
+ clearOverride: true,
+ };
+ }
+
+ const percentUnit = helpers.getPercentUnit(styleValue);
+ if (percentUnit === undefined) {
+ return { type: "none" };
+ }
+
+ const normalized = helpers.clampPercentUnit(percentUnit);
+ return {
+ type: "apply",
+ hint: normalized,
+ override: normalized,
+ clearOverride: false,
+ };
+};
+
+export const ensureGradientHasStops = <T extends ParsedGradient>(
+ gradient: T
+): T => {
+ const stops =
+ gradient.stops.length === 0
+ ? createDefaultStops()
+ : gradient.stops.map((stop) =>
+ stop.color === undefined
+ ? {
+ ...stop,
+ color: { ...fallbackStopColor },
+ }
+ : stop
+ );
+
+ return {
+ ...gradient,
+ stops,
+ } as T;
+};
+
+export const clampStopIndex = <T extends ParsedGradient>(
+ index: number,
+ gradient: T
+) => clamp(index, 0, Math.max(gradient.stops.length - 1, 0));
+
+const parseColorString = (value: string): GradientStop["color"] | undefined => {
+ const parsed = parseCssValue("color", value);
+ if (
+ parsed.type === "rgb" ||
+ parsed.type === "keyword" ||
+ parsed.type === "var"
+ ) {
+ return parsed;
+ }
+};
+
+export const styleValueToColor = (
+ styleValue: StyleValue | IntermediateColorValue | undefined
+): GradientStop["color"] | undefined => {
+ if (styleValue === undefined) {
+ return;
+ }
+
+ if (styleValue.type === "intermediate") {
+ return parseColorString(styleValue.value);
+ }
+
+ if (styleValue.type === "rgb") {
+ return styleValue;
+ }
+
+ if (styleValue.type === "var") {
+ return styleValue;
+ }
+
+ if (styleValue.type === "keyword") {
+ return parseColorString(styleValue.value);
+ }
+
+ if (styleValue.type === "invalid") {
+ return parseColorString(styleValue.value);
+ }
+
+ return parseColorString(toValue(styleValue));
+};
+
+export type BackgroundType =
+ | "image"
+ | "linearGradient"
+ | "conicGradient"
+ | "radialGradient"
+ | "solid";
+
+const getGradientColorSignature = (color?: GradientStop["color"]) => {
+ if (color === undefined) {
+ return;
+ }
+ return toValue(color as StyleValue);
+};
+
+export const isSolidLinearGradient = (gradient: ParsedLinearGradient) => {
+ // Only consider it a solid gradient if there are exactly 2 stops
+ if (gradient.stops.length !== 2) {
+ return false;
+ }
+
+ // Fill in default positions (0% and 100%) for any missing positions
+ const normalized = fillMissingStopPositions(gradient);
+ const firstStop = normalized.stops[0];
+ const secondStop = normalized.stops[1];
+
+ // Check if both stops have the same color
+ const firstColor = getGradientColorSignature(firstStop?.color);
+ const secondColor = getGradientColorSignature(secondStop?.color);
+
+ if (
+ firstColor === undefined ||
+ secondColor === undefined ||
+ firstColor !== secondColor
+ ) {
+ return false;
+ }
+
+ // Check if first position is 0% and second position is 100%
+ const firstPosition = firstStop?.position;
+ const secondPosition = secondStop?.position;
+
+ const isFirstAt0 =
+ firstPosition?.type === "unit" &&
+ firstPosition.unit === "%" &&
+ firstPosition.value === 0;
+
+ const isSecondAt100 =
+ secondPosition?.type === "unit" &&
+ secondPosition.unit === "%" &&
+ secondPosition.value === 100;
+
+ return isFirstAt0 && isSecondAt100;
+};
+
+const formatSolidColorGradient = (styleValue: StyleValue | undefined) => {
+ const cssValue = styleValue === undefined ? "" : toValue(styleValue);
+ const gradientString = typeof cssValue === "string" ? cssValue : "";
+ const parsed =
+ gradientString.length > 0 ? parseAnyGradient(gradientString) : undefined;
+ const parsedLinear =
+ parsed?.type === "linear" ? parsed : createDefaultLinearGradient();
+ const source = parsedLinear;
+ const baseColor = source.stops[0]?.color ?? createDefaultStops()[0].color;
+ const solidStops: GradientStop[] = [
+ {
+ color: baseColor,
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ {
+ color: baseColor,
+ position: { type: "unit", unit: "%", value: 100 },
+ },
+ ];
+ return formatLinearGradient({
+ type: "linear",
+ angle: source.angle,
+ sideOrCorner: source.sideOrCorner,
+ stops: solidStops,
+ });
+};
+
+type GradientByType<T extends GradientType> = Extract<
+ ParsedGradient,
+ { type: T }
+>;
+
+// Cache for parsed gradients - avoids re-parsing the same gradient string
+const parsedGradientCache = new Map<string, ParsedGradient | undefined>();
+
+export const parseAnyGradient = (value: string): ParsedGradient | undefined => {
+ // Check cache first
+ if (parsedGradientCache.has(value)) {
+ return parsedGradientCache.get(value);
+ }
+
+ // Parse gradient
+ const parsed =
+ parseLinearGradient(value) ??
+ parseConicGradient(value) ??
+ parseRadialGradient(value);
+
+ // Cache the result
+ parsedGradientCache.set(value, parsed);
+
+ return parsed;
+};
+
+export const convertGradientToTarget = <Target extends GradientType>(
+ styleValue: StyleValue | undefined,
+ target: Target
+): GradientByType<Target> => {
+ const cssValue = styleValue === undefined ? "" : toValue(styleValue);
+ const gradientString = typeof cssValue === "string" ? cssValue : "";
+ const parsed =
+ gradientString.length > 0 ? parseAnyGradient(gradientString) : undefined;
+ const source = ensureGradientHasStops(
+ parsed ?? createDefaultGradient(target)
+ );
+ if (source.type === target) {
+ return source as GradientByType<Target>;
+ }
+ const template = createDefaultGradient(target);
+ const converted = {
+ ...template,
+ repeating: source.repeating,
+ stops: source.stops,
+ } satisfies ParsedGradient;
+ return converted as GradientByType<Target>;
+};
+
+export const formatGradientForType = (
+ styleValue: StyleValue | undefined,
+ target: Exclude<BackgroundType, "image">
+) => {
+ if (target === "solid") {
+ return formatSolidColorGradient(styleValue);
+ }
+ if (target === "linearGradient") {
+ const parsed = convertGradientToTarget(styleValue, "linear");
+ return formatLinearGradient(parsed);
+ }
+
+ if (target === "conicGradient") {
+ const parsed = convertGradientToTarget(styleValue, "conic");
+ return formatConicGradient(parsed);
+ }
+
+ const parsed = convertGradientToTarget(styleValue, "radial");
+ return formatRadialGradient(parsed);
+};
+
+export const detectBackgroundType = (
+ styleValue?: StyleValue
+): BackgroundType => {
+ if (styleValue === undefined) {
+ return "image";
+ }
+
+ if (styleValue.type === "image") {
+ return "image";
+ }
+
+ if (styleValue.type === "keyword") {
+ // The only allowed keyword for backgroundImage is none
+ return "image";
+ }
+
+ const cssValue = toValue(styleValue);
+ if (typeof cssValue === "string") {
+ // Use parseAnyGradient (which is cached) for all gradient detection
+ const parsed = parseAnyGradient(cssValue);
+
+ if (parsed !== undefined) {
+ if (parsed.type === "linear") {
+ return isSolidLinearGradient(parsed) ? "solid" : "linearGradient";
+ }
+ if (parsed.type === "conic") {
+ return "conicGradient";
+ }
+ if (parsed.type === "radial") {
+ return "radialGradient";
+ }
+ }
+
+ // Fallback checks for unparseable gradients
+ if (startsWithGradientFunction(cssValue, "conic")) {
+ return "conicGradient";
+ }
+
+ if (startsWithGradientFunction(cssValue, "radial")) {
+ return "radialGradient";
+ }
+
+ if (startsWithGradientFunction(cssValue, "linear")) {
+ return "linearGradient";
+ }
+ }
+
+ return "image";
+};
+
+export const getBackgroundStyleItem = (
+ styleDecl: ComputedStyleDecl,
+ index: number
+) => {
+ const repeatedItem = getRepeatedStyleItem(styleDecl, index);
+ if (repeatedItem !== undefined) {
+ return repeatedItem;
+ }
+
+ if (index > 0) {
+ return;
+ }
+
+ const cascaded = styleDecl.cascadedValue;
+ if (cascaded.type === "layers" || cascaded.type === "tuple") {
+ return cascaded.value[0];
+ }
+
+ return cascaded;
+};
diff --git a/apps/builder/app/builder/features/style-panel/sections/borders/border-color.tsx b/apps/builder/app/builder/features/style-panel/sections/borders/border-color.tsx
index 21563557bc..cdea476986 100644
--- a/apps/builder/app/builder/features/style-panel/sections/borders/border-color.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/borders/border-color.tsx
@@ -2,7 +2,7 @@ import { toValue, type CssProperty } from "@webstudio-is/css-engine";
import { Box, Grid } from "@webstudio-is/design-system";
import { rowCss } from "./utils";
import { PropertyLabel, PropertyValueTooltip } from "../../property-label";
-import { ColorPicker } from "../../shared/color-picker";
+import { ColorPickerControl } from "../../shared/color-picker";
import {
$availableColorVariables,
useComputedStyles,
@@ -49,7 +49,7 @@ export const BorderColor = () => {
isAdvanced={isAdvanced}
>
<div>
- <ColorPicker
+ <ColorPickerControl
disabled={isAdvanced}
currentColor={currentColor}
property={local.property}
diff --git a/apps/builder/app/builder/features/style-panel/shared/color-picker.tsx b/apps/builder/app/builder/features/style-panel/shared/color-picker.tsx
index c6e54878d1..9fb9936257 100644
--- a/apps/builder/app/builder/features/style-panel/shared/color-picker.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/color-picker.tsx
@@ -1,170 +1,14 @@
import { useState } from "react";
-import { colord, extend, type RgbaColor } from "colord";
-import namesPlugin from "colord/plugins/names";
-import { useDebouncedCallback } from "use-debounce";
-import { RgbaColorPicker } from "react-colorful";
-import { EyedropperIcon } from "@webstudio-is/icons";
-import type {
- StyleValue,
- KeywordValue,
- RgbValue,
- VarValue,
- CssProperty,
-} from "@webstudio-is/css-engine";
import {
- Popover,
- PopoverTrigger,
- PopoverContent,
- useDisableCanvasPointerEvents,
- css,
- InputField,
- IconButton,
- Grid,
-} from "@webstudio-is/design-system";
-import { toValue } from "@webstudio-is/css-engine";
-import { theme } from "@webstudio-is/design-system";
+ toValue,
+ type StyleValue,
+ type KeywordValue,
+ type VarValue,
+ type CssProperty,
+} from "@webstudio-is/css-engine";
+import { Box, ColorPickerPopover } from "@webstudio-is/design-system";
import { CssValueInput } from "./css-value-input";
import type { IntermediateStyleValue } from "./css-value-input/css-value-input";
-import { ColorThumb } from "./color-thumb";
-
-// To support color names
-extend([namesPlugin]);
-
-const colorfulStyles = css({
- ".react-colorful__pointer": {
- width: theme.spacing[10],
- height: theme.spacing[10],
- },
-});
-
-const colorResultToRgbValue = (rgb: RgbaColor): RgbValue => {
- return {
- type: "rgb",
- r: rgb.r,
- g: rgb.g,
- b: rgb.b,
- alpha: rgb.a ?? 1,
- };
-};
-
-const styleValueToRgbaColor = (
- value: StyleValue | IntermediateStyleValue
-): RgbaColor => {
- const color = colord(
- value.type === "intermediate" ? value.value : toValue(value)
- ).toRgb();
-
- return {
- r: color.r,
- g: color.g,
- b: color.b,
- a: color.a,
- };
-};
-
-const getEyeDropper = () => {
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- const Constructor = (window as any).EyeDropper;
- if (Constructor === undefined) {
- return;
- }
- const eyeDropper = new Constructor();
- return (callback: (rgb: string) => void) => {
- eyeDropper.open().then((result: { sRGBHex: string }) => {
- callback(result.sRGBHex);
- });
- };
-};
-
-const EyeDropper = ({ onChange }: { onChange: (rgb: string) => void }) => {
- const open = getEyeDropper();
- return (
- <IconButton
- disabled={open === undefined}
- onClick={() => {
- open?.(onChange);
- }}
- >
- <EyedropperIcon />
- </IconButton>
- );
-};
-
-const normalizeHex = (value: string) => {
- const trimmed = value.trim();
- const hex = trimmed.startsWith("#") ? trimmed : `#${trimmed}`;
- return hex;
-};
-
-/**
- * Keep content in separate component
- * to reset local state on outside changes
- * local state makes all changes less laggy
- */
-const ColorPickerPopoverContent = ({
- value,
- onChange,
- onChangeComplete,
-}: {
- value: StyleValue | IntermediateStyleValue;
- onChange: (value: StyleValue | undefined) => void;
- onChangeComplete: (value: StyleValue) => void;
-}) => {
- const [hex, setHex] = useState(() =>
- colord(styleValueToRgbaColor(value)).toHex()
- );
- const normalizedHex = normalizeHex(hex);
- const handleCompleteDebounced = useDebouncedCallback(
- (newValue: RgbValue) => onChangeComplete(newValue),
- 500
- );
- /**
- * By default, the color can be transparent, but if the user chooses a color from the picker,
- * we must set alpha = 1 otherwise all selected colors will be transparent.
- */
- const fixColor = (color: RgbaColor) => {
- if (value.type === "keyword" && value.value === "transparent") {
- color = { ...color, a: 1 };
- }
- return color;
- };
- return (
- <>
- <RgbaColorPicker
- className={colorfulStyles.toString()}
- color={colord(normalizedHex).toRgb()}
- onChange={(newRgb) => {
- const fixedRgb = fixColor(newRgb);
- setHex(colord(fixedRgb).toHex());
- const newValue = colorResultToRgbValue(fixedRgb);
- onChange(newValue);
- handleCompleteDebounced(newValue);
- }}
- />
- <Grid css={{ gridTemplateColumns: "auto 1fr" }} gap="1">
- <EyeDropper
- onChange={(newHex) => {
- setHex(newHex);
- const newValue = colorResultToRgbValue(colord(newHex).toRgb());
- onChangeComplete(newValue);
- }}
- />
- <InputField
- value={hex}
- onChange={(event) => {
- setHex(event.target.value);
- const color = colord(normalizeHex(event.target.value));
- if (color.isValid()) {
- const newValue = colorResultToRgbValue(color.toRgb());
- onChange(newValue);
- handleCompleteDebounced(newValue);
- }
- }}
- />
- </Grid>
- </>
- );
-};
type ColorPickerProps = {
onChange: (value: StyleValue) => void;
@@ -178,65 +22,7 @@ type ColorPickerProps = {
disabled?: boolean;
};
-export const ColorPopover = ({
- value,
- onChange,
- onChangeComplete,
-}: {
- value: StyleValue;
- onChange: (value: undefined | StyleValue) => void;
- onChangeComplete: (value: StyleValue) => void;
-}) => {
- const [displayColorPicker, setDisplayColorPicker] = useState(false);
- const { enableCanvasPointerEvents, disableCanvasPointerEvents } =
- useDisableCanvasPointerEvents();
-
- const handleOpenChange = (open: boolean) => {
- setDisplayColorPicker(open);
- if (open) {
- // Dragging over canvas iframe with CORS policies will lead to loosing events and getting stuck in mousedown state.
- disableCanvasPointerEvents();
- // User may drag outside of the color picker and that will select everything.
- document.body.style.userSelect = "none";
- return;
- }
-
- document.body.style.removeProperty("user-select");
- enableCanvasPointerEvents();
- };
-
- return (
- <Popover modal open={displayColorPicker} onOpenChange={handleOpenChange}>
- <PopoverTrigger
- asChild
- aria-label="Open color picker"
- onClick={() => setDisplayColorPicker((shown) => !shown)}
- >
- <ColorThumb
- color={styleValueToRgbaColor(value)}
- css={{ margin: theme.spacing[2] }}
- interactive={true}
- tabIndex={-1}
- />
- </PopoverTrigger>
- <PopoverContent
- css={{
- display: "grid",
- padding: theme.spacing[5],
- gap: theme.spacing[5],
- }}
- >
- <ColorPickerPopoverContent
- value={value}
- onChange={onChange}
- onChangeComplete={onChangeComplete}
- />
- </PopoverContent>
- </Popover>
- );
-};
-
-export const ColorPicker = ({
+export const ColorPickerControl = ({
value,
currentColor,
getOptions,
@@ -256,21 +42,23 @@ export const ColorPicker = ({
aria-disabled={disabled}
styleSource="default"
prefix={
- <ColorPopover
- value={currentColor}
- onChange={(styleValue) => {
- setIntermediateValue(styleValue);
- if (styleValue) {
- onChange(styleValue);
- } else {
- onAbort();
- }
- }}
- onChangeComplete={(value) => {
- setIntermediateValue(undefined);
- onChangeComplete(value);
- }}
- />
+ <Box css={{ paddingLeft: 2 }}>
+ <ColorPickerPopover
+ value={currentColor}
+ onChange={(styleValue) => {
+ setIntermediateValue(styleValue);
+ if (styleValue) {
+ onChange(styleValue);
+ } else {
+ onAbort();
+ }
+ }}
+ onChangeComplete={(value) => {
+ setIntermediateValue(undefined);
+ onChangeComplete(value);
+ }}
+ />
+ </Box>
}
showSuffix={false}
property={property}
diff --git a/apps/builder/app/builder/features/style-panel/shared/color-thumb.tsx b/apps/builder/app/builder/features/style-panel/shared/color-thumb.tsx
deleted file mode 100644
index 15a6d605a0..0000000000
--- a/apps/builder/app/builder/features/style-panel/shared/color-thumb.tsx
+++ /dev/null
@@ -1,94 +0,0 @@
-import { rawTheme, theme, css, type CSS } from "@webstudio-is/design-system";
-import { colord, type RgbaColor } from "colord";
-import { forwardRef, type ElementRef, type ComponentProps } from "react";
-import { clamp } from "~/shared/math-utils";
-
-const whiteColor: RgbaColor = { r: 255, g: 255, b: 255, a: 1 };
-const borderColorSwatch = colord(rawTheme.colors.borderColorSwatch).toRgb();
-const transparentColor: RgbaColor = { r: 0, g: 0, b: 0, a: 0 };
-
-const distance = (a: RgbaColor, b: RgbaColor) => {
- // Use Euclidian distance
- // If results are not good, lets switch to https://zschuessler.github.io/DeltaE/
- return Math.sqrt(
- Math.pow(a.r / 255 - b.r / 255, 2) +
- Math.pow(a.g / 255 - b.g / 255, 2) +
- Math.pow(a.b / 255 - b.b / 255, 2) +
- Math.pow(a.a - b.a, 2)
- );
-};
-
-// White color is invisible on white background, so we need to draw border
-// the more color is white the more border is visible
-const calcBorderColor = (color: RgbaColor) => {
- const distanceToStartDrawBorder = 0.15;
- const alpha = clamp(
- (distanceToStartDrawBorder - distance(whiteColor, color)) /
- distanceToStartDrawBorder,
- 0,
- 1
- );
- return colord(lerpColor(transparentColor, borderColorSwatch, alpha));
-};
-
-const lerp = (a: number, b: number, t: number) => {
- return a * (1 - t) + b * t;
-};
-
-const lerpColor = (a: RgbaColor, b: RgbaColor, t: number) => {
- return {
- r: lerp(a.r, b.r, t),
- g: lerp(a.g, b.g, t),
- b: lerp(a.b, b.b, t),
- a: lerp(a.a, b.a, t),
- };
-};
-
-const thumbStyle = css({
- display: "block",
- width: theme.spacing[9],
- height: theme.spacing[9],
- backgroundBlendMode: "difference",
- borderRadius: theme.borderRadius[2],
- borderWidth: 0,
- borderStyle: "solid",
- "&:focus-visible": {
- outline: `1px solid ${theme.colors.borderFocus}`,
- outlineOffset: 1,
- },
-});
-
-type Props = Omit<ComponentProps<"button" | "span">, "color"> & {
- interactive?: boolean;
- color?: RgbaColor;
- css?: CSS;
-};
-
-export const ColorThumb = forwardRef<ElementRef<"button">, Props>(
- ({ interactive, color = transparentColor, css, ...rest }, ref) => {
- const background =
- color === undefined || color.a < 1
- ? // Chessboard pattern 5x5
- `repeating-conic-gradient(rgba(0,0,0,0.22) 0% 25%, transparent 0% 50%) 0% 33.33% / 40% 40%, ${colord(color).toRgbString()}`
- : colord(color).toRgbString();
- const borderColor = calcBorderColor(color);
-
- const Component = interactive ? "button" : "span";
-
- return (
- <Component
- {...rest}
- ref={ref}
- style={{
- background,
- borderColor: borderColor.toRgbString(),
- // Border becomes visible when color is close to white so that the thumb is visible in the white input.
- borderWidth: borderColor.alpha() === 0 ? 0 : 1,
- }}
- className={thumbStyle({ css })}
- />
- );
- }
-);
-
-ColorThumb.displayName = "ColorThumb";
diff --git a/apps/builder/app/builder/features/style-panel/shared/css-fragment.tsx b/apps/builder/app/builder/features/style-panel/shared/css-fragment.tsx
index b5b937efd2..9f87003706 100644
--- a/apps/builder/app/builder/features/style-panel/shared/css-fragment.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/css-fragment.tsx
@@ -8,19 +8,21 @@ import {
type CompletionSource,
} from "@codemirror/autocomplete";
import { parseCss, shorthandProperties } from "@webstudio-is/css-data";
-import { css as style } from "@webstudio-is/design-system";
+import { css as style, type CSS } from "@webstudio-is/design-system";
import type { CssProperty, StyleValue } from "@webstudio-is/css-engine";
import {
EditorContent,
EditorDialog,
EditorDialogButton,
EditorDialogControl,
- getMinMaxHeightVars,
+ getCodeEditorCssVars,
} from "~/builder/shared/code-editor-base";
import { $availableVariables } from "./model";
type ShorthandProperty = (typeof shorthandProperties)[number];
+export { getCodeEditorCssVars };
+
export const parseCssFragment = (
css: string,
fallbacks: (CssProperty | ShorthandProperty)[]
@@ -71,7 +73,7 @@ const scopeCompletionSource: CompletionSource = (context) => {
const wrapperStyle = style({
position: "relative",
- ...getMinMaxHeightVars({ minHeight: "40px", maxHeight: "80px" }),
+ ...getCodeEditorCssVars({ minHeight: "3lh", maxHeight: "6lh" }),
});
export const CssFragmentEditorContent = ({
@@ -106,12 +108,14 @@ export const CssFragmentEditorContent = ({
export const CssFragmentEditor = ({
content,
onOpenChange,
+ css,
}: {
content: ReactNode;
onOpenChange?: (newOpen: boolean) => void;
+ css?: CSS;
}) => {
return (
- <div className={wrapperStyle()}>
+ <div className={wrapperStyle({ css })}>
<EditorDialogControl>
{content}
<EditorDialog
diff --git a/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input-container.tsx b/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input-container.tsx
index ae8dd8c56a..f1f435b4a4 100644
--- a/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input-container.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input-container.tsx
@@ -56,7 +56,7 @@ export const CssValueInputContainer = ({
}
}}
onChangeComplete={(event) => {
- onUpdate(event.value);
+ onUpdate(event.value, { isEphemeral: false });
setIntermediateValue(undefined);
onChangeComplete?.(event);
}}
diff --git a/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx b/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx
index 32e375a373..7098e69575 100644
--- a/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx
@@ -17,6 +17,7 @@ import {
Flex,
styled,
Text,
+ ColorThumb,
} from "@webstudio-is/design-system";
import type {
CssProperty,
@@ -51,7 +52,6 @@ import { convertUnits } from "./convert-units";
import { mergeRefs } from "@react-aria/utils";
import { composeEventHandlers } from "~/shared/event-utils";
import type { StyleValueSourceColor } from "~/shared/style-object-model";
-import { ColorThumb } from "../color-thumb";
import {
cssButtonDisplay,
isComplexValue,
@@ -651,7 +651,9 @@ export const CssValueInput = ({
// Probably no changes have been made at this point
// In that case we will call onAbort instead of onChangeComplete
if (props.intermediateValue === undefined) {
- onAbort();
+ if (props.value === undefined) {
+ onAbort();
+ }
return;
}
@@ -740,25 +742,14 @@ export const CssValueInput = ({
value.type === "unit" ? value.value : Number(value.value.trim());
const meta = { altKey: event.altKey, shiftKey: event.shiftKey };
- const hasMeta = meta.altKey || meta.shiftKey;
-
- if (hasMeta) {
- // @todo switch to using props.onChange instead of props.onChangeComplete
- // this will require modifying input-popover.tsx
- const newValue = {
- type: "unit" as const,
- value: handleNumericInputArrowKeys(inputValue, event),
- unit: value.unit,
- };
- onChangeComplete({ value: newValue, ...meta, type: "delta" });
- } else {
- props.onChange({
- type: "unit",
- value: handleNumericInputArrowKeys(inputValue, event),
- unit: value.unit,
- });
- }
+ const newValue = {
+ type: "unit" as const,
+ value: handleNumericInputArrowKeys(inputValue, event),
+ unit: value.unit,
+ };
+
+ onChangeComplete({ value: newValue, ...meta, type: "delta" });
event.preventDefault();
}
};
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.tsx
index 9f86f1c608..cdb2def4f1 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
@@ -1,4 +1,4 @@
-import { useMemo, type ComponentProps, type JSX } from "react";
+import { useMemo, type ComponentProps, type JSX, type ReactNode } from "react";
import type { RgbaColor } from "colord";
import {
toValue,
@@ -20,11 +20,11 @@ import {
toast,
useSortable,
FloatingPanel,
+ ColorThumb,
} from "@webstudio-is/design-system";
import { repeatUntil } from "~/shared/array-utils";
import type { ComputedStyleDecl } from "~/shared/style-object-model";
import { createBatchUpdate, type StyleUpdateOptions } from "./use-style-data";
-import { ColorThumb } from "./color-thumb";
const isRepeatedValue = (
styleValue: StyleValue
@@ -332,6 +332,16 @@ export const RepeatedStyle = (props: {
floatingPanelOffset?: ComponentProps<typeof FloatingPanel>["offset"];
renderThumbnail?: (index: number, primaryItem: StyleValue) => JSX.Element;
renderItemContent: (index: number, primaryItem: StyleValue) => JSX.Element;
+ renderItemButtons?: (
+ index: number,
+ primaryItem: StyleValue,
+ options: { isHidden: boolean; canBeChanged: boolean }
+ ) => ReactNode;
+ renderPanelTitleSuffix?: (
+ index: number,
+ primaryItem: StyleValue,
+ options: { isHidden: boolean; canBeChanged: boolean }
+ ) => ReactNode;
}) => {
const {
label,
@@ -340,6 +350,8 @@ export const RepeatedStyle = (props: {
renderThumbnail,
renderItemContent,
floatingPanelOffset,
+ renderItemButtons,
+ renderPanelTitleSuffix,
} = props;
// first property should describe the amount of layers or tuple items
const primaryValue = styles[0].cascadedValue;
@@ -385,11 +397,24 @@ export const RepeatedStyle = (props: {
const isHidden = isItemHidden(styles[0].cascadedValue, index);
const canBeChanged =
styles[0].cascadedValue.type === "var" ? index === 0 : true;
+ const customButtons = renderItemButtons?.(index, primaryItem, {
+ isHidden,
+ canBeChanged,
+ });
+ const panelTitleSuffix = renderPanelTitleSuffix?.(
+ index,
+ primaryItem,
+ {
+ isHidden,
+ canBeChanged,
+ }
+ );
return (
<FloatingPanel
key={index}
title={label}
content={renderItemContent(index, primaryItem)}
+ titleSuffix={panelTitleSuffix}
offset={floatingPanelOffset}
>
<CssValueListItem
@@ -405,6 +430,7 @@ export const RepeatedStyle = (props: {
}
buttons={
<>
+ {customButtons}
<SmallToggleButton
variant="normal"
pressed={isHidden}
diff --git a/apps/builder/app/builder/features/style-panel/shared/shadow-content.tsx b/apps/builder/app/builder/features/style-panel/shared/shadow-content.tsx
index cd256e6144..c01f2d57e1 100644
--- a/apps/builder/app/builder/features/style-panel/shared/shadow-content.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/shadow-content.tsx
@@ -40,7 +40,7 @@ import {
CssFragmentEditorContent,
parseCssFragment,
} from "./css-fragment";
-import { ColorPicker } from "./color-picker";
+import { ColorPickerControl } from "./color-picker";
import { $availableColorVariables, $availableUnitVariables } from "./model";
/*
@@ -328,7 +328,7 @@ export const ShadowContent = ({
label="Color"
description={shadowPropertySyntaxes[property].color}
/>
- <ColorPicker
+ <ColorPickerControl
property="color"
aria-disabled={disabledControls}
value={shadowValue.color ?? defaultColor}
diff --git a/apps/builder/app/builder/shared/client-settings/settings.ts b/apps/builder/app/builder/shared/client-settings/settings.ts
index cf09f9928b..1bb119926f 100644
--- a/apps/builder/app/builder/shared/client-settings/settings.ts
+++ b/apps/builder/app/builder/shared/client-settings/settings.ts
@@ -43,7 +43,9 @@ const write = (settings: Settings) => {
localStorage.setItem(namespace, JSON.stringify(settings));
};
-export const $settings = atom<Settings>(defaultSettings);
+const initialSettings = read();
+
+export const $settings = atom<Settings>(initialSettings);
export const setSetting = <Name extends keyof Settings>(
name: Name,
@@ -59,10 +61,5 @@ export const setSetting = <Name extends keyof Settings>(
};
export const getSetting = <Name extends keyof Settings>(name: Name) => {
- let settings = $settings.get();
- if (settings === defaultSettings) {
- settings = read();
- $settings.set(settings);
- }
- return settings[name];
+ return $settings.get()[name];
};
diff --git a/apps/builder/app/builder/shared/code-editor-base.tsx b/apps/builder/app/builder/shared/code-editor-base.tsx
index 7086a61698..dc730fe33f 100644
--- a/apps/builder/app/builder/shared/code-editor-base.tsx
+++ b/apps/builder/app/builder/shared/code-editor-base.tsx
@@ -55,7 +55,7 @@ const minHeightVar = "--ws-code-editor-min-height";
const maxHeightVar = "--ws-code-editor-max-height";
const maximizeIconVisibilityVar = "--ws-code-editor-maximize-icon-visibility";
-export const getMinMaxHeightVars = ({
+export const getCodeEditorCssVars = ({
minHeight,
maxHeight,
}: {
diff --git a/apps/builder/app/builder/shared/code-editor.tsx b/apps/builder/app/builder/shared/code-editor.tsx
index b9ef1b4fe8..b703c8f8b9 100644
--- a/apps/builder/app/builder/shared/code-editor.tsx
+++ b/apps/builder/app/builder/shared/code-editor.tsx
@@ -33,7 +33,7 @@ import {
EditorDialogButton,
EditorDialogControl,
foldGutterExtension,
- getMinMaxHeightVars,
+ getCodeEditorCssVars,
} from "./code-editor-base";
import { cssCompletionSource, cssLanguage } from "@codemirror/lang-css";
@@ -42,8 +42,8 @@ const wrapperStyle = css({
variants: {
size: {
- default: getMinMaxHeightVars({ minHeight: "160px", maxHeight: "320px" }),
- small: getMinMaxHeightVars({ minHeight: "16px", maxHeight: "120px" }),
+ default: getCodeEditorCssVars({ minHeight: "160px", maxHeight: "320px" }),
+ small: getCodeEditorCssVars({ minHeight: "16px", maxHeight: "120px" }),
},
},
defaultVariants: {
diff --git a/apps/builder/app/builder/shared/collapsible-section.tsx b/apps/builder/app/builder/shared/collapsible-section.tsx
index 1d614e1b98..56dbd0b179 100644
--- a/apps/builder/app/builder/shared/collapsible-section.tsx
+++ b/apps/builder/app/builder/shared/collapsible-section.tsx
@@ -131,7 +131,7 @@ export const CollapsibleSectionRoot = ({
onOpenChange,
}: CollapsibleSectionBaseProps) => {
return (
- <Collapsible.Root open={isOpen} onOpenChange={onOpenChange}>
+ <Collapsible.Root defaultOpen open={isOpen} onOpenChange={onOpenChange}>
<Collapsible.Trigger asChild>
{trigger ?? (
<SectionTitle>
diff --git a/apps/builder/app/builder/shared/css-editor/css-editor.tsx b/apps/builder/app/builder/shared/css-editor/css-editor.tsx
index 3c42a58803..c726c57edb 100644
--- a/apps/builder/app/builder/shared/css-editor/css-editor.tsx
+++ b/apps/builder/app/builder/shared/css-editor/css-editor.tsx
@@ -35,7 +35,7 @@ import {
import { CssValueInputContainer } from "../../features/style-panel/shared/css-value-input";
import { $availableVariables } from "../../features/style-panel/shared/model";
import { PropertyInfo } from "../../features/style-panel/property-label";
-import { ColorPopover } from "../../features/style-panel/shared/color-picker";
+import { ColorPickerPopover } from "@webstudio-is/design-system";
import { useClientSupports } from "~/shared/client-supports";
import { CssEditorContextMenu, copyAttribute } from "./css-editor-context-menu";
import { AddStyleInput } from "./add-style-input";
@@ -142,7 +142,7 @@ const AdvancedPropertyValue = ({
fieldSizing="content"
prefix={
isColor && (
- <ColorPopover
+ <ColorPickerPopover
value={styleDecl.usedValue}
onChange={(styleValue) => {
const options = { isEphemeral: true, listed: true };
diff --git a/apps/builder/package.json b/apps/builder/package.json
index beb71c1af1..2389c26d74 100644
--- a/apps/builder/package.json
+++ b/apps/builder/package.json
@@ -107,7 +107,6 @@
"picocolors": "^1.1.1",
"pretty-bytes": "^6.1.1",
"react": "18.3.0-canary-14898b6a9-20240318",
- "react-colorful": "^5.6.1",
"react-dom": "18.3.0-canary-14898b6a9-20240318",
"react-error-boundary": "^5.0.0",
"remix-auth": "^3.7.0",
diff --git a/packages/css-data/src/property-parsers/conic-gradient.test.ts b/packages/css-data/src/property-parsers/conic-gradient.test.ts
new file mode 100644
index 0000000000..783981df49
--- /dev/null
+++ b/packages/css-data/src/property-parsers/conic-gradient.test.ts
@@ -0,0 +1,318 @@
+import { describe, expect, test } from "vitest";
+import { parseConicGradient, formatConicGradient } from "./conic-gradient";
+
+type ConicGradient = NonNullable<ReturnType<typeof parseConicGradient>>;
+const conic = (gradient: Omit<ConicGradient, "type">): ConicGradient => ({
+ type: "conic",
+ ...gradient,
+});
+
+describe("parse conic-gradient", () => {
+ test("parses gradient without angle or position", () => {
+ expect(
+ parseConicGradient("conic-gradient(red 0%, blue 50%, yellow 100%)")
+ ).toEqual(
+ conic({
+ angle: undefined,
+ position: undefined,
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 0 },
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 0, g: 0, b: 255, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 50 },
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 255, g: 255, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 100 },
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ });
+
+ test("parses gradient with angle", () => {
+ expect(
+ parseConicGradient("conic-gradient(from 135deg, orange 0%, cyan 100%)")
+ ).toEqual(
+ conic({
+ angle: { type: "unit", unit: "deg", value: 135 },
+ position: undefined,
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 165, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 0 },
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 0, g: 255, b: 255, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 100 },
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ });
+
+ test("parses gradient with position", () => {
+ expect(
+ parseConicGradient("conic-gradient(at center, red 0%, blue 100%)")
+ ).toEqual(
+ conic({
+ angle: undefined,
+ position: "center",
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 0 },
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 0, g: 0, b: 255, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 100 },
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ });
+
+ test("parses gradient with angle positions", () => {
+ expect(
+ parseConicGradient(
+ "conic-gradient(from 0deg at 50% 50%, rgba(255,126,95,1) 0deg, rgba(254,180,123,1) 120deg, rgba(134,168,231,1) 240deg, rgba(255,126,95,1) 360deg)"
+ )
+ ).toEqual(
+ conic({
+ angle: { type: "unit", unit: "deg", value: 0 },
+ position: "50% 50%",
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 126, b: 95, alpha: 1 },
+ position: { type: "unit", unit: "deg", value: 0 },
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 254, g: 180, b: 123, alpha: 1 },
+ position: { type: "unit", unit: "deg", value: 120 },
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 134, g: 168, b: 231, alpha: 1 },
+ position: { type: "unit", unit: "deg", value: 240 },
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 255, g: 126, b: 95, alpha: 1 },
+ position: { type: "unit", unit: "deg", value: 360 },
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ });
+
+ test("parses repeating conic gradient", () => {
+ const parsed = parseConicGradient(
+ "repeating-conic-gradient(red 0% 25%, blue 50% 75%)"
+ );
+ expect(parsed).toEqual(
+ conic({
+ angle: undefined,
+ position: undefined,
+ repeating: true,
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 0 },
+ hint: { type: "unit", unit: "%", value: 25 },
+ },
+ {
+ color: { type: "rgb", r: 0, g: 0, b: 255, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 50 },
+ hint: { type: "unit", unit: "%", value: 75 },
+ },
+ ],
+ })
+ );
+ expect(formatConicGradient(parsed!)).toBe(
+ "repeating-conic-gradient(rgba(255, 0, 0, 1) 0% 25%, rgba(0, 0, 255, 1) 50% 75%)"
+ );
+ });
+
+ test("parses gradient with css variables", () => {
+ expect(
+ parseConicGradient(
+ "conic-gradient(from var(--angle, 45deg), var(--start-color, red) var(--start, 0%) var(--start-hint, 5%), var(--end-color) var(--end))"
+ )
+ ).toEqual(
+ conic({
+ angle: {
+ type: "var",
+ value: "angle",
+ fallback: { type: "unparsed", value: "45deg" },
+ },
+ position: undefined,
+ stops: [
+ {
+ color: {
+ type: "var",
+ value: "start-color",
+ fallback: { type: "unparsed", value: "red" },
+ },
+ position: {
+ type: "var",
+ value: "start",
+ fallback: { type: "unparsed", value: "0%" },
+ },
+ hint: {
+ type: "var",
+ value: "start-hint",
+ fallback: { type: "unparsed", value: "5%" },
+ },
+ },
+ {
+ color: { type: "var", value: "end-color" },
+ position: { type: "var", value: "end" },
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ });
+
+ test("parses gradient with variable angle without fallback", () => {
+ expect(
+ parseConicGradient("conic-gradient(from var(--angle), red 0%, blue 100%)")
+ ).toEqual(
+ conic({
+ angle: {
+ type: "var",
+ value: "angle",
+ },
+ position: undefined,
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 0 },
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 0, g: 0, b: 255, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 100 },
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ });
+
+ test("parses gradient with variable positions and hints", () => {
+ const parsed = parseConicGradient(
+ "conic-gradient(red var(--start, 10%) var(--hint, 20%), blue var(--end))"
+ );
+ expect(parsed).toEqual(
+ conic({
+ angle: undefined,
+ position: undefined,
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: {
+ type: "var",
+ value: "start",
+ fallback: { type: "unparsed", value: "10%" },
+ },
+ hint: {
+ type: "var",
+ value: "hint",
+ fallback: { type: "unparsed", value: "20%" },
+ },
+ },
+ {
+ color: { type: "rgb", r: 0, g: 0, b: 255, alpha: 1 },
+ position: { type: "var", value: "end" },
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ expect(formatConicGradient(parsed!)).toBe(
+ "conic-gradient(rgba(255, 0, 0, 1) var(--start, 10%) var(--hint, 20%), rgba(0, 0, 255, 1) var(--end))"
+ );
+ });
+
+ test("parses keyword colors", () => {
+ const parsed = parseConicGradient(
+ "conic-gradient(green 0%, blue 50%, yellow 100%)"
+ );
+ expect(parsed).toEqual(
+ conic({
+ angle: undefined,
+ position: undefined,
+ stops: [
+ {
+ color: { type: "rgb", r: 0, g: 128, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 0 },
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 0, g: 0, b: 255, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 50 },
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 255, g: 255, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 100 },
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ expect(formatConicGradient(parsed!)).toBe(
+ "conic-gradient(rgba(0, 128, 0, 1) 0%, rgba(0, 0, 255, 1) 50%, rgba(255, 255, 0, 1) 100%)"
+ );
+ });
+
+ test("parses gradient with rgb colors", () => {
+ const parsed = parseConicGradient(
+ "conic-gradient(rgb(255, 0, 0), rgb(0, 255, 0), rgb(0, 0, 255))"
+ );
+ expect(parsed).toEqual(
+ conic({
+ angle: undefined,
+ position: undefined,
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: undefined,
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 0, g: 255, b: 0, alpha: 1 },
+ position: undefined,
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 0, g: 0, b: 255, alpha: 1 },
+ position: undefined,
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ expect(formatConicGradient(parsed!)).toBe(
+ "conic-gradient(rgba(255, 0, 0, 1), rgba(0, 255, 0, 1), rgba(0, 0, 255, 1))"
+ );
+ });
+
+ test("returns undefined for invalid input", () => {
+ expect(parseConicGradient("conic-gradient()")).toBeUndefined();
+ expect(parseConicGradient("conic-gradient(var())")).toBeUndefined();
+ });
+});
diff --git a/packages/css-data/src/property-parsers/conic-gradient.ts b/packages/css-data/src/property-parsers/conic-gradient.ts
new file mode 100644
index 0000000000..a94ca9199e
--- /dev/null
+++ b/packages/css-data/src/property-parsers/conic-gradient.ts
@@ -0,0 +1,197 @@
+import * as csstree from "css-tree";
+import { cssTryParseValue } from "../parse-css-value";
+import {
+ type UnitValue,
+ toValue,
+ type VarValue,
+} from "@webstudio-is/css-engine";
+import {
+ getColor,
+ isAngleUnit,
+ isColorStop,
+ mapLengthPercentageOrVar,
+ formatGradientStops,
+ normalizeRepeatingGradient,
+ forEachGradientParts,
+} from "./gradient-utils";
+import type { GradientStop, ParsedConicGradient } from "./types";
+
+type GradientPartResult =
+ | { type: "angle"; value: UnitValue | VarValue }
+ | { type: "position"; value: string }
+ | { type: "stop"; value: GradientStop }
+ | { type: "hint"; value: GradientStop["hint"] };
+
+const isIdentifier = (node: csstree.CssNode, value: string) =>
+ node.type === "Identifier" && node.name.toLowerCase() === value;
+
+const parseGradientPart = (
+ nodes: csstree.CssNode[]
+): GradientPartResult | undefined => {
+ const filtered = nodes.filter((node) => node.type !== "WhiteSpace");
+ if (filtered.length === 0) {
+ return;
+ }
+
+ if (isIdentifier(filtered[0], "from")) {
+ const angleNode = filtered[1];
+ const mapped = mapLengthPercentageOrVar(angleNode);
+ if (
+ mapped !== undefined &&
+ ((mapped.type === "unit" && isAngleUnit(mapped.unit)) ||
+ mapped.type === "var")
+ ) {
+ return { type: "angle", value: mapped };
+ }
+ return;
+ }
+
+ if (isIdentifier(filtered[0], "at")) {
+ const css = filtered
+ .slice(1)
+ .map((item) => csstree.generate(item))
+ .join(" ")
+ .trim();
+ if (css.length > 0) {
+ return { type: "position", value: css };
+ }
+ return;
+ }
+
+ const colorNode = filtered.find(isColorStop);
+ if (colorNode !== undefined) {
+ const color = getColor(colorNode);
+ const colorIndex = filtered.indexOf(colorNode);
+ const positionNode = filtered[colorIndex + 1];
+ const hintNode = filtered[colorIndex + 2];
+
+ const stop: GradientStop = {
+ color,
+ position: mapLengthPercentageOrVar(positionNode),
+ hint: mapLengthPercentageOrVar(hintNode),
+ };
+
+ return { type: "stop", value: stop };
+ }
+
+ const hint = mapLengthPercentageOrVar(filtered[0]);
+ if (hint !== undefined) {
+ return { type: "hint", value: hint };
+ }
+};
+
+export const parseConicGradient = (
+ gradient: string
+): ParsedConicGradient | undefined => {
+ const { normalized: normalizedGradient, isRepeating } =
+ normalizeRepeatingGradient(
+ gradient,
+ "repeating-conic-gradient",
+ "conic-gradient"
+ );
+
+ const ast = cssTryParseValue(normalizedGradient);
+ if (ast === undefined) {
+ return;
+ }
+
+ // css-tree grammar doesn't allow angles in color stops, so we fall back to
+ // manual parsing even when the built-in matcher rejects the value.
+ csstree.lexer.match(
+ "conic-gradient( [ from <angle> ]? [ at <position> ]? , <color-stop-list> )",
+ ast
+ );
+
+ let angle: UnitValue | VarValue | undefined;
+ let position: string | undefined;
+ const stops: GradientStop[] = [];
+
+ forEachGradientParts(ast, "conic-gradient", (gradientParts) => {
+ const filteredParts = gradientParts.filter(
+ (node) => node.type !== "WhiteSpace"
+ );
+ const containsStop = filteredParts.some(isColorStop);
+
+ let handledDirective = false;
+ const fromIndex = filteredParts.findIndex((node) =>
+ isIdentifier(node, "from")
+ );
+ if (fromIndex !== -1) {
+ const angleNode = filteredParts[fromIndex + 1];
+ const mapped = mapLengthPercentageOrVar(angleNode);
+ if (
+ mapped !== undefined &&
+ ((mapped.type === "unit" && isAngleUnit(mapped.unit)) ||
+ mapped.type === "var")
+ ) {
+ angle = mapped;
+ handledDirective = true;
+ }
+ }
+
+ const atIndex = filteredParts.findIndex((node) => isIdentifier(node, "at"));
+ if (atIndex !== -1) {
+ const css = filteredParts
+ .slice(atIndex + 1)
+ .map((item) => csstree.generate(item))
+ .join(" ")
+ .trim();
+ if (css.length > 0) {
+ position = css;
+ handledDirective = true;
+ }
+ }
+
+ if (handledDirective && containsStop === false) {
+ return;
+ }
+
+ const parsedPart = parseGradientPart(filteredParts);
+ if (parsedPart === undefined) {
+ return;
+ }
+ if (parsedPart.type === "angle") {
+ angle = parsedPart.value;
+ } else if (parsedPart.type === "position") {
+ position = parsedPart.value;
+ } else if (parsedPart.type === "stop") {
+ stops.push(parsedPart.value);
+ } else if (parsedPart.type === "hint") {
+ stops.push({ hint: parsedPart.value });
+ }
+ });
+
+ if (stops.length === 0) {
+ return;
+ }
+
+ const parsed: ParsedConicGradient = {
+ type: "conic",
+ angle,
+ position,
+ stops,
+ };
+ if (isRepeating) {
+ parsed.repeating = true;
+ }
+
+ return parsed;
+};
+
+export const formatConicGradient = (parsed: ParsedConicGradient): string => {
+ const segments: string[] = [];
+ if (parsed.angle) {
+ segments.push(`from ${toValue(parsed.angle)}`);
+ }
+ if (parsed.position) {
+ segments.push(`at ${parsed.position}`);
+ }
+
+ const stops = formatGradientStops(parsed.stops);
+
+ const functionName =
+ parsed.repeating === true ? "repeating-conic-gradient" : "conic-gradient";
+ const prefix = segments.length > 0 ? `${segments.join(" ")}, ` : "";
+
+ return `${functionName}(${prefix}${stops})`;
+};
diff --git a/packages/css-data/src/property-parsers/gradient-utils.ts b/packages/css-data/src/property-parsers/gradient-utils.ts
new file mode 100644
index 0000000000..198160b034
--- /dev/null
+++ b/packages/css-data/src/property-parsers/gradient-utils.ts
@@ -0,0 +1,200 @@
+import * as csstree from "css-tree";
+import { parseCssValue } from "../parse-css-value";
+import {
+ type UnitValue,
+ type Unit,
+ type VarValue,
+ toValue,
+} from "@webstudio-is/css-engine";
+import { colord, extend } from "colord";
+import namesPlugin from "colord/plugins/names";
+import type { GradientColorValue, GradientStop } from "./types";
+
+extend([namesPlugin]);
+
+export const angleUnitIdentifiers = ["deg", "grad", "rad", "turn"] as const;
+const angleUnitSet = new Set<string>(angleUnitIdentifiers);
+
+export const isAngleUnit = (unit: string): boolean => angleUnitSet.has(unit);
+
+export const isAngleDimension = (
+ node: csstree.CssNode
+): node is csstree.Dimension =>
+ node.type === "Dimension" && isAngleUnit(node.unit);
+
+export const isAngleLikeFallback = (
+ fallback: VarValue["fallback"]
+): boolean => {
+ if (fallback === undefined) {
+ return false;
+ }
+
+ if (fallback.type === "unit") {
+ return isAngleUnit(fallback.unit);
+ }
+
+ if (fallback.type === "keyword") {
+ const normalized = fallback.value.trim().toLowerCase();
+ return normalized.startsWith("to ");
+ }
+
+ if (fallback.type === "unparsed") {
+ const normalized = fallback.value.trim().toLowerCase();
+ if (normalized.startsWith("to ")) {
+ return true;
+ }
+ return angleUnitIdentifiers.some((unit) => normalized.endsWith(unit));
+ }
+
+ return false;
+};
+
+export const isVarAngle = (value: VarValue): boolean => {
+ if (isAngleLikeFallback(value.fallback)) {
+ return true;
+ }
+
+ const name = value.value.toLowerCase();
+ return (
+ name.includes("angle") || name.includes("direction") || name.includes("deg")
+ );
+};
+
+export const mapLengthPercentageOrVar = (
+ node?: csstree.CssNode
+): UnitValue | VarValue | undefined => {
+ if (node === undefined) {
+ return;
+ }
+
+ if (node.type === "Percentage" || node.type === "Dimension") {
+ return {
+ type: "unit",
+ value: Number.parseFloat(node.value),
+ unit: node.type === "Percentage" ? "%" : (node.unit as Unit),
+ } satisfies UnitValue;
+ }
+
+ if (node.type === "Number") {
+ return {
+ type: "unit",
+ value: Number.parseFloat(node.value),
+ unit: "number",
+ } satisfies UnitValue;
+ }
+
+ if (node.type === "Function" && node.name === "var") {
+ const css = csstree.generate(node).trim();
+ if (css.length === 0) {
+ return;
+ }
+ const parsed = parseCssValue("margin-left", css);
+ if (parsed.type === "var") {
+ return parsed;
+ }
+ if (parsed.type === "unit") {
+ return parsed;
+ }
+ }
+};
+
+export const getColor = (
+ node: csstree.CssNode
+): GradientColorValue | undefined => {
+ if (
+ node.type !== "Function" &&
+ node.type !== "Identifier" &&
+ node.type !== "Hash"
+ ) {
+ return;
+ }
+
+ const css = csstree.generate(node).trim();
+ if (css.length === 0) {
+ return;
+ }
+
+ const parsed = parseCssValue("color", css);
+ if (parsed.type === "rgb" || parsed.type === "var") {
+ return parsed;
+ }
+ if (parsed.type === "keyword") {
+ const color = colord(parsed.value);
+ if (color.isValid()) {
+ const { r, g, b, a } = color.toRgb();
+ return {
+ type: "rgb",
+ r,
+ g,
+ b,
+ alpha: a,
+ } satisfies GradientColorValue;
+ }
+ }
+};
+
+export const isColorStop = (node: csstree.CssNode): boolean =>
+ getColor(node) !== undefined;
+
+export const formatGradientStops = (stops: GradientStop[]): string =>
+ stops
+ .map((stop) => {
+ let result = toValue(stop.color);
+ if (stop.position) {
+ result += ` ${toValue(stop.position)}`;
+ }
+ if (stop.hint) {
+ result += ` ${toValue(stop.hint)}`;
+ }
+ return result;
+ })
+ .join(", ");
+
+export const normalizeRepeatingGradient = (
+ gradient: string,
+ repeatingName: string,
+ baseName: string
+): {
+ normalized: string;
+ isRepeating: boolean;
+} => {
+ const pattern = new RegExp(`^(\\s*)${repeatingName}`, "i");
+ const normalized = gradient.replace(
+ pattern,
+ (_match, leadingWhitespace: string) => `${leadingWhitespace}${baseName}`
+ );
+ return {
+ normalized,
+ isRepeating: normalized !== gradient,
+ };
+};
+
+export const forEachGradientParts = (
+ ast: csstree.CssNode,
+ functionName: string,
+ callback: (parts: csstree.CssNode[]) => void
+): void => {
+ csstree.walk(ast, (node) => {
+ if (node.type !== "Function" || node.name !== functionName) {
+ return;
+ }
+
+ let gradientParts: csstree.CssNode[] = [];
+ for (const item of node.children) {
+ if (item.type !== "Operator") {
+ gradientParts.push(item);
+ }
+
+ const isSeparator =
+ (item.type === "Operator" && item.value === ",") ||
+ node.children.last === item;
+
+ if (isSeparator === false) {
+ continue;
+ }
+
+ callback(gradientParts);
+ gradientParts = [];
+ }
+ });
+};
diff --git a/packages/css-data/src/property-parsers/index.ts b/packages/css-data/src/property-parsers/index.ts
index a0961be175..7d33f13570 100644
--- a/packages/css-data/src/property-parsers/index.ts
+++ b/packages/css-data/src/property-parsers/index.ts
@@ -1 +1,4 @@
export * from "./linear-gradient";
+export * from "./conic-gradient";
+export * from "./radial-gradient";
+export * from "./types";
diff --git a/packages/css-data/src/property-parsers/linear-gradient.test.ts b/packages/css-data/src/property-parsers/linear-gradient.test.ts
index 8ec6a193ad..0536c30d6c 100644
--- a/packages/css-data/src/property-parsers/linear-gradient.test.ts
+++ b/packages/css-data/src/property-parsers/linear-gradient.test.ts
@@ -1,54 +1,61 @@
import { test, describe, expect } from "vitest";
-import {
- parseLinearGradient,
- reconstructLinearGradient,
-} from "./linear-gradient";
+import { parseLinearGradient, formatLinearGradient } from "./linear-gradient";
+
+type LinearGradient = NonNullable<ReturnType<typeof parseLinearGradient>>;
+const linear = (gradient: Omit<LinearGradient, "type">): LinearGradient => ({
+ type: "linear",
+ ...gradient,
+});
describe("parses linear-gradient", () => {
test("parses gradient without angle, sides and color-stops", () => {
- expect(parseLinearGradient("linear-gradient(red, blue, yellow)")).toEqual({
- angle: undefined,
- sideOrCorner: undefined,
- stops: [
- {
- color: { alpha: 1, b: 0, g: 0, r: 255, type: "rgb" },
- hint: undefined,
- position: undefined,
- },
- {
- color: { alpha: 1, b: 255, g: 0, r: 0, type: "rgb" },
- hint: undefined,
- position: undefined,
- },
- {
- color: { alpha: 1, b: 0, g: 255, r: 255, type: "rgb" },
- hint: undefined,
- position: undefined,
- },
- ],
- });
+ expect(parseLinearGradient("linear-gradient(red, blue, yellow)")).toEqual(
+ linear({
+ angle: undefined,
+ sideOrCorner: undefined,
+ stops: [
+ {
+ color: { alpha: 1, b: 0, g: 0, r: 255, type: "rgb" },
+ hint: undefined,
+ position: undefined,
+ },
+ {
+ color: { alpha: 1, b: 255, g: 0, r: 0, type: "rgb" },
+ hint: undefined,
+ position: undefined,
+ },
+ {
+ color: { alpha: 1, b: 0, g: 255, r: 255, type: "rgb" },
+ hint: undefined,
+ position: undefined,
+ },
+ ],
+ })
+ );
});
test("parses linear-gradient with angle and color-stops", () => {
expect(
parseLinearGradient("linear-gradient(135deg, orange 60% 20%, 40%, cyan)")
- ).toEqual({
- angle: { type: "unit", unit: "deg", value: 135 },
- sideOrCorner: undefined,
- stops: [
- {
- color: { alpha: 1, b: 0, g: 165, r: 255, type: "rgb" },
- hint: { type: "unit", unit: "%", value: 20 },
- position: { type: "unit", unit: "%", value: 60 },
- },
- { hint: { type: "unit", unit: "%", value: 40 } },
- {
- color: { alpha: 1, b: 255, g: 255, r: 0, type: "rgb" },
- hint: undefined,
- position: undefined,
- },
- ],
- });
+ ).toEqual(
+ linear({
+ angle: { type: "unit", unit: "deg", value: 135 },
+ sideOrCorner: undefined,
+ stops: [
+ {
+ color: { alpha: 1, b: 0, g: 165, r: 255, type: "rgb" },
+ hint: { type: "unit", unit: "%", value: 20 },
+ position: { type: "unit", unit: "%", value: 60 },
+ },
+ { hint: { type: "unit", unit: "%", value: 40 } },
+ {
+ color: { alpha: 1, b: 255, g: 255, r: 0, type: "rgb" },
+ hint: undefined,
+ position: undefined,
+ },
+ ],
+ })
+ );
});
test("parses linear-gradient with side-or-corer and multiple colors without stops", () => {
@@ -56,32 +63,34 @@ describe("parses linear-gradient", () => {
parseLinearGradient(
"linear-gradient(to top right, orange, yellow, blue, green)"
)
- ).toEqual({
- angle: undefined,
- sideOrCorner: { type: "keyword", value: "to top right" },
- stops: [
- {
- color: { alpha: 1, b: 0, g: 165, r: 255, type: "rgb" },
- hint: undefined,
- position: undefined,
- },
- {
- color: { alpha: 1, b: 0, g: 255, r: 255, type: "rgb" },
- hint: undefined,
- position: undefined,
- },
- {
- color: { alpha: 1, b: 255, g: 0, r: 0, type: "rgb" },
- hint: undefined,
- position: undefined,
- },
- {
- color: { alpha: 1, b: 0, g: 128, r: 0, type: "rgb" },
- hint: undefined,
- position: undefined,
- },
- ],
- });
+ ).toEqual(
+ linear({
+ angle: undefined,
+ sideOrCorner: { type: "keyword", value: "to top right" },
+ stops: [
+ {
+ color: { alpha: 1, b: 0, g: 165, r: 255, type: "rgb" },
+ hint: undefined,
+ position: undefined,
+ },
+ {
+ color: { alpha: 1, b: 0, g: 255, r: 255, type: "rgb" },
+ hint: undefined,
+ position: undefined,
+ },
+ {
+ color: { alpha: 1, b: 255, g: 0, r: 0, type: "rgb" },
+ hint: undefined,
+ position: undefined,
+ },
+ {
+ color: { alpha: 1, b: 0, g: 128, r: 0, type: "rgb" },
+ hint: undefined,
+ position: undefined,
+ },
+ ],
+ })
+ );
});
test("parses linear-gradient with multiple angles and color-stops", () => {
@@ -89,37 +98,39 @@ describe("parses linear-gradient", () => {
parseLinearGradient(
"linear-gradient(to right, red 20%, orange 20% 40%, yellow 40% 60%, green 60% 80%, blue 80% )"
)
- ).toEqual({
- angle: undefined,
- sideOrCorner: { type: "keyword", value: "to right" },
- stops: [
- {
- color: { alpha: 1, b: 0, g: 0, r: 255, type: "rgb" },
- hint: undefined,
- position: { type: "unit", unit: "%", value: 20 },
- },
- {
- color: { alpha: 1, b: 0, g: 165, r: 255, type: "rgb" },
- hint: { type: "unit", unit: "%", value: 40 },
- position: { type: "unit", unit: "%", value: 20 },
- },
- {
- color: { alpha: 1, b: 0, g: 255, r: 255, type: "rgb" },
- hint: { type: "unit", unit: "%", value: 60 },
- position: { type: "unit", unit: "%", value: 40 },
- },
- {
- color: { alpha: 1, b: 0, g: 128, r: 0, type: "rgb" },
- hint: { type: "unit", unit: "%", value: 80 },
- position: { type: "unit", unit: "%", value: 60 },
- },
- {
- color: { alpha: 1, b: 255, g: 0, r: 0, type: "rgb" },
- hint: undefined,
- position: { type: "unit", unit: "%", value: 80 },
- },
- ],
- });
+ ).toEqual(
+ linear({
+ angle: undefined,
+ sideOrCorner: { type: "keyword", value: "to right" },
+ stops: [
+ {
+ color: { alpha: 1, b: 0, g: 0, r: 255, type: "rgb" },
+ hint: undefined,
+ position: { type: "unit", unit: "%", value: 20 },
+ },
+ {
+ color: { alpha: 1, b: 0, g: 165, r: 255, type: "rgb" },
+ hint: { type: "unit", unit: "%", value: 40 },
+ position: { type: "unit", unit: "%", value: 20 },
+ },
+ {
+ color: { alpha: 1, b: 0, g: 255, r: 255, type: "rgb" },
+ hint: { type: "unit", unit: "%", value: 60 },
+ position: { type: "unit", unit: "%", value: 40 },
+ },
+ {
+ color: { alpha: 1, b: 0, g: 128, r: 0, type: "rgb" },
+ hint: { type: "unit", unit: "%", value: 80 },
+ position: { type: "unit", unit: "%", value: 60 },
+ },
+ {
+ color: { alpha: 1, b: 255, g: 0, r: 0, type: "rgb" },
+ hint: undefined,
+ position: { type: "unit", unit: "%", value: 80 },
+ },
+ ],
+ })
+ );
});
test("parses linear-gradient with rgb values", () => {
@@ -130,8 +141,248 @@ describe("parses linear-gradient", () => {
throw new Error("parsed is undefined");
}
- expect(reconstructLinearGradient(parsed)).toEqual(
+ expect(formatLinearGradient(parsed)).toEqual(
"linear-gradient(rgba(255, 0, 0, 1), rgba(0, 255, 0, 1), rgba(0, 0, 255, 1))"
);
});
+
+ test("parses repeating-linear-gradient", () => {
+ const parsed = parseLinearGradient("repeating-linear-gradient(red, blue)");
+ if (parsed === undefined) {
+ throw new Error("parsed is undefined");
+ }
+
+ expect(parsed.repeating).toBe(true);
+ expect(formatLinearGradient(parsed)).toEqual(
+ "repeating-linear-gradient(rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
+ );
+ });
+
+ test("parses linear-gradient with css variables", () => {
+ expect(
+ parseLinearGradient("linear-gradient(var(--brand-color), blue)")
+ ).toEqual(
+ linear({
+ angle: undefined,
+ sideOrCorner: undefined,
+ stops: [
+ {
+ color: {
+ type: "var",
+ value: "brand-color",
+ },
+ hint: undefined,
+ position: undefined,
+ },
+ {
+ color: { alpha: 1, b: 255, g: 0, r: 0, type: "rgb" },
+ hint: undefined,
+ position: undefined,
+ },
+ ],
+ })
+ );
+ });
+
+ test("parses linear-gradient with css variables and fallbacks", () => {
+ expect(
+ parseLinearGradient(
+ "linear-gradient(var(--heading-color, #ff0000) 25% 50%, yellow)"
+ )
+ ).toEqual(
+ linear({
+ angle: undefined,
+ sideOrCorner: undefined,
+ stops: [
+ {
+ color: {
+ type: "var",
+ value: "heading-color",
+ fallback: { type: "unparsed", value: "#ff0000" },
+ },
+ position: { type: "unit", unit: "%", value: 25 },
+ hint: { type: "unit", unit: "%", value: 50 },
+ },
+ {
+ color: { alpha: 1, b: 0, g: 255, r: 255, type: "rgb" },
+ hint: undefined,
+ position: undefined,
+ },
+ ],
+ })
+ );
+ });
+
+ test("parses linear-gradient with keyword and variable mix", () => {
+ const parsed = parseLinearGradient(
+ "linear-gradient(to bottom, green 0%, var(--accent))"
+ );
+ expect(parsed).toEqual(
+ linear({
+ angle: undefined,
+ sideOrCorner: { type: "keyword", value: "to bottom" },
+ stops: [
+ {
+ color: { alpha: 1, b: 0, g: 128, r: 0, type: "rgb" },
+ hint: undefined,
+ position: { type: "unit", unit: "%", value: 0 },
+ },
+ {
+ color: { type: "var", value: "accent" },
+ hint: undefined,
+ position: undefined,
+ },
+ ],
+ })
+ );
+ if (parsed) {
+ expect(formatLinearGradient(parsed)).toEqual(
+ "linear-gradient(to bottom, rgba(0, 128, 0, 1) 0%, var(--accent))"
+ );
+ }
+ });
+
+ test("parses linear-gradient with css variable positions", () => {
+ const parsed = parseLinearGradient(
+ "linear-gradient(rgba(255, 0, 0, 1) var(--start, 10%), blue var(--end))"
+ );
+ expect(parsed).toEqual(
+ linear({
+ angle: undefined,
+ sideOrCorner: undefined,
+ stops: [
+ {
+ color: { alpha: 1, b: 0, g: 0, r: 255, type: "rgb" },
+ hint: undefined,
+ position: {
+ type: "var",
+ value: "start",
+ fallback: { type: "unparsed", value: "10%" },
+ },
+ },
+ {
+ color: { alpha: 1, b: 255, g: 0, r: 0, type: "rgb" },
+ hint: undefined,
+ position: { type: "var", value: "end" },
+ },
+ ],
+ })
+ );
+ if (parsed) {
+ expect(formatLinearGradient(parsed)).toEqual(
+ "linear-gradient(rgba(255, 0, 0, 1) var(--start, 10%), rgba(0, 0, 255, 1) var(--end))"
+ );
+ }
+ });
+
+ test("parses linear-gradient with css variable hints", () => {
+ expect(
+ parseLinearGradient(
+ "linear-gradient(red 0% var(--hint-position, 20%), blue)"
+ )
+ ).toEqual(
+ linear({
+ angle: undefined,
+ sideOrCorner: undefined,
+ stops: [
+ {
+ color: { alpha: 1, b: 0, g: 0, r: 255, type: "rgb" },
+ position: { type: "unit", unit: "%", value: 0 },
+ hint: {
+ type: "var",
+ value: "hint-position",
+ fallback: { type: "unparsed", value: "20%" },
+ },
+ },
+ {
+ color: { alpha: 1, b: 255, g: 0, r: 0, type: "rgb" },
+ position: undefined,
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ });
+
+ test("parses linear-gradient with variable colors, positions, and hints", () => {
+ const gradient =
+ "linear-gradient(var(--primary, red) var(--start, 5%) var(--hint-start, 10%), var(--secondary) var(--end) var(--hint-end))";
+ const parsed = parseLinearGradient(gradient);
+ expect(parsed).toEqual(
+ linear({
+ angle: undefined,
+ sideOrCorner: undefined,
+ stops: [
+ {
+ color: {
+ type: "var",
+ value: "primary",
+ fallback: { type: "unparsed", value: "red" },
+ },
+ position: {
+ type: "var",
+ value: "start",
+ fallback: { type: "unparsed", value: "5%" },
+ },
+ hint: {
+ type: "var",
+ value: "hint-start",
+ fallback: { type: "unparsed", value: "10%" },
+ },
+ },
+ {
+ color: { type: "var", value: "secondary" },
+ position: { type: "var", value: "end" },
+ hint: { type: "var", value: "hint-end" },
+ },
+ ],
+ })
+ );
+ if (parsed) {
+ expect(formatLinearGradient(parsed)).toEqual(gradient);
+ }
+ });
+
+ test("returns undefined for invalid gradient input", () => {
+ expect(parseLinearGradient("linear-gradient(var())")).toBeUndefined();
+ expect(parseLinearGradient("linear-gradient(, , ,)")).toBeUndefined();
+ });
+
+ test("parses linear-gradient with variable angle", () => {
+ const parsed = parseLinearGradient(
+ "linear-gradient(var(--angle, 45deg), red, blue)"
+ );
+ if (parsed === undefined) {
+ throw new Error("parsed is undefined");
+ }
+
+ expect(parsed.angle).toMatchObject({
+ type: "var",
+ value: "angle",
+ });
+ expect(formatLinearGradient(parsed)).toEqual(
+ "linear-gradient(var(--angle, 45deg), rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
+ );
+ });
+
+ test("parses linear-gradient with radian angle", () => {
+ expect(parseLinearGradient("linear-gradient(0.5rad, red, blue)")).toEqual(
+ linear({
+ angle: { type: "unit", unit: "rad", value: 0.5 },
+ sideOrCorner: undefined,
+ stops: [
+ {
+ color: { alpha: 1, b: 0, g: 0, r: 255, type: "rgb" },
+ hint: undefined,
+ position: undefined,
+ },
+ {
+ color: { alpha: 1, b: 255, g: 0, r: 0, type: "rgb" },
+ hint: undefined,
+ position: undefined,
+ },
+ ],
+ })
+ );
+ });
});
diff --git a/packages/css-data/src/property-parsers/linear-gradient.ts b/packages/css-data/src/property-parsers/linear-gradient.ts
index cc1af7aecd..bae8046b0e 100644
--- a/packages/css-data/src/property-parsers/linear-gradient.ts
+++ b/packages/css-data/src/property-parsers/linear-gradient.ts
@@ -1,28 +1,32 @@
import * as csstree from "css-tree";
import { cssTryParseValue } from "../parse-css-value";
-import { colord, extend } from "colord";
import {
type UnitValue,
- type Unit,
toValue,
KeywordValue,
- type RgbValue,
+ type VarValue,
} from "@webstudio-is/css-engine";
-import namesPlugin from "colord/plugins/names";
-
-extend([namesPlugin]);
-
-export type GradientStop = {
- color?: RgbValue;
- position?: UnitValue;
- hint?: UnitValue;
-};
-
-export type ParsedGradient = {
- angle?: UnitValue;
- sideOrCorner?: KeywordValue;
- stops: GradientStop[];
-};
+import {
+ getColor,
+ isAngleDimension,
+ isAngleUnit,
+ isColorStop,
+ isVarAngle,
+ mapLengthPercentageOrVar,
+ formatGradientStops,
+ normalizeRepeatingGradient,
+ forEachGradientParts,
+} from "./gradient-utils";
+
+export type {
+ GradientColorValue,
+ GradientStop,
+ ParsedGradient,
+ ParsedLinearGradient,
+ ParsedConicGradient,
+} from "./types";
+
+import type { GradientStop, ParsedLinearGradient } from "./types";
const sideOrCorderIdentifiers = ["to", "top", "bottom", "left", "right"];
@@ -38,8 +42,15 @@ const sideOrCorderIdentifiers = ["to", "top", "bottom", "left", "right"];
export const parseLinearGradient = (
gradient: string
-): ParsedGradient | undefined => {
- const ast = cssTryParseValue(gradient);
+): ParsedLinearGradient | undefined => {
+ const { normalized: normalizedGradient, isRepeating } =
+ normalizeRepeatingGradient(
+ gradient,
+ "repeating-linear-gradient",
+ "linear-gradient"
+ );
+
+ const ast = cssTryParseValue(normalizedGradient);
if (ast === undefined) {
return;
}
@@ -48,153 +59,92 @@ export const parseLinearGradient = (
"linear-gradient( [ <angle> | to <side-or-corner> ]? , <color-stop-list> )",
ast
);
- if (match.matched === null) {
+ const containsVar = normalizedGradient.includes("var(");
+ if (match.matched === null && containsVar === false) {
return;
}
- let angle: UnitValue | undefined;
+ let angle: UnitValue | VarValue | undefined;
let sideOrCorner: KeywordValue | undefined;
const stops: GradientStop[] = [];
- let gradientParts: csstree.CssNode[] = [];
-
- csstree.walk(ast, (node) => {
- if (node.type === "Function" && node.name === "linear-gradient") {
- for (const item of node.children) {
- if (item.type !== "Operator") {
- gradientParts.push(item);
+ forEachGradientParts(ast, "linear-gradient", (gradientParts) => {
+ let handledAsAngle = false;
+
+ if (gradientParts.length === 1) {
+ const singlePart = gradientParts[0];
+ const mappedValue = mapLengthPercentageOrVar(singlePart);
+ const isAngleValue =
+ (isAngleDimension(singlePart) &&
+ mappedValue?.type === "unit" &&
+ isAngleUnit(mappedValue.unit)) ||
+ (singlePart.type === "Function" &&
+ singlePart.name === "var" &&
+ mappedValue?.type === "var" &&
+ isVarAngle(mappedValue));
+
+ if (isAngleValue && mappedValue !== undefined) {
+ angle = mappedValue;
+ handledAsAngle = true;
+ } else if (isColorStop(singlePart) === false) {
+ if (mappedValue !== undefined) {
+ stops.push({
+ hint: mappedValue,
+ });
}
+ }
+ }
- if (
- (item.type === "Operator" && item.value === ",") ||
- node.children.last === item
- ) {
- // If the gradientParts lenght is 1, then we need to check if it is angle or not.
- // If it's angle, then the value is related to <angle> or else it is a <color-hint>.
- if (gradientParts.length === 1) {
- if (isAngle(gradientParts[0]) === true) {
- angle = mapPercenTageOrDimentionToUnit(gradientParts[0]);
- }
-
- if (
- gradientParts[0].type === "Percentage" ||
- (gradientParts[0].type === "Dimension" &&
- ["deg", "grad", "rad", "turn"].includes(
- gradientParts[0].unit
- ) === false)
- ) {
- stops.push({
- hint: mapPercenTageOrDimentionToUnit(gradientParts[0]),
- });
- }
- }
-
- if (gradientParts.length && isSideOrCorner(gradientParts[0])) {
- const value = gradientParts
- .map((item) => csstree.generate(item))
- .join(" ");
- sideOrCorner = { type: "keyword", value };
- }
-
- // if there is a color-stop in the gradientParts, then we need to parse it for position and hint.
- const colorStop = gradientParts.find(isColorStop);
- if (colorStop !== undefined) {
- const [_colorStop, position, hint] = gradientParts;
-
- const stop: GradientStop = {
- color: getColor(colorStop),
- position: mapPercenTageOrDimentionToUnit(position),
- hint: mapPercenTageOrDimentionToUnit(hint),
- };
-
- stops.push(stop);
- }
-
- gradientParts = [];
- }
+ if (gradientParts.length && isSideOrCorner(gradientParts[0])) {
+ const value = gradientParts
+ .map((item) => csstree.generate(item))
+ .join(" ");
+ sideOrCorner = { type: "keyword", value };
+ }
+
+ if (handledAsAngle === false) {
+ const colorStop = gradientParts.find(isColorStop);
+ if (colorStop !== undefined) {
+ const colorIndex = gradientParts.indexOf(colorStop);
+ const position = gradientParts[colorIndex + 1];
+ const hint = gradientParts[colorIndex + 2];
+
+ const stop: GradientStop = {
+ color: getColor(colorStop),
+ position: mapLengthPercentageOrVar(position),
+ hint: mapLengthPercentageOrVar(hint),
+ };
+
+ stops.push(stop);
}
}
});
- return { angle, sideOrCorner, stops };
-};
-
-const mapPercenTageOrDimentionToUnit = (
- node?: csstree.CssNode
-): UnitValue | undefined => {
- if (node === undefined) {
+ if (stops.length === 0) {
return;
}
- if (node.type !== "Percentage" && node.type !== "Dimension") {
- return;
+ const parsedGradient: ParsedLinearGradient = {
+ type: "linear",
+ angle,
+ sideOrCorner,
+ stops,
+ };
+ if (isRepeating) {
+ parsedGradient.repeating = true;
}
- return {
- type: "unit",
- value: Number.parseFloat(node.value),
- unit: node.type === "Percentage" ? "%" : (node.unit as Unit),
- };
+ return parsedGradient;
};
-const isAngle = (node: csstree.CssNode): node is csstree.Dimension =>
- node.type === "Dimension" &&
- ["deg", "grad", "rad", "turn"].includes(node.unit);
-
const isSideOrCorner = (node: csstree.CssNode): node is csstree.Identifier =>
node.type === "Identifier" && sideOrCorderIdentifiers.includes(node.name);
-const isColorStop = (
- node: csstree.CssNode
-): node is csstree.Identifier | csstree.FunctionNode | csstree.Hash => {
- return (
- (node.type === "Function" ||
- (node.type === "Identifier" &&
- sideOrCorderIdentifiers.includes(node.name)) === false ||
- node.type === "Hash") &&
- colord(csstree.generate(node)).isValid() === true
- );
-};
-
-const getColor = (
- node: csstree.FunctionNode | csstree.Identifier | csstree.Hash
-): RgbValue | undefined => {
- let color: string;
- if (node.type === "Function") {
- color = csstree.generate(node);
- } else if (node.type === "Identifier") {
- color = node.name;
- } else {
- color = csstree.generate(node);
- }
+export const formatLinearGradient = (parsed: ParsedLinearGradient): string => {
+ const direction = parsed.angle || parsed.sideOrCorner;
+ const stops = formatGradientStops(parsed.stops);
- const result = colord(color);
- if (result.isValid()) {
- const value = result.toRgb();
-
- return {
- type: "rgb",
- r: value.r,
- g: value.g,
- b: value.b,
- alpha: value.a,
- };
- }
-};
-
-export const reconstructLinearGradient = (parsed: ParsedGradient): string => {
- const direction = parsed?.angle || parsed?.sideOrCorner;
- const stops = parsed.stops
- .map((stop: GradientStop) => {
- let result = toValue(stop.color);
- if (stop.position) {
- result += ` ${toValue(stop.position)}`;
- }
- if (stop.hint) {
- result += ` ${toValue(stop.hint)}`;
- }
- return result;
- })
- .join(", ");
+ const functionName =
+ parsed.repeating === true ? "repeating-linear-gradient" : "linear-gradient";
- return `linear-gradient(${direction ? toValue(direction) + ", " : ""}${stops})`;
+ return `${functionName}(${direction ? toValue(direction) + ", " : ""}${stops})`;
};
diff --git a/packages/css-data/src/property-parsers/radial-gradient.test.ts b/packages/css-data/src/property-parsers/radial-gradient.test.ts
new file mode 100644
index 0000000000..e9aa82804e
--- /dev/null
+++ b/packages/css-data/src/property-parsers/radial-gradient.test.ts
@@ -0,0 +1,286 @@
+import { describe, expect, test } from "vitest";
+import { parseRadialGradient, formatRadialGradient } from "./radial-gradient";
+
+// casts helper similar to other gradient tests
+type RadialGradient = NonNullable<ReturnType<typeof parseRadialGradient>>;
+const radial = (gradient: Omit<RadialGradient, "type">): RadialGradient => ({
+ type: "radial",
+ ...gradient,
+});
+
+describe("parse radial-gradient", () => {
+ test("parses gradient with single color stop", () => {
+ expect(parseRadialGradient("radial-gradient(red)")).toEqual(
+ radial({
+ shape: undefined,
+ size: undefined,
+ position: undefined,
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: undefined,
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ });
+
+ test("parses gradient with shape and multiple stops", () => {
+ expect(
+ parseRadialGradient("radial-gradient(circle, red, blue, yellow)")
+ ).toEqual(
+ radial({
+ shape: { type: "keyword", value: "circle" },
+ size: undefined,
+ position: undefined,
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: undefined,
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 0, g: 0, b: 255, alpha: 1 },
+ position: undefined,
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 255, g: 255, b: 0, alpha: 1 },
+ position: undefined,
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ });
+
+ test("parses gradient with shape, size, position and stops", () => {
+ expect(
+ parseRadialGradient(
+ "radial-gradient(circle closest-side at center, orange 0%, cyan 100%)"
+ )
+ ).toEqual(
+ radial({
+ shape: { type: "keyword", value: "circle" },
+ size: "closest-side",
+ position: "center",
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 165, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 0 },
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 0, g: 255, b: 255, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 100 },
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ });
+
+ test("parses ellipse with keyword size and keyword position", () => {
+ expect(
+ parseRadialGradient(
+ "radial-gradient(ellipse farthest-corner at left top, red 0%, blue 100%)"
+ )
+ ).toEqual(
+ radial({
+ shape: { type: "keyword", value: "ellipse" },
+ size: "farthest-corner",
+ position: "left top",
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 0 },
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 0, g: 0, b: 255, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 100 },
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ });
+
+ test("parses gradient with size keyword only", () => {
+ expect(
+ parseRadialGradient("radial-gradient(closest-side, red, blue)")
+ ).toEqual(
+ radial({
+ shape: undefined,
+ size: "closest-side",
+ position: undefined,
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: undefined,
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 0, g: 0, b: 255, alpha: 1 },
+ position: undefined,
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ });
+
+ test("parses circle with explicit radius length", () => {
+ expect(
+ parseRadialGradient("radial-gradient(circle 25px, red, blue)")
+ ).toEqual(
+ radial({
+ shape: { type: "keyword", value: "circle" },
+ size: "25px",
+ position: undefined,
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: undefined,
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 0, g: 0, b: 255, alpha: 1 },
+ position: undefined,
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ });
+
+ test("parses ellipse with explicit radii", () => {
+ expect(
+ parseRadialGradient("radial-gradient(ellipse 20% 40%, red, blue)")
+ ).toEqual(
+ radial({
+ shape: { type: "keyword", value: "ellipse" },
+ size: "20% 40%",
+ position: undefined,
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: undefined,
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 0, g: 0, b: 255, alpha: 1 },
+ position: undefined,
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ });
+
+ test("parses descriptors regardless of ordering", () => {
+ expect(
+ parseRadialGradient(
+ "radial-gradient(farthest-side circle at 40px 40px, red, blue)"
+ )
+ ).toEqual(
+ radial({
+ shape: { type: "keyword", value: "circle" },
+ size: "farthest-side",
+ position: "40px 40px",
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: undefined,
+ hint: undefined,
+ },
+ {
+ color: { type: "rgb", r: 0, g: 0, b: 255, alpha: 1 },
+ position: undefined,
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ });
+
+ test("parses gradient with explicit size values and position coordinates", () => {
+ expect(
+ parseRadialGradient(
+ "radial-gradient(20px 40px at 10px 20px, red 10% 40%, blue 80%)"
+ )
+ ).toEqual(
+ radial({
+ shape: undefined,
+ size: "20px 40px",
+ position: "10px 20px",
+ stops: [
+ {
+ color: { type: "rgb", r: 255, g: 0, b: 0, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 10 },
+ hint: { type: "unit", unit: "%", value: 40 },
+ },
+ {
+ color: { type: "rgb", r: 0, g: 0, b: 255, alpha: 1 },
+ position: { type: "unit", unit: "%", value: 80 },
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ });
+
+ test("parses radial-gradient with css variables", () => {
+ expect(
+ parseRadialGradient(
+ "radial-gradient(circle, var(--brand-color), var(--accent-color))"
+ )
+ ).toEqual(
+ radial({
+ shape: { type: "keyword", value: "circle" },
+ size: undefined,
+ position: undefined,
+ stops: [
+ {
+ color: { type: "var", value: "brand-color" },
+ position: undefined,
+ hint: undefined,
+ },
+ {
+ color: { type: "var", value: "accent-color" },
+ position: undefined,
+ hint: undefined,
+ },
+ ],
+ })
+ );
+ });
+
+ test("parses repeating radial-gradient and formats back", () => {
+ const parsed = parseRadialGradient(
+ "repeating-radial-gradient(red 0%, blue 100%)"
+ );
+ if (parsed === undefined) {
+ throw new Error("parsed radial gradient is undefined");
+ }
+
+ expect(parsed.repeating).toBe(true);
+ expect(formatRadialGradient(parsed)).toEqual(
+ "repeating-radial-gradient(rgba(255, 0, 0, 1) 0%, rgba(0, 0, 255, 1) 100%)"
+ );
+ });
+
+ test("formats gradient with descriptors in order", () => {
+ const parsed = parseRadialGradient(
+ "radial-gradient(circle 40px at top, red, blue)"
+ );
+ if (parsed === undefined) {
+ throw new Error("parsed radial gradient is undefined");
+ }
+
+ expect(formatRadialGradient(parsed)).toEqual(
+ "radial-gradient(circle 40px at top, rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
+ );
+ });
+});
diff --git a/packages/css-data/src/property-parsers/radial-gradient.ts b/packages/css-data/src/property-parsers/radial-gradient.ts
new file mode 100644
index 0000000000..c8ba153a7a
--- /dev/null
+++ b/packages/css-data/src/property-parsers/radial-gradient.ts
@@ -0,0 +1,171 @@
+import * as csstree from "css-tree";
+import { cssTryParseValue } from "../parse-css-value";
+import { toValue, type KeywordValue } from "@webstudio-is/css-engine";
+import {
+ getColor,
+ isColorStop,
+ mapLengthPercentageOrVar,
+ formatGradientStops,
+ normalizeRepeatingGradient,
+ forEachGradientParts,
+} from "./gradient-utils";
+import type { GradientStop, ParsedRadialGradient } from "./types";
+
+const shapeKeywords = new Set(["circle", "ellipse"]);
+
+const isIdentifier = (node: csstree.CssNode, value: string) =>
+ node.type === "Identifier" && node.name.toLowerCase() === value;
+
+const toKeywordValue = (value: string): KeywordValue => ({
+ type: "keyword",
+ value,
+});
+
+const toCssText = (nodes: csstree.CssNode[]): string =>
+ nodes
+ .map((item) => csstree.generate(item))
+ .join(" ")
+ .trim();
+
+export const parseRadialGradient = (
+ gradient: string
+): ParsedRadialGradient | undefined => {
+ const { normalized: normalizedGradient, isRepeating } =
+ normalizeRepeatingGradient(
+ gradient,
+ "repeating-radial-gradient",
+ "radial-gradient"
+ );
+
+ const ast = cssTryParseValue(normalizedGradient);
+ if (ast === undefined) {
+ return;
+ }
+
+ const containsVar = normalizedGradient.includes("var(");
+ let matchesGrammar = true;
+ try {
+ const match = csstree.lexer.match(
+ "radial-gradient( [ <ending-shape> || <ending-size> ]? [ at <position> ]? , <color-stop-list> )",
+ ast
+ );
+ matchesGrammar = match.matched !== null;
+ } catch {
+ // css-tree 2.3.1 does not define <ending-size>, so skip validation
+ matchesGrammar = true;
+ }
+ if (matchesGrammar === false && containsVar === false) {
+ return;
+ }
+
+ let shape: KeywordValue | undefined;
+ let size: string | undefined;
+ let position: string | undefined;
+ const stops: GradientStop[] = [];
+
+ forEachGradientParts(ast, "radial-gradient", (gradientParts) => {
+ const filtered = gradientParts.filter((node) => node.type !== "WhiteSpace");
+ if (filtered.length === 0) {
+ return;
+ }
+
+ const colorStopNode = filtered.find(isColorStop);
+ if (colorStopNode !== undefined) {
+ const color = getColor(colorStopNode);
+ const colorIndex = filtered.indexOf(colorStopNode);
+ const positionNode = filtered[colorIndex + 1];
+ const hintNode = filtered[colorIndex + 2];
+ const stop: GradientStop = {
+ color,
+ position: mapLengthPercentageOrVar(positionNode),
+ hint: mapLengthPercentageOrVar(hintNode),
+ };
+ stops.push(stop);
+ return;
+ }
+
+ const directiveTokens = [...filtered];
+ const atIndex = directiveTokens.findIndex((node) =>
+ isIdentifier(node, "at")
+ );
+ if (atIndex !== -1) {
+ const positionTokens = directiveTokens.slice(atIndex + 1);
+ const css = toCssText(positionTokens);
+ if (css.length > 0) {
+ position = css;
+ }
+ directiveTokens.length = atIndex;
+ }
+
+ if (directiveTokens.length === 0) {
+ return;
+ }
+
+ const remainderTokens: csstree.CssNode[] = [];
+ for (const token of directiveTokens) {
+ if (
+ token.type === "Identifier" &&
+ shapeKeywords.has(token.name.toLowerCase()) &&
+ shape === undefined
+ ) {
+ shape = toKeywordValue(token.name);
+ continue;
+ }
+ remainderTokens.push(token);
+ }
+
+ const sizeCss = toCssText(remainderTokens);
+ if (sizeCss.length > 0) {
+ size = sizeCss;
+ return;
+ }
+
+ const hint = mapLengthPercentageOrVar(directiveTokens[0]);
+ if (hint !== undefined) {
+ stops.push({ hint });
+ }
+ });
+
+ if (stops.length === 0) {
+ return;
+ }
+
+ const parsed: ParsedRadialGradient = {
+ type: "radial",
+ shape,
+ size,
+ position,
+ stops,
+ };
+ if (isRepeating) {
+ parsed.repeating = true;
+ }
+
+ return parsed;
+};
+
+export const formatRadialGradient = (parsed: ParsedRadialGradient): string => {
+ const shapeSizeParts: string[] = [];
+ if (parsed.shape) {
+ shapeSizeParts.push(toValue(parsed.shape));
+ }
+ if (parsed.size) {
+ shapeSizeParts.push(parsed.size);
+ }
+ const descriptors: string[] = [];
+ const shapeSize = shapeSizeParts.join(" ").trim();
+ if (shapeSize.length > 0) {
+ descriptors.push(shapeSize);
+ }
+ if (parsed.position) {
+ descriptors.push(`at ${parsed.position}`);
+ }
+
+ const functionName =
+ parsed.repeating === true ? "repeating-radial-gradient" : "radial-gradient";
+ const descriptorPrefix =
+ descriptors.length > 0 ? `${descriptors.join(" ")}, ` : "";
+ const stops = formatGradientStops(parsed.stops);
+
+ return `${functionName}(${descriptorPrefix}${stops})`;
+};
diff --git a/packages/css-data/src/property-parsers/types.ts b/packages/css-data/src/property-parsers/types.ts
new file mode 100644
index 0000000000..2adb1858ba
--- /dev/null
+++ b/packages/css-data/src/property-parsers/types.ts
@@ -0,0 +1,43 @@
+import {
+ type KeywordValue,
+ type RgbValue,
+ type UnitValue,
+ type VarValue,
+} from "@webstudio-is/css-engine";
+
+export type GradientColorValue = RgbValue | KeywordValue | VarValue;
+
+export type GradientStop = {
+ color?: GradientColorValue;
+ position?: UnitValue | VarValue;
+ hint?: UnitValue | VarValue;
+};
+
+export type ParsedGradientBase = {
+ stops: GradientStop[];
+ repeating?: boolean;
+};
+
+export type ParsedLinearGradient = ParsedGradientBase & {
+ type: "linear";
+ angle?: UnitValue | VarValue;
+ sideOrCorner?: KeywordValue;
+};
+
+export type ParsedConicGradient = ParsedGradientBase & {
+ type: "conic";
+ angle?: UnitValue | VarValue;
+ position?: string;
+};
+
+export type ParsedRadialGradient = ParsedGradientBase & {
+ type: "radial";
+ shape?: KeywordValue;
+ size?: string;
+ position?: string;
+};
+
+export type ParsedGradient =
+ | ParsedLinearGradient
+ | ParsedConicGradient
+ | ParsedRadialGradient;
diff --git a/packages/design-system/package.json b/packages/design-system/package.json
index 5c4631df9b..c568097563 100644
--- a/packages/design-system/package.json
+++ b/packages/design-system/package.json
@@ -66,6 +66,7 @@
"cmdk": "^1.1.1",
"downshift": "^6.1.7",
"match-sorter": "^8.0.0",
+ "react-colorful": "^5.6.1",
"react-hot-toast": "^2.5.1",
"token-transformer": "^0.0.28",
"type-fest": "^4.37.0",
diff --git a/packages/design-system/src/components/color-picker.stories.tsx b/packages/design-system/src/components/color-picker.stories.tsx
new file mode 100644
index 0000000000..cb5e1cf929
--- /dev/null
+++ b/packages/design-system/src/components/color-picker.stories.tsx
@@ -0,0 +1,66 @@
+import type { StoryFn } from "@storybook/react";
+import { useState } from "react";
+import type { RgbValue, StyleValue } from "@webstudio-is/css-engine";
+import { ColorPicker, ColorPickerPopover } from "./color-picker";
+import { Flex } from "./flex";
+import { Text } from "./text";
+
+export default {
+ title: "Library/ColorPicker",
+};
+
+const initialColor: RgbValue = {
+ type: "rgb",
+ r: 90,
+ g: 155,
+ b: 255,
+ alpha: 1,
+};
+
+const formatValue = (value: StyleValue) => JSON.stringify(value);
+
+const createHandlers = (setValue: (value: StyleValue) => void) => {
+ const handleChange = (value?: StyleValue) => {
+ if (value !== undefined) {
+ setValue(value);
+ }
+ };
+
+ const handleChangeComplete = (value: StyleValue) => {
+ setValue(value);
+ };
+
+ return { handleChange, handleChangeComplete };
+};
+
+export const Inline: StoryFn<typeof ColorPicker> = () => {
+ const [value, setValue] = useState<StyleValue>(initialColor);
+ const { handleChange, handleChangeComplete } = createHandlers(setValue);
+
+ return (
+ <Flex direction="column" gap="4">
+ <ColorPicker
+ value={value}
+ onChange={handleChange}
+ onChangeComplete={handleChangeComplete}
+ />
+ <Text>{formatValue(value)}</Text>
+ </Flex>
+ );
+};
+
+export const WithPopover: StoryFn<typeof ColorPickerPopover> = () => {
+ const [value, setValue] = useState<StyleValue>(initialColor);
+ const { handleChange, handleChangeComplete } = createHandlers(setValue);
+
+ return (
+ <Flex direction="column" gap="4">
+ <ColorPickerPopover
+ value={value}
+ onChange={handleChange}
+ onChangeComplete={handleChangeComplete}
+ />
+ <Text>{formatValue(value)}</Text>
+ </Flex>
+ );
+};
diff --git a/packages/design-system/src/components/color-picker.tsx b/packages/design-system/src/components/color-picker.tsx
new file mode 100644
index 0000000000..ca1e5e6a87
--- /dev/null
+++ b/packages/design-system/src/components/color-picker.tsx
@@ -0,0 +1,332 @@
+import {
+ forwardRef,
+ type ComponentProps,
+ type ElementRef,
+ useEffect,
+ useState,
+} from "react";
+import { colord, extend, type RgbaColor } from "colord";
+import namesPlugin from "colord/plugins/names";
+import { clamp } from "@react-aria/utils";
+import { useDebouncedCallback } from "use-debounce";
+import { RgbaColorPicker } from "react-colorful";
+import { EyedropperIcon } from "@webstudio-is/icons";
+import {
+ toValue,
+ type StyleValue,
+ type Unit,
+ type RgbValue,
+} from "@webstudio-is/css-engine";
+import { css, rawTheme, theme, type CSS } from "../stitches.config";
+import { useDisableCanvasPointerEvents } from "../utilities";
+import { Grid } from "./grid";
+import { IconButton } from "./icon-button";
+import { InputField } from "./input-field";
+import { Popover, PopoverContent, PopoverTrigger } from "./popover";
+
+extend([namesPlugin]);
+
+const colorfulStyles = css({
+ ".react-colorful__pointer": {
+ width: theme.spacing[10],
+ height: theme.spacing[10],
+ },
+});
+
+const whiteColor: RgbaColor = { r: 255, g: 255, b: 255, a: 1 };
+const borderColorSwatch = colord(rawTheme.colors.borderColorSwatch).toRgb();
+const transparentColor: RgbaColor = { r: 0, g: 0, b: 0, a: 0 };
+
+const distance = (a: RgbaColor, b: RgbaColor) =>
+ Math.sqrt(
+ Math.pow(a.r / 255 - b.r / 255, 2) +
+ Math.pow(a.g / 255 - b.g / 255, 2) +
+ Math.pow(a.b / 255 - b.b / 255, 2) +
+ Math.pow(a.a - b.a, 2)
+ );
+
+const calcBorderColor = (color: RgbaColor) => {
+ const distanceToStartDrawBorder = 0.15;
+ const alpha = clamp(
+ (distanceToStartDrawBorder - distance(whiteColor, color)) /
+ distanceToStartDrawBorder,
+ 0,
+ 1
+ );
+ return colord(lerpColor(transparentColor, borderColorSwatch, alpha));
+};
+
+const lerp = (a: number, b: number, t: number) => a * (1 - t) + b * t;
+
+const lerpColor = (a: RgbaColor, b: RgbaColor, t: number) => ({
+ r: lerp(a.r, b.r, t),
+ g: lerp(a.g, b.g, t),
+ b: lerp(a.b, b.b, t),
+ a: lerp(a.a, b.a, t),
+});
+
+const thumbStyle = css({
+ display: "block",
+ width: theme.spacing[9],
+ height: theme.spacing[9],
+ backgroundBlendMode: "difference",
+ borderRadius: theme.borderRadius[2],
+ borderWidth: 0,
+ borderStyle: "solid",
+ "&:focus-visible": {
+ outline: `1px solid ${theme.colors.borderFocus}`,
+ outlineOffset: 1,
+ },
+});
+
+export type ColorThumbProps = Omit<
+ ComponentProps<"button" | "span">,
+ "color"
+> & {
+ interactive?: boolean;
+ color?: RgbaColor;
+ css?: CSS;
+};
+
+export const ColorThumb = forwardRef<ElementRef<"button">, ColorThumbProps>(
+ ({ interactive, color = transparentColor, css, ...rest }, ref) => {
+ const background =
+ color === undefined || color.a < 1
+ ? `repeating-conic-gradient(rgba(0,0,0,0.22) 0% 25%, transparent 0% 50%) 0% 33.33% / 40% 40%, ${colord(
+ color
+ ).toRgbString()}`
+ : colord(color).toRgbString();
+ const borderColor = calcBorderColor(color);
+
+ const Component = interactive ? "button" : "span";
+
+ return (
+ <Component
+ style={{
+ background,
+ borderColor: borderColor.toRgbString(),
+ borderWidth: borderColor.alpha() === 0 ? 0 : 1,
+ }}
+ className={thumbStyle({ css })}
+ tabIndex={-1}
+ {...rest}
+ ref={ref}
+ />
+ );
+ }
+);
+
+ColorThumb.displayName = "ColorThumb";
+
+const colorResultToRgbValue = (rgb: RgbaColor): RgbValue => ({
+ type: "rgb",
+ r: rgb.r,
+ g: rgb.g,
+ b: rgb.b,
+ alpha: rgb.a ?? 1,
+});
+
+const normalizeHex = (value: string) => {
+ const trimmed = value.trim();
+ const hex = trimmed.startsWith("#") ? trimmed : `#${trimmed}`;
+ return hex;
+};
+
+export const styleValueToRgbaColor = (
+ value: StyleValue | IntermediateColorValue
+): RgbaColor => {
+ const color = colord(
+ value.type === "intermediate" ? value.value : toValue(value)
+ ).toRgb();
+
+ return {
+ r: color.r,
+ g: color.g,
+ b: color.b,
+ a: color.a,
+ };
+};
+
+const getEyeDropper = () => {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const Constructor = (window as any).EyeDropper;
+ if (Constructor === undefined) {
+ return;
+ }
+ const eyeDropper = new Constructor();
+ return (callback: (rgb: string) => void) => {
+ eyeDropper.open().then((result: { sRGBHex: string }) => {
+ callback(result.sRGBHex);
+ });
+ };
+};
+
+type IntermediateColorValue = {
+ type: "intermediate";
+ value: string;
+ unit?: Unit;
+};
+
+type ColorPickerValue = StyleValue | IntermediateColorValue;
+
+type ColorPickerProps = {
+ value: ColorPickerValue;
+ onChange: (value: StyleValue | undefined) => void;
+ onChangeComplete: (value: StyleValue) => void;
+};
+
+type ColorPickerPopoverProps = {
+ value: StyleValue;
+ onChange: (value: StyleValue | undefined) => void;
+ onChangeComplete: (value: StyleValue) => void;
+ open?: boolean;
+ onOpenChange?: (open: boolean) => void;
+ thumb?: React.ReactElement;
+ side?: "top" | "right" | "bottom" | "left";
+ align?: "start" | "center" | "end";
+ sideOffset?: number;
+};
+
+const fixColor = (value: ColorPickerValue, color: RgbaColor) => {
+ if (value.type === "keyword" && value.value === "transparent") {
+ return { ...color, a: 1 };
+ }
+ return color;
+};
+
+const EyeDropper = ({ onChange }: { onChange: (rgb: string) => void }) => {
+ const open = getEyeDropper();
+ return (
+ <IconButton
+ disabled={open === undefined}
+ onClick={() => {
+ open?.(onChange);
+ }}
+ >
+ <EyedropperIcon />
+ </IconButton>
+ );
+};
+
+export const ColorPicker = ({
+ value,
+ onChange,
+ onChangeComplete,
+}: ColorPickerProps) => {
+ const [hex, setHex] = useState(() =>
+ colord(styleValueToRgbaColor(value)).toHex()
+ );
+ const normalizedHex = normalizeHex(hex);
+ const handleCompleteDebounced = useDebouncedCallback(
+ (newValue: RgbValue) => onChangeComplete(newValue),
+ 500
+ );
+
+ return (
+ <>
+ <RgbaColorPicker
+ className={colorfulStyles.toString()}
+ color={colord(normalizedHex).toRgb()}
+ onChange={(newRgb) => {
+ const fixedRgb = fixColor(value, newRgb);
+ setHex(colord(fixedRgb).toHex());
+ const newValue = colorResultToRgbValue(fixedRgb);
+ onChange(newValue);
+ handleCompleteDebounced(newValue);
+ }}
+ />
+ <Grid css={{ gridTemplateColumns: "auto 1fr" }} gap="1">
+ <EyeDropper
+ onChange={(newHex) => {
+ setHex(newHex);
+ const newValue = colorResultToRgbValue(colord(newHex).toRgb());
+ onChangeComplete(newValue);
+ }}
+ />
+ <InputField
+ value={hex}
+ onChange={(event) => {
+ setHex(event.target.value);
+ const color = colord(normalizeHex(event.target.value));
+ if (color.isValid()) {
+ const newValue = colorResultToRgbValue(color.toRgb());
+ onChange(newValue);
+ handleCompleteDebounced(newValue);
+ }
+ }}
+ />
+ </Grid>
+ </>
+ );
+};
+
+export const ColorPickerPopover = ({
+ value,
+ onChange,
+ onChangeComplete,
+ open,
+ onOpenChange,
+ thumb,
+ side = "bottom",
+ align = "center",
+ sideOffset,
+}: ColorPickerPopoverProps) => {
+ const [displayColorPicker, setDisplayColorPicker] = useState(false);
+ const { enableCanvasPointerEvents, disableCanvasPointerEvents } =
+ useDisableCanvasPointerEvents();
+
+ const isControlled = open !== undefined;
+ const isOpen = isControlled ? open : displayColorPicker;
+
+ useEffect(() => {
+ if (isOpen) {
+ disableCanvasPointerEvents();
+ document.body.style.userSelect = "none";
+ } else {
+ document.body.style.removeProperty("user-select");
+ enableCanvasPointerEvents();
+ }
+
+ return () => {
+ document.body.style.removeProperty("user-select");
+ enableCanvasPointerEvents();
+ };
+ }, [isOpen, disableCanvasPointerEvents, enableCanvasPointerEvents]);
+
+ const handleOpenChange = (nextOpen: boolean) => {
+ if (!isControlled) {
+ setDisplayColorPicker(nextOpen);
+ }
+ onOpenChange?.(nextOpen);
+ };
+
+ return (
+ <Popover modal open={isOpen} onOpenChange={handleOpenChange}>
+ <PopoverTrigger
+ asChild
+ aria-label="Open color picker"
+ onClick={() => handleOpenChange(!isOpen)}
+ >
+ {thumb ?? (
+ <ColorThumb color={styleValueToRgbaColor(value)} interactive={true} />
+ )}
+ </PopoverTrigger>
+ <PopoverContent
+ side={side}
+ align={align}
+ sideOffset={sideOffset}
+ css={{
+ display: "grid",
+ padding: theme.spacing[5],
+ gap: theme.spacing[5],
+ }}
+ >
+ <ColorPicker
+ value={value}
+ onChange={onChange}
+ onChangeComplete={onChangeComplete}
+ />
+ </PopoverContent>
+ </Popover>
+ );
+};
diff --git a/packages/design-system/src/components/dialog.tsx b/packages/design-system/src/components/dialog.tsx
index fca4a6c26b..a0a4543794 100644
--- a/packages/design-system/src/components/dialog.tsx
+++ b/packages/design-system/src/components/dialog.tsx
@@ -228,6 +228,7 @@ const useDraggable = ({
}, [props.x, props.y]);
const handleDragStart: DragEventHandler = (event) => {
+ event.stopPropagation();
const target = ref.current;
if (target === null) {
return;
@@ -246,6 +247,7 @@ const useDraggable = ({
};
const handleDrag: DragEventHandler = (event) => {
+ event.stopPropagation();
const target = ref.current;
if (
@@ -268,7 +270,8 @@ const useDraggable = ({
target.style.top = `${top}px`;
};
- const handleDragEnd: DragEventHandler = () => {
+ const handleDragEnd: DragEventHandler = (event) => {
+ event.stopPropagation();
const target = ref.current;
if (target === null) {
return;
diff --git a/packages/design-system/src/components/floating-panel.tsx b/packages/design-system/src/components/floating-panel.tsx
index 65b5006e87..3cd6d28ca4 100644
--- a/packages/design-system/src/components/floating-panel.tsx
+++ b/packages/design-system/src/components/floating-panel.tsx
@@ -18,13 +18,76 @@ import {
DialogTrigger,
DialogMaximize,
} from "./dialog";
-import {
- computePosition,
- flip,
- offset,
- shift,
- type OffsetOptions,
-} from "@floating-ui/dom";
+
+type OffsetOptions =
+ | number
+ | { mainAxis?: number; crossAxis?: number; alignmentAxis?: number | null };
+
+const computeFloatingPosition = (
+ trigger: HTMLElement,
+ floating: HTMLElement,
+ placement: "left-start" | "right-start" | "bottom",
+ offsetOptions: OffsetOptions
+): { x: number; y: number } => {
+ const triggerRect = trigger.getBoundingClientRect();
+ const floatingRect = floating.getBoundingClientRect();
+
+ const mainAxis =
+ typeof offsetOptions === "number"
+ ? offsetOptions
+ : (offsetOptions.mainAxis ?? 0);
+
+ let x = 0;
+ let y = 0;
+
+ if (placement === "left-start") {
+ // Position to the left of the trigger, aligned with the top
+ x = triggerRect.left - floatingRect.width - mainAxis;
+ y = triggerRect.top;
+ } else if (placement === "right-start") {
+ // Position to the right of the trigger, aligned with the top
+ x = triggerRect.right + mainAxis;
+ y = triggerRect.top;
+ } else if (placement === "bottom") {
+ // Position below the trigger
+ x = triggerRect.left;
+ y = triggerRect.bottom + mainAxis;
+ }
+
+ // Keep within viewport bounds (simple shift)
+ const viewportWidth = window.innerWidth;
+ const viewportHeight = window.innerHeight;
+
+ // Adjust horizontal position if needed
+ if (x < 0) {
+ x = 0;
+ } else if (x + floatingRect.width > viewportWidth) {
+ x = viewportWidth - floatingRect.width;
+ }
+
+ // Adjust vertical position if needed
+ if (y < 0) {
+ y = 0;
+ } else if (y + floatingRect.height > viewportHeight) {
+ y = viewportHeight - floatingRect.height;
+ }
+
+ return { x, y };
+};
+
+const contentFitsAtPosition = (
+ contentElement: HTMLElement,
+ position: { x: number; y: number }
+): boolean => {
+ const rect = contentElement.getBoundingClientRect();
+ const { x, y } = position;
+ return (
+ y >= 0 &&
+ y + rect.height <= window.innerHeight &&
+ x >= 0 &&
+ x + rect.width <= window.innerWidth
+ );
+};
const FloatingPanelContext = createContext<{
container: RefObject<null | HTMLElement>;
@@ -50,6 +113,7 @@ type FloatingPanelProps = {
title: ReactNode;
content: ReactNode;
children: ReactNode;
+ titleSuffix?: ReactNode;
maximizable?: boolean;
resize?: ComponentProps<typeof Dialog>["resize"];
width?: number;
@@ -73,6 +137,7 @@ export const FloatingPanel = ({
title,
content,
children,
+ titleSuffix,
resize,
maximizable,
width,
@@ -88,6 +153,24 @@ export const FloatingPanel = ({
);
const triggerRef = useRef<HTMLButtonElement>(null);
const [position, setPosition] = useState<{ x: number; y: number }>();
+ const currentPositionRef = useRef<{ x: number; y: number }>();
+
+ // Wrap onOpenChange to reset position when panel closes
+ const handleOpenChange = (isOpen: boolean) => {
+ if (isOpen === false) {
+ currentPositionRef.current = undefined;
+ setPosition(undefined);
+ }
+ onOpenChange?.(isOpen);
+ };
+
+ // Reset position tracking when panel closes via open prop
+ useLayoutEffect(() => {
+ if (open === false) {
+ currentPositionRef.current = undefined;
+ setPosition(undefined);
+ }
+ }, [open]);
useLayoutEffect(() => {
if (
@@ -95,18 +178,72 @@ export const FloatingPanel = ({
containerRef.current === null ||
contentElement === null ||
// When centering the dialog, we don't need to calculate the position
- placement === "center"
+ placement === "center" ||
+ // Don't recalculate position when panel is closed
+ open === false
) {
return;
}
- computePosition(triggerRef.current, contentElement, {
- placement,
- middleware: [shift(), flip(), offset(offsetProp)],
- }).then(({ x, y }) => {
- setPosition({ x, y });
+ const updatePosition = () => {
+ if (
+ triggerRef.current === null ||
+ containerRef.current === null ||
+ contentElement === null
+ ) {
+ return;
+ }
+
+ // Set initial position once when panel opens
+ if (!currentPositionRef.current) {
+ const { x, y } = computeFloatingPosition(
+ triggerRef.current,
+ contentElement,
+ placement,
+ offsetProp
+ );
+ currentPositionRef.current = { x, y };
+ setPosition({ x, y });
+ return;
+ }
+
+ // Only recalculate if content doesn't fit at current position
+
+ if (contentFitsAtPosition(contentElement, currentPositionRef.current)) {
+ return;
+ }
+
+ const { x, y } = computeFloatingPosition(
+ triggerRef.current,
+ contentElement,
+ placement,
+ offsetProp
+ );
+ currentPositionRef.current = { x, y };
+
+ // Only update state if position actually changed
+ setPosition((current) => {
+ if (current && current.x === x && current.y === y) {
+ return current;
+ }
+ return { x, y };
+ });
+ };
+
+ // Calculate initial position or check if it still fits
+ updatePosition();
+
+ // Observe content size changes and update position
+ const resizeObserver = new ResizeObserver(() => {
+ updatePosition();
});
- }, [contentElement, triggerRef, containerRef, placement, offsetProp]);
+
+ resizeObserver.observe(contentElement);
+
+ return () => {
+ resizeObserver.disconnect();
+ };
+ }, [contentElement, containerRef, placement, offsetProp, open]);
return (
<Dialog
@@ -114,7 +251,7 @@ export const FloatingPanel = ({
resize={resize}
open={open}
modal={false}
- onOpenChange={onOpenChange}
+ onOpenChange={handleOpenChange}
>
<DialogTrigger asChild ref={triggerRef}>
{children}
@@ -147,6 +284,7 @@ export const FloatingPanel = ({
<DialogTitle
suffix={
<DialogTitleActions>
+ {titleSuffix}
{maximizable && <DialogMaximize />}
<DialogClose />
</DialogTitleActions>
diff --git a/packages/design-system/src/components/gradient-picker.stories.tsx b/packages/design-system/src/components/gradient-picker.stories.tsx
index 445bf761aa..2c1e98f3c3 100644
--- a/packages/design-system/src/components/gradient-picker.stories.tsx
+++ b/packages/design-system/src/components/gradient-picker.stories.tsx
@@ -1,7 +1,7 @@
import {
parseLinearGradient,
- reconstructLinearGradient,
- type ParsedGradient,
+ formatLinearGradient,
+ type ParsedLinearGradient,
} from "@webstudio-is/css-data";
import { useState } from "react";
import { GradientPicker } from "./gradient-picker";
@@ -12,20 +12,36 @@ export default {
title: "Library/GradientPicker",
};
+const parseLinearGradientOrThrow = (
+ gradientString: string
+): ParsedLinearGradient => {
+ const parsed = parseLinearGradient(gradientString);
+ if (parsed === undefined) {
+ throw new Error(`Invalid gradient: ${gradientString}`);
+ }
+ return parsed;
+};
+
export const GradientWithoutAngle = () => {
- const gradientString = "linear-gradient(black 0%, white 100%)";
- const [gradient, setGradient] = useState<string>(gradientString);
+ const gradientString = "linear-gradient(90deg, black 0%, white 100%)";
+ const [gradient, setGradient] = useState<ParsedLinearGradient>(() =>
+ parseLinearGradientOrThrow(gradientString)
+ );
return (
<Flex direction="column" gap="4">
<GradientPicker
- gradient={parseLinearGradient(gradientString) as ParsedGradient}
+ gradient={gradient}
+ backgroundImage={formatLinearGradient(gradient)}
onChange={(value) => {
- setGradient(reconstructLinearGradient(value));
+ setGradient(value);
+ }}
+ onChangeComplete={(value) => {
+ setGradient(value);
}}
- onThumbSelected={() => {}}
+ onThumbSelect={() => {}}
/>
- <Text>{gradient}</Text>
+ <Text>{formatLinearGradient(gradient)}</Text>
</Flex>
);
};
@@ -33,36 +49,48 @@ export const GradientWithoutAngle = () => {
export const GradientWithAngleAndHints = () => {
const gradientString =
"linear-gradient(145deg, #ff00fa 0%, #00f497 34% 34%, #ffa800 56% 56%, #00eaff 100%)";
- const [gradient, setGradient] = useState<string>(gradientString);
+ const [gradient, setGradient] = useState<ParsedLinearGradient>(() =>
+ parseLinearGradientOrThrow(gradientString)
+ );
return (
<Flex direction="column" gap="4">
<GradientPicker
- gradient={parseLinearGradient(gradientString) as ParsedGradient}
+ gradient={gradient}
+ backgroundImage={formatLinearGradient(gradient)}
onChange={(value) => {
- setGradient(reconstructLinearGradient(value));
+ setGradient(value);
+ }}
+ onChangeComplete={(value) => {
+ setGradient(value);
}}
- onThumbSelected={() => {}}
+ onThumbSelect={() => {}}
/>
- <Text>{gradient}</Text>
+ <Text>{formatLinearGradient(gradient)}</Text>
</Flex>
);
};
export const GradientWithSideOrCorner = () => {
const gradientString = "linear-gradient(to left top, blue 0%, red 100%)";
- const [gradient, setGradient] = useState<string>(gradientString);
+ const [gradient, setGradient] = useState<ParsedLinearGradient>(() =>
+ parseLinearGradientOrThrow(gradientString)
+ );
return (
<Flex direction="column" gap="4">
<GradientPicker
- gradient={parseLinearGradient(gradientString) as ParsedGradient}
+ gradient={gradient}
+ backgroundImage={formatLinearGradient(gradient)}
onChange={(value) => {
- setGradient(reconstructLinearGradient(value));
+ setGradient(value);
+ }}
+ onChangeComplete={(value) => {
+ setGradient(value);
}}
- onThumbSelected={() => {}}
+ onThumbSelect={() => {}}
/>
- <Text>{gradient}</Text>
+ <Text>{formatLinearGradient(gradient)}</Text>
</Flex>
);
};
diff --git a/packages/design-system/src/components/gradient-picker.tsx b/packages/design-system/src/components/gradient-picker.tsx
index 456b059d67..40b552473c 100644
--- a/packages/design-system/src/components/gradient-picker.tsx
+++ b/packages/design-system/src/components/gradient-picker.tsx
@@ -1,15 +1,20 @@
import { clamp } from "@react-aria/utils";
-import { toValue, UnitValue, type RgbValue } from "@webstudio-is/css-engine";
+import {
+ toValue,
+ type RgbValue,
+ type StyleValue,
+} from "@webstudio-is/css-engine";
import {
useState,
useCallback,
useRef,
- type KeyboardEvent as ReactKeyboardEvent,
- type MouseEvent as ReactMouseEvent,
+ useEffect,
+ type KeyboardEvent,
+ type MouseEvent,
type PointerEvent as ReactPointerEvent,
} from "react";
import {
- reconstructLinearGradient,
+ type GradientColorValue,
type GradientStop,
type ParsedGradient,
} from "@webstudio-is/css-data";
@@ -19,59 +24,191 @@ import { ChevronFilledUpIcon } from "@webstudio-is/icons";
import { styled, theme } from "../stitches.config";
import { Flex } from "./flex";
import { Box } from "./box";
+import {
+ ColorPickerPopover,
+ ColorThumb,
+ styleValueToRgbaColor,
+} from "./color-picker";
extend([mixPlugin]);
-type GradientPickerProps = {
- gradient: ParsedGradient;
- onChange: (value: ParsedGradient) => void;
- onThumbSelected: (index: number, stop: GradientStop) => void;
+type GradientPickerProps<T extends ParsedGradient = ParsedGradient> = {
+ gradient: T;
+ backgroundImage: string;
+ onChange: (value: T) => void;
+ onChangeComplete: (value: T) => void;
+ onThumbSelect: (index: number, stop: GradientStop) => void;
+ selectedStopIndex?: number;
+ type?: T["type"];
};
-const defaultAngle: UnitValue = {
- type: "unit",
- value: 90,
- unit: "deg",
+const THUMB_INTERACTION_DISTANCE = 12;
+const DRAG_THRESHOLD = 3;
+const SLIDER_HEIGHT = 16;
+const THUMB_HEIGHT = 14;
+
+const defaultStopColor: RgbValue = {
+ type: "rgb",
+ r: 0,
+ g: 0,
+ b: 0,
+ alpha: 1,
};
-const THUMB_INTERACTION_PX = 12;
+const toRgbColor = (
+ color: GradientStop["color"] | undefined
+): RgbValue | undefined => {
+ if (color === undefined) {
+ return;
+ }
+
+ if (color.type === "rgb") {
+ return color;
+ }
-export const GradientPicker = (props: GradientPickerProps) => {
- const { gradient, onChange, onThumbSelected } = props;
+ const parsed = colord(toValue(color));
+ if (parsed.isValid()) {
+ const { r, g, b, a } = parsed.toRgb();
+ return {
+ type: "rgb",
+ r,
+ g,
+ b,
+ alpha: a,
+ };
+ }
+};
+
+const cloneColor = (
+ color: GradientStop["color"] | undefined
+): GradientStop["color"] | undefined => {
+ if (color === undefined) {
+ return;
+ }
+
+ return { ...color };
+};
+
+export const GradientPicker = <T extends ParsedGradient>(
+ props: GradientPickerProps<T>
+) => {
+ const {
+ gradient,
+ backgroundImage,
+ onChange,
+ onChangeComplete,
+ onThumbSelect,
+ selectedStopIndex,
+ } = props;
const [stops, setStops] = useState<Array<GradientStop>>(gradient.stops);
const [selectedStop, setSelectedStop] = useState<number | undefined>();
const [isHoveredOnStop, setIsHoveredOnStop] = useState<boolean>(false);
+ const [colorPickerOpenStop, setColorPickerOpenStop] = useState<
+ number | undefined
+ >();
const sliderRef = useRef<HTMLDivElement | null>(null);
+ const thumbRefs = useRef<Array<HTMLDivElement | null>>([]);
+ const stopsRef = useRef(stops);
+
+ useEffect(() => {
+ stopsRef.current = stops;
+ }, [stops]);
+
+ useEffect(() => {
+ if (selectedStopIndex !== undefined) {
+ setSelectedStop(selectedStopIndex);
+ }
+ }, [selectedStopIndex]);
+
+ const buildGradient = useCallback(
+ (stopsValue: GradientStop[]): T => {
+ return {
+ ...gradient,
+ stops: stopsValue,
+ } as T;
+ },
+ [gradient]
+ );
+
+ useEffect(() => {
+ setStops(gradient.stops);
+ stopsRef.current = gradient.stops;
+
+ setSelectedStop((currentSelected) => {
+ if (gradient.stops.length === 0) {
+ return;
+ }
+
+ // If no stop is selected, select the first one
+ if (currentSelected === undefined) {
+ const firstStop = gradient.stops[0];
+ if (firstStop !== undefined) {
+ onThumbSelect(0, firstStop);
+ }
+ return 0;
+ }
+
+ const nextIndex = Math.min(currentSelected, gradient.stops.length - 1);
+ const nextStop = gradient.stops[nextIndex];
+
+ if (nextStop !== undefined && nextIndex !== currentSelected) {
+ onThumbSelect(nextIndex, nextStop);
+ }
+
+ return nextIndex;
+ });
+ }, [gradient.stops, onThumbSelect]);
const positions = stops
- .map((stop) => stop.position?.value)
+ .map((stop) =>
+ stop.position?.type === "unit" && stop.position.unit === "%"
+ ? stop.position.value
+ : undefined
+ )
.filter((item): item is number => item !== undefined);
const hints = gradient.stops
- .map((stop): number | undefined => stop.hint?.value)
+ .map((stop): number | undefined =>
+ stop.hint?.type === "unit" && stop.hint.unit === "%"
+ ? stop.hint.value
+ : undefined
+ )
.filter((item): item is number => item !== undefined);
- const background = reconstructLinearGradient({
- stops,
- sideOrCorner: gradient.sideOrCorner,
- angle: defaultAngle,
- });
const updateStops = useCallback(
- (updater: (currentStops: GradientStop[]) => GradientStop[]) => {
+ (
+ updater: (currentStops: GradientStop[]) => GradientStop[],
+ type: "change" | "complete"
+ ) => {
+ let nextStops: GradientStop[] | undefined;
+ let hasChanged = false;
setStops((currentStops) => {
- const nextStops = updater(currentStops);
- onChange({
- angle: gradient.angle,
- stops: nextStops,
- sideOrCorner: gradient.sideOrCorner,
- });
- return nextStops;
+ nextStops = updater(currentStops);
+ if (nextStops !== currentStops) {
+ hasChanged = true;
+ stopsRef.current = nextStops;
+ return nextStops;
+ }
+ nextStops = currentStops;
+ return currentStops;
});
+
+ if (hasChanged === false || nextStops === undefined) {
+ return;
+ }
+
+ const nextGradient = buildGradient(nextStops);
+
+ if (type === "change") {
+ onChange(nextGradient);
+ } else {
+ onChangeComplete(nextGradient);
+ }
},
- [gradient.angle, gradient.sideOrCorner, onChange]
+ [buildGradient, onChange, onChangeComplete]
);
const updateStopPosition = useCallback(
- (index: number, value: number) => {
+ (index: number, value: number, type: "change" | "complete") => {
const nextValue = clamp(value, 0, 100);
updateStops((currentStops) => {
if (index < 0 || index >= currentStops.length) {
@@ -82,30 +219,70 @@ export const GradientPicker = (props: GradientPickerProps) => {
if (stopIndex !== index) {
return stop;
}
+ return {
+ ...stop,
+ position: {
+ type: "unit",
+ unit: "%",
+ value: nextValue,
+ },
+ };
+ });
+ }, type);
+ },
+ [updateStops]
+ );
- const nextPosition = {
- type: "unit",
- unit: "%",
- value: nextValue,
- } as const;
+ const handleColorPickerOpenChange = useCallback(
+ (index: number, open: boolean) => {
+ setColorPickerOpenStop(open ? index : undefined);
+ },
+ []
+ );
- if (stop.position === undefined) {
- return {
- ...stop,
- position: nextPosition,
- };
- }
+ const isGradientColorValue = (
+ value: StyleValue
+ ): value is GradientColorValue =>
+ value.type === "rgb" || value.type === "keyword" || value.type === "var";
+
+ const handleStopColorChange = useCallback(
+ (
+ index: number,
+ value: StyleValue | undefined,
+ changeType: "change" | "complete"
+ ) => {
+ if (value === undefined || !isGradientColorValue(value)) {
+ return;
+ }
+
+ updateStops((currentStops) => {
+ if (index < 0 || index >= currentStops.length) {
+ return currentStops;
+ }
+ return currentStops.map((stop, stopIndex) => {
+ if (stopIndex !== index) {
+ return stop;
+ }
return {
...stop,
- position: nextPosition,
+ color: value,
};
});
- });
+ }, changeType);
},
[updateStops]
);
+ useEffect(() => {
+ if (
+ colorPickerOpenStop !== undefined &&
+ colorPickerOpenStop >= stops.length
+ ) {
+ setColorPickerOpenStop(undefined);
+ }
+ }, [colorPickerOpenStop, stops.length]);
+
const computePositionFromClientX = useCallback((clientX: number) => {
const rect = sliderRef.current?.getBoundingClientRect();
if (rect === undefined || rect.width === 0) {
@@ -132,7 +309,7 @@ export const GradientPicker = (props: GradientPickerProps) => {
const relativeX = clamp(clientX - rect.left, 0, rect.width);
const isStopExistingAtPosition = positions.some((position) => {
const positionPx = (position / 100) * rect.width;
- return Math.abs(positionPx - relativeX) <= THUMB_INTERACTION_PX;
+ return Math.abs(positionPx - relativeX) <= THUMB_INTERACTION_DISTANCE;
});
return { isStopExistingAtPosition, newPosition };
@@ -143,51 +320,105 @@ export const GradientPicker = (props: GradientPickerProps) => {
const handleStopSelected = useCallback(
(index: number, stop: GradientStop) => {
setSelectedStop(index);
- onThumbSelected(index, stop);
+ onThumbSelect(index, stop);
},
- [onThumbSelected]
+ [onThumbSelect]
);
+ useEffect(() => {
+ if (selectedStop === undefined) {
+ return;
+ }
+
+ const thumb = thumbRefs.current[selectedStop];
+ thumb?.focus({ preventScroll: true });
+ }, [selectedStop]);
+
const handleThumbPointerDown = useCallback(
(index: number, stop: GradientStop) =>
(event: ReactPointerEvent<HTMLDivElement>) => {
- event.preventDefault();
event.stopPropagation();
+ // Don't start drag if the color picker is open for this thumb
+ if (colorPickerOpenStop === index) {
+ return;
+ }
handleStopSelected(index, stop);
setIsHoveredOnStop(true);
const pointerId = event.pointerId;
- const target = event.currentTarget;
- target.setPointerCapture(pointerId);
+ const target = event.currentTarget as HTMLDivElement;
+ const startX = event.clientX;
+ let hasDragged = false;
+ let isCleanedUp = false;
+
+ const cleanup = () => {
+ if (isCleanedUp) {
+ return;
+ }
+ isCleanedUp = true;
+
+ target.removeEventListener("pointermove", handlePointerMove);
+ target.removeEventListener("pointerup", handlePointerUp);
+ target.removeEventListener("pointercancel", handlePointerUp);
+ setIsHoveredOnStop(false);
+ if (target.hasPointerCapture(pointerId)) {
+ target.releasePointerCapture(pointerId);
+ }
+ };
const handlePointerMove = (moveEvent: PointerEvent) => {
+ if (!hasDragged) {
+ if (Math.abs(moveEvent.clientX - startX) <= DRAG_THRESHOLD) {
+ return;
+ }
+ hasDragged = true;
+ target.setPointerCapture(pointerId);
+ setColorPickerOpenStop(undefined);
+ }
const newPosition = computePositionFromClientX(moveEvent.clientX);
- updateStopPosition(index, newPosition);
+ updateStopPosition(index, newPosition, "change");
};
const handlePointerUp = () => {
- target.releasePointerCapture(pointerId);
- target.removeEventListener("pointermove", handlePointerMove);
- target.removeEventListener("pointerup", handlePointerUp);
- target.removeEventListener("pointercancel", handlePointerUp);
- setIsHoveredOnStop(false);
+ cleanup();
+ if (hasDragged) {
+ onChangeComplete(buildGradient(stopsRef.current));
+ }
+ hasDragged = false;
};
target.addEventListener("pointermove", handlePointerMove);
target.addEventListener("pointerup", handlePointerUp);
target.addEventListener("pointercancel", handlePointerUp);
},
- [computePositionFromClientX, handleStopSelected, updateStopPosition]
+ [
+ colorPickerOpenStop,
+ computePositionFromClientX,
+ onChangeComplete,
+ handleStopSelected,
+ updateStopPosition,
+ buildGradient,
+ ]
);
const handleKeyDown = useCallback(
- (event: ReactKeyboardEvent<HTMLDivElement>) => {
+ (event: KeyboardEvent<HTMLDivElement>) => {
if (selectedStop === undefined) {
return;
}
- if (event.key === "Backspace") {
+ if (event.key === "Enter") {
+ event.preventDefault();
+ if (colorPickerOpenStop === selectedStop) {
+ setColorPickerOpenStop(undefined);
+ } else {
+ setColorPickerOpenStop(selectedStop);
+ }
+ return;
+ }
+
+ if (event.key === "Backspace" || event.key === "Delete") {
event.preventDefault();
let nextSelection:
| { index: number | undefined; stop?: GradientStop }
@@ -213,11 +444,11 @@ export const GradientPicker = (props: GradientPickerProps) => {
}
return nextStops;
- });
+ }, "complete");
if (nextSelection?.index !== undefined && nextSelection.stop) {
setSelectedStop(nextSelection.index);
- onThumbSelected(nextSelection.index, nextSelection.stop);
+ onThumbSelect(nextSelection.index, nextSelection.stop);
} else {
setSelectedStop(undefined);
}
@@ -225,15 +456,48 @@ export const GradientPicker = (props: GradientPickerProps) => {
return;
}
+ if (event.key === "ArrowUp" || event.key === "ArrowDown") {
+ event.preventDefault();
+ const stopCount = stops.length;
+ if (stopCount === 0) {
+ return;
+ }
+
+ const normalizedCurrent =
+ ((selectedStop % stopCount) + stopCount) % stopCount;
+ const delta = event.key === "ArrowUp" ? -1 : 1;
+ const nextIndex = (normalizedCurrent + delta + stopCount) % stopCount;
+
+ if (nextIndex !== normalizedCurrent) {
+ const nextStop = stops[nextIndex];
+ if (nextStop !== undefined) {
+ handleStopSelected(nextIndex, nextStop);
+ }
+ }
+
+ return;
+ }
+
if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
event.preventDefault();
const step = event.shiftKey ? 10 : 1;
const delta = event.key === "ArrowLeft" ? -step : step;
- const currentPosition = stops[selectedStop]?.position?.value ?? 0;
- updateStopPosition(selectedStop, currentPosition + delta);
+ const currentPosition =
+ stops[selectedStop]?.position?.type === "unit"
+ ? stops[selectedStop]?.position.value
+ : 0;
+ updateStopPosition(selectedStop, currentPosition + delta, "complete");
}
},
- [onThumbSelected, selectedStop, stops, updateStopPosition, updateStops]
+ [
+ handleStopSelected,
+ onThumbSelect,
+ selectedStop,
+ stops,
+ updateStopPosition,
+ updateStops,
+ colorPickerOpenStop,
+ ]
);
const handlePointerDown = useCallback(
@@ -245,6 +509,8 @@ export const GradientPicker = (props: GradientPickerProps) => {
return;
}
+ setColorPickerOpenStop(undefined);
+
const { isStopExistingAtPosition, newPosition } =
checkIfStopExistsAtPosition(event.clientX);
@@ -262,7 +528,9 @@ export const GradientPicker = (props: GradientPickerProps) => {
}
const currentPositions = currentStops
- .map((stop) => stop.position?.value)
+ .map((stop) =>
+ stop.position?.type === "unit" ? stop.position.value : undefined
+ )
.filter((value): value is number => value !== undefined);
const newStopIndex = currentPositions.findIndex(
@@ -280,27 +548,31 @@ export const GradientPicker = (props: GradientPickerProps) => {
const prevColor = currentStops[prevIndex]?.color;
const nextColor = currentStops[nextIndex]?.color ?? prevColor;
- if (prevColor === undefined && nextColor === undefined) {
- return currentStops;
+ const prevRgb = toRgbColor(prevColor);
+ const nextRgb = toRgbColor(nextColor);
+
+ let newColor: GradientStop["color"] | undefined;
+ if (prevRgb !== undefined && nextRgb !== undefined) {
+ const interpolationColor = colord(prevRgb)
+ .mix(colord(nextRgb), newPosition / 100)
+ .toRgb();
+ newColor = {
+ type: "rgb",
+ alpha: interpolationColor.a,
+ r: interpolationColor.r,
+ g: interpolationColor.g,
+ b: interpolationColor.b,
+ };
+ } else if (prevColor !== undefined) {
+ newColor = cloneColor(prevColor);
+ } else if (nextColor !== undefined) {
+ newColor = cloneColor(nextColor);
+ } else {
+ newColor = { ...defaultStopColor };
}
- const interpolationColor =
- prevColor !== undefined && nextColor !== undefined
- ? colord(toValue(prevColor))
- .mix(colord(toValue(nextColor)), newPosition / 100)
- .toRgb()
- : colord(toValue((prevColor ?? nextColor)!)).toRgb();
-
- const newColorStop: RgbValue = {
- type: "rgb",
- alpha: interpolationColor.a,
- r: interpolationColor.r,
- g: interpolationColor.g,
- b: interpolationColor.b,
- };
-
const newStop: GradientStop = {
- color: newColorStop,
+ color: newColor,
position: { type: "unit", value: newPosition, unit: "%" },
};
@@ -313,20 +585,20 @@ export const GradientPicker = (props: GradientPickerProps) => {
nextSelection = { index: insertionIndex, stop: newStop };
return nextStops;
- });
+ }, "complete");
if (nextSelection !== undefined) {
setSelectedStop(nextSelection.index);
- onThumbSelected(nextSelection.index, nextSelection.stop);
+ onThumbSelect(nextSelection.index, nextSelection.stop);
}
setIsHoveredOnStop(true);
},
- [checkIfStopExistsAtPosition, onThumbSelected, updateStops]
+ [checkIfStopExistsAtPosition, onThumbSelect, updateStops]
);
const handleMouseIndicator = useCallback(
- (event: ReactMouseEvent<HTMLDivElement>) => {
+ (event: MouseEvent<HTMLDivElement>) => {
const { isStopExistingAtPosition } = checkIfStopExistsAtPosition(
event.clientX
);
@@ -336,40 +608,44 @@ export const GradientPicker = (props: GradientPickerProps) => {
);
const handleSliderFocus = useCallback(() => {
- if (selectedStop !== undefined || stops.length === 0) {
+ if (stops.length === 0) {
return;
}
- const [firstStop] = stops;
- if (firstStop !== undefined) {
- handleStopSelected(0, firstStop);
+ // Always ensure a stop is selected when focusing
+ if (selectedStop === undefined) {
+ const [firstStop] = stops;
+ if (firstStop !== undefined) {
+ handleStopSelected(0, firstStop);
+ }
}
}, [handleStopSelected, selectedStop, stops]);
if (
stops.some(
- (stop) => stop.position === undefined || stop.color === undefined
+ (stop) =>
+ stop.color === undefined ||
+ stop.position?.type !== "unit" ||
+ stop.position.unit !== "%"
)
) {
- return null;
+ return;
}
return (
<Flex
align="end"
- css={{
- height: theme.spacing[18],
- }}
+ css={{ height: theme.spacing[16] }}
+ onKeyDown={handleKeyDown}
>
<SliderRoot
ref={sliderRef}
- css={{ background }}
+ css={{ backgroundImage }}
isHoveredOnStop={isHoveredOnStop}
tabIndex={0}
role="group"
aria-label="Gradient stops"
onPointerDown={handlePointerDown}
- onKeyDown={handleKeyDown}
onFocus={handleSliderFocus}
onMouseEnter={handleMouseIndicator}
onMouseMove={handleMouseIndicator}
@@ -377,17 +653,23 @@ export const GradientPicker = (props: GradientPickerProps) => {
>
<SliderTrack />
{stops.map((stop, index) => {
- if (stop.color === undefined || stop.position === undefined) {
- return null;
+ const isSelected = selectedStop === index;
+ if (
+ stop.color === undefined ||
+ stop.position?.type !== "unit" ||
+ stop.position.unit !== "%"
+ ) {
+ return;
}
+ const stopColor = stop.color as StyleValue;
+
return (
<SliderThumb
key={index}
data-thumb="true"
style={{
left: `${stop.position.value}%`,
- background: toValue(stop.color),
}}
role="slider"
aria-orientation="horizontal"
@@ -395,31 +677,54 @@ export const GradientPicker = (props: GradientPickerProps) => {
aria-valuemax={100}
aria-valuenow={stop.position.value}
aria-label={`Gradient stop ${index + 1}`}
+ aria-selected={isSelected}
tabIndex={-1}
+ ref={(element) => {
+ thumbRefs.current[index] = element;
+ }}
onPointerDown={handleThumbPointerDown(index, stop)}
- onClick={() => handleStopSelected(index, stop)}
+ onClick={() => {
+ handleStopSelected(index, stop);
+ }}
>
- <SliderThumbTrigger data-thumb="true" />
+ <ColorPickerPopover
+ value={stopColor}
+ onChange={(value) =>
+ handleStopColorChange(index, value, "change")
+ }
+ onChangeComplete={(value) =>
+ handleStopColorChange(index, value, "complete")
+ }
+ open={colorPickerOpenStop === index}
+ onOpenChange={(open) =>
+ handleColorPickerOpenChange(index, open)
+ }
+ sideOffset={SLIDER_HEIGHT + THUMB_HEIGHT}
+ thumb={
+ <ColorThumb
+ color={
+ stop.color ? styleValueToRgbaColor(stop.color) : undefined
+ }
+ interactive={true}
+ css={{
+ margin: 1,
+ width: THUMB_HEIGHT,
+ height: THUMB_HEIGHT,
+ }}
+ data-thumb="true"
+ />
+ }
+ />
+ <SliderThumbPointer aria-hidden />
</SliderThumb>
);
})}
- {hints.map((hint) => {
- return (
- <Flex
- key={hint}
- align="center"
- justify="center"
- css={{
- position: "absolute",
- left: `${hint}%`,
- top: theme.spacing[9],
- }}
- >
- <ChevronFilledUpIcon />
- </Flex>
- );
- })}
+ {hints.map((hint) => (
+ <SliderHint key={hint} css={{ left: `${hint}%` }}>
+ <ChevronFilledUpIcon size="100%" />
+ </SliderHint>
+ ))}
</SliderRoot>
</Flex>
);
@@ -428,12 +733,21 @@ export const GradientPicker = (props: GradientPickerProps) => {
const SliderRoot = styled("div", {
position: "relative",
width: "100%",
- height: theme.spacing[9],
+ height: SLIDER_HEIGHT,
border: `1px solid ${theme.colors.borderMain}`,
borderRadius: theme.borderRadius[3],
touchAction: "none",
userSelect: "none",
outline: "none",
+ "&::before": {
+ content: '""',
+ position: "absolute",
+ inset: 0,
+ background: `repeating-conic-gradient(rgba(0,0,0,0.22) 0% 25%, transparent 0% 50%) 0% 33.33% / 40% 40%`,
+ pointerEvents: "none",
+ backgroundSize: "10px 10px",
+ zIndex: -1,
+ },
variants: {
isHoveredOnStop: {
true: {
@@ -445,7 +759,7 @@ const SliderRoot = styled("div", {
},
},
"&:focus-visible": {
- boxShadow: `0 0 0 2px ${theme.colors.borderFocus}`,
+ boxShadow: `0 0 0 1px ${theme.colors.borderFocus}`,
},
});
@@ -454,37 +768,55 @@ const SliderTrack = styled("div", {
inset: 0,
borderRadius: theme.borderRadius[3],
pointerEvents: "none",
+ isolation: "isolate",
});
const SliderThumb = styled(Box, {
+ "--thumb-border-color": theme.colors.borderMain,
position: "absolute",
- display: "block",
- transform: `translate(-50%, calc(-1 * ${theme.spacing[9]} - 10px))`,
- outline: `3px solid ${theme.colors.borderFocus}`,
- borderRadius: theme.borderRadius[5],
- outlineOffset: -3,
+ display: "grid",
+ placeItems: "center",
+ bottom: `calc(100% + ${theme.spacing[6]})`,
+ transform: "translateX(-50%)",
+ borderRadius: theme.borderRadius[2],
+ boxShadow: `0 0 0 1px var(--thumb-border-color)`,
+ outline: "none",
zIndex: 1,
cursor: "grab",
"&:active": {
cursor: "grabbing",
},
- "&::before": {
- content: "''",
- position: "absolute",
- borderLeft: "5px solid transparent",
- borderRight: "5px solid transparent",
- borderTop: `5px solid ${theme.colors.borderFocus}`,
- bottom: -5,
- marginLeft: "50%",
- transform: "translateX(-50%)",
+ "&:focus-visible, &[aria-selected=true]": {
+ "--thumb-border-color": theme.colors.borderFocus,
+ boxShadow: `0 0 0 1px ${theme.colors.borderFocus}`,
},
});
-const SliderThumbTrigger = styled(Box, {
- width: theme.spacing[10],
- height: theme.spacing[10],
- borderRadius: theme.borderRadius[4],
- backgroundColor: "inherit",
+const SliderThumbPointer = styled("div", {
+ position: "absolute",
+ width: theme.spacing[3],
+ height: theme.spacing[3],
+ left: "50%",
+ bottom: 0,
+ background: "white",
+ zIndex: -1,
+ border: `1px solid var(--thumb-border-color)`,
+ borderTopColor: "transparent",
+ borderLeftColor: "transparent",
+ borderRadius: theme.borderRadius[1],
+ transform: "translate(-50%, 50%) rotate(45deg)",
+ pointerEvents: "none",
+});
+
+const SliderHint = styled(Flex, {
+ position: "absolute",
+ top: `calc(-1 * ${theme.spacing[6]})`,
+ width: theme.spacing[7],
+ height: theme.spacing[7],
+ pointerEvents: "none",
+ transform: "translateX(-50%)",
+ alignItems: "center",
+ justifyContent: "center",
});
export type { GradientPickerProps };
diff --git a/packages/design-system/src/components/position-grid.tsx b/packages/design-system/src/components/position-grid.tsx
index 4b887e4e71..8478ccf3a8 100644
--- a/packages/design-system/src/components/position-grid.tsx
+++ b/packages/design-system/src/components/position-grid.tsx
@@ -33,7 +33,7 @@ const toNumericPosition = (position?: MixedPosition) => {
const containerStyle = css({
background: theme.colors.backgroundControls,
- padding: theme.spacing[4],
+ padding: theme.spacing[3],
width: "fit-content",
borderRadius: theme.borderRadius[4],
border: `1px solid transparent`,
@@ -50,7 +50,8 @@ const containerStyle = css({
});
const dotStyle = css({
- padding: theme.spacing[5],
+ padding: theme.spacing[4],
+ margin: 1,
background: theme.colors.backgroundControls,
border: `1px solid transparent`,
borderRadius: theme.borderRadius[4],
diff --git a/packages/design-system/src/index.ts b/packages/design-system/src/index.ts
index fa609fc9a2..80a822d619 100644
--- a/packages/design-system/src/index.ts
+++ b/packages/design-system/src/index.ts
@@ -49,6 +49,7 @@ export * from "./components/focus-ring";
export * from "./components/tree";
export * from "./components/command";
export * from "./components/gradient-picker";
+export * from "./components/color-picker";
// Not aligned
diff --git a/packages/icons/generate.ts b/packages/icons/generate.ts
index 991be946ee..7fcf7b0845 100644
--- a/packages/icons/generate.ts
+++ b/packages/icons/generate.ts
@@ -1,9 +1,24 @@
import { mkdir, readdir, readFile, writeFile } from "node:fs/promises";
import { basename, extname } from "node:path";
+import { createHash } from "node:crypto";
import { type Config, optimize } from "svgo";
import { convertSvgToJsx } from "@svgo/jsx";
import { pascalCase } from "change-case";
+const prefixCache = new Map<string, string>();
+const getHashedPrefix = (path?: string) => {
+ if (path === undefined) {
+ return "svg";
+ }
+ const cached = prefixCache.get(path);
+ if (cached !== undefined) {
+ return cached;
+ }
+ const hash = createHash("sha256").update(path).digest("hex").slice(0, 8);
+ prefixCache.set(path, hash);
+ return hash;
+};
+
const sharedPlugins: Config["plugins"] = [
{
name: "preset-default",
@@ -13,11 +28,20 @@ const sharedPlugins: Config["plugins"] = [
removeViewBox: false,
convertTransform: false,
inlineStyles: false,
+ cleanupIds: false,
},
},
},
// convert width/height to viewBox if missing
{ name: "removeDimensions" },
+ {
+ name: "prefixIds",
+ params: {
+ prefix: (_node: unknown, info: { path?: string }) =>
+ getHashedPrefix(info.path),
+ prefixClassNames: false,
+ },
+ },
];
type GenerateOptions = {
@@ -28,6 +52,7 @@ type GenerateOptions = {
export const generateStringExport = (options: GenerateOptions) => {
const { data: optimized } = optimize(options.content, {
+ path: options.file,
plugins: [
...sharedPlugins,
{
diff --git a/packages/icons/icons/arrow-right-left.svg b/packages/icons/icons/arrow-right-left.svg
new file mode 100644
index 0000000000..a7e7b5e5c0
--- /dev/null
+++ b/packages/icons/icons/arrow-right-left.svg
@@ -0,0 +1,15 @@
+<svg
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+>
+ <path
+ d="M11 2L13.6667 4.66667M13.6667 4.66667L11 7.33333M13.6667 4.66667L3 4.66666M5.66667 14L3 11.3333M3 11.3333L5.66667 8.66666M3 11.3333L13.6667 11.3333"
+ stroke="currentColor"
+ stroke-width="0.666667"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ />
+</svg>
diff --git a/packages/icons/icons/circle.svg b/packages/icons/icons/circle.svg
new file mode 100644
index 0000000000..2ba61e4d35
--- /dev/null
+++ b/packages/icons/icons/circle.svg
@@ -0,0 +1,14 @@
+<svg
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+>
+ <path
+ fill-rule="evenodd"
+ clip-rule="evenodd"
+ d="M7.99998 3.65001C5.59754 3.65001 3.64998 5.59757 3.64998 8.00001C3.64998 10.4024 5.59754 12.35 7.99998 12.35C10.4024 12.35 12.35 10.4024 12.35 8.00001C12.35 5.59757 10.4024 3.65001 7.99998 3.65001ZM2.34998 8.00001C2.34998 4.8796 4.87957 2.35001 7.99998 2.35001C11.1204 2.35001 13.65 4.8796 13.65 8.00001C13.65 11.1204 11.1204 13.65 7.99998 13.65C4.87957 13.65 2.34998 11.1204 2.34998 8.00001Z"
+ fill="currentColor"
+ />
+</svg>
diff --git a/packages/icons/icons/ellipse.svg b/packages/icons/icons/ellipse.svg
new file mode 100644
index 0000000000..9cdd840b90
--- /dev/null
+++ b/packages/icons/icons/ellipse.svg
@@ -0,0 +1,14 @@
+<svg
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+>
+ <path
+ fill-rule="evenodd"
+ clip-rule="evenodd"
+ d="M3.37272 5.73594C2.20251 6.40462 1.64998 7.22936 1.64998 8.00001C1.64998 8.77065 2.20251 9.59539 3.37272 10.2641C4.52453 10.9223 6.15914 11.35 7.99998 11.35C9.84081 11.35 11.4754 10.9223 12.6272 10.2641C13.7974 9.59539 14.35 8.77065 14.35 8.00001C14.35 7.22936 13.7974 6.40462 12.6272 5.73594C11.4754 5.07776 9.84081 4.65001 7.99998 4.65001C6.15914 4.65001 4.52453 5.07776 3.37272 5.73594ZM2.72774 4.60722C4.10942 3.81769 5.97482 3.35001 7.99998 3.35001C10.0251 3.35001 11.8905 3.81769 13.2722 4.60722C14.6355 5.38625 15.65 6.56151 15.65 8.00001C15.65 9.4385 14.6355 10.6138 13.2722 11.3928C11.8905 12.1823 10.0251 12.65 7.99998 12.65C5.97482 12.65 4.10942 12.1823 2.72774 11.3928C1.36444 10.6138 0.349976 9.4385 0.349976 8.00001C0.349976 6.56151 1.36444 5.38625 2.72774 4.60722Z"
+ fill="currentColor"
+ />
+</svg>
diff --git a/packages/icons/icons/gradient-conic.svg b/packages/icons/icons/gradient-conic.svg
new file mode 100644
index 0000000000..90afbffadf
--- /dev/null
+++ b/packages/icons/icons/gradient-conic.svg
@@ -0,0 +1,31 @@
+<svg
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+>
+ <g clip-path="url(#paint0_angular_9413_9319_clip_path)">
+ <g fill="#11181C">
+ <path d="M8 8 L8 0 A8 8 0 0 1 12 1.072 Z" fill-opacity="1" />
+ <path d="M8 8 L12 1.072 A8 8 0 0 1 14.928 4 Z" fill-opacity="0.909" />
+ <path d="M8 8 L14.928 4 A8 8 0 0 1 16 8 Z" fill-opacity="0.818" />
+ <path d="M8 8 L16 8 A8 8 0 0 1 14.928 12 Z" fill-opacity="0.727" />
+ <path d="M8 8 L14.928 12 A8 8 0 0 1 12 14.928 Z" fill-opacity="0.636" />
+ <path d="M8 8 L12 14.928 A8 8 0 0 1 8 16 Z" fill-opacity="0.545" />
+ <path d="M8 8 L8 16 A8 8 0 0 1 4 14.928 Z" fill-opacity="0.455" />
+ <path d="M8 8 L4 14.928 A8 8 0 0 1 1.072 12 Z" fill-opacity="0.364" />
+ <path d="M8 8 L1.072 12 A8 8 0 0 1 0 8 Z" fill-opacity="0.273" />
+ <path d="M8 8 L0 8 A8 8 0 0 1 1.072 4 Z" fill-opacity="0.182" />
+ <path d="M8 8 L1.072 4 A8 8 0 0 1 4 1.072 Z" fill-opacity="0.091" />
+ <path d="M8 8 L4 1.072 A8 8 0 0 1 8 0 Z" fill-opacity="0" />
+ </g>
+ </g>
+ <defs>
+ <clipPath id="paint0_angular_9413_9319_clip_path">
+ <path
+ d="M2 5.2C2 4.07989 2 3.51984 2.21799 3.09202C2.40973 2.71569 2.71569 2.40973 3.09202 2.21799C3.51984 2 4.0799 2 5.2 2H10.8C11.9201 2 12.4802 2 12.908 2.21799C13.2843 2.40973 13.5903 2.71569 13.782 3.09202C14 3.51984 14 4.0799 14 5.2V10.8C14 11.9201 14 12.4802 13.782 12.908C13.5903 13.2843 13.2843 13.5903 12.908 13.782C12.4802 14 11.9201 14 10.8 14H5.2C4.07989 14 3.51984 14 3.09202 13.782C2.71569 13.5903 2.40973 13.2843 2.21799 12.908C2 12.4802 2 11.9201 2 10.8V5.2Z"
+ />
+ </clipPath>
+ </defs>
+</svg>
diff --git a/packages/icons/icons/gradient-linear.svg b/packages/icons/icons/gradient-linear.svg
new file mode 100644
index 0000000000..ac721c0181
--- /dev/null
+++ b/packages/icons/icons/gradient-linear.svg
@@ -0,0 +1,25 @@
+<svg
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+>
+ <path
+ d="M2 5.2C2 4.07989 2 3.51984 2.21799 3.09202C2.40973 2.71569 2.71569 2.40973 3.09202 2.21799C3.51984 2 4.0799 2 5.2 2H10.8C11.9201 2 12.4802 2 12.908 2.21799C13.2843 2.40973 13.5903 2.71569 13.782 3.09202C14 3.51984 14 4.0799 14 5.2V10.8C14 11.9201 14 12.4802 13.782 12.908C13.5903 13.2843 13.2843 13.5903 12.908 13.782C12.4802 14 11.9201 14 10.8 14H5.2C4.07989 14 3.51984 14 3.09202 13.782C2.71569 13.5903 2.40973 13.2843 2.21799 12.908C2 12.4802 2 11.9201 2 10.8V5.2Z"
+ fill="url(#gradient-linear_svg__a)"
+ />
+ <defs>
+ <linearGradient
+ id="gradient-linear_svg__a"
+ x1="8"
+ y1="2"
+ x2="8"
+ y2="14"
+ gradientUnits="userSpaceOnUse"
+ >
+ <stop offset="0" stop-color="#11181C" stop-opacity="1" />
+ <stop offset="1" stop-color="#11181C" stop-opacity="0" />
+ </linearGradient>
+ </defs>
+</svg>
diff --git a/packages/icons/icons/gradient-radial.svg b/packages/icons/icons/gradient-radial.svg
new file mode 100644
index 0000000000..7e4e4d4574
--- /dev/null
+++ b/packages/icons/icons/gradient-radial.svg
@@ -0,0 +1,25 @@
+<svg
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+>
+ <path
+ d="M2 5.2C2 4.07989 2 3.51984 2.21799 3.09202C2.40973 2.71569 2.71569 2.40973 3.09202 2.21799C3.51984 2 4.0799 2 5.2 2H10.8C11.9201 2 12.4802 2 12.908 2.21799C13.2843 2.40973 13.5903 2.71569 13.782 3.09202C14 3.51984 14 4.0799 14 5.2V10.8C14 11.9201 14 12.4802 13.782 12.908C13.5903 13.2843 13.2843 13.5903 12.908 13.782C12.4802 14 11.9201 14 10.8 14H5.2C4.07989 14 3.51984 14 3.09202 13.782C2.71569 13.5903 2.40973 13.2843 2.21799 12.908C2 12.4802 2 11.9201 2 10.8V5.2Z"
+ fill="url(#paint0_radial_9420_9425)"
+ />
+ <defs>
+ <radialGradient
+ id="paint0_radial_9420_9425"
+ cx="0"
+ cy="0"
+ r="1"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(8 8) rotate(135) scale(8.48528)"
+ >
+ <stop stop-color="#11181C" />
+ <stop offset="1" stop-color="#11181C" stop-opacity="0" />
+ </radialGradient>
+ </defs>
+</svg>
diff --git a/packages/icons/src/__generated__/components.tsx b/packages/icons/src/__generated__/components.tsx
index 48a1c059a4..7ab0e8eb57 100644
--- a/packages/icons/src/__generated__/components.tsx
+++ b/packages/icons/src/__generated__/components.tsx
@@ -60,7 +60,7 @@ export const AiLoadingIcon: IconComponent = forwardRef(
return (
<svg
xmlns="http://www.w3.org/2000/svg"
- id="evA4hI5dD261"
+ id="86546c68__evA4hI5dD261"
shapeRendering="geometricPrecision"
textRendering="geometricPrecision"
viewBox="0 0 17 17"
@@ -72,7 +72,7 @@ export const AiLoadingIcon: IconComponent = forwardRef(
>
<style>
{
- "@keyframes evA4hI5dD263_s_do{0%,to{stroke-dashoffset:6.2}17.5%,82.5%{stroke-dashoffset:-6.24}}@keyframes evA4hI5dD264_s_do{0%,10%,90%,to{stroke-dashoffset:6.8}22.5%,77.5%{stroke-dashoffset:-6.8}}@keyframes evA4hI5dD265_s_do{0%,17.5%,82.5%,to{stroke-dashoffset:2.32}27.5%,72.5%{stroke-dashoffset:-2.32}}@keyframes evA4hI5dD266_s_do{0%,22.5%,77.5%,to{stroke-dashoffset:2.47}32.5%,67.5%{stroke-dashoffset:-2.47}}@keyframes evA4hI5dD267_s_do{0%,27.5%,72.5%,to{stroke-dashoffset:5.42}40%,60%{stroke-dashoffset:-5.42}}@keyframes evA4hI5dD268_s_do{0%,32.5%,67.5%,to{stroke-dashoffset:6.13}50%{stroke-dashoffset:-6.1}}#evA4hI5dD263{animation:evA4hI5dD263_s_do 4000ms linear infinite normal forwards}#evA4hI5dD264{animation:evA4hI5dD264_s_do 4000ms linear infinite normal forwards}#evA4hI5dD265{animation:evA4hI5dD265_s_do 4000ms linear infinite normal forwards}#evA4hI5dD266{animation:evA4hI5dD266_s_do 4000ms linear infinite normal forwards}#evA4hI5dD267{animation:evA4hI5dD267_s_do 4000ms linear infinite normal forwards}#evA4hI5dD268{animation:evA4hI5dD268_s_do 4000ms linear infinite normal forwards}"
+ "@keyframes evA4hI5dD263_s_do{0%,to{stroke-dashoffset:6.2}17.5%,82.5%{stroke-dashoffset:-6.24}}@keyframes evA4hI5dD264_s_do{0%,10%,90%,to{stroke-dashoffset:6.8}22.5%,77.5%{stroke-dashoffset:-6.8}}@keyframes evA4hI5dD265_s_do{0%,17.5%,82.5%,to{stroke-dashoffset:2.32}27.5%,72.5%{stroke-dashoffset:-2.32}}@keyframes evA4hI5dD266_s_do{0%,22.5%,77.5%,to{stroke-dashoffset:2.47}32.5%,67.5%{stroke-dashoffset:-2.47}}@keyframes evA4hI5dD267_s_do{0%,27.5%,72.5%,to{stroke-dashoffset:5.42}40%,60%{stroke-dashoffset:-5.42}}@keyframes evA4hI5dD268_s_do{0%,32.5%,67.5%,to{stroke-dashoffset:6.13}50%{stroke-dashoffset:-6.1}}#86546c68__evA4hI5dD263{animation:evA4hI5dD263_s_do 4000ms linear infinite normal forwards}#86546c68__evA4hI5dD264{animation:evA4hI5dD264_s_do 4000ms linear infinite normal forwards}#86546c68__evA4hI5dD265{animation:evA4hI5dD265_s_do 4000ms linear infinite normal forwards}#86546c68__evA4hI5dD266{animation:evA4hI5dD266_s_do 4000ms linear infinite normal forwards}#86546c68__evA4hI5dD267{animation:evA4hI5dD267_s_do 4000ms linear infinite normal forwards}#86546c68__evA4hI5dD268{animation:evA4hI5dD268_s_do 4000ms linear infinite normal forwards}"
}
</style>
<path
@@ -84,7 +84,7 @@ export const AiLoadingIcon: IconComponent = forwardRef(
d="m2.816 12.956 1.513-6.051a2.563 2.563 0 0 1 4.974 0l1.159 4.634a1.888 1.888 0 0 0 1.816 1.417 1.892 1.892 0 0 0 1.872-1.872V4.956"
/>
<path
- id="evA4hI5dD263"
+ id="86546c68__evA4hI5dD263"
fill="none"
stroke="#fff"
strokeDasharray="6.24"
@@ -94,7 +94,7 @@ export const AiLoadingIcon: IconComponent = forwardRef(
d="m2.816 12.956 1.513-6.051"
/>
<path
- id="evA4hI5dD264"
+ id="86546c68__evA4hI5dD264"
fill="none"
stroke="#fff"
strokeDasharray="6.8"
@@ -104,7 +104,7 @@ export const AiLoadingIcon: IconComponent = forwardRef(
d="M4.329 6.905a2.563 2.563 0 0 1 4.974 0"
/>
<path
- id="evA4hI5dD265"
+ id="86546c68__evA4hI5dD265"
fill="none"
stroke="#fff"
strokeDasharray="2.32"
@@ -114,7 +114,7 @@ export const AiLoadingIcon: IconComponent = forwardRef(
d="m9.303 6.905.561 2.243"
/>
<path
- id="evA4hI5dD266"
+ id="86546c68__evA4hI5dD266"
fill="none"
stroke="#fff"
strokeDasharray="2.47"
@@ -124,7 +124,7 @@ export const AiLoadingIcon: IconComponent = forwardRef(
d="m9.864 9.148.598 2.391"
/>
<path
- id="evA4hI5dD267"
+ id="86546c68__evA4hI5dD267"
fill="none"
stroke="#fff"
strokeDasharray="5.42"
@@ -134,7 +134,7 @@ export const AiLoadingIcon: IconComponent = forwardRef(
d="M10.462 11.54a1.888 1.888 0 0 0 1.816 1.416 1.892 1.892 0 0 0 1.872-1.872"
/>
<path
- id="evA4hI5dD268"
+ id="86546c68__evA4hI5dD268"
fill="none"
stroke="#fff"
strokeDasharray="6.13"
@@ -818,6 +818,31 @@ export const ArrowLeftIcon: IconComponent = forwardRef(
);
ArrowLeftIcon.displayName = "ArrowLeftIcon";
+export const ArrowRightLeftIcon: IconComponent = forwardRef(
+ ({ fill = "none", size = 16, ...props }, forwardedRef) => {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 16 16"
+ width={size}
+ height={size}
+ fill={fill}
+ {...props}
+ ref={forwardedRef}
+ >
+ <path
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth=".667"
+ d="m11 2 2.667 2.667m0 0L11 7.333m2.667-2.666H3M5.667 14 3 11.333m0 0 2.667-2.666M3 11.333h10.667"
+ />
+ </svg>
+ );
+ }
+);
+ArrowRightLeftIcon.displayName = "ArrowRightLeftIcon";
+
export const ArrowRightIcon: IconComponent = forwardRef(
({ fill = "none", size = 16, ...props }, forwardedRef) => {
return (
@@ -1600,14 +1625,17 @@ export const ChevronLeftIcon: IconComponent = forwardRef(
{...props}
ref={forwardedRef}
>
- <path
- fill="none"
- stroke="currentColor"
- strokeLinecap="round"
- strokeLinejoin="round"
- strokeWidth="1.3"
- d="m9.256 4.499-3.512 3.5 3.512 3.502"
- />
+ <g id="1893fb9d__icon/chevron left">
+ <path
+ id="1893fb9d__vector"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.3"
+ d="m9.256 4.499-3.512 3.5 3.512 3.502"
+ />
+ </g>
</svg>
);
}
@@ -1686,6 +1714,30 @@ export const ChevronsLeftIcon: IconComponent = forwardRef(
);
ChevronsLeftIcon.displayName = "ChevronsLeftIcon";
+export const CircleIcon: IconComponent = forwardRef(
+ ({ fill = "none", size = 16, ...props }, forwardedRef) => {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 16 16"
+ width={size}
+ height={size}
+ fill={fill}
+ {...props}
+ ref={forwardedRef}
+ >
+ <path
+ fill="currentColor"
+ fillRule="evenodd"
+ d="M8 3.65a4.35 4.35 0 1 0 0 8.7 4.35 4.35 0 0 0 0-8.7ZM2.35 8a5.65 5.65 0 1 1 11.3 0 5.65 5.65 0 0 1-11.3 0Z"
+ clipRule="evenodd"
+ />
+ </svg>
+ );
+ }
+);
+CircleIcon.displayName = "CircleIcon";
+
export const CloudIcon: IconComponent = forwardRef(
({ fill = "none", size = 16, ...props }, forwardedRef) => {
return (
@@ -2165,6 +2217,30 @@ export const DynamicPageIcon: IconComponent = forwardRef(
);
DynamicPageIcon.displayName = "DynamicPageIcon";
+export const EllipseIcon: IconComponent = forwardRef(
+ ({ fill = "none", size = 16, ...props }, forwardedRef) => {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 16 16"
+ width={size}
+ height={size}
+ fill={fill}
+ {...props}
+ ref={forwardedRef}
+ >
+ <path
+ fill="currentColor"
+ fillRule="evenodd"
+ d="M3.373 5.736C2.203 6.405 1.65 7.229 1.65 8c0 .77.553 1.595 1.723 2.264C4.525 10.922 6.159 11.35 8 11.35c1.84 0 3.475-.428 4.627-1.086C13.797 9.595 14.35 8.771 14.35 8c0-.77-.553-1.595-1.723-2.264C11.475 5.078 9.841 4.65 8 4.65c-1.84 0-3.475.428-4.627 1.086Zm-.645-1.129C4.109 3.817 5.975 3.35 8 3.35c2.025 0 3.89.468 5.272 1.257 1.364.78 2.378 1.955 2.378 3.393 0 1.438-1.014 2.614-2.378 3.393-1.382.79-3.247 1.257-5.272 1.257-2.025 0-3.89-.468-5.272-1.257C1.364 10.613.35 9.438.35 8c0-1.438 1.014-2.614 2.378-3.393Z"
+ clipRule="evenodd"
+ />
+ </svg>
+ );
+ }
+);
+EllipseIcon.displayName = "EllipseIcon";
+
export const EllipsesIcon: IconComponent = forwardRef(
({ fill = "none", size = 16, ...props }, forwardedRef) => {
return (
@@ -2647,6 +2723,116 @@ export const GoogleIcon: IconComponent = forwardRef(
);
GoogleIcon.displayName = "GoogleIcon";
+export const GradientConicIcon: IconComponent = forwardRef(
+ ({ fill = "none", size = 16, ...props }, forwardedRef) => {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 16 16"
+ width={size}
+ height={size}
+ fill={fill}
+ {...props}
+ ref={forwardedRef}
+ >
+ <g
+ fill="#11181C"
+ clipPath="url(#15388f97__paint0_angular_9413_9319_clip_path)"
+ >
+ <path d="M8 8V0a8 8 0 0 1 4 1.072Z" />
+ <path fillOpacity=".909" d="m8 8 4-6.928A8 8 0 0 1 14.928 4Z" />
+ <path fillOpacity=".818" d="m8 8 6.928-4A8 8 0 0 1 16 8Z" />
+ <path fillOpacity=".727" d="M8 8h8a8 8 0 0 1-1.072 4Z" />
+ <path fillOpacity=".636" d="m8 8 6.928 4A8 8 0 0 1 12 14.928Z" />
+ <path fillOpacity=".545" d="m8 8 4 6.928A8 8 0 0 1 8 16Z" />
+ <path fillOpacity=".455" d="M8 8v8a8 8 0 0 1-4-1.072Z" />
+ <path fillOpacity=".364" d="m8 8-4 6.928A8 8 0 0 1 1.072 12Z" />
+ <path fillOpacity=".273" d="m8 8-6.928 4A8 8 0 0 1 0 8Z" />
+ <path fillOpacity=".182" d="M8 8H0a8 8 0 0 1 1.072-4Z" />
+ <path fillOpacity=".091" d="M8 8 1.072 4A8 8 0 0 1 4 1.072Z" />
+ <path fill="none" d="M8 8 4 1.072A8 8 0 0 1 8 0Z" />
+ </g>
+ <defs>
+ <clipPath id="15388f97__paint0_angular_9413_9319_clip_path">
+ <path d="M2 5.2c0-1.12 0-1.68.218-2.108a2 2 0 0 1 .874-.874C3.52 2 4.08 2 5.2 2h5.6c1.12 0 1.68 0 2.108.218a2 2 0 0 1 .874.874C14 3.52 14 4.08 14 5.2v5.6c0 1.12 0 1.68-.218 2.108a2 2 0 0 1-.874.874C12.48 14 11.92 14 10.8 14H5.2c-1.12 0-1.68 0-2.108-.218a2 2 0 0 1-.874-.874C2 12.48 2 11.92 2 10.8V5.2Z" />
+ </clipPath>
+ </defs>
+ </svg>
+ );
+ }
+);
+GradientConicIcon.displayName = "GradientConicIcon";
+
+export const GradientLinearIcon: IconComponent = forwardRef(
+ ({ fill = "none", size = 16, ...props }, forwardedRef) => {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 16 16"
+ width={size}
+ height={size}
+ fill={fill}
+ {...props}
+ ref={forwardedRef}
+ >
+ <path
+ fill="url(#1fa533d5__gradient-linear_svg__a)"
+ d="M2 5.2c0-1.12 0-1.68.218-2.108a2 2 0 0 1 .874-.874C3.52 2 4.08 2 5.2 2h5.6c1.12 0 1.68 0 2.108.218a2 2 0 0 1 .874.874C14 3.52 14 4.08 14 5.2v5.6c0 1.12 0 1.68-.218 2.108a2 2 0 0 1-.874.874C12.48 14 11.92 14 10.8 14H5.2c-1.12 0-1.68 0-2.108-.218a2 2 0 0 1-.874-.874C2 12.48 2 11.92 2 10.8V5.2Z"
+ />
+ <defs>
+ <linearGradient
+ id="1fa533d5__gradient-linear_svg__a"
+ x1="8"
+ x2="8"
+ y1="2"
+ y2="14"
+ gradientUnits="userSpaceOnUse"
+ >
+ <stop offset="0" stopColor="#11181C" />
+ <stop offset="1" stopColor="#11181C" stopOpacity="0" />
+ </linearGradient>
+ </defs>
+ </svg>
+ );
+ }
+);
+GradientLinearIcon.displayName = "GradientLinearIcon";
+
+export const GradientRadialIcon: IconComponent = forwardRef(
+ ({ fill = "none", size = 16, ...props }, forwardedRef) => {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 16 16"
+ width={size}
+ height={size}
+ fill={fill}
+ {...props}
+ ref={forwardedRef}
+ >
+ <path
+ fill="url(#539a7588__paint0_radial_9420_9425)"
+ d="M2 5.2c0-1.12 0-1.68.218-2.108a2 2 0 0 1 .874-.874C3.52 2 4.08 2 5.2 2h5.6c1.12 0 1.68 0 2.108.218a2 2 0 0 1 .874.874C14 3.52 14 4.08 14 5.2v5.6c0 1.12 0 1.68-.218 2.108a2 2 0 0 1-.874.874C12.48 14 11.92 14 10.8 14H5.2c-1.12 0-1.68 0-2.108-.218a2 2 0 0 1-.874-.874C2 12.48 2 11.92 2 10.8V5.2Z"
+ />
+ <defs>
+ <radialGradient
+ id="539a7588__paint0_radial_9420_9425"
+ cx="0"
+ cy="0"
+ r="1"
+ gradientTransform="translate(8 8) rotate(135) scale(8.48528)"
+ gradientUnits="userSpaceOnUse"
+ >
+ <stop stopColor="#11181C" />
+ <stop offset="1" stopColor="#11181C" stopOpacity="0" />
+ </radialGradient>
+ </defs>
+ </svg>
+ );
+ }
+);
+GradientRadialIcon.displayName = "GradientRadialIcon";
+
export const GrowIcon: IconComponent = forwardRef(
({ fill = "none", size = 16, ...props }, forwardedRef) => {
return (
@@ -3170,7 +3356,7 @@ export const LoadingDotsIcon: IconComponent = forwardRef(
return (
<svg
xmlns="http://www.w3.org/2000/svg"
- id="eEMFTOz1Zbw1"
+ id="fdbcf7a5__eEMFTOz1Zbw1"
shapeRendering="geometricPrecision"
textRendering="geometricPrecision"
viewBox="0 0 300 300"
@@ -3182,23 +3368,23 @@ export const LoadingDotsIcon: IconComponent = forwardRef(
>
<style>
{
- "@keyframes eEMFTOz1Zbw12_to__to{0%,26.666667%,56.666667%,6.333333%,77%,to{transform:translate(150px,180px)}16.666667%,67%{transform:translate(150px,120px);animation-timing-function:cubic-bezier(.42,0,.58,1)}}@keyframes eEMFTOz1Zbw13_to__to{0%,20%,50%,70%,to{transform:translate(80px,180px)}10%,60%{transform:translate(80px,120px);animation-timing-function:cubic-bezier(.42,0,.58,1)}}@keyframes eEMFTOz1Zbw14_to__to{0%,13.333333%,33.333333%,63.333333%,83.333333%,to{transform:translate(220px,180px)}23.333333%,73.333333%{transform:translate(220px,120px);animation-timing-function:cubic-bezier(.42,0,.58,1)}}#eEMFTOz1Zbw12_to{animation:eEMFTOz1Zbw12_to__to 2000ms linear infinite normal forwards}#eEMFTOz1Zbw13_to{animation:eEMFTOz1Zbw13_to__to 2000ms linear infinite normal forwards}#eEMFTOz1Zbw14_to{animation:eEMFTOz1Zbw14_to__to 2000ms linear infinite normal forwards}"
+ "@keyframes eEMFTOz1Zbw12_to__to{0%,26.666667%,56.666667%,6.333333%,77%,to{transform:translate(150px,180px)}16.666667%,67%{transform:translate(150px,120px);animation-timing-function:cubic-bezier(.42,0,.58,1)}}@keyframes eEMFTOz1Zbw13_to__to{0%,20%,50%,70%,to{transform:translate(80px,180px)}10%,60%{transform:translate(80px,120px);animation-timing-function:cubic-bezier(.42,0,.58,1)}}@keyframes eEMFTOz1Zbw14_to__to{0%,13.333333%,33.333333%,63.333333%,83.333333%,to{transform:translate(220px,180px)}23.333333%,73.333333%{transform:translate(220px,120px);animation-timing-function:cubic-bezier(.42,0,.58,1)}}#fdbcf7a5__eEMFTOz1Zbw12_to{animation:eEMFTOz1Zbw12_to__to 2000ms linear infinite normal forwards}#fdbcf7a5__eEMFTOz1Zbw13_to{animation:eEMFTOz1Zbw13_to__to 2000ms linear infinite normal forwards}#fdbcf7a5__eEMFTOz1Zbw14_to{animation:eEMFTOz1Zbw14_to__to 2000ms linear infinite normal forwards}"
}
</style>
<circle
- id="eEMFTOz1Zbw12_to"
+ id="fdbcf7a5__eEMFTOz1Zbw12_to"
r="20"
strokeWidth="0"
transform="translate(150,180) translate(0,0)"
/>
<circle
- id="eEMFTOz1Zbw13_to"
+ id="fdbcf7a5__eEMFTOz1Zbw13_to"
r="20"
strokeWidth="0"
transform="translate(80,180) translate(0,0)"
/>
<circle
- id="eEMFTOz1Zbw14_to"
+ id="fdbcf7a5__eEMFTOz1Zbw14_to"
r="20"
strokeWidth="0"
transform="translate(220,180) translate(0,0)"
@@ -4436,7 +4622,7 @@ export const SpinnerIcon: IconComponent = forwardRef(
return (
<svg
xmlns="http://www.w3.org/2000/svg"
- id="e2CRglijn891"
+ id="765c5cf3__e2CRglijn891"
shapeRendering="geometricPrecision"
textRendering="geometricPrecision"
viewBox="0 0 128 128"
@@ -4448,12 +4634,15 @@ export const SpinnerIcon: IconComponent = forwardRef(
>
<style>
{
- "@keyframes e2CRglijn892_tr__tr{0%{transform:translate(64px,64px) rotate(90deg);animation-timing-function:cubic-bezier(.42,0,.58,1)}50%{transform:translate(64px,64px) rotate(810deg);animation-timing-function:cubic-bezier(.42,0,.58,1)}to{transform:translate(64px,64px) rotate(1530deg)}}@keyframes e2CRglijn892_s_p{0%,to{stroke:#39fbbb}25%{stroke:#4a4efa}50%{stroke:#e63cfe}75%{stroke:#ffae3c}}@keyframes e2CRglijn892_s_do{0%{stroke-dashoffset:251.89}2.5%,52.5%{stroke-dashoffset:263.88;animation-timing-function:cubic-bezier(.42,0,.58,1)}25%,75%{stroke-dashoffset:131.945}to{stroke-dashoffset:251.885909}}#e2CRglijn892_tr{animation:e2CRglijn892_tr__tr 3000ms linear infinite normal forwards}#e2CRglijn892{animation-name:e2CRglijn892_s_p,e2CRglijn892_s_do;animation-duration:3000ms;animation-fill-mode:forwards;animation-timing-function:linear;animation-direction:normal;animation-iteration-count:infinite}"
+ "@keyframes e2CRglijn892_tr__tr{0%{transform:translate(64px,64px) rotate(90deg);animation-timing-function:cubic-bezier(.42,0,.58,1)}50%{transform:translate(64px,64px) rotate(810deg);animation-timing-function:cubic-bezier(.42,0,.58,1)}to{transform:translate(64px,64px) rotate(1530deg)}}@keyframes e2CRglijn892_s_p{0%,to{stroke:#39fbbb}25%{stroke:#4a4efa}50%{stroke:#e63cfe}75%{stroke:#ffae3c}}@keyframes e2CRglijn892_s_do{0%{stroke-dashoffset:251.89}2.5%,52.5%{stroke-dashoffset:263.88;animation-timing-function:cubic-bezier(.42,0,.58,1)}25%,75%{stroke-dashoffset:131.945}to{stroke-dashoffset:251.885909}}#765c5cf3__e2CRglijn892_tr{animation:e2CRglijn892_tr__tr 3000ms linear infinite normal forwards}#765c5cf3__e2CRglijn892{animation-name:e2CRglijn892_s_p,e2CRglijn892_s_do;animation-duration:3000ms;animation-fill-mode:forwards;animation-timing-function:linear;animation-direction:normal;animation-iteration-count:infinite}"
}
</style>
- <g id="e2CRglijn892_tr" transform="translate(64,64) rotate(90)">
+ <g
+ id="765c5cf3__e2CRglijn892_tr"
+ transform="translate(64,64) rotate(90)"
+ >
<circle
- id="e2CRglijn892"
+ id="765c5cf3__e2CRglijn892"
r="42"
fill="none"
stroke="#39fbbb"
@@ -5292,38 +5481,38 @@ export const WebstudioIcon: IconComponent = forwardRef(
ref={forwardedRef}
>
<path
- fill="url(#a)"
+ fill="url(#69f97277__paint0_linear_5232_4740)"
fillRule="evenodd"
d="m12.32 12.416 2.62-8.085a1.205 1.205 0 1 0-2.292-.746l-2.62 8.084a1.205 1.205 0 1 0 2.292.747Z"
clipRule="evenodd"
/>
<path
- fill="url(#b)"
+ fill="url(#69f97277__paint1_linear_5232_4740)"
fillRule="evenodd"
d="m12.32 12.416 2.62-8.085a1.205 1.205 0 1 0-2.292-.746l-2.62 8.084a1.205 1.205 0 1 0 2.292.747Z"
clipRule="evenodd"
/>
<path
- fill="url(#c)"
+ fill="url(#69f97277__paint2_linear_5232_4740)"
fillOpacity=".8"
fillRule="evenodd"
d="m12.32 12.416 2.62-8.085a1.205 1.205 0 1 0-2.292-.746l-2.62 8.084a1.205 1.205 0 1 0 2.292.747Z"
clipRule="evenodd"
/>
<path
- fill="url(#d)"
+ fill="url(#69f97277__paint3_radial_5232_4740)"
fillRule="evenodd"
d="m12.32 12.416 2.62-8.085a1.205 1.205 0 1 0-2.292-.746l-2.62 8.084a1.205 1.205 0 1 0 2.292.747Z"
clipRule="evenodd"
/>
<path
- fill="url(#e)"
+ fill="url(#69f97277__paint4_radial_5232_4740)"
fillRule="evenodd"
d="m12.32 12.416 2.62-8.085a1.205 1.205 0 1 0-2.292-.746l-2.62 8.084a1.205 1.205 0 1 0 2.292.747Z"
clipRule="evenodd"
/>
<path
- fill="url(#f)"
+ fill="url(#69f97277__paint5_radial_5232_4740)"
fillRule="evenodd"
d="m12.32 12.416 2.62-8.085a1.205 1.205 0 1 0-2.292-.746l-2.62 8.084a1.205 1.205 0 1 0 2.292.747Z"
clipRule="evenodd"
@@ -5335,86 +5524,86 @@ export const WebstudioIcon: IconComponent = forwardRef(
clipRule="evenodd"
/>
<path
- fill="url(#g)"
+ fill="url(#69f97277__paint6_radial_5232_4740)"
fillRule="evenodd"
d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z"
clipRule="evenodd"
/>
<path
- fill="url(#h)"
+ fill="url(#69f97277__paint7_radial_5232_4740)"
fillRule="evenodd"
d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z"
clipRule="evenodd"
/>
<path
- fill="url(#i)"
+ fill="url(#69f97277__paint8_radial_5232_4740)"
fillRule="evenodd"
d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z"
clipRule="evenodd"
/>
<path
- fill="url(#j)"
+ fill="url(#69f97277__paint9_radial_5232_4740)"
fillRule="evenodd"
d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z"
clipRule="evenodd"
/>
<path
- fill="url(#k)"
+ fill="url(#69f97277__paint10_radial_5232_4740)"
fillRule="evenodd"
d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z"
clipRule="evenodd"
/>
<path
- fill="url(#l)"
+ fill="url(#69f97277__paint11_radial_5232_4740)"
fillRule="evenodd"
d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z"
clipRule="evenodd"
/>
<path
- fill="url(#m)"
+ fill="url(#69f97277__paint12_radial_5232_4740)"
fillRule="evenodd"
d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z"
clipRule="evenodd"
/>
<path
- fill="url(#n)"
+ fill="url(#69f97277__paint13_radial_5232_4740)"
fillRule="evenodd"
d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z"
clipRule="evenodd"
/>
<path
- fill="url(#o)"
+ fill="url(#69f97277__paint14_linear_5232_4740)"
fillRule="evenodd"
d="M5.973 11.669 3.352 3.585a1.205 1.205 0 1 0-2.293.746l2.622 8.084a1.205 1.205 0 1 0 2.292-.746Z"
clipRule="evenodd"
/>
<path
- fill="url(#p)"
+ fill="url(#69f97277__paint15_radial_5232_4740)"
fillRule="evenodd"
d="M5.973 11.669 3.352 3.585a1.205 1.205 0 1 0-2.293.746l2.622 8.084a1.205 1.205 0 1 0 2.292-.746Z"
clipRule="evenodd"
/>
<path
- fill="url(#q)"
+ fill="url(#69f97277__paint16_linear_5232_4740)"
fillRule="evenodd"
d="M5.973 11.669 3.352 3.585a1.205 1.205 0 1 0-2.293.746l2.622 8.084a1.205 1.205 0 1 0 2.292-.746Z"
clipRule="evenodd"
/>
<path
- fill="url(#r)"
+ fill="url(#69f97277__paint17_radial_5232_4740)"
fillRule="evenodd"
d="M5.973 11.669 3.352 3.585a1.205 1.205 0 1 0-2.293.746l2.622 8.084a1.205 1.205 0 1 0 2.292-.746Z"
clipRule="evenodd"
/>
<path
- fill="url(#s)"
+ fill="url(#69f97277__paint18_radial_5232_4740)"
fillRule="evenodd"
d="M5.973 11.669 3.352 3.585a1.205 1.205 0 1 0-2.293.746l2.622 8.084a1.205 1.205 0 1 0 2.292-.746Z"
clipRule="evenodd"
/>
<defs>
<radialGradient
- id="d"
+ id="69f97277__paint3_radial_5232_4740"
cx="0"
cy="0"
r="1"
@@ -5425,7 +5614,7 @@ export const WebstudioIcon: IconComponent = forwardRef(
<stop offset="1" stopColor="#4A4EFA" stopOpacity=".75" />
</radialGradient>
<radialGradient
- id="e"
+ id="69f97277__paint4_radial_5232_4740"
cx="0"
cy="0"
r="1"
@@ -5436,7 +5625,7 @@ export const WebstudioIcon: IconComponent = forwardRef(
<stop offset=".926" stopColor="#4069D4" stopOpacity="0" />
</radialGradient>
<radialGradient
- id="f"
+ id="69f97277__paint5_radial_5232_4740"
cx="0"
cy="0"
r="1"
@@ -5447,7 +5636,7 @@ export const WebstudioIcon: IconComponent = forwardRef(
<stop offset="1" stopColor="#E63CFE" stopOpacity="0" />
</radialGradient>
<radialGradient
- id="g"
+ id="69f97277__paint6_radial_5232_4740"
cx="0"
cy="0"
r="1"
@@ -5459,7 +5648,7 @@ export const WebstudioIcon: IconComponent = forwardRef(
<stop offset="1" stopColor="#39FBBB" stopOpacity="0" />
</radialGradient>
<radialGradient
- id="h"
+ id="69f97277__paint7_radial_5232_4740"
cx="0"
cy="0"
r="1"
@@ -5470,7 +5659,7 @@ export const WebstudioIcon: IconComponent = forwardRef(
<stop offset="1" stopColor="#E63CFE" stopOpacity="0" />
</radialGradient>
<radialGradient
- id="i"
+ id="69f97277__paint8_radial_5232_4740"
cx="0"
cy="0"
r="1"
@@ -5481,7 +5670,7 @@ export const WebstudioIcon: IconComponent = forwardRef(
<stop offset=".935" stopColor="#4A4EFA" stopOpacity="0" />
</radialGradient>
<radialGradient
- id="j"
+ id="69f97277__paint9_radial_5232_4740"
cx="0"
cy="0"
r="1"
@@ -5492,7 +5681,7 @@ export const WebstudioIcon: IconComponent = forwardRef(
<stop offset="1" stopColor="#E63CFE" stopOpacity="0" />
</radialGradient>
<radialGradient
- id="k"
+ id="69f97277__paint10_radial_5232_4740"
cx="0"
cy="0"
r="1"
@@ -5503,7 +5692,7 @@ export const WebstudioIcon: IconComponent = forwardRef(
<stop offset=".973" stopColor="#11417A" />
</radialGradient>
<radialGradient
- id="l"
+ id="69f97277__paint11_radial_5232_4740"
cx="0"
cy="0"
r="1"
@@ -5514,7 +5703,7 @@ export const WebstudioIcon: IconComponent = forwardRef(
<stop offset="1" stopColor="#FFAE3C" stopOpacity="0" />
</radialGradient>
<radialGradient
- id="m"
+ id="69f97277__paint12_radial_5232_4740"
cx="0"
cy="0"
r="1"
@@ -5525,7 +5714,7 @@ export const WebstudioIcon: IconComponent = forwardRef(
<stop offset="1" stopColor="#E63CFE" stopOpacity="0" />
</radialGradient>
<radialGradient
- id="n"
+ id="69f97277__paint13_radial_5232_4740"
cx="0"
cy="0"
r="1"
@@ -5536,7 +5725,7 @@ export const WebstudioIcon: IconComponent = forwardRef(
<stop offset="1" stopColor="#FFAE3C" stopOpacity="0" />
</radialGradient>
<radialGradient
- id="p"
+ id="69f97277__paint15_radial_5232_4740"
cx="0"
cy="0"
r="1"
@@ -5547,7 +5736,7 @@ export const WebstudioIcon: IconComponent = forwardRef(
<stop offset="1" stopColor="#4A4EFA" stopOpacity="0" />
</radialGradient>
<radialGradient
- id="r"
+ id="69f97277__paint17_radial_5232_4740"
cx="0"
cy="0"
r="1"
@@ -5558,7 +5747,7 @@ export const WebstudioIcon: IconComponent = forwardRef(
<stop offset=".926" stopColor="#FFAE3C" stopOpacity="0" />
</radialGradient>
<radialGradient
- id="s"
+ id="69f97277__paint18_radial_5232_4740"
cx="0"
cy="0"
r="1"
@@ -5569,7 +5758,7 @@ export const WebstudioIcon: IconComponent = forwardRef(
<stop offset="1" stopColor="#E63CFE" />
</radialGradient>
<linearGradient
- id="a"
+ id="69f97277__paint0_linear_5232_4740"
x1="16.343"
x2="12.418"
y1=".102"
@@ -5580,7 +5769,7 @@ export const WebstudioIcon: IconComponent = forwardRef(
<stop offset=".549" stopColor="#E63CFE" />
</linearGradient>
<linearGradient
- id="b"
+ id="69f97277__paint1_linear_5232_4740"
x1="11.413"
x2="13.636"
y1="7.419"
@@ -5591,7 +5780,7 @@ export const WebstudioIcon: IconComponent = forwardRef(
<stop offset=".946" stopColor="#4A4EFA" stopOpacity="0" />
</linearGradient>
<linearGradient
- id="c"
+ id="69f97277__paint2_linear_5232_4740"
x1="11.75"
x2="13.147"
y1="6.351"
@@ -5602,7 +5791,7 @@ export const WebstudioIcon: IconComponent = forwardRef(
<stop offset="1" stopColor="#39FBBB" stopOpacity="0" />
</linearGradient>
<linearGradient
- id="o"
+ id="69f97277__paint14_linear_5232_4740"
x1=".588"
x2="3.972"
y1="3.255"
@@ -5613,7 +5802,7 @@ export const WebstudioIcon: IconComponent = forwardRef(
<stop offset=".709" stopColor="#FFAE3C" />
</linearGradient>
<linearGradient
- id="q"
+ id="69f97277__paint16_linear_5232_4740"
x1="4.844"
x2="4.37"
y1="8.176"
diff --git a/packages/icons/src/__generated__/svg.ts b/packages/icons/src/__generated__/svg.ts
index 298d83fc67..a9ca5bd3aa 100644
--- a/packages/icons/src/__generated__/svg.ts
+++ b/packages/icons/src/__generated__/svg.ts
@@ -2,7 +2,7 @@ export const AccordionIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none
export const AddTemplateInstanceIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M4.5 2H3.333A1.333 1.333 0 0 0 2 3.333V4.5M14 12.667c0 .021 0 .042-.002.063M11.5 14h1.167a1.333 1.333 0 0 0 1.331-1.27m0 0V11.5M2 11.5v1.167A1.333 1.333 0 0 0 3.333 14H4.5M7 14h2M2 7v2M8.461 4.77H14M11.23 2v5.538"/></svg>`;
-export const AiLoadingIcon = `<svg xmlns="http://www.w3.org/2000/svg" id="evA4hI5dD261" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" viewBox="0 0 17 17" fill="currentColor" width="100%" height="100%" style="display: block;"><style>@keyframes evA4hI5dD263_s_do{0%,to{stroke-dashoffset:6.2}17.5%,82.5%{stroke-dashoffset:-6.24}}@keyframes evA4hI5dD264_s_do{0%,10%,90%,to{stroke-dashoffset:6.8}22.5%,77.5%{stroke-dashoffset:-6.8}}@keyframes evA4hI5dD265_s_do{0%,17.5%,82.5%,to{stroke-dashoffset:2.32}27.5%,72.5%{stroke-dashoffset:-2.32}}@keyframes evA4hI5dD266_s_do{0%,22.5%,77.5%,to{stroke-dashoffset:2.47}32.5%,67.5%{stroke-dashoffset:-2.47}}@keyframes evA4hI5dD267_s_do{0%,27.5%,72.5%,to{stroke-dashoffset:5.42}40%,60%{stroke-dashoffset:-5.42}}@keyframes evA4hI5dD268_s_do{0%,32.5%,67.5%,to{stroke-dashoffset:6.13}50%{stroke-dashoffset:-6.1}}#evA4hI5dD263{animation:evA4hI5dD263_s_do 4000ms linear infinite normal forwards}#evA4hI5dD264{animation:evA4hI5dD264_s_do 4000ms linear infinite normal forwards}#evA4hI5dD265{animation:evA4hI5dD265_s_do 4000ms linear infinite normal forwards}#evA4hI5dD266{animation:evA4hI5dD266_s_do 4000ms linear infinite normal forwards}#evA4hI5dD267{animation:evA4hI5dD267_s_do 4000ms linear infinite normal forwards}#evA4hI5dD268{animation:evA4hI5dD268_s_do 4000ms linear infinite normal forwards}</style><path fill="none" stroke="rgba(255,255,255,0.4)" stroke-dasharray="0" stroke-linecap="round" stroke-width="2.2" d="m2.816 12.956 1.513-6.051a2.563 2.563 0 0 1 4.974 0l1.159 4.634a1.888 1.888 0 0 0 1.816 1.417 1.892 1.892 0 0 0 1.872-1.872V4.956"/><path id="evA4hI5dD263" fill="none" stroke="#fff" stroke-dasharray="6.24" stroke-dashoffset="6.2" stroke-linecap="round" stroke-width="3.3" d="m2.816 12.956 1.513-6.051"/><path id="evA4hI5dD264" fill="none" stroke="#fff" stroke-dasharray="6.8" stroke-dashoffset="6.8" stroke-linecap="round" stroke-width="3.3" d="M4.329 6.905a2.563 2.563 0 0 1 4.974 0"/><path id="evA4hI5dD265" fill="none" stroke="#fff" stroke-dasharray="2.32" stroke-dashoffset="2.32" stroke-linecap="round" stroke-width="3.3" d="m9.303 6.905.561 2.243"/><path id="evA4hI5dD266" fill="none" stroke="#fff" stroke-dasharray="2.47" stroke-dashoffset="2.47" stroke-linecap="round" stroke-width="3.3" d="m9.864 9.148.598 2.391"/><path id="evA4hI5dD267" fill="none" stroke="#fff" stroke-dasharray="5.42" stroke-dashoffset="5.42" stroke-linecap="round" stroke-width="3.3" d="M10.462 11.54a1.888 1.888 0 0 0 1.816 1.416 1.892 1.892 0 0 0 1.872-1.872"/><path id="evA4hI5dD268" fill="none" stroke="#fff" stroke-dasharray="6.13" stroke-dashoffset="6.13" stroke-linecap="round" stroke-width="3.3" d="M14.15 11.084V4.956"/></svg>`;
+export const AiLoadingIcon = `<svg xmlns="http://www.w3.org/2000/svg" id="86546c68__evA4hI5dD261" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" viewBox="0 0 17 17" fill="currentColor" width="100%" height="100%" style="display: block;"><style>@keyframes evA4hI5dD263_s_do{0%,to{stroke-dashoffset:6.2}17.5%,82.5%{stroke-dashoffset:-6.24}}@keyframes evA4hI5dD264_s_do{0%,10%,90%,to{stroke-dashoffset:6.8}22.5%,77.5%{stroke-dashoffset:-6.8}}@keyframes evA4hI5dD265_s_do{0%,17.5%,82.5%,to{stroke-dashoffset:2.32}27.5%,72.5%{stroke-dashoffset:-2.32}}@keyframes evA4hI5dD266_s_do{0%,22.5%,77.5%,to{stroke-dashoffset:2.47}32.5%,67.5%{stroke-dashoffset:-2.47}}@keyframes evA4hI5dD267_s_do{0%,27.5%,72.5%,to{stroke-dashoffset:5.42}40%,60%{stroke-dashoffset:-5.42}}@keyframes evA4hI5dD268_s_do{0%,32.5%,67.5%,to{stroke-dashoffset:6.13}50%{stroke-dashoffset:-6.1}}#86546c68__evA4hI5dD263{animation:evA4hI5dD263_s_do 4000ms linear infinite normal forwards}#86546c68__evA4hI5dD264{animation:evA4hI5dD264_s_do 4000ms linear infinite normal forwards}#86546c68__evA4hI5dD265{animation:evA4hI5dD265_s_do 4000ms linear infinite normal forwards}#86546c68__evA4hI5dD266{animation:evA4hI5dD266_s_do 4000ms linear infinite normal forwards}#86546c68__evA4hI5dD267{animation:evA4hI5dD267_s_do 4000ms linear infinite normal forwards}#86546c68__evA4hI5dD268{animation:evA4hI5dD268_s_do 4000ms linear infinite normal forwards}</style><path fill="none" stroke="rgba(255,255,255,0.4)" stroke-dasharray="0" stroke-linecap="round" stroke-width="2.2" d="m2.816 12.956 1.513-6.051a2.563 2.563 0 0 1 4.974 0l1.159 4.634a1.888 1.888 0 0 0 1.816 1.417 1.892 1.892 0 0 0 1.872-1.872V4.956"/><path id="86546c68__evA4hI5dD263" fill="none" stroke="#fff" stroke-dasharray="6.24" stroke-dashoffset="6.2" stroke-linecap="round" stroke-width="3.3" d="m2.816 12.956 1.513-6.051"/><path id="86546c68__evA4hI5dD264" fill="none" stroke="#fff" stroke-dasharray="6.8" stroke-dashoffset="6.8" stroke-linecap="round" stroke-width="3.3" d="M4.329 6.905a2.563 2.563 0 0 1 4.974 0"/><path id="86546c68__evA4hI5dD265" fill="none" stroke="#fff" stroke-dasharray="2.32" stroke-dashoffset="2.32" stroke-linecap="round" stroke-width="3.3" d="m9.303 6.905.561 2.243"/><path id="86546c68__evA4hI5dD266" fill="none" stroke="#fff" stroke-dasharray="2.47" stroke-dashoffset="2.47" stroke-linecap="round" stroke-width="3.3" d="m9.864 9.148.598 2.391"/><path id="86546c68__evA4hI5dD267" fill="none" stroke="#fff" stroke-dasharray="5.42" stroke-dashoffset="5.42" stroke-linecap="round" stroke-width="3.3" d="M10.462 11.54a1.888 1.888 0 0 0 1.816 1.416 1.892 1.892 0 0 0 1.872-1.872"/><path id="86546c68__evA4hI5dD268" fill="none" stroke="#fff" stroke-dasharray="6.13" stroke-dashoffset="6.13" stroke-linecap="round" stroke-width="3.3" d="M14.15 11.084V4.956"/></svg>`;
export const AiIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" d="m1.5 12.588 1.735-6.94a2.94 2.94 0 0 1 5.705 0l1.33 5.315a2.165 2.165 0 0 0 2.083 1.625 2.17 2.17 0 0 0 2.147-2.147v-7.03"/></svg>`;
@@ -56,6 +56,8 @@ export const ArrowDownIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none
export const ArrowLeftIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M12.667 8H3.333M8 3.333 3.333 8 8 12.667"/></svg>`;
+export const ArrowRightLeftIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width=".667" d="m11 2 2.667 2.667m0 0L11 7.333m2.667-2.666H3M5.667 14 3 11.333m0 0 2.667-2.666M3 11.333h10.667"/></svg>`;
+
export const ArrowRightIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M3.333 8h9.334M8 3.333 12.667 8 8 12.667"/></svg>`;
export const ArrowUpIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M8 12.667V3.333M3.333 8 8 3.333 12.667 8"/></svg>`;
@@ -118,7 +120,7 @@ export const ChevronDownIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="no
export const ChevronFilledUpIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path fill="currentColor" d="M13 11 8 5l-5 6"/></svg>`;
-export const ChevronLeftIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" width="100%" height="100%" style="display: block;"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.3" d="m9.256 4.499-3.512 3.5 3.512 3.502"/></svg>`;
+export const ChevronLeftIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" width="100%" height="100%" style="display: block;"><g id="1893fb9d__icon/chevron left"><path id="1893fb9d__vector" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.3" d="m9.256 4.499-3.512 3.5 3.512 3.502"/></g></svg>`;
export const ChevronRightIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="m6 12 4-4-4-4"/></svg>`;
@@ -126,6 +128,8 @@ export const ChevronUpIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none
export const ChevronsLeftIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="#000" stroke-linecap="round" stroke-linejoin="round" d="M7.069 12.656 2.413 8l4.656-4.656M13.587 12.656 8.931 8l4.656-4.656"/></svg>`;
+export const CircleIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path fill="currentColor" fill-rule="evenodd" d="M8 3.65a4.35 4.35 0 1 0 0 8.7 4.35 4.35 0 0 0 0-8.7ZM2.35 8a5.65 5.65 0 1 1 11.3 0 5.65 5.65 0 0 1-11.3 0Z" clip-rule="evenodd"/></svg>`;
+
export const CloudIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M11.667 12.667H6a4.667 4.667 0 1 1 4.473-6h1.194a3 3 0 1 1 0 6Z"/></svg>`;
export const CollapsibleIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M8 14.667v-4M8 5.333v-4M2.5 8h-1M6.5 8h-1M10.5 8h-1M14.5 8h-1M10 12.667l-2-2-2 2M10 3.333l-2 2-2-2"/></svg>`;
@@ -162,6 +166,8 @@ export const DragHandleIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="non
export const DynamicPageIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M8 12.203H3.855a1.474 1.474 0 0 1-1.473-1.473V2.81a1.474 1.474 0 0 1 1.473-1.474h6.079l3.684 3.683v5.71a1.474 1.474 0 0 1-1.474 1.474H8Zm0 0 .01 2.462m0 0H2.39m5.618 0h5.618"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M9.198 1.888V3.73a1.474 1.474 0 0 0 1.473 1.474h2.947"/></svg>`;
+export const EllipseIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path fill="currentColor" fill-rule="evenodd" d="M3.373 5.736C2.203 6.405 1.65 7.229 1.65 8c0 .77.553 1.595 1.723 2.264C4.525 10.922 6.159 11.35 8 11.35c1.84 0 3.475-.428 4.627-1.086C13.797 9.595 14.35 8.771 14.35 8c0-.77-.553-1.595-1.723-2.264C11.475 5.078 9.841 4.65 8 4.65c-1.84 0-3.475.428-4.627 1.086Zm-.645-1.129C4.109 3.817 5.975 3.35 8 3.35c2.025 0 3.89.468 5.272 1.257 1.364.78 2.378 1.955 2.378 3.393 0 1.438-1.014 2.614-2.378 3.393-1.382.79-3.247 1.257-5.272 1.257-2.025 0-3.89-.468-5.272-1.257C1.364 10.613.35 9.438.35 8c0-1.438 1.014-2.614 2.378-3.393Z" clip-rule="evenodd"/></svg>`;
+
export const EllipsesIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path fill="currentColor" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M7.112 8a.888.888 0 1 0 1.777 0 .888.888 0 0 0-1.777 0ZM12.724 8a.888.888 0 1 0 1.777 0 .888.888 0 0 0-1.777 0ZM1.499 8a.888.888 0 1 0 1.777 0 .888.888 0 0 0-1.777 0Z"/></svg>`;
export const EmailIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M13.333 2.667H2.667c-.737 0-1.334.597-1.334 1.333v8c0 .736.597 1.333 1.334 1.333h10.666c.737 0 1.334-.597 1.334-1.333V4c0-.736-.597-1.333-1.334-1.333Z"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="m14.667 4.667-5.98 3.8a1.293 1.293 0 0 1-1.374 0l-5.98-3.8"/></svg>`;
@@ -198,6 +204,12 @@ export const GithubIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0
export const GoogleIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path fill="currentColor" d="M14.72 8.16c0-.497-.045-.975-.127-1.433H8v2.711h3.767a3.228 3.228 0 0 1-1.406 2.107v1.762h2.272c1.323-1.222 2.087-3.016 2.087-5.148Z"/><path fill="currentColor" d="M8 15c1.89 0 3.475-.624 4.633-1.693l-2.272-1.762c-.624.42-1.42.674-2.361.674-1.82 0-3.366-1.228-3.92-2.883H1.75v1.808A6.993 6.993 0 0 0 8 15Z"/><path fill="currentColor" d="M4.08 9.33A4.195 4.195 0 0 1 3.857 8c0-.465.083-.91.223-1.33V4.863H1.75A6.914 6.914 0 0 0 1 8c0 1.133.274 2.195.75 3.137l1.815-1.412.515-.395Z"/><path fill="currentColor" d="M8 3.787c1.03 0 1.947.357 2.679 1.044l2.005-2.005C11.468 1.694 9.89 1 8 1a6.988 6.988 0 0 0-6.25 3.863L4.08 6.67C4.634 5.015 6.18 3.787 8 3.787Z"/></svg>`;
+export const GradientConicIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><g fill="#11181C" clip-path="url(#15388f97__paint0_angular_9413_9319_clip_path)"><path d="M8 8V0a8 8 0 0 1 4 1.072Z"/><path fill-opacity=".909" d="m8 8 4-6.928A8 8 0 0 1 14.928 4Z"/><path fill-opacity=".818" d="m8 8 6.928-4A8 8 0 0 1 16 8Z"/><path fill-opacity=".727" d="M8 8h8a8 8 0 0 1-1.072 4Z"/><path fill-opacity=".636" d="m8 8 6.928 4A8 8 0 0 1 12 14.928Z"/><path fill-opacity=".545" d="m8 8 4 6.928A8 8 0 0 1 8 16Z"/><path fill-opacity=".455" d="M8 8v8a8 8 0 0 1-4-1.072Z"/><path fill-opacity=".364" d="m8 8-4 6.928A8 8 0 0 1 1.072 12Z"/><path fill-opacity=".273" d="m8 8-6.928 4A8 8 0 0 1 0 8Z"/><path fill-opacity=".182" d="M8 8H0a8 8 0 0 1 1.072-4Z"/><path fill-opacity=".091" d="M8 8 1.072 4A8 8 0 0 1 4 1.072Z"/><path fill="none" d="M8 8 4 1.072A8 8 0 0 1 8 0Z"/></g><defs><clipPath id="15388f97__paint0_angular_9413_9319_clip_path"><path d="M2 5.2c0-1.12 0-1.68.218-2.108a2 2 0 0 1 .874-.874C3.52 2 4.08 2 5.2 2h5.6c1.12 0 1.68 0 2.108.218a2 2 0 0 1 .874.874C14 3.52 14 4.08 14 5.2v5.6c0 1.12 0 1.68-.218 2.108a2 2 0 0 1-.874.874C12.48 14 11.92 14 10.8 14H5.2c-1.12 0-1.68 0-2.108-.218a2 2 0 0 1-.874-.874C2 12.48 2 11.92 2 10.8V5.2Z"/></clipPath></defs></svg>`;
+
+export const GradientLinearIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path fill="url(#1fa533d5__gradient-linear_svg__a)" d="M2 5.2c0-1.12 0-1.68.218-2.108a2 2 0 0 1 .874-.874C3.52 2 4.08 2 5.2 2h5.6c1.12 0 1.68 0 2.108.218a2 2 0 0 1 .874.874C14 3.52 14 4.08 14 5.2v5.6c0 1.12 0 1.68-.218 2.108a2 2 0 0 1-.874.874C12.48 14 11.92 14 10.8 14H5.2c-1.12 0-1.68 0-2.108-.218a2 2 0 0 1-.874-.874C2 12.48 2 11.92 2 10.8V5.2Z"/><defs><linearGradient id="1fa533d5__gradient-linear_svg__a" x1="8" x2="8" y1="2" y2="14" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#11181C"/><stop offset="1" stop-color="#11181C" stop-opacity="0"/></linearGradient></defs></svg>`;
+
+export const GradientRadialIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path fill="url(#539a7588__paint0_radial_9420_9425)" d="M2 5.2c0-1.12 0-1.68.218-2.108a2 2 0 0 1 .874-.874C3.52 2 4.08 2 5.2 2h5.6c1.12 0 1.68 0 2.108.218a2 2 0 0 1 .874.874C14 3.52 14 4.08 14 5.2v5.6c0 1.12 0 1.68-.218 2.108a2 2 0 0 1-.874.874C12.48 14 11.92 14 10.8 14H5.2c-1.12 0-1.68 0-2.108-.218a2 2 0 0 1-.874-.874C2 12.48 2 11.92 2 10.8V5.2Z"/><defs><radialGradient id="539a7588__paint0_radial_9420_9425" cx="0" cy="0" r="1" gradientTransform="translate(8 8) rotate(135) scale(8.48528)" gradientUnits="userSpaceOnUse"><stop stop-color="#11181C"/><stop offset="1" stop-color="#11181C" stop-opacity="0"/></radialGradient></defs></svg>`;
+
export const GrowIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M4 8h4M6 10 4 8l2-2M12 8H8M10 6l2 2-2 2M2 14V2M14.003 14V2"/></svg>`;
export const HeaderIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M12.667 2H3.333C2.597 2 2 2.597 2 3.333v9.334C2 13.403 2.597 14 3.333 14h9.334c.736 0 1.333-.597 1.333-1.333V3.333C14 2.597 13.403 2 12.667 2ZM4 4h8"/></svg>`;
@@ -236,7 +248,7 @@ export const ListViewIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none"
export const ListIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" width="100%" height="100%" style="display: block;"><path d="M3.7 4.35a.85.85 0 1 1-1.7 0 .85.85 0 0 1 1.7 0Z"/><path fill-rule="evenodd" d="M5 4.35c0-.346.28-.626.625-.626h7.75a.625.625 0 1 1 0 1.25h-7.75A.625.625 0 0 1 5 4.35Z" clip-rule="evenodd"/><path d="M3.7 8A.85.85 0 1 1 2 8a.85.85 0 0 1 1.7 0Z"/><path fill-rule="evenodd" d="M5 8c0-.345.28-.625.625-.625h7.75a.625.625 0 1 1 0 1.25h-7.75A.625.625 0 0 1 5 8Z" clip-rule="evenodd"/><path d="M3.7 11.65a.85.85 0 1 1-1.7 0 .85.85 0 0 1 1.7 0Z"/><path fill-rule="evenodd" d="M5 11.65c0-.346.28-.626.625-.626h7.75a.625.625 0 1 1 0 1.25h-7.75A.625.625 0 0 1 5 11.65Z" clip-rule="evenodd"/></svg>`;
-export const LoadingDotsIcon = `<svg xmlns="http://www.w3.org/2000/svg" id="eEMFTOz1Zbw1" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" viewBox="0 0 300 300" fill="currentColor" width="100%" height="100%" style="display: block;"><style>@keyframes eEMFTOz1Zbw12_to__to{0%,26.666667%,56.666667%,6.333333%,77%,to{transform:translate(150px,180px)}16.666667%,67%{transform:translate(150px,120px);animation-timing-function:cubic-bezier(.42,0,.58,1)}}@keyframes eEMFTOz1Zbw13_to__to{0%,20%,50%,70%,to{transform:translate(80px,180px)}10%,60%{transform:translate(80px,120px);animation-timing-function:cubic-bezier(.42,0,.58,1)}}@keyframes eEMFTOz1Zbw14_to__to{0%,13.333333%,33.333333%,63.333333%,83.333333%,to{transform:translate(220px,180px)}23.333333%,73.333333%{transform:translate(220px,120px);animation-timing-function:cubic-bezier(.42,0,.58,1)}}#eEMFTOz1Zbw12_to{animation:eEMFTOz1Zbw12_to__to 2000ms linear infinite normal forwards}#eEMFTOz1Zbw13_to{animation:eEMFTOz1Zbw13_to__to 2000ms linear infinite normal forwards}#eEMFTOz1Zbw14_to{animation:eEMFTOz1Zbw14_to__to 2000ms linear infinite normal forwards}</style><circle id="eEMFTOz1Zbw12_to" r="20" stroke-width="0" transform="translate(150,180) translate(0,0)"/><circle id="eEMFTOz1Zbw13_to" r="20" stroke-width="0" transform="translate(80,180) translate(0,0)"/><circle id="eEMFTOz1Zbw14_to" r="20" stroke-width="0" transform="translate(220,180) translate(0,0)"/></svg>`;
+export const LoadingDotsIcon = `<svg xmlns="http://www.w3.org/2000/svg" id="fdbcf7a5__eEMFTOz1Zbw1" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" viewBox="0 0 300 300" fill="currentColor" width="100%" height="100%" style="display: block;"><style>@keyframes eEMFTOz1Zbw12_to__to{0%,26.666667%,56.666667%,6.333333%,77%,to{transform:translate(150px,180px)}16.666667%,67%{transform:translate(150px,120px);animation-timing-function:cubic-bezier(.42,0,.58,1)}}@keyframes eEMFTOz1Zbw13_to__to{0%,20%,50%,70%,to{transform:translate(80px,180px)}10%,60%{transform:translate(80px,120px);animation-timing-function:cubic-bezier(.42,0,.58,1)}}@keyframes eEMFTOz1Zbw14_to__to{0%,13.333333%,33.333333%,63.333333%,83.333333%,to{transform:translate(220px,180px)}23.333333%,73.333333%{transform:translate(220px,120px);animation-timing-function:cubic-bezier(.42,0,.58,1)}}#fdbcf7a5__eEMFTOz1Zbw12_to{animation:eEMFTOz1Zbw12_to__to 2000ms linear infinite normal forwards}#fdbcf7a5__eEMFTOz1Zbw13_to{animation:eEMFTOz1Zbw13_to__to 2000ms linear infinite normal forwards}#fdbcf7a5__eEMFTOz1Zbw14_to{animation:eEMFTOz1Zbw14_to__to 2000ms linear infinite normal forwards}</style><circle id="fdbcf7a5__eEMFTOz1Zbw12_to" r="20" stroke-width="0" transform="translate(150,180) translate(0,0)"/><circle id="fdbcf7a5__eEMFTOz1Zbw13_to" r="20" stroke-width="0" transform="translate(80,180) translate(0,0)"/><circle id="fdbcf7a5__eEMFTOz1Zbw14_to" r="20" stroke-width="0" transform="translate(220,180) translate(0,0)"/></svg>`;
export const MarkdownEmbedIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M4.667 5.333h4M4.667 8H10M14 8.75V3.5A1.5 1.5 0 0 0 12.5 2h-9A1.5 1.5 0 0 0 2 3.5v9.191c0 .725.588 1.313 1.313 1.313h4.691"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M10 14.314v-4l2 2.03 2-2.03v4"/></svg>`;
@@ -328,7 +340,7 @@ export const SliderIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" v
export const SlotComponentIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M4.5 2H3.333A1.333 1.333 0 0 0 2 3.333V4.5M14 4.5V3.333A1.333 1.333 0 0 0 12.667 2H11.5M14 12.667c0 .021 0 .042-.002.063M11.5 14h1.167a1.333 1.333 0 0 0 1.331-1.27m0 0V11.5M2 11.5v1.167A1.333 1.333 0 0 0 3.333 14H4.5M7 2h2M7 14h2M2 7v2M14 7v2"/></svg>`;
-export const SpinnerIcon = `<svg xmlns="http://www.w3.org/2000/svg" id="e2CRglijn891" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" viewBox="0 0 128 128" fill="currentColor" width="100%" height="100%" style="display: block;"><style>@keyframes e2CRglijn892_tr__tr{0%{transform:translate(64px,64px) rotate(90deg);animation-timing-function:cubic-bezier(.42,0,.58,1)}50%{transform:translate(64px,64px) rotate(810deg);animation-timing-function:cubic-bezier(.42,0,.58,1)}to{transform:translate(64px,64px) rotate(1530deg)}}@keyframes e2CRglijn892_s_p{0%,to{stroke:#39fbbb}25%{stroke:#4a4efa}50%{stroke:#e63cfe}75%{stroke:#ffae3c}}@keyframes e2CRglijn892_s_do{0%{stroke-dashoffset:251.89}2.5%,52.5%{stroke-dashoffset:263.88;animation-timing-function:cubic-bezier(.42,0,.58,1)}25%,75%{stroke-dashoffset:131.945}to{stroke-dashoffset:251.885909}}#e2CRglijn892_tr{animation:e2CRglijn892_tr__tr 3000ms linear infinite normal forwards}#e2CRglijn892{animation-name:e2CRglijn892_s_p,e2CRglijn892_s_do;animation-duration:3000ms;animation-fill-mode:forwards;animation-timing-function:linear;animation-direction:normal;animation-iteration-count:infinite}</style><g id="e2CRglijn892_tr" transform="translate(64,64) rotate(90)"><circle id="e2CRglijn892" r="42" fill="none" stroke="#39fbbb" stroke-dasharray="263.89" stroke-dashoffset="251.89" stroke-linecap="round" stroke-width="16" transform="scale(-1,1) translate(0,0)"/></g></svg>`;
+export const SpinnerIcon = `<svg xmlns="http://www.w3.org/2000/svg" id="765c5cf3__e2CRglijn891" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" viewBox="0 0 128 128" fill="currentColor" width="100%" height="100%" style="display: block;"><style>@keyframes e2CRglijn892_tr__tr{0%{transform:translate(64px,64px) rotate(90deg);animation-timing-function:cubic-bezier(.42,0,.58,1)}50%{transform:translate(64px,64px) rotate(810deg);animation-timing-function:cubic-bezier(.42,0,.58,1)}to{transform:translate(64px,64px) rotate(1530deg)}}@keyframes e2CRglijn892_s_p{0%,to{stroke:#39fbbb}25%{stroke:#4a4efa}50%{stroke:#e63cfe}75%{stroke:#ffae3c}}@keyframes e2CRglijn892_s_do{0%{stroke-dashoffset:251.89}2.5%,52.5%{stroke-dashoffset:263.88;animation-timing-function:cubic-bezier(.42,0,.58,1)}25%,75%{stroke-dashoffset:131.945}to{stroke-dashoffset:251.885909}}#765c5cf3__e2CRglijn892_tr{animation:e2CRglijn892_tr__tr 3000ms linear infinite normal forwards}#765c5cf3__e2CRglijn892{animation-name:e2CRglijn892_s_p,e2CRglijn892_s_do;animation-duration:3000ms;animation-fill-mode:forwards;animation-timing-function:linear;animation-direction:normal;animation-iteration-count:infinite}</style><g id="765c5cf3__e2CRglijn892_tr" transform="translate(64,64) rotate(90)"><circle id="765c5cf3__e2CRglijn892" r="42" fill="none" stroke="#39fbbb" stroke-dasharray="263.89" stroke-dashoffset="251.89" stroke-linecap="round" stroke-width="16" transform="scale(-1,1) translate(0,0)"/></g></svg>`;
export const StaggerAnimationIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M14.222 5H8.778A.778.778 0 0 0 8 5.778v5.444c0 .43.348.778.778.778h5.444c.43 0 .778-.348.778-.778V5.778A.778.778 0 0 0 14.222 5ZM5.444 6H1.556A.556.556 0 0 0 1 6.556v3.888c0 .307.249.556.556.556h3.888A.556.556 0 0 0 6 10.444V6.556A.556.556 0 0 0 5.444 6Z"/></svg>`;
@@ -392,7 +404,7 @@ export const WebhookFormIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="no
export const Webstudio1cIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path fill-rule="evenodd" d="m12.32 12.416 2.62-8.085a1.205 1.205 0 1 0-2.292-.746l-2.62 8.084a1.205 1.205 0 1 0 2.292.747Z" clip-rule="evenodd"/><path fill-rule="evenodd" d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.206 1.206 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.8-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.206 1.206 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z" clip-rule="evenodd"/><path fill-rule="evenodd" d="M5.973 11.669 3.352 3.585a1.205 1.205 0 1 0-2.293.746l2.622 8.084a1.205 1.205 0 1 0 2.292-.746Z" clip-rule="evenodd"/></svg>`;
-export const WebstudioIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path fill="url(#a)" fill-rule="evenodd" d="m12.32 12.416 2.62-8.085a1.205 1.205 0 1 0-2.292-.746l-2.62 8.084a1.205 1.205 0 1 0 2.292.747Z" clip-rule="evenodd"/><path fill="url(#b)" fill-rule="evenodd" d="m12.32 12.416 2.62-8.085a1.205 1.205 0 1 0-2.292-.746l-2.62 8.084a1.205 1.205 0 1 0 2.292.747Z" clip-rule="evenodd"/><path fill="url(#c)" fill-opacity=".8" fill-rule="evenodd" d="m12.32 12.416 2.62-8.085a1.205 1.205 0 1 0-2.292-.746l-2.62 8.084a1.205 1.205 0 1 0 2.292.747Z" clip-rule="evenodd"/><path fill="url(#d)" fill-rule="evenodd" d="m12.32 12.416 2.62-8.085a1.205 1.205 0 1 0-2.292-.746l-2.62 8.084a1.205 1.205 0 1 0 2.292.747Z" clip-rule="evenodd"/><path fill="url(#e)" fill-rule="evenodd" d="m12.32 12.416 2.62-8.085a1.205 1.205 0 1 0-2.292-.746l-2.62 8.084a1.205 1.205 0 1 0 2.292.747Z" clip-rule="evenodd"/><path fill="url(#f)" fill-rule="evenodd" d="m12.32 12.416 2.62-8.085a1.205 1.205 0 1 0-2.292-.746l-2.62 8.084a1.205 1.205 0 1 0 2.292.747Z" clip-rule="evenodd"/><path fill="#E63CFE" fill-rule="evenodd" d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z" clip-rule="evenodd"/><path fill="url(#g)" fill-rule="evenodd" d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z" clip-rule="evenodd"/><path fill="url(#h)" fill-rule="evenodd" d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z" clip-rule="evenodd"/><path fill="url(#i)" fill-rule="evenodd" d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z" clip-rule="evenodd"/><path fill="url(#j)" fill-rule="evenodd" d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z" clip-rule="evenodd"/><path fill="url(#k)" fill-rule="evenodd" d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z" clip-rule="evenodd"/><path fill="url(#l)" fill-rule="evenodd" d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z" clip-rule="evenodd"/><path fill="url(#m)" fill-rule="evenodd" d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z" clip-rule="evenodd"/><path fill="url(#n)" fill-rule="evenodd" d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z" clip-rule="evenodd"/><path fill="url(#o)" fill-rule="evenodd" d="M5.973 11.669 3.352 3.585a1.205 1.205 0 1 0-2.293.746l2.622 8.084a1.205 1.205 0 1 0 2.292-.746Z" clip-rule="evenodd"/><path fill="url(#p)" fill-rule="evenodd" d="M5.973 11.669 3.352 3.585a1.205 1.205 0 1 0-2.293.746l2.622 8.084a1.205 1.205 0 1 0 2.292-.746Z" clip-rule="evenodd"/><path fill="url(#q)" fill-rule="evenodd" d="M5.973 11.669 3.352 3.585a1.205 1.205 0 1 0-2.293.746l2.622 8.084a1.205 1.205 0 1 0 2.292-.746Z" clip-rule="evenodd"/><path fill="url(#r)" fill-rule="evenodd" d="M5.973 11.669 3.352 3.585a1.205 1.205 0 1 0-2.293.746l2.622 8.084a1.205 1.205 0 1 0 2.292-.746Z" clip-rule="evenodd"/><path fill="url(#s)" fill-rule="evenodd" d="M5.973 11.669 3.352 3.585a1.205 1.205 0 1 0-2.293.746l2.622 8.084a1.205 1.205 0 1 0 2.292-.746Z" clip-rule="evenodd"/><defs><radialGradient id="d" cx="0" cy="0" r="1" gradientTransform="translate(11.2336 9.30762) rotate(-64.165) scale(7.2853)" gradientUnits="userSpaceOnUse"><stop offset=".832" stop-color="#4A4EFA" stop-opacity="0"/><stop offset="1" stop-color="#4A4EFA" stop-opacity=".75"/></radialGradient><radialGradient id="e" cx="0" cy="0" r="1" gradientTransform="translate(11.0923 8.82676) scale(1.62424 3.47362)" gradientUnits="userSpaceOnUse"><stop offset=".169" stop-color="#11417A"/><stop offset=".926" stop-color="#4069D4" stop-opacity="0"/></radialGradient><radialGradient id="f" cx="0" cy="0" r="1" gradientTransform="translate(12.9724 13.2501) rotate(-90) scale(5.37233 2.57477)" gradientUnits="userSpaceOnUse"><stop offset=".349" stop-color="#E63CFE"/><stop offset="1" stop-color="#E63CFE" stop-opacity="0"/></radialGradient><radialGradient id="g" cx="0" cy="0" r="1" gradientTransform="translate(7.59145 9.4488) rotate(-85.7675) scale(5.53509 4.91478)" gradientUnits="userSpaceOnUse"><stop stop-color="#39FBBB" stop-opacity=".5"/><stop offset=".689" stop-color="#39FBBB"/><stop offset="1" stop-color="#39FBBB" stop-opacity="0"/></radialGradient><radialGradient id="h" cx="0" cy="0" r="1" gradientTransform="translate(15.4778 12.5651) rotate(-122.629) scale(13.2696 3.2283)" gradientUnits="userSpaceOnUse"><stop stop-color="#E63CFE"/><stop offset="1" stop-color="#E63CFE" stop-opacity="0"/></radialGradient><radialGradient id="i" cx="0" cy="0" r="1" gradientTransform="translate(7.81141 11.1572) rotate(-85.0198) scale(5.97107 5.13635)" gradientUnits="userSpaceOnUse"><stop offset=".557" stop-color="#4A4EFA"/><stop offset=".935" stop-color="#4A4EFA" stop-opacity="0"/></radialGradient><radialGradient id="j" cx="0" cy="0" r="1" gradientTransform="translate(6.19224 12.9644) rotate(-68.6367) scale(6.23573 3.72131)" gradientUnits="userSpaceOnUse"><stop offset=".613" stop-color="#E63CFE"/><stop offset="1" stop-color="#E63CFE" stop-opacity="0"/></radialGradient><radialGradient id="k" cx="0" cy="0" r="1" gradientTransform="translate(12.2257 8.7415) rotate(176.233) scale(7.74243 19.5729)" gradientUnits="userSpaceOnUse"><stop offset=".814" stop-color="#4A98D0" stop-opacity="0"/><stop offset=".973" stop-color="#11417A"/></radialGradient><radialGradient id="l" cx="0" cy="0" r="1" gradientTransform="translate(5.72725 13.2501) rotate(-90) scale(5.54893 4.6041)" gradientUnits="userSpaceOnUse"><stop offset=".458" stop-color="#FFAE3C"/><stop offset="1" stop-color="#FFAE3C" stop-opacity="0"/></radialGradient><radialGradient id="m" cx="0" cy="0" r="1" gradientTransform="translate(12.4559 13.2501) rotate(-90) scale(5.00159)" gradientUnits="userSpaceOnUse"><stop offset=".192" stop-color="#E63CFE"/><stop offset="1" stop-color="#E63CFE" stop-opacity="0"/></radialGradient><radialGradient id="n" cx="0" cy="0" r="1" gradientTransform="translate(9.52162 13.2501) rotate(-90) scale(3.76368 1.78782)" gradientUnits="userSpaceOnUse"><stop offset=".174" stop-color="#FFAE3C"/><stop offset="1" stop-color="#FFAE3C" stop-opacity="0"/></radialGradient><radialGradient id="p" cx="0" cy="0" r="1" gradientTransform="translate(3.35867 5.95923) rotate(161.042) scale(1.68855 8.24528)" gradientUnits="userSpaceOnUse"><stop offset=".12" stop-color="#4A4EFA"/><stop offset="1" stop-color="#4A4EFA" stop-opacity="0"/></radialGradient><radialGradient id="r" cx="0" cy="0" r="1" gradientTransform="translate(6.03209 13.2501) rotate(-90) scale(5.42506 5.92649)" gradientUnits="userSpaceOnUse"><stop offset=".465" stop-color="#FFAE3C"/><stop offset=".926" stop-color="#FFAE3C" stop-opacity="0"/></radialGradient><radialGradient id="s" cx="0" cy="0" r="1" gradientTransform="translate(6.03209 13.2501) rotate(-90) scale(11.8703)" gradientUnits="userSpaceOnUse"><stop offset=".844" stop-color="#E63CFE" stop-opacity="0"/><stop offset="1" stop-color="#E63CFE"/></radialGradient><linearGradient id="a" x1="16.343" x2="12.418" y1=".102" y2="12.794" gradientUnits="userSpaceOnUse"><stop stop-color="#4A4EFA"/><stop offset=".549" stop-color="#E63CFE"/></linearGradient><linearGradient id="b" x1="11.413" x2="13.636" y1="7.419" y2="8.138" gradientUnits="userSpaceOnUse"><stop offset=".16" stop-color="#4A4EFA"/><stop offset=".946" stop-color="#4A4EFA" stop-opacity="0"/></linearGradient><linearGradient id="c" x1="11.75" x2="13.147" y1="6.351" y2="6.798" gradientUnits="userSpaceOnUse"><stop stop-color="#39FBBB"/><stop offset="1" stop-color="#39FBBB" stop-opacity="0"/></linearGradient><linearGradient id="o" x1=".588" x2="3.972" y1="3.255" y2="13.784" gradientUnits="userSpaceOnUse"><stop offset=".17" stop-color="#E63CFE"/><stop offset=".709" stop-color="#FFAE3C"/></linearGradient><linearGradient id="q" x1="4.844" x2="4.37" y1="8.176" y2="8.331" gradientUnits="userSpaceOnUse"><stop stop-color="#E63CFE" stop-opacity=".33"/><stop offset="1" stop-color="#E63CFE" stop-opacity="0"/></linearGradient></defs></svg>`;
+export const WebstudioIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path fill="url(#69f97277__paint0_linear_5232_4740)" fill-rule="evenodd" d="m12.32 12.416 2.62-8.085a1.205 1.205 0 1 0-2.292-.746l-2.62 8.084a1.205 1.205 0 1 0 2.292.747Z" clip-rule="evenodd"/><path fill="url(#69f97277__paint1_linear_5232_4740)" fill-rule="evenodd" d="m12.32 12.416 2.62-8.085a1.205 1.205 0 1 0-2.292-.746l-2.62 8.084a1.205 1.205 0 1 0 2.292.747Z" clip-rule="evenodd"/><path fill="url(#69f97277__paint2_linear_5232_4740)" fill-opacity=".8" fill-rule="evenodd" d="m12.32 12.416 2.62-8.085a1.205 1.205 0 1 0-2.292-.746l-2.62 8.084a1.205 1.205 0 1 0 2.292.747Z" clip-rule="evenodd"/><path fill="url(#69f97277__paint3_radial_5232_4740)" fill-rule="evenodd" d="m12.32 12.416 2.62-8.085a1.205 1.205 0 1 0-2.292-.746l-2.62 8.084a1.205 1.205 0 1 0 2.292.747Z" clip-rule="evenodd"/><path fill="url(#69f97277__paint4_radial_5232_4740)" fill-rule="evenodd" d="m12.32 12.416 2.62-8.085a1.205 1.205 0 1 0-2.292-.746l-2.62 8.084a1.205 1.205 0 1 0 2.292.747Z" clip-rule="evenodd"/><path fill="url(#69f97277__paint5_radial_5232_4740)" fill-rule="evenodd" d="m12.32 12.416 2.62-8.085a1.205 1.205 0 1 0-2.292-.746l-2.62 8.084a1.205 1.205 0 1 0 2.292.747Z" clip-rule="evenodd"/><path fill="#E63CFE" fill-rule="evenodd" d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z" clip-rule="evenodd"/><path fill="url(#69f97277__paint6_radial_5232_4740)" fill-rule="evenodd" d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z" clip-rule="evenodd"/><path fill="url(#69f97277__paint7_radial_5232_4740)" fill-rule="evenodd" d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z" clip-rule="evenodd"/><path fill="url(#69f97277__paint8_radial_5232_4740)" fill-rule="evenodd" d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z" clip-rule="evenodd"/><path fill="url(#69f97277__paint9_radial_5232_4740)" fill-rule="evenodd" d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z" clip-rule="evenodd"/><path fill="url(#69f97277__paint10_radial_5232_4740)" fill-rule="evenodd" d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z" clip-rule="evenodd"/><path fill="url(#69f97277__paint11_radial_5232_4740)" fill-rule="evenodd" d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z" clip-rule="evenodd"/><path fill="url(#69f97277__paint12_radial_5232_4740)" fill-rule="evenodd" d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z" clip-rule="evenodd"/><path fill="url(#69f97277__paint13_radial_5232_4740)" fill-rule="evenodd" d="M8 7.624c.297 0 .517.175.704.394.207.243.373.545.514.866.634 1.44.753 3.241.753 3.241a1.207 1.207 0 0 0 1.285 1.122 1.207 1.207 0 0 0 1.12-1.287s-.16-2.25-.952-4.05C10.744 6.364 9.594 5.208 8 5.208c-1.594 0-2.744 1.156-3.424 2.7-.792 1.801-.951 4.05-.951 4.05a1.207 1.207 0 0 0 1.12 1.288 1.207 1.207 0 0 0 1.284-1.122s.119-1.8.753-3.24a3.52 3.52 0 0 1 .514-.867c.187-.22.406-.394.704-.394Z" clip-rule="evenodd"/><path fill="url(#69f97277__paint14_linear_5232_4740)" fill-rule="evenodd" d="M5.973 11.669 3.352 3.585a1.205 1.205 0 1 0-2.293.746l2.622 8.084a1.205 1.205 0 1 0 2.292-.746Z" clip-rule="evenodd"/><path fill="url(#69f97277__paint15_radial_5232_4740)" fill-rule="evenodd" d="M5.973 11.669 3.352 3.585a1.205 1.205 0 1 0-2.293.746l2.622 8.084a1.205 1.205 0 1 0 2.292-.746Z" clip-rule="evenodd"/><path fill="url(#69f97277__paint16_linear_5232_4740)" fill-rule="evenodd" d="M5.973 11.669 3.352 3.585a1.205 1.205 0 1 0-2.293.746l2.622 8.084a1.205 1.205 0 1 0 2.292-.746Z" clip-rule="evenodd"/><path fill="url(#69f97277__paint17_radial_5232_4740)" fill-rule="evenodd" d="M5.973 11.669 3.352 3.585a1.205 1.205 0 1 0-2.293.746l2.622 8.084a1.205 1.205 0 1 0 2.292-.746Z" clip-rule="evenodd"/><path fill="url(#69f97277__paint18_radial_5232_4740)" fill-rule="evenodd" d="M5.973 11.669 3.352 3.585a1.205 1.205 0 1 0-2.293.746l2.622 8.084a1.205 1.205 0 1 0 2.292-.746Z" clip-rule="evenodd"/><defs><radialGradient id="69f97277__paint3_radial_5232_4740" cx="0" cy="0" r="1" gradientTransform="translate(11.2336 9.30762) rotate(-64.165) scale(7.2853)" gradientUnits="userSpaceOnUse"><stop offset=".832" stop-color="#4A4EFA" stop-opacity="0"/><stop offset="1" stop-color="#4A4EFA" stop-opacity=".75"/></radialGradient><radialGradient id="69f97277__paint4_radial_5232_4740" cx="0" cy="0" r="1" gradientTransform="translate(11.0923 8.82676) scale(1.62424 3.47362)" gradientUnits="userSpaceOnUse"><stop offset=".169" stop-color="#11417A"/><stop offset=".926" stop-color="#4069D4" stop-opacity="0"/></radialGradient><radialGradient id="69f97277__paint5_radial_5232_4740" cx="0" cy="0" r="1" gradientTransform="translate(12.9724 13.2501) rotate(-90) scale(5.37233 2.57477)" gradientUnits="userSpaceOnUse"><stop offset=".349" stop-color="#E63CFE"/><stop offset="1" stop-color="#E63CFE" stop-opacity="0"/></radialGradient><radialGradient id="69f97277__paint6_radial_5232_4740" cx="0" cy="0" r="1" gradientTransform="translate(7.59145 9.4488) rotate(-85.7675) scale(5.53509 4.91478)" gradientUnits="userSpaceOnUse"><stop stop-color="#39FBBB" stop-opacity=".5"/><stop offset=".689" stop-color="#39FBBB"/><stop offset="1" stop-color="#39FBBB" stop-opacity="0"/></radialGradient><radialGradient id="69f97277__paint7_radial_5232_4740" cx="0" cy="0" r="1" gradientTransform="translate(15.4778 12.5651) rotate(-122.629) scale(13.2696 3.2283)" gradientUnits="userSpaceOnUse"><stop stop-color="#E63CFE"/><stop offset="1" stop-color="#E63CFE" stop-opacity="0"/></radialGradient><radialGradient id="69f97277__paint8_radial_5232_4740" cx="0" cy="0" r="1" gradientTransform="translate(7.81141 11.1572) rotate(-85.0198) scale(5.97107 5.13635)" gradientUnits="userSpaceOnUse"><stop offset=".557" stop-color="#4A4EFA"/><stop offset=".935" stop-color="#4A4EFA" stop-opacity="0"/></radialGradient><radialGradient id="69f97277__paint9_radial_5232_4740" cx="0" cy="0" r="1" gradientTransform="translate(6.19224 12.9644) rotate(-68.6367) scale(6.23573 3.72131)" gradientUnits="userSpaceOnUse"><stop offset=".613" stop-color="#E63CFE"/><stop offset="1" stop-color="#E63CFE" stop-opacity="0"/></radialGradient><radialGradient id="69f97277__paint10_radial_5232_4740" cx="0" cy="0" r="1" gradientTransform="translate(12.2257 8.7415) rotate(176.233) scale(7.74243 19.5729)" gradientUnits="userSpaceOnUse"><stop offset=".814" stop-color="#4A98D0" stop-opacity="0"/><stop offset=".973" stop-color="#11417A"/></radialGradient><radialGradient id="69f97277__paint11_radial_5232_4740" cx="0" cy="0" r="1" gradientTransform="translate(5.72725 13.2501) rotate(-90) scale(5.54893 4.6041)" gradientUnits="userSpaceOnUse"><stop offset=".458" stop-color="#FFAE3C"/><stop offset="1" stop-color="#FFAE3C" stop-opacity="0"/></radialGradient><radialGradient id="69f97277__paint12_radial_5232_4740" cx="0" cy="0" r="1" gradientTransform="translate(12.4559 13.2501) rotate(-90) scale(5.00159)" gradientUnits="userSpaceOnUse"><stop offset=".192" stop-color="#E63CFE"/><stop offset="1" stop-color="#E63CFE" stop-opacity="0"/></radialGradient><radialGradient id="69f97277__paint13_radial_5232_4740" cx="0" cy="0" r="1" gradientTransform="translate(9.52162 13.2501) rotate(-90) scale(3.76368 1.78782)" gradientUnits="userSpaceOnUse"><stop offset=".174" stop-color="#FFAE3C"/><stop offset="1" stop-color="#FFAE3C" stop-opacity="0"/></radialGradient><radialGradient id="69f97277__paint15_radial_5232_4740" cx="0" cy="0" r="1" gradientTransform="translate(3.35867 5.95923) rotate(161.042) scale(1.68855 8.24528)" gradientUnits="userSpaceOnUse"><stop offset=".12" stop-color="#4A4EFA"/><stop offset="1" stop-color="#4A4EFA" stop-opacity="0"/></radialGradient><radialGradient id="69f97277__paint17_radial_5232_4740" cx="0" cy="0" r="1" gradientTransform="translate(6.03209 13.2501) rotate(-90) scale(5.42506 5.92649)" gradientUnits="userSpaceOnUse"><stop offset=".465" stop-color="#FFAE3C"/><stop offset=".926" stop-color="#FFAE3C" stop-opacity="0"/></radialGradient><radialGradient id="69f97277__paint18_radial_5232_4740" cx="0" cy="0" r="1" gradientTransform="translate(6.03209 13.2501) rotate(-90) scale(11.8703)" gradientUnits="userSpaceOnUse"><stop offset=".844" stop-color="#E63CFE" stop-opacity="0"/><stop offset="1" stop-color="#E63CFE"/></radialGradient><linearGradient id="69f97277__paint0_linear_5232_4740" x1="16.343" x2="12.418" y1=".102" y2="12.794" gradientUnits="userSpaceOnUse"><stop stop-color="#4A4EFA"/><stop offset=".549" stop-color="#E63CFE"/></linearGradient><linearGradient id="69f97277__paint1_linear_5232_4740" x1="11.413" x2="13.636" y1="7.419" y2="8.138" gradientUnits="userSpaceOnUse"><stop offset=".16" stop-color="#4A4EFA"/><stop offset=".946" stop-color="#4A4EFA" stop-opacity="0"/></linearGradient><linearGradient id="69f97277__paint2_linear_5232_4740" x1="11.75" x2="13.147" y1="6.351" y2="6.798" gradientUnits="userSpaceOnUse"><stop stop-color="#39FBBB"/><stop offset="1" stop-color="#39FBBB" stop-opacity="0"/></linearGradient><linearGradient id="69f97277__paint14_linear_5232_4740" x1=".588" x2="3.972" y1="3.255" y2="13.784" gradientUnits="userSpaceOnUse"><stop offset=".17" stop-color="#E63CFE"/><stop offset=".709" stop-color="#FFAE3C"/></linearGradient><linearGradient id="69f97277__paint16_linear_5232_4740" x1="4.844" x2="4.37" y1="8.176" y2="8.331" gradientUnits="userSpaceOnUse"><stop stop-color="#E63CFE" stop-opacity=".33"/><stop offset="1" stop-color="#E63CFE" stop-opacity="0"/></linearGradient></defs></svg>`;
export const WindowInfoIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M12.667 2H3.333C2.597 2 2 2.597 2 3.333v9.334C2 13.403 2.597 14 3.333 14h9.334c.736 0 1.333-.597 1.333-1.333V3.333C14 2.597 13.403 2 12.667 2ZM8 11.516V7.853"/><rect width="1.4" height="1.4" x="7.3" y="4.484" fill="currentColor" rx=".7"/></svg>`;
diff --git a/packages/icons/svg-string.ts b/packages/icons/svg-string.ts
index fbdffd0b83..eeafbd9804 100644
--- a/packages/icons/svg-string.ts
+++ b/packages/icons/svg-string.ts
@@ -1,5 +1,6 @@
import { readdir, readFile, writeFile } from "node:fs/promises";
import { basename, extname } from "node:path";
+import { createHash } from "node:crypto"; // Import createHash
import { type Config, optimize } from "svgo";
const pascalcase = (string: string) => {
@@ -16,6 +17,20 @@ const transformComponentName = (filename: string) => {
return `${pascalcase(name).replace(/^[0-9]/, (char) => `_${char}`)}Icon`;
};
+const prefixCache = new Map<string, string>();
+const getHashedPrefix = (path?: string) => {
+ if (path === undefined) {
+ return "svg";
+ }
+ const cached = prefixCache.get(path);
+ if (cached !== undefined) {
+ return cached;
+ }
+ const hash = createHash("sha256").update(path).digest("hex").slice(0, 8);
+ prefixCache.set(path, hash);
+ return hash;
+};
+
const plugins: Config["plugins"] = [
{
name: "preset-default",
@@ -25,11 +40,20 @@ const plugins: Config["plugins"] = [
removeViewBox: false,
convertTransform: false,
inlineStyles: false,
+ cleanupIds: false,
},
},
},
// convert width/height to viewBox if missing
{ name: "removeDimensions" },
+ {
+ name: "prefixIds",
+ params: {
+ prefix: (_node: unknown, info: { path?: string }) =>
+ getHashedPrefix(info.path),
+ prefixClassNames: false,
+ },
+ },
{
name: "addAttributesToSVGElement",
params: {
@@ -52,6 +76,7 @@ for (const name of await readdir("./icons")) {
const exportName = transformComponentName(name);
const content = await readFile(`./icons/${name}`, "utf-8");
const { data: optimized } = optimize(content, {
+ path: `./icons/${name}`,
plugins,
});
moduleContent += `export const ${exportName} = \`${optimized.trim()}\`;\n`;
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index d346e86ff1..328dd2fe70 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -382,9 +382,6 @@ importers:
react:
specifier: 18.3.0-canary-14898b6a9-20240318
version: 18.3.0-canary-14898b6a9-20240318
- react-colorful:
- specifier: ^5.6.1
react-dom:
specifier: 18.3.0-canary-14898b6a9-20240318
version: 18.3.0-canary-14898b6a9-20240318([email protected])
@@ -1450,6 +1447,9 @@ importers:
match-sorter:
specifier: ^8.0.0
version: 8.0.0
+ react-colorful:
+ specifier: ^5.6.1
react-hot-toast:
specifier: ^2.5.1