UNPKG

@angular-mdc/web

Version:
22 lines (20 loc) 12.2 kB
/** * @license * Copyright (c) Dominic Carretto * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/trimox/angular-mdc-web/blob/master/LICENSE */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common"),require("@angular/forms"),require("@angular/cdk/coercion"),require("@angular/cdk/platform"),require("rxjs"),require("rxjs/operators"),require("@angular-mdc/web/base"),require("@material/slider")):"function"==typeof define&&define.amd?define("@angular-mdc/web/slider",["exports","@angular/core","@angular/common","@angular/forms","@angular/cdk/coercion","@angular/cdk/platform","rxjs","rxjs/operators","@angular-mdc/web/base","@material/slider"],t):t(((e=e||self).ng=e.ng||{},e.ng.web=e.ng.web||{},e.ng.web.slider={}),e.ng.core,e.ng.common,e.ng.forms,e.ng.cdk.coercion,e.ng.cdk.platform,e.rxjs,e.rxjs.operators,e.ng.web.base,e.mdc.slider)}(this,(function(e,t,n,r,i,o,a,s,u,c){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */var l=function(e,t){return(l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function d(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function s(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))}function p(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=(i=a.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}var f={provide:r.NG_VALUE_ACCESSOR,useExisting:t.forwardRef((function(){return m})),multi:!0},h=function(e,t){this.source=e,this.value=t},m=function(e){function n(n,r,i,o,s){var u=e.call(this,o)||this;return u._platform=n,u._ngZone=r,u._changeDetectorRef=i,u.elementRef=o,u._destroyed=new a.Subject,u._initialized=!1,u.tabIndex=0,u._discrete=!1,u._markers=!1,u._min=0,u._max=100,u._step=1,u._value=null,u._disabled=!1,u.change=new t.EventEmitter,u.input=new t.EventEmitter,u.valueChange=new t.EventEmitter,u._onTouched=function(){},u._controlValueAccessorChangeFn=function(){},u.tabIndex=parseInt(s,10)||0,u._root=u.elementRef.nativeElement,u}return function(e,t){function n(){this.constructor=e}l(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(n,e),Object.defineProperty(n.prototype,"discrete",{get:function(){return this._discrete},set:function(e){this._discrete=i.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"markers",{get:function(){return this._markers},set:function(e){this._markers=i.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"min",{get:function(){return this._min},set:function(e){var t=i.coerceNumberProperty(e);t!==this._min&&(this._min=t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"max",{get:function(){return this._max},set:function(e){var t=i.coerceNumberProperty(e);t!==this._max&&(this._max=t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"step",{get:function(){return this._step},set:function(e){var t=i.coerceNumberProperty(e,this._step);t!==this._step&&(this._step=t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"value",{get:function(){return null===this._value&&(this.value=this.min),this._value},set:function(e){this._value=i.coerceNumberProperty(e,null)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"disabled",{get:function(){return this._disabled},set:function(e){this.setDisabledState(e)},enumerable:!0,configurable:!0}),n.prototype.getDefaultFoundation=function(){var e=this,t={hasClass:function(t){return e._root.classList.contains(t)},addClass:function(t){return e._root.classList.add(t)},removeClass:function(t){return e._root.classList.remove(t)},getAttribute:function(t){return e._root.getAttribute(t)},setAttribute:function(t,n){return e._root.setAttribute(t,n)},removeAttribute:function(t){return e._root.removeAttribute(t)},computeBoundingRect:function(){return e._root.getBoundingClientRect()},getTabIndex:function(){return e._root.tabIndex},registerInteractionHandler:function(t,n){return e._root.addEventListener(t,n)},deregisterInteractionHandler:function(t,n){return e._root.removeEventListener(t,n)},registerThumbContainerInteractionHandler:function(t,n){e._ngZone.runOutsideAngular((function(){e.thumbContainer.nativeElement.addEventListener(t,n,o.supportsPassiveEventListeners())}))},deregisterThumbContainerInteractionHandler:function(t,n){return e.thumbContainer.nativeElement.removeEventListener(t,n,o.supportsPassiveEventListeners())},registerBodyInteractionHandler:function(e,t){return document.body.addEventListener(e,t)},deregisterBodyInteractionHandler:function(e,t){return document.body.removeEventListener(e,t)},registerResizeHandler:function(){},deregisterResizeHandler:function(){},notifyInput:function(){var t=e._foundation.getValue();t!==e.value&&(e.value=t,e.input.emit(e._createChangeEvent(t)))},notifyChange:function(){e.value=e._foundation.getValue(),e._emitChangeEvent(e.value)},setThumbContainerStyleProperty:function(t,n){return e.thumbContainer.nativeElement.style.setProperty(t,n)},setTrackStyleProperty:function(t,n){return e.track.nativeElement.style.setProperty(t,n)},setMarkerValue:function(t){e._changeDetectorRef.markForCheck(),e.pinValueMarker.nativeElement.innerText=null!==t?t.toString():null},setTrackMarkers:function(t,n,r){return e.trackMarkerContainer.nativeElement.style.setProperty("background",e._getTrackMarkersBackground(t,r,n))},isRTL:function(){return!!e._platform.isBrowser&&"rtl"===window.getComputedStyle(e._root).getPropertyValue("direction")}};return new c.MDCSliderFoundation(t)},n.prototype.ngOnChanges=function(e){this._initialized&&(e.step&&this._syncStepWithFoundation(),e.max&&this._syncMaxWithFoundation(),e.min&&this._syncMinWithFoundation(),e.value&&this._syncValueWithFoundation(),(e.markers||e.discrete)&&this._refreshTrackMarkers())},n.prototype._asyncInitializeFoundation=function(){return d(this,void 0,void 0,(function(){return p(this,(function(e){return this._foundation.init(),[2]}))}))},n.prototype.ngAfterViewInit=function(){var e=this;this._platform.isBrowser&&(this._initialized=!0,this._asyncInitializeFoundation().then((function(){e._syncStepWithFoundation(),e._syncMaxWithFoundation(),e._syncMinWithFoundation(),e._syncValueWithFoundation(),e._foundation.setupTrackMarker(),e._loadListeners(),e._changeDetectorRef.markForCheck()})))},n.prototype.ngOnDestroy=function(){this._destroyed.next(),this._destroyed.complete(),this.destroy()},n.prototype.writeValue=function(e){this.value=e,this._syncValueWithFoundation()},n.prototype.registerOnChange=function(e){this._controlValueAccessorChangeFn=e},n.prototype.registerOnTouched=function(e){this._onTouched=e},n.prototype.setDisabledState=function(e){this._disabled=i.coerceBooleanProperty(e),this._foundation.setDisabled(e),this._changeDetectorRef.markForCheck()},n.prototype.layout=function(){this._foundation.layout()},n.prototype._loadListeners=function(){var e=this;this._ngZone.runOutsideAngular((function(){return a.fromEvent(window,"resize").pipe(s.auditTime(16),s.takeUntil(e._destroyed)).subscribe((function(){return e.layout()}))}))},n.prototype._syncValueWithFoundation=function(){this._foundation.setValue(this.value)},n.prototype._syncStepWithFoundation=function(){this._foundation.setStep(this.step)},n.prototype._syncMinWithFoundation=function(){this._foundation.setMin(this.min)},n.prototype._syncMaxWithFoundation=function(){this._foundation.setMax(this.max)},n.prototype._createChangeEvent=function(e){return new h(this,e)},n.prototype._emitChangeEvent=function(e){this._controlValueAccessorChangeFn(e),this.valueChange.emit(e),this.change.emit(this._createChangeEvent(e))},n.prototype._getTrackMarkersBackground=function(e,t,n){var r=e.toLocaleString();return"linear-gradient(to right, currentColor 2px, transparent 0) "+("0 center / calc((100% - 2px) / "+("(("+n.toLocaleString()+" - "+t.toLocaleString()+") / "+r+")")+") 100% repeat-x")},n.prototype._refreshTrackMarkers=function(){this._foundation.hasTrackMarker_=this.markers,this._foundation.setupTrackMarker()},n.decorators=[{type:t.Component,args:[{selector:"mdc-slider",exportAs:"mdcSlider",host:{role:"slider","aria-orientation":"horizontal","[attr.tabindex]":"tabIndex || 0",class:"mdc-slider","[class.mdc-slider--discrete]":"discrete","[class.mdc-slider--display-markers]":"markers && discrete","(blur)":"_onTouched()"},template:'\n <div class="mdc-slider__track-container">\n <div #track class="mdc-slider__track"></div>\n <div #markercontainer *ngIf="markers" class="mdc-slider__track-marker-container"></div>\n </div>\n <div #thumbcontainer class="mdc-slider__thumb-container">\n <div *ngIf="discrete" class="mdc-slider__pin">\n <span #pin class="mdc-slider__pin-value-marker"></span>\n </div>\n <svg #sliderThumb\n class="mdc-slider__thumb"\n width="21" height="21"\n focusable="false">\n <circle cx="10.5" cy="10.5" r="7.875"></circle>\n </svg>\n <div class="mdc-slider__focus-ring"></div>\n </div>',providers:[f],changeDetection:t.ChangeDetectionStrategy.OnPush,encapsulation:t.ViewEncapsulation.None}]}],n.ctorParameters=function(){return[{type:o.Platform},{type:t.NgZone},{type:t.ChangeDetectorRef},{type:t.ElementRef},{type:String,decorators:[{type:t.Attribute,args:["tabindex"]}]}]},n.propDecorators={tabIndex:[{type:t.Input}],discrete:[{type:t.Input}],markers:[{type:t.Input}],min:[{type:t.Input}],max:[{type:t.Input}],step:[{type:t.Input}],value:[{type:t.Input}],disabled:[{type:t.Input}],change:[{type:t.Output}],input:[{type:t.Output}],valueChange:[{type:t.Output}],thumbContainer:[{type:t.ViewChild,args:["thumbcontainer",{static:!1}]}],_sliderThumb:[{type:t.ViewChild,args:["sliderThumb",{static:!1}]}],track:[{type:t.ViewChild,args:["track",{static:!1}]}],pinValueMarker:[{type:t.ViewChild,args:["pin",{static:!1}]}],trackMarkerContainer:[{type:t.ViewChild,args:["markercontainer",{static:!1}]}]},n}(u.MDCComponent),y=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{imports:[n.CommonModule],exports:[m],declarations:[m]}]}],e}();e.MDC_SLIDER_CONTROL_VALUE_ACCESSOR=f,e.MdcSlider=m,e.MdcSliderChange=h,e.MdcSliderModule=y,Object.defineProperty(e,"__esModule",{value:!0})}));