Skip to content

About

A small javascript thing to resolve URIs and create cards

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

Repository files navigation

@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 and dark: variants.

Table of Contents


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 @graph payloads via seedRecords() so static sites can render without external network requests.
  • Viewport-aware popovers: Cards shift or flip to stay on screen, and scroll internally if they are taller than the viewport. Browsers supporting the Popover API also display cards above clipping containers.
  • Cross-Component Event Bus: Emits and listens for heritage:select CustomEvents 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
│   ├── position.js            # Shared viewport-aware popover positioning
│   ├── 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.md

Installation & Build

Install from npm:

npm install @micropasts/authority-card

Or build locally from source with zero external build dependencies:

npm run build

Running npm run build generates:

  • dist/authority-card.esm.js — Combined ES Module bundle
  • dist/authority-card.iife.js — Global <script> bundle (window.AuthorityCardLib)
  • docs/index.html and docs/authority-card.esm.js — Self-contained GitHub Pages demo

To build and serve the demo locally:

npm run dev

Quick 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.

  1. Push your repository to GitHub with main as your default branch.
  2. In Settings → Pages, choose either:
    • Source: GitHub Actions (uses .github/workflows/pages.yml to run npm run build and deploy ./docs), or
    • Source: Deploy from a branch → select main and /docs after running npm run build.

License

MIT

About

A small javascript thing to resolve URIs and create cards

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages