@panomc/theme-core 1.0.0-dev.60 → 1.0.0-dev.62

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 +8 -9
  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 +79 -21
  36. package/src/kit/route-map.js +300 -0
  37. package/src/kit/specifiers.js +3 -62
  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
@@ -1,24 +1,81 @@
1
1
  /**
2
- * Theme config + view registry.
2
+ * Theme config + view registry (doc 01 §4): one resolution rule for engine
3
+ * views and plugin views.
3
4
  *
4
- * A theme declares overrides in its theme.config.js; the generated root layout
5
- * shim calls setThemeConfig() as a module side effect, so the registry is
6
- * populated on both server and client before any load function runs.
5
+ * A theme declares overrides in its theme.config.js (`views`); the generated
6
+ * root layout shim calls setThemeConfig() as a module side effect, so the
7
+ * registry is populated on the server and the client. Resolution waits for it
8
+ * because page and layout loads run in parallel.
7
9
  *
8
- * Core code never imports a theme's view directly — it resolves through
9
- * resolveView(name, defaultThunk):
10
- * - theme override registered → the theme's component wins
11
- * - otherwise → core's default view (code-split via the thunk)
10
+ * Core code never imports a theme's view directly. It resolves through
11
+ * resolveView(name, defaultThunk) / loadView(event, name, defaultThunk):
12
12
  *
13
- * If a theme override fails to load at runtime, the default view is used and
14
- * the failure is logged instead of crashing the page (graceful degradation —
15
- * the site keeps working while the theme author catches up with a core major).
13
+ * 1. `def` is the registered default (registerEngineViews / registerViews);
14
+ * a passed `defaultThunk` wins as the thunk, so the ~40 old callers keep
15
+ * working. No `def` -> null (the plugin is not installed).
16
+ * 2. `ov` = themeConfig.views[name]: a function -> { contract: 1, component },
17
+ * an object -> as is.
18
+ * 3. No `ov` -> the default. `ov.contract !== def.contract` -> the default and
19
+ * issue CONTRACT_MISMATCH. A controller named in `ov.controllers` whose theme
20
+ * pin differs from the registered controller version -> the default and
21
+ * issue CONTROLLER_MISMATCH. An override that fails to import -> the default
22
+ * and issue LOAD_FAILED.
23
+ * 4. Data always comes from the default: module = { ...defaultModule,
24
+ * default: Override ?? Default }. A `load` exported by an override is ignored.
25
+ * 5. Cached per name (not in dev). resetPluginViews() clears plugin entries.
26
+ *
27
+ * Plugin views are ids `<ns>:<Name>`; `<pluginId>:<Name>` is always accepted as
28
+ * an alias. Engine views keep bare names.
16
29
  */
17
30
 
31
+ import { dev } from "$app/environment";
32
+ import { blockKey } from "./view.js";
33
+
34
+ // `route()` (doc 01 section 9) is part of this module's public surface, so themes and plugins
35
+ // import it from `$pano/registry/index.js`; the implementation is `./routes.js`.
36
+ export { route } from "./routes.js";
37
+
38
+ // ---------------------------------------------------------------------------
39
+ // Theme config
40
+ // ---------------------------------------------------------------------------
41
+
18
42
  let themeConfig = {};
19
43
 
44
+ // SvelteKit runs the root layout and page loads in parallel, so a page load can
45
+ // call resolveView() before the root layout module (which calls setThemeConfig)
46
+ // finished evaluating. Resolution waits for this promise instead of reading an
47
+ // empty config. Safety valve: a theme that never registers gets the core
48
+ // defaults after READY_TIMEOUT_MS rather than a hung page.
49
+ const READY_TIMEOUT_MS = 5000;
50
+ let configured = false;
51
+ let markReady;
52
+ let ready;
53
+
54
+ function newReady() {
55
+ ready = new Promise((resolve) => {
56
+ markReady = resolve;
57
+ });
58
+ }
59
+ newReady();
60
+
20
61
  export function setThemeConfig(config) {
21
62
  themeConfig = config ?? {};
63
+ configured = true;
64
+ derived.config = null;
65
+ clearResolution();
66
+ markReady();
67
+ }
68
+
69
+ async function waitForThemeConfig() {
70
+ if (configured) return;
71
+ let timer;
72
+ await Promise.race([
73
+ ready,
74
+ new Promise((resolve) => {
75
+ timer = setTimeout(resolve, READY_TIMEOUT_MS);
76
+ }),
77
+ ]);
78
+ clearTimeout(timer);
22
79
  }
