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

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 (216) hide show
  1. package/README.md +5 -5
  2. package/dist/app-icons.d.ts +26 -0
  3. package/dist/app-icons.d.ts.map +1 -0
  4. package/dist/app-icons.js +9 -0
  5. package/dist/app-icons.js.map +1 -0
  6. package/dist/files.d.ts +4 -0
  7. package/dist/files.d.ts.map +1 -0
  8. package/dist/files.js +3 -0
  9. package/dist/files.js.map +1 -0
  10. package/dist/native/app-icons.android.d.ts +4 -0
  11. package/dist/native/app-icons.android.d.ts.map +1 -0
  12. package/dist/native/app-icons.android.js +67 -0
  13. package/dist/native/app-icons.android.js.map +1 -0
  14. package/dist/native/app-icons.d.ts +4 -0
  15. package/dist/native/app-icons.d.ts.map +1 -0
  16. package/dist/native/app-icons.ios.d.ts +4 -0
  17. package/dist/native/app-icons.ios.d.ts.map +1 -0
  18. package/dist/native/app-icons.ios.js +45 -0
  19. package/dist/native/app-icons.ios.js.map +1 -0
  20. package/dist/native/app-icons.js +9 -0
  21. package/dist/native/app-icons.js.map +1 -0
  22. package/dist/native/combobox-editor.android.d.ts +3 -0
  23. package/dist/native/combobox-editor.android.d.ts.map +1 -0
  24. package/dist/native/combobox-editor.android.js +5 -0
  25. package/dist/native/combobox-editor.android.js.map +1 -0
  26. package/dist/native/combobox-editor.d.ts +4 -0
  27. package/dist/native/combobox-editor.d.ts.map +1 -0
  28. package/dist/native/combobox-editor.js +5 -0
  29. package/dist/native/combobox-editor.js.map +1 -0
  30. package/dist/native/file-access.d.ts +23 -0
  31. package/dist/native/file-access.d.ts.map +1 -0
  32. package/dist/native/file-access.js +55 -0
  33. package/dist/native/file-access.js.map +1 -0
  34. package/dist/native/file-picker.android.d.ts +3 -0
  35. package/dist/native/file-picker.android.d.ts.map +1 -0
  36. package/dist/native/file-picker.android.js +147 -0
  37. package/dist/native/file-picker.android.js.map +1 -0
  38. package/dist/native/file-picker.d.ts +4 -0
  39. package/dist/native/file-picker.d.ts.map +1 -0
  40. package/dist/native/file-picker.ios.d.ts +3 -0
  41. package/dist/native/file-picker.ios.d.ts.map +1 -0
  42. package/dist/native/file-picker.ios.js +152 -0
  43. package/dist/native/file-picker.ios.js.map +1 -0
  44. package/dist/native/file-picker.js +7 -0
  45. package/dist/native/file-picker.js.map +1 -0
  46. package/dist/native/motion-owner.d.ts +5 -0
  47. package/dist/native/motion-owner.d.ts.map +1 -0
  48. package/dist/native/motion-owner.js +57 -0
  49. package/dist/native/motion-owner.js.map +1 -0
  50. package/dist/native/motion-region.d.ts +6 -0
  51. package/dist/native/motion-region.d.ts.map +1 -0
  52. package/dist/native/motion-region.js +237 -0
  53. package/dist/native/motion-region.js.map +1 -0
  54. package/dist/native/motion-surface.d.ts +1 -1
  55. package/dist/native/motion-surface.d.ts.map +1 -1
  56. package/dist/native/motion-surface.js +43 -2
  57. package/dist/native/motion-surface.js.map +1 -1
  58. package/dist/native/press.d.ts +3 -2
  59. package/dist/native/press.d.ts.map +1 -1
  60. package/dist/native/press.js.map +1 -1
  61. package/dist/native/scroll-motion.d.ts +1 -0
  62. package/dist/native/scroll-motion.d.ts.map +1 -1
  63. package/dist/native/scroll-motion.js +6 -0
  64. package/dist/native/scroll-motion.js.map +1 -1
  65. package/dist/vue/components/ChoiceControl.d.ts +21 -11
  66. package/dist/vue/components/ChoiceControl.d.ts.map +1 -1
  67. package/dist/vue/components/DateCalendar.d.ts +94 -0
  68. package/dist/vue/components/DateCalendar.d.ts.map +1 -0
  69. package/dist/vue/components/DateCalendar.js +96 -0
  70. package/dist/vue/components/DateCalendar.js.map +1 -0
  71. package/dist/vue/components/MAccordion.d.ts +19 -9
  72. package/dist/vue/components/MAccordion.d.ts.map +1 -1
  73. package/dist/vue/components/MAlert.d.ts +20 -10
  74. package/dist/vue/components/MAlert.d.ts.map +1 -1
  75. package/dist/vue/components/MAvatar.d.ts +12 -6
  76. package/dist/vue/components/MAvatar.d.ts.map +1 -1
  77. package/dist/vue/components/MBadge.d.ts +12 -6
  78. package/dist/vue/components/MBadge.d.ts.map +1 -1
  79. package/dist/vue/components/MButton.d.ts +127 -39
  80. package/dist/vue/components/MButton.d.ts.map +1 -1
  81. package/dist/vue/components/MButton.js +20 -13
  82. package/dist/vue/components/MButton.js.map +1 -1
  83. package/dist/vue/components/MCard.d.ts +89 -15
  84. package/dist/vue/components/MCard.d.ts.map +1 -1
  85. package/dist/vue/components/MCard.js +12 -5
  86. package/dist/vue/components/MCard.js.map +1 -1
  87. package/dist/vue/components/MCheckbox.d.ts +20 -10
  88. package/dist/vue/components/MCheckbox.d.ts.map +1 -1
  89. package/dist/vue/components/MChip.d.ts +22 -12
  90. package/dist/vue/components/MChip.d.ts.map +1 -1
  91. package/dist/vue/components/MCombobox.d.ts +279 -0
  92. package/dist/vue/components/MCombobox.d.ts.map +1 -0
  93. package/dist/vue/components/MCombobox.js +234 -0
  94. package/dist/vue/components/MCombobox.js.map +1 -0
  95. package/dist/vue/components/MDatePicker.d.ts +1302 -0
  96. package/dist/vue/components/MDatePicker.d.ts.map +1 -0
  97. package/dist/vue/components/MDatePicker.js +35 -0
  98. package/dist/vue/components/MDatePicker.js.map +1 -0
  99. package/dist/vue/components/MDialog.d.ts +7 -5
  100. package/dist/vue/components/MDialog.d.ts.map +1 -1
  101. package/dist/vue/components/MEmptyState.d.ts +19 -9
  102. package/dist/vue/components/MEmptyState.d.ts.map +1 -1
  103. package/dist/vue/components/MFilePicker.d.ts +112 -0
  104. package/dist/vue/components/MFilePicker.d.ts.map +1 -0
  105. package/dist/vue/components/MFilePicker.js +196 -0
  106. package/dist/vue/components/MFilePicker.js.map +1 -0
  107. package/dist/vue/components/MIcon.d.ts +4 -2
  108. package/dist/vue/components/MIcon.d.ts.map +1 -1
  109. package/dist/vue/components/MInput.d.ts +132 -60
  110. package/dist/vue/components/MInput.d.ts.map +1 -1
  111. package/dist/vue/components/MInput.js +3 -3
  112. package/dist/vue/components/MInput.js.map +1 -1
  113. package/dist/vue/components/MLink.d.ts +120 -0
  114. package/dist/vue/components/MLink.d.ts.map +1 -0
  115. package/dist/vue/components/MLink.js +81 -0
  116. package/dist/vue/components/MLink.js.map +1 -0
  117. package/dist/vue/components/MListItem.d.ts +26 -12
  118. package/dist/vue/components/MListItem.d.ts.map +1 -1
  119. package/dist/vue/components/MProgress.d.ts +18 -8
  120. package/dist/vue/components/MProgress.d.ts.map +1 -1
  121. package/dist/vue/components/MRadioGroup.d.ts +19 -9
  122. package/dist/vue/components/MRadioGroup.d.ts.map +1 -1
  123. package/dist/vue/components/MReveal.d.ts +71 -35
  124. package/dist/vue/components/MReveal.d.ts.map +1 -1
  125. package/dist/vue/components/MReveal.js +80 -35
  126. package/dist/vue/components/MReveal.js.map +1 -1
  127. package/dist/vue/components/MScreen.d.ts +12 -6
  128. package/dist/vue/components/MScreen.d.ts.map +1 -1
  129. package/dist/vue/components/MSegmentedControl.d.ts +19 -9
  130. package/dist/vue/components/MSegmentedControl.d.ts.map +1 -1
  131. package/dist/vue/components/MSelect.d.ts +21 -11
  132. package/dist/vue/components/MSelect.d.ts.map +1 -1
  133. package/dist/vue/components/MSeparator.d.ts +4 -2
  134. package/dist/vue/components/MSeparator.d.ts.map +1 -1
  135. package/dist/vue/components/MSheet.d.ts +18 -12
  136. package/dist/vue/components/MSheet.d.ts.map +1 -1
  137. package/dist/vue/components/MSkeleton.d.ts +16 -8
  138. package/dist/vue/components/MSkeleton.d.ts.map +1 -1
  139. package/dist/vue/components/MSlider.d.ts +9 -5
  140. package/dist/vue/components/MSlider.d.ts.map +1 -1
  141. package/dist/vue/components/MStack.d.ts +199 -0
  142. package/dist/vue/components/MStack.d.ts.map +1 -0
  143. package/dist/vue/components/MStack.js +62 -0
  144. package/dist/vue/components/MStack.js.map +1 -0
  145. package/dist/vue/components/MSwitch.d.ts +19 -9
  146. package/dist/vue/components/MSwitch.d.ts.map +1 -1
  147. package/dist/vue/components/MTabs.d.ts +19 -9
  148. package/dist/vue/components/MTabs.d.ts.map +1 -1
  149. package/dist/vue/components/MText.d.ts +42 -26
  150. package/dist/vue/components/MText.d.ts.map +1 -1
  151. package/dist/vue/components/MText.js +3 -3
  152. package/dist/vue/components/MText.js.map +1 -1
  153. package/dist/vue/components/layout.d.ts +191 -82
  154. package/dist/vue/components/layout.d.ts.map +1 -1
  155. package/dist/vue/components/layout.js +9 -7
  156. package/dist/vue/components/layout.js.map +1 -1
  157. package/dist/vue/components/workflows.d.ts +251 -0
  158. package/dist/vue/components/workflows.d.ts.map +1 -0
  159. package/dist/vue/components/workflows.js +35 -0
  160. package/dist/vue/components/workflows.js.map +1 -0
  161. package/dist/vue/index.d.ts +9 -2
  162. package/dist/vue/index.d.ts.map +1 -1
  163. package/dist/vue/index.js +19 -2
  164. package/dist/vue/index.js.map +1 -1
  165. package/dist/vue/navigation.d.ts +4 -0
  166. package/dist/vue/navigation.d.ts.map +1 -0
  167. package/dist/vue/navigation.js +16 -0
  168. package/dist/vue/navigation.js.map +1 -0
  169. package/dist/vue/reveal-motion.d.ts.map +1 -1
  170. package/dist/vue/reveal-motion.js +6 -3
  171. package/dist/vue/reveal-motion.js.map +1 -1
  172. package/dist/vue/use-motion-region.d.ts +7 -0
  173. package/dist/vue/use-motion-region.d.ts.map +1 -0
  174. package/dist/vue/use-motion-region.js +28 -0
  175. package/dist/vue/use-motion-region.js.map +1 -0
  176. package/dist/vue/use-motion-surface.d.ts.map +1 -1
  177. package/dist/vue/use-motion-surface.js +3 -2
  178. package/dist/vue/use-motion-surface.js.map +1 -1
  179. package/dist/vue/use-press.js +3 -3
  180. package/dist/vue/use-press.js.map +1 -1
  181. package/package.json +7 -3
  182. package/src/app-icons.ts +21 -0
  183. package/src/files.ts +3 -0
  184. package/src/native/app-icons.android.ts +95 -0
  185. package/src/native/app-icons.ios.ts +74 -0
  186. package/src/native/app-icons.ts +12 -0
  187. package/src/native/combobox-editor.android.ts +11 -0
  188. package/src/native/combobox-editor.ts +6 -0
  189. package/src/native/file-access.ts +71 -0
  190. package/src/native/file-picker.android.ts +191 -0
  191. package/src/native/file-picker.ios.ts +230 -0
  192. package/src/native/file-picker.ts +8 -0
  193. package/src/native/motion-owner.ts +65 -0
  194. package/src/native/motion-region.ts +275 -0
  195. package/src/native/motion-surface.ts +55 -2
  196. package/src/native/press.ts +3 -3
  197. package/src/native/scroll-motion.ts +5 -0
  198. package/src/vue/components/DateCalendar.ts +117 -0
  199. package/src/vue/components/MButton.ts +20 -10
  200. package/src/vue/components/MCard.ts +22 -5
  201. package/src/vue/components/MCombobox.ts +257 -0
  202. package/src/vue/components/MDatePicker.ts +33 -0
  203. package/src/vue/components/MFilePicker.ts +226 -0
  204. package/src/vue/components/MInput.ts +3 -3
  205. package/src/vue/components/MLink.ts +96 -0
  206. package/src/vue/components/MReveal.ts +89 -47
  207. package/src/vue/components/MStack.ts +83 -0
  208. package/src/vue/components/MText.ts +3 -3
  209. package/src/vue/components/layout.ts +15 -7
  210. package/src/vue/components/workflows.ts +38 -0
  211. package/src/vue/index.ts +35 -1
  212. package/src/vue/navigation.ts +15 -0
  213. package/src/vue/use-motion-region.ts +29 -0
  214. package/src/vue/use-motion-surface.ts +21 -14
  215. package/src/vue/use-press.ts +3 -3
  216. package/src/vue/reveal-motion.ts +0 -61
