{"version":3,"file":"LargestContentfulPaint.js","sourceRoot":"","sources":["../../../../../../../../front_end/models/trace/lantern/metrics/LargestContentfulPaint.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AAKxC,OAAO,EAAC,oBAAoB,EAAC,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAEL,MAAM,GAIP,MAAM,aAAa,CAAC;AAErB,MAAM,sBAAuB,SAAQ,MAAM;IACzC,MAAM,KAAc,YAAY;QAC9B,OAAO;YACL,SAAS,EAAE,CAAC;YACZ,UAAU,EAAE,GAAG;YACf,WAAW,EAAE,GAAG;SACjB,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,yBAAyB,CAAC,IAAgB;QAC/C,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,KAAK,OAAO,CAAC;QACtD,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,KAAK,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,KAAK,SAAS,CAAC;QAC7F,OAAO,CAAC,OAAO,IAAI,CAAC,aAAa,CAAC;IACpC,CAAC;IAED,MAAM,CAAU,kBAAkB,CAC9B,eAA2B,EAAE,mBAAyD;QACxF,MAAM,GAAG,GAAG,mBAAmB,CAAC,UAAU,CAAC,sBAAsB,CAAC;QAClE,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QACxC,CAAC;QAED,OAAO,oBAAoB,CAAC,uBAAuB,CAAC,eAAe,EAAE;YACnE,eAAe,EAAE,GAAG;YACpB,yBAAyB,EAAE,sBAAsB,CAAC,yBAAyB;SAC5E,CAAC,CAAC;IACL,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AC;QACjD,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QACtE,OAAO,YAAY,CAAC;IACtB,CAAC;CACF;AAED,OAAO,EAAC,sBAAsB,EAAC,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Core from '../core/core.js';\nimport type * as Graph from '../graph/graph.js';\nimport type * as Simulation from '../simulation/simulation.js';\nimport type * as Types from '../types/types.js';\n\nimport {FirstContentfulPaint} from './FirstContentfulPaint.js';\nimport {\n type Extras,\n Metric,\n type MetricCoefficients,\n type MetricComputationDataInput,\n type MetricResult,\n} from './Metric.js';\n\nclass LargestContentfulPaint extends Metric {\n static override get coefficients(): MetricCoefficients {\n return {\n intercept: 0,\n optimistic: 0.5,\n pessimistic: 0.5,\n };\n }\n\n /**\n * Low priority image nodes are usually offscreen and very unlikely to be the\n * resource that is required for LCP. Our LCP graphs include everything except for these images.\n */\n static isNotLowPriorityImageNode(node: Graph.Node): boolean {\n if (node.type !== 'network') {\n return true;\n }\n const isImage = node.request.resourceType === 'Image';\n const isLowPriority = node.request.priority === 'Low' || node.request.priority === 'VeryLow';\n return !isImage || !isLowPriority;\n }\n\n static override getOptimisticGraph(\n dependencyGraph: Graph.Node, processedNavigation: Types.Simulation.ProcessedNavigation): Graph.Node {\n const lcp = processedNavigation.timestamps.largestContentfulPaint;\n if (!lcp) {\n throw new Core.LanternError('NO_LCP');\n }\n\n return FirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {\n cutoffTimestamp: lcp,\n treatNodeAsRenderBlocking: LargestContentfulPaint.isNotLowPriorityImageNode,\n });\n }\n\n static override getPessimisticGraph(\n dependencyGraph: Graph.Node, processedNavigation: Types.Simulation.ProcessedNavigation): Graph.Node {\n const lcp = processedNavigation.timestamps.largestContentfulPaint;\n if (!lcp) {\n throw new Core.LanternError('NO_LCP');\n }\n\n return FirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {\n cutoffTimestamp: lcp,\n treatNodeAsRenderBlocking: _ => true,\n // For pessimistic LCP we'll include *all* layout nodes\n additionalCpuNodesToTreatAsRenderBlocking: node => node.didPerformLayout(),\n });\n }\n\n static override getEstimateFromSimulation(simulationResult: Simulation.Result): Simulation.Result {\n const nodeTimesNotOffscreenImages = Array.from(simulationResult.nodeTimings.entries())\n .filter(entry => LargestContentfulPaint.isNotLowPriorityImageNode(entry[0]))\n .map(entry => entry[1].endTime);\n\n return {\n timeInMs: Math.max(...nodeTimesNotOffscreenImages),\n nodeTimings: simulationResult.nodeTimings,\n };\n }\n\n static override compute(data: MetricComputationDataInput, extras?: Omit): MetricResult {\n const fcpResult = extras?.fcpResult;\n if (!fcpResult) {\n throw new Core.LanternError('FCP is required to calculate the LCP metric');\n }\n\n const metricResult = super.compute(data, extras);\n metricResult.timing = Math.max(metricResult.timing, fcpResult.timing);\n return metricResult;\n }\n}\n\nexport {LargestContentfulPaint};\n"]}