@motir/design-system 0.10.1 → 0.12.0

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.
@@ -0,0 +1,222 @@
1
+ /**
2
+ * The Motir FONT-SET REGISTRY: which faces each locale's script is drawn in
3
+ * (Story MOTIR-7733 · Subtask MOTIR-7843).
4
+ *
5
+ * A Type pairing (`./typography.ts`) decides the LATIN faces of the three roles
6
+ * (sans / serif / mono). A font set decides the SCRIPT face that sits BEHIND
7
+ * them, so a ja page draws its Latin in the pairing's face and its kana and
8
+ * kanji in the ja set's face, under every pairing. The two axes are
9
+ * independent: a set never changes which pairing is active, and a pairing never
10
+ * changes which set a locale uses.
11
+ *
12
+ * ── Where the rows come from ────────────────────────────────────────────
13
+ * Every set, member and default below is taken from
14
+ * `docs/typography/font-sets.md` (MOTIR-7841), which read dooooWeb's mapping at
15
+ * `225af77` and filled the roles dooooWeb leaves empty from cited references.
16
+ * `inDooooWeb` carries that document's `in dooooWeb` / `added (not in dooooWeb)`
17
+ * tag. Change a row here only together with that document; the package test
18
+ * holds the two equal.
19
+ *
20
+ * ── What this module is NOT ─────────────────────────────────────────────
21
+ * Data and pure resolvers only. It names CSS custom properties (the contract
22
+ * between the app's `next/font` loader and `theme.css`) but sets none, loads no
23
+ * face, and writes no CSS. Loading stays in the consuming app.
24
+ */
25
+ /** The eleven locales app.motir.co ships in. A closed product decision. */
26
+ declare const FONT_SET_LOCALES: readonly ["en", "zh", "ja", "ko", "de", "fr", "es", "it", "nl", "pl", "pt"];
27
+ /** A locale the font-set registry knows. */
28
+ type FontSetLocale = (typeof FONT_SET_LOCALES)[number];
29
+ /** The three type roles every set covers: the same roles `--font-*` carries. */
30
+ declare const FONT_SET_ROLES: readonly ["sans", "serif", "mono"];
31
+ /** One of the three type roles. */
32
+ type FontSetRole = (typeof FONT_SET_ROLES)[number];
33
+ /**
34
+ * Where a member's face comes from.
35
+ *
36
+ * - `type-pairing`: the active Type pairing's own face for the role. The Latin
37
+ * set's only member; it loads nothing and has no CSS variable.
38
+ * - `next/font/google`: a Google Fonts face the app loads with `next/font`;
39
+ * `googleFamily` is the loader's export name (`Noto_Sans_JP`).
40
+ */
41
+ type FontSetMemberSource = {
42
+ readonly kind: 'type-pairing';
43
+ } | {
44
+ readonly kind: 'next/font/google';
45
+ readonly googleFamily: string;
46
+ };
47
+ /** One selectable face in one role of one set. */
48
+ interface FontSetMember {
49
+ /** Stable kebab-case slug, unique within its role. The value a pick stores. */
50
+ readonly id: string;
51
+ /** The display name, or `null` for the `type-pairing` member. */
52
+ readonly family: string | null;
53
+ readonly source: FontSetMemberSource;
54
+ /** `docs/typography/font-sets.md`'s tag: `in dooooWeb` (true) or `added` (false). */
55
+ readonly inDooooWeb: boolean;
56
+ /**
57
+ * The role whose member of the SAME id this member re-uses the face of. A
58
+ * CJK set's mono role draws its Han glyphs from the set's sans face (the Noto
59
+ * Sans Mono CJK practice, see the doc), so the face is loaded once and both
60
+ * roles read one variable.
61
+ */
62
+ readonly sameFaceAs?: FontSetRole;
63
+ }
64
+ /** One role of one set: its members, and which one a page uses by default. */
65
+ interface FontSetRoleMembers {
66
+ /** The id of the member used when nobody has picked one. */
67
+ readonly default: string;
68
+ readonly members: readonly FontSetMember[];
69
+ }
70
+ /** A locale group's font set. */
71
+ interface FontSet {
72
+ readonly id: string;
73
+ /** Display name for `/tokens` and the picker. */
74
+ readonly label: string;
75
+ /**
76
+ * The BCP 47 tag the set's `:lang()` rule matches. It is the tag the app
77
+ * renders on `<html lang>` (`zh`, not `zh-Hans`), because `:lang(zh)`
78
+ * matches `zh` and `zh-Hans` while `:lang(zh-Hans)` does not match `zh`.
79
+ * `null` for the Latin set, which is matched by its locales instead.
80
+ */
81
+ readonly lang: string | null;
82
+ /** True for a CJK set: its faces are unicode-range sliced and never preloaded. */
83
+ readonly cjk: boolean;
84
+ readonly roles: Readonly<Record<FontSetRole, FontSetRoleMembers>>;
85
+ }
86
+ /**
87
+ * The registry, one entry per set. Ids are the doc's registry ids; dooooWeb's
88
+ * own group names are noted beside each.
89
+ */
90
+ declare const FONT_SET_REGISTRY: {
91
+ readonly latin: {
92
+ readonly id: "latin";
93
+ readonly label: "Latin";
94
+ readonly lang: null;
95
+ readonly cjk: false;
96
+ readonly roles: {
97
+ readonly sans: {
98
+ readonly default: "type-pairing";
99
+ readonly members: readonly [FontSetMember];
100
+ };
101
+ readonly serif: {
102
+ readonly default: "type-pairing";
103
+ readonly members: readonly [FontSetMember];
104
+ };
105
+ readonly mono: {
106
+ readonly default: "type-pairing";
107
+ readonly members: readonly [FontSetMember];
108
+ };
109
+ };
110
+ };
111
+ readonly 'zh-Hans': {
112
+ readonly id: "zh-Hans";
113
+ readonly label: "Simplified Chinese";
114
+ readonly lang: "zh";
115
+ readonly cjk: true;
116
+ readonly roles: {
117
+ readonly sans: {
118
+ readonly default: "noto-sans-sc";
119
+ readonly members: readonly [FontSetMember];
120
+ };
121
+ readonly serif: {
122
+ readonly default: "noto-serif-sc";
123
+ readonly members: readonly [FontSetMember, FontSetMember];
124
+ };
125
+ readonly mono: {
126
+ readonly default: "noto-sans-sc";
127
+ readonly members: readonly [FontSetMember];
128
+ };
129
+ };
130
+ };
131
+ readonly ja: {
132
+ readonly id: "ja";
133
+ readonly label: "Japanese";
134
+ readonly lang: "ja";
135
+ readonly cjk: true;
136
+ readonly roles: {
137
+ readonly sans: {
138
+ readonly default: "noto-sans-jp";
139
+ readonly members: readonly [FontSetMember, FontSetMember];
140
+ };
141
+ readonly serif: {
142
+ readonly default: "noto-serif-jp";
143
+ readonly members: readonly [FontSetMember];
144
+ };
145
+ readonly mono: {
146
+ readonly default: "noto-sans-jp";
147
+ readonly members: readonly [FontSetMember];
148
+ };
149
+ };
150
+ };
151
+ readonly ko: {
152
+ readonly id: "ko";
153
+ readonly label: "Korean";
154
+ readonly lang: "ko";
155
+ readonly cjk: true;
156
+ readonly roles: {
157
+ readonly sans: {
158
+ readonly default: "noto-sans-kr";
159
+ readonly members: readonly [FontSetMember, FontSetMember];
160
+ };
161
+ readonly serif: {
162
+ readonly default: "noto-serif-kr";
163
+ readonly members: readonly [FontSetMember];
164
+ };
165
+ readonly mono: {
166
+ readonly default: "noto-sans-kr";
167
+ readonly members: readonly [FontSetMember];
168
+ };
169
+ };
170
+ };
171
+ };
172
+ /** The id of every registered set. */
173
+ type FontSetId = keyof typeof FONT_SET_REGISTRY;
174
+ /** All set ids, in registry order. */
175
+ declare const FONT_SET_IDS: FontSetId[];
176
+ /** The set an unknown or empty page language falls back to: the app renders it in English. */
177
+ declare const DEFAULT_FONT_SET_ID: FontSetId;
178
+ /** Which set each locale is drawn in (font-sets.md § Locale → set). */
179
+ declare const LOCALE_FONT_SET: {
180
+ readonly en: "latin";
181
+ readonly zh: "zh-Hans";
182
+ readonly ja: "ja";
183
+ readonly ko: "ko";
184
+ readonly de: "latin";
185
+ readonly fr: "latin";
186
+ readonly es: "latin";
187
+ readonly it: "latin";
188
+ readonly nl: "latin";
189
+ readonly pl: "latin";
190
+ readonly pt: "latin";
191
+ };
192
+ /** Narrowing guard: is an arbitrary value one of the eleven locales? */
193
+ declare function isFontSetLocale(value: unknown): value is FontSetLocale;
194
+ /**
195
+ * The set for an `<html lang>` value. Matches the primary subtag
196
+ * case-insensitively (`ja-JP` → ja, `PT-br` → pt, `zh-Hans` → zh).
197
+ *
198
+ * The fallback is explicit: an empty or unknown tag returns the Latin set,
199
+ * because the app renders an unknown language in English. It never falls back
200
+ * to "the nearest CJK set". Use `isFontSetLocale` on the primary subtag to tell
201
+ * a fallback from a match.
202
+ */
203
+ declare function resolveFontSet(lang: string): FontSet;
204
+ /**
205
+ * A member of one role of one set, by id. A missing or unknown id (a stored
206
+ * pick naming a member that has since been removed) returns that role's
207
+ * default, never another set's face.
208
+ */
209
+ declare function resolveFontSetMember(setId: FontSetId, role: FontSetRole, memberId?: string): FontSetMember;
210
+ /**
211
+ * The CSS custom property the app's `next/font` loader assigns to a member's
212
+ * face and `theme.css` reads: `--font-set-<set>-<role>-<member>`. This name is
213
+ * the contract between the registry, the loader and the stylesheet, so it is
214
+ * built here and nowhere else.
215
+ *
216
+ * A member that re-uses another role's face (`sameFaceAs`) returns THAT role's
217
+ * variable, so the face is declared once. The `type-pairing` member, and an id
218
+ * the role does not have, return `null`.
219
+ */
220
+ declare function fontSetMemberVar(setId: FontSetId, role: FontSetRole, memberId: string): string | null;
221
+
222
+ export { DEFAULT_FONT_SET_ID, FONT_SET_IDS, FONT_SET_LOCALES, FONT_SET_REGISTRY, FONT_SET_ROLES, type FontSet, type FontSetId, type FontSetLocale, type FontSetMember, type FontSetMemberSource, type FontSetRole, type FontSetRoleMembers, LOCALE_FONT_SET, fontSetMemberVar, isFontSetLocale, resolveFontSet, resolveFontSetMember };
@@ -0,0 +1,155 @@
1
+ // src/theme/fontSets.ts
2
+ var FONT_SET_LOCALES = [
3
+ "en",
4
+ "zh",
5
+ "ja",
6
+ "ko",
7
+ "de",
8
+ "fr",
9
+ "es",
10
+ "it",
11
+ "nl",
12
+ "pl",
13
+ "pt"
14
+ ];
15
+ var FONT_SET_ROLES = ["sans", "serif", "mono"];
16
+ var TYPE_PAIRING = {
17
+ id: "type-pairing",
18
+ family: null,
19
+ source: { kind: "type-pairing" },
20
+ inDooooWeb: false
21
+ };
22
+ function google(id, family, inDooooWeb, sameFaceAs) {
23
+ return {
24
+ id,
25
+ family,
26
+ source: { kind: "next/font/google", googleFamily: family.replace(/ /g, "_") },
27
+ inDooooWeb,
28
+ ...sameFaceAs ? { sameFaceAs } : {}
29
+ };
30
+ }
31
+ var FONT_SET_REGISTRY = {
32
+ // dooooWeb: `latin`. Its Latin picker faces are deliberately not members:
33
+ // behind the pairing's face they would never draw a glyph (font-sets.md § latin).
34
+ latin: {
35
+ id: "latin",
36
+ label: "Latin",
37
+ lang: null,
38
+ cjk: false,
39
+ roles: {
40
+ sans: { default: "type-pairing", members: [TYPE_PAIRING] },
41
+ serif: { default: "type-pairing", members: [TYPE_PAIRING] },
42
+ mono: { default: "type-pairing", members: [TYPE_PAIRING] }
43
+ }
44
+ },
45
+ // dooooWeb: `chinese-simplified`.
46
+ "zh-Hans": {
47
+ id: "zh-Hans",
48
+ label: "Simplified Chinese",
49
+ lang: "zh",
50
+ cjk: true,
51
+ roles: {
52
+ sans: { default: "noto-sans-sc", members: [google("noto-sans-sc", "Noto Sans SC", false)] },
53
+ serif: {
54
+ default: "noto-serif-sc",
55
+ members: [
56
+ google("noto-serif-sc", "Noto Serif SC", true),
57
+ // Draws Traditional / inherited forms, so never the default (font-sets.md § Region forms).
58
+ google("lxgw-wenkai-tc", "LXGW WenKai TC", true)
59
+ ]
60
+ },
61
+ mono: {
62
+ default: "noto-sans-sc",
63
+ members: [google("noto-sans-sc", "Noto Sans SC", false, "sans")]
64
+ }
65
+ }
66
+ },
67
+ // dooooWeb: `japanese`.
68
+ ja: {
69
+ id: "ja",
70
+ label: "Japanese",
71
+ lang: "ja",
72
+ cjk: true,
73
+ roles: {
74
+ sans: {
75
+ default: "noto-sans-jp",
76
+ members: [
77
+ google("noto-sans-jp", "Noto Sans JP", true),
78
+ google("m-plus-rounded-1c", "M PLUS Rounded 1c", true)
79
+ ]
80
+ },
81
+ serif: {
82
+ default: "noto-serif-jp",
83
+ members: [google("noto-serif-jp", "Noto Serif JP", false)]
84
+ },
85
+ mono: {
86
+ default: "noto-sans-jp",
87
+ members: [google("noto-sans-jp", "Noto Sans JP", false, "sans")]
88
+ }
89
+ }
90
+ },
91
+ // dooooWeb: `korean`.
92
+ ko: {
93
+ id: "ko",
94
+ label: "Korean",
95
+ lang: "ko",
96
+ cjk: true,
97
+ roles: {
98
+ sans: {
99
+ default: "noto-sans-kr",
100
+ members: [
101
+ google("noto-sans-kr", "Noto Sans KR", true),
102
+ google("nanum-gothic", "Nanum Gothic", true)
103
+ ]
104
+ },
105
+ serif: {
106
+ default: "noto-serif-kr",
107
+ members: [google("noto-serif-kr", "Noto Serif KR", false)]
108
+ },
109
+ mono: {
110
+ default: "noto-sans-kr",
111
+ members: [google("noto-sans-kr", "Noto Sans KR", false, "sans")]
112
+ }
113
+ }
114
+ }
115
+ };
116
+ var FONT_SET_IDS = Object.keys(FONT_SET_REGISTRY);
117
+ var DEFAULT_FONT_SET_ID = "latin";
118
+ var LOCALE_FONT_SET = {
119
+ en: "latin",
120
+ zh: "zh-Hans",
121
+ ja: "ja",
122
+ ko: "ko",
123
+ de: "latin",
124
+ fr: "latin",
125
+ es: "latin",
126
+ it: "latin",
127
+ nl: "latin",
128
+ pl: "latin",
129
+ pt: "latin"
130
+ };
131
+ function isFontSetLocale(value) {
132
+ return typeof value === "string" && FONT_SET_LOCALES.includes(value);
133
+ }
134
+ function resolveFontSet(lang) {
135
+ const primary = lang.trim().split(/[-_]/)[0]?.toLowerCase() ?? "";
136
+ const id = isFontSetLocale(primary) ? LOCALE_FONT_SET[primary] : DEFAULT_FONT_SET_ID;
137
+ return FONT_SET_REGISTRY[id];
138
+ }
139
+ function resolveFontSetMember(setId, role, memberId) {
140
+ const r = FONT_SET_REGISTRY[setId].roles[role];
141
+ const named = memberId === void 0 ? void 0 : r.members.find((m) => m.id === memberId);
142
+ return named ?? r.members.find((m) => m.id === r.default);
143
+ }
144
+ function fontSetMemberVar(setId, role, memberId) {
145
+ const member = FONT_SET_REGISTRY[setId].roles[role].members.find(
146
+ (m) => m.id === memberId
147
+ );
148
+ if (!member || member.source.kind === "type-pairing") return null;
149
+ const faceRole = member.sameFaceAs ?? role;
150
+ return `--font-set-${setId}-${faceRole}-${member.id}`;
151
+ }
152
+
153
+ export { DEFAULT_FONT_SET_ID, FONT_SET_IDS, FONT_SET_LOCALES, FONT_SET_REGISTRY, FONT_SET_ROLES, LOCALE_FONT_SET, fontSetMemberVar, isFontSetLocale, resolveFontSet, resolveFontSetMember };
154
+ //# sourceMappingURL=fontSets.js.map
155
+ //# sourceMappingURL=fontSets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/theme/fontSets.ts"],"names":[],"mappings":";AA0BO,IAAM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EAAA,OAAO,cAAc,KAAK,CAAA,CAAA,EAAI,QAAQ,CAAA,CAAA,EAAI,OAAO,EAAE,CAAA,CAAA;AACrD","file":"fontSets.js","sourcesContent":["/**\n * The Motir FONT-SET REGISTRY: which faces each locale's script is drawn in\n * (Story MOTIR-7733 · Subtask MOTIR-7843).\n *\n * A Type pairing (`./typography.ts`) decides the LATIN faces of the three roles\n * (sans / serif / mono). A font set decides the SCRIPT face that sits BEHIND\n * them, so a ja page draws its Latin in the pairing's face and its kana and\n * kanji in the ja set's face, under every pairing. The two axes are\n * independent: a set never changes which pairing is active, and a pairing never\n * changes which set a locale uses.\n *\n * ── Where the rows come from ────────────────────────────────────────────\n * Every set, member and default below is taken from\n * `docs/typography/font-sets.md` (MOTIR-7841), which read dooooWeb's mapping at\n * `225af77` and filled the roles dooooWeb leaves empty from cited references.\n * `inDooooWeb` carries that document's `in dooooWeb` / `added (not in dooooWeb)`\n * tag. Change a row here only together with that document; the package test\n * holds the two equal.\n *\n * ── What this module is NOT ─────────────────────────────────────────────\n * Data and pure resolvers only. It names CSS custom properties (the contract\n * between the app's `next/font` loader and `theme.css`) but sets none, loads no\n * face, and writes no CSS. Loading stays in the consuming app.\n */\n\n/** The eleven locales app.motir.co ships in. A closed product decision. */\nexport const FONT_SET_LOCALES = [\n 'en',\n 'zh',\n 'ja',\n 'ko',\n 'de',\n 'fr',\n 'es',\n 'it',\n 'nl',\n 'pl',\n 'pt',\n] as const;\n\n/** A locale the font-set registry knows. */\nexport type FontSetLocale = (typeof FONT_SET_LOCALES)[number];\n\n/** The three type roles every set covers: the same roles `--font-*` carries. */\nexport const FONT_SET_ROLES = ['sans', 'serif', 'mono'] as const;\n\n/** One of the three type roles. */\nexport type FontSetRole = (typeof FONT_SET_ROLES)[number];\n\n/**\n * Where a member's face comes from.\n *\n * - `type-pairing`: the active Type pairing's own face for the role. The Latin\n * set's only member; it loads nothing and has no CSS variable.\n * - `next/font/google`: a Google Fonts face the app loads with `next/font`;\n * `googleFamily` is the loader's export name (`Noto_Sans_JP`).\n */\nexport type FontSetMemberSource =\n | { readonly kind: 'type-pairing' }\n | { readonly kind: 'next/font/google'; readonly googleFamily: string };\n\n/** One selectable face in one role of one set. */\nexport interface FontSetMember {\n /** Stable kebab-case slug, unique within its role. The value a pick stores. */\n readonly id: string;\n /** The display name, or `null` for the `type-pairing` member. */\n readonly family: string | null;\n readonly source: FontSetMemberSource;\n /** `docs/typography/font-sets.md`'s tag: `in dooooWeb` (true) or `added` (false). */\n readonly inDooooWeb: boolean;\n /**\n * The role whose member of the SAME id this member re-uses the face of. A\n * CJK set's mono role draws its Han glyphs from the set's sans face (the Noto\n * Sans Mono CJK practice, see the doc), so the face is loaded once and both\n * roles read one variable.\n */\n readonly sameFaceAs?: FontSetRole;\n}\n\n/** One role of one set: its members, and which one a page uses by default. */\nexport interface FontSetRoleMembers {\n /** The id of the member used when nobody has picked one. */\n readonly default: string;\n readonly members: readonly FontSetMember[];\n}\n\n/** A locale group's font set. */\nexport interface FontSet {\n readonly id: string;\n /** Display name for `/tokens` and the picker. */\n readonly label: string;\n /**\n * The BCP 47 tag the set's `:lang()` rule matches. It is the tag the app\n * renders on `<html lang>` (`zh`, not `zh-Hans`), because `:lang(zh)`\n * matches `zh` and `zh-Hans` while `:lang(zh-Hans)` does not match `zh`.\n * `null` for the Latin set, which is matched by its locales instead.\n */\n readonly lang: string | null;\n /** True for a CJK set: its faces are unicode-range sliced and never preloaded. */\n readonly cjk: boolean;\n readonly roles: Readonly<Record<FontSetRole, FontSetRoleMembers>>;\n}\n\nconst TYPE_PAIRING: FontSetMember = {\n id: 'type-pairing',\n family: null,\n source: { kind: 'type-pairing' },\n inDooooWeb: false,\n};\n\nfunction google(\n id: string,\n family: string,\n inDooooWeb: boolean,\n sameFaceAs?: FontSetRole,\n): FontSetMember {\n return {\n id,\n family,\n source: { kind: 'next/font/google', googleFamily: family.replace(/ /g, '_') },\n inDooooWeb,\n ...(sameFaceAs ? { sameFaceAs } : {}),\n };\n}\n\n/**\n * The registry, one entry per set. Ids are the doc's registry ids; dooooWeb's\n * own group names are noted beside each.\n */\nexport const FONT_SET_REGISTRY = {\n // dooooWeb: `latin`. Its Latin picker faces are deliberately not members:\n // behind the pairing's face they would never draw a glyph (font-sets.md § latin).\n latin: {\n id: 'latin',\n label: 'Latin',\n lang: null,\n cjk: false,\n roles: {\n sans: { default: 'type-pairing', members: [TYPE_PAIRING] },\n serif: { default: 'type-pairing', members: [TYPE_PAIRING] },\n mono: { default: 'type-pairing', members: [TYPE_PAIRING] },\n },\n },\n // dooooWeb: `chinese-simplified`.\n 'zh-Hans': {\n id: 'zh-Hans',\n label: 'Simplified Chinese',\n lang: 'zh',\n cjk: true,\n roles: {\n sans: { default: 'noto-sans-sc', members: [google('noto-sans-sc', 'Noto Sans SC', false)] },\n serif: {\n default: 'noto-serif-sc',\n members: [\n google('noto-serif-sc', 'Noto Serif SC', true),\n // Draws Traditional / inherited forms, so never the default (font-sets.md § Region forms).\n google('lxgw-wenkai-tc', 'LXGW WenKai TC', true),\n ],\n },\n mono: {\n default: 'noto-sans-sc',\n members: [google('noto-sans-sc', 'Noto Sans SC', false, 'sans')],\n },\n },\n },\n // dooooWeb: `japanese`.\n ja: {\n id: 'ja',\n label: 'Japanese',\n lang: 'ja',\n cjk: true,\n roles: {\n sans: {\n default: 'noto-sans-jp',\n members: [\n google('noto-sans-jp', 'Noto Sans JP', true),\n google('m-plus-rounded-1c', 'M PLUS Rounded 1c', true),\n ],\n },\n serif: {\n default: 'noto-serif-jp',\n members: [google('noto-serif-jp', 'Noto Serif JP', false)],\n },\n mono: {\n default: 'noto-sans-jp',\n members: [google('noto-sans-jp', 'Noto Sans JP', false, 'sans')],\n },\n },\n },\n // dooooWeb: `korean`.\n ko: {\n id: 'ko',\n label: 'Korean',\n lang: 'ko',\n cjk: true,\n roles: {\n sans: {\n default: 'noto-sans-kr',\n members: [\n google('noto-sans-kr', 'Noto Sans KR', true),\n google('nanum-gothic', 'Nanum Gothic', true),\n ],\n },\n serif: {\n default: 'noto-serif-kr',\n members: [google('noto-serif-kr', 'Noto Serif KR', false)],\n },\n mono: {\n default: 'noto-sans-kr',\n members: [google('noto-sans-kr', 'Noto Sans KR', false, 'sans')],\n },\n },\n },\n} as const satisfies Record<string, FontSet>;\n\n/** The id of every registered set. */\nexport type FontSetId = keyof typeof FONT_SET_REGISTRY;\n\n/** All set ids, in registry order. */\nexport const FONT_SET_IDS = Object.keys(FONT_SET_REGISTRY) as FontSetId[];\n\n/** The set an unknown or empty page language falls back to: the app renders it in English. */\nexport const DEFAULT_FONT_SET_ID: FontSetId = 'latin';\n\n/** Which set each locale is drawn in (font-sets.md § Locale → set). */\nexport const LOCALE_FONT_SET = {\n en: 'latin',\n zh: 'zh-Hans',\n ja: 'ja',\n ko: 'ko',\n de: 'latin',\n fr: 'latin',\n es: 'latin',\n it: 'latin',\n nl: 'latin',\n pl: 'latin',\n pt: 'latin',\n} as const satisfies Record<FontSetLocale, FontSetId>;\n\n/** Narrowing guard: is an arbitrary value one of the eleven locales? */\nexport function isFontSetLocale(value: unknown): value is FontSetLocale {\n return typeof value === 'string' && (FONT_SET_LOCALES as readonly string[]).includes(value);\n}\n\n/**\n * The set for an `<html lang>` value. Matches the primary subtag\n * case-insensitively (`ja-JP` → ja, `PT-br` → pt, `zh-Hans` → zh).\n *\n * The fallback is explicit: an empty or unknown tag returns the Latin set,\n * because the app renders an unknown language in English. It never falls back\n * to \"the nearest CJK set\". Use `isFontSetLocale` on the primary subtag to tell\n * a fallback from a match.\n */\nexport function resolveFontSet(lang: string): FontSet {\n const primary = lang.trim().split(/[-_]/)[0]?.toLowerCase() ?? '';\n const id = isFontSetLocale(primary) ? LOCALE_FONT_SET[primary] : DEFAULT_FONT_SET_ID;\n return FONT_SET_REGISTRY[id];\n}\n\n/**\n * A member of one role of one set, by id. A missing or unknown id (a stored\n * pick naming a member that has since been removed) returns that role's\n * default, never another set's face.\n */\nexport function resolveFontSetMember(\n setId: FontSetId,\n role: FontSetRole,\n memberId?: string,\n): FontSetMember {\n const r: FontSetRoleMembers = FONT_SET_REGISTRY[setId].roles[role];\n const named = memberId === undefined ? undefined : r.members.find((m) => m.id === memberId);\n return named ?? r.members.find((m) => m.id === r.default)!;\n}\n\n/**\n * The CSS custom property the app's `next/font` loader assigns to a member's\n * face and `theme.css` reads: `--font-set-<set>-<role>-<member>`. This name is\n * the contract between the registry, the loader and the stylesheet, so it is\n * built here and nowhere else.\n *\n * A member that re-uses another role's face (`sameFaceAs`) returns THAT role's\n * variable, so the face is declared once. The `type-pairing` member, and an id\n * the role does not have, return `null`.\n */\nexport function fontSetMemberVar(\n setId: FontSetId,\n role: FontSetRole,\n memberId: string,\n): string | null {\n const member = FONT_SET_REGISTRY[setId].roles[role].members.find(\n (m: FontSetMember) => m.id === memberId,\n );\n if (!member || member.source.kind === 'type-pairing') return null;\n const faceRole = member.sameFaceAs ?? role;\n return `--font-set-${setId}-${faceRole}-${member.id}`;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@motir/design-system",
3
- "version": "0.10.1",
3
+ "version": "0.12.0",
4
4
  "description": "Motir's 3-axis design system (colour · style · type): distributable token CSS, the axis registries, the theme-apply API, and framework-agnostic React primitives. Shared by motir-core and planner-scaffolded products.",
5
5
  "license": "GPL-3.0-only",
6
6
  "repository": {
@@ -66,6 +66,6 @@
66
66
  "happy-dom": "^20.9.0",
67
67
  "tsup": "^8.5.0",
68
68
  "typescript": "^5",
69
- "vitest": "^4.1.7"
69
+ "vitest": "^4.1.11"
70
70
  }
71
71
  }