@@ -0,0 +1,230 @@
1
+ import { Application, ImageSource } from '@nativescript/core'
2
+ import type { FilePickerAdapter, SelectedFile } from '@getcortexlabs/mavis-core'
3
+ import { ownNativeFile } from './file-access.js'
4
+
5
+ interface URLValue {
6
+ path: string
7
+ lastPathComponent: string
8
+ pathExtension: string
9
+ }
10
+ interface ContentType {
11
+ identifier: string
12
+ preferredMIMEType?: string
13
+ }
14
+ interface Controller {
15
+ presentedViewController?: Controller
16
+ presentViewControllerAnimatedCompletion(
17
+ controller: Controller,
18
+ animated: boolean,
19
+ completion: (() => void) | null,
20
+ ): void
21
+ dismissViewControllerAnimatedCompletion(animated: boolean, completion: (() => void) | null): void
22
+ }
23
+ interface Picker extends Controller {
24
+ delegate: object | null
25
+ allowsMultipleSelection: boolean
26
+ presentationController?: { delegate: object | null }
27
+ }
28
+ interface ThumbnailRequest {}
29
+ interface ThumbnailGenerator {
30
+ generateBestRepresentationForRequestCompletionHandler(
31
+ request: ThumbnailRequest,
32
+ completion: (representation: { UIImage: unknown } | null, error: unknown) => void,
33
+ ): void
34
+ cancelRequest(request: ThumbnailRequest): void
35
+ }
36
+ declare const NSObject: { extend(members: object, options: object): { new (): object } }
37
+ declare const UIDocumentPickerDelegate: unknown
38
+ declare const UIAdaptivePresentationControllerDelegate: unknown
39
+ declare const UIDocumentPickerViewController: {
40
+ alloc(): { initForOpeningContentTypesAsCopy(types: ContentType[], asCopy: boolean): Picker }
41
+ }
42
+ declare const UTType: {
43
+ typeWithMIMEType(type: string): ContentType | null
44
+ typeWithFilenameExtension(extension: string): ContentType | null
45
+ typeWithIdentifier(identifier: string): ContentType
46
+ }
47
+ declare const NSFileManager: {
48
+ defaultManager: {
49
+ attributesOfItemAtPathError(path: string): { objectForKey(name: string): unknown }
50
+ removeItemAtURLError(url: URLValue): boolean
51
+ }
52
+ }
53
+ declare const NSInputStream: { inputStreamWithURL(url: URLValue): { open(): void; close(): void } }
54
+ declare const QLThumbnailGenerationRequest: {
55
+ alloc(): {
56
+ initWithFileAtURLSizeScaleRepresentationTypes(
57
+ url: URLValue,
58
+ size: { width: number; height: number },
59
+ scale: number,
60
+ types: number,
61
+ ): ThumbnailRequest
62
+ }
63
+ }
64
+ declare const QLThumbnailGenerator: { sharedGenerator: ThumbnailGenerator }
65
+
66
+ const families: Readonly<Record<string, string>> = {
67
+ 'image/*': 'public.image',
68
+ 'video/*': 'public.movie',
69
+ 'audio/*': 'public.audio',
70
+ 'text/*': 'public.text',
71
+ }
72
+ interface PickerCallbacks {
73
+ cancel(): void
74
+ selected(urls: { count: number; objectAtIndex(index: number): URLValue }): void
75
+ }
76
+ const delegates = new WeakMap<object, PickerCallbacks>()
77
+ let Delegate: { new (): object } | undefined
78
+ function delegateClass() {
79
+ Delegate ??= NSObject.extend(
80
+ {
81
+ documentPickerWasCancelled(this: object) {
82
+ delegates.get(this)?.cancel()
83
+ },
84
+ presentationControllerDidDismiss(this: object) {
85
+ delegates.get(this)?.cancel()
86
+ },
87
+ documentPickerDidPickDocumentsAtURLs(
88
+ this: object,
89
+ _controller: Picker,
90
+ urls: { count: number; objectAtIndex(index: number): URLValue },
91
+ ) {
92
+ delegates.get(this)?.selected(urls)
93
+ },
94
+ },
95
+ { protocols: [UIDocumentPickerDelegate, UIAdaptivePresentationControllerDelegate] },
96
+ )
97
+ return Delegate
98
+ }
99
+
100
+ export function createNativeFilePicker(): FilePickerAdapter {
101
+ return {
102
+ pick(request, cancellation) {
103
+ if (cancellation.cancelled) return Promise.resolve(null)
104
+ let presenter = Application.ios.rootController as Controller | undefined
105
+ while (presenter?.presentedViewController) presenter = presenter.presentedViewController
106
+ if (!presenter)
107
+ return Promise.reject(new Error('File selection requires a mounted iOS view controller'))
108
+ return new Promise((resolve, reject) => {
109
+ let done = false
110
+ let unsubscribe = () => {}
111
+ let picker: Picker | undefined
112
+ // UIKit delegates are weak. Keep this reference until the picker has finished.
113
+ let delegate: object | undefined
114
+ const finish = (files: readonly SelectedFile[] | null, error?: unknown) => {
115
+ if (done) {
116
+ for (const file of files ?? []) file.release()
117
+ return
118
+ }
119
+ done = true
120
+ unsubscribe()
121
+ if (picker) {
122
+ picker.delegate = null
123
+ if (picker.presentationController) picker.presentationController.delegate = null
124
+ }
125
+ if (delegate) delegates.delete(delegate)
126
+ delegate = undefined
127
+ if (error) reject(error)
128
+ else resolve(files)
129
+ }
130
+ try {
131
+ const types = request.accept.map((hint) => {
132
+ if (hint.startsWith('.')) return UTType.typeWithFilenameExtension(hint.slice(1))
133
+ if (hint.endsWith('/*'))
134
+ return families[hint] ? UTType.typeWithIdentifier(families[hint]) : null
135
+ return UTType.typeWithMIMEType(hint)
136
+ })
137
+ const effective =
138
+ !types.length || types.some((type) => !type)
139
+ ? [UTType.typeWithIdentifier('public.data')]
140
+ : (types as ContentType[])
141
+ // Import a private temporary copy: no security-scoped bookmark or broad permission.
142
+ picker = UIDocumentPickerViewController.alloc().initForOpeningContentTypesAsCopy(
143
+ effective,
144
+ true,
145
+ )
146
+ picker.allowsMultipleSelection = request.multiple
147
+ const PickerDelegate = delegateClass()
148
+ delegate = new PickerDelegate()
149
+ delegates.set(delegate, {
150
+ cancel() {
151
+ finish(null)
152
+ },
153
+ selected(urls) {
154
+ const files: SelectedFile[] = []
155
+ try {
156
+ for (let index = 0; index < urls.count; index++) {
157
+ const url = urls.objectAtIndex(index)
158
+ const attributes = NSFileManager.defaultManager.attributesOfItemAtPathError(
159
+ url.path,
160
+ )
161
+ const size = attributes?.objectForKey('NSFileSize')
162
+ let thumbnail: ThumbnailRequest | undefined
163
+ let released = false
164
+ const owner = ownNativeFile(
165
+ 'ios',
166
+ url,
167
+ () => {
168
+ const stream = NSInputStream.inputStreamWithURL(url)
169
+ stream.open()
170
+ return { native: stream, close: () => stream.close() }
171
+ },
172
+ () => {
173
+ released = true
174
+ if (thumbnail) QLThumbnailGenerator.sharedGenerator.cancelRequest(thumbnail)
175
+ // asCopy=true guarantees that this is the imported sandbox copy.
176
+ NSFileManager.defaultManager.removeItemAtURLError(url)
177
+ },
178
+ )
179
+ files.push({
180
+ name: url.lastPathComponent,
181
+ size: size == null ? undefined : Number(size),
182
+ type:
183
+ UTType.typeWithFilenameExtension(url.pathExtension)?.preferredMIMEType ||
184
+ undefined,
185
+ ...owner,
186
+ preview() {
187
+ if (released) return Promise.resolve(undefined)
188
+ return new Promise((previewResolve, previewReject) => {
189
+ thumbnail =
190
+ QLThumbnailGenerationRequest.alloc().initWithFileAtURLSizeScaleRepresentationTypes(
191
+ url,
192
+ { width: 160, height: 160 },
193
+ 1,
194
+ 4,
195
+ )
196
+ QLThumbnailGenerator.sharedGenerator.generateBestRepresentationForRequestCompletionHandler(
197
+ thumbnail,
198
+ (representation, error) => {
199
+ thumbnail = undefined
200
+ if (released) previewResolve(undefined)
201
+ else if (representation)
202
+ previewResolve(new ImageSource(representation.UIImage))
203
+ else previewReject(error ?? new Error('Preview unavailable'))
204
+ },
205
+ )
206
+ })
207
+ },
208
+ })
209
+ }
210
+ finish(files)
211
+ } catch (error) {
212
+ for (const file of files) file.release()
213
+ finish(null, error)
214
+ }
215
+ },
216
+ })
217
+ picker.delegate = delegate
218
+ if (picker.presentationController) picker.presentationController.delegate = delegate
219
+ unsubscribe = cancellation.onCancel(() => {
220
+ picker?.dismissViewControllerAnimatedCompletion(true, null)
221
+ finish(null)
222
+ })
223
+ presenter!.presentViewControllerAnimatedCompletion(picker, true, null)
224
+ } catch (error) {
225
+ finish(null, error)
226
+ }
227
+ })
228
+ },
229
+ }
230
+ }
@@ -0,0 +1,8 @@
1
+ import type { FilePickerAdapter } from '@getcortexlabs/mavis-core'
2
+
3
+ /** NativeScript resolves this module to the .ios/.android implementation at bundle time. */
4
+ export function createNativeFilePicker(): FilePickerAdapter {
5
+ return {
6
+ pick: () => Promise.reject(new Error('File picking requires the iOS or Android runtime')),
7
+ }
8
+ }
@@ -0,0 +1,65 @@
1
+ import { motionScope } from '@rafaelaugusto/jolt'
2
+ import type { MotionSurfaceAdapter } from '@getcortexlabs/mavis-core/experimental'
3
+ import type { View } from '@nativescript/core'
4
+ import { registerNativeSurface } from './motion-region.js'
5
+
6
+ /** Native scopes also recreate subscriptions after application suspension. */
7
+ export function nativeMotionOwner(
8
+ adapter: MotionSurfaceAdapter,
9
+ target: View,
10
+ ): MotionSurfaceAdapter {
11
+ const result: MotionSurfaceAdapter = {
12
+ ...adapter,
13
+ use(setup) {
14
+ const parent = motionScope()
15
+ try {
16
+ parent.use(() => {
17
+ const child = motionScope()
18
+ const owned: MotionSurfaceAdapter = {
19
+ ...result,
20
+ animate: (...args) => child.add(result.animate(...args)),
21
+ animateValue:
22
+ result.animateValue && ((...args) => child.add(result.animateValue!(...args))),
23
+ playbackProgress:
24
+ result.playbackProgress &&
25
+ ((...args) => child.add(result.playbackProgress!(...args))),
26
+ decay: result.decay && ((...args) => child.add(result.decay!(...args))),
27
+ set: (...args) => child.add(result.set(...args)),
28
+ motionValue:
29
+ result.motionValue && ((...args) => child.add(result.motionValue!(...args))),
30
+ springValue:
31
+ result.springValue && ((...args) => child.add(result.springValue!(...args))),
32
+ map: result.map && ((...args) => child.add(result.map!(...args))),
33
+ bind: result.bind && ((...args) => child.add(result.bind!(...args))),
34
+ drag: result.drag && ((...args) => child.add(result.drag!(...args))),
35
+ pointerFollow:
36
+ result.pointerFollow && ((...args) => child.add(result.pointerFollow!(...args))),
37
+ scrollLinked:
38
+ result.scrollLinked && ((...args) => child.add(result.scrollLinked!(...args))),
39
+ }
40
+ registerNativeSurface(owned, target)
41
+ let cleanup: () => void
42
+ try {
43
+ cleanup = setup(owned)
44
+ } catch (error) {
45
+ child.dispose()
46
+ throw error
47
+ }
48
+ return () => {
49
+ try {
50
+ cleanup()
51
+ } finally {
52
+ child.dispose()
53
+ }
54
+ }
55
+ })
56
+ } catch (error) {
57
+ parent.dispose()
58
+ throw error
59
+ }
60
+ return () => parent.dispose()
61
+ },
62
+ }
63
+ registerNativeSurface(result, target)
64
+ return result
65
+ }
@@ -0,0 +1,275 @@
1
+ import { Application, ScrollView, type View } from '@nativescript/core'
2
+ import { animate, motionScope, reducedMotion, onReducedMotion } from '@rafaelaugusto/jolt'
3
+ import { sharedLayout } from '@rafaelaugusto/jolt/shared-layout'
4
+ import {
5
+ bindMotionRegion,
6
+ type MotionRegion,
7
+ type MotionRegionAdapter,
8
+ type MotionSurfaceAdapter,
9
+ } from '@getcortexlabs/mavis-core/experimental'
10
+ import { nativeScrollElement } from './scroll-motion.js'
11
+
12
+ const targets = new WeakMap<MotionSurfaceAdapter, View>()
13
+ const regions = new WeakMap<MotionRegionAdapter, View>()
14
+ export function assertNativeRegion(adapter: MotionRegionAdapter, target: View) {
15
+ const region = regions.get(adapter)
16
+ if (!region || region === target || !inside(target, region))
17
+ throw new TypeError('Use a separate enclosing native motion region.')
18
+ }
19
+ export function registerNativeSurface(adapter: MotionSurfaceAdapter, target: View) {
20
+ targets.set(adapter, target)
21
+ }
22
+ function resolve(adapter: MotionSurfaceAdapter) {
23
+ const target = targets.get(adapter)
24
+ if (!target?.isLoaded) throw new Error('Use a loaded native motion surface.')
25
+ return target
26
+ }
27
+ function inside(view: View, container: View) {
28
+ for (let current: View | undefined = view; current; current = current.parent as View | undefined)
29
+ if (current === container) return true
30
+ return false
31
+ }
32
+
33
+ /** Native observation is event-driven geometry; Jolt remains the only playback clock. */
34
+ function viewportEnter(
35
+ container: View,
36
+ surfaces: readonly MotionSurfaceAdapter[],
37
+ options: Parameters<MotionRegionAdapter['viewportEnter']>[1],
38
+ ) {
39
+ const targets = surfaces.map(resolve)
40
+ let root: View = options.root ? nativeScrollElement(options.root) : container
41
+ if (!options.root) {
42
+ for (
43
+ let parent = container.parent as View | undefined;
44
+ parent;
45
+ parent = parent.parent as View | undefined
46
+ )
47
+ if (parent instanceof ScrollView) {
48
+ root = parent
49
+ break
50
+ }
51
+ }
52
+ const states = targets.map((target, index) => ({
53
+ target,
54
+ index,
55
+ visible: false,
56
+ completed: false,
57
+ animation: undefined as ReturnType<typeof animate> | undefined,
58
+ }))
59
+ let disposed = false,
60
+ disabled = options.disabled ?? false,
61
+ observing = false
62
+ const stop = (state: (typeof states)[number]) => {
63
+ const handle = state.animation
64
+ state.animation = undefined
65
+ if (handle) {
66
+ handle.progress = 1
67
+ handle.stop()
68
+ }
69
+ }
70
+ const detach = () => {
71
+ if (!observing) return
72
+ observing = false
73
+ root.off('scroll', refresh)
74
+ root.off('layoutChanged', refresh)
75
+ for (const state of states) state.target.off('layoutChanged', refresh)
76
+ }
77
+ const refresh = () => {
78
+ if (disposed || disabled || Application.suspended || reducedMotion()) {
79
+ for (const state of states) {
80
+ stop(state)
81
+ state.visible = false
82
+ }
83
+ return
84
+ }
85
+ const size = root.getActualSize(),
86
+ margin = options.margin ?? 0
87
+ for (const state of states) {
88
+ if (!state.target.isLoaded || (options.once !== false && state.completed)) continue
89
+ const point = state.target.getLocationRelativeTo(root),
90
+ bounds = state.target.getActualSize()
91
+ const area = bounds.width * bounds.height
92
+ const overlap = point
93
+ ? Math.max(
94
+ 0,
95
+ Math.min(point.x + bounds.width, size.width + margin) - Math.max(point.x, -margin),
96
+ ) *
97
+ Math.max(
98
+ 0,
99
+ Math.min(point.y + bounds.height, size.height + margin) - Math.max(point.y, -margin),
100
+ )
101
+ : 0
102
+ const visible = area > 0 && overlap > 0 && overlap / area >= (options.threshold ?? 0)
103
+ if (!visible) stop(state)
104
+ if (visible && !state.visible && !state.animation) {
105
+ const animation = animate(state.target, options.frames ?? { opacity: [0, 1], y: [20, 0] }, {
106
+ duration: 450,
107
+ ...options.transition,
108
+ delay: (options.transition?.delay ?? 0) + state.index * (options.stagger ?? 70),
109
+ })
110
+ state.animation = animation
111
+ void animation.finished.then((completed) => {
112
+ if (disposed || state.animation !== animation) return
113
+ state.animation = undefined
114
+ if (completed) state.completed = true
115
+ if (
116
+ options.once !== false &&
117
+ states.every((entry) => entry.completed || !entry.target.isLoaded)
118
+ )
119
+ detach()
120
+ })
121
+ }
122
+ state.visible = visible
123
+ }
124
+ }
125
+ const attach = () => {
126
+ if (
127
+ observing ||
128
+ disposed ||
129
+ disabled ||
130
+ (options.once !== false && states.every((state) => state.completed))
131
+ )
132
+ return
133
+ observing = true
134
+ root.on('scroll', refresh)
135
+ root.on('layoutChanged', refresh)
136
+ for (const state of states) state.target.on('layoutChanged', refresh)
137
+ }
138
+ const preference = onReducedMotion(() => {
139
+ attach()
140
+ refresh()
141
+ })
142
+ Application.on(Application.suspendEvent, refresh)
143
+ Application.on(Application.resumeEvent, refresh)
144
+ attach()
145
+ refresh()
146
+ return {
147
+ execution: 'native-layout' as const,
148
+ get pending() {
149
+ return states.filter((state) => state.animation).length
150
+ },
151
+ get completed() {
152
+ return states.filter((state) => state.completed).length
153
+ },
154
+ update(state: { disabled: boolean }) {
155
+ disabled = state.disabled
156
+ if (disabled) detach()
157
+ else attach()
158
+ refresh()
159
+ },
160
+ refresh,
161
+ dispose() {
162
+ if (disposed) return
163
+ disposed = true
164
+ detach()
165
+ preference()
166
+ Application.off(Application.suspendEvent, refresh)
167
+ Application.off(Application.resumeEvent, refresh)
168
+ for (const state of states) stop(state)
169
+ },
170
+ }
171
+ }
172
+
173
+ export function attachNativeMotionRegion(reference: MotionRegion, target: View) {
174
+ const resolveChild = (adapter: MotionSurfaceAdapter) => {
175
+ const child = resolve(adapter)
176
+ if (!inside(child, target) || child === target)
177
+ throw new Error('Declare each surface inside this motion region.')
178
+ return child
179
+ }
180
+ const scope = motionScope()
181
+ const steps = (
182
+ items: readonly (
183
+ | import('@getcortexlabs/mavis-core/experimental').MotionStep<MotionSurfaceAdapter>
184
+ | import('@getcortexlabs/mavis-core/experimental').MotionTimelineStep<MotionSurfaceAdapter>
185
+ )[],
186
+ ) =>
187
+ items.map((step) =>
188
+ typeof step === 'function' || 'run' in step
189
+ ? step
190
+ : ([resolveChild(step[0]), step[1], step[2]] as const),
191
+ )
192
+ const adapter: MotionRegionAdapter = {
193
+ sequence: (items) =>
194
+ scope.sequence(steps(items) as unknown as Parameters<typeof scope.sequence>[0]),
195
+ timeline: (items) =>
196
+ scope.timeline(steps(items) as unknown as Parameters<typeof scope.timeline>[0]),
197
+ states(targets, definitions, options) {
198
+ const timing = (
199
+ input: import('@getcortexlabs/mavis-core/experimental').MotionStateTransition | undefined,
200
+ ) => {
201
+ const { targets, ...transition } = input ?? {}
202
+ return { ...transition, ...targets }
203
+ }
204
+ const control = scope.states(
205
+ Object.fromEntries(
206
+ Object.entries(targets).map(([name, surface]) => [
207
+ name,
208
+ surface && resolveChild(surface),
209
+ ]),
210
+ ),
211
+ Object.fromEntries(
212
+ Object.entries(definitions).map(([name, frames]) => [
213
+ name,
214
+ Object.fromEntries(
215
+ Object.entries(frames).filter(
216
+ (row): row is [string, NonNullable<(typeof row)[1]>] => row[1] !== undefined,
217
+ ),
218
+ ),
219
+ ]),
220
+ ),
221
+ { transition: timing(options?.transition) },
222
+ )
223
+ return {
224
+ get current() {
225
+ return control.current
226
+ },
227
+ get settled() {
228
+ return control.settled
229
+ },
230
+ get paused() {
231
+ return control.paused
232
+ },
233
+ to: (name, transition) => control.to(name, timing(transition)),
234
+ attach: (name, surface) => control.attach(name, surface && resolveChild(surface)),
235
+ pause: () => control.pause(),
236
+ play: () => control.play(),
237
+ stop: () => control.stop(),
238
+ dispose: () => control.dispose(),
239
+ }
240
+ },
241
+ kind: 'native',
242
+ viewportEnter(surfaces, options) {
243
+ surfaces.forEach(resolveChild)
244
+ return viewportEnter(target, surfaces, options)
245
+ },
246
+ sharedLayout(options) {
247
+ const control = sharedLayout(target, options)
248
+ return {
249
+ get active() {
250
+ return control.active
251
+ },
252
+ attach: (surface, identity) => control.attach(resolveChild(surface), identity),
253
+ transition: (change, options) => control.transition(change, options),
254
+ cancel: () => control.cancel(),
255
+ dispose: () => control.dispose(),
256
+ }
257
+ },
258
+ }
259
+ regions.set(adapter, target)
260
+ try {
261
+ const release = bindMotionRegion(reference, adapter)
262
+ return () => {
263
+ try {
264
+ release()
265
+ } finally {
266
+ regions.delete(adapter)
267
+ scope.dispose()
268
+ }
269
+ }
270
+ } catch (error) {
271
+ regions.delete(adapter)
272
+ scope.dispose()
273
+ throw error
274
+ }
275
+ }
@@ -1,6 +1,10 @@
1
1
  import { nativeScrollMotion } from './scroll-motion.js'
