@getcortexlabs/mavis 0.1.0-alpha.3 → 0.1.0-alpha.4

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 (370) hide show
  1. package/README.md +7 -5
  2. package/dist/native/avatar-image.d.ts +4 -0
  3. package/dist/native/avatar-image.d.ts.map +1 -0
  4. package/dist/native/avatar-image.js +12 -0
  5. package/dist/native/avatar-image.js.map +1 -0
  6. package/dist/native/avatar-label.android.d.ts +9 -0
  7. package/dist/native/avatar-label.android.d.ts.map +1 -0
  8. package/dist/native/avatar-label.android.js +9 -0
  9. package/dist/native/avatar-label.android.js.map +1 -0
  10. package/dist/native/avatar-label.d.ts +2 -0
  11. package/dist/native/avatar-label.d.ts.map +1 -0
  12. package/dist/native/avatar-label.js +2 -0
  13. package/dist/native/avatar-label.js.map +1 -0
  14. package/dist/native/box.ios.d.ts.map +1 -1
  15. package/dist/native/box.ios.js +16 -1
  16. package/dist/native/box.ios.js.map +1 -1
  17. package/dist/native/button.ios.d.ts +9 -1
  18. package/dist/native/button.ios.d.ts.map +1 -1
  19. package/dist/native/button.ios.js +17 -1
  20. package/dist/native/button.ios.js.map +1 -1
  21. package/dist/native/checkbox.android.d.ts +7 -0
  22. package/dist/native/checkbox.android.d.ts.map +1 -0
  23. package/dist/native/checkbox.android.js +26 -0
  24. package/dist/native/checkbox.android.js.map +1 -0
  25. package/dist/native/checkbox.d.ts +7 -0
  26. package/dist/native/checkbox.d.ts.map +1 -0
  27. package/dist/native/checkbox.js +7 -0
  28. package/dist/native/checkbox.js.map +1 -0
  29. package/dist/native/composed-button.android.d.ts +4 -0
  30. package/dist/native/composed-button.android.d.ts.map +1 -0
  31. package/dist/native/composed-button.android.js +53 -0
  32. package/dist/native/composed-button.android.js.map +1 -0
  33. package/dist/native/composed-button.d.ts +3 -0
  34. package/dist/native/composed-button.d.ts.map +1 -0
  35. package/dist/native/composed-button.js +4 -0
  36. package/dist/native/composed-button.js.map +1 -0
  37. package/dist/native/dialog.android.d.ts +12 -0
  38. package/dist/native/dialog.android.d.ts.map +1 -0
  39. package/dist/native/dialog.android.js +46 -0
  40. package/dist/native/dialog.android.js.map +1 -0
  41. package/dist/native/dialog.d.ts +12 -0
  42. package/dist/native/dialog.d.ts.map +1 -0
  43. package/dist/native/dialog.ios.d.ts +12 -0
  44. package/dist/native/dialog.ios.d.ts.map +1 -0
  45. package/dist/native/dialog.ios.js +13 -0
  46. package/dist/native/dialog.ios.js.map +1 -0
  47. package/dist/native/dialog.js +4 -0
  48. package/dist/native/dialog.js.map +1 -0
  49. package/dist/native/dynamic-type.d.ts +15 -0
  50. package/dist/native/dynamic-type.d.ts.map +1 -0
  51. package/dist/native/dynamic-type.js +47 -0
  52. package/dist/native/dynamic-type.js.map +1 -0
  53. package/dist/native/flex-layout.ios.d.ts +5 -0
  54. package/dist/native/flex-layout.ios.d.ts.map +1 -1
  55. package/dist/native/flex-layout.ios.js +63 -2
  56. package/dist/native/flex-layout.ios.js.map +1 -1
  57. package/dist/native/input-action.d.ts +5 -0
  58. package/dist/native/input-action.d.ts.map +1 -0
  59. package/dist/native/input-action.js +13 -0
  60. package/dist/native/input-action.js.map +1 -0
  61. package/dist/native/keyboard-dismiss.ios.d.ts.map +1 -1
  62. package/dist/native/keyboard-dismiss.ios.js +3 -0
  63. package/dist/native/keyboard-dismiss.ios.js.map +1 -1
  64. package/dist/native/label.android.d.ts +12 -0
  65. package/dist/native/label.android.d.ts.map +1 -0
  66. package/dist/native/label.android.js +19 -0
  67. package/dist/native/label.android.js.map +1 -0
  68. package/dist/native/label.ios.d.ts +10 -1
  69. package/dist/native/label.ios.d.ts.map +1 -1
  70. package/dist/native/label.ios.js +25 -1
  71. package/dist/native/label.ios.js.map +1 -1
  72. package/dist/native/motion-surface.d.ts +9 -0
  73. package/dist/native/motion-surface.d.ts.map +1 -0
  74. package/dist/native/motion-surface.js +119 -0
  75. package/dist/native/motion-surface.js.map +1 -0
  76. package/dist/native/press.d.ts +5 -2
  77. package/dist/native/press.d.ts.map +1 -1
  78. package/dist/native/press.js +52 -8
  79. package/dist/native/press.js.map +1 -1
  80. package/dist/native/progress.d.ts +7 -0
  81. package/dist/native/progress.d.ts.map +1 -0
  82. package/dist/native/progress.js +77 -0
  83. package/dist/native/progress.js.map +1 -0
  84. package/dist/native/scroll-motion.d.ts +11 -0
  85. package/dist/native/scroll-motion.d.ts.map +1 -0
  86. package/dist/native/scroll-motion.js +94 -0
  87. package/dist/native/scroll-motion.js.map +1 -0
  88. package/dist/native/segmented.d.ts +14 -0
  89. package/dist/native/segmented.d.ts.map +1 -0
  90. package/dist/native/segmented.js +86 -0
  91. package/dist/native/segmented.js.map +1 -0
  92. package/dist/native/sheet.android.d.ts +5 -1
  93. package/dist/native/sheet.android.d.ts.map +1 -1
  94. package/dist/native/sheet.android.js +2 -2
  95. package/dist/native/sheet.android.js.map +1 -1
  96. package/dist/native/sheet.d.ts +5 -1
  97. package/dist/native/sheet.d.ts.map +1 -1
  98. package/dist/native/sheet.ios.d.ts +5 -1
  99. package/dist/native/sheet.ios.d.ts.map +1 -1
  100. package/dist/native/sheet.ios.js +12 -3
  101. package/dist/native/sheet.ios.js.map +1 -1
  102. package/dist/native/sheet.js +2 -2
  103. package/dist/native/sheet.js.map +1 -1
  104. package/dist/native/tabs.android.d.ts +3 -0
  105. package/dist/native/tabs.android.d.ts.map +1 -0
  106. package/dist/native/tabs.android.js +29 -0
  107. package/dist/native/tabs.android.js.map +1 -0
  108. package/dist/native/tabs.d.ts +3 -0
  109. package/dist/native/tabs.d.ts.map +1 -0
  110. package/dist/native/tabs.js +4 -0
  111. package/dist/native/tabs.js.map +1 -0
  112. package/dist/native/text-field.android.d.ts +1 -0
  113. package/dist/native/text-field.android.d.ts.map +1 -1
  114. package/dist/native/text-field.android.js +13 -0
  115. package/dist/native/text-field.android.js.map +1 -1
  116. package/dist/native/text-field.ios.d.ts +9 -0
  117. package/dist/native/text-field.ios.d.ts.map +1 -0
  118. package/dist/native/text-field.ios.js +52 -0
  119. package/dist/native/text-field.ios.js.map +1 -0
  120. package/dist/native/text-view.ios.d.ts +7 -0
  121. package/dist/native/text-view.ios.d.ts.map +1 -0
  122. package/dist/native/text-view.ios.js +10 -0
  123. package/dist/native/text-view.ios.js.map +1 -0
  124. package/dist/native/toast.android.d.ts +4 -0
  125. package/dist/native/toast.android.d.ts.map +1 -0
  126. package/dist/native/toast.android.js +10 -0
  127. package/dist/native/toast.android.js.map +1 -0
  128. package/dist/native/toast.d.ts +4 -0
  129. package/dist/native/toast.d.ts.map +1 -0
  130. package/dist/native/toast.ios.d.ts +4 -0
  131. package/dist/native/toast.ios.d.ts.map +1 -0
  132. package/dist/native/toast.ios.js +8 -0
  133. package/dist/native/toast.ios.js.map +1 -0
  134. package/dist/native/toast.js +5 -0
  135. package/dist/native/toast.js.map +1 -0
  136. package/dist/vue/components/ChoiceControl.d.ts +101 -0
  137. package/dist/vue/components/ChoiceControl.d.ts.map +1 -0
  138. package/dist/vue/components/ChoiceControl.js +196 -0
  139. package/dist/vue/components/ChoiceControl.js.map +1 -0
  140. package/dist/vue/components/MAccordion.d.ts +109 -0
  141. package/dist/vue/components/MAccordion.d.ts.map +1 -0
  142. package/dist/vue/components/MAccordion.js +83 -0
  143. package/dist/vue/components/MAccordion.js.map +1 -0
  144. package/dist/vue/components/MAlert.d.ts +99 -0
  145. package/dist/vue/components/MAlert.d.ts.map +1 -0
  146. package/dist/vue/components/MAlert.js +126 -0
  147. package/dist/vue/components/MAlert.js.map +1 -0
  148. package/dist/vue/components/MAvatar.d.ts +74 -0
  149. package/dist/vue/components/MAvatar.d.ts.map +1 -0
  150. package/dist/vue/components/MAvatar.js +86 -0
  151. package/dist/vue/components/MAvatar.js.map +1 -0
  152. package/dist/vue/components/MBadge.d.ts +64 -0
  153. package/dist/vue/components/MBadge.d.ts.map +1 -0
  154. package/dist/vue/components/MBadge.js +30 -0
  155. package/dist/vue/components/MBadge.js.map +1 -0
  156. package/dist/vue/components/MButton.d.ts +57 -5
  157. package/dist/vue/components/MButton.d.ts.map +1 -1
  158. package/dist/vue/components/MButton.js +129 -11
  159. package/dist/vue/components/MButton.js.map +1 -1
  160. package/dist/vue/components/MCard.d.ts +25 -7
  161. package/dist/vue/components/MCard.d.ts.map +1 -1
  162. package/dist/vue/components/MCard.js +14 -4
  163. package/dist/vue/components/MCard.js.map +1 -1
  164. package/dist/vue/components/MCheckbox.d.ts +93 -0
  165. package/dist/vue/components/MCheckbox.d.ts.map +1 -0
  166. package/dist/vue/components/MCheckbox.js +26 -0
  167. package/dist/vue/components/MCheckbox.js.map +1 -0
  168. package/dist/vue/components/MChip.d.ts +107 -0
  169. package/dist/vue/components/MChip.d.ts.map +1 -0
  170. package/dist/vue/components/MChip.js +120 -0
  171. package/dist/vue/components/MChip.js.map +1 -0
  172. package/dist/vue/components/MDialog.d.ts +95 -0
  173. package/dist/vue/components/MDialog.d.ts.map +1 -0
  174. package/dist/vue/components/MDialog.js +245 -0
  175. package/dist/vue/components/MDialog.js.map +1 -0
  176. package/dist/vue/components/MEmptyState.d.ts +107 -0
  177. package/dist/vue/components/MEmptyState.d.ts.map +1 -0
  178. package/dist/vue/components/MEmptyState.js +79 -0
  179. package/dist/vue/components/MEmptyState.js.map +1 -0
  180. package/dist/vue/components/MInput.d.ts +63 -8
  181. package/dist/vue/components/MInput.d.ts.map +1 -1
  182. package/dist/vue/components/MInput.js +88 -14
  183. package/dist/vue/components/MInput.js.map +1 -1
  184. package/dist/vue/components/MListItem.d.ts +92 -0
  185. package/dist/vue/components/MListItem.d.ts.map +1 -0
  186. package/dist/vue/components/MListItem.js +53 -0
  187. package/dist/vue/components/MListItem.js.map +1 -0
  188. package/dist/vue/components/MProgress.d.ts +112 -0
  189. package/dist/vue/components/MProgress.d.ts.map +1 -0
  190. package/dist/vue/components/MProgress.js +75 -0
  191. package/dist/vue/components/MProgress.js.map +1 -0
  192. package/dist/vue/components/MRadioGroup.d.ts +93 -0
  193. package/dist/vue/components/MRadioGroup.d.ts.map +1 -0
  194. package/dist/vue/components/MRadioGroup.js +57 -0
  195. package/dist/vue/components/MRadioGroup.js.map +1 -0
  196. package/dist/vue/components/MReveal.d.ts +2 -2
  197. package/dist/vue/components/MReveal.d.ts.map +1 -1
  198. package/dist/vue/components/MReveal.js +5 -7
  199. package/dist/vue/components/MReveal.js.map +1 -1
  200. package/dist/vue/components/MScreen.d.ts +9 -0
  201. package/dist/vue/components/MScreen.d.ts.map +1 -1
  202. package/dist/vue/components/MScreen.js +19 -4
  203. package/dist/vue/components/MScreen.js.map +1 -1
  204. package/dist/vue/components/MSegmentedControl.d.ts +85 -0
  205. package/dist/vue/components/MSegmentedControl.d.ts.map +1 -0
  206. package/dist/vue/components/MSegmentedControl.js +172 -0
  207. package/dist/vue/components/MSegmentedControl.js.map +1 -0
  208. package/dist/vue/components/MSelect.d.ts +130 -0
  209. package/dist/vue/components/MSelect.d.ts.map +1 -0
  210. package/dist/vue/components/MSelect.js +158 -0
  211. package/dist/vue/components/MSelect.js.map +1 -0
  212. package/dist/vue/components/MSeparator.d.ts +54 -0
  213. package/dist/vue/components/MSeparator.d.ts.map +1 -0
  214. package/dist/vue/components/MSeparator.js +36 -0
  215. package/dist/vue/components/MSeparator.js.map +1 -0
  216. package/dist/vue/components/MSheet.d.ts +10 -4
  217. package/dist/vue/components/MSheet.d.ts.map +1 -1
  218. package/dist/vue/components/MSheet.js +66 -34
  219. package/dist/vue/components/MSheet.js.map +1 -1
  220. package/dist/vue/components/MSkeleton.d.ts +70 -0
  221. package/dist/vue/components/MSkeleton.d.ts.map +1 -0
  222. package/dist/vue/components/MSkeleton.js +87 -0
  223. package/dist/vue/components/MSkeleton.js.map +1 -0
  224. package/dist/vue/components/MSlider.d.ts +1 -1
  225. package/dist/vue/components/MSlider.d.ts.map +1 -1
  226. package/dist/vue/components/MSlider.js +2 -1
  227. package/dist/vue/components/MSlider.js.map +1 -1
  228. package/dist/vue/components/MSwitch.d.ts +79 -0
  229. package/dist/vue/components/MSwitch.d.ts.map +1 -0
  230. package/dist/vue/components/MSwitch.js +163 -0
  231. package/dist/vue/components/MSwitch.js.map +1 -0
  232. package/dist/vue/components/MTabs.d.ts +91 -0
  233. package/dist/vue/components/MTabs.d.ts.map +1 -0
  234. package/dist/vue/components/MTabs.js +245 -0
  235. package/dist/vue/components/MTabs.js.map +1 -0
  236. package/dist/vue/components/MText.d.ts +17 -8
  237. package/dist/vue/components/MText.d.ts.map +1 -1
  238. package/dist/vue/components/MText.js +43 -17
  239. package/dist/vue/components/MText.js.map +1 -1
  240. package/dist/vue/components/MToast.d.ts +23 -0
  241. package/dist/vue/components/MToast.d.ts.map +1 -0
  242. package/dist/vue/components/MToast.js +242 -0
  243. package/dist/vue/components/MToast.js.map +1 -0
  244. package/dist/vue/components/layout.d.ts +6 -6
  245. package/dist/vue/index.d.ts +24 -3
  246. package/dist/vue/index.d.ts.map +1 -1
  247. package/dist/vue/index.js +43 -4
  248. package/dist/vue/index.js.map +1 -1
  249. package/dist/vue/layers.d.ts +2 -0
  250. package/dist/vue/layers.d.ts.map +1 -1
  251. package/dist/vue/layers.js.map +1 -1
  252. package/dist/vue/reveal-motion.d.ts +13 -0
  253. package/dist/vue/reveal-motion.d.ts.map +1 -0
  254. package/dist/vue/reveal-motion.js +55 -0
  255. package/dist/vue/reveal-motion.js.map +1 -0
  256. package/dist/vue/use-motion-surface.d.ts +8 -0
  257. package/dist/vue/use-motion-surface.d.ts.map +1 -0
  258. package/dist/vue/use-motion-surface.js +75 -0
  259. package/dist/vue/use-motion-surface.js.map +1 -0
  260. package/dist/vue/use-press.d.ts +1 -1
  261. package/dist/vue/use-press.d.ts.map +1 -1
  262. package/dist/vue/use-press.js +12 -4
  263. package/dist/vue/use-press.js.map +1 -1
  264. package/dist/vue/use-scroll-motion.d.ts +7 -0
  265. package/dist/vue/use-scroll-motion.d.ts.map +1 -0
  266. package/dist/vue/use-scroll-motion.js +30 -0
  267. package/dist/vue/use-scroll-motion.js.map +1 -0
  268. package/package.json +3 -3
  269. package/platforms/android/java/com/mavis/ui/Box.java +3 -1
  270. package/platforms/android/java/com/mavis/ui/ContentWidth.java +77 -0
  271. package/platforms/android/java/com/mavis/ui/FlexLayout.java +5 -1
  272. package/src/native/avatar-image.ts +9 -0
  273. package/src/native/avatar-label.android.ts +14 -0
  274. package/src/native/avatar-label.ts +1 -0
  275. package/src/native/box.ios.ts +21 -1
  276. package/src/native/button.ios.ts +40 -2
  277. package/src/native/checkbox.android.ts +35 -0
  278. package/src/native/checkbox.ts +9 -0
  279. package/src/native/composed-button.android.ts +74 -0
  280. package/src/native/composed-button.ts +9 -0
  281. package/src/native/dialog.android.ts +56 -0
  282. package/src/native/dialog.ios.ts +23 -0
  283. package/src/native/dialog.ts +10 -0
  284. package/src/native/dynamic-type.ts +71 -0
  285. package/src/native/flex-layout.ios.ts +74 -2
  286. package/src/native/input-action.ts +15 -0
  287. package/src/native/keyboard-dismiss.ios.ts +2 -0
  288. package/src/native/label.android.ts +27 -0
  289. package/src/native/label.ios.ts +40 -1
  290. package/src/native/motion-surface.ts +137 -0
  291. package/src/native/press.ts +52 -10
  292. package/src/native/progress.ts +78 -0
  293. package/src/native/scroll-motion.ts +101 -0
  294. package/src/native/segmented.ts +95 -0
  295. package/src/native/sheet.android.ts +2 -2
  296. package/src/native/sheet.ios.ts +12 -3
  297. package/src/native/sheet.ts +2 -2
  298. package/src/native/tabs.android.ts +58 -0
  299. package/src/native/tabs.ts +8 -0
  300. package/src/native/text-field.android.ts +19 -0
  301. package/src/native/text-field.ios.ts +53 -0
  302. package/src/native/text-view.ios.ts +10 -0
  303. package/src/native/toast.android.ts +9 -0
  304. package/src/native/toast.ios.ts +13 -0
  305. package/src/native/toast.ts +6 -0
  306. package/src/vue/components/ChoiceControl.ts +238 -0
  307. package/src/vue/components/MAccordion.ts +123 -0
  308. package/src/vue/components/MAlert.ts +156 -0
  309. package/src/vue/components/MAvatar.ts +103 -0
  310. package/src/vue/components/MBadge.ts +34 -0
  311. package/src/vue/components/MButton.ts +176 -9
  312. package/src/vue/components/MCard.ts +23 -3
  313. package/src/vue/components/MCheckbox.ts +25 -0
  314. package/src/vue/components/MChip.ts +134 -0
  315. package/src/vue/components/MDialog.ts +312 -0
  316. package/src/vue/components/MEmptyState.ts +96 -0
  317. package/src/vue/components/MInput.ts +96 -12
  318. package/src/vue/components/MListItem.ts +66 -0
  319. package/src/vue/components/MProgress.ts +94 -0
  320. package/src/vue/components/MRadioGroup.ts +64 -0
  321. package/src/vue/components/MReveal.ts +6 -7
  322. package/src/vue/components/MScreen.ts +21 -6
  323. package/src/vue/components/MSegmentedControl.ts +214 -0
  324. package/src/vue/components/MSelect.ts +185 -0
  325. package/src/vue/components/MSeparator.ts +40 -0
  326. package/src/vue/components/MSheet.ts +83 -43
  327. package/src/vue/components/MSkeleton.ts +100 -0
  328. package/src/vue/components/MSlider.ts +7 -1
  329. package/src/vue/components/MSwitch.ts +187 -0
  330. package/src/vue/components/MTabs.ts +302 -0
  331. package/src/vue/components/MText.ts +37 -6
  332. package/src/vue/components/MToast.ts +289 -0
  333. package/src/vue/index.ts +65 -2
  334. package/src/vue/layers.ts +2 -0
  335. package/src/vue/reveal-motion.ts +61 -0
  336. package/src/vue/use-motion-surface.ts +77 -0
  337. package/src/vue/use-press.ts +12 -4
  338. package/src/vue/use-scroll-motion.ts +31 -0
  339. package/dist/native/input-description.android.d.ts +0 -4
  340. package/dist/native/input-description.android.d.ts.map +0 -1
  341. package/dist/native/input-description.android.js +0 -18
  342. package/dist/native/input-description.android.js.map +0 -1
  343. package/dist/theme/resolve.d.ts +0 -3
  344. package/dist/theme/resolve.d.ts.map +0 -1
  345. package/dist/theme/resolve.js +0 -8
  346. package/dist/theme/resolve.js.map +0 -1
  347. package/dist/theme/themes.d.ts +0 -6
  348. package/dist/theme/themes.d.ts.map +0 -1
  349. package/dist/theme/themes.js +0 -83
  350. package/dist/theme/themes.js.map +0 -1
  351. package/dist/theme/types.d.ts +0 -50
  352. package/dist/theme/types.d.ts.map +0 -1
  353. package/dist/theme/types.js +0 -2
  354. package/dist/theme/types.js.map +0 -1
  355. package/dist/vue/global-components.d.ts +0 -21
  356. package/dist/vue/global-components.d.ts.map +0 -1
  357. package/dist/vue/global-components.js +0 -2
  358. package/dist/vue/global-components.js.map +0 -1
  359. package/dist/vue/layout-context.d.ts +0 -5
  360. package/dist/vue/layout-context.d.ts.map +0 -1
  361. package/dist/vue/layout-context.js +0 -7
  362. package/dist/vue/layout-context.js.map +0 -1
  363. package/dist/vue/text-content.d.ts +0 -4
  364. package/dist/vue/text-content.d.ts.map +0 -1
  365. package/dist/vue/text-content.js +0 -17
  366. package/dist/vue/text-content.js.map +0 -1
  367. package/dist/vue/theme.d.ts +0 -177
  368. package/dist/vue/theme.d.ts.map +0 -1
  369. package/dist/vue/theme.js +0 -17
  370. package/dist/vue/theme.js.map +0 -1
