summaryrefslogtreecommitdiff
path: root/src/components/jet/today-card/media/TodayCardMediaWithArtwork.svelte
blob: e604708e3a61e795f2d07d477f9427054f147ae0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<script lang="ts" context="module">
    import type {
        Artwork as ArtworkModel,
        TodayCardMedia,
        TodayCardMediaWithArtwork,
    } from '@jet-app/app-store/api/models';

    export function isTodayCardMediaWithArtwork(
        media: TodayCardMedia,
    ): media is TodayCardMediaWithArtwork {
        return (
            media.kind === 'artwork' &&
            'artworks' in media &&
            Array.isArray(media.artworks) &&
            media.artworks.length > 0
        );
    }
</script>

<script lang="ts">
    import Artwork, {
        type Profile as ArtworkProfile,
    } from '~/components/Artwork.svelte';

    export let media: TodayCardMediaWithArtwork;

    export let pinArtworkToLeft: boolean = false;

    /**
     * A `Profile` to override the default for the card's media
     */
    export let artworkProfile: ArtworkProfile | undefined = undefined;

    let artworkToDisplay: ArtworkModel;
    // Today Card artwork comes back from Jet with a width of 800px, even though the source artwork
    // is _much_ larger. The shared `Artwork` component doesn't let us render an image beyond the
    // artwork's `width` and `height` properties, and we absolutely need to render these images
    // larger than 800px wide, so we are forcing these new upper bounds for the artworks dimensions.
    // Eventually, we should rethink this and have the proper dimensions come back from Jet:
    // rdar://148730199 (Bigger images for TodayCard)
    $: artworkToDisplay = Object.assign({}, media.artworks[0], {
        width: 3840,
        height: 2160,
    });
</script>

{#if artworkProfile}
    <Artwork profile={artworkProfile} artwork={artworkToDisplay} />
{:else}
    <div class="wrapper">
        <div class="artwork-container portrait">
            <Artwork profile="card" artwork={artworkToDisplay} />
        </div>

        <div
            class="artwork-container landscape"
            class:pinned-to-left={pinArtworkToLeft}
        >
            <Artwork profile="card-horizontal" artwork={artworkToDisplay} />
        </div>
    </div>
{/if}

<style>
    .wrapper,
    .artwork-container {
        height: 100%;
        width: 100%;
    }

    .wrapper .artwork-container :global(.artwork-component),
    .wrapper .artwork-container :global(img) {
        object-fit: cover;
        height: 100%;
    }

    .pinned-to-left {
        --artwork-override-object-position: left;
    }

    @container (orientation: landscape) {
        .artwork-container.landscape {
            display: block;
        }

        .artwork-container.portrait {
            display: none;
        }
    }

    @container (orientation: portrait) {
        .artwork-container.landscape {
            display: none;
        }

        .artwork-container.portrait {
            display: block;
        }
    }
</style>