Skip to main content
Auric Artisan · Documentation

Gradient Library Developer Reference

A source-level map of library/gradient/index.html and library/gradient/gradient-library.js: route shell, generated data, runtime state, filters, panels, exports, sharing, saved items, UI chrome and validation.

Updated: May 26, 2026 Route: /library/gradient/ Runtime: gradient-library.js Author: Chirag Bansal
Back to Documentation Auric Artisan Home

Overview

A source-level map of library/gradient/index.html and library/gradient/gradient-library.js : route shell, generated data, runtime state, filters, panels, exports, sharing, saved items, UI chrome and validation.

Table of contents

  1. 1. Runtime overview
  2. 2. File and dependency map
  3. 3. Page shell, SEO and UI Chrome
  4. 4. DOM contract
  5. 5. Data contract
  6. 6. State and load sequence
  7. 7. Color and sampling helpers
  8. 8. Filtering, sorting and scrolling
  9. 9. Rendering and interaction model
  10. 10. Panel responsibilities
  11. 11. Export system
  12. 12. Save, share and token dialog
  13. 13. Accessibility and UX rules
  14. 14. Performance notes
  15. 15. Validation and maintenance

1. Runtime overview

+

Gradient Library is a static HTML route plus an ESM browser runtime. The page shell declares SEO, structured data, application containers, SVG color-vision filters, tabs, form controls and shared Auric Artisan UI chrome. The runtime fetches a compact index of the generated data, normalizes each gradient, renders the card grid and powers advanced analysis panels.

  • Page shell: library/gradient/index.html.
  • Runtime: library/gradient/gradient-library.js.
  • Data URL: /data/gradient-gen/gradient-index.json, with detail shards at /data/gradient-gen/detail/NN.json.
  • Saved key: aa.gradient.saved.
  • Share type: gradient.
  • Workspace domain: gradient.

2. File and dependency map

+
File Role
library/gradient/index.html HTML route, metadata, JSON-LD, application containers, filters, panels and includes.
library/gradient/gradient-library.js ESM runtime for data loading, filtering, rendering, inspection, export, save and share behavior.
data/gradient-gen/gradients.json Site-compatible JSON array with all 8,192 generated gradients. The page no longer loads it: scripts/generate-gradient-index.mjs derives gradient-index.json and the 32 detail/NN.json shards from it.
data/gradient-gen/gradients.ndjson One-gradient-per-line companion dataset for streaming and external processing.
data/gradient-gen/index.json Generation manifest with count, seed, methods, interpolation spaces, easing methods, score range and stop count range.
js/library/page-mirror.js Mirrors saved gradients into the Library workspace.
js/library/share/dialog.js Opens the share dialog for gradient payloads.
js/library/share/router.js Registers the gradient share handler and hydrates shared ids.
js/library/tokens/dialog.js Opens the design-token export dialog.
js/library/tokens/index.js Provides tokensFromGradient() for composite and stop token output.
/js/unified.js Shared site behavior for includes, legal sections, cursor, loader, idle layer and page chrome.

3. Page shell, SEO and UI Chrome

+
  • Canonical: https://auricartisan.com/library/gradient/.
  • Preload: /data/gradient-gen/gradient-index.json as fetch.
  • Structured data: Dataset, CollectionPage, ImageObject and BreadcrumbList.
  • Shared styles: main, unified, dark-mode and gradient-library CSS.
  • Route inline script: /js/generated-inline/771583026d107068e662.js.
  • Chrome: header, time, announcement, custom cursor, scroll rail, loader, eye-rest panel, footer, idle layer and generated scripts.
  • Application panels: Library, Inspect, Vision, Accessibility, Pair, Tags, Stats, Export and Saved.

The route also defines SVG filters for deuteranopia, protanopia, tritanopia, achromatopsia and low-vision previews. Those filter ids are referenced from the Vision panel.

4. DOM contract

+
Group Important IDs
Gradient check (gradient-check.js) glib-check-stops, glib-check-add, glib-check-run, glib-check-out
Search glib-search, glib-result-search, glib-result-clear, glib-shuffle, glib-random
Tabs and badges .anz-tab-btn, .anz-panel, glib-tab-library-badge, glib-tab-saved-badge
Filters glib-filter-method, glib-filter-scheme, glib-filter-complexity, glib-filter-stops, glib-filter-space, glib-filter-easing, glib-filter-score, glib-filter-banding, glib-sort, glib-reset
Library grid glib-loading, glib-grid, glib-export-visible, glib-page-info, glib-scroll-top, glib-hero-count
Advanced content glib-inspect-empty, glib-inspect, glib-vision, glib-accessibility, glib-pair, glib-tags, glib-stats, glib-export, glib-saved, glib-toast

5. Data contract

+

