license import { MDCComponent } from '@material/base/component' ; import { MDCProgressIndicator } from '@material/progress-indicator/component' ; import { MDCLinearProgressAdapter } from './adapter' ; import { MDCLinearProgressFoundation } from './foundation' ; import { WithMDCResizeObserver } from './types' ; export class MDCLinearProgress extends MDCComponent < MDCLinearProgressFoundation > implements MDCProgressIndicator { static override attachTo ( root ) { return new MDCLinearProgress ( root ) ; } set determinate ( value ) { this . foundation . setDeterminate ( value ) ; } set progress ( value ) { this . foundation . setProgress ( value ) ; } set buffer ( value ) { this . foundation . setBuffer ( value ) ; } open ( ) { this . foundation . open ( ) ; } close ( ) { this . foundation . close ( ) ; } override initialSyncWithDOM ( ) { this . root . addEventListener ( 'transitionend' , ( ) => { this . foundation . handleTransitionEnd ( ) ; } ) ; } override getDefaultFoundation ( ) { const adapter = { addClass : ( className ) => { this . root . classList . add ( className ) ; } , forceLayout : ( ) => { this . root . getBoundingClientRect ( ) ; } , setBufferBarStyle : ( styleProperty , value ) => { const bufferBar = this . root . querySelector < HTMLElement > ( MDCLinearProgressFoundation . strings . BUFFER_BAR_SELECTOR ) ; if ( bufferBar ) { bufferBar . style . setProperty ( styleProperty , value ) ; } } , setPrimaryBarStyle : ( styleProperty , value ) => { const primaryBar = this . root . querySelector < HTMLElement > ( MDCLinearProgressFoundation . strings . PRIMARY_BAR_SELECTOR ) ; if ( primaryBar ) { primaryBar . style . setProperty ( styleProperty , value ) ; } } , hasClass : ( className ) => this . root . classList . contains ( className ) , removeAttribute : ( attributeName ) => { this . root . removeAttribute ( attributeName ) ; } , removeClass : ( className ) => { this . root . classList . remove ( className ) ; } , setAttribute : ( attributeName , value ) => { this . root . setAttribute ( attributeName , value ) ; } , setStyle : ( name , value ) => { ( this . root as HTMLElement ) . style . setProperty ( name , value ) ; } , attachResizeObserver : ( callback ) => { const RO = ( window as unknown as WithMDCResizeObserver ) . ResizeObserver ; if ( RO ) { const ro = new RO ( callback ) ; ro . observe ( this . root ) ; return ro ; } return null ; } , getWidth : ( ) => ( this . root as HTMLElement ) . offsetWidth , } ; return new MDCLinearProgressFoundation ( adapter ) ; } }