@panomc/theme-core 1.0.0-dev.60 → 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.
- package/assets/css/pano-fallback-legacy.css +12381 -0
- package/assets/css/pano-fallback.css +3222 -0
- package/bin/__tests__/check/fixtures/plugin-contracts/market/controllers.json +4 -0
- package/bin/__tests__/check/fixtures/plugin-contracts/market/views.json +67 -0
- package/bin/__tests__/check/fixtures/routes.json +5 -0
- package/bin/__tests__/check/helpers.js +55 -0
- package/bin/__tests__/check/overrides.test.js +287 -0
- package/bin/__tests__/check/theme.test.js +332 -0
- package/bin/__tests__/cli/accept-and-list.test.js +159 -0
- package/bin/__tests__/cli/config-edit.test.js +213 -0
- package/bin/__tests__/cli/contracts-pull.test.js +187 -0
- package/bin/__tests__/cli/core-meta.test.js +305 -0
- package/bin/__tests__/cli/eject-view.test.js +356 -0
- package/bin/__tests__/cli/helpers.js +258 -0
- package/bin/__tests__/scaffold/scaffold.test.js +84 -0
- package/bin/bundle-internal-libs.js +14 -2
- package/bin/check.js +1150 -213
- package/bin/contracts.js +1643 -0
- package/bin/generate-contract.js +378 -0
- package/bin/generate-licenses.js +14 -2
- package/bin/generate-runtime-shims.js +27 -9
- package/bin/new.js +101 -2
- package/bin/package-zip.js +16 -2
- package/bin/sync.js +360 -7
- package/bin/theme-core.js +65 -107
- package/lang/en-US.json +1 -0
- package/lang/ru.json +1 -0
- package/lang/tr.json +1 -0
- package/package.json +7 -3
- package/skin-contract.json +864 -19
- package/src/kit/__tests__/hooks-server-fetch.test.js +56 -0
- package/src/kit/__tests__/route-map.test.js +154 -0
- package/src/kit/__tests__/theme-meta.test.js +249 -0
- package/src/kit/hooks-client.js +3 -0
- package/src/kit/hooks-server.js +79 -21
- package/src/kit/route-map.js +300 -0
- package/src/kit/specifiers.js +3 -0
- package/src/kit/svelte-config.js +3 -0
- package/src/kit/theme-meta.js +405 -0
- package/src/kit/vite-config.js +156 -12
- package/src/lib/NotificationManager.js +18 -0
- package/src/lib/PluginAPI.js +313 -9
- package/src/lib/Store.js +18 -5
- package/src/lib/__tests__/avatarVersion.test.js +25 -0
- package/src/lib/__tests__/check.test.js +201 -0
- package/src/lib/__tests__/controllerHost.test.js +363 -0
- package/src/lib/__tests__/cx03.test.js +245 -0
- package/src/lib/__tests__/engineBoot.test.js +151 -0
- package/src/lib/__tests__/engineParts.helper.js +284 -0
- package/src/lib/__tests__/engineParts.test.js +179 -0
- package/src/lib/__tests__/engineSidebars.helper.js +353 -0
- package/src/lib/__tests__/engineSidebars.test.js +273 -0
- package/src/lib/__tests__/engineStyles.test.js +227 -0
- package/src/lib/__tests__/engineWiring.test.js +1000 -0
- package/src/lib/__tests__/fallbackStyles.test.js +1254 -0
- package/src/lib/__tests__/fixtures/Probe.svelte +5 -0
- package/src/lib/__tests__/fixtures/engine-parts.ssr.json +29 -0
- package/src/lib/__tests__/fixtures/engine-sidebars.ssr.json +16 -0
- package/src/lib/__tests__/home.test.js +563 -0
- package/src/lib/__tests__/injectedScope.test.js +490 -0
- package/src/lib/__tests__/languageConcurrency.test.js +55 -0
- package/src/lib/__tests__/languageLayers.test.js +286 -0
- package/src/lib/__tests__/pageHead.test.js +167 -0
- package/src/lib/__tests__/pageMeta.util.test.js +216 -0
- package/src/lib/__tests__/pageTitle.util.test.js +96 -0
- package/src/lib/__tests__/pluginApiViews.test.js +529 -0
- package/src/lib/__tests__/plugins.test.js +53 -0
- package/src/lib/__tests__/profileNav.util.test.js +145 -0
- package/src/lib/__tests__/registryReady.test.js +26 -0
- package/src/lib/__tests__/returnTo.util.test.js +294 -0
- package/src/lib/__tests__/routeConfig.test.js +361 -0
- package/src/lib/__tests__/sidebarSpec.util.test.js +152 -0
- package/src/lib/__tests__/skinContract.test.js +558 -0
- package/src/lib/__tests__/svelteSsr.helper.js +68 -0
- package/src/lib/__tests__/tc03.test.js +427 -0
- package/src/lib/__tests__/tc11.test.js +184 -0
- package/src/lib/__tests__/translationLayers.test.js +161 -0
- package/src/lib/avatarVersion.js +39 -0
- package/src/lib/components/Breadcrumb.svelte +9 -40
- package/src/lib/components/Date.svelte +1 -1
- package/src/lib/components/DefaultToast.svelte +13 -3
- package/src/lib/components/FallbackLinks.svelte +28 -0
- package/src/lib/components/FallbackScope.svelte +24 -0
- package/src/lib/components/Footer.svelte +8 -8
- package/src/lib/components/Header.svelte +3 -3
- package/src/lib/components/Hook.svelte +12 -1
- package/src/lib/components/LoginFormBody.svelte +5 -5
- package/src/lib/components/Main.svelte +22 -47
- package/src/lib/components/Navbar.svelte +30 -29
- package/src/lib/components/NoContent.svelte +2 -2
- package/src/lib/components/NotificationContainer.svelte +31 -82
- package/src/lib/components/OnlineAdmins.svelte +3 -2
- package/src/lib/components/PageActions.svelte +1 -1
- package/src/lib/components/PageHead.svelte +50 -0
- package/src/lib/components/PageTitle.svelte +2 -2
- package/src/lib/components/Pagination.svelte +6 -6
- package/src/lib/components/PlayerHead.svelte +4 -4
- package/src/lib/components/PluginBlock.svelte +132 -0
- package/src/lib/components/PluginSlot.svelte +40 -0
- package/src/lib/components/Post.svelte +13 -230
- package/src/lib/components/Posts.svelte +7 -14
- package/src/lib/components/RegisterForm.svelte +12 -11
- package/src/lib/components/Sidebar.svelte +9 -7
- package/src/lib/components/TicketRow.svelte +8 -48
- package/src/lib/components/TicketStatus.svelte +10 -16
- package/src/lib/components/Tickets.svelte +8 -30
- package/src/lib/components/Toast.svelte +16 -14
- package/src/lib/components/ToastContainer.svelte +16 -9
- package/src/lib/components/ViewComponent.svelte +13 -1
- package/src/lib/components/modals/CloseTicketConfirmModal.svelte +15 -46
- package/src/lib/components/modals/ConfirmRemoveAllNotificationsModal.svelte +17 -39
- package/src/lib/components/modals/LogoutSessionConfirmModal.svelte +12 -30
- package/src/lib/components/sidebars/HomeSidebar.svelte +33 -284
- package/src/lib/components/sidebars/PlayerDetailSidebar.svelte +14 -63
- package/src/lib/components/sidebars/PluginSidebar.svelte +21 -0
- package/src/lib/components/sidebars/ProfileNavCard.svelte +24 -0
- package/src/lib/components/sidebars/ProfileSidebar.svelte +44 -84
- package/src/lib/components/sidebars/SupportSidebar.svelte +19 -22
- package/src/lib/components/sidebars/TicketCreateAndDetailSidebar.svelte +23 -35
- package/src/lib/components/sidebars/profileNav.util.js +105 -0
- package/src/lib/components/sidebars/sidebarSpec.util.js +92 -0
- package/src/lib/controllerHost.js +261 -0
- package/src/lib/fallbackStyles.js +317 -0
- package/src/lib/home.js +202 -0
- package/src/lib/language.util.js +70 -37
- package/src/lib/layouts/AppLayout.svelte +16 -8
- package/src/lib/layouts/AuthLayout.svelte +6 -4
- package/src/lib/layouts/MainLayout.svelte +17 -12
- package/src/lib/layouts/ProfileLayout.svelte +6 -4
- package/src/lib/layouts/ThemeSettingsLayout.svelte +6 -4
- package/src/lib/layouts/TicketsLayout.svelte +6 -5
- package/src/lib/pageMeta.util.js +212 -0
- package/src/lib/pageShape.js +33 -0
- package/src/lib/pageTitle.util.js +32 -0
- package/src/lib/pages/ActivateEmailPage.svelte +2 -7
- package/src/lib/pages/ConfirmNewEmailPage.svelte +2 -7
- package/src/lib/pages/ErrorPage.svelte +5 -2
- package/src/lib/pages/HomePage.svelte +31 -8
- package/src/lib/pages/LoginPage.svelte +38 -41
- package/src/lib/pages/NotificationsPage.svelte +2 -7
- package/src/lib/pages/PlayerDetailPage.svelte +2 -7
- package/src/lib/pages/PostDetailPage.svelte +2 -7
- package/src/lib/pages/PreviewPostPage.svelte +2 -7
- package/src/lib/pages/RegisterPage.svelte +10 -13
- package/src/lib/pages/RenewPasswordPage.svelte +2 -7
- package/src/lib/pages/ResetPasswordPage.svelte +2 -7
- package/src/lib/pages/RulesPage.svelte +3 -8
- package/src/lib/pages/SupportPage.svelte +2 -7
- package/src/lib/pages/ThemeSettingsPage.svelte +2 -7
- package/src/lib/pages/profile/ProfilePage.svelte +2 -7
- package/src/lib/pages/profile/SettingsPage.svelte +2 -7
- package/src/lib/pages/profile/TicketsPage.svelte +2 -7
- package/src/lib/pages/ticket/CreateTicketPage.svelte +2 -7
- package/src/lib/pages/ticket/TicketDetailPage.svelte +2 -7
- package/src/lib/plugins.js +61 -0
- package/src/lib/returnTo.util.js +116 -0
- package/src/lib/services/auth.js +11 -11
- package/src/lib/services/posts.js +21 -10
- package/src/lib/services/profile.js +5 -5
- package/src/lib/services/theme-setting.js +1 -1
- package/src/lib/services/tickets.js +36 -15
- package/src/lib/siteRealtime.js +55 -8
- package/src/lib/themePageLoad.js +38 -0
- package/src/lib/translationLayers.js +144 -0
- package/src/lib/ui-logics/layout-logics/AppLayoutLogics.js +160 -6
- package/src/lib/ui-logics/layout-logics/AuthLayoutLogics.js +3 -2
- package/src/lib/ui-logics/layout-logics/ProfileLayoutLogics.js +3 -2
- package/src/lib/ui-logics/layout-logics/TicketsLayoutLogics.js +3 -2
- package/src/lib/ui-logics/page-logics/ActiveEmailPageLogics.js +4 -4
- package/src/lib/ui-logics/page-logics/ConfirmNewEmailPageLogics.js +4 -4
- package/src/lib/ui-logics/page-logics/CreateTicketPageLogics.js +5 -5
- package/src/lib/ui-logics/page-logics/HomePageLogics.js +5 -3
- package/src/lib/ui-logics/page-logics/NotificationsPageLogics.js +40 -16
- package/src/lib/ui-logics/page-logics/PlayerDetailPageLogics.js +3 -3
- package/src/lib/ui-logics/page-logics/PostDetailPageLogics.js +3 -3
- package/src/lib/ui-logics/page-logics/PreviewPostPageLogics.js +1 -1
- package/src/lib/ui-logics/page-logics/RenewPasswordPageLogics.js +4 -4
- package/src/lib/ui-logics/page-logics/ResetPasswordPageLogics.js +6 -6
- package/src/lib/ui-logics/page-logics/SettingsPageLogics.js +8 -8
- package/src/lib/ui-logics/page-logics/TicketDetailPageLogics.js +3 -3
- package/src/lib/ui-logics/page-logics/TicketsPageLogics.js +5 -3
- package/src/lib/views/ActivateEmailView.samples.js +22 -0
- package/src/lib/views/ActivateEmailView.svelte +4 -4
- package/src/lib/views/AppLayoutView.samples.js +17 -0
- package/src/lib/views/AppLayoutView.svelte +1 -1
- package/src/lib/views/AuthLayoutView.samples.js +4 -0
- package/src/lib/views/AuthLayoutView.svelte +1 -1
- package/src/lib/views/Breadcrumb.samples.js +15 -0
- package/src/lib/views/CloseTicketConfirmModal.samples.js +12 -0
- package/src/lib/views/ConfirmNewEmailView.samples.js +22 -0
- package/src/lib/views/ConfirmNewEmailView.svelte +4 -4
- package/src/lib/views/ConfirmRemoveAllNotificationsModal.samples.js +9 -0
- package/src/lib/views/CreateTicketView.samples.js +21 -0
- package/src/lib/views/CreateTicketView.svelte +5 -5
- package/src/lib/views/Date.samples.js +9 -0
- package/src/lib/views/DefaultToast.samples.js +7 -0
- package/src/lib/views/ErrorView.samples.js +8 -0
- package/src/lib/views/ErrorView.svelte +4 -2
- package/src/lib/views/Footer.samples.js +8 -0
- package/src/lib/views/Header.samples.js +8 -0
- package/src/lib/views/HomeSidebar.samples.js +59 -0
- package/src/lib/views/HomeView.samples.js +34 -0
- package/src/lib/views/HomeView.svelte +14 -6
- package/src/lib/views/LoginFormBody.samples.js +8 -0
- package/src/lib/views/LoginView.samples.js +50 -0
- package/src/lib/views/LoginView.svelte +24 -22
- package/src/lib/views/LogoutSessionConfirmModal.samples.js +8 -0
- package/src/lib/views/Main.samples.js +23 -0
- package/src/lib/views/MainLayoutView.svelte +3 -4
- package/src/lib/views/Navbar.samples.js +8 -0
- package/src/lib/views/NoContent.samples.js +7 -0
- package/src/lib/views/NotificationContainer.samples.js +25 -0
- package/src/lib/views/NotificationsView.samples.js +36 -0
- package/src/lib/views/NotificationsView.svelte +21 -12
- package/src/lib/views/PageActions.samples.js +7 -0
- package/src/lib/views/PageTitle.samples.js +8 -0
- package/src/lib/views/Pagination.samples.js +7 -0
- package/src/lib/views/PlayerDetailSidebar.samples.js +35 -0
- package/src/lib/views/PlayerDetailView.samples.js +8 -0
- package/src/lib/views/PlayerDetailView.svelte +3 -3
- package/src/lib/views/PlayerHead.samples.js +8 -0
- package/src/lib/views/Post.samples.js +10 -0
- package/src/lib/views/PostDetailView.samples.js +28 -0
- package/src/lib/views/PostDetailView.svelte +24 -16
- package/src/lib/views/Posts.samples.js +9 -0
- package/src/lib/views/PreviewPostView.samples.js +20 -0
- package/src/lib/views/PreviewPostView.svelte +10 -10
- package/src/lib/views/ProfileLayoutView.samples.js +4 -0
- package/src/lib/views/ProfileSidebar.samples.js +33 -0
- package/src/lib/views/ProfileView.samples.js +29 -0
- package/src/lib/views/ProfileView.svelte +2 -2
- package/src/lib/views/RegisterForm.samples.js +7 -0
- package/src/lib/views/RegisterView.samples.js +28 -0
- package/src/lib/views/RegisterView.svelte +5 -3
- package/src/lib/views/RenewPasswordView.samples.js +24 -0
- package/src/lib/views/RenewPasswordView.svelte +6 -6
- package/src/lib/views/ResetPasswordView.samples.js +24 -0
- package/src/lib/views/ResetPasswordView.svelte +3 -3
- package/src/lib/views/RulesView.samples.js +14 -0
- package/src/lib/views/RulesView.svelte +3 -3
- package/src/lib/views/SettingsView.svelte +48 -17
- package/src/lib/views/Sidebar.samples.js +7 -0
- package/src/lib/views/SupportSidebar.samples.js +24 -0
- package/src/lib/views/SupportView.samples.js +16 -0
- package/src/lib/views/SupportView.svelte +8 -6
- package/src/lib/views/ThemeSettingsLayoutView.samples.js +9 -0
- package/src/lib/views/ThemeSettingsLayoutView.svelte +1 -1
- package/src/lib/views/ThemeSettingsView.svelte +89 -89
- package/src/lib/views/TicketCreateAndDetailSidebar.samples.js +33 -0
- package/src/lib/views/TicketDetailView.samples.js +34 -0
- package/src/lib/views/TicketDetailView.svelte +17 -15
- package/src/lib/views/TicketRow.samples.js +10 -0
- package/src/lib/views/TicketStatus.samples.js +8 -0
- package/src/lib/views/Tickets.samples.js +9 -0
- package/src/lib/views/TicketsLayoutView.samples.js +4 -0
- package/src/lib/views/TicketsView.samples.js +23 -0
- package/src/lib/views/TicketsView.svelte +11 -9
- package/src/lib/views/Toast.samples.js +9 -0
- package/src/lib/views/ToastContainer.samples.js +8 -0
- package/src/lib/views/parts/Breadcrumb.svelte +53 -0
- package/src/lib/views/parts/CloseTicketConfirmModal.svelte +63 -0
- package/src/lib/views/parts/ConfirmRemoveAllNotificationsModal.svelte +55 -0
- package/src/lib/views/parts/DefaultToast.svelte +22 -0
- package/src/lib/views/parts/HomeSidebar.svelte +334 -0
- package/src/lib/views/parts/LogoutSessionConfirmModal.svelte +46 -0
- package/src/lib/views/parts/Main.svelte +71 -0
- package/src/lib/views/parts/NotificationContainer.svelte +109 -0
- package/src/lib/views/parts/PlayerDetailSidebar.svelte +81 -0
- package/src/lib/views/parts/Post.svelte +255 -0
- package/src/lib/views/parts/Posts.svelte +25 -0
- package/src/lib/views/parts/ProfileSidebar.svelte +115 -0
- package/src/lib/views/parts/Sidebar.svelte +19 -0
- package/src/lib/views/parts/SupportSidebar.svelte +34 -0
- package/src/lib/views/parts/TicketCreateAndDetailSidebar.svelte +51 -0
- package/src/lib/views/parts/TicketRow.svelte +63 -0
- package/src/lib/views/parts/TicketStatus.svelte +24 -0
- package/src/lib/views/parts/Tickets.svelte +45 -0
- package/src/lib/views/parts/Toast.svelte +27 -0
- package/src/lib/views/parts/ToastContainer.svelte +17 -0
- package/src/lib/views/parts/engine-views.generated.js +63 -0
- package/src/lib/views/parts/publicHref.js +18 -0
- package/src/lib/views/parts/ticketStatuses.js +7 -0
- package/src/plugin-engine/__tests__/engine.test.js +161 -0
- package/src/plugin-engine/engine.js +80 -12
- package/src/registry/__tests__/registry.test.js +510 -0
- package/src/registry/__tests__/view.test.js +52 -0
- package/src/registry/index.js +700 -51
- package/src/registry/routes.js +62 -0
- package/src/registry/view.js +69 -0
- package/src/routes/RootLayout.svelte +24 -1
- package/src/routes/catalogue/List.svelte +163 -0
- package/src/routes/catalogue/Stage.svelte +355 -0
- package/src/routes/catalogue/__tests__/browserSafe.test.js +13 -0
- package/src/routes/catalogue/__tests__/catalogue.test.js +539 -0
- package/src/routes/catalogue/catalogue.js +129 -0
- package/src/routes/catalogue/deps.js +147 -0
- package/src/routes/catalogue/engineSamples.js +63 -0
- package/src/routes/catalogue/fixtures.js +77 -0
- package/src/routes/catalogue/list.js +37 -0
- package/src/routes/catalogue/model.js +286 -0
- package/src/routes/catalogue/stage.js +69 -0
- package/src/routes/catalogue/views-json.js +24 -0
- package/src/routes/plugin-ui/Layout.svelte +29 -4
- package/src/routes/plugin-ui/Page.svelte +86 -31
- package/src/routes/plugin-ui/load.js +173 -0
- package/src/routes/plugins-client-file.js +8 -3
- package/src/routes/plugins-ui-file.js +60 -0
- package/src/routes/root-layout-load.js +59 -2
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
// Theme meta scan (doc 01 sections 4 and 5). Pure: node:fs and node:path only, no vite, no svelte
|
|
2
|
+
// compiler. It reads the theme's overrides (`theme.config.js` `views`), its added route pages
|
|
3
|
+
// (`routes.add`) and its home pages (`home.options.*.page`), plus every theme-local file they import
|
|
4
|
+
// (relative paths and `$lib`, recursively), and looks for the three ways a theme places a plugin view:
|
|
5
|
+
//
|
|
6
|
+
// <PluginBlock id="market:ProductGrid" limit={8} /> a block placement (props = literal attributes)
|
|
7
|
+
// pluginView("market:PriceTag") a proxy to a registered view
|
|
8
|
+
// <PluginSlot id="market:checkout:payment" ... /> a slot opened by the theme itself
|
|
9
|
+
//
|
|
10
|
+
// The result is what `virtual:pano-theme-meta` serves:
|
|
11
|
+
//
|
|
12
|
+
// { refs: { [overrideName | "route:<path>" | "home:<id>"]: [{ id, props }] },
|
|
13
|
+
// claims: string[], // found ids that are not the override's own name, merged with config.claims
|
|
14
|
+
// homePages: { [id]: path }, // theme.config.js `home.options.<id>.page`, as written
|
|
15
|
+
// files: string[] } // every file that was read (absolute), for watchers
|
|
16
|
+
//
|
|
17
|
+
// A placement whose `id` is not a literal (`id={name}`) is skipped: the block loads in the browser
|
|
18
|
+
// after mount (doc 01 section 5). Props that are not literal (`{...rest}`, `onclick={fn}`, `a={b}`)
|
|
19
|
+
// are left out, the same rule `blockKey` applies at run time.
|
|
20
|
+
|
|
21
|
+
import fs from "node:fs";
|
|
22
|
+
import path from "node:path";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @typedef {{ id: string, props: Record<string, string | number | boolean> }} Ref
|
|
26
|
+
* @typedef {{
|
|
27
|
+
* refs: Record<string, Ref[]>,
|
|
28
|
+
* claims: string[],
|
|
29
|
+
* homePages: Record<string, string>,
|
|
30
|
+
* files: string[],
|
|
31
|
+
* }} ThemeMeta
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
const SOURCE_EXTENSIONS = [".svelte", ".js", ".mjs", ".ts"];
|
|
35
|
+
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
// Source scanning
|
|
38
|
+
// ---------------------------------------------------------------------------
|
|
39
|
+
|
|
40
|
+
/** Keeps the length-insensitive text only: HTML comments are removed. */
|
|
41
|
+
function stripHtmlComments(text) {
|
|
42
|
+
return text.replace(/<!--[\s\S]*?-->/g, "");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Removes JS comments from script text (a `//` after `:` is a URL and stays). */
|
|
46
|
+
function stripJsComments(text) {
|
|
47
|
+
return text.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:"'`\w\\])\/\/.*$/gm, "$1");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {string} text
|
|
52
|
+
* @returns {{ markup: string, script: string }} `script` = the content of every <script>; `markup` = the rest
|
|
53
|
+
*/
|
|
54
|
+
function splitSvelte(text) {
|
|
55
|
+
const withoutComments = stripHtmlComments(text);
|
|
56
|
+
const scripts = [];
|
|
57
|
+
const markup = withoutComments.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi, (_, body) => {
|
|
58
|
+
scripts.push(body);
|
|
59
|
+
return "";
|
|
60
|
+
});
|
|
61
|
+
return { markup, script: stripJsComments(scripts.join("\n")) };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Index of the `}` that closes the `{` at `start`, skipping strings and template literals.
|
|
66
|
+
* @param {string} text
|
|
67
|
+
* @param {number} start index of the opening "{"
|
|
68
|
+
* @returns {number} -1 when unbalanced
|
|
69
|
+
*/
|
|
70
|
+
function closingBrace(text, start) {
|
|
71
|
+
let depth = 0;
|
|
72
|
+
for (let i = start; i < text.length; i++) {
|
|
73
|
+
const c = text[i];
|
|
74
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
75
|
+
for (i++; i < text.length && text[i] !== c; i++) if (text[i] === "\\") i++;
|
|
76
|
+
} else if (c === "{") {
|
|
77
|
+
depth++;
|
|
78
|
+
} else if (c === "}") {
|
|
79
|
+
depth--;
|
|
80
|
+
if (depth === 0) return i;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return -1;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The value of a `{expr}` attribute when it is a literal, else `undefined`.
|
|
88
|
+
* @param {string} expr
|
|
89
|
+
* @returns {string | number | boolean | undefined}
|
|
90
|
+
*/
|
|
91
|
+
function literalOfExpression(expr) {
|
|
92
|
+
const value = expr.trim();
|
|
93
|
+
if (value === "true") return true;
|
|
94
|
+
if (value === "false") return false;
|
|
95
|
+
if (/^-?(\d+\.?\d*|\.\d+)$/.test(value)) return Number(value);
|
|
96
|
+
const quoted = /^(["'`])([\s\S]*)\1$/.exec(value);
|
|
97
|
+
if (quoted && !quoted[2].includes("\\") && !quoted[2].includes(quoted[1])) {
|
|
98
|
+
if (quoted[1] === "`" && quoted[2].includes("${")) return undefined;
|
|
99
|
+
return quoted[2];
|
|
100
|
+
}
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Attributes of the tag whose name ends at `from`.
|
|
106
|
+
* @param {string} text
|
|
107
|
+
* @param {number} from
|
|
108
|
+
* @returns {Map<string, string | number | boolean | undefined>} name -> literal value (undefined = not literal)
|
|
109
|
+
*/
|
|
110
|
+
function parseAttributes(text, from) {
|
|
111
|
+
/** @type {Map<string, string | number | boolean | undefined>} */
|
|
112
|
+
const attrs = new Map();
|
|
113
|
+
let i = from;
|
|
114
|
+
|
|
115
|
+
while (i < text.length) {
|
|
116
|
+
while (i < text.length && /\s/.test(text[i])) i++;
|
|
117
|
+
const c = text[i];
|
|
118
|
+
if (c === undefined || c === ">") break;
|
|
119
|
+
if (c === "/") {
|
|
120
|
+
i++;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (c === "{") {
|
|
125
|
+
// `{...spread}` or `{shorthand}`: the value is not a literal
|
|
126
|
+
const end = closingBrace(text, i);
|
|
127
|
+
if (end < 0) break;
|
|
128
|
+
const inner = text.slice(i + 1, end).trim();
|
|
129
|
+
if (!inner.startsWith("...") && /^[A-Za-z_$][\w$]*$/.test(inner)) attrs.set(inner, undefined);
|
|
130
|
+
i = end + 1;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
let j = i;
|
|
135
|
+
while (j < text.length && !/[\s=/>]/.test(text[j])) j++;
|
|
136
|
+
const name = text.slice(i, j);
|
|
137
|
+
i = j;
|
|
138
|
+
if (!name) {
|
|
139
|
+
i++;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
while (i < text.length && /\s/.test(text[i])) i++;
|
|
144
|
+
if (text[i] !== "=") {
|
|
145
|
+
attrs.set(name, true); // bare attribute
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
i++;
|
|
149
|
+
while (i < text.length && /\s/.test(text[i])) i++;
|
|
150
|
+
|
|
151
|
+
const q = text[i];
|
|
152
|
+
if (q === '"' || q === "'") {
|
|
153
|
+
const end = text.indexOf(q, i + 1);
|
|
154
|
+
if (end < 0) break;
|
|
155
|
+
const body = text.slice(i + 1, end);
|
|
156
|
+
attrs.set(name, body.includes("{") ? undefined : body);
|
|
157
|
+
i = end + 1;
|
|
158
|
+
} else if (q === "{") {
|
|
159
|
+
const end = closingBrace(text, i);
|
|
160
|
+
if (end < 0) break;
|
|
161
|
+
attrs.set(name, literalOfExpression(text.slice(i + 1, end)));
|
|
162
|
+
i = end + 1;
|
|
163
|
+
} else {
|
|
164
|
+
let k = i;
|
|
165
|
+
while (k < text.length && !/[\s>]/.test(text[k])) k++;
|
|
166
|
+
const raw = text.slice(i, k).replace(/\/$/, "");
|
|
167
|
+
attrs.set(name, raw);
|
|
168
|
+
i = k;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return attrs;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* @param {string} markup
|
|
177
|
+
* @param {"PluginBlock" | "PluginSlot"} tag
|
|
178
|
+
* @returns {Map<string, string | number | boolean | undefined>[]}
|
|
179
|
+
*/
|
|
180
|
+
function findTags(markup, tag) {
|
|
181
|
+
const out = [];
|
|
182
|
+
const open = new RegExp(`<${tag}(?=[\\s/>])`, "g");
|
|
183
|
+
let match;
|
|
184
|
+
while ((match = open.exec(markup))) out.push(parseAttributes(markup, match.index + match[0].length));
|
|
185
|
+
return out;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Refs found in one file's text.
|
|
190
|
+
* @param {string} source
|
|
191
|
+
* @param {boolean} isSvelte
|
|
192
|
+
* @returns {{ refs: Ref[], imports: string[] }}
|
|
193
|
+
*/
|
|
194
|
+
export function scanSource(source, isSvelte) {
|
|
195
|
+
const { markup, script } = isSvelte ? splitSvelte(source) : { markup: "", script: stripJsComments(source) };
|
|
196
|
+
/** @type {Ref[]} */
|
|
197
|
+
const refs = [];
|
|
198
|
+
|
|
199
|
+
for (const [tag, withProps] of /** @type {const} */ ([["PluginBlock", true], ["PluginSlot", false]])) {
|
|
200
|
+
for (const attrs of findTags(markup, tag)) {
|
|
201
|
+
const id = attrs.get("id");
|
|
202
|
+
if (typeof id !== "string" || !id) continue;
|
|
203
|
+
/** @type {Record<string, string | number | boolean>} */
|
|
204
|
+
const props = {};
|
|
205
|
+
if (withProps) {
|
|
206
|
+
for (const [name, value] of attrs) if (name !== "id" && value !== undefined) props[name] = value;
|
|
207
|
+
}
|
|
208
|
+
refs.push({ id, props });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// pluginView("x") is JS: in <script> blocks and in {expressions} of the markup
|
|
213
|
+
const jsText = isSvelte ? `${script}\n${markup}` : script;
|
|
214
|
+
for (const m of jsText.matchAll(/\bpluginView\(\s*(["'`])([^"'`$\\\n]+)\1\s*[,)]/g)) {
|
|
215
|
+
refs.push({ id: m[2], props: {} });
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const imports = [];
|
|
219
|
+
for (const m of script.matchAll(/\b(?:import|export)\s+(?:[^"'`;]*?\s+from\s+)?(["'])([^"'\n]+)\1/g)) imports.push(m[2]);
|
|
220
|
+
for (const m of script.matchAll(/\bimport\(\s*(["'])([^"'\n]+)\1\s*\)/g)) imports.push(m[2]);
|
|
221
|
+
|
|
222
|
+
return { refs, imports };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// ---------------------------------------------------------------------------
|
|
226
|
+
// Files
|
|
227
|
+
// ---------------------------------------------------------------------------
|
|
228
|
+
|
|
229
|
+
function isFile(file) {
|
|
230
|
+
try {
|
|
231
|
+
return fs.statSync(file).isFile();
|
|
232
|
+
} catch {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Theme-local file for an import specifier, or null (package, outside the theme, missing).
|
|
239
|
+
* @param {string} themeDir
|
|
240
|
+
* @param {string} fromFile
|
|
241
|
+
* @param {string} specifier
|
|
242
|
+
* @returns {string | null}
|
|
243
|
+
*/
|
|
244
|
+
function resolveImport(themeDir, fromFile, specifier) {
|
|
245
|
+
const spec = specifier.split(/[?#]/)[0];
|
|
246
|
+
let base;
|
|
247
|
+
if (spec.startsWith("./") || spec.startsWith("../")) base = path.resolve(path.dirname(fromFile), spec);
|
|
248
|
+
else if (spec === "$lib" || spec.startsWith("$lib/")) base = path.join(themeDir, "src", "lib", spec.slice(5));
|
|
249
|
+
else return null;
|
|
250
|
+
|
|
251
|
+
const candidates = SOURCE_EXTENSIONS.includes(path.extname(base))
|
|
252
|
+
? [base]
|
|
253
|
+
: [...SOURCE_EXTENSIONS.map((ext) => base + ext), ...SOURCE_EXTENSIONS.map((ext) => path.join(base, "index" + ext))];
|
|
254
|
+
|
|
255
|
+
for (const file of candidates) {
|
|
256
|
+
if (!SOURCE_EXTENSIONS.includes(path.extname(file)) || !isFile(file)) continue;
|
|
257
|
+
const rel = path.relative(themeDir, file);
|
|
258
|
+
if (rel.startsWith("..") || path.isAbsolute(rel) || rel.split(path.sep).includes("node_modules")) return null;
|
|
259
|
+
return file;
|
|
260
|
+
}
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const refKey = (ref) =>
|
|
265
|
+
ref.id + "#" + JSON.stringify(Object.fromEntries(Object.entries(ref.props ?? {}).sort(([a], [b]) => (a < b ? -1 : 1))));
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Refs of a root file and of the theme-local files it imports (recursively).
|
|
269
|
+
* @param {string} themeDir
|
|
270
|
+
* @param {string} rootFile absolute
|
|
271
|
+
* @param {Set<string>} seenFiles every file read, accumulated
|
|
272
|
+
* @returns {Ref[]}
|
|
273
|
+
*/
|
|
274
|
+
function scanClosure(themeDir, rootFile, seenFiles) {
|
|
275
|
+
/** @type {Ref[]} */
|
|
276
|
+
const refs = [];
|
|
277
|
+
const keys = new Set();
|
|
278
|
+
const visited = new Set();
|
|
279
|
+
const queue = [rootFile];
|
|
280
|
+
|
|
281
|
+
while (queue.length) {
|
|
282
|
+
const file = /** @type {string} */ (queue.shift());
|
|
283
|
+
if (visited.has(file)) continue;
|
|
284
|
+
visited.add(file);
|
|
285
|
+
|
|
286
|
+
let text;
|
|
287
|
+
try {
|
|
288
|
+
text = fs.readFileSync(file, "utf-8");
|
|
289
|
+
} catch {
|
|
290
|
+
continue; // a missing file is `theme-core check`'s business
|
|
291
|
+
}
|
|
292
|
+
seenFiles.add(file);
|
|
293
|
+
|
|
294
|
+
const found = scanSource(text, file.endsWith(".svelte"));
|
|
295
|
+
for (const ref of found.refs) {
|
|
296
|
+
const key = refKey(ref);
|
|
297
|
+
if (keys.has(key)) continue;
|
|
298
|
+
keys.add(key);
|
|
299
|
+
refs.push(ref);
|
|
300
|
+
}
|
|
301
|
+
for (const spec of found.imports) {
|
|
302
|
+
const next = resolveImport(themeDir, file, spec);
|
|
303
|
+
if (next && !visited.has(next)) queue.push(next);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return refs;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// ---------------------------------------------------------------------------
|
|
311
|
+
// theme.config.js
|
|
312
|
+
// ---------------------------------------------------------------------------
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* The file a view entry points at: `() => import("./x.svelte")`, `{ component: () => import(...) }`
|
|
316
|
+
* or a plain path string. A function is read through its source text, so it is never called (a
|
|
317
|
+
* `.svelte` import cannot run in plain node).
|
|
318
|
+
* @param {any} entry
|
|
319
|
+
* @returns {string | null} as written (theme-relative)
|
|
320
|
+
*/
|
|
321
|
+
export function entryFile(entry) {
|
|
322
|
+
if (typeof entry === "string") return entry;
|
|
323
|
+
if (typeof entry === "function") {
|
|
324
|
+
const source = Function.prototype.toString.call(entry);
|
|
325
|
+
const m = /(["'`])([^"'`\n$]+\.svelte)\1/.exec(source) ?? /\bimport\(\s*(["'`])([^"'`\n$]+)\1\s*\)/.exec(source);
|
|
326
|
+
return m ? m[2] : null;
|
|
327
|
+
}
|
|
328
|
+
if (entry && typeof entry === "object") return entryFile(entry.component ?? entry.page);
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** @param {string} themeDir @param {string} file */
|
|
333
|
+
function absolute(themeDir, file) {
|
|
334
|
+
return path.resolve(themeDir, file.replace(/^\//, ""));
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Scans a theme.
|
|
339
|
+
* @param {{ themeDir: string, config?: any }} options
|
|
340
|
+
* `config` = the default export of theme.config.js (the caller imports it)
|
|
341
|
+
* @returns {ThemeMeta}
|
|
342
|
+
*/
|
|
343
|
+
export function scanThemeMeta({ themeDir, config }) {
|
|
344
|
+
const cfg = config ?? {};
|
|
345
|
+
/** @type {Record<string, Ref[]>} */
|
|
346
|
+
const refs = {};
|
|
347
|
+
/** @type {Record<string, string>} */
|
|
348
|
+
const homePages = {};
|
|
349
|
+
const seenFiles = new Set();
|
|
350
|
+
const claims = new Set();
|
|
351
|
+
|
|
352
|
+
/** @param {string} key @param {any} entry */
|
|
353
|
+
const scanEntry = (key, entry) => {
|
|
354
|
+
const file = entryFile(entry);
|
|
355
|
+
if (!file) return;
|
|
356
|
+
const found = scanClosure(themeDir, absolute(themeDir, file), seenFiles);
|
|
357
|
+
refs[key] = found;
|
|
358
|
+
for (const ref of found) if (ref.id !== key) claims.add(ref.id);
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
for (const [name, entry] of Object.entries(cfg.views ?? {})) scanEntry(name, entry);
|
|
362
|
+
|
|
363
|
+
for (const [routePath, page] of Object.entries(cfg.routes?.add ?? {})) scanEntry(`route:${routePath}`, page);
|
|
364
|
+
|
|
365
|
+
for (const [id, option] of Object.entries(cfg.home?.options ?? {})) {
|
|
366
|
+
const page = /** @type {any} */ (option)?.page;
|
|
367
|
+
if (!page) continue;
|
|
368
|
+
const file = entryFile(page);
|
|
369
|
+
if (!file) continue;
|
|
370
|
+
homePages[id] = file;
|
|
371
|
+
scanEntry(`home:${id}`, file);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// an explicit entry in theme.config.js `claims` wins over the scan
|
|
375
|
+
for (const [id, value] of Object.entries(cfg.claims ?? {})) {
|
|
376
|
+
if (value === false) claims.delete(id);
|
|
377
|
+
else if (value) claims.add(id);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return { refs, claims: [...claims].sort(), homePages, files: [...seenFiles].sort() };
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// ---------------------------------------------------------------------------
|
|
384
|
+
// The virtual module
|
|
385
|
+
// ---------------------------------------------------------------------------
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Source of `virtual:pano-theme-meta`: `refs` and `claims` as data, `homePages` as dynamic imports.
|
|
389
|
+
* @param {ThemeMeta} meta
|
|
390
|
+
* @param {string} themeDir
|
|
391
|
+
* @returns {string}
|
|
392
|
+
*/
|
|
393
|
+
export function renderThemeMetaModule(meta, themeDir) {
|
|
394
|
+
const pages = Object.entries(meta.homePages ?? {})
|
|
395
|
+
.map(([id, file]) => ` ${JSON.stringify(id)}: () => import(${JSON.stringify(absolute(themeDir, file))})`)
|
|
396
|
+
.join(",\n");
|
|
397
|
+
|
|
398
|
+
return [
|
|
399
|
+
`export const refs = ${JSON.stringify(meta.refs ?? {})};`,
|
|
400
|
+
`export const claims = ${JSON.stringify(meta.claims ?? [])};`,
|
|
401
|
+
`export const homePages = {${pages ? "\n" + pages + "\n" : ""}};`,
|
|
402
|
+
`export default { refs, claims, homePages };`,
|
|
403
|
+
"",
|
|
404
|
+
].join("\n");
|
|
405
|
+
}
|
package/src/kit/vite-config.js
CHANGED
|
@@ -13,7 +13,11 @@ import { defineConfig, loadEnv } from "vite";
|
|
|
13
13
|
import fs from "node:fs";
|
|
14
14
|
import path from "node:path";
|
|
15
15
|
import { createRequire } from "node:module";
|
|
16
|
+
import { createHash } from "node:crypto";
|
|
17
|
+
import { pathToFileURL } from "node:url";
|
|
16
18
|
import { importFromTheme } from "./resolve.js";
|
|
19
|
+
import { scanThemeMeta, renderThemeMetaModule } from "./theme-meta.js";
|
|
20
|
+
import { loadThemeConfig, pullContracts, writeCoreMeta } from "../../bin/contracts.js";
|
|
17
21
|
|
|
18
22
|
const require = createRequire(import.meta.url);
|
|
19
23
|
|
|
@@ -45,7 +49,7 @@ function copyFolderPlugin(folder) {
|
|
|
45
49
|
};
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
function copyManifestPlugin(filename = "manifest.json") {
|
|
52
|
+
export function copyManifestPlugin(filename = "manifest.json") {
|
|
49
53
|
let outDir = "";
|
|
50
54
|
|
|
51
55
|
return {
|
|
@@ -64,7 +68,7 @@ function copyManifestPlugin(filename = "manifest.json") {
|
|
|
64
68
|
}
|
|
65
69
|
|
|
66
70
|
try {
|
|
67
|
-
await fs.promises.
|
|
71
|
+
await fs.promises.writeFile(destPath, await manifestWithApiLevel(srcPath));
|
|
68
72
|
console.log(`Copied manifest from ${srcPath} to ${destPath}`);
|
|
69
73
|
} catch (err) {
|
|
70
74
|
console.error("Failed to copy manifest.json:", err);
|
|
@@ -73,9 +77,34 @@ function copyManifestPlugin(filename = "manifest.json") {
|
|
|
73
77
|
};
|
|
74
78
|
}
|
|
75
79
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
/**
|
|
81
|
+
* The manifest as it goes into build/: `apiLevel` is stamped from the engine's package.json
|
|
82
|
+
* (`pano.apiLevel`, doc 04 section 7) unless the theme's own manifest sets one. A manifest that is
|
|
83
|
+
* not valid JSON is copied byte for byte.
|
|
84
|
+
*/
|
|
85
|
+
async function manifestWithApiLevel(srcPath) {
|
|
86
|
+
const raw = await fs.promises.readFile(srcPath);
|
|
87
|
+
|
|
88
|
+
let manifest;
|
|
89
|
+
try {
|
|
90
|
+
manifest = JSON.parse(raw.toString("utf-8"));
|
|
91
|
+
} catch {
|
|
92
|
+
return raw;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!manifest || typeof manifest !== "object" || Array.isArray(manifest) || "apiLevel" in manifest) return raw;
|
|
96
|
+
|
|
97
|
+
const apiLevel = require("@panomc/theme-core/package.json").pano?.apiLevel;
|
|
98
|
+
if (!Number.isInteger(apiLevel)) return raw;
|
|
99
|
+
|
|
100
|
+
return JSON.stringify({ ...manifest, apiLevel }, null, 2) + "\n";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function copyCoreMetaPlugin() {
|
|
104
|
+
// core-meta.json is what the platform reads about a theme (overrides, engine, supports, home, routes,
|
|
105
|
+
// controllers, urls, settingsSchema; doc 01 section 7) plus the author's own keys (tier, baseTheme, ...)
|
|
106
|
+
// and the coreVersion stamped here. It is generated from theme.config.js on every build, so it cannot be
|
|
107
|
+
// stale; `finalize-fingerprint.js` runs after this and covers it. See docs/P0-SPIKE.md section 6.
|
|
79
108
|
let outDir = "";
|
|
80
109
|
|
|
81
110
|
return {
|
|
@@ -85,20 +114,123 @@ function copyCoreMetaPlugin() {
|
|
|
85
114
|
outDir = "build/";
|
|
86
115
|
},
|
|
87
116
|
async closeBundle() {
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
117
|
+
const themeDir = process.cwd();
|
|
118
|
+
const destPath = path.resolve(themeDir, outDir, "core-meta.json");
|
|
91
119
|
const corePkg = require("@panomc/theme-core/package.json");
|
|
92
|
-
const meta = JSON.parse(await fs.promises.readFile(srcPath, "utf-8"));
|
|
93
|
-
meta.coreVersion = corePkg.version;
|
|
94
120
|
|
|
95
|
-
|
|
96
|
-
await
|
|
121
|
+
let configFailed = false;
|
|
122
|
+
const config = await loadThemeConfig(themeDir, (error) => {
|
|
123
|
+
configFailed = true;
|
|
124
|
+
console.warn(`[core-meta] could not import theme.config.js: ${error?.message ?? error}`);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
if (configFailed) {
|
|
128
|
+
// keep the committed file rather than write metadata from an empty config
|
|
129
|
+
const srcPath = path.resolve(themeDir, "core-meta.json");
|
|
130
|
+
if (!fs.existsSync(srcPath)) return;
|
|
131
|
+
const meta = JSON.parse(await fs.promises.readFile(srcPath, "utf-8"));
|
|
132
|
+
meta.coreVersion = corePkg.version;
|
|
133
|
+
await fs.promises.writeFile(destPath, JSON.stringify(meta, null, 2));
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
writeCoreMeta({ themeDir, config, outFile: destPath, extra: { coreVersion: corePkg.version } });
|
|
97
138
|
console.log(`Wrote core-meta.json (coreVersion ${corePkg.version})`);
|
|
98
139
|
},
|
|
99
140
|
};
|
|
100
141
|
}
|
|
101
142
|
|
|
143
|
+
/**
|
|
144
|
+
* A short digest of the installed @panomc/sdk and @panomc/theme-core files (path, size, mtime).
|
|
145
|
+
*
|
|
146
|
+
* `vite dev` serves files under node_modules with `?v=<browserHash>` and `Cache-Control: immutable`.
|
|
147
|
+
* That hash is built from the lockfile and the config only, so it stays the same when `bun install`
|
|
148
|
+
* refreshes these two `file:` packages from the theme-core submodule: the browser then keeps the old
|
|
149
|
+
* files for a year and the app dies on a missing export. The digest goes into a plugin NAME (plugin
|
|
150
|
+
* names are part of vite's config hash), so new package content always gives a new `?v=`.
|
|
151
|
+
*/
|
|
152
|
+
function corePackagesDigest() {
|
|
153
|
+
const hash = createHash("sha1");
|
|
154
|
+
|
|
155
|
+
const walk = (dir) => {
|
|
156
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true }).sort((x, y) => (x.name < y.name ? -1 : 1))) {
|
|
157
|
+
if (entry.name === "node_modules" || entry.name === ".git") continue;
|
|
158
|
+
|
|
159
|
+
const full = path.join(dir, entry.name);
|
|
160
|
+
|
|
161
|
+
if (entry.isDirectory()) {
|
|
162
|
+
walk(full);
|
|
163
|
+
} else if (entry.isFile()) {
|
|
164
|
+
const stat = fs.statSync(full);
|
|
165
|
+
hash.update(`${full}:${stat.size}:${Math.floor(stat.mtimeMs)}\n`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
for (const name of ["@panomc/sdk", "@panomc/theme-core"]) {
|
|
171
|
+
try {
|
|
172
|
+
walk(path.dirname(require.resolve(`${name}/package.json`)));
|
|
173
|
+
} catch {
|
|
174
|
+
// not installed in this consumer: nothing to track
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return hash.digest("hex").slice(0, 12);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function corePackagesCacheKeyPlugin() {
|
|
182
|
+
return { name: `pano-core-packages-${corePackagesDigest()}`, apply: "serve" };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const THEME_META_ID = "virtual:pano-theme-meta";
|
|
186
|
+
const THEME_META_RESOLVED = "\0" + THEME_META_ID;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Serves `virtual:pano-theme-meta` (doc 01 section 4): the blocks, slots and claims found by scanning
|
|
190
|
+
* the theme's overrides, added route pages and home pages (see theme-meta.js). The scanned files and
|
|
191
|
+
* theme.config.js are watched, so an edit rebuilds the module.
|
|
192
|
+
* @param {{ themeDir?: string }} [options]
|
|
193
|
+
*/
|
|
194
|
+
export function panoThemeMeta(options = {}) {
|
|
195
|
+
const themeDir = options.themeDir ?? process.cwd();
|
|
196
|
+
const configPath = path.join(themeDir, "theme.config.js");
|
|
197
|
+
/** @type {Set<string>} */
|
|
198
|
+
let watched = new Set();
|
|
199
|
+
|
|
200
|
+
async function loadConfig() {
|
|
201
|
+
if (!fs.existsSync(configPath)) return {};
|
|
202
|
+
try {
|
|
203
|
+
// a fresh URL every time: the module cache must not serve an old theme.config.js
|
|
204
|
+
const mod = await import(`${pathToFileURL(configPath).href}?t=${Date.now()}`);
|
|
205
|
+
return mod.default ?? {};
|
|
206
|
+
} catch (error) {
|
|
207
|
+
console.warn(`[pano-theme-meta] could not import theme.config.js: ${error?.message ?? error}`);
|
|
208
|
+
return {};
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return {
|
|
213
|
+
name: "pano-theme-meta",
|
|
214
|
+
enforce: "pre",
|
|
215
|
+
resolveId(id) {
|
|
216
|
+
return id === THEME_META_ID ? THEME_META_RESOLVED : null;
|
|
217
|
+
},
|
|
218
|
+
async load(id) {
|
|
219
|
+
if (id !== THEME_META_RESOLVED) return null;
|
|
220
|
+
const meta = scanThemeMeta({ themeDir, config: await loadConfig() });
|
|
221
|
+
watched = new Set([configPath, ...meta.files]);
|
|
222
|
+
for (const file of watched) this.addWatchFile?.(file);
|
|
223
|
+
return renderThemeMetaModule(meta, themeDir);
|
|
224
|
+
},
|
|
225
|
+
handleHotUpdate({ file, server }) {
|
|
226
|
+
if (!watched.has(path.normalize(file))) return;
|
|
227
|
+
const mod = server.moduleGraph.getModuleById(THEME_META_RESOLVED);
|
|
228
|
+
if (mod) server.moduleGraph.invalidateModule(mod);
|
|
229
|
+
server.ws.send({ type: "full-reload" });
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
102
234
|
/** Absolute path to @panomc/theme-core's src/ inside the consumer's node_modules. */
|
|
103
235
|
function corePackageSrc() {
|
|
104
236
|
return path.dirname(require.resolve("@panomc/theme-core/package.json")) + "/src";
|
|
@@ -128,9 +260,20 @@ export function createViteConfig(opts = {}) {
|
|
|
128
260
|
// $app/runtime code (see kit/resolve.js).
|
|
129
261
|
const { sveltekit } = await importFromTheme("@sveltejs/kit", "./vite");
|
|
130
262
|
|
|
263
|
+
// Every dev start refreshes plugin-contracts/ from the installed plugins and prints the views whose
|
|
264
|
+
// contract changed (doc 01 section 5). Never fatal: a broken plugin folder must not stop the dev server.
|
|
265
|
+
if (command === "serve") {
|
|
266
|
+
try {
|
|
267
|
+
pullContracts({ themeDir: process.cwd(), log: (line) => console.log(`[theme-core] ${line}`) });
|
|
268
|
+
} catch (error) {
|
|
269
|
+
console.warn(`[theme-core] plugin contracts were not refreshed: ${error?.message ?? error}`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
131
273
|
const config = {
|
|
132
274
|
clearScreen: false,
|
|
133
275
|
plugins: [
|
|
276
|
+
panoThemeMeta(),
|
|
134
277
|
sveltekit(),
|
|
135
278
|
// NOTE: licenses.json is generated by bin/license/finalize-fingerprint.js
|
|
136
279
|
// AFTER vite build — a closeBundle plugin races adapter-node's build/
|
|
@@ -138,6 +281,7 @@ export function createViteConfig(opts = {}) {
|
|
|
138
281
|
...copyFolders.map((f) => copyFolderPlugin(f)),
|
|
139
282
|
copyManifestPlugin(),
|
|
140
283
|
copyCoreMetaPlugin(),
|
|
284
|
+
corePackagesCacheKeyPlugin(),
|
|
141
285
|
...(opts.extraPlugins ?? []),
|
|
142
286
|
],
|
|
143
287
|
// NOTE: The theme file-fingerprint is stamped into build/manifest.json by
|
|
@@ -1 +1,19 @@
|
|
|
1
|
+
import { onNotificationClick as onNotificationClickWithPaths } from "@panomc/sdk/core/js/NotificationManager.js";
|
|
2
|
+
|
|
3
|
+
import { publicHref } from "./views/parts/publicHref.js";
|
|
4
|
+
|
|
1
5
|
export * from "@panomc/sdk/core/js/NotificationManager.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Same as the SDK's: runs the listeners, or navigates to the notification's `details.href`. The href is a
|
|
9
|
+
* canonical site path; it goes through `route()` so a renamed route (`/store` -> `/shop`) is opened at the
|
|
10
|
+
* path the theme publishes (doc 01 section 9).
|
|
11
|
+
* @param {{ type: string, details?: { href?: string } }} notification
|
|
12
|
+
* @param {(path: string) => void} [navigate]
|
|
13
|
+
*/
|
|
14
|
+
export function onNotificationClick(notification, navigate) {
|
|
15
|
+
return onNotificationClickWithPaths(
|
|
16
|
+
notification,
|
|
17
|
+
typeof navigate === "function" ? (path) => navigate(/** @type {string} */ (publicHref(path))) : navigate,
|
|
18
|
+
);
|
|
19
|
+
}
|