@govuk-react/primitives 0.0.0-stage → 0.2.1

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 (121) hide show
  1. package/README.md +271 -2
  2. package/dist/accordion/element.d.ts +14 -0
  3. package/dist/accordion/element.js +302 -0
  4. package/dist/accordion/element.js.map +1 -0
  5. package/dist/accordion/index.d.ts +74 -0
  6. package/dist/accordion/index.js +138 -0
  7. package/dist/accordion/index.js.map +1 -0
  8. package/dist/auto-focus/element.d.ts +1 -0
  9. package/dist/auto-focus/element.js +75 -0
  10. package/dist/auto-focus/element.js.map +1 -0
  11. package/dist/auto-focus/index.d.ts +297 -0
  12. package/dist/auto-focus/index.js +29 -0
  13. package/dist/auto-focus/index.js.map +1 -0
  14. package/dist/autocomplete/element.d.ts +27 -0
  15. package/dist/autocomplete/element.js +597 -0
  16. package/dist/autocomplete/element.js.map +1 -0
  17. package/dist/autocomplete/index.d.ts +350 -0
  18. package/dist/autocomplete/index.js +108 -0
  19. package/dist/autocomplete/index.js.map +1 -0
  20. package/dist/button/element.d.ts +1 -0
  21. package/dist/button/element.js +59 -0
  22. package/dist/button/element.js.map +1 -0
  23. package/dist/button/index.d.ts +10 -0
  24. package/dist/button/index.js +9 -0
  25. package/dist/button/index.js.map +1 -0
  26. package/dist/character-count/element.d.ts +7 -0
  27. package/dist/character-count/element.js +287 -0
  28. package/dist/character-count/element.js.map +1 -0
  29. package/dist/character-count/index.d.ts +57 -0
  30. package/dist/character-count/index.js +79 -0
  31. package/dist/character-count/index.js.map +1 -0
  32. package/dist/character-count/messages.d.ts +20 -0
  33. package/dist/character-count/messages.js +54 -0
  34. package/dist/character-count/messages.js.map +1 -0
  35. package/dist/choices/element.d.ts +5 -0
  36. package/dist/choices/element.js +202 -0
  37. package/dist/choices/element.js.map +1 -0
  38. package/dist/choices/index.d.ts +309 -0
  39. package/dist/choices/index.js +37 -0
  40. package/dist/choices/index.js.map +1 -0
  41. package/dist/disclosure/element.d.ts +14 -0
  42. package/dist/disclosure/element.js +123 -0
  43. package/dist/disclosure/element.js.map +1 -0
  44. package/dist/disclosure/index.d.ts +307 -0
  45. package/dist/disclosure/index.js +66 -0
  46. package/dist/disclosure/index.js.map +1 -0
  47. package/dist/exit-this-page/element.d.ts +19 -0
  48. package/dist/exit-this-page/element.js +201 -0
  49. package/dist/exit-this-page/element.js.map +1 -0
  50. package/dist/exit-this-page/index.d.ts +330 -0
  51. package/dist/exit-this-page/index.js +54 -0
  52. package/dist/exit-this-page/index.js.map +1 -0
  53. package/dist/file-upload/element.d.ts +23 -0
  54. package/dist/file-upload/element.js +270 -0
  55. package/dist/file-upload/element.js.map +1 -0
  56. package/dist/file-upload/index.d.ts +46 -0
  57. package/dist/file-upload/index.js +65 -0
  58. package/dist/file-upload/index.js.map +1 -0
  59. package/dist/focus-links/element.d.ts +1 -0
  60. package/dist/focus-links/element.js +90 -0
  61. package/dist/focus-links/element.js.map +1 -0
  62. package/dist/focus-links/index.d.ts +288 -0
  63. package/dist/focus-links/index.js +7 -0
  64. package/dist/focus-links/index.js.map +1 -0
  65. package/dist/index.d.ts +13 -0
  66. package/dist/index.js +14 -0
  67. package/dist/index.js.map +1 -0
  68. package/dist/inline/accordion-element.js +1 -0
  69. package/dist/inline/auto-focus-element.js +1 -0
  70. package/dist/inline/autocomplete-element.js +2 -0
  71. package/dist/inline/button-element.js +1 -0
  72. package/dist/inline/character-count-element.js +1 -0
  73. package/dist/inline/choices-element.js +1 -0
  74. package/dist/inline/disclosure-element.js +1 -0
  75. package/dist/inline/exit-this-page-element.js +1 -0
  76. package/dist/inline/file-upload-element.js +1 -0
  77. package/dist/inline/focus-links-element.js +1 -0
  78. package/dist/inline/modal-element.js +1 -0
  79. package/dist/inline/password-input-element.js +1 -0
  80. package/dist/inline/tabs-element.js +1 -0
  81. package/dist/inline-script/index.d.ts +26 -0
  82. package/dist/inline-script/index.js +31 -0
  83. package/dist/inline-script/index.js.map +1 -0
  84. package/dist/modal/element.d.ts +10 -0
  85. package/dist/modal/element.js +114 -0
  86. package/dist/modal/element.js.map +1 -0
  87. package/dist/modal/index.d.ts +36 -0
  88. package/dist/modal/index.js +109 -0
  89. package/dist/modal/index.js.map +1 -0
  90. package/dist/password-input/element.d.ts +1 -0
  91. package/dist/password-input/element.js +134 -0
  92. package/dist/password-input/element.js.map +1 -0
  93. package/dist/password-input/index.d.ts +318 -0
  94. package/dist/password-input/index.js +35 -0
  95. package/dist/password-input/index.js.map +1 -0
  96. package/dist/tabs/element.d.ts +19 -0
  97. package/dist/tabs/element.js +416 -0
  98. package/dist/tabs/element.js.map +1 -0
  99. package/dist/tabs/index.d.ts +83 -0
  100. package/dist/tabs/index.js +138 -0
  101. package/dist/tabs/index.js.map +1 -0
  102. package/dist/utils/dom.d.ts +9 -0
  103. package/dist/utils/dom.js +27 -0
  104. package/dist/utils/dom.js.map +1 -0
  105. package/dist/utils/on-property-set.d.ts +9 -0
  106. package/dist/utils/on-property-set.js +38 -0
  107. package/dist/utils/on-property-set.js.map +1 -0
  108. package/dist/utils/set-focus.d.ts +11 -0
  109. package/dist/utils/set-focus.js +38 -0
  110. package/dist/utils/set-focus.js.map +1 -0
  111. package/dist/utils/set-up-when-ready.d.ts +6 -0
  112. package/dist/utils/set-up-when-ready.js +16 -0
  113. package/dist/utils/set-up-when-ready.js.map +1 -0
  114. package/dist/utils/slot.d.ts +13 -0
  115. package/dist/utils/slot.js +40 -0
  116. package/dist/utils/slot.js.map +1 -0
  117. package/dist/utils/translation.d.ts +13 -0
  118. package/dist/utils/translation.js +57 -0
  119. package/dist/utils/translation.js.map +1 -0
  120. package/licences/accessible-autocomplete.txt +20 -0
  121. package/package.json +49 -4
