123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894 |
- /*!
- * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
- * v1.0.0-beta.97
- */
- import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client/index.js';
- import { g as guid } from './guid.js';
- import { i as isPrimaryPointerButton, k as intersects } from './dom.js';
- import { d as decimalPlaces, c as clamp } from './math.js';
- import { c as connectLabel, d as disconnectLabel } from './label2.js';
- import { c as connectForm, d as disconnectForm, a as afterConnectDefaultValueSet, H as HiddenFormInputSlot } from './form.js';
- import { u as updateHostInteraction } from './interactive.js';
- import { i as isActivationKey } from './key.js';
- import { n as numberStringFormatter, c as connectLocalized, d as disconnectLocalized } from './locale.js';
- import { d as defineCustomElement$2 } from './graph.js';
- const CSS = {
- handleLabel: "handle__label",
- handleLabelMinValue: "handle__label--minValue",
- handleLabelValue: "handle__label--value",
- tickMin: "tick__label--min",
- tickMax: "tick__label--max"
- };
- const sliderCss = "@charset \"UTF-8\";@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}.scale--s{--calcite-slider-handle-size:10px;--calcite-slider-handle-extension-height:6.5px;--calcite-slider-container-font-size:var(--calcite-font-size--3)}.scale--s .handle__label,.scale--s .tick__label{line-height:.75rem}.scale--m{--calcite-slider-handle-size:14px;--calcite-slider-handle-extension-height:8px;--calcite-slider-container-font-size:var(--calcite-font-size--2)}.scale--m .handle__label,.scale--m .tick__label{line-height:1rem}.scale--l{--calcite-slider-handle-size:16px;--calcite-slider-handle-extension-height:10.5px;--calcite-slider-container-font-size:var(--calcite-font-size--1)}.scale--l .handle__label,.scale--l .tick__label{line-height:1rem}.handle__label,.tick__label{font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-2);font-size:var(--calcite-slider-container-font-size)}:host{display:block}.container{position:relative;display:block;overflow-wrap:normal;word-break:normal;padding-inline:calc(var(--calcite-slider-handle-size) * 0.5);padding-block:calc(var(--calcite-slider-handle-size) * 0.5);margin-block:calc(var(--calcite-slider-handle-size) * 0.5);margin-inline:0;--calcite-slider-full-handle-height:calc(\n var(--calcite-slider-handle-size) + var(--calcite-slider-handle-extension-height)\n )}:host([disabled]) .track__range,:host([disabled]) .tick--active{background-color:var(--calcite-ui-text-3)}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}.scale--s .thumb:not(.thumb--precise){--calcite-slider-thumb-y-offset:-6px}.scale--m .thumb:not(.thumb--precise){--calcite-slider-thumb-y-offset:-8px}.scale--l .thumb:not(.thumb--precise){--calcite-slider-thumb-y-offset:-9px}:host([precise]:not([has-histogram])) .container .thumb--value{--calcite-slider-thumb-y-offset:calc(var(--calcite-slider-full-handle-height) * -1)}.thumb-container{position:relative;max-inline-size:100%}.thumb{--calcite-slider-thumb-x-offset:calc(var(--calcite-slider-handle-size) * 0.5);position:absolute;margin:0px;display:flex;cursor:pointer;flex-direction:column;align-items:center;border-style:none;background-color:transparent;padding:0px;font-family:inherit;outline:2px solid transparent;outline-offset:2px;transform:translate(var(--calcite-slider-thumb-x-offset), var(--calcite-slider-thumb-y-offset))}.thumb .handle__label.static,.thumb .handle__label.transformed{position:absolute;inset-block:0px;opacity:0}.thumb .handle__label.hyphen::after{content:\"—\";display:inline-block;inline-size:1em}.thumb .handle__label.hyphen--wrap{display:flex}.thumb .handle{box-sizing:border-box;border-radius:9999px;background-color:var(--calcite-ui-foreground-1);outline-color:transparent;block-size:var(--calcite-slider-handle-size);inline-size:var(--calcite-slider-handle-size);box-shadow:0 0 0 2px var(--calcite-ui-text-3) inset;transition:border var(--calcite-internal-animation-timing-medium) ease, background-color var(--calcite-internal-animation-timing-medium) ease, box-shadow var(--calcite-animation-timing) ease}.thumb .handle-extension{inline-size:0.125rem;block-size:var(--calcite-slider-handle-extension-height);background-color:var(--calcite-ui-text-3)}.thumb:hover .handle{box-shadow:0 0 0 3px var(--calcite-ui-brand) inset}.thumb:hover .handle-extension{background-color:var(--calcite-ui-brand)}.thumb:focus .handle{outline:2px solid var(--calcite-ui-brand);outline-offset:2px}.thumb:focus .handle-extension{background-color:var(--calcite-ui-brand)}.thumb.thumb--minValue{transform:translate(calc(var(--calcite-slider-thumb-x-offset) * -1), var(--calcite-slider-thumb-y-offset))}.thumb.thumb--precise{--calcite-slider-thumb-y-offset:-2px}:host([label-handles]) .thumb{--calcite-slider-thumb-x-offset:50%}:host([label-handles]):host(:not([has-histogram])) .scale--s .thumb:not(.thumb--precise){--calcite-slider-thumb-y-offset:-23px}:host([label-handles]):host(:not([has-histogram])) .scale--m .thumb:not(.thumb--precise){--calcite-slider-thumb-y-offset:-30px}:host([label-handles]):host(:not([has-histogram])) .scale--l .thumb:not(.thumb--precise){--calcite-slider-thumb-y-offset:-32px}:host([has-histogram][label-handles]) .handle__label,:host([label-handles]:not([has-histogram])) .thumb--minValue.thumb--precise .handle__label{margin-block-start:0.5em}:host(:not([has-histogram]):not([precise])) .handle__label,:host([label-handles]:not([has-histogram])) .thumb--value .handle__label{margin-block-end:0.5em}:host([label-handles][precise]):host(:not([has-histogram])) .scale--s .thumb--value{--calcite-slider-thumb-y-offset:-33px}:host([label-handles][precise]):host(:not([has-histogram])) .scale--m .thumb--value{--calcite-slider-thumb-y-offset:-44px}:host([label-handles][precise]):host(:not([has-histogram])) .scale--l .thumb--value{--calcite-slider-thumb-y-offset:-49px}.thumb:focus .handle,.thumb--active .handle{background-color:var(--calcite-ui-brand);box-shadow:0 0 8px 0 rgba(0, 0, 0, 0.16)}.thumb:hover.thumb--precise:after,.thumb:focus.thumb--precise:after,.thumb--active.thumb--precise:after{background-color:var(--calcite-ui-brand)}.track{position:relative;block-size:0.125rem;border-radius:0px;background-color:var(--calcite-ui-border-2);transition:all var(--calcite-internal-animation-timing-medium) ease-in}.track__range{position:absolute;inset-block-start:0px;block-size:0.125rem;background-color:var(--calcite-ui-brand)}.container--range .track__range:hover{cursor:ew-resize}.container--range .track__range:after{position:absolute;inline-size:100%;content:\"\";inset-block-start:calc(var(--calcite-slider-full-handle-height) * 0.5 * -1);block-size:calc(var(--calcite-slider-handle-size) + var(--calcite-slider-handle-extension-height))}@media (forced-colors: active){.thumb{outline-width:0;outline-offset:0}.handle{outline:2px solid transparent;outline-offset:2px}.thumb:focus .handle,.thumb .handle-extension,.thumb:hover .handle-extension,.thumb:focus .handle-extension,.thumb:active .handle-extension{background-color:canvasText}.track{background-color:canvasText}.track__range{background-color:highlight}}.tick{position:absolute;block-size:0.25rem;inline-size:0.125rem;border-width:1px;border-style:solid;background-color:var(--calcite-ui-border-input);border-color:var(--calcite-ui-foreground-1);inset-block-start:-2px;pointer-events:none;margin-inline-start:calc(-1 * 0.125rem)}.tick--active{background-color:var(--calcite-ui-brand)}.tick__label{pointer-events:none;margin-block-start:0.875rem;display:flex;justify-content:center}.tick__label--min{transition:opacity var(--calcite-animation-timing)}.tick__label--max{transition:opacity var(--calcite-internal-animation-timing-fast)}:host([has-histogram][label-handles]) .tick__label--min,:host([has-histogram][label-handles]) .tick__label--max,:host([has-histogram][precise]) .tick__label--min,:host([has-histogram][precise]) .tick__label--max{font-weight:var(--calcite-font-weight-normal);color:var(--calcite-ui-text-3)}.graph{color:var(--calcite-ui-foreground-3);block-size:48px}:host([label-ticks][ticks]) .container{padding-block-end:calc(0.875rem + var(--calcite-slider-container-font-size))}:host([has-histogram]):host([precise][label-handles]) .container{padding-block-end:calc(var(--calcite-slider-full-handle-height) + 1em)}:host([has-histogram]):host([label-handles]:not([precise])) .container{padding-block-end:calc(var(--calcite-slider-handle-size) * 0.5 + 1em)}:host([has-histogram]):host([precise]:not([label-handles])) .container{padding-block-end:var(--calcite-slider-full-handle-height)}:host(:not([has-histogram])):host([precise]:not([label-handles])) .container{padding-block-start:var(--calcite-slider-full-handle-height)}:host(:not([has-histogram])):host([precise]:not([label-handles])) .container--range{padding-block-end:var(--calcite-slider-full-handle-height)}:host(:not([has-histogram])):host([label-handles]:not([precise])) .container{padding-block-start:calc(var(--calcite-slider-full-handle-height) + 4px)}:host(:not([has-histogram])):host([label-handles][precise]) .container{padding-block-start:calc(var(--calcite-slider-full-handle-height) + var(--calcite-slider-container-font-size) + 4px)}:host(:not([has-histogram])):host([label-handles][precise]) .container--range{padding-block-end:calc(var(--calcite-slider-full-handle-height) + var(--calcite-slider-container-font-size) + 4px)}::slotted(input[slot=hidden-form-input]){margin:0 !important;opacity:0 !important;outline:none !important;padding:0 !important;position:absolute !important;inset:0 !important;transform:none !important;-webkit-appearance:none !important;z-index:-1 !important}";
- function isRange(value) {
- return Array.isArray(value);
- }
- const Slider = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
- constructor() {
- super();
- this.__registerHost();
- this.__attachShadow();
- this.calciteSliderInput = createEvent(this, "calciteSliderInput", 6);
- this.calciteSliderChange = createEvent(this, "calciteSliderChange", 6);
- this.calciteSliderUpdate = createEvent(this, "calciteSliderUpdate", 6);
- //--------------------------------------------------------------------------
- //
- // Properties
- //
- //--------------------------------------------------------------------------
- /** When `true`, interaction is prevented and the component is displayed with lower opacity. */
- this.disabled = false;
- /**
- * When `true`, number values are displayed with a group separator corresponding to the language and country format.
- */
- this.groupSeparator = false;
- /** When `true`, indicates a histogram is present. */
- this.hasHistogram = false;
- /** When `true`, displays label handles with their numeric value. */
- this.labelHandles = false;
- /** When `true` and `ticks` is specified, displays label tick marks with their numeric value. */
- this.labelTicks = false;
- /** The component's maximum selectable value. */
- this.max = 100;
- /** The component's minimum selectable value. */
- this.min = 0;
- /**
- * When `true`, the slider will display values from high to low.
- *
- * Note that this value will be ignored if the slider has an associated histogram.
- */
- this.mirrored = false;
- /** When `true`, sets a finer point for handles. */
- this.precise = false;
- /**
- * When `true`, the component must have a value in order for the form to submit.
- */
- this.required = false;
- /** When `true`, enables snap selection in coordination with `step` via a mouse. */
- this.snap = false;
- /** Specifies the interval to move with the up, or down keys. */
- this.step = 1;
- /** The component's value. */
- this.value = 0;
- /**
- * Specifies the size of the component.
- */
- this.scale = "m";
- this.activeProp = "value";
- this.guid = `calcite-slider-${guid()}`;
- this.effectiveLocale = "";
- this.minMaxValueRange = null;
- this.minValueDragRange = null;
- this.maxValueDragRange = null;
- this.tickValues = [];
- this.dragUpdate = (event) => {
- event.preventDefault();
- if (this.dragProp) {
- const value = this.translate(event.clientX || event.pageX);
- if (isRange(this.value) && this.dragProp === "minMaxValue") {
- if (this.minValueDragRange && this.maxValueDragRange && this.minMaxValueRange) {
- const newMinValue = value - this.minValueDragRange;
- const newMaxValue = value + this.maxValueDragRange;
- if (newMaxValue <= this.max &&
- newMinValue >= this.min &&
- newMaxValue - newMinValue === this.minMaxValueRange) {
- this.setValue({
- minValue: this.clamp(newMinValue, "minValue"),
- maxValue: this.clamp(newMaxValue, "maxValue")
- });
- }
- }
- else {
- this.minValueDragRange = value - this.minValue;
- this.maxValueDragRange = this.maxValue - value;
- this.minMaxValueRange = this.maxValue - this.minValue;
- }
- }
- else {
- this.setValue({ [this.dragProp]: this.clamp(value, this.dragProp) });
- }
- }
- };
- this.pointerUpDragEnd = (event) => {
- if (!isPrimaryPointerButton(event)) {
- return;
- }
- this.dragEnd(event);
- };
- this.dragEnd = (event) => {
- this.removeDragListeners();
- this.focusActiveHandle(event.clientX);
- if (this.lastDragPropValue != this[this.dragProp]) {
- this.emitChange();
- }
- this.dragProp = null;
- this.lastDragPropValue = null;
- this.minValueDragRange = null;
- this.maxValueDragRange = null;
- this.minMaxValueRange = null;
- };
- /**
- * Set the reference of the track Element
- *
- * @internal
- * @param node
- */
- this.storeTrackRef = (node) => {
- this.trackEl = node;
- };
- /**
- * Returns a string representing the localized label value based if the groupSeparator prop is parsed.
- *
- * @param value
- */
- this.determineGroupSeparator = (value) => {
- if (typeof value === "number") {
- numberStringFormatter.numberFormatOptions = {
- locale: this.effectiveLocale,
- numberingSystem: this.numberingSystem,
- useGrouping: this.groupSeparator
- };
- return numberStringFormatter.localize(value.toString());
- }
- };
- }
- histogramWatcher(newHistogram) {
- this.hasHistogram = !!newHistogram;
- }
- valueHandler() {
- this.setMinMaxFromValue();
- }
- minMaxValueHandler() {
- this.setValueFromMinMax();
- }
- //--------------------------------------------------------------------------
- //
- // Lifecycle
- //
- //--------------------------------------------------------------------------
- connectedCallback() {
- connectLocalized(this);
- this.setMinMaxFromValue();
- this.setValueFromMinMax();
- connectLabel(this);
- connectForm(this);
- }
- disconnectedCallback() {
- disconnectLabel(this);
- disconnectForm(this);
- disconnectLocalized(this);
- this.removeDragListeners();
- }
- componentWillLoad() {
- this.tickValues = this.generateTickValues();
- if (!isRange(this.value)) {
- this.value = this.clamp(this.value);
- }
- afterConnectDefaultValueSet(this, this.value);
- if (this.snap && !isRange(this.value)) {
- this.value = this.getClosestStep(this.value);
- }
- if (this.histogram) {
- this.hasHistogram = true;
- }
- }
- componentDidRender() {
- if (this.labelHandles) {
- this.adjustHostObscuredHandleLabel("value");
- if (isRange(this.value)) {
- this.adjustHostObscuredHandleLabel("minValue");
- if (!(this.precise && !this.hasHistogram)) {
- this.hyphenateCollidingRangeHandleLabels();
- }
- }
- }
- this.hideObscuredBoundingTickLabels();
- updateHostInteraction(this);
- }
- render() {
- const id = this.el.id || this.guid;
- const maxProp = isRange(this.value) ? "maxValue" : "value";
- const value = isRange(this.value) ? this.maxValue : this.value;
- const displayedValue = this.determineGroupSeparator(value);
- const displayedMinValue = this.determineGroupSeparator(this.minValue);
- const min = this.minValue || this.min;
- const useMinValue = this.shouldUseMinValue();
- const minInterval = this.getUnitInterval(useMinValue ? this.minValue : min) * 100;
- const maxInterval = this.getUnitInterval(value) * 100;
- const mirror = this.shouldMirror();
- const leftThumbOffset = `${mirror ? 100 - minInterval : minInterval}%`;
- const rightThumbOffset = `${mirror ? maxInterval : 100 - maxInterval}%`;
- const valueIsRange = isRange(this.value);
- const handleLabelMinValueClasses = `${CSS.handleLabel} ${CSS.handleLabelMinValue}`;
- const handleLabelValueClasses = `${CSS.handleLabel} ${CSS.handleLabelValue}`;
- const handle = (h("div", { "aria-disabled": this.disabled, "aria-label": valueIsRange ? this.maxLabel : this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": value, class: {
- thumb: true,
- "thumb--value": true,
- "thumb--active": this.lastDragProp !== "minMaxValue" && this.dragProp === maxProp
- }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = maxProp), onPointerDown: (event) => this.pointerDownDragStart(event, maxProp), ref: (el) => (this.maxHandle = el), role: "slider", style: { right: rightThumbOffset }, tabIndex: 0 }, h("div", { class: "handle" })));
- const labeledHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": valueIsRange ? this.maxLabel : this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": value, class: {
- thumb: true,
- "thumb--value": true,
- "thumb--active": this.lastDragProp !== "minMaxValue" && this.dragProp === maxProp
- }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = maxProp), onPointerDown: (event) => this.pointerDownDragStart(event, maxProp), ref: (el) => (this.maxHandle = el), role: "slider", style: { right: rightThumbOffset }, tabIndex: 0 }, h("span", { "aria-hidden": "true", class: handleLabelValueClasses }, displayedValue), h("span", { "aria-hidden": "true", class: `${handleLabelValueClasses} static` }, displayedValue), h("span", { "aria-hidden": "true", class: `${handleLabelValueClasses} transformed` }, displayedValue), h("div", { class: "handle" })));
- const histogramLabeledHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": valueIsRange ? this.maxLabel : this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": value, class: {
- thumb: true,
- "thumb--value": true,
- "thumb--active": this.lastDragProp !== "minMaxValue" && this.dragProp === maxProp
- }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = maxProp), onPointerDown: (event) => this.pointerDownDragStart(event, maxProp), ref: (el) => (this.maxHandle = el), role: "slider", style: { right: rightThumbOffset }, tabIndex: 0 }, h("div", { class: "handle" }), h("span", { "aria-hidden": "true", class: handleLabelValueClasses }, displayedValue), h("span", { "aria-hidden": "true", class: `${handleLabelValueClasses} static` }, displayedValue), h("span", { "aria-hidden": "true", class: `${handleLabelValueClasses} transformed` }, displayedValue)));
- const preciseHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": valueIsRange ? this.maxLabel : this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": value, class: {
- thumb: true,
- "thumb--value": true,
- "thumb--active": this.lastDragProp !== "minMaxValue" && this.dragProp === maxProp,
- "thumb--precise": true
- }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = maxProp), onPointerDown: (event) => this.pointerDownDragStart(event, maxProp), ref: (el) => (this.maxHandle = el), role: "slider", style: { right: rightThumbOffset }, tabIndex: 0 }, h("div", { class: "handle" }), h("div", { class: "handle-extension" })));
- const histogramPreciseHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": valueIsRange ? this.maxLabel : this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": value, class: {
- thumb: true,
- "thumb--value": true,
- "thumb--active": this.lastDragProp !== "minMaxValue" && this.dragProp === maxProp,
- "thumb--precise": true
- }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = maxProp), onPointerDown: (event) => this.pointerDownDragStart(event, maxProp), ref: (el) => (this.maxHandle = el), role: "slider", style: { right: rightThumbOffset }, tabIndex: 0 }, h("div", { class: "handle-extension" }), h("div", { class: "handle" })));
- const labeledPreciseHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": valueIsRange ? this.maxLabel : this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": value, class: {
- thumb: true,
- "thumb--value": true,
- "thumb--active": this.lastDragProp !== "minMaxValue" && this.dragProp === maxProp,
- "thumb--precise": true
- }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = maxProp), onPointerDown: (event) => this.pointerDownDragStart(event, maxProp), ref: (el) => (this.maxHandle = el), role: "slider", style: { right: rightThumbOffset }, tabIndex: 0 }, h("span", { "aria-hidden": "true", class: handleLabelValueClasses }, displayedValue), h("span", { "aria-hidden": "true", class: `${handleLabelValueClasses} static` }, displayedValue), h("span", { "aria-hidden": "true", class: `${handleLabelValueClasses} transformed` }, displayedValue), h("div", { class: "handle" }), h("div", { class: "handle-extension" })));
- const histogramLabeledPreciseHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": valueIsRange ? this.maxLabel : this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": value, class: {
- thumb: true,
- "thumb--value": true,
- "thumb--active": this.lastDragProp !== "minMaxValue" && this.dragProp === maxProp,
- "thumb--precise": true
- }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = maxProp), onPointerDown: (event) => this.pointerDownDragStart(event, maxProp), ref: (el) => (this.maxHandle = el), role: "slider", style: { right: rightThumbOffset }, tabIndex: 0 }, h("div", { class: "handle-extension" }), h("div", { class: "handle" }), h("span", { "aria-hidden": "true", class: handleLabelValueClasses }, displayedValue), h("span", { "aria-hidden": "true", class: `${handleLabelValueClasses} static` }, displayedValue), h("span", { "aria-hidden": "true", class: `${handleLabelValueClasses} transformed` }, displayedValue)));
- const minHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": this.minValue, class: {
- thumb: true,
- "thumb--minValue": true,
- "thumb--active": this.dragProp === "minValue"
- }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = "minValue"), onPointerDown: (event) => this.pointerDownDragStart(event, "minValue"), ref: (el) => (this.minHandle = el), role: "slider", style: { left: leftThumbOffset }, tabIndex: 0 }, h("div", { class: "handle" })));
- const minLabeledHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": this.minValue, class: {
- thumb: true,
- "thumb--minValue": true,
- "thumb--active": this.dragProp === "minValue"
- }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = "minValue"), onPointerDown: (event) => this.pointerDownDragStart(event, "minValue"), ref: (el) => (this.minHandle = el), role: "slider", style: { left: leftThumbOffset }, tabIndex: 0 }, h("span", { "aria-hidden": "true", class: handleLabelMinValueClasses }, displayedMinValue), h("span", { "aria-hidden": "true", class: `${handleLabelMinValueClasses} static` }, displayedMinValue), h("span", { "aria-hidden": "true", class: `${handleLabelMinValueClasses} transformed` }, displayedMinValue), h("div", { class: "handle" })));
- const minHistogramLabeledHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": this.minValue, class: {
- thumb: true,
- "thumb--minValue": true,
- "thumb--active": this.dragProp === "minValue"
- }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = "minValue"), onPointerDown: (event) => this.pointerDownDragStart(event, "minValue"), ref: (el) => (this.minHandle = el), role: "slider", style: { left: leftThumbOffset }, tabIndex: 0 }, h("div", { class: "handle" }), h("span", { "aria-hidden": "true", class: handleLabelMinValueClasses }, displayedMinValue), h("span", { "aria-hidden": "true", class: `${handleLabelMinValueClasses} static` }, displayedMinValue), h("span", { "aria-hidden": "true", class: `${handleLabelMinValueClasses} transformed` }, displayedMinValue)));
- const minPreciseHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": this.minValue, class: {
- thumb: true,
- "thumb--minValue": true,
- "thumb--active": this.dragProp === "minValue",
- "thumb--precise": true
- }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = "minValue"), onPointerDown: (event) => this.pointerDownDragStart(event, "minValue"), ref: (el) => (this.minHandle = el), role: "slider", style: { left: leftThumbOffset }, tabIndex: 0 }, h("div", { class: "handle-extension" }), h("div", { class: "handle" })));
- const minLabeledPreciseHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": this.minValue, class: {
- thumb: true,
- "thumb--minValue": true,
- "thumb--active": this.dragProp === "minValue",
- "thumb--precise": true
- }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = "minValue"), onPointerDown: (event) => this.pointerDownDragStart(event, "minValue"), ref: (el) => (this.minHandle = el), role: "slider", style: { left: leftThumbOffset }, tabIndex: 0 }, h("div", { class: "handle-extension" }), h("div", { class: "handle" }), h("span", { "aria-hidden": "true", class: handleLabelMinValueClasses }, displayedMinValue), h("span", { "aria-hidden": "true", class: `${handleLabelMinValueClasses} static` }, displayedMinValue), h("span", { "aria-hidden": "true", class: `${handleLabelMinValueClasses} transformed` }, displayedMinValue)));
- return (h(Host, { id: id, onTouchStart: this.handleTouchStart }, h("div", { class: {
- ["container"]: true,
- ["container--range"]: valueIsRange,
- [`scale--${this.scale}`]: true
- } }, this.renderGraph(), h("div", { class: "track", ref: this.storeTrackRef }, h("div", { class: "track__range", onPointerDown: (event) => this.pointerDownDragStart(event, "minMaxValue"), style: {
- left: `${mirror ? 100 - maxInterval : minInterval}%`,
- right: `${mirror ? minInterval : 100 - maxInterval}%`
- } }), h("div", { class: "ticks" }, this.tickValues.map((tick) => {
- const tickOffset = `${this.getUnitInterval(tick) * 100}%`;
- let activeTicks = tick >= min && tick <= value;
- if (useMinValue) {
- activeTicks = tick >= this.minValue && tick <= this.maxValue;
- }
- return (h("span", { class: {
- tick: true,
- "tick--active": activeTicks
- }, style: {
- left: mirror ? "" : tickOffset,
- right: mirror ? tickOffset : ""
- } }, this.renderTickLabel(tick)));
- }))), h("div", { class: "thumb-container" }, !this.precise && !this.labelHandles && valueIsRange && minHandle, !this.hasHistogram &&
- !this.precise &&
- this.labelHandles &&
- valueIsRange &&
- minLabeledHandle, this.precise && !this.labelHandles && valueIsRange && minPreciseHandle, this.precise && this.labelHandles && valueIsRange && minLabeledPreciseHandle, this.hasHistogram &&
- !this.precise &&
- this.labelHandles &&
- valueIsRange &&
- minHistogramLabeledHandle, !this.precise && !this.labelHandles && handle, !this.hasHistogram && !this.precise && this.labelHandles && labeledHandle, !this.hasHistogram && this.precise && !this.labelHandles && preciseHandle, this.hasHistogram && this.precise && !this.labelHandles && histogramPreciseHandle, !this.hasHistogram && this.precise && this.labelHandles && labeledPreciseHandle, this.hasHistogram && !this.precise && this.labelHandles && histogramLabeledHandle, this.hasHistogram &&
- this.precise &&
- this.labelHandles &&
- histogramLabeledPreciseHandle, h(HiddenFormInputSlot, { component: this })))));
- }
- renderGraph() {
- return this.histogram ? (h("calcite-graph", { class: "graph", colorStops: this.histogramStops, data: this.histogram, highlightMax: isRange(this.value) ? this.maxValue : this.value, highlightMin: isRange(this.value) ? this.minValue : this.min, max: this.max, min: this.min })) : null;
- }
- renderTickLabel(tick) {
- const valueIsRange = isRange(this.value);
- const isMinTickLabel = tick === this.min;
- const isMaxTickLabel = tick === this.max;
- const displayedTickValue = this.determineGroupSeparator(tick);
- const tickLabel = (h("span", { class: {
- tick__label: true,
- [CSS.tickMin]: isMinTickLabel,
- [CSS.tickMax]: isMaxTickLabel
- } }, displayedTickValue));
- if (this.labelTicks && !this.hasHistogram && !valueIsRange) {
- return tickLabel;
- }
- if (this.labelTicks &&
- !this.hasHistogram &&
- valueIsRange &&
- !this.precise &&
- !this.labelHandles) {
- return tickLabel;
- }
- if (this.labelTicks &&
- !this.hasHistogram &&
- valueIsRange &&
- !this.precise &&
- this.labelHandles) {
- return tickLabel;
- }
- if (this.labelTicks &&
- !this.hasHistogram &&
- valueIsRange &&
- this.precise &&
- (isMinTickLabel || isMaxTickLabel)) {
- return tickLabel;
- }
- if (this.labelTicks && this.hasHistogram && !this.precise && !this.labelHandles) {
- return tickLabel;
- }
- if (this.labelTicks &&
- this.hasHistogram &&
- this.precise &&
- !this.labelHandles &&
- (isMinTickLabel || isMaxTickLabel)) {
- return tickLabel;
- }
- if (this.labelTicks &&
- this.hasHistogram &&
- !this.precise &&
- this.labelHandles &&
- (isMinTickLabel || isMaxTickLabel)) {
- return tickLabel;
- }
- if (this.labelTicks &&
- this.hasHistogram &&
- this.precise &&
- this.labelHandles &&
- (isMinTickLabel || isMaxTickLabel)) {
- return tickLabel;
- }
- return null;
- }
- //--------------------------------------------------------------------------
- //
- // Event Listeners
- //
- //--------------------------------------------------------------------------
- keyDownHandler(event) {
- const mirror = this.shouldMirror();
- const { activeProp, max, min, pageStep, step } = this;
- const value = this[activeProp];
- const { key } = event;
- if (isActivationKey(key)) {
- event.preventDefault();
- return;
- }
- let adjustment;
- if (key === "ArrowUp" || key === "ArrowRight") {
- const directionFactor = mirror && key === "ArrowRight" ? -1 : 1;
- adjustment = value + step * directionFactor;
- }
- else if (key === "ArrowDown" || key === "ArrowLeft") {
- const directionFactor = mirror && key === "ArrowLeft" ? -1 : 1;
- adjustment = value - step * directionFactor;
- }
- else if (key === "PageUp") {
- if (pageStep) {
- adjustment = value + pageStep;
- }
- }
- else if (key === "PageDown") {
- if (pageStep) {
- adjustment = value - pageStep;
- }
- }
- else if (key === "Home") {
- adjustment = min;
- }
- else if (key === "End") {
- adjustment = max;
- }
- if (isNaN(adjustment)) {
- return;
- }
- event.preventDefault();
- const fixedDecimalAdjustment = Number(adjustment.toFixed(decimalPlaces(step)));
- this.setValue({
- [activeProp]: this.clamp(fixedDecimalAdjustment, activeProp)
- });
- }
- pointerDownHandler(event) {
- if (!isPrimaryPointerButton(event)) {
- return;
- }
- const x = event.clientX || event.pageX;
- const position = this.translate(x);
- let prop = "value";
- if (isRange(this.value)) {
- const inRange = position >= this.minValue && position <= this.maxValue;
- if (inRange && this.lastDragProp === "minMaxValue") {
- prop = "minMaxValue";
- }
- else {
- const closerToMax = Math.abs(this.maxValue - position) < Math.abs(this.minValue - position);
- prop = closerToMax || position > this.maxValue ? "maxValue" : "minValue";
- }
- }
- this.lastDragPropValue = this[prop];
- this.dragStart(prop);
- const isThumbActive = this.el.shadowRoot.querySelector(".thumb:active");
- if (!isThumbActive) {
- this.setValue({ [prop]: this.clamp(position, prop) });
- }
- this.focusActiveHandle(x);
- }
- handleTouchStart(event) {
- // needed to prevent extra click at the end of a handle drag
- event.preventDefault();
- }
- //--------------------------------------------------------------------------
- //
- // Public Methods
- //
- //--------------------------------------------------------------------------
- /** Sets focus on the component. */
- async setFocus() {
- const handle = this.minHandle ? this.minHandle : this.maxHandle;
- handle === null || handle === void 0 ? void 0 : handle.focus();
- }
- //--------------------------------------------------------------------------
- //
- // Private Methods
- //
- //--------------------------------------------------------------------------
- setValueFromMinMax() {
- const { minValue, maxValue } = this;
- if (typeof minValue === "number" && typeof maxValue === "number") {
- this.value = [minValue, maxValue];
- }
- }
- setMinMaxFromValue() {
- const { value } = this;
- if (isRange(value)) {
- this.minValue = value[0];
- this.maxValue = value[1];
- }
- }
- onLabelClick() {
- this.setFocus();
- }
- shouldMirror() {
- return this.mirrored && !this.hasHistogram;
- }
- shouldUseMinValue() {
- if (!isRange(this.value)) {
- return false;
- }
- return ((this.hasHistogram && this.maxValue === 0) || (!this.hasHistogram && this.minValue === 0));
- }
- generateTickValues() {
- const ticks = [];
- let current = this.min;
- while (this.ticks && current < this.max + this.ticks) {
- ticks.push(Math.min(current, this.max));
- current = current + this.ticks;
- }
- return ticks;
- }
- pointerDownDragStart(event, prop) {
- if (!isPrimaryPointerButton(event)) {
- return;
- }
- this.dragStart(prop);
- }
- dragStart(prop) {
- this.dragProp = prop;
- this.lastDragProp = this.dragProp;
- this.activeProp = prop;
- document.addEventListener("pointermove", this.dragUpdate);
- document.addEventListener("pointerup", this.pointerUpDragEnd);
- document.addEventListener("pointercancel", this.dragEnd);
- }
- focusActiveHandle(valueX) {
- switch (this.dragProp) {
- case "minValue":
- this.minHandle.focus();
- break;
- case "maxValue":
- case "value":
- this.maxHandle.focus();
- break;
- case "minMaxValue":
- this.getClosestHandle(valueX).focus();
- break;
- }
- }
- emitInput() {
- this.calciteSliderInput.emit();
- this.calciteSliderUpdate.emit();
- }
- emitChange() {
- this.calciteSliderChange.emit();
- }
- removeDragListeners() {
- document.removeEventListener("pointermove", this.dragUpdate);
- document.removeEventListener("pointerup", this.pointerUpDragEnd);
- document.removeEventListener("pointercancel", this.dragEnd);
- }
- /**
- * Set prop value(s) if changed at the component level
- *
- * @param {object} values - a set of key/value pairs delineating what properties in the component to update
- */
- setValue(values) {
- let valueChanged;
- Object.keys(values).forEach((propName) => {
- const newValue = values[propName];
- if (!valueChanged) {
- const oldValue = this[propName];
- valueChanged = oldValue !== newValue;
- }
- this[propName] = newValue;
- });
- if (!valueChanged) {
- return;
- }
- const dragging = this.dragProp;
- if (!dragging) {
- this.emitChange();
- }
- this.emitInput();
- }
- /**
- * If number is outside range, constrain to min or max
- *
- * @param value
- * @param prop
- * @internal
- */
- clamp(value, prop) {
- value = clamp(value, this.min, this.max);
- // ensure that maxValue and minValue don't swap positions
- if (prop === "maxValue") {
- value = Math.max(value, this.minValue);
- }
- if (prop === "minValue") {
- value = Math.min(value, this.maxValue);
- }
- return value;
- }
- /**
- * Translate a pixel position to value along the range
- *
- * @param x
- * @internal
- */
- translate(x) {
- const range = this.max - this.min;
- const { left, width } = this.trackEl.getBoundingClientRect();
- const percent = (x - left) / width;
- const mirror = this.shouldMirror();
- const clampedValue = this.clamp(this.min + range * (mirror ? 1 - percent : percent));
- let value = Number(clampedValue.toFixed(decimalPlaces(this.step)));
- if (this.snap && this.step) {
- value = this.getClosestStep(value);
- }
- return value;
- }
- /**
- * Get closest allowed value along stepped values
- *
- * @param num
- * @internal
- */
- getClosestStep(num) {
- num = Number(this.clamp(num).toFixed(decimalPlaces(this.step)));
- if (this.step) {
- const step = Math.round(num / this.step) * this.step;
- num = Number(this.clamp(step).toFixed(decimalPlaces(this.step)));
- }
- return num;
- }
- getClosestHandle(valueX) {
- return this.getDistanceX(this.maxHandle, valueX) > this.getDistanceX(this.minHandle, valueX)
- ? this.minHandle
- : this.maxHandle;
- }
- getDistanceX(el, valueX) {
- return Math.abs(el.getBoundingClientRect().left - valueX);
- }
- getFontSizeForElement(element) {
- return Number(window.getComputedStyle(element).getPropertyValue("font-size").match(/\d+/)[0]);
- }
- /**
- * Get position of value along range as fractional value
- *
- * @param num
- * @return {number} number in the unit interval [0,1]
- * @internal
- */
- getUnitInterval(num) {
- num = this.clamp(num);
- const range = this.max - this.min;
- return (num - this.min) / range;
- }
- adjustHostObscuredHandleLabel(name) {
- const label = this.el.shadowRoot.querySelector(`.handle__label--${name}`);
- const labelStatic = this.el.shadowRoot.querySelector(`.handle__label--${name}.static`);
- const labelTransformed = this.el.shadowRoot.querySelector(`.handle__label--${name}.transformed`);
- const labelStaticBounds = labelStatic.getBoundingClientRect();
- const labelStaticOffset = this.getHostOffset(labelStaticBounds.left, labelStaticBounds.right);
- label.style.transform = `translateX(${labelStaticOffset}px)`;
- labelTransformed.style.transform = `translateX(${labelStaticOffset}px)`;
- }
- hyphenateCollidingRangeHandleLabels() {
- const { shadowRoot } = this.el;
- const mirror = this.shouldMirror();
- const leftModifier = mirror ? "value" : "minValue";
- const rightModifier = mirror ? "minValue" : "value";
- const leftValueLabel = shadowRoot.querySelector(`.handle__label--${leftModifier}`);
- const leftValueLabelStatic = shadowRoot.querySelector(`.handle__label--${leftModifier}.static`);
- const leftValueLabelTransformed = shadowRoot.querySelector(`.handle__label--${leftModifier}.transformed`);
- const leftValueLabelStaticHostOffset = this.getHostOffset(leftValueLabelStatic.getBoundingClientRect().left, leftValueLabelStatic.getBoundingClientRect().right);
- const rightValueLabel = shadowRoot.querySelector(`.handle__label--${rightModifier}`);
- const rightValueLabelStatic = shadowRoot.querySelector(`.handle__label--${rightModifier}.static`);
- const rightValueLabelTransformed = shadowRoot.querySelector(`.handle__label--${rightModifier}.transformed`);
- const rightValueLabelStaticHostOffset = this.getHostOffset(rightValueLabelStatic.getBoundingClientRect().left, rightValueLabelStatic.getBoundingClientRect().right);
- const labelFontSize = this.getFontSizeForElement(leftValueLabel);
- const labelTransformedOverlap = this.getRangeLabelOverlap(leftValueLabelTransformed, rightValueLabelTransformed);
- const hyphenLabel = leftValueLabel;
- const labelOffset = labelFontSize / 2;
- if (labelTransformedOverlap > 0) {
- hyphenLabel.classList.add("hyphen", "hyphen--wrap");
- if (rightValueLabelStaticHostOffset === 0 && leftValueLabelStaticHostOffset === 0) {
- // Neither handle overlaps the host boundary
- let leftValueLabelTranslate = labelTransformedOverlap / 2 - labelOffset;
- leftValueLabelTranslate =
- Math.sign(leftValueLabelTranslate) === -1
- ? Math.abs(leftValueLabelTranslate)
- : -leftValueLabelTranslate;
- const leftValueLabelTransformedHostOffset = this.getHostOffset(leftValueLabelTransformed.getBoundingClientRect().left +
- leftValueLabelTranslate -
- labelOffset, leftValueLabelTransformed.getBoundingClientRect().right +
- leftValueLabelTranslate -
- labelOffset);
- let rightValueLabelTranslate = labelTransformedOverlap / 2;
- const rightValueLabelTransformedHostOffset = this.getHostOffset(rightValueLabelTransformed.getBoundingClientRect().left + rightValueLabelTranslate, rightValueLabelTransformed.getBoundingClientRect().right + rightValueLabelTranslate);
- if (leftValueLabelTransformedHostOffset !== 0) {
- leftValueLabelTranslate += leftValueLabelTransformedHostOffset;
- rightValueLabelTranslate += leftValueLabelTransformedHostOffset;
- }
- if (rightValueLabelTransformedHostOffset !== 0) {
- leftValueLabelTranslate += rightValueLabelTransformedHostOffset;
- rightValueLabelTranslate += rightValueLabelTransformedHostOffset;
- }
- leftValueLabel.style.transform = `translateX(${leftValueLabelTranslate}px)`;
- leftValueLabelTransformed.style.transform = `translateX(${leftValueLabelTranslate - labelOffset}px)`;
- rightValueLabel.style.transform = `translateX(${rightValueLabelTranslate}px)`;
- rightValueLabelTransformed.style.transform = `translateX(${rightValueLabelTranslate}px)`;
- }
- else if (leftValueLabelStaticHostOffset > 0 || rightValueLabelStaticHostOffset > 0) {
- // labels overlap host boundary on the left side
- leftValueLabel.style.transform = `translateX(${leftValueLabelStaticHostOffset + labelOffset}px)`;
- rightValueLabel.style.transform = `translateX(${labelTransformedOverlap + rightValueLabelStaticHostOffset}px)`;
- rightValueLabelTransformed.style.transform = `translateX(${labelTransformedOverlap + rightValueLabelStaticHostOffset}px)`;
- }
- else if (leftValueLabelStaticHostOffset < 0 || rightValueLabelStaticHostOffset < 0) {
- // labels overlap host boundary on the right side
- let leftValueLabelTranslate = Math.abs(leftValueLabelStaticHostOffset) + labelTransformedOverlap - labelOffset;
- leftValueLabelTranslate =
- Math.sign(leftValueLabelTranslate) === -1
- ? Math.abs(leftValueLabelTranslate)
- : -leftValueLabelTranslate;
- leftValueLabel.style.transform = `translateX(${leftValueLabelTranslate}px)`;
- leftValueLabelTransformed.style.transform = `translateX(${leftValueLabelTranslate - labelOffset}px)`;
- }
- }
- else {
- hyphenLabel.classList.remove("hyphen", "hyphen--wrap");
- leftValueLabel.style.transform = `translateX(${leftValueLabelStaticHostOffset}px)`;
- leftValueLabelTransformed.style.transform = `translateX(${leftValueLabelStaticHostOffset}px)`;
- rightValueLabel.style.transform = `translateX(${rightValueLabelStaticHostOffset}px)`;
- rightValueLabelTransformed.style.transform = `translateX(${rightValueLabelStaticHostOffset}px)`;
- }
- }
- /**
- * Hides bounding tick labels that are obscured by either handle.
- */
- hideObscuredBoundingTickLabels() {
- const valueIsRange = isRange(this.value);
- if (!this.hasHistogram && !valueIsRange && !this.labelHandles && !this.precise) {
- return;
- }
- if (!this.hasHistogram && !valueIsRange && this.labelHandles && !this.precise) {
- return;
- }
- if (!this.hasHistogram && !valueIsRange && !this.labelHandles && this.precise) {
- return;
- }
- if (!this.hasHistogram && !valueIsRange && this.labelHandles && this.precise) {
- return;
- }
- if (!this.hasHistogram && valueIsRange && !this.precise) {
- return;
- }
- if (this.hasHistogram && !this.precise && !this.labelHandles) {
- return;
- }
- const minHandle = this.el.shadowRoot.querySelector(".thumb--minValue");
- const maxHandle = this.el.shadowRoot.querySelector(".thumb--value");
- const minTickLabel = this.el.shadowRoot.querySelector(".tick__label--min");
- const maxTickLabel = this.el.shadowRoot.querySelector(".tick__label--max");
- if (!minHandle && maxHandle && minTickLabel && maxTickLabel) {
- minTickLabel.style.opacity = this.isMinTickLabelObscured(minTickLabel, maxHandle) ? "0" : "1";
- maxTickLabel.style.opacity = this.isMaxTickLabelObscured(maxTickLabel, maxHandle) ? "0" : "1";
- }
- if (minHandle && maxHandle && minTickLabel && maxTickLabel) {
- minTickLabel.style.opacity =
- this.isMinTickLabelObscured(minTickLabel, minHandle) ||
- this.isMinTickLabelObscured(minTickLabel, maxHandle)
- ? "0"
- : "1";
- maxTickLabel.style.opacity =
- this.isMaxTickLabelObscured(maxTickLabel, minHandle) ||
- (this.isMaxTickLabelObscured(maxTickLabel, maxHandle) && this.hasHistogram)
- ? "0"
- : "1";
- }
- }
- /**
- * Returns an integer representing the number of pixels to offset on the left or right side based on desired position behavior.
- *
- * @param leftBounds
- * @param rightBounds
- * @internal
- */
- getHostOffset(leftBounds, rightBounds) {
- const hostBounds = this.el.getBoundingClientRect();
- const buffer = 7;
- if (leftBounds + buffer < hostBounds.left) {
- return hostBounds.left - leftBounds - buffer;
- }
- if (rightBounds - buffer > hostBounds.right) {
- return -(rightBounds - hostBounds.right) + buffer;
- }
- return 0;
- }
- /**
- * Returns an integer representing the number of pixels that the two given span elements are overlapping, taking into account
- * a space in between the two spans equal to the font-size set on them to account for the space needed to render a hyphen.
- *
- * @param leftLabel
- * @param rightLabel
- */
- getRangeLabelOverlap(leftLabel, rightLabel) {
- const leftLabelBounds = leftLabel.getBoundingClientRect();
- const rightLabelBounds = rightLabel.getBoundingClientRect();
- const leftLabelFontSize = this.getFontSizeForElement(leftLabel);
- const rangeLabelOverlap = leftLabelBounds.right + leftLabelFontSize - rightLabelBounds.left;
- return Math.max(rangeLabelOverlap, 0);
- }
- /**
- * Returns a boolean value representing if the minLabel span element is obscured (being overlapped) by the given handle div element.
- *
- * @param minLabel
- * @param handle
- */
- isMinTickLabelObscured(minLabel, handle) {
- const minLabelBounds = minLabel.getBoundingClientRect();
- const handleBounds = handle.getBoundingClientRect();
- return intersects(minLabelBounds, handleBounds);
- }
- /**
- * Returns a boolean value representing if the maxLabel span element is obscured (being overlapped) by the given handle div element.
- *
- * @param maxLabel
- * @param handle
- */
- isMaxTickLabelObscured(maxLabel, handle) {
- const maxLabelBounds = maxLabel.getBoundingClientRect();
- const handleBounds = handle.getBoundingClientRect();
- return intersects(maxLabelBounds, handleBounds);
- }
- get el() { return this; }
- static get watchers() { return {
- "histogram": ["histogramWatcher"],
- "value": ["valueHandler"],
- "minValue": ["minMaxValueHandler"],
- "maxValue": ["minMaxValueHandler"]
- }; }
- static get style() { return sliderCss; }
- }, [1, "calcite-slider", {
- "disabled": [516],
- "groupSeparator": [516, "group-separator"],
- "hasHistogram": [1540, "has-histogram"],
- "histogram": [16],
- "histogramStops": [16],
- "labelHandles": [516, "label-handles"],
- "labelTicks": [516, "label-ticks"],
- "max": [514],
- "maxLabel": [1, "max-label"],
- "maxValue": [1026, "max-value"],
- "min": [514],
- "minLabel": [1, "min-label"],
- "minValue": [1026, "min-value"],
- "mirrored": [516],
- "name": [513],
- "numberingSystem": [1, "numbering-system"],
- "pageStep": [514, "page-step"],
- "precise": [516],
- "required": [516],
- "snap": [516],
- "step": [514],
- "ticks": [514],
- "value": [1538],
- "scale": [513],
- "effectiveLocale": [32],
- "minMaxValueRange": [32],
- "minValueDragRange": [32],
- "maxValueDragRange": [32],
- "tickValues": [32],
- "setFocus": [64]
- }, [[0, "keydown", "keyDownHandler"], [1, "pointerdown", "pointerDownHandler"]]]);
- function defineCustomElement$1() {
- if (typeof customElements === "undefined") {
- return;
- }
- const components = ["calcite-slider", "calcite-graph"];
- components.forEach(tagName => { switch (tagName) {
- case "calcite-slider":
- if (!customElements.get(tagName)) {
- customElements.define(tagName, Slider);
- }
- break;
- case "calcite-graph":
- if (!customElements.get(tagName)) {
- defineCustomElement$2();
- }
- break;
- } });
- }
- defineCustomElement$1();
- const CalciteSlider = Slider;
- const defineCustomElement = defineCustomElement$1;
- export { CalciteSlider, defineCustomElement };
|