wevu 6.18.6 → 6.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (585) hide show
  1. package/dist/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/defineProperty.mjs +1 -0
  2. package/dist/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/toPrimitive.mjs +1 -0
  3. package/dist/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/toPropertyKey.mjs +1 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/typeof.mjs +1 -0
  5. package/dist/{rolldown-runtime-CenpyGzJ.mjs → _virtual/_rolldown/runtime.mjs} +1 -1
  6. package/dist/dev/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/defineProperty.mjs +14 -0
  7. package/dist/dev/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/toPrimitive.mjs +16 -0
  8. package/dist/dev/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/toPropertyKey.mjs +11 -0
  9. package/dist/dev/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/typeof.mjs +12 -0
  10. package/dist/dev/{rolldown-runtime-BUUfjzRC.mjs → _virtual/_rolldown/runtime.mjs} +1 -1
  11. package/dist/dev/index.mjs +49 -10
  12. package/dist/dev/internal-reactivity.mjs +15 -5
  13. package/dist/dev/internal-runtime.mjs +32 -4
  14. package/dist/dev/internal-template.mjs +1 -1
  15. package/dist/dev/package.mjs +6 -0
  16. package/dist/dev/package.mjs.map +1 -0
  17. package/dist/dev/reactivity/computed.mjs +49 -0
  18. package/dist/dev/reactivity/computed.mjs.map +1 -0
  19. package/dist/dev/reactivity/core.mjs +184 -0
  20. package/dist/dev/reactivity/core.mjs.map +1 -0
  21. package/dist/dev/reactivity/reactive/mutation.mjs +12 -0
  22. package/dist/dev/reactivity/reactive/mutation.mjs.map +1 -0
  23. package/dist/dev/{computed-BxRsUJgi.mjs → reactivity/reactive/patch.mjs} +6 -48
  24. package/dist/dev/reactivity/reactive/patch.mjs.map +1 -0
  25. package/dist/dev/reactivity/reactive/patchState.mjs +138 -0
  26. package/dist/dev/reactivity/reactive/patchState.mjs.map +1 -0
  27. package/dist/dev/reactivity/reactive/shallow.mjs +77 -0
  28. package/dist/dev/reactivity/reactive/shallow.mjs.map +1 -0
  29. package/dist/dev/reactivity/reactive/shared.mjs +40 -0
  30. package/dist/dev/reactivity/reactive/shared.mjs.map +1 -0
  31. package/dist/dev/reactivity/reactive/state.mjs +8 -0
  32. package/dist/dev/reactivity/reactive/state.mjs.map +1 -0
  33. package/dist/dev/reactivity/reactive.mjs +212 -0
  34. package/dist/dev/reactivity/reactive.mjs.map +1 -0
  35. package/dist/dev/reactivity/readonly.mjs +69 -0
  36. package/dist/dev/reactivity/readonly.mjs.map +1 -0
  37. package/dist/dev/reactivity/ref.mjs +97 -0
  38. package/dist/dev/reactivity/ref.mjs.map +1 -0
  39. package/dist/dev/reactivity/shallowRef.mjs +71 -0
  40. package/dist/dev/reactivity/shallowRef.mjs.map +1 -0
  41. package/dist/dev/{toRefs-D06VmFK2.mjs → reactivity/toRefs.mjs} +4 -3
  42. package/dist/dev/reactivity/toRefs.mjs.map +1 -0
  43. package/dist/dev/reactivity/traverse.mjs +40 -0
  44. package/dist/dev/reactivity/traverse.mjs.map +1 -0
  45. package/dist/dev/reactivity/watch/helpers.mjs +78 -0
  46. package/dist/dev/reactivity/watch/helpers.mjs.map +1 -0
  47. package/dist/dev/reactivity/watch/types.mjs +20 -0
  48. package/dist/dev/reactivity/watch/types.mjs.map +1 -0
  49. package/dist/dev/reactivity/watch.mjs +167 -0
  50. package/dist/dev/reactivity/watch.mjs.map +1 -0
  51. package/dist/dev/router/backNavigation.mjs +32 -0
  52. package/dist/dev/router/backNavigation.mjs.map +1 -0
  53. package/dist/dev/router/createRouter.mjs +176 -0
  54. package/dist/dev/router/createRouter.mjs.map +1 -0
  55. package/dist/dev/router/instance.mjs +17 -0
  56. package/dist/dev/router/instance.mjs.map +1 -0
  57. package/dist/dev/router/navigationApi.mjs +94 -0
  58. package/dist/dev/router/navigationApi.mjs.map +1 -0
  59. package/dist/dev/router/navigationCore.mjs +139 -0
  60. package/dist/dev/router/navigationCore.mjs.map +1 -0
  61. package/dist/dev/router/navigationResult.mjs +54 -0
  62. package/dist/dev/router/navigationResult.mjs.map +1 -0
  63. package/dist/dev/router/navigationTarget.mjs +121 -0
  64. package/dist/dev/router/navigationTarget.mjs.map +1 -0
  65. package/dist/dev/router/navigationTargetHelpers.mjs +38 -0
  66. package/dist/dev/router/navigationTargetHelpers.mjs.map +1 -0
  67. package/dist/dev/router/resolve.mjs +22 -0
  68. package/dist/dev/router/resolve.mjs.map +1 -0
  69. package/dist/dev/router/routeRegistry.mjs +78 -0
  70. package/dist/dev/router/routeRegistry.mjs.map +1 -0
  71. package/dist/dev/router/routeSync.mjs +72 -0
  72. package/dist/dev/router/routeSync.mjs.map +1 -0
  73. package/dist/dev/router/types.mjs +11 -0
  74. package/dist/dev/router/types.mjs.map +1 -0
  75. package/dist/dev/router/useRoute.mjs +106 -0
  76. package/dist/dev/router/useRoute.mjs.map +1 -0
  77. package/dist/dev/router/useRouter.mjs +15 -0
  78. package/dist/dev/router/useRouter.mjs.map +1 -0
  79. package/dist/dev/router.mjs +9 -1316
  80. package/dist/dev/routerInternal/location.mjs +66 -0
  81. package/dist/dev/routerInternal/location.mjs.map +1 -0
  82. package/dist/dev/routerInternal/matching.mjs +149 -0
  83. package/dist/dev/routerInternal/matching.mjs.map +1 -0
  84. package/dist/dev/routerInternal/params.mjs +95 -0
  85. package/dist/dev/routerInternal/params.mjs.map +1 -0
  86. package/dist/dev/routerInternal/path.mjs +42 -0
  87. package/dist/dev/routerInternal/path.mjs.map +1 -0
  88. package/dist/dev/routerInternal/query.mjs +113 -0
  89. package/dist/dev/routerInternal/query.mjs.map +1 -0
  90. package/dist/dev/routerInternal/records.mjs +172 -0
  91. package/dist/dev/routerInternal/records.mjs.map +1 -0
  92. package/dist/dev/routerInternal/recordsWarnings.mjs +49 -0
  93. package/dist/dev/routerInternal/recordsWarnings.mjs.map +1 -0
  94. package/dist/dev/routerInternal/snapshots.mjs +126 -0
  95. package/dist/dev/routerInternal/snapshots.mjs.map +1 -0
  96. package/dist/dev/runtime/app/computed.mjs +68 -0
  97. package/dist/dev/runtime/app/computed.mjs.map +1 -0
  98. package/dist/dev/runtime/app/context.mjs +275 -0
  99. package/dist/dev/runtime/app/context.mjs.map +1 -0
  100. package/dist/dev/runtime/app/diagnostics.mjs +34 -0
  101. package/dist/dev/runtime/app/diagnostics.mjs.map +1 -0
  102. package/dist/dev/runtime/app/mount.mjs +269 -0
  103. package/dist/dev/runtime/app/mount.mjs.map +1 -0
  104. package/dist/dev/runtime/app/pending.mjs +14 -0
  105. package/dist/dev/runtime/app/pending.mjs.map +1 -0
  106. package/dist/dev/runtime/app/setData/patchScheduler.mjs +158 -0
  107. package/dist/dev/runtime/app/setData/patchScheduler.mjs.map +1 -0
  108. package/dist/dev/runtime/app/setData/payload.mjs +161 -0
  109. package/dist/dev/runtime/app/setData/payload.mjs.map +1 -0
  110. package/dist/dev/runtime/app/setData/scheduler.mjs +313 -0
  111. package/dist/dev/runtime/app/setData/scheduler.mjs.map +1 -0
  112. package/dist/dev/runtime/app/setData/snapshot.mjs +129 -0
  113. package/dist/dev/runtime/app/setData/snapshot.mjs.map +1 -0
  114. package/dist/dev/runtime/app/setDataOptions.mjs +73 -0
  115. package/dist/dev/runtime/app/setDataOptions.mjs.map +1 -0
  116. package/dist/dev/runtime/app.mjs +93 -0
  117. package/dist/dev/runtime/app.mjs.map +1 -0
  118. package/dist/dev/runtime/bindModel.mjs +92 -0
  119. package/dist/dev/runtime/bindModel.mjs.map +1 -0
  120. package/dist/dev/runtime/defaults.mjs +61 -0
  121. package/dist/dev/runtime/defaults.mjs.map +1 -0
  122. package/dist/dev/runtime/define/initialComputed.mjs +125 -0
  123. package/dist/dev/runtime/define/initialComputed.mjs.map +1 -0
  124. package/dist/dev/runtime/define/options.mjs +169 -0
  125. package/dist/dev/runtime/define/options.mjs.map +1 -0
  126. package/dist/dev/runtime/define/optionsApi.mjs +48 -0
  127. package/dist/dev/runtime/define/optionsApi.mjs.map +1 -0
  128. package/dist/dev/runtime/define/props.mjs +194 -0
  129. package/dist/dev/runtime/define/props.mjs.map +1 -0
  130. package/dist/dev/runtime/define/scopedSlotOptions.mjs +313 -0
  131. package/dist/dev/runtime/define/scopedSlotOptions.mjs.map +1 -0
  132. package/dist/dev/runtime/define/setupResult.mjs +78 -0
  133. package/dist/dev/runtime/define/setupResult.mjs.map +1 -0
  134. package/dist/dev/runtime/define.mjs +140 -0
  135. package/dist/dev/runtime/define.mjs.map +1 -0
  136. package/dist/dev/runtime/diff.mjs +193 -0
  137. package/dist/dev/runtime/diff.mjs.map +1 -0
  138. package/dist/dev/runtime/disposables.mjs +81 -0
  139. package/dist/dev/runtime/disposables.mjs.map +1 -0
  140. package/dist/dev/runtime/elementIntersectionObserver.mjs +80 -0
  141. package/dist/dev/runtime/elementIntersectionObserver.mjs.map +1 -0
  142. package/dist/dev/runtime/emit.mjs +36 -0
  143. package/dist/dev/runtime/emit.mjs.map +1 -0
  144. package/dist/dev/{base-CYkvI7w8.mjs → runtime/hooks/base.mjs} +3 -140
  145. package/dist/dev/runtime/hooks/base.mjs.map +1 -0
  146. package/dist/dev/runtime/hooks/register.mjs +92 -0
  147. package/dist/dev/runtime/hooks/register.mjs.map +1 -0
  148. package/dist/dev/runtime/hooks/vue.mjs +81 -0
  149. package/dist/dev/runtime/hooks/vue.mjs.map +1 -0
  150. package/dist/dev/runtime/internal.mjs +18 -0
  151. package/dist/dev/runtime/internal.mjs.map +1 -0
  152. package/dist/dev/runtime/intersectionObserver.mjs +46 -0
  153. package/dist/dev/runtime/intersectionObserver.mjs.map +1 -0
  154. package/dist/dev/runtime/layoutBridge.mjs +303 -0
  155. package/dist/dev/runtime/layoutBridge.mjs.map +1 -0
  156. package/dist/dev/runtime/layoutComponentMatcher.mjs +11 -0
  157. package/dist/dev/runtime/layoutComponentMatcher.mjs.map +1 -0
  158. package/dist/dev/runtime/nativeBridge.mjs +21 -0
  159. package/dist/dev/runtime/nativeBridge.mjs.map +1 -0
  160. package/dist/dev/runtime/noSetData.mjs +18 -0
  161. package/dist/dev/runtime/noSetData.mjs.map +1 -0
  162. package/dist/dev/runtime/pageEnvironment.mjs +100 -0
  163. package/dist/dev/runtime/pageEnvironment.mjs.map +1 -0
  164. package/dist/dev/runtime/pageLayout.mjs +71 -0
  165. package/dist/dev/runtime/pageLayout.mjs.map +1 -0
  166. package/dist/dev/runtime/pageScroll.mjs +110 -0
  167. package/dist/dev/runtime/pageScroll.mjs.map +1 -0
  168. package/dist/dev/runtime/platform.mjs +77 -0
  169. package/dist/dev/runtime/platform.mjs.map +1 -0
  170. package/dist/dev/runtime/provide.mjs +71 -0
  171. package/dist/dev/runtime/provide.mjs.map +1 -0
  172. package/dist/dev/runtime/provideContext.mjs +101 -0
  173. package/dist/dev/runtime/provideContext.mjs.map +1 -0
  174. package/dist/dev/runtime/provideStore.mjs +18 -0
  175. package/dist/dev/runtime/provideStore.mjs.map +1 -0
  176. package/dist/dev/runtime/pullDownRefresh.mjs +24 -0
  177. package/dist/dev/runtime/pullDownRefresh.mjs.map +1 -0
  178. package/dist/dev/runtime/register/app.mjs +159 -0
  179. package/dist/dev/runtime/register/app.mjs.map +1 -0
  180. package/dist/dev/runtime/register/component/features.mjs +43 -0
  181. package/dist/dev/runtime/register/component/features.mjs.map +1 -0
  182. package/dist/dev/runtime/register/component/lifecycle/optionalHooks.mjs +64 -0
  183. package/dist/dev/runtime/register/component/lifecycle/optionalHooks.mjs.map +1 -0
  184. package/dist/dev/runtime/register/component/lifecycle/platform.mjs +95 -0
  185. package/dist/dev/runtime/register/component/lifecycle/platform.mjs.map +1 -0
  186. package/dist/dev/runtime/register/component/lifecycle.mjs +122 -0
  187. package/dist/dev/runtime/register/component/lifecycle.mjs.map +1 -0
  188. package/dist/dev/runtime/register/component/methods.mjs +80 -0
  189. package/dist/dev/runtime/register/component/methods.mjs.map +1 -0
  190. package/dist/dev/runtime/register/component/options.mjs +204 -0
  191. package/dist/dev/runtime/register/component/options.mjs.map +1 -0
  192. package/dist/dev/runtime/register/component/props.mjs +218 -0
  193. package/dist/dev/runtime/register/component/props.mjs.map +1 -0
  194. package/dist/dev/runtime/register/component/registerDefinition.mjs +290 -0
  195. package/dist/dev/runtime/register/component/registerDefinition.mjs.map +1 -0
  196. package/dist/dev/runtime/register/component.mjs +128 -0
  197. package/dist/dev/runtime/register/component.mjs.map +1 -0
  198. package/dist/dev/runtime/register/inline.mjs +145 -0
  199. package/dist/dev/runtime/register/inline.mjs.map +1 -0
  200. package/dist/dev/runtime/register/runtimeInstance/methodBridge.mjs +53 -0
  201. package/dist/dev/runtime/register/runtimeInstance/methodBridge.mjs.map +1 -0
  202. package/dist/dev/runtime/register/runtimeInstance/provideContext.mjs +34 -0
  203. package/dist/dev/runtime/register/runtimeInstance/provideContext.mjs.map +1 -0
  204. package/dist/dev/runtime/register/runtimeInstance/setupContext.mjs +230 -0
  205. package/dist/dev/runtime/register/runtimeInstance/setupContext.mjs.map +1 -0
  206. package/dist/dev/runtime/register/runtimeInstance/setupPhase.mjs +164 -0
  207. package/dist/dev/runtime/register/runtimeInstance/setupPhase.mjs.map +1 -0
  208. package/dist/dev/runtime/register/runtimeInstance/utils.mjs +122 -0
  209. package/dist/dev/runtime/register/runtimeInstance/utils.mjs.map +1 -0
  210. package/dist/dev/runtime/register/runtimeInstance.mjs +438 -0
  211. package/dist/dev/runtime/register/runtimeInstance.mjs.map +1 -0
  212. package/dist/dev/runtime/register/setDataFrequencyWarning.mjs +95 -0
  213. package/dist/dev/runtime/register/setDataFrequencyWarning.mjs.map +1 -0
  214. package/dist/dev/runtime/register/setup.mjs +22 -0
  215. package/dist/dev/runtime/register/setup.mjs.map +1 -0
  216. package/dist/dev/runtime/register/snapshot.mjs +17 -0
  217. package/dist/dev/runtime/register/snapshot.mjs.map +1 -0
  218. package/dist/dev/runtime/register/watch.mjs +57 -0
  219. package/dist/dev/runtime/register/watch.mjs.map +1 -0
  220. package/dist/dev/runtime/scopedSlots.mjs +115 -0
  221. package/dist/dev/runtime/scopedSlots.mjs.map +1 -0
  222. package/dist/dev/runtime/selectorQuery.mjs +49 -0
  223. package/dist/dev/runtime/selectorQuery.mjs.map +1 -0
  224. package/dist/dev/runtime/setupTracking.mjs +59 -0
  225. package/dist/dev/runtime/setupTracking.mjs.map +1 -0
  226. package/dist/dev/{template-n_iVr0ey.mjs → runtime/template.mjs} +7 -4
  227. package/dist/dev/runtime/template.mjs.map +1 -0
  228. package/dist/dev/runtime/templateRefs/helpers.mjs +254 -0
  229. package/dist/dev/runtime/templateRefs/helpers.mjs.map +1 -0
  230. package/dist/dev/runtime/templateRefs.mjs +162 -0
  231. package/dist/dev/runtime/templateRefs.mjs.map +1 -0
  232. package/dist/dev/runtime/uniAppHost.mjs +119 -0
  233. package/dist/dev/runtime/uniAppHost.mjs.map +1 -0
  234. package/dist/dev/runtime/updatePerformance.mjs +41 -0
  235. package/dist/dev/runtime/updatePerformance.mjs.map +1 -0
  236. package/dist/dev/runtime/use.mjs +25 -0
  237. package/dist/dev/runtime/use.mjs.map +1 -0
  238. package/dist/dev/runtime/vueCompat/context.mjs +25 -0
  239. package/dist/dev/runtime/vueCompat/context.mjs.map +1 -0
  240. package/dist/dev/runtime/vueCompat/model.mjs +118 -0
  241. package/dist/dev/runtime/vueCompat/model.mjs.map +1 -0
  242. package/dist/dev/runtime/vueCompat/router.mjs +124 -0
  243. package/dist/dev/runtime/vueCompat/router.mjs.map +1 -0
  244. package/dist/dev/runtime/vueCompat/templateRef.mjs +37 -0
  245. package/dist/dev/runtime/vueCompat/templateRef.mjs.map +1 -0
  246. package/dist/dev/scheduler.mjs +75 -0
  247. package/dist/dev/scheduler.mjs.map +1 -0
  248. package/dist/dev/store/actions.mjs +40 -0
  249. package/dist/dev/store/actions.mjs.map +1 -0
  250. package/dist/dev/store/base.mjs +56 -0
  251. package/dist/dev/store/base.mjs.map +1 -0
  252. package/dist/dev/store/define/optionsStyle.mjs +125 -0
  253. package/dist/dev/store/define/optionsStyle.mjs.map +1 -0
  254. package/dist/dev/store/define/setupStyle.mjs +145 -0
  255. package/dist/dev/store/define/setupStyle.mjs.map +1 -0
  256. package/dist/dev/store/define/shared.mjs +38 -0
  257. package/dist/dev/store/define/shared.mjs.map +1 -0
  258. package/dist/dev/store/define.mjs +23 -0
  259. package/dist/dev/store/define.mjs.map +1 -0
  260. package/dist/dev/store/manager.mjs +21 -0
  261. package/dist/dev/store/manager.mjs.map +1 -0
  262. package/dist/dev/store/storeToRefs.mjs +29 -0
  263. package/dist/dev/store/storeToRefs.mjs.map +1 -0
  264. package/dist/dev/store/utils.mjs +49 -0
  265. package/dist/dev/store/utils.mjs.map +1 -0
  266. package/dist/dev/store.mjs +3 -1
  267. package/dist/dev/utils.mjs +16 -0
  268. package/dist/dev/utils.mjs.map +1 -0
  269. package/dist/dev/version.mjs +8 -0
  270. package/dist/dev/version.mjs.map +1 -0
  271. package/dist/dev/vue-demi.mjs +49 -11
  272. package/dist/dev/vue-demi.mjs.map +1 -1
  273. package/dist/index.d.mts +71 -7
  274. package/dist/index.mjs +1 -1
  275. package/dist/internal-reactivity.d.mts +16 -2
  276. package/dist/internal-reactivity.mjs +1 -1
  277. package/dist/internal-runtime.d.mts +35 -2
  278. package/dist/internal-runtime.mjs +1 -1
  279. package/dist/internal-template.d.mts +1 -1
  280. package/dist/internal-template.mjs +1 -1
  281. package/dist/jsx-runtime.d.mts +1 -1
  282. package/dist/macros/shared.d.mts +81 -0
  283. package/dist/macros.d.mts +70 -0
  284. package/dist/package.mjs +1 -0
  285. package/dist/reactivity/computed.d.mts +21 -0
  286. package/dist/reactivity/computed.mjs +1 -0
  287. package/dist/reactivity/core.d.mts +34 -0
  288. package/dist/reactivity/core.mjs +1 -0
  289. package/dist/reactivity/index.d.mts +15 -0
  290. package/dist/reactivity/reactive/mutation.d.mts +21 -0
  291. package/dist/reactivity/reactive/mutation.mjs +1 -0
  292. package/dist/reactivity/reactive/patch.d.mts +18 -0
  293. package/dist/reactivity/reactive/patch.mjs +1 -0
  294. package/dist/reactivity/reactive/patchState.mjs +1 -0
  295. package/dist/reactivity/reactive/shallow.d.mts +22 -0
  296. package/dist/reactivity/reactive/shallow.mjs +1 -0
  297. package/dist/reactivity/reactive/shared.d.mts +4 -0
  298. package/dist/reactivity/reactive/shared.mjs +1 -0
  299. package/dist/reactivity/reactive/state.mjs +1 -0
  300. package/dist/reactivity/reactive.d.mts +41 -0
  301. package/dist/reactivity/reactive.mjs +1 -0
  302. package/dist/reactivity/readonly.d.mts +27 -0
  303. package/dist/reactivity/readonly.mjs +1 -0
  304. package/dist/reactivity/ref.d.mts +27 -0
  305. package/dist/reactivity/ref.mjs +1 -0
  306. package/dist/reactivity/shallowRef.d.mts +19 -0
  307. package/dist/reactivity/shallowRef.mjs +1 -0
  308. package/dist/reactivity/toRefs.d.mts +43 -0
  309. package/dist/reactivity/toRefs.mjs +1 -0
  310. package/dist/reactivity/traverse.d.mts +8 -0
  311. package/dist/reactivity/traverse.mjs +1 -0
  312. package/dist/reactivity/watch/helpers.mjs +1 -0
  313. package/dist/reactivity/watch/types.d.mts +43 -0
  314. package/dist/reactivity/watch/types.mjs +1 -0
  315. package/dist/reactivity/watch.d.mts +21 -0
  316. package/dist/reactivity/watch.mjs +1 -0
  317. package/dist/router/backNavigation.mjs +1 -0
  318. package/dist/router/createRouter.d.mts +8 -0
  319. package/dist/router/createRouter.mjs +1 -0
  320. package/dist/router/instance.mjs +1 -0
  321. package/dist/router/navigationApi.mjs +1 -0
  322. package/dist/router/navigationCore.d.mts +6 -0
  323. package/dist/router/navigationCore.mjs +1 -0
  324. package/dist/router/navigationResult.mjs +1 -0
  325. package/dist/router/navigationTarget.mjs +1 -0
  326. package/dist/router/navigationTargetHelpers.mjs +1 -0
  327. package/dist/router/resolve.d.mts +6 -0
  328. package/dist/router/resolve.mjs +1 -0
  329. package/dist/router/routeRegistry.mjs +1 -0
  330. package/dist/router/routeSync.d.mts +1 -0
  331. package/dist/router/routeSync.mjs +1 -0
  332. package/dist/router/types.d.mts +163 -0
  333. package/dist/router/types.mjs +1 -0
  334. package/dist/router/useRoute.d.mts +19 -0
  335. package/dist/router/useRoute.mjs +1 -0
  336. package/dist/router/useRouter.d.mts +8 -0
  337. package/dist/router/useRouter.mjs +1 -0
  338. package/dist/router.d.mts +9 -204
  339. package/dist/router.mjs +1 -1
  340. package/dist/routerInternal/location.mjs +1 -0
  341. package/dist/routerInternal/matching.mjs +1 -0
  342. package/dist/routerInternal/params.mjs +1 -0
  343. package/dist/routerInternal/path.mjs +1 -0
  344. package/dist/routerInternal/query.d.mts +7 -0
  345. package/dist/routerInternal/query.mjs +1 -0
  346. package/dist/routerInternal/records.mjs +1 -0
  347. package/dist/routerInternal/recordsWarnings.mjs +1 -0
  348. package/dist/routerInternal/snapshots.mjs +1 -0
  349. package/dist/routerInternal/types.d.mts +9 -0
  350. package/dist/runtime/app/computed.mjs +1 -0
  351. package/dist/runtime/app/context.mjs +1 -0
  352. package/dist/runtime/app/diagnostics.mjs +1 -0
  353. package/dist/runtime/app/mount.mjs +1 -0
  354. package/dist/runtime/app/pending.d.mts +10 -0
  355. package/dist/runtime/app/pending.mjs +1 -0
  356. package/dist/runtime/app/setData/patchScheduler.mjs +1 -0
  357. package/dist/runtime/app/setData/payload.mjs +1 -0
  358. package/dist/runtime/app/setData/scheduler.mjs +1 -0
  359. package/dist/runtime/app/setData/snapshot.mjs +1 -0
  360. package/dist/runtime/app/setDataOptions.mjs +1 -0
  361. package/dist/runtime/app.d.mts +8 -0
  362. package/dist/runtime/app.mjs +1 -0
  363. package/dist/runtime/bindModel.mjs +1 -0
  364. package/dist/runtime/defaults.d.mts +11 -0
  365. package/dist/runtime/defaults.mjs +1 -0
  366. package/dist/runtime/define/initialComputed.mjs +1 -0
  367. package/dist/runtime/define/options.mjs +1 -0
  368. package/dist/runtime/define/optionsApi.mjs +1 -0
  369. package/dist/runtime/define/props.mjs +1 -0
  370. package/dist/runtime/define/scopedSlotOptions.mjs +1 -0
  371. package/dist/runtime/define/setupResult.mjs +1 -0
  372. package/dist/runtime/define.d.mts +105 -0
  373. package/dist/runtime/define.mjs +1 -0
  374. package/dist/runtime/diff.mjs +1 -0
  375. package/dist/runtime/disposables.d.mts +31 -0
  376. package/dist/runtime/disposables.mjs +1 -0
  377. package/dist/runtime/elementIntersectionObserver.d.mts +26 -0
  378. package/dist/runtime/elementIntersectionObserver.mjs +1 -0
  379. package/dist/runtime/emit.mjs +1 -0
  380. package/dist/runtime/hooks/base.d.mts +27 -0
  381. package/dist/runtime/hooks/base.mjs +1 -0
  382. package/dist/runtime/hooks/register.d.mts +30 -0
  383. package/dist/runtime/hooks/register.mjs +1 -0
  384. package/dist/runtime/hooks/vue.d.mts +53 -0
  385. package/dist/runtime/hooks/vue.mjs +1 -0
  386. package/dist/runtime/hooks.d.mts +4 -0
  387. package/dist/runtime/index.d.mts +47 -0
  388. package/dist/runtime/internal.mjs +1 -0
  389. package/dist/runtime/intersectionObserver.d.mts +14 -0
  390. package/dist/runtime/intersectionObserver.mjs +1 -0
  391. package/dist/runtime/layoutBridge.d.mts +59 -0
  392. package/dist/runtime/layoutBridge.mjs +1 -0
  393. package/dist/runtime/layoutComponentMatcher.mjs +1 -0
  394. package/dist/runtime/nativeBridge.mjs +1 -0
  395. package/dist/runtime/noSetData.d.mts +5 -0
  396. package/dist/runtime/noSetData.mjs +1 -0
  397. package/dist/runtime/pageEnvironment.d.mts +50 -0
  398. package/dist/runtime/pageEnvironment.mjs +1 -0
  399. package/dist/runtime/pageLayout.d.mts +26 -0
  400. package/dist/runtime/pageLayout.mjs +1 -0
  401. package/dist/runtime/pageScroll.d.mts +29 -0
  402. package/dist/runtime/pageScroll.mjs +1 -0
  403. package/dist/runtime/platform.mjs +1 -0
  404. package/dist/runtime/provide.d.mts +59 -0
  405. package/dist/runtime/provide.mjs +1 -0
  406. package/dist/runtime/provideContext.mjs +1 -0
  407. package/dist/runtime/provideStore.d.mts +7 -0
  408. package/dist/runtime/provideStore.mjs +1 -0
  409. package/dist/runtime/pullDownRefresh.d.mts +12 -0
  410. package/dist/runtime/pullDownRefresh.mjs +1 -0
  411. package/dist/runtime/register/app.d.mts +14 -0
  412. package/dist/runtime/register/app.mjs +1 -0
  413. package/dist/runtime/register/component/features.mjs +1 -0
  414. package/dist/runtime/register/component/lifecycle/optionalHooks.mjs +1 -0
  415. package/dist/runtime/register/component/lifecycle/platform.mjs +1 -0
  416. package/dist/runtime/register/component/lifecycle.mjs +1 -0
  417. package/dist/runtime/register/component/methods.mjs +1 -0
  418. package/dist/runtime/register/component/options.mjs +1 -0
  419. package/dist/runtime/register/component/props.mjs +1 -0
  420. package/dist/runtime/register/component/registerDefinition.mjs +1 -0
  421. package/dist/runtime/register/component.d.mts +15 -0
  422. package/dist/runtime/register/component.mjs +1 -0
  423. package/dist/runtime/register/inline.d.mts +15 -0
  424. package/dist/runtime/register/inline.mjs +1 -0
  425. package/dist/runtime/register/runtimeInstance/methodBridge.mjs +1 -0
  426. package/dist/runtime/register/runtimeInstance/provideContext.mjs +1 -0
  427. package/dist/runtime/register/runtimeInstance/setupContext.mjs +1 -0
  428. package/dist/runtime/register/runtimeInstance/setupPhase.mjs +1 -0
  429. package/dist/runtime/register/runtimeInstance/utils.mjs +1 -0
  430. package/dist/runtime/register/runtimeInstance.d.mts +26 -0
  431. package/dist/runtime/register/runtimeInstance.mjs +1 -0
  432. package/dist/runtime/register/setDataFrequencyWarning.mjs +1 -0
  433. package/dist/runtime/register/setup.d.mts +11 -0
  434. package/dist/runtime/register/setup.mjs +1 -0
  435. package/dist/runtime/register/snapshot.mjs +1 -0
  436. package/dist/runtime/register/watch.d.mts +12 -0
  437. package/dist/runtime/register/watch.mjs +1 -0
  438. package/dist/runtime/register.d.mts +5 -0
  439. package/dist/runtime/scopedSlots.mjs +1 -0
  440. package/dist/runtime/selectorQuery.d.mts +54 -0
  441. package/dist/runtime/selectorQuery.mjs +1 -0
  442. package/dist/runtime/setupTracking.mjs +1 -0
  443. package/dist/{template-DE8e5dj_.d.mts → runtime/template.d.mts} +1 -1
  444. package/dist/runtime/template.mjs +1 -0
  445. package/dist/runtime/templateRefTypes.d.mts +7 -0
  446. package/dist/runtime/templateRefs/helpers.mjs +1 -0
  447. package/dist/runtime/templateRefs.d.mts +11 -0
  448. package/dist/runtime/templateRefs.mjs +1 -0
  449. package/dist/runtime/types/core.d.mts +35 -0
  450. package/dist/runtime/types/miniprogram.d.mts +80 -0
  451. package/dist/runtime/types/miniprogramHost.d.mts +44 -0
  452. package/dist/runtime/types/miniprogramHostSources.d.mts +112 -0
  453. package/dist/runtime/types/options.d.mts +136 -0
  454. package/dist/runtime/types/props/propTypes.d.mts +79 -0
  455. package/dist/runtime/types/props/router.d.mts +51 -0
  456. package/dist/runtime/types/props/setup.d.mts +96 -0
  457. package/dist/runtime/types/props.d.mts +4 -0
  458. package/dist/runtime/types/runtime.d.mts +59 -0
  459. package/dist/runtime/types/setData.d.mts +220 -0
  460. package/dist/runtime/types.d.mts +28 -0
  461. package/dist/runtime/uniAppHost.d.mts +8 -0
  462. package/dist/runtime/uniAppHost.mjs +1 -0
  463. package/dist/runtime/updatePerformance.d.mts +13 -0
  464. package/dist/runtime/updatePerformance.mjs +1 -0
  465. package/dist/runtime/use.d.mts +13 -0
  466. package/dist/runtime/use.mjs +1 -0
  467. package/dist/runtime/vueCompat/context.d.mts +8 -0
  468. package/dist/runtime/vueCompat/context.mjs +1 -0
  469. package/dist/runtime/vueCompat/model.d.mts +30 -0
  470. package/dist/runtime/vueCompat/model.mjs +1 -0
  471. package/dist/runtime/vueCompat/router.d.mts +28 -0
  472. package/dist/runtime/vueCompat/router.mjs +1 -0
  473. package/dist/runtime/vueCompat/templateRef.d.mts +9 -0
  474. package/dist/runtime/vueCompat/templateRef.mjs +1 -0
  475. package/dist/runtime/vueCompat.d.mts +5 -0
  476. package/dist/scheduler.d.mts +4 -0
  477. package/dist/scheduler.mjs +1 -0
  478. package/dist/store/actions.mjs +1 -0
  479. package/dist/store/base.mjs +1 -0
  480. package/dist/store/define/optionsStyle.mjs +1 -0
  481. package/dist/store/define/setupStyle.mjs +1 -0
  482. package/dist/store/define/shared.mjs +1 -0
  483. package/dist/store/define.d.mts +26 -0
  484. package/dist/store/define.mjs +1 -0
  485. package/dist/store/manager.d.mts +8 -0
  486. package/dist/store/manager.mjs +1 -0
  487. package/dist/store/storeToRefs.d.mts +13 -0
  488. package/dist/store/storeToRefs.mjs +1 -0
  489. package/dist/store/types.d.mts +70 -0
  490. package/dist/store/utils.mjs +1 -0
  491. package/dist/store.d.mts +4 -1
  492. package/dist/store.mjs +1 -1
  493. package/dist/utils.mjs +1 -0
  494. package/dist/version.d.mts +4 -0
  495. package/dist/version.mjs +1 -0
  496. package/dist/vue-augment.d.mts +6 -0
  497. package/dist/vue-demi.d.mts +67 -7
  498. package/dist/vue-demi.mjs +1 -1
  499. package/dist/vue-types.d.mts +18 -0
  500. package/dist/weappIntrinsicElements/base.d.mts +22 -0
  501. package/dist/weappIntrinsicElements/elements/ad-custom.d.mts +13 -0
  502. package/dist/weappIntrinsicElements/elements/ad.d.mts +16 -0
  503. package/dist/weappIntrinsicElements/elements/audio.d.mts +20 -0
  504. package/dist/weappIntrinsicElements/elements/block.d.mts +8 -0
  505. package/dist/weappIntrinsicElements/elements/button.d.mts +40 -0
  506. package/dist/weappIntrinsicElements/elements/camera.d.mts +18 -0
  507. package/dist/weappIntrinsicElements/elements/canvas.d.mts +18 -0
  508. package/dist/weappIntrinsicElements/elements/checkbox-group.d.mts +13 -0
  509. package/dist/weappIntrinsicElements/elements/checkbox.d.mts +13 -0
  510. package/dist/weappIntrinsicElements/elements/cover-image.d.mts +10 -0
  511. package/dist/weappIntrinsicElements/elements/cover-view.d.mts +10 -0
  512. package/dist/weappIntrinsicElements/elements/editor.d.mts +22 -0
  513. package/dist/weappIntrinsicElements/elements/form.d.mts +16 -0
  514. package/dist/weappIntrinsicElements/elements/functional-page-navigator.d.mts +15 -0
  515. package/dist/weappIntrinsicElements/elements/icon.d.mts +12 -0
  516. package/dist/weappIntrinsicElements/elements/image.d.mts +18 -0
  517. package/dist/weappIntrinsicElements/elements/import.d.mts +10 -0
  518. package/dist/weappIntrinsicElements/elements/include.d.mts +10 -0
  519. package/dist/weappIntrinsicElements/elements/input.d.mts +47 -0
  520. package/dist/weappIntrinsicElements/elements/keyboard-accessory.d.mts +8 -0
  521. package/dist/weappIntrinsicElements/elements/label.d.mts +10 -0
  522. package/dist/weappIntrinsicElements/elements/live-player.d.mts +35 -0
  523. package/dist/weappIntrinsicElements/elements/live-pusher.d.mts +57 -0
  524. package/dist/weappIntrinsicElements/elements/map.d.mts +105 -0
  525. package/dist/weappIntrinsicElements/elements/match-media.d.mts +16 -0
  526. package/dist/weappIntrinsicElements/elements/movable-area.d.mts +26 -0
  527. package/dist/weappIntrinsicElements/elements/movable-view.d.mts +26 -0
  528. package/dist/weappIntrinsicElements/elements/navigation-bar.d.mts +15 -0
  529. package/dist/weappIntrinsicElements/elements/navigator.d.mts +25 -0
  530. package/dist/weappIntrinsicElements/elements/official-account.d.mts +13 -0
  531. package/dist/weappIntrinsicElements/elements/open-data.d.mts +15 -0
  532. package/dist/weappIntrinsicElements/elements/page-container.d.mts +25 -0
  533. package/dist/weappIntrinsicElements/elements/page-meta.d.mts +23 -0
  534. package/dist/weappIntrinsicElements/elements/picker-view-column.d.mts +18 -0
  535. package/dist/weappIntrinsicElements/elements/picker-view.d.mts +18 -0
  536. package/dist/weappIntrinsicElements/elements/picker.d.mts +23 -0
  537. package/dist/weappIntrinsicElements/elements/progress.d.mts +21 -0
  538. package/dist/weappIntrinsicElements/elements/radio-group.d.mts +13 -0
  539. package/dist/weappIntrinsicElements/elements/radio.d.mts +13 -0
  540. package/dist/weappIntrinsicElements/elements/rich-text.d.mts +17 -0
  541. package/dist/weappIntrinsicElements/elements/scroll-view.d.mts +68 -0
  542. package/dist/weappIntrinsicElements/elements/share-element.d.mts +18 -0
  543. package/dist/weappIntrinsicElements/elements/slider.d.mts +23 -0
  544. package/dist/weappIntrinsicElements/elements/slot.d.mts +10 -0
  545. package/dist/weappIntrinsicElements/elements/swiper-item.d.mts +42 -0
  546. package/dist/weappIntrinsicElements/elements/swiper.d.mts +42 -0
  547. package/dist/weappIntrinsicElements/elements/switch.d.mts +14 -0
  548. package/dist/weappIntrinsicElements/elements/template.d.mts +12 -0
  549. package/dist/weappIntrinsicElements/elements/text.d.mts +15 -0
  550. package/dist/weappIntrinsicElements/elements/textarea.d.mts +40 -0
  551. package/dist/weappIntrinsicElements/elements/video.d.mts +71 -0
  552. package/dist/weappIntrinsicElements/elements/view.d.mts +13 -0
  553. package/dist/weappIntrinsicElements/elements/voip-room.d.mts +14 -0
  554. package/dist/weappIntrinsicElements/elements/web-view.d.mts +13 -0
  555. package/dist/weappIntrinsicElements.d.mts +153 -0
  556. package/package.json +6 -6
  557. package/dist/base-BxKbbKVO.mjs +0 -1
  558. package/dist/computed-Xoi9XEUx.mjs +0 -1
  559. package/dist/dev/base-CYkvI7w8.mjs.map +0 -1
  560. package/dist/dev/computed-BxRsUJgi.mjs.map +0 -1
  561. package/dist/dev/ref-DRZC3Kc5.mjs +0 -695
  562. package/dist/dev/ref-DRZC3Kc5.mjs.map +0 -1
  563. package/dist/dev/router-DjGhTM7A.mjs +0 -739
  564. package/dist/dev/router-DjGhTM7A.mjs.map +0 -1
  565. package/dist/dev/router.mjs.map +0 -1
  566. package/dist/dev/store-HNsiQJ4d.mjs +0 -479
  567. package/dist/dev/store-HNsiQJ4d.mjs.map +0 -1
  568. package/dist/dev/template-n_iVr0ey.mjs.map +0 -1
  569. package/dist/dev/templateRef-Dyo45y5v.mjs +0 -6436
  570. package/dist/dev/templateRef-Dyo45y5v.mjs.map +0 -1
  571. package/dist/dev/toRefs-D06VmFK2.mjs.map +0 -1
  572. package/dist/dev/watch-jrgL5ald.mjs +0 -445
  573. package/dist/dev/watch-jrgL5ald.mjs.map +0 -1
  574. package/dist/index-BiHILcmb.d.mts +0 -1215
  575. package/dist/index-CCET_bCY.d.mts +0 -111
  576. package/dist/ref-D37CknuD.mjs +0 -1
  577. package/dist/router-DJOmKqXb.mjs +0 -1
  578. package/dist/store-eHrHBQiv.mjs +0 -1
  579. package/dist/template-CNzlwH-E.mjs +0 -1
  580. package/dist/templateRef-L_qeTIeS.mjs +0 -1
  581. package/dist/toRefs-CoytPyo0.mjs +0 -1
  582. package/dist/traverse-B4Ez44Gd.d.mts +0 -108
  583. package/dist/vue-types-B3N60cGV.d.mts +0 -757
  584. package/dist/watch-Bbd-gmEg.mjs +0 -1
  585. package/dist/weappIntrinsicElements-BgDtC53_.d.mts +0 -1257
