@m3ui-vue/m3ui-vue 1.2.2 → 1.3.1

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 (241) hide show
  1. package/dist/API.md +3010 -376
  2. package/dist/MButton-Bl_BSUep.js +172 -0
  3. package/dist/MButton-Bl_BSUep.js.map +1 -0
  4. package/dist/MDialog-D_Yik8ou.js +173 -0
  5. package/dist/MDialog-D_Yik8ou.js.map +1 -0
  6. package/dist/MIconButton-DoNotQ9v.js +282 -0
  7. package/dist/MIconButton-DoNotQ9v.js.map +1 -0
  8. package/dist/MListItem-BxifHJdU.js +824 -0
  9. package/dist/MListItem-BxifHJdU.js.map +1 -0
  10. package/dist/MLoadingIndicator-BxbFhSX6.js +115 -0
  11. package/dist/MLoadingIndicator-BxbFhSX6.js.map +1 -0
  12. package/dist/MMenuItem-Bih0h4-n.js +604 -0
  13. package/dist/MMenuItem-Bih0h4-n.js.map +1 -0
  14. package/dist/MProgressBar-BCoruxA-.js +184 -0
  15. package/dist/MProgressBar-BCoruxA-.js.map +1 -0
  16. package/dist/MSeekBar-BeN9QcB3.js +435 -0
  17. package/dist/MSeekBar-BeN9QcB3.js.map +1 -0
  18. package/dist/MSegmentedButton-DL9JtJFX.js +65 -0
  19. package/dist/MSegmentedButton-DL9JtJFX.js.map +1 -0
  20. package/dist/MSlider-BVSbJlGS.js +691 -0
  21. package/dist/MSlider-BVSbJlGS.js.map +1 -0
  22. package/dist/MSpinner-C2SUnWk4.js +65 -0
  23. package/dist/MSpinner-C2SUnWk4.js.map +1 -0
  24. package/dist/MTextField-CEkWSZ2v.js +296 -0
  25. package/dist/MTextField-CEkWSZ2v.js.map +1 -0
  26. package/dist/MTooltip-CodJGEO-.js +756 -0
  27. package/dist/MTooltip-CodJGEO-.js.map +1 -0
  28. package/dist/_storageKeys-CYXsUBwK.js +18 -0
  29. package/dist/_storageKeys-CYXsUBwK.js.map +1 -0
  30. package/dist/_useEscapeStack-CjndQhqg.js +19 -0
  31. package/dist/_useEscapeStack-CjndQhqg.js.map +1 -0
  32. package/dist/api.json +1 -1
  33. package/dist/chart.js +1 -1
  34. package/dist/code-editor.js +1 -1
  35. package/dist/components/MAudioPlayer.vue.d.ts +115 -0
  36. package/dist/components/MBadge.vue.d.ts +1 -1
  37. package/dist/components/MBottomSheetScaffold.vue.d.ts +1 -1
  38. package/dist/components/MBox.vue.d.ts +1 -1
  39. package/dist/components/MButton.vue.d.ts +1 -1
  40. package/dist/components/MConfirmDialog.vue.d.ts +1 -1
  41. package/dist/components/MCopyButton.vue.d.ts +2 -2
  42. package/dist/components/MDataTable.vue.d.ts +2 -2
  43. package/dist/components/MDialog.vue.d.ts +2 -2
  44. package/dist/components/MDivider.vue.d.ts +1 -1
  45. package/dist/components/MDragHandle.vue.d.ts +1 -1
  46. package/dist/components/MDrawCanvas.vue.d.ts +150 -0
  47. package/dist/components/MDrawLayers.vue.d.ts +3 -0
  48. package/dist/components/MDrawToolbar.vue.d.ts +34 -0
  49. package/dist/components/MExportButton.vue.d.ts +1 -1
  50. package/dist/components/MFab.vue.d.ts +2 -2
  51. package/dist/components/MFabMenu.vue.d.ts +2 -2
  52. package/dist/components/MFixed.vue.d.ts +1 -1
  53. package/dist/components/MFlex.vue.d.ts +2 -2
  54. package/dist/components/MFloorPlan.vue.d.ts +248 -0
  55. package/dist/components/MFloorPlanInspector.vue.d.ts +56 -0
  56. package/dist/components/MFloorPlanToolbar.vue.d.ts +51 -0
  57. package/dist/components/MFlow.vue.d.ts +318 -0
  58. package/dist/components/MFlowControls.vue.d.ts +33 -0
  59. package/dist/components/MFlowHandle.vue.d.ts +16 -0
  60. package/dist/components/MFlowMinimap.vue.d.ts +22 -0
  61. package/dist/components/MFlowNode.vue.d.ts +35 -0
  62. package/dist/components/MGantt.vue.d.ts +141 -0
  63. package/dist/components/MGanttControls.vue.d.ts +32 -0
  64. package/dist/components/MIconButton.vue.d.ts +3 -1
  65. package/dist/components/MImageCropper.vue.d.ts +110 -0
  66. package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
  67. package/dist/components/MLightbox.vue.d.ts +2 -2
  68. package/dist/components/MList.vue.d.ts +1 -1
  69. package/dist/components/MLoadingOverlay.vue.d.ts +1 -1
  70. package/dist/components/MMapControl.vue.d.ts +1 -1
  71. package/dist/components/MMapSearch.vue.d.ts +1 -1
  72. package/dist/components/MMaskField.vue.d.ts +12 -1
  73. package/dist/components/MMenu.vue.d.ts +1 -1
  74. package/dist/components/MNavigationDrawer.vue.d.ts +1 -1
  75. package/dist/components/MNumberField.vue.d.ts +11 -2
  76. package/dist/components/MPdfViewer.vue.d.ts +174 -0
  77. package/dist/components/MPullToRefresh.vue.d.ts +1 -1
  78. package/dist/components/MResourceTimeline.vue.d.ts +149 -0
  79. package/dist/components/MScheduler.vue.d.ts +3 -3
  80. package/dist/components/MScheme.vue.d.ts +1 -1
  81. package/dist/components/MSearchField.vue.d.ts +1 -1
  82. package/dist/components/MSeekBar.vue.d.ts +1 -1
  83. package/dist/components/MSimpleCarousel.vue.d.ts +1 -1
  84. package/dist/components/MSkeleton.vue.d.ts +1 -1
  85. package/dist/components/MSlider.vue.d.ts +2 -2
  86. package/dist/components/MSparkline.vue.d.ts +1 -1
  87. package/dist/components/MSplitter.vue.d.ts +1 -1
  88. package/dist/components/MStack.vue.d.ts +2 -2
  89. package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
  90. package/dist/components/MSwitch.vue.d.ts +1 -1
  91. package/dist/components/MTable.vue.d.ts +1 -1
  92. package/dist/components/MTagInput.vue.d.ts +12 -1
  93. package/dist/components/MTextField.vue.d.ts +13 -2
  94. package/dist/components/MToolbar.vue.d.ts +1 -1
  95. package/dist/components/MTree.vue.d.ts +2 -2
  96. package/dist/components/MVideoPlayer.vue.d.ts +253 -0
  97. package/dist/components/MVirtualTable.vue.d.ts +1 -1
  98. package/dist/components/MWindow.vue.d.ts +3 -3
  99. package/dist/components/_MFlowEdge.vue.d.ts +9 -0
  100. package/dist/components/_MFlowEdgeLabel.vue.d.ts +9 -0
  101. package/dist/components/_MFlowNodeShell.vue.d.ts +9 -0
  102. package/dist/components/_MPdfPage.vue.d.ts +76 -0
  103. package/dist/components/_MTimeBackground.vue.d.ts +14 -0
  104. package/dist/components/_MTimeHeader.vue.d.ts +20 -0
  105. package/dist/composables/_flowPanel.d.ts +2 -0
  106. package/dist/composables/_flowSlot.d.ts +5 -0
  107. package/dist/composables/_ganttTime.d.ts +41 -0
  108. package/dist/composables/_useTimeAxis.d.ts +90 -0
  109. package/dist/composables/drawGeometry.d.ts +119 -0
  110. package/dist/composables/flowFormats.d.ts +79 -0
  111. package/dist/composables/flowLayout.d.ts +45 -0
  112. package/dist/composables/flowPaths.d.ts +53 -0
  113. package/dist/composables/ganttFormats.d.ts +52 -0
  114. package/dist/composables/ganttSchedule.d.ts +99 -0
  115. package/dist/composables/useDrawing.d.ts +44 -0
  116. package/dist/composables/useFloorPlan.d.ts +58 -0
  117. package/dist/composables/useFlow.d.ts +266 -0
  118. package/dist/composables/useGantt.d.ts +87 -0
  119. package/dist/composables/useLocale.d.ts +204 -0
  120. package/dist/composables/useMediaPlayer.d.ts +101 -0
  121. package/dist/composables/usePdf.d.ts +119 -0
  122. package/dist/composables/useResourceTimeline.d.ts +70 -0
  123. package/dist/draw.d.ts +7 -0
  124. package/dist/draw.js +1702 -0
  125. package/dist/draw.js.map +1 -0
  126. package/dist/flow.d.ts +14 -0
  127. package/dist/flow.js +3547 -0
  128. package/dist/flow.js.map +1 -0
  129. package/dist/flowPaths-CUc6X373.js +161 -0
  130. package/dist/flowPaths-CUc6X373.js.map +1 -0
  131. package/dist/gantt.d.ts +12 -0
  132. package/dist/gantt.js +3575 -0
  133. package/dist/gantt.js.map +1 -0
  134. package/dist/index.d.ts +9 -0
  135. package/dist/locales/index.js +1435 -7
  136. package/dist/locales/index.js.map +1 -1
  137. package/dist/m3ui-vue.css +1 -1
  138. package/dist/m3ui.js +8248 -7637
  139. package/dist/m3ui.js.map +1 -1
  140. package/dist/map.js +113 -108
  141. package/dist/map.js.map +1 -1
  142. package/dist/media.d.ts +5 -0
  143. package/dist/media.js +1311 -0
  144. package/dist/media.js.map +1 -0
  145. package/dist/pdf.d.ts +4 -0
  146. package/dist/pdf.js +1871 -0
  147. package/dist/pdf.js.map +1 -0
  148. package/dist/rich-text-editor.js +28 -26
  149. package/dist/rich-text-editor.js.map +1 -1
  150. package/dist/styles.css +1 -1
  151. package/dist/{useLocale-JYxDDeXC.js → useLocale-CaWwi-b6.js} +206 -2
  152. package/dist/useLocale-CaWwi-b6.js.map +1 -0
  153. package/dist/{useThemeTokens-y0HZpyhL.js → useThemeTokens-DQQcaWbE.js} +40 -54
  154. package/dist/useThemeTokens-DQQcaWbE.js.map +1 -0
  155. package/package.json +29 -5
  156. package/src/__tests__/MAudioPlayer.test.ts +75 -0
  157. package/src/__tests__/MDrawCanvas.test.ts +118 -0
  158. package/src/__tests__/MFloorPlan.test.ts +299 -0
  159. package/src/__tests__/MFlow.test.ts +590 -0
  160. package/src/__tests__/MGantt.test.ts +130 -0
  161. package/src/__tests__/MImageCropper.test.ts +89 -0
  162. package/src/__tests__/MPdfViewer.test.ts +235 -0
  163. package/src/__tests__/MResourceTimeline.test.ts +102 -0
  164. package/src/__tests__/MVideoPlayer.test.ts +201 -0
  165. package/src/__tests__/drawGeometry.test.ts +58 -0
  166. package/src/__tests__/fieldExpose.test.ts +30 -0
  167. package/src/__tests__/flowFormats.test.ts +185 -0
  168. package/src/__tests__/flowLayout.test.ts +113 -0
  169. package/src/__tests__/ganttFormats.test.ts +76 -0
  170. package/src/__tests__/ganttSchedule.test.ts +136 -0
  171. package/src/__tests__/pdfMock.ts +83 -0
  172. package/src/__tests__/useMediaPlayer.test.ts +182 -0
  173. package/src/__tests__/usePdf.test.ts +102 -0
  174. package/src/components/MAudioPlayer.vue +319 -0
  175. package/src/components/MDrawCanvas.vue +819 -0
  176. package/src/components/MDrawLayers.vue +114 -0
  177. package/src/components/MDrawToolbar.vue +171 -0
  178. package/src/components/MFloorPlan.vue +1080 -0
  179. package/src/components/MFloorPlanInspector.vue +169 -0
  180. package/src/components/MFloorPlanToolbar.vue +128 -0
  181. package/src/components/MFlow.vue +2060 -0
  182. package/src/components/MFlowControls.vue +110 -0
  183. package/src/components/MFlowHandle.vue +60 -0
  184. package/src/components/MFlowMinimap.vue +134 -0
  185. package/src/components/MFlowNode.vue +98 -0
  186. package/src/components/MGantt.vue +1609 -0
  187. package/src/components/MGanttControls.vue +77 -0
  188. package/src/components/MIconButton.vue +3 -1
  189. package/src/components/MImageCropper.vue +507 -0
  190. package/src/components/MMaskField.vue +13 -0
  191. package/src/components/MNumberField.vue +13 -0
  192. package/src/components/MPdfViewer.vue +1270 -0
  193. package/src/components/MResourceTimeline.vue +1020 -0
  194. package/src/components/MTagInput.vue +13 -0
  195. package/src/components/MTextField.vue +16 -0
  196. package/src/components/MVideoPlayer.vue +839 -0
  197. package/src/components/_MFlowEdge.vue +100 -0
  198. package/src/components/_MFlowEdgeLabel.vue +56 -0
  199. package/src/components/_MFlowNodeShell.vue +111 -0
  200. package/src/components/_MPdfPage.vue +456 -0
  201. package/src/components/_MTimeBackground.vue +16 -0
  202. package/src/components/_MTimeHeader.vue +31 -0
  203. package/src/composables/_flowPanel.ts +13 -0
  204. package/src/composables/_flowSlot.ts +6 -0
  205. package/src/composables/_ganttTime.ts +200 -0
  206. package/src/composables/_useTimeAxis.ts +224 -0
  207. package/src/composables/drawGeometry.ts +405 -0
  208. package/src/composables/flowFormats.ts +916 -0
  209. package/src/composables/flowLayout.ts +297 -0
  210. package/src/composables/flowPaths.ts +239 -0
  211. package/src/composables/ganttFormats.ts +366 -0
  212. package/src/composables/ganttSchedule.ts +403 -0
  213. package/src/composables/useDrawing.ts +53 -0
  214. package/src/composables/useFloorPlan.ts +73 -0
  215. package/src/composables/useFlow.ts +250 -0
  216. package/src/composables/useGantt.ts +92 -0
  217. package/src/composables/useLocale.ts +410 -0
  218. package/src/composables/useMediaPlayer.ts +406 -0
  219. package/src/composables/usePdf.ts +456 -0
  220. package/src/composables/useResourceTimeline.ts +76 -0
  221. package/src/draw.ts +25 -0
  222. package/src/flow.ts +26 -0
  223. package/src/gantt.ts +12 -0
  224. package/src/index.ts +9 -0
  225. package/src/locales/de.ts +204 -0
  226. package/src/locales/es.ts +204 -0
  227. package/src/locales/fr.ts +204 -0
  228. package/src/locales/ja.ts +204 -0
  229. package/src/locales/ko.ts +204 -0
  230. package/src/locales/pt.ts +204 -0
  231. package/src/locales/zh.ts +204 -0
  232. package/src/media.ts +5 -0
  233. package/src/pdf.ts +15 -0
  234. package/dist/MMenuItem-D4Gx_l3F.js +0 -929
  235. package/dist/MMenuItem-D4Gx_l3F.js.map +0 -1
  236. package/dist/MSlider-Dx_S3vJ9.js +0 -1506
  237. package/dist/MSlider-Dx_S3vJ9.js.map +0 -1
  238. package/dist/MTextField-Bz8JIsnl.js +0 -633
  239. package/dist/MTextField-Bz8JIsnl.js.map +0 -1
  240. package/dist/useLocale-JYxDDeXC.js.map +0 -1
  241. package/dist/useThemeTokens-y0HZpyhL.js.map +0 -1
