@myelophone/nuxt 0.18.2
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.
- package/.devcontainer/Dockerfile +7 -0
- package/.devcontainer/devcontainer.json +21 -0
- package/.editorconfig +43 -0
- package/.github/workflows/package.yml +73 -0
- package/.nuxtignore +6 -0
- package/.releaserc.js +132 -0
- package/.yarn/releases/yarn-4.18.0.cjs +1000 -0
- package/.yarnrc.yml +8 -0
- package/CHANGELOG.md +141 -0
- package/LICENSE +77 -0
- package/README.md +3004 -0
- package/app/app.vue +455 -0
- package/app/assets/css/animation.css +81 -0
- package/app/assets/css/backgrounds.css +57 -0
- package/app/assets/css/base.css +182 -0
- package/app/assets/css/index.css +9 -0
- package/app/assets/css/links.css +12 -0
- package/app/assets/css/multimedia.css +102 -0
- package/app/assets/css/preloader.css +68 -0
- package/app/assets/css/print.css +40 -0
- package/app/assets/css/tailwind.css +20 -0
- package/app/assets/css/theme.css +29 -0
- package/app/components/consent/GoogleMap.vue +59 -0
- package/app/components/consent/Youtube.vue +27 -0
- package/app/components/cookie/Banner.vue +70 -0
- package/app/components/cookie/ConsentWrapper.vue +71 -0
- package/app/components/cookie/PrivacyPolicy.vue +179 -0
- package/app/components/cookie/SettingsModal.vue +387 -0
- package/app/components/grid/Col.vue +262 -0
- package/app/components/grid/Container.vue +236 -0
- package/app/components/grid/Row.vue +248 -0
- package/app/components/grid/Stack.vue +233 -0
- package/app/components/myelophone/Copyright.vue +5 -0
- package/app/components/myelophone/Welcome.vue +107 -0
- package/app/components/page/FullscreenPreloader.vue +177 -0
- package/app/components/page/Preloader.vue +18 -0
- package/app/components/page/ReadyLocalized.vue +19 -0
- package/app/components/ready/.gitkeep +0 -0
- package/app/components/safe/Email.vue +52 -0
- package/app/components/safe/ImgWithLoader.vue +180 -0
- package/app/components/safe/NuxtImg.vue +25 -0
- package/app/components/safe/NuxtPicture.vue +29 -0
- package/app/components/section/.gitkeep +0 -0
- package/app/components/seo/BrandInfo.vue +76 -0
- package/app/components/seo/ContentNoIndex.vue +35 -0
- package/app/components/seo/NoIndex.vue +22 -0
- package/app/components/seo/OrgInfo.vue +130 -0
- package/app/components/seo/ProfileInfo.vue +137 -0
- package/app/components/ui/Accordion.vue +163 -0
- package/app/components/ui/Alert.vue +179 -0
- package/app/components/ui/Avatar.vue +88 -0
- package/app/components/ui/Badge.vue +150 -0
- package/app/components/ui/Banner.vue +133 -0
- package/app/components/ui/Button.vue +175 -0
- package/app/components/ui/Card.vue +66 -0
- package/app/components/ui/Checkbox.vue +134 -0
- package/app/components/ui/Chip.vue +136 -0
- package/app/components/ui/CommandPalette.vue +434 -0
- package/app/components/ui/Console.vue +583 -0
- package/app/components/ui/CursorCreative.vue +148 -0
- package/app/components/ui/FeatureAccordion.vue +165 -0
- package/app/components/ui/FileUpload.vue +705 -0
- package/app/components/ui/GeoDependent.vue +72 -0
- package/app/components/ui/Heading.vue +51 -0
- package/app/components/ui/Icon.vue +42 -0
- package/app/components/ui/Icon8.vue +39 -0
- package/app/components/ui/Input.vue +88 -0
- package/app/components/ui/LangLink.vue +34 -0
- package/app/components/ui/LangVisible.vue +33 -0
- package/app/components/ui/LanguageSelect.vue +202 -0
- package/app/components/ui/LightBox.vue +155 -0
- package/app/components/ui/LocalTime.vue +170 -0
- package/app/components/ui/Modal.vue +161 -0
- package/app/components/ui/Popup.vue +200 -0
- package/app/components/ui/PostContent.server.vue +23 -0
- package/app/components/ui/ProtectedEmail.vue +52 -0
- package/app/components/ui/RelativeTime.vue +141 -0
- package/app/components/ui/ScheduledContent.vue +150 -0
- package/app/components/ui/ScrollToTop.client.vue +48 -0
- package/app/components/ui/SegmentedControl.vue +148 -0
- package/app/components/ui/SiteSearch.vue +1191 -0
- package/app/components/ui/Skeleton.vue +91 -0
- package/app/components/ui/SmartContrast.vue +74 -0
- package/app/components/ui/SnapContainer.vue +222 -0
- package/app/components/ui/SnapSection.vue +294 -0
- package/app/components/ui/SonnerStyle.vue +7 -0
- package/app/components/ui/SplitSection.vue +99 -0
- package/app/components/ui/Steps.vue +858 -0
- package/app/components/ui/StickyWrapper.vue +46 -0
- package/app/components/ui/Table.vue +251 -0
- package/app/components/ui/Tabs.vue +451 -0
- package/app/components/ui/TextColumn.vue +36 -0
- package/app/components/ui/Textarea.vue +251 -0
- package/app/components/ui/Toggler.vue +40 -0
- package/app/components/ui/Tooltip.vue +524 -0
- package/app/components/ui/TruncateText.vue +105 -0
- package/app/components/ui/ViewportSpacer.vue +72 -0
- package/app/components/view/AnimatedCounter.vue +121 -0
- package/app/components/view/AnnouncementBar.vue +104 -0
- package/app/components/view/AvatarGroup.vue +104 -0
- package/app/components/view/Breadcrumbs.vue +97 -0
- package/app/components/view/ContentWithToc.vue +152 -0
- package/app/components/view/Copyright.vue +68 -0
- package/app/components/view/CountdownTimer.vue +184 -0
- package/app/components/view/CreativeCTA.vue +143 -0
- package/app/components/view/CurrencySelect.vue +254 -0
- package/app/components/view/FeatureBoxGrid.vue +142 -0
- package/app/components/view/HorizontalMenu.vue +97 -0
- package/app/components/view/ImageCompare.vue +141 -0
- package/app/components/view/ImgSlider.vue +333 -0
- package/app/components/view/InfiniteMarquee.vue +147 -0
- package/app/components/view/InfoBar.vue +86 -0
- package/app/components/view/LogoGrid.vue +106 -0
- package/app/components/view/LogoSlider.vue +83 -0
- package/app/components/view/NotFound.vue +81 -0
- package/app/components/view/PartialBackground.vue +313 -0
- package/app/components/view/QuoteBig.vue +111 -0
- package/app/components/view/ResponsiveMenu.vue +219 -0
- package/app/components/view/ReviewsSlider.vue +230 -0
- package/app/components/view/SocialBar.vue +78 -0
- package/app/components/view/StickyHeadingContent.vue +158 -0
- package/app/components/view/TallyForm.vue +295 -0
- package/app/components/view/WarningOutdated.vue +113 -0
- package/app/composables/useApi.ts +88 -0
- package/app/composables/useAppSeo.ts +78 -0
- package/app/composables/useBreadcrumbs.ts +106 -0
- package/app/composables/useChangeUrl.ts +73 -0
- package/app/composables/useCommand.ts +28 -0
- package/app/composables/useCookieControl.ts +111 -0
- package/app/composables/useCookieModal.ts +9 -0
- package/app/composables/useDevice.ts +109 -0
- package/app/composables/useGeoFetch.ts +139 -0
- package/app/composables/useLoadScript.ts +36 -0
- package/app/composables/useModalState.ts +37 -0
- package/app/composables/useMultiLang.ts +278 -0
- package/app/composables/useNetwork.ts +49 -0
- package/app/composables/useNuxtVersion.ts +5 -0
- package/app/composables/usePiniaStore.ts +5 -0
- package/app/composables/usePopupControl.ts +57 -0
- package/app/composables/useQuery.ts +307 -0
- package/app/composables/useReadyPage.ts +182 -0
- package/app/composables/useSafeList.ts +90 -0
- package/app/composables/useScriptLoader.ts +221 -0
- package/app/composables/useSiteSearch.ts +32 -0
- package/app/composables/useSnapScroll.ts +24 -0
- package/app/composables/useStatic.ts +5 -0
- package/app/composables/useStorage.ts +252 -0
- package/app/composables/useStoreBroadcast.ts +146 -0
- package/app/composables/useThemeSync.ts +81 -0
- package/app/constants/layout.ts +109 -0
- package/app/constants/predefinedCookieScripts.ts +1222 -0
- package/app/constants/ui-events.ts +1 -0
- package/app/error.vue +169 -0
- package/app/layouts/default-blog.vue +5 -0
- package/app/layouts/default.vue +3 -0
- package/app/locales/en/commands.json +5 -0
- package/app/locales/en/cookies.json +182 -0
- package/app/locales/en/error.json +4 -0
- package/app/locales/en/interface.json +33 -0
- package/app/locales/en/myelophone.json +8 -0
- package/app/locales/en/outdated.json +5 -0
- package/app/locales/en/times.json +18 -0
- package/app/locales/pl/commands.json +5 -0
- package/app/locales/pl/cookies.json +182 -0
- package/app/locales/pl/error.json +4 -0
- package/app/locales/pl/interface.json +33 -0
- package/app/locales/pl/myelophone.json +8 -0
- package/app/locales/pl/outdated.json +5 -0
- package/app/locales/pl/times.json +18 -0
- package/app/locales/ru/commands.json +5 -0
- package/app/locales/ru/cookies.json +182 -0
- package/app/locales/ru/error.json +4 -0
- package/app/locales/ru/interface.json +33 -0
- package/app/locales/ru/myelophone.json +8 -0
- package/app/locales/ru/outdated.json +5 -0
- package/app/locales/ru/times.json +18 -0
- package/app/middleware/blog-layout.ts +28 -0
- package/app/middleware/i18n.global.ts +17 -0
- package/app/middleware/not-found-status.ts +11 -0
- package/app/modules/default-blog/index.ts +39 -0
- package/app/modules/default-blog/posts.ts +80 -0
- package/app/modules/default-sitemap/index.ts +116 -0
- package/app/modules/default-sitemap/runtime/sitemap.get.ts +42 -0
- package/app/modules/fullscreen-preloader/module.ts +43 -0
- package/app/modules/htaccess/.htaccess +38 -0
- package/app/modules/htaccess/index.ts +23 -0
- package/app/modules/i18n-shaker.mjs +221 -0
- package/app/modules/multi18n/module.ts +71 -0
- package/app/modules/myelophone-config/module.ts +241 -0
- package/app/pages/[...all].vue +9 -0
- package/app/pages/index.vue +3 -0
- package/app/pages/post/[...slug].vue +30 -0
- package/app/plugins/bfcache-refresh.client.ts +9 -0
- package/app/plugins/canonical.ts +30 -0
- package/app/plugins/csp-nonce.server.ts +41 -0
- package/app/plugins/multi18n.client.ts +21 -0
- package/app/plugins/multi18n.server.ts +15 -0
- package/app/plugins/nuxt-version.client.ts +4 -0
- package/app/plugins/restore.client.ts +21 -0
- package/app/plugins/reveal.ts +89 -0
- package/app/plugins/url-helper.client.ts +66 -0
- package/app/server/api/exchange-rates.get.ts +216 -0
- package/app/server/api/healthz.ts +1 -0
- package/app/server/api/logout.post.ts +6 -0
- package/app/server/middleware/normalize-url.ts +14 -0
- package/app/server/middleware/security-headers.ts +147 -0
- package/app/server/middleware/url-helper.ts +43 -0
- package/app/server/plugins/clean-html-spaces.ts +15 -0
- package/app/server/plugins/clean-styles.ts +94 -0
- package/app/server/plugins/compression.ts +122 -0
- package/app/server/plugins/css-preload.ts +26 -0
- package/app/server/plugins/early-hints.ts +31 -0
- package/app/server/plugins/force-noindex.ts +43 -0
- package/app/server/plugins/html-one-line.ts +17 -0
- package/app/server/plugins/inline-style.ts +7 -0
- package/app/server/routes/healthz.get.ts +1 -0
- package/app/server/tsconfig.json +3 -0
- package/app/stores/cart.ts +945 -0
- package/app/stores/commands.ts +43 -0
- package/app/stores/device.ts +156 -0
- package/app/stores/querySync.ts +5 -0
- package/app/stores/settings.ts +145 -0
- package/app/stores/user.ts +607 -0
- package/app/types/cookie.ts +89 -0
- package/app/types/myelophone.d.ts +87 -0
- package/app/types/site-search.ts +110 -0
- package/app/utils/asyncRefresh.ts +4 -0
- package/app/utils/blog.server.ts +142 -0
- package/app/utils/jsonLd.ts +56 -0
- package/app/utils/myelophoneConfig.ts +4 -0
- package/app/utils/sortBy.ts +18 -0
- package/app/utils/transliterate.ts +75 -0
- package/app/utils/ytVideo.ts +37 -0
- package/app/workers/site-search.worker.ts +661 -0
- package/biome.json +94 -0
- package/commitlint.config.js +3 -0
- package/nuxt.config.ts +539 -0
- package/package.json +101 -0
- package/playground/content/.gitkeep +0 -0
- package/playground/locales/.gitkeep +0 -0
- package/playground/myelophone.dev.ts +45 -0
- package/playground/nuxt.config.ts +105 -0
- package/playground/package.json +5 -0
- package/playground/pages/.gitkeep +0 -0
- package/playground/tsconfig.json +3 -0
- package/playwright.config.ts +23 -0
- package/public/browsers/chrome.svg +77 -0
- package/public/browsers/edge.svg +98 -0
- package/public/browsers/firefox.svg +300 -0
- package/public/favicon.ico +0 -0
- package/public/myelophone_eng.png +0 -0
- package/public/myelophone_eng_white.png +0 -0
- package/spa-loading-template.html +72 -0
- package/tests/home.spec.ts +9 -0
- package/tests/utils.ts +23 -0
- package/tsconfig.json +16 -0
- package/vite/plugins/clean-css.ts +190 -0
- package/vite/plugins/postcss-add-viewportunits.ts +33 -0
- package/vite/plugins/postcss-viewport-fallback.ts +49 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface Command {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
type: 'command';
|
|
5
|
+
hint?: string;
|
|
6
|
+
keywords?: string[];
|
|
7
|
+
action: () => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface CommandInput {
|
|
11
|
+
id?: string;
|
|
12
|
+
name: string;
|
|
13
|
+
hint?: string;
|
|
14
|
+
keywords?: string[];
|
|
15
|
+
action: () => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const useCommandStore = defineStore('commands', () => {
|
|
19
|
+
const commands = ref<Command[]>([]);
|
|
20
|
+
|
|
21
|
+
const register = (input: CommandInput): string => {
|
|
22
|
+
const id = input.id || `cmd-${Math.random().toString(36).slice(2, 11)}`;
|
|
23
|
+
|
|
24
|
+
const newCommand: Command = {
|
|
25
|
+
...input,
|
|
26
|
+
id,
|
|
27
|
+
type: 'command',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
commands.value.unshift(newCommand);
|
|
31
|
+
return id;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const unregister = (id: string) => {
|
|
35
|
+
commands.value = commands.value.filter((c) => c.id !== id);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
commands,
|
|
40
|
+
register,
|
|
41
|
+
unregister,
|
|
42
|
+
};
|
|
43
|
+
});
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
type DeviceType = 'mobile' | 'tablet' | 'desktop';
|
|
2
|
+
type Orientation = 'portrait' | 'landscape' | '';
|
|
3
|
+
|
|
4
|
+
interface NetworkInfo {
|
|
5
|
+
effectiveType?: string;
|
|
6
|
+
saveData?: boolean;
|
|
7
|
+
addEventListener?: (event: 'change', listener: () => void) => void;
|
|
8
|
+
removeEventListener?: (event: 'change', listener: () => void) => void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function detectDevice(): DeviceType {
|
|
12
|
+
if (import.meta.server) return 'desktop';
|
|
13
|
+
|
|
14
|
+
const ua = navigator.userAgent.toLowerCase();
|
|
15
|
+
const width = window.innerWidth;
|
|
16
|
+
const height = window.innerHeight;
|
|
17
|
+
const dpr = window.devicePixelRatio || 1;
|
|
18
|
+
const isTouch = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
|
|
19
|
+
const orientation = width > height ? 'landscape' : 'portrait';
|
|
20
|
+
|
|
21
|
+
const isMobileUA = /mobi|iphone|ipod|android.*mobile|windows phone/i.test(
|
|
22
|
+
ua,
|
|
23
|
+
);
|
|
24
|
+
const isTabletUA = /ipad|tablet|(android(?!.*mobile))/i.test(ua);
|
|
25
|
+
const isDesktopUA = !isMobileUA && !isTabletUA;
|
|
26
|
+
|
|
27
|
+
if (isMobileUA) return 'mobile';
|
|
28
|
+
if (isTabletUA) return 'tablet';
|
|
29
|
+
|
|
30
|
+
if (isTouch) {
|
|
31
|
+
if (width < 768 || (width < 1024 && dpr > 1.5)) return 'mobile';
|
|
32
|
+
if (width >= 768 && width <= 1200) return 'tablet';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (orientation === 'portrait') {
|
|
36
|
+
if (width < 768) return 'mobile';
|
|
37
|
+
if (width >= 768 && width <= 1024) return 'tablet';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (isDesktopUA) return 'desktop';
|
|
41
|
+
|
|
42
|
+
return 'desktop';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function detectOS(userAgent: string): string {
|
|
46
|
+
if (/windows/i.test(userAgent)) return 'Windows';
|
|
47
|
+
if (/mac os/i.test(userAgent)) return 'macOS';
|
|
48
|
+
if (/android/i.test(userAgent)) return 'Android';
|
|
49
|
+
if (/ios|iphone|ipad|ipod/i.test(userAgent)) return 'iOS';
|
|
50
|
+
if (/linux/i.test(userAgent)) return 'Linux';
|
|
51
|
+
return 'Unknown';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function detectBrowser(userAgent: string): string {
|
|
55
|
+
const ua = userAgent.toLowerCase();
|
|
56
|
+
if (/edg/i.test(ua)) return 'Edge';
|
|
57
|
+
if (/opr|opera/i.test(ua)) return 'Opera';
|
|
58
|
+
if (/chrome|crios/i.test(ua) && !/edg/i.test(ua) && !/opr/i.test(ua))
|
|
59
|
+
return 'Chrome';
|
|
60
|
+
if (/safari/i.test(ua) && !/chrome|crios|opr|edg/i.test(ua))
|
|
61
|
+
return 'Safari';
|
|
62
|
+
if (/firefox|fxios/i.test(ua)) return 'Firefox';
|
|
63
|
+
if (/msie|trident/i.test(ua)) return 'Internet Explorer';
|
|
64
|
+
if (/ucbrowser/i.test(ua)) return 'UC Browser';
|
|
65
|
+
if (/samsungbrowser/i.test(ua)) return 'Samsung Browser';
|
|
66
|
+
if (/qqbrowser/i.test(ua)) return 'QQ Browser';
|
|
67
|
+
if (/baidubrowser/i.test(ua)) return 'Baidu Browser';
|
|
68
|
+
if (/yabrowser/i.test(ua)) return 'Yandex Browser';
|
|
69
|
+
if (/vivaldi/i.test(ua)) return 'Vivaldi';
|
|
70
|
+
if (/brave/i.test(ua)) return 'Brave';
|
|
71
|
+
return 'Unknown';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const useDeviceStore = defineStore('device', {
|
|
75
|
+
state: () => ({
|
|
76
|
+
type: '' as DeviceType,
|
|
77
|
+
os: '',
|
|
78
|
+
browser: '',
|
|
79
|
+
isTouch: false,
|
|
80
|
+
width: 0,
|
|
81
|
+
height: 0,
|
|
82
|
+
dpr: 1,
|
|
83
|
+
orientation: '' as Orientation,
|
|
84
|
+
connectionType: '' as string,
|
|
85
|
+
saveData: false,
|
|
86
|
+
language: '',
|
|
87
|
+
}),
|
|
88
|
+
actions: {
|
|
89
|
+
setDeviceInfo(init = false) {
|
|
90
|
+
if (import.meta.server) return;
|
|
91
|
+
|
|
92
|
+
const width = window.innerWidth;
|
|
93
|
+
const height = window.innerHeight;
|
|
94
|
+
const ua = navigator.userAgent;
|
|
95
|
+
const dpr = window.devicePixelRatio || 1;
|
|
96
|
+
const isTouch =
|
|
97
|
+
'ontouchstart' in window || navigator.maxTouchPoints > 0;
|
|
98
|
+
|
|
99
|
+
if (init) {
|
|
100
|
+
this.type = detectDevice();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
this.os = detectOS(ua);
|
|
104
|
+
this.browser = detectBrowser(ua);
|
|
105
|
+
this.isTouch = isTouch;
|
|
106
|
+
this.width = width;
|
|
107
|
+
this.height = height;
|
|
108
|
+
this.dpr = dpr;
|
|
109
|
+
this.orientation = width > height ? 'landscape' : 'portrait';
|
|
110
|
+
this.language = navigator.language || '';
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
updateNetworkInfo() {
|
|
114
|
+
const update = () => {
|
|
115
|
+
const navConn = (
|
|
116
|
+
navigator as unknown as { connection?: NetworkInfo }
|
|
117
|
+
).connection;
|
|
118
|
+
if (navConn) {
|
|
119
|
+
this.connectionType = navConn.effectiveType ?? '';
|
|
120
|
+
this.saveData = navConn.saveData ?? false;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
if ('requestIdleCallback' in window) {
|
|
125
|
+
// biome-ignore lint/suspicious/noExplicitAny: required fix
|
|
126
|
+
(window as any).requestIdleCallback(update);
|
|
127
|
+
} else {
|
|
128
|
+
setTimeout(update, 0);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const navConn = (
|
|
132
|
+
navigator as unknown as { connection?: NetworkInfo }
|
|
133
|
+
).connection;
|
|
134
|
+
if (navConn?.addEventListener) {
|
|
135
|
+
const listener = () => this.updateNetworkInfo();
|
|
136
|
+
navConn.addEventListener('change', listener);
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
initDeviceDetection() {
|
|
141
|
+
if (import.meta.server) return;
|
|
142
|
+
|
|
143
|
+
const resizeHandler = () => this.setDeviceInfo();
|
|
144
|
+
|
|
145
|
+
onMounted(() => {
|
|
146
|
+
this.setDeviceInfo(true);
|
|
147
|
+
window.addEventListener('resize', resizeHandler);
|
|
148
|
+
this.updateNetworkInfo();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
onBeforeUnmount(() => {
|
|
152
|
+
window.removeEventListener('resize', resizeHandler);
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CookiePreferences,
|
|
3
|
+
type CookieSelection,
|
|
4
|
+
COOKIE_CATEGORIES,
|
|
5
|
+
} from '~/types/cookie';
|
|
6
|
+
|
|
7
|
+
const defaultSelection = COOKIE_CATEGORIES.reduce(
|
|
8
|
+
(acc, category) => {
|
|
9
|
+
acc[category] = category === 'necessary';
|
|
10
|
+
return acc;
|
|
11
|
+
},
|
|
12
|
+
{} as Record<string, boolean>,
|
|
13
|
+
) as CookieSelection;
|
|
14
|
+
|
|
15
|
+
const defaultCookiePrefs: CookiePreferences = {
|
|
16
|
+
...defaultSelection,
|
|
17
|
+
timestamp: 0,
|
|
18
|
+
status: 'pending',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const useSettingsStore = defineStore('settings', {
|
|
22
|
+
state: () => ({
|
|
23
|
+
isLoading: false,
|
|
24
|
+
theme: 'light' as 'light' | 'dark',
|
|
25
|
+
count: 0,
|
|
26
|
+
currentLocale: '' as string,
|
|
27
|
+
locales: [] as string[],
|
|
28
|
+
defaultLocale: '' as string,
|
|
29
|
+
cookiePreferences: { ...defaultCookiePrefs },
|
|
30
|
+
isCookieBannerVisible: false,
|
|
31
|
+
}),
|
|
32
|
+
actions: {
|
|
33
|
+
init() {
|
|
34
|
+
const config = useMyelophoneConfig().multi18n;
|
|
35
|
+
|
|
36
|
+
if (!config) {
|
|
37
|
+
console.warn(
|
|
38
|
+
'[multi18n] No myelophone config found for multi18n',
|
|
39
|
+
);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this.defaultLocale = config.defaultLocale;
|
|
44
|
+
this.locales = config.locales;
|
|
45
|
+
this.currentLocale = config.defaultLocale;
|
|
46
|
+
|
|
47
|
+
const route = useRoute();
|
|
48
|
+
const segments = route.path.split('/');
|
|
49
|
+
const urlPrefix = segments[1] ?? '';
|
|
50
|
+
|
|
51
|
+
if (this.locales.includes(urlPrefix)) {
|
|
52
|
+
this.currentLocale = urlPrefix;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
setIsLoading(isLoading: boolean) {
|
|
56
|
+
this.isLoading = isLoading;
|
|
57
|
+
},
|
|
58
|
+
setTheme(theme: 'light' | 'dark') {
|
|
59
|
+
this.theme = theme;
|
|
60
|
+
|
|
61
|
+
const { applyTheme } = useThemeSync();
|
|
62
|
+
applyTheme(theme);
|
|
63
|
+
},
|
|
64
|
+
loadTheme() {
|
|
65
|
+
let saved: 'light' | 'dark' | null = null;
|
|
66
|
+
try {
|
|
67
|
+
const raw = window?.localStorage?.getItem('theme');
|
|
68
|
+
if (raw === 'light' || raw === 'dark') {
|
|
69
|
+
saved = raw;
|
|
70
|
+
}
|
|
71
|
+
} catch (_e) {
|
|
72
|
+
const cookietheme = useCookie<'light' | 'dark' | null>('theme');
|
|
73
|
+
if (
|
|
74
|
+
cookietheme.value !== undefined &&
|
|
75
|
+
cookietheme.value !== null
|
|
76
|
+
) {
|
|
77
|
+
saved = cookietheme.value;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const prefersDark =
|
|
81
|
+
window.matchMedia?.('(prefers-color-scheme: dark)').matches ??
|
|
82
|
+
false;
|
|
83
|
+
const theme: 'light' | 'dark' =
|
|
84
|
+
saved || (prefersDark ? 'dark' : 'light');
|
|
85
|
+
this.setTheme(theme);
|
|
86
|
+
},
|
|
87
|
+
toggleTheme() {
|
|
88
|
+
const newTheme = this.theme === 'light' ? 'dark' : 'light';
|
|
89
|
+
this.setTheme(newTheme);
|
|
90
|
+
},
|
|
91
|
+
increment() {
|
|
92
|
+
this.count++;
|
|
93
|
+
},
|
|
94
|
+
updateLocaleFromRoute(path: string) {
|
|
95
|
+
const segments = path.split('/');
|
|
96
|
+
const prefix = segments[1] ?? '';
|
|
97
|
+
this.currentLocale = this.locales.includes(prefix)
|
|
98
|
+
? prefix
|
|
99
|
+
: this.defaultLocale;
|
|
100
|
+
},
|
|
101
|
+
setLocale(locale: string) {
|
|
102
|
+
if (!this.locales.includes(locale)) {
|
|
103
|
+
console.warn(`[multi18n] Locale "${locale}" is not supported.`);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
this.currentLocale = locale;
|
|
108
|
+
|
|
109
|
+
const route = useRoute();
|
|
110
|
+
const router = useRouter();
|
|
111
|
+
const segments = route.path.split('/').filter(Boolean);
|
|
112
|
+
|
|
113
|
+
const firstSegment = segments[0] ?? '';
|
|
114
|
+
|
|
115
|
+
if (this.locales.includes(firstSegment)) {
|
|
116
|
+
segments.shift();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (locale !== this.defaultLocale) {
|
|
120
|
+
segments.unshift(locale);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const newPath = '/' + segments.join('/');
|
|
124
|
+
|
|
125
|
+
if (newPath !== route.path) {
|
|
126
|
+
router.push({
|
|
127
|
+
path: newPath,
|
|
128
|
+
query: route.query ?? {},
|
|
129
|
+
hash: route.hash ?? '',
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
setCookieConsent(prefs: CookiePreferences) {
|
|
134
|
+
this.cookiePreferences = { ...prefs };
|
|
135
|
+
},
|
|
136
|
+
resetCookieConsent() {
|
|
137
|
+
this.cookiePreferences = {
|
|
138
|
+
...defaultCookiePrefs,
|
|
139
|
+
necessary: true,
|
|
140
|
+
timestamp: Date.now(),
|
|
141
|
+
status: 'declined',
|
|
142
|
+
};
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
});
|