Move files and add minor fixes
This commit is contained in:
parent
6fbc15c402
commit
51c8d06569
16 changed files with 89 additions and 105 deletions
55
src/page/image-viewer/image/image.html.ts
Normal file
55
src/page/image-viewer/image/image.html.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import { last } from '../../../helper/last';
|
||||
import { html } from '../../../types/html';
|
||||
import { ResponsiveImage } from '../../../types/responsive-image';
|
||||
import './image.scss';
|
||||
|
||||
export const Image = ({
|
||||
image,
|
||||
alt,
|
||||
container = false,
|
||||
isIgnoredByImageViewer = false,
|
||||
imageScreenRatio = 0.8,
|
||||
}: {
|
||||
image: ResponsiveImage;
|
||||
alt: string;
|
||||
container?: boolean;
|
||||
isIgnoredByImageViewer?: boolean;
|
||||
imageScreenRatio?: number;
|
||||
}): html => `
|
||||
${
|
||||
container
|
||||
? `<div class="figure-container" style="padding-top:${
|
||||
(image.height / image.width) * 100
|
||||
}%">`
|
||||
: ''
|
||||
}
|
||||
<div
|
||||
class="image"
|
||||
style="background-size: cover; background-image: url('${image.placeholder}')"
|
||||
${isIgnoredByImageViewer ? '' : 'tabindex="0"'}
|
||||
>
|
||||
<picture loading="lazy">
|
||||
<source
|
||||
srcset="${image.srcSet}"
|
||||
sizes="${getSizes(image, imageScreenRatio)}"
|
||||
type="image/"
|
||||
/>
|
||||
<img
|
||||
${isIgnoredByImageViewer ? 'image-viewer-ignore' : ''}
|
||||
|
||||
loading="lazy"
|
||||
width="${image.width}"
|
||||
height="${image.height}"
|
||||
src="${last(image.images)?.path}"
|
||||
alt="${alt}"
|
||||
/>
|
||||
</picture>
|
||||
</div>
|
||||
${container ? `</div>` : ''}
|
||||
`;
|
||||
|
||||
const getSizes = (image: ResponsiveImage, imageScreenRatio: number): string =>
|
||||
image.images
|
||||
.slice(0, -1)
|
||||
.map((d) => `(max-width: ${d.width / imageScreenRatio}px) ${d.width}px,`)
|
||||
.join('\n') + `\n${last(image.images)!.width}px`;
|
||||
12
src/page/image-viewer/image/image.scss
Normal file
12
src/page/image-viewer/image/image.scss
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
.image {
|
||||
overflow: hidden;
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
|
||||
&:not([image-viewer-ignore]) {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue