@proximus/lavender-switch-native 0.1.0-alpha.1 → 0.1.0-alpha.12

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.
@@ -1,19 +1,12 @@
1
1
  import React, { Component } from 'react';
2
2
  import { AccessibilityProps, Animated, StyleProp, ViewStyle } from 'react-native';
3
+ import { IThemeContext } from '@proximus/lavender-styling-native';
3
4
  export interface ISwitchProps extends AccessibilityProps {
4
5
  onValueChange: (value: boolean) => void;
5
6
  disabled?: boolean;
6
7
  lookOnlyProps?: boolean;
7
8
  value?: boolean;
8
- isPending?: boolean;
9
- circleColors?: Array<string>;
10
- circleStyle?: StyleProp<ViewStyle>;
11
- trackColors?: Array<string>;
12
- trackStyle?: StyleProp<ViewStyle>;
13
- disabledStyle?: StyleProp<ViewStyle>;
14
9
  testID?: string;
15
- height?: number;
16
- type?: 'order' | 'primary';
17
10
  labelAccessibilityProp?: AccessibilityProps;
18
11
  containerStyle?: StyleProp<ViewStyle>;
19
12
  hasLabel?: boolean;
@@ -22,9 +15,6 @@ interface IState {
22
15
  value: boolean;
23
16
  transformSwitch: Animated.Value;
24
17
  containerBackgroundColor: Animated.Value;
25
- yesLabelOpacity: Animated.Value;
26
- pendingOpacity: Animated.Value;
27
- noLabelOpacity: Animated.Value;
28
18
  }
29
19
  export declare class PxSwitch extends Component<ISwitchProps, IState> {
30
20
  static defaultProps: {
@@ -32,7 +22,7 @@ export declare class PxSwitch extends Component<ISwitchProps, IState> {
32
22
  value: boolean;
33
23
  type: string;
34
24
  };
35
- static contextType: React.Context<import("@proximus/lavender-styling-native").IThemeContext>;
25
+ static contextType: React.Context<IThemeContext>;
36
26
  constructor(props: ISwitchProps);
37
27
  componentDidUpdate(prevProps: ISwitchProps): void;
38
28
  _handleSwitch: (activate?: boolean) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"PxSwitch.d.ts","sourceRoot":"","sources":["../src/PxSwitch.tsx"],"names":[],"mappings":"AAAA,O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C,SAAS,EAAE,YAAY;IAS1C,aAAa,GAAI,WAAW,OAAO,UAkBjC;IAEF,cAAc,GAAI,OAAO,OAAO,UAc9B;IAEF,MAAM;CA6GP"}
@@ -0,0 +1,130 @@
1
+ import React, { Component } from 'react';
2
+ import { Animated, StyleSheet, TouchableWithoutFeedback, View, } from 'react-native';
3
+ import { Directions, FlingGestureHandler, State, } from 'react-native-gesture-handler';
4
+ import { a11y, e2eID } from '@proximus/lavender-common-native';
5
+ import { ThemeContext, } from '@proximus/lavender-styling-native';
6
+ const defaults = {
7
+ circleSize: 20,
8
+ duration: 200,
9
+ interpolationRange: 100,
10
+ };
11
+ export class PxSwitch extends Component {
12
+ static defaultProps = {
13
+ disabled: false,
14
+ value: false,
15
+ type: 'primary',
16
+ };
17
+ static contextType = ThemeContext;
18
+ constructor(props) {
19
+ super(props);
20
+ const { value } = props;
21
+ this.state = {
22
+ containerBackgroundColor: new Animated.Value(value ? defaults.interpolationRange : -defaults.interpolationRange),
23
+ transformSwitch: new Animated.Value(value ? defaults.circleSize - 10 : -defaults.circleSize + 10),
24
+ value: value || false,
25
+ };
26
+ }
27
+ componentDidUpdate(prevProps) {
28
+ const { disabled, value } = this.props;
29
+ if (prevProps.value !== value && !disabled) {
30
+ this._animateSwitch(!!value);
31
+ this.setState({ value: !!value });
32
+ }
33
+ }
34
+ _handleSwitch = (activate) => {
35
+ const { onValueChange, disabled, lookOnlyProps } = this.props;
36
+ if (!disabled) {
37
+ if (lookOnlyProps) {
38
+ if (onValueChange) {
39
+ onValueChange(!this.props.value);
40
+ }
41
+ }
42
+ else {
43
+ const { value } = this.state;
44
+ this._animateSwitch(activate ?? !value);
45
+ this.setState({ value: activate ?? !value }, () => {
46
+ if (onValueChange) {
47
+ onValueChange(this.state.value);
48
+ }
49
+ });
50
+ }
51
+ }
52
+ };
53
+ _animateSwitch = (value) => {
54
+ Animated.parallel([
55
+ Animated.spring(this.state.transformSwitch, {
56
+ useNativeDriver: true,
57
+ toValue: value ? defaults.circleSize - 10 : -defaults.circleSize + 10,
58
+ }),
59
+ Animated.timing(this.state.containerBackgroundColor, {
60
+ duration: defaults.duration,
61
+ useNativeDriver: true,
62
+ toValue: value
63
+ ? defaults.interpolationRange
64
+ : -defaults.interpolationRange,
65
+ }),
66
+ ]).start();
67
+ };
68
+ render() {
69
+ const { containerBackgroundColor, value } = this.state;
70
+ const { testID, disabled, ...accessibilityProps } = this.props;
71
+ const containerBackground = containerBackgroundColor.interpolate({
72
+ inputRange: [-defaults.interpolationRange, defaults.interpolationRange],
73
+ outputRange: [
74
+ this.context?.theme?.t('ColorBackgroundContainerStrongDefault'),
75
+ this.context?.theme?.t('ColorBackgroundPurposeSuccessDefault'),
76
+ ],
77
+ });
78
+ return (React.createElement(FlingGestureHandler, { direction: Directions.LEFT, numberOfPointers: 1, onHandlerStateChange: ({ nativeEvent }) => {
79
+ if (nativeEvent.state === State.ACTIVE && value) {
80
+ this._handleSwitch(false);
81
+ }
82
+ } },
83
+ React.createElement(FlingGestureHandler, { direction: Directions.RIGHT, numberOfPointers: 1, onHandlerStateChange: ({ nativeEvent }) => {
84
+ if (nativeEvent.state === State.ACTIVE && !value) {
85
+ this._handleSwitch(true);
86
+ }
87
+ } },
88
+ React.createElement(View, { style: [this.props.containerStyle] },
89
+ React.createElement(TouchableWithoutFeedback, { disabled: disabled, onPress: () => this._handleSwitch(), accessible: false, ...e2eID(testID), ...a11y({
90
+ accessible: true,
91
+ accessibilityRole: 'switch',
92
+ accessibilityLabel: this.props.labelAccessibilityProp?.accessibilityLabel,
93
+ accessibilityHint: this.props.labelAccessibilityProp?.accessibilityHint,
94
+ accessibilityState: {
95
+ disabled,
96
+ selected: value,
97
+ },
98
+ ...accessibilityProps,
99
+ }) },
100
+ React.createElement(Animated.View, { style: [
101
+ styles.track,
102
+ {
103
+ backgroundColor: containerBackground,
104
+ borderRadius: this.context?.theme?.t('RadiusPill').number,
105
+ width: this.context?.theme?.t('SizeActionInputSwitchWidth').number,
106
+ padding: this.context?.theme?.t('Padding3xsMobile').number,
107
+ },
108
+ disabled && {
109
+ backgroundColor: this.context?.theme?.t('ColorBackgroundStateDisabledDefault'),
110
+ },
111
+ ] },
112
+ React.createElement(Animated.View, { style: [
113
+ {
114
+ width: this.context?.theme?.t('SizeIconM').number,
115
+ height: this.context?.theme?.t('SizeIconM').number,
116
+ borderRadius: this.context?.theme?.t('RadiusPill').number,
117
+ backgroundColor: disabled
118
+ ? this.context?.theme?.t('ColorBackgroundStateDisabledDefault')
119
+ : this.context?.theme?.t('ColorBackgroundContainerLightDefault'),
120
+ transform: [{ translateX: this.state.transformSwitch }],
121
+ },
122
+ ] })))))));
123
+ }
124
+ }
125
+ const styles = StyleSheet.create({
126
+ track: {
127
+ flexDirection: 'row',
128
+ justifyContent: 'center',
129
+ },
130
+ });
package/package.json CHANGED
@@ -1,41 +1,21 @@
1
1
  {
2
2
  "name": "@proximus/lavender-switch-native",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-alpha.12",
4
4
  "description": "Lavender react native switch component",
5
5
  "license": "MIT",
6
- "main": "src/index.ts",
6
+ "main": "dist/index.js",
7
+ "files": [
8
+ "dist"
9
+ ],
7
10
  "type": "module",
8
- "scripts": {
9
- "clean": "rm -rf dist",
10
- "prepublish": "yarn clean && yarn build",
11
- "build": "npx tsc -p tsconfig.json"
12
- },
13
11
  "peerDependencies": {
14
- "@proximus/lavender-common-native": "workspace:*",
15
- "@proximus/lavender-icon-native": "workspace:*",
16
- "@proximus/lavender-styling-native": "workspace:*",
17
- "@proximus/lavender-texts-native": "workspace:*",
12
+ "@proximus/lavender-common-native": "*",
13
+ "@proximus/lavender-icon-native": "*",
14
+ "@proximus/lavender-styling-native": "*",
15
+ "@proximus/lavender-texts-native": "*",
18
16
  "react-native-gesture-handler": "*"
19
17
  },
20
- "devDependencies": {
21
- "@proximus/lavender-common-native": "0.1.0-alpha.1",
22
- "@proximus/lavender-icon-native": "0.1.0-alpha.1",
23
- "@proximus/lavender-styling-native": "0.1.0-alpha.1",
24
- "@proximus/lavender-texts-native": "0.1.0-alpha.1"
25
- },
26
18
  "publishConfig": {
27
19
  "access": "public"
28
- },
29
- "lerna": {
30
- "command": {
31
- "publish": {
32
- "assets": [
33
- "dist",
34
- "src",
35
- "package.json"
36
- ]
37
- }
38
- }
39
- },
40
- "gitHead": "d422a1d369000e1e249afb26de2cef08930c2407"
20
+ }
41
21
  }
package/CHANGELOG.md DELETED
@@ -1,41 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [0.1.0-alpha.1](https://github.com/Pxs-Corporate/react-native-lavender/compare/@proximus/lavender-switch-native@0.1.0-alpha.0...@proximus/lavender-switch-native@0.1.0-alpha.1) (2025-08-13)
7
-
8
- ### Bug Fixes
9
-
10
- - **BCRI-4210372:** fix types field in modules ([68ac126](https://github.com/Pxs-Corporate/react-native-lavender/commit/68ac12657112473ae9e0e683076b1d9172be9ce6))
11
-
12
- # 0.1.0-alpha.0 (2025-08-13)
13
-
14
- ### Bug Fixes
15
-
16
- - **BCRI-000000:** switch using tokens ([0442cc0](https://github.com/Pxs-Corporate/react-native-lavender/commit/0442cc0aba3fcbbcb21938da0747ea593d413bf6))
17
- - **BCRI-00000:** mendix widgets ids for backward compatibility ([69e61fd](https://github.com/Pxs-Corporate/react-native-lavender/commit/69e61fde51b203b947ec7a1094f10067a1ecfdbb))
18
-
19
- ### Features
20
-
21
- - **BCRI-000000:** remove default E2E on DEV env build for all components ([a5d27bf](https://github.com/Pxs-Corporate/react-native-lavender/commit/a5d27bfaaebf5b75f3160f31c64b590b7bd00b93))
22
- - **BCRI-3651771:** switch module ([d6f8151](https://github.com/Pxs-Corporate/react-native-lavender/commit/d6f81510e13ca3634f843caa0286c444373a039c))
23
- - **BCRI-3660857:** cell components ([af9e45c](https://github.com/Pxs-Corporate/react-native-lavender/commit/af9e45cefc20d08d2338380ff4cd8cd6851abe24))
24
- - **BCRI-4002610:** update icon handling and remove deprecated font references ([4399fe4](https://github.com/Pxs-Corporate/react-native-lavender/commit/4399fe4bff06aa70f5c29705fcc89d5243b0e3e7))
25
- - **BCRI-4210372:** automatic versionning ([9c1f0a0](https://github.com/Pxs-Corporate/react-native-lavender/commit/9c1f0a00e19a9d1a277044ea627632032a674102))
26
- - **BCRI-4210372:** fix bad version numbers ([bc6a8ba](https://github.com/Pxs-Corporate/react-native-lavender/commit/bc6a8ba48c15347442f2ac38dacae7ffba3d95eb))
27
-
28
- # (2025-08-13)
29
-
30
- ### Bug Fixes
31
-
32
- - **BCRI-000000:** switch using tokens ([0442cc0](https://github.com/Pxs-Corporate/react-native-lavender/commit/0442cc0aba3fcbbcb21938da0747ea593d413bf6))
33
- - **BCRI-00000:** mendix widgets ids for backward compatibility ([69e61fd](https://github.com/Pxs-Corporate/react-native-lavender/commit/69e61fde51b203b947ec7a1094f10067a1ecfdbb))
34
-
35
- ### Features
36
-
37
- - **BCRI-000000:** remove default E2E on DEV env build for all components ([a5d27bf](https://github.com/Pxs-Corporate/react-native-lavender/commit/a5d27bfaaebf5b75f3160f31c64b590b7bd00b93))
38
- - **BCRI-3651771:** switch module ([d6f8151](https://github.com/Pxs-Corporate/react-native-lavender/commit/d6f81510e13ca3634f843caa0286c444373a039c))
39
- - **BCRI-3660857:** cell components ([af9e45c](https://github.com/Pxs-Corporate/react-native-lavender/commit/af9e45cefc20d08d2338380ff4cd8cd6851abe24))
40
- - **BCRI-4002610:** update icon handling and remove deprecated font references ([4399fe4](https://github.com/Pxs-Corporate/react-native-lavender/commit/4399fe4bff06aa70f5c29705fcc89d5243b0e3e7))
41
- - **BCRI-4210372:** automatic versionning ([9c1f0a0](https://github.com/Pxs-Corporate/react-native-lavender/commit/9c1f0a00e19a9d1a277044ea627632032a674102))
package/src/PxSwitch.tsx DELETED
@@ -1,314 +0,0 @@
1
- import React, { Component } from 'react';
2
- import {
3
- AccessibilityProps,
4
- Animated,
5
- StyleProp,
6
- StyleSheet,
7
- TouchableWithoutFeedback,
8
- View,
9
- ViewStyle,
10
- } from 'react-native';
11
- import {
12
- Directions,
13
- FlingGestureHandler,
14
- State,
15
- } from 'react-native-gesture-handler';
16
-
17
- import { a11y, e2eID } from '@proximus/lavender-common-native';
18
-
19
- import { ThemeContext } from '@proximus/lavender-styling-native';
20
-
21
- export interface ISwitchProps extends AccessibilityProps {
22
- onValueChange: (value: boolean) => void;
23
- disabled?: boolean;
24
- lookOnlyProps?: boolean;
25
- value?: boolean;
26
- isPending?: boolean;
27
- circleColors?: Array<string>; // Deprecated
28
- circleStyle?: StyleProp<ViewStyle>; // Deprecated
29
- trackColors?: Array<string>;
30
- trackStyle?: StyleProp<ViewStyle>;
31
- disabledStyle?: StyleProp<ViewStyle>;
32
- testID?: string;
33
- height?: number;
34
- type?: 'order' | 'primary';
35
- labelAccessibilityProp?: AccessibilityProps;
36
- containerStyle?: StyleProp<ViewStyle>;
37
- hasLabel?: boolean;
38
- }
39
-
40
- interface IState {
41
- value: boolean;
42
- transformSwitch: Animated.Value;
43
- containerBackgroundColor: Animated.Value;
44
- yesLabelOpacity: Animated.Value;
45
- pendingOpacity: Animated.Value;
46
- noLabelOpacity: Animated.Value;
47
- }
48
-
49
- const defaults = {
50
- circleSize: 20,
51
- duration: 200,
52
- interpolationRange: 100,
53
- };
54
-
55
- export class PxSwitch extends Component<ISwitchProps, IState> {
56
- static defaultProps = {
57
- disabled: false,
58
- value: false,
59
- type: 'primary',
60
- };
61
-
62
- static contextType = ThemeContext;
63
-
64
- constructor(props: ISwitchProps) {
65
- super(props);
66
-
67
- const { value, isPending, disabled } = props;
68
- this.state = {
69
- containerBackgroundColor: new Animated.Value(
70
- value || isPending
71
- ? defaults.interpolationRange
72
- : -defaults.interpolationRange
73
- ),
74
- transformSwitch: new Animated.Value(
75
- value || isPending
76
- ? defaults.circleSize - 10
77
- : -defaults.circleSize + 10
78
- ),
79
- yesLabelOpacity: new Animated.Value(
80
- disabled || !props.value || isPending ? 0 : 1
81
- ),
82
- pendingOpacity: new Animated.Value(isPending && !disabled ? 1 : 0),
83
- noLabelOpacity: new Animated.Value(
84
- disabled || value || isPending ? 0 : 1
85
- ),
86
- value: value || false,
87
- };
88
- }
89
-
90
- componentDidUpdate(prevProps: ISwitchProps) {
91
- const { disabled, value } = this.props;
92
-
93
- if (prevProps.value !== value && !disabled) {
94
- this._animateSwitch(!!value);
95
- this.setState({ value: !!value });
96
- }
97
- }
98
-
99
- _handleSwitch = (activate?: boolean) => {
100
- const { onValueChange, disabled, lookOnlyProps } = this.props;
101
-
102
- if (!disabled) {
103
- if (lookOnlyProps) {
104
- if (onValueChange) {
105
- onValueChange(!this.props.value);
106
- }
107
- } else {
108
- const { value } = this.state;
109
- this._animateSwitch(activate ?? !value);
110
- this.setState({ value: activate ?? !value }, () => {
111
- if (onValueChange) {
112
- onValueChange(this.state.value);
113
- }
114
- });
115
- }
116
- }
117
- };
118
-
119
- _animateSwitch = (value: boolean) => {
120
- const { isPending } = this.props;
121
- Animated.parallel([
122
- Animated.spring(this.state.transformSwitch, {
123
- useNativeDriver: false,
124
- toValue:
125
- value || isPending
126
- ? defaults.circleSize - 10
127
- : -defaults.circleSize + 10,
128
- }),
129
- Animated.timing(this.state.containerBackgroundColor, {
130
- duration: defaults.duration,
131
- useNativeDriver: false,
132
- toValue:
133
- value || isPending
134
- ? defaults.interpolationRange
135
- : -defaults.interpolationRange,
136
- }),
137
- Animated.spring(this.state.yesLabelOpacity, {
138
- useNativeDriver: false,
139
- toValue: value && !isPending ? 1 : 0,
140
- }),
141
- Animated.spring(this.state.noLabelOpacity, {
142
- useNativeDriver: false,
143
- toValue: value || isPending ? 0 : 1,
144
- }),
145
- Animated.spring(this.state.pendingOpacity, {
146
- useNativeDriver: false,
147
- toValue: isPending ? 1 : 0,
148
- }),
149
- ]).start();
150
- };
151
-
152
- render() {
153
- const { containerBackgroundColor, value } = this.state;
154
-
155
- const {
156
- circleStyle,
157
- trackColors,
158
- trackStyle,
159
- testID,
160
- disabled,
161
- isPending,
162
- height = 28,
163
- type,
164
- ...accessibilityProps
165
- } = this.props;
166
-
167
- const containerBackground = containerBackgroundColor.interpolate({
168
- inputRange: [-defaults.interpolationRange, defaults.interpolationRange],
169
- outputRange: trackColors || [
170
- // @ts-ignore
171
- this.context?.theme?.t('BackgroundColorActionNeutralStrongDefault'),
172
- type === 'order'
173
- ? // @ts-ignore
174
- this.context?.theme?.switchActiveForOrder
175
- : // @ts-ignore
176
- this.context?.theme?.t('BackgroundColorPurposeSuccessDefault'),
177
- ],
178
- });
179
-
180
- return (
181
- // @ts-ignore
182
- <FlingGestureHandler
183
- direction={Directions.LEFT}
184
- numberOfPointers={1}
185
- onHandlerStateChange={({ nativeEvent }) => {
186
- if (nativeEvent.state === State.ACTIVE && value) {
187
- this._handleSwitch(false);
188
- }
189
- }}
190
- >
191
- {/*
192
- // @ts-ignore */}
193
- <FlingGestureHandler
194
- direction={Directions.RIGHT}
195
- numberOfPointers={1}
196
- onHandlerStateChange={({ nativeEvent }) => {
197
- if (nativeEvent.state === State.ACTIVE && !value) {
198
- this._handleSwitch(true);
199
- }
200
- }}
201
- >
202
- <View style={[{ height }, this.props.containerStyle]}>
203
- <TouchableWithoutFeedback
204
- disabled={disabled}
205
- onPress={() => this._handleSwitch()}
206
- accessible={false}
207
- {...e2eID(testID)}
208
- {...a11y({
209
- accessible: true,
210
- accessibilityRole: 'switch',
211
- accessibilityLabel:
212
- this.props.labelAccessibilityProp?.accessibilityLabel,
213
- accessibilityHint:
214
- this.props.labelAccessibilityProp?.accessibilityHint,
215
- accessibilityState: {
216
- disabled,
217
- selected: value,
218
- },
219
- ...accessibilityProps,
220
- })}
221
- >
222
- <Animated.View
223
- style={[
224
- styles.track,
225
- {
226
- backgroundColor: containerBackground,
227
- },
228
- trackStyle,
229
- isPending && {
230
- // @ts-ignore
231
- backgroundColor: this.context?.theme?.switchPending,
232
- },
233
- disabled && {
234
- // @ts-ignore
235
- backgroundColor: this.context?.theme?.t(
236
- 'BackgroundColorActionDisabledDefault'
237
- ),
238
- },
239
- ]}
240
- >
241
- <Animated.View
242
- style={[
243
- styles.circle,
244
- {
245
- // @ts-ignore
246
- width: this.context?.theme?.t('AssetsSizeS').number,
247
- // @ts-ignore
248
- height: this.context?.theme?.t('AssetsSizeS').number,
249
- // @ts-ignore
250
- borderRadius: this.context?.theme?.t('RadiusPill').number,
251
- backgroundColor: disabled
252
- ? // @ts-ignore
253
- this.context?.theme?.t(
254
- 'BackgroundColorActionDisabledDefault'
255
- )
256
- : // @ts-ignore
257
- this.context?.theme?.t(
258
- 'BackgroundColorContainerNeutralBareDefault'
259
- ),
260
- left: this.state.transformSwitch,
261
- },
262
- circleStyle,
263
- ]}
264
- ></Animated.View>
265
- <Animated.View
266
- style={{
267
- position: 'absolute',
268
- opacity: this.state.yesLabelOpacity,
269
- left: 9,
270
- }}
271
- ></Animated.View>
272
- {!disabled && (
273
- <Animated.View
274
- style={{
275
- position: 'absolute',
276
- opacity: this.state.noLabelOpacity,
277
- right: 6,
278
- }}
279
- ></Animated.View>
280
- )}
281
- </Animated.View>
282
- </TouchableWithoutFeedback>
283
- </View>
284
- </FlingGestureHandler>
285
- </FlingGestureHandler>
286
- );
287
- }
288
- }
289
-
290
- const styles = StyleSheet.create({
291
- circle: {
292
- borderRadius: 14,
293
- alignItems: 'center',
294
- // height: defaults.circleSize,
295
- // width: defaults.circleSize,
296
- },
297
- disabled: {
298
- bottom: 0,
299
- left: 0,
300
- opacity: 0.5,
301
- position: 'absolute',
302
- right: 0,
303
- top: 0,
304
- },
305
- track: {
306
- alignItems: 'center',
307
- borderRadius: 14,
308
- flex: 1,
309
- flexDirection: 'row',
310
- height: 30,
311
- justifyContent: 'center',
312
- width: 48,
313
- },
314
- });
package/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.npm.json",
3
- "compilerOptions": {
4
- "outDir": "dist"
5
- },
6
- "include": ["src","../../../lib.d.ts"],
7
- "exclude": ["dist", "node_modules", "src/**/*.test.ts", "src/**/*.spec.ts"]
8
- }
File without changes