@m3ui-vue/m3ui-vue 1.0.2 → 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 +599 -9
- 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/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/_MMapLayerItem.vue.d.ts +25 -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 +4 -3
- package/dist/composables/useColorPalette.d.ts +173 -7
- 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 -1
- package/dist/index.d.ts +2 -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 +6709 -7976
- 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 +18 -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__/_fakeMaplibre.ts +158 -0
- package/src/__tests__/hydration.test.ts +33 -0
- package/src/__tests__/ssr.test.ts +63 -1
- package/src/__tests__/ssrState.test.ts +155 -0
- package/src/__tests__/themeInitScript.test.ts +18 -0
- package/src/components/MFab.vue +29 -7
- package/src/components/MIconButton.vue +1 -1
- package/src/components/MLightbox.vue +6 -2
- 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/_MMapLayerItem.vue +77 -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 +6 -4
- package/src/composables/useColorPalette.ts +23 -9
- 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 +8 -3
- package/src/composables/useWindowSizeClass.ts +14 -5
- package/src/index.ts +2 -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 +54 -3
- 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/locales/es.ts
CHANGED
|
@@ -182,5 +182,35 @@ export const esLocale: M3Locale = {
|
|
|
182
182
|
previousPage: 'Página anterior',
|
|
183
183
|
nextPage: 'Página siguiente',
|
|
184
184
|
carousel: 'Carrusel',
|
|
185
|
-
carouselItem: '{index} de {count}',
|
|
185
|
+
carouselItem: '{index} de {count}', // MMap (maplibre controls)
|
|
186
|
+
mapTitle: 'Mapa',
|
|
187
|
+
mapMarker: 'Marcador del mapa',
|
|
188
|
+
mapZoomIn: 'Acercar',
|
|
189
|
+
mapZoomOut: 'Alejar',
|
|
190
|
+
mapResetBearing: 'Restablecer orientación al norte',
|
|
191
|
+
mapFindMyLocation: 'Encontrar mi ubicación',
|
|
192
|
+
mapLocationNotAvailable: 'Ubicación no disponible',
|
|
193
|
+
mapEnterFullscreen: 'Entrar en pantalla completa',
|
|
194
|
+
mapExitFullscreen: 'Salir de pantalla completa',
|
|
195
|
+
mapToggleAttribution: 'Alternar atribución',
|
|
196
|
+
mapFeedback: 'Comentarios del mapa',
|
|
197
|
+
mapCtrlScroll: 'Usa Ctrl + rueda para hacer zoom en el mapa',
|
|
198
|
+
mapCmdScroll: 'Usa ⌘ + rueda para hacer zoom en el mapa',
|
|
199
|
+
mapTwoFingers: 'Usa dos dedos para mover el mapa',
|
|
200
|
+
mapLayers: 'Capas',
|
|
201
|
+
mapSearchLayers: 'Buscar capas',
|
|
202
|
+
mapNoLayers: 'No hay capas',
|
|
203
|
+
mapShowLayer: 'Mostrar capa',
|
|
204
|
+
mapHideLayer: 'Ocultar capa',
|
|
205
|
+
mapOpacity: 'Opacidad',
|
|
206
|
+
mapDownload: 'Descargar',
|
|
207
|
+
mapNoBaseLayer: 'Sin capa base',
|
|
208
|
+
mapHoverInfo: 'Información al pasar el cursor',
|
|
209
|
+
mapNoValue: 'No disponible',
|
|
210
|
+
mapMeasureDistance: 'Medir distancia',
|
|
211
|
+
mapMeasureArea: 'Medir área',
|
|
212
|
+
mapClearMeasurements: 'Borrar mediciones',
|
|
213
|
+
mapDeleteMeasurement: 'Borrar medición',
|
|
214
|
+
mapTotal: 'Total',
|
|
215
|
+
mapSearchPlaces: 'Buscar lugares',
|
|
186
216
|
}
|
package/src/locales/fr.ts
CHANGED
|
@@ -182,5 +182,35 @@ export const frLocale: M3Locale = {
|
|
|
182
182
|
previousPage: 'Page précédente',
|
|
183
183
|
nextPage: 'Page suivante',
|
|
184
184
|
carousel: 'Carrousel',
|
|
185
|
-
carouselItem: '{index} sur {count}',
|
|
185
|
+
carouselItem: '{index} sur {count}', // MMap (maplibre controls)
|
|
186
|
+
mapTitle: 'Carte',
|
|
187
|
+
mapMarker: 'Marqueur de carte',
|
|
188
|
+
mapZoomIn: 'Zoom avant',
|
|
189
|
+
mapZoomOut: 'Zoom arrière',
|
|
190
|
+
mapResetBearing: 'Réorienter vers le nord',
|
|
191
|
+
mapFindMyLocation: 'Trouver ma position',
|
|
192
|
+
mapLocationNotAvailable: 'Position non disponible',
|
|
193
|
+
mapEnterFullscreen: 'Passer en plein écran',
|
|
194
|
+
mapExitFullscreen: 'Quitter le plein écran',
|
|
195
|
+
mapToggleAttribution: 'Afficher ou masquer l\'attribution',
|
|
196
|
+
mapFeedback: 'Commentaires sur la carte',
|
|
197
|
+
mapCtrlScroll: 'Utilisez Ctrl + molette pour zoomer sur la carte',
|
|
198
|
+
mapCmdScroll: 'Utilisez ⌘ + molette pour zoomer sur la carte',
|
|
199
|
+
mapTwoFingers: 'Utilisez deux doigts pour déplacer la carte',
|
|
200
|
+
mapLayers: 'Calques',
|
|
201
|
+
mapSearchLayers: 'Rechercher des calques',
|
|
202
|
+
mapNoLayers: 'Aucun calque',
|
|
203
|
+
mapShowLayer: 'Afficher le calque',
|
|
204
|
+
mapHideLayer: 'Masquer le calque',
|
|
205
|
+
mapOpacity: 'Opacité',
|
|
206
|
+
mapDownload: 'Télécharger',
|
|
207
|
+
mapNoBaseLayer: 'Aucun fond de carte',
|
|
208
|
+
mapHoverInfo: 'Infos au survol',
|
|
209
|
+
mapNoValue: 'Non disponible',
|
|
210
|
+
mapMeasureDistance: 'Mesurer une distance',
|
|
211
|
+
mapMeasureArea: 'Mesurer une surface',
|
|
212
|
+
mapClearMeasurements: 'Effacer les mesures',
|
|
213
|
+
mapDeleteMeasurement: 'Supprimer la mesure',
|
|
214
|
+
mapTotal: 'Total',
|
|
215
|
+
mapSearchPlaces: 'Rechercher un lieu',
|
|
186
216
|
}
|
package/src/locales/ja.ts
CHANGED
|
@@ -182,5 +182,35 @@ export const jaLocale: M3Locale = {
|
|
|
182
182
|
previousPage: '前のページ',
|
|
183
183
|
nextPage: '次のページ',
|
|
184
184
|
carousel: 'カルーセル',
|
|
185
|
-
carouselItem: '{count} 件中 {index} 件目',
|
|
185
|
+
carouselItem: '{count} 件中 {index} 件目', // MMap (maplibre controls)
|
|
186
|
+
mapTitle: '地図',
|
|
187
|
+
mapMarker: '地図のマーカー',
|
|
188
|
+
mapZoomIn: 'ズームイン',
|
|
189
|
+
mapZoomOut: 'ズームアウト',
|
|
190
|
+
mapResetBearing: '北向きにリセット',
|
|
191
|
+
mapFindMyLocation: '現在地を表示',
|
|
192
|
+
mapLocationNotAvailable: '現在地を取得できません',
|
|
193
|
+
mapEnterFullscreen: '全画面表示',
|
|
194
|
+
mapExitFullscreen: '全画面表示を終了',
|
|
195
|
+
mapToggleAttribution: '帰属表示の切り替え',
|
|
196
|
+
mapFeedback: '地図のフィードバック',
|
|
197
|
+
mapCtrlScroll: 'Ctrl + スクロールで地図をズーム',
|
|
198
|
+
mapCmdScroll: '⌘ + スクロールで地図をズーム',
|
|
199
|
+
mapTwoFingers: '2 本の指で地図を移動',
|
|
200
|
+
mapLayers: 'レイヤー',
|
|
201
|
+
mapSearchLayers: 'レイヤーを検索',
|
|
202
|
+
mapNoLayers: 'レイヤーがありません',
|
|
203
|
+
mapShowLayer: 'レイヤーを表示',
|
|
204
|
+
mapHideLayer: 'レイヤーを非表示',
|
|
205
|
+
mapOpacity: '不透明度',
|
|
206
|
+
mapDownload: 'ダウンロード',
|
|
207
|
+
mapNoBaseLayer: 'ベースレイヤーなし',
|
|
208
|
+
mapHoverInfo: 'ホバーで情報を表示',
|
|
209
|
+
mapNoValue: '利用できません',
|
|
210
|
+
mapMeasureDistance: '距離を測定',
|
|
211
|
+
mapMeasureArea: '面積を測定',
|
|
212
|
+
mapClearMeasurements: '測定をクリア',
|
|
213
|
+
mapDeleteMeasurement: '測定を削除',
|
|
214
|
+
mapTotal: '合計',
|
|
215
|
+
mapSearchPlaces: '場所を検索',
|
|
186
216
|
}
|
package/src/locales/ko.ts
CHANGED
|
@@ -182,5 +182,35 @@ export const koLocale: M3Locale = {
|
|
|
182
182
|
previousPage: '이전 페이지',
|
|
183
183
|
nextPage: '다음 페이지',
|
|
184
184
|
carousel: '캐러셀',
|
|
185
|
-
carouselItem: '{count}개 중 {index}번째',
|
|
185
|
+
carouselItem: '{count}개 중 {index}번째', // MMap (maplibre controls)
|
|
186
|
+
mapTitle: '지도',
|
|
187
|
+
mapMarker: '지도 마커',
|
|
188
|
+
mapZoomIn: '확대',
|
|
189
|
+
mapZoomOut: '축소',
|
|
190
|
+
mapResetBearing: '북쪽으로 방향 재설정',
|
|
191
|
+
mapFindMyLocation: '내 위치 찾기',
|
|
192
|
+
mapLocationNotAvailable: '위치를 사용할 수 없음',
|
|
193
|
+
mapEnterFullscreen: '전체 화면',
|
|
194
|
+
mapExitFullscreen: '전체 화면 종료',
|
|
195
|
+
mapToggleAttribution: '출처 표시 전환',
|
|
196
|
+
mapFeedback: '지도 피드백',
|
|
197
|
+
mapCtrlScroll: 'Ctrl + 스크롤로 지도 확대/축소',
|
|
198
|
+
mapCmdScroll: '⌘ + 스크롤로 지도 확대/축소',
|
|
199
|
+
mapTwoFingers: '두 손가락으로 지도 이동',
|
|
200
|
+
mapLayers: '레이어',
|
|
201
|
+
mapSearchLayers: '레이어 검색',
|
|
202
|
+
mapNoLayers: '레이어 없음',
|
|
203
|
+
mapShowLayer: '레이어 표시',
|
|
204
|
+
mapHideLayer: '레이어 숨기기',
|
|
205
|
+
mapOpacity: '불투명도',
|
|
206
|
+
mapDownload: '다운로드',
|
|
207
|
+
mapNoBaseLayer: '기본 레이어 없음',
|
|
208
|
+
mapHoverInfo: '마우스오버 시 정보 표시',
|
|
209
|
+
mapNoValue: '사용할 수 없음',
|
|
210
|
+
mapMeasureDistance: '거리 측정',
|
|
211
|
+
mapMeasureArea: '면적 측정',
|
|
212
|
+
mapClearMeasurements: '측정 지우기',
|
|
213
|
+
mapDeleteMeasurement: '측정 삭제',
|
|
214
|
+
mapTotal: '합계',
|
|
215
|
+
mapSearchPlaces: '장소 검색',
|
|
186
216
|
}
|
package/src/locales/pt.ts
CHANGED
|
@@ -182,5 +182,35 @@ export const ptLocale: M3Locale = {
|
|
|
182
182
|
previousPage: 'Página anterior',
|
|
183
183
|
nextPage: 'Próxima página',
|
|
184
184
|
carousel: 'Carrossel',
|
|
185
|
-
carouselItem: '{index} de {count}',
|
|
185
|
+
carouselItem: '{index} de {count}', // MMap (maplibre controls)
|
|
186
|
+
mapTitle: 'Mapa',
|
|
187
|
+
mapMarker: 'Marcador do mapa',
|
|
188
|
+
mapZoomIn: 'Aproximar',
|
|
189
|
+
mapZoomOut: 'Afastar',
|
|
190
|
+
mapResetBearing: 'Redefinir orientação para o norte',
|
|
191
|
+
mapFindMyLocation: 'Encontrar minha localização',
|
|
192
|
+
mapLocationNotAvailable: 'Localização indisponível',
|
|
193
|
+
mapEnterFullscreen: 'Entrar em tela cheia',
|
|
194
|
+
mapExitFullscreen: 'Sair da tela cheia',
|
|
195
|
+
mapToggleAttribution: 'Alternar atribuição',
|
|
196
|
+
mapFeedback: 'Feedback do mapa',
|
|
197
|
+
mapCtrlScroll: 'Use Ctrl + rolagem para dar zoom no mapa',
|
|
198
|
+
mapCmdScroll: 'Use ⌘ + rolagem para dar zoom no mapa',
|
|
199
|
+
mapTwoFingers: 'Use dois dedos para mover o mapa',
|
|
200
|
+
mapLayers: 'Camadas',
|
|
201
|
+
mapSearchLayers: 'Pesquisar camadas',
|
|
202
|
+
mapNoLayers: 'Nenhuma camada',
|
|
203
|
+
mapShowLayer: 'Mostrar camada',
|
|
204
|
+
mapHideLayer: 'Ocultar camada',
|
|
205
|
+
mapOpacity: 'Opacidade',
|
|
206
|
+
mapDownload: 'Baixar',
|
|
207
|
+
mapNoBaseLayer: 'Sem camada base',
|
|
208
|
+
mapHoverInfo: 'Informações ao passar o cursor',
|
|
209
|
+
mapNoValue: 'Não disponível',
|
|
210
|
+
mapMeasureDistance: 'Medir distância',
|
|
211
|
+
mapMeasureArea: 'Medir área',
|
|
212
|
+
mapClearMeasurements: 'Apagar medições',
|
|
213
|
+
mapDeleteMeasurement: 'Apagar medição',
|
|
214
|
+
mapTotal: 'Total',
|
|
215
|
+
mapSearchPlaces: 'Pesquisar lugares',
|
|
186
216
|
}
|
package/src/locales/zh.ts
CHANGED
|
@@ -182,5 +182,35 @@ export const zhLocale: M3Locale = {
|
|
|
182
182
|
previousPage: '上一页',
|
|
183
183
|
nextPage: '下一页',
|
|
184
184
|
carousel: '轮播',
|
|
185
|
-
carouselItem: '第 {index} 项,共 {count} 项',
|
|
185
|
+
carouselItem: '第 {index} 项,共 {count} 项', // MMap (maplibre controls)
|
|
186
|
+
mapTitle: '地图',
|
|
187
|
+
mapMarker: '地图标记',
|
|
188
|
+
mapZoomIn: '放大',
|
|
189
|
+
mapZoomOut: '缩小',
|
|
190
|
+
mapResetBearing: '重置为正北方向',
|
|
191
|
+
mapFindMyLocation: '查找我的位置',
|
|
192
|
+
mapLocationNotAvailable: '位置不可用',
|
|
193
|
+
mapEnterFullscreen: '进入全屏',
|
|
194
|
+
mapExitFullscreen: '退出全屏',
|
|
195
|
+
mapToggleAttribution: '切换署名信息',
|
|
196
|
+
mapFeedback: '地图反馈',
|
|
197
|
+
mapCtrlScroll: '按住 Ctrl 并滚动以缩放地图',
|
|
198
|
+
mapCmdScroll: '按住 ⌘ 并滚动以缩放地图',
|
|
199
|
+
mapTwoFingers: '使用两根手指移动地图',
|
|
200
|
+
mapLayers: '图层',
|
|
201
|
+
mapSearchLayers: '搜索图层',
|
|
202
|
+
mapNoLayers: '没有图层',
|
|
203
|
+
mapShowLayer: '显示图层',
|
|
204
|
+
mapHideLayer: '隐藏图层',
|
|
205
|
+
mapOpacity: '不透明度',
|
|
206
|
+
mapDownload: '下载',
|
|
207
|
+
mapNoBaseLayer: '无底图',
|
|
208
|
+
mapHoverInfo: '悬停显示信息',
|
|
209
|
+
mapNoValue: '不可用',
|
|
210
|
+
mapMeasureDistance: '测量距离',
|
|
211
|
+
mapMeasureArea: '测量面积',
|
|
212
|
+
mapClearMeasurements: '清除测量',
|
|
213
|
+
mapDeleteMeasurement: '删除测量',
|
|
214
|
+
mapTotal: '总计',
|
|
215
|
+
mapSearchPlaces: '搜索地点',
|
|
186
216
|
}
|
package/src/map.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export { default as MMap } from './components/MMap.vue'
|
|
2
|
+
export type { MapControlPosition } from './components/MMap.vue'
|
|
3
|
+
export { default as MMapMarker } from './components/MMapMarker.vue'
|
|
4
|
+
export { default as MMapPopup } from './components/MMapPopup.vue'
|
|
5
|
+
export { default as MMapGeoJson } from './components/MMapGeoJson.vue'
|
|
6
|
+
export type { MapGeoJsonLayer } from './components/MMapGeoJson.vue'
|
|
7
|
+
export { default as MMapControl } from './components/MMapControl.vue'
|
|
8
|
+
export { useMap } from './composables/useMap'
|
|
9
|
+
export type { MapContext, MaplibreModule } from './composables/useMap'
|
|
10
|
+
export { default as MMapLayers } from './components/MMapLayers.vue'
|
|
11
|
+
export { default as MMapBaseLayers } from './components/MMapBaseLayers.vue'
|
|
12
|
+
export { default as MMapIdentify } from './components/MMapIdentify.vue'
|
|
13
|
+
export { default as MMapFeatureInfo } from './components/MMapFeatureInfo.vue'
|
|
14
|
+
export { default as MMapHover } from './components/MMapHover.vue'
|
|
15
|
+
export { useMapLayers } from './composables/useMapLayers'
|
|
16
|
+
export type { MapLayerState } from './composables/useMapLayers'
|
|
17
|
+
export { genericAdapter, orvianAdapter, identifyFeatures, formatFieldValue, fieldLabel } from './composables/mapAdapters'
|
|
18
|
+
export type {
|
|
19
|
+
MapAdapter,
|
|
20
|
+
MapAdapterContext,
|
|
21
|
+
MapFieldFormat,
|
|
22
|
+
MapIdentifyResult,
|
|
23
|
+
MapLayerInfo,
|
|
24
|
+
MapLayerModel,
|
|
25
|
+
OrvianAdapterOptions,
|
|
26
|
+
} from './composables/mapAdapters'
|
|
27
|
+
export { default as MMapMeasure } from './components/MMapMeasure.vue'
|
|
28
|
+
export { default as MMapFilter } from './components/MMapFilter.vue'
|
|
29
|
+
export { useMapFilter } from './composables/useMapFilter'
|
|
30
|
+
export { default as MMapSearch } from './components/MMapSearch.vue'
|
|
31
|
+
export { nominatimProvider } from './composables/mapSearch'
|
|
32
|
+
export type { MapSearchProvider, MapSearchResult, NominatimOptions } from './composables/mapSearch'
|
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'
|
|
@@ -8,9 +8,13 @@ import type { M3Locale } from './composables/useLocale'
|
|
|
8
8
|
import { M3_LOCALE_KEY, __setAppLocale } from './composables/useLocale'
|
|
9
9
|
import { vRipple } from './directives/vRipple'
|
|
10
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'
|
|
11
15
|
|
|
12
16
|
export interface M3UIOptions {
|
|
13
|
-
palette?: string
|
|
17
|
+
palette?: PaletteId | (string & {})
|
|
14
18
|
/**
|
|
15
19
|
* Set to `false` to make `palette` a hard default that always wins on boot, ignoring
|
|
16
20
|
* whatever is already stored in localStorage, and to stop future `useColorPalette().set()`
|
|
@@ -58,6 +62,41 @@ export interface M3UIOptions {
|
|
|
58
62
|
* (compact: it has no window) so it matches the HTML, and adapt once mounted.
|
|
59
63
|
*/
|
|
60
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
|
+
}
|
|
61
100
|
}
|
|
62
101
|
|
|
63
102
|
export function createM3UI(options: M3UIOptions = {}) {
|
|
@@ -65,6 +104,8 @@ export function createM3UI(options: M3UIOptions = {}) {
|
|
|
65
104
|
install(app: App) {
|
|
66
105
|
app.directive('ripple', vRipple)
|
|
67
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()
|
|
68
109
|
for (const custom of options.customPalettes ?? []) {
|
|
69
110
|
const i = palettes.findIndex((p) => p.id === custom.id)
|
|
70
111
|
if (i === -1) palettes.push(custom)
|
|
@@ -76,7 +117,7 @@ export function createM3UI(options: M3UIOptions = {}) {
|
|
|
76
117
|
if (options.persistPalette === false) {
|
|
77
118
|
if (options.palette) __forcePalette(options.palette, false)
|
|
78
119
|
else if (options.seed) void __defaultSeed(options.seed, options.seedOptions, false)
|
|
79
|
-
} else if (!localStorage.getItem('m3-palette')) {
|
|
120
|
+
} else if (!localStorage.getItem('m3-palette') && !readCookie('m3-palette')) {
|
|
80
121
|
// `palette`/`seed` are only the first-visit default — once the user picks a palette via
|
|
81
122
|
// `useColorPalette().set()` (or a seed via `setSeed()`) it's persisted to localStorage, and that choice
|
|
82
123
|
// must win on every later boot instead of being clobbered back to the plugin's static default.
|
|
@@ -85,6 +126,16 @@ export function createM3UI(options: M3UIOptions = {}) {
|
|
|
85
126
|
}
|
|
86
127
|
if (options.contrast) __defaultContrast(options.contrast, options.persistPalette !== false)
|
|
87
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
|
+
}
|
|
88
139
|
}
|
|
89
140
|
if (options.locale) {
|
|
90
141
|
app.provide(M3_LOCALE_KEY, options.locale)
|