@getcortexlabs/mavis 0.1.0-alpha.7 → 0.1.0-alpha.9

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 (159) hide show
  1. package/README.md +7 -5
  2. package/dist/date-format.android.d.ts +5 -0
  3. package/dist/date-format.android.d.ts.map +1 -0
  4. package/dist/date-format.android.js +39 -0
  5. package/dist/date-format.android.js.map +1 -0
  6. package/dist/date-format.d.ts +3 -0
  7. package/dist/date-format.d.ts.map +1 -0
  8. package/dist/date-format.ios.d.ts +5 -0
  9. package/dist/date-format.ios.d.ts.map +1 -0
  10. package/dist/date-format.ios.js +29 -0
  11. package/dist/date-format.ios.js.map +1 -0
  12. package/dist/date-format.js +2 -0
  13. package/dist/date-format.js.map +1 -0
  14. package/dist/native/collection-motion.d.ts +5 -0
  15. package/dist/native/collection-motion.d.ts.map +1 -0
  16. package/dist/native/collection-motion.js +157 -0
  17. package/dist/native/collection-motion.js.map +1 -0
  18. package/dist/native/date-format.android.d.ts +5 -0
  19. package/dist/native/date-format.android.d.ts.map +1 -0
  20. package/dist/native/date-format.android.js +39 -0
  21. package/dist/native/date-format.android.js.map +1 -0
  22. package/dist/native/date-format.d.ts +6 -0
  23. package/dist/native/date-format.d.ts.map +1 -0
  24. package/dist/native/date-format.ios.d.ts +5 -0
  25. package/dist/native/date-format.ios.d.ts.map +1 -0
  26. package/dist/native/date-format.ios.js +29 -0
  27. package/dist/native/date-format.ios.js.map +1 -0
  28. package/dist/native/date-format.js +8 -0
  29. package/dist/native/date-format.js.map +1 -0
  30. package/dist/native/image-effects.d.ts +11 -0
  31. package/dist/native/image-effects.d.ts.map +1 -0
  32. package/dist/native/image-effects.js +61 -0
  33. package/dist/native/image-effects.js.map +1 -0
  34. package/dist/native/motion-region.d.ts.map +1 -1
  35. package/dist/native/motion-region.js +7 -2
  36. package/dist/native/motion-region.js.map +1 -1
  37. package/dist/native/motion-surface.d.ts +2 -2
  38. package/dist/native/motion-surface.d.ts.map +1 -1
  39. package/dist/native/motion-surface.js +44 -1
  40. package/dist/native/motion-surface.js.map +1 -1
  41. package/dist/native/platform-motion.d.ts +5 -0
  42. package/dist/native/platform-motion.d.ts.map +1 -0
  43. package/dist/native/platform-motion.js +90 -0
  44. package/dist/native/platform-motion.js.map +1 -0
  45. package/dist/native/surface-effects.d.ts +4 -0
  46. package/dist/native/surface-effects.d.ts.map +1 -0
  47. package/dist/native/surface-effects.js +31 -0
  48. package/dist/native/surface-effects.js.map +1 -0
  49. package/dist/native/visual-effects.d.ts +5 -0
  50. package/dist/native/visual-effects.d.ts.map +1 -0
  51. package/dist/native/visual-effects.js +126 -0
  52. package/dist/native/visual-effects.js.map +1 -0
  53. package/dist/vue/components/DateCalendar.d.ts +1 -1
  54. package/dist/vue/components/LoadingDecoration.d.ts +116 -0
  55. package/dist/vue/components/LoadingDecoration.d.ts.map +1 -0
  56. package/dist/vue/components/LoadingDecoration.js +34 -0
  57. package/dist/vue/components/LoadingDecoration.js.map +1 -0
  58. package/dist/vue/components/MAlert.d.ts +1 -1
  59. package/dist/vue/components/MAvatar.d.ts +1 -1
  60. package/dist/vue/components/MButton.d.ts +32 -10
  61. package/dist/vue/components/MButton.d.ts.map +1 -1
  62. package/dist/vue/components/MButton.js +33 -5
  63. package/dist/vue/components/MButton.js.map +1 -1
  64. package/dist/vue/components/MCard.d.ts +4 -4
  65. package/dist/vue/components/MCard.d.ts.map +1 -1
  66. package/dist/vue/components/MCard.js +4 -3
  67. package/dist/vue/components/MCard.js.map +1 -1
  68. package/dist/vue/components/MChip.d.ts +1 -1
  69. package/dist/vue/components/MCombobox.d.ts +2 -2
  70. package/dist/vue/components/MDatePicker.d.ts +56 -8
  71. package/dist/vue/components/MDatePicker.d.ts.map +1 -1
  72. package/dist/vue/components/MDatePicker.js +4 -14
  73. package/dist/vue/components/MDatePicker.js.map +1 -1
  74. package/dist/vue/components/MDialog.d.ts +3 -0
  75. package/dist/vue/components/MDialog.d.ts.map +1 -1
  76. package/dist/vue/components/MEmptyState.d.ts +1 -1
  77. package/dist/vue/components/MGrid.d.ts +165 -0
  78. package/dist/vue/components/MGrid.d.ts.map +1 -0
  79. package/dist/vue/components/MGrid.js +52 -0
  80. package/dist/vue/components/MGrid.js.map +1 -0
  81. package/dist/vue/components/MIcon.d.ts +18 -0
  82. package/dist/vue/components/MIcon.d.ts.map +1 -1
  83. package/dist/vue/components/MIcon.js +13 -2
  84. package/dist/vue/components/MIcon.js.map +1 -1
  85. package/dist/vue/components/MImage.d.ts +57 -1
  86. package/dist/vue/components/MImage.d.ts.map +1 -1
  87. package/dist/vue/components/MImage.js +58 -3
  88. package/dist/vue/components/MImage.js.map +1 -1
  89. package/dist/vue/components/MInput.d.ts +6 -6
  90. package/dist/vue/components/MInput.d.ts.map +1 -1
  91. package/dist/vue/components/MInput.js +15 -0
  92. package/dist/vue/components/MInput.js.map +1 -1
  93. package/dist/vue/components/MLink.d.ts +2 -2
  94. package/dist/vue/components/MLink.d.ts.map +1 -1
  95. package/dist/vue/components/MLink.js +6 -11
  96. package/dist/vue/components/MLink.js.map +1 -1
  97. package/dist/vue/components/MListItem.d.ts +1 -1
  98. package/dist/vue/components/MReveal.d.ts +9 -9
  99. package/dist/vue/components/MScreen.d.ts +11 -1
  100. package/dist/vue/components/MScreen.d.ts.map +1 -1
  101. package/dist/vue/components/MScreen.js +26 -4
  102. package/dist/vue/components/MScreen.js.map +1 -1
  103. package/dist/vue/components/MSelect.d.ts +1 -1
  104. package/dist/vue/components/MSheet.d.ts +13 -4
  105. package/dist/vue/components/MSheet.d.ts.map +1 -1
  106. package/dist/vue/components/MSkeleton.d.ts +12 -1
  107. package/dist/vue/components/MSkeleton.d.ts.map +1 -1
  108. package/dist/vue/components/MSkeleton.js +5 -3
  109. package/dist/vue/components/MSkeleton.js.map +1 -1
  110. package/dist/vue/components/MStack.d.ts +9 -9
  111. package/dist/vue/components/MText.d.ts +11 -0
  112. package/dist/vue/components/MText.d.ts.map +1 -1
  113. package/dist/vue/components/MText.js +3 -1
  114. package/dist/vue/components/MText.js.map +1 -1
  115. package/dist/vue/components/configurator.d.ts +3 -3
  116. package/dist/vue/components/layout.d.ts +30 -19
  117. package/dist/vue/components/layout.d.ts.map +1 -1
  118. package/dist/vue/components/layout.js +3 -1
  119. package/dist/vue/components/layout.js.map +1 -1
  120. package/dist/vue/index.d.ts +11 -11
  121. package/dist/vue/index.d.ts.map +1 -1
  122. package/dist/vue/index.js +12 -12
  123. package/dist/vue/index.js.map +1 -1
  124. package/dist/vue/services.d.ts +16 -0
  125. package/dist/vue/services.d.ts.map +1 -0
  126. package/dist/vue/services.js +18 -0
  127. package/dist/vue/services.js.map +1 -0
  128. package/dist/vue/use-motion-surface.d.ts +1 -1
  129. package/dist/vue/use-motion-surface.d.ts.map +1 -1
  130. package/dist/vue/use-motion-surface.js +31 -2
  131. package/dist/vue/use-motion-surface.js.map +1 -1
  132. package/package.json +15 -4
  133. package/src/date-format.ts +2 -0
  134. package/src/native/collection-motion.ts +166 -0
  135. package/src/native/date-format.android.ts +72 -0
  136. package/src/native/date-format.ios.ts +54 -0
  137. package/src/native/date-format.ts +17 -0
  138. package/src/native/image-effects.ts +71 -0
  139. package/src/native/motion-region.ts +7 -2
  140. package/src/native/motion-surface.ts +51 -2
  141. package/src/native/platform-motion.ts +103 -0
  142. package/src/native/surface-effects.ts +33 -0
  143. package/src/native/visual-effects.ts +147 -0
  144. package/src/vue/components/LoadingDecoration.ts +38 -0
  145. package/src/vue/components/MButton.ts +37 -4
  146. package/src/vue/components/MCard.ts +4 -2
  147. package/src/vue/components/MDatePicker.ts +3 -11
  148. package/src/vue/components/MGrid.ts +86 -0
  149. package/src/vue/components/MIcon.ts +14 -2
  150. package/src/vue/components/MImage.ts +66 -2
  151. package/src/vue/components/MInput.ts +14 -3
  152. package/src/vue/components/MLink.ts +12 -9
  153. package/src/vue/components/MScreen.ts +31 -3
  154. package/src/vue/components/MSkeleton.ts +5 -3
  155. package/src/vue/components/MText.ts +7 -0
  156. package/src/vue/components/layout.ts +3 -0
  157. package/src/vue/index.ts +63 -69
  158. package/src/vue/services.ts +32 -0
  159. package/src/vue/use-motion-surface.ts +32 -1
