@eifi1/ui-kit 0.27.1 → 0.28.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +7 -5
  2. package/dist/chart.d.ts +1 -2
  3. package/dist/components/amount-input.d.ts +1 -2
  4. package/dist/components/button-group.d.ts +1 -2
  5. package/dist/components/calculator.d.ts +1 -2
  6. package/dist/components/confirm-dialog.d.ts +1 -2
  7. package/dist/components/copy-button.d.ts +1 -2
  8. package/dist/components/danger-confirm.d.ts +1 -2
  9. package/dist/components/facing-pair.d.ts +1 -2
  10. package/dist/components/file-button.d.ts +1 -2
  11. package/dist/components/file-dropzone.d.ts +1 -2
  12. package/dist/components/form-actions.d.ts +1 -2
  13. package/dist/components/iban-input.d.ts +1 -2
  14. package/dist/components/language-select.d.ts +1 -2
  15. package/dist/components/legal-page.d.ts +267 -0
  16. package/dist/components/legal-page.js +272 -0
  17. package/dist/components/legal-page.js.map +1 -0
  18. package/dist/components/legal.d.ts +70 -87
  19. package/dist/components/legal.js +232 -11
  20. package/dist/components/legal.js.map +1 -1
  21. package/dist/components/money-field.d.ts +1 -2
  22. package/dist/components/number-field.d.ts +1 -2
  23. package/dist/components/number-input.d.ts +1 -2
  24. package/dist/components/numpad-sheet.d.ts +1 -2
  25. package/dist/components/phone-input.d.ts +1 -2
  26. package/dist/components/series-chart.d.ts +1 -2
  27. package/dist/components/settings-fields.d.ts +1 -2
  28. package/dist/components/share-card.d.ts +1 -2
  29. package/dist/components/text-link.d.ts +1 -2
  30. package/dist/components/time-input.d.ts +1 -2
  31. package/dist/components/translation-review.d.ts +2 -1
  32. package/dist/components/translation-review.js.map +1 -1
  33. package/dist/components/ui.d.ts +1 -2
  34. package/dist/feedback/feedback-attachment.d.ts +1 -2
  35. package/dist/feedback/feedback-context.d.ts +1 -2
  36. package/dist/feedback/feedback-crash.d.ts +1 -2
  37. package/dist/feedback/feedback-dialog.d.ts +1 -2
  38. package/dist/feedback/feedback-inbox.d.ts +1 -2
  39. package/dist/feedback/feedback-labels.d.ts +1 -2
  40. package/dist/feedback/feedback-menu.d.ts +1 -2
  41. package/dist/feedback/feedback-record.d.ts +1 -2
  42. package/dist/feedback/feedback-row-detail.d.ts +1 -2
  43. package/dist/feedback/feedback-status-undo.d.ts +1 -2
  44. package/dist/feedback/feedback-submit.d.ts +1 -2
  45. package/dist/feedback/feedback-swipe.d.ts +1 -2
  46. package/dist/feedback/feedback-table.d.ts +1 -2
  47. package/dist/feedback/feedback-thread.d.ts +1 -2
  48. package/dist/feedback.d.ts +1 -2
  49. package/dist/hooks/use-file-drop.d.ts +1 -2
  50. package/dist/hooks/use-noindex.d.ts +26 -0
  51. package/dist/hooks/use-noindex.js +18 -0
  52. package/dist/hooks/use-noindex.js.map +1 -0
  53. package/dist/i18n/defaults.d.ts +1 -2
  54. package/dist/i18n/german.d.ts +1 -2
  55. package/dist/i18n/german.js +95 -1
  56. package/dist/i18n/german.js.map +1 -1
  57. package/dist/i18n/kit-labels.d.ts +1 -2
  58. package/dist/i18n/kit-labels.js.map +1 -1
  59. package/dist/i18n/languages.d.ts +1 -2
  60. package/dist/i18n/locales/de-CH.d.ts +1 -2
  61. package/dist/i18n/locales/en.d.ts +1 -2
  62. package/dist/i18n/locales/es.d.ts +1 -2
  63. package/dist/i18n/locales/es.js +95 -1
  64. package/dist/i18n/locales/es.js.map +1 -1
  65. package/dist/i18n/locales/fr.d.ts +1 -2
  66. package/dist/i18n/locales/fr.js +97 -1
  67. package/dist/i18n/locales/fr.js.map +1 -1
  68. package/dist/i18n/locales/hu.d.ts +1 -2
  69. package/dist/i18n/locales/hu.js +98 -1
  70. package/dist/i18n/locales/hu.js.map +1 -1
  71. package/dist/i18n/locales/it.d.ts +1 -2
  72. package/dist/i18n/locales/it.js +98 -1
  73. package/dist/i18n/locales/it.js.map +1 -1
  74. package/dist/i18n/locales/zh.d.ts +1 -2
  75. package/dist/i18n/locales/zh.js +95 -1
  76. package/dist/i18n/locales/zh.js.map +1 -1
  77. package/dist/i18n/review.d.ts +24 -5
  78. package/dist/i18n/review.js +26 -3
  79. package/dist/i18n/review.js.map +1 -1
  80. package/dist/index.d.ts +5 -4
  81. package/dist/index.js +23 -1
  82. package/dist/index.js.map +1 -1
  83. package/dist/{kit-labels-DQg82eHB.d.ts → kit-labels-Du0uHBq4.d.ts} +342 -4
  84. package/dist/lib/translation-review.d.ts +26 -3
  85. package/dist/lib/translation-review.js +10 -2
  86. package/dist/lib/translation-review.js.map +1 -1
  87. package/dist/rhf/fields.d.ts +1 -2
  88. package/dist/rhf/form.d.ts +1 -2
  89. package/dist/rhf.d.ts +1 -2
  90. package/dist/shell/app-shell.d.ts +1 -2
  91. package/dist/shell/top-bar-brand.d.ts +1 -2
  92. package/dist/shell.d.ts +1 -2
  93. package/dist/wizard/stepper-nav.d.ts +1 -2
  94. package/dist/wizard.d.ts +1 -2
  95. package/package.json +1 -1
  96. package/src/components/legal-page.tsx +601 -0
  97. package/src/components/legal.tsx +540 -46
  98. package/src/components/translation-review.tsx +2 -1
  99. package/src/hooks/use-noindex.ts +37 -0
  100. package/src/i18n/german.ts +91 -0
  101. package/src/i18n/kit-labels.tsx +4 -1
  102. package/src/i18n/locales/es.ts +91 -0
  103. package/src/i18n/locales/fr.ts +93 -0
  104. package/src/i18n/locales/hu.ts +94 -0
  105. package/src/i18n/locales/it.ts +94 -0
  106. package/src/i18n/locales/zh.ts +91 -0
  107. package/src/i18n/review.ts +57 -3
  108. package/src/index.ts +41 -2
  109. package/src/lib/translation-review.ts +43 -4
