All files / src/components/ig IgSplit.vue

100% Statements 221/221
81.25% Branches 13/16
80% Functions 4/5
100% Lines 221/221

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 6021x 1x       1x 1x 1x 1x 1x 1x 1x   1x     1x 1x 1x 1x 1x 1x 1x 1x   1x       1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x         1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x   1x     1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 3x 1x     1x   9x   1x 1x   1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12x 12x 12x 12x 12x 12x   12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 1596x 1596x 12x 12x 12x 12x 12x 480x 480x 480x 468x 468x 480x 180x 180x 468x 468x 468x 468x 12x 12x 12x 12x 12x   12x 12x 12x 12x 12x 12x 1x 1x                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
<template>
  <!--
    Brand Split template (SB-32). Left = solid navy brand panel with big
    wordmark + crests + date. Right = photo. Inspired by MLS Next Pro
    match-preview cards.
  -->
  <div
    ref="root"
    class="ig-share-card ig-split"
    data-testid="ig-share-card"
    data-template="split"
    :data-mode="mode"
  >
    <!-- Brand panel. The torn-paper right edge is drawn by an inline SVG
         layered behind the content (clip-path is ignored by html2canvas
         so we paint the shape instead). The .panel container itself
         stays a clean absolutely-positioned flex column. -->
    <div class="panel">
      <svg
        class="panel-bg-svg"
        viewBox="0 0 620 1080"
        preserveAspectRatio="none"
        xmlns="http://www.w3.org/2000/svg"
        aria-hidden="true"
      >
        <!-- Same tear, drawn twice: the accent copy sits a few px to the
             right so it peeks out along the rip like colored paper
             backing the torn sheet. Cheaper and sharper than a second
             generated path, and it keeps the two edges perfectly
             congruent. -->
        <path
          :d="panelPath"
          :fill="accentColor"
          transform="translate(7,0)"
          :opacity="0.9"
        />
        <path :d="panelPath" fill="#0B0B0D" />
      </svg>
      <div class="panel-top">
        <div class="panel-top-row">
          <div class="panel-top-text">
            <span class="meta" data-testid="ig-meta">{{ metaLabel }}</span>
          </div>
          <MlsNextBadge v-if="isHomegrownLeague" class="mls-badge" />
          <!-- White chip + background-image (not <img>) so dark logos stay
               legible and html2canvas renders contain correctly — see
               [[feedback-html2canvas-object-fit]]. -->
          <div
            v-if="tournamentLogoUrl"
            :class="[
              'tournament-logo',
              { 'tournament-logo--plated': tournamentLogoNeedsPlate },
            ]"
          >
            <div
              class="tournament-logo-img"
              data-testid="ig-tournament-logo"
              :style="{ backgroundImage: `url(${tournamentLogoUrl})` }"
            ></div>
          </div>
        </div>
      </div>
 
      <div class="hero">
        <span
          class="hero-eyebrow"
          data-testid="ig-eyebrow"
          :style="{ background: accentColor, color: accentTextColor }"
        >
          {{ ageGroupLabel }}
        </span>
        <h1 class="hero-title" data-testid="ig-status">
          <template v-if="isResult">FULL TIME</template>
          <template v-else>MATCH<br />PREVIEW</template>
        </h1>
      </div>
 
      <!-- Stacked home / VS / away. Three rows rather than a side-by-side
           trio: the panel is now too narrow for two team names abreast,
           and stacking lets each name run at a readable size instead of
           wrapping into a column an inch wide. -->
      <div class="matchup">
        <div class="team-row">
          <div
            class="crest"
            :class="{ 'crest-filled': !homeLogoUrl }"
            :style="{ boxShadow: `0 0 36px ${homeColor}aa` }"
          >
            <img
              v-if="homeLogoUrl"
              :src="homeLogoUrl"
              :alt="`${homeTeamName} logo`"
              class="crest-img"
              crossorigin="anonymous"
            />
            <span v-else class="crest-initials">{{ homeInitials }}</span>
          </div>
          <div class="team-name" data-testid="ig-home-name">
            {{ homeTeamName }}
          </div>
        </div>
 
        <div class="vs-row">
          <template v-if="isResult">
            <div class="score" data-testid="ig-score">
              {{ homeScore }} – {{ awayScore }}
            </div>
          </template>
          <template v-else>
            <div class="vs" data-testid="ig-vs" :style="{ color: accentColor }">
              VS
            </div>
          </template>
          <div class="vs-rule" :style="{ background: accentColor }"></div>
        </div>
 
        <div class="team-row">
          <div
            class="crest"
            :class="{ 'crest-filled': !awayLogoUrl }"
            :style="{ boxShadow: `0 0 36px ${awayColor}aa` }"
          >
            <img
              v-if="awayLogoUrl"
              :src="awayLogoUrl"
              :alt="`${awayTeamName} logo`"
              class="crest-img"
              crossorigin="anonymous"
            />
            <span v-else class="crest-initials">{{ awayInitials }}</span>
          </div>
          <div class="team-name" data-testid="ig-away-name">
            {{ awayTeamName }}
          </div>
        </div>
      </div>
 
      <!-- Goal scorers (live-scored result only) -->
      <div v-if="isResult && hasScorers" class="panel-scorers">
        <IgScorers
          :home="homeScorers"
          :away="awayScorers"
          :hat-tricks="hatTricks"
          size="sm"
        />
      </div>
 
      <div
        class="footer-band"
        :style="{ background: accentColor, color: accentTextColor }"
      >
        <div class="footer-row">
          <div class="footer-date" data-testid="ig-date">
            {{ shortDateLabel
            }}<span v-if="kickoffLabel"> · {{ kickoffLabel }}</span>
          </div>
          <div class="footer-handle" data-testid="ig-handle">@missingtable</div>
        </div>
        <div class="footer-tagline" data-testid="ig-tagline">
          {{ tagline }}
        </div>
      </div>
    </div>
 
    <!-- Photo layer (full bleed, behind panel). background-image, not <img>,
         so html2canvas honors cover cropping. -->
    <div
      v-if="photoSrc"
      class="photo"
      data-testid="ig-photo"
      :style="{ backgroundImage: `url(${photoSrc})` }"
    ></div>
    <div v-else class="photo-fallback" data-testid="ig-photo-fallback"></div>
  </div>
