Files
yoga/javascript/src/generated/YGEnums.ts

216 lines
4.7 KiB
TypeScript
Raw Normal View History

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// @generated by enums.py
export enum Align {
Auto = 0,
FlexStart = 1,
Center = 2,
FlexEnd = 3,
Stretch = 4,
Baseline = 5,
SpaceBetween = 6,
SpaceAround = 7,
SpaceEvenly = 8,
}
export enum BoxSizing {
BorderBox = 0,
ContentBox = 1,
}
export enum Dimension {
Width = 0,
Height = 1,
}
export enum Direction {
Inherit = 0,
LTR = 1,
RTL = 2,
}
export enum Display {
Flex = 0,
None = 1,
Add support for `display: contents` style (#1726) Summary: X-link: https://github.com/facebook/react-native/pull/47035 This PR adds support for `display: contents` style by effectively skipping nodes with `display: contents` set during layout. This required changes in the logic related to children traversal - before this PR a node would be always laid out in the context of its direct parent. After this PR that assumption is no longer true - `display: contents` allows nodes to be skipped, i.e.: ```html <div id="node1"> <div id="node2" style="display: contents;"> <div id="node3" /> </div> </div> ``` `node3` will be laid out as if it were a child of `node1`. Because of this, iterating over direct children of a node is no longer correct to achieve the correct layout. This PR introduces `LayoutableChildren::Iterator` which can traverse the subtree of a given node in a way that nodes with `display: contents` are replaced with their concrete children. A tree like this: ```mermaid flowchart TD A((A)) B((B)) C((C)) D((D)) E((E)) F((F)) G((G)) H((H)) I((I)) J((J)) A --> B A --> C B --> D B --> E C --> F D --> G F --> H G --> I H --> J style B fill:https://github.com/facebook/yoga/issues/050 style C fill:https://github.com/facebook/yoga/issues/050 style D fill:https://github.com/facebook/yoga/issues/050 style H fill:https://github.com/facebook/yoga/issues/050 style I fill:https://github.com/facebook/yoga/issues/050 ``` would be laid out as if the green nodes (ones with `display: contents`) did not exist. It also changes the logic where children were accessed by index to use the iterator instead as random access would be non-trivial to implement and it's not really necessary - the iteration was always sequential and indices were only used as boundaries. There's one place where knowledge of layoutable children is required to calculate the gap. An optimization for this is for a node to keep a counter of how many `display: contents` nodes are its children. If there are none, a short path of just returning the size of the children vector can be taken, otherwise it needs to iterate over layoutable children and count them, since the structure may be complex. One more major change this PR introduces is `cleanupContentsNodesRecursively`. Since nodes with `display: contents` would be entirely skipped during the layout pass, they would keep previous metrics, would be kept as dirty, and, in the case of nested `contents` nodes, would not be cloned, breaking `doesOwn` relation. All of this is handled in the new method which clones `contents` nodes recursively, sets empty layout, and marks them as clean and having a new layout so that it can be used on the React Native side. Relies on https://github.com/facebook/yoga/pull/1725 Changelog: [Internal] Pull Request resolved: https://github.com/facebook/yoga/pull/1726 Test Plan: Added tests for `display: contents` based on existing tests for `display: none` and ensured that all the tests were passing. Reviewed By: joevilches Differential Revision: D64404340 Pulled By: NickGerleman fbshipit-source-id: f6f6e9a6fad82873f18c8a0ead58aad897df5d09
2024-10-18 22:05:41 -07:00
Contents = 2,
}
export enum Edge {
Left = 0,
Top = 1,
Right = 2,
Bottom = 3,
Start = 4,
End = 5,
Horizontal = 6,
Vertical = 7,
All = 8,
}
export enum Errata {
None = 0,
StretchFlexBasis = 1,
Remove legacy absolute positioning path (#1725) Summary: X-link: https://github.com/facebook/react-native/pull/46984 Pull Request resolved: https://github.com/facebook/yoga/pull/1725 The legacy (wrong) absolute positioning path positions in two places, including work that is definitely always overwritten in the new absolute layout path. This came up before for position: static, but we didn't clean this up at the time. This code is also now leading display: contents impl being more annoying. This diff tries to converge to the more spec correct implementation of positioning here, that also only happens in one place. Previous path would potentially also incorrectly justify when `justify-content` was non-default, but not handled in the previous few cases? We don't have access to the flexLine at this point later, and apart from the existing tests now passing I reused the new correct logic for justification (spec says we should position child as if its the only child in the container https://www.w3.org/TR/css-flexbox-1/#abspos-items). I added a new, more scoped errata `AbsolutePositionWithoutInsetsExcludesPadding` to preserve some of the legacy behavior that showed as very breaking. I also did not try removing `AbsolutePercentAgainstInnerSize` which I suspect would be more breaking than this change. Changelog: [General][Breaking] - More spec compliant absolute positioning Reviewed By: joevilches Differential Revision: D64244949 fbshipit-source-id: ca97570e0de82e8f0424a0912adfd0b05254559e
2024-10-17 22:40:16 -07:00
AbsolutePositionWithoutInsetsExcludesPadding = 2,
AbsolutePercentAgainstInnerSize = 4,
All = 2147483647,
Classic = 2147483646,
}
export enum ExperimentalFeature {
WebFlexBasis = 0,
}
export enum FlexDirection {
Column = 0,
ColumnReverse = 1,
Row = 2,
RowReverse = 3,
}
export enum Gutter {
Column = 0,
Row = 1,
All = 2,
}
export enum Justify {
FlexStart = 0,
Center = 1,
FlexEnd = 2,
SpaceBetween = 3,
SpaceAround = 4,
SpaceEvenly = 5,
}
export enum LogLevel {
Error = 0,
Warn = 1,
Info = 2,
Debug = 3,
Verbose = 4,
Fatal = 5,
}
export enum MeasureMode {
Undefined = 0,
Exactly = 1,
AtMost = 2,
}
export enum NodeType {
Default = 0,
Text = 1,
}
export enum Overflow {
Visible = 0,
Hidden = 1,
Scroll = 2,
}
export enum PositionType {
Static = 0,
Relative = 1,
Absolute = 2,
}
export enum Unit {
Undefined = 0,
Point = 1,
Percent = 2,
Auto = 3,
MaxContent = 4,
FitContent = 5,
Stretch = 6,
}
export enum Wrap {
NoWrap = 0,
Wrap = 1,
WrapReverse = 2,
}
const constants = {
ALIGN_AUTO: Align.Auto,
ALIGN_FLEX_START: Align.FlexStart,
ALIGN_CENTER: Align.Center,
ALIGN_FLEX_END: Align.FlexEnd,
ALIGN_STRETCH: Align.Stretch,
ALIGN_BASELINE: Align.Baseline,
ALIGN_SPACE_BETWEEN: Align.SpaceBetween,
ALIGN_SPACE_AROUND: Align.SpaceAround,
ALIGN_SPACE_EVENLY: Align.SpaceEvenly,
BOX_SIZING_BORDER_BOX: BoxSizing.BorderBox,
BOX_SIZING_CONTENT_BOX: BoxSizing.ContentBox,
DIMENSION_WIDTH: Dimension.Width,
DIMENSION_HEIGHT: Dimension.Height,
DIRECTION_INHERIT: Direction.Inherit,
DIRECTION_LTR: Direction.LTR,
DIRECTION_RTL: Direction.RTL,
DISPLAY_FLEX: Display.Flex,
DISPLAY_NONE: Display.None,
Add support for `display: contents` style (#1726) Summary: X-link: https://github.com/facebook/react-native/pull/47035 This PR adds support for `display: contents` style by effectively skipping nodes with `display: contents` set during layout. This required changes in the logic related to children traversal - before this PR a node would be always laid out in the context of its direct parent. After this PR that assumption is no longer true - `display: contents` allows nodes to be skipped, i.e.: ```html <div id="node1"> <div id="node2" style="display: contents;"> <div id="node3" /> </div> </div> ``` `node3` will be laid out as if it were a child of `node1`. Because of this, iterating over direct children of a node is no longer correct to achieve the correct layout. This PR introduces `LayoutableChildren::Iterator` which can traverse the subtree of a given node in a way that nodes with `display: contents` are replaced with their concrete children. A tree like this: ```mermaid flowchart TD A((A)) B((B)) C((C)) D((D)) E((E)) F((F)) G((G)) H((H)) I((I)) J((J)) A --> B A --> C B --> D B --> E C --> F D --> G F --> H G --> I H --> J style B fill:https://github.com/facebook/yoga/issues/050 style C fill:https://github.com/facebook/yoga/issues/050 style D fill:https://github.com/facebook/yoga/issues/050 style H fill:https://github.com/facebook/yoga/issues/050 style I fill:https://github.com/facebook/yoga/issues/050 ``` would be laid out as if the green nodes (ones with `display: contents`) did not exist. It also changes the logic where children were accessed by index to use the iterator instead as random access would be non-trivial to implement and it's not really necessary - the iteration was always sequential and indices were only used as boundaries. There's one place where knowledge of layoutable children is required to calculate the gap. An optimization for this is for a node to keep a counter of how many `display: contents` nodes are its children. If there are none, a short path of just returning the size of the children vector can be taken, otherwise it needs to iterate over layoutable children and count them, since the structure may be complex. One more major change this PR introduces is `cleanupContentsNodesRecursively`. Since nodes with `display: contents` would be entirely skipped during the layout pass, they would keep previous metrics, would be kept as dirty, and, in the case of nested `contents` nodes, would not be cloned, breaking `doesOwn` relation. All of this is handled in the new method which clones `contents` nodes recursively, sets empty layout, and marks them as clean and having a new layout so that it can be used on the React Native side. Relies on https://github.com/facebook/yoga/pull/1725 Changelog: [Internal] Pull Request resolved: https://github.com/facebook/yoga/pull/1726 Test Plan: Added tests for `display: contents` based on existing tests for `display: none` and ensured that all the tests were passing. Reviewed By: joevilches Differential Revision: D64404340 Pulled By: NickGerleman fbshipit-source-id: f6f6e9a6fad82873f18c8a0ead58aad897df5d09
2024-10-18 22:05:41 -07:00
DISPLAY_CONTENTS: Display.Contents,
EDGE_LEFT: Edge.Left,
EDGE_TOP: Edge.Top,
EDGE_RIGHT: Edge.Right,
EDGE_BOTTOM: Edge.Bottom,
EDGE_START: Edge.Start,
EDGE_END: Edge.End,
EDGE_HORIZONTAL: Edge.Horizontal,
EDGE_VERTICAL: Edge.Vertical,
EDGE_ALL: Edge.All,
ERRATA_NONE: Errata.None,
ERRATA_STRETCH_FLEX_BASIS: Errata.StretchFlexBasis,
Remove legacy absolute positioning path (#1725) Summary: X-link: https://github.com/facebook/react-native/pull/46984 Pull Request resolved: https://github.com/facebook/yoga/pull/1725 The legacy (wrong) absolute positioning path positions in two places, including work that is definitely always overwritten in the new absolute layout path. This came up before for position: static, but we didn't clean this up at the time. This code is also now leading display: contents impl being more annoying. This diff tries to converge to the more spec correct implementation of positioning here, that also only happens in one place. Previous path would potentially also incorrectly justify when `justify-content` was non-default, but not handled in the previous few cases? We don't have access to the flexLine at this point later, and apart from the existing tests now passing I reused the new correct logic for justification (spec says we should position child as if its the only child in the container https://www.w3.org/TR/css-flexbox-1/#abspos-items). I added a new, more scoped errata `AbsolutePositionWithoutInsetsExcludesPadding` to preserve some of the legacy behavior that showed as very breaking. I also did not try removing `AbsolutePercentAgainstInnerSize` which I suspect would be more breaking than this change. Changelog: [General][Breaking] - More spec compliant absolute positioning Reviewed By: joevilches Differential Revision: D64244949 fbshipit-source-id: ca97570e0de82e8f0424a0912adfd0b05254559e
2024-10-17 22:40:16 -07:00
ERRATA_ABSOLUTE_POSITION_WITHOUT_INSETS_EXCLUDES_PADDING: Errata.AbsolutePositionWithoutInsetsExcludesPadding,
ERRATA_ABSOLUTE_PERCENT_AGAINST_INNER_SIZE: Errata.AbsolutePercentAgainstInnerSize,
ERRATA_ALL: Errata.All,
ERRATA_CLASSIC: Errata.Classic,
EXPERIMENTAL_FEATURE_WEB_FLEX_BASIS: ExperimentalFeature.WebFlexBasis,
FLEX_DIRECTION_COLUMN: FlexDirection.Column,
FLEX_DIRECTION_COLUMN_REVERSE: FlexDirection.ColumnReverse,
FLEX_DIRECTION_ROW: FlexDirection.Row,
FLEX_DIRECTION_ROW_REVERSE: FlexDirection.RowReverse,
GUTTER_COLUMN: Gutter.Column,
GUTTER_ROW: Gutter.Row,
GUTTER_ALL: Gutter.All,
JUSTIFY_FLEX_START: Justify.FlexStart,
JUSTIFY_CENTER: Justify.Center,
JUSTIFY_FLEX_END: Justify.FlexEnd,
JUSTIFY_SPACE_BETWEEN: Justify.SpaceBetween,
JUSTIFY_SPACE_AROUND: Justify.SpaceAround,
JUSTIFY_SPACE_EVENLY: Justify.SpaceEvenly,
LOG_LEVEL_ERROR: LogLevel.Error,
LOG_LEVEL_WARN: LogLevel.Warn,
LOG_LEVEL_INFO: LogLevel.Info,
LOG_LEVEL_DEBUG: LogLevel.Debug,
LOG_LEVEL_VERBOSE: LogLevel.Verbose,
LOG_LEVEL_FATAL: LogLevel.Fatal,
MEASURE_MODE_UNDEFINED: MeasureMode.Undefined,
MEASURE_MODE_EXACTLY: MeasureMode.Exactly,
MEASURE_MODE_AT_MOST: MeasureMode.AtMost,
NODE_TYPE_DEFAULT: NodeType.Default,
NODE_TYPE_TEXT: NodeType.Text,
OVERFLOW_VISIBLE: Overflow.Visible,
OVERFLOW_HIDDEN: Overflow.Hidden,
OVERFLOW_SCROLL: Overflow.Scroll,
POSITION_TYPE_STATIC: PositionType.Static,
POSITION_TYPE_RELATIVE: PositionType.Relative,
POSITION_TYPE_ABSOLUTE: PositionType.Absolute,
UNIT_UNDEFINED: Unit.Undefined,
UNIT_POINT: Unit.Point,
UNIT_PERCENT: Unit.Percent,
UNIT_AUTO: Unit.Auto,
UNIT_MAX_CONTENT: Unit.MaxContent,
UNIT_FIT_CONTENT: Unit.FitContent,
UNIT_STRETCH: Unit.Stretch,
WRAP_NO_WRAP: Wrap.NoWrap,
WRAP_WRAP: Wrap.Wrap,
WRAP_WRAP_REVERSE: Wrap.WrapReverse,
}
export default constants