@m3ui-vue/m3ui-vue 1.2.1 → 1.3.0

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 (269) hide show
  1. package/dist/API.md +2914 -348
  2. package/dist/MButton-CuNzpoxm.js +172 -0
  3. package/dist/MButton-CuNzpoxm.js.map +1 -0
  4. package/dist/MDialog-HxEL-m58.js +173 -0
  5. package/dist/MDialog-HxEL-m58.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-DnPtv-hY.js +824 -0
  9. package/dist/MListItem-DnPtv-hY.js.map +1 -0
  10. package/dist/MLoadingIndicator-BQMNX6Dx.js +115 -0
  11. package/dist/MLoadingIndicator-BQMNX6Dx.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-LURE1Ah7.js +435 -0
  17. package/dist/MSeekBar-LURE1Ah7.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-_J4IS2_z.js +691 -0
  21. package/dist/MSlider-_J4IS2_z.js.map +1 -0
  22. package/dist/MSpinner-BhkMYKOM.js +65 -0
  23. package/dist/MSpinner-BhkMYKOM.js.map +1 -0
  24. package/dist/MTextField-CkzwNBWS.js +296 -0
  25. package/dist/MTextField-CkzwNBWS.js.map +1 -0
  26. package/dist/MTooltip-B67ZDSGp.js +756 -0
  27. package/dist/MTooltip-B67ZDSGp.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 +148 -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 +160 -0
  55. package/dist/components/MFlow.vue.d.ts +305 -0
  56. package/dist/components/MFlowControls.vue.d.ts +33 -0
  57. package/dist/components/MFlowHandle.vue.d.ts +16 -0
  58. package/dist/components/MFlowMinimap.vue.d.ts +22 -0
  59. package/dist/components/MFlowNode.vue.d.ts +35 -0
  60. package/dist/components/MGantt.vue.d.ts +141 -0
  61. package/dist/components/MGanttControls.vue.d.ts +32 -0
  62. package/dist/components/MIconButton.vue.d.ts +3 -1
  63. package/dist/components/MImageCropper.vue.d.ts +110 -0
  64. package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
  65. package/dist/components/MLightbox.vue.d.ts +2 -2
  66. package/dist/components/MList.vue.d.ts +1 -1
  67. package/dist/components/MLoadingOverlay.vue.d.ts +1 -1
  68. package/dist/components/MMap.vue.d.ts +1 -1
  69. package/dist/components/MMapControl.vue.d.ts +1 -1
  70. package/dist/components/MMapSearch.vue.d.ts +1 -1
  71. package/dist/components/MMaskField.vue.d.ts +12 -1
  72. package/dist/components/MMenu.vue.d.ts +1 -1
  73. package/dist/components/MNavigationDrawer.vue.d.ts +1 -1
  74. package/dist/components/MNumberField.vue.d.ts +11 -2
  75. package/dist/components/MPdfViewer.vue.d.ts +174 -0
  76. package/dist/components/MPullToRefresh.vue.d.ts +1 -1
  77. package/dist/components/MResourceTimeline.vue.d.ts +149 -0
  78. package/dist/components/MScheduler.vue.d.ts +3 -3
  79. package/dist/components/MScheme.vue.d.ts +1 -1
  80. package/dist/components/MSearchField.vue.d.ts +1 -1
  81. package/dist/components/MSeekBar.vue.d.ts +1 -1
  82. package/dist/components/MSimpleCarousel.vue.d.ts +1 -1
  83. package/dist/components/MSkeleton.vue.d.ts +1 -1
  84. package/dist/components/MSlider.vue.d.ts +4 -4
  85. package/dist/components/MSparkline.vue.d.ts +1 -1
  86. package/dist/components/MSplitter.vue.d.ts +1 -1
  87. package/dist/components/MStack.vue.d.ts +2 -2
  88. package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
  89. package/dist/components/MSwitch.vue.d.ts +1 -1
  90. package/dist/components/MTable.vue.d.ts +1 -1
  91. package/dist/components/MTagInput.vue.d.ts +12 -1
  92. package/dist/components/MTextField.vue.d.ts +13 -2
  93. package/dist/components/MToolbar.vue.d.ts +1 -1
  94. package/dist/components/MTree.vue.d.ts +2 -2
  95. package/dist/components/MVideoPlayer.vue.d.ts +253 -0
  96. package/dist/components/MVirtualTable.vue.d.ts +1 -1
  97. package/dist/components/MWindow.vue.d.ts +3 -3
  98. package/dist/components/_MFlowEdge.vue.d.ts +9 -0
  99. package/dist/components/_MFlowEdgeLabel.vue.d.ts +9 -0
  100. package/dist/components/_MFlowNodeShell.vue.d.ts +9 -0
  101. package/dist/components/_MPdfPage.vue.d.ts +76 -0
  102. package/dist/components/_MTimeBackground.vue.d.ts +14 -0
  103. package/dist/components/_MTimeHeader.vue.d.ts +20 -0
  104. package/dist/composables/_effectCanvas.d.ts +23 -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/_storageKeys.d.ts +9 -0
  109. package/dist/composables/_useTimeAxis.d.ts +90 -0
  110. package/dist/composables/drawGeometry.d.ts +119 -0
  111. package/dist/composables/flowFormats.d.ts +79 -0
  112. package/dist/composables/flowLayout.d.ts +45 -0
  113. package/dist/composables/flowPaths.d.ts +53 -0
  114. package/dist/composables/ganttFormats.d.ts +52 -0
  115. package/dist/composables/ganttSchedule.d.ts +99 -0
  116. package/dist/composables/themeInitScript.d.ts +2 -0
  117. package/dist/composables/useConfetti.d.ts +19 -8
  118. package/dist/composables/useDrawing.d.ts +44 -0
  119. package/dist/composables/useFireworks.d.ts +37 -0
  120. package/dist/composables/useFlow.d.ts +266 -0
  121. package/dist/composables/useGantt.d.ts +87 -0
  122. package/dist/composables/useLocale.d.ts +163 -0
  123. package/dist/composables/useMediaPlayer.d.ts +101 -0
  124. package/dist/composables/usePdf.d.ts +119 -0
  125. package/dist/composables/useReactions.d.ts +32 -0
  126. package/dist/composables/useResourceTimeline.d.ts +70 -0
  127. package/dist/composables/viewportHints.d.ts +2 -0
  128. package/dist/directives/vSparkle.d.ts +27 -0
  129. package/dist/draw.d.ts +7 -0
  130. package/dist/draw.js +1700 -0
  131. package/dist/draw.js.map +1 -0
  132. package/dist/flow.d.ts +14 -0
  133. package/dist/flow.js +3542 -0
  134. package/dist/flow.js.map +1 -0
  135. package/dist/flowPaths-CUc6X373.js +161 -0
  136. package/dist/flowPaths-CUc6X373.js.map +1 -0
  137. package/dist/gantt.d.ts +12 -0
  138. package/dist/gantt.js +3575 -0
  139. package/dist/gantt.js.map +1 -0
  140. package/dist/index.d.ts +11 -1
  141. package/dist/locales/index.js +1148 -7
  142. package/dist/locales/index.js.map +1 -1
  143. package/dist/m3ui-vue.css +1 -1
  144. package/dist/m3ui.js +7822 -7809
  145. package/dist/m3ui.js.map +1 -1
  146. package/dist/map.js +593 -588
  147. package/dist/map.js.map +1 -1
  148. package/dist/media.d.ts +5 -0
  149. package/dist/media.js +1311 -0
  150. package/dist/media.js.map +1 -0
  151. package/dist/pdf.d.ts +4 -0
  152. package/dist/pdf.js +1871 -0
  153. package/dist/pdf.js.map +1 -0
  154. package/dist/plugin.d.ts +10 -0
  155. package/dist/rich-text-editor.js +28 -26
  156. package/dist/rich-text-editor.js.map +1 -1
  157. package/dist/styles.css +1 -1
  158. package/dist/{useLocale-JYxDDeXC.js → useLocale-BpGxplLV.js} +165 -2
  159. package/dist/useLocale-BpGxplLV.js.map +1 -0
  160. package/dist/{useThemeTokens-Bv-Uv8eX.js → useThemeTokens-DQQcaWbE.js} +41 -40
  161. package/dist/useThemeTokens-DQQcaWbE.js.map +1 -0
  162. package/package.json +29 -5
  163. package/src/__tests__/MAudioPlayer.test.ts +75 -0
  164. package/src/__tests__/MDrawCanvas.test.ts +110 -0
  165. package/src/__tests__/MFloorPlan.test.ts +97 -0
  166. package/src/__tests__/MFlow.test.ts +575 -0
  167. package/src/__tests__/MGantt.test.ts +130 -0
  168. package/src/__tests__/MImageCropper.test.ts +89 -0
  169. package/src/__tests__/MPdfViewer.test.ts +235 -0
  170. package/src/__tests__/MResourceTimeline.test.ts +102 -0
  171. package/src/__tests__/MSlider.test.ts +36 -0
  172. package/src/__tests__/MVideoPlayer.test.ts +201 -0
  173. package/src/__tests__/drawGeometry.test.ts +58 -0
  174. package/src/__tests__/fieldExpose.test.ts +30 -0
  175. package/src/__tests__/flowFormats.test.ts +185 -0
  176. package/src/__tests__/flowLayout.test.ts +113 -0
  177. package/src/__tests__/ganttFormats.test.ts +76 -0
  178. package/src/__tests__/ganttSchedule.test.ts +136 -0
  179. package/src/__tests__/pdfMock.ts +83 -0
  180. package/src/__tests__/plugin.test.ts +56 -1
  181. package/src/__tests__/ssr.test.ts +1 -1
  182. package/src/__tests__/themeInitScript.test.ts +10 -0
  183. package/src/__tests__/useConfetti.test.ts +33 -2
  184. package/src/__tests__/useFireworks.test.ts +104 -0
  185. package/src/__tests__/useMediaPlayer.test.ts +182 -0
  186. package/src/__tests__/usePdf.test.ts +102 -0
  187. package/src/__tests__/useReactions.test.ts +51 -0
  188. package/src/__tests__/vSparkle.test.ts +83 -0
  189. package/src/components/MAudioPlayer.vue +319 -0
  190. package/src/components/MDrawCanvas.vue +813 -0
  191. package/src/components/MDrawLayers.vue +114 -0
  192. package/src/components/MDrawToolbar.vue +171 -0
  193. package/src/components/MEmojiSelector.vue +3 -2
  194. package/src/components/MFloorPlan.vue +581 -0
  195. package/src/components/MFlow.vue +2049 -0
  196. package/src/components/MFlowControls.vue +110 -0
  197. package/src/components/MFlowHandle.vue +60 -0
  198. package/src/components/MFlowMinimap.vue +134 -0
  199. package/src/components/MFlowNode.vue +98 -0
  200. package/src/components/MGantt.vue +1609 -0
  201. package/src/components/MGanttControls.vue +77 -0
  202. package/src/components/MIconButton.vue +3 -1
  203. package/src/components/MImageCropper.vue +507 -0
  204. package/src/components/MMap.vue +3 -2
  205. package/src/components/MMaskField.vue +13 -0
  206. package/src/components/MNumberField.vue +13 -0
  207. package/src/components/MPdfViewer.vue +1269 -0
  208. package/src/components/MResourceTimeline.vue +1020 -0
  209. package/src/components/MSlider.vue +22 -4
  210. package/src/components/MTagInput.vue +13 -0
  211. package/src/components/MTextField.vue +24 -4
  212. package/src/components/MVideoPlayer.vue +839 -0
  213. package/src/components/_MFlowEdge.vue +100 -0
  214. package/src/components/_MFlowEdgeLabel.vue +56 -0
  215. package/src/components/_MFlowNodeShell.vue +111 -0
  216. package/src/components/_MPdfPage.vue +456 -0
  217. package/src/components/_MTimeBackground.vue +16 -0
  218. package/src/components/_MTimeHeader.vue +31 -0
  219. package/src/composables/_colorUtils.ts +4 -2
  220. package/src/composables/_effectCanvas.ts +109 -0
  221. package/src/composables/_flowPanel.ts +13 -0
  222. package/src/composables/_flowSlot.ts +6 -0
  223. package/src/composables/_ganttTime.ts +200 -0
  224. package/src/composables/_ssrState.ts +2 -2
  225. package/src/composables/_storageKeys.ts +28 -0
  226. package/src/composables/_useTimeAxis.ts +224 -0
  227. package/src/composables/drawGeometry.ts +405 -0
  228. package/src/composables/flowFormats.ts +916 -0
  229. package/src/composables/flowLayout.ts +297 -0
  230. package/src/composables/flowPaths.ts +239 -0
  231. package/src/composables/ganttFormats.ts +366 -0
  232. package/src/composables/ganttSchedule.ts +403 -0
  233. package/src/composables/themeInitScript.ts +5 -2
  234. package/src/composables/useColorPalette.ts +36 -8
  235. package/src/composables/useConfetti.ts +84 -107
  236. package/src/composables/useDrawing.ts +53 -0
  237. package/src/composables/useFireworks.ts +360 -0
  238. package/src/composables/useFlow.ts +250 -0
  239. package/src/composables/useGantt.ts +92 -0
  240. package/src/composables/useLocale.ts +328 -0
  241. package/src/composables/useMediaPlayer.ts +406 -0
  242. package/src/composables/usePdf.ts +456 -0
  243. package/src/composables/useReactions.ts +131 -0
  244. package/src/composables/useResourceTimeline.ts +76 -0
  245. package/src/composables/useTheme.ts +21 -4
  246. package/src/composables/viewportHints.ts +6 -5
  247. package/src/directives/vSparkle.ts +180 -0
  248. package/src/draw.ts +25 -0
  249. package/src/flow.ts +26 -0
  250. package/src/gantt.ts +12 -0
  251. package/src/index.ts +11 -1
  252. package/src/locales/de.ts +163 -0
  253. package/src/locales/es.ts +163 -0
  254. package/src/locales/fr.ts +163 -0
  255. package/src/locales/ja.ts +163 -0
  256. package/src/locales/ko.ts +163 -0
  257. package/src/locales/pt.ts +163 -0
  258. package/src/locales/zh.ts +163 -0
  259. package/src/media.ts +5 -0
  260. package/src/pdf.ts +15 -0
  261. package/src/plugin.ts +21 -5
  262. package/dist/MMenuItem-DI351kIf.js +0 -929
  263. package/dist/MMenuItem-DI351kIf.js.map +0 -1
  264. package/dist/MSlider-BnEy5ieZ.js +0 -1500
  265. package/dist/MSlider-BnEy5ieZ.js.map +0 -1
  266. package/dist/MTextField-BBmkaIbO.js +0 -633
  267. package/dist/MTextField-BBmkaIbO.js.map +0 -1
  268. package/dist/useLocale-JYxDDeXC.js.map +0 -1
  269. package/dist/useThemeTokens-Bv-Uv8eX.js.map +0 -1
