@getcortexlabs/mavis-web 0.1.0-alpha.7 → 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.
Files changed (129) hide show
  1. package/README.md +4 -4
  2. package/dist/collection-motion.d.ts +4 -0
  3. package/dist/collection-motion.d.ts.map +1 -0
  4. package/dist/collection-motion.js +97 -0
  5. package/dist/collection-motion.js.map +1 -0
  6. package/dist/components/LoadingDecoration.d.ts +116 -0
  7. package/dist/components/LoadingDecoration.d.ts.map +1 -0
  8. package/dist/components/LoadingDecoration.js +35 -0
  9. package/dist/components/LoadingDecoration.js.map +1 -0
  10. package/dist/components/MAccordion.d.ts +1 -1
  11. package/dist/components/MAlert.d.ts +1 -1
  12. package/dist/components/MAvatar.d.ts +2 -2
  13. package/dist/components/MButton.d.ts +33 -11
  14. package/dist/components/MButton.d.ts.map +1 -1
  15. package/dist/components/MButton.js +15 -1
  16. package/dist/components/MButton.js.map +1 -1
  17. package/dist/components/MCard.d.ts +4 -4
  18. package/dist/components/MCheckbox.d.ts +1 -1
  19. package/dist/components/MChip.d.ts +2 -2
  20. package/dist/components/MCombobox.d.ts +1 -1
  21. package/dist/components/MCombobox.d.ts.map +1 -1
  22. package/dist/components/MCombobox.js +10 -0
  23. package/dist/components/MCombobox.js.map +1 -1
  24. package/dist/components/MDialog.d.ts +3 -0
  25. package/dist/components/MDialog.d.ts.map +1 -1
  26. package/dist/components/MDialog.js +69 -4
  27. package/dist/components/MDialog.js.map +1 -1
  28. package/dist/components/MEmptyState.d.ts +2 -2
  29. package/dist/components/MIcon.d.ts +18 -0
  30. package/dist/components/MIcon.d.ts.map +1 -1
  31. package/dist/components/MIcon.js +6 -2
  32. package/dist/components/MIcon.js.map +1 -1
  33. package/dist/components/MImage.d.ts +13 -2
  34. package/dist/components/MImage.d.ts.map +1 -1
  35. package/dist/components/MImage.js +57 -6
  36. package/dist/components/MImage.js.map +1 -1
  37. package/dist/components/MInput.d.ts +6 -6
  38. package/dist/components/MLink.d.ts +2 -2
  39. package/dist/components/MListItem.d.ts +1 -1
  40. package/dist/components/MProgress.d.ts +1 -1
  41. package/dist/components/MRadioGroup.d.ts +1 -1
  42. package/dist/components/MReveal.d.ts +10 -10
  43. package/dist/components/MScreen.d.ts +9 -0
  44. package/dist/components/MScreen.d.ts.map +1 -1
  45. package/dist/components/MScreen.js +37 -24
  46. package/dist/components/MScreen.js.map +1 -1
  47. package/dist/components/MSegmentedControl.d.ts +1 -1
  48. package/dist/components/MSelect.d.ts +1 -1
  49. package/dist/components/MSelect.d.ts.map +1 -1
  50. package/dist/components/MSelect.js +6 -0
  51. package/dist/components/MSelect.js.map +1 -1
  52. package/dist/components/MSheet.d.ts +6 -6
  53. package/dist/components/MSheet.d.ts.map +1 -1
  54. package/dist/components/MSheet.js +20 -13
  55. package/dist/components/MSheet.js.map +1 -1
  56. package/dist/components/MSkeleton.d.ts +12 -1
  57. package/dist/components/MSkeleton.d.ts.map +1 -1
  58. package/dist/components/MSkeleton.js +10 -4
  59. package/dist/components/MSkeleton.js.map +1 -1
  60. package/dist/components/MStack.d.ts +11 -11
  61. package/dist/components/MSwitch.d.ts +1 -1
  62. package/dist/components/MTabs.d.ts +1 -1
  63. package/dist/components/MText.d.ts +14 -3
  64. package/dist/components/MText.d.ts.map +1 -1
  65. package/dist/components/MText.js +8 -3
  66. package/dist/components/MText.js.map +1 -1
  67. package/dist/components/layout.d.ts +43 -32
  68. package/dist/components/layout.d.ts.map +1 -1
  69. package/dist/components/layout.js +3 -1
  70. package/dist/components/layout.js.map +1 -1
  71. package/dist/experimental.d.ts +2 -0
  72. package/dist/experimental.d.ts.map +1 -1
  73. package/dist/experimental.js +4 -0
  74. package/dist/experimental.js.map +1 -1
  75. package/dist/image-effects.d.ts +11 -0
  76. package/dist/image-effects.d.ts.map +1 -0
  77. package/dist/image-effects.js +65 -0
  78. package/dist/image-effects.js.map +1 -0
  79. package/dist/motion-region.d.ts.map +1 -1
  80. package/dist/motion-region.js +10 -1
  81. package/dist/motion-region.js.map +1 -1
  82. package/dist/motion-surface.d.ts +1 -1
  83. package/dist/motion-surface.d.ts.map +1 -1
  84. package/dist/motion-surface.js +45 -2
  85. package/dist/motion-surface.js.map +1 -1
  86. package/dist/platform-motion.d.ts +4 -0
  87. package/dist/platform-motion.d.ts.map +1 -0
  88. package/dist/platform-motion.js +23 -0
  89. package/dist/platform-motion.js.map +1 -0
  90. package/dist/sheet-motion.d.ts +6 -2
  91. package/dist/sheet-motion.d.ts.map +1 -1
  92. package/dist/sheet-motion.js +56 -155
  93. package/dist/sheet-motion.js.map +1 -1
  94. package/dist/surface-effects.d.ts +4 -0
  95. package/dist/surface-effects.d.ts.map +1 -0
  96. package/dist/surface-effects.js +28 -0
  97. package/dist/surface-effects.js.map +1 -0
  98. package/dist/use-motion-surface.d.ts +8 -0
  99. package/dist/use-motion-surface.d.ts.map +1 -0
  100. package/dist/use-motion-surface.js +33 -0
  101. package/dist/use-motion-surface.js.map +1 -0
  102. package/dist/visual-effects.d.ts +4 -0
  103. package/dist/visual-effects.d.ts.map +1 -0
  104. package/dist/visual-effects.js +120 -0
  105. package/dist/visual-effects.js.map +1 -0
  106. package/package.json +3 -3
  107. package/src/collection-motion.ts +107 -0
  108. package/src/components/LoadingDecoration.ts +39 -0
  109. package/src/components/MButton.ts +15 -1
  110. package/src/components/MCombobox.ts +10 -0
  111. package/src/components/MDialog.ts +78 -4
  112. package/src/components/MIcon.ts +10 -1
  113. package/src/components/MImage.ts +65 -5
  114. package/src/components/MScreen.ts +26 -2
  115. package/src/components/MSelect.ts +5 -0
  116. package/src/components/MSheet.ts +29 -18
  117. package/src/components/MSkeleton.ts +13 -4
  118. package/src/components/MText.ts +11 -2
  119. package/src/components/layout.ts +3 -0
  120. package/src/experimental.ts +8 -0
  121. package/src/image-effects.ts +78 -0
  122. package/src/motion-region.ts +10 -1
  123. package/src/motion-surface.ts +47 -1
  124. package/src/platform-motion.ts +36 -0
  125. package/src/sheet-motion.ts +51 -152
  126. package/src/style.css +24 -5
  127. package/src/surface-effects.ts +33 -0
  128. package/src/use-motion-surface.ts +43 -0
  129. package/src/visual-effects.ts +139 -0
