@zuzjs/ui 0.9.5 → 0.9.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.
Files changed (55) hide show
  1. package/dist/cjs/comps/Chart/index.d.ts +8 -0
  2. package/dist/cjs/comps/Chart/index.js +66 -0
  3. package/dist/cjs/comps/Chart/types.d.ts +10 -0
  4. package/dist/cjs/comps/Chart/types.js +4 -0
  5. package/dist/cjs/comps/Form/index.js +7 -3
  6. package/dist/cjs/comps/Password/index.d.ts +1 -1
  7. package/dist/cjs/comps/Select/index.d.ts +1 -0
  8. package/dist/cjs/comps/Select/index.js +10 -5
  9. package/dist/cjs/comps/Select/types.d.ts +4 -0
  10. package/dist/cjs/comps/TextWheel/index.d.ts +2 -0
  11. package/dist/cjs/comps/TextWheel/index.js +24 -12
  12. package/dist/cjs/comps/TextWheel/types.d.ts +2 -0
  13. package/dist/cjs/comps/index.d.ts +2 -0
  14. package/dist/cjs/comps/index.js +2 -0
  15. package/dist/cjs/hooks/index.d.ts +2 -0
  16. package/dist/cjs/hooks/index.js +2 -0
  17. package/dist/cjs/hooks/useLineChart.d.ts +25 -0
  18. package/dist/cjs/hooks/useLineChart.js +86 -0
  19. package/dist/cjs/hooks/usePosition.d.ts +12 -0
  20. package/dist/cjs/hooks/usePosition.js +191 -0
  21. package/dist/cjs/hooks/useResizeObserver.d.ts +1 -1
  22. package/dist/cjs/hooks/useResizeObserver.js +5 -4
  23. package/dist/cjs/hooks/useScrollbar.js +115 -70
  24. package/dist/cjs/types/enums.d.ts +2 -0
  25. package/dist/cjs/types/enums.js +2 -0
  26. package/dist/cjs/types/index.d.ts +2 -1
  27. package/dist/esm/comps/Chart/index.d.ts +8 -0
  28. package/dist/esm/comps/Chart/index.js +66 -0
  29. package/dist/esm/comps/Chart/types.d.ts +10 -0
  30. package/dist/esm/comps/Chart/types.js +4 -0
  31. package/dist/esm/comps/Form/index.js +7 -3
  32. package/dist/esm/comps/Password/index.d.ts +1 -1
  33. package/dist/esm/comps/Select/index.d.ts +1 -0
  34. package/dist/esm/comps/Select/index.js +10 -5
  35. package/dist/esm/comps/Select/types.d.ts +4 -0
  36. package/dist/esm/comps/TextWheel/index.d.ts +2 -0
  37. package/dist/esm/comps/TextWheel/index.js +24 -12
  38. package/dist/esm/comps/TextWheel/types.d.ts +2 -0
  39. package/dist/esm/comps/index.d.ts +2 -0
  40. package/dist/esm/comps/index.js +2 -0
  41. package/dist/esm/hooks/index.d.ts +2 -0
  42. package/dist/esm/hooks/index.js +2 -0
  43. package/dist/esm/hooks/useLineChart.d.ts +25 -0
  44. package/dist/esm/hooks/useLineChart.js +86 -0
  45. package/dist/esm/hooks/usePosition.d.ts +12 -0
  46. package/dist/esm/hooks/usePosition.js +191 -0
  47. package/dist/esm/hooks/useResizeObserver.d.ts +1 -1
  48. package/dist/esm/hooks/useResizeObserver.js +5 -4
  49. package/dist/esm/hooks/useScrollbar.js +115 -70
  50. package/dist/esm/types/enums.d.ts +2 -0
  51. package/dist/esm/types/enums.js +2 -0
  52. package/dist/esm/types/index.d.ts +2 -1
  53. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  54. package/dist/tsconfig.tsbuildinfo +1 -1
  55. package/package.json +2 -2
