typewritingclass 0.2.0
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 +107 -0
- package/package.json +71 -0
- package/src/css.ts +140 -0
- package/src/cx.ts +105 -0
- package/src/dcx.ts +79 -0
- package/src/dynamic.ts +117 -0
- package/src/hash.ts +54 -0
- package/src/index.ts +137 -0
- package/src/inject.ts +86 -0
- package/src/layer.ts +81 -0
- package/src/modifiers/aria.ts +15 -0
- package/src/modifiers/colorScheme.ts +32 -0
- package/src/modifiers/data.ts +6 -0
- package/src/modifiers/direction.ts +5 -0
- package/src/modifiers/group.ts +21 -0
- package/src/modifiers/index.ts +17 -0
- package/src/modifiers/media.ts +11 -0
- package/src/modifiers/peer.ts +24 -0
- package/src/modifiers/pseudo.ts +183 -0
- package/src/modifiers/pseudoElements.ts +26 -0
- package/src/modifiers/responsive.ts +110 -0
- package/src/modifiers/supports.ts +6 -0
- package/src/registry.ts +171 -0
- package/src/rule.ts +202 -0
- package/src/runtime.ts +36 -0
- package/src/theme/animations.ts +11 -0
- package/src/theme/borders.ts +9 -0
- package/src/theme/colors.ts +326 -0
- package/src/theme/createTheme.ts +238 -0
- package/src/theme/filters.ts +20 -0
- package/src/theme/index.ts +9 -0
- package/src/theme/inject-theme.ts +81 -0
- package/src/theme/shadows.ts +8 -0
- package/src/theme/sizes.ts +37 -0
- package/src/theme/spacing.ts +44 -0
- package/src/theme/typography.ts +72 -0
- package/src/types.ts +273 -0
- package/src/utilities/accessibility.ts +33 -0
- package/src/utilities/backgrounds.ts +86 -0
- package/src/utilities/borders.ts +610 -0
- package/src/utilities/colors.ts +127 -0
- package/src/utilities/effects.ts +169 -0
- package/src/utilities/filters.ts +96 -0
- package/src/utilities/index.ts +57 -0
- package/src/utilities/interactivity.ts +253 -0
- package/src/utilities/layout.ts +1149 -0
- package/src/utilities/spacing.ts +681 -0
- package/src/utilities/svg.ts +34 -0
- package/src/utilities/tables.ts +54 -0
- package/src/utilities/transforms.ts +85 -0
- package/src/utilities/transitions.ts +98 -0
- package/src/utilities/typography.ts +380 -0
- package/src/when.ts +63 -0
|
@@ -0,0 +1,681 @@
|
|
|
1
|
+
import type { StyleRule } from '../types.ts'
|
|
2
|
+
import type { DynamicValue } from '../dynamic.ts'
|
|
3
|
+
import { createRule, createDynamicRule, wrapWithSelectorTemplate } from '../rule.ts'
|
|
4
|
+
import { resolveSpacing } from '../theme/spacing.ts'
|
|
5
|
+
import { isDynamic } from '../dynamic.ts'
|
|
6
|
+
|
|
7
|
+
function sp(value: number | string | DynamicValue): string | DynamicValue {
|
|
8
|
+
if (isDynamic(value)) return value
|
|
9
|
+
return resolveSpacing(value as number | string)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function spacingRule(prop: string, value: number | string | DynamicValue): StyleRule {
|
|
13
|
+
const v = sp(value)
|
|
14
|
+
if (isDynamic(v)) {
|
|
15
|
+
return createDynamicRule(
|
|
16
|
+
{ [prop]: `var(${v.__id})` },
|
|
17
|
+
{ [v.__id]: String(v.__value) },
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
return createRule({ [prop]: v as string })
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function spacingRuleMulti(props: string[], value: number | string | DynamicValue): StyleRule {
|
|
24
|
+
const v = sp(value)
|
|
25
|
+
if (isDynamic(v)) {
|
|
26
|
+
const decls: Record<string, string> = {}
|
|
27
|
+
for (const prop of props) decls[prop] = `var(${v.__id})`
|
|
28
|
+
return createDynamicRule(decls, { [v.__id]: String(v.__value) })
|
|
29
|
+
}
|
|
30
|
+
const decls: Record<string, string> = {}
|
|
31
|
+
for (const prop of props) decls[prop] = v as string
|
|
32
|
+
return createRule(decls)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Sets padding on all sides.
|
|
37
|
+
*
|
|
38
|
+
* Accepts a theme spacing scale number (maps to the spacing scale), a raw CSS string,
|
|
39
|
+
* or a {@link DynamicValue} for runtime values.
|
|
40
|
+
*
|
|
41
|
+
* @param value - Spacing scale number (`4` -> `1rem`), raw string (`'2.5rem'`), or `dynamic()` value.
|
|
42
|
+
* @returns A {@link StyleRule} that sets `padding`.
|
|
43
|
+
*
|
|
44
|
+
* @example Theme scale
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { cx, p } from 'typewritingclass'
|
|
47
|
+
*
|
|
48
|
+
* cx(p(4))
|
|
49
|
+
* // CSS: padding: 1rem;
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example Raw value
|
|
53
|
+
* ```ts
|
|
54
|
+
* cx(p('2.5rem'))
|
|
55
|
+
* // CSS: padding: 2.5rem;
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @example Dynamic value
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { dcx, p, dynamic } from 'typewritingclass'
|
|
61
|
+
*
|
|
62
|
+
* const { className, style } = dcx(p(dynamic(spacing)))
|
|
63
|
+
* // CSS: padding: var(--twc-d0);
|
|
64
|
+
* // style: { '--twc-d0': spacing }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export function p(value: number | string | DynamicValue): StyleRule {
|
|
68
|
+
return spacingRule('padding', value)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Sets horizontal padding (left and right).
|
|
73
|
+
*
|
|
74
|
+
* Accepts a theme spacing scale number, a raw CSS string,
|
|
75
|
+
* or a {@link DynamicValue} for runtime values.
|
|
76
|
+
*
|
|
77
|
+
* @param value - Spacing scale number (`4` -> `1rem`), raw string (`'20px'`), or `dynamic()` value.
|
|
78
|
+
* @returns A {@link StyleRule} that sets `padding-left` and `padding-right`.
|
|
79
|
+
*
|
|
80
|
+
* @example Theme scale
|
|
81
|
+
* ```ts
|
|
82
|
+
* import { cx, px } from 'typewritingclass'
|
|
83
|
+
*
|
|
84
|
+
* cx(px(6))
|
|
85
|
+
* // CSS: padding-left: 1.5rem; padding-right: 1.5rem;
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example Raw value
|
|
89
|
+
* ```ts
|
|
90
|
+
* cx(px('10px'))
|
|
91
|
+
* // CSS: padding-left: 10px; padding-right: 10px;
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @example Dynamic value
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { dcx, px, dynamic } from 'typewritingclass'
|
|
97
|
+
*
|
|
98
|
+
* const { className, style } = dcx(px(dynamic(spacing)))
|
|
99
|
+
* // CSS: padding-left: var(--twc-d0); padding-right: var(--twc-d0);
|
|
100
|
+
* // style: { '--twc-d0': spacing }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export function px(value: number | string | DynamicValue): StyleRule {
|
|
104
|
+
return spacingRuleMulti(['padding-left', 'padding-right'], value)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Sets vertical padding (top and bottom).
|
|
109
|
+
*
|
|
110
|
+
* Accepts a theme spacing scale number, a raw CSS string,
|
|
111
|
+
* or a {@link DynamicValue} for runtime values.
|
|
112
|
+
*
|
|
113
|
+
* @param value - Spacing scale number (`4` -> `1rem`), raw string (`'20px'`), or `dynamic()` value.
|
|
114
|
+
* @returns A {@link StyleRule} that sets `padding-top` and `padding-bottom`.
|
|
115
|
+
*
|
|
116
|
+
* @example Theme scale
|
|
117
|
+
* ```ts
|
|
118
|
+
* import { cx, py } from 'typewritingclass'
|
|
119
|
+
*
|
|
120
|
+
* cx(py(2))
|
|
121
|
+
* // CSS: padding-top: 0.5rem; padding-bottom: 0.5rem;
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @example Raw value
|
|
125
|
+
* ```ts
|
|
126
|
+
* cx(py('1em'))
|
|
127
|
+
* // CSS: padding-top: 1em; padding-bottom: 1em;
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @example Dynamic value
|
|
131
|
+
* ```ts
|
|
132
|
+
* import { dcx, py, dynamic } from 'typewritingclass'
|
|
133
|
+
*
|
|
134
|
+
* const { className, style } = dcx(py(dynamic(spacing)))
|
|
135
|
+
* // CSS: padding-top: var(--twc-d0); padding-bottom: var(--twc-d0);
|
|
136
|
+
* // style: { '--twc-d0': spacing }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export function py(value: number | string | DynamicValue): StyleRule {
|
|
140
|
+
return spacingRuleMulti(['padding-top', 'padding-bottom'], value)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Sets top padding.
|
|
145
|
+
*
|
|
146
|
+
* Accepts a theme spacing scale number, a raw CSS string,
|
|
147
|
+
* or a {@link DynamicValue} for runtime values.
|
|
148
|
+
*
|
|
149
|
+
* @param value - Spacing scale number (`4` -> `1rem`), raw string (`'8px'`), or `dynamic()` value.
|
|
150
|
+
* @returns A {@link StyleRule} that sets `padding-top`.
|
|
151
|
+
*
|
|
152
|
+
* @example Theme scale
|
|
153
|
+
* ```ts
|
|
154
|
+
* import { cx, pt } from 'typewritingclass'
|
|
155
|
+
*
|
|
156
|
+
* cx(pt(8))
|
|
157
|
+
* // CSS: padding-top: 2rem;
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* @example Raw value
|
|
161
|
+
* ```ts
|
|
162
|
+
* cx(pt('0.5em'))
|
|
163
|
+
* // CSS: padding-top: 0.5em;
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @example Dynamic value
|
|
167
|
+
* ```ts
|
|
168
|
+
* import { dcx, pt, dynamic } from 'typewritingclass'
|
|
169
|
+
*
|
|
170
|
+
* const { className, style } = dcx(pt(dynamic(spacing)))
|
|
171
|
+
* // CSS: padding-top: var(--twc-d0);
|
|
172
|
+
* // style: { '--twc-d0': spacing }
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
export function pt(value: number | string | DynamicValue): StyleRule {
|
|
176
|
+
return spacingRule('padding-top', value)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Sets right padding.
|
|
181
|
+
*
|
|
182
|
+
* Accepts a theme spacing scale number, a raw CSS string,
|
|
183
|
+
* or a {@link DynamicValue} for runtime values.
|
|
184
|
+
*
|
|
185
|
+
* @param value - Spacing scale number (`4` -> `1rem`), raw string (`'12px'`), or `dynamic()` value.
|
|
186
|
+
* @returns A {@link StyleRule} that sets `padding-right`.
|
|
187
|
+
*
|
|
188
|
+
* @example Theme scale
|
|
189
|
+
* ```ts
|
|
190
|
+
* import { cx, pr } from 'typewritingclass'
|
|
191
|
+
*
|
|
192
|
+
* cx(pr(3))
|
|
193
|
+
* // CSS: padding-right: 0.75rem;
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* @example Raw value
|
|
197
|
+
* ```ts
|
|
198
|
+
* cx(pr('1rem'))
|
|
199
|
+
* // CSS: padding-right: 1rem;
|
|
200
|
+
* ```
|
|
201
|
+
*
|
|
202
|
+
* @example Dynamic value
|
|
203
|
+
* ```ts
|
|
204
|
+
* import { dcx, pr, dynamic } from 'typewritingclass'
|
|
205
|
+
*
|
|
206
|
+
* const { className, style } = dcx(pr(dynamic(spacing)))
|
|
207
|
+
* // CSS: padding-right: var(--twc-d0);
|
|
208
|
+
* // style: { '--twc-d0': spacing }
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
export function pr(value: number | string | DynamicValue): StyleRule {
|
|
212
|
+
return spacingRule('padding-right', value)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Sets bottom padding.
|
|
217
|
+
*
|
|
218
|
+
* Accepts a theme spacing scale number, a raw CSS string,
|
|
219
|
+
* or a {@link DynamicValue} for runtime values.
|
|
220
|
+
*
|
|
221
|
+
* @param value - Spacing scale number (`4` -> `1rem`), raw string (`'16px'`), or `dynamic()` value.
|
|
222
|
+
* @returns A {@link StyleRule} that sets `padding-bottom`.
|
|
223
|
+
*
|
|
224
|
+
* @example Theme scale
|
|
225
|
+
* ```ts
|
|
226
|
+
* import { cx, pb } from 'typewritingclass'
|
|
227
|
+
*
|
|
228
|
+
* cx(pb(10))
|
|
229
|
+
* // CSS: padding-bottom: 2.5rem;
|
|
230
|
+
* ```
|
|
231
|
+
*
|
|
232
|
+
* @example Raw value
|
|
233
|
+
* ```ts
|
|
234
|
+
* cx(pb('2em'))
|
|
235
|
+
* // CSS: padding-bottom: 2em;
|
|
236
|
+
* ```
|
|
237
|
+
*
|
|
238
|
+
* @example Dynamic value
|
|
239
|
+
* ```ts
|
|
240
|
+
* import { dcx, pb, dynamic } from 'typewritingclass'
|
|
241
|
+
*
|
|
242
|
+
* const { className, style } = dcx(pb(dynamic(spacing)))
|
|
243
|
+
* // CSS: padding-bottom: var(--twc-d0);
|
|
244
|
+
* // style: { '--twc-d0': spacing }
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
export function pb(value: number | string | DynamicValue): StyleRule {
|
|
248
|
+
return spacingRule('padding-bottom', value)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Sets left padding.
|
|
253
|
+
*
|
|
254
|
+
* Accepts a theme spacing scale number, a raw CSS string,
|
|
255
|
+
* or a {@link DynamicValue} for runtime values.
|
|
256
|
+
*
|
|
257
|
+
* @param value - Spacing scale number (`4` -> `1rem`), raw string (`'24px'`), or `dynamic()` value.
|
|
258
|
+
* @returns A {@link StyleRule} that sets `padding-left`.
|
|
259
|
+
*
|
|
260
|
+
* @example Theme scale
|
|
261
|
+
* ```ts
|
|
262
|
+
* import { cx, pl } from 'typewritingclass'
|
|
263
|
+
*
|
|
264
|
+
* cx(pl(5))
|
|
265
|
+
* // CSS: padding-left: 1.25rem;
|
|
266
|
+
* ```
|
|
267
|
+
*
|
|
268
|
+
* @example Raw value
|
|
269
|
+
* ```ts
|
|
270
|
+
* cx(pl('3ch'))
|
|
271
|
+
* // CSS: padding-left: 3ch;
|
|
272
|
+
* ```
|
|
273
|
+
*
|
|
274
|
+
* @example Dynamic value
|
|
275
|
+
* ```ts
|
|
276
|
+
* import { dcx, pl, dynamic } from 'typewritingclass'
|
|
277
|
+
*
|
|
278
|
+
* const { className, style } = dcx(pl(dynamic(spacing)))
|
|
279
|
+
* // CSS: padding-left: var(--twc-d0);
|
|
280
|
+
* // style: { '--twc-d0': spacing }
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
export function pl(value: number | string | DynamicValue): StyleRule {
|
|
284
|
+
return spacingRule('padding-left', value)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Sets margin on all sides.
|
|
289
|
+
*
|
|
290
|
+
* Accepts a theme spacing scale number, a raw CSS string,
|
|
291
|
+
* or a {@link DynamicValue} for runtime values.
|
|
292
|
+
*
|
|
293
|
+
* @param value - Spacing scale number (`4` -> `1rem`), raw string (`'auto'`), or `dynamic()` value.
|
|
294
|
+
* @returns A {@link StyleRule} that sets `margin`.
|
|
295
|
+
*
|
|
296
|
+
* @example Theme scale
|
|
297
|
+
* ```ts
|
|
298
|
+
* import { cx, m } from 'typewritingclass'
|
|
299
|
+
*
|
|
300
|
+
* cx(m(4))
|
|
301
|
+
* // CSS: margin: 1rem;
|
|
302
|
+
* ```
|
|
303
|
+
*
|
|
304
|
+
* @example Raw value
|
|
305
|
+
* ```ts
|
|
306
|
+
* cx(m('auto'))
|
|
307
|
+
* // CSS: margin: auto;
|
|
308
|
+
* ```
|
|
309
|
+
*
|
|
310
|
+
* @example Dynamic value
|
|
311
|
+
* ```ts
|
|
312
|
+
* import { dcx, m, dynamic } from 'typewritingclass'
|
|
313
|
+
*
|
|
314
|
+
* const { className, style } = dcx(m(dynamic(spacing)))
|
|
315
|
+
* // CSS: margin: var(--twc-d0);
|
|
316
|
+
* // style: { '--twc-d0': spacing }
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
export function m(value: number | string | DynamicValue): StyleRule {
|
|
320
|
+
return spacingRule('margin', value)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Sets horizontal margin (left and right).
|
|
325
|
+
*
|
|
326
|
+
* Accepts a theme spacing scale number, a raw CSS string,
|
|
327
|
+
* or a {@link DynamicValue} for runtime values.
|
|
328
|
+
*
|
|
329
|
+
* @param value - Spacing scale number (`4` -> `1rem`), raw string (`'auto'`), or `dynamic()` value.
|
|
330
|
+
* @returns A {@link StyleRule} that sets `margin-left` and `margin-right`.
|
|
331
|
+
*
|
|
332
|
+
* @example Theme scale
|
|
333
|
+
* ```ts
|
|
334
|
+
* import { cx, mx } from 'typewritingclass'
|
|
335
|
+
*
|
|
336
|
+
* cx(mx(8))
|
|
337
|
+
* // CSS: margin-left: 2rem; margin-right: 2rem;
|
|
338
|
+
* ```
|
|
339
|
+
*
|
|
340
|
+
* @example Raw value
|
|
341
|
+
* ```ts
|
|
342
|
+
* cx(mx('auto'))
|
|
343
|
+
* // CSS: margin-left: auto; margin-right: auto;
|
|
344
|
+
* ```
|
|
345
|
+
*
|
|
346
|
+
* @example Dynamic value
|
|
347
|
+
* ```ts
|
|
348
|
+
* import { dcx, mx, dynamic } from 'typewritingclass'
|
|
349
|
+
*
|
|
350
|
+
* const { className, style } = dcx(mx(dynamic(spacing)))
|
|
351
|
+
* // CSS: margin-left: var(--twc-d0); margin-right: var(--twc-d0);
|
|
352
|
+
* // style: { '--twc-d0': spacing }
|
|
353
|
+
* ```
|
|
354
|
+
*/
|
|
355
|
+
export function mx(value: number | string | DynamicValue): StyleRule {
|
|
356
|
+
return spacingRuleMulti(['margin-left', 'margin-right'], value)
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Sets vertical margin (top and bottom).
|
|
361
|
+
*
|
|
362
|
+
* Accepts a theme spacing scale number, a raw CSS string,
|
|
363
|
+
* or a {@link DynamicValue} for runtime values.
|
|
364
|
+
*
|
|
365
|
+
* @param value - Spacing scale number (`4` -> `1rem`), raw string (`'2em'`), or `dynamic()` value.
|
|
366
|
+
* @returns A {@link StyleRule} that sets `margin-top` and `margin-bottom`.
|
|
367
|
+
*
|
|
368
|
+
* @example Theme scale
|
|
369
|
+
* ```ts
|
|
370
|
+
* import { cx, my } from 'typewritingclass'
|
|
371
|
+
*
|
|
372
|
+
* cx(my(6))
|
|
373
|
+
* // CSS: margin-top: 1.5rem; margin-bottom: 1.5rem;
|
|
374
|
+
* ```
|
|
375
|
+
*
|
|
376
|
+
* @example Raw value
|
|
377
|
+
* ```ts
|
|
378
|
+
* cx(my('0.5em'))
|
|
379
|
+
* // CSS: margin-top: 0.5em; margin-bottom: 0.5em;
|
|
380
|
+
* ```
|
|
381
|
+
*
|
|
382
|
+
* @example Dynamic value
|
|
383
|
+
* ```ts
|
|
384
|
+
* import { dcx, my, dynamic } from 'typewritingclass'
|
|
385
|
+
*
|
|
386
|
+
* const { className, style } = dcx(my(dynamic(spacing)))
|
|
387
|
+
* // CSS: margin-top: var(--twc-d0); margin-bottom: var(--twc-d0);
|
|
388
|
+
* // style: { '--twc-d0': spacing }
|
|
389
|
+
* ```
|
|
390
|
+
*/
|
|
391
|
+
export function my(value: number | string | DynamicValue): StyleRule {
|
|
392
|
+
return spacingRuleMulti(['margin-top', 'margin-bottom'], value)
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Sets top margin.
|
|
397
|
+
*
|
|
398
|
+
* Accepts a theme spacing scale number, a raw CSS string,
|
|
399
|
+
* or a {@link DynamicValue} for runtime values.
|
|
400
|
+
*
|
|
401
|
+
* @param value - Spacing scale number (`4` -> `1rem`), raw string (`'1em'`), or `dynamic()` value.
|
|
402
|
+
* @returns A {@link StyleRule} that sets `margin-top`.
|
|
403
|
+
*
|
|
404
|
+
* @example Theme scale
|
|
405
|
+
* ```ts
|
|
406
|
+
* import { cx, mt } from 'typewritingclass'
|
|
407
|
+
*
|
|
408
|
+
* cx(mt(2))
|
|
409
|
+
* // CSS: margin-top: 0.5rem;
|
|
410
|
+
* ```
|
|
411
|
+
*
|
|
412
|
+
* @example Raw value
|
|
413
|
+
* ```ts
|
|
414
|
+
* cx(mt('10px'))
|
|
415
|
+
* // CSS: margin-top: 10px;
|
|
416
|
+
* ```
|
|
417
|
+
*
|
|
418
|
+
* @example Dynamic value
|
|
419
|
+
* ```ts
|
|
420
|
+
* import { dcx, mt, dynamic } from 'typewritingclass'
|
|
421
|
+
*
|
|
422
|
+
* const { className, style } = dcx(mt(dynamic(spacing)))
|
|
423
|
+
* // CSS: margin-top: var(--twc-d0);
|
|
424
|
+
* // style: { '--twc-d0': spacing }
|
|
425
|
+
* ```
|
|
426
|
+
*/
|
|
427
|
+
export function mt(value: number | string | DynamicValue): StyleRule {
|
|
428
|
+
return spacingRule('margin-top', value)
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Sets right margin.
|
|
433
|
+
*
|
|
434
|
+
* Accepts a theme spacing scale number, a raw CSS string,
|
|
435
|
+
* or a {@link DynamicValue} for runtime values.
|
|
436
|
+
*
|
|
437
|
+
* @param value - Spacing scale number (`4` -> `1rem`), raw string (`'1em'`), or `dynamic()` value.
|
|
438
|
+
* @returns A {@link StyleRule} that sets `margin-right`.
|
|
439
|
+
*
|
|
440
|
+
* @example Theme scale
|
|
441
|
+
* ```ts
|
|
442
|
+
* import { cx, mr } from 'typewritingclass'
|
|
443
|
+
*
|
|
444
|
+
* cx(mr(3))
|
|
445
|
+
* // CSS: margin-right: 0.75rem;
|
|
446
|
+
* ```
|
|
447
|
+
*
|
|
448
|
+
* @example Raw value
|
|
449
|
+
* ```ts
|
|
450
|
+
* cx(mr('auto'))
|
|
451
|
+
* // CSS: margin-right: auto;
|
|
452
|
+
* ```
|
|
453
|
+
*
|
|
454
|
+
* @example Dynamic value
|
|
455
|
+
* ```ts
|
|
456
|
+
* import { dcx, mr, dynamic } from 'typewritingclass'
|
|
457
|
+
*
|
|
458
|
+
* const { className, style } = dcx(mr(dynamic(spacing)))
|
|
459
|
+
* // CSS: margin-right: var(--twc-d0);
|
|
460
|
+
* // style: { '--twc-d0': spacing }
|
|
461
|
+
* ```
|
|
462
|
+
*/
|
|
463
|
+
export function mr(value: number | string | DynamicValue): StyleRule {
|
|
464
|
+
return spacingRule('margin-right', value)
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Sets bottom margin.
|
|
469
|
+
*
|
|
470
|
+
* Accepts a theme spacing scale number, a raw CSS string,
|
|
471
|
+
* or a {@link DynamicValue} for runtime values.
|
|
472
|
+
*
|
|
473
|
+
* @param value - Spacing scale number (`4` -> `1rem`), raw string (`'2em'`), or `dynamic()` value.
|
|
474
|
+
* @returns A {@link StyleRule} that sets `margin-bottom`.
|
|
475
|
+
*
|
|
476
|
+
* @example Theme scale
|
|
477
|
+
* ```ts
|
|
478
|
+
* import { cx, mb } from 'typewritingclass'
|
|
479
|
+
*
|
|
480
|
+
* cx(mb(4))
|
|
481
|
+
* // CSS: margin-bottom: 1rem;
|
|
482
|
+
* ```
|
|
483
|
+
*
|
|
484
|
+
* @example Raw value
|
|
485
|
+
* ```ts
|
|
486
|
+
* cx(mb('20px'))
|
|
487
|
+
* // CSS: margin-bottom: 20px;
|
|
488
|
+
* ```
|
|
489
|
+
*
|
|
490
|
+
* @example Dynamic value
|
|
491
|
+
* ```ts
|
|
492
|
+
* import { dcx, mb, dynamic } from 'typewritingclass'
|
|
493
|
+
*
|
|
494
|
+
* const { className, style } = dcx(mb(dynamic(spacing)))
|
|
495
|
+
* // CSS: margin-bottom: var(--twc-d0);
|
|
496
|
+
* // style: { '--twc-d0': spacing }
|
|
497
|
+
* ```
|
|
498
|
+
*/
|
|
499
|
+
export function mb(value: number | string | DynamicValue): StyleRule {
|
|
500
|
+
return spacingRule('margin-bottom', value)
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Sets left margin.
|
|
505
|
+
*
|
|
506
|
+
* Accepts a theme spacing scale number, a raw CSS string,
|
|
507
|
+
* or a {@link DynamicValue} for runtime values.
|
|
508
|
+
*
|
|
509
|
+
* @param value - Spacing scale number (`4` -> `1rem`), raw string (`'auto'`), or `dynamic()` value.
|
|
510
|
+
* @returns A {@link StyleRule} that sets `margin-left`.
|
|
511
|
+
*
|
|
512
|
+
* @example Theme scale
|
|
513
|
+
* ```ts
|
|
514
|
+
* import { cx, ml } from 'typewritingclass'
|
|
515
|
+
*
|
|
516
|
+
* cx(ml(12))
|
|
517
|
+
* // CSS: margin-left: 3rem;
|
|
518
|
+
* ```
|
|
519
|
+
*
|
|
520
|
+
* @example Raw value
|
|
521
|
+
* ```ts
|
|
522
|
+
* cx(ml('auto'))
|
|
523
|
+
* // CSS: margin-left: auto;
|
|
524
|
+
* ```
|
|
525
|
+
*
|
|
526
|
+
* @example Dynamic value
|
|
527
|
+
* ```ts
|
|
528
|
+
* import { dcx, ml, dynamic } from 'typewritingclass'
|
|
529
|
+
*
|
|
530
|
+
* const { className, style } = dcx(ml(dynamic(spacing)))
|
|
531
|
+
* // CSS: margin-left: var(--twc-d0);
|
|
532
|
+
* // style: { '--twc-d0': spacing }
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
export function ml(value: number | string | DynamicValue): StyleRule {
|
|
536
|
+
return spacingRule('margin-left', value)
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Sets gap between flex or grid children on both axes.
|
|
541
|
+
*
|
|
542
|
+
* Accepts a theme spacing scale number, a raw CSS string,
|
|
543
|
+
* or a {@link DynamicValue} for runtime values.
|
|
544
|
+
*
|
|
545
|
+
* @param value - Spacing scale number (`4` -> `1rem`), raw string (`'20px'`), or `dynamic()` value.
|
|
546
|
+
* @returns A {@link StyleRule} that sets `gap`.
|
|
547
|
+
*
|
|
548
|
+
* @example Theme scale
|
|
549
|
+
* ```ts
|
|
550
|
+
* import { cx, gap } from 'typewritingclass'
|
|
551
|
+
*
|
|
552
|
+
* cx(gap(4))
|
|
553
|
+
* // CSS: gap: 1rem;
|
|
554
|
+
* ```
|
|
555
|
+
*
|
|
556
|
+
* @example Raw value
|
|
557
|
+
* ```ts
|
|
558
|
+
* cx(gap('1.5em'))
|
|
559
|
+
* // CSS: gap: 1.5em;
|
|
560
|
+
* ```
|
|
561
|
+
*
|
|
562
|
+
* @example Dynamic value
|
|
563
|
+
* ```ts
|
|
564
|
+
* import { dcx, gap, dynamic } from 'typewritingclass'
|
|
565
|
+
*
|
|
566
|
+
* const { className, style } = dcx(gap(dynamic(spacing)))
|
|
567
|
+
* // CSS: gap: var(--twc-d0);
|
|
568
|
+
* // style: { '--twc-d0': spacing }
|
|
569
|
+
* ```
|
|
570
|
+
*/
|
|
571
|
+
export function gap(value: number | string | DynamicValue): StyleRule {
|
|
572
|
+
return spacingRule('gap', value)
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Sets horizontal (column) gap between flex or grid children.
|
|
577
|
+
*
|
|
578
|
+
* Accepts a theme spacing scale number, a raw CSS string,
|
|
579
|
+
* or a {@link DynamicValue} for runtime values.
|
|
580
|
+
*
|
|
581
|
+
* @param value - Spacing scale number (`4` -> `1rem`), raw string (`'10px'`), or `dynamic()` value.
|
|
582
|
+
* @returns A {@link StyleRule} that sets `column-gap`.
|
|
583
|
+
*
|
|
584
|
+
* @example Theme scale
|
|
585
|
+
* ```ts
|
|
586
|
+
* import { cx, gapX } from 'typewritingclass'
|
|
587
|
+
*
|
|
588
|
+
* cx(gapX(2))
|
|
589
|
+
* // CSS: column-gap: 0.5rem;
|
|
590
|
+
* ```
|
|
591
|
+
*
|
|
592
|
+
* @example Raw value
|
|
593
|
+
* ```ts
|
|
594
|
+
* cx(gapX('12px'))
|
|
595
|
+
* // CSS: column-gap: 12px;
|
|
596
|
+
* ```
|
|
597
|
+
*
|
|
598
|
+
* @example Dynamic value
|
|
599
|
+
* ```ts
|
|
600
|
+
* import { dcx, gapX, dynamic } from 'typewritingclass'
|
|
601
|
+
*
|
|
602
|
+
* const { className, style } = dcx(gapX(dynamic(spacing)))
|
|
603
|
+
* // CSS: column-gap: var(--twc-d0);
|
|
604
|
+
* // style: { '--twc-d0': spacing }
|
|
605
|
+
* ```
|
|
606
|
+
*/
|
|
607
|
+
export function gapX(value: number | string | DynamicValue): StyleRule {
|
|
608
|
+
return spacingRule('column-gap', value)
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Sets vertical (row) gap between flex or grid children.
|
|
613
|
+
*
|
|
614
|
+
* Accepts a theme spacing scale number, a raw CSS string,
|
|
615
|
+
* or a {@link DynamicValue} for runtime values.
|
|
616
|
+
*
|
|
617
|
+
* @param value - Spacing scale number (`4` -> `1rem`), raw string (`'10px'`), or `dynamic()` value.
|
|
618
|
+
* @returns A {@link StyleRule} that sets `row-gap`.
|
|
619
|
+
*
|
|
620
|
+
* @example Theme scale
|
|
621
|
+
* ```ts
|
|
622
|
+
* import { cx, gapY } from 'typewritingclass'
|
|
623
|
+
*
|
|
624
|
+
* cx(gapY(3))
|
|
625
|
+
* // CSS: row-gap: 0.75rem;
|
|
626
|
+
* ```
|
|
627
|
+
*
|
|
628
|
+
* @example Raw value
|
|
629
|
+
* ```ts
|
|
630
|
+
* cx(gapY('8px'))
|
|
631
|
+
* // CSS: row-gap: 8px;
|
|
632
|
+
* ```
|
|
633
|
+
*
|
|
634
|
+
* @example Dynamic value
|
|
635
|
+
* ```ts
|
|
636
|
+
* import { dcx, gapY, dynamic } from 'typewritingclass'
|
|
637
|
+
*
|
|
638
|
+
* const { className, style } = dcx(gapY(dynamic(spacing)))
|
|
639
|
+
* // CSS: row-gap: var(--twc-d0);
|
|
640
|
+
* // style: { '--twc-d0': spacing }
|
|
641
|
+
* ```
|
|
642
|
+
*/
|
|
643
|
+
export function gapY(value: number | string | DynamicValue): StyleRule {
|
|
644
|
+
return spacingRule('row-gap', value)
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
export function ps(value: number | string | DynamicValue): StyleRule {
|
|
648
|
+
return spacingRule('padding-inline-start', value)
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
export function pe(value: number | string | DynamicValue): StyleRule {
|
|
652
|
+
return spacingRule('padding-inline-end', value)
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
export function ms(value: number | string | DynamicValue): StyleRule {
|
|
656
|
+
return spacingRule('margin-inline-start', value)
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
export function me(value: number | string | DynamicValue): StyleRule {
|
|
660
|
+
return spacingRule('margin-inline-end', value)
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
export function spaceX(value: number | string | DynamicValue): StyleRule {
|
|
664
|
+
const rule = spacingRule('margin-left', value)
|
|
665
|
+
return wrapWithSelectorTemplate(rule, '& > :not([hidden]) ~ :not([hidden])')
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
export function spaceY(value: number | string | DynamicValue): StyleRule {
|
|
669
|
+
const rule = spacingRule('margin-top', value)
|
|
670
|
+
return wrapWithSelectorTemplate(rule, '& > :not([hidden]) ~ :not([hidden])')
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
export function spaceXReverse(): StyleRule {
|
|
674
|
+
const rule = createRule({ '--twc-space-x-reverse': '1' })
|
|
675
|
+
return wrapWithSelectorTemplate(rule, '& > :not([hidden]) ~ :not([hidden])')
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
export function spaceYReverse(): StyleRule {
|
|
679
|
+
const rule = createRule({ '--twc-space-y-reverse': '1' })
|
|
680
|
+
return wrapWithSelectorTemplate(rule, '& > :not([hidden]) ~ :not([hidden])')
|
|
681
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { StyleRule } from '../types.ts'
|
|
2
|
+
import type { DynamicValue } from '../dynamic.ts'
|
|
3
|
+
import { createRule, createDynamicRule } from '../rule.ts'
|
|
4
|
+
import { isDynamic } from '../dynamic.ts'
|
|
5
|
+
|
|
6
|
+
export function fill(value: string | DynamicValue): StyleRule {
|
|
7
|
+
if (isDynamic(value)) {
|
|
8
|
+
return createDynamicRule(
|
|
9
|
+
{ fill: `var(${value.__id})` },
|
|
10
|
+
{ [value.__id]: String(value.__value) },
|
|
11
|
+
)
|
|
12
|
+
}
|
|
13
|
+
return createRule({ fill: value })
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function stroke(value: string | DynamicValue): StyleRule {
|
|
17
|
+
if (isDynamic(value)) {
|
|
18
|
+
return createDynamicRule(
|
|
19
|
+
{ stroke: `var(${value.__id})` },
|
|
20
|
+
{ [value.__id]: String(value.__value) },
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
return createRule({ stroke: value })
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function strokeWidth(value: string | number | DynamicValue): StyleRule {
|
|
27
|
+
if (isDynamic(value)) {
|
|
28
|
+
return createDynamicRule(
|
|
29
|
+
{ 'stroke-width': `var(${value.__id})` },
|
|
30
|
+
{ [value.__id]: String(value.__value) },
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
return createRule({ 'stroke-width': String(value) })
|
|
34
|
+
}
|