UNPKG

@dcl/react-ecs

Version:
92 lines (91 loc) 3.56 kB
import { getAlign, getDisplay, getFlexDirection, getFlexWrap, getJustify, getOverflow, getPointerFilter, getPositionType, parseBorderColor, parseBorderRadius, parseBorderWidth, parsePosition, parseSize } from './utils'; /** * @internal */ export const CANVAS_ROOT_ENTITY = 0; const defaultUiTransform = { overflow: 0 /* YGOverflow.YGO_VISIBLE */, display: 0 /* YGDisplay.YGD_FLEX */, justifyContent: 0 /* YGJustify.YGJ_FLEX_START */, alignSelf: 0 /* YGAlign.YGA_AUTO */, flexDirection: 0 /* YGFlexDirection.YGFD_ROW */, positionType: 0 /* YGPositionType.YGPT_RELATIVE */, parent: CANVAS_ROOT_ENTITY, rightOf: 0, flexBasis: 0, width: 0, height: 0, minWidth: 0, minHeight: 0, maxWidth: 0, maxHeight: 0, flexGrow: 0, marginBottom: 0, marginBottomUnit: 0 /* YGUnit.YGU_UNDEFINED */, marginLeft: 0, marginLeftUnit: 0 /* YGUnit.YGU_UNDEFINED */, marginRight: 0, marginRightUnit: 0 /* YGUnit.YGU_UNDEFINED */, marginTop: 0, marginTopUnit: 0 /* YGUnit.YGU_UNDEFINED */, maxHeightUnit: 0 /* YGUnit.YGU_UNDEFINED */, maxWidthUnit: 0 /* YGUnit.YGU_UNDEFINED */, minHeightUnit: 0 /* YGUnit.YGU_UNDEFINED */, minWidthUnit: 0 /* YGUnit.YGU_UNDEFINED */, paddingBottom: 0, paddingBottomUnit: 0 /* YGUnit.YGU_UNDEFINED */, paddingLeft: 0, paddingLeftUnit: 0 /* YGUnit.YGU_UNDEFINED */, paddingTopUnit: 0 /* YGUnit.YGU_UNDEFINED */, paddingRight: 0, paddingRightUnit: 0 /* YGUnit.YGU_UNDEFINED */, paddingTop: 0, positionBottom: 0, positionBottomUnit: 0 /* YGUnit.YGU_UNDEFINED */, positionLeft: 0, positionLeftUnit: 0 /* YGUnit.YGU_UNDEFINED */, positionRight: 0, positionRightUnit: 0 /* YGUnit.YGU_UNDEFINED */, positionTop: 0, positionTopUnit: 0 /* YGUnit.YGU_UNDEFINED */, flexBasisUnit: 0 /* YGUnit.YGU_UNDEFINED */, widthUnit: 3 /* YGUnit.YGU_AUTO */, heightUnit: 0 /* YGUnit.YGU_UNDEFINED */, pointerFilter: 0 /* PointerFilterMode.PFM_NONE */, opacity: 1, zIndex: 0 }; /** * @public */ /* @__PURE__ */ export function parseUiTransform(props = {}) { const { height, minHeight, maxHeight, width, minWidth, maxWidth, alignItems, alignContent, flexWrap, borderRadius, borderWidth, borderColor, ...otherProps } = props; return { ...defaultUiTransform, ...otherProps, ...parsePosition(props.position, 'position'), ...parsePosition(props.margin, 'margin'), ...parsePosition(props.padding, 'padding'), ...parseSize(props.height, 'height'), ...parseSize(props.minHeight, 'minHeight'), ...parseSize(props.maxHeight, 'maxHeight'), ...parseSize(props.width, 'width'), ...parseSize(props.minWidth, 'minWidth'), ...parseSize(props.maxWidth, 'maxWidth'), ...getDisplay(props.display), ...getAlign('alignSelf', props.alignSelf ?? 'auto'), ...getJustify(props.justifyContent), ...getFlexDirection(props.flexDirection), ...getOverflow(props.overflow), ...getPointerFilter(props.pointerFilter), ...getPositionType(props.positionType), // Optional values ...(alignContent && getAlign('alignContent', alignContent)), ...(alignItems && getAlign('alignItems', alignItems)), ...(flexWrap && getFlexWrap(flexWrap)), ...(borderRadius && parseBorderRadius(borderRadius)), ...(borderWidth && parseBorderWidth(borderWidth)), ...(borderColor && parseBorderColor(borderColor)) }; }