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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/README.md +6 -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/DateCalendar.d.ts +1 -1
  7. package/dist/components/LoadingDecoration.d.ts +116 -0
  8. package/dist/components/LoadingDecoration.d.ts.map +1 -0
  9. package/dist/components/LoadingDecoration.js +35 -0
  10. package/dist/components/LoadingDecoration.js.map +1 -0
  11. package/dist/components/MAccordion.d.ts +2 -2
  12. package/dist/components/MAlert.d.ts +3 -3
  13. package/dist/components/MAvatar.d.ts +3 -3
  14. package/dist/components/MBadge.d.ts +1 -1
  15. package/dist/components/MButton.d.ts +36 -14
  16. package/dist/components/MButton.d.ts.map +1 -1
  17. package/dist/components/MButton.js +29 -9
  18. package/dist/components/MButton.js.map +1 -1
  19. package/dist/components/MCard.d.ts +7 -7
  20. package/dist/components/MCard.d.ts.map +1 -1
  21. package/dist/components/MCard.js +3 -2
  22. package/dist/components/MCard.js.map +1 -1
  23. package/dist/components/MCheckbox.d.ts +2 -2
  24. package/dist/components/MChip.d.ts +3 -3
  25. package/dist/components/MCombobox.d.ts +2 -2
  26. package/dist/components/MCombobox.d.ts.map +1 -1
  27. package/dist/components/MCombobox.js +10 -0
  28. package/dist/components/MCombobox.js.map +1 -1
  29. package/dist/components/MDatePicker.d.ts +56 -8
  30. package/dist/components/MDatePicker.d.ts.map +1 -1
  31. package/dist/components/MDatePicker.js +2 -10
  32. package/dist/components/MDatePicker.js.map +1 -1
  33. package/dist/components/MDialog.d.ts +3 -0
  34. package/dist/components/MDialog.d.ts.map +1 -1
  35. package/dist/components/MDialog.js +69 -4
  36. package/dist/components/MDialog.js.map +1 -1
  37. package/dist/components/MEmptyState.d.ts +3 -3
  38. package/dist/components/MGrid.d.ts +163 -0
  39. package/dist/components/MGrid.d.ts.map +1 -0
  40. package/dist/components/MGrid.js +32 -0
  41. package/dist/components/MGrid.js.map +1 -0
  42. package/dist/components/MIcon.d.ts +19 -1
  43. package/dist/components/MIcon.d.ts.map +1 -1
  44. package/dist/components/MIcon.js +11 -4
  45. package/dist/components/MIcon.js.map +1 -1
  46. package/dist/components/MImage.d.ts +61 -5
  47. package/dist/components/MImage.d.ts.map +1 -1
  48. package/dist/components/MImage.js +76 -10
  49. package/dist/components/MImage.js.map +1 -1
  50. package/dist/components/MInput.d.ts +10 -10
  51. package/dist/components/MInput.d.ts.map +1 -1
  52. package/dist/components/MInput.js +7 -0
  53. package/dist/components/MInput.js.map +1 -1
  54. package/dist/components/MLink.d.ts +3 -3
  55. package/dist/components/MLink.d.ts.map +1 -1
  56. package/dist/components/MLink.js +5 -33
  57. package/dist/components/MLink.js.map +1 -1
  58. package/dist/components/MListItem.d.ts +2 -2
  59. package/dist/components/MProgress.d.ts +3 -3
  60. package/dist/components/MRadioGroup.d.ts +2 -2
  61. package/dist/components/MReveal.d.ts +13 -13
  62. package/dist/components/MScreen.d.ts +9 -0
  63. package/dist/components/MScreen.d.ts.map +1 -1
  64. package/dist/components/MScreen.js +37 -24
  65. package/dist/components/MScreen.js.map +1 -1
  66. package/dist/components/MSegmentedControl.d.ts +2 -2
  67. package/dist/components/MSelect.d.ts +2 -2
  68. package/dist/components/MSelect.d.ts.map +1 -1
  69. package/dist/components/MSelect.js +6 -0
  70. package/dist/components/MSelect.js.map +1 -1
  71. package/dist/components/MSheet.d.ts +15 -6
  72. package/dist/components/MSheet.d.ts.map +1 -1
  73. package/dist/components/MSheet.js +65 -27
  74. package/dist/components/MSheet.js.map +1 -1
  75. package/dist/components/MSkeleton.d.ts +13 -2
  76. package/dist/components/MSkeleton.d.ts.map +1 -1
  77. package/dist/components/MSkeleton.js +10 -4
  78. package/dist/components/MSkeleton.js.map +1 -1
  79. package/dist/components/MStack.d.ts +14 -14
  80. package/dist/components/MStack.d.ts.map +1 -1
  81. package/dist/components/MStack.js +3 -13
  82. package/dist/components/MStack.js.map +1 -1
  83. package/dist/components/MSwitch.d.ts +2 -2
  84. package/dist/components/MTabs.d.ts +2 -2
  85. package/dist/components/MText.d.ts +16 -5
  86. package/dist/components/MText.d.ts.map +1 -1
  87. package/dist/components/MText.js +8 -3
  88. package/dist/components/MText.js.map +1 -1
  89. package/dist/components/configurator.d.ts +3 -3
  90. package/dist/components/layout.d.ts +55 -44
  91. package/dist/components/layout.d.ts.map +1 -1
  92. package/dist/components/layout.js +3 -1
  93. package/dist/components/layout.js.map +1 -1
  94. package/dist/content-width.d.ts +4 -0
  95. package/dist/content-width.d.ts.map +1 -0
  96. package/dist/content-width.js +62 -0
  97. package/dist/content-width.js.map +1 -0
  98. package/dist/date-format.d.ts +6 -0
  99. package/dist/date-format.d.ts.map +1 -0
  100. package/dist/date-format.js +23 -0
  101. package/dist/date-format.js.map +1 -0
  102. package/dist/experimental.d.ts +2 -0
  103. package/dist/experimental.d.ts.map +1 -1
  104. package/dist/experimental.js +4 -0
  105. package/dist/experimental.js.map +1 -1
  106. package/dist/icons.d.ts +14 -0
  107. package/dist/icons.d.ts.map +1 -0
  108. package/dist/icons.js +23 -0
  109. package/dist/icons.js.map +1 -0
  110. package/dist/image-effects.d.ts +11 -0
  111. package/dist/image-effects.d.ts.map +1 -0
  112. package/dist/image-effects.js +67 -0
  113. package/dist/image-effects.js.map +1 -0
  114. package/dist/index.d.ts +11 -8
  115. package/dist/index.d.ts.map +1 -1
  116. package/dist/index.js +13 -10
  117. package/dist/index.js.map +1 -1
  118. package/dist/motion-region.d.ts.map +1 -1
  119. package/dist/motion-region.js +10 -1
  120. package/dist/motion-region.js.map +1 -1
  121. package/dist/motion-surface.d.ts +1 -1
  122. package/dist/motion-surface.d.ts.map +1 -1
  123. package/dist/motion-surface.js +45 -2
  124. package/dist/motion-surface.js.map +1 -1
  125. package/dist/platform-motion.d.ts +4 -0
  126. package/dist/platform-motion.d.ts.map +1 -0
  127. package/dist/platform-motion.js +23 -0
  128. package/dist/platform-motion.js.map +1 -0
  129. package/dist/services.d.ts +16 -0
  130. package/dist/services.d.ts.map +1 -0
  131. package/dist/services.js +18 -0
  132. package/dist/services.js.map +1 -0
  133. package/dist/sheet-motion.d.ts +6 -2
  134. package/dist/sheet-motion.d.ts.map +1 -1
  135. package/dist/sheet-motion.js +56 -155
  136. package/dist/sheet-motion.js.map +1 -1
  137. package/dist/surface-effects.d.ts +4 -0
  138. package/dist/surface-effects.d.ts.map +1 -0
  139. package/dist/surface-effects.js +28 -0
  140. package/dist/surface-effects.js.map +1 -0
  141. package/dist/use-motion-surface.d.ts +8 -0
  142. package/dist/use-motion-surface.d.ts.map +1 -0
  143. package/dist/use-motion-surface.js +33 -0
  144. package/dist/use-motion-surface.js.map +1 -0
  145. package/dist/visual-effects.d.ts +4 -0
  146. package/dist/visual-effects.d.ts.map +1 -0
  147. package/dist/visual-effects.js +120 -0
  148. package/dist/visual-effects.js.map +1 -0
  149. package/package.json +22 -4
  150. package/src/base.css +992 -0
  151. package/src/collection-motion.ts +107 -0
  152. package/src/components/LoadingDecoration.ts +39 -0
  153. package/src/components/MButton.ts +43 -26
  154. package/src/components/MCard.ts +3 -1
  155. package/src/components/MCombobox.ts +10 -0
  156. package/src/components/MDatePicker.ts +1 -9
  157. package/src/components/MDialog.ts +78 -4
  158. package/src/components/MGrid.ts +45 -0
  159. package/src/components/MIcon.ts +11 -3
  160. package/src/components/MImage.ts +85 -10
  161. package/src/components/MInput.ts +9 -3
  162. package/src/components/MLink.ts +10 -32
  163. package/src/components/MScreen.ts +26 -2
  164. package/src/components/MSelect.ts +5 -0
  165. package/src/components/MSheet.ts +76 -32
  166. package/src/components/MSkeleton.ts +13 -4
  167. package/src/components/MStack.ts +3 -20
  168. package/src/components/MText.ts +11 -2
  169. package/src/components/layout.ts +3 -0
  170. package/src/content-width.ts +70 -0
  171. package/src/date-format.ts +36 -0
  172. package/src/experimental.ts +8 -0
  173. package/src/icons.css +7 -0
  174. package/src/icons.ts +28 -0
  175. package/src/image-effects.ts +80 -0
  176. package/src/index.ts +63 -63
  177. package/src/motion-region.ts +10 -1
  178. package/src/motion-surface.ts +47 -1
  179. package/src/platform-motion.ts +36 -0
  180. package/src/services.ts +33 -0
  181. package/src/sheet-motion.ts +51 -152
  182. package/src/style.css +2 -981
  183. package/src/surface-effects.ts +33 -0
  184. package/src/use-motion-surface.ts +43 -0
  185. package/src/visual-effects.ts +139 -0
