import { Hash } from "@siteimprove/alfa-hash" ; import { Parser } from "@siteimprove/alfa-parser" ; import { Slice } from "@siteimprove/alfa-slice" ; import { Token } from "../../syntax/token" ; import { Function } from "../../syntax/function" ; import { Value } from "../../value" ; import { Keyword } from "../keyword" ; import { Position } from "../position" ; import { Radius } from "./radius" ; const { map , option , pair , right } = Parser ; /**
 *  https public export class Ellipse < R extends Radius = Radius , P extends Position = Position > extends Value < "basic-shape" > { public static of < R extends Radius = Radius , P extends Position = Position > ( rx , ry , center ) { return new Ellipse ( rx , ry , center ) ; } private readonly _rx : R ; private readonly _ry : R ; private readonly _center : P ; private constructor ( rx , ry , center ) { super ( ) ; this . _rx = rx ; this . _ry = ry ; this . _center = center ; } public get type ( ) : "basic-shape" { return "basic-shape" ; } public get kind ( ) : "ellipse" { return "ellipse" ; } public get rx ( ) : R { return this . _rx ; } public get ry ( ) : R { return this . _ry ; } public get center ( ) : P { return this . _center ; } public equals ( value ) ; public equals ( value ) ; public equals ( value ) { return ( value instanceof Ellipse && value . _rx . equals ( this . _rx ) && value . _ry . equals ( this . _ry ) && value . _center . equals ( this . _center ) ) ; } public hash ( hash ) { hash . writeHashable ( this . _rx ) . writeHashable ( this . _ry ) . writeHashable ( this . _center ) ; } public toJSON ( ) { return { type : "basic-shape" , kind : "ellipse" , rx : this . _rx . toJSON ( ) , ry : this . _ry . toJSON ( ) , center : this . _center . toJSON ( ) , } ; } public toString ( ) { return `ellipse(${ this . _rx } ${ this . _ry } at ${ this . _center })` ; } } public export namespace Ellipse { export interface JSON extends Value . JSON < "basic-shape" > { kind : "ellipse" ; rx : Radius . JSON ; ry : Radius . JSON ; center : Position . JSON ; } export function isEllipse ( value ) { return value instanceof Ellipse ; } export const parse = map ( Function . parse ( "ellipse" , pair ( option ( pair ( Radius . parse , right ( Token . parseWhitespace , Radius . parse ) ) ) , option ( right ( option ( Token . parseWhitespace ) , right ( Keyword . parse ( "at" ) , right ( Token . parseWhitespace , Position . parse ( ) ) ) ) ) ) ) , ( [ _ , [ radii , center ] ] ) => { const [ rx , ry ] = radii . getOr ( [ Radius . of ( Keyword . of ( "closest-side" ) ) , Radius . of ( Keyword . of ( "closest-side" ) ) , ] ) ; return Ellipse . of ( rx , ry , center . getOr ( Position . of ( Keyword . of ( "center" ) , Keyword . of ( "center" ) ) ) ) ; } ) ; }