@@ -13,60 +13,78 @@ const useScrollbar = (speed, breakpoints = {}) => {
13
13
  const dragStartY = useRef(0);
14
14
  const scrollStartY = useRef(0);
15
15
  const scrollStartX = useRef(0);
16
- const thumbHeight = useRef(30); // Default min height
17
- const thumbWidth = useRef(30); // Default min height
16
+ // No need for thumbHeight/Width refs if calculating them dynamically
17
+ // const thumbHeight = useRef(30);
18
+ // const thumbWidth = useRef(30);
19
+ // Animation frame ID for batching visual updates
20
+ const animationFrameId = useRef(null);
18
21
  const updateThumb = useCallback(() => {
19
22
  if (!containerRef.current || !thumbY.current || !thumbX.current)
20
23
  return;
21
24
  const { clientHeight, scrollHeight, scrollTop, clientWidth, scrollWidth, scrollLeft } = containerRef.current;
22
- //Y thumb
23
- const thumbSizeY = Math.max((clientHeight / scrollHeight) * clientHeight, 30); // Min thumb size: 30px
24
- thumbHeight.current = thumbSizeY;
25
- const thumbPosY = (scrollTop / (scrollHeight - clientHeight)) * (clientHeight - thumbSizeY);
25
+ // Y thumb calculations and update
26
+ const actualThumbMinHeight = 30; // Min thumb size: 30px
27
+ const thumbSizeY = Math.max((clientHeight / scrollHeight) * clientHeight, actualThumbMinHeight);
28
+ const maxThumbPosY = clientHeight - thumbSizeY;
29
+ const thumbPosY = (scrollTop / (scrollHeight - clientHeight)) * maxThumbPosY;
26
30
  thumbY.current.style.height = `${thumbSizeY}px`;
27
- thumbY.current.style.top = `${thumbPosY}px`;
28
- //X thumb
29
- const thumbSizeX = Math.max((clientWidth / scrollWidth) * clientWidth, 30); // Min thumb size: 30px
30
- thumbWidth.current = thumbSizeX;
31
- const thumbPosX = (scrollLeft / (scrollWidth - clientWidth)) * (clientWidth - thumbSizeX);
31
+ // *** KEY CHANGE: Use transform for positioning ***
32
+ thumbY.current.style.transform = `translateY(${thumbPosY}px)`;
33
+ thumbY.current.style.willChange = 'transform, height'; // Hint for browser
34
+ // X thumb calculations and update
35
+ const actualThumbMinWidth = 30; // Min thumb size: 30px
36
+ const thumbSizeX = Math.max((clientWidth / scrollWidth) * clientWidth, actualThumbMinWidth);
37
+ const maxThumbPosX = clientWidth - thumbSizeX;
38
+ const thumbPosX = (scrollLeft / (scrollWidth - clientWidth)) * maxThumbPosX;
32
39
  thumbX.current.style.width = `${thumbSizeX}px`;
33
- thumbX.current.style.left = `${thumbPosX}px`;
34
- if (thumbY.current.clientHeight == clientHeight && rootRef) {
35
- rootRef.current?.classList.add(`--no-y`);
40
+ // *** KEY CHANGE: Use transform for positioning ***
41
+ thumbX.current.style.transform = `translateX(${thumbPosX}px)`;
42
+ thumbX.current.style.willChange = 'transform, width'; // Hint for browser
43
+ // Handle --no-y and --no-x classes (consider if these are strictly needed on every frame)
44
+ // These might still cause reflows, but less frequently than 'top'/'left'
45
+ if (scrollHeight <= clientHeight && rootRef.current) { // Use scrollHeight <= clientHeight for accurate check
46
+ rootRef.current.classList.add(`--no-y`);
36
47
  }
37
- else
38
- rootRef.current?.classList.remove(`--no-y`);
39
- if (thumbX.current.clientWidth == clientWidth && rootRef) {
40
- rootRef.current?.classList.add(`--no-x`);
48
+ else if (rootRef.current) {
49
+ rootRef.current.classList.remove(`--no-y`);
41
50
  }
42
- else
43
- rootRef.current?.classList.remove(`--no-x`);
44
- }, []);
45
- const postScroll = (scrollPercentY) => {
46
- updateThumb();
47
- // Trigger breakpoints
48
- Object.keys(breakpoints).forEach((key) => {
49
- const breakpoint = parseFloat(key);
50
- if (Math.abs(scrollPercentY - breakpoint) < 1) {
51
- breakpoints[breakpoint]?.();
51
+ if (scrollWidth <= clientWidth && rootRef.current) { // Use scrollWidth <= clientWidth for accurate check
52
+ rootRef.current.classList.add(`--no-x`);
53
+ }
54
+ else if (rootRef.current) {
55
+ rootRef.current.classList.remove(`--no-x`);
56
+ }
57
+ }, []); // Dependencies can be added here if needed, but often not for core calculations
58
+ // *** NEW: Central function to request a visual update via requestAnimationFrame ***
59
+ const requestVisualUpdate = useCallback(() => {
60
+ if (animationFrameId.current) {
61
+ cancelAnimationFrame(animationFrameId.current);
62
+ }
63
+ animationFrameId.current = requestAnimationFrame(() => {
64
+ updateThumb();
65
+ // Trigger breakpoints after the visual update for this frame
66
+ if (containerRef.current) {
67
+ const { scrollTop, scrollHeight, clientHeight, scrollLeft, scrollWidth, clientWidth } = containerRef.current;
68
+ const scrollPercentY = (scrollTop / (scrollHeight - clientHeight)) * 100;
69
+ const scrollPercentX = (scrollLeft / (scrollWidth - clientWidth)) * 100;
70
+ Object.keys(breakpoints).forEach((key) => {
71
+ const breakpoint = parseFloat(key);
72
+ if (Math.abs(scrollPercentY - breakpoint) < 1) {
73
+ breakpoints[breakpoint]?.();
74
+ }
75
+ if (Math.abs(scrollPercentX - breakpoint) < 1) { // Assuming breakpoints can be for X too
76
+ breakpoints[breakpoint]?.();
77
+ }
78
+ });
52
79
  }
53
80
  });
54
- };
81
+ }, [updateThumb, breakpoints]);
55
82
  const handleScroll = useCallback(() => {
56
- if (!containerRef.current
57
- // ||
58
- // (
59
- // typeof window !== `undefined` &&
60
- // window.document.body.classList.contains(`--no-scroll`)
61
- // )
62
- )
83
+ if (!containerRef.current)
63
84
  return;
64
- const { scrollTop, scrollHeight, clientHeight, scrollLeft, scrollWidth, clientWidth } = containerRef.current;
65
- const scrollPercentY = (scrollTop / (scrollHeight - clientHeight)) * 100;
66
- const scrollPercentX = (scrollLeft / (scrollWidth - clientWidth)) * 100;
67
- postScroll(scrollPercentY);
68
- postScroll(scrollPercentX);
69
- }, [breakpoints, updateThumb]);
85
+ // *** Call requestVisualUpdate instead of postScroll ***
86
+ requestVisualUpdate();
87
+ }, [requestVisualUpdate]);
70
88
  // Dragging logic
71
89
  const onScrollY = (e) => {
72
90
  isDraggingY.current = true;
@@ -85,30 +103,37 @@ const useScrollbar = (speed, breakpoints = {}) => {
85
103
  rootRef.current?.classList.add(`--scrolling`);
86
104
  };
87
105
  const handleDragMove = useCallback((e) => {
88
- if (!containerRef.current || !thumbY.current || !thumbX.current)
106
+ if (!containerRef.current || (!isDraggingY.current && !isDraggingX.current))
89
107
  return;
90
108
  const { clientHeight, scrollHeight, clientWidth, scrollWidth } = containerRef.current;
91
109
  if (isDraggingY.current) {
92
110
  const maxScroll = scrollHeight - clientHeight;
93
- const maxThumbMove = clientHeight - thumbHeight.current;
111
+ const thumbCurrentHeight = thumbY.current?.clientHeight || 30; // Use actual thumb height
112
+ const maxThumbMove = clientHeight - thumbCurrentHeight;
94
113
  const deltaY = e.clientY - dragStartY.current;
95
114
  const newScrollTop = Math.min(Math.max(scrollStartY.current + (deltaY / maxThumbMove) * maxScroll, 0), maxScroll);
96
115
  containerRef.current.scrollTop = newScrollTop;
116
+ // *** No direct updateThumb here, the scroll event listener will trigger requestVisualUpdate ***
97
117
  }
98
118
  if (isDraggingX.current) {
99
119
  const maxScrollX = scrollWidth - clientWidth;
100
- const maxThumbMoveX = clientWidth - thumbWidth.current;
120
+ const thumbCurrentWidth = thumbX.current?.clientWidth || 30; // Use actual thumb width
121
+ const maxThumbMoveX = clientWidth - thumbCurrentWidth;
101
122
  const deltaX = e.clientX - dragStartX.current;
102
123
  const newScrollLeft = Math.min(Math.max(scrollStartX.current + (deltaX / maxThumbMoveX) * maxScrollX, 0), maxScrollX);
103
124
  containerRef.current.scrollLeft = newScrollLeft;
125
+ // *** No direct updateThumb here, the scroll event listener will trigger requestVisualUpdate ***
104
126
  }
105
- }, []);
127
+ }, []); // No dependencies needed if current values are always fresh
106
128
  const handleDragEnd = () => {
107
129
  isDraggingY.current = false;
108
130
  isDraggingX.current = false;
109
131
  document.body.style.userSelect = "";
110
132
  if (rootRef.current)
111
133
  rootRef.current?.classList.remove(`--scrolling`);
134
+ if (animationFrameId.current) {
135
+ cancelAnimationFrame(animationFrameId.current); // Clear any pending rAF
136
+ }
112
137
  };
113
138
  const scrollToTop = () => containerRef.current?.scrollTo({ top: 0, behavior: "smooth" });
114
139
  const scrollToBottom = () => containerRef.current?.scrollTo({ top: containerRef.current.scrollHeight, behavior: "smooth" });
@@ -119,49 +144,69 @@ const useScrollbar = (speed, breakpoints = {}) => {
119
144
  if (!container)
120
145
  return;
121
146
  const handleWheel = (e) => {
122
- e.preventDefault();
123
- e.stopPropagation();
147
+ // *** Passive listener means preventDefault is often not needed/effective here ***
148
+ // e.preventDefault();
149
+ // e.stopPropagation();
124
150
  if (!containerRef.current)
125
151
  return;
126
- // Adjust scrollTop manually based on deltaY
127
152
  const { scrollTop, scrollHeight, clientHeight, scrollLeft, scrollWidth, clientWidth } = containerRef.current;
153
+ let newScrollTop = scrollTop;
154
+ let newScrollLeft = scrollLeft;
155
+ let changed = false;
128
156
  if (Math.abs(e.deltaY) > Math.abs(e.deltaX)) {
129
157
  const maxScrollY = scrollHeight - clientHeight;
130
- let newScrollTop = scrollTop + e.deltaY;
158
+ newScrollTop = scrollTop + e.deltaY * SCROLL_SPEED;
131
159
  newScrollTop = Math.max(0, Math.min(newScrollTop, maxScrollY));
132
- containerRef.current.scrollTop = newScrollTop * SCROLL_SPEED;
160
+ if (newScrollTop !== scrollTop) {
161
+ containerRef.current.scrollTop = newScrollTop;
162
+ changed = true;
163
+ }
133
164
  }
134
- if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) {
165
+ else { // Prefer deltaX if it's larger or if deltaY is 0
135
166
  const maxScrollX = scrollWidth - clientWidth;
136
- let newScrollLeft = scrollLeft + e.deltaX;
167
+ newScrollLeft = scrollLeft + e.deltaX * SCROLL_SPEED;
137
168
  newScrollLeft = Math.max(0, Math.min(newScrollLeft, maxScrollX));
138
- containerRef.current.scrollLeft = newScrollLeft * SCROLL_SPEED;
169
+ if (newScrollLeft !== scrollLeft) {
170
+ containerRef.current.scrollLeft = newScrollLeft;
171
+ changed = true;
172
+ }
173
+ }
174
+ // *** Only request update if scroll position actually changed ***
175
+ if (changed) {
176
+ requestVisualUpdate();
139
177
  }
140
- const scrollPercentY = (containerRef.current.scrollTop / (containerRef.current.scrollHeight - clientHeight)) * 100;
141
- const scrollPercentX = (containerRef.current.scrollLeft / (containerRef.current.scrollWidth - clientWidth)) * 100;
142
- postScroll(scrollPercentY);
143
- postScroll(scrollPercentX);
144
178
  };
145
- window.addEventListener("resize", updateThumb);
146
- container.addEventListener("scroll", handleScroll);
147
- // Prevent blocking default scrolling (fixes touchpad scrolling)
148
- container.addEventListener("wheel", handleWheel, { passive: false });
179
+ window.addEventListener("resize", requestVisualUpdate); // Use requestVisualUpdate for resize
180
+ container.addEventListener("scroll", handleScroll, { passive: true }); // Make scroll passive if you don't preventDefault
181
+ container.addEventListener("wheel", handleWheel, { passive: true }); // Keep passive for wheel
149
182
  document.addEventListener("mousemove", handleDragMove);
150
183
  document.addEventListener("mouseup", handleDragEnd);
151
- updateThumb();
184
+ // Initial update
185
+ requestVisualUpdate(); // Use requestVisualUpdate for initial render
152
186
  return () => {
153
- window.removeEventListener("resize", updateThumb);
154
- window.removeEventListener("wheel", handleWheel);
187
+ window.removeEventListener("resize", requestVisualUpdate);
155
188
  container.removeEventListener("scroll", handleScroll);
189
+ container.removeEventListener("wheel", handleWheel); // Corrected: remove from container
156
190
  document.removeEventListener("mousemove", handleDragMove);
157
191
  document.removeEventListener("mouseup", handleDragEnd);
192
+ if (animationFrameId.current) {
193
+ cancelAnimationFrame(animationFrameId.current); // Clean up any pending rAF
194
+ }
158
195
  };
159
- }, [handleScroll, handleDragMove, updateThumb]);
160
- useMutationObserver(containerRef.current, updateThumb);
196
+ }, [handleScroll, handleDragMove, requestVisualUpdate, SCROLL_SPEED]); // Added SCROLL_SPEED to deps
197
+ // *** NEW: Hook useMutationObserver to call requestVisualUpdate ***
198
+ useMutationObserver(containerRef.current, requestVisualUpdate);
161
199
  return {
162
- rootRef, containerRef, thumbY, thumbX,
163
- scrollToTop, scrollToBottom, scrollToLeft, scrollToRight,
164
- onScrollY, onScrollX
200
+ rootRef,
201
+ containerRef,
202
+ thumbY,
203
+ thumbX,
204
+ scrollToTop,
205
+ scrollToBottom,
206
+ scrollToLeft,
207
+ scrollToRight,
208
+ onScrollY,
209
+ onScrollX,
165
210
  };
