UNPKG

@taiga-ui/kit

Version:
16 lines (14 loc) 10.4 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@taiga-ui/cdk"),require("@taiga-ui/core"),require("@taiga-ui/kit/constants"),require("@angular/forms"),require("@taiga-ui/kit/tokens"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@taiga-ui/kit/abstract",["exports","@angular/core","@taiga-ui/cdk","@taiga-ui/core","@taiga-ui/kit/constants","@angular/forms","@taiga-ui/kit/tokens","rxjs","rxjs/operators"],e):e(((t=t||self)["taiga-ui"]=t["taiga-ui"]||{},t["taiga-ui"].kit=t["taiga-ui"].kit||{},t["taiga-ui"].kit.abstract={}),t.ng.core,t.cdk,t.core$1,t["taiga-ui"].kit.constants,t.ng.forms,t["taiga-ui"].kit.tokens,t.rxjs,t.rxjs.operators)}(this,(function(t,e,o,i,n,r,u,s,a){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */var p=function(t,e){return(p=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])})(t,e)};function c(t,e){function o(){this.constructor=t}p(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}function l(t,e,o,i){var n,r=arguments.length,u=r<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(t,e,o,i);else for(var s=t.length-1;s>=0;s--)(n=t[s])&&(u=(r<3?n(u):r>3?n(e,o,u):n(e,o))||u);return r>3&&u&&Object.defineProperty(e,o,u),u}function f(t){return t>0}var m=function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e.min=0,e.max=1/0,e.minLabel="",e.maxLabel="",e.pluralize=null,e.segmentsPluralize=null,e.segments=0,e.steps=0,e.quantum=1,e.keySteps=null,e.size="l",e.mask=function(t,e){return{mask:i.tuiCreateNumberMask({allowNegative:e<0,allowDecimal:!Number.isInteger(t)}),pipe:i.tuiCreateAutoCorrectedNumberPipe(),guide:!1}},e}return c(r,t),Object.defineProperty(r.prototype,"segmented",{get:function(){return this.segments>0},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"hasPlaceholder",{get:function(){return"l"===this.size},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"inputMode",{get:function(){return Number.isInteger(this.quantum)?"numeric":"decimal"},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"length",{get:function(){return this.max-this.min},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"computedSteps",{get:function(){return this.steps||this.length/this.quantum},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"step",{get:function(){return this.length/this.computedSteps},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"hostMode",{get:function(){return this.modeDirective&&this.modeDirective.mode},enumerable:!0,configurable:!0}),r.prototype.onHovered=function(t){this.updateHovered(t)},r.prototype.isPluralized=function(t){return null!==t&&3===t.length},r.prototype.valueGuard=function(t){return this.quantum?o.clamp(o.round(Math.round(t/this.quantum)*this.quantum,n.TUI_FLOATING_PRECISION),this.min,this.max):o.clamp(t,this.min,this.max)},r.prototype.capInputValue=function(t,e){void 0===e&&(e=this.max);var o=Math.min(i.maskedNumberStringToNumber(t),e);return this.min<0&&o<this.min?this.min:isNaN(o)||o<this.min?null:o},l([e.Input(),o.tuiDefaultProp()],r.prototype,"min",void 0),l([e.Input(),o.tuiDefaultProp()],r.prototype,"max",void 0),l([e.Input(),o.tuiDefaultProp()],r.prototype,"minLabel",void 0),l([e.Input(),o.tuiDefaultProp()],r.prototype,"maxLabel",void 0),l([e.Input(),o.tuiDefaultProp()],r.prototype,"pluralize",void 0),l([e.Input(),o.tuiDefaultProp()],r.prototype,"segmentsPluralize",void 0),l([e.Input(),o.tuiDefaultProp()],r.prototype,"segments",void 0),l([e.Input(),o.tuiDefaultProp()],r.prototype,"steps",void 0),l([e.Input(),o.tuiDefaultProp(f,"Quantum must be positive")],r.prototype,"quantum",void 0),l([e.Input(),o.tuiDefaultProp()],r.prototype,"keySteps",void 0),l([e.Input(),e.HostBinding("attr.data-tui-host-size")],r.prototype,"size",void 0),l([e.HostBinding("class._segmented")],r.prototype,"segmented",null),l([e.HostBinding("attr.data-mode")],r.prototype,"hostMode",null),r=l([e.Directive()],r)}(o.AbstractTuiControl),d={s:8,m:16},h=function(t){function i(e,o,i,n){var r=t.call(this,e,o)||this;return r.documentRef=i,r.fromToTexts$=n,r.min=0,r.max=1/0,r.segments=0,r.steps=0,r.pluralize=null,r.size="m",r.keySteps=null,r.focusVisibleLeft=!1,r.focusVisibleRight=!1,r.pointerDown$=new s.Subject,r}var p,f;return c(i,t),Object.defineProperty(i.prototype,"segmented",{get:function(){return this.segments>0},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"discrete",{get:function(){return this.steps>0},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"length",{get:function(){return this.max-this.min},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"isLeftFocusable",{get:function(){return!this.disabled&&this.focusable&&100!==this.right},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"isRightFocusable",{get:function(){return!this.disabled&&this.focusable&&100!==this.left},enumerable:!0,configurable:!0}),i.prototype.ngOnInit=function(){var e=this;t.prototype.ngOnInit.call(this);var i,n=o.typedFromEvent(this.documentRef,"mousemove"),r=o.typedFromEvent(this.documentRef,"mouseup"),u=o.typedFromEvent(this.documentRef,"touchmove"),p=o.typedFromEvent(this.documentRef,"touchend");this.pointerDown$.pipe(a.map((function(t){var n=t.currentTarget.getBoundingClientRect(),r=t instanceof MouseEvent?t.clientX:t.touches[0].clientX,u=o.clamp(e.getFractionFromEvents(n,r),0,1),s=100*u-e.left,a=100*u-100+e.right;i=Math.abs(s)>Math.abs(a)||a>0||0===e.left&&100===e.right;var p=o.clamp(e.getCalibratedFractionFromEvents(n,r,i),0,1),c=e.getValueFromFraction(e.fractionGuard(p));return e.processValue(c,i),e.processFocus(i),n})),a.switchMap((function(t){return s.race([u,n]).pipe(a.map((function(o){return e.getCalibratedFractionFromEvents(t,o instanceof MouseEvent?o.clientX:o.touches[0].clientX,i)})),a.takeUntil(s.race([r,p])))})),a.map((function(t){return e.fractionGuard(t)}))).subscribe((function(t){e.processValue(e.getValueFromFraction(t),i)}))},i.prototype.ngOnDestroy=function(){t.prototype.ngOnDestroy.call(this),this.pointerDown$.complete()},i.prototype.onMouseDown=function(t){this.disabled||(t.preventDefault(),this.pointerDown$.next(t))},i.prototype.onTouchStart=function(t){this.disabled||(t.preventDefault(),this.pointerDown$.next(t))},i.prototype.isPluralized=function(t){return null!==t&&3===t.length},i.prototype.decrement=function(t){this.processStep(!1,t)},i.prototype.increment=function(t){this.processStep(!0,t)},i.prototype.getSegmentLabel=function(t){return o.round(this.getValueFromFraction(t/this.segments),2)},i.prototype.getSegmentPrefix=function(t,e){return 1!==this.segments?"":0===t?e[0]+" ":e[1]+" "},i.prototype.onActiveZone=function(t){this.updateFocused(t)},i.prototype.onLeftFocusVisible=function(t){this.focusVisibleLeft=t},i.prototype.onRightFocusVisible=function(t){this.focusVisibleRight=t},i.prototype.getFractionFromValue=function(t){var e=(t-this.min)/this.length;return null!==this.keySteps?this.fractionValueKeyStepConverter(t,!1):o.clamp(Number.isFinite(e)?e:1,0,1)},i.prototype.getValueFromFraction=function(t){return null!==this.keySteps?this.fractionValueKeyStepConverter(t,!0):o.round(this.fractionGuard(t)*this.length+this.min,n.TUI_FLOATING_PRECISION)},i.prototype.getCalibratedFractionFromEvents=function(t,e,o){return this.getFractionFromEvents(t,e)},i.prototype.processFocus=function(t){this.focusable&&this.dotRight&&this.dotLeft&&(t?o.setNativeFocused(this.dotRight.nativeElement):o.setNativeFocused(this.dotLeft.nativeElement))},i.prototype.fractionValueKeyStepConverter=function(t,e){for(var i=[[0,this.min]].concat(this.keySteps,[[100,this.max]]),r=0,u=100,s=this.min,a=this.max,p=1;p<i.length;p++)if(e&&i[p][0]/100>t||!e&&i[p][1]>t){r=i[p-1][0]||0,u=i[p][0],s=i[p-1][1],a=i[p][1];break}var c=u-r,l=a-s;return e?o.round((100*t-r)/c*l+s,n.TUI_FLOATING_PRECISION):o.clamp((t-s)/l*c+r,0,100)/100},i.prototype.fractionGuard=function(t){return this.discrete?o.clamp(o.quantize(t,1/this.steps),0,1):o.clamp(t,0,1)},i.prototype.getFractionFromEvents=function(t,e){var i=e-t.left-d[this.size]/2,r=t.width-d[this.size];return o.round(i/r,n.TUI_FLOATING_PRECISION)},i.ctorParameters=function(){return[{type:r.NgControl},{type:e.ChangeDetectorRef},{type:Document},{type:s.Observable,decorators:[{type:e.Inject,args:[u.TUI_FROM_TO_TEXTS]}]}]},l([e.Input(),o.tuiDefaultProp()],i.prototype,"min",void 0),l([e.Input(),o.tuiDefaultProp()],i.prototype,"max",void 0),l([e.Input(),o.tuiDefaultProp()],i.prototype,"segments",void 0),l([e.Input(),o.tuiDefaultProp()],i.prototype,"steps",void 0),l([e.Input(),o.tuiDefaultProp()],i.prototype,"pluralize",void 0),l([e.Input(),e.HostBinding("attr.data-tui-host-size"),o.tuiDefaultProp()],i.prototype,"size",void 0),l([e.Input(),o.tuiDefaultProp()],i.prototype,"keySteps",void 0),l([e.ViewChild("dotLeft")],i.prototype,"dotLeft",void 0),l([e.ViewChild("dotRight")],i.prototype,"dotRight",void 0),l([e.HostBinding("class._segmented")],i.prototype,"segmented",null),i=l([e.Directive(),(p=3,f=e.Inject(u.TUI_FROM_TO_TEXTS),function(t,e){f(t,e,p)})],i)}(o.AbstractTuiControl);t.AbstractTuiInputSlider=m,t.AbstractTuiSlider=h,t.DOT_WIDTH=d,t.SLIDER_KEYBOARD_STEP=.05,t.quantumAssertion=f,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=taiga-ui-kit-abstract.umd.min.js.map