このページの翻訳はまだありません。英語版を表示しています。

Style

CSS layout configuration for a node, including flexbox, sizing, spacing, and alignment properties.

This class holds all CSS layout properties for a node. Create an instance with new Style() and configure properties before passing to TaffyTree.newLeaf().

Default Value

When created, all properties are set to their CSS default values:

  • display: Display.Block
  • position: Position.Relative
  • flexDirection: FlexDirection.Row
  • flexWrap: FlexWrap.NoWrap
  • flexGrow: 0
  • flexShrink: 1
  • All alignment properties: undefined (use default behavior)
  • All dimensions: "auto"
  • All spacing: 0

Constructors

Constructor

new Style(props?): Style;

Creates a new Style instance with default values

Parameters

ParameterTypeDescription
props?anyOptional object with initial style properties

Returns

Style

  • A new Style object with all properties set to CSS defaults

Example

// Create with defaults const style = new Style(); console.log(style.display); // Display.Block // Create with initial properties const style2 = new Style({ display: Display.Flex, flexDirection: FlexDirection.Column, width: 200, marginLeft: 10, });

Properties

PropertyTypeDefault valueDescription
alignContentAlignContent | undefinedundefinedGets the align-content property Controls distribution of space between lines in a multi-line flex container.
alignItemsAlignItems | undefinedundefinedGets the align-items property Defines the default alignment for all children on the cross axis.
alignSelfAlignSelf | undefinedundefinedGets the align-self property Overrides the parent's align-items for this specific element.
aspectRationumber | undefinedundefinedGets the aspect ratio The ratio of width to height. Used to maintain proportions.
borderRect<LengthPercentage>undefinedGets the border width Width of the element's border on each side.
borderBottomanyundefinedGets the bottom border width
borderLeftanyundefinedGets the left border width
borderRightanyundefinedGets the right border width
borderTopanyundefinedGets the top border width
bottomanyundefinedGets the bottom inset offset
boxSizingBoxSizingBoxSizing.BorderBoxGets the box sizing mode Determines whether padding and border are included in dimensions.
columnGapanyundefinedGets the column gap (horizontal spacing between items)
displayDisplay- Display.BlockGets the display mode Determines the layout algorithm used for this element and its children.
flexBasisDimensionundefinedGets the flex-basis The initial size of a flex item before growing/shrinking.
flexDirectionFlexDirection- FlexDirection.RowGets the flex direction Defines the main axis direction for flex items.
flexGrownumberundefinedGets the flex grow factor Determines how much the item grows relative to siblings when there is extra space available.
flexShrinknumberundefinedGets the flex shrink factor Determines how much the item shrinks relative to siblings when there is insufficient space.
flexWrapFlexWrap- FlexWrap.NoWrapGets the flex wrap mode Controls whether flex items wrap to new lines.
gapSize<LengthPercentage>undefinedGets the gap Spacing between flex/grid items.
gridAutoColumnsTrackSizingFunction[]undefinedGets the grid-auto-columns property Defines the size of implicitly created columns.
gridAutoFlowGridAutoFlow- GridAutoFlow.RowGets the grid-auto-flow property Controls how auto-placed items are inserted into the grid.
gridAutoRowsTrackSizingFunction[]undefinedGets the grid-auto-rows property Defines the size of implicitly created rows.
gridColumnLine<GridPlacement>undefinedGets the grid-column property Defines which column in the grid the item should start and end at. Corresponds to CSS grid-column shorthand.
gridColumnEndanyundefinedGets the grid-column-end property
gridColumnStartanyundefinedGets the grid-column-start property
gridRowLine<GridPlacement>undefinedGets the grid-row property Defines which row in the grid the item should start and end at. Corresponds to CSS grid-row shorthand.
gridRowEndanyundefinedGets the grid-row-end property
gridRowStartanyundefinedGets the grid-row-start property
gridTemplateAreasGridTemplateArea[]undefinedGets the grid-template-areas property Defines named grid areas that can be referenced by grid items.
gridTemplateColumnNamesstring[][]undefinedGets the grid-template-column-names property Defines the named lines between the columns.
gridTemplateColumnsGridTemplateComponent[]undefinedGets the grid-template-columns property Defines the track sizing functions (widths) of the grid columns.
gridTemplateRowNamesstring[][]undefinedGets the grid-template-row-names property Defines the named lines between the rows.
gridTemplateRowsGridTemplateComponent[]undefinedGets the grid-template-rows property Defines the track sizing functions (heights) of the grid rows.
heightDimensionundefinedGets the height
insetRect<LengthPercentageAuto>undefinedGets the inset Positioning offsets for absolutely positioned elements.
itemIsReplacedboolean- falseGets whether this item is a replaced element Replaced elements have special sizing behavior (e.g., <img>, <video>).
itemIsTableboolean- falseGets whether this item is a table Table children are handled specially in block layout.
justifyContentJustifyContent | undefinedundefinedGets the justify-content property Defines alignment and spacing of items along the main axis.
justifyItemsAlignItems | undefinedundefinedGets the justify-items property Defines the default justify-self for all children in the inline axis. This is primarily used for CSS Grid layout.
justifySelfAlignSelf | undefinedundefinedGets the justify-self property Overrides the parent's justify-items for this specific element in the inline axis.
leftanyundefinedGets the left inset offset
marginRect<LengthPercentageAuto>undefinedGets the margin Outer spacing around the element.
marginBottomanyundefinedGets the bottom margin
marginLeftanyundefinedGets the left margin
marginRightanyundefinedGets the right margin
marginTopanyundefinedGets the top margin
maxHeightDimensionundefinedGets the maximum height
maxSizeSize<Dimension>undefinedGets the maximum size constraints
maxWidthDimensionundefinedGets the maximum width
minHeightDimensionundefinedGets the minimum height
minSizeSize<Dimension>undefinedGets the minimum size constraints
minWidthDimensionundefinedGets the minimum width
overflowPoint<Overflow>undefinedGets the overflow behavior Controls how content that exceeds the container is handled.
overflowXOverflowundefinedGets the horizontal overflow behavior
overflowYOverflowundefinedGets the vertical overflow behavior
paddingRect<LengthPercentage>undefinedGets the padding Inner spacing between the element's border and content.
paddingBottomanyundefinedGets the bottom padding
paddingLeftanyundefinedGets the left padding
paddingRightanyundefinedGets the right padding
paddingTopanyundefinedGets the top padding
positionPosition- Position.RelativeGets the position mode Determines how the element is positioned within its parent.
rightanyundefinedGets the right inset offset
rowGapanyundefinedGets the row gap (vertical spacing between items)
scrollbarWidthnumber- 0Gets the scrollbar width The width of the scrollbar gutter when overflow is set to Scroll.
sizeSize<Dimension>undefinedGets the size (width and height)
textAlignTextAlign- TextAlign.AutoGets the text-align property Used by block layout to implement legacy text alignment behavior.
topanyundefinedGets the top inset offset
widthDimensionundefinedGets the width

Methods

[dispose]()

dispose: void;

Returns

void


free()

free(): void;

Returns

void


get()

Call Signature

get<K>(...keys): StylePropertyValues[K];

Reads multiple style properties in a single WASM call. Supports both object properties and individual flat properties.

Type Parameters
Type Parameter
K extends StyleProperty
Parameters
ParameterType
...keys[K]
Returns

StylePropertyValues[K]

Single value for one key, tuple for 2-3 keys, array for 4+ keys

Throws

Error if any property key is unknown.

Remarks
  • Single property: returns exact value type (including undefined for optional properties)
  • 2-3 properties: returns typed tuple for destructuring
  • 4+ properties: returns array of union types
Example
const style = new Style(); style.display = Display.Flex; // Single property - returns exact type (includes undefined for optional properties) const display = style.get("display"); // Display | undefined // Individual flat property - returns exact type const width = style.get("width"); // Dimension // Optional properties return undefined when not set const alignItems = style.get("alignItems"); // AlignItems | undefined // Two properties - returns tuple for destructuring const [d, w] = style.get("display", "width"); // [Display | undefined, Dimension] // Three properties - returns tuple for destructuring const [d2, w2, f] = style.get("display", "width", "flexGrow"); // Four or more properties - returns array const values = style.get("display", "width", "flexGrow", "flexShrink"); // values type is: (Display | Dimension | number | undefined)[]

Call Signature

get<K1, K2>(...keys): [StylePropertyValues[K1], StylePropertyValues[K2]];
Type Parameters
Type Parameter
K1 extends StyleProperty
K2 extends StyleProperty
Parameters
ParameterType
...keys[K1, K2]
Returns

[StylePropertyValues[K1], StylePropertyValues[K2]]

Call Signature

get<K1, K2, K3>(...keys): [StylePropertyValues[K1], StylePropertyValues[K2], StylePropertyValues[K3]];
Type Parameters
Type Parameter
K1 extends StyleProperty
K2 extends StyleProperty
K3 extends StyleProperty
Parameters
ParameterType
...keys[K1, K2, K3]
Returns

[StylePropertyValues[K1], StylePropertyValues[K2], StylePropertyValues[K3]]

Call Signature

get<Keys>(...keys): StylePropertyArrayValues<Keys>;
Type Parameters
Type Parameter
Keys extends StyleProperty[]
Parameters
ParameterType
...keysKeys
Returns

StylePropertyArrayValues<Keys>


set()

set(props): void;

Sets multiple style properties in a single WASM call. Supports both object properties and individual flat properties.

Parameters

ParameterTypeDescription
propsStylePropertyValuesObject mapping property keys to their values

Returns

void

Remarks

Only accepts valid property keys with their corresponding value types.

Throws

Error if any property key is unknown.

Example

const style = new Style(); style.set({ display: Display.Flex, width: 200, marginLeft: 10, marginRight: "auto", });

© 2026 ByteLand Technology Limited