import { Hash } from "@siteimprove/alfa-hash" ; import { Parser } from "@siteimprove/alfa-parser" ; import { Slice } from "@siteimprove/alfa-slice" ; import { Token } from "../syntax/token" ; import { Converter } from "./converter" ; import { Unit } from "./unit" ; import { Dimension } from "./dimension" ; const { map } = Parser ; /**
 *  https public export class Angle < U extends Unit . Angle = Unit . Angle > extends Dimension < "angle" , Unit . Angle , U > { public static of < U extends Unit . Angle > ( value , unit ) { return new Angle ( value , unit ) ; } private constructor ( value , unit ) { super ( value , unit ) ; } public get type ( ) : "angle" { return "angle" ; } public get canonicalUnit ( ) : "deg" { return "deg" ; } public hasUnit < U extends Unit . Angle > ( unit ) { return ( this . _unit as Unit . Angle ) === unit ; } public withUnit < U extends Unit . Angle > ( unit ) { if ( this . hasUnit ( unit ) ) { return this ; } return new Angle ( Converter . angle ( this . _value , this . _unit , unit ) , unit ) ; } public equals ( value ) { return ( value instanceof Angle && super . equals ( value ) && value . _unit === this . _unit ) ; } public hash ( hash ) { super . hash ( hash ) ; hash . writeString ( this . _unit ) ; } public toJSON ( ) { return { type : "angle" , value : this . _value , unit : this . _unit , } ; } public toString ( ) { return `${ this . _value }${ this . _unit }` ; } } public export namespace Angle { export interface JSON extends Dimension . JSON < "angle" > { unit : Unit . Angle ; } export function isAngle ( value ) { return value instanceof Angle ; } export const parse = map ( Token . parseDimension ( ( dimension ) => Unit . isAngle ( dimension . unit ) ) , ( dimension ) => Angle . of ( dimension . value , dimension . unit as Unit . Angle ) ) ; }