@panomc/theme-core 1.0.0-dev.59 → 1.0.0-dev.61

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 (308) hide show
  1. package/assets/css/pano-fallback-legacy.css +12381 -0
  2. package/assets/css/pano-fallback.css +3222 -0
  3. package/bin/__tests__/check/fixtures/plugin-contracts/market/controllers.json +4 -0
  4. package/bin/__tests__/check/fixtures/plugin-contracts/market/views.json +67 -0
  5. package/bin/__tests__/check/fixtures/routes.json +5 -0
  6. package/bin/__tests__/check/helpers.js +55 -0
  7. package/bin/__tests__/check/overrides.test.js +287 -0
  8. package/bin/__tests__/check/theme.test.js +332 -0
  9. package/bin/__tests__/cli/accept-and-list.test.js +159 -0
  10. package/bin/__tests__/cli/config-edit.test.js +213 -0
  11. package/bin/__tests__/cli/contracts-pull.test.js +187 -0
  12. package/bin/__tests__/cli/core-meta.test.js +305 -0
  13. package/bin/__tests__/cli/eject-view.test.js +356 -0
  14. package/bin/__tests__/cli/helpers.js +258 -0
  15. package/bin/__tests__/scaffold/scaffold.test.js +84 -0
  16. package/bin/bundle-internal-libs.js +14 -2
  17. package/bin/check.js +1150 -213
  18. package/bin/contracts.js +1643 -0
  19. package/bin/generate-contract.js +378 -0
  20. package/bin/generate-licenses.js +14 -2
  21. package/bin/generate-runtime-shims.js +27 -9
  22. package/bin/new.js +101 -2
  23. package/bin/package-zip.js +16 -2
  24. package/bin/sync.js +360 -7
  25. package/bin/theme-core.js +65 -107
  26. package/lang/en-US.json +1 -0
  27. package/lang/ru.json +1 -0
  28. package/lang/tr.json +1 -0
  29. package/package.json +7 -3
  30. package/skin-contract.json +864 -19
  31. package/src/kit/__tests__/hooks-server-fetch.test.js +56 -0
  32. package/src/kit/__tests__/route-map.test.js +154 -0
  33. package/src/kit/__tests__/theme-meta.test.js +249 -0
  34. package/src/kit/hooks-client.js +3 -0
  35. package/src/kit/hooks-server.js +91 -7
  36. package/src/kit/route-map.js +300 -0
  37. package/src/kit/specifiers.js +3 -0
  38. package/src/kit/svelte-config.js +3 -0
  39. package/src/kit/theme-meta.js +405 -0
  40. package/src/kit/vite-config.js +156 -12
  41. package/src/lib/NotificationManager.js +18 -0
  42. package/src/lib/PluginAPI.js +313 -9
  43. package/src/lib/Store.js +18 -5
  44. package/src/lib/__tests__/avatarVersion.test.js +25 -0
  45. package/src/lib/__tests__/check.test.js +201 -0
  46. package/src/lib/__tests__/controllerHost.test.js +363 -0
  47. package/src/lib/__tests__/cx03.test.js +245 -0
  48. package/src/lib/__tests__/engineBoot.test.js +151 -0
  49. package/src/lib/__tests__/engineParts.helper.js +284 -0
  50. package/src/lib/__tests__/engineParts.test.js +179 -0
  51. package/src/lib/__tests__/engineSidebars.helper.js +353 -0
  52. package/src/lib/__tests__/engineSidebars.test.js +273 -0
  53. package/src/lib/__tests__/engineStyles.test.js +227 -0
  54. package/src/lib/__tests__/engineWiring.test.js +1000 -0
  55. package/src/lib/__tests__/fallbackStyles.test.js +1254 -0
  56. package/src/lib/__tests__/fixtures/Probe.svelte +5 -0
  57. package/src/lib/__tests__/fixtures/engine-parts.ssr.json +29 -0
  58. package/src/lib/__tests__/fixtures/engine-sidebars.ssr.json +16 -0
  59. package/src/lib/__tests__/home.test.js +563 -0
  60. package/src/lib/__tests__/injectedScope.test.js +490 -0
  61. package/src/lib/__tests__/languageConcurrency.test.js +55 -0
  62. package/src/lib/__tests__/languageLayers.test.js +286 -0
  63. package/src/lib/__tests__/pageHead.test.js +167 -0
  64. package/src/lib/__tests__/pageMeta.util.test.js +216 -0
  65. package/src/lib/__tests__/pageTitle.util.test.js +96 -0
  66. package/src/lib/__tests__/pluginApiViews.test.js +529 -0
  67. package/src/lib/__tests__/plugins.test.js +53 -0
  68. package/src/lib/__tests__/profileNav.util.test.js +145 -0
  69. package/src/lib/__tests__/registryReady.test.js +26 -0
  70. package/src/lib/__tests__/returnTo.util.test.js +294 -0
  71. package/src/lib/__tests__/routeConfig.test.js +361 -0
  72. package/src/lib/__tests__/sidebarSpec.util.test.js +152 -0
  73. package/src/lib/__tests__/skinContract.test.js +558 -0
  74. package/src/lib/__tests__/svelteSsr.helper.js +68 -0
  75. package/src/lib/__tests__/tc03.test.js +427 -0
  76. package/src/lib/__tests__/tc11.test.js +184 -0
  77. package/src/lib/__tests__/translationLayers.test.js +161 -0
  78. package/src/lib/avatarVersion.js +39 -0
  79. package/src/lib/components/Breadcrumb.svelte +9 -40
  80. package/src/lib/components/Date.svelte +1 -1
  81. package/src/lib/components/DefaultToast.svelte +13 -3
  82. package/src/lib/components/FallbackLinks.svelte +28 -0
  83. package/src/lib/components/FallbackScope.svelte +24 -0
  84. package/src/lib/components/Footer.svelte +8 -8
  85. package/src/lib/components/Header.svelte +3 -3
  86. package/src/lib/components/Hook.svelte +12 -1
  87. package/src/lib/components/LoginFormBody.svelte +5 -5
  88. package/src/lib/components/Main.svelte +22 -47
  89. package/src/lib/components/Navbar.svelte +30 -29
  90. package/src/lib/components/NoContent.svelte +2 -2
  91. package/src/lib/components/NotificationContainer.svelte +31 -82
  92. package/src/lib/components/OnlineAdmins.svelte +3 -2
  93. package/src/lib/components/PageActions.svelte +1 -1
  94. package/src/lib/components/PageHead.svelte +50 -0
  95. package/src/lib/components/PageTitle.svelte +2 -2
  96. package/src/lib/components/Pagination.svelte +6 -6
  97. package/src/lib/components/PlayerHead.svelte +4 -4
  98. package/src/lib/components/PluginBlock.svelte +132 -0
  99. package/src/lib/components/PluginSlot.svelte +40 -0
  100. package/src/lib/components/Post.svelte +13 -230
  101. package/src/lib/components/Posts.svelte +7 -14
  102. package/src/lib/components/RegisterForm.svelte +12 -11
  103. package/src/lib/components/Sidebar.svelte +9 -7
  104. package/src/lib/components/TicketRow.svelte +8 -48
  105. package/src/lib/components/TicketStatus.svelte +10 -16
  106. package/src/lib/components/Tickets.svelte +8 -30
  107. package/src/lib/components/Toast.svelte +16 -14
  108. package/src/lib/components/ToastContainer.svelte +16 -9
  109. package/src/lib/components/ViewComponent.svelte +13 -1
  110. package/src/lib/components/modals/CloseTicketConfirmModal.svelte +15 -46
  111. package/src/lib/components/modals/ConfirmRemoveAllNotificationsModal.svelte +17 -39
  112. package/src/lib/components/modals/LogoutSessionConfirmModal.svelte +12 -30
  113. package/src/lib/components/sidebars/HomeSidebar.svelte +33 -284
  114. package/src/lib/components/sidebars/PlayerDetailSidebar.svelte +14 -63
  115. package/src/lib/components/sidebars/PluginSidebar.svelte +21 -0
  116. package/src/lib/components/sidebars/ProfileNavCard.svelte +24 -0
  117. package/src/lib/components/sidebars/ProfileSidebar.svelte +44 -84
  118. package/src/lib/components/sidebars/SupportSidebar.svelte +19 -22
  119. package/src/lib/components/sidebars/TicketCreateAndDetailSidebar.svelte +23 -35
  120. package/src/lib/components/sidebars/profileNav.util.js +105 -0
  121. package/src/lib/components/sidebars/sidebarSpec.util.js +92 -0
  122. package/src/lib/controllerHost.js +261 -0
  123. package/src/lib/fallbackStyles.js +317 -0
  124. package/src/lib/home.js +202 -0
  125. package/src/lib/language.util.js +70 -37
  126. package/src/lib/layouts/AppLayout.svelte +16 -8
  127. package/src/lib/layouts/AuthLayout.svelte +6 -4
  128. package/src/lib/layouts/MainLayout.svelte +17 -12
  129. package/src/lib/layouts/ProfileLayout.svelte +6 -4
  130. package/src/lib/layouts/ThemeSettingsLayout.svelte +6 -4
  131. package/src/lib/layouts/TicketsLayout.svelte +6 -5
  132. package/src/lib/pageMeta.util.js +212 -0
  133. package/src/lib/pageShape.js +33 -0
  134. package/src/lib/pageTitle.util.js +32 -0
  135. package/src/lib/pages/ActivateEmailPage.svelte +2 -7
  136. package/src/lib/pages/ConfirmNewEmailPage.svelte +2 -7
  137. package/src/lib/pages/ErrorPage.svelte +5 -2
  138. package/src/lib/pages/HomePage.svelte +31 -8
  139. package/src/lib/pages/LoginPage.svelte +38 -41
  140. package/src/lib/pages/NotificationsPage.svelte +2 -7
  141. package/src/lib/pages/PlayerDetailPage.svelte +2 -7
  142. package/src/lib/pages/PostDetailPage.svelte +2 -7
  143. package/src/lib/pages/PreviewPostPage.svelte +2 -7
  144. package/src/lib/pages/RegisterPage.svelte +10 -13
  145. package/src/lib/pages/RenewPasswordPage.svelte +2 -7
  146. package/src/lib/pages/ResetPasswordPage.svelte +2 -7
  147. package/src/lib/pages/RulesPage.svelte +3 -8
  148. package/src/lib/pages/SupportPage.svelte +2 -7
  149. package/src/lib/pages/ThemeSettingsPage.svelte +2 -7
  150. package/src/lib/pages/profile/ProfilePage.svelte +2 -7
  151. package/src/lib/pages/profile/SettingsPage.svelte +2 -7
  152. package/src/lib/pages/profile/TicketsPage.svelte +2 -7
  153. package/src/lib/pages/ticket/CreateTicketPage.svelte +2 -7
  154. package/src/lib/pages/ticket/TicketDetailPage.svelte +2 -7
  155. package/src/lib/plugins.js +61 -0
  156. package/src/lib/returnTo.util.js +116 -0
  157. package/src/lib/services/auth.js +11 -11
  158. package/src/lib/services/posts.js +21 -10
  159. package/src/lib/services/profile.js +5 -5
  160. package/src/lib/services/theme-setting.js +1 -1
  161. package/src/lib/services/tickets.js +36 -15
  162. package/src/lib/siteRealtime.js +55 -8
  163. package/src/lib/themePageLoad.js +38 -0
  164. package/src/lib/translationLayers.js +144 -0
  165. package/src/lib/ui-logics/layout-logics/AppLayoutLogics.js +160 -6
  166. package/src/lib/ui-logics/layout-logics/AuthLayoutLogics.js +3 -2
  167. package/src/lib/ui-logics/layout-logics/ProfileLayoutLogics.js +3 -2
  168. package/src/lib/ui-logics/layout-logics/TicketsLayoutLogics.js +3 -2
  169. package/src/lib/ui-logics/page-logics/ActiveEmailPageLogics.js +4 -4
  170. package/src/lib/ui-logics/page-logics/ConfirmNewEmailPageLogics.js +4 -4
  171. package/src/lib/ui-logics/page-logics/CreateTicketPageLogics.js +5 -5
  172. package/src/lib/ui-logics/page-logics/HomePageLogics.js +5 -3
  173. package/src/lib/ui-logics/page-logics/NotificationsPageLogics.js +40 -16
  174. package/src/lib/ui-logics/page-logics/PlayerDetailPageLogics.js +3 -3
  175. package/src/lib/ui-logics/page-logics/PostDetailPageLogics.js +3 -3
  176. package/src/lib/ui-logics/page-logics/PreviewPostPageLogics.js +1 -1
  177. package/src/lib/ui-logics/page-logics/RenewPasswordPageLogics.js +4 -4
  178. package/src/lib/ui-logics/page-logics/ResetPasswordPageLogics.js +6 -6
  179. package/src/lib/ui-logics/page-logics/SettingsPageLogics.js +8 -8
  180. package/src/lib/ui-logics/page-logics/TicketDetailPageLogics.js +3 -3
  181. package/src/lib/ui-logics/page-logics/TicketsPageLogics.js +5 -3
  182. package/src/lib/views/ActivateEmailView.samples.js +22 -0
  183. package/src/lib/views/ActivateEmailView.svelte +4 -4
  184. package/src/lib/views/AppLayoutView.samples.js +17 -0
  185. package/src/lib/views/AppLayoutView.svelte +1 -1
  186. package/src/lib/views/AuthLayoutView.samples.js +4 -0
  187. package/src/lib/views/AuthLayoutView.svelte +1 -1
  188. package/src/lib/views/Breadcrumb.samples.js +15 -0
  189. package/src/lib/views/CloseTicketConfirmModal.samples.js +12 -0
  190. package/src/lib/views/ConfirmNewEmailView.samples.js +22 -0
  191. package/src/lib/views/ConfirmNewEmailView.svelte +4 -4
  192. package/src/lib/views/ConfirmRemoveAllNotificationsModal.samples.js +9 -0
  193. package/src/lib/views/CreateTicketView.samples.js +21 -0
  194. package/src/lib/views/CreateTicketView.svelte +5 -5
  195. package/src/lib/views/Date.samples.js +9 -0
  196. package/src/lib/views/DefaultToast.samples.js +7 -0
  197. package/src/lib/views/ErrorView.samples.js +8 -0
  198. package/src/lib/views/ErrorView.svelte +4 -2
  199. package/src/lib/views/Footer.samples.js +8 -0
  200. package/src/lib/views/Header.samples.js +8 -0
  201. package/src/lib/views/HomeSidebar.samples.js +59 -0
  202. package/src/lib/views/HomeView.samples.js +34 -0
  203. package/src/lib/views/HomeView.svelte +14 -6
  204. package/src/lib/views/LoginFormBody.samples.js +8 -0
  205. package/src/lib/views/LoginView.samples.js +50 -0
  206. package/src/lib/views/LoginView.svelte +24 -22
  207. package/src/lib/views/LogoutSessionConfirmModal.samples.js +8 -0
  208. package/src/lib/views/Main.samples.js +23 -0
  209. package/src/lib/views/MainLayoutView.svelte +3 -4
  210. package/src/lib/views/Navbar.samples.js +8 -0
  211. package/src/lib/views/NoContent.samples.js +7 -0
  212. package/src/lib/views/NotificationContainer.samples.js +25 -0
  213. package/src/lib/views/NotificationsView.samples.js +36 -0
  214. package/src/lib/views/NotificationsView.svelte +21 -12
  215. package/src/lib/views/PageActions.samples.js +7 -0
  216. package/src/lib/views/PageTitle.samples.js +8 -0
  217. package/src/lib/views/Pagination.samples.js +7 -0
  218. package/src/lib/views/PlayerDetailSidebar.samples.js +35 -0
  219. package/src/lib/views/PlayerDetailView.samples.js +8 -0
  220. package/src/lib/views/PlayerDetailView.svelte +3 -3
  221. package/src/lib/views/PlayerHead.samples.js +8 -0
  222. package/src/lib/views/Post.samples.js +10 -0
  223. package/src/lib/views/PostDetailView.samples.js +28 -0
  224. package/src/lib/views/PostDetailView.svelte +24 -16
  225. package/src/lib/views/Posts.samples.js +9 -0
  226. package/src/lib/views/PreviewPostView.samples.js +20 -0
  227. package/src/lib/views/PreviewPostView.svelte +10 -10
  228. package/src/lib/views/ProfileLayoutView.samples.js +4 -0
  229. package/src/lib/views/ProfileSidebar.samples.js +33 -0
  230. package/src/lib/views/ProfileView.samples.js +29 -0
  231. package/src/lib/views/ProfileView.svelte +2 -2
  232. package/src/lib/views/RegisterForm.samples.js +7 -0
  233. package/src/lib/views/RegisterView.samples.js +28 -0
  234. package/src/lib/views/RegisterView.svelte +5 -3
  235. package/src/lib/views/RenewPasswordView.samples.js +24 -0
  236. package/src/lib/views/RenewPasswordView.svelte +6 -6
  237. package/src/lib/views/ResetPasswordView.samples.js +24 -0
  238. package/src/lib/views/ResetPasswordView.svelte +3 -3
  239. package/src/lib/views/RulesView.samples.js +14 -0
  240. package/src/lib/views/RulesView.svelte +3 -3
  241. package/src/lib/views/SettingsView.svelte +48 -17
  242. package/src/lib/views/Sidebar.samples.js +7 -0
  243. package/src/lib/views/SupportSidebar.samples.js +24 -0
  244. package/src/lib/views/SupportView.samples.js +16 -0
  245. package/src/lib/views/SupportView.svelte +8 -6
  246. package/src/lib/views/ThemeSettingsLayoutView.samples.js +9 -0
  247. package/src/lib/views/ThemeSettingsLayoutView.svelte +1 -1
  248. package/src/lib/views/ThemeSettingsView.svelte +89 -89
  249. package/src/lib/views/TicketCreateAndDetailSidebar.samples.js +33 -0
  250. package/src/lib/views/TicketDetailView.samples.js +34 -0
  251. package/src/lib/views/TicketDetailView.svelte +17 -15
  252. package/src/lib/views/TicketRow.samples.js +10 -0
  253. package/src/lib/views/TicketStatus.samples.js +8 -0
  254. package/src/lib/views/Tickets.samples.js +9 -0
  255. package/src/lib/views/TicketsLayoutView.samples.js +4 -0
  256. package/src/lib/views/TicketsView.samples.js +23 -0
  257. package/src/lib/views/TicketsView.svelte +11 -9
  258. package/src/lib/views/Toast.samples.js +9 -0
  259. package/src/lib/views/ToastContainer.samples.js +8 -0
  260. package/src/lib/views/parts/Breadcrumb.svelte +53 -0
  261. package/src/lib/views/parts/CloseTicketConfirmModal.svelte +63 -0
  262. package/src/lib/views/parts/ConfirmRemoveAllNotificationsModal.svelte +55 -0
  263. package/src/lib/views/parts/DefaultToast.svelte +22 -0
  264. package/src/lib/views/parts/HomeSidebar.svelte +334 -0
  265. package/src/lib/views/parts/LogoutSessionConfirmModal.svelte +46 -0
  266. package/src/lib/views/parts/Main.svelte +71 -0
  267. package/src/lib/views/parts/NotificationContainer.svelte +109 -0
  268. package/src/lib/views/parts/PlayerDetailSidebar.svelte +81 -0
  269. package/src/lib/views/parts/Post.svelte +255 -0
  270. package/src/lib/views/parts/Posts.svelte +25 -0
  271. package/src/lib/views/parts/ProfileSidebar.svelte +115 -0
  272. package/src/lib/views/parts/Sidebar.svelte +19 -0
  273. package/src/lib/views/parts/SupportSidebar.svelte +34 -0
  274. package/src/lib/views/parts/TicketCreateAndDetailSidebar.svelte +51 -0
  275. package/src/lib/views/parts/TicketRow.svelte +63 -0
  276. package/src/lib/views/parts/TicketStatus.svelte +24 -0
  277. package/src/lib/views/parts/Tickets.svelte +45 -0
  278. package/src/lib/views/parts/Toast.svelte +27 -0
  279. package/src/lib/views/parts/ToastContainer.svelte +17 -0
  280. package/src/lib/views/parts/engine-views.generated.js +63 -0
  281. package/src/lib/views/parts/publicHref.js +18 -0
  282. package/src/lib/views/parts/ticketStatuses.js +7 -0
  283. package/src/plugin-engine/__tests__/engine.test.js +161 -0
  284. package/src/plugin-engine/engine.js +80 -12
  285. package/src/registry/__tests__/registry.test.js +510 -0
  286. package/src/registry/__tests__/view.test.js +52 -0
  287. package/src/registry/index.js +700 -51
  288. package/src/registry/routes.js +62 -0
  289. package/src/registry/view.js +69 -0
  290. package/src/routes/RootLayout.svelte +24 -1
  291. package/src/routes/catalogue/List.svelte +163 -0
  292. package/src/routes/catalogue/Stage.svelte +355 -0
  293. package/src/routes/catalogue/__tests__/browserSafe.test.js +13 -0
  294. package/src/routes/catalogue/__tests__/catalogue.test.js +539 -0
  295. package/src/routes/catalogue/catalogue.js +129 -0
  296. package/src/routes/catalogue/deps.js +147 -0
  297. package/src/routes/catalogue/engineSamples.js +63 -0
  298. package/src/routes/catalogue/fixtures.js +77 -0
  299. package/src/routes/catalogue/list.js +37 -0
  300. package/src/routes/catalogue/model.js +286 -0
  301. package/src/routes/catalogue/stage.js +69 -0
  302. package/src/routes/catalogue/views-json.js +24 -0
  303. package/src/routes/plugin-ui/Layout.svelte +29 -4
  304. package/src/routes/plugin-ui/Page.svelte +86 -31
  305. package/src/routes/plugin-ui/load.js +173 -0
  306. package/src/routes/plugins-client-file.js +8 -3
  307. package/src/routes/plugins-ui-file.js +60 -0
  308. package/src/routes/root-layout-load.js +59 -2