loadData() fetches INDEX_URL, /data/gradient-gen/gradient-index.json, with cache: "force-cache". fromIndexRow() rebuilds each row into the shape below, deriving OKLCH from the HEX. Sample count, complexity score, Delta E mean, uniformity and seed are not in the index: fullGradient() fetches them from /data/gradient-gen/detail/NN.json, one shard per 256 gradients, when a gradient is opened.

{
  "angle": 0,
  "type": "linear",
  "stops": [
    {
      "pos": 0,
      "hex": "#723C2D",
      "oklch": [0.4204, 0.08, 36.4]
    },
    {
      "pos": 1,
      "hex": "#7B3600",
      "oklch": [0.4194, 0.1115, 49.6]
    }
  ],
  "name": "Aurora Simple #00001",
  "meta": {
    "scheme": "Aurora",
    "method": "aurora",
    "complexity": "simple",
    "stops": 2,
    "sample_count": 96,
    "interpolation_space": "oklch-short",
    "easing": "linear",
    "score": 0.4045,
    "complexity_score": 0.1005,
    "deltaE_mean": 0.1732,
    "uniformity": 0.0391,
    "banding": "smooth",
    "css_preview": "linear-gradient(0deg, #723c2d 0%, #7b3600 100%)",
    "source": "@auric-artisan/gradient-gen",
    "seed": 20260514
  }
}

normalizeGradient() assigns a one-based _id, stores generated CSS in _css, sorts and clamps stops, uppercases stop HEX values and computes internal search text, stop count, score, complexity score, dominant hue, average lightness, average chroma, minimum white contrast and minimum black contrast.

6. State and load sequence

+
{
  all: [],
  filtered: [],
  page: 0,
  active: null,
  pairText: "#ffffff",
  panelsRendered: {
    vision: false,
    accessibility: false,
    pair: false,
    tags: false,
    stats: false,
    export: false,
    saved: false
  },
  progress: {
    browse: false,
    inspect: false,
    vision: false,
    pair: false,
    export: false
  }
}
  1. Resolve DOM nodes into els.
  2. Attach search, filter, back-to-top, card, panel, export and pair listeners.
  3. Call setMode("advanced"), a no-op kept for the old mode buttons: every tab is visible.
  4. Call loadData().
  5. Normalize all gradient records and populate dynamic method, scheme, interpolation and easing filters.
  6. Hand the filtered set to the virtual grid, update badges, render Saved and register the gradient share handler.

7. Color and sampling helpers

