@getcortexlabs/mavis 0.1.0-rc.13 → 0.1.0-rc.15

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 (190) hide show
  1. package/README.md +7 -5
  2. package/dist/components/bindings.d.ts +14 -0
  3. package/dist/components/bindings.d.ts.map +1 -0
  4. package/dist/components/bindings.js +21 -0
  5. package/dist/components/bindings.js.map +1 -0
  6. package/dist/components/contracts.d.ts +28 -0
  7. package/dist/components/contracts.d.ts.map +1 -0
  8. package/dist/components/contracts.js +27 -0
  9. package/dist/components/contracts.js.map +1 -0
  10. package/dist/components/controller.d.ts +56 -0
  11. package/dist/components/controller.d.ts.map +1 -0
  12. package/dist/components/controller.js +508 -0
  13. package/dist/components/controller.js.map +1 -0
  14. package/dist/components/index.d.ts +53 -0
  15. package/dist/components/index.d.ts.map +1 -0
  16. package/dist/components/index.js +95 -0
  17. package/dist/components/index.js.map +1 -0
  18. package/dist/components/style.d.ts +52 -0
  19. package/dist/components/style.d.ts.map +1 -0
  20. package/dist/components/style.js +68 -0
  21. package/dist/components/style.js.map +1 -0
  22. package/dist/components/theme.d.ts +12 -0
  23. package/dist/components/theme.d.ts.map +1 -0
  24. package/dist/components/theme.js +29 -0
  25. package/dist/components/theme.js.map +1 -0
  26. package/dist/native/box.ios.d.ts +1 -0
  27. package/dist/native/box.ios.d.ts.map +1 -1
  28. package/dist/native/box.ios.js +21 -1
  29. package/dist/native/box.ios.js.map +1 -1
  30. package/dist/native/flex-layout.ios.d.ts.map +1 -1
  31. package/dist/native/flex-layout.ios.js +4 -0
  32. package/dist/native/flex-layout.ios.js.map +1 -1
  33. package/dist/native/motion-binding.d.ts +11 -0
  34. package/dist/native/motion-binding.d.ts.map +1 -0
  35. package/dist/native/motion-binding.js +132 -0
  36. package/dist/native/motion-binding.js.map +1 -0
  37. package/dist/native/motion-region.d.ts.map +1 -1
  38. package/dist/native/motion-region.js +1 -0
  39. package/dist/native/motion-region.js.map +1 -1
  40. package/dist/native/motion-surface.d.ts +1 -1
  41. package/dist/native/motion-surface.d.ts.map +1 -1
  42. package/dist/native/motion-surface.js +40 -8
  43. package/dist/native/motion-surface.js.map +1 -1
  44. package/dist/native/navigation.d.ts +4 -0
  45. package/dist/native/navigation.d.ts.map +1 -0
  46. package/dist/native/navigation.js +16 -0
  47. package/dist/native/navigation.js.map +1 -0
  48. package/dist/native/pointer-availability.d.ts +7 -0
  49. package/dist/native/pointer-availability.d.ts.map +1 -0
  50. package/dist/native/pointer-availability.js +43 -0
  51. package/dist/native/pointer-availability.js.map +1 -0
  52. package/dist/native/scroll-motion.d.ts +1 -1
  53. package/dist/native/scroll-motion.d.ts.map +1 -1
  54. package/dist/native/scroll-motion.js +55 -16
  55. package/dist/native/scroll-motion.js.map +1 -1
  56. package/dist/native/section-scroll.d.ts +1 -1
  57. package/dist/native/section-scroll.d.ts.map +1 -1
  58. package/dist/native/section-scroll.js +19 -6
  59. package/dist/native/section-scroll.js.map +1 -1
  60. package/dist/vue/card-input.d.ts +4 -0
  61. package/dist/vue/card-input.d.ts.map +1 -0
  62. package/dist/vue/card-input.js +37 -0
  63. package/dist/vue/card-input.js.map +1 -0
  64. package/dist/vue/components/ChoiceControl.d.ts +3 -3
  65. package/dist/vue/components/LoadingDecoration.d.ts +5 -5
  66. package/dist/vue/components/MAccordion.d.ts +3 -3
  67. package/dist/vue/components/MAlert.d.ts +4 -4
  68. package/dist/vue/components/MAvatar.d.ts +4 -4
  69. package/dist/vue/components/MBadge.d.ts +3 -3
  70. package/dist/vue/components/MButton.d.ts +20 -20
  71. package/dist/vue/components/MCard.d.ts +11 -11
  72. package/dist/vue/components/MCard.d.ts.map +1 -1
  73. package/dist/vue/components/MCard.js +3 -2
  74. package/dist/vue/components/MCard.js.map +1 -1
  75. package/dist/vue/components/MCheckbox.d.ts +3 -3
  76. package/dist/vue/components/MChip.d.ts +4 -4
  77. package/dist/vue/components/MCombobox.d.ts +5 -5
  78. package/dist/vue/components/MDatePicker.d.ts +96 -96
  79. package/dist/vue/components/MDatePicker.d.ts.map +1 -1
  80. package/dist/vue/components/MDialog.d.ts +3 -3
  81. package/dist/vue/components/MEmptyState.d.ts +3 -3
  82. package/dist/vue/components/MGrid.d.ts +7 -7
  83. package/dist/vue/components/MGrid.d.ts.map +1 -1
  84. package/dist/vue/components/MGrid.js +5 -1
  85. package/dist/vue/components/MGrid.js.map +1 -1
  86. package/dist/vue/components/MIcon.d.ts +2 -2
  87. package/dist/vue/components/MImage.d.ts +7 -7
  88. package/dist/vue/components/MImageCompare.d.ts +1 -1
  89. package/dist/vue/components/MInput.d.ts +22 -22
  90. package/dist/vue/components/MLink.d.ts +5 -5
  91. package/dist/vue/components/MListItem.d.ts +5 -5
  92. package/dist/vue/components/MPinInput.d.ts +1 -1
  93. package/dist/vue/components/MPopover.d.ts +3 -3
  94. package/dist/vue/components/MProgress.d.ts +5 -5
  95. package/dist/vue/components/MRadioGroup.d.ts +3 -3
  96. package/dist/vue/components/MRangeSlider.d.ts +1 -1
  97. package/dist/vue/components/MResizablePanels.d.ts +3 -3
  98. package/dist/vue/components/MReveal.d.ts +17 -17
  99. package/dist/vue/components/MScreen.d.ts +3 -3
  100. package/dist/vue/components/MScreen.d.ts.map +1 -1
  101. package/dist/vue/components/MScreen.js +11 -1
  102. package/dist/vue/components/MScreen.js.map +1 -1
  103. package/dist/vue/components/MSegmentedControl.d.ts +3 -3
  104. package/dist/vue/components/MSelect.d.ts +4 -4
  105. package/dist/vue/components/MSheet.d.ts +7 -7
  106. package/dist/vue/components/MSkeleton.d.ts +3 -3
  107. package/dist/vue/components/MSlider.d.ts +1 -1
  108. package/dist/vue/components/MStack.d.ts +19 -19
  109. package/dist/vue/components/MStack.d.ts.map +1 -1
  110. package/dist/vue/components/MStack.js +12 -2
  111. package/dist/vue/components/MStack.js.map +1 -1
  112. package/dist/vue/components/MSwitch.d.ts +3 -3
  113. package/dist/vue/components/MTabs.d.ts +3 -3
  114. package/dist/vue/components/MText.d.ts +8 -8
  115. package/dist/vue/components/MText.d.ts.map +1 -1
  116. package/dist/vue/components/MText.js +4 -1
  117. package/dist/vue/components/MText.js.map +1 -1
  118. package/dist/vue/components/MTimePicker.d.ts +40 -40
  119. package/dist/vue/components/MTimePicker.d.ts.map +1 -1
  120. package/dist/vue/components/MTooltip.d.ts +2 -2
  121. package/dist/vue/components/MVirtualList.d.ts.map +1 -1
  122. package/dist/vue/components/MVirtualList.js +88 -67
  123. package/dist/vue/components/MVirtualList.js.map +1 -1
  124. package/dist/vue/components/advanced.d.ts +34 -34
  125. package/dist/vue/components/configurator.d.ts +33 -33
  126. package/dist/vue/components/creative.d.ts +20 -20
  127. package/dist/vue/components/dashboard.d.ts +12 -12
  128. package/dist/vue/components/dashboard.d.ts.map +1 -1
  129. package/dist/vue/components/dashboard.js +185 -69
  130. package/dist/vue/components/dashboard.js.map +1 -1
  131. package/dist/vue/components/discovery.d.ts +10 -10
  132. package/dist/vue/components/interactive.d.ts +6 -6
  133. package/dist/vue/components/layout.d.ts +45 -45
  134. package/dist/vue/components/layout.d.ts.map +1 -1
  135. package/dist/vue/components/layout.js +8 -2
  136. package/dist/vue/components/layout.js.map +1 -1
  137. package/dist/vue/components/navigation.d.ts +4 -4
  138. package/dist/vue/components/screen-components.d.ts +23 -23
  139. package/dist/vue/components/screen-components.d.ts.map +1 -1
  140. package/dist/vue/components/screen-components.js +15 -0
  141. package/dist/vue/components/screen-components.js.map +1 -1
  142. package/dist/vue/components/wayfinding.d.ts +11 -11
  143. package/dist/vue/components/workflows.d.ts +5 -5
  144. package/dist/vue/layout-context.d.ts +4 -0
  145. package/dist/vue/layout-context.d.ts.map +1 -0
  146. package/dist/vue/layout-context.js +3 -0
  147. package/dist/vue/layout-context.js.map +1 -0
  148. package/dist/vue/navigation.d.ts +1 -3
  149. package/dist/vue/navigation.d.ts.map +1 -1
  150. package/dist/vue/navigation.js +1 -15
  151. package/dist/vue/navigation.js.map +1 -1
  152. package/dist/vue/screen-overlay.d.ts +9 -0
  153. package/dist/vue/screen-overlay.d.ts.map +1 -0
  154. package/dist/vue/screen-overlay.js +17 -0
  155. package/dist/vue/screen-overlay.js.map +1 -0
  156. package/dist/vue/use-motion-surface.d.ts +2 -3
  157. package/dist/vue/use-motion-surface.d.ts.map +1 -1
  158. package/dist/vue/use-motion-surface.js +9 -134
  159. package/dist/vue/use-motion-surface.js.map +1 -1
  160. package/package.json +8 -4
  161. package/platforms/android/java/com/mavis/ui/Box.java +31 -0
  162. package/src/components/bindings.ts +32 -0
  163. package/src/components/contracts.ts +60 -0
  164. package/src/components/controller.ts +542 -0
  165. package/src/components/index.ts +136 -0
  166. package/src/components/style.ts +84 -0
  167. package/src/components/theme.ts +25 -0
  168. package/src/native/box.ios.ts +31 -1
  169. package/src/native/flex-layout.ios.ts +4 -0
  170. package/src/native/motion-binding.ts +143 -0
  171. package/src/native/motion-region.ts +1 -0
  172. package/src/native/motion-surface.ts +41 -8
  173. package/src/native/navigation.ts +15 -0
  174. package/src/native/pointer-availability.ts +44 -0
  175. package/src/native/scroll-motion.ts +60 -19
  176. package/src/native/section-scroll.ts +16 -6
  177. package/src/vue/card-input.ts +44 -0
  178. package/src/vue/components/MCard.ts +4 -3
  179. package/src/vue/components/MGrid.ts +10 -1
  180. package/src/vue/components/MScreen.ts +12 -1
  181. package/src/vue/components/MStack.ts +17 -2
  182. package/src/vue/components/MText.ts +4 -1
  183. package/src/vue/components/MVirtualList.ts +104 -78
  184. package/src/vue/components/dashboard.ts +192 -69
  185. package/src/vue/components/layout.ts +8 -0
  186. package/src/vue/components/screen-components.ts +14 -0
  187. package/src/vue/layout-context.ts +4 -0
  188. package/src/vue/navigation.ts +1 -15
  189. package/src/vue/screen-overlay.ts +20 -0
  190. package/src/vue/use-motion-surface.ts +10 -137
