{"version":3,"sources":["DistanceResources.min__ff92a1d47dbcec2611e1.js","./src/ui/Distance/DistanceResources.ts","./src/ui/Distance/GoogleApiPositionProvider.ts","./src/ui/Distance/NavigatorPositionProvider.ts","./src/ui/Distance/StaticPositionProvider.ts"],"names":["webpackJsonpCoveo__temporary","251","module","exports","__webpack_require__","__extends","this","extendStatics","Object","setPrototypeOf","__proto__","Array","d","b","p","hasOwnProperty","__","constructor","prototype","create","__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","value","step","next","e","rejected","result","done","then","apply","__generator","body","verb","n","v","op","f","TypeError","_","y","t","call","label","ops","pop","trys","length","push","g","sent","throw","return","Symbol","iterator","defineProperty","element","options","bindings","DistanceResources","ID","isFirstPositionResolved","ComponentOptions","initComponentOptions","registerDistanceQuery","bind","onRootElement","InitializationEvents","afterComponentsInitialization","args","onAfterComponentsInitialization","_this","setPosition","latitude","longitude","enable","position","trigger","DistanceEvents","onPositionResolved","shouldTriggerQuery","shouldTriggerQueryWhenPositionSet","sendAnalytics","queryController","executeQuery","getLastPositionRequest","_a","lastPositionRequest","usageAnalytics","logSearchEvent","analyticsActionCauseList","positionSet","firstQuery","triggerNewQueryOnNewPosition","afterComponentsInitializationArgs","providers","getProvidersFromOptions","onResolvingPosition","tryToSetPositionFromProviders","cancelQueryUntilPositionResolved","defer","error_1","tryGetPositionFromProviders","triggerDistanceNotSet","logger","error","useNavigator","NavigatorPositionProvider","googleApiKey","GoogleApiPositionProvider","longitudeValue","latitudeValue","StaticPositionProvider","provider","error_2","shift","getPosition","warn","onPositionNotResolved","disable","QueryEvents","buildingQuery","queryBuilder","geoQueryFunction","function","getConvertedUnitsFunction","latitudeField","longitudeField","fieldName","distanceField","queryFunctions","enableDistanceComponents","$$","root","findAll","disabledDistanceCssClass","forEach","classList","remove","coveoComponent","get","exception","queryFunction","unitConversionFactor","doExport","exportGlobally","buildFieldOption","required","buildNumberOption","defaultValue","validator","buildStringOption","float","buildBooleanOption","Component","Initialization","registerAutoCreateComponent","608","responseData","location","EndpointCaller","errorsAsSuccess","method","queryString","requestData","responseType","url","data","lng","lat","609","navigator","geolocation","getCurrentPosition","coords","610"],"mappings":"AAAAA,8BAA8B,KAExBC,IACA,SAAUC,EAAQC,EAASC,GAEjC,YAEA,IAAIC,GAAaC,MAAQA,KAAKD,WAAc,WACxC,GAAIE,GAAgBC,OAAOC,iBACpBC,uBAA2BC,QAAS,SAAUC,EAAGC,GAAKD,EAAEF,UAAYG,IACvE,SAAUD,EAAGC,GAAK,IAAK,GAAIC,KAAKD,GAAOA,EAAEE,eAAeD,KAAIF,EAAEE,GAAKD,EAAEC,IACzE,OAAO,UAAUF,EAAGC,GAEhB,QAASG,KAAOV,KAAKW,YAAcL,EADnCL,EAAcK,EAAGC,GAEjBD,EAAEM,UAAkB,OAANL,EAAaL,OAAOW,OAAON,IAAMG,EAAGE,UAAYL,EAAEK,UAAW,GAAIF,QAGnFI,EAAad,MAAQA,KAAKc,WAAc,SAAUC,EAASC,EAAYC,EAAGC,GAC1E,MAAO,KAAKD,IAAMA,EAAIE,UAAU,SAAUC,EAASC,GAC/C,QAASC,GAAUC,GAAS,IAAMC,EAAKN,EAAUO,KAAKF,IAAW,MAAOG,GAAKL,EAAOK,IACpF,QAASC,GAASJ,GAAS,IAAMC,EAAKN,EAAiB,MAAEK,IAAW,MAAOG,GAAKL,EAAOK,IACvF,QAASF,GAAKI,GAAUA,EAAOC,KAAOT,EAAQQ,EAAOL,OAAS,GAAIN,GAAE,SAAUG,GAAWA,EAAQQ,EAAOL,SAAWO,KAAKR,EAAWK,GACnIH,GAAMN,EAAYA,EAAUa,MAAMhB,EAASC,QAAmBS,WAGlEO,EAAehC,MAAQA,KAAKgC,aAAgB,SAAUjB,EAASkB,GAG/D,QAASC,GAAKC,GAAK,MAAO,UAAUC,GAAK,MAAOZ,IAAMW,EAAGC,KACzD,QAASZ,GAAKa,GACV,GAAIC,EAAG,KAAM,IAAIC,WAAU,kCAC3B,MAAOC,GAAG,I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C,CAClB,OAAOhI,GAAYhC,KAAM,SAAUuF,GAC/B,OAAQA,EAAG3C,OACP,IAAK,GE9bA,UAAM,GAAI,GAAAqH,gBAAiBtH,MAC9CuH,iBAAiB,EACjBC,OAAQ,OACRC,aAAc,OAAOpK,KAAK6G,cAC1BwD,eACAC,aAAc,OACdC,IA5BsB,wDF4dR,KAAK,GE7brB,MATMR,GAAe,SAQfC,EAAWD,EAAaS,KAAKR,UACnC,GACErF,UAAWqF,EAASS,IACpB/F,SAAUsF,EAASU,YAGzB,IAlBa,GAAA5D,6BF4dP6D,IACA,SAAU/K,EAAQC,EAASC,GAEjC,YAEAI,QAAOsD,eAAe3D,EAAS,cAAgB0B,OAAO,GG5etD,gCAgBA,MAfS,aAAA8F,YAAP,WACE,MAAO,IAAIlG,SAA8B,SAACC,EAASC,GACjDuJ,UAAUC,YAAYC,mBACpB,SAAAjG,GACEzD,GACEsD,SAAUG,EAASkG,OAAOrG,SAC1BC,UAAWE,EAASkG,OAAOpG,aAG/B,SAAA+B,GACErF,EAAOqF,QAKjB,IAhBa,GAAAE,6BH2gBPoE,IACA,SAAUpL,EAAQC,EAASC,GAEjC,YAEAI,QAAOsD,eAAe3D,EAAS,cAAgB0B,OAAO,GIphBtD,kBACE,WAAoBmD,EAA0BC,GAA1B,KAAAD,WAA0B,KAAAC,YAQhD,MANS,aAAA0C,YAAP,WACE,MAAOlG,SAAQC,SACbuD,UAAW3E,KAAK2E,UAChBD,SAAU1E,KAAK0E,YAGrB,IATa,GAAAuC","file":"DistanceResources.min__ff92a1d47dbcec2611e1.js","sourcesContent":["webpackJsonpCoveo__temporary([33],{\n\n/***/ 251:\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar DistanceEvents_1 = __webpack_require__(204);\nvar EventsModules_1 = __webpack_require__(101);\nvar GlobalExports_1 = __webpack_require__(3);\nvar Dom_1 = __webpack_require__(1);\nvar AnalyticsActionListMeta_1 = __webpack_require__(10);\nvar Component_1 = __webpack_require__(7);\nvar ComponentOptions_1 = __webpack_require__(8);\nvar Initialization_1 = __webpack_require__(2);\nvar RegisteredNamedMethods_1 = __webpack_require__(30);\nvar GoogleApiPositionProvider_1 = __webpack_require__(608);\nvar NavigatorPositionProvider_1 = __webpack_require__(609);\nvar StaticPositionProvider_1 = __webpack_require__(610);\n/**\n * The `DistanceResources` component defines a field that computes the distance according to the current position of the\n * end user.\n *\n * Components relying on the current distance should be disabled until this component successfully provides a distance.\n *\n * See also [`DistanceEvents`]{@link DistanceEvents}.\n *\n * @availablesince [November 2017 Release (v2.3477.9)](https://docs.coveo.com/en/373/#november-2017-release-v234779)\n */\nvar DistanceResources = /** @class */ (function (_super) {\n __extends(DistanceResources, _super);\n /**\n * Creates a new `DistanceResources` component.\n * @param element The HTMLElement on which to instantiate the component.\n * @param options The options for the `DistanceResources` component.\n * @param bindings The bindings that the component requires to function normally. If not set, these will be\n * automatically resolved (with a slower execution time).\n */\n function DistanceResources(element, options, bindings) {\n var _this = _super.call(this, element, DistanceResources.ID, bindings) || this;\n _this.element = element;\n _this.options = options;\n _this.bindings = bindings;\n _this.isFirstPositionResolved = false;\n _this.options = ComponentOptions_1.ComponentOptions.initComponentOptions(element, DistanceResources, options);\n _this.registerDistanceQuery();\n _this.bind.onRootElement(EventsModules_1.InitializationEvents.afterComponentsInitialization, function (args) {\n return _this.onAfterComponentsInitialization(args);\n });\n return _this;\n }\n /**\n * Overrides the current position with the provided values.\n *\n * **Note:**\n * > Calling this method does not automatically trigger a query.\n *\n * @param latitude The latitude to set.\n * @param longitude The longitude to set.\n */\n DistanceResources.prototype.setPosition = function (latitude, longitude) {\n this.enable();\n this.latitude = latitude;\n this.longitude = longitude;\n var args = {\n position: {\n latitude: latitude,\n longitude: longitude\n }\n };\n this.bind.trigger(this.element, DistanceEvents_1.DistanceEvents.onPositionResolved, args);\n var shouldTriggerQuery = this.shouldTriggerQueryWhenPositionSet();\n this.isFirstPositionResolved = true;\n if (shouldTriggerQuery) {\n this.sendAnalytics();\n this.queryController.executeQuery();\n }\n };\n /**\n * Returns a promise of the last position resolved using the registered position providers.\n *\n * @returns {Promise} A promise of the last resolved position value.\n */\n DistanceResources.prototype.getLastPositionRequest = function () {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!!!this.lastPositionRequest) return [3 /*break*/, 2];\n return [4 /*yield*/, this.lastPositionRequest];\n case 1:\n _a.sent();\n return [2 /*return*/, {\n latitude: this.latitude,\n longitude: this.longitude\n }];\n case 2:\n Promise.reject('No position request was executed yet.');\n _a.label = 3;\n case 3: return [2 /*return*/];\n }\n });\n });\n };\n DistanceResources.prototype.sendAnalytics = function () {\n this.usageAnalytics.logSearchEvent(AnalyticsActionListMeta_1.analyticsActionCauseList.positionSet, {});\n };\n DistanceResources.prototype.shouldTriggerQueryWhenPositionSet = function () {\n // Don't trigger the query if the first one is not yet executed.\n return !this.queryController.firstQuery && this.options.triggerNewQueryOnNewPosition;\n };\n DistanceResources.prototype.onAfterComponentsInitialization = function (afterComponentsInitializationArgs) {\n var args = {\n providers: this.getProvidersFromOptions()\n };\n this.bind.trigger(this.element, DistanceEvents_1.DistanceEvents.onResolvingPosition, args);\n this.lastPositionRequest = this.tryToSetPositionFromProviders(args.providers);\n if (this.options.cancelQueryUntilPositionResolved) {\n afterComponentsInitializationArgs.defer.push(this.lastPositionRequest);\n }\n };\n DistanceResources.prototype.tryToSetPositionFromProviders = function (providers) {\n return __awaiter(this, void 0, void 0, function () {\n var position, error_1;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n _a.trys.push([0, 2, , 3]);\n return [4 /*yield*/, this.tryGetPositionFromProviders(providers)];\n case 1:\n position = _a.sent();\n if (position) {\n this.setPosition(position.latitude, position.longitude);\n }\n else {\n this.triggerDistanceNotSet();\n }\n return [3 /*break*/, 3];\n case 2:\n error_1 = _a.sent();\n this.logger.error('An error occurred while trying to resolve the current position.', error_1);\n this.triggerDistanceNotSet();\n return [3 /*break*/, 3];\n case 3: return [2 /*return*/];\n }\n });\n });\n };\n DistanceResources.prototype.getProvidersFromOptions = function () {\n var providers = [];\n if (this.options.useNavigator) {\n providers.push(new NavigatorPositionProvider_1.NavigatorPositionProvider());\n }\n if (this.options.googleApiKey) {\n providers.push(new GoogleApiPositionProvider_1.GoogleApiPositionProvider(this.options.googleApiKey));\n }\n if (this.options.longitudeValue && this.options.latitudeValue) {\n providers.push(new StaticPositionProvider_1.StaticPositionProvider(this.options.latitudeValue, this.options.longitudeValue));\n }\n return providers;\n };\n DistanceResources.prototype.tryGetPositionFromProviders = function (providers) {\n return __awaiter(this, void 0, void 0, function () {\n var provider, position, error_2;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!(providers.length > 0)) return [3 /*break*/, 5];\n provider = providers.shift();\n _a.label = 1;\n case 1:\n _a.trys.push([1, 3, , 4]);\n return [4 /*yield*/, provider.getPosition()];\n case 2:\n position = _a.sent();\n if (!!position.latitude && !!position.longitude) {\n return [2 /*return*/, position];\n }\n return [3 /*break*/, 4];\n case 3:\n error_2 = _a.sent();\n this.logger.warn('An error occurred while trying to resolve the position within a position provider.', error_2);\n return [3 /*break*/, 4];\n case 4: return [3 /*break*/, 0];\n case 5: return [2 /*return*/];\n }\n });\n });\n };\n DistanceResources.prototype.triggerDistanceNotSet = function () {\n this.isFirstPositionResolved = true;\n this.logger.warn(\"None of the given position providers could resolve the current position. The distance field will not be calculated and the distance components will be disabled until the next call to 'setPosition'.\");\n this.bind.trigger(this.element, DistanceEvents_1.DistanceEvents.onPositionNotResolved, {});\n this.disable();\n };\n DistanceResources.prototype.registerDistanceQuery = function () {\n var _this = this;\n this.bind.onRootElement(EventsModules_1.QueryEvents.buildingQuery, function (args) {\n if (_this.isFirstPositionResolved) {\n if (args && args.queryBuilder) {\n var geoQueryFunction = {\n function: _this.getConvertedUnitsFunction(\"dist(\" + _this.options.latitudeField + \", \" + _this.options.longitudeField + \", \" + _this.latitude + \", \" + _this.longitude + \")\"),\n fieldName: \"\" + _this.options.distanceField\n };\n args.queryBuilder.queryFunctions.push(geoQueryFunction);\n _this.enableDistanceComponents();\n }\n }\n });\n };\n DistanceResources.prototype.enableDistanceComponents = function () {\n var _this = this;\n Dom_1.$$(this.root)\n .findAll(\".\" + this.options.disabledDistanceCssClass)\n .forEach(function (element) {\n try {\n element.classList.remove(_this.options.disabledDistanceCssClass);\n var coveoComponent = RegisteredNamedMethods_1.get(element);\n if (coveoComponent) {\n coveoComponent.enable();\n }\n }\n catch (exception) {\n _this.logger.error('Could not re-enable distance component.', exception, element);\n }\n });\n };\n DistanceResources.prototype.getConvertedUnitsFunction = function (queryFunction) {\n return queryFunction + \"/\" + this.options.unitConversionFactor;\n };\n DistanceResources.ID = 'DistanceResources';\n DistanceResources.doExport = function () {\n GlobalExports_1.exportGlobally({\n DistanceResources: DistanceResources\n });\n };\n /**\n * The possible options for a DistanceResources.\n * @componentOptions\n */\n DistanceResources.options = {\n /**\n * Specifies the name of the field in which to store the distance value.\n *\n * Specifying a value for this option is required for the `DistanceResources` component to work.\n */\n distanceField: ComponentOptions_1.ComponentOptions.buildFieldOption({\n required: true\n }),\n /**\n * Specifies the name of the field that contains the latitude value.\n *\n * **Note:**\n * > The field you specify for this option must be an existing numerical field in your index (see\n * > [Adding and Managing Fields](https://docs.coveo.com/en/1833/). Otherwise, your query responses\n * > will contain a `QueryExceptionInvalidQueryFunctionField` or QueryExceptionInvalidQueryFunctionFieldType`\n * > exception, and the DistanceResources component will be unable to evaluate distances.\n *\n * Specifying a value for this option is required for the `DistanceResources` component to work.\n */\n latitudeField: ComponentOptions_1.ComponentOptions.buildFieldOption({\n required: true\n }),\n /**\n * Specifies the name of the field that contains the longitude value.\n *\n * **Note:**\n * > The field you specify for this option must be an existing numerical field in your index (see\n * > [Adding and Managing Fields](https://docs.coveo.com/en/1833/). Otherwise, your query responses\n * > will contain a `QueryExceptionInvalidQueryFunctionField` or QueryExceptionInvalidQueryFunctionFieldType`\n * > exception, and the DistanceResources component will be unable to evaluate distances.\n *\n * Specifying a value for this option is required for the `DistanceResources` component to work.\n */\n longitudeField: ComponentOptions_1.ComponentOptions.buildFieldOption({\n required: true\n }),\n /**\n * The conversion factor to apply to the base distance unit (meter).\n *\n * **Note:**\n * > - If you want to convert distances to kilometers, you should set the `unitConversionFactor` to `1000`.\n * > - If you want to convert distance to miles, you should set the `unitConversionFactor` to `1610` (one mile is\n * > approximately equal to 1610 meters).\n *\n * Default value is `1000`.\n */\n unitConversionFactor: ComponentOptions_1.ComponentOptions.buildNumberOption({\n defaultValue: 1000,\n validator: function (value) {\n return !!value && value > 0;\n }\n }),\n /**\n * The CSS class for components that need to be re-enabled when the `DistanceResources` component successfully\n * provides a distance.\n *\n * Default value is `coveo-distance-disabled`.\n */\n disabledDistanceCssClass: ComponentOptions_1.ComponentOptions.buildStringOption({\n defaultValue: 'coveo-distance-disabled'\n }),\n /**\n * The latitude to use if no other position was provided.\n *\n * **Note:**\n * > You must also specify a [`longitudeValue`]{@link DistanceResources.options.longitudeValue} if you specify a\n * > `latitudeValue`.\n */\n latitudeValue: ComponentOptions_1.ComponentOptions.buildNumberOption({\n float: true\n }),\n /**\n * The longitude to use if no other position was provided.\n *\n * **Note:**\n * > You must also specify a [`latitudeValue`]{@link DistanceResources.options.latitudeValue} if you specify a\n * > `longitudeValue`.\n */\n longitudeValue: ComponentOptions_1.ComponentOptions.buildNumberOption({\n float: true\n }),\n /**\n * The API key to use to request the Google API geolocation service.\n *\n * If you do not specify a value for this option, the `DistanceResources` component does not try to request the\n * service.\n */\n googleApiKey: ComponentOptions_1.ComponentOptions.buildStringOption(),\n /**\n * Whether to request the geolocation service of the web browser.\n *\n * If not defined, will not try to request the service.\n *\n * **Note:**\n * > Recent web browsers typically require a site to be in HTTPS to enable their geolocation service.\n *\n * If you do not specify a value for this option, the `DistanceResources` component does not try to request the\n * service.\n */\n useNavigator: ComponentOptions_1.ComponentOptions.buildBooleanOption(),\n /**\n * Whether to execute a new query when the `DistanceResources` component successfully provides a new position.\n *\n * Default value is `false`.\n */\n triggerNewQueryOnNewPosition: ComponentOptions_1.ComponentOptions.buildBooleanOption({\n defaultValue: false\n }),\n /**\n * Whether to cancel all the queries until the `DistanceResources` component successfully resolves a position.\n *\n * Default value is `true`\n */\n cancelQueryUntilPositionResolved: ComponentOptions_1.ComponentOptions.buildBooleanOption({\n defaultValue: true\n })\n };\n return DistanceResources;\n}(Component_1.Component));\nexports.DistanceResources = DistanceResources;\nInitialization_1.Initialization.registerAutoCreateComponent(DistanceResources);\n\n\n/***/ }),\n\n/***/ 608:\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar EndpointCaller_1 = __webpack_require__(91);\nvar GOOGLE_MAP_BASE_URL = 'https://www.googleapis.com/geolocation/v1/geolocate';\n/**\n * The `GoogleApiPositionProvider` class uses the\n * [Google Maps Geolocation API](https://developers.google.com/maps/documentation/geolocation/intro) to provide the\n * position of the end user to a [`DistanceResources`]{@link DistanceResources} component whose\n * [`googleApiKey`]{@link DistanceResources.options.googleApiKey} option is set to a valid Google Maps Geolocation API\n * key.\n */\nvar GoogleApiPositionProvider = /** @class */ (function () {\n function GoogleApiPositionProvider(googleApiKey) {\n this.googleApiKey = googleApiKey;\n }\n GoogleApiPositionProvider.prototype.getPosition = function () {\n return __awaiter(this, void 0, void 0, function () {\n var responseData, location;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, new EndpointCaller_1.EndpointCaller().call({\n errorsAsSuccess: false,\n method: 'POST',\n queryString: [\"key=\" + this.googleApiKey],\n requestData: {},\n responseType: 'json',\n url: GOOGLE_MAP_BASE_URL\n })];\n case 1:\n responseData = _a.sent();\n location = responseData.data.location;\n return [2 /*return*/, {\n longitude: location.lng,\n latitude: location.lat\n }];\n }\n });\n });\n };\n return GoogleApiPositionProvider;\n}());\nexports.GoogleApiPositionProvider = GoogleApiPositionProvider;\n\n\n/***/ }),\n\n/***/ 609:\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", { value: true });\n/**\n * The `NavigatorPositionProvider` class uses the current web browser to provide the position of the end user to\n * a [`DistanceResources`]{@link DistanceResources} component whose\n * [`useNavigator`]{DistanceResources.options.useNavigator} option is set to `true`.\n *\n * **Note:**\n * > Recent web browsers typically require a site to be in HTTPS to enable their geolocation service.\n */\nvar NavigatorPositionProvider = /** @class */ (function () {\n function NavigatorPositionProvider() {\n }\n NavigatorPositionProvider.prototype.getPosition = function () {\n return new Promise(function (resolve, reject) {\n navigator.geolocation.getCurrentPosition(function (position) {\n resolve({\n latitude: position.coords.latitude,\n longitude: position.coords.longitude\n });\n }, function (error) {\n reject(error);\n });\n });\n };\n return NavigatorPositionProvider;\n}());\nexports.NavigatorPositionProvider = NavigatorPositionProvider;\n\n\n/***/ }),\n\n/***/ 610:\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", { value: true });\n/**\n * The `StaticPositionProvider` class provides a static end user position to a\n * [`DistanceResources`]{@link DistanceResources} component.\n */\nvar StaticPositionProvider = /** @class */ (function () {\n function StaticPositionProvider(latitude, longitude) {\n this.latitude = latitude;\n this.longitude = longitude;\n }\n StaticPositionProvider.prototype.getPosition = function () {\n return Promise.resolve({\n longitude: this.longitude,\n latitude: this.latitude\n });\n };\n return StaticPositionProvider;\n}());\nexports.StaticPositionProvider = StaticPositionProvider;\n\n\n/***/ })\n\n});\n\n\n// WEBPACK FOOTER //\n// DistanceResources.min__ff92a1d47dbcec2611e1.js","import {\n DistanceEvents,\n IGeolocationPosition,\n IGeolocationPositionProvider,\n IPositionResolvedEventArgs,\n IResolvingPositionEventArgs\n} from '../../events/DistanceEvents';\nimport { IInitializationEventArgs } from '../../events/InitializationEvents';\nimport { IBuildingQueryEventArgs } from '../../events/QueryEvents';\nimport { InitializationEvents, QueryEvents } from '../../EventsModules';\nimport { exportGlobally } from '../../GlobalExports';\nimport { IQueryFunction } from '../../rest/QueryFunction';\nimport { $$ } from '../../utils/Dom';\nimport { analyticsActionCauseList } from '../Analytics/AnalyticsActionListMeta';\nimport { Component } from '../Base/Component';\nimport { IComponentBindings } from '../Base/ComponentBindings';\nimport { ComponentOptions } from '../Base/ComponentOptions';\nimport { IFieldOption } from '../Base/IComponentOptions';\nimport { Initialization } from '../Base/Initialization';\nimport { get } from '../Base/RegisteredNamedMethods';\nimport { GoogleApiPositionProvider } from './GoogleApiPositionProvider';\nimport { NavigatorPositionProvider } from './NavigatorPositionProvider';\nimport { StaticPositionProvider } from './StaticPositionProvider';\n\nexport interface IDistanceOptions {\n distanceField: IFieldOption;\n latitudeField: IFieldOption;\n longitudeField: IFieldOption;\n unitConversionFactor: number;\n disabledDistanceCssClass: string;\n latitudeValue: number;\n longitudeValue: number;\n googleApiKey: string;\n useNavigator: boolean;\n triggerNewQueryOnNewPosition: boolean;\n cancelQueryUntilPositionResolved: boolean;\n}\n\n/**\n * The `DistanceResources` component defines a field that computes the distance according to the current position of the\n * end user.\n *\n * Components relying on the current distance should be disabled until this component successfully provides a distance.\n *\n * See also [`DistanceEvents`]{@link DistanceEvents}.\n *\n * @availablesince [November 2017 Release (v2.3477.9)](https://docs.coveo.com/en/373/#november-2017-release-v234779)\n */\nexport class DistanceResources extends Component {\n public static ID = 'DistanceResources';\n static doExport = () => {\n exportGlobally({\n DistanceResources: DistanceResources\n });\n };\n private latitude: number;\n private longitude: number;\n private lastPositionRequest: Promise;\n private isFirstPositionResolved = false;\n\n /**\n * The possible options for a DistanceResources.\n * @componentOptions\n */\n public static options: IDistanceOptions = {\n /**\n * Specifies the name of the field in which to store the distance value.\n *\n * Specifying a value for this option is required for the `DistanceResources` component to work.\n */\n distanceField: ComponentOptions.buildFieldOption({\n required: true\n }),\n\n /**\n * Specifies the name of the field that contains the latitude value.\n *\n * **Note:**\n * > The field you specify for this option must be an existing numerical field in your index (see\n * > [Adding and Managing Fields](https://docs.coveo.com/en/1833/). Otherwise, your query responses\n * > will contain a `QueryExceptionInvalidQueryFunctionField` or QueryExceptionInvalidQueryFunctionFieldType`\n * > exception, and the DistanceResources component will be unable to evaluate distances.\n *\n * Specifying a value for this option is required for the `DistanceResources` component to work.\n */\n latitudeField: ComponentOptions.buildFieldOption({\n required: true\n }),\n\n /**\n * Specifies the name of the field that contains the longitude value.\n *\n * **Note:**\n * > The field you specify for this option must be an existing numerical field in your index (see\n * > [Adding and Managing Fields](https://docs.coveo.com/en/1833/). Otherwise, your query responses\n * > will contain a `QueryExceptionInvalidQueryFunctionField` or QueryExceptionInvalidQueryFunctionFieldType`\n * > exception, and the DistanceResources component will be unable to evaluate distances.\n *\n * Specifying a value for this option is required for the `DistanceResources` component to work.\n */\n longitudeField: ComponentOptions.buildFieldOption({\n required: true\n }),\n\n /**\n * The conversion factor to apply to the base distance unit (meter).\n *\n * **Note:**\n * > - If you want to convert distances to kilometers, you should set the `unitConversionFactor` to `1000`.\n * > - If you want to convert distance to miles, you should set the `unitConversionFactor` to `1610` (one mile is\n * > approximately equal to 1610 meters).\n *\n * Default value is `1000`.\n */\n unitConversionFactor: ComponentOptions.buildNumberOption({\n defaultValue: 1000,\n validator: value => {\n return !!value && value > 0;\n }\n }),\n\n /**\n * The CSS class for components that need to be re-enabled when the `DistanceResources` component successfully\n * provides a distance.\n *\n * Default value is `coveo-distance-disabled`.\n */\n disabledDistanceCssClass: ComponentOptions.buildStringOption({\n defaultValue: 'coveo-distance-disabled'\n }),\n\n /**\n * The latitude to use if no other position was provided.\n *\n * **Note:**\n * > You must also specify a [`longitudeValue`]{@link DistanceResources.options.longitudeValue} if you specify a\n * > `latitudeValue`.\n */\n latitudeValue: ComponentOptions.buildNumberOption({\n float: true\n }),\n\n /**\n * The longitude to use if no other position was provided.\n *\n * **Note:**\n * > You must also specify a [`latitudeValue`]{@link DistanceResources.options.latitudeValue} if you specify a\n * > `longitudeValue`.\n */\n longitudeValue: ComponentOptions.buildNumberOption({\n float: true\n }),\n\n /**\n * The API key to use to request the Google API geolocation service.\n *\n * If you do not specify a value for this option, the `DistanceResources` component does not try to request the\n * service.\n */\n googleApiKey: ComponentOptions.buildStringOption(),\n\n /**\n * Whether to request the geolocation service of the web browser.\n *\n * If not defined, will not try to request the service.\n *\n * **Note:**\n * > Recent web browsers typically require a site to be in HTTPS to enable their geolocation service.\n *\n * If you do not specify a value for this option, the `DistanceResources` component does not try to request the\n * service.\n */\n useNavigator: ComponentOptions.buildBooleanOption(),\n\n /**\n * Whether to execute a new query when the `DistanceResources` component successfully provides a new position.\n *\n * Default value is `false`.\n */\n triggerNewQueryOnNewPosition: ComponentOptions.buildBooleanOption({\n defaultValue: false\n }),\n\n /**\n * Whether to cancel all the queries until the `DistanceResources` component successfully resolves a position.\n *\n * Default value is `true`\n */\n cancelQueryUntilPositionResolved: ComponentOptions.buildBooleanOption({\n defaultValue: true\n })\n };\n\n /**\n * Creates a new `DistanceResources` component.\n * @param element The HTMLElement on which to instantiate the component.\n * @param options The options for the `DistanceResources` component.\n * @param bindings The bindings that the component requires to function normally. If not set, these will be\n * automatically resolved (with a slower execution time).\n */\n constructor(public element: HTMLElement, public options: IDistanceOptions, public bindings: IComponentBindings) {\n super(element, DistanceResources.ID, bindings);\n\n this.options = ComponentOptions.initComponentOptions(element, DistanceResources, options);\n this.registerDistanceQuery();\n this.bind.onRootElement(InitializationEvents.afterComponentsInitialization, (args: IInitializationEventArgs) =>\n this.onAfterComponentsInitialization(args)\n );\n }\n\n /**\n * Overrides the current position with the provided values.\n *\n * **Note:**\n * > Calling this method does not automatically trigger a query.\n *\n * @param latitude The latitude to set.\n * @param longitude The longitude to set.\n */\n public setPosition(latitude: number, longitude: number): void {\n this.enable();\n this.latitude = latitude;\n this.longitude = longitude;\n\n const args: IPositionResolvedEventArgs = {\n position: {\n latitude: latitude,\n longitude: longitude\n }\n };\n\n this.bind.trigger(this.element, DistanceEvents.onPositionResolved, args);\n\n const shouldTriggerQuery = this.shouldTriggerQueryWhenPositionSet();\n this.isFirstPositionResolved = true;\n if (shouldTriggerQuery) {\n this.sendAnalytics();\n this.queryController.executeQuery();\n }\n }\n\n /**\n * Returns a promise of the last position resolved using the registered position providers.\n *\n * @returns {Promise} A promise of the last resolved position value.\n */\n public async getLastPositionRequest(): Promise {\n if (!!this.lastPositionRequest) {\n await this.lastPositionRequest;\n return {\n latitude: this.latitude,\n longitude: this.longitude\n };\n } else {\n Promise.reject('No position request was executed yet.');\n }\n }\n\n private sendAnalytics() {\n this.usageAnalytics.logSearchEvent(analyticsActionCauseList.positionSet, {});\n }\n\n private shouldTriggerQueryWhenPositionSet() {\n // Don't trigger the query if the first one is not yet executed.\n return !this.queryController.firstQuery && this.options.triggerNewQueryOnNewPosition;\n }\n\n private onAfterComponentsInitialization(afterComponentsInitializationArgs: IInitializationEventArgs): void {\n const args: IResolvingPositionEventArgs = {\n providers: this.getProvidersFromOptions()\n };\n\n this.bind.trigger(this.element, DistanceEvents.onResolvingPosition, args);\n\n this.lastPositionRequest = this.tryToSetPositionFromProviders(args.providers);\n\n if (this.options.cancelQueryUntilPositionResolved) {\n afterComponentsInitializationArgs.defer.push(this.lastPositionRequest);\n }\n }\n\n private async tryToSetPositionFromProviders(providers: IGeolocationPositionProvider[]): Promise {\n try {\n const position = await this.tryGetPositionFromProviders(providers);\n if (position) {\n this.setPosition(position.latitude, position.longitude);\n } else {\n this.triggerDistanceNotSet();\n }\n } catch (error) {\n this.logger.error('An error occurred while trying to resolve the current position.', error);\n this.triggerDistanceNotSet();\n }\n }\n\n private getProvidersFromOptions(): IGeolocationPositionProvider[] {\n const providers: IGeolocationPositionProvider[] = [];\n\n if (this.options.useNavigator) {\n providers.push(new NavigatorPositionProvider());\n }\n\n if (this.options.googleApiKey) {\n providers.push(new GoogleApiPositionProvider(this.options.googleApiKey));\n }\n\n if (this.options.longitudeValue && this.options.latitudeValue) {\n providers.push(new StaticPositionProvider(this.options.latitudeValue, this.options.longitudeValue));\n }\n\n return providers;\n }\n\n private async tryGetPositionFromProviders(providers: IGeolocationPositionProvider[]): Promise {\n while (providers.length > 0) {\n const provider = providers.shift();\n try {\n const position = await provider.getPosition();\n if (!!position.latitude && !!position.longitude) {\n return position;\n }\n } catch (error) {\n this.logger.warn('An error occurred while trying to resolve the position within a position provider.', error);\n }\n }\n return;\n }\n\n private triggerDistanceNotSet(): void {\n this.isFirstPositionResolved = true;\n this.logger.warn(\n `None of the given position providers could resolve the current position. The distance field will not be calculated and the distance components will be disabled until the next call to 'setPosition'.`\n );\n this.bind.trigger(this.element, DistanceEvents.onPositionNotResolved, {});\n this.disable();\n }\n\n private registerDistanceQuery(): void {\n this.bind.onRootElement(QueryEvents.buildingQuery, (args: IBuildingQueryEventArgs) => {\n if (this.isFirstPositionResolved) {\n if (args && args.queryBuilder) {\n const geoQueryFunction: IQueryFunction = {\n function: this.getConvertedUnitsFunction(\n `dist(${this.options.latitudeField}, ${this.options.longitudeField}, ${this.latitude}, ${this.longitude})`\n ),\n fieldName: `${this.options.distanceField}`\n };\n args.queryBuilder.queryFunctions.push(geoQueryFunction);\n this.enableDistanceComponents();\n }\n }\n });\n }\n\n private enableDistanceComponents(): void {\n $$(this.root)\n .findAll(`.${this.options.disabledDistanceCssClass}`)\n .forEach(element => {\n try {\n element.classList.remove(this.options.disabledDistanceCssClass);\n const coveoComponent = get(element);\n if (coveoComponent) {\n coveoComponent.enable();\n }\n } catch (exception) {\n this.logger.error('Could not re-enable distance component.', exception, element);\n }\n });\n }\n\n private getConvertedUnitsFunction(queryFunction: string): string {\n return `${queryFunction}/${this.options.unitConversionFactor}`;\n }\n}\n\nInitialization.registerAutoCreateComponent(DistanceResources);\n\n\n\n// WEBPACK FOOTER //\n// ./src/ui/Distance/DistanceResources.ts","import { EndpointCaller } from '../../rest/EndpointCaller';\nimport { IGeolocationPosition, IGeolocationPositionProvider } from '../../events/DistanceEvents';\n\nconst GOOGLE_MAP_BASE_URL = 'https://www.googleapis.com/geolocation/v1/geolocate';\n\ninterface IGeolocationResponse {\n location: IGeolocationResponseLocation;\n}\n\ninterface IGeolocationResponseLocation {\n lat: number;\n lng: number;\n}\n\n/**\n * The `GoogleApiPositionProvider` class uses the\n * [Google Maps Geolocation API](https://developers.google.com/maps/documentation/geolocation/intro) to provide the\n * position of the end user to a [`DistanceResources`]{@link DistanceResources} component whose\n * [`googleApiKey`]{@link DistanceResources.options.googleApiKey} option is set to a valid Google Maps Geolocation API\n * key.\n */\nexport class GoogleApiPositionProvider implements IGeolocationPositionProvider {\n constructor(private googleApiKey: string) {}\n\n public async getPosition(): Promise {\n const responseData = await new EndpointCaller().call({\n errorsAsSuccess: false,\n method: 'POST',\n queryString: [`key=${this.googleApiKey}`],\n requestData: {},\n responseType: 'json',\n url: GOOGLE_MAP_BASE_URL\n });\n const location = responseData.data.location;\n return {\n longitude: location.lng,\n latitude: location.lat\n };\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/ui/Distance/GoogleApiPositionProvider.ts","import { IGeolocationPositionProvider, IGeolocationPosition } from '../../events/DistanceEvents';\n\n/**\n * The `NavigatorPositionProvider` class uses the current web browser to provide the position of the end user to\n * a [`DistanceResources`]{@link DistanceResources} component whose\n * [`useNavigator`]{DistanceResources.options.useNavigator} option is set to `true`.\n *\n * **Note:**\n * > Recent web browsers typically require a site to be in HTTPS to enable their geolocation service.\n */\nexport class NavigatorPositionProvider implements IGeolocationPositionProvider {\n public getPosition(): Promise {\n return new Promise((resolve, reject) => {\n navigator.geolocation.getCurrentPosition(\n position => {\n resolve({\n latitude: position.coords.latitude,\n longitude: position.coords.longitude\n });\n },\n error => {\n reject(error);\n }\n );\n });\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/ui/Distance/NavigatorPositionProvider.ts","import { IGeolocationPositionProvider, IGeolocationPosition } from '../../events/DistanceEvents';\n\n/**\n * The `StaticPositionProvider` class provides a static end user position to a\n * [`DistanceResources`]{@link DistanceResources} component.\n */\nexport class StaticPositionProvider implements IGeolocationPositionProvider {\n constructor(private latitude: number, private longitude: number) {}\n\n public getPosition(): Promise {\n return Promise.resolve({\n longitude: this.longitude,\n latitude: this.latitude\n });\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/ui/Distance/StaticPositionProvider.ts"],"sourceRoot":""}