+
  • parseHex(), rgbToHex() and relLuminance() power sampled color conversion and WCAG-style contrast.
  • contrastRatio() computes relative-luminance contrast for pairs.
  • textOn() chooses near-black (#111111) or white text at a relative luminance threshold of 0.45.
  • sortedStops() and cssFromStops() keep stop order and CSS output deterministic.
  • cssGradient() prefers meta.css_preview when available.
  • representativeStops() samples a manageable stop strip for dense gradients.
  • sampleGradient() linearly interpolates RGB across stops for accessibility and pair checks.
  • dominantHue() and averageStopValue() derive search and sort metrics from stop OKLCH values.
  • minContrastAgainst() samples 24 positions against a fixed text color.
  • adjacentStopContrast() checks contrast between neighboring stored stops.

The runtime does not re-run the generator. It analyzes the generated site-compatible output in the browser.

8. Filtering, sorting and scrolling

+
Feature Runtime Rule
Search Combines glib-search and glib-result-search, splits terms and requires every term to appear in _search.
Dynamic filters Method, scheme, interpolation and easing options are populated from state.all after data load.
Complexity Matches meta.complexity values: simple, detailed and extreme.
Stop count Filters on _stopCount using 2-4, 5-8, 9-16, 17-32 and 33+ buckets.
Score Top is _score >= 0.7, balanced is _score >= 0.55, wild is _score < 0.55.
Banding Maps low to smooth, medium to subtle-compression and high to visible-step-risk.
Sort Sorts by original order, score descending, complexity descending, stops descending, stops ascending, dominant hue or random.
Scrolling renderPage() hands state.filtered to createVirtualGrid() from js/library/virtual-grid.js, which keeps one screenful of cards in the DOM and writes the visible range to glib-page-info.

Search is debounced at 120 ms. Reset clears all filters, restores original sort and re-renders from the top of the grid.

9. Rendering and interaction model

+
  • renderGradientCard() builds a focusable card with preview, name, scheme, interpolation, representative stop strip, score chip, CSS action and Save action.
  • handleCardClick() routes card-level CSS copy, Save and selection actions.
  • selectGradient() sets state.active, renders Inspect, invalidates derived panels and marks the Inspect flow step complete.
  • Keyboard Enter or Space on a focused card opens Inspect.
  • Pressing / focuses the main search input unless an input or textarea is active.
  • Panel headers toggle a collapsed class on advanced cards for dense technical views.
  • setMode() no longer hides anything: every panel is reachable from its tab.

10. Panel responsibilities

+
Panel Function
Library Filters, sorts and renders gradient cards in a windowed, continuous scroll.
Inspect Renders hero preview, quick metrics, CSS, stop list, generator metrics and active export buttons.
Vision Applies SVG filters for normal, deuteranopia, protanopia, tritanopia, achromatopsia and low vision.
Accessibility Samples the active gradient, computes white, black, auto and adjacent-stop contrast values and renders 17 sampled stops.
Pair Lets users test a specific text color over the active gradient and reports minimum and average contrast.
Tags Counts methods, schemes, complexity levels, interpolation spaces, easing curves and banding labels. Tag clicks apply filters.
Stats Builds bar charts for methods, complexity, stop counts, interpolation, easing and score bands over the filtered set or full collection.
Export Shows selected-gradient exports and visible-set bulk export buttons.
Saved Reads saved ids, resolves them against state.all and renders saved cards with a workspace hint.

11. Export system

+
  • cleanGradient() returns angle, type, sorted stops, name and metadata for JSON export.
  • cssClassFor() writes a slugged .aa-gradient-... background class.
  • tailwindTokenFor() writes a quoted Tailwind-friendly token value.
  • gradientToSvg() creates a 1440 x 900 SVG with a linearGradient definition.
  • exportGradientPng() paints the gradient to a 1600 x 1000 canvas and downloads a PNG blob.
  • exportGradient() routes selected CSS copy, CSS file, JSON, SVG, Tailwind, PNG, share and token-dialog actions.
  • exportBulk() routes visible-set JSON, minified JSON, CSS, CSV and Tailwind output.
  • csvFor() writes id, name, type, angle, stops, scheme, method, complexity, interpolation, easing, score, complexity score, banding and CSS.
{
  "exported_at": "2026-05-26T00:00:00.000Z",
  "source": "Auric Artisan gradient-gen",
  "count": 48,
  "gradients": [
    {
      "angle": 0,
      "type": "linear",
      "stops": [
        {
          "pos": 0,
          "hex": "#723C2D",
          "oklch": [0.4204, 0.08, 36.4]
        }
      ],
      "name": "Aurora Simple #00001",
      "meta": {}
    }
  ]
}

12. Save, share and token dialog

+
  • getSavedIds() reads aa.gradient.saved and returns numeric ids.
  • toggleSaved(id) stores up to 240 ids and updates the card, Inspect and Saved panel state.
  • mirrorSave() stores domain gradient, asset type gradient, tool id library-gradient, gradient CSS, stops and payload.
  • mirrorRemove() removes the mirrored workspace item when a saved gradient is toggled off.
  • shareGradientLink() calls shareViaDialog() with type gradient.
  • registerShareHandler("gradient", hydrateFromSharedGradient) opens a matching gradient by id from shared payloads.
  • openTokensDialog() uses a slugged gradient name and tokensFromGradient() for the selected gradient.

Shared payloads include id, name, CSS, stops and method. Hydration resolves by numeric one-based id against state.all. If the source dataset order changes, old share ids may resolve to different gradients.

13. Accessibility and UX rules

+
  • The app container uses role="application".
  • Tabs use role="tablist", role="tab", aria-selected and aria-controls.
  • Panels use role="tabpanel" with matching labels.
  • The toast uses role="status" and aria-live="polite".
  • Cards support click plus keyboard activation with Enter and Space.
  • Vision filters are visual previews, while Accessibility and Pair provide numeric contrast support.

14. Performance notes

+
  • The compact index is fetched once with cache: "force-cache" and normalized in memory; a detail shard is fetched only when one of its gradients is opened.
  • The virtual grid keeps one screenful of cards in the DOM and recycles rows as you scroll.
  • Advanced panels render lazily when their tabs are selected.
  • Stats invalidate when filters change because the filtered set changes.
  • Accessibility and Pair sample the active gradient instead of every gradient.
  • SVG and PNG exports create object URLs and revoke them after download.
  • Large visible-set exports depend on the current filtered set; keep page interactions responsive before expanding export scope.

15. Validation and maintenance

+
  • Keep route metadata, hero count, documentation and data/gradient-gen/index.json aligned when the generated dataset changes, and rerun scripts/generate-gradient-index.mjs to rebuild the index and detail shards.
  • Update dynamic filter documentation when methods, interpolation spaces, easing curves, complexity labels or banding labels change.
  • Validate share hydration when changing _id, dataset order or share payload shape.
  • Check workspace mirroring before changing SAVED_KEY, mirror domain or payload shape.
  • Validate CSS, SVG, PNG, JSON, CSV, Tailwind and design-token export paths when changing stop schema.
  • 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 Gradient Library User Guide. For generator internals, see the Gradient Gen Developer Reference.