@synerise/ds-slider 1.1.12 → 1.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/Slider.d.ts +2 -2
  3. package/dist/Slider.js +15 -13
  4. package/dist/Slider.styles.d.ts +12 -12
  5. package/dist/Slider.styles.js +37 -67
  6. package/dist/Slider.types.d.ts +2 -2
  7. package/dist/Slider.types.js +1 -1
  8. package/dist/components/AllocationMarks.d.ts +2 -2
  9. package/dist/components/AllocationMarks.js +37 -42
  10. package/dist/components/AllocationMarks.styles.d.ts +5 -5
  11. package/dist/components/AllocationMarks.styles.js +16 -17
  12. package/dist/components/AllocationSlider.d.ts +2 -2
  13. package/dist/components/AllocationSlider.js +65 -88
  14. package/dist/components/DefaultSlider.d.ts +2 -2
  15. package/dist/components/DefaultSlider.js +58 -79
  16. package/dist/components/RangeSlider.d.ts +2 -2
  17. package/dist/components/RangeSlider.js +63 -88
  18. package/dist/components/SliderAbove.d.ts +1 -1
  19. package/dist/components/SliderAbove.js +15 -14
  20. package/dist/components/SliderDots.d.ts +2 -2
  21. package/dist/components/SliderDots.js +28 -31
  22. package/dist/components/SliderHandles.d.ts +2 -2
  23. package/dist/components/SliderHandles.js +36 -54
  24. package/dist/components/SliderLine.d.ts +2 -2
  25. package/dist/components/SliderLine.js +34 -46
  26. package/dist/components/SliderMarks.d.ts +2 -2
  27. package/dist/components/SliderMarks.js +48 -64
  28. package/dist/components/SliderSections.d.ts +2 -2
  29. package/dist/components/SliderSections.js +24 -28
  30. package/dist/context/SliderContext.d.ts +2 -2
  31. package/dist/context/SliderContext.js +20 -16
  32. package/dist/hooks/useColorMap.d.ts +1 -1
  33. package/dist/hooks/useColorMap.js +8 -5
  34. package/dist/hooks/useInvertedColors.d.ts +1 -1
  35. package/dist/hooks/useInvertedColors.js +13 -9
  36. package/dist/index.js +4 -2
  37. package/dist/modules.d.js +1 -1
  38. package/dist/modules.d.ts +0 -0
  39. package/dist/utils/Slider.interpolators.d.ts +1 -1
  40. package/dist/utils/Slider.interpolators.js +10 -16
  41. package/dist/utils/Slider.utils.d.ts +2 -2
  42. package/dist/utils/Slider.utils.js +36 -33
  43. package/dist/utils/allocation.utils.d.ts +2 -2
  44. package/dist/utils/allocation.utils.js +30 -63
  45. package/dist/utils/allocationHandlers.utils.d.ts +1 -1
  46. package/dist/utils/allocationHandlers.utils.js +17 -18
  47. package/package.json +8 -8
@@ -1,3 +1,3 @@
1
- import React from 'react';
2
- import { type SliderMarksProps } from '../Slider.types';
1
+ import { default as React } from 'react';
2
+ import { SliderMarksProps } from '../Slider.types';
3
3
  export declare const SliderMarks: ({ marks, handlesWithValue, }: SliderMarksProps) => React.JSX.Element;
@@ -1,37 +1,33 @@
1
- import React, { useCallback, useEffect, useRef, useState } from 'react';
2
- import { Text } from '@synerise/ds-typography';
3
- import { useResizeObserver } from '@synerise/ds-utils';
4
- import * as S from '../Slider.styles';
5
- import { useSliderContext } from '../context/SliderContext';
6
- import { getTranslateX, isMarksObjType } from '../utils/Slider.utils';
7
- var HANDLE_HALF_WIDTH = 22;
8
- export var SliderMarks = function SliderMarks(_ref) {
9
- var marks = _ref.marks,
10
- _ref$handlesWithValue = _ref.handlesWithValue,
11
- handlesWithValue = _ref$handlesWithValue === void 0 ? true : _ref$handlesWithValue;
12
- var _useSliderContext = useSliderContext(),
13
- rangerInstance = _useSliderContext.rangerInstance,
14
- rangerHandles = _useSliderContext.rangerHandles;
15
- var _useState = useState(),
16
- sliderWidth = _useState[0],
17
- setSliderWidth = _useState[1];
18
- var _useState2 = useState({}),
19
- markAreas = _useState2[0],
20
- setMarkAreas = _useState2[1];
21
- var markRefs = useRef({});
22
- var sliderElementRef = useRef();
23
- var marksData = Object.entries(marks);
24
- var handles = rangerInstance.handles().map(function (handle) {
25
- return handle.value;
26
- });
27
- var updateMeasurements = useCallback(function () {
28
- var element = sliderElementRef.current;
29
- if (element != null && element.clientWidth) {
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useState, useRef, useCallback, useEffect } from "react";
3
+ import { Text } from "@synerise/ds-typography";
4
+ import { useResizeObserver } from "@synerise/ds-utils";
5
+ import { SliderMarks as SliderMarks$1, SliderMark } from "../Slider.styles.js";
6
+ import { useSliderContext } from "../context/SliderContext.js";
7
+ import { getTranslateX, isMarksObjType } from "../utils/Slider.utils.js";
8
+ const HANDLE_HALF_WIDTH = 22;
9
+ const SliderMarks = ({
10
+ marks,
11
+ handlesWithValue = true
12
+ }) => {
13
+ const {
14
+ rangerInstance,
15
+ rangerHandles
16
+ } = useSliderContext();
17
+ const [sliderWidth, setSliderWidth] = useState();
18
+ const [markAreas, setMarkAreas] = useState({});
19
+ const markRefs = useRef({});
20
+ const sliderElementRef = useRef();
21
+ const marksData = Object.entries(marks);
22
+ const handles = rangerInstance.handles().map((handle) => handle.value);
23
+ const updateMeasurements = useCallback(() => {
24
+ const element = sliderElementRef.current;
25
+ if (element?.clientWidth) {
30
26
  setSliderWidth(element.clientWidth);
31
27
  }
32
- var areas = {};
33
- Object.keys(markRefs.current).forEach(function (index) {
34
- var markElement = markRefs.current[index];
28
+ const areas = {};
29
+ Object.keys(markRefs.current).forEach((index) => {
30
+ const markElement = markRefs.current[index];
35
31
  areas[index] = {
36
32
  left: markElement.offsetLeft + getTranslateX(markElement),
37
33
  width: markElement.clientWidth
@@ -39,47 +35,35 @@ export var SliderMarks = function SliderMarks(_ref) {
39
35
  });
40
36
  setMarkAreas(areas);
41
37
  }, []);
42
- useEffect(function () {
43
- var element = rangerInstance.options.getRangerElement();
38
+ useEffect(() => {
39
+ const element = rangerInstance.options.getRangerElement();
44
40
  if (element) {
45
41
  sliderElementRef.current = element;
46
42
  }
47
43
  updateMeasurements();
48
44
  }, [rangerInstance, updateMeasurements]);
49
45
  useResizeObserver(sliderElementRef, updateMeasurements);
50
- var isNearHandle = useCallback(function (index) {
51
- var markArea = markAreas[index];
46
+ const isNearHandle = useCallback((index) => {
47
+ const markArea = markAreas[index];
52
48
  if (!markArea || !sliderWidth) {
53
49
  return false;
54
50
  }
55
- return handlesWithValue && handles.some(function (handleValue, handleIndex) {
56
- var _rangerHandles$curren, _rangerHandles$curren2;
57
- var tooltipHalfWidth = (_rangerHandles$curren = rangerHandles.current) != null && _rangerHandles$curren[handleIndex] ? ((_rangerHandles$curren2 = rangerHandles.current) == null ? void 0 : _rangerHandles$curren2[handleIndex].clientWidth) / 2 : HANDLE_HALF_WIDTH;
58
- var handleLeft = rangerInstance.getPercentageForValue(handleValue);
59
- var handleLeftPx = handleLeft * sliderWidth / 100;
60
- var handleLowerThanMark = handleLeftPx < markArea.left;
51
+ return handlesWithValue && handles.some((handleValue, handleIndex) => {
52
+ const tooltipHalfWidth = rangerHandles.current?.[handleIndex] ? rangerHandles.current?.[handleIndex].clientWidth / 2 : HANDLE_HALF_WIDTH;
53
+ const handleLeft = rangerInstance.getPercentageForValue(handleValue);
54
+ const handleLeftPx = handleLeft * sliderWidth / 100;
55
+ const handleLowerThanMark = handleLeftPx < markArea.left;
61
56
  return handleLowerThanMark && handleLeftPx + tooltipHalfWidth > markArea.left || !handleLowerThanMark && handleLeftPx - tooltipHalfWidth < markArea.left + markArea.width;
62
57
  });
63
58
  }, [handles, handlesWithValue, markAreas, rangerHandles, rangerInstance, sliderWidth]);
64
- return /*#__PURE__*/React.createElement(S.SliderMarks, {
65
- "data-testid": "ds-slider-marks"
66
- }, marksData.map(function (_ref2, index) {
67
- var mark = _ref2[0],
68
- markLabel = _ref2[1];
69
- var markValue = parseFloat(mark);
70
- var left = rangerInstance.getPercentageForValue(markValue);
71
- var labelStyle = isMarksObjType(markLabel) ? markLabel.style : undefined;
72
- var labelContent = isMarksObjType(markLabel) ? markLabel.label : markLabel;
73
- return /*#__PURE__*/React.createElement(S.SliderMark, {
74
- ref: function ref(node) {
75
- return node && (markRefs.current[index] = node);
76
- },
77
- isNear: isNearHandle(index),
78
- $left: left,
79
- key: "slider-mark-" + index
80
- }, /*#__PURE__*/React.createElement(Text, {
81
- size: "medium",
82
- style: labelStyle
83
- }, labelContent));
84
- }));
85
- };
59
+ return /* @__PURE__ */ jsx(SliderMarks$1, { "data-testid": "ds-slider-marks", children: marksData.map(([mark, markLabel], index) => {
60
+ const markValue = parseFloat(mark);
61
+ const left = rangerInstance.getPercentageForValue(markValue);
62
+ const labelStyle = isMarksObjType(markLabel) ? markLabel.style : void 0;
63
+ const labelContent = isMarksObjType(markLabel) ? markLabel.label : markLabel;
64
+ return /* @__PURE__ */ jsx(SliderMark, { ref: (node) => node && (markRefs.current[index] = node), isNear: isNearHandle(index), $left: left, children: /* @__PURE__ */ jsx(Text, { size: "medium", style: labelStyle, children: labelContent }) }, `slider-mark-${index}`);
65
+ }) });
66
+ };
67
+ export {
68
+ SliderMarks
69
+ };
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
- import { type ColorMap } from '../Slider.types';
1
+ import { default as React } from 'react';
2
+ import { ColorMap } from '../Slider.types';
3
3
  type SliderSectionsProps = {
4
4
  type: 'range' | 'allocation' | 'default';
5
5
  tracksColorMap: ColorMap;
@@ -1,33 +1,29 @@
1
- import React from 'react';
2
- import { useTheme } from '@synerise/ds-core';
3
- import * as S from '../Slider.styles';
4
- import { useSliderContext } from '../context/SliderContext';
5
- import { getVisibleSectionsForType } from '../utils/Slider.utils';
6
- var normalizeReversed = function normalizeReversed(section, reverse) {
1
+ import { jsx, Fragment } from "react/jsx-runtime";
2
+ import { useTheme } from "@synerise/ds-core";
3
+ import { SliderSection } from "../Slider.styles.js";
4
+ import { useSliderContext } from "../context/SliderContext.js";
5
+ import { getVisibleSectionsForType } from "../utils/Slider.utils.js";
6
+ const normalizeReversed = (section, reverse) => {
7
7
  return reverse ? {
8
8
  width: -section.width,
9
9
  left: section.left + section.width
10
10
  } : section;
11
11
  };
12
- export var SliderSections = function SliderSections(_ref) {
13
- var tracksColorMap = _ref.tracksColorMap,
14
- _ref$type = _ref.type,
15
- type = _ref$type === void 0 ? 'default' : _ref$type,
16
- reverse = _ref.reverse;
17
- var theme = useTheme();
18
- var _useSliderContext = useSliderContext(),
19
- rangerInstance = _useSliderContext.rangerInstance;
20
- var steps = rangerInstance.getSteps();
21
- return /*#__PURE__*/React.createElement(React.Fragment, null, steps.filter(getVisibleSectionsForType(type, steps.length)).map(function (section, index) {
22
- var normalisedSection = normalizeReversed(section, reverse);
23
- return /*#__PURE__*/React.createElement(S.SliderSection, {
24
- key: "slider-section-" + index,
25
- "data-testid": "ds-slider-section",
26
- "data-index": index,
27
- $left: normalisedSection.left,
28
- $width: normalisedSection.width,
29
- "data-color": tracksColorMap[index],
30
- $color: theme.palette[tracksColorMap[index]]
31
- });
32
- }));
33
- };
12
+ const SliderSections = ({
13
+ tracksColorMap,
14
+ type = "default",
15
+ reverse
16
+ }) => {
17
+ const theme = useTheme();
18
+ const {
19
+ rangerInstance
20
+ } = useSliderContext();
21
+ const steps = rangerInstance.getSteps();
22
+ return /* @__PURE__ */ jsx(Fragment, { children: steps.filter(getVisibleSectionsForType(type, steps.length)).map((section, index) => {
23
+ const normalisedSection = normalizeReversed(section, reverse);
24
+ return /* @__PURE__ */ jsx(SliderSection, { "data-testid": `ds-slider-section`, "data-index": index, $left: normalisedSection.left, $width: normalisedSection.width, "data-color": tracksColorMap[index], $color: theme.palette[tracksColorMap[index]] }, `slider-section-${index}`);
25
+ }) });
26
+ };
27
+ export {
28
+ SliderSections
29
+ };
@@ -1,5 +1,5 @@
1
- import React, { type ReactNode, type RefObject } from 'react';
2
- import type { Ranger } from '@tanstack/react-ranger';
1
+ import { default as React, ReactNode, RefObject } from 'react';
2
+ import { Ranger } from '@tanstack/react-ranger';
3
3
  interface SliderContextType {
4
4
  rangerInstance: Ranger<HTMLDivElement>;
5
5
  rangerHandles: RefObject<Record<number, HTMLElement>>;
@@ -1,20 +1,24 @@
1
- import React, { createContext, useContext } from 'react';
2
- var SliderContext = /*#__PURE__*/createContext(undefined);
3
- export var SliderProvider = function SliderProvider(_ref) {
4
- var children = _ref.children,
5
- rangerInstance = _ref.rangerInstance,
6
- rangerHandles = _ref.rangerHandles;
7
- return /*#__PURE__*/React.createElement(SliderContext.Provider, {
8
- value: {
9
- rangerInstance: rangerInstance,
10
- rangerHandles: rangerHandles
11
- }
12
- }, children);
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext } from "react";
3
+ const SliderContext = createContext(void 0);
4
+ const SliderProvider = ({
5
+ children,
6
+ rangerInstance,
7
+ rangerHandles
8
+ }) => {
9
+ return /* @__PURE__ */ jsx(SliderContext.Provider, { value: {
10
+ rangerInstance,
11
+ rangerHandles
12
+ }, children });
13
13
  };
14
- export var useSliderContext = function useSliderContext() {
15
- var context = useContext(SliderContext);
14
+ const useSliderContext = () => {
15
+ const context = useContext(SliderContext);
16
16
  if (!context) {
17
- throw new Error('useSliderContext must be used within a SliderProvider');
17
+ throw new Error("useSliderContext must be used within a SliderProvider");
18
18
  }
19
19
  return context;
20
- };
20
+ };
21
+ export {
22
+ SliderProvider,
23
+ useSliderContext
24
+ };
@@ -1,2 +1,2 @@
1
- import { type ColorMap } from '../Slider.types';
1
+ import { ColorMap } from '../Slider.types';
2
2
  export declare const useColorMap: (count: number, type: "default" | "allocation" | "range", customMap?: ColorMap) => ColorMap;
@@ -1,7 +1,10 @@
1
- import { useMemo } from 'react';
2
- import { getDefaultColorMap } from '../utils/Slider.utils';
3
- export var useColorMap = function useColorMap(count, type, customMap) {
4
- return useMemo(function () {
1
+ import { useMemo } from "react";
2
+ import { getDefaultColorMap } from "../utils/Slider.utils.js";
3
+ const useColorMap = (count, type, customMap) => {
4
+ return useMemo(() => {
5
5
  return customMap || getDefaultColorMap(count, type);
6
6
  }, [customMap, count, type]);
7
- };
7
+ };
8
+ export {
9
+ useColorMap
10
+ };
@@ -1,4 +1,4 @@
1
- import { type ColorMap } from '../Slider.types';
1
+ import { ColorMap } from '../Slider.types';
2
2
  export declare const useInvertedColors: ({ inverted, colorMap, }: {
3
3
  inverted: boolean;
4
4
  colorMap: ColorMap;
@@ -1,13 +1,17 @@
1
- export var useInvertedColors = function useInvertedColors(_ref) {
2
- var inverted = _ref.inverted,
3
- colorMap = _ref.colorMap;
4
- var GREY_200 = 'grey-200';
5
- var lineColor = inverted ? colorMap[0] : GREY_200;
6
- var tracksColorMap = inverted ? {
1
+ const useInvertedColors = ({
2
+ inverted,
3
+ colorMap
4
+ }) => {
5
+ const GREY_200 = "grey-200";
6
+ const lineColor = inverted ? colorMap[0] : GREY_200;
7
+ const tracksColorMap = inverted ? {
7
8
  0: GREY_200
8
9
  } : colorMap;
9
10
  return {
10
- lineColor: lineColor,
11
- tracksColorMap: tracksColorMap
11
+ lineColor,
12
+ tracksColorMap
12
13
  };
13
- };
14
+ };
15
+ export {
16
+ useInvertedColors
17
+ };
package/dist/index.js CHANGED
@@ -1,2 +1,4 @@
1
- export { default } from './Slider';
2
- export * from './Slider.types';
1
+ import { default as default2 } from "./Slider.js";
2
+ export {
3
+ default2 as default
4
+ };
package/dist/modules.d.js CHANGED
@@ -1 +1 @@
1
- import '@testing-library/jest-dom';
1
+ import "@testing-library/jest-dom";
File without changes
@@ -1,4 +1,4 @@
1
- import type { RangerInterpolator } from '@tanstack/react-ranger';
1
+ import { RangerInterpolator } from '@tanstack/react-ranger';
2
2
  /**
3
3
  * Linear interpolator for reversed slider
4
4
  * Maps values from right to left (max on left, min on right)
@@ -1,23 +1,17 @@
1
- /**
2
- * Linear interpolator for reversed slider
3
- * Maps values from right to left (max on left, min on right)
4
- */
5
- export var reversedInterpolator = {
6
- getPercentageForValue: function getPercentageForValue(val, min, max) {
1
+ const reversedInterpolator = {
2
+ getPercentageForValue: (val, min, max) => {
7
3
  if (max === min) {
8
4
  return 0;
9
5
  }
10
- // Reverse the percentage calculation
11
6
  return (max - val) / (max - min) * 100;
12
7
  },
13
- getValueForClientX: function getValueForClientX(clientX, trackDims, min, max) {
14
- // Calculate position relative to track start
15
- var relativePosition = clientX - trackDims.left;
16
- // Get percentage from left
17
- var percentage = Math.min(Math.max(relativePosition / trackDims.width, 0), 1);
18
- // Reverse: percentage from left becomes percentage from right
19
- var reversedPercentage = 1 - percentage;
20
- // Convert back to value
8
+ getValueForClientX: (clientX, trackDims, min, max) => {
9
+ const relativePosition = clientX - trackDims.left;
10
+ const percentage = Math.min(Math.max(relativePosition / trackDims.width, 0), 1);
11
+ const reversedPercentage = 1 - percentage;
21
12
  return min + reversedPercentage * (max - min);
22
13
  }
23
- };
14
+ };
15
+ export {
16
+ reversedInterpolator
17
+ };
@@ -1,5 +1,5 @@
1
- import { type ReactNode } from 'react';
2
- import { type ColorMap, type MarkObj } from '../Slider.types';
1
+ import { ReactNode } from 'react';
2
+ import { ColorMap, MarkObj } from '../Slider.types';
3
3
  export declare const getDefaultTooltipPopupContainer: () => HTMLElement;
4
4
  export declare const couldBeInverted: (value: number | readonly number[], inverted?: boolean) => boolean;
5
5
  export declare const getDefaultColorMap: (handleCount: number, type: "default" | "allocation" | "range") => ColorMap;
@@ -1,29 +1,25 @@
1
- import { defaultColorsOrder } from '@synerise/ds-core';
2
- export var getDefaultTooltipPopupContainer = function getDefaultTooltipPopupContainer() {
3
- return document.querySelector(".ant-slider");
4
- };
5
- export var couldBeInverted = function couldBeInverted(value, inverted) {
6
- return Boolean(inverted && (typeof value === 'number' || value.length < 3));
7
- };
8
- export var getDefaultColorMap = function getDefaultColorMap(handleCount, type) {
9
- var colorMap = {};
10
- if (type !== 'allocation' && handleCount <= 2) {
11
- colorMap['0'] = 'green-600';
1
+ import { defaultColorsOrder } from "@synerise/ds-core";
2
+ const getDefaultTooltipPopupContainer = () => document.querySelector(`.ant-slider`);
3
+ const couldBeInverted = (value, inverted) => Boolean(inverted && (typeof value === "number" || value.length < 3));
4
+ const getDefaultColorMap = (handleCount, type) => {
5
+ const colorMap = {};
6
+ if (type !== "allocation" && handleCount <= 2) {
7
+ colorMap["0"] = "green-600";
12
8
  } else {
13
- defaultColorsOrder.forEach(function (item, index) {
9
+ defaultColorsOrder.forEach((item, index) => {
14
10
  colorMap[index] = item;
15
11
  });
16
12
  }
17
13
  return colorMap;
18
14
  };
19
- export var isMarksObjType = function isMarksObjType(item) {
20
- return Boolean(item && typeof item === 'object' && 'label' in item);
15
+ const isMarksObjType = (item) => {
16
+ return Boolean(item && typeof item === "object" && "label" in item);
21
17
  };
22
- export var getClosestIndex = function getClosestIndex(values, targetValue) {
23
- var closestIndex = 0;
24
- var minDistance = Math.abs(values[0] - targetValue);
25
- for (var i = 1; i < values.length; i++) {
26
- var distance = Math.abs(values[i] - targetValue);
18
+ const getClosestIndex = (values, targetValue) => {
19
+ let closestIndex = 0;
20
+ let minDistance = Math.abs(values[0] - targetValue);
21
+ for (let i = 1; i < values.length; i++) {
22
+ const distance = Math.abs(values[i] - targetValue);
27
23
  if (distance < minDistance) {
28
24
  minDistance = distance;
29
25
  closestIndex = i;
@@ -31,19 +27,26 @@ export var getClosestIndex = function getClosestIndex(values, targetValue) {
31
27
  }
32
28
  return closestIndex;
33
29
  };
34
- export var getVisibleSectionsForType = function getVisibleSectionsForType(type, total) {
35
- return function (_, index) {
36
- if (type === 'range') {
37
- return index !== 0 && index !== total - 1;
38
- }
39
- if (type === 'default') {
40
- return index !== total - 1;
41
- }
42
- return true;
43
- };
30
+ const getVisibleSectionsForType = (type, total) => (_, index) => {
31
+ if (type === "range") {
32
+ return index !== 0 && index !== total - 1;
33
+ }
34
+ if (type === "default") {
35
+ return index !== total - 1;
36
+ }
37
+ return true;
44
38
  };
45
- export var getTranslateX = function getTranslateX(element) {
46
- var style = window.getComputedStyle(element);
47
- var matrix = new WebKitCSSMatrix(style.transform);
39
+ const getTranslateX = (element) => {
40
+ const style = window.getComputedStyle(element);
41
+ const matrix = new WebKitCSSMatrix(style.transform);
48
42
  return matrix.m41;
49
- };
43
+ };
44
+ export {
45
+ couldBeInverted,
46
+ getClosestIndex,
47
+ getDefaultColorMap,
48
+ getDefaultTooltipPopupContainer,
49
+ getTranslateX,
50
+ getVisibleSectionsForType,
51
+ isMarksObjType
52
+ };
@@ -1,5 +1,5 @@
1
- import { type ReactNode } from 'react';
2
- import { type AllocationVariant } from '../Slider.types';
1
+ import { ReactNode } from 'react';
2
+ import { AllocationVariant } from '../Slider.types';
3
3
  export declare const countControlGroupAllocation: (userAllocation: number[]) => number;
4
4
  export declare const countAllocation: (variants?: AllocationVariant[] | undefined, controlGroup?: boolean) => number[];
5
5
  export declare const mergeAllocationWithVariants: (variants: Partial<AllocationVariant>[] | undefined, allocation: number[]) => AllocationVariant[];
@@ -1,74 +1,41 @@
1
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- export var countControlGroupAllocation = function countControlGroupAllocation(userAllocation) {
3
- return 100 - userAllocation.reduce(function (prev, curr) {
4
- return prev + curr;
5
- }, 0);
6
- };
7
- export var countAllocation = function countAllocation(variants, controlGroup) {
8
- if (variants === void 0) {
9
- variants = [];
10
- }
11
- if (controlGroup === void 0) {
12
- controlGroup = false;
13
- }
1
+ const countControlGroupAllocation = (userAllocation) => 100 - userAllocation.reduce((prev, curr) => prev + curr, 0);
2
+ const countAllocation = (variants = [], controlGroup = false) => {
14
3
  if (variants.length === 0) {
15
4
  return [];
16
5
  }
17
- var allocation = [].concat(variants.map(function (v) {
18
- return v.percentage;
19
- }));
6
+ const allocation = [...variants.map((v) => v.percentage)];
20
7
  if (controlGroup) {
21
8
  allocation.push(countControlGroupAllocation(allocation));
22
9
  }
23
10
  return allocation;
24
11
  };
25
- export var mergeAllocationWithVariants = function mergeAllocationWithVariants(variants, allocation) {
26
- if (variants === void 0) {
27
- variants = [];
28
- }
29
- return variants.map(function (v, index) {
30
- return _extends({}, v, {
31
- percentage: allocation[index]
32
- });
33
- });
34
- };
35
- export var mapUserAllocationToHandles = function mapUserAllocationToHandles(userAllocation) {
36
- return userAllocation.reduce(function (result, item, index) {
37
- return [].concat(result, [parseInt(item, 10) + parseInt(result[index - 1] || 0, 10)]);
38
- }, []).slice(0, userAllocation.length - 1);
39
- };
40
- export var mapUserAllocationToMarks = function mapUserAllocationToMarks(userAllocation, markRenderer, variants) {
41
- if (variants === void 0) {
42
- variants = [];
43
- }
44
- return userAllocation.map(function (a, i) {
45
- return {
46
- value: a + "%",
47
- view: a / 2 + (i ? userAllocation.slice(0, i).reduce(function (result, item) {
48
- return result + item;
49
- }, 0) : 0)
50
- };
51
- }).reduce(function (result, item, index) {
52
- var _extends2;
53
- return _extends({}, result, (_extends2 = {}, _extends2[item.view] = markRenderer(item.value, index, variants), _extends2));
54
- }, {});
55
- };
56
- export var mapSliderValueToVariants = function mapSliderValueToVariants(value, variants) {
57
- if (variants === void 0) {
58
- variants = [];
59
- }
60
- var allocation = value.reduce(function (prev, curr) {
61
- return [].concat(prev, [curr - prev.reduce(function (previous, current) {
62
- return previous + current;
63
- }, 0)]);
64
- }, []);
12
+ const mergeAllocationWithVariants = (variants = [], allocation) => variants.map((v, index) => ({
13
+ ...v,
14
+ percentage: allocation[index]
15
+ }));
16
+ const mapUserAllocationToHandles = (userAllocation) => userAllocation.reduce((result, item, index) => [...result, parseInt(item, 10) + parseInt(result[index - 1] || 0, 10)], []).slice(0, userAllocation.length - 1);
17
+ const mapUserAllocationToMarks = (userAllocation, markRenderer, variants = []) => userAllocation.map((a, i) => ({
18
+ value: `${a}%`,
19
+ view: a / 2 + (i ? userAllocation.slice(0, i).reduce((result, item) => result + item, 0) : 0)
20
+ })).reduce((result, item, index) => ({
21
+ ...result,
22
+ [item.view]: markRenderer(item.value, index, variants)
23
+ }), {});
24
+ const mapSliderValueToVariants = (value, variants = []) => {
25
+ const allocation = value.reduce((prev, curr) => [...prev, curr - prev.reduce((previous, current) => previous + current, 0)], []);
65
26
  allocation.push(countControlGroupAllocation(allocation));
66
27
  return mergeAllocationWithVariants(variants, allocation);
67
28
  };
68
- var DEFAULT_MIN_PERCENTAGE = 1;
69
- export var checkIsPercentageInBoundaries = function checkIsPercentageInBoundaries(variants) {
70
- return !variants.some(function (variant) {
71
- var _variant$minPercentag;
72
- return variant.percentage < ((_variant$minPercentag = variant.minPercentage) != null ? _variant$minPercentag : DEFAULT_MIN_PERCENTAGE);
73
- });
74
- };
29
+ const DEFAULT_MIN_PERCENTAGE = 1;
30
+ const checkIsPercentageInBoundaries = (variants) => {
31
+ return !variants.some((variant) => variant.percentage < (variant.minPercentage ?? DEFAULT_MIN_PERCENTAGE));
32
+ };
33
+ export {
34
+ checkIsPercentageInBoundaries,
35
+ countAllocation,
36
+ countControlGroupAllocation,
37
+ mapSliderValueToVariants,
38
+ mapUserAllocationToHandles,
39
+ mapUserAllocationToMarks,
40
+ mergeAllocationWithVariants
41
+ };
@@ -1,4 +1,4 @@
1
- import { type AllocationVariant, type HandlerConfig } from '../Slider.types';
1
+ import { AllocationVariant, HandlerConfig } from '../Slider.types';
2
2
  export declare const calculateHandlersPercentagePosition: (variants?: AllocationVariant[]) => number[];
3
3
  export declare const getBlockedHandlersKeys: (handlers?: HandlerConfig) => number[];
4
4
  export declare const checkIsBlockedHandlersConfigEnabled: (handlers?: HandlerConfig) => boolean;