@birdapi/velinstyle 1.2.0 → 1.2.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 (39) hide show
  1. package/README.de.md +22 -19
  2. package/README.md +24 -25
  3. package/cli/cli-manifest.json +1 -1
  4. package/cli/docgen/extract-attributes.js +2 -0
  5. package/cli/index.js +32 -3
  6. package/cli/transparency.js +221 -0
  7. package/core/a11y/component-contracts.json +1 -1
  8. package/core/attributes/registry.js +14 -0
  9. package/core/meta/schema.js +10 -0
  10. package/core/transparency/attach.js +74 -0
  11. package/core/transparency/claims.js +97 -0
  12. package/core/transparency/doctor.js +142 -0
  13. package/core/transparency/engine.js +75 -0
  14. package/core/transparency/export.js +98 -0
  15. package/core/transparency/index.js +30 -0
  16. package/core/transparency/migrate.js +130 -0
  17. package/core/transparency/normalize.js +125 -0
  18. package/core/transparency/policy.js +105 -0
  19. package/core/transparency/providers.js +235 -0
  20. package/core/transparency/registry.js +104 -0
  21. package/core/transparency/renderer.js +111 -0
  22. package/core/transparency/reporter.js +113 -0
  23. package/core/transparency/validator.js +112 -0
  24. package/dist/chunks/attach-H2ZSEAE6.js +365 -0
  25. package/dist/chunks/attributes-DZCXX2RZ.js +404 -0
  26. package/dist/chunks/chunk-CQMTCEI6.js +113 -0
  27. package/dist/chunks/runtime-entry.js +1 -1
  28. package/dist/llms.txt +3 -2
  29. package/dist/search-index.json +28 -2
  30. package/dist/velin-agent.json +10 -6
  31. package/dist/velinstyle-components.iife.js +411 -2
  32. package/dist/velinstyle-components.js +411 -2
  33. package/dist/velinstyle-components.min.js +113 -113
  34. package/dist/velinstyle.css +160 -0
  35. package/dist/velinstyle.min.css +1 -1
  36. package/package.json +2 -1
  37. package/packages/velinstyle-skills/catalog.json +1 -1
  38. package/src/components/transparency.css +138 -0
  39. package/src/velinstyle.css +1 -0
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Build report artifacts from a doctor result.
3
+ * @param {Awaited<ReturnType<import('./doctor.js').transparencyDoctor>>} report
4
+ * @param {{ title?: string }} [opts]
5
+ */
6
+ export function buildTransparencyReports(report, opts = {}) {
7
+ const title = opts.title || 'Velin Transparency Report';
8
+ const json = {
9
+ schema: 'velinstyle.transparency.report',
10
+ version: 1,
11
+ generatedAt: new Date().toISOString(),
12
+ title,
13
+ ...report,
14
+ };
15
+ const sarif = toSarif(report, title);
16
+ const html = toHtml(report, title);
17
+ return { json, sarif, html };
18
+ }
19
+
20
+ function toSarif(report, title) {
21
+ const results = (report.findings || []).map((f) => ({
22
+ ruleId: f.code,
23
+ level: f.severity === 'error' ? 'error' : f.severity === 'warning' ? 'warning' : 'note',
24
+ message: { text: f.message },
25
+ locations: f.id || f.target
26
+ ? [{
27
+ physicalLocation: {
28
+ artifactLocation: { uri: report.file || 'document.html' },
29
+ region: { snippet: { text: f.id || f.target?.src || '' } },
30
+ },
31
+ }]
32
+ : [],
33
+ }));
34
+ return {
35
+ $schema: 'https://json.schemastore.org/sarif-2.1.0.json',
36
+ version: '2.1.0',
37
+ runs: [{
38
+ tool: {
39
+ driver: {
40
+ name: 'velinstyle-transparency',
41
+ informationUri: 'https://velinstyle.info',
42
+ rules: [],
43
+ },
44
+ },
45
+ results,
46
+ properties: { title, scores: report.scores },
47
+ }],
48
+ };
49
+ }
50
+
51
+ function toHtml(report, title) {
52
+ const scores = report.scores || {};
53
+ const rows = (report.findings || []).map((f) => `
54
+ <tr>
55
+ <td>${esc(f.severity)}</td>
56
+ <td><code>${esc(f.code)}</code></td>
57
+ <td>${esc(f.message)}</td>
58
+ <td>${esc(f.id || '')}</td>
59
+ </tr>`).join('');
60
+ const items = (report.registry?.items || []).map((r) => `
61
+ <tr>
62
+ <td><code>${esc(r.id)}</code></td>
63
+ <td>${esc(r.type)}</td>
64
+ <td>${esc(r.label)}</td>
65
+ <td>${esc((r.claims || []).join(', '))}</td>
66
+ <td>${esc(JSON.stringify(r.provenance || {}))}</td>
67
+ </tr>`).join('');
68
+ return `<!DOCTYPE html>
69
+ <html lang="en">
70
+ <head>
71
+ <meta charset="utf-8">
72
+ <title>${esc(title)}</title>
73
+ <style>
74
+ body{font-family:system-ui,sans-serif;margin:2rem;background:#0c0b0a;color:#f5f2eb}
75
+ table{border-collapse:collapse;width:100%;margin-block:1rem}
76
+ th,td{border:1px solid #333;padding:.5rem;text-align:left;vertical-align:top}
77
+ th{background:#1a1917}
78
+ .scores{display:flex;flex-wrap:wrap;gap:.75rem}
79
+ .score{padding:.75rem 1rem;background:#1a1917;border-radius:8px;min-width:7rem}
80
+ .ok{color:#7ddea0}.bad{color:#f5a5a5}
81
+ </style>
82
+ </head>
83
+ <body>
84
+ <h1>${esc(title)}</h1>
85
+ <p class="${report.ok ? 'ok' : 'bad'}">${report.ok ? 'PASS' : 'FAIL'} — ${report.summary?.errors || 0} errors, ${report.summary?.warnings || 0} warnings</p>
86
+ <div class="scores">
87
+ ${scoreCard('Transparency', scores.transparency)}
88
+ ${scoreCard('AI', scores.ai)}
89
+ ${scoreCard('Trust', scores.trust)}
90
+ ${scoreCard('Metadata', scores.metadata)}
91
+ ${scoreCard('Compliance', scores.compliance)}
92
+ ${scoreCard('Provenance', scores.provenance)}
93
+ </div>
94
+ <h2>Findings</h2>
95
+ <table><thead><tr><th>Severity</th><th>Code</th><th>Message</th><th>Id</th></tr></thead><tbody>${rows || '<tr><td colspan="4">None</td></tr>'}</tbody></table>
96
+ <h2>Registry</h2>
97
+ <table><thead><tr><th>Id</th><th>Type</th><th>Label</th><th>Claims</th><th>Provenance</th></tr></thead><tbody>${items || '<tr><td colspan="5">Empty</td></tr>'}</tbody></table>
98
+ </body>
99
+ </html>`;
100
+ }
101
+
102
+ function scoreCard(name, value) {
103
+ const v = value == null ? '—' : `${value}%`;
104
+ return `<div class="score"><strong>${esc(name)}</strong><div>${v}</div></div>`;
105
+ }
106
+
107
+ function esc(s) {
108
+ return String(s ?? '')
109
+ .replace(/&/g, '&amp;')
110
+ .replace(/</g, '&lt;')
111
+ .replace(/>/g, '&gt;')
112
+ .replace(/"/g, '&quot;');
113
+ }
@@ -0,0 +1,112 @@
1
+ import { CLAIM_CATALOG } from './claims.js';
2
+ import { requiredProvenanceFields } from './policy.js';
3
+
4
+ const VALID_STATUS = new Set([
5
+ 'generated', 'assisted', 'ai-assisted', 'human-reviewed', 'human-edited', 'verified', 'edited', 'draft',
6
+ ]);
7
+ const VALID_REVIEW = new Set(['human', 'human-reviewed', 'verified', 'none']);
8
+ const VALID_TYPES = new Set([
9
+ 'ai', 'trust', 'compliance', 'metadata', 'review', 'verification', 'license',
10
+ 'accessibility', 'security', 'custom', 'image', 'video', 'audio', 'text', 'pdf', 'document',
11
+ ]);
12
+
13
+ /**
14
+ * @param {import('./registry.js').DisclosureRecord} record
15
+ * @param {object} policy
16
+ */
17
+ export function validateRecord(record, policy) {
18
+ const findings = [];
19
+ if (!record?.id) {
20
+ findings.push(finding('error', 'invalid.id', 'Disclosure missing id'));
21
+ }
22
+ if (record.type && !VALID_TYPES.has(String(record.type).toLowerCase())) {
23
+ findings.push(finding('warning', 'invalid.type', `Unknown type "${record.type}"`, record.id));
24
+ }
25
+ if (record.status && !VALID_STATUS.has(String(record.status).toLowerCase())) {
26
+ findings.push(finding('error', 'invalid.status', `Invalid status "${record.status}"`, record.id));
27
+ }
28
+ if (record.review && !VALID_REVIEW.has(String(record.review).toLowerCase())) {
29
+ findings.push(finding('error', 'invalid.review', `Invalid review "${record.review}"`, record.id));
30
+ }
31
+ if (!record.label) {
32
+ findings.push(finding('warning', 'missing.label', 'Missing label', record.id));
33
+ }
34
+ if (policy.rules?.requireReview && !record.review && !record.claims?.includes('review.human')) {
35
+ findings.push(finding('error', 'policy.requireReview', 'Policy requires review', record.id));
36
+ }
37
+ if (policy.rules?.allowGenerated === false && record.claims?.includes('ai.generated')) {
38
+ findings.push(finding('error', 'policy.allowGenerated', 'Generated content not allowed by policy', record.id));
39
+ }
40
+ if (policy.rules?.minimumStatus === 'human-reviewed') {
41
+ const ok = record.claims?.includes('review.human') || record.claims?.includes('review.verified')
42
+ || record.review === 'human' || record.review === 'human-reviewed' || record.review === 'verified';
43
+ if (!ok && (record.claims?.includes('ai.generated') || record.claims?.includes('ai.assisted'))) {
44
+ findings.push(finding('error', 'policy.minimumStatus', 'minimumStatus human-reviewed not met', record.id));
45
+ }
46
+ }
47
+ for (const claim of record.claims || []) {
48
+ if (!CLAIM_CATALOG[claim] && !String(claim).startsWith('custom.')) {
49
+ findings.push(finding('warning', 'unknown.claim', `Unknown claim "${claim}"`, record.id));
50
+ }
51
+ }
52
+ const mediaKind = inferMediaKind(record);
53
+ const required = requiredProvenanceFields(mediaKind, policy);
54
+ for (const field of required) {
55
+ if (!record.provenance?.[field]) {
56
+ findings.push(finding('error', `missing-provenance.${field}`, `Missing provenance.${field}`, record.id));
57
+ }
58
+ }
59
+ for (const field of policy.provenance?.recommended || []) {
60
+ if (!record.provenance?.[field]) {
61
+ findings.push(finding('info', `recommended-provenance.${field}`, `Recommended provenance.${field}`, record.id));
62
+ }
63
+ }
64
+ if (record.updated || record.provenance?.reviewedAt) {
65
+ const staleDays = policy.rules?.staleDays ?? 365;
66
+ const dateStr = record.provenance?.reviewedAt || record.updated;
67
+ const age = ageDays(dateStr);
68
+ if (age != null && age > staleDays) {
69
+ findings.push(finding('warning', 'stale-reviewedAt', `Review/update is ${age} days old (limit ${staleDays})`, record.id));
70
+ }
71
+ }
72
+ return findings;
73
+ }
74
+
75
+ /**
76
+ * @param {import('./registry.js').DisclosureRecord[]} records
77
+ * @param {object} policy
78
+ */
79
+ export function validateRecords(records, policy) {
80
+ const findings = [];
81
+ const seen = new Map();
82
+ for (const r of records) {
83
+ if (seen.has(r.id)) {
84
+ findings.push(finding('error', 'duplicate.id', `Duplicate disclosure id "${r.id}"`, r.id));
85
+ }
86
+ seen.set(r.id, true);
87
+ findings.push(...validateRecord(r, policy));
88
+ }
89
+ return findings;
90
+ }
91
+
92
+ export function inferMediaKind(record) {
93
+ const tag = String(record.target?.tag || '').toUpperCase();
94
+ const type = String(record.type || '').toLowerCase();
95
+ const src = String(record.target?.src || '');
96
+ if (tag === 'IMG' || type === 'image' || /\.(png|jpe?g|webp|gif|svg)(\?|$)/i.test(src)) return 'images';
97
+ if (tag === 'VIDEO' || type === 'video' || /\.(mp4|webm|mov)(\?|$)/i.test(src)) return 'videos';
98
+ if (tag === 'AUDIO' || type === 'audio' || /\.(mp3|wav|ogg)(\?|$)/i.test(src)) return 'audio';
99
+ if (type === 'pdf' || /\.pdf(\?|$)/i.test(src)) return 'pdf';
100
+ return 'text';
101
+ }
102
+
103
+ function ageDays(dateStr) {
104
+ if (!dateStr) return null;
105
+ const t = Date.parse(dateStr);
106
+ if (Number.isNaN(t)) return null;
107
+ return Math.floor((Date.now() - t) / 86400000);
108
+ }
109
+
110
+ function finding(severity, code, message, id) {
111
+ return { severity, code, message, id: id || null };
112
+ }
@@ -0,0 +1,365 @@
1
+ // core/transparency/claims.js
2
+ var CLAIM_CATALOG = {
3
+ "ai.generated": { pillar: "ai", label: { en: "AI generated", de: "KI-generiert" } },
4
+ "ai.assisted": { pillar: "ai", label: { en: "AI assisted", de: "KI-unterst\xFCtzt" } },
5
+ "review.human": { pillar: "ai", label: { en: "Human reviewed", de: "Mensch gepr\xFCft" } },
6
+ "review.verified": { pillar: "trust", label: { en: "Verified", de: "Verifiziert" } },
7
+ "security.checked": { pillar: "trust", label: { en: "Security checked", de: "Security gepr\xFCft" } },
8
+ "accessibility.checked": { pillar: "trust", label: { en: "Accessibility checked", de: "Barrierefreiheit gepr\xFCft" } },
9
+ "trust.official": { pillar: "trust", label: { en: "Official", de: "Offiziell" } },
10
+ "trust.signed": { pillar: "trust", label: { en: "Signed", de: "Signiert" } },
11
+ "trust.opensource": { pillar: "trust", label: { en: "Open source", de: "Open Source" } },
12
+ "privacy.gdpr": { pillar: "compliance", label: { en: "GDPR", de: "DSGVO" } },
13
+ "license.cc-by": { pillar: "compliance", label: { en: "CC BY", de: "CC BY" } },
14
+ "license.mit": { pillar: "compliance", label: { en: "MIT", de: "MIT" } },
15
+ "license.apache-2": { pillar: "compliance", label: { en: "Apache-2.0", de: "Apache-2.0" } },
16
+ "content.updated": { pillar: "metadata", label: { en: "Updated", de: "Aktualisiert" } },
17
+ "content.author": { pillar: "metadata", label: { en: "Author", de: "Autor" } },
18
+ "content.source": { pillar: "metadata", label: { en: "Source", de: "Quelle" } },
19
+ "content.language": { pillar: "metadata", label: { en: "Language", de: "Sprache" } },
20
+ "version.current": { pillar: "metadata", label: { en: "Version", de: "Version" } },
21
+ "provenance.complete": { pillar: "provenance", label: { en: "Provenance complete", de: "Nachweis vollst\xE4ndig" } }
22
+ };
23
+ var STATUS_TO_CLAIM = {
24
+ generated: "ai.generated",
25
+ assisted: "ai.assisted",
26
+ "ai-assisted": "ai.assisted",
27
+ "human-reviewed": "review.human",
28
+ "human-edited": "review.human",
29
+ verified: "review.verified",
30
+ edited: "review.human",
31
+ draft: null
32
+ };
33
+ var REVIEW_TO_CLAIM = {
34
+ human: "review.human",
35
+ "human-reviewed": "review.human",
36
+ verified: "review.verified",
37
+ none: null
38
+ };
39
+ var LICENSE_TO_CLAIM = {
40
+ "cc by 4.0": "license.cc-by",
41
+ "cc-by": "license.cc-by",
42
+ "cc-by-4.0": "license.cc-by",
43
+ mit: "license.mit",
44
+ "apache-2.0": "license.apache-2",
45
+ apache: "license.apache-2"
46
+ };
47
+ function deriveClaims({ status, review, license, claims = [] } = {}) {
48
+ const out = new Set(Array.isArray(claims) ? claims.filter(Boolean) : []);
49
+ const statusClaim = STATUS_TO_CLAIM[String(status || "").toLowerCase()];
50
+ if (statusClaim) out.add(statusClaim);
51
+ const reviewClaim = REVIEW_TO_CLAIM[String(review || "").toLowerCase()];
52
+ if (reviewClaim) out.add(reviewClaim);
53
+ if (license) {
54
+ const key = String(license).toLowerCase().trim();
55
+ const mapped = LICENSE_TO_CLAIM[key] || (key.startsWith("cc") ? "license.cc-by" : null);
56
+ if (mapped) out.add(mapped);
57
+ }
58
+ return [...out];
59
+ }
60
+ function claimLabel(claim, lang = "en") {
61
+ const entry = CLAIM_CATALOG[claim];
62
+ if (!entry) return claim;
63
+ return entry.label[lang] || entry.label.en || claim;
64
+ }
65
+ function primaryLabel(claims = [], lang = "en") {
66
+ const order = ["ai.generated", "ai.assisted", "review.human", "review.verified", "trust.official", "license.cc-by", "license.mit"];
67
+ for (const c of order) {
68
+ if (claims.includes(c)) return claimLabel(c, lang);
69
+ }
70
+ if (claims[0]) return claimLabel(claims[0], lang);
71
+ return lang === "de" ? "Transparenz" : "Transparency";
72
+ }
73
+
74
+ // core/transparency/registry.js
75
+ function createRegistry() {
76
+ const map = /* @__PURE__ */ new Map();
77
+ return {
78
+ register(record) {
79
+ if (!record?.id) throw new Error("DisclosureRecord requires id");
80
+ map.set(record.id, structuredCloneSafe(record));
81
+ return map.get(record.id);
82
+ },
83
+ get(id) {
84
+ return map.get(id) || null;
85
+ },
86
+ has(id) {
87
+ return map.has(id);
88
+ },
89
+ remove(id) {
90
+ return map.delete(id);
91
+ },
92
+ list() {
93
+ return [...map.values()].map((r) => structuredCloneSafe(r));
94
+ },
95
+ query(predicate) {
96
+ return this.list().filter(predicate);
97
+ },
98
+ clear() {
99
+ map.clear();
100
+ },
101
+ size() {
102
+ return map.size;
103
+ },
104
+ export() {
105
+ return { schema: "velinstyle.transparency.registry", version: 1, items: this.list() };
106
+ },
107
+ diff(otherList = []) {
108
+ const other = new Map(otherList.map((r) => [r.id, r]));
109
+ const added = [];
110
+ const removed = [];
111
+ const changed = [];
112
+ for (const r of map.values()) {
113
+ if (!other.has(r.id)) added.push(r.id);
114
+ else if (JSON.stringify(r) !== JSON.stringify(other.get(r.id))) changed.push(r.id);
115
+ }
116
+ for (const id of other.keys()) {
117
+ if (!map.has(id)) removed.push(id);
118
+ }
119
+ return { added, removed, changed };
120
+ }
121
+ };
122
+ }
123
+ function structuredCloneSafe(obj) {
124
+ return JSON.parse(JSON.stringify(obj));
125
+ }
126
+ function stableDisclosureId(parts = {}) {
127
+ if (parts.id) return String(parts.id).trim();
128
+ const raw = [parts.file || "", parts.selector || "", parts.src || "", parts.tag || "", parts.type || ""].join("|").toLowerCase();
129
+ let h = 2166136261;
130
+ for (let i = 0; i < raw.length; i += 1) {
131
+ h ^= raw.charCodeAt(i);
132
+ h = Math.imul(h, 16777619);
133
+ }
134
+ return `tx-${(h >>> 0).toString(16)}`;
135
+ }
136
+
137
+ // core/transparency/normalize.js
138
+ var PROVENANCE_KEYS = [
139
+ "createdBy",
140
+ "createdAt",
141
+ "reviewedAt",
142
+ "approvedBy",
143
+ "source",
144
+ "license",
145
+ "version",
146
+ "publishedAt"
147
+ ];
148
+ function normalizeDisclosure(draft = {}, ctx = {}) {
149
+ const provider = String(draft.provider || ctx.provider || "api");
150
+ const type = String(draft.type || "ai").toLowerCase();
151
+ const status = draft.status != null ? String(draft.status).toLowerCase() : void 0;
152
+ const review = draft.review != null ? String(draft.review).toLowerCase() : void 0;
153
+ const provenance = normalizeProvenance(draft.provenance || draft);
154
+ if (draft.license && !provenance.license) provenance.license = String(draft.license);
155
+ if (draft.model && !provenance.source) provenance.source = `model:${draft.model}`;
156
+ if (draft.generated === true && !status) {
157
+ }
158
+ const resolvedStatus = status || (draft.generated === true ? "generated" : void 0);
159
+ const claims = deriveClaims({
160
+ status: resolvedStatus,
161
+ review,
162
+ license: provenance.license,
163
+ claims: draft.claims
164
+ });
165
+ const target = {
166
+ selector: draft.target?.selector || draft.selector || void 0,
167
+ tag: draft.target?.tag || draft.tag || void 0,
168
+ src: draft.target?.src || draft.src || void 0,
169
+ file: draft.target?.file || ctx.file || draft.file || void 0
170
+ };
171
+ const id = stableDisclosureId({
172
+ id: draft.id || draft.velinTransparencyId,
173
+ selector: target.selector,
174
+ src: target.src,
175
+ tag: target.tag,
176
+ type,
177
+ file: target.file
178
+ });
179
+ const lang = ctx.lang === "de" ? "de" : "en";
180
+ const label = draft.label ? String(draft.label) : primaryLabel(claims, lang);
181
+ const updated = draft.updated || provenance.publishedAt || provenance.reviewedAt || provenance.createdAt || void 0;
182
+ return {
183
+ id,
184
+ type,
185
+ status: resolvedStatus,
186
+ review,
187
+ provider,
188
+ claims,
189
+ provenance,
190
+ updated,
191
+ label,
192
+ description: draft.description ? String(draft.description) : void 0,
193
+ renderer: draft.renderer || draft.overlay || "badge",
194
+ tone: draft.tone || toneFromClaims(claims),
195
+ position: draft.position || "top-right",
196
+ target,
197
+ meta: draft.meta && typeof draft.meta === "object" ? draft.meta : void 0
198
+ };
199
+ }
200
+ function normalizeProvenance(src = {}) {
201
+ const out = {};
202
+ for (const key of PROVENANCE_KEYS) {
203
+ const v = src[key] ?? src[key.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)];
204
+ if (v != null && String(v).trim()) out[key] = String(v).trim();
205
+ }
206
+ if (src["created-by"]) out.createdBy = String(src["created-by"]);
207
+ if (src["created-at"]) out.createdAt = String(src["created-at"]);
208
+ if (src["reviewed-at"]) out.reviewedAt = String(src["reviewed-at"]);
209
+ if (src["approved-by"]) out.approvedBy = String(src["approved-by"]);
210
+ if (src["published-at"]) out.publishedAt = String(src["published-at"]);
211
+ return out;
212
+ }
213
+ function toneFromClaims(claims) {
214
+ if (claims.includes("ai.generated")) return "generated";
215
+ if (claims.includes("review.verified") || claims.includes("trust.official")) return "verified";
216
+ if (claims.includes("review.human")) return "human";
217
+ if (claims.includes("ai.assisted")) return "mixed";
218
+ return "neutral";
219
+ }
220
+
221
+ // core/transparency/renderer.js
222
+ var renderers = /* @__PURE__ */ new Map();
223
+ function registerTransparencyRenderer(name, fn) {
224
+ renderers.set(name, fn);
225
+ }
226
+ function renderDisclosure(el, record) {
227
+ if (typeof document === "undefined" || !el) return null;
228
+ const name = record.renderer || "badge";
229
+ const custom = renderers.get(name);
230
+ if (custom) {
231
+ custom(el, record);
232
+ return el.querySelector(".velin-transparency");
233
+ }
234
+ return defaultRender(el, record);
235
+ }
236
+ function defaultRender(el, record) {
237
+ const cs = getComputedStyle(el);
238
+ if (cs.position === "static") el.style.position = "relative";
239
+ let mark = el.querySelector(":scope > .velin-transparency");
240
+ if (!mark) {
241
+ mark = document.createElement("div");
242
+ el.prepend(mark);
243
+ }
244
+ const renderer = record.renderer || "badge";
245
+ const tone = record.tone || "neutral";
246
+ const position = record.position || "top-right";
247
+ mark.className = [
248
+ "velin-transparency",
249
+ `velin-transparency--${renderer}`,
250
+ `velin-transparency--tone-${tone}`,
251
+ `velin-transparency--pos-${position}`
252
+ ].join(" ");
253
+ mark.setAttribute("data-velin-transparency-id", record.id);
254
+ mark.setAttribute("role", "note");
255
+ const claimsText = (record.claims || []).join(", ");
256
+ const prov = record.provenance || {};
257
+ const sr = document.createElement("span");
258
+ sr.className = "velin-sr-only";
259
+ const lang = (el.closest("[lang]")?.getAttribute("lang") || document.documentElement.lang || "en").startsWith("de") ? "de" : "en";
260
+ sr.textContent = lang === "de" ? `Transparenzhinweis: ${record.label}. ${claimsText}. ${provenanceSr(prov, "de")}` : `Transparency notice: ${record.label}. ${claimsText}. ${provenanceSr(prov, "en")}`;
261
+ const visible = document.createElement("span");
262
+ visible.className = "velin-transparency__label";
263
+ visible.textContent = record.label || "Transparency";
264
+ const details = document.createElement("span");
265
+ details.className = "velin-transparency__details";
266
+ details.hidden = renderer === "badge" || renderer === "icon";
267
+ details.textContent = formatDetails(record, lang);
268
+ mark.replaceChildren(sr, visible, details);
269
+ if (record.description) mark.title = record.description;
270
+ else if (details.textContent) mark.title = details.textContent;
271
+ el.setAttribute("data-velin-transparency", record.id);
272
+ return mark;
273
+ }
274
+ function provenanceSr(p, lang) {
275
+ const parts = [];
276
+ if (p.createdBy) parts.push(lang === "de" ? `Erstellt von ${p.createdBy}` : `Created by ${p.createdBy}`);
277
+ if (p.createdAt) parts.push(lang === "de" ? `am ${p.createdAt}` : `on ${p.createdAt}`);
278
+ if (p.approvedBy) parts.push(lang === "de" ? `Freigegeben von ${p.approvedBy}` : `Approved by ${p.approvedBy}`);
279
+ if (p.license) parts.push(p.license);
280
+ if (p.version) parts.push(`v${p.version}`);
281
+ return parts.join(". ");
282
+ }
283
+ function formatDetails(record, lang) {
284
+ const p = record.provenance || {};
285
+ const bits = [];
286
+ if (p.approvedBy) bits.push(lang === "de" ? `Freigabe: ${p.approvedBy}` : `Approved: ${p.approvedBy}`);
287
+ if (p.license) bits.push(p.license);
288
+ if (p.version) bits.push(`v${p.version}`);
289
+ if (p.updated || record.updated) bits.push(record.updated || p.publishedAt || "");
290
+ return bits.filter(Boolean).join(" \xB7 ");
291
+ }
292
+ for (const name of ["overlay", "badge", "inline", "tooltip", "footer", "ribbon", "panel", "icon", "corner-badge", "stamp", "sidebar", "floating-card", "banner"]) {
293
+ registerTransparencyRenderer(name, (el, record) => {
294
+ defaultRender(el, { ...record, renderer: normalizeRendererName(name) });
295
+ });
296
+ }
297
+ function normalizeRendererName(name) {
298
+ if (name === "corner-badge" || name === "stamp") return "badge";
299
+ if (name === "floating-card" || name === "sidebar") return "panel";
300
+ if (name === "banner") return "footer";
301
+ return name;
302
+ }
303
+
304
+ // core/transparency/attach.js
305
+ var defaultRegistry = createRegistry();
306
+ function attach(el, options = {}, ctx = {}) {
307
+ if (!el) throw new Error("VelinTransparency.attach requires an element");
308
+ const registry = ctx.registry || defaultRegistry;
309
+ const draft = {
310
+ ...options,
311
+ tag: el.tagName,
312
+ src: el.getAttribute?.("src") || el.getAttribute?.("href") || options.src,
313
+ selector: el.id ? `#${el.id}` : options.selector,
314
+ id: options.id || el.getAttribute?.("velin-transparency-id") || el.id,
315
+ provider: options.provider || "api"
316
+ };
317
+ if (el.hasAttribute?.("velin-transparency") || el.hasAttribute?.("velin-disclosure")) {
318
+ draft.type = draft.type || el.getAttribute("velin-type") || "ai";
319
+ draft.status = draft.status || el.getAttribute("velin-status");
320
+ draft.review = draft.review || el.getAttribute("velin-review");
321
+ draft.license = draft.license || el.getAttribute("velin-license");
322
+ draft.label = draft.label || el.getAttribute("velin-label");
323
+ draft.description = draft.description || el.getAttribute("velin-description");
324
+ draft.overlay = draft.overlay || el.getAttribute("velin-overlay") || el.getAttribute("velin-renderer");
325
+ draft.provenance = {
326
+ createdBy: el.getAttribute("velin-created-by"),
327
+ createdAt: el.getAttribute("velin-created-at"),
328
+ reviewedAt: el.getAttribute("velin-reviewed-at"),
329
+ approvedBy: el.getAttribute("velin-approved-by"),
330
+ source: el.getAttribute("velin-source"),
331
+ license: el.getAttribute("velin-license"),
332
+ version: el.getAttribute("velin-version"),
333
+ publishedAt: el.getAttribute("velin-published-at"),
334
+ ...options.provenance || {}
335
+ };
336
+ }
337
+ const record = normalizeDisclosure(draft, { provider: draft.provider, lang: ctx.lang });
338
+ registry.register(record);
339
+ if (!el.hasAttribute("velin-transparency")) el.setAttribute("velin-transparency", "");
340
+ if (!el.hasAttribute("velin-transparency-id")) el.setAttribute("velin-transparency-id", record.id);
341
+ renderDisclosure(el, record);
342
+ return record;
343
+ }
344
+ function enhanceAll(root = typeof document !== "undefined" ? document : null) {
345
+ if (!root?.querySelectorAll) return [];
346
+ const out = [];
347
+ root.querySelectorAll("[velin-transparency], [velin-disclosure]").forEach((el) => {
348
+ out.push(attach(el, {}, { registry: defaultRegistry }));
349
+ });
350
+ return out;
351
+ }
352
+ function getDefaultRegistry() {
353
+ return defaultRegistry;
354
+ }
355
+ var VelinTransparency = {
356
+ attach,
357
+ enhanceAll,
358
+ getRegistry: getDefaultRegistry
359
+ };
360
+ export {
361
+ VelinTransparency,
362
+ attach,
363
+ enhanceAll,
364
+ getDefaultRegistry
365
+ };