@archireport/react-native-svg-draw 1.4.0 → 2.0.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 (130) hide show
  1. package/README.md +73 -27
  2. package/lib/commonjs/components/DrawCore/CurrentAnimatedItem.js +10 -5
  3. package/lib/commonjs/components/DrawCore/CurrentAnimatedItem.js.map +1 -1
  4. package/lib/commonjs/components/DrawCore/CurrentAnimatedText.js.map +1 -1
  5. package/lib/commonjs/components/DrawCore/DrawContext.js +18 -0
  6. package/lib/commonjs/components/DrawCore/DrawContext.js.map +1 -0
  7. package/lib/commonjs/components/DrawCore/DrawPad.js.map +1 -1
  8. package/lib/commonjs/components/DrawCore/DrawProvider.js +103 -0
  9. package/lib/commonjs/components/DrawCore/DrawProvider.js.map +1 -0
  10. package/lib/commonjs/components/DrawCore/Item.js.map +1 -1
  11. package/lib/commonjs/components/DrawCore/index.js +41 -168
  12. package/lib/commonjs/components/DrawCore/index.js.map +1 -1
  13. package/lib/commonjs/components/DrawCore/useDrawHook.js +76 -0
  14. package/lib/commonjs/components/DrawCore/useDrawHook.js.map +1 -0
  15. package/lib/commonjs/components/DrawWithOptions/ArrowSvg.js.map +1 -1
  16. package/lib/commonjs/components/DrawWithOptions/CancelSvg.js.map +1 -1
  17. package/lib/commonjs/components/DrawWithOptions/CircleSvg.js.map +1 -1
  18. package/lib/commonjs/components/DrawWithOptions/CloseSvg.js.map +1 -1
  19. package/lib/commonjs/components/DrawWithOptions/DoubleHeadSvg.js.map +1 -1
  20. package/lib/commonjs/components/DrawWithOptions/PenSvg.js.map +1 -1
  21. package/lib/commonjs/components/DrawWithOptions/SendSvg.js.map +1 -1
  22. package/lib/commonjs/components/DrawWithOptions/SliderSvg.js +31 -0
  23. package/lib/commonjs/components/DrawWithOptions/SliderSvg.js.map +1 -0
  24. package/lib/commonjs/components/DrawWithOptions/SquareSvg.js.map +1 -1
  25. package/lib/commonjs/components/DrawWithOptions/TextSvg.js.map +1 -1
  26. package/lib/commonjs/components/DrawWithOptions/ThrashSvg.js +27 -2
  27. package/lib/commonjs/components/DrawWithOptions/ThrashSvg.js.map +1 -1
  28. package/lib/commonjs/components/DrawWithOptions/index.js +124 -70
  29. package/lib/commonjs/components/DrawWithOptions/index.js.map +1 -1
  30. package/lib/commonjs/components/{DrawCore → Slider}/ColorSlider.js +45 -62
  31. package/lib/commonjs/components/Slider/ColorSlider.js.map +1 -0
  32. package/lib/commonjs/components/Slider/Sliders.js +88 -0
  33. package/lib/commonjs/components/Slider/Sliders.js.map +1 -0
  34. package/lib/commonjs/components/{DrawCore → Slider}/StrokeSlider.js +38 -47
  35. package/lib/commonjs/components/Slider/StrokeSlider.js.map +1 -0
  36. package/lib/commonjs/components/Slider/sliderStyle.js +37 -0
  37. package/lib/commonjs/components/Slider/sliderStyle.js.map +1 -0
  38. package/lib/commonjs/index.js +7 -0
  39. package/lib/commonjs/index.js.map +1 -1
  40. package/lib/module/components/DrawCore/CurrentAnimatedItem.js +10 -5
  41. package/lib/module/components/DrawCore/CurrentAnimatedItem.js.map +1 -1
  42. package/lib/module/components/DrawCore/CurrentAnimatedText.js.map +1 -1
  43. package/lib/module/components/DrawCore/DrawContext.js +11 -0
  44. package/lib/module/components/DrawCore/DrawContext.js.map +1 -0
  45. package/lib/module/components/DrawCore/DrawPad.js.map +1 -1
  46. package/lib/module/components/DrawCore/DrawProvider.js +94 -0
  47. package/lib/module/components/DrawCore/DrawProvider.js.map +1 -0
  48. package/lib/module/components/DrawCore/Item.js.map +1 -1
  49. package/lib/module/components/DrawCore/index.js +43 -170
  50. package/lib/module/components/DrawCore/index.js.map +1 -1
  51. package/lib/module/components/DrawCore/useDrawHook.js +69 -0
  52. package/lib/module/components/DrawCore/useDrawHook.js.map +1 -0
  53. package/lib/module/components/DrawWithOptions/ArrowSvg.js.map +1 -1
  54. package/lib/module/components/DrawWithOptions/CancelSvg.js.map +1 -1
  55. package/lib/module/components/DrawWithOptions/CircleSvg.js.map +1 -1
  56. package/lib/module/components/DrawWithOptions/CloseSvg.js.map +1 -1
  57. package/lib/module/components/DrawWithOptions/DoubleHeadSvg.js.map +1 -1
  58. package/lib/module/components/DrawWithOptions/PenSvg.js.map +1 -1
  59. package/lib/module/components/DrawWithOptions/SendSvg.js.map +1 -1
  60. package/lib/module/components/DrawWithOptions/SliderSvg.js +22 -0
  61. package/lib/module/components/DrawWithOptions/SliderSvg.js.map +1 -0
  62. package/lib/module/components/DrawWithOptions/SquareSvg.js.map +1 -1
  63. package/lib/module/components/DrawWithOptions/TextSvg.js.map +1 -1
  64. package/lib/module/components/DrawWithOptions/ThrashSvg.js +27 -2
  65. package/lib/module/components/DrawWithOptions/ThrashSvg.js.map +1 -1
  66. package/lib/module/components/DrawWithOptions/index.js +124 -70
  67. package/lib/module/components/DrawWithOptions/index.js.map +1 -1
  68. package/lib/module/components/Slider/ColorSlider.js +95 -0
  69. package/lib/module/components/Slider/ColorSlider.js.map +1 -0
  70. package/lib/module/components/Slider/Sliders.js +79 -0
  71. package/lib/module/components/Slider/Sliders.js.map +1 -0
  72. package/lib/module/components/Slider/StrokeSlider.js +82 -0
  73. package/lib/module/components/Slider/StrokeSlider.js.map +1 -0
  74. package/lib/module/components/Slider/sliderStyle.js +29 -0
  75. package/lib/module/components/Slider/sliderStyle.js.map +1 -0
  76. package/lib/module/index.js +1 -0
  77. package/lib/module/index.js.map +1 -1
  78. package/lib/typescript/components/DrawCore/CurrentAnimatedItem.d.ts.map +1 -1
  79. package/lib/typescript/components/DrawCore/DrawContext.d.ts +14 -0
  80. package/lib/typescript/components/DrawCore/DrawContext.d.ts.map +1 -0
  81. package/lib/typescript/components/DrawCore/DrawPad.d.ts.map +1 -1
  82. package/lib/typescript/components/DrawCore/DrawProvider.d.ts +6 -0
  83. package/lib/typescript/components/DrawCore/DrawProvider.d.ts.map +1 -0
  84. package/lib/typescript/components/DrawCore/index.d.ts +3 -11
  85. package/lib/typescript/components/DrawCore/index.d.ts.map +1 -1
  86. package/lib/typescript/components/DrawCore/useDrawHook.d.ts +18 -0
  87. package/lib/typescript/components/DrawCore/useDrawHook.d.ts.map +1 -0
  88. package/lib/typescript/components/DrawWithOptions/SliderSvg.d.ts +4 -0
  89. package/lib/typescript/components/DrawWithOptions/SliderSvg.d.ts.map +1 -0
  90. package/lib/typescript/components/DrawWithOptions/ThrashSvg.d.ts.map +1 -1
  91. package/lib/typescript/components/DrawWithOptions/index.d.ts +3 -5
  92. package/lib/typescript/components/DrawWithOptions/index.d.ts.map +1 -1
  93. package/lib/typescript/components/Slider/ColorSlider.d.ts +8 -0
  94. package/lib/typescript/components/Slider/ColorSlider.d.ts.map +1 -0
  95. package/lib/typescript/components/Slider/Sliders.d.ts +8 -0
  96. package/lib/typescript/components/Slider/Sliders.d.ts.map +1 -0
  97. package/lib/typescript/components/Slider/StrokeSlider.d.ts +6 -0
  98. package/lib/typescript/components/Slider/StrokeSlider.d.ts.map +1 -0
  99. package/lib/typescript/components/Slider/sliderStyle.d.ts +28 -0
  100. package/lib/typescript/components/Slider/sliderStyle.d.ts.map +1 -0
  101. package/lib/typescript/index.d.ts +1 -0
  102. package/lib/typescript/index.d.ts.map +1 -1
  103. package/package.json +22 -22
  104. package/src/components/DrawCore/CurrentAnimatedItem.tsx +10 -5
  105. package/src/components/DrawCore/DrawContext.tsx +22 -0
  106. package/src/components/DrawCore/DrawPad.tsx +0 -1
  107. package/src/components/DrawCore/DrawProvider.tsx +122 -0
  108. package/src/components/DrawCore/index.tsx +938 -1139
  109. package/src/components/DrawCore/useDrawHook.tsx +70 -0
  110. package/src/components/DrawWithOptions/SliderSvg.tsx +24 -0
  111. package/src/components/DrawWithOptions/ThrashSvg.tsx +29 -2
  112. package/src/components/DrawWithOptions/index.tsx +199 -146
  113. package/src/components/Slider/ColorSlider.tsx +144 -0
  114. package/src/components/Slider/Sliders.tsx +75 -0
  115. package/src/components/Slider/StrokeSlider.tsx +104 -0
  116. package/src/components/Slider/sliderStyle.tsx +28 -0
  117. package/src/index.tsx +1 -0
  118. package/src/types.d.ts +35 -1
  119. package/lib/commonjs/components/DrawCore/ColorSlider.js.map +0 -1
  120. package/lib/commonjs/components/DrawCore/StrokeSlider.js.map +0 -1
  121. package/lib/module/components/DrawCore/ColorSlider.js +0 -113
  122. package/lib/module/components/DrawCore/ColorSlider.js.map +0 -1
  123. package/lib/module/components/DrawCore/StrokeSlider.js +0 -91
  124. package/lib/module/components/DrawCore/StrokeSlider.js.map +0 -1
  125. package/lib/typescript/components/DrawCore/ColorSlider.d.ts +0 -13
  126. package/lib/typescript/components/DrawCore/ColorSlider.d.ts.map +0 -1
  127. package/lib/typescript/components/DrawCore/StrokeSlider.d.ts +0 -9
  128. package/lib/typescript/components/DrawCore/StrokeSlider.d.ts.map +0 -1
  129. package/src/components/DrawCore/ColorSlider.tsx +0 -169
  130. package/src/components/DrawCore/StrokeSlider.tsx +0 -117
