Socket
Socket
Sign inDemoInstall

@mapbox/search-js-core

Package Overview
Dependencies
Maintainers
14
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mapbox/search-js-core - npm Package Compare versions

Comparing version 1.0.0-beta.5 to 1.0.0-beta.6

dist/autofill/constants.d.ts

25

dist/index-development.js

@@ -113,2 +113,3 @@ var __create = Object.create;

__export(src_exports, {
Evented: () => Evented,
LngLat: () => LngLat,

@@ -352,12 +353,9 @@ LngLatBounds: () => LngLatBounds,

var _getQueryParams, getQueryParams_fn, _getFetchInfo, getFetchInfo_fn;
var MapboxSearch = class {
var _MapboxSearch = class {
constructor(options = {}) {
__privateAdd(this, _getQueryParams);
__privateAdd(this, _getFetchInfo);
this.defaults = {
language: "en"
};
const _a = options, { accessToken } = _a, defaults = __objRest(_a, ["accessToken"]);
this.accessToken = accessToken;
Object.assign(this.defaults, defaults);
this.defaults = __spreadValues(__spreadValues({}, _MapboxSearch.defaults), defaults);
}

@@ -490,2 +488,3 @@ suggest(searchText, optionsArg) {

};
var MapboxSearch = _MapboxSearch;
_getQueryParams = new WeakSet();

@@ -528,2 +527,5 @@ getQueryParams_fn = function(options) {

};
MapboxSearch.defaults = {
language: "en"
};

@@ -539,12 +541,8 @@ // src/autofill/constants.ts

var _getQueryParams2, getQueryParams_fn2;
var MapboxAutofill = class {
var _MapboxAutofill = class {
constructor(options = {}) {
__privateAdd(this, _getQueryParams2);
this.defaults = {
language: "en",
proximity: "ip"
};
const _a = options, { accessToken } = _a, defaults = __objRest(_a, ["accessToken"]);
this.accessToken = accessToken;
Object.assign(this.defaults, defaults);
this.defaults = __spreadValues(__spreadValues({}, _MapboxAutofill.defaults), defaults);
}

@@ -619,2 +617,3 @@ suggest(searchText, optionsArg) {

};
var MapboxAutofill = _MapboxAutofill;
_getQueryParams2 = new WeakSet();

@@ -635,2 +634,6 @@ getQueryParams_fn2 = function(options) {

};
MapboxAutofill.defaults = {
language: "en",
proximity: "ip"
};

@@ -637,0 +640,0 @@ // src/utils/Evented.ts

@@ -319,12 +319,9 @@ var __defProp = Object.defineProperty;

var _getQueryParams, getQueryParams_fn, _getFetchInfo, getFetchInfo_fn;
var MapboxSearch = class {
var _MapboxSearch = class {
constructor(options = {}) {
__privateAdd(this, _getQueryParams);
__privateAdd(this, _getFetchInfo);
this.defaults = {
language: "en"
};
const _a = options, { accessToken } = _a, defaults = __objRest(_a, ["accessToken"]);
this.accessToken = accessToken;
Object.assign(this.defaults, defaults);
this.defaults = __spreadValues(__spreadValues({}, _MapboxSearch.defaults), defaults);
}

@@ -457,2 +454,3 @@ suggest(searchText, optionsArg) {

};
var MapboxSearch = _MapboxSearch;
_getQueryParams = new WeakSet();

@@ -495,2 +493,5 @@ getQueryParams_fn = function(options) {

};
MapboxSearch.defaults = {
language: "en"
};

@@ -506,12 +507,8 @@ // src/autofill/constants.ts

var _getQueryParams2, getQueryParams_fn2;
var MapboxAutofill = class {
var _MapboxAutofill = class {
constructor(options = {}) {
__privateAdd(this, _getQueryParams2);
this.defaults = {
language: "en",
proximity: "ip"
};
const _a = options, { accessToken } = _a, defaults = __objRest(_a, ["accessToken"]);
this.accessToken = accessToken;
Object.assign(this.defaults, defaults);
this.defaults = __spreadValues(__spreadValues({}, _MapboxAutofill.defaults), defaults);
}

@@ -586,2 +583,3 @@ suggest(searchText, optionsArg) {

};
var MapboxAutofill = _MapboxAutofill;
_getQueryParams2 = new WeakSet();

@@ -602,2 +600,6 @@ getQueryParams_fn2 = function(options) {

};
MapboxAutofill.defaults = {
language: "en",
proximity: "ip"
};

@@ -784,2 +786,3 @@ // src/utils/Evented.ts

export {
Evented,
LngLat,

@@ -786,0 +789,0 @@ LngLatBounds,

@@ -1,1464 +0,13 @@

// Generated by dts-bundle-generator v5.9.0
/// <reference types="geojson" />
/// <reference types="node" />
/**
* A `LngLat` object represents a given longitude and latitude coordinate, measured in degrees.
* These coordinates use longitude, latitude coordinate order (as opposed to latitude, longitude)
* to match the [GeoJSON specification](https://datatracker.ietf.org/doc/html/rfc7946#section-4),
* which is equivalent to the OGC:CRS84 coordinate reference system.
*
* Note that any method that accepts a `LngLat` object as an argument or option
* can also accept an `Array` of two numbers and will perform an implicit conversion.
* This flexible type is documented as {@link LngLatLike}.
*
* @class LngLat
* @param lng - Longitude, measured in degrees.
* @param lat - Latitude, measured in degrees.
* @example
* ```typescript
* const ll = new LngLat(-123.9749, 40.7736);
* console.log(ll.lng); // = -123.9749
* ```
*/
export declare class LngLat {
/**
* @name lng
* @instance
* @memberof LngLat
*/
readonly lng: number;
/**
* @name lat
* @instance
* @memberof LngLat
*/
readonly lat: number;
constructor(lng: number, lat: number);
/**
* Returns the coordinates represented as an array of two numbers.
*
* @returns The coordinates represeted as an array of longitude and latitude.
* @example
* ```typescript
* const ll = new LngLat(-73.9749, 40.7736);
* ll.toArray(); // = [-73.9749, 40.7736]
* ```
*/
toArray(): [
number,
number
];
/**
* Returns the coordinates represent as a string.
*
* @returns The coordinates represented as a string of the format `'LngLat(lng, lat)'`.
* @example
* ```typescript
* const ll = new LngLat(-73.9749, 40.7736);
* ll.toString(); // = "LngLat(-73.9749, 40.7736)"
* ```
*/
toString(): string;
/**
* Converts an array of two numbers or an object with `lng` and `lat` or `lon` and `lat` properties
* to a `LngLat` object.
*
* If a `LngLat` object is passed in, the function returns a copy.
*
* @param input - An array of two numbers or object to convert, or a `LngLat` object to return.
* @returns A new `LngLat` object, if a conversion occurred, or the original `LngLat` object.
* @example
* ```typescript
* const arr = [-73.9749, 40.7736];
* const ll = LngLat.convert(arr);
* console.log(ll); // = LngLat {lng: -73.9749, lat: 40.7736}
* ```
*/
static convert(input: LngLat | {
lng: number;
lat: number;
} | {
lon: number;
lat: number;
} | [
number,
number
]): LngLat;
}
/**
* A {@link LngLat} object, an array of two numbers representing longitude and latitude,
* or an object with `lng` and `lat` or `lon` and `lat` properties.
*
* @typedef LngLatLike
* @type {LngLat | [number, number] | { lng: number, lat: number } | { lon: number, lat: number }}
* @example
* ```typescript
* const v1 = new LngLat(-122.420679, 37.772537);
* const v2 = [-122.420679, 37.772537];
* const v3 = {lon: -122.420679, lat: 37.772537};
* ```
*/
export declare type LngLatLike = LngLat | {
lng: number;
lat: number;
} | {
lon: number;
lat: number;
} | [
number,
number
];
/**
* A `LngLatBounds` object represents a geographical bounding box,
* defined by its southwest and northeast points in longitude and latitude.
*
* Note that any method that accepts a `LngLatBounds` object as an argument or option
* can also accept an `Array` of two {@link LngLatLike} constructs and will perform an implicit conversion.
* This flexible type is documented as {@link LngLatBoundsLike}.
*
* @class LngLatBounds
*/
export declare class LngLatBounds {
private _ne;
private _sw;
/**
* @param sw - The southwest corner of the bounding box.
* @param ne - The northeast corner of the bounding box.
* @example
* ```typescript
* const sw = new LngLat(-73.9876, 40.7661);
* const ne = new LngLat(-73.9397, 40.8002);
* const llb = new LngLatBounds(sw, ne);
* ```
*/
constructor(sw: LngLatLike, ne: LngLatLike);
/**
* Returns the southwest corner of the bounding box.
*
* @returns The southwest corner of the bounding box.
* @example
* ```typescript
* const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
* llb.getSouthWest(); // LngLat {lng: -73.9876, lat: 40.7661}
* ```
*/
getSouthWest(): LngLat;
/**
* Returns the northeast corner of the bounding box.
*
* @returns The northeast corner of the bounding box.
* @example
* ```typescript
* const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
* llb.getNorthEast(); // LngLat {lng: -73.9397, lat: 40.8002}
* ```
*/
getNorthEast(): LngLat;
/**
* Returns the northwest corner of the bounding box. This is commonly used
* as the 'min' point in the bounding box.
*
* @returns The northwest corner of the bounding box.
* @example
* ```typescript
* const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
* llb.getNorthWest(); // LngLat {lng: -73.9876, lat: 40.8002}
* ```
*/
getNorthWest(): LngLat;
/**
* Returns the southeast corner of the bounding box. This is commonly used
* as the 'max' point in the bounding box.
*
* @returns The southeast corner of the bounding box.
* @example
* ```typescript
* const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
* llb.getSouthEast(); // LngLat {lng: -73.9397, lat: 40.7661}
* ```
*/
getSouthEast(): LngLat;
/**
* Returns the west edge of the bounding box.
*
* @returns The west edge of the bounding box.
* @example
* ```typescript
* const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
* llb.getWest(); // -73.9876
* ```
*/
getWest(): number;
/**
* Returns the south edge of the bounding box.
*
* @returns The south edge of the bounding box.
* @example
* ```typescript
* const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
* llb.getSouth(); // 40.7661
* ```
*/
getSouth(): number;
/**
* Returns the east edge of the bounding box.
*
* @returns The east edge of the bounding box.
* @example
* ```typescript
* const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
* llb.getEast(); // -73.9397
* ```
*/
getEast(): number;
/**
* Returns the north edge of the bounding box.
*
* @returns The north edge of the bounding box.
* @example
* ```typescript
* const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
* llb.getNorth(); // 40.8002
* ```
*/
getNorth(): number;
/**
* Returns the bounding box represented as an array.
*
* @returns The bounding box represented as an array, consisting of the
* southwest and northeast coordinates of the bounding represented as arrays of numbers.
* @example
* ```typescript
* const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
* llb.toArray(); // = [[-73.9876, 40.7661], [-73.9397, 40.8002]]
* ```
*/
toArray(): [
[
number,
number
],
[
number,
number
]
];
/**
* Returns the bounding box represented as a flattened array.
*
* @returns The bounding box represented as an array of numbers in [west, south, east, north] order.
* @example
* ```typescript
* const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
* llb.toFlatArray(); // = [-73.9876, 40.7661, -73.9397, 40.8002]
* ```
*/
toFlatArray(): [
number,
number,
number,
number
];
/**
* Return the bounding box represented as a string.
*
* @returns The bounding box represents as a string of the format
* `'LngLatBounds(LngLat(lng, lat), LngLat(lng, lat))'`.
* @example
* ```typescript
* const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
* llb.toString(); // = "LngLatBounds(LngLat(-73.9876, 40.7661), LngLat(-73.9397, 40.8002))"
* ```
*/
toString(): string;
/**
* Converts an array to a `LngLatBounds` object.
*
* If a `LngLatBounds` object is passed in, the function returns a copy.
*
* Internally, the function calls `LngLat#convert` to convert arrays to `LngLat` values.
*
* @param input - An array of two coordinates to convert, or a `LngLatBounds` object to return.
* @returns A new `LngLatBounds` object, if a conversion occurred, or the original `LngLatBounds` object.
* @example
* ```typescript
* const arr = [[-73.9876, 40.7661], [-73.9397, 40.8002]];
* const llb = LngLatBounds.convert(arr);
* console.log(llb); // = LngLatBounds {_sw: LngLat {lng: -73.9876, lat: 40.7661}, _ne: LngLat {lng: -73.9397, lat: 40.8002}}
* ```
*/
static convert(input: LngLatBounds | [
LngLatLike,
LngLatLike
] | [
number,
number,
number,
number
]): LngLatBounds;
}
/**
* A {@link LngLatBounds} object, an array of {@link LngLatLike} objects in [sw, ne] order,
* or an array of numbers in [west, south, east, north] order.
*
* @typedef LngLatBoundsLike
* @type {LngLatBounds | [LngLatLike, LngLatLike] | [number, number, number, number]}
* @example
* ```typescript
* const v1 = new LngLatBounds(
* new LngLat(-73.9876, 40.7661),
* new LngLat(-73.9397, 40.8002)
* );
* const v2 = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
* const v3 = [[-73.9876, 40.7661], [-73.9397, 40.8002]];
* ```
*/
export declare type LngLatBoundsLike = LngLatBounds | [
LngLatLike,
LngLatLike
] | [
number,
number,
number,
number
];
/**
* Administrative unit types for the [Mapbox Search API](https://docs.mapbox.com/api/search/search/).
*
* @typedef AdministrativeUnitTypes
* @see https://docs.mapbox.com/api/search/search/#administrative-unit-types
*/
export declare type AdministrativeUnitTypes = "country" | "region" | "prefecture" | "postcode" | "district" | "place" | "city" | "locality" | "oaza" | "neighborhood" | "chome" | "block" | "street" | "address";
export interface SuggestionJSONAction {
/**
* The endpoint to point the next request to. The current options are suggest and retrieve.
*
* The `suggest` call is used when the API determines the next best option is another round of suggestions.
*
* The `retrieve` call is used when the API determines it understands what feature the user is looking for
* and that the user is ready for the geographic coordinates of the results.
*/
endpoint: "suggest" | "retrieve";
/**
* The type of HTTP methods that are allowed for the next request. Options are `POST` or, less commonly, `GET`.
*/
method: "POST" | "GET";
/**
* The JSON body to pass in the actionable request.
*/
body: unknown;
/**
* Indicates whether the feature can be fetched as part of a batch retrieve. Not applicable during the public beta phase.
*/
multi_retrievable?: boolean;
}
/**
* Raw JSON form of a suggestion result's "context" from the [Mapbox Search API](https://docs.mapbox.com/api/search/search/).
*
* Reference:
* https://docs.mapbox.com/api/search/search/#response-retrieve-a-suggestion
*/
export interface SuggestionJSONContext {
layer: string;
localized_layer: string;
name: string;
}
/**
* A `Suggestion` object represents a suggestion result from the [Mapbox Search API](https://docs.mapbox.com/api/search/search/).
*
* Suggestion objects are "part one" of the two-step interactive search experience, and include useful information about the result,
* such as: {@link Suggestion#feature_name}, {@link Suggestion#description}, and {@link Suggestion#maki}.
*
* Suggestion objects do not include geographic coordinates. To get the coordinates of the result, use {@link MapboxSearch#retrieve}.
* It may be useful to call {@link MapboxSearch#canRetrieve} before calling this method, as the suggestion may be a reference to
* another suggest query. This can also be tested with {@link MapboxSearch#canSuggest}, and called with {@link MapboxSearch#suggest}.
*
* For tracking purposes, it is useful for any follow-up requests based on this suggestion to include same
* {@link SessionToken} as the original request.
*
* Reference:
* https://docs.mapbox.com/api/search/search/#response-retrieve-a-suggestion
*
* @typedef Suggestion
* @example
* ```typescript
* const search = new MapboxSearch({ accessToken: 'pk.my-mapbox-access-token' });
*
* const sessionToken = new SessionToken();
* const result = await search.suggest('Washington D.C.', { sessionToken });
* if (result.suggestions.length === 0) return;
*
* const suggestion = result.suggestions[0];
* if (search.canRetrieve(suggestion)) {
* const { features } = await search.retrieve(suggestion, { sessionToken });
* doSomethingWithCoordinates(features);
* } else if (search.canSuggest(suggestion)) {
* // .. go through suggest flow again ..
* }
* ```
*/
export interface Suggestion {
/**
* The name of the feature.
*/
feature_name: string;
/**
* The feature name, as matched by the search algorithm.
*/
matching_name: string;
/**
* Additional details, such as city and state for addresses.
*/
description: string;
/**
* The name of the [Maki](https://labs.mapbox.com/maki-icons/) icon associated with the feature.
*/
maki?: string;
/**
* For results with an address, the locally formatted address.
*/
address?: string;
/**
* The house number for address objects.
*/
address_number?: string;
/**
* The [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag) of the feature.
*/
language: string;
/**
* The type of result using the global context hierarchy (region, place, locality, neighborhood, address).
*
* @see {@link AdministrativeUnitTypes}
*/
result_type?: AdministrativeUnitTypes[];
/**
* Action block of the suggestion result.
* "body" is an opaque object.
*
* Reference: https://docs.mapbox.com/api/search/search/#response-retrieve-a-suggestion
*/
action?: SuggestionJSONAction;
/**
* A list of category IDs that the feature belongs to.
*/
category?: string[];
internal_id?: string;
external_ids?: {
federated: string;
mbx_poi?: string;
foursquare?: string;
[name: string]: string | undefined;
};
mapbox_id?: string;
/**
* Address context fields of the feature.
*/
context: SuggestionJSONContext[];
/**
* Address metadata fields of the feature.
*/
metadata: {
[key: string]: string;
};
}
/**
* Raw [GeoJSON](https://docs.mapbox.com/help/glossary/geojson/) feature properties
* from the [Mapbox Search API](https://docs.mapbox.com/api/search/search/).
*
* Reference:
* https://docs.mapbox.com/api/search/search/#response-forward-geocoding
*
* @typedef SearchFeatureProperties
* @see {@link Suggestion}
*/
export interface SearchFeatureProperties extends Suggestion {
/**
* ID of the feature.
*/
id: string;
/**
* The name of the place.
*/
place_name?: string;
/**
* The type of place using the global context hierarchy (region, place, locality, neighborhood, address).
*
* @see {@link AdministrativeUnitTypes}
*/
place_type?: AdministrativeUnitTypes[];
}
/**
* A `FeatureSuggestion` object represents a [GeoJSON](https://docs.mapbox.com/help/glossary/geojson/) suggestion result from the [Mapbox Search API](https://docs.mapbox.com/api/search/search/).
*
* Feature suggestions are "part two" of the two-step interactive search experience and includes geographic coordinates. Multiple feature suggestions may be returned from a single search query,
* for example in an airport with multiple terminals.
*
* As per the [Mapbox Search API](https://docs.mapbox.com/api/search/search/), this will always be
* [Point](https://geojson.org/geojson-spec.html#point).
*
* **Legal terms:**
*
* Due to legal terms from our data sources, feature suggestions from the [Mapbox Search API](https://docs.mapbox.com/api/search/search/) should come from the `permanentForward` & `permanentReverse`
* methods if the results are to be cached/stored in a customer database. Otherwise, results should be used ephemerally and not persisted.
*
* This permanent policy is consistent with the [Mapbox Terms of Service](https://www.mapbox.com/tos/) and failure to comply
* may result in modified or discontinued service.
*
* Additionally, the [Mapbox Terms of Service](https://www.mapbox.com/tos/) states any rendering of a feature suggestion
* must be using Mapbox map services (for example, displaying results on Google Maps or MapKit JS is not allowed).
*
* **Disclaimer:**
*
* The failure of Mapbox to exercise or enforce any right or provision of these Terms will not constitute a waiver of such right or provision.
*
* @typedef FeatureSuggestion
* @example
* ```typescript
* const featureSuggestion = {
* type: 'Feature',
* geometry: {
* type: 'Point',
* coordinates: [0,0]
* },
* properties: {
* feature_name: 'Washington D.C.',
* }
* };
* ```
* @see [Response: Forward geocoding](https://docs.mapbox.com/api/search/search/#response-forward-geocoding)
*/
export declare type FeatureSuggestion = GeoJSON.Feature<GeoJSON.Point, SearchFeatureProperties> & {
/**
* A bounding box for the feature. This may be significantly
* larger than the geometry.
*/
bbox?: LngLatBoundsLike;
};
/**
* A `SessionToken` object is a unique identifier that groups together `suggest` / `retrieve` calls as part of the
* [Mapbox Search API](https://docs.mapbox.com/api/search/search/#retrieve-a-suggestion).
*
* Session tokens are used for [billing](https://docs.mapbox.com/api/search/search/#search-api-pricing) and
* customer-accessible analytics.
*
* A [UUIDv4](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random)) value is recommended,
* and is generated if an `id` is not provided.
*
* Note that any method that accepts a `SessionToken` object as an argument or option
* can also accept a unique `string` and will perform an implicit conversion.
* This flexible type is documented as {@link SessionTokenLike}.
*
* @name SessionToken
* @example
* ```typescript
* const token = new SessionToken();
* console.log(token.id); // = I am a UUIDv4 value!
* ```
*/
export declare class SessionToken {
/**
* The session token in string format.
*/
readonly id: string;
/**
* Returns the timestamp of when the session token was initialized.
*/
readonly ts: number;
constructor(id?: string, ts?: number);
/**
* Returns the session token in string format.
*
* This is the same as calling `token.id`, and is okay to be used for serialization.
*/
toString(): string;
/**
* Converts a string to a `SessionToken` object.
*
* If a `SessionToken` object is passed in, the function returns a copy.
*/
static convert(token: SessionToken | string): SessionToken;
/**
* Returns `true` if the session token has expired (expired after 60 minutes).
*/
isExpired(): boolean;
}
/**
* A {@link SessionToken} object or string representing a Mapbox Search API session token.
*
* It's recommended this value is a [UUIDv4](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random)) value.
*
* @typedef SessionTokenLike
* @type {SessionToken | string}
* @example
* const v1 = new SessionToken();
* const v2 = new SessionToken('f06e7531-6373-4d5a-8614-b6f313488050');
* const v3 = 'f06e7531-6373-4d5a-8614-b6f313488050';
*/
export declare type SessionTokenLike = string | SessionToken;
export interface AccessTokenOptions {
/**
* The [Mapbox access token](https://docs.mapbox.com/help/glossary/access-token/) to use for all requests.
*/
accessToken: string;
}
export interface FetchOptions {
/**
* If specified, the connected {@link AbortController} can be used to
* abort the current network request(s).
*
* This mechanism works in the same way as the [`fetch` API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#aborting_a_fetch).
*
* Reference:
* https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal#examples
*/
signal?: AbortSignal;
}
export interface SessionTokenOptions {
/**
* A customer-provided session token value, which groups a series of requests
* together for [billing purposes](https://docs.mapbox.com/api/search/search/#search-api-pricing).
*
* Reference:
* https://docs.mapbox.com/api/search/search/#session-based-pricing
*/
sessionToken: SessionTokenLike;
}
/**
* @typedef Options
*/
export interface Options {
/**
* The [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag) to be returned.
*
* If not specified, `en` will be used.
*/
language: string;
/**
* An [ISO 3166 alpha-2 country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) to be returned.
*
* If not specified, results will not be filtered by country.
*/
country: string;
/**
* Limit results to only those contained within the supplied bounding box.
*/
bbox: string | LngLatBoundsLike;
/**
* The number of results to return, up to `10`.
*/
limit: string | number;
/**
* The navigation routing profile to use for distance/eta calculations.
*
* For distance calculations, both {@link Options#navigation_profile} and
* {@link Options#origin} must be specified.
*
* For ETA calculations: {@link Options#navigation_profile},
* {@link Options#origin}, and {@link Options#eta_type} must be specified.
*/
navigation_profile?: "driving" | "walking" | "cycling";
/**
* The location from which to calculate distance. **This parameter may incur additional latency.**
*
* When both {@link Options#proximity} and {@link Options#origin} are specified, `origin` is interpreted as the
* target of a route, while `proximity` indicates the current user location.
*
* For distance calculations, both {@link Options#navigation_profile} and
* {@link Options#origin} must be specified.
*
* For ETA calculations: {@link Options#navigation_profile},
* {@link Options#origin}, and {@link Options#eta_type} must be specified.
*/
origin: string | LngLatLike;
/**
* Bias the response to favor results that are closer to this location.
*
* When both {@link Options#proximity} and {@link Options#origin} are specified, `origin` is interpreted as the
* target of a route, while `proximity` indicates the current user location.
*/
proximity: string | LngLatLike;
/**
* Used to estimate the time of arrival from {@link Options#origin}. **This parameter may incur additional latency.**
*
* For ETA calculations: {@link Options#navigation_profile},
* {@link Options#origin}, and {@link Options#eta_type} must be specified.
*/
eta_type?: "navigation";
/**
* Limit results to one or more types of features. If no types are specified, all possible types may be returned.
*
* Reference:
* https://docs.mapbox.com/api/search/search/#administrative-unit-types
*/
types?: string | Set<AdministrativeUnitTypes>;
}
export interface PermanentOptions {
/**
* The permanent endpoints are used for use cases that require storing
* position data. If 'true', the permanent endpoints will be used, which are
* billed separately.
*
* If you're interested in using {@link PermanentOptions#permanent}, contact
* [Mapbox sales](https://www.mapbox.com/contact/sales/).
*
* It's important to speak with an Account Manager on the Sales team prior to making requests
* with {@link PermanentOptions#permanent} set to `true`, as unsuccessful requests
* made by an account that does not have access to the endpoint may be billable.
*/
permanent: boolean;
}
/**
* @typedef SuggestionResponse
*/
export interface SuggestionResponse {
/**
* The attribution data for results.
*/
attribution?: string;
/**
* The returned suggestion objects.
*
* @see {@link Suggestion}
*/
suggestions: Suggestion[];
}
/**
* @typedef RetrieveResponse
*/
export interface RetrieveResponse {
type: "FeatureCollection";
/**
* The attribution data for results.
*/
attribution?: string;
/**
* The returned feature objects.
*
* @see {@link FeatureSuggestion}
*/
features: FeatureSuggestion[];
}
/**
* A `MapboxSearch` object is an application's main entrypoint to the [Mapbox Search API](https://docs.mapbox.com/api/search/search/).
*
* `MapboxSearch` is focused on the two-step, interactive search experience. These steps are:
* 1. {@link MapboxSearch#suggest}: The user enters a search term, and a list of suggested results is returned with
* optional data such as: eta, distance calculations, etc.
* 2. {@link MapboxSearch#retrieve}: The user selects a result from the list of suggested results, and the
* corresponding geographic coordinates are returned for displaying on a map or otherwise manipulating.
*
* A [Mapbox access token](https://docs.mapbox.com/help/glossary/access-token/) is required to use `MapboxSearch`, and
* other options may be specified either in the constructor or in the {@link MapboxSearch#suggest} call.
*
* @class MapboxSearch
* @param {Options} [options]
* @param {string} [options.accessToken]
*
* @example
* ```typescript
* const search = new MapboxSearch({ accessToken: 'pk.my-mapbox-access-token' });
*
* const sessionToken = new SessionToken();
* const result = await search.suggest('Washington D.C.', { sessionToken });
* if (result.suggestions.length === 0) return;
*
* const suggestion = result.suggestions[0];
* if (search.canRetrieve(suggestion)) {
* const { features } = await search.retrieve(suggestion, { sessionToken });
* doSomethingWithCoordinates(features);
* } else if (search.canSuggest(suggestion)) {
* // .. go through suggest flow again ..
* }
* ```
*/
export declare class MapboxSearch {
#private;
/**
* The [Mapbox access token](https://docs.mapbox.com/help/glossary/access-token/) to use for all requests.
*/
accessToken: string;
/**
* Any default options ({@link Options}) to be merged into options in the following methods:
* - {@link MapboxSearch#suggest}
* - {@link MapboxSearch#forward}
* - {@link MapboxSearch#reverse}
*/
defaults: Partial<Options>;
constructor(options?: Partial<AccessTokenOptions & Options>);
/** @section {Interactive search} */
/**
* {@link MapboxSearch#suggest} is "part one" of the two-step interactive search experience, and includes
* useful information such as: {@link Suggestion#feature_name}, {@link Suggestion#description}, and {@link Suggestion#maki}.
*
* Suggestion objects **do not include geographic coordinates**. To get the coordinates of the result, use {@link MapboxSearch#retrieve}.
*
* It may be useful to call {@link MapboxSearch#canRetrieve} before calling this method, as the suggestion may be a reference to
* another suggest query. This can also be tested with {@link MapboxSearch#canSuggest}, and further calls to {@link MapboxSearch#suggest}.
*
* For tracking purposes, it is useful for any follow-up requests based on this suggestion to include same
* {@link Suggestion#sessionToken} as the original request.
*
* If you'd like session tokens to be handled automatically, see {@link SearchSession}.
*
* @param {string} searchText
* @param {Options} optionsArg
* @param {SessionTokenLike} optionsArg.sessionToken
* @param {AbortSignal} [optionsArg.signal]
*/
suggest(searchText: string, optionsArg: SessionTokenOptions & Partial<FetchOptions & Options>): Promise<SuggestionResponse>;
/**
* {@link MapboxSearch#retrieve} is "part two" of the two-step interactive search experience and includes
* geographic coordinates in [GeoJSON](https://docs.mapbox.com/help/glossary/geojson/) format.
*
* {@link suggestion} is usually a {@link Suggestion} returned from "part one," {@link MapboxSearch#suggest}.
*
* Multiple feature suggestions may be returned from a single search query, for example in an airport with
* multiple terminals.
*
* **Legal terms:**
*
* Due to legal terms from our data sources, if the results are to be cached/stored in a customer database,
* feature suggestions should come from the {@link MapboxSearch#forward} method
* with {@link PermanentOptions#permanent} enabled.
*
* Otherwise, results should be used ephemerally and not persisted.
*
* This permanent policy is consistent with the [Mapbox Terms of Service](https://www.mapbox.com/tos/) and failure to comply
* may result in modified or discontinued service.
*
* Additionally, the [Mapbox Terms of Service](https://www.mapbox.com/tos/) states any rendering of a feature suggestion
* must be using Mapbox map services (for example, displaying results on Google Maps or MapKit JS is not allowed).
*
* **Disclaimer:**
*
* The failure of Mapbox to exercise or enforce any right or provision of these Terms will not constitute a waiver of such right or provision.
*
* @param {any} optionsArg
* @param {SessionTokenLike} optionsArg.sessionToken
* @param {AbortSignal} [optionsArg.signal]
*/
retrieve(suggestion: Suggestion, optionsArg: SessionTokenOptions & Partial<FetchOptions>): Promise<RetrieveResponse>;
/**
* Returns true if {@link MapboxSearch#retrieve} can be called on this suggestion,
* false otherwise.
*
* This indicates the [Mapbox Search API](https://docs.mapbox.com/api/search/search/) has geographic coordinates
* for this suggestion.
*
* This method is mutually exclusive with {@link MapboxSearch#canSuggest}.
*/
canRetrieve(suggestion: Suggestion): boolean;
/**
* Returns true if {@link MapboxSearch#suggest} can be called on this suggestion,
* false otherwise.
*
* This indicates the [Mapbox Search API](https://docs.mapbox.com/api/search/search/) wants to do another
* suggestion search on this result, and does not have geographic coordinates.
*
* This method is mutually exclusive with {@link MapboxSearch#canRetrieve}.
*/
canSuggest(suggestion: Suggestion): boolean;
/** @section {Programmatic search} */
/**
* {@link MapboxSearch#forward} is our programmatic one-step search experience and includes
* geographic coordinates in [GeoJSON](https://docs.mapbox.com/help/glossary/geojson/) format.
*
* Multiple feature suggestions may be returned from a single search query, for example in an airport with
* multiple terminals.
*
* **Legal terms:**
*
* Due to legal terms from our data sources, if the results are to be cached/stored in a customer database,
* {@link PermanentOptions#permanent} should be enabled. This requires contacting Mapbox support.
*
* Otherwise, results should be used ephemerally and not persisted.
*
* This permanent policy is consistent with the [Mapbox Terms of Service](https://www.mapbox.com/tos/) and failure to comply
* may result in modified or discontinued service.
*
* Additionally, the [Mapbox Terms of Service](https://www.mapbox.com/tos/) states any rendering of a feature suggestion
* must be using Mapbox map services (for example, displaying results on Google Maps or MapKit JS is not allowed).
*
* **Disclaimer:**
*
* The failure of Mapbox to exercise or enforce any right or provision of these Terms will not constitute a waiver of such right or provision.
*
* @param {Options} optionsArg
* @param {AbortSignal} [optionsArg.signal]
* @param {boolean} [optionsArg.permanent]
*/
forward(searchText: string, optionsArg?: Partial<FetchOptions & Options & PermanentOptions>): Promise<RetrieveResponse>;
/**
* {@link MapboxSearch#reverse} allows you to look up a geographic coordinate pair
* and returns the feature(s) in [GeoJSON](https://docs.mapbox.com/help/glossary/geojson/) format.
*
* Multiple feature suggestions may be returned from a single search query, for example in an airport with
* multiple terminals.
*
* **Legal terms:**
*
* Due to legal terms from our data sources, if the results are to be cached/stored in a customer database,
* {@link PermanentOptions#permanent} should be enabled. This requires contacting Mapbox support.
*
* Otherwise, results should be used ephemerally and not persisted.
*
* This permanent policy is consistent with the [Mapbox Terms of Service](https://www.mapbox.com/tos/) and failure to comply
* may result in modified or discontinued service.
*
* Additionally, the [Mapbox Terms of Service](https://www.mapbox.com/tos/) states any rendering of a feature suggestion
* must be using Mapbox map services (for example, displaying results on Google Maps or MapKit JS is not allowed).
*
* **Disclaimer:**
*
* The failure of Mapbox to exercise or enforce any right or provision of these Terms will not constitute a waiver of such right or provision.
*
* @param lngLat - Either a {@link LngLatLike} object or string in 'lng,lat' comma-separated format.
* @param {Options} optionsArg
* @param {AbortSignal} [optionsArg.signal]
* @param {boolean} [optionsArg.permanent]
*/
reverse(lngLat: string | LngLatLike, optionsArg?: Partial<FetchOptions & Options & PermanentOptions>): Promise<RetrieveResponse>;
}
/**
* An `AutofillSuggestion` object represents a suggestion
* result from the Mapbox Autofill API.
*
* Suggestion objects are "part one" of the two-step interactive autofill experience.
* Suggestion objects do not include geographic coordinates.
*
* To get the coordinates of the result, use {@link MapboxAutofill#retrieve}.
*
* For tracking purposes, it is useful for any follow-up requests based on this suggestion to include same
* {@link SessionToken} as the original request.
*
* @typedef AutofillSuggestion
* @example
* ```typescript
* const autofill = new MapboxAutofill({ accessToken: 'pk.my-mapbox-access-token' });
*
* const sessionToken = new SessionToken();
* const result = await search.autofill('Washington D.C.', { sessionToken });
* if (result.suggestions.length === 0) return;
*
* const suggestion = result.suggestions[0];
* const { features } = await autofill.retrieve(suggestion, { sessionToken });
* doSomethingWithCoordinates(features);
* ```
*/
export interface AutofillSuggestion {
/**
* This is added by {@link MapboxAutofill} and is **not** part of the
* Autofill API.
*
* @ignore
*/
original_search_text: string;
/**
* The name of the feature.
*/
feature_name: string;
/**
* The feature name, as matched by the search algorithm.
*/
matching_name: string;
/**
* Additional details, such as city and state for addresses.
*/
description: string;
/**
* The name of the [Maki](https://labs.mapbox.com/maki-icons/) icon associated with the feature.
*/
maki?: string;
/**
* The [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag) of the feature.
*/
language: string;
address?: string;
/**
* The full address of the suggestion.
*/
full_address?: string;
/**
* Address line 1 from the [WHATWG Autocomplete Specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill)
*/
address_line1?: string;
/**
* Address line 2 from the [WHATWG Autocomplete Specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill)
*/
address_line2?: string;
/**
* Address line 3 from the [WHATWG Autocomplete Specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill)
*/
address_line3?: string;
/**
* Address level 1 from the [WHATWG Autocomplete Specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill)
*/
address_level1?: string;
/**
* Address level 2 from the [WHATWG Autocomplete Specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill)
*/
address_level2?: string;
/**
* Address level 3 from the [WHATWG Autocomplete Specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill)
*/
address_level3?: string;
/**
* Long form country name, for example: "United States"
*/
country?: string;
/**
* Postal code.
*/
postcode?: string;
/**
* Address metadata fields of the feature.
*
* Includes the short form country name, for example: "us". This follows the
* [ISO 3166 alpha-2 country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) specification.
*/
metadata: {
iso_3166_1: string;
};
}
/**
* An `AutofillFeatureSuggestion` object represents [GeoJSON](https://docs.mapbox.com/help/glossary/geojson/)
* suggestion results from the Mapbox Autofill API.
*
* As per the Mapbox Autofill API, this will always be [Point](https://geojson.org/geojson-spec.html#point).
*
* @typedef AutofillFeatureSuggestion
* @example
* ```typescript
* const featureSuggestion = {
* type: 'Feature',
* geometry: {
* type: 'Point',
* coordinates: [0,0]
* },
* properties: {
* feature_name: 'Washington D.C.',
* }
* };
* ```
*/
export declare type AutofillFeatureSuggestion = GeoJSON.Feature<GeoJSON.Point, AutofillSuggestion> & {
/**
* A bounding box for the feature. This may be significantly
* larger than the geometry.
*/
bbox?: LngLatBoundsLike;
};
export interface AccessTokenOptions {
/**
* The [Mapbox access token](https://docs.mapbox.com/help/glossary/access-token/) to use for all requests.
*/
accessToken: string;
}
export interface FetchOptions {
/**
* If specified, the connected {@link AbortController} can be used to
* abort the current network request(s).
*
* This mechanism intentionally works in the same way as the
* [`fetch` API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#aborting_a_fetch).
*
* Reference:
* https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal#examples
*/
signal?: AbortSignal;
}
export interface SessionTokenOptions {
/**
* A customer-provided session token value, which groups a series of requests together for [billing purposes](https://docs.mapbox.com/api/search/search/#search-api-pricing).
*
* Reference:
* https://docs.mapbox.com/api/search/search/#session-based-pricing
*/
sessionToken: SessionTokenLike;
}
/**
* @typedef AutofillOptions
*/
export interface AutofillOptions {
/**
* The [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag) to be returned.
*
* If not specified, `en` will be used.
*/
language: string;
/**
* An [ISO 3166 alpha-2 country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) to be returned.
*
* If not specified, results will not be filtered by country.
*/
country: string;
/**
* Limit results to only those contained within the supplied bounding box.
*/
bbox: string | LngLatBoundsLike;
/**
* The number of results to return, up to `10`.
*/
limit: string | number;
/**
* Bias the response to favor results that are closer to this location.
*
* When both {@link AutofillOptions#proximity} and {@link AutofillOptions#origin} are specified, `origin` is interpreted as the
* target of a route, while `proximity` indicates the current user location.
*/
proximity: string | LngLatLike;
}
/**
* @typedef AutofillSuggestionResponse
*/
export interface AutofillSuggestionResponse {
/**
* The attribution data for results.
*/
attribution?: string;
/**
* The returned suggestion objects.
*
* @see {@link Suggestion}
*/
suggestions: AutofillSuggestion[];
}
/**
* @typedef AutofillRetrieveResponse
*/
export interface AutofillRetrieveResponse {
type: "FeatureCollection";
/**
* The attribution data for results.
*/
attribution?: string;
/**
* The returned feature objects.
*
* @see {@link FeatureSuggestion}
*/
features: AutofillFeatureSuggestion[];
}
/**
* A `MapboxAutofill` object is an application's main entrypoint to the
* Mapbox Autofill API. The Mapbox Autofill API is an API similar to {@link MapboxSearch},
* but targeted towards **address** autocomplete.
*
* Only address types are returned by the API.
*
* `MapboxAutofill` is focused on the two-step, interactive search experience. These steps are:
* 1. {@link MapboxAutofill#suggest}: The user enters a search term, and a list of suggested results is returned with
* address data.
* 2. {@link MapboxAutofill#retrieve}: The user selects a result from the list of suggested results, and the
* corresponding geographic coordinates are returned.
*
* A [Mapbox access token](https://docs.mapbox.com/help/glossary/access-token/) is required to use `MapboxAutofill`, and
* other options may be specified either in the constructor or in the {@link MapboxAutofill#suggest} call.
*
* @class MapboxAutofill
* @param {AutofillOptions} [options]
* @param {string} [options.accessToken]
*/
export declare class MapboxAutofill {
#private;
/**
* The [Mapbox access token](https://docs.mapbox.com/help/glossary/access-token/) to use for all requests.
*/
accessToken: string;
/**
* Any default options ({@link AutofillOptions}) to be merged into options in the following methods:
* - {@link MapboxAutofill#suggest}
*
* @type {AutofillOptions}
*/
defaults: Partial<AutofillOptions>;
constructor(options?: Partial<AccessTokenOptions & AutofillOptions>);
/** @section {Methods} */
/**
* {@link MapboxAutofill#suggest} is "part one" of the two-step autofill experience, and includes
* autofill information.
*
* Suggestion objects **do not include geographic coordinates**. To get the coordinates of the result, use {@link MapboxSearch#retrieve}.
*
* For tracking purposes, it is useful for any follow-up requests based on this suggestion to include same
* {@link Suggestion#sessionToken} as the original request.
*
* If you'd like session tokens to be handled automatically, see {@link SearchSession}.
*
* @param {AutofillOptions} optionsArg
* @param {SessionTokenLike} optionsArg.sessionToken
* @param {AbortSignal} [optionsArg.signal]
*/
suggest(searchText: string, optionsArg: SessionTokenOptions & Partial<FetchOptions & AutofillOptions>): Promise<AutofillSuggestionResponse>;
/**
* {@link MapboxAutofill#retrieve} is "part two" of the two-step autofill experience and includes
* geographic coordinates in [GeoJSON](https://docs.mapbox.com/help/glossary/geojson/) format.
*
* {@link suggestion} is usually a {@link AutofillSuggestion} returned from "part one,"
* {@link MapboxAutofill#suggest}.
*
* Multiple feature suggestions may be returned from a single address,
* for example an address with multiple buildings.
*
* **Legal terms:**
*
* Geographic coordinates should be used ephemerally and not persisted.
*
* This permanent policy is consistent with the [Mapbox Terms of Service](https://www.mapbox.com/tos/) and failure to comply
* may result in modified or discontinued service.
*
* Additionally, the [Mapbox Terms of Service](https://www.mapbox.com/tos/) states any rendering of a feature suggestion
* must be using Mapbox map services (for example, displaying results on Google Maps or MapKit JS is not allowed).
*
* **Disclaimer:**
*
* The failure of Mapbox to exercise or enforce any right or provision of these Terms will not constitute a waiver of such right or provision.
*
* @param {AutofillOptions} optionsArg
* @param {SessionTokenLike} optionsArg.sessionToken
* @param {AbortSignal} [optionsArg.signal]
*/
retrieve(suggestion: string | AutofillSuggestion, optionsArg: SessionTokenOptions & Partial<FetchOptions & AutofillOptions>): Promise<AutofillRetrieveResponse>;
}
declare class Evented<T> {
#private;
/**
* Adds a listener to a specified event type.
*
* @param type - The event type to add a listen for.
* @param listener - The function to be called when the event is fired.
*/
addEventListener<K extends keyof T>(type: K, listener: (arg0: T[K]) => void): void;
/**
* Removes a previously registered event listener.
*
* @param type - The event type to remove listeners for.
* @param listener - The listener function to remove.
*/
removeEventListener<K extends keyof T>(type: K, listener: (arg0: T[K]) => void): void;
fire<K extends keyof T>(type: K, arg0: T[K]): void;
}
export interface EventTypes<SuggestionResponse, RetrieveResponse> {
suggest: SuggestionResponse;
suggesterror: Error;
retrieve: RetrieveResponse;
}
/**
* TypeScript magic section: what is this?
*
* Despite the name {@link SearchSession}, in Search JS Web we use it to control
* both {@link MapboxSearch} **and** {@link MapboxAutofill} instances. Both
* of these have similar workflows, but are separate APIs with different options
* and responses.
*
* In order to make TypeScript happy, this type is an "approximation" of what
* {@link SearchSession} uses. When you construct a new {@link SearchSession},
* because of this type [Options, Suggestion, SuggestionResponse, RetrieveResponse]
* are automatically inferred.
*
* @internal
* @example
* ```typescript
* const autofill = new MapboxAutofill({
* accessToken: 'pk.my-fancy-token',
* });
*
* const session = new SearchSession(autofill);
*
* `session` has inferred type = SearchSession<
* AutofillOptions,
* AutofillSuggestion,
* AutofillSuggestionResponse,
* AutofillRetrieveResponse
* >
* ```
*/
export declare type SuggestSearch<Options, Suggestion, SuggestionResponse, RetrieveResponse> = {
suggest: (text: string, options: Partial<Options> & {
sessionToken: SessionTokenLike;
signal: AbortSignal;
}) => Promise<SuggestionResponse>;
retrieve: (suggestion: Suggestion, options: {
sessionToken: SessionTokenLike;
}) => Promise<RetrieveResponse>;
canRetrieve?: (suggestion: Suggestion) => boolean;
canSuggest?: (suggestion: Suggestion) => boolean;
};
/**
* A `SearchSession` object is a managed entrypoint to the [Mapbox Search API](https://docs.mapbox.com/api/search/search/)
* or Mapbox Autocomplete API.
*
* `SearchSession` abstracts the suggest/retrieve flow of the two-step interactive search experience.
*
* Compared to using these APIs directly, you can use a `SearchSession` to:
* 1. Automatically manage the session token lifecycle.
* 2. Debounce calls to {@link SearchSession#suggest}.
* 2. Abort in-flight requests with an imperative API.
*
* @class SearchSession
* @example
* ```typescript
* const search = new MapboxSearch({ accessToken: 'pk.my-mapbox-access-token' });
* const session = new SearchSession(search);
*
* session.addEventListener('suggest', (res) => {
* presentResultsToUser(res.suggestions);
* });
*
* session.addEventListener('retrieve', (res) => {
* doSomethingWithFeatureCollection(res);
* });
*
* document.querySelector('button').addEventListener('click', (event) => {
* const suggestions = session.suggestions?.suggestions;
* if (!suggestions || !suggestions.length) {
* return;
* }
*
* const suggestion = suggestions[0];
* if (session.canRetrieve(suggestion)) {
* session.retrieve(suggestion);
* } else if (session.canSuggest(suggestion)) {
* // .. go through suggest flow again ..
* session.suggest(suggestion.text);
* }
* });
*
* session.suggest('Washington D.C.');
* ```
* @param {MapboxSearch | MapboxAutofill} search - The search interface to wrap.
* @param {number} wait - The time in milliseconds to wait before sending a new request to the {@link SearchSession#suggest} call.
*/
export declare class SearchSession<Options, Suggestion, SuggestionResponse, RetrieveResponse> extends Evented<EventTypes<SuggestionResponse, RetrieveResponse>> {
#private;
readonly search: SuggestSearch<Options, Suggestion, SuggestionResponse, RetrieveResponse>;
/**
* The time in milliseconds to wait before sending a new request to the
* {@link SearchSession#suggest} call.
*/
readonly debounce: number;
/**
* The suggestions from the last successful suggest call, if any.
*/
get suggestions(): SuggestionResponse | null;
constructor(search: SuggestSearch<Options, Suggestion, SuggestionResponse, RetrieveResponse>, wait?: number);
/** @section {Methods} */
/**
* {@link SearchSession#suggest} is "part one" of the two-step interactive search experience,
* and each suggestion includes metadata to present to the user.
*
* Suggestion objects **do not include geographic coordinates**. To get the coordinates of the result, use {@link SearchSession#retrieve}.
*
* It may be useful to call {@link SearchSession#canRetrieve} before calling this method, as the suggestion may be a reference to
* another suggest query. This can also be tested with {@link SearchSession#canSuggest}, and further calls to {@link SearchSession#suggest}.
*
* Results can be retrieved with the "suggest" event.
*
* @example
* ```typescript
* const search = new MapboxSearch({ accessToken: 'pk.my-mapbox-access-token' });
* const session = new SearchSession(search);
*
* session.addEventListener('suggest', (res) => {
* presentResultsToUser(res.suggestions);
* });
*
* session.suggest('Washington D.C.');
* ```
*/
suggest(searchText: string, options?: Partial<Options>): Promise<SuggestionResponse>;
/**
* Clears the current suggestions.
*/
clear(): void;
/**
* {@link SearchSession#retrieve} is "part two" of the two-step interactive search experience and includes
* geographic coordinates in [GeoJSON](https://docs.mapbox.com/help/glossary/geojson/) format.
*
* {@link suggestion} is usually a {@link Suggestion} returned from "part one," {@link SearchSession#suggest}.
*
* Multiple feature suggestions may be returned from a single search query, for example in an airport with
* multiple terminals.
*
* **Legal terms:**
*
* Due to legal terms from our data sources, results should not be stored in a customer database.
* Results should be used ephemerally and not persisted.
*
* This permanent policy is consistent with the [Mapbox Terms of Service](https://www.mapbox.com/tos/) and failure to comply
* may result in modified or discontinued service.
*
* Additionally, the [Mapbox Terms of Service](https://www.mapbox.com/tos/) states any rendering of a feature suggestion
* must be using Mapbox map services (for example, displaying results on Google Maps or MapKit JS is not allowed).
*
* **Disclaimer:**
*
* The failure of Mapbox to exercise or enforce any right or provision of these Terms will not constitute a waiver of such right or provision.
*/
retrieve(suggestion: Suggestion): Promise<RetrieveResponse>;
/**
* Returns true if {@link SearchSession#retrieve} can be called on this suggestion,
* false otherwise.
*
* This indicates the [Mapbox Search API](https://docs.mapbox.com/api/search/search/) has geographic coordinates
* for this suggestion.
*
* This method is mutually exclusive with {@link SearchSession#canSuggest}.
*/
canRetrieve(suggestion: Suggestion): boolean;
/**
* Returns true if {@link SearchSession#suggest} can be called on this suggestion,
* false otherwise.
*
* This indicates the [Mapbox Search API](https://docs.mapbox.com/api/search/search/) wants to do another
* suggestion search on this result, and does not have geographic coordinates.
*
* This method is mutually exclusive with {@link SearchSession#canRetrieve}.
*/
canSuggest(suggestion: Suggestion): boolean;
/**
* Aborts the current {@link SearchSession#suggest} request.
*/
abort(): void;
}
/**
* Thrown from Search JS Core functions when a network request fails.
*
* See common errors here:
* - [MapboxSearch](https://docs.mapbox.com/api/search/search/#search-api-errors)
* - [MapboxAutofill](https://docs.mapbox.com/api/search/geocoding/#geocoding-api-errors)
*/
export declare class MapboxError extends Error {
readonly statusCode: number;
constructor(json: Record<string, unknown>, statusCode: number);
/**
* Modified Error toString() method to include the status code.
*/
toString(): string;
}
export interface FetchImplementation {
fetch: typeof fetch;
AbortController: typeof AbortController;
}
/**
* Polyfills {@link fetch} implementation used in Search JS Core.
*
* If a `fetch` implementation is already available, the polyfill will be
* silently ignored.
*
* Search JS Core will automatically use `node-fetch` if running in Node.js,
* making this function unnecessary for most use cases.
*
* @param opts Options for the polyfill.
* @param {fetch} opts.fetch Required. A custom `fetch` implementation.
* @param {AbortController} opts.AbortController Required. A custom `AbortController` implementation.
* @param {boolean} force If `true`, the polyfill will be forced to load. Otherwise, it will only load if `fetch` is not available.
*/
export declare function polyfillFetch({ fetch, AbortController }: FetchImplementation, force?: boolean): void;
export declare function featureToSuggestion(feature: FeatureSuggestion): Suggestion;
export declare function featureToSuggestion(feature: AutofillFeatureSuggestion): AutofillSuggestion;
export {};
import { Options, MapboxSearch, SuggestionResponse, RetrieveResponse } from './search/MapboxSearch';
import { AdministrativeUnitTypes, Suggestion, FeatureSuggestion } from './search/types';
import { AutofillOptions, MapboxAutofill, AutofillSuggestionResponse, AutofillRetrieveResponse } from './autofill/MapboxAutofill';
import { AutofillSuggestion, AutofillFeatureSuggestion } from './autofill/types';
import { SearchSession } from './SearchSession';
import { SessionToken, SessionTokenLike } from './SessionToken';
import { MapboxError } from './MapboxError';
import { LngLat, LngLatLike } from './LngLat';
import { LngLatBounds, LngLatBoundsLike } from './LngLatBounds';
import { polyfillFetch } from './fetch';
import { featureToSuggestion } from './featureToSuggestion';
import { Evented } from './utils/Evented';
export { Options, MapboxSearch, SuggestionResponse, RetrieveResponse, Suggestion, FeatureSuggestion, AutofillOptions, MapboxAutofill, AutofillSuggestionResponse, AutofillRetrieveResponse, AutofillSuggestion, AutofillFeatureSuggestion, AdministrativeUnitTypes, SearchSession, SessionToken, SessionTokenLike, MapboxError, LngLat, LngLatLike, LngLatBounds, LngLatBoundsLike, polyfillFetch, featureToSuggestion, Evented };

@@ -1,2 +0,2 @@

var ke=Object.create;var _=Object.defineProperty,ye=Object.defineProperties,we=Object.getOwnPropertyDescriptor,ve=Object.getOwnPropertyDescriptors,Ee=Object.getOwnPropertyNames,I=Object.getOwnPropertySymbols,xe=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var Y=(n,e,t)=>e in n?_(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,c=(n,e)=>{for(var t in e||(e={}))V.call(e,t)&&Y(n,t,e[t]);if(I)for(var t of I(e))z.call(e,t)&&Y(n,t,e[t]);return n},d=(n,e)=>ye(n,ve(e)),Z=n=>_(n,"__esModule",{value:!0});var j=(n,e)=>{var t={};for(var r in n)V.call(n,r)&&e.indexOf(r)<0&&(t[r]=n[r]);if(n!=null&&I)for(var r of I(n))e.indexOf(r)<0&&z.call(n,r)&&(t[r]=n[r]);return t};var Oe=(n,e)=>{for(var t in e)_(n,t,{get:e[t],enumerable:!0})},ee=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Ee(e))!V.call(n,s)&&(t||s!=="default")&&_(n,s,{get:()=>e[s],enumerable:!(r=we(e,s))||r.enumerable});return n},Ae=(n,e)=>ee(Z(_(n!=null?ke(xe(n)):{},"default",!e&&n&&n.__esModule?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n),_e=(n=>(e,t)=>n&&n.get(e)||(t=ee(Z({}),e,1),n&&n.set(e,t),t))(typeof WeakMap!="undefined"?new WeakMap:0);var G=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var l=(n,e,t)=>(G(n,e,"read from private field"),t?t.call(n):e.get(n)),h=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)},b=(n,e,t,r)=>(G(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t),te=(n,e,t,r)=>({set _(s){b(n,e,s,t)},get _(){return l(n,e,r)}}),L=(n,e,t)=>(G(n,e,"access private method"),t);var p=(n,e,t)=>new Promise((r,s)=>{var o=i=>{try{u(t.next(i))}catch(m){s(m)}},a=i=>{try{u(t.throw(i))}catch(m){s(m)}},u=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,a);u((t=t.apply(n,e)).next())});var De={};Oe(De,{LngLat:()=>g,LngLatBounds:()=>S,MapboxAutofill:()=>H,MapboxError:()=>$,MapboxSearch:()=>M,SearchSession:()=>X,SessionToken:()=>f,featureToSuggestion:()=>Le,polyfillFetch:()=>W});var E="https://api.mapbox.com/search/v1",B="suggest",K="retrieve",ne="forward",re="reverse",se=`${E}/${B}`,oe=`${E}/${K}`,ie=`${E}/${ne}`,ae=`${E}/permanent/${ne}`,ge=`${E}/${re}`,ue=`${E}/permanent/${re}`;var g=class{constructor(e,t){if(isNaN(e)||isNaN(t))throw new Error(`Invalid LngLat object: (${e}, ${t})`);if(this.lng=+e,this.lat=+t,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(e){if(e instanceof g)return new g(e.lng,e.lat);if(Array.isArray(e)&&e.length===2)return new g(Number(e[0]),Number(e[1]));if(!Array.isArray(e)&&typeof e=="object"&&e!==null&&("lng"in e||"lon"in e)&&"lat"in e)return new g(Number("lng"in e?e.lng:e.lon),Number(e.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>]")}};var S=class{constructor(e,t){this._sw=g.convert(e),this._ne=g.convert(t)}getSouthWest(){return this._sw}getNorthEast(){return this._ne}getNorthWest(){return new g(this.getWest(),this.getNorth())}getSouthEast(){return new g(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(e){if(!e)throw new Error("Invalid LngLatBounds convert value: falsy");if(e instanceof S)return new S(e.getSouthWest(),e.getNorthEast());if(Array.isArray(e)&&e.length===2)return new S(g.convert(e[0]),g.convert(e[1]));if(Array.isArray(e)&&e.length===4)return new S(g.convert([e[0],e[1]]),g.convert([e[2],e[3]]));throw new Error("`LngLatBoundsLike` argument must be specified as an array [<LngLatLike>, <LngLatLike>] or an array [<west>, <south>, <east>, <north>]")}};var ce=Ae(require("polyfill-crypto.getrandomvalues"));function Pe(n){return typeof globalThis.crypto=="undefined"||typeof globalThis.crypto.getRandomValues!="function"?(0,ce.default)(n):globalThis.crypto.getRandomValues(n)}function Ue(n){let e=[...n].map(t=>{let r=t.toString(16);return t<16?"0"+r:r});return[...e.slice(0,4),"-",...e.slice(4,6),"-",...e.slice(6,8),"-",...e.slice(8,10),"-",...e.slice(10,16)].join("")}function le(){let n=Pe(new Uint8Array(16));return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Ue(n)}var Fe=60*60*1e3,f=class{constructor(e,t=Date.now()){this.id=e!=null?e:le(),this.ts=t}toString(){return this.id}static convert(e){return new f(e instanceof f?e.id:e.toString(),e instanceof f?e.ts:Date.now())}isExpired(){return Date.now()-this.ts>Fe}};var Ne="Unknown error",$=class extends Error{constructor(e,t){super(String(e.message||e.error||Ne));this.name="MapboxError",this.statusCode=t}toString(){return`${this.name} (${this.statusCode}): ${this.message}`}};function k(n){return p(this,null,function*(){if(!n.ok){let e=yield n.json();throw new $(e,n.status)}})}var P=globalThis.fetch,me=globalThis.AbortController;function W({fetch:n,AbortController:e},t=!1){if(!n)throw new Error("Fetch implementation must include implementations of `fetch`.");P&&!t||(P=n,me=e)}function R(){if(!P)throw new Error("Fetch implementation not found. Please use `polyfillFetch` from `@mapbox/search-js-core` to fix this issue.");return{fetch:P,AbortController:me}}function fe(n,e){return n(e)}if(!P&&!0&&process.versions.node){let{default:n}=fe(require,"node-fetch"),e=fe(require,"abort-controller");W({fetch:n,AbortController:e})}function x(...n){let e=[];for(let t of n){if(!t)continue;let r=Object.entries(t);for(let[s,o]of r)o!=null&&e.push(`${s}=${encodeURIComponent(String(o))}`)}return e.join("&")}var U,he,q,Ie,M=class{constructor(e={}){h(this,U);h(this,q);this.defaults={language:"en"};let s=e,{accessToken:t}=s,r=j(s,["accessToken"]);this.accessToken=t,Object.assign(this.defaults,r)}suggest(e,t){return p(this,null,function*(){if(!e)throw new Error("searchText is required");if(!this.accessToken)throw new Error("accessToken is required");if(!t||!t.sessionToken)throw new Error("sessionToken is required");let{sessionToken:r,signal:s}=t,o=d(c(c({},this.defaults),t),{sessionToken:r});if(o.eta_type&&(!o.origin||!o.navigation_profile))throw new Error("to provide eta estimate: eta, navigation_profile, and origin are required");if(o.origin&&!o.navigation_profile)throw new Error("to provide distance estimate: both navigation_profile and origin are required");let a=new URL(`${se}/${encodeURIComponent(e)}`);a.search=L(this,U,he).call(this,o);let{fetch:u}=R(),i=yield u(a.toString(),{signal:s});return yield k(i),yield i.json()})}retrieve(e,t){return p(this,null,function*(){if(!e)throw new Error("suggestion is required");if(!this.accessToken)throw new Error("accessToken is required");if(!this.canRetrieve(e))throw new Error("suggestion cannot be retrieved");if(!t||!t.sessionToken)throw new Error("sessionToken is required");let{sessionToken:r,signal:s}=t,o=f.convert(r),a=new URL(oe);a.search=x({access_token:this.accessToken,session_token:o.id});let{fetch:u}=R(),i=yield u(a.toString(),d(c({},L(this,q,Ie).call(this,e)),{signal:s}));return yield k(i),yield i.json()})}canRetrieve(e){let t=e.action;return t?t.method==="POST"&&t.endpoint===K:!1}canSuggest(e){let t=e.action;return t?t.method==="POST"&&t.endpoint===B:!1}forward(r){return p(this,arguments,function*(e,t={}){if(!e)throw new Error("searchText is required");if(!this.accessToken)throw new Error("accessToken is required");let s=c(c({},this.defaults),t),o=s.permanent?ae:ie,a=new URL(`${o}/${encodeURIComponent(e)}`);a.search=L(this,U,he).call(this,s);let{fetch:u}=R(),i=yield u(a.toString(),{signal:s.signal});return yield k(i),yield i.json()})}reverse(r){return p(this,arguments,function*(e,t={}){if(!e)throw new Error("lngLat is required");if(!this.accessToken)throw new Error("accessToken is required");let s=c(c({},this.defaults),t),o=typeof e=="string"?e:g.convert(e).toArray().join(","),a=s.permanent?ue:ge,u=new URL(`${a}/${encodeURIComponent(o)}`);u.search=x({access_token:this.accessToken,language:s.language,limit:s.limit},s.types&&{types:typeof s.types=="string"?s.types:[...s.types].join(",")});let{fetch:i}=R(),m=yield i(u.toString(),{signal:s.signal});return yield k(m),yield m.json()})}};U=new WeakSet,he=function(e){return x({access_token:this.accessToken,language:e.language,country:e.country,limit:e.limit,navigation_profile:e.navigation_profile,eta_type:e.eta_type},e.sessionToken&&{session_token:f.convert(e.sessionToken).id},e.origin&&{origin:typeof e.origin=="string"?e.origin:g.convert(e.origin).toArray().join(",")},e.proximity&&{proximity:typeof e.proximity=="string"?e.proximity:g.convert(e.proximity).toArray().join(",")},e.bbox&&{bbox:typeof e.bbox=="string"?e.bbox:S.convert(e.bbox).toFlatArray().join(",")},e.types&&{types:typeof e.types=="string"?e.types:[...e.types].join(",")})},q=new WeakSet,Ie=function(e){if(!this.canRetrieve(e)&&!this.canSuggest(e))throw new Error("Suggestion cannot be retrieved or suggested");let t=e.action,r=JSON.stringify(t.body);return{method:t.method,body:r,headers:{"Content-Type":"application/json","Content-Length":r.length.toString()}}};var pe="https://api.mapbox.com/autofill/v1",je="suggest",$e="retrieve",Se=`${pe}/${je}`,de=`${pe}/${$e}`;var F,be,H=class{constructor(e={}){h(this,F);this.defaults={language:"en",proximity:"ip"};let s=e,{accessToken:t}=s,r=j(s,["accessToken"]);this.accessToken=t,Object.assign(this.defaults,r)}suggest(e,t){return p(this,null,function*(){if(!e)throw new Error("searchText is required");if(!this.accessToken)throw new Error("accessToken is required");if(!t||!t.sessionToken)throw new Error("sessionToken is required");let{sessionToken:r,signal:s}=t,o=d(c(c({},this.defaults),t),{sessionToken:r}),a=new URL(`${Se}/${encodeURIComponent(e)}`);a.search=L(this,F,be).call(this,o);let{fetch:u}=R(),i=yield u(a.toString(),{signal:s});yield k(i);let m=yield i.json();return d(c({},m),{suggestions:m.suggestions.map(A=>d(c({},A),{original_search_text:e}))})})}retrieve(e,t){return p(this,null,function*(){if(!e)throw new Error("suggestion is required");if(!this.accessToken)throw new Error("accessToken is required");if(!t||!t.sessionToken)throw new Error("sessionToken is required");let{sessionToken:r,signal:s}=t,o=d(c(c({},this.defaults),t),{sessionToken:r}),a=typeof e!="string",u=a?e.original_search_text:e,i=new URL(`${de}/${encodeURIComponent(u)}`);i.search=L(this,F,be).call(this,o);let{fetch:m}=R(),A=yield m(i.toString(),{signal:s});yield k(A);let D=yield A.json();return a?d(c({},D),{features:D.features.filter(Te=>Te.properties.full_address===e.full_address)}):D})}};F=new WeakSet,be=function(e){return x({access_token:this.accessToken,language:e.language,country:e.country,limit:e.limit},e.sessionToken&&{session_token:f.convert(e.sessionToken).id},e.proximity&&{proximity:typeof e.proximity=="string"?e.proximity:g.convert(e.proximity).toArray().join(",")},e.bbox&&{bbox:typeof e.bbox=="string"?e.bbox:S.convert(e.bbox).toFlatArray().join(",")})};var O,Q=class{constructor(){h(this,O,{})}addEventListener(e,t){let r=l(this,O);r[e]||(r[e]=[]),r[e].push(t)}removeEventListener(e,t){let r=l(this,O);if(!r[e])return;let s=r[e],o=s.indexOf(t);o!==-1&&s.splice(o,1)}fire(e,t){let r=l(this,O);if(!r[e])return;let s=r[e];for(let o of s)o(t)}};O=new WeakMap;function Re(n,e,t){let r=null;return(...s)=>{r!==null&&clearTimeout(r);let o=t&&t();r=setTimeout(()=>{r=null,!(o==null?void 0:o.aborted)&&n(...s)},e)}}var qe=50;function J(){let{AbortController:n}=R();return new n}var y,w,C,Ce,v,T,N,X=class extends Q{constructor(e,t=0){super();h(this,C);h(this,y,new f);h(this,w,0);h(this,v,void 0);h(this,T,J());h(this,N,void 0);b(this,N,Re((o,...a)=>p(this,[o,...a],function*(r,s={}){if(l(this,T).abort(),b(this,T,J()),!r){b(this,v,null),this.fire("suggest",l(this,v));return}let u=L(this,C,Ce).call(this);try{let i=yield this.search.suggest(r,d(c({sessionToken:u},s),{signal:l(this,T).signal}));b(this,v,i),this.fire("suggest",i)}catch(i){if(i.name==="AbortError")return;this.fire("suggesterror",i)}}),t,()=>l(this,T).signal)),Object.defineProperties(this,{search:{value:e,writable:!1},debounce:{value:t,writable:!1}})}get suggestions(){return l(this,v)}suggest(e,t){return l(this,N).call(this,e,t),new Promise((r,s)=>{let o,a;o=u=>{this.removeEventListener("suggest",o),this.removeEventListener("suggesterror",a),r(u)},a=u=>{this.removeEventListener("suggest",o),this.removeEventListener("suggesterror",a),s(u)},this.addEventListener("suggest",o),this.addEventListener("suggesterror",a)})}clear(){this.suggest("")}retrieve(e){return p(this,null,function*(){let t=yield this.search.retrieve(e,{sessionToken:l(this,y)});return b(this,y,new f),b(this,w,0),this.fire("retrieve",t),t})}canRetrieve(e){return this.search.canRetrieve?this.search.canRetrieve(e):!0}canSuggest(e){return this.search.canSuggest?this.search.canSuggest(e):!0}abort(){l(this,T).abort(),b(this,T,J())}};y=new WeakMap,w=new WeakMap,C=new WeakSet,Ce=function(){return(l(this,y).isExpired()||l(this,w)>=qe)&&(b(this,y,new f),b(this,w,0)),te(this,w)._++,l(this,y)},v=new WeakMap,T=new WeakMap,N=new WeakMap;function Le(n){let{properties:e}=n;return c({},e)}module.exports=_e(De);
var ve=Object.create;var _=Object.defineProperty,we=Object.defineProperties,Ee=Object.getOwnPropertyDescriptor,xe=Object.getOwnPropertyDescriptors,Oe=Object.getOwnPropertyNames,$=Object.getOwnPropertySymbols,Ae=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty,ee=Object.prototype.propertyIsEnumerable;var Z=(n,e,t)=>e in n?_(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,a=(n,e)=>{for(var t in e||(e={}))K.call(e,t)&&Z(n,t,e[t]);if($)for(var t of $(e))ee.call(e,t)&&Z(n,t,e[t]);return n},S=(n,e)=>we(n,xe(e)),te=n=>_(n,"__esModule",{value:!0});var j=(n,e)=>{var t={};for(var s in n)K.call(n,s)&&e.indexOf(s)<0&&(t[s]=n[s]);if(n!=null&&$)for(var s of $(n))e.indexOf(s)<0&&ee.call(n,s)&&(t[s]=n[s]);return t};var _e=(n,e)=>{for(var t in e)_(n,t,{get:e[t],enumerable:!0})},ne=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Oe(e))!K.call(n,r)&&(t||r!=="default")&&_(n,r,{get:()=>e[r],enumerable:!(s=Ee(e,r))||s.enumerable});return n},Pe=(n,e)=>ne(te(_(n!=null?ve(Ae(n)):{},"default",!e&&n&&n.__esModule?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n),Ue=(n=>(e,t)=>n&&n.get(e)||(t=ne(te({}),e,1),n&&n.set(e,t),t))(typeof WeakMap!="undefined"?new WeakMap:0);var W=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var l=(n,e,t)=>(W(n,e,"read from private field"),t?t.call(n):e.get(n)),h=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)},R=(n,e,t,s)=>(W(n,e,"write to private field"),s?s.call(n,t):e.set(n,t),t),se=(n,e,t,s)=>({set _(r){R(n,e,r,t)},get _(){return l(n,e,s)}}),L=(n,e,t)=>(W(n,e,"access private method"),t);var p=(n,e,t)=>new Promise((s,r)=>{var o=i=>{try{c(t.next(i))}catch(m){r(m)}},g=i=>{try{c(t.throw(i))}catch(m){r(m)}},c=i=>i.done?s(i.value):Promise.resolve(i.value).then(o,g);c((t=t.apply(n,e)).next())});var Ge={};_e(Ge,{Evented:()=>N,LngLat:()=>u,LngLatBounds:()=>d,MapboxAutofill:()=>V,MapboxError:()=>q,MapboxSearch:()=>C,SearchSession:()=>z,SessionToken:()=>f,featureToSuggestion:()=>ke,polyfillFetch:()=>Q});var E="https://api.mapbox.com/search/v1",M="suggest",H="retrieve",re="forward",oe="reverse",ie=`${E}/${M}`,ae=`${E}/${H}`,ge=`${E}/${re}`,ue=`${E}/permanent/${re}`,ce=`${E}/${oe}`,le=`${E}/permanent/${oe}`;var u=class{constructor(e,t){if(isNaN(e)||isNaN(t))throw new Error(`Invalid LngLat object: (${e}, ${t})`);if(this.lng=+e,this.lat=+t,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(e){if(e instanceof u)return new u(e.lng,e.lat);if(Array.isArray(e)&&e.length===2)return new u(Number(e[0]),Number(e[1]));if(!Array.isArray(e)&&typeof e=="object"&&e!==null&&("lng"in e||"lon"in e)&&"lat"in e)return new u(Number("lng"in e?e.lng:e.lon),Number(e.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>]")}};var d=class{constructor(e,t){this._sw=u.convert(e),this._ne=u.convert(t)}getSouthWest(){return this._sw}getNorthEast(){return this._ne}getNorthWest(){return new u(this.getWest(),this.getNorth())}getSouthEast(){return new u(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(e){if(!e)throw new Error("Invalid LngLatBounds convert value: falsy");if(e instanceof d)return new d(e.getSouthWest(),e.getNorthEast());if(Array.isArray(e)&&e.length===2)return new d(u.convert(e[0]),u.convert(e[1]));if(Array.isArray(e)&&e.length===4)return new d(u.convert([e[0],e[1]]),u.convert([e[2],e[3]]));throw new Error("`LngLatBoundsLike` argument must be specified as an array [<LngLatLike>, <LngLatLike>] or an array [<west>, <south>, <east>, <north>]")}};var fe=Pe(require("polyfill-crypto.getrandomvalues"));function Fe(n){return typeof globalThis.crypto=="undefined"||typeof globalThis.crypto.getRandomValues!="function"?(0,fe.default)(n):globalThis.crypto.getRandomValues(n)}function Ne(n){let e=[...n].map(t=>{let s=t.toString(16);return t<16?"0"+s:s});return[...e.slice(0,4),"-",...e.slice(4,6),"-",...e.slice(6,8),"-",...e.slice(8,10),"-",...e.slice(10,16)].join("")}function me(){let n=Fe(new Uint8Array(16));return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Ne(n)}var Ie=60*60*1e3,f=class{constructor(e,t=Date.now()){this.id=e!=null?e:me(),this.ts=t}toString(){return this.id}static convert(e){return new f(e instanceof f?e.id:e.toString(),e instanceof f?e.ts:Date.now())}isExpired(){return Date.now()-this.ts>Ie}};var $e="Unknown error",q=class extends Error{constructor(e,t){super(String(e.message||e.error||$e));this.name="MapboxError",this.statusCode=t}toString(){return`${this.name} (${this.statusCode}): ${this.message}`}};function k(n){return p(this,null,function*(){if(!n.ok){let e=yield n.json();throw new q(e,n.status)}})}var P=globalThis.fetch,pe=globalThis.AbortController;function Q({fetch:n,AbortController:e},t=!1){if(!n)throw new Error("Fetch implementation must include implementations of `fetch`.");P&&!t||(P=n,pe=e)}function b(){if(!P)throw new Error("Fetch implementation not found. Please use `polyfillFetch` from `@mapbox/search-js-core` to fix this issue.");return{fetch:P,AbortController:pe}}function he(n,e){return n(e)}if(!P&&!0&&process.versions.node){let{default:n}=he(require,"node-fetch"),e=he(require,"abort-controller");Q({fetch:n,AbortController:e})}function x(...n){let e=[];for(let t of n){if(!t)continue;let s=Object.entries(t);for(let[r,o]of s)o!=null&&e.push(`${r}=${encodeURIComponent(String(o))}`)}return e.join("&")}var U,de,D,je,J=class{constructor(e={}){h(this,U);h(this,D);let r=e,{accessToken:t}=r,s=j(r,["accessToken"]);this.accessToken=t,this.defaults=a(a({},J.defaults),s)}suggest(e,t){return p(this,null,function*(){if(!e)throw new Error("searchText is required");if(!this.accessToken)throw new Error("accessToken is required");if(!t||!t.sessionToken)throw new Error("sessionToken is required");let{sessionToken:s,signal:r}=t,o=S(a(a({},this.defaults),t),{sessionToken:s});if(o.eta_type&&(!o.origin||!o.navigation_profile))throw new Error("to provide eta estimate: eta, navigation_profile, and origin are required");if(o.origin&&!o.navigation_profile)throw new Error("to provide distance estimate: both navigation_profile and origin are required");let g=new URL(`${ie}/${encodeURIComponent(e)}`);g.search=L(this,U,de).call(this,o);let{fetch:c}=b(),i=yield c(g.toString(),{signal:r});return yield k(i),yield i.json()})}retrieve(e,t){return p(this,null,function*(){if(!e)throw new Error("suggestion is required");if(!this.accessToken)throw new Error("accessToken is required");if(!this.canRetrieve(e))throw new Error("suggestion cannot be retrieved");if(!t||!t.sessionToken)throw new Error("sessionToken is required");let{sessionToken:s,signal:r}=t,o=f.convert(s),g=new URL(ae);g.search=x({access_token:this.accessToken,session_token:o.id});let{fetch:c}=b(),i=yield c(g.toString(),S(a({},L(this,D,je).call(this,e)),{signal:r}));return yield k(i),yield i.json()})}canRetrieve(e){let t=e.action;return t?t.method==="POST"&&t.endpoint===H:!1}canSuggest(e){let t=e.action;return t?t.method==="POST"&&t.endpoint===M:!1}forward(s){return p(this,arguments,function*(e,t={}){if(!e)throw new Error("searchText is required");if(!this.accessToken)throw new Error("accessToken is required");let r=a(a({},this.defaults),t),o=r.permanent?ue:ge,g=new URL(`${o}/${encodeURIComponent(e)}`);g.search=L(this,U,de).call(this,r);let{fetch:c}=b(),i=yield c(g.toString(),{signal:r.signal});return yield k(i),yield i.json()})}reverse(s){return p(this,arguments,function*(e,t={}){if(!e)throw new Error("lngLat is required");if(!this.accessToken)throw new Error("accessToken is required");let r=a(a({},this.defaults),t),o=typeof e=="string"?e:u.convert(e).toArray().join(","),g=r.permanent?le:ce,c=new URL(`${g}/${encodeURIComponent(o)}`);c.search=x({access_token:this.accessToken,language:r.language,limit:r.limit},r.types&&{types:typeof r.types=="string"?r.types:[...r.types].join(",")});let{fetch:i}=b(),m=yield i(c.toString(),{signal:r.signal});return yield k(m),yield m.json()})}},C=J;U=new WeakSet,de=function(e){return x({access_token:this.accessToken,language:e.language,country:e.country,limit:e.limit,navigation_profile:e.navigation_profile,eta_type:e.eta_type},e.sessionToken&&{session_token:f.convert(e.sessionToken).id},e.origin&&{origin:typeof e.origin=="string"?e.origin:u.convert(e.origin).toArray().join(",")},e.proximity&&{proximity:typeof e.proximity=="string"?e.proximity:u.convert(e.proximity).toArray().join(",")},e.bbox&&{bbox:typeof e.bbox=="string"?e.bbox:d.convert(e.bbox).toFlatArray().join(",")},e.types&&{types:typeof e.types=="string"?e.types:[...e.types].join(",")})},D=new WeakSet,je=function(e){if(!this.canRetrieve(e)&&!this.canSuggest(e))throw new Error("Suggestion cannot be retrieved or suggested");let t=e.action,s=JSON.stringify(t.body);return{method:t.method,body:s,headers:{"Content-Type":"application/json","Content-Length":s.length.toString()}}},C.defaults={language:"en"};var Se="https://api.mapbox.com/autofill/v1",qe="suggest",Ce="retrieve",Re=`${Se}/${qe}`,be=`${Se}/${Ce}`;var F,Le,X=class{constructor(e={}){h(this,F);let r=e,{accessToken:t}=r,s=j(r,["accessToken"]);this.accessToken=t,this.defaults=a(a({},X.defaults),s)}suggest(e,t){return p(this,null,function*(){if(!e)throw new Error("searchText is required");if(!this.accessToken)throw new Error("accessToken is required");if(!t||!t.sessionToken)throw new Error("sessionToken is required");let{sessionToken:s,signal:r}=t,o=S(a(a({},this.defaults),t),{sessionToken:s}),g=new URL(`${Re}/${encodeURIComponent(e)}`);g.search=L(this,F,Le).call(this,o);let{fetch:c}=b(),i=yield c(g.toString(),{signal:r});yield k(i);let m=yield i.json();return S(a({},m),{suggestions:m.suggestions.map(A=>S(a({},A),{original_search_text:e}))})})}retrieve(e,t){return p(this,null,function*(){if(!e)throw new Error("suggestion is required");if(!this.accessToken)throw new Error("accessToken is required");if(!t||!t.sessionToken)throw new Error("sessionToken is required");let{sessionToken:s,signal:r}=t,o=S(a(a({},this.defaults),t),{sessionToken:s}),g=typeof e!="string",c=g?e.original_search_text:e,i=new URL(`${be}/${encodeURIComponent(c)}`);i.search=L(this,F,Le).call(this,o);let{fetch:m}=b(),A=yield m(i.toString(),{signal:r});yield k(A);let B=yield A.json();return g?S(a({},B),{features:B.features.filter(ye=>ye.properties.full_address===e.full_address)}):B})}},V=X;F=new WeakSet,Le=function(e){return x({access_token:this.accessToken,language:e.language,country:e.country,limit:e.limit},e.sessionToken&&{session_token:f.convert(e.sessionToken).id},e.proximity&&{proximity:typeof e.proximity=="string"?e.proximity:u.convert(e.proximity).toArray().join(",")},e.bbox&&{bbox:typeof e.bbox=="string"?e.bbox:d.convert(e.bbox).toFlatArray().join(",")})},V.defaults={language:"en",proximity:"ip"};var O,N=class{constructor(){h(this,O,{})}addEventListener(e,t){let s=l(this,O);s[e]||(s[e]=[]),s[e].push(t)}removeEventListener(e,t){let s=l(this,O);if(!s[e])return;let r=s[e],o=r.indexOf(t);o!==-1&&r.splice(o,1)}fire(e,t){let s=l(this,O);if(!s[e])return;let r=s[e];for(let o of r)o(t)}};O=new WeakMap;function Te(n,e,t){let s=null;return(...r)=>{s!==null&&clearTimeout(s);let o=t&&t();s=setTimeout(()=>{s=null,!(o==null?void 0:o.aborted)&&n(...r)},e)}}var De=50;function Y(){let{AbortController:n}=b();return new n}var y,v,G,Ve,w,T,I,z=class extends N{constructor(e,t=0){super();h(this,G);h(this,y,new f);h(this,v,0);h(this,w,void 0);h(this,T,Y());h(this,I,void 0);R(this,I,Te((o,...g)=>p(this,[o,...g],function*(s,r={}){if(l(this,T).abort(),R(this,T,Y()),!s){R(this,w,null),this.fire("suggest",l(this,w));return}let c=L(this,G,Ve).call(this);try{let i=yield this.search.suggest(s,S(a({sessionToken:c},r),{signal:l(this,T).signal}));R(this,w,i),this.fire("suggest",i)}catch(i){if(i.name==="AbortError")return;this.fire("suggesterror",i)}}),t,()=>l(this,T).signal)),Object.defineProperties(this,{search:{value:e,writable:!1},debounce:{value:t,writable:!1}})}get suggestions(){return l(this,w)}suggest(e,t){return l(this,I).call(this,e,t),new Promise((s,r)=>{let o,g;o=c=>{this.removeEventListener("suggest",o),this.removeEventListener("suggesterror",g),s(c)},g=c=>{this.removeEventListener("suggest",o),this.removeEventListener("suggesterror",g),r(c)},this.addEventListener("suggest",o),this.addEventListener("suggesterror",g)})}clear(){this.suggest("")}retrieve(e){return p(this,null,function*(){let t=yield this.search.retrieve(e,{sessionToken:l(this,y)});return R(this,y,new f),R(this,v,0),this.fire("retrieve",t),t})}canRetrieve(e){return this.search.canRetrieve?this.search.canRetrieve(e):!0}canSuggest(e){return this.search.canSuggest?this.search.canSuggest(e):!0}abort(){l(this,T).abort(),R(this,T,Y())}};y=new WeakMap,v=new WeakMap,G=new WeakSet,Ve=function(){return(l(this,y).isExpired()||l(this,v)>=De)&&(R(this,y,new f),R(this,v,0)),se(this,v)._++,l(this,y)},w=new WeakMap,T=new WeakMap,I=new WeakMap;function ke(n){let{properties:e}=n;return a({},e)}module.exports=Ue(Ge);
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

var mapboxsearchcore=(()=>{var Ae=Object.create;var N=Object.defineProperty,Oe=Object.defineProperties,Ne=Object.getOwnPropertyDescriptor,Pe=Object.getOwnPropertyDescriptors,Ue=Object.getOwnPropertyNames,j=Object.getOwnPropertySymbols,Fe=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty,ee=Object.prototype.propertyIsEnumerable;var Z=(n,e,t)=>e in n?N(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,c=(n,e)=>{for(var t in e||(e={}))K.call(e,t)&&Z(n,t,e[t]);if(j)for(var t of j(e))ee.call(e,t)&&Z(n,t,e[t]);return n},S=(n,e)=>Oe(n,Pe(e)),te=n=>N(n,"__esModule",{value:!0});var V=(n=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(n,{get:(e,t)=>(typeof require!="undefined"?require:e)[t]}):n)(function(n){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+n+'" is not supported')});var $=(n,e)=>{var t={};for(var s in n)K.call(n,s)&&e.indexOf(s)<0&&(t[s]=n[s]);if(n!=null&&j)for(var s of j(n))e.indexOf(s)<0&&ee.call(n,s)&&(t[s]=n[s]);return t};var ne=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Ie=(n,e)=>{for(var t in e)N(n,t,{get:e[t],enumerable:!0})},se=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ue(e))!K.call(n,r)&&(t||r!=="default")&&N(n,r,{get:()=>e[r],enumerable:!(s=Ne(e,r))||s.enumerable});return n},je=(n,e)=>se(te(N(n!=null?Ae(Fe(n)):{},"default",!e&&n&&n.__esModule?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n),$e=(n=>(e,t)=>n&&n.get(e)||(t=se(te({}),e,1),n&&n.set(e,t),t))(typeof WeakMap!="undefined"?new WeakMap:0);var G=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var l=(n,e,t)=>(G(n,e,"read from private field"),t?t.call(n):e.get(n)),m=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)},R=(n,e,t,s)=>(G(n,e,"write to private field"),s?s.call(n,t):e.set(n,t),t),re=(n,e,t,s)=>({set _(r){R(n,e,r,t)},get _(){return l(n,e,s)}}),L=(n,e,t)=>(G(n,e,"access private method"),t);var p=(n,e,t)=>new Promise((s,r)=>{var i=o=>{try{u(t.next(o))}catch(f){r(f)}},a=o=>{try{u(t.throw(o))}catch(f){r(f)}},u=o=>o.done?s(o.value):Promise.resolve(o.value).then(i,a);u((t=t.apply(n,e)).next())});var me=ne((rt,fe)=>{var T=function(n){n==null&&(n=new Date().getTime()),this.N=624,this.M=397,this.MATRIX_A=2567483615,this.UPPER_MASK=2147483648,this.LOWER_MASK=2147483647,this.mt=new Array(this.N),this.mti=this.N+1,n.constructor==Array?this.init_by_array(n,n.length):this.init_seed(n)};T.prototype.init_seed=function(n){for(this.mt[0]=n>>>0,this.mti=1;this.mti<this.N;this.mti++){var n=this.mt[this.mti-1]^this.mt[this.mti-1]>>>30;this.mt[this.mti]=(((n&4294901760)>>>16)*1812433253<<16)+(n&65535)*1812433253+this.mti,this.mt[this.mti]>>>=0}};T.prototype.init_by_array=function(n,e){var t,s,r;for(this.init_seed(19650218),t=1,s=0,r=this.N>e?this.N:e;r;r--){var i=this.mt[t-1]^this.mt[t-1]>>>30;this.mt[t]=(this.mt[t]^(((i&4294901760)>>>16)*1664525<<16)+(i&65535)*1664525)+n[s]+s,this.mt[t]>>>=0,t++,s++,t>=this.N&&(this.mt[0]=this.mt[this.N-1],t=1),s>=e&&(s=0)}for(r=this.N-1;r;r--){var i=this.mt[t-1]^this.mt[t-1]>>>30;this.mt[t]=(this.mt[t]^(((i&4294901760)>>>16)*1566083941<<16)+(i&65535)*1566083941)-t,this.mt[t]>>>=0,t++,t>=this.N&&(this.mt[0]=this.mt[this.N-1],t=1)}this.mt[0]=2147483648};T.prototype.random_int=function(){var n,e=new Array(0,this.MATRIX_A);if(this.mti>=this.N){var t;for(this.mti==this.N+1&&this.init_seed(5489),t=0;t<this.N-this.M;t++)n=this.mt[t]&this.UPPER_MASK|this.mt[t+1]&this.LOWER_MASK,this.mt[t]=this.mt[t+this.M]^n>>>1^e[n&1];for(;t<this.N-1;t++)n=this.mt[t]&this.UPPER_MASK|this.mt[t+1]&this.LOWER_MASK,this.mt[t]=this.mt[t+(this.M-this.N)]^n>>>1^e[n&1];n=this.mt[this.N-1]&this.UPPER_MASK|this.mt[0]&this.LOWER_MASK,this.mt[this.N-1]=this.mt[this.M-1]^n>>>1^e[n&1],this.mti=0}return n=this.mt[this.mti++],n^=n>>>11,n^=n<<7&2636928640,n^=n<<15&4022730752,n^=n>>>18,n>>>0};T.prototype.random_int31=function(){return this.random_int()>>>1};T.prototype.random_incl=function(){return this.random_int()*(1/4294967295)};T.prototype.random=function(){return this.random_int()*(1/4294967296)};T.prototype.random_excl=function(){return(this.random_int()+.5)*(1/4294967296)};T.prototype.random_long=function(){var n=this.random_int()>>>5,e=this.random_int()>>>6;return(n*67108864+e)*(1/9007199254740992)};fe.exports=T});var de=ne((it,pe)=>{var Me=me(),qe=new Me(Math.random()*Number.MAX_SAFE_INTEGER);pe.exports=Ce;function Ce(n){for(var e=n.length;e--;)n[e]=Math.floor(De()*256);return n}function De(){return qe.random()}});var Ye={};Ie(Ye,{LngLat:()=>g,LngLatBounds:()=>d,MapboxAutofill:()=>Q,MapboxError:()=>M,MapboxSearch:()=>H,SearchSession:()=>z,SessionToken:()=>h,featureToSuggestion:()=>ke,polyfillFetch:()=>X});var k="https://api.mapbox.com/search/v1",W="suggest",B="retrieve",ie="forward",oe="reverse",ae=`${k}/${W}`,ge=`${k}/${B}`,ue=`${k}/${ie}`,ce=`${k}/permanent/${ie}`,le=`${k}/${oe}`,he=`${k}/permanent/${oe}`;var g=class{constructor(e,t){if(isNaN(e)||isNaN(t))throw new Error(`Invalid LngLat object: (${e}, ${t})`);if(this.lng=+e,this.lat=+t,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(e){if(e instanceof g)return new g(e.lng,e.lat);if(Array.isArray(e)&&e.length===2)return new g(Number(e[0]),Number(e[1]));if(!Array.isArray(e)&&typeof e=="object"&&e!==null&&("lng"in e||"lon"in e)&&"lat"in e)return new g(Number("lng"in e?e.lng:e.lon),Number(e.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>]")}};var d=class{constructor(e,t){this._sw=g.convert(e),this._ne=g.convert(t)}getSouthWest(){return this._sw}getNorthEast(){return this._ne}getNorthWest(){return new g(this.getWest(),this.getNorth())}getSouthEast(){return new g(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(e){if(!e)throw new Error("Invalid LngLatBounds convert value: falsy");if(e instanceof d)return new d(e.getSouthWest(),e.getNorthEast());if(Array.isArray(e)&&e.length===2)return new d(g.convert(e[0]),g.convert(e[1]));if(Array.isArray(e)&&e.length===4)return new d(g.convert([e[0],e[1]]),g.convert([e[2],e[3]]));throw new Error("`LngLatBoundsLike` argument must be specified as an array [<LngLatLike>, <LngLatLike>] or an array [<west>, <south>, <east>, <north>]")}};var Se=je(de());function Ke(n){return typeof globalThis.crypto=="undefined"||typeof globalThis.crypto.getRandomValues!="function"?(0,Se.default)(n):globalThis.crypto.getRandomValues(n)}function Ve(n){let e=[...n].map(t=>{let s=t.toString(16);return t<16?"0"+s:s});return[...e.slice(0,4),"-",...e.slice(4,6),"-",...e.slice(6,8),"-",...e.slice(8,10),"-",...e.slice(10,16)].join("")}function Re(){let n=Ke(new Uint8Array(16));return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Ve(n)}var Ge=60*60*1e3,h=class{constructor(e,t=Date.now()){this.id=e!=null?e:Re(),this.ts=t}toString(){return this.id}static convert(e){return new h(e instanceof h?e.id:e.toString(),e instanceof h?e.ts:Date.now())}isExpired(){return Date.now()-this.ts>Ge}};var We="Unknown error",M=class extends Error{constructor(e,t){super(String(e.message||e.error||We));this.name="MapboxError",this.statusCode=t}toString(){return`${this.name} (${this.statusCode}): ${this.message}`}};function v(n){return p(this,null,function*(){if(!n.ok){let e=yield n.json();throw new M(e,n.status)}})}var P=globalThis.fetch,Le=globalThis.AbortController;function X({fetch:n,AbortController:e},t=!1){if(!n)throw new Error("Fetch implementation must include implementations of `fetch`.");P&&!t||(P=n,Le=e)}function b(){if(!P)throw new Error("Fetch implementation not found. Please use `polyfillFetch` from `@mapbox/search-js-core` to fix this issue.");return{fetch:P,AbortController:Le}}function be(n,e){return n(e)}if(!P&&!0&&process.versions.node){let{default:n}=be(V,"node-fetch"),e=be(V,"abort-controller");X({fetch:n,AbortController:e})}function _(...n){let e=[];for(let t of n){if(!t)continue;let s=Object.entries(t);for(let[r,i]of s)i!=null&&e.push(`${r}=${encodeURIComponent(String(i))}`)}return e.join("&")}var U,Te,q,Be,H=class{constructor(e={}){m(this,U);m(this,q);this.defaults={language:"en"};let r=e,{accessToken:t}=r,s=$(r,["accessToken"]);this.accessToken=t,Object.assign(this.defaults,s)}suggest(e,t){return p(this,null,function*(){if(!e)throw new Error("searchText is required");if(!this.accessToken)throw new Error("accessToken is required");if(!t||!t.sessionToken)throw new Error("sessionToken is required");let{sessionToken:s,signal:r}=t,i=S(c(c({},this.defaults),t),{sessionToken:s});if(i.eta_type&&(!i.origin||!i.navigation_profile))throw new Error("to provide eta estimate: eta, navigation_profile, and origin are required");if(i.origin&&!i.navigation_profile)throw new Error("to provide distance estimate: both navigation_profile and origin are required");let a=new URL(`${ae}/${encodeURIComponent(e)}`);a.search=L(this,U,Te).call(this,i);let{fetch:u}=b(),o=yield u(a.toString(),{signal:r});return yield v(o),yield o.json()})}retrieve(e,t){return p(this,null,function*(){if(!e)throw new Error("suggestion is required");if(!this.accessToken)throw new Error("accessToken is required");if(!this.canRetrieve(e))throw new Error("suggestion cannot be retrieved");if(!t||!t.sessionToken)throw new Error("sessionToken is required");let{sessionToken:s,signal:r}=t,i=h.convert(s),a=new URL(ge);a.search=_({access_token:this.accessToken,session_token:i.id});let{fetch:u}=b(),o=yield u(a.toString(),S(c({},L(this,q,Be).call(this,e)),{signal:r}));return yield v(o),yield o.json()})}canRetrieve(e){let t=e.action;return t?t.method==="POST"&&t.endpoint===B:!1}canSuggest(e){let t=e.action;return t?t.method==="POST"&&t.endpoint===W:!1}forward(s){return p(this,arguments,function*(e,t={}){if(!e)throw new Error("searchText is required");if(!this.accessToken)throw new Error("accessToken is required");let r=c(c({},this.defaults),t),i=r.permanent?ce:ue,a=new URL(`${i}/${encodeURIComponent(e)}`);a.search=L(this,U,Te).call(this,r);let{fetch:u}=b(),o=yield u(a.toString(),{signal:r.signal});return yield v(o),yield o.json()})}reverse(s){return p(this,arguments,function*(e,t={}){if(!e)throw new Error("lngLat is required");if(!this.accessToken)throw new Error("accessToken is required");let r=c(c({},this.defaults),t),i=typeof e=="string"?e:g.convert(e).toArray().join(","),a=r.permanent?he:le,u=new URL(`${a}/${encodeURIComponent(i)}`);u.search=_({access_token:this.accessToken,language:r.language,limit:r.limit},r.types&&{types:typeof r.types=="string"?r.types:[...r.types].join(",")});let{fetch:o}=b(),f=yield o(u.toString(),{signal:r.signal});return yield v(f),yield f.json()})}};U=new WeakSet,Te=function(e){return _({access_token:this.accessToken,language:e.language,country:e.country,limit:e.limit,navigation_profile:e.navigation_profile,eta_type:e.eta_type},e.sessionToken&&{session_token:h.convert(e.sessionToken).id},e.origin&&{origin:typeof e.origin=="string"?e.origin:g.convert(e.origin).toArray().join(",")},e.proximity&&{proximity:typeof e.proximity=="string"?e.proximity:g.convert(e.proximity).toArray().join(",")},e.bbox&&{bbox:typeof e.bbox=="string"?e.bbox:d.convert(e.bbox).toFlatArray().join(",")},e.types&&{types:typeof e.types=="string"?e.types:[...e.types].join(",")})},q=new WeakSet,Be=function(e){if(!this.canRetrieve(e)&&!this.canSuggest(e))throw new Error("Suggestion cannot be retrieved or suggested");let t=e.action,s=JSON.stringify(t.body);return{method:t.method,body:s,headers:{"Content-Type":"application/json","Content-Length":s.length.toString()}}};var ye="https://api.mapbox.com/autofill/v1",Xe="suggest",He="retrieve",ve=`${ye}/${Xe}`,we=`${ye}/${He}`;var F,Ee,Q=class{constructor(e={}){m(this,F);this.defaults={language:"en",proximity:"ip"};let r=e,{accessToken:t}=r,s=$(r,["accessToken"]);this.accessToken=t,Object.assign(this.defaults,s)}suggest(e,t){return p(this,null,function*(){if(!e)throw new Error("searchText is required");if(!this.accessToken)throw new Error("accessToken is required");if(!t||!t.sessionToken)throw new Error("sessionToken is required");let{sessionToken:s,signal:r}=t,i=S(c(c({},this.defaults),t),{sessionToken:s}),a=new URL(`${ve}/${encodeURIComponent(e)}`);a.search=L(this,F,Ee).call(this,i);let{fetch:u}=b(),o=yield u(a.toString(),{signal:r});yield v(o);let f=yield o.json();return S(c({},f),{suggestions:f.suggestions.map(O=>S(c({},O),{original_search_text:e}))})})}retrieve(e,t){return p(this,null,function*(){if(!e)throw new Error("suggestion is required");if(!this.accessToken)throw new Error("accessToken is required");if(!t||!t.sessionToken)throw new Error("sessionToken is required");let{sessionToken:s,signal:r}=t,i=S(c(c({},this.defaults),t),{sessionToken:s}),a=typeof e!="string",u=a?e.original_search_text:e,o=new URL(`${we}/${encodeURIComponent(u)}`);o.search=L(this,F,Ee).call(this,i);let{fetch:f}=b(),O=yield f(o.toString(),{signal:r});yield v(O);let D=yield O.json();return a?S(c({},D),{features:D.features.filter(_e=>_e.properties.full_address===e.full_address)}):D})}};F=new WeakSet,Ee=function(e){return _({access_token:this.accessToken,language:e.language,country:e.country,limit:e.limit},e.sessionToken&&{session_token:h.convert(e.sessionToken).id},e.proximity&&{proximity:typeof e.proximity=="string"?e.proximity:g.convert(e.proximity).toArray().join(",")},e.bbox&&{bbox:typeof e.bbox=="string"?e.bbox:d.convert(e.bbox).toFlatArray().join(",")})};var A,J=class{constructor(){m(this,A,{})}addEventListener(e,t){let s=l(this,A);s[e]||(s[e]=[]),s[e].push(t)}removeEventListener(e,t){let s=l(this,A);if(!s[e])return;let r=s[e],i=r.indexOf(t);i!==-1&&r.splice(i,1)}fire(e,t){let s=l(this,A);if(!s[e])return;let r=s[e];for(let i of r)i(t)}};A=new WeakMap;function xe(n,e,t){let s=null;return(...r)=>{s!==null&&clearTimeout(s);let i=t&&t();s=setTimeout(()=>{s=null,!(i==null?void 0:i.aborted)&&n(...r)},e)}}var Qe=50;function Y(){let{AbortController:n}=b();return new n}var w,E,C,Je,x,y,I,z=class extends J{constructor(e,t=0){super();m(this,C);m(this,w,new h);m(this,E,0);m(this,x,void 0);m(this,y,Y());m(this,I,void 0);R(this,I,xe((i,...a)=>p(this,[i,...a],function*(s,r={}){if(l(this,y).abort(),R(this,y,Y()),!s){R(this,x,null),this.fire("suggest",l(this,x));return}let u=L(this,C,Je).call(this);try{let o=yield this.search.suggest(s,S(c({sessionToken:u},r),{signal:l(this,y).signal}));R(this,x,o),this.fire("suggest",o)}catch(o){if(o.name==="AbortError")return;this.fire("suggesterror",o)}}),t,()=>l(this,y).signal)),Object.defineProperties(this,{search:{value:e,writable:!1},debounce:{value:t,writable:!1}})}get suggestions(){return l(this,x)}suggest(e,t){return l(this,I).call(this,e,t),new Promise((s,r)=>{let i,a;i=u=>{this.removeEventListener("suggest",i),this.removeEventListener("suggesterror",a),s(u)},a=u=>{this.removeEventListener("suggest",i),this.removeEventListener("suggesterror",a),r(u)},this.addEventListener("suggest",i),this.addEventListener("suggesterror",a)})}clear(){this.suggest("")}retrieve(e){return p(this,null,function*(){let t=yield this.search.retrieve(e,{sessionToken:l(this,w)});return R(this,w,new h),R(this,E,0),this.fire("retrieve",t),t})}canRetrieve(e){return this.search.canRetrieve?this.search.canRetrieve(e):!0}canSuggest(e){return this.search.canSuggest?this.search.canSuggest(e):!0}abort(){l(this,y).abort(),R(this,y,Y())}};w=new WeakMap,E=new WeakMap,C=new WeakSet,Je=function(){return(l(this,w).isExpired()||l(this,E)>=Qe)&&(R(this,w,new h),R(this,E,0)),re(this,E)._++,l(this,w)},x=new WeakMap,y=new WeakMap,I=new WeakMap;function ke(n){let{properties:e}=n;return c({},e)}return $e(Ye);})();
var mapboxsearchcore=(()=>{var Pe=Object.create;var P=Object.defineProperty,Ne=Object.defineProperties,Ue=Object.getOwnPropertyDescriptor,Fe=Object.getOwnPropertyDescriptors,Ie=Object.getOwnPropertyNames,j=Object.getOwnPropertySymbols,$e=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty,ne=Object.prototype.propertyIsEnumerable;var te=(n,e,t)=>e in n?P(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,a=(n,e)=>{for(var t in e||(e={}))W.call(e,t)&&te(n,t,e[t]);if(j)for(var t of j(e))ne.call(e,t)&&te(n,t,e[t]);return n},R=(n,e)=>Ne(n,Fe(e)),se=n=>P(n,"__esModule",{value:!0});var B=(n=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(n,{get:(e,t)=>(typeof require!="undefined"?require:e)[t]}):n)(function(n){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+n+'" is not supported')});var q=(n,e)=>{var t={};for(var s in n)W.call(n,s)&&e.indexOf(s)<0&&(t[s]=n[s]);if(n!=null&&j)for(var s of j(n))e.indexOf(s)<0&&ne.call(n,s)&&(t[s]=n[s]);return t};var re=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),je=(n,e)=>{for(var t in e)P(n,t,{get:e[t],enumerable:!0})},ie=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ie(e))!W.call(n,r)&&(t||r!=="default")&&P(n,r,{get:()=>e[r],enumerable:!(s=Ue(e,r))||s.enumerable});return n},qe=(n,e)=>ie(se(P(n!=null?Pe($e(n)):{},"default",!e&&n&&n.__esModule?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n),Me=(n=>(e,t)=>n&&n.get(e)||(t=ie(se({}),e,1),n&&n.set(e,t),t))(typeof WeakMap!="undefined"?new WeakMap:0);var X=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var l=(n,e,t)=>(X(n,e,"read from private field"),t?t.call(n):e.get(n)),m=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)},S=(n,e,t,s)=>(X(n,e,"write to private field"),s?s.call(n,t):e.set(n,t),t),oe=(n,e,t,s)=>({set _(r){S(n,e,r,t)},get _(){return l(n,e,s)}}),b=(n,e,t)=>(X(n,e,"access private method"),t);var p=(n,e,t)=>new Promise((s,r)=>{var i=o=>{try{c(t.next(o))}catch(h){r(h)}},u=o=>{try{c(t.throw(o))}catch(h){r(h)}},c=o=>o.done?s(o.value):Promise.resolve(o.value).then(i,u);c((t=t.apply(n,e)).next())});var de=re((ot,pe)=>{var T=function(n){n==null&&(n=new Date().getTime()),this.N=624,this.M=397,this.MATRIX_A=2567483615,this.UPPER_MASK=2147483648,this.LOWER_MASK=2147483647,this.mt=new Array(this.N),this.mti=this.N+1,n.constructor==Array?this.init_by_array(n,n.length):this.init_seed(n)};T.prototype.init_seed=function(n){for(this.mt[0]=n>>>0,this.mti=1;this.mti<this.N;this.mti++){var n=this.mt[this.mti-1]^this.mt[this.mti-1]>>>30;this.mt[this.mti]=(((n&4294901760)>>>16)*1812433253<<16)+(n&65535)*1812433253+this.mti,this.mt[this.mti]>>>=0}};T.prototype.init_by_array=function(n,e){var t,s,r;for(this.init_seed(19650218),t=1,s=0,r=this.N>e?this.N:e;r;r--){var i=this.mt[t-1]^this.mt[t-1]>>>30;this.mt[t]=(this.mt[t]^(((i&4294901760)>>>16)*1664525<<16)+(i&65535)*1664525)+n[s]+s,this.mt[t]>>>=0,t++,s++,t>=this.N&&(this.mt[0]=this.mt[this.N-1],t=1),s>=e&&(s=0)}for(r=this.N-1;r;r--){var i=this.mt[t-1]^this.mt[t-1]>>>30;this.mt[t]=(this.mt[t]^(((i&4294901760)>>>16)*1566083941<<16)+(i&65535)*1566083941)-t,this.mt[t]>>>=0,t++,t>=this.N&&(this.mt[0]=this.mt[this.N-1],t=1)}this.mt[0]=2147483648};T.prototype.random_int=function(){var n,e=new Array(0,this.MATRIX_A);if(this.mti>=this.N){var t;for(this.mti==this.N+1&&this.init_seed(5489),t=0;t<this.N-this.M;t++)n=this.mt[t]&this.UPPER_MASK|this.mt[t+1]&this.LOWER_MASK,this.mt[t]=this.mt[t+this.M]^n>>>1^e[n&1];for(;t<this.N-1;t++)n=this.mt[t]&this.UPPER_MASK|this.mt[t+1]&this.LOWER_MASK,this.mt[t]=this.mt[t+(this.M-this.N)]^n>>>1^e[n&1];n=this.mt[this.N-1]&this.UPPER_MASK|this.mt[0]&this.LOWER_MASK,this.mt[this.N-1]=this.mt[this.M-1]^n>>>1^e[n&1],this.mti=0}return n=this.mt[this.mti++],n^=n>>>11,n^=n<<7&2636928640,n^=n<<15&4022730752,n^=n>>>18,n>>>0};T.prototype.random_int31=function(){return this.random_int()>>>1};T.prototype.random_incl=function(){return this.random_int()*(1/4294967295)};T.prototype.random=function(){return this.random_int()*(1/4294967296)};T.prototype.random_excl=function(){return(this.random_int()+.5)*(1/4294967296)};T.prototype.random_long=function(){var n=this.random_int()>>>5,e=this.random_int()>>>6;return(n*67108864+e)*(1/9007199254740992)};pe.exports=T});var Se=re((at,Re)=>{var Ce=de(),De=new Ce(Math.random()*Number.MAX_SAFE_INTEGER);Re.exports=Ke;function Ke(n){for(var e=n.length;e--;)n[e]=Math.floor(Ve()*256);return n}function Ve(){return De.random()}});var Ze={};je(Ze,{Evented:()=>I,LngLat:()=>g,LngLatBounds:()=>d,MapboxAutofill:()=>K,MapboxError:()=>M,MapboxSearch:()=>C,SearchSession:()=>ee,SessionToken:()=>f,featureToSuggestion:()=>Ae,polyfillFetch:()=>J});var k="https://api.mapbox.com/search/v1",H="suggest",Q="retrieve",ae="forward",ue="reverse",ge=`${k}/${H}`,ce=`${k}/${Q}`,le=`${k}/${ae}`,fe=`${k}/permanent/${ae}`,he=`${k}/${ue}`,me=`${k}/permanent/${ue}`;var g=class{constructor(e,t){if(isNaN(e)||isNaN(t))throw new Error(`Invalid LngLat object: (${e}, ${t})`);if(this.lng=+e,this.lat=+t,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(e){if(e instanceof g)return new g(e.lng,e.lat);if(Array.isArray(e)&&e.length===2)return new g(Number(e[0]),Number(e[1]));if(!Array.isArray(e)&&typeof e=="object"&&e!==null&&("lng"in e||"lon"in e)&&"lat"in e)return new g(Number("lng"in e?e.lng:e.lon),Number(e.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>]")}};var d=class{constructor(e,t){this._sw=g.convert(e),this._ne=g.convert(t)}getSouthWest(){return this._sw}getNorthEast(){return this._ne}getNorthWest(){return new g(this.getWest(),this.getNorth())}getSouthEast(){return new g(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(e){if(!e)throw new Error("Invalid LngLatBounds convert value: falsy");if(e instanceof d)return new d(e.getSouthWest(),e.getNorthEast());if(Array.isArray(e)&&e.length===2)return new d(g.convert(e[0]),g.convert(e[1]));if(Array.isArray(e)&&e.length===4)return new d(g.convert([e[0],e[1]]),g.convert([e[2],e[3]]));throw new Error("`LngLatBoundsLike` argument must be specified as an array [<LngLatLike>, <LngLatLike>] or an array [<west>, <south>, <east>, <north>]")}};var Le=qe(Se());function Ge(n){return typeof globalThis.crypto=="undefined"||typeof globalThis.crypto.getRandomValues!="function"?(0,Le.default)(n):globalThis.crypto.getRandomValues(n)}function We(n){let e=[...n].map(t=>{let s=t.toString(16);return t<16?"0"+s:s});return[...e.slice(0,4),"-",...e.slice(4,6),"-",...e.slice(6,8),"-",...e.slice(8,10),"-",...e.slice(10,16)].join("")}function be(){let n=Ge(new Uint8Array(16));return n[6]=n[6]&15|64,n[8]=n[8]&63|128,We(n)}var Be=60*60*1e3,f=class{constructor(e,t=Date.now()){this.id=e!=null?e:be(),this.ts=t}toString(){return this.id}static convert(e){return new f(e instanceof f?e.id:e.toString(),e instanceof f?e.ts:Date.now())}isExpired(){return Date.now()-this.ts>Be}};var Xe="Unknown error",M=class extends Error{constructor(e,t){super(String(e.message||e.error||Xe));this.name="MapboxError",this.statusCode=t}toString(){return`${this.name} (${this.statusCode}): ${this.message}`}};function v(n){return p(this,null,function*(){if(!n.ok){let e=yield n.json();throw new M(e,n.status)}})}var N=globalThis.fetch,ye=globalThis.AbortController;function J({fetch:n,AbortController:e},t=!1){if(!n)throw new Error("Fetch implementation must include implementations of `fetch`.");N&&!t||(N=n,ye=e)}function L(){if(!N)throw new Error("Fetch implementation not found. Please use `polyfillFetch` from `@mapbox/search-js-core` to fix this issue.");return{fetch:N,AbortController:ye}}function Te(n,e){return n(e)}if(!N&&!0&&process.versions.node){let{default:n}=Te(B,"node-fetch"),e=Te(B,"abort-controller");J({fetch:n,AbortController:e})}function _(...n){let e=[];for(let t of n){if(!t)continue;let s=Object.entries(t);for(let[r,i]of s)i!=null&&e.push(`${r}=${encodeURIComponent(String(i))}`)}return e.join("&")}var U,ve,D,He,Y=class{constructor(e={}){m(this,U);m(this,D);let r=e,{accessToken:t}=r,s=q(r,["accessToken"]);this.accessToken=t,this.defaults=a(a({},Y.defaults),s)}suggest(e,t){return p(this,null,function*(){if(!e)throw new Error("searchText is required");if(!this.accessToken)throw new Error("accessToken is required");if(!t||!t.sessionToken)throw new Error("sessionToken is required");let{sessionToken:s,signal:r}=t,i=R(a(a({},this.defaults),t),{sessionToken:s});if(i.eta_type&&(!i.origin||!i.navigation_profile))throw new Error("to provide eta estimate: eta, navigation_profile, and origin are required");if(i.origin&&!i.navigation_profile)throw new Error("to provide distance estimate: both navigation_profile and origin are required");let u=new URL(`${ge}/${encodeURIComponent(e)}`);u.search=b(this,U,ve).call(this,i);let{fetch:c}=L(),o=yield c(u.toString(),{signal:r});return yield v(o),yield o.json()})}retrieve(e,t){return p(this,null,function*(){if(!e)throw new Error("suggestion is required");if(!this.accessToken)throw new Error("accessToken is required");if(!this.canRetrieve(e))throw new Error("suggestion cannot be retrieved");if(!t||!t.sessionToken)throw new Error("sessionToken is required");let{sessionToken:s,signal:r}=t,i=f.convert(s),u=new URL(ce);u.search=_({access_token:this.accessToken,session_token:i.id});let{fetch:c}=L(),o=yield c(u.toString(),R(a({},b(this,D,He).call(this,e)),{signal:r}));return yield v(o),yield o.json()})}canRetrieve(e){let t=e.action;return t?t.method==="POST"&&t.endpoint===Q:!1}canSuggest(e){let t=e.action;return t?t.method==="POST"&&t.endpoint===H:!1}forward(s){return p(this,arguments,function*(e,t={}){if(!e)throw new Error("searchText is required");if(!this.accessToken)throw new Error("accessToken is required");let r=a(a({},this.defaults),t),i=r.permanent?fe:le,u=new URL(`${i}/${encodeURIComponent(e)}`);u.search=b(this,U,ve).call(this,r);let{fetch:c}=L(),o=yield c(u.toString(),{signal:r.signal});return yield v(o),yield o.json()})}reverse(s){return p(this,arguments,function*(e,t={}){if(!e)throw new Error("lngLat is required");if(!this.accessToken)throw new Error("accessToken is required");let r=a(a({},this.defaults),t),i=typeof e=="string"?e:g.convert(e).toArray().join(","),u=r.permanent?me:he,c=new URL(`${u}/${encodeURIComponent(i)}`);c.search=_({access_token:this.accessToken,language:r.language,limit:r.limit},r.types&&{types:typeof r.types=="string"?r.types:[...r.types].join(",")});let{fetch:o}=L(),h=yield o(c.toString(),{signal:r.signal});return yield v(h),yield h.json()})}},C=Y;U=new WeakSet,ve=function(e){return _({access_token:this.accessToken,language:e.language,country:e.country,limit:e.limit,navigation_profile:e.navigation_profile,eta_type:e.eta_type},e.sessionToken&&{session_token:f.convert(e.sessionToken).id},e.origin&&{origin:typeof e.origin=="string"?e.origin:g.convert(e.origin).toArray().join(",")},e.proximity&&{proximity:typeof e.proximity=="string"?e.proximity:g.convert(e.proximity).toArray().join(",")},e.bbox&&{bbox:typeof e.bbox=="string"?e.bbox:d.convert(e.bbox).toFlatArray().join(",")},e.types&&{types:typeof e.types=="string"?e.types:[...e.types].join(",")})},D=new WeakSet,He=function(e){if(!this.canRetrieve(e)&&!this.canSuggest(e))throw new Error("Suggestion cannot be retrieved or suggested");let t=e.action,s=JSON.stringify(t.body);return{method:t.method,body:s,headers:{"Content-Type":"application/json","Content-Length":s.length.toString()}}},C.defaults={language:"en"};var Ee="https://api.mapbox.com/autofill/v1",Qe="suggest",Je="retrieve",we=`${Ee}/${Qe}`,xe=`${Ee}/${Je}`;var F,ke,z=class{constructor(e={}){m(this,F);let r=e,{accessToken:t}=r,s=q(r,["accessToken"]);this.accessToken=t,this.defaults=a(a({},z.defaults),s)}suggest(e,t){return p(this,null,function*(){if(!e)throw new Error("searchText is required");if(!this.accessToken)throw new Error("accessToken is required");if(!t||!t.sessionToken)throw new Error("sessionToken is required");let{sessionToken:s,signal:r}=t,i=R(a(a({},this.defaults),t),{sessionToken:s}),u=new URL(`${we}/${encodeURIComponent(e)}`);u.search=b(this,F,ke).call(this,i);let{fetch:c}=L(),o=yield c(u.toString(),{signal:r});yield v(o);let h=yield o.json();return R(a({},h),{suggestions:h.suggestions.map(O=>R(a({},O),{original_search_text:e}))})})}retrieve(e,t){return p(this,null,function*(){if(!e)throw new Error("suggestion is required");if(!this.accessToken)throw new Error("accessToken is required");if(!t||!t.sessionToken)throw new Error("sessionToken is required");let{sessionToken:s,signal:r}=t,i=R(a(a({},this.defaults),t),{sessionToken:s}),u=typeof e!="string",c=u?e.original_search_text:e,o=new URL(`${xe}/${encodeURIComponent(c)}`);o.search=b(this,F,ke).call(this,i);let{fetch:h}=L(),O=yield h(o.toString(),{signal:r});yield v(O);let G=yield O.json();return u?R(a({},G),{features:G.features.filter(Oe=>Oe.properties.full_address===e.full_address)}):G})}},K=z;F=new WeakSet,ke=function(e){return _({access_token:this.accessToken,language:e.language,country:e.country,limit:e.limit},e.sessionToken&&{session_token:f.convert(e.sessionToken).id},e.proximity&&{proximity:typeof e.proximity=="string"?e.proximity:g.convert(e.proximity).toArray().join(",")},e.bbox&&{bbox:typeof e.bbox=="string"?e.bbox:d.convert(e.bbox).toFlatArray().join(",")})},K.defaults={language:"en",proximity:"ip"};var A,I=class{constructor(){m(this,A,{})}addEventListener(e,t){let s=l(this,A);s[e]||(s[e]=[]),s[e].push(t)}removeEventListener(e,t){let s=l(this,A);if(!s[e])return;let r=s[e],i=r.indexOf(t);i!==-1&&r.splice(i,1)}fire(e,t){let s=l(this,A);if(!s[e])return;let r=s[e];for(let i of r)i(t)}};A=new WeakMap;function _e(n,e,t){let s=null;return(...r)=>{s!==null&&clearTimeout(s);let i=t&&t();s=setTimeout(()=>{s=null,!(i==null?void 0:i.aborted)&&n(...r)},e)}}var Ye=50;function Z(){let{AbortController:n}=L();return new n}var E,w,V,ze,x,y,$,ee=class extends I{constructor(e,t=0){super();m(this,V);m(this,E,new f);m(this,w,0);m(this,x,void 0);m(this,y,Z());m(this,$,void 0);S(this,$,_e((i,...u)=>p(this,[i,...u],function*(s,r={}){if(l(this,y).abort(),S(this,y,Z()),!s){S(this,x,null),this.fire("suggest",l(this,x));return}let c=b(this,V,ze).call(this);try{let o=yield this.search.suggest(s,R(a({sessionToken:c},r),{signal:l(this,y).signal}));S(this,x,o),this.fire("suggest",o)}catch(o){if(o.name==="AbortError")return;this.fire("suggesterror",o)}}),t,()=>l(this,y).signal)),Object.defineProperties(this,{search:{value:e,writable:!1},debounce:{value:t,writable:!1}})}get suggestions(){return l(this,x)}suggest(e,t){return l(this,$).call(this,e,t),new Promise((s,r)=>{let i,u;i=c=>{this.removeEventListener("suggest",i),this.removeEventListener("suggesterror",u),s(c)},u=c=>{this.removeEventListener("suggest",i),this.removeEventListener("suggesterror",u),r(c)},this.addEventListener("suggest",i),this.addEventListener("suggesterror",u)})}clear(){this.suggest("")}retrieve(e){return p(this,null,function*(){let t=yield this.search.retrieve(e,{sessionToken:l(this,E)});return S(this,E,new f),S(this,w,0),this.fire("retrieve",t),t})}canRetrieve(e){return this.search.canRetrieve?this.search.canRetrieve(e):!0}canSuggest(e){return this.search.canSuggest?this.search.canSuggest(e):!0}abort(){l(this,y).abort(),S(this,y,Z())}};E=new WeakMap,w=new WeakMap,V=new WeakSet,ze=function(){return(l(this,E).isExpired()||l(this,w)>=Ye)&&(S(this,E,new f),S(this,w,0)),oe(this,w)._++,l(this,E)},x=new WeakMap,y=new WeakMap,$=new WeakMap;function Ae(n){let{properties:e}=n;return a({},e)}return Me(Ze);})();
//# sourceMappingURL=mapboxsearchcore.js.map
{
"name": "@mapbox/search-js-core",
"version": "1.0.0-beta.5",
"version": "1.0.0-beta.6",
"description": "Platform agnostic wrappers for the Search API and Geocoding API.",

@@ -10,4 +10,3 @@ "main": "dist/index.js",

"scripts": {
"build": "typehead build && dts-bundle-generator -o dist/index.d.ts src/index.ts",
"copy:cdn": "mkdir -p dist/cdn && cp dist/mapboxsearchcore.js dist/cdn/core.js",
"build": "typehead build && tsc -p tsconfig.types.json",
"watch": "typehead build --watch",

@@ -23,3 +22,3 @@ "serve": "typehead serve",

"devDependencies": {
"@mapbox/search-js-jest-preset": "^1.0.0",
"@mapbox/esbuild-jest": "^1.1.0",
"@mapbox/typehead": "^1.2.0",

@@ -29,3 +28,2 @@ "@size-limit/preset-small-lib": "^7.0.5",

"abort-controller": "^3.0.0",
"dts-bundle-generator": "^5.9.0",
"jest": "^27.4.7",

@@ -40,3 +38,3 @@ "size-limit": "^7.0.5",

"jest": {
"preset": "@mapbox/search-js-jest-preset"
"preset": "@mapbox/esbuild-jest"
},

@@ -43,0 +41,0 @@ "dependencies": {

@@ -20,3 +20,4 @@ {

]
}
},
"exclude": ["dist/*", "dist/**/*"]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc