import { Device } from "@siteimprove/alfa-device" ; import { Element , Node } from "@siteimprove/alfa-dom" ; import { Option } from "@siteimprove/alfa-option" ; import { Err , Ok } from "@siteimprove/alfa-result" ; import * as act from "@siteimprove/alfa-act" ; import { expectation } from "../expectation" ; import { isPerceivable } from "../predicate/is-perceivable" ; import { Question } from "../question" ; import { Diagnostic } from "@siteimprove/alfa-act" ; function mediaTextAlternative ( alt , label , device , kind ) { return { 1 : alt . map ( ( alt ) => expectation ( alt . isSome ( ) , ( ) => expectation ( alt . some ( isPerceivable ( device ) ) , ( ) => Outcomes . HasPerceivableAlternative ( kind ) , ( ) => Outcomes . HasNonPerceivableAlternative ( kind ) ) , ( ) => Outcomes . HasNoAlternative ( kind ) ) ) , 2 : label . map ( ( label ) => expectation ( label . isSome ( ) , ( ) => expectation ( label . some ( isPerceivable ( device ) ) , ( ) => Outcomes . HasPerceivableLabel ( kind ) , ( ) => Outcomes . HasNonPerceivableLabel ( kind ) ) , ( ) => Outcomes . HasNoLabel ( kind ) ) ) , } ; } export function audioTextAlternative ( target , device ) { const alt = Question . of ( "text-alternative" , target , Diagnostic . of ( `Where is the text alternative of the \`<audio>\` element?` ) ) ; const label = Question . of ( "label" , target , Diagnostic . of ( `Where is the text that labels the \`<audio>\` element as a video alternative?` ) ) ; return mediaTextAlternative ( alt , label , device , "<video>" ) ; } export function videoTextAlternative ( target , device ) { const alt = Question . of ( "text-alternative" , target , Diagnostic . of ( `Where is the text alternative of the \`<video>\` element?` ) ) ; const label = Question . of ( "label" , target , Diagnostic . of ( `Where is the text that labels the \`<video>\` element as a video alternative?` ) ) ; return mediaTextAlternative ( alt , label , device , "<video>" ) ; } export namespace Outcomes { export const HasPerceivableAlternative = ( kind ) => Ok . of ( Diagnostic . of ( `The \`${ kind }\` element has a text alternative that is perceivable` ) ) ; export const HasNonPerceivableAlternative = ( kind ) => Err . of ( Diagnostic . of ( `The \`${ kind }\` element has a text alternative that is not perceivable` ) ) ; export const HasNoAlternative = ( kind ) => Err . of ( Diagnostic . of ( `The \`${ kind }\` element has no text alternative` ) ) ; export const HasPerceivableLabel = ( kind ) => Ok . of ( Diagnostic . of ( `The \`${ kind }\` element is labelled as a video alternative and the label is perceivable` ) ) ; export const HasNonPerceivableLabel = ( kind ) => Err . of ( Diagnostic . of ( `The \`${ kind }\` element is labelled as a video alternative, but the label is not perceivable` ) ) ; export const HasNoLabel = ( kind ) => Err . of ( Diagnostic . of ( `The \`${ kind }\` element is not labelled as a video alternative` ) ) ; }