native-variants 0.1.63 → 0.1.69

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 (37) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +125 -125
  3. package/dist/example.js +1 -0
  4. package/dist/index.d.ts +17 -8
  5. package/dist/index.js +72 -22
  6. package/dist/index.js.map +1 -1
  7. package/dist/lib/cn.d.ts +82 -2
  8. package/dist/lib/cn.js +138 -8
  9. package/dist/lib/cn.js.map +1 -1
  10. package/dist/lib/create-nva.d.ts +209 -6
  11. package/dist/lib/create-nva.js +460 -47
  12. package/dist/lib/create-nva.js.map +1 -1
  13. package/dist/lib/media-query.d.ts +84 -2
  14. package/dist/lib/media-query.js +103 -9
  15. package/dist/lib/media-query.js.map +1 -1
  16. package/dist/provider/create-provider.d.ts +44 -4
  17. package/dist/provider/create-provider.js +1 -1
  18. package/dist/provider/create-provider.jsx +110 -9
  19. package/dist/provider/create-provider.jsx.map +1 -1
  20. package/dist/provider/theme-provider.d.ts +266 -0
  21. package/dist/provider/theme-provider.js +1 -0
  22. package/dist/provider/theme-provider.jsx +328 -0
  23. package/dist/provider/theme-provider.jsx.map +1 -0
  24. package/dist/tokens/default-tokens.d.ts +2737 -0
  25. package/dist/tokens/default-tokens.js +1067 -0
  26. package/dist/tokens/default-tokens.js.map +1 -0
  27. package/dist/types.d.ts +318 -3
  28. package/dist/utils/alpha.d.ts +68 -0
  29. package/dist/utils/alpha.js +147 -4
  30. package/dist/utils/alpha.js.map +1 -1
  31. package/dist/utils/compose-text.d.ts +64 -2
  32. package/dist/utils/compose-text.js +103 -3
  33. package/dist/utils/compose-text.js.map +1 -1
  34. package/package.json +1 -1
  35. package/dist/utils/compose-refs.d.ts +0 -4
  36. package/dist/utils/compose-refs.js +0 -39
  37. package/dist/utils/compose-refs.js.map +0 -1
@@ -1,3 +1,65 @@
1
- import { TextStyle } from "react-native";
2
- import { Styles } from "../types.js";
1
+ import type { TextStyle } from "react-native";
2
+ import type { Styles } from "../types.js";
3
+ /**
4
+ * Extracts text-specific styles from a combined style object.
5
+ * Useful when you need to apply text styles to a Text component
6
+ * from a style object that may contain View styles.
7
+ *
8
+ * @param style - The combined style object to extract from
9
+ * @returns A new object containing only TextStyle properties
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const combinedStyles = {
14
+ * backgroundColor: "#fff",
15
+ * padding: 16,
16
+ * color: "#000",
17
+ * fontSize: 14,
18
+ * fontWeight: "600",
19
+ * };
20
+ *
21
+ * const textStyles = composeText(combinedStyles);
22
+ * // Result: { color: "#000", fontSize: 14, fontWeight: "600" }
23
+ *
24
+ * // Usage in components
25
+ * <View style={combinedStyles}>
26
+ * <Text style={composeText(combinedStyles)}>Hello</Text>
27
+ * </View>
28
+ * ```
29
+ */
3
30
  export declare function composeText(style?: Styles): Partial<TextStyle>;
