UNPKG

3.77 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';
13/**
14 * Interface to apply PrintHook to call anonymous `target.updateStyles()`
15 */
16export interface HookTarget {
17 activatedBreakpoints: BreakPoint[];
18 updateStyles(): void;
19}
20export declare const BREAKPOINT_PRINT: {
21 alias: string;
22 mediaQuery: string;
23 priority: number;
24};
25/**
26 * PrintHook - Use to intercept print MediaQuery activations and force
27 * layouts to render with the specified print alias/breakpoint
28 *
29 * Used in MediaMarshaller and MediaObserver
30 */
31export declare class PrintHook implements OnDestroy {
32 protected breakpoints: BreakPointRegistry;
33 protected layoutConfig: LayoutConfigOptions;
34 protected _document: any;
35 constructor(breakpoints: BreakPointRegistry, layoutConfig: LayoutConfigOptions, _document: any);
36 /** Add 'print' mediaQuery: to listen for matchMedia activations */
37 withPrintQuery(queries: string[]): string[];
38 /** Is the MediaChange event for any 'print' @media */
39 isPrintEvent(e: MediaChange): Boolean;
40 /** What is the desired mqAlias to use while printing? */
41 get printAlias(): string[];
42 /** Lookup breakpoints associated with print aliases. */
43 get printBreakPoints(): BreakPoint[];
44 /** Lookup breakpoint associated with mediaQuery */
45 getEventBreakpoints({ mediaQuery }: MediaChange): BreakPoint[];
46 /** Update event with printAlias mediaQuery information */
47 updateEvent(event: MediaChange): MediaChange;
48 private registeredBeforeAfterPrintHooks;
49 private isPrintingBeforeAfterEvent;
50 private beforePrintEventListeners;
51 private afterPrintEventListeners;
52 private registerBeforeAfterPrintHooks;
53 /**
54 * Prepare RxJS filter operator with partial application
55 * @return pipeable filter predicate
56 */
57 interceptEvents(target: HookTarget): (event: MediaChange) => void;
58 /** Stop mediaChange event propagation in event streams */
59 blockPropagation(): (event: MediaChange) => boolean;
60 /**
61 * Save current activateBreakpoints (for later restore)
62 * and substitute only the printAlias breakpoint
63 */
64 protected startPrinting(target: HookTarget, bpList: OptionalBreakPoint[]): void;
65 /** For any print de-activations, reset the entire print queue */
66 protected stopPrinting(target: HookTarget): void;
67 /**
68 * To restore pre-Print Activations, we must capture the proper
69 * list of breakpoint activations BEFORE print starts. OnBeforePrint()
70 * is supported; so 'print' mediaQuery activations are used as a fallback
71 * in browsers without `beforeprint` support.
72 *
73 * > But activated breakpoints are deactivated BEFORE 'print' activation.
74 *
75 * Let's capture all de-activations using the following logic:
76 *
77 * When not printing:
78 * - clear cache when activating non-print breakpoint
79 * - update cache (and sort) when deactivating
80 *
81 * When printing:
82 * - sort and save when starting print
83 * - restore as activatedTargets and clear when stop printing
84 */
85 collectActivations(event: MediaChange): void;
86 /** Teardown logic for the service. */
87 ngOnDestroy(): void;
88 /** Is this service currently in Print-mode ? */
89 private isPrinting;
90 private queue;
91 private deactivations;
92}