{"version":3,"file":"initMetric.js","sources":["../../../../../src/metrics/web-vitals/lib/initMetric.ts"],"sourcesContent":["/*\n * Copyright 2020 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { WINDOW } from '../../../types';\nimport type { MetricType } from '../types';\nimport { generateUniqueID } from './generateUniqueID';\nimport { getActivationStart } from './getActivationStart';\nimport { getNavigationEntry } from './getNavigationEntry';\n\nexport const initMetric = (name: MetricName, value: number = -1) => {\n const navEntry = getNavigationEntry();\n let navigationType: MetricType['navigationType'] = 'navigate';\n\n if (navEntry) {\n if (WINDOW.document?.prerendering || getActivationStart() > 0) {\n navigationType = 'prerender';\n } else if (WINDOW.document?.wasDiscarded) {\n navigationType = 'restore';\n } else if (navEntry.type) {\n navigationType = navEntry.type.replace(/_/g, '-') as MetricType['navigationType'];\n }\n }\n\n // Use `entries` type specific for the metric.\n const entries: Extract['entries'] = [];\n\n return {\n name,\n value,\n rating: 'good' as const, // If needed, will be updated when reported. `const` to keep the type from widening to `string`.\n delta: 0,\n entries,\n id: generateUniqueID(),\n navigationType,\n };\n};\n"],"names":["getNavigationEntry","WINDOW","getActivationStart","generateUniqueID"],"mappings":";;;;;;;AAsBO,MAAM,UAAA,GAAa,CAAwC,IAAA,EAAkB,KAAA,GAAgB,EAAA,KAAO;AACzG,EAAA,MAAM,WAAWA,qCAAA,EAAmB;AACpC,EAAA,IAAI,cAAA,GAA+C,UAAA;AAEnD,EAAA,IAAI,QAAA,EAAU;AACZ,IAAA,IAAIC,YAAA,CAAO,QAAA,EAAU,YAAA,IAAgBC,qCAAA,KAAuB,CAAA,EAAG;AAC7D,MAAA,cAAA,GAAiB,WAAA;AAAA,IACnB,CAAA,MAAA,IAAWD,YAAA,CAAO,QAAA,EAAU,YAAA,EAAc;AACxC,MAAA,cAAA,GAAiB,SAAA;AAAA,IACnB,CAAA,MAAA,IAAW,SAAS,IAAA,EAAM;AACxB,MAAA,cAAA,GAAiB,QAAA,CAAS,IAAA,CAAK,OAAA,CAAQ,IAAA,EAAM,GAAG,CAAA;AAAA,IAClD;AAAA,EACF;AAGA,EAAA,MAAM,UAAgE,EAAC;AAEvE,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,KAAA;AAAA,IACA,MAAA,EAAQ,MAAA;AAAA;AAAA,IACR,KAAA,EAAO,CAAA;AAAA,IACP,OAAA;AAAA,IACA,IAAIE,iCAAA,EAAiB;AAAA,IACrB;AAAA,GACF;AACF;;;;"}