</template>
 
<script>
import { computed, ref, toRefs } from 'vue';
import { useIgShareData } from '@/composables/useIgShareData';
import MlsNextBadge from './MlsNextBadge.vue';
import IgScorers from './IgScorers.vue';
 
export default {
  name: 'IgSplit',
  components: { MlsNextBadge, IgScorers },
  props: {
    match: { type: Object, required: true },
    photoSrc: { type: String, default: null },
    photoIsCrossOrigin: { type: Boolean, default: false },
    events: { type: Array, default: () => [] },
    mode: {
      type: String,
      required: true,
      validator: v => ['preview', 'result'].includes(v),
    },
    // SB-659: which team's colors drive the accent.
    accentPreference: {
      type: String,
      default: 'auto',
      validator: v => ['auto', 'home', 'away', 'mt'].includes(v),
    },
  },
  setup(props) {
    const root = ref(null);
    const { match, mode, events, accentPreference } = toRefs(props);
    const data = useIgShareData(match, mode, events, accentPreference);
    const photoCrossOrigin = computed(() =>
      props.photoIsCrossOrigin ? 'anonymous' : null
    );
 
    // SVG path describing the torn panel shape. The base x lerps from
    // `topX` to `bottomX` so the tear leans diagonally (panel is wider
    // at the top, narrower at the bottom). Deterministic pseudo-random
    // jaggies in between. The path is filled inside an inline <svg>
    // layered behind the panel content; using SVG (not CSS clip-path)
    // because html2canvas 1.4.1 ignores clip-path: polygon() during
    // capture, leaving the PNG with a straight edge.
    const panelPath = computed(() => {
      // Strong lean: the panel gives up ~half its width by the bottom so
      // the photo opens out toward the lower right, where the action in
      // a match photo usually sits (feet, ball). A gentler angle wasted
      // the frame on flat panel.
      const topX = 600;
      const bottomX = 250;
      const height = 1080;
      const hash = n => {
        const s = Math.sin(n) * 43758.5453;
        return s - Math.floor(s);
      };
      const parts = ['M 0 0', `L ${topX} 0`];
      let y = 0;
      let i = 1;
      while (y < height) {
        const step = 16 + hash(i * 7) * 22;
        y = Math.min(y + step, height);
        if (y >= height) break;
        const baseX = topX + ((bottomX - topX) * y) / height;
        let xOffset = (hash(i * 13) - 0.5) * 28;
        if (hash(i * 17) > 0.72) {
          xOffset += (hash(i * 23) - 0.4) * 52;
        }
        const x = baseX + xOffset;
        parts.push(`L ${x.toFixed(1)} ${y.toFixed(1)}`);
        i++;
      }
      parts.push(`L ${bottomX} ${height}`);
      parts.push(`L 0 ${height}`);
      parts.push('Z');
      return parts.join(' ');
    });
 
    return {
      root,
      ...data,
      photoCrossOrigin,
      panelPath,
    };
  },
};
</script>
 
