import * as i0 from '@angular/core'; import { EnvironmentProviders, InjectionToken } from '@angular/core'; /** * @license * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE */ /** Open Graph (`og:*`) tag values. */ interface WrMetaOg { readonly title?: string; readonly description?: string; readonly image?: string; readonly url?: string; readonly type?: string; readonly siteName?: string; } /** Twitter card (`twitter:*`) tag values. */ interface WrMetaTwitter { readonly card?: 'summary' | 'summary_large_image' | 'app' | 'player'; readonly title?: string; readonly description?: string; readonly image?: string; readonly creator?: string; } /** * Declarative description of `` metadata. Every field is optional — * unset values inherit from the layer below or fall back to defaults * registered via {@link provideWrMeta}. */ interface WrMetaConfig { readonly title?: string; /** Template applied to `title` when set — `{{ title }}` (or `%s`) is replaced with the page title. */ readonly titleTemplate?: string; readonly description?: string; readonly keywords?: readonly string[]; readonly canonical?: string; readonly themeColor?: string; readonly og?: WrMetaOg; readonly twitter?: WrMetaTwitter; } /** Returned by {@link WrMeta.push} — call `.pop()` to remove the layer. */ interface WrMetaHandle { readonly pop: () => void; } /** * Centralised `` metadata manager — title, description, keywords, * canonical, Open Graph and Twitter Card tags. * * Stack-based: `push(config)` adds a layer (returned handle pops it), * `set(config)` replaces the current top, `reset()` clears all overrides. * Layers merge via shallow merge for scalars and a one-level deep merge * for `og` / `twitter` groups. * * The resolved metadata is applied diff-style — only changed tags are * touched in the DOM, so reads of `document.head` stay cheap. * * @example * ```ts * const meta = inject(WrMeta); * meta.set({ title: 'Pricing', description: 'Plans for every team.' }); * * // From a route component — auto-pop on destroy via the directive: *
* ``` * * @see https://ngwr.dev/services/meta */ declare class WrMeta { private readonly title; private readonly meta; private readonly doc; private readonly defaults; private readonly injector; /** Stack of meta layers. Bottom = defaults, top = currently applied. */ private readonly stack; /** Resolved (merged) metadata at the top of the stack. */ readonly resolved: i0.Signal; /** Last applied snapshot — used to diff against the next resolution. */ private applied; constructor(); /** Snapshot of the resolved metadata currently in the DOM. */ current(): Readonly; /** Replace the top layer (or create one if only defaults are present). */ set(config: WrMetaConfig): void; /** Push a new layer. Returns a handle whose `.pop()` removes it. */ push(config: WrMetaConfig): WrMetaHandle; /** * Reactive layer. Runs `factory` inside an effect and re-applies the * resolved metadata whenever any signal it reads changes — so a title * (or any field) built from {@link WrI18n}'s `t()` updates live on * locale switch, with no manual re-`set()`. * * Returns a handle whose `.pop()` removes the layer and stops the effect. * Safe to call outside an injection context. * * @example Locale-aware title * ```ts * const meta = inject(WrMeta); * const i18n = inject(WrI18n); * * // `i18n.t(...)` tracks the active locale, so the title re-renders * // every time `i18n.use(...)` switches languages. * meta.bind(() => ({ * title: i18n.t('home.title'), * description: i18n.t('home.description'), * })); * ``` */ bind(factory: () => WrMetaConfig): WrMetaHandle; /** Pop the most recently pushed layer (defaults remain). */ pop(): void; /** Clear all overrides, restore the defaults registered via `provideWrMeta`. */ reset(): void; private apply; private diffTitle; private diffMeta; private updateName; private updateProp; private diffLink; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * Declarative wrapper around {@link WrMeta}. * * - Pushes the bound config on init. * - Re-pushes (replacing) when the config reference changes. * - Pops the layer on destroy — perfect for route-level meta overrides. * * @example * ```html *
* ``` */ declare class WrMetaBinding { readonly wrMeta: i0.InputSignal; private readonly metaService; private handle; constructor(); static ɵfac: i0.ɵɵFactoryDeclaration; static ɵdir: i0.ɵɵDirectiveDeclaration; } /** * @license * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE */ /** * Register app-wide defaults for {@link WrMeta}. Use to set a * consistent baseline `title` / `titleTemplate` / `og` / `twitter` for every * route — individual routes / components can override via * `metaService.push(...)` or the `[wrMeta]` directive. * * @example * ```ts * bootstrapApplication(AppComponent, { * providers: [ * provideWrMeta({ * titleTemplate: '{{ title }} · NGWR', * description: 'Angular UI components library', * og: { siteName: 'NGWR', type: 'website' }, * twitter: { card: 'summary_large_image', creator: '@thekhegay' }, * }), * ], * }); * ``` */ declare function provideWrMeta(defaults?: WrMetaConfig): EnvironmentProviders; /** * @license * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE */ /** App-wide defaults registered via {@link provideWrMeta}. */ declare const WR_META_DEFAULTS: InjectionToken; export { WR_META_DEFAULTS, WrMeta, WrMetaBinding, provideWrMeta }; export type { WrMetaConfig, WrMetaHandle, WrMetaOg, WrMetaTwitter };