zkit-ui 1.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 (267) hide show
  1. package/README.md +267 -0
  2. package/dist/ComponentLibProvider.d.ts +15 -0
  3. package/dist/ComponentLibProvider.d.ts.map +1 -0
  4. package/dist/ComponentLibProvider.js +18 -0
  5. package/dist/assets/animations/spinner.json +1 -0
  6. package/dist/assets/icons/check.svg +4 -0
  7. package/dist/assets/icons/toast/error.webp +0 -0
  8. package/dist/assets/icons/toast/success.webp +0 -0
  9. package/dist/assets/icons/toast/warning.webp +0 -0
  10. package/dist/config.d.ts +16 -0
  11. package/dist/config.d.ts.map +1 -0
  12. package/dist/config.js +42 -0
  13. package/dist/i18n/I18nProvider.d.ts +11 -0
  14. package/dist/i18n/I18nProvider.d.ts.map +1 -0
  15. package/dist/i18n/I18nProvider.js +84 -0
  16. package/dist/i18n/locale.d.ts +7 -0
  17. package/dist/i18n/locale.d.ts.map +1 -0
  18. package/dist/i18n/locale.js +87 -0
  19. package/dist/i18n/locales/de.d.ts +51 -0
  20. package/dist/i18n/locales/de.d.ts.map +1 -0
  21. package/dist/i18n/locales/de.js +62 -0
  22. package/dist/i18n/locales/en-US.d.ts +51 -0
  23. package/dist/i18n/locales/en-US.d.ts.map +1 -0
  24. package/dist/i18n/locales/en-US.js +62 -0
  25. package/dist/i18n/locales/index.d.ts +9 -0
  26. package/dist/i18n/locales/index.d.ts.map +1 -0
  27. package/dist/i18n/locales/index.js +23 -0
  28. package/dist/i18n/locales/ja.d.ts +51 -0
  29. package/dist/i18n/locales/ja.d.ts.map +1 -0
  30. package/dist/i18n/locales/ja.js +62 -0
  31. package/dist/i18n/locales/zh-CN.d.ts +51 -0
  32. package/dist/i18n/locales/zh-CN.d.ts.map +1 -0
  33. package/dist/i18n/locales/zh-CN.js +62 -0
  34. package/dist/i18n/locales/zh-TW.d.ts +51 -0
  35. package/dist/i18n/locales/zh-TW.d.ts.map +1 -0
  36. package/dist/i18n/locales/zh-TW.js +62 -0
  37. package/dist/i18n/types.d.ts +11 -0
  38. package/dist/i18n/types.d.ts.map +1 -0
  39. package/dist/i18n/types.js +2 -0
  40. package/dist/i18n/useI18n.d.ts +2 -0
  41. package/dist/i18n/useI18n.d.ts.map +1 -0
  42. package/dist/i18n/useI18n.js +41 -0
  43. package/dist/index.d.ts +57 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +90 -0
  46. package/dist/services/ActionDialogService/ActionDialog.d.ts +4 -0
  47. package/dist/services/ActionDialogService/ActionDialog.d.ts.map +1 -0
  48. package/dist/services/ActionDialogService/ActionDialog.js +531 -0
  49. package/dist/services/ActionDialogService/index.d.ts +4 -0
  50. package/dist/services/ActionDialogService/index.d.ts.map +1 -0
  51. package/dist/services/ActionDialogService/index.js +8 -0
  52. package/dist/services/ActionDialogService/service.d.ts +7 -0
  53. package/dist/services/ActionDialogService/service.d.ts.map +1 -0
  54. package/dist/services/ActionDialogService/service.js +309 -0
  55. package/dist/services/ActionDialogService/shared.d.ts +17 -0
  56. package/dist/services/ActionDialogService/shared.d.ts.map +1 -0
  57. package/dist/services/ActionDialogService/shared.js +167 -0
  58. package/dist/services/ActionDialogService/types.d.ts +160 -0
  59. package/dist/services/ActionDialogService/types.d.ts.map +1 -0
  60. package/dist/services/ActionDialogService/types.js +2 -0
  61. package/dist/services/CardToastService/index.d.ts +115 -0
  62. package/dist/services/CardToastService/index.d.ts.map +1 -0
  63. package/dist/services/CardToastService/index.js +899 -0
  64. package/dist/services/ImagePreviewService/index.d.ts +179 -0
  65. package/dist/services/ImagePreviewService/index.d.ts.map +1 -0
  66. package/dist/services/ImagePreviewService/index.js +1383 -0
  67. package/dist/services/LoadingService/index.d.ts +146 -0
  68. package/dist/services/LoadingService/index.d.ts.map +1 -0
  69. package/dist/services/LoadingService/index.js +827 -0
  70. package/dist/services/PermissionPurposeDialogService/index.d.ts +99 -0
  71. package/dist/services/PermissionPurposeDialogService/index.d.ts.map +1 -0
  72. package/dist/services/PermissionPurposeDialogService/index.js +360 -0
  73. package/dist/services/PickerService/index.d.ts +128 -0
  74. package/dist/services/PickerService/index.d.ts.map +1 -0
  75. package/dist/services/PickerService/index.js +250 -0
  76. package/dist/theme/ThemeProvider.d.ts +15 -0
  77. package/dist/theme/ThemeProvider.d.ts.map +1 -0
  78. package/dist/theme/ThemeProvider.js +61 -0
  79. package/dist/theme/defaultTheme.d.ts +3 -0
  80. package/dist/theme/defaultTheme.d.ts.map +1 -0
  81. package/dist/theme/defaultTheme.js +28 -0
  82. package/dist/theme/mergeTheme.d.ts +3 -0
  83. package/dist/theme/mergeTheme.d.ts.map +1 -0
  84. package/dist/theme/mergeTheme.js +19 -0
  85. package/dist/theme/types.d.ts +17 -0
  86. package/dist/theme/types.d.ts.map +1 -0
  87. package/dist/theme/types.js +2 -0
  88. package/dist/theme/useTheme.d.ts +2 -0
  89. package/dist/theme/useTheme.d.ts.map +1 -0
  90. package/dist/theme/useTheme.js +46 -0
  91. package/dist/ui/Accordion/index.d.ts +99 -0
  92. package/dist/ui/Accordion/index.d.ts.map +1 -0
  93. package/dist/ui/Accordion/index.js +777 -0
  94. package/dist/ui/AddressCascader/index.d.ts +58 -0
  95. package/dist/ui/AddressCascader/index.d.ts.map +1 -0
  96. package/dist/ui/AddressCascader/index.js +710 -0
  97. package/dist/ui/BetweenTime/index.d.ts +82 -0
  98. package/dist/ui/BetweenTime/index.d.ts.map +1 -0
  99. package/dist/ui/BetweenTime/index.js +702 -0
  100. package/dist/ui/Button/index.d.ts +93 -0
  101. package/dist/ui/Button/index.d.ts.map +1 -0
  102. package/dist/ui/Button/index.js +832 -0
  103. package/dist/ui/Checkbox/index.d.ts +103 -0
  104. package/dist/ui/Checkbox/index.d.ts.map +1 -0
  105. package/dist/ui/Checkbox/index.js +694 -0
  106. package/dist/ui/DatePicker/index.d.ts +5 -0
  107. package/dist/ui/DatePicker/index.d.ts.map +1 -0
  108. package/dist/ui/DatePicker/index.js +157 -0
  109. package/dist/ui/DatePicker/types.d.ts +99 -0
  110. package/dist/ui/DatePicker/types.d.ts.map +1 -0
  111. package/dist/ui/DatePicker/types.js +2 -0
  112. package/dist/ui/DatePicker/utils.d.ts +32 -0
  113. package/dist/ui/DatePicker/utils.d.ts.map +1 -0
  114. package/dist/ui/DatePicker/utils.js +316 -0
  115. package/dist/ui/LinkedScroll/index.d.ts +78 -0
  116. package/dist/ui/LinkedScroll/index.d.ts.map +1 -0
  117. package/dist/ui/LinkedScroll/index.js +470 -0
  118. package/dist/ui/LoadingSpinner/index.d.ts +8 -0
  119. package/dist/ui/LoadingSpinner/index.d.ts.map +1 -0
  120. package/dist/ui/LoadingSpinner/index.js +122 -0
  121. package/dist/ui/Picker/actionBar.d.ts +14 -0
  122. package/dist/ui/Picker/actionBar.d.ts.map +1 -0
  123. package/dist/ui/Picker/actionBar.js +28 -0
  124. package/dist/ui/Picker/index.d.ts +5 -0
  125. package/dist/ui/Picker/index.d.ts.map +1 -0
  126. package/dist/ui/Picker/index.js +412 -0
  127. package/dist/ui/Picker/types.d.ts +80 -0
  128. package/dist/ui/Picker/types.d.ts.map +1 -0
  129. package/dist/ui/Picker/types.js +2 -0
  130. package/dist/ui/Picker/utils.d.ts +27 -0
  131. package/dist/ui/Picker/utils.d.ts.map +1 -0
  132. package/dist/ui/Picker/utils.js +182 -0
  133. package/dist/ui/Radio/index.d.ts +95 -0
  134. package/dist/ui/Radio/index.d.ts.map +1 -0
  135. package/dist/ui/Radio/index.js +633 -0
  136. package/dist/ui/Sheet/index.d.ts +12 -0
  137. package/dist/ui/Sheet/index.d.ts.map +1 -0
  138. package/dist/ui/Sheet/index.js +832 -0
  139. package/dist/ui/Sheet/nativeBottom.d.ts +52 -0
  140. package/dist/ui/Sheet/nativeBottom.d.ts.map +1 -0
  141. package/dist/ui/Sheet/nativeBottom.js +442 -0
  142. package/dist/ui/Sheet/nativeBottom.web.d.ts +18 -0
  143. package/dist/ui/Sheet/nativeBottom.web.d.ts.map +1 -0
  144. package/dist/ui/Sheet/nativeBottom.web.js +46 -0
  145. package/dist/ui/Sheet/slots.d.ts +5 -0
  146. package/dist/ui/Sheet/slots.d.ts.map +1 -0
  147. package/dist/ui/Sheet/slots.js +40 -0
  148. package/dist/ui/Sheet/types.d.ts +131 -0
  149. package/dist/ui/Sheet/types.d.ts.map +1 -0
  150. package/dist/ui/Sheet/types.js +2 -0
  151. package/dist/ui/SliderCaptcha/index.d.ts +57 -0
  152. package/dist/ui/SliderCaptcha/index.d.ts.map +1 -0
  153. package/dist/ui/SliderCaptcha/index.js +586 -0
  154. package/dist/ui/Switch/index.d.ts +72 -0
  155. package/dist/ui/Switch/index.d.ts.map +1 -0
  156. package/dist/ui/Switch/index.js +671 -0
  157. package/dist/ui/Text/index.d.ts +41 -0
  158. package/dist/ui/Text/index.d.ts.map +1 -0
  159. package/dist/ui/Text/index.js +325 -0
  160. package/dist/ui/TextInput/TextInputPrimitive.d.ts +8 -0
  161. package/dist/ui/TextInput/TextInputPrimitive.d.ts.map +1 -0
  162. package/dist/ui/TextInput/TextInputPrimitive.js +54 -0
  163. package/dist/ui/TextInput/index.d.ts +89 -0
  164. package/dist/ui/TextInput/index.d.ts.map +1 -0
  165. package/dist/ui/TextInput/index.js +545 -0
  166. package/dist/ui/WheelColumn/ZKitWheelPickerNativeComponent.d.ts +39 -0
  167. package/dist/ui/WheelColumn/ZKitWheelPickerNativeComponent.d.ts.map +1 -0
  168. package/dist/ui/WheelColumn/ZKitWheelPickerNativeComponent.js +60 -0
  169. package/dist/ui/WheelColumn/constants.d.ts +2 -0
  170. package/dist/ui/WheelColumn/constants.d.ts.map +1 -0
  171. package/dist/ui/WheelColumn/constants.js +4 -0
  172. package/dist/ui/WheelColumn/index.d.ts +59 -0
  173. package/dist/ui/WheelColumn/index.d.ts.map +1 -0
  174. package/dist/ui/WheelColumn/index.js +547 -0
  175. package/ios/ZKitWheelPicker.h +18 -0
  176. package/ios/ZKitWheelPicker.mm +230 -0
  177. package/ios/ZKitWheelPickerLabel.h +10 -0
  178. package/ios/ZKitWheelPickerLabel.mm +31 -0
  179. package/ios/ZKitWheelPickerManager.h +5 -0
  180. package/ios/ZKitWheelPickerManager.mm +53 -0
  181. package/package.json +75 -0
  182. package/react-native.config.js +10 -0
  183. package/src/ComponentLibProvider.tsx +56 -0
  184. package/src/assets/animations/spinner.json +1 -0
  185. package/src/assets/icons/check.svg +4 -0
  186. package/src/assets/icons/toast/error.webp +0 -0
  187. package/src/assets/icons/toast/success.webp +0 -0
  188. package/src/assets/icons/toast/warning.webp +0 -0
  189. package/src/config.ts +65 -0
  190. package/src/i18n/I18nProvider.tsx +69 -0
  191. package/src/i18n/locale.ts +108 -0
  192. package/src/i18n/locales/de.ts +67 -0
  193. package/src/i18n/locales/en-US.ts +67 -0
  194. package/src/i18n/locales/index.ts +19 -0
  195. package/src/i18n/locales/ja.ts +67 -0
  196. package/src/i18n/locales/zh-CN.ts +67 -0
  197. package/src/i18n/locales/zh-TW.ts +67 -0
  198. package/src/i18n/types.ts +21 -0
  199. package/src/i18n/useI18n.ts +7 -0
  200. package/src/index.ts +395 -0
  201. package/src/services/ActionDialogService/ActionDialog.tsx +756 -0
  202. package/src/services/ActionDialogService/README.md +146 -0
  203. package/src/services/ActionDialogService/index.tsx +39 -0
  204. package/src/services/ActionDialogService/service.tsx +355 -0
  205. package/src/services/ActionDialogService/shared.ts +204 -0
  206. package/src/services/ActionDialogService/types.ts +197 -0
  207. package/src/services/CardToastService/README.md +128 -0
  208. package/src/services/CardToastService/index.tsx +1284 -0
  209. package/src/services/ImagePreviewService/README.md +67 -0
  210. package/src/services/ImagePreviewService/index.tsx +2148 -0
  211. package/src/services/LoadingService/README.md +128 -0
  212. package/src/services/LoadingService/index.tsx +1113 -0
  213. package/src/services/PermissionPurposeDialogService/README.md +80 -0
  214. package/src/services/PermissionPurposeDialogService/index.tsx +449 -0
  215. package/src/services/PickerService/README.md +154 -0
  216. package/src/services/PickerService/index.tsx +410 -0
  217. package/src/theme/ThemeProvider.tsx +40 -0
  218. package/src/theme/defaultTheme.ts +30 -0
  219. package/src/theme/mergeTheme.ts +16 -0
  220. package/src/theme/types.ts +36 -0
  221. package/src/theme/useTheme.ts +10 -0
  222. package/src/types/svg.d.ts +9 -0
  223. package/src/types/vant-area-data.d.ts +19 -0
  224. package/src/ui/Accordion/README.md +67 -0
  225. package/src/ui/Accordion/index.tsx +1221 -0
  226. package/src/ui/AddressCascader/README.md +144 -0
  227. package/src/ui/AddressCascader/index.tsx +1084 -0
  228. package/src/ui/BetweenTime/README.md +490 -0
  229. package/src/ui/BetweenTime/index.tsx +1001 -0
  230. package/src/ui/Button/README.md +186 -0
  231. package/src/ui/Button/index.tsx +1356 -0
  232. package/src/ui/Checkbox/README.md +211 -0
  233. package/src/ui/Checkbox/index.tsx +1231 -0
  234. package/src/ui/DatePicker/README.md +117 -0
  235. package/src/ui/DatePicker/index.tsx +295 -0
  236. package/src/ui/DatePicker/types.ts +115 -0
  237. package/src/ui/DatePicker/utils.ts +405 -0
  238. package/src/ui/LinkedScroll/README.md +55 -0
  239. package/src/ui/LinkedScroll/index.tsx +809 -0
  240. package/src/ui/LoadingSpinner/index.tsx +104 -0
  241. package/src/ui/Picker/README.md +190 -0
  242. package/src/ui/Picker/actionBar.tsx +70 -0
  243. package/src/ui/Picker/index.tsx +694 -0
  244. package/src/ui/Picker/types.ts +94 -0
  245. package/src/ui/Picker/utils.ts +239 -0
  246. package/src/ui/Radio/README.md +207 -0
  247. package/src/ui/Radio/index.tsx +1117 -0
  248. package/src/ui/Sheet/README.md +82 -0
  249. package/src/ui/Sheet/index.tsx +1163 -0
  250. package/src/ui/Sheet/nativeBottom.tsx +683 -0
  251. package/src/ui/Sheet/nativeBottom.web.tsx +40 -0
  252. package/src/ui/Sheet/slots.tsx +75 -0
  253. package/src/ui/Sheet/types.ts +195 -0
  254. package/src/ui/SliderCaptcha/README.md +61 -0
  255. package/src/ui/SliderCaptcha/index.tsx +816 -0
  256. package/src/ui/Switch/README.md +143 -0
  257. package/src/ui/Switch/index.tsx +1092 -0
  258. package/src/ui/Text/README.md +157 -0
  259. package/src/ui/Text/index.tsx +450 -0
  260. package/src/ui/TextInput/README.md +197 -0
  261. package/src/ui/TextInput/TextInputPrimitive.tsx +44 -0
  262. package/src/ui/TextInput/index.tsx +942 -0
  263. package/src/ui/WheelColumn/README.md +104 -0
  264. package/src/ui/WheelColumn/ZKitWheelPickerNativeComponent.tsx +68 -0
  265. package/src/ui/WheelColumn/constants.ts +1 -0
  266. package/src/ui/WheelColumn/index.tsx +826 -0
  267. package/zkit-ui.podspec +19 -0