2
+ import { assertNativeRegion } from './motion-region.js'
2
3
  import type { View, EventData, TouchGestureEventData } from '@nativescript/core'
3
4
  import {
5
+ animate,
6
+ decay,
7
+ playbackProgress,
4
8
  bind,
5
9
  motionValue,
6
10
  springValue,
@@ -24,8 +28,36 @@ export function nativeContinuousSurface(target: View, enabled: () => boolean) {
24
28
  let suppressUntil = 0
25
29
  const adapter: Pick<
26
30
  MotionSurfaceAdapter,
27
- 'motionValue' | 'springValue' | 'bind' | 'drag' | 'map' | 'refresh' | 'scrollLinked'
31
+ | 'animateValue'
32
+ | 'stopValue'
33
+ | 'playbackProgress'
34
+ | 'decay'
35
+ | 'motionValue'
36
+ | 'springValue'
37
+ | 'bind'
38
+ | 'drag'
39
+ | 'map'
40
+ | 'refresh'
41
+ | 'scrollLinked'
42
+ | 'pointerFollow'
28
43
  > = {
44
+ pointerFollow(region, options) {
45
+ assertNativeRegion(region, target)
46
+ const x = adapter.motionValue!(options.rest?.x ?? 0)
47
+ const y = adapter.motionValue!(options.rest?.y ?? 0)
48
+ return {
49
+ x,
50
+ y,
51
+ execution: 'static',
52
+ active: false,
53
+ update() {},
54
+ refresh() {},
55
+ dispose() {
56
+ x.dispose()
57
+ y.dispose()
58
+ },
59
+ }
60
+ },
29
61
  scrollLinked(source, frames, options) {
30
62
  interrupt(Object.keys(frames))
31
63
  const scroll = nativeScrollMotion(source, target, frames, options)
@@ -49,6 +81,26 @@ export function nativeContinuousSurface(target: View, enabled: () => boolean) {
49
81
  sources.set(value, mapped)
50
82
  return value
51
83
  },
84
+ animateValue(value, frames, options) {
85
+ const source = sources.get(value)
86
+ if (!source) throw new TypeError('Use a mutable native motion value.')
87
+ return animate(source as ReturnType<typeof motionValue>, frames, options)
88
+ },
89
+ stopValue(value, options) {
90
+ const source = sources.get(value)
91
+ if (!source) throw new TypeError('Use a native motion value.')
92
+ stop(source as ReturnType<typeof motionValue>, options)
93
+ },
94
+ playbackProgress(handle) {
95
+ const progress = playbackProgress(handle as Parameters<typeof playbackProgress>[0])
96
+ const value = { get: () => progress.get(), dispose() {} }
97
+ sources.set(value, progress)
98
+ return value
99
+ },
100
+ decay(velocity, options) {
101
+ interrupt(Object.keys(velocity))
102
+ return decay(target, velocity, options)
103
+ },
52
104
  motionValue(initial) {
53
105
  const source = motionValue(initial)
54
106
  const value: MotionValueAdapter = {
@@ -94,8 +146,9 @@ export function nativeContinuousSurface(target: View, enabled: () => boolean) {
94
146
  onMove: () => {
95
147
  suppressUntil = Date.now() + 500
96
148
  },
97
- onRelease: () => {
149
+ onRelease: (event) => {
98
150
  suppressUntil = Date.now() + 500
151
+ options.onRelease?.(event)
99
152
  },
100
153
  })
101
154
  const refresh = () => (paused || !enabled() ? gesture.pause() : gesture.play())
@@ -1,11 +1,11 @@
1
1
  import type { EventData, TouchGestureEventData, View } from '@nativescript/core'
2
2
  import { animate, stop, onReducedMotion } from '@rafaelaugusto/jolt'
3
- import { pressMotion } from '@getcortexlabs/mavis-core'
3
+ import { pressMotion, type MotionTheme } from '@getcortexlabs/mavis-core'
4
4
 
5
5
  let nextLayer = 0
6
6
 
7
7
  /** Press multiplies the app's scale; releasing it removes only that contribution. */
8
- export function attachPressFeedback(view: View, scale: number) {
8
+ export function attachPressFeedback(view: View, scale: number | Readonly<MotionTheme>) {
9
9
  let motion = pressMotion(scale)
10
10
  // Each attachment owns its channel, including after a theme change or reload.
11
11
  const layer = `mavis-press-${++nextLayer}`
@@ -47,7 +47,7 @@ export function attachPressFeedback(view: View, scale: number) {
47
47
  press(pressed: boolean) {
48
48
  onTouch({ action: pressed ? 'down' : 'cancel' } as TouchGestureEventData)
49
49
  },
50
- update(scale: number) {
50
+ update(scale: number | Readonly<MotionTheme>) {
51
51
  motion = pressMotion(scale)
52
52
  if (pressed && !disposed) animate(view, motion.pressed[0], { ...motion.pressed[1], layer })
53
53
  },