@m3ui-vue/m3ui-vue 1.5.1 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (367) hide show
  1. package/dist/API.md +981 -63
  2. package/dist/{MButton-D_uxtJa-.js → MButton-OQ4wIERQ.js} +8 -9
  3. package/dist/MButton-OQ4wIERQ.js.map +1 -0
  4. package/dist/{MDialog-DT4KAPmn.js → MDialog-DYMnaBlt.js} +38 -44
  5. package/dist/MDialog-DYMnaBlt.js.map +1 -0
  6. package/dist/{MIcon-Bxh9j135.js → MIcon-DpajuUTJ.js} +2 -3
  7. package/dist/MIcon-DpajuUTJ.js.map +1 -0
  8. package/dist/{MIconButton-DoNotQ9v.js → MIconButton-BBggVwBV.js} +5 -6
  9. package/dist/MIconButton-BBggVwBV.js.map +1 -0
  10. package/dist/{MListItem-CwYrxpPZ.js → MListItem-D2cNUyzP.js} +217 -180
  11. package/dist/MListItem-D2cNUyzP.js.map +1 -0
  12. package/dist/{MLoadingIndicator-DhzECYRI.js → MLoadingIndicator-DWUj0BAB.js} +3 -4
  13. package/dist/MLoadingIndicator-DWUj0BAB.js.map +1 -0
  14. package/dist/{MMenuItem-Bih0h4-n.js → MMenuItem-BuxYoASE.js} +140 -170
  15. package/dist/MMenuItem-BuxYoASE.js.map +1 -0
  16. package/dist/{MProgressBar-BCoruxA-.js → MProgressBar-BWly1UKN.js} +3 -8
  17. package/dist/MProgressBar-BWly1UKN.js.map +1 -0
  18. package/dist/{MSeekBar-DQPF5FTp.js → MSeekBar-C4cn9RIF.js} +4 -5
  19. package/dist/MSeekBar-C4cn9RIF.js.map +1 -0
  20. package/dist/{MSegmentedButton-DL9JtJFX.js → MSegmentedButton-BEB4gXLA.js} +3 -4
  21. package/dist/MSegmentedButton-BEB4gXLA.js.map +1 -0
  22. package/dist/{MSlider-BvoMZTy9.js → MSlider-BIkA6DiE.js} +22 -23
  23. package/dist/MSlider-BIkA6DiE.js.map +1 -0
  24. package/dist/{MSpinner-CgcCQhS9.js → MSpinner-DZkXZJpc.js} +3 -4
  25. package/dist/MSpinner-DZkXZJpc.js.map +1 -0
  26. package/dist/{MTextField-BRntFeNR.js → MTextField-CNH-byir.js} +12 -16
  27. package/dist/MTextField-CNH-byir.js.map +1 -0
  28. package/dist/{MTooltip-YyF1CO75.js → MTooltip-Dd5g2zhh.js} +10 -12
  29. package/dist/MTooltip-Dd5g2zhh.js.map +1 -0
  30. package/dist/THIRD_PARTY_LICENSES.md +2 -2
  31. package/dist/{_plugin-vue_export-helper-B3ysoDQm.js → _plugin-vue_export-helper-Djzt4Yr7.js} +1 -2
  32. package/dist/{_useEscapeStack-CjndQhqg.js → _popupPosition-nL8SVKPK.js} +21 -4
  33. package/dist/_popupPosition-nL8SVKPK.js.map +1 -0
  34. package/dist/{_storageKeys-CYXsUBwK.js → _storageKeys-C4W_4xK4.js} +2 -3
  35. package/dist/_storageKeys-C4W_4xK4.js.map +1 -0
  36. package/dist/api.json +1 -1
  37. package/dist/barcode.js +1 -2
  38. package/dist/barcode.js.map +1 -1
  39. package/dist/chart.js +2 -4
  40. package/dist/chart.js.map +1 -1
  41. package/dist/code-editor.js +22 -23
  42. package/dist/code-editor.js.map +1 -1
  43. package/dist/{common-0dgrgaPL.js → common-kIb6A2Qu.js} +8 -37
  44. package/dist/common-kIb6A2Qu.js.map +1 -0
  45. package/dist/components/MAbsolute.vue.d.ts +5 -3
  46. package/dist/components/MAddressField.vue.d.ts +54 -0
  47. package/dist/components/MAlert.vue.d.ts +8 -6
  48. package/dist/components/MAppBar.vue.d.ts +9 -7
  49. package/dist/components/MAppBarWithSearch.vue.d.ts +15 -13
  50. package/dist/components/MAppLayout.vue.d.ts +13 -11
  51. package/dist/components/MAspectRatio.vue.d.ts +5 -3
  52. package/dist/components/MAudioPlayer.vue.d.ts +23 -21
  53. package/dist/components/MAudioRecorder.vue.d.ts +51 -0
  54. package/dist/components/MAutocomplete.vue.d.ts +1 -1
  55. package/dist/components/MAvailabilityCalendar.vue.d.ts +18 -16
  56. package/dist/components/MBadge.vue.d.ts +6 -4
  57. package/dist/components/MBar.vue.d.ts +14 -12
  58. package/dist/components/MBarcode.vue.d.ts +5 -3
  59. package/dist/components/MBeforeAfter.vue.d.ts +12 -10
  60. package/dist/components/MBodyMap.vue.d.ts +1 -1
  61. package/dist/components/MBottomAppBar.vue.d.ts +10 -8
  62. package/dist/components/MBottomSheet.vue.d.ts +8 -6
  63. package/dist/components/MBottomSheetScaffold.vue.d.ts +9 -7
  64. package/dist/components/MBox.vue.d.ts +6 -4
  65. package/dist/components/MButton.vue.d.ts +7 -5
  66. package/dist/components/MCameraCapture.vue.d.ts +51 -0
  67. package/dist/components/MCard.vue.d.ts +12 -10
  68. package/dist/components/MCenter.vue.d.ts +5 -3
  69. package/dist/components/MChatBubble.vue.d.ts +6 -4
  70. package/dist/components/MCheckbox.vue.d.ts +5 -3
  71. package/dist/components/MChip.vue.d.ts +9 -7
  72. package/dist/components/MCircleProgressBar.vue.d.ts +6 -4
  73. package/dist/components/MCodeEditor.vue.d.ts +5 -3
  74. package/dist/components/MCollapse.vue.d.ts +32 -0
  75. package/dist/components/MContainer.vue.d.ts +6 -4
  76. package/dist/components/MContextMenu.vue.d.ts +8 -6
  77. package/dist/components/MCopyButton.vue.d.ts +1 -1
  78. package/dist/components/MCountrySelect.vue.d.ts +41 -0
  79. package/dist/components/MCronField.vue.d.ts +26 -0
  80. package/dist/components/MDashboardGrid.vue.d.ts +65 -0
  81. package/dist/components/MDataTable.vue.d.ts +21 -19
  82. package/dist/components/MDialog.vue.d.ts +21 -19
  83. package/dist/components/MDiffViewer.vue.d.ts +56 -0
  84. package/dist/components/MDragHandle.vue.d.ts +1 -1
  85. package/dist/components/MDrawCanvas.vue.d.ts +5 -3
  86. package/dist/components/MDrawToolbar.vue.d.ts +7 -5
  87. package/dist/components/MEmptyState.vue.d.ts +5 -3
  88. package/dist/components/MExpansionPanel.vue.d.ts +32 -7
  89. package/dist/components/MExportButton.vue.d.ts +7 -5
  90. package/dist/components/MFab.vue.d.ts +11 -9
  91. package/dist/components/MFabMenu.vue.d.ts +3 -3
  92. package/dist/components/MFilterBuilder.vue.d.ts +22 -0
  93. package/dist/components/MFixed.vue.d.ts +5 -3
  94. package/dist/components/MFlex.vue.d.ts +7 -5
  95. package/dist/components/MFloorPlan.vue.d.ts +3 -3
  96. package/dist/components/MFloorPlanInspector.vue.d.ts +32 -30
  97. package/dist/components/MFloorPlanToolbar.vue.d.ts +2 -2
  98. package/dist/components/MFlow.vue.d.ts +4 -4
  99. package/dist/components/MFlowControls.vue.d.ts +6 -4
  100. package/dist/components/MFlowHandle.vue.d.ts +1 -1
  101. package/dist/components/MFlowNode.vue.d.ts +11 -9
  102. package/dist/components/MFooter.vue.d.ts +12 -10
  103. package/dist/components/MFullscreen.vue.d.ts +5 -3
  104. package/dist/components/MGantt.vue.d.ts +33 -31
  105. package/dist/components/MGanttControls.vue.d.ts +8 -6
  106. package/dist/components/MGrid.vue.d.ts +6 -4
  107. package/dist/components/MIcon.vue.d.ts +5 -0
  108. package/dist/components/MIconButton.vue.d.ts +1 -1
  109. package/dist/components/MImageCropper.vue.d.ts +14 -12
  110. package/dist/components/MInfiniteScroll.vue.d.ts +11 -9
  111. package/dist/components/MList.vue.d.ts +5 -3
  112. package/dist/components/MListGroup.vue.d.ts +7 -5
  113. package/dist/components/MListItem.vue.d.ts +21 -19
  114. package/dist/components/MListSubheader.vue.d.ts +5 -3
  115. package/dist/components/MLoadingOverlay.vue.d.ts +10 -8
  116. package/dist/components/MMap.vue.d.ts +14 -6
  117. package/dist/components/MMapCluster.vue.d.ts +80 -0
  118. package/dist/components/MMapControl.vue.d.ts +12 -10
  119. package/dist/components/MMapDraw.vue.d.ts +79 -0
  120. package/dist/components/MMapFeatureInfo.vue.d.ts +11 -9
  121. package/dist/components/MMapIdentify.vue.d.ts +9 -7
  122. package/dist/components/MMapLayers.vue.d.ts +13 -11
  123. package/dist/components/MMapMarker.vue.d.ts +7 -5
  124. package/dist/components/MMapPopup.vue.d.ts +5 -3
  125. package/dist/components/MMasonry.vue.d.ts +5 -3
  126. package/dist/components/MMentionField.vue.d.ts +102 -0
  127. package/dist/components/MMenu.vue.d.ts +12 -10
  128. package/dist/components/MMenuItem.vue.d.ts +11 -9
  129. package/dist/components/MMultiAutocomplete.vue.d.ts +1 -1
  130. package/dist/components/MMultiSelect.vue.d.ts +6 -4
  131. package/dist/components/MNavigationDrawer.vue.d.ts +14 -12
  132. package/dist/components/MNavigationRail.vue.d.ts +7 -5
  133. package/dist/components/MNotificationCenter.vue.d.ts +57 -0
  134. package/dist/components/MOdontogram.vue.d.ts +1 -1
  135. package/dist/components/MOrderBook.vue.d.ts +1 -1
  136. package/dist/components/MOverlay.vue.d.ts +5 -3
  137. package/dist/components/MPdfViewer.vue.d.ts +4 -4
  138. package/dist/components/MPhoneInput.vue.d.ts +11 -9
  139. package/dist/components/MPosKeypad.vue.d.ts +18 -16
  140. package/dist/components/MProgressBar.vue.d.ts +1 -1
  141. package/dist/components/MPullToRefresh.vue.d.ts +5 -3
  142. package/dist/components/MQRCode.vue.d.ts +7 -5
  143. package/dist/components/MQRScanner.vue.d.ts +52 -0
  144. package/dist/components/MQuiz.vue.d.ts +1 -1
  145. package/dist/components/MRadioGroup.vue.d.ts +1 -1
  146. package/dist/components/MReceipt.vue.d.ts +2 -2
  147. package/dist/components/MRelative.vue.d.ts +5 -3
  148. package/dist/components/MResourceTimeline.vue.d.ts +31 -29
  149. package/dist/components/MResponsive.vue.d.ts +5 -3
  150. package/dist/components/MResult.vue.d.ts +7 -5
  151. package/dist/components/MScrollable.vue.d.ts +7 -5
  152. package/dist/components/MSearchBar.vue.d.ts +13 -11
  153. package/dist/components/MSearchField.vue.d.ts +7 -5
  154. package/dist/components/MSection.vue.d.ts +11 -9
  155. package/dist/components/MSeekBar.vue.d.ts +3 -3
  156. package/dist/components/MSelect.vue.d.ts +1 -1
  157. package/dist/components/MShader.vue.d.ts +11 -9
  158. package/dist/components/MShortNavigationBar.vue.d.ts +1 -1
  159. package/dist/components/MSideSheet.vue.d.ts +9 -7
  160. package/dist/components/MSimpleCarousel.vue.d.ts +2 -2
  161. package/dist/components/MSkeleton.vue.d.ts +2 -2
  162. package/dist/components/MSlider.vue.d.ts +3 -3
  163. package/dist/components/MSparkline.vue.d.ts +1 -1
  164. package/dist/components/MSplitButton.vue.d.ts +7 -5
  165. package/dist/components/MSplitter.vue.d.ts +9 -7
  166. package/dist/components/MSpotlightSearch.vue.d.ts +1 -1
  167. package/dist/components/MStack.vue.d.ts +8 -6
  168. package/dist/components/MStatCard.vue.d.ts +5 -3
  169. package/dist/components/MStepper.vue.d.ts +5 -3
  170. package/dist/components/MSticky.vue.d.ts +5 -3
  171. package/dist/components/MSubtitle.vue.d.ts +6 -4
  172. package/dist/components/MSwipeToDismiss.vue.d.ts +11 -9
  173. package/dist/components/MTable.vue.d.ts +17 -15
  174. package/dist/components/MText.vue.d.ts +5 -3
  175. package/dist/components/MTextField.vue.d.ts +6 -4
  176. package/dist/components/MTimePickerModal.vue.d.ts +1 -1
  177. package/dist/components/MTimezoneSelect.vue.d.ts +39 -0
  178. package/dist/components/MTitle.vue.d.ts +6 -4
  179. package/dist/components/MToggleButton.vue.d.ts +5 -3
  180. package/dist/components/MToolbar.vue.d.ts +24 -22
  181. package/dist/components/MTooltip.vue.d.ts +10 -8
  182. package/dist/components/MTopAppBar.vue.d.ts +22 -20
  183. package/dist/components/MTour.vue.d.ts +28 -26
  184. package/dist/components/MTransition.vue.d.ts +5 -3
  185. package/dist/components/MTree.vue.d.ts +6 -4
  186. package/dist/components/MTreeTable.vue.d.ts +21 -19
  187. package/dist/components/MTypewriter.vue.d.ts +6 -4
  188. package/dist/components/MVideoPlayer.vue.d.ts +1 -1
  189. package/dist/components/MVirtualTable.vue.d.ts +8 -6
  190. package/dist/components/_MFilterGroup.vue.d.ts +17 -0
  191. package/dist/components/_MMapLayerItem.vue.d.ts +8 -6
  192. package/dist/components/_MPdfPage.vue.d.ts +2 -2
  193. package/dist/components/_MToolbarFab.vue.d.ts +5 -3
  194. package/dist/components/_MTreeNode.vue.d.ts +13 -11
  195. package/dist/composables/_caretPosition.d.ts +6 -0
  196. package/dist/composables/_useCamera.d.ts +16 -0
  197. package/dist/composables/_useFollowAnchor.d.ts +15 -0
  198. package/dist/composables/cron.d.ts +29 -0
  199. package/dist/composables/dashboardLayout.d.ts +28 -0
  200. package/dist/composables/filterBuilder.d.ts +55 -0
  201. package/dist/composables/mapAdapters.d.ts +6 -1
  202. package/dist/composables/mapSearch.d.ts +1 -0
  203. package/dist/composables/textDiff.d.ts +24 -0
  204. package/dist/composables/useLocale.d.ts +108 -0
  205. package/dist/composables/useMap.d.ts +8 -0
  206. package/dist/{dist-CrjSW5DN.js → dist-Bj5kEq8G.js} +4 -6
  207. package/dist/dist-Bj5kEq8G.js.map +1 -0
  208. package/dist/draw.js +62 -82
  209. package/dist/draw.js.map +1 -1
  210. package/dist/{emoji-names-de-BphO5XpV.js → emoji-names-de-Cu3OSpp6.js} +2 -3
  211. package/dist/emoji-names-de-Cu3OSpp6.js.map +1 -0
  212. package/dist/{emoji-names-en-9ZvMRvzi.js → emoji-names-en-BNX1pM9h.js} +2 -3
  213. package/dist/emoji-names-en-BNX1pM9h.js.map +1 -0
  214. package/dist/{emoji-names-es-DvfWU3Pj.js → emoji-names-es-C_Dafg4D.js} +2 -3
  215. package/dist/emoji-names-es-C_Dafg4D.js.map +1 -0
  216. package/dist/{emoji-names-fr-B-jhUlsP.js → emoji-names-fr-D4HTMFuM.js} +2 -3
  217. package/dist/emoji-names-fr-D4HTMFuM.js.map +1 -0
  218. package/dist/{emoji-names-ja-l8cMFJo1.js → emoji-names-ja-BCql-Sj6.js} +2 -3
  219. package/dist/emoji-names-ja-BCql-Sj6.js.map +1 -0
  220. package/dist/{emoji-names-ko-YP-o9G0c.js → emoji-names-ko-CT8L52nn.js} +2 -3
  221. package/dist/emoji-names-ko-CT8L52nn.js.map +1 -0
  222. package/dist/{emoji-names-pt-DGj_Js4M.js → emoji-names-pt-DHiwPiL-.js} +2 -3
  223. package/dist/emoji-names-pt-DHiwPiL-.js.map +1 -0
  224. package/dist/{emoji-names-zh-Dzecwtw_.js → emoji-names-zh-L3FXVief.js} +2 -3
  225. package/dist/emoji-names-zh-L3FXVief.js.map +1 -0
  226. package/dist/flow.js +351 -374
  227. package/dist/flow.js.map +1 -1
  228. package/dist/{flowPaths-CcWOKY4Z.js → flowPaths-BaH7yaUM.js} +3 -8
  229. package/dist/flowPaths-BaH7yaUM.js.map +1 -0
  230. package/dist/gantt.js +272 -333
  231. package/dist/gantt.js.map +1 -1
  232. package/dist/index.d.ts +25 -0
  233. package/dist/locales/index.js +750 -2
  234. package/dist/locales/index.js.map +1 -1
  235. package/dist/m3ui-vue.css +1 -1
  236. package/dist/m3ui.js +9988 -7215
  237. package/dist/m3ui.js.map +1 -1
  238. package/dist/map.d.ts +6 -1
  239. package/dist/map.js +1600 -713
  240. package/dist/map.js.map +1 -1
  241. package/dist/markdown.js +3 -4
  242. package/dist/markdown.js.map +1 -1
  243. package/dist/{material-color-utilities-C_iikgRm.js → material-color-utilities-CEFytLsr.js} +15 -32
  244. package/dist/material-color-utilities-CEFytLsr.js.map +1 -0
  245. package/dist/media.js +80 -94
  246. package/dist/media.js.map +1 -1
  247. package/dist/{motion-DZiXG09o.js → motion-BcejVTeX.js} +2 -3
  248. package/dist/motion-BcejVTeX.js.map +1 -0
  249. package/dist/pdf.js +103 -115
  250. package/dist/pdf.js.map +1 -1
  251. package/dist/qrcode.js +1 -2
  252. package/dist/qrcode.js.map +1 -1
  253. package/dist/rich-text-editor.js +33 -34
  254. package/dist/rich-text-editor.js.map +1 -1
  255. package/dist/styles.css +1 -1
  256. package/dist/terminal.js +2 -3
  257. package/dist/terminal.js.map +1 -1
  258. package/dist/{useLocale-DLcG3qPC.js → useLocale-DaVSTdm0.js} +109 -3
  259. package/dist/useLocale-DaVSTdm0.js.map +1 -0
  260. package/dist/{useThemeTokens-DQQcaWbE.js → useThemeTokens-DyAdPQB0.js} +6 -10
  261. package/dist/useThemeTokens-DyAdPQB0.js.map +1 -0
  262. package/package.json +32 -32
  263. package/src/__tests__/MAddressField.test.ts +149 -0
  264. package/src/__tests__/MAudioRecorder.test.ts +125 -0
  265. package/src/__tests__/MCameraCapture.test.ts +154 -0
  266. package/src/__tests__/MCountrySelect.test.ts +67 -0
  267. package/src/__tests__/MCronField.test.ts +100 -0
  268. package/src/__tests__/MDashboardGrid.test.ts +122 -0
  269. package/src/__tests__/MDiffViewer.test.ts +68 -0
  270. package/src/__tests__/MExpansionPanel.test.ts +107 -0
  271. package/src/__tests__/MFab.test.ts +10 -1
  272. package/src/__tests__/MFilterBuilder.test.ts +130 -0
  273. package/src/__tests__/MMap.test.ts +16 -1
  274. package/src/__tests__/MMapCluster.test.ts +127 -0
  275. package/src/__tests__/MMapDraw.test.ts +188 -0
  276. package/src/__tests__/MMapLayers.test.ts +56 -0
  277. package/src/__tests__/MMentionField.test.ts +163 -0
  278. package/src/__tests__/MNotificationCenter.test.ts +94 -0
  279. package/src/__tests__/_fakeMaplibre.ts +16 -3
  280. package/src/__tests__/attrsFallthrough.test.ts +4 -0
  281. package/src/__tests__/cron.test.ts +68 -0
  282. package/src/__tests__/dashboardLayout.test.ts +45 -0
  283. package/src/__tests__/filterBuilder.test.ts +91 -0
  284. package/src/__tests__/followAnchor.test.ts +162 -0
  285. package/src/__tests__/ssr.test.ts +3 -0
  286. package/src/__tests__/textDiff.test.ts +37 -0
  287. package/src/components/MAddressField.vue +301 -0
  288. package/src/components/MAudioRecorder.vue +334 -0
  289. package/src/components/MAutocomplete.vue +3 -7
  290. package/src/components/MCameraCapture.vue +156 -0
  291. package/src/components/MCollapse.vue +91 -0
  292. package/src/components/MColorPicker.vue +4 -8
  293. package/src/components/MCountrySelect.vue +89 -0
  294. package/src/components/MCronField.vue +251 -0
  295. package/src/components/MDashboardGrid.vue +382 -0
  296. package/src/components/MDatePicker.vue +10 -7
  297. package/src/components/MDateRangePicker.vue +10 -7
  298. package/src/components/MDiffViewer.vue +234 -0
  299. package/src/components/MExpansionPanel.vue +56 -48
  300. package/src/components/MFilterBuilder.vue +47 -0
  301. package/src/components/MMap.vue +12 -3
  302. package/src/components/MMapCluster.vue +295 -0
  303. package/src/components/MMapDraw.vue +601 -0
  304. package/src/components/MMapMeasure.vue +3 -1
  305. package/src/components/MMapSearch.vue +1 -9
  306. package/src/components/MMentionField.vue +373 -0
  307. package/src/components/MMultiAutocomplete.vue +3 -7
  308. package/src/components/MMultiSelect.vue +3 -7
  309. package/src/components/MNotificationCenter.vue +252 -0
  310. package/src/components/MPhoneInput.vue +3 -10
  311. package/src/components/MQRScanner.vue +177 -0
  312. package/src/components/MSelect.vue +3 -7
  313. package/src/components/MTimePicker.vue +10 -7
  314. package/src/components/MTimezoneSelect.vue +116 -0
  315. package/src/components/_MFilterGroup.vue +210 -0
  316. package/src/composables/_caretPosition.ts +44 -0
  317. package/src/composables/_useCamera.ts +66 -0
  318. package/src/composables/_useFollowAnchor.ts +109 -0
  319. package/src/composables/cron.ts +179 -0
  320. package/src/composables/dashboardLayout.ts +94 -0
  321. package/src/composables/filterBuilder.ts +195 -0
  322. package/src/composables/mapAdapters.ts +29 -15
  323. package/src/composables/mapSearch.ts +10 -0
  324. package/src/composables/textDiff.ts +106 -0
  325. package/src/composables/useLocale.ts +215 -0
  326. package/src/composables/useMap.ts +17 -0
  327. package/src/composables/useMapLayers.ts +4 -1
  328. package/src/index.ts +25 -0
  329. package/src/locales/de.ts +107 -0
  330. package/src/locales/es.ts +107 -0
  331. package/src/locales/fr.ts +107 -0
  332. package/src/locales/ja.ts +107 -0
  333. package/src/locales/ko.ts +107 -0
  334. package/src/locales/pt.ts +107 -0
  335. package/src/locales/zh.ts +107 -0
  336. package/src/map.ts +6 -1
  337. package/dist/MButton-D_uxtJa-.js.map +0 -1
  338. package/dist/MDialog-DT4KAPmn.js.map +0 -1
  339. package/dist/MIcon-Bxh9j135.js.map +0 -1
  340. package/dist/MIconButton-DoNotQ9v.js.map +0 -1
  341. package/dist/MListItem-CwYrxpPZ.js.map +0 -1
  342. package/dist/MLoadingIndicator-DhzECYRI.js.map +0 -1
  343. package/dist/MMenuItem-Bih0h4-n.js.map +0 -1
  344. package/dist/MProgressBar-BCoruxA-.js.map +0 -1
  345. package/dist/MSeekBar-DQPF5FTp.js.map +0 -1
  346. package/dist/MSegmentedButton-DL9JtJFX.js.map +0 -1
  347. package/dist/MSlider-BvoMZTy9.js.map +0 -1
  348. package/dist/MSpinner-CgcCQhS9.js.map +0 -1
  349. package/dist/MTextField-BRntFeNR.js.map +0 -1
  350. package/dist/MTooltip-YyF1CO75.js.map +0 -1
  351. package/dist/_storageKeys-CYXsUBwK.js.map +0 -1
  352. package/dist/_useEscapeStack-CjndQhqg.js.map +0 -1
  353. package/dist/common-0dgrgaPL.js.map +0 -1
  354. package/dist/dist-CrjSW5DN.js.map +0 -1
  355. package/dist/emoji-names-de-BphO5XpV.js.map +0 -1
  356. package/dist/emoji-names-en-9ZvMRvzi.js.map +0 -1
  357. package/dist/emoji-names-es-DvfWU3Pj.js.map +0 -1
  358. package/dist/emoji-names-fr-B-jhUlsP.js.map +0 -1
  359. package/dist/emoji-names-ja-l8cMFJo1.js.map +0 -1
  360. package/dist/emoji-names-ko-YP-o9G0c.js.map +0 -1
  361. package/dist/emoji-names-pt-DGj_Js4M.js.map +0 -1
  362. package/dist/emoji-names-zh-Dzecwtw_.js.map +0 -1
  363. package/dist/flowPaths-CcWOKY4Z.js.map +0 -1
  364. package/dist/material-color-utilities-C_iikgRm.js.map +0 -1
  365. package/dist/motion-DZiXG09o.js.map +0 -1
  366. package/dist/useLocale-DLcG3qPC.js.map +0 -1
  367. package/dist/useThemeTokens-DQQcaWbE.js.map +0 -1
