@krak-stack/registry 0.1.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 (84) hide show
  1. package/README.md +29 -0
  2. package/dist/components/ui/alert-dialog.d.ts +18 -0
  3. package/dist/components/ui/app-brand.d.ts +26 -0
  4. package/dist/components/ui/app-brand.js +78 -0
  5. package/dist/components/ui/attachment.d.ts +23 -0
  6. package/dist/components/ui/badge.d.ts +7 -0
  7. package/dist/components/ui/button.d.ts +8 -0
  8. package/dist/components/ui/card.d.ts +11 -0
  9. package/dist/components/ui/checkbox.d.ts +3 -0
  10. package/dist/components/ui/code-block.d.ts +14 -0
  11. package/dist/components/ui/code-block.js +224 -0
  12. package/dist/components/ui/command.d.ts +18 -0
  13. package/dist/components/ui/copy-button.d.ts +18 -0
  14. package/dist/components/ui/copy-button.js +133 -0
  15. package/dist/components/ui/data-table.d.ts +264 -0
  16. package/dist/components/ui/data-table.js +3594 -0
  17. package/dist/components/ui/dialog.d.ts +13 -0
  18. package/dist/components/ui/dropdown-menu.d.ts +29 -0
  19. package/dist/components/ui/editing-locale-switcher.d.ts +7 -0
  20. package/dist/components/ui/editing-locale-switcher.js +626 -0
  21. package/dist/components/ui/effect-form.d.ts +137 -0
  22. package/dist/components/ui/effect-form.js +2330 -0
  23. package/dist/components/ui/field.d.ts +24 -0
  24. package/dist/components/ui/file-picker.d.ts +30 -0
  25. package/dist/components/ui/file-picker.js +811 -0
  26. package/dist/components/ui/form.d.ts +402 -0
  27. package/dist/components/ui/form.js +2245 -0
  28. package/dist/components/ui/google-map.d.ts +103 -0
  29. package/dist/components/ui/google-map.js +754 -0
  30. package/dist/components/ui/icon-input.d.ts +9 -0
  31. package/dist/components/ui/icon-input.js +971 -0
  32. package/dist/components/ui/input-group.d.ts +17 -0
  33. package/dist/components/ui/input.d.ts +3 -0
  34. package/dist/components/ui/label.d.ts +3 -0
  35. package/dist/components/ui/loading.d.ts +7 -0
  36. package/dist/components/ui/loading.js +467 -0
  37. package/dist/components/ui/locale-switcher.d.ts +7 -0
  38. package/dist/components/ui/locale-switcher.js +632 -0
  39. package/dist/components/ui/pagination.d.ts +43 -0
  40. package/dist/components/ui/pagination.js +787 -0
  41. package/dist/components/ui/popover.d.ts +9 -0
  42. package/dist/components/ui/scroll-area.d.ts +4 -0
  43. package/dist/components/ui/search-menu.d.ts +34 -0
  44. package/dist/components/ui/search-menu.js +839 -0
  45. package/dist/components/ui/select.d.ts +15 -0
  46. package/dist/components/ui/separator.d.ts +3 -0
  47. package/dist/components/ui/sheet.d.ts +14 -0
  48. package/dist/components/ui/sidebar-layout.d.ts +29 -0
  49. package/dist/components/ui/sidebar-layout.js +755 -0
  50. package/dist/components/ui/sidebar.d.ts +63 -0
  51. package/dist/components/ui/skeleton.d.ts +2 -0
  52. package/dist/components/ui/stats-card.d.ts +12 -0
  53. package/dist/components/ui/stats-card.js +125 -0
  54. package/dist/components/ui/table.d.ts +10 -0
  55. package/dist/components/ui/textarea.d.ts +3 -0
  56. package/dist/components/ui/theme-switcher.d.ts +29 -0
  57. package/dist/components/ui/theme-switcher.js +775 -0
  58. package/dist/components/ui/tooltip.d.ts +6 -0
  59. package/dist/components/ui/virtualized-combobox.d.ts +54 -0
  60. package/dist/components/ui/virtualized-combobox.js +821 -0
  61. package/dist/hooks/use-mobile.d.ts +1 -0
  62. package/dist/lib/query.d.ts +49 -0
  63. package/dist/lib/utils.d.ts +2 -0
  64. package/dist/paraglide/runtime.d.ts +978 -0
  65. package/dist/services/embedding.d.ts +2 -0
  66. package/dist/services/embedding.js +23 -0
  67. package/dist/services/notification/channels/index.d.ts +22 -0
  68. package/dist/services/notification/channels/index.js +11 -0
  69. package/dist/services/notification/channels/ses/index.d.ts +51 -0
  70. package/dist/services/notification/channels/ses/index.js +145 -0
  71. package/dist/services/notification/channels/ses/schema.d.ts +13 -0
  72. package/dist/services/notification/channels/ses/schema.js +35 -0
  73. package/dist/services/notification/index.d.ts +15 -0
  74. package/dist/services/notification/index.js +67 -0
  75. package/dist/services/notification/schema.d.ts +10 -0
  76. package/dist/services/notification/schema.js +30 -0
  77. package/dist/services/opentelemetry.d.ts +8 -0
  78. package/dist/services/opentelemetry.js +23 -0
  79. package/dist/services/s3/index.d.ts +62 -0
  80. package/dist/services/s3/index.js +208 -0
  81. package/dist/services/s3/schema.d.ts +18 -0
  82. package/dist/services/s3/schema.js +37 -0
  83. package/package.json +218 -0
  84. package/tailwind.css +1 -0
