Skip to content

Commit

Permalink
add support for devtools's fancy print & save handling
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish authored Dec 21, 2021
1 parent 6be05d7 commit c8435cc
Showing 1 changed file with 50 additions and 44 deletions.
94 changes: 50 additions & 44 deletions report/types/report-renderer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,53 @@
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

import { Result as AuditResult } from "../../types/lhr/audit-result";

declare module Renderer {
function renderReport(lhr: AuditResult, options?: Options): HTMLElement;

interface Options {
/**
* Don't automatically apply dark-mode to dark based on (prefers-color-scheme: dark). (DevTools and PSI don't want this.)
* Also, the fireworks easter-egg will want to flip to dark, so this setting will also disable chance of fireworks. */
disableAutoDarkModeAndFireworks?: boolean;

/** Disable the topbar UI component */
omitTopbar?: boolean;
/** Prevent injection of report styles. Set to true if these styles are already included by the environment. */
omitGlobalStyles?: boolean;
/**
* Convert report anchor links to a different format.
* Flow report uses this to convert `#seo` to `#index=0&anchor=seo`.
*/
onPageAnchorRendered?: (link: HTMLAnchorElement) => void;

/** If defined, the 'Save as Gist' item in the topbar dropdown will be shown and when clicked, will run this function. */
onSaveGist?: (lhr: LH.Result) => string;

/** If defined, when the 'Save/Copy as HTML' items are clicked, this fn will be used instead of `documentElement.outerHTML`. */
getStandaloneReportHTML?: () => string;

/**
* DOM element that will the overlay DOM should be a child of.
* Between stacking contexts and z-index, the overlayParentEl should have a stacking/paint order high enough to cover all elements that the overlay should paint above.
* Defaults to the containerEl, but will be set in PSI to avoid being under the sticky header.
* @see https://philipwalton.com/articles/what-no-one-told-you-about-z-index/ */
overlayParentEl?: HTMLElement;

/** Callback running after a DOM element (like .lh-node or .lh-source-location) has been created */
onDetailsItemRendered?: (
type: LH.Audit.Details['type'],
el: HTMLElement,
value: LH.Audit.Details
) => void;
}
}

export default Renderer;
import { Result as AuditResult } from "../../types/lhr/audit-result";

declare module Renderer {
function renderReport(lhr: AuditResult, options?: Options): HTMLElement;

interface Options {
/**
* Don't automatically apply dark-mode to dark based on (prefers-color-scheme: dark). (DevTools and PSI don't want this.)
* Also, the fireworks easter-egg will want to flip to dark, so this setting will also disable chance of fireworks. */
disableAutoDarkModeAndFireworks?: boolean;

/** Disable the topbar UI component */
omitTopbar?: boolean;
/** Prevent injection of report styles. Set to true if these styles are already included by the environment. */
omitGlobalStyles?: boolean;
/**
* Convert report anchor links to a different format.
* Flow report uses this to convert `#seo` to `#index=0&anchor=seo`.
*/
onPageAnchorRendered?: (link: HTMLAnchorElement) => void;

/** If defined, the 'Save as Gist' item in the topbar dropdown will be shown and when clicked, will run this function. */
onSaveGist?: (lhr: LH.Result) => string;

/** If defined, when the 'Save/Copy as HTML' items are clicked, this fn will be used instead of `documentElement.outerHTML`. */
getStandaloneReportHTML?: () => string;

/** If defined, renderer will call this when printing is invoked instead of window.print() */
onPrintOverride?: (rootEl: HTMLElement) => Promise<void>;

/** If defined, renderer will call this rather than using a `<a download>.click()>` to trigger a JSON/HTML download. Blob will be either json or html. */
onSaveFileOverride?: (blob: Blob, lhr: LH.Result) => Promise<void>;

/**
* DOM element that will the overlay DOM should be a child of.
* Between stacking contexts and z-index, the overlayParentEl should have a stacking/paint order high enough to cover all elements that the overlay should paint above.
* Defaults to the containerEl, but will be set in PSI to avoid being under the sticky header.
* @see https://philipwalton.com/articles/what-no-one-told-you-about-z-index/ */
overlayParentEl?: HTMLElement;

/** Callback running after a DOM element (like .lh-node or .lh-source-location) has been created */
onDetailsItemRendered?: (
type: LH.Audit.Details['type'],
el: HTMLElement,
value: LH.Audit.Details
) => void;
}
}

export default Renderer;

0 comments on commit c8435cc

Please sign in to comment.