defra_ruby_template 6.4.0 → 6.6.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 (180) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +73 -19
  3. data/Rakefile +10 -33
  4. data/lib/defra_ruby_template/version.rb +1 -1
  5. data/node_modules/govuk-frontend/dist/govuk/all.bundle.js +202 -137
  6. data/node_modules/govuk-frontend/dist/govuk/all.bundle.js.map +1 -1
  7. data/node_modules/govuk-frontend/dist/govuk/all.bundle.mjs +202 -137
  8. data/node_modules/govuk-frontend/dist/govuk/all.bundle.mjs.map +1 -1
  9. data/node_modules/govuk-frontend/dist/govuk/common/closest-attribute-value.mjs.map +1 -1
  10. data/node_modules/govuk-frontend/dist/govuk/common/configuration.mjs +5 -1
  11. data/node_modules/govuk-frontend/dist/govuk/common/configuration.mjs.map +1 -1
  12. data/node_modules/govuk-frontend/dist/govuk/common/create-element.mjs +13 -0
  13. data/node_modules/govuk-frontend/dist/govuk/common/create-element.mjs.map +1 -0
  14. data/node_modules/govuk-frontend/dist/govuk/common/govuk-frontend-version.mjs +1 -1
  15. data/node_modules/govuk-frontend/dist/govuk/common/govuk-frontend-version.mjs.map +1 -1
  16. data/node_modules/govuk-frontend/dist/govuk/common/index.mjs.map +1 -1
  17. data/node_modules/govuk-frontend/dist/govuk/component.mjs +2 -1
  18. data/node_modules/govuk-frontend/dist/govuk/component.mjs.map +1 -1
  19. data/node_modules/govuk-frontend/dist/govuk/components/_index.import.scss +2 -0
  20. data/node_modules/govuk-frontend/dist/govuk/components/_index.scss +2 -0
  21. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js +87 -62
  22. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js.map +1 -1
  23. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs +87 -62
  24. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs.map +1 -1
  25. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.mjs +60 -56
  26. data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.mjs.map +1 -1
  27. data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.js +17 -6
  28. data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.js.map +1 -1
  29. data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.mjs +17 -6
  30. data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.mjs.map +1 -1
  31. data/node_modules/govuk-frontend/dist/govuk/components/button/button.mjs.map +1 -1
  32. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js +90 -32
  33. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js.map +1 -1
  34. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs +90 -32
  35. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs.map +1 -1
  36. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.mjs +64 -27
  37. data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.mjs.map +1 -1
  38. data/node_modules/govuk-frontend/dist/govuk/components/character-count/fixtures.json +173 -6
  39. data/node_modules/govuk-frontend/dist/govuk/components/character-count/macro-options.json +13 -6
  40. data/node_modules/govuk-frontend/dist/govuk/components/character-count/template-with-count-type-characters-and-error-message.html +12 -0
  41. data/node_modules/govuk-frontend/dist/govuk/components/character-count/template-with-count-type-characters-and-threshold.html +9 -0
  42. data/node_modules/govuk-frontend/dist/govuk/components/character-count/template-with-count-type-characters-and-value.html +9 -0
  43. data/node_modules/govuk-frontend/dist/govuk/components/character-count/template-with-count-type-characters.html +9 -0
  44. data/node_modules/govuk-frontend/dist/govuk/components/character-count/template-with-count-type-length.html +9 -0
  45. data/node_modules/govuk-frontend/dist/govuk/components/character-count/template-with-count-type-words-and-error-message.html +12 -0
  46. data/node_modules/govuk-frontend/dist/govuk/components/character-count/template-with-count-type-words-and-threshold.html +9 -0
  47. data/node_modules/govuk-frontend/dist/govuk/components/character-count/template-with-count-type-words-and-value.html +9 -0
  48. data/node_modules/govuk-frontend/dist/govuk/components/character-count/template-with-count-type-words.html +9 -0
  49. data/node_modules/govuk-frontend/dist/govuk/components/character-count/template-with-maxwords.html +9 -0
  50. data/node_modules/govuk-frontend/dist/govuk/components/character-count/template.njk +10 -3
  51. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js +12 -5
  52. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js.map +1 -1
  53. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs +12 -5
  54. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs.map +1 -1
  55. data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.mjs.map +1 -1
  56. data/node_modules/govuk-frontend/dist/govuk/components/cookie-banner/_mixin.scss +6 -0
  57. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js +17 -6
  58. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js.map +1 -1
  59. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs +17 -6
  60. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs.map +1 -1
  61. data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.mjs.map +1 -1
  62. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js +43 -18
  63. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js.map +1 -1
  64. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs +43 -18
  65. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs.map +1 -1
  66. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.mjs +16 -12
  67. data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.mjs.map +1 -1
  68. data/node_modules/govuk-frontend/dist/govuk/components/feedback/README.md +15 -0
  69. data/node_modules/govuk-frontend/dist/govuk/components/feedback/_feedback.import.scss +6 -0
  70. data/node_modules/govuk-frontend/dist/govuk/components/feedback/_index.import.scss +8 -0
  71. data/node_modules/govuk-frontend/dist/govuk/components/feedback/_index.scss +5 -0
  72. data/node_modules/govuk-frontend/dist/govuk/components/feedback/_mixin.scss +48 -0
  73. data/node_modules/govuk-frontend/dist/govuk/components/feedback/fixtures.json +95 -0
  74. data/node_modules/govuk-frontend/dist/govuk/components/feedback/macro-options.json +50 -0
  75. data/node_modules/govuk-frontend/dist/govuk/components/feedback/macro.njk +3 -0
  76. data/node_modules/govuk-frontend/dist/govuk/components/feedback/template-default.html +12 -0
  77. data/node_modules/govuk-frontend/dist/govuk/components/feedback/template-silly-example.html +19 -0
  78. data/node_modules/govuk-frontend/dist/govuk/components/feedback/template.njk +24 -0
  79. data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.js +54 -30
  80. data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.js.map +1 -1
  81. data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.mjs +54 -30
  82. data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.mjs.map +1 -1
  83. data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.mjs +27 -24
  84. data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.mjs.map +1 -1
  85. data/node_modules/govuk-frontend/dist/govuk/components/footer/_mixin.scss +6 -0
  86. data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/README.md +15 -0
  87. data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/_index.import.scss +8 -0
  88. data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/_index.scss +6 -0
  89. data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/_language-navigation.import.scss +6 -0
  90. data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/_mixin.scss +68 -0
  91. data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/fixtures.json +482 -0
  92. data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/macro-options.json +88 -0
  93. data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/macro.njk +3 -0
  94. data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/template-default.html +12 -0
  95. data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/template-inverse.html +12 -0
  96. data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/template-with-language-description.html +12 -0
  97. data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/template-with-large-amount-of-multiple-languages.html +99 -0
  98. data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/template-with-mixed-text-directions.html +12 -0
  99. data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/template-with-multiple-languages.html +24 -0
  100. data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/template-with-translated-navigation-label.html +12 -0
  101. data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/template.njk +33 -0
  102. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js +17 -6
  103. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js.map +1 -1
  104. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs +17 -6
  105. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs.map +1 -1
  106. data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs.map +1 -1
  107. data/node_modules/govuk-frontend/dist/govuk/components/panel/fixtures.json +13 -11
  108. data/node_modules/govuk-frontend/dist/govuk/components/panel/template-interruption-with-headings-content-and-lists.html +6 -1
  109. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js +32 -9
  110. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js.map +1 -1
  111. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs +32 -9
  112. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs.map +1 -1
  113. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.mjs +5 -3
  114. data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.mjs.map +1 -1
  115. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.js +12 -5
  116. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.js.map +1 -1
  117. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs +12 -5
  118. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs.map +1 -1
  119. data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.mjs.map +1 -1
  120. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/_mixin.scss +48 -3
  121. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/fixtures.json +121 -0
  122. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/macro-options.json +20 -0
  123. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js +12 -5
  124. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js.map +1 -1
  125. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs +12 -5
  126. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs.map +1 -1
  127. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.mjs.map +1 -1
  128. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/template-inverse-with-language-navigation.html +72 -0
  129. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/template-with-inline-end-slot.html +33 -0
  130. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/template-with-language-navigation.html +62 -0
  131. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/template-with-right-aligned-language-navigation.html +62 -0
  132. data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/template.njk +8 -3
  133. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js +14 -6
  134. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js.map +1 -1
  135. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs +14 -6
  136. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs.map +1 -1
  137. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.mjs +2 -1
  138. data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.mjs.map +1 -1
  139. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js +12 -5
  140. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js.map +1 -1
  141. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs +12 -5
  142. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs.map +1 -1
  143. data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.mjs.map +1 -1
  144. data/node_modules/govuk-frontend/dist/govuk/custom-properties/_frontend-version.mixin.scss +1 -1
  145. data/node_modules/govuk-frontend/dist/govuk/custom-properties/_functional-colours.mixin.scss +1 -0
  146. data/node_modules/govuk-frontend/dist/govuk/errors/index.mjs +8 -5
  147. data/node_modules/govuk-frontend/dist/govuk/errors/index.mjs.map +1 -1
  148. data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.css +2 -2
  149. data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.css.map +1 -1
  150. data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.js +1 -1
  151. data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.js.map +1 -1
  152. data/node_modules/govuk-frontend/dist/govuk/helpers/_colour.scss +1 -1
  153. data/node_modules/govuk-frontend/dist/govuk/i18n.mjs.map +1 -1
  154. data/node_modules/govuk-frontend/dist/govuk/init.mjs +8 -8
  155. data/node_modules/govuk-frontend/dist/govuk/init.mjs.map +1 -1
  156. data/node_modules/govuk-frontend/dist/govuk/settings/_colours-organisations.scss +16 -2
  157. data/node_modules/govuk-frontend/govuk-prototype-kit.config.json +9 -1
  158. data/node_modules/govuk-frontend/package.json +9 -7
  159. data/vendor/assets/javascripts/defra_ruby_template.js +202 -137
  160. data/vendor/assets/stylesheets/components/_index.import.scss +2 -0
  161. data/vendor/assets/stylesheets/components/_index.scss +2 -0
  162. data/vendor/assets/stylesheets/components/cookie-banner/_mixin.scss +6 -0
  163. data/vendor/assets/stylesheets/components/feedback/_feedback.import.scss +6 -0
  164. data/vendor/assets/stylesheets/components/feedback/_index.import.scss +8 -0
  165. data/vendor/assets/stylesheets/components/feedback/_index.scss +5 -0
  166. data/vendor/assets/stylesheets/components/feedback/_mixin.scss +48 -0
  167. data/vendor/assets/stylesheets/components/footer/_mixin.scss +6 -0
  168. data/vendor/assets/stylesheets/components/language-navigation/_index.import.scss +8 -0
  169. data/vendor/assets/stylesheets/components/language-navigation/_index.scss +6 -0
  170. data/vendor/assets/stylesheets/components/language-navigation/_language-navigation.import.scss +6 -0
  171. data/vendor/assets/stylesheets/components/language-navigation/_mixin.scss +68 -0
  172. data/vendor/assets/stylesheets/components/service-navigation/_mixin.scss +48 -3
  173. data/vendor/assets/stylesheets/custom-properties/_frontend-version.mixin.scss +1 -1
  174. data/vendor/assets/stylesheets/custom-properties/_functional-colours.mixin.scss +1 -0
  175. data/vendor/assets/stylesheets/defra_ruby_template.scss +8 -30
  176. data/vendor/assets/stylesheets/govuk-frontend.min.css +2 -2
  177. data/vendor/assets/stylesheets/helpers/_colour.scss +1 -1
  178. data/vendor/assets/stylesheets/settings/_colours-organisations.scss +16 -2
  179. metadata +53 -3
  180. data/node_modules/govuk-frontend/dist/govuk/components/character-count/template-with-word-count.html +0 -9
@@ -3,6 +3,9 @@
3
3
  {%- set menuButtonText = params.menuButtonText | default("Menu", true) -%}
4
4
  {%- set navigationId = params.navigationId | default("navigation", true) %}
5
5
 
6
+ {%- set endSlotHtml = params.slots.end if params.slots.end is string else params.slots.end.html %}
7
+ {%- set endSlotInline = params.slots.end is mapping and params.slots.end.align == 'inline' %}
8
+
6
9
  {%- set commonAttributes %}
7
10
  class="govuk-service-navigation {%- if params.classes %} {{ params.classes }}{% endif %}"
8
11
  data-module="govuk-service-navigation"