@@ -0,0 +1,754 @@
1
+ // ../../src/components/ui/google-map.tsx
2
+ import { Minus, Plus } from "lucide-react";
3
+ import { useEffect, useEffectEvent, useRef, useState } from "react";
4
+
5
+ // ../../src/lib/utils.ts
6
+ import { clsx } from "clsx";
7
+ import { twMerge } from "tailwind-merge";
8
+ function cn(...inputs) {
9
+ return twMerge(clsx(inputs));
10
+ }
11
+
12
+ // ../../src/paraglide/runtime.js
13
+ import"@inlang/paraglide-js/urlpattern-polyfill";
14
+ var baseLocale = "en";
15
+ var locales = ["en", "fr"];
16
+ var cookieName = "locale";
17
+ var cookieMaxAge = 34560000;
18
+ var cookieDomain = "";
19
+ var localStorageKey = "PARAGLIDE_LOCALE";
20
+ var strategy = [
21
+ "url",
22
+ "cookie",
23
+ "preferredLanguage",
24
+ "baseLocale"
25
+ ];
26
+ var routeStrategies = [
27
+ {
28
+ match: "/api/:path(.*)?",
29
+ exclude: true
30
+ }
31
+ ];
32
+ var urlPatterns = [
33
+ {
34
+ pattern: "/:path(.*)?",
35
+ localized: [
36
+ [
37
+ "en",
38
+ "/en/:path(.*)?"
39
+ ],
40
+ [
41
+ "fr",
42
+ "/fr/:path(.*)?"
43
+ ]
44
+ ]
45
+ }
46
+ ];
47
+ var cachedRouteStrategyUrl;
48
+ var cachedRouteStrategy;
49
+ function findMatchingRouteStrategy(url) {
50
+ if (routeStrategies.length === 0) {
51
+ return;
52
+ }
53
+ const urlString = typeof url === "string" ? url : url.href;
54
+ if (cachedRouteStrategyUrl === urlString) {
55
+ return cachedRouteStrategy;
56
+ }
57
+ const urlObject = new URL(urlString, "http://dummy.com");
58
+ let match;
59
+ for (const routeStrategy of routeStrategies) {
60
+ const pattern = new URLPattern(routeStrategy.match, urlObject.href);
61
+ if (pattern.exec(urlObject.href)) {
62
+ match = routeStrategy;
63
+ break;
64
+ }
65
+ }
66
+ cachedRouteStrategyUrl = urlString;
67
+ cachedRouteStrategy = match;
68
+ return match;
69
+ }
70
+ function getStrategyForUrl(url) {
71
+ const routeStrategy = findMatchingRouteStrategy(url);
72
+ if (routeStrategy && routeStrategy.exclude !== true && Array.isArray(routeStrategy.strategy)) {
73
+ return routeStrategy.strategy;
74
+ }
75
+ return strategy;
76
+ }
77
+ var serverAsyncLocalStorage = undefined;
78
+ var isServer = import.meta.env?.SSR ?? typeof window === "undefined";
79
+ var experimentalStaticLocale = undefined;
80
+ var TREE_SHAKE_COOKIE_STRATEGY_USED = true;
81
+ var TREE_SHAKE_URL_STRATEGY_USED = true;
82
+ var TREE_SHAKE_GLOBAL_VARIABLE_STRATEGY_USED = false;
83
+ var TREE_SHAKE_PREFERRED_LANGUAGE_STRATEGY_USED = true;
84
+ var TREE_SHAKE_DEFAULT_URL_PATTERN_USED = false;
85
+ var TREE_SHAKE_LOCAL_STORAGE_STRATEGY_USED = false;
86
+ globalThis.__paraglide = globalThis.__paraglide ?? {};
87
+ globalThis.__paraglide.ssr = globalThis.__paraglide.ssr ?? {};
88
+ var _locale;
89
+ var localeInitiallySet = false;
90
+ var getLocale = () => {
91
+ if (experimentalStaticLocale !== undefined) {
92
+ return experimentalStaticLocale;
93
+ }
94
+ if (serverAsyncLocalStorage) {
95
+ const locale = serverAsyncLocalStorage?.getStore()?.locale;
96
+ if (locale) {
97
+ return locale;
98
+ }
99
+ }
100
+ let strategyToUse = strategy;
101
+ if (!isServer && typeof window !== "undefined" && window.location?.href) {
102
+ strategyToUse = getStrategyForUrl(window.location.href);
103
+ }
104
+ const resolved = resolveLocaleWithStrategies(strategyToUse, typeof window !== "undefined" ? window.location?.href : undefined);
105
+ if (resolved) {
106
+ if (!localeInitiallySet) {
107
+ _locale = resolved;
108
+ localeInitiallySet = true;
109
+ setLocale(resolved, { reload: false });
110
+ }
111
+ return resolved;
112
+ }
113
+ throw new Error("No locale found. Read the docs https://paraglidejs.com/errors#no-locale-found");
114
+ };
115
+ function resolveLocaleWithStrategies(strategyToUse, urlForUrlStrategy) {
116
+ let locale;
117
+ for (const strat of strategyToUse) {
118
+ if (TREE_SHAKE_COOKIE_STRATEGY_USED && strat === "cookie") {
119
+ locale = extractLocaleFromCookie();
120
+ } else if (strat === "baseLocale") {
121
+ locale = baseLocale;
122
+ } else if (TREE_SHAKE_URL_STRATEGY_USED && strat === "url" && !isServer && typeof urlForUrlStrategy === "string") {
123
+ locale = extractLocaleFromUrl(urlForUrlStrategy);
124
+ } else if (TREE_SHAKE_GLOBAL_VARIABLE_STRATEGY_USED && strat === "globalVariable" && _locale !== undefined) {
125
+ locale = _locale;
126
+ } else if (TREE_SHAKE_PREFERRED_LANGUAGE_STRATEGY_USED && strat === "preferredLanguage" && !isServer) {
127
+ locale = extractLocaleFromNavigator();
128
+ } else if (TREE_SHAKE_LOCAL_STORAGE_STRATEGY_USED && strat === "localStorage" && !isServer) {
129
+ locale = localStorage.getItem(localStorageKey) ?? undefined;
130
+ } else if (isCustomStrategy(strat) && customClientStrategies.has(strat)) {
131
+ const handler = customClientStrategies.get(strat);
132
+ if (handler) {
133
+ const result = handler.getLocale();
134
+ if (result instanceof Promise) {
135
+ continue;
136
+ }
137
+ if (result !== undefined) {
138
+ return assertIsLocale(result);
139
+ }
140
+ }
141
+ }
142
+ const matchedLocale = toLocale(locale);
143
+ if (matchedLocale) {
144
+ return matchedLocale;
145
+ }
146
+ }
147
+ return;
148
+ }
149
+ var rtlLanguages = new Set([
150
+ "ar",
151
+ "dv",
152
+ "fa",
153
+ "he",
154
+ "ks",
155
+ "ku",
156
+ "ps",
157
+ "sd",
158
+ "ug",
159
+ "ur",
160
+ "yi"
161
+ ]);
162
+ var navigateOrReload = (newLocation) => {
163
+ if (newLocation) {
164
+ window.location.href = newLocation;
165
+ } else {
166
+ window.location.reload();
167
+ }
168
+ };
169
+ var setLocale = (newLocale, options) => {
170
+ const optionsWithDefaults = {
171
+ reload: true,
172
+ ...options
173
+ };
174
+ let currentLocale;
175
+ try {
176
+ currentLocale = getLocale();
177
+ } catch {}
178
+ const customSetLocalePromises = [];
179
+ let newLocation = undefined;
180
+ let strategyToUse = strategy;
181
+ if (!isServer && typeof window !== "undefined" && window.location?.href) {
182
+ strategyToUse = getStrategyForUrl(window.location.href);
183
+ }
184
+ for (const strat of strategyToUse) {
185
+ if (TREE_SHAKE_GLOBAL_VARIABLE_STRATEGY_USED && strat === "globalVariable") {
186
+ _locale = newLocale;
187
+ } else if (TREE_SHAKE_COOKIE_STRATEGY_USED && strat === "cookie") {
188
+ if (isServer || typeof document === "undefined" || typeof window === "undefined") {
189
+ continue;
190
+ }
191
+ const cookieString = `${cookieName}=${newLocale}; path=/; max-age=${cookieMaxAge}`;
192
+ document.cookie = cookieDomain ? `${cookieString}; domain=${cookieDomain}` : cookieString;
193
+ } else if (strat === "baseLocale") {
194
+ continue;
195
+ } else if (TREE_SHAKE_URL_STRATEGY_USED && strat === "url" && typeof window !== "undefined") {
196
+ newLocation = localizeUrl(window.location.href, {
197
+ locale: newLocale
198
+ }).href;
199
+ } else if (TREE_SHAKE_LOCAL_STORAGE_STRATEGY_USED && strat === "localStorage" && typeof window !== "undefined") {
200
+ localStorage.setItem(localStorageKey, newLocale);
201
+ } else if (isCustomStrategy(strat) && customClientStrategies.has(strat)) {
202
+ const handler = customClientStrategies.get(strat);
203
+ if (handler) {
204
+ let result = handler.setLocale(newLocale);
205
+ if (result instanceof Promise) {
206
+ result = result.catch((error) => {
207
+ throw new Error(`Custom strategy "${strat}" setLocale failed.`, {
208
+ cause: error
209
+ });
210
+ });
211
+ customSetLocalePromises.push(result);
212
+ }
213
+ }
214
+ }
215
+ }
216
+ const runReload = () => {
217
+ if (!isServer && optionsWithDefaults.reload && window.location && newLocale !== currentLocale) {
218
+ navigateOrReload(newLocation);
219
+ }
220
+ };
221
+ if (customSetLocalePromises.length) {
222
+ return Promise.all(customSetLocalePromises).then(() => {
223
+ runReload();
224
+ });
225
+ }
226
+ runReload();
227
+ return;
228
+ };
229
+ var getUrlOrigin = () => {
230
+ if (serverAsyncLocalStorage) {
231
+ return serverAsyncLocalStorage.getStore()?.origin ?? "http://fallback.com";
232
+ } else if (typeof window !== "undefined") {
233
+ return window.location.origin;
234
+ }
235
+ return "http://fallback.com";
236
+ };
237
+ function toLocale(value) {
238
+ if (typeof value !== "string") {
239
+ return;
240
+ }
241
+ const lowerValue = value.toLowerCase();
242
+ for (const locale of locales) {
243
+ if (locale.toLowerCase() === lowerValue) {
244
+ return locale;
245
+ }
246
+ }
247
+ return;
248
+ }
249
+ function assertIsLocale(input) {
250
+ const locale = toLocale(input);
251
+ if (locale)
252
+ return locale;
253
+ throw new Error(`Invalid locale: ${input}. Expected one of: ${locales.join(", ")}`);
254
+ }
255
+ function extractLocaleFromCookie() {
256
+ if (typeof document === "undefined" || !document.cookie) {
257
+ return;
258
+ }
259
+ const match = document.cookie.match(new RegExp(`(^| )${cookieName}=([^;]+)`));
260
+ const locale = match?.[2];
261
+ return toLocale(locale);
262
+ }
263
+ function extractLocaleFromNavigator() {
264
+ if (!navigator?.languages?.length) {
265
+ return;
266
+ }
267
+ const languages = navigator.languages.map((lang) => ({
268
+ fullTag: lang,
269
+ baseTag: lang.split("-")[0]
270
+ }));
271
+ for (const lang of languages) {
272
+ const fullLocale = toLocale(lang.fullTag);
273
+ if (fullLocale) {
274
+ return fullLocale;
275
+ }
276
+ const baseLocale2 = toLocale(lang.baseTag);
277
+ if (baseLocale2) {
278
+ return baseLocale2;
279
+ }
280
+ }
281
+ return;
282
+ }
283
+ var cachedUrl;
284
+ var cachedLocale;
285
+ function extractLocaleFromUrl(url) {
286
+ const urlString = typeof url === "string" ? url : url.href;
287
+ if (cachedUrl === urlString) {
288
+ return cachedLocale;
289
+ }
290
+ let result;
291
+ if (TREE_SHAKE_DEFAULT_URL_PATTERN_USED) {
292
+ result = defaultUrlPatternExtractLocale(url);
293
+ } else {
294
+ const urlObj = typeof url === "string" ? new URL(url) : url;
295
+ for (const element of urlPatterns) {
296
+ for (const [locale, localizedPattern] of element.localized) {
297
+ const match = new URLPattern(localizedPattern, urlObj.href).exec(urlObj.href);
298
+ if (match) {
299
+ result = locale;
300
+ break;
301
+ }
302
+ }
303
+ if (result)
304
+ break;
305
+ }
306
+ }
307
+ cachedUrl = urlString;
308
+ cachedLocale = result;
309
+ return result;
310
+ }
311
+ function defaultUrlPatternExtractLocale(url) {
312
+ const urlObj = new URL(url, "http://dummy.com");
313
+ const pathSegments = urlObj.pathname.split("/").filter(Boolean);
314
+ return toLocale(pathSegments[0]) || baseLocale;
315
+ }
316
+ function localizeUrl(url, options) {
317
+ const targetLocale = options?.locale ? assertIsLocale(options?.locale) : getLocale();
318
+ if (TREE_SHAKE_DEFAULT_URL_PATTERN_USED) {
319
+ return localizeUrlDefaultPattern(url, targetLocale);
320
+ }
321
+ const urlObj = typeof url === "string" ? new URL(url) : url;
322
+ for (const element of urlPatterns) {
323
+ for (const [, localizedPattern] of element.localized) {
324
+ const match = new URLPattern(localizedPattern, urlObj.href).exec(urlObj.href);
325
+ if (!match) {
326
+ continue;
327
+ }
328
+ const targetPattern = element.localized.find(([locale]) => locale === targetLocale)?.[1];
329
+ if (!targetPattern) {
330
+ continue;
331
+ }
332
+ const localizedUrl = fillPattern(targetPattern, aggregateGroups(match), urlObj.origin);
333
+ return fillMissingUrlParts(localizedUrl, match);
334
+ }
335
+ const unlocalizedMatch = new URLPattern(element.pattern, urlObj.href).exec(urlObj.href);
336
+ if (unlocalizedMatch) {
337
+ const targetPattern = element.localized.find(([locale]) => locale === targetLocale)?.[1];
338
+ if (targetPattern) {
339
+ const localizedUrl = fillPattern(targetPattern, aggregateGroups(unlocalizedMatch), urlObj.origin);
340
+ return fillMissingUrlParts(localizedUrl, unlocalizedMatch);
341
+ }
342
+ }
343
+ }
344
+ return urlObj;
345
+ }
346
+ function localizeUrlDefaultPattern(url, locale) {
347
+ const urlObj = typeof url === "string" ? new URL(url, getUrlOrigin()) : new URL(url);
348
+ const currentLocale = extractLocaleFromUrl(urlObj);
349
+ if (currentLocale === locale) {
350
+ return urlObj;
351
+ }
352
+ const pathSegments = urlObj.pathname.split("/").filter(Boolean);
353
+ if (pathSegments.length > 0 && toLocale(pathSegments[0])) {
354
+ pathSegments.shift();
355
+ }
356
+ if (locale === baseLocale) {
357
+ urlObj.pathname = "/" + pathSegments.join("/");
358
+ } else {
359
+ urlObj.pathname = "/" + locale + "/" + pathSegments.join("/");
360
+ }
361
+ return urlObj;
362
+ }
363
+ function fillMissingUrlParts(url, match) {
364
+ if (match.protocol.groups["0"]) {
365
+ url.protocol = match.protocol.groups["0"] ?? "";
366
+ }
367
+ if (match.hostname.groups["0"]) {
368
+ url.hostname = match.hostname.groups["0"] ?? "";
369
+ }
370
+ if (match.username.groups["0"]) {
371
+ url.username = match.username.groups["0"] ?? "";
372
+ }
373
+ if (match.password.groups["0"]) {
374
+ url.password = match.password.groups["0"] ?? "";
375
+ }
376
+ if (match.port.groups["0"]) {
377
+ url.port = match.port.groups["0"] ?? "";
378
+ }
379
+ if (match.pathname.groups["0"]) {
380
+ url.pathname = match.pathname.groups["0"] ?? "";
381
+ }
382
+ if (match.search.groups["0"]) {
383
+ url.search = match.search.groups["0"] ?? "";
384
+ }
385
+ if (match.hash.groups["0"]) {
386
+ url.hash = match.hash.groups["0"] ?? "";
387
+ }
388
+ return url;
389
+ }
390
+ function fillPattern(pattern, values, origin) {
391
+ let processedPattern = pattern.replace(/(https?:\/\/[^:/]+):(\d+)(\/|$)/g, (_, protocol, port, slash) => {
392
+ return `${protocol}#PORT-${port}#${slash}`;
393
+ });
394
+ let processedGroupDelimiters = processedPattern.replace(/\{([^{}]*)\}([?+*]?)/g, (_, content, modifier) => {
395
+ if (modifier === "?") {
396
+ return content;
397
+ }
398
+ return content;
399
+ });
400
+ let filled = processedGroupDelimiters.replace(/(\/?):([a-zA-Z0-9_]+)(\([^)]*\))?([?+*]?)/g, (_, slash, name, __, modifier) => {
401
+ const value = values[name];
402
+ if (value === null) {
403
+ return "";
404
+ }
405
+ if (modifier === "?") {
406
+ return value !== undefined ? `${slash}${value}` : "";
407
+ }
408
+ if (modifier === "+" || modifier === "*") {
409
+ if (value === undefined && modifier === "+") {
410
+ throw new Error(`Missing value for "${name}" (one or more required)`);
411
+ }
412
+ return value ? `${slash}${value}` : "";
413
+ }
414
+ if (value === undefined) {
415
+ throw new Error(`Missing value for "${name}"`);
416
+ }
417
+ return `${slash}${value}`;
418
+ });
419
+ filled = filled.replace(/#PORT-(\d+)#/g, ":$1");
420
+ return new URL(filled, origin);
421
+ }
422
+ function aggregateGroups(match) {
423
+ return {
424
+ ...match.hash.groups,
425
+ ...match.hostname.groups,
426
+ ...match.password.groups,
427
+ ...match.pathname.groups,
428
+ ...match.port.groups,
429
+ ...match.protocol.groups,
430
+ ...match.search.groups,
431
+ ...match.username.groups
432
+ };
433
+ }
434
+ var customServerStrategies = new Map;
435
+ var customClientStrategies = new Map;
436
+ function isCustomStrategy(strategy2) {
437
+ return typeof strategy2 === "string" && /^custom-[A-Za-z0-9_-]+$/.test(strategy2);
438
+ }
439
+
440
+ // ../../src/components/ui/google-map.tsx
441
+ import { jsxDEV } from "react/jsx-dev-runtime";
442
+ var googleMapsScriptId = "krak-stack-google-maps-script";
443
+ var googleMapsCallbackName = "__krakStackGoogleMapsInit";
444
+ var googleMapsPromise;
445
+ var defaultMessages = {
446
+ en: {
447
+ mapLabel: "Google map",
448
+ loading: "Loading map...",
449
+ missingKeyTitle: "Map unavailable",
450
+ missingKeyBody: "Provide a Google Maps API key to display the map.",
451
+ errorTitle: "Map unavailable",
452
+ errorBody: "Google Maps could not be loaded. Try again later.",
453
+ zoomIn: "Zoom in",
454
+ zoomOut: "Zoom out"
455
+ },
456
+ fr: {
457
+ mapLabel: "Carte Google",
458
+ loading: "Chargement de la carte...",
459
+ missingKeyTitle: "Carte indisponible",
460
+ missingKeyBody: "Fournissez une clé d’API Google Maps pour afficher la carte.",
461
+ errorTitle: "Carte indisponible",
462
+ errorBody: "Impossible de charger Google Maps. Réessayez plus tard.",
463
+ zoomIn: "Zoom avant",
464
+ zoomOut: "Zoom arrière"
465
+ }
466
+ };
467
+ var googleMapMessages = (overrides) => ({
468
+ ...getLocale().startsWith("fr") ? defaultMessages.fr : defaultMessages.en,
469
+ ...overrides
470
+ });
471
+ var isGoogleMapsReady = (api) => Boolean(api?.maps.Map && api.maps.Marker && api.maps.Circle && api.maps.event);
472
+ var loadGoogleMaps = (apiKey) => {
473
+ if (typeof window === "undefined" || typeof document === "undefined") {
474
+ return Promise.reject(new Error("Google Maps requires a browser."));
475
+ }
476
+ if (isGoogleMapsReady(window.google))
477
+ return Promise.resolve(window.google);
478
+ if (googleMapsPromise)
479
+ return googleMapsPromise;
480
+ googleMapsPromise = new Promise((resolve, reject) => {
481
+ const resolveApi = () => {
482
+ if (isGoogleMapsReady(window.google))
483
+ resolve(window.google);
484
+ else
485
+ reject(new Error("Google Maps failed to initialize."));
486
+ };
487
+ const rejectLoad = () => reject(new Error("Google Maps failed to load."));
488
+ window[googleMapsCallbackName] = resolveApi;
489
+ const existingScript = document.getElementById(googleMapsScriptId);
490
+ if (existingScript) {
491
+ existingScript.addEventListener("error", rejectLoad, { once: true });
492
+ existingScript.addEventListener("load", resolveApi, { once: true });
493
+ return;
494
+ }
495
+ const script = document.createElement("script");
496
+ script.id = googleMapsScriptId;
497
+ script.async = true;
498
+ script.src = `https://maps.googleapis.com/maps/api/js?key=${encodeURIComponent(apiKey)}&loading=async&callback=${googleMapsCallbackName}`;
499
+ script.addEventListener("error", rejectLoad, { once: true });
500
+ document.head.append(script);
501
+ }).catch((error) => {
502
+ googleMapsPromise = undefined;
503
+ window[googleMapsCallbackName] = undefined;
504
+ document.getElementById(googleMapsScriptId)?.remove();
505
+ throw error;
506
+ });
507
+ return googleMapsPromise;
508
+ };
509
+ var clampZoom = (zoom, minZoom, maxZoom) => Math.min(maxZoom, Math.max(minZoom, zoom));
510
+ var mapOptions = (center, zoom, interactive, minZoom, maxZoom) => ({
511
+ center,
512
+ zoom: clampZoom(zoom, minZoom, maxZoom),
513
+ clickableIcons: interactive,
514
+ disableDefaultUI: true,
515
+ draggable: interactive,
516
+ fullscreenControl: false,
517
+ gestureHandling: interactive ? "auto" : "none",
518
+ keyboardShortcuts: interactive,
519
+ mapTypeControl: false,
520
+ maxZoom,
521
+ minZoom,
522
+ scrollwheel: interactive,
523
+ streetViewControl: false,
524
+ zoomControl: false
525
+ });
526
+ function GoogleMap({
527
+ apiKey,
528
+ center,
529
+ zoom,
530
+ marker,
531
+ radius,
532
+ interactive = true,
533
+ zoomControls = true,
534
+ minZoom = 3,
535
+ maxZoom = 20,
536
+ className,
537
+ messages: messageOverrides
538
+ }) {
539
+ const mapElementRef = useRef(null);
540
+ const apiRef = useRef(null);
541
+ const mapRef = useRef(null);
542
+ const markerRef = useRef(null);
543
+ const circleRef = useRef(null);
544
+ const zoomListenerRef = useRef(null);
545
+ const normalizedApiKey = apiKey.trim();
546
+ const normalizedMinZoom = Math.min(minZoom, maxZoom);
547
+ const normalizedMaxZoom = Math.max(minZoom, maxZoom);
548
+ const initialZoom = clampZoom(zoom, normalizedMinZoom, normalizedMaxZoom);
549
+ const [loadState, setLoadState] = useState(normalizedApiKey ? "loading" : "missing-key");
550
+ const [currentZoom, setCurrentZoom] = useState(initialZoom);
551
+ const labels = googleMapMessages(messageOverrides);
552
+ const markerEnabled = marker === true || typeof marker === "object";
553
+ const markerIcon = typeof marker === "object" ? marker.icon : undefined;
554
+ const centerLat = center.lat;
555
+ const centerLng = center.lng;
556
+ const radiusMeters = radius?.radiusMeters;
557
+ const radiusFillColor = radius?.fillColor;
558
+ const radiusFillOpacity = radius?.fillOpacity;
559
+ const radiusStrokeColor = radius?.strokeColor;
560
+ const radiusStrokeOpacity = radius?.strokeOpacity;
561
+ const radiusStrokeWeight = radius?.strokeWeight;
562
+ const initializeMap = useEffectEvent((api, element) => {
563
+ const map = new api.maps.Map(element, mapOptions(center, zoom, interactive, normalizedMinZoom, normalizedMaxZoom));
564
+ apiRef.current = api;
565
+ mapRef.current = map;
566
+ zoomListenerRef.current = api.maps.event.addListener(map, "zoom_changed", () => setCurrentZoom(map.getZoom() ?? zoom));
567
+ setCurrentZoom(clampZoom(zoom, normalizedMinZoom, normalizedMaxZoom));
568
+ setLoadState("ready");
569
+ });
570
+ useEffect(() => {
571
+ if (!normalizedApiKey) {
572
+ setLoadState("missing-key");
573
+ return;
574
+ }
575
+ const element = mapElementRef.current;
576
+ if (!element)
577
+ return;
578
+ let mounted = true;
579
+ setLoadState("loading");
580
+ loadGoogleMaps(normalizedApiKey).then((api) => {
581
+ if (!mounted)
582
+ return;
583
+ try {
584
+ initializeMap(api, element);
585
+ } catch {
586
+ setLoadState("error");
587
+ }
588
+ }).catch(() => {
589
+ if (mounted)
590
+ setLoadState("error");
591
+ });
592
+ return () => {
593
+ mounted = false;
594
+ zoomListenerRef.current?.remove();
595
+ markerRef.current?.setMap(null);
596
+ circleRef.current?.setMap(null);
597
+ if (mapRef.current) {
598
+ apiRef.current?.maps.event.clearInstanceListeners(mapRef.current);
599
+ }
600
+ markerRef.current = null;
601
+ circleRef.current = null;
602
+ zoomListenerRef.current = null;
603
+ mapRef.current = null;
604
+ apiRef.current = null;
605
+ element.replaceChildren();
606
+ };
607
+ }, [normalizedApiKey]);
608
+ useEffect(() => {
609
+ const api = apiRef.current;
610
+ const map = mapRef.current;
611
+ if (loadState !== "ready" || !api || !map)
612
+ return;
613
+ try {
614
+ const nextCenter = { lat: centerLat, lng: centerLng };
615
+ const nextZoom = clampZoom(zoom, normalizedMinZoom, normalizedMaxZoom);
616
+ map.setCenter(nextCenter);
617
+ map.setZoom(nextZoom);
618
+ map.setOptions(mapOptions(nextCenter, nextZoom, interactive, normalizedMinZoom, normalizedMaxZoom));
619
+ setCurrentZoom(nextZoom);
620
+ if (markerEnabled) {
621
+ if (markerRef.current) {
622
+ markerRef.current.setMap(map);
623
+ markerRef.current.setPosition(nextCenter);
624
+ markerRef.current.setIcon(markerIcon);
625
+ } else {
626
+ markerRef.current = new api.maps.Marker({
627
+ icon: markerIcon,
628
+ map,
629
+ position: nextCenter
630
+ });
631
+ }
632
+ } else {
633
+ markerRef.current?.setMap(null);
634
+ markerRef.current = null;
635
+ }
636
+ if (radiusMeters !== undefined) {
637
+ const style = {
638
+ fillColor: radiusFillColor ?? "#18181b",
639
+ fillOpacity: radiusFillOpacity ?? 0.12,
640
+ strokeColor: radiusStrokeColor ?? "#18181b",
641
+ strokeOpacity: radiusStrokeOpacity ?? 0.7,
642
+ strokeWeight: radiusStrokeWeight ?? 2
643
+ };
644
+ if (circleRef.current) {
645
+ circleRef.current.setMap(map);
646
+ circleRef.current.setCenter(nextCenter);
647
+ circleRef.current.setRadius(radiusMeters);
648
+ circleRef.current.setOptions(style);
649
+ } else {
650
+ circleRef.current = new api.maps.Circle({
651
+ ...style,
652
+ center: nextCenter,
653
+ clickable: false,
654
+ map,
655
+ radius: radiusMeters
656
+ });
657
+ }
658
+ } else {
659
+ circleRef.current?.setMap(null);
660
+ circleRef.current = null;
661
+ }
662
+ } catch {
663
+ setLoadState("error");
664
+ }
665
+ }, [
666
+ centerLat,
667
+ centerLng,
668
+ interactive,
669
+ loadState,
670
+ markerEnabled,
671
+ markerIcon,
672
+ normalizedMaxZoom,
673
+ normalizedMinZoom,
674
+ radiusFillColor,
675
+ radiusFillOpacity,
676
+ radiusMeters,
677
+ radiusStrokeColor,
678
+ radiusStrokeOpacity,
679
+ radiusStrokeWeight,
680
+ zoom
681
+ ]);
682
+ const changeZoom = (delta) => {
683
+ const map = mapRef.current;
684
+ if (!map)
685
+ return;
686
+ const nextZoom = clampZoom((map.getZoom() ?? currentZoom) + delta, normalizedMinZoom, normalizedMaxZoom);
687
+ map.setZoom(nextZoom);
688
+ setCurrentZoom(nextZoom);
689
+ };
690
+ return /* @__PURE__ */ jsxDEV("div", {
691
+ className: cn("bg-muted relative min-h-64 overflow-hidden rounded-lg border", className),
692
+ children: [
693
+ /* @__PURE__ */ jsxDEV("div", {
694
+ ref: mapElementRef,
695
+ className: "h-full min-h-[inherit] w-full",
696
+ role: "region",
697
+ "aria-label": labels.mapLabel
698
+ }, undefined, false, undefined, this),
699
+ loadState === "ready" && zoomControls ? /* @__PURE__ */ jsxDEV("div", {
700
+ className: "bg-background/95 absolute right-4 bottom-4 z-10 overflow-hidden rounded-md border shadow-sm backdrop-blur",
701
+ children: [
702
+ /* @__PURE__ */ jsxDEV("button", {
703
+ type: "button",
704
+ className: "text-muted-foreground hover:bg-accent hover:text-accent-foreground flex size-9 items-center justify-center transition-colors disabled:pointer-events-none disabled:opacity-50",
705
+ disabled: currentZoom >= normalizedMaxZoom,
706
+ onClick: () => changeZoom(1),
707
+ "aria-label": labels.zoomIn,
708
+ children: /* @__PURE__ */ jsxDEV(Plus, {
709
+ className: "size-4"
710
+ }, undefined, false, undefined, this)
711
+ }, undefined, false, undefined, this),
712
+ /* @__PURE__ */ jsxDEV("div", {
713
+ className: "bg-border h-px"
714
+ }, undefined, false, undefined, this),
715
+ /* @__PURE__ */ jsxDEV("button", {
716
+ type: "button",
717
+ className: "text-muted-foreground hover:bg-accent hover:text-accent-foreground flex size-9 items-center justify-center transition-colors disabled:pointer-events-none disabled:opacity-50",
718
+ disabled: currentZoom <= normalizedMinZoom,
719
+ onClick: () => changeZoom(-1),
720
+ "aria-label": labels.zoomOut,
721
+ children: /* @__PURE__ */ jsxDEV(Minus, {
722
+ className: "size-4"
723
+ }, undefined, false, undefined, this)
724
+ }, undefined, false, undefined, this)
725
+ ]
726
+ }, undefined, true, undefined, this) : null,
727
+ loadState === "loading" ? /* @__PURE__ */ jsxDEV("div", {
728
+ className: "bg-background/75 text-muted-foreground absolute inset-0 grid place-items-center text-sm font-medium backdrop-blur-sm",
729
+ role: "status",
730
+ children: labels.loading
731
+ }, undefined, false, undefined, this) : null,
732
+ loadState === "missing-key" || loadState === "error" ? /* @__PURE__ */ jsxDEV("div", {
733
+ className: "bg-background/85 absolute inset-0 grid place-items-center p-6 text-center backdrop-blur-sm",
734
+ children: /* @__PURE__ */ jsxDEV("div", {
735
+ className: "bg-card text-card-foreground max-w-sm rounded-lg border p-5 shadow-sm",
736
+ role: "alert",
737
+ children: [
738
+ /* @__PURE__ */ jsxDEV("p", {
739
+ className: "text-sm font-semibold",
740
+ children: loadState === "missing-key" ? labels.missingKeyTitle : labels.errorTitle
741
+ }, undefined, false, undefined, this),
742
+ /* @__PURE__ */ jsxDEV("p", {
743
+ className: "text-muted-foreground mt-2 text-xs",
744
+ children: loadState === "missing-key" ? labels.missingKeyBody : labels.errorBody
745
+ }, undefined, false, undefined, this)
746
+ ]
747
+ }, undefined, true, undefined, this)
748
+ }, undefined, false, undefined, this) : null
749
+ ]
750
+ }, undefined, true, undefined, this);
751
+ }
752
+ export {
753
+ GoogleMap
754
+ };