import { Keyword , Token } from "@siteimprove/alfa-css" ; import { Parser } from "@siteimprove/alfa-parser" ; import { Err , Result } from "@siteimprove/alfa-result" ; import { Slice } from "@siteimprove/alfa-slice" ; import { Property } from "../property" ; import { Tuple } from "./value/tuple" ; const { map , either } = Parser ; declare module "../property" { interface Longhands { display : Property < Specified , Computed > ; } } internal export type Specified = Tuple < [ outside : Specified . Outside , inside : Specified . Inside , listitem ? : Specified . ListItem ] | [ outside : Specified . Internal , inside : Specified . Inside ] | [ Specified . Box ] > ; internal export namespace Specified { /**
     *  https export type Outside = Keyword < "block" > | Keyword < "inline" > | Keyword < "run-in" > ; /**
     *  https export type Inside = Keyword < "flow" > | Keyword < "flow-root" > | Keyword < "table" > | Keyword < "flex" > | Keyword < "grid" > | Keyword < "ruby" > ; /**
     *  https export type ListItem = Keyword < "list-item" > ; /**
     *  https export type Internal = Keyword < "table-row-group" > | Keyword < "table-header-group" > | Keyword < "table-footer-group" > | Keyword < "table-row" > | Keyword < "table-cell" > | Keyword < "table-column-group" > | Keyword < "table-column" > | Keyword < "table-caption" > | Keyword < "ruby-base" > | Keyword < "ruby-text" > | Keyword < "ruby-base-container" > | Keyword < "ruby-text-container" > ; /**
     *  https export type Box = Keyword < "contents" > | Keyword < "none" > ; } internal export type Computed = Specified ; /**
 *  https const parseOutside = Keyword . parse ( "block" , "inline" , "run-in" ) ; /**
 *  https const parseInside = Keyword . parse ( "flow" , "flow-root" , "table" , "flex" , "grid" , "ruby" ) ; /**
 *  https const parseListItem = Keyword . parse ( "list-item" ) ; /**
 *  https const parseInternal = Keyword . parse ( "table-row-group" , "table-header-group" , "table-footer-group" , "table-row" , "table-cell" , "table-column-group" , "table-column" , "table-caption" , "ruby-base" , "ruby-text" , "ruby-base-container" , "ruby-text-container" ) ; /**
 *  https const parseBox = Keyword . parse ( "contents" , "none" ) ; /**
 *  https const parseLegacy = Keyword . parse ( "inline-block" , "inline-table" , "inline-flex" , "inline-grid" ) ; internal export const parse = either < Slice < Token > , Specified , string > ( ( input ) => { let outside ; let inside ; let listItem ; while ( true ) { for ( [ input ] of Token . parseWhitespace ( input ) ) { } if ( outside === undefined ) { const result = parseOutside ( input ) ; if ( result . isOk ( ) ) { [ input , outside ] = result . get ( ) ; continue ; } } if ( inside === undefined ) { const result = parseInside ( input ) ; if ( result . isOk ( ) ) { [ input , inside ] = result . get ( ) ; continue ; } } if ( listItem === undefined ) { const result = parseListItem ( input ) ; if ( result . isOk ( ) ) { [ input , listItem ] = result . get ( ) ; continue ; } } break ; } if ( outside === undefined && inside === undefined && listItem === undefined ) { return Err . of ( `Expected an outer or inner display type or a list marker` ) ; } if ( inside === undefined ) { inside = Keyword . of ( "flow" ) ; } if ( outside === undefined ) { outside = inside . value === "ruby" ? Keyword . of ( "inline" ) : Keyword . of ( "block" ) ; } if ( listItem === undefined ) { return Result . of ( [ input , Tuple . of ( outside , inside ) ] ) ; } switch ( inside . value ) { case "flow" : case "flow-root" : break ; default : return Err . of ( `Unexpected inner display type for list marker` ) ; } return Result . of ( [ input , Tuple . of ( outside , inside , listItem ) ] ) ; } , map ( parseInternal , ( keyword ) => { switch ( keyword . value ) { case "table-row-group" : case "table-header-group" : case "table-footer-group" : case "table-row" : case "table-cell" : case "table-column-group" : case "table-column" : case "table-caption" : return Tuple . of ( keyword , Keyword . of ( "flow-root" ) ) ; case "ruby-base" : case "ruby-text" : case "ruby-base-container" : case "ruby-text-container" : return Tuple . of ( keyword , Keyword . of ( "flow" ) ) ; } } ) , map ( parseBox , ( keyword ) => Tuple . of ( keyword ) ) , map ( parseLegacy , ( keyword ) => { const inline = Keyword . of ( "inline" ) ; switch ( keyword . value ) { case "inline-block" : return Tuple . of ( inline , Keyword . of ( "flow-root" ) ) ; case "inline-table" : return Tuple . of ( inline , Keyword . of ( "table" ) ) ; case "inline-flex" : return Tuple . of ( inline , Keyword . of ( "flex" ) ) ; case "inline-grid" : return Tuple . of ( inline , Keyword . of ( "grid" ) ) ; } } ) ) ; /**
 *  https internal export default Property . register ( "display" , Property . of < Specified , Computed > ( Tuple . of ( Keyword . of ( "inline" ) , Keyword . of ( "flow" ) ) , parse , ( value , style ) => style . computed ( "position" ) . value . equals ( Keyword . of ( "absolute" ) ) || style . computed ( "position" ) . value . equals ( Keyword . of ( "fixed" ) ) || ! style . computed ( "float" ) . value . equals ( Keyword . of ( "none" ) ) ? value . map ( displayTable ) : value ) ) ; /**
 *  https internal export function displayTable ( value ) { if ( value . values . length === 1 ) { return value ; } const [ outside , inside ] = value . values ; switch ( outside . value ) { case "inline" : switch ( inside . value ) { case "table" : return Tuple . of ( Keyword . of ( "block" ) , Keyword . of ( "table" ) ) ; case "flow" : case "flow-root" : return Tuple . of ( Keyword . of ( "block" ) , Keyword . of ( "flow" ) ) ; default : return value ; } case "table-row-group" : case "table-header-group" : case "table-footer-group" : case "table-row" : case "table-cell" : case "table-column-group" : case "table-column" : case "table-caption" : return Tuple . of ( Keyword . of ( "block" ) , Keyword . of ( "flow" ) ) ; default : return value ; } }