@micropasts/authority-card
v0.1.0
Published
Zero-dependency JavaScript Web Components for resolving and rendering Linked Open Data authority records (Pleiades, Wikidata, Getty AAT/TGN/ULAN, Nomisma) with Shadow DOM and Tailwind CSS support.
Maintainers
Readme
@micropasts/authority-card
Zero-dependency JavaScript Web Components that turn persistent Linked Open Data URIs (Pleiades, Wikidata, Getty AAT/TGN/ULAN, Nomisma.org, or custom endpoints) into cached hover popovers and synchronized inspector panels.
Available in two flavors:
<authority-card>— Encapsulated Shadow DOM component with CSS custom properties,::part()selectors, and custom HTML template hooks.<authority-card-tw>— Light-DOM component styled with Tailwind CSS utility classes anddark:variants.
Table of Contents
- Features
- Project Structure
- Installation & Build
- Quick Start
- Customizing Styles
- Registering Custom Adapters & Seeding Offline Data
- Deploying the Demo to GitHub Pages (
docs/) - License
Features
- Pure ES2022 JavaScript: Written in clean vanilla JavaScript without TypeScript compilation, framework lock-in, or runtime dependencies.
- Built-in LOD Adapters: Resolves URIs from Pleiades, Wikidata, Getty Vocabularies (AAT, TGN, ULAN), and Nomisma.org into a consistent display model.
- Request Deduplication & Caching: Concurrent or repeated lookups for the same URI share a single in-flight promise and cache results in memory.
- Offline / Static Hydration: Pre-seed records from embedded JSON-LD or Linked Art
@graphpayloads viaseedRecords()so static sites can render without external network requests. - Cross-Component Event Bus: Emits and listens for
heritage:selectCustomEvents so maps, timelines, graphs, and side panels stay synchronized.
Project Structure
authority-card/
├── .github/
│ └── workflows/
│ └── pages.yml # Builds dist + docs/ and deploys docs/ to GitHub Pages
├── scripts/
│ └── build.js # Bundles dist/ and builds self-contained docs/ output
├── src/
│ ├── core.js # Cache, deduplication, event bus, LOD adapters
│ ├── shadow.js # Encapsulated <authority-card> (CSS vars + ::part + templates)
│ ├── tailwind.js # Light-DOM <authority-card-tw> (Tailwind utility classes)
│ ├── demo.html # Source HTML template for the demo
│ └── index.js # Package entry point
├── docs/ # Generated GitHub Pages output (index.html + authority-card.esm.js)
├── package.json
└── README.mdInstallation & Build
Install from npm:
npm install @micropasts/authority-cardOr build locally from source with zero external build dependencies:
npm run buildRunning npm run build generates:
dist/authority-card.esm.js— Combined ES Module bundledist/authority-card.iife.js— Global<script>bundle (window.AuthorityCardLib)docs/index.htmlanddocs/authority-card.esm.js— Self-contained GitHub Pages demo
To build and serve the demo locally:
npm run devQuick Start
1. Tailwind CSS Version (<authority-card-tw>)
<script type="module" src="./dist/authority-card.esm.js"></script>
<p>
Excavated at
<authority-card-tw uri="https://pleiades.stoa.org/places/79739">
Verulamium
</authority-card-tw>,
a silver
<authority-card-tw uri="https://nomisma.org/id/denarius">
denarius
</authority-card-tw>
of
<authority-card-tw uri="http://www.wikidata.org/entity/Q1405">
Augustus
</authority-card-tw>.
</p>2. Shadow DOM Version (<authority-card>)
Works without Tailwind CSS on any static page, CMS, or scholarly edition:
<script type="module" src="./dist/authority-card.esm.js"></script>
<authority-card uri="http://vocab.getty.edu/aat/300037222">
denarii
</authority-card>3. Synchronized Inspector Panel Mode
Mount a persistent panel that updates whenever any inline card (or external map, timeline, or graph component) broadcasts heritage:select:
<authority-card-tw mode="panel" listen="heritage:select"></authority-card-tw>
<script type="module">
import { emitSelect } from '@micropasts/authority-card';
// Example: triggered when a user selects a site on a map or timeline
emitSelect(window, 'https://pleiades.stoa.org/places/79739');
</script>Customizing Styles
Tailwind Utility Overrides (<authority-card-tw>)
Pass trigger-class and card-class attributes on individual instances:
<authority-card-tw
uri="http://vocab.getty.edu/aat/300037222"
trigger-class="text-amber-700 font-semibold"
card-class="border-amber-500 shadow-2xl">
denarii
</authority-card-tw>Or override the shared class dictionary globally at application startup:
import { AuthorityCardTailwind } from '@micropasts/authority-card';
AuthorityCardTailwind.classes.popover =
'absolute left-0 top-full mt-2 z-50 w-96 rounded-none border-2 border-black bg-white p-4 shadow-lg';Shadow DOM Tokens & ::part() (<authority-card>)
Customize CSS custom properties or style exposed ::part() elements directly from your stylesheet:
authority-card.custom-theme {
--ac-bg: #1c1917;
--ac-fg: #fafaf9;
--ac-muted: #a8a29e;
--ac-border: #b45309;
--ac-radius: 0.25rem;
--ac-width: 360px;
}
authority-card.custom-theme::part(title) {
font-family: Georgia, serif;
color: #fbbf24;
}Full Markup Template Override
Replace the card inner markup while keeping all caching, deduplication, and adapter logic:
import { AuthorityCard } from '@micropasts/authority-card';
AuthorityCard.setTemplate((record, esc) => `
<div class="my-card">
<strong>${esc(record.label)}</strong> (${esc(record.source)})
<p>${esc(record.scopeNote)}</p>
</div>
`);Registering Custom Adapters & Seeding Offline Data
import { registerAdapter, seedRecords } from '@micropasts/authority-card';
// 1. Register a custom authority resolver
registerAdapter({
name: 'British Museum',
badgeColor: '#1e3a8a',
match: (uri) => /collection\.britishmuseum\.org\/id\/object\/([^/?#]+)/i.exec(uri),
async fetch([, id], uri) {
const res = await fetch(`${uri}.json`);
const data = await res.json();
return {
id,
label: data._label || id,
subtitle: 'British Museum Collection',
scopeNote: data.referred_to_by?.[0]?.content || '',
};
},
});
// 2. Seed records from embedded JSON-LD (zero network requests)
seedRecords({
'https://pleiades.stoa.org/places/79739': {
source: 'Pleiades',
badgeColor: '#15803d',
label: 'Verulamium',
subtitle: 'Ancient Roman Municipium',
scopeNote: 'Major Roman town near modern St Albans, Hertfordshire.',
meta: [{ label: 'Coordinates', value: '51.7519°, -0.3558°' }],
},
});Deploying the Demo to GitHub Pages (docs/)
npm run build outputs the demo site to docs/index.html alongside docs/authority-card.esm.js.
- Push your repository to GitHub with
mainas your default branch. - In Settings → Pages, choose either:
- Source: GitHub Actions (uses
.github/workflows/pages.ymlto runnpm run buildand deploy./docs), or - Source: Deploy from a branch → select
mainand/docsafter runningnpm run build.
- Source: GitHub Actions (uses
License
MIT