@@ -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
  )
@@ -0,0 +1,70 @@
1
+ import {
2
+ onActivated,
3
+ onBeforeUnmount,
4
+ onDeactivated,
5
+ onMounted,
6
+ shallowRef,
7
+ watch,
8
+ type ShallowRef,
9
+ } from 'vue'
10
+
11
+ /** Width-only observation: layout updates run outside ResizeObserver's delivery loop. */
12
+ export function useContentWidth(
13
+ element: ShallowRef<HTMLElement | undefined>,
14
+ enabled: () => boolean,
15
+ ) {
16
+ const width = shallowRef<number>()
17
+ let observer: ResizeObserver | undefined
18
+ let frame: number | undefined
19
+ let measured: number | undefined
20
+ let mounted = false
21
+ function stop() {
22
+ observer?.disconnect()
23
+ observer = undefined
24
+ if (frame !== undefined) cancelAnimationFrame(frame)
25
+ frame = undefined
26
+ measured = undefined
27
+ }
28
+ function start() {
29
+ if (
30
+ !mounted ||
31
+ observer ||
32
+ !enabled() ||
33
+ !element.value ||
34
+ typeof ResizeObserver === 'undefined'
35
+ )
36
+ return
37
+ observer = new ResizeObserver(([entry]) => {
38
+ if (!mounted || !enabled() || !entry || entry.contentRect.width === measured) return
39
+ measured = entry.contentRect.width
40
+ if (frame !== undefined) cancelAnimationFrame(frame)
41
+ frame = requestAnimationFrame(() => {
42
+ frame = undefined
43
+ width.value = measured
44
+ })
45
+ })
46
+ observer.observe(element.value)
47
+ }
48
+ onMounted(() => {
49
+ mounted = true
50
+ start()
51
+ })
52
+ onActivated(() => {
53
+ mounted = true
54
+ start()
55
+ })
56
+ onDeactivated(() => {
57
+ mounted = false
58
+ stop()
59
+ })
60
+ onBeforeUnmount(() => {
61
+ mounted = false
62
+ stop()
63
+ })
64
+ watch(enabled, () => {
65
+ stop()
66
+ if (enabled()) start()
67
+ else width.value = undefined
68
+ })
69
+ return width
70
+ }
@@ -0,0 +1,36 @@
1
+ import {
2
+ civilDate,
3
+ dateTimeMilliseconds,
4
+ resolveDateTimeOptions,
5
+ type DateTimeValue,
6
+ type DateTimeFormatOptions,
7
+ } from '@getcortexlabs/mavis-core'
8
+ export type { DateTimeValue, DateTimeFormatOptions, DateTimeStyle } from '@getcortexlabs/mavis-core'
9
+
10
+ export function formatDateTime(value: DateTimeValue, options: DateTimeFormatOptions): string {
11
+ const { locale, ...format } = resolveDateTimeOptions(options)
12
+ return new Intl.DateTimeFormat(locale, { ...format, calendar: 'gregory' }).format(
13
+ dateTimeMilliseconds(value),
14
+ )
15
+ }
16
+
17
+ /** Explicit conversion from an instant to a Gregorian calendar day in a named zone. */
18
+ export function dateTimeToCivilDate(
19
+ value: DateTimeValue,
20
+ options: Pick<DateTimeFormatOptions, 'timeZone'>,
21
+ ) {
22
+ const { timeZone } = resolveDateTimeOptions(options)
23
+ const parts = new Intl.DateTimeFormat('en-US', {
24
+ timeZone,
25
+ calendar: 'gregory',
26
+ numberingSystem: 'latn',
27
+ year: 'numeric',
28
+ month: '2-digit',
29
+ day: '2-digit',
30
+ era: 'short',
31
+ }).formatToParts(dateTimeMilliseconds(value))
32
+ const part = (type: Intl.DateTimeFormatPartTypes) =>
33
+ parts.find((part) => part.type === type)?.value
34
+ if (part('era') !== 'AD') throw new RangeError('Civil dates support years 0001–9999.')
35
+ return civilDate(`${part('year')!.padStart(4, '0')}-${part('month')}-${part('day')}`)
36
+ }
@@ -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.
package/src/icons.css ADDED
@@ -0,0 +1,7 @@
1
+ @font-face {
2
+ font-family: 'lucide';
3
+ src: url('./fonts/lucide.woff2') format('woff2');
4
+ font-weight: normal;
5
+ font-style: normal;
6
+ font-display: block;
7
+ }
package/src/icons.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { h, inject, type Component, type InjectionKey, type VNode } from 'vue'
2
+ import { iconFontFamily, iconGlyph, type IconName } from '@getcortexlabs/mavis-core'
3
+
4
+ export interface MavisIconOptions {
5
+ /** Import only the SVG components the application uses. Missing entries use iconFallback. */
6
+ icons?: Partial<Record<IconName, Component>>
7
+ iconFallback?: 'font' | 'none'
8
+ }
9
+ export const iconOptionsKey: InjectionKey<MavisIconOptions> = Symbol('mavis.icons')
10
+
11
+ /** One app-scoped resolver shared by standalone icons and control adornments. */
12
+ export function useIconContent() {
13
+ const options = inject(iconOptionsKey, undefined)
14
+ return (name: IconName, size: number): { content: string | VNode; fontFamily?: string } => {
15
+ const component = options?.icons?.[name]
16
+ if (component)
17
+ return {
18
+ content: h(component, {
19
+ width: size,
20
+ height: size,
21
+ 'aria-hidden': 'true',
22
+ focusable: 'false',
23
+ }),
24
+ }
25
+ if (options?.iconFallback === 'none') return { content: '' }
26
+ return { content: iconGlyph(name), fontFamily: iconFontFamily }
27
+ }
28
+ }
@@ -0,0 +1,80 @@
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
+ if (to !== undefined && image.srcset?.trim())
37
+ throw new TypeError('Dissolve source replacement requires an image without srcset.')
38
+ const preparation = {}
39
+ preparations.set(image, preparation)
40
+ let destination: HTMLImageElement | undefined
41
+ if (to !== undefined) {
42
+ if (name !== 'dissolve' || !to.trim())
43
+ throw new TypeError('Only dissolve accepts a nonempty destination source.')
44
+ destination = new image.ownerDocument.defaultView!.Image()
45
+ destination.crossOrigin = image.crossOrigin ?? 'anonymous'
46
+ destination.src = to
47
+ await destination.decode()
48
+ }
49
+ if (
50
+ !live() ||
51
+ preparations.get(image) !== preparation ||
52
+ !presentation.current() ||
53
+ images.get(image) !== presentation ||
54
+ !image.isConnected
55
+ )
56
+ throw new Error('Image presentation changed while preparing the effect.')
57
+ const previous = image.src
58
+ const raw = owner.imageEffect(image, name, {
59
+ ...rest,
60
+ ...(destination ? { to: destination } : {}),
61
+ })
62
+ const finished = raw.finished.then(async (success) => {
63
+ if (!success || !to || raw.progress !== 1) return success
64
+ if (!presentation.current() || images.get(image) !== presentation) return false
65
+ if (!live()) {
66
+ if (image.src === destination?.src) image.src = previous
67
+ return false
68
+ }
69
+ return presentation.commit(to)
70
+ })
71
+ return new Proxy(raw as MotionPlayback, {
72
+ get(target, key) {
73
+ if (key === 'then') return undefined
74
+ if (key === 'finished') return finished
75
+ const value = Reflect.get(target, key, target)
76
+ return typeof value === 'function' ? value.bind(target) : value
77
+ },
78
+ set: (target, key, value) => Reflect.set(target, key, value, target),
79
+ })
80
+ }
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { MNumberInput, MMultiSelect } from './components/configurator.js'
2
2
  import { MImage } from './components/MImage.js'
