diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e64d1f24..87bc54eaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - added `HighlightedText.svelte` - added `CopyToClipboard.svelte` - added `ScrollbarStyler.svelte` +- added `PLATFORM` and `isPlatformIn(oses, browsers)` ## `@svizzle/site` v0.4.1 (next) diff --git a/package-lock.json b/package-lock.json index 07e638fcf..c9c784a42 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "@turf/centroid": "6.5.0", "@turf/helpers": "6.5.0", "@turf/truncate": "6.5.0", + "bowser": "^2.11.0", "camelcase": "^7.0.0", "chance": "^1.1.8", "commander": "^7.2.0", @@ -4554,6 +4555,11 @@ "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==", "dev": true }, + "node_modules/bowser": { + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/bowser/-/bowser-2.11.0.tgz", + "integrity": "sha512-AlcaJBi/pqqJBIQ8U9Mcpc9i8Aqxn88Skv5d+xBX006BY5u8N3mGLHa5Lgppa7L/HfwgwLgZ6NYs+Ag6uUmJRA==" + }, "node_modules/boxen": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/boxen/-/boxen-1.3.0.tgz", @@ -17247,6 +17253,11 @@ "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==", "dev": true }, + "bowser": { + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/bowser/-/bowser-2.11.0.tgz", + "integrity": "sha512-AlcaJBi/pqqJBIQ8U9Mcpc9i8Aqxn88Skv5d+xBX006BY5u8N3mGLHa5Lgppa7L/HfwgwLgZ6NYs+Ag6uUmJRA==" + }, "boxen": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/boxen/-/boxen-1.3.0.tgz", diff --git a/packages/components/ui/CHANGELOG.md b/packages/components/ui/CHANGELOG.md index e54892ba9..3bb385a02 100644 --- a/packages/components/ui/CHANGELOG.md +++ b/packages/components/ui/CHANGELOG.md @@ -6,6 +6,7 @@ - added `HighlightedText.svelte` - added `CopyToClipboard.svelte` - added `ScrollbarStyler.svelte` +- added `PLATFORM` and `isPlatformIn(oses, browsers)` ## `@svizzle/ui` v0.8.0 diff --git a/packages/components/ui/package.json b/packages/components/ui/package.json index df4861148..2f0ba3bd6 100644 --- a/packages/components/ui/package.json +++ b/packages/components/ui/package.json @@ -11,6 +11,7 @@ "@macfja/svelte-persistent-store": "^2.1.0", "@svizzle/dom": "^0.7.0", "@svizzle/utils": "^0.18.0", + "bowser": "^2.11.0", "just-compare": "^2.2.2", "uid": "^2.0.0" }, diff --git a/packages/components/ui/src/utils/env.js b/packages/components/ui/src/utils/env.js index ea57099ed..f708a2801 100644 --- a/packages/components/ui/src/utils/env.js +++ b/packages/components/ui/src/utils/env.js @@ -1,3 +1,13 @@ +import Bowser from 'bowser'; + export const isServerSide = typeof window === 'undefined'; export const isClientSide = !isServerSide; + +export const PLATFORM = isClientSide + ? {...Bowser.parse(window.navigator.userAgent)} + : null; + +export const isPlatformIn = (oses, browsers) => isClientSide + && oses.includes(PLATFORM?.os.name) + && browsers.includes(PLATFORM?.browser.name);