@m3ui-vue/m3ui-vue 0.9.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -2
- package/dist/API.md +3806 -0
- package/dist/MIcon-CaEooCmZ.js.map +1 -1
- package/dist/{MTextField-B0wGv1Mx.js → MTextField-Ck0oWDMk.js} +9 -3
- package/dist/MTextField-Ck0oWDMk.js.map +1 -0
- package/dist/api.json +1 -0
- package/dist/barcode.js.map +1 -1
- package/dist/chart.js.map +1 -1
- package/dist/code-editor.js +2 -2
- package/dist/code-editor.js.map +1 -1
- package/dist/components/MAbsolute.vue.d.ts +12 -0
- package/dist/components/MAlert.vue.d.ts +4 -0
- package/dist/components/MAppBar.vue.d.ts +12 -0
- package/dist/components/MAppLayout.vue.d.ts +2 -0
- package/dist/components/MAspectRatio.vue.d.ts +1 -0
- package/dist/components/MAutocomplete.vue.d.ts +18 -0
- package/dist/components/MAvatar.vue.d.ts +3 -0
- package/dist/components/MBadge.vue.d.ts +6 -0
- package/dist/components/MBar.vue.d.ts +5 -0
- package/dist/components/MBarcode.vue.d.ts +9 -0
- package/dist/components/MBottomSheet.vue.d.ts +3 -0
- package/dist/components/MBox.vue.d.ts +8 -2
- package/dist/components/MBreadcrumbs.vue.d.ts +2 -0
- package/dist/components/MButton.vue.d.ts +14 -4
- package/dist/components/MButtonGroup.vue.d.ts +7 -0
- package/dist/components/MCalendar.vue.d.ts +8 -0
- package/dist/components/MCard.vue.d.ts +17 -0
- package/dist/components/MCarousel.vue.d.ts +7 -1
- package/dist/components/MCenter.vue.d.ts +1 -0
- package/dist/components/MChart.vue.d.ts +7 -0
- package/dist/components/MChatBubble.vue.d.ts +10 -0
- package/dist/components/MCheckbox.vue.d.ts +5 -0
- package/dist/components/MChip.vue.d.ts +9 -0
- package/dist/components/MCircleProgressBar.vue.d.ts +7 -0
- package/dist/components/MCodeEditor.vue.d.ts +9 -0
- package/dist/components/MColorPicker.vue.d.ts +20 -0
- package/dist/components/MColorPickerModal.vue.d.ts +16 -0
- package/dist/components/MCommandPalette.vue.d.ts +8 -0
- package/dist/components/MConfirmDialog.vue.d.ts +7 -0
- package/dist/components/MContainer.vue.d.ts +4 -0
- package/dist/components/MContextMenu.vue.d.ts +3 -6
- package/dist/components/MCopyButton.vue.d.ts +10 -0
- package/dist/components/MDataTable.vue.d.ts +33 -12
- package/dist/components/MDatePicker.vue.d.ts +16 -0
- package/dist/components/MDatePickerModal.vue.d.ts +9 -0
- package/dist/components/MDateRangePicker.vue.d.ts +18 -0
- package/dist/components/MDateRangePickerModal.vue.d.ts +9 -0
- package/dist/components/MDialog.vue.d.ts +9 -7
- package/dist/components/MDivider.vue.d.ts +6 -0
- package/dist/components/MDragDropList.vue.d.ts +6 -0
- package/dist/components/MDragHandle.vue.d.ts +12 -0
- package/dist/components/MEmoji.vue.d.ts +6 -0
- package/dist/components/MEmojiButton.vue.d.ts +5 -0
- package/dist/components/MEmojiSelector.vue.d.ts +1 -1
- package/dist/components/MEmptyState.vue.d.ts +4 -0
- package/dist/components/MExpansionPanel.vue.d.ts +9 -0
- package/dist/components/MExportButton.vue.d.ts +8 -0
- package/dist/components/MFab.vue.d.ts +10 -1
- package/dist/components/MFabMenu.vue.d.ts +15 -1
- package/dist/components/MFileUpload.vue.d.ts +8 -0
- package/dist/components/MFixed.vue.d.ts +10 -0
- package/dist/components/MFlex.vue.d.ts +6 -0
- package/dist/components/MFooter.vue.d.ts +11 -0
- package/dist/components/MFullscreen.vue.d.ts +2 -0
- package/dist/components/MGrid.vue.d.ts +7 -0
- package/dist/components/MHotkeys.vue.d.ts +4 -0
- package/dist/components/MIcon.vue.d.ts +2 -0
- package/dist/components/MIconButton.vue.d.ts +10 -0
- package/dist/components/MInfiniteScroll.vue.d.ts +6 -0
- package/dist/components/MJsonEditor.vue.d.ts +8 -0
- package/dist/components/MJsonViewer.vue.d.ts +4 -0
- package/dist/components/MKanban.vue.d.ts +2 -0
- package/dist/components/MKbd.vue.d.ts +2 -0
- package/dist/components/MLightbox.vue.d.ts +4 -0
- package/dist/components/MList.vue.d.ts +7 -0
- package/dist/components/MListItem.vue.d.ts +29 -5
- package/dist/components/MListSubheader.vue.d.ts +6 -0
- package/dist/components/MLoadingIndicator.vue.d.ts +10 -0
- package/dist/components/MLoadingOverlay.vue.d.ts +5 -0
- package/dist/components/MMarkdown.vue.d.ts +3 -0
- package/dist/components/MMaskField.vue.d.ts +15 -0
- package/dist/components/MMasonry.vue.d.ts +5 -0
- package/dist/components/MMenu.vue.d.ts +3 -6
- package/dist/components/MMenuDivider.vue.d.ts +4 -0
- package/dist/components/MMenuItem.vue.d.ts +5 -0
- package/dist/components/MMultiAutocomplete.vue.d.ts +20 -0
- package/dist/components/MMultiSelect.vue.d.ts +21 -0
- package/dist/components/MNavigationBar.vue.d.ts +2 -0
- package/dist/components/MNavigationDrawer.vue.d.ts +11 -0
- package/dist/components/MNavigationRail.vue.d.ts +9 -6
- package/dist/components/MNavigationSuite.vue.d.ts +5 -3
- package/dist/components/MNumberField.vue.d.ts +17 -0
- package/dist/components/MOverlay.vue.d.ts +4 -1
- package/dist/components/MPageProgress.vue.d.ts +3 -0
- package/dist/components/MPagination.vue.d.ts +3 -0
- package/dist/components/MPasswordMeter.vue.d.ts +1 -0
- package/dist/components/MPinInput.vue.d.ts +11 -0
- package/dist/components/MProgressBar.vue.d.ts +6 -0
- package/dist/components/MPullToRefresh.vue.d.ts +8 -0
- package/dist/components/MQRCode.vue.d.ts +6 -0
- package/dist/components/MRadio.vue.d.ts +5 -0
- package/dist/components/MRadioGroup.vue.d.ts +6 -0
- package/dist/components/MRating.vue.d.ts +11 -0
- package/dist/components/MRelativeTime.vue.d.ts +1 -0
- package/dist/components/MResponsive.vue.d.ts +3 -0
- package/dist/components/MResult.vue.d.ts +6 -0
- package/dist/components/MRichTextEditor.vue.d.ts +8 -0
- package/dist/components/MScheduler.vue.d.ts +10 -0
- package/dist/components/MScrollField.vue.d.ts +40 -0
- package/dist/components/MScrollable.vue.d.ts +12 -0
- package/dist/components/MSearchBar.vue.d.ts +6 -0
- package/dist/components/MSection.vue.d.ts +5 -0
- package/dist/components/MSegmentedButton.vue.d.ts +5 -0
- package/dist/components/MSelect.vue.d.ts +17 -0
- package/dist/components/MShader.vue.d.ts +1 -0
- package/dist/components/MShortNavigationBar.vue.d.ts +8 -9
- package/dist/components/MSideSheet.vue.d.ts +3 -0
- package/dist/components/MSignaturePad.vue.d.ts +7 -0
- package/dist/components/MSimpleCarousel.vue.d.ts +10 -0
- package/dist/components/MSkeleton.vue.d.ts +8 -0
- package/dist/components/MSlider.vue.d.ts +14 -0
- package/dist/components/MSnackbar.vue.d.ts +1 -0
- package/dist/components/MSpinner.vue.d.ts +6 -0
- package/dist/components/MSplitButton.vue.d.ts +7 -0
- package/dist/components/MSplitter.vue.d.ts +6 -2
- package/dist/components/MSpotlightSearch.vue.d.ts +18 -0
- package/dist/components/MStack.vue.d.ts +7 -0
- package/dist/components/MStatCard.vue.d.ts +7 -0
- package/dist/components/MStepper.vue.d.ts +7 -0
- package/dist/components/MSticky.vue.d.ts +2 -0
- package/dist/components/MSubtitle.vue.d.ts +4 -0
- package/dist/components/MSwipeToDismiss.vue.d.ts +49 -0
- package/dist/components/MSwitch.vue.d.ts +5 -6
- package/dist/components/MTable.vue.d.ts +17 -4
- package/dist/components/MTabs.vue.d.ts +6 -0
- package/dist/components/MTagInput.vue.d.ts +17 -0
- package/dist/components/MTerminal.vue.d.ts +4 -0
- package/dist/components/MText.vue.d.ts +10 -0
- package/dist/components/MTextField.vue.d.ts +18 -0
- package/dist/components/MTimePicker.vue.d.ts +10 -0
- package/dist/components/MTimePickerModal.vue.d.ts +5 -0
- package/dist/components/MTimeline.vue.d.ts +3 -0
- package/dist/components/MTitle.vue.d.ts +4 -0
- package/dist/components/MToggleButton.vue.d.ts +4 -0
- package/dist/components/MToolbar.vue.d.ts +5 -0
- package/dist/components/MTooltip.vue.d.ts +7 -0
- package/dist/components/MTopAppBar.vue.d.ts +8 -0
- package/dist/components/MTour.vue.d.ts +5 -0
- package/dist/components/MTransferList.vue.d.ts +11 -0
- package/dist/components/MTransition.vue.d.ts +34 -0
- package/dist/components/MTree.vue.d.ts +11 -0
- package/dist/components/MTreeTable.vue.d.ts +7 -0
- package/dist/components/MVirtualTable.vue.d.ts +6 -0
- package/dist/components/MWindow.vue.d.ts +33 -1
- package/dist/components/_MColorPanel.vue.d.ts +18 -0
- package/dist/composables/_colorUtils.d.ts +34 -0
- package/dist/composables/_themeColor.d.ts +1 -0
- package/dist/composables/_useSpring.d.ts +15 -0
- package/dist/composables/dynamicColor.d.ts +18 -0
- package/dist/composables/useColorPalette.d.ts +27 -0
- package/dist/composables/useLocale.d.ts +12 -0
- package/dist/index.d.ts +9 -1
- package/dist/locales/index.js +70 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +6456 -5273
- package/dist/m3ui.js.map +1 -1
- package/dist/markdown.js +1 -1
- package/dist/markdown.js.map +1 -1
- package/dist/material-color-utilities-Cktu8DBU.js +3160 -0
- package/dist/material-color-utilities-Cktu8DBU.js.map +1 -0
- package/dist/plugin.d.ts +18 -0
- package/dist/qrcode.js.map +1 -1
- package/dist/rich-text-editor.js +3 -3
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles/palettes.css +546 -0
- package/dist/styles/theme.css +77 -0
- package/dist/styles.css +1 -1
- package/dist/terminal.js.map +1 -1
- package/dist/{useLocale-CmI675Ab.js → useLocale-CFW8cIzL.js} +23 -10
- package/dist/useLocale-CFW8cIzL.js.map +1 -0
- package/package.json +5 -2
- package/src/__tests__/MButtonGroup.test.ts +51 -0
- package/src/__tests__/MColorPicker.test.ts +141 -0
- package/src/__tests__/MDragHandle.test.ts +57 -0
- package/src/__tests__/MHotkeys.test.ts +57 -0
- package/src/__tests__/MListItemShape.test.ts +76 -0
- package/src/__tests__/MScrollField.test.ts +41 -0
- package/src/__tests__/MScrollable.test.ts +42 -0
- package/src/__tests__/MSwipeToDismiss.test.ts +104 -0
- package/src/__tests__/MTransition.test.ts +27 -0
- package/src/__tests__/dynamicColor.test.ts +191 -0
- package/src/__tests__/hostLocale.test.ts +57 -0
- package/src/components/MAbsolute.vue +18 -0
- package/src/components/MAlert.vue +12 -0
- package/src/components/MAppBar.vue +12 -0
- package/src/components/MAppLayout.vue +11 -0
- package/src/components/MAspectRatio.vue +6 -0
- package/src/components/MAutocomplete.vue +24 -0
- package/src/components/MAvatar.vue +12 -1
- package/src/components/MBadge.vue +11 -0
- package/src/components/MBar.vue +19 -0
- package/src/components/MBarcode.vue +14 -0
- package/src/components/MBottomSheet.vue +12 -0
- package/src/components/MBox.vue +15 -1
- package/src/components/MBreadcrumbs.vue +7 -0
- package/src/components/MButton.vue +22 -4
- package/src/components/MButtonGroup.vue +129 -35
- package/src/components/MCalendar.vue +14 -0
- package/src/components/MCard.vue +26 -0
- package/src/components/MCarousel.vue +17 -1
- package/src/components/MCenter.vue +6 -0
- package/src/components/MChart.vue +12 -0
- package/src/components/MChatBubble.vue +17 -0
- package/src/components/MCheckbox.vue +11 -0
- package/src/components/MChip.vue +17 -0
- package/src/components/MCircleProgressBar.vue +13 -0
- package/src/components/MCodeEditor.vue +15 -0
- package/src/components/MColorPicker.vue +124 -207
- package/src/components/MColorPickerModal.vue +58 -247
- package/src/components/MCommandPalette.vue +16 -0
- package/src/components/MConfirmDialog.vue +15 -0
- package/src/components/MContainer.vue +9 -0
- package/src/components/MContextMenu.vue +17 -6
- package/src/components/MCopyButton.vue +16 -0
- package/src/components/MDataTable.vue +58 -12
- package/src/components/MDatePicker.vue +21 -0
- package/src/components/MDatePickerModal.vue +16 -0
- package/src/components/MDateRangePicker.vue +23 -0
- package/src/components/MDateRangePickerModal.vue +16 -0
- package/src/components/MDialog.vue +27 -7
- package/src/components/MDivider.vue +6 -0
- package/src/components/MDragDropList.vue +18 -0
- package/src/components/MDragHandle.vue +54 -0
- package/src/components/MEmoji.vue +6 -0
- package/src/components/MEmojiButton.vue +11 -0
- package/src/components/MEmojiSelector.vue +7 -0
- package/src/components/MEmptyState.vue +9 -0
- package/src/components/MExpansionPanel.vue +17 -0
- package/src/components/MExportButton.vue +15 -0
- package/src/components/MFab.vue +17 -0
- package/src/components/MFabMenu.vue +20 -0
- package/src/components/MFileUpload.vue +19 -0
- package/src/components/MFixed.vue +16 -0
- package/src/components/MFlex.vue +11 -0
- package/src/components/MFooter.vue +11 -0
- package/src/components/MFullscreen.vue +8 -0
- package/src/components/MGrid.vue +12 -0
- package/src/components/MHotkeys.vue +20 -13
- package/src/components/MIcon.vue +10 -1
- package/src/components/MIconButton.vue +13 -0
- package/src/components/MInfiniteScroll.vue +16 -0
- package/src/components/MJsonEditor.vue +13 -0
- package/src/components/MJsonViewer.vue +7 -0
- package/src/components/MKanban.vue +18 -0
- package/src/components/MKbd.vue +6 -0
- package/src/components/MLightbox.vue +16 -0
- package/src/components/MList.vue +48 -3
- package/src/components/MListDetail.vue +11 -0
- package/src/components/MListItem.vue +112 -5
- package/src/components/MListSubheader.vue +6 -0
- package/src/components/MLoadingIndicator.vue +15 -0
- package/src/components/MLoadingOverlay.vue +12 -0
- package/src/components/MMarkdown.vue +7 -0
- package/src/components/MMaskField.vue +21 -0
- package/src/components/MMasonry.vue +11 -0
- package/src/components/MMenu.vue +16 -6
- package/src/components/MMenuDivider.vue +4 -0
- package/src/components/MMenuItem.vue +16 -0
- package/src/components/MMultiAutocomplete.vue +26 -0
- package/src/components/MMultiSelect.vue +27 -0
- package/src/components/MNavigationBar.vue +7 -0
- package/src/components/MNavigationDrawer.vue +25 -0
- package/src/components/MNavigationRail.vue +24 -6
- package/src/components/MNavigationSuite.vue +20 -3
- package/src/components/MNotificationHost.vue +3 -0
- package/src/components/MNumberField.vue +24 -0
- package/src/components/MOverlay.vue +10 -0
- package/src/components/MPageProgress.vue +7 -0
- package/src/components/MPagination.vue +15 -1
- package/src/components/MPasswordMeter.vue +7 -0
- package/src/components/MPinInput.vue +19 -0
- package/src/components/MProgressBar.vue +9 -0
- package/src/components/MPullToRefresh.vue +17 -0
- package/src/components/MQRCode.vue +12 -0
- package/src/components/MRadio.vue +11 -0
- package/src/components/MRadioGroup.vue +11 -0
- package/src/components/MRating.vue +19 -0
- package/src/components/MRelative.vue +8 -0
- package/src/components/MRelativeTime.vue +6 -0
- package/src/components/MResponsive.vue +9 -0
- package/src/components/MResult.vue +14 -0
- package/src/components/MRichTextEditor.vue +14 -0
- package/src/components/MScheduler.vue +21 -0
- package/src/components/MScrollField.vue +302 -0
- package/src/components/MScrollable.vue +167 -4
- package/src/components/MSearchBar.vue +17 -0
- package/src/components/MSection.vue +13 -0
- package/src/components/MSegmentedButton.vue +10 -0
- package/src/components/MSelect.vue +22 -0
- package/src/components/MShader.vue +13 -0
- package/src/components/MShape.vue +6 -0
- package/src/components/MShortNavigationBar.vue +23 -9
- package/src/components/MSideSheet.vue +13 -0
- package/src/components/MSignaturePad.vue +15 -0
- package/src/components/MSimpleCarousel.vue +18 -0
- package/src/components/MSkeleton.vue +8 -0
- package/src/components/MSlider.vue +21 -0
- package/src/components/MSnackbar.vue +5 -0
- package/src/components/MSpacer.vue +6 -0
- package/src/components/MSpinner.vue +10 -0
- package/src/components/MSplitButton.vue +14 -0
- package/src/components/MSplitter.vue +42 -9
- package/src/components/MSpotlightSearch.vue +27 -0
- package/src/components/MStack.vue +12 -0
- package/src/components/MStatCard.vue +13 -0
- package/src/components/MStepper.vue +12 -0
- package/src/components/MSticky.vue +7 -0
- package/src/components/MSubtitle.vue +9 -0
- package/src/components/MSupportingPane.vue +10 -0
- package/src/components/MSwipeToDismiss.vue +247 -0
- package/src/components/MSwitch.vue +14 -6
- package/src/components/MTable.vue +33 -4
- package/src/components/MTabs.vue +12 -0
- package/src/components/MTagInput.vue +23 -0
- package/src/components/MTerminal.vue +11 -0
- package/src/components/MText.vue +15 -0
- package/src/components/MTextField.vue +26 -0
- package/src/components/MTimePicker.vue +15 -0
- package/src/components/MTimePickerModal.vue +12 -0
- package/src/components/MTimeline.vue +7 -0
- package/src/components/MTitle.vue +9 -0
- package/src/components/MToggleButton.vue +12 -0
- package/src/components/MToolbar.vue +12 -0
- package/src/components/MTooltip.vue +15 -0
- package/src/components/MTopAppBar.vue +18 -0
- package/src/components/MTour.vue +13 -0
- package/src/components/MTransferList.vue +24 -0
- package/src/components/MTransition.vue +149 -0
- package/src/components/MTree.vue +11 -0
- package/src/components/MTreeTable.vue +15 -0
- package/src/components/MVirtualTable.vue +12 -0
- package/src/components/MWindow.vue +34 -0
- package/src/components/_MColorPanel.vue +478 -0
- package/src/composables/_colorUtils.ts +107 -0
- package/src/composables/_themeColor.ts +33 -0
- package/src/composables/_useSpring.ts +89 -0
- package/src/composables/dynamicColor.ts +85 -0
- package/src/composables/useColorPalette.ts +171 -25
- package/src/composables/useFieldBg.ts +6 -0
- package/src/composables/useLocale.ts +38 -3
- package/src/index.ts +9 -1
- package/src/locales/de.ts +10 -0
- package/src/locales/es.ts +10 -0
- package/src/locales/fr.ts +10 -0
- package/src/locales/ja.ts +10 -0
- package/src/locales/ko.ts +10 -0
- package/src/locales/pt.ts +10 -0
- package/src/locales/zh.ts +10 -0
- package/src/plugin.ts +30 -8
- package/src/styles/palettes.css +546 -0
- package/src/styles/theme.css +77 -0
- package/dist/MTextField-B0wGv1Mx.js.map +0 -1
- package/dist/useLocale-CmI675Ab.js.map +0 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Internal: keeps <meta name="theme-color"> (the browser bar / status bar color on phones) in sync with a color
|
|
2
|
+
// role of the active palette, dark mode and seed included. Started by createM3UI({ themeColor }).
|
|
3
|
+
|
|
4
|
+
let observer: MutationObserver | undefined
|
|
5
|
+
|
|
6
|
+
function metas(): HTMLMetaElement[] {
|
|
7
|
+
const found = Array.from(document.querySelectorAll<HTMLMetaElement>('meta[name="theme-color"]'))
|
|
8
|
+
if (found.length) return found
|
|
9
|
+
const meta = document.createElement('meta')
|
|
10
|
+
meta.name = 'theme-color'
|
|
11
|
+
document.head.appendChild(meta)
|
|
12
|
+
return [meta]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function update(role: string) {
|
|
16
|
+
const color = getComputedStyle(document.documentElement).getPropertyValue(`--color-${role}`).trim()
|
|
17
|
+
if (!color) return
|
|
18
|
+
for (const meta of metas()) {
|
|
19
|
+
// A media-scoped pair (light/dark) would fight the live value: one meta, kept current, replaces them
|
|
20
|
+
meta.removeAttribute('media')
|
|
21
|
+
if (meta.content !== color) meta.content = color
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function syncThemeColor(role: string) {
|
|
26
|
+
if (typeof document === 'undefined') return
|
|
27
|
+
observer?.disconnect()
|
|
28
|
+
update(role)
|
|
29
|
+
// Palette (data-palette), dark mode and palette switches (class: dark, theme-transitioning) all land on <html>;
|
|
30
|
+
// a new seed also toggles theme-transitioning, after its CSS is in place
|
|
31
|
+
observer = new MutationObserver(() => update(role))
|
|
32
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class', 'data-palette'] })
|
|
33
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Internal: a set of numbers (corner radii, sizes...) that springs toward a target, written to the DOM
|
|
2
|
+
// once per frame through `apply`. Same integration as the rest of the library (semi-implicit Euler),
|
|
3
|
+
// in fixed 4ms substeps so a stiff spring stays stable on a dropped frame. Not exported from index.ts.
|
|
4
|
+
import { onMounted, onUnmounted, watch } from 'vue'
|
|
5
|
+
|
|
6
|
+
export interface SpringSpec { dampingRatio: number; stiffness: number }
|
|
7
|
+
|
|
8
|
+
/** MotionSchemeKeyTokens.FastSpatial in the Standard scheme (StandardMotionTokens.SpringFastSpatial*) */
|
|
9
|
+
export const FAST_SPATIAL: SpringSpec = { dampingRatio: 0.9, stiffness: 1400 }
|
|
10
|
+
/** MotionSchemeKeyTokens.DefaultEffects in the Standard scheme */
|
|
11
|
+
export const DEFAULT_EFFECTS: SpringSpec = { dampingRatio: 1, stiffness: 1600 }
|
|
12
|
+
/** MotionSchemeKeyTokens.DefaultSpatial in the Standard scheme */
|
|
13
|
+
export const DEFAULT_SPATIAL: SpringSpec = { dampingRatio: 0.9, stiffness: 700 }
|
|
14
|
+
|
|
15
|
+
const SUBSTEP = 0.004
|
|
16
|
+
|
|
17
|
+
export function useSpring(
|
|
18
|
+
target: () => number[],
|
|
19
|
+
apply: (values: readonly number[]) => void,
|
|
20
|
+
spec: SpringSpec = FAST_SPATIAL,
|
|
21
|
+
) {
|
|
22
|
+
let current = [...target()]
|
|
23
|
+
let velocity = current.map(() => 0)
|
|
24
|
+
let raf = 0
|
|
25
|
+
let last = 0
|
|
26
|
+
|
|
27
|
+
function frame(now: number) {
|
|
28
|
+
let dt = Math.min((now - last) / 1000, 1 / 30)
|
|
29
|
+
last = now
|
|
30
|
+
const t = target()
|
|
31
|
+
if (t.length !== current.length) {
|
|
32
|
+
current = [...t]
|
|
33
|
+
velocity = t.map(() => 0)
|
|
34
|
+
}
|
|
35
|
+
const k = spec.stiffness
|
|
36
|
+
const c = 2 * spec.dampingRatio * Math.sqrt(k)
|
|
37
|
+
while (dt > 0) {
|
|
38
|
+
const h = Math.min(dt, SUBSTEP)
|
|
39
|
+
dt -= h
|
|
40
|
+
for (let i = 0; i < t.length; i++) {
|
|
41
|
+
velocity[i]! += (-k * (current[i]! - t[i]!) - c * velocity[i]!) * h
|
|
42
|
+
current[i]! += velocity[i]! * h
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const settled = t.every((v, i) => Math.abs(v - current[i]!) < 0.05 && Math.abs(velocity[i]!) < 0.05)
|
|
46
|
+
if (settled) {
|
|
47
|
+
current = [...t]
|
|
48
|
+
velocity = t.map(() => 0)
|
|
49
|
+
}
|
|
50
|
+
apply(current)
|
|
51
|
+
raf = settled ? 0 : requestAnimationFrame(frame)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function start() {
|
|
55
|
+
if (raf) return
|
|
56
|
+
last = performance.now()
|
|
57
|
+
raf = requestAnimationFrame(frame)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Jumps to the target without animating (e.g. when the layout context changes). */
|
|
61
|
+
function snap() {
|
|
62
|
+
cancelAnimationFrame(raf)
|
|
63
|
+
raf = 0
|
|
64
|
+
current = [...target()]
|
|
65
|
+
velocity = current.map(() => 0)
|
|
66
|
+
apply(current)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
watch(() => target().join(','), start)
|
|
70
|
+
onMounted(() => apply(current))
|
|
71
|
+
onUnmounted(() => cancelAnimationFrame(raf))
|
|
72
|
+
|
|
73
|
+
return { snap }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Compose's FastOutSlowInEasing, cubic-bezier(0.4, 0, 0.2, 1) — the easing of a default tween() */
|
|
77
|
+
export function fastOutSlowIn(t: number): number {
|
|
78
|
+
if (t <= 0) return 0
|
|
79
|
+
if (t >= 1) return 1
|
|
80
|
+
// Solve x(u) = t for the curve parameter u (Newton), then return y(u)
|
|
81
|
+
let u = t
|
|
82
|
+
for (let i = 0; i < 8; i++) {
|
|
83
|
+
const x = 3 * u * (1 - u) ** 2 * 0.4 + 3 * u ** 2 * (1 - u) * 0.2 + u ** 3 - t
|
|
84
|
+
const dx = 3 * (1 - u) ** 2 * 0.4 + 6 * u * (1 - u) * (0.2 - 0.4) + 3 * u ** 2 * 0.8
|
|
85
|
+
if (Math.abs(dx) < 1e-6) break
|
|
86
|
+
u -= x / dx
|
|
87
|
+
}
|
|
88
|
+
return 3 * u ** 2 * (1 - u) + u ** 3
|
|
89
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Dynamic color: a full M3 color scheme (light and dark) generated from one seed color with Google's
|
|
2
|
+
// material-color-utilities (HCT, DynamicScheme). The package is loaded with a dynamic import, so apps that
|
|
3
|
+
// never use a seed don't download it; it's bundled into the library (its 0.4.0 ESM build has an extensionless
|
|
4
|
+
// import that Node can't resolve, which would break SSR and tests if it were left external).
|
|
5
|
+
|
|
6
|
+
export type SchemeVariant =
|
|
7
|
+
| 'tonal-spot'
|
|
8
|
+
| 'expressive'
|
|
9
|
+
| 'vibrant'
|
|
10
|
+
| 'fidelity'
|
|
11
|
+
| 'content'
|
|
12
|
+
| 'neutral'
|
|
13
|
+
| 'monochrome'
|
|
14
|
+
| 'rainbow'
|
|
15
|
+
| 'fruit-salad'
|
|
16
|
+
|
|
17
|
+
export interface SeedOptions {
|
|
18
|
+
/** How the seed spreads into the scheme. `tonal-spot` is Android's default (calm, seed-led). */
|
|
19
|
+
variant?: SchemeVariant
|
|
20
|
+
/** Contrast level: 0 standard, 0.5 medium, 1 high (-1 reduced). */
|
|
21
|
+
contrast?: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Token name (as in `--color-<name>`) → hex, for each scheme. */
|
|
25
|
+
export interface GeneratedScheme {
|
|
26
|
+
light: Record<string, string>
|
|
27
|
+
dark: Record<string, string>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The `--color-*` roles a generated scheme sets. `success*` is a library extension and stays as themed. */
|
|
31
|
+
export const schemeRoles = [
|
|
32
|
+
'primary', 'on-primary', 'primary-container', 'on-primary-container',
|
|
33
|
+
'secondary', 'on-secondary', 'secondary-container', 'on-secondary-container',
|
|
34
|
+
'tertiary', 'on-tertiary', 'tertiary-container', 'on-tertiary-container',
|
|
35
|
+
'error', 'on-error', 'error-container', 'on-error-container',
|
|
36
|
+
'background', 'on-background',
|
|
37
|
+
'surface', 'on-surface', 'surface-variant', 'on-surface-variant',
|
|
38
|
+
'surface-dim', 'surface-bright',
|
|
39
|
+
'surface-container-lowest', 'surface-container-low', 'surface-container',
|
|
40
|
+
'surface-container-high', 'surface-container-highest',
|
|
41
|
+
'outline', 'outline-variant',
|
|
42
|
+
'inverse-surface', 'inverse-on-surface', 'inverse-primary',
|
|
43
|
+
'scrim', 'shadow',
|
|
44
|
+
'primary-fixed', 'primary-fixed-dim', 'on-primary-fixed', 'on-primary-fixed-variant',
|
|
45
|
+
'secondary-fixed', 'secondary-fixed-dim', 'on-secondary-fixed', 'on-secondary-fixed-variant',
|
|
46
|
+
'tertiary-fixed', 'tertiary-fixed-dim', 'on-tertiary-fixed', 'on-tertiary-fixed-variant',
|
|
47
|
+
] as const
|
|
48
|
+
|
|
49
|
+
const camel = (role: string) => role.replace(/-([a-z])/g, (_, c: string) => c.toUpperCase())
|
|
50
|
+
|
|
51
|
+
/** Generates the light and dark schemes for a seed color (`#rrggbb`). */
|
|
52
|
+
export async function generateScheme(seed: string, options: SeedOptions = {}): Promise<GeneratedScheme> {
|
|
53
|
+
const mcu = await import('@material/material-color-utilities')
|
|
54
|
+
const variants = {
|
|
55
|
+
'tonal-spot': mcu.SchemeTonalSpot,
|
|
56
|
+
expressive: mcu.SchemeExpressive,
|
|
57
|
+
vibrant: mcu.SchemeVibrant,
|
|
58
|
+
fidelity: mcu.SchemeFidelity,
|
|
59
|
+
content: mcu.SchemeContent,
|
|
60
|
+
neutral: mcu.SchemeNeutral,
|
|
61
|
+
monochrome: mcu.SchemeMonochrome,
|
|
62
|
+
rainbow: mcu.SchemeRainbow,
|
|
63
|
+
'fruit-salad': mcu.SchemeFruitSalad,
|
|
64
|
+
}
|
|
65
|
+
const Scheme = variants[options.variant ?? 'tonal-spot'] ?? mcu.SchemeTonalSpot
|
|
66
|
+
const source = mcu.Hct.fromInt(mcu.argbFromHex(seed))
|
|
67
|
+
const colors = new mcu.MaterialDynamicColors() as unknown as Record<string, () => { getArgb(s: unknown): number }>
|
|
68
|
+
const build = (dark: boolean) => {
|
|
69
|
+
const scheme = new Scheme(source, dark, options.contrast ?? 0)
|
|
70
|
+
const out: Record<string, string> = {}
|
|
71
|
+
for (const role of schemeRoles) {
|
|
72
|
+
const color = colors[camel(role)]?.call(colors)
|
|
73
|
+
if (color) out[role] = mcu.hexFromArgb(color.getArgb(scheme))
|
|
74
|
+
}
|
|
75
|
+
return out
|
|
76
|
+
}
|
|
77
|
+
return { light: build(false), dark: build(true) }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** CSS for a scheme under `[data-palette='<id>']` (light) and `[data-palette='<id>'].dark`, like palettes.css. */
|
|
81
|
+
export function schemeToCss(scheme: GeneratedScheme, id: string): string {
|
|
82
|
+
const block = (tokens: Record<string, string>) =>
|
|
83
|
+
Object.entries(tokens).map(([k, v]) => ` --color-${k}: ${v};`).join('\n')
|
|
84
|
+
return `[data-palette='${id}'] {\n${block(scheme.light)}\n}\n[data-palette='${id}'].dark {\n color-scheme: dark;\n${block(scheme.dark)}\n}\n`
|
|
85
|
+
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { ref, watchEffect } from 'vue'
|
|
1
|
+
import { readonly, ref, watchEffect } from 'vue'
|
|
2
|
+
import { generateScheme, schemeToCss, type SeedOptions } from './dynamicColor'
|
|
2
3
|
|
|
3
4
|
export interface Palette {
|
|
4
5
|
id: string
|
|
5
6
|
label: string
|
|
7
|
+
/**
|
|
8
|
+
* The palette's key color. A custom palette (`createM3UI({ customPalettes })`) with no CSS of its own gets its
|
|
9
|
+
* scheme generated from it; one with `[data-palette='<id>']` rules keeps them.
|
|
10
|
+
*/
|
|
6
11
|
seed: string
|
|
7
12
|
}
|
|
8
13
|
|
|
@@ -49,44 +54,171 @@ export const palettes: Palette[] = [
|
|
|
49
54
|
{ id: 'mauve', label: 'Mauve', seed: '#914277' },
|
|
50
55
|
]
|
|
51
56
|
|
|
52
|
-
|
|
57
|
+
// Ids whose CSS ships in palettes.css (plus 'purple', the theme.css baseline): never generated
|
|
58
|
+
const builtInIds = new Set(palettes.map((p) => p.id))
|
|
59
|
+
|
|
60
|
+
/** The palette id used while a seed color is active (`useColorPalette().setSeed()`). */
|
|
61
|
+
export const SEED_PALETTE = 'seed'
|
|
62
|
+
|
|
63
|
+
export interface ActiveSeed extends SeedOptions {
|
|
64
|
+
seed: string
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const PALETTE_KEY = 'm3-palette'
|
|
68
|
+
const SEED_KEY = 'm3-seed'
|
|
69
|
+
// The generated CSS of the active palette, so a reload applies it before the generator has loaded
|
|
70
|
+
const CSS_KEY = 'm3-palette-css'
|
|
71
|
+
|
|
72
|
+
function read<T>(key: string): T | null {
|
|
73
|
+
try {
|
|
74
|
+
const v = localStorage.getItem(key)
|
|
75
|
+
return v == null ? null : (key === PALETTE_KEY ? v : JSON.parse(v)) as T
|
|
76
|
+
} catch {
|
|
77
|
+
return null
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function write(key: string, value: unknown) {
|
|
81
|
+
try {
|
|
82
|
+
if (value == null) localStorage.removeItem(key)
|
|
83
|
+
else localStorage.setItem(key, typeof value === 'string' ? value : JSON.stringify(value))
|
|
84
|
+
} catch { /* storage blocked */ }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const current = ref(read<string>(PALETTE_KEY) ?? 'purple')
|
|
88
|
+
const activeSeed = ref<ActiveSeed | null>(read<ActiveSeed>(SEED_KEY))
|
|
53
89
|
|
|
54
90
|
// Whether palette changes are written to localStorage. Defaults to true (existing behavior).
|
|
55
91
|
// An app can disable it via `createM3UI({ persistPalette: false })` or `useColorPalette().setPersistPalette(false)`
|
|
56
92
|
// so its chosen palette can't be overridden by a stored value on the next boot.
|
|
57
93
|
const persistEnabled = ref(true)
|
|
58
94
|
|
|
95
|
+
function applyAttribute(id: string) {
|
|
96
|
+
if (id === 'purple') document.documentElement.removeAttribute('data-palette')
|
|
97
|
+
else document.documentElement.setAttribute('data-palette', id)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ── Generated palettes ──────────────────────────────────────────────────────────────────────────
|
|
101
|
+
// One <style> element holds the generated CSS of the active palette (a seed, or a custom palette
|
|
102
|
+
// without CSS of its own).
|
|
103
|
+
|
|
104
|
+
const STYLE_ID = 'm3-dynamic-palette'
|
|
105
|
+
|
|
106
|
+
function injectCss(css: string) {
|
|
107
|
+
let el = document.getElementById(STYLE_ID) as HTMLStyleElement | null
|
|
108
|
+
if (!el) {
|
|
109
|
+
el = document.createElement('style')
|
|
110
|
+
el.id = STYLE_ID
|
|
111
|
+
document.head.appendChild(el)
|
|
112
|
+
}
|
|
113
|
+
el.textContent = css
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Whether a stylesheet (other than our generated one) already styles `[data-palette='<id>']`. */
|
|
117
|
+
function hasPaletteCss(id: string): boolean {
|
|
118
|
+
const needles = [`[data-palette="${id}"]`, `[data-palette='${id}']`, `[data-palette=${id}]`]
|
|
119
|
+
const scan = (rules: CSSRuleList): boolean => {
|
|
120
|
+
for (const rule of Array.from(rules)) {
|
|
121
|
+
const selector = (rule as CSSStyleRule).selectorText
|
|
122
|
+
if (selector && needles.some((n) => selector.includes(n))) return true
|
|
123
|
+
const nested = (rule as CSSGroupingRule).cssRules
|
|
124
|
+
if (nested && scan(nested)) return true
|
|
125
|
+
}
|
|
126
|
+
return false
|
|
127
|
+
}
|
|
128
|
+
for (const sheet of Array.from(document.styleSheets)) {
|
|
129
|
+
if ((sheet.ownerNode as Element | null)?.id === STYLE_ID) continue
|
|
130
|
+
try {
|
|
131
|
+
if (scan(sheet.cssRules)) return true
|
|
132
|
+
} catch { /* cross-origin sheet */ }
|
|
133
|
+
}
|
|
134
|
+
return false
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
let generation = 0
|
|
138
|
+
|
|
139
|
+
/** Generates and injects the CSS for a palette id from a seed. Resolves false if a newer request won. */
|
|
140
|
+
async function generateInto(id: string, seed: ActiveSeed): Promise<boolean> {
|
|
141
|
+
const mine = ++generation
|
|
142
|
+
const css = schemeToCss(await generateScheme(seed.seed, seed), id)
|
|
143
|
+
if (mine !== generation) return false
|
|
144
|
+
injectCss(css)
|
|
145
|
+
if (persistEnabled.value) write(CSS_KEY, { id, css })
|
|
146
|
+
return true
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Switches to a palette id with the theme transition. Applied directly, not only through useColorPalette()'s
|
|
150
|
+
* watcher, so it also works when no component uses the composable (createM3UI's defaults). */
|
|
151
|
+
function switchTo(id: string) {
|
|
152
|
+
document.documentElement.classList.add('theme-transitioning')
|
|
153
|
+
void document.documentElement.offsetHeight
|
|
154
|
+
current.value = id
|
|
155
|
+
applyAttribute(id)
|
|
156
|
+
if (persistEnabled.value) write(PALETTE_KEY, id)
|
|
157
|
+
setTimeout(() => document.documentElement.classList.remove('theme-transitioning'), 300)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Picks a palette by id; a custom one with a seed and no CSS of its own is generated first. */
|
|
161
|
+
async function selectPalette(id: string) {
|
|
162
|
+
generation++
|
|
163
|
+
const custom = palettes.find((p) => p.id === id)
|
|
164
|
+
if (custom && !builtInIds.has(id) && custom.seed && !hasPaletteCss(id)) {
|
|
165
|
+
if (!(await generateInto(id, { seed: custom.seed }))) return
|
|
166
|
+
}
|
|
167
|
+
switchTo(id)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Activates a seed color: generates its scheme and switches to it. */
|
|
171
|
+
async function selectSeed(seed: string, options: SeedOptions = {}) {
|
|
172
|
+
const next: ActiveSeed = { seed, ...options }
|
|
173
|
+
if (!(await generateInto(SEED_PALETTE, next))) return
|
|
174
|
+
activeSeed.value = next
|
|
175
|
+
if (persistEnabled.value) write(SEED_KEY, next)
|
|
176
|
+
switchTo(SEED_PALETTE)
|
|
177
|
+
}
|
|
178
|
+
|
|
59
179
|
export function useColorPalette() {
|
|
60
180
|
watchEffect(() => {
|
|
61
181
|
const id = current.value
|
|
62
|
-
if (persistEnabled.value)
|
|
63
|
-
|
|
64
|
-
if (id === 'purple') {
|
|
65
|
-
document.documentElement.removeAttribute('data-palette')
|
|
66
|
-
} else {
|
|
67
|
-
document.documentElement.setAttribute('data-palette', id)
|
|
68
|
-
}
|
|
182
|
+
if (persistEnabled.value) write(PALETTE_KEY, id)
|
|
183
|
+
applyAttribute(id)
|
|
69
184
|
})
|
|
70
185
|
|
|
186
|
+
/** Switches to a palette by id. */
|
|
71
187
|
function set(id: string) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
188
|
+
void selectPalette(id)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Switches to a scheme generated from a seed color (Google's dynamic color: HCT, `tonal-spot` by default).
|
|
193
|
+
* `palette` becomes `'seed'`. The last choice wins: `set(id)` afterwards switches back to that palette, and
|
|
194
|
+
* `seed` keeps the last seed so a picker can offer it again.
|
|
195
|
+
*/
|
|
196
|
+
function setSeed(seed: string, options?: SeedOptions) {
|
|
197
|
+
return selectSeed(seed, options)
|
|
76
198
|
}
|
|
77
199
|
|
|
78
200
|
function setPersistPalette(enabled: boolean) {
|
|
79
201
|
persistEnabled.value = enabled
|
|
80
|
-
if (enabled)
|
|
202
|
+
if (enabled) write(PALETTE_KEY, current.value)
|
|
81
203
|
}
|
|
82
204
|
|
|
83
|
-
return {
|
|
205
|
+
return {
|
|
206
|
+
palette: current,
|
|
207
|
+
palettes,
|
|
208
|
+
set,
|
|
209
|
+
seed: readonly(activeSeed),
|
|
210
|
+
setSeed,
|
|
211
|
+
persistPalette: persistEnabled,
|
|
212
|
+
setPersistPalette,
|
|
213
|
+
}
|
|
84
214
|
}
|
|
85
215
|
|
|
86
|
-
// Apply on module load so palette is visible before any component mounts
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
216
|
+
// Apply on module load so the palette is visible before any component mounts, a generated one included
|
|
217
|
+
{
|
|
218
|
+
const saved = read<string>(PALETTE_KEY)
|
|
219
|
+
const cached = read<{ id: string; css: string }>(CSS_KEY)
|
|
220
|
+
if (saved && cached && cached.id === saved) injectCss(cached.css)
|
|
221
|
+
if (saved && saved !== 'purple') document.documentElement.setAttribute('data-palette', saved)
|
|
90
222
|
}
|
|
91
223
|
|
|
92
224
|
/**
|
|
@@ -98,10 +230,24 @@ if (saved && saved !== 'purple') {
|
|
|
98
230
|
export function __forcePalette(id: string, persist: boolean) {
|
|
99
231
|
persistEnabled.value = persist
|
|
100
232
|
current.value = id
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
233
|
+
applyAttribute(id)
|
|
234
|
+
if (persist) write(PALETTE_KEY, id)
|
|
235
|
+
if (palettes.some((p) => p.id === id) && !builtInIds.has(id)) void selectPalette(id)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Internal: `createM3UI({ palette })`'s first-visit default. Sets `current` too, so a later `useColorPalette()`
|
|
240
|
+
* doesn't write its stale initial value back over it.
|
|
241
|
+
*/
|
|
242
|
+
export function __defaultPalette(id: string) {
|
|
243
|
+
current.value = id
|
|
244
|
+
applyAttribute(id)
|
|
245
|
+
write(PALETTE_KEY, id)
|
|
246
|
+
if (palettes.some((p) => p.id === id) && !builtInIds.has(id)) void selectPalette(id)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** Internal: `createM3UI({ seed })`. */
|
|
250
|
+
export function __defaultSeed(seed: string, options: SeedOptions | undefined, persist: boolean) {
|
|
251
|
+
persistEnabled.value = persist
|
|
252
|
+
return selectSeed(seed, options)
|
|
107
253
|
}
|
|
@@ -16,6 +16,12 @@ const M3_BG_CLASSES = [
|
|
|
16
16
|
'bg-secondary-container',
|
|
17
17
|
'bg-tertiary-container',
|
|
18
18
|
'bg-error-container',
|
|
19
|
+
'bg-primary-fixed',
|
|
20
|
+
'bg-primary-fixed-dim',
|
|
21
|
+
'bg-secondary-fixed',
|
|
22
|
+
'bg-secondary-fixed-dim',
|
|
23
|
+
'bg-tertiary-fixed',
|
|
24
|
+
'bg-tertiary-fixed-dim',
|
|
19
25
|
'bg-primary',
|
|
20
26
|
'bg-secondary',
|
|
21
27
|
'bg-tertiary',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { inject, reactive, watchEffect, toValue, type InjectionKey, type MaybeRef } from 'vue'
|
|
1
|
+
import { inject, reactive, shallowRef, watchEffect, toValue, type InjectionKey, type MaybeRef } from 'vue'
|
|
2
2
|
|
|
3
3
|
export interface M3Locale {
|
|
4
4
|
/** BCP-47 language tag (e.g. 'en', 'es', 'pt') — read by locale-aware components (MRelativeTime) that use Intl formatting. */
|
|
@@ -45,6 +45,18 @@ export interface M3Locale {
|
|
|
45
45
|
previousMonth: string
|
|
46
46
|
nextMonth: string
|
|
47
47
|
|
|
48
|
+
// Color picker
|
|
49
|
+
selectColor: string
|
|
50
|
+
colorHue: string
|
|
51
|
+
colorSaturation: string
|
|
52
|
+
colorBrightness: string
|
|
53
|
+
colorAlpha: string
|
|
54
|
+
colorEyedropper: string
|
|
55
|
+
colorOriginal: string
|
|
56
|
+
colorFormat: string
|
|
57
|
+
colorRecent: string
|
|
58
|
+
colorPresets: string
|
|
59
|
+
|
|
48
60
|
// Scheduler
|
|
49
61
|
dayView: string
|
|
50
62
|
weekView: string
|
|
@@ -205,6 +217,16 @@ export const defaultLocale: M3Locale = {
|
|
|
205
217
|
pickEnd: 'Select end',
|
|
206
218
|
previousMonth: 'Previous month',
|
|
207
219
|
nextMonth: 'Next month',
|
|
220
|
+
selectColor: 'Select color',
|
|
221
|
+
colorHue: 'Hue',
|
|
222
|
+
colorSaturation: 'Saturation',
|
|
223
|
+
colorBrightness: 'Brightness',
|
|
224
|
+
colorAlpha: 'Opacity',
|
|
225
|
+
colorEyedropper: 'Pick a color from the screen',
|
|
226
|
+
colorOriginal: 'Original color',
|
|
227
|
+
colorFormat: 'Color format',
|
|
228
|
+
colorRecent: 'Recent',
|
|
229
|
+
colorPresets: 'Presets',
|
|
208
230
|
|
|
209
231
|
dayView: 'Day',
|
|
210
232
|
weekView: 'Week',
|
|
@@ -323,12 +345,25 @@ export const defaultLocale: M3Locale = {
|
|
|
323
345
|
|
|
324
346
|
export const M3_LOCALE_KEY: InjectionKey<MaybeRef<Partial<M3Locale>>> = Symbol('m3-locale')
|
|
325
347
|
|
|
348
|
+
/**
|
|
349
|
+
* The locale given to `createM3UI()`, for components rendered outside the app that installed it:
|
|
350
|
+
* `useToast()` and `useNotification()` mount their hosts with an app of their own, where the
|
|
351
|
+
* plugin's `provide` doesn't reach. Inside the user's app the provided locale still wins.
|
|
352
|
+
*/
|
|
353
|
+
// Wrapped in an object: a shallowRef holding a ref directly gets that ref unwrapped in its type.
|
|
354
|
+
const appLocale = shallowRef<{ locale: MaybeRef<Partial<M3Locale>> } | null>(null)
|
|
355
|
+
|
|
356
|
+
/** @internal Called by `createM3UI()`; not exported from the package. */
|
|
357
|
+
export function __setAppLocale(locale: MaybeRef<Partial<M3Locale>> | null) {
|
|
358
|
+
appLocale.value = locale ? { locale } : null
|
|
359
|
+
}
|
|
360
|
+
|
|
326
361
|
export function useLocale(): M3Locale {
|
|
327
|
-
const provided = inject(M3_LOCALE_KEY,
|
|
362
|
+
const provided = inject(M3_LOCALE_KEY, null)
|
|
328
363
|
const locale = reactive({ ...defaultLocale }) as M3Locale
|
|
329
364
|
|
|
330
365
|
watchEffect(() => {
|
|
331
|
-
Object.assign(locale, defaultLocale, toValue(provided))
|
|
366
|
+
Object.assign(locale, defaultLocale, toValue(provided ?? appLocale.value?.locale ?? {}))
|
|
332
367
|
})
|
|
333
368
|
|
|
334
369
|
return locale
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,10 @@ export type { M3UIOptions } from './plugin'
|
|
|
6
6
|
export { useTheme } from './composables/useTheme'
|
|
7
7
|
export type { Theme } from './composables/useTheme'
|
|
8
8
|
export { useColorPalette, palettes } from './composables/useColorPalette'
|
|
9
|
-
export type { Palette } from './composables/useColorPalette'
|
|
9
|
+
export type { Palette, ActiveSeed } from './composables/useColorPalette'
|
|
10
|
+
export { SEED_PALETTE } from './composables/useColorPalette'
|
|
11
|
+
export { generateScheme, schemeToCss, schemeRoles } from './composables/dynamicColor'
|
|
12
|
+
export type { SchemeVariant, SeedOptions, GeneratedScheme } from './composables/dynamicColor'
|
|
10
13
|
export { useToast } from './composables/useToast'
|
|
11
14
|
export type { Toast, ToastVariant, ToastPosition, ToastAction, ToastOptions } from './composables/useToast'
|
|
12
15
|
export { useFieldBg } from './composables/useFieldBg'
|
|
@@ -60,6 +63,7 @@ export { default as MDateRangePicker } from './components/MDateRangePicker.vue'
|
|
|
60
63
|
export { default as MDateRangePickerModal } from './components/MDateRangePickerModal.vue'
|
|
61
64
|
export { default as MDialog } from './components/MDialog.vue'
|
|
62
65
|
export { default as MDivider } from './components/MDivider.vue'
|
|
66
|
+
export { default as MDragHandle } from './components/MDragHandle.vue'
|
|
63
67
|
export { default as MDragDropList } from './components/MDragDropList.vue'
|
|
64
68
|
export { default as MEmoji } from './components/MEmoji.vue'
|
|
65
69
|
export { default as MEmojiButton } from './components/MEmojiButton.vue'
|
|
@@ -130,6 +134,7 @@ export { default as MScrollable } from './components/MScrollable.vue'
|
|
|
130
134
|
export { default as MSearchBar } from './components/MSearchBar.vue'
|
|
131
135
|
export { default as MSection } from './components/MSection.vue'
|
|
132
136
|
export { default as MSegmentedButton } from './components/MSegmentedButton.vue'
|
|
137
|
+
export { default as MScrollField } from './components/MScrollField.vue'
|
|
133
138
|
export { default as MSelect } from './components/MSelect.vue'
|
|
134
139
|
export type { SelectOption } from './components/MSelect.vue'
|
|
135
140
|
export { default as MShader } from './components/MShader.vue'
|
|
@@ -156,6 +161,8 @@ export { default as MStatCard } from './components/MStatCard.vue'
|
|
|
156
161
|
export { default as MStepper } from './components/MStepper.vue'
|
|
157
162
|
export { default as MSticky } from './components/MSticky.vue'
|
|
158
163
|
export { default as MSubtitle } from './components/MSubtitle.vue'
|
|
164
|
+
export { default as MSwipeToDismiss } from './components/MSwipeToDismiss.vue'
|
|
165
|
+
export type { SwipeToDismissValue } from './components/MSwipeToDismiss.vue'
|
|
159
166
|
export { default as MSwitch } from './components/MSwitch.vue'
|
|
160
167
|
export { default as MTable } from './components/MTable.vue'
|
|
161
168
|
export { default as MTagInput } from './components/MTagInput.vue'
|
|
@@ -174,6 +181,7 @@ export { default as MTopAppBar } from './components/MTopAppBar.vue'
|
|
|
174
181
|
export { default as MTour } from './components/MTour.vue'
|
|
175
182
|
export { default as MTransferList } from './components/MTransferList.vue'
|
|
176
183
|
export { default as MTree } from './components/MTree.vue'
|
|
184
|
+
export { default as MTransition } from './components/MTransition.vue'
|
|
177
185
|
export { default as MTreeTable } from './components/MTreeTable.vue'
|
|
178
186
|
export { default as MVirtualTable } from './components/MVirtualTable.vue'
|
|
179
187
|
export { default as MWindow } from './components/MWindow.vue'
|
package/src/locales/de.ts
CHANGED
|
@@ -43,6 +43,16 @@ export const deLocale: M3Locale = {
|
|
|
43
43
|
pickEnd: 'Ende auswählen',
|
|
44
44
|
previousMonth: 'Vorheriger Monat',
|
|
45
45
|
nextMonth: 'Nächster Monat',
|
|
46
|
+
selectColor: 'Farbe auswählen',
|
|
47
|
+
colorHue: 'Farbton',
|
|
48
|
+
colorSaturation: 'Sättigung',
|
|
49
|
+
colorBrightness: 'Helligkeit',
|
|
50
|
+
colorAlpha: 'Deckkraft',
|
|
51
|
+
colorEyedropper: 'Farbe vom Bildschirm aufnehmen',
|
|
52
|
+
colorOriginal: 'Ursprüngliche Farbe',
|
|
53
|
+
colorFormat: 'Farbformat',
|
|
54
|
+
colorRecent: 'Zuletzt verwendet',
|
|
55
|
+
colorPresets: 'Vorgaben',
|
|
46
56
|
|
|
47
57
|
// Scheduler
|
|
48
58
|
dayView: 'Tag',
|
package/src/locales/es.ts
CHANGED
|
@@ -43,6 +43,16 @@ export const esLocale: M3Locale = {
|
|
|
43
43
|
pickEnd: 'Seleccionar fin',
|
|
44
44
|
previousMonth: 'Mes anterior',
|
|
45
45
|
nextMonth: 'Mes siguiente',
|
|
46
|
+
selectColor: 'Seleccionar color',
|
|
47
|
+
colorHue: 'Tono',
|
|
48
|
+
colorSaturation: 'Saturación',
|
|
49
|
+
colorBrightness: 'Brillo',
|
|
50
|
+
colorAlpha: 'Opacidad',
|
|
51
|
+
colorEyedropper: 'Tomar un color de la pantalla',
|
|
52
|
+
colorOriginal: 'Color original',
|
|
53
|
+
colorFormat: 'Formato de color',
|
|
54
|
+
colorRecent: 'Recientes',
|
|
55
|
+
colorPresets: 'Predefinidos',
|
|
46
56
|
|
|
47
57
|
// Scheduler
|
|
48
58
|
dayView: 'Día',
|
package/src/locales/fr.ts
CHANGED
|
@@ -43,6 +43,16 @@ export const frLocale: M3Locale = {
|
|
|
43
43
|
pickEnd: 'Sélectionner la fin',
|
|
44
44
|
previousMonth: 'Mois précédent',
|
|
45
45
|
nextMonth: 'Mois suivant',
|
|
46
|
+
selectColor: 'Choisir une couleur',
|
|
47
|
+
colorHue: 'Teinte',
|
|
48
|
+
colorSaturation: 'Saturation',
|
|
49
|
+
colorBrightness: 'Luminosité',
|
|
50
|
+
colorAlpha: 'Opacité',
|
|
51
|
+
colorEyedropper: 'Prélever une couleur à l\'écran',
|
|
52
|
+
colorOriginal: 'Couleur d’origine',
|
|
53
|
+
colorFormat: 'Format de couleur',
|
|
54
|
+
colorRecent: 'Récentes',
|
|
55
|
+
colorPresets: 'Prédéfinies',
|
|
46
56
|
|
|
47
57
|
// Scheduler
|
|
48
58
|
dayView: 'Jour',
|
package/src/locales/ja.ts
CHANGED
|
@@ -43,6 +43,16 @@ export const jaLocale: M3Locale = {
|
|
|
43
43
|
pickEnd: '終了を選択',
|
|
44
44
|
previousMonth: '前月',
|
|
45
45
|
nextMonth: '翌月',
|
|
46
|
+
selectColor: '色を選択',
|
|
47
|
+
colorHue: '色相',
|
|
48
|
+
colorSaturation: '彩度',
|
|
49
|
+
colorBrightness: '明度',
|
|
50
|
+
colorAlpha: '不透明度',
|
|
51
|
+
colorEyedropper: '画面から色を取得',
|
|
52
|
+
colorOriginal: '元の色',
|
|
53
|
+
colorFormat: 'カラー形式',
|
|
54
|
+
colorRecent: '最近使用',
|
|
55
|
+
colorPresets: 'プリセット',
|
|
46
56
|
|
|
47
57
|
// Scheduler
|
|
48
58
|
dayView: '日',
|
package/src/locales/ko.ts
CHANGED
|
@@ -43,6 +43,16 @@ export const koLocale: M3Locale = {
|
|
|
43
43
|
pickEnd: '종료 선택',
|
|
44
44
|
previousMonth: '이전 달',
|
|
45
45
|
nextMonth: '다음 달',
|
|
46
|
+
selectColor: '색상 선택',
|
|
47
|
+
colorHue: '색조',
|
|
48
|
+
colorSaturation: '채도',
|
|
49
|
+
colorBrightness: '밝기',
|
|
50
|
+
colorAlpha: '불투명도',
|
|
51
|
+
colorEyedropper: '화면에서 색상 가져오기',
|
|
52
|
+
colorOriginal: '원래 색상',
|
|
53
|
+
colorFormat: '색상 형식',
|
|
54
|
+
colorRecent: '최근 사용',
|
|
55
|
+
colorPresets: '프리셋',
|
|
46
56
|
|
|
47
57
|
// Scheduler
|
|
48
58
|
dayView: '일',
|