@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,104 @@
1
+ // Bundles the non-module internal libs (currently just Bootstrap) into a
2
+ // content-hashed /lib/<hash>/ dir referenced by hooks.server.js.
3
+ //
4
+ // The svelte/@panomc/sdk bundles that used to live here are gone: plugins now
5
+ // share the HOST bundle's own module instances via the /runtime shims generated
6
+ // by scripts/generate-runtime-shims.js (see that file for the architecture).
7
+ import {
8
+ existsSync,
9
+ mkdirSync,
10
+ rmSync,
11
+ writeFileSync,
12
+ readFileSync,
13
+ readdirSync,
14
+ statSync,
15
+ renameSync,
16
+ copyFileSync,
17
+ } from "node:fs";
18
+ import { join } from "node:path";
19
+ import { createHash } from "node:crypto";
20
+
21
+ const libRootDir = "./static/lib";
22
+ const tempBundleDir = "./.lib-bundle-output";
23
+ const internalLibsModulePath = "./src/lib/internalLibs.js";
24
+
25
+ // How many previous content-hash dirs to retain alongside the current one. A stale
26
+ // cached HTML document references the hash dir that was current when it was rendered;
27
+ // deleting old dirs immediately turned every such document into a dead page (each
28
+ // failed module fetch is cached in the browser's module map until reload). Keeping a
29
+ // few generations gives those documents a grace window instead.
30
+ const keepPreviousHashDirs = 3;
31
+
32
+ // SHA256 over (relative_path \0 file_bytes \0) for every file, walked in sorted order so
33
+ // the digest is deterministic across runs with identical inputs.
34
+ function hashDirectory(dir) {
35
+ const hasher = createHash("sha256");
36
+ function walk(d, prefix) {
37
+ const entries = readdirSync(d).sort();
38
+ for (const name of entries) {
39
+ const full = join(d, name);
40
+ const rel = prefix ? `${prefix}/${name}` : name;
41
+ const stat = statSync(full);
42
+ if (stat.isDirectory()) {
43
+ walk(full, rel);
44
+ } else {
45
+ hasher.update(rel + "\0");
46
+ hasher.update(readFileSync(full));
47
+ hasher.update("\0");
48
+ }
49
+ }
50
+ }
51
+ walk(dir, "");
52
+ return hasher.digest("hex").slice(0, 16);
53
+ }
54
+
55
+ if (existsSync(tempBundleDir))
56
+ rmSync(tempBundleDir, { recursive: true, force: true });
57
+ mkdirSync(join(tempBundleDir, "bootstrap"), { recursive: true });
58
+
59
+ const bootstrapSrc = "./node_modules/bootstrap/dist/js/bootstrap.bundle.min.js";
60
+ if (existsSync(bootstrapSrc)) {
61
+ copyFileSync(
62
+ bootstrapSrc,
63
+ join(tempBundleDir, "bootstrap", "bootstrap.bundle.min.js"),
64
+ );
65
+ console.log("Copied Bootstrap bundle into temp output");
66
+ } else {
67
+ console.warn("Bootstrap bundle not found at:", bootstrapSrc);
68
+ }
69
+
70
+ const internalLibsHash = hashDirectory(tempBundleDir);
71
+ console.log("Internal libs hash:", internalLibsHash);
72
+
73
+ mkdirSync(libRootDir, { recursive: true });
74
+
75
+ const targetDir = join(libRootDir, internalLibsHash);
76
+ if (existsSync(targetDir)) {
77
+ // Same content already staged (e.g. repeated install) — nothing to move.
78
+ rmSync(tempBundleDir, { recursive: true, force: true });
79
+ } else {
80
+ renameSync(tempBundleDir, targetDir);
81
+ }
82
+
83
+ // Prune all but the newest N previous hash dirs (by mtime), never the current one.
84
+ const staleDirs = readdirSync(libRootDir)
85
+ .filter((name) => name !== internalLibsHash)
86
+ .map((name) => join(libRootDir, name))
87
+ .filter((full) => statSync(full).isDirectory())
88
+ .sort((a, b) => statSync(b).mtimeMs - statSync(a).mtimeMs)
89
+ .slice(keepPreviousHashDirs);
90
+
91
+ for (const dir of staleDirs) {
92
+ console.log(`Pruning old lib dir ${dir}`);
93
+ rmSync(dir, { recursive: true, force: true });
94
+ }
95
+
96
+ mkdirSync("./src/lib", { recursive: true });
97
+ writeFileSync(
98
+ internalLibsModulePath,
99
+ `// AUTO-GENERATED by scripts/bundle-internal-libs.js — do not edit.\n` +
100
+ `// The hash changes on every bundle, so this file is gitignored.\n` +
101
+ `export const internalLibsHash = ${JSON.stringify(internalLibsHash)};\n`,
102
+ );
103
+
104
+ console.log(`Internal libs bundled into ${libRootDir}/${internalLibsHash}`);
package/bin/check.js ADDED
@@ -0,0 +1,253 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * theme-core check — the machine-enforced theme contract.
4
+ *
5
+ * Replaces the prose contract (PANO-THEME-DESIGN-CONTEXT.md) with checks that
6
+ * fail CI before a broken theme ships:
7
+ * 1. svelte is pinned to EXACTLY core's version (plugins compile against the
8
+ * host runtime surface; skew silently drops plugins at runtime)
9
+ * 2. every view in theme.config.js exists on disk and is a KNOWN view name
10
+ * from skin-contract.json (typos = silent fallback to default views)
11
+ * 3. overridden views mount every <ViewSlot>/<Hook> the default view mounts
12
+ * (plugin injection points must not be lost by a restyle)
13
+ * 4. lang-overrides files are valid JSON and only add/replace keys
14
+ * 5. manifest.json carries the required keys
15
+ * 6. settingsSchema (theme.config.js) is shape-valid, appends only, puts no
16
+ * key in a different tab than the base does, and its defaultTab exists
17
+ * Exit code 1 on any violation.
18
+ */
19
+ import { existsSync, readFileSync, readdirSync } from "node:fs";
20
+ import { join, dirname } from "node:path";
21
+ import { fileURLToPath, pathToFileURL } from "node:url";
22
+
23
+ const pkgDir = join(dirname(fileURLToPath(import.meta.url)), "..");
24
+ const themeDir = process.cwd();
25
+ const problems = [];
26
+ const warnings = [];
27
+
28
+ const contract = JSON.parse(readFileSync(join(pkgDir, "skin-contract.json"), "utf-8"));
29
+ const corePkg = JSON.parse(readFileSync(join(pkgDir, "package.json"), "utf-8"));
30
+
31
+ // 1. svelte pin
32
+ const themePkg = JSON.parse(readFileSync(join(themeDir, "package.json"), "utf-8"));
33
+ const themeSvelte =
34
+ themePkg.dependencies?.svelte ?? themePkg.devDependencies?.svelte;
35
+ const coreSvelte = corePkg.dependencies.svelte;
36
+ if (themeSvelte !== coreSvelte) {
37
+ problems.push(
38
+ `svelte must be pinned to exactly "${coreSvelte}" (core's pin); found "${themeSvelte}" — version skew silently drops plugins at runtime`,
39
+ );
40
+ }
41
+
42
+ // 2. view registry entries
43
+ const themeConfigPath = join(themeDir, "theme.config.js");
44
+ let registered = [];
45
+ if (existsSync(themeConfigPath)) {
46
+ const cfgSource = readFileSync(themeConfigPath, "utf-8")
47
+ // strip comments so documentation examples aren't parsed as registrations
48
+ .replace(/\/\*[\s\S]*?\*\//g, "")
49
+ .replace(/^\s*\/\/.*$/gm, "");
50
+ for (const m of cfgSource.matchAll(/([A-Za-z0-9]+)\s*:\s*\(\)\s*=>\s*import\("([^"]+)"\)/g)) {
51
+ const [, name, path] = m;
52
+ registered.push(name);
53
+ if (!(name in contract.views) && !contract.registry_components.includes(name)) {
54
+ problems.push(`theme.config.js registers unknown view '${name}' — not part of the core contract (typo? removed in this core version?)`);
55
+ }
56
+ if (!existsSync(join(themeDir, path))) {
57
+ problems.push(`theme.config.js: view '${name}' points at missing file ${path}`);
58
+ }
59
+ }
60
+ } else {
61
+ warnings.push("no theme.config.js — theme runs with all default views");
62
+ }
63
+
64
+ // 3. slot/hook preservation in overridden views
65
+ for (const name of registered) {
66
+ const defaultView = join(pkgDir, "src", "lib", "views", `${name}.svelte`);
67
+ const overridePath = join(themeDir, "src", "views", `${name}.svelte`);
68
+ if (!existsSync(defaultView) || !existsSync(overridePath)) continue;
69
+ const wanted = new Set();
70
+ const dv = readFileSync(defaultView, "utf-8");
71
+ for (const m of dv.matchAll(/<ViewComponent[^>]*id="([^"]+)"/g)) wanted.add(`slot:${m[1]}`);
72
+ for (const m of dv.matchAll(/<Hook[^>]*name="([^"]+)"/g)) wanted.add(`hook:${m[1]}`);
73
+ const ov = readFileSync(overridePath, "utf-8");
74
+ for (const item of wanted) {
75
+ // hook ids themselves contain ':' (e.g. "page:top") — split on the FIRST
76
+ // colon only.
77
+ const sep = item.indexOf(":");
78
+ const kind = item.slice(0, sep);
79
+ const id = item.slice(sep + 1);
80
+ const present =
81
+ kind === "slot"
82
+ ? new RegExp(`<ViewComponent[^>]*id="${id}"`).test(ov)
83
+ : new RegExp(`<Hook[^>]*name="${id}"`).test(ov);
84
+ if (!present) {
85
+ problems.push(`view '${name}' override lost plugin ${kind} '${id}' — plugins mounting there will silently disappear`);
86
+ }
87
+ }
88
+ }
89
+
90
+ // 3b. no hook may be mounted in MORE than one effective view (override when
91
+ // registered, default otherwise): a duplicated hook renders every plugin
92
+ // mounted there twice on the same page (e.g. page:home:top in both a
93
+ // MainLayoutView override and HomeView).
94
+ {
95
+ const defaultViewsDir = join(pkgDir, "src", "lib", "views");
96
+ const hookOwners = {};
97
+ for (const file of readdirSync(defaultViewsDir)) {
98
+ if (!file.endsWith(".svelte")) continue;
99
+ const name = file.slice(0, -7);
100
+ const overridePath = join(themeDir, "src", "views", file);
101
+ const effective =
102
+ registered.includes(name) && existsSync(overridePath)
103
+ ? { path: overridePath, label: `src/views/${file}` }
104
+ : { path: join(defaultViewsDir, file), label: `${file} (default)` };
105
+ const src = readFileSync(effective.path, "utf-8");
106
+ for (const m of src.matchAll(/<Hook[^>]*name="([^"]+)"/g)) {
107
+ (hookOwners[m[1]] ??= []).push(effective.label);
108
+ }
109
+ }
110
+ for (const [hook, owners] of Object.entries(hookOwners)) {
111
+ if (new Set(owners).size > 1) {
112
+ problems.push(
113
+ `hook '${hook}' is mounted in multiple views (${[...new Set(owners)].join(", ")}) — plugins there render twice on the same page`,
114
+ );
115
+ }
116
+ }
117
+ }
118
+
119
+ // 4. lang-overrides sanity
120
+ const langOverrides = join(themeDir, "lang-overrides");
121
+ if (existsSync(langOverrides)) {
122
+ for (const f of readdirSync(langOverrides)) {
123
+ if (!f.endsWith(".json")) continue;
124
+ try {
125
+ JSON.parse(readFileSync(join(langOverrides, f), "utf-8"));
126
+ } catch (e) {
127
+ problems.push(`lang-overrides/${f} is not valid JSON: ${e.message}`);
128
+ }
129
+ }
130
+ }
131
+
132
+ // 5. manifest required keys
133
+ const manifestPath = join(themeDir, "manifest.json");
134
+ if (existsSync(manifestPath)) {
135
+ const manifest = JSON.parse(readFileSync(manifestPath, "utf-8"));
136
+ for (const key of ["id", "title", "version", "author", "panoVersion", "screenshots"]) {
137
+ if (!(key in manifest)) problems.push(`manifest.json missing required key '${key}' (install is refused without it)`);
138
+ }
139
+ if (manifest.id === "vanilla-theme" && themePkg.name !== "pano-vanilla-theme") {
140
+ problems.push(`manifest id 'vanilla-theme' is reserved for the SYSTEM theme — installs would be refused`);
141
+ }
142
+ } else {
143
+ problems.push("manifest.json missing");
144
+ }
145
+
146
+ // 6. settings-schema extension (theme.config.js → settingsSchema)
147
+ // Imported (not regex-scanned): the schema is a nested object literal, and the
148
+ // view thunks stay lazy, so importing the config runs no Svelte code.
149
+ if (existsSync(themeConfigPath) && contract.settings_tabs) {
150
+ let settingsSchema;
151
+ try {
152
+ const mod = await import(pathToFileURL(themeConfigPath).href);
153
+ settingsSchema = (mod.default ?? mod)?.settingsSchema ?? null;
154
+ } catch (e) {
155
+ problems.push(`theme.config.js could not be imported to validate settingsSchema: ${e.message}`);
156
+ settingsSchema = null;
157
+ }
158
+
159
+ if (settingsSchema != null) {
160
+ if (typeof settingsSchema !== "object" || Array.isArray(settingsSchema)) {
161
+ problems.push("theme.config.js: settingsSchema must be an object ({ tabs?, defaultTab? })");
162
+ } else {
163
+ // base tab → keys, dropping the "_note" doc string (non-array values)
164
+ const baseTabs = {};
165
+ for (const tab in contract.settings_tabs) {
166
+ if (Array.isArray(contract.settings_tabs[tab])) baseTabs[tab] = contract.settings_tabs[tab];
167
+ }
168
+
169
+ // key → the single tab it may live in; base first, extension appends.
170
+ // A key mapped to two different tabs is a save conflict (save/reset are
171
+ // per-tab), so cross-tab duplicates FAIL; same-tab duplicates just dedupe.
172
+ const keyToTab = {};
173
+ for (const tab in baseTabs) for (const key of baseTabs[tab]) keyToTab[key] = tab;
174
+ const tabSet = new Set(Object.keys(baseTabs));
175
+
176
+ const extTabs = settingsSchema.tabs;
177
+ if (extTabs != null) {
178
+ if (typeof extTabs !== "object" || Array.isArray(extTabs)) {
179
+ problems.push("theme.config.js: settingsSchema.tabs must be an object mapping tabId → string[]");
180
+ } else {
181
+ for (const tab in extTabs) {
182
+ tabSet.add(tab);
183
+ const keys = extTabs[tab];
184
+ if (!Array.isArray(keys) || keys.some((k) => typeof k !== "string")) {
185
+ problems.push(`theme.config.js: settingsSchema.tabs['${tab}'] must be an array of setting-key strings`);
186
+ continue;
187
+ }
188
+ for (const key of keys) {
189
+ const owner = keyToTab[key];
190
+ if (owner === undefined) keyToTab[key] = tab;
191
+ else if (owner !== tab)
192
+ problems.push(`settingsSchema key '${key}' is declared in tab '${tab}' but already belongs to tab '${owner}' — the same key in two tabs makes save/reset ambiguous`);
193
+ // owner === tab → harmless duplicate, deduped at runtime
194
+ }
195
+ }
196
+ }
197
+ }
198
+
199
+ if (settingsSchema.defaultTab != null) {
200
+ if (typeof settingsSchema.defaultTab !== "string") {
201
+ problems.push("theme.config.js: settingsSchema.defaultTab must be a string");
202
+ } else if (!tabSet.has(settingsSchema.defaultTab)) {
203
+ problems.push(`settingsSchema.defaultTab '${settingsSchema.defaultTab}' is not a known tab (base tabs + your settingsSchema.tabs) — the settings page would open on an empty tab`);
204
+ }
205
+ }
206
+ }
207
+ }
208
+ }
209
+
210
+ // 7. i18n keys used by overridden views must exist in the MERGED lang tree
211
+ // (lang/ is generated: core base + lang-overrides). A missing key renders raw
212
+ // on screen ("components.header.status"). WARNING not FAIL: some keys may be
213
+ // served by the backend's dynamic THEME translations at runtime.
214
+ const viewsDir = join(themeDir, "src", "views");
215
+ const mergedLangPath = join(themeDir, "lang", "en-US.json");
216
+ if (existsSync(viewsDir) && existsSync(mergedLangPath)) {
217
+ const lang = JSON.parse(readFileSync(mergedLangPath, "utf-8"));
218
+ const hasKey = (dotted) => {
219
+ let node = lang;
220
+ for (const part of dotted.split(".")) {
221
+ if (node == null || typeof node !== "object" || !(part in node)) return false;
222
+ node = node[part];
223
+ }
224
+ return true;
225
+ };
226
+ const scan = (dir) => {
227
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
228
+ const p = join(dir, entry.name);
229
+ if (entry.isDirectory()) scan(p);
230
+ else if (entry.name.endsWith(".svelte")) {
231
+ const src = readFileSync(p, "utf-8");
232
+ // static literals only: $_("a.b.c") / $_('a.b.c') — the closing quote
233
+ // must be followed by ')' or ',' so concatenated dynamic keys like
234
+ // $_("errors." + code) are skipped
235
+ for (const m of src.matchAll(/\$_\(\s*["']([\w.-]+)["']\s*[),]/g)) {
236
+ if (!hasKey(m[1])) {
237
+ warnings.push(
238
+ `src/views/${p.slice(viewsDir.length + 1)} uses i18n key '${m[1]}' missing from the merged lang tree — it will render raw; add it to lang-overrides/`,
239
+ );
240
+ }
241
+ }
242
+ }
243
+ }
244
+ };
245
+ scan(viewsDir);
246
+ }
247
+
248
+ for (const w of warnings) console.log(`[check] warn: ${w}`);
249
+ if (problems.length) {
250
+ for (const p of problems) console.error(`[check] FAIL: ${p}`);
251
+ process.exit(1);
252
+ }
253
+ console.log(`[check] OK — ${registered.length} view overrides validated against core ${corePkg.version}`);
@@ -0,0 +1,125 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
2
+ import { dirname, join } from "path";
3
+ import { fileURLToPath } from "url";
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = dirname(__filename);
7
+ const projectRoot = process.cwd();
8
+
9
+ function readPackageJson(path) {
10
+ try {
11
+ const content = readFileSync(path, "utf-8");
12
+ return JSON.parse(content);
13
+ } catch (e) {
14
+ return null;
15
+ }
16
+ }
17
+
18
+ function getLicenseFromPackage(pkg) {
19
+ if (pkg.license) {
20
+ return typeof pkg.license === "string" ? pkg.license : pkg.license.type || "Unknown";
21
+ }
22
+ if (pkg.licenses) {
23
+ return Array.isArray(pkg.licenses)
24
+ ? pkg.licenses.map(l => typeof l === "string" ? l : l.type).join(", ")
25
+ : "Unknown";
26
+ }
27
+ return "Unknown";
28
+ }
29
+
30
+ function getLicenseText(packagePath) {
31
+ const licenseFiles = ["LICENSE", "LICENSE.txt", "LICENSE.md", "LICENCE", "LICENCE.txt", "LICENCE.md"];
32
+
33
+ for (const licenseFile of licenseFiles) {
34
+ const licensePath = join(packagePath, licenseFile);
35
+ if (existsSync(licensePath)) {
36
+ try {
37
+ return readFileSync(licensePath, "utf-8").trim();
38
+ } catch (e) {
39
+ // Continue to next file
40
+ }
41
+ }
42
+ }
43
+
44
+ return null;
45
+ }
46
+
47
+ export function collectLicenses(outputDir = null) {
48
+ const packageJsonPath = join(projectRoot, "package.json");
49
+ const packageJson = readPackageJson(packageJsonPath);
50
+
51
+ if (!packageJson) {
52
+ throw new Error("package.json bulunamadı!");
53
+ }
54
+
55
+ const allDependencies = {
56
+ ...packageJson.dependencies || {},
57
+ ...packageJson.devDependencies || {}
58
+ };
59
+
60
+ const licenses = [];
61
+ const nodeModulesPath = join(projectRoot, "node_modules");
62
+
63
+ for (const [packageName, version] of Object.entries(allDependencies)) {
64
+ const packagePath = join(nodeModulesPath, packageName);
65
+ const packageJsonPath = join(packagePath, "package.json");
66
+
67
+ if (!existsSync(packageJsonPath)) {
68
+ console.warn(`Paket bulunamadı: ${packageName}`);
69
+ continue;
70
+ }
71
+
72
+ const pkg = readPackageJson(packageJsonPath);
73
+ if (!pkg) continue;
74
+
75
+ const license = getLicenseFromPackage(pkg);
76
+ const licenseText = getLicenseText(packagePath);
77
+ const repository = pkg.repository
78
+ ? (typeof pkg.repository === "string" ? pkg.repository : pkg.repository.url)
79
+ : null;
80
+ const homepage = pkg.homepage || repository;
81
+
82
+ licenses.push({
83
+ name: packageName,
84
+ version: version,
85
+ license: license,
86
+ licenseText: licenseText,
87
+ repository: repository,
88
+ homepage: homepage,
89
+ author: pkg.author
90
+ ? (typeof pkg.author === "string" ? pkg.author : pkg.author.name)
91
+ : null
92
+ });
93
+ }
94
+
95
+ // Lisanslara göre sırala
96
+ licenses.sort((a, b) => a.name.localeCompare(b.name));
97
+
98
+ // Output path'i belirle
99
+ let outputPath;
100
+ if (outputDir) {
101
+ // Build klasörüne kaydet (sadece build sırasında)
102
+ if (!existsSync(outputDir)) {
103
+ mkdirSync(outputDir, { recursive: true });
104
+ }
105
+ outputPath = join(outputDir, "licenses.json");
106
+ } else {
107
+ // Ana dizine kaydet (npm run generate-licenses için)
108
+ outputPath = join(projectRoot, "licenses.json");
109
+ }
110
+
111
+ writeFileSync(outputPath, JSON.stringify(licenses, null, 2), "utf-8");
112
+
113
+ console.log(`✅ ${licenses.length} paketin lisans bilgisi toplandı ve ${outputPath} dosyasına kaydedildi.`);
114
+ }
115
+
116
+ // Eğer direkt çalıştırılıyorsa (npm run generate-licenses)
117
+ // Sadece script direkt çalıştırıldığında çalış, import edildiğinde çalışma
118
+ // import.meta.url'yi file:// ile karşılaştırarak kontrol et
119
+ const isMainModule = import.meta.url === `file://${process.argv[1]}` ||
120
+ (process.argv[1] && process.argv[1].endsWith("generate-licenses.js"));
121
+
122
+ if (isMainModule) {
123
+ collectLicenses();
124
+ }
125
+
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Generates the runtime shim modules that let plugin bundles share the HOST
3
+ * application's own bundled Svelte / SDK module instances.
4
+ *
5
+ * Architecture ("registry + shims"):
6
+ * - src/hooks.client.js captures the host bundle's live module instances into
7
+ * globalThis.__PANO_RUNTIME__ (a registry of lazy import thunks) before hydration.
8
+ * - The import map in hooks.server.js points every bare specifier plugins use
9
+ * ("svelte", "svelte/store", "@panomc/sdk", ...) at the tiny shim files this
10
+ * script emits into static/runtime/.
11
+ * - Each shim awaits the registry and re-exports the host's module instance, so
12
+ * host pages and plugins run on ONE Svelte runtime (same effect scheduler, same
13
+ * component context) and plugins download no second runtime copy at hydration.
14
+ *
15
+ * The shim URLs are STABLE across deploys (unlike the old /lib/<hash>/ scheme), so
16
+ * stale cached HTML can never 404 on them; their content only changes when the
17
+ * theme's svelte/sdk dependency is upgraded, which the ?v=<runtimeShimsHash> query
18
+ * appended by hooks.server.js cache-busts.
19
+ *
20
+ * Export lists are derived from the actual installed packages at build time
21
+ * (Bun.build flattens each specifier, Bun.Transpiler enumerates its exports), so a
22
+ * svelte upgrade automatically regenerates the full export surface.
23
+ */
24
+ import {
25
+ mkdirSync,
26
+ rmSync,
27
+ writeFileSync,
28
+ readdirSync,
29
+ readFileSync,
30
+ statSync,
31
+ } from "node:fs";
32
+ import { join } from "node:path";
33
+ import { createHash } from "node:crypto";
34
+ import { SVELTE_SPECIFIERS, SDK_SPECIFIERS } from "../src/kit/specifiers.js";
35
+
36
+ const outputRootDir = "./static/runtime";
37
+ const tempEntryDir = "./.runtime-shims-temp";
38
+ const generatedModulePath = "./src/lib/runtimeShims.js";
39
+
40
+ // Modules with a default export that `export * from` does not carry over.
41
+ const defaultExportSpecs = new Set([
42
+ "@panomc/sdk/utils/api",
43
+ "@panomc/sdk/utils/tooltip",
44
+ ]);
45
+
46
+ const identifierRe = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
47
+
48
+ // Names that parse as IdentifierName but cannot be declared with `const` — they must
49
+ // go through the aliased-export path (svelte/internal/client exports `if`, `await`, …).
50
+ // prettier-ignore
51
+ const reservedWords = new Set([
52
+ "await", "break", "case", "catch", "class", "const", "continue", "debugger",
53
+ "default", "delete", "do", "else", "enum", "export", "extends", "false",
54
+ "finally", "for", "function", "if", "implements", "import", "in", "instanceof",
55
+ "interface", "let", "new", "null", "package", "private", "protected", "public",
56
+ "return", "static", "super", "switch", "this", "throw", "true", "try", "typeof",
57
+ "var", "void", "while", "with", "yield", "arguments", "eval",
58
+ ]);
59
+
60
+ async function enumerateExports(spec) {
61
+ const entryPath = join(
62
+ tempEntryDir,
63
+ spec.replace(/[^a-z0-9]+/gi, "_") + ".js",
64
+ );
65
+ let entrySource = `export * from ${JSON.stringify(spec)};\n`;
66
+ if (defaultExportSpecs.has(spec)) {
67
+ entrySource += `export { default } from ${JSON.stringify(spec)};\n`;
68
+ }
69
+ writeFileSync(entryPath, entrySource);
70
+
71
+ const result = await Bun.build({
72
+ entrypoints: [entryPath],
73
+ target: "browser",
74
+ format: "esm",
75
+ splitting: false,
76
+ minify: false,
77
+ // The bundle is only scanned for its export list, never executed or shipped.
78
+ outdir: undefined,
79
+ });
80
+
81
+ if (!result.success) {
82
+ console.error(`Failed to bundle '${spec}' for export enumeration:`);
83
+ console.error(result.logs);
84
+ process.exit(1);
85
+ }
86
+
87
+ const code = await result.outputs[0].text();
88
+ const transpiler = new Bun.Transpiler({ loader: "js" });
89
+ const { exports } = transpiler.scan(code);
90
+ return exports.sort();
91
+ }
92
+
93
+ function renderShim(spec, exportNames) {
94
+ const lines = [
95
+ `// AUTO-GENERATED by scripts/generate-runtime-shims.js — do not edit.`,
96
+ `// Re-exports the host application's live ${JSON.stringify(spec)} module instance`,
97
+ `// from the runtime registry populated by src/hooks.client.js.`,
98
+ `const g = globalThis;`,
99
+ `g.__PANO_RT_READY__ ??= new Promise((resolve) => (g.__PANO_RT_RESOLVE__ = resolve));`,
100
+ `const registry =`,
101
+ ` g.__PANO_RUNTIME__ ??`,
102
+ ` (await Promise.race([`,
103
+ ` g.__PANO_RT_READY__,`,
104
+ ` new Promise((_, reject) =>`,
105
+ ` setTimeout(`,
106
+ ` () => reject(new Error("[pano-runtime] host runtime registry missing for " + ${JSON.stringify(spec)})),`,
107
+ ` 15000,`,
108
+ ` ),`,
109
+ ` ),`,
110
+ ` ]));`,
111
+ `const m = await registry.import(${JSON.stringify(spec)});`,
112
+ ];
113
+
114
+ let i = 0;
115
+ for (const name of exportNames) {
116
+ if (name === "default") {
117
+ lines.push(`export default m.default;`);
118
+ } else if (identifierRe.test(name) && !reservedWords.has(name)) {
119
+ lines.push(`export const ${name} = m.${name};`);
120
+ } else {
121
+ // Reserved words (exported alias is legal, `const` declaration is not) and
122
+ // arbitrary module namespace names (ES2022 string export names).
123
+ const local = `__pano_export_${i++}`;
124
+ lines.push(`const ${local} = m[${JSON.stringify(name)}];`);
125
+ lines.push(`export { ${local} as ${JSON.stringify(name)} };`);
126
+ }
127
+ }
128
+
129
+ return lines.join("\n") + "\n";
130
+ }
131
+
132
+ function hashDirectory(dir) {
133
+ const hasher = createHash("sha256");
134
+ function walk(d, prefix) {
135
+ const entries = readdirSync(d).sort();
136
+ for (const name of entries) {
137
+ const full = join(d, name);
138
+ const rel = prefix ? `${prefix}/${name}` : name;
139
+ if (statSync(full).isDirectory()) {
140
+ walk(full, rel);
141
+ } else {
142
+ hasher.update(rel + "\0");
143
+ hasher.update(readFileSync(full));
144
+ hasher.update("\0");
145
+ }
146
+ }
147
+ }
148
+ walk(dir, "");
149
+ return hasher.digest("hex").slice(0, 16);
150
+ }
151
+
152
+ rmSync(outputRootDir, { recursive: true, force: true });
153
+ rmSync(tempEntryDir, { recursive: true, force: true });
154
+ mkdirSync(join(outputRootDir, "svelte"), { recursive: true });
155
+ mkdirSync(join(outputRootDir, "sdk"), { recursive: true });
156
+ mkdirSync(tempEntryDir, { recursive: true });
157
+
158
+ const allShims = { ...SVELTE_SPECIFIERS, ...SDK_SPECIFIERS };
159
+
160
+ for (const [spec, outFile] of Object.entries(allShims)) {
161
+ const exportNames = await enumerateExports(spec);
162
+ writeFileSync(join(outputRootDir, outFile), renderShim(spec, exportNames));
163
+ console.log(`Shim ${outFile}: ${exportNames.length} exports`);
164
+ }
165
+
166
+ const runtimeShimsHash = hashDirectory(outputRootDir);
167
+
168
+ writeFileSync(
169
+ generatedModulePath,
170
+ `// AUTO-GENERATED by scripts/generate-runtime-shims.js — do not edit.\n` +
171
+ `// Changes only when the installed svelte/sdk export surface changes; used by\n` +
172
+ `// hooks.server.js to cache-bust shim URLs in the import map.\n` +
173
+ `export const runtimeShimsHash = ${JSON.stringify(runtimeShimsHash)};\n`,
174
+ );
175
+
176
+ rmSync(tempEntryDir, { recursive: true, force: true });
177
+
178
+ console.log(
179
+ `Runtime shims generated into ${outputRootDir} (hash ${runtimeShimsHash})`,
180
+ );