3
3
  import { MStack } from './components/MStack.js'
4
+ import { MGrid } from './components/MGrid.js'
4
5
  export { themeVariables, useMavisTokens } from './tokens.js'
5
6
  import { MLink } from './components/MLink.js'
6
7
  import { MDatePicker, MDateRangePicker } from './components/MDatePicker.js'
@@ -9,16 +10,11 @@ import { MFilePicker } from './components/MFilePicker.js'
9
10
  import { MFormGroup, MFormErrors, MSteps, MPagination } from './components/workflows.js'
10
11
  import { MChip } from './components/MChip.js'
11
12
  import { MEmptyState } from './components/MEmptyState.js'
12
- import type { App } from 'vue'
13
- import {
14
- MThemeProvider,
15
- MSpan,
16
- createThemeContext,
17
- installAppToast,
18
- themeKey,
19
- type ThemeContextOptions,
20
- } from '@getcortexlabs/mavis-core/vue'
21
- import { systemAppearance } from './appearance.js'
13
+ import type { App, Component } from 'vue'
14
+ import { createMavisServices, type MavisServiceOptions } from './services.js'
15
+ export { createMavisServices } from './services.js'
16
+ export type { MavisServiceOptions, MavisIconOptions } from './services.js'
17
+ import { MThemeProvider, MSpan } from '@getcortexlabs/mavis-core/vue'
22
18
  import { MScreen } from './components/MScreen.js'
