@sweberdev/witness-react 0.0.0-stage → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Seya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,19 @@
1
- # Temporary Holding Version
1
+ # @sweberdev/witness-react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ React components for [Witness](https://packages.sweber.dev/witness): the chatbot AI notice (EU AI Act Art. 50(1)), AI labels and marked content blocks.
4
+
5
+ ```sh
6
+ pnpm add @sweberdev/witness @sweberdev/witness-react
7
+ ```
8
+
9
+ ```tsx
10
+ import "@sweberdev/witness/styles.css";
11
+ import { AiContent, AiLabel, AiNotice, WitnessProvider } from "@sweberdev/witness-react";
12
+
13
+ <WitnessProvider locale="de">
14
+ <AiNotice id="support-chat" href="/ki-einsatz" />
15
+ <AiContent marking={{ generator: "Claude" }}>{summary}</AiContent>
16
+ </WitnessProvider>;
17
+ ```
18
+
19
+ Docs: [packages.sweber.dev/witness/docs/guides/react](https://packages.sweber.dev/witness/docs/guides/react) · MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,346 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ AiContent: () => AiContent,
25
+ AiLabel: () => AiLabel,
26
+ AiNotice: () => AiNotice,
27
+ WitnessProvider: () => WitnessProvider,
28
+ useAiDisclosure: () => useAiDisclosure,
29
+ useWitnessMessages: () => useWitnessMessages
30
+ });
31
+ module.exports = __toCommonJS(index_exports);
32
+
33
+ // src/AiContent.tsx
34
+ var import_witness4 = require("@sweberdev/witness");
35
+ var import_react5 = require("react");
36
+
37
+ // src/AiLabel.tsx
38
+ var import_witness3 = require("@sweberdev/witness");
39
+ var import_react4 = require("react");
40
+
41
+ // src/AiNotice.tsx
42
+ var import_react3 = require("react");
43
+
44
+ // src/context.tsx
45
+ var import_witness = require("@sweberdev/witness");
46
+ var import_react = require("react");
47
+ var import_jsx_runtime = require("react/jsx-runtime");
48
+ var WitnessContext = (0, import_react.createContext)(null);
49
+ function WitnessProvider({ locale, messages, children }) {
50
+ const value = (0, import_react.useMemo)(
51
+ () => ({ locale: (0, import_witness.resolveLocale)(locale), messages: (0, import_witness.getMessages)(locale, messages) }),
52
+ [locale, messages]
53
+ );
54
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WitnessContext.Provider, { value, children });
55
+ }
56
+ function useWitnessMessages(locale) {
57
+ const context = (0, import_react.useContext)(WitnessContext);
58
+ return (0, import_react.useMemo)(() => {
59
+ if (locale) return { locale: (0, import_witness.resolveLocale)(locale), messages: (0, import_witness.getMessages)(locale) };
60
+ return context ?? { locale: "en", messages: (0, import_witness.getMessages)("en") };
61
+ }, [context, locale]);
62
+ }
63
+
64
+ // src/useAiDisclosure.ts
65
+ var import_witness2 = require("@sweberdev/witness");
66
+ var import_react2 = require("react");
67
+ function useAiDisclosure(options = {}) {
68
+ const onEvent = (0, import_react2.useRef)(options.onEvent);
69
+ onEvent.current = options.onEvent;
70
+ const { id, kind, version, locale, storage } = options;
71
+ const disclosure = (0, import_react2.useMemo)(
72
+ () => (0, import_witness2.createDisclosure)({
73
+ ...id ? { id } : {},
74
+ ...kind ? { kind } : {},
75
+ ...version ? { version } : {},
76
+ ...locale ? { locale } : {},
77
+ ...storage ? { storage } : {},
78
+ onEvent: (event) => onEvent.current?.(event)
79
+ }),
80
+ [id, kind, version, locale, storage]
81
+ );
82
+ const subscribe = (0, import_react2.useCallback)(
83
+ (listener) => {
84
+ const unsubscribe = disclosure.subscribe(listener);
85
+ const onStorage = (event) => {
86
+ if (event.key === null || event.key.startsWith("witness:ack:")) listener();
87
+ };
88
+ if (typeof window !== "undefined") window.addEventListener("storage", onStorage);
89
+ return () => {
90
+ unsubscribe();
91
+ if (typeof window !== "undefined") window.removeEventListener("storage", onStorage);
92
+ };
93
+ },
94
+ [disclosure]
95
+ );
96
+ const acknowledgedAt = (0, import_react2.useSyncExternalStore)(
97
+ subscribe,
98
+ () => disclosure.acknowledgedAt(),
99
+ () => null
100
+ );
101
+ return {
102
+ needsAcknowledgement: acknowledgedAt === null,
103
+ acknowledgedAt,
104
+ acknowledge: disclosure.acknowledge,
105
+ markShown: disclosure.markShown,
106
+ reset: disclosure.reset,
107
+ disclosure
108
+ };
109
+ }
110
+
111
+ // src/AiNotice.tsx
112
+ var import_jsx_runtime2 = require("react/jsx-runtime");
113
+ function AiNotice({
114
+ kind = "chatbot",
115
+ id,
116
+ version,
117
+ locale,
118
+ href,
119
+ storage,
120
+ onEvent,
121
+ children,
122
+ className
123
+ }) {
124
+ const { locale: code, messages } = useWitnessMessages(locale);
125
+ const disclosure = useAiDisclosure({
126
+ kind,
127
+ locale: code,
128
+ ...id ? { id } : {},
129
+ ...version ? { version } : {},
130
+ ...storage ? { storage } : {},
131
+ ...onEvent ? { onEvent } : {}
132
+ });
133
+ const [reopened, setReopened] = (0, import_react3.useState)(false);
134
+ const titleId = (0, import_react3.useId)();
135
+ const text = messages.kinds[kind];
136
+ const full = reopened || disclosure.needsAcknowledgement;
137
+ const { markShown } = disclosure;
138
+ (0, import_react3.useEffect)(() => {
139
+ if (full) markShown();
140
+ }, [full, markShown]);
141
+ if (!full) {
142
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
143
+ "button",
144
+ {
145
+ type: "button",
146
+ className: cx("witness-notice--compact", className),
147
+ "aria-label": `${text.label}: ${messages.ui.details}`,
148
+ onClick: () => setReopened(true),
149
+ children: [
150
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "witness-label__icon", "aria-hidden": "true", children: "AI" }),
151
+ text.label
152
+ ]
153
+ }
154
+ );
155
+ }
156
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("section", { className: cx("witness-notice", className), role: "note", "aria-labelledby": titleId, children: [
157
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "witness-label__icon", "aria-hidden": "true", children: "AI" }),
158
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
159
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { id: titleId, className: "witness-notice__title", children: text.title }),
160
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "witness-notice__body", children: children ?? text.body }),
161
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "witness-notice__actions", children: [
162
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
163
+ "button",
164
+ {
165
+ type: "button",
166
+ className: "witness-notice__ack",
167
+ onClick: () => {
168
+ setReopened(false);
169
+ disclosure.acknowledge();
170
+ },
171
+ children: messages.ui.acknowledge
172
+ }
173
+ ),
174
+ href ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { href, children: messages.ui.moreInfo }) : null
175
+ ] })
176
+ ] })
177
+ ] });
178
+ }
179
+ function cx(...names) {
180
+ return names.filter(Boolean).join(" ");
181
+ }
182
+
183
+ // src/AiLabel.tsx
184
+ var import_jsx_runtime3 = require("react/jsx-runtime");
185
+ function AiLabel({
186
+ kind = "generated",
187
+ generator,
188
+ generatorVersion,
189
+ createdAt,
190
+ reviewed,
191
+ href,
192
+ locale,
193
+ variant = "inline",
194
+ className
195
+ }) {
196
+ const { locale: code, messages } = useWitnessMessages(locale);
197
+ const [open, setOpen] = (0, import_react4.useState)(false);
198
+ const panelId = (0, import_react4.useId)();
199
+ const root = (0, import_react4.useRef)(null);
200
+ const button = (0, import_react4.useRef)(null);
201
+ const text = messages.kinds[kind];
202
+ const name = [generator, generatorVersion].filter(Boolean).join(" ");
203
+ (0, import_react4.useEffect)(() => {
204
+ if (!open) return;
205
+ const onKey = (event) => {
206
+ if (event.key === "Escape") {
207
+ setOpen(false);
208
+ button.current?.focus();
209
+ }
210
+ };
211
+ const onClick = (event) => {
212
+ if (root.current && !root.current.contains(event.target)) setOpen(false);
213
+ };
214
+ document.addEventListener("keydown", onKey);
215
+ document.addEventListener("click", onClick);
216
+ return () => {
217
+ document.removeEventListener("keydown", onKey);
218
+ document.removeEventListener("click", onClick);
219
+ };
220
+ }, [open]);
221
+ const facts = [];
222
+ if (name) facts.push((0, import_witness3.format)(messages.ui.generatedWith, { generator: name }));
223
+ if (createdAt) facts.push((0, import_witness3.format)(messages.ui.createdOn, { date: formatDate(createdAt, code) }));
224
+ if (reviewed) facts.push(messages.ui.humanReviewed);
225
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
226
+ "span",
227
+ {
228
+ ref: root,
229
+ className: cx("witness-badge", `witness-badge--${variant}`, className),
230
+ style: variant === "overlay" ? overlayStyle : inlineStyle,
231
+ children: [
232
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
233
+ "button",
234
+ {
235
+ ref: button,
236
+ type: "button",
237
+ className: "witness-label",
238
+ style: { margin: 0, font: "inherit", cursor: "pointer" },
239
+ "aria-expanded": open,
240
+ "aria-controls": panelId,
241
+ title: messages.ui.details,
242
+ onClick: () => setOpen((value) => !value),
243
+ children: [
244
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "witness-label__icon", "aria-hidden": "true", children: "AI" }),
245
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "witness-label__text", children: text.label })
246
+ ]
247
+ }
248
+ ),
249
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
250
+ "span",
251
+ {
252
+ id: panelId,
253
+ role: "dialog",
254
+ "aria-label": text.title,
255
+ className: "witness-badge__panel",
256
+ hidden: !open,
257
+ style: variant === "overlay" ? { ...panelStyle, right: 0 } : { ...panelStyle, left: 0 },
258
+ children: [
259
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("strong", { style: { display: "block", marginBottom: "0.25em" }, children: text.title }),
260
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { display: "block" }, children: text.body }),
261
+ facts.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("ul", { style: { margin: "0.4em 0", paddingInlineStart: "1.1em" }, children: facts.map((fact) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("li", { children: fact }, fact)) }) : null,
262
+ href ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("a", { href, children: messages.ui.moreInfo }) : null
263
+ ]
264
+ }
265
+ )
266
+ ]
267
+ }
268
+ );
269
+ }
270
+ var inlineStyle = { position: "relative", display: "inline-block" };
271
+ var overlayStyle = { position: "absolute", top: "0.5em", right: "0.5em", zIndex: 1 };
272
+ var panelStyle = {
273
+ position: "absolute",
274
+ top: "calc(100% + 0.4em)",
275
+ zIndex: 10,
276
+ width: "max-content",
277
+ maxWidth: "min(22em, 80vw)",
278
+ padding: "0.75em 0.875em",
279
+ border: "1px solid var(--witness-border, #d7dbe3)",
280
+ borderRadius: "var(--witness-radius, 8px)",
281
+ background: "var(--witness-bg, #fff)",
282
+ color: "var(--witness-fg, #1a1a1a)",
283
+ boxShadow: "0 6px 24px rgb(0 0 0 / 0.15)",
284
+ lineHeight: 1.45,
285
+ fontSize: "0.875rem",
286
+ textAlign: "start"
287
+ };
288
+ function formatDate(value, locale) {
289
+ const date = new Date(value);
290
+ if (Number.isNaN(date.getTime())) return value;
291
+ try {
292
+ return new Intl.DateTimeFormat(locale, { dateStyle: "medium" }).format(date);
293
+ } catch {
294
+ return value;
295
+ }
296
+ }
297
+
298
+ // src/AiContent.tsx
299
+ var import_jsx_runtime4 = require("react/jsx-runtime");
300
+ function AiContent({
301
+ marking,
302
+ as: Tag = "div",
303
+ labelPosition = "top",
304
+ locale,
305
+ className,
306
+ children
307
+ }) {
308
+ const m = (0, import_react5.useMemo)(() => (0, import_witness4.createMarking)(marking), [marking]);
309
+ const label = labelPosition === "none" ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
310
+ AiLabel,
311
+ {
312
+ kind: m.kind,
313
+ variant: labelPosition === "overlay" ? "overlay" : "inline",
314
+ createdAt: m.createdAt,
315
+ reviewed: m.humanReviewed,
316
+ ...m.generator ? { generator: m.generator } : {},
317
+ ...m.generatorVersion ? { generatorVersion: m.generatorVersion } : {},
318
+ ...m.disclosureUrl ? { href: m.disclosureUrl } : {},
319
+ ...locale ? { locale } : {}
320
+ }
321
+ );
322
+ const labelBlock = label && labelPosition !== "overlay" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { marginBlock: "0.5em" }, children: label }) : label;
323
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
324
+ Tag,
325
+ {
326
+ className: cx("witness-content", className),
327
+ style: labelPosition === "overlay" ? { position: "relative" } : void 0,
328
+ ...(0, import_witness4.markingAttributes)(m),
329
+ children: [
330
+ labelPosition === "bottom" ? null : labelBlock,
331
+ children,
332
+ labelPosition === "bottom" ? labelBlock : null
333
+ ]
334
+ }
335
+ );
336
+ }
337
+ // Annotate the CommonJS export names for ESM import in node:
338
+ 0 && (module.exports = {
339
+ AiContent,
340
+ AiLabel,
341
+ AiNotice,
342
+ WitnessProvider,
343
+ useAiDisclosure,
344
+ useWitnessMessages
345
+ });
346
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/AiContent.tsx","../src/AiLabel.tsx","../src/AiNotice.tsx","../src/context.tsx","../src/useAiDisclosure.ts"],"sourcesContent":["export { AiContent, type AiContentProps } from \"./AiContent.js\";\nexport { AiLabel, type AiLabelProps } from \"./AiLabel.js\";\nexport { AiNotice, type AiNoticeProps } from \"./AiNotice.js\";\nexport { useWitnessMessages, WitnessProvider, type WitnessProviderProps } from \"./context.js\";\nexport { type UseAiDisclosureResult, useAiDisclosure } from \"./useAiDisclosure.js\";\n","import {\n createMarking,\n type Marking,\n type MarkingInput,\n markingAttributes,\n} from \"@sweberdev/witness\";\nimport { type ElementType, type ReactNode, useMemo } from \"react\";\nimport { AiLabel } from \"./AiLabel.js\";\nimport { cx } from \"./AiNotice.js\";\n\nexport interface AiContentProps {\n marking: Marking | MarkingInput;\n /** Element that wraps label and content. Default `div`. */\n as?: ElementType;\n /** Text should be labelled at the top (default). Use `overlay` for images and video. */\n labelPosition?: \"top\" | \"bottom\" | \"overlay\" | \"none\";\n locale?: string | readonly string[];\n className?: string;\n children: ReactNode;\n}\n\n/**\n * Wraps AI-generated content: adds the `data-ai-*` marking attributes and a visible label.\n * With `labelPosition=\"overlay\"` the wrapper becomes `position: relative`.\n */\nexport function AiContent({\n marking,\n as: Tag = \"div\",\n labelPosition = \"top\",\n locale,\n className,\n children,\n}: AiContentProps) {\n const m = useMemo(() => createMarking(marking), [marking]);\n const label =\n labelPosition === \"none\" ? null : (\n <AiLabel\n kind={m.kind}\n variant={labelPosition === \"overlay\" ? \"overlay\" : \"inline\"}\n createdAt={m.createdAt}\n reviewed={m.humanReviewed}\n {...(m.generator ? { generator: m.generator } : {})}\n {...(m.generatorVersion ? { generatorVersion: m.generatorVersion } : {})}\n {...(m.disclosureUrl ? { href: m.disclosureUrl } : {})}\n {...(locale ? { locale } : {})}\n />\n );\n const labelBlock =\n label && labelPosition !== \"overlay\" ? (\n <div style={{ marginBlock: \"0.5em\" }}>{label}</div>\n ) : (\n label\n );\n return (\n <Tag\n className={cx(\"witness-content\", className)}\n style={labelPosition === \"overlay\" ? { position: \"relative\" } : undefined}\n {...markingAttributes(m)}\n >\n {labelPosition === \"bottom\" ? null : labelBlock}\n {children}\n {labelPosition === \"bottom\" ? labelBlock : null}\n </Tag>\n );\n}\n","import { type ContentKind, type DisclosureKind, format } from \"@sweberdev/witness\";\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport { cx } from \"./AiNotice.js\";\nimport { useWitnessMessages } from \"./context.js\";\n\nexport interface AiLabelProps {\n /** Default `generated`. */\n kind?: ContentKind | DisclosureKind;\n generator?: string;\n generatorVersion?: string;\n /** ISO date or timestamp. */\n createdAt?: string;\n /** A person reviewed the content and holds editorial responsibility. */\n reviewed?: boolean;\n /** Link to a page that explains how you use AI. */\n href?: string;\n locale?: string | readonly string[];\n /** `overlay` places the label in the top corner of a positioned parent, e.g. over an image. */\n variant?: \"inline\" | \"overlay\";\n className?: string;\n}\n\n/** A badge for AI-generated or AI-edited content. Clicking it shows what the label means. */\nexport function AiLabel({\n kind = \"generated\",\n generator,\n generatorVersion,\n createdAt,\n reviewed,\n href,\n locale,\n variant = \"inline\",\n className,\n}: AiLabelProps) {\n const { locale: code, messages } = useWitnessMessages(locale);\n const [open, setOpen] = useState(false);\n const panelId = useId();\n const root = useRef<HTMLSpanElement>(null);\n const button = useRef<HTMLButtonElement>(null);\n const text = messages.kinds[kind];\n const name = [generator, generatorVersion].filter(Boolean).join(\" \");\n\n useEffect(() => {\n if (!open) return;\n const onKey = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n setOpen(false);\n button.current?.focus();\n }\n };\n const onClick = (event: MouseEvent) => {\n if (root.current && !root.current.contains(event.target as Node)) setOpen(false);\n };\n document.addEventListener(\"keydown\", onKey);\n document.addEventListener(\"click\", onClick);\n return () => {\n document.removeEventListener(\"keydown\", onKey);\n document.removeEventListener(\"click\", onClick);\n };\n }, [open]);\n\n const facts: string[] = [];\n if (name) facts.push(format(messages.ui.generatedWith, { generator: name }));\n if (createdAt) facts.push(format(messages.ui.createdOn, { date: formatDate(createdAt, code) }));\n if (reviewed) facts.push(messages.ui.humanReviewed);\n\n return (\n <span\n ref={root}\n className={cx(\"witness-badge\", `witness-badge--${variant}`, className)}\n style={variant === \"overlay\" ? overlayStyle : inlineStyle}\n >\n <button\n ref={button}\n type=\"button\"\n className=\"witness-label\"\n style={{ margin: 0, font: \"inherit\", cursor: \"pointer\" }}\n aria-expanded={open}\n aria-controls={panelId}\n title={messages.ui.details}\n onClick={() => setOpen((value) => !value)}\n >\n <span className=\"witness-label__icon\" aria-hidden=\"true\">\n AI\n </span>\n <span className=\"witness-label__text\">{text.label}</span>\n </button>\n <span\n id={panelId}\n role=\"dialog\"\n aria-label={text.title}\n className=\"witness-badge__panel\"\n hidden={!open}\n style={variant === \"overlay\" ? { ...panelStyle, right: 0 } : { ...panelStyle, left: 0 }}\n >\n <strong style={{ display: \"block\", marginBottom: \"0.25em\" }}>{text.title}</strong>\n <span style={{ display: \"block\" }}>{text.body}</span>\n {facts.length > 0 ? (\n <ul style={{ margin: \"0.4em 0\", paddingInlineStart: \"1.1em\" }}>\n {facts.map((fact) => (\n <li key={fact}>{fact}</li>\n ))}\n </ul>\n ) : null}\n {href ? <a href={href}>{messages.ui.moreInfo}</a> : null}\n </span>\n </span>\n );\n}\n\nconst inlineStyle = { position: \"relative\", display: \"inline-block\" } as const;\nconst overlayStyle = { position: \"absolute\", top: \"0.5em\", right: \"0.5em\", zIndex: 1 } as const;\nconst panelStyle = {\n position: \"absolute\",\n top: \"calc(100% + 0.4em)\",\n zIndex: 10,\n width: \"max-content\",\n maxWidth: \"min(22em, 80vw)\",\n padding: \"0.75em 0.875em\",\n border: \"1px solid var(--witness-border, #d7dbe3)\",\n borderRadius: \"var(--witness-radius, 8px)\",\n background: \"var(--witness-bg, #fff)\",\n color: \"var(--witness-fg, #1a1a1a)\",\n boxShadow: \"0 6px 24px rgb(0 0 0 / 0.15)\",\n lineHeight: 1.45,\n fontSize: \"0.875rem\",\n textAlign: \"start\",\n} as const;\n\nfunction formatDate(value: string, locale: string): string {\n const date = new Date(value);\n if (Number.isNaN(date.getTime())) return value;\n try {\n return new Intl.DateTimeFormat(locale, { dateStyle: \"medium\" }).format(date);\n } catch {\n return value;\n }\n}\n","import type { DisclosureEvent, DisclosureKind } from \"@sweberdev/witness\";\nimport { type ReactNode, useEffect, useId, useState } from \"react\";\nimport { useWitnessMessages } from \"./context.js\";\nimport { useAiDisclosure } from \"./useAiDisclosure.js\";\n\nexport interface AiNoticeProps {\n /** Default `chatbot`. Also fits `emotion-recognition` and `biometric-categorisation`. */\n kind?: DisclosureKind;\n /** Your id for this disclosure. Default: the kind. */\n id?: string;\n /** Bump when the wording changes, so people see it again. Default \"1\". */\n version?: string;\n locale?: string | readonly string[];\n /** Link to a page that explains how you use AI. */\n href?: string;\n storage?: \"local\" | \"session\" | \"memory\";\n /** Evidence hook: called when the notice is shown and acknowledged. */\n onEvent?: (event: DisclosureEvent) => void;\n /** Replaces the default body text. */\n children?: ReactNode;\n className?: string;\n}\n\n/**\n * The AI notice for a chat (Art. 50(1)): expanded until acknowledged, then a compact label\n * that stays visible and can be reopened. Style it with `@sweberdev/witness/styles.css`.\n */\nexport function AiNotice({\n kind = \"chatbot\",\n id,\n version,\n locale,\n href,\n storage,\n onEvent,\n children,\n className,\n}: AiNoticeProps) {\n const { locale: code, messages } = useWitnessMessages(locale);\n const disclosure = useAiDisclosure({\n kind,\n locale: code,\n ...(id ? { id } : {}),\n ...(version ? { version } : {}),\n ...(storage ? { storage } : {}),\n ...(onEvent ? { onEvent } : {}),\n });\n const [reopened, setReopened] = useState(false);\n const titleId = useId();\n const text = messages.kinds[kind];\n const full = reopened || disclosure.needsAcknowledgement;\n const { markShown } = disclosure;\n\n useEffect(() => {\n if (full) markShown();\n }, [full, markShown]);\n\n if (!full) {\n return (\n <button\n type=\"button\"\n className={cx(\"witness-notice--compact\", className)}\n aria-label={`${text.label}: ${messages.ui.details}`}\n onClick={() => setReopened(true)}\n >\n <span className=\"witness-label__icon\" aria-hidden=\"true\">\n AI\n </span>\n {text.label}\n </button>\n );\n }\n\n return (\n <section className={cx(\"witness-notice\", className)} role=\"note\" aria-labelledby={titleId}>\n <span className=\"witness-label__icon\" aria-hidden=\"true\">\n AI\n </span>\n <div>\n <h2 id={titleId} className=\"witness-notice__title\">\n {text.title}\n </h2>\n <p className=\"witness-notice__body\">{children ?? text.body}</p>\n <div className=\"witness-notice__actions\">\n <button\n type=\"button\"\n className=\"witness-notice__ack\"\n onClick={() => {\n setReopened(false);\n disclosure.acknowledge();\n }}\n >\n {messages.ui.acknowledge}\n </button>\n {href ? <a href={href}>{messages.ui.moreInfo}</a> : null}\n </div>\n </div>\n </section>\n );\n}\n\nexport function cx(...names: Array<string | undefined | false>): string {\n return names.filter(Boolean).join(\" \");\n}\n","import {\n getMessages,\n type LocaleMessages,\n type LocaleOverride,\n resolveLocale,\n} from \"@sweberdev/witness\";\nimport { createContext, type ReactNode, useContext, useMemo } from \"react\";\n\ninterface WitnessContextValue {\n locale: string;\n messages: LocaleMessages;\n}\n\nconst WitnessContext = createContext<WitnessContextValue | null>(null);\n\nexport interface WitnessProviderProps {\n /** A locale tag such as \"de-CH\", or a list such as `navigator.languages`. Default \"en\". */\n locale?: string | readonly string[];\n /** Overrides for the wording, e.g. the informal \"du\" in German. */\n messages?: LocaleOverride;\n children: ReactNode;\n}\n\n/** Sets the language and wording for all Witness components below it. */\nexport function WitnessProvider({ locale, messages, children }: WitnessProviderProps) {\n const value = useMemo(\n () => ({ locale: resolveLocale(locale), messages: getMessages(locale, messages) }),\n [locale, messages],\n );\n return <WitnessContext.Provider value={value}>{children}</WitnessContext.Provider>;\n}\n\n/** The active locale and messages. A `locale` prop on a component wins over the provider. */\nexport function useWitnessMessages(locale?: string | readonly string[]): WitnessContextValue {\n const context = useContext(WitnessContext);\n return useMemo(() => {\n if (locale) return { locale: resolveLocale(locale), messages: getMessages(locale) };\n return context ?? { locale: \"en\", messages: getMessages(\"en\") };\n }, [context, locale]);\n}\n","import { createDisclosure, type Disclosure, type DisclosureOptions } from \"@sweberdev/witness\";\nimport { useCallback, useMemo, useRef, useSyncExternalStore } from \"react\";\n\nexport interface UseAiDisclosureResult {\n /** True until the current version was acknowledged. Always true during server rendering. */\n needsAcknowledgement: boolean;\n acknowledgedAt: string | null;\n acknowledge: () => void;\n /** Records that the notice was rendered (emits a `shown` event once). */\n markShown: () => void;\n reset: () => void;\n disclosure: Disclosure;\n}\n\n/**\n * State for a custom AI disclosure UI. The server snapshot always needs acknowledgement, so\n * the full notice is in the server HTML and collapses after hydration for people who already\n * acknowledged it.\n */\nexport function useAiDisclosure(options: DisclosureOptions = {}): UseAiDisclosureResult {\n const onEvent = useRef(options.onEvent);\n onEvent.current = options.onEvent;\n const { id, kind, version, locale, storage } = options;\n\n const disclosure = useMemo(\n () =>\n createDisclosure({\n ...(id ? { id } : {}),\n ...(kind ? { kind } : {}),\n ...(version ? { version } : {}),\n ...(locale ? { locale } : {}),\n ...(storage ? { storage } : {}),\n onEvent: (event) => onEvent.current?.(event),\n }),\n [id, kind, version, locale, storage],\n );\n\n const subscribe = useCallback(\n (listener: () => void) => {\n const unsubscribe = disclosure.subscribe(listener);\n // Another tab acknowledged or reset: the browser tells us through a storage event.\n const onStorage = (event: StorageEvent) => {\n if (event.key === null || event.key.startsWith(\"witness:ack:\")) listener();\n };\n if (typeof window !== \"undefined\") window.addEventListener(\"storage\", onStorage);\n return () => {\n unsubscribe();\n if (typeof window !== \"undefined\") window.removeEventListener(\"storage\", onStorage);\n };\n },\n [disclosure],\n );\n const acknowledgedAt = useSyncExternalStore(\n subscribe,\n () => disclosure.acknowledgedAt(),\n () => null,\n );\n\n return {\n needsAcknowledgement: acknowledgedAt === null,\n acknowledgedAt,\n acknowledge: disclosure.acknowledge,\n markShown: disclosure.markShown,\n reset: disclosure.reset,\n disclosure,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,kBAKO;AACP,IAAAC,gBAA0D;;;ACN1D,IAAAC,kBAA8D;AAC9D,IAAAC,gBAAmD;;;ACAnD,IAAAC,gBAA2D;;;ACD3D,qBAKO;AACP,mBAAmE;AAuB1D;AAhBT,IAAM,qBAAiB,4BAA0C,IAAI;AAW9D,SAAS,gBAAgB,EAAE,QAAQ,UAAU,SAAS,GAAyB;AACpF,QAAM,YAAQ;AAAA,IACZ,OAAO,EAAE,YAAQ,8BAAc,MAAM,GAAG,cAAU,4BAAY,QAAQ,QAAQ,EAAE;AAAA,IAChF,CAAC,QAAQ,QAAQ;AAAA,EACnB;AACA,SAAO,4CAAC,eAAe,UAAf,EAAwB,OAAe,UAAS;AAC1D;AAGO,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_witness","import_react","import_witness","import_react","import_react","import_witness","import_react","import_jsx_runtime","import_jsx_runtime","import_jsx_runtime"]}
@@ -0,0 +1,96 @@
1
+ import * as react from 'react';
2
+ import { ElementType, ReactNode } from 'react';
3
+ import { Marking, MarkingInput, ContentKind, DisclosureKind, DisclosureEvent, LocaleOverride, LocaleMessages, Disclosure, DisclosureOptions } from '@sweberdev/witness';
4
+
5
+ interface AiContentProps {
6
+ marking: Marking | MarkingInput;
7
+ /** Element that wraps label and content. Default `div`. */
8
+ as?: ElementType;
9
+ /** Text should be labelled at the top (default). Use `overlay` for images and video. */
10
+ labelPosition?: "top" | "bottom" | "overlay" | "none";
11
+ locale?: string | readonly string[];
12
+ className?: string;
13
+ children: ReactNode;
14
+ }
15
+ /**
16
+ * Wraps AI-generated content: adds the `data-ai-*` marking attributes and a visible label.
17
+ * With `labelPosition="overlay"` the wrapper becomes `position: relative`.
18
+ */
19
+ declare function AiContent({ marking, as: Tag, labelPosition, locale, className, children, }: AiContentProps): react.JSX.Element;
20
+
21
+ interface AiLabelProps {
22
+ /** Default `generated`. */
23
+ kind?: ContentKind | DisclosureKind;
24
+ generator?: string;
25
+ generatorVersion?: string;
26
+ /** ISO date or timestamp. */
27
+ createdAt?: string;
28
+ /** A person reviewed the content and holds editorial responsibility. */
29
+ reviewed?: boolean;
30
+ /** Link to a page that explains how you use AI. */
31
+ href?: string;
32
+ locale?: string | readonly string[];
33
+ /** `overlay` places the label in the top corner of a positioned parent, e.g. over an image. */
34
+ variant?: "inline" | "overlay";
35
+ className?: string;
36
+ }
37
+ /** A badge for AI-generated or AI-edited content. Clicking it shows what the label means. */
38
+ declare function AiLabel({ kind, generator, generatorVersion, createdAt, reviewed, href, locale, variant, className, }: AiLabelProps): react.JSX.Element;
39
+
40
+ interface AiNoticeProps {
41
+ /** Default `chatbot`. Also fits `emotion-recognition` and `biometric-categorisation`. */
42
+ kind?: DisclosureKind;
43
+ /** Your id for this disclosure. Default: the kind. */
44
+ id?: string;
45
+ /** Bump when the wording changes, so people see it again. Default "1". */
46
+ version?: string;
47
+ locale?: string | readonly string[];
48
+ /** Link to a page that explains how you use AI. */
49
+ href?: string;
50
+ storage?: "local" | "session" | "memory";
51
+ /** Evidence hook: called when the notice is shown and acknowledged. */
52
+ onEvent?: (event: DisclosureEvent) => void;
53
+ /** Replaces the default body text. */
54
+ children?: ReactNode;
55
+ className?: string;
56
+ }
57
+ /**
58
+ * The AI notice for a chat (Art. 50(1)): expanded until acknowledged, then a compact label
59
+ * that stays visible and can be reopened. Style it with `@sweberdev/witness/styles.css`.
60
+ */
61
+ declare function AiNotice({ kind, id, version, locale, href, storage, onEvent, children, className, }: AiNoticeProps): react.JSX.Element;
62
+
63
+ interface WitnessContextValue {
64
+ locale: string;
65
+ messages: LocaleMessages;
66
+ }
67
+ interface WitnessProviderProps {
68
+ /** A locale tag such as "de-CH", or a list such as `navigator.languages`. Default "en". */
69
+ locale?: string | readonly string[];
70
+ /** Overrides for the wording, e.g. the informal "du" in German. */
71
+ messages?: LocaleOverride;
72
+ children: ReactNode;
73
+ }
74
+ /** Sets the language and wording for all Witness components below it. */
75
+ declare function WitnessProvider({ locale, messages, children }: WitnessProviderProps): react.JSX.Element;
76
+ /** The active locale and messages. A `locale` prop on a component wins over the provider. */
77
+ declare function useWitnessMessages(locale?: string | readonly string[]): WitnessContextValue;
78
+
79
+ interface UseAiDisclosureResult {
80
+ /** True until the current version was acknowledged. Always true during server rendering. */
81
+ needsAcknowledgement: boolean;
82
+ acknowledgedAt: string | null;
83
+ acknowledge: () => void;
84
+ /** Records that the notice was rendered (emits a `shown` event once). */
85
+ markShown: () => void;
86
+ reset: () => void;
87
+ disclosure: Disclosure;
88
+ }
89
+ /**
90
+ * State for a custom AI disclosure UI. The server snapshot always needs acknowledgement, so
91
+ * the full notice is in the server HTML and collapses after hydration for people who already
92
+ * acknowledged it.
93
+ */
94
+ declare function useAiDisclosure(options?: DisclosureOptions): UseAiDisclosureResult;
95
+
96
+ export { AiContent, type AiContentProps, AiLabel, type AiLabelProps, AiNotice, type AiNoticeProps, type UseAiDisclosureResult, WitnessProvider, type WitnessProviderProps, useAiDisclosure, useWitnessMessages };
@@ -0,0 +1,96 @@
1
+ import * as react from 'react';
2
+ import { ElementType, ReactNode } from 'react';
3
+ import { Marking, MarkingInput, ContentKind, DisclosureKind, DisclosureEvent, LocaleOverride, LocaleMessages, Disclosure, DisclosureOptions } from '@sweberdev/witness';
4
+
5
+ interface AiContentProps {
6
+ marking: Marking | MarkingInput;
7
+ /** Element that wraps label and content. Default `div`. */
8
+ as?: ElementType;
9
+ /** Text should be labelled at the top (default). Use `overlay` for images and video. */
10
+ labelPosition?: "top" | "bottom" | "overlay" | "none";
11
+ locale?: string | readonly string[];
12
+ className?: string;
13
+ children: ReactNode;
14
+ }
15
+ /**
16
+ * Wraps AI-generated content: adds the `data-ai-*` marking attributes and a visible label.
17
+ * With `labelPosition="overlay"` the wrapper becomes `position: relative`.
18
+ */
19
+ declare function AiContent({ marking, as: Tag, labelPosition, locale, className, children, }: AiContentProps): react.JSX.Element;
20
+
21
+ interface AiLabelProps {
22
+ /** Default `generated`. */
23
+ kind?: ContentKind | DisclosureKind;
24
+ generator?: string;
25
+ generatorVersion?: string;
26
+ /** ISO date or timestamp. */
27
+ createdAt?: string;
28
+ /** A person reviewed the content and holds editorial responsibility. */
29
+ reviewed?: boolean;
30
+ /** Link to a page that explains how you use AI. */
31
+ href?: string;
32
+ locale?: string | readonly string[];
33
+ /** `overlay` places the label in the top corner of a positioned parent, e.g. over an image. */
34
+ variant?: "inline" | "overlay";
35
+ className?: string;
36
+ }
37
+ /** A badge for AI-generated or AI-edited content. Clicking it shows what the label means. */
38
+ declare function AiLabel({ kind, generator, generatorVersion, createdAt, reviewed, href, locale, variant, className, }: AiLabelProps): react.JSX.Element;
39
+
40
+ interface AiNoticeProps {
41
+ /** Default `chatbot`. Also fits `emotion-recognition` and `biometric-categorisation`. */
42
+ kind?: DisclosureKind;
43
+ /** Your id for this disclosure. Default: the kind. */
44
+ id?: string;
45
+ /** Bump when the wording changes, so people see it again. Default "1". */
46
+ version?: string;
47
+ locale?: string | readonly string[];
48
+ /** Link to a page that explains how you use AI. */
49
+ href?: string;
50
+ storage?: "local" | "session" | "memory";
51
+ /** Evidence hook: called when the notice is shown and acknowledged. */
52
+ onEvent?: (event: DisclosureEvent) => void;
53
+ /** Replaces the default body text. */
54
+ children?: ReactNode;
55
+ className?: string;
56
+ }
57
+ /**
58
+ * The AI notice for a chat (Art. 50(1)): expanded until acknowledged, then a compact label
59
+ * that stays visible and can be reopened. Style it with `@sweberdev/witness/styles.css`.
60
+ */
61
+ declare function AiNotice({ kind, id, version, locale, href, storage, onEvent, children, className, }: AiNoticeProps): react.JSX.Element;
62
+
63
+ interface WitnessContextValue {
64
+ locale: string;
65
+ messages: LocaleMessages;
66
+ }
67
+ interface WitnessProviderProps {
68
+ /** A locale tag such as "de-CH", or a list such as `navigator.languages`. Default "en". */
69
+ locale?: string | readonly string[];
70
+ /** Overrides for the wording, e.g. the informal "du" in German. */
71
+ messages?: LocaleOverride;
72
+ children: ReactNode;
73
+ }
74
+ /** Sets the language and wording for all Witness components below it. */
75
+ declare function WitnessProvider({ locale, messages, children }: WitnessProviderProps): react.JSX.Element;
76
+ /** The active locale and messages. A `locale` prop on a component wins over the provider. */
77
+ declare function useWitnessMessages(locale?: string | readonly string[]): WitnessContextValue;
78
+
79
+ interface UseAiDisclosureResult {
80
+ /** True until the current version was acknowledged. Always true during server rendering. */
81
+ needsAcknowledgement: boolean;
82
+ acknowledgedAt: string | null;
83
+ acknowledge: () => void;
84
+ /** Records that the notice was rendered (emits a `shown` event once). */
85
+ markShown: () => void;
86
+ reset: () => void;
87
+ disclosure: Disclosure;
88
+ }
89
+ /**
90
+ * State for a custom AI disclosure UI. The server snapshot always needs acknowledgement, so
91
+ * the full notice is in the server HTML and collapses after hydration for people who already
92
+ * acknowledged it.
93
+ */
94
+ declare function useAiDisclosure(options?: DisclosureOptions): UseAiDisclosureResult;
95
+
96
+ export { AiContent, type AiContentProps, AiLabel, type AiLabelProps, AiNotice, type AiNoticeProps, type UseAiDisclosureResult, WitnessProvider, type WitnessProviderProps, useAiDisclosure, useWitnessMessages };