@panomc/theme-core 1.0.0-dev.39

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 (166) hide show
  1. package/bin/bundle-internal-libs.js +104 -0
  2. package/bin/check.js +253 -0
  3. package/bin/generate-licenses.js +125 -0
  4. package/bin/generate-runtime-shims.js +180 -0
  5. package/bin/license/file-fingerprint.js +74 -0
  6. package/bin/license/finalize-fingerprint.js +72 -0
  7. package/bin/license/generate-license-constants.js +335 -0
  8. package/bin/new.js +281 -0
  9. package/bin/package-zip.js +57 -0
  10. package/bin/sync.js +326 -0
  11. package/bin/templates/app.html +59 -0
  12. package/bin/theme-core.js +103 -0
  13. package/package.json +77 -0
  14. package/src/index.js +15 -0
  15. package/src/kit/hooks-client.js +128 -0
  16. package/src/kit/hooks-server.js +319 -0
  17. package/src/kit/license-runtime.js +373 -0
  18. package/src/kit/resolve.js +71 -0
  19. package/src/kit/specifiers.js +62 -0
  20. package/src/kit/svelte-config.js +74 -0
  21. package/src/kit/vite-config.js +249 -0
  22. package/src/lib/NotificationManager.js +1 -0
  23. package/src/lib/PluginAPI.js +368 -0
  24. package/src/lib/PluginManager.js +1 -0
  25. package/src/lib/Store.js +43 -0
  26. package/src/lib/api.util.js +5 -0
  27. package/src/lib/auth.util.js +77 -0
  28. package/src/lib/components/App.svelte +10 -0
  29. package/src/lib/components/Breadcrumb.svelte +88 -0
  30. package/src/lib/components/CardHeader.svelte +42 -0
  31. package/src/lib/components/Date.svelte +34 -0
  32. package/src/lib/components/DefaultToast.svelte +11 -0
  33. package/src/lib/components/ErrorAlert.svelte +16 -0
  34. package/src/lib/components/Footer.svelte +223 -0
  35. package/src/lib/components/Header.svelte +122 -0
  36. package/src/lib/components/Hook.svelte +71 -0
  37. package/src/lib/components/LinkCodeInput.svelte +129 -0
  38. package/src/lib/components/LoginFormBody.svelte +90 -0
  39. package/src/lib/components/Main.svelte +76 -0
  40. package/src/lib/components/Navbar.svelte +462 -0
  41. package/src/lib/components/NoContent.svelte +14 -0
  42. package/src/lib/components/NotificationContainer.svelte +304 -0
  43. package/src/lib/components/OnlineAdmins.svelte +64 -0
  44. package/src/lib/components/PageActions.svelte +39 -0
  45. package/src/lib/components/PageTitle.svelte +36 -0
  46. package/src/lib/components/Pagination.svelte +65 -0
  47. package/src/lib/components/PlayerHead.svelte +58 -0
  48. package/src/lib/components/PlayerPermissionBadge.svelte +19 -0
  49. package/src/lib/components/PlayerStatusBadge.svelte +63 -0
  50. package/src/lib/components/Post.svelte +240 -0
  51. package/src/lib/components/Posts.svelte +19 -0
  52. package/src/lib/components/RegisterForm.svelte +125 -0
  53. package/src/lib/components/Sidebar.svelte +12 -0
  54. package/src/lib/components/SuccessAlert.svelte +14 -0
  55. package/src/lib/components/TicketRow.svelte +61 -0
  56. package/src/lib/components/TicketStatus.svelte +24 -0
  57. package/src/lib/components/Tickets.svelte +43 -0
  58. package/src/lib/components/Toast.svelte +13 -0
  59. package/src/lib/components/ToastContainer.svelte +83 -0
  60. package/src/lib/components/ViewComponent.svelte +8 -0
  61. package/src/lib/components/modals/CloseTicketConfirmModal.svelte +121 -0
  62. package/src/lib/components/modals/ConfirmRemoveAllNotificationsModal.svelte +93 -0
  63. package/src/lib/components/modals/LogoutSessionConfirmModal.svelte +61 -0
  64. package/src/lib/components/sidebars/HomeSidebar.svelte +333 -0
  65. package/src/lib/components/sidebars/PlayerDetailSidebar.svelte +124 -0
  66. package/src/lib/components/sidebars/ProfileSidebar.svelte +149 -0
  67. package/src/lib/components/sidebars/SupportSidebar.svelte +54 -0
  68. package/src/lib/components/sidebars/TicketCreateAndDetailSidebar.svelte +84 -0
  69. package/src/lib/csrf.js +5 -0
  70. package/src/lib/init.libs.js +2 -0
  71. package/src/lib/language.util.js +154 -0
  72. package/src/lib/layouts/AppLayout.svelte +59 -0
  73. package/src/lib/layouts/AuthLayout.svelte +29 -0
  74. package/src/lib/layouts/MainLayout.svelte +60 -0
  75. package/src/lib/layouts/ProfileLayout.svelte +29 -0
  76. package/src/lib/layouts/ThemeSettingsLayout.svelte +37 -0
  77. package/src/lib/layouts/TicketsLayout.svelte +31 -0
  78. package/src/lib/loginInput.util.js +4 -0
  79. package/src/lib/orderNavLinks.util.js +58 -0
  80. package/src/lib/pages/ActivateEmailPage.svelte +48 -0
  81. package/src/lib/pages/ConfirmNewEmailPage.svelte +48 -0
  82. package/src/lib/pages/ErrorPage.svelte +41 -0
  83. package/src/lib/pages/HomePage.svelte +35 -0
  84. package/src/lib/pages/LoginPage.svelte +448 -0
  85. package/src/lib/pages/NotificationsPage.svelte +70 -0
  86. package/src/lib/pages/PlayerDetailPage.svelte +29 -0
  87. package/src/lib/pages/PostDetailPage.svelte +36 -0
  88. package/src/lib/pages/PreviewPostPage.svelte +38 -0
  89. package/src/lib/pages/RegisterPage.svelte +144 -0
  90. package/src/lib/pages/RenewPasswordPage.svelte +49 -0
  91. package/src/lib/pages/ResetPasswordPage.svelte +55 -0
  92. package/src/lib/pages/RulesPage.svelte +52 -0
  93. package/src/lib/pages/SupportPage.svelte +36 -0
  94. package/src/lib/pages/ThemeSettingsPage.svelte +551 -0
  95. package/src/lib/pages/profile/ProfilePage.svelte +32 -0
  96. package/src/lib/pages/profile/SettingsPage.svelte +163 -0
  97. package/src/lib/pages/profile/TicketsPage.svelte +54 -0
  98. package/src/lib/pages/ticket/CreateTicketPage.svelte +48 -0
  99. package/src/lib/pages/ticket/TicketDetailPage.svelte +59 -0
  100. package/src/lib/services/auth.js +85 -0
  101. package/src/lib/services/posts.js +152 -0
  102. package/src/lib/services/profile.js +37 -0
  103. package/src/lib/services/theme-setting.js +22 -0
  104. package/src/lib/services/tickets.js +95 -0
  105. package/src/lib/siteRealtime.js +244 -0
  106. package/src/lib/string.util.js +27 -0
  107. package/src/lib/tooltip.util.js +5 -0
  108. package/src/lib/ui-logics/layout-logics/AppLayoutLogics.js +321 -0
  109. package/src/lib/ui-logics/layout-logics/AuthLayoutLogics.js +10 -0
  110. package/src/lib/ui-logics/layout-logics/MainLayoutLogics.js +19 -0
  111. package/src/lib/ui-logics/layout-logics/ProfileLayoutLogics.js +10 -0
  112. package/src/lib/ui-logics/layout-logics/ThemeSettingsLayoutLogics.js +215 -0
  113. package/src/lib/ui-logics/layout-logics/TicketsLayoutLogics.js +10 -0
  114. package/src/lib/ui-logics/page-logics/ActiveEmailPageLogics.js +45 -0
  115. package/src/lib/ui-logics/page-logics/ConfirmNewEmailPageLogics.js +42 -0
  116. package/src/lib/ui-logics/page-logics/CreateTicketPageLogics.js +83 -0
  117. package/src/lib/ui-logics/page-logics/HomePageLogics.js +65 -0
  118. package/src/lib/ui-logics/page-logics/NotificationsPageLogics.js +264 -0
  119. package/src/lib/ui-logics/page-logics/PlayerDetailPageLogics.js +40 -0
  120. package/src/lib/ui-logics/page-logics/PostDetailPageLogics.js +58 -0
  121. package/src/lib/ui-logics/page-logics/PreviewPostPageLogics.js +53 -0
  122. package/src/lib/ui-logics/page-logics/ProfilePageLogics.js +44 -0
  123. package/src/lib/ui-logics/page-logics/RenewPasswordPageLogics.js +44 -0
  124. package/src/lib/ui-logics/page-logics/ResetPasswordPageLogics.js +53 -0
  125. package/src/lib/ui-logics/page-logics/SettingsPageLogics.js +230 -0
  126. package/src/lib/ui-logics/page-logics/SupportPageLogics.js +60 -0
  127. package/src/lib/ui-logics/page-logics/TicketDetailPageLogics.js +160 -0
  128. package/src/lib/ui-logics/page-logics/TicketsPageLogics.js +132 -0
  129. package/src/lib/variables.js +1 -0
  130. package/src/lib/views/ActivateEmailView.svelte +71 -0
  131. package/src/lib/views/AppLayoutView.svelte +31 -0
  132. package/src/lib/views/AuthLayoutView.svelte +23 -0
  133. package/src/lib/views/ConfirmNewEmailView.svelte +71 -0
  134. package/src/lib/views/CreateTicketView.svelte +73 -0
  135. package/src/lib/views/ErrorView.svelte +38 -0
  136. package/src/lib/views/HomeView.svelte +72 -0
  137. package/src/lib/views/LoginView.svelte +372 -0
  138. package/src/lib/views/MainLayoutView.svelte +86 -0
  139. package/src/lib/views/NotificationsView.svelte +129 -0
  140. package/src/lib/views/PlayerDetailView.svelte +31 -0
  141. package/src/lib/views/PostDetailView.svelte +199 -0
  142. package/src/lib/views/PreviewPostView.svelte +151 -0
  143. package/src/lib/views/ProfileLayoutView.svelte +16 -0
  144. package/src/lib/views/ProfileView.svelte +68 -0
  145. package/src/lib/views/RegisterView.svelte +113 -0
  146. package/src/lib/views/RenewPasswordView.svelte +98 -0
  147. package/src/lib/views/ResetPasswordView.svelte +88 -0
  148. package/src/lib/views/RulesView.svelte +26 -0
  149. package/src/lib/views/SettingsView.svelte +471 -0
  150. package/src/lib/views/SupportView.svelte +79 -0
  151. package/src/lib/views/ThemeSettingsLayoutView.svelte +19 -0
  152. package/src/lib/views/ThemeSettingsView.svelte +1508 -0
  153. package/src/lib/views/TicketDetailView.svelte +185 -0
  154. package/src/lib/views/TicketsLayoutView.svelte +21 -0
  155. package/src/lib/views/TicketsView.svelte +87 -0
  156. package/src/plugin-engine/engine.js +484 -0
  157. package/src/registry/index.js +86 -0
  158. package/src/routes/RootLayout.svelte +21 -0
  159. package/src/routes/plugin-ui/Layout.svelte +291 -0
  160. package/src/routes/plugin-ui/Page.svelte +117 -0
  161. package/src/routes/plugin-ui/layout.js +8 -0
  162. package/src/routes/plugin-ui/page.js +8 -0
  163. package/src/routes/plugins-client-file.js +76 -0
  164. package/src/routes/root-layout-load.js +15 -0
  165. package/src/routes/theme-api-languages.js +52 -0
  166. package/src/routes/theme-api-licenses.js +28 -0
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Theme-first module resolution for plain-node contexts (svelte.config.js /
3
+ * vite.config.js load time).
4
+ *
5
+ * The core package is symlinked (file:/link:) or installed under the theme's
6
+ * node_modules; node resolves core's own imports from core's REAL location, so
7
+ * naively importing "@sveltejs/kit/vite" here could load a DIFFERENT toolchain
8
+ * copy than the one the theme's build actually runs. These helpers resolve the
9
+ * requested package from the THEME's node_modules first and only fall back to
10
+ * core's own dependency tree.
11
+ *
12
+ * require.resolve can't be used: kit/adapter-node are ESM-only (no "require"
13
+ * export condition), so the exports map is read manually.
14
+ */
15
+ import { readFileSync, existsSync } from "node:fs";
16
+ import { join } from "node:path";
17
+ import { pathToFileURL } from "node:url";
18
+
19
+ function pickCondition(entry) {
20
+ if (typeof entry === "string") return entry;
21
+ if (entry && typeof entry === "object") {
22
+ for (const key of ["svelte", "import", "default", "node"]) {
23
+ if (key in entry) {
24
+ const picked = pickCondition(entry[key]);
25
+ if (picked) return picked;
26
+ }
27
+ }
28
+ }
29
+ return null;
30
+ }
31
+
32
+ /**
33
+ * Resolve `pkgName` + `subpath` (e.g. "@sveltejs/kit", "./vite") from
34
+ * `baseDir`'s node_modules via the package's exports map, or `main`/`module`
35
+ * fields for legacy packages.
36
+ * @returns {string|null} absolute file path, or null if not found
37
+ */
38
+ export function resolveFrom(baseDir, pkgName, subpath = ".") {
39
+ const pkgDir = join(baseDir, "node_modules", ...pkgName.split("/"));
40
+ const pkgJsonPath = join(pkgDir, "package.json");
41
+ if (!existsSync(pkgJsonPath)) return null;
42
+
43
+ const pkg = JSON.parse(readFileSync(pkgJsonPath, "utf-8"));
44
+
45
+ if (pkg.exports) {
46
+ const entry = pkg.exports[subpath] ?? (subpath === "." ? pkg.exports : null);
47
+ const target = pickCondition(entry);
48
+ return target ? join(pkgDir, target) : null;
49
+ }
50
+
51
+ if (subpath === ".") {
52
+ const target = pkg.module ?? pkg.main ?? "index.js";
53
+ return join(pkgDir, target);
54
+ }
55
+
56
+ return join(pkgDir, subpath);
57
+ }
58
+
59
+ /**
60
+ * Import a toolchain module, preferring the theme's own copy (process.cwd())
61
+ * over core's dependency tree, so exactly ONE toolchain instance drives the
62
+ * build.
63
+ */
64
+ export async function importFromTheme(pkgName, subpath = ".") {
65
+ const resolved = resolveFrom(process.cwd(), pkgName, subpath);
66
+ if (resolved) {
67
+ return import(pathToFileURL(resolved).href);
68
+ }
69
+ // Fallback: core's own tree (e.g. running core's tests inside this repo).
70
+ return import(subpath === "." ? pkgName : pkgName + subpath.slice(1));
71
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * THE single source of truth for the plugin runtime module surface.
3
+ *
4
+ * Every bare specifier a plugin build may import is listed here, mapped to the
5
+ * stable shim file the theme serves under /runtime/. This list drives:
6
+ * - bin/generate-runtime-shims.js (emits static/runtime/<shimFile> per entry)
7
+ * - createThemeHooks() (the <script type="importmap"> in every page)
8
+ * - the runtime registry in kit/hooks-client.js (which must keep literal
9
+ * import() calls for bundler static analysis — its keys are asserted
10
+ * against this list in dev so the two can never drift)
11
+ *
12
+ * FROZEN CONTRACT: shipped plugin client builds resolve these exact names via
13
+ * the import map forever. Never rename or remove an entry; additions are a
14
+ * core minor version.
15
+ */
16
+ export const RUNTIME_SPECIFIERS = {
17
+ "svelte": "svelte/index.js",
18
+ "svelte/animate": "svelte/animate.js",
19
+ "svelte/easing": "svelte/easing.js",
20
+ "svelte/motion": "svelte/motion.js",
21
+ "svelte/store": "svelte/store.js",
22
+ "svelte/transition": "svelte/transition.js",
23
+ "svelte/internal": "svelte/internal.js",
24
+ "svelte/internal/client": "svelte/internal-client.js",
25
+ "svelte/internal/disclose-version": "svelte/internal-disclose-version.js",
26
+ "svelte/internal/flags/legacy": "svelte/internal-flags-legacy.js",
27
+ "svelte/internal/flags/async": "svelte/internal-flags-async.js",
28
+ "svelte/internal/flags/tracing": "svelte/internal-flags-tracing.js",
29
+ "svelte/legacy": "svelte/legacy.js",
30
+ "svelte/events": "svelte/events.js",
31
+ "svelte/attachments": "svelte/attachments.js",
32
+ "svelte/reactivity": "svelte/reactivity.js",
33
+ "svelte/reactivity/window": "svelte/reactivity-window.js",
34
+ "svelte-i18n": "svelte/i18n.js",
35
+ "@panomc/sdk": "sdk/index.js",
36
+ "@panomc/sdk/components/theme": "sdk/components-theme.js",
37
+ "@panomc/sdk/components/panel": "sdk/components-panel.js",
38
+ "@panomc/sdk/toasts": "sdk/toasts.js",
39
+ "@panomc/sdk/utils/api": "sdk/utils-api.js",
40
+ "@panomc/sdk/utils/auth": "sdk/utils-auth.js",
41
+ "@panomc/sdk/utils/tooltip": "sdk/utils-tooltip.js",
42
+ "@panomc/sdk/utils/language": "sdk/utils-language.js",
43
+ "@panomc/sdk/utils/component": "sdk/utils-component.js",
44
+ "@panomc/sdk/utils/text": "sdk/utils-text.js",
45
+ "@panomc/sdk/variables": "sdk/variables.js",
46
+ "@panomc/sdk/svelte": "sdk/svelte.js",
47
+ "@panomc/sdk/internal": "sdk/internal.js",
48
+ };
49
+
50
+ /** Entries whose shim re-exports come from the svelte/svelte-i18n packages. */
51
+ export const SVELTE_SPECIFIERS = Object.fromEntries(
52
+ Object.entries(RUNTIME_SPECIFIERS).filter(([, file]) =>
53
+ file.startsWith("svelte/"),
54
+ ),
55
+ );
56
+
57
+ /** Entries whose shim re-exports come from @panomc/sdk. */
58
+ export const SDK_SPECIFIERS = Object.fromEntries(
59
+ Object.entries(RUNTIME_SPECIFIERS).filter(([, file]) =>
60
+ file.startsWith("sdk/"),
61
+ ),
62
+ );
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Factory for a theme's svelte.config.js (plain-node context — no vite aliases,
3
+ * no $app imports here). A theme's config becomes:
4
+ *
5
+ * import { createSvelteConfig } from "@panomc/theme-core/kit/svelte-config";
6
+ * export default createSvelteConfig(import.meta.url);
7
+ */
8
+ import { readFileSync } from "node:fs";
9
+ import { importFromTheme } from "./resolve.js";
10
+
11
+ /**
12
+ * @param {string} themeMetaUrl the theme's `import.meta.url` (locates its package.json)
13
+ * @param {object} [overrides] optional kit config overrides merged shallowly into `kit`
14
+ *
15
+ * Async on purpose (consumer: `export default await createSvelteConfig(...)`):
16
+ * the preprocessor and adapter are imported from the THEME's node_modules so
17
+ * only one toolchain instance exists (see kit/resolve.js).
18
+ */
19
+ export async function createSvelteConfig(themeMetaUrl, overrides = {}) {
20
+ const [preprocessMod, adapterMod] = await Promise.all([
21
+ importFromTheme("svelte-preprocess"),
22
+ importFromTheme("@sveltejs/adapter-node"),
23
+ ]);
24
+ const SveltePreprocess = preprocessMod.default ?? preprocessMod;
25
+ const NodeAdapter = adapterMod.default ?? adapterMod;
26
+
27
+ const pkg = JSON.parse(
28
+ readFileSync(new URL("./package.json", themeMetaUrl), "utf-8"),
29
+ );
30
+
31
+ /** @type {import('@sveltejs/kit').Config} */
32
+ const config = {
33
+ kit: {
34
+ adapter: NodeAdapter(),
35
+ version: {
36
+ // SvelteKit defaults version.name to Date.now(), which leaks into
37
+ // /_app/version.json and makes every build differ byte-for-byte. The
38
+ // theme zip's sha256 IS the premium license identity, so builds must
39
+ // be reproducible: pin the version to the theme's package version.
40
+ name: pkg.version,
41
+ },
42
+ ...overrides,
43
+ },
44
+
45
+ preprocess: SveltePreprocess({
46
+ scss: {
47
+ api: "modern-compiler",
48
+ quietDeps: true,
49
+ silenceDeprecations: [
50
+ "mixed-decls",
51
+ "color-functions",
52
+ "global-builtin",
53
+ "import",
54
+ ],
55
+ },
56
+ }),
57
+
58
+ onwarn: (warning, handler) => {
59
+ if (warning.code.startsWith("a11y-")) {
60
+ return;
61
+ }
62
+
63
+ if (warning.code === "vite-plugin-svelte-preprocess-many-dependencies") {
64
+ return;
65
+ }
66
+
67
+ console.log(warning.code);
68
+
69
+ handler(warning);
70
+ },
71
+ };
72
+
73
+ return config;
74
+ }
@@ -0,0 +1,249 @@
1
+ /**
2
+ * Factory for a theme's vite.config.js (plain-node context). A theme's config
3
+ * becomes:
4
+ *
5
+ * import { createViteConfig } from "@panomc/theme-core/kit/vite-config";
6
+ * export default createViteConfig();
7
+ *
8
+ * Owning this file in core kills the config-drift class (blocky/frost's stale
9
+ * vite majors, hand-edited proxy blocks, missing dedupe entries): a toolchain
10
+ * fix ships as a core bump.
11
+ */
12
+ import { defineConfig, loadEnv } from "vite";
13
+ import fs from "node:fs";
14
+ import path from "node:path";
15
+ import { createRequire } from "node:module";
16
+ import { importFromTheme } from "./resolve.js";
17
+
18
+ const require = createRequire(import.meta.url);
19
+
20
+ function copyFolderPlugin(folder) {
21
+ let outDir = "";
22
+
23
+ return {
24
+ name: `copy-${folder}-folder`,
25
+ apply: "build", // Run only during build
26
+ configResolved() {
27
+ outDir = "build/";
28
+ },
29
+ async closeBundle() {
30
+ const srcDir = path.resolve(process.cwd(), folder);
31
+ const destDir = path.resolve(process.cwd(), outDir, folder);
32
+
33
+ if (!fs.existsSync(srcDir)) {
34
+ console.warn(`Source folder "${folder}" not found at: ${srcDir}`);
35
+ return;
36
+ }
37
+
38
+ try {
39
+ await fs.promises.cp(srcDir, destDir, { recursive: true });
40
+ console.log(`Copied "${folder}" folder from ${srcDir} to ${destDir}`);
41
+ } catch (error) {
42
+ console.error(`Error copying "${folder}" folder:`, error);
43
+ }
44
+ },
45
+ };
46
+ }
47
+
48
+ function copyManifestPlugin(filename = "manifest.json") {
49
+ let outDir = "";
50
+
51
+ return {
52
+ name: "copy-manifest-json",
53
+ apply: "build",
54
+ configResolved() {
55
+ outDir = "build/";
56
+ },
57
+ async closeBundle() {
58
+ const srcPath = path.resolve(process.cwd(), filename);
59
+ const destPath = path.resolve(process.cwd(), outDir, filename);
60
+
61
+ if (!fs.existsSync(srcPath)) {
62
+ console.warn(`Manifest file not found at: ${srcPath}`);
63
+ return;
64
+ }
65
+
66
+ try {
67
+ await fs.promises.copyFile(srcPath, destPath);
68
+ console.log(`Copied manifest from ${srcPath} to ${destPath}`);
69
+ } catch (err) {
70
+ console.error("Failed to copy manifest.json:", err);
71
+ }
72
+ },
73
+ };
74
+ }
75
+
76
+ function copyCoreMetaPlugin() {
77
+ // core-meta.json is the sidecar that carries theme metadata the platform
78
+ // must not rewrite (coreVersion, tier, baseTheme). See docs/P0-SPIKE.md §6.
79
+ let outDir = "";
80
+
81
+ return {
82
+ name: "copy-core-meta-json",
83
+ apply: "build",
84
+ configResolved() {
85
+ outDir = "build/";
86
+ },
87
+ async closeBundle() {
88
+ const srcPath = path.resolve(process.cwd(), "core-meta.json");
89
+ if (!fs.existsSync(srcPath)) return;
90
+
91
+ 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
+
95
+ const destPath = path.resolve(process.cwd(), outDir, "core-meta.json");
96
+ await fs.promises.writeFile(destPath, JSON.stringify(meta, null, 2));
97
+ console.log(`Wrote core-meta.json (coreVersion ${corePkg.version})`);
98
+ },
99
+ };
100
+ }
101
+
102
+ /** Absolute path to @panomc/theme-core's src/ inside the consumer's node_modules. */
103
+ function corePackageSrc() {
104
+ return path.dirname(require.resolve("@panomc/theme-core/package.json")) + "/src";
105
+ }
106
+
107
+ /**
108
+ * @param {object} [opts]
109
+ * @param {string} [opts.base] app base path ("" for themes, "/panel" for panel-ui);
110
+ * drives the extra dev proxy entry and hmr path
111
+ * @param {string[]} [opts.copyFolders] folders copied into build/ (default lang+screenshots;
112
+ * panel: ["lang"])
113
+ * @param {object} [opts.extraAliases] additional resolve.alias entries
114
+ * @param {string[]} [opts.extraNoExternalDev] extra ssr.noExternal entries for dev
115
+ * @param {string[]} [opts.extraOptimizeExclude] extra optimizeDeps.exclude entries
116
+ * @param {any[]} [opts.extraPlugins] profile-specific vite plugins appended to the list
117
+ * @param {(config: object, ctx: {command: string}) => object} [opts.finalize]
118
+ * last-chance escape hatch to adjust the resolved config
119
+ */
120
+ export function createViteConfig(opts = {}) {
121
+ const base = opts.base ?? "";
122
+ const copyFolders = opts.copyFolders ?? ["lang", "screenshots"];
123
+ const env = loadEnv("", process.cwd());
124
+
125
+ return defineConfig(async ({ command }) => {
126
+ // The kit vite plugin MUST come from the theme's own node_modules — core's
127
+ // copy can be a different version and would drive the build with mismatched
128
+ // $app/runtime code (see kit/resolve.js).
129
+ const { sveltekit } = await importFromTheme("@sveltejs/kit", "./vite");
130
+
131
+ const config = {
132
+ clearScreen: false,
133
+ plugins: [
134
+ sveltekit(),
135
+ // NOTE: licenses.json is generated by bin/license/finalize-fingerprint.js
136
+ // AFTER vite build — a closeBundle plugin races adapter-node's build/
137
+ // rewrite (SSR pass's output gets wiped by the final adapter pass).
138
+ ...copyFolders.map((f) => copyFolderPlugin(f)),
139
+ copyManifestPlugin(),
140
+ copyCoreMetaPlugin(),
141
+ ...(opts.extraPlugins ?? []),
142
+ ],
143
+ // NOTE: The theme file-fingerprint is stamped into build/manifest.json by
144
+ // bin/license/finalize-fingerprint.js, which the theme's `build` script runs
145
+ // AFTER `vite build`. Doing it inside a vite plugin would race with SvelteKit's
146
+ // adapter-node two-pass bundling (SSR + client), producing a digest that doesn't
147
+ // cover all files.
148
+ ssr: {
149
+ noExternal:
150
+ command === "build"
151
+ ? true
152
+ : [
153
+ "@panomc/sdk",
154
+ "@panomc/theme-core",
155
+ "svelte-i18n",
156
+ ...(opts.extraNoExternalDev ?? []),
157
+ ],
158
+ },
159
+ css: {
160
+ preprocessorOptions: {
161
+ scss: {
162
+ api: "modern-compiler",
163
+ loadPaths: [
164
+ process.cwd(),
165
+ path.resolve(process.cwd(), "node_modules"),
166
+ ],
167
+ quietDeps: true,
168
+ silenceDeprecations: [
169
+ "mixed-decls",
170
+ "color-functions",
171
+ "global-builtin",
172
+ "import",
173
+ ],
174
+ },
175
+ },
176
+ },
177
+ optimizeDeps: {
178
+ include: ["deepmerge", "svelte-i18n"],
179
+ exclude: [
180
+ "@panomc/sdk",
181
+ "@panomc/theme-core",
182
+ "svelte",
183
+ ...(opts.extraOptimizeExclude ?? []),
184
+ ],
185
+ },
186
+ server: {
187
+ proxy: {
188
+ // NEVER proxy /plugins here: the app itself serves plugin client
189
+ // chunks; proxying it to the backend creates a request loop.
190
+ "/api": env.VITE_API_URL
191
+ ? env.VITE_API_URL.replace("/api", "")
192
+ : "http://localhost:8088",
193
+ ...(base
194
+ ? {
195
+ [`${base}/api`]: env.VITE_API_URL
196
+ ? env.VITE_API_URL.replace(`${base}/api`, "").replace("/api", "")
197
+ : "http://localhost:8088",
198
+ }
199
+ : {}),
200
+ },
201
+ allowedHosts: true,
202
+ hmr: {
203
+ path: base ? `${base}/` : "/",
204
+ },
205
+ },
206
+ resolve: {
207
+ alias: {
208
+ // $pano resolves core-internal imports; it works in every
209
+ // vite-processed context (theme code, core code, generated shims).
210
+ "$pano": corePackageSrc(),
211
+ "@theme-style":
212
+ command === "serve" && process.env.VITE_DEV_UI !== "true"
213
+ ? path.resolve(process.cwd(), "src/styles/_empty.scss")
214
+ : path.resolve(process.cwd(), "src/styles/style.scss"),
215
+ ...(opts.extraAliases ?? {}),
216
+ },
217
+ preserveSymlinks: true,
218
+ // @sveltejs/kit is deduped so core-internal `import { error } from
219
+ // "@sveltejs/kit"` resolves to the THEME's kit, not a second copy from
220
+ // core's own node_modules.
221
+ dedupe: [
222
+ "svelte",
223
+ "@panomc/sdk",
224
+ "@panomc/theme-core",
225
+ "svelte-i18n",
226
+ "@sveltejs/kit",
227
+ // core's own runtime deps: resolve them from the THEME's root so a
228
+ // symlinked (file:/link:) core never drags in a second copy from its
229
+ // own isolated store (preserveSymlinks defeats nested resolution).
230
+ "date-fns",
231
+ "copy-to-clipboard",
232
+ "@jill64/universal-sanitizer",
233
+ "mime-types",
234
+ "tippy.js",
235
+ "adm-zip",
236
+ ],
237
+ },
238
+ build: {
239
+ manifest: true,
240
+ // svelte/@panomc/sdk/@panomc/theme-core are deliberately NOT externalized:
241
+ // the host bundles its own runtime (immutable-cached under /_app/immutable),
242
+ // and plugins reach the very same module instances through the /runtime
243
+ // shims + the registry installed by kit/hooks-client.js.
244
+ },
245
+ };
246
+
247
+ return opts.finalize ? opts.finalize(config, { command }) : config;
248
+ });
249
+ }
@@ -0,0 +1 @@
1
+ export * from "@panomc/sdk/core/js/NotificationManager.js";