@@ -11,12 +11,14 @@ import {
11
11
  } from '@getcortexlabs/mavis-core/vue'
12
12
  import { webAttrs } from '../style.js'
13
13
  import { useScreenViewport } from '../screen-viewport.js'
14
+ import { useMotionRegion } from '../motion-region.js'
14
15
 
15
16
  export const MScreen = defineComponent({
16
17
  name: 'MScreen',
17
18
  inheritAttrs: false,
18
19
  props: screenProps,
19
20
  setup(props, { attrs, slots }) {
21
+ const region = useMotionRegion(() => props.motionRegion)
20
22
  const { theme } = useMavisTheme()
21
23
  const appToast = useAppToastHost()
22
24
  const element = useScreenViewport(() => props.scroll)
@@ -39,8 +41,8 @@ export const MScreen = defineComponent({
39
41
  active.isContentEditable
40
42
  if (editor) active.blur()
41
43
  }
42
- return () =>
43
- h(
44
+ return () => {
45
+ const screen = h(
44
46
  'main',
45
47
  mergeProps(
46
48
  {
@@ -63,6 +65,7 @@ export const MScreen = defineComponent({
63
65
  },
64
66
  },
65
67
  webAttrs({ ...attrs, ...viewAttrs(props) }),
68
+ slots.overlay ? {} : region,
66
69
  ),
67
70
  [
68
71
  slots.default?.(),
@@ -71,5 +74,26 @@ export const MScreen = defineComponent({
71
74
  : null,
72
75
  ],
73
76
  )
77
+ return slots.overlay
78
+ ? h(
79
+ 'div',
80
+ mergeProps(
81
+ { class: 'm-screen-frame', style: { position: 'relative', overflow: 'clip' } },
82
+ region,
83
+ ),
84
+ [
85
+ screen,
86
+ h(
87
+ 'div',
88
+ {
89
+ class: 'm-screen-overlay',
90
+ style: { position: 'absolute', inset: 0, display: 'grid', pointerEvents: 'none' },
91
+ },
92
+ slots.overlay(),
93
+ ),
94
+ ],
95
+ )
96
+ : screen
97
+ }
74
98
  },
75
99
  })
@@ -299,6 +299,11 @@ export const MSelect = defineComponent({
299
299
  backgroundColor: checked ? colors.primarySoft : 'transparent',
300
300
  opacity: option.disabled ? 0.45 : 1,
301
301
  },
302
+ // Keep focus on the listbox and let this option own activation.
303
+ // The enclosing sheet must not capture and retarget its click.
304
+ onPointerdown: (event: PointerEvent) => {
305
+ if (event.button === 0) event.preventDefault()
306
+ },
302
307
  onClick: () => choose(option),
303
308
  },
304
309
  [
@@ -128,8 +128,12 @@ const Sheet = defineComponent({
128
128
  motion = sheetMotion(
129
129
  element,
130
130
  panel.value!,
131
- handle.value ?? null,
132
- () => props.dismissible,
131
+ handle.value!,
132
+ () => ({
133
+ dismissible: props.dismissible,
134
+ fullscreen: props.fullscreen,
135
+ label: checkSheetName(props.title, props.accessibilityLabel),
136
+ }),
133
137
  () => {
134
138
  if (props.open) return
135
139
  motion?.dispose()
@@ -157,7 +161,7 @@ const Sheet = defineComponent({
157
161
  }
158
162
  }
159
163
  watch(
160
- () => props.dismissible,
164
+ () => [props.dismissible, props.fullscreen, props.title, props.accessibilityLabel],
161
165
  () => motion?.refresh(),
162
166
  )
163
167
 
@@ -281,27 +285,34 @@ const Sheet = defineComponent({
281
285
  {
282
286
  class: 'm-sheet-panel',
283
287
  ref: panel,
284
- style: {
285
- padding: `${resolveSpace(theme.value, props.padding ?? 'lg')}px`,
286
- gap: `${space.md}px`,
287
- },
288
288
  },
289
289
  [
290
290
  h(
291
291
  'div',
292
292
  {
293
- ref: handle,
294
- class: 'm-sheet-handle',
295
- 'aria-hidden': 'true',
296
- style: { display: props.dismissible ? undefined : 'none' },
293
+ class: 'm-sheet-content',
294
+ style: {
295
+ padding: `${resolveSpace(theme.value, props.padding ?? 'lg')}px`,
296
+ gap: `${space.md}px`,
297
+ },
297
298
  },
298
- [h('span')],
299
- ),
300
- header,
301
- h(
302
- MColumn,
303
- { class: 'm-sheet-body', shrink: 1, gap: props.gap, align: props.align },
304
- { default: () => slots.default?.() },
299
+ [
300
+ h(
301
+ 'div',
302
+ {
303
+ ref: handle,
304
+ class: 'm-sheet-handle',
305
+ style: { display: props.dismissible ? undefined : 'none' },
306
+ },
307
+ [h('span')],
308
+ ),
309
+ header,
310
+ h(
311
+ MColumn,
312
+ { class: 'm-sheet-body', shrink: 1, gap: props.gap, align: props.align },
313
+ { default: () => slots.default?.() },
314
+ ),
315
+ ],
305
316
  ),
306
317
  ],
307
318
  ),
@@ -1,6 +1,7 @@
1
- import { defineComponent, h, mergeProps, onBeforeUnmount, onMounted, ref } from 'vue'
1
+ import { defineComponent, h, mergeProps, onBeforeUnmount, onMounted, ref, watch } from 'vue'
2
2
  import { skeletonProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
3
3
  import { MBox } from './layout.js'
4
+ import { LoadingDecoration } from './LoadingDecoration.js'
4
5
 
5
6
  export const MSkeleton = defineComponent({
6
7
  name: 'MSkeleton',
@@ -14,12 +15,19 @@ export const MSkeleton = defineComponent({
14
15
  }
15
16
  onMounted(() => {
16
17
  visibility()
17
- document.addEventListener('visibilitychange', visibility)
18
+ watch(
19
+ () => props.effect,
20
+ (effect) => {
21
+ document.removeEventListener('visibilitychange', visibility)
22
+ if (effect === 'pulse') document.addEventListener('visibilitychange', visibility)
23
+ },
24
+ { immediate: true },
25
+ )
18
26
  })
19
27
  onBeforeUnmount(() => document.removeEventListener('visibilitychange', visibility))
20
28
  return () =>
21
29
  h(
22
- MBox,
30
+ props.effect === 'shimmer' ? LoadingDecoration : MBox,
23
31
  mergeProps(
24
32
  {
25
33
  style: {
@@ -37,7 +45,8 @@ export const MSkeleton = defineComponent({
37
45
  shrink: props.shrink,
38
46
  backgroundColor: theme.value.colors.border,
39
47
  class: 'm-skeleton',
40
- 'data-animated': props.animated,
48
+ 'data-animated': props.effect === 'pulse' && props.animated,
49
+ ...(props.effect === 'shimmer' ? { kind: 'shimmer', animated: props.animated } : {}),
41
50
  style: {
42
51
  animationPlayState: hidden.value ? 'paused' : 'running',
43
52
  pointerEvents: 'none',
@@ -1,4 +1,4 @@
1
- import { defineComponent, h, mergeProps } from 'vue'
1
+ import { defineComponent, h, mergeProps, Text } from 'vue'
2
2
  import {
3
3
  textProps,
4
4
  useMavisTheme,
@@ -8,6 +8,7 @@ import {
8
8
  } from '@getcortexlabs/mavis-core/vue'
9
9
  import { fontFamily, nonNegative, validateWeight } from '@getcortexlabs/mavis-core'
10
10
  import { webAttrs } from '../style.js'
11
+ import { useMotionSurface } from '../use-motion-surface.js'
11
12
 
12
13
  export const MText = defineComponent({
13
14
  name: 'MText',
@@ -16,6 +17,10 @@ export const MText = defineComponent({
16
17
  setup(props, { attrs, slots }) {
17
18
  const { theme } = useMavisTheme()
18
19
  const shrink = useLayoutShrink()
20
+ const motion = useMotionSurface(
21
+ () => props.motionSurface,
22
+ () => props.text !== undefined,
23
+ )
19
24
  return () => {
20
25
  const type = theme.value.typography[props.variant]
21
26
  const runs =
@@ -27,6 +32,7 @@ export const MText = defineComponent({
27
32
  class: 'm-text',
28
33
  style: {
29
34
  margin: 0,
35
+ display: props.motionSurface && props.as === 'span' ? 'inline-block' : undefined,
30
36
  fontFamily: `var(--m-text-font-family, ${fontFamily(type.fontFamily, 'web')})`,
31
37
  fontSize: `var(--m-text-font-size, ${type.fontSize}px)`,
32
38
  fontWeight: props.weight
@@ -44,9 +50,12 @@ export const MText = defineComponent({
44
50
  },
45
51
  },
46
52
  webAttrs({ ...attrs, ...viewAttrs(props) }),
53
+ motion,
47
54
  ),
48
55
  runs.every((run) => !run.weight && !run.tone && !run.strong && !run.italic)
49
- ? runs.map((run) => run.text).join('')
56
+ ? props.motionSurface
57
+ ? [h(Text, null, runs.map((run) => run.text).join(''))]
58
+ : runs.map((run) => run.text).join('')
50
59
  : runs.map((run) => {
51
60
  if (!run.weight && !run.tone && !run.strong && !run.italic) return run.text
52
61
  if (run.tone && !(run.tone in theme.value.colors))
@@ -11,6 +11,7 @@ import { defineComponent, h, mergeProps, provide } from 'vue'
11
11
  import { resolveSpace } from '@getcortexlabs/mavis-core'
12
12
  import { boxStyle, webAttrs } from '../style.js'
13
13
  import { useMotionRegion } from '../motion-region.js'
14
+ import { useMotionSurface } from '../use-motion-surface.js'
14
15
 
15
16
  export type { Align, Justify } from '@getcortexlabs/mavis-core/vue'
16
17
 
@@ -68,6 +69,7 @@ export const MBox = defineComponent({
68
69
  props: motionBoxProps,
69
70
  setup(props, { attrs, slots }) {
70
71
  const region = useMotionRegion(() => props.motionRegion)
72
+ const surface = useMotionSurface(() => props.motionSurface)
71
73
  const { theme } = useMavisTheme()
72
74
  const shrink = useLayoutShrink()
73
75
  return () =>
@@ -80,6 +82,7 @@ export const MBox = defineComponent({
80
82
  },
81
83
  webAttrs({ ...attrs, ...viewAttrs(props) }),
82
84
  region,
85
+ surface,
83
86
  ),
84
87
  slots.default?.(),
85
88
  )
@@ -3,6 +3,14 @@ import type { WebMotionScope, WebMotionResource } from '@rafaelaugusto/jolt/web'
3
3
  import { regionState, type MotionRegion } from '@getcortexlabs/mavis-core/experimental'
4
4
  import { webRegion } from './motion-region.js'
5
5
 
6
+ /** Call from an explicit application action; a request does not prove physical vibration. */
7
+ export function requestMavisWebHaptic(
8
+ region: MotionRegion,
9
+ style: import('@rafaelaugusto/jolt/web').HapticStyle,
10
+ ): import('@rafaelaugusto/jolt/web').WebHapticResult {
11
+ return webRegion(regionState(region).adapter).runtime.haptic(style)
12
+ }
13
+
6
14
  /**
7
15
  * Web-only composition for application HTML/SVG inside a declared MBox region.
8
16
  * Borrows the very same Jolt context as the region's component press surfaces.
@@ -0,0 +1,78 @@
1
+ import type {
2
+ MotionImageEffectName,
3
+ MotionImageEffectOptions,
4
+ MotionPlayback,
5
+ } from '@getcortexlabs/mavis-core/experimental'
6
+ import type { WebRuntime, WebMotionScope } from '@rafaelaugusto/jolt/web'
7
+
8
+ type Presentation = {
9
+ current(): boolean
10
+ commit(src: string): Promise<boolean>
11
+ }
12
+ const images = new WeakMap<HTMLImageElement, Presentation>()
13
+ const preparations = new WeakMap<HTMLImageElement, object>()
14
+ export function registerMotionImage(target: HTMLImageElement, presentation: Presentation) {
15
+ images.set(target, presentation)
16
+ return () => {
17
+ if (images.get(target) === presentation) images.delete(target)
18
+ }
19
+ }
20
+ export function loadedMotionImage(target: HTMLElement): HTMLImageElement {
21
+ const image = target as HTMLImageElement
22
+ if (!images.has(image) || !image.complete || !image.naturalWidth)
23
+ throw new TypeError('Use the ready motionSurface of MImage for pixel effects.')
24
+ return image
25
+ }
26
+ export async function webImageEffect(
27
+ owner: WebRuntime | WebMotionScope,
28
+ target: HTMLElement,
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
+ const preparation = {}
37
+ preparations.set(image, preparation)
38
+ let destination: HTMLImageElement | undefined
39
+ if (to !== undefined) {
40
+ if (name !== 'dissolve' || !to.trim())
41
+ throw new TypeError('Only dissolve accepts a nonempty destination source.')
42
+ destination = new image.ownerDocument.defaultView!.Image()
43
+ destination.crossOrigin = image.crossOrigin ?? 'anonymous'
44
+ destination.src = to
45
+ await destination.decode()
46
+ }
47
+ if (
48
+ !live() ||
49
+ preparations.get(image) !== preparation ||
50
+ !presentation.current() ||
51
+ images.get(image) !== presentation ||
52
+ !image.isConnected
53
+ )
54
+ throw new Error('Image presentation changed while preparing the effect.')
55
+ const previous = image.src
56
+ const raw = owner.imageEffect(image, name, {
57
+ ...rest,
58
+ ...(destination ? { to: destination } : {}),
59
+ })
60
+ const finished = raw.finished.then(async (success) => {
61
+ if (!success || !to || raw.progress !== 1) return success
62
+ if (!presentation.current() || images.get(image) !== presentation) return false
63
+ if (!live()) {
64
+ if (image.src === destination?.src) image.src = previous
65
+ return false
66
+ }
67
+ return presentation.commit(to)
68
+ })
69
+ return new Proxy(raw as MotionPlayback, {
70
+ get(target, key) {
71
+ if (key === 'then') return undefined
72
+ if (key === 'finished') return finished
73
+ const value = Reflect.get(target, key, target)
74
+ return typeof value === 'function' ? value.bind(target) : value
75
+ },
76
+ set: (target, key, value) => Reflect.set(target, key, value, target),
77
+ })
78
+ }
@@ -9,6 +9,8 @@ import { webSurfaceTarget } from './motion-surface.js'
9
9
  import { webScrollElement } from './scroll-motion.js'
10
10
  import type { WebRuntime } from '@rafaelaugusto/jolt/web'
11
11
  import { useConnectedMotion } from './connected-motion.js'
12
+ import { webCollectionMotion } from './collection-motion.js'
13
+ import { webPlatformMotion } from './platform-motion.js'
12
14
 
13
15
  const regions = new WeakMap<MotionRegionAdapter, { target: HTMLElement; runtime: WebRuntime }>()
14
16
  export function webRegion(adapter: MotionRegionAdapter) {
@@ -39,6 +41,8 @@ function regionAdapter(runtime: WebRuntime, target: HTMLElement): MotionRegionAd
39
41
  : ([resolve(step[0]), step[1], step[2]] as const),
40
42
  )
41
43
  const adapter: MotionRegionAdapter = {
44
+ ...webPlatformMotion(runtime, target, resolve),
45
+ ...webCollectionMotion(runtime, target, resolve),
42
46
  sequence: (items) =>
43
47
  runtime.sequence(steps(items) as unknown as Parameters<WebRuntime['sequence']>[0]),
44
48
  timeline: (items) =>
@@ -88,7 +92,12 @@ function regionAdapter(runtime: WebRuntime, target: HTMLElement): MotionRegionAd
88
92
  viewportEnter(surfaces, options) {
89
93
  const control = runtime.viewportEnter(surfaces.map(resolve), {
90
94
  keyframes: options.frames ?? { opacity: [0, 1], y: [20, 0] },
91
- transition: { duration: 450, ...options.transition, stagger: options.stagger ?? 70 },
95
+ transition: {
96
+ ...(options.transition?.type === 'gravity'
97
+ ? options.transition
98
+ : { duration: 450, ...options.transition }),
99
+ stagger: options.stagger ?? 70,
100
+ },
92
101
  root: options.root && webScrollElement(options.root),
93
102
  rootMargin: `${options.margin ?? 0}px`,
94
103
  threshold: options.threshold,
@@ -7,6 +7,7 @@ import type {
7
7
  } from '@rafaelaugusto/jolt/web'
8
8
  import type { MotionSurfaceAdapter } from '@getcortexlabs/mavis-core/experimental'
9
9
  import { webRegion } from './motion-region.js'
10
+ import { webVisualEffects } from './visual-effects.js'
10
11
 
11
12
  const boundPaint = new WeakMap<HTMLElement, Map<string, number>>()
12
13
  const paintKeys = new Set([
@@ -43,13 +44,58 @@ export function webMotionSurface(
43
44
  owner: WebRuntime | WebMotionScope = runtime,
44
45
  sources = new WeakMap<object, WebReadableValue>(),
45
46
  refreshes = new Map<object, () => void>(),
47
+ plainText: () => boolean = () => false,
46
48
  ) {
47
49
  const adapter: MotionSurfaceAdapter = {
50
+ ...webVisualEffects(owner, target, sources, plainText),
51
+ sensor(kind, options) {
52
+ const sensor = owner.sensor(kind, options)
53
+ const wrap = (value: WebReadableValue) => {
54
+ const borrowed = { get: () => value.get(), dispose() {} }
55
+ sources.set(borrowed, value)
56
+ return borrowed
57
+ }
58
+ return {
59
+ kind,
60
+ x: wrap(sensor.x),
61
+ y: wrap(sensor.y),
62
+ z: wrap(sensor.z),
63
+ quaternion:
64
+ sensor.kind === 'rotation'
65
+ ? {
66
+ x: wrap(sensor.quaternion.x),
67
+ y: wrap(sensor.quaternion.y),
68
+ z: wrap(sensor.quaternion.z),
69
+ w: wrap(sensor.quaternion.w),
70
+ }
71
+ : undefined,
72
+ get status() {
73
+ return sensor.status
74
+ },
75
+ get available() {
76
+ return sensor.available
77
+ },
78
+ get paused() {
79
+ return sensor.paused
80
+ },
81
+ pause: () => sensor.pause(),
82
+ resume: () => sensor.play(),
83
+ recenter: () => {
84
+ if (sensor.kind === 'rotation') sensor.recenter()
85
+ },
86
+ requestPermission: () => sensor.requestPermission(),
87
+ snapshot: () => sensor.snapshot(),
88
+ dispose: () => sensor.dispose(),
89
+ }
90
+ },
48
91
  use(setup) {
49
92
  const scope = runtime.scope()
50
93
  try {
51
94
  scope.use((child) =>
52
- setup(webMotionSurface(runtime, target, enabled, child, sources, refreshes).adapter),
95
+ setup(
96
+ webMotionSurface(runtime, target, enabled, child, sources, refreshes, plainText)
97
+ .adapter,
98
+ ),
53
99
  )
54
100
  } catch (error) {
55
101
  scope.dispose()
@@ -0,0 +1,36 @@
1
+ import type { WebRuntime } from '@rafaelaugusto/jolt/web'
2
+ import type {
3
+ MotionRegionAdapter,
4
+ MotionSurfaceAdapter,
5
+ } from '@getcortexlabs/mavis-core/experimental'
6
+
7
+ export function webPlatformMotion(
8
+ runtime: WebRuntime,
9
+ target: HTMLElement,
10
+ resolve: (surface: MotionSurfaceAdapter) => HTMLElement,
11
+ ): Pick<MotionRegionAdapter, 'onKeyboard' | 'physicsWorld'> {
12
+ return {
13
+ onKeyboard: (callback) => runtime.onKeyboard(callback),
14
+ async physicsWorld(bodies, options) {
15
+ const world = runtime.physicsWorld(
16
+ target,
17
+ bodies.map(({ target, ...body }) => ({ ...body, view: resolve(target) })),
18
+ options,
19
+ )
20
+ return {
21
+ get paused() {
22
+ return world.paused
23
+ },
24
+ pause: () => world.pause(),
25
+ resume: () => world.play(),
26
+ reset: () => world.reset(),
27
+ impulse: (id, value) => world.impulse(id, value),
28
+ attach: (id, value) => world.attach(id, value),
29
+ spring: (id, value) => world.spring(id, value),
30
+ snapTo: (id, index) => world.snapTo(id, index),
31
+ snapshot: () => world.snapshot(),
32
+ dispose: () => world.dispose(),
33
+ }
34
+ },
35
+ }
36
+ }