@getcortexlabs/create-mavis 0.1.0-rc.14 → 0.1.0-rc.16

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 (69) hide show
  1. package/README.md +21 -28
  2. package/package.json +2 -4
  3. package/src/adapters.mjs +45 -23
  4. package/src/add-desktop.mjs +354 -0
  5. package/src/capabilities.mjs +233 -134
  6. package/src/cli.mjs +64 -60
  7. package/src/desktop.mjs +155 -0
  8. package/src/doctor.mjs +77 -108
  9. package/src/native-framework.mjs +144 -0
  10. package/src/portability.mjs +7 -106
  11. package/src/scaffold.mjs +36 -12
  12. package/src/shared-api.mjs +3 -0
  13. package/src/ui.mjs +30 -42
  14. package/templates/desktop/common/LICENSE +21 -0
  15. package/templates/desktop/common/build.mjs +49 -0
  16. package/templates/desktop/common/src/components.ts +60 -0
  17. package/templates/desktop/common/src/contract.mjs +35 -0
  18. package/templates/desktop/common/src/renderer.ts +76 -0
  19. package/templates/desktop/common/src/storage.ts +29 -0
  20. package/templates/desktop/directory/main.ts +35 -0
  21. package/templates/desktop/macos/launch.mjs +6 -0
  22. package/templates/desktop/macos/package.mjs +114 -0
  23. package/templates/desktop/macos/src/host.mjs +471 -0
  24. package/templates/desktop/welcome/Welcome.vue +56 -0
  25. package/templates/desktop/welcome/main.ts +24 -0
  26. package/templates/desktop/windows/NativeScript-LICENSE +19 -0
  27. package/templates/desktop/windows/launch.mjs +16 -0
  28. package/templates/desktop/windows/package.mjs +54 -0
  29. package/templates/desktop/windows/prepare-host.mjs +73 -0
  30. package/templates/desktop/windows/src/host.mjs +294 -0
  31. package/templates/native-framework/angular/screen.ts +84 -0
  32. package/templates/native-framework/common/nativescript.config.ts +6 -0
  33. package/templates/native-framework/common/src/app.ts +5 -0
  34. package/templates/native-framework/common/src/model.ts +40 -0
  35. package/templates/native-framework/common/src/references.d.ts +8 -0
  36. package/templates/native-framework/common/tsconfig.json +16 -0
  37. package/templates/native-framework/common/webpack.config.js +67 -0
  38. package/templates/native-framework/plain/screen.ts +102 -0
  39. package/templates/native-framework/react/screen.ts +83 -0
  40. package/templates/native-framework/solid/screen.ts +111 -0
  41. package/templates/native-framework/svelte/Welcome.svelte +26 -0
  42. package/templates/native-framework/svelte/screen.ts +14 -0
  43. package/templates/native-framework/svelte-tooling/svelte.config.js +20 -0
  44. package/src/add-macos.mjs +0 -386
  45. package/src/macos-capabilities.generated.mjs +0 -4190
  46. package/src/macos.mjs +0 -394
  47. package/src/migrate-directory.mjs +0 -121
  48. package/templates/directory/macos/DirectoryStorage.swift +0 -68
  49. package/templates/macos/examples/tasks/shared/TaskDetail.lite.tsx +0 -57
  50. package/templates/macos/examples/tasks/shared/TaskRow.lite.tsx +0 -33
  51. package/templates/macos/examples/tasks/shared/Tasks.lite.tsx +0 -251
  52. package/templates/macos/examples/tasks/shared/types.ts +0 -10
  53. package/templates/macos/mobile/src/App.vue +0 -14
  54. package/templates/macos/mobile/src/app.ts +0 -7
  55. package/templates/macos/native/Package.swift +0 -19
  56. package/templates/macos/native/Sources/MavisDesktop/App.swift +0 -35
  57. package/templates/macos/native/Sources/MavisDesktop/Fonts/LICENSE +0 -45
  58. package/templates/macos/native/Sources/MavisDesktop/Fonts/lucide.ttf +0 -0
  59. package/templates/macos/root/tsconfig.json +0 -14
  60. package/templates/macos/scripts/generate.mjs +0 -13
  61. package/templates/macos/scripts/macos-manifest.mjs +0 -33
  62. package/templates/macos/scripts/macos.mjs +0 -58
  63. package/templates/macos/shared/Welcome.lite.tsx +0 -42
  64. package/templates/macos/web/index.html +0 -12
  65. package/templates/macos/web/src/main.js +0 -212
  66. package/templates/macos/web/src/mavis.js +0 -2
  67. package/templates/macos/web/src/style.css +0 -14
  68. package/templates/macos/web/vite.config.mjs +0 -14
  69. package/templates/migrations/directory-rc13.json +0 -36
