| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 | var __defProp = Object.defineProperty;var __getOwnPropDesc = Object.getOwnPropertyDescriptor;var __getOwnPropNames = Object.getOwnPropertyNames;var __hasOwnProp = Object.prototype.hasOwnProperty;var __export = (target, all) => {  for (var name2 in all)    __defProp(target, name2, { get: all[name2], enumerable: true });};var __copyProps = (to, from, except, desc) => {  if (from && typeof from === "object" || typeof from === "function") {    for (let key of __getOwnPropNames(from))      if (!__hasOwnProp.call(to, key) && key !== except)        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });  }  return to;};var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);var stdin_exports = {};__export(stdin_exports, {  default: () => stdin_default});module.exports = __toCommonJS(stdin_exports);var import_vue = require("vue");var import_vue2 = require("vue");var import_utils = require("../utils");var import_use = require("@vant/use");var import_use_touch = require("../composables/use-touch");const [name, bem] = (0, import_utils.createNamespace)("slider");const sliderProps = {  min: (0, import_utils.makeNumericProp)(0),  max: (0, import_utils.makeNumericProp)(100),  step: (0, import_utils.makeNumericProp)(1),  range: Boolean,  reverse: Boolean,  disabled: Boolean,  readonly: Boolean,  vertical: Boolean,  barHeight: import_utils.numericProp,  buttonSize: import_utils.numericProp,  activeColor: String,  inactiveColor: String,  modelValue: {    type: [Number, Array],    default: 0  }};var stdin_default = (0, import_vue2.defineComponent)({  name,  props: sliderProps,  emits: ["change", "drag-end", "drag-start", "update:modelValue"],  setup(props, {    emit,    slots  }) {    let buttonIndex;    let current;    let startValue;    const root = (0, import_vue2.ref)();    const slider = (0, import_vue2.ref)();    const dragStatus = (0, import_vue2.ref)();    const touch = (0, import_use_touch.useTouch)();    const scope = (0, import_vue2.computed)(() => Number(props.max) - Number(props.min));    const wrapperStyle = (0, import_vue2.computed)(() => {      const crossAxis = props.vertical ? "width" : "height";      return {        background: props.inactiveColor,        [crossAxis]: (0, import_utils.addUnit)(props.barHeight)      };    });    const isRange = (val) => props.range && Array.isArray(val);    const calcMainAxis = () => {      const {        modelValue,        min      } = props;      if (isRange(modelValue)) {        return `${(modelValue[1] - modelValue[0]) * 100 / scope.value}%`;      }      return `${(modelValue - Number(min)) * 100 / scope.value}%`;    };    const calcOffset = () => {      const {        modelValue,        min      } = props;      if (isRange(modelValue)) {        return `${(modelValue[0] - Number(min)) * 100 / scope.value}%`;      }      return "0%";    };    const barStyle = (0, import_vue2.computed)(() => {      const mainAxis = props.vertical ? "height" : "width";      const style = {        [mainAxis]: calcMainAxis(),        background: props.activeColor      };      if (dragStatus.value) {        style.transition = "none";      }      const getPositionKey = () => {        if (props.vertical) {          return props.reverse ? "bottom" : "top";        }        return props.reverse ? "right" : "left";      };      style[getPositionKey()] = calcOffset();      return style;    });    const format = (value) => {      const min = +props.min;      const max = +props.max;      const step = +props.step;      value = (0, import_utils.clamp)(value, min, max);      const diff = Math.round((value - min) / step) * step;      return (0, import_utils.addNumber)(min, diff);    };    const isSameValue = (newValue, oldValue) => JSON.stringify(newValue) === JSON.stringify(oldValue);    const handleRangeValue = (value) => {      var _a, _b;      const left = (_a = value[0]) != null ? _a : Number(props.min);      const right = (_b = value[1]) != null ? _b : Number(props.max);      return left > right ? [right, left] : [left, right];    };    const updateValue = (value, end) => {      if (isRange(value)) {        value = handleRangeValue(value).map(format);      } else {        value = format(value);      }      if (!isSameValue(value, props.modelValue)) {        emit("update:modelValue", value);      }      if (end && !isSameValue(value, startValue)) {        emit("change", value);      }    };    const onClick = (event) => {      event.stopPropagation();      if (props.disabled || props.readonly) {        return;      }      const {        min,        reverse,        vertical,        modelValue      } = props;      const rect = (0, import_use.useRect)(root);      const getDelta = () => {        if (vertical) {          if (reverse) {            return rect.bottom - event.clientY;          }          return event.clientY - rect.top;        }        if (reverse) {          return rect.right - event.clientX;        }        return event.clientX - rect.left;      };      const total = vertical ? rect.height : rect.width;      const value = Number(min) + getDelta() / total * scope.value;      if (isRange(modelValue)) {        const [left, right] = modelValue;        const middle = (left + right) / 2;        if (value <= middle) {          updateValue([value, right], true);        } else {          updateValue([left, value], true);        }      } else {        updateValue(value, true);      }    };    const onTouchStart = (event) => {      if (props.disabled || props.readonly) {        return;      }      touch.start(event);      current = props.modelValue;      if (isRange(current)) {        startValue = current.map(format);      } else {        startValue = format(current);      }      dragStatus.value = "start";    };    const onTouchMove = (event) => {      if (props.disabled || props.readonly) {        return;      }      if (dragStatus.value === "start") {        emit("drag-start", event);      }      (0, import_utils.preventDefault)(event, true);      touch.move(event);      dragStatus.value = "dragging";      const rect = (0, import_use.useRect)(root);      const delta = props.vertical ? touch.deltaY.value : touch.deltaX.value;      const total = props.vertical ? rect.height : rect.width;      let diff = delta / total * scope.value;      if (props.reverse) {        diff = -diff;      }      if (isRange(startValue)) {        const index = props.reverse ? 1 - buttonIndex : buttonIndex;        current[index] = startValue[index] + diff;      } else {        current = startValue + diff;      }      updateValue(current);    };    const onTouchEnd = (event) => {      if (props.disabled || props.readonly) {        return;      }      if (dragStatus.value === "dragging") {        updateValue(current, true);        emit("drag-end", event);      }      dragStatus.value = "";    };    const getButtonClassName = (index) => {      if (typeof index === "number") {        const position = ["left", "right"];        return bem(`button-wrapper`, position[index]);      }      return bem("button-wrapper", props.reverse ? "left" : "right");    };    const renderButtonContent = (value, index) => {      if (typeof index === "number") {        const slot = slots[index === 0 ? "left-button" : "right-button"];        if (slot) {          return slot({            value          });        }      }      if (slots.button) {        return slots.button({          value        });      }      return (0, import_vue.createVNode)("div", {        "class": bem("button"),        "style": (0, import_utils.getSizeStyle)(props.buttonSize)      }, null);    };    const renderButton = (index) => {      const current2 = typeof index === "number" ? props.modelValue[index] : props.modelValue;      return (0, import_vue.createVNode)("div", {        "ref": slider,        "role": "slider",        "class": getButtonClassName(index),        "tabindex": props.disabled ? void 0 : 0,        "aria-valuemin": props.min,        "aria-valuenow": current2,        "aria-valuemax": props.max,        "aria-disabled": props.disabled || void 0,        "aria-readonly": props.readonly || void 0,        "aria-orientation": props.vertical ? "vertical" : "horizontal",        "onTouchstartPassive": (event) => {          if (typeof index === "number") {            buttonIndex = index;          }          onTouchStart(event);        },        "onTouchend": onTouchEnd,        "onTouchcancel": onTouchEnd,        "onClick": import_utils.stopPropagation      }, [renderButtonContent(current2, index)]);    };    updateValue(props.modelValue);    (0, import_use.useCustomFieldValue)(() => props.modelValue);    (0, import_use.useEventListener)("touchmove", onTouchMove, {      target: slider    });    return () => (0, import_vue.createVNode)("div", {      "ref": root,      "style": wrapperStyle.value,      "class": bem({        vertical: props.vertical,        disabled: props.disabled      }),      "onClick": onClick    }, [(0, import_vue.createVNode)("div", {      "class": bem("bar"),      "style": barStyle.value    }, [props.range ? [renderButton(0), renderButton(1)] : renderButton()])]);  }});
 |