| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- /**
- * @license
- * Copyright 2020 Google Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
- import { MDCFoundation } from '@material/base/foundation';
- import { MDCSliderAdapter } from './adapter';
- import { Thumb } from './types';
- /**
- * Foundation class for slider. Responsibilities include:
- * - Updating slider values (internal state and DOM updates) based on client
- * 'x' position.
- * - Updating DOM after slider property updates (e.g. min, max).
- */
- export declare class MDCSliderFoundation extends MDCFoundation<MDCSliderAdapter> {
- static SUPPORTS_POINTER_EVENTS: boolean;
- private initialStylesRemoved;
- private min;
- private max;
- private valueStart;
- private value;
- private rect;
- private isDisabled;
- private isDiscrete;
- private step;
- private minRange;
- private numDecimalPlaces;
- private hasTickMarks;
- private isRange;
- private thumb;
- private downEventClientX;
- private valueStartBeforeDownEvent;
- private valueBeforeDownEvent;
- private startThumbKnobWidth;
- private endThumbKnobWidth;
- private readonly animFrame;
- private mousedownOrTouchstartListener;
- private moveListener;
- private pointerdownListener;
- private pointerupListener;
- private thumbMouseenterListener;
- private thumbMouseleaveListener;
- private inputStartChangeListener;
- private inputEndChangeListener;
- private inputStartFocusListener;
- private inputEndFocusListener;
- private inputStartBlurListener;
- private inputEndBlurListener;
- private resizeListener;
- constructor(adapter?: Partial<MDCSliderAdapter>);
- static get defaultAdapter(): MDCSliderAdapter;
- init(): void;
- destroy(): void;
- setMin(value: number): void;
- setMax(value: number): void;
- getMin(): number;
- getMax(): number;
- /**
- * - For single point sliders, returns the thumb value.
- * - For range (two-thumb) sliders, returns the end thumb's value.
- */
- getValue(): number;
- /**
- * - For single point sliders, sets the thumb value.
- * - For range (two-thumb) sliders, sets the end thumb's value.
- */
- setValue(value: number): void;
- /**
- * Only applicable for range sliders.
- * @return The start thumb's value.
- */
- getValueStart(): number;
- /**
- * Only applicable for range sliders. Sets the start thumb's value.
- */
- setValueStart(valueStart: number): void;
- setStep(value: number): void;
- /**
- * Only applicable for range sliders. Sets the minimum difference between the
- * start and end values.
- */
- setMinRange(value: number): void;
- setIsDiscrete(value: boolean): void;
- getStep(): number;
- getMinRange(): number;
- setHasTickMarks(value: boolean): void;
- getDisabled(): boolean;
- /**
- * Sets disabled state, including updating styles and thumb tabindex.
- */
- setDisabled(disabled: boolean): void;
- /** @return Whether the slider is a range slider. */
- getIsRange(): boolean;
- /**
- * - Syncs slider boundingClientRect with the current DOM.
- * - Updates UI based on internal state.
- */
- layout({ skipUpdateUI }?: {
- skipUpdateUI?: boolean;
- }): void;
- /** Handles resize events on the window. */
- handleResize(): void;
- /**
- * Handles pointer down events on the slider root element.
- */
- handleDown(event: PointerEvent | MouseEvent | TouchEvent): void;
- /**
- * Handles pointer move events on the slider root element.
- */
- handleMove(event: PointerEvent | MouseEvent | TouchEvent): void;
- /**
- * Handles pointer up events on the slider root element.
- */
- handleUp(): void;
- /**
- * For range, discrete slider, shows the value indicator on both thumbs.
- */
- handleThumbMouseenter(): void;
- /**
- * For range, discrete slider, hides the value indicator on both thumbs.
- */
- handleThumbMouseleave(): void;
- handleMousedownOrTouchstart(event: MouseEvent | TouchEvent): void;
- handlePointerdown(event: PointerEvent): void;
- /**
- * Handles input `change` event by setting internal slider value to match
- * input's new value.
- */
- handleInputChange(thumb: Thumb): void;
- /** Shows activated state and value indicator on thumb(s). */
- handleInputFocus(thumb: Thumb): void;
- /** Removes activated state and value indicator from thumb(s). */
- handleInputBlur(thumb: Thumb): void;
- /**
- * Emits custom dragStart event, along with focusing the underlying input.
- */
- private handleDragStart;
- /**
- * @return The thumb to be moved based on initial down event.
- */
- private getThumbFromDownEvent;
- /**
- * @return The thumb to be moved based on move event (based on drag
- * direction from original down event). Only applicable if thumbs
- * were overlapping in the down event.
- */
- private getThumbFromMoveEvent;
- /**
- * Updates UI based on internal state.
- * @param thumb Thumb whose value is being updated. If undefined, UI is
- * updated for both thumbs based on current internal state.
- */
- private updateUI;
- /**
- * Updates thumb and input attributes based on current value.
- * @param thumb Thumb whose aria attributes to update.
- */
- private updateThumbAndInputAttributes;
- /**
- * Updates value indicator UI based on current value.
- * @param thumb Thumb whose value indicator to update. If undefined, all
- * thumbs' value indicators are updated.
- */
- private updateValueIndicatorUI;
- /**
- * Updates tick marks UI within slider, based on current min, max, and step.
- */
- private updateTickMarksUI;
- /** Maps clientX to a value on the slider scale. */
- private mapClientXOnSliderScale;
- /** Calculates the quantized value based on step value. */
- private quantize;
- /**
- * Updates slider value (internal state and UI) based on the given value.
- */
- private updateValue;
- /**
- * Clamps the given value for the given thumb based on slider properties:
- * - Restricts value within [min, max].
- * - If range slider, clamp start value <= end value - min range, and
- * end value >= start value + min range.
- */
- private clampValue;
- /**
- * Updates the active track and thumb style properties to reflect current
- * value.
- */
- private updateThumbAndTrackUI;
- /**
- * Shifts the value indicator to either side if it would otherwise stick
- * beyond the slider's length while keeping the caret above the knob.
- */
- private alignValueIndicator;
- /**
- * Removes initial inline styles if not already removed. `left:<...>%`
- * inline styles can be added to position the thumb correctly before JS
- * initialization. However, they need to be removed before the JS starts
- * positioning the thumb. This is because the JS uses
- * `transform:translateX(<...>)px` (for performance reasons) to position
- * the thumb (which is not possible for initial styles since we need the
- * bounding rect measurements).
- */
- private removeInitialStyles;
- /**
- * Resets track/thumb animation to prevent animation when adding
- * `transform` styles to thumb initially.
- */
- private resetTrackAndThumbAnimation;
- /**
- * Adds THUMB_TOP class to active thumb if thumb knobs overlap; otherwise
- * removes THUMB_TOP class from both thumbs.
- * @param thumb Thumb that is active (being moved).
- */
- private updateOverlappingThumbsUI;
- /**
- * Converts attribute value to a number, e.g. '100' => 100. Throws errors
- * for invalid values.
- * @param attributeValue Attribute value, e.g. 100.
- * @param attributeName Attribute name, e.g. `aria-valuemax`.
- */
- private convertAttributeValueToNumber;
- /** Checks that the given properties are valid slider values. */
- private validateProperties;
- private registerEventHandlers;
- private deregisterEventHandlers;
- private handlePointerup;
- }
|