Harmony Library Developer Reference
A source-level map of library/harmony/index.html and
library/harmony/harmony-library.js: compact manifest, deterministic generation,
schemes, state, rendering, exports, sharing, saved items, UI chrome and validation.
Overview
A source-level map of library/harmony/index.html and library/harmony/harmony-library.js : compact manifest, deterministic generation, schemes, state, rendering, exports, sharing, saved items, UI chrome and validation.
1. Runtime overview
+Harmony Library is a static page plus an ESM browser runtime. The page shell declares SEO, structured data, application containers, filters, tabs and shared Auric Artisan UI chrome. The runtime fetches a compact deterministic manifest, regenerates all harmonies on load, enriches them with color science data and powers Inspect, Theory, Accessibility, Stats, Export and Saved.
- Page shell:
library/harmony/index.html. - Runtime:
library/harmony/harmony-library.js. - Data URL:
/data/harmony-db/harmonies.json. - Saved key:
aa.harmony.saved. - Identify script:
library/harmony/harmony-identify.js. - Share type:
harmony. - Workspace domain:
harmony.
2. File and dependency map
+| File | Role |
|---|---|
library/harmony/index.html |
HTML route, SEO, JSON-LD, application containers, tabs, filters and includes. |
library/harmony/harmony-library.js |
ESM runtime for virtual harmony generation, filtering, rendering, inspection, export, save and share. |
data/harmony-db/harmonies.json |
Compact deterministic manifest for 8,192 harmonies. |
library/harmony/harmony-identify.js |
The “What harmony is this?” panel. Exports identify(manifest,
hexes), parses input with library/color/color-parse.js and reads
the same manifest; api/lib/handlers/harmony-library.js runs the same
matcher for POST /v1/harmony/identify. |
js/library/page-mirror.js |
Mirrors saved harmonies into the Library workspace. |
js/library/share/dialog.js |
Opens the share dialog for harmony payloads. |
js/library/share/router.js |
Registers the harmony share handler and hydrates shared harmony ids.
|
js/library/tokens/dialog.js |
Opens the design-token export dialog. |
js/library/tokens/index.js |
Provides tokensFromSwatchList() for selected-harmony token output. |
/js/unified.js |
Shared site behavior for includes, legal sections, cursor, loader and page chrome. |
3. Page shell, SEO and UI Chrome
+- Canonical:
https://auricartisan.com/library/harmony/. - Preload:
/data/harmony-db/harmonies.json. - Structured data: ImageObject, CollectionPage and BreadcrumbList.
- Shared styles: main, unified, dark-mode and harmony-library CSS.
- Route script:
/js/generated-inline/f89b771545ccd909c69c.js. - Chrome: header, time, announcement, custom cursor, scroll rail, loader, eye-rest panel, footer, idle layer and generated inline scripts.
- Application panels: Library, Inspect, Theory, Accessibility, Stats, Export and Saved.
4. DOM contract
+| Group | Important IDs |
|---|---|
| Identify | hlib-id-colors, hlib-id-add,
hlib-id-run, hlib-id-out,
hlib-hero-count |
| Search | hlib-search, hlib-result-search,
hlib-result-clear, hlib-shuffle,
hlib-random |
| Tabs and panels | .anz-tab-btn, .anz-panel, h-library,
h-inspect, h-theory, h-accessibility,
h-stats, h-export, h-saved |
| Filters | hlib-filter-hue, hlib-filter-chroma,
hlib-filter-light, hlib-filter-method,
hlib-filter-family, hlib-sort,
hlib-reset, hlib-export-visible |
| Library grid | hlib-loading, hlib-grid,
hlib-tab-library-badge, hlib-page-info,
hlib-scroll-top, hlib-tab-saved-badge |
| Advanced content | hlib-inspect-empty, hlib-inspect,
hlib-theory, hlib-accessibility,
hlib-stats, hlib-export, hlib-saved,
hlib-toast |
5. Manifest contract
+
loadData() fetches DATA_URL with cache: "force-cache".
Expanded arrays are rejected because this route is designed as a compact virtual viewer.
{
"schema": "aa.harmony-db.compact.v1",
"format": "deterministic-harmony-gen-manifest",
"source": "@auric-artisan/harmony-gen",
"count": 8192,
"seed": 137,
"batch_size": 1024,
"batch_seed_stride": 2654435761,
"methods": ["complementary", "split_complementary", "triadic"],
"color_count_by_method": {},
"families_by_method": {},
"canonical_angles": {},
"method_descriptions": {}
}
Production data must include all 23 methods plus family, color count, canonical angle and description maps. Those maps drive UI labels, filters and theory details.
6. Virtual Harmony Generation
+nextXor()advances a xorshift integer state.batchSeed(batch)computesseed + batch * batch_seed_stride.harmonyId(index)returnshar_plus the base-36 index.indexFromHarmonyId(id)acceptshar_...ids or numeric strings.methodForIndex(index)assigns methods byindex % methods.length.baseSeedForIndex(index)derives base hue, saturation, lightness and method.SCHEMEScontains the browser-side implementations for all harmony methods.enrichHarmony()computes roles, HEX, RGB, HSL, Lab, OKLCH, family, base data, Delta E, entropy, contrast matrix and adherence score.
loadData() materializes all 8,192 harmonies into state.all; the
lookup cache state.harmonyCache keeps up to 1,200 of them for id lookups.
7. State and load sequence
+{
dataset: null,
count: 0,
page: 0,
all: [],
filteredCount: 0,
visibleHarmonies: [],
activeHarmony: null,
exactSearchIndex: null,
harmonyCache: new Map(),
panelsRendered: {
theory: false,
stats: false,
accessibility: false,
export: false,
saved: false
},
progress: {
browse: false,
inspect: false,
theory: false,
accessibility: false,
export: false
}
}
- Resolve DOM ids into
els. - Attach event listeners for search, filters, cards, exports, tabs and the back-to-top button.
- Call
loadData(). - Fetch and normalize the deterministic manifest.
- Populate method filter options.
- Materialize every harmony into
state.alland render the virtual grid. - Render saved panel state and register the
harmonyshare handler.
8. Color science helpers
+hslToRgb()andrgbToHsl()bridge scheme geometry and rendered color data.rgbToLab()computes CIE Lab values for inspection and Delta E average.rgbToOklab()andrgbToOklch()compute perceptual lightness, chroma and hue.contrastRatio()computes WCAG-style contrast between colors.dominantHue(),hueSpread(),avgLightness()andavgChroma()drive filters and stats.deltaEAvg(),paletteEntropy()andadherenceScore()drive Inspect, Theory and Stats panels.roleForIndex()androleLabel()convert scheme position into human-facing labels.
9. Filtering, sorting and scrolling
+| Feature | Runtime Rule |
|---|---|
| Exact id search | updateExactSearch() detects har_... or numeric input and
sets state.exactSearchIndex. |
| Method filter | localFilterAndSort() keeps harmonies whose method equals the
selected method, alongside the family filter. |
| Random sort | Shuffle sets the sort to random, which shuffles the whole filtered set. |
| Local search | HEX, method, family and harmony id terms filter state.all unless an
exact id was found. |
| Local filters | Hue, chroma, lightness and family filters run over all materialized harmonies. |
| Local sort | Sorts the filtered set by lightness, chroma, hue, color count or random order. |
Search is debounced at 90 ms. Filter and sort changes call applyFilters(), which
calls renderPage().
10. Rendering and interaction model
+harmonyCardInner()builds cards with swatches, harmony id, scheme badge, Inspect, Copy and Save controls.- Clicking a swatch copies that swatch HEX.
- Clicking Copy copies all harmony HEX values.
- Clicking Save toggles local saved state and workspace mirroring.
- Clicking the card body or Inspect calls
openInspect(harmony). - Keyboard Enter or Space on a focused card opens Inspect.
- Pressing / focuses search unless an input or textarea is already active.
11. Panel responsibilities
+| Panel | Function |
|---|---|
What harmony is this? |
Matches 2 to 12 colors against every method whose color_count_by_method
equals the color count: sorted hue offsets against canonical_angles,
with each color tried as the anchor. Fit is max(0, 1 - error / 60);
methods within 0.01 of the best fit are reported as ties. Also reports family, base
color, the worst and best WCAG pair and the next four candidates. |
Inspect |
Renders harmony strip, summary metrics, theory card, pair contrast list, per-color RGB, HSL, Lab, OKLCH and WCAG contrast plus selected export actions. |
Theory |
Summarizes visible harmonies by scheme, family, hue bucket, color count, adherence and chroma/lightness profile. |
Accessibility |
Computes any-AA harmonies, any-AAA harmonies, pair-level AA/AAA counts and all-pair AA candidates. |
Stats |
Builds histograms for average lightness, average chroma, hue spread, minimum pair contrast, adherence and colors per harmony. |
Export |
Shows selected-harmony copy/download buttons and bulk export buttons for the filtered results. |
Saved |
Reads local saved ids, materializes those harmonies and renders cards with a workspace link. |
12. Export system
+stripHarmony()returns id, method, family, base, colors and metadata.buildAse()creates an Adobe Swatch Exchange binary using RGB records.buildSvg()creates a 720 x 240 SVG strip with HEX and role labels.buildPng()creates a 960 x 360 canvas strip and downloads a PNG.- Selected CSS export writes a
:rootblock with--{harmony_id}-{role}variables. - Bulk CSV writes
harmony_id,method,family,color_count,base_hexandcolors. - Bulk Tailwind export writes a
module.exportsconfig fragment.
{
"harmony_id": "har_abc",
"method": "triadic",
"family": "polyadic",
"base": {
"hue": 210,
"saturation": 0.7,
"lightness": 0.55,
"hex": "#3388cc"
},
"colors": [
{
"role": "base",
"hex": "#3388cc",
"rgb": [51, 136, 204],
"hsl": [205, 0.6, 0.5],
"oklch": [0.62, 0.13, 245.1],
"lab": [55.2, -4.1, -42.5]
}
],
"metadata": {
"method": "triadic",
"family": "polyadic",
"color_count": 3,
"canonical_angles": [120, 240],
"adherence": 0.98
}
}
14. Accessibility and UX rules
+- The app container uses
role="application"and the search input is labelledaria-label="Search harmonies". - Tabs use
role="tablist",role="tab",aria-selectedandaria-controls. - Panels use
role="tabpanel"with matching labels. - The grid uses
aria-live="polite"so result changes can be announced. - The toast uses
role="status"andaria-live="polite". - Cards support keyboard activation with Enter and Space.
- All seven tabs are always available; there is no Simple or Advanced mode to hide them.
- The result counter
hlib-page-infousesrole="status"andaria-live="polite".
15. Performance, validation and maintenance
+- Keep manifest count, hero count, page metadata and docs aligned.
- Do not change
seed,batch_size,batch_seed_strideor method order without treating harmony ids as migrated data. - Keep package algorithm logic and browser
SCHEMESimplementations synchronized. - Update docs when hue buckets, chroma thresholds, lightness thresholds, families or sort modes change.
- Validate clipboard, ASE, SVG, PNG and URL object cleanup when changing exports.
- Check localStorage migration before changing
SAVED_KEYor saved id format. - After documentation changes, regenerate documentation discovery, feeds, sitemaps, PWA cache and search index.
node scripts/generate-discovery.mjs
node scripts/generate-pwa-cache-manifest.mjs
node search/client/build-index.js
For user-facing workflow details, see the Harmony Library User Guide. For generator internals, see the Harmony Gen Developer Reference.