import { Equatable } from "@siteimprove/alfa-equatable" ; import { Serializable } from "@siteimprove/alfa-json" ; import { Option , None } from "@siteimprove/alfa-option" ; import { Sequence } from "@siteimprove/alfa-sequence" ; import * as json from "@siteimprove/alfa-json" ; import { Attributes } from "./attribute/data" ; import { Role } from "./role" ; import { Roles } from "./role/data" ; public export class Attribute < N extends Attribute . Name = Attribute . Name > implements Equatable , Serializable { public static of < N extends Attribute . Name > ( name , value ) { return new Attribute ( name , value ) ; } private readonly _name : N ; private readonly _value : string ; private constructor ( name , value ) { this . _name = name ; this . _value = value ; } public get name ( ) : N { return this . _name ; } public get value ( ) : string { return this . _value ; } public get kind ( ) : Attribute . Kind < N > { return Attributes [ this . _name ] . kind ; } public get type ( ) : Attribute . Type < N > { return Attributes [ this . _name ] . type ; } public get default ( ) : Option < Attribute . Default < N > > { const value = Attributes [ this . _name ] . default ; if ( value === null ) { return None ; } return Option . of ( value as Attribute . Default < N > ) ; } public get options ( ) : Sequence < Attribute . Option < N > > { const options = Attributes [ this . _name ] . options ; if ( options === null ) { return Sequence . empty ( ) ; } return Sequence . from ( options as Iterable < Attribute . Option < N > > ) ; } /**
     *  https public isGlobal ( ) { return Role . of ( "roletype" ) . isAttributeSupported ( this . _name ) ; } public equals ( value ) { return ( value instanceof Attribute && value . _name === this . _name && value . _value === this . _value ) ; } public toJSON ( ) { return { name : this . _name , value : this . _value , } ; } } public export namespace Attribute { export interface JSON { [ key ] : json . JSON ; name : Name ; value : string ; } export type Name = keyof Attributes ; export function isName ( value ) { return value in Attributes ; } /**
     * The names of all global attributes.
     */ export type Global = Members < Roles [ "roletype" ] [ "attributes" ] > [ 0 ] ; /**
     * The kind of the specified attribute.
     */ export type Kind < N extends Name = Name > = Attributes [ N ] [ "kind" ] ; /**
     * The type of the specified attribute.
     */ export type Type < N extends Name = Name > = Attributes [ N ] [ "type" ] ; remarks export type Default < N extends Name = Name > = Exclude < Attributes [ N ] [ "default" ] , null > ; remarks export type Option < N extends Name = Name > = Members < Attributes [ N ] [ "options" ] > ; } type Members < T > = T extends Iterable < infer T > ? T : never ;