Some improvement ideas #2
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Usually I like to keep PRs scoped smaller, but I had some ideas to enhance/improve the initial implementation. Not all the changes herein are intentional.
First off, I thought that we could support both types of toot URLs (see code for examples). To do this, I am using the URL Pattern API which is only supported in Chromium. We could always use regex to do this. I’m getting the toot ID to just make API url for it. You’ll notice I was lazy with my TypeScript here.
Second, I thought we could use
ElementInternalsto improve the accessibility. I didn’t check what Tweet embeds do which might have been a better guide. Instead, I used a Tweet/Toot from the timeline as my reference point. Both use the<article>element and corresponding role and then create the label from selected text content inside of the post.Third, I did move the setting of the
ShadowRoot.innerHTMLto the#rendermethod, since I just found it nicer when adding all of the content. We could always move it back.Finally, there’s an initial flash of unpleasant styling when none of the content exists. I used a
CustomStateSetpseudo-selector (i.e.--loading) to avoid this. We could always repurpose this for an actual loading state.Anyway, I thought I’d make a draft out of this. I could always break this into smaller PRs as well. I made a pen where I was experimenting with some styling: https://codepen.io/knowler/pen/oNMvYwm. I only made progress on the dark mode styling. The pen has slightly different code than this PR.