166
211
  };
167
212
  export default useScrollbar;
@@ -14,6 +14,8 @@ export declare enum FORMVALIDATION_STYLE {
14
14
  Dots = "DOTS"
15
15
  }
16
16
  export declare enum FORMVALIDATION {
17
+ IPV4 = "IPV4",
18
+ IPV6 = "IPV6",
17
19
  Email = "EMAIL",
18
20
  Uri = "URI",
19
21
  Password = "PASSWORD",
@@ -19,6 +19,8 @@ export var FORMVALIDATION_STYLE;
19
19
  })(FORMVALIDATION_STYLE || (FORMVALIDATION_STYLE = {}));
20
20
  export var FORMVALIDATION;
21
21
  (function (FORMVALIDATION) {
22
+ FORMVALIDATION["IPV4"] = "IPV4";
23
+ FORMVALIDATION["IPV6"] = "IPV6";
22
24
  FORMVALIDATION["Email"] = "EMAIL";
23
25
  FORMVALIDATION["Uri"] = "URI";
24
26
  FORMVALIDATION["Password"] = "PASSWORD";
@@ -1,6 +1,6 @@
1
1
  import { ComponentPropsWithoutRef, ElementType } from "react";
2
2
  import { DragOptions } from "../hooks";
3
- import { SHIMMER, SORT, TRANSITIONS } from "./enums";
3
+ import { Position, SHIMMER, SORT, TRANSITIONS } from "./enums";
4
4
  import { animationProps, Skeleton } from "./interfaces";
5
5
  export type Deprecated<T, M extends string> = T & {
6
6
  __deprecatedMessage?: M;
@@ -85,3 +85,4 @@ export type cssShortKeys = {
85
85
  sy: string | number;
86
86
  sz: string | number;
87
87
  };
88
+ export type Direction = Position;