license import { MDCFoundation } from '@material/base/foundation' ; import { MDCProgressIndicatorFoundation } from '@material/progress-indicator/foundation' ; import { MDCCircularProgressAdapter } from './adapter' ; import { cssClasses , strings } from './constants' ; export class MDCCircularProgressFoundation extends MDCFoundation < MDCCircularProgressAdapter > implements MDCProgressIndicatorFoundation { static override get cssClasses ( ) { return cssClasses ; } static override get strings ( ) { return strings ; } static override get defaultAdapter ( ) : MDCCircularProgressAdapter { return { addClass : ( ) => undefined , getDeterminateCircleAttribute : ( ) => null , hasClass : ( ) => false , removeClass : ( ) => undefined , removeAttribute : ( ) => undefined , setAttribute : ( ) => undefined , setDeterminateCircleAttribute : ( ) => undefined , } ; } private closed ! : boolean ; private determinate ! : boolean ; private progress ! : number ; private radius ! : number ; constructor ( adapter ? ) { super ( { ... MDCCircularProgressFoundation . defaultAdapter , ... adapter } ) ; } override init ( ) { this . closed = this . adapter . hasClass ( cssClasses . CLOSED_CLASS ) ; this . determinate = ! this . adapter . hasClass ( cssClasses . INDETERMINATE_CLASS ) ; this . progress = 0 ; if ( this . determinate ) { this . adapter . setAttribute ( strings . ARIA_VALUENOW , this . progress . toString ( ) ) ; } this . radius = Number ( this . adapter . getDeterminateCircleAttribute ( strings . RADIUS ) ) ; } param determinate setDeterminate ( determinate ) { this . determinate = determinate ; if ( this . determinate ) { this . adapter . removeClass ( cssClasses . INDETERMINATE_CLASS ) ; this . setProgress ( this . progress ) ; } else { this . adapter . addClass ( cssClasses . INDETERMINATE_CLASS ) ; this . adapter . removeAttribute ( strings . ARIA_VALUENOW ) ; } } isDeterminate ( ) { return this . determinate ; } param value setProgress ( value ) { this . progress = value ; if ( this . determinate ) { const unfilledArcLength = ( 1 - this . progress ) * ( 2 * Math . PI * this . radius ) ; this . adapter . setDeterminateCircleAttribute ( strings . STROKE_DASHOFFSET , `${ unfilledArcLength }` ) ; this . adapter . setAttribute ( strings . ARIA_VALUENOW , this . progress . toString ( ) ) ; } } getProgress ( ) { return this . progress ; } /**
     * Shows the progress indicator.
     */ open ( ) { this . closed = false ; this . adapter . removeClass ( cssClasses . CLOSED_CLASS ) ; this . adapter . removeAttribute ( strings . ARIA_HIDDEN ) ; } /**
     * Hides the progress indicator
     */ close ( ) { this . closed = true ; this . adapter . addClass ( cssClasses . CLOSED_CLASS ) ; this . adapter . setAttribute ( strings . ARIA_HIDDEN , 'true' ) ; } return isClosed ( ) { return this . closed ; } } export default MDCCircularProgressFoundation ;