dealsystem 0.0.1 → 0.2.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/README.md +64 -2
- package/dist/api/errors.d.ts +25 -0
- package/dist/api/errors.js +38 -0
- package/dist/api/http.d.ts +56 -0
- package/dist/api/http.js +406 -0
- package/dist/api/legal.d.ts +9 -0
- package/dist/api/legal.js +20 -0
- package/dist/api/oauth.d.ts +35 -0
- package/dist/api/oauth.js +113 -0
- package/dist/api/types.d.ts +142 -0
- package/dist/api/types.js +9 -0
- package/dist/auth/credentials.d.ts +28 -0
- package/dist/auth/credentials.js +96 -0
- package/dist/auth/session.d.ts +10 -0
- package/dist/auth/session.js +46 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +4 -0
- package/dist/check/allowlist.d.ts +9 -0
- package/dist/check/allowlist.js +74 -0
- package/dist/check/catalog.d.ts +6 -0
- package/dist/check/catalog.js +410 -0
- package/dist/check/context.d.ts +79 -0
- package/dist/check/context.js +230 -0
- package/dist/check/fileset.d.ts +19 -0
- package/dist/check/fileset.js +91 -0
- package/dist/check/format.d.ts +25 -0
- package/dist/check/format.js +79 -0
- package/dist/check/index.d.ts +8 -0
- package/dist/check/index.js +9 -0
- package/dist/check/rule.d.ts +15 -0
- package/dist/check/rule.js +6 -0
- package/dist/check/rules/a11y.d.ts +3 -0
- package/dist/check/rules/a11y.js +433 -0
- package/dist/check/rules/privacy.d.ts +9 -0
- package/dist/check/rules/privacy.js +437 -0
- package/dist/check/rules/quality.d.ts +11 -0
- package/dist/check/rules/quality.js +451 -0
- package/dist/check/rules/schedule.d.ts +2 -0
- package/dist/check/rules/schedule.js +30 -0
- package/dist/check/rules/security.d.ts +18 -0
- package/dist/check/rules/security.js +744 -0
- package/dist/check/rules/structure.d.ts +2 -0
- package/dist/check/rules/structure.js +399 -0
- package/dist/check/run.d.ts +15 -0
- package/dist/check/run.js +147 -0
- package/dist/check/sdk.d.ts +56 -0
- package/dist/check/sdk.js +58 -0
- package/dist/check/types.d.ts +116 -0
- package/dist/check/types.js +2 -0
- package/dist/check/util/code.d.ts +19 -0
- package/dist/check/util/code.js +113 -0
- package/dist/check/util/color.d.ts +10 -0
- package/dist/check/util/color.js +53 -0
- package/dist/check/util/csp.d.ts +71 -0
- package/dist/check/util/csp.js +229 -0
- package/dist/check/util/html.d.ts +31 -0
- package/dist/check/util/html.js +65 -0
- package/dist/check/util/lines.d.ts +1 -0
- package/dist/check/util/lines.js +2 -0
- package/dist/check/util/literal.d.ts +1 -0
- package/dist/check/util/literal.js +3 -0
- package/dist/check/util/svelte.d.ts +42 -0
- package/dist/check/util/svelte.js +109 -0
- package/dist/cli/context.d.ts +40 -0
- package/dist/cli/context.js +107 -0
- package/dist/cli/io.d.ts +26 -0
- package/dist/cli/io.js +68 -0
- package/dist/cli/main.d.ts +24 -0
- package/dist/cli/main.js +269 -0
- package/dist/commands/check.d.ts +4 -0
- package/dist/commands/check.js +54 -0
- package/dist/commands/deploy.d.ts +20 -0
- package/dist/commands/deploy.js +315 -0
- package/dist/commands/dev.d.ts +29 -0
- package/dist/commands/dev.js +149 -0
- package/dist/commands/image.d.ts +12 -0
- package/dist/commands/image.js +291 -0
- package/dist/commands/login.d.ts +3 -0
- package/dist/commands/login.js +116 -0
- package/dist/commands/pull.d.ts +12 -0
- package/dist/commands/pull.js +178 -0
- package/dist/commands/site.d.ts +9 -0
- package/dist/commands/site.js +84 -0
- package/dist/commands/sync.d.ts +2 -0
- package/dist/commands/sync.js +126 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/project/agentFiles.d.ts +17 -0
- package/dist/project/agentFiles.js +156 -0
- package/dist/project/agentsBlock.d.ts +2 -0
- package/dist/project/agentsBlock.js +14 -0
- package/dist/project/siteConfig.d.ts +5 -0
- package/dist/project/siteConfig.js +35 -0
- package/dist/project/snapshot.d.ts +21 -0
- package/dist/project/snapshot.js +125 -0
- package/dist/project/svelteConfig.d.ts +4 -0
- package/dist/project/svelteConfig.js +74 -0
- package/dist/project/tar.d.ts +8 -0
- package/dist/project/tar.js +89 -0
- package/dist/project/untar.d.ts +27 -0
- package/dist/project/untar.js +232 -0
- package/dist/project/uploadFiles.d.ts +17 -0
- package/dist/project/uploadFiles.js +55 -0
- package/package.json +63 -7
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { ResolvedExternal } from '@dealsystem/site/config';
|
|
2
|
+
/** `source` prüft den Quellcode (Q), `output` die gebaute Seite (A). `browser` ist für Phase 2 (axe, Lighthouse) reserviert. */
|
|
3
|
+
export type CheckStage = 'source' | 'output' | 'browser';
|
|
4
|
+
export type Severity = 'error' | 'warning';
|
|
5
|
+
/** Eine Meldung. `message` beschreibt das Problem, `fix` sagt als Anweisung, wie man es behebt. */
|
|
6
|
+
export interface Finding {
|
|
7
|
+
rule: string;
|
|
8
|
+
severity: Severity;
|
|
9
|
+
/** Pfad relativ zum Projekt (Quelle) oder zum Ausgabeordner (Ausgabe), immer mit `/`. */
|
|
10
|
+
file: string | null;
|
|
11
|
+
/** 1-basiert. */
|
|
12
|
+
line: number | null;
|
|
13
|
+
/** 1-basiert. */
|
|
14
|
+
column: number | null;
|
|
15
|
+
message: string;
|
|
16
|
+
fix: string;
|
|
17
|
+
}
|
|
18
|
+
export interface CheckResult {
|
|
19
|
+
passed: boolean;
|
|
20
|
+
ruleSetVersion: string;
|
|
21
|
+
/** Welche Stufen gelaufen sind. */
|
|
22
|
+
stages: CheckStage[];
|
|
23
|
+
errors: Finding[];
|
|
24
|
+
warnings: Finding[];
|
|
25
|
+
}
|
|
26
|
+
/** Ein Eintrag im Regelkatalog. */
|
|
27
|
+
export interface RuleMeta {
|
|
28
|
+
id: string;
|
|
29
|
+
/** Schweregrad, wenn nichts anderes eingestellt ist. */
|
|
30
|
+
severity: Severity;
|
|
31
|
+
/** Wo die Regel prüft. Leer = Meldung kommt vom Build-Host (BLD-*), nicht aus `check`. */
|
|
32
|
+
stages: CheckStage[];
|
|
33
|
+
/** Kurzbeschreibung, was geprüft wird. */
|
|
34
|
+
title: string;
|
|
35
|
+
/** Standard-Korrektur, falls die Meldung keine eigene hat. */
|
|
36
|
+
fix: string;
|
|
37
|
+
}
|
|
38
|
+
/** Was eine Regel meldet; Schweregrad und Regel-ID ergänzt der Lauf. */
|
|
39
|
+
export interface RawFinding {
|
|
40
|
+
file?: string | null;
|
|
41
|
+
line?: number | null;
|
|
42
|
+
column?: number | null;
|
|
43
|
+
message: string;
|
|
44
|
+
fix?: string;
|
|
45
|
+
/** Nur für Regeln, die je Fund unterschiedlich streng sind (z. B. QUA-006). */
|
|
46
|
+
severity?: Severity;
|
|
47
|
+
}
|
|
48
|
+
export interface FileEntry {
|
|
49
|
+
/** Relativ, mit `/`. */
|
|
50
|
+
path: string;
|
|
51
|
+
size: number;
|
|
52
|
+
}
|
|
53
|
+
/** Lesezugriff auf einen Projekt- oder Ausgabeordner. Läuft ohne Netz; Tests nutzen eine Speicher-Variante. */
|
|
54
|
+
export interface FileSet {
|
|
55
|
+
/** Alle regulären Dateien, sortiert. */
|
|
56
|
+
list(): FileEntry[];
|
|
57
|
+
has(path: string): boolean;
|
|
58
|
+
/** Text (UTF-8) oder `null`, wenn die Datei fehlt. */
|
|
59
|
+
readText(path: string): string | null;
|
|
60
|
+
readBytes(path: string): Uint8Array | null;
|
|
61
|
+
}
|
|
62
|
+
export interface CheckOptions {
|
|
63
|
+
/** Projektordner (Quelle). Fehlt er, läuft die Stufe `source` nicht. */
|
|
64
|
+
projectDir?: string;
|
|
65
|
+
/** Ausgabeordner von `vite build` (adapter-static, meist `build`). Fehlt er, läuft `output` nicht. */
|
|
66
|
+
outputDir?: string;
|
|
67
|
+
/** Alternativ zu den Ordnern: fertige Dateimengen (Tests, Build-Host mit eigenem Entpacker). */
|
|
68
|
+
source?: FileSet;
|
|
69
|
+
output?: FileSet;
|
|
70
|
+
/** Nur diese Stufen. Standard: alle, für die Dateien vorliegen. */
|
|
71
|
+
stages?: CheckStage[];
|
|
72
|
+
/** Unterstützter Bereich von `@dealsystem/site` (Build-Job `sdkRange`). */
|
|
73
|
+
sdkRange?: string;
|
|
74
|
+
/** Erwartete Version des Regelkatalogs (Build-Job `ruleSetVersion`). Abweichung → Ausnahme. */
|
|
75
|
+
ruleSetVersion?: string;
|
|
76
|
+
/** Öffentliche Adresse der Seite; absolute Links dorthin gelten als intern. */
|
|
77
|
+
siteUrl?: string;
|
|
78
|
+
/** Adresse der Site-API, für die die Seite gebaut wurde (`PUBLIC_DEALSYSTEM_API`). Nur für die Ausgabe-Prüfung der CSP. */
|
|
79
|
+
apiUrl?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Fremde Dienste der Seite (`external` aus dem Manifest, schon aufgelöst). Nur für die Ausgabe-Prüfung der CSP
|
|
82
|
+
* (SEC-008), wenn die Quelle nicht im selben Lauf geprüft wird (Build-Host). Fehlt die Angabe und gibt es keine
|
|
83
|
+
* Quelle, prüft SEC-008 nur die harten Verbote und meldet Abweichungen als Warnung (Seite mit älterem SDK).
|
|
84
|
+
*/
|
|
85
|
+
external?: readonly ResolvedExternal[];
|
|
86
|
+
/**
|
|
87
|
+
* Wo die Seite läuft. Nur der Build-Host kennt das (SEC-011). `standardHostOnly`: Die Seite hat keine eigene
|
|
88
|
+
* Domain, nur `<name>.dealsystem.site`. `sitesDomainOnPsl`: `dealsystem.site` steht auf der Public Suffix List
|
|
89
|
+
* (Env `SITES_DOMAIN_ON_PSL` im Core).
|
|
90
|
+
*/
|
|
91
|
+
hosting?: {
|
|
92
|
+
standardHostOnly: boolean;
|
|
93
|
+
sitesDomainOnPsl: boolean;
|
|
94
|
+
};
|
|
95
|
+
/** Schweregrad je Regel überschreiben (neue Regeln kommen erst als Warnung). */
|
|
96
|
+
severityOverrides?: Record<string, Severity>;
|
|
97
|
+
/** Regeln abschalten. Nur für Tests und Werkzeuge, nie für den Build-Host. */
|
|
98
|
+
disabledRules?: string[];
|
|
99
|
+
/** Zusätzliche Regeln, z. B. die Browser-Stufe aus Phase 2. */
|
|
100
|
+
plugins?: CheckPlugin[];
|
|
101
|
+
}
|
|
102
|
+
/** Andockpunkt für weitere Prüfungen (Phase 2: axe-core, Lighthouse in einem Browser ohne Netz). */
|
|
103
|
+
export interface CheckPlugin {
|
|
104
|
+
meta: RuleMeta[];
|
|
105
|
+
run(input: PluginInput): Promise<(RawFinding & {
|
|
106
|
+
rule: string;
|
|
107
|
+
})[]> | (RawFinding & {
|
|
108
|
+
rule: string;
|
|
109
|
+
})[];
|
|
110
|
+
}
|
|
111
|
+
export interface PluginInput {
|
|
112
|
+
stages: CheckStage[];
|
|
113
|
+
source: FileSet | null;
|
|
114
|
+
output: FileSet | null;
|
|
115
|
+
options: CheckOptions;
|
|
116
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LineIndex } from './lines.js';
|
|
2
|
+
export declare function isScriptFile(path: string): boolean;
|
|
3
|
+
export declare function isSvelteFile(path: string): boolean;
|
|
4
|
+
/** Ersetzt JS/TS-Kommentare durch Leerzeichen. Zeilenumbrüche bleiben, damit Zeilennummern stimmen. */
|
|
5
|
+
export declare function blankJsComments(code: string): string;
|
|
6
|
+
/** Svelte-Datei: HTML-Kommentare und Kommentare in `<script>`-Blöcken ausblenden. */
|
|
7
|
+
export declare function blankSvelteComments(code: string): string;
|
|
8
|
+
/** Text mit ausgeblendeten Kommentaren je nach Dateityp. */
|
|
9
|
+
export declare function codeWithoutComments(path: string, code: string): string;
|
|
10
|
+
export interface Match {
|
|
11
|
+
line: number;
|
|
12
|
+
column: number;
|
|
13
|
+
text: string;
|
|
14
|
+
index: number;
|
|
15
|
+
}
|
|
16
|
+
/** Alle Treffer eines Musters (das Muster braucht das Flag `g`). */
|
|
17
|
+
export declare function findAll(text: string, pattern: RegExp, lines?: LineIndex): Match[];
|
|
18
|
+
/** Kürzt einen Fund für Meldungen (fremder Text, B10). */
|
|
19
|
+
export declare function excerpt(text: string, max?: number): string;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Hilfen für Prüfungen am Code: Kommentare ausblenden (Offsets bleiben gleich), Fundstellen per Muster.
|
|
2
|
+
import ts from 'typescript';
|
|
3
|
+
import { LineIndex } from './lines.js';
|
|
4
|
+
const SCRIPT_EXTENSIONS = ['.ts', '.js', '.mjs', '.cjs', '.mts', '.cts'];
|
|
5
|
+
export function isScriptFile(path) {
|
|
6
|
+
return SCRIPT_EXTENSIONS.some((ext) => path.endsWith(ext)) && !path.endsWith('.d.ts');
|
|
7
|
+
}
|
|
8
|
+
export function isSvelteFile(path) {
|
|
9
|
+
return path.endsWith('.svelte');
|
|
10
|
+
}
|
|
11
|
+
function blank(text, start, end, out) {
|
|
12
|
+
for (let i = start; i < end; i++) {
|
|
13
|
+
const ch = text[i];
|
|
14
|
+
out[i] = ch === '\n' || ch === '\r' ? ch : ' ';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Nach diesen Token ist `/` eine Division, sonst beginnt ein Regex-Literal. */
|
|
18
|
+
function endsExpression(kind) {
|
|
19
|
+
return (kind === ts.SyntaxKind.Identifier ||
|
|
20
|
+
kind === ts.SyntaxKind.NumericLiteral ||
|
|
21
|
+
kind === ts.SyntaxKind.StringLiteral ||
|
|
22
|
+
kind === ts.SyntaxKind.BigIntLiteral ||
|
|
23
|
+
kind === ts.SyntaxKind.RegularExpressionLiteral ||
|
|
24
|
+
kind === ts.SyntaxKind.NoSubstitutionTemplateLiteral ||
|
|
25
|
+
kind === ts.SyntaxKind.TemplateTail ||
|
|
26
|
+
kind === ts.SyntaxKind.CloseParenToken ||
|
|
27
|
+
kind === ts.SyntaxKind.CloseBracketToken ||
|
|
28
|
+
kind === ts.SyntaxKind.CloseBraceToken ||
|
|
29
|
+
kind === ts.SyntaxKind.ThisKeyword ||
|
|
30
|
+
kind === ts.SyntaxKind.PlusPlusToken ||
|
|
31
|
+
kind === ts.SyntaxKind.MinusMinusToken);
|
|
32
|
+
}
|
|
33
|
+
/** Ersetzt JS/TS-Kommentare durch Leerzeichen. Zeilenumbrüche bleiben, damit Zeilennummern stimmen. */
|
|
34
|
+
export function blankJsComments(code) {
|
|
35
|
+
const out = code.split('');
|
|
36
|
+
const scanner = ts.createScanner(ts.ScriptTarget.Latest, false, ts.LanguageVariant.Standard, code);
|
|
37
|
+
// Der Scanner allein kennt keinen Kontext: Template-Fortsetzungen nach `}` und Regex-Literale
|
|
38
|
+
// müssen nachgescannt werden, sonst gilt `//` in `https://…` als Kommentar.
|
|
39
|
+
const templateDepth = [];
|
|
40
|
+
let prev = ts.SyntaxKind.Unknown;
|
|
41
|
+
let token = scanner.scan();
|
|
42
|
+
while (token !== ts.SyntaxKind.EndOfFileToken) {
|
|
43
|
+
if (token === ts.SyntaxKind.SingleLineCommentTrivia || token === ts.SyntaxKind.MultiLineCommentTrivia) {
|
|
44
|
+
blank(code, scanner.getTokenStart(), scanner.getTokenEnd(), out);
|
|
45
|
+
}
|
|
46
|
+
else if (token !== ts.SyntaxKind.WhitespaceTrivia && token !== ts.SyntaxKind.NewLineTrivia) {
|
|
47
|
+
if (token === ts.SyntaxKind.TemplateHead)
|
|
48
|
+
templateDepth.push(0);
|
|
49
|
+
else if (token === ts.SyntaxKind.OpenBraceToken && templateDepth.length > 0) {
|
|
50
|
+
templateDepth[templateDepth.length - 1] += 1;
|
|
51
|
+
}
|
|
52
|
+
else if (token === ts.SyntaxKind.CloseBraceToken && templateDepth.length > 0) {
|
|
53
|
+
if (templateDepth[templateDepth.length - 1] === 0) {
|
|
54
|
+
token = scanner.reScanTemplateToken(false);
|
|
55
|
+
if (token === ts.SyntaxKind.TemplateTail)
|
|
56
|
+
templateDepth.pop();
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
templateDepth[templateDepth.length - 1] -= 1;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else if ((token === ts.SyntaxKind.SlashToken || token === ts.SyntaxKind.SlashEqualsToken) &&
|
|
63
|
+
!endsExpression(prev)) {
|
|
64
|
+
token = scanner.reScanSlashToken();
|
|
65
|
+
}
|
|
66
|
+
prev = token;
|
|
67
|
+
}
|
|
68
|
+
token = scanner.scan();
|
|
69
|
+
}
|
|
70
|
+
return out.join('');
|
|
71
|
+
}
|
|
72
|
+
/** Svelte-Datei: HTML-Kommentare und Kommentare in `<script>`-Blöcken ausblenden. */
|
|
73
|
+
export function blankSvelteComments(code) {
|
|
74
|
+
const out = code.split('');
|
|
75
|
+
for (const m of code.matchAll(/<!--[\s\S]*?-->/g)) {
|
|
76
|
+
blank(code, m.index, m.index + m[0].length, out);
|
|
77
|
+
}
|
|
78
|
+
let text = out.join('');
|
|
79
|
+
for (const m of text.matchAll(/(<script\b[^>]*>)([\s\S]*?)(<\/script>)/g)) {
|
|
80
|
+
const start = m.index + (m[1]?.length ?? 0);
|
|
81
|
+
const inner = m[2] ?? '';
|
|
82
|
+
const cleaned = blankJsComments(inner);
|
|
83
|
+
text = text.slice(0, start) + cleaned + text.slice(start + inner.length);
|
|
84
|
+
}
|
|
85
|
+
return text;
|
|
86
|
+
}
|
|
87
|
+
/** Text mit ausgeblendeten Kommentaren je nach Dateityp. */
|
|
88
|
+
export function codeWithoutComments(path, code) {
|
|
89
|
+
if (isSvelteFile(path))
|
|
90
|
+
return blankSvelteComments(code);
|
|
91
|
+
if (isScriptFile(path))
|
|
92
|
+
return blankJsComments(code);
|
|
93
|
+
if (path.endsWith('.html'))
|
|
94
|
+
return code.replace(/<!--[\s\S]*?-->/g, (m) => m.replace(/[^\n]/g, ' '));
|
|
95
|
+
if (path.endsWith('.css'))
|
|
96
|
+
return code.replace(/\/\*[\s\S]*?\*\//g, (m) => m.replace(/[^\n]/g, ' '));
|
|
97
|
+
return code;
|
|
98
|
+
}
|
|
99
|
+
/** Alle Treffer eines Musters (das Muster braucht das Flag `g`). */
|
|
100
|
+
export function findAll(text, pattern, lines) {
|
|
101
|
+
const index = lines ?? new LineIndex(text);
|
|
102
|
+
const out = [];
|
|
103
|
+
for (const m of text.matchAll(pattern)) {
|
|
104
|
+
const pos = index.at(m.index);
|
|
105
|
+
out.push({ line: pos.line, column: pos.column, text: m[0], index: m.index });
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
/** Kürzt einen Fund für Meldungen (fremder Text, B10). */
|
|
110
|
+
export function excerpt(text, max = 80) {
|
|
111
|
+
const oneLine = text.replace(/\s+/g, ' ').trim();
|
|
112
|
+
return oneLine.length > max ? `${oneLine.slice(0, max - 1)}…` : oneLine;
|
|
113
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface Rgb {
|
|
2
|
+
r: number;
|
|
3
|
+
g: number;
|
|
4
|
+
b: number;
|
|
5
|
+
}
|
|
6
|
+
/** Liest `#rgb`, `#rrggbb`, `#rrggbbaa`, `rgb()`, `rgba()`, `hsl()`, `white`, `black`. Sonst `null`. */
|
|
7
|
+
export declare function parseColor(raw: string): Rgb | null;
|
|
8
|
+
export declare function luminance(c: Rgb): number;
|
|
9
|
+
/** Kontrastverhältnis, auf zwei Stellen abgerundet (4,499 zählt nicht als 4,5). */
|
|
10
|
+
export declare function contrastRatio(a: Rgb, b: Rgb): number;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Farben lesen und Kontrast nach WCAG 2.1 berechnen.
|
|
2
|
+
function clamp(n) {
|
|
3
|
+
return Math.min(255, Math.max(0, n));
|
|
4
|
+
}
|
|
5
|
+
function hslToRgb(h, s, l) {
|
|
6
|
+
const hue = (((h % 360) + 360) % 360) / 360;
|
|
7
|
+
const k = (n) => (n + hue * 12) % 12;
|
|
8
|
+
const a = s * Math.min(l, 1 - l);
|
|
9
|
+
const f = (n) => l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));
|
|
10
|
+
return { r: Math.round(f(0) * 255), g: Math.round(f(8) * 255), b: Math.round(f(4) * 255) };
|
|
11
|
+
}
|
|
12
|
+
const NAMED = {
|
|
13
|
+
white: { r: 255, g: 255, b: 255 },
|
|
14
|
+
black: { r: 0, g: 0, b: 0 },
|
|
15
|
+
};
|
|
16
|
+
/** Liest `#rgb`, `#rrggbb`, `#rrggbbaa`, `rgb()`, `rgba()`, `hsl()`, `white`, `black`. Sonst `null`. */
|
|
17
|
+
export function parseColor(raw) {
|
|
18
|
+
const v = raw.trim().toLowerCase();
|
|
19
|
+
const named = NAMED[v];
|
|
20
|
+
if (named)
|
|
21
|
+
return named;
|
|
22
|
+
let m = /^#([0-9a-f]{3,4})$/.exec(v);
|
|
23
|
+
if (m?.[1]) {
|
|
24
|
+
const [r, g, b] = m[1].split('').map((c) => parseInt(c + c, 16));
|
|
25
|
+
return { r: r ?? 0, g: g ?? 0, b: b ?? 0 };
|
|
26
|
+
}
|
|
27
|
+
m = /^#([0-9a-f]{6})(?:[0-9a-f]{2})?$/.exec(v);
|
|
28
|
+
if (m?.[1]) {
|
|
29
|
+
const n = parseInt(m[1], 16);
|
|
30
|
+
return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255 };
|
|
31
|
+
}
|
|
32
|
+
m = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/.exec(v);
|
|
33
|
+
if (m)
|
|
34
|
+
return { r: clamp(Number(m[1])), g: clamp(Number(m[2])), b: clamp(Number(m[3])) };
|
|
35
|
+
m = /^hsla?\(\s*([\d.]+)(?:deg)?[\s,]+([\d.]+)%[\s,]+([\d.]+)%/.exec(v);
|
|
36
|
+
if (m)
|
|
37
|
+
return hslToRgb(Number(m[1]), Number(m[2]) / 100, Number(m[3]) / 100);
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
function channel(c) {
|
|
41
|
+
const s = c / 255;
|
|
42
|
+
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
43
|
+
}
|
|
44
|
+
export function luminance(c) {
|
|
45
|
+
return 0.2126 * channel(c.r) + 0.7152 * channel(c.g) + 0.0722 * channel(c.b);
|
|
46
|
+
}
|
|
47
|
+
/** Kontrastverhältnis, auf zwei Stellen abgerundet (4,499 zählt nicht als 4,5). */
|
|
48
|
+
export function contrastRatio(a, b) {
|
|
49
|
+
const la = luminance(a);
|
|
50
|
+
const lb = luminance(b);
|
|
51
|
+
const ratio = (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
|
|
52
|
+
return Math.floor(ratio * 100) / 100;
|
|
53
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type ResolvedExternal } from '@dealsystem/site/config';
|
|
2
|
+
import type { SourceContext } from '../context.js';
|
|
3
|
+
import type { Severity } from '../types.js';
|
|
4
|
+
import { type LiteralValue, type Opaque, type ParsedModule } from './literal.js';
|
|
5
|
+
export type Csp = Record<string, string[]>;
|
|
6
|
+
/** Platzhalter für die Adresse der Site-API in einer Quellenliste: erst beim Build bekannt. */
|
|
7
|
+
export declare const SITE_API_SOURCE = "<site-api>";
|
|
8
|
+
/** SvelteKit schreibt Schlüsselwörter ohne Anführungszeichen (`'self'` → `['self']`); beide Formen zählen. */
|
|
9
|
+
export declare const unquote: (v: string) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Wie `kit.csp` in svelte.config.js steht:
|
|
12
|
+
* - `dealsystem`: `csp: dealsystemCsp()` aus `@dealsystem/site/csp` (Regelsatz 3, Starter ab SDK 0.2)
|
|
13
|
+
* - `legacy`: feste Liste wie im Starter bis SDK 0.1
|
|
14
|
+
* - `other`: etwas anderes (fehlt, anderer Aufruf, Variable)
|
|
15
|
+
*/
|
|
16
|
+
export type CspForm = {
|
|
17
|
+
kind: 'dealsystem';
|
|
18
|
+
path: string;
|
|
19
|
+
mod: ParsedModule;
|
|
20
|
+
call: Opaque;
|
|
21
|
+
} | {
|
|
22
|
+
kind: 'legacy';
|
|
23
|
+
path: string;
|
|
24
|
+
mod: ParsedModule;
|
|
25
|
+
csp: {
|
|
26
|
+
[key: string]: LiteralValue;
|
|
27
|
+
};
|
|
28
|
+
} | {
|
|
29
|
+
kind: 'other';
|
|
30
|
+
path: string;
|
|
31
|
+
mod: ParsedModule;
|
|
32
|
+
csp: LiteralValue;
|
|
33
|
+
} | null;
|
|
34
|
+
export declare function cspForm(ctx: SourceContext): CspForm;
|
|
35
|
+
/** Ob `dealsystemCsp()` richtig importiert und ohne Argumente aufgerufen ist. */
|
|
36
|
+
export declare function isValidDealsystemCall(form: CspForm): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Schweregrad für Verschärfungen in Regelsatz 3: Fehler für Seiten mit `dealsystemCsp()` (neues SDK), Warnung
|
|
39
|
+
* für die Altform. So baut eine unveränderte Live-Seite weiter (Konzept Phase 2, Abschnitt 3).
|
|
40
|
+
*/
|
|
41
|
+
export declare function tighteningSeverity(ctx: SourceContext): Severity;
|
|
42
|
+
/** Fremde Dienste aus dealsystem.config.ts, statisch gelesen. Nur gültige Einträge. */
|
|
43
|
+
export declare function declaredExternal(ctx: SourceContext): ResolvedExternal[];
|
|
44
|
+
/**
|
|
45
|
+
* Quellenliste einer CSP-Direktive. Erlaubt sind feste Zeichenketten und `siteApiOrigin()` aus
|
|
46
|
+
* `@dealsystem/site/config`; alles andere ergibt `null`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function cspSourceList(mod: ParsedModule, value: LiteralValue): string[] | null;
|
|
49
|
+
/**
|
|
50
|
+
* CSP, wie sie beim Build entsteht: bei `dealsystemCsp()` aus Basis und Deklaration, bei der Altform aus den
|
|
51
|
+
* festen Listen. `null`, wenn sie sich nicht lesen lässt (SEC-005 meldet das).
|
|
52
|
+
*/
|
|
53
|
+
export declare function sourceCsp(ctx: SourceContext): {
|
|
54
|
+
path: string;
|
|
55
|
+
csp: Csp;
|
|
56
|
+
kind: 'dealsystem' | 'legacy';
|
|
57
|
+
} | null;
|
|
58
|
+
/** Ob eine Host-Quelle (`https://a.de`, `*.a.de`, `http://localhost:5173`) zu `url` passt. */
|
|
59
|
+
export declare function hostSourceMatches(source: string, url: URL): boolean;
|
|
60
|
+
/** Ob die Direktive (sonst `default-src`) das Laden von `url` erlaubt. Ohne beide Direktiven ist alles erlaubt. */
|
|
61
|
+
export declare function cspAllows(csp: Csp, directive: string, url: URL): boolean;
|
|
62
|
+
/** CSP aus dem `<meta http-equiv="content-security-policy">` einer fertigen Seite. */
|
|
63
|
+
export declare function metaCsp(content: string): Csp;
|
|
64
|
+
/**
|
|
65
|
+
* Was am Meta-Tag einer fertigen Seite lockerer ist als die erwartete CSP. Strenger ist erlaubt (dann bleibt nur
|
|
66
|
+
* etwas auf der eigenen Seite leer, das melden die Einbettungs-Prüfungen). `apiOrigin`: Adresse der Site-API, für
|
|
67
|
+
* die gebaut wurde; ohne Angabe gilt jede Adresse von DealSystem und ein lokaler Entwicklungsserver.
|
|
68
|
+
*/
|
|
69
|
+
export declare function cspLooserThan(meta: Csp, expected: Csp, apiOrigin: string | null,
|
|
70
|
+
/** Fehlende Direktiven melden (`default-src`, `base-uri`, `form-action`). Nur, wenn die Deklaration bekannt ist. */
|
|
71
|
+
requireAll?: boolean): string[];
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
// Content-Security-Policy für die Regeln: Form in svelte.config.js erkennen, erwartete CSP berechnen, Quellen
|
|
2
|
+
// gegen Adressen abgleichen, Meta-Tag der Ausgabe gegen die erwartete CSP vergleichen.
|
|
3
|
+
import { buildCspDirectives, parseHostSource } from '@dealsystem/site/config';
|
|
4
|
+
import { CONFIG_MODULE, CSP_MODULE, DEALSYSTEM_CSP_FN, SITE_API_ORIGIN_FN } from '../sdk.js';
|
|
5
|
+
import { evaluate, isOpaque, isPlainObject, } from './literal.js';
|
|
6
|
+
/** Platzhalter für die Adresse der Site-API in einer Quellenliste: erst beim Build bekannt. */
|
|
7
|
+
export const SITE_API_SOURCE = '<site-api>';
|
|
8
|
+
/** SvelteKit schreibt Schlüsselwörter ohne Anführungszeichen (`'self'` → `['self']`); beide Formen zählen. */
|
|
9
|
+
export const unquote = (v) => v.trim().replace(/^'(.*)'$/, '$1');
|
|
10
|
+
const forms = new WeakMap();
|
|
11
|
+
export function cspForm(ctx) {
|
|
12
|
+
if (forms.has(ctx))
|
|
13
|
+
return forms.get(ctx);
|
|
14
|
+
let form = null;
|
|
15
|
+
const path = ctx.svelteConfigPath();
|
|
16
|
+
const mod = path ? ctx.module(path) : null;
|
|
17
|
+
if (path && mod) {
|
|
18
|
+
const config = mod.defaultExport ? evaluate(mod, mod.defaultExport) : undefined;
|
|
19
|
+
const kit = isPlainObject(config) ? config.kit : undefined;
|
|
20
|
+
const csp = isPlainObject(kit) ? kit.csp : undefined;
|
|
21
|
+
if (isOpaque(csp) && csp.call === DEALSYSTEM_CSP_FN)
|
|
22
|
+
form = { kind: 'dealsystem', path, mod, call: csp };
|
|
23
|
+
else if (isPlainObject(csp))
|
|
24
|
+
form = { kind: 'legacy', path, mod, csp };
|
|
25
|
+
else
|
|
26
|
+
form = { kind: 'other', path, mod, csp };
|
|
27
|
+
}
|
|
28
|
+
forms.set(ctx, form);
|
|
29
|
+
return form;
|
|
30
|
+
}
|
|
31
|
+
/** Ob `dealsystemCsp()` richtig importiert und ohne Argumente aufgerufen ist. */
|
|
32
|
+
export function isValidDealsystemCall(form) {
|
|
33
|
+
return (form?.kind === 'dealsystem' &&
|
|
34
|
+
(form.call.args?.length ?? 0) === 0 &&
|
|
35
|
+
form.mod.imports.get(DEALSYSTEM_CSP_FN) === CSP_MODULE);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Schweregrad für Verschärfungen in Regelsatz 3: Fehler für Seiten mit `dealsystemCsp()` (neues SDK), Warnung
|
|
39
|
+
* für die Altform. So baut eine unveränderte Live-Seite weiter (Konzept Phase 2, Abschnitt 3).
|
|
40
|
+
*/
|
|
41
|
+
export function tighteningSeverity(ctx) {
|
|
42
|
+
return cspForm(ctx)?.kind === 'dealsystem' ? 'error' : 'warning';
|
|
43
|
+
}
|
|
44
|
+
/** Fremde Dienste aus dealsystem.config.ts, statisch gelesen. Nur gültige Einträge. */
|
|
45
|
+
export function declaredExternal(ctx) {
|
|
46
|
+
return ctx.siteConfig().data?.external ?? [];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Quellenliste einer CSP-Direktive. Erlaubt sind feste Zeichenketten und `siteApiOrigin()` aus
|
|
50
|
+
* `@dealsystem/site/config`; alles andere ergibt `null`.
|
|
51
|
+
*/
|
|
52
|
+
export function cspSourceList(mod, value) {
|
|
53
|
+
if (!Array.isArray(value))
|
|
54
|
+
return null;
|
|
55
|
+
const out = [];
|
|
56
|
+
for (const item of value) {
|
|
57
|
+
if (typeof item === 'string')
|
|
58
|
+
out.push(item);
|
|
59
|
+
else if (isOpaque(item) &&
|
|
60
|
+
item.call === SITE_API_ORIGIN_FN &&
|
|
61
|
+
(item.args?.length ?? 0) === 0 &&
|
|
62
|
+
mod.imports.get(item.call) === CONFIG_MODULE)
|
|
63
|
+
out.push(SITE_API_SOURCE);
|
|
64
|
+
else
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* CSP, wie sie beim Build entsteht: bei `dealsystemCsp()` aus Basis und Deklaration, bei der Altform aus den
|
|
71
|
+
* festen Listen. `null`, wenn sie sich nicht lesen lässt (SEC-005 meldet das).
|
|
72
|
+
*/
|
|
73
|
+
export function sourceCsp(ctx) {
|
|
74
|
+
const form = cspForm(ctx);
|
|
75
|
+
if (!form)
|
|
76
|
+
return null;
|
|
77
|
+
if (form.kind === 'dealsystem') {
|
|
78
|
+
return {
|
|
79
|
+
path: form.path,
|
|
80
|
+
csp: buildCspDirectives(declaredExternal(ctx), SITE_API_SOURCE),
|
|
81
|
+
kind: 'dealsystem',
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (form.kind !== 'legacy' || !isPlainObject(form.csp.directives))
|
|
85
|
+
return null;
|
|
86
|
+
const csp = {};
|
|
87
|
+
for (const [name, value] of Object.entries(form.csp.directives)) {
|
|
88
|
+
const sources = cspSourceList(form.mod, value);
|
|
89
|
+
if (sources)
|
|
90
|
+
csp[name] = sources;
|
|
91
|
+
}
|
|
92
|
+
return { path: form.path, csp, kind: 'legacy' };
|
|
93
|
+
}
|
|
94
|
+
/** Ob eine Host-Quelle (`https://a.de`, `*.a.de`, `http://localhost:5173`) zu `url` passt. */
|
|
95
|
+
export function hostSourceMatches(source, url) {
|
|
96
|
+
const m = /^(?:([a-z][a-z0-9+.-]*):\/\/)?(\*\.)?([a-z0-9.-]+)(?::(\d+|\*))?(?:\/.*)?$/i.exec(source);
|
|
97
|
+
if (!m)
|
|
98
|
+
return false;
|
|
99
|
+
const [, scheme, wildcard, host, port] = m;
|
|
100
|
+
if (scheme && `${scheme.toLowerCase()}:` !== url.protocol)
|
|
101
|
+
return false;
|
|
102
|
+
const name = url.hostname.toLowerCase();
|
|
103
|
+
const wanted = host.toLowerCase();
|
|
104
|
+
if (wildcard ? !name.endsWith(`.${wanted}`) : name !== wanted)
|
|
105
|
+
return false;
|
|
106
|
+
if (port === undefined || port === '*')
|
|
107
|
+
return port === '*' || url.port === '';
|
|
108
|
+
return port === (url.port || (url.protocol === 'https:' ? '443' : '80'));
|
|
109
|
+
}
|
|
110
|
+
/** Ob die Direktive (sonst `default-src`) das Laden von `url` erlaubt. Ohne beide Direktiven ist alles erlaubt. */
|
|
111
|
+
export function cspAllows(csp, directive, url) {
|
|
112
|
+
const sources = csp[directive] ?? csp['default-src'];
|
|
113
|
+
if (!sources)
|
|
114
|
+
return true;
|
|
115
|
+
return sources.some((raw) => {
|
|
116
|
+
const source = unquote(raw).toLowerCase();
|
|
117
|
+
if (source === SITE_API_SOURCE)
|
|
118
|
+
return false;
|
|
119
|
+
return source === '*' || source === url.protocol || hostSourceMatches(source, url);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/** CSP aus dem `<meta http-equiv="content-security-policy">` einer fertigen Seite. */
|
|
123
|
+
export function metaCsp(content) {
|
|
124
|
+
const csp = {};
|
|
125
|
+
for (const part of content.split(';')) {
|
|
126
|
+
const [name, ...sources] = part.trim().split(/\s+/);
|
|
127
|
+
if (name)
|
|
128
|
+
csp[name.toLowerCase()] = sources;
|
|
129
|
+
}
|
|
130
|
+
return csp;
|
|
131
|
+
}
|
|
132
|
+
/** Fetch-Direktiven, deren Quellen die Seite einschränken. */
|
|
133
|
+
const FETCH_DIRECTIVES = [
|
|
134
|
+
'default-src',
|
|
135
|
+
'script-src',
|
|
136
|
+
'script-src-elem',
|
|
137
|
+
'script-src-attr',
|
|
138
|
+
'style-src',
|
|
139
|
+
'style-src-elem',
|
|
140
|
+
'style-src-attr',
|
|
141
|
+
'img-src',
|
|
142
|
+
'font-src',
|
|
143
|
+
'connect-src',
|
|
144
|
+
'frame-src',
|
|
145
|
+
'child-src',
|
|
146
|
+
'media-src',
|
|
147
|
+
'worker-src',
|
|
148
|
+
'object-src',
|
|
149
|
+
'manifest-src',
|
|
150
|
+
];
|
|
151
|
+
/** Weitere Direktiven, die nicht lockerer sein dürfen als erwartet. Fehlen sie, gilt nichts. */
|
|
152
|
+
const NAVIGATION_DIRECTIVES = ['base-uri', 'form-action'];
|
|
153
|
+
/** Direktiven, die die Seite gar nicht setzen darf: Berichte gingen an fremde Hosts. */
|
|
154
|
+
const FORBIDDEN_DIRECTIVES = ['report-uri', 'report-to'];
|
|
155
|
+
/** Welche Quellen wirklich gelten (CSP-Rückfall-Kette). `undefined` = keine Einschränkung. */
|
|
156
|
+
function effective(csp, directive) {
|
|
157
|
+
const chain = {
|
|
158
|
+
'script-src-elem': ['script-src', 'default-src'],
|
|
159
|
+
'script-src-attr': ['script-src', 'default-src'],
|
|
160
|
+
'style-src-elem': ['style-src', 'default-src'],
|
|
161
|
+
'style-src-attr': ['style-src', 'default-src'],
|
|
162
|
+
'worker-src': ['child-src', 'script-src', 'default-src'],
|
|
163
|
+
'frame-src': ['child-src', 'default-src'],
|
|
164
|
+
'default-src': [],
|
|
165
|
+
};
|
|
166
|
+
if (csp[directive])
|
|
167
|
+
return csp[directive];
|
|
168
|
+
for (const next of chain[directive] ?? ['default-src'])
|
|
169
|
+
if (csp[next])
|
|
170
|
+
return csp[next];
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
const DEALSYSTEM_API = /^https:\/\/(?:[a-z0-9-]+\.)*dealsystem\.io$/;
|
|
174
|
+
const LOCAL_API = /^http:\/\/(?:localhost|127\.0\.0\.1)(?::\d+)?$/;
|
|
175
|
+
/**
|
|
176
|
+
* Was am Meta-Tag einer fertigen Seite lockerer ist als die erwartete CSP. Strenger ist erlaubt (dann bleibt nur
|
|
177
|
+
* etwas auf der eigenen Seite leer, das melden die Einbettungs-Prüfungen). `apiOrigin`: Adresse der Site-API, für
|
|
178
|
+
* die gebaut wurde; ohne Angabe gilt jede Adresse von DealSystem und ein lokaler Entwicklungsserver.
|
|
179
|
+
*/
|
|
180
|
+
export function cspLooserThan(meta, expected, apiOrigin,
|
|
181
|
+
/** Fehlende Direktiven melden (`default-src`, `base-uri`, `form-action`). Nur, wenn die Deklaration bekannt ist. */
|
|
182
|
+
requireAll = true) {
|
|
183
|
+
const problems = [];
|
|
184
|
+
for (const name of FORBIDDEN_DIRECTIVES) {
|
|
185
|
+
if (meta[name])
|
|
186
|
+
problems.push(`\`${name}\` ist gesetzt (Berichte gingen an \`${meta[name].join(' ')}\`).`);
|
|
187
|
+
}
|
|
188
|
+
const norm = (s) => unquote(s).toLowerCase();
|
|
189
|
+
const allowedIn = (directive, source) => {
|
|
190
|
+
const s = norm(source);
|
|
191
|
+
if (s === 'none')
|
|
192
|
+
return true;
|
|
193
|
+
// SvelteKit trägt die Prüfsummen seiner eigenen Inline-Skripte und -Styles ein.
|
|
194
|
+
if (/^(?:sha256|sha384|sha512)-[A-Za-z0-9+/=_-]+$/i.test(s) && /^(?:script|style)-src/.test(directive))
|
|
195
|
+
return true;
|
|
196
|
+
const list = (effective(expected, directive) ?? []).map(norm);
|
|
197
|
+
if (list.includes(s))
|
|
198
|
+
return true;
|
|
199
|
+
// Site-API: jede Adresse von DealSystem (eigene Domain, kein fremder Empfänger); ein lokaler Server nur,
|
|
200
|
+
// wenn die Seite für ihn gebaut wurde oder die Adresse unbekannt ist.
|
|
201
|
+
if (directive === 'connect-src' || directive === 'default-src') {
|
|
202
|
+
if (DEALSYSTEM_API.test(s))
|
|
203
|
+
return true;
|
|
204
|
+
if (LOCAL_API.test(s) && (!apiOrigin || LOCAL_API.test(apiOrigin.toLowerCase())))
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
const host = parseHostSource(s);
|
|
208
|
+
return list.some((e) => {
|
|
209
|
+
const wanted = parseHostSource(e);
|
|
210
|
+
return Boolean(wanted?.wildcard && host && host.host.endsWith(`.${wanted.host}`));
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
for (const name of [...FETCH_DIRECTIVES, ...NAVIGATION_DIRECTIVES]) {
|
|
214
|
+
// Ohne bekannte Deklaration nur, was der Meta-Tag selbst setzt (eine knappe, ältere CSP bleibt still).
|
|
215
|
+
const sources = FETCH_DIRECTIVES.includes(name) && requireAll ? effective(meta, name) : meta[name];
|
|
216
|
+
if (sources === undefined) {
|
|
217
|
+
if (requireAll && (name === 'default-src' || NAVIGATION_DIRECTIVES.includes(name)))
|
|
218
|
+
problems.push(`\`${name}\` fehlt, damit gilt dafür keine Einschränkung.`);
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
if (!FETCH_DIRECTIVES.includes(name) && !meta[name])
|
|
222
|
+
continue;
|
|
223
|
+
const looser = sources.filter((s) => !allowedIn(name, s));
|
|
224
|
+
if (looser.length > 0) {
|
|
225
|
+
problems.push(`\`${name}\` erlaubt zusätzlich \`${looser.join(' ')}\`.`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return [...new Set(problems)];
|
|
229
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { LineIndex } from './lines.js';
|
|
2
|
+
export interface HtmlElement {
|
|
3
|
+
tag: string;
|
|
4
|
+
attrs: Record<string, string>;
|
|
5
|
+
children: HtmlNode[];
|
|
6
|
+
parent: HtmlElement | null;
|
|
7
|
+
/** Zeichen-Offset des öffnenden Tags. */
|
|
8
|
+
start: number;
|
|
9
|
+
}
|
|
10
|
+
export interface HtmlText {
|
|
11
|
+
text: string;
|
|
12
|
+
parent: HtmlElement | null;
|
|
13
|
+
start: number;
|
|
14
|
+
}
|
|
15
|
+
export type HtmlNode = HtmlElement | HtmlText;
|
|
16
|
+
export interface HtmlDoc {
|
|
17
|
+
root: HtmlElement;
|
|
18
|
+
lines: LineIndex;
|
|
19
|
+
/** Alle Elemente in Dokument-Reihenfolge. */
|
|
20
|
+
elements: HtmlElement[];
|
|
21
|
+
}
|
|
22
|
+
export declare function isElement(node: HtmlNode): node is HtmlElement;
|
|
23
|
+
export declare function parseHtml(html: string): HtmlDoc;
|
|
24
|
+
/** Sichtbarer Text eines Elements (ohne `script`, `style`, `template`). */
|
|
25
|
+
export declare function textContent(el: HtmlElement): string;
|
|
26
|
+
export declare function ancestors(el: HtmlElement): HtmlElement[];
|
|
27
|
+
/** Element oder ein Vorfahre ist für Hilfstechnik versteckt. */
|
|
28
|
+
export declare function isHidden(el: HtmlElement): boolean;
|
|
29
|
+
export declare function lineOf(doc: HtmlDoc, el: {
|
|
30
|
+
start: number;
|
|
31
|
+
}): number;
|