(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.GOVUKFrontend = {})); })(this, (function (exports) { 'use strict'; function mergeConfigs(...configObjects) { function flattenObject(configObject) { const flattenedObject = {}; function flattenLoop(obj, prefix) { for (const [key, value] of Object.entries(obj)) { const prefixedKey = prefix ? `${prefix}.${key}` : key; if (value && typeof value === 'object') { flattenLoop(value, prefixedKey); } else { flattenedObject[prefixedKey] = value; } } } flattenLoop(configObject); return flattenedObject; } const formattedConfigObject = {}; for (const configObject of configObjects) { const obj = flattenObject(configObject); for (const [key, value] of Object.entries(obj)) { formattedConfigObject[key] = value; } } return formattedConfigObject; } function isSupported($scope = document.body) { if (!$scope) { return false; } return $scope.classList.contains('govuk-frontend-supported'); } /** * Schema for component config * * @typedef {object} Schema * @property {SchemaCondition[]} [anyOf] - List of schema conditions */ /** * Schema condition for component config * * @typedef {object} SchemaCondition * @property {string[]} required - List of required config fields * @property {string} errorMessage - Error message when required config fields not provided */ function normaliseString(value) { if (typeof value !== 'string') { return value; } const trimmedValue = value.trim(); if (trimmedValue === 'true') { return true; } if (trimmedValue === 'false') { return false; } if (trimmedValue.length > 0 && isFinite(Number(trimmedValue))) { return Number(trimmedValue); } return value; } function normaliseDataset(dataset) { const out = {}; for (const [key, value] of Object.entries(dataset)) { out[key] = normaliseString(value); } return out; } class GOVUKFrontendError extends Error { constructor(...args) { super(...args); this.name = 'GOVUKFrontendError'; } } class SupportError extends GOVUKFrontendError { /** * Checks if GOV.UK Frontend is supported on this page * * @param {HTMLElement | null} [$scope] - HTML element `
` checked for browser support */ constructor($scope = document.body) { const supportMessage = 'noModule' in HTMLScriptElement.prototype ? 'GOV.UK Frontend initialised without `` from template `