<style scoped>
.ig-share-card {
  position: relative;
  width: 1080px;
  height: 1080px;
  overflow: hidden;
  /* Neutral near-black rather than navy, so club accents read as the
     club's color instead of shifting blue against a blue ground. */
  background: #0b0b0d;
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
    Arial, sans-serif;
  color: #ffffff;
  isolation: isolate;
}
 
.panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 540px;
  height: 100%;
  z-index: 2;
  /* Right padding clears the diagonal torn edge so content stays inside
     the visible shape at every y. The tear now leans hard (600 -> 250 in
     the 620-wide path space), so the bottom of the panel is much
     narrower than the top — the footer band handles that with its own
     negative right margin rather than padding the whole column for the
     worst case, which would strand the headline in a thin gutter. */
  padding: 56px 96px 48px 48px;
  display: flex;
  flex-direction: column;
  /* No CSS background — the inline SVG below paints the torn-shape fill
     so the same shape shows up in both the live preview AND the
     html2canvas-rendered PNG. */
  background: transparent;
}
 
.panel-bg-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
 
/* Position the panel's content blocks so they paint above the absolutely
   positioned SVG background. Without an explicit z-index, the in-flow
   children would still paint above the abs SVG in most browsers, but
   html2canvas can be order-sensitive — being explicit keeps both
   renderers agreeing. */
.panel-top,
.hero,
.matchup,
.footer-band {
  position: relative;
  z-index: 1;
}
 
.panel-top {
  margin-bottom: 32px;
}
 
.panel-top-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
 
.panel-top-text {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
 
.mls-badge {
  height: 88px;
  flex-shrink: 0;
}
 
.tournament-logo {
  height: 104px;
  width: 104px;
  flex-shrink: 0;
  margin-left: 8px;
  padding: 4px;
  box-sizing: border-box;
}
 
/* Only the logos that would otherwise disappear against the dark
   card ground get a plate (SB-901). Plating is the default until
   sampling proves it unnecessary. */
.tournament-logo--plated {
  background: #ffffff;
  border-radius: 14px;
}
 
.tournament-logo-img {
  width: 100%;
  height: 100%;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
}
 
.meta {
  /* Leads the panel now that the missingtable.com wordmark above it is gone
     (SB-899) -- the tournament is the subject of the card. Tracking stays
     tight so the longest real label, "PRESEASON FRIENDLY · 2026-2027",
     still fits the narrowed panel. */
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #ffffff;
}
 
.hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
}
 
.hero-eyebrow {
  display: inline-block;
  align-self: flex-start;
  padding: 8px 18px;
  background: #dc2626;
  color: #ffffff;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.16em;
  border-radius: 4px;
}
 