@@ -1 +0,0 @@
1
- {"version":3,"file":"StrokeSlider.d.ts","sourceRoot":"","sources":["../../../../src/components/DrawCore/StrokeSlider.tsx"],"names":[],"mappings":"AAKA,OAAO,QAMN,MAAM,yBAAyB,CAAC;AAiCjC,QAAA,MAAM,YAAY;cAMN,MAAM;cACN,MAAM;YACR,SAAS,WAAW,CAAC,MAAM,CAAC;oBACpB,MAAM,IAAI;iBA6D3B,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -1,169 +0,0 @@
1
- import React, { useCallback } from 'react';
2
- import { LayoutChangeEvent, StyleSheet, View, ViewProps } from 'react-native';
3
-
4
- import {
5
- PanGestureHandler,
6
- PanGestureHandlerGestureEvent,
7
- } from 'react-native-gesture-handler';
8
- import Animated, {
9
- runOnJS,
10
- useAnimatedGestureHandler,
11
- useAnimatedStyle,
12
- useDerivedValue,
13
- useSharedValue,
14
- } from 'react-native-reanimated';
15
- import type { hslColor } from '../../types';
16
-
17
- const TRACK_R = 10;
18
-
19
- const gradientColors = [
20
- 'hsl(0, 100%, 100%) 00%',
21
- 'hsl(0, 100%, 50%) 10%',
22
- 'hsl(45, 100%, 50%) 20%',
23
- 'hsl(90, 100%, 50%) 30%',
24
- 'hsl(135, 100%, 50%) 40%',
25
- 'hsl(180, 100%, 50%) 50%',
26
- 'hsl(225, 100%, 50%) 60%',
27
- 'hsl(270, 100%, 50%) 70%',
28
- 'hsl(315, 100%, 50%) 80%',
29
- 'hsl(360, 100%, 50%) 90%',
30
- 'hsl(0, 100%, 0%) 100% ',
31
- ];
32
-
33
- const styles = StyleSheet.create({
34
- container: {
35
- flex: 1,
36
- alignItems: 'center',
37
- width: '100%',
38
- },
39
- thumb: {
40
- position: 'absolute',
41
- width: TRACK_R * 2,
42
- height: TRACK_R * 2,
43
- borderRadius: TRACK_R,
44
- top: 0,
45
- backgroundColor: 'white',
46
- },
47
- track: { width: 10, flex: 1, borderRadius: 5, borderWidth: 1 },
48
- indicator: {
49
- width: 22,
50
- height: 22,
51
- borderRadius: 22,
52
- marginTop: 20,
53
- },
54
- });
55
-
56
- const ColorSlider = ({
57
- color,
58
- linearGradient: LinearGradient,
59
- onColorChange,
60
- }: {
61
- color: Animated.SharedValue<hslColor>;
62
- linearGradient: React.ComponentType<{ colors: any[] } & ViewProps>;
63
- onColorChange: () => void;
64
- }) => {
65
- const sliderHeight = useSharedValue(0);
66
-
67
- const position = useDerivedValue(() => {
68
- const hslRegExp = new RegExp(/hsl\(([\d.]+),\s*(\d+)%,\s*([\d.]+)%\)/);
69
- const res = hslRegExp.exec(color.value);
70
-
71
- const lum = res ? parseFloat(res[3] ?? '0') : 0;
72
-
73
- const tint = res ? parseFloat(res[1] ?? '0') : 0;
74
-
75
- if (lum > 50) {
76
- return ((sliderHeight.value * 0.1) / 50) * (100 - lum);
77
- }
78
-
79
- if (lum < 50) {
80
- return sliderHeight.value - ((sliderHeight.value * 0.1) / 50) * lum;
81
- }
82
-
83
- return Math.min(
84
- sliderHeight.value,
85
- Math.max(
86
- 0,
87
- sliderHeight.value * 0.1 +
88
- tint * ((sliderHeight.value - sliderHeight.value * 0.2) / 360)
89
- )
90
- );
91
- }, [sliderHeight.value]);
92
-
93
- const onGestureEvent = useAnimatedGestureHandler<
94
- PanGestureHandlerGestureEvent,
95
- { startY: number }
96
- >(
97
- {
98
- onStart: ({ y }, ctx) => {
99
- ctx.startY = y;
100
- },
101
- onActive: ({ translationY }, { startY }) => {
102
- const slidePos = Math.min(sliderHeight.value, startY + translationY);
103
-
104
- if (slidePos < 0.1 * sliderHeight.value) {
105
- color.value = `hsl(0, 100%, ${Math.min(
106
- 100,
107
- 100 - (slidePos / (0.1 * sliderHeight.value)) * 50
108
- ).toFixed(10)}%)`;
109
- } else if (slidePos > 0.9 * sliderHeight.value) {
110
- color.value = `hsl(0, 100%, ${Math.max(
111
- 50 -
112
- ((slidePos - 0.9 * sliderHeight.value) /
113
- (0.1 * sliderHeight.value)) *
114
- 50,
115
- 0
116
- ).toFixed(10)}%)`;
117
- } else {
118
- color.value = `hsl(${
119
- ((slidePos - sliderHeight.value * 0.1) /
120
- (sliderHeight.value - sliderHeight.value * 0.2)) *
121
- 360
122
- }, 100%, 50%)`;
123
- }
124
- },
125
- onEnd: () => {
126
- runOnJS(onColorChange)();
127
- },
128
- },
129
- []
130
- );
131
-
132
- const style = useAnimatedStyle(() => {
133
- return {
134
- transform: [{ translateY: position.value - TRACK_R }],
135
- };
136
- }, [position.value]);
137
-
138
- const selectedColorStyle = useAnimatedStyle(() => {
139
- return {
140
- backgroundColor: color.value,
141
- };
142
- }, [color.value]);
143
-
144
- const onLayout = useCallback(
145
- (event: LayoutChangeEvent) => {
146
- sliderHeight.value = event.nativeEvent.layout.height;
147
- },
148
- [sliderHeight]
149
- );
150
-
151
- return (
152
- <View style={styles.container}>
153
- <PanGestureHandler onGestureEvent={onGestureEvent}>
154
- <Animated.View style={styles.container}>
155
- <LinearGradient
156
- colors={gradientColors}
157
- onLayout={onLayout}
158
- style={styles.track}
159
- />
160
- <Animated.View style={[styles.thumb, style]} />
161
- </Animated.View>
162
- </PanGestureHandler>
163
-
164
- <Animated.View style={[styles.indicator, selectedColorStyle]} />
165
- </View>
166
- );
167
- };
168
-
169
- export default ColorSlider;
@@ -1,117 +0,0 @@
1
- import React, { useState } from 'react';
2
- import {
3
- PanGestureHandler,
4
- PanGestureHandlerGestureEvent,
5
- } from 'react-native-gesture-handler';
6
- import Animated, {
7
- runOnJS,
8
- useAnimatedGestureHandler,
9
- useAnimatedStyle,
10
- useDerivedValue,
11
- useSharedValue,
12
- } from 'react-native-reanimated';
13
- import { View, StyleSheet, Text } from 'react-native';
14
-
15
- const TRACK_R = 10;
16
-
17
- const styles = StyleSheet.create({
18
- container: {
19
- flex: 1,
20
- alignItems: 'center',
21
- width: '100%',
22
- },
23
- thumb: {
24
- position: 'absolute',
25
- width: TRACK_R * 2,
26
- height: TRACK_R * 2,
27
- borderRadius: TRACK_R,
28
- top: 0,
29
- backgroundColor: 'white',
30
- },
31
- track: {
32
- width: 10,
33
- flex: 1,
34
- borderRadius: 5,
35
- backgroundColor: 'black',
36
- },
37
- textIndicator: {
38
- color: 'white',
39
- fontSize: 14,
40
- marginTop: 10,
41
- fontWeight: 'bold',
42
- },
43
- });
44
-
45
- const StrokeSlider = ({
46
- minValue,
47
- maxValue,
48
- stroke,
49
- onStrokeChange,
50
- }: {
51
- minValue: number;
52
- maxValue: number;
53
- stroke: Animated.SharedValue<number>;
54
- onStrokeChange: () => void;
55
- }) => {
56
- const sliderHeight = useSharedValue(0);
57
-
58
- const [text, setText] = useState(stroke.value);
59
-
60
- const position = useDerivedValue(() => {
61
- runOnJS(setText)(Math.round(stroke.value));
62
- return (
63
- (sliderHeight.value / (maxValue - minValue)) * (stroke.value - minValue)
64
- );
65
- });
66
-
67
- const onGestureEvent = useAnimatedGestureHandler<
68
- PanGestureHandlerGestureEvent,
69
- { startY: number }
70
- >(
71
- {
72
- onStart: ({ y }, ctx) => {
73
- ctx.startY = y;
74
- },
75
- onActive: ({ translationY }, { startY }) => {
76
- stroke.value = Math.min(
77
- maxValue,
78
- Math.max(
79
- minValue,
80
- ((startY + translationY) / sliderHeight.value) *
81
- (maxValue - minValue) +
82
- minValue
83
- )
84
- );
85
- },
86
- onEnd: () => {
87
- runOnJS(onStrokeChange)();
88
- },
89
- },
90
- []
91
- );
92
-
93
- const style = useAnimatedStyle(() => {
94
- return {
95
- transform: [{ translateY: position.value - TRACK_R }],
96
- };
97
- }, [position.value]);
98
-
99
- return (
100
- <View style={styles.container}>
101
- <PanGestureHandler onGestureEvent={onGestureEvent}>
102
- <Animated.View style={styles.container}>
103
- <View
104
- onLayout={(event) => {
105
- sliderHeight.value = event.nativeEvent.layout.height;
106
- }}
107
- style={styles.track}
108
- />
109
- <Animated.View style={[styles.thumb, style]} />
110
- </Animated.View>
111
- </PanGestureHandler>
112
- <Text style={styles.textIndicator}>{text}</Text>
113
- </View>
114
- );
115
- };
116
-
117
- export default StrokeSlider;