@kolkrabbi/kol-component 0.6.0 → 0.7.0

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 (91) hide show
  1. package/package.json +4 -2
  2. package/src/chess/ChessPiece.jsx +191 -0
  3. package/src/chess/apparatus/AlternativeControlsMock.jsx +460 -0
  4. package/src/chess/apparatus/ChessAnalysisLayout.jsx +24 -0
  5. package/src/chess/apparatus/ChessBoard.jsx +210 -0
  6. package/src/chess/apparatus/ChessBoardFullscreen.jsx +49 -0
  7. package/src/chess/apparatus/ChessBoardWithControls.jsx +41 -0
  8. package/src/chess/apparatus/ChessBoardWithSidebar.jsx +122 -0
  9. package/src/chess/apparatus/ChessSidebar.jsx +131 -0
  10. package/src/chess/apparatus/GameArchiveTable.jsx +493 -0
  11. package/src/chess/apparatus/GameSelector.jsx +47 -0
  12. package/src/chess/apparatus/NotationPanel.jsx +70 -0
  13. package/src/chess/apparatus/PlaybackControls.jsx +52 -0
  14. package/src/chess/apparatus/VariationTree.jsx +137 -0
  15. package/src/chess/assets/chess-extra-set/set-1/bishop-1.svg +6 -0
  16. package/src/chess/assets/chess-extra-set/set-1/bishop.svg +6 -0
  17. package/src/chess/assets/chess-extra-set/set-1/king-1.svg +9 -0
  18. package/src/chess/assets/chess-extra-set/set-1/king.svg +7 -0
  19. package/src/chess/assets/chess-extra-set/set-1/knight-1.svg +8 -0
  20. package/src/chess/assets/chess-extra-set/set-1/knight.svg +7 -0
  21. package/src/chess/assets/chess-extra-set/set-1/pawn-1.svg +3 -0
  22. package/src/chess/assets/chess-extra-set/set-1/pawn.svg +3 -0
  23. package/src/chess/assets/chess-extra-set/set-1/queen-1.svg +11 -0
  24. package/src/chess/assets/chess-extra-set/set-1/queen.svg +6 -0
  25. package/src/chess/assets/chess-extra-set/set-1/rook-1.svg +7 -0
  26. package/src/chess/assets/chess-extra-set/set-1/rook.svg +11 -0
  27. package/src/chess/assets/chess-extra-set/set-2/bishop-1.svg +4 -0
  28. package/src/chess/assets/chess-extra-set/set-2/bishop.svg +4 -0
  29. package/src/chess/assets/chess-extra-set/set-2/king-1.svg +4 -0
  30. package/src/chess/assets/chess-extra-set/set-2/king.svg +4 -0
  31. package/src/chess/assets/chess-extra-set/set-2/knight-1.svg +5 -0
  32. package/src/chess/assets/chess-extra-set/set-2/knight.svg +5 -0
  33. package/src/chess/assets/chess-extra-set/set-2/pawn-1.svg +4 -0
  34. package/src/chess/assets/chess-extra-set/set-2/pawn.svg +4 -0
  35. package/src/chess/assets/chess-extra-set/set-2/queen-1.svg +4 -0
  36. package/src/chess/assets/chess-extra-set/set-2/queen.svg +4 -0
  37. package/src/chess/assets/chess-extra-set/set-2/rook-1.svg +5 -0
  38. package/src/chess/assets/chess-extra-set/set-2/rook.svg +5 -0
  39. package/src/chess/assets/chess-extra-set/set-3/bishop-1.svg +10 -0
  40. package/src/chess/assets/chess-extra-set/set-3/bishop.svg +3 -0
  41. package/src/chess/assets/chess-extra-set/set-3/king-1.svg +12 -0
  42. package/src/chess/assets/chess-extra-set/set-3/king.svg +3 -0
  43. package/src/chess/assets/chess-extra-set/set-3/knight-1.svg +3 -0
  44. package/src/chess/assets/chess-extra-set/set-3/knight.svg +10 -0
  45. package/src/chess/assets/chess-extra-set/set-3/pawn-1.svg +10 -0
  46. package/src/chess/assets/chess-extra-set/set-3/pawn.svg +10 -0
  47. package/src/chess/assets/chess-extra-set/set-3/queen-1.svg +10 -0
  48. package/src/chess/assets/chess-extra-set/set-3/queen.svg +3 -0
  49. package/src/chess/assets/chess-extra-set/set-3/rook-1.svg +3 -0
  50. package/src/chess/assets/chess-extra-set/set-3/rook.svg +11 -0
  51. package/src/chess/assets/chess-vector-set/ABoard.svg +164 -0
  52. package/src/chess/assets/chess-vector-set/BBiskup.svg +12 -0
  53. package/src/chess/assets/chess-vector-set/BKing.svg +15 -0
  54. package/src/chess/assets/chess-vector-set/BKnight.svg +13 -0
  55. package/src/chess/assets/chess-vector-set/BPawn.svg +7 -0
  56. package/src/chess/assets/chess-vector-set/BQueen.svg +6 -0
  57. package/src/chess/assets/chess-vector-set/BRook.svg +12 -0
  58. package/src/chess/assets/chess-vector-set/WBiskup.svg +14 -0
  59. package/src/chess/assets/chess-vector-set/WKing.svg +13 -0
  60. package/src/chess/assets/chess-vector-set/WKnight.svg +10 -0
  61. package/src/chess/assets/chess-vector-set/WPawn.svg +8 -0
  62. package/src/chess/assets/chess-vector-set/WQueen.svg +17 -0
  63. package/src/chess/assets/chess-vector-set/WRook.svg +13 -0
  64. package/src/chess/context/ChessControlsContext.jsx +379 -0
  65. package/src/chess/dashboards/ChessHero.jsx +303 -0
  66. package/src/chess/index.js +32 -0
  67. package/src/chess/utils/parsePgnTree.js +97 -0
  68. package/src/dashboards/cards/DashAlertCard.jsx +44 -0
  69. package/src/dashboards/cards/DashChartCard.jsx +44 -0
  70. package/src/dashboards/cards/DashFeaturedCard.jsx +42 -0
  71. package/src/dashboards/cards/DashListCard.jsx +87 -0
  72. package/src/dashboards/cards/DashMetricCard.jsx +59 -0
  73. package/src/dashboards/cards/DashSlotCard.jsx +45 -0
  74. package/src/dashboards/cards/DashStackedBarCard.jsx +70 -0
  75. package/src/dashboards/cards/DashTableCard.jsx +31 -0
  76. package/src/dashboards/cards/_shared/CardHeader.jsx +15 -0
  77. package/src/dashboards/cards/_shared/LegendRow.jsx +25 -0
  78. package/src/dashboards/charts/Candlestick.jsx +79 -0
  79. package/src/dashboards/charts/DonutChart.jsx +87 -0
  80. package/src/dashboards/charts/Heatmap.jsx +79 -0
  81. package/src/dashboards/charts/Histogram.jsx +56 -0
  82. package/src/dashboards/charts/LineChart.jsx +157 -0
  83. package/src/dashboards/charts/ScatterPlot.jsx +93 -0
  84. package/src/dashboards/charts/Sparkline.jsx +63 -0
  85. package/src/dashboards/index.js +28 -0
  86. package/src/dashboards/layout/DashboardGrid.jsx +30 -0
  87. package/src/dashboards/layout/GridCard.jsx +44 -0
  88. package/src/dashboards/shared/DashTooltip.jsx +6 -0
  89. package/src/dashboards/shared/formatMetric.js +26 -0
  90. package/src/dashboards/shared/useChartTooltip.js +25 -0
  91. package/src/dashboards/shared/useCountUp.js +107 -0
