@cognitap/radiant 0.0.4 → 0.0.6
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 +44 -0
- package/README.md +17 -0
- package/dist/library/Button.d.ts +3 -1
- package/dist/library/Button.d.ts.map +1 -1
- package/dist/library/Button.js +43 -2
- package/dist/library/Button.js.map +1 -1
- package/dist/library/Card.d.ts.map +1 -1
- package/dist/library/Card.js +8 -6
- package/dist/library/Card.js.map +1 -1
- package/dist/library/Checkbox.js +2 -2
- package/dist/library/Checkbox.js.map +1 -1
- package/dist/library/Collapsible.d.ts +2 -1
- package/dist/library/Collapsible.d.ts.map +1 -1
- package/dist/library/Collapsible.js +10 -6
- package/dist/library/Collapsible.js.map +1 -1
- package/dist/library/Dialog.d.ts +2 -1
- package/dist/library/Dialog.d.ts.map +1 -1
- package/dist/library/Dialog.js +13 -8
- package/dist/library/Dialog.js.map +1 -1
- package/dist/library/Field.js +4 -4
- package/dist/library/Field.js.map +1 -1
- package/dist/library/Input.d.ts.map +1 -1
- package/dist/library/Input.js +4 -3
- package/dist/library/Input.js.map +1 -1
- package/dist/library/Link.d.ts.map +1 -1
- package/dist/library/Link.js +0 -1
- package/dist/library/Link.js.map +1 -1
- package/dist/library/RadioGroup.js +2 -2
- package/dist/library/RadioGroup.js.map +1 -1
- package/dist/library/ThemeScope.d.ts.map +1 -1
- package/dist/library/ThemeScope.js +11 -10
- package/dist/library/ThemeScope.js.map +1 -1
- package/dist/library/actionStyles.js +2 -2
- package/dist/library/actionStyles.js.map +1 -1
- package/dist/library/cn.d.ts +2 -1
- package/dist/library/cn.d.ts.map +1 -1
- package/dist/library/cn.js +22 -1
- package/dist/library/cn.js.map +1 -1
- package/dist/library/index.d.ts +5 -1
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js +2 -0
- package/dist/library/index.js.map +1 -1
- package/dist/library/motion/MotionLink.d.ts +7 -0
- package/dist/library/motion/MotionLink.d.ts.map +1 -0
- package/dist/library/motion/MotionLink.js +45 -0
- package/dist/library/motion/MotionLink.js.map +1 -0
- package/dist/library/motion/browser.d.ts +5 -0
- package/dist/library/motion/browser.d.ts.map +1 -0
- package/dist/library/motion/browser.js +35 -0
- package/dist/library/motion/browser.js.map +1 -0
- package/dist/library/motion/config.d.ts +26 -0
- package/dist/library/motion/config.d.ts.map +1 -0
- package/dist/library/motion/config.js +58 -0
- package/dist/library/motion/config.js.map +1 -0
- package/dist/library/motion/context.d.ts +2 -0
- package/dist/library/motion/context.d.ts.map +1 -0
- package/dist/library/motion/context.js +5 -0
- package/dist/library/motion/context.js.map +1 -0
- package/dist/library/motion/drag.d.ts +20 -0
- package/dist/library/motion/drag.d.ts.map +1 -0
- package/dist/library/motion/drag.js +138 -0
- package/dist/library/motion/drag.js.map +1 -0
- package/dist/library/motion/dragBrowser.d.ts +4 -0
- package/dist/library/motion/dragBrowser.d.ts.map +1 -0
- package/dist/library/motion/dragBrowser.js +156 -0
- package/dist/library/motion/dragBrowser.js.map +1 -0
- package/dist/library/motion/follow.d.ts +9 -0
- package/dist/library/motion/follow.d.ts.map +1 -0
- package/dist/library/motion/follow.js +26 -0
- package/dist/library/motion/follow.js.map +1 -0
- package/dist/library/motion/host.d.ts +27 -0
- package/dist/library/motion/host.d.ts.map +1 -0
- package/dist/library/motion/host.js +62 -0
- package/dist/library/motion/host.js.map +1 -0
- package/dist/library/motion/index.d.ts +16 -0
- package/dist/library/motion/index.d.ts.map +1 -0
- package/dist/library/motion/index.js +9 -0
- package/dist/library/motion/index.js.map +1 -0
- package/dist/library/motion/layout.d.ts +20 -0
- package/dist/library/motion/layout.d.ts.map +1 -0
- package/dist/library/motion/layout.js +67 -0
- package/dist/library/motion/layout.js.map +1 -0
- package/dist/library/motion/layoutDom.d.ts +17 -0
- package/dist/library/motion/layoutDom.d.ts.map +1 -0
- package/dist/library/motion/layoutDom.js +272 -0
- package/dist/library/motion/layoutDom.js.map +1 -0
- package/dist/library/motion/press.d.ts +5 -0
- package/dist/library/motion/press.d.ts.map +1 -0
- package/dist/library/motion/press.js +72 -0
- package/dist/library/motion/press.js.map +1 -0
- package/dist/library/motion/pressPolicy.d.ts +5 -0
- package/dist/library/motion/pressPolicy.d.ts.map +1 -0
- package/dist/library/motion/pressPolicy.js +8 -0
- package/dist/library/motion/pressPolicy.js.map +1 -0
- package/dist/library/motion/react.d.ts +35 -0
- package/dist/library/motion/react.d.ts.map +1 -0
- package/dist/library/motion/react.js +224 -0
- package/dist/library/motion/react.js.map +1 -0
- package/dist/library/motion/runtime.d.ts +22 -0
- package/dist/library/motion/runtime.d.ts.map +1 -0
- package/dist/library/motion/runtime.js +117 -0
- package/dist/library/motion/runtime.js.map +1 -0
- package/dist/library/motion/transitions.d.ts +5 -0
- package/dist/library/motion/transitions.d.ts.map +1 -0
- package/dist/library/motion/transitions.js +211 -0
- package/dist/library/motion/transitions.js.map +1 -0
- package/dist/library/styles.css +1 -1
- package/dist/library/themes/defineTheme.d.ts +3 -0
- package/dist/library/themes/defineTheme.d.ts.map +1 -1
- package/dist/library/themes/defineTheme.js +9 -3
- package/dist/library/themes/defineTheme.js.map +1 -1
- package/dist/library/themes/index.d.ts +1 -1
- package/dist/library/themes/index.d.ts.map +1 -1
- package/dist/library/themes/index.js.map +1 -1
- package/dist/library/themes/themeDocument.d.ts.map +1 -1
- package/dist/library/themes/themeDocument.js +39 -8
- package/dist/library/themes/themeDocument.js.map +1 -1
- package/dist/library/themes/themeDocumentTypes.d.ts +16 -1
- package/dist/library/themes/themeDocumentTypes.d.ts.map +1 -1
- package/dist/library/themes/themeDocumentTypes.js.map +1 -1
- package/dist/library/themes/tokens.d.ts +7 -0
- package/dist/library/themes/tokens.d.ts.map +1 -1
- package/dist/library/themes/tokens.js +99 -0
- package/dist/library/themes/tokens.js.map +1 -1
- package/dist/library/typography/index.d.ts +72 -0
- package/dist/library/typography/index.d.ts.map +1 -0
- package/dist/library/typography/index.js +160 -0
- package/dist/library/typography/index.js.map +1 -0
- package/dist/library/typography/types.d.ts +78 -0
- package/dist/library/typography/types.d.ts.map +1 -0
- package/dist/library/typography/types.js +2 -0
- package/dist/library/typography/types.js.map +1 -0
- package/docs/motion.md +434 -0
- package/docs/system.md +33 -0
- package/docs/theming.md +204 -0
- package/package.json +20 -4
- package/src/Button.tsx +49 -1
- package/src/Card.tsx +8 -6
- package/src/Checkbox.tsx +2 -2
- package/src/Collapsible.tsx +18 -5
- package/src/Dialog.tsx +18 -7
- package/src/Field.tsx +4 -4
- package/src/Input.tsx +4 -3
- package/src/Link.tsx +0 -1
- package/src/RadioGroup.tsx +2 -2
- package/src/ThemeScope.tsx +22 -18
- package/src/actionStyles.ts +2 -2
- package/src/cn.ts +25 -1
- package/src/index.ts +12 -0
- package/src/motion/MotionLink.tsx +64 -0
- package/src/motion/browser.ts +45 -0
- package/src/motion/config.ts +79 -0
- package/src/motion/context.ts +4 -0
- package/src/motion/drag.ts +151 -0
- package/src/motion/dragBrowser.ts +159 -0
- package/src/motion/follow.ts +28 -0
- package/src/motion/host.ts +88 -0
- package/src/motion/index.ts +28 -0
- package/src/motion/layout.ts +78 -0
- package/src/motion/layoutDom.ts +293 -0
- package/src/motion/press.ts +77 -0
- package/src/motion/pressPolicy.ts +12 -0
- package/src/motion/react.ts +272 -0
- package/src/motion/runtime.ts +122 -0
- package/src/motion/transitions.ts +206 -0
- package/src/styles.css +1 -0
- package/src/themes/baseline.css +131 -0
- package/src/themes/defineTheme.ts +15 -3
- package/src/themes/index.ts +2 -0
- package/src/themes/themeDocument.ts +47 -9
- package/src/themes/themeDocumentTypes.ts +24 -5
- package/src/themes/tokens.ts +137 -0
- package/src/typography/index.ts +199 -0
- package/src/typography/types.ts +92 -0
- package/src/typography.css +336 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { typographyRoles } from '../themes/tokens.js';
|
|
2
|
+
import type { TypographyInput, TypographyResult } from './types.js';
|
|
3
|
+
export type * from './types.js';
|
|
4
|
+
export { typographyRoles };
|
|
5
|
+
export declare const typographyPresets: Readonly<{
|
|
6
|
+
readonly inter: {
|
|
7
|
+
readonly name: "Inter";
|
|
8
|
+
readonly fonts: {
|
|
9
|
+
readonly body: {
|
|
10
|
+
readonly family: "Inter, system-ui, sans-serif";
|
|
11
|
+
readonly profile: "inter";
|
|
12
|
+
};
|
|
13
|
+
readonly headings: {
|
|
14
|
+
readonly family: "Inter, system-ui, sans-serif";
|
|
15
|
+
readonly profile: "inter";
|
|
16
|
+
};
|
|
17
|
+
readonly ui: {
|
|
18
|
+
readonly family: "Inter, system-ui, sans-serif";
|
|
19
|
+
readonly profile: "inter";
|
|
20
|
+
};
|
|
21
|
+
readonly code: {
|
|
22
|
+
readonly family: "\"IBM Plex Mono\", ui-monospace, monospace";
|
|
23
|
+
readonly profile: "plex-mono";
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
readonly 'source-serif': {
|
|
28
|
+
readonly name: "Source Serif 4 + Inter";
|
|
29
|
+
readonly fonts: {
|
|
30
|
+
readonly body: {
|
|
31
|
+
readonly family: "\"Source Serif 4\", Georgia, serif";
|
|
32
|
+
readonly profile: "source-serif-4";
|
|
33
|
+
};
|
|
34
|
+
readonly headings: {
|
|
35
|
+
readonly family: "\"Source Serif 4\", Georgia, serif";
|
|
36
|
+
readonly profile: "source-serif-4";
|
|
37
|
+
};
|
|
38
|
+
readonly ui: {
|
|
39
|
+
readonly family: "Inter, system-ui, sans-serif";
|
|
40
|
+
readonly profile: "inter";
|
|
41
|
+
};
|
|
42
|
+
readonly code: {
|
|
43
|
+
readonly family: "\"IBM Plex Mono\", ui-monospace, monospace";
|
|
44
|
+
readonly profile: "plex-mono";
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
readonly plex: {
|
|
49
|
+
readonly name: "Plex Sans + Plex Mono";
|
|
50
|
+
readonly fonts: {
|
|
51
|
+
readonly body: {
|
|
52
|
+
readonly family: "\"IBM Plex Sans\", system-ui, sans-serif";
|
|
53
|
+
readonly profile: "plex-sans";
|
|
54
|
+
};
|
|
55
|
+
readonly headings: {
|
|
56
|
+
readonly family: "\"IBM Plex Sans\", system-ui, sans-serif";
|
|
57
|
+
readonly profile: "plex-sans";
|
|
58
|
+
};
|
|
59
|
+
readonly ui: {
|
|
60
|
+
readonly family: "\"IBM Plex Sans\", system-ui, sans-serif";
|
|
61
|
+
readonly profile: "plex-sans";
|
|
62
|
+
};
|
|
63
|
+
readonly code: {
|
|
64
|
+
readonly family: "\"IBM Plex Mono\", ui-monospace, monospace";
|
|
65
|
+
readonly profile: "plex-mono";
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
}>;
|
|
70
|
+
/** Pure, server-safe calculations. Input omits automatic metrics; output never loads a font. */
|
|
71
|
+
export declare function generateTypography(input?: TypographyInput): TypographyResult;
|
|
72
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/typography/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EAGhB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAGV,eAAe,EAGf,gBAAgB,EACjB,MAAM,YAAY,CAAA;AACnB,mBAAmB,YAAY,CAAA;AAC/B,OAAO,EAAE,eAAe,EAAE,CAAA;AAM1B,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUnB,CAAA;AA4CX,gGAAgG;AAChG,wBAAgB,kBAAkB,CAAC,KAAK,GAAE,eAAoB,GAAG,gBAAgB,CAuHhF"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { freezeTree, typographyRoles, typographyStyles, typographyTokens } from '../themes/tokens.js';
|
|
2
|
+
export { typographyRoles };
|
|
3
|
+
const inter = { family: 'Inter, system-ui, sans-serif', profile: 'inter' };
|
|
4
|
+
const serif = { family: '"Source Serif 4", Georgia, serif', profile: 'source-serif-4' };
|
|
5
|
+
const plex = { family: '"IBM Plex Sans", system-ui, sans-serif', profile: 'plex-sans' };
|
|
6
|
+
const mono = { family: '"IBM Plex Mono", ui-monospace, monospace', profile: 'plex-mono' };
|
|
7
|
+
export const typographyPresets = freezeTree({
|
|
8
|
+
inter: { name: 'Inter', fonts: { body: inter, headings: inter, ui: inter, code: mono } },
|
|
9
|
+
'source-serif': {
|
|
10
|
+
name: 'Source Serif 4 + Inter',
|
|
11
|
+
fonts: { body: serif, headings: serif, ui: inter, code: mono }
|
|
12
|
+
},
|
|
13
|
+
plex: {
|
|
14
|
+
name: 'Plex Sans + Plex Mono',
|
|
15
|
+
fonts: { body: plex, headings: plex, ui: plex, code: mono }
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const assignments = ['body', 'headings', 'ui', 'code'];
|
|
19
|
+
const profiles = [
|
|
20
|
+
'inter',
|
|
21
|
+
'source-serif-4',
|
|
22
|
+
'plex-sans',
|
|
23
|
+
'plex-mono',
|
|
24
|
+
'manual'
|
|
25
|
+
];
|
|
26
|
+
const bodyProfiles = {
|
|
27
|
+
inter: [20, 1.6, 64],
|
|
28
|
+
'source-serif-4': [21, 1.65, 62],
|
|
29
|
+
'plex-sans': [20, 1.6, 62]
|
|
30
|
+
};
|
|
31
|
+
const weights = {
|
|
32
|
+
inter: [100, 900],
|
|
33
|
+
'source-serif-4': [200, 900],
|
|
34
|
+
'plex-sans': [100, 700],
|
|
35
|
+
'plex-mono': [100, 700]
|
|
36
|
+
};
|
|
37
|
+
function record(value, path) {
|
|
38
|
+
if (!value ||
|
|
39
|
+
typeof value !== 'object' ||
|
|
40
|
+
Array.isArray(value) ||
|
|
41
|
+
![Object.prototype, null].includes(Object.getPrototypeOf(value)))
|
|
42
|
+
throw new TypeError(`${path} must be a plain object.`);
|
|
43
|
+
}
|
|
44
|
+
function keys(value, allowed, path) {
|
|
45
|
+
for (const key of Object.keys(value))
|
|
46
|
+
if (!allowed.includes(key))
|
|
47
|
+
throw new TypeError(`Unknown key: ${path}.${key}.`);
|
|
48
|
+
}
|
|
49
|
+
function number(value, min, max, path) {
|
|
50
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value < min || value > max)
|
|
51
|
+
throw new TypeError(`${path} must be a finite number from ${min} to ${max}.`);
|
|
52
|
+
}
|
|
53
|
+
function metrics(value, bounds, path) {
|
|
54
|
+
record(value, path);
|
|
55
|
+
keys(value, Object.keys(bounds), path);
|
|
56
|
+
for (const [key, item] of Object.entries(value))
|
|
57
|
+
if (item !== undefined)
|
|
58
|
+
number(item, ...bounds[key], `${path}.${key}`);
|
|
59
|
+
}
|
|
60
|
+
/** Pure, server-safe calculations. Input omits automatic metrics; output never loads a font. */
|
|
61
|
+
export function generateTypography(input = {}) {
|
|
62
|
+
record(input, 'typography');
|
|
63
|
+
keys(input, ['preset', 'fonts', 'prose', 'ui', 'styles'], 'typography');
|
|
64
|
+
const preset = input.preset === undefined ? 'inter' : input.preset;
|
|
65
|
+
if (typeof preset !== 'string' || !Object.hasOwn(typographyPresets, preset))
|
|
66
|
+
throw new TypeError('Unknown typography.preset.');
|
|
67
|
+
const fonts = { ...typographyPresets[preset].fonts };
|
|
68
|
+
if (input.fonts !== undefined) {
|
|
69
|
+
record(input.fonts, 'typography.fonts');
|
|
70
|
+
keys(input.fonts, assignments, 'typography.fonts');
|
|
71
|
+
for (const key of assignments) {
|
|
72
|
+
const font = input.fonts[key];
|
|
73
|
+
if (font === undefined)
|
|
74
|
+
continue;
|
|
75
|
+
record(font, `typography.fonts.${key}`);
|
|
76
|
+
keys(font, ['family', 'profile'], `typography.fonts.${key}`);
|
|
77
|
+
if (typeof font.family !== 'string' ||
|
|
78
|
+
!font.family.trim() ||
|
|
79
|
+
/[;{}@]|url\s*\(/i.test(font.family) ||
|
|
80
|
+
[...font.family].some(character => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127))
|
|
81
|
+
throw new TypeError(`typography.fonts.${key}.family must be a CSS font-family list.`);
|
|
82
|
+
if (font.profile !== undefined && !profiles.includes(font.profile))
|
|
83
|
+
throw new TypeError(`Unknown typography.fonts.${key}.profile.`);
|
|
84
|
+
fonts[key] = { family: font.family, profile: font.profile ?? 'manual' };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const manualProse = input.prose === undefined ? {} : input.prose, manualUI = input.ui === undefined ? {} : input.ui;
|
|
88
|
+
metrics(manualProse, {
|
|
89
|
+
size: [12, 40],
|
|
90
|
+
lineHeight: [1, 3],
|
|
91
|
+
paragraphSpacing: [0, 4],
|
|
92
|
+
measure: [20, 120],
|
|
93
|
+
headingScale: [1.1, 1.5]
|
|
94
|
+
}, 'typography.prose');
|
|
95
|
+
metrics(manualUI, { size: [12, 32], lineHeight: [1, 3] }, 'typography.ui');
|
|
96
|
+
const profile = bodyProfiles[fonts.body.profile ?? 'manual'];
|
|
97
|
+
const prose = {
|
|
98
|
+
size: profile?.[0] ?? 20,
|
|
99
|
+
lineHeight: profile?.[1] ?? 1.65,
|
|
100
|
+
measure: profile?.[2] ?? 64,
|
|
101
|
+
paragraphSpacing: 1.25,
|
|
102
|
+
headingScale: 1.25,
|
|
103
|
+
...defined(manualProse)
|
|
104
|
+
};
|
|
105
|
+
const ui = { size: 16, lineHeight: 1.5, ...defined(manualUI) };
|
|
106
|
+
const styles = typographyStyles(prose, ui);
|
|
107
|
+
const overrides = input.styles === undefined ? {} : input.styles;
|
|
108
|
+
record(overrides, 'typography.styles');
|
|
109
|
+
keys(overrides, typographyRoles, 'typography.styles');
|
|
110
|
+
for (const role of typographyRoles) {
|
|
111
|
+
const override = overrides[role];
|
|
112
|
+
if (override === undefined)
|
|
113
|
+
continue;
|
|
114
|
+
record(override, `typography.styles.${role}`);
|
|
115
|
+
const { assignment, ...numeric } = override;
|
|
116
|
+
if (assignment !== undefined && !assignments.includes(assignment))
|
|
117
|
+
throw new TypeError(`Unknown typography.styles.${role}.assignment.`);
|
|
118
|
+
metrics(numeric, {
|
|
119
|
+
narrow: [8, 256],
|
|
120
|
+
wide: [8, 512],
|
|
121
|
+
weight: [1, 1000],
|
|
122
|
+
lineHeight: [0.8, 3],
|
|
123
|
+
tracking: [-0.2, 0.5],
|
|
124
|
+
measure: [0, 120]
|
|
125
|
+
}, `typography.styles.${role}`);
|
|
126
|
+
styles[role] = { ...styles[role], ...defined(override) };
|
|
127
|
+
if (styles[role].wide < styles[role].narrow)
|
|
128
|
+
throw new TypeError(`typography.styles.${role}.wide must be at least narrow.`);
|
|
129
|
+
}
|
|
130
|
+
const warnings = [];
|
|
131
|
+
for (const role of typographyRoles) {
|
|
132
|
+
const s = styles[role], range = weights[fonts[s.assignment].profile ?? 'manual'];
|
|
133
|
+
if (range && (s.weight < range[0] || s.weight > range[1]))
|
|
134
|
+
warnings.push({ role, requestedWeight: s.weight, supportedWeights: range });
|
|
135
|
+
}
|
|
136
|
+
return freezeTree({
|
|
137
|
+
input: {
|
|
138
|
+
preset,
|
|
139
|
+
fonts,
|
|
140
|
+
prose: defined(manualProse),
|
|
141
|
+
ui: defined(manualUI),
|
|
142
|
+
styles: Object.fromEntries(Object.entries(overrides)
|
|
143
|
+
.filter(([, v]) => v !== undefined)
|
|
144
|
+
.map(([k, v]) => [k, defined(v)]))
|
|
145
|
+
},
|
|
146
|
+
prose,
|
|
147
|
+
ui,
|
|
148
|
+
styles,
|
|
149
|
+
tokens: typographyTokens(styles, Object.fromEntries(assignments.map(key => [key, fonts[key].family])), prose.paragraphSpacing),
|
|
150
|
+
recommendations: {
|
|
151
|
+
body: !!profile,
|
|
152
|
+
ui: fonts.ui.profile === 'inter' || fonts.ui.profile === 'plex-sans'
|
|
153
|
+
},
|
|
154
|
+
warnings
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function defined(value) {
|
|
158
|
+
return Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined));
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=index.js.map
|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AC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAGlE,EACD,KAAK,CAAC,gBAAgB,CACvB;QACD,eAAe,EAAE;YACf,IAAI,EAAE,CAAC,CAAC,OAAO;YACf,EAAE,EAAE,KAAK,CAAC,EAAE,CAAC,OAAO,KAAK,OAAO,IAAI,KAAK,CAAC,EAAE,CAAC,OAAO,KAAK,WAAW;SACrE;QACD,QAAQ;KACT,CAAC,CAAA;AACJ,CAAC;AACD,SAAS,OAAO,CAAmB,KAAQ;IACzC,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAM,CAAA;AAC1F,CAAC","sourcesContent":["import {\n freezeTree,\n typographyRoles,\n typographyStyles,\n typographyTokens\n} from '../themes/tokens.js'\nimport type {\n TypographyAssignment,\n TypographyFont,\n TypographyInput,\n TypographyProfile,\n TypographyProseRhythm,\n TypographyResult\n} from './types.js'\nexport type * from './types.js'\nexport { typographyRoles }\n\nconst inter = { family: 'Inter, system-ui, sans-serif', profile: 'inter' } as const\nconst serif = { family: '\"Source Serif 4\", Georgia, serif', profile: 'source-serif-4' } as const\nconst plex = { family: '\"IBM Plex Sans\", system-ui, sans-serif', profile: 'plex-sans' } as const\nconst mono = { family: '\"IBM Plex Mono\", ui-monospace, monospace', profile: 'plex-mono' } as const\nexport const typographyPresets = freezeTree({\n inter: { name: 'Inter', fonts: { body: inter, headings: inter, ui: inter, code: mono } },\n 'source-serif': {\n name: 'Source Serif 4 + Inter',\n fonts: { body: serif, headings: serif, ui: inter, code: mono }\n },\n plex: {\n name: 'Plex Sans + Plex Mono',\n fonts: { body: plex, headings: plex, ui: plex, code: mono }\n }\n} as const)\nconst assignments: readonly TypographyAssignment[] = ['body', 'headings', 'ui', 'code']\nconst profiles: readonly TypographyProfile[] = [\n 'inter',\n 'source-serif-4',\n 'plex-sans',\n 'plex-mono',\n 'manual'\n]\nconst bodyProfiles: Partial<Record<TypographyProfile, readonly [number, number, number]>> = {\n inter: [20, 1.6, 64],\n 'source-serif-4': [21, 1.65, 62],\n 'plex-sans': [20, 1.6, 62]\n}\nconst weights: Partial<Record<TypographyProfile, readonly [number, number]>> = {\n inter: [100, 900],\n 'source-serif-4': [200, 900],\n 'plex-sans': [100, 700],\n 'plex-mono': [100, 700]\n}\nfunction record(value: unknown, path: string): void {\n if (\n !value ||\n typeof value !== 'object' ||\n Array.isArray(value) ||\n ![Object.prototype, null].includes(Object.getPrototypeOf(value))\n )\n throw new TypeError(`${path} must be a plain object.`)\n}\nfunction keys(value: object, allowed: readonly string[], path: string) {\n for (const key of Object.keys(value))\n if (!allowed.includes(key)) throw new TypeError(`Unknown key: ${path}.${key}.`)\n}\nfunction number(value: unknown, min: number, max: number, path: string) {\n if (typeof value !== 'number' || !Number.isFinite(value) || value < min || value > max)\n throw new TypeError(`${path} must be a finite number from ${min} to ${max}.`)\n}\nfunction metrics(value: object, bounds: Record<string, readonly [number, number]>, path: string) {\n record(value, path)\n keys(value, Object.keys(bounds), path)\n for (const [key, item] of Object.entries(value))\n if (item !== undefined) number(item, ...bounds[key], `${path}.${key}`)\n}\n\n/** Pure, server-safe calculations. Input omits automatic metrics; output never loads a font. */\nexport function generateTypography(input: TypographyInput = {}): TypographyResult {\n record(input, 'typography')\n keys(input, ['preset', 'fonts', 'prose', 'ui', 'styles'], 'typography')\n const preset = input.preset === undefined ? 'inter' : input.preset\n if (typeof preset !== 'string' || !Object.hasOwn(typographyPresets, preset))\n throw new TypeError('Unknown typography.preset.')\n const fonts = { ...typographyPresets[preset].fonts } as Record<\n TypographyAssignment,\n TypographyFont\n >\n if (input.fonts !== undefined) {\n record(input.fonts, 'typography.fonts')\n keys(input.fonts, assignments, 'typography.fonts')\n for (const key of assignments) {\n const font = input.fonts[key]\n if (font === undefined) continue\n record(font, `typography.fonts.${key}`)\n keys(font, ['family', 'profile'], `typography.fonts.${key}`)\n if (\n typeof font.family !== 'string' ||\n !font.family.trim() ||\n /[;{}@]|url\\s*\\(/i.test(font.family) ||\n [...font.family].some(\n character => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127\n )\n )\n throw new TypeError(`typography.fonts.${key}.family must be a CSS font-family list.`)\n if (font.profile !== undefined && !profiles.includes(font.profile))\n throw new TypeError(`Unknown typography.fonts.${key}.profile.`)\n fonts[key] = { family: font.family, profile: font.profile ?? 'manual' }\n }\n }\n const manualProse = input.prose === undefined ? {} : input.prose,\n manualUI = input.ui === undefined ? {} : input.ui\n metrics(\n manualProse,\n {\n size: [12, 40],\n lineHeight: [1, 3],\n paragraphSpacing: [0, 4],\n measure: [20, 120],\n headingScale: [1.1, 1.5]\n },\n 'typography.prose'\n )\n metrics(manualUI, { size: [12, 32], lineHeight: [1, 3] }, 'typography.ui')\n const profile = bodyProfiles[fonts.body.profile ?? 'manual']\n const prose: TypographyProseRhythm = {\n size: profile?.[0] ?? 20,\n lineHeight: profile?.[1] ?? 1.65,\n measure: profile?.[2] ?? 64,\n paragraphSpacing: 1.25,\n headingScale: 1.25,\n ...defined(manualProse)\n }\n const ui = { size: 16, lineHeight: 1.5, ...defined(manualUI) }\n const styles = typographyStyles(prose, ui)\n const overrides = input.styles === undefined ? {} : input.styles\n record(overrides, 'typography.styles')\n keys(overrides, typographyRoles, 'typography.styles')\n for (const role of typographyRoles) {\n const override = overrides[role]\n if (override === undefined) continue\n record(override, `typography.styles.${role}`)\n const { assignment, ...numeric } = override\n if (assignment !== undefined && !assignments.includes(assignment))\n throw new TypeError(`Unknown typography.styles.${role}.assignment.`)\n metrics(\n numeric,\n {\n narrow: [8, 256],\n wide: [8, 512],\n weight: [1, 1000],\n lineHeight: [0.8, 3],\n tracking: [-0.2, 0.5],\n measure: [0, 120]\n },\n `typography.styles.${role}`\n )\n styles[role] = { ...styles[role], ...defined(override) }\n if (styles[role].wide < styles[role].narrow)\n throw new TypeError(`typography.styles.${role}.wide must be at least narrow.`)\n }\n const warnings: TypographyResult['warnings'][number][] = []\n for (const role of typographyRoles) {\n const s = styles[role],\n range = weights[fonts[s.assignment].profile ?? 'manual']\n if (range && (s.weight < range[0] || s.weight > range[1]))\n warnings.push({ role, requestedWeight: s.weight, supportedWeights: range })\n }\n return freezeTree({\n input: {\n preset,\n fonts,\n prose: defined(manualProse),\n ui: defined(manualUI),\n styles: Object.fromEntries(\n Object.entries(overrides)\n .filter(([, v]) => v !== undefined)\n .map(([k, v]) => [k, defined(v!)])\n )\n },\n prose,\n ui,\n styles,\n tokens: typographyTokens(\n styles,\n Object.fromEntries(assignments.map(key => [key, fonts[key].family])) as Record<\n TypographyAssignment,\n string\n >,\n prose.paragraphSpacing\n ),\n recommendations: {\n body: !!profile,\n ui: fonts.ui.profile === 'inter' || fonts.ui.profile === 'plex-sans'\n },\n warnings\n })\n}\nfunction defined<T extends object>(value: T): T {\n return Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined)) as T\n}\n"]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** Stable text styles; presentation is independent of the element's HTML semantics. */
|
|
2
|
+
export type TypographyRole = 'prose-title' | 'prose-heading' | 'prose-subheading' | 'prose-body' | 'prose-lead' | 'prose-small' | 'prose-quote' | 'ui-title' | 'ui-body' | 'ui-label' | 'ui-supporting' | 'ui-caption' | 'ui-metric' | 'ui-eyebrow' | 'display' | 'code';
|
|
3
|
+
export type TypographyAssignment = 'body' | 'headings' | 'ui' | 'code';
|
|
4
|
+
export type TypographyProfile = 'inter' | 'source-serif-4' | 'plex-sans' | 'plex-mono' | 'manual';
|
|
5
|
+
export type TypographyPreset = 'inter' | 'source-serif' | 'plex';
|
|
6
|
+
export interface TypographyFont {
|
|
7
|
+
/** CSS font-family list; choosing it never loads a font. */
|
|
8
|
+
readonly family: string;
|
|
9
|
+
/** Explicit provenance of a studied font. Omitted for an unfamiliar/manual font. */
|
|
10
|
+
readonly profile?: TypographyProfile;
|
|
11
|
+
}
|
|
12
|
+
export interface TypographyProseRhythm {
|
|
13
|
+
/** Reference pixels at a 16px root, emitted as rem. */
|
|
14
|
+
readonly size: number;
|
|
15
|
+
readonly lineHeight: number;
|
|
16
|
+
readonly paragraphSpacing: number;
|
|
17
|
+
readonly measure: number;
|
|
18
|
+
readonly headingScale: number;
|
|
19
|
+
}
|
|
20
|
+
export interface TypographyUIRhythm {
|
|
21
|
+
readonly size: number;
|
|
22
|
+
readonly lineHeight: number;
|
|
23
|
+
}
|
|
24
|
+
export interface TypographyStyle {
|
|
25
|
+
readonly assignment: TypographyAssignment;
|
|
26
|
+
/** Reference pixels at a 16px root. */
|
|
27
|
+
readonly narrow: number;
|
|
28
|
+
readonly wide: number;
|
|
29
|
+
readonly weight: number;
|
|
30
|
+
readonly lineHeight: number;
|
|
31
|
+
/** em; zero is deliberately not the old global negative tracking. */
|
|
32
|
+
readonly tracking: number;
|
|
33
|
+
/** ch; zero means the layout owns measure. */
|
|
34
|
+
readonly measure: number;
|
|
35
|
+
}
|
|
36
|
+
export interface TypographyInput {
|
|
37
|
+
readonly preset?: TypographyPreset;
|
|
38
|
+
readonly fonts?: Readonly<Partial<Record<TypographyAssignment, TypographyFont>>>;
|
|
39
|
+
/** Only manual settings belong here; omission keeps a profile-derived default live. */
|
|
40
|
+
readonly prose?: Partial<TypographyProseRhythm>;
|
|
41
|
+
readonly ui?: Partial<TypographyUIRhythm>;
|
|
42
|
+
readonly styles?: Readonly<Partial<Record<TypographyRole, Partial<TypographyStyle>>>>;
|
|
43
|
+
}
|
|
44
|
+
export interface TypographyRoleTokens {
|
|
45
|
+
readonly family: string;
|
|
46
|
+
readonly size: string;
|
|
47
|
+
readonly fluidSize: string;
|
|
48
|
+
readonly weight: number | string;
|
|
49
|
+
readonly lineHeight: string;
|
|
50
|
+
readonly letterSpacing: string;
|
|
51
|
+
readonly measure: string;
|
|
52
|
+
}
|
|
53
|
+
export interface TypographyTokens {
|
|
54
|
+
readonly roles: Readonly<Record<TypographyRole, TypographyRoleTokens>>;
|
|
55
|
+
readonly flow: {
|
|
56
|
+
readonly paragraph: string;
|
|
57
|
+
readonly headingBefore: string;
|
|
58
|
+
readonly headingAfter: string;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export interface TypographyResult {
|
|
62
|
+
/** Replayable input retains manual/automatic ownership rather than pinning computed defaults. */
|
|
63
|
+
readonly input: TypographyInput;
|
|
64
|
+
readonly prose: TypographyProseRhythm;
|
|
65
|
+
readonly ui: TypographyUIRhythm;
|
|
66
|
+
readonly styles: Readonly<Record<TypographyRole, TypographyStyle>>;
|
|
67
|
+
readonly tokens: TypographyTokens;
|
|
68
|
+
readonly recommendations: {
|
|
69
|
+
readonly body: boolean;
|
|
70
|
+
readonly ui: boolean;
|
|
71
|
+
};
|
|
72
|
+
readonly warnings: readonly {
|
|
73
|
+
readonly role: TypographyRole;
|
|
74
|
+
readonly requestedWeight: number;
|
|
75
|
+
readonly supportedWeights: readonly [number, number];
|
|
76
|
+
}[];
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/typography/types.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,MAAM,MAAM,cAAc,GACtB,aAAa,GACb,eAAe,GACf,kBAAkB,GAClB,YAAY,GACZ,YAAY,GACZ,aAAa,GACb,aAAa,GACb,UAAU,GACV,SAAS,GACT,UAAU,GACV,eAAe,GACf,YAAY,GACZ,WAAW,GACX,YAAY,GACZ,SAAS,GACT,MAAM,CAAA;AAEV,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,UAAU,GAAG,IAAI,GAAG,MAAM,CAAA;AACtE,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,gBAAgB,GAAG,WAAW,GA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AAE,gBAAgB,CAAA;IACjC,QAAQ,CAAC,eAAe,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAA;KAAE,CAAA;IAC1E,QAAQ,CAAC,QAAQ,EAAE,SAAS;QAC1B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;QAC7B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;QAChC,QAAQ,CAAC,gBAAgB,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KACrD,EAAE,CAAA;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/typography/types.ts"],"names":[],"mappings":"","sourcesContent":["/** Stable text styles; presentation is independent of the element's HTML semantics. */\nexport type TypographyRole =\n | 'prose-title'\n | 'prose-heading'\n | 'prose-subheading'\n | 'prose-body'\n | 'prose-lead'\n | 'prose-small'\n | 'prose-quote'\n | 'ui-title'\n | 'ui-body'\n | 'ui-label'\n | 'ui-supporting'\n | 'ui-caption'\n | 'ui-metric'\n | 'ui-eyebrow'\n | 'display'\n | 'code'\n\nexport type TypographyAssignment = 'body' | 'headings' | 'ui' | 'code'\nexport type TypographyProfile = 'inter' | 'source-serif-4' | 'plex-sans' | 'plex-mono' | 'manual'\nexport type TypographyPreset = 'inter' | 'source-serif' | 'plex'\n\nexport interface TypographyFont {\n /** CSS font-family list; choosing it never loads a font. */\n readonly family: string\n /** Explicit provenance of a studied font. Omitted for an unfamiliar/manual font. */\n readonly profile?: TypographyProfile\n}\nexport interface TypographyProseRhythm {\n /** Reference pixels at a 16px root, emitted as rem. */\n readonly size: number\n readonly lineHeight: number\n readonly paragraphSpacing: number\n readonly measure: number\n readonly headingScale: number\n}\nexport interface TypographyUIRhythm {\n readonly size: number\n readonly lineHeight: number\n}\nexport interface TypographyStyle {\n readonly assignment: TypographyAssignment\n /** Reference pixels at a 16px root. */\n readonly narrow: number\n readonly wide: number\n readonly weight: number\n readonly lineHeight: number\n /** em; zero is deliberately not the old global negative tracking. */\n readonly tracking: number\n /** ch; zero means the layout owns measure. */\n readonly measure: number\n}\nexport interface TypographyInput {\n readonly preset?: TypographyPreset\n readonly fonts?: Readonly<Partial<Record<TypographyAssignment, TypographyFont>>>\n /** Only manual settings belong here; omission keeps a profile-derived default live. */\n readonly prose?: Partial<TypographyProseRhythm>\n readonly ui?: Partial<TypographyUIRhythm>\n readonly styles?: Readonly<Partial<Record<TypographyRole, Partial<TypographyStyle>>>>\n}\nexport interface TypographyRoleTokens {\n readonly family: string\n readonly size: string\n readonly fluidSize: string\n readonly weight: number | string\n readonly lineHeight: string\n readonly letterSpacing: string\n readonly measure: string\n}\nexport interface TypographyTokens {\n readonly roles: Readonly<Record<TypographyRole, TypographyRoleTokens>>\n readonly flow: {\n readonly paragraph: string\n readonly headingBefore: string\n readonly headingAfter: string\n }\n}\nexport interface TypographyResult {\n /** Replayable input retains manual/automatic ownership rather than pinning computed defaults. */\n readonly input: TypographyInput\n readonly prose: TypographyProseRhythm\n readonly ui: TypographyUIRhythm\n readonly styles: Readonly<Record<TypographyRole, TypographyStyle>>\n readonly tokens: TypographyTokens\n readonly recommendations: { readonly body: boolean; readonly ui: boolean }\n readonly warnings: readonly {\n readonly role: TypographyRole\n readonly requestedWeight: number\n readonly supportedWeights: readonly [number, number]\n }[]\n}\n"]}
|