PageSourceSearch

https://maptools.com/assets/vendor/@mapbox/search-js-core/search-js-core.index-R7qPF0Y.js

js maptools.com collected 2026-10-02 06:14:56 UTC 15,576 bytes, 7 lines download raw bytes

1/**
2 * Bundled by jsDelivr using Rollup v2.79.2 and Terser v5.39.0.
3 * Original file: /npm/@mapbox/[email protected]/dist/index-esm.js
4 *
5 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
6 */
7var t=Object.defineProperty,e=Object.defineProperties,r=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,s=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,o=(e,r,n)=>r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,a=(t,e)=>{for(var r in e||(e={}))s.call(e,r)&&o(t,r,e[r]);if(n)for(var r of n(e))i.call(e,r)&&o(t,r,e[r]);return t},c=(t,n)=>e(t,r(n)),l=(t,e)=>{var r={};for(var o in t)s.call(t,o)&&e.indexOf(o)<0&&(r[o]=t[o]);if(null!=t&&n)for(var o of n(t))e.indexOf(o)<0&&i.call(t,o)&&(r[o]=t[o]);return r},u=(t,e,r)=>{if(!e.has(t))throw TypeError("Cannot "+r)},h=(t,e,r)=>(u(t,e,"read from private field"),r?r.call(t):e.get(t)),g=(t,e,r)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,r)},d=(t,e,r,n)=>(u(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),f=(t,e,r)=>(u(t,e,"access private method"),r),p=(t,e,r)=>new Promise(((n,s)=>{var i=t=>{try{a(r.next(t))}catch(t){s(t)}},o=t=>{try{a(r.throw(t))}catch(t){s(t)}},a=t=>t.done?n(t.value):Promise.resolve(t.value).then(i,o);a((r=r.apply(t,e)).next())})),y="https://api.mapbox.com/autofill/v1",m=`${y}/suggest`,v=`${y}/retrieve`,w=class{constructor(t,e){if(isNaN(t)||isNaN(e))throw new Error(`Invalid LngLat object: (${t}, ${e})`);if(this.lng=+t,this.lat=+e,this.lat>90||this.lat<-90)throw new Error("Invalid LngLat latitude value: must be between -90 and 90");if(this.lng>180||this.lng<-180)throw new Error("Invalid LngLat longitude value: must be between -180 and 180")}toArray(){return[this.lng,this.lat]}toString(){return`LngLat(${this.lng}, ${this.lat})`}static convert(t){if(t instanceof w)return new w(t.lng,t.lat);if(Array.isArray(t)&&2===t.length)return new w(Number(t[0]),Number(t[1]));if(!Array.isArray(t)&&"object"==typeof t&&null!==t&&("lng"in t||"lon"in t)&&"lat"in t)return new w(Number("lng"in t?t.lng:t.lon),Number(t.lat));throw new Error("`LngLatLike` argument must be specified as an object {lng: <lng>, lat: <lat>}, an object {lon: <lng>, lat: <lat>}, or an array of [<lng>, <lat>]")}},b=class{constructor(t,e){this._sw=w.convert(t),this._ne=w.convert(e)}getSouthWest(){return this._sw}getNorthEast(){return this._ne}getNorthWest(){return new w(this.getWest(),this.getNorth())}getSouthEast(){return new w(this.getEast(),this.getSouth())}getWest(){return this._sw.lng}getSouth(){return this._sw.lat}getEast(){return this._ne.lng}getNorth(){return this._ne.lat}toArray(){return[this._sw.toArray(),this._ne.toArray()]}toFlatArray(){return[this._sw.lng,this._sw.lat,this._ne.lng,this._ne.lat]}toString(){return`LngLatBounds(${this._sw.toString()}, ${this._ne.toString()})`}static convert(t){if(!t)throw new Error("Invalid LngLatBounds convert value: falsy");
7if(t instanceof b)return new b(t.getSouthWest(),t.getNorthEast());if(Array.isArray(t)&&2===t.length)return new b(w.convert(t[0]),w.convert(t[1]));if(Array.isArray(t)&&4===t.length)return new b(w.convert([t[0],t[1]]),w.convert([t[2],t[3]]));throw new Error("`LngLatBoundsLike` argument must be specified as an array [<LngLatLike>, <LngLatLike>] or an array [<west>, <south>, <east>, <north>]")}};var k=class{constructor(t){this.id=null!=t?t:function(){const t=(Math.random().toString(16)+Date.now().toString(16)+Math.random().toString(16)).replace(/\./g,"");return[t.slice(0,8),t.slice(8,12),"4"+t.slice(12,15)+"-8"+t.slice(15,18),t.slice(18,30)].join("-")}()}toString(){return this.id}static convert(t){return new k(t instanceof k?t.id:t.toString())}},x=class extends Error{constructor(t,e){super(String(t.message||t.error||"Unknown error")),this.name="MapboxError",this.statusCode=e}toString(){return`${this.name} (${this.statusCode}): ${this.message}`}};function _(t){return p(this,null,(function*(){if(!t.ok){const e=yield t.json();throw new x(e,t.status)}}))}var T,S,L,E=globalThis.fetch,j=globalThis.AbortController;function $({fetch:t,AbortController:e},r=!1){if(!t)throw new Error("Fetch implementation must include implementations of `fetch`.");E&&!r||(E=t,j=e)}function A(){if(!E)throw new Error("Fetch implementation not found. Please include a fetch polyfill in your application or use `polyfillFetch` from `@mapbox/search-js-core` to fix this issue.");return{fetch:E,AbortController:j}}function N(...t){const e=[];for(const r of t){if(!r)continue;const t=Object.entries(r);for(const[r,n]of t)null!=n&&e.push(`${r}=${encodeURIComponent(String(n))}`)}return e.join("&")}var R=class{constructor(t={}){g(this,S),g(this,T,void 0);const e=t,{accessToken:r}=e,n=l(e,["accessToken"]);this.accessToken=r,this.defaults=a(a({},R.defaults),n)}get responseHeaders(){return h(this,T)}suggest(t,e){return p(this,null,(function*(){if(!t)throw new Error("searchText is required");const{sessionToken:r,signal:n}=e,s=c(a(a({},this.defaults),e),{sessionToken:r}),i=new URL(`${m}/${encodeURIComponent(t)}`);i.search=f(this,S,L).call(this,s);const{fetch:o}=A(),l=yield o(i.toString(),{signal:n});d(this,T,l.headers),yield _(l);const u=yield l.json();return c(a({},u),{suggestions:u.suggestions.map((e=>c(a({},e),{original_search_text:t}))),url:i.toString()})}))}retrieve(t,e){return p(this,null,(function*(){if(!t)throw new Error("suggestion is required");if(!this.canRetrieve(t))throw new Error("suggestion cannot be retrieved");const{sessionToken:r,signal:n}=e,s=k.convert(r),i=new URL(`${v}/${t.action.id}`);i.search=N({access_token:this.accessToken,session_token:s.id});const{fetch:o}=A(),a=yield o(i.toString(),{signal:n});yield _(a);const c=yield a.json();return c.url=i.toString(),c}))}canRetrieve(t){const e=t.action;return"string"==typeof(null==e?void 0:e.id)}},W=R;T=new WeakMap,S=new WeakSet,L=function(t){return N({types:"address",access_token:this.accessToken,streets:t.streets,language:t.language,country:t.country,limit:t.limit},t.sessionToken&&{session_token:k.convert(t.sessionToken).id},t.proximity&&{proximity:"string"==typeof t.proximity?t.proximity:w.convert(t.proximity).toArray().join(",")},t.bbox&&{bbox:"string"==typeof t.bbox?t.bbox:b.convert(t.bbox).toFlatArray().join(",")})},W.defaults={language:"en",proximity:"ip",streets:!0};var q,M,U="https://api.mapbox.com/search/searchbox/v1",O=`${U}/suggest`,C=`${U}/retrieve`,I=`${U}/category`,P=`${U}/reverse`,F=class{constructor(t={}){g(this,q);const e=t,{accessToken:r}=e,n=l(e,["accessToken"]);this.accessToken=r,this.defaults=a(a({},F.defaults),n)}suggest(t,e){return p(this,null,(function*(){if(!t)throw new Error("searchText is required");const{sessionToken:r,signal:n}=e,s=c(a(a({},this.defaults),e),{q:t,sessionToken:r});if(s.eta_type&&(!s.origin||!s.navigation_profile))throw new Error("to provide eta estimate: eta, navigation_profile, and origin are required");if(s.origin&&!s.navigation_profile)throw new Error("to provide distance estimate: both navigation_profile and origin are required");const i=new URL(O);i.search=f(this,q,M).call(this,s);const{fetch:o}=A(),l=yield o(i.toString(),{signal:n});yield _(l);const u=yield l.json();return u.url=i.toString(),u}))}retrieve(t,e){return p(this,null,(function*(){if(!t)throw new Error("suggestion is required");const{sessionToken:r,signal:n,language:s}=e,i=k.convert(r),o=a(a({},this.defaults),s&&{language:s}),c=new URL(`${C}/${encodeURIComponent(t.mapbox_id)}`);c.search=N({access_token:this.accessToken,session_token:i.id},{language:o.language});const{fetch:l}=A(),u=yield l(c.toString(),{signal:n});yield _(u);const h=yield u.json();return h.url=c.toString(),h}))}category(t){return p(this,arguments,(function*(t,e={}){if(!t)throw new Error("category is required");const r=a(a({},this.defaults),e),n=new URL(`${I}/${encodeURIComponent(t)}`);n.search=f(this,q,M).call(this,r);const{fetch:s}=A(),i=yield s(n.toString(),{signal:r.signal});yield _(i);const o=yield i.json();return o.url=n.toString(),o}))}reverse(t){return p(this,arguments,(function*(t,e={}){if(!t)throw new Error("lngLat is required");const[r,n]="string"==typeof t?t.split(",").map((t=>parseFloat(t))):w.convert(t).toArray();if(isNaN(r)||isNaN(n))throw new Error("lngLat is required");const s=a(a({},this.defaults),e),i=new URL(P);i.search=N({access_token:this.accessToken,language:s.language,limit:s.limit,longitude:r,latitude:n},s.types&&{types:"string"==typeof s.types?s.types:[...s.types].join(",")});const{fetch:o}=A(),c=yield o(i.toString(),{signal:s.signal});yield _(c);const l=yield c.json();return l.url=i.toString(),l}))}},B=F;q=new WeakSet,M=function(t){return N({q:t.q,access_token:this.accessToken,language:t.language,limit:t.limit,navigation_profile:t.navigation_profile,route:t.route,route_geometry:t.route_geometry,sar_type:t.sar_type,time_deviation:t.time_deviation,eta_type:t.eta_type,country:t.country,poi_category:t.poi_category,rich_metadata_provider:t.rich_metadata_provider,poi_category_exclusions:t.poi_category_exclusions},t.sessionToken&&{session_token:k.convert(t.sessionToken).id},t.proximity&&{proximity:"string"==typeof t.proximity?t.proximity:w.convert(t.proximity).toArray().join(",")},t.origin&&{origin:"string"==typeof t.origin?t.origin:w.convert(t.origin).toArray().join(",")},t.bbox&&{bbox:"string"==typeof t.bbox?t.bbox:b.convert(t.bbox).toFlatArray().join(",")},t.types&&{types:"string"==typeof t.types?t.types:[...t.types].join(",")})},B.defaults={language:"en"};var D,H,G=class{constructor(t={}){g(this,D);const e=t,{accessToken:r}=e,n=l(e,["accessToken"]);this.accessToken=r,this.defaults=a(a({},G.defaults),n)}validate(t,e){return p(this,null,(function*(){if(!t)throw new Error("searchText is required");const{sessionToken:r,signal:n}=e,s=c(a(a({},this.defaults),e),{sessionToken:r}),i=new URL(`https://api.mapbox.com/autofill/v1/retrieve/${encodeURIComponent(t)}`);i.search=f(this,D,H).call(this,s);const{fetch:o}=A(),l=yield o(i.toString(),{signal:n});yield _(l);const u=yield l.json();return u.url=i.toString(),u.features.length>0&&(u.features=[u.features[0]]),u}))}},V=G;D=new WeakSet,H=function(t){return N({access_token:this.accessToken,language:t.language,country:t.country},t.sessionToken&&{session_token:k.convert(t.sessionToken).id},t.proximity&&{proximity:"string"==typeof t.proximity?t.proximity:w.convert(t.proximity).toArray().join(",")},t.bbox&&{bbox:"string"==typeof t.bbox?t.bbox:b.convert(t.bbox).toFlatArray().join(",")})},V.defaults={language:"en",proximity:"ip"};var z,J,K,Q="https://api.mapbox.com/search/geocode/v6",X=`${Q}/forward`,Y=`${Q}/reverse`,Z=/^[ ]*(-?\d{1,3}(\.\d{0,256})?)[, ]+(-?\d{1,3}(\.\d{0,256}
7)?)[ ]*$/,tt=/[\s,]+/,et=class{constructor(t={}){g(this,J),g(this,z,void 0);const e=t,{accessToken:r}=e,n=l(e,["accessToken"]);this.accessToken=r,this.defaults=a({},n)}get responseHeaders(){return h(this,z)}forward(t,e){return p(this,null,(function*(){if(!t)throw new Error("searchText is required");let r;e&&({signal:r}=e);const n=c(a(a({},this.defaults),e),{q:t}),s=new URL(`${X}`);s.search=f(this,J,K).call(this,n);const{fetch:i}=A(),o=r?{signal:r}:{},l=yield i(s.toString(),o);d(this,z,l.headers),yield _(l);const u=yield l.json();return u.url=s.toString(),u}))}reverse(t,e){return p(this,null,(function*(){if(!t)throw new Error("lngLat is required");let r,n;if(e&&({signal:r}=e),"string"==typeof t){const[e,r]=t.split(",");n=new w(Number(e),Number(r))}else n=w.convert(t);const s=c(a(a({},this.defaults),e),{longitude:n.lng,latitude:n.lat}),i=new URL(`${Y}`);i.search=f(this,J,K).call(this,s,!0);const{fetch:o}=A(),l=r?{signal:r}:{},u=yield o(i.toString(),l);d(this,z,u.headers),yield _(u);const h=yield u.json();return h.url=i.toString(),h}))}suggest(t,e){return p(this,null,(function*(){if(Z.test(t)){const r=t.trim().split(tt).map((t=>t.trim())).join(",");return this.reverse(r,e)}return this.forward(t,e)}))}retrieve(t){return p(this,null,(function*(){return t}))}};z=new WeakMap,J=new WeakSet,K=function(t,e=!1){return e&&["proximity","autocomplete","bbox"].forEach((e=>{e in t&&delete t[e]})),N({q:t.q,longitude:t.longitude,latitude:t.latitude,access_token:this.accessToken,permanent:t.permanent,language:t.language,country:t.country,limit:t.limit,autocomplete:t.autocomplete,worldview:t.worldview},t.sessionToken&&{session_token:k.convert(t.sessionToken).id},t.proximity&&{proximity:"string"==typeof t.proximity?t.proximity:w.convert(t.proximity).toArray().join(",")},t.bbox&&{bbox:"string"==typeof t.bbox?t.bbox:b.convert(t.bbox).toFlatArray().join(",")},t.types&&{types:"string"==typeof t.types?t.types:[...t.types].join(",")})};var rt,nt,st,it,ot,at,ct,lt=(t=>(t.matched="matched",t.unmatched="unmatched",t.plausible="plausible",t.not_applicable="not_applicable",t.inferred="inferred",t))(lt||{}),ut=(t=>(t.exact="exact",t.high="high",t.medium="medium",t.low="low",t))(ut||{}),ht=class{constructor(){g(this,rt,{})}addEventListener(t,e){const r=h(this,rt);r[t]||(r[t]=[]),r[t].push(e)}removeEventListener(t,e){const r=h(this,rt);if(!r[t])return;const n=r[t],s=n.indexOf(e);-1!==s&&n.splice(s,1)}fire(t,e){const r=h(this,rt);if(!r[t])return;const n=r[t];for(const t of n)t(e)}};function gt(t,e,r){let n=null;return(...s)=>{null!==n&&clearTimeout(n);const i=r&&r();n=setTimeout((()=>{n=null,(null==i?void 0:i.aborted)||t(...s)}),e)}}function dt(){const{AbortController:t}=A();return new t}rt=new WeakMap;var ft=class extends ht{constructor(t,e=0){super(),g(this,nt,new k),g(this,st,0),g(this,it,!1),g(this,ot,void 0),g(this,at,dt()),g(this,ct,void 0),d(this,ct,gt(((t,...e)=>p(this,[t,...e],(function*(t,e={}){if(h(this,at).abort(),d(this,at,dt()),!t)return d(this,ot,null),void this.fire("suggest",h(this,ot));try{const r=yield this.search.suggest(t,c(a({sessionToken:this.sessionToken},e),{signal:h(this,at).signal}));d(this,ot,r),this.fire("suggest",r)}catch(t){if("AbortError"===t.name)return;this.fire("suggesterror",t)}}))),e,(()=>h(this,at).signal))),Object.defineProperties(this,{search:{value:t,writable:!1},debounce:{value:e,writable:!1}})}get sessionToken(){return h(this,it)?h(this,nt).id:`${h(this,nt).id}.${h(this,st)}`}set sessionToken(t){d(this,it,!0),d(this,nt,new k(t))}get suggestions(){return h(this,ot)}suggest(t,e){return h(this,ct).call(this,t,e),new Promise(((t,e)=>{let r,n;r=e=>{this.removeEventListener("suggest",r),this.removeEventListener("suggesterror",n),t(e)},n=t=>{this.removeEventListener("suggest",r),this.removeEventListener("suggesterror",n),e(t)},this.addEventListener("suggest",r),this.addEventListener("suggesterror",n)}))}clear(){this.suggest("")}retrieve(t,e){return p(this,null,(function*(){const r=yield this.search.retrieve(t,a({sessionToken:this.sessionToken},e));return this.fire("retrieve",r),r}))}canRetrieve(t){return!this.search.canRetrieve||this.search.canRetrieve(t)}canSuggest(t){return!this.search.canSuggest||this.search.canSuggest(t)}abort(){h(this,at).abort(),d(this,at,dt())}incrementSession(){var t,e,r,n;(t=this,e=st,{set _(n){d(t,e,n,r)},get _(){return h(t,e,n)}})._++}};function pt(t){const{properties:e}=t;return a({},e)}nt=new WeakMap,st=new WeakMap,it=new WeakMap,ot=new WeakMap,at=new WeakMap,ct=new WeakMap;export{W as AddressAutofillCore,ht as Evented,et as GeocodingCore,w as LngLat,b as LngLatBounds,W as MapboxAutofill,x as MapboxError,et as MapboxGeocode,V as MapboxValidate,ut as MatchCodeConfidence,lt as MatchCodeType,B as SearchBoxCore,ft as SearchSession,k as SessionToken,V as ValidationCore,gt as debounce,pt as featureToSuggestion,$ as polyfillFetch};export default null;

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.