23
19
  import { MBox, MRow, MColumn } from './components/layout.js'
24
20
  import { MCard } from './components/MCard.js'
@@ -54,6 +50,7 @@ export {
54
50
  MRow,
55
51
  MColumn,
56
52
  MStack,
53
+ MGrid,
57
54
  MLink,
58
55
  MCard,
59
56
  MText,
@@ -99,6 +96,7 @@ export {
99
96
  useFormController,
100
97
  useFormField,
101
98
  useFileSelection,
99
+ useMavisNavigation,
102
100
  } from '@getcortexlabs/mavis-core/vue'
103
101
  export type {
104
102
  MavisThemeContext,
@@ -109,64 +107,65 @@ export type {
109
107
  export type { Align, Justify } from './components/layout.js'
110
108
  export * from '@getcortexlabs/mavis-core'
111
109
 
112
- export type MavisOptions = Omit<ThemeContextOptions, 'source'> & { toast?: { closeLabel?: string } }
110
+ export type MavisOptions = MavisServiceOptions & { components?: false | Record<string, Component> }
113
111
 
114
112
  /** Create one plugin per application; `system` appearance follows `prefers-color-scheme`. */
115
113
  export function createMavis(options: MavisOptions = {}) {
116
114
  return {
117
115
  install(app: App) {
118
- installAppToast(app, options.toast)
119
- const { toast: _toast, ...theme } = options
120
- const context = createThemeContext({ ...theme, source: systemAppearance() })
121
- app.provide(themeKey, context)
122
- app.onUnmount(() => context.dispose())
123
- for (const [name, component] of Object.entries({
124
- MThemeProvider,
125
- MSpan,
126
- MScreen,
127
- MBox,
128
- MRow,
129
- MColumn,
130
- MStack,
131
- MLink,
132
- MCard,
133
- MText,
134
- MButton,
135
- MSlider,
136
- MSwitch,
137
- MCheckbox,
138
- MRadioGroup,
139
- MSelect,
140
- MToast,
141
- MDialog,
142
- MTabs,
143
- MSkeleton,
144
- MChip,
145
- MEmptyState,
146
- MProgress,
147
- MAccordion,
148
- MSegmentedControl,
149
- MAlert,
150
- MListItem,
151
- MSeparator,
152
- MAvatar,
153
- MBadge,
154
- MInput,
155
- MIcon,
156
- MReveal,
157
- MSheet,
158
- MDatePicker,
159
- MDateRangePicker,
160
- MNumberInput,
161
- MMultiSelect,
162
- MImage,
163
- MCombobox,
164
- MFilePicker,
165
- MFormGroup,
166
- MFormErrors,
167
- MSteps,
168
- MPagination,
169
- })) {
116
+ const { components, ...services } = options
117
+ createMavisServices(services).install(app)
118
+ if (components === false) return
119
+ for (const [name, component] of Object.entries(
120
+ components ?? {
121
+ MThemeProvider,
122
+ MSpan,
123
+ MScreen,
124
+ MBox,
125
+ MRow,
126
+ MColumn,
127
+ MStack,
128
+ MGrid,
129
+ MLink,
130
+ MCard,
131
+ MText,
132
+ MButton,
133
+ MSlider,
134
+ MSwitch,
135
+ MCheckbox,
136
+ MRadioGroup,
137
+ MSelect,
138
+ MToast,
139
+ MDialog,
140
+ MTabs,
141
+ MSkeleton,
142
+ MChip,
143
+ MEmptyState,
144
+ MProgress,
145
+ MAccordion,
146
+ MSegmentedControl,
147
+ MAlert,
148
+ MListItem,
149
+ MSeparator,
150
+ MAvatar,
151
+ MBadge,
152
+ MInput,
153
+ MIcon,
154
+ MReveal,
155
+ MSheet,
156
+ MDatePicker,
157
+ MDateRangePicker,
158
+ MNumberInput,
159
+ MMultiSelect,
160
+ MImage,
161
+ MCombobox,
162
+ MFilePicker,
163
+ MFormGroup,
164
+ MFormErrors,
165
+ MSteps,
166
+ MPagination,
167
+ },
168
+ )) {
170
169
  app.component(name, component)
171
170
  }
172
171
  },
@@ -174,3 +173,4 @@ export function createMavis(options: MavisOptions = {}) {
174
173
  }
175
174
 
176
175
  export * from './files.js'
176
+ export { formatDateTime, dateTimeToCivilDate } from './date-format.js'
@@ -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
+ }
@@ -0,0 +1,33 @@
1
+ import { iconOptionsKey, type MavisIconOptions } from './icons.js'
2
+ export type { MavisIconOptions } from './icons.js'
3
+ import type { App } from 'vue'
4
+ import type { MavisNavigation } from '@getcortexlabs/mavis-core'
5
+ import {
6
+ createThemeContext,
7
+ installAppToast,
8
+ themeKey,
9
+ navigationKey,
10
+ type ThemeContextOptions,
11
+ } from '@getcortexlabs/mavis-core/vue'
12
+ import { systemAppearance } from './appearance.js'
13
+
14
+ export type MavisServiceOptions = Omit<ThemeContextOptions, 'source'> &
15
+ MavisIconOptions & {
16
+ toast?: { closeLabel?: string }
17
+ navigation?: MavisNavigation
18
+ }
19
+
20
+ /** Application-owned services without global component registration. */
21
+ export function createMavisServices(options: MavisServiceOptions = {}) {
22
+ return {
23
+ install(app: App) {
24
+ installAppToast(app, options.toast)
25
+ const { toast: _toast, icons, iconFallback, navigation, ...theme } = options
26
+ const context = createThemeContext({ ...theme, source: systemAppearance() })
27
+ app.provide(themeKey, context)
28
+ app.provide(iconOptionsKey, { icons, iconFallback })
29
+ app.provide(navigationKey, navigation)
30
+ app.onUnmount(() => context.dispose())
31
+ },
32
+ }
33
+ }