@@ -1,48 +1,433 @@
1
- import type { ReactNode } from "react";
1
+ import { createContext, useContext } from "react";
2
+ import type { MouseEvent, ReactNode } from "react";
2
3
 
3
4
  import { useKitLabels } from "../i18n/kit-labels";
5
+ import type { LabelOverride } from "../i18n/kit-labels";
4
6
  import { cn } from "../lib/cn";
7
+ import { countryName } from "../lib/countries";
5
8
  import { AlertBanner } from "./alert-banner";
6
9
  import { TextLink } from "./text-link";
7
10
 
8
11
  /**
9
- * The legal pages' shell — Imprint, Privacy Policy, Terms — for every app (Marcel,
10
- * 2026-10-02: every app has them; docs/i18n-harmonization.md H10).
12
+ * The legal pages — Imprint, Privacy Policy, Terms — for every app.
11
13
  *
12
- * keksdose and kastlan each carried the same shell, written twice: a back link, the
13
- * title, a "closed beta, not yet reviewed by a lawyer" notice, sections of heading +
14
- * running text, and kastlan's row of links to the three pages with the current one
15
- * marked. Kurvenschmiede had none. The words stay in each app — they are the app's
16
- * legal statements, reviewed under the `legal` area of the translation review — and
17
- * only the shape moves here.
14
+ * 0.19 (docs/i18n-harmonization.md H10): keksdose and kastlan each carried the same
15
+ * shell, written twice: a back link, the title, a "closed beta, not yet reviewed by a
16
+ * lawyer" notice, sections of heading + running text, and kastlan's row of links to the
17
+ * three pages with the current one marked. That shape moved here; the words stayed in
18
+ * each app.
18
19
  *
19
- * A CONTENT COLUMN, not a page: keksdose shows its legal pages inside its public
20
- * landing header and footer, kastlan inside `AuthLayout` (`width="wide" card={false}`,
21
- * no title of its own). Both put this inside their chrome; a page-owning layout would
22
- * have fought one of them.
20
+ * 0.28 (docs/legal-harmonization.md) reverses the second half: the wording that is the
21
+ * same in all three apps is the kit's too, in all seven languages, so there is ONE text
22
+ * to change after the lawyer's review instead of three apps drifting apart sentence by
23
+ * sentence. This module holds the labels (every kit-owned legal word, §4.3/§4.4), the
24
+ * column (`LegalLayout`), the section (`LegalSection`, now numbered and cross-referenced
25
+ * inside a `LegalPage`), the links row and the public footer. The page frame, the
26
+ * kit-owned sections and the terms checkbox are in `./legal-page`.
27
+ *
28
+ * `LegalLayout` stays a CONTENT COLUMN, not a page: before 0.28 keksdose showed it inside
29
+ * its public landing header and footer and kastlan inside `AuthLayout`. `LegalPage` is
30
+ * the frame around it that the contract (§3.2) settled on — keksdose's.
31
+ */
32
+
33
+ // ── The operator ──────────────────────────────────────────────────────────────
34
+
35
+ /** The three pages, by the key every app uses for them (§4.1). Kurvenschmiede's
36
+ * `imprint` became `impressum`. */
37
+ export type LegalPageKey = "impressum" | "privacy" | "terms";
38
+
39
+ /** The three routes (§3.1): one per page, the language from i18n, no per-language URLs. */
40
+ export const LEGAL_HREFS: Readonly<Record<LegalPageKey, string>> = Object.freeze({
41
+ impressum: "/impressum",
42
+ privacy: "/privacy",
43
+ terms: "/terms",
44
+ });
45
+
46
+ /**
47
+ * Who runs the app — the values the kit's legal sections are filled in with (§5).
48
+ *
49
+ * The kit holds NO personal data: every app passes the same values once, to
50
+ * {@link LegalPage}'s `operator`. Plain strings, so the app's config or env can hold them.
51
+ */
52
+ export interface LegalOperator {
53
+ /** The operator's name, as the imprint prints it. */
54
+ name: string;
55
+ /** "9470"-shaped; printed before the city. */
56
+ postalCode: string;
57
+ /** The place — the imprint's address line and the terms' place of jurisdiction. */
58
+ city: string;
59
+ /** The canton or state, abbreviated as the place of jurisdiction writes it: "SG". */
60
+ region: string;
61
+ /**
62
+ * ISO 3166-1 alpha-2: "CH". A CODE, not a name — the kit names it in the page's
63
+ * language (`Intl.DisplayNames`, see `countryName`), so "Switzerland", "Schweiz",
64
+ * "Suisse" and "瑞士" all come from one value.
65
+ */
66
+ country: string;
67
+ /** The contact address the imprint and the privacy policy print. */
68
+ email: string;
69
+ /**
70
+ * The language whose version of the legal texts is BINDING ("de-CH"), a BCP 47 code
71
+ * (0.28.1, Marcel 2026-10-05). The lawyer reviews that one; the others are translations
72
+ * for convenience. With it, {@link LegalPage} shows a note on every page read in
73
+ * another language, and the terms' `language` section says which version prevails.
74
+ * Only the language subtag counts: "de-CH" and "de" are the same language here.
75
+ */
76
+ bindingLanguage?: string;
77
+ }
78
+
79
+ /**
80
+ * The operator as the kit's texts read it: {@link LegalOperator} with `country` already
81
+ * NAMED in the page's language ("Schweiz", not "CH").
82
+ *
83
+ * The label functions take this rather than the code so they stay pure string functions
84
+ * of plain values, like every other function label in the kit: a catalogue never calls
85
+ * `Intl`, and a review row can be rendered from placeholders (`{{country}}`).
23
86
  */
