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