@@ -0,0 +1,671 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.Switch = void 0;
37
+ const jsx_runtime_1 = require("react/jsx-runtime");
38
+ const React = __importStar(require("react"));
39
+ const react_native_1 = require("react-native");
40
+ const react_native_reanimated_1 = __importStar(require("react-native-reanimated"));
41
+ const zkit_tools_1 = require("zkit-tools");
42
+ const useTheme_1 = require("../../theme/useTheme");
43
+ const LoadingSpinner_1 = require("../LoadingSpinner");
44
+ const Text_1 = require("../Text");
45
+ const SEMANTIC_COLORS = {
46
+ danger: '#DC2626',
47
+ error: '#DC2626',
48
+ info: '#2563EB',
49
+ success: '#16A34A',
50
+ warn: '#D97706',
51
+ warning: '#D97706',
52
+ };
53
+ const SIZE_TOKENS = {
54
+ sm: {
55
+ width: 44,
56
+ height: 26,
57
+ thumbInset: 2,
58
+ labelGap: 10,
59
+ textInset: 4,
60
+ textSize: 11,
61
+ textLineHeight: 13,
62
+ textSlotMinWidth: 24,
63
+ },
64
+ md: {
65
+ width: 52,
66
+ height: 32,
67
+ thumbInset: 3,
68
+ labelGap: 12,
69
+ textInset: 5,
70
+ textSize: 12,
71
+ textLineHeight: 14,
72
+ textSlotMinWidth: 30,
73
+ },
74
+ lg: {
75
+ width: 64,
76
+ height: 38,
77
+ thumbInset: 3,
78
+ labelGap: 14,
79
+ textInset: 6,
80
+ textSize: 13,
81
+ textLineHeight: 16,
82
+ textSlotMinWidth: 36,
83
+ },
84
+ };
85
+ const PRESSED_OPACITY = 0.92;
86
+ const STATE_TEXT_WIDTH_FACTOR = 0.58;
87
+ const STATE_TEXT_WIDTH_GUARD_FACTOR = 0.25;
88
+ const VALUE_TIMING_DURATION = 180;
89
+ const PRESS_IN_DURATION = 90;
90
+ const PRESS_OUT_DURATION = 140;
91
+ const FOCUS_DURATION = 120;
92
+ function resolveSwitchMetrics(size) {
93
+ var _a;
94
+ const token = (_a = SIZE_TOKENS[size]) !== null && _a !== void 0 ? _a : SIZE_TOKENS.md;
95
+ return {
96
+ width: (0, zkit_tools_1.wp)(token.width),
97
+ height: (0, zkit_tools_1.wp)(token.height),
98
+ thumbInset: (0, zkit_tools_1.wp)(token.thumbInset),
99
+ labelGap: (0, zkit_tools_1.wp)(token.labelGap),
100
+ textInset: (0, zkit_tools_1.wp)(token.textInset),
101
+ textSize: (0, zkit_tools_1.wp)(token.textSize),
102
+ textLineHeight: (0, zkit_tools_1.wp)(token.textLineHeight),
103
+ textSlotMinWidth: (0, zkit_tools_1.wp)(token.textSlotMinWidth),
104
+ minTouchTarget: (0, zkit_tools_1.wp)(44),
105
+ focusRingWidth: (0, zkit_tools_1.wp)(2),
106
+ focusRingOffset: (0, zkit_tools_1.wp)(3),
107
+ };
108
+ }
109
+ function isProcessableColor(color) {
110
+ return (0, react_native_1.processColor)(color) != null;
111
+ }
112
+ function colorToRgba(color, alpha) {
113
+ const processed = (0, react_native_1.processColor)(color);
114
+ if (typeof processed !== 'number')
115
+ return undefined;
116
+ const normalized = processed >>> 0;
117
+ const r = (normalized >> 16) & 255;
118
+ const g = (normalized >> 8) & 255;
119
+ const b = normalized & 255;
120
+ const a = Math.max(0, Math.min(1, alpha));
121
+ return `rgba(${r},${g},${b},${a})`;
122
+ }
123
+ function colorToChannels(color) {
124
+ const processed = (0, react_native_1.processColor)(color);
125
+ if (typeof processed !== 'number')
126
+ return undefined;
127
+ const normalized = processed >>> 0;
128
+ return {
129
+ r: (normalized >> 16) & 255,
130
+ g: (normalized >> 8) & 255,
131
+ b: normalized & 255,
132
+ a: ((normalized >> 24) & 255) / 255,
133
+ };
134
+ }
135
+ function overlayColor(foreground, background, opacity) {
136
+ const fg = colorToChannels(foreground);
137
+ const bg = colorToChannels(background);
138
+ if (!fg || !bg)
139
+ return undefined;
140
+ const fgAlpha = Math.max(0, Math.min(1, opacity)) * fg.a;
141
+ const bgAlpha = bg.a;
142
+ const alpha = fgAlpha + bgAlpha * (1 - fgAlpha);
143
+ if (alpha <= 0)
144
+ return 'rgba(0,0,0,0)';
145
+ const r = Math.round((fg.r * fgAlpha + bg.r * bgAlpha * (1 - fgAlpha)) / alpha);
146
+ const g = Math.round((fg.g * fgAlpha + bg.g * bgAlpha * (1 - fgAlpha)) / alpha);
147
+ const b = Math.round((fg.b * fgAlpha + bg.b * bgAlpha * (1 - fgAlpha)) / alpha);
148
+ return `rgba(${r},${g},${b},${Math.round(alpha * 1000) / 1000})`;
149
+ }
150
+ function resolveColorToken(input, fallback, theme) {
151
+ var _a;
152
+ if (input == null)
153
+ return fallback;
154
+ const key = input.trim();
155
+ if (!key)
156
+ return fallback;
157
+ const resolved = key === 'primary'
158
+ ? theme.colors.primary
159
+ : key === 'onPrimary'
160
+ ? theme.colors.onPrimary
161
+ : key === 'secondary' || key === 'neutral'
162
+ ? theme.colors.secondary
163
+ : key === 'onSecondary'
164
+ ? theme.colors.onSecondary
165
+ : key === 'surface'
166
+ ? theme.colors.surface
167
+ : key === 'onSurface'
168
+ ? theme.colors.onSurface
169
+ : key === 'border'
170
+ ? theme.colors.border
171
+ : key === 'muted'
172
+ ? theme.colors.muted
173
+ : key === 'disabled'
174
+ ? theme.colors.disabled
175
+ : (_a = SEMANTIC_COLORS[key]) !== null && _a !== void 0 ? _a : key;
176
+ return isProcessableColor(resolved) ? resolved : fallback;
177
+ }
178
+ function resolveTonePalette(tone, theme) {
179
+ if (tone === 'neutral') {
180
+ return {
181
+ checkedTrack: theme.colors.onSurface,
182
+ checkedText: theme.colors.surface,
183
+ };
184
+ }
185
+ if (tone === 'success') {
186
+ return {
187
+ checkedTrack: SEMANTIC_COLORS.success,
188
+ checkedText: '#FFFFFF',
189
+ };
190
+ }
191
+ if (tone === 'warning') {
192
+ return {
193
+ checkedTrack: SEMANTIC_COLORS.warning,
194
+ checkedText: '#111827',
195
+ };
196
+ }
197
+ if (tone === 'danger') {
198
+ return {
199
+ checkedTrack: SEMANTIC_COLORS.danger,
200
+ checkedText: '#FFFFFF',
201
+ };
202
+ }
203
+ if (tone === 'info') {
204
+ return {
205
+ checkedTrack: SEMANTIC_COLORS.info,
206
+ checkedText: '#FFFFFF',
207
+ };
208
+ }
209
+ return {
210
+ checkedTrack: theme.colors.primary,
211
+ checkedText: theme.colors.onPrimary,
212
+ };
213
+ }
214
+ function resolveUncheckedTrackFallback(scheme, theme) {
215
+ var _a;
216
+ if (scheme === 'dark')
217
+ return '#374151';
218
+ return (_a = colorToRgba(theme.colors.onSurface, 0.12)) !== null && _a !== void 0 ? _a : theme.colors.border;
219
+ }
220
+ function clampNumber(value, min, max) {
221
+ if (!Number.isFinite(value))
222
+ return min;
223
+ return Math.min(Math.max(value, min), max);
224
+ }
225
+ function resolvePositiveNumber(value, fallback) {
226
+ return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : fallback;
227
+ }
228
+ function resolveNonNegativeNumber(value, fallback) {
229
+ return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : fallback;
230
+ }
231
+ function resolveDuration(duration) {
232
+ if (duration == null || !Number.isFinite(duration))
233
+ return VALUE_TIMING_DURATION;
234
+ return Math.max(0, duration);
235
+ }
236
+ function toTimingConfig(duration) {
237
+ return {
238
+ duration,
239
+ easing: react_native_reanimated_1.Easing.out(react_native_reanimated_1.Easing.cubic),
240
+ reduceMotion: react_native_reanimated_1.ReduceMotion.System,
241
+ };
242
+ }
243
+ function resolveHitSlop(width, height, minTouchTarget) {
244
+ const vertical = Math.max(0, (minTouchTarget - height) / 2);
245
+ const horizontal = Math.max(0, (minTouchTarget - width) / 2);
246
+ if (vertical === 0 && horizontal === 0)
247
+ return undefined;
248
+ return {
249
+ top: vertical,
250
+ bottom: vertical,
251
+ left: horizontal,
252
+ right: horizontal,
253
+ };
254
+ }
255
+ function resolveWebCursorStyle(disabled) {
256
+ if (react_native_1.Platform.OS !== 'web')
257
+ return undefined;
258
+ return { cursor: disabled ? 'not-allowed' : 'pointer' };
259
+ }
260
+ function isPrimitiveText(node) {
261
+ return typeof node === 'string' || typeof node === 'number';
262
+ }
263
+ function isRenderProp(children) {
264
+ return typeof children === 'function';
265
+ }
266
+ function getTextLength(text) {
267
+ return text == null ? 0 : Array.from(text).length;
268
+ }
269
+ function isWideGlyph(codePoint) {
270
+ return ((codePoint >= 0x1100 && codePoint <= 0x115f) ||
271
+ (codePoint >= 0x2329 && codePoint <= 0x232a) ||
272
+ (codePoint >= 0x2e80 && codePoint <= 0xa4cf) ||
273
+ (codePoint >= 0xac00 && codePoint <= 0xd7a3) ||
274
+ (codePoint >= 0xf900 && codePoint <= 0xfaff) ||
275
+ (codePoint >= 0xfe10 && codePoint <= 0xfe6f) ||
276
+ (codePoint >= 0xff00 && codePoint <= 0xff60) ||
277
+ (codePoint >= 0xffe0 && codePoint <= 0xffe6) ||
278
+ (codePoint >= 0x1f000 && codePoint <= 0x1faff));
279
+ }
280
+ function estimateStateTextWidth(text, fontSize) {
281
+ var _a;
282
+ const glyphs = Array.from(text !== null && text !== void 0 ? text : '');
283
+ if (glyphs.length === 0)
284
+ return 0;
285
+ let widthUnits = 0;
286
+ for (const glyph of glyphs) {
287
+ const codePoint = (_a = glyph.codePointAt(0)) !== null && _a !== void 0 ? _a : 0;
288
+ if (isWideGlyph(codePoint)) {
289
+ widthUnits += 1;
290
+ }
291
+ else if (/\s/.test(glyph)) {
292
+ widthUnits += 0.32;
293
+ }
294
+ else if (/[ilI.,'`|!]/.test(glyph)) {
295
+ widthUnits += 0.34;
296
+ }
297
+ else if (/[mwMW@#%&]/.test(glyph)) {
298
+ widthUnits += 0.82;
299
+ }
300
+ else if (/[A-Z0-9]/.test(glyph)) {
301
+ widthUnits += 0.62;
302
+ }
303
+ else {
304
+ widthUnits += 0.56;
305
+ }
306
+ }
307
+ return Math.max(getTextLength(text) * fontSize * STATE_TEXT_WIDTH_FACTOR, widthUnits * fontSize);
308
+ }
309
+ function SwitchImpl({ checked: checkedProp, defaultChecked = false, onCheckedChange, disabled = false, loading = false, loadingIndicator, size = 'md', tone = 'primary', duration, color, colors, layout, stateText, label, description, labelPlacement = 'start', children, style, contentStyle, trackStyle, thumbStyle, labelStyle, descriptionStyle, stateTextStyle, accessibilityLabel, accessibilityState, accessibilityValue, hitSlop, onPress, onPressIn, onPressOut, onFocus, onBlur, testID, ...pressableProps }, ref) {
310
+ var _a, _b, _c, _d, _e;
311
+ const theme = (0, useTheme_1.useTheme)();
312
+ const scheme = (0, react_native_1.useColorScheme)();
313
+ const { width: viewportWidth } = (0, react_native_1.useWindowDimensions)();
314
+ const isRTL = react_native_1.I18nManager.isRTL;
315
+ const isControlled = checkedProp !== undefined;
316
+ const [uncontrolledChecked, setUncontrolledChecked] = React.useState(() => defaultChecked);
317
+ const checked = isControlled ? checkedProp : uncontrolledChecked;
318
+ const checkedRef = React.useRef(checked);
319
+ checkedRef.current = checked;
320
+ const interactionDisabled = disabled || loading;
321
+ const interactive = !interactionDisabled;
322
+ const metrics = React.useMemo(() => resolveSwitchMetrics(size), [size, viewportWidth]);
323
+ const tonePalette = React.useMemo(() => resolveTonePalette(tone, theme), [theme, tone]);
324
+ const checkedTrackColor = React.useMemo(() => resolveColorToken(color !== null && color !== void 0 ? color : colors === null || colors === void 0 ? void 0 : colors.checkedTrack, tonePalette.checkedTrack, theme), [color, colors === null || colors === void 0 ? void 0 : colors.checkedTrack, theme, tonePalette.checkedTrack]);
325
+ const uncheckedTrackColor = React.useMemo(() => resolveColorToken(colors === null || colors === void 0 ? void 0 : colors.uncheckedTrack, resolveUncheckedTrackFallback(scheme, theme), theme), [colors === null || colors === void 0 ? void 0 : colors.uncheckedTrack, scheme, theme]);
326
+ const checkedThumbColor = React.useMemo(() => { var _a; return resolveColorToken((_a = colors === null || colors === void 0 ? void 0 : colors.checkedThumb) !== null && _a !== void 0 ? _a : colors === null || colors === void 0 ? void 0 : colors.thumb, theme.colors.surface, theme); }, [colors === null || colors === void 0 ? void 0 : colors.checkedThumb, colors === null || colors === void 0 ? void 0 : colors.thumb, theme]);
327
+ const uncheckedThumbColor = React.useMemo(() => { var _a; return resolveColorToken((_a = colors === null || colors === void 0 ? void 0 : colors.uncheckedThumb) !== null && _a !== void 0 ? _a : colors === null || colors === void 0 ? void 0 : colors.thumb, theme.colors.surface, theme); }, [colors === null || colors === void 0 ? void 0 : colors.thumb, colors === null || colors === void 0 ? void 0 : colors.uncheckedThumb, theme]);
328
+ const checkedTextColor = React.useMemo(() => resolveColorToken(colors === null || colors === void 0 ? void 0 : colors.checkedText, tonePalette.checkedText, theme), [colors === null || colors === void 0 ? void 0 : colors.checkedText, theme, tonePalette.checkedText]);
329
+ const uncheckedTextColor = React.useMemo(() => resolveColorToken(colors === null || colors === void 0 ? void 0 : colors.uncheckedText, scheme === 'dark' ? '#E5E7EB' : theme.colors.muted, theme), [colors === null || colors === void 0 ? void 0 : colors.uncheckedText, scheme, theme]);
330
+ const focusRingColor = React.useMemo(() => {
331
+ var _a;
332
+ return resolveColorToken(colors === null || colors === void 0 ? void 0 : colors.focusRing, (_a = colorToRgba(checkedTrackColor, scheme === 'dark' ? 0.36 : 0.28)) !== null && _a !== void 0 ? _a : checkedTrackColor, theme);
333
+ }, [checkedTrackColor, colors === null || colors === void 0 ? void 0 : colors.focusRing, scheme, theme]);
334
+ const disabledUncheckedTrackColor = React.useMemo(() => {
335
+ var _a;
336
+ return (_a = overlayColor(uncheckedTrackColor, theme.colors.surface, scheme === 'dark' ? 0.68 : 0.56)) !== null && _a !== void 0 ? _a : uncheckedTrackColor;
337
+ }, [scheme, theme.colors.surface, uncheckedTrackColor]);
338
+ const disabledCheckedTrackColor = React.useMemo(() => {
339
+ var _a;
340
+ return (_a = overlayColor(checkedTrackColor, theme.colors.surface, scheme === 'dark' ? 0.5 : 0.56)) !== null && _a !== void 0 ? _a : checkedTrackColor;
341
+ }, [checkedTrackColor, scheme, theme.colors.surface]);
342
+ const visualUncheckedTrackColor = disabled ? disabledUncheckedTrackColor : uncheckedTrackColor;
343
+ const visualCheckedTrackColor = disabled ? disabledCheckedTrackColor : checkedTrackColor;
344
+ const disabledUncheckedThumbColor = React.useMemo(() => {
345
+ var _a;
346
+ return (_a = overlayColor(uncheckedThumbColor, disabledUncheckedTrackColor, scheme === 'dark' ? 0.84 : 0.95)) !== null && _a !== void 0 ? _a : uncheckedThumbColor;
347
+ }, [disabledUncheckedTrackColor, scheme, uncheckedThumbColor]);
348
+ const disabledCheckedThumbColor = React.useMemo(() => {
349
+ var _a;
350
+ return (_a = overlayColor(checkedThumbColor, disabledCheckedTrackColor, scheme === 'dark' ? 0.84 : 0.92)) !== null && _a !== void 0 ? _a : checkedThumbColor;
351
+ }, [checkedThumbColor, disabledCheckedTrackColor, scheme]);
352
+ const visualUncheckedThumbColor = disabled ? disabledUncheckedThumbColor : uncheckedThumbColor;
353
+ const visualCheckedThumbColor = disabled ? disabledCheckedThumbColor : checkedThumbColor;
354
+ const visualCheckedTextColor = React.useMemo(() => {
355
+ var _a;
356
+ return disabled
357
+ ? (_a = overlayColor(checkedTextColor, disabledCheckedTrackColor, scheme === 'dark' ? 0.78 : 0.72)) !== null && _a !== void 0 ? _a : checkedTextColor
358
+ : checkedTextColor;
359
+ }, [checkedTextColor, disabled, disabledCheckedTrackColor, scheme]);
360
+ const visualUncheckedTextColor = React.useMemo(() => {
361
+ var _a;
362
+ return disabled
363
+ ? (_a = overlayColor(uncheckedTextColor, disabledUncheckedTrackColor, scheme === 'dark' ? 0.78 : 0.72)) !== null && _a !== void 0 ? _a : uncheckedTextColor
364
+ : uncheckedTextColor;
365
+ }, [disabled, disabledUncheckedTrackColor, scheme, uncheckedTextColor]);
366
+ const loadingColor = React.useMemo(() => resolveColorToken(colors === null || colors === void 0 ? void 0 : colors.loading, checked ? visualCheckedTrackColor : theme.colors.muted, theme), [checked, colors === null || colors === void 0 ? void 0 : colors.loading, theme, visualCheckedTrackColor]);
367
+ const thumbColorChanges = visualCheckedThumbColor !== visualUncheckedThumbColor;
368
+ const trackHeight = resolvePositiveNumber(layout === null || layout === void 0 ? void 0 : layout.height, metrics.height);
369
+ const baseTrackWidth = Math.max(trackHeight, resolvePositiveNumber(layout === null || layout === void 0 ? void 0 : layout.width, metrics.width));
370
+ const onePx = (0, zkit_tools_1.wp)(1);
371
+ const resolvedThumbInset = clampNumber(resolveNonNegativeNumber(layout === null || layout === void 0 ? void 0 : layout.thumbInset, metrics.thumbInset), 0, Math.max(0, (trackHeight - onePx) / 2));
372
+ const thumbSize = Math.max(onePx, trackHeight - resolvedThumbInset * 2);
373
+ const stateTextSize = resolvePositiveNumber(layout === null || layout === void 0 ? void 0 : layout.textSize, metrics.textSize);
374
+ const stateTextLineHeight = resolvePositiveNumber(layout === null || layout === void 0 ? void 0 : layout.textLineHeight, metrics.textLineHeight);
375
+ const stateTextInset = resolveNonNegativeNumber(layout === null || layout === void 0 ? void 0 : layout.textInset, metrics.textInset);
376
+ const labelGap = resolveNonNegativeNumber(layout === null || layout === void 0 ? void 0 : layout.labelGap, metrics.labelGap);
377
+ const hasStateText = (stateText === null || stateText === void 0 ? void 0 : stateText.checked) != null || (stateText === null || stateText === void 0 ? void 0 : stateText.unchecked) != null;
378
+ const maxStateTextWidth = Math.max(estimateStateTextWidth(stateText === null || stateText === void 0 ? void 0 : stateText.checked, stateTextSize), estimateStateTextWidth(stateText === null || stateText === void 0 ? void 0 : stateText.unchecked, stateTextSize));
379
+ const stateTextSlotWidth = hasStateText
380
+ ? Math.max(metrics.textSlotMinWidth, maxStateTextWidth + stateTextSize * STATE_TEXT_WIDTH_GUARD_FACTOR + stateTextInset * 2)
381
+ : 0;
382
+ const trackWidth = hasStateText
383
+ ? Math.max(baseTrackWidth, thumbSize + resolvedThumbInset + stateTextSlotWidth)
384
+ : baseTrackWidth;
385
+ const travel = Math.max(0, trackWidth - thumbSize - resolvedThumbInset * 2);
386
+ const thumbStart = isRTL ? trackWidth - thumbSize - resolvedThumbInset : resolvedThumbInset;
387
+ const travelDirection = isRTL ? -1 : 1;
388
+ const trackRadius = Math.max(0, (_a = layout === null || layout === void 0 ? void 0 : layout.radius) !== null && _a !== void 0 ? _a : trackHeight / 2);
389
+ const thumbRadius = thumbSize / 2;
390
+ const defaultHitSlop = React.useMemo(() => resolveHitSlop(trackWidth, trackHeight, metrics.minTouchTarget), [metrics.minTouchTarget, trackHeight, trackWidth]);
391
+ const thumbShadowStyle = React.useMemo(() => ({
392
+ shadowColor: '#000000',
393
+ shadowOffset: { width: 0, height: (0, zkit_tools_1.wp)(1) },
394
+ shadowOpacity: disabled ? 0 : scheme === 'dark' ? 0.28 : 0.14,
395
+ shadowRadius: disabled ? 0 : (0, zkit_tools_1.wp)(4),
396
+ elevation: disabled ? 0 : (0, zkit_tools_1.wp)(1),
397
+ }), [disabled, scheme]);
398
+ const webCursorStyle = React.useMemo(() => resolveWebCursorStyle(interactionDisabled), [interactionDisabled]);
399
+ const resolvedDuration = resolveDuration(duration);
400
+ const valueTiming = React.useMemo(() => toTimingConfig(resolvedDuration), [resolvedDuration]);
401
+ const pressInTiming = React.useMemo(() => toTimingConfig(PRESS_IN_DURATION), []);
402
+ const pressOutTiming = React.useMemo(() => toTimingConfig(PRESS_OUT_DURATION), []);
403
+ const focusTiming = React.useMemo(() => toTimingConfig(FOCUS_DURATION), []);
404
+ const progressSv = (0, react_native_reanimated_1.useSharedValue)(checked ? 1 : 0);
405
+ const pressSv = (0, react_native_reanimated_1.useSharedValue)(0);
406
+ const focusSv = (0, react_native_reanimated_1.useSharedValue)(0);
407
+ React.useEffect(() => {
408
+ if (!isControlled)
409
+ return;
410
+ progressSv.value = (0, react_native_reanimated_1.withTiming)(checked ? 1 : 0, valueTiming);
411
+ }, [checked, isControlled, progressSv, valueTiming]);
412
+ React.useEffect(() => {
413
+ if (interactive)
414
+ return;
415
+ pressSv.value = (0, react_native_reanimated_1.withTiming)(0, pressOutTiming);
416
+ focusSv.value = (0, react_native_reanimated_1.withTiming)(0, focusTiming);
417
+ }, [focusSv, focusTiming, interactive, pressOutTiming, pressSv]);
418
+ const commitChecked = React.useCallback((next) => {
419
+ if (!isControlled) {
420
+ checkedRef.current = next;
421
+ progressSv.value = (0, react_native_reanimated_1.withTiming)(next ? 1 : 0, valueTiming);
422
+ setUncontrolledChecked(next);
423
+ }
424
+ onCheckedChange === null || onCheckedChange === void 0 ? void 0 : onCheckedChange(next);
425
+ }, [isControlled, onCheckedChange, progressSv, valueTiming]);
426
+ const toggle = React.useCallback(() => {
427
+ if (interactionDisabled)
428
+ return;
429
+ commitChecked(!checkedRef.current);
430
+ }, [commitChecked, interactionDisabled]);
431
+ const handlePress = React.useCallback((event) => {
432
+ if (!interactionDisabled) {
433
+ commitChecked(!checkedRef.current);
434
+ }
435
+ onPress === null || onPress === void 0 ? void 0 : onPress(event);
436
+ }, [commitChecked, interactionDisabled, onPress]);
437
+ const handlePressIn = React.useCallback((event) => {
438
+ if (!interactionDisabled) {
439
+ pressSv.value = (0, react_native_reanimated_1.withTiming)(1, pressInTiming);
440
+ }
441
+ onPressIn === null || onPressIn === void 0 ? void 0 : onPressIn(event);
442
+ }, [interactionDisabled, onPressIn, pressInTiming, pressSv]);
443
+ const handlePressOut = React.useCallback((event) => {
444
+ pressSv.value = (0, react_native_reanimated_1.withTiming)(0, pressOutTiming);
445
+ onPressOut === null || onPressOut === void 0 ? void 0 : onPressOut(event);
446
+ }, [onPressOut, pressOutTiming, pressSv]);
447
+ const handleFocus = React.useCallback((event) => {
448
+ if (!interactionDisabled) {
449
+ focusSv.value = (0, react_native_reanimated_1.withTiming)(1, focusTiming);
450
+ }
451
+ onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
452
+ }, [focusSv, focusTiming, interactionDisabled, onFocus]);
453
+ const handleBlur = React.useCallback((event) => {
454
+ focusSv.value = (0, react_native_reanimated_1.withTiming)(0, focusTiming);
455
+ onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
456
+ }, [focusSv, focusTiming, onBlur]);
457
+ const visualAnimatedStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => {
458
+ const pressedOpacity = (0, react_native_reanimated_1.interpolate)(pressSv.value, [0, 1], [1, PRESSED_OPACITY]);
459
+ return { opacity: pressedOpacity };
460
+ });
461
+ const focusRingAnimatedStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => {
462
+ const opacity = (0, react_native_reanimated_1.interpolate)(focusSv.value, [0, 1], [0, 1]);
463
+ const scale = (0, react_native_reanimated_1.interpolate)(focusSv.value, [0, 1], [0.96, 1]);
464
+ return {
465
+ opacity,
466
+ transform: [{ scale }],
467
+ };
468
+ });
469
+ const checkedTrackAnimatedStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => {
470
+ return { opacity: progressSv.value };
471
+ });
472
+ const thumbAnimatedStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => {
473
+ if (!thumbColorChanges) {
474
+ return {
475
+ transform: [{ translateX: travel * travelDirection * progressSv.value }],
476
+ };
477
+ }
478
+ return {
479
+ backgroundColor: (0, react_native_reanimated_1.interpolateColor)(progressSv.value, [0, 1], [visualUncheckedThumbColor, visualCheckedThumbColor]),
480
+ transform: [{ translateX: travel * travelDirection * progressSv.value }],
481
+ };
482
+ }, [thumbColorChanges, travel, travelDirection, visualCheckedThumbColor, visualUncheckedThumbColor]);
483
+ const checkedTextAnimatedStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => {
484
+ return { opacity: progressSv.value };
485
+ });
486
+ const uncheckedTextAnimatedStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => {
487
+ return { opacity: 1 - progressSv.value };
488
+ });
489
+ const checkedTextSlotStyle = React.useMemo(() => isRTL
490
+ ? {
491
+ left: thumbSize + resolvedThumbInset,
492
+ right: 0,
493
+ paddingLeft: stateTextInset,
494
+ paddingRight: stateTextInset,
495
+ }
496
+ : {
497
+ left: 0,
498
+ right: thumbSize + resolvedThumbInset,
499
+ paddingLeft: stateTextInset,
500
+ paddingRight: stateTextInset,
501
+ }, [isRTL, resolvedThumbInset, stateTextInset, thumbSize]);
502
+ const uncheckedTextSlotStyle = React.useMemo(() => isRTL
503
+ ? {
504
+ left: 0,
505
+ right: thumbSize + resolvedThumbInset,
506
+ paddingLeft: stateTextInset,
507
+ paddingRight: stateTextInset,
508
+ }
509
+ : {
510
+ left: thumbSize + resolvedThumbInset,
511
+ right: 0,
512
+ paddingLeft: stateTextInset,
513
+ paddingRight: stateTextInset,
514
+ }, [isRTL, resolvedThumbInset, stateTextInset, thumbSize]);
515
+ const slot = React.useMemo(() => ({
516
+ checked,
517
+ disabled: interactionDisabled,
518
+ loading,
519
+ interactive,
520
+ size,
521
+ tone,
522
+ toggle,
523
+ }), [checked, interactionDisabled, interactive, loading, size, tone, toggle]);
524
+ const renderedContent = React.useMemo(() => {
525
+ if (isRenderProp(children))
526
+ return children(slot);
527
+ if (children != null)
528
+ return children;
529
+ if (label == null && description == null)
530
+ return null;
531
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.copy, children: [label != null ? (isPrimitiveText(label) ? ((0, jsx_runtime_1.jsx)(Text_1.Text, { disabled: interactionDisabled, numberOfLines: 1, variant: "label", style: labelStyle, children: label })) : (label)) : null, description != null ? (isPrimitiveText(description) ? ((0, jsx_runtime_1.jsx)(Text_1.Text, { disabled: interactionDisabled, numberOfLines: 2, tone: interactionDisabled ? 'disabled' : 'muted', variant: "caption", style: descriptionStyle, children: description })) : (description)) : null] }));
532
+ }, [children, description, descriptionStyle, interactionDisabled, label, labelStyle, slot]);
533
+ const hasContent = renderedContent != null;
534
+ const inferredAccessibilityLabel = isPrimitiveText(label) ? String(label) : undefined;
535
+ const resolvedAccessibilityValue = accessibilityValue !== null && accessibilityValue !== void 0 ? accessibilityValue : (hasStateText
536
+ ? {
537
+ text: checked ? ((_b = stateText === null || stateText === void 0 ? void 0 : stateText.checked) !== null && _b !== void 0 ? _b : '') : ((_c = stateText === null || stateText === void 0 ? void 0 : stateText.unchecked) !== null && _c !== void 0 ? _c : ''),
538
+ }
539
+ : undefined);
540
+ const resolvedStyle = React.useCallback((state) => {
541
+ const userStyle = typeof style === 'function' ? style(state) : style;
542
+ return [styles.root, webCursorStyle, userStyle];
543
+ }, [style, webCursorStyle]);
544
+ const switchNode = ((0, jsx_runtime_1.jsxs)(react_native_reanimated_1.default.View, { style: [
545
+ styles.visual,
546
+ {
547
+ width: trackWidth,
548
+ height: trackHeight,
549
+ borderRadius: trackRadius,
550
+ },
551
+ visualAnimatedStyle,
552
+ ], children: [(0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { pointerEvents: "none", style: [
553
+ styles.focusRing,
554
+ {
555
+ top: -metrics.focusRingOffset,
556
+ bottom: -metrics.focusRingOffset,
557
+ left: -metrics.focusRingOffset,
558
+ right: -metrics.focusRingOffset,
559
+ borderWidth: metrics.focusRingWidth,
560
+ borderRadius: trackRadius + metrics.focusRingOffset,
561
+ borderColor: focusRingColor,
562
+ },
563
+ focusRingAnimatedStyle,
564
+ ] }), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: [
565
+ react_native_1.StyleSheet.absoluteFillObject,
566
+ {
567
+ borderRadius: trackRadius,
568
+ backgroundColor: visualUncheckedTrackColor,
569
+ },
570
+ trackStyle,
571
+ ] }), (0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { pointerEvents: "none", style: [
572
+ react_native_1.StyleSheet.absoluteFillObject,
573
+ {
574
+ borderRadius: trackRadius,
575
+ backgroundColor: visualCheckedTrackColor,
576
+ },
577
+ checkedTrackAnimatedStyle,
578
+ ] }), hasStateText ? ((0, jsx_runtime_1.jsxs)(react_native_1.View, { pointerEvents: "none", style: styles.stateTextLayer, children: [(0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { style: [styles.stateTextSlot, checkedTextSlotStyle, checkedTextAnimatedStyle], children: (0, jsx_runtime_1.jsx)(Text_1.Text, { allowFontScaling: false, ellipsizeMode: "clip", numberOfLines: 1, style: [
579
+ styles.stateText,
580
+ {
581
+ color: visualCheckedTextColor,
582
+ fontSize: stateTextSize,
583
+ lineHeight: stateTextLineHeight,
584
+ },
585
+ stateTextStyle,
586
+ ], children: (_d = stateText === null || stateText === void 0 ? void 0 : stateText.checked) !== null && _d !== void 0 ? _d : '' }) }), (0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { style: [styles.stateTextSlot, uncheckedTextSlotStyle, uncheckedTextAnimatedStyle], children: (0, jsx_runtime_1.jsx)(Text_1.Text, { allowFontScaling: false, ellipsizeMode: "clip", numberOfLines: 1, style: [
587
+ styles.stateText,
588
+ {
589
+ color: visualUncheckedTextColor,
590
+ fontSize: stateTextSize,
591
+ lineHeight: stateTextLineHeight,
592
+ },
593
+ stateTextStyle,
594
+ ], children: (_e = stateText === null || stateText === void 0 ? void 0 : stateText.unchecked) !== null && _e !== void 0 ? _e : '' }) })] })) : null, (0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { style: [
595
+ styles.thumb,
596
+ {
597
+ width: thumbSize,
598
+ height: thumbSize,
599
+ left: thumbStart,
600
+ top: resolvedThumbInset,
601
+ borderRadius: thumbRadius,
602
+ backgroundColor: visualUncheckedThumbColor,
603
+ },
604
+ thumbAnimatedStyle,
605
+ thumbShadowStyle,
606
+ thumbStyle,
607
+ ], children: loading ? (loadingIndicator !== null && loadingIndicator !== void 0 ? loadingIndicator : ((0, jsx_runtime_1.jsx)(LoadingSpinner_1.LoadingSpinner, { size: Math.max((0, zkit_tools_1.wp)(12), thumbSize * 0.58), color: loadingColor }))) : null })] }));
608
+ const contentNode = hasContent ? ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: [
609
+ styles.content,
610
+ contentStyle,
611
+ ], children: labelPlacement === 'start' ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_native_1.View, { style: [styles.contentSlot, { marginEnd: labelGap }], children: renderedContent }), switchNode] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [switchNode, (0, jsx_runtime_1.jsx)(react_native_1.View, { style: [styles.contentSlot, { marginStart: labelGap }], children: renderedContent })] })) })) : (switchNode);
612
+ return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { ...pressableProps, ref: ref, accessibilityLabel: accessibilityLabel !== null && accessibilityLabel !== void 0 ? accessibilityLabel : inferredAccessibilityLabel, accessibilityRole: "switch", accessibilityState: {
613
+ ...accessibilityState,
614
+ checked,
615
+ disabled: Boolean(interactionDisabled),
616
+ busy: Boolean(loading || (accessibilityState === null || accessibilityState === void 0 ? void 0 : accessibilityState.busy)),
617
+ }, accessibilityValue: resolvedAccessibilityValue, disabled: interactionDisabled, hitSlop: hitSlop !== null && hitSlop !== void 0 ? hitSlop : defaultHitSlop, onBlur: handleBlur, onFocus: handleFocus, onPress: handlePress, onPressIn: handlePressIn, onPressOut: handlePressOut, style: resolvedStyle, testID: testID, children: contentNode }));
618
+ }
619
+ const SwitchWithRef = React.forwardRef(SwitchImpl);
620
+ SwitchWithRef.displayName = 'Switch';
621
+ exports.Switch = React.memo(SwitchWithRef);
622
+ exports.Switch.displayName = 'Switch';
623
+ const styles = react_native_1.StyleSheet.create({
624
+ root: {
625
+ alignSelf: 'flex-start',
626
+ },
627
+ content: {
628
+ alignItems: 'center',
629
+ flexDirection: 'row',
630
+ minWidth: 0,
631
+ },
632
+ contentSlot: {
633
+ flexGrow: 1,
634
+ flexShrink: 1,
635
+ minWidth: 0,
636
+ },
637
+ copy: {
638
+ flexShrink: 1,
639
+ minWidth: 0,
640
+ },
641
+ visual: {
642
+ flexShrink: 0,
643
+ overflow: 'visible',
644
+ },
645
+ focusRing: {
646
+ position: 'absolute',
647
+ },
648
+ stateTextLayer: {
649
+ ...react_native_1.StyleSheet.absoluteFillObject,
650
+ alignItems: 'center',
651
+ justifyContent: 'center',
652
+ },
653
+ stateTextSlot: {
654
+ ...react_native_1.StyleSheet.absoluteFillObject,
655
+ alignItems: 'center',
656
+ justifyContent: 'center',
657
+ overflow: 'hidden',
658
+ },
659
+ stateText: {
660
+ includeFontPadding: false,
661
+ fontWeight: '600',
662
+ margin: 0,
663
+ padding: 0,
664
+ textAlign: 'center',
665
+ },
666
+ thumb: {
667
+ alignItems: 'center',
668
+ justifyContent: 'center',
669
+ position: 'absolute',
670
+ },
671
+ });