UNPKG

3.94 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { OnDestroy } from '@angular/core';
9import { MediaChange } from '../media-change';
10import { BreakPoint } from '../breakpoints/break-point';
11import { LayoutConfigOptions } from '../tokens/library-config';
12import { BreakPointRegistry, OptionalBreakPoint } from '../breakpoints/break-point-registry';
13import * as i0 from "@angular/core";
14/**
15 * Interface to apply PrintHook to call anonymous `target.updateStyles()`
16 */
17export interface HookTarget {
18 activatedBreakpoints: BreakPoint[];
19 updateStyles(): void;
20}
21export declare const BREAKPOINT_PRINT: {
22 alias: string;
23 mediaQuery: string;
24 priority: number;
25};
26/**
27 * PrintHook - Use to intercept print MediaQuery activations and force
28 * layouts to render with the specified print alias/breakpoint
29 *
30 * Used in MediaMarshaller and MediaObserver
31 */
32export declare class PrintHook implements OnDestroy {
33 protected breakpoints: BreakPointRegistry;
34 protected layoutConfig: LayoutConfigOptions;
35 protected _document: any;
36 constructor(breakpoints: BreakPointRegistry, layoutConfig: LayoutConfigOptions, _document: any);
37 /** Add 'print' mediaQuery: to listen for matchMedia activations */
38 withPrintQuery(queries: string[]): string[];
39 /** Is the MediaChange event for any 'print' @media */
40 isPrintEvent(e: MediaChange): boolean;
41 /** What is the desired mqAlias to use while printing? */
42 get printAlias(): string[];
43 /** Lookup breakpoints associated with print aliases. */
44 get printBreakPoints(): BreakPoint[];
45 /** Lookup breakpoint associated with mediaQuery */
46 getEventBreakpoints({ mediaQuery }: MediaChange): BreakPoint[];
47 /** Update event with printAlias mediaQuery information */
48 updateEvent(event: MediaChange): MediaChange;
49 private registeredBeforeAfterPrintHooks;
50 private isPrintingBeforeAfterEvent;
51 private beforePrintEventListeners;
52 private afterPrintEventListeners;
53 private formerActivations;
54 registerBeforeAfterPrintHooks(target: HookTarget): void;
55 /**
56 * Prepare RxJS tap operator with partial application
57 * @return pipeable tap predicate
58 */
59 interceptEvents(target: HookTarget): (event: MediaChange) => void;
60 /** Stop mediaChange event propagation in event streams */
61 blockPropagation(): (event: MediaChange) => boolean;
62 /**
63 * Save current activateBreakpoints (for later restore)
64 * and substitute only the printAlias breakpoint
65 */
66 protected startPrinting(target: HookTarget, bpList: OptionalBreakPoint[]): void;
67 /** For any print de-activations, reset the entire print queue */
68 protected stopPrinting(target: HookTarget): void;
69 /**
70 * To restore pre-Print Activations, we must capture the proper
71 * list of breakpoint activations BEFORE print starts. OnBeforePrint()
72 * is supported; so 'print' mediaQuery activations are used as a fallback
73 * in browsers without `beforeprint` support.
74 *
75 * > But activated breakpoints are deactivated BEFORE 'print' activation.
76 *
77 * Let's capture all de-activations using the following logic:
78 *
79 * When not printing:
80 * - clear cache when activating non-print breakpoint
81 * - update cache (and sort) when deactivating
82 *
83 * When printing:
84 * - sort and save when starting print
85 * - restore as activatedTargets and clear when stop printing
86 */
87 collectActivations(target: HookTarget, event: MediaChange): void;
88 /** Teardown logic for the service. */
89 ngOnDestroy(): void;
90 private isPrinting;
91 private queue;
92 private deactivations;
93 static ɵfac: i0.ɵɵFactoryDeclaration<PrintHook, never>;
94 static ɵprov: i0.ɵɵInjectableDeclaration<PrintHook>;
95}