import { Property } from 'csstype'; import { cssProperty } from '../utils/style'; import { Formatter, SizePropertyTheme, Theme, TLength } from './typings'; import { pxFormatter } from '../utils/formatter'; import { get } from 'onekijs-framework'; const sizeFormatter = (type: 'width' | 'height', value: SizePropertyTheme, theme: Theme): string => { if (get(theme.sizes, `${value}`) !== undefined) { return get(theme.sizes, `${value}`) as string; } if (value === 'auto') return 'auto'; if (value === 'none') return 'none'; if (value === 'full') return '100%'; if (value === 'screen') return type === 'height' ? '100vh' : '100vw'; if (value.toString().includes('/')) { const [time, div] = value .toString() .split('/') .map((x) => parseInt(x)); return `${(100 * time) / div}%`; } return pxFormatter(value, theme); }; const widthFormatter: Formatter = (value, theme) => { return sizeFormatter('width', value, theme); }; const heightFormatter: Formatter = (value, theme) => { return sizeFormatter('height', value, theme); }; // spacing or fraction or auto or full or screen export const width = cssProperty>('width', widthFormatter); // spacing or fraction or auto or full or screen export const minWidth = cssProperty>('min-width', widthFormatter); export const maxWidth = cssProperty>('max-width', widthFormatter); export const height = cssProperty>('height', heightFormatter); export const minHeight = cssProperty>('min-height', heightFormatter); export const maxHeight = cssProperty>('max-height', heightFormatter); export const overscrollBehavior = cssProperty('overscroll-behavior'); export const overscrollBehaviorBlock = cssProperty('overscroll-behavior-block'); export const overscrollBehaviorInline = cssProperty('overscroll-behavior-inline'); export const overscrollBehaviorX = cssProperty('overscroll-behavior-x'); export const overscrollBehaviorY = cssProperty('overscroll-behavior-y');