@@ -0,0 +1,166 @@
1
+ import { LayoutBase, isIOS, type View } from '@nativescript/core'
2
+ import { scrollHeader, type MotionScope } from '@rafaelaugusto/jolt'
3
+ import { reorder, type Reorder } from '@rafaelaugusto/jolt/reorder'
4
+ import {
5
+ mapMotionItems,
6
+ type MotionRegionAdapter,
7
+ type MotionSurfaceAdapter,
8
+ } from '@getcortexlabs/mavis-core/experimental'
9
+ import { nativeScrollElement } from './scroll-motion.js'
10
+
11
+ const headerInsets = new WeakMap<LayoutBase, { previous: boolean; owners: number }>()
12
+ function retainHeaderLayout(header: LayoutBase) {
13
+ if (!isIOS) return () => {}
14
+ const state = headerInsets.get(header) ?? { previous: header.iosIgnoreSafeArea, owners: 0 }
15
+ state.owners++
16
+ headerInsets.set(header, state)
17
+ header.iosIgnoreSafeArea = true
18
+ let released = false
19
+ return () => {
20
+ if (released) return
21
+ released = true
22
+ if (--state.owners) return
23
+ headerInsets.delete(header)
24
+ if (header.iosIgnoreSafeArea === true) header.iosIgnoreSafeArea = state.previous
25
+ }
26
+ }
27
+
28
+ export function nativeCollectionMotion(
29
+ target: View,
30
+ resolve: (surface: MotionSurfaceAdapter) => View,
31
+ scope: MotionScope,
32
+ ): Pick<MotionRegionAdapter, 'scrollHeader' | 'reorder'> {
33
+ return {
34
+ scrollHeader(source, options) {
35
+ const {
36
+ header,
37
+ artwork,
38
+ title,
39
+ toolbar,
40
+ toolbarTitle,
41
+ section,
42
+ items,
43
+ expanded,
44
+ minimum,
45
+ ...rest
46
+ } = options
47
+ const headerView = resolve(header)
48
+ if (!(headerView instanceof LayoutBase))
49
+ throw new TypeError('Use a layout surface for the header.')
50
+ const artworkView = resolve(artwork)
51
+ // The moving header already sits inside MScreen's safe area. Reapplying
52
+ // UIKit's changing insets to its children would shift them during reflow.
53
+ const restoreHeader = retainHeaderLayout(headerView)
54
+ let headerControl: ReturnType<typeof scrollHeader>
55
+ try {
56
+ headerControl = scrollHeader(nativeScrollElement(source), {
57
+ ...rest,
58
+ header: headerView,
59
+ artwork: artworkView,
60
+ title: resolve(title),
61
+ toolbar: resolve(toolbar),
62
+ toolbarTitle: resolve(toolbarTitle),
63
+ section: resolve(section),
64
+ expandedHeight: expanded,
65
+ minimumHeight: minimum,
66
+ items: () => mapMotionItems(items(), resolve),
67
+ })
68
+ } catch (error) {
69
+ restoreHeader()
70
+ throw error
71
+ }
72
+ const control = headerControl
73
+ let released = false
74
+ const lifetime = scope.add({
75
+ dispose() {
76
+ if (released) return
77
+ released = true
78
+ try {
79
+ control.dispose()
80
+ } finally {
81
+ restoreHeader()
82
+ }
83
+ },
84
+ })
85
+ return {
86
+ get ready() {
87
+ return control.ready
88
+ },
89
+ get state() {
90
+ return {
91
+ offset: control.state.offset,
92
+ refreshing: control.state.refresh === 'refreshing',
93
+ }
94
+ },
95
+ refresh: () => control.refresh(),
96
+ cancelRefresh: () => control.cancelRefresh(),
97
+ remeasure: () => control.remeasure(),
98
+ preserveAnchor: (change) => control.preserveAnchor(change),
99
+ scrollToItem(key, animated = true) {
100
+ const index = items().findIndex((item) => item.key === key)
101
+ if (index < 0) return false
102
+ control.scrollToItem(index, animated)
103
+ return true
104
+ },
105
+ scrollToTop: (animated = true) => control.scrollToTop(animated),
106
+ pause: () => control.pause(),
107
+ play: () => control.play(),
108
+ dispose: () => lifetime.dispose(),
109
+ }
110
+ },
111
+ reorder(options) {
112
+ const { container, items, scroll, accessibility, ...rest } = options
113
+ const layout = resolve(container)
114
+ if (!(layout instanceof LayoutBase))
115
+ throw new TypeError('Use a layout motion surface for retained rows.')
116
+ let control: Reorder<string> | undefined
117
+ let disposed = false,
118
+ paused = false,
119
+ queued = false
120
+ const attach = () => {
121
+ if (disposed || control) return
122
+ layout.off('layoutChanged', laidOut)
123
+ control = reorder(layout, {
124
+ ...rest,
125
+ scroll: nativeScrollElement(scroll),
126
+ items: () => mapMotionItems(items(), resolve),
127
+ accessibility: { moveUp: accessibility?.moveUp, moveDown: accessibility?.moveDown },
128
+ })
129
+ if (paused) control.pause()
130
+ }
131
+ // `loaded` precedes native layout. Wait for that lifecycle boundary once;
132
+ // Jolt owns subsequent geometry updates, gestures and animation scheduling.
133
+ const laidOut = () => {
134
+ if (queued) return
135
+ queued = true
136
+ void Promise.resolve().then(attach)
137
+ }
138
+ if (layout.isLayoutValid && layout.getActualSize().height > 0) attach()
139
+ else layout.on('layoutChanged', laidOut)
140
+ return scope.add({
141
+ get activeKey() {
142
+ return control?.activeKey
143
+ },
144
+ move: (key: string, before: string | null) => control?.move(key, before) ?? false,
145
+ moveUp: (key: string) => control?.moveUp(key) ?? false,
146
+ moveDown: (key: string) => control?.moveDown(key) ?? false,
147
+ refresh: () => control?.refresh(),
148
+ cancel: () => control?.cancel(),
149
+ pause() {
150
+ paused = true
151
+ control?.pause()
152
+ },
153
+ play() {
154
+ paused = false
155
+ control?.play()
156
+ },
157
+ dispose() {
158
+ disposed = true
159
+ layout.off('layoutChanged', laidOut)
160
+ control?.dispose()
161
+ control = undefined
162
+ },
163
+ })
164
+ },
165
+ }
166
+ }
@@ -0,0 +1,72 @@
1
+ import {
2
+ civilDate,
3
+ dateTimeMilliseconds,
4
+ resolveDateTimeOptions,
5
+ type DateTimeValue,
6
+ type DateTimeFormatOptions,
7
+ } from '@getcortexlabs/mavis-core'
8
+ export type { DateTimeValue, DateTimeFormatOptions, DateTimeStyle } from '@getcortexlabs/mavis-core'
9
+
10
+ interface Formatter {
11
+ setTimeZone(zone: unknown): void
12
+ setCalendar(calendar: unknown): void
13
+ format(date: unknown): string
14
+ }
15
+ declare const java: {
16
+ util: {
17
+ Date: new (milliseconds: number) => unknown
18
+ GregorianCalendar: new (
19
+ zone: unknown,
20
+ locale: unknown,
21
+ ) => { setGregorianChange(date: unknown): void }
22
+ Locale: { forLanguageTag(locale: string): unknown; US: unknown }
23
+ TimeZone: { getAvailableIDs(): ArrayLike<string>; getTimeZone(id: string): unknown }
24
+ }
25
+ text: {
26
+ DateFormat: {
27
+ getDateTimeInstance(date: number, time: number, locale: unknown): Formatter
28
+ getDateInstance(date: number, locale: unknown): Formatter
29
+ getTimeInstance(time: number, locale: unknown): Formatter
30
+ }
31
+ SimpleDateFormat: new (pattern: string, locale: unknown) => Formatter
32
+ }
33
+ }
34
+ function zone(name: string) {
35
+ // TimeZone.getTimeZone silently returns GMT for unknown identifiers. Reject that fallback.
36
+ const known = Array.from(java.util.TimeZone.getAvailableIDs())
37
+ if (!known.includes(name)) throw new RangeError(`Unknown timeZone: ${name}`)
38
+ return java.util.TimeZone.getTimeZone(name)
39
+ }
40
+ function configureCalendar(formatter: Formatter, timeZone: string, locale: unknown) {
41
+ const value = zone(timeZone)
42
+ const calendar = new java.util.GregorianCalendar(value, locale)
43
+ calendar.setGregorianChange(new java.util.Date(-8640000000000000))
44
+ formatter.setCalendar(calendar)
45
+ }
46
+ export function formatDateTime(value: DateTimeValue, options: DateTimeFormatOptions): string {
47
+ const milliseconds = dateTimeMilliseconds(value)
48
+ const config = resolveDateTimeOptions(options)
49
+ const locale = java.util.Locale.forLanguageTag(config.locale)
50
+ const styles = { full: 0, long: 1, medium: 2, short: 3 }
51
+ const factory = java.text.DateFormat
52
+ const result =
53
+ config.dateStyle && config.timeStyle
54
+ ? factory.getDateTimeInstance(styles[config.dateStyle], styles[config.timeStyle], locale)
55
+ : config.dateStyle
56
+ ? factory.getDateInstance(styles[config.dateStyle], locale)
57
+ : factory.getTimeInstance(styles[config.timeStyle!], locale)
58
+ configureCalendar(result, config.timeZone, locale)
59
+ return String(result.format(new java.util.Date(milliseconds)))
60
+ }
61
+ export function dateTimeToCivilDate(
62
+ value: DateTimeValue,
63
+ options: Pick<DateTimeFormatOptions, 'timeZone'>,
64
+ ) {
65
+ const milliseconds = dateTimeMilliseconds(value)
66
+ const { timeZone } = resolveDateTimeOptions(options)
67
+ const result = new java.text.SimpleDateFormat('G yyyy-MM-dd', java.util.Locale.US)
68
+ configureCalendar(result, timeZone, java.util.Locale.US)
69
+ const text = String(result.format(new java.util.Date(milliseconds)))
70
+ if (!text.startsWith('AD ')) throw new RangeError('Civil dates support years 0001–9999.')
71
+ return civilDate(text.slice(3))
72
+ }
@@ -0,0 +1,54 @@
1
+ import {
2
+ civilDate,
3
+ dateTimeMilliseconds,
4
+ resolveDateTimeOptions,
5
+ type DateTimeValue,
6
+ type DateTimeFormatOptions,
7
+ } from '@getcortexlabs/mavis-core'
8
+ export type { DateTimeValue, DateTimeFormatOptions, DateTimeStyle } from '@getcortexlabs/mavis-core'
9
+
10
+ declare const NSDate: { dateWithTimeIntervalSince1970(seconds: number): unknown }
11
+ declare const NSTimeZone: { timeZoneWithName(name: string): unknown | null }
12
+ declare const NSLocale: { alloc(): { initWithLocaleIdentifier(locale: string): unknown } }
13
+ declare const NSCalendar: { calendarWithIdentifier(identifier: string): unknown }
14
+ interface Formatter {
15
+ locale: unknown
16
+ timeZone: unknown
17
+ calendar: unknown
18
+ dateStyle: number
19
+ timeStyle: number
20
+ dateFormat: string
21
+ gregorianStartDate: unknown
22
+ stringFromDate(value: unknown): string
23
+ }
24
+ declare const NSDateFormatter: { new: () => Formatter }
25
+ function formatter(options: DateTimeFormatOptions) {
26
+ const config = resolveDateTimeOptions(options)
27
+ const zone = NSTimeZone.timeZoneWithName(config.timeZone)
28
+ if (!zone) throw new RangeError(`Unknown timeZone: ${config.timeZone}`)
29
+ const result = NSDateFormatter.new()
30
+ result.locale = NSLocale.alloc().initWithLocaleIdentifier(config.locale)
31
+ result.calendar = NSCalendar.calendarWithIdentifier('gregorian')
32
+ result.gregorianStartDate = NSDate.dateWithTimeIntervalSince1970(-8640000000000)
33
+ result.timeZone = zone
34
+ const styles = { short: 1, medium: 2, long: 3, full: 4 }
35
+ result.dateStyle = config.dateStyle ? styles[config.dateStyle] : 0
36
+ result.timeStyle = config.timeStyle ? styles[config.timeStyle] : 0
37
+ return result
38
+ }
39
+ export function formatDateTime(value: DateTimeValue, options: DateTimeFormatOptions): string {
40
+ const instant = NSDate.dateWithTimeIntervalSince1970(dateTimeMilliseconds(value) / 1000)
41
+ return formatter(options).stringFromDate(instant)
42
+ }
43
+ export function dateTimeToCivilDate(
44
+ value: DateTimeValue,
45
+ options: Pick<DateTimeFormatOptions, 'timeZone'>,
46
+ ) {
47
+ const result = formatter({ ...options, locale: 'en-US-POSIX', dateStyle: 'short' })
48
+ result.dateFormat = 'G yyyy-MM-dd'
49
+ const text = result.stringFromDate(
50
+ NSDate.dateWithTimeIntervalSince1970(dateTimeMilliseconds(value) / 1000),
51
+ )
52
+ if (!text.startsWith('AD ')) throw new RangeError('Civil dates support years 0001–9999.')
53
+ return civilDate(text.slice(3))
54
+ }
@@ -0,0 +1,17 @@
1
+ import type { DateTimeValue, DateTimeFormatOptions, CivilDate } from '@getcortexlabs/mavis-core'
2
+ export type { DateTimeValue, DateTimeFormatOptions, DateTimeStyle } from '@getcortexlabs/mavis-core'
3
+
4
+ /** NativeScript resolves the .ios/.android implementation in a device bundle. */
5
+ export function formatDateTime(_value: DateTimeValue, _options: DateTimeFormatOptions): string {
6
+ throw new Error(
7
+ 'Native date formatting requires an iOS or Android runtime. Use the Web formatter on the server.',
8
+ )
9
+ }
10
+ export function dateTimeToCivilDate(
11
+ _value: DateTimeValue,
12
+ _options: Pick<DateTimeFormatOptions, 'timeZone'>,
13
+ ): CivilDate {
14
+ throw new Error(
15
+ 'Native date formatting requires an iOS or Android runtime. Use the Web formatter on the server.',
16
+ )
17
+ }
@@ -0,0 +1,71 @@
1
+ import { Image, type View } from '@nativescript/core'
2
+ import { imageEffect } from '@rafaelaugusto/jolt'
3
+ import type {
4
+ MotionImageEffectName,
5
+ MotionImageEffectOptions,
6
+ MotionPlayback,
7
+ } from '@getcortexlabs/mavis-core/experimental'
8
+ import { loadAvatarImage } from './avatar-image.js'
9
+
10
+ type Presentation = {
11
+ current(): boolean
12
+ commit(src: string, image: Image['imageSource']): Promise<boolean>
13
+ }
14
+ const images = new WeakMap<Image, Presentation>()
15
+ const preparations = new WeakMap<Image, object>()
16
+ export function registerMotionImage(target: Image, presentation: Presentation) {
17
+ images.set(target, presentation)
18
+ return () => {
19
+ if (images.get(target) === presentation) images.delete(target)
20
+ }
21
+ }
22
+ export function loadedMotionImage(target: View): Image {
23
+ if (!(target instanceof Image) || !images.has(target) || !target.imageSource)
24
+ throw new TypeError('Use the ready motionSurface of MImage for pixel effects.')
25
+ return target
26
+ }
27
+ export async function nativeImageEffect(
28
+ target: View,
29
+ name: MotionImageEffectName,
30
+ options: MotionImageEffectOptions = {},
31
+ live: () => boolean = () => true,
32
+ ) {
33
+ const image = loadedMotionImage(target),
34
+ presentation = images.get(image)!
35
+ const { to, ...rest } = options
36
+ if (to !== undefined && (name !== 'dissolve' || !to.trim()))
37
+ throw new TypeError('Only dissolve accepts a nonempty destination source.')
38
+ const preparation = {}
39
+ preparations.set(image, preparation)
40
+ const destination = to === undefined ? undefined : await loadAvatarImage(to)
41
+ if (to !== undefined && !destination) throw new Error('Destination image could not be decoded.')
42
+ if (
43
+ !live() ||
44
+ preparations.get(image) !== preparation ||
45
+ !presentation.current() ||
46
+ images.get(image) !== presentation ||
47
+ !image.isLoaded
48
+ )
49
+ throw new Error('Image presentation changed while preparing the effect.')
50
+ const previous = image.imageSource
51
+ const raw = imageEffect(image, name, { ...rest, ...(destination ? { to: destination } : {}) })
52
+ const finished = raw.finished.then(async (success) => {
53
+ if (!success || !to || raw.progress !== 1) return success
54
+ if (!presentation.current() || images.get(image) !== presentation) return false
55
+ if (!live()) {
56
+ if (image.imageSource === destination) image.imageSource = previous
57
+ return false
58
+ }
59
+ return presentation.commit(to, destination!)
60
+ })
61
+ return new Proxy(raw as MotionPlayback, {
62
+ get(target, key) {
63
+ // Native animations are thenable; returning one from an async factory would await completion.
64
+ if (key === 'then') return undefined
65
+ if (key === 'finished') return finished
66
+ const value = Reflect.get(target, key, target)
67
+ return typeof value === 'function' ? value.bind(target) : value
68
+ },
69
+ set: (target, key, value) => Reflect.set(target, key, value, target),
70
+ })
71
+ }
@@ -8,6 +8,8 @@ import {
8
8
  type MotionSurfaceAdapter,
9
9
  } from '@getcortexlabs/mavis-core/experimental'