.hero-title {
  /* Sized to fit the narrowed panel's content width without crossing the
     torn edge. Anton is condensed, so this still reads far larger than
     the old 116px Inter did. */
  font-size: 88px;
  /* Anton ships a single 400 weight. Asking for 900 here would make the
     browser synthesise a fake bold on top of an already-heavy face. */
  font-weight: 400;
  line-height: 0.88;
  letter-spacing: 0.005em;
  margin: 0;
  text-transform: uppercase;
  font-family: Anton, 'Arial Narrow Bold', sans-serif;
  /* No font-style: italic and no skewX(). Anton has no italic cut, so
     both were synthesising a slant — and stacking them applied it
     twice. A real condensed face upright reads better than a faked
     oblique. */
  /* Solid white + layered shadow for depth. Avoid background-clip:text;
     html2canvas renders that as transparent in the downloaded PNG. */
  color: #ffffff;
  text-shadow:
    0 2px 0 rgba(0, 0, 0, 0.25),
    0 6px 24px rgba(0, 0, 0, 0.55);
}
 
.matchup {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  margin-top: 28px;
  margin-bottom: 28px;
}
 
.team-row {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}
 
.vs-row {
  display: flex;
  align-items: center;
  gap: 16px;
  /* Sit the VS under the crest lane so the three rows read as one
     stack rather than three unrelated lines. */
  padding-left: 22px;
}
 
.vs-rule {
  height: 3px;
  flex: 1;
  border-radius: 2px;
  opacity: 0.55;
}
 
.panel-scorers {
  position: relative;
  z-index: 1;
  margin-bottom: 28px;
}
 
.crest {
  width: 86px;
  height: 86px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
 
.crest-filled {
  background: rgba(255, 255, 255, 0.96);
  overflow: hidden;
}
 
.crest-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.5));
}
 
.crest-initials {
  font-size: 40px;
  font-weight: 800;
  color: #0f172a;
}
 
.team-name {
  font-family: Anton, 'Arial Narrow Bold', sans-serif;
  font-weight: 400;
  font-size: 40px;
  line-height: 1.02;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  min-width: 0;
  word-break: break-word;
}
 
.vs {
  /* Anton at a big optical size, in the accent, is the "cooler VS" —
     a condensed display cut carrying color, rather than bold Inter. */
  font-family: Anton, 'Arial Narrow Bold', sans-serif;
  font-weight: 400;
  font-size: 46px;
  line-height: 1;
  letter-spacing: 0.06em;
  flex-shrink: 0;
}
 
.score {
  font-size: 56px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: #ffffff;
  white-space: nowrap;
}
 
.footer-band {
  /* Flat accent, set inline from accentColor so the band tracks the
     club's brand color. Previously a fixed red gradient, which both
     ignored the clubs and dated the card. */
  /* Runs out past the panel as a banner across the photo. The tear now
     ends far to the left at the bottom, so the band no longer has to
     reserve a wide right padding to stay inside the torn shape — it
     deliberately overhangs instead, which also stops the date and handle
     wrapping in a narrow column. */
  margin: 24px -190px -24px -24px;
  padding: 18px 32px;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 700;
  letter-spacing: 0.04em;
  /* Soft drop shadow for lift. The inset white highlight went with the
     gradient — on a flat fill it just muddies the top edge. */
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}
 
.footer-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 20px;
  font-size: 21px;
}
 
.footer-date {
  text-transform: uppercase;
  white-space: nowrap;
}
 
.footer-handle {
  font-size: 21px;
  white-space: nowrap;
}
 
.footer-tagline {
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.04em;
  /* Inherit the band's accent-aware text color rather than assuming
     white — the band is light when the accent is light. */
  color: inherit;
  opacity: 0.9;
}
 
.photo,
.photo-fallback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}
 
.photo {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
 
.photo-fallback {
  background:
    radial-gradient(
      circle at 30% 30%,
      rgba(59, 130, 246, 0.4),
      transparent 55%
    ),
    radial-gradient(
      circle at 70% 70%,
      rgba(239, 68, 68, 0.35),
      transparent 55%
    ),
    linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
}
</style>