@lanfermann/ui 0.5.0 → 0.6.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.
Files changed (165) hide show
  1. package/dist/components/action-bar/action-bar.d.ts +59 -0
  2. package/dist/components/action-bar/action-bar.js +116 -0
  3. package/dist/components/alert/alert.d.ts +1 -1
  4. package/dist/components/alert/alert.js +3 -17
  5. package/dist/components/alert-dialog/alert-dialog.d.ts +1 -1
  6. package/dist/components/app-shell/app-shell.d.ts +33 -0
  7. package/dist/components/app-shell/app-shell.js +93 -0
  8. package/dist/components/attachment/attachment.d.ts +46 -0
  9. package/dist/components/attachment/attachment.js +222 -0
  10. package/dist/components/attachment/kinds.d.ts +7 -0
  11. package/dist/components/attachment/kinds.js +100 -0
  12. package/dist/components/avatar/avatar.d.ts +14 -4
  13. package/dist/components/avatar/avatar.js +57 -13
  14. package/dist/components/avatar-group/avatar-group.d.ts +33 -0
  15. package/dist/components/avatar-group/avatar-group.js +110 -0
  16. package/dist/components/avatar-group/people.d.ts +12 -0
  17. package/dist/components/avatar-group/people.js +24 -0
  18. package/dist/components/badge/badge.d.ts +9 -3
  19. package/dist/components/badge/badge.js +21 -6
  20. package/dist/components/banner/banner.d.ts +39 -0
  21. package/dist/components/banner/banner.js +149 -0
  22. package/dist/components/card/card.d.ts +11 -3
  23. package/dist/components/card/card.js +18 -4
  24. package/dist/components/checkbox-card/checkbox-card.d.ts +21 -0
  25. package/dist/components/checkbox-card/checkbox-card.js +49 -0
  26. package/dist/components/chip/chip-group.d.ts +15 -0
  27. package/dist/components/chip/chip-group.js +44 -0
  28. package/dist/components/chip/chip-variants.d.ts +6 -0
  29. package/dist/components/chip/chip-variants.js +28 -0
  30. package/dist/components/chip/chip.d.ts +39 -0
  31. package/dist/components/chip/chip.js +71 -0
  32. package/dist/components/code-block/code-copy.d.ts +3 -11
  33. package/dist/components/code-block/code-copy.js +15 -62
  34. package/dist/components/code-block/code-keys.js +10 -22
  35. package/dist/components/combobox/combobox.d.ts +50 -2
  36. package/dist/components/combobox/combobox.js +178 -9
  37. package/dist/components/command/command.d.ts +131 -0
  38. package/dist/components/command/command.js +335 -0
  39. package/dist/components/consent/consent-card.js +365 -0
  40. package/dist/components/consent/consent-embed.d.ts +21 -0
  41. package/dist/components/consent/consent-embed.js +111 -0
  42. package/dist/components/consent/consent-labels.d.ts +70 -0
  43. package/dist/components/consent/consent-labels.js +61 -0
  44. package/dist/components/consent/consent-record.d.ts +95 -0
  45. package/dist/components/consent/consent-record.js +112 -0
  46. package/dist/components/consent/consent-store.d.ts +26 -0
  47. package/dist/components/consent/consent-store.js +240 -0
  48. package/dist/components/consent/consent.d.ts +86 -0
  49. package/dist/components/consent/consent.js +306 -0
  50. package/dist/components/container/container.d.ts +1 -1
  51. package/dist/components/context-menu/context-menu.d.ts +23 -0
  52. package/dist/components/context-menu/context-menu.js +50 -0
  53. package/dist/components/conversation/conversation.d.ts +45 -0
  54. package/dist/components/conversation/conversation.js +295 -0
  55. package/dist/components/conversation/stick.js +23 -0
  56. package/dist/components/copy-button/copy-button.d.ts +50 -0
  57. package/dist/components/copy-button/copy-button.js +65 -0
  58. package/dist/components/copy-page/copy-page.js +7 -17
  59. package/dist/components/copy-pill/copy-pill.js +1 -1
  60. package/dist/components/description-list/description-list.d.ts +32 -0
  61. package/dist/components/description-list/description-list.js +51 -0
  62. package/dist/components/empty/empty.d.ts +38 -0
  63. package/dist/components/empty/empty.js +57 -0
  64. package/dist/components/field/field.js +1 -1
  65. package/dist/components/file-upload/file-upload.d.ts +96 -0
  66. package/dist/components/file-upload/file-upload.js +347 -0
  67. package/dist/components/file-upload/files.d.ts +39 -0
  68. package/dist/components/file-upload/files.js +74 -0
  69. package/dist/components/grow/grow.d.ts +15 -3
  70. package/dist/components/grow/grow.js +24 -9
  71. package/dist/components/heading/heading.d.ts +1 -1
  72. package/dist/components/icon/icon.d.ts +1 -1
  73. package/dist/components/input/input.js +1 -1
  74. package/dist/components/message/message.d.ts +73 -0
  75. package/dist/components/message/message.js +196 -0
  76. package/dist/components/otp-field/otp-field.d.ts +37 -0
  77. package/dist/components/otp-field/otp-field.js +126 -0
  78. package/dist/components/pagination/pagination.d.ts +50 -0
  79. package/dist/components/pagination/pagination.js +188 -0
  80. package/dist/components/prompt-input/keys.js +15 -0
  81. package/dist/components/prompt-input/prompt-input.d.ts +89 -0
  82. package/dist/components/prompt-input/prompt-input.js +331 -0
  83. package/dist/components/radio-card/radio-card.d.ts +23 -0
  84. package/dist/components/radio-card/radio-card.js +48 -0
  85. package/dist/components/rolling-number/rolling-number.d.ts +30 -0
  86. package/dist/components/rolling-number/rolling-number.js +149 -0
  87. package/dist/components/seam/seam.d.ts +1 -1
  88. package/dist/components/secret-field/secret-field.d.ts +53 -0
  89. package/dist/components/secret-field/secret-field.js +121 -0
  90. package/dist/components/section/section.d.ts +1 -1
  91. package/dist/components/select/select.d.ts +1 -1
  92. package/dist/components/select/select.js +1 -1
  93. package/dist/components/shortcut/shortcut.d.ts +46 -0
  94. package/dist/components/shortcut/shortcut.js +87 -0
  95. package/dist/components/sidebar/sidebar-context.js +16 -0
  96. package/dist/components/sidebar/sidebar.d.ts +161 -0
  97. package/dist/components/sidebar/sidebar.js +588 -0
  98. package/dist/components/site-header/site-header.js +1 -1
  99. package/dist/components/skeleton/loaded.d.ts +21 -0
  100. package/dist/components/skeleton/loaded.js +57 -0
  101. package/dist/components/skeleton/skeleton.d.ts +43 -0
  102. package/dist/components/skeleton/skeleton.js +48 -0
  103. package/dist/components/sources/source-list.d.ts +17 -0
  104. package/dist/components/sources/source-list.js +26 -0
  105. package/dist/components/sources/sources.d.ts +45 -0
  106. package/dist/components/sources/sources.js +167 -0
  107. package/dist/components/stat/stat.d.ts +57 -0
  108. package/dist/components/stat/stat.js +110 -0
  109. package/dist/components/steps/steps.d.ts +57 -0
  110. package/dist/components/steps/steps.js +131 -0
  111. package/dist/components/table/table.d.ts +18 -9
  112. package/dist/components/table/table.js +21 -13
  113. package/dist/components/text/text.d.ts +1 -1
  114. package/dist/components/theme-switch/theme-switch.js +1 -1
  115. package/dist/components/time-field/time-field.js +1 -1
  116. package/dist/components/timeline/timeline.d.ts +45 -0
  117. package/dist/components/timeline/timeline.js +86 -0
  118. package/dist/components/toast/toast.js +10 -26
  119. package/dist/components/toggle/toggle.d.ts +24 -0
  120. package/dist/components/toggle/toggle.js +53 -0
  121. package/dist/components/toggle-group/toggle-group.d.ts +27 -0
  122. package/dist/components/toggle-group/toggle-group.js +38 -0
  123. package/dist/components/toolbar/toolbar-context.js +12 -0
  124. package/dist/components/toolbar/toolbar.d.ts +45 -0
  125. package/dist/components/toolbar/toolbar.js +92 -0
  126. package/dist/components/trace/trace.d.ts +2 -1
  127. package/dist/components/trace/trace.js +14 -26
  128. package/dist/index.d.ts +46 -3
  129. package/dist/index.js +44 -3
  130. package/dist/internal/arriving-pieces.js +56 -0
  131. package/dist/internal/arriving.js +171 -0
  132. package/dist/internal/avatar-cut.d.ts +15 -0
  133. package/dist/internal/avatar-cut.js +83 -0
  134. package/dist/internal/choice-card.d.ts +15 -0
  135. package/dist/internal/choice-card.js +65 -0
  136. package/dist/internal/clipboard.js +37 -0
  137. package/dist/internal/copy.js +58 -0
  138. package/dist/internal/field.js +24 -4
  139. package/dist/internal/glyphs.js +26 -1
  140. package/dist/internal/live-list.js +41 -0
  141. package/dist/internal/number-places.js +156 -0
  142. package/dist/internal/picker-sheet.js +1 -1
  143. package/dist/internal/presence-dot.js +24 -0
  144. package/dist/internal/presence.js +104 -0
  145. package/dist/internal/rail-mark.d.ts +3 -0
  146. package/dist/internal/rail-mark.js +33 -0
  147. package/dist/internal/status-icon.js +22 -0
  148. package/dist/internal/travelling-mark.js +204 -0
  149. package/dist/lib/cn.js +4 -0
  150. package/dist/lib/shortcut.d.ts +11 -0
  151. package/dist/lib/shortcut.js +165 -0
  152. package/package.json +1 -1
  153. package/src/styles/action-bar.css +28 -0
  154. package/src/styles/assistant.css +83 -0
  155. package/src/styles/avatar.css +24 -0
  156. package/src/styles/consent.css +65 -0
  157. package/src/styles/copy.css +12 -11
  158. package/src/styles/depth.css +46 -2
  159. package/src/styles/marks.css +20 -2
  160. package/src/styles/rail.css +49 -0
  161. package/src/styles/rolling-number.css +94 -0
  162. package/src/styles/steps.css +98 -0
  163. package/src/styles/timeline.css +48 -0
  164. package/src/styles/travel.css +36 -0
  165. package/src/styles.css +9 -0
