import { Keyword , Token } from "@siteimprove/alfa-css" ; import { None , Option } from "@siteimprove/alfa-option" ; import { Parser } from "@siteimprove/alfa-parser" ; import { Result } from "@siteimprove/alfa-result" ; import * as slice from "@siteimprove/alfa-slice" ; import { Property } from "../property" ; import * as Outset from "./border-image-outset" ; import * as Repeat from "./border-image-repeat" ; import * as Source from "./border-image-source" ; import * as Slice from "./border-image-slice" ; import * as Width from "./border-image-width" ; const { delimited , either , map , option , pair , right } = Parser ; declare module "../property" { interface Shorthands { "border-image" : Property . Shorthand < "border-image-source" | "border-image-slice" | "border-image-width" | "border-image-outset" | "border-image-repeat" > ; } } const parseSlash = delimited ( option ( Token . parseWhitespace ) , Token . parseDelim ( "/" ) ) ; /**
 * Parsing
 * [ / <'width'> | / <'width'>? / <'outset'> ]?
 */ const parseWidthOutset = map < slice . Slice < Token > , Option < [ Option < Width . Specified > , Option < Outset . Specified > ] > , [ Option < Width . Specified > , Option < Outset . Specified > ] , string > ( option ( right ( parseSlash , either ( map ( pair ( option ( Width . parse ) , right ( parseSlash , Outset . parse ) ) , ( [ width , outset ] ) => [ width , Option . of ( outset ) ] ) , map ( Width . parse , ( width ) => [ Option . of ( width ) , None ] ) ) ) ) , ( result ) => result . getOr ( [ None , None ] ) ) ; const parse = ( input ) => { let source ; let slice ; let width = None ; let outset = None ; let repeat ; while ( true ) { for ( const [ remainder ] of Token . parseWhitespace ( input ) ) { input = remainder ; } if ( source === undefined ) { const result = Source . parse ( input ) ; if ( result . isOk ( ) ) { [ input , source ] = result . get ( ) ; continue ; } } if ( slice === undefined ) { const result = pair ( Slice . parse , parseWidthOutset ) ( input ) ; if ( result . isOk ( ) ) { [ input , [ slice , [ width , outset ] ] ] = result . get ( ) ; continue ; } } if ( repeat === undefined ) { const result = Repeat . parse ( input ) ; if ( result . isOk ( ) ) { [ input , repeat ] = result . get ( ) ; continue ; } } break ; } return Result . of ( [ input , [ source ?? Keyword . of ( "initial" ) , slice ?? Keyword . of ( "initial" ) , width . getOr ( Keyword . of ( "initial" ) ) , outset . getOr ( Keyword . of ( "initial" ) ) , repeat ?? Keyword . of ( "initial" ) , ] , ] ) ; } ; /**
 *  https internal export default Property . registerShorthand ( "border-image" , Property . shorthand ( [ "border-image-source" , "border-image-slice" , "border-image-width" , "border-image-outset" , "border-image-repeat" , ] , map ( parse , ( [ source , slice , width , outset , repeat ] ) => [ [ "border-image-source" , source ] , [ "border-image-slice" , slice ] , [ "border-image-width" , width ] , [ "border-image-outset" , outset ] , [ "border-image-repeat" , repeat ] , ] ) ) ) ;