@playpilot/tpi 8.28.1 → 8.29.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playpilot/tpi",
3
- "version": "8.28.1",
3
+ "version": "8.29.0-beta.2",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -6,6 +6,14 @@ export type ParticipantData = {
6
6
  jobs: Job[]
7
7
  image: string | null
8
8
  image_uuid: string | null
9
+ image_metadata?: {
10
+ license_name: string
11
+ license_url: string
12
+ source_text: string
13
+ source_url: string
14
+ author_text: string
15
+ author_url: string
16
+ }
9
17
  gender: string
10
18
  character?: string | null
11
19
  bio?: string | null
@@ -0,0 +1,3 @@
1
+ <svg height="24px" viewBox="0 -960 960 960" width="24px">
2
+ <path fill="currentColor" d="M430-200h100v-180h60v-184q0-27-28.5-41.5T480-620q-53 0-81.5 14.5T370-564v184h60v180Zm-105 88.5q-73-31.5-127.5-86t-86-127.5Q80-398 80-480.5t31.5-155q31.5-72.5 86-127t127.5-86Q398-880 480.5-880t155 31.5q72.5 31.5 127 86t86 127Q880-563 880-480.5T848.5-325q-31.5 73-86 127.5t-127 86Q563-80 480.5-80T325-111.5Zm381.5-142Q800-347 800-480t-93.5-226.5Q613-800 480-800t-226.5 93.5Q160-613 160-480t93.5 226.5Q347-160 480-160t226.5-93.5ZM523-657q17-17 17-43t-17-43q-17-17-43-17t-43 17q-17 17-17 43t17 43q17 17 43 17t43-17Zm-43 177Z"/>
3
+ </svg>
@@ -10,7 +10,7 @@
10
10
  import { trackViaPixel } from '@playpilot/retargeting-tracking'
11
11
  import Popover from './Popover.svelte'
12
12
  import Title from './Title.svelte'
13
- import Participant from './Participant.svelte'
13
+ import Participant from './Participants/Participant.svelte'
14
14
  import TopScroll from './Ads/TopScroll.svelte'
15
15
  import Display from './Ads/Display.svelte'
16
16
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  <script lang="ts">
3
3
  import Modal from './Modal.svelte'
4
- import Participant from '../Participant.svelte'
4
+ import Participant from '../Participants/Participant.svelte'
5
5
  import type { ParticipantData } from '$lib/types/participant'
6
6
  import { TrackingEvent } from '$lib/enums/TrackingEvent'
7
7
  import { track } from '$lib/tracking'
@@ -5,11 +5,12 @@
5
5
  import { openModal } from '$lib/modal'
6
6
  import type { ParticipantData } from '$lib/types/participant'
7
7
  import type { TitleData } from '$lib/types/title'
8
- import ListTitle from './ListTitle.svelte'
9
8
  import { t } from '$lib/localization'
10
9
  import { isRetargetingAllowed } from '$lib/retargeting'
11
10
  import { trackViaPixel } from '@playpilot/retargeting-tracking'
12
11
  import { MetaEvent } from '$lib/enums/TrackingEvent'
12
+ import ParticipantImage from './ParticipantImage.svelte'
13
+ import ListTitle from '../ListTitle.svelte'
13
14
 
14
15
  interface Props {
15
16
  participant: ParticipantData
@@ -54,13 +55,17 @@
54
55
  </script>
55
56
 
56
57
  <div class="header" class:small>
57
- <div class="heading" use:heading={2} id="heading">{name}</div>
58
+ <ParticipantImage {participant} />
58
59
 
59
- {#if birth_date}
60
- <p class="dates">
61
- {t('Born On')} <strong>{formatDate(birth_date)}</strong>{#if death_date}, {t('Died On')} <strong>{formatDate(death_date)}</strong>{/if}
62
- </p>
63
- {/if}
60
+ <div>
61
+ <div class="heading" use:heading={2} id="heading">{name}</div>
62
+
63
+ {#if birth_date}
64
+ <p class="dates">
65
+ {t('Born On')} <strong>{formatDate(birth_date)}</strong>{#if death_date}, {t('Died On')} <strong>{formatDate(death_date)}</strong>{/if}
66
+ </p>
67
+ {/if}
68
+ </div>
64
69
  </div>
65
70
 
66
71
  <div class="content">
@@ -85,13 +90,22 @@
85
90
 
86
91
  <style lang="scss">
87
92
  .header {
88
- padding: margin(4) margin(1) margin(2);
93
+ --participant-image-size: #{margin(6)};
94
+ display: grid;
95
+ grid-template-columns: calc(var(--participant-image-size)) auto;
96
+ align-items: center;
97
+ gap: margin(1);
98
+ padding: margin(3) margin(1) margin(2);
89
99
  font-family: theme(detail-font-family, font-family);
90
100
  font-weight: theme(detail-font-weight, normal);
91
101
  font-size: theme(detail-font-size, font-size-base);
92
102
  line-height: theme(participant-description-line-height, normal);
93
103
  color: theme(detail-text-color, text-color);
94
104
 
105
+ @include desktop {
106
+ --participant-image-size: #{margin(8)};
107
+ }
108
+
95
109
  &.small {
96
110
  padding: margin(1);
97
111
  }
@@ -101,7 +115,7 @@
101
115
  margin: 0;
102
116
  font-family: theme(detail-title-font-family, font-family);
103
117
  font-weight: theme(detail-title-font-weight, lighter);
104
- font-size: theme(detail-title-font-size, margin(1.5));
118
+ font-size: clamp(1.25em, 5vw, 1.5em);
105
119
  line-height: normal;
106
120
  font-style: theme(detail-title-font-style, normal);
107
121
 
@@ -109,6 +123,10 @@
109
123
  margin: 0 0 margin(0.5);
110
124
  font-size: theme(detail-title-small-font-size, margin(1.25));
111
125
  }
126
+
127
+ .small & {
128
+ font-size: 1em;
129
+ }
112
130
  }
113
131
 
114
132
  .dates {
@@ -0,0 +1,130 @@
1
+ <script lang="ts">
2
+ import { t } from '$lib/localization'
3
+ import type { ParticipantData } from '$lib/types/participant'
4
+ import IconAttribution from '../Icons/IconAttribution.svelte'
5
+
6
+ interface Props {
7
+ participant?: ParticipantData | null
8
+ }
9
+
10
+ const { participant = null }: Props = $props()
11
+
12
+ const { image_metadata } = $derived(participant || { image_metadata: null })
13
+
14
+ let showAttribution = $state(false)
15
+
16
+ function toggleAttribution(event: MouseEvent): void {
17
+ event.stopImmediatePropagation()
18
+
19
+ if ((event.target as HTMLElement).nodeName === 'A') return
20
+
21
+ event.preventDefault()
22
+
23
+ showAttribution = !showAttribution
24
+ }
25
+ </script>
26
+
27
+ <div class="image">
28
+ {#if participant?.image}
29
+ <img loading="lazy" src={participant.image} alt="" />
30
+
31
+ {#if image_metadata}
32
+ <button class="attribution-icon" onclick={toggleAttribution}>
33
+ <IconAttribution />
34
+ </button>
35
+ {/if}
36
+ {/if}
37
+
38
+ {#if participant && image_metadata && showAttribution}
39
+ <!-- svelte-ignore a11y_click_events_have_key_events -->
40
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
41
+ <div class="attribution-overlay" onclick={toggleAttribution}>
42
+ <a href={image_metadata.source_url} target="_blank" rel="external nofollow noreferrer">{image_metadata.source_text}</a>
43
+ {t('By')}
44
+ <a href={image_metadata.author_url} target="_blank" rel="external nofollow noreferrer">{image_metadata.author_text}</a>
45
+ /
46
+ <a href={image_metadata.license_url} target="_blank" rel="external nofollow noreferrer">{image_metadata.license_name}</a>
47
+ </div>
48
+ {/if}
49
+ </div>
50
+
51
+ <style lang="scss">
52
+ $item-width: #{var(--participant-image-size, margin(6))};
53
+
54
+ .image {
55
+ position: relative;
56
+ display: block;
57
+ width: $item-width;
58
+ height: $item-width;
59
+ border-radius: theme(border-radius);
60
+ overflow: hidden;
61
+ background: theme(cast-background, lighter);
62
+
63
+ &::before,
64
+ &::after {
65
+ content: '';
66
+ display: block;
67
+ position: absolute;
68
+ width: 50%;
69
+ height: 50%;
70
+ top: 50%;
71
+ left: 50%;
72
+ border-radius: 50%;
73
+ transform: translateX(-50%) translateY(-50%);
74
+ background: currentColor;
75
+ opacity: 0.1;
76
+ }
77
+
78
+ &::after {
79
+ top: 100%;
80
+ width: 75%;
81
+ }
82
+
83
+ img {
84
+ z-index: 1;
85
+ position: relative;
86
+ width: 100%;
87
+ height: auto;
88
+ }
89
+ }
90
+
91
+ .attribution-icon {
92
+ z-index: 2;
93
+ cursor: pointer;
94
+ position: absolute;
95
+ right: 0;
96
+ bottom: 0;
97
+ padding: margin(0.25);
98
+ margin: 0;
99
+ border: 0;
100
+ background: transparent;
101
+ color: rgba(255, 255, 255, 0.75);
102
+
103
+ &:hover {
104
+ color: white;
105
+ }
106
+
107
+ :global(svg) {
108
+ display: block;
109
+ }
110
+ }
111
+
112
+ .attribution-overlay {
113
+ z-index: 1;
114
+ position: absolute;
115
+ top: 0;
116
+ right: 0;
117
+ bottom: 0;
118
+ left: 0;
119
+ padding: margin(0.25);
120
+ background: rgba(0, 0, 0, 0.85);
121
+ font-size: 11px;
122
+ line-height: 1.25;
123
+ white-space: wrap;
124
+ text-align: left;
125
+
126
+ a {
127
+ color: currentColor;
128
+ }
129
+ }
130
+ </style>
@@ -8,6 +8,7 @@
8
8
  import { track } from '$lib/tracking'
9
9
  import type { ParticipantData } from '$lib/types/participant'
10
10
  import type { TitleData } from '$lib/types/title'
11
+ import ParticipantImage from '../Participants/ParticipantImage.svelte'
11
12
  import Rail from './Rail.svelte'
12
13
 
13
14
  interface Props {
@@ -35,8 +36,6 @@
35
36
  participantsByOccurrence[participant.sid] = { participant, count }
36
37
  }
37
38
 
38
- // Sort all participants by their occurrences. If a participant did not occur their positioned will be retained
39
- // relative to where it was before
40
39
  const participantsSortedByCount = Object.values(participantsByOccurrence).sort((a, b) => b.count - a.count)
41
40
 
42
41
  return participantsSortedByCount.map(({ participant }) => participant)
@@ -51,7 +50,10 @@
51
50
  {#await fetchParticipantsForTitle(title)}
52
51
  <Rail {heading}>
53
52
  {#each { length: 5 }}
54
- <div class="participant"></div>
53
+ <div class="participant">
54
+ <ParticipantImage />
55
+ <div class="name">&nbsp;</div>
56
+ </div>
55
57
  {/each}
56
58
  </Rail>
57
59
  {:then participants}
@@ -59,11 +61,9 @@
59
61
  <Rail {heading}>
60
62
  {#each orderParticipantsByPageTextOccurrence(participants).slice(0, 15) as participant}
61
63
  <button class="participant" data-testid="participant" onclick={event => onclick(event, participant)}>
62
- <span class="truncate">{participant.name}</span>
64
+ <ParticipantImage {participant} />
63
65
 
64
- {#if participant.character}
65
- <div class="character truncate">{participant.character}</div>
66
- {/if}
66
+ <div class="name">{participant.name}</div>
67
67
  </button>
68
68
  {/each}
69
69
  </Rail>
@@ -71,22 +71,25 @@
71
71
  {/await}
72
72
 
73
73
  <style lang="scss">
74
+ $item-width: #{theme(rail-size-default, margin(6))};
75
+
74
76
  .participant {
77
+ --participant-image-size: #{$item-width};
75
78
  display: flex;
76
79
  flex-direction: column;
77
- flex: 0 0 10rem;
78
- width: 10rem;
79
- min-height: margin(3.375); // Matches 54 pixels, the height of a card with both name and character
80
- padding: margin(0.5);
81
- border: theme(cast-border, 0);
80
+ flex: 0 0 $item-width;
81
+ gap: margin(0.5);
82
+ width: $item-width;
83
+ padding: 0;
82
84
  border-radius: theme(cast-border-radius, border-radius);
83
- background: theme(cast-background, lighter);
85
+ border: 0;
86
+ background: transparent;
84
87
  cursor: pointer;
85
- font-family: inherit;
86
- text-align: left;
87
88
  color: inherit;
89
+ font-family: inherit;
88
90
  font-size: theme(cast-font-size, font-size-small);
89
91
  line-height: normal;
92
+ text-align: center;
90
93
  white-space: nowrap;
91
94
 
92
95
  &:is(button):hover,
@@ -96,13 +99,10 @@
96
99
  }
97
100
  }
98
101
 
99
- .character {
100
- color: theme(cast-character-text-color, text-color-alt);
101
- font-style: italic;
102
- }
103
-
104
- .truncate {
102
+ .name {
103
+ min-height: 1lh;
105
104
  overflow: hidden;
105
+ color: theme(participant-text-color, text-color-alt) !important;
106
106
  text-overflow: ellipsis;
107
107
  white-space: nowrap;
108
108
  }
@@ -1,7 +1,7 @@
1
1
  import { fireEvent, render, waitFor } from '@testing-library/svelte'
2
2
  import { describe, expect, it, vi, beforeEach } from 'vitest'
3
3
 
4
- import Participant from '../../../routes/components/Participant.svelte'
4
+ import Participant from '../../../../routes/components/Participants/Participant.svelte'
5
5
  import { participants, title } from '$lib/fakeData'
6
6
  import { fetchTitlesForParticipant } from '$lib/api/participants'
7
7
 
@@ -80,4 +80,23 @@ describe('Participant.svelte', () => {
80
80
  expect(queryByText('Credits')).not.toBeTruthy()
81
81
  expect(container.querySelector('.small')).toBeTruthy()
82
82
  })
83
+
84
+ it('Should render image if given', async () => {
85
+ const participantWithImage = { ...participants[0], image: 'some-image.jpg' }
86
+
87
+ const { getByRole } = render(Participant, { participant: participantWithImage })
88
+
89
+ await waitFor(() => {
90
+ expect(getByRole('presentation')).toBeTruthy()
91
+ })
92
+ })
93
+
94
+ it('Should not render image if not given', async () => {
95
+
96
+ const { queryByRole } = render(Participant, { participant: participants[0] })
97
+
98
+ await waitFor(() => {
99
+ expect(queryByRole('presentation')).not.toBeTruthy()
100
+ })
101
+ })
83
102
  })
@@ -36,6 +36,19 @@ describe('ParticipantsRail.svelte', () => {
36
36
  })
37
37
  })
38
38
 
39
+ it('Should render image only for participants with image', async () => {
40
+ const participantsWithImage = [...participants]
41
+ participantsWithImage[0].image = 'some-image.jpg'
42
+
43
+ vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participantsWithImage)
44
+
45
+ const { getAllByRole } = render(ParticipantsRail, { title })
46
+
47
+ await waitFor(() => {
48
+ expect(getAllByRole('presentation')).toHaveLength(1)
49
+ })
50
+ })
51
+
39
52
  it('Should order participants by their number of occurrences on the page', async () => {
40
53
  document.body.innerHTML = `<main>${participants[1].name}. ${participants[2].name}, ${participants[2].name}</main>`
41
54
  vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)