@@ -0,0 +1,300 @@
1
+ // Pure route map (doc 01 section 9). Canonical paths never change in route files or in plugin
2
+ // registrations; a theme can rename or disable them in `theme.config.js` (`routes.rename`,
3
+ // `routes.disable`). This module only maps strings: no framework imports, no state.
4
+ //
5
+ // Patterns use the `[param]` syntax of RouteMatcher (`/store/[slug]`, and a final `[...rest]`).
6
+ // Both sides of a rename must name the same params. Params are carried over as the raw path
7
+ // segments, so percent-encoding is never touched.
8
+
9
+ /**
10
+ * @typedef {{ rename?: Record<string, string>, disable?: string[] }} RouteMapConfig
11
+ * @typedef {{
12
+ * toCanonical: (pathname: string) => string | null,
13
+ * toPublic: (canonicalPath: string) => string,
14
+ * isRenamedAway: (pathname: string) => boolean,
15
+ * }} RouteMap
16
+ */
17
+
18
+ const PARAM = /^\[(\.\.\.)?([A-Za-z_$][\w$]*)\]$/;
19
+
20
+ /**
21
+ * @typedef {{ literal: string } | { param: string } | { rest: string }} Segment
22
+ * @typedef {{ source: string, segments: Segment[], names: string[], score: number[] }} Pattern
23
+ */
24
+
25
+ /**
26
+ * @param {string} source
27
+ * @returns {Pattern}
28
+ */
29
+ function parsePattern(source) {
30
+ if (typeof source !== "string" || !source.startsWith("/") || source.startsWith("//")) {
31
+ throw new Error(`Invalid route pattern ${JSON.stringify(source)}: a route starts with a single "/".`);
32
+ }
33
+ if (/[?#]/.test(source)) {
34
+ throw new Error(`Invalid route pattern "${source}": no query string or hash.`);
35
+ }
36
+
37
+ const parts = source.split("/").filter(Boolean);
38
+ /** @type {Segment[]} */
39
+ const segments = [];
40
+ /** @type {string[]} */
41
+ const names = [];
42
+
43
+ parts.forEach((part, index) => {
44
+ const match = PARAM.exec(part);
45
+
46
+ if (!match) {
47
+ if (part.includes("[") || part.includes("]")) {
48
+ throw new Error(`Invalid route pattern "${source}": unsupported segment "${part}".`);
49
+ }
50
+ segments.push({ literal: part });
51
+ return;
52
+ }
53
+
54
+ const [, dots, name] = match;
55
+
56
+ if (names.includes(name)) {
57
+ throw new Error(`Invalid route pattern "${source}": param "${name}" is used twice.`);
58
+ }
59
+ names.push(name);
60
+
61
+ if (dots) {
62
+ if (index !== parts.length - 1) {
63
+ throw new Error(`Invalid route pattern "${source}": a [...${name}] segment must be the last one.`);
64
+ }
65
+ segments.push({ rest: name });
66
+ } else {
67
+ segments.push({ param: name });
68
+ }
69
+ });
70
+
71
+ // Specificity per segment (literal 2, param 1, rest 0); compared lexicographically.
72
+ const score = segments.map((segment) => ("literal" in segment ? 2 : "param" in segment ? 1 : 0));
73
+
74
+ return { source, segments, names, score };
75
+ }
76
+
77
+ /**
78
+ * @param {Pattern} a
79
+ * @param {Pattern} b
80
+ */
81
+ function compareSpecificity(a, b) {
82
+ const length = Math.max(a.score.length, b.score.length);
83
+
84
+ for (let i = 0; i < length; i++) {
85
+ const left = a.score[i] ?? -1;
86
+ const right = b.score[i] ?? -1;
87
+
88
+ if (left !== right) {
89
+ return right - left;
90
+ }
91
+ }
92
+
93
+ return 0;
94
+ }
95
+
96
+ /**
97
+ * Splits `/a/b/?x=1#y` into the path part and the untouched suffix.
98
+ * @param {string} value
99
+ */
100
+ function splitSuffix(value) {
101
+ const index = value.search(/[?#]/);
102
+
103
+ return index === -1 ? [value, ""] : [value.slice(0, index), value.slice(index)];
104
+ }
105
+
106
+ /**
107
+ * Match a path against a pattern.
108
+ * @param {Pattern} pattern
109
+ * @param {string[]} parts non-empty path segments
110
+ * @returns {Record<string, string> | null}
111
+ */
112
+ function matchPattern(pattern, parts) {
113
+ /** @type {Record<string, string>} */
114
+ const params = {};
115
+ const { segments } = pattern;
116
+ const last = segments[segments.length - 1];
117
+ const hasRest = last !== undefined && "rest" in last;
118
+ const fixed = hasRest ? segments.length - 1 : segments.length;
119
+
120
+ if (hasRest ? parts.length < fixed : parts.length !== fixed) {
121
+ return null;
122
+ }
123
+
124
+ for (let i = 0; i < fixed; i++) {
125
+ const segment = segments[i];
126
+
127
+ if ("literal" in segment) {
128
+ if (segment.literal !== parts[i]) {
129
+ return null;
130
+ }
131
+ } else if ("param" in segment) {
132
+ params[segment.param] = parts[i];
133
+ }
134
+ }
135
+
136
+ if (hasRest) {
137
+ params[/** @type {{ rest: string }} */ (last).rest] = parts.slice(fixed).join("/");
138
+ }
139
+
140
+ return params;
141
+ }
142
+
143
+ /**
144
+ * @param {Pattern} pattern
145
+ * @param {Record<string, string>} params
146
+ */
147
+ function fillPattern(pattern, params) {
148
+ const parts = [];
149
+
150
+ for (const segment of pattern.segments) {
151
+ if ("literal" in segment) {
152
+ parts.push(segment.literal);
153
+ } else {
154
+ const value = params["param" in segment ? segment.param : segment.rest];
155
+
156
+ if (value !== "") {
157
+ parts.push(value);
158
+ }
159
+ }
160
+ }
161
+
162
+ return "/" + parts.join("/");
163
+ }
164
+
165
+ /**
166
+ * @param {Pattern[]} patterns sorted, most specific first
167
+ * @param {string} path
168
+ * @returns {{ pattern: Pattern, params: Record<string, string>, trailingSlash: boolean, suffix: string } | null}
169
+ */
170
+ function findPattern(patterns, path) {
171
+ const [pathOnly, suffix] = splitSuffix(path);
172
+
173
+ if (!pathOnly.startsWith("/") || pathOnly.startsWith("//")) {
174
+ return null;
175
+ }
176
+
177
+ const parts = pathOnly.split("/").filter(Boolean);
178
+ const trailingSlash = parts.length > 0 && pathOnly.endsWith("/");
179
+
180
+ for (const pattern of patterns) {
181
+ const params = matchPattern(pattern, parts);
182
+
183
+ if (params) {
184
+ return { pattern, params, trailingSlash, suffix };
185
+ }
186
+ }
187
+
188
+ return null;
189
+ }
190
+
191
+ /**
192
+ * @param {{ pattern: Pattern, params: Record<string, string>, trailingSlash: boolean, suffix: string }} hit
193
+ * @param {Pattern} target
194
+ */
195
+ function rewrite(hit, target) {
196
+ const path = fillPattern(target, hit.params);
197
+
198
+ return path + (hit.trailingSlash && path !== "/" ? "/" : "") + hit.suffix;
199
+ }
200
+
201
+ /**
202
+ * @param {RouteMapConfig} [config]
203
+ * @returns {RouteMap}
204
+ */
205
+ export function createRouteMap({ rename = {}, disable = [] } = {}) {
206
+ /** @type {{ canonical: Pattern, public: Pattern }[]} */
207
+ const renames = [];
208
+ const publicSeen = new Map();
209
+
210
+ for (const [canonicalSource, publicSource] of Object.entries(rename ?? {})) {
211
+ const canonical = parsePattern(canonicalSource);
212
+ const publicPattern = parsePattern(publicSource);
213
+
214
+ const same =
215
+ canonical.names.length === publicPattern.names.length &&
216
+ canonical.names.every((name) => publicPattern.names.includes(name));
217
+
218
+ if (!same) {
219
+ throw new Error(
220
+ `Route rename "${canonicalSource}" -> "${publicSource}": both sides need the same params ` +
221
+ `([${canonical.names.join(", ")}] vs [${publicPattern.names.join(", ")}]).`,
222
+ );
223
+ }
224
+
225
+ // A rest param must stay a rest param (and a plain param a plain param), otherwise the
226
+ // reverse mapping would merge or split segments.
227
+ const kinds = (pattern) => pattern.segments.flatMap((s) => ("param" in s ? [`p:${s.param}`] : "rest" in s ? [`r:${s.rest}`] : []));
228
+ const left = kinds(canonical).sort().join(",");
229
+ const right = kinds(publicPattern).sort().join(",");
230
+
231
+ if (left !== right) {
232
+ throw new Error(`Route rename "${canonicalSource}" -> "${publicSource}": a [...rest] param must be a [...rest] param on both sides.`);
233
+ }
234
+
235
+ // `/a/[x]` and `/a/[y]` are the same public shape.
236
+ const shape = publicPattern.segments.map((s) => ("literal" in s ? s.literal : "param" in s ? "*" : "**")).join("/");
237
+
238
+ if (publicSeen.has(shape)) {
239
+ throw new Error(`Route rename: "${publicSource}" is the public path of both "${publicSeen.get(shape)}" and "${canonicalSource}".`);
240
+ }
241
+ publicSeen.set(shape, canonicalSource);
242
+
243
+ renames.push({ canonical, public: publicPattern });
244
+ }
245
+
246
+ const disabled = (disable ?? []).map(parsePattern).sort(compareSpecificity);
247
+
248
+ const byPublic = renames.map((r) => r.public).sort(compareSpecificity);
249
+ const byCanonical = renames.map((r) => r.canonical).sort(compareSpecificity);
250
+ const canonicalOfPublic = new Map(renames.map((r) => [r.public, r.canonical]));
251
+ const publicOfCanonical = new Map(renames.map((r) => [r.canonical, r.public]));
252
+
253
+ /** @param {string} path */
254
+ function mapToCanonical(path) {
255
+ const hit = findPattern(byPublic, path);
256
+
257
+ return hit ? rewrite(hit, /** @type {Pattern} */ (canonicalOfPublic.get(hit.pattern))) : path;
258
+ }
259
+
260
+ return {
261
+ /**
262
+ * Public pathname -> canonical pathname. `null` = the route is disabled. A canonical path
263
+ * that was renamed away is returned unchanged (the server answers it with a 308 and the
264
+ * client keeps resolving it).
265
+ * @param {string} pathname
266
+ * @returns {string | null}
267
+ */
268
+ toCanonical(pathname) {
269
+ const canonical = mapToCanonical(pathname);
270
+
271
+ return findPattern(disabled, canonical) ? null : canonical;
272
+ },
273
+
274
+ /**
275
+ * Canonical path -> public path. Anything that is not a site path (absolute URLs, `#top`,
276
+ * `mailto:`) and every path without a rename comes back as given; query and hash are kept.
277
+ * @param {string} canonicalPath
278
+ * @returns {string}
279
+ */
280
+ toPublic(canonicalPath) {
281
+ const hit = findPattern(byCanonical, canonicalPath);
282
+
283
+ return hit ? rewrite(hit, /** @type {Pattern} */ (publicOfCanonical.get(hit.pattern))) : canonicalPath;
284
+ },
285
+
286
+ /**
287
+ * True for a canonical path whose public path is different (and which is not itself a
288
+ * public path of another rename).
289
+ * @param {string} pathname
290
+ * @returns {boolean}
291
+ */
292
+ isRenamedAway(pathname) {
293
+ if (!findPattern(byCanonical, pathname)) {
294
+ return false;
295
+ }
296
+
297
+ return !findPattern(byPublic, pathname);
298
+ },
299
+ };
300
+ }
@@ -45,6 +45,9 @@ export const RUNTIME_SPECIFIERS = {
45
45
  "@panomc/sdk/variables": "sdk/variables.js",
46
46
  "@panomc/sdk/svelte": "sdk/svelte.js",
47
47
  "@panomc/sdk/internal": "sdk/internal.js",
48
+ "@panomc/sdk/views": "sdk/views.js",
49
+ "@panomc/sdk/controllers": "sdk/controllers.js",
50
+ "@panomc/sdk/utils/route": "sdk/utils-route.js",
48
51
  };
49
52
 
50
53
  /** Entries whose shim re-exports come from the svelte/svelte-i18n packages. */
@@ -40,6 +40,9 @@ export async function createSvelteConfig(themeMetaUrl, overrides = {}) {
40
40
  name: pkg.version,
41
41
  },
42
42
  ...overrides,
43
+ // `$contracts` -> plugin-contracts/ (the snapshots `theme-core contracts pull` keeps, doc 02 section 5.3):
44
+ // /** @type {import('$contracts/market/controllers.types.js').Controllers['market/cart']} */
45
+ alias: { $contracts: "plugin-contracts", ...(overrides.alias ?? {}) },
43
46
  },
44
47
 
45
48
  preprocess: SveltePreprocess({