@@ -0,0 +1,100 @@
1
+ import { defineComponent, h, mergeProps, onBeforeUnmount, watch } from 'nativescript-vue'
2
+ import { Application, type EventData, type View } from '@nativescript/core'
3
+ import { animate, onReducedMotion, reducedMotion, set } from '@rafaelaugusto/jolt'
4
+ import { skeletonProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
5
+ import { MBox } from './layout.js'
6
+
7
+ export const MSkeleton = defineComponent({
8
+ name: 'MSkeleton',
9
+ inheritAttrs: false,
10
+ props: skeletonProps,
11
+ setup(props, { attrs }) {
12
+ const { theme } = useMavisTheme()
13
+ let view: View | undefined
14
+ let motion: ReturnType<typeof animate> | undefined
15
+ let pending: ReturnType<typeof setTimeout> | undefined
16
+ let offMotion: (() => void) | undefined
17
+ let suspended = Application.suspended
18
+
19
+ function stop() {
20
+ clearTimeout(pending)
21
+ pending = undefined
22
+ motion?.stop()
23
+ motion = undefined
24
+ if (view) set(view, { opacity: 1 })
25
+ }
26
+ function update() {
27
+ if (!view || suspended || !props.animated || reducedMotion()) {
28
+ stop()
29
+ return
30
+ }
31
+ if (motion || pending !== undefined) return
32
+ // Let loaded finish syncing native styles before attaching the opacity animation.
33
+ pending = setTimeout(() => {
34
+ pending = undefined
35
+ if (!view || suspended || !props.animated || reducedMotion()) return
36
+ motion = animate(
37
+ view,
38
+ { opacity: [1, 0.45, 1] },
39
+ { duration: 1600, ease: 'easeInOut', repeat: Infinity },
40
+ )
41
+ }, 0)
42
+ }
43
+
44
+ function suspend() {
45
+ suspended = true
46
+ stop()
47
+ }
48
+ function resume() {
49
+ suspended = false
50
+ update()
51
+ }
52
+ function release() {
53
+ stop()
54
+ offMotion?.()
55
+ offMotion = undefined
56
+ Application.off(Application.suspendEvent, suspend)
57
+ Application.off(Application.resumeEvent, resume)
58
+ view = undefined
59
+ }
60
+ function loaded(event: EventData) {
61
+ release()
62
+ view = event.object as View
63
+ suspended = Application.suspended
64
+ offMotion = onReducedMotion(update)
65
+ Application.on(Application.suspendEvent, suspend)
66
+ Application.on(Application.resumeEvent, resume)
67
+ update()
68
+ }
69
+ watch(() => props.animated, update, { flush: 'post' })
70
+ onBeforeUnmount(release)
71
+
72
+ return () =>
73
+ h(
74
+ MBox,
75
+ mergeProps(
76
+ {
77
+ style: {
78
+ alignSelf:
79
+ props.width === undefined || props.width === 'auto' ? 'stretch' : 'flex-start',
80
+ },
81
+ },
82
+ attrs,
83
+ {
84
+ id: props.id,
85
+ width: props.width,
86
+ height: props.height,
87
+ radius: props.radius,
88
+ grow: props.grow,
89
+ shrink: props.shrink,
90
+ backgroundColor: theme.value.colors.border,
91
+ accessible: false,
92
+ accessibilityHidden: true,
93
+ isUserInteractionEnabled: false,
94
+ onLoaded: loaded,
95
+ onUnloaded: release,
96
+ },
97
+ ),
98
+ )
99
+ },
100
+ })
@@ -1,5 +1,10 @@
1
1
  import { defineComponent, h, mergeProps, registerElement } from 'nativescript-vue'
2
- import { sliderProps, useMavisTheme, sliderEmits } from '@getcortexlabs/mavis-core/vue'
2
+ import {
3
+ useButtonAction,
4
+ sliderProps,
5
+ useMavisTheme,
6
+ sliderEmits,
7
+ } from '@getcortexlabs/mavis-core/vue'
3
8
  import { sliderScale } from '@getcortexlabs/mavis-core'
4
9
  import { isAndroid, type PropertyChangeData } from '@nativescript/core'
5
10
  import { MavisSlider } from '../../native/slider'
@@ -13,6 +18,7 @@ export const MSlider = defineComponent({
13
18
  props: sliderProps,
14
19
  emits: sliderEmits,
15
20
  setup(props, { attrs, emit }) {
21
+ useButtonAction()
16
22
  const { theme } = useMavisTheme()
17
23
  const nativeAttrs = useNativeViewAttrs(props)
18
24
  return () => {
@@ -0,0 +1,187 @@
1
+ import { isAndroid } from '@nativescript/core'
2
+ import { defineComponent, h, mergeProps, nextTick, onBeforeUnmount } from 'nativescript-vue'
3
+ import type {
4
+ EventData,
5
+ PropertyChangeData,
6
+ Switch,
7
+ TouchGestureEventData,
8
+ } from '@nativescript/core'
9
+ import {
10
+ useButtonAction,
11
+ switchProps,
12
+ switchEmits,
13
+ useMavisTheme,
14
+ } from '@getcortexlabs/mavis-core/vue'
15
+ import { MRow, MColumn } from './layout.js'
16
+ import { MText } from './MText.js'
17
+ import { useNativeViewAttrs } from '../accessibility.js'
18
+ import { usePressFeedback } from '../use-press.js'
19
+
20
+ export const MSwitch = defineComponent({
21
+ name: 'MSwitch',
22
+ inheritAttrs: false,
23
+ props: switchProps,
24
+ emits: switchEmits,
25
+ setup(props, { attrs, emit }) {
26
+ useButtonAction()
27
+ const { theme } = useMavisTheme()
28
+ const nativeAttrs = useNativeViewAttrs(props)
29
+ const feedback = usePressFeedback(() => !props.disabled, theme)
30
+ let control: Switch | undefined
31
+ let restoring = false
32
+ let revision = 0
33
+ let start: { x: number; y: number } | undefined
34
+ let verticalDrag = false
35
+ let touchEnd: ReturnType<typeof setTimeout> | undefined
36
+
37
+ function resetTouch() {
38
+ clearTimeout(touchEnd)
39
+ touchEnd = undefined
40
+ start = undefined
41
+ verticalDrag = false
42
+ }
43
+ function touch(event: TouchGestureEventData) {
44
+ if (event.action === 'down') {
45
+ resetTouch()
46
+ start = { x: event.getX(), y: event.getY() }
47
+ } else {
48
+ if (start) {
49
+ const x = Math.abs(event.getX() - start.x)
50
+ const y = Math.abs(event.getY() - start.y)
51
+ if (y > 8 && y > x) verticalDrag = true
52
+ }
53
+ if (event.action === 'cancel') verticalDrag = true
54
+ if (event.action === 'up' || event.action === 'cancel') {
55
+ // UIKit can send valueChanged after touch-up in the same dispatch.
56
+ // Keep the decision until dispatch finishes, then allow keyboard/AT.
57
+ clearTimeout(touchEnd)
58
+ touchEnd = setTimeout(resetTouch, 0)
59
+ }
60
+ }
61
+ }
62
+
63
+ function release() {
64
+ resetTouch()
65
+ control = undefined
66
+ revision++
67
+ }
68
+ onBeforeUnmount(release)
69
+
70
+ function change(event: PropertyChangeData) {
71
+ if (restoring) return
72
+ const view = event.object as Switch
73
+ const value = Boolean(event.value)
74
+ if (!props.disabled && !verticalDrag && value !== props.modelValue)
75
+ emit('update:modelValue', value)
76
+ const current = ++revision
77
+ // Native controls update themselves before Vue. Restore a rejected change,
78
+ // without treating that restoration as another user activation.
79
+ void nextTick(() => {
80
+ if (current !== revision || control !== view || view.checked === props.modelValue) return
81
+ restoring = true
82
+ try {
83
+ view.checked = props.modelValue
84
+ } finally {
85
+ restoring = false
86
+ }
87
+ })
88
+ }
89
+
90
+ return () => {
91
+ const { colors } = theme.value
92
+ return h(
93
+ MRow,
94
+ mergeProps(
95
+ {
96
+ width: props.width,
97
+ grow: props.grow,
98
+ shrink: props.shrink,
99
+ gap: 'md',
100
+ justify: 'between',
101
+ style: { minHeight: 48, opacity: props.disabled ? 0.45 : 1 },
102
+ },
103
+ attrs,
104
+ { accessibilityHidden: props.accessibilityHidden },
105
+ ),
106
+ {
107
+ default: () => [
108
+ h(
109
+ MColumn,
110
+ {
111
+ gap: 'xs',
112
+ paddingY: 'sm',
113
+ justify: 'center',
114
+ style: { minHeight: 48 },
115
+ accessibilityHidden: true,
116
+ isUserInteractionEnabled: !props.disabled,
117
+ ...feedback,
118
+ onTap: () => {
119
+ if (!props.disabled) emit('update:modelValue', !props.modelValue)
120
+ },
121
+ },
122
+ {
123
+ default: () => [
124
+ h(MText, {
125
+ text: props.label,
126
+ accessibilityHidden: true,
127
+ style: { fontWeight: '600' },
128
+ }),
129
+ props.helperText
130
+ ? h(MText, {
131
+ text: props.helperText,
132
+ accessibilityHidden: true,
133
+ variant: 'caption',
134
+ tone: 'muted',
135
+ })
136
+ : null,
137
+ ],
138
+ },
139
+ ),
140
+ h(
141
+ MColumn,
142
+ { width: 64, shrink: 0, align: 'center', justify: 'center' },
143
+ {
144
+ default: () =>
145
+ h('Switch', {
146
+ ...nativeAttrs(),
147
+ checked: props.modelValue,
148
+ isEnabled: !props.disabled,
149
+ accessible: true,
150
+ accessibilityRole: 'switch',
151
+ accessibilityState: props.modelValue ? 'checked' : 'unchecked',
152
+ accessibilityLabel: props.label,
153
+ accessibilityHint: props.helperText || undefined,
154
+ // Android's thumb extends beyond the narrow track: a light
155
+ // thumb disappears against a light settings surface.
156
+ color: isAndroid
157
+ ? props.modelValue
158
+ ? colors.primary
159
+ : colors.muted
160
+ : props.modelValue
161
+ ? colors.onPrimary
162
+ : colors.surface,
163
+ backgroundColor: isAndroid ? colors.primarySoft : colors.primary,
164
+ offBackgroundColor: isAndroid ? colors.border : colors.muted,
165
+ margin: 0,
166
+ onTouch: touch,
167
+ onCheckedChange: change,
168
+ onLoaded: (event: EventData) => {
169
+ control = event.object as Switch
170
+ // A retained page can unload before a pending restoration.
171
+ restoring = true
172
+ try {
173
+ control.checked = props.modelValue
174
+ } finally {
175
+ restoring = false
176
+ }
177
+ },
178
+ onUnloaded: release,
179
+ }),
180
+ },
181
+ ),
182
+ ],
183
+ },
184
+ )
185
+ }
186
+ },
187
+ })
@@ -0,0 +1,302 @@
1
+ import {
2
+ computed,
3
+ KeepAlive,
4
+ defineComponent,
5
+ h,
6
+ mergeProps,
7
+ onBeforeUnmount,
8
+ ref,
9
+ registerElement,
10
+ watch,
11
+ type SlotsType,
12
+ } from 'nativescript-vue'
13
+ import type { EventData, ScrollView, View } from '@nativescript/core'
14
+ import { animate, onReducedMotion, set } from '@rafaelaugusto/jolt'
15
+ import {
16
+ canChoose,
17
+ choiceKey,
18
+ tabFocusTarget,
19
+ tabScrollOffset,
20
+ validateTabs,
21
+ type TabOption,
22
+ type TabPanelProps,
23
+ } from '@getcortexlabs/mavis-core'
24
+ import { useButtonAction, tabsProps, tabsEmits, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
25
+ import { MavisButton } from '../../native/button'
26
+ import { observeTab } from '../../native/tabs'
27
+ import { useNativeViewAttrs } from '../accessibility.js'
28
+ import { MColumn } from './layout.js'
29
+
30
+ registerElement('MavisTabButton', () => MavisButton)
31
+
32
+ export const MTabs = defineComponent({
33
+ name: 'MTabs',
34
+ inheritAttrs: false,
35
+ props: tabsProps,
36
+ emits: tabsEmits,
37
+ slots: Object as SlotsType<{ default: TabPanelProps }>,
38
+ setup(props, { attrs, emit, slots }) {
39
+ useButtonAction()
40
+ const { theme } = useMavisTheme()
41
+ const nativeAttrs = useNativeViewAttrs(props)
42
+ const controls = new Map<string, View>()
43
+ const observers = new Map<string, () => void>()
44
+ const focusKey = ref<string>()
45
+ const selected = computed(() => {
46
+ validateTabs(props.tabs, props.modelValue, props.label)
47
+ return props.tabs.find((tab) => tab.value === props.modelValue)
48
+ })
49
+ let scroll: ScrollView | undefined, row: View | undefined, indicator: View | undefined
50
+ let motion: ReturnType<typeof animate> | undefined
51
+ let timer: ReturnType<typeof setTimeout> | undefined
52
+ let reduced: (() => void) | undefined
53
+ let previous: { key: string; x: number; width: number } | undefined
54
+ let animateNext = false
55
+ function reveal(view: View) {
56
+ if (!scroll || !row) return
57
+ const point = view.getLocationRelativeTo(row)
58
+ if (!point) return
59
+ const offset = tabScrollOffset(
60
+ point.x,
61
+ view.getActualSize().width,
62
+ scroll.horizontalOffset,
63
+ scroll.getActualSize().width,
64
+ )
65
+ if (Math.abs(offset - scroll.horizontalOffset) > 0.5)
66
+ scroll.scrollToHorizontalOffset(offset, false)
67
+ }
68
+ function update() {
69
+ timer = undefined
70
+ if (!scroll || !row || !indicator) return
71
+ const active = selected.value
72
+ const key = active && choiceKey(active.value)
73
+ const button = key && controls.get(key)
74
+ const point = button && button.getLocationRelativeTo(row)
75
+ const width = button && button.getActualSize().width
76
+ if (!key || !button || !point || !width) {
77
+ motion?.stop()
78
+ motion = undefined
79
+ indicator.opacity = 0
80
+ previous = undefined
81
+ animateNext = false
82
+ return
83
+ }
84
+ const changed = !previous || previous.x !== point.x || previous.width !== width
85
+ if (changed) {
86
+ motion?.stop()
87
+ motion = undefined
88
+ indicator.width = width
89
+ indicator.opacity = 1
90
+ if (previous && animateNext)
91
+ motion = animate(indicator, { x: point.x }, { type: 'spring', duration: 240, bounce: 0 })
92
+ else set(indicator, { x: point.x })
93
+ }
94
+ previous = { key, x: point.x, width }
95
+ animateNext = false
96
+ reveal(button)
97
+ }
98
+ function schedule(animated = false) {
99
+ animateNext ||= animated
100
+ if (timer === undefined) timer = setTimeout(update, 0)
101
+ }
102
+ function release() {
103
+ clearTimeout(timer)
104
+ timer = undefined
105
+ motion?.stop()
106
+ motion = undefined
107
+ reduced?.()
108
+ reduced = undefined
109
+ for (const dispose of observers.values()) dispose()
110
+ observers.clear()
111
+ controls.clear()
112
+ scroll = undefined
113
+ row = indicator = undefined
114
+ previous = undefined
115
+ animateNext = false
116
+ focusKey.value = undefined
117
+ }
118
+ onBeforeUnmount(release)
119
+ watch(
120
+ () => props.modelValue,
121
+ () => schedule(true),
122
+ { flush: 'post' },
123
+ )
124
+ watch(
125
+ () => [props.tabs, props.disabled],
126
+ () => schedule(),
127
+ { deep: true, flush: 'post' },
128
+ )
129
+ function navigate(tab: TabOption, key: string) {
130
+ if (props.disabled || props.tabs.find((item) => item.value === tab.value)?.disabled) return
131
+ const next = tabFocusTarget(props.tabs, tab.value, key)
132
+ const button = next && controls.get(choiceKey(next.value))
133
+ if (button) {
134
+ button.focus()
135
+ reveal(button)
136
+ }
137
+ }
138
+ return () => {
139
+ const active = selected.value
140
+ const { colors, typography } = theme.value
141
+ return h(
142
+ MColumn,
143
+ mergeProps(attrs, {
144
+ id: props.id,
145
+ width: props.width,
146
+ grow: props.grow,
147
+ shrink: props.shrink,
148
+ gap: 'md',
149
+ accessibilityHidden: props.accessibilityHidden,
150
+ }),
151
+ {
152
+ default: () => [
153
+ h(
154
+ 'ScrollView',
155
+ {
156
+ orientation: 'horizontal',
157
+ scrollBarIndicatorVisible: false,
158
+ accessibilityHidden: props.accessibilityHidden,
159
+ onLoaded: (event: EventData) => {
160
+ scroll = event.object as ScrollView
161
+ reduced?.()
162
+ reduced = onReducedMotion((value) => {
163
+ if (value && indicator && previous) {
164
+ motion?.stop()
165
+ motion = undefined
166
+ set(indicator, { x: previous.x })
167
+ }
168
+ })
169
+ schedule()
170
+ },
171
+ onLayoutChanged: () => schedule(),
172
+ onUnloaded: release,
173
+ },
174
+ [
175
+ h('MavisBox', { verticalAlignment: 'top' }, [
176
+ h(
177
+ 'StackLayout',
178
+ {
179
+ orientation: 'horizontal',
180
+ horizontalAlignment: 'left',
181
+ borderBottomWidth: 1,
182
+ borderBottomColor: colors.border,
183
+ onLoaded: (event: EventData) => {
184
+ row = event.object as View
185
+ schedule()
186
+ },
187
+ onLayoutChanged: () => schedule(),
188
+ },
189
+ props.tabs.map((tab) => {
190
+ const key = choiceKey(tab.value),
191
+ chosen = active?.value === tab.value
192
+ const disabled = props.disabled || Boolean(tab.disabled)
193
+ return h('MavisTabButton', {
194
+ ...nativeAttrs(),
195
+ id: undefined,
196
+ key,
197
+ text: tab.label,
198
+ textWrap: false,
199
+ accessible: true,
200
+ accessibilityRole: 'button',
201
+ accessibilityLabel: tab.label,
202
+ accessibilityHint: props.label,
203
+ accessibilityState: [chosen ? 'selected' : '', disabled ? 'disabled' : '']
204
+ .filter(Boolean)
205
+ .join(','),
206
+ isEnabled: !disabled,
207
+ iosAccessibilityAdjustsFontSize: true,
208
+ style: {
209
+ minHeight: 52,
210
+ minWidth: 48,
211
+ margin: 0,
212
+ paddingLeft: 20,
213
+ paddingRight: 20,
214
+ paddingTop: 14,
215
+ paddingBottom: 17,
216
+ fontSize: typography.body.fontSize,
217
+ fontWeight: '600',
218
+ textTransform: 'none',
219
+ color: chosen ? colors.primary : colors.muted,
220
+ backgroundColor:
221
+ focusKey.value === key ? colors.primarySoft : 'transparent',
222
+ borderWidth: 0,
223
+ borderRadius: 0,
224
+ opacity: disabled ? 0.4 : 1,
225
+ androidElevation: 0,
226
+ androidDynamicElevationOffset: 0,
227
+ },
228
+ onTap: () => {
229
+ if (canChoose(tab, props.modelValue, props.disabled))
230
+ emit('update:modelValue', tab.value)
231
+ },
232
+ onLoaded: (event: EventData) => {
233
+ const button = event.object as View
234
+ controls.set(key, button)
235
+ observers.get(key)?.()
236
+ observers.set(
237
+ key,
238
+ observeTab(
239
+ button,
240
+ (focused) => {
241
+ if (focused) focusKey.value = key
242
+ else if (focusKey.value === key) focusKey.value = undefined
243
+ },
244
+ (direction) => navigate(tab, direction),
245
+ ),
246
+ )
247
+ schedule()
248
+ },
249
+ onUnloaded: () => {
250
+ observers.get(key)?.()
251
+ observers.delete(key)
252
+ controls.delete(key)
253
+ },
254
+ onLayoutChanged: () => schedule(),
255
+ })
256
+ }),
257
+ ),
258
+ h('MavisBox', {
259
+ accessible: false,
260
+ accessibilityHidden: true,
261
+ isUserInteractionEnabled: false,
262
+ horizontalAlignment: 'left',
263
+ verticalAlignment: 'bottom',
264
+ width: 1,
265
+ height: 3,
266
+ borderRadius: 2,
267
+ backgroundColor: colors.primary,
268
+ opacity: 0,
269
+ onLoaded: (event: EventData) => {
270
+ indicator = event.object as View
271
+ schedule()
272
+ },
273
+ }),
274
+ ]),
275
+ ],
276
+ ),
277
+ props.keepAlive
278
+ ? props.tabs.map((tab) =>
279
+ h(
280
+ KeepAlive,
281
+ { key: choiceKey(tab.value), max: 1 },
282
+ {
283
+ default: () =>
284
+ active?.value === tab.value
285
+ ? h(MColumn, {}, { default: () => slots.default?.({ value: tab.value }) })
286
+ : null,
287
+ },
288
+ ),
289
+ )
290
+ : active
291
+ ? h(
292
+ MColumn,
293
+ { key: choiceKey(active.value) },
294
+ { default: () => slots.default?.({ value: active.value }) },
295
+ )
296
+ : null,
297
+ ],
298
+ },
299
+ )
300
+ }
301
+ },
302
+ })
@@ -2,10 +2,11 @@ import { defineComponent, h, mergeProps, registerElement } from 'nativescript-vu
2
2
  import {
3
3
  textProps,
4
4
  useMavisTheme,
5
- textContent,
5
+ inlineContent,
6
6
  useDefaultShrink,
7
7
  } from '@getcortexlabs/mavis-core/vue'
8
- import { nonNegative } from '@getcortexlabs/mavis-core'
8
+ import { fontFamily, nonNegative, validateWeight } from '@getcortexlabs/mavis-core'
9
+ import { isAndroid } from '@nativescript/core'
9
10
  import { MavisLabel } from '../../native/label'
10
11
  import { useNativeViewAttrs } from '../accessibility.js'
11
12
 
@@ -19,18 +20,29 @@ export const MText = defineComponent({
19
20
  const { theme } = useMavisTheme()
20
21
  const nativeAttrs = useNativeViewAttrs(props)
21
22
  const shrink = useDefaultShrink()
22
- return () =>
23
- h(
23
+ return () => {
24
+ const type = theme.value.typography[props.variant]
25
+ const runs =
26
+ props.text !== undefined ? [{ text: props.text }] : inlineContent(slots.default?.())
27
+ const text = runs.map((run) => run.text).join('')
28
+ const formatted = runs.some((run) => run.weight || run.tone || run.strong || run.italic)
29
+ return h(
24
30
  'MavisLabel',
25
31
  mergeProps(
26
32
  {
27
- text: props.text ?? textContent(slots.default?.()),
33
+ text,
34
+ ...(formatted ? {} : { formattedText: null }),
28
35
  textWrap: props.wrap,
29
36
  iosAccessibilityAdjustsFontSize: true,
37
+ dynamicTypeStyle: props.variant,
30
38
  accessible: true,
31
39
  accessibilityRole: /^h[1-6]$/.test(props.as) ? 'header' : 'text',
32
40
  style: {
33
- ...theme.value.typography[props.variant],
41
+ ...type,
42
+ fontFamily: fontFamily(type.fontFamily, isAndroid ? 'android' : 'ios'),
43
+ fontWeight: props.weight ? validateWeight(props.weight) : type.fontWeight,
44
+ // Core's lineHeight is additional leading in device-independent units.
45
+ lineHeight: type.fontSize * (type.lineHeight - 1),
34
46
  color: theme.value.colors[props.tone],
35
47
  textAlignment: props.align,
36
48
  flexGrow: nonNegative(props.grow, 'grow'),
@@ -41,6 +53,25 @@ export const MText = defineComponent({
41
53
  nativeAttrs(),
42
54
  attrs,
43
55
  ),
56
+ formatted
57
+ ? [
58
+ h(
59
+ 'FormattedString',
60
+ {},
61
+ runs.map((run) => {
62
+ if (run.tone && !(run.tone in theme.value.colors))
63
+ throw new RangeError(`Unknown text tone: ${run.tone}`)
64
+ return h('Span', {
65
+ text: run.text,
66
+ fontWeight: run.weight,
67
+ fontStyle: run.italic ? 'italic' : undefined,
68
+ color: run.tone ? theme.value.colors[run.tone] : undefined,
69
+ })
70
+ }),
71
+ ),
72
+ ]
73
+ : undefined,
44
74
  )
75
+ }
45
76
  },
46
77
  })