87
+ export type LegalOperatorText = Readonly<Record<keyof LegalOperator, string>>;
88
+
89
+ /** The language subtag of a BCP 47 code, lower-cased: "de-CH" → "de". */
90
+ export function baseLanguage(code: string): string {
91
+ return code.split(/[-_]/)[0]!.toLowerCase();
92
+ }
93
+
94
+ const languageNamers = new Map<string, Intl.DisplayNames | null>();
95
+
96
+ /** The name of a language in `locale` — "Deutsch", "German", "allemand", "德语" — from its
97
+ * language subtag, so "de-CH" is plain "German", not "Swiss High German". The code itself
98
+ * when the runtime cannot name it. */
99
+ function languageName(code: string, locale: string): string {
100
+ let namer = languageNamers.get(locale);
101
+ if (namer === undefined) {
102
+ try {
103
+ namer = new Intl.DisplayNames([locale], { type: "language" });
104
+ } catch {
105
+ namer = null;
106
+ }
107
+ languageNamers.set(locale, namer);
108
+ }
109
+ const base = baseLanguage(code);
110
+ try {
111
+ return namer?.of(base) ?? base;
112
+ } catch {
113
+ return base;
114
+ }
115
+ }
116
+
117
+ /** @internal The operator as the texts read it: its country named in `locale` (English
118
+ * without one — `countryName`'s rule, so an app that set no locale reads English). */
119
+ export function legalOperatorText(operator: LegalOperator, locale: string = "en"): LegalOperatorText {
120
+ return {
121
+ ...operator,
122
+ country: countryName(operator.country, locale),
123
+ bindingLanguage: operator.bindingLanguage ? languageName(operator.bindingLanguage, locale) : "",
124
+ };
125
+ }
24
126
 
25
127
  // ── Labels ────────────────────────────────────────────────────────────────────
26
128
 
