library.svelte.ts

view source

Declarations
#

4 declarations

Library
#

library.svelte.ts view source

import {Library} from '@fuzdev/fuz_ui/library.svelte.js';

Rich runtime representation of a library.

Wraps LibraryJson with computed properties and provides the root of the API documentation hierarchy: Library → Module → Declaration.

A Library and everything it materializes is immutable — library_json is assigned once in the constructor — so the computed properties across all three classes are plain getters, with the allocating ones (the Module and Declaration trees, the lookup maps) cached in a private field on first read. They are deliberately not $derived: Svelte's server runtime only memoizes a $derived created during a render (ssr_context is otherwise null), so a Library constructed at module scope — the normal shape for a multi-package docs site — rebuilds its entire Module/Declaration tree on every property read, turning a declaration_by_name lookup into a full re-materialization of the library. Reactivity is at the instance level instead: swap the Library (see library_context), don't mutate one.

see also

library_json

type LibraryJson

readonly $state.raw

url_prefix

URL path prefix for multi-package documentation sites. Prepended to /docs/api/ paths in Module.url_api and Declaration.url_api. Default '' preserves single-package behavior.

type string

readonly

constructor

type new (library_json: LibraryJson, url_prefix?: string): Library

library_json

type LibraryJson

url_prefix?

type string
optional default ''

lookup_directory_modules

Look up modules within a directory prefix. Returns modules whose paths start with path + "/", or null if none match.

type (path: string): Module[] | null

path

type string
returns Module[] | null

search_declarations

Search declarations by query string with multi-term AND logic.

type (query: string): Declaration[]

query

type string
returns Declaration[]

pkg_json

type PkgJson

getter

source_json

type SourceJson

getter

name

type string

getter

repo_name

type string

getter

repo_url

Non-null — the constructor rejects a pkg_json without a parseable repository.

type Url

getter

owner_name

type string | null

getter

homepage_url

type Url | null

getter

logo_url

type Url | null

getter

logo_alt

type string

getter

published

type boolean

getter

npm_url

type Url | null

getter

changelog_url

type Url | null

getter

org_url

Organization URL (e.g., 'https://github.com/ryanatkn'), built from owner_name.

type string | null

getter

modules

All modules as rich Module instances.

type Module[]

getter

modules_sorted

All modules sorted alphabetically by path.

type Module[]

getter

declarations

All declarations across all modules as a flat array.

type Declaration[]

getter

module_by_path

Module lookup map by path. Provides O(1) lookup.

type Map<string, Module>

getter

declaration_by_name

Declaration lookup map by name. Provides O(1) lookup.

type Map<string, Declaration>

getter

library_context
#

library.svelte.ts view source

{ get: (error_message?: string | undefined) => () => Library; get_maybe: () => (() => Library) | undefined; set: (value: () => Library) => () => Library; } import {library_context} from '@fuzdev/fuz_ui/library.svelte.js';

Holds a getter to the active Library for the current subtree.

The getter form keeps consumers reactive when the library changes without requiring a remount — set it with a closure over reactive state, e.g. library_context.set(() => library). Components that accept a library prop (ApiIndex, ApiModule) project the prop into this context for their subtree, so descendants like ModuleLink, DeclarationLink, and TSDoc-rendered DocsLink resolve against the same library — including when an aggregator renders a foreign library that differs from the site-level context.

parse_library_url_prefix
#

library.svelte.ts view source

(value: unknown): string import {parse_library_url_prefix} from '@fuzdev/fuz_ui/library.svelte.js';

Normalizes a URL prefix: ensures leading /, strips trailing /, returns '' for falsy and non-string values.

value

type unknown

returns

string

set_library_context_with_fallback
#

library.svelte.ts view source

(get_library_prop: () => Library | undefined, component_name: string): () => Library import {set_library_context_with_fallback} from '@fuzdev/fuz_ui/library.svelte.js';

Sets library_context for the component's subtree to a getter that prefers the component's library prop and falls back to the ancestor's value, returning the resolved getter.

Pass get_library_prop as a getter (not a snapshot) so prop changes remain reactive. The ancestor lookup happens once at component init, before the projection — the fallback sees the parent value, not the projection.

get_library_prop

Getter for the component's library prop. A thunk so the prop stays reactive.

type () => Library | undefined

component_name

Used in the error when neither the prop nor the context provides a library.

type string

returns

() => Library

getter for the resolved library; read it lazily, e.g. $derived(get_library())

Depends on
#

Imported by
#