@@ -0,0 +1,601 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Drawing and editing points, lines and polygons on an `MMap`, as GeoJSON (v-model: a FeatureCollection), with its
4
+ * own control (point, line, polygon, delete). To draw: click to add points (a preview follows the pointer), then
5
+ * double-click, Enter or Escape to finish, or click the first point to close a polygon; Backspace takes back the last
6
+ * point. A point is placed with one click. To edit: click a shape to select it, then drag a vertex, drag a midpoint to
7
+ * add one, double-click a vertex to remove it, or press Delete (or the control's button) to delete the shape. Escape
8
+ * or a click on empty map deselects. Everything follows the theme. While drawing or dragging it owns the map's clicks
9
+ * (`MMapIdentify` waits). Features keep their `properties`; ones without an `id` get one. Multi-geometries are shown
10
+ * and can be selected and deleted, not reshaped. Available from the `/map` entry point.
11
+ *
12
+ * @event update:modelValue The shapes changed (drawn, edited, deleted): the whole FeatureCollection
13
+ * @event update:mode The drawing mode changed (`'point'`, `'line'`, `'polygon'`, or null when it finished)
14
+ * @event select A shape was selected (its feature), or the selection was cleared (null)
15
+ */
16
+ import { computed, onBeforeUnmount, ref, useId, watch } from 'vue'
17
+ import type * as Maplibre from 'maplibre-gl'
18
+ import MIcon from './MIcon.vue'
19
+ import MMapControl from './MMapControl.vue'
20
+ import { useLocale } from '../composables/useLocale'
21
+ import { useMap } from '../composables/useMap'
22
+ import { useThemeTokens } from '../composables/useThemeTokens'
23
+ import { useEscapeStack } from '../composables/_useEscapeStack'
24
+ import { midpoint, type LngLat } from '../composables/_mapGeometry'
25
+ import type { MapControlPosition } from './MMap.vue'
26
+
27
+ /** What `MMapDraw` draws. */
28
+ export type MapDrawMode = 'point' | 'line' | 'polygon'
29
+
30
+ type Geometry =
31
+ | { type: 'Point'; coordinates: LngLat }
32
+ | { type: 'LineString'; coordinates: LngLat[] }
33
+ | { type: 'Polygon'; coordinates: LngLat[][] }
34
+ | { type: 'MultiPoint' | 'MultiLineString' | 'MultiPolygon' | 'GeometryCollection'; [key: string]: unknown }
35
+
36
+ /** A shape of `MMapDraw` (a GeoJSON feature). */
37
+ export interface MapDrawFeature {
38
+ type: 'Feature'
39
+ id?: string | number
40
+ geometry: Geometry
41
+ properties: Record<string, unknown> | null
42
+ }
43
+
44
+ /** `MMapDraw`'s v-model. */
45
+ export interface MapDrawCollection {
46
+ type: 'FeatureCollection'
47
+ features: MapDrawFeature[]
48
+ }
49
+
50
+ const props = withDefaults(
51
+ defineProps<{
52
+ /** The shapes (v-model) */
53
+ modelValue?: MapDrawCollection
54
+ /** The drawing mode (v-model:mode): `'point'`, `'line'`, `'polygon'`, or null. Set it to start drawing from outside */
55
+ mode?: MapDrawMode | null
56
+ /** Which shapes its control offers, in order */
57
+ modes?: MapDrawMode[]
58
+ /** Its buttons: `false` (drive it with v-model:mode), or a corner (`true` is top-right) */
59
+ control?: boolean | MapControlPosition
60
+ /** The theme color of the shapes */
61
+ color?: 'primary' | 'secondary' | 'tertiary'
62
+ /** Let the user select, reshape and delete shapes (false: draw only) */
63
+ editable?: boolean
64
+ }>(),
65
+ { mode: null, modes: () => ['point', 'line', 'polygon'], control: true, color: 'primary', editable: true },
66
+ )
67
+
68
+ const emit = defineEmits<{
69
+ 'update:modelValue': [collection: MapDrawCollection]
70
+ 'update:mode': [mode: MapDrawMode | null]
71
+ select: [feature: MapDrawFeature | null]
72
+ }>()
73
+
74
+ const t = useLocale()
75
+ const { onReady, styleVersion, activeTool } = useMap()
76
+ const theme = useThemeTokens(['primary', 'secondary', 'tertiary', 'surface'] as const)
77
+
78
+ const uid = `m3-draw-${useId()}`
79
+ const SRC = { shapes: `${uid}-shapes`, draft: `${uid}-draft`, handles: `${uid}-handles` }
80
+ const SHAPE_LAYERS = [`${SRC.shapes}-fill`, `${SRC.shapes}-line`, `${SRC.shapes}-point`]
81
+ const VERTEX = `${SRC.handles}-vertex`
82
+ const MIDPOINT = `${SRC.handles}-midpoint`
83
+ const TOOL = 'draw'
84
+ /** How far from a shape a click still selects it, in pixels */
85
+ const HIT = 6
86
+
87
+ // Plain state, stepped on every pointer move: only the mode and the selection are reactive
88
+ let features: MapDrawFeature[] = []
89
+ let lastEmitted = ''
90
+ let nextId = 1
91
+ let draft: LngLat[] = []
92
+ let cursor: LngLat | null = null
93
+ let drag: { id: string | number; v: number; moved: boolean } | null = null
94
+ let raf = 0
95
+ let map: Maplibre.Map | undefined
96
+
97
+ const mode = ref<MapDrawMode | null>(null)
98
+ const selected = ref<string | number | null>(null)
99
+
100
+ const clone = <T,>(v: T): T => JSON.parse(JSON.stringify(v)) as T
101
+ const byId = (id: string | number | null) => (id === null ? undefined : features.find((f) => f.id === id))
102
+
103
+ /** Takes the v-model in, giving an id to features without one. */
104
+ function load(collection: MapDrawCollection | undefined) {
105
+ features = clone(collection?.features ?? [])
106
+ for (const f of features) {
107
+ if (f.id === undefined || f.id === null) f.id = nextFeatureId()
108
+ }
109
+ if (selected.value !== null && !byId(selected.value)) selected.value = null
110
+ }
111
+
112
+ function commit() {
113
+ const collection: MapDrawCollection = { type: 'FeatureCollection', features: clone(features) }
114
+ lastEmitted = JSON.stringify(collection.features)
115
+ emit('update:modelValue', collection)
116
+ }
117
+
118
+ // ── Geometry access ────────────────────────────────────────────────────────────────────────────
119
+
120
+ /** The editable vertices of a shape (a polygon's outer ring without its closing point), or null. */
121
+ function verticesOf(f: MapDrawFeature): LngLat[] | null {
122
+ const g = f.geometry
123
+ if (g.type === 'Point') return [g.coordinates as LngLat]
124
+ if (g.type === 'LineString') return g.coordinates as LngLat[]
125
+ if (g.type === 'Polygon') return ((g.coordinates as LngLat[][])[0] ?? []).slice(0, -1)
126
+ return null
127
+ }
128
+
129
+ function setVertices(f: MapDrawFeature, vertices: LngLat[]) {
130
+ const g = f.geometry
131
+ if (g.type === 'Point') g.coordinates = vertices[0]!
132
+ else if (g.type === 'LineString') g.coordinates = vertices
133
+ else if (g.type === 'Polygon') {
134
+ const rings = g.coordinates as LngLat[][]
135
+ rings[0] = [...vertices, [...vertices[0]!] as LngLat]
136
+ }
137
+ }
138
+
139
+ const minVertices = (f: MapDrawFeature) => (f.geometry.type === 'Polygon' ? 3 : f.geometry.type === 'LineString' ? 2 : 1)
140
+
141
+ // ── Rendering ──────────────────────────────────────────────────────────────────────────────────
142
+
143
+ type Shape = { type: 'Feature'; geometry: unknown; properties: Record<string, unknown> }
144
+ const point = (p: LngLat, properties: Record<string, unknown> = {}): Shape => ({ type: 'Feature', geometry: { type: 'Point', coordinates: p }, properties })
145
+ const collection = (list: Shape[]) => ({ type: 'FeatureCollection' as const, features: list })
146
+ const setData = (source: string, list: Shape[]) => (map?.getSource(source) as Maplibre.GeoJSONSource | undefined)?.setData(collection(list) as never)
147
+
148
+ function render() {
149
+ if (!map) return
150
+ setData(SRC.shapes, features.map((f) => ({
151
+ type: 'Feature',
152
+ geometry: f.geometry,
153
+ // Internal keys for the layers: which shape it is, and whether it's the selected one
154
+ properties: { ...f.properties, __draw_id: String(f.id), __draw_selected: f.id === selected.value },
155
+ })))
156
+
157
+ const preview: Shape[] = []
158
+ if (mode.value && mode.value !== 'point' && draft.length) {
159
+ const path = cursor ? [...draft, cursor] : draft
160
+ draft.forEach((p) => preview.push(point(p)))
161
+ if (path.length >= 2) preview.push({ type: 'Feature', geometry: { type: 'LineString', coordinates: mode.value === 'polygon' && path.length >= 3 ? [...path, path[0]] : path }, properties: {} })
162
+ if (mode.value === 'polygon' && path.length >= 3) preview.push({ type: 'Feature', geometry: { type: 'Polygon', coordinates: [[...path, path[0]]] }, properties: {} })
163
+ }
164
+ setData(SRC.draft, preview)
165
+
166
+ const handles: Shape[] = []
167
+ const f = byId(selected.value)
168
+ const vertices = f && !mode.value && props.editable ? verticesOf(f) : null
169
+ if (f && vertices) {
170
+ vertices.forEach((p, v) => handles.push(point(p, { handle: 'vertex', v })))
171
+ if (f.geometry.type !== 'Point') {
172
+ const path = f.geometry.type === 'Polygon' ? [...vertices, vertices[0]!] : vertices
173
+ for (let i = 0; i < path.length - 1; i++) handles.push(point(midpoint(path[i]!, path[i + 1]!), { handle: 'midpoint', after: i }))
174
+ }
175
+ }
176
+ setData(SRC.handles, handles)
177
+ }
178
+
179
+ function scheduleRender() {
180
+ if (raf) return
181
+ raf = requestAnimationFrame(() => {
182
+ raf = 0
183
+ render()
184
+ })
185
+ }
186
+
187
+ // ── Layers ─────────────────────────────────────────────────────────────────────────────────────
188
+
189
+ const is = (...types: string[]): Maplibre.FilterSpecification => ['match', ['geometry-type'], types, true, false]
190
+ const SEL: Maplibre.ExpressionSpecification = ['==', ['get', '__draw_selected'], true]
191
+
192
+ function paints() {
193
+ const color = theme.value[props.color]
194
+ const surface = theme.value.surface
195
+ return {
196
+ fill: { 'fill-color': color, 'fill-opacity': ['case', SEL, 0.3, 0.18] },
197
+ line: { 'line-color': color, 'line-width': ['case', SEL, 4, 2.5] },
198
+ point: { 'circle-color': color, 'circle-radius': ['case', SEL, 8, 6], 'circle-stroke-color': surface, 'circle-stroke-width': 2 },
199
+ draftFill: { 'fill-color': color, 'fill-opacity': 0.12 },
200
+ draftLine: { 'line-color': color },
201
+ handle: { 'circle-color': surface, 'circle-stroke-color': color },
202
+ }
203
+ }
204
+
205
+ function ensureLayers() {
206
+ if (!map) return
207
+ for (const source of Object.values(SRC)) {
208
+ if (!map.getSource(source)) map.addSource(source, { type: 'geojson', data: collection([]) as never })
209
+ }
210
+ const p = paints()
211
+ const add = (layer: Record<string, unknown>) => { if (!map!.getLayer(layer.id as string)) map!.addLayer(layer as Maplibre.LayerSpecification) }
212
+ add({ id: SHAPE_LAYERS[0], type: 'fill', source: SRC.shapes, filter: is('Polygon', 'MultiPolygon'), paint: p.fill })
213
+ add({ id: SHAPE_LAYERS[1], type: 'line', source: SRC.shapes, filter: is('LineString', 'MultiLineString', 'Polygon', 'MultiPolygon'), paint: p.line })
214
+ add({ id: SHAPE_LAYERS[2], type: 'circle', source: SRC.shapes, filter: is('Point', 'MultiPoint'), paint: p.point })
215
+ add({ id: `${SRC.draft}-fill`, type: 'fill', source: SRC.draft, filter: is('Polygon'), paint: p.draftFill })
216
+ add({ id: `${SRC.draft}-line`, type: 'line', source: SRC.draft, filter: is('LineString'), paint: { ...p.draftLine, 'line-width': 2.5, 'line-dasharray': [2, 2] } })
217
+ add({ id: `${SRC.draft}-point`, type: 'circle', source: SRC.draft, filter: is('Point'), paint: { ...p.handle, 'circle-radius': 5, 'circle-stroke-width': 2 } })
218
+ add({ id: MIDPOINT, type: 'circle', source: SRC.handles, filter: ['==', ['get', 'handle'], 'midpoint'], paint: { ...p.handle, 'circle-radius': 4, 'circle-stroke-width': 1.5, 'circle-opacity': 0.7 } })
219
+ add({ id: VERTEX, type: 'circle', source: SRC.handles, filter: ['==', ['get', 'handle'], 'vertex'], paint: { ...p.handle, 'circle-radius': 7, 'circle-stroke-width': 2.5 } })
220
+ }
221
+
222
+ type SetPaint = Parameters<Maplibre.Map['setPaintProperty']>
223
+ watch([theme, () => props.color], () => {
224
+ if (!map) return
225
+ const p = paints()
226
+ const set = (layer: string, paint: Record<string, unknown>) => {
227
+ if (map!.getLayer(layer)) for (const [k, v] of Object.entries(paint)) map!.setPaintProperty(layer, k as SetPaint[1], v as SetPaint[2])
228
+ }
229
+ set(SHAPE_LAYERS[0]!, p.fill)
230
+ set(SHAPE_LAYERS[1]!, p.line)
231
+ set(SHAPE_LAYERS[2]!, p.point)
232
+ set(`${SRC.draft}-fill`, p.draftFill)
233
+ set(`${SRC.draft}-line`, p.draftLine)
234
+ set(`${SRC.draft}-point`, p.handle)
235
+ set(MIDPOINT, p.handle)
236
+ set(VERTEX, p.handle)
237
+ })
238
+
239
+ // ── Selecting ──────────────────────────────────────────────────────────────────────────────────
240
+
241
+ function select(id: string | number | null) {
242
+ if (id !== null && !byId(id)) id = null
243
+ if (selected.value === id) return
244
+ selected.value = id
245
+ render()
246
+ const f = byId(id)
247
+ emit('select', f ? clone(f) : null)
248
+ }
249
+
250
+ /** Deletes a shape (the selected one by default). */
251
+ function remove(id: string | number | null = selected.value) {
252
+ const i = features.findIndex((f) => f.id === id)
253
+ if (i < 0) return
254
+ features.splice(i, 1)
255
+ if (selected.value === id) {
256
+ selected.value = null
257
+ emit('select', null)
258
+ }
259
+ render()
260
+ commit()
261
+ }
262
+
263
+ /** Deletes every shape. */
264
+ function clear() {
265
+ if (mode.value) finish()
266
+ if (!features.length) return
267
+ features = []
268
+ if (selected.value !== null) {
269
+ selected.value = null
270
+ emit('select', null)
271
+ }
272
+ render()
273
+ commit()
274
+ }
275
+
276
+ type LayerEvent = (Maplibre.MapMouseEvent | Maplibre.MapTouchEvent) & { features?: Maplibre.MapGeoJSONFeature[] }
277
+
278
+ const lngLatOf = (e: { lngLat: { lng: number; lat: number } }): LngLat => [e.lngLat.lng, e.lngLat.lat]
279
+
280
+ /** A click on the map while not drawing: selects the shape under it, or clears the selection. */
281
+ function onMapClick(e: Maplibre.MapMouseEvent) {
282
+ if (mode.value || !map || !props.editable) return
283
+ if (activeTool.value && activeTool.value !== TOOL) return
284
+ // A few pixels around the click, or a thin line is almost impossible to hit
285
+ const { x, y } = e.point
286
+ const box: [Maplibre.PointLike, Maplibre.PointLike] = [[x - HIT, y - HIT], [x + HIT, y + HIT]]
287
+ const hit = map.queryRenderedFeatures(box, { layers: SHAPE_LAYERS.filter((l) => map!.getLayer(l)) })[0]
288
+ const id = hit?.properties?.__draw_id as string | undefined
289
+ if (id === undefined) return select(null)
290
+ const f = features.find((x) => String(x.id) === id)
291
+ select(f ? f.id! : null)
292
+ }
293
+
294
+ // Pressing a shape takes the click from MMapIdentify (it reads activeTool on click)
295
+ function onShapeDown() {
296
+ if (mode.value || !props.editable || activeTool.value) return
297
+ activeTool.value = TOOL
298
+ setTimeout(() => { if (activeTool.value === TOOL && !mode.value && !drag) activeTool.value = null }, 0)
299
+ }
300
+ const onShapeEnter = () => { if (map && !mode.value && !drag && props.editable) map.getCanvas().style.cursor = 'pointer' }
301
+ const onShapeLeave = () => { if (map && !mode.value && !drag) map.getCanvas().style.cursor = '' }
302
+
303
+ // ── Drawing ────────────────────────────────────────────────────────────────────────────────────
304
+
305
+ function onDrawClick(e: Maplibre.MapMouseEvent) {
306
+ if (!mode.value || !map) return
307
+ if (mode.value === 'point') {
308
+ add({ type: 'Point', coordinates: lngLatOf(e) })
309
+ finish()
310
+ return
311
+ }
312
+ if (mode.value === 'polygon' && draft.length >= 3) {
313
+ const first = map.project(draft[0]!)
314
+ if (Math.hypot(first.x - e.point.x, first.y - e.point.y) < 20) return finish()
315
+ }
316
+ draft.push(lngLatOf(e))
317
+ render()
318
+ }
319
+
320
+ function onDrawMove(e: Maplibre.MapMouseEvent) {
321
+ cursor = lngLatOf(e)
322
+ scheduleRender()
323
+ }
324
+
325
+ function onDrawDblClick(e: Maplibre.MapMouseEvent) {
326
+ e.preventDefault()
327
+ if (!map || draft.length < 2) return
328
+ // The double click's first click added a point on top of the last one
329
+ const a = map.project(draft[draft.length - 1]!)
330
+ const b = map.project(draft[draft.length - 2]!)
331
+ if (Math.hypot(a.x - b.x, a.y - b.y) < 10) draft.pop()
332
+ finish()
333
+ }
334
+
335
+ /** Keys are ours only with the focus on the map (or nowhere in particular), never in a field or another control. */
336
+ function keysAreOurs() {
337
+ const active = document.activeElement
338
+ if (!active || active === document.body) return true
339
+ if (!map?.getContainer().contains(active)) return false
340
+ return !(active instanceof HTMLElement && (active.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(active.tagName)))
341
+ }
342
+
343
+ function onKey(e: KeyboardEvent) {
344
+ if (!keysAreOurs()) return
345
+ if (mode.value) {
346
+ if (e.key === 'Enter') {
347
+ // Kept from a focused control button too, which would start drawing again
348
+ e.preventDefault()
349
+ finish()
350
+ } else if (e.key === 'Backspace' && draft.length) {
351
+ e.preventDefault()
352
+ draft.pop()
353
+ render()
354
+ }
355
+ return
356
+ }
357
+ if ((e.key === 'Delete' || e.key === 'Backspace') && selected.value !== null && props.editable) {
358
+ e.preventDefault()
359
+ remove()
360
+ }
361
+ }
362
+ // Escape finishes a drawing, else clears the selection; through the library's stack, so a map in a dialog stays open
363
+ useEscapeStack(() => !!mode.value || selected.value !== null, () => (mode.value ? finish() : select(null)))
364
+
365
+ /** A new id no shape has yet. */
366
+ function nextFeatureId() {
367
+ let id = `shape-${nextId++}`
368
+ while (features.some((f) => f.id === id)) id = `shape-${nextId++}`
369
+ return id
370
+ }
371
+ function add(geometry: Geometry) {
372
+ const f: MapDrawFeature = { type: 'Feature', id: nextFeatureId(), geometry, properties: {} }
373
+ features.push(f)
374
+ selected.value = props.editable ? f.id! : null
375
+ commit()
376
+ if (props.editable) emit('select', clone(f))
377
+ }
378
+
379
+ function start(next: MapDrawMode) {
380
+ if (!map) return
381
+ if (mode.value === next) return finish()
382
+ if (mode.value) finish()
383
+ if (selected.value !== null) select(null)
384
+ mode.value = next
385
+ activeTool.value = TOOL
386
+ draft = []
387
+ cursor = null
388
+ map.getCanvas().style.cursor = 'crosshair'
389
+ map.doubleClickZoom.disable()
390
+ map.on('click', onDrawClick)
391
+ map.on('mousemove', onDrawMove)
392
+ map.on('dblclick', onDrawDblClick)
393
+ render()
394
+ if (props.mode !== next) emit('update:mode', next)
395
+ }
396
+
397
+ /** Ends drawing, keeping the shape when it has enough points. */
398
+ function finish() {
399
+ if (!map || !mode.value) return
400
+ cancelAnimationFrame(raf)
401
+ raf = 0
402
+ const drawn = mode.value
403
+ const points = draft
404
+ draft = []
405
+ cursor = null
406
+ mode.value = null
407
+ if (activeTool.value === TOOL) activeTool.value = null
408
+ map.getCanvas().style.cursor = ''
409
+ map.doubleClickZoom.enable()
410
+ map.off('click', onDrawClick)
411
+ map.off('mousemove', onDrawMove)
412
+ map.off('dblclick', onDrawDblClick)
413
+ if (drawn === 'line' && points.length >= 2) add({ type: 'LineString', coordinates: points })
414
+ else if (drawn === 'polygon' && points.length >= 3) add({ type: 'Polygon', coordinates: [[...points, [...points[0]!] as LngLat]] })
415
+ render()
416
+ if (props.mode !== null) emit('update:mode', null)
417
+ }
418
+
419
+ // ── Editing ────────────────────────────────────────────────────────────────────────────────────
420
+
421
+ function onHandleDown(e: LayerEvent) {
422
+ const h = e.features?.[0]
423
+ const f = byId(selected.value)
424
+ if (!h || !f || mode.value || !map || !props.editable) return
425
+ const vertices = verticesOf(f)
426
+ if (!vertices) return
427
+ e.preventDefault()
428
+ let v = h.properties.v as number
429
+ if (h.properties.handle === 'midpoint') {
430
+ v = (h.properties.after as number) + 1
431
+ vertices.splice(v, 0, lngLatOf(e))
432
+ setVertices(f, vertices)
433
+ }
434
+ drag = { id: f.id!, v, moved: h.properties.handle === 'midpoint' }
435
+ activeTool.value = TOOL
436
+ map.getCanvas().style.cursor = 'grabbing'
437
+ const touch = e.type === 'touchstart'
438
+ if (touch) map.dragPan.disable()
439
+ map.on(touch ? 'touchmove' : 'mousemove', onDragMove)
440
+ map.once(touch ? 'touchend' : 'mouseup', onDragEnd)
441
+ render()
442
+ }
443
+
444
+ function onDragMove(e: Maplibre.MapMouseEvent | Maplibre.MapTouchEvent) {
445
+ const f = drag && byId(drag.id)
446
+ const vertices = f && verticesOf(f)
447
+ if (!drag || !f || !vertices) return
448
+ vertices[drag.v] = lngLatOf(e)
449
+ setVertices(f, vertices)
450
+ drag.moved = true
451
+ scheduleRender()
452
+ }
453
+
454
+ function onDragEnd() {
455
+ if (!map) return
456
+ const moved = drag?.moved
457
+ drag = null
458
+ map.off('mousemove', onDragMove)
459
+ map.off('touchmove', onDragMove)
460
+ map.dragPan.enable()
461
+ map.getCanvas().style.cursor = ''
462
+ render()
463
+ if (moved) commit()
464
+ // The click that ends a press comes after mouseup: keep it from MMapIdentify and from deselecting
465
+ setTimeout(() => { if (activeTool.value === TOOL && !mode.value) activeTool.value = null })
466
+ }
467
+
468
+ function onVertexDblClick(e: LayerEvent) {
469
+ const h = e.features?.[0]
470
+ const f = byId(selected.value)
471
+ if (!h || !f || mode.value || !props.editable) return
472
+ e.preventDefault()
473
+ const vertices = verticesOf(f)
474
+ if (!vertices || vertices.length <= minVertices(f)) return
475
+ vertices.splice(h.properties.v as number, 1)
476
+ setVertices(f, vertices)
477
+ render()
478
+ commit()
479
+ }
480
+
481
+ const onHandleEnter = () => { if (map && !drag && !mode.value) map.getCanvas().style.cursor = 'grab' }
482
+ const onHandleLeave = () => { if (map && !drag && !mode.value) map.getCanvas().style.cursor = '' }
483
+
484
+ // ── Wiring ─────────────────────────────────────────────────────────────────────────────────────
485
+
486
+ load(props.modelValue)
487
+ lastEmitted = JSON.stringify(features)
488
+
489
+ onReady((m) => {
490
+ map = m
491
+ ensureLayers()
492
+ render()
493
+ m.on('click', onMapClick)
494
+ for (const layer of SHAPE_LAYERS) {
495
+ m.on('mousedown', layer, onShapeDown)
496
+ m.on('touchstart', layer, onShapeDown)
497
+ m.on('mouseenter', layer, onShapeEnter)
498
+ m.on('mouseleave', layer, onShapeLeave)
499
+ }
500
+ for (const layer of [VERTEX, MIDPOINT]) {
501
+ m.on('mousedown', layer, onHandleDown)
502
+ m.on('touchstart', layer, onHandleDown)
503
+ m.on('mouseenter', layer, onHandleEnter)
504
+ m.on('mouseleave', layer, onHandleLeave)
505
+ }
506
+ m.on('dblclick', VERTEX, onVertexDblClick)
507
+ document.addEventListener('keydown', onKey)
508
+ if (props.mode) start(props.mode)
509
+ })
510
+
511
+ watch(styleVersion, () => {
512
+ ensureLayers()
513
+ render()
514
+ })
515
+ // Only a change from outside reloads (our own emits come back as the same shapes)
516
+ watch(() => props.modelValue, (next) => {
517
+ if (JSON.stringify(next?.features ?? []) === lastEmitted) return
518
+ load(next)
519
+ lastEmitted = JSON.stringify(features)
520
+ render()
521
+ }, { deep: true })
522
+ watch(() => props.mode, (next) => {
523
+ if (next && next !== mode.value) start(next)
524
+ else if (!next && mode.value) finish()
525
+ })
526
+ watch(() => props.editable, (editable) => {
527
+ if (!editable && selected.value !== null) select(null)
528
+ })
529
+
530
+ onBeforeUnmount(() => {
531
+ document.removeEventListener('keydown', onKey)
532
+ if (!map) return
533
+ if (mode.value) finish()
534
+ cancelAnimationFrame(raf)
535
+ map.off('click', onMapClick)
536
+ for (const layer of SHAPE_LAYERS) {
537
+ map.off('mousedown', layer, onShapeDown)
538
+ map.off('touchstart', layer, onShapeDown)
539
+ map.off('mouseenter', layer, onShapeEnter)
540
+ map.off('mouseleave', layer, onShapeLeave)
541
+ }
542
+ for (const layer of [VERTEX, MIDPOINT]) {
543
+ map.off('mousedown', layer, onHandleDown)
544
+ map.off('touchstart', layer, onHandleDown)
545
+ map.off('mouseenter', layer, onHandleEnter)
546
+ map.off('mouseleave', layer, onHandleLeave)
547
+ }
548
+ map.off('dblclick', VERTEX, onVertexDblClick)
549
+ const layers = [VERTEX, MIDPOINT, `${SRC.draft}-point`, `${SRC.draft}-line`, `${SRC.draft}-fill`, ...[...SHAPE_LAYERS].reverse()]
550
+ for (const layer of layers) if (map.getLayer(layer)) map.removeLayer(layer)
551
+ for (const source of Object.values(SRC)) if (map.getSource(source)) map.removeSource(source)
552
+ map = undefined
553
+ })
554
+
555
+ const corner = computed(() => (props.control === true ? 'top-right' : props.control || 'top-right'))
556
+ const ICONS: Record<MapDrawMode, string> = { point: 'location_on', line: 'polyline', polygon: 'pentagon' }
557
+ const titles = computed<Record<MapDrawMode, string>>(() => ({ point: t.mapDrawPoint, line: t.mapDrawLine, polygon: t.mapDrawPolygon }))
558
+
559
+ defineExpose({
560
+ /** Starts drawing a shape (again: finishes) */
561
+ start,
562
+ /** Ends drawing, keeping the shape when it has enough points */
563
+ finish,
564
+ /** Selects a shape by id (null: none) */
565
+ select,
566
+ /** Deletes a shape (the selected one by default) */
567
+ remove,
568
+ /** Deletes every shape */
569
+ clear,
570
+ })
571
+ </script>
572
+
573
+ <template>
574
+ <div class="hidden">
575
+ <MMapControl v-if="control" :position="corner">
576
+ <button
577
+ v-for="m in modes"
578
+ :key="m"
579
+ type="button"
580
+ class="grid place-items-center"
581
+ :title="titles[m]"
582
+ :aria-label="titles[m]"
583
+ :aria-pressed="mode === m"
584
+ @click="start(m)"
585
+ >
586
+ <MIcon :name="ICONS[m]" :size="20" />
587
+ </button>
588
+ <button
589
+ v-if="editable"
590
+ type="button"
591
+ class="grid place-items-center"
592
+ :title="t.mapDeleteFeature"
593
+ :aria-label="t.mapDeleteFeature"
594
+ :disabled="selected === null"
595
+ @click="remove()"
596
+ >
597
+ <MIcon name="delete" :size="20" />
598
+ </button>
599
+ </MMapControl>
600
+ </div>
601
+ </template>
@@ -166,11 +166,13 @@ function ensureLayers() {
166
166
  add({ id: VERTEX, type: 'circle', source: SRC.handles, filter: ['==', ['get', 'handle'], 'vertex'], paint: { ...p.vertices, 'circle-radius': 7, 'circle-stroke-width': 2.5 } })
167
167
  }
168
168
 
169
+ type SetPaint = Parameters<Maplibre.Map['setPaintProperty']>
170
+
169
171
  watch(theme, () => {
170
172
  if (!map) return
171
173
  const p = paints()
172
174
  const set = (layer: string, paint: Record<string, unknown>) => {
173
- if (map!.getLayer(layer)) for (const [k, v] of Object.entries(paint)) map!.setPaintProperty(layer, k, v)
175
+ if (map!.getLayer(layer)) for (const [k, v] of Object.entries(paint)) map!.setPaintProperty(layer, k as SetPaint[1], v as SetPaint[2])
174
176
  }
175
177
  for (const source of [SRC.done, SRC.draft]) {
176
178
  set(`${source}-fill`, p.fill)
@@ -18,7 +18,7 @@ import MMapControl from './MMapControl.vue'
18
18
  import MMapMarker from './MMapMarker.vue'
19
19
  import { useLocale } from '../composables/useLocale'
20
20
  import { useMap } from '../composables/useMap'
21
- import { nominatimProvider, type MapSearchProvider, type MapSearchResult } from '../composables/mapSearch'
21
+ import { nominatimProvider, placeIcon as iconOf, type MapSearchProvider, type MapSearchResult } from '../composables/mapSearch'
22
22
  import type { MapControlPosition } from './MMap.vue'
23
23
 
24
24
  const props = withDefaults(
@@ -109,14 +109,6 @@ onBeforeUnmount(() => {
109
109
  clearTimeout(debounce)
110
110
  })
111
111
 
112
- const ICONS: Record<string, string> = {
113
- city: 'location_city', town: 'location_city', village: 'holiday_village', hamlet: 'cottage', suburb: 'apartment',
114
- neighbourhood: 'maps_home_work', road: 'road', residential: 'home', house: 'home', building: 'domain',
115
- shop: 'storefront', park: 'park', water: 'water', river: 'water', lake: 'water', school: 'school',
116
- university: 'school', hospital: 'local_hospital', restaurant: 'restaurant', cafe: 'local_cafe', hotel: 'hotel',
117
- station: 'train', bus_stop: 'directions_bus', administrative: 'map', country: 'public', state: 'map',
118
- }
119
- const iconOf = (type?: string) => (type && ICONS[type]) || 'location_on'
120
112
  </script>
121
113
 
122
114
  <template>