129
+ /** A kit section whose text is fixed: a heading and one body. */
130
+ export interface LegalTextSectionLabels {
131
+ title: string;
132
+ body: string;
133
+ }
134
+
135
+ /** A kit section whose text names the operator (§4.3 `{name}`, `{email}`, …). */
136
+ export interface LegalOperatorSectionLabels {
137
+ title: string;
138
+ /** Called with the operator, its country already named in the page's language. Line
139
+ * breaks are kept (`white-space: pre-line`): an address is plain lines. */
140
+ body: (operator: LegalOperatorText) => string;
141
+ }
142
+
143
+ /** A kit section with an app slot (or a list) between its two parts. */
144
+ export interface LegalFramedSectionLabels {
145
+ title: string;
146
+ /** Before the app's part. */
147
+ lead: string;
148
+ /** After it. */
149
+ tail: string;
150
+ }
151
+
152
+ /**
153
+ * Every word of the legal pages that is the kit's — docs/legal-harmonization.md §4.3 and
154
+ * §4.4, verbatim. English, British spelling; the other six languages are in the
155
+ * catalogues (`@eifi1/ui-kit/i18n/<code>`).
156
+ *
157
+ * Keys follow the contract: `sections.<page>.<section key>`, the section keys being
158
+ * keksdose's (`legal_basis`, not `legalBasis`), because the same key is the section's
159
+ * `id` (`/privacy#legal_basis`) and the app's own sections sit beside these under the
160
+ * same names in its catalogue. Titles carry NO number: {@link LegalPage} numbers the
161
+ * privacy and terms sections in render order (§4.1).
162
+ */
27
163
  export interface LegalLabels {
28
- /** The accessible name of {@link LegalLinks}' `<nav>`. */
164
+ /** The accessible name of {@link LegalLinks}' and {@link LegalFooter}'s `<nav>`. */
29
165
  navLabel: string;
166
+ /** The short labels of the three links, everywhere the links appear (§3.3). */
167
+ links: Record<LegalPageKey, string>;
168
+ /** The pages' titles — the `<h1>`, and the links of the terms checkbox. */
169
+ titles: Record<LegalPageKey, string>;
170
+ /** The back link above the title: "← Back to home". */
171
+ backHome: string;
172
+ /**
173
+ * The terms checkbox (§3.4) — ONE template with `{terms}` and `{privacy}`, which
174
+ * become the links (named with `titles`). Not a prefix plus a joiner: a language puts
175
+ * the links where its grammar wants them, articles included, and nothing is added
176
+ * around a placeholder — Italian elides, "e l’{privacy}", with no space.
177
+ */
178
+ accept: string;
179
+ /** The notice under the title (§3.2): `beta` on the imprint and the terms, `privacy`
180
+ * on the privacy policy. */
181
+ notice: {
182
+ beta: string;
183
+ privacy: string;
184
+ };
185
+ /**
186
+ * 0.28.1: on a page read in another language than the operator's `bindingLanguage` —
187
+ * `note` under the title, `show` on the button that switches to the binding version
188
+ * (when the app passes `onShowBindingLanguage`). `o.bindingLanguage` is the binding
189
+ * language's NAME in the reader's language ("German", "allemand").
190
+ */
191
+ translation: {
192
+ note: (o: LegalOperatorText) => string;
193
+ show: (o: LegalOperatorText) => string;
194
+ };
195
+ /** The kit's sections (§4.3), by page and section key. */
196
+ sections: {
197
+ impressum: {
198
+ operator: LegalOperatorSectionLabels;
199
+ contact: LegalOperatorSectionLabels;
200
+ disclaimer: LegalTextSectionLabels;
201
+ };
202
+ privacy: {
203
+ controller: LegalOperatorSectionLabels;
204
+ /** The app's paragraph follows the body (§4.2): consent, where an app relies on it. */
205
+ legal_basis: LegalTextSectionLabels;
206
+ /** `lead`, then the app's entries as a list, then `tail`, then the app's paragraph. */
207
+ browser: LegalFramedSectionLabels;
208
+ /** `lead` (the rights), then the app's paragraph (export, deletion), then `tail`
209
+ * (the supervisory authorities). */
210
+ rights: LegalFramedSectionLabels;
211
+ contact: LegalOperatorSectionLabels;
212
+ };
213
+ terms: {
214
+ warranty: LegalTextSectionLabels;
215
+ liability: LegalTextSectionLabels;
216
+ changes: LegalTextSectionLabels;
217
+ /** 0.28.1: which language's version prevails — `o.bindingLanguage`, named. */
218
+ language: LegalOperatorSectionLabels;
219
+ /** The place of jurisdiction is the operator's `{city} ({region}), {country}`. */
220
+ law: LegalOperatorSectionLabels;
221
+ };
222
+ };
30
223
  }
31
224
 