@@ -0,0 +1,31 @@
1
+ import * as React from 'react';
2
+ const accordion = "\"use strict\";(()=>{var d=a=>a?.split(/\\s+/).filter(Boolean)??[];function p(a,c){if(a.textContent===c)return;let{firstChild:u}=a;u instanceof Text&&a.childNodes.length===1?u.nodeValue=c:a.textContent=c}var g=\"govuk-react-accordion\",m={\"show-section-text\":\"Show\",\"hide-section-text\":\"Hide\",\"show-section-label\":\"Show this section\",\"hide-section-label\":\"Hide this section\",\"show-all-sections-text\":\"Show all sections\",\"hide-all-sections-text\":\"Hide all sections\"},h=a=>a?.split(/\\s+/).filter(Boolean);if(typeof HTMLElement<\"u\"&&typeof customElements<\"u\"){class a extends HTMLElement{constructor(){super(...arguments);this.open=new Set;this.upgraded=!1;this.controlled=!1;this.prepared=new WeakSet;this.onClick=t=>{let e=t.target instanceof Element?t.target:null,s=e?.closest(\"button[data-accordion-trigger]\");if(s&&this.ownsElement(s)){let n=this.sectionOf(s)?.dataset.value;if(n===void 0)return;let r=new Set(this.open);r.has(n)?r.delete(n):r.add(n),this.change(r);return}let i=e?.closest(\"button[data-accordion-show-all]\");if(i&&this.ownsElement(i)){let n=this.sections.map(r=>r.dataset.value??\"\");this.change(new Set(this.allOpen?[]:n))}};this.onBeforeMatch=t=>{let s=(t.target instanceof Element?this.sectionOf(t.target):void 0)?.dataset.value;s===void 0||this.open.has(s)||this.change(new Set([...this.open,s]),!0)}}static get observedAttributes(){return[\"value\"]}get openValues(){return this.upgraded?[...this.open]:void 0}get pickedValue(){return this.picked}connectedCallback(){this.observer=new MutationObserver(t=>{if(!this.upgraded){this.setup();return}t.some(e=>e.type===\"childList\")&&this.sections.forEach(e=>this.prepare(e)),this.render()}),this.observer.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[\"class\"]}),this.upgraded?(this.listen(),this.render()):this.setup()}disconnectedCallback(){this.observer?.disconnect(),this.removeEventListener(\"click\",this.onClick),this.removeEventListener(\"beforematch\",this.onBeforeMatch,!0)}attributeChangedCallback(){let t=h(this.getAttribute(\"value\"));this.controlled=t!==void 0,t&&(this.open=new Set(t),this.render())}get sections(){return this.own(\"[data-accordion-section]\")}get allOpen(){return this.sections.every(t=>this.open.has(t.dataset.value??\"\"))}own(t){return Array.from(this.querySelectorAll(t)).filter(e=>this.ownsElement(e))}ownsElement(t){return t.closest(g)===this}sectionOf(t){let e=t.closest(\"[data-accordion-section]\");return e&&this.ownsElement(e)?e:void 0}find(t,e){return Array.from(t.querySelectorAll(e)).find(s=>this.sectionOf(s)===t)}text(t){return this.getAttribute(t)??m[t]}get remember(){return this.getAttribute(\"remember-expanded\")!==\"false\"}setup(){let t=this.sections;if(!t.some(i=>this.find(i,\"button[data-accordion-trigger]\")))return;this.upgraded=!0;let e=h(this.getAttribute(\"value\"));this.controlled=e!==void 0,this.open=new Set(e??h(this.getAttribute(\"default-value\"))),this.dataset.upgraded=\"\";let s=d(this.getAttribute(\"upgraded-class\"));s.length&&this.classList.add(...s),this.own(\"[data-accordion-controls]\").forEach(i=>{i.hidden=!1}),t.forEach(i=>this.prepare(i)),this.listen(),this.render()}listen(){this.addEventListener(\"click\",this.onClick),this.addEventListener(\"beforematch\",this.onBeforeMatch,!0)}prepare(t){let e=this.find(t,\"button[data-accordion-trigger]\");if(!e||this.prepared.has(t))return;this.prepared.add(t);let s=t.dataset.value??\"\";if(!this.controlled){let n=h(this.getAttribute(\"default-value\"));(n?n.includes(s):t.hasAttribute(\"data-expanded\"))&&this.open.add(s),this.restore(t)}Array.from(t.querySelectorAll(\"[data-accordion-fallback]\")).filter(n=>this.sectionOf(n)===t).forEach(n=>{n.hidden=!0}),e.hidden=!1;let i=this.find(t,\"[data-accordion-content]\");i?.id&&e.setAttribute(\"aria-controls\",i.id)}restore(t){let e=this.find(t,\"[data-accordion-content]\")?.id,s=t.dataset.value;if(!(!this.remember||!e||s===void 0))try{let i=window.sessionStorage.getItem(e);i===\"true\"?this.open.add(s):i===\"false\"&&this.open.delete(s)}catch{}}store(t){this.remember&&this.sections.forEach(e=>{let s=e.dataset.value??\"\",i=this.find(e,\"[data-accordion-content]\")?.id;if(!(!i||t.has(s)===this.open.has(s)))try{window.sessionStorage.setItem(i,String(this.open.has(s)))}catch{}})}change(t,e=!1){let s=this.sections.map(i=>i.dataset.value??\"\").filter(i=>t.has(i));if(!this.controlled||e){let i=this.open;this.open=new Set(s),this.controlled||(this.picked=s,this.store(i)),this.render()}this.dispatchEvent(new CustomEvent(\"govuk-react-accordion:change\",{detail:{value:s},bubbles:!0}))}render(){if(!this.upgraded)return;let t=d(this.getAttribute(\"expanded-section-class\")),e=d(this.getAttribute(\"collapsed-icon-class\")),s=(n,r)=>{Array.from(n.querySelectorAll(\"[data-accordion-icon]\")).forEach(o=>{e.forEach(l=>o.classList.toggle(l,!r))})};this.sections.forEach(n=>{let r=this.open.has(n.dataset.value??\"\"),o=this.find(n,\"button[data-accordion-trigger]\"),l=this.find(n,\"[data-accordion-content]\");if(n.dataset.state=r?\"open\":\"closed\",t.forEach(f=>n.classList.toggle(f,r)),l&&(r?l.removeAttribute(\"hidden\"):l.setAttribute(\"hidden\",\"until-found\")),!o)return;o.setAttribute(\"aria-expanded\",String(r));let b=Array.from(o.querySelectorAll(\"[data-accordion-label]\")).map(f=>f.textContent?.trim()??\"\");o.setAttribute(\"aria-label\",[...b,this.text(r?\"hide-section-label\":\"show-section-label\")].join(\" , \"));let v=o.querySelector(\"[data-accordion-toggle-text]\");v&&p(v,this.text(r?\"hide-section-text\":\"show-section-text\")),s(o,r)});let i=this.allOpen;this.own(\"button[data-accordion-show-all]\").forEach(n=>{n.setAttribute(\"aria-expanded\",String(i));let r=n.querySelector(\"[data-accordion-show-all-text]\");r&&p(r,this.text(i?\"hide-all-sections-text\":\"show-all-sections-text\")),s(n,i)})}}customElements.get(g)||customElements.define(g,a)}})();";
3
+ const autocomplete = "\"use strict\";(()=>{var E=[\"zero\",\"one\",\"two\",\"few\",\"many\",\"other\"];var L=s=>[s,...E.map(o=>`${s}-${o}`)];function w(s,o){let l=s.getAttribute(o);if(l!==null)return l;let t=E.flatMap(e=>{let n=s.getAttribute(`${o}-${e}`);return n===null?[]:[[e,n]]});return t.length?Object.fromEntries(t):void 0}function A(s){try{return s(void 0)}catch{return s(\"en\")}}function v(s,o){try{return o(s)}catch{return A(o)}}function p(s,o,l){let t;if(typeof s==\"string\")t=s;else{let n=v(l,i=>new Intl.PluralRules(i)).select(o);t=s[n]??s.other}let e=v(l,n=>new Intl.NumberFormat(n)).format(o);return(t??\"\").replaceAll(\"%{count}\",e)}function g(s,o){if(s.textContent===o)return;let{firstChild:l}=s;l instanceof Text&&s.childNodes.length===1?l.nodeValue=o:s.textContent=o}function u(s,o,l){l===null?s.removeAttribute(o):s.getAttribute(o)!==l&&s.setAttribute(o,l)}var b=\"govuk-react-autocomplete\",M={\"status-query-too-short\":\"Type in %{count} or more characters for results\",\"status-no-results\":\"No search results\",\"status-selected-option\":\"%{option} %{position} of %{count} is highlighted\",\"status-results\":{one:\"%{count} result is available.\",other:\"%{count} results are available.\"}},I=1400,k=100,y=()=>typeof navigator<\"u\"&&/(iPod|iPhone|iPad)/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent),x=typeof HTMLInputElement>\"u\"?void 0:Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,\"value\")?.set;if(typeof HTMLElement<\"u\"&&typeof customElements<\"u\"){class s extends HTMLElement{constructor(){super(...arguments);this.focused=null;this.hovered=null;this.menuOpen=!1;this.options=[];this.currentQuery=\"\";this.validChoiceMade=!1;this.selected=null;this.ariaHint=!0;this.lastFocused=null;this.settingValue=!1;this.bump=!1;this.generatedIds=0;this.onPoll=()=>{this.input&&this.input.value!==this.currentQuery&&this.handleInputChange(this.input.value)};this.onInput=()=>{this.input&&!this.settingValue&&this.handleInputChange(this.input.value)};this.onInputFocus=()=>{let t=!this.validChoiceMade&&this.queryLongEnough&&this.options.length>0;this.focused=-1,t&&(this.menuOpen=!0,this.selected=-1),this.render()};this.onFocusOut=t=>{let{target:e,relatedTarget:n}=t;if(e===this.input){if(this.focused!==-1)return;let m=y();this.handleComponentBlur({menuOpen:this.menuOpen&&m,query:m?this.currentQuery:this.valueOf(this.selectedOption)});return}if(!(e instanceof HTMLElement)||!e.isConnected)return;let i=this.options.indexOf(e);if(i===-1)return;let r=n===null,h=n===this.input,d=this.focused!==i&&this.focused!==-1;(!d&&r||!(d||h))&&this.handleComponentBlur({menuOpen:this.menuOpen&&y(),query:this.valueOf(this.selectedOption)})};this.onKeyDown=t=>{let{target:e}=t,n=e===this.input,i=e instanceof HTMLElement&&this.options.includes(e);if(!n&&!i)return;let r=this.selected??-1;switch(t.key){case\"ArrowUp\":t.preventDefault(),this.menuOpen&&r!==-1&&this.focusOption(r-1);break;case\"ArrowDown\":t.preventDefault(),this.menuOpen&&r!==this.options.length-1&&this.focusOption(r+1);break;case\" \":this.focused!==null&&this.focused!==-1&&(t.preventDefault(),this.confirm(this.focused));break;case\"Enter\":if(!this.menuOpen)break;r>=0?(t.preventDefault(),this.confirm(r)):this.submitOnConfirm||t.preventDefault();break;case\"Escape\":i&&this.input?.focus(),this.handleComponentBlur({menuOpen:!1,query:this.currentQuery});break;default:i&&!t.ctrlKey&&!t.metaKey&&!t.altKey&&(t.key.length===1||t.key===\"Backspace\")&&this.input?.focus()}};this.onOptionMouseDown=t=>{this.optionOf(t.target)!==-1&&t.preventDefault()};this.onOptionClick=t=>{let e=this.optionOf(t.target);e!==-1&&this.confirm(e)};this.onOptionMouseOver=t=>{let e=this.optionOf(t.target);e===-1||e===this.hovered||y()||(this.hovered=e,this.render())};this.onListMouseLeave=()=>{this.hovered!==null&&(this.hovered=null,this.render())}}static get observedAttributes(){return[\"min-length\",\"filter\",\"confirm-on-blur\",\"submit-on-confirm\",...Object.keys(M).flatMap(L)]}get query(){return this.input?this.currentQuery:void 0}connectedCallback(){this.observer=new MutationObserver(t=>this.onMutation(t)),this.observer.observe(this,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:[\"aria-describedby\",\"data-value\"]}),this.setup()}disconnectedCallback(){this.observer?.disconnect(),this.unbind()}attributeChangedCallback(){this.isConnected&&(this.input?this.render():this.setup())}own(t){return this.ownAll(t)[0]}ownAll(t){return Array.from(this.querySelectorAll(t)).filter(e=>e.closest(b)===this)}get allOptions(){return this.ownAll(\"[data-autocomplete-option]\")}get minLength(){let t=Number(this.getAttribute(\"min-length\"));return Number.isFinite(t)&&t>0?t:0}get filterType(){let t=this.getAttribute(\"filter\");return t===\"starts-with\"||t===\"none\"?t:\"contains\"}get confirmOnBlur(){return this.getAttribute(\"confirm-on-blur\")!==\"false\"}get submitOnConfirm(){return this.hasAttribute(\"submit-on-confirm\")}get locale(){return(this.input??this).closest(\"[lang]\")?.getAttribute(\"lang\")||\"en\"}setup(){let t=this.own(\"[data-autocomplete-input]\"),e=this.own(\"[data-autocomplete-listbox]\");if(!(t instanceof HTMLInputElement)||!t.id||!e){this.unbind(),delete this.dataset.upgraded;return}if(t===this.input&&e===this.listbox){this.render();return}this.unbind(),this.input=t,this.listbox=e,t.addEventListener(\"input\",this.onInput),t.addEventListener(\"click\",this.onInput),t.addEventListener(\"focus\",this.onInputFocus),this.addEventListener(\"keydown\",this.onKeyDown),this.addEventListener(\"focusout\",this.onFocusOut),e.addEventListener(\"mousedown\",this.onOptionMouseDown),e.addEventListener(\"click\",this.onOptionClick),e.addEventListener(\"mouseover\",this.onOptionMouseOver),e.addEventListener(\"mouseleave\",this.onListMouseLeave),this.poll=window.setInterval(this.onPoll,k),this.currentQuery=t.value,this.ariaHint=t.value===\"\",this.options=this.queryLongEnough?this.matchingOptions():[],this.focused=document.activeElement===t?-1:null,this.lastFocused=this.focused,this.selected=null,this.menuOpen=!1,this.validChoiceMade=!1,this.dataset.upgraded=\"\",this.render()}unbind(){let{input:t,listbox:e}=this;window.clearInterval(this.poll),window.clearTimeout(this.statusTimer),!(!t||!e)&&(t.removeEventListener(\"input\",this.onInput),t.removeEventListener(\"click\",this.onInput),t.removeEventListener(\"focus\",this.onInputFocus),this.removeEventListener(\"keydown\",this.onKeyDown),this.removeEventListener(\"focusout\",this.onFocusOut),e.removeEventListener(\"mousedown\",this.onOptionMouseDown),e.removeEventListener(\"click\",this.onOptionClick),e.removeEventListener(\"mouseover\",this.onOptionMouseOver),e.removeEventListener(\"mouseleave\",this.onListMouseLeave),this.input=void 0,this.listbox=void 0)}onMutation(t){let e=this.own(\"[data-autocomplete-status]\"),n=t.filter(i=>!(e?.contains(i.target)??!1)&&!(i.type===\"attributes\"&&i.target===this.input&&this.describedByIsCurrent()));if(n.length){if(!this.input?.isConnected||!this.listbox?.isConnected||!this.contains(this.input)){this.setup();return}n.some(i=>this.listbox?.contains(i.target))&&this.updateOptions(),this.render()}}updateOptions(){let t=this.selectedOption;if(!this.queryLongEnough||this.currentQuery===\"\"){this.options=[];return}if(this.options=this.matchingOptions(),this.focused===null||this.validChoiceMade)return;this.menuOpen=this.options.length>0;let e=t?this.options.indexOf(t):-1;this.selected=e,this.focused>=0&&(this.focused=e)}get queryLongEnough(){return this.currentQuery.length>=this.minLength}valueOf(t){if(t)return t.dataset.value??t.textContent?.trim()??\"\"}matchingOptions(){let t=this.currentQuery.toLowerCase(),e=this.filterType;return this.allOptions.filter(n=>{if(e===\"none\")return!0;let i=(this.valueOf(n)??\"\").toLowerCase();return e===\"starts-with\"?i.startsWith(t):i.includes(t)})}isQueryAnOption(t){return this.options.some(e=>this.valueOf(e)?.toLowerCase()===t.toLowerCase())}handleInputChange(t){let e=this.currentQuery!==t;this.currentQuery=t,this.ariaHint=t===\"\",t!==\"\"&&e&&this.queryLongEnough?(this.dispatchEvent(new CustomEvent(\"govuk-react-autocomplete:query\",{bubbles:!0,detail:{query:t}})),this.options=this.matchingOptions(),this.menuOpen=this.options.length>0,this.selected=-1,this.validChoiceMade=!1):(t===\"\"||!this.queryLongEnough)&&(this.menuOpen=!1,this.options=[]),this.render()}get selectedOption(){return this.selected===null||this.selected<0?void 0:this.options[this.selected]}handleComponentBlur({menuOpen:t,query:e}){let n=this.currentQuery,i=this.selectedOption;this.confirmOnBlur&&(n=e||this.currentQuery,i&&this.confirmEvent(this.valueOf(i)??\"\")),this.focused=null,this.menuOpen=t,this.selected=null,this.validChoiceMade=this.isQueryAnOption(n),this.setQuery(n),this.render()}setQuery(t){this.currentQuery=t;let{input:e}=this;!e||e.value===t||(this.settingValue=!0,x?x.call(e,t):e.value=t,e.dispatchEvent(new Event(\"input\",{bubbles:!0})),this.settingValue=!1)}confirmEvent(t){return this.dispatchEvent(new CustomEvent(\"govuk-react-autocomplete:confirm\",{bubbles:!0,cancelable:!0,detail:{value:t}}))}confirm(t){let e=this.options[t];if(!e)return;let n=this.valueOf(e)??\"\";this.focused=-1,this.hovered=null,this.menuOpen=!1,this.selected=-1,this.validChoiceMade=!0,this.setQuery(n),this.render();let i=this.confirmEvent(n),r=this.input?.form;i&&this.submitOnConfirm&&r&&window.setTimeout(()=>r.requestSubmit())}focusOption(t){this.focused=t,this.hovered=null,this.selected=t,this.render()}optionOf(t){if(!(t instanceof Element))return-1;let e=t.closest(\"[data-autocomplete-option]\");return e?this.options.indexOf(e):-1}ensureId(t,e){return t.id||(this.generatedIds+=1,t.id=`${this.input?.id}__${e}${e.endsWith(\"--\")?this.generatedIds:\"\"}`),t.id}get hint(){return this.own(\"[data-autocomplete-hint]\")}describedBy(){let{input:t}=this;if(!t)return null;let e=this.hint,n=e?this.ensureId(e,\"assistiveHint\"):void 0,i=(t.getAttribute(\"aria-describedby\")??\"\").split(/\\s+/).filter(r=>r&&r!==n);return this.ariaHint&&n&&i.push(n),i.length?i.join(\" \"):null}describedByIsCurrent(){return(this.input?.getAttribute(\"aria-describedby\")??null)===this.describedBy()}render(){let{input:t,listbox:e}=this;if(!t||!e)return;let{focused:n,hovered:i,menuOpen:r,options:h,selected:d}=this,O=n===-1&&h.length===0&&this.currentQuery!==\"\"&&this.queryLongEnough,T=n!==null&&n!==-1,C=this.ensureId(e,\"listbox\");u(e,\"role\",\"listbox\"),e.hasAttribute(\"aria-labelledby\")||e.setAttribute(\"aria-labelledby\",t.id),e.hidden=!(r||O),this.allOptions.forEach(a=>{let c=h.indexOf(a);this.ensureId(a,\"option--\"),a.hidden=c===-1,u(a,\"role\",\"option\"),u(a,\"tabindex\",\"-1\"),u(a,\"aria-selected\",n===c&&c!==-1?\"true\":\"false\"),u(a,\"aria-posinset\",c===-1?null:String(c+1)),u(a,\"aria-setsize\",c===-1?null:String(h.length)),u(a,\"data-focused\",c!==-1&&(n===-1?d===c:n===c)&&i===null?\"\":null)});let f=this.own(\"[data-autocomplete-no-results]\");if(f&&(f.hidden=!O,u(f,\"role\",\"option\"),u(f,\"aria-disabled\",\"true\")),u(t,\"role\",\"combobox\"),u(t,\"autocomplete\",\"off\"),u(t,\"aria-autocomplete\",\"list\"),u(t,\"aria-controls\",C),u(t,\"aria-expanded\",r?\"true\":\"false\"),u(t,\"aria-activedescendant\",T?h[n]?.id??null:null),u(t,\"aria-describedby\",this.describedBy()),u(this,\"data-focused\",n===null?null:\"\"),n!==this.lastFocused&&n!==null){let a=n===-1?t:h[n];a&&document.activeElement!==a&&a.focus(),n===-1&&this.lastFocused===null&&t.selectionStart!==null&&t.setSelectionRange(0,t.value.length)}this.lastFocused=n,this.scheduleStatus()}message(t){return w(this,t)??M[t]}statusText(){let{locale:t,options:e}=this;if(!this.queryLongEnough)return p(this.message(\"status-query-too-short\"),this.minLength,t);if(e.length===0)return p(this.message(\"status-no-results\"),0,t);let n=p(this.message(\"status-results\"),e.length,t),i=this.valueOf(this.selectedOption);if(i===void 0||this.selected===null)return n;let r=v(t,d=>new Intl.NumberFormat(d)).format(this.selected+1),h=p(this.message(\"status-selected-option\"),e.length,t).replaceAll(\"%{option}\",()=>i).replaceAll(\"%{position}\",()=>r);return`${n} ${h}`}scheduleStatus(){let t=this.ownAll(\"[data-autocomplete-status-region]\");t.length&&(t.forEach(e=>g(e,\"\")),window.clearTimeout(this.statusTimer),this.statusTimer=window.setTimeout(()=>{this.bump=!this.bump;let n=this.focused===null||this.validChoiceMade?\"\":this.statusText();t.forEach((i,r)=>g(i,r===0===this.bump?n:\"\"))},I))}}customElements.get(b)||customElements.define(b,s)}})();\n/*! Based on accessible-autocomplete, Copyright (c) 2017 Crown Copyright (Government Digital Service), MIT licence: licences/accessible-autocomplete.txt */";
4
+ const autoFocus = "\"use strict\";(()=>{function s(t,r,o){o.forEach(e=>t.classList.remove(e)),r&&t.removeAttribute(\"tabindex\"),t.removeAttribute(\"data-focus-tabindex\"),t.removeAttribute(\"autofocus\")}var a=t=>!t.hasAttribute(\"tabindex\")||t.hasAttribute(\"data-focus-tabindex\")&&t.getAttribute(\"tabindex\")===\"-1\";function c(t){s(t,t.hasAttribute(\"tabindex\")&&a(t),[])}function u(t,{focusedClasses:r=[],preventScroll:o=!1}={}){let e=a(t);return t.hasAttribute(\"tabindex\")||t.setAttribute(\"tabindex\",\"-1\"),document.activeElement!==t&&(r.forEach(i=>t.classList.add(i)),t.focus({preventScroll:o})),document.activeElement!==t?(s(t,e,r),!1):(r.forEach(i=>t.classList.add(i)),t.addEventListener(\"blur\",()=>s(t,e,r),{once:!0}),!0)}function d(t,r){if(r())return;let o=new MutationObserver(()=>{r()&&o.disconnect()});return o.observe(t,{childList:!0,subtree:!0}),o}var n=\"govuk-react-auto-focus\";if(typeof HTMLElement<\"u\"&&typeof customElements<\"u\"){class t extends HTMLElement{constructor(){super(...arguments);this.focused=!1}connectedCallback(){this.observer=d(this,()=>this.focusTarget())}disconnectedCallback(){this.observer?.disconnect()}get target(){let e=Array.from(this.querySelectorAll(\"[data-auto-focus]\")).find(i=>i.closest(n)===this)??this.firstElementChild;return e instanceof HTMLElement?e:void 0}focusTarget(){if(this.focused)return!0;let{target:e}=this;if(!e)return!1;if(this.focused=!0,this.hasAttribute(\"disabled\"))return!0;if(e.hasAttribute(\"autofocus\")){let i=document.activeElement;if(i===e)return u(e,{preventScroll:!0}),!0;if(i&&i!==document.body)return c(e),!0}return queueMicrotask(()=>{(!e.isConnected||!u(e))&&(this.focused=!1)}),!0}}customElements.get(n)||customElements.define(n,t)}})();";
5
+ const button = "\"use strict\";(()=>{var o=Symbol.for(\"govuk-react-button\"),u=new WeakMap,r=t=>{for(let e of t.composedPath())if(e instanceof HTMLElement&&e.hasAttribute(\"data-button\"))return e;return null};function i(t){let e=r(t);if(!e||e.getAttribute(\"data-prevent-double-click\")!==\"true\")return;let n=u.get(e);if(n!==void 0&&t.timeStamp-n<1e3){t.preventDefault(),t.stopImmediatePropagation();return}u.set(e,t.timeStamp)}function a(t){if(t.key!==\" \"||t.repeat||t.defaultPrevented)return;let e=r(t);!e||e!==t.composedPath()[0]||e.getAttribute(\"role\")!==\"button\"||e instanceof HTMLButtonElement||(t.preventDefault(),e.click())}typeof document<\"u\"&&(Reflect.get(globalThis,o)||(Reflect.set(globalThis,o,!0),document.addEventListener(\"click\",i,!0),document.addEventListener(\"keydown\",a)));})();";
6
+ const characterCount = "\"use strict\";(()=>{var C=(e,s)=>{for(let i=e;i;i=Object.getPrototypeOf(i)){let t=Object.getOwnPropertyDescriptor(i,s);if(t)return{descriptor:t,own:i===e}}};function v(e,s,i){let t=C(e,s),n=t?.descriptor.get,r=t?.descriptor.set;return!t||!n||!r?()=>{}:(Object.defineProperty(e,s,{configurable:!0,enumerable:t.descriptor.enumerable,get(){return n.call(this)},set(o){r.call(this,o),i()}}),()=>{t.own?Object.defineProperty(e,s,t.descriptor):Reflect.deleteProperty(e,s)})}var b=[\"zero\",\"one\",\"two\",\"few\",\"many\",\"other\"];var w=e=>[e,...b.map(s=>`${e}-${s}`)];function y(e,s){let i=e.getAttribute(s);if(i!==null)return i;let t=b.flatMap(n=>{let r=e.getAttribute(`${s}-${n}`);return r===null?[]:[[n,r]]});return t.length?Object.fromEntries(t):void 0}function I(e){try{return e(void 0)}catch{return e(\"en\")}}function l(e,s){try{return s(e)}catch{return I(s)}}function A(e,s,i){let t;if(typeof e==\"string\")t=e;else{let r=l(i,o=>new Intl.PluralRules(o)).select(s);t=e[r]??e.other}let n=l(i,r=>new Intl.NumberFormat(r)).format(s);return(t??\"\").replaceAll(\"%{count}\",n)}var p=[\"characters-under-limit\",\"characters-at-limit\",\"characters-over-limit\",\"words-under-limit\",\"words-at-limit\",\"words-over-limit\"],M={\"characters-under-limit\":{one:\"You have %{count} character remaining\",other:\"You have %{count} characters remaining\"},\"characters-at-limit\":\"You have 0 characters remaining\",\"characters-over-limit\":{one:\"You have %{count} character too many\",other:\"You have %{count} characters too many\"},\"words-under-limit\":{one:\"You have %{count} word remaining\",other:\"You have %{count} words remaining\"},\"words-at-limit\":\"You have 0 words remaining\",\"words-over-limit\":{one:\"You have %{count} word too many\",other:\"You have %{count} words too many\"}};var E=(e,s)=>y(e,s);function T(e,s,i){if(s===\"length\")return e.length;if(typeof Intl.Segmenter!=\"function\")return s===\"words\"?e.match(/\\S+/g)?.length??0:Array.from(e).length;let t=l(i,r=>new Intl.Segmenter(r,{granularity:s===\"words\"?\"word\":\"grapheme\"})),n=Array.from(t.segment(e));return s===\"words\"?n.filter(r=>r.isWordLike).length:n.length}function x(e,s,i,t){let n=e<0?\"over\":e===0?\"at\":\"under\",r=`${s===\"words\"?\"words\":\"characters\"}-${n}-limit`,o=i[r]??M[r];return{state:n,text:A(o,Math.abs(e),t)}}var u=e=>e?.split(/\\s+/).filter(Boolean)??[];function f(e,s){if(e.textContent===s)return;let{firstChild:i}=e;i instanceof Text&&e.childNodes.length===1?i.nodeValue=s:e.textContent=s}var g=\"govuk-react-character-count\",L={position:\"absolute\",width:\"1px\",height:\"1px\",margin:\"0\",padding:\"0\",overflow:\"hidden\",clip:\"rect(0 0 0 0)\",\"clip-path\":\"inset(50%)\",border:\"0\",\"white-space\":\"nowrap\"},P=e=>e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement;if(typeof HTMLElement<\"u\"&&typeof customElements<\"u\"){class e extends HTMLElement{constructor(){super(...arguments);this.currentCount=0;this.onInput=()=>{this.update(),this.lastInputTime=Date.now()};this.onFocus=()=>{window.clearInterval(this.checker),this.checker=window.setInterval(()=>{(!this.lastInputTime||Date.now()-500>=this.lastInputTime)&&this.announceIfChanged()},1e3)};this.onBlur=()=>window.clearInterval(this.checker);this.onReset=t=>{this.input&&t.target===this.input.form&&window.setTimeout(()=>this.update())};this.onPageShow=()=>{this.input&&(this.update(),this.announceIfChanged())}}static get observedAttributes(){return[\"maxlength\",\"count-type\",\"threshold\",\"within-limit-class\",\"over-limit-class\",\"below-threshold-class\",\"input-over-limit-class\",...p.flatMap(w)]}get count(){return this.input?this.currentCount:void 0}connectedCallback(){this.observer=new MutationObserver(t=>{t.some(n=>n.type===\"childList\")?this.setup():this.update()}),this.observer.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[\"class\",\"maxlength\"]}),window.addEventListener(\"pageshow\",this.onPageShow),document.addEventListener(\"reset\",this.onReset,!0),this.setup()}disconnectedCallback(){this.observer?.disconnect(),window.removeEventListener(\"pageshow\",this.onPageShow),document.removeEventListener(\"reset\",this.onReset,!0),window.clearInterval(this.checker),this.unbind()}attributeChangedCallback(){if(this.isConnected){if(!this.input){this.setup();return}if(this.maxLength===void 0){this.downgrade();return}this.lastAnnouncedValue=void 0,this.update()}}own(t){return Array.from(this.querySelectorAll(t)).find(n=>n.closest(g)===this)}get maxLength(){let t=Number(this.getAttribute(\"maxlength\"));return this.hasAttribute(\"maxlength\")&&Number.isFinite(t)?t:void 0}get countType(){let t=this.getAttribute(\"count-type\");return t===\"characters\"||t===\"words\"?t:\"length\"}get locale(){return(this.input??this).closest(\"[lang]\")?.getAttribute(\"lang\")||\"en\"}setup(){let t=this.own(\"[data-character-count-input]\");if(!P(t)||this.maxLength===void 0)return;let n=t!==this.input;n&&(this.unbind(),this.input=t,t.addEventListener(\"input\",this.onInput),t.addEventListener(\"focus\",this.onFocus),t.addEventListener(\"blur\",this.onBlur),this.stopWatchingValue=v(t,\"value\",()=>this.update()),t.removeAttribute(\"maxlength\"),this.lastAnnouncedValue=void 0),this.dataset.upgraded=\"\";let r=this.own(\"[data-character-count-description]\");r&&!this.hasAttribute(\"hidden-description-class\")&&Object.entries(L).forEach(([o,h])=>r.style.setProperty(o,h)),[this.own(\"[data-character-count-status]\"),this.own(\"[data-character-count-sr-status]\")].forEach(o=>{o&&(o.hidden=!1)}),this.update(),n&&this.announceIfChanged()}unbind(){let{input:t}=this;t&&(t.removeEventListener(\"input\",this.onInput),t.removeEventListener(\"focus\",this.onFocus),t.removeEventListener(\"blur\",this.onBlur),this.stopWatchingValue?.(),window.clearInterval(this.checker),this.input=void 0)}downgrade(){let{input:t}=this;if(!t)return;u(this.getAttribute(\"input-over-limit-class\")).forEach(r=>t.classList.toggle(r,!1)),this.unbind(),delete this.dataset.upgraded;let n=this.own(\"[data-character-count-description]\");n&&(this.hasAttribute(\"hidden-description-class\")?u(this.getAttribute(\"hidden-description-class\")).forEach(r=>n.classList.toggle(r,!1)):Object.keys(L).forEach(r=>n.style.removeProperty(r))),[this.own(\"[data-character-count-status]\"),this.own(\"[data-character-count-sr-status]\")].forEach(r=>{r&&(r.hidden=!0)})}update(){this.input&&(this.input.removeAttribute(\"maxlength\"),this.currentCount=T(this.input.value,this.countType,this.locale),this.render())}message(){let t=Object.fromEntries(p.map(n=>[n,E(this,n)]));return x((this.maxLength??1/0)-this.currentCount,this.countType,t,this.locale)}get belowThreshold(){let t=Number(this.getAttribute(\"threshold\"));return t?this.currentCount<(this.maxLength??1/0)*t/100:!1}render(){let{input:t}=this;if(!t)return;let{state:n,text:r}=this.message(),o=n===\"over\",h=this.own(\"[data-character-count-description]\");u(this.getAttribute(\"hidden-description-class\")).forEach(a=>h?.classList.toggle(a,!0)),u(this.getAttribute(\"input-over-limit-class\")).forEach(a=>t.classList.toggle(a,o));let d=this.belowThreshold,m=this.own(\"[data-character-count-sr-status]\");d?m?.setAttribute(\"aria-hidden\",\"true\"):m?.removeAttribute(\"aria-hidden\");let c=this.own(\"[data-character-count-status]\");c&&(c.dataset.state=n,c.toggleAttribute(\"data-below-threshold\",d),u(this.getAttribute(\"below-threshold-class\")).forEach(a=>c.classList.toggle(a,d)),u(this.getAttribute(\"within-limit-class\")).forEach(a=>c.classList.toggle(a,!o)),u(this.getAttribute(\"over-limit-class\")).forEach(a=>c.classList.toggle(a,o)),f(c,r))}announceIfChanged(){let{input:t}=this,n=this.own(\"[data-character-count-sr-status]\");if(!t||!n||t.value===this.lastAnnouncedValue)return;this.lastAnnouncedValue=t.value;let{state:r,text:o}=this.message();n.dataset.state=r,f(n,o)}}customElements.get(g)||customElements.define(g,e)}})();";
7
+ const choices = "\"use strict\";(()=>{var d=s=>s?.split(/\\s+/).filter(Boolean)??[];var u=(s,c)=>{for(let o=s;o;o=Object.getPrototypeOf(o)){let e=Object.getOwnPropertyDescriptor(o,c);if(e)return{descriptor:e,own:o===s}}};function l(s,c,o){let e=u(s,c),t=e?.descriptor.get,i=e?.descriptor.set;return!e||!t||!i?()=>{}:(Object.defineProperty(s,c,{configurable:!0,enumerable:e.descriptor.enumerable,get(){return t.call(this)},set(n){i.call(this,n),o()}}),()=>{e.own?Object.defineProperty(s,c,e.descriptor):Reflect.deleteProperty(s,c)})}var a=\"govuk-react-choices\",h=s=>s instanceof HTMLInputElement&&(s.type===\"radio\"||s.type===\"checkbox\");if(typeof HTMLElement<\"u\"&&typeof customElements<\"u\"){class s extends HTMLElement{constructor(){super(...arguments);this.upgraded=!1;this.watched=new Map;this.syncQueued=!1;this.onCheckedSet=()=>{this.syncQueued||(this.syncQueued=!0,queueMicrotask(()=>{this.syncQueued=!1,this.syncAll()}))};this.onClick=e=>{let t=e.target;if(!h(t)||!this.owns(t))return;if(t.type===\"radio\"){this.syncAll();return}if(this.syncInput(t),!t.checked)return;let i=t.hasAttribute(\"data-choices-exclusive\"),n=this.inputsNamed(t).filter(r=>r!==t&&r.type===\"checkbox\"&&r.checked&&(i||r.hasAttribute(\"data-choices-exclusive\")));window.setTimeout(()=>{n.filter(r=>r.checked).forEach(r=>{r.disabled?r.checked=!1:r.click()}),this.syncAll()})};this.onReset=e=>{e.target instanceof HTMLFormElement&&this.choices().some(t=>t.form===e.target)&&window.setTimeout(()=>this.sync())};this.onChange=e=>{h(e.target)&&this.owns(e.target)&&this.sync()};this.onPageShow=()=>this.sync()}connectedCallback(){this.observer=new MutationObserver(e=>{e.some(t=>t.type===\"childList\")?this.setup():(this.upgraded&&this.addUpgradedClasses(),this.sync())}),this.observer.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[\"class\"]}),this.addEventListener(\"click\",this.onClick),this.addEventListener(\"change\",this.onChange),window.addEventListener(\"pageshow\",this.onPageShow),document.addEventListener(\"reset\",this.onReset,!0),this.setup()}disconnectedCallback(){this.observer?.disconnect(),this.removeEventListener(\"click\",this.onClick),this.removeEventListener(\"change\",this.onChange),window.removeEventListener(\"pageshow\",this.onPageShow),document.removeEventListener(\"reset\",this.onReset,!0),this.watched.forEach(e=>e()),this.watched.clear()}get root(){let e=this.getRootNode();return e instanceof Document||e instanceof ShadowRoot?e:document}inputsNamed(e){return Array.from(this.root.querySelectorAll(\"input\")).filter(t=>t.type===e.type&&t.name===e.name&&t.form===e.form)}syncAll(){Array.from(this.root.querySelectorAll(a)).forEach(e=>{e instanceof s&&e.sync()})}owns(e){return e.closest(a)===this}choices(){return Array.from(this.querySelectorAll(\"input\")).filter(e=>h(e)&&this.owns(e))}target(e){let t=e.getAttribute(\"data-choices-controls\");if(!t)return;let i=this.getRootNode(),n=i instanceof Document||i instanceof ShadowRoot?i.getElementById(t):null;return n instanceof HTMLElement&&n.hasAttribute(\"data-choices-conditional\")?n:void 0}watch(e){this.watched.forEach((t,i)=>{e.includes(i)||(t(),this.watched.delete(i))}),e.forEach(t=>{this.watched.has(t)||this.watched.set(t,l(t,\"checked\",this.onCheckedSet))})}setup(){let e=this.choices();this.watch(e),e.length&&(this.upgraded||(this.upgraded=!0,this.dataset.upgraded=\"\",this.addUpgradedClasses()),this.sync())}addUpgradedClasses(){d(this.getAttribute(\"upgraded-class\")).forEach(e=>this.classList.toggle(e,!0))}sync(){this.upgraded&&this.choices().forEach(e=>this.syncInput(e))}syncInput(e){let t=this.target(e);if(!t)return;e.setAttribute(\"aria-controls\",t.id),e.setAttribute(\"aria-expanded\",String(e.checked));let i=d(this.getAttribute(\"hidden-conditional-class\"));i.length?i.forEach(n=>t.classList.toggle(n,!e.checked)):t.hidden=!e.checked}}customElements.get(a)||customElements.define(a,s)}})();";
8
+ const disclosure = "\"use strict\";(()=>{function a(r,o){if(o())return;let i=new MutationObserver(()=>{o()&&i.disconnect()});return i.observe(r,{childList:!0,subtree:!0}),i}var d=\"govuk-react-disclosure\";if(typeof HTMLElement<\"u\"&&typeof customElements<\"u\"){class r extends HTMLElement{constructor(){super(...arguments);this.isOpen=!1;this.controlled=!1;this.onClick=()=>{let e=!this.isOpen;this.hasAttribute(\"open\")||(this.apply(e),this.controlled||(this.picked=e)),this.dispatchEvent(new CustomEvent(\"govuk-react-disclosure:change\",{detail:{open:e},bubbles:!0}))};this.onModeChange=()=>this.render()}static get observedAttributes(){return[\"open\"]}get expanded(){return this.toggle?this.isOpen:void 0}get pickedOpen(){return this.picked}connectedCallback(){this.observer=a(this,()=>this.setup())}disconnectedCallback(){this.observer?.disconnect(),this.toggle?.removeEventListener(\"click\",this.onClick),this.mql?.removeEventListener(\"change\",this.onModeChange),this.toggle=void 0,this.content=void 0,this.mql=void 0}attributeChangedCallback(){let e=this.getAttribute(\"open\");e!==null&&(this.controlled=!0,this.apply(e===\"true\"))}own(e,t){let n=Array.from(this.querySelectorAll(e)).find(s=>s.closest(d)===this);return n instanceof t?n:void 0}setup(){if(this.toggle)return!0;let e=this.own(\"[data-disclosure-toggle]\",HTMLButtonElement),t=this.own(\"[data-disclosure-content]\",HTMLElement);if(!e||!t)return!1;this.toggle=e,this.content=t;let n=this.getAttribute(\"open\");this.isOpen=n===null?this.hasAttribute(\"default-open\"):n===\"true\";let s=this.getAttribute(\"media\");return s&&(this.mql=window.matchMedia(s),this.mql.addEventListener(\"change\",this.onModeChange)),e.addEventListener(\"click\",this.onClick),this.render(),!0}apply(e){e!==this.isOpen&&(this.isOpen=e,this.render())}render(){let{toggle:e,content:t}=this;if(!(!e||!t)){if(this.mql?.matches){t.hidden=!1,e.hidden=!0,e.setAttribute(\"aria-hidden\",\"true\"),e.removeAttribute(\"aria-expanded\");return}e.hidden=!1,e.removeAttribute(\"aria-hidden\"),e.setAttribute(\"aria-expanded\",String(this.isOpen)),t.id&&e.setAttribute(\"aria-controls\",t.id),t.hidden=!this.isOpen}}}customElements.get(d)||customElements.define(d,r)}})();";
9
+ const exitThisPage = "\"use strict\";(()=>{var o=d=>d?.split(/\\s+/).filter(Boolean)??[];var a=\"govuk-react-exit-this-page\",v=[\"activated\",\"timed-out\",\"press-two-more-times\",\"press-one-more-time\"],c={activated:\"Loading.\",\"timed-out\":\"Exit this page expired.\",\"press-two-more-times\":\"Shift, press 2 more times to exit.\",\"press-one-more-time\":\"Shift, press 1 more time to exit.\"},u=5e3,h={position:\"fixed\",inset:\"0\",\"z-index\":\"2147483647\",background:\"white\"};if(typeof HTMLElement<\"u\"&&typeof customElements<\"u\"){class d extends HTMLElement{constructor(){super(...arguments);this.presses=0;this.lastKeyWasModified=!1;this.onClick=e=>{if(e.defaultPrevented||e.button!==0)return;let t=e.target instanceof Element?e.target.closest(\"a\"):null;if(!t)return;let s=t.matches(\"[data-exit-this-page-button]\")&&t.closest(a)===this,i=t.matches(\"[data-exit-this-page-skiplink]\")&&this.listening;!s&&!i||(e.preventDefault(),this.exit())};this.onKeyup=e=>{this.listening&&(e.key===\"Shift\"&&!this.lastKeyWasModified?(this.presses+=1,this.updateIndicator(),window.clearTimeout(this.messageTimeout),this.presses>=3?(this.presses=0,window.clearTimeout(this.pressTimeout),this.pressTimeout=void 0,this.exit()):(this.setStatus(this.message(this.presses===1?\"press-two-more-times\":\"press-one-more-time\")),window.clearTimeout(this.pressTimeout),this.pressTimeout=window.setTimeout(this.timeOut,u))):this.pressTimeout!==void 0&&this.timeOut(),this.lastKeyWasModified=e.shiftKey)};this.timeOut=()=>{window.clearTimeout(this.pressTimeout),this.pressTimeout=void 0,this.presses=0,this.setStatus(this.message(\"timed-out\")),this.messageTimeout=window.setTimeout(()=>this.setStatus(\"\"),u),this.updateIndicator()};this.reset=e=>{e.persisted&&(o(this.getAttribute(\"hide-content-class\")).forEach(t=>document.body.classList.remove(t)),this.overlay?.remove(),this.overlay=void 0,this.presses=0,this.setStatus(\"\"),this.updateIndicator(),this.clearTimers())}}connectedCallback(){this.dataset.upgraded=\"\",document.addEventListener(\"keyup\",this.onKeyup,!0),document.addEventListener(\"click\",this.onClick),window.addEventListener(\"pageshow\",this.reset)}disconnectedCallback(){document.removeEventListener(\"keyup\",this.onKeyup,!0),document.removeEventListener(\"click\",this.onClick),window.removeEventListener(\"pageshow\",this.reset),this.clearTimers(),this.presses=0,this.setStatus(\"\"),this.updateIndicator()}exit(){let e=this.own(\"[data-exit-this-page-button]\"),t=e instanceof HTMLAnchorElement?e.href:void 0,s=t!==void 0&&this.dispatchEvent(new CustomEvent(\"govuk-react-exit-this-page:exit\",{detail:{href:t},bubbles:!0,cancelable:!0}));if(!t||!s){this.setStatus(\"\"),this.updateIndicator();return}this.setStatus(\"\"),o(this.getAttribute(\"hide-content-class\")).forEach(r=>document.body.classList.add(r)),this.overlay?.remove();let i=document.createElement(\"div\");i.setAttribute(\"role\",\"alert\");let n=o(this.getAttribute(\"overlay-class\"));n.length?i.classList.add(...n):Object.entries(h).forEach(([r,l])=>i.style.setProperty(r,l)),document.body.appendChild(i),i.textContent=this.message(\"activated\"),this.overlay=i,window.location.href=t}get listening(){return document.querySelector(a)===this}own(e){return Array.from(this.querySelectorAll(e)).find(t=>t.closest(a)===this)}message(e){return this.getAttribute(e)??c[e]}setStatus(e){let t=this.own(\"[data-exit-this-page-status]\");if(!t||t.textContent===e)return;let{firstChild:s}=t;s instanceof Text&&t.childNodes.length===1?s.nodeValue=e:t.textContent=e}clearTimers(){window.clearTimeout(this.pressTimeout),window.clearTimeout(this.messageTimeout),this.pressTimeout=void 0,this.messageTimeout=void 0}updateIndicator(){let e=this.own(\"[data-exit-this-page-indicator]\");if(!e)return;let t=this.presses>0;e.toggleAttribute(\"data-visible\",t),o(this.getAttribute(\"indicator-visible-class\")).forEach(s=>e.classList.toggle(s,t)),e.querySelectorAll(\"[data-exit-this-page-light]\").forEach((s,i)=>{let n=i<this.presses;s.toggleAttribute(\"data-on\",n),o(this.getAttribute(\"light-on-class\")).forEach(r=>s.classList.toggle(r,n))})}}customElements.get(a)||customElements.define(a,d)}})();";
10
+ const fileUpload = "\"use strict\";(()=>{var m=[\"zero\",\"one\",\"two\",\"few\",\"many\",\"other\"];var b=n=>[n,...m.map(i=>`${n}-${i}`)];function v(n,i){let s=n.getAttribute(i);if(s!==null)return s;let t=m.flatMap(e=>{let r=n.getAttribute(`${i}-${e}`);return r===null?[]:[[e,r]]});return t.length?Object.fromEntries(t):void 0}function y(n){try{return n(void 0)}catch{return n(\"en\")}}function g(n,i){try{return i(n)}catch{return y(i)}}function u(n,i,s){let t;if(typeof n==\"string\")t=n;else{let r=g(s,a=>new Intl.PluralRules(a)).select(i);t=n[r]??n.other}let e=g(s,r=>new Intl.NumberFormat(r)).format(i);return(t??\"\").replaceAll(\"%{count}\",e)}var c=n=>n?.split(/\\s+/).filter(Boolean)??[];function E(n,i){if(n.textContent===i)return;let{firstChild:s}=n;s instanceof Text&&n.childNodes.length===1?s.nodeValue=i:n.textContent=i}function o(n,i,s){s===null?n.removeAttribute(i):n.getAttribute(i)!==s&&n.setAttribute(i,s)}var p=\"govuk-react-file-upload\",h={\"no-file-chosen\":\"No file chosen\",\"multiple-files-chosen\":{one:\"%{count} file chosen\",other:\"%{count} files chosen\"},\"entered-drop-zone\":\"Entered drop zone\",\"left-drop-zone\":\"Left drop zone\"};function L(n,i,s){return n.length===0?u(i[\"no-file-chosen\"]??h[\"no-file-chosen\"],0,s):n.length===1?n[0].name:u(i[\"multiple-files-chosen\"]??h[\"multiple-files-chosen\"],n.length,s)}var D=n=>Array.from(n).filter(i=>i.kind===\"file\").length;if(typeof HTMLElement<\"u\"&&typeof customElements<\"u\"){class n extends HTMLElement{constructor(){super(...arguments);this.fieldId=\"\";this.dragging=!1;this.enteredAnotherElement=!1;this.onChange=()=>this.update();this.onReset=()=>window.setTimeout(()=>this.update());this.onClick=()=>this.input?.click();this.onDragOver=t=>t.preventDefault();this.onDrop=t=>{t.preventDefault();let{input:e}=this,r=t.dataTransfer?.files;!e||!r||!this.matchesCapacity(r.length)||(e.files=r,e.dispatchEvent(new Event(\"input\",{bubbles:!0})),e.dispatchEvent(new Event(\"change\",{bubbles:!0})),this.setDragging(!1))};this.onDocumentDragEnter=t=>{this.enteredAnotherElement=!0,!(!this.button||this.button.disabled||!(t.target instanceof Node))&&(this.dropZone.contains(t.target)?t.dataTransfer&&this.canDrop(t.dataTransfer)&&!this.dragging&&(this.setDragging(!0),this.announce(\"entered-drop-zone\")):this.dragging&&(this.setDragging(!1),this.announce(\"left-drop-zone\")))};this.onDocumentDragLeave=()=>{!this.enteredAnotherElement&&this.dragging&&!this.button?.disabled&&(this.setDragging(!1),this.announce(\"left-drop-zone\")),this.enteredAnotherElement=!1}}static get observedAttributes(){return[\"empty-class\",\"dragging-class\",\"disabled-class\",...Object.keys(h).flatMap(b)]}connectedCallback(){this.observer=new MutationObserver(()=>this.setup()),this.observer.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[\"class\",\"disabled\",\"id\",\"aria-describedby\"]}),document.addEventListener(\"dragenter\",this.onDocumentDragEnter),document.addEventListener(\"dragleave\",this.onDocumentDragLeave),this.setup()}disconnectedCallback(){this.observer?.disconnect(),document.removeEventListener(\"dragenter\",this.onDocumentDragEnter),document.removeEventListener(\"dragleave\",this.onDocumentDragLeave),this.unbind()}attributeChangedCallback(){this.isConnected&&this.update()}own(t){return Array.from(this.querySelectorAll(t)).find(e=>e.closest(p)===this)}get dropZone(){return this.own(\"[data-file-upload-drop-zone]\")??this}get locale(){return this.closest(\"[lang]\")?.getAttribute(\"lang\")||\"en\"}message(t){return v(this,t)??h[t]}setup(){let t=this.own('input[type=\"file\"]'),e=this.own(\"button[data-file-upload-button]\");!t||!e||(t.id!==`${this.fieldId}-input`&&(this.fieldId=t.id),this.fieldId&&((t!==this.input||e!==this.button)&&(this.unbind(),this.input=t,this.button=e,this.form=t.form,t.addEventListener(\"change\",this.onChange),this.form?.addEventListener(\"reset\",this.onReset),e.addEventListener(\"click\",this.onClick),e.addEventListener(\"dragover\",this.onDragOver),e.addEventListener(\"drop\",this.onDrop)),this.upgrade(t,e),this.update()))}unbind(){this.input?.removeEventListener(\"change\",this.onChange),this.form?.removeEventListener(\"reset\",this.onReset),this.button?.removeEventListener(\"click\",this.onClick),this.button?.removeEventListener(\"dragover\",this.onDragOver),this.button?.removeEventListener(\"drop\",this.onDrop),this.input=void 0,this.button=void 0,this.form=void 0}upgrade(t,e){let r=this.fieldId,a=this.getRootNode(),l=a instanceof Document||a instanceof ShadowRoot?a.querySelector(`label[for=\"${CSS.escape(r)}\"]`):null;l&&!l.id&&(l.id=`${r}-label`),o(t,\"id\",`${r}-input`),o(e,\"id\",r);let d=e.querySelector(\"[data-file-upload-separator]\");d&&o(d,\"id\",`${r}-comma`),l&&o(e,\"aria-labelledby\",[l.id,d?.id,r].filter(Boolean).join(\" \")),o(e,\"aria-describedby\",t.getAttribute(\"aria-describedby\")),o(t,\"hidden\",\"hidden\"),e.hidden&&(e.hidden=!1),this.dataset.upgraded=\"\"}update(){let{input:t,button:e}=this;if(!t||!e)return;let{files:r}=t,a=!r?.length,l=e.querySelector(\"[data-file-upload-status]\");l&&E(l,L(r??[],{\"no-file-chosen\":this.message(\"no-file-chosen\"),\"multiple-files-chosen\":this.message(\"multiple-files-chosen\")},this.locale)),o(e,\"data-empty\",a?\"\":null),c(this.getAttribute(\"empty-class\")).forEach(f=>e.classList.toggle(f,a)),e.disabled!==t.disabled&&(e.disabled=t.disabled);let d=this.dropZone;o(d,\"data-disabled\",t.disabled?\"\":null),c(this.getAttribute(\"disabled-class\")).forEach(f=>d.classList.toggle(f,t.disabled)),t.disabled?this.setDragging(!1):this.renderDragging()}setDragging(t){this.dragging=t,this.renderDragging()}renderDragging(){let{button:t,dragging:e}=this;t&&(o(t,\"data-dragging\",e?\"\":null),c(this.getAttribute(\"dragging-class\")).forEach(r=>t.classList.toggle(r,e)))}announce(t){let e=this.own(\"[data-file-upload-announcements]\");e&&(e.textContent=u(this.message(t),0,this.locale))}canDrop(t){return t.items.length?this.matchesCapacity(D(t.items)):t.types.length?t.types.includes(\"Files\"):!0}matchesCapacity(t){return this.input?.multiple?t>0:t===1}}customElements.get(p)||customElements.define(p,n)}})();";
11
+ const focusLinks = "\"use strict\";(()=>{function a(t,n,o){o.forEach(e=>t.classList.remove(e)),n&&t.removeAttribute(\"tabindex\"),t.removeAttribute(\"data-focus-tabindex\"),t.removeAttribute(\"autofocus\")}var f=t=>!t.hasAttribute(\"tabindex\")||t.hasAttribute(\"data-focus-tabindex\")&&t.getAttribute(\"tabindex\")===\"-1\";function u(t,{focusedClasses:n=[],preventScroll:o=!1}={}){let e=f(t);return t.hasAttribute(\"tabindex\")||t.setAttribute(\"tabindex\",\"-1\"),document.activeElement!==t&&(n.forEach(i=>t.classList.add(i)),t.focus({preventScroll:o})),document.activeElement!==t?(a(t,e,n),!1):(n.forEach(i=>t.classList.add(i)),t.addEventListener(\"blur\",()=>a(t,e,n),{once:!0}),!0)}var l=t=>t?.split(/\\s+/).filter(Boolean)??[];var d=\"govuk-react-focus-links\",g=t=>t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement||t instanceof HTMLButtonElement;function h(t){let n=t.closest(\"fieldset\")?.getElementsByTagName(\"legend\")[0];if(n){if(t instanceof HTMLInputElement&&(t.type===\"checkbox\"||t.type===\"radio\"))return n;let o=n.getBoundingClientRect().top,e=t.getBoundingClientRect();if(e.height&&window.innerHeight&&e.top+e.height-o<window.innerHeight/2)return n}return document.querySelector(`label[for=\"${CSS.escape(t.id)}\"]`)??t.closest(\"label\")}if(typeof HTMLElement<\"u\"&&typeof customElements<\"u\"){class t extends HTMLElement{constructor(){super(...arguments);this.onClick=e=>{if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey)return;let i=e.target instanceof Element?e.target.closest(\"a[href]\"):null;if(!(i instanceof HTMLAnchorElement)||!this.contains(i)||!(i.getAttribute(\"href\")?.startsWith(\"#\")||i.origin===window.location.origin&&i.pathname===window.location.pathname&&i.search===window.location.search))return;let r=i.hash.slice(1);try{r=decodeURIComponent(r)}catch{}let s=r?document.getElementById(r):null;if(s){if(g(s)){let c=h(s);if(!c)return;e.preventDefault(),c.scrollIntoView(),s.focus({preventScroll:!0});return}u(s,{focusedClasses:l(this.getAttribute(\"focused-class\"))})}}}connectedCallback(){this.addEventListener(\"click\",this.onClick)}disconnectedCallback(){this.removeEventListener(\"click\",this.onClick)}}customElements.get(d)||customElements.define(d,t)}})();";
12
+ const modal = "\"use strict\";(()=>{function c(i,l){if(l())return;let o=new MutationObserver(()=>{l()&&o.disconnect()});return o.observe(i,{childList:!0,subtree:!0}),o}var s=\"govuk-react-modal\",d=()=>typeof HTMLButtonElement<\"u\"&&\"command\"in HTMLButtonElement.prototype;if(typeof HTMLElement<\"u\"&&typeof customElements<\"u\"){class i extends HTMLElement{constructor(){super(...arguments);this.wasOpen=!1;this.onClick=e=>{let n=e.target instanceof Element?e.target.closest(\"button[commandfor]\"):null;if(!(n instanceof HTMLButtonElement)||n.closest(s)!==this)return;let t=document.getElementById(n.getAttribute(\"commandfor\")??\"\");if(!(t instanceof HTMLDialogElement))return;let r=n.getAttribute(\"command\");if(r===\"show-modal\"&&!t.open)t.showModal();else if(r===\"close\"&&t.open)t.close();else if(r===\"request-close\"&&t.open){let a=Reflect.get(t,\"requestClose\");typeof a==\"function\"?a.call(t):t.close()}};this.onToggle=()=>{let{dialog:e}=this;!e||e.open===this.wasOpen||(this.wasOpen=e.open,this.dispatchEvent(new CustomEvent(\"govuk-react-modal:change\",{detail:{open:e.open},bubbles:!0})))}}static get observedAttributes(){return[\"open\"]}connectedCallback(){d()||this.addEventListener(\"click\",this.onClick),this.observer=c(this,()=>this.setup())}disconnectedCallback(){this.removeEventListener(\"click\",this.onClick),this.observer?.disconnect(),this.dialog?.removeEventListener(\"close\",this.onToggle),this.dialog?.removeEventListener(\"toggle\",this.onToggle),this.dialog=void 0}attributeChangedCallback(){this.sync()}setup(){if(this.dialog)return!0;let e=Array.from(this.querySelectorAll(\"dialog\")).find(n=>n.closest(s)===this);return e?(this.dialog=e,this.wasOpen=e.open,e.addEventListener(\"toggle\",this.onToggle),e.addEventListener(\"close\",this.onToggle),this.sync(),!0):!1}sync(){let{dialog:e}=this,n=this.getAttribute(\"open\");if(!e||n===null)return;let t=n===\"true\";t!==e.open&&(this.wasOpen=t,t&&e.isConnected?e.showModal():t||e.close())}}customElements.get(s)||customElements.define(s,i)}})();";
13
+ const passwordInput = "\"use strict\";(()=>{var d=(i,n)=>{for(let s=i;s;s=Object.getPrototypeOf(s)){let t=Object.getOwnPropertyDescriptor(s,n);if(t)return{descriptor:t,own:s===i}}};function a(i,n,s){let t=d(i,n),e=t?.descriptor.get,o=t?.descriptor.set;return!t||!e||!o?()=>{}:(Object.defineProperty(i,n,{configurable:!0,enumerable:t.descriptor.enumerable,get(){return e.call(this)},set(u){o.call(this,u),s()}}),()=>{t.own?Object.defineProperty(i,n,t.descriptor):Reflect.deleteProperty(i,n)})}function l(i,n){if(n())return;let s=new MutationObserver(()=>{n()&&s.disconnect()});return s.observe(i,{childList:!0,subtree:!0}),s}var r=\"govuk-react-password-input\",p={\"show-text\":\"Show\",\"hide-text\":\"Hide\",\"show-label\":\"Show password\",\"hide-label\":\"Hide password\",\"shown-announcement\":\"Your password is visible\",\"hidden-announcement\":\"Your password is hidden\"},h=\"position:absolute;width:1px;height:1px;margin:0;padding:0;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);border:0;white-space:nowrap\";if(typeof HTMLElement<\"u\"&&typeof customElements<\"u\"){class i extends HTMLElement{constructor(){super(...arguments);this.visible=!1;this.onTypeSet=()=>{let t=this.visible?\"text\":\"password\";this.input&&this.input.type!==t&&(this.input.type=t)};this.onToggle=t=>{t.preventDefault(),this.setVisible(!this.visible)};this.onSubmit=t=>{let e=t instanceof SubmitEvent?t.submitter:null;t.target===this.input?.form&&!(e instanceof HTMLElement&&e.hidden)&&this.setVisible(!1)};this.onPageShow=t=>{t.persisted&&this.setVisible(!1)}}connectedCallback(){this.observer=l(this,()=>this.setup())}disconnectedCallback(){this.observer?.disconnect(),this.toggle?.removeEventListener(\"click\",this.onToggle),document.removeEventListener(\"submit\",this.onSubmit),window.removeEventListener(\"pageshow\",this.onPageShow),this.stopWatchingType?.(),this.input=void 0,this.toggle=void 0}text(t){return this.getAttribute(t)??p[t]}own(t,e){let o=this.querySelector(t);return o instanceof e&&o.closest(r)===this?o:void 0}setup(){if(this.input)return!0;let t=this.own(\"[data-password-input]\",HTMLInputElement),e=this.own(\"[data-password-toggle]\",HTMLButtonElement);return!t||!e?!1:(this.input=t,this.toggle=e,this.status=this.own(\"[data-password-status]\",HTMLElement),this.status||(this.status=document.createElement(\"div\"),this.status.dataset.passwordStatus=\"\",this.status.setAttribute(\"aria-live\",\"polite\"),this.status.setAttribute(\"style\",h),t.insertAdjacentElement(\"afterend\",this.status)),e.hidden=!1,e.addEventListener(\"click\",this.onToggle),document.addEventListener(\"submit\",this.onSubmit),window.addEventListener(\"pageshow\",this.onPageShow),this.visible=!1,t.type=\"password\",this.stopWatchingType=a(t,\"type\",this.onTypeSet),this.label(!1),!0)}setVisible(t){let{input:e}=this;!e||t===this.visible||(this.visible=t,e.type=t?\"text\":\"password\",this.label(t),this.status&&(this.status.textContent=this.text(t?\"shown-announcement\":\"hidden-announcement\")))}label(t){this.toggle&&(this.toggle.textContent=this.text(t?\"hide-text\":\"show-text\"),this.toggle.setAttribute(\"aria-label\",this.text(t?\"hide-label\":\"show-label\")))}}customElements.get(r)||customElements.define(r,i)}})();";
14
+ const tabs = "\"use strict\";(()=>{var h=n=>n?.split(/\\s+/).filter(Boolean)??[];var c=\"govuk-react-tabs\",r=n=>n instanceof HTMLElement?n.dataset.value:void 0,v=(n,g)=>{let u=g.filter(e=>!n.classList.contains(e));u.length&&n.classList.add(...u)};if(typeof HTMLElement<\"u\"&&typeof customElements<\"u\"){class n extends HTMLElement{constructor(){super(...arguments);this.started=!1;this.active=!1;this.provisional=!1;this.onModeChange=()=>this.checkMode();this.onReady=()=>this.start();this.onHashChange=()=>{let e=this.triggerForHash();e&&this.choose(e)};this.onClick=e=>{if(e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=this.ownTrigger(e.target);!t||this.radiosFallback||(e.preventDefault(),this.choose(t))};this.onKeydown=e=>{if(e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=this.ownTrigger(e.target);if(!t)return;let i=this.triggers,s=i.indexOf(t),a=i.length-1,o=this.getAttribute(\"orientation\")===\"vertical\",d={[o?\"ArrowDown\":\"ArrowRight\"]:s===a?0:s+1,[o?\"ArrowUp\":\"ArrowLeft\"]:s===0?a:s-1,Home:0,End:a}[e.key];d!==void 0&&(e.preventDefault(),this.choose(i[d]),i[d].focus())};this.onChange=e=>{let t=e.target;if(!(t instanceof HTMLInputElement)||!t.checked)return;let i=t.parentElement;if(!i?.matches(\"[data-tabs-content]\")||i.closest(c)!==this||this.radioOf(i)!==t)return;let s=r(i);if(!(s===void 0||s===this.dataset.value)){if(this.picked=s,this.provisional=!1,this.hasAttribute(\"value\"))queueMicrotask(()=>this.restoreRadio(t));else if(!this.active)this.dataset.value=s;else{this.show(this.triggerFor(s));let a=i.id;!this.radiosFallback&&this.active&&a&&window.location.hash!==`#${a}`&&window.history.pushState(window.history.state,\"\",`#${a}`)}this.dispatchEvent(new CustomEvent(\"govuk-react-tabs:change\",{detail:{value:s},bubbles:!0}))}}}static get observedAttributes(){return[\"value\"]}get value(){return this.getAttribute(\"value\")}set value(e){e==null?this.removeAttribute(\"value\"):this.setAttribute(\"value\",e)}get selectedValue(){return this.dataset.value}get pickedValue(){return this.picked!==void 0&&this.picked!==this.defaultSelection()?this.picked:void 0}select(e){let t=this.triggerFor(e);t&&(this.provisional=!1,this.active?this.show(t):(this.dataset.value=e,this.checkRadio(e)))}connectedCallback(){this.addEventListener(\"change\",this.onChange),this.observer=new MutationObserver(e=>{if(this.started){if(!this.active){(!this.mql||this.mql.matches)&&this.setup();return}e.some(t=>t.type===\"childList\")&&(this.wire(),this.provisional&&this.show(this.initialTrigger())),this.show(this.triggerFor(this.dataset.value)??this.triggers[0]),v(this,h(this.getAttribute(\"upgraded-class\")))}}),this.observer.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[\"class\"]}),document.readyState===\"loading\"?document.addEventListener(\"DOMContentLoaded\",this.onReady):this.start()}disconnectedCallback(){this.removeEventListener(\"change\",this.onChange),this.observer?.disconnect(),document.removeEventListener(\"DOMContentLoaded\",this.onReady),this.mql?.removeEventListener(\"change\",this.onModeChange),this.mql=void 0,this.started=!1,this.teardown()}attributeChangedCallback(e,t,i){this.started&&i!=null&&t!==i&&i!==this.dataset.value&&this.select(i)}get radiosFallback(){return this.getAttribute(\"fallback\")===\"radios\"}get triggers(){return this.own(\"[data-tabs-trigger]\")}own(e){return Array.from(this.querySelectorAll(e)).filter(t=>t.closest(c)===this)}ownTrigger(e){let t=e instanceof Element?e.closest(\"[data-tabs-trigger]\"):null;return this.triggers.find(i=>i===t)}triggerFor(e){return e==null?void 0:this.triggers.find(t=>r(t)===e)}triggerForHash(){if(this.radiosFallback)return;let e=decodeURIComponent(window.location.hash.slice(1));return e?this.triggers.find(t=>this.parts(r(t)).content?.id===e):void 0}parts(e){let t=i=>r(i)===e;return{item:this.own(\"[data-tabs-item]\").find(t),content:this.own(\"[data-tabs-content]\").find(t)}}radioOf(e){let t=e?.firstElementChild;return t instanceof HTMLInputElement&&t.type===\"radio\"?t:void 0}checkRadio(e){let t=this.own(\"[data-tabs-content]\").map(i=>({radio:this.radioOf(i),selected:r(i)===e}));t.some(({radio:i,selected:s})=>i&&s)&&(t.forEach(({radio:i,selected:s})=>{i&&!s&&(i.checked=!1)}),t.forEach(({radio:i,selected:s})=>{i&&s&&(i.checked=!0)}))}restoreRadio(e){r(e.parentElement)!==this.dataset.value&&this.checkRadio(this.dataset.value)}defaultSelection(){return r(this.triggerFor(this.getAttribute(\"value\")))??r(this.triggerFor(this.getAttribute(\"default-value\")))??r(this.triggers[0])}start(){if(document.removeEventListener(\"DOMContentLoaded\",this.onReady),this.started)return;this.started=!0;let e=this.getAttribute(\"media\");e&&(this.mql=window.matchMedia(e),this.mql.addEventListener(\"change\",this.onModeChange)),this.checkMode()}checkMode(){!this.mql||this.mql.matches?this.setup():this.teardown()}pickedTrigger(){let e=this.triggerForHash();if(e)return e;let t=this.own(\"[data-tabs-content]\").find(i=>this.radioOf(i)?.checked);return this.triggerFor(r(t))}initialTrigger(){let e=this.triggerFor(this.getAttribute(\"value\")),t=this.triggerFor(this.dataset.value),i=this.pickedTrigger(),s=this.triggerFor(this.getAttribute(\"default-value\")),a=(this.hasAttribute(\"prefer-pick\")&&!t?i:void 0)??e??t??i??s;return this.provisional=!a,a??this.triggers[0]}setup(){this.active||!this.triggers.length||(this.active=!0,this.dataset.upgraded=\"\",v(this,h(this.getAttribute(\"upgraded-class\"))),this.wire(),this.addEventListener(\"click\",this.onClick),this.addEventListener(\"keydown\",this.onKeydown),this.radiosFallback||window.addEventListener(\"hashchange\",this.onHashChange),this.picked===void 0&&!this.dataset.value&&(this.picked=r(this.pickedTrigger())),this.show(this.initialTrigger()))}wire(){let e=this.getAttribute(\"orientation\")===\"vertical\"?\"vertical\":\"horizontal\";this.own(\"[data-tabs-list]\").forEach(t=>{t.setAttribute(\"role\",\"tablist\"),t.setAttribute(\"aria-orientation\",e)}),this.own(\"[data-tabs-item]\").forEach(t=>t.setAttribute(\"role\",\"presentation\")),this.triggers.forEach(t=>{let{content:i}=this.parts(r(t));t.setAttribute(\"role\",\"tab\"),i&&(i.id||(i.id=`${r(t)}-panel`,i.dataset.tabsGeneratedId=\"\"),t.id||(t.id=`${i.id}-tab`,t.dataset.tabsGeneratedId=\"\"),t.setAttribute(\"aria-controls\",i.id),i.setAttribute(\"role\",\"tabpanel\"),i.setAttribute(\"aria-labelledby\",t.id))})}teardown(){if(!this.active)return;this.active=!1,delete this.dataset.upgraded,this.removeEventListener(\"click\",this.onClick),this.removeEventListener(\"keydown\",this.onKeydown),window.removeEventListener(\"hashchange\",this.onHashChange),this.radiosFallback||this.classList.remove(...h(this.getAttribute(\"upgraded-class\"))),this.own(\"[data-tabs-list]\").forEach(t=>{t.removeAttribute(\"role\"),t.removeAttribute(\"aria-orientation\")});let e=t=>{t.dataset.tabsGeneratedId!==void 0&&(t.removeAttribute(\"id\"),delete t.dataset.tabsGeneratedId)};this.own(\"[data-tabs-item]\").forEach(t=>{[\"role\",\"data-state\"].forEach(i=>t.removeAttribute(i)),t.classList.remove(...h(this.getAttribute(\"active-item-class\")))}),this.triggers.forEach(t=>{e(t),[\"role\",\"aria-controls\",\"aria-selected\",\"tabindex\",\"data-state\"].forEach(i=>t.removeAttribute(i))}),this.own(\"[data-tabs-content]\").forEach(t=>{e(t),[\"role\",\"aria-labelledby\",\"tabindex\",\"hidden\",\"data-state\"].forEach(i=>t.removeAttribute(i)),t.classList.remove(...h(this.getAttribute(\"hidden-content-class\")))})}choose(e){this.radioOf(this.parts(r(e)).content)?.click()}show(e){if(!e)return;let t=h(this.getAttribute(\"active-item-class\")),i=h(this.getAttribute(\"hidden-content-class\"));this.triggers.forEach(s=>{let a=s===e,o=a?\"active\":\"inactive\",{item:d,content:l}=this.parts(r(s));s.dataset.state!==o&&(s.dataset.state=o),s.setAttribute(\"aria-selected\",String(a)),s.setAttribute(\"tabindex\",a?\"0\":\"-1\"),d&&(d.dataset.state!==o&&(d.dataset.state=o),t.forEach(f=>d.classList.toggle(f,a))),l&&(l.dataset.state!==o&&(l.dataset.state=o),l.hidden=!a,i.forEach(f=>l.classList.toggle(f,!a)),a?l.setAttribute(\"tabindex\",\"0\"):l.removeAttribute(\"tabindex\"))}),this.dataset.value=r(e),this.checkRadio(this.dataset.value)}}customElements.get(c)||customElements.define(c,n)}})();";
15
+ /*
16
+ * The elements' scripts, to inline in the page, so the markup is interactive as soon as it loads,
17
+ * before React. Once React loads, its parts pick up where the elements are, and each element is
18
+ * defined only once, whichever script runs first.
19
+ *
20
+ * Each script is a string, so a bundler includes only the ones you import.
21
+ */
22
+ export { accordion, autocomplete, autoFocus, button, characterCount, choices, disclosure, exitThisPage, fileUpload, focusLinks, modal, passwordInput, tabs, };
23
+ /**
24
+ * Renders an element's script inline, such as `<InlineScript script={tabs} />` in the page's
25
+ * `head`. Pass `nonce` for a Content Security Policy. Rendered on the server: a script that React
26
+ * adds in the browser doesn't run, and isn't needed, since React's parts define their elements.
27
+ */
28
+ export function InlineScript({ script, ...props }) {
29
+ return React.createElement("script", { ...props, dangerouslySetInnerHTML: { __html: script } });
30
+ }
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/inline-script/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,YAAY,MAAM,qBAAqB,CAAC;AAC/C,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,cAAc,MAAM,wBAAwB,CAAC;AACpD,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,UAAU,MAAM,mBAAmB,CAAC;AAC3C,OAAO,YAAY,MAAM,uBAAuB,CAAC;AACjD,OAAO,UAAU,MAAM,oBAAoB,CAAC;AAC5C,OAAO,UAAU,MAAM,oBAAoB,CAAC;AAC5C,OAAO,KAAK,MAAM,cAAc,CAAC;AACjC,OAAO,aAAa,MAAM,uBAAuB,CAAC;AAClD,OAAO,IAAI,MAAM,aAAa,CAAC;AAE/B;;;;;;GAMG;AAEH,OAAO,EACL,SAAS,EACT,YAAY,EACZ,SAAS,EACT,MAAM,EACN,cAAc,EACd,OAAO,EACP,UAAU,EACV,YAAY,EACZ,UAAU,EACV,UAAU,EACV,KAAK,EACL,aAAa,EACb,IAAI,GACL,CAAC;AAOF;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,KAAK,EAAqB;IAClE,OAAO,mCAAY,KAAK,EAAE,uBAAuB,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAI,CAAC;AAC5E,CAAC","sourcesContent":["import * as React from 'react';\nimport type { ComponentProps } from 'react';\nimport accordion from 'inline:accordion';\nimport autocomplete from 'inline:autocomplete';\nimport autoFocus from 'inline:auto-focus';\nimport button from 'inline:button';\nimport characterCount from 'inline:character-count';\nimport choices from 'inline:choices';\nimport disclosure from 'inline:disclosure';\nimport exitThisPage from 'inline:exit-this-page';\nimport fileUpload from 'inline:file-upload';\nimport focusLinks from 'inline:focus-links';\nimport modal from 'inline:modal';\nimport passwordInput from 'inline:password-input';\nimport tabs from 'inline:tabs';\n\n/*\n * The elements' scripts, to inline in the page, so the markup is interactive as soon as it loads,\n * before React. Once React loads, its parts pick up where the elements are, and each element is\n * defined only once, whichever script runs first.\n *\n * Each script is a string, so a bundler includes only the ones you import.\n */\n\nexport {\n accordion,\n autocomplete,\n autoFocus,\n button,\n characterCount,\n choices,\n disclosure,\n exitThisPage,\n fileUpload,\n focusLinks,\n modal,\n passwordInput,\n tabs,\n};\n\nexport type InlineScriptProps = Omit<ComponentProps<'script'>, 'children' | 'dangerouslySetInnerHTML' | 'src'> & {\n /** One of this module's scripts, such as `tabs`. */\n script: string;\n};\n\n/**\n * Renders an element's script inline, such as `<InlineScript script={tabs} />` in the page's\n * `head`. Pass `nonce` for a Content Security Policy. Rendered on the server: a script that React\n * adds in the browser doesn't run, and isn't needed, since React's parts define their elements.\n */\nexport function InlineScript({ script, ...props }: InlineScriptProps) {\n return <script {...props} dangerouslySetInnerHTML={{ __html: script }} />;\n}\n"]}
@@ -0,0 +1,10 @@
1
+ declare global {
2
+ interface HTMLElementEventMap {
3
+ 'govuk-react-modal:change': CustomEvent<{
4
+ open: boolean;
5
+ }>;
6
+ }
7
+ }
8
+ export declare const tagName = "govuk-react-modal";
9
+ /** Whether the browser runs invoker commands itself. */
10
+ export declare const supportsCommands: () => boolean;
@@ -0,0 +1,114 @@
1
+ /*
2
+ * <govuk-react-modal>: a headless, light-DOM custom element around a modal `dialog` and the
3
+ * buttons that open and close it.
4
+ *
5
+ * The buttons use invoker commands (`command="show-modal"` or `command="close"`, with
6
+ * `commandfor` naming the dialog), so a browser that supports them opens a true modal dialog
7
+ * with no JavaScript: the page behind is inert, focus moves into the dialog and Escape closes
8
+ * it. The `dialog` element is the state.
9
+ *
10
+ * The element only adds what HTML can't do on its own:
11
+ * - In a browser without invoker commands, it runs the commands of its own buttons.
12
+ * - `open` (when present) controls the dialog: "true" opens it with `showModal()`, anything
13
+ * else closes it. Changing `open` fires no change event.
14
+ * - It fires a bubbling `govuk-react-modal:change` event with `{ open }` when the dialog opens
15
+ * or closes, for code that doesn't use React.
16
+ *
17
+ * Markup inside the element:
18
+ * - a `dialog` with an id
19
+ * - `button`s with `commandfor` set to the dialog's id, and `command` set to "show-modal",
20
+ * "close" or "request-close"
21
+ */
22
+ import { setUpWhenReady } from '../utils/set-up-when-ready.js';
23
+ export const tagName = 'govuk-react-modal';
24
+ /** Whether the browser runs invoker commands itself. */
25
+ export const supportsCommands = () => typeof HTMLButtonElement !== 'undefined' && 'command' in HTMLButtonElement.prototype;
26
+ if (typeof HTMLElement !== 'undefined' && typeof customElements !== 'undefined') {
27
+ class GovukReactModal extends HTMLElement {
28
+ constructor() {
29
+ super(...arguments);
30
+ this.wasOpen = false;
31
+ // Runs the commands of the element's own buttons when the browser can't.
32
+ this.onClick = (event) => {
33
+ var _a;
34
+ const button = event.target instanceof Element ? event.target.closest('button[commandfor]') : null;
35
+ if (!(button instanceof HTMLButtonElement) || button.closest(tagName) !== this)
36
+ return;
37
+ const dialog = document.getElementById((_a = button.getAttribute('commandfor')) !== null && _a !== void 0 ? _a : '');
38
+ if (!(dialog instanceof HTMLDialogElement))
39
+ return;
40
+ const command = button.getAttribute('command');
41
+ if (command === 'show-modal' && !dialog.open)
42
+ dialog.showModal();
43
+ else if (command === 'close' && dialog.open)
44
+ dialog.close();
45
+ else if (command === 'request-close' && dialog.open) {
46
+ // Newer than this package's DOM types.
47
+ const requestClose = Reflect.get(dialog, 'requestClose');
48
+ if (typeof requestClose === 'function')
49
+ requestClose.call(dialog);
50
+ else
51
+ dialog.close();
52
+ }
53
+ };
54
+ this.onToggle = () => {
55
+ const { dialog } = this;
56
+ if (!dialog || dialog.open === this.wasOpen)
57
+ return;
58
+ this.wasOpen = dialog.open;
59
+ this.dispatchEvent(new CustomEvent('govuk-react-modal:change', { detail: { open: dialog.open }, bubbles: true }));
60
+ };
61
+ }
62
+ static get observedAttributes() {
63
+ return ['open'];
64
+ }
65
+ connectedCallback() {
66
+ if (!supportsCommands())
67
+ this.addEventListener('click', this.onClick);
68
+ this.observer = setUpWhenReady(this, () => this.setup());
69
+ }
70
+ disconnectedCallback() {
71
+ var _a, _b, _c;
72
+ this.removeEventListener('click', this.onClick);
73
+ (_a = this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
74
+ (_b = this.dialog) === null || _b === void 0 ? void 0 : _b.removeEventListener('close', this.onToggle);
75
+ (_c = this.dialog) === null || _c === void 0 ? void 0 : _c.removeEventListener('toggle', this.onToggle);
76
+ this.dialog = undefined;
77
+ }
78
+ attributeChangedCallback() {
79
+ this.sync();
80
+ }
81
+ setup() {
82
+ if (this.dialog)
83
+ return true;
84
+ const dialog = Array.from(this.querySelectorAll('dialog')).find((found) => found.closest(tagName) === this);
85
+ if (!dialog)
86
+ return false;
87
+ this.dialog = dialog;
88
+ this.wasOpen = dialog.open;
89
+ // `toggle` fires on open and close where supported, and `close` everywhere.
90
+ dialog.addEventListener('toggle', this.onToggle);
91
+ dialog.addEventListener('close', this.onToggle);
92
+ this.sync();
93
+ return true;
94
+ }
95
+ /** Opens or closes the dialog to match `open`, without reporting it. */
96
+ sync() {
97
+ const { dialog } = this;
98
+ const controlled = this.getAttribute('open');
99
+ if (!dialog || controlled === null)
100
+ return;
101
+ const open = controlled === 'true';
102
+ if (open === dialog.open)
103
+ return;
104
+ this.wasOpen = open;
105
+ if (open && dialog.isConnected)
106
+ dialog.showModal();
107
+ else if (!open)
108
+ dialog.close();
109
+ }
110
+ }
111
+ if (!customElements.get(tagName))
112
+ customElements.define(tagName, GovukReactModal);
113
+ }
114
+ //# sourceMappingURL=element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element.js","sourceRoot":"","sources":["../../src/modal/element.ts"],"names":[],"mappings":"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","sourcesContent":["/*\n * <govuk-react-modal>: a headless, light-DOM custom element around a modal `dialog` and the\n * buttons that open and close it.\n *\n * The buttons use invoker commands (`command=\"show-modal\"` or `command=\"close\"`, with\n * `commandfor` naming the dialog), so a browser that supports them opens a true modal dialog\n * with no JavaScript: the page behind is inert, focus moves into the dialog and Escape closes\n * it. The `dialog` element is the state.\n *\n * The element only adds what HTML can't do on its own:\n * - In a browser without invoker commands, it runs the commands of its own buttons.\n * - `open` (when present) controls the dialog: \"true\" opens it with `showModal()`, anything\n * else closes it. Changing `open` fires no change event.\n * - It fires a bubbling `govuk-react-modal:change` event with `{ open }` when the dialog opens\n * or closes, for code that doesn't use React.\n *\n * Markup inside the element:\n * - a `dialog` with an id\n * - `button`s with `commandfor` set to the dialog's id, and `command` set to \"show-modal\",\n * \"close\" or \"request-close\"\n */\n\nimport { setUpWhenReady } from '../utils/set-up-when-ready.js';\n\ndeclare global {\n interface HTMLElementEventMap {\n 'govuk-react-modal:change': CustomEvent<{ open: boolean }>;\n }\n}\n\nexport const tagName = 'govuk-react-modal';\n\n/** Whether the browser runs invoker commands itself. */\nexport const supportsCommands = () =>\n typeof HTMLButtonElement !== 'undefined' && 'command' in HTMLButtonElement.prototype;\n\nif (typeof HTMLElement !== 'undefined' && typeof customElements !== 'undefined') {\n class GovukReactModal extends HTMLElement {\n static get observedAttributes() {\n return ['open'];\n }\n\n private dialog?: HTMLDialogElement;\n\n private observer?: MutationObserver;\n\n private wasOpen = false;\n\n // Runs the commands of the element's own buttons when the browser can't.\n private readonly onClick = (event: MouseEvent) => {\n const button = event.target instanceof Element ? event.target.closest('button[commandfor]') : null;\n if (!(button instanceof HTMLButtonElement) || button.closest(tagName) !== this) return;\n const dialog = document.getElementById(button.getAttribute('commandfor') ?? '');\n if (!(dialog instanceof HTMLDialogElement)) return;\n const command = button.getAttribute('command');\n if (command === 'show-modal' && !dialog.open) dialog.showModal();\n else if (command === 'close' && dialog.open) dialog.close();\n else if (command === 'request-close' && dialog.open) {\n // Newer than this package's DOM types.\n const requestClose: unknown = Reflect.get(dialog, 'requestClose');\n if (typeof requestClose === 'function') requestClose.call(dialog);\n else dialog.close();\n }\n };\n\n private readonly onToggle = () => {\n const { dialog } = this;\n if (!dialog || dialog.open === this.wasOpen) return;\n this.wasOpen = dialog.open;\n this.dispatchEvent(new CustomEvent('govuk-react-modal:change', { detail: { open: dialog.open }, bubbles: true }));\n };\n\n connectedCallback() {\n if (!supportsCommands()) this.addEventListener('click', this.onClick);\n this.observer = setUpWhenReady(this, () => this.setup());\n }\n\n disconnectedCallback() {\n this.removeEventListener('click', this.onClick);\n this.observer?.disconnect();\n this.dialog?.removeEventListener('close', this.onToggle);\n this.dialog?.removeEventListener('toggle', this.onToggle);\n this.dialog = undefined;\n }\n\n attributeChangedCallback() {\n this.sync();\n }\n\n private setup() {\n if (this.dialog) return true;\n const dialog = Array.from(this.querySelectorAll('dialog')).find((found) => found.closest(tagName) === this);\n if (!dialog) return false;\n this.dialog = dialog;\n this.wasOpen = dialog.open;\n // `toggle` fires on open and close where supported, and `close` everywhere.\n dialog.addEventListener('toggle', this.onToggle);\n dialog.addEventListener('close', this.onToggle);\n this.sync();\n return true;\n }\n\n /** Opens or closes the dialog to match `open`, without reporting it. */\n private sync() {\n const { dialog } = this;\n const controlled = this.getAttribute('open');\n if (!dialog || controlled === null) return;\n const open = controlled === 'true';\n if (open === dialog.open) return;\n this.wasOpen = open;\n if (open && dialog.isConnected) dialog.showModal();\n else if (!open) dialog.close();\n }\n }\n\n if (!customElements.get(tagName)) customElements.define(tagName, GovukReactModal);\n}\n"]}
@@ -0,0 +1,36 @@
1
+ import * as React from 'react';
2
+ import type { ComponentProps, ReactNode } from 'react';
3
+ export type RootProps = Omit<React.HTMLAttributes<HTMLElement>, 'onChange'> & {
4
+ children?: ReactNode;
5
+ /** Whether the dialog is open, to control it. Without it, the buttons alone open and close it. */
6
+ open?: boolean;
7
+ /** Called when the dialog opens or closes. */
8
+ onOpenChange?: (open: boolean) => void;
9
+ /** The dialog's id, which the buttons' `commandfor` names. Defaults to a generated one. */
10
+ dialogId?: string;
11
+ };
12
+ export declare function Root({ children, open, onOpenChange, dialogId: dialogIdProp, ...props }: RootProps): React.JSX.Element;
13
+ type PartProps<E extends keyof React.JSX.IntrinsicElements> = ComponentProps<E> & {
14
+ /** Render the only child instead, with this part's props merged onto it. */
15
+ asChild?: boolean;
16
+ };
17
+ type CommandProps = PartProps<'button'> & {
18
+ /** The dialog's id. Set by Root. */
19
+ dialogId?: string;
20
+ };
21
+ export type TriggerProps = CommandProps;
22
+ /** A button that opens the dialog as a modal. */
23
+ export declare function Trigger(props: TriggerProps): React.JSX.Element;
24
+ export type CloseProps = CommandProps;
25
+ /** A button that closes the dialog. */
26
+ export declare function Close(props: CloseProps): React.JSX.Element;
27
+ export type ContentProps = PartProps<'dialog'>;
28
+ /**
29
+ * The dialog. It's named by Title, unless you pass `aria-labelledby` or `aria-label`. Pass
30
+ * `closedby="any"` to also close it when the user clicks outside it.
31
+ */
32
+ export declare function Content({ asChild, id, onClose, ref, ...props }: ContentProps): React.JSX.Element;
33
+ export type TitleProps = PartProps<'h2'>;
34
+ /** The dialog's heading, which names it. */
35
+ export declare function Title({ asChild, ...props }: TitleProps): React.JSX.Element;
36
+ export {};
@@ -0,0 +1,109 @@
1
+ 'use client';
2
+ import * as React from 'react';
3
+ import { createContext, useContext, useEffect, useId, useRef } from 'react';
4
+ import { Slot } from '../utils/slot.js';
5
+ import { tagName } from './element.js';
6
+ /*
7
+ * Headless modal dialog: unstyled parts over a native `dialog` and the <govuk-react-modal>
8
+ * element (./element.ts). Every part except Root takes `asChild`.
9
+ *
10
+ * Trigger and Close are buttons with invoker commands (`command` and `commandfor`), so where
11
+ * the browser supports them the dialog opens as a true modal with no JavaScript: the page behind
12
+ * is inert, focus moves into the dialog, and Escape closes it. The element runs the commands in
13
+ * browsers without them, and applies `open` when controlled.
14
+ *
15
+ * Context only fills in ids: in an island without a Root, pass `dialogId` to Trigger and Close,
16
+ * and `id` to Content.
17
+ */
18
+ const ModalContext = createContext({});
19
+ export function Root({ children, open, onOpenChange, dialogId: dialogIdProp, ...props }) {
20
+ const generatedId = useId();
21
+ const dialogId = dialogIdProp !== null && dialogIdProp !== void 0 ? dialogIdProp : generatedId;
22
+ return (React.createElement(ModalContext.Provider, { value: { dialogId, titleId: `${dialogId}-title`, onOpenChange } }, React.createElement(tagName, {
23
+ ...props,
24
+ open: open === undefined ? undefined : String(open),
25
+ suppressHydrationWarning: true,
26
+ }, children)));
27
+ }
28
+ function Command({ command, asChild, dialogId, ...props }) {
29
+ const context = useContext(ModalContext);
30
+ // `command` and `commandfor` aren't in React's types yet, so they go in as a spread.
31
+ const invoker = { command, commandfor: dialogId !== null && dialogId !== void 0 ? dialogId : context.dialogId };
32
+ if (asChild)
33
+ return React.createElement(Slot, { ...invoker, ...props });
34
+ return React.createElement("button", { type: "button", ...invoker, ...props });
35
+ }
36
+ /** A button that opens the dialog as a modal. */
37
+ export function Trigger(props) {
38
+ return React.createElement(Command, { command: "show-modal", ...props });
39
+ }
40
+ /** A button that closes the dialog. */
41
+ export function Close(props) {
42
+ return React.createElement(Command, { command: "close", ...props });
43
+ }
44
+ /**
45
+ * The dialog. It's named by Title, unless you pass `aria-labelledby` or `aria-label`. Pass
46
+ * `closedby="any"` to also close it when the user clicks outside it.
47
+ */
48
+ export function Content({ asChild, id, onClose, ref, ...props }) {
49
+ const context = useContext(ModalContext);
50
+ const reported = useRef(undefined);
51
+ const onOpenChange = useRef(context.onOpenChange);
52
+ useEffect(() => {
53
+ onOpenChange.current = context.onOpenChange;
54
+ });
55
+ // Report each change once: `toggle` fires on opening and closing where the browser fires it on
56
+ // dialogs, and `close` on closing everywhere.
57
+ const report = (dialog) => {
58
+ var _a;
59
+ if (reported.current === dialog.open)
60
+ return;
61
+ reported.current = dialog.open;
62
+ (_a = onOpenChange.current) === null || _a === void 0 ? void 0 : _a.call(onOpenChange, dialog.open);
63
+ };
64
+ // A dialog the user opened before hydration, through its invoker command or the element, fired
65
+ // nothing React heard, so report it once.
66
+ const dialogRef = useRef(null);
67
+ useEffect(() => {
68
+ var _a;
69
+ const dialog = dialogRef.current;
70
+ if ((dialog === null || dialog === void 0 ? void 0 : dialog.open) && reported.current === undefined) {
71
+ reported.current = true;
72
+ (_a = onOpenChange.current) === null || _a === void 0 ? void 0 : _a.call(onOpenChange, true);
73
+ }
74
+ }, []);
75
+ // React doesn't listen for `toggle` on a dialog, so listen natively.
76
+ const listen = (dialog) => {
77
+ dialogRef.current = dialog;
78
+ if (typeof ref === 'function')
79
+ ref(dialog);
80
+ else if (ref)
81
+ ref.current = dialog;
82
+ if (!dialog)
83
+ return undefined;
84
+ const onToggle = () => report(dialog);
85
+ dialog.addEventListener('toggle', onToggle);
86
+ return () => dialog.removeEventListener('toggle', onToggle);
87
+ };
88
+ const shared = {
89
+ id: id !== null && id !== void 0 ? id : context.dialogId,
90
+ 'aria-labelledby': props['aria-label'] ? undefined : context.titleId,
91
+ ref: listen,
92
+ onClose: (event) => {
93
+ onClose === null || onClose === void 0 ? void 0 : onClose(event);
94
+ report(event.currentTarget);
95
+ },
96
+ // The dialog's open state belongs to the browser.
97
+ suppressHydrationWarning: true,
98
+ };
99
+ if (asChild)
100
+ return React.createElement(Slot, { ...shared, ...props });
101
+ return React.createElement("dialog", { ...shared, ...props });
102
+ }
103
+ /** The dialog's heading, which names it. */
104
+ export function Title({ asChild, ...props }) {
105
+ const context = useContext(ModalContext);
106
+ const Element = asChild ? Slot : 'h2';
107
+ return React.createElement(Element, { id: context.titleId, ...props });
108
+ }
109
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/modal/index.tsx"],"names":[],"mappings":"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","sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createContext, useContext, useEffect, useId, useRef } from 'react';\nimport type { ComponentProps, ReactNode, SyntheticEvent } from 'react';\nimport { Slot } from '../utils/slot.js';\nimport { tagName } from './element.js';\n\n/*\n * Headless modal dialog: unstyled parts over a native `dialog` and the <govuk-react-modal>\n * element (./element.ts). Every part except Root takes `asChild`.\n *\n * Trigger and Close are buttons with invoker commands (`command` and `commandfor`), so where\n * the browser supports them the dialog opens as a true modal with no JavaScript: the page behind\n * is inert, focus moves into the dialog, and Escape closes it. The element runs the commands in\n * browsers without them, and applies `open` when controlled.\n *\n * Context only fills in ids: in an island without a Root, pass `dialogId` to Trigger and Close,\n * and `id` to Content.\n */\n\nconst ModalContext = createContext<{\n dialogId?: string;\n titleId?: string;\n onOpenChange?: (open: boolean) => void;\n}>({});\n\nexport type RootProps = Omit<React.HTMLAttributes<HTMLElement>, 'onChange'> & {\n children?: ReactNode;\n /** Whether the dialog is open, to control it. Without it, the buttons alone open and close it. */\n open?: boolean;\n /** Called when the dialog opens or closes. */\n onOpenChange?: (open: boolean) => void;\n /** The dialog's id, which the buttons' `commandfor` names. Defaults to a generated one. */\n dialogId?: string;\n};\n\nexport function Root({ children, open, onOpenChange, dialogId: dialogIdProp, ...props }: RootProps) {\n const generatedId = useId();\n const dialogId = dialogIdProp ?? generatedId;\n return (\n <ModalContext.Provider value={{ dialogId, titleId: `${dialogId}-title`, onOpenChange }}>\n {React.createElement(\n tagName,\n {\n ...props,\n open: open === undefined ? undefined : String(open),\n suppressHydrationWarning: true,\n },\n children\n )}\n </ModalContext.Provider>\n );\n}\n\ntype PartProps<E extends keyof React.JSX.IntrinsicElements> = ComponentProps<E> & {\n /** Render the only child instead, with this part's props merged onto it. */\n asChild?: boolean;\n};\n\ntype CommandProps = PartProps<'button'> & {\n /** The dialog's id. Set by Root. */\n dialogId?: string;\n};\n\nfunction Command({ command, asChild, dialogId, ...props }: CommandProps & { command: string }) {\n const context = useContext(ModalContext);\n // `command` and `commandfor` aren't in React's types yet, so they go in as a spread.\n const invoker = { command, commandfor: dialogId ?? context.dialogId };\n if (asChild) return <Slot {...invoker} {...props} />;\n return <button type=\"button\" {...invoker} {...props} />;\n}\n\nexport type TriggerProps = CommandProps;\n\n/** A button that opens the dialog as a modal. */\nexport function Trigger(props: TriggerProps) {\n return <Command command=\"show-modal\" {...props} />;\n}\n\nexport type CloseProps = CommandProps;\n\n/** A button that closes the dialog. */\nexport function Close(props: CloseProps) {\n return <Command command=\"close\" {...props} />;\n}\n\nexport type ContentProps = PartProps<'dialog'>;\n\n/**\n * The dialog. It's named by Title, unless you pass `aria-labelledby` or `aria-label`. Pass\n * `closedby=\"any\"` to also close it when the user clicks outside it.\n */\nexport function Content({ asChild, id, onClose, ref, ...props }: ContentProps) {\n const context = useContext(ModalContext);\n const reported = useRef<boolean | undefined>(undefined);\n const onOpenChange = useRef(context.onOpenChange);\n useEffect(() => {\n onOpenChange.current = context.onOpenChange;\n });\n // Report each change once: `toggle` fires on opening and closing where the browser fires it on\n // dialogs, and `close` on closing everywhere.\n const report = (dialog: HTMLDialogElement) => {\n if (reported.current === dialog.open) return;\n reported.current = dialog.open;\n onOpenChange.current?.(dialog.open);\n };\n // A dialog the user opened before hydration, through its invoker command or the element, fired\n // nothing React heard, so report it once.\n const dialogRef = useRef<HTMLDialogElement | null>(null);\n useEffect(() => {\n const dialog = dialogRef.current;\n if (dialog?.open && reported.current === undefined) {\n reported.current = true;\n onOpenChange.current?.(true);\n }\n }, []);\n // React doesn't listen for `toggle` on a dialog, so listen natively.\n const listen = (dialog: HTMLDialogElement | null) => {\n dialogRef.current = dialog;\n if (typeof ref === 'function') ref(dialog);\n else if (ref) ref.current = dialog;\n if (!dialog) return undefined;\n const onToggle = () => report(dialog);\n dialog.addEventListener('toggle', onToggle);\n return () => dialog.removeEventListener('toggle', onToggle);\n };\n const shared = {\n id: id ?? context.dialogId,\n 'aria-labelledby': props['aria-label'] ? undefined : context.titleId,\n ref: listen,\n onClose: (event: SyntheticEvent<HTMLDialogElement>) => {\n onClose?.(event);\n report(event.currentTarget);\n },\n // The dialog's open state belongs to the browser.\n suppressHydrationWarning: true,\n };\n if (asChild) return <Slot {...shared} {...props} />;\n return <dialog {...shared} {...props} />;\n}\n\nexport type TitleProps = PartProps<'h2'>;\n\n/** The dialog's heading, which names it. */\nexport function Title({ asChild, ...props }: TitleProps) {\n const context = useContext(ModalContext);\n const Element = asChild ? Slot : 'h2';\n return <Element id={context.titleId} {...props} />;\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare const tagName = "govuk-react-password-input";