Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include message card in Image Export so dark mode text is visible #652

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rjwignar
Copy link
Collaborator

@rjwignar rjwignar commented Jun 8, 2024

This fixes #651

The white text in the dark mode card body is camouflaged by the white background of html2canvas.

One solution to make this text visible is to include the entire card (which wraps the text) in the HTML sent to html2canvas:
Before (card body only, white text invisible):
message
After (entire card, white text appears as rendered inside card:
message

…d (as messageCard) instead of card body content (as messageContent)
@rjwignar
Copy link
Collaborator Author

rjwignar commented Jun 8, 2024

I must add that this change has a visual bug in which the background colours invert:
On Edge:
message
On Chrome:
message

On the Chrome screenshot you can see the message options menu didn't completely close.
I wonder if we should add a delay between clicking "Export as Image" and html2canvas taking a screenshot

@rjwignar rjwignar requested a review from menghif June 8, 2024 16:26
Copy link

cloudflare-workers-and-pages bot commented Jun 8, 2024

Deploying chatcraft-org with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0d8eaa3
Status: ✅  Deploy successful!
Preview URL: https://96c9de34.console-overthinker-dev.pages.dev
Branch Preview URL: https://issue-651.console-overthinker-dev.pages.dev

View logs

src/lib/utils.ts Outdated
windowWidth: element.scrollWidth,
windowHeight: element.scrollHeight,
});
return html2canvas(element, {});
Copy link
Collaborator Author

@rjwignar rjwignar Jun 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the options object is empty ({}) we can remove it from our code.

I'm wondering if we should replace it with a Partial object so maintainers know we can configure options for it, something like this (I'm not 100% on the TypeScript usage):

import { Options } from "html2canvas";
// ...
export const screenshotElement = (element: HTMLElement): Promise<Blob> => {
  return import("html2canvas")
    .then((module) => {
      const options: Partial<Options> = {};
      const html2canvas = module.default;
      return html2canvas(element, options);
    })
    .then(
    // ...
    );
};

@menghif
Copy link
Collaborator

menghif commented Jun 9, 2024

On the Chrome screenshot you can see the message options menu didn't completely close.
I wonder if we should add a delay between clicking "Export as Image" and html2canvas taking a screenshot

I tested this and I found the same problem you described on Firefox and Safari (surprisingly not on Chrome after many attempts). I think adding a delay is a good idea.

screenshot showing message option still open

@rjwignar
Copy link
Collaborator Author

rjwignar commented Jun 9, 2024

I think I fixed the color inversion by using a windowWidth of 2.5 * element.scrollWidth (I played around with this setting and found the inverted portion shrunk as I scaled the element.scrollWidth value until it eventually disappeared.

Although, a lot of the text is still pushed-down slightly (most noticeable at the avatar icon, although this already exists in production):
image

The screenshots don't look the best in light mode either:
message (3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export as Image doesn't work in dark mode
2 participants