32
225
  export const DEFAULT_LEGAL_LABELS: LegalLabels = {
33
226
  navLabel: "Legal",
227
+ links: {
228
+ impressum: "Imprint",
229
+ privacy: "Privacy Policy",
230
+ terms: "Terms",
231
+ },
232
+ titles: {
233
+ impressum: "Imprint",
234
+ privacy: "Privacy Policy",
235
+ terms: "Terms of Service",
236
+ },
237
+ backHome: "Back to home",
238
+ accept: "I accept the {terms} and the {privacy}",
239
+ notice: {
240
+ beta: "Closed beta. These texts have not been reviewed by a lawyer yet and will be before a public launch.",
241
+ privacy:
242
+ "Closed beta. The legal wording below has not been reviewed by a lawyer yet and will be before a public launch. The technical descriptions — what is stored, where, and who can read it — describe what the software actually does today, and are meant to be checked against it.",
243
+ },
244
+ translation: {
245
+ note: (o) =>
246
+ `This is a translation for your convenience. The ${o.bindingLanguage} version is binding.`,
247
+ show: (o) => `Show the ${o.bindingLanguage} version`,
248
+ },
249
+ sections: {
250
+ impressum: {
251
+ operator: {
252
+ title: "Operator",
253
+ body: (o) =>
254
+ `${o.name}\n${o.postalCode} ${o.city}\n${o.country}\n\nThe full postal address is supplied on request to anyone with a legitimate legal interest; write to the contact address below.`,
255
+ },
256
+ contact: {
257
+ title: "Contact",
258
+ body: (o) => `Email: ${o.email}`,
259
+ },
260
+ disclaimer: {
261
+ title: "Liability for content and links",
262
+ body: "This is a private, non-commercial project offered during a closed beta, without warranty. External sites we link to are the responsibility of their respective operators; we have no control over their content.",
263
+ },
264
+ },
265
+ privacy: {
266
+ controller: {
267
+ title: "Controller",
268
+ body: (o) =>
269
+ `The party responsible for processing personal data in this service is:\n${o.name}\n${o.postalCode} ${o.city}, ${o.country}\nEmail: ${o.email}\n\nThe full postal address is supplied on request to data subjects and supervisory authorities.`,
270
+ },
271
+ legal_basis: {
272
+ title: "Legal basis",
273
+ body: "As the operator is based in Switzerland, processing is governed by the Swiss Federal Act on Data Protection (FADP). Where the EU General Data Protection Regulation (GDPR) applies to you, we rely on the performance of a contract to provide the service (Art. 6(1)(b) GDPR) and our legitimate interest in operating and securing it (Art. 6(1)(f) GDPR).",
274
+ },
275
+ browser: {
276
+ title: "What your browser stores",
277
+ lead: "No cookies. The app keeps the following in your browser's storage:",
278
+ tail: "None of it is used to track you. Entries waiting to be sent are sent to us as soon as they can be; everything else stays on your device. All of it disappears when you clear the site's data, and signing out removes the sign-in tokens.",
279
+ },
280
+ rights: {
281
+ title: "Your rights",
282
+ lead: "You have the right to access, rectification, erasure, restriction, data portability and objection.",
283
+ tail: "If you are in Switzerland you may contact the Federal Data Protection and Information Commissioner (FDPIC); if you are in the EU you may lodge a complaint with your local supervisory authority.",
284
+ },
285
+ contact: {
286
+ title: "Contact for data protection",
287
+ body: (o) => `For any privacy request, contact: ${o.email}`,
288
+ },
289
+ },
290
+ terms: {
291
+ warranty: {
292
+ title: "No warranty",
293
+ body: 'The service is provided "as is" and "as available", without warranties of any kind to the extent permitted by law. As a beta it may contain errors, change, or be interrupted at any time — keep your own backups of important data.',
294
+ },
295
+ liability: {
296
+ title: "Limitation of liability",
297
+ body: "To the extent permitted by applicable law, the operator is not liable for any indirect or consequential damage arising from the use of, or inability to use, the service. Nothing here limits liability that cannot be limited by law.",
298
+ },
299
+ changes: {
300
+ title: "Changes to these terms",
301
+ body: "These terms may be updated as the service evolves. Material changes will be announced by email or in the app; continued use after a change means you accept it.",
302
+ },
303
+ language: {
304
+ title: "Language",
305
+ body: (o) =>
306
+ `These terms are written in ${o.bindingLanguage}. Translations into other languages are provided for convenience only; where a translation differs, the ${o.bindingLanguage} version prevails.`,
307
+ },
308
+ law: {
309
+ title: "Governing law",
310
+ body: (o) =>
311
+ `These terms are governed by Swiss law, excluding its conflict-of-laws rules. As far as legally permissible, the place of jurisdiction is ${o.city} (${o.region}), ${o.country}.`,
312
+ },
313
+ },
314
+ },
34
315
  };
35
316
 
317
+ /** The `legal` namespace, resolved: defaults < provider < `labels` prop. The prop may be
318
+ * partial at every depth (`{ titles: { terms: "…" } }`), as the provider's is. */
319
+ export function useLegalLabels(labels?: LabelOverride<LegalLabels>): LegalLabels {
320
+ return useKitLabels("legal", DEFAULT_LEGAL_LABELS, labels as Partial<LegalLabels> | undefined);
321
+ }
322
+
323
+ // ── What a LegalPage tells the sections inside it ─────────────────────────────
324
+
325
+ /** Where a `{ref:key}` points: the section's number on a numbered page, else its heading. */
326
+ export interface LegalRefTarget {
327
+ number?: number;
328
+ heading: ReactNode;
329
+ }
330
+
331
+ /** @internal Set by `LegalPage` around its column; `null` outside one. */
332
+ export interface LegalPageContextValue {
333
+ page: LegalPageKey;
334
+ /** The operator with its country named — what the kit sections are filled in with. */
335
+ operator: LegalOperatorText;
336
+ /** The heading level of a section that does not choose one: one below the title. */
337
+ sectionHeading: "h2" | "h3";
338
+ /** Every section's key, in render order — known BEFORE any section renders, so a
339
+ * reference can point forward (keksdose's section 2 refers to section 10). */
340
+ targets: ReadonlyMap<string, LegalRefTarget>;
341
+ }
342
+
343
+ /** @internal */
344
+ export const LegalPageContext = createContext<LegalPageContextValue | null>(null);
345
+
346
+ /** @internal The place `LegalPage` gave one section: its key and its number. Reset to
347
+ * `null` inside a section, so a section nested in another's children takes neither. */
348
+ export interface LegalSectionSlot {
349
+ id?: string;
350
+ number?: number;
351
+ }
352
+
353
+ /** @internal */
354
+ export const LegalSlotContext = createContext<LegalSectionSlot | null>(null);
355
+
356
+ /** @internal `{ref:retention}`. A key is a section key: letters, digits, `_` and `-`. */
357
+ const REF_TOKEN = /\{ref:([A-Za-z0-9_-]+)\}/g;
358
+
359
+ /**
360
+ * A development build's console note — never in production (the consumer's bundler
361
+ * makes `import.meta.env.DEV` false) and never under vitest. Optional-chained:
362
+ * `import.meta.env` is a Vite injection, absent under plain Node.
363
+ */
364
+ function devWarnings(): boolean {
365
+ return Boolean(import.meta.env?.DEV) && !import.meta.env?.VITEST;
366
+ }
367
+ const warned = new Set<string>();
368
+ /** @internal Once per message. */
369
+ export function warnLegalOnce(message: string): void {
370
+ if (!devWarnings() || warned.has(message)) return;
371
+ warned.add(message);
372
+ console.warn(`[ui-kit] ${message}`);
373
+ }
374
+
375
+ /**
376
+ * `text` with every `{ref:key}` replaced by a link to `#key` that reads the section's
377
+ * number — the words around it stay the app's ("see section {ref:retention}", "siehe
378
+ * Abschnitt {ref:retention}"), so each language keeps its grammar (§4.1). On the imprint,
379
+ * which is not numbered, the link reads the section's heading instead.
380
+ *
381
+ * Outside a {@link LegalPage} the text is returned as it is: there is no order to count.
382
+ * A key the page has no section for stays visible as the raw token — a broken reference
383
+ * an app test can find (`not.toHaveTextContent("{ref:")`), not a silently wrong number.
384
+ */
385
+ export function resolveLegalRefs(text: string, page: LegalPageContextValue | null): ReactNode {
386
+ if (!page || !text.includes("{ref:")) return text;
387
+ const out: ReactNode[] = [];
388
+ let last = 0;
389
+ for (const match of text.matchAll(REF_TOKEN)) {
390
+ const at = match.index ?? 0;
391
+ if (at > last) out.push(text.slice(last, at));
392
+ const key = match[1];
393
+ const target = page.targets.get(key);
394
+ if (target) {
395
+ out.push(
396
+ <TextLink key={`${key}@${at}`} href={`#${key}`}>
397
+ {target.number ?? target.heading}
398
+ </TextLink>,
399
+ );
400
+ } else {
401
+ warnLegalOnce(`{ref:${key}} on the ${page.page} page points at no section of it.`);
402
+ out.push(match[0]);
403
+ }
404
+ last = at + match[0].length;
405
+ }
406
+ if (last < text.length) out.push(text.slice(last));
407
+ return out;
408
+ }
409
+
410
+ /** @internal Running text — one translation string — with its line breaks kept and its
411
+ * `{ref:key}` tokens resolved. */
412
+ export function LegalText({ text, className }: { text: string; className?: string }) {
413
+ const page = useContext(LegalPageContext);
414
+ // `break-words`: an address, an email or a URL in a translation is one long word, and
415
+ // on a 390px phone it would push the column wider than the screen.
416
+ return <p className={cn("whitespace-pre-line break-words", className)}>{resolveLegalRefs(text, page)}</p>;
417
+ }
418
+
36
419
  // ── Links ─────────────────────────────────────────────────────────────────────
