Skip to content

Commit

Permalink
fix(source): @nuxt/image densities definition
Browse files Browse the repository at this point in the history
  • Loading branch information
ThornWalli committed Nov 8, 2023
1 parent c8a5c55 commit 8adfa89
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 33 deletions.
12 changes: 4 additions & 8 deletions playground/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ const stage = {
xl: '100vw',
xxl: '100vw'
},
media: '(orientation: landscape)',
densities: ['x1', 'x2']
media: '(orientation: landscape)'
},
{
src: '/img/stage-portrait.jpg',
sizes: { default: '100vw', xxs: '100vw', xs: '100vw' },
media: '(orientation: portrait)',
densities: ['x1', 'x2']
media: '(orientation: portrait)'
}
]
}
Expand Down Expand Up @@ -88,8 +86,7 @@ const imageTextA = {
xxl: '100vw'
}
}
],
densities: ['x1', 'x2']
]
}
};
Expand Down Expand Up @@ -120,8 +117,7 @@ const imageTextB = {
xxl: '100vw'
}
}
],
densities: ['x1', 'x2']
]
}
};
Expand Down
3 changes: 1 addition & 2 deletions playground/pages/tests/image/components/Critical.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const image = {
lg: '100vw',
xl: '100vw',
xxl: '100vw'
},
densities: ['x1', 'x2']
}
}
};
</script>
3 changes: 1 addition & 2 deletions playground/pages/tests/image/components/Lazy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ const image = {
lg: '100vw',
xl: '100vw',
xxl: '100vw'
},
densities: ['x1', 'x2']
}
}
};
</script>
3 changes: 1 addition & 2 deletions playground/pages/tests/picture/components/Critical.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const picture = {
lg: '100vw',
xl: '100vw',
xxl: '100vw'
},
densities: ['x1', 'x2']
}
}
]
};
Expand Down
3 changes: 1 addition & 2 deletions playground/pages/tests/picture/components/Lazy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const picture = {
lg: '100vw',
xl: '100vw',
xxl: '100vw'
},
densities: ['x1', 'x2']
}
}
]
};
Expand Down
1 change: 1 addition & 0 deletions src/module.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ async function addBuildTemplates(nuxt, options) {
mode,
options: {
mode,
densities: options.densities,
targetFormats: options.targetFormats,
crossorigin: getCrossorigin(options.crossorigin),
supportedBrowserDetector,
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/components/SpeedkitImage/Base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default {
const config = $img.getSizes(source.src, {
sizes: source.sizes,
modifiers: source.getModifiers(),
...source.getOptions()
...source.getOptions($speedkit)
});
const meta = ref(null);
Expand Down
7 changes: 2 additions & 5 deletions src/runtime/components/SpeedkitImage/classes/Source.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,11 @@ export default class Source {
return { ...this.modifiers, format: this.format, quality: this.quality };
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/components/SpeedkitPicture/Source.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default {
const config = $img.getSizes(props.source.src, {
sizes: props.source.sizes,
modifiers: props.source.getModifiers(),
...props.source.getOptions()
...props.source.getOptions($speedkit)
});
const resolvedCrossorigin = computed(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default class SourceList {
const config = $img.getSizes(source.src, {
sizes: source.sizes,
modifiers: source.getModifiers(),
...source.getOptions()
...source.getOptions($speedkit)
});
return source.getMeta(config.src, $speedkit);
})
Expand Down
6 changes: 2 additions & 4 deletions src/runtime/components/SpeedkitVimeo/Base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,8 @@ export default {
},
posterDensities: {
type: [Array, String],
default() {
return ['x1', 'x2'];
}
type: [String, Number],
default: undefined
}
},
emits: ['playing', 'ready'],
Expand Down
6 changes: 2 additions & 4 deletions src/runtime/components/SpeedkitYoutube/Base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,8 @@ export default {
},
posterDensities: {
type: [Array, String],
default() {
return ['x1', 'x2'];
}
type: [String, Number],
default: undefined
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/tmpl/plugin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export default defineNuxtPlugin({
getFont: fontList.getFont.bind(fontList),
crossorigin: <%= options.crossorigin ? `'${options.crossorigin}'` : null %>,
isBrowserSupported: () => isSupportedBrowser(<%= options.supportedBrowserDetector %>),
targetFormats: <%= JSON.stringify(options.targetFormats) %>
targetFormats: <%= JSON.stringify(options.targetFormats) %>,
densities: <%= JSON.stringify(options.densities) %>
});
},
Expand Down
1 change: 1 addition & 0 deletions src/utils/options.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function getDefaultOptions() {
fonts: [],

targetFormats: null,
densities: 'x1 x2',

/**
* IntersectionObserver rootMargin for Compoennts and Assets
Expand Down

0 comments on commit 8adfa89

Please sign in to comment.