-
Notifications
You must be signed in to change notification settings - Fork 3
/
layoutHelper.ts
155 lines (140 loc) · 4.04 KB
/
layoutHelper.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import type { CSSProperties } from 'vue'
// import { colors } from '@unocss/preset-mini'
// export function resolveColor(colorName: string, defaultColor: string = '#000000'): string {
// // If the input is already a hex code, return it
// if (/^#([0-9A-F]{3}){1,2}$/i.test(colorName)) {
// return colorName
// }
// // Split the color name into base and shade
// const [baseColor, shade] = colorName.toLowerCase().split('-')
// // Function to find the color in the colors object
// function findColor(obj: any, base: string, shade?: string): string | null {
// if (base in obj) {
// if (shade && typeof obj[base] === 'object' && shade in obj[base]) {
// return obj[base][shade]
// } else if (!shade && typeof obj[base] === 'string') {
// return obj[base]
// }
// }
// for (const value of Object.values(obj)) {
// if (typeof value === 'object' && value !== null) {
// const result = findColor(value, base, shade)
// if (result) return result
// }
// }
// return null
// }
// // Search for the color in the UnoCSS colors object
// const hexCode = findColor(colors, baseColor, shade)
// // If a valid color is found, return its hex code; otherwise, return the default color
// return hexCode || defaultColor
// }
/**
* Resolve urls from frontmatter and append with the base url
*/
export function resolveAssetUrl(url: string) {
if (url.startsWith('/')) return import.meta.env.BASE_URL + url.slice(1)
return url
}
export function handleBackground(background?: string, dim = false): CSSProperties {
const isColor = background && ['#', 'rgb', 'hsl'].some((v) => background.indexOf(v) === 0)
const style = {
background: isColor ? background : undefined,
color: background && !isColor ? 'white' : undefined,
backgroundImage: isColor
? undefined
: background
? dim
? `linear-gradient(#0005, #0008), url(${resolveAssetUrl(background)})`
: `url("${resolveAssetUrl(background)}")`
: undefined,
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center',
backgroundSize: 'cover',
}
if (!style.background) delete style.background
return style
}
export function compute_alignment(val) {
switch (val) {
case 'ct':
return 'ns-c-center ns-c-top'
case 'cm':
return 'ns-c-center ns-c-middle'
case 'cb':
return 'ns-c-center ns-c-bottom'
case 'lt':
return 'ns-c-left ns-c-top'
case 'lm':
return 'ns-c-left ns-c-middle'
case 'lb':
return 'ns-c-left ns-c-bottom'
case 'rt':
return 'ns-c-right ns-c-top'
case 'rm':
return 'ns-c-right ns-c-middle'
case 'rb':
return 'ns-c-right ns-c-bottom'
case 'c':
return 'ns-c-center ns-c-top'
case 'l':
return 'ns-c-left ns-c-top'
case 'r':
return 'ns-c-right ns-c-top'
default:
return 'error'
}
}
function compute_size(left) {
return { l: left, r: 12 - left }
}
export function compute_column_size(val) {
switch (val) {
case 'is-1':
case 'is-1-11':
case 'is-one-twelfth':
return compute_size(1)
case 'is-2':
case 'is-2-10':
case 'is-one-sixth':
return compute_size(2)
case 'is-3':
case 'is-3-9':
case 'is-one-quarter':
return compute_size(3)
case 'is-4':
case 'is-4-8':
case 'is-one-third':
return compute_size(4)
case 'is-5':
case 'is-5-7':
return compute_size(5)
case 'is-6':
case 'is-6-6':
case 'is-two-quarters':
case 'is-two-fourths':
case 'is-one-half':
case 'is-half':
return compute_size(6)
case 'is-7':
case 'is-7-5':
return compute_size(7)
case 'is-8':
case 'is-8-4':
case 'is-two-thirds':
return compute_size(8)
case 'is-9':
case 'is-9-3':
case 'is-three-quarters':
case 'three-fourths':
return compute_size(9)
case 'is-10':
case 'is-10-2':
return compute_size(10)
case 'is-11':
case 'is-11-1':
return compute_size(11)
default:
return 'error'
}
}