@@ -10,7 +13,9 @@ data-module="govuk-service-navigation"
10
13
  {% endset -%}
11
14
 
12
15
  {%- set innerContent %}
13
- <div class="govuk-width-container">
16
+ <div class="govuk-width-container
17
+ {%- if endSlotInline %} govuk-service-navigation__inlining-container{% endif -%}
18
+ ">
14
19
 
15
20
  {# Slot: start #}
16
21
  {%- if params.slots.start %}{{ params.slots.start | safe }}{% endif -%}
@@ -87,7 +92,7 @@ data-module="govuk-service-navigation"
87
92
  </div>
88
93
 
89
94
  {# Slot: end #}
90
- {%- if params.slots.end %}{{ params.slots.end | safe }}{% endif -%}
95
+ {%- if endSlotHtml %}{{ endSlotHtml | safe }}{% endif -%}
91
96
 
92
97
  </div>
93
98
  {% endset -%}
@@ -95,7 +100,7 @@ data-module="govuk-service-navigation"
95
100
  {# If a service name is included, we use a <section> element with an
96
101
  aria-label to create a containing landmark region. Otherwise, the <nav> in
97
102
  the innerContent can do the job just fine by itself. #}
98
- {% if params.serviceName or params.slots.start or params.slots.end %}
103
+ {% if params.serviceName or params.slots.start or endSlotHtml %}
99
104
  <section aria-label="{{ params.ariaLabel | default("Service information") }}" {{ commonAttributes | safe }}>
100
105
  {{ innerContent | safe }}
101
106
  </section>
@@ -53,6 +53,9 @@
53
53
  function isObject(option) {
54
54
  return !!option && typeof option === 'object' && !isArray(option);
55
55
  }
56
+ function isScope($scope) {
57
+ return !!$scope && ($scope instanceof Element || $scope instanceof Document);
58
+ }
56
59
  function formatErrorMessage(Component, message) {
57
60
  return `${Component.moduleName}: ${message}`;
58
61
  }
@@ -71,11 +74,14 @@
71
74
  /**
72
75
  * Checks if GOV.UK Frontend is supported on this page
73
76
  *
74
- * @param {HTMLElement | null} [$scope] - HTML element `<body>` checked for browser support
77
+ * @param {Element | Document | null | string} [scopeOrMessage] - HTML element `<body>` checked for browser support or support error message
75
78
  */
76
- constructor($scope = document.body) {
77
- 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';
78
- super($scope ? supportMessage : 'GOV.UK Frontend initialised without `<script type="module">`');
79
+ constructor(scopeOrMessage = document.body) {
80
+ let 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';
81
+ if (!isScope(scopeOrMessage)) {
82
+ supportMessage = 'GOV.UK Frontend initialised without `<script type="module">`';
83
+ }
84
+ super(typeof scopeOrMessage === 'string' ? scopeOrMessage : supportMessage);
79
85
  this.name = 'SupportError';
80
86
  }
81
87
  }
@@ -110,6 +116,7 @@
110
116
  * @import { ComponentWithModuleName } from '../common/index.mjs'
111
117
  */
112
118
 
119
+ const _self$1 = typeof globalThis !== 'undefined' ? globalThis : self;
113
120
  class Component {
114
121
  /**
115
122
  * Returns the root element of the component
@@ -163,8 +170,9 @@
163
170
  /**
164
171
  * @typedef {typeof Component & ChildClass} ChildClassConstructor
165
172
  */
166
- Component.elementType = HTMLElement;
173
+ Component.elementType = _self$1.HTMLElement;
167
174
 
175
+ const _self = typeof globalThis !== 'undefined' ? globalThis : self;
168
176
  /**
169
177
  * Skip link component
170
178
  *
@@ -208,7 +216,7 @@
208
216
  }));
209
217
  }
210
218
  }
211
- SkipLink.elementType = HTMLAnchorElement;
219
+ SkipLink.elementType = _self.HTMLAnchorElement;
212
220
  SkipLink.moduleName = 'govuk-skip-link';
213
221
 
214
222
  exports.SkipLink = SkipLink;
@@ -1 +1 @@
1
- {"version":3,"file":"skip-link.bundle.js","sources":["../../../../src/govuk/common/index.mjs","../../../../src/govuk/errors/index.mjs","../../../../src/govuk/component.mjs","../../../../src/govuk/components/skip-link/skip-link.mjs"],"sourcesContent":["/**\n * Common helpers which do not require polyfill.\n *\n * IMPORTANT: If a helper require a polyfill, please isolate it in its own module\n * so that the polyfill can be properly tree-shaken and does not burden\n * the components that do not need that helper\n */\n\n/**\n * Get GOV.UK Frontend breakpoint value from CSS custom property\n *\n * @private\n * @param {string} name - Breakpoint name\n * @returns {{ property: string, value?: string }} Breakpoint object\n */\nexport function getBreakpoint(name) {\n const property = `--govuk-breakpoint-${name}`\n\n // Get value from `<html>` with breakpoints on CSS :root\n const value = window\n .getComputedStyle(document.documentElement)\n .getPropertyValue(property)\n\n return {\n property,\n value: value || undefined\n }\n}\n\n/**\n * Move focus to element\n *\n * Sets tabindex to -1 to make the element programmatically focusable,\n * but removes it on blur as the element doesn't need to be focused again.\n *\n * @private\n * @template {HTMLElement} FocusElement\n * @param {FocusElement} $element - HTML element\n * @param {object} [options] - Handler options\n * @param {function(this: FocusElement): void} [options.onBeforeFocus] - Callback before focus\n * @param {function(this: FocusElement): void} [options.onBlur] - Callback on blur\n */\nexport function setFocus($element, options = {}) {\n const isFocusable = $element.getAttribute('tabindex')\n\n if (!isFocusable) {\n $element.setAttribute('tabindex', '-1')\n }\n\n /**\n * Handle element focus\n */\n function onFocus() {\n $element.addEventListener('blur', onBlur, { once: true })\n }\n\n /**\n * Handle element blur\n */\n function onBlur() {\n options.onBlur?.call($element)\n\n if (!isFocusable) {\n $element.removeAttribute('tabindex')\n }\n }\n\n // Add listener to reset element on blur, after focus\n $element.addEventListener('focus', onFocus, { once: true })\n\n // Focus element\n options.onBeforeFocus?.call($element)\n $element.focus()\n}\n\n/**\n * Checks if component is already initialised\n *\n * @internal\n * @param {Element} $root - HTML element to be checked\n * @param {string} moduleName - name of component module\n * @returns {boolean} Whether component is already initialised\n */\nexport function isInitialised($root, moduleName) {\n return (\n $root instanceof HTMLElement &&\n $root.hasAttribute(`data-${moduleName}-init`)\n )\n}\n\n/**\n * Checks if GOV.UK Frontend is supported on this page\n *\n * Some browsers will load and run our JavaScript but GOV.UK Frontend\n * won't be supported.\n *\n * @param {HTMLElement | null} [$scope] - (internal) `<body>` HTML element checked for browser support\n * @returns {boolean} Whether GOV.UK Frontend is supported on this page\n */\nexport function isSupported($scope = document.body) {\n if (!$scope) {\n return false\n }\n\n return $scope.classList.contains('govuk-frontend-supported')\n}\n\n/**\n * Check for an array\n *\n * @internal\n * @param {unknown} option - Option to check\n * @returns {boolean} Whether the option is an array\n */\nfunction isArray(option) {\n return Array.isArray(option)\n}\n\n/**\n * Check for an object\n *\n * @internal\n * @template {Partial<Record<keyof ObjectType, unknown>>} ObjectType\n * @param {unknown | ObjectType} option - Option to check\n * @returns {option is ObjectType} Whether the option is an object\n */\nexport function isObject(option) {\n return !!option && typeof option === 'object' && !isArray(option)\n}\n\n/**\n * Check for valid scope\n *\n * @internal\n * @template {Element | Document} ScopeType\n * @param {unknown | ScopeType} $scope - Scope of the document to search within\n * @returns {$scope is ScopeType} Whether the scope can be queried\n */\nexport function isScope($scope) {\n return !!$scope && ($scope instanceof Element || $scope instanceof Document)\n}\n\n/**\n * Format error message\n *\n * @internal\n * @param {ComponentWithModuleName} Component - Component that threw the error\n * @param {string} message - Error message\n * @returns {string} - Formatted error message\n */\nexport function formatErrorMessage(Component, message) {\n return `${Component.moduleName}: ${message}`\n}\n\n/* eslint-disable jsdoc/valid-types --\n * `{new(...args: any[] ): object}` is not recognised as valid\n * https://github.com/gajus/eslint-plugin-jsdoc/issues/145#issuecomment-1308722878\n * https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/131\n **/\n\n/**\n * @typedef ComponentWithModuleName\n * @property {string} moduleName - Name of the component\n */\n\n/* eslint-enable jsdoc/valid-types */\n","import { formatErrorMessage, isObject } from '../common/index.mjs'\n\n/**\n * GOV.UK Frontend error\n *\n * A base class for `Error`s thrown by GOV.UK Frontend.\n *\n * It is meant to be extended into specific types of errors\n * to be thrown by our code.\n *\n * @example\n * ```js\n * class MissingRootError extends GOVUKFrontendError {\n * // Setting an explicit name is important as extending the class will not\n * // set a new `name` on the subclass. The `name` property is important\n * // to ensure intelligible error names even if the class name gets\n * // mangled by a minifier\n * name = \"MissingRootError\"\n * }\n * ```\n * @virtual\n */\nexport class GOVUKFrontendError extends Error {\n name = 'GOVUKFrontendError'\n}\n\n/**\n * Indicates that GOV.UK Frontend is not supported\n */\nexport class SupportError extends GOVUKFrontendError {\n name = 'SupportError'\n\n /**\n * Checks if GOV.UK Frontend is supported on this page\n *\n * @param {HTMLElement | null} [$scope] - HTML element `<body>` checked for browser support\n */\n constructor($scope = document.body) {\n const supportMessage =\n 'noModule' in HTMLScriptElement.prototype\n ? 'GOV.UK Frontend initialised without `<body class=\"govuk-frontend-supported\">` from template `<script>` snippet'\n : 'GOV.UK Frontend is not supported in this browser'\n\n super(\n $scope\n ? supportMessage\n : 'GOV.UK Frontend initialised without `<script type=\"module\">`'\n )\n }\n}\n\n/**\n * Indicates that a component has received an illegal configuration\n */\nexport class ConfigError extends GOVUKFrontendError {\n name = 'ConfigError'\n}\n\n/**\n * Indicates an issue with an element (possibly `null` or `undefined`)\n */\nexport class ElementError extends GOVUKFrontendError {\n name = 'ElementError'\n\n /**\n * @internal\n * @overload\n * @param {string} message - Element error message\n */\n\n /**\n * @internal\n * @overload\n * @param {ElementErrorOptions} options - Element error options\n */\n\n /**\n * @internal\n * @param {string | ElementErrorOptions} messageOrOptions - Element error message or options\n */\n constructor(messageOrOptions) {\n let message = typeof messageOrOptions === 'string' ? messageOrOptions : ''\n\n // Build message from options\n if (isObject(messageOrOptions)) {\n const { component, identifier, element, expectedType } = messageOrOptions\n\n message = identifier\n\n // Append reason\n message += element\n ? ` is not of type ${expectedType ?? 'HTMLElement'}`\n : ' not found'\n\n // Prepend with module name (optional)\n if (component) {\n message = formatErrorMessage(component, message)\n }\n }\n\n super(message)\n }\n}\n\n/**\n * Indicates that a component is already initialised\n */\nexport class InitError extends GOVUKFrontendError {\n name = 'InitError'\n\n /**\n * @internal\n * @param {ComponentWithModuleName | string} componentOrMessage - name of the component module\n */\n constructor(componentOrMessage) {\n const message =\n typeof componentOrMessage === 'string'\n ? componentOrMessage\n : formatErrorMessage(\n componentOrMessage,\n `Root element (\\`$root\\`) already initialised`\n )\n\n super(message)\n }\n}\n\n/**\n * Element error options\n *\n * @internal\n * @typedef {object} ElementErrorOptions\n * @property {Element | Document | null} [element] - The element in error (optional)\n * @property {ComponentWithModuleName} [component] - Component throwing the error (optional)\n * @property {string} identifier - An identifier that'll let the user understand which element has an error. This is whatever makes the most sense\n * @property {string} [expectedType] - The type that was expected for the identifier (optional)\n */\n\n/**\n * @import { ComponentWithModuleName } from '../common/index.mjs'\n */\n","import { isInitialised, isSupported } from './common/index.mjs'\nimport { ElementError, InitError, SupportError } from './errors/index.mjs'\n\n/**\n * Base Component class\n *\n * Centralises the behaviours shared by our components\n *\n * @virtual\n * @template {Element} [RootElementType=HTMLElement]\n */\nexport class Component {\n /**\n * @type {typeof Element}\n */\n static elementType = HTMLElement\n\n // allows Typescript user to work around the lack of types\n // in GOVUKFrontend package, Typescript is not aware of $root\n // in components that extend GOVUKFrontendComponent\n /**\n * Returns the root element of the component\n *\n * @protected\n * @returns {RootElementType} - the root element of component\n */\n get $root() {\n return this._$root\n }\n\n /**\n * @protected\n * @type {RootElementType}\n */\n _$root\n\n /**\n * Constructs a new component, validating that GOV.UK Frontend is supported\n *\n * @internal\n * @param {Element | null} [$root] - HTML element to use for component\n */\n constructor($root) {\n const childConstructor = /** @type {ChildClassConstructor} */ (\n this.constructor\n )\n\n // TypeScript does not enforce that inheriting classes will define a `moduleName`\n // (even if we add a `@virtual` `static moduleName` property to this class).\n // While we trust users to do this correctly, we do a little check to provide them\n // a helpful error message.\n //\n // After this, we'll be sure that `childConstructor` has a `moduleName`\n // as expected of the `ChildClassConstructor` we've cast `this.constructor` to.\n if (typeof childConstructor.moduleName !== 'string') {\n throw new InitError(`\\`moduleName\\` not defined in component`)\n }\n\n if (!($root instanceof childConstructor.elementType)) {\n throw new ElementError({\n element: $root,\n component: childConstructor,\n identifier: 'Root element (`$root`)',\n expectedType: childConstructor.elementType.name\n })\n } else {\n this._$root = /** @type {RootElementType} */ ($root)\n }\n\n childConstructor.checkSupport()\n\n this.checkInitialised()\n\n const moduleName = childConstructor.moduleName\n\n this.$root.setAttribute(`data-${moduleName}-init`, '')\n }\n\n /**\n * Validates whether component is already initialised\n *\n * @private\n * @throws {InitError} when component is already initialised\n */\n checkInitialised() {\n const constructor = /** @type {ChildClassConstructor} */ (this.constructor)\n const moduleName = constructor.moduleName\n\n if (moduleName && isInitialised(this.$root, moduleName)) {\n throw new InitError(constructor)\n }\n }\n\n /**\n * Validates whether components are supported\n *\n * @throws {SupportError} when the components are not supported\n */\n static checkSupport() {\n if (!isSupported()) {\n throw new SupportError()\n }\n }\n}\n\n/**\n * @typedef ChildClass\n * @property {string} moduleName - The module name that'll be looked for in the DOM when initialising the component\n */\n\n/**\n * @typedef {typeof Component & ChildClass} ChildClassConstructor\n */\n","import { setFocus } from '../../common/index.mjs'\nimport { Component } from '../../component.mjs'\nimport { ElementError } from '../../errors/index.mjs'\n\n/**\n * Skip link component\n *\n * @preserve\n * @augments Component<HTMLAnchorElement>\n */\nexport class SkipLink extends Component {\n static elementType = HTMLAnchorElement\n\n /**\n * @param {Element | null} $root - HTML element to use for skip link\n * @throws {ElementError} when $root is not set or the wrong type\n * @throws {ElementError} when $root.hash does not contain a hash\n * @throws {ElementError} when the linked element is missing or the wrong type\n */\n constructor($root) {\n super($root)\n\n const hash = this.$root.hash\n const href = this.$root.getAttribute('href') ?? ''\n\n // Return early for external URLs or links to other pages\n if (\n this.$root.origin !== window.location.origin ||\n this.$root.pathname !== window.location.pathname\n ) {\n return\n }\n\n const linkedElementId = hash.replace('#', '')\n\n // Check link path matching current page\n if (!linkedElementId) {\n throw new ElementError(\n `Skip link: Target link (\\`href=\"${href}\"\\`) has no hash fragment`\n )\n }\n\n const $linkedElement = document.getElementById(linkedElementId)\n\n // Check for link target element\n if (!$linkedElement) {\n throw new ElementError({\n component: SkipLink,\n element: $linkedElement,\n identifier: `Target content (\\`id=\"${linkedElementId}\"\\`)`\n })\n }\n\n /**\n * Focus the linked element on click\n *\n * Adds a helper CSS class to hide native focus styles,\n * but removes it on blur to restore native focus styles\n */\n this.$root.addEventListener('click', () =>\n setFocus($linkedElement, {\n onBeforeFocus() {\n $linkedElement.classList.add('govuk-skip-link-focused-element')\n },\n onBlur() {\n $linkedElement.classList.remove('govuk-skip-link-focused-element')\n }\n })\n )\n }\n\n /**\n * Name for the component used when initialising using data-module attributes.\n */\n static moduleName = 'govuk-skip-link'\n}\n"],"names":["setFocus","$element","options","_options$onBeforeFocu","isFocusable","getAttribute","setAttribute","onFocus","addEventListener","onBlur","once","_options$onBlur","call","removeAttribute","onBeforeFocus","focus","isInitialised","$root","moduleName","HTMLElement","hasAttribute","isSupported","$scope","document","body","classList","contains","isArray","option","Array","isObject","formatErrorMessage","Component","message","GOVUKFrontendError","Error","constructor","args","name","SupportError","supportMessage","HTMLScriptElement","prototype","ElementError","messageOrOptions","component","identifier","element","expectedType","InitError","componentOrMessage","_$root","childConstructor","elementType","checkSupport","checkInitialised","SkipLink","_this$$root$getAttrib","hash","href","origin","window","location","pathname","linkedElementId","replace","$linkedElement","getElementById","add","remove","HTMLAnchorElement"],"mappings":";;;;;;EA0CO,SAASA,QAAQA,CAACC,QAAQ,EAAEC,OAAO,GAAG,EAAE,EAAE;EAAA,EAAA,IAAAC,qBAAA;EAC/C,EAAA,MAAMC,WAAW,GAAGH,QAAQ,CAACI,YAAY,CAAC,UAAU,CAAC;IAErD,IAAI,CAACD,WAAW,EAAE;EAChBH,IAAAA,QAAQ,CAACK,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC;EACzC,EAAA;IAKA,SAASC,OAAOA,GAAG;EACjBN,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AAM,KAAKC,MAAM,CAACC,QAAQ,CAACF,MAAM,IAC5C,IAAI,CAAC3C,KAAK,CAAC8C,QAAQ,KAAKF,MAAM,CAACC,QAAQ,CAACC,QAAQ,EAChD;EACA,MAAA;EACF,IAAA;MAEA,MAAMC,eAAe,GAAGN,IAAI,CAACO,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC;MAG7C,IAAI,CAACD,eAAe,EAAE;EACpB,MAAA,MAAM,IAAIrB,YAAY,CACpB,CAAA,gCAAA,EAAmCgB,IAAI,2BACzC,CAAC;EACH,IAAA;EAEA,IAAA,MAAMO,cAAc,GAAG3C,QAAQ,CAAC4C,cAAc,CAACH,eAAe,CAAC;MAG/D,IAAI,CAACE,cAAc,EAAE;QACnB,MAAM,IAAIvB,YAAY,CAAC;EACrBE,QAAAA,SAAS,EAAEW,QAAQ;EACnBT,QAAAA,OAAO,EAAEmB,cAAc;UACvBpB,UAAU,EAAE,yBAAyBkB,eAAe,CAAA,IAAA;EACtD,OAAC,CAAC;EACJ,IAAA;MAQA,IAAI,CAAC/C,KAAK,CAACT,gBAAgB,CAAC,OAAO,EAAE,MACnCR,QAAQ,CAACkE,cAAc,EAAE;EACvBpD,MAAAA,aAAaA,GAAG;EACdoD,QAAAA,cAAc,CAACzC,SAAS,CAAC2C,GAAG,CAAC,iCAAiC,CAAC;QACjE,CAAC;EACD3D,MAAAA,MAAMA,GAAG;EACPyD,QAAAA,cAAc,CAACzC,SAAS,CAAC4C,MAAM,CAAC,iCAAiC,CAAC;EACpE,MAAA;EACF,KAAC,CACH,CAAC;EACH,EAAA;EAMF;EAjEab,QAAQ,CACZH,WAAW,GAAGiB,iBAAiB;EAD3Bd,QAAQ,CAgEZtC,UAAU,GAAG,iBAAiB;;;;;;;;"}
1
+ {"version":3,"file":"skip-link.bundle.js","sources":["../../../../src/govuk/common/index.mjs","../../../../src/govuk/errors/index.mjs","../../../../src/govuk/component.mjs","../../../../src/govuk/components/skip-link/skip-link.mjs"],"sourcesContent":["/**\n * Common helpers which do not require polyfill.\n *\n * IMPORTANT: If a helper require a polyfill, please isolate it in its own module\n * so that the polyfill can be properly tree-shaken and does not burden\n * the components that do not need that helper\n */\n\n/**\n * Get GOV.UK Frontend breakpoint value from CSS custom property\n *\n * @private\n * @param {string} name - Breakpoint name\n * @returns {{ property: string, value?: string }} Breakpoint object\n */\nexport function getBreakpoint(name) {\n const property = `--govuk-breakpoint-${name}`\n\n // Get value from `<html>` with breakpoints on CSS :root\n const value = window\n .getComputedStyle(document.documentElement)\n .getPropertyValue(property)\n\n return {\n property,\n value: value || undefined\n }\n}\n\n/**\n * Move focus to element\n *\n * Sets tabindex to -1 to make the element programmatically focusable,\n * but removes it on blur as the element doesn't need to be focused again.\n *\n * @private\n * @template {HTMLElement} FocusElement\n * @param {FocusElement} $element - HTML element\n * @param {object} [options] - Handler options\n * @param {function(this: FocusElement): void} [options.onBeforeFocus] - Callback before focus\n * @param {function(this: FocusElement): void} [options.onBlur] - Callback on blur\n */\nexport function setFocus($element, options = {}) {\n const isFocusable = $element.getAttribute('tabindex')\n\n if (!isFocusable) {\n $element.setAttribute('tabindex', '-1')\n }\n\n /**\n * Handle element focus\n */\n function onFocus() {\n $element.addEventListener('blur', onBlur, { once: true })\n }\n\n /**\n * Handle element blur\n */\n function onBlur() {\n options.onBlur?.call($element)\n\n if (!isFocusable) {\n $element.removeAttribute('tabindex')\n }\n }\n\n // Add listener to reset element on blur, after focus\n $element.addEventListener('focus', onFocus, { once: true })\n\n // Focus element\n options.onBeforeFocus?.call($element)\n $element.focus()\n}\n\n/**\n * Checks if component is already initialised\n *\n * @internal\n * @param {Element} $root - HTML element to be checked\n * @param {string} moduleName - name of component module\n * @returns {boolean} Whether component is already initialised\n */\nexport function isInitialised($root, moduleName) {\n return (\n $root instanceof HTMLElement &&\n $root.hasAttribute(`data-${moduleName}-init`)\n )\n}\n\n/**\n * Checks if GOV.UK Frontend is supported on this page\n *\n * Some browsers will load and run our JavaScript but GOV.UK Frontend\n * won't be supported.\n *\n * @param {HTMLElement | null} [$scope] - (internal) `<body>` HTML element checked for browser support\n * @returns {boolean} Whether GOV.UK Frontend is supported on this page\n */\nexport function isSupported($scope = document.body) {\n if (!$scope) {\n return false\n }\n\n return $scope.classList.contains('govuk-frontend-supported')\n}\n\n/**\n * Check for an array\n *\n * @internal\n * @param {unknown} option - Option to check\n * @returns {boolean} Whether the option is an array\n */\nfunction isArray(option) {\n return Array.isArray(option)\n}\n\n/**\n * Check for an object\n *\n * @internal\n * @template {Partial<Record<keyof ObjectType, unknown>>} ObjectType\n * @param {unknown | ObjectType} option - Option to check\n * @returns {option is ObjectType} Whether the option is an object\n */\nexport function isObject(option) {\n return !!option && typeof option === 'object' && !isArray(option)\n}\n\n/**\n * Check for valid scope\n *\n * @internal\n * @template {Element | Document} ScopeType\n * @param {unknown | ScopeType} $scope - Scope of the document to search within\n * @returns {$scope is ScopeType} Whether the scope can be queried\n */\nexport function isScope($scope) {\n return !!$scope && ($scope instanceof Element || $scope instanceof Document)\n}\n\n/**\n * Format error message\n *\n * @internal\n * @param {ComponentWithModuleName} Component - Component that threw the error\n * @param {string} message - Error message\n * @returns {string} - Formatted error message\n */\nexport function formatErrorMessage(Component, message) {\n return `${Component.moduleName}: ${message}`\n}\n\n/* eslint-disable jsdoc/valid-types --\n * `{new(...args: any[] ): object}` is not recognised as valid\n * https://github.com/gajus/eslint-plugin-jsdoc/issues/145#issuecomment-1308722878\n * https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/131\n **/\n\n/**\n * @typedef ComponentWithModuleName\n * @property {string} moduleName - Name of the component\n */\n\n/* eslint-enable jsdoc/valid-types */\n","import { formatErrorMessage, isObject, isScope } from '../common/index.mjs'\n\n/**\n * GOV.UK Frontend error\n *\n * A base class for `Error`s thrown by GOV.UK Frontend.\n *\n * It is meant to be extended into specific types of errors\n * to be thrown by our code.\n *\n * @example\n * ```js\n * class MissingRootError extends GOVUKFrontendError {\n * // Setting an explicit name is important as extending the class will not\n * // set a new `name` on the subclass. The `name` property is important\n * // to ensure intelligible error names even if the class name gets\n * // mangled by a minifier\n * name = \"MissingRootError\"\n * }\n * ```\n * @virtual\n */\nexport class GOVUKFrontendError extends Error {\n name = 'GOVUKFrontendError'\n}\n\n/**\n * Indicates that GOV.UK Frontend is not supported\n */\nexport class SupportError extends GOVUKFrontendError {\n name = 'SupportError'\n\n /**\n * Checks if GOV.UK Frontend is supported on this page\n *\n * @param {Element | Document | null | string} [scopeOrMessage] - HTML element `<body>` checked for browser support or support error message\n */\n constructor(scopeOrMessage = document.body) {\n let supportMessage =\n 'noModule' in HTMLScriptElement.prototype\n ? 'GOV.UK Frontend initialised without `<body class=\"govuk-frontend-supported\">` from template `<script>` snippet'\n : 'GOV.UK Frontend is not supported in this browser'\n\n if (!isScope(scopeOrMessage)) {\n supportMessage =\n 'GOV.UK Frontend initialised without `<script type=\"module\">`'\n }\n\n super(typeof scopeOrMessage === 'string' ? scopeOrMessage : supportMessage)\n }\n}\n\n/**\n * Indicates that a component has received an illegal configuration\n */\nexport class ConfigError extends GOVUKFrontendError {\n name = 'ConfigError'\n}\n\n/**\n * Indicates an issue with an element (possibly `null` or `undefined`)\n */\nexport class ElementError extends GOVUKFrontendError {\n name = 'ElementError'\n\n /**\n * @internal\n * @overload\n * @param {string} message - Element error message\n */\n\n /**\n * @internal\n * @overload\n * @param {ElementErrorOptions} options - Element error options\n */\n\n /**\n * @internal\n * @param {string | ElementErrorOptions} messageOrOptions - Element error message or options\n */\n constructor(messageOrOptions) {\n let message = typeof messageOrOptions === 'string' ? messageOrOptions : ''\n\n // Build message from options\n if (isObject(messageOrOptions)) {\n const { component, identifier, element, expectedType } = messageOrOptions\n\n message = identifier\n\n // Append reason\n message += element\n ? ` is not of type ${expectedType ?? 'HTMLElement'}`\n : ' not found'\n\n // Prepend with module name (optional)\n if (component) {\n message = formatErrorMessage(component, message)\n }\n }\n\n super(message)\n }\n}\n\n/**\n * Indicates that a component is already initialised\n */\nexport class InitError extends GOVUKFrontendError {\n name = 'InitError'\n\n /**\n * @internal\n * @param {ComponentWithModuleName | string} componentOrMessage - name of the component module\n */\n constructor(componentOrMessage) {\n const message =\n typeof componentOrMessage === 'string'\n ? componentOrMessage\n : formatErrorMessage(\n componentOrMessage,\n `Root element (\\`$root\\`) already initialised`\n )\n\n super(message)\n }\n}\n\n/**\n * Element error options\n *\n * @internal\n * @typedef {object} ElementErrorOptions\n * @property {Element | Document | null} [element] - The element in error (optional)\n * @property {ComponentWithModuleName} [component] - Component throwing the error (optional)\n * @property {string} identifier - An identifier that'll let the user understand which element has an error. This is whatever makes the most sense\n * @property {string} [expectedType] - The type that was expected for the identifier (optional)\n */\n\n/**\n * @import { ComponentWithModuleName } from '../common/index.mjs'\n */\n","/* eslint-disable es-x/no-global-this */\n\nimport { isInitialised, isSupported } from './common/index.mjs'\nimport { ElementError, InitError, SupportError } from './errors/index.mjs'\n\nconst _self =\n typeof globalThis !== 'undefined'\n ? globalThis // Modern browsers, Node.js\n : self // Old browsers, web workers\n\n/**\n * Base Component class\n *\n * Centralises the behaviours shared by our components\n *\n * @virtual\n * @template {Element} [RootElementType=HTMLElement]\n */\nexport class Component {\n /**\n * @type {typeof Element}\n */\n static elementType = _self.HTMLElement\n\n // allows Typescript user to work around the lack of types\n // in GOVUKFrontend package, Typescript is not aware of $root\n // in components that extend GOVUKFrontendComponent\n /**\n * Returns the root element of the component\n *\n * @protected\n * @returns {RootElementType} - the root element of component\n */\n get $root() {\n return this._$root\n }\n\n /**\n * @protected\n * @type {RootElementType}\n */\n _$root\n\n /**\n * Constructs a new component, validating that GOV.UK Frontend is supported\n *\n * @internal\n * @param {Element | null} [$root] - HTML element to use for component\n */\n constructor($root) {\n const childConstructor = /** @type {ChildClassConstructor} */ (\n this.constructor\n )\n\n // TypeScript does not enforce that inheriting classes will define a `moduleName`\n // (even if we add a `@virtual` `static moduleName` property to this class).\n // While we trust users to do this correctly, we do a little check to provide them\n // a helpful error message.\n //\n // After this, we'll be sure that `childConstructor` has a `moduleName`\n // as expected of the `ChildClassConstructor` we've cast `this.constructor` to.\n if (typeof childConstructor.moduleName !== 'string') {\n throw new InitError(`\\`moduleName\\` not defined in component`)\n }\n\n if (!($root instanceof childConstructor.elementType)) {\n throw new ElementError({\n element: $root,\n component: childConstructor,\n identifier: 'Root element (`$root`)',\n expectedType: childConstructor.elementType.name\n })\n } else {\n this._$root = /** @type {RootElementType} */ ($root)\n }\n\n childConstructor.checkSupport()\n\n this.checkInitialised()\n\n const moduleName = childConstructor.moduleName\n\n this.$root.setAttribute(`data-${moduleName}-init`, '')\n }\n\n /**\n * Validates whether component is already initialised\n *\n * @private\n * @throws {InitError} when component is already initialised\n */\n checkInitialised() {\n const constructor = /** @type {ChildClassConstructor} */ (this.constructor)\n const moduleName = constructor.moduleName\n\n if (moduleName && isInitialised(this.$root, moduleName)) {\n throw new InitError(constructor)\n }\n }\n\n /**\n * Validates whether components are supported\n *\n * @throws {SupportError} when the components are not supported\n */\n static checkSupport() {\n if (!isSupported()) {\n throw new SupportError()\n }\n }\n}\n\n/**\n * @typedef ChildClass\n * @property {string} moduleName - The module name that'll be looked for in the DOM when initialising the component\n */\n\n/**\n * @typedef {typeof Component & ChildClass} ChildClassConstructor\n */\n","/* eslint-disable es-x/no-global-this */\n\nimport { setFocus } from '../../common/index.mjs'\nimport { Component } from '../../component.mjs'\nimport { ElementError } from '../../errors/index.mjs'\n\nconst _self =\n typeof globalThis !== 'undefined'\n ? globalThis // Modern browsers, Node.js\n : self // Old browsers, web workers\n\n/**\n * Skip link component\n *\n * @preserve\n * @augments Component<HTMLAnchorElement>\n */\nexport class SkipLink extends Component {\n static elementType = _self.HTMLAnchorElement\n\n /**\n * @param {Element | null} $root - HTML element to use for skip link\n * @throws {ElementError} when $root is not set or the wrong type\n * @throws {ElementError} when $root.hash does not contain a hash\n * @throws {ElementError} when the linked element is missing or the wrong type\n */\n constructor($root) {\n super($root)\n\n const hash = this.$root.hash\n const href = this.$root.getAttribute('href') ?? ''\n\n // Return early for external URLs or links to other pages\n if (\n this.$root.origin !== window.location.origin ||\n this.$root.pathname !== window.location.pathname\n ) {\n return\n }\n\n const linkedElementId = hash.replace('#', '')\n\n // Check link path matching current page\n if (!linkedElementId) {\n throw new ElementError(\n `Skip link: Target link (\\`href=\"${href}\"\\`) has no hash fragment`\n )\n }\n\n const $linkedElement = document.getElementById(linkedElementId)\n\n // Check for link target element\n if (!$linkedElement) {\n throw new ElementError({\n component: SkipLink,\n element: $linkedElement,\n identifier: `Target content (\\`id=\"${linkedElementId}\"\\`)`\n })\n }\n\n /**\n * Focus the linked element on click\n *\n * Adds a helper CSS class to hide native focus styles,\n * but removes it on blur to restore native focus styles\n */\n this.$root.addEventListener('click', () =>\n setFocus($linkedElement, {\n onBeforeFocus() {\n $linkedElement.classList.add('govuk-skip-link-focused-element')\n },\n onBlur() {\n $linkedElement.classList.remove('govuk-skip-link-focused-element')\n }\n })\n )\n }\n\n /**\n * Name for the component used when initialising using data-module attributes.\n */\n static moduleName = 'govuk-skip-link'\n}\n"],"names":["setFocus","$element","options","_options$onBeforeFocu","isFocusable","getAttribute","setAttribute","onFocus","addEventListener","onBlur","once","_options$onBlur","call","removeAttribute","onBeforeFocus","focus","isInitialised","$root","moduleName","HTMLElement","hasAttribute","isSupported","$scope","document","body","classList","contains","isArray","option","Array","isObject","isScope","Element","Document","formatErrorMessage","Component","message","GOVUKFrontendError","Error","constructor","args","name","SupportError","scopeOrMessage","supportMessage","HTMLScriptElement","prototype","ElementError","messageOrOptions","component","identifier","element","expectedType","InitError","componentOrMessage","_self","globalThis","self","_$root","childConstructor","elementType","checkSupport","checkInitialised","SkipLink","_this$$root$getAttrib","hash","href","origin","window","location","pathname","linkedElementId","replace","$linkedElement","getElementById","add","remove","HTMLAnchorElement"],"mappings":";;;;;;EA0CO,SAASA,QAAQA,CAACC,QAAQ,EAAEC,OAAO,GAAG,EAAE,EAAE;EAAA,EAAA,IAAAC,qBAAA;EAC/C,EAAA,MAAMC,WAAW,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CAAC;EACJ,IAAA;MAQA,IAAI,CAACtD,KAAK,CAACT,gBAAgB,CAAC,OAAO,EAAE,MACnCR,QAAQ,CAACyE,cAAc,EAAE;EACvB3D,MAAAA,aAAaA,GAAG;EACd2D,QAAAA,cAAc,CAAChD,SAAS,CAACkD,GAAG,CAAC,iCAAiC,CAAC;QACjE,CAAC;EACDlE,MAAAA,MAAMA,GAAG;EACPgE,QAAAA,cAAc,CAAChD,SAAS,CAACmD,MAAM,CAAC,iCAAiC,CAAC;EACpE,MAAA;EACF,KAAC,CACH,CAAC;EACH,EAAA;EAMF;EAjEab,QAAQ,CACZH,WAAW,GAAGL,KAAK,CAACsB,iBAAiB;EADjCd,QAAQ,CAgEZ7C,UAAU,GAAG,iBAAiB;;;;"}
@@ -47,6 +47,9 @@ function isArray(option) {
47
47
  function isObject(option) {
48
48
  return !!option && typeof option === 'object' && !isArray(option);
49
49
  }
50
+ function isScope($scope) {
51
+ return !!$scope && ($scope instanceof Element || $scope instanceof Document);
52
+ }
50
53
  function formatErrorMessage(Component, message) {
51
54
  return `${Component.moduleName}: ${message}`;
52
55
  }
@@ -65,11 +68,14 @@ class SupportError extends GOVUKFrontendError {
65
68
  /**
66
69
  * Checks if GOV.UK Frontend is supported on this page
67
70
  *
68
- * @param {HTMLElement | null} [$scope] - HTML element `<body>` checked for browser support
71
+ * @param {Element | Document | null | string} [scopeOrMessage] - HTML element `<body>` checked for browser support or support error message
69
72
  */
70
- constructor($scope = document.body) {
71
- 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';
72
- super($scope ? supportMessage : 'GOV.UK Frontend initialised without `<script type="module">`');
73
+ constructor(scopeOrMessage = document.body) {
74
+ let 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';
75
+ if (!isScope(scopeOrMessage)) {
76
+ supportMessage = 'GOV.UK Frontend initialised without `<script type="module">`';
77
+ }
78
+ super(typeof scopeOrMessage === 'string' ? scopeOrMessage : supportMessage);
73
79
  this.name = 'SupportError';
74
80
  }
75
81
  }
@@ -104,6 +110,7 @@ class InitError extends GOVUKFrontendError {
104
110
  * @import { ComponentWithModuleName } from '../common/index.mjs'
105
111
  */
106
112
 
113
+ const _self$1 = typeof globalThis !== 'undefined' ? globalThis : self;
107
114
  class Component {
108
115
  /**
109
116
  * Returns the root element of the component
@@ -157,8 +164,9 @@ class Component {
157
164
  /**
158
165
  * @typedef {typeof Component & ChildClass} ChildClassConstructor
159
166
  */
160
- Component.elementType = HTMLElement;
167
+ Component.elementType = _self$1.HTMLElement;
161
168
 
169
+ const _self = typeof globalThis !== 'undefined' ? globalThis : self;
162
170
  /**
163
171
  * Skip link component
164
172
  *
@@ -202,7 +210,7 @@ class SkipLink extends Component {
202
210
  }));
203
211
  }
204
212
  }
205
- SkipLink.elementType = HTMLAnchorElement;
213
+ SkipLink.elementType = _self.HTMLAnchorElement;
206
214
  SkipLink.moduleName = 'govuk-skip-link';
207
215
 
208
216
  export { SkipLink };
@@ -1 +1 @@
1
- {"version":3,"file":"skip-link.bundle.mjs","sources":["../../../../src/govuk/common/index.mjs","../../../../src/govuk/errors/index.mjs","../../../../src/govuk/component.mjs","../../../../src/govuk/components/skip-link/skip-link.mjs"],"sourcesContent":["/**\n * Common helpers which do not require polyfill.\n *\n * IMPORTANT: If a helper require a polyfill, please isolate it in its own module\n * so that the polyfill can be properly tree-shaken and does not burden\n * the components that do not need that helper\n */\n\n/**\n * Get GOV.UK Frontend breakpoint value from CSS custom property\n *\n * @private\n * @param {string} name - Breakpoint name\n * @returns {{ property: string, value?: string }} Breakpoint object\n */\nexport function getBreakpoint(name) {\n const property = `--govuk-breakpoint-${name}`\n\n // Get value from `<html>` with breakpoints on CSS :root\n const value = window\n .getComputedStyle(document.documentElement)\n .getPropertyValue(property)\n\n return {\n property,\n value: value || undefined\n }\n}\n\n/**\n * Move focus to element\n *\n * Sets tabindex to -1 to make the element programmatically focusable,\n * but removes it on blur as the element doesn't need to be focused again.\n *\n * @private\n * @template {HTMLElement} FocusElement\n * @param {FocusElement} $element - HTML element\n * @param {object} [options] - Handler options\n * @param {function(this: FocusElement): void} [options.onBeforeFocus] - Callback before focus\n * @param {function(this: FocusElement): void} [options.onBlur] - Callback on blur\n */\nexport function setFocus($element, options = {}) {\n const isFocusable = $element.getAttribute('tabindex')\n\n if (!isFocusable) {\n $element.setAttribute('tabindex', '-1')\n }\n\n /**\n * Handle element focus\n */\n function onFocus() {\n $element.addEventListener('blur', onBlur, { once: true })\n }\n\n /**\n * Handle element blur\n */\n function onBlur() {\n options.onBlur?.call($element)\n\n if (!isFocusable) {\n $element.removeAttribute('tabindex')\n }\n }\n\n // Add listener to reset element on blur, after focus\n $element.addEventListener('focus', onFocus, { once: true })\n\n // Focus element\n options.onBeforeFocus?.call($element)\n $element.focus()\n}\n\n/**\n * Checks if component is already initialised\n *\n * @internal\n * @param {Element} $root - HTML element to be checked\n * @param {string} moduleName - name of component module\n * @returns {boolean} Whether component is already initialised\n */\nexport function isInitialised($root, moduleName) {\n return (\n $root instanceof HTMLElement &&\n $root.hasAttribute(`data-${moduleName}-init`)\n )\n}\n\n/**\n * Checks if GOV.UK Frontend is supported on this page\n *\n * Some browsers will load and run our JavaScript but GOV.UK Frontend\n * won't be supported.\n *\n * @param {HTMLElement | null} [$scope] - (internal) `<body>` HTML element checked for browser support\n * @returns {boolean} Whether GOV.UK Frontend is supported on this page\n */\nexport function isSupported($scope = document.body) {\n if (!$scope) {\n return false\n }\n\n return $scope.classList.contains('govuk-frontend-supported')\n}\n\n/**\n * Check for an array\n *\n * @internal\n * @param {unknown} option - Option to check\n * @returns {boolean} Whether the option is an array\n */\nfunction isArray(option) {\n return Array.isArray(option)\n}\n\n/**\n * Check for an object\n *\n * @internal\n * @template {Partial<Record<keyof ObjectType, unknown>>} ObjectType\n * @param {unknown | ObjectType} option - Option to check\n * @returns {option is ObjectType} Whether the option is an object\n */\nexport function isObject(option) {\n return !!option && typeof option === 'object' && !isArray(option)\n}\n\n/**\n * Check for valid scope\n *\n * @internal\n * @template {Element | Document} ScopeType\n * @param {unknown | ScopeType} $scope - Scope of the document to search within\n * @returns {$scope is ScopeType} Whether the scope can be queried\n */\nexport function isScope($scope) {\n return !!$scope && ($scope instanceof Element || $scope instanceof Document)\n}\n\n/**\n * Format error message\n *\n * @internal\n * @param {ComponentWithModuleName} Component - Component that threw the error\n * @param {string} message - Error message\n * @returns {string} - Formatted error message\n */\nexport function formatErrorMessage(Component, message) {\n return `${Component.moduleName}: ${message}`\n}\n\n/* eslint-disable jsdoc/valid-types --\n * `{new(...args: any[] ): object}` is not recognised as valid\n * https://github.com/gajus/eslint-plugin-jsdoc/issues/145#issuecomment-1308722878\n * https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/131\n **/\n\n/**\n * @typedef ComponentWithModuleName\n * @property {string} moduleName - Name of the component\n */\n\n/* eslint-enable jsdoc/valid-types */\n","import { formatErrorMessage, isObject } from '../common/index.mjs'\n\n/**\n * GOV.UK Frontend error\n *\n * A base class for `Error`s thrown by GOV.UK Frontend.\n *\n * It is meant to be extended into specific types of errors\n * to be thrown by our code.\n *\n * @example\n * ```js\n * class MissingRootError extends GOVUKFrontendError {\n * // Setting an explicit name is important as extending the class will not\n * // set a new `name` on the subclass. The `name` property is important\n * // to ensure intelligible error names even if the class name gets\n * // mangled by a minifier\n * name = \"MissingRootError\"\n * }\n * ```\n * @virtual\n */\nexport class GOVUKFrontendError extends Error {\n name = 'GOVUKFrontendError'\n}\n\n/**\n * Indicates that GOV.UK Frontend is not supported\n */\nexport class SupportError extends GOVUKFrontendError {\n name = 'SupportError'\n\n /**\n * Checks if GOV.UK Frontend is supported on this page\n *\n * @param {HTMLElement | null} [$scope] - HTML element `<body>` checked for browser support\n */\n constructor($scope = document.body) {\n const supportMessage =\n 'noModule' in HTMLScriptElement.prototype\n ? 'GOV.UK Frontend initialised without `<body class=\"govuk-frontend-supported\">` from template `<script>` snippet'\n : 'GOV.UK Frontend is not supported in this browser'\n\n super(\n $scope\n ? supportMessage\n : 'GOV.UK Frontend initialised without `<script type=\"module\">`'\n )\n }\n}\n\n/**\n * Indicates that a component has received an illegal configuration\n */\nexport class ConfigError extends GOVUKFrontendError {\n name = 'ConfigError'\n}\n\n/**\n * Indicates an issue with an element (possibly `null` or `undefined`)\n */\nexport class ElementError extends GOVUKFrontendError {\n name = 'ElementError'\n\n /**\n * @internal\n * @overload\n * @param {string} message - Element error message\n */\n\n /**\n * @internal\n * @overload\n * @param {ElementErrorOptions} options - Element error options\n */\n\n /**\n * @internal\n * @param {string | ElementErrorOptions} messageOrOptions - Element error message or options\n */\n constructor(messageOrOptions) {\n let message = typeof messageOrOptions === 'string' ? messageOrOptions : ''\n\n // Build message from options\n if (isObject(messageOrOptions)) {\n const { component, identifier, element, expectedType } = messageOrOptions\n\n message = identifier\n\n // Append reason\n message += element\n ? ` is not of type ${expectedType ?? 'HTMLElement'}`\n : ' not found'\n\n // Prepend with module name (optional)\n if (component) {\n message = formatErrorMessage(component, message)\n }\n }\n\n super(message)\n }\n}\n\n/**\n * Indicates that a component is already initialised\n */\nexport class InitError extends GOVUKFrontendError {\n name = 'InitError'\n\n /**\n * @internal\n * @param {ComponentWithModuleName | string} componentOrMessage - name of the component module\n */\n constructor(componentOrMessage) {\n const message =\n typeof componentOrMessage === 'string'\n ? componentOrMessage\n : formatErrorMessage(\n componentOrMessage,\n `Root element (\\`$root\\`) already initialised`\n )\n\n super(message)\n }\n}\n\n/**\n * Element error options\n *\n * @internal\n * @typedef {object} ElementErrorOptions\n * @property {Element | Document | null} [element] - The element in error (optional)\n * @property {ComponentWithModuleName} [component] - Component throwing the error (optional)\n * @property {string} identifier - An identifier that'll let the user understand which element has an error. This is whatever makes the most sense\n * @property {string} [expectedType] - The type that was expected for the identifier (optional)\n */\n\n/**\n * @import { ComponentWithModuleName } from '../common/index.mjs'\n */\n","import { isInitialised, isSupported } from './common/index.mjs'\nimport { ElementError, InitError, SupportError } from './errors/index.mjs'\n\n/**\n * Base Component class\n *\n * Centralises the behaviours shared by our components\n *\n * @virtual\n * @template {Element} [RootElementType=HTMLElement]\n */\nexport class Component {\n /**\n * @type {typeof Element}\n */\n static elementType = HTMLElement\n\n // allows Typescript user to work around the lack of types\n // in GOVUKFrontend package, Typescript is not aware of $root\n // in components that extend GOVUKFrontendComponent\n /**\n * Returns the root element of the component\n *\n * @protected\n * @returns {RootElementType} - the root element of component\n */\n get $root() {\n return this._$root\n }\n\n /**\n * @protected\n * @type {RootElementType}\n */\n _$root\n\n /**\n * Constructs a new component, validating that GOV.UK Frontend is supported\n *\n * @internal\n * @param {Element | null} [$root] - HTML element to use for component\n */\n constructor($root) {\n const childConstructor = /** @type {ChildClassConstructor} */ (\n this.constructor\n )\n\n // TypeScript does not enforce that inheriting classes will define a `moduleName`\n // (even if we add a `@virtual` `static moduleName` property to this class).\n // While we trust users to do this correctly, we do a little check to provide them\n // a helpful error message.\n //\n // After this, we'll be sure that `childConstructor` has a `moduleName`\n // as expected of the `ChildClassConstructor` we've cast `this.constructor` to.\n if (typeof childConstructor.moduleName !== 'string') {\n throw new InitError(`\\`moduleName\\` not defined in component`)\n }\n\n if (!($root instanceof childConstructor.elementType)) {\n throw new ElementError({\n element: $root,\n component: childConstructor,\n identifier: 'Root element (`$root`)',\n expectedType: childConstructor.elementType.name\n })\n } else {\n this._$root = /** @type {RootElementType} */ ($root)\n }\n\n childConstructor.checkSupport()\n\n this.checkInitialised()\n\n const moduleName = childConstructor.moduleName\n\n this.$root.setAttribute(`data-${moduleName}-init`, '')\n }\n\n /**\n * Validates whether component is already initialised\n *\n * @private\n * @throws {InitError} when component is already initialised\n */\n checkInitialised() {\n const constructor = /** @type {ChildClassConstructor} */ (this.constructor)\n const moduleName = constructor.moduleName\n\n if (moduleName && isInitialised(this.$root, moduleName)) {\n throw new InitError(constructor)\n }\n }\n\n /**\n * Validates whether components are supported\n *\n * @throws {SupportError} when the components are not supported\n */\n static checkSupport() {\n if (!isSupported()) {\n throw new SupportError()\n }\n }\n}\n\n/**\n * @typedef ChildClass\n * @property {string} moduleName - The module name that'll be looked for in the DOM when initialising the component\n */\n\n/**\n * @typedef {typeof Component & ChildClass} ChildClassConstructor\n */\n","import { setFocus } from '../../common/index.mjs'\nimport { Component } from '../../component.mjs'\nimport { ElementError } from '../../errors/index.mjs'\n\n/**\n * Skip link component\n *\n * @preserve\n * @augments Component<HTMLAnchorElement>\n */\nexport class SkipLink extends Component {\n static elementType = HTMLAnchorElement\n\n /**\n * @param {Element | null} $root - HTML element to use for skip link\n * @throws {ElementError} when $root is not set or the wrong type\n * @throws {ElementError} when $root.hash does not contain a hash\n * @throws {ElementError} when the linked element is missing or the wrong type\n */\n constructor($root) {\n super($root)\n\n const hash = this.$root.hash\n const href = this.$root.getAttribute('href') ?? ''\n\n // Return early for external URLs or links to other pages\n if (\n this.$root.origin !== window.location.origin ||\n this.$root.pathname !== window.location.pathname\n ) {\n return\n }\n\n const linkedElementId = hash.replace('#', '')\n\n // Check link path matching current page\n if (!linkedElementId) {\n throw new ElementError(\n `Skip link: Target link (\\`href=\"${href}\"\\`) has no hash fragment`\n )\n }\n\n const $linkedElement = document.getElementById(linkedElementId)\n\n // Check for link target element\n if (!$linkedElement) {\n throw new ElementError({\n component: SkipLink,\n element: $linkedElement,\n identifier: `Target content (\\`id=\"${linkedElementId}\"\\`)`\n })\n }\n\n /**\n * Focus the linked element on click\n *\n * Adds a helper CSS class to hide native focus styles,\n * but removes it on blur to restore native focus styles\n */\n this.$root.addEventListener('click', () =>\n setFocus($linkedElement, {\n onBeforeFocus() {\n $linkedElement.classList.add('govuk-skip-link-focused-element')\n },\n onBlur() {\n $linkedElement.classList.remove('govuk-skip-link-focused-element')\n }\n })\n )\n }\n\n /**\n * Name for the component used when initialising using data-module attributes.\n */\n static moduleName = 'govuk-skip-link'\n}\n"],"names":["setFocus","$element","options","_options$onBeforeFocu","isFocusable","getAttribute","setAttribute","onFocus","addEventListener","onBlur","once","_options$onBlur","call","removeAttribute","onBeforeFocus","focus","isInitialised","$root","moduleName","HTMLElement","hasAttribute","isSupported","$scope","document","body","classList","contains","isArray","option","Array","isObject","formatErrorMessage","Component","message","GOVUKFrontendError","Error","constructor","args","name","SupportError","supportMessage","HTMLScriptElement","prototype","ElementError","messageOrOptions","component","identifier","element","expectedType","InitError","componentOrMessage","_$root","childConstructor","elementType","checkSupport","checkInitialised","SkipLink","_this$$root$getAttrib","hash","href","origin","window","location","pathname","linkedElementId","replace","$linkedElement","getElementById","add","remove","HTMLAnchorElement"],"mappings":"AA0CO,SAASA,QAAQA,CAACC,QAAQ,EAAEC,OAAO,GAAG,EAAE,EAAE;AAAA,EAAA,IAAAC,qBAAA;AAC/C,EAAA,MAAMC,WAAW,GAAGH,QAAQ,CAACI,YAAY,CAAC,UAAU,CAAC;EAErD,IAAI,CAACD,WAAW,EAAE;AAChBH,IAAAA,QAAQ,CAACK,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC;AACzC,EAAA;EAKA,SAASC,OAAOA,GAAG;AACjBN,IAAAA,QAAQ,CAACO,gBAAgB,CAAC,MAAM,EAAEC,MAAM,EAAE;AAAEC,MAAAA,IAAI,EAAE;AAAK,KAAC,CAAC;AAC3D,EAAA;EAKA,SAASD,MAAMA,GAAG;AAAA,IAAA,IAAAE,eAAA;IAChB,CAAAA,eAAA,GAAAT,OAAO,CAACO,MAAM,KAAA,IAAA,IAAdE,eAAA,CAAgBC,IAAI,CAACX,QAAQ,CAAC;IAE9B,IAAI,CAACG,WAAW,EAAE;AAChBH,MAAAA,QAAQ,CAACY,eAAe,CAAC,UAAU,CAAC;AACtC,IAAA;AACF,EAAA;AAGAZ,EAAAA,QAAQ,CAACO,gBAAgB,CAAC,OAAO,EAAED,OAAO,EAAE;AAAEG,IAAAA,IAAI,EAAE;AAAK,GAAC,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AAC;AACrBE,QAAAA,SAAS,EAAEW,QAAQ;AACnBT,QAAAA,OAAO,EAAEmB,cAAc;QACvBpB,UAAU,EAAE,yBAAyBkB,eAAe,CAAA,IAAA;AACtD,OAAC,CAAC;AACJ,IAAA;IAQA,IAAI,CAAC/C,KAAK,CAACT,gBAAgB,CAAC,OAAO,EAAE,MACnCR,QAAQ,CAACkE,cAAc,EAAE;AACvBpD,MAAAA,aAAaA,GAAG;AACdoD,QAAAA,cAAc,CAACzC,SAAS,CAAC2C,GAAG,CAAC,iCAAiC,CAAC;MACjE,CAAC;AACD3D,MAAAA,MAAMA,GAAG;AACPyD,QAAAA,cAAc,CAACzC,SAAS,CAAC4C,MAAM,CAAC,iCAAiC,CAAC;AACpE,MAAA;AACF,KAAC,CACH,CAAC;AACH,EAAA;AAMF;AAjEab,QAAQ,CACZH,WAAW,GAAGiB,iBAAiB;AAD3Bd,QAAQ,CAgEZtC,UAAU,GAAG,iBAAiB;;;;"}
1
+ {"version":3,"file":"skip-link.bundle.mjs","sources":["../../../../src/govuk/common/index.mjs","../../../../src/govuk/errors/index.mjs","../../../../src/govuk/component.mjs","../../../../src/govuk/components/skip-link/skip-link.mjs"],"sourcesContent":["/**\n * Common helpers which do not require polyfill.\n *\n * IMPORTANT: If a helper require a polyfill, please isolate it in its own module\n * so that the polyfill can be properly tree-shaken and does not burden\n * the components that do not need that helper\n */\n\n/**\n * Get GOV.UK Frontend breakpoint value from CSS custom property\n *\n * @private\n * @param {string} name - Breakpoint name\n * @returns {{ property: string, value?: string }} Breakpoint object\n */\nexport function getBreakpoint(name) {\n const property = `--govuk-breakpoint-${name}`\n\n // Get value from `<html>` with breakpoints on CSS :root\n const value = window\n .getComputedStyle(document.documentElement)\n .getPropertyValue(property)\n\n return {\n property,\n value: value || undefined\n }\n}\n\n/**\n * Move focus to element\n *\n * Sets tabindex to -1 to make the element programmatically focusable,\n * but removes it on blur as the element doesn't need to be focused again.\n *\n * @private\n * @template {HTMLElement} FocusElement\n * @param {FocusElement} $element - HTML element\n * @param {object} [options] - Handler options\n * @param {function(this: FocusElement): void} [options.onBeforeFocus] - Callback before focus\n * @param {function(this: FocusElement): void} [options.onBlur] - Callback on blur\n */\nexport function setFocus($element, options = {}) {\n const isFocusable = $element.getAttribute('tabindex')\n\n if (!isFocusable) {\n $element.setAttribute('tabindex', '-1')\n }\n\n /**\n * Handle element focus\n */\n function onFocus() {\n $element.addEventListener('blur', onBlur, { once: true })\n }\n\n /**\n * Handle element blur\n */\n function onBlur() {\n options.onBlur?.call($element)\n\n if (!isFocusable) {\n $element.removeAttribute('tabindex')\n }\n }\n\n // Add listener to reset element on blur, after focus\n $element.addEventListener('focus', onFocus, { once: true })\n\n // Focus element\n options.onBeforeFocus?.call($element)\n $element.focus()\n}\n\n/**\n * Checks if component is already initialised\n *\n * @internal\n * @param {Element} $root - HTML element to be checked\n * @param {string} moduleName - name of component module\n * @returns {boolean} Whether component is already initialised\n */\nexport function isInitialised($root, moduleName) {\n return (\n $root instanceof HTMLElement &&\n $root.hasAttribute(`data-${moduleName}-init`)\n )\n}\n\n/**\n * Checks if GOV.UK Frontend is supported on this page\n *\n * Some browsers will load and run our JavaScript but GOV.UK Frontend\n * won't be supported.\n *\n * @param {HTMLElement | null} [$scope] - (internal) `<body>` HTML element checked for browser support\n * @returns {boolean} Whether GOV.UK Frontend is supported on this page\n */\nexport function isSupported($scope = document.body) {\n if (!$scope) {\n return false\n }\n\n return $scope.classList.contains('govuk-frontend-supported')\n}\n\n/**\n * Check for an array\n *\n * @internal\n * @param {unknown} option - Option to check\n * @returns {boolean} Whether the option is an array\n */\nfunction isArray(option) {\n return Array.isArray(option)\n}\n\n/**\n * Check for an object\n *\n * @internal\n * @template {Partial<Record<keyof ObjectType, unknown>>} ObjectType\n * @param {unknown | ObjectType} option - Option to check\n * @returns {option is ObjectType} Whether the option is an object\n */\nexport function isObject(option) {\n return !!option && typeof option === 'object' && !isArray(option)\n}\n\n/**\n * Check for valid scope\n *\n * @internal\n * @template {Element | Document} ScopeType\n * @param {unknown | ScopeType} $scope - Scope of the document to search within\n * @returns {$scope is ScopeType} Whether the scope can be queried\n */\nexport function isScope($scope) {\n return !!$scope && ($scope instanceof Element || $scope instanceof Document)\n}\n\n/**\n * Format error message\n *\n * @internal\n * @param {ComponentWithModuleName} Component - Component that threw the error\n * @param {string} message - Error message\n * @returns {string} - Formatted error message\n */\nexport function formatErrorMessage(Component, message) {\n return `${Component.moduleName}: ${message}`\n}\n\n/* eslint-disable jsdoc/valid-types --\n * `{new(...args: any[] ): object}` is not recognised as valid\n * https://github.com/gajus/eslint-plugin-jsdoc/issues/145#issuecomment-1308722878\n * https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/131\n **/\n\n/**\n * @typedef ComponentWithModuleName\n * @property {string} moduleName - Name of the component\n */\n\n/* eslint-enable jsdoc/valid-types */\n","import { formatErrorMessage, isObject, isScope } from '../common/index.mjs'\n\n/**\n * GOV.UK Frontend error\n *\n * A base class for `Error`s thrown by GOV.UK Frontend.\n *\n * It is meant to be extended into specific types of errors\n * to be thrown by our code.\n *\n * @example\n * ```js\n * class MissingRootError extends GOVUKFrontendError {\n * // Setting an explicit name is important as extending the class will not\n * // set a new `name` on the subclass. The `name` property is important\n * // to ensure intelligible error names even if the class name gets\n * // mangled by a minifier\n * name = \"MissingRootError\"\n * }\n * ```\n * @virtual\n */\nexport class GOVUKFrontendError extends Error {\n name = 'GOVUKFrontendError'\n}\n\n/**\n * Indicates that GOV.UK Frontend is not supported\n */\nexport class SupportError extends GOVUKFrontendError {\n name = 'SupportError'\n\n /**\n * Checks if GOV.UK Frontend is supported on this page\n *\n * @param {Element | Document | null | string} [scopeOrMessage] - HTML element `<body>` checked for browser support or support error message\n */\n constructor(scopeOrMessage = document.body) {\n let supportMessage =\n 'noModule' in HTMLScriptElement.prototype\n ? 'GOV.UK Frontend initialised without `<body class=\"govuk-frontend-supported\">` from template `<script>` snippet'\n : 'GOV.UK Frontend is not supported in this browser'\n\n if (!isScope(scopeOrMessage)) {\n supportMessage =\n 'GOV.UK Frontend initialised without `<script type=\"module\">`'\n }\n\n super(typeof scopeOrMessage === 'string' ? scopeOrMessage : supportMessage)\n }\n}\n\n/**\n * Indicates that a component has received an illegal configuration\n */\nexport class ConfigError extends GOVUKFrontendError {\n name = 'ConfigError'\n}\n\n/**\n * Indicates an issue with an element (possibly `null` or `undefined`)\n */\nexport class ElementError extends GOVUKFrontendError {\n name = 'ElementError'\n\n /**\n * @internal\n * @overload\n * @param {string} message - Element error message\n */\n\n /**\n * @internal\n * @overload\n * @param {ElementErrorOptions} options - Element error options\n */\n\n /**\n * @internal\n * @param {string | ElementErrorOptions} messageOrOptions - Element error message or options\n */\n constructor(messageOrOptions) {\n let message = typeof messageOrOptions === 'string' ? messageOrOptions : ''\n\n // Build message from options\n if (isObject(messageOrOptions)) {\n const { component, identifier, element, expectedType } = messageOrOptions\n\n message = identifier\n\n // Append reason\n message += element\n ? ` is not of type ${expectedType ?? 'HTMLElement'}`\n : ' not found'\n\n // Prepend with module name (optional)\n if (component) {\n message = formatErrorMessage(component, message)\n }\n }\n\n super(message)\n }\n}\n\n/**\n * Indicates that a component is already initialised\n */\nexport class InitError extends GOVUKFrontendError {\n name = 'InitError'\n\n /**\n * @internal\n * @param {ComponentWithModuleName | string} componentOrMessage - name of the component module\n */\n constructor(componentOrMessage) {\n const message =\n typeof componentOrMessage === 'string'\n ? componentOrMessage\n : formatErrorMessage(\n componentOrMessage,\n `Root element (\\`$root\\`) already initialised`\n )\n\n super(message)\n }\n}\n\n/**\n * Element error options\n *\n * @internal\n * @typedef {object} ElementErrorOptions\n * @property {Element | Document | null} [element] - The element in error (optional)\n * @property {ComponentWithModuleName} [component] - Component throwing the error (optional)\n * @property {string} identifier - An identifier that'll let the user understand which element has an error. This is whatever makes the most sense\n * @property {string} [expectedType] - The type that was expected for the identifier (optional)\n */\n\n/**\n * @import { ComponentWithModuleName } from '../common/index.mjs'\n */\n","/* eslint-disable es-x/no-global-this */\n\nimport { isInitialised, isSupported } from './common/index.mjs'\nimport { ElementError, InitError, SupportError } from './errors/index.mjs'\n\nconst _self =\n typeof globalThis !== 'undefined'\n ? globalThis // Modern browsers, Node.js\n : self // Old browsers, web workers\n\n/**\n * Base Component class\n *\n * Centralises the behaviours shared by our components\n *\n * @virtual\n * @template {Element} [RootElementType=HTMLElement]\n */\nexport class Component {\n /**\n * @type {typeof Element}\n */\n static elementType = _self.HTMLElement\n\n // allows Typescript user to work around the lack of types\n // in GOVUKFrontend package, Typescript is not aware of $root\n // in components that extend GOVUKFrontendComponent\n /**\n * Returns the root element of the component\n *\n * @protected\n * @returns {RootElementType} - the root element of component\n */\n get $root() {\n return this._$root\n }\n\n /**\n * @protected\n * @type {RootElementType}\n */\n _$root\n\n /**\n * Constructs a new component, validating that GOV.UK Frontend is supported\n *\n * @internal\n * @param {Element | null} [$root] - HTML element to use for component\n */\n constructor($root) {\n const childConstructor = /** @type {ChildClassConstructor} */ (\n this.constructor\n )\n\n // TypeScript does not enforce that inheriting classes will define a `moduleName`\n // (even if we add a `@virtual` `static moduleName` property to this class).\n // While we trust users to do this correctly, we do a little check to provide them\n // a helpful error message.\n //\n // After this, we'll be sure that `childConstructor` has a `moduleName`\n // as expected of the `ChildClassConstructor` we've cast `this.constructor` to.\n if (typeof childConstructor.moduleName !== 'string') {\n throw new InitError(`\\`moduleName\\` not defined in component`)\n }\n\n if (!($root instanceof childConstructor.elementType)) {\n throw new ElementError({\n element: $root,\n component: childConstructor,\n identifier: 'Root element (`$root`)',\n expectedType: childConstructor.elementType.name\n })\n } else {\n this._$root = /** @type {RootElementType} */ ($root)\n }\n\n childConstructor.checkSupport()\n\n this.checkInitialised()\n\n const moduleName = childConstructor.moduleName\n\n this.$root.setAttribute(`data-${moduleName}-init`, '')\n }\n\n /**\n * Validates whether component is already initialised\n *\n * @private\n * @throws {InitError} when component is already initialised\n */\n checkInitialised() {\n const constructor = /** @type {ChildClassConstructor} */ (this.constructor)\n const moduleName = constructor.moduleName\n\n if (moduleName && isInitialised(this.$root, moduleName)) {\n throw new InitError(constructor)\n }\n }\n\n /**\n * Validates whether components are supported\n *\n * @throws {SupportError} when the components are not supported\n */\n static checkSupport() {\n if (!isSupported()) {\n throw new SupportError()\n }\n }\n}\n\n/**\n * @typedef ChildClass\n * @property {string} moduleName - The module name that'll be looked for in the DOM when initialising the component\n */\n\n/**\n * @typedef {typeof Component & ChildClass} ChildClassConstructor\n */\n","/* eslint-disable es-x/no-global-this */\n\nimport { setFocus } from '../../common/index.mjs'\nimport { Component } from '../../component.mjs'\nimport { ElementError } from '../../errors/index.mjs'\n\nconst _self =\n typeof globalThis !== 'undefined'\n ? globalThis // Modern browsers, Node.js\n : self // Old browsers, web workers\n\n/**\n * Skip link component\n *\n * @preserve\n * @augments Component<HTMLAnchorElement>\n */\nexport class SkipLink extends Component {\n static elementType = _self.HTMLAnchorElement\n\n /**\n * @param {Element | null} $root - HTML element to use for skip link\n * @throws {ElementError} when $root is not set or the wrong type\n * @throws {ElementError} when $root.hash does not contain a hash\n * @throws {ElementError} when the linked element is missing or the wrong type\n */\n constructor($root) {\n super($root)\n\n const hash = this.$root.hash\n const href = this.$root.getAttribute('href') ?? ''\n\n // Return early for external URLs or links to other pages\n if (\n this.$root.origin !== window.location.origin ||\n this.$root.pathname !== window.location.pathname\n ) {\n return\n }\n\n const linkedElementId = hash.replace('#', '')\n\n // Check link path matching current page\n if (!linkedElementId) {\n throw new ElementError(\n `Skip link: Target link (\\`href=\"${href}\"\\`) has no hash fragment`\n )\n }\n\n const $linkedElement = document.getElementById(linkedElementId)\n\n // Check for link target element\n if (!$linkedElement) {\n throw new ElementError({\n component: SkipLink,\n element: $linkedElement,\n identifier: `Target content (\\`id=\"${linkedElementId}\"\\`)`\n })\n }\n\n /**\n * Focus the linked element on click\n *\n * Adds a helper CSS class to hide native focus styles,\n * but removes it on blur to restore native focus styles\n */\n this.$root.addEventListener('click', () =>\n setFocus($linkedElement, {\n onBeforeFocus() {\n $linkedElement.classList.add('govuk-skip-link-focused-element')\n },\n onBlur() {\n $linkedElement.classList.remove('govuk-skip-link-focused-element')\n }\n })\n )\n }\n\n /**\n * Name for the component used when initialising using data-module attributes.\n */\n static moduleName = 'govuk-skip-link'\n}\n"],"names":["setFocus","$element","options","_options$onBeforeFocu","isFocusable","getAttribute","setAttribute","onFocus","addEventListener","onBlur","once","_options$onBlur","call","removeAttribute","onBeforeFocus","focus","isInitialised","$root","moduleName","HTMLElement","hasAttribute","isSupported","$scope","document","body","classList","contains","isArray","option","Array","isObject","isScope","Element","Document","formatErrorMessage","Component","message","GOVUKFrontendError","Error","constructor","args","name","SupportError","scopeOrMessage","supportMessage","HTMLScriptElement","prototype","ElementError","messageOrOptions","component","identifier","element","expectedType","InitError","componentOrMessage","_self","globalThis","self","_$root","childConstructor","elementType","checkSupport","checkInitialised","SkipLink","_this$$root$getAttrib","hash","href","origin","window","location","pathname","linkedElementId","replace","$linkedElement","getElementById","add","remove","HTMLAnchorElement"],"mappings":"AA0CO,SAASA,QAAQA,CAACC,QAAQ,EAAEC,OAAO,GAAG,EAAE,EAAE;AAAA,EAAA,IAAAC,qBAAA;AAC/C,EAAA,MAAMC,WAAW,GAAGH,QAAQ,CAACI,YAAY,CAAC,UAAU,CAAC;EAErD,IAAI,CAACD,WAAW,EAAE;AAChBH,IAAAA,QAAQ,CAACK,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC;AACzC,EAAA;EAKA,SAASC,OAAOA,GAAG;AACjBN,IAAAA,QAAQ,CAACO,gBAAgB,CAAC,MAAM,EAAEC,MAAM,EAAE;AAAEC,MAAAA,IAAI,EAAE;AAAK,KAAC,CAAC;AAC3D,EAAA;EAKA,SAASD,MAAMA,GAAG;AAAA,IAAA,IAAAE,eAAA;IAChB,CAAAA,eAAA,GAAAT,OAAO,CAACO,MAAM,KAAA,IAAA,IAAdE,eAAA,CAAgBC,IAAI,CAACX,QAAQ,CAAC;IAE9B,IAAI,CAACG,WAAW,EAAE;AAChBH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Focus } from '../../common/index.mjs';
2
2
  import { Component } from '../../component.mjs';
3
3
  import { ElementError } from '../../errors/index.mjs';
4
4
 
5
+ const _self = typeof globalThis !== 'undefined' ? globalThis : self;
5
6
  /**
6
7
  * Skip link component
7
8
  *
@@ -45,7 +46,7 @@ class SkipLink extends Component {
45
46
  }));
46
47
  }
47
48
  }
48
- SkipLink.elementType = HTMLAnchorElement;
49
+ SkipLink.elementType = _self.HTMLAnchorElement;
49
50
  SkipLink.moduleName = 'govuk-skip-link';
50
51
 
51
52
  export { SkipLink };
@@ -1 +1 @@
1
- {"version":3,"file":"skip-link.mjs","sources":["../../../../src/govuk/components/skip-link/skip-link.mjs"],"sourcesContent":["import { setFocus } from '../../common/index.mjs'\nimport { Component } from '../../component.mjs'\nimport { ElementError } from '../../errors/index.mjs'\n\n/**\n * Skip link component\n *\n * @preserve\n * @augments Component<HTMLAnchorElement>\n */\nexport class SkipLink extends Component {\n static elementType = HTMLAnchorElement\n\n /**\n * @param {Element | null} $root - HTML element to use for skip link\n * @throws {ElementError} when $root is not set or the wrong type\n * @throws {ElementError} when $root.hash does not contain a hash\n * @throws {ElementError} when the linked element is missing or the wrong type\n */\n constructor($root) {\n super($root)\n\n const hash = this.$root.hash\n const href = this.$root.getAttribute('href') ?? ''\n\n // Return early for external URLs or links to other pages\n if (\n this.$root.origin !== window.location.origin ||\n this.$root.pathname !== window.location.pathname\n ) {\n return\n }\n\n const linkedElementId = hash.replace('#', '')\n\n // Check link path matching current page\n if (!linkedElementId) {\n throw new ElementError(\n `Skip link: Target link (\\`href=\"${href}\"\\`) has no hash fragment`\n )\n }\n\n const $linkedElement = document.getElementById(linkedElementId)\n\n // Check for link target element\n if (!$linkedElement) {\n throw new ElementError({\n component: SkipLink,\n element: $linkedElement,\n identifier: `Target content (\\`id=\"${linkedElementId}\"\\`)`\n })\n }\n\n /**\n * Focus the linked element on click\n *\n * Adds a helper CSS class to hide native focus styles,\n * but removes it on blur to restore native focus styles\n */\n this.$root.addEventListener('click', () =>\n setFocus($linkedElement, {\n onBeforeFocus() {\n $linkedElement.classList.add('govuk-skip-link-focused-element')\n },\n onBlur() {\n $linkedElement.classList.remove('govuk-skip-link-focused-element')\n }\n })\n )\n }\n\n /**\n * Name for the component used when initialising using data-module attributes.\n */\n static moduleName = 'govuk-skip-link'\n}\n"],"names":["SkipLink","Component","constructor","$root","_this$$root$getAttrib","hash","href","getAttribute","origin","window","location","pathname","linkedElementId","replace","ElementError","$linkedElement","document","getElementById","component","element","identifier","addEventListener","setFocus","onBeforeFocus","classList","add","onBlur","remove","elementType","HTMLAnchorElement","moduleName"],"mappings":";;;;AAIA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,QAAQ,SAASC,SAAS,CAAC;AAGtC;AACF;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAACC,KAAK,EAAE;AAAA,IAAA,IAAAC,qBAAA;IACjB,KAAK,CAACD,KAAK,CAAC;AAEZ,IAAA,MAAME,IAAI,GAAG,IAAI,CAACF,KAAK,CAACE,IAAI;AAC5B,IAAA,MAAMC,IAAI,GAAA,CAAAF,qBAAA,GAAG,IAAI,CAACD,KAAK,CAACI,YAAY,CAAC,MAAM,CAAC,KAAA,IAAA,GAAAH,qBAAA,GAAI,EAAE;IAGlD,IACE,IAAI,CAACD,KAAK,CAACK,MAAM,KAAKC,MAAM,CAACC,QAAQ,CAACF,MAAM,IAC5C,IAAI,CAACL,KAAK,CAACQ,QAAQ,KAAKF,MAAM,CAACC,QAAQ,CAACC,QAAQ,EAChD;AACA,MAAA;AACF,IAAA;IAEA,MAAMC,eAAe,GAAGP,IAAI,CAACQ,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC;IAG7C,IAAI,CAACD,eAAe,EAAE;AACpB,MAAA,MAAM,IAAIE,YAAY,CACpB,CAAA,gCAAA,EAAmCR,IAAI,2BACzC,CAAC;AACH,IAAA;AAEA,IAAA,MAAMS,cAAc,GAAGC,QAAQ,CAACC,cAAc,CAACL,eAAe,CAAC;IAG/D,IAAI,CAACG,cAAc,EAAE;MACnB,MAAM,IAAID,YAAY,CAAC;AACrBI,QAAAA,SAAS,EAAElB,QAAQ;AACnBmB,QAAAA,OAAO,EAAEJ,cAAc;QACvBK,UAAU,EAAE,yBAAyBR,eAAe,CAAA,IAAA;AACtD,OAAC,CAAC;AACJ,IAAA;IAQA,IAAI,CAACT,KAAK,CAACkB,gBAAgB,CAAC,OAAO,EAAE,MACnCC,QAAQ,CAACP,cAAc,EAAE;AACvBQ,MAAAA,aAAaA,GAAG;AACdR,QAAAA,cAAc,CAACS,SAAS,CAACC,GAAG,CAAC,iCAAiC,CAAC;MACjE,CAAC;AACDC,MAAAA,MAAMA,GAAG;AACPX,QAAAA,cAAc,CAACS,SAAS,CAACG,MAAM,CAAC,iCAAiC,CAAC;AACpE,MAAA;AACF,KAAC,CACH,CAAC;AACH,EAAA;AAMF;AAjEa3B,QAAQ,CACZ4B,WAAW,GAAGC,iBAAiB;AAD3B7B,QAAQ,CAgEZ8B,UAAU,GAAG,iBAAiB;;;;"}
1
+ {"version":3,"file":"skip-link.mjs","sources":["../../../../src/govuk/components/skip-link/skip-link.mjs"],"sourcesContent":["/* eslint-disable es-x/no-global-this */\n\nimport { setFocus } from '../../common/index.mjs'\nimport { Component } from '../../component.mjs'\nimport { ElementError } from '../../errors/index.mjs'\n\nconst _self =\n typeof globalThis !== 'undefined'\n ? globalThis // Modern browsers, Node.js\n : self // Old browsers, web workers\n\n/**\n * Skip link component\n *\n * @preserve\n * @augments Component<HTMLAnchorElement>\n */\nexport class SkipLink extends Component {\n static elementType = _self.HTMLAnchorElement\n\n /**\n * @param {Element | null} $root - HTML element to use for skip link\n * @throws {ElementError} when $root is not set or the wrong type\n * @throws {ElementError} when $root.hash does not contain a hash\n * @throws {ElementError} when the linked element is missing or the wrong type\n */\n constructor($root) {\n super($root)\n\n const hash = this.$root.hash\n const href = this.$root.getAttribute('href') ?? ''\n\n // Return early for external URLs or links to other pages\n if (\n this.$root.origin !== window.location.origin ||\n this.$root.pathname !== window.location.pathname\n ) {\n return\n }\n\n const linkedElementId = hash.replace('#', '')\n\n // Check link path matching current page\n if (!linkedElementId) {\n throw new ElementError(\n `Skip link: Target link (\\`href=\"${href}\"\\`) has no hash fragment`\n )\n }\n\n const $linkedElement = document.getElementById(linkedElementId)\n\n // Check for link target element\n if (!$linkedElement) {\n throw new ElementError({\n component: SkipLink,\n element: $linkedElement,\n identifier: `Target content (\\`id=\"${linkedElementId}\"\\`)`\n })\n }\n\n /**\n * Focus the linked element on click\n *\n * Adds a helper CSS class to hide native focus styles,\n * but removes it on blur to restore native focus styles\n */\n this.$root.addEventListener('click', () =>\n setFocus($linkedElement, {\n onBeforeFocus() {\n $linkedElement.classList.add('govuk-skip-link-focused-element')\n },\n onBlur() {\n $linkedElement.classList.remove('govuk-skip-link-focused-element')\n }\n })\n )\n }\n\n /**\n * Name for the component used when initialising using data-module attributes.\n */\n static moduleName = 'govuk-skip-link'\n}\n"],"names":["_self","globalThis","self","SkipLink","Component","constructor","$root","_this$$root$getAttrib","hash","href","getAttribute","origin","window","location","pathname","linkedElementId","replace","ElementError","$linkedElement","document","getElementById","component","element","identifier","addEventListener","setFocus","onBeforeFocus","classList","add","onBlur","remove","elementType","HTMLAnchorElement","moduleName"],"mappings":";;;;AAMA,MAAMA,KAAK,GACT,OAAOC,UAAU,KAAK,WAAW,GAC7BA,UAAU,GACVC,IAAI;AAEV;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,QAAQ,SAASC,SAAS,CAAC;AAGtC;AACF;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAACC,KAAK,EAAE;AAAA,IAAA,IAAAC,qBAAA;IACjB,KAAK,CAACD,KAAK,CAAC;AAEZ,IAAA,MAAME,IAAI,GAAG,IAAI,CAACF,KAAK,CAACE,IAAI;AAC5B,IAAA,MAAMC,IAAI,GAAA,CAAAF,qBAAA,GAAG,IAAI,CAACD,KAAK,CAACI,YAAY,CAAC,MAAM,CAAC,KAAA,IAAA,GAAAH,qBAAA,GAAI,EAAE;IAGlD,IACE,IAAI,CAACD,KAAK,CAACK,MAAM,KAAKC,MAAM,CAACC,QAAQ,CAACF,MAAM,IAC5C,IAAI,CAACL,KAAK,CAACQ,QAAQ,KAAKF,MAAM,CAACC,QAAQ,CAACC,QAAQ,EAChD;AACA,MAAA;AACF,IAAA;IAEA,MAAMC,eAAe,GAAGP,IAAI,CAACQ,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC;IAG7C,IAAI,CAACD,eAAe,EAAE;AACpB,MAAA,MAAM,IAAIE,YAAY,CACpB,CAAA,gCAAA,EAAmCR,IAAI,2BACzC,CAAC;AACH,IAAA;AAEA,IAAA,MAAMS,cAAc,GAAGC,QAAQ,CAACC,cAAc,CAACL,eAAe,CAAC;IAG/D,IAAI,CAACG,cAAc,EAAE;MACnB,MAAM,IAAID,YAAY,CAAC;AACrBI,QAAAA,SAAS,EAAElB,QAAQ;AACnBmB,QAAAA,OAAO,EAAEJ,cAAc;QACvBK,UAAU,EAAE,yBAAyBR,eAAe,CAAA,IAAA;AACtD,OAAC,CAAC;AACJ,IAAA;IAQA,IAAI,CAACT,KAAK,CAACkB,gBAAgB,CAAC,OAAO,EAAE,MACnCC,QAAQ,CAACP,cAAc,EAAE;AACvBQ,MAAAA,aAAaA,GAAG;AACdR,QAAAA,cAAc,CAACS,SAAS,CAACC,GAAG,CAAC,iCAAiC,CAAC;MACjE,CAAC;AACDC,MAAAA,MAAMA,GAAG;AACPX,QAAAA,cAAc,CAACS,SAAS,CAACG,MAAM,CAAC,iCAAiC,CAAC;AACpE,MAAA;AACF,KAAC,CACH,CAAC;AACH,EAAA;AAMF;AAjEa3B,QAAQ,CACZ4B,WAAW,GAAG/B,KAAK,CAACgC,iBAAiB;AADjC7B,QAAQ,CAgEZ8B,UAAU,GAAG,iBAAiB;;"}
@@ -37,6 +37,9 @@
37
37
  function isObject(option) {
38
38
  return !!option && typeof option === 'object' && !isArray(option);
39
39
  }
40
+ function isScope($scope) {
41
+ return !!$scope && ($scope instanceof Element || $scope instanceof Document);
42
+ }
40
43
  function formatErrorMessage(Component, message) {
41
44
  return `${Component.moduleName}: ${message}`;
42
45
  }
@@ -55,11 +58,14 @@
55
58
  /**
56
59
  * Checks if GOV.UK Frontend is supported on this page
57
60
  *
58
- * @param {HTMLElement | null} [$scope] - HTML element `<body>` checked for browser support
61
+ * @param {Element | Document | null | string} [scopeOrMessage] - HTML element `<body>` checked for browser support or support error message
59
62
  */
60
- constructor($scope = document.body) {
61
- 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';
62
- super($scope ? supportMessage : 'GOV.UK Frontend initialised without `<script type="module">`');
63
+ constructor(scopeOrMessage = document.body) {
64
+ let 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';
65
+ if (!isScope(scopeOrMessage)) {
66
+ supportMessage = 'GOV.UK Frontend initialised without `<script type="module">`';
67
+ }
68
+ super(typeof scopeOrMessage === 'string' ? scopeOrMessage : supportMessage);
63
69
  this.name = 'SupportError';
64
70
  }
65
71
  }
@@ -94,6 +100,7 @@
94
100
  * @import { ComponentWithModuleName } from '../common/index.mjs'
95
101
  */
96
102
 
103
+ const _self = typeof globalThis !== 'undefined' ? globalThis : self;
97
104
  class Component {
98
105
  /**
99
106
  * Returns the root element of the component
@@ -147,7 +154,7 @@
147
154
  /**
148
155
  * @typedef {typeof Component & ChildClass} ChildClassConstructor
149
156
  */
150
- Component.elementType = HTMLElement;
157
+ Component.elementType = _self.HTMLElement;
151
158
 
152
159
  /**
153
160
  * Tabs component