1/*! 2 * Postcode.eu international address autocompletion 3 * 4 * https://developer.postcode.eu/documentation/international/javascript 5 * 6 * Copyright Postcode.nl 7 * Released under the Apple MIT License (AML) 8 * https://www.tldrlegal.com/license/apple-mit-license-aml 9 * 10 * @author Postcode.nl 11 * @version 1.4.2 12 */ 13!function(e,t){"use strict";"function"==typeof define&&define.amd?define([],t):(e.PostcodeNl=e.PostcodeNl||{},e.PostcodeNl.AutocompleteAddress=t())}("undefined"!=typeof self?self:this,(function(){"use strict";const e=window.document,t=new WeakMap,n="autocomplete-",s="Address",o={PAGED:"paged",SHORT:"short"},i=Object.create(null,{context:{value:"nld",writable:!0},autocompleteUrl:{writable:!0},addressDetailsUrl:{writable:!0},tags:{value:{"unvalidated-housenumber":"(unknown house number)","unvalidated-housenumber-addition":"(unknown house number addition)"},writable:!0},cssPrefix:{value:"postcodenl-autocomplete-",writable:!0},minLength:{value:1,writable:!0},delay:{value:300,writable:!0},appendTo:{value:e.body,writable:!0},autoFocus:{value:!0,writable:!0},autoSelectSingleAddress:{value:!0,writable:!0},autoResize:{value:!0,writable:!0},showLogo:{value:!0,writable:!0},getResponseMessage:{value:function(e){let t;return t=e>1?e+" address suggestions available. ":"One address suggestion available. ",t+="Use up and down arrow keys to navigate.",t},writable:!0},language:{writable:!0},buildingListMode:{set(e){Object.values(o).includes(e)?this.mode=e:console.error("Invalid mode for option buildingListMode:",e)},get(){return this.mode||o.SHORT}}}),l=function(s){const o=this,i=e.createElement("ul"),l=e.createElement("div"),r={menuOpen:s.cssPrefix+"menu-open",itemFocus:s.cssPrefix+"item-focus",logo:s.cssPrefix+"logo"},c=function(e,s,o){const l=i.children.length;if(0===l)return;o=o||!1;let r,c=e;if((s=s||!1)&&(null===w?c=e>0?e-1:l+e:(r=a(w),c=r+e)),c%=l,c=c>=0?c:l+c,s&&null!==w&&(e>0&&c<r||e<0&&c>r))return u(null),h.value=g,void(t.get(h).context=v);u(i.children[c]);const d=t.get(w);o&&!0===h.dispatchEvent(new CustomEvent(n+"focus",{detail:d,cancelable:!0,bubbles:!0}))&&(h.value=d.value,t.get(h).context=d.context,L=c,i.scrollTop>w.offsetTop?i.scrollTop=w.offsetTop:w.offsetTop>=i.clientHeight+i.scrollTop&&(i.scrollTop=w.offsetHeight+w.offsetTop-i.clientHeight))},a=function(e){return Array.prototype.indexOf.call(i.children,e)},u=function(e){d(),w=e,w&&w.classList.add(r.itemFocus)},d=function(){null!==w&&w.classList.remove(r.itemFocus)},p=function(e){b&&e.target!==h&&!l.contains(e.target)&&o.close()},f=function(){b&&o.close()};let h,g,v,b=!1,m=!1,w=null,L=null;Object.defineProperties(this,{isOpen:{get:function(){return b}},isMousedown:{get:function(){return m}},hasFocus:{get:function(){return null!==w}},wrapper:{get:function(){return l}},ul:{get:function(){return i}},suppress:{value:!1,writable:!0}}),l.classList.add(s.cssPrefix+"menu"),l.classList.toggle(r.logo,s.showLogo),i.classList.add(s.cssPrefix+"menu-items"),l.appendChild(i),i.addEventListener("mousemove",(function(e){if(e.target===w||e.target===i)return;let t=e.target;for(;t.parentElement!==i;)t=t.parentElement;u(t),c(a(t))})),l.addEventListener("mousedown",(function(){m=!0})),l.addEventListener("click",(function(e){e.preventDefault(),null!==w&&o.select(),window.setTimeout((function(){m=!1}))})),Object.prototype.isPrototypeOf.call(HTMLElement.prototype,s.appendTo)?s.appendTo.appendChild(l):(e.querySelector(s.appendTo)||e.body).appendChild(l),this.setItems=function(e,n){i.innerHTML="";for(let s,o,l=0;o=e[l++];)s=n(i,o),t.set(s,o);u(null),L=null,i.scrollTop=0},this.open=function(e){h=e,g=h.value,v=t.get(h).context,s.autoFocus&&null===L&&(L=0),null!==L&&c(L),b||this.suppress||(!function(e){const t=e.getBoundingClientRect();l.style.top=t.bottom+(window.scrollY||window.pageYOffset)+"px",l.style.left=t.left+(window.scrollX||window.pageXOffset)+"px",s.autoResize&&(l.style.width=t.width+"px")}(h),l.classList.add(r.menuOpen),i.scrollTop=0,b=!0,h.dispatchEvent(new CustomEvent(n+"open",{bubbles:!0})))},this.close=function(e){b&&(e&&(h.value=g,t.get(h).context=v,L=null),o.blur(),l.classList.remove(r.menuOpen),b=!1,h.dispatchEvent(new CustomEvent(n+"close",{bubbles:!0})))},this.focusPrevious=c.bind(this,-1,!0),this.focusNext=c.bind(this,1,!0),this.blur=function(){u(null)},this.select=function(e){const s=t.get(w),o=a(w);!0===h.dispatchEvent(new CustomEvent(n+"select",{detail:s,cancelable:!0,bubbles:!0}))&&(h.value=s.value,L=o),(void 0===e||e)&&h.focus()},this.clear=function(){u(null),L=null,i.innerHTML=""},this.destroy=function(){return null!==l.parentNode&&(l.parentNode.removeChild(l),e.removeEventListener("click",p),window.removeEventListener("resize",f),!0)},e.addEventListener("click",p),window.addEventListener("resize",f)},r=function(){const e=new Uint8Array(32),t=[],n="0123456789abcdef";(window.crypto||window.msCrypto).getRandomValues(e);for(let s=0,o=16;s<32;s++)t.push(n[e[s]%o]);return t.join("")},c=function(e){return Object.prototype.toString.call(e).slice(8,-1)};if("function"!=typeof window.CustomEvent){const t=function(t,n){n=n||{bubbles:!1,cancelable:!1,detail:null};var s=e.createEvent("CustomEvent");
13return s.initCustomEvent(t,n.bubbles,n.cancelable,n.detail),s};window.CustomEvent=t}0===window.DOMTokenList.prototype.toggle.length&&(window.DOMTokenList.prototype.toggle=function(e){return arguments.length>1?(this[arguments[1]?"add":"remove"](e),!!arguments[1]):(this[this.contains(e)?"remove":"add"](e),this.contains(e))});const a=function(a,u){let d;if("String"===c(a))p=a,d=e.querySelectorAll(p);else if(Object.prototype.isPrototypeOf.call(HTMLElement.prototype,a))d=[a];else{if(!Object.prototype.isPrototypeOf.call(NodeList.prototype,a))throw new TypeError("Element(s) or selector has invalid type. Use HTMLElement, NodeList or valid CSS selector string.");d=a}var p;if(0===d.length)return;(u=function(e,t){for(let n in t)e[n]=t[n];return e}(Object.create(i),u)).context=u.context.toLowerCase(),Object.defineProperty(this,"options",{get:function(){return u}});let f=null,h=null,g=null,v=null,b=null,m=[];const w=this,L=new l(u),x=u.cssPrefix+"address-input-blank",E=r(),y=e.createElement("div"),O="aria-live-region";y.id=function(t){let n=2,s=t;for(;null!==e.getElementById(s);)s=t+"-"+n,n++;return s}(O),y.setAttribute("role","status"),y.setAttribute("aria-live","assertive"),y.classList.add(u.cssPrefix+O),e.body.appendChild(y),window.addEventListener("beforeunload",(function(){window.clearTimeout(f)})),Object.defineProperty(this,"elements",{get:function(){return{menu:L.wrapper,menuItems:L.ul,liveRegion:y}}}),this.announce=function(e){y.innerHTML="<div>"+e+"</div>"},this.xhrGet=function(e,s){null!==v&&v.readyState<4&&v.abort(),v=new XMLHttpRequest,v.addEventListener("load",(function(){200===this.status&&s.call(this,JSON.parse(v.response))}));let o=E;if(null!==b){const e=b,s=function(t){200!==this.status&&e.dispatchEvent(new CustomEvent(n+"error",{detail:{event:t,request:this},bubbles:!0}))};o=t.get(e).sessionId,v.addEventListener("error",s),v.addEventListener("load",s),e.classList.add(u.cssPrefix+"loading"),v.addEventListener("loadend",(function(){e.classList.remove(u.cssPrefix+"loading")}))}return v.open("GET",e),v.setRequestHeader("X-Autocomplete-Session",o),v.send(),v},this.getSuggestions=function(e,t,n){const s=[this.options.autocompleteUrl,encodeURIComponent(e),encodeURIComponent(t),u.language||""];return u.buildingListMode!==o.SHORT&&s.push(u.buildingListMode),this.xhrGet(s.join("/").replace(/\/+$/,""),n)},this.getDetails=function(e){let t=null,n=arguments[1];const s=[e];return 3===arguments.length&&(t=arguments[1],n=arguments[2],s.push(t)),this.xhrGet(this.options.addressDetailsUrl+"/"+s.join("/"),n)},this.renderItem=function(t,n){const o=e.createElement("li"),i=e.createElement("span");if(o.classList.add(this.options.cssPrefix+"item"),i.classList.add(this.options.cssPrefix+"item-label"),i.innerHTML=this.highlight(n.label,n.highlights),o.appendChild(i),n.precision!==s&&o.classList.add(this.options.cssPrefix+"item-more"),n.description){const t=e.createElement("span");t.textContent=n.description,t.classList.add(this.options.cssPrefix+"item-description"),o.appendChild(t)}if(n.tags)for(let t,s=0;t=n.tags[s++];){const n=e.createElement("em");n.textContent=this.options.tags[t],n.classList.add(this.options.cssPrefix+"item-tag"),o.appendChild(n)}return t.appendChild(o),o},this.highlight=function(e,t){if(0===t.length)return e;let n,s=0,o=0,i=0,l=[];for(;n=t[s++];)l.push(e.slice(i,n[0])),o=n[0],i=n[1],l.push("<mark>"+e.slice(o,i)+"</mark>");return l.push(e.slice(i)),l.join("")},this.setCountry=function(e){u.context=e.toLowerCase();for(let e,n=0;e=d[n++];)t.get(e).context=u.context},this.setLanguage=function(e){u.language=e},this.search=function(e){let n;if(n="Object"===c(arguments[1])?arguments[1]:{term:arguments[1],context:arguments[2]},void 0!==n.term&&(e.value=n.term),void 0!==n.context){const s=t.get(e);s.context=n.context,t.set(e,s)}const s=L.suppress;L.suppress=!(void 0===n.showMenu||n.showMenu),b=e,e.classList.toggle(x,""===e.value),P(e),L.suppress=s},this.reset=function(){h=null,g=null,m=[],L.clear();for(let e,n=0;e=d[n++];){const n=t.get(e);n.context=u.context,n.match={},e.value="",e.classList.add(x)}},this.destroy=function(){if(L.destroy()){e.body.removeChild(y);for(let e,o=0;e=d[o++];){const o=t.get(e);for(var n in o.eventHandlers)e.removeEventListener(n,o.eventHandlers[n]);for(var s in o.initialAttributeValues){const t=o.initialAttributeValues[s];null===t?e.removeAttribute(s):e.setAttribute(s,t)}t.delete(e),e.classList.remove(u.cssPrefix+"address-input",u.cssPrefix+"loading",x,u.cssPrefix+"logo")}}},Array.prototype.forEach.call(d,(function(e){const o=Object.create(null);let i=!1;t.set(e,{match:{},context:u.context,eventHandlers:o,initialAttributeValues:{spellcheck:e.hasAttribute("spellcheck")?e.getAttribute("spellcheck"):null,autocomplete:e.hasAttribute("autocomplete")?e.getAttribute("autocomplete"):null,"aria-controls":e.hasAttribute("aria-controls")?e.getAttribute("aria-controls"):null},sessionId:r()}),!1===e.hasAttribute("autocomplete")&&(e.autocomplete="off"),e.spellcheck=!1,e.setAttribute("aria-controls",y.id),e.classList.add(u.cssPrefix+"address-input"),e.classList.toggle(x,""===e.value),e.classList.toggle(u.cssPrefix+"logo",u.showLogo),e.addEventListener("keydown",o.keydown=function(t){switch(i=!0,t.key){case"ArrowUp":case"Up":L.isOpen?L.focusPrevious(!0):P(e),t.preventDefault();break;case"ArrowDown":case"Down":L.isOpen?L.focusNext(!0):P(e),t.preventDefault();break;case"Escape":case"Esc":L.close(!0);break;case"Tab":L.hasFocus&&(L.select(),t.preventDefault());break;case"Enter":L.hasFocus?(L.select(),t.preventDefault()):L.close();break;default:C(e)}}),e.addEventListener("input",o.input=function(){e.classList.remove(x),L.blur(),m=[],i?i=!1:C(e)}),e.addEventListener("focus",o.focus=function(){if(L.isMousedown)return;L.open(e);const n=t.get(e);void 0!==n.match.precision&&n.match.precision===s||P(e)}),e.addEventListener("click",o.click=L.open.bind(L,e)),e.addEventListener(n+"select",o[n+"select"]=function(n){const o=t.get(e);o.match=n.detail,n.detail.precision===s?L.close():(L.open(e),o.context=n.detail.context,window.setTimeout(P,0,e))}),e.addEventListener("blur",o.blur=function(){L.isMousedown||(window.clearTimeout(f),T(),L.close(),e.classList.toggle(x,""===e.value))}),e.dispatchEvent(new CustomEvent(n+"create",{detail:w,bubbles:!0}))}
13));const T=function(){u.autoFocus&&u.autoSelectSingleAddress&&L.hasFocus&&1===m.length&&m[0].precision===s&&L.select(!1)},C=function(e){window.clearTimeout(f);let t=10;e.value.length>3&&(t=u.delay),f=window.setTimeout(P,t,e)},P=function(e){L.open(e);const s=t.get(e);if(b=e,e.value===h&&s.context===g)return;const o=s.context===g&&null!==h&&(0===e.value.indexOf(h)||0===h.indexOf(e.value));if(h=e.value,g=s.context,s.match={},e.value.length<u.minLength)return s.context=u.context,void L.clear();if(!1===e.dispatchEvent(new CustomEvent(n+"search",{cancelable:!0,bubbles:!0})))return;const i=L.suppress;w.getSuggestions.call(w,s.context,e.value,(function(t){if("String"===c(t.newContext)&&(s.context=t.newContext),!0===e.dispatchEvent(new CustomEvent(n+"response",{detail:t,cancelable:!0,bubbles:!0}))){if(m=t.matches||[],o&&0===m.length)return;L.setItems(m,w.renderItem.bind(w)),w.announce(u.getResponseMessage(m.length,u.language)),!1===i&&L.open(e)}}))}};return Object.defineProperty(a,"defaults",{get:function(){return i}}),Object.defineProperty(a,"version",{value:"1.4.2"}),a}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.