You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.5 KiB
TypeScript
96 lines
2.5 KiB
TypeScript
export function valueToUI(value: any): any {
|
|
if (!value || !value._kind)
|
|
throw new Error(`Expected UI constructor, got: ${JSON.stringify(value)}`);
|
|
|
|
switch(value._kind) {
|
|
case 'rect':
|
|
return {
|
|
kind: 'rect',
|
|
w: value.w,
|
|
h: value.h,
|
|
color: value.color,
|
|
radius: value.radius,
|
|
strokeWidth: value.strokeWidth,
|
|
strokeColor: value.strokeColor,
|
|
};
|
|
|
|
case 'text':
|
|
return {
|
|
kind: 'text',
|
|
content: value.content,
|
|
color: value.color,
|
|
};
|
|
|
|
case 'row':
|
|
return {
|
|
kind: 'row',
|
|
gap: value.gap || 0,
|
|
children: value.children.map(valueToUI),
|
|
};
|
|
|
|
case 'column':
|
|
return {
|
|
kind: 'column',
|
|
gap: value.gap || 0,
|
|
children: value.children.map(valueToUI),
|
|
};
|
|
|
|
case 'stack':
|
|
return {
|
|
kind: 'stack',
|
|
children: value.children.map(valueToUI),
|
|
};
|
|
|
|
case 'positioned':
|
|
return {
|
|
kind: 'positioned',
|
|
x: value.x || 0,
|
|
y: value.y || 0,
|
|
child: valueToUI(value.child),
|
|
};
|
|
|
|
case 'padding':
|
|
return {
|
|
kind: 'padding',
|
|
amount: value.amount || 0,
|
|
child: valueToUI(value.child),
|
|
};
|
|
|
|
case 'clickable':
|
|
return {
|
|
kind: 'clickable',
|
|
event: value.event,
|
|
child: valueToUI(value.child),
|
|
};
|
|
|
|
case 'clip':
|
|
return {
|
|
kind: 'clip',
|
|
w: value.w,
|
|
h: value.h,
|
|
child: valueToUI(value.child),
|
|
};
|
|
|
|
case 'opacity':
|
|
return {
|
|
kind: 'opacity',
|
|
opacity: value.opacity,
|
|
child: valueToUI(value.child),
|
|
};
|
|
|
|
case 'stateful':
|
|
return {
|
|
kind: 'stateful',
|
|
key: value.key,
|
|
focusable: value.focusable,
|
|
autoFocus: value.autoFocus,
|
|
init: value.init,
|
|
update: value.update,
|
|
view: value.view,
|
|
};
|
|
|
|
default:
|
|
throw new Error(`Unknown UI constructor: ${value._kind}`);
|
|
}
|
|
}
|