starfyi-embed
v1.1.0
Published
Embed StarFYI astronomy widgets — spectral badges, magnitude display, constellation cards. Zero dependencies, Shadow DOM, 4 themes.
Downloads
354
Maintainers
Readme
starfyi-embed
Embed StarFYI widgets — stars, glossary terms, interactive tools, and inline elements — on any website. 9 widget types, zero dependencies, Shadow DOM style isolation, 4 built-in themes (light, dark, sepia, auto), 2 styles (modern, technical), and live data from the StarFYI database.
Every widget includes a "Powered by StarFYI" backlink directing readers to the full reference.
Try the interactive widget builder at widget.starfyi.com
Quick Start
<!-- Place widget div where you want it to appear -->
<div data-starfyi="entity" data-slug="stars" data-theme="light"></div>
<!-- Load the embed script once, anywhere on the page -->
<script src="https://cdn.jsdelivr.net/npm/starfyi-embed@1/dist/embed.min.js"></script>That's it. The widget fetches data from the StarFYI API and renders with full style isolation.
Widget Types
| Type | Usage | Description |
|------|-------|-------------|
| entity | <div data-starfyi="entity" data-slug="..."></div> | Entity detail card — element, alloy, gem, star, or mineral |
| glossary | <div data-starfyi="glossary" data-slug="..."></div> | Glossary term definition with cross-references |
| guide | <div data-starfyi="guide" data-slug="..."></div> | Guide summary card with key takeaways |
| compare | <div data-starfyi="compare" data-slug="..."></div> | Side-by-side entity comparison |
| search | <div data-starfyi="search" data-slug="..."></div> | Search box linking to the full database |
| spectral-badge | <div data-starfyi="spectral-badge" data-slug="..."></div> | OBAFGKM spectral classification badge with color |
| magnitude-display | <div data-starfyi="magnitude-display" data-slug="..."></div> | Dual apparent + absolute magnitude display |
| constellation-card | <div data-starfyi="constellation-card" data-slug="..."></div> | Constellation info card with metadata |
| spectral-inline | <div data-starfyi="spectral-inline" data-slug="..."></div> | Colored OBAFGKM spectral pill |
Widget Options
| Attribute | Values | Default | Description |
|-----------|--------|---------|-------------|
| data-starfyi | entity, compare, glossary, guide, search, [tools] | required | Widget type |
| data-slug | e.g. "stars" | — | Entity slug from the StarFYI database |
| data-theme | light, dark, sepia, auto | light | Visual theme (auto follows OS preference) |
| data-styleVariant | modern, technical | modern | Widget design style |
| data-size | default, compact, large | default | Widget size |
| data-placeholder | any string | "Search Stars..." | Search box placeholder |
Themes
<!-- Light (default) -->
<div data-starfyi="entity" data-slug="stars" data-theme="light"></div>
<!-- Dark -->
<div data-starfyi="entity" data-slug="stars" data-theme="dark"></div>
<!-- Sepia -->
<div data-starfyi="entity" data-slug="stars" data-theme="sepia"></div>
<!-- Auto — follows OS dark/light preference -->
<div data-starfyi="entity" data-slug="stars" data-theme="auto"></div>Styles
<!-- Modern (default) — clean lines, rounded corners, accent gradients -->
<div data-starfyi="entity" data-slug="stars" data-styleVariant="modern"></div>
<!-- Technical — monospace type, grid overlays, laboratory aesthetic -->
<div data-starfyi="entity" data-slug="stars" data-styleVariant="technical"></div>Web Components (Custom Elements)
As an alternative to data-* attributes, you can use native HTML custom elements:
<!-- Custom element form -->
<starfyi-entity slug="stars" theme="light"></starfyi-entity>
<starfyi-compare slugs="stars,other-slug"></starfyi-compare>
<starfyi-search placeholder="Search Stars..."></starfyi-search>
<script src="https://cdn.jsdelivr.net/npm/starfyi-embed@1/dist/embed.min.js"></script>Use style-variant (not style) to avoid conflicts with the HTML reserved style attribute.
Examples
Entity Card
<div data-starfyi="entity" data-slug="stars" data-theme="light"></div>
<script src="https://cdn.jsdelivr.net/npm/starfyi-embed@1/dist/embed.min.js"></script>Side-by-Side Comparison
<div data-starfyi="compare" data-slugs="stars,other-slug"></div>
<script src="https://cdn.jsdelivr.net/npm/starfyi-embed@1/dist/embed.min.js"></script>Search Box
<div data-starfyi="search" data-placeholder="Search Stars..."></div>
<script src="https://cdn.jsdelivr.net/npm/starfyi-embed@1/dist/embed.min.js"></script>Glossary Term
<div data-starfyi="glossary" data-slug="example-term" data-theme="light"></div>
<script src="https://cdn.jsdelivr.net/npm/starfyi-embed@1/dist/embed.min.js"></script>CDN Options
jsDelivr (recommended — global CDN, auto-updates with npm)
<script src="https://cdn.jsdelivr.net/npm/starfyi-embed@1/dist/embed.min.js"></script>Specific version (production stability)
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/embed.min.js"></script>npm (for bundlers)
npm install starfyi-embedimport 'starfyi-embed';Technical Details
- Shadow DOM: Complete style isolation — no CSS conflicts with your site
- Zero dependencies: No jQuery, React, or any external library
- 2 styles: Modern (accent gradients) and Technical (monospace, lab aesthetic)
- 4 themes: Light, Dark, Sepia, Auto (OS preference detection)
- CORS: StarFYI API has CORS enabled for all origins
- MutationObserver: Works with dynamically added elements (SPAs)
- IntersectionObserver: Lazy loading — widgets only fetch when entering viewport (200px margin)
- Rich Snippets: DefinedTerm JSON-LD injected for glossary widgets
- Bundle size: Tree-shaken per site — only includes tools available on StarFYI
Learn More About Stars
Visit starfyi.com — StarFYI is a comprehensive stars reference with interactive tools, guides, and developer resources.
- API docs: starfyi.com/developers/
- Widget builder: widget.starfyi.com
- npm package: npmjs.com/package/starfyi-embed
- GitHub: github.com/fyipedia/starfyi-embed
Science FYI Family
Part of FYIPedia — open-source developer tools ecosystem. Science FYI covers chemistry, geology, astronomy, and materials science. Hub: labfyi.com.
| Site | Domain | Focus | Package | |------|--------|-------|---------| | ChemFYI | chemfyi.com | Periodic table, elements, compounds, reactions | npm | | AlloyFYI | alloyfyi.com | Metal alloys, compositions, properties, 6-axis ratings | npm | | GemFYI | gemfyi.com | Gemstones, Mohs hardness, optical properties, origins | npm | | StarFYI | starfyi.com | Stars, constellations, spectral classification, magnitudes | npm | | MineralFYI | mineralfyi.com | 6,215 minerals, crystal systems, Mohs hardness | npm |
License
MIT — see LICENSE.
Built with care by FYIPedia.