@@ -0,0 +1,84 @@
1
+ import {
2
+ fontFamily,
3
+ nonNegative,
4
+ resolveDimension,
5
+ resolveRadius,
6
+ resolveSpace,
7
+ shadowStyle,
8
+ validateWeight,
9
+ type MavisTheme,
10
+ } from '@getcortexlabs/mavis-core'
11
+ import { isAndroid } from '@nativescript/core'
12
+ import type { MBoxProps, MTextProps, MButtonProps } from './contracts.js'
13
+
14
+ export function nativeBoxStyle(theme: MavisTheme, props: MBoxProps, shrink = 0) {
15
+ const padding = props.padding === undefined ? undefined : resolveSpace(theme, props.padding)
16
+ const x = props.paddingX === undefined ? padding : resolveSpace(theme, props.paddingX)
17
+ const y = props.paddingY === undefined ? padding : resolveSpace(theme, props.paddingY)
18
+ return {
19
+ paddingLeft: x ?? 0,
20
+ paddingRight: x ?? 0,
21
+ paddingTop: y ?? 0,
22
+ paddingBottom: y ?? 0,
23
+ borderRadius: props.radius === undefined ? 0 : resolveRadius(theme, props.radius),
24
+ width: resolveDimension(props.width) ?? 'auto',
25
+ height: resolveDimension(props.height) ?? 'auto',
26
+ backgroundColor: props.backgroundColor ?? 'transparent',
27
+ flexGrow: nonNegative(props.grow ?? 0, 'grow'),
28
+ flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
29
+ minWidth: 0,
30
+ }
31
+ }
32
+
33
+ export function nativeTextStyle(theme: MavisTheme, props: MTextProps, shrink = 0) {
34
+ const type = theme.typography[props.variant ?? 'body']
35
+ return {
36
+ ...type,
37
+ fontFamily: fontFamily(type.fontFamily, isAndroid ? 'android' : 'ios'),
38
+ fontWeight: props.weight === undefined ? type.fontWeight : validateWeight(props.weight),
39
+ lineHeight: type.fontSize * (type.lineHeight - 1),
40
+ color: theme.colors[props.tone ?? 'text'],
41
+ textAlignment: props.align ?? 'left',
42
+ flexGrow: nonNegative(props.grow ?? 0, 'grow'),
43
+ flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
44
+ minWidth: 0,
45
+ }
46
+ }
47
+
48
+ export function nativeButtonStyle(theme: MavisTheme, props: MButtonProps, shrink = 0) {
49
+ const tokens = theme.components.button
50
+ const size = theme.control[props.size ?? 'md']
51
+ const primary = (props.variant ?? 'primary') === 'primary'
52
+ return {
53
+ minHeight: Math.max(size.height, isAndroid ? 48 : 44),
54
+ minWidth: isAndroid ? 48 : 44,
55
+ paddingLeft: size.padding,
56
+ paddingRight: size.padding,
57
+ paddingTop: tokens.paddingY,
58
+ paddingBottom: tokens.paddingY,
59
+ fontSize: size.fontSize,
60
+ fontWeight: tokens.fontWeight,
61
+ fontFamily: fontFamily(
62
+ tokens.fontFamily ?? theme.typography.body.fontFamily,
63
+ isAndroid ? 'android' : 'ios',
64
+ ),
65
+ lineHeight: size.fontSize * (tokens.lineHeight - 1),
66
+ textTransform: 'none',
67
+ backgroundColor: primary
68
+ ? theme.colors.primary
69
+ : props.variant === 'secondary'
70
+ ? theme.colors.elevated
71
+ : 'transparent',
72
+ color: primary ? theme.colors.onPrimary : theme.colors.text,
73
+ borderRadius: resolveRadius(theme, tokens.radius),
74
+ borderWidth: 0,
75
+ androidElevation: 0,
76
+ androidDynamicElevationOffset: 0,
77
+ margin: 0,
78
+ boxShadow:
79
+ props.variant === 'ghost' ? 'none' : shadowStyle(theme.elevation[tokens.elevation], 'native'),
80
+ opacity: props.disabled ? 0.45 : 1,
81
+ flexGrow: nonNegative(props.grow ?? 0, 'grow'),
82
+ flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
83
+ }
84
+ }
@@ -0,0 +1,25 @@
1
+ import { mavis, type MavisTheme } from '@getcortexlabs/mavis-core'
2
+
3
+ /** An application or an explicitly isolated theme scope. No process-wide mutable theme. */
4
+ export class MavisThemeScope {
5
+ private listeners = new Set<() => void>()
6
+ constructor(private current: MavisTheme = mavis) {}
7
+ get theme() {
8
+ return this.current
9
+ }
10
+ setTheme(theme: MavisTheme) {
11
+ if (theme === this.current) return
12
+ this.current = theme
13
+ for (const listener of [...this.listeners]) listener()
14
+ }
15
+ subscribe(listener: () => void) {
16
+ this.listeners.add(listener)
17
+ return () => {
18
+ this.listeners.delete(listener)
19
+ }
20
+ }
21
+ }
22
+
23
+ export function createMavisTheme(theme: MavisTheme = mavis) {
24
+ return new MavisThemeScope(theme)
25
+ }
@@ -1,4 +1,4 @@
1
- import { GridLayout, Utils } from '@nativescript/core'
1
+ import { GridLayout, Utils, View } from '@nativescript/core'
2
2
  import {
3
3
  filledLimit,
4
4
  layoutChildren,
@@ -13,6 +13,36 @@ const { layout } = Utils
13
13
  export class MavisBox extends GridLayout {
14
14
  measureRecord?: MeasureRecord
15
15
 
16
+ // MBox is one shared area. Core centres a fixed child whose default alignment
17
+ // is stretch; CSS grid instead anchors that child at the start of the area.
18
+ // Offer only its measured extent on a fixed axis, without changing its style
19
+ // or laying it out twice. Unsized axes still receive the whole content area.
20
+ onLayout(left: number, top: number, right: number, bottom: number) {
21
+ const insets = this.getSafeAreaInsets()
22
+ const x = this.effectiveBorderLeftWidth + this.effectivePaddingLeft + insets.left
23
+ const y = this.effectiveBorderTopWidth + this.effectivePaddingTop + insets.top
24
+ const endX =
25
+ right - left - this.effectiveBorderRightWidth - this.effectivePaddingRight - insets.right
26
+ const endY =
27
+ bottom - top - this.effectiveBorderBottomWidth - this.effectivePaddingBottom - insets.bottom
28
+ this.eachLayoutChild((child) => {
29
+ const fixedX = child.effectiveWidth >= 0 && child.horizontalAlignment === 'stretch'
30
+ const fixedY = child.effectiveHeight >= 0 && child.verticalAlignment === 'stretch'
31
+ View.layoutChild(
32
+ this,
33
+ child,
34
+ x,
35
+ y,
36
+ fixedX
37
+ ? x + child.getMeasuredWidth() + child.effectiveMarginLeft + child.effectiveMarginRight
38
+ : endX,
39
+ fixedY
40
+ ? y + child.getMeasuredHeight() + child.effectiveMarginTop + child.effectiveMarginBottom
41
+ : endY,
42
+ )
43
+ })
44
+ }
45
+
16
46
  measure(widthSpec: number, heightSpec: number) {
17
47
  if (reuseMeasurement(this, widthSpec, heightSpec)) return
18
48
  super.measure(widthSpec, heightSpec)
@@ -222,5 +222,9 @@ export class MavisFlexLayout extends FlexboxLayout {
222
222
  ? layout.makeMeasureSpec(child.effectiveHeight, layout.EXACTLY)
223
223
  : layout.makeMeasureSpec(available, mode),
224
224
  )
225
+ // Core applies min/max constraints before our width-aware remeasurement. Its
226
+ // Flexbox onMeasure does not enforce its own minimum, so measuring a nested
227
+ // row again can collapse a 44-point link to its label's intrinsic height.
228
+ base._checkSizeConstraints.call(this, child)
225
229
  }
226
230
  }
@@ -0,0 +1,143 @@
1
+ import { Utils, isAndroid, type EventData, type View } from '@nativescript/core'
2
+ import { animate, set, onReducedMotion } from '@rafaelaugusto/jolt'
3
+ import {
4
+ bindMotionSurface,
5
+ motionChannels,
6
+ motionKeyframes,
7
+ type MotionFrames,
8
+ type MotionSurface,
9
+ } from '@getcortexlabs/mavis-core/experimental'
10
+ import { nativeContinuousSurface } from './motion-surface.js'
11
+ import { nativeMotionOwner } from './motion-owner.js'
12
+ import { takeShadow } from './moved-shadow.js'
13
+
14
+ export function createNativeMotionSurface(
15
+ surface: () => MotionSurface | undefined,
16
+ enabled: () => boolean = () => true,
17
+ plainText: () => boolean = () => false,
18
+ afterLayout = false,
19
+ perspective?: () => number | undefined,
20
+ ) {
21
+ let view: View | undefined
22
+ let unbind: (() => void) | undefined
23
+ let offPreference: (() => void) | undefined
24
+ let continuous: ReturnType<typeof nativeContinuousSurface> | undefined
25
+ const active = new Map<ReturnType<typeof animate>, MotionFrames>()
26
+ let layoutView: View | undefined
27
+ let layoutQueued = false
28
+ let flat: { view: View; perspective: number } | undefined
29
+ const project = () => {
30
+ const depth = perspective?.()
31
+ if (flat && (depth === undefined || flat.view !== view)) {
32
+ flat.view.perspective = flat.perspective
33
+ flat = undefined
34
+ }
35
+ if (!view || depth === undefined || !unbind) return
36
+ flat ??= { view, perspective: view.perspective }
37
+ // Core multiplies by the density for Android's camera distance, whose unit is not the
38
+ // CSS distance. This is the factor that draws the same projection as iOS and the Web.
39
+ view.perspective = isAndroid ? depth * Utils.layout.getDisplayDensity() * Math.sqrt(5) : depth
40
+ }
41
+ const clearLayout = () => {
42
+ layoutView?.off('layoutChanged', laidOut)
43
+ layoutView = undefined
44
+ }
45
+ const release = () => {
46
+ unbind?.()
47
+ unbind = undefined
48
+ continuous = undefined
49
+ offPreference?.()
50
+ offPreference = undefined
51
+ for (const handle of active.keys()) handle.stop()
52
+ active.clear()
53
+ project()
54
+ }
55
+ const bind = () => {
56
+ release()
57
+ const target = view
58
+ const reference = surface()
59
+ if (!target || !reference) return
60
+ if (
61
+ afterLayout &&
62
+ (!target.isLayoutValid ||
63
+ target.getActualSize().width <= 0 ||
64
+ target.getActualSize().height <= 0)
65
+ ) {
66
+ if (layoutView !== target) {
67
+ clearLayout()
68
+ layoutView = target
69
+ target.on('layoutChanged', laidOut)
70
+ }
71
+ return
72
+ }
73
+ clearLayout()
74
+ continuous = nativeContinuousSurface(target, enabled, plainText)
75
+ unbind = bindMotionSurface(
76
+ reference,
77
+ nativeMotionOwner(
78
+ {
79
+ ...continuous.adapter,
80
+ animate(values, options) {
81
+ continuous?.interrupt(motionChannels(values))
82
+ const handle = animate(target, motionKeyframes(values), options)
83
+ takeShadow(target, values)
84
+ active.set(handle, values)
85
+ void handle.finished.then(() => active.delete(handle))
86
+ return handle
87
+ },
88
+ set: (values) => {
89
+ continuous?.interrupt(Object.keys(values))
90
+ const handle = animate(target, values, { duration: 0 })
91
+ takeShadow(target, values)
92
+ return handle
93
+ },
94
+ },
95
+ target,
96
+ ),
97
+ )
98
+ project()
99
+ offPreference = onReducedMotion((reduced) => {
100
+ if (!reduced) return
101
+ // Set only spatial channels: opacity and shadow paint can keep their timelines.
102
+ const values: Record<string, number> = {}
103
+ for (const frames of active.values()) {
104
+ if (frames.path)
105
+ Object.assign(values, {
106
+ x: frames.path.end.x,
107
+ y: frames.path.end.y,
108
+ ...(frames.orient ? { rotate: frames.path.end.rotate } : {}),
109
+ })
110
+ for (const [property, value] of Object.entries(frames)) {
111
+ if (property === 'opacity' || property.startsWith('shadow')) continue
112
+ const final = Array.isArray(value) ? value.at(-1) : value
113
+ if (typeof final === 'number') values[property] = final
114
+ }
115
+ }
116
+ if (Object.keys(values).length) set(target, values)
117
+ })
118
+ }
119
+ const laidOut = () => {
120
+ if (layoutQueued) return
121
+ layoutQueued = true
122
+ void Promise.resolve().then(() => {
123
+ layoutQueued = false
124
+ if (view) bind()
125
+ })
126
+ }
127
+ const unloaded = () => {
128
+ clearLayout()
129
+ release()
130
+ view = undefined
131
+ }
132
+ return {
133
+ refresh: bind,
134
+ refreshEnabled: () => continuous?.refresh(),
135
+ refreshPerspective: project,
136
+ allowsActivation: () => continuous?.allowsActivation() ?? true,
137
+ onLoaded(event: EventData) {
138
+ view = event.object as View
139
+ bind()
140
+ },
141
+ onUnloaded: unloaded,
142
+ }
143
+ }
@@ -204,6 +204,7 @@ export function attachNativeMotionRegion(reference: MotionRegion, target: View)
204
204
  : ([resolveChild(step[0]), step[1], step[2]] as const),
205
205
  )
