@seip/bluebird-js 0.1.6 → 0.2.0

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 (152) hide show
  1. package/.vscode/extensions.json +7 -7
  2. package/.vscode/settings.json +10 -10
  3. package/AGENTS.md +266 -116
  4. package/README.md +258 -245
  5. package/app/models/user.js +19 -0
  6. package/app/resources/html/home.html +137 -0
  7. package/app/resources/html/layouts/main.html +54 -0
  8. package/app/resources/html/notFound.html +14 -0
  9. package/app/resources/html/terms.html +46 -0
  10. package/app/resources/index.html +27 -0
  11. package/app/resources/layouts/AppLayout.jsx +89 -0
  12. package/app/resources/main.jsx +18 -0
  13. package/app/resources/pages/Dashboard.jsx +98 -0
  14. package/app/resources/pages/Home.jsx +140 -0
  15. package/app/resources/pages/Login.jsx +35 -0
  16. package/app/resources/pages/NotFound.jsx +16 -0
  17. package/app/resources/pages/Register.jsx +55 -0
  18. package/app/resources/routes.jsx +54 -0
  19. package/app/resources/spa.js +67 -0
  20. package/app/resources/styles.css +9 -0
  21. package/app/routes/api.js +85 -50
  22. package/app/routes/auth.js +209 -0
  23. package/app/routes/web.js +49 -37
  24. package/core/ai.d.ts +151 -151
  25. package/core/ai.js +1071 -1051
  26. package/core/app.d.ts +2 -18
  27. package/core/app.js +978 -792
  28. package/core/auth.d.ts +2 -13
  29. package/core/auth.js +444 -326
  30. package/core/cli/backup.js +167 -167
  31. package/core/cli/build.js +37 -0
  32. package/core/cli/dev.js +155 -0
  33. package/core/cli/doctor.js +37 -2
  34. package/core/cli/export.js +191 -0
  35. package/core/cli/init.js +101 -332
  36. package/core/cli/nginx.js +1 -1
  37. package/core/cli/templates.js +139 -0
  38. package/core/cli/view.js +73 -136
  39. package/core/config.js +44 -2
  40. package/core/csrf.js +156 -24
  41. package/core/database.js +737 -684
  42. package/core/debug.js +1 -1
  43. package/core/html.js +8 -1
  44. package/core/index.d.ts +1286 -1431
  45. package/core/paths.js +55 -0
  46. package/core/ratelimit.js +10 -1
  47. package/core/react/client/api.js +237 -0
  48. package/core/react/client/auth.js +236 -0
  49. package/core/react/client/components.js +1321 -0
  50. package/core/react/client/i18n.js +338 -0
  51. package/core/react/client/index.d.ts +249 -0
  52. package/core/react/client/index.js +49 -0
  53. package/core/react/client/router.js +26 -0
  54. package/core/react/client/theme.css +512 -0
  55. package/core/render-cache.js +250 -212
  56. package/core/render.d.ts +25 -21
  57. package/core/render.js +613 -603
  58. package/core/router.d.ts +2 -3
  59. package/core/router.js +171 -171
  60. package/core/seo.js +10 -0
  61. package/core/spa.js +599 -0
  62. package/core/view-loader.js +81 -455
  63. package/core/vite-plugin.d.ts +18 -0
  64. package/core/vite-plugin.js +162 -0
  65. package/core/vite.js +250 -145
  66. package/index.js +22 -18
  67. package/jsconfig.json +5 -3
  68. package/package.json +114 -92
  69. package/production.md +8 -3
  70. package/public/js/bluebird.js +1160 -0
  71. package/templates/_auth/app/database.js +19 -0
  72. package/templates/_auth/app/models/user.js +22 -0
  73. package/templates/_auth/app/routes/auth-router.js +304 -0
  74. package/templates/_base/app/resources/html/layouts/main.html +55 -0
  75. package/templates/_base/app/resources/html/notFound.html +14 -0
  76. package/templates/_base/app/resources/index.html +27 -0
  77. package/templates/_base/app/resources/styles.css +9 -0
  78. package/templates/api/app/models/note.js +18 -0
  79. package/templates/api/app/routes/api.js +82 -0
  80. package/templates/api/app/routes/auth.js +11 -0
  81. package/templates/api/index.js +19 -0
  82. package/templates/api/template.json +13 -0
  83. package/templates/auth/app/mail.js +11 -0
  84. package/templates/auth/app/models/password_reset.js +18 -0
  85. package/templates/auth/app/resources/html/home.html +21 -0
  86. package/templates/auth/app/resources/html/partials/nav.html +2 -0
  87. package/templates/auth/app/resources/layouts/AppLayout.jsx +60 -0
  88. package/templates/auth/app/resources/main.jsx +18 -0
  89. package/templates/auth/app/resources/pages/Dashboard.jsx +51 -0
  90. package/templates/auth/app/resources/pages/ForgotPassword.jsx +34 -0
  91. package/templates/auth/app/resources/pages/Login.jsx +36 -0
  92. package/templates/auth/app/resources/pages/NotFound.jsx +16 -0
  93. package/templates/auth/app/resources/pages/Profile.jsx +99 -0
  94. package/templates/auth/app/resources/pages/Register.jsx +50 -0
  95. package/templates/auth/app/resources/pages/ResetPassword.jsx +50 -0
  96. package/templates/auth/app/resources/routes.jsx +54 -0
  97. package/templates/auth/app/resources/spa.js +29 -0
  98. package/templates/auth/app/routes/api.js +17 -0
  99. package/templates/auth/app/routes/auth.js +13 -0
  100. package/templates/auth/app/routes/web.js +21 -0
  101. package/templates/auth/index.js +19 -0
  102. package/templates/auth/template.json +15 -0
  103. package/templates/blank/app/models/.gitkeep +0 -0
  104. package/templates/blank/app/resources/html/home.html +27 -0
  105. package/templates/blank/app/resources/html/partials/nav.html +1 -0
  106. package/templates/blank/app/resources/main.jsx +16 -0
  107. package/templates/blank/app/resources/pages/Home.jsx +42 -0
  108. package/templates/blank/app/resources/pages/NotFound.jsx +27 -0
  109. package/templates/blank/app/resources/routes.jsx +15 -0
  110. package/templates/blank/app/resources/spa.js +24 -0
  111. package/templates/blank/app/routes/api.js +11 -0
  112. package/templates/blank/app/routes/web.js +21 -0
  113. package/templates/blank/index.js +13 -0
  114. package/templates/blank/template.json +12 -0
  115. package/templates/blog/app/lib/blog.js +149 -0
  116. package/templates/blog/app/models/post.js +22 -0
  117. package/templates/blog/app/resources/html/home.html +28 -0
  118. package/templates/blog/app/resources/html/not-found.html +5 -0
  119. package/templates/blog/app/resources/html/partials/nav.html +2 -0
  120. package/templates/blog/app/resources/html/partials/post-card.html +9 -0
  121. package/templates/blog/app/resources/html/post.html +8 -0
  122. package/templates/blog/app/resources/layouts/AdminLayout.jsx +54 -0
  123. package/templates/blog/app/resources/main.jsx +18 -0
  124. package/templates/blog/app/resources/pages/Login.jsx +31 -0
  125. package/templates/blog/app/resources/pages/NotFound.jsx +16 -0
  126. package/templates/blog/app/resources/pages/PostEditor.jsx +51 -0
  127. package/templates/blog/app/resources/pages/Posts.jsx +83 -0
  128. package/templates/blog/app/resources/pages/Register.jsx +43 -0
  129. package/templates/blog/app/resources/routes.jsx +51 -0
  130. package/templates/blog/app/resources/spa.js +25 -0
  131. package/templates/blog/app/resources/styles.css +40 -0
  132. package/templates/blog/app/routes/api.js +77 -0
  133. package/templates/blog/app/routes/auth.js +10 -0
  134. package/templates/blog/app/routes/web.js +114 -0
  135. package/templates/blog/index.js +21 -0
  136. package/templates/blog/template.json +14 -0
  137. package/vite.config.js +11 -0
  138. package/app/views/about.jsx +0 -98
  139. package/app/views/components/Header.jsx +0 -42
  140. package/app/views/components/LiveCounter.jsx +0 -66
  141. package/app/views/dashboard.jsx +0 -300
  142. package/app/views/index.jsx +0 -123
  143. package/app/views/layouts/main/view.jsx +0 -201
  144. package/app/views/legal/terms.html +0 -29
  145. package/app/views/login.jsx +0 -141
  146. package/core/actions.d.ts +0 -4
  147. package/core/actions.js +0 -329
  148. package/core/jsx.d.ts +0 -38
  149. package/core/jsx.js +0 -1432
  150. package/core/vite.d.ts +0 -3
  151. package/public/js/bluebird-client.js +0 -3161
  152. package/public/js/tailwind.js +0 -8
