import { Rule , Diagnostic } from "@siteimprove/alfa-act" ; import { Array } from "@siteimprove/alfa-array" ; import { Document , Element , Namespace } from "@siteimprove/alfa-dom" ; import { Iterable } from "@siteimprove/alfa-iterable" ; import { Predicate } from "@siteimprove/alfa-predicate" ; import { Err , Ok } from "@siteimprove/alfa-result" ; import { Page } from "@siteimprove/alfa-web" ; import { expectation } from "../common/expectation" ; import { hasChild , isRendered , isDocumentElement } from "../common/predicate" ; import { Scope } from "../tags" ; const { isElement , hasName , hasNamespace } = Element ; const { and , test } = Predicate ; const isDeprecated = hasName ( "acronym" , "applet" , "basefont" , "bgsound" , "big" , "blink" , "center" , "content" , "dir" , "font" , "frame" , "frameset" , "hgroup" , "image" , "keygen" , "marquee" , "menuitem" , "nobr" , "noembed" , "noframes" , "plaintext" , "rb" , "rtc" , "shadow" , "spacer" , "strike" , "tt" , "xmp" ) ; export default Rule . Atomic . of < Page , Document > ( { uri : "https://alfa.siteimprove.com/rules/sia-r70" , tags : [ Scope . Page ] , evaluate ( { device , document } ) { return { applicability ( ) { return test ( hasChild ( isDocumentElement ) , document ) ? [ document ] : [ ] ; } , expectations ( target ) { const deprecatedElements = target . descendants ( { flattened : true , nested : true } ) . filter ( isElement ) . filter ( and ( hasNamespace ( Namespace . HTML ) , isDeprecated , isRendered ( device ) ) ) ; return { 1 : expectation ( deprecatedElements . isEmpty ( ) , ( ) => Outcomes . HasNoDeprecatedElement , ( ) => Outcomes . HasDeprecatedElements ( deprecatedElements ) ) , } ; } , } ; } , } ) ; export namespace Outcomes { export const HasNoDeprecatedElement = Ok . of ( Diagnostic . of ( `The document doesn't contain any deprecated elements` ) ) ; export const HasDeprecatedElements = ( errors ) => Err . of ( DeprecatedElements . of ( `The document contains deprecated elements` , errors ) ) ; } class DeprecatedElements extends Diagnostic implements Iterable < Element > { public static of ( message , errors = [ ] ) { return new DeprecatedElements ( message , Array . from ( errors ) ) ; } private _errors : ReadonlyArray < Element > ; private constructor ( message , errors ) { super ( message ) ; this . _errors = errors ; } public get errors ( ) : ReadonlyArray < Element > { return this . _errors ; } public equals ( value ) ; public equals ( value ) ; public equals ( value ) { return ( value instanceof DeprecatedElements && value . _message === this . _message && Array . equals ( value . _errors , this . _errors ) ) ; } public * [ Symbol . iterator ] ( ) { yield * this . _errors ; } public toJSON ( ) { return { ... super . toJSON ( ) , errors : this . _errors . map ( ( element ) => element . path ( ) ) , } ; } } namespace DeprecatedElements { export interface JSON extends Diagnostic . JSON { errors : Array < string > ; } export function isDeprecatedElements ( value ) { return value instanceof DeprecatedElements ; } }