37
420
 
38
421
  export interface LegalLink {
39
422
  href: string;
40
- /** "Imprint", "Privacy Policy", "Terms" — the app's words. */
423
+ /** "Imprint", "Privacy Policy", "Terms". */
41
424
  label: ReactNode;
42
425
  }
43
426
 
44
427
  export interface LegalLinksProps {
45
- links: readonly LegalLink[];
428
+ /** Default (0.28): the three routes, `/impressum`, `/privacy` and `/terms`, with the
429
+ * kit's short link labels (`legal.links`), in the contract's order. */
430
+ links?: readonly LegalLink[];
46
431
  /** The page being shown; its link is marked `aria-current="page"`. Usually the
47
432
  * router's pathname. */
48
433
  currentHref?: string;
@@ -52,20 +437,47 @@ export interface LegalLinksProps {
52
437
  * links, so in a plain container — Kurvenschmiede's account-menu `<li>` — they ran
53
438
  * together as "ImpressumDatenschutzerklärungNutz…" and overflowed). Default true. */
54
439
  nav?: boolean;
55
- labels?: Partial<LegalLabels>;
440
+ /** Called on a click on any of the links, before it navigates — an account menu closes
441
+ * itself here (0.28.1, keksdose: it had to catch the click on a wrapping `<div>`). */
442
+ onLinkClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
443
+ labels?: LabelOverride<LegalLabels>;
56
444
  className?: string;
57
445
  }
58
446
 
