report: add options disableFireworks and disableDarkMode (#13649)
This commit is contained in:
Родитель
9331636ae6
Коммит
fa7b543e01
|
@ -33,7 +33,8 @@ export const Report: FunctionComponent<{hashState: LH.FlowResult.HashState}> =
|
||||||
({hashState}) => {
|
({hashState}) => {
|
||||||
const ref = useExternalRenderer<HTMLDivElement>(() => {
|
const ref = useExternalRenderer<HTMLDivElement>(() => {
|
||||||
return renderReport(hashState.currentLhr, {
|
return renderReport(hashState.currentLhr, {
|
||||||
disableAutoDarkModeAndFireworks: true,
|
disableFireworks: true,
|
||||||
|
disableDarkMode: true,
|
||||||
omitTopbar: true,
|
omitTopbar: true,
|
||||||
omitGlobalStyles: true,
|
omitGlobalStyles: true,
|
||||||
onPageAnchorRendered: link => convertAnchor(link, hashState.index),
|
onPageAnchorRendered: link => convertAnchor(link, hashState.index),
|
||||||
|
|
|
@ -70,12 +70,13 @@ export class ReportUIFeatures {
|
||||||
this._setupThirdPartyFilter();
|
this._setupThirdPartyFilter();
|
||||||
this._setupElementScreenshotOverlay(this._dom.rootEl);
|
this._setupElementScreenshotOverlay(this._dom.rootEl);
|
||||||
|
|
||||||
let turnOffTheLights = false;
|
|
||||||
// Do not query the system preferences for DevTools - DevTools should only apply dark theme
|
// Do not query the system preferences for DevTools - DevTools should only apply dark theme
|
||||||
// if dark is selected in the settings panel.
|
// if dark is selected in the settings panel.
|
||||||
const disableDarkMode = this._dom.isDevTools() || this._opts.disableAutoDarkModeAndFireworks;
|
// TODO: set `disableDarkMode` in devtools and delete this special case.
|
||||||
|
const disableDarkMode = this._dom.isDevTools() ||
|
||||||
|
this._opts.disableDarkMode || this._opts.disableAutoDarkModeAndFireworks;
|
||||||
if (!disableDarkMode && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
if (!disableDarkMode && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||||
turnOffTheLights = true;
|
toggleDarkTheme(this._dom, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fireworks!
|
// Fireworks!
|
||||||
|
@ -85,13 +86,12 @@ export class ReportUIFeatures {
|
||||||
const cat = lhr.categories[id];
|
const cat = lhr.categories[id];
|
||||||
return cat && cat.score === 1;
|
return cat && cat.score === 1;
|
||||||
});
|
});
|
||||||
if (scoresAll100 && !this._opts.disableAutoDarkModeAndFireworks) {
|
const disableFireworks =
|
||||||
turnOffTheLights = true;
|
this._opts.disableFireworks || this._opts.disableAutoDarkModeAndFireworks;
|
||||||
|
if (scoresAll100 && !disableFireworks) {
|
||||||
this._enableFireworks();
|
this._enableFireworks();
|
||||||
}
|
// If dark mode is allowed, force it on because it looks so much better.
|
||||||
|
if (!disableDarkMode) toggleDarkTheme(this._dom, true);
|
||||||
if (turnOffTheLights) {
|
|
||||||
toggleDarkTheme(this._dom, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show the metric descriptions by default when there is an error.
|
// Show the metric descriptions by default when there is an error.
|
||||||
|
|
|
@ -46,7 +46,8 @@ async function renderLHReport() {
|
||||||
|
|
||||||
const reportRootEl = lighthouseRenderer.renderReport(lhr, {
|
const reportRootEl = lighthouseRenderer.renderReport(lhr, {
|
||||||
omitTopbar: true,
|
omitTopbar: true,
|
||||||
disableAutoDarkModeAndFireworks: true,
|
disableFireworks: true,
|
||||||
|
disableDarkMode: true,
|
||||||
});
|
});
|
||||||
// TODO: display warnings if appropriate.
|
// TODO: display warnings if appropriate.
|
||||||
for (const el of reportRootEl.querySelectorAll('.lh-warnings--toplevel')) {
|
for (const el of reportRootEl.querySelectorAll('.lh-warnings--toplevel')) {
|
||||||
|
|
|
@ -12,8 +12,16 @@ declare module Renderer {
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
/**
|
/**
|
||||||
* Don't automatically apply dark-mode to dark based on (prefers-color-scheme: dark). (DevTools and PSI don't want this.)
|
* Disables automatically applying dark mode based on `prefers-color-scheme: dark`. Dark mode can still
|
||||||
* Also, the fireworks easter-egg will want to flip to dark, so this setting will also disable chance of fireworks. */
|
* be manually applied by assigning the class `lh-dark` to the report element.
|
||||||
|
*/
|
||||||
|
disableDarkMode?: boolean;
|
||||||
|
/** Disables the fireworks animation that plays when all core categories have a 100 score. */
|
||||||
|
disableFireworks?: boolean;
|
||||||
|
/**
|
||||||
|
* Disable dark mode and fireworks.
|
||||||
|
* @deprecated Use `disableDarkMode` and `disableFireworks` instead.
|
||||||
|
*/
|
||||||
disableAutoDarkModeAndFireworks?: boolean;
|
disableAutoDarkModeAndFireworks?: boolean;
|
||||||
|
|
||||||
/** Disable the topbar UI component */
|
/** Disable the topbar UI component */
|
||||||
|
|
Загрузка…
Ссылка в новой задаче