10
10
  import { nativeScrollElement } from './scroll-motion.js'
11
+ import { nativeCollectionMotion } from './collection-motion.js'
12
+ import { nativePlatformMotion } from './platform-motion.js'
11
13
 
12
14
  const targets = new WeakMap<MotionSurfaceAdapter, View>()
13
15
  const regions = new WeakMap<MotionRegionAdapter, View>()
@@ -103,8 +105,9 @@ function viewportEnter(
103
105
  if (!visible) stop(state)
104
106
  if (visible && !state.visible && !state.animation) {
105
107
  const animation = animate(state.target, options.frames ?? { opacity: [0, 1], y: [20, 0] }, {
106
- duration: 450,
107
- ...options.transition,
108
+ ...(options.transition?.type === 'gravity'
109
+ ? options.transition
110
+ : { duration: 450, ...options.transition }),
108
111
  delay: (options.transition?.delay ?? 0) + state.index * (options.stagger ?? 70),
109
112
  })
110
113
  state.animation = animation
@@ -190,6 +193,8 @@ export function attachNativeMotionRegion(reference: MotionRegion, target: View)
190
193
  : ([resolveChild(step[0]), step[1], step[2]] as const),
191
194
  )
192
195
  const adapter: MotionRegionAdapter = {
196
+ ...nativePlatformMotion(target, resolveChild, scope),
197
+ ...nativeCollectionMotion(target, resolveChild, scope),
193
198
  sequence: (items) =>
194
199
  scope.sequence(steps(items) as unknown as Parameters<typeof scope.sequence>[0]),
195
200
  timeline: (items) =>
@@ -1,5 +1,7 @@
1
1
  import { nativeScrollMotion } from './scroll-motion.js'
2
2
  import { assertNativeRegion } from './motion-region.js'
3
+ import { nativeVisualEffects } from './visual-effects.js'
4
+ import { sensor } from '@rafaelaugusto/jolt/sensors'
3
5
  import type { View, EventData, TouchGestureEventData } from '@nativescript/core'
4
6
  import {
5
7
  animate,
@@ -18,7 +20,11 @@ import type {
18
20
  MotionValueAdapter,
19
21
  } from '@getcortexlabs/mavis-core/experimental'
20
22
 
21
- export function nativeContinuousSurface(target: View, enabled: () => boolean) {
23
+ export function nativeContinuousSurface(
24
+ target: View,
25
+ enabled: () => boolean,
26
+ plainText: () => boolean = () => false,
27
+ ) {
22
28
  const sources = new WeakMap<object, DerivedValue>()
23
29
  const colorSources = new WeakMap<object, import('@rafaelaugusto/jolt').DerivedColor>()
24
30
  const refreshes = new Set<() => void>()
@@ -42,7 +48,50 @@ export function nativeContinuousSurface(target: View, enabled: () => boolean) {
42
48
  | 'refresh'
43
49
  | 'scrollLinked'
44
50
  | 'pointerFollow'
45
- > = {
51
+ | 'sensor'
52
+ > &
53
+ import('@getcortexlabs/mavis-core/experimental').MotionVisualAdapter = {
54
+ ...nativeVisualEffects(target, sources, colorSources, plainText),
55
+ sensor(kind, options) {
56
+ const input = sensor(kind, options)
57
+ const wrap = (source: DerivedValue) => {
58
+ const value = { get: () => source.get(), dispose() {} }
59
+ sources.set(value, source)
60
+ return value
61
+ }
62
+ return {
63
+ kind,
64
+ x: wrap(input.x),
65
+ y: wrap(input.y),
66
+ z: wrap(input.z),
67
+ quaternion:
68
+ input.kind === 'rotation'
69
+ ? {
70
+ x: wrap(input.quaternion.x),
71
+ y: wrap(input.quaternion.y),
72
+ z: wrap(input.quaternion.z),
73
+ w: wrap(input.quaternion.w),
74
+ }
75
+ : undefined,
76
+ get status() {
77
+ return input.status
78
+ },
79
+ get available() {
80
+ return input.available
81
+ },
82
+ get paused() {
83
+ return input.paused
84
+ },
85
+ pause: () => input.pause(),
86
+ resume: () => input.play(),
87
+ recenter: () => {
88
+ if (input.kind === 'rotation') input.recenter()
89
+ },
90
+ requestPermission: async () => 'not-required' as const,
91
+ snapshot: () => ({ ...input.snapshot(), backend: 'native' as const }),
92
+ dispose: () => input.dispose(),
93
+ }
94
+ },
46
95
  pointerFollow(region, options) {
47
96
  assertNativeRegion(region, target)
48
97
  const x = adapter.motionValue!(options.rest?.x ?? 0)
@@ -0,0 +1,103 @@
1
+ import type { View } from '@nativescript/core'
2
+ import { onKeyboard, type MotionScope } from '@rafaelaugusto/jolt'
3
+ import { physicsWorld } from '@rafaelaugusto/jolt/physics'
4
+ import type {
5
+ MotionRegionAdapter,
6
+ MotionSurfaceAdapter,
7
+ MotionKeyboardState,
8
+ } from '@getcortexlabs/mavis-core/experimental'
9
+
10
+ function afterLayout(targets: readonly View[], scope: MotionScope): Promise<void> {
11
+ return new Promise((resolve, reject) => {
12
+ let settled = false,
13
+ release: (() => void) | undefined
14
+ const clear = () => {
15
+ settled = true
16
+ for (const target of targets) {
17
+ target.off('layoutChanged', changed)
18
+ target.off('unloaded', unloaded)
19
+ }
20
+ release?.()
21
+ }
22
+ const check = () => {
23
+ if (settled) return
24
+ if (
25
+ targets.every(
26
+ (target) =>
27
+ target.isLoaded &&
28
+ target.isLayoutValid &&
29
+ target.getActualSize().width > 0 &&
30
+ target.getActualSize().height > 0,
31
+ )
32
+ ) {
33
+ clear()
34
+ resolve()
35
+ }
36
+ }
37
+ const changed = () => {
38
+ void Promise.resolve().then(check)
39
+ }
40
+ const unloaded = () => {
41
+ if (settled) return
42
+ clear()
43
+ reject(new Error('Physics presentation released before layout.'))
44
+ }
45
+ if (scope.disposed || scope.suspended) {
46
+ unloaded()
47
+ return
48
+ }
49
+ for (const target of targets) {
50
+ target.on('layoutChanged', changed)
51
+ target.on('unloaded', unloaded)
52
+ }
53
+ release = scope.use(() => unloaded)
54
+ check()
55
+ })
56
+ }
57
+ export function nativePlatformMotion(
58
+ target: View,
59
+ resolve: (surface: MotionSurfaceAdapter) => View,
60
+ scope: MotionScope,
61
+ ): Pick<MotionRegionAdapter, 'onKeyboard' | 'physicsWorld'> {
62
+ return {
63
+ onKeyboard(callback) {
64
+ let state: MotionKeyboardState = {
65
+ visible: false,
66
+ height: 0,
67
+ duration: 0,
68
+ backend: 'native',
69
+ accuracy: 'unavailable',
70
+ }
71
+ const read = () => state
72
+ const release = scope.use(() => {
73
+ const off = onKeyboard((value) => {
74
+ state = { ...value, backend: 'native', accuracy: 'native' }
75
+ callback(state)
76
+ })
77
+ callback(read())
78
+ return off
79
+ })
80
+ return { snapshot: read, dispose: release }
81
+ },
82
+ async physicsWorld(bodies, options) {
83
+ const mapped = bodies.map(({ target, ...body }) => ({ ...body, view: resolve(target) }))
84
+ await afterLayout([target, ...mapped.map((body) => body.view)], scope)
85
+ if (scope.disposed || scope.suspended) throw new Error('Physics presentation is inactive.')
86
+ const world = physicsWorld(target, mapped, { ...options, scope })
87
+ return {
88
+ get paused() {
89
+ return world.paused
90
+ },
91
+ pause: () => world.pause(),
92
+ resume: () => world.play(),
93
+ reset: () => world.reset(),
94
+ impulse: (id, value) => world.impulse(id, value),
95
+ attach: (id, value) => world.attach(id, value),
96
+ spring: (id, value) => world.spring(id, value),
97
+ snapTo: (id, index) => world.snapTo(id, index),
98
+ snapshot: () => world.snapshot(),
99
+ dispose: () => world.dispose(),
100
+ }
101
+ },
102
+ }
103
+ }
@@ -0,0 +1,33 @@
1
+ import { Image, isIOS, isAndroid, type View } from '@nativescript/core'
2
+ import { particles, confetti, liquid, symbolEffect, followKeyboard } from '@rafaelaugusto/jolt'
3
+ import { blur } from '@rafaelaugusto/jolt/blur'
4
+ import { shape } from '@rafaelaugusto/jolt/shapes'
5
+ import type { MotionSurfaceEffectsAdapter } from '@getcortexlabs/mavis-core/experimental'
6
+ import { loadedMotionImage, nativeImageEffect } from './image-effects.js'
7
+
8
+ export function nativeSurfaceEffects(target: View): MotionSurfaceEffectsAdapter {
9
+ return {
10
+ particles: (options) => ({
11
+ supported: isIOS || isAndroid,
12
+ dispose: particles(target, options),
13
+ }),
14
+ confetti: (options) => ({ supported: isIOS || isAndroid, dispose: confetti(target, options) }),
15
+ blur: (options) => blur(target, options),
16
+ shape: (options) => shape(target, options),
17
+ liquid(options) {
18
+ const effect = liquid(loadedMotionImage(target), options)
19
+ return {
20
+ supported: isIOS,
21
+ pause: () => effect.pause(),
22
+ resume: () => effect.resume(),
23
+ dispose: () => effect.stop(),
24
+ }
25
+ },
26
+ imageEffect: (name, options, live) => nativeImageEffect(target, name, options, live),
27
+ symbolEffect: (name, options) =>
28
+ target instanceof Image
29
+ ? symbolEffect(target, name, options)
30
+ : { finished: Promise.resolve(false), stop() {} },
31
+ followKeyboard: (options) => ({ dispose: followKeyboard(target, options) }),
32
+ }
33
+ }