@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,95 @@
1
+ import ApiUtil, { buildQueryParams } from "../api.util.js";
2
+
3
+ export const getTickets = async ({ page, pageType, categoryUrl, request, csrfToken }) => {
4
+ const queryParams = buildQueryParams({ page, pageType, categoryUrl });
5
+
6
+ return ApiUtil.get({
7
+ path: `/api/tickets${queryParams}`,
8
+ request,
9
+ csrfToken
10
+ }).then((body) => {
11
+ body.page = parseInt(page);
12
+ body.pageType = pageType;
13
+
14
+ return body;
15
+ });
16
+ };
17
+
18
+ export const getTicketCategories = async ({ page, request, csrfToken }) => {
19
+ return ApiUtil.get({
20
+ path: `/api/ticket/categories?page=${page}`,
21
+ request,
22
+ csrfToken
23
+ }).then((body) => {
24
+ body.page = parseInt(page);
25
+
26
+ return body;
27
+ });
28
+ };
29
+
30
+ export const updateTicket = async ({ id, status, request, csrfToken }) => {
31
+ return ApiUtil.put({
32
+ path: `/api/tickets/${id}`,
33
+ body: {
34
+ status,
35
+ },
36
+ request,
37
+ csrfToken
38
+ });
39
+ };
40
+
41
+ export const createTicket = async ({
42
+ title,
43
+ message,
44
+ categoryId,
45
+ request,
46
+ csrfToken
47
+ }) => {
48
+ return ApiUtil.post({
49
+ path: `/api/tickets`,
50
+ body: {
51
+ title,
52
+ message,
53
+ categoryId,
54
+ },
55
+ request,
56
+ csrfToken
57
+ });
58
+ };
59
+
60
+ export const getTicketDetail = async ({ id, request, csrfToken }) => {
61
+ return ApiUtil.get({
62
+ path: `/api/tickets/${id}`,
63
+ request,
64
+ csrfToken
65
+ });
66
+ };
67
+
68
+ export const loadMoreTicketMessages = async ({
69
+ id,
70
+ lastMessageId,
71
+ request,
72
+ csrfToken
73
+ }) => {
74
+ return ApiUtil.get({
75
+ path: `/api/tickets/${id}/messages?lastMessageId=${lastMessageId}`,
76
+ request,
77
+ csrfToken
78
+ });
79
+ };
80
+
81
+ export const sendTicketMessage = async ({
82
+ ticketId,
83
+ message,
84
+ request,
85
+ csrfToken
86
+ }) => {
87
+ return ApiUtil.post({
88
+ path: `/api/tickets/${ticketId}/messages`,
89
+ body: {
90
+ message,
91
+ },
92
+ request,
93
+ csrfToken
94
+ });
95
+ };
@@ -0,0 +1,244 @@
1
+ import { base } from '$app/paths';
2
+
3
+ const listeners = new Set();
4
+ let ws;
5
+ let shouldReconnect = false;
6
+ let reconnectTimer;
7
+ /** Reconnect cadence: 1 second forever, until logout or auth-rejected. */
8
+ const RECONNECT_MS = 1000;
9
+ let wantSiteNotifications = false;
10
+
11
+ /**
12
+ * If a brand new socket closes within this window without ever reaching OPEN, we treat
13
+ * it as a rejected upgrade. The backend rejects unauthenticated upgrades with HTTP 401
14
+ * before the socket has a chance to open, which the browser surfaces as a near-instant
15
+ * onclose with code 1006.
16
+ */
17
+ const FAST_FAILURE_THRESHOLD_MS = 300;
18
+ /**
19
+ * After this many consecutive fast failures we run a single HTTP probe to find out if
20
+ * the backend really considers us logged out (vs. just temporarily flapping). On a 401
21
+ * we stop reconnecting altogether; any other outcome resets the counter and reconnects
22
+ * keep going.
23
+ */
24
+ const MAX_FAST_FAILURES = 3;
25
+
26
+ let consecutiveFastFailures = 0;
27
+ /**
28
+ * Latched on a 401 probe response. Once latched, we stop trying until
29
+ * setSiteNotificationsSubscription(true) is called again, which is the signal that the
30
+ * consumer (NotificationContainer) re-armed us after a fresh login.
31
+ */
32
+ let stoppedDueToAuth = false;
33
+
34
+ function buildWsUrl() {
35
+ if (typeof window === 'undefined') return '';
36
+ const withBase = `${base || ''}/api/ws`.replace(/\/+/g, '/');
37
+ const path = withBase.startsWith('/') ? withBase : `/${withBase}`;
38
+ const u = new URL(path, window.location.origin);
39
+ u.protocol = u.protocol === 'https:' ? 'wss:' : 'ws:';
40
+ return u.toString();
41
+ }
42
+
43
+ function buildAuthProbeUrl() {
44
+ if (typeof window === 'undefined') return '';
45
+ // Logged-in-only endpoint: returns 200 when the session is valid, 401 otherwise.
46
+ // Cheap (small payload) and already used elsewhere by the notification UI.
47
+ const withBase = `${base || ''}/api/notifications/quick`.replace(/\/+/g, '/');
48
+ const path = withBase.startsWith('/') ? withBase : `/${withBase}`;
49
+ return new URL(path, window.location.origin).href;
50
+ }
51
+
52
+ function scheduleReconnect() {
53
+ if (!shouldReconnect || typeof window === 'undefined') {
54
+ return;
55
+ }
56
+ if (stoppedDueToAuth) {
57
+ return;
58
+ }
59
+ if (reconnectTimer) {
60
+ clearTimeout(reconnectTimer);
61
+ }
62
+ reconnectTimer = setTimeout(() => {
63
+ reconnectTimer = null;
64
+ if (shouldReconnect && wantSiteNotifications && !stoppedDueToAuth) {
65
+ connect();
66
+ }
67
+ }, RECONNECT_MS);
68
+ }
69
+
70
+ function sendConfig() {
71
+ if (!ws || ws.readyState !== WebSocket.OPEN) {
72
+ return;
73
+ }
74
+ ws.send(JSON.stringify({ subscribeNotifications: true }));
75
+ }
76
+
77
+ function emitRefresh() {
78
+ listeners.forEach((fn) => {
79
+ try {
80
+ fn();
81
+ } catch {
82
+ /* ignore */
83
+ }
84
+ });
85
+ }
86
+
87
+ async function probeAuthAndDecide() {
88
+ if (typeof window === 'undefined') return;
89
+ let httpStatus = 0;
90
+ try {
91
+ const r = await fetch(buildAuthProbeUrl(), {
92
+ credentials: 'include',
93
+ cache: 'no-store',
94
+ headers: { Accept: 'application/json' }
95
+ });
96
+ httpStatus = r.status;
97
+ } catch {
98
+ httpStatus = 0;
99
+ }
100
+ if (httpStatus === 401 || httpStatus === 403) {
101
+ // Backend confirms we're logged out. Stop the reconnect loop until the next
102
+ // explicit setSiteNotificationsSubscription(true) call (i.e. fresh login).
103
+ stoppedDueToAuth = true;
104
+ consecutiveFastFailures = 0;
105
+ if (reconnectTimer) {
106
+ clearTimeout(reconnectTimer);
107
+ reconnectTimer = null;
108
+ }
109
+ return;
110
+ }
111
+ // Anything else (network blip, 5xx, transient): give the next failure window its own
112
+ // probing chance. The reconnect loop continues.
113
+ consecutiveFastFailures = 0;
114
+ }
115
+
116
+ function connect() {
117
+ if (typeof window === 'undefined') {
118
+ return;
119
+ }
120
+ if (stoppedDueToAuth) {
121
+ return;
122
+ }
123
+ if (ws && (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING)) {
124
+ return;
125
+ }
126
+ shouldReconnect = true;
127
+ let attemptHasOpened = false;
128
+ const startedAt = Date.now();
129
+ try {
130
+ ws = new WebSocket(buildWsUrl());
131
+ } catch {
132
+ scheduleReconnect();
133
+ return;
134
+ }
135
+ ws.onopen = () => {
136
+ attemptHasOpened = true;
137
+ consecutiveFastFailures = 0;
138
+ sendConfig();
139
+ };
140
+ ws.onmessage = (ev) => {
141
+ let msg;
142
+ try {
143
+ msg = JSON.parse(ev.data);
144
+ } catch {
145
+ return;
146
+ }
147
+ if (msg.type === 'ready') {
148
+ sendConfig();
149
+ return;
150
+ }
151
+ if (msg.type === 'notificationRefresh' || msg.type === 'panelNotificationRefresh') {
152
+ emitRefresh();
153
+ }
154
+ };
155
+ ws.onclose = () => {
156
+ const wasOpen = attemptHasOpened;
157
+ const ageMs = Date.now() - startedAt;
158
+ ws = null;
159
+ if (!shouldReconnect || !wantSiteNotifications) {
160
+ return;
161
+ }
162
+ if (wasOpen) {
163
+ // Healthy session that just dropped; treat the next series as a fresh attempt.
164
+ consecutiveFastFailures = 0;
165
+ scheduleReconnect();
166
+ return;
167
+ }
168
+ // Never made it to OPEN. A near-instant close is the fingerprint of a rejected
169
+ // HTTP upgrade (most often 401). Keep trying, but verify with a real HTTP probe
170
+ // after a few in a row so we don't reconnect forever against a logged-out session.
171
+ if (ageMs < FAST_FAILURE_THRESHOLD_MS) {
172
+ consecutiveFastFailures++;
173
+ if (consecutiveFastFailures >= MAX_FAST_FAILURES) {
174
+ void probeAuthAndDecide();
175
+ }
176
+ } else {
177
+ consecutiveFastFailures = 0;
178
+ }
179
+ scheduleReconnect();
180
+ };
181
+ ws.onerror = () => {
182
+ /* reconnect via onclose */
183
+ };
184
+ }
185
+
186
+ function updateConnection() {
187
+ if (typeof window === 'undefined') {
188
+ return;
189
+ }
190
+ if (wantSiteNotifications) {
191
+ // A fresh subscribe is always allowed to start trying again, even if a previous
192
+ // session latched stoppedDueToAuth — a new login wiped the auth state.
193
+ stoppedDueToAuth = false;
194
+ consecutiveFastFailures = 0;
195
+ if (!ws || ws.readyState === WebSocket.CLOSED) {
196
+ connect();
197
+ } else if (ws.readyState === WebSocket.OPEN) {
198
+ sendConfig();
199
+ }
200
+ } else {
201
+ shouldReconnect = false;
202
+ stoppedDueToAuth = false;
203
+ consecutiveFastFailures = 0;
204
+ if (reconnectTimer) {
205
+ clearTimeout(reconnectTimer);
206
+ reconnectTimer = null;
207
+ }
208
+ if (ws) {
209
+ try {
210
+ ws.onopen = null;
211
+ ws.onmessage = null;
212
+ ws.onerror = null;
213
+ ws.onclose = null;
214
+ ws.close();
215
+ } catch {
216
+ /* ignore */
217
+ }
218
+ ws = null;
219
+ }
220
+ }
221
+ }
222
+
223
+ /**
224
+ * Keep a WebSocket for the logged-in site session (nudges re-fetch of /api/notifications/quick).
225
+ *
226
+ * The reconnect loop runs at [RECONNECT_MS] forever while active, until either:
227
+ * - the consumer calls setSiteNotificationsSubscription(false) (logout / unmount), or
228
+ * - the backend confirms we're logged out via a 401/403 on the auth probe.
229
+ *
230
+ * @param {boolean} active
231
+ */
232
+ export function setSiteNotificationsSubscription(active) {
233
+ wantSiteNotifications = !!active;
234
+ updateConnection();
235
+ }
236
+
237
+ /**
238
+ * @param {() => void} fn
239
+ * @returns {() => void} unsubscribe
240
+ */
241
+ export function onNotificationRefresh(fn) {
242
+ listeners.add(fn);
243
+ return () => listeners.delete(fn);
244
+ }
@@ -0,0 +1,27 @@
1
+ export function truncate(str, n) {
2
+ return str.length > n ? str.substr(0, n - 1) : str;
3
+ }
4
+
5
+ export function parseUserAgent(userAgent) {
6
+ if (!userAgent || userAgent === "-") return "Unknown";
7
+
8
+ const ua = userAgent.toLowerCase();
9
+
10
+ // Browser detection
11
+ let browser = "Unknown Browser";
12
+ if (ua.includes("firefox")) browser = "Firefox";
13
+ else if (ua.includes("edg")) browser = "Edge";
14
+ else if (ua.includes("chrome")) browser = "Chrome";
15
+ else if (ua.includes("safari")) browser = "Safari";
16
+ else if (ua.includes("opera") || ua.includes("opr")) browser = "Opera";
17
+
18
+ // OS detection
19
+ let os = "Unknown OS";
20
+ if (ua.includes("win")) os = "Windows";
21
+ else if (ua.includes("mac")) os = "macOS";
22
+ else if (ua.includes("linux")) os = "Linux";
23
+ else if (ua.includes("android")) os = "Android";
24
+ else if (ua.includes("iphone") || ua.includes("ipad")) os = "iOS";
25
+
26
+ return `${browser} (${os})`;
27
+ }
@@ -0,0 +1,5 @@
1
+ import { default as Default } from "@panomc/sdk/core/js/tooltip.util";
2
+
3
+ export * from "@panomc/sdk/core/js/tooltip.util";
4
+
5
+ export default Default;
@@ -0,0 +1,321 @@
1
+ import { onDestroy, onMount, setContext } from "svelte";
2
+ import { get, writable } from "svelte/store";
3
+ import { setPanoContext } from "@panomc/sdk/internal";
4
+ import { resolveView } from "$pano/registry/index.js";
5
+ import { _ } from "svelte-i18n";
6
+ import copy from "copy-to-clipboard";
7
+
8
+ import { browser } from "$app/environment";
9
+ import { goto } from "$app/navigation";
10
+ import { navigating, page } from "$app/stores";
11
+ import { base } from "$app/paths";
12
+ import { error, redirect } from "@sveltejs/kit";
13
+
14
+ import { avatarVersion, initialized } from "$pano/lib/Store";
15
+
16
+ import * as languageStuff from "$pano/lib/language.util";
17
+ import ApiUtil, * as ApiUtilStuff from "$pano/lib/api.util";
18
+ import * as variableStuff from "$pano/lib/variables";
19
+ import { checkDomainRedirection, updateApiUrl, updatePanoWebsiteUrl } from "$pano/lib/variables";
20
+ import * as toastStuff from "$pano/lib/components/ToastContainer.svelte";
21
+ import tooltip from "$pano/lib/tooltip.util";
22
+
23
+ import { addListener } from "$pano/lib/NotificationManager";
24
+ import { initializePlugins, preparePlugins } from "$pano/lib/PluginManager";
25
+ import { executeLifecycle, executeViewLoad } from "$pano/lib/PluginAPI";
26
+ import { hasPermission } from "$pano/lib/auth.util";
27
+ import { trackPostView } from "$pano/lib/services/posts";
28
+
29
+ import DateComponent from "$pano/lib/components/Date.svelte";
30
+ import Pagination from "$pano/lib/components/Pagination.svelte";
31
+ import NoContent from "$pano/lib/components/NoContent.svelte";
32
+ import PageActions from "$pano/lib/components/PageActions.svelte";
33
+ import PageTitle from "$pano/lib/components/PageTitle.svelte";
34
+ import PlayerHead from "$pano/lib/components/PlayerHead.svelte";
35
+
36
+ const initLanguage = languageStuff.init;
37
+ const POST_VIEW_ENGAGEMENT_DELAY_MS = 8000;
38
+
39
+ async function sendVisitorVisitRequest({ event, csrfToken, isDemo }) {
40
+ if (isDemo) return;
41
+ ApiUtil.post({ path: "/api/visitorVisit", request: event, csrfToken });
42
+ }
43
+
44
+ function extractPostUrlFromPath(pathname) {
45
+ if (!pathname || typeof pathname !== "string") {
46
+ return null;
47
+ }
48
+
49
+ const normalizedPath = pathname.endsWith("/") && pathname.length > 1
50
+ ? pathname.slice(0, -1)
51
+ : pathname;
52
+
53
+ const postPathMatch = normalizedPath.match(/^\/post\/([^/]+)$/);
54
+ if (!postPathMatch || !postPathMatch[1]) {
55
+ return null;
56
+ }
57
+
58
+ try {
59
+ return decodeURIComponent(postPathMatch[1]);
60
+ } catch (_error) {
61
+ return postPathMatch[1];
62
+ }
63
+ }
64
+
65
+ function initNotificationListeners() {
66
+ addListener("AN_ADMIN_REPLIED_TICKET", async (notification) => {
67
+ const {
68
+ details: { id }
69
+ } = notification;
70
+
71
+ await goto("/ticket/" + id, { invalidateAll: true });
72
+ });
73
+
74
+ addListener("AN_ADMIN_CLOSED_TICKET", async (notification) => {
75
+ const {
76
+ details: { id }
77
+ } = notification;
78
+
79
+ await goto("/ticket/" + id, { invalidateAll: true });
80
+ });
81
+ }
82
+
83
+ export async function processServerLoad(event) {
84
+ const {
85
+ locals: { user, csrfToken, apiUrlEnv, panoWebsiteUrlEnv }
86
+ } = event;
87
+
88
+ let siteInfo = await ApiUtil.get({
89
+ path: "/api/siteInfo",
90
+ request: event,
91
+ csrfToken
92
+ });
93
+
94
+ await preparePlugins(siteInfo);
95
+
96
+ const avatarVersionDate = `v=${Date.now()}`;
97
+
98
+ return {
99
+ user,
100
+ csrfToken,
101
+ siteInfo,
102
+ apiUrlEnv,
103
+ panoWebsiteUrlEnv,
104
+ avatarVersionDate,
105
+ };
106
+ }
107
+
108
+ export async function processLoad(event) {
109
+ const {
110
+ data: {
111
+ user,
112
+ csrfToken,
113
+ siteInfo,
114
+ apiUrlEnv,
115
+ panoWebsiteUrlEnv,
116
+ avatarVersionDate,
117
+ },
118
+ parent,
119
+ } = event;
120
+ await parent();
121
+ avatarVersion.set(avatarVersionDate);
122
+
123
+ if (apiUrlEnv) {
124
+ updateApiUrl(apiUrlEnv);
125
+ }
126
+
127
+ if (panoWebsiteUrlEnv) {
128
+ updatePanoWebsiteUrl(panoWebsiteUrlEnv);
129
+ }
130
+
131
+ if (browser) {
132
+ checkDomainRedirection();
133
+ }
134
+
135
+ const [
136
+ ResolvedDate,
137
+ ResolvedPagination,
138
+ ResolvedNoContent,
139
+ ResolvedPageActions,
140
+ ResolvedPageTitle,
141
+ ResolvedPlayerHead,
142
+ ] = await Promise.all([
143
+ resolveView("Date", async () => DateComponent),
144
+ resolveView("Pagination", async () => Pagination),
145
+ resolveView("NoContent", async () => NoContent),
146
+ resolveView("PageActions", async () => PageActions),
147
+ resolveView("PageTitle", async () => PageTitle),
148
+ resolveView("PlayerHead", async () => PlayerHead),
149
+ ]);
150
+
151
+ setPanoContext({
152
+ page,
153
+ base,
154
+ navigating,
155
+ browser,
156
+ goto,
157
+ error,
158
+ redirect,
159
+ components: {
160
+ Date: ResolvedDate,
161
+ Pagination: ResolvedPagination,
162
+ NoContent: ResolvedNoContent,
163
+ PageActions: ResolvedPageActions,
164
+ PageTitle: ResolvedPageTitle,
165
+ PlayerHead: ResolvedPlayerHead,
166
+ },
167
+ utils: {
168
+ api: {
169
+ ApiUtil,
170
+ ...ApiUtilStuff,
171
+ },
172
+ language: {
173
+ ...languageStuff,
174
+ _,
175
+ },
176
+ tooltip: {
177
+ tooltip,
178
+ },
179
+ toast: {
180
+ ...toastStuff,
181
+ },
182
+ auth: {
183
+ hasPermission,
184
+ },
185
+ text: {
186
+ copy,
187
+ },
188
+ },
189
+ variables: {
190
+ ...variableStuff,
191
+ },
192
+ });
193
+
194
+ await initializePlugins(siteInfo);
195
+
196
+ const output = {
197
+ session: { user, csrfToken, siteInfo },
198
+ _pageTitleStore: writable(null),
199
+ _breadcrumbsStore: writable(null)
200
+ };
201
+
202
+ // theme:navbar:load must run first — plugins may register items into
203
+ // navbar-right / navbar-profile-dropdown views during this lifecycle.
204
+ await executeLifecycle("theme:navbar:load", output, event);
205
+
206
+ // After navbar lifecycle, the two view loads operate on independent viewIds,
207
+ // theme:app:load writes to output but doesn't depend on view results,
208
+ // and initLanguage is fully independent. Run them all in parallel.
209
+ await Promise.all([
210
+ executeViewLoad("navbar-right", event),
211
+ executeViewLoad("navbar-profile-dropdown", event),
212
+ executeLifecycle("theme:app:load", output, event),
213
+ initLanguage(siteInfo.locale, event)
214
+ ]);
215
+
216
+ if (browser && !get(initialized)) {
217
+ initNotificationListeners();
218
+ }
219
+
220
+ return output;
221
+ }
222
+
223
+ export function init(data) {
224
+ const session = writable(data.session);
225
+ const sidebar = writable(null);
226
+ const sidebarProps = writable({});
227
+ let activePostUrl = null;
228
+ let postViewTimeoutId = null;
229
+
230
+ const clearPendingPostViewTracking = () => {
231
+ if (!browser || postViewTimeoutId === null) {
232
+ return;
233
+ }
234
+
235
+ window.clearTimeout(postViewTimeoutId);
236
+ postViewTimeoutId = null;
237
+ };
238
+
239
+ const schedulePostViewTracking = (postUrl) => {
240
+ clearPendingPostViewTracking();
241
+
242
+ if (!browser || !postUrl || document.visibilityState !== "visible") {
243
+ return;
244
+ }
245
+
246
+ postViewTimeoutId = window.setTimeout(() => {
247
+ if (document.visibilityState !== "visible" || activePostUrl !== postUrl) {
248
+ return;
249
+ }
250
+
251
+ trackPostView({
252
+ url: postUrl,
253
+ csrfToken: get(session)?.csrfToken
254
+ });
255
+ }, POST_VIEW_ENGAGEMENT_DELAY_MS);
256
+ };
257
+
258
+ const pageUnsubscribe = page.subscribe((currentPage) => {
259
+ session.update((current) => {
260
+ const incoming = currentPage.data.session;
261
+ if (!incoming) return current;
262
+
263
+ if (!!current?.user !== !!incoming.user) {
264
+ return { ...incoming, user: current.user, csrfToken: current.csrfToken };
265
+ }
266
+
267
+ return incoming;
268
+ });
269
+ sidebar.update(() => currentPage.data.sidebar);
270
+ sidebarProps.update(() => currentPage.data.sidebarProps || {});
271
+ // Sync pageTitle store from page load data.
272
+ // Pages that return pageTitle in their load function will have it here.
273
+ // Pages without a pageTitle will have undefined, clearing the old value.
274
+ data._pageTitleStore.set(currentPage.data.pageTitle || null);
275
+ // Breadcrumbs are opt-in per page: pages that want a breadcrumb must
276
+ // return a `breadcrumbs` array from their load function. Pages that
277
+ // don't provide one will clear any previous value.
278
+ data._breadcrumbsStore.set(currentPage.data.breadcrumbs || null);
279
+
280
+ if (!browser) {
281
+ return;
282
+ }
283
+
284
+ activePostUrl = extractPostUrlFromPath(currentPage.url?.pathname);
285
+ schedulePostViewTracking(activePostUrl);
286
+ });
287
+
288
+ setContext("session", session);
289
+ setContext("sidebar", sidebar);
290
+ setContext("sidebarProps", sidebarProps);
291
+ setContext("pageTitle", data._pageTitleStore);
292
+ setContext("breadcrumbs", data._breadcrumbsStore);
293
+ setContext("themeSettings", data.session.siteInfo.themeSettings);
294
+
295
+ const onVisibilityChange = () => {
296
+ schedulePostViewTracking(activePostUrl);
297
+ };
298
+
299
+ if (browser) {
300
+ document.addEventListener("visibilitychange", onVisibilityChange);
301
+ }
302
+
303
+ onDestroy(() => {
304
+ pageUnsubscribe();
305
+ clearPendingPostViewTracking();
306
+
307
+ if (browser) {
308
+ document.removeEventListener("visibilitychange", onVisibilityChange);
309
+ }
310
+ });
311
+
312
+ onMount(() => {
313
+ initialized.set(true);
314
+
315
+ sendVisitorVisitRequest({ isDemo: data.session.siteInfo.isDemo });
316
+ });
317
+
318
+ const pageTitle = data._pageTitleStore;
319
+ const breadcrumbs = data._breadcrumbsStore;
320
+ return { session, sidebar, sidebarProps, pageTitle, breadcrumbs };
321
+ }
@@ -0,0 +1,10 @@
1
+ import { requireNotLogin } from "$pano/lib/Store";
2
+
3
+ export async function processLoad({ parent }) {
4
+ const parentData = await parent();
5
+ const { session } = parentData;
6
+
7
+ requireNotLogin(session);
8
+
9
+ return parentData;
10
+ }