(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 getFragmentFromUrl(url) { if (!url.includes('#')) { return undefined; } return url.split('#').pop(); } function setFocus($element, options = {}) { var _options$onBeforeFocu; const isFocusable = $element.getAttribute('tabindex'); if (!isFocusable) { $element.setAttribute('tabindex', '-1'); } function onFocus() { $element.addEventListener('blur', onBlur, { once: true }); } function onBlur() { var _options$onBlur; (_options$onBlur = options.onBlur) == null || _options$onBlur.call($element); if (!isFocusable) { $element.removeAttribute('tabindex'); } } $element.addEventListener('focus', onFocus, { once: true }); (_options$onBeforeFocu = options.onBeforeFocus) == null || _options$onBeforeFocu.call($element); $element.focus(); } function isSupported($scope = document.body) { if (!$scope) { return false; } return $scope.classList.contains('govuk-frontend-supported'); } /** * Schema for component config * * @typedef {object} Schema * @property {{ [field: string]: SchemaProperty | undefined }} properties - Schema properties * @property {SchemaCondition[]} [anyOf] - List of schema conditions */ /** * Schema property for component config * * @typedef {object} SchemaProperty * @property {'string' | 'boolean' | 'number' | 'object'} type - Property type */ /** * 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 */ 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 `