31
+ /**
32
+ * Checks if a style object contains any text-specific styles.
33
+ *
34
+ * @param style - The style object to check
35
+ * @returns True if the style contains at least one text style property
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * hasTextStyles({ padding: 10 }); // false
40
+ * hasTextStyles({ color: "red" }); // true
41
+ * hasTextStyles({ padding: 10, fontSize: 14 }); // true
42
+ * ```
43
+ */
44
+ export declare function hasTextStyles(style?: Styles): boolean;
45
+ /**
46
+ * Extracts non-text styles (View styles) from a combined style object.
47
+ * Complement to composeText - returns everything except text styles.
48
+ *
49
+ * @param style - The combined style object to extract from
50
+ * @returns A new object containing only non-TextStyle properties
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * const combinedStyles = {
55
+ * backgroundColor: "#fff",
56
+ * padding: 16,
57
+ * color: "#000",
58
+ * fontSize: 14,
59
+ * };
60
+ *
61
+ * const viewStyles = composeView(combinedStyles);
62
+ * // Result: { backgroundColor: "#fff", padding: 16 }
63
+ * ```
64
+ */
65
+ export declare function composeView(style?: Styles): Styles;
@@ -1,7 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.composeText = composeText;
4
- const textStyleKeys = [
4
+ exports.hasTextStyles = hasTextStyles;
5
+ exports.composeView = composeView;
6
+ /**
7
+ * Complete list of React Native TextStyle property keys.
8
+ * Used to filter text-specific styles from combined style objects.
9
+ */
10
+ const textStyleKeys = new Set([
5
11
  "color",
6
12
  "fontSize",
7
13
  "fontWeight",
@@ -20,10 +26,104 @@ const textStyleKeys = [
20
26
  "textShadowColor",
21
27
  "textShadowOffset",
22
28
  "textShadowRadius",
23
- ];
29
+ "fontVariant",
30
+ "userSelect",
31
+ ]);
32
+ /**
33
+ * Extracts text-specific styles from a combined style object.
34
+ * Useful when you need to apply text styles to a Text component
35
+ * from a style object that may contain View styles.
36
+ *
37
+ * @param style - The combined style object to extract from
38
+ * @returns A new object containing only TextStyle properties
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * const combinedStyles = {
43
+ * backgroundColor: "#fff",
44
+ * padding: 16,
45
+ * color: "#000",
46
+ * fontSize: 14,
47
+ * fontWeight: "600",
48
+ * };
49
+ *
50
+ * const textStyles = composeText(combinedStyles);
51
+ * // Result: { color: "#000", fontSize: 14, fontWeight: "600" }
52
+ *
53
+ * // Usage in components
54
+ * <View style={combinedStyles}>
55
+ * <Text style={composeText(combinedStyles)}>Hello</Text>
56
+ * </View>
57
+ * ```
58
+ */
24
59
  function composeText(style) {
25
60
  if (!style)
26
61
  return {};
27
- return Object.fromEntries(Object.entries(style).filter(([key]) => textStyleKeys.includes(key)));
62
+ const result = {};
63
+ const keys = Object.keys(style);
64
+ for (let i = 0; i < keys.length; i++) {
65
+ const key = keys[i];
66
+ if (textStyleKeys.has(key)) {
67
+ result[key] = style[key];
68
+ }
69
+ }
70
+ return result;
71
+ }
72
+ /**
73
+ * Checks if a style object contains any text-specific styles.
74
+ *
75
+ * @param style - The style object to check
76
+ * @returns True if the style contains at least one text style property
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * hasTextStyles({ padding: 10 }); // false
81
+ * hasTextStyles({ color: "red" }); // true
82
+ * hasTextStyles({ padding: 10, fontSize: 14 }); // true
83
+ * ```
84
+ */
85
+ function hasTextStyles(style) {
86
+ if (!style)
87
+ return false;
88
+ const keys = Object.keys(style);
89
+ for (let i = 0; i < keys.length; i++) {
90
+ if (textStyleKeys.has(keys[i])) {
91
+ return true;
92
+ }
93
+ }
94
+ return false;
95
+ }
96
+ /**
97
+ * Extracts non-text styles (View styles) from a combined style object.
98
+ * Complement to composeText - returns everything except text styles.
99
+ *
100
+ * @param style - The combined style object to extract from
101
+ * @returns A new object containing only non-TextStyle properties
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * const combinedStyles = {
106
+ * backgroundColor: "#fff",
107
+ * padding: 16,
108
+ * color: "#000",
109
+ * fontSize: 14,
110
+ * };
111
+ *
112
+ * const viewStyles = composeView(combinedStyles);
113
+ * // Result: { backgroundColor: "#fff", padding: 16 }
114
+ * ```
115
+ */
116
+ function composeView(style) {
117
+ if (!style)
118
+ return {};
119
+ const result = {};
120
+ const keys = Object.keys(style);
121
+ for (let i = 0; i < keys.length; i++) {
122
+ const key = keys[i];
123
+ if (!textStyleKeys.has(key)) {
124
+ result[key] = style[key];
125
+ }
126
+ }
127
+ return result;
28
128
  }
29
129
  //# sourceMappingURL=compose-text.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"compose-text.js","sourceRoot":"","sources":["../../src/utils/compose-text.ts"],"names":[],"mappings":";;AAwBA,kCAQC;AA7BD,MAAM,aAAa,GAAwB;IACzC,OAAO;IACP,UAAU;IACV,YAAY;IACZ,WAAW;IACX,WAAW;IACX,mBAAmB;IACnB,eAAe;IACf,YAAY;IACZ,oBAAoB;IACpB,qBAAqB;IACrB,qBAAqB;IACrB,YAAY;IACZ,oBAAoB;IACpB,eAAe;IACf,kBAAkB;IAClB,iBAAiB;IACjB,kBAAkB;IAClB,kBAAkB;CACnB,CAAC;AAEF,SAAgB,WAAW,CAAC,KAAc;IACxC,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,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;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IAEzB,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,IAAI,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAoB,CAAC,EAAE,CAAC;YAClD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,WAAW,CAAC,KAAc;IACxC,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IAEtB,MAAM,MAAM,GAAW,EAAE,CAAC;IAC1B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAqB,CAAC;IAEpD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAsB,CAAC,EAAE,CAAC;YAC9C,MAAkC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-variants",
3
- "version": "0.1.63",
3
+ "version": "0.1.69",
4
4
  "description": "A library for handling variants in React Native components with theme support.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,4 +0,0 @@
1
- import { RefCallback, type Ref } from "react";
2
- type PossibleRef<T> = Ref<T> | undefined;
3
- export declare function composeRefs<T>(...refs: PossibleRef<T>[]): RefCallback<T>;
4
- export {};
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.composeRefs = composeRefs;
4
- function setRef(ref, value) {
5
- if (typeof ref === "function") {
6
- return ref(value);
7
- }
8
- else if (ref !== null && ref !== undefined) {
9
- //@ts-expect-error
10
- ref.current = value;
11
- }
12
- }
13
- function composeRefs(...refs) {
14
- return (node) => {
15
- let hasCleanup = false;
16
- const cleanups = refs.map((ref) => {
17
- const cleanup = setRef(ref, node);
18
- if (!hasCleanup && typeof cleanup == "function") {
19
- hasCleanup = true;
20
- }
21
- return cleanup;
22
- });
23
- if (hasCleanup) {
24
- return () => {
25
- for (let i = 0; i < cleanups.length; i++) {
26
- const cleanup = cleanups[i];
27
- if (typeof cleanup == "function") {
28
- //@ts-expect-error
29
- cleanup();
30
- }
31
- else {
32
- setRef(refs[i], null);
33
- }
34
- }
35
- };
36
- }
37
- };
38
- }
39
- //# sourceMappingURL=compose-refs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compose-refs.js","sourceRoot":"","sources":["../../src/utils/compose-refs.ts"],"names":[],"mappings":";;AAaA,kCA2BC;AApCD,SAAS,MAAM,CAAI,GAAmB,EAAE,KAAQ;IAC9C,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;QAC9B,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;SAAM,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QAC7C,kBAAkB;QAClB,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;IACtB,CAAC;AACH,CAAC;AAED,SAAgB,WAAW,CACzB,GAAG,IAAsB;IAEzB,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,IAAI,UAAU,GAAG,KAAK,CAAC;QACvB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,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