59
- /** The legal pages as a row of quiet links, the one you are on marked (kastlan's
60
- * `LegalLinks`). Wraps on a phone. */
61
- export function LegalLinks({ links, currentHref, nav = true, labels: labelsProp, className }: LegalLinksProps) {
62
- const labels = useKitLabels("legal", DEFAULT_LEGAL_LABELS, labelsProp);
63
- const items = links.map((link) => (
64
- <TextLink key={link.href} href={link.href} tone="muted" current={link.href === currentHref}>
447
+ /** The default links: the three routes under the kit's short labels. */
448
+ function defaultLinks(labels: LegalLabels): LegalLink[] {
449
+ return (["impressum", "privacy", "terms"] as const).map((page) => ({
450
+ href: LEGAL_HREFS[page],
451
+ label: labels.links[page],
452
+ }));
453
+ }
454
+
455
+ /**
456
+ * The legal pages as a row of quiet links, the one you are on marked (kastlan's
457
+ * `LegalLinks`). Wraps on a phone.
458
+ *
459
+ * 0.28: `·` separators between the links, keksdose's footer style, wherever the links
460
+ * appear — the account menu included (§3.3). The dots are `aria-hidden`: a screen reader
461
+ * already hears three links, and "middle dot" between them is noise. They are flex items
462
+ * of the row like the links, so the row's gap spaces them evenly.
463
+ */
464
+ export function LegalLinks({
465
+ links,
466
+ currentHref,
467
+ nav = true,
468
+ onLinkClick,
469
+ labels: labelsProp,
470
+ className,
471
+ }: LegalLinksProps) {
472
+ const labels = useLegalLabels(labelsProp);
473
+ const shown = links ?? defaultLinks(labels);
474
+ const items = shown.flatMap((link, i) => [
475
+ ...(i > 0 ? [<span key={`sep-${link.href}`} aria-hidden="true">·</span>] : []),
476
+ <TextLink key={link.href} href={link.href} tone="muted" current={link.href === currentHref} onClick={onLinkClick}>
65
477
  {link.label}
66
- </TextLink>
67
- ));
68
- const rowClass = cn("flex flex-wrap gap-x-4 gap-y-1 text-xs", className);
478
+ </TextLink>,
479
+ ]);
480
+ const rowClass = cn("flex flex-wrap items-center gap-x-4 gap-y-1 text-xs", className);
69
481
  if (!nav) return <div className={rowClass}>{items}</div>;
70
482
  return (
71
483
  <nav aria-label={labels.navLabel} className={rowClass}>
@@ -74,31 +486,109 @@ export function LegalLinks({ links, currentHref, nav = true, labels: labelsProp,
74
486
  );
75
487
  }
76
488
 
489
+ // ── Footer ────────────────────────────────────────────────────────────────────
490
+
491
+ export interface LegalFooterProps {
492
+ /** Under the links, centred — the app's tagline (keksdose: "Self-hosted household
493
+ * budgeting & bookkeeping."). */
494
+ children?: ReactNode;
495
+ /** Default: the three routes with the kit's link labels — see {@link LegalLinks}. */
496
+ links?: readonly LegalLink[];
497
+ /** Marks that link `aria-current="page"`. {@link LegalPage}'s default footer passes
498
+ * its own page. */
499
+ currentHref?: string;
500
+ /**
501
+ * Default true: the footer is a `<footer>`. `false` draws a `<div>` — for a host that is
502
+ * a footer already: `AuthLayout`'s `footer` slot is one, and HTML forbids a footer inside
503
+ * a footer (0.28.1, kastlan). On an `AuthLayout` page the usual choice is simpler still:
504
+ * `footer={<LegalLinks nav={false} />}` with `footerLabel` set to the kit's `navLabel`
505
+ * ({@link useLegalLabels}).
506
+ */
507
+ landmark?: boolean;
508
+ className?: string;
509
+ labels?: LabelOverride<LegalLabels>;
510
+ }
511
+
512
+ /**
513
+ * The public footer (§3.3): the three links, centred, with their separators, in a
514
+ * `<nav aria-label="Legal">` — on the landing or home page, every signed-out page the app
515
+ * has, the legal pages and the 404. The rule behind it: from every page a signed-out
516
+ * visitor can reach, the three links are one click away.
517
+ *
518
+ * keksdose's `SiteFooter` (features/landing/site-footer.tsx), which carried them on its
519
+ * landing, auth, legal and 404 pages; kastlan and Kurvenschmiede had them on some pages
520
+ * only. Its palette classes (`border-slate-200 bg-white dark:…`) became the surface and
521
+ * border tokens, so it follows the theme like the rest of the kit.
522
+ */
523
+ export function LegalFooter({ children, links, currentHref, landmark = true, className, labels }: LegalFooterProps) {
524
+ const Root = landmark ? "footer" : "div";
525
+ return (
526
+ <Root className={cn("border-t border-[var(--border)] bg-[var(--bg-surface)]", className)}>
527
+ <div className="mx-auto max-w-5xl px-4 py-8 text-sm text-[var(--text-muted)]">
528
+ <LegalLinks
529
+ links={links}
530
+ currentHref={currentHref}
531
+ labels={labels}
532
+ className="justify-center gap-y-2 text-sm"
533
+ />
534
+ {children !== undefined && children !== null && <p className="mt-4 text-center">{children}</p>}
535
+ </div>
536
+ </Root>
537
+ );
538
+ }
539
+
77
540
  // ── Section ───────────────────────────────────────────────────────────────────
78
541
 
79
542
  export interface LegalSectionProps {
80
543
  heading: ReactNode;
81
544
  /** Running text. Line breaks in it are kept (`white-space: pre-line`), so a
82
- * translation can hold an address or a list as plain lines. */
545
+ * translation can hold an address or a list as plain lines. Inside a
546
+ * {@link LegalPage}, `{ref:key}` becomes the number of section `key`, linked. */
83
547
  body?: string;
84
- /** Anything richer than plain text — links, a list — after `body`. */
548
+ /** Anything richer than plain text — links, a list — after `body`. A plain string
549
+ * here has its `{ref:key}` tokens resolved too. */
85
550
  children?: ReactNode;
86
- /** The section's `id`, for a link to it from elsewhere ("see §4"). */
551
+ /**
552
+ * The section's `id`, for a link to it from elsewhere. Inside a {@link LegalPage} it
553
+ * defaults to the element's React `key` — keksdose's
554
+ * `SECTIONS.map((s) => <LegalSection key={s} … />)` gets `id="retention"` with
555
+ * nothing added — and it is the key a `{ref:…}` names.
556
+ */
87
557
  id?: string;
88
- /** The heading's element. Default `h2`, under the layout's `h1`. */
558
+ /** The heading's element. Default `h2` under the layout's `h1` (inside a
559
+ * `LegalPage`, one level below its title). */
89
560
  headingAs?: "h2" | "h3";
90
561
  }
91
562
 
92
- export function LegalSection({ heading, body, children, id, headingAs: Heading = "h2" }: LegalSectionProps) {
563
+ /**
564
+ * One section: heading and running text.
565
+ *
566
+ * 0.28, inside a {@link LegalPage}: its `id` (the `key` unless given), its number on the
567
+ * privacy policy and the terms ("3. Legal basis" — titles carry no number, §4.1), and
568
+ * `{ref:key}` resolution in `body`. Outside one it is exactly the 0.19 section.
569
+ */
570
+ export function LegalSection({ heading, body, children, id: idProp, headingAs }: LegalSectionProps) {
571
+ const page = useContext(LegalPageContext);
572
+ const slot = useContext(LegalSlotContext);
573
+ const id = idProp ?? slot?.id;
574
+ const number = slot?.number;
575
+ const Heading = headingAs ?? page?.sectionHeading ?? "h2";
93
576
  return (
94
577
  <section id={id} className="scroll-mt-20">
95
- <Heading className="text-lg font-semibold text-[var(--text-primary)]">{heading}</Heading>
96
- {body !== undefined && (
97
- <p className="mt-2 whitespace-pre-line text-sm leading-relaxed text-[var(--text-secondary)]">{body}</p>
98
- )}
99
- {children !== undefined && (
100
- <div className="mt-2 text-sm leading-relaxed text-[var(--text-secondary)]">{children}</div>
101
- )}
578
+ <Heading className="text-lg font-semibold break-words text-[var(--text-primary)]">
579
+ {number !== undefined && `${number}. `}
580
+ {heading}
581
+ </Heading>
582
+ <LegalSlotContext.Provider value={null}>
583
+ {body !== undefined && (
584
+ <LegalText text={body} className="mt-2 text-sm leading-relaxed text-[var(--text-secondary)]" />
585
+ )}
586
+ {children !== undefined && (
587
+ <div className="mt-2 text-sm leading-relaxed break-words text-[var(--text-secondary)]">
588
+ {typeof children === "string" ? resolveLegalRefs(children, page) : children}
589
+ </div>
590
+ )}
591
+ </LegalSlotContext.Provider>
102
592
  </section>
103
593
  );
104
594
  }
@@ -108,33 +598,36 @@ export function LegalSection({ heading, body, children, id, headingAs: Heading =
108
598
  export interface LegalLayoutProps {
109
599
  /** "Imprint", "Privacy Policy", "Terms". */
110
600
  title: ReactNode;
111
- /** Above the title — the app's "← Back" link (`<TextLink icon={ArrowLeft}>`), whose
112
- * target differs per app (keksdose's start page, kastlan's sign-in). */
601
+ /** Above the title — the app's "← Back" link (`<TextLink icon={ArrowLeft}>`). Inside
602
+ * a {@link LegalPage}, "← Back to home". */
113
603
  back?: ReactNode;
114
604
  /**
115
605
  * A notice under the title, as a warning banner with `role="note"` — page furniture,
116
- * not an alert. Both apps say their legal texts await a lawyer's review; keksdose's
117
- * privacy page says something more precise than the others (its technical sections
118
- * describe running code), so the notice is per page, not per layout.
606
+ * not an alert. Per page, not per layout: the privacy page says something more precise
607
+ * than the others (its technical sections describe running code).
119
608
  */
120
609
  notice?: ReactNode;
610
+ /** 0.28.1: under the title, before the notice — {@link LegalPage}'s note that this
611
+ * page is a translation and which language is binding. */
612
+ translationNote?: ReactNode;
121
613
  /** The sections — {@link LegalSection}s. */
122
614
  children: ReactNode;
123
615
  /** The three pages, linked at the end of the column with the current one marked.
124
- * Leave out when the page's chrome already shows them (kastlan's AuthLayout footer). */
616
+ * Leave out when the page's chrome already shows them (a {@link LegalFooter}). */
125
617
  links?: readonly LegalLink[];
126
618
  currentHref?: string;
127
619
  /** Default `h1`: the page's heading. */
128
620
  headingAs?: "h1" | "h2";
129
621
  /** Extra classes on the column — `px-0 py-0` inside a chrome that pads already. */
130
622
  className?: string;
131
- labels?: Partial<LegalLabels>;
623
+ labels?: LabelOverride<LegalLabels>;
132
624
  }
133
625
 
134
626
  export function LegalLayout({
135
627
  title,
136
628
  back,
137
629
  notice,
630
+ translationNote,
138
631
  children,
139
632
  links,
140
633
  currentHref,
@@ -145,7 +638,8 @@ export function LegalLayout({
145
638
  return (
146
639
  <article className={cn("mx-auto w-full max-w-3xl px-4 py-12", className)}>
147
640
  {back !== undefined && <div className="mb-4 text-sm">{back}</div>}
148
- <Heading className="text-3xl font-bold tracking-tight text-[var(--text-primary)]">{title}</Heading>
641
+ <Heading className="text-3xl font-bold tracking-tight break-words text-[var(--text-primary)]">{title}</Heading>
642
+ {translationNote !== undefined && translationNote !== null && <div className="mt-3">{translationNote}</div>}
149
643
  {notice !== undefined && notice !== null && (
150
644
  <AlertBanner tone="warning" role="note" className="mt-4">
151
645
  {notice}