react-native-wagmi-charts 2.0.1 → 2.1.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 (46) hide show
  1. package/.DS_Store +0 -0
  2. package/README.md +30 -1
  3. package/example/.DS_Store +0 -0
  4. package/example/package.json +11 -13
  5. package/example/src/App.tsx +39 -34
  6. package/example/src/LineChart.tsx +2 -1
  7. package/example/yarn.lock +1819 -8871
  8. package/lib/commonjs/charts/candle/HoverTrap/index.web.js +120 -0
  9. package/lib/commonjs/charts/candle/HoverTrap/index.web.js.map +1 -0
  10. package/lib/commonjs/charts/line/ChartPath.js +8 -3
  11. package/lib/commonjs/charts/line/ChartPath.js.map +1 -1
  12. package/lib/commonjs/charts/line/HoverTrap/index.js +15 -0
  13. package/lib/commonjs/charts/line/HoverTrap/index.js.map +1 -0
  14. package/lib/commonjs/charts/line/HoverTrap/index.web.js +120 -0
  15. package/lib/commonjs/charts/line/HoverTrap/index.web.js.map +1 -0
  16. package/lib/commonjs/charts/line/index.js +4 -1
  17. package/lib/commonjs/charts/line/index.js.map +1 -1
  18. package/lib/commonjs/components/AnimatedText.js +3 -5
  19. package/lib/commonjs/components/AnimatedText.js.map +1 -1
  20. package/lib/module/charts/candle/HoverTrap/index.web.js +101 -0
  21. package/lib/module/charts/candle/HoverTrap/index.web.js.map +1 -0
  22. package/lib/module/charts/line/ChartPath.js +8 -3
  23. package/lib/module/charts/line/ChartPath.js.map +1 -1
  24. package/lib/module/charts/line/HoverTrap/index.js +3 -0
  25. package/lib/module/charts/line/HoverTrap/index.js.map +1 -0
  26. package/lib/module/charts/line/HoverTrap/index.web.js +101 -0
  27. package/lib/module/charts/line/HoverTrap/index.web.js.map +1 -0
  28. package/lib/module/charts/line/index.js +3 -1
  29. package/lib/module/charts/line/index.js.map +1 -1
  30. package/lib/module/components/AnimatedText.js +2 -5
  31. package/lib/module/components/AnimatedText.js.map +1 -1
  32. package/lib/typescript/src/charts/candle/HoverTrap/index.web.d.ts +2 -0
  33. package/lib/typescript/src/charts/line/ChartPath.d.ts +3 -3
  34. package/lib/typescript/src/charts/line/HoverTrap/index.d.ts +2 -0
  35. package/lib/typescript/src/charts/line/HoverTrap/index.web.d.ts +2 -0
  36. package/lib/typescript/src/charts/line/index.d.ts +2 -0
  37. package/package.json +5 -5
  38. package/src/charts/candle/HoverTrap/index.web.tsx +110 -0
  39. package/src/charts/line/ChartPath.tsx +19 -14
  40. package/src/charts/line/HoverTrap/index.tsx +3 -0
  41. package/src/charts/line/HoverTrap/index.web.tsx +110 -0
  42. package/src/charts/line/index.ts +2 -0
  43. package/src/components/AnimatedText.tsx +2 -5
  44. package/tsconfig.json +1 -1
  45. package/yarn.lock +1840 -796
  46. package/example/patches/react-native-reanimated+2.2.2.patch +0 -28
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.LineChartHoverTrap = void 0;
7
+
8
+ var React = _interopRequireWildcard(require("react"));
9
+
10
+ var _reactNative = require("react-native");
11
+
12
+ var _reactNativeRedash = require("react-native-redash");
13
+
14
+ var _Chart = require("../../line/Chart");
15
+
16
+ var _useLineChart = require("../../line/useLineChart");
17
+
18
+ var _ExecutionEnvironment = require("fbjs/lib/ExecutionEnvironment");
19
+
20
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
+
22
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
+
24
+ // @ts-expect-error missing types
25
+ let isEnabled = false; // the following logic comes from the creator of react-native-web
26
+ // https://gist.github.com/necolas/1c494e44e23eb7f8c5864a2fac66299a
27
+ // it's also used by MotiPressable's hover interactions
28
+ // https://github.com/nandorojo/moti/blob/master/packages/interactions/src/pressable/hoverable.tsx
29
+
30
+ if (_ExecutionEnvironment.canUseDOM) {
31
+ /**
32
+ * Web browsers emulate mouse events (and hover states) after touch events.
33
+ * This code infers when the currently-in-use modality supports hover
34
+ * (including for multi-modality devices) and considers "hover" to be enabled
35
+ * if a mouse movement occurs more than 1 second after the last touch event.
36
+ * This threshold is long enough to account for longer delays between the
37
+ * browser firing touch and mouse events on low-powered devices.
38
+ */
39
+ const HOVER_THRESHOLD_MS = 1000;
40
+ let lastTouchTimestamp = 0;
41
+
42
+ function enableHover() {
43
+ if (isEnabled || Date.now() - lastTouchTimestamp < HOVER_THRESHOLD_MS) {
44
+ return;
45
+ }
46
+
47
+ isEnabled = true;
48
+ }
49
+
50
+ function disableHover() {
51
+ lastTouchTimestamp = Date.now();
52
+
53
+ if (isEnabled) {
54
+ isEnabled = false;
55
+ }
56
+ }
57
+
58
+ document.addEventListener('touchstart', disableHover, true);
59
+ document.addEventListener('touchmove', disableHover, true);
60
+ document.addEventListener('mousemove', enableHover, true);
61
+ }
62
+
63
+ function isHoverEnabled() {
64
+ return isEnabled;
65
+ }
66
+
67
+ const LineChartHoverTrap = () => {
68
+ const {
69
+ width,
70
+ path
71
+ } = React.useContext(_Chart.LineChartDimensionsContext);
72
+ const {
73
+ currentX,
74
+ currentIndex,
75
+ isActive,
76
+ data
77
+ } = (0, _useLineChart.useLineChart)();
78
+ const parsedPath = React.useMemo(() => path ? (0, _reactNativeRedash.parse)(path) : undefined, [path]);
79
+ const onMouseMove = React.useCallback(({
80
+ x
81
+ }) => {
82
+ if (isHoverEnabled()) {
83
+ if (parsedPath) {
84
+ const boundedX = Math.min(x, width);
85
+ isActive.value = true;
86
+ currentX.value = boundedX; // on Web, we could drag the cursor to be negative, breaking it
87
+ // so we clamp the index at 0 to fix it
88
+ // https://github.com/coinjar/react-native-wagmi-charts/issues/24
89
+
90
+ const minIndex = 0;
91
+ const boundedIndex = Math.max(minIndex, Math.round(boundedX / width / (1 / (data.length - 1))));
92
+ currentIndex.value = boundedIndex;
93
+ }
94
+ } else {
95
+ isActive.value = false;
96
+ currentIndex.value = -1;
97
+ }
98
+ }, [currentIndex, currentX, data.length, isActive, parsedPath, width]);
99
+ const onMouseLeave = React.useCallback(() => {
100
+ isActive.value = false;
101
+ currentIndex.value = -1;
102
+ }, [currentIndex, isActive]);
103
+ return /*#__PURE__*/React.createElement(_reactNative.View, {
104
+ style: _reactNative.StyleSheet.absoluteFill // @ts-expect-error mouse move event
105
+ ,
106
+ onMouseMove: React.useCallback( // eslint-disable-next-line no-undef
107
+ e => {
108
+ let rect = e.currentTarget.getBoundingClientRect();
109
+ let x = e.clientX - rect.left; // x position within the element.
110
+
111
+ onMouseMove({
112
+ x
113
+ });
114
+ }, [onMouseMove]),
115
+ onMouseLeave: onMouseLeave
116
+ });
117
+ };
118
+
119
+ exports.LineChartHoverTrap = LineChartHoverTrap;
120
+ //# sourceMappingURL=index.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.web.tsx"],"names":["isEnabled","canUseDOM","HOVER_THRESHOLD_MS","lastTouchTimestamp","enableHover","Date","now","disableHover","document","addEventListener","isHoverEnabled","LineChartHoverTrap","width","path","React","useContext","LineChartDimensionsContext","currentX","currentIndex","isActive","data","parsedPath","useMemo","undefined","onMouseMove","useCallback","x","boundedX","Math","min","value","minIndex","boundedIndex","max","round","length","onMouseLeave","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;AAFF;AAGE,IAAA,WAAW,EAAExB,KAAK,CAACW,WAAN,EACX;AACCc,IAAAA,CAAD,IAAsC;AACpC,UAAIC,IAAI,GAAGD,CAAC,CAACE,aAAF,CAAgBC,qBAAhB,EAAX;AACA,UAAIhB,CAAC,GAAGa,CAAC,CAACI,OAAF,GAAYH,IAAI,CAACI,IAAzB,CAFoC,CAEL;;AAE/BpB,MAAAA,WAAW,CAAC;AAAEE,QAAAA;AAAF,OAAD,CAAX;AACD,KAPU,EAQX,CAACF,WAAD,CARW,CAHf;AAaE,IAAA,YAAY,EAAEY;AAbhB,IADF;AAiBD,CA1DM","sourcesContent":["import * as React from 'react';\nimport { View, StyleSheet } from 'react-native';\nimport { parse } from 'react-native-redash';\n\nimport { LineChartDimensionsContext } from '../../line/Chart';\nimport { useLineChart } from '../../line/useLineChart';\n\n// @ts-expect-error missing types\nimport { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';\n\nlet isEnabled = false;\n\n// the following logic comes from the creator of react-native-web\n// https://gist.github.com/necolas/1c494e44e23eb7f8c5864a2fac66299a\n// it's also used by MotiPressable's hover interactions\n// https://github.com/nandorojo/moti/blob/master/packages/interactions/src/pressable/hoverable.tsx\nif (canUseDOM) {\n /**\n * Web browsers emulate mouse events (and hover states) after touch events.\n * This code infers when the currently-in-use modality supports hover\n * (including for multi-modality devices) and considers \"hover\" to be enabled\n * if a mouse movement occurs more than 1 second after the last touch event.\n * This threshold is long enough to account for longer delays between the\n * browser firing touch and mouse events on low-powered devices.\n */\n const HOVER_THRESHOLD_MS = 1000;\n let lastTouchTimestamp = 0;\n\n function enableHover() {\n if (isEnabled || Date.now() - lastTouchTimestamp < HOVER_THRESHOLD_MS) {\n return;\n }\n isEnabled = true;\n }\n\n function disableHover() {\n lastTouchTimestamp = Date.now();\n if (isEnabled) {\n isEnabled = false;\n }\n }\n\n document.addEventListener('touchstart', disableHover, true);\n document.addEventListener('touchmove', disableHover, true);\n document.addEventListener('mousemove', enableHover, true);\n}\n\nfunction isHoverEnabled(): boolean {\n return isEnabled;\n}\n\nexport const LineChartHoverTrap = () => {\n const { width, path } = React.useContext(LineChartDimensionsContext);\n const { currentX, currentIndex, isActive, data } = useLineChart();\n\n const parsedPath = React.useMemo(\n () => (path ? parse(path) : undefined),\n [path]\n );\n\n const onMouseMove = React.useCallback(\n ({ x }: { x: number }) => {\n if (isHoverEnabled()) {\n if (parsedPath) {\n const boundedX = Math.min(x, width);\n isActive.value = true;\n currentX.value = boundedX;\n\n // on Web, we could drag the cursor to be negative, breaking it\n // so we clamp the index at 0 to fix it\n // https://github.com/coinjar/react-native-wagmi-charts/issues/24\n const minIndex = 0;\n const boundedIndex = Math.max(\n minIndex,\n Math.round(boundedX / width / (1 / (data.length - 1)))\n );\n\n currentIndex.value = boundedIndex;\n }\n } else {\n isActive.value = false;\n currentIndex.value = -1;\n }\n },\n [currentIndex, currentX, data.length, isActive, parsedPath, width]\n );\n\n const onMouseLeave = React.useCallback(() => {\n isActive.value = false;\n currentIndex.value = -1;\n }, [currentIndex, isActive]);\n\n return (\n <View\n style={StyleSheet.absoluteFill}\n // @ts-expect-error mouse move event\n onMouseMove={React.useCallback(\n // eslint-disable-next-line no-undef\n (e: React.MouseEvent<HTMLElement>) => {\n let rect = e.currentTarget.getBoundingClientRect();\n let x = e.clientX - rect.left; // x position within the element.\n\n onMouseMove({ x });\n },\n [onMouseMove]\n )}\n onMouseLeave={onMouseLeave}\n />\n );\n};\n"]}
@@ -77,12 +77,17 @@ function LineChartPathWrapper({
77
77
  const svgProps = (0, _reactNativeReanimated.useAnimatedProps)(() => {
78
78
  const shouldAnimateOnMount = animateOnMount === 'foreground';
79
79
  const inactiveWidth = !isMounted.value && shouldAnimateOnMount ? 0 : pathWidth;
80
- const duration = shouldAnimateOnMount && !hasMountedAnimation.value ? mountAnimationDuration : animationDuration;
80
+ let duration = shouldAnimateOnMount && !hasMountedAnimation.value ? mountAnimationDuration : animationDuration;
81
81
  const props = shouldAnimateOnMount && !hasMountedAnimation.value ? mountAnimationProps : animationProps;
82
+
83
+ if (isActive.value) {
84
+ duration = 0;
85
+ }
86
+
82
87
  return {
83
- width: isActive.value ? // on Web, <svg /> elements don't support negative widths
88
+ width: (0, _reactNativeReanimated.withTiming)(isActive.value ? // on Web, <svg /> elements don't support negative widths
84
89
  // https://github.com/coinjar/react-native-wagmi-charts/issues/24#issuecomment-955789904
85
- Math.max(currentX.value, 0) : (0, _reactNativeReanimated.withTiming)(inactiveWidth + widthOffset, Object.assign({
90
+ Math.max(currentX.value, 0) : inactiveWidth + widthOffset, Object.assign({
86
91
  duration
87
92
  }, props), () => {
88
93
  hasMountedAnimation.value = true;
@@ -1 +1 @@
1
- {"version":3,"sources":["ChartPath.tsx"],"names":["BACKGROUND_COMPONENTS","FOREGROUND_COMPONENTS","AnimatedSVG","Animated","createAnimatedComponent","Svg","LineChartPathContext","React","createContext","color","isInactive","isTransitionEnabled","LineChartPathWrapper","displayName","animationDuration","animationProps","children","inactiveColor","width","strokeWidth","widthOffset","pathProps","showInactivePath","animateOnMount","mountAnimationDuration","mountAnimationProps","height","pathWidth","useContext","LineChartDimensionsContext","currentX","isActive","isMounted","hasMountedAnimation","useEffect","value","svgProps","shouldAnimateOnMount","inactiveWidth","duration","props","Math","max","Object","assign","viewSize","useMemo","backgroundChildren","foregroundChildren","iterableChildren","filter","child","includes","type","StyleSheet","absoluteFill"],"mappings":";;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAKA;;AAEA;;AACA;;AACA;;;;;;;;;;AAEA,MAAMA,qBAAqB,GAAG,CAC5B,oBAD4B,EAE5B,yBAF4B,EAG5B,mBAH4B,EAI5B,cAJ4B,CAA9B;AAMA,MAAMC,qBAAqB,GAAG,CAAC,oBAAD,EAAuB,cAAvB,CAA9B;;AAEA,MAAMC,WAAW,GAAGC,+BAASC,uBAAT,CAAiCC,mBAAjC,CAApB;;AAEO,MAAMC,oBAAoB,gBAAGC,KAAK,CAACC,aAAN,CAAoB;AACtDC,EAAAA,KAAK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AA+BA,KAAK,CAAEE,IAAtC,iDAA+B,aAAaxC,WAA5C;AAF2C;AAAA,KAAxB,CAArB;AAID,GA5D2B,CA8D5B;;;AAEA,sBACE,uDACE,oBAAC,oBAAD,CAAsB,QAAtB;AACE,IAAA,KAAK,EAAE;AACLJ,MAAAA,KADK;AAELC,MAAAA,UAAU,EAAEY,gBAFP;AAGLX,MAAAA,mBAAmB,2BAAEU,SAAS,CAACV,mBAAZ,yEAAmC;AAHjD;AADT,kBAOE,oBAAC,iBAAD;AAAM,IAAA,KAAK,EAAEkC;AAAb,kBACE,oBAAC,mBAAD;AAAK,IAAA,KAAK,EAAE3B,KAAZ;AAAmB,IAAA,MAAM,EAAEQ;AAA3B,kBACE,oBAAC,mBAAD;AACE,IAAA,KAAK,EAAEjB,KADT;AAEE,IAAA,aAAa,EAAEQ,aAFjB;AAGE,IAAA,KAAK,EAAEE;AAHT,KAIME,SAJN,EADF,EAOG0B,kBAPH,CADF,CAPF,CADF,eAoBE,oBAAC,oBAAD,CAAsB,QAAtB;AACE,IAAA,KAAK,EAAE;AACLtC,MAAAA,KADK;AAELC,MAAAA,UAAU,EAAE,KAFP;AAGLC,MAAAA,mBAAmB,4BAAEU,SAAS,CAACV,mBAAZ,2EAAmC;AAHjD;AADT,kBAOE,oBAAC,iBAAD;AAAM,IAAA,KAAK,EAAE2C,wBAAWC;AAAxB,kBACE,oBAAC,WAAD;AAAa,IAAA,aAAa,EAAEnB,QAA5B;AAAsC,IAAA,MAAM,EAAEV;AAA9C,kBACE,oBAAC,mBAAD;AAAe,IAAA,KAAK,EAAEjB,KAAtB;AAA6B,IAAA,KAAK,EAAEU;AAApC,KAAqDE,SAArD,EADF,EAEG2B,kBAFH,CADF,CAPF,CApBF,CADF;AAqCD","sourcesContent":["import * as React from 'react';\nimport { StyleSheet, View } from 'react-native';\nimport { Svg } from 'react-native-svg';\nimport Animated, {\n useAnimatedProps,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport flattenChildren from 'react-keyed-flatten-children';\n\nimport { LineChartDimensionsContext } from './Chart';\nimport { LineChartPath, LineChartPathProps } from './Path';\nimport { useLineChart } from './useLineChart';\n\nconst BACKGROUND_COMPONENTS = [\n 'LineChartHighlight',\n 'LineChartHorizontalLine',\n 'LineChartGradient',\n 'LineChartDot',\n];\nconst FOREGROUND_COMPONENTS = ['LineChartHighlight', 'LineChartDot'];\n\nconst AnimatedSVG = Animated.createAnimatedComponent(Svg);\n\nexport const LineChartPathContext = React.createContext({\n color: '',\n isInactive: false,\n isTransitionEnabled: true,\n});\n\ntype LineChartPathWrapperProps = {\n animationDuration?: number;\n animationProps?: Partial<Animated.WithTimingConfig>;\n children?: React.ReactNode;\n color?: string;\n inactiveColor?: string;\n width?: number;\n widthOffset?: number;\n pathProps?: Partial<LineChartPathProps>;\n showInactivePath?: boolean;\n animateOnMount?: 'foreground';\n mountAnimationDuration?: number;\n mountAnimationProps?: Partial<Animated.WithTimingConfig>;\n};\n\nLineChartPathWrapper.displayName = 'LineChartPathWrapper';\n\nexport function LineChartPathWrapper({\n animationDuration = 300,\n animationProps = {},\n children,\n color = 'black',\n inactiveColor,\n width: strokeWidth = 3,\n widthOffset = 20,\n pathProps = {},\n showInactivePath = true,\n animateOnMount,\n mountAnimationDuration = animationDuration,\n mountAnimationProps = animationProps,\n}: LineChartPathWrapperProps) {\n const { height, pathWidth, width } = React.useContext(\n LineChartDimensionsContext\n );\n const { currentX, isActive } = useLineChart();\n const isMounted = useSharedValue(false);\n const hasMountedAnimation = useSharedValue(false);\n\n React.useEffect(() => {\n isMounted.value = true;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n ////////////////////////////////////////////////\n\n const svgProps = useAnimatedProps(() => {\n const shouldAnimateOnMount = animateOnMount === 'foreground';\n const inactiveWidth =\n !isMounted.value && shouldAnimateOnMount ? 0 : pathWidth;\n\n const duration =\n shouldAnimateOnMount && !hasMountedAnimation.value\n ? mountAnimationDuration\n : animationDuration;\n const props =\n shouldAnimateOnMount && !hasMountedAnimation.value\n ? mountAnimationProps\n : animationProps;\n\n return {\n width: isActive.value\n ? // on Web, <svg /> elements don't support negative widths\n // https://github.com/coinjar/react-native-wagmi-charts/issues/24#issuecomment-955789904\n Math.max(currentX.value, 0)\n : withTiming(\n inactiveWidth + widthOffset,\n Object.assign({ duration }, props),\n () => {\n hasMountedAnimation.value = true;\n }\n ),\n };\n });\n\n const viewSize = React.useMemo(() => ({ width, height }), [width, height]);\n\n ////////////////////////////////////////////////\n\n let backgroundChildren;\n let foregroundChildren;\n if (children) {\n const iterableChildren = flattenChildren(children);\n backgroundChildren = iterableChildren.filter((child) =>\n // @ts-ignore\n BACKGROUND_COMPONENTS.includes(child?.type?.displayName)\n );\n foregroundChildren = iterableChildren.filter((child) =>\n // @ts-ignore\n FOREGROUND_COMPONENTS.includes(child?.type?.displayName)\n );\n }\n\n ////////////////////////////////////////////////\n\n return (\n <>\n <LineChartPathContext.Provider\n value={{\n color,\n isInactive: showInactivePath,\n isTransitionEnabled: pathProps.isTransitionEnabled ?? true,\n }}\n >\n <View style={viewSize}>\n <Svg width={width} height={height}>\n <LineChartPath\n color={color}\n inactiveColor={inactiveColor}\n width={strokeWidth}\n {...pathProps}\n />\n {backgroundChildren}\n </Svg>\n </View>\n </LineChartPathContext.Provider>\n <LineChartPathContext.Provider\n value={{\n color,\n isInactive: false,\n isTransitionEnabled: pathProps.isTransitionEnabled ?? true,\n }}\n >\n <View style={StyleSheet.absoluteFill}>\n <AnimatedSVG animatedProps={svgProps} height={height}>\n <LineChartPath color={color} width={strokeWidth} {...pathProps} />\n {foregroundChildren}\n </AnimatedSVG>\n </View>\n </LineChartPathContext.Provider>\n </>\n );\n}\n"]}
1
+ {"version":3,"sources":["ChartPath.tsx"],"names":["BACKGROUND_COMPONENTS","FOREGROUND_COMPONENTS","AnimatedSVG","Animated","createAnimatedComponent","Svg","LineChartPathContext","React","createContext","color","isInactive","isTransitionEnabled","LineChartPathWrapper","displayName","animationDuration","animationProps","children","inactiveColor","width","strokeWidth","widthOffset","pathProps","showInactivePath","animateOnMount","mountAnimationDuration","mountAnimationProps","height","pathWidth","useContext","LineChartDimensionsContext","currentX","isActive","isMounted","hasMountedAnimation","useEffect","value","svgProps","shouldAnimateOnMount","inactiveWidth","duration","props","Math","max","Object","assign","viewSize","useMemo","backgroundChildren","foregroundChildren","iterableChildren","filter","child","includes","type","StyleSheet","absoluteFill"],"mappings":";;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAMA;;AAEA;;AACA;;AACA;;;;;;;;;;AAEA,MAAMA,qBAAqB,GAAG,CAC5B,oBAD4B,EAE5B,yBAF4B,EAG5B,mBAH4B,EAI5B,cAJ4B,CAA9B;AAMA,MAAMC,qBAAqB,GAAG,CAAC,oBAAD,EAAuB,cAAvB,CAA9B;;AAEA,MAAMC,WAAW,GAAGC,+BAASC,uBAAT,CAAiCC,mBAAjC,CAApB;;AAEO,MAAMC,oBAAoB,gBAAGC,KAAK,CAACC,aAAN,CAAoB;AACtDC,EAAAA,KAAK,EAAE,EAD+C;AAEtDC,EAAAA,UAAU,EAAE,KAF0C;AAGtDC,EAAAA,mBAAmB,EAAE;AAHiC,CAApB,CAA7B;;AAqBPC,oBAAoB,CAACC,WAArB,GAAmC,sBAAnC;;AAEO,SAASD,oBAAT,CAA8B;AACnCE,EAAAA,iBAAiB,GAAG,GADe;AAEnCC,EAAAA,cAAc,GAAG,EAFkB;AAGnCC,EAAAA,QAHmC;AAInCP,EAAAA,KAAK,GAAG,OAJ2B;AAKnCQ,EAAAA,aALmC;AAMnCC,EAAAA,KAAK,EAAEC,WAAW,GAAG,CANc;AAOnCC,EAAAA,WAAW,GAAG,EAPqB;AAQnCC,EAAAA,SAAS,GAAG,EARuB;AASnCC,EAAAA,gBAAgB,GAAG,IATgB;AAUnCC,EAAAA,cAVmC;AAWnCC,EAAAA,sBAAsB,GAAGV,iBAXU;AAYnCW,EAAAA,mBAAmB,GAAGV;AAZa,CAA9B,EAauB;AAAA;;AAC5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,aAFjB;AAGE,IAAA,KAAK,EAAEE;AAHT,KAIME,SAJN,EADF,EAOG0B,kBAPH,CADF,CAPF,CADF,eAoBE,oBAAC,oBAAD,CAAsB,QAAtB;AACE,IAAA,KAAK,EAAE;AACLtC,MAAAA,KADK;AAELC,MAAAA,UAAU,EAAE,KAFP;AAGLC,MAAAA,mBAAmB,4BAAEU,SAAS,CAACV,mBAAZ,2EAAmC;AAHjD;AADT,kBAOE,oBAAC,iBAAD;AAAM,IAAA,KAAK,EAAE2C,wBAAWC;AAAxB,kBACE,oBAAC,WAAD;AAAa,IAAA,aAAa,EAAEnB,QAA5B;AAAsC,IAAA,MAAM,EAAEV;AAA9C,kBACE,oBAAC,mBAAD;AAAe,IAAA,KAAK,EAAEjB,KAAtB;AAA6B,IAAA,KAAK,EAAEU;AAApC,KAAqDE,SAArD,EADF,EAEG2B,kBAFH,CADF,CAPF,CApBF,CADF;AAqCD","sourcesContent":["import * as React from 'react';\nimport { StyleSheet, View } from 'react-native';\nimport { Svg } from 'react-native-svg';\nimport Animated, {\n useAnimatedProps,\n useSharedValue,\n withTiming,\n WithTimingConfig,\n} from 'react-native-reanimated';\nimport flattenChildren from 'react-keyed-flatten-children';\n\nimport { LineChartDimensionsContext } from './Chart';\nimport { LineChartPath, LineChartPathProps } from './Path';\nimport { useLineChart } from './useLineChart';\n\nconst BACKGROUND_COMPONENTS = [\n 'LineChartHighlight',\n 'LineChartHorizontalLine',\n 'LineChartGradient',\n 'LineChartDot',\n];\nconst FOREGROUND_COMPONENTS = ['LineChartHighlight', 'LineChartDot'];\n\nconst AnimatedSVG = Animated.createAnimatedComponent(Svg);\n\nexport const LineChartPathContext = React.createContext({\n color: '',\n isInactive: false,\n isTransitionEnabled: true,\n});\n\ntype LineChartPathWrapperProps = {\n animationDuration?: number;\n animationProps?: Omit<Partial<WithTimingConfig>, 'duration'>;\n children?: React.ReactNode;\n color?: string;\n inactiveColor?: string;\n width?: number;\n widthOffset?: number;\n pathProps?: Partial<LineChartPathProps>;\n showInactivePath?: boolean;\n animateOnMount?: 'foreground';\n mountAnimationDuration?: number;\n mountAnimationProps?: Partial<WithTimingConfig>;\n};\n\nLineChartPathWrapper.displayName = 'LineChartPathWrapper';\n\nexport function LineChartPathWrapper({\n animationDuration = 300,\n animationProps = {},\n children,\n color = 'black',\n inactiveColor,\n width: strokeWidth = 3,\n widthOffset = 20,\n pathProps = {},\n showInactivePath = true,\n animateOnMount,\n mountAnimationDuration = animationDuration,\n mountAnimationProps = animationProps,\n}: LineChartPathWrapperProps) {\n const { height, pathWidth, width } = React.useContext(\n LineChartDimensionsContext\n );\n const { currentX, isActive } = useLineChart();\n const isMounted = useSharedValue(false);\n const hasMountedAnimation = useSharedValue(false);\n\n React.useEffect(() => {\n isMounted.value = true;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n ////////////////////////////////////////////////\n\n const svgProps = useAnimatedProps(() => {\n const shouldAnimateOnMount = animateOnMount === 'foreground';\n const inactiveWidth =\n !isMounted.value && shouldAnimateOnMount ? 0 : pathWidth;\n\n let duration =\n shouldAnimateOnMount && !hasMountedAnimation.value\n ? mountAnimationDuration\n : animationDuration;\n const props =\n shouldAnimateOnMount && !hasMountedAnimation.value\n ? mountAnimationProps\n : animationProps;\n\n if (isActive.value) {\n duration = 0;\n }\n\n return {\n width: withTiming(\n isActive.value\n ? // on Web, <svg /> elements don't support negative widths\n // https://github.com/coinjar/react-native-wagmi-charts/issues/24#issuecomment-955789904\n Math.max(currentX.value, 0)\n : inactiveWidth + widthOffset,\n Object.assign({ duration }, props),\n () => {\n hasMountedAnimation.value = true;\n }\n ),\n };\n });\n\n const viewSize = React.useMemo(() => ({ width, height }), [width, height]);\n\n ////////////////////////////////////////////////\n\n let backgroundChildren;\n let foregroundChildren;\n if (children) {\n const iterableChildren = flattenChildren(children);\n backgroundChildren = iterableChildren.filter((child) =>\n // @ts-ignore\n BACKGROUND_COMPONENTS.includes(child?.type?.displayName)\n );\n foregroundChildren = iterableChildren.filter((child) =>\n // @ts-ignore\n FOREGROUND_COMPONENTS.includes(child?.type?.displayName)\n );\n }\n\n ////////////////////////////////////////////////\n\n return (\n <>\n <LineChartPathContext.Provider\n value={{\n color,\n isInactive: showInactivePath,\n isTransitionEnabled: pathProps.isTransitionEnabled ?? true,\n }}\n >\n <View style={viewSize}>\n <Svg width={width} height={height}>\n <LineChartPath\n color={color}\n inactiveColor={inactiveColor}\n width={strokeWidth}\n {...pathProps}\n />\n {backgroundChildren}\n </Svg>\n </View>\n </LineChartPathContext.Provider>\n <LineChartPathContext.Provider\n value={{\n color,\n isInactive: false,\n isTransitionEnabled: pathProps.isTransitionEnabled ?? true,\n }}\n >\n <View style={StyleSheet.absoluteFill}>\n <AnimatedSVG animatedProps={svgProps} height={height}>\n <LineChartPath color={color} width={strokeWidth} {...pathProps} />\n {foregroundChildren}\n </AnimatedSVG>\n </View>\n </LineChartPathContext.Provider>\n </>\n );\n}\n"]}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.LineChartHoverTrap = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ const LineChartHoverTrap = () => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
13
+
14
+ exports.LineChartHoverTrap = LineChartHoverTrap;
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.tsx"],"names":["LineChartHoverTrap"],"mappings":";;;;;;;AAAA;;;;AAEO,MAAMA,kBAAkB,GAAG,mBAAM,2DAAjC","sourcesContent":["import React from 'react';\n\nexport const LineChartHoverTrap = () => <></>;\n"]}
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.LineChartHoverTrap = void 0;
7
+
8
+ var React = _interopRequireWildcard(require("react"));
9
+
10
+ var _reactNative = require("react-native");
11
+
12
+ var _reactNativeRedash = require("react-native-redash");
13
+
14
+ var _Chart = require("../Chart");
15
+
16
+ var _useLineChart = require("../useLineChart");
17
+
18
+ var _ExecutionEnvironment = require("fbjs/lib/ExecutionEnvironment");
19
+
20
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
+
22
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
+
24
+ // @ts-expect-error missing types
25
+ let isEnabled = false; // the following logic comes from the creator of react-native-web
26
+ // https://gist.github.com/necolas/1c494e44e23eb7f8c5864a2fac66299a
27
+ // it's also used by MotiPressable's hover interactions
28
+ // https://github.com/nandorojo/moti/blob/master/packages/interactions/src/pressable/hoverable.tsx
29
+
30
+ if (_ExecutionEnvironment.canUseDOM) {
31
+ /**
32
+ * Web browsers emulate mouse events (and hover states) after touch events.
33
+ * This code infers when the currently-in-use modality supports hover
34
+ * (including for multi-modality devices) and considers "hover" to be enabled
35
+ * if a mouse movement occurs more than 1 second after the last touch event.
36
+ * This threshold is long enough to account for longer delays between the
37
+ * browser firing touch and mouse events on low-powered devices.
38
+ */
39
+ const HOVER_THRESHOLD_MS = 1000;
40
+ let lastTouchTimestamp = 0;
41
+
42
+ function enableHover() {
43
+ if (isEnabled || Date.now() - lastTouchTimestamp < HOVER_THRESHOLD_MS) {
44
+ return;
45
+ }
46
+
47
+ isEnabled = true;
48
+ }
49
+
50
+ function disableHover() {
51
+ lastTouchTimestamp = Date.now();
52
+
53
+ if (isEnabled) {
54
+ isEnabled = false;
55
+ }
56
+ }
57
+
58
+ document.addEventListener('touchstart', disableHover, true);
59
+ document.addEventListener('touchmove', disableHover, true);
60
+ document.addEventListener('mousemove', enableHover, true);
61
+ }
62
+
63
+ function isHoverEnabled() {
64
+ return isEnabled;
65
+ }
66
+
67
+ const LineChartHoverTrap = () => {
68
+ const {
69
+ width,
70
+ path
71
+ } = React.useContext(_Chart.LineChartDimensionsContext);
72
+ const {
73
+ currentX,
74
+ currentIndex,
75
+ isActive,
76
+ data
77
+ } = (0, _useLineChart.useLineChart)();
78
+ const parsedPath = React.useMemo(() => path ? (0, _reactNativeRedash.parse)(path) : undefined, [path]);
79
+ const onMouseMove = React.useCallback(({
80
+ x
81
+ }) => {
82
+ if (isHoverEnabled()) {
83
+ if (parsedPath) {
84
+ const boundedX = Math.min(x, width);
85
+ isActive.value = true;
86
+ currentX.value = boundedX; // on Web, we could drag the cursor to be negative, breaking it
87
+ // so we clamp the index at 0 to fix it
88
+ // https://github.com/coinjar/react-native-wagmi-charts/issues/24
89
+
90
+ const minIndex = 0;
91
+ const boundedIndex = Math.max(minIndex, Math.round(boundedX / width / (1 / (data.length - 1))));
92
+ currentIndex.value = boundedIndex;
93
+ }
94
+ } else {
95
+ isActive.value = false;
96
+ currentIndex.value = -1;
97
+ }
98
+ }, [currentIndex, currentX, data.length, isActive, parsedPath, width]);
99
+ const onMouseLeave = React.useCallback(() => {
100
+ isActive.value = false;
101
+ currentIndex.value = -1;
102
+ }, [currentIndex, isActive]);
103
+ return /*#__PURE__*/React.createElement(_reactNative.View, {
104
+ style: _reactNative.StyleSheet.absoluteFill // @ts-expect-error mouse move event
105
+ ,
106
+ onMouseMove: React.useCallback( // eslint-disable-next-line no-undef
107
+ e => {
108
+ let rect = e.currentTarget.getBoundingClientRect();
109
+ let x = e.clientX - rect.left; // x position within the element.
110
+
111
+ onMouseMove({
112
+ x
113
+ });
114
+ }, [onMouseMove]),
115
+ onMouseLeave: onMouseLeave
116
+ });
117
+ };
118
+
119
+ exports.LineChartHoverTrap = LineChartHoverTrap;
120
+ //# sourceMappingURL=index.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.web.tsx"],"names":["isEnabled","canUseDOM","HOVER_THRESHOLD_MS","lastTouchTimestamp","enableHover","Date","now","disableHover","document","addEventListener","isHoverEnabled","LineChartHoverTrap","width","path","React","useContext","LineChartDimensionsContext","currentX","currentIndex","isActive","data","parsedPath","useMemo","undefined","onMouseMove","useCallback","x","boundedX","Math","min","value","minIndex","boundedIndex","max","round","length","onMouseLeave","StyleSheet","absoluteFill","e","rect","currentTarget","getBoundingClientRect","clientX","left"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;AAGA;;;;;;AADA;AAGA,IAAIA,SAAS,GAAG,KAAhB,C,CAEA;AACA;AACA;AACA;;AACA,IAAIC,+BAAJ,EAAe;AACb;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACE,QAAMC,kBAAkB,GAAG,IAA3B;AACA,MAAIC,kBAAkB,GAAG,CAAzB;;AAEA,WAASC,WAAT,GAAuB;AACrB,QAAIJ,SAAS,IAAIK,IAAI,CAACC,GAAL,KAAaH,kBAAb,GAAkCD,kBAAnD,EAAuE;AACrE;AACD;;AACDF,IAAAA,SAAS,GAAG,IAAZ;AACD;;AAED,WAASO,YAAT,GAAwB;AACtBJ,IAAAA,kBAAkB,GAAGE,IAAI,CAACC,GAAL,EAArB;;AACA,QAAIN,SAAJ,EAAe;AACbA,MAAAA,SAAS,GAAG,KAAZ;AACD;AACF;;AAEDQ,EAAAA,QAAQ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AAAA,YAAY,CAACY,KAAb,GAAqBE,YAArB;AACD;AACF,KAjBD,MAiBO;AACLb,MAAAA,QAAQ,CAACW,KAAT,GAAiB,KAAjB;AACAZ,MAAAA,YAAY,CAACY,KAAb,GAAqB,CAAC,CAAtB;AACD;AACF,GAvBiB,EAwBlB,CAACZ,YAAD,EAAeD,QAAf,EAAyBG,IAAI,CAACe,MAA9B,EAAsChB,QAAtC,EAAgDE,UAAhD,EAA4DT,KAA5D,CAxBkB,CAApB;AA2BA,QAAMwB,YAAY,GAAGtB,KAAK,CAACW,WAAN,CAAkB,MAAM;AAC3CN,IAAAA,QAAQ,CAACW,KAAT,GAAiB,KAAjB;AACAZ,IAAAA,YAAY,CAACY,KAAb,GAAqB,CAAC,CAAtB;AACD,GAHoB,EAGlB,CAACZ,YAAD,EAAeC,QAAf,CAHkB,CAArB;AAKA,sBACE,oBAAC,iBAAD;AACE,IAAA,KAAK,EAAEkB,wBAAWC,YADpB,CAEE;AAFF;AAGE,IAAA,WAAW,EAAExB,KAAK,CAACW,WAAN,EACX;AACCc,IAAAA,CAAD,IAAsC;AACpC,UAAIC,IAAI,GAAGD,CAAC,CAACE,aAAF,CAAgBC,qBAAhB,EAAX;AACA,UAAIhB,CAAC,GAAGa,CAAC,CAACI,OAAF,GAAYH,IAAI,CAACI,IAAzB,CAFoC,CAEL;;AAE/BpB,MAAAA,WAAW,CAAC;AAAEE,QAAAA;AAAF,OAAD,CAAX;AACD,KAPU,EAQX,CAACF,WAAD,CARW,CAHf;AAaE,IAAA,YAAY,EAAEY;AAbhB,IADF;AAiBD,CA1DM","sourcesContent":["import * as React from 'react';\nimport { View, StyleSheet } from 'react-native';\nimport { parse } from 'react-native-redash';\n\nimport { LineChartDimensionsContext } from '../Chart';\nimport { useLineChart } from '../useLineChart';\n\n// @ts-expect-error missing types\nimport { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';\n\nlet isEnabled = false;\n\n// the following logic comes from the creator of react-native-web\n// https://gist.github.com/necolas/1c494e44e23eb7f8c5864a2fac66299a\n// it's also used by MotiPressable's hover interactions\n// https://github.com/nandorojo/moti/blob/master/packages/interactions/src/pressable/hoverable.tsx\nif (canUseDOM) {\n /**\n * Web browsers emulate mouse events (and hover states) after touch events.\n * This code infers when the currently-in-use modality supports hover\n * (including for multi-modality devices) and considers \"hover\" to be enabled\n * if a mouse movement occurs more than 1 second after the last touch event.\n * This threshold is long enough to account for longer delays between the\n * browser firing touch and mouse events on low-powered devices.\n */\n const HOVER_THRESHOLD_MS = 1000;\n let lastTouchTimestamp = 0;\n\n function enableHover() {\n if (isEnabled || Date.now() - lastTouchTimestamp < HOVER_THRESHOLD_MS) {\n return;\n }\n isEnabled = true;\n }\n\n function disableHover() {\n lastTouchTimestamp = Date.now();\n if (isEnabled) {\n isEnabled = false;\n }\n }\n\n document.addEventListener('touchstart', disableHover, true);\n document.addEventListener('touchmove', disableHover, true);\n document.addEventListener('mousemove', enableHover, true);\n}\n\nfunction isHoverEnabled(): boolean {\n return isEnabled;\n}\n\nexport const LineChartHoverTrap = () => {\n const { width, path } = React.useContext(LineChartDimensionsContext);\n const { currentX, currentIndex, isActive, data } = useLineChart();\n\n const parsedPath = React.useMemo(\n () => (path ? parse(path) : undefined),\n [path]\n );\n\n const onMouseMove = React.useCallback(\n ({ x }: { x: number }) => {\n if (isHoverEnabled()) {\n if (parsedPath) {\n const boundedX = Math.min(x, width);\n isActive.value = true;\n currentX.value = boundedX;\n\n // on Web, we could drag the cursor to be negative, breaking it\n // so we clamp the index at 0 to fix it\n // https://github.com/coinjar/react-native-wagmi-charts/issues/24\n const minIndex = 0;\n const boundedIndex = Math.max(\n minIndex,\n Math.round(boundedX / width / (1 / (data.length - 1)))\n );\n\n currentIndex.value = boundedIndex;\n }\n } else {\n isActive.value = false;\n currentIndex.value = -1;\n }\n },\n [currentIndex, currentX, data.length, isActive, parsedPath, width]\n );\n\n const onMouseLeave = React.useCallback(() => {\n isActive.value = false;\n currentIndex.value = -1;\n }, [currentIndex, isActive]);\n\n return (\n <View\n style={StyleSheet.absoluteFill}\n // @ts-expect-error mouse move event\n onMouseMove={React.useCallback(\n // eslint-disable-next-line no-undef\n (e: React.MouseEvent<HTMLElement>) => {\n let rect = e.currentTarget.getBoundingClientRect();\n let x = e.clientX - rect.left; // x position within the element.\n\n onMouseMove({ x });\n },\n [onMouseMove]\n )}\n onMouseLeave={onMouseLeave}\n />\n );\n};\n"]}
@@ -222,6 +222,8 @@ Object.keys(_useLineChart).forEach(function (key) {
222
222
  });
223
223
  });
224
224
 
225
+ var _HoverTrap = require("../line/HoverTrap");
226
+
225
227
  var _Path = require("./Path");
226
228
 
227
229
  Object.keys(_Path).forEach(function (key) {
@@ -266,7 +268,8 @@ const LineChart = Object.assign(_Chart.LineChart, {
266
268
  DatetimeText: _DatetimeText.LineChartDatetimeText,
267
269
  useDatetime: _useDatetime.useLineChartDatetime,
268
270
  usePrice: _usePrice.useLineChartPrice,
269
- useChart: _useLineChart.useLineChart
271
+ useChart: _useLineChart.useLineChart,
272
+ HoverTrap: _HoverTrap.LineChartHoverTrap
270
273
  });
271
274
  exports.LineChart = LineChart;
272
275
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":["LineChart","Object","assign","_LineChart","Chart","Dot","LineChartDot","Path","LineChartPathWrapper","Cursor","LineChartCursor","CursorCrosshair","LineChartCursorCrosshair","CursorLine","LineChartCursorLine","Gradient","LineChartGradient","Group","LineChartGroup","Highlight","LineChartHighlight","HorizontalLine","LineChartHorizontalLine","Tooltip","LineChartTooltip","Provider","LineChartProvider","PriceText","LineChartPriceText","DatetimeText","LineChartDatetimeText","useDatetime","useLineChartDatetime","usePrice","useLineChartPrice","useChart","useLineChart"],"mappings":";;;;;;;;;;AAAA;;AAkBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAjBA;;AAkBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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B;AACjDC,EAAAA,KAAK,EAAED,gBAD0C;AAEjDE,EAAAA,GAAG,EAAEC,iBAF4C;AAGjDC,EAAAA,IAAI,EAAEC,+BAH2C;AAIjDC,EAAAA,MAAM,EAAEC,uBAJyC;AAKjDC,EAAAA,eAAe,EAAEC,yCALgC;AAMjDC,EAAAA,UAAU,EAAEC,+BANqC;AAOjDC,EAAAA,QAAQ,EAAEC,2BAPuC;AAQjDC,EAAAA,KAAK,EAAEC,qBAR0C;AASjDC,EAAAA,SAAS,EAAEC,6BATsC;AAUjDC,EAAAA,cAAc,EAAEC,uCAViC;AAWjDC,EAAAA,OAAO,EAAEC,yBAXwC;AAYjDC,EAAAA,QAAQ,EAAEC,0BAZuC;AAajDC,EAAAA,SAAS,EAAEC,6BAbsC;AAcjDC,EAAAA,YAAY,EAAEC,mCAdmC;AAejDC,EAAAA,WAAW,EAAEC,iCAfoC;AAgBjDC,EAAAA,QAAQ,EAAEC,2BAhBuC;AAiBjDC,EAAAA,QAAQ,EAAEC;AAjBuC,CAA1B,CAAlB","sourcesContent":["import { LineChart as _LineChart } from './Chart';\nimport { LineChartPathWrapper } from './ChartPath';\nimport { LineChartHighlight } from './Highlight';\nimport { LineChartProvider } from './Context';\nimport { LineChartCursor } from './Cursor';\nimport { LineChartCursorCrosshair } from './CursorCrosshair';\nimport { LineChartCursorLine } from './CursorLine';\nimport { LineChartDot } from './Dot';\nimport { LineChartGradient } from './Gradient';\nimport { LineChartGroup } from './Group';\nimport { LineChartHorizontalLine } from './HorizontalLine';\nimport { LineChartTooltip } from './Tooltip';\nimport { LineChartPriceText } from './PriceText';\nimport { LineChartDatetimeText } from './DatetimeText';\nimport { useLineChartDatetime } from './useDatetime';\nimport { useLineChartPrice } from './usePrice';\nimport { useLineChart } from './useLineChart';\n\nexport * from './Chart';\nexport * from './ChartPath';\nexport * from './Highlight';\nexport * from './Context';\nexport * from './Cursor';\nexport * from './CursorCrosshair';\nexport * from './CursorLine';\nexport * from './Dot';\nexport * from './Gradient';\nexport * from './Tooltip';\nexport * from './DatetimeText';\nexport * from './Path';\nexport * from './PriceText';\nexport * from './useDatetime';\nexport * from './useLineChart';\nexport * from './usePrice';\nexport * from './types';\n\nexport const LineChart = Object.assign(_LineChart, {\n Chart: _LineChart,\n Dot: LineChartDot,\n Path: LineChartPathWrapper,\n Cursor: LineChartCursor,\n CursorCrosshair: LineChartCursorCrosshair,\n CursorLine: LineChartCursorLine,\n Gradient: LineChartGradient,\n Group: LineChartGroup,\n Highlight: LineChartHighlight,\n HorizontalLine: LineChartHorizontalLine,\n Tooltip: LineChartTooltip,\n Provider: LineChartProvider,\n PriceText: LineChartPriceText,\n DatetimeText: LineChartDatetimeText,\n useDatetime: useLineChartDatetime,\n usePrice: useLineChartPrice,\n useChart: useLineChart,\n});\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":["LineChart","Object","assign","_LineChart","Chart","Dot","LineChartDot","Path","LineChartPathWrapper","Cursor","LineChartCursor","CursorCrosshair","LineChartCursorCrosshair","CursorLine","LineChartCursorLine","Gradient","LineChartGradient","Group","LineChartGroup","Highlight","LineChartHighlight","HorizontalLine","LineChartHorizontalLine","Tooltip","LineChartTooltip","Provider","LineChartProvider","PriceText","LineChartPriceText","DatetimeText","LineChartDatetimeText","useDatetime","useLineChartDatetime","usePrice","useLineChartPrice","useChart","useLineChart","HoverTrap","LineChartHoverTrap"],"mappings":";;;;;;;;;;AAAA;;AAmBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAlBA;;AAmBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAlBA;;AAmBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAlBA;;AAmBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAlBA;;AAmBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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AEC,+BANqC;AAOjDC,EAAAA,QAAQ,EAAEC,2BAPuC;AAQjDC,EAAAA,KAAK,EAAEC,qBAR0C;AASjDC,EAAAA,SAAS,EAAEC,6BATsC;AAUjDC,EAAAA,cAAc,EAAEC,uCAViC;AAWjDC,EAAAA,OAAO,EAAEC,yBAXwC;AAYjDC,EAAAA,QAAQ,EAAEC,0BAZuC;AAajDC,EAAAA,SAAS,EAAEC,6BAbsC;AAcjDC,EAAAA,YAAY,EAAEC,mCAdmC;AAejDC,EAAAA,WAAW,EAAEC,iCAfoC;AAgBjDC,EAAAA,QAAQ,EAAEC,2BAhBuC;AAiBjDC,EAAAA,QAAQ,EAAEC,0BAjBuC;AAkBjDC,EAAAA,SAAS,EAAEC;AAlBsC,CAA1B,CAAlB","sourcesContent":["import { LineChart as _LineChart } from './Chart';\nimport { LineChartPathWrapper } from './ChartPath';\nimport { LineChartHighlight } from './Highlight';\nimport { LineChartProvider } from './Context';\nimport { LineChartCursor } from './Cursor';\nimport { LineChartCursorCrosshair } from './CursorCrosshair';\nimport { LineChartCursorLine } from './CursorLine';\nimport { LineChartDot } from './Dot';\nimport { LineChartGradient } from './Gradient';\nimport { LineChartGroup } from './Group';\nimport { LineChartHorizontalLine } from './HorizontalLine';\nimport { LineChartTooltip } from './Tooltip';\nimport { LineChartPriceText } from './PriceText';\nimport { LineChartDatetimeText } from './DatetimeText';\nimport { useLineChartDatetime } from './useDatetime';\nimport { useLineChartPrice } from './usePrice';\nimport { useLineChart } from './useLineChart';\nimport { LineChartHoverTrap } from '../line/HoverTrap';\n\nexport * from './Chart';\nexport * from './ChartPath';\nexport * from './Highlight';\nexport * from './Context';\nexport * from './Cursor';\nexport * from './CursorCrosshair';\nexport * from './CursorLine';\nexport * from './Dot';\nexport * from './Gradient';\nexport * from './Tooltip';\nexport * from './DatetimeText';\nexport * from './Path';\nexport * from './PriceText';\nexport * from './useDatetime';\nexport * from './useLineChart';\nexport * from './usePrice';\nexport * from './types';\n\nexport const LineChart = Object.assign(_LineChart, {\n Chart: _LineChart,\n Dot: LineChartDot,\n Path: LineChartPathWrapper,\n Cursor: LineChartCursor,\n CursorCrosshair: LineChartCursorCrosshair,\n CursorLine: LineChartCursorLine,\n Gradient: LineChartGradient,\n Group: LineChartGroup,\n Highlight: LineChartHighlight,\n HorizontalLine: LineChartHorizontalLine,\n Tooltip: LineChartTooltip,\n Provider: LineChartProvider,\n PriceText: LineChartPriceText,\n DatetimeText: LineChartDatetimeText,\n useDatetime: useLineChartDatetime,\n usePrice: useLineChartPrice,\n useChart: useLineChart,\n HoverTrap: LineChartHoverTrap,\n});\n"]}
@@ -28,7 +28,8 @@ const AnimatedText = ({
28
28
  text,
29
29
  style
30
30
  }) => {
31
- const inputRef = _react.default.useRef(null);
31
+ const inputRef = _react.default.useRef(null); // eslint-disable-line @typescript-eslint/no-explicit-any
32
+
32
33
 
33
34
  if (_reactNative.Platform.OS === 'web') {
34
35
  // For some reason, the worklet reaction evaluates upfront regardless of any
@@ -40,10 +41,7 @@ const AnimatedText = ({
40
41
  return text.value;
41
42
  }, (data, prevData) => {
42
43
  if (data !== prevData && inputRef.current) {
43
- inputRef.current.setNativeProps({
44
- value: data,
45
- style
46
- });
44
+ inputRef.current.value = data;
47
45
  }
48
46
  });
49
47
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["AnimatedText.tsx"],"names":["Animated","addWhitelistedNativeProps","text","AnimatedTextInput","createAnimatedComponent","TextInput","AnimatedText","style","inputRef","React","useRef","Platform","OS","value","data","prevData","current","setNativeProps","animatedProps","select","web","styles","StyleSheet","create","color"],"mappings":";;;;;;;AAEA;;AACA;;AAEA;;;;;;;;AALA;AAUAA,+BAASC,yBAAT,CAAmC;AAAEC,EAAAA,IAAI,EAAE;AAAR,CAAnC;;AAOA,MAAMC,iBAAiB,GAAGH,+BAASI,uBAAT,CAAiCC,sBAAjC,CAA1B;;AAEO,MAAMC,YAAY,GAAG,CAAC;AAAEJ,EAAAA,IAAF;AAAQK,EAAAA;AAAR,CAAD,KAAwC;AAClE,QAAMC,QAAQ,GAAGC,eAAMC,MAAN,CAAwB,IAAxB,CAAjB;;AAEA,MAAIC,sBAASC,EAAT,KAAgB,KAApB,EAA2B;AACzB;AACA;AACA;AACA;AAEA;AACA,oDACE,MAAM;AACJ,aAAOV,IAAI,CAACW,KAAZ;AACD,KAHH,EAIE,CAACC,IAAD,EAAOC,QAAP,KAAoB;AAClB,UAAID,IAAI,KAAKC,QAAT,IAAqBP,QAAQ,CAACQ,OAAlC,EAA2C;AACzCR,QAAAA,QAAQ,CAACQ,OAAT,CAAiBC,cAAjB,CAAgC;AAC9BJ,UAAAA,KAAK,EAAEC,IADuB;AAE9BP,UAAAA;AAF8B,SAAhC;AAID;AACF,KAXH;AAaD;;AACD,QAAMW,aAAa,GAAG,6CAAiB,MAAM;AAC3C,WAAO;AACLhB,MAAAA,IAAI,EAAEA,IAAI,CAACW,KADN,CAEL;AACA;;AAHK,KAAP;AAKD,GANqB,CAAtB;AAOA,sBACE,6BAAC,iBAAD;AACE,IAAA,qBAAqB,EAAC,aADxB;AAEE,IAAA,QAAQ,EAAE,KAFZ;AAGE,IAAA,GAAG,EAAEF,sBAASQ,MAAT,CAAgB;AAAEC,MAAAA,GAAG,EAAEZ;AAAP,KAAhB,CAHP;AAIE,IAAA,KAAK,EAAEN,IAAI,CAACW,KAJd;AAKE,IAAA,KAAK,EAAE,CAACQ,MAAM,CAACnB,IAAR,EAAcK,KAAd,CALT;AAME,IAAA,aAAa,EAAEW;AANjB,IADF;AAUD,CAzCM;;;;AA2CP,MAAMG,MAAM,GAAGC,wBAAWC,MAAX,CAAkB;AAC/BrB,EAAAA,IAAI,EAAE;AACJsB,IAAAA,KAAK,EAAE;AADH;AADyB,CAAlB,CAAf","sourcesContent":["// forked from https://github.com/wcandillon/react-native-redash/blob/master/src/ReText.tsx\n\nimport React from 'react';\nimport { Platform, StyleSheet, TextProps as RNTextProps } from 'react-native';\nimport { TextInput } from 'react-native';\nimport Animated, {\n useAnimatedProps,\n useAnimatedReaction,\n} from 'react-native-reanimated';\n\nAnimated.addWhitelistedNativeProps({ text: true });\n\ninterface AnimatedTextProps {\n text: Animated.SharedValue<string>;\n style?: Animated.AnimateProps<RNTextProps>['style'];\n}\n\nconst AnimatedTextInput = Animated.createAnimatedComponent(TextInput);\n\nexport const AnimatedText = ({ text, style }: AnimatedTextProps) => {\n const inputRef = React.useRef<TextInput>(null);\n\n if (Platform.OS === 'web') {\n // For some reason, the worklet reaction evaluates upfront regardless of any\n // conditionals within it, causing Android to crash upon the invokation of `setNativeProps`.\n // We are going to break the rules of hooks here so it doesn't invoke `useAnimatedReaction`\n // for platforms outside of the web.\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useAnimatedReaction(\n () => {\n return text.value;\n },\n (data, prevData) => {\n if (data !== prevData && inputRef.current) {\n inputRef.current.setNativeProps({\n value: data,\n style,\n });\n }\n }\n );\n }\n const animatedProps = useAnimatedProps(() => {\n return {\n text: text.value,\n // Here we use any because the text prop is not available in the type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any;\n });\n return (\n <AnimatedTextInput\n underlineColorAndroid=\"transparent\"\n editable={false}\n ref={Platform.select({ web: inputRef })}\n value={text.value}\n style={[styles.text, style]}\n animatedProps={animatedProps}\n />\n );\n};\n\nconst styles = StyleSheet.create({\n text: {\n color: 'black',\n },\n});\n"]}
1
+ {"version":3,"sources":["AnimatedText.tsx"],"names":["Animated","addWhitelistedNativeProps","text","AnimatedTextInput","createAnimatedComponent","TextInput","AnimatedText","style","inputRef","React","useRef","Platform","OS","value","data","prevData","current","animatedProps","select","web","styles","StyleSheet","create","color"],"mappings":";;;;;;;AAEA;;AACA;;AAEA;;;;;;;;AALA;AAUAA,+BAASC,yBAAT,CAAmC;AAAEC,EAAAA,IAAI,EAAE;AAAR,CAAnC;;AAOA,MAAMC,iBAAiB,GAAGH,+BAASI,uBAAT,CAAiCC,sBAAjC,CAA1B;;AAEO,MAAMC,YAAY,GAAG,CAAC;AAAEJ,EAAAA,IAAF;AAAQK,EAAAA;AAAR,CAAD,KAAwC;AAClE,QAAMC,QAAQ,GAAGC,eAAMC,MAAN,CAAkB,IAAlB,CAAjB,CADkE,CACxB;;;AAE1C,MAAIC,sBAASC,EAAT,KAAgB,KAApB,EAA2B;AACzB;AACA;AACA;AACA;AAEA;AACA,oDACE,MAAM;AACJ,aAAOV,IAAI,CAACW,KAAZ;AACD,KAHH,EAIE,CAACC,IAAD,EAAOC,QAAP,KAAoB;AAClB,UAAID,IAAI,KAAKC,QAAT,IAAqBP,QAAQ,CAACQ,OAAlC,EAA2C;AACzCR,QAAAA,QAAQ,CAACQ,OAAT,CAAiBH,KAAjB,GAAyBC,IAAzB;AACD;AACF,KARH;AAUD;;AACD,QAAMG,aAAa,GAAG,6CAAiB,MAAM;AAC3C,WAAO;AACLf,MAAAA,IAAI,EAAEA,IAAI,CAACW,KADN,CAEL;AACA;;AAHK,KAAP;AAKD,GANqB,CAAtB;AAOA,sBACE,6BAAC,iBAAD;AACE,IAAA,qBAAqB,EAAC,aADxB;AAEE,IAAA,QAAQ,EAAE,KAFZ;AAGE,IAAA,GAAG,EAAEF,sBAASO,MAAT,CAAgB;AAAEC,MAAAA,GAAG,EAAEX;AAAP,KAAhB,CAHP;AAIE,IAAA,KAAK,EAAEN,IAAI,CAACW,KAJd;AAKE,IAAA,KAAK,EAAE,CAACO,MAAM,CAAClB,IAAR,EAAcK,KAAd,CALT;AAME,IAAA,aAAa,EAAEU;AANjB,IADF;AAUD,CAtCM;;;;AAwCP,MAAMG,MAAM,GAAGC,wBAAWC,MAAX,CAAkB;AAC/BpB,EAAAA,IAAI,EAAE;AACJqB,IAAAA,KAAK,EAAE;AADH;AADyB,CAAlB,CAAf","sourcesContent":["// forked from https://github.com/wcandillon/react-native-redash/blob/master/src/ReText.tsx\n\nimport React from 'react';\nimport { Platform, StyleSheet, TextProps as RNTextProps } from 'react-native';\nimport { TextInput } from 'react-native';\nimport Animated, {\n useAnimatedProps,\n useAnimatedReaction,\n} from 'react-native-reanimated';\n\nAnimated.addWhitelistedNativeProps({ text: true });\n\ninterface AnimatedTextProps {\n text: Animated.SharedValue<string>;\n style?: Animated.AnimateProps<RNTextProps>['style'];\n}\n\nconst AnimatedTextInput = Animated.createAnimatedComponent(TextInput);\n\nexport const AnimatedText = ({ text, style }: AnimatedTextProps) => {\n const inputRef = React.useRef<any>(null); // eslint-disable-line @typescript-eslint/no-explicit-any\n\n if (Platform.OS === 'web') {\n // For some reason, the worklet reaction evaluates upfront regardless of any\n // conditionals within it, causing Android to crash upon the invokation of `setNativeProps`.\n // We are going to break the rules of hooks here so it doesn't invoke `useAnimatedReaction`\n // for platforms outside of the web.\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useAnimatedReaction(\n () => {\n return text.value;\n },\n (data, prevData) => {\n if (data !== prevData && inputRef.current) {\n inputRef.current.value = data;\n }\n }\n );\n }\n const animatedProps = useAnimatedProps(() => {\n return {\n text: text.value,\n // Here we use any because the text prop is not available in the type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any;\n });\n return (\n <AnimatedTextInput\n underlineColorAndroid=\"transparent\"\n editable={false}\n ref={Platform.select({ web: inputRef })}\n value={text.value}\n style={[styles.text, style]}\n animatedProps={animatedProps}\n />\n );\n};\n\nconst styles = StyleSheet.create({\n text: {\n color: 'black',\n },\n});\n"]}
@@ -0,0 +1,101 @@
1
+ import * as React from 'react';
2
+ import { View, StyleSheet } from 'react-native';
3
+ import { parse } from 'react-native-redash';
4
+ import { LineChartDimensionsContext } from '../../line/Chart';
5
+ import { useLineChart } from '../../line/useLineChart'; // @ts-expect-error missing types
6
+
7
+ import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
8
+ let isEnabled = false; // the following logic comes from the creator of react-native-web
9
+ // https://gist.github.com/necolas/1c494e44e23eb7f8c5864a2fac66299a
10
+ // it's also used by MotiPressable's hover interactions
11
+ // https://github.com/nandorojo/moti/blob/master/packages/interactions/src/pressable/hoverable.tsx
12
+
13
+ if (canUseDOM) {
14
+ /**
15
+ * Web browsers emulate mouse events (and hover states) after touch events.
16
+ * This code infers when the currently-in-use modality supports hover
17
+ * (including for multi-modality devices) and considers "hover" to be enabled
18
+ * if a mouse movement occurs more than 1 second after the last touch event.
19
+ * This threshold is long enough to account for longer delays between the
20
+ * browser firing touch and mouse events on low-powered devices.
21
+ */
22
+ const HOVER_THRESHOLD_MS = 1000;
23
+ let lastTouchTimestamp = 0;
24
+
25
+ function enableHover() {
26
+ if (isEnabled || Date.now() - lastTouchTimestamp < HOVER_THRESHOLD_MS) {
27
+ return;
28
+ }
29
+
30
+ isEnabled = true;
31
+ }
32
+
33
+ function disableHover() {
34
+ lastTouchTimestamp = Date.now();
35
+
36
+ if (isEnabled) {
37
+ isEnabled = false;
38
+ }
39
+ }
40
+
41
+ document.addEventListener('touchstart', disableHover, true);
42
+ document.addEventListener('touchmove', disableHover, true);
43
+ document.addEventListener('mousemove', enableHover, true);
44
+ }
45
+
46
+ function isHoverEnabled() {
47
+ return isEnabled;
48
+ }
49
+
50
+ export const LineChartHoverTrap = () => {
51
+ const {
52
+ width,
53
+ path
54
+ } = React.useContext(LineChartDimensionsContext);
55
+ const {
56
+ currentX,
57
+ currentIndex,
58
+ isActive,
59
+ data
60
+ } = useLineChart();
61
+ const parsedPath = React.useMemo(() => path ? parse(path) : undefined, [path]);
62
+ const onMouseMove = React.useCallback(({
63
+ x
64
+ }) => {
65
+ if (isHoverEnabled()) {
66
+ if (parsedPath) {
67
+ const boundedX = Math.min(x, width);
68
+ isActive.value = true;
69
+ currentX.value = boundedX; // on Web, we could drag the cursor to be negative, breaking it
70
+ // so we clamp the index at 0 to fix it
71
+ // https://github.com/coinjar/react-native-wagmi-charts/issues/24
72
+
73
+ const minIndex = 0;
74
+ const boundedIndex = Math.max(minIndex, Math.round(boundedX / width / (1 / (data.length - 1))));
75
+ currentIndex.value = boundedIndex;
76
+ }
77
+ } else {
78
+ isActive.value = false;
79
+ currentIndex.value = -1;
80
+ }
81
+ }, [currentIndex, currentX, data.length, isActive, parsedPath, width]);
82
+ const onMouseLeave = React.useCallback(() => {
83
+ isActive.value = false;
84
+ currentIndex.value = -1;
85
+ }, [currentIndex, isActive]);
86
+ return /*#__PURE__*/React.createElement(View, {
87
+ style: StyleSheet.absoluteFill // @ts-expect-error mouse move event
88
+ ,
89
+ onMouseMove: React.useCallback( // eslint-disable-next-line no-undef
90
+ e => {
91
+ let rect = e.currentTarget.getBoundingClientRect();
92
+ let x = e.clientX - rect.left; // x position within the element.
93
+
94
+ onMouseMove({
95
+ x
96
+ });
97
+ }, [onMouseMove]),
98
+ onMouseLeave: onMouseLeave
99
+ });
100
+ };
101
+ //# sourceMappingURL=index.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.web.tsx"],"names":["React","View","StyleSheet","parse","LineChartDimensionsContext","useLineChart","canUseDOM","isEnabled","HOVER_THRESHOLD_MS","lastTouchTimestamp","enableHover","Date","now","disableHover","document","addEventListener","isHoverEnabled","LineChartHoverTrap","width","path","useContext","currentX","currentIndex","isActive","data","parsedPath","useMemo","undefined","onMouseMove","useCallback","x","boundedX","Math","min","value","minIndex","boundedIndex","max","round","length","onMouseLeave","absoluteFill","e","rect","currentTarget","getBoundingClientRect","clientX","left"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,IAAT,EAAeC,UAAf,QAAiC,cAAjC;AACA,SAASC,KAAT,QAAsB,qBAAtB;AAEA,SAASC,0BAAT,QAA2C,kBAA3C;AACA,SAASC,YAAT,QAA6B,yBAA7B,C,CAEA;;AACA,SAASC,SAAT,QAA0B,+BAA1B;AAEA,IAAIC,SAAS,GAAG,KAAhB,C,CAEA;AACA;AACA;AACA;;AACA,IAAID,SAAJ,EAAe;AACb;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACE,QAAME,kBAAkB,GAAG,IAA3B;AACA,MAAIC,kBAAkB,GAAG,CAAzB;;AAEA,WAASC,WAAT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D,CAAX;AACD,KAPU,EAQX,CAACF,WAAD,CARW,CAHf;AAaE,IAAA,YAAY,EAAEY;AAbhB,IADF;AAiBD,CA1DM","sourcesContent":["import * as React from 'react';\nimport { View, StyleSheet } from 'react-native';\nimport { parse } from 'react-native-redash';\n\nimport { LineChartDimensionsContext } from '../../line/Chart';\nimport { useLineChart } from '../../line/useLineChart';\n\n// @ts-expect-error missing types\nimport { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';\n\nlet isEnabled = false;\n\n// the following logic comes from the creator of react-native-web\n// https://gist.github.com/necolas/1c494e44e23eb7f8c5864a2fac66299a\n// it's also used by MotiPressable's hover interactions\n// https://github.com/nandorojo/moti/blob/master/packages/interactions/src/pressable/hoverable.tsx\nif (canUseDOM) {\n /**\n * Web browsers emulate mouse events (and hover states) after touch events.\n * This code infers when the currently-in-use modality supports hover\n * (including for multi-modality devices) and considers \"hover\" to be enabled\n * if a mouse movement occurs more than 1 second after the last touch event.\n * This threshold is long enough to account for longer delays between the\n * browser firing touch and mouse events on low-powered devices.\n */\n const HOVER_THRESHOLD_MS = 1000;\n let lastTouchTimestamp = 0;\n\n function enableHover() {\n if (isEnabled || Date.now() - lastTouchTimestamp < HOVER_THRESHOLD_MS) {\n return;\n }\n isEnabled = true;\n }\n\n function disableHover() {\n lastTouchTimestamp = Date.now();\n if (isEnabled) {\n isEnabled = false;\n }\n }\n\n document.addEventListener('touchstart', disableHover, true);\n document.addEventListener('touchmove', disableHover, true);\n document.addEventListener('mousemove', enableHover, true);\n}\n\nfunction isHoverEnabled(): boolean {\n return isEnabled;\n}\n\nexport const LineChartHoverTrap = () => {\n const { width, path } = React.useContext(LineChartDimensionsContext);\n const { currentX, currentIndex, isActive, data } = useLineChart();\n\n const parsedPath = React.useMemo(\n () => (path ? parse(path) : undefined),\n [path]\n );\n\n const onMouseMove = React.useCallback(\n ({ x }: { x: number }) => {\n if (isHoverEnabled()) {\n if (parsedPath) {\n const boundedX = Math.min(x, width);\n isActive.value = true;\n currentX.value = boundedX;\n\n // on Web, we could drag the cursor to be negative, breaking it\n // so we clamp the index at 0 to fix it\n // https://github.com/coinjar/react-native-wagmi-charts/issues/24\n const minIndex = 0;\n const boundedIndex = Math.max(\n minIndex,\n Math.round(boundedX / width / (1 / (data.length - 1)))\n );\n\n currentIndex.value = boundedIndex;\n }\n } else {\n isActive.value = false;\n currentIndex.value = -1;\n }\n },\n [currentIndex, currentX, data.length, isActive, parsedPath, width]\n );\n\n const onMouseLeave = React.useCallback(() => {\n isActive.value = false;\n currentIndex.value = -1;\n }, [currentIndex, isActive]);\n\n return (\n <View\n style={StyleSheet.absoluteFill}\n // @ts-expect-error mouse move event\n onMouseMove={React.useCallback(\n // eslint-disable-next-line no-undef\n (e: React.MouseEvent<HTMLElement>) => {\n let rect = e.currentTarget.getBoundingClientRect();\n let x = e.clientX - rect.left; // x position within the element.\n\n onMouseMove({ x });\n },\n [onMouseMove]\n )}\n onMouseLeave={onMouseLeave}\n />\n );\n};\n"]}
@@ -51,12 +51,17 @@ export function LineChartPathWrapper({
51
51
  const svgProps = useAnimatedProps(() => {
52
52
  const shouldAnimateOnMount = animateOnMount === 'foreground';
53
53
  const inactiveWidth = !isMounted.value && shouldAnimateOnMount ? 0 : pathWidth;
54
- const duration = shouldAnimateOnMount && !hasMountedAnimation.value ? mountAnimationDuration : animationDuration;
54
+ let duration = shouldAnimateOnMount && !hasMountedAnimation.value ? mountAnimationDuration : animationDuration;
55
55
  const props = shouldAnimateOnMount && !hasMountedAnimation.value ? mountAnimationProps : animationProps;
56
+
57
+ if (isActive.value) {
58
+ duration = 0;
59
+ }
60
+
56
61
  return {
57
- width: isActive.value ? // on Web, <svg /> elements don't support negative widths
62
+ width: withTiming(isActive.value ? // on Web, <svg /> elements don't support negative widths
58
63
  // https://github.com/coinjar/react-native-wagmi-charts/issues/24#issuecomment-955789904
59
- Math.max(currentX.value, 0) : withTiming(inactiveWidth + widthOffset, Object.assign({
64
+ Math.max(currentX.value, 0) : inactiveWidth + widthOffset, Object.assign({
60
65
  duration
61
66
  }, props), () => {
62
67
  hasMountedAnimation.value = true;