Skip to content

Commit

Permalink
fix(source): added densities option
Browse files Browse the repository at this point in the history
  • Loading branch information
ThornWalli committed Nov 3, 2023
1 parent 75bdca5 commit c8a5c55
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 16 deletions.
12 changes: 8 additions & 4 deletions playground/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ const stage = {
xl: '100vw',
xxl: '100vw'
},
media: '(orientation: landscape)'
media: '(orientation: landscape)',
densities: ['x1', 'x2']
},
{
src: '/img/stage-portrait.jpg',
sizes: { default: '100vw', xxs: '100vw', xs: '100vw' },
media: '(orientation: portrait)'
media: '(orientation: portrait)',
densities: ['x1', 'x2']
}
]
}
Expand Down Expand Up @@ -86,7 +88,8 @@ const imageTextA = {
xxl: '100vw'
}
}
]
],
densities: ['x1', 'x2']
}
};
Expand Down Expand Up @@ -117,7 +120,8 @@ const imageTextB = {
xxl: '100vw'
}
}
]
],
densities: ['x1', 'x2']
}
};
Expand Down
3 changes: 2 additions & 1 deletion playground/pages/tests/image/components/Critical.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const image = {
lg: '100vw',
xl: '100vw',
xxl: '100vw'
}
},
densities: ['x1', 'x2']
}
};
</script>
3 changes: 2 additions & 1 deletion playground/pages/tests/image/components/Lazy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const image = {
lg: '100vw',
xl: '100vw',
xxl: '100vw'
}
},
densities: ['x1', 'x2']
}
};
</script>
3 changes: 2 additions & 1 deletion playground/pages/tests/picture/components/Critical.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const picture = {
lg: '100vw',
xl: '100vw',
xxl: '100vw'
}
},
densities: ['x1', 'x2']
}
]
};
Expand Down
3 changes: 2 additions & 1 deletion playground/pages/tests/picture/components/Lazy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const picture = {
lg: '100vw',
xl: '100vw',
xxl: '100vw'
}
},
densities: ['x1', 'x2']
}
]
};
Expand Down
23 changes: 17 additions & 6 deletions src/runtime/components/SpeedkitImage/classes/Source.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ export default class Source {
format = null;
quality = null;
preload = false;
modifiers = {};
provider = undefined; // https://image.nuxtjs.org/api/optionsproviders
preset = undefined; // https://image.nuxtjs.org/api/optionspresets
modifiers = {}; // https://image.nuxt.com/usage/nuxt-img#modifiers
provider = undefined; // https://image.nuxt.com/usage/nuxt-img#provider
preset = undefined; // https://image.nuxt.com/usage/nuxt-img#preset
densities = undefined; // https://image.nuxt.com/usage/nuxt-img#densities

constructor({
src,
Expand All @@ -25,7 +26,8 @@ export default class Source {
preload = false,
modifiers = {},
provider = undefined,
preset = undefined
preset = undefined,
densities = undefined
}) {
this.src = src;
this.sizes = sizes;
Expand All @@ -38,6 +40,7 @@ export default class Source {
this.modifiers = modifiers;
this.provider = provider;
this.preset = preset;
this.densities = densities;
}

get key() {
Expand Down Expand Up @@ -65,7 +68,14 @@ export default class Source {
}

getOptions() {
return { provider: this.provider, preset: this.preset };
return {
provider: this.provider,
preset: this.preset,
densities: []
.concat(this.densities || 1)
.map(v => String(v).trim())
.join(' ')
};
}

getMeta(compiledSrc, $speedkit) {
Expand Down Expand Up @@ -100,7 +110,8 @@ export default class Source {
preload: this.preload,
modifiers: this.modifiers,
provider: this.provider,
preset: this.preset
preset: this.preset,
densities: this.densities
};
}

Expand Down
10 changes: 9 additions & 1 deletion src/runtime/components/SpeedkitVimeo/Base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ export default {
xxl: '100vw'
};
}
},
posterDensities: {
type: [Array, String],
default() {
return ['x1', 'x2'];
}
}
},
emits: ['playing', 'ready'],
Expand Down Expand Up @@ -183,7 +190,8 @@ export default {
'vimeo'
),
sizes: this.posterSizes,
media: 'all'
media: 'all',
densities: this.posterDensities
}
]
};
Expand Down
10 changes: 9 additions & 1 deletion src/runtime/components/SpeedkitYoutube/Base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ export default {
xxl: '100vw'
};
}
},
posterDensities: {
type: [Array, String],
default() {
return ['x1', 'x2'];
}
}
},
Expand Down Expand Up @@ -122,7 +129,8 @@ export default {
{
src: `/youtube/vi/${this.videoId}/maxresdefault.jpg`,
sizes: this.posterSizes,
media: 'all'
media: 'all',
densities: this.posterDensities
}
]
};
Expand Down

0 comments on commit c8a5c55

Please sign in to comment.