govuk_tech_docs 3.4.5 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (327) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/publish.yaml +8 -4
  3. data/.github/workflows/test.yaml +11 -4
  4. data/.rubocop.yml +1 -1
  5. data/CHANGELOG.md +22 -1
  6. data/example/.ruby-version +1 -1
  7. data/example/source/javascripts/govuk_frontend.js +1 -0
  8. data/govuk_tech_docs.gemspec +17 -11
  9. data/lib/assets/javascripts/_modules/page-expiry.js +2 -2
  10. data/lib/assets/javascripts/_modules/table-of-contents.js +48 -2
  11. data/lib/assets/javascripts/govuk_frontend_all.js +3 -0
  12. data/lib/assets/javascripts/govuk_tech_docs.js +0 -2
  13. data/lib/assets/stylesheets/_govuk_tech_docs.scss +4 -10
  14. data/lib/assets/stylesheets/modules/_page-review.scss +0 -2
  15. data/lib/assets/stylesheets/modules/_search.scss +0 -4
  16. data/lib/govuk_tech_docs/meta_tags.rb +1 -1
  17. data/lib/govuk_tech_docs/redirects.rb +1 -1
  18. data/lib/govuk_tech_docs/table_of_contents/heading_tree_builder.rb +1 -1
  19. data/lib/govuk_tech_docs/table_of_contents/helpers.rb +2 -2
  20. data/lib/govuk_tech_docs/tech_docs_html_renderer.rb +6 -2
  21. data/lib/govuk_tech_docs/version.rb +1 -1
  22. data/lib/govuk_tech_docs.rb +20 -3
  23. data/lib/source/layouts/_header.erb +8 -12
  24. data/lib/source/layouts/_page_review.erb +1 -1
  25. data/lib/source/layouts/_search.erb +2 -2
  26. data/lib/source/layouts/core.erb +8 -2
  27. data/lib/source/stylesheets/manifest.css +1 -1
  28. data/node_modules/govuk-frontend/dist/govuk/_base.scss +5 -0
  29. data/node_modules/govuk-frontend/dist/govuk/all.bundle.js +2554 -0
  30. data/node_modules/govuk-frontend/dist/govuk/all.bundle.mjs +2529 -0
  31. data/node_modules/govuk-frontend/dist/govuk/all.mjs +18 -0
  32. data/node_modules/govuk-frontend/dist/govuk/all.scss +3 -0
  33. data/node_modules/govuk-frontend/dist/govuk/assets/images/favicon.svg +1 -0
  34. data/node_modules/govuk-frontend/dist/govuk/assets/images/govuk-crest.svg +1 -0
  35. data/node_modules/govuk-frontend/dist/govuk/assets/images/govuk-icon-180.png +0 -0
  36. data/node_modules/govuk-frontend/dist/govuk/assets/images/govuk-icon-192.png +0 -0
  37. data/node_modules/govuk-frontend/dist/govuk/assets/images/govuk-icon-512.png +0 -0
  38. data/node_modules/govuk-frontend/dist/govuk/assets/images/govuk-icon-mask.svg +1 -0
  39. data/node_modules/govuk-frontend/dist/govuk/assets/images/govuk-opengraph-image.png +0 -0
  40. data/node_modules/govuk-frontend/dist/govuk/common/closest-attribute-value.mjs +7 -0
  41. data/node_modules/govuk-frontend/dist/govuk/common/govuk-frontend-version.mjs +4 -0
  42. data/node_modules/govuk-frontend/dist/govuk/common/index.mjs +159 -0
  43. data/node_modules/govuk-frontend/dist/govuk/common/normalise-dataset.mjs +18 -0
  44. data/node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs +31 -0
  45. data/node_modules/govuk-frontend/dist/govuk/components/_all.scss +10 -0
  46. data/node_modules/govuk-frontend/{govuk/components/_all.scss → dist/govuk/components/_index.scss} +8 -3
  47. data/node_modules/govuk-frontend/dist/govuk/components/accordion/_accordion.scss +4 -0
  48. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/accordion/_index.scss +55 -77
  49. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js +785 -0
  50. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs +777 -0
  51. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.mjs +349 -0
  52. data/node_modules/govuk-frontend/dist/govuk/components/back-link/_back-link.scss +4 -0
  53. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/back-link/_index.scss +12 -36
  54. data/node_modules/govuk-frontend/dist/govuk/components/breadcrumbs/_breadcrumbs.scss +4 -0
  55. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/breadcrumbs/_index.scss +11 -36
  56. data/node_modules/govuk-frontend/dist/govuk/components/button/_button.scss +4 -0
  57. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/button/_index.scss +30 -103
  58. data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.js +318 -0
  59. data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.mjs +310 -0
  60. data/node_modules/govuk-frontend/dist/govuk/components/button/button.mjs +73 -0
  61. data/node_modules/govuk-frontend/dist/govuk/components/character-count/_character-count.scss +4 -0
  62. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/character-count/_index.scss +8 -6
  63. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js +761 -0
  64. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs +753 -0
  65. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.mjs +295 -0
  66. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/_checkboxes.scss +4 -0
  67. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/checkboxes/_index.scss +108 -132
  68. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js +268 -0
  69. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs +260 -0
  70. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.mjs +111 -0
  71. data/node_modules/govuk-frontend/dist/govuk/components/cookie-banner/_cookie-banner.scss +4 -0
  72. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/cookie-banner/_index.scss +19 -15
  73. data/node_modules/govuk-frontend/dist/govuk/components/date-input/_date-input.scss +4 -0
  74. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/date-input/_index.scss +3 -2
  75. data/node_modules/govuk-frontend/dist/govuk/components/details/_details.scss +4 -0
  76. data/node_modules/govuk-frontend/dist/govuk/components/details/_index.scss +139 -0
  77. data/node_modules/govuk-frontend/dist/govuk/components/error-message/_error-message.scss +4 -0
  78. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/error-message/_index.scss +2 -0
  79. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/_error-summary.scss +4 -0
  80. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/error-summary/_index.scss +19 -6
  81. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js +378 -0
  82. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs +370 -0
  83. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.mjs +103 -0
  84. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/_exit-this-page.scss +4 -0
  85. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/exit-this-page/_index.scss +5 -10
  86. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js +662 -0
  87. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs +654 -0
  88. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.mjs +226 -0
  89. data/node_modules/govuk-frontend/dist/govuk/components/fieldset/_fieldset.scss +4 -0
  90. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/fieldset/_index.scss +20 -15
  91. data/node_modules/govuk-frontend/dist/govuk/components/file-upload/_file-upload.scss +4 -0
  92. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/file-upload/_index.scss +11 -15
  93. data/node_modules/govuk-frontend/dist/govuk/components/footer/_footer.scss +4 -0
  94. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/footer/_index.scss +25 -68
  95. data/node_modules/govuk-frontend/dist/govuk/components/header/_header.scss +4 -0
  96. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/header/_index.scss +84 -79
  97. data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.js +252 -0
  98. data/node_modules/govuk-frontend/dist/govuk/components/header/header.bundle.mjs +244 -0
  99. data/node_modules/govuk-frontend/dist/govuk/components/header/header.mjs +88 -0
  100. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/hint/_hint.scss +2 -0
  101. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/hint/_index.scss +3 -0
  102. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/input/_index.scss +24 -49
  103. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/input/_input.scss +2 -0
  104. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/inset-text/_index.scss +2 -0
  105. data/node_modules/govuk-frontend/dist/govuk/components/inset-text/_inset-text.scss +4 -0
  106. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/label/_index.scss +12 -7
  107. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/label/_label.scss +2 -0
  108. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/notification-banner/_index.scss +11 -7
  109. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/_notification-banner.scss +4 -0
  110. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js +320 -0
  111. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs +312 -0
  112. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs +51 -0
  113. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/pagination/_index.scss +36 -55
  114. data/node_modules/govuk-frontend/dist/govuk/components/pagination/_pagination.scss +4 -0
  115. data/node_modules/govuk-frontend/dist/govuk/components/panel/_index.scss +58 -0
  116. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/panel/_panel.scss +2 -0
  117. data/node_modules/govuk-frontend/dist/govuk/components/password-input/_index.scss +57 -0
  118. data/node_modules/govuk-frontend/dist/govuk/components/password-input/_password-input.scss +4 -0
  119. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js +594 -0
  120. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs +586 -0
  121. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.mjs +154 -0
  122. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/phase-banner/_index.scss +10 -1
  123. data/node_modules/govuk-frontend/dist/govuk/components/phase-banner/_phase-banner.scss +4 -0
  124. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/radios/_index.scss +92 -113
  125. data/node_modules/govuk-frontend/dist/govuk/components/radios/_radios.scss +4 -0
  126. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.js +245 -0
  127. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs +237 -0
  128. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.mjs +88 -0
  129. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/select/_index.scss +9 -16
  130. data/node_modules/govuk-frontend/dist/govuk/components/select/_select.scss +4 -0
  131. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/_index.scss +168 -0
  132. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/_service-navigation.scss +4 -0
  133. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js +249 -0
  134. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs +241 -0
  135. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.mjs +85 -0
  136. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/skip-link/_index.scss +10 -5
  137. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/_skip-link.scss +4 -0
  138. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js +244 -0
  139. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs +236 -0
  140. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.mjs +58 -0
  141. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/summary-list/_index.scss +22 -20
  142. data/node_modules/govuk-frontend/dist/govuk/components/summary-list/_summary-list.scss +4 -0
  143. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/table/_index.scss +21 -17
  144. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/table/_table.scss +2 -0
  145. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/tabs/_index.scss +13 -9
  146. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/tabs/_tabs.scss +2 -0
  147. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js +453 -0
  148. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs +445 -0
  149. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.mjs +283 -0
  150. data/node_modules/govuk-frontend/dist/govuk/components/tag/_index.scss +97 -0
  151. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/tag/_tag.scss +2 -0
  152. data/node_modules/govuk-frontend/dist/govuk/components/task-list/_index.scss +79 -0
  153. data/node_modules/govuk-frontend/dist/govuk/components/task-list/_task-list.scss +4 -0
  154. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/textarea/_index.scss +6 -10
  155. data/node_modules/govuk-frontend/dist/govuk/components/textarea/_textarea.scss +4 -0
  156. data/node_modules/govuk-frontend/{govuk → dist/govuk}/components/warning-text/_index.scss +13 -13
  157. data/node_modules/govuk-frontend/dist/govuk/components/warning-text/_warning-text.scss +4 -0
  158. data/node_modules/govuk-frontend/dist/govuk/core/_all.scss +10 -0
  159. data/node_modules/govuk-frontend/{govuk → dist/govuk}/core/_global-styles.scss +2 -1
  160. data/node_modules/govuk-frontend/dist/govuk/core/_govuk-frontend-properties.scss +12 -0
  161. data/node_modules/govuk-frontend/{govuk/core/_all.scss → dist/govuk/core/_index.scss} +3 -1
  162. data/node_modules/govuk-frontend/{govuk → dist/govuk}/core/_links.scss +8 -1
  163. data/node_modules/govuk-frontend/{govuk → dist/govuk}/core/_lists.scss +2 -1
  164. data/node_modules/govuk-frontend/{govuk → dist/govuk}/core/_section-break.scss +2 -7
  165. data/node_modules/govuk-frontend/{govuk → dist/govuk}/core/_typography.scss +8 -5
  166. data/node_modules/govuk-frontend/dist/govuk/errors/index.mjs +57 -0
  167. data/node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs +60 -0
  168. data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.js +1 -0
  169. data/node_modules/govuk-frontend/dist/govuk/helpers/_all.scss +10 -0
  170. data/node_modules/govuk-frontend/{govuk → dist/govuk}/helpers/_clearfix.scss +3 -1
  171. data/node_modules/govuk-frontend/dist/govuk/helpers/_colour.scss +127 -0
  172. data/node_modules/govuk-frontend/{govuk → dist/govuk}/helpers/_device-pixels.scss +4 -3
  173. data/node_modules/govuk-frontend/{govuk → dist/govuk}/helpers/_focused.scss +22 -6
  174. data/node_modules/govuk-frontend/dist/govuk/helpers/_font-faces.scss +41 -0
  175. data/node_modules/govuk-frontend/{govuk → dist/govuk}/helpers/_grid.scss +3 -1
  176. data/node_modules/govuk-frontend/{govuk/helpers/_all.scss → dist/govuk/helpers/_index.scss} +2 -0
  177. data/node_modules/govuk-frontend/{govuk → dist/govuk}/helpers/_links.scss +38 -76
  178. data/node_modules/govuk-frontend/{govuk → dist/govuk}/helpers/_media-queries.scss +3 -12
  179. data/node_modules/govuk-frontend/{govuk → dist/govuk}/helpers/_shape-arrow.scss +3 -1
  180. data/node_modules/govuk-frontend/{govuk → dist/govuk}/helpers/_spacing.scss +12 -10
  181. data/node_modules/govuk-frontend/dist/govuk/helpers/_typography.scss +288 -0
  182. data/node_modules/govuk-frontend/{govuk → dist/govuk}/helpers/_visually-hidden.scss +39 -50
  183. data/node_modules/govuk-frontend/dist/govuk/i18n.mjs +195 -0
  184. data/node_modules/govuk-frontend/dist/govuk/index.scss +11 -0
  185. data/node_modules/govuk-frontend/dist/govuk/init.mjs +162 -0
  186. data/node_modules/govuk-frontend/dist/govuk/objects/_all.scss +10 -0
  187. data/node_modules/govuk-frontend/{govuk → dist/govuk}/objects/_button-group.scss +7 -12
  188. data/node_modules/govuk-frontend/{govuk → dist/govuk}/objects/_form-group.scss +2 -0
  189. data/node_modules/govuk-frontend/{govuk → dist/govuk}/objects/_grid.scss +4 -2
  190. data/node_modules/govuk-frontend/{govuk/objects/_all.scss → dist/govuk/objects/_index.scss} +2 -0
  191. data/node_modules/govuk-frontend/{govuk → dist/govuk}/objects/_main-wrapper.scss +2 -0
  192. data/node_modules/govuk-frontend/{govuk → dist/govuk}/objects/_template.scss +2 -1
  193. data/node_modules/govuk-frontend/{govuk → dist/govuk}/objects/_width-container.scss +2 -9
  194. data/node_modules/govuk-frontend/dist/govuk/overrides/_all.scss +9 -0
  195. data/node_modules/govuk-frontend/{govuk → dist/govuk}/overrides/_display.scss +2 -0
  196. data/node_modules/govuk-frontend/{govuk/overrides/_all.scss → dist/govuk/overrides/_index.scss} +2 -0
  197. data/node_modules/govuk-frontend/{govuk → dist/govuk}/overrides/_spacing.scss +3 -19
  198. data/node_modules/govuk-frontend/{govuk → dist/govuk}/overrides/_text-align.scss +2 -0
  199. data/node_modules/govuk-frontend/dist/govuk/overrides/_typography.scss +42 -0
  200. data/node_modules/govuk-frontend/{govuk → dist/govuk}/overrides/_width.scss +2 -0
  201. data/node_modules/govuk-frontend/dist/govuk/settings/_all.scss +10 -0
  202. data/node_modules/govuk-frontend/{govuk → dist/govuk}/settings/_assets.scss +2 -0
  203. data/node_modules/govuk-frontend/{govuk → dist/govuk}/settings/_colours-applied.scss +9 -7
  204. data/node_modules/govuk-frontend/dist/govuk/settings/_colours-organisations.scss +378 -0
  205. data/node_modules/govuk-frontend/dist/govuk/settings/_colours-palette.scss +37 -0
  206. data/node_modules/govuk-frontend/{govuk → dist/govuk}/settings/_global-styles.scss +2 -0
  207. data/node_modules/govuk-frontend/{govuk/settings/_all.scss → dist/govuk/settings/_index.scss} +2 -3
  208. data/node_modules/govuk-frontend/{govuk → dist/govuk}/settings/_links.scss +3 -20
  209. data/node_modules/govuk-frontend/{govuk → dist/govuk}/settings/_measurements.scss +18 -6
  210. data/node_modules/govuk-frontend/{govuk → dist/govuk}/settings/_media-queries.scss +5 -3
  211. data/node_modules/govuk-frontend/{govuk → dist/govuk}/settings/_spacing.scss +2 -0
  212. data/node_modules/govuk-frontend/dist/govuk/settings/_typography-font.scss +52 -0
  213. data/node_modules/govuk-frontend/dist/govuk/settings/_typography-responsive.scss +322 -0
  214. data/node_modules/govuk-frontend/{govuk → dist/govuk}/settings/_warnings.scss +33 -8
  215. data/node_modules/govuk-frontend/dist/govuk/tools/_all.scss +10 -0
  216. data/node_modules/govuk-frontend/{govuk → dist/govuk}/tools/_exports.scss +2 -0
  217. data/node_modules/govuk-frontend/{govuk → dist/govuk}/tools/_font-url.scss +3 -0
  218. data/node_modules/govuk-frontend/{govuk → dist/govuk}/tools/_image-url.scss +3 -0
  219. data/node_modules/govuk-frontend/{govuk/tools/_all.scss → dist/govuk/tools/_index.scss} +2 -2
  220. data/node_modules/govuk-frontend/{govuk → dist/govuk}/tools/_px-to-em.scss +2 -0
  221. data/node_modules/govuk-frontend/{govuk → dist/govuk}/tools/_px-to-rem.scss +2 -0
  222. data/node_modules/govuk-frontend/dist/govuk/utilities/_all.scss +10 -0
  223. data/node_modules/govuk-frontend/{govuk → dist/govuk}/utilities/_clearfix.scss +2 -0
  224. data/node_modules/govuk-frontend/{govuk/utilities/_all.scss → dist/govuk/utilities/_index.scss} +2 -0
  225. data/node_modules/govuk-frontend/{govuk → dist/govuk}/utilities/_visually-hidden.scss +2 -0
  226. data/node_modules/govuk-frontend/{govuk → dist/govuk}/vendor/_sass-mq.scss +3 -1
  227. data/node_modules/govuk-frontend/dist/govuk-prototype-kit/init.js +15 -0
  228. data/node_modules/govuk-frontend/{govuk-prototype-kit → dist/govuk-prototype-kit}/init.scss +3 -2
  229. data/package-lock.json +37 -37
  230. data/package.json +6 -1
  231. metadata +316 -206
  232. data/node_modules/govuk-frontend/govuk/_base.scss +0 -3
  233. data/node_modules/govuk-frontend/govuk/all-ie8.scss +0 -14
  234. data/node_modules/govuk-frontend/govuk/all.js +0 -5172
  235. data/node_modules/govuk-frontend/govuk/all.scss +0 -9
  236. data/node_modules/govuk-frontend/govuk/assets/images/favicon.ico +0 -0
  237. data/node_modules/govuk-frontend/govuk/assets/images/govuk-apple-touch-icon-152x152.png +0 -0
  238. data/node_modules/govuk-frontend/govuk/assets/images/govuk-apple-touch-icon-167x167.png +0 -0
  239. data/node_modules/govuk-frontend/govuk/assets/images/govuk-apple-touch-icon-180x180.png +0 -0
  240. data/node_modules/govuk-frontend/govuk/assets/images/govuk-apple-touch-icon.png +0 -0
  241. data/node_modules/govuk-frontend/govuk/assets/images/govuk-crest-2x.png +0 -0
  242. data/node_modules/govuk-frontend/govuk/assets/images/govuk-crest.png +0 -0
  243. data/node_modules/govuk-frontend/govuk/assets/images/govuk-logotype-crown.png +0 -0
  244. data/node_modules/govuk-frontend/govuk/assets/images/govuk-mask-icon.svg +0 -7
  245. data/node_modules/govuk-frontend/govuk/assets/images/govuk-opengraph-image.png +0 -0
  246. data/node_modules/govuk-frontend/govuk/common/closest-attribute-value.js +0 -75
  247. data/node_modules/govuk-frontend/govuk/common/govuk-frontend-version.js +0 -17
  248. data/node_modules/govuk-frontend/govuk/common/index.js +0 -192
  249. data/node_modules/govuk-frontend/govuk/common/normalise-dataset.js +0 -386
  250. data/node_modules/govuk-frontend/govuk/common.js +0 -194
  251. data/node_modules/govuk-frontend/govuk/components/accordion/_accordion.scss +0 -2
  252. data/node_modules/govuk-frontend/govuk/components/accordion/accordion.js +0 -2386
  253. data/node_modules/govuk-frontend/govuk/components/back-link/_back-link.scss +0 -2
  254. data/node_modules/govuk-frontend/govuk/components/breadcrumbs/_breadcrumbs.scss +0 -2
  255. data/node_modules/govuk-frontend/govuk/components/button/_button.scss +0 -2
  256. data/node_modules/govuk-frontend/govuk/components/button/button.js +0 -1027
  257. data/node_modules/govuk-frontend/govuk/components/character-count/_character-count.scss +0 -2
  258. data/node_modules/govuk-frontend/govuk/components/character-count/character-count.js +0 -2281
  259. data/node_modules/govuk-frontend/govuk/components/checkboxes/_checkboxes.scss +0 -2
  260. data/node_modules/govuk-frontend/govuk/components/checkboxes/checkboxes.js +0 -1277
  261. data/node_modules/govuk-frontend/govuk/components/cookie-banner/_cookie-banner.scss +0 -2
  262. data/node_modules/govuk-frontend/govuk/components/date-input/_date-input.scss +0 -2
  263. data/node_modules/govuk-frontend/govuk/components/details/_details.scss +0 -2
  264. data/node_modules/govuk-frontend/govuk/components/details/_index.scss +0 -88
  265. data/node_modules/govuk-frontend/govuk/components/details/details.js +0 -873
  266. data/node_modules/govuk-frontend/govuk/components/error-message/_error-message.scss +0 -2
  267. data/node_modules/govuk-frontend/govuk/components/error-summary/_error-summary.scss +0 -2
  268. data/node_modules/govuk-frontend/govuk/components/error-summary/error-summary.js +0 -1189
  269. data/node_modules/govuk-frontend/govuk/components/exit-this-page/_exit-this-page.scss +0 -2
  270. data/node_modules/govuk-frontend/govuk/components/exit-this-page/exit-this-page.js +0 -2120
  271. data/node_modules/govuk-frontend/govuk/components/fieldset/_fieldset.scss +0 -2
  272. data/node_modules/govuk-frontend/govuk/components/file-upload/_file-upload.scss +0 -2
  273. data/node_modules/govuk-frontend/govuk/components/footer/_footer.scss +0 -2
  274. data/node_modules/govuk-frontend/govuk/components/header/_header.scss +0 -2
  275. data/node_modules/govuk-frontend/govuk/components/header/header.js +0 -794
  276. data/node_modules/govuk-frontend/govuk/components/inset-text/_inset-text.scss +0 -2
  277. data/node_modules/govuk-frontend/govuk/components/notification-banner/_notification-banner.scss +0 -2
  278. data/node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js +0 -843
  279. data/node_modules/govuk-frontend/govuk/components/pagination/_pagination.scss +0 -2
  280. data/node_modules/govuk-frontend/govuk/components/panel/_index.scss +0 -56
  281. data/node_modules/govuk-frontend/govuk/components/phase-banner/_phase-banner.scss +0 -2
  282. data/node_modules/govuk-frontend/govuk/components/radios/_radios.scss +0 -2
  283. data/node_modules/govuk-frontend/govuk/components/radios/radios.js +0 -1222
  284. data/node_modules/govuk-frontend/govuk/components/select/_select.scss +0 -2
  285. data/node_modules/govuk-frontend/govuk/components/skip-link/_skip-link.scss +0 -2
  286. data/node_modules/govuk-frontend/govuk/components/skip-link/skip-link.js +0 -1145
  287. data/node_modules/govuk-frontend/govuk/components/summary-list/_summary-list.scss +0 -2
  288. data/node_modules/govuk-frontend/govuk/components/tabs/tabs.js +0 -1621
  289. data/node_modules/govuk-frontend/govuk/components/tag/_index.scss +0 -81
  290. data/node_modules/govuk-frontend/govuk/components/textarea/_textarea.scss +0 -2
  291. data/node_modules/govuk-frontend/govuk/components/warning-text/_warning-text.scss +0 -2
  292. data/node_modules/govuk-frontend/govuk/core/_govuk-frontend-version.scss +0 -5
  293. data/node_modules/govuk-frontend/govuk/helpers/_colour.scss +0 -98
  294. data/node_modules/govuk-frontend/govuk/helpers/_font-faces.scss +0 -41
  295. data/node_modules/govuk-frontend/govuk/helpers/_typography.scss +0 -214
  296. data/node_modules/govuk-frontend/govuk/i18n.js +0 -397
  297. data/node_modules/govuk-frontend/govuk/overrides/_typography.scss +0 -21
  298. data/node_modules/govuk-frontend/govuk/settings/_colours-organisations.scss +0 -146
  299. data/node_modules/govuk-frontend/govuk/settings/_colours-palette.scss +0 -120
  300. data/node_modules/govuk-frontend/govuk/settings/_compatibility.scss +0 -100
  301. data/node_modules/govuk-frontend/govuk/settings/_ie8.scss +0 -34
  302. data/node_modules/govuk-frontend/govuk/settings/_typography-font-families.scss +0 -32
  303. data/node_modules/govuk-frontend/govuk/settings/_typography-font.scss +0 -112
  304. data/node_modules/govuk-frontend/govuk/settings/_typography-responsive.scss +0 -195
  305. data/node_modules/govuk-frontend/govuk/tools/_compatibility.scss +0 -50
  306. data/node_modules/govuk-frontend/govuk/tools/_ie8.scss +0 -87
  307. data/node_modules/govuk-frontend/govuk/vendor/polyfills/DOMTokenList.js +0 -274
  308. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Date/now.js +0 -23
  309. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Document.js +0 -36
  310. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/classList.js +0 -597
  311. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/closest.js +0 -58
  312. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/dataset.js +0 -307
  313. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/matches.js +0 -33
  314. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/nextElementSibling.js +0 -261
  315. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/previousElementSibling.js +0 -261
  316. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element.js +0 -151
  317. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Event.js +0 -512
  318. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Function/prototype/bind.js +0 -256
  319. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Object/defineProperty.js +0 -96
  320. data/node_modules/govuk-frontend/govuk/vendor/polyfills/String/prototype/trim.js +0 -23
  321. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Window.js +0 -30
  322. data/node_modules/govuk-frontend/govuk-prototype-kit/init.js +0 -8
  323. /data/node_modules/govuk-frontend/{govuk → dist/govuk}/assets/fonts/bold-affa96571d-v2.woff +0 -0
  324. /data/node_modules/govuk-frontend/{govuk → dist/govuk}/assets/fonts/bold-b542beb274-v2.woff2 +0 -0
  325. /data/node_modules/govuk-frontend/{govuk → dist/govuk}/assets/fonts/light-94a07e06a1-v2.woff2 +0 -0
  326. /data/node_modules/govuk-frontend/{govuk → dist/govuk}/assets/fonts/light-f591b13f7d-v2.woff +0 -0
  327. /data/{lib/source → node_modules/govuk-frontend/dist/govuk/assets/images}/favicon.ico +0 -0
