Skip to content

Commit fe552e2

Browse files
committed
made model viewer dynamic
1 parent d01b500 commit fe552e2

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/components/icon.astro

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,14 @@ export interface Props {
99
const { filename } = Astro.props as Props;
1010
1111
---
12-
{(filename == "github") &&<img src={githubImg.src} height="32px"/>}
13-
{(filename == "search") &&<img src={search.src} height="32px"/>}
12+
{(filename == "github") && <img class="icon-img" src={githubImg.src} alt="GitHub" />}
13+
{(filename == "search") && <img class="icon-img" src={search.src} alt="Search" />}
14+
15+
<style>
16+
.icon-img {
17+
height: 32px !important;
18+
width: 32px !important;
19+
object-fit: contain !important;
20+
display: inline-block;
21+
}
22+
</style>

src/components/markdown/model/ModelViewer.astro

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ const { src, title} = Astro.props as Props;
2626
</model-viewer>
2727

2828
<script>
29-
import '@google/model-viewer';
29+
// Load the heavy model-viewer library only when a <model-viewer> tag exists on the page
30+
if (typeof window !== 'undefined' && !customElements.get('model-viewer')) {
31+
if (document.querySelector('model-viewer')) {
32+
import('@google/model-viewer');
33+
}
34+
}
3035
</script>
3136

3237
<style>

src/components/markdown/model/ModelViewerCode.astro

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ if(Object.hasOwn(data,"environment-image")){
7070
}
7171

7272
<script>
73-
import '@google/model-viewer';
73+
// Load the heavy model-viewer library only when a <model-viewer> tag exists on the page
74+
if (typeof window !== 'undefined' && !customElements.get('model-viewer')) {
75+
if (document.querySelector('model-viewer')) {
76+
import('@google/model-viewer');
77+
}
78+
}
7479
</script>
7580

7681
<style>

0 commit comments

Comments
 (0)