Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
fix: hide alignment UI dots at line intersections to avoid sub-pixel artifacts
Oleg Isonen7d308a5a7f15
diff --git a/apps/builder/app/builder/features/style-panel/sections/layout/shared/alignment-ui.stories.tsx b/apps/builder/app/builder/features/style-panel/sections/layout/shared/alignment-ui.stories.tsxindex 9a36814640..67b4c0dcbb 100644--- a/apps/builder/app/builder/features/style-panel/sections/layout/shared/alignment-ui.stories.tsx+++ b/apps/builder/app/builder/features/style-panel/sections/layout/shared/alignment-ui.stories.tsx@@ -6,8 +6,9 @@ export default {component: AlignmentUi,};-const alignItems = ["start", "center", "end", "stretch", "baseline"];+const alignItems = ["normal", "start", "center", "end", "stretch", "baseline"];const justifyContent = [+ "normal","start","center","end",@@ -15,68 +16,51 @@ const justifyContent = ["space-around",];-export const RowDirection = () => (- <Box css={{ width: 72, color: theme.colors.foregroundFlexUiMain }}>- <AlignmentUi- justifyContent="center"- alignItems="center"- isColumnDirection={false}- color="currentColor"- itemStretchWidth={false}- itemStretchHeight={false}- onSelect={() => {}}- />- </Box>-);--export const ColumnDirection = () => (- <Box css={{ width: 72, color: theme.colors.foregroundFlexUiMain }}>- <AlignmentUi- justifyContent="center"- alignItems="center"- isColumnDirection={true}- color="currentColor"- itemStretchWidth={false}- itemStretchHeight={false}- onSelect={() => {}}- />- </Box>-);--export const StretchedItems = () => (- <Box css={{ width: 72, color: theme.colors.foregroundFlexUiMain }}>- <AlignmentUi- justifyContent="start"- alignItems="stretch"- isColumnDirection={false}- color="currentColor"- itemStretchWidth={false}- itemStretchHeight={true}- onSelect={() => {}}- />- </Box>-);--export const AllCombinations = () => (+const CombinationGrid = ({+ isColumnDirection,+}: {+ isColumnDirection: boolean;+}) => (<Flex direction="column" gap="2">- <Box css={{ fontSize: 10, paddingLeft: 80, fontWeight: "bold" }}>- justify-content- </Box>+ <Flex gap="2" align="center">+ <Box css={{ width: 70 }} />+ {justifyContent.map((jc) => (+ <Box+ key={jc}+ css={{+ width: 64,+ fontSize: 10,+ textAlign: "center",+ fontWeight: "bold",+ }}+ >+ {jc}+ </Box>+ ))}+ </Flex>{alignItems.map((ai) => (<Flex key={ai} gap="2" align="center"><Box css={{ fontSize: 10, width: 70, textAlign: "right" }}>{ai}</Box>{justifyContent.map((jc) => (<Boxkey={jc}- css={{ width: 72, color: theme.colors.foregroundFlexUiMain }}+ css={{+ width: 64,+ height: 62,+ color: theme.colors.foregroundFlexUiMain,+ }}><AlignmentUijustifyContent={jc}alignItems={ai}- isColumnDirection={false}+ isColumnDirection={isColumnDirection}color="currentColor"- itemStretchWidth={ai === "stretch"}- itemStretchHeight={false}+ itemStretchWidth={+ isColumnDirection && (ai === "stretch" || ai === "normal")+ }+ itemStretchHeight={+ !isColumnDirection && (ai === "stretch" || ai === "normal")+ }onSelect={() => {}}/></Box>@@ -85,3 +69,7 @@ export const AllCombinations = () => ())}</Flex>);++export const FlexRow = () => <CombinationGrid isColumnDirection={false} />;++export const FlexColumn = () => <CombinationGrid isColumnDirection={true} />;diff --git a/apps/builder/app/builder/features/style-panel/sections/layout/shared/alignment-ui.tsx b/apps/builder/app/builder/features/style-panel/sections/layout/shared/alignment-ui.tsxindex 5dfc4269b7..cb9918c699 100644--- a/apps/builder/app/builder/features/style-panel/sections/layout/shared/alignment-ui.tsx+++ b/apps/builder/app/builder/features/style-panel/sections/layout/shared/alignment-ui.tsx@@ -2,27 +2,71 @@ import { Box, Flex, Grid, IconButton } from "@webstudio-is/design-system";import { DotIcon } from "@webstudio-is/icons";import { theme } from "@webstudio-is/design-system";-// Sometimes we need to hide a dot that ends up at an end-// of a line and visually extends it+// Hide dots where flex/grid item lines overlap to avoid sub-pixel artifacts.+// Lines have a cross-axis position (from alignItems) and main-axis positions+// (from justifyContent). A dot is hidden when it sits at an intersection.const shouldHideDot = ({x,y,justifyContent,alignItems,+ isColumnDirection,+ itemStretchWidth,+ itemStretchHeight,}: {x: number;y: number;justifyContent: string;alignItems: string;+ isColumnDirection: boolean;+ itemStretchWidth: boolean;+ itemStretchHeight: boolean;}) => {- if (justifyContent === "space-between") {- if (alignItems === "start" || alignItems === "baseline") {- return x === 2 && y === 0;- }- if (alignItems === "end") {- return x === 2 && y === 2;+ const crossAxis = isColumnDirection ? x : y;+ const mainAxis = isColumnDirection ? y : x;++ // Determine if the dot's cross-axis position overlaps with lines+ const isStretched =+ (isColumnDirection ? itemStretchWidth : itemStretchHeight) ||+ alignItems === "stretch" ||+ alignItems === "normal";++ let crossMatch = false;+ if (isStretched) {+ crossMatch = true; // lines span all cross-axis positions+ } else {+ switch (alignItems) {+ case "start":+ case "baseline":+ crossMatch = crossAxis === 0;+ break;+ case "center":+ crossMatch = crossAxis === 1;+ break;+ case "end":+ crossMatch = crossAxis === 2;+ break;}}++ if (!crossMatch) {+ return false;+ }++ // Determine if the dot's main-axis position overlaps with lines+ switch (justifyContent) {+ case "normal":+ case "start":+ return mainAxis === 0;+ case "center":+ return mainAxis === 1;+ case "end":+ return mainAxis === 2;+ case "space-between":+ case "space-around":+ return true;+ }+return false;};@@ -106,16 +150,24 @@ export const AlignmentUi = ({}}onClick={() => onSelect({ x, y })}>- {shouldHideDot({- x,- y,- justifyContent,- alignItems,- }) === false && (- <Box css={{ size: 16 }}>- <DotIcon size={8} />- </Box>- )}+ <Box+ css={{+ size: 16,+ visibility: shouldHideDot({+ x,+ y,+ justifyContent,+ alignItems,+ isColumnDirection,+ itemStretchWidth,+ itemStretchHeight,+ })+ ? "hidden"+ : "visible",+ }}+ >+ <DotIcon size={8} />+ </Box></IconButton></Flex>);