npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

embedodon

v1.0.6

Published

A simple client-side script to render an Activity Stream (like from Mastodon)

Downloads

14

Readme

embedodon

Simple js to render a Mastodon user’s public toots.

Live example here: https://danieldickison.github.io/embedodon/

npm tests

simple example

<script type="module">
  import { EmbedodonElement } from 'https://cdn.jsdelivr.net/npm/embedodon@^1.0.6/dist/index.js'
  customElements.define('embed-odon', EmbedodonElement)
</script>
<embed-odon username="@[email protected]" class="standard"></embed-odon>

Note that custom element names must contain a hyphen. The "standard" class enables a default color scheme.

customize styles

Styles can be customized in several ways. Ordered from simplest to most complex but flexible, you can:

  1. Specify a set of custom CSS properties
  2. Apply styles using ::part selectors
  3. Override adoptedStyleSheets to style arbitrary shadowRoot elements
  4. Call Embedodon#render directly without using the EmbedodonElement web component

custom CSS properties

Custom CSS properties can be used to specify some basic colors. Make sure class="standard" is not included on the root element or else the standard colors will take precedence. You should specify all of these properties if you are not using class="standard":

| property | standard | definition | |----------|-------------|---------------------------| | --fg | black/white | foreground color for text | | --bg | white/black | background color for toot | | --link | blue | link text color | | --border | 1px gray | border for toot |

Example:

embed-odon {
  --fg: #603;
  --bg: #eee;
  --link: #b0b;
  --border: 2px dashed var(--fg);
}
@media (prefers-color-scheme: dark) {
  embed-odon {
    --fg: #d9b;
    --bg: #222;
    --link: #b6e;
  }
}

::part selectors

CSS ::part selectors can be used to target specific elements within the Embededon-rendered component from your page CSS. Exposed parts are:

| part | element | definition | |-----------|-------------|-------------------------------------------| | toot | <article> | container for each toot | | timestamp | <time> | timestamp link of toot | | content | <div> | text contents, containing <p>, etc | | media | <div> | media attachments, containing images, etc | | image | <img> | thumbnail image for media attachment | | video | <video> | inline video for media attachment | | progress | <progress>| progress bar while toots load |

Example:

embed-odon::part(timestamp) {
  font-style: italic;
  text-align: right;
}

override adoptedStyleSheets

Because the shadow root of EmbedodonElement is created with mode: 'open', its adoptedStyleSheets property can be overridden. You can choose to include or omit the base stylesheet, which is exposed as Embedodon.baseStyleSheet:

import { Embedodon, EmbedodonElement } from 'https://cdn.jsdelivr.net/npm/embedodon@^1.0.6/dist/index.js'
customElements.define('embed-odon', EmbedodonElement)
const styleSheet = new CSSStyleSheet()
styleSheet.replaceSync(`
  a {
    text-decoration-style: wavy;
  }
`)
for (const el of document.querySelectorAll('embed-odon')) {
  el.shadowRoot.adoptedStyleSheets = [Embedodon.baseStyleSheet, styleSheet]
}

call Embedodon#render directly

If you would like full control of styling the DOM elements rendered by Embedodon, you can forego EmbedodonElement and inject the results of calling the render method directly into your DOM:

import { Embedodon } from 'https://cdn.jsdelivr.net/npm/embedodon@^1.0.6/dist/index.js'
const container = document.getElementById('embedodon-container')
const embedodon = new Embedodon(username)
await embedodon.refresh()
container.append(...embedodon.render())