@@ -0,0 +1,1160 @@
1
+ (function (global) {
2
+ if (typeof window === "undefined" || typeof document === "undefined") return;
3
+ if (global.Bluebird && global.Bluebird.__loaded) return;
4
+
5
+ const THEME_STORAGE_KEY = "bb-theme";
6
+ const TONES = ["info", "success", "warning", "error"];
7
+ /**
8
+ * Built-in UI strings (kept identical to `core/react/client/i18n.js`). Missing keys fall back to English.
9
+ * @type {Record<string, Record<string, string>>}
10
+ */
11
+ const MESSAGES = {
12
+ "en": {
13
+ "toast.info": "Info",
14
+ "toast.success": "Success",
15
+ "toast.warning": "Warning",
16
+ "toast.error": "Error",
17
+ "toast.danger": "Alert",
18
+ "toast.region": "Notifications",
19
+ "toast.dismiss": "Dismiss notification",
20
+ "theme.toLight": "Switch to light theme",
21
+ "theme.toDark": "Switch to dark theme",
22
+ "theme.light": "Light",
23
+ "theme.dark": "Dark",
24
+ "dialog.close": "Close",
25
+ "dialog.label": "Dialog",
26
+ "drawer.label": "Panel",
27
+ "carousel.label": "Featured showcase",
28
+ "carousel.role": "carousel",
29
+ "carousel.slide": "slide",
30
+ "carousel.slides": "Slides",
31
+ "carousel.choose": "Choose a slide",
32
+ "carousel.prev": "Previous slide",
33
+ "carousel.next": "Next slide",
34
+ "carousel.prevShort": "Prev",
35
+ "carousel.nextShort": "Next",
36
+ "carousel.goTo": "Go to slide {n}",
37
+ "carousel.position": "{n} of {total}",
38
+ "carousel.status": "Slide {n} of {total}",
39
+ "loading": "Loading...",
40
+ "request.failed": "Request failed",
41
+ "request.network": "Network error",
42
+ "form.invalid": "Please check this field.",
43
+ "form.validation": "Validation error",
44
+ "value.invalid": "Invalid value",
45
+ "copy.done": "Copied to clipboard",
46
+ "auth.deniedTitle": "Access denied",
47
+ "auth.deniedText": "You do not have permission to view this section."
48
+ },
49
+ "es": {
50
+ "toast.info": "Info",
51
+ "toast.success": "Correcto",
52
+ "toast.warning": "Cuidado",
53
+ "toast.error": "Error",
54
+ "toast.danger": "Alerta",
55
+ "toast.region": "Notificaciones",
56
+ "toast.dismiss": "Cerrar notificación",
57
+ "theme.toLight": "Cambiar a tema claro",
58
+ "theme.toDark": "Cambiar a tema oscuro",
59
+ "theme.light": "Claro",
60
+ "theme.dark": "Oscuro",
61
+ "dialog.close": "Cerrar",
62
+ "dialog.label": "Diálogo",
63
+ "drawer.label": "Panel",
64
+ "carousel.label": "Destacados",
65
+ "carousel.role": "carrusel",
66
+ "carousel.slide": "diapositiva",
67
+ "carousel.slides": "Diapositivas",
68
+ "carousel.choose": "Elegir diapositiva",
69
+ "carousel.prev": "Diapositiva anterior",
70
+ "carousel.next": "Diapositiva siguiente",
71
+ "carousel.prevShort": "Anterior",
72
+ "carousel.nextShort": "Siguiente",
73
+ "carousel.goTo": "Ir a la diapositiva {n}",
74
+ "carousel.position": "{n} de {total}",
75
+ "carousel.status": "Diapositiva {n} de {total}",
76
+ "loading": "Cargando...",
77
+ "request.failed": "La solicitud falló",
78
+ "request.network": "Error de red",
79
+ "form.invalid": "Revisa este campo.",
80
+ "form.validation": "Error de validación",
81
+ "value.invalid": "Valor inválido",
82
+ "copy.done": "Copiado al portapapeles",
83
+ "auth.deniedTitle": "Acceso denegado",
84
+ "auth.deniedText": "No tienes permiso para ver esta sección."
85
+ },
86
+ "pt": {
87
+ "toast.info": "Info",
88
+ "toast.success": "Sucesso",
89
+ "toast.warning": "Atenção",
90
+ "toast.error": "Erro",
91
+ "toast.danger": "Alerta",
92
+ "toast.region": "Notificações",
93
+ "toast.dismiss": "Fechar notificação",
94
+ "theme.toLight": "Mudar para o tema claro",
95
+ "theme.toDark": "Mudar para o tema escuro",
96
+ "theme.light": "Claro",
97
+ "theme.dark": "Escuro",
98
+ "dialog.close": "Fechar",
99
+ "dialog.label": "Diálogo",
100
+ "drawer.label": "Painel",
101
+ "carousel.label": "Destaques",
102
+ "carousel.role": "carrossel",
103
+ "carousel.slide": "slide",
104
+ "carousel.slides": "Slides",
105
+ "carousel.choose": "Escolher slide",
106
+ "carousel.prev": "Slide anterior",
107
+ "carousel.next": "Próximo slide",
108
+ "carousel.prevShort": "Anterior",
109
+ "carousel.nextShort": "Próximo",
110
+ "carousel.goTo": "Ir para o slide {n}",
111
+ "carousel.position": "{n} de {total}",
112
+ "carousel.status": "Slide {n} de {total}",
113
+ "loading": "Carregando...",
114
+ "request.failed": "A solicitação falhou",
115
+ "request.network": "Erro de rede",
116
+ "form.invalid": "Verifique este campo.",
117
+ "form.validation": "Erro de validação",
118
+ "value.invalid": "Valor inválido",
119
+ "copy.done": "Copiado para a área de transferência",
120
+ "auth.deniedTitle": "Acesso negado",
121
+ "auth.deniedText": "Você não tem permissão para ver esta seção."
122
+ },
123
+ "fr": {
124
+ "toast.info": "Info",
125
+ "toast.success": "Succès",
126
+ "toast.warning": "Attention",
127
+ "toast.error": "Erreur",
128
+ "toast.danger": "Alerte",
129
+ "toast.region": "Notifications",
130
+ "toast.dismiss": "Fermer la notification",
131
+ "theme.toLight": "Passer au thème clair",
132
+ "theme.toDark": "Passer au thème sombre",
133
+ "theme.light": "Clair",
134
+ "theme.dark": "Sombre",
135
+ "dialog.close": "Fermer",
136
+ "dialog.label": "Boîte de dialogue",
137
+ "drawer.label": "Panneau",
138
+ "carousel.label": "À la une",
139
+ "carousel.role": "carrousel",
140
+ "carousel.slide": "diapositive",
141
+ "carousel.slides": "Diapositives",
142
+ "carousel.choose": "Choisir une diapositive",
143
+ "carousel.prev": "Diapositive précédente",
144
+ "carousel.next": "Diapositive suivante",
145
+ "carousel.prevShort": "Préc.",
146
+ "carousel.nextShort": "Suiv.",
147
+ "carousel.goTo": "Aller à la diapositive {n}",
148
+ "carousel.position": "{n} sur {total}",
149
+ "carousel.status": "Diapositive {n} sur {total}",
150
+ "loading": "Chargement...",
151
+ "request.failed": "La requête a échoué",
152
+ "request.network": "Erreur réseau",
153
+ "form.invalid": "Vérifiez ce champ.",
154
+ "form.validation": "Erreur de validation",
155
+ "value.invalid": "Valeur invalide",
156
+ "copy.done": "Copié dans le presse-papiers",
157
+ "auth.deniedTitle": "Accès refusé",
158
+ "auth.deniedText": "Vous n'avez pas l'autorisation de voir cette section."
159
+ },
160
+ "de": {
161
+ "toast.info": "Info",
162
+ "toast.success": "Erfolg",
163
+ "toast.warning": "Achtung",
164
+ "toast.error": "Fehler",
165
+ "toast.danger": "Warnung",
166
+ "toast.region": "Benachrichtigungen",
167
+ "toast.dismiss": "Benachrichtigung schließen",
168
+ "theme.toLight": "Zum hellen Design wechseln",
169
+ "theme.toDark": "Zum dunklen Design wechseln",
170
+ "theme.light": "Hell",
171
+ "theme.dark": "Dunkel",
172
+ "dialog.close": "Schließen",
173
+ "dialog.label": "Dialog",
174
+ "drawer.label": "Seitenleiste",
175
+ "carousel.label": "Highlights",
176
+ "carousel.role": "Karussell",
177
+ "carousel.slide": "Folie",
178
+ "carousel.slides": "Folien",
179
+ "carousel.choose": "Folie auswählen",
180
+ "carousel.prev": "Vorherige Folie",
181
+ "carousel.next": "Nächste Folie",
182
+ "carousel.prevShort": "Zurück",
183
+ "carousel.nextShort": "Weiter",
184
+ "carousel.goTo": "Zu Folie {n}",
185
+ "carousel.position": "{n} von {total}",
186
+ "carousel.status": "Folie {n} von {total}",
187
+ "loading": "Wird geladen...",
188
+ "request.failed": "Anfrage fehlgeschlagen",
189
+ "request.network": "Netzwerkfehler",
190
+ "form.invalid": "Bitte überprüfe dieses Feld.",
191
+ "form.validation": "Validierungsfehler",
192
+ "value.invalid": "Ungültiger Wert",
193
+ "copy.done": "In die Zwischenablage kopiert",
194
+ "auth.deniedTitle": "Zugriff verweigert",
195
+ "auth.deniedText": "Du hast keine Berechtigung, diesen Bereich zu sehen."
196
+ },
197
+ "it": {
198
+ "toast.info": "Info",
199
+ "toast.success": "Fatto",
200
+ "toast.warning": "Attenzione",
201
+ "toast.error": "Errore",
202
+ "toast.danger": "Avviso",
203
+ "toast.region": "Notifiche",
204
+ "toast.dismiss": "Chiudi notifica",
205
+ "theme.toLight": "Passa al tema chiaro",
206
+ "theme.toDark": "Passa al tema scuro",
207
+ "theme.light": "Chiaro",
208
+ "theme.dark": "Scuro",
209
+ "dialog.close": "Chiudi",
210
+ "dialog.label": "Finestra di dialogo",
211
+ "drawer.label": "Pannello",
212
+ "carousel.label": "In evidenza",
213
+ "carousel.role": "carosello",
214
+ "carousel.slide": "slide",
215
+ "carousel.slides": "Slide",
216
+ "carousel.choose": "Scegli una slide",
217
+ "carousel.prev": "Slide precedente",
218
+ "carousel.next": "Slide successiva",
219
+ "carousel.prevShort": "Prec.",
220
+ "carousel.nextShort": "Succ.",
221
+ "carousel.goTo": "Vai alla slide {n}",
222
+ "carousel.position": "{n} di {total}",
223
+ "carousel.status": "Slide {n} di {total}",
224
+ "loading": "Caricamento...",
225
+ "request.failed": "Richiesta non riuscita",
226
+ "request.network": "Errore di rete",
227
+ "form.invalid": "Controlla questo campo.",
228
+ "form.validation": "Errore di convalida",
229
+ "value.invalid": "Valore non valido",
230
+ "copy.done": "Copiato negli appunti",
231
+ "auth.deniedTitle": "Accesso negato",
232
+ "auth.deniedText": "Non hai il permesso di vedere questa sezione."
233
+ }
234
+ };
235
+ const customMessages = {};
236
+ let forcedLocale = null;
237
+ let toastSeq = 0;
238
+ let toastRoot = null;
239
+ let toastLive = null;
240
+ let stylesInjected = false;
241
+ let cachedDisplayTransitionSupport;
242
+
243
+ /**
244
+ * Returns the active UI locale: `Bluebird.i18n.setLocale()` override, then `<html lang>`, then the browser language.
245
+ * @returns {string}
246
+ */
247
+ function getLocale() {
248
+ return forcedLocale || document.documentElement.lang || navigator.language || "en";
249
+ }
250
+
251
+ /**
252
+ * Translates a UI string key for the active locale (exact tag, base language, then English), replacing `{name}` placeholders.
253
+ * @param {string} key
254
+ * @param {Record<string, string|number>} [params]
255
+ * @returns {string}
256
+ */
257
+ function t(key, params) {
258
+ const full = String(getLocale()).toLowerCase();
259
+ let message;
260
+ for (const tag of [full, full.split("-")[0], "en"]) {
261
+ message = customMessages[tag]?.[key] ?? MESSAGES[tag]?.[key];
262
+ if (message !== undefined) break;
263
+ }
264
+ message = message ?? key;
265
+ if (!params) return message;
266
+ return message.replace(/\{(\w+)\}/g, (match, name) => (params[name] !== undefined ? String(params[name]) : match));
267
+ }
268
+
269
+ /**
270
+ * Adds or overrides UI strings for a language.
271
+ * @param {string} locale
272
+ * @param {Record<string, string>} messages
273
+ */
274
+ function addMessages(locale, messages) {
275
+ const key = String(locale).toLowerCase();
276
+ customMessages[key] = Object.assign({}, customMessages[key], messages);
277
+ }
278
+
279
+ /**
280
+ * Forces the UI locale (`null` returns to `<html lang>` detection).
281
+ * @param {string|null} locale
282
+ */
283
+ function setLocale(locale) {
284
+ forcedLocale = locale ? String(locale) : null;
285
+ }
286
+
287
+ /**
288
+ * Injects minimal self-contained styles for toasts, native `<dialog>` modals, and scroll-snap carousels.
289
+ */
290
+ function ensureStyles() {
291
+ if (stylesInjected || !document.head) return;
292
+ stylesInjected = true;
293
+ const style = document.createElement("style");
294
+ style.setAttribute("data-bb-ui", "true");
295
+ style.textContent = [
296
+ ".bb-vh:where(:not(:focus-within,:active)){position:absolute!important;clip-path:inset(50%)!important;overflow:hidden!important;width:1px!important;height:1px!important;margin:-1px!important;padding:0!important;border:0!important;white-space:nowrap!important}",
297
+ ".bb-toast-stack{position:fixed;bottom:1rem;right:1rem;inset:auto 1rem 1rem auto;z-index:9999;margin:0;padding:0;border:0;background:transparent;overflow:visible;display:flex;flex-direction:column;gap:.625rem;width:22rem;max-width:calc(100vw - 2rem);pointer-events:none}",
298
+ ".bb-toast-stack[popover]:not(:is(:popover-open,.\\:popover-open)){display:none}",
299
+ ".bb-toast{pointer-events:auto;display:flex;flex-direction:column;gap:.35rem;padding:.875rem 1rem;border-radius:1rem;border:1px solid var(--border,rgba(161,161,170,.3));background:color-mix(in oklab,var(--popover,#fff) 90%,transparent);color:var(--popover-foreground,#18181b);box-shadow:inset 0 1px 0 0 rgba(255,255,255,.5),0 2px 6px rgba(0,0,0,.05),0 18px 40px -14px rgba(0,0,0,.2);-webkit-backdrop-filter:blur(20px) saturate(1.5);backdrop-filter:blur(20px) saturate(1.5);font-family:inherit;font-size:.875rem;line-height:1.45;opacity:1;transition:opacity .22s,transform .22s;transition-timing-function:cubic-bezier(.22,1,.36,1)}",
300
+ "@media (prefers-reduced-motion:no-preference){@starting-style{.bb-toast{opacity:0;transform:translateY(.5rem) scale(.98)}}}",
301
+ "@media (prefers-reduced-motion:reduce){.bb-toast{transition-duration:.08s}}",
302
+ "html.dark .bb-toast,html[data-theme='dark'] .bb-toast{background:color-mix(in oklab,var(--popover,#18181b) 90%,transparent);color:var(--popover-foreground,#fafafa);box-shadow:inset 0 1px 0 0 rgba(255,255,255,.06),0 4px 12px rgba(0,0,0,.35),0 20px 44px -14px rgba(0,0,0,.7)}",
303
+ ".bb-toast-head{display:flex;align-items:center;justify-content:space-between;gap:.5rem}",
304
+ ".bb-toast-badge{display:inline-flex;align-items:center;gap:.375rem;border-radius:9999px;padding:.125rem .5rem;font-size:.6875rem;font-weight:500;line-height:1.25;border:1px solid color-mix(in oklab,var(--info,#0284c7) 30%,transparent);background:color-mix(in oklab,var(--info,#0284c7) 12%,transparent);color:color-mix(in oklab,var(--info,#0284c7) 85%,var(--foreground,#18181b))}",
305
+ ".bb-toast-dot{width:.375rem;height:.375rem;border-radius:9999px;flex-shrink:0;background:var(--info,#0284c7)}",
306
+ ".bb-toast[data-type='success'] .bb-toast-badge{border-color:color-mix(in oklab,var(--success,#16a34a) 32%,transparent);background:color-mix(in oklab,var(--success,#16a34a) 13%,transparent);color:color-mix(in oklab,var(--success,#16a34a) 82%,var(--foreground,#18181b))}",
307
+ ".bb-toast[data-type='success'] .bb-toast-dot{background:var(--success,#16a34a)}",
308
+ ".bb-toast[data-type='warning'] .bb-toast-badge{border-color:color-mix(in oklab,var(--warning,#d97706) 35%,transparent);background:color-mix(in oklab,var(--warning,#d97706) 15%,transparent);color:color-mix(in oklab,var(--warning,#d97706) 75%,var(--foreground,#18181b))}",
309
+ ".bb-toast[data-type='warning'] .bb-toast-dot{background:var(--warning,#d97706)}",
310
+ ".bb-toast[data-type='error'] .bb-toast-badge{border-color:color-mix(in oklab,var(--destructive,#dc2626) 32%,transparent);background:color-mix(in oklab,var(--destructive,#dc2626) 12%,transparent);color:var(--destructive,#dc2626)}",
311
+ ".bb-toast[data-type='error'] .bb-toast-dot{background:var(--destructive,#dc2626)}",
312
+ ".bb-toast-title{font-weight:600;margin:.125rem 0 0;color:var(--popover-foreground,#18181b)}",
313
+ "html.dark .bb-toast-title,html[data-theme='dark'] .bb-toast-title{color:var(--popover-foreground,#fafafa)}",
314
+ ".bb-toast-desc{margin:0;color:var(--muted-foreground,#71717a);font-size:.8125rem;line-height:1.45}",
315
+ ".bb-toast-close{display:inline-flex;align-items:center;justify-content:center;width:1.75rem;height:1.75rem;border:none;background:transparent;color:var(--muted-foreground,#71717a);cursor:pointer;margin:-.25rem -.25rem 0 0;border-radius:.5rem;font-size:.75rem;line-height:1;transition:background-color .15s,color .15s}",
316
+ ".bb-toast-close:hover{background:var(--accent,rgba(161,161,170,.16));color:var(--foreground,#18181b)}",
317
+ "html.dark .bb-toast-close:hover,html[data-theme='dark'] .bb-toast-close:hover{color:var(--foreground,#fafafa)}",
318
+ "[data-carousel]{position:relative;overflow:hidden}",
319
+ "[data-carousel-track]{display:flex;overflow-x:auto;scroll-snap-type:x mandatory;overscroll-behavior-x:contain;scrollbar-width:none;touch-action:manipulation}",
320
+ "[data-carousel-track]::-webkit-scrollbar{display:none}",
321
+ "@media (prefers-reduced-motion:no-preference){[data-carousel-track]{scroll-behavior:smooth}}",
322
+ "[data-carousel-slide]{width:100%;flex:0 0 100%;min-width:0;scroll-snap-align:center;box-sizing:border-box}",
323
+ "[data-carousel-dot]{display:inline-flex;align-items:center;justify-content:center;min-width:24px;min-height:24px;padding:6px;background:transparent;border:0;cursor:pointer;touch-action:manipulation}",
324
+ "[data-carousel-dot]::before{content:'';display:block;height:6px;width:6px;border-radius:9999px;background:color-mix(in oklab,var(--muted-foreground,#71717a) 35%,transparent);transition:width .25s,background-color .25s}",
325
+ "[data-carousel-dot][aria-current='true']::before{width:24px;background:var(--foreground,#18181b)}",
326
+ "html.dark [data-carousel-dot][aria-current='true']::before,html[data-theme='dark'] [data-carousel-dot][aria-current='true']::before{background:var(--foreground,#fafafa)}",
327
+ "dialog[data-modal]:modal{overscroll-behavior:contain}",
328
+ "dialog[data-modal]{opacity:0;transition-property:opacity,transform,display,overlay;transition-duration:.22s;transition-timing-function:cubic-bezier(.22,1,.36,1);transition-behavior:allow-discrete}",
329
+ "@media (prefers-reduced-motion:no-preference){dialog[data-modal]{transform:scale(.96) translateY(.5rem)}}",
330
+ "dialog[data-modal]::backdrop{overflow:hidden;overscroll-behavior:contain;background-color:rgba(0,0,0,0);backdrop-filter:blur(0);transition-property:background-color,backdrop-filter,display,overlay;transition-duration:.22s;transition-timing-function:ease-out;transition-behavior:allow-discrete}",
331
+ "dialog[data-modal][open]:where(:not([data-closing])){opacity:1}",
332
+ "@starting-style{dialog[data-modal][open]:where(:not([data-closing])){opacity:0}}",
333
+ "@media (prefers-reduced-motion:no-preference){dialog[data-modal][open]:where(:not([data-closing])){transform:scale(1) translateY(0)}@starting-style{dialog[data-modal][open]:where(:not([data-closing])){transform:scale(.96) translateY(.5rem)}}}",
334
+ "dialog[data-modal][open]:where(:not([data-closing]))::backdrop{background-color:rgba(9,9,11,.45);backdrop-filter:blur(5px)}",
335
+ "@starting-style{dialog[data-modal][open]:where(:not([data-closing]))::backdrop{background-color:rgba(0,0,0,0);backdrop-filter:blur(0)}}",
336
+ "@media (prefers-reduced-motion:reduce){dialog[data-modal],dialog[data-modal]::backdrop{transition-duration:.08s}}",
337
+ ].join("");
338
+ document.head.appendChild(style);
339
+ }
340
+
341
+ /**
342
+ * Detects whether discrete `display` transitions are genuinely supported.
343
+ * @returns {boolean}
344
+ */
345
+ function canTransitionDisplay() {
346
+ if (cachedDisplayTransitionSupport !== undefined) return cachedDisplayTransitionSupport;
347
+ if (!window.CSS?.supports?.("transition-behavior", "allow-discrete") || !document.body) {
348
+ return false;
349
+ }
350
+ const probe = document.createElement("div");
351
+ probe.style.cssText = "transition: display 1s allow-discrete !important; display: block;";
352
+ document.body.appendChild(probe);
353
+ window.getComputedStyle(probe).display;
354
+ probe.style.display = "none";
355
+ cachedDisplayTransitionSupport = window.getComputedStyle(probe).display === "block";
356
+ probe.remove();
357
+ return cachedDisplayTransitionSupport;
358
+ }
359
+
360
+ /**
361
+ * Checks whether native top-layer exit transitions (`overlay` + discrete `display`) are supported.
362
+ * @returns {boolean}
363
+ */
364
+ function supportsTopLayerExit() {
365
+ return Boolean(window.CSS?.supports?.("overlay", "auto")) && canTransitionDisplay();
366
+ }
367
+
368
+ /**
369
+ * Animates a `<dialog>` out of the top layer when exit transitions require a closing attribute, then closes it.
370
+ * @param {HTMLDialogElement} dialog
371
+ */
372
+ async function closeTopLayerDialog(dialog) {
373
+ if (!dialog || !dialog.open) return;
374
+ if (!supportsTopLayerExit()) {
375
+ dialog.setAttribute("data-closing", "");
376
+ const animations = dialog.getAnimations ? dialog.getAnimations({ subtree: true }) : [];
377
+ if (animations.length > 0) {
378
+ await Promise.race([
379
+ Promise.allSettled(animations.map((a) => a.finished)),
380
+ new Promise((r) => setTimeout(r, 400)),
381
+ ]);
382
+ }
383
+ if (!dialog.hasAttribute("data-closing")) return;
384
+ dialog.removeAttribute("data-closing");
385
+ }
386
+ if (dialog.open) dialog.close();
387
+ }
388
+
389
+ /**
390
+ * Reads the `_csrf` cookie value for XHR/fetch double-submit CSRF headers.
391
+ * @returns {string}
392
+ */
393
+ function getCsrfToken() {
394
+ const match = document.cookie.match(/(?:^|;\s*)_csrf=([^;]*)/);
395
+ if (!match || !match[1]) return "";
396
+ try {
397
+ return decodeURIComponent(match[1]);
398
+ } catch {
399
+ return match[1];
400
+ }
401
+ }
402
+
403
+ /**
404
+ * Returns the system preferred color scheme (`"dark"` or `"light"`).
405
+ * @returns {"dark"|"light"}
406
+ */
407
+ function getSystemTheme() {
408
+ return window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
409
+ }
410
+
411
+ /**
412
+ * Applies theme classes, `<meta name="color-scheme">`, labels, and sync events.
413
+ * @param {"dark"|"light"} resolved
414
+ * @param {string|null} storedOverride
415
+ */
416
+ function applyDocumentTheme(resolved, storedOverride) {
417
+ const root = document.documentElement;
418
+ root.classList.toggle("dark", resolved === "dark");
419
+ root.setAttribute("data-theme", resolved);
420
+ const meta = document.querySelector('meta[name="color-scheme"]');
421
+ if (meta) {
422
+ meta.setAttribute("content", storedOverride === "light" || storedOverride === "dark" ? storedOverride : "light dark");
423
+ }
424
+ document.querySelectorAll("[data-theme-label]").forEach((el) => {
425
+ el.textContent = t(resolved === "dark" ? "theme.light" : "theme.dark");
426
+ });
427
+ window.dispatchEvent(new CustomEvent("bluebird:theme", { detail: { theme: resolved, stored: storedOverride } }));
428
+ }
429
+
430
+ /**
431
+ * Resolves and sets an explicit dark/light theme preference.
432
+ * @param {"dark"|"light"} mode
433
+ * @returns {"dark"|"light"}
434
+ */
435
+ function setTheme(mode) {
436
+ const resolved = mode === "light" ? "light" : "dark";
437
+ try {
438
+ window.localStorage.setItem(THEME_STORAGE_KEY, resolved);
439
+ } catch {}
440
+ applyDocumentTheme(resolved, resolved);
441
+ return resolved;
442
+ }
443
+
444
+ /**
445
+ * Returns the active theme name (`"dark"` or `"light"`).
446
+ * @returns {"dark"|"light"}
447
+ */
448
+ function getTheme() {
449
+ try {
450
+ const saved = window.localStorage.getItem(THEME_STORAGE_KEY);
451
+ if (saved === "light" || saved === "dark") return saved;
452
+ } catch {}
453
+ if (document.documentElement.classList.contains("dark")) return "dark";
454
+ if (document.documentElement.getAttribute("data-theme") === "light") return "light";
455
+ return getSystemTheme();
456
+ }
457
+
458
+ /**
459
+ * Toggles between light and dark themes, removing stored override when reverting to system default.
460
+ * @returns {"dark"|"light"}
461
+ */
462
+ function toggleTheme() {
463
+ const next = getTheme() === "dark" ? "light" : "dark";
464
+ const sys = getSystemTheme();
465
+ let stored = next;
466
+ try {
467
+ if (next === sys) {
468
+ window.localStorage.removeItem(THEME_STORAGE_KEY);
469
+ stored = null;
470
+ } else {
471
+ window.localStorage.setItem(THEME_STORAGE_KEY, next);
472
+ }
473
+ } catch {}
474
+ applyDocumentTheme(next, stored);
475
+ return next;
476
+ }
477
+
478
+ /**
479
+ * Announces toast messages cleanly via `navigator.ariaNotify` or a hidden polite live region.
480
+ * @param {string} text
481
+ */
482
+ function announceToast(text) {
483
+ if (!text) return;
484
+ if (typeof navigator !== "undefined" && typeof navigator.ariaNotify === "function") {
485
+ navigator.ariaNotify(text);
486
+ return;
487
+ }
488
+ if (!toastLive || !document.body.contains(toastLive)) {
489
+ toastLive = document.createElement("p");
490
+ toastLive.className = "bb-vh";
491
+ toastLive.setAttribute("aria-live", "polite");
492
+ document.body.appendChild(toastLive);
493
+ }
494
+ toastLive.textContent = "";
495
+ window.setTimeout(() => {
496
+ if (toastLive) toastLive.textContent = text;
497
+ }, 30);
498
+ }
499
+
500
+ /**
501
+ * Displays a frosted glass toast notification with a compact color-coded type badge inside a top-layer `popover="manual"` region.
502
+ * @param {string|{title?: string, description?: string, badge?: string, type?: "info"|"success"|"warning"|"error", duration?: number}} input
503
+ * @returns {number}
504
+ */
505
+ function toast(input) {
506
+ ensureStyles();
507
+ const opts = typeof input === "string" ? { title: input } : input || {};
508
+ const type = TONES.includes(opts.type) ? opts.type : "info";
509
+ const duration = opts.duration !== undefined ? Number(opts.duration) : 4500;
510
+ const triggerEl = document.activeElement;
511
+
512
+ if (!toastRoot || !document.body.contains(toastRoot)) {
513
+ toastRoot = document.createElement("div");
514
+ toastRoot.className = "bb-toast-stack";
515
+ toastRoot.setAttribute("role", "region");
516
+ toastRoot.setAttribute("aria-label", t("toast.region"));
517
+ if (Object.hasOwn(HTMLElement.prototype, "popover") || typeof toastRoot.showPopover === "function") {
518
+ toastRoot.setAttribute("popover", "manual");
519
+ }
520
+ document.body.appendChild(toastRoot);
521
+ }
522
+
523
+ if (typeof toastRoot.showPopover === "function") {
524
+ try {
525
+ if (!toastRoot.matches(":popover-open")) toastRoot.showPopover();
526
+ } catch {}
527
+ }
528
+
529
+ const id = ++toastSeq;
530
+ const item = document.createElement("div");
531
+ item.className = "bb-toast";
532
+ item.setAttribute("data-type", type);
533
+ item.setAttribute("data-toast-id", String(id));
534
+
535
+ const head = document.createElement("div");
536
+ head.className = "bb-toast-head";
537
+
538
+ const badge = document.createElement("span");
539
+ badge.className = "bb-toast-badge";
540
+ const dot = document.createElement("span");
541
+ dot.className = "bb-toast-dot";
542
+ dot.setAttribute("aria-hidden", "true");
543
+ badge.appendChild(dot);
544
+ badge.appendChild(document.createTextNode(opts.badge || t("toast." + type)));
545
+ head.appendChild(badge);
546
+
547
+ const closeBtn = document.createElement("button");
548
+ closeBtn.type = "button";
549
+ closeBtn.className = "bb-toast-close";
550
+ closeBtn.setAttribute("aria-label", t("toast.dismiss"));
551
+ closeBtn.textContent = "\u2715";
552
+ head.appendChild(closeBtn);
553
+ item.appendChild(head);
554
+
555
+ if (opts.title) {
556
+ const titleEl = document.createElement("p");
557
+ titleEl.className = "bb-toast-title";
558
+ titleEl.textContent = String(opts.title);
559
+ item.appendChild(titleEl);
560
+ }
561
+ if (opts.description) {
562
+ const descEl = document.createElement("p");
563
+ descEl.className = "bb-toast-desc";
564
+ descEl.textContent = String(opts.description);
565
+ item.appendChild(descEl);
566
+ }
567
+
568
+ let timer = null;
569
+ let remaining = duration;
570
+ let startedAt = Date.now();
571
+ let paused = false;
572
+
573
+ const removeToast = (fromKeyboard) => {
574
+ if (timer) clearTimeout(timer);
575
+ const siblings = toastRoot ? Array.from(toastRoot.querySelectorAll(".bb-toast-close")) : [];
576
+ const closeIndex = siblings.indexOf(closeBtn);
577
+ if (item.parentNode) item.parentNode.removeChild(item);
578
+ if (toastRoot && toastRoot.children.length === 0 && typeof toastRoot.hidePopover === "function") {
579
+ try {
580
+ if (toastRoot.matches(":popover-open")) toastRoot.hidePopover();
581
+ } catch {}
582
+ }
583
+ if (fromKeyboard) {
584
+ const nextBtns = toastRoot ? toastRoot.querySelectorAll(".bb-toast-close") : [];
585
+ if (nextBtns.length > 0) {
586
+ const target = nextBtns[Math.min(closeIndex, nextBtns.length - 1)];
587
+ target?.focus?.();
588
+ } else if (triggerEl?.isConnected) {
589
+ triggerEl.focus?.();
590
+ }
591
+ }
592
+ };
593
+
594
+ const pause = () => {
595
+ if (duration <= 0 || paused) return;
596
+ clearTimeout(timer);
597
+ remaining = Math.max(0, remaining - (Date.now() - startedAt));
598
+ paused = true;
599
+ };
600
+
601
+ const resume = () => {
602
+ if (duration <= 0 || !paused || remaining <= 0) return;
603
+ paused = false;
604
+ startedAt = Date.now();
605
+ timer = setTimeout(() => removeToast(false), remaining);
606
+ };
607
+
608
+ closeBtn.addEventListener("click", (e) => removeToast(e.detail === 0));
609
+ item.addEventListener("pointerenter", pause);
610
+ item.addEventListener("pointerleave", resume);
611
+ item.addEventListener("focusin", pause);
612
+ item.addEventListener("focusout", (e) => {
613
+ if (!item.contains(e.relatedTarget)) resume();
614
+ });
615
+
616
+ toastRoot.appendChild(item);
617
+ announceToast([opts.title, opts.description].filter(Boolean).join(". "));
618
+
619
+ if (duration > 0) {
620
+ startedAt = Date.now();
621
+ timer = setTimeout(() => removeToast(false), duration);
622
+ }
623
+ return id;
624
+ }
625
+
626
+ toast.success = (title, description) => toast({ type: "success", title, description });
627
+ toast.error = (title, description) => toast({ type: "error", title, description });
628
+ toast.info = (title, description) => toast({ type: "info", title, description });
629
+ toast.warning = (title, description) => toast({ type: "warning", title, description });
630
+
631
+ /**
632
+ * Initializes a native scroll-snap `[data-carousel]` element with controls, pill dots, autoplay, and polite live status.
633
+ * @param {HTMLElement} el
634
+ */
635
+ function initCarousel(el) {
636
+ if (!el || el.dataset.bbCarouselInit === "1") return;
637
+ const track = el.querySelector("[data-carousel-track]");
638
+ const slides = Array.from(el.querySelectorAll("[data-carousel-slide]"));
639
+ if (!track || slides.length === 0) return;
640
+ el.dataset.bbCarouselInit = "1";
641
+
642
+ if (!el.hasAttribute("role")) el.setAttribute("role", "region");
643
+ if (!el.hasAttribute("aria-roledescription")) el.setAttribute("aria-roledescription", t("carousel.role"));
644
+ if (!el.hasAttribute("aria-label")) el.setAttribute("aria-label", t("carousel.label"));
645
+ if (!track.hasAttribute("tabindex")) track.setAttribute("tabindex", "0");
646
+ if (!track.hasAttribute("role")) track.setAttribute("role", "group");
647
+ if (!track.hasAttribute("aria-label")) track.setAttribute("aria-label", t("carousel.slides"));
648
+
649
+ slides.forEach((slide, idx) => {
650
+ if (!slide.hasAttribute("role")) slide.setAttribute("role", "group");
651
+ if (!slide.hasAttribute("aria-roledescription")) slide.setAttribute("aria-roledescription", t("carousel.slide"));
652
+ if (!slide.hasAttribute("aria-label")) slide.setAttribute("aria-label", t("carousel.position", { n: idx + 1, total: slides.length }));
653
+ });
654
+
655
+ let statusEl = el.querySelector("[data-carousel-status]");
656
+ if (!statusEl) {
657
+ statusEl = document.createElement("p");
658
+ statusEl.className = "bb-vh";
659
+ statusEl.setAttribute("data-carousel-status", "");
660
+ statusEl.setAttribute("role", "status");
661
+ statusEl.setAttribute("aria-live", "polite");
662
+ el.appendChild(statusEl);
663
+ }
664
+
665
+ let current = Math.max(0, Number(el.dataset.index || 0)) % slides.length;
666
+ let settledIndex = current;
667
+ let pendingTarget = null;
668
+ let userInitiated = false;
669
+ let rafId = null;
670
+ let debounceTimer = null;
671
+ const loop = el.dataset.loop !== "false";
672
+ const autoplayMs = Number(el.dataset.autoplay || 0);
673
+ const dotsContainer = el.querySelector("[data-carousel-dots]");
674
+ const prevButton = el.querySelector("[data-carousel-prev]");
675
+ const nextButton = el.querySelector("[data-carousel-next]");
676
+ let timer = null;
677
+
678
+ if (dotsContainer && dotsContainer.children.length === 0) {
679
+ slides.forEach((_, idx) => {
680
+ const dot = document.createElement("button");
681
+ dot.type = "button";
682
+ dot.setAttribute("data-carousel-dot", String(idx));
683
+ dot.setAttribute("aria-label", t("carousel.goTo", { n: idx + 1 }));
684
+ dotsContainer.appendChild(dot);
685
+ });
686
+ }
687
+
688
+ const syncDots = (idx) => {
689
+ el.dataset.index = String(idx);
690
+ el.querySelectorAll("[data-carousel-dot]").forEach((dot, i) => {
691
+ const active = i === idx;
692
+ dot.setAttribute("data-active", active ? "true" : "false");
693
+ dot.setAttribute("aria-current", active ? "true" : "false");
694
+ });
695
+ if (!loop && slides.length > 1) {
696
+ if (prevButton) {
697
+ const prevDisabled = idx === 0;
698
+ if (prevDisabled && document.activeElement === prevButton) nextButton?.focus();
699
+ prevButton.disabled = prevDisabled;
700
+ }
701
+ if (nextButton) {
702
+ const nextDisabled = idx === slides.length - 1;
703
+ if (nextDisabled && document.activeElement === nextButton) prevButton?.focus();
704
+ nextButton.disabled = nextDisabled;
705
+ }
706
+ }
707
+ };
708
+
709
+ const getNearestSlide = () => {
710
+ const center = track.scrollLeft + track.clientWidth / 2;
711
+ let best = 0;
712
+ let bestDist = Infinity;
713
+ slides.forEach((slide, i) => {
714
+ const slideCenter = slide.offsetLeft + slide.offsetWidth / 2;
715
+ const dist = Math.abs(slideCenter - center);
716
+ if (dist < bestDist) {
717
+ bestDist = dist;
718
+ best = i;
719
+ }
720
+ });
721
+ return best;
722
+ };
723
+
724
+ const goTo = (rawIdx, initiatedByUser) => {
725
+ const target = loop
726
+ ? ((rawIdx % slides.length) + slides.length) % slides.length
727
+ : Math.max(0, Math.min(slides.length - 1, rawIdx));
728
+ if (initiatedByUser) userInitiated = true;
729
+ pendingTarget = target;
730
+ current = target;
731
+ syncDots(target);
732
+ const slide = slides[target];
733
+ if (!slide) return;
734
+ const targetLeft = Math.max(0, slide.offsetLeft - (track.clientWidth - slide.offsetWidth) / 2);
735
+ if (Math.abs(track.scrollLeft - targetLeft) < 1) {
736
+ pendingTarget = null;
737
+ return;
738
+ }
739
+ const reduced = window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
740
+ track.scrollTo({ left: targetLeft, behavior: reduced ? "auto" : "smooth" });
741
+ };
742
+
743
+ const onSettle = () => {
744
+ const nearest = getNearestSlide();
745
+ pendingTarget = null;
746
+ current = nearest;
747
+ syncDots(nearest);
748
+ if (userInitiated && nearest !== settledIndex) {
749
+ statusEl.textContent = t("carousel.status", { n: nearest + 1, total: slides.length });
750
+ }
751
+ settledIndex = nearest;
752
+ userInitiated = false;
753
+ };
754
+
755
+ el.addEventListener("click", (e) => {
756
+ const base = pendingTarget !== null ? pendingTarget : current;
757
+ const prevBtn = e.target.closest("[data-carousel-prev]");
758
+ if (prevBtn) return goTo(base - 1, true);
759
+ const nextBtn = e.target.closest("[data-carousel-next]");
760
+ if (nextBtn) return goTo(base + 1, true);
761
+ const dotBtn = e.target.closest("[data-carousel-dot]");
762
+ if (dotBtn) return goTo(Number(dotBtn.getAttribute("data-carousel-dot")), true);
763
+ });
764
+
765
+ const supportsScrollEnd = "onscrollend" in window;
766
+ track.addEventListener("scroll", () => {
767
+ if (pendingTarget === null && !rafId) {
768
+ rafId = window.requestAnimationFrame(() => {
769
+ rafId = null;
770
+ const live = getNearestSlide();
771
+ if (live !== current) {
772
+ current = live;
773
+ syncDots(live);
774
+ }
775
+ });
776
+ }
777
+ if (!supportsScrollEnd) {
778
+ clearTimeout(debounceTimer);
779
+ debounceTimer = setTimeout(onSettle, 140);
780
+ }
781
+ }, { passive: true });
782
+ if (supportsScrollEnd) track.addEventListener("scrollend", onSettle);
783
+
784
+ const startAuto = () => {
785
+ if (autoplayMs > 0 && slides.length > 1) {
786
+ stopAuto();
787
+ timer = setInterval(() => {
788
+ const base = pendingTarget !== null ? pendingTarget : current;
789
+ goTo(base + 1, false);
790
+ }, autoplayMs);
791
+ }
792
+ };
793
+ const stopAuto = () => {
794
+ if (timer) {
795
+ clearInterval(timer);
796
+ timer = null;
797
+ }
798
+ };
799
+
800
+ el.addEventListener("mouseenter", stopAuto);
801
+ el.addEventListener("mouseleave", startAuto);
802
+ el.addEventListener("focusin", stopAuto);
803
+ el.addEventListener("focusout", (e) => {
804
+ if (!el.contains(e.relatedTarget)) startAuto();
805
+ });
806
+ syncDots(current);
807
+ startAuto();
808
+ }
809
+
810
+ /**
811
+ * Attaches light-dismiss fallback (`closedby="any"`) and animated `cancel` interception to native `<dialog data-modal>`.
812
+ * @param {HTMLDialogElement} dialog
813
+ */
814
+ function initModalDialog(dialog) {
815
+ if (!dialog || dialog.tagName !== "DIALOG" || dialog.dataset.bbDialogInit === "1") return;
816
+ dialog.dataset.bbDialogInit = "1";
817
+ if (!dialog.hasAttribute("closedby")) dialog.setAttribute("closedby", "any");
818
+
819
+ dialog.addEventListener("cancel", (e) => {
820
+ if (e.cancelable) {
821
+ e.preventDefault();
822
+ closeTopLayerDialog(dialog);
823
+ }
824
+ });
825
+
826
+ if (typeof HTMLDialogElement !== "undefined" && !("closedBy" in HTMLDialogElement.prototype)) {
827
+ const outside = (e) => {
828
+ const r = dialog.getBoundingClientRect();
829
+ return e.clientX < r.left || e.clientX > r.right || e.clientY < r.top || e.clientY > r.bottom;
830
+ };
831
+ let pressedOutside = false;
832
+ dialog.addEventListener("pointerdown", (e) => {
833
+ pressedOutside = outside(e);
834
+ });
835
+ dialog.addEventListener("pointerup", (e) => {
836
+ if (pressedOutside && outside(e) && dialog.getAttribute("closedby") === "any") {
837
+ closeTopLayerDialog(dialog);
838
+ }
839
+ });
840
+ }
841
+ }
842
+
843
+ /**
844
+ * Opens or closes a `[data-modal]` element by id using native `<dialog>` when available.
845
+ * @param {string} id
846
+ * @param {boolean} open
847
+ */
848
+ function setModal(id, open) {
849
+ const modal = document.querySelector('[data-modal="' + CSS.escape(id) + '"]') || document.getElementById(id);
850
+ if (!modal) return;
851
+ if (typeof modal.showModal === "function") {
852
+ initModalDialog(modal);
853
+ if (open && !modal.open) {
854
+ modal.removeAttribute("data-closing");
855
+ modal.showModal();
856
+ } else if (!open && modal.open) {
857
+ closeTopLayerDialog(modal);
858
+ }
859
+ return;
860
+ }
861
+ modal.classList.toggle("hidden", !open);
862
+ modal.setAttribute("aria-hidden", open ? "false" : "true");
863
+ }
864
+
865
+ /**
866
+ * Submits a `[data-form]` HTML form via fetch with CSRF header, loading state, and inline field errors.
867
+ * @param {HTMLFormElement} form
868
+ */
869
+ async function submitDeclarativeForm(form) {
870
+ const url = form.getAttribute("action") || window.location.pathname;
871
+ const method = (form.getAttribute("method") || "POST").toUpperCase();
872
+ const submits = Array.from(form.querySelectorAll('button[type="submit"], input[type="submit"]'));
873
+ submits.forEach((btn) => {
874
+ btn.disabled = true;
875
+ btn.setAttribute("aria-busy", "true");
876
+ });
877
+
878
+ form.querySelectorAll("[data-error-for]").forEach((el) => {
879
+ el.textContent = "";
880
+ el.classList.add("hidden");
881
+ });
882
+
883
+ try {
884
+ const formData = new FormData(form);
885
+ const hasFiles = Array.from(form.elements).some((el) => el.type === "file" && el.files && el.files.length > 0);
886
+ const headers = { Accept: "application/json" };
887
+ const csrf = getCsrfToken();
888
+ if (csrf) headers["X-CSRF-Token"] = csrf;
889
+
890
+ let body;
891
+ if (hasFiles || form.dataset.formMode === "multipart") {
892
+ body = formData;
893
+ } else {
894
+ headers["Content-Type"] = "application/json";
895
+ const obj = {};
896
+ formData.forEach((val, key) => {
897
+ if (key in obj) obj[key] = [].concat(obj[key], val);
898
+ else obj[key] = val;
899
+ });
900
+ body = JSON.stringify(obj);
901
+ }
902
+
903
+ const res = await fetch(url, {
904
+ method,
905
+ credentials: "same-origin",
906
+ headers,
907
+ body: method === "GET" || method === "HEAD" ? undefined : body,
908
+ });
909
+
910
+ const payload = (res.headers.get("Content-Type") || "").includes("application/json") ? await res.json() : {};
911
+ if (!res.ok || payload?.status === "error") {
912
+ const rawErrs = payload?.errors;
913
+ if (Array.isArray(rawErrs)) {
914
+ rawErrs.forEach((item) => {
915
+ if (!item?.field) return;
916
+ const target = form.querySelector('[data-error-for="' + CSS.escape(item.field) + '"]');
917
+ if (target) {
918
+ target.textContent = item.message || t("value.invalid");
919
+ target.classList.remove("hidden");
920
+ }
921
+ });
922
+ } else if (rawErrs && typeof rawErrs === "object") {
923
+ Object.entries(rawErrs).forEach(([field, msg]) => {
924
+ const target = form.querySelector('[data-error-for="' + CSS.escape(field) + '"]');
925
+ if (target) {
926
+ target.textContent = String(msg);
927
+ target.classList.remove("hidden");
928
+ }
929
+ });
930
+ }
931
+ const msg = Array.isArray(payload?.message) ? payload.message.join(", ") : payload?.message;
932
+ toast.error(t("form.validation"), msg || t("request.failed"));
933
+ return;
934
+ }
935
+
936
+ if (form.dataset.toastSuccess) {
937
+ toast.success(form.dataset.toastSuccess);
938
+ } else if (payload?.message) {
939
+ toast.success(payload.message);
940
+ }
941
+ if (form.dataset.reset !== "false") {
942
+ form.reset();
943
+ }
944
+ if (payload?.redirect) {
945
+ window.location.href = payload.redirect;
946
+ }
947
+ } catch (err) {
948
+ toast.error(t("request.failed"), err?.message || t("request.network"));
949
+ } finally {
950
+ submits.forEach((btn) => {
951
+ btn.disabled = false;
952
+ btn.removeAttribute("aria-busy");
953
+ });
954
+ }
955
+ }
956
+
957
+ /**
958
+ * Marks navigation links pointing at the active pathname with `aria-current="page"`.
959
+ */
960
+ function syncActiveNavLinks() {
961
+ const here = window.location.pathname.replace(/\/+$/, "") || "/";
962
+ document.querySelectorAll("header nav a.nav-link[href]").forEach((link) => {
963
+ try {
964
+ const url = new URL(link.getAttribute("href"), window.location.origin);
965
+ const linkPath = url.pathname.replace(/\/+$/, "") || "/";
966
+ if (url.origin === window.location.origin && linkPath === here && !link.hasAttribute("aria-current")) {
967
+ link.setAttribute("aria-current", "page");
968
+ }
969
+ } catch {}
970
+ });
971
+ }
972
+
973
+ /**
974
+ * Initializes carousels, native modal dialogs, active nav state, and initial theme sync.
975
+ */
976
+ function initAll() {
977
+ ensureStyles();
978
+ let stored = null;
979
+ try {
980
+ const s = window.localStorage.getItem(THEME_STORAGE_KEY);
981
+ if (s === "light" || s === "dark") stored = s;
982
+ } catch {}
983
+ applyDocumentTheme(getTheme(), stored);
984
+ syncActiveNavLinks();
985
+ document.querySelectorAll("[data-carousel]").forEach(initCarousel);
986
+ document.querySelectorAll("dialog[data-modal]").forEach(initModalDialog);
987
+ }
988
+
989
+ window.addEventListener("storage", (e) => {
990
+ if (e.key !== THEME_STORAGE_KEY) return;
991
+ const stored = e.newValue === "light" || e.newValue === "dark" ? e.newValue : null;
992
+ applyDocumentTheme(stored || getSystemTheme(), stored);
993
+ });
994
+
995
+ if (window.matchMedia) {
996
+ const mq = window.matchMedia("(prefers-color-scheme: dark)");
997
+ mq.addEventListener?.("change", () => {
998
+ let saved = null;
999
+ try {
1000
+ saved = window.localStorage.getItem(THEME_STORAGE_KEY);
1001
+ } catch {}
1002
+ if (saved !== "light" && saved !== "dark") {
1003
+ applyDocumentTheme(mq.matches ? "dark" : "light", null);
1004
+ }
1005
+ });
1006
+ }
1007
+
1008
+ document.addEventListener("click", (e) => {
1009
+ const confirmTarget = e.target.closest("[data-confirm]");
1010
+ if (confirmTarget && !window.confirm(confirmTarget.getAttribute("data-confirm"))) {
1011
+ e.preventDefault();
1012
+ e.stopImmediatePropagation();
1013
+ return;
1014
+ }
1015
+
1016
+ const themeBtn = e.target.closest("[data-theme-toggle]");
1017
+ if (themeBtn) {
1018
+ e.preventDefault();
1019
+ toggleTheme();
1020
+ return;
1021
+ }
1022
+
1023
+ const toastBtn = e.target.closest("[data-toast]");
1024
+ if (toastBtn) {
1025
+ toast({
1026
+ title: toastBtn.getAttribute("data-toast"),
1027
+ description: toastBtn.getAttribute("data-toast-description") || undefined,
1028
+ badge: toastBtn.getAttribute("data-toast-badge") || undefined,
1029
+ type: toastBtn.getAttribute("data-toast-type") || "info",
1030
+ duration: toastBtn.hasAttribute("data-toast-duration")
1031
+ ? Number(toastBtn.getAttribute("data-toast-duration"))
1032
+ : 4500,
1033
+ });
1034
+ return;
1035
+ }
1036
+
1037
+ const openModalBtn = e.target.closest("[data-modal-open]");
1038
+ if (openModalBtn) {
1039
+ e.preventDefault();
1040
+ setModal(openModalBtn.getAttribute("data-modal-open"), true);
1041
+ return;
1042
+ }
1043
+
1044
+ const closeModalBtn = e.target.closest("[data-modal-close]");
1045
+ if (closeModalBtn) {
1046
+ const targetId = closeModalBtn.getAttribute("data-modal-close");
1047
+ if (targetId) {
1048
+ setModal(targetId, false);
1049
+ } else {
1050
+ const parentModal = closeModalBtn.closest("[data-modal]");
1051
+ if (parentModal) setModal(parentModal.getAttribute("data-modal") || parentModal.id, false);
1052
+ }
1053
+ return;
1054
+ }
1055
+
1056
+ const modalBackdrop = e.target.matches("[data-modal]") && e.target.tagName !== "DIALOG" ? e.target : null;
1057
+ if (modalBackdrop) {
1058
+ setModal(modalBackdrop.getAttribute("data-modal") || modalBackdrop.id, false);
1059
+ return;
1060
+ }
1061
+
1062
+ const ddTrigger = e.target.closest("[data-dropdown-trigger]");
1063
+ if (ddTrigger) {
1064
+ e.preventDefault();
1065
+ const dd = ddTrigger.closest("[data-dropdown]");
1066
+ const menu = dd?.querySelector("[data-dropdown-menu]");
1067
+ if (menu) {
1068
+ const willOpen = menu.classList.contains("hidden");
1069
+ document.querySelectorAll("[data-dropdown-menu]").forEach((m) => m.classList.add("hidden"));
1070
+ menu.classList.toggle("hidden", !willOpen);
1071
+ ddTrigger.setAttribute("aria-expanded", willOpen ? "true" : "false");
1072
+ }
1073
+ return;
1074
+ }
1075
+
1076
+ if (!e.target.closest("[data-dropdown]")) {
1077
+ document.querySelectorAll("[data-dropdown-menu]").forEach((m) => m.classList.add("hidden"));
1078
+ }
1079
+
1080
+ const tabBtn = e.target.closest("[data-tab]");
1081
+ if (tabBtn) {
1082
+ const container = tabBtn.closest("[data-tabs]");
1083
+ const name = tabBtn.getAttribute("data-tab");
1084
+ if (container && name) {
1085
+ container.querySelectorAll("[data-tab]").forEach((btn) => {
1086
+ const active = btn.getAttribute("data-tab") === name;
1087
+ btn.setAttribute("data-active", active ? "true" : "false");
1088
+ btn.setAttribute("aria-selected", active ? "true" : "false");
1089
+ });
1090
+ container.querySelectorAll("[data-tab-panel]").forEach((panel) => {
1091
+ panel.classList.toggle("hidden", panel.getAttribute("data-tab-panel") !== name);
1092
+ });
1093
+ }
1094
+ return;
1095
+ }
1096
+
1097
+ const copyBtn = e.target.closest("[data-copy]");
1098
+ if (copyBtn && navigator.clipboard) {
1099
+ const text = copyBtn.getAttribute("data-copy");
1100
+ navigator.clipboard.writeText(text || "").then(() => {
1101
+ toast.success(copyBtn.getAttribute("data-copy-message") || t("copy.done"));
1102
+ });
1103
+ return;
1104
+ }
1105
+
1106
+ const pwBtn = e.target.closest("[data-password-toggle]");
1107
+ if (pwBtn) {
1108
+ const input = document.getElementById(pwBtn.getAttribute("data-password-toggle"));
1109
+ if (input) input.type = input.type === "password" ? "text" : "password";
1110
+ }
1111
+ });
1112
+
1113
+ document.addEventListener("keydown", (e) => {
1114
+ if (e.key === "Escape") {
1115
+ document.querySelectorAll("[data-dropdown-menu]").forEach((m) => m.classList.add("hidden"));
1116
+ document.querySelectorAll("[data-modal]").forEach((m) => {
1117
+ if (m.tagName !== "DIALOG" && !m.classList.contains("hidden")) {
1118
+ setModal(m.getAttribute("data-modal") || m.id, false);
1119
+ }
1120
+ });
1121
+ }
1122
+ });
1123
+
1124
+ document.addEventListener("submit", (e) => {
1125
+ const form = e.target.closest("form[data-form]");
1126
+ if (!form) return;
1127
+ e.preventDefault();
1128
+ submitDeclarativeForm(form);
1129
+ });
1130
+
1131
+ if (document.readyState === "loading") {
1132
+ document.addEventListener("DOMContentLoaded", initAll);
1133
+ } else {
1134
+ initAll();
1135
+ }
1136
+
1137
+ if (typeof MutationObserver !== "undefined" && document.documentElement) {
1138
+ let scanQueued = false;
1139
+ const observer = new MutationObserver(() => {
1140
+ if (scanQueued) return;
1141
+ scanQueued = true;
1142
+ window.requestAnimationFrame(() => {
1143
+ scanQueued = false;
1144
+ document.querySelectorAll("[data-carousel]:not([data-bb-carousel-init='1'])").forEach(initCarousel);
1145
+ document.querySelectorAll("dialog[data-modal]:not([data-bb-dialog-init='1'])").forEach(initModalDialog);
1146
+ });
1147
+ });
1148
+ observer.observe(document.documentElement, { childList: true, subtree: true });
1149
+ }
1150
+
1151
+ global.Bluebird = {
1152
+ __loaded: true,
1153
+ toast,
1154
+ i18n: { t, getLocale, setLocale, addMessages, messages: MESSAGES },
1155
+ csrf: getCsrfToken,
1156
+ theme: { get: getTheme, set: setTheme, toggle: toggleTheme },
1157
+ modal: { open: (id) => setModal(id, true), close: (id) => setModal(id, false) },
1158
+ init: initAll,
1159
+ };
1160
+ })(window);