@docgeni/template
Version:
Docgeni - Angular Template Components
957 lines (936 loc) • 202 kB
JavaScript
import * as i0 from '@angular/core';
import { Directive, Component, ChangeDetectionStrategy, Input, NgModule, InjectionToken, signal, computed, Injectable, Inject, HostBinding, HostListener, ViewChild, Pipe, ɵNgModuleFactory as _NgModuleFactory, EventEmitter, Output, ElementRef, APP_INITIALIZER } from '@angular/core';
import * as i2 from '@angular/common';
import { CommonModule, DOCUMENT } from '@angular/common';
import * as i1 from '@angular/common/http';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { BehaviorSubject, Subject, fromEvent, forkJoin, combineLatest } from 'rxjs';
import * as i1$1 from '@angular/platform-browser';
import * as i2$1 from '@angular/router';
import { NavigationEnd, RouterModule } from '@angular/router';
import { takeUntil, debounceTime, map, distinctUntilChanged, filter, take } from 'rxjs/operators';
import * as i4 from '@angular/forms';
import { FormsModule } from '@angular/forms';
class DocgeniBuiltInComponent {
get hostElement() {
return this.elementRef.nativeElement;
}
constructor(elementRef) {
this.elementRef = elementRef;
this.classes = [];
}
setAttribute(qualifiedName, value) {
this[qualifiedName] = value;
this.hostElement.setAttribute(qualifiedName, value);
}
updateHostClass(classes) {
if (this.classes) {
this.classes.forEach((className) => {
if (!this.classes.includes(className)) {
this.removeClass(className);
}
});
}
const newClasses = [];
classes.forEach((className) => {
if (className) {
newClasses.push(className);
if (!this.classes.includes(className)) {
this.addClass(className);
}
}
});
this.classes = newClasses;
return this;
}
addClass(className) {
this.hostElement.classList.add(className);
}
removeClass(className) {
this.hostElement.classList.remove(className);
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: DocgeniBuiltInComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); }
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.0.3", type: DocgeniBuiltInComponent, isStandalone: true, ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: DocgeniBuiltInComponent, decorators: [{
type: Directive
}], ctorParameters: () => [{ type: i0.ElementRef }] });
class DocgeniLabelComponent extends DocgeniBuiltInComponent {
get type() {
return this.internalType;
}
set type(value) {
this.internalType = value;
this.updateHostClass([`dg-label-${this.type}`]);
}
constructor(elementRef) {
super(elementRef);
this.internalType = 'primary';
}
ngOnInit() {
this.updateHostClass([`dg-label-${this.type}`]);
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: DocgeniLabelComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.3", type: DocgeniLabelComponent, isStandalone: false, selector: "label", inputs: { type: "type" }, host: { classAttribute: "dg-label" }, usesInheritance: true, ngImport: i0, template: "<ng-content></ng-content>\n", changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: DocgeniLabelComponent, decorators: [{
type: Component,
args: [{ selector: 'label', host: {
class: 'dg-label',
}, changeDetection: ChangeDetectionStrategy.OnPush, standalone: false, template: "<ng-content></ng-content>\n" }]
}], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { type: [{
type: Input
}] } });
var label = {
selector: 'label',
component: DocgeniLabelComponent,
};
class DocgeniAlertComponent extends DocgeniBuiltInComponent {
get type() {
return this.internalType;
}
set type(value) {
this.internalType = value;
this.updateHostClass([`dg-alert-${this.type}`]);
}
constructor(elementRef) {
super(elementRef);
this.internalType = 'info';
}
ngOnInit() {
this.updateHostClass([`dg-alert-${this.type}`]);
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: DocgeniAlertComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.3", type: DocgeniAlertComponent, isStandalone: false, selector: "alert", inputs: { type: "type" }, host: { classAttribute: "dg-alert" }, usesInheritance: true, ngImport: i0, template: "<ng-content></ng-content>\n", changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: DocgeniAlertComponent, decorators: [{
type: Component,
args: [{ selector: 'alert', host: {
class: 'dg-alert',
}, changeDetection: ChangeDetectionStrategy.OnPush, standalone: false, template: "<ng-content></ng-content>\n" }]
}], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { type: [{
type: Input
}] } });
var alert = {
selector: 'alert',
component: DocgeniAlertComponent,
};
let builtInComponents;
function setBuiltInComponents(components) {
builtInComponents = components || [];
}
function getBuiltInComponents() {
return builtInComponents;
}
function addBuiltInComponents(components) {
builtInComponents = builtInComponents ? builtInComponents.concat(components) : components;
}
function loadBuiltInComponents() {
setBuiltInComponents([label, alert]);
}
class DocgeniBuiltInModule {
constructor() {
loadBuiltInComponents();
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: DocgeniBuiltInModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.0.3", ngImport: i0, type: DocgeniBuiltInModule, declarations: [DocgeniLabelComponent, DocgeniAlertComponent], imports: [CommonModule] }); }
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: DocgeniBuiltInModule, imports: [CommonModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: DocgeniBuiltInModule, decorators: [{
type: NgModule,
args: [{
declarations: [DocgeniLabelComponent, DocgeniAlertComponent],
imports: [CommonModule],
exports: [],
providers: [],
}]
}], ctorParameters: () => [] });
const BUILT_IN_COMPONENTS = [label, alert];
var DocgeniTheme;
(function (DocgeniTheme) {
DocgeniTheme["light"] = "light";
DocgeniTheme["dark"] = "dark";
DocgeniTheme["system"] = "system";
})(DocgeniTheme || (DocgeniTheme = {}));
function languageCompare(language1, language2) {
return language1.toLocaleLowerCase().replace(/_/g, '-') === language2.toLocaleLowerCase().replace(/_/g, '-');
}
const CONFIG_TOKEN = new InjectionToken('DOC_SITE_CONFIG');
const DEFAULT_CONFIG = {
title: 'Docgeni',
description: '',
};
const DOCGENI_LOCALE_KEY = 'docgeni-locale';
const DOCGENI_MODE_KEY = 'docgeni-mode';
const DOCGENI_THEME_KEY = 'docgeni-theme';
class GlobalContext {
get isDefaultLocale() {
return this.locale === this.config.defaultLocale;
}
constructor(config, http, document, location) {
this.config = config;
this.http = http;
this.document = document;
this.location = location;
this.theme = signal(DocgeniTheme.light);
this.isDarkTheme = computed(() => {
return ((this.theme() === DocgeniTheme.system && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) ||
this.theme() === DocgeniTheme.dark);
});
this.setup();
}
getLocaleKey() {
const localeKeyFromUrl = this.getLocalKeyFromUrl();
if (localeKeyFromUrl) {
return localeKeyFromUrl;
}
else {
const cacheLocale = window.localStorage.getItem(DOCGENI_LOCALE_KEY) || window.navigator.language || '';
const locale = (this.config.locales || []).find((locale) => {
return languageCompare(locale.key, cacheLocale);
});
if (locale) {
return locale.key;
}
else {
return this.config.defaultLocale;
}
}
}
setup() {
this.setLocale(this.getLocaleKey());
this.setTheme(this.getTheme());
const cacheMode = window.localStorage.getItem(DOCGENI_MODE_KEY);
if (cacheMode && ['lite', 'full'].includes(cacheMode)) {
this.config.mode = cacheMode;
}
document.body.classList.add(`dg-mode-${this.config.mode}`, `dg-navbar-theme-${this.config.theme}`);
if (this.config.repoUrl) {
const pattern = /https:\/\/github.com\/([^\/]*)\/([^\/]*)/.exec(this.config.repoUrl);
if (pattern && pattern.length === 3) {
this.owner = pattern[1];
this.repo = pattern[2];
}
}
}
getLocalKeyFromUrl() {
const localeFromUrl = (this.config.locales || []).find((locale) => {
return this.location.path().startsWith(`/${locale.key}`);
});
return localeFromUrl && localeFromUrl.key;
}
setLocale(locale) {
this.locale = locale;
window.localStorage.setItem(DOCGENI_LOCALE_KEY, locale);
}
getTheme() {
const cacheTheme = window.localStorage.getItem(DOCGENI_THEME_KEY);
if (cacheTheme && [DocgeniTheme.light, DocgeniTheme.dark, DocgeniTheme.system].includes(cacheTheme)) {
return cacheTheme;
}
else {
return DocgeniTheme.light;
}
}
setTheme(theme) {
this.theme.set(theme);
window.localStorage.setItem(DOCGENI_THEME_KEY, theme);
if (this.isDarkTheme()) {
document.documentElement.setAttribute('theme', DocgeniTheme.dark);
document.documentElement.style.setProperty('color-scheme', 'dark');
}
else {
document.documentElement.removeAttribute('theme');
document.documentElement.style.removeProperty('color-scheme');
}
}
getNowTimestamp() {
return new Date().getTime();
}
initialize() {
return new Promise((resolve, reject) => {
this.http
.get(`assets/content/navigations-${this.locale}.json?t=${this.getNowTimestamp()}`)
.subscribe({
next: (response) => {
this.homeMeta = response.homeMeta;
this.navs = response.navs;
this.docItems = this.sortDocItems(this.navs);
resolve(response);
},
error: (error) => {
reject(error);
},
});
});
}
getAssetsContentPath(path) {
return path.startsWith('/') ? `assets/content${path}` : `assets/content/${path}`;
}
sortDocItems(navs) {
navs = navs.slice();
const list = [];
while (navs.length) {
const item = navs.shift();
if (item) {
if (item.items) {
item.items.forEach((child) => {
child.ancestors = child.ancestors || [];
child.ancestors.push(...(item.ancestors || []), item);
});
navs.unshift(...item.items);
}
else if (!item.hidden) {
list.push(item);
}
}
}
return list;
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: GlobalContext, deps: [{ token: CONFIG_TOKEN }, { token: i1.HttpClient }, { token: DOCUMENT }, { token: i2.Location }], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: GlobalContext, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: GlobalContext, decorators: [{
type: Injectable,
args: [{
providedIn: 'root',
}]
}], ctorParameters: () => [{ type: undefined, decorators: [{
type: Inject,
args: [CONFIG_TOKEN]
}] }, { type: i1.HttpClient }, { type: undefined, decorators: [{
type: Inject,
args: [DOCUMENT]
}] }, { type: i2.Location }] });
class NavigationService {
get channel() {
return this.channel$.value;
}
get docItem() {
return this.docItem$.value;
}
get navs() {
return this.global.navs;
}
get docItems() {
return this.global.docItems;
}
constructor(global) {
this.global = global;
this.channel$ = new BehaviorSubject(null);
this.docItem$ = new BehaviorSubject(null);
this.docPages$ = new BehaviorSubject(null);
/** Responsive layout, sidebar default is hide */
this.showSidebar = false;
}
getChannels() {
return this.navs;
}
getChannel(path) {
return this.navs.find((nav) => {
return nav.path === path;
});
}
getDocItemByPath(path) {
let index;
if (this.channel) {
// 类库频道
if (this.channel.lib) {
index = this.docItems.findIndex((docItem) => {
return docItem.path === path && docItem.channelPath === this.channel.path && !!docItem.importSpecifier;
});
}
else {
index = this.docItems.findIndex((docItem) => {
return docItem.path === path && docItem.channelPath === this.channel.path;
});
}
}
else {
index = this.docItems.findIndex((docItem) => {
return docItem.path === path && (this.global.config.mode === 'lite' ? true : !docItem.channelPath);
});
}
if (index > -1) {
const preDocItem = index ? this.docItems[index - 1] : undefined;
const nextDocItem = this.docItems.length - 1 === index ? undefined : this.docItems[index + 1];
this.docPages$.next({
pre: preDocItem,
next: nextDocItem,
});
}
return this.docItems[index];
}
selectChannelByPath(path) {
const channel = this.getChannel(path);
this.channel$.next(channel);
return channel;
}
clearChannel() {
this.channel$.next(null);
}
selectDocItem(path) {
const docItem = this.getDocItemByPath(path);
this.docItem$.next(docItem);
}
getChannelFirstDocItem() {
if (this.channel && this.channel.items) {
return this.searchFirstDocItem(this.channel.items);
}
return null;
}
searchFirstDocItem(items = this.navs) {
let docItem;
for (const nav of items) {
if (this.isDocItem(nav)) {
docItem = nav;
}
else {
docItem = this.getNavFirstDocItem(nav);
}
if (docItem) {
break;
}
}
return docItem;
}
getNavFirstDocItem(nav) {
let docItem;
for (const item of nav.items) {
if (item && this.isCategoryItem(item)) {
docItem = this.getNavFirstDocItem(item);
}
else {
docItem = item;
}
if (docItem) {
break;
}
}
return docItem;
}
toggleSidebar() {
this.showSidebar = !this.showSidebar;
}
resetShowSidebar() {
this.showSidebar = false;
}
isCategoryItem(category) {
return category.items;
}
isDocItem(item) {
return !item.items;
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NavigationService, deps: [{ token: GlobalContext }], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NavigationService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NavigationService, decorators: [{
type: Injectable,
args: [{
providedIn: 'root',
}]
}], ctorParameters: () => [{ type: GlobalContext }] });
class ChannelResolver {
constructor(navigationService) {
this.navigationService = navigationService;
}
resolve(route) {
const path = route.paramMap.get('channel');
const channel = this.navigationService.getChannel(path);
return channel;
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: ChannelResolver, deps: [{ token: NavigationService }], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: ChannelResolver, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: ChannelResolver, decorators: [{
type: Injectable,
args: [{ providedIn: 'root' }]
}], ctorParameters: () => [{ type: NavigationService }] });
class ExampleLoader {
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: ExampleLoader, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: ExampleLoader }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: ExampleLoader, decorators: [{
type: Injectable
}] });
class PageTitleService {
get title() {
return this.innerTitle;
}
set title(title) {
this.innerTitle = title;
if (title !== '') {
title = `${title} - ${this.globalContext.config.title}`;
}
else {
title = this.globalContext.config.title;
}
this.bodyTitle.setTitle(title);
}
constructor(bodyTitle, globalContext) {
this.bodyTitle = bodyTitle;
this.globalContext = globalContext;
this.innerTitle = '';
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: PageTitleService, deps: [{ token: i1$1.Title }, { token: GlobalContext }], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: PageTitleService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: PageTitleService, decorators: [{
type: Injectable,
args: [{ providedIn: 'root' }]
}], ctorParameters: () => [{ type: i1$1.Title }, { type: GlobalContext }] });
const github = `<svg focusable="false" viewBox="0 0 51.8 50.4" xmlns="http://www.w3.org/2000/svg" width="1em" height="1em">
<path
d="M25.9,0.2C11.8,0.2,0.3,11.7,0.3,25.8c0,11.3,7.3,20.9,17.5,24.3c1.3,0.2,1.7-0.6,1.7-1.2c0-0.6,0-2.6,0-4.8c-7.1,1.5-8.6-3-8.6-3c-1.2-3-2.8-3.7-2.8-3.7c-2.3-1.6,0.2-1.6,0.2-1.6c2.6,0.2,3.9,2.6,3.9,2.6c2.3,3.9,6,2.8,7.5,2.1c0.2-1.7,0.9-2.8,1.6-3.4c-5.7-0.6-11.7-2.8-11.7-12.7c0-2.8,1-5.1,2.6-6.9c-0.3-0.7-1.1-3.3,0.3-6.8c0,0,2.1-0.7,7,2.6c2-0.6,4.2-0.9,6.4-0.9c2.2,0,4.4,0.3,6.4,0.9c4.9-3.3,7-2.6,7-2.6c1.4,3.5,0.5,6.1,0.3,6.8c1.6,1.8,2.6,4.1,2.6,6.9c0,9.8-6,12-11.7,12.6c0.9,0.8,1.7,2.4,1.7,4.7c0,3.4,0,6.2,0,7c0,0.7,0.5,1.5,1.8,1.2c10.2-3.4,17.5-13,17.5-24.3C51.5,11.7,40.1,0.2,25.9,0.2z"
></path>
</svg>`;
const code = `<svg
viewBox="0 0 16 16"
xmlns="http://www.w3.org/2000/svg"
fit=""
height="1em"
width="1em"
preserveAspectRatio="xMidYMid meet"
focusable="false"
>
<g fill-rule="evenodd">
<path d="M.003 8.306l4.302 4.304.849-.848L.852 7.458z"></path>
<path d="M0 8.308l.847.85 4.31-4.296-.847-.85zM10.8 4.861l4.309 4.296.848-.85-4.309-4.296z"></path>
<path d="M10.804 11.762l.849.848 4.302-4.304-.85-.848zM8.526 4L6.1 12.582l1.241.006 2.435-8.565z"></path>
</g>
</svg>`;
const external = `<svg
fit=""
focusable="false"
height="100%"
preserveAspectRatio="xMidYMid meet"
viewBox="0 0 24 24"
width="100%"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M0 0h24v24H0z" fill="none"></path>
<path
d="M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z"
></path>
</svg>`;
const copy = `<svg
viewBox="0 0 16 16"
xmlns="http://www.w3.org/2000/svg"
fit=""
height="1em"
width="1em"
preserveAspectRatio="xMidYMid meet"
focusable="false"
>
<path
d="M7.6 8.2V7h4.174v1.2H7.6zm0 3V10h4.174v1.2H7.6zm-4.4-10v10.074H2L2.003 2c0-1.088.895-2 1.997-2h7.585v1.2H3.2zM5 2h9a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1zm.2 1.2v11.6h8.6V3.2H5.2z"
></path>
</svg>`;
const check = `
<svg
viewBox="0 0 16 16"
xmlns="http://www.w3.org/2000/svg"
fit=""
height="1em"
width="1em"
preserveAspectRatio="xMidYMid meet"
focusable="false"
>
<path d="M6.012 11.201L1.313 6.832l-.817.879 5.54 5.15 9.304-9.163-.842-.855z"></path>
</svg>`;
const list = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" id="align-justify">
<g id="ageditor/align-justify" stroke-width="1" fill-rule="evenodd">
<path d="M0 1h16v1.2H0V1zm0 6.4h16v1.2H0V7.4zm0 6.4h16V15H0v-1.2z" id="ag合并形状"></path>
</g>
</svg>`;
const arrowLeft = `<svg width="1em" height="1em" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 55.2 (78181) - https://sketchapp.com -->
<title>navigation/arrow-left</title>
<desc>Created with Sketch.</desc>
<g id="navigation/arrow-left" stroke="none" stroke-width="1" fill-rule="evenodd">
<path d="M7.4,4.14955232 L4.4383,7.3151 C4.2123,7.5571 3.8323,7.5691 3.5903,7.3431 C3.3483,7.1161 3.3353,6.7371 3.5623,6.4951 L7.53151194,2.2516372 C7.55538364,2.21814642 7.58305703,2.18659454 7.6145,2.1576 C7.8585,1.9336 8.2375,1.9496 8.4615,2.1946 L12.4315,6.5176 C12.6565,6.7616 12.6395,7.1416 12.3955,7.3656 C12.1515,7.5896 11.7725,7.5736 11.5475,7.3296 L8.6,4.11846621 L8.6,13.2666667 C8.6,13.6712222 8.331,14 8,14 C7.668,14 7.4,13.6712222 7.4,13.2666667 L7.4,4.14955232 Z" id="形状结合" transform="translate(7.995013, 7.999832) rotate(-90.000000) translate(-7.995013, -7.999832) "></path>
</g>
</svg>`;
const arrowRight = `<svg width="1em" height="1em" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 55.2 (78181) - https://sketchapp.com -->
<title>navigation/arrow-right</title>
<desc>Created with Sketch.</desc>
<g id="navigation/arrow-right" stroke="none" stroke-width="1" fill-rule="evenodd">
<path d="M7.4,4.14955232 L4.4383,7.3151 C4.2123,7.5571 3.8323,7.5691 3.5903,7.3431 C3.3483,7.1161 3.3353,6.7371 3.5623,6.4951 L7.53151194,2.2516372 C7.55538364,2.21814642 7.58305703,2.18659454 7.6145,2.1576 C7.8585,1.9336 8.2375,1.9496 8.4615,2.1946 L12.4315,6.5176 C12.6565,6.7616 12.6395,7.1416 12.3955,7.3656 C12.1515,7.5896 11.7725,7.5736 11.5475,7.3296 L8.6,4.11846621 L8.6,13.2666667 C8.6,13.6712222 8.331,14 8,14 C7.668,14 7.4,13.6712222 7.4,13.2666667 L7.4,4.14955232 Z" id="形状结合" transform="translate(7.995013, 7.999832) rotate(90.000000) translate(-7.995013, -7.999832) "></path>
</g>
</svg>`;
const angleRight = `<svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 55.2 (78181) - https://sketchapp.com -->
<title>navigation/angle-right</title>
<desc>Created with Sketch.</desc>
<g id="navigation/angle-right" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<path d="M7.97815,11.49765 L7.9728,11.503 L2.2998,5.831 L3.1298,5 L7.97807731,9.84827731 L12.8255,5 L13.6565,5.831 L7.9835,11.503 L7.97815,11.49765 Z" id="形状结合" fill="#888888" transform="translate(7.978150, 8.251500) scale(-1, -1) rotate(-270.000000) translate(-7.978150, -8.251500) "></path>
</g>
</svg>`;
const search = `<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fit="" height="1em" width="1em" preserveAspectRatio="xMidYMid meet" focusable="false"><g id="oonormal/search" stroke-width="1" fill-rule="evenodd"><path d="M6.751 12.303A5.557 5.557 0 0 1 1.2 6.751C1.2 3.691 3.69 1.2 6.751 1.2a5.558 5.558 0 0 1 5.551 5.551 5.557 5.557 0 0 1-5.551 5.552M6.751 0a6.751 6.751 0 1 0 4.309 11.949l3.855 3.855a.6.6 0 1 0 .849-.849l-3.854-3.853A6.751 6.751 0 0 0 6.751 0" id="ooFill-1"></path></g></svg>`;
const empty = `<svg width="148px" height="134px" viewBox="0 0 148 134" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="ng-star-inserted"><defs><filter x="0.0%" y="0.0%" width="100.0%" height="100.0%" filterUnits="objectBoundingBox" id="filter-1"><feGaussianBlur stdDeviation="0" in="SourceGraphic"></feGaussianBlur></filter></defs><g id="148x134" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="编组-6" transform="translate(1.000000, 1.000000)"><ellipse id="椭圆形" fill="#EDEEF2" opacity="0.3" filter="url(#filter-1)" cx="73.0800017" cy="115.920003" rx="73.0800017" ry="16.8000004"></ellipse><g id="编组-5" transform="translate(15.120000, 0.000000)"><polygon id="矩形" fill="#E2E4E9" points="19.2789848 49.5600011 99.1200023 48.7200011 117.600003 75.9297673 117.600003 92.313049 0 92.313049 0 75.0356267"></polygon><path d="M23.5200005,0 L94.0800002,0 C97.7913538,2.06413823e-16 100.8,3.00864655 100.8,6.72000015 L100.8,99.1200023 L100.8,99.1200023 L16.8000004,99.1200023 L16.8000004,6.72000015 C16.8000004,3.00864655 19.8086469,1.56994302e-15 23.5200005,0 Z" id="矩形" fill="#F9FAFB"></path><path d="M30.9200007,12.4400003 L86.6800019,12.4400003 C88.5356787,12.4400003 90.040002,13.9443236 90.040002,15.8000004 L90.040002,42.000001 C90.040002,43.8556778 88.5356787,45.360001 86.6800019,45.360001 L30.9200007,45.360001 C29.0643239,45.360001 27.5600006,43.8556778 27.5600006,42.000001 L27.5600006,15.8000004 C27.5600006,13.9443236 29.0643239,12.4400003 30.9200007,12.4400003 Z" id="矩形" fill="#E8EAEE"></path><text id="</null>" font-family="PingFangSC-Medium, PingFang SC" font-size="15.1200003" font-weight="400" fill="#BCBECD"><tspan x="33.6000008" y="32.8000004"></null></tspan></text><rect id="矩形" fill="#E8EAEE" x="27.5600006" y="52.0800012" width="61.4800014" height="5.04000011" rx="2.52000006"></rect><rect id="矩形备份" fill="#E8EAEE" x="27.5600006" y="63.8400014" width="61.4800014" height="5.04000011" rx="2.52000006"></rect><path d="M0,75.6000017 L29.280235,75.6000017 C32.0637502,75.6000017 34.3202352,77.8564866 34.3202352,80.6400018 L34.3202352,86.2591426 C34.3202352,89.0426578 36.5767201,91.2991427 39.3602353,91.2991427 L78.4136737,91.2991427 C81.1971889,91.2991427 83.4536738,89.0426578 83.4536738,86.2591426 L83.4536738,80.6400018 C83.4536738,77.8564866 85.7101587,75.6000017 88.4936739,75.6000017 L117.600003,75.6000017 L117.600003,75.6000017 L117.600003,110.880003 C117.600003,115.519195 113.839194,119.280003 109.200002,119.280003 L8.40000019,119.280003 C3.76080819,119.280003 -6.53729019e-15,115.519195 0,110.880003 L0,75.6000017 L0,75.6000017 Z" id="矩形" fill="#EDEFF2"></path></g></g></g></svg>`;
const stackBlitz = `<svg viewBox="0 0 28 28" aria-hidden="true" class="StackBlitzLogo-module-boltIcon-3IWaX" width="28" height="28"><path d="M12.747 16.273h-7.46L18.925 1.5l-3.671 10.227h7.46L9.075 26.5l3.671-10.227z"></path></svg>`;
const lightTheme = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-width="4" viewBox="0 0 48 48" aria-hidden="true" focusable="false"><circle cx="24" cy="24" r="9" fill="currentColor" stroke="none"/><path fill="currentColor" stroke="none" d="M21 5.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 .5.5v5a.5.5 0 0 1-.5.5h-5a.5.5 0 0 1-.5-.5v-5ZM21 37.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 .5.5v5a.5.5 0 0 1-.5.5h-5a.5.5 0 0 1-.5-.5v-5ZM42.5 21a.5.5 0 0 1 .5.5v5a.5.5 0 0 1-.5.5h-5a.5.5 0 0 1-.5-.5v-5a.5.5 0 0 1 .5-.5h5ZM10.5 21a.5.5 0 0 1 .5.5v5a.5.5 0 0 1-.5.5h-5a.5.5 0 0 1-.5-.5v-5a.5.5 0 0 1 .5-.5h5ZM39.203 34.96a.5.5 0 0 1 0 .707l-3.536 3.536a.5.5 0 0 1-.707 0l-3.535-3.536a.5.5 0 0 1 0-.707l3.535-3.535a.5.5 0 0 1 .707 0l3.536 3.535ZM16.575 12.333a.5.5 0 0 1 0 .707l-3.535 3.535a.5.5 0 0 1-.707 0L8.797 13.04a.5.5 0 0 1 0-.707l3.536-3.536a.5.5 0 0 1 .707 0l3.535 3.536ZM13.04 39.203a.5.5 0 0 1-.707 0l-3.536-3.536a.5.5 0 0 1 0-.707l3.536-3.535a.5.5 0 0 1 .707 0l3.536 3.535a.5.5 0 0 1 0 .707l-3.536 3.536ZM35.668 16.575a.5.5 0 0 1-.708 0l-3.535-3.535a.5.5 0 0 1 0-.707l3.535-3.536a.5.5 0 0 1 .708 0l3.535 3.536a.5.5 0 0 1 0 .707l-3.535 3.535Z"/></svg>`;
const darkTheme = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-width="4" viewBox="0 0 48 48" aria-hidden="true" focusable="false"><path fill="currentColor" stroke="none" d="M42.108 29.769c.124-.387-.258-.736-.645-.613A17.99 17.99 0 0 1 36 30c-9.941 0-18-8.059-18-18 0-1.904.296-3.74.844-5.463.123-.387-.226-.768-.613-.645C10.558 8.334 5 15.518 5 24c0 10.493 8.507 19 19 19 8.482 0 15.666-5.558 18.108-13.231Z"/></svg>`;
const systemTheme = `<svg fill="none" stroke="currentColor" stroke-width="4" viewBox="0 0 48 48" width="1em" height="1em"><path d="M24 32v8m0 0h-9m9 0h9M7 32h34a1 1 0 0 0 1-1V9a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1v22a1 1 0 0 0 1 1Z"></path></svg>`;
const locale = `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M2 5C2 3.34315 3.34315 2 5 2H7C8.65685 2 10 3.34315 10 5V11H8V8.5H4V11H2V5ZM4 6.5H8V5C8 4.44772 7.55228 4 7 4H5C4.44772 4 4 4.44772 4 5V6.5ZM12 3.5H18C19.6569 3.5 21 4.84315 21 6.5V9H19V6.5C19 5.94772 18.5523 5.5 18 5.5H12V3.5ZM18 11.5V13H22V15H20.9381C20.7182 16.7638 19.9241 18.3492 18.7488 19.5634C19.4441 19.845 20.2041 20 21 20H22V22H21C19.5425 22 18.1765 21.6102 17.0001 20.9297C15.8234 21.6104 14.4572 22 13 22H12V20H13C13.7962 20 14.5562 19.8449 15.2514 19.5633C14.6487 18.9407 14.1463 18.2205 13.7704 17.4291L13.3413 16.5258L15.1478 15.6676L15.5769 16.5709C15.9219 17.2971 16.4081 17.9427 16.9999 18.4723C17.9921 17.5843 18.687 16.371 18.917 15H12V13H16V11.5H18ZM6 13V19C6 19.5523 6.44772 20 7 20H9.5V22H7C5.34315 22 4 20.6569 4 19V13H6Z" fill="currentColor"/>
</svg>`;
const BUILTIN_SVGS = {
github,
code,
external,
copy,
check,
list,
arrowLeft,
arrowRight,
angleRight,
search,
empty,
stackBlitz,
locale,
lightTheme,
darkTheme,
systemTheme,
};
class IconComponent {
set iconName(name) {
this.setSvg(name);
}
constructor(elementRef, domSanitizer) {
this.elementRef = elementRef;
this.domSanitizer = domSanitizer;
this.isIcon = true;
}
ngOnInit() { }
ngAfterViewInit() { }
setSvg(name) {
const svg = BUILTIN_SVGS[name];
if (svg) {
this.elementRef.nativeElement.innerHTML = svg;
}
else {
this.elementRef.nativeElement.innerHTML = '';
}
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: IconComponent, deps: [{ token: i0.ElementRef }, { token: i1$1.DomSanitizer }], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.3", type: IconComponent, isStandalone: false, selector: "dg-icon", inputs: { iconName: "iconName" }, host: { properties: { "class.dg-icon": "this.isIcon" } }, ngImport: i0, template: "<ng-content></ng-content>\n" }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: IconComponent, decorators: [{
type: Component,
args: [{ selector: 'dg-icon', standalone: false, template: "<ng-content></ng-content>\n" }]
}], ctorParameters: () => [{ type: i0.ElementRef }, { type: i1$1.DomSanitizer }], propDecorators: { isIcon: [{
type: HostBinding,
args: ['class.dg-icon']
}], iconName: [{
type: Input
}] } });
function colorMetadata(color) {
let obj;
if (color.startsWith('#')) {
obj = hexColorMetadata(color);
}
else if (color.startsWith('rgb')) {
obj = rgbColorMetadata(color);
}
else {
throw new Error('unsupported color format ' + color);
}
return obj;
}
function hexColorMetadata(color) {
const rgx = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
const hex = color.replace(rgx, (m, r, g, b) => r + r + g + g + b + b);
const rgb = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return rgb ? { r: parseInt(rgb[1], 16), g: parseInt(rgb[2], 16), b: parseInt(rgb[3], 16) } : {};
}
function rgbColorMetadata(color) {
const result = /rgb\(([0-9]{1,3})\s*[,\s]\s*([0-9]{1,3})\s*[,\s]\s*([0-9]{1,3})\)/i.exec(color);
return result
? {
r: parseInt(result[1], 10),
g: parseInt(result[2], 10),
b: parseInt(result[3], 10),
}
: {};
}
const LABEL_LIST = ['primary', 'danger', 'warning', 'info'];
class LabelComponent {
set labelType(value) {
if (LABEL_LIST.includes(value)) {
this.classList = ['dg-label', `dg-label-${value}`];
}
else {
this.classList = ['dg-label'];
this.renderer.setStyle(this.elementRef.nativeElement, 'background-color', this.getBackgroundColor(value));
this.renderer.setStyle(this.elementRef.nativeElement, 'color', value);
}
}
constructor(elementRef, renderer) {
this.elementRef = elementRef;
this.renderer = renderer;
}
ngOnInit() { }
getBackgroundColor(color) {
const { r, g, b } = colorMetadata(color);
return `rgba(${r},${g},${b},0.20)`;
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: LabelComponent, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.3", type: LabelComponent, isStandalone: false, selector: "dg-label", inputs: { labelType: "labelType" }, host: { properties: { "class": "this.classList" } }, ngImport: i0, template: "<ng-content></ng-content>\n" }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: LabelComponent, decorators: [{
type: Component,
args: [{ selector: 'dg-label', standalone: false, template: "<ng-content></ng-content>\n" }]
}], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.Renderer2 }], propDecorators: { classList: [{
type: HostBinding,
args: [`class`]
}], labelType: [{
type: Input
}] } });
let OFFSET$1 = 0;
class TocService {
get links$() {
return this.linksSubject$.asObservable();
}
get links() {
return this.linksSubject$.value;
}
get activeLink$() {
return this.activeLinkSubject$.asObservable();
}
constructor(document, global, viewportScroller) {
this.document = document;
this.viewportScroller = viewportScroller;
this.linksSubject$ = new BehaviorSubject([]);
this.activeLinkSubject$ = new BehaviorSubject(null);
this.destroyed$ = new Subject();
if (global.config.mode === 'lite') {
OFFSET$1 = 0;
}
this.viewportScroller.setOffset([0, OFFSET$1]);
}
reset() {
this.linksSubject$.next([]);
this.activeLinkSubject$.next(null);
this.highestLevel = 0;
this.destroyed$.next(null);
this.destroyed$.complete();
}
generateToc(docViewerContent, scrollContainer = '.dg-scroll-container') {
const headers = Array.from(docViewerContent.querySelectorAll('h1, h2, h3, h4, dg-examples'));
const links = [];
headers.forEach((header) => {
if (header.tagName === 'DG-EXAMPLES') {
const allExamples = header.querySelectorAll('example');
const headerLevel = 2;
allExamples.forEach((example) => {
links.push({
name: example.getAttribute('title'),
type: 'h2',
top: example.getBoundingClientRect().top,
id: example.getAttribute('name'),
active: false,
level: headerLevel,
element: example,
});
});
return;
}
// remove the 'TocLink' icon name from the inner text
const name = header.innerText.trim().replace(/^TocLink/, '');
const { top } = header.getBoundingClientRect();
const headerLevel = parseInt(header.tagName[1], 10);
links.push({
name,
type: header.tagName.toLowerCase(),
top,
id: header.id,
active: false,
level: headerLevel,
element: header,
});
this.highestLevel = this.highestLevel && headerLevel > this.highestLevel ? this.highestLevel : headerLevel;
});
this.initializeScrollContainer(scrollContainer);
this.linksSubject$.next(links);
}
initializeScrollContainer(scrollContainerSelector) {
this.scrollContainer = scrollContainerSelector ? this.document.querySelectorAll(scrollContainerSelector)[0] : window;
Promise.resolve().then(() => {
if (this.scrollContainer) {
fromEvent(this.scrollContainer, 'scroll')
.pipe(takeUntil(this.destroyed$), debounceTime(10))
.subscribe(() => this.onScroll());
}
this.onScroll();
});
}
onScroll() {
const scrollOffset = this.getScrollOffset();
let activeItem;
if (scrollOffset <= OFFSET$1 + 1) {
activeItem = this.links[0];
}
else {
const itemOffset = this.links.find((link) => {
return link.element.offsetTop >= scrollOffset;
});
if (itemOffset) {
activeItem = itemOffset;
}
else {
activeItem = this.links[this.links.length - 1];
}
}
this.activeLinkSubject$.next(activeItem || null);
}
scrollToAnchor(urlFragment) {
if (this.scrollContainer) {
if (this.scrollContainer === this.document.window) {
this.viewportScroller.scrollToAnchor(urlFragment);
}
else {
const link = this.links.find((link) => {
return link.id === urlFragment;
});
if (link) {
this.scrollContainer.scrollTop = link.element.offsetTop - 10;
}
}
}
}
getScrollOffset() {
if (this.scrollContainer) {
if (typeof this.scrollContainer.scrollTop !== 'undefined') {
return this.scrollContainer.scrollTop + OFFSET$1;
}
else if (typeof this.scrollContainer.pageYOffset !== 'undefined') {
return this.scrollContainer.pageYOffset + OFFSET$1;
}
return 0;
}
else {
return 0;
}
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: TocService, deps: [{ token: DOCUMENT }, { token: GlobalContext }, { token: i2.ViewportScroller }], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: TocService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: TocService, decorators: [{
type: Injectable,
args: [{
providedIn: 'root',
}]
}], ctorParameters: () => [{ type: undefined, decorators: [{
type: Inject,
args: [DOCUMENT]
}] }, { type: GlobalContext }, { type: i2.ViewportScroller }] });
let OFFSET = 60;
class TableOfContentsComponent {
constructor(router, route, global, locationStrategy, tocService) {
this.router = router;
this.route = route;
this.locationStrategy = locationStrategy;
this.tocService = tocService;
this.isToc = true;
this.container = '.dg-scroll-container';
this.links = [];
this.rootUrl = this.locationStrategy.path(false);
this.hideToc = true;
this.destroyed = new Subject();
this.urlFragment = '';
if (global.config.mode === 'lite') {
OFFSET = 0;
}
this.router.events.pipe(takeUntil(this.destroyed)).subscribe((event) => {
if (event instanceof NavigationEnd) {
const rootUrl = this.locationStrategy.path(false);
if (rootUrl !== this.rootUrl) {
this.rootUrl = rootUrl;
}
}
});
this.route.fragment.pipe(takeUntil(this.destroyed)).subscribe((fragment) => {
this.urlFragment = fragment;
this.tocService.scrollToAnchor(this.urlFragment);
});
this.tocService.links$.pipe(takeUntil(this.destroyed)).subscribe((links) => {
this.hideToc = !links || links.length === 0;
if (!this.hideToc) {
this.tocService.scrollToAnchor(this.urlFragment);
}
});
this.tocService.activeLink$.pipe(takeUntil(this.destroyed)).subscribe((activeLink) => {
this.activeLink = activeLink;
});
}
ngOnInit() { }
ngOnDestroy() {
this.destroyed.next();
}
onLinkClick($event, link) {
// 当前的 urlFragment 和点击相同,阻止默认行为,因为浏览器会按照整个文档可视区域滚动,
// if (link.id === this.urlFragment) {
// $event.preventDefault();
// }
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: TableOfContentsComponent, deps: [{ token: i2$1.Router }, { token: i2$1.ActivatedRoute }, { token: GlobalContext }, { token: i2.LocationStrategy }, { token: TocService }], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.3", type: TableOfContentsComponent, isStandalone: false, selector: "dg-toc", inputs: { container: "container" }, host: { properties: { "class.dg-toc": "this.isToc", "class.dg-d-none": "this.hideToc" } }, ngImport: i0, template: "<div class=\"dg-toc-container\">\n <ul [attr.aria-label]=\"'Table of Contents'\">\n <li\n *ngFor=\"let link of tocService.links$ | async; let i = index\"\n class=\"dg-level-{{ link.type }}\"\n [attr.data-level]=\"link.level - tocService.highestLevel + 1\"\n >\n <a\n class=\"dg-link\"\n [class.active]=\"link === activeLink\"\n (click)=\"onLinkClick($event, link)\"\n [href]=\"rootUrl + '#' + link.id\"\n [attr.data-level]=\"link.level - tocService.highestLevel + 1\"\n >\n {{ link.name }}\n </a>\n </li>\n </ul>\n</div>\n", dependencies: [{ kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "pipe", type: i2.AsyncPipe, name: "async" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: TableOfContentsComponent, decorators: [{
type: Component,
args: [{ selector: 'dg-toc', standalone: false, template: "<div class=\"dg-toc-container\">\n <ul [attr.aria-label]=\"'Table of Contents'\">\n <li\n *ngFor=\"let link of tocService.links$ | async; let i = index\"\n class=\"dg-level-{{ link.type }}\"\n [attr.data-level]=\"link.level - tocService.highestLevel + 1\"\n >\n <a\n class=\"dg-link\"\n [class.active]=\"link === activeLink\"\n (click)=\"onLinkClick($event, link)\"\n [href]=\"rootUrl + '#' + link.id\"\n [attr.data-level]=\"link.level - tocService.highestLevel + 1\"\n >\n {{ link.name }}\n </a>\n </li>\n </ul>\n</div>\n" }]
}], ctorParameters: () => [{ type: i2$1.Router }, { type: i2$1.ActivatedRoute }, { type: GlobalContext }, { type: i2.LocationStrategy }, { type: TocService }], propDecorators: { isToc: [{
type: HostBinding,
args: [`class.dg-toc`]
}], container: [{
type: Input
}], hideToc: [{
type: HostBinding,
args: ['class.dg-d-none']
}] } });
class LocalesSelectorComponent {
constructor(global, navigationService, location) {
this.global = global;
this.navigationService = navigationService;
this.location = location;
this.isNavbar = true;
this.isDropdownOpen = false;
}
ngOnInit() {
this.locale = this.global.locale;
}
openDropdown() {
this.isDropdownOpen = true;
}
closeDropdown() {
this.isDropdownOpen = false;
}
selectLocale(locale) {
this.locale = locale;
this.isDropdownOpen = false;
this.localeModelChange();
}
localeModelChange() {
const isDefaultLocale = this.locale === this.global.config.defaultLocale;
const localKeyFromUrl = this.global.getLocalKeyFromUrl();
if (isDefaultLocale) {
this.global.setLocale(this.locale);
}
const currentPath = this.location.path();
if (localKeyFromUrl) {
this.location.go(currentPath.replace('/' + localKeyFromUrl, isDefaultLocale ? '' : `/${this.locale}`));
}
else {
this.location.go(isDefaultLocale ? currentPath : `/${this.locale}${currentPath}`);
}
// 强制刷新
location.href = location.href;
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: LocalesSelectorComponent, deps: [{ token: GlobalContext }, { token: NavigationService }, { token: i2.Location }], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.3", type: LocalesSelectorComponent, isStandalone: false, selector: "dg-locales-selector", host: { listeners: { "mouseenter": "openDropdown()", "mouseleave": "closeDropdown()" }, properties: { "class.dg-locales-selector": "this.isNavbar" } }, ngImport: i0, template: "<button\n *ngIf=\"global.config.locales && global.config.locales.length > 1\"\n type=\"button\"\n class=\"action-icon\"\n [ngClass]=\"{ active: !!isDropdownOpen }\"\n>\n <dg-icon iconName=\"locale\"></dg-icon>\n</button>\n<div *ngIf=\"!!isDropdownOpen\" class=\"locales-container\">\n <div class=\"locales-menu\">\n <div\n *ngFor=\"let item of global.config.locales\"\n class=\"locale\"\n [ngClass]=\"{ active: item.key === locale }\"\n (click)=\"selectLocale(item.key)\"\n >\n {{ item.name }}\n </div>\n </div>\n</div>\n", dependencies: [{ kind: "directive", type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: IconComponent, selector: "dg-icon", inputs: ["iconName"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: LocalesSelectorComponent, decorators: [{
type: Component,
args: [{ selector: 'dg-locales-selector', standalone: false, template: "<button\n *ngIf=\"global.config.locales && global.config.locales.length > 1\"\n type=\"button\"\n class=\"action-icon\"\n [ngClass]=\"{ active: !!isDropdownOpen }\"\n>\n <dg-icon iconName=\"locale\"></dg-icon>\n</button>\n<div *ngIf=\"!!isDropdownOpen\" class=\"locales-containe