@@ -1,1316 +1,9 @@
1
- import { d as reactive } from "./ref-DRZC3Kc5.mjs";
2
- import { c as getCurrentSetupContext, g as getMiniProgramGlobalObject, x as readonly } from "./base-CYkvI7w8.mjs";
3
- import { J as onReady, S as registerRouteStateSyncHandler, V as onLoad, X as onRouteDone, _ as injectGlobal, a as resolveCurrentRoute, b as installRouteStateSyncOnNativeRouter, c as normalizeQuery, d as stringifyQuery, et as onShow, f as createAbsoluteRoutePath, i as parsePathInput, it as onUnload, l as normalizeRouteParams, m as resolvePath, n as useNativeRouter$1, o as resolvePageRoute, p as isDynamicRoutePath, r as createRouteLocation, s as normalizeHash, t as useNativePageRouter$1, u as parseQuery, x as notifyRouteStateSync, y as provideGlobal } from "./router-DjGhTM7A.mjs";
4
-
5
- //#region src/routerInternal/params.ts
6
- const PATH_PARAM_TOKEN_RE = /^:(\w+)(?:\([^)]*\))?([+*?])?$/;
7
- function parsePathParamToken(segment) {
8
- var _match$;
9
- const match = PATH_PARAM_TOKEN_RE.exec(segment);
10
- if (!match) return;
11
- return {
12
- key: match[1],
13
- modifier: (_match$ = match[2]) !== null && _match$ !== void 0 ? _match$ : ""
14
- };
15
- }
16
- function normalizePathParamValues(value) {
17
- if (value === void 0) return [];
18
- if (Array.isArray(value)) return value;
19
- return [value];
20
- }
21
- function stringifyPathParamSegment(value) {
22
- return encodeURIComponent(value);
23
- }
24
- function decodeRouteParamSegment(value) {
25
- try {
26
- return decodeURIComponent(value);
27
- } catch (_unused) {
28
- return value;
29
- }
30
- }
31
- function resolveNamedRoutePath(pathTemplate, params, routeName) {
32
- const resolvedSegments = [];
33
- const consumedKeys = /* @__PURE__ */ new Set();
34
- for (const rawSegment of pathTemplate.split("/")) {
35
- if (!rawSegment) continue;
36
- const token = parsePathParamToken(rawSegment);
37
- if (!token) {
38
- resolvedSegments.push(rawSegment);
39
- continue;
40
- }
41
- const values = normalizePathParamValues(params[token.key]);
42
- if (token.modifier === "") {
43
- if (values.length !== 1) throw new Error(`Missing required param "${token.key}" for named route "${routeName}"`);
44
- consumedKeys.add(token.key);
45
- resolvedSegments.push(stringifyPathParamSegment(values[0]));
46
- continue;
47
- }
48
- if (token.modifier === "?") {
49
- if (values.length === 0) continue;
50
- if (values.length > 1) throw new Error(`Param "${token.key}" for named route "${routeName}" must be a single value`);
51
- consumedKeys.add(token.key);
52
- resolvedSegments.push(stringifyPathParamSegment(values[0]));
53
- continue;
54
- }
55
- if (token.modifier === "+") {
56
- if (values.length === 0) throw new Error(`Missing required repeatable param "${token.key}" for named route "${routeName}"`);
57
- consumedKeys.add(token.key);
58
- for (const value of values) resolvedSegments.push(stringifyPathParamSegment(value));
59
- continue;
60
- }
61
- if (values.length > 0) consumedKeys.add(token.key);
62
- for (const value of values) resolvedSegments.push(stringifyPathParamSegment(value));
63
- }
64
- return {
65
- path: resolvedSegments.join("/"),
66
- consumedKeys
67
- };
68
- }
69
- function hasNonEmptyRouteParamValue(value) {
70
- if (value === void 0) return false;
71
- if (Array.isArray(value)) return value.length > 0;
72
- return true;
73
- }
74
- function assertNoUnexpectedNamedRouteParams(params, consumedKeys, routeName) {
75
- const unexpectedKeys = Object.keys(params).filter((key) => !consumedKeys.has(key)).filter((key) => hasNonEmptyRouteParamValue(params[key]));
76
- if (unexpectedKeys.length === 0) return;
77
- throw new Error(`Unexpected params for named route "${routeName}": ${unexpectedKeys.join(", ")}`);
78
- }
79
- function resolveNamedRouteLocation(to, lookup, paramsMode) {
80
- const routeName = to.name;
81
- if (typeof routeName !== "string" || !routeName) return to;
82
- if (to.path !== void 0 || to.fullPath !== void 0) return to;
83
- const routeRecord = lookup.recordByName.get(routeName);
84
- if (!routeRecord) throw new Error(`Named route "${routeName}" is not defined in createRouter({ routes | namedRoutes })`);
85
- const params = to.params ? normalizeRouteParams(to.params) : {};
86
- const resolvedResult = resolveNamedRoutePath(routeRecord.path, params, routeName);
87
- if (paramsMode === "strict") assertNoUnexpectedNamedRouteParams(params, resolvedResult.consumedKeys, routeName);
88
- return {
89
- ...to,
90
- path: resolvedResult.path ? `/${resolvedResult.path}` : "/",
91
- params
92
- };
93
- }
94
-
95
- //#endregion
96
- //#region src/routerInternal/matching.ts
97
- function splitRoutePathSegments(path) {
98
- return path.split("/").filter(Boolean);
99
- }
100
- function listRouteRecordMatchPaths(record) {
101
- return [record.path, ...record.aliasPaths];
102
- }
103
- function resolveMatchedRouteRecordChain(record, lookup) {
104
- const matchedRecords = [];
105
- const visitedNames = /* @__PURE__ */ new Set();
106
- let currentRecord = record;
107
- while (currentRecord) {
108
- if (visitedNames.has(currentRecord.name)) break;
109
- visitedNames.add(currentRecord.name);
110
- matchedRecords.unshift(currentRecord);
111
- if (!currentRecord.parentName) break;
112
- currentRecord = lookup.recordByName.get(currentRecord.parentName);
113
- }
114
- return matchedRecords;
115
- }
116
- function mergeMatchedRouteMeta(matchedRecords) {
117
- let mergedRouteMeta;
118
- for (const matchedRecord of matchedRecords) {
119
- if (!matchedRecord.meta) continue;
120
- if (!mergedRouteMeta) mergedRouteMeta = {};
121
- Object.assign(mergedRouteMeta, matchedRecord.meta);
122
- }
123
- return mergedRouteMeta;
124
- }
125
- function collectRouteNamesForRemoval(routeName, recordByName) {
126
- const namesToRemove = /* @__PURE__ */ new Set();
127
- if (!recordByName.has(routeName)) return namesToRemove;
128
- namesToRemove.add(routeName);
129
- let expanded = true;
130
- while (expanded) {
131
- expanded = false;
132
- for (const [name, record] of recordByName.entries()) {
133
- if (!record.parentName || namesToRemove.has(name)) continue;
134
- if (namesToRemove.has(record.parentName)) {
135
- namesToRemove.add(name);
136
- expanded = true;
137
- }
138
- }
139
- }
140
- return namesToRemove;
141
- }
142
- function buildRouteParamsFromMatch(matchValues) {
143
- const params = {};
144
- for (const [key, values] of matchValues.entries()) {
145
- if (values.length === 0) continue;
146
- params[key] = values.length === 1 ? values[0] : values;
147
- }
148
- return params;
149
- }
150
- function matchRoutePathParams(pathTemplate, targetPath) {
151
- const templateSegments = splitRoutePathSegments(pathTemplate);
152
- const targetSegments = splitRoutePathSegments(targetPath);
153
- const matchedValues = /* @__PURE__ */ new Map();
154
- const pushValue = (key, value) => {
155
- const previous = matchedValues.get(key);
156
- if (previous) {
157
- previous.push(value);
158
- return;
159
- }
160
- matchedValues.set(key, [value]);
161
- };
162
- const popValue = (key) => {
163
- const previous = matchedValues.get(key);
164
- if (!previous || previous.length === 0) return;
165
- previous.pop();
166
- if (previous.length === 0) matchedValues.delete(key);
167
- };
168
- const consumeRepeatableToken = (key, startIndex, count) => {
169
- for (let index = 0; index < count; index += 1) pushValue(key, decodeRouteParamSegment(targetSegments[startIndex + index]));
170
- return () => {
171
- for (let index = 0; index < count; index += 1) popValue(key);
172
- };
173
- };
174
- const matchRecursively = (templateIndex, targetIndex) => {
175
- if (templateIndex >= templateSegments.length) return targetIndex >= targetSegments.length;
176
- const templateSegment = templateSegments[templateIndex];
177
- const token = parsePathParamToken(templateSegment);
178
- if (!token) {
179
- if (targetIndex >= targetSegments.length || templateSegment !== targetSegments[targetIndex]) return false;
180
- return matchRecursively(templateIndex + 1, targetIndex + 1);
181
- }
182
- if (token.modifier === "") {
183
- if (targetIndex >= targetSegments.length) return false;
184
- pushValue(token.key, decodeRouteParamSegment(targetSegments[targetIndex]));
185
- const matched = matchRecursively(templateIndex + 1, targetIndex + 1);
186
- if (!matched) popValue(token.key);
187
- return matched;
188
- }
189
- if (token.modifier === "?") {
190
- if (targetIndex < targetSegments.length) {
191
- pushValue(token.key, decodeRouteParamSegment(targetSegments[targetIndex]));
192
- if (matchRecursively(templateIndex + 1, targetIndex + 1)) return true;
193
- popValue(token.key);
194
- }
195
- return matchRecursively(templateIndex + 1, targetIndex);
196
- }
197
- const minimumCount = token.modifier === "+" ? 1 : 0;
198
- const maximumCount = targetSegments.length - targetIndex;
199
- for (let count = maximumCount; count >= minimumCount; count -= 1) {
200
- const rollback = consumeRepeatableToken(token.key, targetIndex, count);
201
- if (matchRecursively(templateIndex + 1, targetIndex + count)) return true;
202
- rollback();
203
- }
204
- return false;
205
- };
206
- if (!matchRecursively(0, 0)) return;
207
- return buildRouteParamsFromMatch(matchedValues);
208
- }
209
- function resolveMatchedRouteRecord(target, lookup) {
210
- if (target.name) {
211
- const byName = lookup.recordByName.get(target.name);
212
- if (byName) return {
213
- record: byName,
214
- matchedRecords: resolveMatchedRouteRecordChain(byName, lookup)
215
- };
216
- }
217
- const staticNamedRoute = lookup.nameByStaticPath.get(target.path);
218
- if (staticNamedRoute) {
219
- const record = lookup.recordByName.get(staticNamedRoute);
220
- if (record) return {
221
- record,
222
- matchedRecords: resolveMatchedRouteRecordChain(record, lookup),
223
- matchedPath: target.path
224
- };
225
- }
226
- for (const record of lookup.recordByName.values()) for (const routePath of listRouteRecordMatchPaths(record)) {
227
- if (!isDynamicRoutePath(routePath)) continue;
228
- const matchedParams = matchRoutePathParams(routePath, target.path);
229
- if (!matchedParams) continue;
230
- return {
231
- record,
232
- matchedRecords: resolveMatchedRouteRecordChain(record, lookup),
233
- matchedPath: routePath,
234
- params: matchedParams
235
- };
236
- }
237
- }
238
-
239
- //#endregion
240
- //#region src/routerInternal/recordsWarnings.ts
241
- function warnRouteConfig(message) {
242
- if (typeof console === "undefined" || typeof console.warn !== "function") return;
243
- console.warn(`[wevu/router] ${message}`);
244
- }
245
- function formatRoutePathForWarning(path) {
246
- const normalizedPath = resolvePath(path, "");
247
- if (!normalizedPath) return "/";
248
- return createAbsoluteRoutePath(normalizedPath);
249
- }
250
- function hasCircularChildrenReference(routeRecord, ancestorRecords = /* @__PURE__ */ new Set()) {
251
- if (ancestorRecords.has(routeRecord)) return true;
252
- if (!Array.isArray(routeRecord.children) || routeRecord.children.length === 0) return false;
253
- const nextAncestorRecords = new Set(ancestorRecords);
254
- nextAncestorRecords.add(routeRecord);
255
- for (const childRecord of routeRecord.children) if (hasCircularChildrenReference(childRecord, nextAncestorRecords)) return true;
256
- return false;
257
- }
258
- function assertValidAddRouteInput(routeRecord) {
259
- const routeName = typeof routeRecord.name === "string" ? routeRecord.name.trim() : "";
260
- if (!routeName) throw new Error("Route name is required when adding a named route");
261
- if (typeof routeRecord.path !== "string" || !routeRecord.path) throw new Error(`Route path is required when adding named route "${routeName}"`);
262
- if (hasCircularChildrenReference(routeRecord)) throw new Error(`Circular children reference detected when adding named route "${routeName}"`);
263
- }
264
- function warnDuplicateRouteEntries(routeEntries) {
265
- const latestRouteInfoByName = /* @__PURE__ */ new Map();
266
- const duplicateMessages = [];
267
- for (const routeEntry of routeEntries) {
268
- var _routeEntry$source;
269
- const routeName = typeof routeEntry.route.name === "string" ? routeEntry.route.name.trim() : "";
270
- if (!routeName) continue;
271
- const currentSource = (_routeEntry$source = routeEntry.source) !== null && _routeEntry$source !== void 0 ? _routeEntry$source : "namedRoutes";
272
- const currentPath = formatRoutePathForWarning(routeEntry.route.path);
273
- const previousInfo = latestRouteInfoByName.get(routeName);
274
- if (previousInfo) duplicateMessages.push(`"${routeName}" (${previousInfo.source}:${previousInfo.path} -> ${currentSource}:${currentPath})`);
275
- latestRouteInfoByName.set(routeName, {
276
- source: currentSource,
277
- path: currentPath
278
- });
279
- }
280
- if (duplicateMessages.length === 0) return;
281
- warnRouteConfig(`duplicate route names detected, later entries override earlier ones: ${duplicateMessages.join(", ")}`);
282
- }
283
-
284
- //#endregion
285
- //#region src/routerInternal/records.ts
286
- function normalizeBeforeEnterGuards(beforeEnter) {
287
- if (!beforeEnter) return [];
288
- if (Array.isArray(beforeEnter)) return beforeEnter;
289
- return [beforeEnter];
290
- }
291
- function resolveRouteRecordName(route, normalizedPath, source = "namedRoutes") {
292
- if (typeof route.name === "string" && route.name.trim()) return route.name.trim();
293
- if (source === "routes") return normalizedPath || "/";
294
- return "";
295
- }
296
- function normalizeRouteRecordAliasPaths(alias, normalizedPath) {
297
- if (!alias) return [];
298
- const aliasList = Array.isArray(alias) ? alias : [alias];
299
- const normalizedAliasPaths = [];
300
- for (const aliasPath of aliasList) {
301
- if (typeof aliasPath !== "string") continue;
302
- const normalizedAliasPath = resolvePath(aliasPath, "");
303
- if (!normalizedAliasPath || normalizedAliasPath === normalizedPath) continue;
304
- if (!normalizedAliasPaths.includes(normalizedAliasPath)) normalizedAliasPaths.push(normalizedAliasPath);
305
- }
306
- return normalizedAliasPaths;
307
- }
308
- function normalizeRouteRecordRaw(route, parentName, source = "namedRoutes") {
309
- const normalizedPath = resolvePath(route.path, "");
310
- if (!normalizedPath && route.path !== "/") return;
311
- const routeName = resolveRouteRecordName(route, normalizedPath, source);
312
- if (!routeName) return;
313
- return {
314
- name: routeName,
315
- path: normalizedPath,
316
- aliasPaths: normalizeRouteRecordAliasPaths(route.alias, normalizedPath),
317
- parentName,
318
- meta: route.meta,
319
- beforeEnterGuards: normalizeBeforeEnterGuards(route.beforeEnter),
320
- redirect: route.redirect
321
- };
322
- }
323
- function normalizeNestedRoutePath(path, parentPath) {
324
- if (!parentPath || path.startsWith("/")) return resolvePath(path, "");
325
- return resolvePath(`${createAbsoluteRoutePath(parentPath)}/${path}`, "");
326
- }
327
- function normalizeAliasInputList(alias) {
328
- if (!alias) return [];
329
- if (Array.isArray(alias)) return alias.filter((item) => typeof item === "string" && item.length > 0);
330
- return typeof alias === "string" && alias.length > 0 ? [alias] : [];
331
- }
332
- function mergeAliasPaths(aliasPaths) {
333
- const mergedAliasPaths = [];
334
- for (const aliasPath of aliasPaths) {
335
- if (!aliasPath || mergedAliasPaths.includes(aliasPath)) continue;
336
- mergedAliasPaths.push(aliasPath);
337
- }
338
- return mergedAliasPaths;
339
- }
340
- function createRouteRecordAliasValue(aliasPaths) {
341
- if (aliasPaths.length === 0) return;
342
- if (aliasPaths.length === 1) return createAbsoluteRoutePath(aliasPaths[0]);
343
- return aliasPaths.map((aliasPath) => createAbsoluteRoutePath(aliasPath));
344
- }
345
- function flattenNamedRouteRecords(records, parentPath, parentName, parentAliasPaths = [], source, pathPrefix = "namedRoutes", ancestorRecords = /* @__PURE__ */ new Set()) {
346
- const flattenedRecords = [];
347
- for (const [index, record] of records.entries()) {
348
- const routeConfigPath = `${pathPrefix}[${index}]`;
349
- if (ancestorRecords.has(record)) {
350
- warnRouteConfig(`ignored route record at ${routeConfigPath}: detected circular children reference`);
351
- continue;
352
- }
353
- if (typeof record.path !== "string" || !record.path) {
354
- warnRouteConfig(`ignored route record "${typeof (record === null || record === void 0 ? void 0 : record.name) === "string" ? record.name.trim() : ""}" at ${routeConfigPath}: route path is required`);
355
- continue;
356
- }
357
- const normalizedPath = normalizeNestedRoutePath(record.path, parentPath);
358
- const routeName = resolveRouteRecordName(record, normalizedPath, source);
359
- if (!routeName) {
360
- warnRouteConfig(`ignored route record at ${routeConfigPath}: route name is required`);
361
- continue;
362
- }
363
- const normalizedDirectAliasPaths = [];
364
- const directAliasByNormalizedPath = /* @__PURE__ */ new Map();
365
- for (const rawAliasPath of normalizeAliasInputList(record.alias)) {
366
- const normalizedAliasPath = normalizeNestedRoutePath(rawAliasPath, parentPath);
367
- if (!normalizedAliasPath) continue;
368
- if (normalizedAliasPath === normalizedPath) {
369
- warnRouteConfig(`ignored alias "${createAbsoluteRoutePath(normalizedAliasPath)}" for route "${routeName}" at ${routeConfigPath}: alias is same as route path`);
370
- continue;
371
- }
372
- const duplicateAliasPath = directAliasByNormalizedPath.get(normalizedAliasPath);
373
- if (duplicateAliasPath) {
374
- warnRouteConfig(`ignored duplicate alias "${createAbsoluteRoutePath(normalizedAliasPath)}" for route "${routeName}" at ${routeConfigPath}: already declared by "${duplicateAliasPath}"`);
375
- continue;
376
- }
377
- directAliasByNormalizedPath.set(normalizedAliasPath, rawAliasPath);
378
- normalizedDirectAliasPaths.push(normalizedAliasPath);
379
- }
380
- const normalizedInheritedAliasPaths = record.path.startsWith("/") ? [] : parentAliasPaths.map((parentAliasPath) => normalizeNestedRoutePath(record.path, parentAliasPath)).filter(Boolean).filter((aliasPath) => aliasPath !== normalizedPath);
381
- const normalizedAliasPaths = mergeAliasPaths([...normalizedDirectAliasPaths, ...normalizedInheritedAliasPaths]);
382
- const normalizedRecord = {
383
- name: routeName,
384
- path: normalizedPath ? createAbsoluteRoutePath(normalizedPath) : "/",
385
- alias: createRouteRecordAliasValue(normalizedAliasPaths),
386
- meta: record.meta,
387
- beforeEnter: record.beforeEnter,
388
- redirect: record.redirect
389
- };
390
- flattenedRecords.push({
391
- route: normalizedRecord,
392
- parentName,
393
- source
394
- });
395
- if (Array.isArray(record.children) && record.children.length > 0) {
396
- const nextAncestorRecords = new Set(ancestorRecords);
397
- nextAncestorRecords.add(record);
398
- flattenedRecords.push(...flattenNamedRouteRecords(record.children, normalizedPath, routeName, normalizedAliasPaths, source, `${routeConfigPath}.children`, nextAncestorRecords));
399
- }
400
- }
401
- return flattenedRecords;
402
- }
403
- function normalizeNamedRouteEntries(namedRoutes, source = "namedRoutes") {
404
- if (!namedRoutes) return [];
405
- if (Array.isArray(namedRoutes)) return flattenNamedRouteRecords(namedRoutes, void 0, void 0, [], source, source);
406
- const normalizedEntries = [];
407
- for (const [rawName, rawPath] of Object.entries(namedRoutes)) {
408
- const routeName = typeof rawName === "string" ? rawName.trim() : "";
409
- if (!routeName) {
410
- warnRouteConfig(`ignored route record at ${source}: route name is required`);
411
- continue;
412
- }
413
- if (typeof rawPath !== "string" || !rawPath) {
414
- warnRouteConfig(`ignored route record "${routeName}" at ${source}: route path is required`);
415
- continue;
416
- }
417
- normalizedEntries.push({
418
- route: {
419
- name: routeName,
420
- path: rawPath
421
- },
422
- source
423
- });
424
- }
425
- return normalizedEntries;
426
- }
427
- function resolveRouteOptionEntries(options) {
428
- return [...normalizeNamedRouteEntries(options.routes, "routes"), ...normalizeNamedRouteEntries(options.namedRoutes, "namedRoutes")];
429
- }
430
- function createNamedRouteNameByStaticPath(recordByName) {
431
- const nameByStaticPath = /* @__PURE__ */ new Map();
432
- for (const [name, record] of recordByName.entries()) {
433
- if (!isDynamicRoutePath(record.path) && !nameByStaticPath.has(record.path)) nameByStaticPath.set(record.path, name);
434
- for (const aliasPath of record.aliasPaths) if (!isDynamicRoutePath(aliasPath) && !nameByStaticPath.has(aliasPath)) nameByStaticPath.set(aliasPath, name);
435
- }
436
- return nameByStaticPath;
437
- }
438
- function createNamedRouteLookup(routeEntries) {
439
- const recordByName = /* @__PURE__ */ new Map();
440
- for (const routeRecord of routeEntries) {
441
- const normalizedRecord = normalizeRouteRecordRaw(routeRecord.route, routeRecord.parentName, routeRecord.source);
442
- if (!normalizedRecord) continue;
443
- recordByName.set(normalizedRecord.name, normalizedRecord);
444
- }
445
- return {
446
- recordByName,
447
- nameByStaticPath: createNamedRouteNameByStaticPath(recordByName)
448
- };
449
- }
450
-
451
- //#endregion
452
- //#region src/routerInternal/snapshots.ts
453
- function cloneRouteMeta(meta) {
454
- if (!meta) return;
455
- return { ...meta };
456
- }
457
- function freezeRouteRecordRawSnapshot(routeRecord) {
458
- const snapshot = {
459
- name: routeRecord.name,
460
- path: routeRecord.path
461
- };
462
- if (routeRecord.meta !== void 0) snapshot.meta = cloneRouteMeta(routeRecord.meta);
463
- if (Array.isArray(routeRecord.alias)) snapshot.alias = Object.freeze(routeRecord.alias.slice());
464
- else if (routeRecord.alias !== void 0) snapshot.alias = routeRecord.alias;
465
- if (Array.isArray(routeRecord.beforeEnter)) snapshot.beforeEnter = Object.freeze(routeRecord.beforeEnter.slice());
466
- else if (routeRecord.beforeEnter !== void 0) snapshot.beforeEnter = routeRecord.beforeEnter;
467
- if (routeRecord.redirect !== void 0) snapshot.redirect = routeRecord.redirect;
468
- return Object.freeze(snapshot);
469
- }
470
- function createRouterOptionsSnapshot(normalizedTabBarEntries, normalizedNamedRoutes, paramsMode, maxRedirects, routeResolveCodec, rejectOnError) {
471
- const tabBarEntriesSnapshot = Object.freeze(normalizedTabBarEntries.map((path) => createAbsoluteRoutePath(path)));
472
- const routesSnapshot = Object.freeze(normalizedNamedRoutes.map(freezeRouteRecordRawSnapshot));
473
- return Object.freeze({
474
- tabBarEntries: tabBarEntriesSnapshot,
475
- routes: routesSnapshot,
476
- namedRoutes: routesSnapshot,
477
- paramsMode,
478
- maxRedirects,
479
- parseQuery: routeResolveCodec.parseQuery,
480
- stringifyQuery: routeResolveCodec.stringifyQuery,
481
- rejectOnError
482
- });
483
- }
484
- function normalizeRouteRecordMatched(record, matchedPath) {
485
- const matchedRecord = {
486
- name: record.name,
487
- path: createAbsoluteRoutePath(record.path)
488
- };
489
- const normalizedMatchedPath = typeof matchedPath === "string" && matchedPath ? createAbsoluteRoutePath(resolvePath(matchedPath, "")) : void 0;
490
- if (normalizedMatchedPath && normalizedMatchedPath !== matchedRecord.path) matchedRecord.aliasPath = normalizedMatchedPath;
491
- if (record.meta !== void 0) matchedRecord.meta = cloneRouteMeta(record.meta);
492
- return matchedRecord;
493
- }
494
- function cloneRouteRecordMatchedList(matched) {
495
- if (!matched) return;
496
- return matched.map((record) => ({
497
- name: record.name,
498
- path: record.path,
499
- aliasPath: record.aliasPath,
500
- meta: cloneRouteMeta(record.meta)
501
- }));
502
- }
503
- function cloneLocationQuery(query) {
504
- const cloned = {};
505
- for (const key of Object.keys(query)) {
506
- const value = query[key];
507
- cloned[key] = Array.isArray(value) ? value.slice() : value;
508
- }
509
- return cloned;
510
- }
511
- function cloneRouteParams(params) {
512
- const cloned = {};
513
- for (const key of Object.keys(params)) {
514
- const value = params[key];
515
- cloned[key] = Array.isArray(value) ? value.slice() : value;
516
- }
517
- return cloned;
518
- }
519
- function cloneRouteLocationRedirectedFrom(redirectedFrom) {
520
- if (!redirectedFrom) return;
521
- const cloned = {
522
- path: redirectedFrom.path,
523
- fullPath: redirectedFrom.fullPath,
524
- query: cloneLocationQuery(redirectedFrom.query),
525
- hash: redirectedFrom.hash,
526
- params: cloneRouteParams(redirectedFrom.params)
527
- };
528
- if (redirectedFrom.name !== void 0) cloned.name = redirectedFrom.name;
529
- if (redirectedFrom.meta !== void 0) cloned.meta = cloneRouteMeta(redirectedFrom.meta);
530
- if (redirectedFrom.href !== void 0) cloned.href = redirectedFrom.href;
531
- if (redirectedFrom.matched !== void 0) cloned.matched = cloneRouteRecordMatchedList(redirectedFrom.matched);
532
- return cloned;
533
- }
534
- function createRedirectedFromSnapshot(route) {
535
- const snapshot = {
536
- path: route.path,
537
- fullPath: route.fullPath,
538
- query: cloneLocationQuery(route.query),
539
- hash: route.hash,
540
- params: cloneRouteParams(route.params)
541
- };
542
- if (route.name !== void 0) snapshot.name = route.name;
543
- if (route.meta !== void 0) snapshot.meta = cloneRouteMeta(route.meta);
544
- if (route.href !== void 0) snapshot.href = route.href;
545
- if (route.matched !== void 0) snapshot.matched = cloneRouteRecordMatchedList(route.matched);
546
- return snapshot;
547
- }
548
- function snapshotRouteLocation(route) {
549
- const snapshot = {
550
- path: route.path,
551
- fullPath: route.fullPath,
552
- query: cloneLocationQuery(route.query),
553
- hash: route.hash,
554
- params: cloneRouteParams(route.params)
555
- };
556
- if (route.meta !== void 0) snapshot.meta = cloneRouteMeta(route.meta);
557
- if (route.href !== void 0) snapshot.href = route.href;
558
- if (route.matched !== void 0) snapshot.matched = cloneRouteRecordMatchedList(route.matched);
559
- if (route.redirectedFrom !== void 0) snapshot.redirectedFrom = cloneRouteLocationRedirectedFrom(route.redirectedFrom);
560
- if (route.name !== void 0) snapshot.name = route.name;
561
- return snapshot;
562
- }
563
- function createNativeRouteUrl(target, queryStringifier = stringifyQuery) {
564
- const basePath = createAbsoluteRoutePath(target.path);
565
- const queryString = queryStringifier(target.query);
566
- return queryString ? `${basePath}?${queryString}` : basePath;
567
- }
568
- function hasLocationQuery(query) {
569
- return Object.keys(query).length > 0;
570
- }
571
-
572
- //#endregion
573
- //#region src/router/instance.ts
574
- const ROUTER_INSTANCE_KEY = Symbol("wevu.router.instance");
575
- let activeRouter;
576
- function setActiveRouter(router) {
577
- activeRouter = router;
578
- provideGlobal(ROUTER_INSTANCE_KEY, router);
579
- }
580
- function getActiveRouter() {
581
- var _activeRouter;
582
- return (_activeRouter = activeRouter) !== null && _activeRouter !== void 0 ? _activeRouter : injectGlobal(ROUTER_INSTANCE_KEY, void 0);
583
- }
584
-
585
- //#endregion
586
- //#region src/router/types.ts
587
- const NavigationFailureType = {
588
- unknown: 1,
589
- aborted: 4,
590
- cancelled: 8,
591
- duplicated: 16
592
- };
593
-
594
- //#endregion
595
- //#region src/router/navigationCore.ts
596
- const DUPLICATED_RE = /already|same|duplicat|重复/;
597
- const CANCELLED_RE = /cancel|取消/;
598
- const ABORTED_RE = /abort|interrupt|中断/;
599
- function normalizeNavigationErrorMessage(error) {
600
- if (typeof error === "string") return error;
601
- if (error && typeof error === "object") {
602
- const message = error.errMsg;
603
- if (typeof message === "string") return message;
604
- if (error instanceof Error) return error.message;
605
- }
606
- return "";
607
- }
608
- function resolveNavigationFailureType(error) {
609
- const normalizedMessage = normalizeNavigationErrorMessage(error).toLowerCase();
610
- if (DUPLICATED_RE.test(normalizedMessage)) return NavigationFailureType.duplicated;
611
- if (CANCELLED_RE.test(normalizedMessage)) return NavigationFailureType.cancelled;
612
- if (ABORTED_RE.test(normalizedMessage)) return NavigationFailureType.aborted;
613
- return NavigationFailureType.unknown;
614
- }
615
- function createNavigationFailure(type, to, from, cause) {
616
- const message = normalizeNavigationErrorMessage(cause) || "Navigation failed";
617
- const error = new Error(message);
618
- error.__wevuNavigationFailure = true;
619
- error.type = type;
620
- error.to = to;
621
- error.from = from;
622
- error.cause = cause;
623
- return error;
624
- }
625
- function isNavigationFailure(error, type) {
626
- if (!error || typeof error !== "object") return false;
627
- const navigationError = error;
628
- if (navigationError.__wevuNavigationFailure !== true) return false;
629
- if (type === void 0) return true;
630
- return navigationError.type === type;
631
- }
632
- function isNavigationRedirectCandidate(value) {
633
- if (!value || typeof value !== "object") return false;
634
- return "to" in value;
635
- }
636
- function isRouteLocationRawCandidate(value) {
637
- if (typeof value === "string") return true;
638
- if (!value || typeof value !== "object") return false;
639
- const candidate = value;
640
- return "path" in candidate || "fullPath" in candidate || "query" in candidate || "hash" in candidate || "name" in candidate || "params" in candidate;
641
- }
642
- async function runNavigationGuards(guards, context, resolveRoute) {
643
- for (const guard of guards) try {
644
- const result = await guard(context.to, context.from, context);
645
- if (isNavigationFailure(result)) return {
646
- status: "failure",
647
- failure: result
648
- };
649
- if (result === false) return {
650
- status: "failure",
651
- failure: createNavigationFailure(NavigationFailureType.aborted, context.to, context.from, "Navigation aborted by guard")
652
- };
653
- if (isNavigationRedirectCandidate(result)) {
654
- if (!context.to) return {
655
- status: "failure",
656
- failure: createNavigationFailure(NavigationFailureType.aborted, context.to, context.from, "Redirect is not supported in back navigation guards")
657
- };
658
- return {
659
- status: "redirect",
660
- target: resolveRoute(result.to, context.to.path),
661
- replace: result.replace
662
- };
663
- }
664
- if (isRouteLocationRawCandidate(result)) {
665
- if (!context.to) return {
666
- status: "failure",
667
- failure: createNavigationFailure(NavigationFailureType.aborted, context.to, context.from, "Redirect is not supported in back navigation guards")
668
- };
669
- return {
670
- status: "redirect",
671
- target: resolveRoute(result, context.to.path)
672
- };
673
- }
674
- } catch (error) {
675
- return {
676
- status: "failure",
677
- failure: createNavigationFailure(NavigationFailureType.aborted, context.to, context.from, error)
678
- };
679
- }
680
- return { status: "continue" };
681
- }
682
- function executeNavigationMethod(method, options, to, from) {
683
- return new Promise((resolve) => {
684
- let settled = false;
685
- const finalize = (result) => {
686
- if (settled) return;
687
- settled = true;
688
- resolve(result);
689
- };
690
- try {
691
- const maybePromise = method({
692
- ...options,
693
- success: () => finalize(),
694
- fail: (error) => {
695
- finalize(createNavigationFailure(resolveNavigationFailureType(error), to, from, error));
696
- }
697
- });
698
- if (maybePromise && typeof maybePromise.then === "function") maybePromise.then(() => finalize(), (error) => finalize(createNavigationFailure(resolveNavigationFailureType(error), to, from, error)));
699
- } catch (error) {
700
- finalize(createNavigationFailure(resolveNavigationFailureType(error), to, from, error));
701
- }
702
- });
703
- }
704
- async function runAfterEachHooks(hooks, context) {
705
- for (const hook of hooks) try {
706
- await hook(context.to, context.from, context.failure, context);
707
- } catch (_unused) {}
708
- }
709
- async function runNavigationErrorHooks(handlers, error, context) {
710
- for (const handler of handlers) try {
711
- await handler(error, context);
712
- } catch (_unused2) {}
713
- }
714
- function isNativeFailureLikeError(value) {
715
- if (!value || typeof value !== "object") return false;
716
- return typeof value.errMsg === "string";
717
- }
718
- function shouldEmitNavigationError(failure) {
719
- if (failure.type === NavigationFailureType.unknown) return true;
720
- if (failure.cause instanceof Error) return true;
721
- if (failure.type === NavigationFailureType.aborted && failure.cause !== void 0) {
722
- if (typeof failure.cause === "string") return false;
723
- if (isNativeFailureLikeError(failure.cause)) return false;
724
- return true;
725
- }
726
- return false;
727
- }
728
-
729
- //#endregion
730
- //#region src/router/navigationResult.ts
731
- function createNavigationRunResult(mode, from, to, failure) {
732
- return {
733
- mode,
734
- from,
735
- to,
736
- failure
737
- };
738
- }
739
- function createNavigationResultController(options) {
740
- const { afterEachHooks, errorHandlers, nativeRouter, rejectOnError } = options;
741
- async function emitNavigationAfterEach(result) {
742
- await runAfterEachHooks(afterEachHooks, {
743
- mode: result.mode,
744
- to: result.to,
745
- from: result.from,
746
- nativeRouter,
747
- failure: result.failure
748
- });
749
- if (result.failure && shouldEmitNavigationError(result.failure)) {
750
- var _result$failure$cause;
751
- await runNavigationErrorHooks(errorHandlers, (_result$failure$cause = result.failure.cause) !== null && _result$failure$cause !== void 0 ? _result$failure$cause : result.failure, {
752
- mode: result.mode,
753
- to: result.to,
754
- from: result.from,
755
- nativeRouter,
756
- failure: result.failure
757
- });
758
- }
759
- }
760
- function shouldRejectNavigationFailure(failure) {
761
- return rejectOnError && shouldEmitNavigationError(failure);
762
- }
763
- async function settleNavigationResult(result) {
764
- if (!result.failure) notifyRouteStateSync(result.to ? { route: result.to } : void 0);
765
- await emitNavigationAfterEach(result);
766
- if (result.failure && shouldRejectNavigationFailure(result.failure)) throw result.failure;
767
- return result.failure;
768
- }
769
- return { settleNavigationResult };
770
- }
771
-
772
- //#endregion
773
- //#region src/router/navigationTargetHelpers.ts
774
- function createDuplicatedFailure(target, from) {
775
- return createNavigationFailure(NavigationFailureType.duplicated, target, from, "Avoided redundant navigation to current location");
776
- }
777
- function createTabBarQueryFailure(target, from) {
778
- return createNavigationFailure(NavigationFailureType.aborted, target, from, "switchTab does not support query parameters");
779
- }
780
- function createTooManyRedirectsFailure(target, from, maxRedirects) {
781
- return createNavigationFailure(NavigationFailureType.aborted, target, from, `Navigation redirected more than ${maxRedirects} times`);
782
- }
783
- function createHashOnlyNavigationFailure(target, from) {
784
- return createNavigationFailure(NavigationFailureType.aborted, target, from, "Hash-only navigation is not supported in mini-program router");
785
- }
786
- function createForwardNotSupportedFailure(from) {
787
- return createNavigationFailure(NavigationFailureType.aborted, void 0, from, "Forward navigation is not supported in mini-program router");
788
- }
789
- function applyRedirectedFrom(redirectedTarget, currentTarget) {
790
- redirectedTarget.redirectedFrom = currentTarget.redirectedFrom ? cloneRouteLocationRedirectedFrom(currentTarget.redirectedFrom) : createRedirectedFromSnapshot(currentTarget);
791
- }
792
- async function resolveRouteRecordRedirect(redirect, to, from, resolveWithCodec) {
793
- const redirectResult = typeof redirect === "function" ? await redirect(to, from) : redirect;
794
- if (isNavigationRedirectCandidate(redirectResult)) return {
795
- target: resolveWithCodec(redirectResult.to, to.path),
796
- replace: redirectResult.replace
797
- };
798
- return {
799
- target: resolveWithCodec(redirectResult, to.path),
800
- replace: true
801
- };
802
- }
803
-
804
- //#endregion
805
- //#region src/router/navigationTarget.ts
806
- async function navigateWithTarget(options) {
807
- const { mode, target, from, nativeRouter, routeResolveCodec, namedRouteLookup, beforeEachGuards, beforeResolveGuards, maxRedirects, tabBarPathSet, resolveWithCodec } = options;
808
- let currentTarget = target;
809
- let currentMode = mode;
810
- let redirectCount = 0;
811
- while (true) {
812
- var _matchedRouteResult$m;
813
- const tabBarTarget = tabBarPathSet.has(currentTarget.path);
814
- if (createNativeRouteUrl(currentTarget, routeResolveCodec.stringifyQuery) === createNativeRouteUrl(from, routeResolveCodec.stringifyQuery) && currentTarget.hash !== from.hash) return createNavigationRunResult(currentMode, from, currentTarget, createHashOnlyNavigationFailure(currentTarget, from));
815
- if (tabBarTarget ? currentTarget.path === from.path : currentTarget.fullPath === from.fullPath) return createNavigationRunResult(currentMode, from, currentTarget, createDuplicatedFailure(currentTarget, from));
816
- if (tabBarTarget && hasLocationQuery(currentTarget.query)) return createNavigationRunResult(currentMode, from, currentTarget, createTabBarQueryFailure(currentTarget, from));
817
- const beforeEachResult = await runNavigationGuards(beforeEachGuards, {
818
- mode: currentMode,
819
- to: currentTarget,
820
- from,
821
- nativeRouter
822
- }, resolveWithCodec);
823
- if (beforeEachResult.status === "failure") return createNavigationRunResult(currentMode, from, currentTarget, beforeEachResult.failure);
824
- if (beforeEachResult.status === "redirect") {
825
- const redirectedTarget = beforeEachResult.target;
826
- const redirectedMode = beforeEachResult.replace === true ? "replace" : beforeEachResult.replace === false ? "push" : currentMode;
827
- if (redirectedTarget.fullPath !== currentTarget.fullPath || redirectedMode !== currentMode) {
828
- applyRedirectedFrom(redirectedTarget, currentTarget);
829
- currentTarget = redirectedTarget;
830
- currentMode = redirectedMode;
831
- redirectCount += 1;
832
- if (redirectCount > maxRedirects) return createNavigationRunResult(currentMode, from, currentTarget, createTooManyRedirectsFailure(currentTarget, from, maxRedirects));
833
- continue;
834
- }
835
- }
836
- const matchedRouteResult = resolveMatchedRouteRecord(currentTarget, namedRouteLookup);
837
- const matchedRouteRecords = (_matchedRouteResult$m = matchedRouteResult === null || matchedRouteResult === void 0 ? void 0 : matchedRouteResult.matchedRecords) !== null && _matchedRouteResult$m !== void 0 ? _matchedRouteResult$m : [];
838
- let redirectedByRouteRecord = false;
839
- for (const matchedRouteRecord of matchedRouteRecords) {
840
- if (matchedRouteRecord.redirect === void 0) continue;
841
- let redirectedByRecord;
842
- try {
843
- redirectedByRecord = await resolveRouteRecordRedirect(matchedRouteRecord.redirect, currentTarget, from, resolveWithCodec);
844
- } catch (error) {
845
- return createNavigationRunResult(currentMode, from, currentTarget, createNavigationFailure(NavigationFailureType.aborted, currentTarget, from, error));
846
- }
847
- const redirectedMode = redirectedByRecord.replace === false ? "push" : "replace";
848
- const redirectedTarget = redirectedByRecord.target;
849
- if (redirectedTarget.fullPath !== currentTarget.fullPath || redirectedMode !== currentMode) {
850
- applyRedirectedFrom(redirectedTarget, currentTarget);
851
- currentTarget = redirectedTarget;
852
- currentMode = redirectedMode;
853
- redirectCount += 1;
854
- if (redirectCount > maxRedirects) return createNavigationRunResult(currentMode, from, currentTarget, createTooManyRedirectsFailure(currentTarget, from, maxRedirects));
855
- redirectedByRouteRecord = true;
856
- break;
857
- }
858
- }
859
- if (redirectedByRouteRecord) continue;
860
- let redirectedByBeforeEnter = false;
861
- for (const matchedRouteRecord of matchedRouteRecords) {
862
- if (matchedRouteRecord.beforeEnterGuards.length === 0) continue;
863
- const beforeEnterResult = await runNavigationGuards(new Set(matchedRouteRecord.beforeEnterGuards), {
864
- mode: currentMode,
865
- to: currentTarget,
866
- from,
867
- nativeRouter
868
- }, resolveWithCodec);
869
- if (beforeEnterResult.status === "failure") return createNavigationRunResult(currentMode, from, currentTarget, beforeEnterResult.failure);
870
- if (beforeEnterResult.status === "redirect") {
871
- const redirectedTarget = beforeEnterResult.target;
872
- const redirectedMode = beforeEnterResult.replace === true ? "replace" : beforeEnterResult.replace === false ? "push" : currentMode;
873
- if (redirectedTarget.fullPath !== currentTarget.fullPath || redirectedMode !== currentMode) {
874
- applyRedirectedFrom(redirectedTarget, currentTarget);
875
- currentTarget = redirectedTarget;
876
- currentMode = redirectedMode;
877
- redirectCount += 1;
878
- if (redirectCount > maxRedirects) return createNavigationRunResult(currentMode, from, currentTarget, createTooManyRedirectsFailure(currentTarget, from, maxRedirects));
879
- redirectedByBeforeEnter = true;
880
- break;
881
- }
882
- }
883
- }
884
- if (redirectedByBeforeEnter) continue;
885
- const beforeResolveResult = await runNavigationGuards(beforeResolveGuards, {
886
- mode: currentMode,
887
- to: currentTarget,
888
- from,
889
- nativeRouter
890
- }, resolveWithCodec);
891
- if (beforeResolveResult.status === "failure") return createNavigationRunResult(currentMode, from, currentTarget, beforeResolveResult.failure);
892
- if (beforeResolveResult.status === "redirect") {
893
- const redirectedTarget = beforeResolveResult.target;
894
- const redirectedMode = beforeResolveResult.replace === true ? "replace" : beforeResolveResult.replace === false ? "push" : currentMode;
895
- if (redirectedTarget.fullPath !== currentTarget.fullPath || redirectedMode !== currentMode) {
896
- applyRedirectedFrom(redirectedTarget, currentTarget);
897
- currentTarget = redirectedTarget;
898
- currentMode = redirectedMode;
899
- redirectCount += 1;
900
- if (redirectCount > maxRedirects) return createNavigationRunResult(currentMode, from, currentTarget, createTooManyRedirectsFailure(currentTarget, from, maxRedirects));
901
- continue;
902
- }
903
- }
904
- if (tabBarTarget) {
905
- const result = await executeNavigationMethod(nativeRouter.switchTab, { url: createAbsoluteRoutePath(currentTarget.path) }, currentTarget, from);
906
- if (isNavigationFailure(result)) return createNavigationRunResult(currentMode, from, currentTarget, result);
907
- return createNavigationRunResult(currentMode, from, currentTarget);
908
- }
909
- const result = await executeNavigationMethod(currentMode === "push" ? nativeRouter.navigateTo : nativeRouter.redirectTo, { url: createNativeRouteUrl(currentTarget, routeResolveCodec.stringifyQuery) }, currentTarget, from);
910
- if (isNavigationFailure(result)) return createNavigationRunResult(currentMode, from, currentTarget, result);
911
- return createNavigationRunResult(currentMode, from, currentTarget);
912
- }
913
- }
914
-
915
- //#endregion
916
- //#region src/router/navigationApi.ts
917
- function createNavigationApi(options) {
918
- const { nativeRouter, route, routeResolveCodec, namedRouteLookup, beforeEachGuards, beforeResolveGuards, maxRedirects, tabBarPathSet, resolveWithCodec, settleNavigationResult } = options;
919
- async function push(to) {
920
- const from = snapshotRouteLocation(route);
921
- let target;
922
- try {
923
- target = resolveWithCodec(to, from.path);
924
- } catch (error) {
925
- return settleNavigationResult(createNavigationRunResult("push", from, void 0, createNavigationFailure(NavigationFailureType.unknown, void 0, from, error)));
926
- }
927
- const result = await navigateWithTarget({
928
- mode: "push",
929
- target,
930
- from,
931
- nativeRouter,
932
- routeResolveCodec,
933
- namedRouteLookup,
934
- beforeEachGuards,
935
- beforeResolveGuards,
936
- maxRedirects,
937
- tabBarPathSet,
938
- resolveWithCodec
939
- });
940
- return settleNavigationResult(result);
941
- }
942
- async function replace(to) {
943
- const from = snapshotRouteLocation(route);
944
- let target;
945
- try {
946
- target = resolveWithCodec(to, from.path);
947
- } catch (error) {
948
- return settleNavigationResult(createNavigationRunResult("replace", from, void 0, createNavigationFailure(NavigationFailureType.unknown, void 0, from, error)));
949
- }
950
- const result = await navigateWithTarget({
951
- mode: "replace",
952
- target,
953
- from,
954
- nativeRouter,
955
- routeResolveCodec,
956
- namedRouteLookup,
957
- beforeEachGuards,
958
- beforeResolveGuards,
959
- maxRedirects,
960
- tabBarPathSet,
961
- resolveWithCodec
962
- });
963
- return settleNavigationResult(result);
964
- }
965
- async function back(delta = 1) {
966
- const from = snapshotRouteLocation(route);
967
- const beforeEachResult = await runNavigationGuards(beforeEachGuards, {
968
- mode: "back",
969
- from,
970
- nativeRouter
971
- }, resolveWithCodec);
972
- if (beforeEachResult.status === "failure") return settleNavigationResult(createNavigationRunResult("back", from, void 0, beforeEachResult.failure));
973
- if (beforeEachResult.status === "redirect") return settleNavigationResult(createNavigationRunResult("back", from, void 0, createNavigationFailure(NavigationFailureType.aborted, void 0, from, "Redirect is not supported in back navigation guards")));
974
- const beforeResolveResult = await runNavigationGuards(beforeResolveGuards, {
975
- mode: "back",
976
- from,
977
- nativeRouter
978
- }, resolveWithCodec);
979
- if (beforeResolveResult.status === "failure") return settleNavigationResult(createNavigationRunResult("back", from, void 0, beforeResolveResult.failure));
980
- if (beforeResolveResult.status === "redirect") return settleNavigationResult(createNavigationRunResult("back", from, void 0, createNavigationFailure(NavigationFailureType.aborted, void 0, from, "Redirect is not supported in back navigation guards")));
981
- const result = await executeNavigationMethod(nativeRouter.navigateBack, { delta }, void 0, from);
982
- const runResult = isNavigationFailure(result) ? createNavigationRunResult("back", from, void 0, result) : createNavigationRunResult("back", from);
983
- return settleNavigationResult(runResult);
984
- }
985
- async function go(delta) {
986
- if (delta < 0) return back(Math.abs(delta));
987
- if (delta === 0) return;
988
- const from = snapshotRouteLocation(route);
989
- return settleNavigationResult(createNavigationRunResult("back", from, void 0, createForwardNotSupportedFailure(from)));
990
- }
991
- async function forward() {
992
- return go(1);
993
- }
994
- return {
995
- push,
996
- replace,
997
- back,
998
- go,
999
- forward
1000
- };
1001
- }
1002
-
1003
- //#endregion
1004
- //#region src/router/resolve.ts
1005
- const DEFAULT_ROUTE_RESOLVE_CODEC = {
1006
- parseQuery,
1007
- stringifyQuery
1008
- };
1009
- function resolveRouteLocation(to, currentPath = "", codec = DEFAULT_ROUTE_RESOLVE_CODEC) {
1010
- var _ref, _to$path, _parsedFromFullPath$q, _to$hash;
1011
- if (typeof to === "string") {
1012
- const parsed = parsePathInput(to, codec);
1013
- return createRouteLocation(resolvePath(parsed.path, currentPath), parsed.query, parsed.hash, void 0, {}, codec.stringifyQuery);
1014
- }
1015
- const parsedFromFullPath = typeof to.fullPath === "string" ? parsePathInput(to.fullPath, codec) : void 0;
1016
- return createRouteLocation(resolvePath((_ref = (_to$path = to.path) !== null && _to$path !== void 0 ? _to$path : parsedFromFullPath === null || parsedFromFullPath === void 0 ? void 0 : parsedFromFullPath.path) !== null && _ref !== void 0 ? _ref : currentPath, currentPath), to.query ? normalizeQuery(to.query) : (_parsedFromFullPath$q = parsedFromFullPath === null || parsedFromFullPath === void 0 ? void 0 : parsedFromFullPath.query) !== null && _parsedFromFullPath$q !== void 0 ? _parsedFromFullPath$q : {}, normalizeHash((_to$hash = to.hash) !== null && _to$hash !== void 0 ? _to$hash : parsedFromFullPath === null || parsedFromFullPath === void 0 ? void 0 : parsedFromFullPath.hash), typeof to.name === "string" ? to.name : void 0, to.params ? normalizeRouteParams(to.params) : {}, codec.stringifyQuery);
1017
- }
1018
-
1019
- //#endregion
1020
- //#region src/router/routeRegistry.ts
1021
- function normalizeRouteRecordForOutput(record) {
1022
- const normalizedRoute = {
1023
- name: record.name,
1024
- path: record.path ? `/${record.path}` : "/"
1025
- };
1026
- if (record.meta !== void 0) normalizedRoute.meta = cloneRouteMeta(record.meta);
1027
- if (record.aliasPaths.length === 1) normalizedRoute.alias = createAbsoluteRoutePath(record.aliasPaths[0]);
1028
- else if (record.aliasPaths.length > 1) normalizedRoute.alias = record.aliasPaths.map((aliasPath) => createAbsoluteRoutePath(aliasPath));
1029
- if (record.beforeEnterGuards.length === 1) normalizedRoute.beforeEnter = record.beforeEnterGuards[0];
1030
- else if (record.beforeEnterGuards.length > 1) normalizedRoute.beforeEnter = record.beforeEnterGuards.slice();
1031
- if (record.redirect !== void 0) normalizedRoute.redirect = record.redirect;
1032
- return normalizedRoute;
1033
- }
1034
- function createRouteRegistry(namedRouteLookup) {
1035
- const hasRoute = (name) => namedRouteLookup.recordByName.has(name);
1036
- const getRoutes = () => Array.from(namedRouteLookup.recordByName.values(), normalizeRouteRecordForOutput);
1037
- const addRoute = ((parentNameOrRoute, maybeRoute) => {
1038
- const route = typeof parentNameOrRoute === "string" ? maybeRoute : parentNameOrRoute;
1039
- if (!route) throw new Error("Route record is required when adding a child route");
1040
- assertValidAddRouteInput(route);
1041
- const parentRouteName = typeof parentNameOrRoute === "string" ? parentNameOrRoute : void 0;
1042
- const parentRouteRecord = parentRouteName ? namedRouteLookup.recordByName.get(parentRouteName) : void 0;
1043
- if (parentRouteName && !parentRouteRecord) throw new Error(`Parent route "${parentRouteName}" is not defined in createRouter({ routes | namedRoutes })`);
1044
- const routeRecords = flattenNamedRouteRecords([route], parentRouteRecord === null || parentRouteRecord === void 0 ? void 0 : parentRouteRecord.path, parentRouteName, parentRouteRecord === null || parentRouteRecord === void 0 ? void 0 : parentRouteRecord.aliasPaths, void 0, "addRoute");
1045
- if (routeRecords.length === 0) throw new Error("Route name and path are required when adding a named route");
1046
- const addedRoutes = [];
1047
- for (const routeRecord of routeRecords) {
1048
- const normalizedRoute = normalizeRouteRecordRaw(routeRecord.route, routeRecord.parentName);
1049
- if (!normalizedRoute) continue;
1050
- const existingRoute = namedRouteLookup.recordByName.get(normalizedRoute.name);
1051
- if (existingRoute) {
1052
- const namesToRemove = collectRouteNamesForRemoval(existingRoute.name, namedRouteLookup.recordByName);
1053
- for (const routeName of namesToRemove) namedRouteLookup.recordByName.delete(routeName);
1054
- warnRouteConfig(`addRoute() replaced existing route "${normalizedRoute.name}" (${createAbsoluteRoutePath(existingRoute.path)} -> ${createAbsoluteRoutePath(normalizedRoute.path)}) and removed ${namesToRemove.size - 1} nested route(s)`);
1055
- }
1056
- namedRouteLookup.recordByName.set(normalizedRoute.name, normalizedRoute);
1057
- addedRoutes.push(normalizedRoute);
1058
- }
1059
- namedRouteLookup.nameByStaticPath = createNamedRouteNameByStaticPath(namedRouteLookup.recordByName);
1060
- return () => {
1061
- let changed = false;
1062
- for (const addedRoute of addedRoutes) if (namedRouteLookup.recordByName.get(addedRoute.name) === addedRoute) {
1063
- namedRouteLookup.recordByName.delete(addedRoute.name);
1064
- changed = true;
1065
- }
1066
- if (changed) namedRouteLookup.nameByStaticPath = createNamedRouteNameByStaticPath(namedRouteLookup.recordByName);
1067
- };
1068
- });
1069
- function removeRoute(name) {
1070
- const namesToRemove = collectRouteNamesForRemoval(name, namedRouteLookup.recordByName);
1071
- if (namesToRemove.size === 0) return;
1072
- let changed = false;
1073
- for (const routeName of namesToRemove) changed = namedRouteLookup.recordByName.delete(routeName) || changed;
1074
- if (changed) namedRouteLookup.nameByStaticPath = createNamedRouteNameByStaticPath(namedRouteLookup.recordByName);
1075
- }
1076
- function clearRoutes() {
1077
- namedRouteLookup.recordByName.clear();
1078
- namedRouteLookup.nameByStaticPath.clear();
1079
- }
1080
- return {
1081
- hasRoute,
1082
- getRoutes,
1083
- addRoute,
1084
- removeRoute,
1085
- clearRoutes
1086
- };
1087
- }
1088
-
1089
- //#endregion
1090
- //#region src/router/useRoute.ts
1091
- function applyRouteState(routeState, nextRoute) {
1092
- routeState.path = nextRoute.path;
1093
- routeState.fullPath = nextRoute.fullPath;
1094
- routeState.query = cloneLocationQuery(nextRoute.query);
1095
- routeState.hash = nextRoute.hash;
1096
- routeState.params = cloneRouteParams(nextRoute.params);
1097
- if (nextRoute.name === void 0) delete routeState.name;
1098
- else routeState.name = nextRoute.name;
1099
- if (nextRoute.meta === void 0) delete routeState.meta;
1100
- else routeState.meta = cloneRouteMeta(nextRoute.meta);
1101
- if (nextRoute.href === void 0) delete routeState.href;
1102
- else routeState.href = nextRoute.href;
1103
- if (nextRoute.matched === void 0) delete routeState.matched;
1104
- else routeState.matched = cloneRouteRecordMatchedList(nextRoute.matched);
1105
- if (nextRoute.redirectedFrom === void 0) delete routeState.redirectedFrom;
1106
- else routeState.redirectedFrom = cloneRouteLocationRedirectedFrom(nextRoute.redirectedFrom);
1107
- }
1108
- function createRouteStateController(options = {}) {
1109
- var _options$resolveRoute;
1110
- const setupContext = getCurrentSetupContext();
1111
- if (!setupContext) throw new Error("useRoute() 必须在 setup() 的同步阶段调用");
1112
- const fallbackPage = setupContext.instance;
1113
- const resolveRoute = (_options$resolveRoute = options.resolveRoute) !== null && _options$resolveRoute !== void 0 ? _options$resolveRoute : ((route) => {
1114
- var _getActiveRouter$reso, _getActiveRouter;
1115
- return (_getActiveRouter$reso = (_getActiveRouter = getActiveRouter()) === null || _getActiveRouter === void 0 ? void 0 : _getActiveRouter.resolve(route)) !== null && _getActiveRouter$reso !== void 0 ? _getActiveRouter$reso : route;
1116
- });
1117
- const currentRoute = resolveRoute(resolveCurrentRoute(void 0, fallbackPage));
1118
- const routeState = reactive({
1119
- path: currentRoute.path,
1120
- fullPath: currentRoute.fullPath,
1121
- query: cloneLocationQuery(currentRoute.query),
1122
- hash: currentRoute.hash,
1123
- params: cloneRouteParams(currentRoute.params)
1124
- });
1125
- applyRouteState(routeState, currentRoute);
1126
- function syncRoute(queryOverride, routeOverride) {
1127
- const nextRoute = routeOverride ? resolveRoute(routeOverride) : resolveRoute(resolveCurrentRoute(queryOverride, fallbackPage));
1128
- applyRouteState(routeState, nextRoute);
1129
- }
1130
- onLoad((query) => {
1131
- syncRoute(query);
1132
- });
1133
- onReady(() => {
1134
- syncRoute();
1135
- });
1136
- onShow(() => {
1137
- syncRoute();
1138
- });
1139
- onRouteDone(() => {
1140
- syncRoute();
1141
- });
1142
- const unregisterRouteStateSync = registerRouteStateSyncHandler((payload) => {
1143
- if (payload === null || payload === void 0 ? void 0 : payload.route) {
1144
- syncRoute(void 0, payload.route);
1145
- return;
1146
- }
1147
- if (payload === null || payload === void 0 ? void 0 : payload.page) {
1148
- syncRoute(void 0, resolvePageRoute(payload.page));
1149
- return;
1150
- }
1151
- if (payload === null || payload === void 0 ? void 0 : payload.url) {
1152
- syncRoute(void 0, resolveRouteLocation(payload.url, routeState.path));
1153
- return;
1154
- }
1155
- syncRoute();
1156
- });
1157
- onUnload(() => {
1158
- unregisterRouteStateSync();
1159
- });
1160
- return { route: readonly(routeState) };
1161
- }
1162
- function useRoute(options = {}) {
1163
- return createRouteStateController(options).route;
1164
- }
1165
- /**
1166
- * @description 获取当前组件路径语义的原生 Router
1167
- */
1168
- function useNativeRouter() {
1169
- return useNativeRouter$1();
1170
- }
1171
- /**
1172
- * @description 获取当前页面路径语义的原生 Page Router
1173
- */
1174
- function useNativePageRouter() {
1175
- return useNativePageRouter$1();
1176
- }
1177
-
1178
- //#endregion
1179
- //#region src/router/createRouter.ts
1180
- /**
1181
- * @description 创建高阶路由导航器(对齐 Vue Router 的 createRouter 心智)
1182
- */
1183
- function createRouter(options = {}) {
1184
- var _options$maxRedirects, _options$paramsMode, _options$rejectOnErro, _options$parseQuery, _options$stringifyQue, _options$tabBarEntrie;
1185
- const nativeRouter = useNativeRouter();
1186
- installRouteStateSyncOnNativeRouter(getMiniProgramGlobalObject());
1187
- const beforeEachGuards = /* @__PURE__ */ new Set();
1188
- const beforeResolveGuards = /* @__PURE__ */ new Set();
1189
- const afterEachHooks = /* @__PURE__ */ new Set();
1190
- const errorHandlers = /* @__PURE__ */ new Set();
1191
- const maxRedirects = (_options$maxRedirects = options.maxRedirects) !== null && _options$maxRedirects !== void 0 ? _options$maxRedirects : 10;
1192
- const paramsMode = (_options$paramsMode = options.paramsMode) !== null && _options$paramsMode !== void 0 ? _options$paramsMode : "loose";
1193
- const rejectOnError = (_options$rejectOnErro = options.rejectOnError) !== null && _options$rejectOnErro !== void 0 ? _options$rejectOnErro : true;
1194
- const routeResolveCodec = {
1195
- parseQuery: (_options$parseQuery = options.parseQuery) !== null && _options$parseQuery !== void 0 ? _options$parseQuery : parseQuery,
1196
- stringifyQuery: (_options$stringifyQue = options.stringifyQuery) !== null && _options$stringifyQue !== void 0 ? _options$stringifyQue : stringifyQuery
1197
- };
1198
- const readyPromise = Promise.resolve();
1199
- const routeEntries = resolveRouteOptionEntries(options);
1200
- warnDuplicateRouteEntries(routeEntries);
1201
- const namedRouteLookup = createNamedRouteLookup(routeEntries);
1202
- const normalizedTabBarEntries = ((_options$tabBarEntrie = options.tabBarEntries) !== null && _options$tabBarEntrie !== void 0 ? _options$tabBarEntrie : []).map((path) => resolvePath(path, "")).filter(Boolean);
1203
- const tabBarPathSet = new Set(normalizedTabBarEntries);
1204
- const routeRegistry = createRouteRegistry(namedRouteLookup);
1205
- const routerOptions = createRouterOptionsSnapshot(normalizedTabBarEntries, routeRegistry.getRoutes(), paramsMode, maxRedirects, routeResolveCodec, rejectOnError);
1206
- function enrichRouteRecordState(routeLocation) {
1207
- const resolved = { ...routeLocation };
1208
- resolved.href = resolved.fullPath;
1209
- const matchedResult = resolveMatchedRouteRecord(resolved, namedRouteLookup);
1210
- if (matchedResult) {
1211
- const matchedRecord = matchedResult.record;
1212
- if (resolved.name === void 0) resolved.name = matchedRecord.name;
1213
- const mergedRouteMeta = mergeMatchedRouteMeta(matchedResult.matchedRecords);
1214
- if (mergedRouteMeta !== void 0) resolved.meta = cloneRouteMeta(mergedRouteMeta);
1215
- if (matchedResult.params && Object.keys(resolved.params).length === 0) resolved.params = cloneRouteParams(matchedResult.params);
1216
- resolved.matched = matchedResult.matchedRecords.map((record, index, records) => {
1217
- return normalizeRouteRecordMatched(record, index === records.length - 1 ? matchedResult.matchedPath : void 0);
1218
- });
1219
- } else resolved.matched = [];
1220
- return resolved;
1221
- }
1222
- function resolveWithCodec(to, currentPath) {
1223
- return enrichRouteRecordState(resolveRouteLocation(typeof to === "string" ? to : resolveNamedRouteLocation(to, namedRouteLookup, paramsMode), currentPath, routeResolveCodec));
1224
- }
1225
- const route = createRouteStateController({ resolveRoute: enrichRouteRecordState }).route;
1226
- function resolve(to) {
1227
- return resolveWithCodec(to, route.path);
1228
- }
1229
- const navigationApi = createNavigationApi({
1230
- nativeRouter,
1231
- route,
1232
- routeResolveCodec,
1233
- namedRouteLookup,
1234
- beforeEachGuards,
1235
- beforeResolveGuards,
1236
- maxRedirects,
1237
- tabBarPathSet,
1238
- resolveWithCodec,
1239
- settleNavigationResult: createNavigationResultController({
1240
- afterEachHooks,
1241
- errorHandlers,
1242
- nativeRouter,
1243
- rejectOnError
1244
- }).settleNavigationResult
1245
- });
1246
- function beforeEach(guard) {
1247
- beforeEachGuards.add(guard);
1248
- return () => {
1249
- beforeEachGuards.delete(guard);
1250
- };
1251
- }
1252
- function beforeResolve(guard) {
1253
- beforeResolveGuards.add(guard);
1254
- return () => {
1255
- beforeResolveGuards.delete(guard);
1256
- };
1257
- }
1258
- function afterEach(hook) {
1259
- afterEachHooks.add(hook);
1260
- return () => {
1261
- afterEachHooks.delete(hook);
1262
- };
1263
- }
1264
- function onError(handler) {
1265
- errorHandlers.add(handler);
1266
- return () => {
1267
- errorHandlers.delete(handler);
1268
- };
1269
- }
1270
- const router = {
1271
- nativeRouter,
1272
- options: routerOptions,
1273
- currentRoute: route,
1274
- install(app) {
1275
- var _config;
1276
- setActiveRouter(router);
1277
- const globalProperties = app === null || app === void 0 || (_config = app.config) === null || _config === void 0 ? void 0 : _config.globalProperties;
1278
- if (globalProperties) globalProperties.$router = router;
1279
- },
1280
- resolve,
1281
- isReady() {
1282
- return readyPromise;
1283
- },
1284
- push: navigationApi.push,
1285
- replace: navigationApi.replace,
1286
- back: navigationApi.back,
1287
- go: navigationApi.go,
1288
- forward: navigationApi.forward,
1289
- hasRoute: routeRegistry.hasRoute,
1290
- getRoutes: routeRegistry.getRoutes,
1291
- addRoute: routeRegistry.addRoute,
1292
- removeRoute: routeRegistry.removeRoute,
1293
- clearRoutes: routeRegistry.clearRoutes,
1294
- beforeEach,
1295
- beforeResolve,
1296
- afterEach,
1297
- onError
1298
- };
1299
- setActiveRouter(router);
1300
- return router;
1301
- }
1302
-
1303
- //#endregion
1304
- //#region src/router/useRouter.ts
1305
- /**
1306
- * @description 获取当前已创建的路由实例。
1307
- */
1308
- function useRouter() {
1309
- const router = getActiveRouter();
1310
- if (router) return router;
1311
- throw new Error("useRouter() 未找到已创建的 router 实例。请先在 setup() 中调用 createRouter()。");
1312
- }
1313
-
1314
- //#endregion
1315
- export { NavigationFailureType, createNavigationFailure, createRouter, isNavigationFailure, parseQuery, resolveRouteLocation, stringifyQuery, useNativePageRouter, useNativeRouter, useRoute, useRouter };
1316
- //# sourceMappingURL=router.mjs.map
1
+ import { parseQuery, stringifyQuery } from "./routerInternal/query.mjs";
2
+ import { NavigationFailureType } from "./router/types.mjs";
3
+ import { createNavigationFailure, isNavigationFailure } from "./router/navigationCore.mjs";
4
+ import { resolveRouteLocation } from "./router/resolve.mjs";
5
+ import { useNativePageRouter, useNativeRouter, useRoute } from "./router/useRoute.mjs";
6
+ import { createRouter } from "./router/createRouter.mjs";
7
+ import { useRouter } from "./router/useRouter.mjs";
8
+
9
+ export { NavigationFailureType, createNavigationFailure, createRouter, isNavigationFailure, parseQuery, resolveRouteLocation, stringifyQuery, useNativePageRouter, useNativeRouter, useRoute, useRouter };