[6a3a178] | 1 | /**
|
---|
| 2 | * Copyright 2018 Google LLC
|
---|
| 3 | *
|
---|
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
---|
| 5 | * use this file except in compliance with the License. You may obtain a copy of
|
---|
| 6 | * the License at
|
---|
| 7 | *
|
---|
| 8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 9 | *
|
---|
| 10 | * Unless required by applicable law or agreed to in writing, software
|
---|
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
---|
| 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
---|
| 13 | * License for the specific language governing permissions and limitations under
|
---|
| 14 | * the License.
|
---|
| 15 | */
|
---|
| 16 |
|
---|
[e29cc2e] | 17 | export default class Critters {
|
---|
| 18 | /**
|
---|
| 19 | * Create an instance of Critters with custom options.
|
---|
| 20 | * The `.process()` method can be called repeatedly to re-use this instance and its cache.
|
---|
| 21 | */
|
---|
| 22 | constructor(options: Options);
|
---|
| 23 | /**
|
---|
| 24 | * Process an HTML document to inline critical CSS from its stylesheets.
|
---|
| 25 | * @param {string} html String containing a full HTML document to be parsed.
|
---|
| 26 | * @returns {string} A modified copy of the provided HTML with critical CSS inlined.
|
---|
| 27 | */
|
---|
| 28 | process(html: string): Promise<string>;
|
---|
| 29 | /**
|
---|
| 30 | * Read the contents of a file from the specified filesystem or disk.
|
---|
| 31 | * Override this method to customize how stylesheets are loaded.
|
---|
| 32 | */
|
---|
| 33 | readFile(filename: string): Promise<string> | string;
|
---|
| 34 | /**
|
---|
| 35 | * Given a stylesheet URL, returns the corresponding CSS asset.
|
---|
| 36 | * Overriding this method requires doing your own URL normalization, so it's generally better to override `readFile()`.
|
---|
| 37 | */
|
---|
| 38 | getCssAsset(href: string): Promise<string | undefined> | string | undefined;
|
---|
| 39 | }
|
---|
[6a3a178] | 40 |
|
---|
[e29cc2e] | 41 | export interface Options {
|
---|
| 42 | path?: string;
|
---|
| 43 | publicPath?: string;
|
---|
| 44 | external?: boolean;
|
---|
| 45 | inlineThreshold?: number;
|
---|
| 46 | minimumExternalSize?: number;
|
---|
| 47 | pruneSource?: boolean;
|
---|
| 48 | mergeStylesheets?: boolean;
|
---|
| 49 | additionalStylesheets?: string[];
|
---|
| 50 | preload?: 'body' | 'media' | 'swap' | 'js' | 'js-lazy';
|
---|
| 51 | noscriptFallback?: boolean;
|
---|
| 52 | inlineFonts?: boolean;
|
---|
| 53 | preloadFonts?: boolean;
|
---|
| 54 | fonts?: boolean;
|
---|
| 55 | keyframes?: string;
|
---|
| 56 | compress?: boolean;
|
---|
| 57 | logLevel?: 'info' | 'warn' | 'error' | 'trace' | 'debug' | 'silent';
|
---|
| 58 | reduceInlineStyles?: boolean;
|
---|
| 59 | logger?: Logger;
|
---|
| 60 | }
|
---|
[6a3a178] | 61 |
|
---|
[e29cc2e] | 62 | export interface Logger {
|
---|
| 63 | trace?: (message: string) => void;
|
---|
| 64 | debug?: (message: string) => void;
|
---|
| 65 | info?: (message: string) => void;
|
---|
| 66 | warn?: (message: string) => void;
|
---|
| 67 | error?: (message: string) => void;
|
---|
[6a3a178] | 68 | }
|
---|