@getcortexlabs/mavis 0.1.0-rc.12 → 0.1.0-rc.12.2

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 (76) hide show
  1. package/README.md +5 -5
  2. package/dist/native/date-format.android.d.ts +4 -0
  3. package/dist/native/date-format.android.d.ts.map +1 -1
  4. package/dist/native/date-format.android.js +20 -0
  5. package/dist/native/date-format.android.js.map +1 -1
  6. package/dist/native/date-format.d.ts +3 -0
  7. package/dist/native/date-format.d.ts.map +1 -1
  8. package/dist/native/date-format.ios.d.ts +4 -0
  9. package/dist/native/date-format.ios.d.ts.map +1 -1
  10. package/dist/native/date-format.ios.js +18 -0
  11. package/dist/native/date-format.ios.js.map +1 -1
  12. package/dist/native/date-format.js +3 -0
  13. package/dist/native/date-format.js.map +1 -1
  14. package/dist/native/image-crop-common.d.ts +5 -0
  15. package/dist/native/image-crop-common.d.ts.map +1 -0
  16. package/dist/native/image-crop-common.js +36 -0
  17. package/dist/native/image-crop-common.js.map +1 -0
  18. package/dist/native/image-crop.android.d.ts +3 -0
  19. package/dist/native/image-crop.android.d.ts.map +1 -0
  20. package/dist/native/image-crop.android.js +92 -0
  21. package/dist/native/image-crop.android.js.map +1 -0
  22. package/dist/native/image-crop.d.ts +3 -0
  23. package/dist/native/image-crop.d.ts.map +1 -0
  24. package/dist/native/image-crop.ios.d.ts +3 -0
  25. package/dist/native/image-crop.ios.d.ts.map +1 -0
  26. package/dist/native/image-crop.ios.js +68 -0
  27. package/dist/native/image-crop.ios.js.map +1 -0
  28. package/dist/native/image-crop.js +4 -0
  29. package/dist/native/image-crop.js.map +1 -0
  30. package/dist/vue/components/DateCalendar.d.ts +1 -1
  31. package/dist/vue/components/MAccordion.d.ts +1 -1
  32. package/dist/vue/components/MButton.d.ts +5 -5
  33. package/dist/vue/components/MCard.d.ts +1 -1
  34. package/dist/vue/components/MChip.d.ts +1 -1
  35. package/dist/vue/components/MCombobox.d.ts +2 -2
  36. package/dist/vue/components/MDatePicker.d.ts +16 -16
  37. package/dist/vue/components/MDialog.d.ts +2 -2
  38. package/dist/vue/components/MEmptyState.d.ts +1 -1
  39. package/dist/vue/components/MImageCompare.d.ts +1 -1
  40. package/dist/vue/components/MImageViewer.d.ts +5 -5
  41. package/dist/vue/components/MInput.d.ts +3 -3
  42. package/dist/vue/components/MPopover.d.ts +1 -1
  43. package/dist/vue/components/MProgress.d.ts +1 -1
  44. package/dist/vue/components/MRangeSlider.d.ts +1 -1
  45. package/dist/vue/components/MResizablePanels.d.ts +3 -3
  46. package/dist/vue/components/MSelect.d.ts +1 -1
  47. package/dist/vue/components/MStack.d.ts +6 -6
  48. package/dist/vue/components/MTimePicker.d.ts +8 -8
  49. package/dist/vue/components/MTooltip.d.ts +1 -1
  50. package/dist/vue/components/advanced.d.ts +850 -0
  51. package/dist/vue/components/advanced.d.ts.map +1 -0
  52. package/dist/vue/components/advanced.js +214 -0
  53. package/dist/vue/components/advanced.js.map +1 -0
  54. package/dist/vue/components/configurator.d.ts +6 -6
  55. package/dist/vue/components/creative.d.ts +3 -3
  56. package/dist/vue/components/dashboard.d.ts +5 -5
  57. package/dist/vue/components/discovery.d.ts +1 -1
  58. package/dist/vue/components/interactive.d.ts +1 -1
  59. package/dist/vue/components/navigation.d.ts +3 -3
  60. package/dist/vue/components/screen-components.d.ts +5 -5
  61. package/dist/vue/components/wayfinding.d.ts +6 -6
  62. package/dist/vue/components/workflows.d.ts +3 -3
  63. package/dist/vue/index.d.ts +2 -1
  64. package/dist/vue/index.d.ts.map +1 -1
  65. package/dist/vue/index.js +8 -1
  66. package/dist/vue/index.js.map +1 -1
  67. package/package.json +3 -3
  68. package/src/native/date-format.android.ts +22 -0
  69. package/src/native/date-format.ios.ts +22 -0
  70. package/src/native/date-format.ts +7 -0
  71. package/src/native/image-crop-common.ts +46 -0
  72. package/src/native/image-crop.android.ts +140 -0
  73. package/src/native/image-crop.ios.ts +94 -0
  74. package/src/native/image-crop.ts +4 -0
  75. package/src/vue/components/advanced.ts +263 -0
  76. package/src/vue/index.ts +20 -0
