padding.ts

 1type PaddingOptions = {
 2    all?: number
 3    left?: number
 4    right?: number
 5    top?: number
 6    bottom?: number
 7}
 8
 9export type PaddingStyle = {
10    top: number
11    bottom: number
12    left: number
13    right: number
14}
15
16export const padding_style = (options: PaddingOptions): PaddingStyle => {
17    const { all, top, bottom, left, right } = options
18
19    if (all !== undefined)
20        return {
21            top: all,
22            bottom: all,
23            left: all,
24            right: all,
25        }
26
27    if (
28        top === undefined &&
29        bottom === undefined &&
30        left === undefined &&
31        right === undefined
32    )
33        throw new Error("Padding must have at least one value")
34
35    return {
36        top: top || 0,
37        bottom: bottom || 0,
38        left: left || 0,
39        right: right || 0,
40    }
41}