_id
stringlengths 21
254
| text
stringlengths 1
93.7k
| metadata
dict |
---|---|---|
angular/adev/shared-docs/providers/example-viewer-content-loader.ts_0_446 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {InjectionToken} from '@angular/core';
import {ExampleViewerContentLoader} from '../interfaces/index';
export const EXAMPLE_VIEWER_CONTENT_LOADER = new InjectionToken<ExampleViewerContentLoader>(
'EXAMPLE_VIEWER_CONTENT_LOADER',
);
| {
"end_byte": 446,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/providers/example-viewer-content-loader.ts"
} |
angular/adev/shared-docs/providers/docs-content-loader.ts_0_627 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {InjectionToken, inject} from '@angular/core';
import {ResolveFn} from '@angular/router';
import {DocContent, DocsContentLoader} from '../interfaces/index';
export const DOCS_CONTENT_LOADER = new InjectionToken<DocsContentLoader>('DOCS_CONTENT_LOADER');
export function contentResolver(contentPath: string): ResolveFn<DocContent | undefined> {
return () => inject(DOCS_CONTENT_LOADER).getContent(contentPath);
}
| {
"end_byte": 627,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/providers/docs-content-loader.ts"
} |
angular/adev/shared-docs/providers/BUILD.bazel_0_613 | load("//tools:defaults.bzl", "ng_module", "ts_library")
package(default_visibility = ["//visibility:private"])
ts_library(
name = "providers",
srcs = [
"index.ts",
],
visibility = ["//adev/shared-docs:__subpackages__"],
deps = [
":lib",
],
)
ng_module(
name = "lib",
srcs = glob(
[
"**/*.ts",
],
exclude = [
"index.ts",
"**/*.spec.ts",
],
),
deps = [
"//adev/shared-docs/interfaces",
"//packages/common",
"//packages/core",
"//packages/router",
],
)
| {
"end_byte": 613,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/providers/BUILD.bazel"
} |
angular/adev/shared-docs/providers/window.ts_0_759 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {InjectionToken} from '@angular/core';
// Providing window using injection token could increase testability and portability (i.e SSR don't have a real browser environment).
export const WINDOW = new InjectionToken<Window>('WINDOW');
// The project uses prerendering, to resolve issue: 'window is not defined', we should get window from DOCUMENT.
// As it is recommended here: https://github.com/angular/universal/blob/main/docs/gotchas.md#strategy-1-injection
export function windowProvider(document: Document) {
return document.defaultView;
}
| {
"end_byte": 759,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/providers/window.ts"
} |
angular/adev/shared-docs/providers/index.ts_0_462 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
export * from './docs-content-loader';
export * from './environment';
export * from './example-viewer-content-loader';
export * from './is-search-dialog-open';
export * from './local-storage';
export * from './previews-components';
export * from './window';
| {
"end_byte": 462,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/providers/index.ts"
} |
angular/adev/shared-docs/utils/analytics.utils.ts_0_1053 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
declare global {
interface Window {
gtag: (...args: any[]) => void;
}
}
export const setCookieConsent = (state: 'denied' | 'granted'): void => {
try {
if (window.gtag) {
const consentOptions = {
ad_user_data: state,
ad_personalization: state,
ad_storage: state,
analytics_storage: state,
};
if (state === 'denied') {
window.gtag('consent', 'default', {
...consentOptions,
wait_for_update: 500,
});
} else if (state === 'granted') {
window.gtag('consent', 'update', {
...consentOptions,
});
}
}
} catch {
if (state === 'denied') {
console.error('Unable to set default cookie consent.');
} else if (state === 'granted') {
console.error('Unable to grant cookie consent.');
}
}
};
| {
"end_byte": 1053,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/utils/analytics.utils.ts"
} |
angular/adev/shared-docs/utils/filesystem.utils.ts_0_1492 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {normalizePath} from './navigation.utils';
import {FileAndContent} from '../interfaces';
interface DirEnt<T> {
name: T;
isFile(): boolean;
isDirectory(): boolean;
}
interface FileSystemAPI {
readdir(
path: string,
options: {
encoding?:
| 'ascii'
| 'utf8'
| 'utf-8'
| 'utf16le'
| 'ucs2'
| 'ucs-2'
| 'base64'
| 'base64url'
| 'latin1'
| 'binary'
| 'hex'
| null;
withFileTypes: true;
},
): Promise<DirEnt<string>[]>;
readFile(path: string, encoding?: string): Promise<string>;
}
export const checkFilesInDirectory = async (
dir: string,
fs: FileSystemAPI,
filterFoldersPredicate: (path?: string) => boolean = () => true,
files: FileAndContent[] = [],
) => {
const entries = (await fs.readdir(dir, {withFileTypes: true})) ?? [];
for (const entry of entries) {
const fullPath = normalizePath(`${dir}/${entry.name}`);
if (entry.isFile()) {
const content = await fs.readFile(fullPath, 'utf-8');
files.push({content, path: fullPath});
} else if (entry.isDirectory() && filterFoldersPredicate(entry.name)) {
await checkFilesInDirectory(fullPath, fs, filterFoldersPredicate, files);
}
}
return files;
};
| {
"end_byte": 1492,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/utils/filesystem.utils.ts"
} |
angular/adev/shared-docs/utils/animations.utils.ts_0_353 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
export const shouldReduceMotion = () =>
typeof window !== 'undefined' &&
window.matchMedia(`(prefers-reduced-motion: reduce)`).matches === true;
| {
"end_byte": 353,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/utils/animations.utils.ts"
} |
angular/adev/shared-docs/utils/BUILD.bazel_0_696 | load("//tools:defaults.bzl", "ts_library")
package(default_visibility = ["//visibility:private"])
ts_library(
name = "utils",
srcs = [
"index.ts",
],
visibility = ["//adev/shared-docs:__subpackages__"],
deps = [
":lib",
],
)
ts_library(
name = "lib",
srcs = glob(
[
"**/*.ts",
],
exclude = [
"index.ts",
"**/*.spec.ts",
],
),
deps = [
"//adev/shared-docs/interfaces",
"//adev/shared-docs/providers",
"//packages/core",
"//packages/router",
"@npm//@types/node",
"@npm//@webcontainer/api",
"@npm//fflate",
],
)
| {
"end_byte": 696,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/utils/BUILD.bazel"
} |
angular/adev/shared-docs/utils/index.ts_0_437 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
export * from './analytics.utils';
export * from './animations.utils';
export * from './device.utils';
export * from './filesystem.utils';
export * from './navigation.utils';
export * from './url.utils';
export * from './zip.utils';
| {
"end_byte": 437,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/utils/index.ts"
} |
angular/adev/shared-docs/utils/url.utils.ts_0_343 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
export const removeTrailingSlash = (url: string): string => {
if (url.endsWith('/')) {
return url.slice(0, -1);
}
return url;
};
| {
"end_byte": 343,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/utils/url.utils.ts"
} |
angular/adev/shared-docs/utils/zip.utils.ts_0_814 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {FileAndContent} from '../interfaces';
// TODO(josephperrott): Determine how we can load the fflate package dynamically again.
import {zip, strToU8} from 'fflate';
export async function generateZip(files: FileAndContent[]): Promise<Uint8Array> {
const filesObj: Record<string, Uint8Array> = {};
files.forEach(({path, content}) => {
filesObj[path] = typeof content === 'string' ? strToU8(content) : content;
});
return new Promise((resolve, reject) => {
zip(filesObj, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}
| {
"end_byte": 814,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/utils/zip.utils.ts"
} |
angular/adev/shared-docs/utils/navigation.utils.ts_0_3764 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {inject} from '@angular/core';
import {ActivatedRouteSnapshot, Route, Router} from '@angular/router';
import {NavigationItem} from '../interfaces/index';
import {DOCS_CONTENT_LOADER} from '../providers/index';
export const flatNavigationData = (tree: NavigationItem[]) => {
const result: NavigationItem[] = [];
const traverse = (node: NavigationItem, level: number) => {
node.level = level;
if (node.path) {
result.push(node);
}
if (node.children) {
for (const child of node.children) {
child.parent = node;
traverse(child, level + 1);
}
}
};
for (const node of tree) {
traverse(node, 1);
}
return result;
};
export const getNavigationItemsTree = (
tree: NavigationItem[],
mapFn: (item: NavigationItem) => void,
) => {
const traverse = (node: NavigationItem) => {
mapFn(node);
if (node.children) {
for (const child of node.children) {
traverse(child);
}
}
};
for (const node of tree) {
traverse(node);
}
return tree;
};
export const findNavigationItem = (
items: NavigationItem[],
predicate: (item: NavigationItem) => boolean,
): NavigationItem | null => {
let result: NavigationItem | null = null;
const traverse = (node: NavigationItem) => {
if (predicate(node)) {
result = node;
}
if (node.children && !result) {
for (const child of node.children) {
traverse(child);
}
}
};
for (const node of items) {
traverse(node);
}
return result;
};
export const isExternalLink = (link: string, windowOrigin: string) =>
new URL(link).origin !== windowOrigin;
export const markExternalLinks = (item: NavigationItem, origin: string): void => {
if (item.path) {
try {
item.isExternal = isExternalLink(item.path, origin);
} catch (err) {}
}
};
export const mapNavigationItemsToRoutes = (
navigationItems: NavigationItem[],
additionalRouteProperties: Partial<Route>,
): Route[] =>
navigationItems
.filter((route): route is NavigationItem & {path: string} => Boolean(route.path))
.map((navigationItem) => {
const route = {
path: navigationItem.path,
...additionalRouteProperties,
};
route.data = {
...navigationItem,
...route.data,
};
route.resolve = {
'docContent': (snapshot: ActivatedRouteSnapshot) => {
return snapshot.data['contentPath'] !== undefined
? inject(DOCS_CONTENT_LOADER).getContent(snapshot.data['contentPath'])
: undefined;
},
...route.resolve,
};
return route;
});
export const normalizePath = (path: string): string => {
if (path[0] === '/') {
return path.substring(1);
}
return path;
};
export const getBaseUrlAfterRedirects = (url: string, router: Router): string => {
const route = router.parseUrl(url);
route.fragment = null;
route.queryParams = {};
return normalizePath(route.toString());
};
export function handleHrefClickEventWithRouter(e: Event, router: Router, relativeUrl: string) {
const pointerEvent = e as PointerEvent;
if (
pointerEvent.ctrlKey ||
pointerEvent.shiftKey ||
pointerEvent.altKey ||
pointerEvent.metaKey
) {
return;
}
e.preventDefault();
router.navigateByUrl(relativeUrl);
}
export function getActivatedRouteSnapshotFromRouter(router: Router): ActivatedRouteSnapshot {
let route = router.routerState.root.snapshot;
while (route.firstChild) {
route = route.firstChild;
}
return route;
}
| {
"end_byte": 3764,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/utils/navigation.utils.ts"
} |
angular/adev/shared-docs/utils/device.utils.ts_0_793 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
export const isMobile =
typeof window !== 'undefined' && window.navigator.userAgent.toLowerCase().includes('mobi');
export const isApple =
typeof window !== 'undefined' &&
(/iPad|iPhone/.test(window.navigator.userAgent) || window.navigator.userAgent.includes('Mac'));
export const isIpad =
typeof window !== 'undefined' &&
isApple &&
!!window.navigator.maxTouchPoints &&
window.navigator.maxTouchPoints > 1;
export const isIos = (isMobile && isApple) || isIpad;
export const isFirefox =
typeof window !== 'undefined' && window.navigator.userAgent.includes('Firefox/');
| {
"end_byte": 793,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/utils/device.utils.ts"
} |
angular/adev/shared-docs/pipes/relative-link.pipe.spec.ts_0_1139 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {RelativeLink} from './relative-link.pipe';
describe('RelativeLink', () => {
let pipe: RelativeLink;
beforeEach(() => {
pipe = new RelativeLink();
});
it('should transform absolute url to relative', () => {
const absoluteUrl = 'https://angular.dev/guide/directives#test';
const result = pipe.transform(absoluteUrl);
expect(result).toBe('guide/directives#test');
});
it('should return fragment once result param is equal to `hash`', () => {
const absoluteUrl = 'https://angular.dev/guide/directives#test';
const result = pipe.transform(absoluteUrl, 'hash');
expect(result).toBe('test');
});
it('should return relative url without fragment once result param is equal to `pathname`', () => {
const absoluteUrl = 'https://angular.dev/guide/directives#test';
const result = pipe.transform(absoluteUrl, 'pathname');
expect(result).toBe('guide/directives');
});
});
| {
"end_byte": 1139,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/pipes/relative-link.pipe.spec.ts"
} |
angular/adev/shared-docs/pipes/is-active-navigation-item.pipe.spec.ts_0_1733 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {NavigationItem} from '../interfaces';
import {IsActiveNavigationItem} from './is-active-navigation-item.pipe';
describe('IsActiveNavigationItem', () => {
let pipe: IsActiveNavigationItem;
beforeEach(() => {
pipe = new IsActiveNavigationItem();
});
it('should return true when itemToCheck is parent of the activeItem', () => {
const result = pipe.transform(parent, activeItem);
expect(result).toBe(true);
});
it('should return true when itemToCheck is any kind of the ancestor of the activeItem', () => {
const result = pipe.transform(grandparent, activeItem);
expect(result).toBe(true);
});
it('should return false when itemToCheck is not ancestor of the activeItem', () => {
const result = pipe.transform(notRelatedItem, activeItem);
expect(result).toBe(false);
});
it('should return false when activeItem is null', () => {
const result = pipe.transform(notRelatedItem, null);
expect(result).toBe(false);
});
it('should return false when activeItem is parent of the itemToCheck', () => {
const result = pipe.transform(child, activeItem);
expect(result).toBe(false);
});
});
const notRelatedItem: NavigationItem = {
label: 'Example',
};
const grandparent: NavigationItem = {
label: 'Grandparent',
};
const parent: NavigationItem = {
label: 'Parent',
parent: grandparent,
};
const activeItem: NavigationItem = {
label: 'Active Item',
parent: parent,
};
const child: NavigationItem = {
label: 'Child',
parent: activeItem,
};
| {
"end_byte": 1733,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/pipes/is-active-navigation-item.pipe.spec.ts"
} |
angular/adev/shared-docs/pipes/relative-link.pipe.ts_0_857 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {Pipe, PipeTransform} from '@angular/core';
import {normalizePath, removeTrailingSlash} from '../utils/index';
@Pipe({
name: 'relativeLink',
standalone: true,
})
export class RelativeLink implements PipeTransform {
transform(absoluteUrl: string, result: 'relative' | 'pathname' | 'hash' = 'relative'): string {
const url = new URL(normalizePath(absoluteUrl));
if (result === 'hash') {
return url.hash?.substring(1) ?? '';
}
if (result === 'pathname') {
return `${removeTrailingSlash(normalizePath(url.pathname))}`;
}
return `${removeTrailingSlash(normalizePath(url.pathname))}${url.hash ?? ''}`;
}
}
| {
"end_byte": 857,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/pipes/relative-link.pipe.ts"
} |
angular/adev/shared-docs/pipes/BUILD.bazel_0_587 | load("//tools:defaults.bzl", "ng_module", "ts_library")
package(default_visibility = ["//visibility:private"])
ts_library(
name = "pipes",
srcs = [
"index.ts",
],
visibility = ["//adev/shared-docs:__subpackages__"],
deps = [
":lib",
],
)
ng_module(
name = "lib",
srcs = glob(
[
"**/*.ts",
],
exclude = [
"index.ts",
"**/*.spec.ts",
],
),
deps = [
"//adev/shared-docs/interfaces",
"//adev/shared-docs/utils",
"//packages/core",
],
)
| {
"end_byte": 587,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/pipes/BUILD.bazel"
} |
angular/adev/shared-docs/pipes/index.ts_0_88 | export * from './is-active-navigation-item.pipe';
export * from './relative-link.pipe';
| {
"end_byte": 88,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/pipes/index.ts"
} |
angular/adev/shared-docs/pipes/is-active-navigation-item.pipe.ts_0_894 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {Pipe, PipeTransform} from '@angular/core';
import {NavigationItem} from '../interfaces/index';
@Pipe({
name: 'isActiveNavigationItem',
standalone: true,
})
export class IsActiveNavigationItem implements PipeTransform {
// Check whether provided item: `itemToCheck` should be marked as active, based on `activeItem`.
// In addition to `activeItem`, we should mark all its parents, grandparents, etc. as active.
transform(itemToCheck: NavigationItem, activeItem: NavigationItem | null): boolean {
let node = activeItem?.parent;
while (node) {
if (node === itemToCheck) {
return true;
}
node = node.parent;
}
return false;
}
}
| {
"end_byte": 894,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/pipes/is-active-navigation-item.pipe.ts"
} |
angular/adev/shared-docs/testing/testing-helper.ts_0_5755 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ChangeDetectorRef} from '@angular/core';
import {
DirEnt,
ErrorListener,
FSWatchCallback,
FSWatchOptions,
FileSystemAPI,
FileSystemTree,
IFSWatcher,
PortListener,
ServerReadyListener,
Unsubscribe,
WebContainer,
WebContainerProcess,
} from '@webcontainer/api';
export class FakeEventTarget implements EventTarget {
listeners: Map<string, EventListenerOrEventListenerObject[]> = new Map();
addEventListener(type: string, listener: EventListenerOrEventListenerObject): void {
const listeners = this.listeners.get(type) || [];
listeners.push(listener);
this.listeners.set(type, listeners);
}
removeEventListener(type: string, listener: EventListenerOrEventListenerObject): void {
const listeners = this.listeners.get(type);
if (listeners) {
const index = listeners.indexOf(listener);
if (index !== -1) {
listeners.splice(index, 1);
}
}
}
dispatchEvent(event: Event): boolean {
const listeners = this.listeners.get(event.type);
if (listeners) {
for (const listener of listeners) {
if (typeof listener === 'function') {
listener.call(this, event);
} else {
listener.handleEvent(event);
}
}
}
return true;
}
}
export class MockLocalStorage implements Pick<Storage, 'getItem' | 'setItem'> {
private items = new Map<string, string | null>();
getItem(key: string): string | null {
return this.items.get(key) ?? null;
}
setItem(key: string, value: string | null): void {
this.items.set(key, value);
}
}
export class FakeChangeDetectorRef implements ChangeDetectorRef {
markForCheck(): void {}
detach(): void {}
checkNoChanges(): void {}
reattach(): void {}
detectChanges(): void {}
}
export class FakeWebContainer extends WebContainer {
fakeSpawn: FakeWebContainerProcess | undefined = undefined;
constructor(fakeOptions?: {spawn: FakeWebContainerProcess}) {
super();
if (fakeOptions?.spawn) this.fakeSpawn = fakeOptions.spawn;
}
override spawn(
command: unknown,
args?: unknown,
options?: unknown,
): Promise<FakeWebContainerProcess> {
if (this.fakeSpawn) return Promise.resolve(this.fakeSpawn);
const fakeProcess = new FakeWebContainerProcess();
return Promise.resolve(fakeProcess);
}
override on(event: 'port', listener: PortListener): Unsubscribe;
override on(event: 'server-ready', listener: ServerReadyListener): Unsubscribe;
override on(event: 'error', listener: ErrorListener): Unsubscribe;
override on(event: unknown, listener: unknown): Unsubscribe {
return () => {};
}
override mount(
tree: FileSystemTree,
options?: {mountPoint?: string | undefined} | undefined,
): Promise<void> {
return Promise.resolve();
}
override get path() {
return '/fake-path';
}
override get workdir() {
return '/fake-workdir';
}
override teardown() {}
override fs: FakeFileSystemAPI = new FakeFileSystemAPI();
}
class FakeFileSystemAPI implements FileSystemAPI {
readdir(
path: string,
options: 'buffer' | {encoding: 'buffer'; withFileTypes?: false | undefined},
): Promise<Uint8Array[]>;
readdir(
path: string,
options?:
| string
| {encoding?: string | null | undefined; withFileTypes?: false | undefined}
| null
| undefined,
): Promise<string[]>;
readdir(
path: string,
options: {encoding: 'buffer'; withFileTypes: true},
): Promise<DirEnt<Uint8Array>[]>;
readdir(
path: string,
options: {encoding?: string | null | undefined; withFileTypes: true},
): Promise<DirEnt<string>[]>;
readdir(
path: unknown,
options?: unknown,
):
| Promise<Uint8Array[]>
| Promise<string[]>
| Promise<DirEnt<Uint8Array>[]>
| Promise<DirEnt<string>[]> {
return Promise.resolve(['/fake-dirname']);
}
readFile(path: string, encoding?: null | undefined): Promise<Uint8Array>;
readFile(path: string, encoding: string): Promise<string>;
readFile(path: unknown, encoding?: unknown): Promise<Uint8Array> | Promise<string> {
return Promise.resolve('fake file content');
}
writeFile(
path: string,
data: string | Uint8Array,
options?: string | {encoding?: string | null | undefined} | null | undefined,
): Promise<void> {
return Promise.resolve();
}
mkdir(path: string, options?: {recursive?: false | undefined} | undefined): Promise<void>;
mkdir(path: string, options: {recursive: true}): Promise<string>;
mkdir(path: unknown, options?: unknown): Promise<void> | Promise<string> {
return Promise.resolve();
}
rm(
path: string,
options?: {force?: boolean | undefined; recursive?: boolean | undefined} | undefined,
): Promise<void> {
return Promise.resolve();
}
rename(oldPath: string, newPath: string): Promise<void> {
throw Error('Not implemented');
}
watch(
filename: string,
options?: FSWatchOptions | undefined,
listener?: FSWatchCallback | undefined,
): IFSWatcher;
watch(filename: string, listener?: FSWatchCallback | undefined): IFSWatcher;
watch(filename: unknown, options?: unknown, listener?: unknown): IFSWatcher {
throw Error('Not implemented');
}
}
export class FakeWebContainerProcess implements WebContainerProcess {
exit: Promise<number> = Promise.resolve(0);
input: WritableStream<string> = new WritableStream<string>();
output: ReadableStream<string> = new ReadableStream<string>();
kill(): void {}
resize(dimensions: {cols: number; rows: number}): void {}
}
| {
"end_byte": 5755,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/testing/testing-helper.ts"
} |
angular/adev/shared-docs/testing/BUILD.bazel_0_504 | load("//tools:defaults.bzl", "ts_library")
package(default_visibility = ["//visibility:private"])
ts_library(
name = "testing",
srcs = [
"index.ts",
],
visibility = ["//adev/shared-docs:__subpackages__"],
deps = [
":lib",
],
)
ts_library(
name = "lib",
srcs = glob(
[
"*.ts",
],
exclude = [
"index.ts",
],
),
deps = [
"//packages/core",
"@npm//@webcontainer/api",
],
)
| {
"end_byte": 504,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/testing/BUILD.bazel"
} |
angular/adev/shared-docs/testing/index.ts_0_238 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
export * from './testing-helper';
| {
"end_byte": 238,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/testing/index.ts"
} |
angular/adev/shared-docs/styles/_z-index.scss_0_139 | :root {
--z-index-mini-menu: 200;
--z-index-nav: 100;
--z-index-cookie-consent: 60;
--z-index-content: 50;
--z-index-icon: 10;
}
| {
"end_byte": 139,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/_z-index.scss"
} |
angular/adev/shared-docs/styles/_split.scss_0_557 | $gutter-border: 1px solid var(--senary-contrast) !important;
as-split {
::ng-deep .as-split-gutter {
flex-basis: 5px !important;
background-color: inherit !important;
position: relative;
}
&.as-horizontal.docs-editor {
::ng-deep .as-split-gutter {
border-inline: $gutter-border;
}
}
&.as-vertical.docs-editor {
::ng-deep .as-split-gutter {
border-block-start: $gutter-border;
}
}
&.as-vertical.docs-right-side {
::ng-deep .as-split-gutter {
border-block-start: $gutter-border;
}
}
}
| {
"end_byte": 557,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/_split.scss"
} |
angular/adev/shared-docs/styles/_colors.scss_0_195 | // Colors
// Using OKLCH color space for better color reproduction on P3 displays,
// as well as better human-readability
// --> https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/oklch | {
"end_byte": 195,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/_colors.scss"
} |
angular/adev/shared-docs/styles/_colors.scss_197_5071 | @mixin root-definitions() {
// PRIMITIVES
// Colors
--bright-blue: oklch(51.01% 0.274 263.83); // #0546ff
--indigo-blue: oklch(51.64% 0.229 281.65); // #5c44e4
--electric-violet: oklch(53.18% 0.28 296.97); // #8514f5
--french-violet: oklch(47.66% 0.246 305.88); // #8001c6
--vivid-pink: oklch(69.02% 0.277 332.77); // #f637e3
--hot-pink: oklch(59.91% 0.239 8.14); // #e90464
--hot-red: oklch(61.42% 0.238 15.34); // #f11653
--orange-red: oklch(63.32% 0.24 31.68); // #fa2c04
--super-green: oklch(79.12% 0.257 155.13); // #00c572 // Used for success, merge additions, etc.
// subtle-purple is used for inline-code bg, docs-card hover bg & docs-code header bg
--subtle-purple: color-mix(in srgb, var(--bright-blue) 5%, white 10%);
--light-blue: color-mix(in srgb, var(--bright-blue), white 50%);
--light-violet: color-mix(in srgb, var(--electric-violet), white 65%);
--light-orange: color-mix(in srgb, var(--orange-red), white 50%);
--light-pink: color-mix(in srgb, var(--vivid-pink) 10%, white 80%);
// SYMBOLIC COLORS
// Used for Type Labels
--symbolic-purple: oklch(42.86% 0.29 266.4); //#1801ea
--symbolic-gray: oklch(66.98% 0 0); // #959595
--symbolic-blue: oklch(42.45% 0.223 263.38); // #0037c5;
--symbolic-pink: oklch(63.67% 0.254 13.47); // #ff025c
--symbolic-orange: oklch(64.73% 0.23769984683784018 33.18328352127882); // #fe3700
--symbolic-yellow: oklch(78.09% 0.163 65.69); // #fd9f28
--symbolic-green: oklch(67.83% 0.229 142.73); // #00b80a
--symbolic-cyan: oklch(67.05% 0.1205924489987394 181.34025902203868); // #00ad9a
--symbolic-magenta: oklch(51.74% 0.25453048882711515 315.26261625862725); // #9c00c8
--symbolic-teal: oklch(57.59% 0.083 230.58); // #3f82a1
--symbolic-brown: oklch(49.06% 0.128 46.41); // #994411
--symbolic-lime: oklch(70.33% 0.2078857836035299 135.66843631046476); // #5dba00
// Grays
--gray-1000: oklch(16.93% 0.004 285.95); // #0f0f11
--gray-900: oklch(19.37% 0.006 300.98); // #151417
--gray-800: oklch(25.16% 0.008 308.11); // #232125
--gray-700: oklch(36.98% 0.014 302.71); // #413e46
--gray-600: oklch(44% 0.019 306.08); // #55505b
--gray-500: oklch(54.84% 0.023 304.99); // #746e7c
--gray-400: oklch(70.9% 0.015 304.04); // #a39fa9
--gray-300: oklch(84.01% 0.009 308.34); // #ccc9cf
--gray-200: oklch(91.75% 0.004 301.42); // #e4e3e6
--gray-100: oklch(97.12% 0.002 325.59); // #f6f5f6
--gray-50: oklch(98.81% 0 0); // #fbfbfb
// GRADIENTS
--red-to-pink-horizontal-gradient: linear-gradient(
90deg,
var(--hot-pink) 11.42%,
var(--hot-red) 34.83%,
var(--vivid-pink) 60.69%
);
--red-to-pink-to-purple-horizontal-gradient: linear-gradient(
90deg,
var(--orange-red) 0%,
var(--vivid-pink) 50%,
var(--electric-violet) 100%
);
--pink-to-highlight-to-purple-to-blue-horizontal-gradient: linear-gradient(
140deg,
var(--vivid-pink) 0%,
var(--vivid-pink) 15%,
color-mix(in srgb, var(--vivid-pink), var(--electric-violet) 50%) 25%,
color-mix(in srgb, var(--vivid-pink), var(--electric-violet) 10%) 35%,
color-mix(in srgb, var(--vivid-pink), var(--orange-red) 50%) 42%,
color-mix(in srgb, var(--vivid-pink), var(--orange-red) 50%) 44%,
color-mix(in srgb, var(--vivid-pink), var(--page-background) 70%) 47%,
var(--electric-violet) 48%,
var(--bright-blue) 60%
);
--purple-to-blue-horizontal-gradient: linear-gradient(
90deg,
var(--electric-violet) 0%,
var(--bright-blue) 100%
);
--purple-to-blue-vertical-gradient: linear-gradient(
0deg,
var(--electric-violet) 0%,
var(--bright-blue) 100%
);
--red-to-orange-horizontal-gradient: linear-gradient(
90deg,
var(--hot-pink) 0%,
var(--orange-red) 100%
);
--red-to-orange-vertical-gradient: linear-gradient(
0deg,
var(--hot-pink) 0%,
var(--orange-red) 100%
);
--pink-to-purple-horizontal-gradient: linear-gradient(
90deg,
var(--vivid-pink) 0%,
var(--electric-violet) 100%
);
--pink-to-purple-vertical-gradient: linear-gradient(
0deg,
var(--electric-violet) 0%,
var(--vivid-pink) 100%
);
--purple-to-light-purple-vertical-gradient: linear-gradient(
0deg,
var(--french-violet) 0%,
var(--light-violet) 100%
);
--green-to-cyan-vertical-gradient: linear-gradient(
0deg,
var(--symbolic-cyan) 0%,
var(--super-green) 100%
);
--blue-to-teal-vertical-gradient: linear-gradient(
0deg,
var(--bright-blue) 0%,
var(--light-blue) 100%
);
--blue-to-cyan-vertical-gradient: linear-gradient(
0deg,
var(--bright-blue) 0%,
var(--symbolic-cyan) 100%
);
--black-to-gray-vertical-gradient: linear-gradient(
0deg,
var(--primary-contrast) 0%,
var(--gray-400) 100%
);
--red-to-pink-vertical-gradient: linear-gradient(0deg, var(--hot-red) 0%, var(--vivid-pink) 100%); | {
"end_byte": 5071,
"start_byte": 197,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/_colors.scss"
} |
angular/adev/shared-docs/styles/_colors.scss_5074_10536 | --orange-to-pink-vertical-gradient: linear-gradient(
0deg,
var(--vivid-pink) 0%,
var(--light-orange) 100%
);
// Radial Gradients
--page-bg-radial-gradient: radial-gradient(circle, white 0%, white 100%);
--soft-pink-radial-gradient: radial-gradient(
circle at center bottom,
var(--light-pink) 0%,
white 80%
);
// ABSTRACTIONS light - dark
// --full-contrast: black - white
// --primary-constrast: gray-900 - gray-100
// --secondary-contrast: gray-800 - gray-300
// --tertiary-contrast: gray-700 - gray-300
// --quaternary-contrast: gray-500 - gray-400
// --quinary-contrast: gray-300 - gray-500
// --senary-contrast: gray-200 - gray-700
// --septenary-contrast: gray-100 - gray-800
// --octonary-contrast: gray-50 - gray-900
// --page-background white - gray-1000
// LIGHT MODE is default
// contrast - light mode
--full-contrast: black;
--primary-contrast: var(--gray-900);
--secondary-contrast: var(--gray-800);
--tertiary-contrast: var(--gray-700);
--quaternary-contrast: var(--gray-500);
--quinary-contrast: var(--gray-300);
--senary-contrast: var(--gray-200);
--septenary-contrast: var(--gray-100);
--octonary-contrast: var(--gray-50);
--page-background: white;
// Home page
// for the "unfilled" portion of the word that hasn't
// been highlighted by the gradient
--gray-unfilled: var(--gray-400);
// TODO: convert oklch to hex at build time
--webgl-page-background: #ffffff;
--webgl-gray-unfilled: #a39fa9;
}
@mixin dark-mode-definitions() {
// Contrasts
--full-contrast: white;
--primary-contrast: var(--gray-50);
--secondary-contrast: var(--gray-300);
--tertiary-contrast: var(--gray-300);
--quaternary-contrast: var(--gray-400);
--quinary-contrast: var(--gray-500);
--senary-contrast: var(--gray-700);
--septenary-contrast: var(--gray-800);
--octonary-contrast: var(--gray-900);
--page-background: var(--gray-1000);
--bright-blue: color-mix(in srgb, oklch(51.01% 0.274 263.83), var(--full-contrast) 60%);
--indigo-blue: color-mix(in srgb, oklch(51.64% 0.229 281.65), var(--full-contrast) 70%);
--electric-violet: color-mix(in srgb, oklch(53.18% 0.28 296.97), var(--full-contrast) 70%);
--french-violet: color-mix(in srgb, oklch(47.66% 0.246 305.88), var(--full-contrast) 70%);
--vivid-pink: color-mix(in srgb, oklch(69.02% 0.277 332.77), var(--full-contrast) 70%);
--hot-pink: color-mix(in srgb, oklch(59.91% 0.239 8.14), var(--full-contrast) 70%);
--hot-red: color-mix(in srgb, oklch(61.42% 0.238 15.34), var(--full-contrast) 70%);
--orange-red: color-mix(in srgb, oklch(63.32% 0.24 31.68), var(--full-contrast) 60%);
--super-green: color-mix(in srgb, oklch(79.12% 0.257 155.13), var(--full-contrast) 70%);
--light-pink: color-mix(in srgb, var(--vivid-pink) 5%, var(--page-background) 75%);
--symbolic-purple: color-mix(in srgb, oklch(42.86% 0.29 266.4), var(--full-contrast) 65%);
--symbolic-gray: color-mix(in srgb, oklch(66.98% 0 0), var(--full-contrast) 65%);
--symbolic-blue: color-mix(in srgb, oklch(42.45% 0.223 263.38), var(--full-contrast) 65%);
--symbolic-pink: color-mix(in srgb, oklch(63.67% 0.254 13.47), var(--full-contrast) 65%);
--symbolic-orange: color-mix(
in srgb,
oklch(64.73% 0.23769984683784018 33.18328352127882),
var(--full-contrast) 65%
);
--symbolic-yellow: color-mix(in srgb, oklch(78.09% 0.163 65.69), var(--full-contrast) 65%);
--symbolic-green: color-mix(in srgb, oklch(67.83% 0.229 142.73), var(--full-contrast) 65%);
--symbolic-cyan: color-mix(
in srgb,
oklch(67.05% 0.1205924489987394 181.34025902203868),
var(--full-contrast) 65%
);
--symbolic-magenta: color-mix(
in srgb,
oklch(51.74% 0.25453048882711515 315.26261625862725),
var(--full-contrast) 65%
);
--symbolic-teal: color-mix(in srgb, oklch(57.59% 0.083 230.58), var(--full-contrast) 65%);
--symbolic-brown: color-mix(in srgb, oklch(49.06% 0.128 46.41), var(--full-contrast) 65%);
--symbolic-lime: color-mix(
in srgb,
oklch(70.33% 0.2078857836035299 135.66843631046476),
var(--full-contrast) 65%
);
--page-bg-radial-gradient: radial-gradient(circle, black 0%, black 100%);
--soft-pink-radial-gradient: radial-gradient(
circle at center bottom,
var(--light-pink) 0%,
color-mix(in srgb, black, transparent 15%) 80%
);
// Home page - dark mode
--gray-unfilled: var(--gray-700);
// TODO: convert oklch to hex at build time
--webgl-page-background: #0f0f11;
--webgl-gray-unfilled: #413e46;
.docs-toggle {
input {
&:checked + .docs-slider {
background: var(--pink-to-purple-horizontal-gradient) !important;
}
}
}
}
@mixin mdc-definitions() {
--mdc-snackbar-container-shape: 0.25rem;
--mdc-snackbar-container-color: var(--page-background);
--mdc-snackbar-supporting-text-color: var(--primary-contrast);
}
// LIGHT MODE (Explicit)
.docs-light-mode {
background-color: #ffffff;
@include root-definitions();
@include mdc-definitions();
.docs-invert-mode {
@include dark-mode-definitions();
@include mdc-definitions();
}
}
// DARK MODE (Explicit)
.docs-dark-mode {
background-color: oklch(16.93% 0.004 285.95);
@include root-definitions();
@include dark-mode-definitions();
@include mdc-definitions();
.docs-invert-mode {
@include root-definitions();
@include mdc-definitions();
}
} | {
"end_byte": 10536,
"start_byte": 5074,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/_colors.scss"
} |
angular/adev/shared-docs/styles/_typography.scss_0_2366 | // Base Typography styles
@mixin typography() {
:root {
--code-font: 'DM Mono', monospace;
--inter-font: 'Inter', var(--fallback-font-stack);
--inter-tight-font: 'Inter Tight', var(--fallback-font-stack);
--icons: 'Material Symbols Outlined';
--selection-background: var(--vivid-pink);
--selection-color: var(--vivid-pink);
}
:nth-child(6n + 1) {
--selection-color: var(--vivid-pink);
}
:nth-child(6n + 2) {
--selection-background: var(--hot-pink);
--selection-color: var(--hot-pink);
}
:nth-child(6n + 3) {
--selection-background: var(--electric-violet);
--selection-color: var(--electric-violet);
}
:nth-child(6n + 4) {
--selection-background: var(--french-violet);
--selection-color: var(--french-violet);
}
:nth-child(6n + 5) {
--selection-background: var(--indigo-blue);
--selection-color: var(--indigo-blue);
}
:nth-child(6n + 6) {
--selection-background: var(--bright-blue);
--selection-color: var(--bright-blue);
}
::selection {
// Added fallback color due to browser idiosyncrasies with color-mix and ::selection
background: color-mix(in srgb, var(--selection-background) 10%, var(--octonary-contrast));
color: color-mix(in srgb, var(--selection-color) 40%, var(--primary-contrast));
}
h1,
h2,
h3,
h4,
h5,
h6 {
font-family: var(--inter-tight-font);
font-weight: 500;
text-wrap: balance;
}
p {
font-size: 0.875rem;
line-height: 1.4rem;
font-weight: 400;
letter-spacing: -0.00875rem;
}
p ~ ul,
p ~ ol {
margin-block-start: 0;
}
ul,
ol {
font-size: 0.875rem;
line-height: 1.4rem;
font-weight: 400;
letter-spacing: -0.01rem;
}
a {
text-decoration: none;
font-weight: 500;
transition: color 0.3s ease;
}
p > a,
td > a,
div > a:not(.docs-card),
code > a,
li:not(.docs-faceted-list *) a {
color: var(--bright-blue);
&:hover {
color: var(--vivid-pink);
}
&:active {
color: var(--hot-red);
}
}
p > a,
.docs-list a,
.docs-card a {
margin-block: 0;
text-decoration: underline;
}
hr {
border: 0;
border-block-start-width: 1px;
border-style: solid;
border-color: var(--senary-contrast);
width: 100%;
margin-block: 1rem;
transition: border-color 0.3s ease;
}
}
| {
"end_byte": 2366,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/_typography.scss"
} |
angular/adev/shared-docs/styles/_api-item-label.scss_0_2167 | @mixin api-item-label() {
.docs-api-item-label {
--label-theme: var(--symbolic-purple);
display: flex;
justify-content: center;
align-items: center;
font-weight: 500;
color: var(--label-theme);
background: color-mix(in srgb, var(--label-theme) 10%, white);
border-radius: 0.25rem;
transition:
color 0.3s ease,
background-color 0.3s ease;
text-transform: capitalize;
&[data-mode='short'] {
height: 22px;
width: 22px;
}
&[data-mode='full'] {
font-size: 0.75rem;
padding: 0.25rem 0.5rem;
}
a {
color: var(--label-theme);
&:hover {
text-decoration: underline;
}
}
@media screen and (prefers-color-scheme: dark) {
background: color-mix(in srgb, var(--label-theme) 17%, #272727);
}
.docs-dark-mode & {
background: color-mix(in srgb, var(--label-theme) 17%, #272727);
}
.docs-light-mode & {
background: color-mix(in srgb, var(--label-theme) 10%, white);
}
&[data-type='undecorated_class'],
&[data-type='class'] {
--label-theme: var(--symbolic-purple);
}
&[data-type='constant'],
&[data-type='const'] {
--label-theme: var(--symbolic-gray);
}
&[data-type='decorator'] {
--label-theme: var(--symbolic-blue);
}
&[data-type='directive'] {
--label-theme: var(--symbolic-pink);
}
&[data-type='element'] {
--label-theme: var(--symbolic-orange);
}
&[data-type='enum'] {
--label-theme: var(--symbolic-yellow);
}
&[data-type='function'] {
--label-theme: var(--symbolic-green);
}
&[data-type='interface'] {
--label-theme: var(--symbolic-cyan);
}
&[data-type='pipe'] {
--label-theme: var(--symbolic-teal);
}
&[data-type='ng_module'] {
--label-theme: var(--symbolic-brown);
}
&[data-type='type_alias'] {
--label-theme: var(--symbolic-lime);
}
&[data-type='block'] {
--label-theme: var(--vivid-pink);
}
&[data-type='developer_preview'],
&[data-type='deprecated'] {
--label-theme: var(--hot-red);
}
}
}
| {
"end_byte": 2167,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/_api-item-label.scss"
} |
angular/adev/shared-docs/styles/_scroll-track.scss_0_1631 | @mixin scroll-track {
// used on secondary nav
.docs-scroll-hide {
&::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0);
}
&::-webkit-scrollbar {
width: 0;
}
}
// used for main page scroll
.docs-scroll-track-transparent-large {
&::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0);
cursor: pointer;
}
&::-webkit-scrollbar {
width: 8px;
height: 8px;
}
&::-webkit-scrollbar-thumb {
background-color: var(--quinary-contrast);
border-radius: 10px;
transition: background-color 0.3s ease;
}
&::-webkit-scrollbar-thumb:hover {
background-color: var(--quaternary-contrast);
}
}
// used on table & secondary navigation
.docs-scroll-track-transparent {
&::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0);
cursor: pointer;
}
&::-webkit-scrollbar {
width: 6px;
height: 6px;
}
&::-webkit-scrollbar-thumb {
background-color: var(--senary-contrast);
border-radius: 10px;
transition: background-color 0.3s ease;
}
&::-webkit-scrollbar-thumb:hover {
background-color: var(--quaternary-contrast);
}
}
// used on docs-code blocks
.docs-mini-scroll-track {
&::-webkit-scrollbar-track {
background: transparent;
}
&::-webkit-scrollbar {
width: 6px;
height: 6px;
}
&::-webkit-scrollbar-thumb {
background-color: var(--senary-contrast);
border-radius: 10px;
}
&::-webkit-scrollbar-thumb:hover {
background-color: var(--quinary-contrast);
}
}
}
| {
"end_byte": 1631,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/_scroll-track.scss"
} |
angular/adev/shared-docs/styles/global-styles.scss_0_3528 | // TODO: Continue organizing and refactoring this file
@use '@angular/material' as mat;
// Using disable-next-line to avoid stylelint errors - these imports are necessary
// TODO: Is there another way to prevent these linting errors?
// stylelint-disable-next-line @angular/no-unused-import
@use '_colors';
// stylelint-disable-next-line @angular/no-unused-import
@use '_z-index';
// Global
@use 'resets';
@use 'typography';
@use 'scroll-track';
@use 'button';
@use 'kbd';
@use 'api-item-label';
@use 'faceted-list';
@use 'media-queries' as mq;
// Docs
@use 'docs/alert';
@use 'docs/callout';
@use 'docs/card';
@use 'docs/code';
@use 'docs/decorative-header';
@use 'docs/icon';
@use 'docs/pill';
@use 'docs/steps';
@use 'docs/table';
@use 'docs/video';
@use 'docs/mermaid';
// Global
@include resets.resets();
@include typography.typography();
@include scroll-track.scroll-track();
@include button.button();
@include kbd.kbd();
@include api-item-label.api-item-label();
@include faceted-list.faceted-list();
@include mq.for-phone-only();
@include mq.for-tablet-portrait-up();
@include mq.for-tablet-landscape-up();
@include mq.for-desktop-up();
@include mq.for-big-desktop-up();
@include mq.for-tablet-landscape-down();
// temporary just to show different options of code component UI.
$primary: mat.m2-define-palette(mat.$m2-indigo-palette);
$accent: mat.m2-define-palette(mat.$m2-pink-palette, A200, A100, A400);
$theme: mat.m2-define-light-theme(
(
color: (
primary: $primary,
accent: $accent,
),
typography: mat.m2-define-typography-config(),
)
);
// Include material core styles.
@include mat.core();
@include mat.tabs-theme($theme);
@include mat.button-toggle-theme($theme);
@include mat.tooltip-theme($theme);
// Include custom docs styles
@include alert.docs-alert();
@include callout.docs-callout();
@include card.docs-card();
@include code.docs-code-block();
@include code.docs-code-editor();
@include decorative-header.docs-decorative-header();
@include icon.docs-icon();
@include pill.docs-pill();
@include steps.docs-steps();
@include code.docs-syntax-highlighting();
@include table.docs-table();
@include video.docs-video();
// Include custom angular.dev styles
// Disable view transitions when reduced motion is requested.
@media (prefers-reduced-motion) {
::view-transition-group(*),
::view-transition-old(*),
::view-transition-new(*) {
animation: none !important;
}
}
.docs-dark-mode .shiki {
color: var(--shiki-dark);
background-color: var(--shiki-dark-bg);
span {
color: var(--shiki-dark);
background-color: var(--shiki-dark-bg);
/* Optional, if you also want font styles */
font-style: var(--shiki-dark-font-style);
font-weight: var(--shiki-dark-font-weight);
}
.shiki-ln-line-highlighted,
button:hover {
span {
background-color: inherit;
}
}
}
.shiki {
padding-block: 1rem;
&.cli {
padding-inline-start: 1rem;
}
a {
color: inherit;
&:hover {
text-decoration: underline;
}
}
}
.docs-light-mode .shiki {
color: var(--shiki-light);
background-color: var(--shiki-light-bg);
span {
color: var(--shiki-light);
background-color: var(--shiki-light-bg);
/* Optional, if you also want font styles */
font-style: var(--shiki-light-font-style);
font-weight: var(--shiki-light-font-weight);
text-decoration: var(--shiki-light-text-decoration);
}
.shiki-ln-line-highlighted,
button:hover {
span {
background-color: inherit;
}
}
}
| {
"end_byte": 3528,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/global-styles.scss"
} |
angular/adev/shared-docs/styles/_button.scss_0_3106 | @mixin button() {
button {
font-family: var(--inter-font);
background: transparent;
-webkit-appearance: none;
border: 0;
font-weight: 600;
// Remove excess padding and border in Firefox 4+
&::-moz-focus-inner {
border: 0;
padding: 0;
}
&:disabled {
cursor: not-allowed;
}
}
@property --angle {
syntax: '<angle>';
initial-value: 90deg;
inherits: false;
}
@keyframes spin-gradient {
0% {
--angle: 90deg;
}
100% {
--angle: 450deg;
}
}
.docs-primary-btn {
cursor: pointer;
border: none;
outline: none;
position: relative;
border-radius: 0.25rem;
padding: 0.75rem 1.5rem;
width: max-content;
color: transparent;
// border gradient / background
--angle: 90deg;
background: linear-gradient(
var(--angle),
var(--orange-red) 0%,
var(--vivid-pink) 50%,
var(--electric-violet) 100%
);
docs-icon {
z-index: var(--z-index-content);
position: relative;
}
// text & radial gradient
&::before {
content: attr(text);
position: absolute;
inset: 1px;
background: var(--page-bg-radial-gradient);
border-radius: 0.2rem;
display: flex;
align-items: center;
justify-content: center;
transition: opacity 0.3s ease, background 0.3s ease;
color: var(--primary-contrast);
}
// solid color negative space - CSS transition supported
&::after {
content: attr(text);
position: absolute;
inset: 1px;
background: var(--page-background);
border-radius: 0.2rem;
display: flex;
align-items: center;
justify-content: center;
transition: opacity 0.3s ease, background 0.3s ease;
color: var(--primary-contrast);
}
&:hover {
animation: spin-gradient 4s linear infinite forwards;
&::before {
background-color: var(--page-background);
background: var(--soft-pink-radial-gradient);
opacity: 0.9;
}
&::after {
opacity: 0;
}
}
&:active {
&::before {
opacity: 0.8;
}
}
&:disabled {
//gradient stroke
background: var(--quinary-contrast);
color: var(--quinary-contrast);
&::before {
background-color: var(--page-background);
background: var(--page-bg-radial-gradient);
opacity: 1;
}
docs-icon {
color: var(--quinary-contrast);
}
}
docs-icon {
z-index: var(--z-index-icon);
color: var(--primary-contrast);
}
}
.docs-secondary-btn {
border: 1px solid var(--senary-contrast);
background: var(--page-background);
padding: 0.75rem 1.5rem;
border-radius: 0.25rem;
color: var(--primary-contrast);
transition: background 0.3s ease;
docs-icon {
color: var(--quaternary-contrast);
transition: color 0.3s ease;
}
&:hover {
background: var(--septenary-contrast);
docs-icon {
color: var(--primary-contrast);
}
}
}
}
| {
"end_byte": 3106,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/_button.scss"
} |
angular/adev/shared-docs/styles/_kbd.scss_0_902 | @mixin kbd() {
// We only target non-nested kbd elements
kbd:not(:has(kbd)) {
position: relative;
color: var(---tertiary-contrast);
border: 1px solid var(--quinary-contrast);
box-shadow:
0 1px 0 rgba(0, 0, 0, 0.2),
0 0 0 2px var(--octonary-contrast) inset;
// NOTE: This line (in addition to others) prevents proper contrast checking in Lighthouse
text-shadow: 0 1px 0 var(--octonary-contrast);
border-radius: 3px;
display: inline-block;
font-family: sans-serif;
line-height: 1.5;
margin: 0 0.1em;
padding: 1px 0.4em;
min-width: 14px;
min-height: 20px;
vertical-align: middle;
text-align: center;
@media (prefers-reduced-motion: no-preference) {
*:hover > & {
box-shadow:
0 0.5px 0 rgba(0, 0, 0, 0.2),
0 0 0 2px var(--octonary-contrast) inset;
top: 1px;
}
}
}
}
| {
"end_byte": 902,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/_kbd.scss"
} |
angular/adev/shared-docs/styles/_links.scss_0_233 | @mixin external-link-with-icon() {
&::after {
display: inline-block;
content: '\e89e'; // codepoint for "open_in_new"
font-family: 'Material Symbols Outlined';
margin-left: 0.2rem;
vertical-align: middle;
}
}
| {
"end_byte": 233,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/_links.scss"
} |
angular/adev/shared-docs/styles/_faceted-list.scss_0_1506 | @mixin faceted-list() {
.docs-faceted-list {
--faceted-list-border-width: 2px;
list-style: none;
padding: 0;
margin: 0;
border-inline-start: calc(var(--faceted-list-border-width) - 1px) solid var(--senary-contrast);
}
.docs-faceted-list-item {
a,
button:not(.docs-expanded-button) {
position: relative;
background-color: var(--quaternary-contrast);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
transition: background-color 0.3s ease;
line-height: 1.1rem;
&::before {
content: '';
position: absolute;
top: 0;
left: calc(var(--faceted-list-border-width) * -1);
width: var(--faceted-list-border-width);
height: 100%;
background: var(--primary-contrast);
opacity: 0;
transform: scaleY(0.7);
transition: transform 0.3s ease, opacity 0.3s ease;
}
&:hover {
background-color: var(--primary-contrast);
&::before {
opacity: 0.3;
}
}
&.docs-faceted-list-item-active {
// font gradient
background-image: var(--pink-to-purple-vertical-gradient);
&::before {
opacity: 1;
transform: scaleY(1);
background: var(--pink-to-purple-vertical-gradient);
}
&:hover {
&::before {
opacity: 1;
transform: scaleY(1.1);
}
}
}
}
}
// a or button
}
| {
"end_byte": 1506,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/_faceted-list.scss"
} |
angular/adev/shared-docs/styles/_resets.scss_0_6976 | @use './media-queries' as mq;
@mixin resets() {
:root {
--fallback-font-stack: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI',
Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji',
'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
--page-width: 80ch;
--layout-padding: 3.12rem; // a common padding value throughout the layout
--primary-nav-width: 110px;
--secondary-nav-width: 16.25rem;
--fixed-content-height: calc(100vh - var(--layout-padding) * 2);
@include mq.for-tablet-landscape-down {
--layout-padding: 2rem;
}
@include mq.for-phone-only {
--layout-padding: 1rem;
}
}
html {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
// Define the default font for the document
font-family: var(--inter-font);
font-size: 16px;
background-color: var(--page-background);
color: var(--primary-contrast);
transition:
color 0.3s ease,
background-color 0.3s ease;
scroll-behavior: smooth;
}
@media (prefers-reduced-motion) {
html {
scroll-behavior: auto;
}
}
body {
margin: 0;
overflow-y: auto;
overflow-x: hidden;
}
html,
body {
// Ensures that these elements extend to the full height of the viewport
height: 100vh;
min-height: 100vh;
@supports (height: 100svh) {
height: 100svh;
}
}
button {
cursor: pointer;
}
img {
width: 100%;
border-radius: 0.25rem;
overflow: hidden;
margin: 1rem 0;
&[src$='#small'] {
max-width: 250px;
}
&[src$='#medium'] {
max-width: 450px;
}
}
abbr[title] {
text-decoration: none;
}
// Select & Input
.docs-form-element {
display: flex;
align-items: center;
gap: 0.5rem;
border: 1px solid var(--senary-contrast);
border-radius: 0.25rem;
padding: 0.5rem;
background-color: var(--page-background);
transition:
color 0.3s ease,
background-color 0.3s ease,
border-color 0.3s ease;
docs-icon,
label {
color: var(--quinary-contrast);
transition: color 0.3s ease;
}
label {
font-size: 0.875rem;
}
select,
input {
width: 16rem;
-webkit-appearance: none;
display: flex;
flex: 1;
font-size: 0.875rem;
border: none;
outline: none;
height: 100%;
background-color: var(--page-background);
color: var(--tertiary-contrast);
transition:
color 0.3s ease,
background-color 0.3s ease;
}
select {
width: 10rem;
background-image: url('../icons/chevron.svg');
background-size: 0.7rem;
background-repeat: no-repeat;
background-position: right center;
margin-inline-end: 0.3rem;
}
&:focus-within {
border: 1px solid var(--french-violet);
docs-icon {
color: var(--tertiary-contrast);
}
}
}
// Progress bar styling
.ng-spinner {
display: none !important;
}
.ng-progress-bar {
.ng-bar {
background: var(--red-to-pink-to-purple-horizontal-gradient) !important;
}
}
// Material tab styling
.mat-mdc-tab-header {
--mat-tab-header-disabled-ripple-color: transparent;
--mat-tab-header-pagination-icon-color: var(--secondary-contrast);
--mat-tab-header-inactive-label-text-color: var(--secondary-contrast);
--mat-tab-header-inactive-ripple-color: transparent;
--mat-tab-header-inactive-hover-label-text-color: var(--tertiary-contrast);
--mat-tab-header-inactive-focus-label-text-color: var(--secondary-contrast);
--mat-tab-header-active-label-text-color: var(--primary-contrast);
--mat-tab-header-active-ripple-color: transparent;
--mdc-tab-indicator-active-indicator-color: color-mix(in srgb, var(--bright-blue) 40%, white);
--mat-tab-header-active-focus-label-text-color: var(--primary-contrast);
--mat-tab-header-active-hover-label-text-color: var(--primary-contrast);
--mat-tab-header-active-focus-indicator-color: var(--bright-blue);
--mat-tab-header-active-hover-indicator-color: color-mix(
in srgb,
var(--bright-blue) 40%,
white
);
.mdc-tab {
--mat-tab-header-label-text-font: Inter, sans-serif;
--mat-tab-header-label-text-letter-spacing: -0.00875rem;
--mat-tab-header-label-text-size: 0.875rem;
--mat-tab-header-label-text-weight: 500;
}
.mdc-tab__text-label {
user-select: none;
letter-spacing: -0.00875rem;
}
.mdc-tab--active {
--mat-tab-header-label-text-weight: 500;
}
}
// Material tab styling on Reference page
.docs-reference-tabs {
.mat-mdc-tab-labels {
gap: 20px;
border-bottom: 1px solid var(--senary-contrast);
transition: border-color 0.3s ease;
}
.mdc-tab__text-label {
letter-spacing: -0.00875rem;
}
.mdc-tab {
min-width: min-content !important;
padding-inline: 2px !important;
}
}
// Tabs on Tutorials page, Tutorials Playground
.docs-tutorial-editor,
.docs-code-editor-tabs,
.docs-editor-tabs {
.mat-mdc-tab-header {
--mdc-tab-indicator-active-indicator-color: transparent;
--mat-tab-header-active-focus-indicator-color: transparent;
--mat-tab-header-active-hover-indicator-color: transparent;
--mat-tab-header-label-text-font: InterTight, sans-serif;
--mat-tab-header-label-text-tracking: -0.00875rem;
--mat-tab-header-label-text-size: 0.8125rem;
.mat-mdc-tab-labels {
gap: 0;
transition: border-color 0.3s ease;
width: 100%;
}
.mdc-tab {
padding-inline: 18px !important;
}
.mdc-tab--active {
border: 0;
border-block-end-width: 2px;
border-style: solid;
border-image: var(--pink-to-purple-horizontal-gradient) 1;
&.cdk-keyboard-focused {
border-image: var(--blue-to-cyan-vertical-gradient) 1;
}
&:has(.docs-delete-file) {
padding-inline-start: 18px !important;
padding-inline-end: 0.5px !important;
}
}
}
}
.docs-editor-tabs {
.mat-mdc-tab-header {
border-block-end: 1px solid var(--senary-contrast);
}
}
.docs-code-editor-tabs {
.mat-mdc-tab-group {
// adjust width for + (add file) button
max-width: calc(100% - 40px);
}
}
.docs-editor-tabs,
.docs-code-editor-tabs {
.mat-mdc-tab-header {
background-color: var(--octonary-contrast);
transition:
background-color 0.3s ease,
border-color 0.3s ease;
}
.mdc-tab__text-label {
i {
color: var(--bright-blue);
margin-inline-start: 0.5rem;
margin-inline-end: 0.25rem;
font-size: 1.25rem;
}
span {
color: var(--primary-contrast);
}
}
}
// Tabs inside Example Viewer Header | {
"end_byte": 6976,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/_resets.scss"
} |
angular/adev/shared-docs/styles/_resets.scss_6979_9275 | .docs-example-viewer-actions {
.mat-mdc-tab-labels {
width: 100%;
}
.mat-mdc-tab-header {
--mdc-tab-indicator-active-indicator-color: transparent;
--mat-tab-header-active-focus-indicator-color: transparent;
--mat-tab-header-active-hover-indicator-color: transparent;
--mat-tab-header-active-focus-label-text-color: transparent;
--mat-tab-header-active-hover-label-text-color: transparent;
--mat-tab-header-active-label-text-color: transparent;
--mat-tab-header-label-text-font: InterTight, sans-serif;
--mat-tab-header-label-text-letter-spacing: -0.00875rem;
--mat-tab-header-label-text-size: 0.8125rem;
.mat-mdc-tab-labels {
gap: 0;
border-bottom: 0;
}
.mdc-tab {
padding-inline: 15px !important;
}
.mdc-tab--active {
border: 0;
border-block-end-width: 2px;
border-style: solid;
border-image: var(--purple-to-blue-horizontal-gradient) 1;
span {
background-image: var(--purple-to-blue-horizontal-gradient);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
}
}
}
}
}
.cm-editor,
.ͼ3 .cm-gutters,
.cm-scroller {
background-color: var(--page-background);
transition: background-color 0.3s ease;
font-size: 0.875rem;
}
.ͼ1.cm-focused {
outline: none;
}
.ͼ2u {
.cm-line.cm-activeLine,
.cm-activeLineGutter {
background-color: color-mix(in srgb, var(--primary-contrast) 5%, transparent);
transition: background-color 0.3s ease;
}
}
.ͼ1 .cm-button {
background-image: linear-gradient(var(--octonary-contrast), var(--page-background));
&:focus {
background-image: linear-gradient(var(--senary-contrast), var(--page-background));
}
}
.cm-scroller {
&::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0);
cursor: pointer;
margin: 2px;
}
&::-webkit-scrollbar {
width: 6px;
height: 6px;
}
&::-webkit-scrollbar-thumb {
background-color: var(--senary-contrast);
border-radius: 10px;
transition: background-color 0.3s ease;
}
&::-webkit-scrollbar-thumb:hover {
background-color: var(--quaternary-contrast);
}
}
[docs-breadcrumb] {
height: 2.5625rem;
}
| {
"end_byte": 9275,
"start_byte": 6979,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/_resets.scss"
} |
angular/adev/shared-docs/styles/BUILD.bazel_0_303 | load("@io_bazel_rules_sass//:defs.bzl", "sass_library")
package(default_visibility = ["//visibility:private"])
sass_library(
name = "styles",
srcs = glob(["**/*.scss"]),
visibility = [
"//adev/shared-docs:__pkg__",
"//adev/shared-docs/components:__subpackages__",
],
)
| {
"end_byte": 303,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/BUILD.bazel"
} |
angular/adev/shared-docs/styles/_media-queries.scss_0_954 | $screen-xs: 700px;
$screen-sm: 775px;
$screen-md: 900px;
$screen-lg: 1200px;
$screen-xl: 1800px;
@mixin for-phone-only {
@media (max-width: $screen-xs) {
@content;
}
}
@mixin for-tablet-portrait-up {
@media (min-width: $screen-xs) {
@content;
}
}
@mixin for-tablet {
@media (min-width: $screen-xs) and (max-width: $screen-md) {
@content;
}
}
@mixin for-tablet-up {
@media (min-width: $screen-sm) {
@content;
}
}
@mixin for-tablet-landscape-up {
@media (min-width: $screen-md) {
@content;
}
}
@mixin for-desktop-up {
@media (min-width: $screen-lg) {
@content;
}
}
@mixin for-big-desktop-up {
@media (min-width: $screen-xl) {
@content;
}
}
@mixin for-desktop-down {
@media (max-width: $screen-lg) {
@content;
}
}
@mixin for-tablet-landscape-down {
@media (max-width: $screen-md) {
@content;
}
}
@mixin for-tablet-down {
@media (max-width: $screen-sm) {
@content;
}
}
| {
"end_byte": 954,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/_media-queries.scss"
} |
angular/adev/shared-docs/styles/_anchor.scss_0_373 | @mixin docs-anchor() {
&::after {
content: '\e157'; // codepoint for "link"
font-family: 'Material Symbols Outlined';
opacity: 0;
margin-left: 8px;
vertical-align: middle;
color: var(--quaternary-contrast);
font-size: clamp(18px, 1.25em, 30px);
transition: opacity 0.3s ease;
}
&:hover {
&::after {
opacity: 1;
}
}
}
| {
"end_byte": 373,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/_anchor.scss"
} |
angular/adev/shared-docs/styles/docs/_code.scss_0_7068 | // TODO: Working on refactoring all code components & syntax highlighting
/* stylelint-disable */
@mixin docs-code-block {
// code across docs, inline, blocks, shell, example viewer, etc.
code {
font-family: var(--code-font);
border-radius: 0.25rem;
font-weight: 400;
// Create a new stacking context to allow for the psuedo element content to be placed behind the
// text so that the text is properly selectable by the user.
isolation: isolate;
// Inline code only
&:not(pre *) {
position: relative;
padding: 0 0.3rem;
// Fallback for older browsers
background: #e62600;
background: var(--red-to-orange-horizontal-gradient);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
max-width: max-content;
width: 100%;
display: inline-block;
&::before {
content: '';
position: absolute;
inset: 0;
width: 100%;
height: 100%;
background: var(--subtle-purple);
border-radius: 0.25rem;
z-index: -1;
}
a:not(.docs-anchor) > & {
position: relative;
padding: 0 0.3rem;
white-space: nowrap;
background: var(--purple-to-blue-horizontal-gradient);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
max-width: max-content;
&::before {
content: '';
position: absolute;
inset: 0;
width: 100%;
height: 100%;
background: var(--subtle-purple);
border-radius: 0.25rem;
transition: background 0.3s ease;
z-index: -1;
}
&:hover {
background: var(--vivid-pink);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
max-width: max-content;
}
}
}
// render inline code emjois without gradient
.docs-emoji {
color: initial;
}
}
pre {
white-space: pre;
}
// render inline code emjois without gradient
.docs-emoji {
color: inherit;
}
// docs-code shell, multifile, mermaid diagrams
.docs-code {
.docs-viewer & {
margin-block: 1rem;
}
display: block;
position: relative;
border: 1px solid var(--senary-contrast);
border-radius: 0.25rem;
background: var(--octonary-contrast);
transition:
background 0.3s ease,
border-color 0.3s ease;
container: codeblock / inline-size;
pre {
overflow-x: auto;
}
code {
display: flex;
flex-direction: column;
font-size: 0.875rem;
counter-reset: line;
}
}
// shell doesn't have a header, for commands only
.shell {
border: 1px solid var(--quinary-contrast);
pre {
white-space: nowrap;
}
.shiki .line {
&::before {
content: '$';
padding-inline-end: 0.5rem;
}
display: block;
&.hidden {
display: none;
}
}
button[docs-copy-source-code] {
background-color: var(--quaternary-contrast);
border: 1px solid var(--quinary-contrast);
@container codeblock (min-width: 400px) {
border: 1px solid transparent;
}
.docs-copy {
path {
fill: var(--quinary-contrast);
}
}
.docs-check {
color: var(--page-background);
}
&:hover {
.docs-copy {
path {
fill: var(--octonary-contrast);
}
}
}
}
}
// copy code button
button[docs-copy-source-code] {
padding: 0.375rem 0.4rem 0.15rem 0.5rem;
position: absolute;
top: 3.1rem;
right: 0.2rem;
border-radius: 0.25rem;
cursor: pointer;
z-index: var(--z-index-icon);
background-color: var(--octonary-contrast);
border: 1px solid var(--senary-contrast);
transition:
background-color 0.3s ease,
border-color 0.3s ease;
@container codeblock (min-width: 400px) {
border: 1px solid transparent;
}
.docs-icon {
transition: opacity 0.3s ease-out;
}
.docs-copy {
opacity: 1;
path {
transition: fill 0.3s ease;
fill: var(--gray-400);
}
}
.docs-check {
opacity: 0;
color: var(--primary-contrast);
position: absolute;
inset: 0;
top: 0.35rem;
path {
transition: fill 0.3s ease;
}
}
&.docs-copy-source-code-button-success {
.docs-copy {
opacity: 0;
}
.docs-check {
opacity: 1;
}
}
&:hover {
.docs-copy {
path {
fill: var(--primary-contrast);
}
}
}
}
.docs-code .docs-code-header {
position: relative;
h3 {
background-image: var(--purple-to-blue-horizontal-gradient);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
font-size: 0.875rem;
font-style: normal;
font-weight: 400;
line-height: 1.4rem;
letter-spacing: -0.00875rem;
margin: 0;
word-wrap: break-word;
width: fit-content;
}
}
.docs-code-header {
padding: 0.75rem;
// docs header background
&::before {
content: '';
position: absolute;
inset: 0;
width: 100%;
height: 100%;
background: var(--subtle-purple);
border-radius: 0.25rem 0.25rem 0 0;
transition: background 0.3s ease;
}
}
// Single line docs-code elements, without headers, shell code
.docs-code:not(:has(.docs-code-header)) {
button[docs-copy-source-code] {
top: 0.2rem;
right: 0.2rem;
}
}
.docs-code[mermaid] {
border: 0;
width: 100%;
background-color: transparent;
}
// Line numbers styling: Add a grid, if there are line numbers
.docs-code:not([mermaid]),
.docs-example-viewer-code-wrapper {
code:has(.shiki-ln-number) {
display: grid;
grid-template-columns: min-content 1fr;
height: 100%;
}
pre {
overflow-x: auto;
display: flex;
flex-direction: column;
}
}
.docs-example-viewer-code-wrapper {
.docs-code-header {
display: none;
}
}
.shiki-ln-number {
border-inline-end: 1px solid var(--senary-contrast);
padding-inline-start: 0.75rem;
padding-inline-end: 0.5rem;
color: var(--quaternary-contrast);
font-size: 0.875rem;
text-align: right;
}
.highlighted {
background: color-mix(in srgb, var(--bright-blue) 9%, var(--page-background));
color: color-mix(in srgb, var(--bright-blue) 60%, var(--full-contrast));
}
.remove {
background: color-mix(in srgb, var(--orange-red) 10%, var(--page-background));
color: color-mix(in srgb, var(--hot-red) 80%, var(--full-contrast));
}
.add {
background: color-mix(in srgb, oklch(68.82% 0.224 155.13) 12%, var(--page-background));
color: color-mix(in srgb, var(--super-green), var(--full-contrast) 50%);
}
.hidden {
display: none;
}
} | {
"end_byte": 7068,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/docs/_code.scss"
} |
angular/adev/shared-docs/styles/docs/_code.scss_7070_8146 | @mixin docs-syntax-highlighting {
.shiki .line {
min-height: 1.375em;
padding-inline: 1rem;
color: var(--tertiary-contrast);
display: block;
&.hidden {
display: none;
}
span:last-child {
margin-inline-end: 4rem;
}
}
.shiki-ln-group {
display: flex;
flex-direction: column;
margin: 1rem 0;
}
.shiki-deprecated {
text-decoration: line-through;
}
.gap {
color: var(--quaternary-contrast);
}
.hljs-constructor {
color: var(--symbolic-cyan);
}
.hljs-params {
color: var(--bright-blue);
}
}
@mixin docs-code-editor {
.cm-tooltip-hover {
display: flex;
flex-direction: column-reverse;
padding: 0.75rem;
&::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0);
}
&::-webkit-scrollbar {
width: 6px;
height: 6px;
}
&::-webkit-scrollbar-thumb {
background-color: var(--senary-contrast);
border-radius: 10px;
}
&::-webkit-scrollbar-thumb:hover {
background-color: var(--quinary-contrast);
}
}
} | {
"end_byte": 8146,
"start_byte": 7070,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/docs/_code.scss"
} |
angular/adev/shared-docs/styles/docs/_steps.scss_0_2128 | // Doc Steps/Ordered Doc section
// Did somebody order a doc?
@use '../media-queries' as mq;
@mixin docs-steps() {
.docs-steps {
--gutter: 4rem;
padding-inline-start: var(--gutter);
counter-reset: code-steps-list;
list-style-type: none;
li {
position: relative;
}
}
.docs-steps li h3 {
font-size: 1.75rem;
margin-block-start: 0;
margin-block-end: 0.5rem;
line-height: 2.5rem;
}
.docs-step-number {
counter-increment: code-steps-list;
display: block;
pointer-events: none;
position: absolute;
left: calc(var(--gutter) * -1);
top: 2.7rem;
bottom: 0;
&::before {
display: flex;
align-items: center;
justify-content: center;
width: 2rem;
content: counter(code-steps-list);
border-radius: 50%;
aspect-ratio: 1 / 1;
border: 1px solid transparent;
background-image: linear-gradient(var(--page-background), var(--page-background)),
var(--pink-to-purple-horizontal-gradient);
background-origin: border-box;
background-clip: content-box, border-box;
position: sticky;
top: 2rem;
// adjust for tablet nav bar height
@include mq.for-tablet-landscape-down {
top: calc(1rem + 75px);
}
// adjust for mobile nav bar height
@include mq.for-phone-only {
top: calc(1rem + 55px);
}
}
.docs-tutorial-content & {
&::before {
// calc(1rem + sticky tutorial nav height)
top: calc(1rem + 120px);
// adjust for tablet nav bar height
@include mq.for-tablet-landscape-down {
top: calc(1rem + 165px);
}
// adjust for mobile nav bar height
@include mq.for-phone-only {
top: calc(1rem + 140px);
}
}
}
.docs-tutorial-content:has(.docs-reveal-answer-button) & {
&::before {
// calc(1rem + sticky tutorial nav height
// + reveal answer button height when on smaller screens)
@container tutorial-content (max-width: 430px) {
top: calc(1rem + 175px);
}
}
}
}
}
| {
"end_byte": 2128,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/docs/_steps.scss"
} |
angular/adev/shared-docs/styles/docs/_video.scss_0_191 | @mixin docs-video() {
.docs-video-container {
iframe {
border: 0;
width: 100%;
border-radius: 0.25rem;
overflow: hidden;
aspect-ratio: 16 / 9;
}
}
}
| {
"end_byte": 191,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/docs/_video.scss"
} |
angular/adev/shared-docs/styles/docs/_table.scss_0_853 | // Table
@mixin docs-table {
.docs-table {
overflow-x: auto;
table {
width: 100%;
border-collapse: collapse;
margin-block: 1rem;
font-size: 0.875rem;
line-height: 160%;
letter-spacing: -0.00875rem;
}
th {
text-align: left;
padding-block: 0.4rem;
padding-inline-end: 1.5rem;
border-block: 1px solid var(--senary-contrast);
font-size: 0.75rem;
font-weight: 600;
}
tr {
td {
padding-block: 0.85rem;
vertical-align: top;
&:not(:last-child) {
padding-inline-end: 1rem;
}
}
td:first-child {
padding-inline-end: 1.62rem;
vertical-align: top;
min-width: 10ch;
}
&:not(:last-child) {
border-block-end: 1px solid var(--senary-contrast);
}
}
}
}
| {
"end_byte": 853,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/docs/_table.scss"
} |
angular/adev/shared-docs/styles/docs/_callout.scss_0_1664 | // Callout
@mixin docs-callout() {
.docs-callout {
// Default theme is purple to blue
--callout-theme: var(--purple-to-blue-horizontal-gradient);
border-width: 0;
border-block-start-width: 2px;
border-block-end-width: 1px;
border-style: solid;
margin-block: 1.5rem;
border-image: var(--callout-theme) 1;
position: relative;
// Removes bottom line if followed by another callout
// Prevents too many lines/visual noise
&:has(+ .docs-callout) {
border-block-end-width: 0;
}
&::before {
font-family: var(--icons);
// content: icon is defined in each docs-alert class below...
position: absolute;
right: 0;
margin-top: 1.35rem;
color: var(--alert-accent);
font-size: 1.3rem;
}
// Callout heading
h2,
h3,
h4,
h5,
h6 {
background-image: var(--callout-theme);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
max-width: fit-content;
}
}
.docs-viewer .docs-callout h3 {
font-size: 0.875rem;
margin-block: 1.6rem;
}
.docs-callout-helpful {
--callout-theme: var(--purple-to-blue-horizontal-gradient);
&::before {
content: 'check_circle';
color: var(--bright-blue);
}
}
.docs-callout-critical {
--callout-theme: var(--red-to-orange-horizontal-gradient);
&::before {
content: 'warning';
color: var(--orange-red);
}
}
.docs-callout-important {
--callout-theme: var(--pink-to-purple-horizontal-gradient);
&::before {
content: 'priority_high';
color: var(--electric-violet);
}
}
}
| {
"end_byte": 1664,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/docs/_callout.scss"
} |
angular/adev/shared-docs/styles/docs/_decorative-header.scss_0_2025 | @mixin docs-decorative-header() {
.docs-decorative-header-container {
container: header / inline-size;
}
.docs-decorative-header {
border-radius: 0.625rem;
background: var(--septenary-contrast);
max-width: var(--page-width);
overflow: hidden;
display: flex;
position: relative;
transition: background 0.3s ease;
@container header (max-width: 550px) {
flex-direction: column-reverse;
}
.docs-header-content {
box-sizing: border-box;
padding: 1.5rem;
padding-inline-end: 0;
flex-grow: 1;
@container header (max-width: 550px) {
width: 100%;
padding-block-end: 1.5rem;
}
h1,
p,
span {
color: var(--primary-contrast);
transition: color 0.3s ease;
}
a {
position: absolute;
top: 1.5rem;
right: 1.5rem;
z-index: 20;
i {
color: var(--quaternary-contrast);
}
&:hover {
i {
color: var(--primary-contrast);
}
}
}
docs-breadcrumb {
padding-block-end: 1rem;
}
.docs-breadcrumb {
font-size: 0.875rem;
span {
color: var(--primary-contrast) !important;
}
}
}
svg {
margin: 0;
margin-block: auto;
padding-inline: 1rem 3.5rem;
padding-block: 2rem;
min-width: 150px;
max-width: 250px;
max-height: 125px;
z-index: 0;
&.docs-what-is-angular-svg {
max-height: 125px;
min-width: 175px;
padding-block-end: 0.5rem;
}
&.docs-directives-svg {
max-height: 150px;
}
&.docs-roadmap-svg {
padding-block-end: 0.5rem;
}
@container header (max-width: 550px) {
padding: 2rem;
padding-block-end: 0;
padding-inline-start: 1.5rem;
width: fit-content;
min-width: auto;
max-width: 80%;
max-height: 125px;
}
}
}
}
| {
"end_byte": 2025,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/docs/_decorative-header.scss"
} |
angular/adev/shared-docs/styles/docs/_pill.scss_0_1840 | // Pill
@mixin docs-pill() {
.docs-pill {
display: flex;
align-items: center;
// Default blue
--pill-accent: var(--bright-blue);
background: color-mix(in srgb, var(--pill-accent) 5%, transparent);
// Darken the text a bit for contrast
color: color-mix(in srgb, var(--pill-accent) 70%, var(--full-contrast));
padding-inline: 0.75rem;
padding-block: 0.375rem;
border-radius: 2.75rem;
border: 0;
transition: background 0.3s ease;
font-family: var(--inter-font);
font-size: 0.875rem;
font-style: normal;
font-weight: 500;
line-height: 1.4rem;
letter-spacing: -0.00875rem;
&:hover {
background: color-mix(in srgb, var(--pill-accent) 15%, transparent);
}
.docs-icon-small {
margin-inline-start: 0.25rem;
}
.docs-dark-mode & {
// Lighten the text a bit for contrast
color: color-mix(in srgb, var(--pill-accent) 60%, white 70%);
background: color-mix(in srgb, var(--pill-accent) 10%, white 2%);
&:hover {
background: color-mix(in srgb, var(--pill-accent) 20%, white 10%);
}
}
}
.docs-pill-row {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 0.5rem;
margin-block: 0.75rem;
.docs-pill {
// TODO: This gradient supports longer rows
// we may want to refine it
&:nth-child(6n + 1) {
--pill-accent: var(--hot-red);
}
&:nth-child(6n + 2) {
--pill-accent: var(--hot-pink);
}
&:nth-child(6n + 3) {
--pill-accent: var(--electric-violet);
}
&:nth-child(6n + 4) {
--pill-accent: var(--french-violet);
}
&:nth-child(6n + 5) {
--pill-accent: var(--indigo-blue);
}
&:nth-child(6n + 6) {
--pill-accent: var(--bright-blue);
}
}
}
}
| {
"end_byte": 1840,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/docs/_pill.scss"
} |
angular/adev/shared-docs/styles/docs/_card.scss_0_2126 | // Card Grid
@mixin docs-card() {
.docs-card-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
@container docs-content (max-width: 450px) {
grid-template-columns: 1fr;
}
grid-gap: 1.25rem;
margin-block: 1rem;
}
.docs-card {
display: flex;
flex-direction: column;
justify-content: space-between;
color: var(--primary-contrast);
padding: 1.5rem;
border: 1px solid var(--senary-contrast);
border-radius: 0.25rem;
overflow: hidden;
transition: border-color 0.3s ease, background-color 0.3s ease;
p:first-of-type {
margin-block-start: 1.5rem;
}
p:last-of-type {
margin-block-end: 1.5rem;
}
span {
font-size: 0.875rem;
font-weight: 500;
margin-block: 0;
position: relative;
}
* + *:not(a):not(code):not(span) {
margin-block: 1.5rem;
}
&.docs-card-with-svg {
padding: 0;
.docs-card-text-content {
flex-grow: 1;
margin-block-start: 0;
padding-inline: 1.5rem;
display: flex;
flex-direction: column;
justify-content: space-between;
border-block-start: 1px solid var(--senary-contrast);
h3 {
margin-bottom: 0;
margin-block-start: 1rem;
font-size: 1rem;
}
p {
margin-block-start: 0;
}
}
}
}
// docs-card with link
a.docs-card {
display: flex;
flex-direction: column;
justify-content: space-between;
span {
background: var(--pink-to-highlight-to-purple-to-blue-horizontal-gradient);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
font-size: 0.875rem;
margin-block: 0;
transition: background-position 1.8s ease-out;
background-size: 200% 100%;
background-position: 100% 0%;
position: relative;
}
&:hover {
span {
background-position: 0% 0%;
}
background: var(--subtle-purple);
}
}
.docs-viewer .docs-card h3 {
margin-block-start: 0;
font-size: 1rem;
}
}
| {
"end_byte": 2126,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/docs/_card.scss"
} |
angular/adev/shared-docs/styles/docs/_icon.scss_0_215 | // Icon styles, primarily for docs
@mixin docs-icon {
.docs-icon {
color: var(--quinary-contrast);
font-size: 1.5rem;
transition: color 0.3s ease;
}
.docs-icon-small {
font-size: 1rem;
}
}
| {
"end_byte": 215,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/docs/_icon.scss"
} |
angular/adev/shared-docs/styles/docs/_alert.scss_0_2685 | // Alert
@mixin docs-alert() {
.docs-alert {
// Default theme is purple to blue
--alert-gradient: var(--purple-to-blue-vertical-gradient);
--alert-accent: var(--bright-blue);
border-width: 0;
border-inline-start-width: 3px;
border-style: solid;
background: color-mix(in srgb, var(--alert-accent) 5%, transparent);
color: var(--primary-contrast);
border-image: var(--alert-gradient) 1;
padding: 1.5rem;
font-weight: 400;
transition: color 0.3s ease;
margin-block: 1rem;
position: relative;
&::before {
font-family: var(--icons);
// content: icon is defined in each docs-alert class below...
position: absolute;
margin-top: -0.05rem;
color: var(--alert-accent);
font-size: 1.3rem;
}
p {
margin-inline-start: 1.65rem;
}
.docs-dark-mode & {
background: color-mix(in srgb, var(--alert-accent) 10%, transparent);
}
.docs-pill-row {
margin-block-end: 0;
}
}
.docs-viewer .docs-alert p {
margin-block: 0;
}
.docs-alert-note {
--alert-gradient: var(--blue-to-teal-vertical-gradient);
--alert-accent: var(--bright-blue);
&::before {
content: 'bookmark';
}
}
.docs-alert-tip {
--alert-gradient: var(--green-to-cyan-vertical-gradient);
--alert-accent: var(--symbolic-cyan);
&::before {
content: 'star';
}
}
.docs-alert-todo {
--alert-gradient: var(--black-to-gray-vertical-gradient);
--alert-accent: var(--quaternary-contrast);
&::before {
content: 'error';
}
}
.docs-alert-question {
--alert-gradient: var(--blue-to-cyan-vertical-gradient);
--alert-accent: var(--symbolic-cyan);
&::before {
content: 'help';
}
}
.docs-alert-summary {
--alert-gradient: var(--purple-to-light-purple-vertical-gradient);
--alert-accent: var(--electric-violet);
&::before {
content: 'sms';
}
}
.docs-alert-tldr {
--alert-gradient: var(--pink-to-purple-vertical-gradient);
--alert-accent: var(--vivid-pink);
&::before {
content: 'speaker_notes';
}
}
.docs-alert-critical {
--alert-gradient: var(--red-to-orange-vertical-gradient);
--alert-accent: var(--orange-red);
&::before {
content: 'warning';
}
}
.docs-alert-important {
--alert-gradient: var(--red-to-pink-vertical-gradient);
--alert-accent: var(--hot-red);
&::before {
content: 'priority_high';
}
}
.docs-alert-helpful {
--alert-gradient: var(--orange-to-pink-vertical-gradient);
--alert-accent: var(--vivid-pink);
&::before {
content: 'check_circle';
}
}
}
| {
"end_byte": 2685,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/docs/_alert.scss"
} |
angular/adev/shared-docs/styles/docs/_mermaid.scss_0_2023 | #mermaid-generated-diagram {
--fontFamily: 'sans-serif';
--primaryColor: '#fff';
--primaryBorderColor: '#000';
--pie1: '#0546ff';
--pie2: '#f637e3';
--pie3: '#f11653';
--pie4: '#8001c6';
--pie5: '#00c572';
--pie6: '#fe3700';
background-color: var(--page-background) !important; // svg background color
g {
rect {
stroke: black !important; // border around the rectangles, same for dark/light theme
filter: drop-shadow(5px 5px 0px var(--primary-contrast));
}
}
.messageText,
.pieTitleText {
fill: var(--primary-contrast) !important; // pie chart title text and line labels
}
.pieOuterCircle {
stroke-width: 1px;
}
.pieCircle {
stroke-width: 1.5px;
}
.legend {
rect {
filter: none;
opacity: 0.7;
}
text {
fill: var(--primary-contrast) !important; // legend label text color
}
}
.slice {
// e.g. text on the pie charts
fill: var(--primary-contrast) !important;
}
.flowchart-link,
line {
// lines
stroke: var(--primary-contrast) !important;
}
.marker,
#statediagram-barbEnd,
.transition,
#arrowhead path {
// arrows
stroke: var(--primary-contrast) !important;
fill: var(--primary-contrast) !important;
}
.cluster rect,
.nodes rect {
stroke: var(--primary-contrast) !important;
fill: var(--page-background) !important;
}
.nodeLabel {
fill: var(--primary-contrast) !important;
color: var(--primary-contrast) !important;
}
.eventNode {
polygon {
fill: var(--hot-pink) !important;
filter: none;
stroke: var(--hot-pink) !important;
}
.nodeLabel p {
color: var(--page-background) !important;
font-weight: 800 !important;
}
}
.checkedNode {
rect {
color: white !important;
filter: drop-shadow(5px 5px 0px var(--hot-pink));
stroke: var(--hot-pink) !important;
}
.nodeLabel p {
color: var(--hot-pink) !important;
font-weight: 800 !important;
}
}
}
| {
"end_byte": 2023,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/styles/docs/_mermaid.scss"
} |
angular/adev/shared-docs/components/BUILD.bazel_0_966 | load("//tools:defaults.bzl", "ts_library")
package(default_visibility = ["//visibility:private"])
ts_library(
name = "components",
srcs = [
"index.ts",
],
visibility = [
"//adev/shared-docs:__pkg__",
],
deps = [
"//adev/shared-docs/components/algolia-icon",
"//adev/shared-docs/components/breadcrumb",
"//adev/shared-docs/components/cookie-popup",
"//adev/shared-docs/components/copy-source-code-button",
"//adev/shared-docs/components/icon",
"//adev/shared-docs/components/navigation-list",
"//adev/shared-docs/components/search-dialog",
"//adev/shared-docs/components/select",
"//adev/shared-docs/components/slide-toggle",
"//adev/shared-docs/components/table-of-contents",
"//adev/shared-docs/components/text-field",
"//adev/shared-docs/components/top-level-banner",
"//adev/shared-docs/components/viewers",
],
)
| {
"end_byte": 966,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/BUILD.bazel"
} |
angular/adev/shared-docs/components/index.ts_0_754 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
export * from './viewers/docs-viewer/docs-viewer.component';
export * from './cookie-popup/cookie-popup.component';
export * from './navigation-list/navigation-list.component';
export * from './select/select.component';
export * from './slide-toggle/slide-toggle.component';
export * from './table-of-contents/table-of-contents.component';
export * from './text-field/text-field.component';
export * from './icon/icon.component';
export * from './search-dialog/search-dialog.component';
export * from './top-level-banner/top-level-banner.component';
| {
"end_byte": 754,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/index.ts"
} |
angular/adev/shared-docs/components/navigation-list/navigation-list.component.spec.ts_0_5155 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {NavigationList} from './navigation-list.component';
import {By} from '@angular/platform-browser';
import {NavigationItem} from '../../interfaces';
import {RouterTestingModule} from '@angular/router/testing';
import {provideExperimentalZonelessChangeDetection, signal} from '@angular/core';
import {NavigationState} from '../../services';
const navigationItems: NavigationItem[] = [
{
label: 'Introduction',
path: 'guide',
level: 1,
},
{
label: 'Getting Started',
level: 1,
children: [
{label: 'What is Angular?', path: 'guide/what-is-angular', level: 2},
{label: 'Setup', path: 'guide/setup', level: 2},
],
},
];
describe('NavigationList', () => {
let component: NavigationList;
let fixture: ComponentFixture<NavigationList>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [NavigationList, RouterTestingModule],
providers: [
{provide: NavigationState, useClass: FakeNavigationListState},
provideExperimentalZonelessChangeDetection(),
],
}).compileComponents();
fixture = TestBed.createComponent(NavigationList);
component = fixture.componentInstance;
});
it('should display provided navigation structure', () => {
component.navigationItems = [...navigationItems];
fixture.detectChanges();
const links = fixture.debugElement.queryAll(By.css('a'));
const nonClickableItem = fixture.debugElement.queryAll(By.css('.docs-secondary-nav-header'));
expect(links.length).toBe(3);
expect(nonClickableItem.length).toBe(1);
});
it('should append `docs-navigation-list-dropdown` when isDropdownView is true', () => {
component.isDropdownView = true;
fixture.detectChanges();
const ulElement = fixture.debugElement.query(By.css('ul.docs-navigation-list-dropdown'));
expect(ulElement).toBeTruthy();
});
it('should not append `docs-navigation-list-dropdown` when isDropdownView is false', () => {
component.isDropdownView = false;
fixture.detectChanges();
const ulElement = fixture.debugElement.query(By.css('ul.docs-navigation-list-dropdown'));
expect(ulElement).toBeFalsy();
});
it('should emit linkClicked when user clicked on link', () => {
const emitClickOnLinkSpy = spyOn(component, 'emitClickOnLink');
component.navigationItems = [...navigationItems];
fixture.detectChanges(true);
const guideLink = fixture.debugElement.query(By.css('a[href="/guide"]'));
guideLink.nativeElement.click();
expect(emitClickOnLinkSpy).toHaveBeenCalledTimes(1);
});
it(`should not call navigationState.toggleItem() when item's level is equal to 1 and is not neither expandable or collapsable level`, () => {
const navigationState = TestBed.inject(NavigationState);
const toggleItemSpy = spyOn(navigationState, 'toggleItem');
const itemToToggle = navigationItems[1];
component.toggle(itemToToggle);
expect(toggleItemSpy).not.toHaveBeenCalled();
});
it(`should call navigationState.toggleItem() when item's level is expandable`, () => {
const navigationState = TestBed.inject(NavigationState);
const toggleItemSpy = spyOn(navigationState, 'toggleItem');
const itemToToggle = navigationItems[1];
component.expandableLevel = 1;
component.toggle(itemToToggle);
expect(toggleItemSpy).toHaveBeenCalledOnceWith(itemToToggle);
});
it(`should call navigationState.toggleItem() when item's level is collapsable`, () => {
const navigationState = TestBed.inject(NavigationState);
const toggleItemSpy = spyOn(navigationState, 'toggleItem');
const itemToToggle = navigationItems[1].children![1];
component.collapsableLevel = 2;
component.toggle(itemToToggle);
expect(toggleItemSpy).toHaveBeenCalledOnceWith(itemToToggle);
});
it('should display items to provided level', () => {
component.navigationItems = [...navigationItems];
component.displayItemsToLevel = 1;
fixture.detectChanges(true);
const visibleItems = fixture.debugElement.queryAll(
By.css('li.docs-faceted-list-item:not(.docs-navigation-link-hidden)'),
);
const hiddenItems = fixture.debugElement.queryAll(
By.css('li.docs-faceted-list-item.docs-navigation-link-hidden'),
);
expect(visibleItems.length).toBe(2);
expect(visibleItems[0].nativeElement.innerText).toBe(navigationItems[0].label);
expect(visibleItems[1].nativeElement.innerText).toBe(navigationItems[1].label);
expect(hiddenItems.length).toBe(2);
expect(hiddenItems[0].nativeElement.innerText).toBe(navigationItems[1].children![0].label);
expect(hiddenItems[1].nativeElement.innerText).toBe(navigationItems[1].children![1].label);
});
});
class FakeNavigationListState {
isOpened = signal(true);
activeNavigationItem = signal(navigationItems.at(1));
toggleItem(item: NavigationItem) {}
}
| {
"end_byte": 5155,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/navigation-list/navigation-list.component.spec.ts"
} |
angular/adev/shared-docs/components/navigation-list/navigation-list.component.scss_0_2943 | @use '../../styles/media-queries' as mq;
:host {
display: flex;
min-width: var(--secondary-nav-width);
list-style: none;
overflow-y: auto;
overflow-x: hidden;
height: 100vh;
padding: 0;
margin: 0;
padding-block: 1.5rem;
font-size: 0.875rem;
box-sizing: border-box;
&::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0);
cursor: pointer;
}
&::-webkit-scrollbar {
width: 6px;
height: 6px;
}
&::-webkit-scrollbar-thumb {
background-color: var(--septenary-contrast);
@include mq.for-tablet-landscape-down {
background-color: var(--quinary-contrast);
}
border-radius: 10px;
transition: background-color 0.3s ease;
}
&::-webkit-scrollbar-thumb:hover {
background-color: var(--quinary-contrast);
}
.docs-nav-secondary & {
padding-block: 2rem;
}
> .docs-faceted-list {
border: 0;
}
.docs-navigation-link-hidden {
display: none;
}
.docs-nav-item-has-icon {
&::after {
// FIXME: for some reason this disappears when transformed
content: 'chevron_right';
font-size: 1.25rem;
font-family: var(--icons);
}
}
}
.docs-secondary-nav-header {
padding-block: 1.25rem;
font-weight: 500;
}
.docs-secondary-nav-button {
width: 15rem;
display: flex;
justify-content: space-between;
align-items: center;
border: none;
padding-block: 1.25rem;
padding-inline-start: 0;
color: var(--primary-contrast);
font-size: 0.875rem;
font-family: var(--inter-font);
line-height: 160%;
letter-spacing: -0.00875rem;
transition: color 0.3s ease, background 0.3s ease;
text-align: left; // forces left alignment of text in button
&.docs-secondary-nav-button-active {
// font gradient
background-image: var(--pink-to-purple-vertical-gradient);
&::before {
opacity: 1;
transform: scaleY(1);
background: var(--pink-to-purple-vertical-gradient);
}
&:hover {
&::before {
opacity: 1;
transform: scaleY(1.1);
}
}
}
}
.docs-expanded-button {
justify-content: start;
gap: 0.5rem;
}
a,
.docs-not-expanded-button {
display: flex;
justify-content: space-between;
align-items: center;
font-weight: 500;
line-height: 1.4rem;
letter-spacing: -0.00875rem;
padding: 0.5rem;
padding-inline-start: 1rem;
text-align: left;
}
// Add padding-bottom to last item in the list
.docs-navigation-list {
width: 100%;
li:last-of-type {
ul:last-of-type {
li:last-of-type {
padding-block-end: 1rem;
}
}
}
&:first-child {
margin-inline-start: 1rem;
}
}
.docs-external-link {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
gap: 0.5rem;
&::after {
content: 'open_in_new';
font-family: var(--icons);
font-size: 1.1rem;
color: var(--quinary-contrast);
transition: color 0.3s ease;
margin-inline-end: 0.4rem;
}
}
| {
"end_byte": 2943,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/navigation-list/navigation-list.component.scss"
} |
angular/adev/shared-docs/components/navigation-list/navigation-list.component.html_0_2721 | <ng-template #navigationList let-navigationItems>
<ul
class="docs-navigation-list docs-faceted-list"
[class.docs-navigation-list-dropdown]="isDropdownView"
>
@for (item of navigationItems; track $index) {
<li
class="docs-faceted-list-item"
[class.docs-navigation-link-hidden]="displayItemsToLevel && item.level > displayItemsToLevel"
>
@if (item.path) { @if (item.isExternal) {
<a [href]="item.path" target="_blank">
<span [class.docs-external-link]="item.isExternal">{{ item.label }}</span>
@if (item.children && item.level! > 1 && !item.isExpanded) {
<docs-icon>chevron_right</docs-icon>
}
</a>
} @else {
<a
[routerLink]="'/' + item.path"
[routerLinkActiveOptions]="{
queryParams: 'ignored',
fragment: 'ignored',
matrixParams: 'exact',
paths: 'exact',
exact: false
}"
routerLinkActive="docs-faceted-list-item-active"
(click)="emitClickOnLink()"
>
<span>{{ item.label }}</span>
@if (item.children && !item.isExpanded) {
<docs-icon>chevron_right</docs-icon>
}
</a>
} } @else {
<!-- Nav Section Header -->
@if (item.level !== collapsableLevel && item.level !== expandableLevel) {
<div class="docs-secondary-nav-header">
<span>{{ item.label }}</span>
</div>
}
<!-- Nav Button Expand/Collapse -->
@if ((item.children && item.level === expandableLevel) || item.level === collapsableLevel) {
<button
type="button"
(click)="toggle(item)"
attr.aria-label="{{ item.isExpanded ? 'Collapse' : 'Expand' }} {{ item.label }}"
[attr.aria-expanded]="item.isExpanded"
class="docs-secondary-nav-button"
[class.docs-faceted-list-item-active]="item | isActiveNavigationItem: activeItem()"
[class.docs-expanded-button]="item.children && item.level == collapsableLevel"
[class.docs-not-expanded-button]="item.children && item.level === expandableLevel"
[class.docs-nav-item-has-icon]="
item.children && item.level === expandableLevel && !item.isExpanded
"
>
@if (item.children && item.level === collapsableLevel) {
<docs-icon>arrow_back</docs-icon>
}
<span>{{ item.label }}</span>
</button>
} } @if (item.children?.length > 0) {
<ng-container
*ngTemplateOutlet="navigationList; context: {$implicit: item.children}"
></ng-container>
}
</li>
}
</ul>
</ng-template>
<ng-container
*ngTemplateOutlet="navigationList; context: {$implicit: navigationItems}"
></ng-container>
| {
"end_byte": 2721,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/navigation-list/navigation-list.component.html"
} |
angular/adev/shared-docs/components/navigation-list/BUILD.bazel_0_1351 | load("//tools:defaults.bzl", "karma_web_test_suite", "ng_module", "ts_library")
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
package(default_visibility = ["//visibility:private"])
ng_module(
name = "navigation-list",
srcs = [
"navigation-list.component.ts",
],
assets = [
":navigation-list.component.css",
"navigation-list.component.html",
],
visibility = [
"//adev/shared-docs/components:__pkg__",
],
deps = [
"//adev/shared-docs/components/icon",
"//adev/shared-docs/interfaces",
"//adev/shared-docs/pipes",
"//adev/shared-docs/services",
"//packages/common",
"//packages/core",
"//packages/router",
],
)
sass_binary(
name = "style",
src = "navigation-list.component.scss",
deps = [
"//adev/shared-docs/styles",
],
)
ts_library(
name = "test_lib",
testonly = True,
srcs = glob(
["*.spec.ts"],
),
deps = [
":navigation-list",
"//adev/shared-docs/interfaces",
"//adev/shared-docs/services",
"//packages/core",
"//packages/core/testing",
"//packages/platform-browser",
"//packages/router",
"//packages/router/testing",
],
)
karma_web_test_suite(
name = "test",
deps = [":test_lib"],
)
| {
"end_byte": 1351,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/navigation-list/BUILD.bazel"
} |
angular/adev/shared-docs/components/navigation-list/navigation-list.component.ts_0_1806 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
Input,
Output,
inject,
} from '@angular/core';
import {NavigationItem} from '../../interfaces/index';
import {NavigationState} from '../../services/index';
import {RouterLink, RouterLinkActive} from '@angular/router';
import {CommonModule} from '@angular/common';
import {IconComponent} from '../icon/icon.component';
import {IsActiveNavigationItem} from '../../pipes/is-active-navigation-item.pipe';
@Component({
selector: 'docs-navigation-list',
standalone: true,
imports: [CommonModule, RouterLink, RouterLinkActive, IconComponent, IsActiveNavigationItem],
templateUrl: './navigation-list.component.html',
styleUrls: ['./navigation-list.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class NavigationList {
@Input({required: true}) navigationItems: NavigationItem[] = [];
@Input() displayItemsToLevel: number = 2;
@Input() collapsableLevel: number | undefined = undefined;
@Input() expandableLevel: number = 2;
@Input() isDropdownView = false;
@Output() linkClicked = new EventEmitter<void>();
private readonly navigationState = inject(NavigationState);
expandedItems = this.navigationState.expandedItems;
activeItem = this.navigationState.activeNavigationItem;
toggle(item: NavigationItem): void {
if (
item.level === 1 &&
item.level !== this.expandableLevel &&
item.level !== this.collapsableLevel
) {
return;
}
this.navigationState.toggleItem(item);
}
emitClickOnLink(): void {
this.linkClicked.emit();
}
}
| {
"end_byte": 1806,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/navigation-list/navigation-list.component.ts"
} |
angular/adev/shared-docs/components/search-dialog/search-dialog.component.ts_0_5142 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {
ChangeDetectionStrategy,
Component,
ElementRef,
Injector,
OnDestroy,
Signal,
afterNextRender,
effect,
inject,
output,
viewChild,
viewChildren,
} from '@angular/core';
import {NgTemplateOutlet} from '@angular/common';
import {WINDOW} from '../../providers/index';
import {ClickOutside} from '../../directives/index';
import {Search} from '../../services/index';
import {TextField} from '../text-field/text-field.component';
import {FormsModule} from '@angular/forms';
import {ActiveDescendantKeyManager} from '@angular/cdk/a11y';
import {SearchItem} from '../../directives/search-item/search-item.directive';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {Router, RouterLink} from '@angular/router';
import {filter, fromEvent} from 'rxjs';
import {AlgoliaIcon} from '../algolia-icon/algolia-icon.component';
import {RelativeLink} from '../../pipes/relative-link.pipe';
import {SearchResult, SnippetResult} from '../../interfaces';
@Component({
selector: 'docs-search-dialog',
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [
ClickOutside,
TextField,
FormsModule,
SearchItem,
AlgoliaIcon,
RelativeLink,
RouterLink,
NgTemplateOutlet,
],
templateUrl: './search-dialog.component.html',
styleUrls: ['./search-dialog.component.scss'],
})
export class SearchDialog implements OnDestroy {
onClose = output();
dialog = viewChild.required<ElementRef<HTMLDialogElement>>('searchDialog');
items = viewChildren(SearchItem);
private readonly search = inject(Search);
private readonly relativeLink = new RelativeLink();
private readonly router = inject(Router);
private readonly window = inject(WINDOW);
private readonly injector = inject(Injector);
private readonly keyManager = new ActiveDescendantKeyManager(
this.items,
this.injector,
).withWrap();
searchQuery = this.search.searchQuery;
searchResults = this.search.searchResults;
constructor() {
effect(() => {
this.items();
afterNextRender(
{
write: () => this.keyManager.setFirstItemActive(),
},
{injector: this.injector},
);
});
this.keyManager.change.pipe(takeUntilDestroyed()).subscribe(() => {
this.keyManager.activeItem?.scrollIntoView();
});
afterNextRender({
write: () => {
if (!this.dialog().nativeElement.open) {
this.dialog().nativeElement.showModal?.();
}
},
});
fromEvent<KeyboardEvent>(this.window, 'keydown')
.pipe(takeUntilDestroyed())
.subscribe((event) => {
// When user presses Enter we can navigate to currently selected item in the search result list.
if (event.key === 'Enter') {
this.navigateToTheActiveItem();
} else {
this.keyManager.onKeydown(event);
}
});
}
splitMarkedText(snippet: string): Array<{highlight: boolean; text: string}> {
const parts: Array<{highlight: boolean; text: string}> = [];
while (snippet.indexOf('<ɵ>') !== -1) {
const beforeMatch = snippet.substring(0, snippet.indexOf('<ɵ>'));
const match = snippet.substring(snippet.indexOf('<ɵ>') + 3, snippet.indexOf('</ɵ>'));
parts.push({highlight: false, text: beforeMatch});
parts.push({highlight: true, text: match});
snippet = snippet.substring(snippet.indexOf('</ɵ>') + 4);
}
parts.push({highlight: false, text: snippet});
return parts;
}
getBestSnippetForMatch(result: SearchResult): string {
// if there is content, return it
if (result._snippetResult.content !== undefined) {
return result._snippetResult.content.value;
}
const hierarchy = result._snippetResult.hierarchy;
if (hierarchy === undefined) {
return '';
}
function matched(snippet: SnippetResult | undefined) {
return snippet?.matchLevel !== undefined && snippet.matchLevel !== 'none';
}
// return the most specific subheader match
if (matched(hierarchy.lvl4)) {
return hierarchy.lvl4!.value;
}
if (matched(hierarchy.lvl3)) {
return hierarchy.lvl3!.value;
}
if (matched(hierarchy.lvl2)) {
return hierarchy.lvl2!.value;
}
// if no subheader matched the query, fall back to just returning the most specific one
return hierarchy.lvl3?.value ?? hierarchy.lvl2?.value ?? '';
}
ngOnDestroy(): void {
this.keyManager.destroy();
}
closeSearchDialog() {
this.dialog().nativeElement.close();
this.onClose.emit();
}
updateSearchQuery(query: string) {
this.search.updateSearchQuery(query);
}
private navigateToTheActiveItem(): void {
const activeItemLink: string | undefined = this.keyManager.activeItem?.item?.url;
if (!activeItemLink) {
return;
}
this.router.navigateByUrl(this.relativeLink.transform(activeItemLink));
this.onClose.emit();
}
}
| {
"end_byte": 5142,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/search-dialog/search-dialog.component.ts"
} |
angular/adev/shared-docs/components/search-dialog/search-dialog.component.html_0_3318 | <dialog #searchDialog>
<div class="docs-search-container" (docsClickOutside)="closeSearchDialog()">
<docs-text-field
[autofocus]="true"
[hideIcon]="true"
[ngModel]="searchQuery()"
(ngModelChange)="updateSearchQuery($event)"
class="docs-search-input"
placeholder="Search docs"
></docs-text-field>
@if (searchResults() && searchResults()!.length > 0) {
<ul class="docs-search-results docs-mini-scroll-track">
@for (result of searchResults(); track result.objectID) {
<li docsSearchItem [item]="result">
<a
[routerLink]="'/' + result.url | relativeLink: 'pathname'"
[fragment]="result.url | relativeLink: 'hash'"
>
<div>
<div class="docs-result-icon-and-type">
<!-- Icon -->
<span class="docs-search-result-icon" aria-hidden="true">
<i role="presentation" class="material-symbols-outlined docs-icon-small">
{{ result.hierarchy.lvl0 === 'Tutorials' ? 'code' : 'description'}}
</i>
</span>
<!-- Results type -->
<span class="docs-search-results__type">
@let snippet = result._snippetResult.hierarchy?.lvl1?.value ?? '';
<ng-container
[ngTemplateOutlet]="highlightSnippet"
[ngTemplateOutletContext]="{snippet}"
></ng-container>
</span>
</div>
@let content = result._snippetResult.content;
@let hierarchy = result._snippetResult.hierarchy;
@if (content || hierarchy?.lvl2 || hierarchy?.lvl3 || hierarchy?.lvl4) {
<span class="docs-search-results__type docs-search-results__lvl2">
@let snippet = getBestSnippetForMatch(result);
<ng-container
[ngTemplateOutlet]="highlightSnippet"
[ngTemplateOutletContext]="{snippet}"
></ng-container>
</span>
}
</div>
<!-- Page title -->
<span class="docs-result-page-title">{{ result.hierarchy?.lvl0 }}</span>
</a>
</li>
}
</ul>
} @else {
<div class="docs-search-results docs-mini-scroll-track">
@if (searchResults() === undefined) {
<div class="docs-search-results__start-typing">
<span>Start typing to see results</span>
</div>
} @else if (searchResults()?.length === 0) {
<div class="docs-search-results__no-results">
<span>No results found</span>
</div>
}
</div>
}
<div class="docs-algolia">
<span>Search by</span>
<a href="https://www.algolia.com/developers/" target="_blank" rel="noopener">
<docs-algolia-icon />
</a>
</div>
</div>
</dialog>
<ng-template #highlightSnippet let-snippet="snippet">
@let parts = splitMarkedText(snippet);
@for (part of parts; track $index) {
@if (part.highlight) {
<mark>{{part.text}}</mark>
} @else {
<span>{{part.text}}</span>
}
}
</ng-template>
| {
"end_byte": 3318,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/search-dialog/search-dialog.component.html"
} |
angular/adev/shared-docs/components/search-dialog/search-dialog.component.scss_0_3380 | dialog {
background-color: transparent;
border: none;
padding-block-end: 3rem;
&::backdrop {
backdrop-filter: blur(5px);
}
}
.docs-search-container {
width: 750px;
max-width: 90vw;
background-color: var(--page-background);
border: 1px solid var(--senary-contrast);
border-radius: 0.25rem;
box-sizing: border-box;
.docs-search-input {
border-radius: 0.25rem 0.25rem 0 0;
border: none;
border-block-end: 1px solid var(--senary-contrast);
height: 2.6875rem; // 43px;
padding-inline-start: 1rem;
position: relative;
&::after {
content: 'Esc';
position: absolute;
right: 1rem;
color: var(--gray-400);
font-size: 0.875rem;
}
}
ul {
max-height: 50vh;
overflow-y: auto;
list-style-type: none;
padding-inline: 0;
padding-block-start: 1rem;
margin: 0;
border-block-end: 1px solid var(--senary-contrast);
li {
border-inline-start: 2px solid var(--senary-contrast);
margin-inline-start: 1rem;
padding-inline-end: 1rem;
padding-block: 0.25rem;
mark {
background: #e62600;
background: var(--red-to-orange-horizontal-gradient);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
}
a {
color: var(--secondary-contrast);
display: flex;
justify-content: space-between;
gap: 0.5rem;
.docs-search-result-icon {
i {
display: flex;
align-items: center;
font-size: 1.2rem;
}
}
}
&.active {
background-color: var(--septenary-contrast); // stylelint-disable-line
}
&:hover,
&.active {
background-color: var(--octonary-contrast); // stylelint-disable-line
border-inline-start: 2px solid var(--primary-contrast);
a {
span:not(.docs-result-page-title),
.docs-search-results__type {
color: var(--primary-contrast);
i {
color: var(--primary-contrast);
}
}
}
}
}
.docs-search-result-icon,
.docs-search-results__type,
.docs-result-page-title {
color: var(--quaternary-contrast);
display: inline-block;
font-size: 0.875rem;
transition: color 0.3s ease;
padding: 0.75rem;
padding-inline-end: 0;
}
.docs-search-results__lvl2 {
display: inline-block;
margin-inline-start: 2rem;
padding-block-start: 0;
}
.docs-search-results__lvl3 {
margin-inline-start: 2rem;
padding-block-start: 0;
}
}
.docs-result-page-title {
font-size: 0.875rem;
font-weight: 400;
}
}
.docs-search-results__start-typing,
.docs-search-results__no-results {
padding: 0.75rem;
color: var(--gray-400);
}
.docs-result-icon-and-type {
display: flex;
.docs-search-results__type {
padding-inline-start: 0;
}
}
.docs-algolia {
display: flex;
align-items: center;
justify-content: end;
color: var(--gray-400);
padding: 1rem;
font-size: 0.75rem;
font-weight: 500;
gap: 0.25rem;
background-color: var(--page-background);
border-radius: 0 0 0.25rem 0.25rem;
docs-algolia-icon {
display: inline-flex;
margin-block-start: 0.12rem;
margin-inline-start: 0.15rem;
width: 4rem;
}
}
| {
"end_byte": 3380,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/search-dialog/search-dialog.component.scss"
} |
angular/adev/shared-docs/components/search-dialog/search-dialog.component.spec.ts_0_4767 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {SearchDialog} from './search-dialog.component';
import {WINDOW} from '../../providers';
import {Search} from '../../services';
import {FakeEventTarget} from '../../testing/index';
import {By} from '@angular/platform-browser';
import {AlgoliaIcon} from '../algolia-icon/algolia-icon.component';
import {RouterTestingModule} from '@angular/router/testing';
import {Router} from '@angular/router';
import {provideExperimentalZonelessChangeDetection} from '@angular/core';
import {SearchResult} from '../../interfaces';
describe('SearchDialog', () => {
let fixture: ComponentFixture<SearchDialog>;
const fakeSearch = {
searchQuery: jasmine.createSpy(),
searchResults: jasmine.createSpy(),
};
const fakeWindow = new FakeEventTarget();
beforeEach(async () => {
fakeSearch.searchResults.and.returnValue([]);
fakeSearch.searchQuery.and.returnValue('');
await TestBed.configureTestingModule({
imports: [SearchDialog, RouterTestingModule],
providers: [
provideExperimentalZonelessChangeDetection(),
{
provide: Search,
useValue: fakeSearch,
},
{
provide: WINDOW,
useValue: fakeWindow,
},
],
}).compileComponents();
fixture = TestBed.createComponent(SearchDialog);
fixture.detectChanges();
});
it('should navigate to active item when user pressed Enter', () => {
const router = TestBed.inject(Router);
const navigateByUrlSpy = spyOn(router, 'navigateByUrl');
fakeSearch.searchResults.and.returnValue(fakeSearchResults);
fixture.detectChanges();
fakeWindow.dispatchEvent(
new KeyboardEvent('keydown', {
code: 'Enter',
key: 'Enter',
charCode: 13,
keyCode: 13,
view: window,
bubbles: true,
}),
);
expect(navigateByUrlSpy).toHaveBeenCalledOnceWith('fakeUrl1#h1');
});
it('should always display algolia logo', () => {
const algoliaIcon = fixture.debugElement.query(By.directive(AlgoliaIcon));
expect(algoliaIcon).toBeTruthy();
});
it('should display `No results found` message when there are no results for provided query', () => {
fakeSearch.searchResults.and.returnValue([]);
fixture.detectChanges();
const noResultsContainer = fixture.debugElement.query(
By.css('.docs-search-results__no-results'),
);
expect(noResultsContainer).toBeTruthy();
});
it('should display `Start typing to see results` message when there are no provided query', () => {
fakeSearch.searchResults.and.returnValue(undefined);
fixture.detectChanges();
const startTypingContainer = fixture.debugElement.query(
By.css('.docs-search-results__start-typing'),
);
expect(startTypingContainer).toBeTruthy();
});
it('should display list of the search results when results exist', () => {
fakeSearch.searchResults.and.returnValue(fakeSearchResults);
fixture.detectChanges();
const resultListContainer = fixture.debugElement.query(By.css('ul.docs-search-results'));
const resultItems = fixture.debugElement.queryAll(By.css('ul.docs-search-results li a'));
expect(resultListContainer).toBeTruthy();
expect(resultItems.length).toBe(2);
expect(resultItems[0].nativeElement.href).toBe(`${window.origin}/fakeUrl1#h1`);
expect(resultItems[1].nativeElement.href).toBe(`${window.origin}/fakeUrl2#h1`);
});
it('should close search dialog when user clicked outside `.docs-search-container`', () => {
const dialogContainer = fixture.debugElement.query(By.css('dialog'));
const closeSearchDialogSpy = spyOn(fixture.componentInstance, 'closeSearchDialog');
dialogContainer.nativeElement.click();
expect(closeSearchDialogSpy).toHaveBeenCalled();
});
});
const fakeSearchResults = [
{
'url': 'https://angular.dev/fakeUrl1#h1',
'hierarchy': {
'lvl0': 'FakeLvl0',
'lvl1': 'FakeLvl1',
'lvl2': 'FakeLvl2',
'lvl3': null,
'lvl4': null,
'lvl5': null,
'lvl6': null,
},
'objectID': 'fakeObjectId1',
_snippetResult: {},
type: '',
content: null,
},
{
'url': 'https://angular.dev/fakeUrl2#h1',
'hierarchy': {
'lvl0': 'FakeLvl0',
'lvl1': 'FakeLvl1',
'lvl2': 'FakeLvl2',
'lvl3': null,
'lvl4': null,
'lvl5': null,
'lvl6': null,
},
'objectID': 'fakeObjectId2',
type: '',
content: null,
_snippetResult: {},
},
] satisfies SearchResult[];
| {
"end_byte": 4767,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/search-dialog/search-dialog.component.spec.ts"
} |
angular/adev/shared-docs/components/search-dialog/BUILD.bazel_0_1543 | load("//tools:defaults.bzl", "karma_web_test_suite", "ng_module", "ts_library")
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
package(default_visibility = ["//visibility:private"])
ng_module(
name = "search-dialog",
srcs = [
"search-dialog.component.ts",
],
assets = [
":search-dialog.component.css",
"search-dialog.component.html",
],
visibility = [
"//adev/shared-docs/components:__pkg__",
],
deps = [
"//adev/shared-docs/components/algolia-icon",
"//adev/shared-docs/components/text-field",
"//adev/shared-docs/directives",
"//adev/shared-docs/interfaces",
"//adev/shared-docs/pipes",
"//adev/shared-docs/services",
"//packages/common",
"//packages/core",
"//packages/forms",
"//packages/router",
],
)
sass_binary(
name = "style",
src = "search-dialog.component.scss",
)
ts_library(
name = "test_lib",
testonly = True,
srcs = glob(
["*.spec.ts"],
),
deps = [
":search-dialog",
"//adev/shared-docs/components/algolia-icon",
"//adev/shared-docs/interfaces",
"//adev/shared-docs/providers",
"//adev/shared-docs/services",
"//adev/shared-docs/testing",
"//packages/core",
"//packages/core/testing",
"//packages/platform-browser",
"//packages/router",
"//packages/router/testing",
],
)
karma_web_test_suite(
name = "test",
deps = [":test_lib"],
)
| {
"end_byte": 1543,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/search-dialog/BUILD.bazel"
} |
angular/adev/shared-docs/components/slide-toggle/slide-toggle.component.ts_0_1898 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ChangeDetectionStrategy, Component, Input, forwardRef, signal} from '@angular/core';
import {CommonModule} from '@angular/common';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
@Component({
selector: 'docs-slide-toggle',
standalone: true,
imports: [CommonModule],
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './slide-toggle.component.html',
styleUrls: ['./slide-toggle.component.scss'],
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => SlideToggle),
multi: true,
},
],
})
export class SlideToggle implements ControlValueAccessor {
@Input({required: true}) buttonId!: string;
@Input({required: true}) label!: string;
@Input() disabled = false;
// Implemented as part of ControlValueAccessor.
private onChange: (value: boolean) => void = (_: boolean) => {};
private onTouched: () => void = () => {};
protected readonly checked = signal(false);
// Implemented as part of ControlValueAccessor.
writeValue(value: boolean): void {
this.checked.set(value);
}
// Implemented as part of ControlValueAccessor.
registerOnChange(fn: any): void {
this.onChange = fn;
}
// Implemented as part of ControlValueAccessor.
registerOnTouched(fn: any): void {
this.onTouched = fn;
}
// Implemented as part of ControlValueAccessor.
setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled;
}
// Toggles the checked state of the slide-toggle.
toggle(): void {
if (this.disabled) {
return;
}
this.checked.update((checked) => !checked);
this.onChange(this.checked());
this.onTouched();
}
}
| {
"end_byte": 1898,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/slide-toggle/slide-toggle.component.ts"
} |
angular/adev/shared-docs/components/slide-toggle/slide-toggle.component.scss_0_1391 | :host,
label {
display: inline-flex;
gap: 0.5em;
align-items: center;
}
.docs-label {
font-size: 0.875rem;
font-style: normal;
font-weight: 500;
line-height: 160%; // 1.4rem
letter-spacing: -0.00875rem;
color: var(--quaternary-contrast);
}
.docs-toggle {
position: relative;
display: inline-block;
width: 3rem;
height: 1.5rem;
border: 1px solid var(--senary-contrast);
border-radius: 34px;
input {
opacity: 0;
width: 0;
height: 0;
}
}
.docs-slider {
position: absolute;
cursor: pointer;
border-radius: 34px;
inset: 0;
background-color: var(--septenary-contrast);
transition: background-color 0.3s ease, border-color 0.3s ease;
// background
&::before {
content: '';
position: absolute;
inset: 0;
border-radius: 34px;
background: var(--pink-to-purple-horizontal-gradient);
opacity: 0;
transition: opacity 0.3s ease;
}
// toggle knob
&::after {
position: absolute;
content: '';
height: 1.25rem;
width: 1.25rem;
left: 0.125rem;
bottom: 0.125rem;
background-color: var(--page-background);
transition: transform 0.3s ease, background-color 0.3s ease;
border-radius: 50%;
}
}
input {
&:checked + .docs-slider {
// background
&::before {
opacity: 1;
}
// toggle knob
&::after {
transform: translateX(1.5rem);
}
}
}
| {
"end_byte": 1391,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/slide-toggle/slide-toggle.component.scss"
} |
angular/adev/shared-docs/components/slide-toggle/slide-toggle.component.spec.ts_0_1955 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {SlideToggle} from './slide-toggle.component';
import {provideExperimentalZonelessChangeDetection} from '@angular/core';
describe('SlideToggle', () => {
let component: SlideToggle;
let fixture: ComponentFixture<SlideToggle>;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [SlideToggle],
providers: [provideExperimentalZonelessChangeDetection()],
});
fixture = TestBed.createComponent(SlideToggle);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should toggle the value when clicked', () => {
expect(component['checked']()).toBeFalse();
const buttonElement = fixture.nativeElement.querySelector('input');
buttonElement.click();
expect(component['checked']()).toBeTrue();
});
it('should call onChange and onTouched when toggled', () => {
const onChangeSpy = jasmine.createSpy('onChangeSpy');
const onTouchedSpy = jasmine.createSpy('onTouchedSpy');
component.registerOnChange(onChangeSpy);
component.registerOnTouched(onTouchedSpy);
component.toggle();
expect(onChangeSpy).toHaveBeenCalled();
expect(onChangeSpy).toHaveBeenCalledWith(true);
expect(onTouchedSpy).toHaveBeenCalled();
});
it('should set active class for button when is checked', () => {
component.writeValue(true);
fixture.detectChanges();
const buttonElement: HTMLButtonElement = fixture.nativeElement.querySelector('input');
expect(buttonElement.classList.contains('docs-toggle-active')).toBeTrue();
component.writeValue(false);
fixture.detectChanges();
expect(buttonElement.classList.contains('docs-toggle-active')).toBeFalse();
});
});
| {
"end_byte": 1955,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/slide-toggle/slide-toggle.component.spec.ts"
} |
angular/adev/shared-docs/components/slide-toggle/slide-toggle.component.html_0_340 | <label [attr.for]="buttonId">
<span class="docs-label">{{ label }}</span>
<div class="docs-toggle">
<input
type="checkbox"
[id]="buttonId"
role="switch"
(click)="toggle()"
[class.docs-toggle-active]="checked()"
[checked]="checked()"
/>
<span class="docs-slider"></span>
</div>
</label>
| {
"end_byte": 340,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/slide-toggle/slide-toggle.component.html"
} |
angular/adev/shared-docs/components/slide-toggle/BUILD.bazel_0_928 | load("//tools:defaults.bzl", "karma_web_test_suite", "ng_module", "ts_library")
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
package(default_visibility = ["//visibility:private"])
ng_module(
name = "slide-toggle",
srcs = [
"slide-toggle.component.ts",
],
assets = [
":slide-toggle.component.css",
"slide-toggle.component.html",
],
visibility = [
"//adev/shared-docs/components:__pkg__",
],
deps = [
"//packages/common",
"//packages/core",
"//packages/forms",
],
)
sass_binary(
name = "style",
src = "slide-toggle.component.scss",
)
ts_library(
name = "test_lib",
testonly = True,
srcs = glob(
["*.spec.ts"],
),
deps = [
":slide-toggle",
"//packages/core",
"//packages/core/testing",
],
)
karma_web_test_suite(
name = "test",
deps = [":test_lib"],
)
| {
"end_byte": 928,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/slide-toggle/BUILD.bazel"
} |
angular/adev/shared-docs/components/algolia-icon/algolia-icon.component.ts_0_482 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ChangeDetectionStrategy, Component} from '@angular/core';
@Component({
selector: 'docs-algolia-icon',
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [],
templateUrl: './algolia-icon.component.html',
})
export class AlgoliaIcon {}
| {
"end_byte": 482,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/algolia-icon/algolia-icon.component.ts"
} |
angular/adev/shared-docs/components/algolia-icon/algolia-icon.component.html_0_2611 | <!-- Algolia logo -->
<svg
id="Layer_1"
class="docs-algolia-logo"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 2196.2 500"
>
<defs>
<style>
.cls-1,
.cls-2 {
fill: #003dff;
}
.cls-2 {
fill-rule: evenodd;
}
</style>
</defs>
<path
class="cls-2"
d="M1070.38,275.3V5.91c0-3.63-3.24-6.39-6.82-5.83l-50.46,7.94c-2.87,.45-4.99,2.93-4.99,5.84l.17,273.22c0,12.92,0,92.7,95.97,95.49,3.33,.1,6.09-2.58,6.09-5.91v-40.78c0-2.96-2.19-5.51-5.12-5.84-34.85-4.01-34.85-47.57-34.85-54.72Z"
/>
<rect class="cls-1" x="1845.88" y="104.73" width="62.58" height="277.9" rx="5.9" ry="5.9" />
<path
class="cls-2"
d="M1851.78,71.38h50.77c3.26,0,5.9-2.64,5.9-5.9V5.9c0-3.62-3.24-6.39-6.82-5.83l-50.77,7.95c-2.87,.45-4.99,2.92-4.99,5.83v51.62c0,3.26,2.64,5.9,5.9,5.9Z"
/>
<path
class="cls-2"
d="M1764.03,275.3V5.91c0-3.63-3.24-6.39-6.82-5.83l-50.46,7.94c-2.87,.45-4.99,2.93-4.99,5.84l.17,273.22c0,12.92,0,92.7,95.97,95.49,3.33,.1,6.09-2.58,6.09-5.91v-40.78c0-2.96-2.19-5.51-5.12-5.84-34.85-4.01-34.85-47.57-34.85-54.72Z"
/>
<path
class="cls-2"
d="M1631.95,142.72c-11.14-12.25-24.83-21.65-40.78-28.31-15.92-6.53-33.26-9.85-52.07-9.85-18.78,0-36.15,3.17-51.92,9.85-15.59,6.66-29.29,16.05-40.76,28.31-11.47,12.23-20.38,26.87-26.76,44.03-6.38,17.17-9.24,37.37-9.24,58.36,0,20.99,3.19,36.87,9.55,54.21,6.38,17.32,15.14,32.11,26.45,44.36,11.29,12.23,24.83,21.62,40.6,28.46,15.77,6.83,40.12,10.33,52.4,10.48,12.25,0,36.78-3.82,52.7-10.48,15.92-6.68,29.46-16.23,40.78-28.46,11.29-12.25,20.05-27.04,26.25-44.36,6.22-17.34,9.24-33.22,9.24-54.21,0-20.99-3.34-41.19-10.03-58.36-6.38-17.17-15.14-31.8-26.43-44.03Zm-44.43,163.75c-11.47,15.75-27.56,23.7-48.09,23.7-20.55,0-36.63-7.8-48.1-23.7-11.47-15.75-17.21-34.01-17.21-61.2,0-26.89,5.59-49.14,17.06-64.87,11.45-15.75,27.54-23.52,48.07-23.52,20.55,0,36.63,7.78,48.09,23.52,11.47,15.57,17.36,37.98,17.36,64.87,0,27.19-5.72,45.3-17.19,61.2Z"
/>
<path
class="cls-2"
d="M894.42,104.73h-49.33c-48.36,0-90.91,25.48-115.75,64.1-14.52,22.58-22.99,49.63-22.99,78.73,0,44.89,20.13,84.92,51.59,111.1,2.93,2.6,6.05,4.98,9.31,7.14,12.86,8.49,28.11,13.47,44.52,13.47,1.23,0,2.46-.03,3.68-.09,.36-.02,.71-.05,1.07-.07,.87-.05,1.75-.11,2.62-.2,.34-.03,.68-.08,1.02-.12,.91-.1,1.82-.21,2.73-.34,.21-.03,.42-.07,.63-.1,32.89-5.07,61.56-30.82,70.9-62.81v57.83c0,3.26,2.64,5.9,5.9,5.9h50.42c3.26,0,5.9-2.64,5.9-5.9V110.63c0-3.26-2.64-5.9-5.9-5.9h-56.32Zm0,206.92c-12.2,10.16-27.97,13.98-44.84,15.12-.16,.01-.33,.03-.49,.04-1.12,.07-2.24,.1-3.36,.1-42.24,0-77.12-35.89-77.12-79.37,0-10.25,1.96-20.01,5.42-28.98,11.22-29.12,38.77-49.74,71.06-49.74h49.33v142.83Z"
/> | {
"end_byte": 2611,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/algolia-icon/algolia-icon.component.html"
} |
angular/adev/shared-docs/components/algolia-icon/algolia-icon.component.html_2612_5083 | <path
class="cls-2"
d="M2133.97,104.73h-49.33c-48.36,0-90.91,25.48-115.75,64.1-14.52,22.58-22.99,49.63-22.99,78.73,0,44.89,20.13,84.92,51.59,111.1,2.93,2.6,6.05,4.98,9.31,7.14,12.86,8.49,28.11,13.47,44.52,13.47,1.23,0,2.46-.03,3.68-.09,.36-.02,.71-.05,1.07-.07,.87-.05,1.75-.11,2.62-.2,.34-.03,.68-.08,1.02-.12,.91-.1,1.82-.21,2.73-.34,.21-.03,.42-.07,.63-.1,32.89-5.07,61.56-30.82,70.9-62.81v57.83c0,3.26,2.64,5.9,5.9,5.9h50.42c3.26,0,5.9-2.64,5.9-5.9V110.63c0-3.26-2.64-5.9-5.9-5.9h-56.32Zm0,206.92c-12.2,10.16-27.97,13.98-44.84,15.12-.16,.01-.33,.03-.49,.04-1.12,.07-2.24,.1-3.36,.1-42.24,0-77.12-35.89-77.12-79.37,0-10.25,1.96-20.01,5.42-28.98,11.22-29.12,38.77-49.74,71.06-49.74h49.33v142.83Z"
/>
<path
class="cls-2"
d="M1314.05,104.73h-49.33c-48.36,0-90.91,25.48-115.75,64.1-11.79,18.34-19.6,39.64-22.11,62.59-.58,5.3-.88,10.68-.88,16.14s.31,11.15,.93,16.59c4.28,38.09,23.14,71.61,50.66,94.52,2.93,2.6,6.05,4.98,9.31,7.14,12.86,8.49,28.11,13.47,44.52,13.47h0c17.99,0,34.61-5.93,48.16-15.97,16.29-11.58,28.88-28.54,34.48-47.75v50.26h-.11v11.08c0,21.84-5.71,38.27-17.34,49.36-11.61,11.08-31.04,16.63-58.25,16.63-11.12,0-28.79-.59-46.6-2.41-2.83-.29-5.46,1.5-6.27,4.22l-12.78,43.11c-1.02,3.46,1.27,7.02,4.83,7.53,21.52,3.08,42.52,4.68,54.65,4.68,48.91,0,85.16-10.75,108.89-32.21,21.48-19.41,33.15-48.89,35.2-88.52V110.63c0-3.26-2.64-5.9-5.9-5.9h-56.32Zm0,64.1s.65,139.13,0,143.36c-12.08,9.77-27.11,13.59-43.49,14.7-.16,.01-.33,.03-.49,.04-1.12,.07-2.24,.1-3.36,.1-1.32,0-2.63-.03-3.94-.1-40.41-2.11-74.52-37.26-74.52-79.38,0-10.25,1.96-20.01,5.42-28.98,11.22-29.12,38.77-49.74,71.06-49.74h49.33Z"
/>
<path
class="cls-1"
d="M249.83,0C113.3,0,2,110.09,.03,246.16c-2,138.19,110.12,252.7,248.33,253.5,42.68,.25,83.79-10.19,120.3-30.03,3.56-1.93,4.11-6.83,1.08-9.51l-23.38-20.72c-4.75-4.21-11.51-5.4-17.36-2.92-25.48,10.84-53.17,16.38-81.71,16.03-111.68-1.37-201.91-94.29-200.13-205.96,1.76-110.26,92-199.41,202.67-199.41h202.69V407.41l-115-102.18c-3.72-3.31-9.42-2.66-12.42,1.31-18.46,24.44-48.53,39.64-81.93,37.34-46.33-3.2-83.87-40.5-87.34-86.81-4.15-55.24,39.63-101.52,94-101.52,49.18,0,89.68,37.85,93.91,85.95,.38,4.28,2.31,8.27,5.52,11.12l29.95,26.55c3.4,3.01,8.79,1.17,9.63-3.3,2.16-11.55,2.92-23.58,2.07-35.92-4.82-70.34-61.8-126.93-132.17-131.26-80.68-4.97-148.13,58.14-150.27,137.25-2.09,77.1,61.08,143.56,138.19,145.26,32.19,.71,62.03-9.41,86.14-26.95l150.26,133.2c6.44,5.71,16.61,1.14,16.61-7.47V9.48C499.66,4.25,495.42,0,490.18,0H249.83Z"
/>
</svg> | {
"end_byte": 5083,
"start_byte": 2612,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/algolia-icon/algolia-icon.component.html"
} |
angular/adev/shared-docs/components/algolia-icon/BUILD.bazel_0_442 | load("//tools:defaults.bzl", "ng_module")
package(default_visibility = ["//visibility:private"])
ng_module(
name = "algolia-icon",
srcs = [
"algolia-icon.component.ts",
],
assets = [
"algolia-icon.component.html",
],
visibility = [
"//adev/shared-docs/components:__pkg__",
"//adev/shared-docs/components/search-dialog:__pkg__",
],
deps = [
"//packages/core",
],
)
| {
"end_byte": 442,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/algolia-icon/BUILD.bazel"
} |
angular/adev/shared-docs/components/table-of-contents/table-of-contents.component.spec.ts_0_3751 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {TableOfContents} from './table-of-contents.component';
import {RouterTestingModule} from '@angular/router/testing';
import {TableOfContentsItem, TableOfContentsLevel} from '../../interfaces/index';
import {TableOfContentsScrollSpy, TableOfContentsLoader} from '../../services/index';
import {WINDOW} from '../../providers/index';
import {provideExperimentalZonelessChangeDetection, signal} from '@angular/core';
describe('TableOfContents', () => {
let component: TableOfContents;
let fixture: ComponentFixture<TableOfContents>;
let scrollSpy: jasmine.SpyObj<TableOfContentsScrollSpy>;
const items: TableOfContentsItem[] = [
{
title: 'Heading 2',
top: 0,
id: 'item-heading-2',
level: TableOfContentsLevel.H2,
},
{
title: 'First Heading 3',
top: 100,
id: 'first-item-heading-3',
level: TableOfContentsLevel.H3,
},
{
title: 'Second Heading 3',
top: 200,
id: 'second-item-heading-3',
level: TableOfContentsLevel.H3,
},
];
const fakeWindow = {
addEventListener: () => {},
removeEventListener: () => {},
};
beforeEach(async () => {
scrollSpy = jasmine.createSpyObj<TableOfContentsScrollSpy>('TableOfContentsScrollSpy', [
'startListeningToScroll',
'activeItemId',
'scrollbarThumbOnTop',
]);
scrollSpy.startListeningToScroll.and.returnValue();
scrollSpy.activeItemId.and.returnValue(items[0].id);
scrollSpy.scrollbarThumbOnTop.and.returnValue(false);
await TestBed.configureTestingModule({
imports: [TableOfContents, RouterTestingModule],
providers: [
provideExperimentalZonelessChangeDetection(),
{
provide: WINDOW,
useValue: fakeWindow,
},
],
}).compileComponents();
TestBed.overrideProvider(TableOfContentsScrollSpy, {
useValue: scrollSpy,
});
const tableOfContentsLoaderSpy = TestBed.inject(TableOfContentsLoader);
spyOn(tableOfContentsLoaderSpy, 'buildTableOfContent').and.returnValue();
tableOfContentsLoaderSpy.tableOfContentItems.set(items);
fixture = TestBed.createComponent(TableOfContents);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should call scrollToTop when user click on Back to the top button', () => {
const spy = spyOn(component, 'scrollToTop');
fixture.detectChanges();
const button: HTMLButtonElement = fixture.nativeElement.querySelector('button');
button.click();
expect(spy).toHaveBeenCalledOnceWith();
});
it('should render items when tableOfContentItems has value', () => {
fixture.detectChanges();
const renderedItems = fixture.nativeElement.querySelectorAll('li');
expect(renderedItems.length).toBe(3);
expect(component.tableOfContentItems().length).toBe(3);
});
it('should append level class to element', () => {
fixture.detectChanges();
const h2Items = fixture.nativeElement.querySelectorAll('li.docs-toc-item-h2');
const h3Items = fixture.nativeElement.querySelectorAll('li.docs-toc-item-h3');
expect(h2Items.length).toBe(1);
expect(h3Items.length).toBe(2);
});
it('should append active class when item is active', () => {
fixture.detectChanges();
const activeItem = fixture.nativeElement.querySelector('.docs-faceted-list-item-active');
expect(activeItem).toBeTruthy();
});
});
| {
"end_byte": 3751,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/table-of-contents/table-of-contents.component.spec.ts"
} |
angular/adev/shared-docs/components/table-of-contents/table-of-contents.component.html_0_932 | <aside>
<nav>
<header>
<h2 class="docs-title">On this page</h2>
</header>
<ul class="docs-faceted-list">
<!-- TODO: Hide li elements with class docs-toc-item-h3 for laptop, table and phone screen resolutions -->
@for (item of tableOfContentItems(); track item.id) {
<li
class="docs-faceted-list-item"
[class.docs-toc-item-h2]="item.level === TableOfContentsLevel.H2"
[class.docs-toc-item-h3]="item.level === TableOfContentsLevel.H3"
>
<a
routerLink="."
[fragment]="item.id"
[class.docs-faceted-list-item-active]="item.id === activeItemId()"
>
{{ item.title }}
</a>
</li>
}
</ul>
</nav>
@if (shouldDisplayScrollToTop()) {
<button type="button" (click)="scrollToTop()">
<docs-icon role="presentation">arrow_upward_alt</docs-icon>
Back to the top
</button>
}
</aside>
| {
"end_byte": 932,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/table-of-contents/table-of-contents.component.html"
} |
angular/adev/shared-docs/components/table-of-contents/table-of-contents.component.scss_0_1733 | :host {
display: flex;
flex-direction: column;
position: fixed;
right: 16px;
top: 0;
height: fit-content;
width: 14rem;
padding-inline: 1rem;
max-height: 100vh;
overflow-y: scroll;
aside {
margin-bottom: 2rem;
}
& :has(ul li:only-child) {
// Hide the entire TOC is there's only one item
display: none;
}
@media only screen and (max-width: 1430px) {
position: relative;
right: 0;
max-height: min-content;
width: 100%;
}
.docs-title {
font-size: 1.25rem;
margin-block-start: var(--layout-padding);
}
&::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0);
cursor: pointer;
}
&::-webkit-scrollbar {
width: 6px;
height: 6px;
}
&::-webkit-scrollbar-thumb {
background-color: var(--septenary-contrast);
border-radius: 10px;
transition: background-color 0.3s ease;
}
&::-webkit-scrollbar-thumb:hover {
background-color: var(--quinary-contrast);
}
.docs-faceted-list-item {
font-size: 0.875rem;
a {
display: block; // to prevent overflow from the li parent
padding: 0.5rem 0.5rem 0.5rem 1rem;
font-weight: 500;
}
&.docs-toc-item-h3 a {
padding-inline-start: 2rem;
}
}
}
button {
background: transparent;
border: none;
font-size: 0.875rem;
font-family: var(--inter-font);
display: flex;
align-items: center;
margin: 0.5rem 0;
color: var(--tertiary-contrast);
transition: color 0.3s ease;
cursor: pointer;
docs-icon {
margin-inline-end: 0.35rem;
opacity: 0.6;
transition: opacity 0.3s ease;
}
&:hover {
docs-icon {
opacity: 1;
}
}
@media only screen and (max-width: 1430px) {
display: none;
}
}
| {
"end_byte": 1733,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/table-of-contents/table-of-contents.component.scss"
} |
angular/adev/shared-docs/components/table-of-contents/BUILD.bazel_0_1328 | load("//tools:defaults.bzl", "karma_web_test_suite", "ng_module", "ts_library")
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
package(default_visibility = ["//visibility:private"])
ng_module(
name = "table-of-contents",
srcs = [
"table-of-contents.component.ts",
],
assets = [
":table-of-contents.component.css",
"table-of-contents.component.html",
],
visibility = [
"//adev/shared-docs/components:__pkg__",
"//adev/shared-docs/components/viewers:__pkg__",
],
deps = [
"//adev/shared-docs/components/icon",
"//adev/shared-docs/interfaces",
"//adev/shared-docs/services",
"//packages/common",
"//packages/core",
"//packages/router",
],
)
sass_binary(
name = "style",
src = "table-of-contents.component.scss",
)
ts_library(
name = "test_lib",
testonly = True,
srcs = glob(
["*.spec.ts"],
),
deps = [
":table-of-contents",
"//adev/shared-docs/interfaces",
"//adev/shared-docs/providers",
"//adev/shared-docs/services",
"//packages/core",
"//packages/core/testing",
"//packages/router",
"//packages/router/testing",
],
)
karma_web_test_suite(
name = "test",
deps = [":test_lib"],
)
| {
"end_byte": 1328,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/table-of-contents/BUILD.bazel"
} |
angular/adev/shared-docs/components/table-of-contents/table-of-contents.component.ts_0_1810 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {
ChangeDetectionStrategy,
Component,
DestroyRef,
Input,
computed,
inject,
} from '@angular/core';
import {RouterLink} from '@angular/router';
import {TableOfContentsLevel} from '../../interfaces/index';
import {TableOfContentsLoader} from '../../services/table-of-contents-loader.service';
import {TableOfContentsScrollSpy} from '../../services/table-of-contents-scroll-spy.service';
import {IconComponent} from '../icon/icon.component';
@Component({
selector: 'docs-table-of-contents',
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './table-of-contents.component.html',
styleUrls: ['./table-of-contents.component.scss'],
imports: [RouterLink, IconComponent],
})
export class TableOfContents {
// Element that contains the content from which the Table of Contents is built
@Input({required: true}) contentSourceElement!: HTMLElement;
private readonly scrollSpy = inject(TableOfContentsScrollSpy);
private readonly tableOfContentsLoader = inject(TableOfContentsLoader);
private readonly destroyRef = inject(DestroyRef);
tableOfContentItems = this.tableOfContentsLoader.tableOfContentItems;
activeItemId = this.scrollSpy.activeItemId;
shouldDisplayScrollToTop = computed(() => !this.scrollSpy.scrollbarThumbOnTop());
TableOfContentsLevel = TableOfContentsLevel;
ngAfterViewInit() {
this.tableOfContentsLoader.buildTableOfContent(this.contentSourceElement);
this.scrollSpy.startListeningToScroll(this.contentSourceElement, this.destroyRef);
}
scrollToTop(): void {
this.scrollSpy.scrollToTop();
}
}
| {
"end_byte": 1810,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/table-of-contents/table-of-contents.component.ts"
} |
angular/adev/shared-docs/components/copy-source-code-button/copy-source-code-button.component.ts_0_2790 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
WritableSignal,
inject,
signal,
} from '@angular/core';
import {CommonModule} from '@angular/common';
import {Clipboard} from '@angular/cdk/clipboard';
import {IconComponent} from '../icon/icon.component';
export const REMOVED_LINE_CLASS_NAME = '.line.remove';
export const CONFIRMATION_DISPLAY_TIME_MS = 2000;
@Component({
selector: 'button[docs-copy-source-code]',
standalone: true,
imports: [CommonModule, IconComponent],
templateUrl: './copy-source-code-button.component.html',
host: {
'type': 'button',
'aria-label': 'Copy example source to clipboard',
'title': 'Copy example source',
'(click)': 'copySourceCode()',
'[class.docs-copy-source-code-button-success]': 'showCopySuccess()',
'[class.docs-copy-source-code-button-failed]': 'showCopyFailure()',
},
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CopySourceCodeButton {
private readonly changeDetector = inject(ChangeDetectorRef);
private readonly clipboard = inject(Clipboard);
private readonly elementRef = inject(ElementRef);
protected readonly showCopySuccess = signal(false);
protected readonly showCopyFailure = signal(false);
copySourceCode(): void {
try {
const codeElement = this.elementRef.nativeElement.parentElement.querySelector(
'code',
) as HTMLElement;
const sourceCode = this.getSourceCode(codeElement);
this.clipboard.copy(sourceCode);
this.showResult(this.showCopySuccess);
} catch {
this.showResult(this.showCopyFailure);
}
}
private getSourceCode(codeElement: HTMLElement): string {
this.showCopySuccess.set(false);
this.showCopyFailure.set(false);
const removedLines: NodeList = codeElement.querySelectorAll(REMOVED_LINE_CLASS_NAME);
if (removedLines.length) {
// Get only those lines which are not marked as removed
const formattedText = Array.from(codeElement.querySelectorAll('.line:not(.remove)'))
.map((line) => (line as HTMLDivElement).innerText)
.join('\n');
return formattedText.trim();
} else {
const text: string = codeElement.innerText || '';
return text.replace(/\n\n\n/g, ``).trim();
}
}
private showResult(messageState: WritableSignal<boolean>) {
messageState.set(true);
setTimeout(() => {
messageState.set(false);
// It's required for code snippets embedded in the ExampleViewer.
this.changeDetector.markForCheck();
}, CONFIRMATION_DISPLAY_TIME_MS);
}
}
| {
"end_byte": 2790,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/copy-source-code-button/copy-source-code-button.component.ts"
} |
angular/adev/shared-docs/components/copy-source-code-button/copy-source-code-button.component.html_0_675 | <i>
<svg
aria-hidden="true"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
class="docs-copy"
>
<path
d="M5 22C4.45 22 3.97917 21.8042 3.5875 21.4125C3.19583 21.0208 3 20.55 3 20V6H5V20H16V22H5ZM9 18C8.45 18 7.97917 17.8042 7.5875 17.4125C7.19583 17.0208 7 16.55 7 16V4C7 3.45 7.19583 2.97917 7.5875 2.5875C7.97917 2.19583 8.45 2 9 2H18C18.55 2 19.0208 2.19583 19.4125 2.5875C19.8042 2.97917 20 3.45 20 4V16C20 16.55 19.8042 17.0208 19.4125 17.4125C19.0208 17.8042 18.55 18 18 18H9ZM9 16H18V4H9V16Z"
fill="#A39FA9"
/>
</svg>
</i>
<docs-icon class="docs-check">check</docs-icon>
| {
"end_byte": 675,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/copy-source-code-button/copy-source-code-button.component.html"
} |
angular/adev/shared-docs/components/copy-source-code-button/copy-source-code-button.component.spec.ts_0_4201 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ComponentFixture, TestBed, fakeAsync, tick} from '@angular/core/testing';
import {
CONFIRMATION_DISPLAY_TIME_MS,
CopySourceCodeButton,
} from './copy-source-code-button.component';
import {
ChangeDetectionStrategy,
Component,
provideExperimentalZonelessChangeDetection,
signal,
} from '@angular/core';
import {By} from '@angular/platform-browser';
import {Clipboard} from '@angular/cdk/clipboard';
const SUCCESSFULLY_COPY_CLASS_NAME = 'docs-copy-source-code-button-success';
const FAILED_COPY_CLASS_NAME = 'docs-copy-source-code-button-failed';
describe('CopySourceCodeButton', () => {
let component: CodeSnippetWrapper;
let fixture: ComponentFixture<CodeSnippetWrapper>;
let copySpy: jasmine.Spy<(text: string) => boolean>;
beforeEach(async () => {
TestBed.configureTestingModule({
imports: [CodeSnippetWrapper],
providers: [provideExperimentalZonelessChangeDetection()],
});
fixture = TestBed.createComponent(CodeSnippetWrapper);
component = fixture.componentInstance;
await fixture.whenStable();
});
beforeEach(() => {
const clipboardService = TestBed.inject(Clipboard);
copySpy = spyOn(clipboardService, 'copy');
});
it('should call clipboard service when clicked on copy source code', async () => {
const expectedCodeToBeCopied = 'npm install -g @angular/cli';
component.code.set(expectedCodeToBeCopied);
await fixture.whenStable();
const button = fixture.debugElement.query(By.directive(CopySourceCodeButton)).nativeElement;
button.click();
expect(copySpy.calls.argsFor(0)[0].trim()).toBe(expectedCodeToBeCopied);
});
it('should not copy lines marked as deleted when code snippet contains diff', async () => {
const codeInHtmlFormat = `
<code>
<div class="line remove"><span class="hljs-tag"><<span class="hljs-name">div</span> *<span class="hljs-attr">ngFor</span>=<span class="hljs-string">"let product of products"</span>></span></div>
<div class="line add"><span class="hljs-tag"><<span class="hljs-name">div</span> *<span class="hljs-attr">ngFor</span>=<span class="hljs-string">"let product of products()"</span>></span></div>
</code>
`;
const expectedCodeToBeCopied = `<div *ngFor="let product of products()">`;
component.code.set(codeInHtmlFormat);
await fixture.whenStable();
const button = fixture.debugElement.query(By.directive(CopySourceCodeButton)).nativeElement;
button.click();
expect(copySpy.calls.argsFor(0)[0].trim()).toBe(expectedCodeToBeCopied);
});
it(`should set ${SUCCESSFULLY_COPY_CLASS_NAME} for ${CONFIRMATION_DISPLAY_TIME_MS} ms when copy was executed properly`, fakeAsync(() => {
component.code.set('example');
fixture.detectChanges();
const button = fixture.debugElement.query(By.directive(CopySourceCodeButton)).nativeElement;
button.click();
fixture.detectChanges();
expect(button).toHaveClass(SUCCESSFULLY_COPY_CLASS_NAME);
tick(CONFIRMATION_DISPLAY_TIME_MS);
fixture.detectChanges();
expect(button).not.toHaveClass(SUCCESSFULLY_COPY_CLASS_NAME);
}));
it(`should set ${FAILED_COPY_CLASS_NAME} for ${CONFIRMATION_DISPLAY_TIME_MS} ms when copy failed`, fakeAsync(() => {
component.code.set('example');
copySpy.and.throwError('Fake copy error');
fixture.detectChanges();
const button = fixture.debugElement.query(By.directive(CopySourceCodeButton)).nativeElement;
button.click();
fixture.detectChanges();
expect(button).toHaveClass(FAILED_COPY_CLASS_NAME);
tick(CONFIRMATION_DISPLAY_TIME_MS);
fixture.detectChanges();
expect(button).not.toHaveClass(FAILED_COPY_CLASS_NAME);
}));
});
@Component({
template: `
<pre>
<code [innerHtml]="code()"></code>
</pre>
<button docs-copy-source-code></button>
`,
imports: [CopySourceCodeButton],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
})
class CodeSnippetWrapper {
code = signal('');
}
| {
"end_byte": 4201,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/copy-source-code-button/copy-source-code-button.component.spec.ts"
} |
angular/adev/shared-docs/components/copy-source-code-button/BUILD.bazel_0_975 | load("//tools:defaults.bzl", "karma_web_test_suite", "ng_module", "ts_library")
package(default_visibility = ["//visibility:private"])
ng_module(
name = "copy-source-code-button",
srcs = [
"copy-source-code-button.component.ts",
],
assets = [
"copy-source-code-button.component.html",
],
visibility = [
"//adev/shared-docs/components:__pkg__",
"//adev/shared-docs/components/viewers:__pkg__",
],
deps = [
"//adev/shared-docs/components/icon",
"//packages/common",
"//packages/core",
"@npm//@angular/cdk",
],
)
ts_library(
name = "test_lib",
testonly = True,
srcs = glob(
["*.spec.ts"],
),
deps = [
":copy-source-code-button",
"//packages/core",
"//packages/core/testing",
"//packages/platform-browser",
"@npm//@angular/cdk",
],
)
karma_web_test_suite(
name = "test",
deps = [":test_lib"],
)
| {
"end_byte": 975,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/copy-source-code-button/BUILD.bazel"
} |
angular/adev/shared-docs/components/viewers/BUILD.bazel_0_2189 | load("//tools:defaults.bzl", "karma_web_test_suite", "ng_module", "ts_library")
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
package(default_visibility = ["//visibility:private"])
ng_module(
name = "viewers",
srcs = [
"docs-viewer/docs-viewer.component.ts",
"example-viewer/example-viewer.component.ts",
],
assets = [
":docs-viewer/docs-viewer.component.css",
":example-viewer/example-viewer.component.css",
"example-viewer/example-viewer.component.html",
],
visibility = [
"//adev/shared-docs/components:__pkg__",
],
deps = [
"//adev/shared-docs/components/breadcrumb",
"//adev/shared-docs/components/copy-source-code-button",
"//adev/shared-docs/components/table-of-contents",
"//adev/shared-docs/interfaces",
"//adev/shared-docs/providers",
"//packages/common",
"//packages/core",
"//packages/router",
"@npm//@angular/cdk",
"@npm//@angular/material",
"@npm//@types/dom-view-transitions",
],
)
sass_binary(
name = "example-viewer-style",
src = "example-viewer/example-viewer.component.scss",
)
sass_binary(
name = "docs-viewer-style",
src = "docs-viewer/docs-viewer.component.scss",
deps = [
"//adev/shared-docs/styles",
],
)
ts_library(
name = "test_lib",
testonly = True,
srcs = glob(
["**/*.spec.ts"],
),
deps = [
":viewers",
"//adev/shared-docs/components/breadcrumb",
"//adev/shared-docs/components/copy-source-code-button",
"//adev/shared-docs/components/icon",
"//adev/shared-docs/components/table-of-contents",
"//adev/shared-docs/interfaces",
"//adev/shared-docs/providers",
"//adev/shared-docs/services",
"//packages/core",
"//packages/core/testing",
"//packages/platform-browser",
"//packages/platform-browser/animations",
"//packages/router",
"//packages/router/testing",
"@npm//@angular/cdk",
"@npm//@angular/material",
],
)
karma_web_test_suite(
name = "test",
deps = [":test_lib"],
)
| {
"end_byte": 2189,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/viewers/BUILD.bazel"
} |
angular/adev/shared-docs/components/viewers/docs-viewer/docs-viewer.component.spec.ts_0_4729 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {RouterTestingModule} from '@angular/router/testing';
import {ExampleViewerContentLoader} from '../../../interfaces';
import {EXAMPLE_VIEWER_CONTENT_LOADER} from '../../../providers';
import {CodeExampleViewMode, ExampleViewer} from '../example-viewer/example-viewer.component';
import {DocViewer} from './docs-viewer.component';
import {IconComponent} from '../../icon/icon.component';
import {Breadcrumb} from '../../breadcrumb/breadcrumb.component';
import {NavigationState} from '../../../services';
import {CopySourceCodeButton} from '../../copy-source-code-button/copy-source-code-button.component';
import {TableOfContents} from '../../table-of-contents/table-of-contents.component';
import {provideExperimentalZonelessChangeDetection} from '@angular/core';
describe('DocViewer', () => {
let fixture: ComponentFixture<DocViewer>;
let exampleContentSpy: jasmine.SpyObj<ExampleViewerContentLoader>;
let navigationStateSpy: jasmine.SpyObj<NavigationState>;
const exampleDocContentWithExampleViewerPlaceholders = `<div class="docs-code linenums" visibleLines="[12, 31]" expanded="true" path="hello-world/hello-world-new.ts">
<div class="docs-code-header">A styled code example</div>
<pre>
<code><div class="hljs-ln-line"><span class="hljs-comment">/*!</div><div class="hljs-ln-line"> * @license</div><div class="hljs-ln-line"> * Copyright Google LLC All Rights Reserved.</div><div class="hljs-ln-line"> *</div><div class="hljs-ln-line"> * Use of this source code is governed by an MIT-style license that can be</div><div class="hljs-ln-line"> * found in the LICENSE file at https://angular.dev/license</div><div class="hljs-ln-line"> */</span></div><div class="hljs-ln-line"></div><div class="hljs-ln-line remove"><span class="hljs-keyword">import</span> {ChangeDetectorRef, Component, <span class="hljs-keyword">inject</span>, signal} <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/core'</span>;</div><div class="hljs-ln-line add"><span class="hljs-keyword">import</span> {Component, signal} <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/core'</span>;</div><div class="hljs-ln-line"><span class="hljs-keyword">import</span> {CommonModule} <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/common'</span>;</div><div class="hljs-ln-line"></div><div class="hljs-ln-line highlighted">@Component({</div><div class="hljs-ln-line highlighted"> selector: <span class="hljs-string">'hello-world'</span>,</div><div class="hljs-ln-line highlighted"> standalone: <span class="hljs-keyword">true</span>,</div><div class="hljs-ln-line highlighted"> imports: [CommonModule],</div><div class="hljs-ln-line highlighted"> templateUrl: <span class="hljs-string">'./hello-world.html'</span>,</div><div class="hljs-ln-line highlighted"> styleUrls: [<span class="hljs-string">'./hello-world.css'</span>],</div><div class="hljs-ln-line highlighted">})</div><div class="hljs-ln-line">export <span class="hljs-keyword">default</span> <span class="hljs-keyword">class</span> HelloWorldComponent {</div><div class="hljs-ln-line remove"> world = <span class="hljs-string">'World'</span>;</div><div class="hljs-ln-line add"> world = <span class="hljs-string">'World!!!'</span>;</div><div class="hljs-ln-line"> <span class="hljs-keyword">count</span> = signal(<span class="hljs-number">0</span>);</div><div class="hljs-ln-line remove"> changeDetector = <span class="hljs-keyword">inject</span>(ChangeDetectorRef);</div><div class="hljs-ln-line"></div><div class="hljs-ln-line"> increase(): <span class="hljs-keyword">void</span> {</div><div class="hljs-ln-line"> <span class="hljs-keyword">this</span>.<span class="hljs-keyword">count</span>.update((<span class="hljs-keyword">previous</span>) => {</div><div class="hljs-ln-line highlighted"> <span class="hljs-keyword">return</span> <span class="hljs-keyword">previous</span> + <span class="hljs-number">1</span>;</div><div class="hljs-ln-line"> });</div><div class="hljs-ln-line remove"> <span class="hljs-keyword">this</span>.changeDetector.detectChanges();</div><div class="hljs-ln-line"> }</div><div class="hljs-ln-line">}</div><div class="hljs-ln-line"></div></code>
</pre>
</div>`; | {
"end_byte": 4729,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/viewers/docs-viewer/docs-viewer.component.spec.ts"
} |
angular/adev/shared-docs/components/viewers/docs-viewer/docs-viewer.component.spec.ts_4733_11218 | const exampleDocContentWithExpandedExampleViewerPlaceholders = `<div class="docs-code-multifile" expanded="true" path="hello-world/hello-world-new.ts">
<div class="docs-code" visibleLines="[12, 31]" path="hello-world/hello-world-new.ts">
<pre>
<code><div class="hljs-ln-line"><span class="hljs-comment">/*!</div><div class="hljs-ln-line"> * @license</div><div class="hljs-ln-line"> * Copyright Google LLC All Rights Reserved.</div><div class="hljs-ln-line"> *</div><div class="hljs-ln-line"> * Use of this source code is governed by an MIT-style license that can be</div><div class="hljs-ln-line"> * found in the LICENSE file at https://angular.dev/license</div><div class="hljs-ln-line"> */</span></div><div class="hljs-ln-line"></div><div class="hljs-ln-line remove"><span class="hljs-keyword">import</span> {ChangeDetectorRef, Component, <span class="hljs-keyword">inject</span>, signal} <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/core'</span>;</div><div class="hljs-ln-line add"><span class="hljs-keyword">import</span> {Component, signal} <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/core'</span>;</div><div class="hljs-ln-line"><span class="hljs-keyword">import</span> {CommonModule} <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/common'</span>;</div><div class="hljs-ln-line"></div><div class="hljs-ln-line">@Component({</div><div class="hljs-ln-line"> selector: <span class="hljs-string">'hello-world'</span>,</div><div class="hljs-ln-line"> standalone: <span class="hljs-keyword">true</span>,</div><div class="hljs-ln-line"> imports: [CommonModule],</div><div class="hljs-ln-line"> templateUrl: <span class="hljs-string">'./hello-world.html'</span>,</div><div class="hljs-ln-line"> styleUrls: [<span class="hljs-string">'./hello-world.css'</span>],</div><div class="hljs-ln-line">})</div><div class="hljs-ln-line">export <span class="hljs-keyword">default</span> <span class="hljs-keyword">class</span> HelloWorldComponent {</div><div class="hljs-ln-line remove"> world = <span class="hljs-string">'World'</span>;</div><div class="hljs-ln-line add"> world = <span class="hljs-string">'World!!!'</span>;</div><div class="hljs-ln-line"> <span class="hljs-keyword">count</span> = signal(<span class="hljs-number">0</span>);</div><div class="hljs-ln-line remove"> changeDetector = <span class="hljs-keyword">inject</span>(ChangeDetectorRef);</div><div class="hljs-ln-line"></div><div class="hljs-ln-line"> increase(): <span class="hljs-keyword">void</span> {</div><div class="hljs-ln-line"> <span class="hljs-keyword">this</span>.<span class="hljs-keyword">count</span>.update((<span class="hljs-keyword">previous</span>) => {</div><div class="hljs-ln-line"> <span class="hljs-keyword">return</span> <span class="hljs-keyword">previous</span> + <span class="hljs-number">1</span>;</div><div class="hljs-ln-line"> });</div><div class="hljs-ln-line remove"> <span class="hljs-keyword">this</span>.changeDetector.detectChanges();</div><div class="hljs-ln-line"> }</div><div class="hljs-ln-line">}</div><div class="hljs-ln-line"></div></code>
</pre>
</div>
<div class="docs-code linenums" path="hello-world/hello-world.html">
<pre>
<code><div class="hljs-ln-line"><span class="language-xml"><span class="hljs-tag"><<span class="hljs-name">h2</span>></span>Hello </span><span class="hljs-template-variable">{{ <span class="hljs-name">world</span> }}</span><span class="language-xml"><span class="hljs-tag"></<span class="hljs-name">h2</span>></span></div><div class="hljs-ln-line"><span class="hljs-tag"><<span class="hljs-name">button</span> (<span class="hljs-attr">click</span>)=<span class="hljs-string">"increase()"</span>></span>Increase<span class="hljs-tag"></<span class="hljs-name">button</span>></span></div><div class="hljs-ln-line"><span class="hljs-tag"><<span class="hljs-name">p</span>></span>Counter: </span><span class="hljs-template-variable">{{ <span class="hljs-name">count</span>() }}</span><span class="language-xml"><span class="hljs-tag"></<span class="hljs-name">p</span>></span></div><div class="hljs-ln-line"></span></div></code>
</pre>
</div>
</div>`;
const exampleContentWithIcons = `
<p>Content</p>
<docs-icon>light_mode</docs-icon>
<p>More content</p>
<docs-icon>dark_mode</docs-icon>
`;
const exampleContentWithBreadcrumbPlaceholder = `
<docs-breadcrumb></docs-breadcrumb>
<p>Content</p>
`;
const exampleContentWithCodeSnippet = `
<div class="docs-code" path="forms/src/app/actor.ts" header="src/app/actor.ts">
<pre class="docs-mini-scroll-track">
<code>
<div class="hljs-ln-line"></div>
</code>
</pre>
</div>
`;
const exampleContentWithHeadings = `
<h2>Heading h2</h2>
<h3>Heading h3</h3>
`;
beforeEach(() => {
exampleContentSpy = jasmine.createSpyObj('ExampleViewerContentLoader', ['getCodeExampleData']);
navigationStateSpy = jasmine.createSpyObj(NavigationState, ['activeNavigationItem']);
});
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [DocViewer, NoopAnimationsModule, RouterTestingModule],
providers: [
provideExperimentalZonelessChangeDetection(),
{provide: EXAMPLE_VIEWER_CONTENT_LOADER, useValue: exampleContentSpy},
{provide: NavigationState, useValue: navigationStateSpy},
],
}).compileComponents();
fixture = TestBed.createComponent(DocViewer);
fixture.detectChanges();
});
it('should load doc into innerHTML', () => {
const fixture = TestBed.createComponent(DocViewer);
fixture.componentRef.setInput('docContent', 'hello world');
fixture.detectChanges();
expect(fixture.nativeElement.innerHTML).toBe('hello world');
});
it('should instantiate example viewer in snippet view mode', async () => {
const fixture = TestBed.createComponent(DocViewer);
fixture.componentRef.setInput('docContent', exampleDocContentWithExampleViewerPlaceholders);
fixture.detectChanges();
await fixture.whenStable();
const exampleViewer = fixture.debugElement.query(By.directive(ExampleViewer));
expect(exampleViewer).not.toBeNull();
expect(exampleViewer.componentInstance.view()).toBe(CodeExampleViewMode.SNIPPET);
}); | {
"end_byte": 11218,
"start_byte": 4733,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/viewers/docs-viewer/docs-viewer.component.spec.ts"
} |
angular/adev/shared-docs/components/viewers/docs-viewer/docs-viewer.component.spec.ts_11222_14900 | it('should display example viewer in multi file mode when user clicks expand', async () => {
const fixture = TestBed.createComponent(DocViewer);
fixture.componentRef.setInput(
'docContent',
exampleDocContentWithExpandedExampleViewerPlaceholders,
);
fixture.detectChanges();
await fixture.whenStable();
const exampleViewer = fixture.debugElement.query(By.directive(ExampleViewer));
const expandButton = fixture.debugElement.query(
By.css('button[aria-label="Expand code example"]'),
);
expandButton.nativeElement.click();
expect(exampleViewer).not.toBeNull();
expect(exampleViewer.componentInstance.view()).toBe(CodeExampleViewMode.MULTI_FILE);
expect(exampleViewer.componentInstance.tabs().length).toBe(2);
});
it('should render Icon component when content has <docs-icon> element', async () => {
const fixture = TestBed.createComponent(DocViewer);
const renderComponentSpy = spyOn(fixture.componentInstance, 'renderComponent' as any);
fixture.componentRef.setInput('docContent', exampleContentWithIcons);
fixture.detectChanges();
await fixture.whenStable();
expect(renderComponentSpy).toHaveBeenCalledTimes(2);
expect(renderComponentSpy.calls.allArgs()[0][0]).toBe(IconComponent);
expect((renderComponentSpy.calls.allArgs()[0][1] as HTMLElement).innerText).toEqual(
`light_mode`,
);
expect(renderComponentSpy.calls.allArgs()[1][0]).toBe(IconComponent);
expect((renderComponentSpy.calls.allArgs()[1][1] as HTMLElement).innerText).toEqual(
`dark_mode`,
);
});
it('should render Breadcrumb component when content has <docs-breadcrumb> element', async () => {
navigationStateSpy.activeNavigationItem.and.returnValue({
label: 'Active Item',
parent: {
label: 'Parent Item',
},
});
const fixture = TestBed.createComponent(DocViewer);
const renderComponentSpy = spyOn(fixture.componentInstance, 'renderComponent' as any);
fixture.componentRef.setInput('docContent', exampleContentWithBreadcrumbPlaceholder);
fixture.detectChanges();
await fixture.whenStable();
expect(renderComponentSpy).toHaveBeenCalledTimes(1);
expect(renderComponentSpy.calls.allArgs()[0][0]).toBe(Breadcrumb);
});
it('should render copy source code buttons', async () => {
const fixture = TestBed.createComponent(DocViewer);
fixture.componentRef.setInput('docContent', exampleContentWithCodeSnippet);
fixture.detectChanges();
await fixture.whenStable();
const copySourceCodeButton = fixture.debugElement.query(By.directive(CopySourceCodeButton));
expect(copySourceCodeButton).toBeTruthy();
});
it('should render ToC', async () => {
const fixture = TestBed.createComponent(DocViewer);
const renderComponentSpy = spyOn(fixture.componentInstance, 'renderComponent' as any);
fixture.componentRef.setInput('docContent', exampleContentWithHeadings);
fixture.componentRef.setInput('hasToc', true);
fixture.detectChanges();
await fixture.whenStable();
expect(renderComponentSpy).toHaveBeenCalled();
expect(renderComponentSpy.calls.allArgs()[0][0]).toBe(TableOfContents);
});
it('should not render ToC when hasToc is false', async () => {
const fixture = TestBed.createComponent(DocViewer);
const renderComponentSpy = spyOn(fixture.componentInstance, 'renderComponent' as any);
fixture.componentRef.setInput('docContent', exampleContentWithHeadings);
fixture.componentRef.setInput('hasToc', false);
fixture.detectChanges();
await fixture.whenStable();
expect(renderComponentSpy).not.toHaveBeenCalled();
});
}); | {
"end_byte": 14900,
"start_byte": 11222,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/viewers/docs-viewer/docs-viewer.component.spec.ts"
} |
angular/adev/shared-docs/components/viewers/docs-viewer/docs-viewer.component.scss_0_2097 | @use '../../../styles/links' as links;
@use '../../../styles/anchor' as anchor;
:host {
--translate-y: clamp(5px, 0.25em, 7px);
}
.docs-viewer {
display: flex;
flex-direction: column;
padding: var(--layout-padding);
max-width: var(--page-width);
width: 100%;
box-sizing: border-box;
@media only screen and (max-width: 1430px) {
container: docs-content / inline-size;
}
// If rendered on the docs page, accommodate width for TOC
docs-docs & {
@media only screen and (min-width: 1430px) and (max-width: 1550px) {
width: calc(100% - 195px - var(--layout-padding));
max-width: var(--page-width);
}
}
pre {
margin-block: 0;
}
h1,
h2,
h3,
h4,
h5,
h6 {
.docs-anchor {
margin-block-start: 2.5rem;
display: inline-block;
color: inherit;
@include anchor.docs-anchor();
}
}
h1 {
font-size: 2.5rem;
margin-block-end: 0;
}
h2 {
font-size: 2rem;
margin-block-end: 0.5rem;
}
h3 {
font-size: 1.5rem;
margin-block-end: 0.5rem;
}
h4 {
font-size: 1.25rem;
margin-block-end: 0.5rem;
}
h5 {
font-size: 1rem;
margin-block-end: 0;
}
h6 {
font-size: 0.875rem;
margin-block-end: 0;
}
> :last-child {
margin-block-end: 0;
}
a:not(.docs-github-links):not(.docs-card):not(.docs-pill):not(.docs-example-github-link) {
&[href^='http:'],
&[href^='https:'] {
@include links.external-link-with-icon();
}
}
&-scroll-margin-large {
h2,
h3 {
scroll-margin: 5em;
}
}
}
.docs-header {
margin-block-end: 1rem;
& > p:first-child {
color: var(--quaternary-contrast);
font-weight: 500;
margin: 0;
}
}
.docs-page-title {
display: flex;
justify-content: space-between;
h1 {
margin-block: 0;
font-size: 2.25rem;
}
a {
color: var(--primary-contrast);
height: fit-content;
docs-icon {
color: var(--gray-400);
transition: color 0.3s ease;
}
&:hover {
docs-icon {
color: var(--primary-contrast);
}
}
}
}
| {
"end_byte": 2097,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/viewers/docs-viewer/docs-viewer.component.scss"
} |
angular/adev/shared-docs/components/viewers/docs-viewer/docs-viewer.component.ts_0_2183 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {CommonModule, DOCUMENT, isPlatformBrowser, Location} from '@angular/common';
import {
ApplicationRef,
ChangeDetectionStrategy,
Component,
ComponentRef,
createComponent,
DestroyRef,
ElementRef,
EnvironmentInjector,
inject,
Injector,
Input,
OnChanges,
PLATFORM_ID,
SimpleChanges,
Type,
ViewContainerRef,
ViewEncapsulation,
ɵPendingTasks as PendingTasks,
EventEmitter,
Output,
} from '@angular/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {TOC_SKIP_CONTENT_MARKER, NavigationState} from '../../../services/index';
import {TableOfContents} from '../../table-of-contents/table-of-contents.component';
import {IconComponent} from '../../icon/icon.component';
import {handleHrefClickEventWithRouter} from '../../../utils/index';
import {Snippet} from '../../../interfaces/index';
import {Router} from '@angular/router';
import {fromEvent} from 'rxjs';
import {Breadcrumb} from '../../breadcrumb/breadcrumb.component';
import {CopySourceCodeButton} from '../../copy-source-code-button/copy-source-code-button.component';
import {ExampleViewer} from '../example-viewer/example-viewer.component';
/// <reference types="@types/dom-view-transitions" />
const TOC_HOST_ELEMENT_NAME = 'docs-table-of-contents';
export const ASSETS_EXAMPLES_PATH = 'assets/content/examples';
export const DOCS_VIEWER_SELECTOR = 'docs-viewer';
export const DOCS_CODE_SELECTOR = '.docs-code';
export const DOCS_CODE_MUTLIFILE_SELECTOR = '.docs-code-multifile';
// TODO: Update the branch/sha
export const GITHUB_CONTENT_URL =
'https://github.com/angular/angular/blob/main/adev/src/content/examples/';
@Component({
selector: DOCS_VIEWER_SELECTOR,
standalone: true,
imports: [CommonModule],
template: '',
styleUrls: ['docs-viewer.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
host: {
'[class.docs-animate-content]': 'animateContent',
},
})
export | {
"end_byte": 2183,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/viewers/docs-viewer/docs-viewer.component.ts"
} |
angular/adev/shared-docs/components/viewers/docs-viewer/docs-viewer.component.ts_2184_11326 | lass DocViewer implements OnChanges {
@Input() docContent?: string;
@Input() hasToc = false;
@Output() contentLoaded = new EventEmitter<void>();
private readonly destroyRef = inject(DestroyRef);
private readonly document = inject(DOCUMENT);
private readonly elementRef = inject(ElementRef);
private readonly location = inject(Location);
private readonly navigationState = inject(NavigationState);
private readonly router = inject(Router);
private readonly viewContainer = inject(ViewContainerRef);
private readonly environmentInjector = inject(EnvironmentInjector);
private readonly injector = inject(Injector);
private readonly appRef = inject(ApplicationRef);
// tslint:disable-next-line:no-unused-variable
private animateContent = false;
private readonly pendingTasks = inject(PendingTasks);
private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
private countOfExamples = 0;
async ngOnChanges(changes: SimpleChanges): Promise<void> {
const taskId = this.pendingTasks.add();
if ('docContent' in changes) {
await this.renderContentsAndRunClientSetup(this.docContent!);
}
this.pendingTasks.remove(taskId);
}
async renderContentsAndRunClientSetup(content?: string): Promise<void> {
const contentContainer = this.elementRef.nativeElement;
if (content) {
if (this.isBrowser && !(this.document as any).startViewTransition) {
// Apply a special class to the host node to trigger animation.
// Note: when a page is hydrated, the `content` would be empty,
// so we don't trigger an animation to avoid a content flickering
// visual effect. In addition, if the browser supports view transitions (startViewTransition is present), the animation is handled by the native View Transition API so it does not need to be done here.
this.animateContent = true;
}
contentContainer.innerHTML = content;
}
if (this.isBrowser) {
// First we setup event listeners on the HTML we just loaded.
// We want to do this before things like the example viewers are loaded.
this.setupAnchorListeners(contentContainer);
// Rewrite relative anchors (hrefs starting with `#`) because relative hrefs are relative to the base URL, which is '/'
this.rewriteRelativeAnchors(contentContainer);
// In case when content contains placeholders for executable examples, create ExampleViewer components.
await this.loadExamples();
// In case when content contains static code snippets, then create buttons
// responsible for copy source code.
this.loadCopySourceCodeButtons();
}
// Display Breadcrumb component if the `<docs-breadcrumb>` element exists
this.loadBreadcrumb(contentContainer);
// Display Icon component if the `<docs-icon>` element exists
this.loadIcons(contentContainer);
// Render ToC
this.renderTableOfContents(contentContainer);
this.contentLoaded.next();
}
/**
* Load ExampleViewer component when:
* - exists docs-code-multifile element with multiple files OR
* - exists docs-code element with single file AND
* - 'preview' attribute was provided OR
* - 'visibleLines' attribute was provided
*/
private async loadExamples(): Promise<void> {
const multifileCodeExamples = <HTMLElement[]>(
Array.from(this.elementRef.nativeElement.querySelectorAll(DOCS_CODE_MUTLIFILE_SELECTOR))
);
for (let placeholder of multifileCodeExamples) {
const path = placeholder.getAttribute('path')!;
const snippets = this.getCodeSnippetsFromMultifileWrapper(placeholder);
await this.renderExampleViewerComponents(placeholder, snippets, path);
}
const docsCodeElements = this.elementRef.nativeElement.querySelectorAll(DOCS_CODE_SELECTOR);
for (const placeholder of docsCodeElements) {
const snippet = this.getStandaloneCodeSnippet(placeholder);
if (snippet) {
await this.renderExampleViewerComponents(placeholder, [snippet], snippet.name);
}
}
}
private renderTableOfContents(element: HTMLElement): void {
if (!this.hasToc) {
return;
}
const firstHeading = element.querySelector<HTMLHeadingElement>('h2,h3[id]');
if (!firstHeading) {
return;
}
// Since the content of the main area is dynamically created and there is
// no host element for a ToC component, we create it manually.
let tocHostElement: HTMLElement | null = element.querySelector(TOC_HOST_ELEMENT_NAME);
if (!tocHostElement) {
tocHostElement = this.document.createElement(TOC_HOST_ELEMENT_NAME);
tocHostElement.setAttribute(TOC_SKIP_CONTENT_MARKER, 'true');
firstHeading?.parentNode?.insertBefore(tocHostElement, firstHeading);
}
this.renderComponent(TableOfContents, tocHostElement, {contentSourceElement: element});
}
private async renderExampleViewerComponents(
placeholder: HTMLElement,
snippets: Snippet[],
path: string,
): Promise<void> {
const preview = Boolean(placeholder.getAttribute('preview'));
const title = placeholder.getAttribute('header') ?? undefined;
const firstCodeSnippetTitle =
snippets.length > 0 ? (snippets[0].title ?? snippets[0].name) : undefined;
const exampleRef = this.viewContainer.createComponent(ExampleViewer);
this.countOfExamples++;
exampleRef.instance.metadata = {
title: title ?? firstCodeSnippetTitle,
path,
files: snippets,
preview,
id: this.countOfExamples,
};
exampleRef.instance.githubUrl = `${GITHUB_CONTENT_URL}/${snippets[0].name}`;
exampleRef.instance.stackblitzUrl = `${ASSETS_EXAMPLES_PATH}/${snippets[0].name}.html`;
placeholder.parentElement!.replaceChild(exampleRef.location.nativeElement, placeholder);
await exampleRef.instance.renderExample();
}
private getCodeSnippetsFromMultifileWrapper(element: HTMLElement): Snippet[] {
const tabs = <Element[]>Array.from(element.querySelectorAll(DOCS_CODE_SELECTOR));
return tabs.map((tab) => ({
name: tab.getAttribute('path') ?? tab.getAttribute('header') ?? '',
content: tab.innerHTML,
visibleLinesRange: tab.getAttribute('visibleLines') ?? undefined,
}));
}
private getStandaloneCodeSnippet(element: HTMLElement): Snippet | null {
const visibleLines = element.getAttribute('visibleLines') ?? undefined;
const preview = element.getAttribute('preview');
if (!visibleLines && !preview) {
return null;
}
const content = element.querySelector('pre')!;
const path = element.getAttribute('path')!;
const title = element.getAttribute('header') ?? undefined;
return {
title,
name: path,
content: content?.outerHTML,
visibleLinesRange: visibleLines,
};
}
// If the content contains static code snippets, we should add buttons to copy
// the code
private loadCopySourceCodeButtons(): void {
const staticCodeSnippets = <Element[]>(
Array.from(this.elementRef.nativeElement.querySelectorAll('.docs-code:not([mermaid])'))
);
for (let codeSnippet of staticCodeSnippets) {
const copySourceCodeButton = this.viewContainer.createComponent(CopySourceCodeButton);
codeSnippet.appendChild(copySourceCodeButton.location.nativeElement);
}
}
private loadBreadcrumb(element: HTMLElement): void {
const breadcrumbPlaceholder = element.querySelector('docs-breadcrumb') as HTMLElement;
const activeNavigationItem = this.navigationState.activeNavigationItem();
if (breadcrumbPlaceholder && !!activeNavigationItem?.parent) {
this.renderComponent(Breadcrumb, breadcrumbPlaceholder);
}
}
private loadIcons(element: HTMLElement): void {
element.querySelectorAll('docs-icon').forEach((iconsPlaceholder) => {
this.renderComponent(IconComponent, iconsPlaceholder as HTMLElement);
});
}
/**
* Helper method to render a component dynamically in a context of this class.
*/
private renderComponent<T>(
type: Type<T>,
hostElement: HTMLElement,
inputs?: {[key: string]: unknown},
): ComponentRef<T> {
const componentRef = createComponent(type, {
hostElement,
elementInjector: this.injector,
environmentInjector: this.environmentInjector,
});
if (inputs) {
for (const [name, value] of Object.entries(inputs)) {
componentRef.setInput(name, value);
}
}
// Trigger change detection after setting inputs.
componentRef.changeDetectorRef.detectChanges();
// Attach a view to the ApplicationRef for change detection
// purposes and for hydration serialization to pick it up
// during SSG.
this.appRef.attachView(componentRef.hostView);
// This is wrapped with `isBrowser` in for hydration purposes.
if (this.isBrowser) {
// The `docs-viewer` may be rendered multiple times when navigating
// between pages, which will create new components that need to be
// destroyed for gradual cleanup.
this.destroyRef.onDestroy(() => componentRef.destroy());
}
return componentRef;
}
| {
"end_byte": 11326,
"start_byte": 2184,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/viewers/docs-viewer/docs-viewer.component.ts"
} |
angular/adev/shared-docs/components/viewers/docs-viewer/docs-viewer.component.ts_11330_12844 | rivate setupAnchorListeners(element: HTMLElement): void {
element.querySelectorAll(`a[href]`).forEach((anchor) => {
// Get the target element's ID from the href attribute
const url = new URL((anchor as HTMLAnchorElement).href);
const isExternalLink = url.origin !== this.document.location.origin;
if (isExternalLink) {
return;
}
fromEvent(anchor, 'click')
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((e) => {
const closestAnchor = (e.target as Element).closest('a');
if (closestAnchor?.target && closestAnchor.target !== 'self') {
return;
}
const hrefAttr = closestAnchor?.getAttribute?.('href');
if (!hrefAttr) {
return;
}
let relativeUrl: string;
if (hrefAttr.startsWith('http')) {
// Url is absolute but we're targeting the same domain
const url = new URL(hrefAttr);
relativeUrl = `${url.pathname}${url.hash}${url.search}`;
} else {
relativeUrl = hrefAttr;
}
handleHrefClickEventWithRouter(e, this.router, relativeUrl);
});
});
}
private rewriteRelativeAnchors(element: HTMLElement) {
for (const anchor of Array.from(element.querySelectorAll(`a[href^="#"]:not(a[download])`))) {
const url = new URL((anchor as HTMLAnchorElement).href);
(anchor as HTMLAnchorElement).href = this.location.path() + url.hash;
}
}
}
| {
"end_byte": 12844,
"start_byte": 11330,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/viewers/docs-viewer/docs-viewer.component.ts"
} |
angular/adev/shared-docs/components/viewers/example-viewer/example-viewer.component.scss_0_2413 | :host {
.docs-example-viewer-preview {
.docs-dark-mode & {
background: var(--gray-100);
}
@media screen and (prefers-color-scheme: dark) {
background: var(--gray-100);
}
.docs-light-mode & {
background: var(--page-background);
}
}
}
.docs-example-viewer {
border: 1px solid var(--senary-contrast);
border-radius: 0.25rem;
overflow: hidden;
}
// Example viewer header
.docs-example-viewer-actions {
background: var(--subtle-purple);
display: flex;
justify-content: space-between;
align-items: center;
gap: 0.5rem;
border-bottom: 1px solid var(--senary-contrast);
transition: background 0.3s ease, border-color 0.3s ease;
padding-inline-end: 0.65rem;
font-family: var(--inter-tight-font);
mat-tab-group {
max-width: calc(100% - 140px);
}
span:first-of-type {
background-image: var(--purple-to-blue-horizontal-gradient);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
padding: 0.7rem 1.1rem;
font-size: 0.875rem;
font-style: normal;
font-weight: 400;
line-height: 1.4rem;
letter-spacing: -0.00875rem;
margin: 0;
word-wrap: break-word;
width: fit-content;
}
.docs-example-viewer-icons {
display: flex;
gap: 0.75rem;
svg {
fill: var(--gray-400);
}
}
a,
button {
padding: 0;
margin: 0;
cursor: pointer;
height: 24px;
width: 24px;
path {
transition: fill 0.3s ease;
}
&:hover {
svg {
fill: var(--tertiary-contrast);
}
}
}
}
// Example viewer code
.docs-example-viewer-code-wrapper {
position: relative;
font-size: 0.875rem;
// TODO: only show this if there is a preview
// border-block-end: 1px solid var(--senary-contrast);
transition: border-color 0.3s ease;
container: viewerblock / inline-size;
background-color: var(--octonary-contrast);
button[docs-copy-source-code] {
top: 0.31rem;
}
}
// stylelint-disable-next-line
::ng-deep {
.docs-example-viewer-preview {
// stylelint-disable-next-line
all: initial;
display: block;
padding: 1rem;
border-block-start: 1px solid var(--senary-contrast);
*,
code::before,
code,
pre,
a,
i,
p,
h1,
h2,
h3,
h4,
h5,
h6,
ol,
ul,
li,
hr,
input,
select,
table {
all: revert;
}
}
}
| {
"end_byte": 2413,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/viewers/example-viewer/example-viewer.component.scss"
} |
angular/adev/shared-docs/components/viewers/example-viewer/example-viewer.component.html_0_3594 | <div class="docs-example-viewer" role="group">
<header class="docs-example-viewer-actions">
@if (view() === CodeExampleViewMode.SNIPPET) {
<span>{{ exampleMetadata()?.title }}</span>
}
@if (view() === CodeExampleViewMode.MULTI_FILE) {
<mat-tab-group
#codeTabs
animationDuration="0ms"
mat-stretch-tabs="false"
>
@for (tab of tabs(); track tab) {
<mat-tab [label]="tab.name"></mat-tab>
}
</mat-tab-group>
}
<div class="docs-example-viewer-icons">
<button
type="button"
class="docs-example-copy-link"
[attr.aria-label]="'Copy link to ' + exampleMetadata()?.title + ' example to the clipboard'"
(click)="copyLink()"
>
<i aria-hidden="true">
<svg
aria-hidden="true"
width="24"
height="24"
viewBox="0 0 24 24"
fill="inherit"
xmlns="http://www.w3.org/2000/svg"
>
<!-- link icon -->
<path
d="M11 17H7C5.61667 17 4.4375 16.5125 3.4625 15.5375C2.4875 14.5625 2 13.3833 2 12C2 10.6167 2.4875 9.4375 3.4625 8.4625C4.4375 7.4875 5.61667 7 7 7H11V9H7C6.16667 9 5.45833 9.29167 4.875 9.875C4.29167 10.4583 4 11.1667 4 12C4 12.8333 4.29167 13.5417 4.875 14.125C5.45833 14.7083 6.16667 15 7 15H11V17ZM8 13V11H16V13H8ZM13 17V15H17C17.8333 15 18.5417 14.7083 19.125 14.125C19.7083 13.5417 20 12.8333 20 12C20 11.1667 19.7083 10.4583 19.125 9.875C18.5417 9.29167 17.8333 9 17 9H13V7H17C18.3833 7 19.5625 7.4875 20.5375 8.4625C21.5125 9.4375 22 10.6167 22 12C22 13.3833 21.5125 14.5625 20.5375 15.5375C19.5625 16.5125 18.3833 17 17 17H13Z"
fill="inherit"
/>
</svg>
</i>
</button>
<ng-container *ngTemplateOutlet="openCodeInExternalProvider" />
@if (expandable()) {
<button
type="button"
(click)="toggleExampleVisibility()"
[attr.title]="(expanded() ? 'Collapse' : 'Expand') + ' example'"
[attr.aria-label]="(expanded() ? 'Collapse' : 'Expand') + ' code example'"
>
<i aria-hidden="true">
@if (!expanded()) {
<svg
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
>
<!-- Expand arrow -->
<path d="M3 21v-8h2v4.6L17.6 5H13V3h8v8h-2V6.4L6.4 19H11v2H3Z" />
</svg>
} @else {
<svg
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
fill="none"
>
<path
fill="var(--gray-400)"
d="M3.4 22 2 20.6 8.6 14H4v-2h8v8h-2v-4.6L3.4 22ZM12 12V4h2v4.6L20.6 2 22 3.4 15.4 10H20v2h-8Z"
/>
</svg>
}
</i>
</button>
}
</div>
</header>
<div
class="docs-example-viewer-code-wrapper"
[class.docs-example-viewer-snippet]="view() === CodeExampleViewMode.SNIPPET"
[class.docs-example-viewer-multi-file]="view() === CodeExampleViewMode.MULTI_FILE"
>
<button docs-copy-source-code></button>
<docs-viewer [docContent]="snippetCode()?.content" />
</div>
@if (exampleComponent) {
<div class="docs-example-viewer-preview">
<ng-container *ngComponentOutlet="exampleComponent" />
</div>
} | {
"end_byte": 3594,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/viewers/example-viewer/example-viewer.component.html"
} |
angular/adev/shared-docs/components/viewers/example-viewer/example-viewer.component.html_3598_6761 | <ng-template #openCodeInExternalProvider>
@if (exampleComponent) {
@if (githubUrl) {
<a
[href]="githubUrl"
target="_blank"
title="Open example on GitHub"
class="docs-example-github-link"
aria-label="Open example on GitHub"
>
<i aria-hidden="true">
<svg
aria-hidden="true"
width="24"
height="24"
viewBox="0 0 24 24"
fill="inherit"
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M9.16141 22.8681C9.16141 22.5894 9.15159 21.8509 9.14614 20.8707C5.96014 21.5798 5.28759 19.296 5.28759 19.296C4.76668 17.9389 4.01559 17.5778 4.01559 17.5778C2.97541 16.8485 4.09414 16.8638 4.09414 16.8638C5.24396 16.9467 5.84886 18.0747 5.84886 18.0747C6.8705 19.8692 8.52923 19.3516 9.18268 19.0505C9.28686 18.2912 9.5825 17.7736 9.90977 17.4801C7.36632 17.184 4.69196 16.176 4.69196 11.6754C4.69196 10.3936 5.13868 9.34523 5.87123 8.52377C5.75396 8.22705 5.36014 7.03305 5.98359 5.41577C5.98359 5.41577 6.94577 5.09996 9.13359 6.61959C10.0467 6.35941 11.0269 6.2285 12.0016 6.22414C12.9741 6.2285 13.9538 6.35941 14.869 6.61959C17.0558 5.09996 18.0163 5.41577 18.0163 5.41577C18.6414 7.0325 18.2481 8.2265 18.1298 8.52377C18.864 9.34523 19.3069 10.3936 19.3069 11.6754C19.3069 16.1874 16.6287 17.1801 14.077 17.4709C14.4889 17.8336 14.8543 18.5503 14.8543 19.6461C14.8543 21.2165 14.8396 22.4836 14.8396 22.8681C14.8396 23.1829 15.0463 23.5478 15.6278 23.4327C20.1758 21.877 23.4545 17.4774 23.4545 12.2907C23.4545 5.80359 18.3256 0.54541 11.9994 0.54541C5.67432 0.54541 0.54541 5.80359 0.54541 12.2907C0.545956 17.479 3.82796 21.8814 8.37977 23.4343C8.95196 23.5418 9.16141 23.179 9.16141 22.8681Z"
fill="inherit"
/>
</svg>
</i>
</a>
}
@if (stackblitzUrl) {
<a
[href]="stackblitzUrl"
target="_blank"
class="docs-example-stackblitz-link"
title="Edit this example in StackBlitz"
aria-label="Edit this example in StackBlitz"
>
<i aria-hidden="true">
<svg
width="24"
height="24"
viewBox="0 0 356 511"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M138.719 150.22C62.6928 232.614 0.340573 300.4 0.158928 300.856C-0.0227172 301.311 33.9559 301.799 75.6665 301.939L151.505 302.195L117.656 396.511C74.7852 515.966 76.7972 510.288 77.3522 510.288C78.2145 510.288 355.296 209.735 355.296 208.799C355.296 208.245 325.263 207.879 279.943 207.879C233.709 207.879 204.591 207.518 204.591 206.943C204.591 206.428 220.136 162.751 239.137 109.883C279.06 -1.20153 278.545 0.264614 277.638 0.347453C277.26 0.382384 214.746 67.8247 138.719 150.22Z"
/>
</svg>
</i>
</a>
}
}
</ng-template>
</div> | {
"end_byte": 6761,
"start_byte": 3598,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/viewers/example-viewer/example-viewer.component.html"
} |
angular/adev/shared-docs/components/viewers/example-viewer/example-viewer.component.ts_0_7716 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {
ChangeDetectionStrategy,
Component,
DestroyRef,
Input,
Type,
computed,
inject,
ChangeDetectorRef,
ViewChild,
signal,
ElementRef,
forwardRef,
} from '@angular/core';
import {CommonModule, DOCUMENT} from '@angular/common';
import {MatTabGroup, MatTabsModule} from '@angular/material/tabs';
import {Clipboard} from '@angular/cdk/clipboard';
import {CopySourceCodeButton} from '../../copy-source-code-button/copy-source-code-button.component';
import {ExampleMetadata, Snippet} from '../../../interfaces/index';
import {EXAMPLE_VIEWER_CONTENT_LOADER} from '../../../providers/index';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {DocViewer} from '../docs-viewer/docs-viewer.component';
export enum CodeExampleViewMode {
SNIPPET = 'snippet',
MULTI_FILE = 'multi',
}
export const CODE_LINE_NUMBER_CLASS_NAME = 'shiki-ln-number';
export const CODE_LINE_CLASS_NAME = 'line';
export const GAP_CODE_LINE_CLASS_NAME = 'gap';
export const HIDDEN_CLASS_NAME = 'hidden';
@Component({
selector: 'docs-example-viewer',
standalone: true,
imports: [CommonModule, forwardRef(() => DocViewer), CopySourceCodeButton, MatTabsModule],
templateUrl: './example-viewer.component.html',
styleUrls: ['./example-viewer.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ExampleViewer {
// TODO: replace by signal-based input when it'll be available
@Input({required: true}) set metadata(value: ExampleMetadata) {
this.exampleMetadata.set(value);
}
@Input() githubUrl: string | null = null;
@Input() stackblitzUrl: string | null = null;
@ViewChild('codeTabs') matTabGroup?: MatTabGroup;
private readonly changeDetector = inject(ChangeDetectorRef);
private readonly clipboard = inject(Clipboard);
private readonly destroyRef = inject(DestroyRef);
private readonly document = inject(DOCUMENT);
private readonly elementRef = inject(ElementRef<HTMLElement>);
private readonly exampleViewerContentLoader = inject(EXAMPLE_VIEWER_CONTENT_LOADER);
private readonly shouldDisplayFullName = computed(() => {
const fileExtensions =
this.exampleMetadata()?.files.map((file) => this.getFileExtension(file.name)) ?? [];
// Display full file names only when exist files with the same extension
return new Set(fileExtensions).size !== fileExtensions.length;
});
CodeExampleViewMode = CodeExampleViewMode;
exampleComponent?: Type<unknown>;
expanded = signal<boolean>(false);
exampleMetadata = signal<ExampleMetadata | null>(null);
snippetCode = signal<Snippet | undefined>(undefined);
tabs = computed(() =>
this.exampleMetadata()?.files.map((file) => ({
name:
file.title ?? (this.shouldDisplayFullName() ? file.name : this.getFileExtension(file.name)),
code: file.content,
})),
);
view = computed(() =>
this.exampleMetadata()?.files.length === 1
? CodeExampleViewMode.SNIPPET
: CodeExampleViewMode.MULTI_FILE,
);
expandable = computed(() =>
this.exampleMetadata()?.files.some((file) => !!file.visibleLinesRange),
);
async renderExample(): Promise<void> {
// Lazy load live example component
if (this.exampleMetadata()?.path && this.exampleMetadata()?.preview) {
this.exampleComponent = await this.exampleViewerContentLoader.loadPreview(
this.exampleMetadata()?.path!,
);
}
this.snippetCode.set(this.exampleMetadata()?.files[0]);
this.changeDetector.detectChanges();
this.setCodeLinesVisibility();
this.elementRef.nativeElement.setAttribute(
'id',
`example-${this.exampleMetadata()?.id.toString()!}`,
);
this.matTabGroup?.realignInkBar();
this.listenToMatTabIndexChange();
}
toggleExampleVisibility(): void {
this.expanded.update((expanded) => !expanded);
this.setCodeLinesVisibility();
}
copyLink(): void {
// Reconstruct the URL using `origin + pathname` so we drop any pre-existing hash.
const fullUrl =
location.origin +
location.pathname +
location.search +
'#example-' +
this.exampleMetadata()?.id;
this.clipboard.copy(fullUrl);
}
private listenToMatTabIndexChange(): void {
this.matTabGroup?.realignInkBar();
this.matTabGroup?.selectedIndexChange
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((index) => {
this.snippetCode.set(this.exampleMetadata()?.files[index]);
this.changeDetector.detectChanges();
this.setCodeLinesVisibility();
});
}
private getFileExtension(name: string): string {
const segments = name.split('.');
return segments.length ? segments[segments.length - 1].toLocaleUpperCase() : '';
}
private setCodeLinesVisibility(): void {
this.expanded()
? this.handleExpandedStateForCodeBlock()
: this.handleCollapsedStateForCodeBlock();
}
private handleExpandedStateForCodeBlock(): void {
const lines = <HTMLDivElement[]>(
Array.from(
this.elementRef.nativeElement.querySelectorAll(
`.${CODE_LINE_CLASS_NAME}.${HIDDEN_CLASS_NAME}`,
),
)
);
const lineNumbers = <HTMLSpanElement[]>(
Array.from(
this.elementRef.nativeElement.querySelectorAll(
`.${CODE_LINE_NUMBER_CLASS_NAME}.${HIDDEN_CLASS_NAME}`,
),
)
);
const gapLines = <HTMLDivElement[]>(
Array.from(
this.elementRef.nativeElement.querySelectorAll(
`.${CODE_LINE_CLASS_NAME}.${GAP_CODE_LINE_CLASS_NAME}`,
),
)
);
for (const line of lines) {
line.classList.remove(HIDDEN_CLASS_NAME);
}
for (const lineNumber of lineNumbers) {
lineNumber.classList.remove(HIDDEN_CLASS_NAME);
}
for (const expandLine of gapLines) {
expandLine.remove();
}
}
private handleCollapsedStateForCodeBlock(): void {
const visibleLinesRange = this.snippetCode()?.visibleLinesRange;
if (!visibleLinesRange) {
return;
}
const linesToDisplay = (visibleLinesRange?.split(',') ?? []).map((line) => Number(line));
const lines = <HTMLDivElement[]>(
Array.from(this.elementRef.nativeElement.querySelectorAll(`.${CODE_LINE_CLASS_NAME}`))
);
const lineNumbers = <HTMLSpanElement[]>(
Array.from(this.elementRef.nativeElement.querySelectorAll(`.${CODE_LINE_NUMBER_CLASS_NAME}`))
);
const appendGapBefore = [];
for (const [index, line] of lines.entries()) {
if (!linesToDisplay.includes(index)) {
line.classList.add(HIDDEN_CLASS_NAME);
} else if (!linesToDisplay.includes(index - 1)) {
appendGapBefore.push(line);
}
}
for (const [index, lineNumber] of lineNumbers.entries()) {
if (!linesToDisplay.includes(index)) {
lineNumber.classList.add(HIDDEN_CLASS_NAME);
}
}
// Create gap line between visible ranges. For example we would like to display 10-16 and 20-29 lines.
// We should display separator, gap between those two scopes.
// TODO: we could replace div it with the component, and allow to expand code block after click.
for (const [index, element] of appendGapBefore.entries()) {
if (index === 0) {
continue;
}
const separator = this.document.createElement('div');
separator.textContent = `...`;
separator.classList.add(CODE_LINE_CLASS_NAME);
separator.classList.add(GAP_CODE_LINE_CLASS_NAME);
element.parentNode?.insertBefore(separator, element);
}
}
}
| {
"end_byte": 7716,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/viewers/example-viewer/example-viewer.component.ts"
} |
angular/adev/shared-docs/components/viewers/example-viewer/example-viewer.component.spec.ts_0_8758 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
import {ExampleViewer} from './example-viewer.component';
import {DocsContentLoader, ExampleMetadata, ExampleViewerContentLoader} from '../../../interfaces';
import {DOCS_CONTENT_LOADER, EXAMPLE_VIEWER_CONTENT_LOADER} from '../../../providers';
import {Component, provideExperimentalZonelessChangeDetection} from '@angular/core';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {HarnessLoader} from '@angular/cdk/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {Clipboard} from '@angular/cdk/clipboard';
import {By} from '@angular/platform-browser';
import {MatTabGroupHarness} from '@angular/material/tabs/testing';
import {CopySourceCodeButton} from '../../copy-source-code-button/copy-source-code-button.component';
import {ActivatedRoute} from '@angular/router';
describe('ExampleViewer', () => {
let component: ExampleViewer;
let fixture: ComponentFixture<ExampleViewer>;
let loader: HarnessLoader;
let exampleContentSpy: jasmine.SpyObj<ExampleViewerContentLoader>;
let contentServiceSpy: jasmine.SpyObj<DocsContentLoader>;
beforeEach(() => {
exampleContentSpy = jasmine.createSpyObj('ExampleContentLoader', ['loadPreview']);
contentServiceSpy = jasmine.createSpyObj('ContentLoader', ['getContent']);
contentServiceSpy.getContent.and.returnValue(Promise.resolve(undefined));
});
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ExampleViewer, NoopAnimationsModule],
providers: [
provideExperimentalZonelessChangeDetection(),
{provide: EXAMPLE_VIEWER_CONTENT_LOADER, useValue: exampleContentSpy},
{provide: DOCS_CONTENT_LOADER, useValue: contentServiceSpy},
{provide: ActivatedRoute, useValue: {snapshot: {fragment: 'fragment'}}},
],
}).compileComponents();
fixture = TestBed.createComponent(ExampleViewer);
component = fixture.componentInstance;
loader = TestbedHarnessEnvironment.loader(fixture);
fixture.detectChanges();
});
it('should set file extensions as tab names when all files have different extension', waitForAsync(async () => {
component.metadata = getMetadata({
files: [
{name: 'file.ts', content: ''},
{name: 'file.html', content: ''},
{name: 'file.css', content: ''},
],
});
await component.renderExample();
expect(component.tabs()!.length).toBe(3);
expect(component.tabs()![0].name).toBe('TS');
expect(component.tabs()![1].name).toBe('HTML');
expect(component.tabs()![2].name).toBe('CSS');
}));
it('should generate correct code content for multi file mode when it is expanded', waitForAsync(async () => {
component.metadata = getMetadata({
files: [
{name: 'file.ts', content: 'typescript file'},
{name: 'file.html', content: 'html file'},
{name: 'file.css', content: 'css file'},
],
});
await component.renderExample();
expect(component.tabs()!.length).toBe(3);
expect(component.tabs()![0].code).toBe('typescript file');
expect(component.tabs()![1].code).toBe('html file');
expect(component.tabs()![2].code).toBe('css file');
}));
it('should set file names as tab names when there is at least one duplication', async () => {
component.metadata = getMetadata({
files: [
{name: 'example.ts', content: 'typescript file'},
{name: 'example.html', content: 'html file'},
{name: 'another-example.ts', content: 'css file'},
],
});
await component.renderExample();
expect(component.tabs()!.length).toBe(3);
expect(component.tabs()![0].name).toBe('example.ts');
expect(component.tabs()![1].name).toBe('example.html');
expect(component.tabs()![2].name).toBe('another-example.ts');
});
it('should expandable be false when none of the example files have defined visibleLinesRange ', waitForAsync(async () => {
component.metadata = getMetadata();
await component.renderExample();
expect(component.expandable()).toBeFalse();
}));
it('should expandable be true when at least one example file has defined visibleLinesRange ', waitForAsync(async () => {
component.metadata = getMetadata({
files: [
{name: 'example.ts', content: 'typescript file'},
{
name: 'example.html',
content: 'html file',
visibleLinesRange: '[1, 2]',
},
{name: 'another-example.ts', content: 'css file'},
],
});
await component.renderExample();
expect(component.expandable()).toBeTrue();
}));
it('should set exampleComponent when metadata contains path and preview is true', waitForAsync(async () => {
exampleContentSpy.loadPreview.and.resolveTo(ExampleComponent);
component.metadata = getMetadata({
path: 'example.ts',
preview: true,
});
await component.renderExample();
expect(component.exampleComponent).toBe(ExampleComponent);
}));
it('should display GitHub button when githubUrl is provided and there is preview', waitForAsync(async () => {
exampleContentSpy.loadPreview.and.resolveTo(ExampleComponent);
component.metadata = getMetadata({
path: 'example.ts',
preview: true,
});
component.githubUrl = 'https://github.com/';
await component.renderExample();
const githubButton = fixture.debugElement.query(
By.css('a[aria-label="Open example on GitHub"]'),
);
expect(githubButton).toBeTruthy();
expect(githubButton.nativeElement.href).toBe(component.githubUrl);
}));
it('should display StackBlitz button when stackblitzUrl is provided and there is preview', waitForAsync(async () => {
exampleContentSpy.loadPreview.and.resolveTo(ExampleComponent);
component.metadata = getMetadata({
path: 'example.ts',
preview: true,
});
component.stackblitzUrl = 'https://stackblitz.com/';
await component.renderExample();
const stackblitzButton = fixture.debugElement.query(
By.css('a[aria-label="Edit this example in StackBlitz"]'),
);
expect(stackblitzButton).toBeTruthy();
expect(stackblitzButton.nativeElement.href).toBe(component.stackblitzUrl);
}));
it('should set expanded flag in metadata after toggleExampleVisibility', waitForAsync(async () => {
component.metadata = getMetadata();
await component.renderExample();
component.toggleExampleVisibility();
expect(component.expanded()).toBeTrue();
const tabGroup = await loader.getHarness(MatTabGroupHarness);
const tab = await tabGroup.getSelectedTab();
expect(await tab.getLabel()).toBe('TS');
component.toggleExampleVisibility();
expect(component.expanded()).toBeFalse();
}));
// TODO(josephperrott): enable once the docs-viewer/example-viewer circle is sorted out.
xit('should call clipboard service when clicked on copy source code', waitForAsync(async () => {
const expectedCodeSnippetContent = 'typescript code';
component.metadata = getMetadata({
files: [
{
name: 'example.ts',
content: `<pre><code>${expectedCodeSnippetContent}</code></pre>`,
},
{name: 'example.css', content: ''},
],
});
const clipboardService = TestBed.inject(Clipboard);
const spy = spyOn(clipboardService, 'copy');
await component.renderExample();
const button = fixture.debugElement.query(By.directive(CopySourceCodeButton)).nativeElement;
button.click();
expect(spy.calls.argsFor(0)[0]?.trim()).toBe(expectedCodeSnippetContent);
}));
it('should call clipboard service when clicked on copy example link', waitForAsync(async () => {
component.metadata = getMetadata();
component.expanded.set(true);
fixture.detectChanges();
const clipboardService = TestBed.inject(Clipboard);
const spy = spyOn(clipboardService, 'copy');
await component.renderExample();
const button = fixture.debugElement.query(
By.css('button.docs-example-copy-link'),
).nativeElement;
button.click();
expect(spy.calls.argsFor(0)[0].trim()).toBe(`${window.origin}/context.html#example-1`);
}));
});
const getMetadata = (value: Partial<ExampleMetadata> = {}): ExampleMetadata => {
return {
id: 1,
files: [
{name: 'example.ts', content: ''},
{name: 'example.css', content: ''},
],
preview: false,
...value,
};
};
@Component({
template: '',
standalone: true,
})
class ExampleComponent {}
| {
"end_byte": 8758,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/viewers/example-viewer/example-viewer.component.spec.ts"
} |
angular/adev/shared-docs/components/top-level-banner/top-level-banner.component.spec.ts_0_3501 | import {ComponentFixture, TestBed} from '@angular/core/testing';
import {STORAGE_KEY_PREFIX, TopLevelBannerComponent} from './top-level-banner.component';
import {LOCAL_STORAGE, WINDOW} from '../../providers';
describe('TopLevelBannerComponent', () => {
let component: TopLevelBannerComponent;
let fixture: ComponentFixture<TopLevelBannerComponent>;
let mockLocalStorage: jasmine.SpyObj<Storage>;
const EXAMPLE_TEXT = 'Click Here';
const EXAMPLE_LINK = 'https://example.com';
const EXAMPLE_ID = 'banner-id';
beforeEach(async () => {
mockLocalStorage = jasmine.createSpyObj('Storage', ['getItem', 'setItem']);
fixture = TestBed.configureTestingModule({
providers: [
{provide: LOCAL_STORAGE, useValue: mockLocalStorage},
{provide: WINDOW, useValue: {location: {origin: ''}}},
],
}).createComponent(TopLevelBannerComponent);
fixture.componentRef.setInput('text', EXAMPLE_TEXT);
fixture.componentRef.setInput('id', EXAMPLE_ID);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should render an anchor element when link is provided', () => {
fixture.componentRef.setInput('text', EXAMPLE_TEXT);
fixture.componentRef.setInput('link', EXAMPLE_LINK);
fixture.detectChanges();
const bannerElement = fixture.nativeElement.querySelector('a.docs-top-level-banner');
expect(bannerElement).toBeTruthy();
expect(bannerElement.getAttribute('href')).toBe(EXAMPLE_LINK);
expect(bannerElement.textContent).toContain(EXAMPLE_TEXT);
});
it('should render a div element when link is not provided', () => {
const EXAMPLE_TEXT = 'No Link Available';
fixture.componentRef.setInput('text', EXAMPLE_TEXT);
fixture.detectChanges();
const bannerElement = fixture.nativeElement.querySelector('div.docs-top-level-banner');
expect(bannerElement).toBeTruthy();
expect(bannerElement.textContent).toContain(EXAMPLE_TEXT);
});
it('should correctly render the text input', () => {
const EXAMPLE_TEXT = 'Lorem ipsum dolor...';
fixture.componentRef.setInput('text', EXAMPLE_TEXT);
fixture.detectChanges();
const bannerElement = fixture.nativeElement.querySelector('.docs-top-level-banner-cta');
expect(bannerElement).toBeTruthy();
expect(bannerElement.textContent).toBe(EXAMPLE_TEXT);
});
it('should set hasClosed to true if the banner was closed before', () => {
mockLocalStorage.getItem.and.returnValue('true');
component.ngOnInit();
expect(component.hasClosed()).toBeTrue();
expect(mockLocalStorage.getItem).toHaveBeenCalledWith(`${STORAGE_KEY_PREFIX}${EXAMPLE_ID}`);
});
it('should set hasClosed to false if the banner was not closed before', () => {
mockLocalStorage.getItem.and.returnValue('false');
component.ngOnInit();
expect(component.hasClosed()).toBeFalse();
expect(mockLocalStorage.getItem).toHaveBeenCalledWith(`${STORAGE_KEY_PREFIX}${EXAMPLE_ID}`);
});
it('should set hasClosed to false if accessing localStorage throws an error', () => {
mockLocalStorage.getItem.and.throwError('Local storage error');
component.ngOnInit();
expect(component.hasClosed()).toBeFalse();
});
it('should set the banner as closed in localStorage and update hasClosed', () => {
component.close();
expect(mockLocalStorage.setItem).toHaveBeenCalledWith(
`${STORAGE_KEY_PREFIX}${EXAMPLE_ID}`,
'true',
);
expect(component.hasClosed()).toBeTrue();
});
});
| {
"end_byte": 3501,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/top-level-banner/top-level-banner.component.spec.ts"
} |
angular/adev/shared-docs/components/top-level-banner/top-level-banner.component.ts_0_2421 | import {ChangeDetectionStrategy, Component, inject, input, OnInit, signal} from '@angular/core';
import {ExternalLink} from '../../directives';
import {LOCAL_STORAGE} from '../../providers';
import {IconComponent} from '../icon/icon.component';
export const STORAGE_KEY_PREFIX = 'docs-was-closed-top-banner-';
@Component({
selector: 'docs-top-level-banner',
standalone: true,
imports: [ExternalLink, IconComponent],
templateUrl: './top-level-banner.component.html',
styleUrl: './top-level-banner.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TopLevelBannerComponent implements OnInit {
private readonly localStorage = inject(LOCAL_STORAGE);
/**
* Unique identifier for the banner. This ID is required to ensure that
* the state of the banner (e.g., whether it has been closed) is tracked
* separately for different events or instances. Without a unique ID,
* closing one banner could inadvertently hide other banners for different events.
*/
id = input.required<string>();
// Optional URL link that the banner should navigate to when clicked.
link = input<string>();
// Text content to be displayed in the banner.
text = input.required<string>();
// Optional expiry date. Setting the default expiry as a future date so we
// don't have to deal with undefined signal values.
expiry = input(new Date('3000-01-01'), {transform: parseDate});
// Whether the user has closed the banner or the survey has expired.
hasClosed = signal<boolean>(false);
ngOnInit(): void {
const expired = Date.now() > this.expiry().getTime();
// Needs to be in a try/catch, because some browsers will
// throw when using `localStorage` in private mode.
try {
this.hasClosed.set(
this.localStorage?.getItem(this.getBannerStorageKey()) === 'true' || expired,
);
} catch {
this.hasClosed.set(false);
}
}
close(): void {
this.localStorage?.setItem(this.getBannerStorageKey(), 'true');
this.hasClosed.set(true);
}
private getBannerStorageKey(): string {
return `${STORAGE_KEY_PREFIX}${this.id()}`;
}
}
const parseDate = (inputDate: string | Date): Date => {
if (inputDate instanceof Date) {
return inputDate;
}
const outputDate = new Date(inputDate);
if (isNaN(outputDate.getTime())) {
throw new Error(`Invalid date string: ${inputDate}`);
}
return outputDate;
};
| {
"end_byte": 2421,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/top-level-banner/top-level-banner.component.ts"
} |
angular/adev/shared-docs/components/top-level-banner/top-level-banner.component.html_0_667 | @if (!hasClosed()) {
@if (link()) {
<a [href]="link()" class="docs-top-level-banner">
<h1 tabindex="-1" class="docs-top-level-banner-cta background">{{ text() }}</h1>
<h1 tabindex="0" class="docs-top-level-banner-cta shimmer">{{ text() }}</h1>
</a>
} @else {
<div class="docs-top-level-banner">
<h1 tabindex="-1" class="docs-top-level-banner-cta background">{{ text() }}</h1>
<h1 tabindex="0" class="docs-top-level-banner-cta shimmer">{{ text() }}</h1>
</div>
}
<button class="docs-top-level-banner-close" type="button" (click)="close()">
<docs-icon class="docs-icon_high-contrast">close</docs-icon>
</button>
}
| {
"end_byte": 667,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/top-level-banner/top-level-banner.component.html"
} |
angular/adev/shared-docs/components/top-level-banner/top-level-banner.component.scss_0_2883 | :host {
&:not(:empty) {
z-index: 50;
position: fixed;
height: 2rem;
width: 100vw;
border-bottom: 1px solid var(--septenary-contrast);
text-align: center;
align-content: center;
backdrop-filter: blur(16px);
background-color: color-mix(in srgb, var(--page-background) 70%, transparent);
}
a.docs-top-level-banner {
width: 100%;
display: inherit;
}
h1.docs-top-level-banner-cta {
display: inline;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 0.875rem;
margin: 0;
width: fit-content;
font-weight: 500;
&.background {
color: var(--tertiary-contrast);
}
&:not(.background) {
color: transparent;
&::after {
content: '';
position: absolute;
width: 100%;
height: 1px;
bottom: -2px;
left: 0;
background: var(--tertiary-contrast);
transform: scaleX(0);
transform-origin: bottom right;
@media (prefers-reduced-motion: no-preference) {
transition: transform 0.3s ease;
}
}
&:hover {
&::after {
transform: scaleX(1);
transform-origin: bottom left;
}
}
}
}
.docs-top-level-banner-close {
position: absolute;
top: 0.25rem;
right: 0.5rem;
color: var(--tertiary-contrast);
}
}
.shimmer {
background: var(--red-to-pink-to-purple-horizontal-gradient);
@media (prefers-reduced-motion: no-preference) {
background-repeat: no-repeat;
-webkit-background-size: 125px 100%;
-moz-background-size: 125px 100%;
background-size: 125px 100%;
-webkit-background-clip: text;
-moz-background-clip: text;
background-clip: text;
-webkit-animation-name: shimmer;
-moz-animation-name: shimmer;
animation-name: shimmer;
-webkit-animation-duration: 10s;
-moz-animation-duration: 10s;
animation-duration: 10s;
-webkit-animation-iteration-count: infinite;
-moz-animation-iteration-count: infinite;
animation-iteration-count: infinite;
}
}
@-moz-keyframes shimmer {
0% {
background-position: top left;
background-position-x: -150px;
}
100% {
background-position: top right;
background-position-x: 500px;
}
}
@-webkit-keyframes shimmer {
0% {
background-position: top left;
background-position-x: -150px;
}
100% {
background-position: top right;
background-position-x: 500px;
}
}
@-o-keyframes shimmer {
0% {
background-position: top left;
background-position-x: -150px;
}
100% {
background-position: top right;
background-position-x: 500px;
}
}
@keyframes shimmer {
0% {
background-position: top left;
background-position-x: -150px;
}
100% {
background-position: top right;
background-position-x: 500px;
}
}
| {
"end_byte": 2883,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/shared-docs/components/top-level-banner/top-level-banner.component.scss"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.