@@ -0,0 +1,2529 @@
1
+ const version = '5.7.1';
2
+
3
+ function normaliseString(value, property) {
4
+ const trimmedValue = value ? value.trim() : '';
5
+ let output;
6
+ let outputType = property == null ? void 0 : property.type;
7
+ if (!outputType) {
8
+ if (['true', 'false'].includes(trimmedValue)) {
9
+ outputType = 'boolean';
10
+ }
11
+ if (trimmedValue.length > 0 && isFinite(Number(trimmedValue))) {
12
+ outputType = 'number';
13
+ }
14
+ }
15
+ switch (outputType) {
16
+ case 'boolean':
17
+ output = trimmedValue === 'true';
18
+ break;
19
+ case 'number':
20
+ output = Number(trimmedValue);
21
+ break;
22
+ default:
23
+ output = value;
24
+ }
25
+ return output;
26
+ }
27
+
28
+ /**
29
+ * @typedef {import('./index.mjs').SchemaProperty} SchemaProperty
30
+ */
31
+
32
+ function mergeConfigs(...configObjects) {
33
+ const formattedConfigObject = {};
34
+ for (const configObject of configObjects) {
35
+ for (const key of Object.keys(configObject)) {
36
+ const option = formattedConfigObject[key];
37
+ const override = configObject[key];
38
+ if (isObject(option) && isObject(override)) {
39
+ formattedConfigObject[key] = mergeConfigs(option, override);
40
+ } else {
41
+ formattedConfigObject[key] = override;
42
+ }
43
+ }
44
+ }
45
+ return formattedConfigObject;
46
+ }
47
+ function extractConfigByNamespace(Component, dataset, namespace) {
48
+ const property = Component.schema.properties[namespace];
49
+ if ((property == null ? void 0 : property.type) !== 'object') {
50
+ return;
51
+ }
52
+ const newObject = {
53
+ [namespace]: ({})
54
+ };
55
+ for (const [key, value] of Object.entries(dataset)) {
56
+ let current = newObject;
57
+ const keyParts = key.split('.');
58
+ for (const [index, name] of keyParts.entries()) {
59
+ if (typeof current === 'object') {
60
+ if (index < keyParts.length - 1) {
61
+ if (!isObject(current[name])) {
62
+ current[name] = {};
63
+ }
64
+ current = current[name];
65
+ } else if (key !== namespace) {
66
+ current[name] = normaliseString(value);
67
+ }
68
+ }
69
+ }
70
+ }
71
+ return newObject[namespace];
72
+ }
73
+ function getFragmentFromUrl(url) {
74
+ if (!url.includes('#')) {
75
+ return undefined;
76
+ }
77
+ return url.split('#').pop();
78
+ }
79
+ function getBreakpoint(name) {
80
+ const property = `--govuk-frontend-breakpoint-${name}`;
81
+ const value = window.getComputedStyle(document.documentElement).getPropertyValue(property);
82
+ return {
83
+ property,
84
+ value: value || undefined
85
+ };
86
+ }
87
+ function setFocus($element, options = {}) {
88
+ var _options$onBeforeFocu;
89
+ const isFocusable = $element.getAttribute('tabindex');
90
+ if (!isFocusable) {
91
+ $element.setAttribute('tabindex', '-1');
92
+ }
93
+ function onFocus() {
94
+ $element.addEventListener('blur', onBlur, {
95
+ once: true
96
+ });
97
+ }
98
+ function onBlur() {
99
+ var _options$onBlur;
100
+ (_options$onBlur = options.onBlur) == null || _options$onBlur.call($element);
101
+ if (!isFocusable) {
102
+ $element.removeAttribute('tabindex');
103
+ }
104
+ }
105
+ $element.addEventListener('focus', onFocus, {
106
+ once: true
107
+ });
108
+ (_options$onBeforeFocu = options.onBeforeFocus) == null || _options$onBeforeFocu.call($element);
109
+ $element.focus();
110
+ }
111
+ function isInitialised($root, moduleName) {
112
+ return $root instanceof HTMLElement && $root.hasAttribute(`data-${moduleName}-init`);
113
+ }
114
+
115
+ /**
116
+ * Checks if GOV.UK Frontend is supported on this page
117
+ *
118
+ * Some browsers will load and run our JavaScript but GOV.UK Frontend
119
+ * won't be supported.
120
+ *
121
+ * @param {HTMLElement | null} [$scope] - (internal) `<body>` HTML element checked for browser support
122
+ * @returns {boolean} Whether GOV.UK Frontend is supported on this page
123
+ */
124
+ function isSupported($scope = document.body) {
125
+ if (!$scope) {
126
+ return false;
127
+ }
128
+ return $scope.classList.contains('govuk-frontend-supported');
129
+ }
130
+ function validateConfig(schema, config) {
131
+ const validationErrors = [];
132
+ for (const [name, conditions] of Object.entries(schema)) {
133
+ const errors = [];
134
+ if (Array.isArray(conditions)) {
135
+ for (const {
136
+ required,
137
+ errorMessage
138
+ } of conditions) {
139
+ if (!required.every(key => !!config[key])) {
140
+ errors.push(errorMessage);
141
+ }
142
+ }
143
+ if (name === 'anyOf' && !(conditions.length - errors.length >= 1)) {
144
+ validationErrors.push(...errors);
145
+ }
146
+ }
147
+ }
148
+ return validationErrors;
149
+ }
150
+ function isArray(option) {
151
+ return Array.isArray(option);
152
+ }
153
+ function isObject(option) {
154
+ return !!option && typeof option === 'object' && !isArray(option);
155
+ }
156
+ function formatErrorMessage(Component, message) {
157
+ return `${Component.moduleName}: ${message}`;
158
+ }
159
+
160
+ /**
161
+ * Schema for component config
162
+ *
163
+ * @typedef {object} Schema
164
+ * @property {{ [field: string]: SchemaProperty | undefined }} properties - Schema properties
165
+ * @property {SchemaCondition[]} [anyOf] - List of schema conditions
166
+ */
167
+
168
+ /**
169
+ * Schema property for component config
170
+ *
171
+ * @typedef {object} SchemaProperty
172
+ * @property {'string' | 'boolean' | 'number' | 'object'} type - Property type
173
+ */
174
+
175
+ /**
176
+ * Schema condition for component config
177
+ *
178
+ * @typedef {object} SchemaCondition
179
+ * @property {string[]} required - List of required config fields
180
+ * @property {string} errorMessage - Error message when required config fields not provided
181
+ */
182
+ /**
183
+ * @typedef ComponentWithModuleName
184
+ * @property {string} moduleName - Name of the component
185
+ */
186
+
187
+ function normaliseDataset(Component, dataset) {
188
+ const out = {};
189
+ for (const [field, property] of Object.entries(Component.schema.properties)) {
190
+ if (field in dataset) {
191
+ out[field] = normaliseString(dataset[field], property);
192
+ }
193
+ if ((property == null ? void 0 : property.type) === 'object') {
194
+ out[field] = extractConfigByNamespace(Component, dataset, field);
195
+ }
196
+ }
197
+ return out;
198
+ }
199
+
200
+ class GOVUKFrontendError extends Error {
201
+ constructor(...args) {
202
+ super(...args);
203
+ this.name = 'GOVUKFrontendError';
204
+ }
205
+ }
206
+ class SupportError extends GOVUKFrontendError {
207
+ /**
208
+ * Checks if GOV.UK Frontend is supported on this page
209
+ *
210
+ * @param {HTMLElement | null} [$scope] - HTML element `<body>` checked for browser support
211
+ */
212
+ constructor($scope = document.body) {
213
+ const supportMessage = 'noModule' in HTMLScriptElement.prototype ? 'GOV.UK Frontend initialised without `<body class="govuk-frontend-supported">` from template `<script>` snippet' : 'GOV.UK Frontend is not supported in this browser';
214
+ super($scope ? supportMessage : 'GOV.UK Frontend initialised without `<script type="module">`');
215
+ this.name = 'SupportError';
216
+ }
217
+ }
218
+ class ConfigError extends GOVUKFrontendError {
219
+ constructor(...args) {
220
+ super(...args);
221
+ this.name = 'ConfigError';
222
+ }
223
+ }
224
+ class ElementError extends GOVUKFrontendError {
225
+ constructor(messageOrOptions) {
226
+ let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
227
+ if (typeof messageOrOptions === 'object') {
228
+ const {
229
+ component,
230
+ identifier,
231
+ element,
232
+ expectedType
233
+ } = messageOrOptions;
234
+ message = identifier;
235
+ message += element ? ` is not of type ${expectedType != null ? expectedType : 'HTMLElement'}` : ' not found';
236
+ message = formatErrorMessage(component, message);
237
+ }
238
+ super(message);
239
+ this.name = 'ElementError';
240
+ }
241
+ }
242
+ class InitError extends GOVUKFrontendError {
243
+ constructor(componentOrMessage) {
244
+ const message = typeof componentOrMessage === 'string' ? componentOrMessage : formatErrorMessage(componentOrMessage, `Root element (\`$root\`) already initialised`);
245
+ super(message);
246
+ this.name = 'InitError';
247
+ }
248
+ }
249
+ /**
250
+ * @typedef {import('../common/index.mjs').ComponentWithModuleName} ComponentWithModuleName
251
+ */
252
+
253
+ class GOVUKFrontendComponent {
254
+ /**
255
+ * Returns the root element of the component
256
+ *
257
+ * @protected
258
+ * @returns {RootElementType} - the root element of component
259
+ */
260
+ get $root() {
261
+ return this._$root;
262
+ }
263
+ constructor($root) {
264
+ this._$root = void 0;
265
+ const childConstructor = this.constructor;
266
+ if (typeof childConstructor.moduleName !== 'string') {
267
+ throw new InitError(`\`moduleName\` not defined in component`);
268
+ }
269
+ if (!($root instanceof childConstructor.elementType)) {
270
+ throw new ElementError({
271
+ element: $root,
272
+ component: childConstructor,
273
+ identifier: 'Root element (`$root`)',
274
+ expectedType: childConstructor.elementType.name
275
+ });
276
+ } else {
277
+ this._$root = $root;
278
+ }
279
+ childConstructor.checkSupport();
280
+ this.checkInitialised();
281
+ const moduleName = childConstructor.moduleName;
282
+ this.$root.setAttribute(`data-${moduleName}-init`, '');
283
+ }
284
+ checkInitialised() {
285
+ const constructor = this.constructor;
286
+ const moduleName = constructor.moduleName;
287
+ if (moduleName && isInitialised(this.$root, moduleName)) {
288
+ throw new InitError(constructor);
289
+ }
290
+ }
291
+ static checkSupport() {
292
+ if (!isSupported()) {
293
+ throw new SupportError();
294
+ }
295
+ }
296
+ }
297
+
298
+ /**
299
+ * @typedef ChildClass
300
+ * @property {string} moduleName - The module name that'll be looked for in the DOM when initialising the component
301
+ */
302
+
303
+ /**
304
+ * @typedef {typeof GOVUKFrontendComponent & ChildClass} ChildClassConstructor
305
+ */
306
+ GOVUKFrontendComponent.elementType = HTMLElement;
307
+
308
+ class I18n {
309
+ constructor(translations = {}, config = {}) {
310
+ var _config$locale;
311
+ this.translations = void 0;
312
+ this.locale = void 0;
313
+ this.translations = translations;
314
+ this.locale = (_config$locale = config.locale) != null ? _config$locale : document.documentElement.lang || 'en';
315
+ }
316
+ t(lookupKey, options) {
317
+ if (!lookupKey) {
318
+ throw new Error('i18n: lookup key missing');
319
+ }
320
+ let translation = this.translations[lookupKey];
321
+ if (typeof (options == null ? void 0 : options.count) === 'number' && typeof translation === 'object') {
322
+ const translationPluralForm = translation[this.getPluralSuffix(lookupKey, options.count)];
323
+ if (translationPluralForm) {
324
+ translation = translationPluralForm;
325
+ }
326
+ }
327
+ if (typeof translation === 'string') {
328
+ if (translation.match(/%{(.\S+)}/)) {
329
+ if (!options) {
330
+ throw new Error('i18n: cannot replace placeholders in string if no option data provided');
331
+ }
332
+ return this.replacePlaceholders(translation, options);
333
+ }
334
+ return translation;
335
+ }
336
+ return lookupKey;
337
+ }
338
+ replacePlaceholders(translationString, options) {
339
+ const formatter = Intl.NumberFormat.supportedLocalesOf(this.locale).length ? new Intl.NumberFormat(this.locale) : undefined;
340
+ return translationString.replace(/%{(.\S+)}/g, function (placeholderWithBraces, placeholderKey) {
341
+ if (Object.prototype.hasOwnProperty.call(options, placeholderKey)) {
342
+ const placeholderValue = options[placeholderKey];
343
+ if (placeholderValue === false || typeof placeholderValue !== 'number' && typeof placeholderValue !== 'string') {
344
+ return '';
345
+ }
346
+ if (typeof placeholderValue === 'number') {
347
+ return formatter ? formatter.format(placeholderValue) : `${placeholderValue}`;
348
+ }
349
+ return placeholderValue;
350
+ }
351
+ throw new Error(`i18n: no data found to replace ${placeholderWithBraces} placeholder in string`);
352
+ });
353
+ }
354
+ hasIntlPluralRulesSupport() {
355
+ return Boolean('PluralRules' in window.Intl && Intl.PluralRules.supportedLocalesOf(this.locale).length);
356
+ }
357
+ getPluralSuffix(lookupKey, count) {
358
+ count = Number(count);
359
+ if (!isFinite(count)) {
360
+ return 'other';
361
+ }
362
+ const translation = this.translations[lookupKey];
363
+ const preferredForm = this.hasIntlPluralRulesSupport() ? new Intl.PluralRules(this.locale).select(count) : this.selectPluralFormUsingFallbackRules(count);
364
+ if (typeof translation === 'object') {
365
+ if (preferredForm in translation) {
366
+ return preferredForm;
367
+ } else if ('other' in translation) {
368
+ console.warn(`i18n: Missing plural form ".${preferredForm}" for "${this.locale}" locale. Falling back to ".other".`);
369
+ return 'other';
370
+ }
371
+ }
372
+ throw new Error(`i18n: Plural form ".other" is required for "${this.locale}" locale`);
373
+ }
374
+ selectPluralFormUsingFallbackRules(count) {
375
+ count = Math.abs(Math.floor(count));
376
+ const ruleset = this.getPluralRulesForLocale();
377
+ if (ruleset) {
378
+ return I18n.pluralRules[ruleset](count);
379
+ }
380
+ return 'other';
381
+ }
382
+ getPluralRulesForLocale() {
383
+ const localeShort = this.locale.split('-')[0];
384
+ for (const pluralRule in I18n.pluralRulesMap) {
385
+ const languages = I18n.pluralRulesMap[pluralRule];
386
+ if (languages.includes(this.locale) || languages.includes(localeShort)) {
387
+ return pluralRule;
388
+ }
389
+ }
390
+ }
391
+ }
392
+ I18n.pluralRulesMap = {
393
+ arabic: ['ar'],
394
+ chinese: ['my', 'zh', 'id', 'ja', 'jv', 'ko', 'ms', 'th', 'vi'],
395
+ french: ['hy', 'bn', 'fr', 'gu', 'hi', 'fa', 'pa', 'zu'],
396
+ 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'],
397
+ irish: ['ga'],
398
+ russian: ['ru', 'uk'],
399
+ scottish: ['gd'],
400
+ spanish: ['pt-PT', 'it', 'es'],
401
+ welsh: ['cy']
402
+ };
403
+ I18n.pluralRules = {
404
+ arabic(n) {
405
+ if (n === 0) {
406
+ return 'zero';
407
+ }
408
+ if (n === 1) {
409
+ return 'one';
410
+ }
411
+ if (n === 2) {
412
+ return 'two';
413
+ }
414
+ if (n % 100 >= 3 && n % 100 <= 10) {
415
+ return 'few';
416
+ }
417
+ if (n % 100 >= 11 && n % 100 <= 99) {
418
+ return 'many';
419
+ }
420
+ return 'other';
421
+ },
422
+ chinese() {
423
+ return 'other';
424
+ },
425
+ french(n) {
426
+ return n === 0 || n === 1 ? 'one' : 'other';
427
+ },
428
+ german(n) {
429
+ return n === 1 ? 'one' : 'other';
430
+ },
431
+ irish(n) {
432
+ if (n === 1) {
433
+ return 'one';
434
+ }
435
+ if (n === 2) {
436
+ return 'two';
437
+ }
438
+ if (n >= 3 && n <= 6) {
439
+ return 'few';
440
+ }
441
+ if (n >= 7 && n <= 10) {
442
+ return 'many';
443
+ }
444
+ return 'other';
445
+ },
446
+ russian(n) {
447
+ const lastTwo = n % 100;
448
+ const last = lastTwo % 10;
449
+ if (last === 1 && lastTwo !== 11) {
450
+ return 'one';
451
+ }
452
+ if (last >= 2 && last <= 4 && !(lastTwo >= 12 && lastTwo <= 14)) {
453
+ return 'few';
454
+ }
455
+ if (last === 0 || last >= 5 && last <= 9 || lastTwo >= 11 && lastTwo <= 14) {
456
+ return 'many';
457
+ }
458
+ return 'other';
459
+ },
460
+ scottish(n) {
461
+ if (n === 1 || n === 11) {
462
+ return 'one';
463
+ }
464
+ if (n === 2 || n === 12) {
465
+ return 'two';
466
+ }
467
+ if (n >= 3 && n <= 10 || n >= 13 && n <= 19) {
468
+ return 'few';
469
+ }
470
+ return 'other';
471
+ },
472
+ spanish(n) {
473
+ if (n === 1) {
474
+ return 'one';
475
+ }
476
+ if (n % 1000000 === 0 && n !== 0) {
477
+ return 'many';
478
+ }
479
+ return 'other';
480
+ },
481
+ welsh(n) {
482
+ if (n === 0) {
483
+ return 'zero';
484
+ }
485
+ if (n === 1) {
486
+ return 'one';
487
+ }
488
+ if (n === 2) {
489
+ return 'two';
490
+ }
491
+ if (n === 3) {
492
+ return 'few';
493
+ }
494
+ if (n === 6) {
495
+ return 'many';
496
+ }
497
+ return 'other';
498
+ }
499
+ };
500
+
501
+ /**
502
+ * Accordion component
503
+ *
504
+ * This allows a collection of sections to be collapsed by default, showing only
505
+ * their headers. Sections can be expanded or collapsed individually by clicking
506
+ * their headers. A "Show all sections" button is also added to the top of the
507
+ * accordion, which switches to "Hide all sections" when all the sections are
508
+ * expanded.
509
+ *
510
+ * The state of each section is saved to the DOM via the `aria-expanded`
511
+ * attribute, which also provides accessibility.
512
+ *
513
+ * @preserve
514
+ */
515
+ class Accordion extends GOVUKFrontendComponent {
516
+ /**
517
+ * @param {Element | null} $root - HTML element to use for accordion
518
+ * @param {AccordionConfig} [config] - Accordion config
519
+ */
520
+ constructor($root, config = {}) {
521
+ super($root);
522
+ this.config = void 0;
523
+ this.i18n = void 0;
524
+ this.controlsClass = 'govuk-accordion__controls';
525
+ this.showAllClass = 'govuk-accordion__show-all';
526
+ this.showAllTextClass = 'govuk-accordion__show-all-text';
527
+ this.sectionClass = 'govuk-accordion__section';
528
+ this.sectionExpandedClass = 'govuk-accordion__section--expanded';
529
+ this.sectionButtonClass = 'govuk-accordion__section-button';
530
+ this.sectionHeaderClass = 'govuk-accordion__section-header';
531
+ this.sectionHeadingClass = 'govuk-accordion__section-heading';
532
+ this.sectionHeadingDividerClass = 'govuk-accordion__section-heading-divider';
533
+ this.sectionHeadingTextClass = 'govuk-accordion__section-heading-text';
534
+ this.sectionHeadingTextFocusClass = 'govuk-accordion__section-heading-text-focus';
535
+ this.sectionShowHideToggleClass = 'govuk-accordion__section-toggle';
536
+ this.sectionShowHideToggleFocusClass = 'govuk-accordion__section-toggle-focus';
537
+ this.sectionShowHideTextClass = 'govuk-accordion__section-toggle-text';
538
+ this.upChevronIconClass = 'govuk-accordion-nav__chevron';
539
+ this.downChevronIconClass = 'govuk-accordion-nav__chevron--down';
540
+ this.sectionSummaryClass = 'govuk-accordion__section-summary';
541
+ this.sectionSummaryFocusClass = 'govuk-accordion__section-summary-focus';
542
+ this.sectionContentClass = 'govuk-accordion__section-content';
543
+ this.$sections = void 0;
544
+ this.$showAllButton = null;
545
+ this.$showAllIcon = null;
546
+ this.$showAllText = null;
547
+ this.config = mergeConfigs(Accordion.defaults, config, normaliseDataset(Accordion, this.$root.dataset));
548
+ this.i18n = new I18n(this.config.i18n);
549
+ const $sections = this.$root.querySelectorAll(`.${this.sectionClass}`);
550
+ if (!$sections.length) {
551
+ throw new ElementError({
552
+ component: Accordion,
553
+ identifier: `Sections (\`<div class="${this.sectionClass}">\`)`
554
+ });
555
+ }
556
+ this.$sections = $sections;
557
+ this.initControls();
558
+ this.initSectionHeaders();
559
+ this.updateShowAllButton(this.areAllSectionsOpen());
560
+ }
561
+ initControls() {
562
+ this.$showAllButton = document.createElement('button');
563
+ this.$showAllButton.setAttribute('type', 'button');
564
+ this.$showAllButton.setAttribute('class', this.showAllClass);
565
+ this.$showAllButton.setAttribute('aria-expanded', 'false');
566
+ this.$showAllIcon = document.createElement('span');
567
+ this.$showAllIcon.classList.add(this.upChevronIconClass);
568
+ this.$showAllButton.appendChild(this.$showAllIcon);
569
+ const $accordionControls = document.createElement('div');
570
+ $accordionControls.setAttribute('class', this.controlsClass);
571
+ $accordionControls.appendChild(this.$showAllButton);
572
+ this.$root.insertBefore($accordionControls, this.$root.firstChild);
573
+ this.$showAllText = document.createElement('span');
574
+ this.$showAllText.classList.add(this.showAllTextClass);
575
+ this.$showAllButton.appendChild(this.$showAllText);
576
+ this.$showAllButton.addEventListener('click', () => this.onShowOrHideAllToggle());
577
+ if ('onbeforematch' in document) {
578
+ document.addEventListener('beforematch', event => this.onBeforeMatch(event));
579
+ }
580
+ }
581
+ initSectionHeaders() {
582
+ this.$sections.forEach(($section, i) => {
583
+ const $header = $section.querySelector(`.${this.sectionHeaderClass}`);
584
+ if (!$header) {
585
+ throw new ElementError({
586
+ component: Accordion,
587
+ identifier: `Section headers (\`<div class="${this.sectionHeaderClass}">\`)`
588
+ });
589
+ }
590
+ this.constructHeaderMarkup($header, i);
591
+ this.setExpanded(this.isExpanded($section), $section);
592
+ $header.addEventListener('click', () => this.onSectionToggle($section));
593
+ this.setInitialState($section);
594
+ });
595
+ }
596
+ constructHeaderMarkup($header, index) {
597
+ const $span = $header.querySelector(`.${this.sectionButtonClass}`);
598
+ const $heading = $header.querySelector(`.${this.sectionHeadingClass}`);
599
+ const $summary = $header.querySelector(`.${this.sectionSummaryClass}`);
600
+ if (!$heading) {
601
+ throw new ElementError({
602
+ component: Accordion,
603
+ identifier: `Section heading (\`.${this.sectionHeadingClass}\`)`
604
+ });
605
+ }
606
+ if (!$span) {
607
+ throw new ElementError({
608
+ component: Accordion,
609
+ identifier: `Section button placeholder (\`<span class="${this.sectionButtonClass}">\`)`
610
+ });
611
+ }
612
+ const $button = document.createElement('button');
613
+ $button.setAttribute('type', 'button');
614
+ $button.setAttribute('aria-controls', `${this.$root.id}-content-${index + 1}`);
615
+ for (const attr of Array.from($span.attributes)) {
616
+ if (attr.name !== 'id') {
617
+ $button.setAttribute(attr.name, attr.value);
618
+ }
619
+ }
620
+ const $headingText = document.createElement('span');
621
+ $headingText.classList.add(this.sectionHeadingTextClass);
622
+ $headingText.id = $span.id;
623
+ const $headingTextFocus = document.createElement('span');
624
+ $headingTextFocus.classList.add(this.sectionHeadingTextFocusClass);
625
+ $headingText.appendChild($headingTextFocus);
626
+ Array.from($span.childNodes).forEach($child => $headingTextFocus.appendChild($child));
627
+ const $showHideToggle = document.createElement('span');
628
+ $showHideToggle.classList.add(this.sectionShowHideToggleClass);
629
+ $showHideToggle.setAttribute('data-nosnippet', '');
630
+ const $showHideToggleFocus = document.createElement('span');
631
+ $showHideToggleFocus.classList.add(this.sectionShowHideToggleFocusClass);
632
+ $showHideToggle.appendChild($showHideToggleFocus);
633
+ const $showHideText = document.createElement('span');
634
+ const $showHideIcon = document.createElement('span');
635
+ $showHideIcon.classList.add(this.upChevronIconClass);
636
+ $showHideToggleFocus.appendChild($showHideIcon);
637
+ $showHideText.classList.add(this.sectionShowHideTextClass);
638
+ $showHideToggleFocus.appendChild($showHideText);
639
+ $button.appendChild($headingText);
640
+ $button.appendChild(this.getButtonPunctuationEl());
641
+ if ($summary) {
642
+ const $summarySpan = document.createElement('span');
643
+ const $summarySpanFocus = document.createElement('span');
644
+ $summarySpanFocus.classList.add(this.sectionSummaryFocusClass);
645
+ $summarySpan.appendChild($summarySpanFocus);
646
+ for (const attr of Array.from($summary.attributes)) {
647
+ $summarySpan.setAttribute(attr.name, attr.value);
648
+ }
649
+ Array.from($summary.childNodes).forEach($child => $summarySpanFocus.appendChild($child));
650
+ $summary.remove();
651
+ $button.appendChild($summarySpan);
652
+ $button.appendChild(this.getButtonPunctuationEl());
653
+ }
654
+ $button.appendChild($showHideToggle);
655
+ $heading.removeChild($span);
656
+ $heading.appendChild($button);
657
+ }
658
+ onBeforeMatch(event) {
659
+ const $fragment = event.target;
660
+ if (!($fragment instanceof Element)) {
661
+ return;
662
+ }
663
+ const $section = $fragment.closest(`.${this.sectionClass}`);
664
+ if ($section) {
665
+ this.setExpanded(true, $section);
666
+ }
667
+ }
668
+ onSectionToggle($section) {
669
+ const nowExpanded = !this.isExpanded($section);
670
+ this.setExpanded(nowExpanded, $section);
671
+ this.storeState($section, nowExpanded);
672
+ }
673
+ onShowOrHideAllToggle() {
674
+ const nowExpanded = !this.areAllSectionsOpen();
675
+ this.$sections.forEach($section => {
676
+ this.setExpanded(nowExpanded, $section);
677
+ this.storeState($section, nowExpanded);
678
+ });
679
+ this.updateShowAllButton(nowExpanded);
680
+ }
681
+ setExpanded(expanded, $section) {
682
+ const $showHideIcon = $section.querySelector(`.${this.upChevronIconClass}`);
683
+ const $showHideText = $section.querySelector(`.${this.sectionShowHideTextClass}`);
684
+ const $button = $section.querySelector(`.${this.sectionButtonClass}`);
685
+ const $content = $section.querySelector(`.${this.sectionContentClass}`);
686
+ if (!$content) {
687
+ throw new ElementError({
688
+ component: Accordion,
689
+ identifier: `Section content (\`<div class="${this.sectionContentClass}">\`)`
690
+ });
691
+ }
692
+ if (!$showHideIcon || !$showHideText || !$button) {
693
+ return;
694
+ }
695
+ const newButtonText = expanded ? this.i18n.t('hideSection') : this.i18n.t('showSection');
696
+ $showHideText.textContent = newButtonText;
697
+ $button.setAttribute('aria-expanded', `${expanded}`);
698
+ const ariaLabelParts = [];
699
+ const $headingText = $section.querySelector(`.${this.sectionHeadingTextClass}`);
700
+ if ($headingText) {
701
+ ariaLabelParts.push(`${$headingText.textContent}`.trim());
702
+ }
703
+ const $summary = $section.querySelector(`.${this.sectionSummaryClass}`);
704
+ if ($summary) {
705
+ ariaLabelParts.push(`${$summary.textContent}`.trim());
706
+ }
707
+ const ariaLabelMessage = expanded ? this.i18n.t('hideSectionAriaLabel') : this.i18n.t('showSectionAriaLabel');
708
+ ariaLabelParts.push(ariaLabelMessage);
709
+ $button.setAttribute('aria-label', ariaLabelParts.join(' , '));
710
+ if (expanded) {
711
+ $content.removeAttribute('hidden');
712
+ $section.classList.add(this.sectionExpandedClass);
713
+ $showHideIcon.classList.remove(this.downChevronIconClass);
714
+ } else {
715
+ $content.setAttribute('hidden', 'until-found');
716
+ $section.classList.remove(this.sectionExpandedClass);
717
+ $showHideIcon.classList.add(this.downChevronIconClass);
718
+ }
719
+ this.updateShowAllButton(this.areAllSectionsOpen());
720
+ }
721
+ isExpanded($section) {
722
+ return $section.classList.contains(this.sectionExpandedClass);
723
+ }
724
+ areAllSectionsOpen() {
725
+ return Array.from(this.$sections).every($section => this.isExpanded($section));
726
+ }
727
+ updateShowAllButton(expanded) {
728
+ if (!this.$showAllButton || !this.$showAllText || !this.$showAllIcon) {
729
+ return;
730
+ }
731
+ this.$showAllButton.setAttribute('aria-expanded', expanded.toString());
732
+ this.$showAllText.textContent = expanded ? this.i18n.t('hideAllSections') : this.i18n.t('showAllSections');
733
+ this.$showAllIcon.classList.toggle(this.downChevronIconClass, !expanded);
734
+ }
735
+
736
+ /**
737
+ * Get the identifier for a section
738
+ *
739
+ * We need a unique way of identifying each content in the Accordion.
740
+ * Since an `#id` should be unique and an `id` is required for `aria-`
741
+ * attributes `id` can be safely used.
742
+ *
743
+ * @param {Element} $section - Section element
744
+ * @returns {string | undefined | null} Identifier for section
745
+ */
746
+ getIdentifier($section) {
747
+ const $button = $section.querySelector(`.${this.sectionButtonClass}`);
748
+ return $button == null ? void 0 : $button.getAttribute('aria-controls');
749
+ }
750
+ storeState($section, isExpanded) {
751
+ if (!this.config.rememberExpanded) {
752
+ return;
753
+ }
754
+ const id = this.getIdentifier($section);
755
+ if (id) {
756
+ try {
757
+ window.sessionStorage.setItem(id, isExpanded.toString());
758
+ } catch (exception) {}
759
+ }
760
+ }
761
+ setInitialState($section) {
762
+ if (!this.config.rememberExpanded) {
763
+ return;
764
+ }
765
+ const id = this.getIdentifier($section);
766
+ if (id) {
767
+ try {
768
+ const state = window.sessionStorage.getItem(id);
769
+ if (state !== null) {
770
+ this.setExpanded(state === 'true', $section);
771
+ }
772
+ } catch (exception) {}
773
+ }
774
+ }
775
+ getButtonPunctuationEl() {
776
+ const $punctuationEl = document.createElement('span');
777
+ $punctuationEl.classList.add('govuk-visually-hidden', this.sectionHeadingDividerClass);
778
+ $punctuationEl.textContent = ', ';
779
+ return $punctuationEl;
780
+ }
781
+ }
782
+
783
+ /**
784
+ * Accordion config
785
+ *
786
+ * @see {@link Accordion.defaults}
787
+ * @typedef {object} AccordionConfig
788
+ * @property {AccordionTranslations} [i18n=Accordion.defaults.i18n] - Accordion translations
789
+ * @property {boolean} [rememberExpanded] - Whether the expanded and collapsed
790
+ * state of each section is remembered and restored when navigating.
791
+ */
792
+
793
+ /**
794
+ * Accordion translations
795
+ *
796
+ * @see {@link Accordion.defaults.i18n}
797
+ * @typedef {object} AccordionTranslations
798
+ *
799
+ * Messages used by the component for the labels of its buttons. This includes
800
+ * the visible text shown on screen, and text to help assistive technology users
801
+ * for the buttons toggling each section.
802
+ * @property {string} [hideAllSections] - The text content for the 'Hide all
803
+ * sections' button, used when at least one section is expanded.
804
+ * @property {string} [hideSection] - The text content for the 'Hide'
805
+ * button, used when a section is expanded.
806
+ * @property {string} [hideSectionAriaLabel] - The text content appended to the
807
+ * 'Hide' button's accessible name when a section is expanded.
808
+ * @property {string} [showAllSections] - The text content for the 'Show all
809
+ * sections' button, used when all sections are collapsed.
810
+ * @property {string} [showSection] - The text content for the 'Show'
811
+ * button, used when a section is collapsed.
812
+ * @property {string} [showSectionAriaLabel] - The text content appended to the
813
+ * 'Show' button's accessible name when a section is expanded.
814
+ */
815
+
816
+ /**
817
+ * @typedef {import('../../common/index.mjs').Schema} Schema
818
+ */
819
+ Accordion.moduleName = 'govuk-accordion';
820
+ Accordion.defaults = Object.freeze({
821
+ i18n: {
822
+ hideAllSections: 'Hide all sections',
823
+ hideSection: 'Hide',
824
+ hideSectionAriaLabel: 'Hide this section',
825
+ showAllSections: 'Show all sections',
826
+ showSection: 'Show',
827
+ showSectionAriaLabel: 'Show this section'
828
+ },
829
+ rememberExpanded: true
830
+ });
831
+ Accordion.schema = Object.freeze({
832
+ properties: {
833
+ i18n: {
834
+ type: 'object'
835
+ },
836
+ rememberExpanded: {
837
+ type: 'boolean'
838
+ }
839
+ }
840
+ });
841
+
842
+ const DEBOUNCE_TIMEOUT_IN_SECONDS = 1;
843
+
844
+ /**
845
+ * JavaScript enhancements for the Button component
846
+ *
847
+ * @preserve
848
+ */
849
+ class Button extends GOVUKFrontendComponent {
850
+ /**
851
+ * @param {Element | null} $root - HTML element to use for button
852
+ * @param {ButtonConfig} [config] - Button config
853
+ */
854
+ constructor($root, config = {}) {
855
+ super($root);
856
+ this.config = void 0;
857
+ this.debounceFormSubmitTimer = null;
858
+ this.config = mergeConfigs(Button.defaults, config, normaliseDataset(Button, this.$root.dataset));
859
+ this.$root.addEventListener('keydown', event => this.handleKeyDown(event));
860
+ this.$root.addEventListener('click', event => this.debounce(event));
861
+ }
862
+ handleKeyDown(event) {
863
+ const $target = event.target;
864
+ if (event.key !== ' ') {
865
+ return;
866
+ }
867
+ if ($target instanceof HTMLElement && $target.getAttribute('role') === 'button') {
868
+ event.preventDefault();
869
+ $target.click();
870
+ }
871
+ }
872
+ debounce(event) {
873
+ if (!this.config.preventDoubleClick) {
874
+ return;
875
+ }
876
+ if (this.debounceFormSubmitTimer) {
877
+ event.preventDefault();
878
+ return false;
879
+ }
880
+ this.debounceFormSubmitTimer = window.setTimeout(() => {
881
+ this.debounceFormSubmitTimer = null;
882
+ }, DEBOUNCE_TIMEOUT_IN_SECONDS * 1000);
883
+ }
884
+ }
885
+
886
+ /**
887
+ * Button config
888
+ *
889
+ * @typedef {object} ButtonConfig
890
+ * @property {boolean} [preventDoubleClick=false] - Prevent accidental double
891
+ * clicks on submit buttons from submitting forms multiple times.
892
+ */
893
+
894
+ /**
895
+ * @typedef {import('../../common/index.mjs').Schema} Schema
896
+ */
897
+ Button.moduleName = 'govuk-button';
898
+ Button.defaults = Object.freeze({
899
+ preventDoubleClick: false
900
+ });
901
+ Button.schema = Object.freeze({
902
+ properties: {
903
+ preventDoubleClick: {
904
+ type: 'boolean'
905
+ }
906
+ }
907
+ });
908
+
909
+ function closestAttributeValue($element, attributeName) {
910
+ const $closestElementWithAttribute = $element.closest(`[${attributeName}]`);
911
+ return $closestElementWithAttribute ? $closestElementWithAttribute.getAttribute(attributeName) : null;
912
+ }
913
+
914
+ /**
915
+ * Character count component
916
+ *
917
+ * Tracks the number of characters or words in the `.govuk-js-character-count`
918
+ * `<textarea>` inside the element. Displays a message with the remaining number
919
+ * of characters/words available, or the number of characters/words in excess.
920
+ *
921
+ * You can configure the message to only appear after a certain percentage
922
+ * of the available characters/words has been entered.
923
+ *
924
+ * @preserve
925
+ */
926
+ class CharacterCount extends GOVUKFrontendComponent {
927
+ /**
928
+ * @param {Element | null} $root - HTML element to use for character count
929
+ * @param {CharacterCountConfig} [config] - Character count config
930
+ */
931
+ constructor($root, config = {}) {
932
+ var _ref, _this$config$maxwords;
933
+ super($root);
934
+ this.$textarea = void 0;
935
+ this.$visibleCountMessage = void 0;
936
+ this.$screenReaderCountMessage = void 0;
937
+ this.lastInputTimestamp = null;
938
+ this.lastInputValue = '';
939
+ this.valueChecker = null;
940
+ this.config = void 0;
941
+ this.i18n = void 0;
942
+ this.maxLength = void 0;
943
+ const $textarea = this.$root.querySelector('.govuk-js-character-count');
944
+ if (!($textarea instanceof HTMLTextAreaElement || $textarea instanceof HTMLInputElement)) {
945
+ throw new ElementError({
946
+ component: CharacterCount,
947
+ element: $textarea,
948
+ expectedType: 'HTMLTextareaElement or HTMLInputElement',
949
+ identifier: 'Form field (`.govuk-js-character-count`)'
950
+ });
951
+ }
952
+ const datasetConfig = normaliseDataset(CharacterCount, this.$root.dataset);
953
+ let configOverrides = {};
954
+ if ('maxwords' in datasetConfig || 'maxlength' in datasetConfig) {
955
+ configOverrides = {
956
+ maxlength: undefined,
957
+ maxwords: undefined
958
+ };
959
+ }
960
+ this.config = mergeConfigs(CharacterCount.defaults, config, configOverrides, datasetConfig);
961
+ const errors = validateConfig(CharacterCount.schema, this.config);
962
+ if (errors[0]) {
963
+ throw new ConfigError(formatErrorMessage(CharacterCount, errors[0]));
964
+ }
965
+ this.i18n = new I18n(this.config.i18n, {
966
+ locale: closestAttributeValue(this.$root, 'lang')
967
+ });
968
+ this.maxLength = (_ref = (_this$config$maxwords = this.config.maxwords) != null ? _this$config$maxwords : this.config.maxlength) != null ? _ref : Infinity;
969
+ this.$textarea = $textarea;
970
+ const textareaDescriptionId = `${this.$textarea.id}-info`;
971
+ const $textareaDescription = document.getElementById(textareaDescriptionId);
972
+ if (!$textareaDescription) {
973
+ throw new ElementError({
974
+ component: CharacterCount,
975
+ element: $textareaDescription,
976
+ identifier: `Count message (\`id="${textareaDescriptionId}"\`)`
977
+ });
978
+ }
979
+ if (`${$textareaDescription.textContent}`.match(/^\s*$/)) {
980
+ $textareaDescription.textContent = this.i18n.t('textareaDescription', {
981
+ count: this.maxLength
982
+ });
983
+ }
984
+ this.$textarea.insertAdjacentElement('afterend', $textareaDescription);
985
+ const $screenReaderCountMessage = document.createElement('div');
986
+ $screenReaderCountMessage.className = 'govuk-character-count__sr-status govuk-visually-hidden';
987
+ $screenReaderCountMessage.setAttribute('aria-live', 'polite');
988
+ this.$screenReaderCountMessage = $screenReaderCountMessage;
989
+ $textareaDescription.insertAdjacentElement('afterend', $screenReaderCountMessage);
990
+ const $visibleCountMessage = document.createElement('div');
991
+ $visibleCountMessage.className = $textareaDescription.className;
992
+ $visibleCountMessage.classList.add('govuk-character-count__status');
993
+ $visibleCountMessage.setAttribute('aria-hidden', 'true');
994
+ this.$visibleCountMessage = $visibleCountMessage;
995
+ $textareaDescription.insertAdjacentElement('afterend', $visibleCountMessage);
996
+ $textareaDescription.classList.add('govuk-visually-hidden');
997
+ this.$textarea.removeAttribute('maxlength');
998
+ this.bindChangeEvents();
999
+ window.addEventListener('pageshow', () => this.updateCountMessage());
1000
+ this.updateCountMessage();
1001
+ }
1002
+ bindChangeEvents() {
1003
+ this.$textarea.addEventListener('keyup', () => this.handleKeyUp());
1004
+ this.$textarea.addEventListener('focus', () => this.handleFocus());
1005
+ this.$textarea.addEventListener('blur', () => this.handleBlur());
1006
+ }
1007
+ handleKeyUp() {
1008
+ this.updateVisibleCountMessage();
1009
+ this.lastInputTimestamp = Date.now();
1010
+ }
1011
+ handleFocus() {
1012
+ this.valueChecker = window.setInterval(() => {
1013
+ if (!this.lastInputTimestamp || Date.now() - 500 >= this.lastInputTimestamp) {
1014
+ this.updateIfValueChanged();
1015
+ }
1016
+ }, 1000);
1017
+ }
1018
+ handleBlur() {
1019
+ if (this.valueChecker) {
1020
+ window.clearInterval(this.valueChecker);
1021
+ }
1022
+ }
1023
+ updateIfValueChanged() {
1024
+ if (this.$textarea.value !== this.lastInputValue) {
1025
+ this.lastInputValue = this.$textarea.value;
1026
+ this.updateCountMessage();
1027
+ }
1028
+ }
1029
+ updateCountMessage() {
1030
+ this.updateVisibleCountMessage();
1031
+ this.updateScreenReaderCountMessage();
1032
+ }
1033
+ updateVisibleCountMessage() {
1034
+ const remainingNumber = this.maxLength - this.count(this.$textarea.value);
1035
+ const isError = remainingNumber < 0;
1036
+ this.$visibleCountMessage.classList.toggle('govuk-character-count__message--disabled', !this.isOverThreshold());
1037
+ this.$textarea.classList.toggle('govuk-textarea--error', isError);
1038
+ this.$visibleCountMessage.classList.toggle('govuk-error-message', isError);
1039
+ this.$visibleCountMessage.classList.toggle('govuk-hint', !isError);
1040
+ this.$visibleCountMessage.textContent = this.getCountMessage();
1041
+ }
1042
+ updateScreenReaderCountMessage() {
1043
+ if (this.isOverThreshold()) {
1044
+ this.$screenReaderCountMessage.removeAttribute('aria-hidden');
1045
+ } else {
1046
+ this.$screenReaderCountMessage.setAttribute('aria-hidden', 'true');
1047
+ }
1048
+ this.$screenReaderCountMessage.textContent = this.getCountMessage();
1049
+ }
1050
+ count(text) {
1051
+ if (this.config.maxwords) {
1052
+ var _text$match;
1053
+ const tokens = (_text$match = text.match(/\S+/g)) != null ? _text$match : [];
1054
+ return tokens.length;
1055
+ }
1056
+ return text.length;
1057
+ }
1058
+ getCountMessage() {
1059
+ const remainingNumber = this.maxLength - this.count(this.$textarea.value);
1060
+ const countType = this.config.maxwords ? 'words' : 'characters';
1061
+ return this.formatCountMessage(remainingNumber, countType);
1062
+ }
1063
+ formatCountMessage(remainingNumber, countType) {
1064
+ if (remainingNumber === 0) {
1065
+ return this.i18n.t(`${countType}AtLimit`);
1066
+ }
1067
+ const translationKeySuffix = remainingNumber < 0 ? 'OverLimit' : 'UnderLimit';
1068
+ return this.i18n.t(`${countType}${translationKeySuffix}`, {
1069
+ count: Math.abs(remainingNumber)
1070
+ });
1071
+ }
1072
+ isOverThreshold() {
1073
+ if (!this.config.threshold) {
1074
+ return true;
1075
+ }
1076
+ const currentLength = this.count(this.$textarea.value);
1077
+ const maxLength = this.maxLength;
1078
+ const thresholdValue = maxLength * this.config.threshold / 100;
1079
+ return thresholdValue <= currentLength;
1080
+ }
1081
+ }
1082
+
1083
+ /**
1084
+ * Character count config
1085
+ *
1086
+ * @see {@link CharacterCount.defaults}
1087
+ * @typedef {object} CharacterCountConfig
1088
+ * @property {number} [maxlength] - The maximum number of characters.
1089
+ * If maxwords is provided, the maxlength option will be ignored.
1090
+ * @property {number} [maxwords] - The maximum number of words. If maxwords is
1091
+ * provided, the maxlength option will be ignored.
1092
+ * @property {number} [threshold=0] - The percentage value of the limit at
1093
+ * which point the count message is displayed. If this attribute is set, the
1094
+ * count message will be hidden by default.
1095
+ * @property {CharacterCountTranslations} [i18n=CharacterCount.defaults.i18n] - Character count translations
1096
+ */
1097
+
1098
+ /**
1099
+ * Character count translations
1100
+ *
1101
+ * @see {@link CharacterCount.defaults.i18n}
1102
+ * @typedef {object} CharacterCountTranslations
1103
+ *
1104
+ * Messages shown to users as they type. It provides feedback on how many words
1105
+ * or characters they have remaining or if they are over the limit. This also
1106
+ * includes a message used as an accessible description for the textarea.
1107
+ * @property {TranslationPluralForms} [charactersUnderLimit] - Message displayed
1108
+ * when the number of characters is under the configured maximum, `maxlength`.
1109
+ * This message is displayed visually and through assistive technologies. The
1110
+ * component will replace the `%{count}` placeholder with the number of
1111
+ * remaining characters. This is a [pluralised list of
1112
+ * messages](https://frontend.design-system.service.gov.uk/localise-govuk-frontend).
1113
+ * @property {string} [charactersAtLimit] - Message displayed when the number of
1114
+ * characters reaches the configured maximum, `maxlength`. This message is
1115
+ * displayed visually and through assistive technologies.
1116
+ * @property {TranslationPluralForms} [charactersOverLimit] - Message displayed
1117
+ * when the number of characters is over the configured maximum, `maxlength`.
1118
+ * This message is displayed visually and through assistive technologies. The
1119
+ * component will replace the `%{count}` placeholder with the number of
1120
+ * remaining characters. This is a [pluralised list of
1121
+ * messages](https://frontend.design-system.service.gov.uk/localise-govuk-frontend).
1122
+ * @property {TranslationPluralForms} [wordsUnderLimit] - Message displayed when
1123
+ * the number of words is under the configured maximum, `maxlength`. This
1124
+ * message is displayed visually and through assistive technologies. The
1125
+ * component will replace the `%{count}` placeholder with the number of
1126
+ * remaining words. This is a [pluralised list of
1127
+ * messages](https://frontend.design-system.service.gov.uk/localise-govuk-frontend).
1128
+ * @property {string} [wordsAtLimit] - Message displayed when the number of
1129
+ * words reaches the configured maximum, `maxlength`. This message is
1130
+ * displayed visually and through assistive technologies.
1131
+ * @property {TranslationPluralForms} [wordsOverLimit] - Message displayed when
1132
+ * the number of words is over the configured maximum, `maxlength`. This
1133
+ * message is displayed visually and through assistive technologies. The
1134
+ * component will replace the `%{count}` placeholder with the number of
1135
+ * remaining words. This is a [pluralised list of
1136
+ * messages](https://frontend.design-system.service.gov.uk/localise-govuk-frontend).
1137
+ * @property {TranslationPluralForms} [textareaDescription] - Message made
1138
+ * available to assistive technologies, if none is already present in the
1139
+ * HTML, to describe that the component accepts only a limited amount of
1140
+ * content. It is visible on the page when JavaScript is unavailable. The
1141
+ * component will replace the `%{count}` placeholder with the value of the
1142
+ * `maxlength` or `maxwords` parameter.
1143
+ */
1144
+
1145
+ /**
1146
+ * @typedef {import('../../common/index.mjs').Schema} Schema
1147
+ * @typedef {import('../../i18n.mjs').TranslationPluralForms} TranslationPluralForms
1148
+ */
1149
+ CharacterCount.moduleName = 'govuk-character-count';
1150
+ CharacterCount.defaults = Object.freeze({
1151
+ threshold: 0,
1152
+ i18n: {
1153
+ charactersUnderLimit: {
1154
+ one: 'You have %{count} character remaining',
1155
+ other: 'You have %{count} characters remaining'
1156
+ },
1157
+ charactersAtLimit: 'You have 0 characters remaining',
1158
+ charactersOverLimit: {
1159
+ one: 'You have %{count} character too many',
1160
+ other: 'You have %{count} characters too many'
1161
+ },
1162
+ wordsUnderLimit: {
1163
+ one: 'You have %{count} word remaining',
1164
+ other: 'You have %{count} words remaining'
1165
+ },
1166
+ wordsAtLimit: 'You have 0 words remaining',
1167
+ wordsOverLimit: {
1168
+ one: 'You have %{count} word too many',
1169
+ other: 'You have %{count} words too many'
1170
+ },
1171
+ textareaDescription: {
1172
+ other: ''
1173
+ }
1174
+ }
1175
+ });
1176
+ CharacterCount.schema = Object.freeze({
1177
+ properties: {
1178
+ i18n: {
1179
+ type: 'object'
1180
+ },
1181
+ maxwords: {
1182
+ type: 'number'
1183
+ },
1184
+ maxlength: {
1185
+ type: 'number'
1186
+ },
1187
+ threshold: {
1188
+ type: 'number'
1189
+ }
1190
+ },
1191
+ anyOf: [{
1192
+ required: ['maxwords'],
1193
+ errorMessage: 'Either "maxlength" or "maxwords" must be provided'
1194
+ }, {
1195
+ required: ['maxlength'],
1196
+ errorMessage: 'Either "maxlength" or "maxwords" must be provided'
1197
+ }]
1198
+ });
1199
+
1200
+ /**
1201
+ * Checkboxes component
1202
+ *
1203
+ * @preserve
1204
+ */
1205
+ class Checkboxes extends GOVUKFrontendComponent {
1206
+ /**
1207
+ * Checkboxes can be associated with a 'conditionally revealed' content block
1208
+ * – for example, a checkbox for 'Phone' could reveal an additional form field
1209
+ * for the user to enter their phone number.
1210
+ *
1211
+ * These associations are made using a `data-aria-controls` attribute, which
1212
+ * is promoted to an aria-controls attribute during initialisation.
1213
+ *
1214
+ * We also need to restore the state of any conditional reveals on the page
1215
+ * (for example if the user has navigated back), and set up event handlers to
1216
+ * keep the reveal in sync with the checkbox state.
1217
+ *
1218
+ * @param {Element | null} $root - HTML element to use for checkboxes
1219
+ */
1220
+ constructor($root) {
1221
+ super($root);
1222
+ this.$inputs = void 0;
1223
+ const $inputs = this.$root.querySelectorAll('input[type="checkbox"]');
1224
+ if (!$inputs.length) {
1225
+ throw new ElementError({
1226
+ component: Checkboxes,
1227
+ identifier: 'Form inputs (`<input type="checkbox">`)'
1228
+ });
1229
+ }
1230
+ this.$inputs = $inputs;
1231
+ this.$inputs.forEach($input => {
1232
+ const targetId = $input.getAttribute('data-aria-controls');
1233
+ if (!targetId) {
1234
+ return;
1235
+ }
1236
+ if (!document.getElementById(targetId)) {
1237
+ throw new ElementError({
1238
+ component: Checkboxes,
1239
+ identifier: `Conditional reveal (\`id="${targetId}"\`)`
1240
+ });
1241
+ }
1242
+ $input.setAttribute('aria-controls', targetId);
1243
+ $input.removeAttribute('data-aria-controls');
1244
+ });
1245
+ window.addEventListener('pageshow', () => this.syncAllConditionalReveals());
1246
+ this.syncAllConditionalReveals();
1247
+ this.$root.addEventListener('click', event => this.handleClick(event));
1248
+ }
1249
+ syncAllConditionalReveals() {
1250
+ this.$inputs.forEach($input => this.syncConditionalRevealWithInputState($input));
1251
+ }
1252
+ syncConditionalRevealWithInputState($input) {
1253
+ const targetId = $input.getAttribute('aria-controls');
1254
+ if (!targetId) {
1255
+ return;
1256
+ }
1257
+ const $target = document.getElementById(targetId);
1258
+ if ($target != null && $target.classList.contains('govuk-checkboxes__conditional')) {
1259
+ const inputIsChecked = $input.checked;
1260
+ $input.setAttribute('aria-expanded', inputIsChecked.toString());
1261
+ $target.classList.toggle('govuk-checkboxes__conditional--hidden', !inputIsChecked);
1262
+ }
1263
+ }
1264
+ unCheckAllInputsExcept($input) {
1265
+ const allInputsWithSameName = document.querySelectorAll(`input[type="checkbox"][name="${$input.name}"]`);
1266
+ allInputsWithSameName.forEach($inputWithSameName => {
1267
+ const hasSameFormOwner = $input.form === $inputWithSameName.form;
1268
+ if (hasSameFormOwner && $inputWithSameName !== $input) {
1269
+ $inputWithSameName.checked = false;
1270
+ this.syncConditionalRevealWithInputState($inputWithSameName);
1271
+ }
1272
+ });
1273
+ }
1274
+ unCheckExclusiveInputs($input) {
1275
+ const allInputsWithSameNameAndExclusiveBehaviour = document.querySelectorAll(`input[data-behaviour="exclusive"][type="checkbox"][name="${$input.name}"]`);
1276
+ allInputsWithSameNameAndExclusiveBehaviour.forEach($exclusiveInput => {
1277
+ const hasSameFormOwner = $input.form === $exclusiveInput.form;
1278
+ if (hasSameFormOwner) {
1279
+ $exclusiveInput.checked = false;
1280
+ this.syncConditionalRevealWithInputState($exclusiveInput);
1281
+ }
1282
+ });
1283
+ }
1284
+ handleClick(event) {
1285
+ const $clickedInput = event.target;
1286
+ if (!($clickedInput instanceof HTMLInputElement) || $clickedInput.type !== 'checkbox') {
1287
+ return;
1288
+ }
1289
+ const hasAriaControls = $clickedInput.getAttribute('aria-controls');
1290
+ if (hasAriaControls) {
1291
+ this.syncConditionalRevealWithInputState($clickedInput);
1292
+ }
1293
+ if (!$clickedInput.checked) {
1294
+ return;
1295
+ }
1296
+ const hasBehaviourExclusive = $clickedInput.getAttribute('data-behaviour') === 'exclusive';
1297
+ if (hasBehaviourExclusive) {
1298
+ this.unCheckAllInputsExcept($clickedInput);
1299
+ } else {
1300
+ this.unCheckExclusiveInputs($clickedInput);
1301
+ }
1302
+ }
1303
+ }
1304
+ Checkboxes.moduleName = 'govuk-checkboxes';
1305
+
1306
+ /**
1307
+ * Error summary component
1308
+ *
1309
+ * Takes focus on initialisation for accessible announcement, unless disabled in
1310
+ * configuration.
1311
+ *
1312
+ * @preserve
1313
+ */
1314
+ class ErrorSummary extends GOVUKFrontendComponent {
1315
+ /**
1316
+ * @param {Element | null} $root - HTML element to use for error summary
1317
+ * @param {ErrorSummaryConfig} [config] - Error summary config
1318
+ */
1319
+ constructor($root, config = {}) {
1320
+ super($root);
1321
+ this.config = void 0;
1322
+ this.config = mergeConfigs(ErrorSummary.defaults, config, normaliseDataset(ErrorSummary, this.$root.dataset));
1323
+ if (!this.config.disableAutoFocus) {
1324
+ setFocus(this.$root);
1325
+ }
1326
+ this.$root.addEventListener('click', event => this.handleClick(event));
1327
+ }
1328
+ handleClick(event) {
1329
+ const $target = event.target;
1330
+ if ($target && this.focusTarget($target)) {
1331
+ event.preventDefault();
1332
+ }
1333
+ }
1334
+ focusTarget($target) {
1335
+ if (!($target instanceof HTMLAnchorElement)) {
1336
+ return false;
1337
+ }
1338
+ const inputId = getFragmentFromUrl($target.href);
1339
+ if (!inputId) {
1340
+ return false;
1341
+ }
1342
+ const $input = document.getElementById(inputId);
1343
+ if (!$input) {
1344
+ return false;
1345
+ }
1346
+ const $legendOrLabel = this.getAssociatedLegendOrLabel($input);
1347
+ if (!$legendOrLabel) {
1348
+ return false;
1349
+ }
1350
+ $legendOrLabel.scrollIntoView();
1351
+ $input.focus({
1352
+ preventScroll: true
1353
+ });
1354
+ return true;
1355
+ }
1356
+ getAssociatedLegendOrLabel($input) {
1357
+ var _document$querySelect;
1358
+ const $fieldset = $input.closest('fieldset');
1359
+ if ($fieldset) {
1360
+ const $legends = $fieldset.getElementsByTagName('legend');
1361
+ if ($legends.length) {
1362
+ const $candidateLegend = $legends[0];
1363
+ if ($input instanceof HTMLInputElement && ($input.type === 'checkbox' || $input.type === 'radio')) {
1364
+ return $candidateLegend;
1365
+ }
1366
+ const legendTop = $candidateLegend.getBoundingClientRect().top;
1367
+ const inputRect = $input.getBoundingClientRect();
1368
+ if (inputRect.height && window.innerHeight) {
1369
+ const inputBottom = inputRect.top + inputRect.height;
1370
+ if (inputBottom - legendTop < window.innerHeight / 2) {
1371
+ return $candidateLegend;
1372
+ }
1373
+ }
1374
+ }
1375
+ }
1376
+ return (_document$querySelect = document.querySelector(`label[for='${$input.getAttribute('id')}']`)) != null ? _document$querySelect : $input.closest('label');
1377
+ }
1378
+ }
1379
+
1380
+ /**
1381
+ * Error summary config
1382
+ *
1383
+ * @typedef {object} ErrorSummaryConfig
1384
+ * @property {boolean} [disableAutoFocus=false] - If set to `true` the error
1385
+ * summary will not be focussed when the page loads.
1386
+ */
1387
+
1388
+ /**
1389
+ * @typedef {import('../../common/index.mjs').Schema} Schema
1390
+ */
1391
+ ErrorSummary.moduleName = 'govuk-error-summary';
1392
+ ErrorSummary.defaults = Object.freeze({
1393
+ disableAutoFocus: false
1394
+ });
1395
+ ErrorSummary.schema = Object.freeze({
1396
+ properties: {
1397
+ disableAutoFocus: {
1398
+ type: 'boolean'
1399
+ }
1400
+ }
1401
+ });
1402
+
1403
+ /**
1404
+ * Exit this page component
1405
+ *
1406
+ * @preserve
1407
+ */
1408
+ class ExitThisPage extends GOVUKFrontendComponent {
1409
+ /**
1410
+ * @param {Element | null} $root - HTML element that wraps the Exit This Page button
1411
+ * @param {ExitThisPageConfig} [config] - Exit This Page config
1412
+ */
1413
+ constructor($root, config = {}) {
1414
+ super($root);
1415
+ this.config = void 0;
1416
+ this.i18n = void 0;
1417
+ this.$button = void 0;
1418
+ this.$skiplinkButton = null;
1419
+ this.$updateSpan = null;
1420
+ this.$indicatorContainer = null;
1421
+ this.$overlay = null;
1422
+ this.keypressCounter = 0;
1423
+ this.lastKeyWasModified = false;
1424
+ this.timeoutTime = 5000;
1425
+ this.keypressTimeoutId = null;
1426
+ this.timeoutMessageId = null;
1427
+ const $button = this.$root.querySelector('.govuk-exit-this-page__button');
1428
+ if (!($button instanceof HTMLAnchorElement)) {
1429
+ throw new ElementError({
1430
+ component: ExitThisPage,
1431
+ element: $button,
1432
+ expectedType: 'HTMLAnchorElement',
1433
+ identifier: 'Button (`.govuk-exit-this-page__button`)'
1434
+ });
1435
+ }
1436
+ this.config = mergeConfigs(ExitThisPage.defaults, config, normaliseDataset(ExitThisPage, this.$root.dataset));
1437
+ this.i18n = new I18n(this.config.i18n);
1438
+ this.$button = $button;
1439
+ const $skiplinkButton = document.querySelector('.govuk-js-exit-this-page-skiplink');
1440
+ if ($skiplinkButton instanceof HTMLAnchorElement) {
1441
+ this.$skiplinkButton = $skiplinkButton;
1442
+ }
1443
+ this.buildIndicator();
1444
+ this.initUpdateSpan();
1445
+ this.initButtonClickHandler();
1446
+ if (!('govukFrontendExitThisPageKeypress' in document.body.dataset)) {
1447
+ document.addEventListener('keyup', this.handleKeypress.bind(this), true);
1448
+ document.body.dataset.govukFrontendExitThisPageKeypress = 'true';
1449
+ }
1450
+ window.addEventListener('pageshow', this.resetPage.bind(this));
1451
+ }
1452
+ initUpdateSpan() {
1453
+ this.$updateSpan = document.createElement('span');
1454
+ this.$updateSpan.setAttribute('role', 'status');
1455
+ this.$updateSpan.className = 'govuk-visually-hidden';
1456
+ this.$root.appendChild(this.$updateSpan);
1457
+ }
1458
+ initButtonClickHandler() {
1459
+ this.$button.addEventListener('click', this.handleClick.bind(this));
1460
+ if (this.$skiplinkButton) {
1461
+ this.$skiplinkButton.addEventListener('click', this.handleClick.bind(this));
1462
+ }
1463
+ }
1464
+ buildIndicator() {
1465
+ this.$indicatorContainer = document.createElement('div');
1466
+ this.$indicatorContainer.className = 'govuk-exit-this-page__indicator';
1467
+ this.$indicatorContainer.setAttribute('aria-hidden', 'true');
1468
+ for (let i = 0; i < 3; i++) {
1469
+ const $indicator = document.createElement('div');
1470
+ $indicator.className = 'govuk-exit-this-page__indicator-light';
1471
+ this.$indicatorContainer.appendChild($indicator);
1472
+ }
1473
+ this.$button.appendChild(this.$indicatorContainer);
1474
+ }
1475
+ updateIndicator() {
1476
+ if (!this.$indicatorContainer) {
1477
+ return;
1478
+ }
1479
+ this.$indicatorContainer.classList.toggle('govuk-exit-this-page__indicator--visible', this.keypressCounter > 0);
1480
+ const $indicators = this.$indicatorContainer.querySelectorAll('.govuk-exit-this-page__indicator-light');
1481
+ $indicators.forEach(($indicator, index) => {
1482
+ $indicator.classList.toggle('govuk-exit-this-page__indicator-light--on', index < this.keypressCounter);
1483
+ });
1484
+ }
1485
+ exitPage() {
1486
+ if (!this.$updateSpan) {
1487
+ return;
1488
+ }
1489
+ this.$updateSpan.textContent = '';
1490
+ document.body.classList.add('govuk-exit-this-page-hide-content');
1491
+ this.$overlay = document.createElement('div');
1492
+ this.$overlay.className = 'govuk-exit-this-page-overlay';
1493
+ this.$overlay.setAttribute('role', 'alert');
1494
+ document.body.appendChild(this.$overlay);
1495
+ this.$overlay.textContent = this.i18n.t('activated');
1496
+ window.location.href = this.$button.href;
1497
+ }
1498
+ handleClick(event) {
1499
+ event.preventDefault();
1500
+ this.exitPage();
1501
+ }
1502
+ handleKeypress(event) {
1503
+ if (!this.$updateSpan) {
1504
+ return;
1505
+ }
1506
+ if (event.key === 'Shift' && !this.lastKeyWasModified) {
1507
+ this.keypressCounter += 1;
1508
+ this.updateIndicator();
1509
+ if (this.timeoutMessageId) {
1510
+ window.clearTimeout(this.timeoutMessageId);
1511
+ this.timeoutMessageId = null;
1512
+ }
1513
+ if (this.keypressCounter >= 3) {
1514
+ this.keypressCounter = 0;
1515
+ if (this.keypressTimeoutId) {
1516
+ window.clearTimeout(this.keypressTimeoutId);
1517
+ this.keypressTimeoutId = null;
1518
+ }
1519
+ this.exitPage();
1520
+ } else {
1521
+ if (this.keypressCounter === 1) {
1522
+ this.$updateSpan.textContent = this.i18n.t('pressTwoMoreTimes');
1523
+ } else {
1524
+ this.$updateSpan.textContent = this.i18n.t('pressOneMoreTime');
1525
+ }
1526
+ }
1527
+ this.setKeypressTimer();
1528
+ } else if (this.keypressTimeoutId) {
1529
+ this.resetKeypressTimer();
1530
+ }
1531
+ this.lastKeyWasModified = event.shiftKey;
1532
+ }
1533
+ setKeypressTimer() {
1534
+ if (this.keypressTimeoutId) {
1535
+ window.clearTimeout(this.keypressTimeoutId);
1536
+ }
1537
+ this.keypressTimeoutId = window.setTimeout(this.resetKeypressTimer.bind(this), this.timeoutTime);
1538
+ }
1539
+ resetKeypressTimer() {
1540
+ if (!this.$updateSpan) {
1541
+ return;
1542
+ }
1543
+ if (this.keypressTimeoutId) {
1544
+ window.clearTimeout(this.keypressTimeoutId);
1545
+ this.keypressTimeoutId = null;
1546
+ }
1547
+ const $updateSpan = this.$updateSpan;
1548
+ this.keypressCounter = 0;
1549
+ $updateSpan.textContent = this.i18n.t('timedOut');
1550
+ this.timeoutMessageId = window.setTimeout(() => {
1551
+ $updateSpan.textContent = '';
1552
+ }, this.timeoutTime);
1553
+ this.updateIndicator();
1554
+ }
1555
+ resetPage() {
1556
+ document.body.classList.remove('govuk-exit-this-page-hide-content');
1557
+ if (this.$overlay) {
1558
+ this.$overlay.remove();
1559
+ this.$overlay = null;
1560
+ }
1561
+ if (this.$updateSpan) {
1562
+ this.$updateSpan.setAttribute('role', 'status');
1563
+ this.$updateSpan.textContent = '';
1564
+ }
1565
+ this.updateIndicator();
1566
+ if (this.keypressTimeoutId) {
1567
+ window.clearTimeout(this.keypressTimeoutId);
1568
+ }
1569
+ if (this.timeoutMessageId) {
1570
+ window.clearTimeout(this.timeoutMessageId);
1571
+ }
1572
+ }
1573
+ }
1574
+
1575
+ /**
1576
+ * Exit this Page config
1577
+ *
1578
+ * @see {@link ExitThisPage.defaults}
1579
+ * @typedef {object} ExitThisPageConfig
1580
+ * @property {ExitThisPageTranslations} [i18n=ExitThisPage.defaults.i18n] - Exit this page translations
1581
+ */
1582
+
1583
+ /**
1584
+ * Exit this Page translations
1585
+ *
1586
+ * @see {@link ExitThisPage.defaults.i18n}
1587
+ * @typedef {object} ExitThisPageTranslations
1588
+ *
1589
+ * Messages used by the component programatically inserted text, including
1590
+ * overlay text and screen reader announcements.
1591
+ * @property {string} [activated] - Screen reader announcement for when EtP
1592
+ * keypress functionality has been successfully activated.
1593
+ * @property {string} [timedOut] - Screen reader announcement for when the EtP
1594
+ * keypress functionality has timed out.
1595
+ * @property {string} [pressTwoMoreTimes] - Screen reader announcement informing
1596
+ * the user they must press the activation key two more times.
1597
+ * @property {string} [pressOneMoreTime] - Screen reader announcement informing
1598
+ * the user they must press the activation key one more time.
1599
+ */
1600
+
1601
+ /**
1602
+ * @typedef {import('../../common/index.mjs').Schema} Schema
1603
+ */
1604
+ ExitThisPage.moduleName = 'govuk-exit-this-page';
1605
+ ExitThisPage.defaults = Object.freeze({
1606
+ i18n: {
1607
+ activated: 'Loading.',
1608
+ timedOut: 'Exit this page expired.',
1609
+ pressTwoMoreTimes: 'Shift, press 2 more times to exit.',
1610
+ pressOneMoreTime: 'Shift, press 1 more time to exit.'
1611
+ }
1612
+ });
1613
+ ExitThisPage.schema = Object.freeze({
1614
+ properties: {
1615
+ i18n: {
1616
+ type: 'object'
1617
+ }
1618
+ }
1619
+ });
1620
+
1621
+ /**
1622
+ * Header component
1623
+ *
1624
+ * @preserve
1625
+ */
1626
+ class Header extends GOVUKFrontendComponent {
1627
+ /**
1628
+ * Apply a matchMedia for desktop which will trigger a state sync if the
1629
+ * browser viewport moves between states.
1630
+ *
1631
+ * @param {Element | null} $root - HTML element to use for header
1632
+ */
1633
+ constructor($root) {
1634
+ super($root);
1635
+ this.$menuButton = void 0;
1636
+ this.$menu = void 0;
1637
+ this.menuIsOpen = false;
1638
+ this.mql = null;
1639
+ const $menuButton = this.$root.querySelector('.govuk-js-header-toggle');
1640
+ if (!$menuButton) {
1641
+ return this;
1642
+ }
1643
+ const menuId = $menuButton.getAttribute('aria-controls');
1644
+ if (!menuId) {
1645
+ throw new ElementError({
1646
+ component: Header,
1647
+ identifier: 'Navigation button (`<button class="govuk-js-header-toggle">`) attribute (`aria-controls`)'
1648
+ });
1649
+ }
1650
+ const $menu = document.getElementById(menuId);
1651
+ if (!$menu) {
1652
+ throw new ElementError({
1653
+ component: Header,
1654
+ element: $menu,
1655
+ identifier: `Navigation (\`<ul id="${menuId}">\`)`
1656
+ });
1657
+ }
1658
+ this.$menu = $menu;
1659
+ this.$menuButton = $menuButton;
1660
+ this.setupResponsiveChecks();
1661
+ this.$menuButton.addEventListener('click', () => this.handleMenuButtonClick());
1662
+ }
1663
+ setupResponsiveChecks() {
1664
+ const breakpoint = getBreakpoint('desktop');
1665
+ if (!breakpoint.value) {
1666
+ throw new ElementError({
1667
+ component: Header,
1668
+ identifier: `CSS custom property (\`${breakpoint.property}\`) on pseudo-class \`:root\``
1669
+ });
1670
+ }
1671
+ this.mql = window.matchMedia(`(min-width: ${breakpoint.value})`);
1672
+ if ('addEventListener' in this.mql) {
1673
+ this.mql.addEventListener('change', () => this.checkMode());
1674
+ } else {
1675
+ this.mql.addListener(() => this.checkMode());
1676
+ }
1677
+ this.checkMode();
1678
+ }
1679
+ checkMode() {
1680
+ if (!this.mql || !this.$menu || !this.$menuButton) {
1681
+ return;
1682
+ }
1683
+ if (this.mql.matches) {
1684
+ this.$menu.removeAttribute('hidden');
1685
+ this.$menuButton.setAttribute('hidden', '');
1686
+ } else {
1687
+ this.$menuButton.removeAttribute('hidden');
1688
+ this.$menuButton.setAttribute('aria-expanded', this.menuIsOpen.toString());
1689
+ if (this.menuIsOpen) {
1690
+ this.$menu.removeAttribute('hidden');
1691
+ } else {
1692
+ this.$menu.setAttribute('hidden', '');
1693
+ }
1694
+ }
1695
+ }
1696
+ handleMenuButtonClick() {
1697
+ this.menuIsOpen = !this.menuIsOpen;
1698
+ this.checkMode();
1699
+ }
1700
+ }
1701
+ Header.moduleName = 'govuk-header';
1702
+
1703
+ /**
1704
+ * Notification Banner component
1705
+ *
1706
+ * @preserve
1707
+ */
1708
+ class NotificationBanner extends GOVUKFrontendComponent {
1709
+ /**
1710
+ * @param {Element | null} $root - HTML element to use for notification banner
1711
+ * @param {NotificationBannerConfig} [config] - Notification banner config
1712
+ */
1713
+ constructor($root, config = {}) {
1714
+ super($root);
1715
+ this.config = void 0;
1716
+ this.config = mergeConfigs(NotificationBanner.defaults, config, normaliseDataset(NotificationBanner, this.$root.dataset));
1717
+ if (this.$root.getAttribute('role') === 'alert' && !this.config.disableAutoFocus) {
1718
+ setFocus(this.$root);
1719
+ }
1720
+ }
1721
+ }
1722
+
1723
+ /**
1724
+ * Notification banner config
1725
+ *
1726
+ * @typedef {object} NotificationBannerConfig
1727
+ * @property {boolean} [disableAutoFocus=false] - If set to `true` the
1728
+ * notification banner will not be focussed when the page loads. This only
1729
+ * applies if the component has a `role` of `alert` – in other cases the
1730
+ * component will not be focused on page load, regardless of this option.
1731
+ */
1732
+
1733
+ /**
1734
+ * @typedef {import('../../common/index.mjs').Schema} Schema
1735
+ */
1736
+ NotificationBanner.moduleName = 'govuk-notification-banner';
1737
+ NotificationBanner.defaults = Object.freeze({
1738
+ disableAutoFocus: false
1739
+ });
1740
+ NotificationBanner.schema = Object.freeze({
1741
+ properties: {
1742
+ disableAutoFocus: {
1743
+ type: 'boolean'
1744
+ }
1745
+ }
1746
+ });
1747
+
1748
+ /**
1749
+ * Password input component
1750
+ *
1751
+ * @preserve
1752
+ */
1753
+ class PasswordInput extends GOVUKFrontendComponent {
1754
+ /**
1755
+ * @param {Element | null} $root - HTML element to use for password input
1756
+ * @param {PasswordInputConfig} [config] - Password input config
1757
+ */
1758
+ constructor($root, config = {}) {
1759
+ super($root);
1760
+ this.config = void 0;
1761
+ this.i18n = void 0;
1762
+ this.$input = void 0;
1763
+ this.$showHideButton = void 0;
1764
+ this.$screenReaderStatusMessage = void 0;
1765
+ const $input = this.$root.querySelector('.govuk-js-password-input-input');
1766
+ if (!($input instanceof HTMLInputElement)) {
1767
+ throw new ElementError({
1768
+ component: PasswordInput,
1769
+ element: $input,
1770
+ expectedType: 'HTMLInputElement',
1771
+ identifier: 'Form field (`.govuk-js-password-input-input`)'
1772
+ });
1773
+ }
1774
+ if ($input.type !== 'password') {
1775
+ throw new ElementError('Password input: Form field (`.govuk-js-password-input-input`) must be of type `password`.');
1776
+ }
1777
+ const $showHideButton = this.$root.querySelector('.govuk-js-password-input-toggle');
1778
+ if (!($showHideButton instanceof HTMLButtonElement)) {
1779
+ throw new ElementError({
1780
+ component: PasswordInput,
1781
+ element: $showHideButton,
1782
+ expectedType: 'HTMLButtonElement',
1783
+ identifier: 'Button (`.govuk-js-password-input-toggle`)'
1784
+ });
1785
+ }
1786
+ if ($showHideButton.type !== 'button') {
1787
+ throw new ElementError('Password input: Button (`.govuk-js-password-input-toggle`) must be of type `button`.');
1788
+ }
1789
+ this.$input = $input;
1790
+ this.$showHideButton = $showHideButton;
1791
+ this.config = mergeConfigs(PasswordInput.defaults, config, normaliseDataset(PasswordInput, this.$root.dataset));
1792
+ this.i18n = new I18n(this.config.i18n, {
1793
+ locale: closestAttributeValue(this.$root, 'lang')
1794
+ });
1795
+ this.$showHideButton.removeAttribute('hidden');
1796
+ const $screenReaderStatusMessage = document.createElement('div');
1797
+ $screenReaderStatusMessage.className = 'govuk-password-input__sr-status govuk-visually-hidden';
1798
+ $screenReaderStatusMessage.setAttribute('aria-live', 'polite');
1799
+ this.$screenReaderStatusMessage = $screenReaderStatusMessage;
1800
+ this.$input.insertAdjacentElement('afterend', $screenReaderStatusMessage);
1801
+ this.$showHideButton.addEventListener('click', this.toggle.bind(this));
1802
+ if (this.$input.form) {
1803
+ this.$input.form.addEventListener('submit', () => this.hide());
1804
+ }
1805
+ window.addEventListener('pageshow', event => {
1806
+ if (event.persisted && this.$input.type !== 'password') {
1807
+ this.hide();
1808
+ }
1809
+ });
1810
+ this.hide();
1811
+ }
1812
+ toggle(event) {
1813
+ event.preventDefault();
1814
+ if (this.$input.type === 'password') {
1815
+ this.show();
1816
+ return;
1817
+ }
1818
+ this.hide();
1819
+ }
1820
+ show() {
1821
+ this.setType('text');
1822
+ }
1823
+ hide() {
1824
+ this.setType('password');
1825
+ }
1826
+ setType(type) {
1827
+ if (type === this.$input.type) {
1828
+ return;
1829
+ }
1830
+ this.$input.setAttribute('type', type);
1831
+ const isHidden = type === 'password';
1832
+ const prefixButton = isHidden ? 'show' : 'hide';
1833
+ const prefixStatus = isHidden ? 'passwordHidden' : 'passwordShown';
1834
+ this.$showHideButton.innerText = this.i18n.t(`${prefixButton}Password`);
1835
+ this.$showHideButton.setAttribute('aria-label', this.i18n.t(`${prefixButton}PasswordAriaLabel`));
1836
+ this.$screenReaderStatusMessage.innerText = this.i18n.t(`${prefixStatus}Announcement`);
1837
+ }
1838
+ }
1839
+
1840
+ /**
1841
+ * Password input config
1842
+ *
1843
+ * @typedef {object} PasswordInputConfig
1844
+ * @property {PasswordInputTranslations} [i18n=PasswordInput.defaults.i18n] - Password input translations
1845
+ */
1846
+
1847
+ /**
1848
+ * Password input translations
1849
+ *
1850
+ * @see {@link PasswordInput.defaults.i18n}
1851
+ * @typedef {object} PasswordInputTranslations
1852
+ *
1853
+ * Messages displayed to the user indicating the state of the show/hide toggle.
1854
+ * @property {string} [showPassword] - Visible text of the button when the
1855
+ * password is currently hidden. Plain text only.
1856
+ * @property {string} [hidePassword] - Visible text of the button when the
1857
+ * password is currently visible. Plain text only.
1858
+ * @property {string} [showPasswordAriaLabel] - aria-label of the button when
1859
+ * the password is currently hidden. Plain text only.
1860
+ * @property {string} [hidePasswordAriaLabel] - aria-label of the button when
1861
+ * the password is currently visible. Plain text only.
1862
+ * @property {string} [passwordShownAnnouncement] - Screen reader
1863
+ * announcement to make when the password has just become visible.
1864
+ * Plain text only.
1865
+ * @property {string} [passwordHiddenAnnouncement] - Screen reader
1866
+ * announcement to make when the password has just been hidden.
1867
+ * Plain text only.
1868
+ */
1869
+
1870
+ /**
1871
+ * @typedef {import('../../common/index.mjs').Schema} Schema
1872
+ * @typedef {import('../../i18n.mjs').TranslationPluralForms} TranslationPluralForms
1873
+ */
1874
+ PasswordInput.moduleName = 'govuk-password-input';
1875
+ PasswordInput.defaults = Object.freeze({
1876
+ i18n: {
1877
+ showPassword: 'Show',
1878
+ hidePassword: 'Hide',
1879
+ showPasswordAriaLabel: 'Show password',
1880
+ hidePasswordAriaLabel: 'Hide password',
1881
+ passwordShownAnnouncement: 'Your password is visible',
1882
+ passwordHiddenAnnouncement: 'Your password is hidden'
1883
+ }
1884
+ });
1885
+ PasswordInput.schema = Object.freeze({
1886
+ properties: {
1887
+ i18n: {
1888
+ type: 'object'
1889
+ }
1890
+ }
1891
+ });
1892
+
1893
+ /**
1894
+ * Radios component
1895
+ *
1896
+ * @preserve
1897
+ */
1898
+ class Radios extends GOVUKFrontendComponent {
1899
+ /**
1900
+ * Radios can be associated with a 'conditionally revealed' content block –
1901
+ * for example, a radio for 'Phone' could reveal an additional form field for
1902
+ * the user to enter their phone number.
1903
+ *
1904
+ * These associations are made using a `data-aria-controls` attribute, which
1905
+ * is promoted to an aria-controls attribute during initialisation.
1906
+ *
1907
+ * We also need to restore the state of any conditional reveals on the page
1908
+ * (for example if the user has navigated back), and set up event handlers to
1909
+ * keep the reveal in sync with the radio state.
1910
+ *
1911
+ * @param {Element | null} $root - HTML element to use for radios
1912
+ */
1913
+ constructor($root) {
1914
+ super($root);
1915
+ this.$inputs = void 0;
1916
+ const $inputs = this.$root.querySelectorAll('input[type="radio"]');
1917
+ if (!$inputs.length) {
1918
+ throw new ElementError({
1919
+ component: Radios,
1920
+ identifier: 'Form inputs (`<input type="radio">`)'
1921
+ });
1922
+ }
1923
+ this.$inputs = $inputs;
1924
+ this.$inputs.forEach($input => {
1925
+ const targetId = $input.getAttribute('data-aria-controls');
1926
+ if (!targetId) {
1927
+ return;
1928
+ }
1929
+ if (!document.getElementById(targetId)) {
1930
+ throw new ElementError({
1931
+ component: Radios,
1932
+ identifier: `Conditional reveal (\`id="${targetId}"\`)`
1933
+ });
1934
+ }
1935
+ $input.setAttribute('aria-controls', targetId);
1936
+ $input.removeAttribute('data-aria-controls');
1937
+ });
1938
+ window.addEventListener('pageshow', () => this.syncAllConditionalReveals());
1939
+ this.syncAllConditionalReveals();
1940
+ this.$root.addEventListener('click', event => this.handleClick(event));
1941
+ }
1942
+ syncAllConditionalReveals() {
1943
+ this.$inputs.forEach($input => this.syncConditionalRevealWithInputState($input));
1944
+ }
1945
+ syncConditionalRevealWithInputState($input) {
1946
+ const targetId = $input.getAttribute('aria-controls');
1947
+ if (!targetId) {
1948
+ return;
1949
+ }
1950
+ const $target = document.getElementById(targetId);
1951
+ if ($target != null && $target.classList.contains('govuk-radios__conditional')) {
1952
+ const inputIsChecked = $input.checked;
1953
+ $input.setAttribute('aria-expanded', inputIsChecked.toString());
1954
+ $target.classList.toggle('govuk-radios__conditional--hidden', !inputIsChecked);
1955
+ }
1956
+ }
1957
+ handleClick(event) {
1958
+ const $clickedInput = event.target;
1959
+ if (!($clickedInput instanceof HTMLInputElement) || $clickedInput.type !== 'radio') {
1960
+ return;
1961
+ }
1962
+ const $allInputs = document.querySelectorAll('input[type="radio"][aria-controls]');
1963
+ const $clickedInputForm = $clickedInput.form;
1964
+ const $clickedInputName = $clickedInput.name;
1965
+ $allInputs.forEach($input => {
1966
+ const hasSameFormOwner = $input.form === $clickedInputForm;
1967
+ const hasSameName = $input.name === $clickedInputName;
1968
+ if (hasSameName && hasSameFormOwner) {
1969
+ this.syncConditionalRevealWithInputState($input);
1970
+ }
1971
+ });
1972
+ }
1973
+ }
1974
+ Radios.moduleName = 'govuk-radios';
1975
+
1976
+ /**
1977
+ * Service Navigation component
1978
+ *
1979
+ * @preserve
1980
+ */
1981
+ class ServiceNavigation extends GOVUKFrontendComponent {
1982
+ /**
1983
+ * @param {Element | null} $root - HTML element to use for header
1984
+ */
1985
+ constructor($root) {
1986
+ super($root);
1987
+ this.$menuButton = void 0;
1988
+ this.$menu = void 0;
1989
+ this.menuIsOpen = false;
1990
+ this.mql = null;
1991
+ const $menuButton = this.$root.querySelector('.govuk-js-service-navigation-toggle');
1992
+ if (!$menuButton) {
1993
+ return this;
1994
+ }
1995
+ const menuId = $menuButton.getAttribute('aria-controls');
1996
+ if (!menuId) {
1997
+ throw new ElementError({
1998
+ component: ServiceNavigation,
1999
+ identifier: 'Navigation button (`<button class="govuk-js-service-navigation-toggle">`) attribute (`aria-controls`)'
2000
+ });
2001
+ }
2002
+ const $menu = document.getElementById(menuId);
2003
+ if (!$menu) {
2004
+ throw new ElementError({
2005
+ component: ServiceNavigation,
2006
+ element: $menu,
2007
+ identifier: `Navigation (\`<ul id="${menuId}">\`)`
2008
+ });
2009
+ }
2010
+ this.$menu = $menu;
2011
+ this.$menuButton = $menuButton;
2012
+ this.setupResponsiveChecks();
2013
+ this.$menuButton.addEventListener('click', () => this.handleMenuButtonClick());
2014
+ }
2015
+ setupResponsiveChecks() {
2016
+ const breakpoint = getBreakpoint('tablet');
2017
+ if (!breakpoint.value) {
2018
+ throw new ElementError({
2019
+ component: ServiceNavigation,
2020
+ identifier: `CSS custom property (\`${breakpoint.property}\`) on pseudo-class \`:root\``
2021
+ });
2022
+ }
2023
+ this.mql = window.matchMedia(`(min-width: ${breakpoint.value})`);
2024
+ if ('addEventListener' in this.mql) {
2025
+ this.mql.addEventListener('change', () => this.checkMode());
2026
+ } else {
2027
+ this.mql.addListener(() => this.checkMode());
2028
+ }
2029
+ this.checkMode();
2030
+ }
2031
+ checkMode() {
2032
+ if (!this.mql || !this.$menu || !this.$menuButton) {
2033
+ return;
2034
+ }
2035
+ if (this.mql.matches) {
2036
+ this.$menu.removeAttribute('hidden');
2037
+ this.$menuButton.setAttribute('hidden', '');
2038
+ } else {
2039
+ this.$menuButton.removeAttribute('hidden');
2040
+ this.$menuButton.setAttribute('aria-expanded', this.menuIsOpen.toString());
2041
+ if (this.menuIsOpen) {
2042
+ this.$menu.removeAttribute('hidden');
2043
+ } else {
2044
+ this.$menu.setAttribute('hidden', '');
2045
+ }
2046
+ }
2047
+ }
2048
+ handleMenuButtonClick() {
2049
+ this.menuIsOpen = !this.menuIsOpen;
2050
+ this.checkMode();
2051
+ }
2052
+ }
2053
+ ServiceNavigation.moduleName = 'govuk-service-navigation';
2054
+
2055
+ /**
2056
+ * Skip link component
2057
+ *
2058
+ * @preserve
2059
+ * @augments GOVUKFrontendComponent<HTMLAnchorElement>
2060
+ */
2061
+ class SkipLink extends GOVUKFrontendComponent {
2062
+ /**
2063
+ * @param {Element | null} $root - HTML element to use for skip link
2064
+ * @throws {ElementError} when $root is not set or the wrong type
2065
+ * @throws {ElementError} when $root.hash does not contain a hash
2066
+ * @throws {ElementError} when the linked element is missing or the wrong type
2067
+ */
2068
+ constructor($root) {
2069
+ var _this$$root$getAttrib;
2070
+ super($root);
2071
+ const hash = this.$root.hash;
2072
+ const href = (_this$$root$getAttrib = this.$root.getAttribute('href')) != null ? _this$$root$getAttrib : '';
2073
+ let url;
2074
+ try {
2075
+ url = new window.URL(this.$root.href);
2076
+ } catch (error) {
2077
+ throw new ElementError(`Skip link: Target link (\`href="${href}"\`) is invalid`);
2078
+ }
2079
+ if (url.origin !== window.location.origin || url.pathname !== window.location.pathname) {
2080
+ return;
2081
+ }
2082
+ const linkedElementId = getFragmentFromUrl(hash);
2083
+ if (!linkedElementId) {
2084
+ throw new ElementError(`Skip link: Target link (\`href="${href}"\`) has no hash fragment`);
2085
+ }
2086
+ const $linkedElement = document.getElementById(linkedElementId);
2087
+ if (!$linkedElement) {
2088
+ throw new ElementError({
2089
+ component: SkipLink,
2090
+ element: $linkedElement,
2091
+ identifier: `Target content (\`id="${linkedElementId}"\`)`
2092
+ });
2093
+ }
2094
+ this.$root.addEventListener('click', () => setFocus($linkedElement, {
2095
+ onBeforeFocus() {
2096
+ $linkedElement.classList.add('govuk-skip-link-focused-element');
2097
+ },
2098
+ onBlur() {
2099
+ $linkedElement.classList.remove('govuk-skip-link-focused-element');
2100
+ }
2101
+ }));
2102
+ }
2103
+ }
2104
+ SkipLink.elementType = HTMLAnchorElement;
2105
+ SkipLink.moduleName = 'govuk-skip-link';
2106
+
2107
+ /**
2108
+ * Tabs component
2109
+ *
2110
+ * @preserve
2111
+ */
2112
+ class Tabs extends GOVUKFrontendComponent {
2113
+ /**
2114
+ * @param {Element | null} $root - HTML element to use for tabs
2115
+ */
2116
+ constructor($root) {
2117
+ super($root);
2118
+ this.$tabs = void 0;
2119
+ this.$tabList = void 0;
2120
+ this.$tabListItems = void 0;
2121
+ this.jsHiddenClass = 'govuk-tabs__panel--hidden';
2122
+ this.changingHash = false;
2123
+ this.boundTabClick = void 0;
2124
+ this.boundTabKeydown = void 0;
2125
+ this.boundOnHashChange = void 0;
2126
+ this.mql = null;
2127
+ const $tabs = this.$root.querySelectorAll('a.govuk-tabs__tab');
2128
+ if (!$tabs.length) {
2129
+ throw new ElementError({
2130
+ component: Tabs,
2131
+ identifier: 'Links (`<a class="govuk-tabs__tab">`)'
2132
+ });
2133
+ }
2134
+ this.$tabs = $tabs;
2135
+ this.boundTabClick = this.onTabClick.bind(this);
2136
+ this.boundTabKeydown = this.onTabKeydown.bind(this);
2137
+ this.boundOnHashChange = this.onHashChange.bind(this);
2138
+ const $tabList = this.$root.querySelector('.govuk-tabs__list');
2139
+ const $tabListItems = this.$root.querySelectorAll('li.govuk-tabs__list-item');
2140
+ if (!$tabList) {
2141
+ throw new ElementError({
2142
+ component: Tabs,
2143
+ identifier: 'List (`<ul class="govuk-tabs__list">`)'
2144
+ });
2145
+ }
2146
+ if (!$tabListItems.length) {
2147
+ throw new ElementError({
2148
+ component: Tabs,
2149
+ identifier: 'List items (`<li class="govuk-tabs__list-item">`)'
2150
+ });
2151
+ }
2152
+ this.$tabList = $tabList;
2153
+ this.$tabListItems = $tabListItems;
2154
+ this.setupResponsiveChecks();
2155
+ }
2156
+ setupResponsiveChecks() {
2157
+ const breakpoint = getBreakpoint('tablet');
2158
+ if (!breakpoint.value) {
2159
+ throw new ElementError({
2160
+ component: Tabs,
2161
+ identifier: `CSS custom property (\`${breakpoint.property}\`) on pseudo-class \`:root\``
2162
+ });
2163
+ }
2164
+ this.mql = window.matchMedia(`(min-width: ${breakpoint.value})`);
2165
+ if ('addEventListener' in this.mql) {
2166
+ this.mql.addEventListener('change', () => this.checkMode());
2167
+ } else {
2168
+ this.mql.addListener(() => this.checkMode());
2169
+ }
2170
+ this.checkMode();
2171
+ }
2172
+ checkMode() {
2173
+ var _this$mql;
2174
+ if ((_this$mql = this.mql) != null && _this$mql.matches) {
2175
+ this.setup();
2176
+ } else {
2177
+ this.teardown();
2178
+ }
2179
+ }
2180
+ setup() {
2181
+ var _this$getTab;
2182
+ this.$tabList.setAttribute('role', 'tablist');
2183
+ this.$tabListItems.forEach($item => {
2184
+ $item.setAttribute('role', 'presentation');
2185
+ });
2186
+ this.$tabs.forEach($tab => {
2187
+ this.setAttributes($tab);
2188
+ $tab.addEventListener('click', this.boundTabClick, true);
2189
+ $tab.addEventListener('keydown', this.boundTabKeydown, true);
2190
+ this.hideTab($tab);
2191
+ });
2192
+ const $activeTab = (_this$getTab = this.getTab(window.location.hash)) != null ? _this$getTab : this.$tabs[0];
2193
+ this.showTab($activeTab);
2194
+ window.addEventListener('hashchange', this.boundOnHashChange, true);
2195
+ }
2196
+ teardown() {
2197
+ this.$tabList.removeAttribute('role');
2198
+ this.$tabListItems.forEach($item => {
2199
+ $item.removeAttribute('role');
2200
+ });
2201
+ this.$tabs.forEach($tab => {
2202
+ $tab.removeEventListener('click', this.boundTabClick, true);
2203
+ $tab.removeEventListener('keydown', this.boundTabKeydown, true);
2204
+ this.unsetAttributes($tab);
2205
+ });
2206
+ window.removeEventListener('hashchange', this.boundOnHashChange, true);
2207
+ }
2208
+ onHashChange() {
2209
+ const hash = window.location.hash;
2210
+ const $tabWithHash = this.getTab(hash);
2211
+ if (!$tabWithHash) {
2212
+ return;
2213
+ }
2214
+ if (this.changingHash) {
2215
+ this.changingHash = false;
2216
+ return;
2217
+ }
2218
+ const $previousTab = this.getCurrentTab();
2219
+ if (!$previousTab) {
2220
+ return;
2221
+ }
2222
+ this.hideTab($previousTab);
2223
+ this.showTab($tabWithHash);
2224
+ $tabWithHash.focus();
2225
+ }
2226
+ hideTab($tab) {
2227
+ this.unhighlightTab($tab);
2228
+ this.hidePanel($tab);
2229
+ }
2230
+ showTab($tab) {
2231
+ this.highlightTab($tab);
2232
+ this.showPanel($tab);
2233
+ }
2234
+ getTab(hash) {
2235
+ return this.$root.querySelector(`a.govuk-tabs__tab[href="${hash}"]`);
2236
+ }
2237
+ setAttributes($tab) {
2238
+ const panelId = getFragmentFromUrl($tab.href);
2239
+ if (!panelId) {
2240
+ return;
2241
+ }
2242
+ $tab.setAttribute('id', `tab_${panelId}`);
2243
+ $tab.setAttribute('role', 'tab');
2244
+ $tab.setAttribute('aria-controls', panelId);
2245
+ $tab.setAttribute('aria-selected', 'false');
2246
+ $tab.setAttribute('tabindex', '-1');
2247
+ const $panel = this.getPanel($tab);
2248
+ if (!$panel) {
2249
+ return;
2250
+ }
2251
+ $panel.setAttribute('role', 'tabpanel');
2252
+ $panel.setAttribute('aria-labelledby', $tab.id);
2253
+ $panel.classList.add(this.jsHiddenClass);
2254
+ }
2255
+ unsetAttributes($tab) {
2256
+ $tab.removeAttribute('id');
2257
+ $tab.removeAttribute('role');
2258
+ $tab.removeAttribute('aria-controls');
2259
+ $tab.removeAttribute('aria-selected');
2260
+ $tab.removeAttribute('tabindex');
2261
+ const $panel = this.getPanel($tab);
2262
+ if (!$panel) {
2263
+ return;
2264
+ }
2265
+ $panel.removeAttribute('role');
2266
+ $panel.removeAttribute('aria-labelledby');
2267
+ $panel.classList.remove(this.jsHiddenClass);
2268
+ }
2269
+ onTabClick(event) {
2270
+ const $currentTab = this.getCurrentTab();
2271
+ const $nextTab = event.currentTarget;
2272
+ if (!$currentTab || !($nextTab instanceof HTMLAnchorElement)) {
2273
+ return;
2274
+ }
2275
+ event.preventDefault();
2276
+ this.hideTab($currentTab);
2277
+ this.showTab($nextTab);
2278
+ this.createHistoryEntry($nextTab);
2279
+ }
2280
+ createHistoryEntry($tab) {
2281
+ const $panel = this.getPanel($tab);
2282
+ if (!$panel) {
2283
+ return;
2284
+ }
2285
+ const panelId = $panel.id;
2286
+ $panel.id = '';
2287
+ this.changingHash = true;
2288
+ window.location.hash = panelId;
2289
+ $panel.id = panelId;
2290
+ }
2291
+ onTabKeydown(event) {
2292
+ switch (event.key) {
2293
+ case 'ArrowLeft':
2294
+ case 'Left':
2295
+ this.activatePreviousTab();
2296
+ event.preventDefault();
2297
+ break;
2298
+ case 'ArrowRight':
2299
+ case 'Right':
2300
+ this.activateNextTab();
2301
+ event.preventDefault();
2302
+ break;
2303
+ }
2304
+ }
2305
+ activateNextTab() {
2306
+ const $currentTab = this.getCurrentTab();
2307
+ if (!($currentTab != null && $currentTab.parentElement)) {
2308
+ return;
2309
+ }
2310
+ const $nextTabListItem = $currentTab.parentElement.nextElementSibling;
2311
+ if (!$nextTabListItem) {
2312
+ return;
2313
+ }
2314
+ const $nextTab = $nextTabListItem.querySelector('a.govuk-tabs__tab');
2315
+ if (!$nextTab) {
2316
+ return;
2317
+ }
2318
+ this.hideTab($currentTab);
2319
+ this.showTab($nextTab);
2320
+ $nextTab.focus();
2321
+ this.createHistoryEntry($nextTab);
2322
+ }
2323
+ activatePreviousTab() {
2324
+ const $currentTab = this.getCurrentTab();
2325
+ if (!($currentTab != null && $currentTab.parentElement)) {
2326
+ return;
2327
+ }
2328
+ const $previousTabListItem = $currentTab.parentElement.previousElementSibling;
2329
+ if (!$previousTabListItem) {
2330
+ return;
2331
+ }
2332
+ const $previousTab = $previousTabListItem.querySelector('a.govuk-tabs__tab');
2333
+ if (!$previousTab) {
2334
+ return;
2335
+ }
2336
+ this.hideTab($currentTab);
2337
+ this.showTab($previousTab);
2338
+ $previousTab.focus();
2339
+ this.createHistoryEntry($previousTab);
2340
+ }
2341
+ getPanel($tab) {
2342
+ const panelId = getFragmentFromUrl($tab.href);
2343
+ if (!panelId) {
2344
+ return null;
2345
+ }
2346
+ return this.$root.querySelector(`#${panelId}`);
2347
+ }
2348
+ showPanel($tab) {
2349
+ const $panel = this.getPanel($tab);
2350
+ if (!$panel) {
2351
+ return;
2352
+ }
2353
+ $panel.classList.remove(this.jsHiddenClass);
2354
+ }
2355
+ hidePanel($tab) {
2356
+ const $panel = this.getPanel($tab);
2357
+ if (!$panel) {
2358
+ return;
2359
+ }
2360
+ $panel.classList.add(this.jsHiddenClass);
2361
+ }
2362
+ unhighlightTab($tab) {
2363
+ if (!$tab.parentElement) {
2364
+ return;
2365
+ }
2366
+ $tab.setAttribute('aria-selected', 'false');
2367
+ $tab.parentElement.classList.remove('govuk-tabs__list-item--selected');
2368
+ $tab.setAttribute('tabindex', '-1');
2369
+ }
2370
+ highlightTab($tab) {
2371
+ if (!$tab.parentElement) {
2372
+ return;
2373
+ }
2374
+ $tab.setAttribute('aria-selected', 'true');
2375
+ $tab.parentElement.classList.add('govuk-tabs__list-item--selected');
2376
+ $tab.setAttribute('tabindex', '0');
2377
+ }
2378
+ getCurrentTab() {
2379
+ return this.$root.querySelector('.govuk-tabs__list-item--selected a.govuk-tabs__tab');
2380
+ }
2381
+ }
2382
+ Tabs.moduleName = 'govuk-tabs';
2383
+
2384
+ /**
2385
+ * Initialise all components
2386
+ *
2387
+ * Use the `data-module` attributes to find, instantiate and init all of the
2388
+ * components provided as part of GOV.UK Frontend.
2389
+ *
2390
+ * @param {Config & { scope?: Element, onError?: OnErrorCallback<CompatibleClass> }} [config] - Config for all components (with optional scope)
2391
+ */
2392
+ function initAll(config) {
2393
+ var _config$scope;
2394
+ config = typeof config !== 'undefined' ? config : {};
2395
+ if (!isSupported()) {
2396
+ if (config.onError) {
2397
+ config.onError(new SupportError(), {
2398
+ config
2399
+ });
2400
+ } else {
2401
+ console.log(new SupportError());
2402
+ }
2403
+ return;
2404
+ }
2405
+ const components = [[Accordion, config.accordion], [Button, config.button], [CharacterCount, config.characterCount], [Checkboxes], [ErrorSummary, config.errorSummary], [ExitThisPage, config.exitThisPage], [Header], [NotificationBanner, config.notificationBanner], [PasswordInput, config.passwordInput], [Radios], [ServiceNavigation], [SkipLink], [Tabs]];
2406
+ const options = {
2407
+ scope: (_config$scope = config.scope) != null ? _config$scope : document,
2408
+ onError: config.onError
2409
+ };
2410
+ components.forEach(([Component, config]) => {
2411
+ createAll(Component, config, options);
2412
+ });
2413
+ }
2414
+
2415
+ /**
2416
+ * Create all instances of a specific component on the page
2417
+ *
2418
+ * Uses the `data-module` attribute to find all elements matching the specified
2419
+ * component on the page, creating instances of the component object for each
2420
+ * of them.
2421
+ *
2422
+ * Any component errors will be caught and logged to the console.
2423
+ *
2424
+ * @template {CompatibleClass} T
2425
+ * @param {T} Component - class of the component to create
2426
+ * @param {T["defaults"]} [config] - Config supplied to component
2427
+ * @param {OnErrorCallback<T> | Element | Document | CreateAllOptions<T> } [createAllOptions] - options for createAll including scope of the document to search within and callback function if error throw by component on init
2428
+ * @returns {Array<InstanceType<T>>} - array of instantiated components
2429
+ */
2430
+ function createAll(Component, config, createAllOptions) {
2431
+ let $scope = document;
2432
+ let onError;
2433
+ if (typeof createAllOptions === 'object') {
2434
+ var _createAllOptions$sco;
2435
+ createAllOptions = createAllOptions;
2436
+ $scope = (_createAllOptions$sco = createAllOptions.scope) != null ? _createAllOptions$sco : $scope;
2437
+ onError = createAllOptions.onError;
2438
+ }
2439
+ if (typeof createAllOptions === 'function') {
2440
+ onError = createAllOptions;
2441
+ }
2442
+ if (createAllOptions instanceof HTMLElement) {
2443
+ $scope = createAllOptions;
2444
+ }
2445
+ const $elements = $scope.querySelectorAll(`[data-module="${Component.moduleName}"]`);
2446
+ if (!isSupported()) {
2447
+ if (onError) {
2448
+ onError(new SupportError(), {
2449
+ component: Component,
2450
+ config
2451
+ });
2452
+ } else {
2453
+ console.log(new SupportError());
2454
+ }
2455
+ return [];
2456
+ }
2457
+ return Array.from($elements).map($element => {
2458
+ try {
2459
+ return typeof config !== 'undefined' ? new Component($element, config) : new Component($element);
2460
+ } catch (error) {
2461
+ if (onError) {
2462
+ onError(error, {
2463
+ element: $element,
2464
+ component: Component,
2465
+ config
2466
+ });
2467
+ } else {
2468
+ console.log(error);
2469
+ }
2470
+ return null;
2471
+ }
2472
+ }).filter(Boolean);
2473
+ }
2474
+ /**
2475
+ * @typedef {{new (...args: any[]): any, defaults?: object, moduleName: string}} CompatibleClass
2476
+ */
2477
+ /**
2478
+ * Config for all components via `initAll()`
2479
+ *
2480
+ * @typedef {object} Config
2481
+ * @property {AccordionConfig} [accordion] - Accordion config
2482
+ * @property {ButtonConfig} [button] - Button config
2483
+ * @property {CharacterCountConfig} [characterCount] - Character Count config
2484
+ * @property {ErrorSummaryConfig} [errorSummary] - Error Summary config
2485
+ * @property {ExitThisPageConfig} [exitThisPage] - Exit This Page config
2486
+ * @property {NotificationBannerConfig} [notificationBanner] - Notification Banner config
2487
+ * @property {PasswordInputConfig} [passwordInput] - Password input config
2488
+ */
2489
+ /**
2490
+ * Config for individual components
2491
+ *
2492
+ * @typedef {import('./components/accordion/accordion.mjs').AccordionConfig} AccordionConfig
2493
+ * @typedef {import('./components/accordion/accordion.mjs').AccordionTranslations} AccordionTranslations
2494
+ * @typedef {import('./components/button/button.mjs').ButtonConfig} ButtonConfig
2495
+ * @typedef {import('./components/character-count/character-count.mjs').CharacterCountConfig} CharacterCountConfig
2496
+ * @typedef {import('./components/character-count/character-count.mjs').CharacterCountTranslations} CharacterCountTranslations
2497
+ * @typedef {import('./components/error-summary/error-summary.mjs').ErrorSummaryConfig} ErrorSummaryConfig
2498
+ * @typedef {import('./components/exit-this-page/exit-this-page.mjs').ExitThisPageConfig} ExitThisPageConfig
2499
+ * @typedef {import('./components/exit-this-page/exit-this-page.mjs').ExitThisPageTranslations} ExitThisPageTranslations
2500
+ * @typedef {import('./components/notification-banner/notification-banner.mjs').NotificationBannerConfig} NotificationBannerConfig
2501
+ * @typedef {import('./components/password-input/password-input.mjs').PasswordInputConfig} PasswordInputConfig
2502
+ */
2503
+ /**
2504
+ * Component config keys, e.g. `accordion` and `characterCount`
2505
+ *
2506
+ * @typedef {keyof Config} ConfigKey
2507
+ */
2508
+ /**
2509
+ * @template {CompatibleClass} T
2510
+ * @typedef {object} ErrorContext
2511
+ * @property {Element} [element] - Element used for component module initialisation
2512
+ * @property {T} [component] - Class of component
2513
+ * @property {T["defaults"]} config - Config supplied to component
2514
+ */
2515
+ /**
2516
+ * @template {CompatibleClass} T
2517
+ * @callback OnErrorCallback
2518
+ * @param {unknown} error - Thrown error
2519
+ * @param {ErrorContext<T>} context - Object containing the element, component class and configuration
2520
+ */
2521
+ /**
2522
+ * @template {CompatibleClass} T
2523
+ * @typedef {object} CreateAllOptions
2524
+ * @property {Element | Document} [scope] - scope of the document to search within
2525
+ * @property {OnErrorCallback<T>} [onError] - callback function if error throw by component on init
2526
+ */
2527
+
2528
+ export { Accordion, Button, CharacterCount, Checkboxes, GOVUKFrontendComponent as Component, ErrorSummary, ExitThisPage, Header, NotificationBanner, PasswordInput, Radios, ServiceNavigation, SkipLink, Tabs, createAll, initAll, isSupported, version };
2529
+ //# sourceMappingURL=all.bundle.mjs.map