-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from bitovi/feat/paragraphs
Feat/paragraphs
- Loading branch information
Showing
13 changed files
with
2,469 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Layout Processing Logic | ||
|
||
## Figma to CSS Flex Layout Mapping | ||
|
||
The layout processors convert Figma's Auto Layout properties to CSS Flexbox properties. Here's how the mapping works: | ||
|
||
### Display Property | ||
- When `layoutMode !== "NONE"` -> `display: flex` | ||
- When `layoutMode === "NONE"` -> no display property output | ||
|
||
### Flex Direction | ||
- `layoutMode === "HORIZONTAL"` -> `flex-direction: row` | ||
- `layoutMode === "VERTICAL"` -> `flex-direction: column` | ||
|
||
### Justify Content (Primary Axis Alignment) | ||
Controlled by `primaryAxisAlignItems`: | ||
- `"MIN"` -> `justify-content: flex-start` | ||
- `"CENTER"` -> `justify-content: center` | ||
- `"MAX"` -> `justify-content: flex-end` | ||
- `"SPACE_BETWEEN"` -> `justify-content: space-between` | ||
|
||
### Align Items (Counter Axis Alignment) | ||
Controlled by `counterAxisAlignItems`: | ||
- `"MIN"` -> `align-items: flex-start` | ||
- `"CENTER"` -> `align-items: center` | ||
- `"MAX"` -> `align-items: flex-end` | ||
- `"BASELINE"` -> `align-items: baseline` | ||
|
||
## Complete Mapping Table | ||
|
||
| Figma layoutMode | Figma primaryAxisAlignItems | Figma counterAxisAlignItems | CSS display | CSS flex-direction | CSS justify-content | CSS align-items | | ||
|-----------------|---------------------------|---------------------------|------------|------------------|-------------------|----------------| | ||
| "HORIZONTAL" | "MIN" | "MIN" | flex | row | flex-start | flex-start | | ||
| "HORIZONTAL" | "CENTER" | "MIN" | flex | row | center | flex-start | | ||
| "HORIZONTAL" | "MAX" | "MIN" | flex | row | flex-end | flex-start | | ||
| "HORIZONTAL" | "SPACE_BETWEEN" | "MIN" | flex | row | space-between | flex-start | | ||
| "VERTICAL" | "MIN" | "MIN" | flex | column | flex-start | flex-start | | ||
| "VERTICAL" | "CENTER" | "MIN" | flex | column | center | flex-start | | ||
| "VERTICAL" | "MAX" | "MIN" | flex | column | flex-end | flex-start | | ||
| "VERTICAL" | "SPACE_BETWEEN" | "MIN" | flex | column | space-between | flex-start | | ||
[...additional combinations omitted for brevity] | ||
|
||
## Implementation Notes | ||
|
||
1. Layout properties are only processed for nodes with Auto Layout enabled (`layoutMode !== "NONE"`) | ||
2. The primary axis alignment maps to justify-content | ||
3. The counter axis alignment maps to align-items | ||
4. Gap is handled separately using the itemSpacing property | ||
|
||
See `layout.processor.ts` for the implementation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { StyleProcessor, ProcessedValue } from '../types'; | ||
|
||
interface NodeWithTextAlign { | ||
textAlignHorizontal: string; | ||
} | ||
|
||
function hasTextAlign(node: SceneNode): node is SceneNode & NodeWithTextAlign { | ||
return 'textAlignHorizontal' in node; | ||
} | ||
|
||
export const textAlignProcessors: StyleProcessor[] = [ | ||
{ | ||
property: "text-align", | ||
bindingKey: undefined, | ||
process: async (_, node?: SceneNode): Promise<ProcessedValue | null> => { | ||
if (!node || !hasTextAlign(node)) return null; | ||
|
||
// Map Figma's text align values to CSS values | ||
const alignmentMap: Record<string, string> = { | ||
LEFT: 'left', | ||
CENTER: 'center', | ||
RIGHT: 'right', | ||
JUSTIFIED: 'justify' | ||
}; | ||
|
||
const alignment = alignmentMap[node.textAlignHorizontal.toUpperCase()]; | ||
if (!alignment) return null; | ||
|
||
return { | ||
value: alignment, | ||
rawValue: alignment | ||
}; | ||
} | ||
} | ||
]; |
Oops, something went wrong.