typewritingclass 0.2.0 → 0.2.2

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.
@@ -2,6 +2,7 @@ import type { StyleRule } from '../types.ts'
2
2
  import type { DynamicValue } from '../dynamic.ts'
3
3
  import { createRule, createDynamicRule } from '../rule.ts'
4
4
  import { isDynamic } from '../dynamic.ts'
5
+ import { resolveColor } from './colors.ts'
5
6
 
6
7
  export function fill(value: string | DynamicValue): StyleRule {
7
8
  if (isDynamic(value)) {
@@ -10,7 +11,7 @@ export function fill(value: string | DynamicValue): StyleRule {
10
11
  { [value.__id]: String(value.__value) },
11
12
  )
12
13
  }
13
- return createRule({ fill: value })
14
+ return createRule({ fill: resolveColor(value) })
14
15
  }
15
16
 
16
17
  export function stroke(value: string | DynamicValue): StyleRule {
@@ -20,7 +21,7 @@ export function stroke(value: string | DynamicValue): StyleRule {
20
21
  { [value.__id]: String(value.__value) },
21
22
  )
22
23
  }
23
- return createRule({ stroke: value })
24
+ return createRule({ stroke: resolveColor(value) })
24
25
  }
25
26
 
26
27
  export function strokeWidth(value: string | number | DynamicValue): StyleRule {
@@ -2,6 +2,7 @@ import type { StyleRule } from '../types.ts'
2
2
  import type { DynamicValue } from '../dynamic.ts'
3
3
  import { createRule, createDynamicRule } from '../rule.ts'
4
4
  import { isDynamic } from '../dynamic.ts'
5
+ import { resolveSpacing } from '../theme/spacing.ts'
5
6
 
6
7
  function transformRule(fn: string, value: string | number | DynamicValue): StyleRule {
7
8
  if (isDynamic(value)) {
@@ -50,11 +51,13 @@ export function rotate(value: string | DynamicValue): StyleRule {
50
51
  return transformRule('rotate', value)
51
52
  }
52
53
 
53
- export function translateX(value: string | DynamicValue): StyleRule {
54
+ export function translateX(value: string | number | DynamicValue): StyleRule {
55
+ if (typeof value === 'number') return transformRule('translateX', resolveSpacing(value))
54
56
  return transformRule('translateX', value)
55
57
  }
56
58
 
57
- export function translateY(value: string | DynamicValue): StyleRule {
59
+ export function translateY(value: string | number | DynamicValue): StyleRule {
60
+ if (typeof value === 'number') return transformRule('translateY', resolveSpacing(value))
58
61
  return transformRule('translateY', value)
59
62
  }
60
63
 
@@ -2,6 +2,15 @@ import type { StyleRule } from '../types.ts'
2
2
  import type { DynamicValue } from '../dynamic.ts'
3
3
  import { createRule, createDynamicRule } from '../rule.ts'
4
4
  import { isDynamic } from '../dynamic.ts'
5
+ import * as animations from '../theme/animations.ts'
6
+
7
+ const animateMap: Record<string, string> = {
8
+ spin: animations.spin,
9
+ ping: animations.ping,
10
+ pulse: animations.pulse,
11
+ bounce: animations.bounce,
12
+ none: 'none',
13
+ }
5
14
 
6
15
  export function transition(): StyleRule {
7
16
  return createRule({
@@ -94,5 +103,5 @@ export function animate(value: string | DynamicValue): StyleRule {
94
103
  { [value.__id]: String(value.__value) },
95
104
  )
96
105
  }
97
- return createRule({ animation: value })
106
+ return createRule({ animation: animateMap[value] ?? value })
98
107
  }
@@ -3,6 +3,12 @@ import type { TextSize } from '../theme/typography.ts'
3
3
  import type { DynamicValue } from '../dynamic.ts'
4
4
  import { createRule, createDynamicRule } from '../rule.ts'
5
5
  import { isDynamic } from '../dynamic.ts'
6
+ import { resolveColor } from './colors.ts'
7
+ import { letterSpacings, lineHeights, fontFamilies } from '../theme/typography.ts'
8
+
9
+ const trackingMap: Record<string, string> = { ...letterSpacings }
10
+ const leadingMap: Record<string, string> = { ...lineHeights }
11
+ const fontFamilyMap: Record<string, string> = { ...fontFamilies }
6
12
 
7
13
  /**
8
14
  * Sets the font size (and optionally line height) of an element.
@@ -132,7 +138,7 @@ export function tracking(value: string | DynamicValue): StyleRule {
132
138
  { [value.__id]: String(value.__value) },
133
139
  )
134
140
  }
135
- return createRule({ 'letter-spacing': value })
141
+ return createRule({ 'letter-spacing': trackingMap[value] ?? value })
136
142
  }
137
143
 
138
144
  /**
@@ -166,14 +172,15 @@ export function tracking(value: string | DynamicValue): StyleRule {
166
172
  * // style: { '--twc-d0': lineHeight }
167
173
  * ```
168
174
  */
169
- export function leading(value: string | DynamicValue): StyleRule {
175
+ export function leading(value: string | number | DynamicValue): StyleRule {
170
176
  if (isDynamic(value)) {
171
177
  return createDynamicRule(
172
178
  { 'line-height': `var(${value.__id})` },
173
179
  { [value.__id]: String(value.__value) },
174
180
  )
175
181
  }
176
- return createRule({ 'line-height': value })
182
+ const v = typeof value === 'string' ? (leadingMap[value] ?? value) : String(value)
183
+ return createRule({ 'line-height': v })
177
184
  }
178
185
 
179
186
  /**
@@ -209,7 +216,7 @@ export function fontFamily(value: string | DynamicValue): StyleRule {
209
216
  { [value.__id]: String(value.__value) },
210
217
  )
211
218
  }
212
- return createRule({ 'font-family': value })
219
+ return createRule({ 'font-family': fontFamilyMap[value] ?? value })
213
220
  }
214
221
 
215
222
  export function antialiased(): StyleRule {
@@ -302,7 +309,7 @@ export function textDecorationColor(value: string | DynamicValue): StyleRule {
302
309
  { [value.__id]: String(value.__value) },
303
310
  )
304
311
  }
305
- return createRule({ 'text-decoration-color': value })
312
+ return createRule({ 'text-decoration-color': resolveColor(value) })
306
313
  }
307
314
 
308
315
  export function textDecorationStyle(value: string): StyleRule {