@@ -0,0 +1,94 @@
1
+ import { ImageSource } from '@nativescript/core'
2
+ import { cropOutputSize, validateImageCrop, type CropSource } from '@getcortexlabs/mavis-core'
3
+ import { loadSource, saveCrop } from './image-crop-common'
4
+ interface Size {
5
+ width: number
6
+ height: number
7
+ }
8
+ interface Rect {
9
+ origin: { x: number; y: number }
10
+ size: Size
11
+ }
12
+ interface UIImage {
13
+ size: Size
14
+ scale: number
15
+ drawInRect(rect: Rect): void
16
+ }
17
+ declare function UIGraphicsBeginImageContextWithOptions(
18
+ size: Size,
19
+ opaque: boolean,
20
+ scale: number,
21
+ ): void
22
+ declare function UIGraphicsGetImageFromCurrentImageContext(): UIImage | null
23
+ declare function UIGraphicsGetCurrentContext(): unknown
24
+ declare function UIGraphicsEndImageContext(): void
25
+ declare function CGContextScaleCTM(context: unknown, x: number, y: number): void
26
+ declare function CGContextTranslateCTM(context: unknown, x: number, y: number): void
27
+ declare function CGContextRotateCTM(context: unknown, angle: number): void
28
+ declare function CGContextSetRGBFillColor(
29
+ context: unknown,
30
+ r: number,
31
+ g: number,
32
+ b: number,
33
+ a: number,
34
+ ): void
35
+ declare function CGContextFillRect(context: unknown, rect: Rect): void
36
+ const rect = (width: number, height: number): Rect => ({
37
+ origin: { x: 0, y: 0 },
38
+ size: { width, height },
39
+ })
40
+ export async function loadCropImage(src: string): Promise<CropSource> {
41
+ const source = await loadSource(src),
42
+ original = source.ios as UIImage,
43
+ width = Math.round(original.size.width * original.scale),
44
+ height = Math.round(original.size.height * original.scale)
45
+ if (width * height > 40000000)
46
+ throw new RangeError('ImageCropper supports at most 40 megapixels.')
47
+ let image: UIImage | null
48
+ UIGraphicsBeginImageContextWithOptions({ width, height }, false, 1)
49
+ try {
50
+ original.drawInRect(rect(width, height))
51
+ image = UIGraphicsGetImageFromCurrentImageContext()
52
+ } finally {
53
+ UIGraphicsEndImageContext()
54
+ }
55
+ if (!image) throw new Error('Could not normalize the source image.')
56
+ const normalized = image,
57
+ preview = new ImageSource(normalized)
58
+ let disposed = false
59
+ return {
60
+ width,
61
+ height,
62
+ preview,
63
+ dispose() {
64
+ disposed = true
65
+ },
66
+ async export(crop, options) {
67
+ if (disposed) throw new Error('Image source has been released.')
68
+ validateImageCrop({ width, height }, crop)
69
+ const size = cropOutputSize(crop, options)
70
+ let result: UIImage | null
71
+ UIGraphicsBeginImageContextWithOptions(size, false, 1)
72
+ try {
73
+ const context = UIGraphicsGetCurrentContext()
74
+ if (!context) throw new Error('Could not allocate the crop context.')
75
+ if (options.mimeType === 'image/jpeg') {
76
+ CGContextSetRGBFillColor(context, 1, 1, 1, 1)
77
+ CGContextFillRect(context, rect(size.width, size.height))
78
+ }
79
+ CGContextScaleCTM(context, size.width / crop.width, size.height / crop.height)
80
+ CGContextTranslateCTM(context, -crop.x, -crop.y)
81
+ if (crop.rotation === 90) CGContextTranslateCTM(context, height, 0)
82
+ if (crop.rotation === 180) CGContextTranslateCTM(context, width, height)
83
+ if (crop.rotation === 270) CGContextTranslateCTM(context, 0, width)
84
+ CGContextRotateCTM(context, (crop.rotation * Math.PI) / 180)
85
+ normalized.drawInRect(rect(width, height))
86
+ result = UIGraphicsGetImageFromCurrentImageContext()
87
+ } finally {
88
+ UIGraphicsEndImageContext()
89
+ }
90
+ if (!result) throw new Error('Could not render the cropped image.')
91
+ return saveCrop(new ImageSource(result), size.width, size.height, options)
92
+ },
93
+ }
94
+ }
@@ -0,0 +1,4 @@
1
+ import type { CropSource } from '@getcortexlabs/mavis-core'
2
+ export async function loadCropImage(_src: string): Promise<CropSource> {
3
+ throw new Error('Image cropping requires an iOS or Android runtime.')
4
+ }
@@ -0,0 +1,263 @@
1
+ import {
2
+ defineComponent,
3
+ h,
4
+ mergeProps,
5
+ onBeforeUnmount,
6
+ onDeactivated,
7
+ onActivated,
8
+ watch,
9
+ type PropType,
10
+ } from 'nativescript-vue'
11
+ import {
12
+ type View,
13
+ type EventData,
14
+ type PanGestureEventData,
15
+ type PinchGestureEventData,
16
+ Application,
17
+ } from '@nativescript/core'
18
+ import {
19
+ createTreeSelect,
20
+ createMasonry,
21
+ createHeatmap,
22
+ createNotificationCenter,
23
+ createImageCropper,
24
+ createScheduler,
25
+ advancedCanvasProps,
26
+ advancedCellProps,
27
+ advancedGestureProps,
28
+ type AdvancedGesture,
29
+ } from '@getcortexlabs/mavis-core/vue'
30
+ import type { CropSource } from '@getcortexlabs/mavis-core'
31
+ import type { MotionSurface } from '@getcortexlabs/mavis-core/experimental'
32
+ import { loadCropImage } from '../../native/image-crop'
33
+ import { schedulerParts } from '../../native/date-format'
34
+ import { notifyAccessibilityLayout } from '../../native/accessibility-layout'
35
+ import { MBox, MColumn, MRow } from './layout.js'
36
+ import { MStack } from './MStack.js'
37
+ import { MCard } from './MCard.js'
38
+ import { MText } from './MText.js'
39
+ import { MButton } from './MButton.js'
40
+ import { MInput } from './MInput.js'
41
+ import { MImage } from './MImage.js'
42
+ import { MCheckbox } from './MCheckbox.js'
43
+ import { MSlider } from './MSlider.js'
44
+ import { MPopover } from './MPopover.js'
45
+
46
+ const Host = defineComponent({
47
+ inheritAttrs: false,
48
+ props: { label: String },
49
+ setup(props, { attrs, slots, expose }) {
50
+ let view: View | undefined
51
+ expose({
52
+ focus(id?: string) {
53
+ const target = (id ? view?.getViewById(id) : view) as View | undefined
54
+ if (target) {
55
+ target.focus()
56
+ notifyAccessibilityLayout(target)
57
+ }
58
+ },
59
+ })
60
+ return () =>
61
+ h(
62
+ 'GridLayout',
63
+ mergeProps(attrs, {
64
+ width: '100%',
65
+ accessibilityLabel: props.label,
66
+ onLoaded: (e: EventData) => (view = e.object as View),
67
+ onUnloaded: () => (view = undefined),
68
+ }),
69
+ slots.default?.(),
70
+ )
71
+ },
72
+ })
73
+ const Measure = defineComponent({
74
+ emits: ['width'],
75
+ setup(_, { slots, emit }) {
76
+ let last = -1
77
+ const measure = (e: EventData) => {
78
+ const width = (e.object as View).getActualSize().width
79
+ if (Number.isFinite(width) && width > 0 && Math.abs(width - last) > 0.5) {
80
+ last = width
81
+ emit('width', width)
82
+ }
83
+ }
84
+ return () => h('GridLayout', { width: '100%', onLayoutChanged: measure }, slots.default?.())
85
+ },
86
+ })
87
+ const Canvas = defineComponent({
88
+ props: advancedCanvasProps,
89
+ setup(props, { slots }) {
90
+ return () =>
91
+ h('AbsoluteLayout', { width: props.width ?? '100%', height: props.height }, slots.default?.())
92
+ },
93
+ })
94
+ const Cell = defineComponent({
95
+ inheritAttrs: false,
96
+ props: advancedCellProps,
97
+ emits: ['height'],
98
+ setup(props, { attrs, slots, emit }) {
99
+ let last = -1
100
+ const measure = (e: EventData) => {
101
+ if (!props.measure) return
102
+ const height = (e.object as View).getActualSize().height
103
+ if (Number.isFinite(height) && height >= 0 && Math.abs(height - last) > 0.5) {
104
+ last = height
105
+ emit('height', height)
106
+ }
107
+ }
108
+ return () =>
109
+ h(
110
+ 'GridLayout',
111
+ mergeProps(attrs, {
112
+ left: props.x,
113
+ top: props.y,
114
+ width: props.width,
115
+ height: props.height,
116
+ verticalAlignment: 'top',
117
+ }),
118
+ [h(MBox, { width: '100%', height: props.height, onLayoutChanged: measure }, slots)],
119
+ )
120
+ },
121
+ })
122
+ const Scroll = defineComponent({
123
+ setup(_, { slots }) {
124
+ return () =>
125
+ h(
126
+ 'ScrollView',
127
+ { orientation: 'horizontal', width: '100%', scrollBarIndicatorVisible: true },
128
+ [h('StackLayout', { orientation: 'horizontal' }, slots.default?.())],
129
+ )
130
+ },
131
+ })
132
+ const Gesture = defineComponent({
133
+ inheritAttrs: false,
134
+ props: advancedGestureProps,
135
+ emits: ['gesture', 'step'],
136
+ setup(props, { attrs, slots, emit }) {
137
+ const active = new Set<string>()
138
+ let last = { x: 0, y: 0, scale: 1 }
139
+ function send(phase: AdvancedGesture['phase']) {
140
+ emit('gesture', { phase, ...last })
141
+ }
142
+ function cancel() {
143
+ if (active.size) send('cancel')
144
+ active.clear()
145
+ last = { x: 0, y: 0, scale: 1 }
146
+ }
147
+ function update(name: string, state: number, value: Partial<typeof last>) {
148
+ if (props.disabled) return
149
+ if (state === 1) {
150
+ if (!active.size) {
151
+ last = { x: 0, y: 0, scale: 1 }
152
+ send('start')
153
+ }
154
+ active.add(name)
155
+ }
156
+ if (state === 2 && active.has(name)) {
157
+ last = { ...last, ...value }
158
+ send('move')
159
+ }
160
+ if (state === 3 && active.has(name)) {
161
+ active.delete(name)
162
+ if (!active.size) {
163
+ send('end')
164
+ last = { x: 0, y: 0, scale: 1 }
165
+ }
166
+ }
167
+ if (state === 4) cancel()
168
+ }
169
+ let listening = false
170
+ function loaded() {
171
+ if (listening) return
172
+ listening = true
173
+ Application.on(Application.suspendEvent, cancel)
174
+ }
175
+ function unloaded() {
176
+ listening = false
177
+ cancel()
178
+ Application.off(Application.suspendEvent, cancel)
179
+ }
180
+ onBeforeUnmount(unloaded)
181
+ onDeactivated(unloaded)
182
+ onActivated(loaded)
183
+ watch(() => props.disabled, cancel)
184
+ return () =>
185
+ h(
186
+ 'GridLayout',
187
+ mergeProps(attrs, {
188
+ accessibilityLabel: props.label,
189
+ accessible: true,
190
+ isEnabled: !props.disabled,
191
+ onLoaded: loaded,
192
+ onUnloaded: unloaded,
193
+ onPan: (e: PanGestureEventData) => update('pan', e.state, { x: e.deltaX, y: e.deltaY }),
194
+ onPinch: (e: PinchGestureEventData) => update('pinch', e.state, { scale: e.scale }),
195
+ onTouch: (e: { action: string }) => {
196
+ if (e.action === 'cancel') cancel()
197
+ },
198
+ }),
199
+ slots.default?.(),
200
+ )
201
+ },
202
+ })
203
+ const CropPreview = defineComponent({
204
+ props: {
205
+ source: { type: Object as PropType<CropSource>, required: true },
206
+ width: Number,
207
+ height: Number,
208
+ motionSurface: Object as PropType<MotionSurface>,
209
+ },
210
+ setup(props) {
211
+ return () =>
212
+ h('AbsoluteLayout', { width: '100%', height: '100%', isUserInteractionEnabled: false }, [
213
+ h(
214
+ MBox,
215
+ {
216
+ left: 0,
217
+ top: 0,
218
+ width: props.width,
219
+ height: props.height,
220
+ motionSurface: props.motionSurface,
221
+ },
222
+ () =>
223
+ h('Image', {
224
+ src: props.source!.preview,
225
+ width: props.width,
226
+ height: props.height,
227
+ stretch: 'fill',
228
+ accessible: false,
229
+ }),
230
+ ),
231
+ ])
232
+ },
233
+ })
234
+ const ui = {
235
+ Box: MBox,
236
+ Column: MColumn,
237
+ Row: MRow,
238
+ Stack: MStack,
239
+ Card: MCard,
240
+ Text: MText,
241
+ Button: MButton,
242
+ Input: MInput,
243
+ Image: MImage,
244
+ Checkbox: MCheckbox,
245
+ Slider: MSlider,
246
+ Popover: MPopover,
247
+ Segmented: MBox,
248
+ Host,
249
+ Measure,
250
+ Cell,
251
+ Canvas,
252
+ Scroll,
253
+ Gesture,
254
+ CropPreview,
255
+ }
256
+ export const MTreeSelect = createTreeSelect(ui, 'native')
257
+ export const MMasonry = createMasonry(ui, 'native')
258
+ export const MHeatmap = createHeatmap(ui, 'native')
259
+ export const MNotificationCenter = createNotificationCenter(ui, 'native')
260
+ export const MImageCropper = createImageCropper(ui, 'native', loadCropImage)
261
+ export const MScheduler = createScheduler(ui, 'native', {
262
+ parts: (instant, timeZone) => schedulerParts(instant, { timeZone }),
263
+ })
package/src/vue/index.ts CHANGED
@@ -1,3 +1,11 @@
1
+ import {
2
+ MTreeSelect,
3
+ MMasonry,
4
+ MHeatmap,
5
+ MImageCropper,
6
+ MScheduler,
7
+ MNotificationCenter,
8
+ } from './components/advanced.js'
1
9
  import {
2
10
  MKanban,
3
11
  MDonutChart,
@@ -90,6 +98,12 @@ import { MSheet } from './components/MSheet.js'
90
98
  import type { ClaimSystemBack, SystemBackClaimant } from './system-back.js'
91
99
 
92
100
  export {
101
+ MTreeSelect,
102
+ MMasonry,
103
+ MHeatmap,
104
+ MImageCropper,
105
+ MScheduler,
106
+ MNotificationCenter,
93
107
  MKanban,
94
108
  MDonutChart,
95
109
  MSparkline,
@@ -216,6 +230,12 @@ export function createMavis(options: MavisOptions = {}) {
216
230
  if (components === false) return
217
231
  for (const [name, component] of Object.entries(
218
232
  components ?? {
233
+ MTreeSelect,
234
+ MMasonry,
235
+ MHeatmap,
236
+ MImageCropper,
237
+ MScheduler,
238
+ MNotificationCenter,
219
239
  MKanban,
220
240
  MDonutChart,
221
241
  MSparkline,