nutrifyi-embed
v1.1.0
Published
Embed NutriFYI widgets — food nutrition facts, BMI calculator, macro badges. 15,236 foods, USDA data. Zero dependencies, Shadow DOM, 4 themes.
Maintainers
Readme
nutrifyi-embed
Embed NutriFYI widgets — foods, 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, clean), and live data from the NutriFYI database.
Every widget includes a "Powered by NutriFYI" backlink and a medical disclaimer directing readers to consult healthcare professionals.
Try the interactive widget builder at widget.nutrifyi.com
⚕️ Medical Disclaimer: All Health FYI widgets include an educational disclaimer. This information is for educational purposes only and should not replace professional medical advice.
Quick Start
<!-- Place widget div where you want it to appear -->
<div data-nutrifyi="entity" data-slug="foods" data-theme="light"></div>
<!-- Load the embed script once, anywhere on the page -->
<script src="https://cdn.jsdelivr.net/npm/nutrifyi-embed@1/dist/embed.min.js"></script>That's it. The widget fetches data from the NutriFYI API and renders with full style isolation.
Widget Types
| Type | Usage | Description |
|------|-------|-------------|
| entity | <div data-nutrifyi="entity" data-slug="..."></div> | Entity detail card |
| glossary | <div data-nutrifyi="glossary" data-slug="..."></div> | Glossary term definition |
| guide | <div data-nutrifyi="guide" data-slug="..."></div> | Guide summary card |
| search | <div data-nutrifyi="search" data-slug="..."></div> | Search box |
| compare | <div data-nutrifyi="compare" data-slug="..."></div> | Side-by-side comparison |
| faq | <div data-nutrifyi="faq" data-slug="..."></div> | FAQ accordion |
| bmi-calculator | <div data-nutrifyi="bmi-calculator" data-slug="..."></div> | Interactive BMI calculator — fully offline |
| nutrition-label | <div data-nutrifyi="nutrition-label" data-slug="..."></div> | USDA-style nutrition facts label |
| macro-badge | <div data-nutrifyi="macro-badge" data-slug="..."></div> | Inline macronutrient badge |
Widget Options
| Attribute | Values | Default | Description |
|-----------|--------|---------|-------------|
| data-nutrifyi | entity, compare, glossary, guide, search, faq, [tools] | required | Widget type |
| data-slug | e.g. "foods" | — | Entity slug from the NutriFYI database |
| data-theme | light, dark, sepia, auto | light | Visual theme (auto follows OS preference) |
| data-style-variant | modern, clean | modern | Widget design style |
| data-size | default, compact, large | default | Widget size |
| data-placeholder | any string | "Search Foods..." | Search box placeholder |
Themes
<!-- Light (default) -->
<div data-nutrifyi="entity" data-slug="foods" data-theme="light"></div>
<!-- Dark -->
<div data-nutrifyi="entity" data-slug="foods" data-theme="dark"></div>
<!-- Sepia -->
<div data-nutrifyi="entity" data-slug="foods" data-theme="sepia"></div>
<!-- Auto — follows OS dark/light preference -->
<div data-nutrifyi="entity" data-slug="foods" data-theme="auto"></div>Styles
<!-- Modern (default) — clean lines, rounded corners, accent gradients -->
<div data-nutrifyi="entity" data-slug="foods" data-style-variant="modern"></div>
<!-- Clean — minimal borders, utility-focused, data-first aesthetic -->
<div data-nutrifyi="entity" data-slug="foods" data-style-variant="clean"></div>Web Components (Custom Elements)
As an alternative to data-* attributes, you can use native HTML custom elements:
<!-- Custom element form -->
<nutrifyi-entity slug="foods" theme="light"></nutrifyi-entity>
<nutrifyi-compare slugs="foods,other-slug"></nutrifyi-compare>
<nutrifyi-search placeholder="Search Foods..."></nutrifyi-search>
<script src="https://cdn.jsdelivr.net/npm/nutrifyi-embed@1/dist/embed.min.js"></script>Use style-variant (not style) to avoid conflicts with the HTML reserved style attribute.
CDN Options
jsDelivr (recommended — global CDN, auto-updates with npm)
<script src="https://cdn.jsdelivr.net/npm/nutrifyi-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 nutrifyi-embedimport 'nutrifyi-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 Clean (minimal, data-first)
- 4 themes: Light, Dark, Sepia, Auto (OS preference detection)
- CORS: NutriFYI 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
- Medical Disclaimer: All widgets include an educational disclaimer footer
- Bundle size: Tree-shaken per site — only includes tools available on NutriFYI
Learn More
Visit nutrifyi.com — NutriFYI is a comprehensive foods reference with interactive tools, guides, and developer resources.
- API docs: nutrifyi.com/developers/
- Widget builder: widget.nutrifyi.com
- npm package: npmjs.com/package/nutrifyi-embed
- GitHub: github.com/fyipedia/nutrifyi-embed
Health FYI Family
Part of FYIPedia — open-source developer tools ecosystem. Health FYI covers anatomy, drugs, pharmacology, and nutrition. Hub: bodyfyi.com.
| Site | Domain | Focus | Package | |------|--------|-------|---------| | AnatomyFYI | anatomyfyi.com | 14,692 anatomical structures, body systems, regions | npm | | PillFYI | pillfyi.com | 4,934 FDA drugs, interactions, side effects | npm | | DrugFYI | drugfyi.com | 4,009 drugs, molecular formulas, pharmacology | npm | | NutriFYI | nutrifyi.com | 15,236 foods, USDA nutrition data, 12 diets | npm |
FYIPedia Developer Tools
| Package | PyPI | npm | Description | |---------|------|-----|-------------| | colorfyi | PyPI | npm | Color conversion, WCAG contrast, harmonies — colorfyi.com | | emojifyi | PyPI | npm | Emoji encoding & metadata for 3,953 emojis — emojifyi.com | | unitfyi | PyPI | npm | Unit conversion, 220 units — unitfyi.com | | timefyi | PyPI | npm | Timezone ops & business hours — timefyi.com | | holidayfyi | PyPI | npm | Holiday dates & Easter calculation — holidayfyi.com | | fyipedia | PyPI | — | Unified CLI for all FYI tools — fyipedia.com |
License
MIT — see LICENSE.
Built with care by FYIPedia.
