@getcortexlabs/mavis 0.1.0-alpha.6 → 0.1.0-alpha.8
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.
- package/README.md +5 -5
- package/dist/native/collection-motion.d.ts +5 -0
- package/dist/native/collection-motion.d.ts.map +1 -0
- package/dist/native/collection-motion.js +157 -0
- package/dist/native/collection-motion.js.map +1 -0
- package/dist/native/image-effects.d.ts +11 -0
- package/dist/native/image-effects.d.ts.map +1 -0
- package/dist/native/image-effects.js +61 -0
- package/dist/native/image-effects.js.map +1 -0
- package/dist/native/motion-owner.d.ts.map +1 -1
- package/dist/native/motion-owner.js +1 -0
- package/dist/native/motion-owner.js.map +1 -1
- package/dist/native/motion-region.d.ts.map +1 -1
- package/dist/native/motion-region.js +7 -2
- package/dist/native/motion-region.js.map +1 -1
- package/dist/native/motion-surface.d.ts +2 -2
- package/dist/native/motion-surface.d.ts.map +1 -1
- package/dist/native/motion-surface.js +55 -2
- package/dist/native/motion-surface.js.map +1 -1
- package/dist/native/platform-motion.d.ts +5 -0
- package/dist/native/platform-motion.d.ts.map +1 -0
- package/dist/native/platform-motion.js +90 -0
- package/dist/native/platform-motion.js.map +1 -0
- package/dist/native/press.d.ts +2 -0
- package/dist/native/press.d.ts.map +1 -1
- package/dist/native/press.js +6 -0
- package/dist/native/press.js.map +1 -1
- package/dist/native/surface-effects.d.ts +4 -0
- package/dist/native/surface-effects.d.ts.map +1 -0
- package/dist/native/surface-effects.js +31 -0
- package/dist/native/surface-effects.js.map +1 -0
- package/dist/native/visual-effects.d.ts +5 -0
- package/dist/native/visual-effects.d.ts.map +1 -0
- package/dist/native/visual-effects.js +126 -0
- package/dist/native/visual-effects.js.map +1 -0
- package/dist/vue/components/ChoiceControl.d.ts.map +1 -1
- package/dist/vue/components/ChoiceControl.js +20 -5
- package/dist/vue/components/ChoiceControl.js.map +1 -1
- package/dist/vue/components/DateCalendar.d.ts +3 -3
- package/dist/vue/components/LoadingDecoration.d.ts +116 -0
- package/dist/vue/components/LoadingDecoration.d.ts.map +1 -0
- package/dist/vue/components/LoadingDecoration.js +34 -0
- package/dist/vue/components/LoadingDecoration.js.map +1 -0
- package/dist/vue/components/MAlert.d.ts +1 -1
- package/dist/vue/components/MAvatar.d.ts +1 -1
- package/dist/vue/components/MBadge.d.ts +1 -1
- package/dist/vue/components/MButton.d.ts +36 -14
- package/dist/vue/components/MButton.d.ts.map +1 -1
- package/dist/vue/components/MButton.js +29 -2
- package/dist/vue/components/MButton.js.map +1 -1
- package/dist/vue/components/MCard.d.ts +6 -6
- package/dist/vue/components/MChip.d.ts +3 -3
- package/dist/vue/components/MCombobox.d.ts +2 -2
- package/dist/vue/components/MDatePicker.d.ts +16 -16
- package/dist/vue/components/MDialog.d.ts +4 -1
- package/dist/vue/components/MDialog.d.ts.map +1 -1
- package/dist/vue/components/MEmptyState.d.ts +2 -2
- package/dist/vue/components/MFilePicker.d.ts +2 -2
- package/dist/vue/components/MIcon.d.ts +19 -1
- package/dist/vue/components/MIcon.d.ts.map +1 -1
- package/dist/vue/components/MIcon.js +13 -2
- package/dist/vue/components/MIcon.js.map +1 -1
- package/dist/vue/components/MImage.d.ts +203 -0
- package/dist/vue/components/MImage.d.ts.map +1 -0
- package/dist/vue/components/MImage.js +157 -0
- package/dist/vue/components/MImage.js.map +1 -0
- package/dist/vue/components/MInput.d.ts +4 -4
- package/dist/vue/components/MInput.d.ts.map +1 -1
- package/dist/vue/components/MInput.js +9 -5
- package/dist/vue/components/MInput.js.map +1 -1
- package/dist/vue/components/MLink.d.ts +3 -3
- package/dist/vue/components/MListItem.d.ts +1 -1
- package/dist/vue/components/MProgress.d.ts +2 -2
- package/dist/vue/components/MReveal.d.ts +11 -11
- package/dist/vue/components/MScreen.d.ts +11 -1
- package/dist/vue/components/MScreen.d.ts.map +1 -1
- package/dist/vue/components/MScreen.js +26 -4
- package/dist/vue/components/MScreen.js.map +1 -1
- package/dist/vue/components/MSelect.d.ts +1 -1
- package/dist/vue/components/MSheet.d.ts +4 -4
- package/dist/vue/components/MSkeleton.d.ts +11 -0
- package/dist/vue/components/MSkeleton.d.ts.map +1 -1
- package/dist/vue/components/MSkeleton.js +5 -3
- package/dist/vue/components/MSkeleton.js.map +1 -1
- package/dist/vue/components/MStack.d.ts +11 -11
- package/dist/vue/components/MSwitch.d.ts.map +1 -1
- package/dist/vue/components/MSwitch.js +13 -3
- package/dist/vue/components/MSwitch.js.map +1 -1
- package/dist/vue/components/MText.d.ts +15 -4
- package/dist/vue/components/MText.d.ts.map +1 -1
- package/dist/vue/components/MText.js +3 -1
- package/dist/vue/components/MText.js.map +1 -1
- package/dist/vue/components/configurator.d.ts +541 -0
- package/dist/vue/components/configurator.d.ts.map +1 -0
- package/dist/vue/components/configurator.js +24 -0
- package/dist/vue/components/configurator.js.map +1 -0
- package/dist/vue/components/layout.d.ts +35 -24
- package/dist/vue/components/layout.d.ts.map +1 -1
- package/dist/vue/components/layout.js +3 -1
- package/dist/vue/components/layout.js.map +1 -1
- package/dist/vue/components/workflows.d.ts +1 -1
- package/dist/vue/index.d.ts +3 -1
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +6 -1
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/use-choice-paint.d.ts +9 -0
- package/dist/vue/use-choice-paint.d.ts.map +1 -0
- package/dist/vue/use-choice-paint.js +32 -0
- package/dist/vue/use-choice-paint.js.map +1 -0
- package/dist/vue/use-motion-surface.d.ts +1 -1
- package/dist/vue/use-motion-surface.d.ts.map +1 -1
- package/dist/vue/use-motion-surface.js +31 -2
- package/dist/vue/use-motion-surface.js.map +1 -1
- package/package.json +3 -3
- package/src/native/collection-motion.ts +166 -0
- package/src/native/image-effects.ts +71 -0
- package/src/native/motion-owner.ts +1 -0
- package/src/native/motion-region.ts +7 -2
- package/src/native/motion-surface.ts +63 -3
- package/src/native/platform-motion.ts +103 -0
- package/src/native/press.ts +6 -0
- package/src/native/surface-effects.ts +33 -0
- package/src/native/visual-effects.ts +147 -0
- package/src/vue/components/ChoiceControl.ts +25 -5
- package/src/vue/components/LoadingDecoration.ts +38 -0
- package/src/vue/components/MButton.ts +33 -2
- package/src/vue/components/MIcon.ts +14 -2
- package/src/vue/components/MImage.ts +181 -0
- package/src/vue/components/MInput.ts +9 -5
- package/src/vue/components/MScreen.ts +31 -3
- package/src/vue/components/MSkeleton.ts +5 -3
- package/src/vue/components/MSwitch.ts +16 -3
- package/src/vue/components/MText.ts +7 -0
- package/src/vue/components/configurator.ts +27 -0
- package/src/vue/components/layout.ts +3 -0
- package/src/vue/index.ts +8 -0
- package/src/vue/use-choice-paint.ts +39 -0
- package/src/vue/use-motion-surface.ts +32 -1
- package/dist/vue/reveal-motion.d.ts +0 -13
- package/dist/vue/reveal-motion.d.ts.map +0 -1
- package/dist/vue/reveal-motion.js +0 -58
- package/dist/vue/reveal-motion.js.map +0 -1
|
@@ -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
|
+
}
|
|
@@ -29,6 +29,7 @@ export function nativeMotionOwner(
|
|
|
29
29
|
result.motionValue && ((...args) => child.add(result.motionValue!(...args))),
|
|
30
30
|
springValue:
|
|
31
31
|
result.springValue && ((...args) => child.add(result.springValue!(...args))),
|
|
32
|
+
mapColor: result.mapColor && ((...args) => child.add(result.mapColor!(...args))),
|
|
32
33
|
map: result.map && ((...args) => child.add(result.map!(...args))),
|
|
33
34
|
bind: result.bind && ((...args) => child.add(result.bind!(...args))),
|
|
34
35
|
drag: result.drag && ((...args) => child.add(result.drag!(...args))),
|
|
@@ -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
|
-
|
|
107
|
-
|
|
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,8 +20,13 @@ import type {
|
|
|
18
20
|
MotionValueAdapter,
|
|
19
21
|
} from '@getcortexlabs/mavis-core/experimental'
|
|
20
22
|
|
|
21
|
-
export function nativeContinuousSurface(
|
|
23
|
+
export function nativeContinuousSurface(
|
|
24
|
+
target: View,
|
|
25
|
+
enabled: () => boolean,
|
|
26
|
+
plainText: () => boolean = () => false,
|
|
27
|
+
) {
|
|
22
28
|
const sources = new WeakMap<object, DerivedValue>()
|
|
29
|
+
const colorSources = new WeakMap<object, import('@rafaelaugusto/jolt').DerivedColor>()
|
|
23
30
|
const refreshes = new Set<() => void>()
|
|
24
31
|
const scrolls = new Set<ReturnType<typeof nativeScrollMotion>>()
|
|
25
32
|
const interrupt = (properties: readonly string[]) => {
|
|
@@ -37,10 +44,54 @@ export function nativeContinuousSurface(target: View, enabled: () => boolean) {
|
|
|
37
44
|
| 'bind'
|
|
38
45
|
| 'drag'
|
|
39
46
|
| 'map'
|
|
47
|
+
| 'mapColor'
|
|
40
48
|
| 'refresh'
|
|
41
49
|
| 'scrollLinked'
|
|
42
50
|
| 'pointerFollow'
|
|
43
|
-
|
|
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
|
+
},
|
|
44
95
|
pointerFollow(region, options) {
|
|
45
96
|
assertNativeRegion(region, target)
|
|
46
97
|
const x = adapter.motionValue!(options.rest?.x ?? 0)
|
|
@@ -81,6 +132,12 @@ export function nativeContinuousSurface(target: View, enabled: () => boolean) {
|
|
|
81
132
|
sources.set(value, mapped)
|
|
82
133
|
return value
|
|
83
134
|
},
|
|
135
|
+
mapColor(source, input, output) {
|
|
136
|
+
const mapped = sources.get(source)!.to(input, output)
|
|
137
|
+
const value = { get: () => mapped.get().hex, dispose() {} }
|
|
138
|
+
colorSources.set(value, mapped)
|
|
139
|
+
return value
|
|
140
|
+
},
|
|
84
141
|
animateValue(value, frames, options) {
|
|
85
142
|
const source = sources.get(value)
|
|
86
143
|
if (!source) throw new TypeError('Use a mutable native motion value.')
|
|
@@ -134,7 +191,10 @@ export function nativeContinuousSurface(target: View, enabled: () => boolean) {
|
|
|
134
191
|
const dispose = bind(
|
|
135
192
|
target,
|
|
136
193
|
Object.fromEntries(
|
|
137
|
-
Object.entries(values).map(([key, value]) => [
|
|
194
|
+
Object.entries(values).map(([key, value]) => [
|
|
195
|
+
key,
|
|
196
|
+
colorSources.get(value) ?? sources.get(value)!,
|
|
197
|
+
]),
|
|
138
198
|
),
|
|
139
199
|
)
|
|
140
200
|
return { dispose }
|
|
@@ -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
|
+
}
|
package/src/native/press.ts
CHANGED
|
@@ -2,6 +2,11 @@ import type { EventData, TouchGestureEventData, View } from '@nativescript/core'
|
|
|
2
2
|
import { animate, stop, onReducedMotion } from '@rafaelaugusto/jolt'
|
|
3
3
|
import { pressMotion, type MotionTheme } from '@getcortexlabs/mavis-core'
|
|
4
4
|
|
|
5
|
+
const pressCallbacks = new WeakSet<Function>()
|
|
6
|
+
/** Internal diagnostics distinguish animation input from a control's own touch behavior. */
|
|
7
|
+
export function isPressFeedbackCallback(callback: unknown) {
|
|
8
|
+
return typeof callback === 'function' && pressCallbacks.has(callback)
|
|
9
|
+
}
|
|
5
10
|
let nextLayer = 0
|
|
6
11
|
|
|
7
12
|
/** Press multiplies the app's scale; releasing it removes only that contribution. */
|
|
@@ -41,6 +46,7 @@ export function attachPressFeedback(view: View, scale: number | Readonly<MotionT
|
|
|
41
46
|
animate(view, motion[pressed ? 'pressed' : 'released'][0], { duration: 0, layer })
|
|
42
47
|
}
|
|
43
48
|
})
|
|
49
|
+
pressCallbacks.add(onTouch)
|
|
44
50
|
view.on('touch', onTouch)
|
|
45
51
|
view.on('unloaded', remove)
|
|
46
52
|
return Object.assign(remove, {
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Label, Image, isIOS, type View } from '@nativescript/core'
|
|
2
|
+
import { nativeSurfaceEffects } from './surface-effects.js'
|
|
3
|
+
import {
|
|
4
|
+
gradient,
|
|
5
|
+
shimmer,
|
|
6
|
+
loader,
|
|
7
|
+
reveal,
|
|
8
|
+
conceal,
|
|
9
|
+
animateText,
|
|
10
|
+
rollTo,
|
|
11
|
+
type DerivedValue,
|
|
12
|
+
type DerivedColor,
|
|
13
|
+
} from '@rafaelaugusto/jolt'
|
|
14
|
+
import {
|
|
15
|
+
mapGradientBindings,
|
|
16
|
+
type MotionVisualAdapter,
|
|
17
|
+
type MotionCircular,
|
|
18
|
+
type MotionPlayback,
|
|
19
|
+
} from '@getcortexlabs/mavis-core/experimental'
|
|
20
|
+
|
|
21
|
+
const circles = new WeakMap<View, { dispose(): void }>()
|
|
22
|
+
export function nativeVisualEffects(
|
|
23
|
+
target: View,
|
|
24
|
+
sources: WeakMap<object, DerivedValue>,
|
|
25
|
+
colors: WeakMap<object, DerivedColor>,
|
|
26
|
+
plainText: () => boolean,
|
|
27
|
+
): MotionVisualAdapter {
|
|
28
|
+
const text = () => {
|
|
29
|
+
if (!plainText() || !(target instanceof Label) || target.formattedText)
|
|
30
|
+
throw new TypeError(
|
|
31
|
+
'Declare a motionSurface on MText with an explicit text prop; rich/slotted text is unsupported.',
|
|
32
|
+
)
|
|
33
|
+
return target
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
...nativeSurfaceEffects(target),
|
|
37
|
+
supports: (effect) => {
|
|
38
|
+
if (effect === 'text') return plainText()
|
|
39
|
+
if (effect === 'symbol')
|
|
40
|
+
return isIOS && target instanceof Image && Boolean(target.ios?.image?.symbolImage)
|
|
41
|
+
if (effect === 'image') return target instanceof Image
|
|
42
|
+
if (effect === 'liquid') return isIOS && target instanceof Image
|
|
43
|
+
return (
|
|
44
|
+
['gradient', 'particles', 'confetti', 'blur', 'shape', 'keyboard'].includes(effect) || isIOS
|
|
45
|
+
)
|
|
46
|
+
},
|
|
47
|
+
gradient(options) {
|
|
48
|
+
const paint = gradient(target, options)
|
|
49
|
+
return {
|
|
50
|
+
type: paint.type,
|
|
51
|
+
get suspended() {
|
|
52
|
+
return paint.suspended
|
|
53
|
+
},
|
|
54
|
+
animate: (values, options) => paint.animate(values, options),
|
|
55
|
+
set: (values) => paint.set(values),
|
|
56
|
+
stop: () => paint.stop(),
|
|
57
|
+
suspend: () => paint.suspend(),
|
|
58
|
+
resume: () => paint.resume(),
|
|
59
|
+
bind(values) {
|
|
60
|
+
const dispose = paint.bind(
|
|
61
|
+
mapGradientBindings(
|
|
62
|
+
values,
|
|
63
|
+
(value) => sources.get(value)!,
|
|
64
|
+
(value) => colors.get(value)!,
|
|
65
|
+
),
|
|
66
|
+
)
|
|
67
|
+
return { dispose }
|
|
68
|
+
},
|
|
69
|
+
dispose: () => paint.remove(),
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
shimmer: (options) => ({ supported: isIOS, dispose: shimmer(target, options) }),
|
|
73
|
+
loader: (options) => ({ supported: isIOS, dispose: loader(target, options) }),
|
|
74
|
+
animateText: (options) => animateText(text(), options),
|
|
75
|
+
rollTo: (value, options) => rollTo(text(), value, options),
|
|
76
|
+
circular() {
|
|
77
|
+
circles.get(target)?.dispose()
|
|
78
|
+
const hidden = target.accessibilityHidden,
|
|
79
|
+
interactive = target.isUserInteractionEnabled
|
|
80
|
+
const visibility = target.visibility
|
|
81
|
+
let active: MotionPlayback | undefined,
|
|
82
|
+
locked = false,
|
|
83
|
+
generation = 0,
|
|
84
|
+
disposed = false
|
|
85
|
+
let writtenVisibility: View['visibility'] | undefined
|
|
86
|
+
const focused = (view: View): boolean => {
|
|
87
|
+
if (view.ios?.isFirstResponder) return true
|
|
88
|
+
let found = false
|
|
89
|
+
view.eachChildView((child) => {
|
|
90
|
+
found = focused(child)
|
|
91
|
+
return !found
|
|
92
|
+
})
|
|
93
|
+
return found
|
|
94
|
+
}
|
|
95
|
+
const unlock = () => {
|
|
96
|
+
if (!locked) return
|
|
97
|
+
locked = false
|
|
98
|
+
if (target.accessibilityHidden) target.accessibilityHidden = hidden
|
|
99
|
+
if (!target.isUserInteractionEnabled) target.isUserInteractionEnabled = interactive
|
|
100
|
+
}
|
|
101
|
+
const run = (open: boolean, options: Parameters<MotionCircular['reveal']>[0] = {}) => {
|
|
102
|
+
if (isIOS && !open && focused(target))
|
|
103
|
+
throw new Error('Move focus outside the circular surface before conceal().')
|
|
104
|
+
const handle = open
|
|
105
|
+
? reveal(target, { from: options.origin, duration: options.duration })
|
|
106
|
+
: conceal(target, { to: options.origin, duration: options.duration })
|
|
107
|
+
const token = ++generation
|
|
108
|
+
active = handle
|
|
109
|
+
if (isIOS) writtenVisibility = target.visibility
|
|
110
|
+
if (isIOS) {
|
|
111
|
+
if (open) unlock()
|
|
112
|
+
else {
|
|
113
|
+
locked = true
|
|
114
|
+
target.accessibilityHidden = true
|
|
115
|
+
target.isUserInteractionEnabled = false
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
void handle.finished.then((completed) => {
|
|
119
|
+
if (token !== generation || disposed) return
|
|
120
|
+
active = undefined
|
|
121
|
+
if (completed && isIOS) writtenVisibility = target.visibility
|
|
122
|
+
if (!completed && target.visibility !== 'hidden') unlock()
|
|
123
|
+
})
|
|
124
|
+
return handle
|
|
125
|
+
}
|
|
126
|
+
const control = {
|
|
127
|
+
supported: isIOS,
|
|
128
|
+
reveal: (options?: Parameters<MotionCircular['reveal']>[0]) => run(true, options),
|
|
129
|
+
conceal: (options?: Parameters<MotionCircular['conceal']>[0]) => run(false, options),
|
|
130
|
+
dispose() {
|
|
131
|
+
if (disposed) return
|
|
132
|
+
disposed = true
|
|
133
|
+
generation++
|
|
134
|
+
active?.stop()
|
|
135
|
+
unlock()
|
|
136
|
+
if (circles.get(target) === control) {
|
|
137
|
+
circles.delete(target)
|
|
138
|
+
if (isIOS && writtenVisibility !== undefined && target.visibility === writtenVisibility)
|
|
139
|
+
target.visibility = visibility
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
}
|
|
143
|
+
circles.set(target, control)
|
|
144
|
+
return control
|
|
145
|
+
},
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useChoicePaint } from '../use-choice-paint.js'
|
|
1
2
|
import {
|
|
2
3
|
defineComponent,
|
|
3
4
|
h,
|
|
@@ -27,7 +28,21 @@ export const ChoiceControl = defineComponent({
|
|
|
27
28
|
setup(props, { attrs, emit }) {
|
|
28
29
|
const { theme } = useMavisTheme()
|
|
29
30
|
const nativeAttrs = useNativeViewAttrs(props)
|
|
31
|
+
const paint = useChoicePaint(
|
|
32
|
+
() => ({
|
|
33
|
+
borderColor:
|
|
34
|
+
props.modelValue || props.indeterminate
|
|
35
|
+
? theme.value.colors.primary
|
|
36
|
+
: theme.value.colors.muted,
|
|
37
|
+
backgroundColor:
|
|
38
|
+
!props.radio && (props.modelValue || props.indeterminate)
|
|
39
|
+
? theme.value.colors.primary
|
|
40
|
+
: 'transparent',
|
|
41
|
+
}),
|
|
42
|
+
theme,
|
|
43
|
+
)
|
|
30
44
|
const focused = ref(false)
|
|
45
|
+
let touchView: View | undefined
|
|
31
46
|
let mark: View | undefined
|
|
32
47
|
let motion: ReturnType<typeof animate> | undefined
|
|
33
48
|
let observer: ReturnType<typeof observeCheckbox> | undefined
|
|
@@ -41,6 +56,8 @@ export const ChoiceControl = defineComponent({
|
|
|
41
56
|
}
|
|
42
57
|
}
|
|
43
58
|
function unload() {
|
|
59
|
+
touchView?.off('touch', touch)
|
|
60
|
+
touchView = undefined
|
|
44
61
|
restore()
|
|
45
62
|
observer?.dispose()
|
|
46
63
|
observer = undefined
|
|
@@ -60,8 +77,9 @@ export const ChoiceControl = defineComponent({
|
|
|
60
77
|
{ flush: 'post' },
|
|
61
78
|
)
|
|
62
79
|
|
|
63
|
-
function touch(
|
|
64
|
-
|
|
80
|
+
function touch(data: EventData) {
|
|
81
|
+
const event = data as TouchGestureEventData
|
|
82
|
+
if (!mark || props.disabled || !props.pressFeedback) return
|
|
65
83
|
if (!['down', 'up', 'cancel'].includes(event.action)) return
|
|
66
84
|
motion?.stop()
|
|
67
85
|
const scale = event.action === 'down' ? 0.9 : 1
|
|
@@ -123,9 +141,10 @@ export const ChoiceControl = defineComponent({
|
|
|
123
141
|
onTap: () => {
|
|
124
142
|
if (!props.disabled) emit('activate')
|
|
125
143
|
},
|
|
126
|
-
onTouch: props.pressFeedback ? touch : undefined,
|
|
127
144
|
onLoaded: (event: EventData) => {
|
|
128
145
|
unload()
|
|
146
|
+
touchView = event.object as View
|
|
147
|
+
touchView.on('touch', touch)
|
|
129
148
|
observer = observeCheckbox(event.object as View, (value) => {
|
|
130
149
|
focused.value = value
|
|
131
150
|
})
|
|
@@ -154,14 +173,15 @@ export const ChoiceControl = defineComponent({
|
|
|
154
173
|
accessibilityHidden: true,
|
|
155
174
|
style: {
|
|
156
175
|
borderWidth: 2,
|
|
157
|
-
|
|
158
|
-
backgroundColor: !props.radio && selected ? colors.primary : 'transparent',
|
|
176
|
+
...paint.style,
|
|
159
177
|
},
|
|
160
178
|
onLoaded: (event: EventData) => {
|
|
161
179
|
mark = event.object as View
|
|
180
|
+
paint.onLoaded(event)
|
|
162
181
|
},
|
|
163
182
|
onUnloaded: () => {
|
|
164
183
|
restore()
|
|
184
|
+
paint.onUnloaded()
|
|
165
185
|
mark = undefined
|
|
166
186
|
},
|
|
167
187
|
},
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { defineComponent, h, mergeProps, type PropType } from 'nativescript-vue'
|
|
2
|
+
import { skeletonProps, useLoadingDecoration } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
+
import { MBox } from './layout.js'
|
|
4
|
+
|
|
5
|
+
export const LoadingDecoration = defineComponent({
|
|
6
|
+
name: 'MavisLoadingDecoration',
|
|
7
|
+
inheritAttrs: false,
|
|
8
|
+
props: {
|
|
9
|
+
...skeletonProps,
|
|
10
|
+
kind: { type: String as PropType<'shimmer' | 'dots' | 'bars' | 'ring'>, required: true },
|
|
11
|
+
color: { type: String, default: undefined },
|
|
12
|
+
size: { type: Number, default: 24 },
|
|
13
|
+
},
|
|
14
|
+
setup(props, { attrs }) {
|
|
15
|
+
const surface = useLoadingDecoration(() => ({
|
|
16
|
+
kind: props.kind,
|
|
17
|
+
animated: props.animated,
|
|
18
|
+
size: props.size,
|
|
19
|
+
color: props.color,
|
|
20
|
+
}))
|
|
21
|
+
return () =>
|
|
22
|
+
h(
|
|
23
|
+
MBox,
|
|
24
|
+
mergeProps(attrs, {
|
|
25
|
+
id: props.id,
|
|
26
|
+
width: props.width,
|
|
27
|
+
height: props.height,
|
|
28
|
+
radius: props.radius,
|
|
29
|
+
grow: props.grow,
|
|
30
|
+
shrink: props.shrink,
|
|
31
|
+
motionSurface: surface,
|
|
32
|
+
accessibilityHidden: true,
|
|
33
|
+
accessible: false,
|
|
34
|
+
isUserInteractionEnabled: false,
|
|
35
|
+
}),
|
|
36
|
+
)
|
|
37
|
+
},
|
|
38
|
+
})
|