@@ -0,0 +1,403 @@
1
+ // Scheduling for MGantt, as pure functions over tasks: summaries rolled up from their children, dependencies pushed
2
+ // forward (or tasks pulled as soon as possible), the critical path with each task's slack, and working days.
3
+ // Tasks are treated as immutable: what changes comes back as new objects, the rest as they were.
4
+ import { DAY, addDays, daysBetween, formatDate, isDateOnly, isWorkingDay, parseDate, startOfDay } from './_ganttTime'
5
+
6
+ /** A predecessor of a task: finish-to-start (default), start-to-start, finish-to-finish or start-to-finish */
7
+ export interface GanttDependency {
8
+ /** The predecessor's id */
9
+ id: string
10
+ type?: 'FS' | 'SS' | 'FF' | 'SF'
11
+ /** Days between them (negative overlaps them); working days with a calendar */
12
+ lag?: number
13
+ }
14
+
15
+ /** A task. MGantt emits new arrays with new objects for whatever changed (`v-model:tasks`) */
16
+ export interface GanttTask<D = any> {
17
+ id: string
18
+ name: string
19
+ /** `YYYY-MM-DD` (whole days) or a datetime (`YYYY-MM-DDTHH:mm`, local, or ISO with a zone) */
20
+ start: string
21
+ /** A date is the last day (inclusive); a datetime is when it ends. A milestone needs none */
22
+ end?: string
23
+ /** 0 to 100 */
24
+ progress?: number
25
+ /** `summary` is implied for a task with children (its dates and progress roll up from them) */
26
+ type?: 'task' | 'milestone' | 'summary'
27
+ /** The summary task it belongs to */
28
+ parentId?: string
29
+ /** Its predecessors: ids (finish-to-start) or `GanttDependency` */
30
+ dependencies?: (string | GanttDependency)[]
31
+ /** An M3 role (default `primary`; `summary` defaults to `neutral`) */
32
+ color?: 'primary' | 'secondary' | 'tertiary' | 'error' | 'success' | 'neutral'
33
+ /** The plan it's compared with (MGantt's `baselines`) */
34
+ baselineStart?: string
35
+ baselineEnd?: string
36
+ /** `false` keeps it from being moved, resized, linked, deleted or selected */
37
+ draggable?: boolean
38
+ resizable?: boolean
39
+ linkable?: boolean
40
+ deletable?: boolean
41
+ selectable?: boolean
42
+ class?: string
43
+ data?: D
44
+ }
45
+
46
+ /** Which days are worked: weekdays (0 Sunday … 6 Saturday, default Monday to Friday) and holidays (`YYYY-MM-DD`) */
47
+ export interface GanttCalendar {
48
+ workingDays?: number[]
49
+ holidays?: string[]
50
+ }
51
+
52
+ export interface GanttScheduleOptions {
53
+ /** `'push'` (default) moves tasks only as late as their dependencies need; `'asap'` also pulls them back to the earliest they can start */
54
+ mode?: 'push' | 'asap'
55
+ /** Count durations and lags in working days (date-only tasks), starting on working days */
56
+ calendar?: GanttCalendar
57
+ }
58
+
59
+ export interface GanttCriticalPath {
60
+ /** Tasks with no slack (and summaries holding one) */
61
+ tasks: string[]
62
+ /** Dependencies on the path, as `'<predecessor>><successor>'` */
63
+ dependencies: string[]
64
+ /** Each task's total slack in days: how late it can finish without delaying the end */
65
+ slack: Record<string, number>
66
+ /** When the last task ends */
67
+ finish: string
68
+ }
69
+
70
+ export function normalizeDependency(d: string | GanttDependency): Required<GanttDependency> {
71
+ return typeof d === 'string' ? { id: d, type: 'FS', lag: 0 } : { id: d.id, type: d.type ?? 'FS', lag: d.lag ?? 0 }
72
+ }
73
+
74
+ /** Ids of tasks that have children */
75
+ export function summaryIds(tasks: readonly GanttTask[]): Set<string> {
76
+ const ids = new Set(tasks.map((t) => t.id))
77
+ const out = new Set<string>()
78
+ for (const t of tasks) if (t.parentId && ids.has(t.parentId)) out.add(t.parentId)
79
+ for (const t of tasks) if (t.type === 'summary') out.add(t.id)
80
+ return out
81
+ }
82
+
83
+ export function isMilestone(t: GanttTask): boolean {
84
+ return t.type === 'milestone' || (!t.end && t.type !== 'summary')
85
+ }
86
+
87
+ /** A task's span in ms, end exclusive: a date-only end runs to the next midnight; a milestone has none */
88
+ export function taskSpan(t: Pick<GanttTask, 'start' | 'end' | 'type'>): { start: number; end: number; dateOnly: boolean } {
89
+ const start = parseDate(t.start)
90
+ const dateOnly = isDateOnly(t.start)
91
+ if (t.type === 'milestone' || !t.end) return { start, end: start, dateOnly }
92
+ const e = parseDate(t.end)
93
+ const end = isDateOnly(t.end) ? addDays(startOfDay(e), 1) : e
94
+ return { start, end: Math.max(start, end), dateOnly }
95
+ }
96
+
97
+ /** The task's `start`/`end` strings for a span (end exclusive), in the format it came in */
98
+ export function spanDates(t: Pick<GanttTask, 'start' | 'end' | 'type'>, start: number, end: number): { start: string; end?: string } {
99
+ const dateOnly = isDateOnly(t.start)
100
+ if (t.type === 'milestone' || !t.end) return { start: formatDate(dateOnly ? startOfDay(start) : start, dateOnly) }
101
+ if (dateOnly) {
102
+ const s = startOfDay(start)
103
+ const last = Math.max(s, startOfDay(end - 1))
104
+ return { start: formatDate(s, true), end: formatDate(last, true) }
105
+ }
106
+ return { start: formatDate(start, false), end: formatDate(Math.max(start, end), false) }
107
+ }
108
+
109
+ /** Duration in whole days (date-only tasks) or fractions of a day */
110
+ export function taskDays(t: GanttTask): number {
111
+ const s = taskSpan(t)
112
+ return s.dateOnly ? daysBetween(s.start, s.end) : (s.end - s.start) / DAY
113
+ }
114
+
115
+ /**
116
+ * Summaries take the span of their children (deepest first) and their progress, weighted by duration. Returns the
117
+ * same array when nothing changes.
118
+ */
119
+ export function rollupSummaries<T extends GanttTask>(tasks: readonly T[]): T[] {
120
+ const sums = summaryIds(tasks)
121
+ if (!sums.size) return tasks as T[]
122
+ const kids = new Map<string, T[]>()
123
+ for (const t of tasks) if (t.parentId && sums.has(t.parentId)) (kids.get(t.parentId) ?? kids.set(t.parentId, []).get(t.parentId)!).push(t)
124
+ const out = new Map<string, T>()
125
+ const visiting = new Set<string>()
126
+ const resolve = (t: T): T => {
127
+ if (!sums.has(t.id) || !kids.has(t.id)) return out.get(t.id) ?? t
128
+ if (out.has(t.id)) return out.get(t.id)!
129
+ if (visiting.has(t.id)) return t
130
+ visiting.add(t.id)
131
+ let start = Infinity
132
+ let end = -Infinity
133
+ let dateOnly = true
134
+ let work = 0
135
+ let done = 0
136
+ for (const k of kids.get(t.id)!) {
137
+ const r = resolve(k)
138
+ const s = taskSpan(r)
139
+ if (!Number.isFinite(s.start)) continue
140
+ start = Math.min(start, s.start)
141
+ end = Math.max(end, s.end)
142
+ if (!s.dateOnly) dateOnly = false
143
+ const w = Math.max(s.end - s.start, isMilestone(r) ? 0 : 1)
144
+ work += w
145
+ done += w * (r.progress ?? 0)
146
+ }
147
+ visiting.delete(t.id)
148
+ if (!Number.isFinite(start)) return t
149
+ const dates = dateOnly
150
+ ? { start: formatDate(start, true), end: formatDate(Math.max(start, startOfDay(end - 1)), true) }
151
+ : { start: formatDate(start, false), end: formatDate(end, false) }
152
+ const progress = work ? Math.round(done / work) : (t.progress ?? 0)
153
+ const next = dates.start === t.start && dates.end === t.end && progress === (t.progress ?? 0) ? t : { ...t, start: dates.start, end: dates.end, progress }
154
+ out.set(t.id, next)
155
+ return next
156
+ }
157
+ let changed = false
158
+ const result = tasks.map((t) => {
159
+ const r = resolve(t)
160
+ if (r !== t) changed = true
161
+ return r
162
+ })
163
+ return changed ? result : (tasks as T[])
164
+ }
165
+
166
+ // ── Working days ──────────────────────────────────────────────────────────────────────────────────────────
167
+
168
+ function calendarOf(c?: GanttCalendar) {
169
+ return { days: c?.workingDays ?? [1, 2, 3, 4, 5], holidays: new Set(c?.holidays ?? []) }
170
+ }
171
+
172
+ /** Working days from `start` to `end`, both included (`YYYY-MM-DD`) */
173
+ export function workingDays(start: string, end: string, calendar?: GanttCalendar): number {
174
+ const c = calendarOf(calendar)
175
+ let n = 0
176
+ const last = startOfDay(parseDate(end))
177
+ for (let d = startOfDay(parseDate(start)); d <= last; d = addDays(d, 1)) if (isWorkingDay(d, c.days, c.holidays)) n++
178
+ return n
179
+ }
180
+
181
+ /** The date `n` working days after `date` (before it when negative); 0 moves a day off to the next working day */
182
+ export function addWorkingDays(date: string, n: number, calendar?: GanttCalendar): string {
183
+ const c = calendarOf(calendar)
184
+ if (!c.days.length) return date
185
+ let d = startOfDay(parseDate(date))
186
+ while (!isWorkingDay(d, c.days, c.holidays)) d = addDays(d, 1)
187
+ const step = n < 0 ? -1 : 1
188
+ for (let left = Math.abs(n); left > 0; ) {
189
+ d = addDays(d, step)
190
+ if (isWorkingDay(d, c.days, c.holidays)) left--
191
+ }
192
+ return formatDate(d, true)
193
+ }
194
+
195
+ // ── Scheduling ────────────────────────────────────────────────────────────────────────────────────────────
196
+
197
+ interface Link { pred: string; succ: string; type: 'FS' | 'SS' | 'FF' | 'SF'; lag: number; key: string }
198
+
199
+ // Dependencies between plain tasks: one onto a summary applies to each of its tasks (as MS Project does), one
200
+ // from a summary is resolved against its span once its tasks are placed
201
+ function expandLinks(tasks: readonly GanttTask[]) {
202
+ const byId = new Map(tasks.map((t) => [t.id, t]))
203
+ const sums = summaryIds(tasks)
204
+ const kids = new Map<string, string[]>()
205
+ for (const t of tasks) if (t.parentId && byId.has(t.parentId)) (kids.get(t.parentId) ?? kids.set(t.parentId, []).get(t.parentId)!).push(t.id)
206
+ const leaves = (id: string, depth = 0): string[] => (sums.has(id) && kids.has(id) && depth < 100 ? kids.get(id)!.flatMap((k) => leaves(k, depth + 1)) : [id])
207
+ const links: Link[] = []
208
+ for (const t of tasks) {
209
+ for (const raw of t.dependencies ?? []) {
210
+ const d = normalizeDependency(raw)
211
+ if (!byId.has(d.id) || d.id === t.id) continue
212
+ for (const succ of leaves(t.id)) links.push({ pred: d.id, succ, type: d.type, lag: d.lag, key: `${d.id}>${t.id}` })
213
+ }
214
+ }
215
+ return { byId, sums, kids, leaves, links }
216
+ }
217
+
218
+ // Order: a task after everything it waits for; a summary used as a predecessor after its tasks. Cycles are cut
219
+ function order(ids: string[], deps: Map<string, string[]>): string[] {
220
+ const out: string[] = []
221
+ const state = new Map<string, 1 | 2>()
222
+ const visit = (id: string) => {
223
+ if (state.get(id)) return
224
+ state.set(id, 1)
225
+ for (const p of deps.get(id) ?? []) if (state.get(p) !== 1) visit(p)
226
+ state.set(id, 2)
227
+ out.push(id)
228
+ }
229
+ for (const id of ids) visit(id)
230
+ return out
231
+ }
232
+
233
+ /**
234
+ * Moves tasks so every dependency holds: by default only later (`'push'`, what dragging a predecessor does), or as
235
+ * soon as possible (`'asap'`), keeping each task's duration. Summaries follow their tasks. Returns the same array
236
+ * when nothing moves.
237
+ */
238
+ export function scheduleTasks<T extends GanttTask>(tasks: readonly T[], options: GanttScheduleOptions = {}): T[] {
239
+ const { sums, kids, leaves, links } = expandLinks(tasks)
240
+ const cal = options.calendar ? calendarOf(options.calendar) : null
241
+ const spans = new Map<string, { start: number; end: number; dateOnly: boolean }>()
242
+ for (const t of tasks) if (!sums.has(t.id)) spans.set(t.id, taskSpan(t))
243
+ const deps = new Map<string, string[]>()
244
+ for (const l of links) (deps.get(l.succ) ?? deps.set(l.succ, []).get(l.succ)!).push(l.pred)
245
+ for (const s of sums) deps.set(s, [...(deps.get(s) ?? []), ...leaves(s)])
246
+ const bySucc = new Map<string, Link[]>()
247
+ for (const l of links) (bySucc.get(l.succ) ?? bySucc.set(l.succ, []).get(l.succ)!).push(l)
248
+
249
+ const span = (id: string) => {
250
+ if (!sums.has(id)) return spans.get(id)
251
+ let start = Infinity
252
+ let end = -Infinity
253
+ for (const l of leaves(id)) {
254
+ const s = spans.get(l)
255
+ if (!s) continue
256
+ start = Math.min(start, s.start)
257
+ end = Math.max(end, s.end)
258
+ }
259
+ return Number.isFinite(start) ? { start, end, dateOnly: true } : undefined
260
+ }
261
+ // Shift by days, on working days with a calendar
262
+ const shift = (ms: number, days: number, dateOnly: boolean) => {
263
+ if (!cal || !dateOnly) return ms + days * DAY
264
+ return parseDate(addWorkingDays(formatDate(ms, true), days, options.calendar))
265
+ }
266
+ const workLength = (s: { start: number; end: number }) => {
267
+ let n = 0
268
+ for (let d = s.start; d < s.end; d = addDays(d, 1)) if (isWorkingDay(d, cal!.days, cal!.holidays)) n++
269
+ return n
270
+ }
271
+
272
+ let moved = false
273
+ for (const id of order([...spans.keys(), ...sums], deps)) {
274
+ if (sums.has(id)) continue
275
+ const own = spans.get(id)!
276
+ const incoming = bySucc.get(id)
277
+ if (!incoming?.length || !Number.isFinite(own.start)) continue
278
+ const dur = own.end - own.start
279
+ let earliest = -Infinity
280
+ for (const l of incoming) {
281
+ const p = span(l.pred)
282
+ if (!p) continue
283
+ const pd = p.dateOnly && own.dateOnly
284
+ let need: number
285
+ if (l.type === 'FS') need = shift(p.end, l.lag, pd)
286
+ else if (l.type === 'SS') need = shift(p.start, l.lag, pd)
287
+ else if (l.type === 'FF') need = shift(p.end, l.lag, pd) - dur
288
+ else need = shift(p.start, l.lag, pd) - dur
289
+ earliest = Math.max(earliest, need)
290
+ }
291
+ if (!Number.isFinite(earliest)) continue
292
+ let start = options.mode === 'asap' ? earliest : Math.max(own.start, earliest)
293
+ if (own.dateOnly) start = startOfDay(start + 12 * 3_600_000)
294
+ let end = start + dur
295
+ if (cal && own.dateOnly) {
296
+ // Starts on a working day and lasts as many working days as before
297
+ const days = workLength(own)
298
+ start = parseDate(addWorkingDays(formatDate(start, true), 0, options.calendar))
299
+ end = days ? addDays(parseDate(addWorkingDays(formatDate(start, true), Math.max(0, days - 1), options.calendar)), 1) : start
300
+ } else if (own.dateOnly) end = addDays(start, daysBetween(own.start, own.end))
301
+ if (start !== own.start || end !== own.end) {
302
+ spans.set(id, { start, end, dateOnly: own.dateOnly })
303
+ moved = true
304
+ }
305
+ }
306
+ if (!moved) return rollupSummaries(tasks)
307
+ const next = tasks.map((t) => {
308
+ if (sums.has(t.id) && kids.has(t.id)) return t
309
+ const s = spans.get(t.id)
310
+ const before = taskSpan(t)
311
+ if (!s || (s.start === before.start && s.end === before.end)) return t
312
+ return { ...t, ...spanDates(t, s.start, s.end) }
313
+ })
314
+ return rollupSummaries(next)
315
+ }
316
+
317
+ /**
318
+ * The critical path over the tasks' current dates: tasks whose delay would delay the last one's end (no slack),
319
+ * through their dependencies. Slack is in calendar days, or working days with a calendar (so a weekend between
320
+ * two tasks isn't slack).
321
+ */
322
+ export function criticalPath(tasks: readonly GanttTask[], options: { calendar?: GanttCalendar } = {}): GanttCriticalPath {
323
+ const { sums, kids, leaves, links } = expandLinks(tasks)
324
+ const real = new Map<string, { start: number; end: number }>()
325
+ for (const t of tasks) if (!sums.has(t.id) || !kids.has(t.id)) real.set(t.id, taskSpan(t))
326
+ const ids = [...real.keys()].filter((id) => Number.isFinite(real.get(id)!.start))
327
+ if (!ids.length) return { tasks: [], dependencies: [], slack: {}, finish: '' }
328
+
329
+ // Everything below runs in days: calendar days, or with a calendar working days (a day off has no length), so
330
+ // the weekend between two tasks is neither slack nor duration
331
+ const cal = options.calendar ? calendarOf(options.calendar) : null
332
+ let toDays = (ms: number) => ms / DAY
333
+ if (cal) {
334
+ const first = startOfDay(Math.min(...ids.map((id) => real.get(id)!.start)))
335
+ const index = new Map<number, number>()
336
+ toDays = (ms: number) => {
337
+ const day = startOfDay(ms)
338
+ let n = index.get(day)
339
+ if (n === undefined) {
340
+ n = 0
341
+ const step = day >= first ? 1 : -1
342
+ for (let d = first; d !== day; d = addDays(d, step)) if (isWorkingDay(step > 0 ? d : addDays(d, -1), cal.days, cal.holidays)) n += step
343
+ index.set(day, n)
344
+ }
345
+ return n + (isWorkingDay(day, cal.days, cal.holidays) ? (ms - day) / DAY : 0)
346
+ }
347
+ }
348
+ const spans = new Map(ids.map((id) => [id, { start: toDays(real.get(id)!.start), end: toDays(real.get(id)!.end) }]))
349
+ // Links from a summary come from each of its tasks
350
+ const flat: Link[] = links.flatMap((l) => (sums.has(l.pred) && kids.has(l.pred) ? leaves(l.pred).map((p) => ({ ...l, pred: p })) : [l]))
351
+ .filter((l) => spans.has(l.pred) && spans.has(l.succ))
352
+ const finish = Math.max(...ids.map((id) => spans.get(id)!.end))
353
+ const out = new Map<string, Link[]>()
354
+ const deps = new Map<string, string[]>()
355
+ for (const l of flat) {
356
+ ;(out.get(l.pred) ?? out.set(l.pred, []).get(l.pred)!).push(l)
357
+ ;(deps.get(l.succ) ?? deps.set(l.succ, []).get(l.succ)!).push(l.pred)
358
+ }
359
+ const late = new Map<string, number>()
360
+ // Backward pass: successors first
361
+ for (const id of order(ids, deps).reverse()) {
362
+ const s = spans.get(id)!
363
+ const dur = s.end - s.start
364
+ let lf = finish
365
+ for (const l of out.get(id) ?? []) {
366
+ const ls = late.get(l.succ)
367
+ if (ls === undefined) continue
368
+ const succ = spans.get(l.succ)!
369
+ const lfSucc = ls + (succ.end - succ.start)
370
+ if (l.type === 'FS') lf = Math.min(lf, ls - l.lag)
371
+ else if (l.type === 'SS') lf = Math.min(lf, ls - l.lag + dur)
372
+ else if (l.type === 'FF') lf = Math.min(lf, lfSucc - l.lag)
373
+ else lf = Math.min(lf, lfSucc - l.lag + dur)
374
+ }
375
+ late.set(id, lf - dur)
376
+ }
377
+ const slack: Record<string, number> = {}
378
+ const critical = new Set<string>()
379
+ for (const id of ids) {
380
+ const days = late.get(id)! - spans.get(id)!.start
381
+ slack[id] = Math.round(days * 1000) / 1000
382
+ if (days < 1e-6) critical.add(id)
383
+ }
384
+ // A dependency is on the path when both ends are and it's what holds the successor back
385
+ const tight = new Set<string>()
386
+ for (const l of flat) {
387
+ if (!critical.has(l.pred) || !critical.has(l.succ)) continue
388
+ const p = spans.get(l.pred)!
389
+ const s = spans.get(l.succ)!
390
+ const from = (l.type === 'FS' || l.type === 'FF' ? p.end : p.start) + l.lag
391
+ const to = l.type === 'FS' || l.type === 'SS' ? s.start : s.end
392
+ if (Math.abs(to - from) < 1e-6) tight.add(l.key)
393
+ }
394
+ for (const s of sums) if (kids.has(s) && leaves(s).some((l) => critical.has(l))) critical.add(s)
395
+ const end = Math.max(...ids.map((id) => real.get(id)!.end))
396
+ const last = tasks.find((t) => real.get(t.id)?.end === end)
397
+ return {
398
+ tasks: tasks.filter((t) => critical.has(t.id)).map((t) => t.id),
399
+ dependencies: [...tight],
400
+ slack,
401
+ finish: formatDate(isDateOnly(last?.start) ? addDays(end, -1) : end, isDateOnly(last?.start)),
402
+ }
403
+ }
@@ -1,4 +1,4 @@
1
- import { THEME_KEY } from './useTheme'
1
+ import { THEME_KEY, storageKey } from './_storageKeys'
2
2
  import { CONTRAST_KEY, CSS_KEY, PALETTE_KEY, STYLE_ID, type ContrastLevel, type PaletteId } from './useColorPalette'