@@ -0,0 +1,25 @@
1
+ import { useState, useCallback, useRef } from 'react'
2
+
3
+ const useChartTooltip = () => {
4
+ const [activeIndex, setActiveIndex] = useState(null)
5
+ const containerRef = useRef(null)
6
+
7
+ const containerHandlers = {
8
+ onMouseMove: (e) => {
9
+ if (!containerRef.current) return
10
+ const rect = containerRef.current.getBoundingClientRect()
11
+ containerRef.current.style.setProperty('--tx', `${e.clientX - rect.left}px`)
12
+ containerRef.current.style.setProperty('--ty', `${e.clientY - rect.top}px`)
13
+ },
14
+ onMouseLeave: () => setActiveIndex(null)
15
+ }
16
+
17
+ const handlers = useCallback((index) => ({
18
+ onMouseEnter: () => setActiveIndex(index),
19
+ onMouseLeave: () => setActiveIndex(null)
20
+ }), [])
21
+
22
+ return { activeIndex, handlers, containerHandlers, containerRef }
23
+ }
24
+
25
+ export default useChartTooltip
@@ -0,0 +1,107 @@
1
+ import { useState, useEffect, useRef } from 'react'
2
+
3
+ const parseNumeric = (value) => {
4
+ const str = String(value)
5
+ const match = str.match(/^([^0-9]*?)([\d,.]+)(.*?)$/)
6
+ if (!match) return null
7
+ const prefix = match[1]
8
+ const numStr = match[2]
9
+ const suffix = match[3]
10
+ const num = parseFloat(numStr.replace(/,/g, ''))
11
+ if (isNaN(num)) return null
12
+ const hasCommas = numStr.includes(',')
13
+ const decimalMatch = numStr.match(/\.(\d+)/)
14
+ const decimals = decimalMatch ? decimalMatch[1].length : 0
15
+ return { prefix, num, suffix, hasCommas, decimals }
16
+ }
17
+
18
+ const formatNumber = (n, hasCommas, decimals) => {
19
+ const fixed = n.toFixed(decimals)
20
+ if (!hasCommas) return fixed
21
+ const [intPart, decPart] = fixed.split('.')
22
+ const withCommas = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
23
+ return decPart ? `${withCommas}.${decPart}` : withCommas
24
+ }
25
+
26
+ const useCountUp = (targetValue, { duration = 600, enabled = true } = {}) => {
27
+ const [displayValue, setDisplayValue] = useState(targetValue)
28
+ const ref = useRef(null)
29
+ const hasEnteredRef = useRef(false)
30
+ const prevTargetRef = useRef(targetValue)
31
+ const rafRef = useRef(null)
32
+ const elRef = useRef(null)
33
+
34
+ useEffect(() => {
35
+ if (!enabled) {
36
+ setDisplayValue(targetValue)
37
+ return
38
+ }
39
+
40
+ const animate = (from, to) => {
41
+ const parsed = parseNumeric(to)
42
+ if (!parsed) {
43
+ setDisplayValue(to)
44
+ return
45
+ }
46
+
47
+ const parsedFrom = parseNumeric(from)
48
+ const startNum = parsedFrom ? parsedFrom.num : 0
49
+ const endNum = parsed.num
50
+ const startTime = performance.now()
51
+
52
+ const step = (now) => {
53
+ const elapsed = now - startTime
54
+ const t = Math.min(elapsed / duration, 1)
55
+ const eased = t * (2 - t) // ease-out quadratic
56
+ const current = startNum + (endNum - startNum) * eased
57
+ const formatted = `${parsed.prefix}${formatNumber(current, parsed.hasCommas, parsed.decimals)}${parsed.suffix}`
58
+ setDisplayValue(formatted)
59
+ if (t < 1) {
60
+ rafRef.current = requestAnimationFrame(step)
61
+ }
62
+ }
63
+
64
+ if (rafRef.current) cancelAnimationFrame(rafRef.current)
65
+ rafRef.current = requestAnimationFrame(step)
66
+ }
67
+
68
+ // On target change while already visible
69
+ if (hasEnteredRef.current && prevTargetRef.current !== targetValue) {
70
+ animate(prevTargetRef.current, targetValue)
71
+ prevTargetRef.current = targetValue
72
+ return
73
+ }
74
+
75
+ prevTargetRef.current = targetValue
76
+
77
+ // IntersectionObserver for first entry
78
+ if (hasEnteredRef.current) return
79
+
80
+ const el = elRef.current
81
+ if (!el) {
82
+ setDisplayValue(targetValue)
83
+ return
84
+ }
85
+
86
+ const observer = new IntersectionObserver(
87
+ ([entry]) => {
88
+ if (entry.isIntersecting && !hasEnteredRef.current) {
89
+ hasEnteredRef.current = true
90
+ animate('0', targetValue)
91
+ observer.disconnect()
92
+ }
93
+ },
94
+ { threshold: 0.1 }
95
+ )
96
+ observer.observe(el)
97
+
98
+ return () => {
99
+ observer.disconnect()
100
+ if (rafRef.current) cancelAnimationFrame(rafRef.current)
101
+ }
102
+ }, [targetValue, duration, enabled])
103
+
104
+ return { displayValue, ref: elRef }
105
+ }
106
+
107
+ export default useCountUp