@m3ui-vue/m3ui-vue 1.2.2 → 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.
- package/dist/API.md +2776 -351
- package/dist/MButton-CuNzpoxm.js +172 -0
- package/dist/MButton-CuNzpoxm.js.map +1 -0
- package/dist/MDialog-HxEL-m58.js +173 -0
- package/dist/MDialog-HxEL-m58.js.map +1 -0
- package/dist/MIconButton-DoNotQ9v.js +282 -0
- package/dist/MIconButton-DoNotQ9v.js.map +1 -0
- package/dist/MListItem-DnPtv-hY.js +824 -0
- package/dist/MListItem-DnPtv-hY.js.map +1 -0
- package/dist/MLoadingIndicator-BQMNX6Dx.js +115 -0
- package/dist/MLoadingIndicator-BQMNX6Dx.js.map +1 -0
- package/dist/MMenuItem-Bih0h4-n.js +604 -0
- package/dist/MMenuItem-Bih0h4-n.js.map +1 -0
- package/dist/MProgressBar-BCoruxA-.js +184 -0
- package/dist/MProgressBar-BCoruxA-.js.map +1 -0
- package/dist/MSeekBar-LURE1Ah7.js +435 -0
- package/dist/MSeekBar-LURE1Ah7.js.map +1 -0
- package/dist/MSegmentedButton-DL9JtJFX.js +65 -0
- package/dist/MSegmentedButton-DL9JtJFX.js.map +1 -0
- package/dist/MSlider-_J4IS2_z.js +691 -0
- package/dist/MSlider-_J4IS2_z.js.map +1 -0
- package/dist/MSpinner-BhkMYKOM.js +65 -0
- package/dist/MSpinner-BhkMYKOM.js.map +1 -0
- package/dist/MTextField-CkzwNBWS.js +296 -0
- package/dist/MTextField-CkzwNBWS.js.map +1 -0
- package/dist/MTooltip-B67ZDSGp.js +756 -0
- package/dist/MTooltip-B67ZDSGp.js.map +1 -0
- package/dist/_storageKeys-CYXsUBwK.js +18 -0
- package/dist/_storageKeys-CYXsUBwK.js.map +1 -0
- package/dist/_useEscapeStack-CjndQhqg.js +19 -0
- package/dist/_useEscapeStack-CjndQhqg.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/chart.js +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MAudioPlayer.vue.d.ts +115 -0
- package/dist/components/MBadge.vue.d.ts +1 -1
- package/dist/components/MBottomSheetScaffold.vue.d.ts +1 -1
- package/dist/components/MBox.vue.d.ts +1 -1
- package/dist/components/MButton.vue.d.ts +1 -1
- package/dist/components/MConfirmDialog.vue.d.ts +1 -1
- package/dist/components/MCopyButton.vue.d.ts +2 -2
- package/dist/components/MDataTable.vue.d.ts +2 -2
- package/dist/components/MDialog.vue.d.ts +2 -2
- package/dist/components/MDivider.vue.d.ts +1 -1
- package/dist/components/MDragHandle.vue.d.ts +1 -1
- package/dist/components/MDrawCanvas.vue.d.ts +148 -0
- package/dist/components/MDrawLayers.vue.d.ts +3 -0
- package/dist/components/MDrawToolbar.vue.d.ts +34 -0
- package/dist/components/MExportButton.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +2 -2
- package/dist/components/MFabMenu.vue.d.ts +2 -2
- package/dist/components/MFixed.vue.d.ts +1 -1
- package/dist/components/MFlex.vue.d.ts +2 -2
- package/dist/components/MFloorPlan.vue.d.ts +160 -0
- package/dist/components/MFlow.vue.d.ts +305 -0
- package/dist/components/MFlowControls.vue.d.ts +33 -0
- package/dist/components/MFlowHandle.vue.d.ts +16 -0
- package/dist/components/MFlowMinimap.vue.d.ts +22 -0
- package/dist/components/MFlowNode.vue.d.ts +35 -0
- package/dist/components/MGantt.vue.d.ts +141 -0
- package/dist/components/MGanttControls.vue.d.ts +32 -0
- package/dist/components/MIconButton.vue.d.ts +3 -1
- package/dist/components/MImageCropper.vue.d.ts +110 -0
- package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
- package/dist/components/MLightbox.vue.d.ts +2 -2
- package/dist/components/MList.vue.d.ts +1 -1
- package/dist/components/MLoadingOverlay.vue.d.ts +1 -1
- package/dist/components/MMapControl.vue.d.ts +1 -1
- package/dist/components/MMapSearch.vue.d.ts +1 -1
- package/dist/components/MMaskField.vue.d.ts +12 -1
- package/dist/components/MMenu.vue.d.ts +1 -1
- package/dist/components/MNavigationDrawer.vue.d.ts +1 -1
- package/dist/components/MNumberField.vue.d.ts +11 -2
- package/dist/components/MPdfViewer.vue.d.ts +174 -0
- package/dist/components/MPullToRefresh.vue.d.ts +1 -1
- package/dist/components/MResourceTimeline.vue.d.ts +149 -0
- package/dist/components/MScheduler.vue.d.ts +3 -3
- package/dist/components/MScheme.vue.d.ts +1 -1
- package/dist/components/MSearchField.vue.d.ts +1 -1
- package/dist/components/MSeekBar.vue.d.ts +1 -1
- package/dist/components/MSimpleCarousel.vue.d.ts +1 -1
- package/dist/components/MSkeleton.vue.d.ts +1 -1
- package/dist/components/MSlider.vue.d.ts +2 -2
- package/dist/components/MSparkline.vue.d.ts +1 -1
- package/dist/components/MSplitter.vue.d.ts +1 -1
- package/dist/components/MStack.vue.d.ts +2 -2
- package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
- package/dist/components/MSwitch.vue.d.ts +1 -1
- package/dist/components/MTable.vue.d.ts +1 -1
- package/dist/components/MTagInput.vue.d.ts +12 -1
- package/dist/components/MTextField.vue.d.ts +13 -2
- package/dist/components/MToolbar.vue.d.ts +1 -1
- package/dist/components/MTree.vue.d.ts +2 -2
- package/dist/components/MVideoPlayer.vue.d.ts +253 -0
- package/dist/components/MVirtualTable.vue.d.ts +1 -1
- package/dist/components/MWindow.vue.d.ts +3 -3
- package/dist/components/_MFlowEdge.vue.d.ts +9 -0
- package/dist/components/_MFlowEdgeLabel.vue.d.ts +9 -0
- package/dist/components/_MFlowNodeShell.vue.d.ts +9 -0
- package/dist/components/_MPdfPage.vue.d.ts +76 -0
- package/dist/components/_MTimeBackground.vue.d.ts +14 -0
- package/dist/components/_MTimeHeader.vue.d.ts +20 -0
- package/dist/composables/_flowPanel.d.ts +2 -0
- package/dist/composables/_flowSlot.d.ts +5 -0
- package/dist/composables/_ganttTime.d.ts +41 -0
- package/dist/composables/_useTimeAxis.d.ts +90 -0
- package/dist/composables/drawGeometry.d.ts +119 -0
- package/dist/composables/flowFormats.d.ts +79 -0
- package/dist/composables/flowLayout.d.ts +45 -0
- package/dist/composables/flowPaths.d.ts +53 -0
- package/dist/composables/ganttFormats.d.ts +52 -0
- package/dist/composables/ganttSchedule.d.ts +99 -0
- package/dist/composables/useDrawing.d.ts +44 -0
- package/dist/composables/useFlow.d.ts +266 -0
- package/dist/composables/useGantt.d.ts +87 -0
- package/dist/composables/useLocale.d.ts +163 -0
- package/dist/composables/useMediaPlayer.d.ts +101 -0
- package/dist/composables/usePdf.d.ts +119 -0
- package/dist/composables/useResourceTimeline.d.ts +70 -0
- package/dist/draw.d.ts +7 -0
- package/dist/draw.js +1700 -0
- package/dist/draw.js.map +1 -0
- package/dist/flow.d.ts +14 -0
- package/dist/flow.js +3542 -0
- package/dist/flow.js.map +1 -0
- package/dist/flowPaths-CUc6X373.js +161 -0
- package/dist/flowPaths-CUc6X373.js.map +1 -0
- package/dist/gantt.d.ts +12 -0
- package/dist/gantt.js +3575 -0
- package/dist/gantt.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/locales/index.js +1148 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7286 -7654
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +113 -108
- package/dist/map.js.map +1 -1
- package/dist/media.d.ts +5 -0
- package/dist/media.js +1311 -0
- package/dist/media.js.map +1 -0
- package/dist/pdf.d.ts +4 -0
- package/dist/pdf.js +1871 -0
- package/dist/pdf.js.map +1 -0
- package/dist/rich-text-editor.js +28 -26
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/{useLocale-JYxDDeXC.js → useLocale-BpGxplLV.js} +165 -2
- package/dist/useLocale-BpGxplLV.js.map +1 -0
- package/dist/{useThemeTokens-y0HZpyhL.js → useThemeTokens-DQQcaWbE.js} +40 -54
- package/dist/useThemeTokens-DQQcaWbE.js.map +1 -0
- package/package.json +29 -5
- package/src/__tests__/MAudioPlayer.test.ts +75 -0
- package/src/__tests__/MDrawCanvas.test.ts +110 -0
- package/src/__tests__/MFloorPlan.test.ts +97 -0
- package/src/__tests__/MFlow.test.ts +575 -0
- package/src/__tests__/MGantt.test.ts +130 -0
- package/src/__tests__/MImageCropper.test.ts +89 -0
- package/src/__tests__/MPdfViewer.test.ts +235 -0
- package/src/__tests__/MResourceTimeline.test.ts +102 -0
- package/src/__tests__/MVideoPlayer.test.ts +201 -0
- package/src/__tests__/drawGeometry.test.ts +58 -0
- package/src/__tests__/fieldExpose.test.ts +30 -0
- package/src/__tests__/flowFormats.test.ts +185 -0
- package/src/__tests__/flowLayout.test.ts +113 -0
- package/src/__tests__/ganttFormats.test.ts +76 -0
- package/src/__tests__/ganttSchedule.test.ts +136 -0
- package/src/__tests__/pdfMock.ts +83 -0
- package/src/__tests__/useMediaPlayer.test.ts +182 -0
- package/src/__tests__/usePdf.test.ts +102 -0
- package/src/components/MAudioPlayer.vue +319 -0
- package/src/components/MDrawCanvas.vue +813 -0
- package/src/components/MDrawLayers.vue +114 -0
- package/src/components/MDrawToolbar.vue +171 -0
- package/src/components/MFloorPlan.vue +581 -0
- package/src/components/MFlow.vue +2049 -0
- package/src/components/MFlowControls.vue +110 -0
- package/src/components/MFlowHandle.vue +60 -0
- package/src/components/MFlowMinimap.vue +134 -0
- package/src/components/MFlowNode.vue +98 -0
- package/src/components/MGantt.vue +1609 -0
- package/src/components/MGanttControls.vue +77 -0
- package/src/components/MIconButton.vue +3 -1
- package/src/components/MImageCropper.vue +507 -0
- package/src/components/MMaskField.vue +13 -0
- package/src/components/MNumberField.vue +13 -0
- package/src/components/MPdfViewer.vue +1269 -0
- package/src/components/MResourceTimeline.vue +1020 -0
- package/src/components/MTagInput.vue +13 -0
- package/src/components/MTextField.vue +16 -0
- package/src/components/MVideoPlayer.vue +839 -0
- package/src/components/_MFlowEdge.vue +100 -0
- package/src/components/_MFlowEdgeLabel.vue +56 -0
- package/src/components/_MFlowNodeShell.vue +111 -0
- package/src/components/_MPdfPage.vue +456 -0
- package/src/components/_MTimeBackground.vue +16 -0
- package/src/components/_MTimeHeader.vue +31 -0
- package/src/composables/_flowPanel.ts +13 -0
- package/src/composables/_flowSlot.ts +6 -0
- package/src/composables/_ganttTime.ts +200 -0
- package/src/composables/_useTimeAxis.ts +224 -0
- package/src/composables/drawGeometry.ts +405 -0
- package/src/composables/flowFormats.ts +916 -0
- package/src/composables/flowLayout.ts +297 -0
- package/src/composables/flowPaths.ts +239 -0
- package/src/composables/ganttFormats.ts +366 -0
- package/src/composables/ganttSchedule.ts +403 -0
- package/src/composables/useDrawing.ts +53 -0
- package/src/composables/useFlow.ts +250 -0
- package/src/composables/useGantt.ts +92 -0
- package/src/composables/useLocale.ts +328 -0
- package/src/composables/useMediaPlayer.ts +406 -0
- package/src/composables/usePdf.ts +456 -0
- package/src/composables/useResourceTimeline.ts +76 -0
- package/src/draw.ts +25 -0
- package/src/flow.ts +26 -0
- package/src/gantt.ts +12 -0
- package/src/index.ts +4 -0
- package/src/locales/de.ts +163 -0
- package/src/locales/es.ts +163 -0
- package/src/locales/fr.ts +163 -0
- package/src/locales/ja.ts +163 -0
- package/src/locales/ko.ts +163 -0
- package/src/locales/pt.ts +163 -0
- package/src/locales/zh.ts +163 -0
- package/src/media.ts +5 -0
- package/src/pdf.ts +15 -0
- package/dist/MMenuItem-D4Gx_l3F.js +0 -929
- package/dist/MMenuItem-D4Gx_l3F.js.map +0 -1
- package/dist/MSlider-Dx_S3vJ9.js +0 -1506
- package/dist/MSlider-Dx_S3vJ9.js.map +0 -1
- package/dist/MTextField-Bz8JIsnl.js +0 -633
- package/dist/MTextField-Bz8JIsnl.js.map +0 -1
- package/dist/useLocale-JYxDDeXC.js.map +0 -1
- package/dist/useThemeTokens-y0HZpyhL.js.map +0 -1
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// Dates and time scales shared by MGantt and MResourceTimeline. Dates are strings: `YYYY-MM-DD` (a whole day, local)
|
|
2
|
+
// or a datetime (`YYYY-MM-DDTHH:mm`, local, or ISO with a zone). Inside, times are epoch ms; a date-only end is the
|
|
3
|
+
// last day (inclusive), so its exclusive end is the next midnight.
|
|
4
|
+
|
|
5
|
+
export const HOUR = 3_600_000
|
|
6
|
+
export const DAY = 86_400_000
|
|
7
|
+
|
|
8
|
+
export type TimeUnit = 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year'
|
|
9
|
+
export const UNITS: TimeUnit[] = ['hour', 'day', 'week', 'month', 'quarter', 'year']
|
|
10
|
+
|
|
11
|
+
const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/
|
|
12
|
+
|
|
13
|
+
export function isDateOnly(s: string | undefined | null): boolean {
|
|
14
|
+
return !!s && DATE_ONLY.test(s)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Epoch ms of a date string (NaN when it isn't one) */
|
|
18
|
+
export function parseDate(s: string | undefined | null): number {
|
|
19
|
+
if (!s) return NaN
|
|
20
|
+
if (DATE_ONLY.test(s)) {
|
|
21
|
+
const [y, m, d] = s.split('-').map(Number)
|
|
22
|
+
return new Date(y!, m! - 1, d!).getTime()
|
|
23
|
+
}
|
|
24
|
+
// A datetime without a zone is local time
|
|
25
|
+
const local = /^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?$/.exec(s)
|
|
26
|
+
if (local) {
|
|
27
|
+
const [, y, mo, d, h, mi, sec] = local
|
|
28
|
+
return new Date(+y!, +mo! - 1, +d!, +h!, +mi!, +(sec ?? 0)).getTime()
|
|
29
|
+
}
|
|
30
|
+
return Date.parse(s)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const pad = (n: number) => String(n).padStart(2, '0')
|
|
34
|
+
|
|
35
|
+
/** A date string, local: `YYYY-MM-DD` or `YYYY-MM-DDTHH:mm` (with seconds when there are some) */
|
|
36
|
+
export function formatDate(ms: number, dateOnly: boolean): string {
|
|
37
|
+
const d = new Date(ms)
|
|
38
|
+
const date = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
|
|
39
|
+
if (dateOnly) return date
|
|
40
|
+
const s = d.getSeconds()
|
|
41
|
+
return `${date}T${pad(d.getHours())}:${pad(d.getMinutes())}${s ? `:${pad(s)}` : ''}`
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function startOfDay(ms: number): number {
|
|
45
|
+
const d = new Date(ms)
|
|
46
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Adds whole days in local time (a DST change doesn't shift the hour) */
|
|
50
|
+
export function addDays(ms: number, n: number): number {
|
|
51
|
+
const d = new Date(ms)
|
|
52
|
+
d.setDate(d.getDate() + n)
|
|
53
|
+
return d.getTime()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Whole local days from a to b (rounded, so DST doesn't matter) */
|
|
57
|
+
export function daysBetween(a: number, b: number): number {
|
|
58
|
+
return Math.round((startOfDay(b) - startOfDay(a)) / DAY)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The start of the unit that holds `ms` */
|
|
62
|
+
export function floorUnit(ms: number, unit: TimeUnit, weekStartsOn = 1): number {
|
|
63
|
+
const d = new Date(ms)
|
|
64
|
+
switch (unit) {
|
|
65
|
+
case 'hour':
|
|
66
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours()).getTime()
|
|
67
|
+
case 'day':
|
|
68
|
+
return startOfDay(ms)
|
|
69
|
+
case 'week': {
|
|
70
|
+
const back = (d.getDay() - weekStartsOn + 7) % 7
|
|
71
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate() - back).getTime()
|
|
72
|
+
}
|
|
73
|
+
case 'month':
|
|
74
|
+
return new Date(d.getFullYear(), d.getMonth(), 1).getTime()
|
|
75
|
+
case 'quarter':
|
|
76
|
+
return new Date(d.getFullYear(), Math.floor(d.getMonth() / 3) * 3, 1).getTime()
|
|
77
|
+
case 'year':
|
|
78
|
+
return new Date(d.getFullYear(), 0, 1).getTime()
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The start of the next unit after the one that starts at `ms` (`step` hours at a time for hours) */
|
|
83
|
+
export function nextUnit(ms: number, unit: TimeUnit, step = 1): number {
|
|
84
|
+
const d = new Date(ms)
|
|
85
|
+
switch (unit) {
|
|
86
|
+
case 'hour':
|
|
87
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours() + step).getTime()
|
|
88
|
+
case 'day':
|
|
89
|
+
return addDays(ms, 1)
|
|
90
|
+
case 'week':
|
|
91
|
+
return addDays(ms, 7)
|
|
92
|
+
case 'month':
|
|
93
|
+
return new Date(d.getFullYear(), d.getMonth() + 1, 1).getTime()
|
|
94
|
+
case 'quarter':
|
|
95
|
+
return new Date(d.getFullYear(), d.getMonth() + 3, 1).getTime()
|
|
96
|
+
case 'year':
|
|
97
|
+
return new Date(d.getFullYear() + 1, 0, 1).getTime()
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Rounds to the nearest step: minutes for sub-day steps, else whole days (local midnights) */
|
|
102
|
+
export function snapTime(ms: number, stepMinutes: number): number {
|
|
103
|
+
if (stepMinutes >= 1440) {
|
|
104
|
+
const days = Math.round(stepMinutes / 1440)
|
|
105
|
+
const day = startOfDay(ms + (12 * HOUR))
|
|
106
|
+
if (days <= 1) return day
|
|
107
|
+
// Steps of several days count from the epoch's local day
|
|
108
|
+
const n = daysBetween(0, day)
|
|
109
|
+
return addDays(day, -(((n % days) + days) % days))
|
|
110
|
+
}
|
|
111
|
+
const step = stepMinutes * 60_000
|
|
112
|
+
const base = startOfDay(ms)
|
|
113
|
+
return base + Math.round((ms - base) / step) * step
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ── Scales ────────────────────────────────────────────────────────────────────────────────────────────────
|
|
117
|
+
|
|
118
|
+
/** The named zoom levels: px per day each starts at */
|
|
119
|
+
export const SCALE_PX_PER_DAY: Record<TimeUnit, number> = {
|
|
120
|
+
hour: 1152,
|
|
121
|
+
day: 40,
|
|
122
|
+
week: 20,
|
|
123
|
+
month: 5,
|
|
124
|
+
quarter: 1.2,
|
|
125
|
+
year: 0.3,
|
|
126
|
+
}
|
|
127
|
+
const UNIT_DAYS: Record<TimeUnit, number> = { hour: 1 / 24, day: 1, week: 7, month: 30.44, quarter: 91.3, year: 365.25 }
|
|
128
|
+
// The narrowest a header cell can get with its label
|
|
129
|
+
const MIN_CELL: Record<TimeUnit, number> = { hour: 36, day: 26, week: 52, month: 44, quarter: 36, year: 44 }
|
|
130
|
+
const TOP: Record<TimeUnit, TimeUnit | null> = { hour: 'day', day: 'month', week: 'month', month: 'year', quarter: 'year', year: null }
|
|
131
|
+
|
|
132
|
+
const HOUR_STEPS = [1, 2, 3, 6, 12]
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The header's two rows for a zoom: the finest unit whose cells still fit a label, and the one above it. Hours come
|
|
136
|
+
* in steps of 2, 3, 6 or 12 when single ones don't fit, before giving way to days
|
|
137
|
+
*/
|
|
138
|
+
export function unitsFor(pxPerDay: number): { bottom: TimeUnit; top: TimeUnit | null; step: number } {
|
|
139
|
+
const step = HOUR_STEPS.find((s) => (s * pxPerDay) / 24 >= MIN_CELL.hour)
|
|
140
|
+
if (step) return { bottom: 'hour', top: 'day', step }
|
|
141
|
+
const bottom = UNITS.find((u) => u !== 'hour' && UNIT_DAYS[u] * pxPerDay >= MIN_CELL[u]) ?? 'year'
|
|
142
|
+
return { bottom, top: TOP[bottom], step: 1 }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** The named scale closest to a zoom */
|
|
146
|
+
export function nearestScale(pxPerDay: number): TimeUnit {
|
|
147
|
+
let best: TimeUnit = 'day'
|
|
148
|
+
let dist = Infinity
|
|
149
|
+
for (const u of UNITS) {
|
|
150
|
+
const d = Math.abs(Math.log(SCALE_PX_PER_DAY[u] / pxPerDay))
|
|
151
|
+
if (d < dist) { dist = d; best = u }
|
|
152
|
+
}
|
|
153
|
+
return best
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Units starting from before `from` until past `to` (hours `step` at a time, from midnight) */
|
|
157
|
+
export function unitStarts(from: number, to: number, unit: TimeUnit, weekStartsOn = 1, step = 1, max = 2000): number[] {
|
|
158
|
+
const out: number[] = []
|
|
159
|
+
let t = floorUnit(from, unit, weekStartsOn)
|
|
160
|
+
if (unit === 'hour' && step > 1) t -= (new Date(t).getHours() % step) * HOUR
|
|
161
|
+
for (; t < to && out.length < max; t = nextUnit(t, unit, step)) out.push(t)
|
|
162
|
+
return out
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** A header cell's label */
|
|
166
|
+
export function unitLabel(ms: number, unit: TimeUnit, width: number, lang: string | undefined, quarter: string, top = false): string {
|
|
167
|
+
const d = new Date(ms)
|
|
168
|
+
const f = (o: Intl.DateTimeFormatOptions) => new Intl.DateTimeFormat(lang, o).format(d)
|
|
169
|
+
switch (unit) {
|
|
170
|
+
case 'hour':
|
|
171
|
+
return f({ hour: 'numeric' })
|
|
172
|
+
case 'day':
|
|
173
|
+
if (top) return f({ weekday: 'short', day: 'numeric', month: 'short' })
|
|
174
|
+
return width >= 44 ? f({ weekday: 'narrow', day: 'numeric' }) : f({ day: 'numeric' })
|
|
175
|
+
case 'week':
|
|
176
|
+
return f({ month: 'short', day: 'numeric' })
|
|
177
|
+
case 'month':
|
|
178
|
+
if (top) return f({ month: 'long', year: 'numeric' })
|
|
179
|
+
return f({ month: width >= 90 ? 'long' : 'short' })
|
|
180
|
+
case 'quarter':
|
|
181
|
+
return quarter.replace('{n}', String(Math.floor(d.getMonth() / 3) + 1))
|
|
182
|
+
case 'year':
|
|
183
|
+
return f({ year: 'numeric' })
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Snap step (minutes) that suits a zoom, for tasks given as datetimes */
|
|
188
|
+
export function defaultSnap(pxPerDay: number): number {
|
|
189
|
+
const pxPerHour = pxPerDay / 24
|
|
190
|
+
if (pxPerHour >= 120) return 5
|
|
191
|
+
if (pxPerHour >= 40) return 15
|
|
192
|
+
if (pxPerHour >= 16) return 30
|
|
193
|
+
if (pxPerHour >= 4) return 60
|
|
194
|
+
return 1440
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Whether a day is a working one */
|
|
198
|
+
export function isWorkingDay(ms: number, workingDays: readonly number[], holidays: ReadonlySet<string>): boolean {
|
|
199
|
+
return workingDays.includes(new Date(ms).getDay()) && !holidays.has(formatDate(ms, true))
|
|
200
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// The time axis MGantt and MResourceTimeline share: a scroller whose content is a list (sticky, `listWidth` wide)
|
|
2
|
+
// beside a timeline. Holds the zoom (px per day, sprung on a log scale, anchored where it zooms), the origin
|
|
3
|
+
// (which moves left, keeping the view in place, when something is dragged before it), the header's cells, the days
|
|
4
|
+
// off, today, and Ctrl + wheel / pinch zooming.
|
|
5
|
+
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch, type ComputedRef, type Ref } from 'vue'
|
|
6
|
+
import { DAY, SCALE_PX_PER_DAY, addDays, isWorkingDay, nearestScale, nextUnit, parseDate, startOfDay, unitLabel, unitStarts, unitsFor, type TimeUnit } from './_ganttTime'
|
|
7
|
+
import { prefersReducedMotion } from './_springAnimation'
|
|
8
|
+
|
|
9
|
+
export interface TimeAxisOptions {
|
|
10
|
+
scroller: Ref<HTMLElement | undefined>
|
|
11
|
+
listWidth: ComputedRef<number>
|
|
12
|
+
headerHeight: number
|
|
13
|
+
/** Earliest and latest ms the content spans */
|
|
14
|
+
extent: ComputedRef<{ min: number; max: number }>
|
|
15
|
+
scale: () => TimeUnit
|
|
16
|
+
pxPerDay: () => number | undefined
|
|
17
|
+
minPxPerDay: () => number
|
|
18
|
+
maxPxPerDay: () => number
|
|
19
|
+
weekStartsOn: () => 0 | 1
|
|
20
|
+
lang: ComputedRef<string | undefined>
|
|
21
|
+
quarterLabel: () => string
|
|
22
|
+
today: () => string | null | undefined
|
|
23
|
+
calendar: () => { workingDays?: number[]; holidays?: string[] } | undefined
|
|
24
|
+
/** Working hours shaded as such on hour scales, e.g. [9, 18] */
|
|
25
|
+
workHours?: () => [number, number] | undefined
|
|
26
|
+
onScale: (s: TimeUnit) => void
|
|
27
|
+
/** A pinch began: drop whatever drag was going on */
|
|
28
|
+
onPinch?: () => void
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function useTimeAxis(o: TimeAxisOptions) {
|
|
32
|
+
const clamp = (z: number) => Math.min(o.maxPxPerDay(), Math.max(o.minPxPerDay(), z))
|
|
33
|
+
const ppd = ref(clamp(o.pxPerDay() ?? SCALE_PX_PER_DAY[o.scale()]))
|
|
34
|
+
const scaleNow = computed(() => nearestScale(ppd.value))
|
|
35
|
+
let emitted: TimeUnit = scaleNow.value
|
|
36
|
+
watch(scaleNow, (s) => {
|
|
37
|
+
if (s === emitted) return
|
|
38
|
+
emitted = s
|
|
39
|
+
o.onScale(s)
|
|
40
|
+
})
|
|
41
|
+
watch(o.scale, (s) => {
|
|
42
|
+
if (s === emitted) return
|
|
43
|
+
emitted = s
|
|
44
|
+
zoomTo(SCALE_PX_PER_DAY[s])
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const view = ref({ left: 0, top: 0, width: 0, height: 0 })
|
|
48
|
+
const timelineView = computed(() => Math.max(0, view.value.width - o.listWidth.value))
|
|
49
|
+
|
|
50
|
+
const nowTick = ref(Date.now())
|
|
51
|
+
let nowTimer: ReturnType<typeof setInterval> | undefined
|
|
52
|
+
const todayMs = computed(() => {
|
|
53
|
+
const t = o.today()
|
|
54
|
+
return t === null ? null : t ? parseDate(t) : nowTick.value
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const padDays = computed(() => Math.max(14, (timelineView.value || 800) / ppd.value))
|
|
58
|
+
const origin = ref(0)
|
|
59
|
+
const span = computed(() => Math.max((o.extent.value.max - origin.value) / DAY + padDays.value, timelineView.value / ppd.value))
|
|
60
|
+
const timelineWidth = computed(() => span.value * ppd.value)
|
|
61
|
+
function updateOrigin() {
|
|
62
|
+
const want = startOfDay(addDays(o.extent.value.min, -Math.ceil(padDays.value)))
|
|
63
|
+
if (!origin.value) { origin.value = want; return }
|
|
64
|
+
// The view keeps its place when the origin moves
|
|
65
|
+
const tooFar = want - origin.value > 3 * padDays.value * DAY
|
|
66
|
+
if (want < origin.value || tooFar) {
|
|
67
|
+
const shift = ((origin.value - want) / DAY) * ppd.value
|
|
68
|
+
origin.value = want
|
|
69
|
+
const el = o.scroller.value
|
|
70
|
+
if (el) {
|
|
71
|
+
el.scrollLeft += shift
|
|
72
|
+
view.value.left = el.scrollLeft
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
watch([o.extent, padDays], updateOrigin, { immediate: true })
|
|
77
|
+
const xOf = (ms: number) => ((ms - origin.value) / DAY) * ppd.value
|
|
78
|
+
const timeAt = (x: number) => origin.value + (x / ppd.value) * DAY
|
|
79
|
+
|
|
80
|
+
// Zoom around a point of the view (px from the timeline's left edge), sprung on a log scale
|
|
81
|
+
let zoomRaf = 0
|
|
82
|
+
let zoomState: { z: number; v: number; target: number; anchor: number; at: number } | null = null
|
|
83
|
+
function zoomTo(target: number, anchor?: number, animate = true) {
|
|
84
|
+
target = clamp(target)
|
|
85
|
+
const a = anchor ?? timelineView.value / 2
|
|
86
|
+
const at = timeAt(view.value.left + a)
|
|
87
|
+
if (!animate || prefersReducedMotion() || !o.scroller.value) {
|
|
88
|
+
cancelAnimationFrame(zoomRaf)
|
|
89
|
+
zoomRaf = 0
|
|
90
|
+
zoomState = null
|
|
91
|
+
applyZoom(target, a, at)
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
zoomState = { z: Math.log(ppd.value), v: zoomState?.v ?? 0, target: Math.log(target), anchor: a, at }
|
|
95
|
+
if (zoomRaf) return
|
|
96
|
+
let last = performance.now()
|
|
97
|
+
const step = (now: number) => {
|
|
98
|
+
const s = zoomState!
|
|
99
|
+
let dt = Math.min((now - last) / 1000, 1 / 30)
|
|
100
|
+
last = now
|
|
101
|
+
// Standard DefaultSpatial
|
|
102
|
+
while (dt > 0) {
|
|
103
|
+
const h = Math.min(dt, 0.004)
|
|
104
|
+
s.v += (-700 * (s.z - s.target) - 2 * 0.9 * Math.sqrt(700) * s.v) * h
|
|
105
|
+
s.z += s.v * h
|
|
106
|
+
dt -= h
|
|
107
|
+
}
|
|
108
|
+
const done = Math.abs(s.z - s.target) < 0.001 && Math.abs(s.v) < 0.01
|
|
109
|
+
applyZoom(Math.exp(done ? s.target : s.z), s.anchor, s.at)
|
|
110
|
+
if (done) { zoomRaf = 0; zoomState = null; return }
|
|
111
|
+
zoomRaf = requestAnimationFrame(step)
|
|
112
|
+
}
|
|
113
|
+
zoomRaf = requestAnimationFrame(step)
|
|
114
|
+
}
|
|
115
|
+
function applyZoom(z: number, anchor: number, at: number) {
|
|
116
|
+
ppd.value = z
|
|
117
|
+
updateOrigin()
|
|
118
|
+
const left = Math.max(0, xOf(at) - anchor)
|
|
119
|
+
view.value.left = left
|
|
120
|
+
// After the timeline has its new width
|
|
121
|
+
nextTick(() => { if (o.scroller.value) o.scroller.value.scrollLeft = left })
|
|
122
|
+
}
|
|
123
|
+
const zoomTarget = () => (zoomState ? Math.exp(zoomState.target) : ppd.value)
|
|
124
|
+
const zoomIn = () => zoomTo(zoomTarget() * 1.6)
|
|
125
|
+
const zoomOut = () => zoomTo(zoomTarget() / 1.6)
|
|
126
|
+
const setScale = (s: TimeUnit) => zoomTo(SCALE_PX_PER_DAY[s])
|
|
127
|
+
function scrollToDate(date?: string, opts: { align?: 'start' | 'center'; animate?: boolean } = {}) {
|
|
128
|
+
const ms = date ? parseDate(date) : Date.now()
|
|
129
|
+
const x = xOf(ms) - (opts.align === 'start' ? 24 : timelineView.value / 2)
|
|
130
|
+
o.scroller.value?.scrollTo({ left: Math.max(0, x), behavior: opts.animate === false || prefersReducedMotion() ? 'auto' : 'smooth' })
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ── Header cells and the background ─────────────────────────────────────────────────────────────────────
|
|
134
|
+
const units = computed(() => unitsFor(ppd.value))
|
|
135
|
+
const visibleFrom = computed(() => timeAt(view.value.left - 200))
|
|
136
|
+
const visibleTo = computed(() => timeAt(view.value.left + timelineView.value + 200))
|
|
137
|
+
function cells(unit: TimeUnit, top: boolean) {
|
|
138
|
+
const step = top ? 1 : units.value.step
|
|
139
|
+
return unitStarts(visibleFrom.value, visibleTo.value, unit, o.weekStartsOn(), step).map((t) => {
|
|
140
|
+
const x = xOf(t)
|
|
141
|
+
const w = xOf(nextUnit(t, unit, step)) - x
|
|
142
|
+
return { key: t, x, w, label: unitLabel(t, unit, w, o.lang.value, o.quarterLabel(), top) }
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
const bottomCells = computed(() => cells(units.value.bottom, false))
|
|
146
|
+
const topCells = computed(() => {
|
|
147
|
+
if (!units.value.top) return []
|
|
148
|
+
// Labels stay in view while their cell is partly scrolled away
|
|
149
|
+
return cells(units.value.top, true).map((c) => ({ ...c, labelX: Math.max(0, Math.min(view.value.left - c.x, c.w - 80)) }))
|
|
150
|
+
})
|
|
151
|
+
const calendar = computed(() => ({ days: o.calendar()?.workingDays ?? [1, 2, 3, 4, 5], holidays: new Set(o.calendar()?.holidays ?? []) }))
|
|
152
|
+
/** Shaded spans: days off, and the hours outside `workHours` when zoomed in that far */
|
|
153
|
+
const offTimes = computed(() => {
|
|
154
|
+
const out: { x: number; w: number }[] = []
|
|
155
|
+
if (ppd.value < 6) return out
|
|
156
|
+
const hours = o.workHours?.()
|
|
157
|
+
for (let d = startOfDay(visibleFrom.value); d < visibleTo.value; d = addDays(d, 1)) {
|
|
158
|
+
const next = addDays(d, 1)
|
|
159
|
+
if (!isWorkingDay(d, calendar.value.days, calendar.value.holidays)) out.push({ x: xOf(d), w: xOf(next) - xOf(d) })
|
|
160
|
+
else if (hours && ppd.value >= 120) {
|
|
161
|
+
const a = d + hours[0] * 3_600_000
|
|
162
|
+
const b = d + hours[1] * 3_600_000
|
|
163
|
+
if (hours[0] > 0) out.push({ x: xOf(d), w: xOf(a) - xOf(d) })
|
|
164
|
+
if (hours[1] < 24) out.push({ x: xOf(b), w: xOf(next) - xOf(b) })
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return out
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
// ── Wheel and pinch ─────────────────────────────────────────────────────────────────────────────────────
|
|
171
|
+
function onWheel(e: WheelEvent) {
|
|
172
|
+
if (!e.ctrlKey && !e.metaKey) return
|
|
173
|
+
e.preventDefault()
|
|
174
|
+
const r = o.scroller.value!.getBoundingClientRect()
|
|
175
|
+
const anchor = e.clientX - r.left - o.listWidth.value
|
|
176
|
+
if (anchor < 0) return
|
|
177
|
+
zoomTo(ppd.value * Math.exp(-e.deltaY * 0.002 * (e.deltaMode === 1 ? 16 : 1)), anchor, false)
|
|
178
|
+
}
|
|
179
|
+
let pinch: { dist: number; z: number; anchor: number } | null = null
|
|
180
|
+
const pinching = () => !!pinch
|
|
181
|
+
function onTouchStart(e: TouchEvent) {
|
|
182
|
+
if (e.touches.length !== 2) return
|
|
183
|
+
o.onPinch?.()
|
|
184
|
+
const [a, b] = [e.touches[0]!, e.touches[1]!]
|
|
185
|
+
const r = o.scroller.value!.getBoundingClientRect()
|
|
186
|
+
pinch = { dist: Math.hypot(a.clientX - b.clientX, a.clientY - b.clientY) || 1, z: ppd.value, anchor: (a.clientX + b.clientX) / 2 - r.left - o.listWidth.value }
|
|
187
|
+
}
|
|
188
|
+
function pinchMove(e: TouchEvent) {
|
|
189
|
+
if (!pinch || e.touches.length !== 2) return false
|
|
190
|
+
if (e.cancelable) e.preventDefault()
|
|
191
|
+
const [a, b] = [e.touches[0]!, e.touches[1]!]
|
|
192
|
+
zoomTo(pinch.z * (Math.hypot(a.clientX - b.clientX, a.clientY - b.clientY) / pinch.dist), pinch.anchor, false)
|
|
193
|
+
return true
|
|
194
|
+
}
|
|
195
|
+
function onTouchEnd(e: TouchEvent) {
|
|
196
|
+
if (e.touches.length < 2) pinch = null
|
|
197
|
+
}
|
|
198
|
+
function readView() {
|
|
199
|
+
const el = o.scroller.value
|
|
200
|
+
if (el) view.value = { left: el.scrollLeft, top: el.scrollTop, width: el.clientWidth, height: el.clientHeight }
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
let ro: ResizeObserver | undefined
|
|
204
|
+
onMounted(() => {
|
|
205
|
+
const el = o.scroller.value!
|
|
206
|
+
el.addEventListener('wheel', onWheel, { passive: false })
|
|
207
|
+
readView()
|
|
208
|
+
ro = new ResizeObserver(readView)
|
|
209
|
+
ro.observe(el)
|
|
210
|
+
if (o.today() !== null) nowTimer = setInterval(() => { nowTick.value = Date.now() }, 60_000)
|
|
211
|
+
})
|
|
212
|
+
onBeforeUnmount(() => {
|
|
213
|
+
o.scroller.value?.removeEventListener('wheel', onWheel)
|
|
214
|
+
ro?.disconnect()
|
|
215
|
+
cancelAnimationFrame(zoomRaf)
|
|
216
|
+
clearInterval(nowTimer)
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
return {
|
|
220
|
+
ppd, scaleNow, view, timelineView, origin, timelineWidth, todayMs, xOf, timeAt,
|
|
221
|
+
zoomTo, zoomIn, zoomOut, setScale, scrollToDate, units, topCells, bottomCells, offTimes,
|
|
222
|
+
onTouchStart, pinchMove, onTouchEnd, pinching, readView,
|
|
223
|
+
}
|
|
224
|
+
}
|