@dcl-regenesislabs/react-ecs 0.0.0-stage → 7.0.0-42722791062.commit-bc8d909
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +130 -2
- package/dist/components/Button/index.d.ts +15 -0
- package/dist/components/Button/index.js +62 -0
- package/dist/components/Button/types.d.ts +16 -0
- package/dist/components/Button/types.js +1 -0
- package/dist/components/Dropdown/index.d.ts +21 -0
- package/dist/components/Dropdown/index.js +48 -0
- package/dist/components/Dropdown/types.d.ts +13 -0
- package/dist/components/Dropdown/types.js +1 -0
- package/dist/components/Input/index.d.ts +25 -0
- package/dist/components/Input/index.js +49 -0
- package/dist/components/Input/types.d.ts +15 -0
- package/dist/components/Input/types.js +1 -0
- package/dist/components/InteractableArea/index.d.ts +23 -0
- package/dist/components/InteractableArea/index.js +34 -0
- package/dist/components/InteractableArea/types.d.ts +23 -0
- package/dist/components/InteractableArea/types.js +1 -0
- package/dist/components/Label/index.d.ts +17 -0
- package/dist/components/Label/index.js +37 -0
- package/dist/components/Label/types.d.ts +34 -0
- package/dist/components/Label/types.js +1 -0
- package/dist/components/Label/utils.d.ts +11 -0
- package/dist/components/Label/utils.js +69 -0
- package/dist/components/ScreenInsetArea/index.d.ts +22 -0
- package/dist/components/ScreenInsetArea/index.js +33 -0
- package/dist/components/ScreenInsetArea/types.d.ts +22 -0
- package/dist/components/ScreenInsetArea/types.js +1 -0
- package/dist/components/index.d.ts +26 -0
- package/dist/components/index.js +36 -0
- package/dist/components/listeners/types.d.ts +19 -0
- package/dist/components/listeners/types.js +11 -0
- package/dist/components/types.d.ts +45 -0
- package/dist/components/types.js +1 -0
- package/dist/components/uiBackground/index.d.ts +6 -0
- package/dist/components/uiBackground/index.js +16 -0
- package/dist/components/uiBackground/types.d.ts +61 -0
- package/dist/components/uiBackground/types.js +1 -0
- package/dist/components/uiBackground/utils.d.ts +1 -0
- package/dist/components/uiBackground/utils.js +51 -0
- package/dist/components/uiTransform/index.d.ts +6 -0
- package/dist/components/uiTransform/index.js +91 -0
- package/dist/components/uiTransform/types.d.ts +134 -0
- package/dist/components/uiTransform/types.js +1 -0
- package/dist/components/uiTransform/utils.d.ts +42 -0
- package/dist/components/uiTransform/utils.js +246 -0
- package/dist/components/utils.d.ts +1 -0
- package/dist/components/utils.js +195 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +15 -0
- package/dist/platform.d.ts +12 -0
- package/dist/platform.js +26 -0
- package/dist/react-ecs.d.ts +87 -0
- package/dist/react-ecs.js +10 -0
- package/dist/reconciler/index.d.ts +6 -0
- package/dist/reconciler/index.js +322 -0
- package/dist/reconciler/types.d.ts +31 -0
- package/dist/reconciler/types.js +1 -0
- package/dist/reconciler/utils.d.ts +40 -0
- package/dist/reconciler/utils.js +174 -0
- package/dist/system.d.ts +92 -0
- package/dist/system.js +264 -0
- package/package.json +41 -3
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { calcOnViewport, getScaleCtx, getUiScaleFactor } from '../utils';
|
|
2
|
+
const parseFont = {
|
|
3
|
+
'sans-serif': 0 /* Font.F_SANS_SERIF */,
|
|
4
|
+
serif: 1 /* Font.F_SERIF */,
|
|
5
|
+
monospace: 2 /* Font.F_MONOSPACE */
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export function getFont(font) {
|
|
11
|
+
if (!font)
|
|
12
|
+
return undefined;
|
|
13
|
+
return { font: parseFont[font] };
|
|
14
|
+
}
|
|
15
|
+
const parseTextAlign = {
|
|
16
|
+
'top-left': 0 /* TextAlignMode.TAM_TOP_LEFT */,
|
|
17
|
+
'top-center': 1 /* TextAlignMode.TAM_TOP_CENTER */,
|
|
18
|
+
'top-right': 2 /* TextAlignMode.TAM_TOP_RIGHT */,
|
|
19
|
+
'middle-left': 3 /* TextAlignMode.TAM_MIDDLE_LEFT */,
|
|
20
|
+
'middle-center': 4 /* TextAlignMode.TAM_MIDDLE_CENTER */,
|
|
21
|
+
'middle-right': 5 /* TextAlignMode.TAM_MIDDLE_RIGHT */,
|
|
22
|
+
'bottom-left': 6 /* TextAlignMode.TAM_BOTTOM_LEFT */,
|
|
23
|
+
'bottom-center': 7 /* TextAlignMode.TAM_BOTTOM_CENTER */,
|
|
24
|
+
'bottom-right': 8 /* TextAlignMode.TAM_BOTTOM_RIGHT */
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export function getTextAlign(textAlign) {
|
|
30
|
+
if (!textAlign)
|
|
31
|
+
return undefined;
|
|
32
|
+
return { textAlign: parseTextAlign[textAlign] };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export function getFontSize(fontSize) {
|
|
38
|
+
if (!fontSize)
|
|
39
|
+
return undefined;
|
|
40
|
+
if (typeof fontSize === 'string')
|
|
41
|
+
return { fontSize: calcOnViewport(fontSize) };
|
|
42
|
+
return { fontSize: fontSize * getUiScaleFactor() };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Scales a font size depending on a context's width/height
|
|
46
|
+
* @param {number} fontSize size of the font to scale
|
|
47
|
+
* @param {ScaleUnit} [scaleUnit=0.39] the scaling unit (uses "width" as unit if a number is supplied)
|
|
48
|
+
* @param {ScaleContext} [ctx=viewport] the context where to apply the scaling
|
|
49
|
+
* @returns {number} the fontSize scaled
|
|
50
|
+
* @see https://matthewjamestaylor.com/responsive-font-size#fluid
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export function scaleFontSize(fontSize, scaleUnit = 0.39, ctx = getScaleCtx()) {
|
|
54
|
+
if (!ctx)
|
|
55
|
+
return fontSize;
|
|
56
|
+
return fontSize + calcOnViewport(scaleUnit, ctx);
|
|
57
|
+
}
|
|
58
|
+
const parseTextWrap = {
|
|
59
|
+
wrap: 0 /* TextWrap.TW_WRAP */,
|
|
60
|
+
nowrap: 1 /* TextWrap.TW_NO_WRAP */
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
export function getTextWrap(textWrap) {
|
|
66
|
+
if (!textWrap)
|
|
67
|
+
return { textWrap: 0 /* TextWrap.TW_WRAP */ };
|
|
68
|
+
return { textWrap: parseTextWrap[textWrap] };
|
|
69
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ReactEcs } from '../../react-ecs';
|
|
2
|
+
import { UiScreenInsetAreaProps } from './types';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
* ScreenInsetArea component
|
|
7
|
+
*
|
|
8
|
+
* Constrains its children to the area inside the renderer-reported screen
|
|
9
|
+
* inset (safe margins). On mobile this is the area excluding the notch,
|
|
10
|
+
* status bar, home indicator and rounded corners. On desktop the insets are
|
|
11
|
+
* typically zero, so the container fills the canvas.
|
|
12
|
+
*
|
|
13
|
+
* The container is absolutely positioned with top/left/right/bottom matching
|
|
14
|
+
* the current `UiCanvasInformation.screenInsetArea`, so a child sized
|
|
15
|
+
* 100%x100% fills the safe area exactly.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* <ScreenInsetArea><MyHud /></ScreenInsetArea>
|
|
19
|
+
*
|
|
20
|
+
* @category Component
|
|
21
|
+
*/
|
|
22
|
+
export declare function ScreenInsetArea(props: UiScreenInsetAreaProps): ReactEcs.JSX.Element;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ReactEcs } from '../../react-ecs';
|
|
2
|
+
import { UiEntity } from '../index';
|
|
3
|
+
import { compensateInsetForUiScale, getScreenInsetArea } from '../utils';
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
* ScreenInsetArea component
|
|
8
|
+
*
|
|
9
|
+
* Constrains its children to the area inside the renderer-reported screen
|
|
10
|
+
* inset (safe margins). On mobile this is the area excluding the notch,
|
|
11
|
+
* status bar, home indicator and rounded corners. On desktop the insets are
|
|
12
|
+
* typically zero, so the container fills the canvas.
|
|
13
|
+
*
|
|
14
|
+
* The container is absolutely positioned with top/left/right/bottom matching
|
|
15
|
+
* the current `UiCanvasInformation.screenInsetArea`, so a child sized
|
|
16
|
+
* 100%x100% fills the safe area exactly.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* <ScreenInsetArea><MyHud /></ScreenInsetArea>
|
|
20
|
+
*
|
|
21
|
+
* @category Component
|
|
22
|
+
*/
|
|
23
|
+
/* @__PURE__ */
|
|
24
|
+
export function ScreenInsetArea(props) {
|
|
25
|
+
// Insets are canvas px; pre-divide so the parser's scale multiplication cancels out.
|
|
26
|
+
const { top, left, right, bottom } = compensateInsetForUiScale(getScreenInsetArea());
|
|
27
|
+
const { uiTransform, ...otherProps } = props;
|
|
28
|
+
return (ReactEcs.createElement(UiEntity, { ...otherProps, uiTransform: {
|
|
29
|
+
...uiTransform,
|
|
30
|
+
positionType: 'absolute',
|
|
31
|
+
position: { top, left, right, bottom }
|
|
32
|
+
} }));
|
|
33
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EntityPropTypes } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* ScreenInsetArea component props
|
|
4
|
+
*
|
|
5
|
+
* The container reads the current `screenInsetArea` reported by the renderer
|
|
6
|
+
* via `UiCanvasInformation` (the device safe margins — notch, status bar,
|
|
7
|
+
* home indicator, rounded corners) and constrains its children to the area
|
|
8
|
+
* inside those insets using absolute positioning. Layout props that control
|
|
9
|
+
* the container's own position (`positionType`, `position`) are owned by the
|
|
10
|
+
* component and are not configurable from props — every other layout,
|
|
11
|
+
* background and event prop is forwarded as usual.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export type UiScreenInsetAreaProps = Omit<EntityPropTypes, 'uiTransform'> & {
|
|
16
|
+
/**
|
|
17
|
+
* Layout overrides forwarded to the underlying entity. The
|
|
18
|
+
* `positionType` and `position` fields are reserved by the container and
|
|
19
|
+
* any value provided here is ignored.
|
|
20
|
+
*/
|
|
21
|
+
uiTransform?: Omit<NonNullable<EntityPropTypes['uiTransform']>, 'positionType' | 'position'>;
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ReactEcs } from '../react-ecs';
|
|
2
|
+
import { UiLabelProps } from './Label/types';
|
|
3
|
+
import { EntityPropTypes } from './types';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export * from './uiTransform/types';
|
|
6
|
+
export * from './listeners/types';
|
|
7
|
+
export * from './Input/types';
|
|
8
|
+
export * from './uiBackground/types';
|
|
9
|
+
export * from './Dropdown/types';
|
|
10
|
+
export * from './Label/types';
|
|
11
|
+
export * from './Button/types';
|
|
12
|
+
export * from './ScreenInsetArea/types';
|
|
13
|
+
export * from './InteractableArea/types';
|
|
14
|
+
export { Dropdown } from './Dropdown';
|
|
15
|
+
export { Input } from './Input';
|
|
16
|
+
export { Label, scaleFontSize } from './Label';
|
|
17
|
+
export { Button } from './Button';
|
|
18
|
+
export { ScreenInsetArea } from './ScreenInsetArea';
|
|
19
|
+
export { InteractableArea } from './InteractableArea';
|
|
20
|
+
/**
|
|
21
|
+
* @public
|
|
22
|
+
* @category Component
|
|
23
|
+
*/
|
|
24
|
+
export declare function UiEntity(props: EntityPropTypes & {
|
|
25
|
+
uiText?: UiLabelProps;
|
|
26
|
+
}): ReactEcs.JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ReactEcs } from '../react-ecs';
|
|
2
|
+
import { getFont, getFontSize, getTextAlign, getTextWrap } from './Label/utils';
|
|
3
|
+
import { parseProps } from './utils';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export * from './uiTransform/types';
|
|
6
|
+
export * from './listeners/types';
|
|
7
|
+
export * from './Input/types';
|
|
8
|
+
export * from './uiBackground/types';
|
|
9
|
+
export * from './Dropdown/types';
|
|
10
|
+
export * from './Label/types';
|
|
11
|
+
export * from './Button/types';
|
|
12
|
+
export * from './ScreenInsetArea/types';
|
|
13
|
+
export * from './InteractableArea/types';
|
|
14
|
+
export { Dropdown } from './Dropdown';
|
|
15
|
+
export { Input } from './Input';
|
|
16
|
+
export { Label, scaleFontSize } from './Label';
|
|
17
|
+
export { Button } from './Button';
|
|
18
|
+
export { ScreenInsetArea } from './ScreenInsetArea';
|
|
19
|
+
export { InteractableArea } from './InteractableArea';
|
|
20
|
+
/**
|
|
21
|
+
* @public
|
|
22
|
+
* @category Component
|
|
23
|
+
*/
|
|
24
|
+
/* @__PURE__ */
|
|
25
|
+
export function UiEntity(props) {
|
|
26
|
+
const uiText = props.uiText && {
|
|
27
|
+
uiText: {
|
|
28
|
+
...props.uiText,
|
|
29
|
+
...getFont(props.uiText.font),
|
|
30
|
+
...getTextAlign(props.uiText.textAlign),
|
|
31
|
+
...getFontSize(props.uiText.fontSize),
|
|
32
|
+
...getTextWrap(props.uiText.textWrap)
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
return ReactEcs.createElement("entity", { ...parseProps(props), ...uiText });
|
|
36
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Callback function to be triggered on a specified event
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export type Callback = () => void;
|
|
6
|
+
/**
|
|
7
|
+
* User key event Listeners
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export type Listeners = {
|
|
11
|
+
/** triggered on mouse down event */
|
|
12
|
+
onMouseDown?: Callback;
|
|
13
|
+
/** triggered on mouse up event */
|
|
14
|
+
onMouseUp?: Callback;
|
|
15
|
+
/** triggered on mouse hover event */
|
|
16
|
+
onMouseEnter?: Callback;
|
|
17
|
+
/** triggered on mouse leave event */
|
|
18
|
+
onMouseLeave?: Callback;
|
|
19
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const listeners = {
|
|
2
|
+
onMouseDown: undefined,
|
|
3
|
+
onMouseUp: undefined,
|
|
4
|
+
onMouseEnter: undefined,
|
|
5
|
+
onMouseLeave: undefined
|
|
6
|
+
};
|
|
7
|
+
const listenersKey = Object.keys(listeners);
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export const isListener = (key) => listenersKey.includes(key);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { PBUiInputBinding } from '@dcl/ecs';
|
|
2
|
+
import { ReactEcs } from '../react-ecs';
|
|
3
|
+
import { Listeners } from './listeners/types';
|
|
4
|
+
import { UiBackgroundProps } from './uiBackground/types';
|
|
5
|
+
import { UiTransformProps } from './uiTransform/types';
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
* Common props to all components
|
|
9
|
+
*/
|
|
10
|
+
export interface EntityPropTypes extends Listeners {
|
|
11
|
+
/** Layout component, to position things in the canvas */
|
|
12
|
+
uiTransform?: UiTransformProps;
|
|
13
|
+
/** To define a background color or image */
|
|
14
|
+
uiBackground?: UiBackgroundProps;
|
|
15
|
+
/** Bind input actions to this element, held down while it's pressed (touch or pointer) */
|
|
16
|
+
uiInputBinding?: PBUiInputBinding;
|
|
17
|
+
/** Uinique key to identiy elments when iterating arrays */
|
|
18
|
+
key?: Key;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Keys help React identify which items have changed, are added, or are removed.
|
|
22
|
+
* Keys should be given to the elements inside the array to give the elements a stable identity:
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export type Key = number | string;
|
|
26
|
+
export type Children = ReactEcs.JSX.ReactNode;
|
|
27
|
+
/**
|
|
28
|
+
* unit value type. i.e. 'vw' || 'vh'
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export type ScaleUnits = 'vw' | 'vh';
|
|
32
|
+
/**
|
|
33
|
+
* unit value specified. i.e. 10 || '10vw' || '10vh'
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export type ScaleUnit = `${number}${ScaleUnits}` | number;
|
|
37
|
+
/**
|
|
38
|
+
* context for applying a scale
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export type ScaleContext = {
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
ratio: number;
|
|
45
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getTexture, getTextureMode } from './utils';
|
|
2
|
+
/**
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
/* @__PURE__ */
|
|
6
|
+
export function parseUiBackground(props) {
|
|
7
|
+
if (!props || !Object.keys(props).length)
|
|
8
|
+
return undefined;
|
|
9
|
+
const texture = getTexture(props);
|
|
10
|
+
return {
|
|
11
|
+
...props,
|
|
12
|
+
...getTextureMode(props.textureMode),
|
|
13
|
+
uvs: props.uvs ?? [],
|
|
14
|
+
texture
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { BorderRect } from '@dcl/ecs';
|
|
2
|
+
import { Color4 } from '@dcl/ecs/dist/components/generated/pb/decentraland/common/colors.gen';
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
* Background Component props
|
|
6
|
+
* .i.e to define a background color or image
|
|
7
|
+
*/
|
|
8
|
+
export interface UiBackgroundProps {
|
|
9
|
+
/** Background color. @defaultValue `{ r: 1, g: 1, b: 1, a: 1 }` */
|
|
10
|
+
color?: Color4 | undefined;
|
|
11
|
+
textureMode?: TextureMode;
|
|
12
|
+
/** Texture slices represents the top | right | bottom | left sizes of the slices for the borders. Values are percentages of the texture. */
|
|
13
|
+
textureSlices?: BorderRect | undefined;
|
|
14
|
+
/** when STRETCH is selected, the uvs are configurable */
|
|
15
|
+
uvs?: number[];
|
|
16
|
+
/** AvatarTexture for the background */
|
|
17
|
+
avatarTexture?: UiAvatarTexture;
|
|
18
|
+
/** Texture for the background */
|
|
19
|
+
texture?: UiTexture;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Avatar Texture
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export interface UiAvatarTexture {
|
|
26
|
+
userId: string;
|
|
27
|
+
wrapMode?: TextureWrapType;
|
|
28
|
+
filterMode?: TextureFilterType;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Texture
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export type UiTexture = {
|
|
35
|
+
src: string;
|
|
36
|
+
wrapMode?: TextureWrapType;
|
|
37
|
+
filterMode?: TextureFilterType;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export type TextureWrapType = 'repeat' | 'clamp' | 'mirror';
|
|
43
|
+
/**
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
export type TextureFilterType = 'point' | 'bi-linear' | 'tri-linear';
|
|
47
|
+
/**
|
|
48
|
+
* @public
|
|
49
|
+
* NINE_SLICES - https://docs.unity3d.com/Manual/UIE-USS-SupportedProperties.html (Slicing section)
|
|
50
|
+
* https://forum.unity.com/threads/how-does-slicing-in-ui-tookkit-works.1235863/
|
|
51
|
+
* https://docs.unity3d.com/Manual/9SliceSprites.html
|
|
52
|
+
* https://developer.mozilla.org/en-US/docs/Web/CSS/border-image-slice
|
|
53
|
+
|
|
54
|
+
* CENTER - CENTER enables the texture to be rendered centered in relation to the
|
|
55
|
+
* element. If the element is smaller than the texture then the background
|
|
56
|
+
* should use the element as stencil to cut off the out-of-bounds area
|
|
57
|
+
|
|
58
|
+
* STRETCH - STRETCH enables the texture to cover all the area of the container,
|
|
59
|
+
* adopting its aspect ratio.
|
|
60
|
+
*/
|
|
61
|
+
export type TextureMode = 'nine-slices' | 'center' | 'stretch';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const parseTextureMode = {
|
|
2
|
+
'nine-slices': 0 /* BackgroundTextureMode.NINE_SLICES */,
|
|
3
|
+
center: 1 /* BackgroundTextureMode.CENTER */,
|
|
4
|
+
stretch: 2 /* BackgroundTextureMode.STRETCH */
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export function getTextureMode(mode) {
|
|
10
|
+
const value = mode ? parseTextureMode[mode] : 1 /* BackgroundTextureMode.CENTER */;
|
|
11
|
+
return { textureMode: value };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export function getTexture(props) {
|
|
17
|
+
if (props.texture) {
|
|
18
|
+
return {
|
|
19
|
+
tex: {
|
|
20
|
+
$case: 'texture',
|
|
21
|
+
texture: parseTexture(props.texture)
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (props.avatarTexture) {
|
|
26
|
+
return {
|
|
27
|
+
tex: {
|
|
28
|
+
$case: 'avatarTexture',
|
|
29
|
+
avatarTexture: parseTexture(props.avatarTexture)
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
function parseTexture(texture) {
|
|
36
|
+
return {
|
|
37
|
+
...texture,
|
|
38
|
+
wrapMode: texture.wrapMode ? parseWrap[texture.wrapMode] : undefined,
|
|
39
|
+
filterMode: texture.filterMode ? parseFilter[texture.filterMode] : undefined
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const parseWrap = {
|
|
43
|
+
repeat: 0 /* TextureWrapMode.TWM_REPEAT */,
|
|
44
|
+
clamp: 1 /* TextureWrapMode.TWM_CLAMP */,
|
|
45
|
+
mirror: 2 /* TextureWrapMode.TWM_MIRROR */
|
|
46
|
+
};
|
|
47
|
+
const parseFilter = {
|
|
48
|
+
point: 0 /* TextureFilterMode.TFM_POINT */,
|
|
49
|
+
'bi-linear': 1 /* TextureFilterMode.TFM_BILINEAR */,
|
|
50
|
+
'tri-linear': 2 /* TextureFilterMode.TFM_TRILINEAR */
|
|
51
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { getAlign, getDisplay, getFlexDirection, getFlexWrap, getJustify, getOverflow, getPointerFilter, getPositionType, parseBorderColor, parseBorderRadius, parseBorderWidth, parsePosition, parseSize } from './utils';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export const CANVAS_ROOT_ENTITY = 0;
|
|
6
|
+
const defaultUiTransform = {
|
|
7
|
+
overflow: 0 /* YGOverflow.YGO_VISIBLE */,
|
|
8
|
+
display: 0 /* YGDisplay.YGD_FLEX */,
|
|
9
|
+
justifyContent: 0 /* YGJustify.YGJ_FLEX_START */,
|
|
10
|
+
alignSelf: 0 /* YGAlign.YGA_AUTO */,
|
|
11
|
+
flexDirection: 0 /* YGFlexDirection.YGFD_ROW */,
|
|
12
|
+
positionType: 0 /* YGPositionType.YGPT_RELATIVE */,
|
|
13
|
+
parent: CANVAS_ROOT_ENTITY,
|
|
14
|
+
rightOf: 0,
|
|
15
|
+
flexBasis: 0,
|
|
16
|
+
width: 0,
|
|
17
|
+
height: 0,
|
|
18
|
+
minWidth: 0,
|
|
19
|
+
minHeight: 0,
|
|
20
|
+
maxWidth: 0,
|
|
21
|
+
maxHeight: 0,
|
|
22
|
+
flexGrow: 0,
|
|
23
|
+
marginBottom: 0,
|
|
24
|
+
marginBottomUnit: 0 /* YGUnit.YGU_UNDEFINED */,
|
|
25
|
+
marginLeft: 0,
|
|
26
|
+
marginLeftUnit: 0 /* YGUnit.YGU_UNDEFINED */,
|
|
27
|
+
marginRight: 0,
|
|
28
|
+
marginRightUnit: 0 /* YGUnit.YGU_UNDEFINED */,
|
|
29
|
+
marginTop: 0,
|
|
30
|
+
marginTopUnit: 0 /* YGUnit.YGU_UNDEFINED */,
|
|
31
|
+
maxHeightUnit: 0 /* YGUnit.YGU_UNDEFINED */,
|
|
32
|
+
maxWidthUnit: 0 /* YGUnit.YGU_UNDEFINED */,
|
|
33
|
+
minHeightUnit: 0 /* YGUnit.YGU_UNDEFINED */,
|
|
34
|
+
minWidthUnit: 0 /* YGUnit.YGU_UNDEFINED */,
|
|
35
|
+
paddingBottom: 0,
|
|
36
|
+
paddingBottomUnit: 0 /* YGUnit.YGU_UNDEFINED */,
|
|
37
|
+
paddingLeft: 0,
|
|
38
|
+
paddingLeftUnit: 0 /* YGUnit.YGU_UNDEFINED */,
|
|
39
|
+
paddingTopUnit: 0 /* YGUnit.YGU_UNDEFINED */,
|
|
40
|
+
paddingRight: 0,
|
|
41
|
+
paddingRightUnit: 0 /* YGUnit.YGU_UNDEFINED */,
|
|
42
|
+
paddingTop: 0,
|
|
43
|
+
positionBottom: 0,
|
|
44
|
+
positionBottomUnit: 0 /* YGUnit.YGU_UNDEFINED */,
|
|
45
|
+
positionLeft: 0,
|
|
46
|
+
positionLeftUnit: 0 /* YGUnit.YGU_UNDEFINED */,
|
|
47
|
+
positionRight: 0,
|
|
48
|
+
positionRightUnit: 0 /* YGUnit.YGU_UNDEFINED */,
|
|
49
|
+
positionTop: 0,
|
|
50
|
+
positionTopUnit: 0 /* YGUnit.YGU_UNDEFINED */,
|
|
51
|
+
flexBasisUnit: 0 /* YGUnit.YGU_UNDEFINED */,
|
|
52
|
+
widthUnit: 3 /* YGUnit.YGU_AUTO */,
|
|
53
|
+
heightUnit: 0 /* YGUnit.YGU_UNDEFINED */,
|
|
54
|
+
pointerFilter: 0 /* PointerFilterMode.PFM_NONE */,
|
|
55
|
+
opacity: 1,
|
|
56
|
+
zIndex: 0
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
/* @__PURE__ */
|
|
62
|
+
export function parseUiTransform(props = {}) {
|
|
63
|
+
const { height, minHeight, maxHeight, width, minWidth, maxWidth, alignItems, alignContent, flexWrap, borderRadius, borderWidth, borderColor, ...otherProps } = props;
|
|
64
|
+
return {
|
|
65
|
+
...defaultUiTransform,
|
|
66
|
+
...otherProps,
|
|
67
|
+
...parsePosition(props.position, 'position'),
|
|
68
|
+
...parsePosition(props.margin, 'margin'),
|
|
69
|
+
...parsePosition(props.padding, 'padding'),
|
|
70
|
+
...parseSize(props.height, 'height'),
|
|
71
|
+
...parseSize(props.minHeight, 'minHeight'),
|
|
72
|
+
...parseSize(props.maxHeight, 'maxHeight'),
|
|
73
|
+
...parseSize(props.width, 'width'),
|
|
74
|
+
...parseSize(props.minWidth, 'minWidth'),
|
|
75
|
+
...parseSize(props.maxWidth, 'maxWidth'),
|
|
76
|
+
...getDisplay(props.display),
|
|
77
|
+
...getAlign('alignSelf', props.alignSelf ?? 'auto'),
|
|
78
|
+
...getJustify(props.justifyContent),
|
|
79
|
+
...getFlexDirection(props.flexDirection),
|
|
80
|
+
...getOverflow(props.overflow),
|
|
81
|
+
...getPointerFilter(props.pointerFilter),
|
|
82
|
+
...getPositionType(props.positionType),
|
|
83
|
+
// Optional values
|
|
84
|
+
...(alignContent && getAlign('alignContent', alignContent)),
|
|
85
|
+
...(alignItems && getAlign('alignItems', alignItems)),
|
|
86
|
+
...(flexWrap && getFlexWrap(flexWrap)),
|
|
87
|
+
...(borderRadius && parseBorderRadius(borderRadius)),
|
|
88
|
+
...(borderWidth && parseBorderWidth(borderWidth)),
|
|
89
|
+
...(borderColor && parseBorderColor(borderColor))
|
|
90
|
+
};
|
|
91
|
+
}
|