/** Built-in accessibility audit rules for rich text content. */
export const BUILT_IN_RULES = [
    {
        id: 'img-alt',
        name: 'Image alt text',
        description: 'Images must have alt attributes',
        severity: 'error',
        check(html) {
            const violations = [];
            const imgRegex = /<img(?![^>]*alt=)[^>]*>/gi;
            let match;
            while ((match = imgRegex.exec(html)) !== null) {
                violations.push({
                    ruleId: 'img-alt',
                    severity: 'error',
                    message: 'Image is missing alt attribute',
                    context: match[0].slice(0, 100),
                });
            }
            return violations;
        },
    },
    {
        id: 'heading-order',
        name: 'Heading order',
        description: 'Headings should not skip levels',
        severity: 'warning',
        check(html) {
            const violations = [];
            const headingRegex = /<h([1-6])/gi;
            let lastLevel = 0;
            let match;
            while ((match = headingRegex.exec(html)) !== null) {
                const level = parseInt(match[1], 10);
                if (lastLevel > 0 && level > lastLevel + 1) {
                    violations.push({
                        ruleId: 'heading-order',
                        severity: 'warning',
                        message: `Heading level skipped from h${lastLevel} to h${level}`,
                    });
                }
                lastLevel = level;
            }
            return violations;
        },
    },
    {
        id: 'link-text',
        name: 'Link text',
        description: "Links should have descriptive text, not 'click here'",
        severity: 'warning',
        check(html) {
            const violations = [];
            const linkRegex = /<a[^>]*>(.*?)<\/a>/gi;
            const badTexts = new Set(['click here', 'here', 'read more', 'more', 'link']);
            let match;
            while ((match = linkRegex.exec(html)) !== null) {
                const text = match[1]
                    ?.replace(/<[^>]*>/g, '')
                    .trim()
                    .toLowerCase();
                if (text && badTexts.has(text)) {
                    violations.push({
                        ruleId: 'link-text',
                        severity: 'warning',
                        message: `Link has non-descriptive text: "${text}"`,
                        context: match[0].slice(0, 100),
                    });
                }
            }
            return violations;
        },
    },
];
/** Run accessibility audit rules against HTML content. */
export function auditContent(html, rules) {
    const activeRules = rules ?? BUILT_IN_RULES;
    const violations = [];
    let passes = 0;
    for (const rule of activeRules) {
        const found = rule.check(html);
        if (found.length > 0) {
            violations.push(...found);
        }
        else {
            passes++;
        }
    }
    return { violations, passes, timestamp: new Date() };
}
//# sourceMappingURL=index.js.map