Skip to content

A platform for community discussion. Free, open, simple.

2.8 KB
Raw Blame
$max_image_height: 150px;
$max_video_height: 250px;

.chat-message {
  // append selectors to set images to a
  // max height of $max_image_height
  .onebox
    img:not(
      .ytp-thumbnail-image,
      .onebox-avatar-inline,
      .discourse-event-onebox__image
    ),
  img.onebox,
  .chat-uploads img,
  p img,
  aside.onebox .onebox-body .aspect-image-full-size,
  aside.onebox .onebox-body .aspect-image-full-size img,
  .chat-message-text p img:not(.emoji) {
    object-fit: contain;
    max-height: $max_image_height;
    max-width: 100%;
    width: unset;
    overflow: hidden;
  }

  iframe.youtube-onebox {
    max-width: calc(#{$max_video_height} / 9 * 16);
  }

  .onebox {
    &:not(img) {
      container-type: inline-size;
    }

    .thumbnail {
      &.onebox-avatar {
        max-height: 100px;
        width: 20%;
        max-width: 60px;
        margin-right: 0.5rem;
      }
    }

    .onebox-body .aspect-image {
      max-width: 50%;
    }
  }

  // Match the maximum width used in posts
  aside.onebox {
    max-width: var(--topic-body-width);
  }

  // Keeps event banner images compact in chat; cropped images lose more and letterboxed ones get wider bars
  .discourse-event-onebox.--banner-image .discourse-event-onebox__image {
    max-height: 12rem;
  }

  .onebox:not(.githubpullrequest, .githubcommit, .githubissue) {
    @container (width < 400px) {
      .onebox-body {
        display: flex;
        flex-direction: column;

        .thumbnail.onebox-avatar {
          display: none;
          max-width: 20%;
          margin-right: 0.5rem;
        }

        .thumbnail:not(.discourse-event-onebox__image) {
          max-width: 100% !important;
          margin: 0;
        }

        .aspect-image {
          margin-right: 0;
          max-width: 100%;

          + h3 {
            margin-top: 0.25rem;
          }
        }

        h3 {
          margin-block: 0.75rem 0;
        }

        p {
          margin-top: 0.5rem;
        }
      }
    }
  }

  .youtube-onebox {
    margin-top: var(--space-1);
  }

  .onebox.twitterstatus {
    max-width: 500px;

    .tweet-images {
      .tweet-video {
        height: calc(576px / (var(--aspect-ratio)));
        max-height: 400px;
      }
    }

    .aspect-image-full-size {
      object-fit: initial;
      max-height: 400px;

      .tweet-image {
        object-fit: initial;
        max-height: 400px;
      }
    }

    .thumbnail.onebox-avatar {
      max-width: 38px;
      margin-right: var(--space-2);
      margin-top: var(--space-1);
    }
  }

  .chat-message-collapser
    .chat-message-collapser-header
    + div
    .chat-message-collapser-lazy-video {
    object-fit: contain;
    max-height: $max_video_height;
    max-width: calc(#{$max_video_height} / 9 * 16);
    margin-top: var(--space-2);

    &:has(div[data-provider-name="tiktok"]) {
      max-height: unset;
    }
  }
}