@m3ui-vue/m3ui-vue 1.0.1 → 1.0.3
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 +636 -20
- package/dist/MMenuItem-DFyXflk9.js +707 -0
- package/dist/MMenuItem-DFyXflk9.js.map +1 -0
- package/dist/MSlider-CdNIH7jc.js +1376 -0
- package/dist/MSlider-CdNIH7jc.js.map +1 -0
- package/dist/MTextField-B4X92vH_.js +671 -0
- package/dist/MTextField-B4X92vH_.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/chart.js +1 -1
- package/dist/chart.js.map +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MIconButton.vue.d.ts +1 -1
- package/dist/components/MMap.vue.d.ts +74 -0
- package/dist/components/MMapBaseLayers.vue.d.ts +15 -0
- package/dist/components/MMapControl.vue.d.ts +23 -0
- package/dist/components/MMapFeatureInfo.vue.d.ts +25 -0
- package/dist/components/MMapFilter.vue.d.ts +19 -0
- package/dist/components/MMapGeoJson.vue.d.ts +34 -0
- package/dist/components/MMapHover.vue.d.ts +17 -0
- package/dist/components/MMapIdentify.vue.d.ts +37 -0
- package/dist/components/MMapLayers.vue.d.ts +31 -0
- package/dist/components/MMapMarker.vue.d.ts +42 -0
- package/dist/components/MMapMeasure.vue.d.ts +43 -0
- package/dist/components/MMapPopup.vue.d.ts +43 -0
- package/dist/components/MMapSearch.vue.d.ts +28 -0
- package/dist/components/MShader.vue.d.ts +9 -3
- package/dist/components/_MMapLayerItem.vue.d.ts +25 -0
- package/dist/composables/_hydration.d.ts +4 -0
- package/dist/composables/_mapGeometry.d.ts +13 -0
- package/dist/composables/_ssrState.d.ts +30 -0
- package/dist/composables/_storageKeys.d.ts +3 -0
- package/dist/composables/_useThemeTokens.d.ts +7 -0
- package/dist/composables/mapAdapters.d.ts +111 -0
- package/dist/composables/mapSearch.d.ts +31 -0
- package/dist/composables/themeInitScript.d.ts +22 -0
- package/dist/composables/useColorPalette.d.ts +176 -6
- package/dist/composables/useLocale.d.ts +30 -0
- package/dist/composables/useMap.d.ts +47 -0
- package/dist/composables/useMapFilter.d.ts +10 -0
- package/dist/composables/useMapLayers.d.ts +30 -0
- package/dist/composables/useTheme.d.ts +2 -0
- package/dist/index.d.ts +4 -1
- package/dist/locales/index.js +217 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +6742 -7961
- package/dist/m3ui.js.map +1 -1
- package/dist/map.d.ts +24 -0
- package/dist/map.js +1931 -0
- package/dist/map.js.map +1 -0
- package/dist/plugin.d.ts +25 -2
- package/dist/rich-text-editor.js +27 -26
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/{useLocale-CuvWRZ1h.js → useLocale-b5-hzsL3.js} +32 -2
- package/dist/useLocale-b5-hzsL3.js.map +1 -0
- package/package.json +11 -2
- package/src/__tests__/MFab.test.ts +52 -6
- package/src/__tests__/MMap.test.ts +292 -0
- package/src/__tests__/MMapLayers.test.ts +257 -0
- package/src/__tests__/MMapTools.test.ts +233 -0
- package/src/__tests__/MShader.test.ts +16 -0
- package/src/__tests__/_fakeMaplibre.ts +158 -0
- package/src/__tests__/hydration.test.ts +119 -0
- package/src/__tests__/ssr.test.ts +171 -0
- package/src/__tests__/ssrState.test.ts +155 -0
- package/src/__tests__/themeInitScript.test.ts +122 -0
- package/src/components/MChart.vue +3 -2
- package/src/components/MFab.vue +29 -7
- package/src/components/MIconButton.vue +1 -1
- package/src/components/MLightbox.vue +10 -1
- package/src/components/MMap.vue +522 -0
- package/src/components/MMapBaseLayers.vue +67 -0
- package/src/components/MMapControl.vue +61 -0
- package/src/components/MMapFeatureInfo.vue +41 -0
- package/src/components/MMapFilter.vue +80 -0
- package/src/components/MMapGeoJson.vue +136 -0
- package/src/components/MMapHover.vue +131 -0
- package/src/components/MMapIdentify.vue +103 -0
- package/src/components/MMapLayers.vue +111 -0
- package/src/components/MMapMarker.vue +102 -0
- package/src/components/MMapMeasure.vue +452 -0
- package/src/components/MMapPopup.vue +99 -0
- package/src/components/MMapSearch.vue +162 -0
- package/src/components/MSearchBar.vue +4 -1
- package/src/components/MShader.vue +11 -3
- package/src/components/_MMapLayerItem.vue +77 -0
- package/src/composables/_hydration.ts +10 -0
- package/src/composables/_mapGeometry.ts +75 -0
- package/src/composables/_ssrState.ts +80 -0
- package/src/composables/_storageKeys.ts +6 -0
- package/src/composables/_useThemeTokens.ts +42 -0
- package/src/composables/mapAdapters.ts +208 -0
- package/src/composables/mapSearch.ts +56 -0
- package/src/composables/themeInitScript.ts +51 -0
- package/src/composables/useColorPalette.ts +32 -14
- package/src/composables/useLocale.ts +62 -0
- package/src/composables/useMap.ts +98 -0
- package/src/composables/useMapFilter.ts +45 -0
- package/src/composables/useMapLayers.ts +124 -0
- package/src/composables/useTheme.ts +18 -7
- package/src/composables/useWindowSizeClass.ts +23 -4
- package/src/index.ts +4 -1
- package/src/locales/de.ts +31 -1
- package/src/locales/es.ts +31 -1
- package/src/locales/fr.ts +31 -1
- package/src/locales/ja.ts +31 -1
- package/src/locales/ko.ts +31 -1
- package/src/locales/pt.ts +31 -1
- package/src/locales/zh.ts +31 -1
- package/src/map.ts +32 -0
- package/src/plugin.ts +77 -13
- package/dist/MTextField-BPbFeI9M.js +0 -1368
- package/dist/MTextField-BPbFeI9M.js.map +0 -1
- package/dist/useLocale-CuvWRZ1h.js.map +0 -1
package/src/plugin.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { App, MaybeRef } from 'vue'
|
|
2
|
-
import type { Palette } from './composables/useColorPalette'
|
|
2
|
+
import type { Palette, PaletteId } from './composables/useColorPalette'
|
|
3
3
|
import { __defaultContrast, __defaultPalette, __defaultSeed, __forcePalette, palettes } from './composables/useColorPalette'
|
|
4
4
|
import type { ContrastLevel } from './composables/useColorPalette'
|
|
5
5
|
import type { SeedOptions } from './composables/dynamicColor'
|
|
@@ -7,9 +7,14 @@ import { syncThemeColor } from './composables/_themeColor'
|
|
|
7
7
|
import type { M3Locale } from './composables/useLocale'
|
|
8
8
|
import { M3_LOCALE_KEY, __setAppLocale } from './composables/useLocale'
|
|
9
9
|
import { vRipple } from './directives/vRipple'
|
|
10
|
+
import { M3_HYDRATING_KEY } from './composables/_hydration'
|
|
11
|
+
import { M3_INITIAL_STATE_KEY, enableCookies, readCookie, trackViewport, writeCookie, type M3InitialState, type ResolvedInitialState } from './composables/_ssrState'
|
|
12
|
+
import { THEME_KEY } from './composables/_storageKeys'
|
|
13
|
+
import type { Theme } from './composables/useTheme'
|
|
14
|
+
import { CONTRAST_KEY, PALETTE_KEY, SEED_PALETTE } from './composables/useColorPalette'
|
|
10
15
|
|
|
11
16
|
export interface M3UIOptions {
|
|
12
|
-
palette?: string
|
|
17
|
+
palette?: PaletteId | (string & {})
|
|
13
18
|
/**
|
|
14
19
|
* Set to `false` to make `palette` a hard default that always wins on boot, ignoring
|
|
15
20
|
* whatever is already stored in localStorage, and to stop future `useColorPalette().set()`
|
|
@@ -50,29 +55,88 @@ export interface M3UIOptions {
|
|
|
50
55
|
* mode (they keep their own dark bar); installed apps (PWA) still get it.
|
|
51
56
|
*/
|
|
52
57
|
themeColor?: 'surface' | 'surface-container' | 'primary' | (string & {})
|
|
58
|
+
/**
|
|
59
|
+
* Server-side rendering: tells the components whether the app is still hydrating the server's HTML (Nuxt's
|
|
60
|
+
* `() => nuxtApp.isHydrating`, which `@m3ui-vue/nuxt` passes). The adaptive layouts (`MNavigationSuite`,
|
|
61
|
+
* `MListDetail`, `MSupportingPane`) and `useWindowSizeClass()` then render their first frame at the server's size
|
|
62
|
+
* (compact: it has no window) so it matches the HTML, and adapt once mounted.
|
|
63
|
+
*/
|
|
64
|
+
isHydrating?: () => boolean
|
|
65
|
+
/**
|
|
66
|
+
* Also keep the theme, the palette and the contrast level in cookies (`m3-theme`, `m3-palette`, `m3-contrast`,
|
|
67
|
+
* a year, `SameSite=Lax`), and the window's size (`m3-viewport`, `<width>x<height>`), so a server can read them
|
|
68
|
+
* and render with the user's choice and for their screen through `initialState`.
|
|
69
|
+
*/
|
|
70
|
+
cookies?: boolean
|
|
71
|
+
/**
|
|
72
|
+
* Server-side rendering: the user's theme, palette and contrast as the server knows them (from the cookies that
|
|
73
|
+
* `cookies` writes), on the server and on the client alike. `useTheme()` and `useColorPalette()` report them on
|
|
74
|
+
* the server, and on the client while hydrating (with `isHydrating`), so what's rendered from them matches the
|
|
75
|
+
* server's HTML. What's missing falls back to this plugin's defaults, like a first visit. With `viewport`, the
|
|
76
|
+
* adaptive layouts (`MNavigationSuite`, `MListDetail`, `MSupportingPane`) and `useWindowSizeClass()` render for
|
|
77
|
+
* that window size instead of compact.
|
|
78
|
+
*/
|
|
79
|
+
initialState?: M3InitialState
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const THEMES: readonly Theme[] = ['light', 'dark', 'system']
|
|
83
|
+
const CONTRASTS: readonly string[] = ['standard', 'medium', 'high', 'system']
|
|
84
|
+
|
|
85
|
+
/** `initialState` with what it lacks (or holds invalid, cookies being user input) taken from the plugin's defaults,
|
|
86
|
+
* by the same rules as the client: a stored choice wins unless `persistPalette` is false. */
|
|
87
|
+
function resolveInitialState(options: M3UIOptions): ResolvedInitialState {
|
|
88
|
+
const state = options.initialState ?? {}
|
|
89
|
+
const forced = options.persistPalette === false
|
|
90
|
+
const fallbackPalette = options.palette ?? (options.seed ? SEED_PALETTE : 'purple')
|
|
91
|
+
const contrast = state.contrast && CONTRASTS.includes(state.contrast) ? state.contrast : undefined
|
|
92
|
+
const size = (n: unknown) => typeof n === 'number' && Number.isFinite(n) && n > 0 && n < 100_000
|
|
93
|
+
const viewport = state.viewport && size(state.viewport.width) && size(state.viewport.height) ? state.viewport : undefined
|
|
94
|
+
return {
|
|
95
|
+
viewport,
|
|
96
|
+
theme: state.theme && THEMES.includes(state.theme) ? state.theme : 'system',
|
|
97
|
+
palette: forced ? fallbackPalette : state.palette || fallbackPalette,
|
|
98
|
+
contrast: (forced && options.contrast) || contrast || options.contrast || 'standard',
|
|
99
|
+
}
|
|
53
100
|
}
|
|
54
101
|
|
|
55
102
|
export function createM3UI(options: M3UIOptions = {}) {
|
|
56
103
|
return {
|
|
57
104
|
install(app: App) {
|
|
58
105
|
app.directive('ripple', vRipple)
|
|
106
|
+
if (options.isHydrating) app.provide(M3_HYDRATING_KEY, options.isHydrating)
|
|
107
|
+
if (options.initialState) app.provide(M3_INITIAL_STATE_KEY, resolveInitialState(options))
|
|
108
|
+
if (options.cookies && typeof window !== 'undefined') enableCookies()
|
|
59
109
|
for (const custom of options.customPalettes ?? []) {
|
|
60
110
|
const i = palettes.findIndex((p) => p.id === custom.id)
|
|
61
111
|
if (i === -1) palettes.push(custom)
|
|
62
112
|
else palettes[i] = custom
|
|
63
113
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
114
|
+
// Palette, seed, contrast and theme-color live on the page and in localStorage: on the server (SSR) there's
|
|
115
|
+
// neither, and the client applies them when it installs the plugin
|
|
116
|
+
if (typeof window !== 'undefined') {
|
|
117
|
+
if (options.persistPalette === false) {
|
|
118
|
+
if (options.palette) __forcePalette(options.palette, false)
|
|
119
|
+
else if (options.seed) void __defaultSeed(options.seed, options.seedOptions, false)
|
|
120
|
+
} else if (!localStorage.getItem('m3-palette') && !readCookie('m3-palette')) {
|
|
121
|
+
// `palette`/`seed` are only the first-visit default — once the user picks a palette via
|
|
122
|
+
// `useColorPalette().set()` (or a seed via `setSeed()`) it's persisted to localStorage, and that choice
|
|
123
|
+
// must win on every later boot instead of being clobbered back to the plugin's static default.
|
|
124
|
+
if (options.palette && options.palette !== 'purple') __defaultPalette(options.palette)
|
|
125
|
+
else if (!options.palette && options.seed) void __defaultSeed(options.seed, options.seedOptions, true)
|
|
126
|
+
}
|
|
127
|
+
if (options.contrast) __defaultContrast(options.contrast, options.persistPalette !== false)
|
|
128
|
+
if (options.themeColor) syncThemeColor(options.themeColor)
|
|
129
|
+
// Cookies for what's already stored (a user from before `cookies`, or the defaults just applied); a cookie
|
|
130
|
+
// without a stored value (cleared storage, or set by a server) stays
|
|
131
|
+
if (options.cookies) {
|
|
132
|
+
for (const key of [THEME_KEY, PALETTE_KEY, CONTRAST_KEY]) {
|
|
133
|
+
let value: string | null = null
|
|
134
|
+
try { value = localStorage.getItem(key) } catch { /* storage blocked */ }
|
|
135
|
+
if (value != null) writeCookie(key, value)
|
|
136
|
+
}
|
|
137
|
+
trackViewport()
|
|
138
|
+
}
|
|
73
139
|
}
|
|
74
|
-
if (options.contrast) __defaultContrast(options.contrast, options.persistPalette !== false)
|
|
75
|
-
if (options.themeColor) syncThemeColor(options.themeColor)
|
|
76
140
|
if (options.locale) {
|
|
77
141
|
app.provide(M3_LOCALE_KEY, options.locale)
|
|
78
142
|
__setAppLocale(options.locale)
|