@@ -0,0 +1,365 @@
1
+ "use client";
2
+ import { Button } from "../button/button.js";
3
+ import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../collapsible/collapsible.js";
4
+ import { Grow } from "../grow/grow.js";
5
+ import { linkVariants } from "../link/link-variants.js";
6
+ import { ScrollFade } from "../scroll-fade/scroll-fade.js";
7
+ import { Switch } from "../switch/switch.js";
8
+ import { ChevronLeftGlyph, CloseGlyph } from "../../internal/glyphs.js";
9
+ import { useReducedMotion } from "../../internal/reduced-motion.js";
10
+ import { cn } from "../../lib/cn.js";
11
+ import { consentSummary } from "./consent-record.js";
12
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
13
+ import { Fragment as Fragment$1, useEffect, useId, useMemo, useRef, useState } from "react";
14
+ // src/components/consent/consent-card.tsx
15
+ /** How long the switches take to flip before the card leaves: the `seat` spring's visible part. */
16
+ const flipMs = 300;
17
+ const flipStaggerMs = 25;
18
+ const PlainTitle = (props) => /* @__PURE__ */ jsx("h2", { ...props });
19
+ const PlainDescription = (props) => /* @__PURE__ */ jsx("p", { ...props });
20
+ /**
21
+ * The content of the consent banner: the first layer, the settings, and the decisions under
22
+ * both. The two views stand in one place and the card's height follows the one shown (`Grow`);
23
+ * the row of decisions under them never moves. Used by `ConsentProvider` inside its dialog, and
24
+ * on its own in the workshop.
25
+ */
26
+ function ConsentCard({ config, labels, intro, privacyHref, imprintHref, granted, defaultView = "intro", revisiting = false, onDecide, onClose, Title = PlainTitle, Description = PlainDescription }) {
27
+ const [view, setView] = useState(defaultView);
28
+ const [draft, setDraft] = useState(() => new Set(granted));
29
+ const [flipping, setFlipping] = useState(false);
30
+ const reduced = useReducedMotion();
31
+ const settingsTitle = useRef(null);
32
+ const third = useRef(null);
33
+ /** When the views last swapped: the button that swapped them ignores presses until then. */
34
+ const swappedAt = useRef(Number.NEGATIVE_INFINITY);
35
+ const firstView = useRef(true);
36
+ const all = useMemo(() => config.categories.flatMap((category) => category.services.map((service) => service.id)), [config]);
37
+ useEffect(() => {
38
+ if (firstView.current) {
39
+ firstView.current = false;
40
+ return;
41
+ }
42
+ if (view === "settings") settingsTitle.current?.focus({ preventScroll: true });
43
+ else third.current?.focus({ preventScroll: true });
44
+ }, [view]);
45
+ const swap = (next) => {
46
+ swappedAt.current = performance.now();
47
+ setView(next);
48
+ };
49
+ const decide = (ids) => {
50
+ if (view === "settings" && !reduced) {
51
+ setDraft(new Set(ids));
52
+ setFlipping(true);
53
+ onDecide(ids, flipMs + flipStaggerMs * config.categories.length);
54
+ } else onDecide(ids, 0);
55
+ };
56
+ const pressThird = () => {
57
+ if (performance.now() - swappedAt.current < 400) return;
58
+ if (view === "intro") swap("settings");
59
+ else onDecide([...draft], 0);
60
+ };
61
+ const summary = consentSummary(config);
62
+ const essentialServices = [consentService(config, labels), ...config.essential ?? []];
63
+ return /* @__PURE__ */ jsxs("div", {
64
+ "data-slot": "consent-card",
65
+ "data-view": view,
66
+ "data-flipping": flipping || void 0,
67
+ className: "flex min-h-0 flex-col",
68
+ children: [/* @__PURE__ */ jsx(Grow, {
69
+ className: "min-h-0 shrink",
70
+ children: /* @__PURE__ */ jsxs("div", {
71
+ className: "relative",
72
+ children: [/* @__PURE__ */ jsxs("section", {
73
+ "data-slot": "consent-view",
74
+ "data-active": view === "intro",
75
+ "data-side": "start",
76
+ inert: view !== "intro",
77
+ className: "flex flex-col gap-3",
78
+ children: [
79
+ /* @__PURE__ */ jsx(Title, {
80
+ className: "pr-2 text-base leading-snug font-semibold text-balance text-fg",
81
+ children: labels.title
82
+ }),
83
+ /* @__PURE__ */ jsxs(ScrollFade, {
84
+ edges: "end",
85
+ className: "-mx-1 flex max-h-[calc(100dvh-15rem)] flex-col gap-2 px-1 text-sm text-fg-body",
86
+ children: [
87
+ /* @__PURE__ */ jsx(Description, { children: intro ?? labels.intro }),
88
+ /* @__PURE__ */ jsx("dl", {
89
+ "data-slot": "consent-facts",
90
+ className: "grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 border-y border-line py-2.5",
91
+ children: labels.facts(summary).map((fact) => /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("dt", {
92
+ className: "text-fg-muted",
93
+ children: fact.term
94
+ }), /* @__PURE__ */ jsx("dd", {
95
+ className: "text-fg",
96
+ children: fact.value
97
+ })] }, fact.term))
98
+ }),
99
+ /* @__PURE__ */ jsx("p", {
100
+ className: "text-fg-muted",
101
+ children: labels.withdraw
102
+ })
103
+ ]
104
+ }),
105
+ /* @__PURE__ */ jsxs("p", {
106
+ className: "flex flex-wrap gap-x-4 gap-y-1 text-sm text-fg-muted",
107
+ children: [/* @__PURE__ */ jsx("a", {
108
+ href: privacyHref,
109
+ className: linkVariants({ variant: "quiet" }),
110
+ children: labels.privacy
111
+ }), /* @__PURE__ */ jsx("a", {
112
+ href: imprintHref,
113
+ className: linkVariants({ variant: "quiet" }),
114
+ children: labels.imprint
115
+ })]
116
+ })
117
+ ]
118
+ }), /* @__PURE__ */ jsxs("section", {
119
+ "data-slot": "consent-view",
120
+ "data-active": view === "settings",
121
+ "data-side": "end",
122
+ inert: view !== "settings",
123
+ className: "flex flex-col gap-2",
124
+ children: [/* @__PURE__ */ jsxs("div", {
125
+ className: "-ml-1.5 flex min-h-(--control-sm) items-center gap-1",
126
+ children: [
127
+ !revisiting && /* @__PURE__ */ jsx(Button, {
128
+ variant: "quiet",
129
+ size: "sm",
130
+ iconOnly: true,
131
+ "aria-label": labels.back,
132
+ className: "text-fg-muted",
133
+ onClick: () => swap("intro"),
134
+ children: /* @__PURE__ */ jsx(ChevronLeftGlyph, {})
135
+ }),
136
+ /* @__PURE__ */ jsx("h2", {
137
+ ref: settingsTitle,
138
+ tabIndex: -1,
139
+ "data-slot": "consent-settings-title",
140
+ className: cn("text-base leading-snug font-semibold text-fg focus:outline-hidden", revisiting && "pl-1.5"),
141
+ children: labels.settingsTitle
142
+ }),
143
+ revisiting && /* @__PURE__ */ jsx(Button, {
144
+ variant: "quiet",
145
+ size: "sm",
146
+ iconOnly: true,
147
+ "aria-label": labels.close,
148
+ className: "ml-auto text-fg-muted",
149
+ onClick: onClose,
150
+ children: /* @__PURE__ */ jsx(CloseGlyph, {})
151
+ })
152
+ ]
153
+ }), /* @__PURE__ */ jsxs(ScrollFade, {
154
+ className: "-mx-5 max-h-[min(30rem,calc(100dvh-14rem))] px-5",
155
+ children: [/* @__PURE__ */ jsxs("ul", {
156
+ className: "flex flex-col",
157
+ children: [/* @__PURE__ */ jsx(CategoryRow, {
158
+ labels,
159
+ name: labels.essentialName,
160
+ description: labels.essentialDescription,
161
+ services: essentialServices,
162
+ essential: true,
163
+ draft,
164
+ setDraft,
165
+ index: 0
166
+ }), config.categories.map((category, index) => /* @__PURE__ */ jsx(CategoryRow, {
167
+ labels,
168
+ name: category.name,
169
+ description: category.description,
170
+ services: category.services,
171
+ draft,
172
+ setDraft,
173
+ index
174
+ }, category.id))]
175
+ }), /* @__PURE__ */ jsx("p", {
176
+ className: "pt-2 pb-1 text-sm text-fg-muted",
177
+ children: labels.withdrawEffect
178
+ })]
179
+ })]
180
+ })]
181
+ })
182
+ }), /* @__PURE__ */ jsxs("div", {
183
+ "data-slot": "consent-footer",
184
+ className: "grid shrink-0 grid-cols-2 gap-2 pt-4",
185
+ children: [
186
+ /* @__PURE__ */ jsx(Button, {
187
+ onClick: () => decide([]),
188
+ children: labels.rejectAll
189
+ }),
190
+ /* @__PURE__ */ jsx(Button, {
191
+ onClick: () => decide(all),
192
+ children: labels.acceptAll
193
+ }),
194
+ /* @__PURE__ */ jsx(Button, {
195
+ ref: third,
196
+ variant: view === "intro" ? "quiet" : "secondary",
197
+ className: "col-span-2",
198
+ onClick: pressThird,
199
+ children: /* @__PURE__ */ jsxs("span", {
200
+ className: "grid",
201
+ children: [/* @__PURE__ */ jsx("span", {
202
+ "data-slot": "consent-third-label",
203
+ "data-active": view === "intro",
204
+ "aria-hidden": view !== "intro" || void 0,
205
+ children: labels.settings
206
+ }), /* @__PURE__ */ jsx("span", {
207
+ "data-slot": "consent-third-label",
208
+ "data-active": view === "settings",
209
+ "aria-hidden": view !== "settings" || void 0,
210
+ children: labels.save
211
+ })]
212
+ })
213
+ })
214
+ ]
215
+ })]
216
+ });
217
+ }
218
+ /** The consent cookie itself, listed under the essential category (Rn. 37: every storage). */
219
+ function consentService(config, labels) {
220
+ return {
221
+ id: "consent",
222
+ name: labels.consentServiceName,
223
+ provider: labels.consentServiceProvider,
224
+ purpose: labels.consentServicePurpose,
225
+ profiling: false,
226
+ storage: [{
227
+ name: config.cookieName ?? "lf-consent",
228
+ duration: labels.duration(config.maxAgeDays ?? 365)
229
+ }]
230
+ };
231
+ }
232
+ /** A purpose: its switch, what it is for, and its services folded under it. */
233
+ function CategoryRow({ labels, name, description, services, essential = false, draft, setDraft, index }) {
234
+ const descriptionId = useId();
235
+ const on = services.filter((service) => draft.has(service.id)).length;
236
+ const mixed = on > 0 && on < services.length;
237
+ const set = (ids, checked) => {
238
+ const next = new Set(draft);
239
+ for (const id of ids) if (checked) next.add(id);
240
+ else next.delete(id);
241
+ setDraft(next);
242
+ };
243
+ return /* @__PURE__ */ jsxs("li", {
244
+ "data-slot": "consent-category",
245
+ className: "flex flex-col gap-1 border-t border-line py-3 first:border-t-0 first:pt-1",
246
+ children: [
247
+ essential ? /* @__PURE__ */ jsxs("div", {
248
+ className: "flex min-h-(--switch-h) items-center justify-between gap-3",
249
+ children: [/* @__PURE__ */ jsx("span", {
250
+ className: "text-control font-medium text-fg",
251
+ children: name
252
+ }), /* @__PURE__ */ jsx("span", {
253
+ className: "text-sm text-fg-muted",
254
+ children: labels.alwaysOn
255
+ })]
256
+ }) : /* @__PURE__ */ jsxs("label", {
257
+ className: "flex items-center justify-between gap-3",
258
+ children: [/* @__PURE__ */ jsx("span", {
259
+ className: "text-control font-medium text-fg",
260
+ children: name
261
+ }), /* @__PURE__ */ jsxs("span", {
262
+ className: "flex items-center gap-2",
263
+ children: [mixed && /* @__PURE__ */ jsx("span", {
264
+ className: "text-sm text-fg-muted tabular-nums",
265
+ children: labels.mixed(on, services.length)
266
+ }), /* @__PURE__ */ jsx(Switch, {
267
+ checked: on === services.length,
268
+ onCheckedChange: (checked) => set(services.map((service) => service.id), checked),
269
+ "aria-describedby": descriptionId,
270
+ style: { "--flip-index": index }
271
+ })]
272
+ })]
273
+ }),
274
+ /* @__PURE__ */ jsx("p", {
275
+ id: descriptionId,
276
+ className: "text-sm text-fg-muted",
277
+ children: description
278
+ }),
279
+ /* @__PURE__ */ jsxs(Collapsible, {
280
+ className: "mt-0.5",
281
+ children: [/* @__PURE__ */ jsx(CollapsibleTrigger, {
282
+ className: "text-sm font-normal text-fg-body",
283
+ children: labels.services(services.length)
284
+ }), /* @__PURE__ */ jsx(CollapsiblePanel, {
285
+ className: "w-full",
286
+ children: /* @__PURE__ */ jsx("ul", {
287
+ className: "flex flex-col gap-2",
288
+ children: services.map((service) => /* @__PURE__ */ jsx(ServiceFacts, {
289
+ labels,
290
+ service,
291
+ toggle: !essential && services.length > 1 ? {
292
+ checked: draft.has(service.id),
293
+ onChange: (checked) => set([service.id], checked)
294
+ } : void 0
295
+ }, service.id))
296
+ })
297
+ })]
298
+ })
299
+ ]
300
+ });
301
+ }
302
+ /** Who runs a service, what for, what it stores, where the data goes. */
303
+ function ServiceFacts({ labels, service, toggle }) {
304
+ const heading = /* @__PURE__ */ jsxs("span", {
305
+ className: "flex min-w-0 flex-col",
306
+ children: [/* @__PURE__ */ jsx("span", {
307
+ className: "text-sm font-medium text-fg",
308
+ children: service.name
309
+ }), /* @__PURE__ */ jsx("span", {
310
+ className: "text-sm text-fg-muted",
311
+ children: service.provider
312
+ })]
313
+ });
314
+ return /* @__PURE__ */ jsxs("li", {
315
+ "data-slot": "consent-service",
316
+ className: "flex flex-col gap-1.5 rounded-lg bg-well px-3 py-2.5 text-sm",
317
+ children: [
318
+ toggle ? /* @__PURE__ */ jsxs("label", {
319
+ className: "flex items-start justify-between gap-3",
320
+ children: [heading, /* @__PURE__ */ jsx(Switch, {
321
+ checked: toggle.checked,
322
+ onCheckedChange: toggle.onChange
323
+ })]
324
+ }) : heading,
325
+ /* @__PURE__ */ jsx("p", {
326
+ className: "text-fg-body",
327
+ children: service.purpose
328
+ }),
329
+ /* @__PURE__ */ jsxs("dl", {
330
+ className: "grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5",
331
+ children: [service.storage?.length ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("dt", {
332
+ className: "text-fg-muted",
333
+ children: labels.stored
334
+ }), /* @__PURE__ */ jsx("dd", {
335
+ className: "min-w-0 text-fg-body",
336
+ children: service.storage.map((entry) => /* @__PURE__ */ jsxs("span", {
337
+ className: "block",
338
+ children: [/* @__PURE__ */ jsx("code", {
339
+ className: "font-mono text-[0.9em] break-all",
340
+ children: entry.name
341
+ }), ` (${labels.storageKind[entry.kind ?? "cookie"]}, ${entry.duration})`]
342
+ }, entry.name))
343
+ })] }) : null, service.thirdCountry && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("dt", {
344
+ className: "text-fg-muted",
345
+ children: labels.thirdCountry
346
+ }), /* @__PURE__ */ jsx("dd", {
347
+ className: "text-fg-body",
348
+ children: service.thirdCountry
349
+ })] })]
350
+ }),
351
+ service.profiling && /* @__PURE__ */ jsx("p", {
352
+ className: "text-fg-muted",
353
+ children: labels.profiling
354
+ }),
355
+ service.privacyUrl && /* @__PURE__ */ jsx("a", {
356
+ href: service.privacyUrl,
357
+ className: cn(linkVariants({ variant: "quiet" }), "self-start text-fg-muted"),
358
+ target: service.privacyUrl.startsWith("http") ? "_blank" : void 0,
359
+ rel: "noreferrer",
360
+ children: labels.privacyPolicy
361
+ })
362
+ ]
363
+ });
364
+ }
365
+ export { ConsentCard };
@@ -0,0 +1,21 @@
1
+ import { ComponentProps, ReactNode } from "react";
2
+ export type ConsentEmbedProps = Omit<ComponentProps<"div">, "children"> & {
3
+ /** The service the content comes from, by its id in the config. */
4
+ service: string;
5
+ /** The content's shape, as CSS `aspect-ratio`: „16 / 9“ for a video, „4 / 3“ for a map. */
6
+ aspect?: string;
7
+ /** What it is, shown as a mark above the placeholder's title: a play mark or a map pin. */
8
+ kind?: "video" | "map";
9
+ /** The content itself, usually an `<iframe>`. Rendered only with consent. */
10
+ children: ReactNode;
11
+ };
12
+ /**
13
+ * Content from another provider (a video, a map) that loads only with consent. Until then a
14
+ * placeholder of the same shape says whose content it is, what loading it sends where, and
15
+ * offers to load it: once, for this page, or always, which stores the consent for that one
16
+ * service. The placeholder itself loads nothing from the provider, not even a picture.
17
+ *
18
+ * Once allowed, the content fades in when it has loaded. Revoking the service in the settings
19
+ * takes it away again.
20
+ */
21
+ export declare function ConsentEmbed({ service: serviceId, aspect, kind, className, style, children, ...props }: ConsentEmbedProps): import("react").JSX.Element | null;
@@ -0,0 +1,111 @@
1
+ "use client";
2
+ import { Button } from "../button/button.js";
3
+ import { Icon } from "../icon/icon.js";
4
+ import { linkVariants } from "../link/link-variants.js";
5
+ import { Spinner } from "../spinner/spinner.js";
6
+ import { cn } from "../../lib/cn.js";
7
+ import { useConsentContext } from "./consent.js";
8
+ import { consentServices } from "./consent-record.js";
9
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
+ import { useCallback, useState } from "react";
11
+ import { Location01Icon, PlayIcon } from "@hugeicons/core-free-icons";
12
+ // src/components/consent/consent-embed.tsx
13
+ /**
14
+ * Content from another provider (a video, a map) that loads only with consent. Until then a
15
+ * placeholder of the same shape says whose content it is, what loading it sends where, and
16
+ * offers to load it: once, for this page, or always, which stores the consent for that one
17
+ * service. The placeholder itself loads nothing from the provider, not even a picture.
18
+ *
19
+ * Once allowed, the content fades in when it has loaded. Revoking the service in the settings
20
+ * takes it away again.
21
+ */
22
+ function ConsentEmbed({ service: serviceId, aspect = "16 / 9", kind, className, style, children, ...props }) {
23
+ const { allows, config, labels, snapshot, store, decide } = useConsentContext("ConsentEmbed");
24
+ const service = consentServices(config).get(serviceId);
25
+ const allowed = allows(serviceId);
26
+ const [loaded, setLoaded] = useState(false);
27
+ const watch = useCallback((element) => {
28
+ if (!element) return;
29
+ if (!element.querySelector("iframe, img, video")) {
30
+ setLoaded(true);
31
+ return;
32
+ }
33
+ const done = () => setLoaded(true);
34
+ element.addEventListener("load", done, true);
35
+ return () => element.removeEventListener("load", done, true);
36
+ }, []);
37
+ const box = cn("relative min-h-fit w-full overflow-hidden rounded-xl bg-well depth-socket", className);
38
+ const shape = {
39
+ aspectRatio: aspect,
40
+ ...style
41
+ };
42
+ if (snapshot.status === "unknown") return /* @__PURE__ */ jsx("div", {
43
+ "data-slot": "consent-embed",
44
+ className: box,
45
+ style: shape,
46
+ ...props
47
+ });
48
+ if (allowed) return /* @__PURE__ */ jsxs("div", {
49
+ "data-slot": "consent-embed",
50
+ "data-loaded": loaded || void 0,
51
+ className: box,
52
+ style: shape,
53
+ ...props,
54
+ children: [!loaded && /* @__PURE__ */ jsx("span", {
55
+ className: "absolute inset-0 grid place-items-center text-fg-muted",
56
+ children: /* @__PURE__ */ jsx(Spinner, {})
57
+ }), /* @__PURE__ */ jsx("div", {
58
+ ref: watch,
59
+ "data-slot": "consent-embed-content",
60
+ className: cn("size-full transition-opacity spring-settle *:size-full", loaded ? "opacity-100" : "opacity-0"),
61
+ children
62
+ })]
63
+ });
64
+ if (!service) return null;
65
+ const decided = snapshot.status === "decided";
66
+ return /* @__PURE__ */ jsx("div", {
67
+ "data-slot": "consent-embed",
68
+ className: cn(box, "grid place-items-center px-6 py-8 text-center"),
69
+ style: shape,
70
+ ...props,
71
+ children: /* @__PURE__ */ jsxs("div", {
72
+ className: "flex max-w-sm flex-col items-center gap-3",
73
+ children: [
74
+ kind && /* @__PURE__ */ jsx("span", {
75
+ "data-slot": "consent-embed-mark",
76
+ className: "mb-1 grid size-11 place-items-center rounded-full border border-line text-fg-muted",
77
+ children: /* @__PURE__ */ jsx(Icon, {
78
+ icon: kind === "video" ? PlayIcon : Location01Icon,
79
+ size: 18
80
+ })
81
+ }),
82
+ /* @__PURE__ */ jsx("p", {
83
+ className: "text-control leading-snug font-semibold text-balance text-fg",
84
+ children: labels.embedTitle(service)
85
+ }),
86
+ /* @__PURE__ */ jsxs("p", {
87
+ className: "text-sm text-pretty text-fg-body",
88
+ children: [labels.embedText(service), service.privacyUrl && /* @__PURE__ */ jsxs(Fragment, { children: [" ", /* @__PURE__ */ jsx("a", {
89
+ href: service.privacyUrl,
90
+ className: linkVariants({ variant: "quiet" }),
91
+ target: service.privacyUrl.startsWith("http") ? "_blank" : void 0,
92
+ rel: "noreferrer",
93
+ children: labels.privacyPolicy
94
+ })] })]
95
+ }),
96
+ /* @__PURE__ */ jsxs("div", {
97
+ className: "flex flex-wrap justify-center gap-2 pt-1",
98
+ children: [/* @__PURE__ */ jsx(Button, {
99
+ onClick: () => store.grantOnce(serviceId),
100
+ children: labels.embedLoadOnce
101
+ }), decided && /* @__PURE__ */ jsx(Button, {
102
+ variant: "quiet",
103
+ onClick: () => decide([...snapshot.record?.granted ?? [], serviceId]),
104
+ children: labels.embedAlways(service)
105
+ })]
106
+ })
107
+ ]
108
+ })
109
+ });
110
+ }
111
+ export { ConsentEmbed };
@@ -0,0 +1,70 @@
1
+ import { ConsentService, ConsentStorageKind, ConsentSummary } from "./consent-record.js";
2
+ /**
3
+ * Every string the consent banner, its settings and the embed placeholder show. A cookie notice
4
+ * addresses nobody (no „Sie“, no „wir“): it states what happens, the way the footer and the
5
+ * imprint do. A site that speaks to its customers may pass its own wording.
6
+ *
7
+ * Some entries are functions, because they are built from the config: the line about providers
8
+ * and countries on the first layer has to name them (DSK, OH Digitale Dienste, Rn. 119).
9
+ */
10
+ export type ConsentLabels = {
11
+ /** The banner's title, a sentence with a full stop. */
12
+ title: string;
13
+ /** What the services do, when the site passes no `intro` of its own. */
14
+ intro: string;
15
+ /**
16
+ * What the first layer must state (Rn. 119): the purposes, how many providers receive data,
17
+ * whether it leaves the EU, and whether profiles are built across sites. Built from the config
18
+ * as short facts, a term and its value each.
19
+ */
20
+ facts: (summary: ConsentSummary) => {
21
+ term: string;
22
+ value: string;
23
+ }[];
24
+ /** That consent is voluntary and where it is changed. */
25
+ withdraw: string;
26
+ /** That a withdrawal counts from then on (Art. 7 (3) GDPR; Rn. 37). Shown in the settings. */
27
+ withdrawEffect: string;
28
+ privacy: string;
29
+ imprint: string;
30
+ rejectAll: string;
31
+ acceptAll: string;
32
+ /** Opens the settings from the first layer. */
33
+ settings: string;
34
+ /** Stores what the switches show. */
35
+ save: string;
36
+ /** The title of the settings view. */
37
+ settingsTitle: string;
38
+ back: string;
39
+ close: string;
40
+ essentialName: string;
41
+ essentialDescription: string;
42
+ /** Beside the essential category, in place of a switch. */
43
+ alwaysOn: string;
44
+ /** The trigger that unfolds a category's services. */
45
+ services: (count: number) => string;
46
+ /** Beside a category whose services are partly on. */
47
+ mixed: (on: number, total: number) => string;
48
+ provider: string;
49
+ purpose: string;
50
+ stored: string;
51
+ storageKind: Record<ConsentStorageKind, string>;
52
+ thirdCountry: string;
53
+ profiling: string;
54
+ /** The link to a provider's privacy policy. */
55
+ privacyPolicy: string;
56
+ /** How long the consent cookie is kept, from `maxAgeDays`. */
57
+ duration: (days: number) => string;
58
+ /** The consent cookie itself, listed under the essential category. */
59
+ consentServiceName: string;
60
+ consentServiceProvider: string;
61
+ consentServicePurpose: string;
62
+ /** The footer link, and the name of the floating button that opens the settings. */
63
+ trigger: string;
64
+ /** The embed placeholder. */
65
+ embedTitle: (service: ConsentService) => string;
66
+ embedText: (service: ConsentService) => string;
67
+ embedLoadOnce: string;
68
+ embedAlways: (service: ConsentService) => string;
69
+ };
70
+ export declare const consentLabels: ConsentLabels;
@@ -0,0 +1,61 @@
1
+ // src/components/consent/consent-labels.ts
2
+ /** „a“, „a und b“, „a, b und c“. */
3
+ function joinGerman(items) {
4
+ if (items.length < 2) return items.join("");
5
+ return `${items.slice(0, -1).join(", ")} und ${items.at(-1)}`;
6
+ }
7
+ const consentLabels = {
8
+ title: "Cookies auf dieser Website.",
9
+ intro: "Einige Dienste dieser Website speichern Daten im Browser oder lesen sie dort aus. Sie werden erst geladen, wenn eine Einwilligung vorliegt.",
10
+ facts: ({ purposes, providers, thirdCountries, profilers }) => [
11
+ {
12
+ term: "Zwecke",
13
+ value: joinGerman(purposes)
14
+ },
15
+ {
16
+ term: "Empfänger",
17
+ value: `${providers.length} Anbieter${thirdCountries.length ? `, auch außerhalb der EU (${joinGerman(thirdCountries)})` : ""}`
18
+ },
19
+ ...profilers.length ? [{
20
+ term: "Profile",
21
+ value: `${profilers.length === providers.length ? providers.length === 1 ? "Vom Anbieter" : "Von allen Anbietern" : profilers.length === 1 ? "Von einem Anbieter" : `Von ${profilers.length} Anbietern`}, über Websites hinweg`
22
+ }] : []
23
+ ],
24
+ withdraw: "Die Einwilligung ist freiwillig und lässt sich jederzeit unter „Cookie-Einstellungen“ am Ende jeder Seite ändern.",
25
+ withdrawEffect: "Ein Widerruf gilt ab diesem Moment. Was bis dahin mit Einwilligung geschehen ist, bleibt davon unberührt.",
26
+ privacy: "Datenschutzerklärung",
27
+ imprint: "Impressum",
28
+ rejectAll: "Alle ablehnen",
29
+ acceptAll: "Alle akzeptieren",
30
+ settings: "Einstellungen",
31
+ save: "Auswahl speichern",
32
+ settingsTitle: "Cookie-Einstellungen.",
33
+ back: "Zurück",
34
+ close: "Schließen",
35
+ essentialName: "Notwendig",
36
+ essentialDescription: "Hält die Website am Laufen und merkt sich diese Auswahl. Dafür ist keine Einwilligung nötig.",
37
+ alwaysOn: "Immer aktiv",
38
+ services: (count) => count === 1 ? "1 Dienst" : `${count} Dienste`,
39
+ mixed: (on, total) => `${on} von ${total} aktiv`,
40
+ provider: "Anbieter",
41
+ purpose: "Zweck",
42
+ stored: "Speichert",
43
+ storageKind: {
44
+ cookie: "Cookie",
45
+ local: "Lokaler Speicher",
46
+ session: "Sitzungsspeicher"
47
+ },
48
+ thirdCountry: "Außerhalb der EU",
49
+ profiling: "Bildet Profile über Websites hinweg.",
50
+ privacyPolicy: "Datenschutzerklärung des Anbieters",
51
+ duration: (days) => days % 365 === 0 ? days === 365 ? "1 Jahr" : `${days / 365} Jahre` : days % 30 === 0 ? `${days / 30} Monate` : `${days} Tage`,
52
+ consentServiceName: "Einwilligung",
53
+ consentServiceProvider: "Diese Website",
54
+ consentServicePurpose: "Speichert diese Auswahl, damit sie nicht bei jedem Besuch erscheint.",
55
+ trigger: "Cookie-Einstellungen",
56
+ embedTitle: (service) => `Hier steht ein Inhalt von ${service.name}.`,
57
+ embedText: (service) => `Beim Laden erhält ${service.provider.split(",")[0]} Daten wie die IP-Adresse${service.thirdCountry ? `, auch außerhalb der EU (${service.thirdCountry})` : ""}.`,
58
+ embedLoadOnce: "Inhalt laden",
59
+ embedAlways: (service) => `${service.name} immer laden`
60
+ };
61
+ export { consentLabels, joinGerman };