206
206
  const adapter: MotionRegionAdapter = {
207
+ // Jolt captures before native unload, then waits for layout; rebuilt RC.15 classes own exits.
207
208
  animateLayout: (change, { transition, ...options }) =>
208
209
  animateLayout(target, change, { ...transition, ...options }),
209
210
  ...nativePlatformMotion(target, resolveChild, scope),
@@ -2,6 +2,7 @@ import { nativeScrollMotion } from './scroll-motion.js'
2
2
  import { assertNativeRegion, nativeRegionTarget } from './motion-region.js'
3
3
  import { nativeSectionScroll } from './section-scroll.js'
4
4
  import { nativeVisualEffects } from './visual-effects.js'
5
+ import { watchPointerAvailability } from './pointer-availability.js'
5
6
  import { sensor } from '@rafaelaugusto/jolt/sensors'
6
7
  import type { View, EventData, TouchGestureEventData } from '@nativescript/core'
7
8
  import {
@@ -48,6 +49,8 @@ export function nativeContinuousSurface(
48
49
  | 'drag'
49
50
  | 'map'
50
51
  | 'mapColor'
52
+ | 'scalar'
53
+ | 'readVelocity'
51
54
  | 'refresh'
52
55
  | 'scrollLinked'
53
56
  | 'scrollSection'
@@ -100,12 +103,18 @@ export function nativeContinuousSurface(
100
103
  assertNativeRegion(region, target)
101
104
  // Jolt owns the hover listener, its geometry, suspension and the views' load state.
102
105
  // Ordinary touch is not hover, so scrolling, taps and focus stay with the app.
103
- const pointer = pointerFollow(nativeRegionTarget(region), {
104
- ...options,
106
+ const { onAvailabilityChange, ...inputOptions } = options
107
+ const inputRegion = nativeRegionTarget(region)
108
+ const pointer = pointerFollow(inputRegion, {
109
+ ...inputOptions,
105
110
  disabled: options.disabled || !enabled(),
106
111
  } as PointerOptions)
107
112
  let disabled = options.disabled ?? false
108
- const refresh = () => pointer.update({ disabled: disabled || !enabled() })
113
+ const unwatch = watchPointerAvailability(pointer, inputRegion, onAvailabilityChange)
114
+ const refresh = () => {
115
+ pointer.update({ disabled: disabled || !enabled() })
116
+ unwatch.notify()
117
+ }
109
118
  refreshes.add(refresh)
110
119
  // The pointer owns its values; wrappers are borrowed by Mavis bindings.
111
120
  const wrap = (source: DerivedValue) => {
@@ -130,10 +139,17 @@ export function nativeContinuousSurface(
130
139
  disabled = state.disabled
131
140
  refresh()
132
141
  },
133
- refresh: () => pointer.refresh(),
142
+ refresh: () => {
143
+ pointer.refresh()
144
+ unwatch.notify()
145
+ },
134
146
  dispose() {
135
147
  refreshes.delete(refresh)
136
- pointer.dispose()
148
+ try {
149
+ unwatch()
150
+ } finally {
151
+ pointer.dispose()
152
+ }
137
153
  },
138
154
  }
139
155
  },
@@ -177,10 +193,27 @@ export function nativeContinuousSurface(
177
193
  refresh: () => target.requestLayout(),
178
194
  map(source, input, output, options) {
179
195
  const mapped = sources.get(source)!.to(input, output, options)
180
- const value = { get: () => mapped.get(), dispose() {} }
196
+ const value = { get: () => mapped.get(), dispose: () => mapped.dispose() }
181
197
  sources.set(value, mapped)
182
198
  return value
183
199
  },
200
+ scalar(source, operation, operand, maximum) {
201
+ const input = sources.get(source)!
202
+ let result: DerivedValue
203
+ if (operation === 'clamp') result = input.clamp(operand as number, maximum!)
204
+ else if (
205
+ operation === 'abs' ||
206
+ operation === 'sin' ||
207
+ operation === 'cos' ||
208
+ operation === 'velocity'
209
+ )
210
+ result = input[operation]()
211
+ else result = input[operation](typeof operand === 'number' ? operand : sources.get(operand!)!)
212
+ const value = { get: () => result.get(), dispose: () => result.dispose() }
213
+ sources.set(value, result)
214
+ return value
215
+ },
216
+ readVelocity: (source) => sources.get(source)!.getVelocity(),
184
217
  mapColor(source, input, output) {
185
218
  const mapped = sources.get(source)!.to(input, output)
186
219
  const value = { get: () => mapped.get().hex, dispose() {} }
@@ -199,7 +232,7 @@ export function nativeContinuousSurface(
199
232
  },
200
233
  playbackProgress(handle) {
201
234
  const progress = playbackProgress(handle as Parameters<typeof playbackProgress>[0])
202
- const value = { get: () => progress.get(), dispose() {} }
235
+ const value = { get: () => progress.get(), dispose: () => progress.dispose() }
203
236
  sources.set(value, progress)
204
237
  return value
205
238
  },
@@ -212,7 +245,7 @@ export function nativeContinuousSurface(
212
245
  const value: MotionValueAdapter = {
213
246
  get: () => source.get(),
214
247
  set: (value) => set(source, value),
215
- dispose: () => stop(source),
248
+ dispose: () => source.dispose(),
216
249
  }
217
250
  sources.set(value, source)
218
251
  return value
@@ -0,0 +1,15 @@
1
+ import { Utils } from '@nativescript/core'
2
+ import { linkDestination, type NavigationOptions } from '@getcortexlabs/mavis-core'
3
+
4
+ export function nativeDestination(options: NavigationOptions) {
5
+ const href = linkDestination(options.href!)
6
+ if (!options.navigate && !/^[a-z][a-z\d+.-]*:/i.test(href))
7
+ throw new TypeError('Native navigation needs a navigate handler for in-app destinations.')
8
+ return href
9
+ }
10
+
11
+ export async function navigateNative(options: NavigationOptions) {
12
+ const href = nativeDestination(options)
13
+ if (options.navigate) await options.navigate(href)
14
+ else if (!(await Utils.openUrl(href))) throw new Error(`The system could not open ${href}.`)
15
+ }
@@ -0,0 +1,44 @@
1
+ import { Application, type View } from '@nativescript/core'
2
+ import { onReducedMotion, type PointerFollow } from '@rafaelaugusto/jolt'
3
+
4
+ /** Publish Jolt's live state after its native load, preference and application handlers run. */
5
+ export function watchPointerAvailability(
6
+ pointer: PointerFollow,
7
+ region: View,
8
+ changed?: (available: boolean) => void,
9
+ ) {
10
+ if (!changed) return Object.assign(() => {}, { notify() {} })
11
+ let stopped = false,
12
+ queued = false,
13
+ previous: boolean | undefined
14
+ const notify = () => {
15
+ if (stopped || queued) return
16
+ queued = true
17
+ void Promise.resolve().then(() => {
18
+ queued = false
19
+ if (stopped) return
20
+ const available = pointer.available
21
+ if (available !== previous) changed((previous = available))
22
+ })
23
+ }
24
+ const events = ['loaded', 'unloaded', 'layoutChanged', 'isEnabledChange', 'visibilityChange']
25
+ for (const event of events) region.on(event, notify)
26
+ region.style.on('visibilityChange', notify)
27
+ Application.on(Application.suspendEvent, notify)
28
+ Application.on(Application.resumeEvent, notify)
29
+ const offReduced = onReducedMotion(notify)
30
+ notify()
31
+ return Object.assign(
32
+ () => {
33
+ if (stopped) return
34
+ stopped = true
35
+ for (const event of events) region.off(event, notify)
36
+ region.style.off('visibilityChange', notify)
37
+ Application.off(Application.suspendEvent, notify)
38
+ Application.off(Application.resumeEvent, notify)
39
+ offReduced()
40
+ if (previous !== false) changed(false)
41
+ },
42
+ { notify },
43
+ )
44
+ }
@@ -1,5 +1,11 @@
1
1
  import type { EventData, ScrollView, View } from '@nativescript/core'
2
- import { bind, scrollValue, onReducedMotion, reducedMotion } from '@rafaelaugusto/jolt'
2
+ import {
3
+ bind,
4
+ scrollValue,
5
+ onReducedMotion,
6
+ reducedMotion,
7
+ type DerivedValue,
8
+ } from '@rafaelaugusto/jolt'
3
9
  import {
4
10
  bindMotionScrollSource,
5
11
  type MotionScrollAdapter,
@@ -33,7 +39,9 @@ export function nativeScrollMotion(
33
39
  ) {
34
40
  const source = sources.get(adapter)
35
41
  if (!source) throw new TypeError('Use a scrolling MScreen in this renderer.')
36
- const offset = scrollValue(source)
42
+ const offset = scrollValue(source, {
43
+ execution: options.execution === 'scheduler' ? 'javascript' : 'auto',
44
+ })
37
45
  const active = new Map<string, readonly number[]>()
38
46
  for (const [key, values] of Object.entries(frames)) {
39
47
  if (key === 'scale') {
@@ -42,21 +50,45 @@ export function nativeScrollMotion(
42
50
  } else active.set(key, values)
43
51
  }
44
52
  const bindings = new Map<string, () => void>()
53
+ let bounded: DerivedValue | undefined
45
54
  let disposed = false
46
55
  let maximum = -1
47
56
  let content: View | undefined
57
+ const clearBindings = () => {
58
+ for (const release of bindings.values()) release()
59
+ bindings.clear()
60
+ bounded?.dispose()
61
+ bounded = undefined
62
+ }
48
63
  const apply = () => {
49
64
  if (disposed) return
50
- const bounded = offset.to([0, Math.max(1, maximum)], [0, Math.max(0, maximum)])
51
- for (const [key, output] of active) {
52
- bindings.get(key)?.()
53
- const input = output.map(
54
- (_, index) =>
55
- options.range[0] + (index * (options.range[1] - options.range[0])) / (output.length - 1),
56
- )
57
- const values =
58
- reducedMotion() && key !== 'opacity' ? output.map(() => output.at(-1)!) : output
59
- bindings.set(key, bind(target, { [key]: bounded.to(input, values) }))
65
+ clearBindings()
66
+ bounded = offset.to([0, Math.max(1, maximum)], [0, Math.max(0, maximum)])
67
+ try {
68
+ for (const [key, output] of active) {
69
+ const input = output.map(
70
+ (_, index) =>
71
+ options.range[0] +
72
+ (index * (options.range[1] - options.range[0])) / (output.length - 1),
73
+ )
74
+ const values =
75
+ reducedMotion() && key !== 'opacity' ? output.map(() => output.at(-1)!) : output
76
+ const mapped = bounded.to(input, values)
77
+ let release: () => void
78
+ try {
79
+ release = bind(target, { [key]: mapped })
80
+ } catch (error) {
81
+ mapped.dispose()
82
+ throw error
83
+ }
84
+ bindings.set(key, () => {
85
+ release()
86
+ mapped.dispose()
87
+ })
88
+ }
89
+ } catch (error) {
90
+ clearBindings()
91
+ throw error
60
92
  }
61
93
  }
62
94
  const refresh = () => {
@@ -71,16 +103,18 @@ export function nativeScrollMotion(
71
103
  }
72
104
  if (changed) apply()
73
105
  // Re-read the actual bounded offset without a Vue update or an additional clock.
74
- offset.ref(null)
75
- offset.ref(source)
106
+ offset.refresh()
76
107
  }
77
108
  const layout = (_event: EventData) => refresh()
78
109
  source.on('layoutChanged', layout)
79
110
  const offReduced = onReducedMotion(apply)
80
- refresh()
81
- return {
111
+ const control = {
82
112
  get execution() {
83
- return disposed || !active.size ? ('released' as const) : ('native' as const)
113
+ return disposed || !active.size
114
+ ? ('released' as const)
115
+ : offset.execution === 'native'
116
+ ? ('native' as const)
117
+ : ('scheduler' as const)
84
118
  },
85
119
  refresh,
86
120
  interrupt(properties: readonly string[]) {
@@ -90,6 +124,7 @@ export function nativeScrollMotion(
90
124
  bindings.get(key)?.()
91
125
  bindings.delete(key)
92
126
  }
127
+ if (!active.size) control.dispose()
93
128
  },
94
129
  dispose() {
95
130
  if (disposed) return
@@ -97,10 +132,16 @@ export function nativeScrollMotion(
97
132
  source.off('layoutChanged', layout)
98
133
  content?.off('layoutChanged', layout)
99
134
  offReduced()
100
- for (const release of bindings.values()) release()
101
- bindings.clear()
135
+ clearBindings()
102
136
  active.clear()
103
137
  offset.dispose()
104
138
  },
105
139
  }
140
+ try {
141
+ refresh()
142
+ } catch (error) {
143
+ control.dispose()
144
+ throw error
145
+ }
146
+ return control
106
147
  }
@@ -21,6 +21,12 @@ export function nativeSectionScroll(
21
21
  let link: ReturnType<typeof nativeScrollMotion> | undefined
22
22
  let previous = '',
23
23
  disposed = false
24
+ const active = new Map(Object.entries(frames))
25
+ if (active.has('scale')) {
26
+ if (!active.has('scaleX')) active.set('scaleX', active.get('scale')!)
27
+ if (!active.has('scaleY')) active.set('scaleY', active.get('scale')!)
28
+ active.delete('scale')
29
+ }
24
30
  const observed = new Set<View>()
25
31
  const refresh = () => {
26
32
  if (disposed) return
@@ -40,14 +46,14 @@ export function nativeSectionScroll(
40
46
  }
41
47
  const values = measured.settled
42
48
  ? Object.fromEntries(
43
- Object.entries(frames).map(([property, values]) => [
44
- property,
45
- [values.at(-1)!, values.at(-1)!],
46
- ]),
49
+ [...active].map(([property, values]) => [property, [values.at(-1)!, values.at(-1)!]]),
47
50
  )
48
- : frames
51
+ : Object.fromEntries(active)
49
52
  link?.dispose()
50
- link = nativeScrollMotion(adapter, target, values, { range: measured.range })
53
+ link = nativeScrollMotion(adapter, target, values, {
54
+ range: measured.range,
55
+ execution: options.execution,
56
+ })
51
57
  previous = key
52
58
  }
53
59
  for (let view: View | undefined = section; view; view = view.parent as View | undefined) {
@@ -74,7 +80,11 @@ export function nativeSectionScroll(
74
80
  },
75
81
  refresh,
76
82
  interrupt(properties: readonly string[]) {
83
+ for (const property of properties)
84
+ for (const key of property === 'scale' ? ['scaleX', 'scaleY'] : [property])
85
+ active.delete(key)
77
86
  link?.interrupt(properties)
87
+ if (!active.size) dispose()
78
88
  },
79
89
  dispose,
80
90
  }