@@ -0,0 +1,201 @@
1
+ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
2
+ import { mount, flushPromises } from '@vue/test-utils'
3
+ import { h, nextTick } from 'vue'
4
+ import MVideoPlayer from '../components/MVideoPlayer.vue'
5
+ import { useMediaPlayer } from '../composables/useMediaPlayer'
6
+
7
+ beforeEach(() => {
8
+ vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockReturnValue({
9
+ left: 0, top: 0, right: 640, bottom: 360, width: 640, height: 360, x: 0, y: 0, toJSON: () => ({}),
10
+ } as DOMRect)
11
+ })
12
+ afterEach(() => {
13
+ vi.useRealTimers()
14
+ vi.restoreAllMocks()
15
+ document.body.innerHTML = ''
16
+ })
17
+
18
+ const surface = (w: ReturnType<typeof mount>) => w.find('.absolute.inset-0[class="absolute inset-0"]').element as HTMLElement
19
+ const pointer = (type: string, x: number, pointerType = 'touch') =>
20
+ new PointerEvent(type, { clientX: x, clientY: 100, pointerId: 1, button: 0, pointerType, bubbles: true })
21
+ const key = (w: ReturnType<typeof mount>, k: string) => w.element.dispatchEvent(new KeyboardEvent('keydown', { key: k, bubbles: true }))
22
+
23
+ // A clock "video" through #media, so nothing depends on happy-dom's media elements
24
+ function clockPlayer(props: Record<string, unknown> = {}) {
25
+ return mount(MVideoPlayer, {
26
+ props: { duration: 100, ...props },
27
+ slots: { media: (p: { time: number }) => h('div', { class: 'scene' }, `t=${p.time.toFixed(1)}`) },
28
+ attachTo: document.body,
29
+ })
30
+ }
31
+
32
+ describe('MVideoPlayer', () => {
33
+ it('renders a video with its sources and subtitle tracks', () => {
34
+ const w = mount(MVideoPlayer, {
35
+ props: {
36
+ sources: [{ src: '/a.webm', type: 'video/webm' }, { src: '/a.mp4', type: 'video/mp4' }],
37
+ poster: '/p.jpg',
38
+ tracks: [{ src: '/es.vtt', srclang: 'es', label: 'Español' }],
39
+ },
40
+ })
41
+ const video = w.find('video')
42
+ expect(video.attributes('poster')).toBe('/p.jpg')
43
+ expect(video.attributes('playsinline')).toBeDefined()
44
+ expect(w.findAll('source').map((s) => s.attributes('src'))).toEqual(['/a.webm', '/a.mp4'])
45
+ expect(w.find('track').attributes('srclang')).toBe('es')
46
+ expect(w.find('[aria-label="Subtitles"]').exists()).toBe(true)
47
+ })
48
+
49
+ it('passes the clock to #media and plays it', async () => {
50
+ vi.useFakeTimers()
51
+ const w = clockPlayer()
52
+ expect(w.find('.scene').text()).toBe('t=0.0')
53
+ await w.find('[aria-label="Play"]').trigger('click')
54
+ vi.advanceTimersByTime(2000)
55
+ await nextTick()
56
+ expect(w.emitted('update:playing')![0]).toEqual([true])
57
+ expect(Number(w.find('.scene').text().slice(2))).toBeGreaterThan(1.5)
58
+ expect(w.find('video').exists()).toBe(false)
59
+ })
60
+
61
+ it('keys: K plays and pauses, L and J skip, digits jump to a tenth', async () => {
62
+ const w = clockPlayer()
63
+ key(w, 'k')
64
+ await nextTick()
65
+ expect(w.emitted('update:playing')!.at(-1)).toEqual([true])
66
+ key(w, 'k')
67
+ await nextTick()
68
+ expect(w.emitted('update:playing')!.at(-1)).toEqual([false])
69
+ key(w, 'l')
70
+ await nextTick()
71
+ expect(w.emitted('update:currentTime')!.at(-1)).toEqual([10])
72
+ key(w, 'j')
73
+ key(w, 'j')
74
+ await nextTick()
75
+ expect(w.emitted('update:currentTime')!.at(-1)).toEqual([0])
76
+ key(w, '7')
77
+ await nextTick()
78
+ expect(w.emitted('update:currentTime')!.at(-1)).toEqual([70])
79
+ })
80
+
81
+ it('a double tap on a side skips, and further taps add up', async () => {
82
+ vi.useFakeTimers()
83
+ const w = clockPlayer({ currentTime: 50 })
84
+ await nextTick()
85
+ const el = surface(w)
86
+ const tap = (x: number) => {
87
+ el.dispatchEvent(pointer('pointerdown', x))
88
+ el.dispatchEvent(pointer('pointerup', x))
89
+ vi.advanceTimersByTime(100)
90
+ }
91
+ tap(600)
92
+ tap(600)
93
+ await nextTick()
94
+ expect(w.emitted('update:currentTime')!.at(-1)).toEqual([60])
95
+ tap(600)
96
+ await nextTick()
97
+ expect(w.emitted('update:currentTime')!.at(-1)).toEqual([70])
98
+ expect(w.text()).toContain('20 seconds')
99
+ vi.advanceTimersByTime(1500)
100
+ tap(20)
101
+ tap(20)
102
+ await nextTick()
103
+ expect(w.emitted('update:currentTime')!.at(-1)).toEqual([60])
104
+ })
105
+
106
+ it('a single tap hides and shows the controls while playing', async () => {
107
+ vi.useFakeTimers()
108
+ const w = clockPlayer({ playing: true })
109
+ await flushPromises()
110
+ expect(w.find('[aria-label="Pause"]').exists()).toBe(true)
111
+ const el = surface(w)
112
+ el.dispatchEvent(pointer('pointerdown', 320))
113
+ el.dispatchEvent(pointer('pointerup', 320))
114
+ vi.advanceTimersByTime(300)
115
+ await nextTick()
116
+ await vi.runOnlyPendingTimersAsync()
117
+ expect(w.find('[aria-label="Pause"]').exists()).toBe(false)
118
+ el.dispatchEvent(pointer('pointerdown', 320))
119
+ el.dispatchEvent(pointer('pointerup', 320))
120
+ vi.advanceTimersByTime(300)
121
+ await nextTick()
122
+ expect(w.find('[aria-label="Pause"]').exists()).toBe(true)
123
+ })
124
+
125
+ it('a long press plays at 2× until released', async () => {
126
+ vi.useFakeTimers()
127
+ const w = clockPlayer({ playing: true, rate: 1.25 })
128
+ await flushPromises()
129
+ const el = surface(w)
130
+ el.dispatchEvent(pointer('pointerdown', 320))
131
+ vi.advanceTimersByTime(600)
132
+ await nextTick()
133
+ expect(w.emitted('update:rate')!.at(-1)).toEqual([2])
134
+ expect(w.text()).toContain('2×')
135
+ el.dispatchEvent(pointer('pointerup', 320))
136
+ await nextTick()
137
+ expect(w.emitted('update:rate')!.at(-1)).toEqual([1.25])
138
+ // The release doesn't also count as a tap
139
+ expect(w.emitted('update:playing')!.at(-1)).toEqual([true])
140
+ })
141
+
142
+ it('a mouse click plays and pauses', async () => {
143
+ const w = clockPlayer()
144
+ const el = surface(w)
145
+ el.dispatchEvent(pointer('pointerdown', 320, 'mouse'))
146
+ el.dispatchEvent(pointer('pointerup', 320, 'mouse'))
147
+ await nextTick()
148
+ expect(w.emitted('update:playing')!.at(-1)).toEqual([true])
149
+ })
150
+
151
+ it('shows previous and next only when asked, and emits them', async () => {
152
+ const w = clockPlayer()
153
+ expect(w.find('[aria-label="Previous"]').exists()).toBe(false)
154
+ await w.setProps({ hasPrevious: true, hasNext: true })
155
+ await w.find('[aria-label="Previous"]').trigger('click')
156
+ await w.find('[aria-label="Next"]').trigger('click')
157
+ expect(w.emitted('previous')).toHaveLength(1)
158
+ expect(w.emitted('next')).toHaveLength(1)
159
+ })
160
+
161
+ it('drives an external player and its previous/next', async () => {
162
+ const onNext = vi.fn()
163
+ const player = useMediaPlayer({ duration: 40, onNext })
164
+ const w = mount(MVideoPlayer, {
165
+ props: { player },
166
+ slots: { media: (p: { time: number }) => h('div', { class: 'scene' }, String(p.time)) },
167
+ })
168
+ player.seek(12)
169
+ await nextTick()
170
+ expect(w.find('.scene').text()).toBe('12')
171
+ await w.find('[aria-label="Next"]').trigger('click')
172
+ expect(onNext).toHaveBeenCalled()
173
+ })
174
+
175
+ it('loads hls.js for an .m3u8 the browser cannot play', async () => {
176
+ vi.spyOn(HTMLMediaElement.prototype, 'canPlayType').mockReturnValue('')
177
+ const instance = { loadSource: vi.fn(), attachMedia: vi.fn(), destroy: vi.fn(), on: vi.fn(), levels: [], currentLevel: -1 }
178
+ class Hls {
179
+ static isSupported = () => true
180
+ static Events = { MANIFEST_PARSED: 'hlsManifestParsed' }
181
+ constructor() { return instance }
182
+ }
183
+ const loader = vi.fn(async () => ({ default: Hls as never }))
184
+ const w = mount(MVideoPlayer, { props: { src: 'https://x.test/live/index.m3u8', hls: loader } })
185
+ await flushPromises()
186
+ expect(loader).toHaveBeenCalled()
187
+ expect(instance.loadSource).toHaveBeenCalledWith('https://x.test/live/index.m3u8')
188
+ expect(instance.attachMedia).toHaveBeenCalledWith(w.find('video').element)
189
+ expect(w.findAll('source')).toHaveLength(0)
190
+ w.unmount()
191
+ expect(instance.destroy).toHaveBeenCalled()
192
+ })
193
+
194
+ it('forwards attrs to its root', () => {
195
+ const w = mount(MVideoPlayer, { props: { duration: 1 }, attrs: { class: 'rounded-xl', 'data-x': '1' } })
196
+ expect(w.classes()).toContain('rounded-xl')
197
+ // position: relative comes from @layer base (.m3-video-player), so a consumer's `absolute` wins
198
+ expect(w.classes()).not.toContain('relative')
199
+ expect(w.attributes('data-x')).toBe('1')
200
+ })
201
+ })
@@ -0,0 +1,58 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { constrain, eraseAt, hitItem, inLasso, itemBox, strokePath, toDrawSvg, transformItem, type DrawStroke, type DrawItem } from '../composables/drawGeometry'
3
+
4
+ const line = (x1: number, x2: number, y = 0): DrawStroke => ({
5
+ id: 's', type: 'stroke', pen: 'marker', color: '#000', size: 4,
6
+ points: Array.from({ length: 11 }, (_, i) => [x1 + ((x2 - x1) * i) / 10, y, 1]),
7
+ })
8
+
9
+ describe('drawGeometry', () => {
10
+ it('outlines a stroke, and a dot as a circle', () => {
11
+ expect(strokePath(line(0, 100))).toMatch(/^M.*A.*A.*Z$/)
12
+ expect(strokePath({ ...line(0, 0), points: [[5, 5, 1]] })).toMatch(/a2 2 0 1 0 4 0/)
13
+ })
14
+ it('cuts a stroke in two where the eraser passes, and removes it when all of it is gone', () => {
15
+ const parts = eraseAt(line(0, 100), 50, 0, 3)
16
+ expect(parts).toHaveLength(2)
17
+ expect(parts[0]!.id).toBe('s')
18
+ expect(parts[1]!.id).not.toBe('s')
19
+ expect((parts[0] as DrawStroke).points.every((p) => p[0] < 50)).toBe(true)
20
+ expect(eraseAt(line(0, 100), 50, 30, 3)).toHaveLength(1)
21
+ const s = line(0, 4)
22
+ expect(eraseAt(s, 2, 0, 10)).toEqual([])
23
+ })
24
+ it('leaves an untouched item as the same object', () => {
25
+ const s = line(0, 100)
26
+ expect(eraseAt(s, 50, 40, 3)[0]).toBe(s)
27
+ })
28
+ it('hits shapes by their outline, filled ones inside too', () => {
29
+ const rect: DrawItem = { id: 'r', type: 'shape', shape: 'rect', from: [0, 0], to: [100, 50], color: '#000', size: 2 }
30
+ expect(hitItem(rect, 50, 0)).toBe(true)
31
+ expect(hitItem(rect, 50, 25)).toBe(false)
32
+ expect(hitItem({ ...rect, fill: '#f00' }, 50, 25)).toBe(true)
33
+ })
34
+ it('selects by lasso when most of an item is inside', () => {
35
+ const poly: [number, number][] = [[-10, -10], [60, -10], [60, 10], [-10, 10]]
36
+ expect(inLasso(line(0, 50), poly)).toBe(true)
37
+ expect(inLasso(line(0, 200), poly)).toBe(false)
38
+ })
39
+ it('moves and scales items', () => {
40
+ const s = transformItem(line(0, 10), { dx: 5, sx: 2, sy: 2 }) as DrawStroke
41
+ expect(s.points[10]![0]).toBe(25)
42
+ expect(s.size).toBe(8)
43
+ expect(itemBox(s).x).toBe(1)
44
+ })
45
+ it('snaps a line to 45° and a rect to a square', () => {
46
+ const [x, y] = constrain('line', [0, 0], [10, 9])
47
+ expect(x).toBeCloseTo(y)
48
+ expect(constrain('rect', [0, 0], [10, -4])).toEqual([10, -10])
49
+ })
50
+ it('exports SVG of one page with its background', () => {
51
+ const svg = toDrawSvg([{ ...line(0, 10), page: 1 }, { ...line(0, 10), id: 'b', page: 0 }, { id: 't', type: 'text', at: [0, 0], text: 'a<b', size: 12, color: '#000', page: 1 }], {
52
+ page: 1, box: { x: 0, y: 0, width: 100, height: 100 }, background: '#fff',
53
+ })
54
+ expect(svg.match(/<path/g)).toHaveLength(1)
55
+ expect(svg).toContain('a&lt;b')
56
+ expect(svg).toContain('fill="#fff"')
57
+ })
58
+ })
@@ -0,0 +1,30 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MTextField from '../components/MTextField.vue'
4
+ import MNumberField from '../components/MNumberField.vue'
5
+ import MMaskField from '../components/MMaskField.vue'
6
+ import MTagInput from '../components/MTagInput.vue'
7
+
8
+ describe('text fields expose focus and selection', () => {
9
+ it('MTextField focuses and selects part of its text, input or textarea', async () => {
10
+ for (const multiline of [false, true]) {
11
+ const w = mount(MTextField, { props: { modelValue: 'report.pdf', label: 'Name', multiline }, attachTo: document.body })
12
+ const vm = w.vm as any
13
+ vm.focus()
14
+ expect(document.activeElement).toBe(vm.inputEl)
15
+ vm.setSelectionRange(0, 6)
16
+ expect([vm.inputEl.selectionStart, vm.inputEl.selectionEnd]).toEqual([0, 6])
17
+ vm.blur()
18
+ expect(document.activeElement).not.toBe(vm.inputEl)
19
+ w.unmount()
20
+ }
21
+ })
22
+ it('MNumberField, MMaskField and MTagInput focus their input', () => {
23
+ for (const [C, props] of [[MNumberField, { modelValue: 3 }], [MMaskField, { modelValue: '', mask: '##' }], [MTagInput, { modelValue: [] }]] as const) {
24
+ const w = mount(C as any, { props, attachTo: document.body })
25
+ ;(w.vm as any).focus()
26
+ expect(document.activeElement).toBe((w.vm as any).inputEl)
27
+ w.unmount()
28
+ }
29
+ })
30
+ })
@@ -0,0 +1,185 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { parseDot, parseMermaid, toDot, toMermaid } from '../composables/flowFormats'
3
+
4
+ const pairs = (g: { edges: { source: string; target: string }[] }) => g.edges.map((e) => `${e.source}>${e.target}`)
5
+
6
+ describe('parseDot', () => {
7
+ it('reads nodes, chains, defaults, attributes and comments', () => {
8
+ const g = parseDot(`
9
+ // a pipeline
10
+ digraph build {
11
+ rankdir=LR; /* left to right */
12
+ node [shape=box];
13
+ edge [color=gray];
14
+ fetch [label="Fetch\\nsources"];
15
+ fetch -> compile -> test [label="ok", style=dashed, penwidth=2];
16
+ test -> deploy [dir=none, color="#ff0000:blue"];
17
+ "odd id" -> deploy
18
+ }`)
19
+ expect(g.name).toBe('build')
20
+ expect(g.rankdir).toBe('LR')
21
+ expect(g.direction).toBe('horizontal')
22
+ expect(g.nodes.map((n) => n.id)).toEqual(['fetch', 'compile', 'test', 'deploy', 'odd id'])
23
+ expect(g.nodes[0]!.data.label).toBe('Fetch\nsources')
24
+ expect(g.nodes[1]!.data.label).toBe('compile')
25
+ expect(g.nodes[1]!.data.attrs.shape).toBe('box')
26
+ expect(pairs(g)).toEqual(['fetch>compile', 'compile>test', 'test>deploy', 'odd id>deploy'])
27
+ expect(g.edges[0]).toMatchObject({ label: 'ok', dashed: true, width: 4, color: 'gray' })
28
+ expect(g.edges[2]).toMatchObject({ markerEnd: 'none', color: '#ff0000' })
29
+ // Laid out left to right
30
+ const x = (id: string) => g.nodes.find((n) => n.id === id)!.position.x
31
+ expect(x('fetch')).toBeLessThan(x('compile'))
32
+ expect(x('compile')).toBeLessThan(x('test'))
33
+ })
34
+
35
+ it('undirected graphs, strict, subgraph operands, ports and HTML labels', () => {
36
+ const g = parseDot(`strict graph { a -- b; a -- b; b -- a; a:n -- { c d }; e [label=<<b>Bold</b><br/>line>] }`)
37
+ expect(g.directed).toBe(false)
38
+ expect(pairs(g)).toEqual(['a>b', 'a>c', 'a>d'])
39
+ expect(g.edges.every((e) => e.markerEnd === 'none')).toBe(true)
40
+ expect(g.edges[1]!.data.attrs.tailport).toBe('n')
41
+ expect(g.nodes.find((n) => n.id === 'e')!.data.label).toBe('Bold\nline')
42
+ })
43
+
44
+ it('clusters become groups laid out from the inside out; circles and hidden nodes', () => {
45
+ const g = parseDot(`digraph {
46
+ subgraph cluster_a { label="Team A"; x; subgraph cluster_inner { y [shape=doublecircle] } }
47
+ x -> y -> z
48
+ ghost [style=invis]
49
+ }`)
50
+ const byId = new Map(g.nodes.map((n) => [n.id, n]))
51
+ expect(byId.get('cluster_a')).toMatchObject({ type: 'group', data: { label: 'Team A' } })
52
+ expect(byId.get('cluster_inner')!.parentId).toBe('cluster_a')
53
+ expect(byId.get('x')!.parentId).toBe('cluster_a')
54
+ expect(byId.get('y')).toMatchObject({ type: 'circle', parentId: 'cluster_inner', data: { ring: 'primary' } })
55
+ expect(byId.get('z')!.parentId).toBeUndefined()
56
+ expect(byId.get('ghost')!.hidden).toBe(true)
57
+ // Parents come before their children; children sit inside the group's padding and header
58
+ const order = g.nodes.map((n) => n.id)
59
+ expect(order.indexOf('cluster_a')).toBeLessThan(order.indexOf('x'))
60
+ expect(byId.get('x')!.position.x).toBeGreaterThanOrEqual(24)
61
+ expect(byId.get('x')!.position.y).toBeGreaterThanOrEqual(36)
62
+ })
63
+
64
+ it('keeps pos when every node has one', () => {
65
+ const g = parseDot('digraph { a [pos="0,0"]; b [pos="150,-75"] }')
66
+ const [a, b] = g.nodes
67
+ expect(b!.position.x - a!.position.x).toBe(200)
68
+ expect(b!.position.y - a!.position.y).toBe(100)
69
+ })
70
+
71
+ it('layout: false leaves the nodes at 0,0', () => {
72
+ const g = parseDot('digraph { a -> b }', { layout: false, edgeType: 'smoothstep', nodeType: 'step' })
73
+ expect(g.nodes.every((n) => n.position.x === 0 && n.position.y === 0)).toBe(true)
74
+ expect(g.nodes[0]!.type).toBe('step')
75
+ expect(g.edges[0]!.type).toBe('smoothstep')
76
+ })
77
+
78
+ it('throws with the line and column', () => {
79
+ expect(() => parseDot('digraph {\n a -> ;\n}')).toThrow(/line 2, column 8/)
80
+ expect(() => parseDot('flowchart LR')).toThrow(SyntaxError)
81
+ })
82
+ })
83
+
84
+ describe('parseMermaid', () => {
85
+ it('reads shapes, chains, & and every kind of link', () => {
86
+ const g = parseMermaid(`
87
+ %% a comment
88
+ flowchart LR
89
+ A[Start] --> B{Is it?}
90
+ B -->|Yes| C((Done))
91
+ B -- No --> D([Retry]) -.-> A
92
+ C & D ==> E[("Log store")]
93
+ E --- F
94
+ F ~~~ G
95
+ G <--> H:::warn
96
+ H --again--> I
97
+ I --x J
98
+ classDef warn fill:#f96
99
+ style A fill:#f9f`)
100
+ expect(g.rankdir).toBe('LR')
101
+ const byId = new Map(g.nodes.map((n) => [n.id, n]))
102
+ expect(byId.get('A')!.data).toMatchObject({ label: 'Start', shape: 'rect' })
103
+ expect(byId.get('B')!.data.shape).toBe('diamond')
104
+ expect(byId.get('C')!.type).toBe('circle')
105
+ expect(byId.get('D')!.data.shape).toBe('stadium')
106
+ expect(byId.get('E')!.data).toMatchObject({ label: 'Log store', shape: 'cylinder' })
107
+ expect(byId.get('H')!.data.label).toBe('H')
108
+ expect(pairs(g)).toEqual(['A>B', 'B>C', 'B>D', 'D>A', 'C>E', 'D>E', 'E>F', 'F>G', 'G>H', 'H>I', 'I>J'])
109
+ const e = g.edges
110
+ expect(e[1]!.label).toBe('Yes')
111
+ expect(e[2]!.label).toBe('No')
112
+ expect(e[3]!.dashed).toBe(true)
113
+ expect(e[4]!.width).toBe(4)
114
+ expect(e[6]!.markerEnd).toBe('none')
115
+ expect(e[7]!.hidden).toBe(true)
116
+ expect(e[8]!.markerStart).toBe('arrow-closed')
117
+ expect(e[9]!.label).toBe('again')
118
+ expect(e[10]!.markerEnd).toBe('arrow')
119
+ })
120
+
121
+ it('subgraphs become groups; graph TD on one line', () => {
122
+ const g = parseMermaid('graph TD; a-->b; subgraph s1 [Backend]; b; c-->d; end')
123
+ expect(g.rankdir).toBe('TB')
124
+ const byId = new Map(g.nodes.map((n) => [n.id, n]))
125
+ expect(byId.get('s1')).toMatchObject({ type: 'group', data: { label: 'Backend' } })
126
+ // b was used before the subgraph: naming it there moves it in, as in Mermaid
127
+ expect(byId.get('b')!.parentId).toBe('s1')
128
+ expect(byId.get('c')!.parentId).toBe('s1')
129
+ expect(byId.get('a')!.parentId).toBeUndefined()
130
+ expect(pairs(g)).toEqual(['a>b', 'c>d'])
131
+ })
132
+
133
+ it('the @{ } node syntax and quoted labels with brackets', () => {
134
+ const g = parseMermaid('flowchart TB\n a@{ shape: circle, label: "Hub" } --> b["Has [brackets]"]')
135
+ expect(g.nodes[0]).toMatchObject({ type: 'circle', data: { label: 'Hub' } })
136
+ expect(g.nodes[1]!.data.label).toBe('Has [brackets]')
137
+ })
138
+
139
+ it('throws on a missing end', () => {
140
+ expect(() => parseMermaid('flowchart LR\nsubgraph x\na-->b')).toThrow(/no "end"/)
141
+ })
142
+ })
143
+
144
+ describe('toDot / toMermaid', () => {
145
+ const nodes = [
146
+ { id: 'g', type: 'group', position: { x: 0, y: 0 }, data: { label: 'Group' } },
147
+ { id: 'a', position: { x: 10, y: 40 }, parentId: 'g', data: { label: 'Say "hi"' } },
148
+ { id: 'b', type: 'circle', position: { x: 300, y: 0 }, data: { label: 'b', ring: 'primary' } },
149
+ { id: 'end', position: { x: 600, y: 0 }, data: { label: 'Finish' } },
150
+ ]
151
+ const edges = [
152
+ { id: 'e1', source: 'a', target: 'b', label: 'go', dashed: true, color: 'red', width: 4 },
153
+ { id: 'e2', source: 'b', target: 'end', markerEnd: 'none' as const, color: 'primary' },
154
+ ]
155
+
156
+ it('writes DOT that reads back the same', () => {
157
+ const text = toDot(nodes, edges, { name: 'demo', direction: 'horizontal' })
158
+ expect(text).toContain('rankdir=LR;')
159
+ expect(text).toContain('subgraph cluster_g {')
160
+ expect(text).toContain('a [label="Say \\"hi\\""];')
161
+ expect(text).toContain('a -> b [label=go, color=red, penwidth=2, style=dashed];')
162
+ expect(text).not.toContain('primary')
163
+ const back = parseDot(text)
164
+ expect(back.nodes.find((n) => n.id === 'a')).toMatchObject({ parentId: 'cluster_g', data: { label: 'Say "hi"' } })
165
+ expect(back.nodes.find((n) => n.id === 'b')).toMatchObject({ type: 'circle', data: { ring: 'primary' } })
166
+ expect(back.edges[0]).toMatchObject({ label: 'go', dashed: true, color: 'red', width: 4 })
167
+ expect(back.edges[1]!.markerEnd).toBe('none')
168
+ // And again: unchanged
169
+ expect(toDot(back.nodes, back.edges, { name: 'demo', direction: 'horizontal' })).toBe(text)
170
+ })
171
+
172
+ it('writes Mermaid that reads back the same', () => {
173
+ const text = toMermaid(nodes, edges, { direction: 'LR' })
174
+ expect(text.split('\n')[0]).toBe('flowchart LR')
175
+ // "end" can't be a Mermaid id
176
+ expect(text).not.toMatch(/^\s*end\[/m)
177
+ const back = parseMermaid(text)
178
+ const a = back.nodes.find((n) => n.data?.label === 'Say "hi"')!
179
+ expect(a.parentId).toBe('g')
180
+ expect(back.nodes.find((n) => n.id === 'b')).toMatchObject({ type: 'circle', data: { ring: 'primary' } })
181
+ expect(back.nodes.find((n) => n.data?.label === 'Finish')).toBeTruthy()
182
+ expect(back.edges[0]).toMatchObject({ label: 'go', dashed: true })
183
+ expect(back.edges[1]!.markerEnd).toBe('none')
184
+ })
185
+ })
@@ -0,0 +1,113 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { layoutLayered, layoutTree } from '../composables/flowLayout'
3
+ import { arrowPath, getBezierPath, getSmoothStepPath, getStraightPath, smoothStepPoints } from '../composables/flowPaths'
4
+ import type { FlowEdge, FlowNode } from '../composables/useFlow'
5
+
6
+ const nodes = (...ids: string[]): FlowNode[] => ids.map((id) => ({ id, position: { x: 0, y: 0 } }))
7
+ const edges = (...pairs: string[]): FlowEdge[] => pairs.map((p) => {
8
+ const [source, target] = p.split('>')
9
+ return { id: p, source: source!, target: target! }
10
+ })
11
+ const size = { width: 100, height: 40 }
12
+ const overlaps = (r: Record<string, { x: number; y: number }>, w = 100, h = 40) => {
13
+ const v = Object.values(r)
14
+ return v.some((a, i) => v.some((b, j) => i < j && a.x < b.x + w && a.x + w > b.x && a.y < b.y + h && a.y + h > b.y))
15
+ }
16
+
17
+ describe('layoutTree', () => {
18
+ it('centers parents over their children, levels apart', () => {
19
+ const r = layoutTree(nodes('a', 'b', 'c', 'd'), edges('a>b', 'a>c', 'b>d'), { defaultSize: size, gap: 20, levelGap: 50 })
20
+ expect(r.b!.y).toBe(90)
21
+ expect(r.d!.y).toBe(180)
22
+ expect(r.a!.x + 50).toBe(((r.b!.x + 50) + (r.c!.x + 50)) / 2)
23
+ expect(r.d!.x).toBe(r.b!.x)
24
+ expect(overlaps(r)).toBe(false)
25
+ })
26
+
27
+ it('runs left to right with LR, and survives cycles and several roots', () => {
28
+ const r = layoutTree(nodes('a', 'b', 'x', 'y'), edges('a>b', 'b>a', 'x>y'), { direction: 'LR', defaultSize: size })
29
+ expect(Object.keys(r).sort()).toEqual(['a', 'b', 'x', 'y'])
30
+ expect(r.b!.x).toBeGreaterThan(r.a!.x)
31
+ expect(r.y!.x).toBeGreaterThan(r.x!.x)
32
+ expect(overlaps(r)).toBe(false)
33
+ })
34
+
35
+ it('leaves hidden nodes and children of groups out', () => {
36
+ const ns = [...nodes('a', 'b'), { id: 'h', position: { x: 5, y: 5 }, hidden: true }, { id: 'k', position: { x: 5, y: 5 }, parentId: 'a' }]
37
+ const r = layoutTree(ns, edges('a>b', 'a>h'), { defaultSize: size })
38
+ expect(Object.keys(r).sort()).toEqual(['a', 'b'])
39
+ })
40
+ })
41
+
42
+ describe('layoutLayered', () => {
43
+ it('puts every edge one level onwards, without overlaps', () => {
44
+ const r = layoutLayered(nodes('in', 'a', 'b', 'join', 'out'), edges('in>a', 'in>b', 'a>join', 'b>join', 'join>out'), { direction: 'LR', defaultSize: size, levelGap: 60 })
45
+ expect(r.in!.x).toBe(0)
46
+ expect(r.a!.x).toBe(160)
47
+ expect(r.b!.x).toBe(160)
48
+ expect(r.join!.x).toBe(320)
49
+ expect(r.out!.x).toBe(480)
50
+ // The join lines up between its two inputs
51
+ expect(r.join!.y).toBeCloseTo((r.a!.y + r.b!.y) / 2)
52
+ expect(overlaps(r)).toBe(false)
53
+ })
54
+
55
+ it('orders a level to avoid crossings', () => {
56
+ // a→d and b→c would cross if c and d stayed in the order given
57
+ const r = layoutLayered(nodes('a', 'b', 'c', 'd'), edges('a>d', 'b>c'), { defaultSize: size })
58
+ expect(Math.sign(r.a!.x - r.b!.x)).toBe(Math.sign(r.d!.x - r.c!.x))
59
+ })
60
+
61
+ it('keeps a lane open for an edge across several levels', () => {
62
+ // a→b→c→d, and a→d skipping two levels: d's long edge must not run under b and c
63
+ const r = layoutLayered(nodes('a', 'b', 'c', 'd', 'x'), edges('a>b', 'b>c', 'c>d', 'a>d', 'x>c'), { direction: 'LR', defaultSize: size, gap: 20 })
64
+ expect(Object.keys(r).sort()).toEqual(['a', 'b', 'c', 'd', 'x'])
65
+ const ys = [r.a!.y, r.d!.y]
66
+ // The straight line from a to d stays clear of b's and c's boxes
67
+ const clear = (n: { y: number }) => Math.min(...ys) + 20 >= n.y + 40 || Math.max(...ys) + 20 <= n.y
68
+ expect(clear(r.b!) || clear(r.c!) || r.a!.y !== r.b!.y).toBe(true)
69
+ expect(overlaps(r)).toBe(false)
70
+ })
71
+
72
+ it('lays out a cycle', () => {
73
+ const r = layoutLayered(nodes('a', 'b', 'c'), edges('a>b', 'b>c', 'c>a'), { defaultSize: size })
74
+ expect(r.a!.y).toBeLessThan(r.b!.y)
75
+ expect(r.b!.y).toBeLessThan(r.c!.y)
76
+ })
77
+ })
78
+
79
+ describe('edge paths', () => {
80
+ const ends = { sourceX: 0, sourceY: 0, targetX: 200, targetY: 100 }
81
+ it('bezier leaves and arrives square to the sides, its label halfway', () => {
82
+ const p = getBezierPath({ ...ends, sourcePosition: 'right', targetPosition: 'left' })
83
+ expect(p.path).toBe('M0,0 C100,0 100,100 200,100')
84
+ expect(p.labelX).toBe(100)
85
+ expect(p.labelY).toBe(50)
86
+ expect(p.targetAngle).toBeCloseTo(0)
87
+ })
88
+
89
+ it('smoothstep facing sides: one run halfway, rounded corners', () => {
90
+ expect(smoothStepPoints({ ...ends, sourcePosition: 'right', targetPosition: 'left' })).toEqual([[0, 0], [100, 0], [100, 100], [200, 100]])
91
+ const p = getSmoothStepPath({ ...ends, sourcePosition: 'right', targetPosition: 'left', borderRadius: 8 })
92
+ expect(p.path).toContain('Q100,0 100,8')
93
+ expect(p.labelX).toBe(100)
94
+ expect(p.labelY).toBe(50)
95
+ })
96
+
97
+ it('smoothstep goes round when the target is behind the source', () => {
98
+ const pts = smoothStepPoints({ sourceX: 200, sourceY: 0, targetX: 0, targetY: 100, sourcePosition: 'right', targetPosition: 'left', offset: 20 })
99
+ expect(pts[1]).toEqual([220, 0])
100
+ expect(pts.at(-2)).toEqual([-20, 100])
101
+ expect(pts.at(-1)).toEqual([0, 100])
102
+ })
103
+
104
+ it('smoothstep from a side to a top: a single corner when it can', () => {
105
+ expect(smoothStepPoints({ ...ends, sourcePosition: 'right', targetPosition: 'top' })).toEqual([[0, 0], [200, 0], [200, 100]])
106
+ })
107
+
108
+ it('straight lines and arrowheads', () => {
109
+ const p = getStraightPath(ends)
110
+ expect(p.path).toBe('M0,0 L200,100')
111
+ expect(arrowPath(10, 0, 0, 10, true)).toMatch(/^M10,0 L.+ Z$/)
112
+ })
113
+ })
@@ -0,0 +1,76 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { parseGanttCsv, parseGanttJson, parseMsProjectXml, toGanttCsv, toGanttJson, toMsProjectXml } from '../composables/ganttFormats'
3
+ import type { GanttTask } from '../composables/ganttSchedule'
4
+
5
+ const tasks: GanttTask[] = [
6
+ { id: 'p', name: 'Launch, phase 1', start: '2026-03-02', end: '2026-03-13', type: 'summary', progress: 40 },
7
+ { id: 'a', name: 'Design "v2"', start: '2026-03-02', end: '2026-03-06', parentId: 'p', progress: 100, color: 'tertiary', baselineStart: '2026-03-02', baselineEnd: '2026-03-04' },
8
+ { id: 'b', name: 'Build', start: '2026-03-09', end: '2026-03-13', parentId: 'p', dependencies: ['a', { id: 'a', type: 'SS', lag: 2 }] },
9
+ { id: 'm', name: 'Ship', start: '2026-03-16', type: 'milestone', dependencies: [{ id: 'b', type: 'FS', lag: -1 }] },
10
+ ]
11
+
12
+ describe('gantt CSV', () => {
13
+ it('round trips, quoting what needs it', () => {
14
+ const csv = toGanttCsv(tasks)
15
+ expect(csv.split('\n')[0]).toBe('id,name,start,end,progress,type,parent,dependencies,color,baselineStart,baselineEnd')
16
+ expect(csv).toContain('"Launch, phase 1"')
17
+ expect(csv).toContain('"Design ""v2"""')
18
+ expect(csv).toContain('a; a SS+2')
19
+ expect(parseGanttCsv(csv)).toEqual(tasks)
20
+ })
21
+ it("reads other tools' headers, separators and dates", () => {
22
+ const csv = 'Task Name;Start Date;Finish;% Complete;Predecessors\nPlan;03/04/2026;05/04/2026;50%;\nDo;2026-04-06 09:00;2026-04-06 17:30;;t1 FF-1\nDone;10/04/2026;;;\n'
23
+ const r = parseGanttCsv(csv)
24
+ expect(r[0]).toEqual({ id: 't1', name: 'Plan', start: '2026-04-03', end: '2026-04-05', progress: 50 })
25
+ expect(r[1]).toMatchObject({ start: '2026-04-06T09:00', end: '2026-04-06T17:30', dependencies: [{ id: 't1', type: 'FF', lag: -1 }] })
26
+ expect(r[2]).toMatchObject({ type: 'milestone', start: '2026-04-10' })
27
+ expect(() => parseGanttCsv('a,b\n1,2')).toThrow(SyntaxError)
28
+ })
29
+ })
30
+
31
+ describe('gantt JSON', () => {
32
+ it('round trips and accepts bare arrays', () => {
33
+ expect(parseGanttJson(toGanttJson(tasks))).toEqual(tasks)
34
+ expect(parseGanttJson('[{"name":"x","start":"2026-01-01"}]')).toEqual([{ id: 't1', name: 'x', start: '2026-01-01' }])
35
+ expect(() => parseGanttJson('{"nope":1}')).toThrow(SyntaxError)
36
+ expect(() => parseGanttJson('[{"name":"x"}]')).toThrow(/no valid start/)
37
+ })
38
+ })
39
+
40
+ describe('MS Project XML', () => {
41
+ it('writes MSPDI that reads back the same', () => {
42
+ const xml = toMsProjectXml(tasks, { name: 'Launch & co' })
43
+ expect(xml).toContain('<Name>Launch &amp; co</Name>')
44
+ expect(xml).toContain('<OutlineLevel>2</OutlineLevel>')
45
+ expect(xml).toContain('<Start>2026-03-02T08:00:00</Start>')
46
+ expect(xml).toContain('<Finish>2026-03-06T17:00:00</Finish>')
47
+ expect(xml).toContain('<Duration>PT45H0M0S</Duration>')
48
+ expect(xml).toContain('<Type>3</Type><LinkLag>9600</LinkLag>')
49
+ const back = parseMsProjectXml(xml)
50
+ expect(back.name).toBe('Launch & co')
51
+ // Ids become Project's UIDs
52
+ const ids = new Map(tasks.map((t, i) => [t.id, String(i + 1)]))
53
+ const expected = tasks.map((t) => ({
54
+ ...t,
55
+ id: ids.get(t.id)!,
56
+ ...(t.parentId ? { parentId: ids.get(t.parentId) } : {}),
57
+ ...(t.dependencies ? { dependencies: t.dependencies.map((d) => (typeof d === 'string' ? ids.get(d) : { ...d, id: ids.get(d.id)! })) } : {}),
58
+ }))
59
+ for (const e of expected) delete (e as Partial<GanttTask>).color
60
+ expect(back.tasks).toEqual(expected)
61
+ })
62
+ it('reads datetimes, namespaces, entities and skips the project summary', () => {
63
+ const xml = `<?xml version="1.0"?><!-- x --><p:Project xmlns:p="http://schemas.microsoft.com/project"><Title>Ops</Title><Tasks>
64
+ <Task><UID>0</UID><OutlineLevel>0</OutlineLevel><Name>Ops</Name><Start>2026-05-01T08:00:00</Start><Finish>2026-05-01T17:00:00</Finish></Task>
65
+ <Task><UID>7</UID><OutlineLevel>1</OutlineLevel><Name>Night &lt;shift&gt;</Name><Start>2026-05-01T22:00:00</Start><Finish>2026-05-02T06:30:00</Finish><PercentComplete>10</PercentComplete></Task>
66
+ <Task><UID>8</UID><OutlineLevel>1</OutlineLevel><Name><![CDATA[A & B]]></Name><Start>2026-05-02T07:00:00</Start><Finish>2026-05-02T08:00:00</Finish><PredecessorLink><PredecessorUID>7</PredecessorUID><Type>1</Type><LinkLag>0</LinkLag></PredecessorLink></Task>
67
+ </Tasks></p:Project>`
68
+ const r = parseMsProjectXml(xml)
69
+ expect(r.name).toBe('Ops')
70
+ expect(r.tasks).toEqual([
71
+ { id: '7', name: 'Night <shift>', start: '2026-05-01T22:00', end: '2026-05-02T06:30', progress: 10 },
72
+ { id: '8', name: 'A & B', start: '2026-05-02T07:00', end: '2026-05-02T08:00', dependencies: ['7'] },
73
+ ])
74
+ expect(() => parseMsProjectXml('<x/>')).toThrow(SyntaxError)
75
+ })
76
+ })