@ariaui/typography 0.2.2 → 0.2.3
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/dist/chunk-F7KWOKBZ.js +428 -0
- package/dist/index.cjs +474 -0
- package/dist/index.d.cts +365 -0
- package/dist/index.d.ts +365 -0
- package/dist/index.js +62 -0
- package/dist/tokens.cjs +579 -0
- package/dist/tokens.d.cts +63 -0
- package/dist/tokens.d.ts +63 -0
- package/dist/tokens.js +159 -0
- package/package.json +3 -3
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
|
|
21
|
+
// src/scale.ts
|
|
22
|
+
var RATIOS = {
|
|
23
|
+
minorSecond: 1.067,
|
|
24
|
+
majorSecond: 1.125,
|
|
25
|
+
minorThird: 1.2,
|
|
26
|
+
majorThird: 1.25,
|
|
27
|
+
perfectFourth: 1.333,
|
|
28
|
+
augmentedFourth: 1.414,
|
|
29
|
+
perfectFifth: 1.5,
|
|
30
|
+
goldenRatio: 1.618
|
|
31
|
+
};
|
|
32
|
+
function round(value, decimals = 4) {
|
|
33
|
+
const f = Math.pow(10, decimals);
|
|
34
|
+
return Math.round(value * f) / f;
|
|
35
|
+
}
|
|
36
|
+
function defaultLineHeight(sizeRem) {
|
|
37
|
+
const ratio = Math.max(1.2, Math.min(1.6, 1.6 - (sizeRem - 0.75) * 0.1));
|
|
38
|
+
return round(sizeRem * ratio);
|
|
39
|
+
}
|
|
40
|
+
function defaultLetterSpacing(sizeRem) {
|
|
41
|
+
if (sizeRem >= 2) return "-0.02em";
|
|
42
|
+
if (sizeRem >= 1.5) return "-0.01em";
|
|
43
|
+
return "0em";
|
|
44
|
+
}
|
|
45
|
+
function createModularScale(base = 1, ratio = RATIOS.majorSecond, stepsUp = 5, stepsDown = 2) {
|
|
46
|
+
const result = {};
|
|
47
|
+
for (let i = -stepsDown; i <= stepsUp; i++) {
|
|
48
|
+
const sizeRem = round(base * Math.pow(ratio, i));
|
|
49
|
+
const lh = defaultLineHeight(sizeRem);
|
|
50
|
+
result[String(i)] = {
|
|
51
|
+
size: `${sizeRem}rem`,
|
|
52
|
+
lineHeight: `${lh}rem`,
|
|
53
|
+
letterSpacing: defaultLetterSpacing(sizeRem)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
function extendScale(base, overrides) {
|
|
59
|
+
const result = __spreadValues({}, base);
|
|
60
|
+
for (const [key, partial] of Object.entries(overrides)) {
|
|
61
|
+
const existing = result[key];
|
|
62
|
+
if (existing) {
|
|
63
|
+
result[key] = __spreadValues(__spreadValues({}, existing), partial);
|
|
64
|
+
} else {
|
|
65
|
+
if (!partial.size || !partial.lineHeight || !partial.letterSpacing) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`New scale step "${key}" requires size, lineHeight, and letterSpacing`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
result[key] = partial;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
function getStep(scale, name) {
|
|
76
|
+
return scale[name];
|
|
77
|
+
}
|
|
78
|
+
function listSteps(scale) {
|
|
79
|
+
return Object.keys(scale).sort((a, b) => {
|
|
80
|
+
const sA = parseFloat(scale[a].size);
|
|
81
|
+
const sB = parseFloat(scale[b].size);
|
|
82
|
+
return sA - sB;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/fluid.ts
|
|
87
|
+
function round2(value, decimals = 4) {
|
|
88
|
+
const f = Math.pow(10, decimals);
|
|
89
|
+
return Math.round(value * f) / f;
|
|
90
|
+
}
|
|
91
|
+
function parseRem(value) {
|
|
92
|
+
const n = parseFloat(value);
|
|
93
|
+
if (Number.isNaN(n)) {
|
|
94
|
+
throw new Error(`Cannot parse rem value: "${value}"`);
|
|
95
|
+
}
|
|
96
|
+
return n;
|
|
97
|
+
}
|
|
98
|
+
function fluidSize(config) {
|
|
99
|
+
const { minSize, maxSize, minViewport = 320, maxViewport = 1280 } = config;
|
|
100
|
+
if (minSize === maxSize) {
|
|
101
|
+
return `${minSize}rem`;
|
|
102
|
+
}
|
|
103
|
+
const lo = Math.min(minSize, maxSize);
|
|
104
|
+
const hi = Math.max(minSize, maxSize);
|
|
105
|
+
const slope = (hi - lo) / (maxViewport - minViewport);
|
|
106
|
+
const slopeVw = round2(slope * 100, 4);
|
|
107
|
+
const intercept = round2(lo - slope * minViewport / 16, 4);
|
|
108
|
+
return `clamp(${lo}rem, ${intercept}rem + ${slopeVw}vw, ${hi}rem)`;
|
|
109
|
+
}
|
|
110
|
+
function fluidStyle(min, max, viewports) {
|
|
111
|
+
var _a;
|
|
112
|
+
const minSize = parseRem(min.size);
|
|
113
|
+
const maxSize = parseRem(max.size);
|
|
114
|
+
const minLh = parseRem(min.lineHeight);
|
|
115
|
+
const maxLh = parseRem(max.lineHeight);
|
|
116
|
+
const fontSize = fluidSize({
|
|
117
|
+
minSize,
|
|
118
|
+
maxSize,
|
|
119
|
+
minViewport: viewports == null ? void 0 : viewports.min,
|
|
120
|
+
maxViewport: viewports == null ? void 0 : viewports.max
|
|
121
|
+
});
|
|
122
|
+
const lineHeight = fluidSize({
|
|
123
|
+
minSize: minLh,
|
|
124
|
+
maxSize: maxLh,
|
|
125
|
+
minViewport: viewports == null ? void 0 : viewports.min,
|
|
126
|
+
maxViewport: viewports == null ? void 0 : viewports.max
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
fontSize,
|
|
130
|
+
lineHeight,
|
|
131
|
+
// Use the larger step's tracking (tighter for headings)
|
|
132
|
+
letterSpacing: maxSize >= minSize ? max.letterSpacing : min.letterSpacing,
|
|
133
|
+
fontWeight: (_a = max.fontWeight) != null ? _a : min.fontWeight
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function fluidScale(mobileScale, desktopScale, viewports) {
|
|
137
|
+
const result = {};
|
|
138
|
+
for (const key of Object.keys(desktopScale)) {
|
|
139
|
+
const mobile = mobileScale[key];
|
|
140
|
+
const desktop = desktopScale[key];
|
|
141
|
+
if (!mobile) {
|
|
142
|
+
result[key] = {
|
|
143
|
+
fontSize: desktop.size,
|
|
144
|
+
lineHeight: desktop.lineHeight,
|
|
145
|
+
letterSpacing: desktop.letterSpacing,
|
|
146
|
+
fontWeight: desktop.fontWeight
|
|
147
|
+
};
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
result[key] = fluidStyle(mobile, desktop, viewports);
|
|
151
|
+
}
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/font-stack.ts
|
|
156
|
+
var systemStack = {
|
|
157
|
+
name: "system",
|
|
158
|
+
families: [
|
|
159
|
+
"system-ui",
|
|
160
|
+
"-apple-system",
|
|
161
|
+
"BlinkMacSystemFont",
|
|
162
|
+
"'Segoe UI'",
|
|
163
|
+
"Roboto",
|
|
164
|
+
"'Helvetica Neue'",
|
|
165
|
+
"Arial",
|
|
166
|
+
"sans-serif",
|
|
167
|
+
"'Apple Color Emoji'",
|
|
168
|
+
"'Segoe UI Emoji'"
|
|
169
|
+
]
|
|
170
|
+
};
|
|
171
|
+
var sansStack = {
|
|
172
|
+
name: "sans",
|
|
173
|
+
families: [
|
|
174
|
+
"'Inter'",
|
|
175
|
+
"system-ui",
|
|
176
|
+
"-apple-system",
|
|
177
|
+
"BlinkMacSystemFont",
|
|
178
|
+
"'Segoe UI'",
|
|
179
|
+
"Roboto",
|
|
180
|
+
"'Helvetica Neue'",
|
|
181
|
+
"Arial",
|
|
182
|
+
"sans-serif"
|
|
183
|
+
]
|
|
184
|
+
};
|
|
185
|
+
var serifStack = {
|
|
186
|
+
name: "serif",
|
|
187
|
+
families: [
|
|
188
|
+
"Georgia",
|
|
189
|
+
"'Times New Roman'",
|
|
190
|
+
"Times",
|
|
191
|
+
"serif"
|
|
192
|
+
]
|
|
193
|
+
};
|
|
194
|
+
var monoStack = {
|
|
195
|
+
name: "mono",
|
|
196
|
+
families: [
|
|
197
|
+
"'JetBrains Mono'",
|
|
198
|
+
"'Fira Code'",
|
|
199
|
+
"'SF Mono'",
|
|
200
|
+
"Menlo",
|
|
201
|
+
"Consolas",
|
|
202
|
+
"'Liberation Mono'",
|
|
203
|
+
"'Courier New'",
|
|
204
|
+
"monospace"
|
|
205
|
+
]
|
|
206
|
+
};
|
|
207
|
+
var FONT_STACKS = {
|
|
208
|
+
system: systemStack,
|
|
209
|
+
sans: sansStack,
|
|
210
|
+
serif: serifStack,
|
|
211
|
+
mono: monoStack
|
|
212
|
+
};
|
|
213
|
+
function buildFontFamily(stack) {
|
|
214
|
+
return stack.families.join(", ");
|
|
215
|
+
}
|
|
216
|
+
function createFontStack(name, primary, fallback = systemStack) {
|
|
217
|
+
const quoted = primary.includes("'") || primary.includes('"') ? primary : `'${primary}'`;
|
|
218
|
+
return {
|
|
219
|
+
name,
|
|
220
|
+
families: [quoted, ...fallback.families]
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// src/style.ts
|
|
225
|
+
function createTextStyle(step, overrides) {
|
|
226
|
+
return __spreadValues({
|
|
227
|
+
fontSize: step.size,
|
|
228
|
+
lineHeight: step.lineHeight,
|
|
229
|
+
letterSpacing: step.letterSpacing,
|
|
230
|
+
fontWeight: step.fontWeight
|
|
231
|
+
}, overrides);
|
|
232
|
+
}
|
|
233
|
+
function mergeTextStyles(...styles) {
|
|
234
|
+
let fontSize;
|
|
235
|
+
let lineHeight;
|
|
236
|
+
let letterSpacing;
|
|
237
|
+
let fontWeight;
|
|
238
|
+
let fontFamily;
|
|
239
|
+
for (const style of styles) {
|
|
240
|
+
if (style.fontSize !== void 0) fontSize = style.fontSize;
|
|
241
|
+
if (style.lineHeight !== void 0) lineHeight = style.lineHeight;
|
|
242
|
+
if (style.letterSpacing !== void 0) letterSpacing = style.letterSpacing;
|
|
243
|
+
if (style.fontWeight !== void 0) fontWeight = style.fontWeight;
|
|
244
|
+
if (style.fontFamily !== void 0) fontFamily = style.fontFamily;
|
|
245
|
+
}
|
|
246
|
+
if (!fontSize || !lineHeight || !letterSpacing) {
|
|
247
|
+
throw new Error(
|
|
248
|
+
"mergeTextStyles: result must have fontSize, lineHeight, and letterSpacing"
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
return { fontSize, lineHeight, letterSpacing, fontWeight, fontFamily };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// src/format.ts
|
|
255
|
+
function toCSSProperties(style) {
|
|
256
|
+
const props = {
|
|
257
|
+
fontSize: style.fontSize,
|
|
258
|
+
lineHeight: style.lineHeight,
|
|
259
|
+
letterSpacing: style.letterSpacing
|
|
260
|
+
};
|
|
261
|
+
if (style.fontWeight) props.fontWeight = style.fontWeight;
|
|
262
|
+
if (style.fontFamily) props.fontFamily = style.fontFamily;
|
|
263
|
+
return props;
|
|
264
|
+
}
|
|
265
|
+
function toCSSDeclarations(style) {
|
|
266
|
+
const lines = [
|
|
267
|
+
`font-size: ${style.fontSize};`,
|
|
268
|
+
`line-height: ${style.lineHeight};`,
|
|
269
|
+
`letter-spacing: ${style.letterSpacing};`
|
|
270
|
+
];
|
|
271
|
+
if (style.fontWeight) lines.push(`font-weight: ${style.fontWeight};`);
|
|
272
|
+
if (style.fontFamily) lines.push(`font-family: ${style.fontFamily};`);
|
|
273
|
+
return lines.join("\n");
|
|
274
|
+
}
|
|
275
|
+
function toCSSVars(stepName) {
|
|
276
|
+
const lines = [
|
|
277
|
+
`font-size: var(--font-size-${stepName});`,
|
|
278
|
+
`line-height: var(--font-size-${stepName}--line-height);`
|
|
279
|
+
];
|
|
280
|
+
lines.push(`letter-spacing: var(--font-size-${stepName}--letter-spacing, 0em);`);
|
|
281
|
+
return lines.join("\n");
|
|
282
|
+
}
|
|
283
|
+
function toTailwindClasses(style) {
|
|
284
|
+
const parts = [
|
|
285
|
+
`text-[${style.fontSize}]`,
|
|
286
|
+
`leading-[${style.lineHeight}]`,
|
|
287
|
+
`tracking-[${style.letterSpacing}]`
|
|
288
|
+
];
|
|
289
|
+
if (style.fontWeight) parts.push(`font-[${style.fontWeight}]`);
|
|
290
|
+
return parts.join(" ");
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// src/responsive.ts
|
|
294
|
+
var BREAKPOINTS = {
|
|
295
|
+
sm: 640,
|
|
296
|
+
md: 768,
|
|
297
|
+
lg: 1024,
|
|
298
|
+
xl: 1280,
|
|
299
|
+
"2xl": 1536
|
|
300
|
+
};
|
|
301
|
+
function responsiveStyle(config, breakpoints = BREAKPOINTS) {
|
|
302
|
+
const defaultEntry = config["default"];
|
|
303
|
+
if (!defaultEntry) {
|
|
304
|
+
throw new Error('responsiveStyle: "default" entry is required');
|
|
305
|
+
}
|
|
306
|
+
const defaultStyle = isTextStyle(defaultEntry) ? defaultEntry : createTextStyle(defaultEntry);
|
|
307
|
+
const bps = {};
|
|
308
|
+
for (const [key, value] of Object.entries(config)) {
|
|
309
|
+
if (key === "default") continue;
|
|
310
|
+
if (!(key in breakpoints)) {
|
|
311
|
+
throw new Error(
|
|
312
|
+
`responsiveStyle: unknown breakpoint "${key}". Available: ${Object.keys(breakpoints).join(", ")}`
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
bps[key] = isTextStyle(value) ? value : createTextStyle(value);
|
|
316
|
+
}
|
|
317
|
+
return { default: defaultStyle, breakpoints: bps };
|
|
318
|
+
}
|
|
319
|
+
function sortedBreakpoints(responsive, breakpoints = BREAKPOINTS) {
|
|
320
|
+
return Object.entries(responsive.breakpoints).map(([name, style]) => {
|
|
321
|
+
var _a;
|
|
322
|
+
return [name, (_a = breakpoints[name]) != null ? _a : 0, style];
|
|
323
|
+
}).sort((a, b) => a[1] - b[1]);
|
|
324
|
+
}
|
|
325
|
+
function isTextStyle(value) {
|
|
326
|
+
return "fontSize" in value;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// src/measure.ts
|
|
330
|
+
function parseRem2(value) {
|
|
331
|
+
const n = parseFloat(value);
|
|
332
|
+
if (Number.isNaN(n)) {
|
|
333
|
+
throw new Error(`Cannot parse rem value: "${value}"`);
|
|
334
|
+
}
|
|
335
|
+
return n;
|
|
336
|
+
}
|
|
337
|
+
function round3(value, decimals = 2) {
|
|
338
|
+
const f = Math.pow(10, decimals);
|
|
339
|
+
return Math.round(value * f) / f;
|
|
340
|
+
}
|
|
341
|
+
function optimalMeasure(options) {
|
|
342
|
+
var _a;
|
|
343
|
+
const ideal = (_a = options == null ? void 0 : options.ideal) != null ? _a : 66;
|
|
344
|
+
return `${ideal}ch`;
|
|
345
|
+
}
|
|
346
|
+
function measureRange(options) {
|
|
347
|
+
var _a, _b, _c;
|
|
348
|
+
const min = (_a = options == null ? void 0 : options.min) != null ? _a : 45;
|
|
349
|
+
const max = (_b = options == null ? void 0 : options.max) != null ? _b : 75;
|
|
350
|
+
const ideal = (_c = options == null ? void 0 : options.ideal) != null ? _c : 66;
|
|
351
|
+
return {
|
|
352
|
+
min: `${min}ch`,
|
|
353
|
+
max: `${max}ch`,
|
|
354
|
+
ideal: `${ideal}ch`
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
function snapToBaseline(fontSize, config) {
|
|
358
|
+
var _a, _b;
|
|
359
|
+
const size = parseRem2(fontSize);
|
|
360
|
+
const grid = (_a = config == null ? void 0 : config.gridUnit) != null ? _a : 0.25;
|
|
361
|
+
const rounding = (_b = config == null ? void 0 : config.rounding) != null ? _b : "ceil";
|
|
362
|
+
const minLh = size * 1.2;
|
|
363
|
+
const steps = minLh / grid;
|
|
364
|
+
let snapped;
|
|
365
|
+
switch (rounding) {
|
|
366
|
+
case "floor":
|
|
367
|
+
snapped = Math.floor(steps) * grid;
|
|
368
|
+
if (snapped < size) snapped = Math.ceil(size / grid) * grid;
|
|
369
|
+
break;
|
|
370
|
+
case "round":
|
|
371
|
+
snapped = Math.round(steps) * grid;
|
|
372
|
+
if (snapped < size) snapped += grid;
|
|
373
|
+
break;
|
|
374
|
+
case "ceil":
|
|
375
|
+
default:
|
|
376
|
+
snapped = Math.ceil(steps) * grid;
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
return `${round3(snapped, 4)}rem`;
|
|
380
|
+
}
|
|
381
|
+
function rhythmSpacing(lineHeight, lines = 1, gridUnit = 0.25) {
|
|
382
|
+
return `${round3(lines * gridUnit, 4)}rem`;
|
|
383
|
+
}
|
|
384
|
+
function verticalRhythm(fontSize, spacingLines = 4, config) {
|
|
385
|
+
var _a;
|
|
386
|
+
const grid = (_a = config == null ? void 0 : config.gridUnit) != null ? _a : 0.25;
|
|
387
|
+
const lineHeight = snapToBaseline(fontSize, config);
|
|
388
|
+
const spacing = rhythmSpacing(lineHeight, spacingLines, grid);
|
|
389
|
+
return {
|
|
390
|
+
lineHeight,
|
|
391
|
+
marginTop: spacing,
|
|
392
|
+
marginBottom: spacing
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export {
|
|
397
|
+
__spreadValues,
|
|
398
|
+
__spreadProps,
|
|
399
|
+
RATIOS,
|
|
400
|
+
createModularScale,
|
|
401
|
+
extendScale,
|
|
402
|
+
getStep,
|
|
403
|
+
listSteps,
|
|
404
|
+
fluidSize,
|
|
405
|
+
fluidStyle,
|
|
406
|
+
fluidScale,
|
|
407
|
+
systemStack,
|
|
408
|
+
sansStack,
|
|
409
|
+
serifStack,
|
|
410
|
+
monoStack,
|
|
411
|
+
FONT_STACKS,
|
|
412
|
+
buildFontFamily,
|
|
413
|
+
createFontStack,
|
|
414
|
+
createTextStyle,
|
|
415
|
+
mergeTextStyles,
|
|
416
|
+
toCSSProperties,
|
|
417
|
+
toCSSDeclarations,
|
|
418
|
+
toCSSVars,
|
|
419
|
+
toTailwindClasses,
|
|
420
|
+
BREAKPOINTS,
|
|
421
|
+
responsiveStyle,
|
|
422
|
+
sortedBreakpoints,
|
|
423
|
+
optimalMeasure,
|
|
424
|
+
measureRange,
|
|
425
|
+
snapToBaseline,
|
|
426
|
+
rhythmSpacing,
|
|
427
|
+
verticalRhythm
|
|
428
|
+
};
|