23
80
 
24
81
  export function getThemeConfig() {
@@ -30,57 +87,649 @@ export function getSettingsSchemaExtension() {
30
87
  return themeConfig.settingsSchema ?? null;
31
88
  }
32
89
 
33
- import { dev } from "$app/environment";
90
+ /**
91
+ * Does the theme ship Bootstrap / Font Awesome itself? false only for an exact
92
+ * `false` (doc 03 §4.1).
93
+ * @returns {{ bootstrap: boolean, fontawesome: boolean }}
94
+ */
95
+ export function getThemeProvides() {
96
+ const provides = themeConfig.provides ?? {};
97
+ return {
98
+ bootstrap: provides.bootstrap !== false,
99
+ fontawesome: provides.fontawesome !== false,
100
+ };
101
+ }
34
102
 
35
- const overrideCache = new Map();
103
+ // ---------------------------------------------------------------------------
104
+ // Theme meta (virtual:pano-theme-meta, doc 01 §4)
105
+ // ---------------------------------------------------------------------------
36
106
 
37
107
  /**
38
- * @param {string} name stable view id, e.g. "LoginView" — part of the theme contract
39
- * @param {() => Promise<any>} defaultThunk core's default view module thunk
40
- * @returns {Promise<any>} the Svelte component to render
108
+ * @typedef {{ id: string, props?: Record<string, string|number|boolean> }} Ref
109
+ * @typedef {{ refs?: Record<string, Ref[]>, claims?: string[], homePages?: Record<string, () => Promise<any>> }} ThemeMeta
41
110
  */
42
- export async function resolveView(name, defaultThunk) {
43
- const override = themeConfig.views?.[name];
44
-
45
- if (override) {
46
- // Never cache in dev: the cache would pin the module instance from the
47
- // first request, so view-file edits (and core fixes) would silently not
48
- // apply until a full dev-server restart. Vite already dedupes and
49
- // HMR-invalidates the underlying import() calls.
50
- if (dev) {
51
- return Promise.resolve(
52
- typeof override === "function" ? override() : override,
53
- ).then(
54
- (mod) => mod?.default ?? mod,
55
- (e) => {
56
- console.error(
57
- `[theme-core] view override '${name}' failed to load; falling back to the default view`,
58
- e,
59
- );
60
- return defaultThunk().then((m) => m?.default ?? m);
61
- },
111
+
112
+ /** @type {ThemeMeta} */
113
+ let themeMeta = { refs: {}, claims: [], homePages: {} };
114
+
115
+ /** @param {ThemeMeta | null | undefined} meta */
116
+ export function setThemeMeta(meta) {
117
+ themeMeta = {
118
+ refs: meta?.refs ?? {},
119
+ claims: meta?.claims ?? [],
120
+ homePages: meta?.homePages ?? {},
121
+ };
122
+ derived.refs = null;
123
+ derived.claims = null;
124
+ }
125
+
126
+ export function getThemeMeta() {
127
+ return themeMeta;
128
+ }
129
+
130
+ // ---------------------------------------------------------------------------
131
+ // Registered defaults
132
+ // ---------------------------------------------------------------------------
133
+
134
+ /**
135
+ * @typedef {{
136
+ * name?: string, pluginId?: string, ns?: string, contract?: number,
137
+ * kind?: "page"|"component"|"layout", component: () => Promise<any>,
138
+ * uses?: string[], slots?: string[], hooks?: string[], block?: boolean,
139
+ * inject?: object[]|null, page?: object|null, home?: object|null,
140
+ * }} ViewDef
141
+ */
142
+
143
+ /** @type {Map<string, ViewDef>} bare engine names */
144
+ const engineViews = new Map();
145
+ /** @type {Map<string, ViewDef>} `<ns>:<Name>` */
146
+ const pluginViews = new Map();
147
+ /** @type {Map<string, string>} ns -> pluginId that owns it (the namespace guard) */
148
+ const nsOwners = new Map();
149
+ /** @type {Map<string, string>} pluginId -> ns (the alias table) */
150
+ const pluginToNs = new Map();
151
+
152
+ // Bumped whenever the alias table changes; derived maps depend on it.
153
+ let aliasVersion = 0;
154
+
155
+ /** Memoised maps computed from themeConfig / themeMeta / the alias table. */
156
+ const derived = {
157
+ /** @type {null | { v: number, map: Map<string, any> }} */
158
+ config: null,
159
+ /** @type {null | { v: number, map: Map<string, Ref[]> }} */
160
+ refs: null,
161
+ /** @type {null | { v: number, set: Set<string> }} */
162
+ claims: null,
163
+ };
164
+
165
+ /**
166
+ * `<pluginId>:<Name>` -> `<ns>:<Name>`. Anything else is returned unchanged.
167
+ * A prefix that is itself a registered namespace wins over an alias.
168
+ * @param {string} name
169
+ */
170
+ function canonical(name) {
171
+ if (typeof name !== "string") return name;
172
+ const at = name.indexOf(":");
173
+ if (at <= 0) return name;
174
+ const prefix = name.slice(0, at);
175
+ if (nsOwners.has(prefix)) return name;
176
+ const ns = pluginToNs.get(prefix);
177
+ return ns ? ns + name.slice(at) : name;
178
+ }
179
+
180
+ /** @param {string} id */
181
+ function lookupDef(id) {
182
+ return pluginViews.get(id) ?? engineViews.get(id) ?? null;
183
+ }
184
+
185
+ /**
186
+ * Generated table of the engine's own views: `{ [name]: { contract, component } }`.
187
+ * @param {Record<string, { contract?: number, component: () => Promise<any>, uses?: string[], slots?: string[], hooks?: string[] }>} table
188
+ */
189
+ export function registerEngineViews(table) {
190
+ for (const [name, entry] of Object.entries(table ?? {})) {
191
+ engineViews.set(name, { ...entry, name, contract: entry.contract ?? 1 });
192
+ dropResolution(name);
193
+ }
194
+ }
195
+
196
+ /**
197
+ * From `pano.views.add` (doc 01 §3). A def whose namespace is owned by another
198
+ * pluginId is rejected with console.error (the clash guard of doc 01 §1).
199
+ * @param {ViewDef[]} defs
200
+ */
201
+ export function registerViews(defs) {
202
+ for (const def of defs ?? []) {
203
+ const name = def?.name;
204
+ const at = typeof name === "string" ? name.indexOf(":") : -1;
205
+ if (at <= 0 || typeof def.component !== "function") {
206
+ console.error(
207
+ `[theme-core] registerViews: '${name}' is not a plugin view id (<ns>:<Name>) with a component; ignored`,
208
+ );
209
+ continue;
210
+ }
211
+ const ns = name.slice(0, at);
212
+ if (def.ns && def.ns !== ns) {
213
+ console.error(
214
+ `[theme-core] registerViews: '${name}' declares namespace '${def.ns}'; ignored`,
215
+ );
216
+ continue;
217
+ }
218
+ const owner = nsOwners.get(ns);
219
+ if (owner && owner !== def.pluginId) {
220
+ console.error(
221
+ `[theme-core] registerViews: namespace '${ns}' is owned by '${owner}', '${name}' of '${def.pluginId}' is rejected (NAMESPACE_CLASH)`,
62
222
  );
223
+ continue;
63
224
  }
225
+ if (!owner) {
226
+ nsOwners.set(ns, def.pluginId);
227
+ aliasVersion++;
228
+ }
229
+ if (def.pluginId && pluginToNs.get(def.pluginId) !== ns) {
230
+ pluginToNs.set(def.pluginId, ns);
231
+ aliasVersion++;
232
+ }
233
+ pluginViews.set(name, { ...def, ns, contract: def.contract ?? 1 });
234
+ dropResolution(name);
235
+ }
236
+ }
237
+
238
+ /** Called by the plugin API's init(): forget every plugin view and namespace. */
239
+ export function resetPluginViews() {
240
+ const ids = [...pluginViews.keys()];
241
+ pluginViews.clear();
242
+ nsOwners.clear();
243
+ pluginToNs.clear();
244
+ aliasVersion++;
245
+ for (const id of ids) dropResolution(id);
246
+ const gone = new Set(ids);
247
+ for (const [key, issue] of [...issues]) {
248
+ if (gone.has(issue.view)) issues.delete(key);
249
+ }
250
+ }
251
+
252
+ /** @param {string} name */
253
+ export function hasView(name) {
254
+ return lookupDef(canonical(name)) !== null;
255
+ }
256
+
257
+ // ---------------------------------------------------------------------------
258
+ // Overrides
259
+ // ---------------------------------------------------------------------------
260
+
261
+ /**
262
+ * `themeConfig.views` keyed by canonical id, every entry in the object form
263
+ * `{ contract, controllers, component }` (a function is `{ contract: 1 }`; a bare
264
+ * module object stays supported as the old "non-function override").
265
+ */
266
+ function overrideMap() {
267
+ if (derived.config && derived.config.v === aliasVersion) return derived.config.map;
268
+ const map = new Map();
269
+ const views = themeConfig.views ?? {};
270
+ for (const key of Object.keys(views)) {
271
+ const raw = views[key];
272
+ if (!raw) continue;
273
+ let entry;
274
+ if (typeof raw === "function") entry = { contract: 1, component: raw };
275
+ else if (typeof raw === "object" && typeof raw.component === "function")
276
+ entry = { contract: raw.contract ?? 1, controllers: raw.controllers ?? [], component: raw.component };
277
+ else entry = { contract: 1, component: () => raw };
278
+ const id = canonical(key);
279
+ // an exact-name key beats an alias spelling of the same view
280
+ if (!map.has(id) || id === key) map.set(id, entry);
281
+ }
282
+ derived.config = { v: aliasVersion, map };
283
+ return map;
284
+ }
285
+
286
+ /** @returns {Map<string, Ref[]>} override / "route:<path>" / "home:<id>" -> refs */
287
+ function refsMap() {
288
+ if (derived.refs && derived.refs.v === aliasVersion) return derived.refs.map;
289
+ const map = new Map();
290
+ for (const [key, refs] of Object.entries(themeMeta.refs ?? {})) {
291
+ const id = canonical(key);
292
+ map.set(id, [...(map.get(id) ?? []), ...(refs ?? [])]);
293
+ }
294
+ derived.refs = { v: aliasVersion, map };
295
+ return map;
296
+ }
297
+
298
+ /**
299
+ * Ids the theme places itself, so the automatic copy must disappear (doc 01 §5):
300
+ * the scan's literal ids plus `themeConfig.claims`; an explicit `false` wins.
301
+ * @returns {Set<string>}
302
+ */
303
+ export function getClaims() {
304
+ if (derived.claims && derived.claims.v === aliasVersion) return derived.claims.set;
305
+ const set = new Set();
306
+ const add = (id) => {
307
+ set.add(id);
308
+ set.add(canonical(id));
309
+ };
310
+ for (const id of themeMeta.claims ?? []) add(id);
311
+ for (const [id, value] of Object.entries(themeConfig.claims ?? {})) {
312
+ if (value === false) {
313
+ set.delete(id);
314
+ set.delete(canonical(id));
315
+ } else if (value) add(id);
316
+ }
317
+ derived.claims = { v: aliasVersion, set };
318
+ return set;
319
+ }
320
+
321
+ // ---------------------------------------------------------------------------
322
+ // Controller versions (doc 02 §2) read through globalThis.__PANO_CONTROLLERS__
323
+ // ---------------------------------------------------------------------------
324
+
325
+ /**
326
+ * The registered version of a controller, `undefined` when it is not
327
+ * registered or the registry is absent. Tolerant about the registry's shape:
328
+ * a `list()` result, or a Map / plain object of definitions.
329
+ * @param {string} name
330
+ * @returns {number | string | undefined}
331
+ */
332
+ function registeredControllerVersion(name) {
333
+ const state = globalThis.__PANO_CONTROLLERS__;
334
+ if (!state) return undefined;
335
+ try {
336
+ if (typeof state.list === "function") {
337
+ const hit = state.list().find((c) => c?.name === name);
338
+ if (hit) return hit.version;
339
+ }
340
+ for (const holder of [state, state.definitions, state.defs, state.controllers, state.registry]) {
341
+ if (!holder) continue;
342
+ const entry = holder instanceof Map ? holder.get(name) : holder[name];
343
+ if (entry && typeof entry === "object" && "version" in entry) return entry.version;
344
+ }
345
+ } catch {
346
+ /* an unreadable registry means no opinion */
347
+ }
348
+ return undefined;
349
+ }
350
+
351
+ // ---------------------------------------------------------------------------
352
+ // Issues
353
+ // ---------------------------------------------------------------------------
354
+
355
+ /** @type {Map<string, any>} */
356
+ const issues = new Map();
357
+
358
+ function report(issue, message) {
359
+ const key = `${issue.type}:${issue.view}:${issue.controller ?? ""}`;
360
+ if (issues.has(key)) return;
361
+ issues.set(key, issue);
362
+ if (dev) console.warn(`[theme-core] ${message}`);
363
+ }
364
+
365
+ /** @returns {Array<{ type: string, view: string, [k: string]: any }>} */
366
+ export function getIssues() {
367
+ return [...issues.values()];
368
+ }
64
369
 
65
- let cached = overrideCache.get(name);
66
- if (!cached) {
67
- cached = Promise.resolve(
68
- typeof override === "function" ? override() : override,
69
- ).then(
70
- (mod) => mod?.default ?? mod,
71
- (e) => {
370
+ // ---------------------------------------------------------------------------
371
+ // Resolution
372
+ // ---------------------------------------------------------------------------
373
+
374
+ /** @type {Map<string, Promise<ResolvedView | null>>} */
375
+ const resolved = new Map();
376
+ /** Sync caches for proxies / PluginBlock: filled by every resolution. */
377
+ const overrideComponents = new Map();
378
+ const defaultComponents = new Map();
379
+ /** @type {Map<string, "default"|"override"|"fallback">} */
380
+ const statuses = new Map();
381
+
382
+ /** @typedef {{ module: any, source: "override"|"default", contract: number }} ResolvedView */
383
+
384
+ function dropResolution(id) {
385
+ resolved.delete(id);
386
+ overrideComponents.delete(id);
387
+ defaultComponents.delete(id);
388
+ statuses.delete(id);
389
+ }
390
+
391
+ function clearResolution() {
392
+ resolved.clear();
393
+ overrideComponents.clear();
394
+ defaultComponents.clear();
395
+ statuses.clear();
396
+ }
397
+
398
+ /**
399
+ * @param {string} id canonical
400
+ * @param {(() => Promise<any>) | undefined} thunk
401
+ * @returns {Promise<ResolvedView | null>}
402
+ */
403
+ async function resolveNow(id, thunk) {
404
+ const registered = lookupDef(id);
405
+ /** @type {ViewDef | null} */
406
+ const def =
407
+ typeof thunk === "function"
408
+ ? { ...registered, name: id, contract: registered?.contract ?? 1, component: thunk }
409
+ : registered;
410
+ if (!def) return null;
411
+
412
+ const defaultModule = await def.component();
413
+ const Default = defaultModule?.default ?? defaultModule;
414
+ defaultComponents.set(id, Default);
415
+
416
+ const ov = overrideMap().get(id);
417
+ /** @type {any} */
418
+ let Override = null;
419
+ if (ov) {
420
+ const where = def.pluginId ? { pluginId: def.pluginId } : {};
421
+ const themeContract = ov.contract ?? 1;
422
+ if (themeContract !== def.contract) {
423
+ report(
424
+ { type: "CONTRACT_MISMATCH", view: id, ...where, themeContract, currentContract: def.contract },
425
+ `override of '${id}' was written for contract ${themeContract}, the view is at ${def.contract}; showing the default view`,
426
+ );
427
+ } else {
428
+ let mismatch = null;
429
+ for (const controller of ov.controllers ?? []) {
430
+ const pin = themeConfig.controllers?.[controller];
431
+ const current = registeredControllerVersion(controller);
432
+ if (pin !== undefined && current !== undefined && pin !== current) {
433
+ mismatch = { controller, themeVersion: pin, currentVersion: current };
434
+ break;
435
+ }
436
+ }
437
+ if (mismatch) {
438
+ report(
439
+ { type: "CONTROLLER_MISMATCH", view: id, ...where, ...mismatch },
440
+ `override of '${id}' pins controller '${mismatch.controller}' at ${mismatch.themeVersion}, the plugin is at ${mismatch.currentVersion}; showing the default view`,
441
+ );
442
+ } else {
443
+ try {
444
+ const mod = await ov.component();
445
+ Override = mod?.default ?? mod;
446
+ if (!Override) throw new Error("the override module has no default export");
447
+ } catch (e) {
448
+ Override = null;
72
449
  console.error(
73
- `[theme-core] view override '${name}' failed to load; falling back to the default view`,
450
+ `[theme-core] view override '${id}' failed to load; falling back to the default view`,
74
451
  e,
75
452
  );
76
- overrideCache.delete(name);
77
- return defaultThunk().then((m) => m?.default ?? m);
78
- },
79
- );
80
- overrideCache.set(name, cached);
453
+ report(
454
+ { type: "LOAD_FAILED", view: id, ...where, error: String(e?.message ?? e) },
455
+ `override of '${id}' failed to load; showing the default view`,
456
+ );
457
+ }
458
+ }
81
459
  }
82
- return cached;
83
460
  }
84
461
 
85
- return defaultThunk().then((m) => m?.default ?? m);
462
+ overrideComponents.set(id, Override);
463
+ statuses.set(id, Override ? "override" : ov ? "fallback" : "default");
464
+
465
+ // Rule 4: data (`load`, controller load) is always the default module's.
466
+ const module =
467
+ defaultModule !== null && typeof defaultModule === "object"
468
+ ? { ...defaultModule, default: Override ?? Default }
469
+ : { default: Override ?? Default };
470
+
471
+ return {
472
+ module,
473
+ source: Override ? "override" : "default",
474
+ contract: Override ? (ov?.contract ?? 1) : def.contract,
475
+ };
476
+ }
477
+
478
+ /**
479
+ * @param {string} name stable view id: "LoginView", "market:ProductCard" or "<pluginId>:ProductCard"
480
+ * @param {() => Promise<any>} [defaultThunk] the default view module thunk
481
+ * @returns {Promise<ResolvedView | null>} null = unknown name (plugin not installed)
482
+ */
483
+ export async function resolveViewModule(name, defaultThunk) {
484
+ await waitForThemeConfig();
485
+ const id = canonical(name);
486
+
487
+ // Never cache in dev: the cache would pin the module instance from the first
488
+ // request, so view-file edits (and core fixes) would silently not apply until
489
+ // a full dev-server restart. Vite already dedupes and HMR-invalidates import().
490
+ if (!dev) {
491
+ const cached = resolved.get(id);
492
+ if (cached) return cached;
493
+ }
494
+ const pending = resolveNow(id, defaultThunk);
495
+ if (!dev) {
496
+ resolved.set(id, pending);
497
+ pending.then(
498
+ (result) => {
499
+ if (!result && resolved.get(id) === pending) resolved.delete(id);
500
+ },
501
+ () => {
502
+ if (resolved.get(id) === pending) resolved.delete(id);
503
+ },
504
+ );
505
+ }
506
+ return pending;
507
+ }
508
+
509
+ /**
510
+ * @param {string} name stable view id, e.g. "LoginView" — part of the theme contract
511
+ * @param {() => Promise<any>} [defaultThunk] core's default view module thunk
512
+ * @returns {Promise<any>} the Svelte component to render (null for an unknown name)
513
+ */
514
+ export async function resolveView(name, defaultThunk) {
515
+ const result = await resolveViewModule(name, defaultThunk);
516
+ return result ? result.module.default : null;
517
+ }
518
+
519
+ /** Loaded override component, sync. null = no (valid) override or not loaded yet. */
520
+ export function getOverride(name) {
521
+ return overrideComponents.get(canonical(name)) ?? null;
522
+ }
523
+
524
+ /** Loaded default component, sync. null = not loaded yet or unknown. */
525
+ export function getDefault(name) {
526
+ return defaultComponents.get(canonical(name)) ?? null;
527
+ }
528
+
529
+ /**
530
+ * @param {string} name
531
+ * @returns {{ contract: number, block: boolean, overridden: boolean, overrideContract: number|null, status: "default"|"override"|"fallback" } | null}
532
+ */
533
+ export function describeView(name) {
534
+ const id = canonical(name);
535
+ const def = lookupDef(id);
536
+ if (!def) return null;
537
+ const ov = overrideMap().get(id);
538
+ return {
539
+ contract: def.contract ?? 1,
540
+ block: Boolean(def.block),
541
+ overridden: Boolean(ov),
542
+ overrideContract: ov ? (ov.contract ?? 1) : null,
543
+ status: statuses.get(id) ?? (ov ? "fallback" : "default"),
544
+ };
545
+ }
546
+
547
+ // ---------------------------------------------------------------------------
548
+ // Closure: preload + block loads + slot loads
549
+ // ---------------------------------------------------------------------------
550
+
551
+ /** Plugin slot ids are `<ns>:<slot>`; engine ids keep today's bare names. */
552
+ const isPluginSlot = (id) => typeof id === "string" && id.includes(":");
553
+
554
+ /** `route:<path>` and `home:<id>` are meta keys, not views. */
555
+ const isMetaKey = (id) => /^(route|home):/.test(id);
556
+
557
+ /**
558
+ * Resolves `rootName` and everything it renders: an overridden view -> the refs
559
+ * the theme-meta scan found in it; a default view -> its `uses`.
560
+ * @param {string} rootName
561
+ * @param {(() => Promise<any>) | undefined} rootThunk
562
+ */
563
+ async function walkClosure(rootName, rootThunk) {
564
+ /** @type {Map<string, { id: string, res: ResolvedView | null, def: ViewDef | null }>} */
565
+ const nodes = new Map();
566
+ /** @type {Ref[]} */
567
+ const refs = [];
568
+ const refsByView = refsMap();
569
+
570
+ async function visit(name, thunk, isRoot) {
571
+ const id = canonical(name);
572
+ if (nodes.has(id)) return;
573
+ nodes.set(id, { id, res: null, def: null });
574
+
575
+ if (isMetaKey(id)) {
576
+ const own = refsByView.get(id) ?? [];
577
+ refs.push(...own);
578
+ await Promise.all(own.map((ref) => visit(ref.id, undefined, false)));
579
+ return;
580
+ }
581
+
582
+ let res;
583
+ try {
584
+ res = await resolveViewModule(id, thunk);
585
+ } catch (e) {
586
+ if (isRoot) throw e;
587
+ console.warn(`[theme-core] could not preload view '${id}'`, e);
588
+ return;
589
+ }
590
+ const def = lookupDef(id);
591
+ nodes.set(id, { id, res, def });
592
+ if (!res) return;
593
+
594
+ let children;
595
+ if (res.source === "override") {
596
+ children = refsByView.get(id) ?? [];
597
+ refs.push(...children);
598
+ } else {
599
+ children = (def?.uses ?? []).map((use) => ({ id: use }));
600
+ }
601
+ await Promise.all(children.map((child) => visit(child.id, undefined, false)));
602
+ }
603
+
604
+ await visit(rootName, rootThunk, true);
605
+ return { nodes, refs, rootId: canonical(rootName) };
606
+ }
607
+
608
+ /**
609
+ * Resolves the given names and their closure into the sync cache that
610
+ * getOverride / getDefault read.
611
+ * @param {string[]} names
612
+ */
613
+ export async function preloadViews(names) {
614
+ await Promise.all(
615
+ (names ?? []).map(async (name) => {
616
+ try {
617
+ await walkClosure(name, undefined);
618
+ } catch (e) {
619
+ console.warn(`[theme-core] could not preload view '${name}'`, e);
620
+ }
621
+ }),
622
+ );
623
+ }
624
+
625
+ /**
626
+ * Module for an injection: the preloaded view module (override markup, the
627
+ * default's `load`). null when the id is unknown.
628
+ * @param {string} id
629
+ */
630
+ export async function loadForInjection(id) {
631
+ await preloadViews([id]);
632
+ const result = await resolveViewModule(id);
633
+ // A plain copy that names the view (and where the markup came from), so `views.wrapInjected` can give the
634
+ // injection its plugin's fallback scope (doc 03 section 4.4). The registry's own module is left alone.
635
+ return result ? { ...result.module, __panoView: canonical(id), __panoSource: result.source } : null;
636
+ }
637
+
638
+ /** @type {((slotId: string, event: any) => Promise<any>) | null} */
639
+ let slotLoader = null;
640
+
641
+ /**
642
+ * Overrides what runs a plugin slot's load (default: `executeViewLoad` of the
643
+ * plugin API, imported on first use so this file has no static dependency on it).
644
+ * @param {((slotId: string, event: any) => Promise<any>) | null} fn
645
+ */
646
+ export function setSlotLoader(fn) {
647
+ slotLoader = fn;
648
+ }
649
+
650
+ async function runSlotLoad(slotId, event) {
651
+ try {
652
+ const run = slotLoader ?? (await import("../lib/PluginAPI.js")).executeViewLoad;
653
+ await run(slotId, event);
654
+ } catch (e) {
655
+ console.warn(`[theme-core] load of slot '${slotId}' failed`, e);
656
+ }
657
+ }
658
+
659
+ /**
660
+ * Resolves a view for a page / layout controller:
661
+ * `{ View, "block:<key>": data, ... }`.
662
+ *
663
+ * Over the closure of `name` it also runs the `load` of every distinct
664
+ * `<PluginBlock>` placement (one per `blockKey`) and the load of each plugin slot
665
+ * a visited view opens, so injected parts are server-rendered.
666
+ * @param {any} event SvelteKit load event
667
+ * @param {string} name
668
+ * @param {() => Promise<any>} [defaultThunk]
669
+ * @returns {Promise<{ View: any } & Record<string, any>>}
670
+ */
671
+ export async function loadView(event, name, defaultThunk) {
672
+ await waitForThemeConfig();
673
+ const { nodes, refs, rootId } = await walkClosure(name, defaultThunk);
674
+ const root = nodes.get(rootId);
675
+ /** @type {Record<string, any>} */
676
+ const out = { View: root?.res ? root.res.module.default : null };
677
+
678
+ /** @type {Map<string, { ref: Ref, node: any }>} */
679
+ const blocks = new Map();
680
+ for (const ref of refs) {
681
+ const node = nodes.get(canonical(ref.id));
682
+ if (!node?.res || !node.def?.block) continue;
683
+ const key = blockKey(ref.id, ref.props);
684
+ if (!blocks.has(key)) blocks.set(key, { ref, node });
685
+ }
686
+
687
+ const slots = new Set();
688
+ for (const node of nodes.values()) {
689
+ for (const slot of node.def?.slots ?? []) if (isPluginSlot(slot)) slots.add(slot);
690
+ }
691
+
692
+ await Promise.all([
693
+ ...[...blocks].map(async ([key, { ref, node }]) => {
694
+ const mod = node.res.module;
695
+ const load = mod?.load ?? mod?.default?.load;
696
+ if (typeof load !== "function") {
697
+ out[key] = {};
698
+ return;
699
+ }
700
+ try {
701
+ const data = await load(event, ref.props ?? {});
702
+ out[key] = data ?? {};
703
+ } catch (e) {
704
+ console.warn(`[theme-core] load of block '${ref.id}' failed`, e);
705
+ }
706
+ }),
707
+ ...[...slots].map((slot) => runSlotLoad(slot, event)),
708
+ ]);
709
+
710
+ return out;
711
+ }
712
+
713
+ // ---------------------------------------------------------------------------
714
+ // Test support
715
+ // ---------------------------------------------------------------------------
716
+
717
+ /**
718
+ * Returns the registry to its pristine state (config, meta, every registered
719
+ * view, caches, issues, the config-ready latch). Tests only.
720
+ */
721
+ export function resetRegistryForTests() {
722
+ themeConfig = {};
723
+ themeMeta = { refs: {}, claims: [], homePages: {} };
724
+ engineViews.clear();
725
+ pluginViews.clear();
726
+ nsOwners.clear();
727
+ pluginToNs.clear();
728
+ aliasVersion++;
729
+ derived.config = derived.refs = derived.claims = null;
730
+ clearResolution();
731
+ issues.clear();
732
+ slotLoader = null;
733
+ configured = false;
734
+ newReady();
86
735
  }