3
3
 
4
4
  export interface ThemeInitOptions {
@@ -8,6 +8,8 @@ export interface ThemeInitOptions {
8
8
  contrast?: ContrastLevel
9
9
  /** `createM3UI`'s `persistPalette`. */
10
10
  persistPalette?: boolean
11
+ /** `createM3UI`'s `storagePrefix`. */
12
+ storagePrefix?: string
11
13
  }
12
14
 
13
15
  /**
@@ -24,7 +26,8 @@ export interface ThemeInitOptions {
24
26
  */
25
27
  export function themeInitScript(options: ThemeInitOptions = {}): string {
26
28
  const config = JSON.stringify({
27
- keys: { theme: THEME_KEY, palette: PALETTE_KEY, contrast: CONTRAST_KEY, css: CSS_KEY },
29
+ keys: Object.fromEntries(Object.entries({ theme: THEME_KEY, palette: PALETTE_KEY, contrast: CONTRAST_KEY, css: CSS_KEY })
30
+ .map(([name, key]) => [name, storageKey(key, options.storagePrefix ?? '')])),
28
31
  styleId: STYLE_ID,
29
32
  palette: options.palette ?? null,
30
33
  contrast: options.contrast ?? null,
@@ -2,7 +2,7 @@ import { computed, readonly, ref, watch, watchEffect, type Ref } from 'vue'
2
2
  import { generateScheme, schemeToCss, type SeedOptions } from './dynamicColor'
3
3
  import { themeTransition } from './_themeTransition'
4
4
  import { initialState, readCookie, ssrValue, writeCookie } from './_ssrState'
5
- import { STYLE_ID } from './_storageKeys'
5
+ import { STYLE_ID, onStoragePrefix, storageKey } from './_storageKeys'
6
6
 
7
7
  export interface Palette {
8
8
  id: string
@@ -82,18 +82,20 @@ export const CSS_KEY = 'm3-palette-css'
82
82
  function read<T>(key: string): T | null {
83
83
  try {
84
84
  // The palette and the contrast level fall back to their cookies (createM3UI({ cookies })) when storage has none
85
- const v = localStorage.getItem(key) ?? (key === PALETTE_KEY || key === CONTRAST_KEY ? readCookie(key) : null)
85
+ const name = storageKey(key)
86
+ const v = localStorage.getItem(name) ?? (key === PALETTE_KEY || key === CONTRAST_KEY ? readCookie(name) : null)
86
87
  return v == null ? null : (key === PALETTE_KEY || key === CONTRAST_KEY ? v : JSON.parse(v)) as T
87
88
  } catch {
88
89
  return null
89
90
  }
90
91
  }
91
92
  function write(key: string, value: unknown) {
93
+ const name = storageKey(key)
92
94
  // The palette and the contrast level also go in cookies (createM3UI({ cookies: true })) for a server to read
93
- if (key === PALETTE_KEY || key === CONTRAST_KEY) writeCookie(key, value == null ? null : String(value))
95
+ if (key === PALETTE_KEY || key === CONTRAST_KEY) writeCookie(name, value == null ? null : String(value))
94
96
  try {
95
- if (value == null) localStorage.removeItem(key)
96
- else localStorage.setItem(key, typeof value === 'string' ? value : JSON.stringify(value))
97
+ if (value == null) localStorage.removeItem(name)
98
+ else localStorage.setItem(name, typeof value === 'string' ? value : JSON.stringify(value))
97
99
  } catch { /* storage blocked */ }
98
100
  }
99
101
 
@@ -107,8 +109,11 @@ const activeSeed = ref<ActiveSeed | null>(read<ActiveSeed>(SEED_KEY))
107
109
  */
108
110
  export type ContrastLevel = 'standard' | 'medium' | 'high' | 'system'
109
111
  const CONTRAST_LEVELS: readonly ContrastLevel[] = ['standard', 'medium', 'high', 'system']
110
- const storedContrast = read<string>(CONTRAST_KEY)
111
- const contrast = ref<ContrastLevel>(CONTRAST_LEVELS.includes(storedContrast as ContrastLevel) ? storedContrast as ContrastLevel : 'standard')
112
+ function readContrast(): ContrastLevel {
113
+ const stored = read<string>(CONTRAST_KEY)
114
+ return CONTRAST_LEVELS.includes(stored as ContrastLevel) ? stored as ContrastLevel : 'standard'
115
+ }
116
+ const contrast = ref<ContrastLevel>(readContrast())
112
117
  const systemMore = ref(false)
113
118
  if (typeof window !== 'undefined' && window.matchMedia) {
114
119
  const mq = window.matchMedia('(prefers-contrast: more)')
@@ -238,7 +243,14 @@ async function selectContrast(level: ContrastLevel, persist = persistEnabled.val
238
243
 
239
244
  // Applied on every change of the effective level (a setting or the OS preference), for every palette kind. A
240
245
  // generated palette is regenerated first, then swapped in with the attribute in one transition.
246
+ // Set while createM3UI({ storagePrefix }) loads another stored level: it's applied right away, with no transition
247
+ let skipContrastWatch = false
248
+
241
249
  watch(activeContrast, async () => {
250
+ if (skipContrastWatch) {
251
+ skipContrastWatch = false
252
+ return
253
+ }
242
254
  const id = current.value
243
255
  let css: string | null | undefined
244
256
  if (id === SEED_PALETTE && activeSeed.value) css = await generateCss(SEED_PALETTE, activeSeed.value)
@@ -308,7 +320,7 @@ export function useColorPalette() {
308
320
 
309
321
  // Apply on module load so the palette is visible before any component mounts, a generated one included (not on
310
322
  // the server: the client does it when the module loads there)
311
- if (typeof document !== 'undefined') {
323
+ function applyStored() {
312
324
  const saved = read<string>(PALETTE_KEY)
313
325
  const cached = read<{ id: string; css: string }>(CSS_KEY)
314
326
  if (saved && cached && cached.id === saved) injectCss(cached.css)
@@ -316,6 +328,22 @@ if (typeof document !== 'undefined') {
316
328
  applyContrast(activeContrast.value)
317
329
  }
318
330
 
331
+ if (typeof document !== 'undefined') applyStored()
332
+
333
+ // createM3UI({ storagePrefix }): this app's own stored palette, seed and contrast, applied before anything renders
334
+ onStoragePrefix(() => {
335
+ if (typeof document === 'undefined') return
336
+ generation++
337
+ current.value = read<string>(PALETTE_KEY) ?? 'purple'
338
+ activeSeed.value = read<ActiveSeed>(SEED_KEY)
339
+ const before = activeContrast.value
340
+ contrast.value = readContrast()
341
+ if (activeContrast.value !== before) skipContrastWatch = true
342
+ document.getElementById(STYLE_ID)?.remove()
343
+ applyAttribute(current.value)
344
+ applyStored()
345
+ })
346
+
319
347
  /**
320
348
  * Internal: used by `createM3UI({ palette, persistPalette: false })` to force a palette on boot,
321
349
  * bypassing whatever is already in localStorage, without waiting for a component to call