nitrowind 0.0.0-stage → 0.1.1
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/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/README.md +51 -2
- package/css.d.ts +6 -0
- package/dist/color.d.ts +24 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +158 -0
- package/dist/color.js.map +1 -0
- package/dist/core.d.ts +121 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +1026 -0
- package/dist/core.js.map +1 -0
- package/dist/css/compile.d.ts +18 -0
- package/dist/css/compile.d.ts.map +1 -0
- package/dist/css/compile.js +1018 -0
- package/dist/css/compile.js.map +1 -0
- package/dist/css/declarations.d.ts +18 -0
- package/dist/css/declarations.d.ts.map +1 -0
- package/dist/css/declarations.js +1173 -0
- package/dist/css/declarations.js.map +1 -0
- package/dist/css/index.d.ts +7 -0
- package/dist/css/index.d.ts.map +1 -0
- package/dist/css/index.js +7 -0
- package/dist/css/index.js.map +1 -0
- package/dist/css/parser.d.ts +9 -0
- package/dist/css/parser.d.ts.map +1 -0
- package/dist/css/parser.js +188 -0
- package/dist/css/parser.js.map +1 -0
- package/dist/css/tokenizer.d.ts +14 -0
- package/dist/css/tokenizer.d.ts.map +1 -0
- package/dist/css/tokenizer.js +200 -0
- package/dist/css/tokenizer.js.map +1 -0
- package/dist/css/types.d.ts +128 -0
- package/dist/css/types.d.ts.map +1 -0
- package/dist/css/types.js +19 -0
- package/dist/css/types.js.map +1 -0
- package/dist/css/values.d.ts +37 -0
- package/dist/css/values.d.ts.map +1 -0
- package/dist/css/values.js +343 -0
- package/dist/css/values.js.map +1 -0
- package/dist/environment.d.ts +5 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/environment.js +99 -0
- package/dist/environment.js.map +1 -0
- package/dist/hooks.d.ts +22 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +140 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-dev-runtime.d.ts +17 -0
- package/dist/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/jsx-dev-runtime.js +12 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-namespace.d.ts +29 -0
- package/dist/jsx-namespace.d.ts.map +1 -0
- package/dist/jsx-namespace.js +2 -0
- package/dist/jsx-namespace.js.map +1 -0
- package/dist/jsx-runtime.d.ts +22 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +21 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/math.d.ts +50 -0
- package/dist/math.d.ts.map +1 -0
- package/dist/math.js +442 -0
- package/dist/math.js.map +1 -0
- package/dist/plugin.d.ts +45 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +172 -0
- package/dist/plugin.js.map +1 -0
- package/dist/props.d.ts +29 -0
- package/dist/props.d.ts.map +1 -0
- package/dist/props.js +163 -0
- package/dist/props.js.map +1 -0
- package/dist/scope.d.ts +99 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +228 -0
- package/dist/scope.js.map +1 -0
- package/dist/store.d.ts +18 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +244 -0
- package/dist/store.js.map +1 -0
- package/dist/tokens/index.d.ts +12 -0
- package/dist/tokens/index.d.ts.map +1 -0
- package/dist/tokens/index.js +237 -0
- package/dist/tokens/index.js.map +1 -0
- package/dist/tokens/tailwind.generated.d.ts +3 -0
- package/dist/tokens/tailwind.generated.d.ts.map +1 -0
- package/dist/tokens/tailwind.generated.js +610 -0
- package/dist/tokens/tailwind.generated.js.map +1 -0
- package/dist/tokens/types.d.ts +95 -0
- package/dist/tokens/types.d.ts.map +1 -0
- package/dist/tokens/types.js +2 -0
- package/dist/tokens/types.js.map +1 -0
- package/dist/transform.d.ts +22 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/transform.js +79 -0
- package/dist/transform.js.map +1 -0
- package/dist/transition.d.ts +7 -0
- package/dist/transition.d.ts.map +1 -0
- package/dist/transition.js +355 -0
- package/dist/transition.js.map +1 -0
- package/dist/types.d.ts +214 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utilities.d.ts +109 -0
- package/dist/utilities.d.ts.map +1 -0
- package/dist/utilities.js +2000 -0
- package/dist/utilities.js.map +1 -0
- package/dist/variables.d.ts +65 -0
- package/dist/variables.d.ts.map +1 -0
- package/dist/variables.js +408 -0
- package/dist/variables.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/dist/withNitroWind.d.ts +11 -0
- package/dist/withNitroWind.d.ts.map +1 -0
- package/dist/withNitroWind.js +27 -0
- package/dist/withNitroWind.js.map +1 -0
- package/package.json +89 -4
- package/src/color.ts +164 -0
- package/src/core.ts +1248 -0
- package/src/css/compile.ts +1198 -0
- package/src/css/declarations.ts +1141 -0
- package/src/css/index.ts +22 -0
- package/src/css/parser.ts +196 -0
- package/src/css/tokenizer.ts +227 -0
- package/src/css/types.ts +178 -0
- package/src/css/values.ts +330 -0
- package/src/environment.ts +112 -0
- package/src/hooks.ts +190 -0
- package/src/index.ts +61 -0
- package/src/jsx-dev-runtime.ts +43 -0
- package/src/jsx-namespace.ts +23 -0
- package/src/jsx-runtime.ts +39 -0
- package/src/math.ts +488 -0
- package/src/plugin.ts +230 -0
- package/src/props.ts +173 -0
- package/src/scope.ts +331 -0
- package/src/store.ts +288 -0
- package/src/tokens/index.ts +252 -0
- package/src/tokens/tailwind.generated.ts +613 -0
- package/src/tokens/types.ts +99 -0
- package/src/transform.ts +115 -0
- package/src/transition.ts +414 -0
- package/src/types.ts +248 -0
- package/src/utilities.ts +1992 -0
- package/src/variables.ts +509 -0
- package/src/version.ts +2 -0
- package/src/withNitroWind.ts +36 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { type PackedColor, parseColor } from '../color'
|
|
2
|
+
import { hasVarCall } from '../variables'
|
|
3
|
+
import { tailwindTokens } from './tailwind.generated'
|
|
4
|
+
import type {
|
|
5
|
+
BreakpointInput,
|
|
6
|
+
ColorInput,
|
|
7
|
+
ColorScaleInput,
|
|
8
|
+
TokenLineHeight,
|
|
9
|
+
Tokens,
|
|
10
|
+
TokensConfig,
|
|
11
|
+
TokensInput,
|
|
12
|
+
} from './types'
|
|
13
|
+
|
|
14
|
+
export * from './types'
|
|
15
|
+
export { tailwindTokens }
|
|
16
|
+
|
|
17
|
+
const ROOT_FONT_SIZE = 16
|
|
18
|
+
const BREAKPOINT_LENGTH_RE = /^(\d+(?:\.\d+)?|\.\d+)(rem|px|pt)?$/
|
|
19
|
+
|
|
20
|
+
/** Parses a breakpoint length (`rem`, `px`, `pt`, or points) into points, or `null` if invalid. */
|
|
21
|
+
export function parseBreakpointLength(value: number | string): number | null {
|
|
22
|
+
if (typeof value === 'number') {
|
|
23
|
+
return Number.isFinite(value) && value >= 0 ? value : null
|
|
24
|
+
}
|
|
25
|
+
const trimmed = value.trim()
|
|
26
|
+
const match = BREAKPOINT_LENGTH_RE.exec(trimmed)
|
|
27
|
+
if (!match) return null
|
|
28
|
+
const amount = Number(match[1])
|
|
29
|
+
if (!Number.isFinite(amount) || amount < 0) return null
|
|
30
|
+
return match[2] === 'rem' ? amount * ROOT_FONT_SIZE : amount
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function applyBreakpoints(
|
|
34
|
+
base: Record<string, number>,
|
|
35
|
+
input: Record<string, BreakpointInput>,
|
|
36
|
+
replace: boolean,
|
|
37
|
+
): Record<string, number> {
|
|
38
|
+
const next: Record<string, number> = replace ? {} : { ...base }
|
|
39
|
+
for (const [name, raw] of Object.entries(input)) {
|
|
40
|
+
if (raw === 'initial') {
|
|
41
|
+
delete next[name]
|
|
42
|
+
continue
|
|
43
|
+
}
|
|
44
|
+
const parsed = parseBreakpointLength(raw)
|
|
45
|
+
if (parsed === null) {
|
|
46
|
+
throw new Error(`[nitrowind] Invalid breakpoint "${String(raw)}" for "${name}".`)
|
|
47
|
+
}
|
|
48
|
+
next[name] = parsed
|
|
49
|
+
}
|
|
50
|
+
return next
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function toColor(value: ColorInput, name: string): PackedColor {
|
|
54
|
+
if (typeof value === 'number') return value >>> 0
|
|
55
|
+
const parsed = parseColor(value)
|
|
56
|
+
if (parsed === null) throw new Error(`[nitrowind] Invalid color "${value}" for token color "${name}".`)
|
|
57
|
+
return parsed
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function toColorToken(value: ColorInput, name: string): PackedColor | string {
|
|
61
|
+
if (typeof value === 'string' && hasVarCall(value)) return value.trim()
|
|
62
|
+
return toColor(value, name)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Flattens `{ brand: { 500: '#33f', DEFAULT: '#33f' } }` into `brand-500` and `brand`. */
|
|
66
|
+
function flattenColors(colors: Record<string, ColorScaleInput>): Record<string, PackedColor | string> {
|
|
67
|
+
const flat: Record<string, PackedColor | string> = {}
|
|
68
|
+
for (const [name, value] of Object.entries(colors)) {
|
|
69
|
+
if (typeof value === 'object') {
|
|
70
|
+
for (const [shade, shadeValue] of Object.entries(value)) {
|
|
71
|
+
const key = shade === 'DEFAULT' ? name : `${name}-${shade}`
|
|
72
|
+
flat[key] = toColorToken(shadeValue, key)
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
flat[name] = toColorToken(value, name)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return flat
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function normalizeVarOrNumber(
|
|
82
|
+
group: Record<string, number | string>,
|
|
83
|
+
groupName: string,
|
|
84
|
+
): Record<string, number | string> {
|
|
85
|
+
const out: Record<string, number | string> = {}
|
|
86
|
+
for (const [key, value] of Object.entries(group)) {
|
|
87
|
+
if (typeof value === 'string') {
|
|
88
|
+
if (!hasVarCall(value)) {
|
|
89
|
+
throw new Error(`[nitrowind] Invalid ${groupName} token "${value}" for "${key}".`)
|
|
90
|
+
}
|
|
91
|
+
out[key] = value.trim()
|
|
92
|
+
} else {
|
|
93
|
+
out[key] = value
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return out
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const PERCENT_RE = /^-?\d*\.?\d+%$/
|
|
100
|
+
|
|
101
|
+
function normalizeLeading(group: Record<string, TokenLineHeight>): Record<string, TokenLineHeight> {
|
|
102
|
+
const out: Record<string, TokenLineHeight> = {}
|
|
103
|
+
for (const [key, value] of Object.entries(group)) {
|
|
104
|
+
if (typeof value === 'string') {
|
|
105
|
+
if (!hasVarCall(value)) {
|
|
106
|
+
throw new Error(`[nitrowind] Invalid leading token "${value}" for "${key}".`)
|
|
107
|
+
}
|
|
108
|
+
out[key] = value.trim()
|
|
109
|
+
} else if (typeof value === 'number') {
|
|
110
|
+
out[key] = value
|
|
111
|
+
} else if (
|
|
112
|
+
typeof value === 'object' &&
|
|
113
|
+
value !== null &&
|
|
114
|
+
typeof value.points === 'number' &&
|
|
115
|
+
Number.isFinite(value.points)
|
|
116
|
+
) {
|
|
117
|
+
out[key] = { points: value.points }
|
|
118
|
+
} else {
|
|
119
|
+
throw new Error(`[nitrowind] Invalid leading token "${String(value)}" for "${key}".`)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return out
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function normalizeSpacingScale(group: Record<string, number | string>): Record<string, number | string> {
|
|
126
|
+
const out: Record<string, number | string> = {}
|
|
127
|
+
for (const [key, value] of Object.entries(group)) {
|
|
128
|
+
if (typeof value === 'string') {
|
|
129
|
+
const trimmed = value.trim()
|
|
130
|
+
if (!hasVarCall(trimmed) && !PERCENT_RE.test(trimmed)) {
|
|
131
|
+
throw new Error(`[nitrowind] Invalid spacingScale token "${value}" for "${key}".`)
|
|
132
|
+
}
|
|
133
|
+
out[key] = trimmed
|
|
134
|
+
} else {
|
|
135
|
+
out[key] = value
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return out
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function normalize(input: TokensInput): Partial<Tokens> {
|
|
142
|
+
const out: Partial<Tokens> = {}
|
|
143
|
+
if (input.spacing !== undefined) {
|
|
144
|
+
if (typeof input.spacing === 'string') {
|
|
145
|
+
if (!hasVarCall(input.spacing)) {
|
|
146
|
+
throw new Error(`[nitrowind] Invalid spacing token "${input.spacing}".`)
|
|
147
|
+
}
|
|
148
|
+
out.spacing = input.spacing.trim()
|
|
149
|
+
} else {
|
|
150
|
+
out.spacing = input.spacing
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (input.spacingScale) out.spacingScale = normalizeSpacingScale(input.spacingScale)
|
|
154
|
+
if (input.colors) out.colors = flattenColors(input.colors)
|
|
155
|
+
if (input.fontSize) {
|
|
156
|
+
out.fontSize = Object.fromEntries(
|
|
157
|
+
Object.entries(input.fontSize).map(([k, v]) => {
|
|
158
|
+
if (typeof v === 'string') {
|
|
159
|
+
if (!hasVarCall(v)) {
|
|
160
|
+
throw new Error(`[nitrowind] Invalid fontSize token "${v}" for "${k}".`)
|
|
161
|
+
}
|
|
162
|
+
return [k, v.trim()]
|
|
163
|
+
}
|
|
164
|
+
if (typeof v === 'number') return [k, { fontSize: v }]
|
|
165
|
+
const fontSize = typeof v.fontSize === 'string' ? v.fontSize.trim() : v.fontSize
|
|
166
|
+
if (typeof fontSize === 'string' && !hasVarCall(fontSize)) {
|
|
167
|
+
throw new Error(`[nitrowind] Invalid fontSize token "${v.fontSize}" for "${k}".`)
|
|
168
|
+
}
|
|
169
|
+
if (v.lineHeight !== undefined) {
|
|
170
|
+
const lineHeight = typeof v.lineHeight === 'string' ? v.lineHeight.trim() : v.lineHeight
|
|
171
|
+
if (typeof lineHeight === 'string' && !hasVarCall(lineHeight)) {
|
|
172
|
+
throw new Error(`[nitrowind] Invalid fontSize lineHeight "${v.lineHeight}" for "${k}".`)
|
|
173
|
+
}
|
|
174
|
+
return [k, { fontSize, lineHeight }]
|
|
175
|
+
}
|
|
176
|
+
return [k, { fontSize }]
|
|
177
|
+
}),
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
if (input.fontWeight) {
|
|
181
|
+
out.fontWeight = Object.fromEntries(
|
|
182
|
+
Object.entries(input.fontWeight).map(([k, v]) => [k, hasVarCall(v) ? v.trim() : v]),
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
if (input.leading) out.leading = normalizeLeading(input.leading)
|
|
186
|
+
if (input.radius) out.radius = normalizeVarOrNumber(input.radius, 'radius')
|
|
187
|
+
if (input.container) out.container = normalizeVarOrNumber(input.container, 'container')
|
|
188
|
+
if (input.aspect) out.aspect = normalizeVarOrNumber(input.aspect, 'aspect')
|
|
189
|
+
if (input.shadow) {
|
|
190
|
+
out.shadow = Object.fromEntries(
|
|
191
|
+
Object.entries(input.shadow).map(([name, layers]) => {
|
|
192
|
+
if (typeof layers === 'string') {
|
|
193
|
+
if (!hasVarCall(layers)) {
|
|
194
|
+
throw new Error(`[nitrowind] Invalid shadow token "${layers}" for "${name}".`)
|
|
195
|
+
}
|
|
196
|
+
return [name, layers.trim()]
|
|
197
|
+
}
|
|
198
|
+
return [name, layers.map((layer) => ({ ...layer, color: toColor(layer.color, `shadow.${name}`) }))]
|
|
199
|
+
}),
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
for (const key of ['insetShadow', 'dropShadow'] as const) {
|
|
203
|
+
const group = input[key]
|
|
204
|
+
if (!group) continue
|
|
205
|
+
out[key] = Object.fromEntries(
|
|
206
|
+
Object.entries(group).map(([name, layers]) => {
|
|
207
|
+
if (typeof layers === 'string') {
|
|
208
|
+
if (!hasVarCall(layers)) {
|
|
209
|
+
throw new Error(`[nitrowind] Invalid ${key} token "${layers}" for "${name}".`)
|
|
210
|
+
}
|
|
211
|
+
return [name, layers.trim()]
|
|
212
|
+
}
|
|
213
|
+
return [
|
|
214
|
+
name,
|
|
215
|
+
(layers as { color: ColorInput }[]).map((layer) => ({
|
|
216
|
+
...layer,
|
|
217
|
+
color: toColor(layer.color, `${key}.${name}`),
|
|
218
|
+
})),
|
|
219
|
+
]
|
|
220
|
+
}),
|
|
221
|
+
) as never
|
|
222
|
+
}
|
|
223
|
+
return out
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Builds design tokens from Tailwind's defaults. Groups set directly on `config`
|
|
228
|
+
* replace the default group; groups under `config.extend` are merged into it.
|
|
229
|
+
*/
|
|
230
|
+
export function createTokens(config: TokensConfig = {}, base: Tokens = tailwindTokens): Tokens {
|
|
231
|
+
const { extend, ...overrides } = config
|
|
232
|
+
const replaced = normalize(overrides)
|
|
233
|
+
const extended = normalize(extend ?? {})
|
|
234
|
+
const tokens = { ...base, ...replaced } as Tokens
|
|
235
|
+
if (overrides.breakpoints) {
|
|
236
|
+
tokens.breakpoints = applyBreakpoints(base.breakpoints, overrides.breakpoints, true)
|
|
237
|
+
}
|
|
238
|
+
for (const key of Object.keys(extended) as (keyof Tokens)[]) {
|
|
239
|
+
const value = extended[key]
|
|
240
|
+
if (key === 'spacing') {
|
|
241
|
+
tokens.spacing = value as number | string
|
|
242
|
+
} else if (key === 'spacingScale') {
|
|
243
|
+
tokens.spacingScale = { ...tokens.spacingScale, ...(value as Record<string, number | string>) }
|
|
244
|
+
} else {
|
|
245
|
+
;(tokens as unknown as Record<string, object>)[key] = { ...(tokens[key] as object), ...(value as object) }
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (extend?.breakpoints) {
|
|
249
|
+
tokens.breakpoints = applyBreakpoints(tokens.breakpoints, extend.breakpoints, false)
|
|
250
|
+
}
|
|
251
|
+
return tokens
|
|
252
|
+
}
|