index.d.cts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. declare class Beasties {
  17. /**
  18. * Create an instance of Beasties with custom options.
  19. * The `.process()` method can be called repeatedly to re-use this instance and its cache.
  20. */
  21. constructor(options?: Options)
  22. /**
  23. * Process an HTML document to inline critical CSS from its stylesheets.
  24. * @param html String containing a full HTML document to be parsed.
  25. * @returns A modified copy of the provided HTML with critical CSS inlined.
  26. */
  27. process(html: string): Promise<string>
  28. /**
  29. * Read the contents of a file from the specified filesystem or disk.
  30. * Override this method to customize how stylesheets are loaded.
  31. */
  32. readFile(filename: string): Promise<string> | string
  33. /**
  34. * Given a stylesheet URL, returns the corresponding CSS asset.
  35. * Overriding this method requires doing your own URL normalization, so it's generally better to override `readFile()`.
  36. */
  37. getCssAsset(href: string): Promise<string | undefined> | string | undefined
  38. }
  39. interface Options {
  40. path?: string
  41. publicPath?: string
  42. external?: boolean
  43. inlineThreshold?: number
  44. minimumExternalSize?: number
  45. pruneSource?: boolean
  46. mergeStylesheets?: boolean
  47. additionalStylesheets?: string[]
  48. preload?: 'body' | 'media' | 'swap' | 'swap-high' | 'js' | 'js-lazy'
  49. noscriptFallback?: boolean
  50. inlineFonts?: boolean
  51. preloadFonts?: boolean
  52. fonts?: boolean
  53. keyframes?: string
  54. compress?: boolean
  55. logLevel?: 'info' | 'warn' | 'error' | 'trace' | 'debug' | 'silent'
  56. reduceInlineStyles?: boolean
  57. logger?: Logger
  58. }
  59. interface Logger {
  60. trace?: (message: string) => void
  61. debug?: (message: string) => void
  62. info?: (message: string) => void
  63. warn?: (message: string) => void
  64. error?: (message: string) => void
  65. }
  66. export { type Logger, type Options, Beasties as default };