@@ -0,0 +1,73 @@
1
+ import { execFileSync } from 'node:child_process'
2
+ import {
3
+ copyFileSync,
4
+ existsSync,
5
+ mkdirSync,
6
+ readFileSync,
7
+ readdirSync,
8
+ writeFileSync,
9
+ } from 'node:fs'
10
+ import { dirname, join, resolve } from 'node:path'
11
+ import { fileURLToPath } from 'node:url'
12
+
13
+ export function findManifestTool() {
14
+ const kits = join(
15
+ process.env['ProgramFiles(x86)'] ?? 'C:/Program Files (x86)',
16
+ 'Windows Kits/10/bin',
17
+ )
18
+ let manifestTool = process.env.MAVIS_MT
19
+ if (!manifestTool && existsSync(kits)) {
20
+ for (const version of readdirSync(kits).sort((a, b) =>
21
+ b.localeCompare(a, undefined, { numeric: true }),
22
+ )) {
23
+ for (const arch of [process.arch === 'arm64' ? 'arm64' : 'x64', 'x64']) {
24
+ const candidate = join(kits, version, arch, 'mt.exe')
25
+ if (existsSync(candidate)) {
26
+ manifestTool = candidate
27
+ break
28
+ }
29
+ }
30
+ if (manifestTool) break
31
+ }
32
+ }
33
+ return manifestTool && existsSync(manifestTool) ? manifestTool : undefined
34
+ }
35
+
36
+ /** XAML Islands require a manifest on the executable hosting Node-API. */
37
+ export function prepareWindowsHost(destination) {
38
+ if (process.platform !== 'win32') throw new Error('Build and run the Windows app on Windows.')
39
+ const executable = resolve(destination)
40
+ const stamp = `${executable}.json`
41
+ const identity = JSON.stringify({ node: process.version, arch: process.arch, manifest: 1 })
42
+ if (existsSync(executable) && existsSync(stamp) && readFileSync(stamp, 'utf8') === identity)
43
+ return executable
44
+ const manifestTool = findManifestTool()
45
+ if (!manifestTool)
46
+ throw new Error('Install the Windows 10/11 SDK (Manifest Tool), or set MAVIS_MT to mt.exe.')
47
+ mkdirSync(dirname(executable), { recursive: true })
48
+ copyFileSync(process.execPath, executable)
49
+ const manifest = `${executable}.manifest`
50
+ execFileSync(manifestTool, ['-nologo', `-inputresource:${executable};#1`, `-out:${manifest}`])
51
+ const bytes = readFileSync(manifest)
52
+ let xml = bytes
53
+ .toString(bytes[0] === 255 && bytes[1] === 254 ? 'utf16le' : 'utf8')
54
+ .replace(/^\uFEFF/, '')
55
+ const maximum = '<maxversiontested Id="10.0.18362.0"/>'
56
+ if (/<maxversiontested\b[^>]*\/>/.test(xml))
57
+ xml = xml.replace(/<maxversiontested\b[^>]*\/>/, maximum)
58
+ else if (/<compatibility\b/.test(xml))
59
+ xml = xml.replace(/(<compatibility\b[\s\S]*?)(<\/application>)/, `$1${maximum}$2`)
60
+ else
61
+ xml = xml.replace(
62
+ '</assembly>',
63
+ `<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"><application>${maximum}</application></compatibility></assembly>`,
64
+ )
65
+ if (!xml.includes(maximum)) throw new Error('Cannot add XAML compatibility to the Node manifest.')
66
+ writeFileSync(manifest, xml)
67
+ execFileSync(manifestTool, ['-nologo', '-manifest', manifest, `-outputresource:${executable};#1`])
68
+ writeFileSync(stamp, identity)
69
+ return executable
70
+ }
71
+
72
+ if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url))
73
+ console.log(prepareWindowsHost(process.argv[2] ?? '.mavis/runtime/node.exe'))
@@ -0,0 +1,294 @@
1
+ import { windowsMotion } from '@rafaelaugusto/jolt/windows'
2
+ import { nativeProps } from './contract.mjs'
3
+ import { createRequire } from 'node:module'
4
+ import { mavis, midnight } from '@getcortexlabs/mavis-core'
5
+ const { Windows, XamlWindow, native } = createRequire(import.meta.url)('@nativescript/windows-napi')
6
+ const Xaml = Windows.UI.Xaml
7
+ const C = Xaml.Controls
8
+ const emit = (listener, ...args) => {
9
+ for (const fn of Array.isArray(listener) ? listener : [listener])
10
+ if (typeof fn === 'function') fn(...args)
11
+ }
12
+ const text = (node) => node.text || node.children.map(text).join('')
13
+ const brush = (hex) => {
14
+ const value = Number.parseInt(hex.replace('#', '').slice(0, 6), 16)
15
+ return new Xaml.Media.SolidColorBrush(
16
+ Windows.UI.ColorHelper.FromArgb(255, value >> 16, (value >> 8) & 255, value & 255),
17
+ )
18
+ }
19
+ const supported = {
20
+ root: [],
21
+ screen: ['scroll'],
22
+ column: ['padding', 'gap'],
23
+ row: ['padding', 'gap'],
24
+ grid: ['minColumnWidth', 'gap'],
25
+ text: ['text', 'as', 'variant', 'tone'],
26
+ input: [
27
+ 'modelValue',
28
+ 'label',
29
+ 'placeholder',
30
+ 'readonly',
31
+ 'disabled',
32
+ 'onUpdate:modelValue',
33
+ 'onSubmit',
34
+ 'onEscape',
35
+ ],
36
+ reveal: ['show'],
37
+ button: ['href', 'text', 'loading', 'loadingText', 'disabled', 'onClick'],
38
+ link: ['href', 'text', 'disabled', 'onClick'],
39
+ card: ['href', 'padding', 'gap', 'onClick', 'disabled'],
40
+ }
41
+
42
+ /** Explicit XAML Islands subset. NativeScript Core mobile widgets are not used on Windows. */
43
+ export function createHost({ title = '__MAVIS_NAME__', onClose = () => {} } = {}) {
44
+ const window = new XamlWindow({ title, theme: 'light' })
45
+ const root = {
46
+ kind: 'root',
47
+ text: '',
48
+ props: {},
49
+ children: [],
50
+ parent: null,
51
+ native: new C.Canvas(),
52
+ }
53
+ root.content = root.native
54
+ window.content = root.native
55
+ window.place({ width: 780, height: 620 })
56
+ const nodes = new Set([root])
57
+ let closed = false,
58
+ scheduled = false,
59
+ timer,
60
+ theme = mavis
61
+ const tokens = (key) => (typeof key === 'number' ? key : (theme.space[key] ?? 0))
62
+ function create(kind) {
63
+ if (!(kind in supported) && !['#text', '#comment'].includes(kind))
64
+ throw new Error(`Windows desktop host does not implement ${kind}`)
65
+ const node = { kind, text: '', props: {}, children: [], parent: null }
66
+ nodes.add(node)
67
+ if (kind[0] === '#') return node
68
+ if (kind === 'text') {
69
+ node.native = new C.TextBlock()
70
+ node.native.TextWrapping = Xaml.TextWrapping.Wrap
71
+ } else if (kind === 'input') {
72
+ node.native = node.editor = new C.TextBox()
73
+ node.native.TextChanged = () => {
74
+ if (!node.updating && !closed) emit(node.props['onUpdate:modelValue'], node.editor.Text)
75
+ }
76
+ node.native.KeyDown = (_sender, event) => {
77
+ if (event.Key === Windows.System.VirtualKey.Enter) emit(node.props.onSubmit)
78
+ if (event.Key === Windows.System.VirtualKey.Escape) emit(node.props.onEscape)
79
+ }
80
+ } else if (['button', 'link', 'card'].includes(kind)) {
81
+ node.native = new C.Button()
82
+ node.native.HorizontalContentAlignment = Xaml.HorizontalAlignment.Stretch
83
+ node.native.Click = () => {
84
+ if (!closed && !node.props.disabled && !node.props.loading) emit(node.props.onClick)
85
+ }
86
+ if (kind === 'card') node.native.Content = node.content = new C.Canvas()
87
+ } else if (kind === 'screen') {
88
+ node.native = new C.ScrollViewer()
89
+ node.native.VerticalScrollBarVisibility = C.ScrollBarVisibility.Auto
90
+ node.native.HorizontalScrollBarVisibility = C.ScrollBarVisibility.Disabled
91
+ node.native.Content = node.content = new C.Canvas()
92
+ } else node.native = new C.Canvas()
93
+ node.content ??= node.native
94
+ if (kind === 'reveal') {
95
+ node.motion = windowsMotion(node.native, Windows)
96
+ node.motion.animate('opacity', 0, { reducedMotion: true })
97
+ }
98
+ node.dispose = () => {
99
+ node.motion?.dispose()
100
+ if (node.editor) {
101
+ node.editor.TextChanged = null
102
+ node.editor.KeyDown = null
103
+ }
104
+ if (['button', 'link', 'card'].includes(kind)) node.native.Click = null
105
+ nodes.delete(node)
106
+ }
107
+ return node
108
+ }
109
+ function update(node) {
110
+ if (!node.native || closed) return
111
+ const p = node.props,
112
+ view = node.native
113
+ for (const key of Object.keys(p))
114
+ if (!nativeProps(node.kind, 'windows').includes(key))
115
+ throw new Error(`Windows desktop host does not implement ${node.kind}.${key}`)
116
+ Xaml.Automation.AutomationProperties.SetAutomationId(view, String(p.id ?? ''))
117
+ if (p.accessibilityLabel)
118
+ Xaml.Automation.AutomationProperties.SetName(view, String(p.accessibilityLabel))
119
+ if (node.kind === 'text') {
120
+ view.Text = String(p.text ?? text(node))
121
+ view.FontSize = { title: 28, heading: 20, caption: 12 }[p.variant] ?? 14
122
+ view.Foreground = brush(theme.colors[p.tone] ?? theme.colors.text)
123
+ }
124
+ if (node.kind === 'input') {
125
+ node.updating = true
126
+ try {
127
+ view.Header = String(p.label ?? '')
128
+ if (view.Text !== String(p.modelValue ?? '')) view.Text = String(p.modelValue ?? '')
129
+ view.PlaceholderText = String(p.placeholder ?? '')
130
+ view.IsReadOnly = Boolean(p.readonly)
131
+ view.IsEnabled = !p.disabled
132
+ } finally {
133
+ node.updating = false
134
+ }
135
+ }
136
+ if (['button', 'link', 'card'].includes(node.kind)) {
137
+ if (node.kind !== 'card')
138
+ view.Content = String(p.loading ? (p.loadingText ?? 'Loading…') : (p.text ?? text(node)))
139
+ view.IsEnabled = !p.disabled && !p.loading
140
+ }
141
+ if (node.kind === 'reveal') {
142
+ const shown = p.show !== false
143
+ if (node.shown !== shown) {
144
+ if (!shown) node.motion.animate('opacity', 0, { reducedMotion: true })
145
+ node.shown = shown
146
+ view.Visibility = shown ? Xaml.Visibility.Visible : Xaml.Visibility.Collapsed
147
+ node.pendingReveal = shown
148
+ }
149
+ }
150
+ if (node.kind === 'screen')
151
+ view.VerticalScrollMode = p.scroll === false ? C.ScrollMode.Disabled : C.ScrollMode.Enabled
152
+ }
153
+ function detachNative(node) {
154
+ const parent = node.attached
155
+ if (parent) {
156
+ const children = parent.content.Children
157
+ // Rebuild from known native children: no reliance on WinRT object wrapper identity.
158
+ children.Clear()
159
+ for (const sibling of parent.children)
160
+ if (sibling !== node && sibling.native) children.Append(sibling.native)
161
+ node.attached = null
162
+ }
163
+ }
164
+ function attach(node, parent) {
165
+ if (!node.native) return
166
+ if (node.attached && node.attached !== parent) detachNative(node)
167
+ parent.content.Children.Clear()
168
+ for (const sibling of parent.children)
169
+ if (sibling.native) parent.content.Children.Append(sibling.native)
170
+ node.attached = parent
171
+ }
172
+ function detach(node) {
173
+ detachNative(node)
174
+ nodes.delete(node)
175
+ }
176
+ function layoutNode(node, x, y, width, viewport) {
177
+ if (!node.native) return 0
178
+ const p = node.props,
179
+ view = node.native
180
+ let height = 0
181
+ width = Math.max(0, width)
182
+ if (node.kind === 'reveal' && !node.shown) height = 0
183
+ else if (node.kind === 'text') {
184
+ view.Width = width
185
+ view.Measure({ Width: width, Height: 100000 })
186
+ height = Math.max(20, view.DesiredSize.Height)
187
+ } else if (node.kind === 'input') height = p.label ? 70 : 40
188
+ else if (['button', 'link'].includes(node.kind)) height = 38
189
+ else {
190
+ const pad = tokens(p.padding ?? (node.kind === 'card' ? 'md' : 'none')),
191
+ gap = tokens(p.gap)
192
+ const children = node.children.filter(
193
+ (child) => child.native && !(child.kind === 'reveal' && !child.shown),
194
+ )
195
+ const columns =
196
+ node.kind === 'grid'
197
+ ? Math.max(
198
+ 1,
199
+ Math.floor((width - pad * 2 + gap) / (Number(p.minColumnWidth ?? 240) + gap)),
200
+ )
201
+ : node.kind === 'row'
202
+ ? Math.max(1, children.length)
203
+ : 1
204
+ const cellWidth = (width - pad * 2 - gap * (columns - 1)) / columns
205
+ let top = pad
206
+ for (let i = 0; i < children.length; i += columns) {
207
+ let rowHeight = 0
208
+ for (let col = 0; col < columns && i + col < children.length; col++)
209
+ rowHeight = Math.max(
210
+ rowHeight,
211
+ layoutNode(children[i + col], pad + col * (cellWidth + gap), top, cellWidth, viewport),
212
+ )
213
+ top += rowHeight + gap
214
+ }
215
+ height = top + pad - (children.length ? gap : 0)
216
+ if (node.kind === 'screen') {
217
+ node.content.Width = width
218
+ node.content.Height = Math.max(viewport, height)
219
+ height = viewport
220
+ }
221
+ if (node.kind === 'card') {
222
+ node.content.Width = Math.max(0, width - 16)
223
+ node.content.Height = height
224
+ height += 16
225
+ }
226
+ }
227
+ if (node.kind !== 'root') {
228
+ C.Canvas.SetLeft(view, x)
229
+ C.Canvas.SetTop(view, y)
230
+ view.Width = width
231
+ view.Height = Math.max(0, height)
232
+ }
233
+ return height
234
+ }
235
+ function layout() {
236
+ if (closed || scheduled) return
237
+ scheduled = true
238
+ queueMicrotask(() => {
239
+ scheduled = false
240
+ if (closed) return
241
+ layoutNode(root, 0, 0, root.native.ActualWidth || 780, root.native.ActualHeight || 620)
242
+ for (const node of nodes) {
243
+ if (node.pendingReveal && node.attached) {
244
+ node.pendingReveal = false
245
+ node.revealPlayback = node.motion.animate('opacity', 1)
246
+ }
247
+ }
248
+ })
249
+ }
250
+ root.native.SizeChanged = layout
251
+ function setTheme(dark) {
252
+ theme = dark ? midnight : mavis
253
+ root.native.RequestedTheme = dark ? Xaml.ElementTheme.Dark : Xaml.ElementTheme.Light
254
+ root.native.Background = brush(theme.colors.background)
255
+ for (const node of nodes) update(node)
256
+ layout()
257
+ }
258
+ function stop() {
259
+ if (closed) return
260
+ closed = true
261
+ clearInterval(timer)
262
+ root.native.SizeChanged = null
263
+ for (const node of nodes) node.dispose?.()
264
+ nodes.clear()
265
+ }
266
+ window.on('closed', () => {
267
+ onClose()
268
+ stop()
269
+ })
270
+ function show() {
271
+ window.show()
272
+ timer = setInterval(() => native.pumpMessages(), 8)
273
+ layout()
274
+ }
275
+ return {
276
+ root,
277
+ window,
278
+ nodes,
279
+ create,
280
+ update,
281
+ attach,
282
+ detach,
283
+ layout,
284
+ show,
285
+ stop,
286
+ setTheme,
287
+ close() {
288
+ window.close()
289
+ },
290
+ get closed() {
291
+ return closed
292
+ },
293
+ }
294
+ }
@@ -0,0 +1,84 @@
1
+ import '@angular/compiler'
2
+ import { Component, signal, ViewChild } from '@angular/core'
3
+ import {
4
+ NativeScriptCommonModule,
5
+ bootstrapApplication,
6
+ runNativeScriptAngularApp,
7
+ } from '@nativescript/angular'
8
+ import { MAVIS_COMPONENTS, MInput } from '@getcortexlabs/mavis-angular-nativescript'
9
+ import { bridge, initial, theme, isolatedTheme, surface } from './model'
10
+
11
+ @Component({
12
+ selector: 'adapter-catalog',
13
+ standalone: true,
14
+ imports: [NativeScriptCommonModule, ...MAVIS_COMPONENTS],
15
+ template: `<Page actionBarHidden="true">
16
+ <MColumn
17
+ id="catalog"
18
+ gap="md"
19
+ padding="lg"
20
+ height="100%"
21
+ [backgroundColor]="background()"
22
+ [theme]="theme"
23
+ >
24
+ <MText id="heading" text="__MAVIS_NAME__" variant="title" [theme]="theme" />
25
+ <MRow id="row" gap="sm"
26
+ ><MButton
27
+ id="action"
28
+ [theme]="theme"
29
+ [text]="'Count ' + state().count"
30
+ [disabled]="state().disabled"
31
+ [loading]="state().loading"
32
+ (click)="update({ count: state().count + 1 })"
33
+ /></MRow>
34
+ <MInput
35
+ id="editor"
36
+ label="Name"
37
+ [theme]="theme"
38
+ [modelValue]="state().value"
39
+ [disabled]="state().disabled"
40
+ (modelValueChange)="update({ value: $event })"
41
+ />
42
+ @if (state().visible) {
43
+ <MBox
44
+ id="motion"
45
+ [width]="100"
46
+ [height]="30"
47
+ backgroundColor="#4f46e5"
48
+ [motionSurface]="surface"
49
+ />
50
+ }
51
+ <MBox padding="md" radius="md" [backgroundColor]="isolated.theme.colors.background"
52
+ ><MText id="isolated" text="Independent theme" [theme]="isolated"
53
+ /></MBox>
54
+ </MColumn>
55
+ </Page>`,
56
+ })
57
+ class Catalog {
58
+ @ViewChild(MInput) input?: MInput
59
+ background = signal(theme.theme.colors.background)
60
+ private offTheme = theme.subscribe(() => this.background.set(theme.theme.colors.background))
61
+ ngOnDestroy() {
62
+ this.offTheme()
63
+ }
64
+ state = signal({ ...initial })
65
+ theme = theme
66
+ isolated = isolatedTheme
67
+ surface = surface
68
+ update = (patch: Partial<typeof initial>) =>
69
+ this.state.update((value) => ({ ...value, ...patch }))
70
+ constructor() {
71
+ bridge.read = this.state
72
+ bridge.update = this.update
73
+ bridge.focus = () => this.input?.focusInput()
74
+ }
75
+ }
76
+ export function start() {
77
+ runNativeScriptAngularApp({
78
+ appModuleBootstrap: async () => {
79
+ const app = await bootstrapApplication(Catalog)
80
+ bridge.dispose = () => app.destroy()
81
+ return app
82
+ },
83
+ })
84
+ }
@@ -0,0 +1,6 @@
1
+ import type { NativeScriptConfig } from '@nativescript/core'
2
+ export default {
3
+ id: 'org.nativescript.__MAVIS_APPID__',
4
+ appPath: 'src',
5
+ appResourcesPath: 'App_Resources',
6
+ } satisfies NativeScriptConfig
@@ -0,0 +1,5 @@
1
+ import { Application } from '@nativescript/core'
2
+ import { start } from './screen'
3
+ import { bridge } from './model'
4
+ Application.on(Application.exitEvent, () => bridge.dispose?.())
5
+ start()
@@ -0,0 +1,40 @@
1
+ import { createMavisTheme } from '@getcortexlabs/mavis/native'
2
+ import { mavis, midnight } from '@getcortexlabs/mavis-core'
3
+ import { createMotionSurface } from '@getcortexlabs/mavis-core/experimental'
4
+
5
+ export type State = {
6
+ value: string
7
+ count: number
8
+ disabled: boolean
9
+ loading: boolean
10
+ visible: boolean
11
+ }
12
+ export const initial: State = {
13
+ value: 'Ada',
14
+ count: 0,
15
+ disabled: false,
16
+ loading: false,
17
+ visible: true,
18
+ }
19
+ export const theme = createMavisTheme(__MAVIS_THEME__)
20
+ export const isolatedTheme = createMavisTheme(midnight)
21
+ export const surface = createMotionSurface()
22
+ export const lifecycle = { active: 0, attached: 0, animations: 0 }
23
+ surface.use((motion) => {
24
+ lifecycle.active++
25
+ lifecycle.attached++
26
+ const animation = motion.animate({ opacity: [0.7, 1] }, { duration: 60 })
27
+ void animation.finished.then(() => {
28
+ lifecycle.animations++
29
+ })
30
+ return () => {
31
+ lifecycle.active--
32
+ animation.stop()
33
+ }
34
+ })
35
+ export const bridge: {
36
+ read?: () => State
37
+ update?: (patch: Partial<State>) => void
38
+ dispose?: () => void
39
+ focus?: () => void
40
+ } = {}
@@ -0,0 +1,8 @@
1
+ /// <reference types="@nativescript/types" />
2
+ /// <reference types="@nativescript/types-ios" />
3
+ /// <reference types="@nativescript/types-android" />
4
+
5
+ declare module '*.svelte' {
6
+ import type { SvelteComponentTyped } from 'svelte'
7
+ export default class Component extends SvelteComponentTyped {}
8
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "strict": true,
7
+ "ignoreDeprecations": "6.0",
8
+ "skipLibCheck": true,
9
+ "experimentalDecorators": true,
10
+ "useDefineForClassFields": false,
11
+ "esModuleInterop": true,
12
+ "lib": ["ES2023", "DOM"],
13
+ "types": ["@nativescript/types"]
14
+ },
15
+ "include": ["src"]
16
+ }
@@ -0,0 +1,67 @@
1
+ const { resolve, dirname } = require('node:path')
2
+ const webpack = require('@nativescript/webpack')
3
+ module.exports = (env) => {
4
+ const framework = '__MAVIS_FRAMEWORK__'
5
+ if (!['plain', 'react', 'angular', 'svelte', 'solid'].includes(framework))
6
+ throw new Error('Unknown framework')
7
+ webpack.init(env)
8
+ webpack.useConfig('typescript')
9
+ webpack.Utils.addCopyRule({
10
+ from: 'lucide.ttf',
11
+ to: 'fonts',
12
+ context: resolve(__dirname, 'node_modules/@getcortexlabs/mavis/fonts'),
13
+ })
14
+ webpack.chainWebpack((config) => {
15
+ config.resolve.alias.set(
16
+ '@nativescript/core',
17
+ resolve(__dirname, 'node_modules/@nativescript/core'),
18
+ )
19
+ config.resolve.alias.set('@rafaelaugusto/jolt$', require.resolve('@rafaelaugusto/jolt'))
20
+ config.resolve.merge({ conditionNames: ['svelte', 'browser', '...'] })
21
+ config.plugin('NoVueInDirectAdapters').use(
22
+ class {
23
+ apply(compiler) {
24
+ compiler.hooks.afterCompile.tap('NoVueInDirectAdapters', (compilation) => {
25
+ for (const module of compilation.modules) {
26
+ const file = module.resource?.replaceAll('\\', '/') ?? ''
27
+ if (
28
+ /\/node_modules\/(vue|@vue|nativescript-vue)\//.test(file) ||
29
+ /\/mavis\/dist\/vue\//.test(file)
30
+ )
31
+ throw new Error(`Direct ${framework} adapter imported Vue: ${file}`)
32
+ }
33
+ })
34
+ }
35
+ },
36
+ )
37
+ config.plugin('DefinePlugin').tap((args) => {
38
+ Object.assign(args[0], {
39
+ __DEV__: 'true',
40
+ __TEST__: 'false',
41
+ __FRAMEWORK__: JSON.stringify(framework),
42
+ __ADAPTER_CHECK__: 'false',
43
+ })
44
+ return args
45
+ })
46
+ // NativeScript's resolver otherwise chooses Solid's nonreactive Node/server condition.
47
+ if (framework === 'solid')
48
+ for (const name of ['solid-js', '@solidjs/signals', '@solidjs/universal']) {
49
+ const manifest = resolve(__dirname, 'node_modules', name, 'package.json')
50
+ const pkg = require(manifest)
51
+ let entry = pkg.exports['.']
52
+ while (typeof entry !== 'string') entry = entry.browser ?? entry.default
53
+ config.resolve.alias.set(`${name}$`, resolve(dirname(manifest), entry))
54
+ }
55
+ if (framework === 'svelte')
56
+ config.module
57
+ .rule('svelte')
58
+ .test(/\.svelte$/)
59
+ .use('svelte-loader')
60
+ .loader('svelte-loader')
61
+ .options({
62
+ compilerOptions: { dev: false, namespace: 'foreign' },
63
+ preprocess: require('./svelte.config.js').preprocess,
64
+ })
65
+ })
66
+ return webpack.resolveConfig()
67
+ }