import { Token , Number , Percentage , Keyword } 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 { either , filter } = Parser ; declare module "../property" { interface Longhands { "border-image-slice" : Property < Specified , Computed > ; } } internal export type Specified = Tuple < [ top : Specified . Item , right : Specified . Item , bottom : Specified . Item , left : Specified . Item , fill ? : Keyword < "fill" > ] > ; internal export namespace Specified { export type Item = Number | Percentage ; } internal export type Computed = Specified ; const parseItem = filter ( either ( Number . parse , Percentage . parse ) , ( size ) => size . value >= 0 , ( ) => `Negative sizes are not allowed` ) ; const parseFill = Keyword . parse ( "fill" ) ; internal export const parse = ( input ) => { let top ; let right ; let bottom ; let left ; let fill ; while ( true ) { for ( [ input ] of Token . parseWhitespace ( input ) ) { } const result = parseItem ( input ) ; if ( result . isOk ( ) ) { if ( top === undefined ) { [ input , top ] = result . get ( ) ; continue ; } if ( right === undefined ) { [ input , right ] = result . get ( ) ; continue ; } if ( bottom === undefined ) { [ input , bottom ] = result . get ( ) ; continue ; } if ( left === undefined ) { [ input , left ] = result . get ( ) ; continue ; } } else if ( fill === undefined ) { const result = parseFill ( input ) ; if ( result . isOk ( ) ) { [ input , fill ] = result . get ( ) ; continue ; } } break ; } if ( top === undefined ) { return Err . of ( `Expected an image slice` ) ; } right = right ?? top ; bottom = bottom ?? top ; left = left ?? right ; return Result . of ( [ input , fill ? Tuple . of ( top , right , bottom , left , fill ) : Tuple . of ( top , right , bottom , left ) , ] ) ; } ; /**
 *  https internal export default Property . register ( "border-image-slice" , Property . of < Specified , Computed > ( Tuple . of ( Percentage . of ( 1 ) , Percentage . of ( 1 ) , Percentage . of ( 1 ) , Percentage . of ( 1 ) ) , parse , ( value ) => value ) ) ;