blob: 4cb0262d30f49e54e9e18e45734bf6575fb98b5a (
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
<script lang="ts" context="module">
import type { Artwork as JetArtworkType } from '@jet-app/app-store/api/models';
import type { NamedProfile } from '~/config/components/artwork';
export type AppIconProfile = Extract<
NamedProfile,
| 'app-icon'
| 'app-icon-large'
| 'app-icon-medium'
| 'app-icon-small'
| 'app-icon-xlarge'
| 'app-icon-river'
| 'brick-app-icon'
>;
export function doesAppIconNeedBorder(icon: JetArtworkType): boolean {
const doesIconHaveTransparentBackground =
icon.backgroundColor &&
isNamedColor(icon.backgroundColor) &&
icon.backgroundColor.name === 'clear';
const isIconPrerendered =
icon.style === 'roundedRectPrerendered' ||
icon.style === 'roundPrerendered';
const isIconUnadorned = icon.style === 'unadorned';
return (
!doesIconHaveTransparentBackground &&
!isIconPrerendered &&
!isIconUnadorned
);
}
</script>
<script lang="ts">
import Artwork from '~/components/Artwork.svelte';
import { ArtworkConfig } from '@amp/web-app-components/config/components/artwork';
import { isNamedColor } from '~/utils/color';
export let icon: JetArtworkType;
export let profile: AppIconProfile = 'app-icon';
export let fixedWidth: boolean = true;
export let disableAutoCenter: boolean = false;
export let withBorder: boolean = false;
const profiles = ArtworkConfig.get().PROFILES;
$: computedProfile = (
icon.style === 'pill'
? `${profile}-pill`
: icon.style === 'tvRect'
? `${profile}-tv-rect`
: profile
) as NamedProfile;
$: widthFromProfile = profiles?.get(computedProfile)?.[0] ?? 0;
$: hasTransparentBackground =
!!icon.backgroundColor &&
isNamedColor(icon.backgroundColor) &&
icon.backgroundColor.name === 'clear';
$: needsBorder = withBorder || doesAppIconNeedBorder(icon);
// These prerendered "Solarium" icons need to use higher than normal quality due to how their
// rendering pipeline downscales/transforms sources.
$: quality =
icon.style &&
['roundedRectPrerendered', 'roundPrerendered'].includes(icon.style)
? 75
: undefined;
</script>
<div
class="app-icon"
class:pill={icon.style === 'pill'}
class:round={icon.style === 'round'}
class:rounded-rect={icon.style === 'roundedRect'}
class:tv-rect={icon.style === 'tvRect'}
class:rounded-rect-prerendered={icon.style === 'roundedRectPrerendered'}
class:round-prerendered={icon.style === 'roundPrerendered'}
class:with-border={needsBorder}
style={fixedWidth ? `--profileWidth: ${widthFromProfile}px` : ''}
>
<Artwork
{disableAutoCenter}
{hasTransparentBackground}
{quality}
artwork={icon}
profile={computedProfile}
noShelfChevronAnchor={true}
/>
</div>
<style>
.app-icon {
aspect-ratio: 1 / 1;
min-width: var(--profileWidth, auto);
}
.app-icon.pill {
aspect-ratio: 4 / 3;
/*
Creates elliptical corners with horizontal radii at 50% of the width and vertical radii
at 65% of the height, for a rounded, squished, pill-like effect
*/
border-radius: 50% 50% 50% 50% / 65% 65% 65% 65%;
}
.app-icon.round {
border-radius: 50%;
}
.app-icon.rounded-rect {
border-radius: 23%;
}
.app-icon.tv-rect {
aspect-ratio: 16/9;
border-radius: 9% / 16%;
}
.app-icon.rounded-rect-prerendered {
border-radius: 25%;
}
.app-icon.round-prerendered {
border-radius: 50%;
}
.app-icon.with-border {
box-shadow: 0 0 0 1px var(--systemQuaternary);
}
</style>
|