tera-system-ui 0.1.4 → 0.1.6

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.
@@ -4,6 +4,12 @@ type SliderVariants = VariantProps<typeof styles>;
4
4
  export interface SliderProps extends SliderVariants {
5
5
  children?: any;
6
6
  class?: string;
7
+ min: number;
8
+ max: number;
9
+ step: number;
10
+ value: number;
11
+ showTicks: boolean;
12
+ onchange: (value: number) => void;
7
13
  }
8
14
  export type SliderContextProps = {};
9
15
  export {};
@@ -38,13 +38,13 @@
38
38
  slider.addEventListener('touchstart', (e) => {
39
39
  sliderHandle.setAttribute('data-state', 'dragging');
40
40
  onDrag(e)
41
- document.addEventListener('touchmove', onDrag);
41
+ document.addEventListener('touchmove', onDrag, { passive: false });
42
42
  document.addEventListener('touchend', () => {
43
43
  document.removeEventListener('touchmove', onDrag);
44
44
  toggleToolTip(false)
45
45
  sliderHandle.removeAttribute('data-state');
46
46
  }, {once: true});
47
- });
47
+ }, { passive: false });
48
48
 
49
49
  sliderHandle.addEventListener('pointerenter', (e) => {
50
50
  toggleToolTip(true)
@@ -72,16 +72,18 @@
72
72
 
73
73
  const calculateValue = (position) => {
74
74
  const sliderWidth = sliderRail.offsetWidth;
75
-
76
- // calculate step size in px
77
- const stepSize = sliderWidth / ((max - min) / step)
75
+ const totalSteps = (max - min) / step;
76
+ const stepSize = sliderWidth / totalSteps;
78
77
 
79
78
  // Clamp position within the slider width
80
79
  const clampedPosition = Math.max(0, Math.min(position, sliderWidth));
81
- // Calculate nearest step position
80
+ // Calculate steps with decimal precision
82
81
  const stepCount = Math.round(clampedPosition / stepSize);
83
82
 
84
- return min + stepCount
83
+ // Calculate the value with proper decimal precision
84
+ const value = min + (stepCount * step);
85
+ // Round to avoid floating-point precision errors
86
+ return Number(value.toFixed(10));
85
87
  };
86
88
 
87
89
  const onDrag = (event) => {
@@ -1 +1 @@
1
- export { cn, observeVisibility } from './utils';
1
+ export { cn, observeVisibility, styleToString } from './utils';
@@ -1 +1 @@
1
- export { cn, observeVisibility } from './utils';
1
+ export { cn, observeVisibility, styleToString } from './utils';
@@ -2,3 +2,4 @@ import { type ClassValue } from "clsx";
2
2
  export declare function cn(...inputs: ClassValue[]): string;
3
3
  export declare function consoleLog(...params: any[]): void;
4
4
  export declare function observeVisibility(element: HTMLElement, callback: (isVisible: boolean, entry?: any) => void): () => void;
5
+ export declare function styleToString(style: Record<string, any>): string;
@@ -22,3 +22,19 @@ export function observeVisibility(element, callback) {
22
22
  // Return a function to stop observing
23
23
  return () => observer.disconnect();
24
24
  }
25
+ export function styleToString(style) {
26
+ return Object.keys(style).reduce((acc, key) => {
27
+ if (style[key] === undefined || style[key] === null)
28
+ return acc;
29
+ // Convert camelCase to kebab-case
30
+ const cssKey = key.replace(/([A-Z])/g, '-$1').toLowerCase();
31
+ // Handle numbers by adding 'px' for certain properties
32
+ const cssValue = typeof style[key] === 'number' &&
33
+ !cssKey.includes('opacity') &&
34
+ !cssKey.includes('z-index') &&
35
+ !cssKey.includes('order')
36
+ ? `${style[key]}px`
37
+ : style[key];
38
+ return `${acc}${cssKey}:${cssValue};`;
39
+ }, '');
40
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tera-system-ui",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "npm run customPrepublish && npm run generate-index && vite build && npm run package && npm run postpublish",