diff --git a/CHANGELOG.md b/CHANGELOG.md index 396a90a1cc..710b52cfa4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ For advice on how to use these release notes see [our guidance on staying up to ## Unreleased -### New features +## 5.0.0-beta.1 (Pre-release) ### Fixes diff --git a/dist/VERSION.txt b/dist/VERSION.txt index 5183a25c3a..9e25fc0ae0 100644 --- a/dist/VERSION.txt +++ b/dist/VERSION.txt @@ -1 +1 @@ -5.0.0-beta.0 +5.0.0-beta.1 diff --git a/dist/govuk-frontend-5.0.0-beta.0.min.js b/dist/govuk-frontend-5.0.0-beta.0.min.js deleted file mode 100644 index 45cebefc1d..0000000000 --- a/dist/govuk-frontend-5.0.0-beta.0.min.js +++ /dev/null @@ -1 +0,0 @@ -const version="5.0.0-beta.0";function mergeConfigs(...t){function flattenObject(t){const e={};return function flattenLoop(t,i){for(const[s,n]of Object.entries(t)){const t=i?`${i}.${s}`:s;n&&"object"==typeof n?flattenLoop(n,t):e[t]=n}}(t),e}const e={};for(const i of t){const t=flattenObject(i);for(const[i,s]of Object.entries(t))e[i]=s}return e}function extractConfigByNamespace(t,e){const i={};for(const[s,n]of Object.entries(t)){const t=s.split(".");if(t[0]===e){t.length>1&&t.shift();i[t.join(".")]=n}}return i}function getFragmentFromUrl(t){if(-1!==t.indexOf("#"))return t.split("#").pop()}function isSupported(t=document.body){return t.classList.contains("govuk-frontend-supported")}function normaliseString(t){if("string"!=typeof t)return t;const e=t.trim();return"true"===e||"false"!==e&&(e.length>0&&isFinite(Number(e))?Number(e):t)}function normaliseDataset(t){const e={};for(const[i,s]of Object.entries(t))e[i]=normaliseString(s);return e}class GOVUKFrontendError extends Error{constructor(...t){super(...t),this.name="GOVUKFrontendError"}}class SupportError extends GOVUKFrontendError{constructor(){super("GOV.UK Frontend is not supported in this browser"),this.name="SupportError"}}class ConfigError extends GOVUKFrontendError{constructor(...t){super(...t),this.name="ConfigError"}}class ElementError extends GOVUKFrontendError{constructor(t){let e="string"==typeof t?t:"";if("object"==typeof t){const{componentName:i,identifier:s,element:n,expectedType:o}=t;e=`${i}: ${s}`,e+=n?` is not of type ${o||"HTMLElement"}`:" not found"}super(e),this.name="ElementError"}}class GOVUKFrontendComponent{constructor(){this.checkSupport()}checkSupport(){if(!isSupported())throw new SupportError}}class I18n{constructor(t={},e={}){this.translations=void 0,this.locale=void 0,this.translations=t,this.locale=e.locale||document.documentElement.lang||"en"}t(t,e){if(!t)throw new Error("i18n: lookup key missing");e&&"number"==typeof e.count&&(t=`${t}.${this.getPluralSuffix(t,e.count)}`);const i=this.translations[t];if("string"==typeof i){if(i.match(/%{(.\S+)}/)){if(!e)throw new Error("i18n: cannot replace placeholders in string if no option data provided");return this.replacePlaceholders(i,e)}return i}return t}replacePlaceholders(t,e){const i=Intl.NumberFormat.supportedLocalesOf(this.locale).length?new Intl.NumberFormat(this.locale):void 0;return t.replace(/%{(.\S+)}/g,(function(t,s){if(Object.prototype.hasOwnProperty.call(e,s)){const t=e[s];return!1===t||"number"!=typeof t&&"string"!=typeof t?"":"number"==typeof t?i?i.format(t):`${t}`:t}throw new Error(`i18n: no data found to replace ${t} placeholder in string`)}))}hasIntlPluralRulesSupport(){return Boolean("PluralRules"in window.Intl&&Intl.PluralRules.supportedLocalesOf(this.locale).length)}getPluralSuffix(t,e){if(e=Number(e),!isFinite(e))return"other";const i=this.hasIntlPluralRulesSupport()?new Intl.PluralRules(this.locale).select(e):this.selectPluralFormUsingFallbackRules(e);if(`${t}.${i}`in this.translations)return i;if(`${t}.other`in this.translations)return console.warn(`i18n: Missing plural form ".${i}" for "${this.locale}" locale. Falling back to ".other".`),"other";throw new Error(`i18n: Plural form ".other" is required for "${this.locale}" locale`)}selectPluralFormUsingFallbackRules(t){t=Math.abs(Math.floor(t));const e=this.getPluralRulesForLocale();return e?I18n.pluralRules[e](t):"other"}getPluralRulesForLocale(){const t=this.locale.split("-")[0];for(const e in I18n.pluralRulesMap)for(const i of I18n.pluralRulesMap[e])if(i===this.locale||i===t)return e}}I18n.pluralRulesMap={arabic:["ar"],chinese:["my","zh","id","ja","jv","ko","ms","th","vi"],french:["hy","bn","fr","gu","hi","fa","pa","zu"],german:["af","sq","az","eu","bg","ca","da","nl","en","et","fi","ka","de","el","hu","lb","no","so","sw","sv","ta","te","tr","ur"],irish:["ga"],russian:["ru","uk"],scottish:["gd"],spanish:["pt-PT","it","es"],welsh:["cy"]},I18n.pluralRules={arabic:t=>0===t?"zero":1===t?"one":2===t?"two":t%100>=3&&t%100<=10?"few":t%100>=11&&t%100<=99?"many":"other",chinese:()=>"other",french:t=>0===t||1===t?"one":"other",german:t=>1===t?"one":"other",irish:t=>1===t?"one":2===t?"two":t>=3&&t<=6?"few":t>=7&&t<=10?"many":"other",russian(t){const e=t%100,i=e%10;return 1===i&&11!==e?"one":i>=2&&i<=4&&!(e>=12&&e<=14)?"few":0===i||i>=5&&i<=9||e>=11&&e<=14?"many":"other"},scottish:t=>1===t||11===t?"one":2===t||12===t?"two":t>=3&&t<=10||t>=13&&t<=19?"few":"other",spanish:t=>1===t?"one":t%1e6==0&&0!==t?"many":"other",welsh:t=>0===t?"zero":1===t?"one":2===t?"two":3===t?"few":6===t?"many":"other"};class Accordion extends GOVUKFrontendComponent{constructor(e,i={}){if(super(),this.$module=void 0,this.config=void 0,this.i18n=void 0,this.controlsClass="govuk-accordion__controls",this.showAllClass="govuk-accordion__show-all",this.showAllTextClass="govuk-accordion__show-all-text",this.sectionClass="govuk-accordion__section",this.sectionExpandedClass="govuk-accordion__section--expanded",this.sectionButtonClass="govuk-accordion__section-button",this.sectionHeaderClass="govuk-accordion__section-header",this.sectionHeadingClass="govuk-accordion__section-heading",this.sectionHeadingDividerClass="govuk-accordion__section-heading-divider",this.sectionHeadingTextClass="govuk-accordion__section-heading-text",this.sectionHeadingTextFocusClass="govuk-accordion__section-heading-text-focus",this.sectionShowHideToggleClass="govuk-accordion__section-toggle",this.sectionShowHideToggleFocusClass="govuk-accordion__section-toggle-focus",this.sectionShowHideTextClass="govuk-accordion__section-toggle-text",this.upChevronIconClass="govuk-accordion-nav__chevron",this.downChevronIconClass="govuk-accordion-nav__chevron--down",this.sectionSummaryClass="govuk-accordion__section-summary",this.sectionSummaryFocusClass="govuk-accordion__section-summary-focus",this.sectionContentClass="govuk-accordion__section-content",this.$sections=void 0,this.browserSupportsSessionStorage=!1,this.$showAllButton=null,this.$showAllIcon=null,this.$showAllText=null,!(e instanceof HTMLElement))throw new ElementError({componentName:"Accordion",element:e,identifier:"Root element (`$module`)"});this.$module=e,this.config=mergeConfigs(Accordion.defaults,i,normaliseDataset(e.dataset)),this.i18n=new I18n(extractConfigByNamespace(this.config,"i18n"));const s=this.$module.querySelectorAll(`.${this.sectionClass}`);if(!s.length)throw new ElementError({componentName:"Accordion",identifier:`Sections (\`