gtfs-to-html 2.12.3 → 2.12.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -85,7 +85,7 @@
85
85
  function requireFuzzy () {
86
86
  if (hasRequiredFuzzy) return fuzzy.exports;
87
87
  hasRequiredFuzzy = 1;
88
- (function (module, exports) {
88
+ (function (module, exports$1) {
89
89
  (function() {
90
90
 
91
91
  var fuzzy = {};
@@ -1711,7 +1711,8 @@
1711
1711
  * A geocoder component that works with maplibre
1712
1712
  */
1713
1713
  class MaplibreGeocoder {
1714
- constructor(geocoderApi, options) {
1714
+ constructor(geocoderApi, options, typeaheadFactory = (input, data, options) => new Typeahead(input, data, options)) {
1715
+ // Fill with default values
1715
1716
  this.options = {
1716
1717
  zoom: 16,
1717
1718
  flyTo: true,
@@ -1729,16 +1730,16 @@
1729
1730
  clearOnBlur: false,
1730
1731
  proximityMinZoom: 9,
1731
1732
  getItemValue: (item) => {
1732
- return item.text !== undefined ? item.text : item.place_name;
1733
+ return item.text != undefined ? item.text : item.place_name;
1733
1734
  },
1734
- render: function (item) {
1735
+ render: (item) => {
1735
1736
  // Render as a suggestion
1736
- if (!item.geometry) {
1737
+ if (!('geometry' in item)) {
1737
1738
  const suggestionString = item.text;
1738
1739
  const indexOfMatch = suggestionString
1739
1740
  .toLowerCase()
1740
- .indexOf(this.query.toLowerCase());
1741
- const lengthOfMatch = this.query.length;
1741
+ .indexOf(this._typeahead.query.toLowerCase());
1742
+ const lengthOfMatch = this._typeahead.query.length;
1742
1743
  const beforeMatch = suggestionString.substring(0, indexOfMatch);
1743
1744
  const match = suggestionString.substring(indexOfMatch, indexOfMatch + lengthOfMatch);
1744
1745
  const afterMatch = suggestionString.substring(indexOfMatch + lengthOfMatch);
@@ -1785,6 +1786,7 @@
1785
1786
  this.fresh = true;
1786
1787
  this.lastSelected = null;
1787
1788
  this.geocoderApi = geocoderApi;
1789
+ this.typeaheadFactory = typeaheadFactory;
1788
1790
  }
1789
1791
  /**
1790
1792
  * Add the geocoder to a container. The container can be either a `Map`, an `HTMLElement` or a CSS selector string.
@@ -1899,7 +1901,7 @@
1899
1901
  el.appendChild(searchIcon);
1900
1902
  el.appendChild(this._inputEl);
1901
1903
  el.appendChild(actions);
1902
- this._typeahead = new Typeahead(this._inputEl, [], {
1904
+ this._typeahead = this.typeaheadFactory(this._inputEl, [], {
1903
1905
  filter: false,
1904
1906
  minLength: this.options.minLength,
1905
1907
  limit: this.options.limit,
@@ -1964,27 +1966,29 @@
1964
1966
  }
1965
1967
  }
1966
1968
  _onKeyDown(e) {
1967
- const ESC_KEY_CODE = 27;
1968
- const TAB_KEY_CODE = 9;
1969
- const ENTER_KEY_CODE = 13;
1970
- if (e.keyCode === ESC_KEY_CODE && this.options.clearAndBlurOnEsc) {
1969
+ if (e.key === 'Escape' && this.options.clearAndBlurOnEsc) {
1971
1970
  this._clear(e);
1972
- return this._inputEl.blur();
1971
+ this._inputEl.blur();
1972
+ return;
1973
1973
  }
1974
1974
  const value = this._inputEl.value;
1975
1975
  if (!value) {
1976
1976
  this.fresh = true;
1977
1977
  // the user has removed all the text
1978
- if (e.keyCode !== TAB_KEY_CODE)
1978
+ if (e.key !== 'Tab')
1979
1979
  this.clear(e);
1980
- return (this._clearEl.style.display = "none");
1980
+ this._clearEl.style.display = "none";
1981
+ return;
1981
1982
  }
1982
- // TAB, ESC, LEFT, RIGHT, UP, DOWN
1983
1983
  if (e.metaKey ||
1984
- [TAB_KEY_CODE, ESC_KEY_CODE, 37, 39, 38, 40].indexOf(e.keyCode) !== -1)
1984
+ e.key === 'Tab' ||
1985
+ e.key === 'Escape' ||
1986
+ e.key === 'ArrowLeft' ||
1987
+ e.key === 'ArrowRight' ||
1988
+ e.key === 'ArrowUp' ||
1989
+ e.key === 'ArrowDown')
1985
1990
  return;
1986
- // ENTER
1987
- if (e.keyCode === ENTER_KEY_CODE) {
1991
+ if (e.key === 'Enter') {
1988
1992
  if (!this.options.showResultsWhileTyping) {
1989
1993
  if (!this._typeahead.selected) {
1990
1994
  this._geocode(value);
@@ -2032,73 +2036,76 @@
2032
2036
  // we cannot depend on some internal values of the suggestion state like `selected` as those will change or before
2033
2037
  // our onKeyDown handler.
2034
2038
  _onChange() {
2039
+ var _a;
2035
2040
  const selected = this._typeahead.selected;
2036
2041
  // If a suggestion was selected
2037
- if (selected && !selected.geometry) {
2042
+ if (!selected)
2043
+ return;
2044
+ if (!('geometry' in selected)) {
2038
2045
  if (selected.placeId)
2039
2046
  this._geocode(selected.placeId, true, true);
2040
2047
  else
2041
2048
  this._geocode(selected.text, true);
2049
+ return;
2042
2050
  }
2043
- else if (selected && JSON.stringify(selected) !== this.lastSelected) {
2044
- this._clearEl.style.display = "none";
2045
- if (this.options.flyTo) {
2046
- let flyOptions;
2047
- this._removeResultMarkers();
2048
- if (selected.properties && exceptions[selected.properties.short_code]) {
2049
- // Certain geocoder search results return (and therefore zoom to fit)
2050
- // an unexpectedly large bounding box: for example, both Russia and the
2051
- // USA span both sides of -180/180, or France includes the island of
2052
- // Reunion in the Indian Ocean. An incomplete list of these exceptions
2053
- // at ./exceptions.json provides "reasonable" bounding boxes as a
2054
- // short-term solution; this may be amended as necessary.
2055
- flyOptions = extend({}, this.options.flyTo);
2056
- if (this._map) {
2057
- this._map.fitBounds(exceptions[selected.properties.short_code].bbox, flyOptions);
2058
- }
2059
- }
2060
- else if (selected.bbox) {
2061
- const bbox = selected.bbox;
2062
- flyOptions = extend({}, this.options.flyTo);
2063
- if (this._map) {
2064
- this._map.fitBounds([
2065
- [bbox[0], bbox[1]],
2066
- [bbox[2], bbox[3]],
2067
- ], flyOptions);
2068
- }
2051
+ if (JSON.stringify(selected) === this.lastSelected) {
2052
+ return;
2053
+ }
2054
+ this._clearEl.style.display = "none";
2055
+ if (this.options.flyTo) {
2056
+ let flyOptions;
2057
+ this._removeResultMarkers();
2058
+ if (selected.properties && exceptions[selected.properties.short_code]) {
2059
+ // Certain geocoder search results return (and therefore zoom to fit)
2060
+ // an unexpectedly large bounding box: for example, both Russia and the
2061
+ // USA span both sides of -180/180, or France includes the island of
2062
+ // Reunion in the Indian Ocean. An incomplete list of these exceptions
2063
+ // at ./exceptions.json provides "reasonable" bounding boxes as a
2064
+ // short-term solution; this may be amended as necessary.
2065
+ flyOptions = extend({}, this.options.flyTo);
2066
+ if (this._map) {
2067
+ this._map.fitBounds(exceptions[selected.properties.short_code].bbox, flyOptions);
2069
2068
  }
2070
- else {
2071
- const defaultFlyOptions = {
2072
- zoom: this.options.zoom,
2073
- };
2074
- flyOptions = extend({}, defaultFlyOptions, this.options.flyTo);
2075
- // ensure that center is not overriden by custom options
2076
- if (selected.center) {
2077
- flyOptions.center = selected.center;
2078
- }
2079
- else if (selected.geometry &&
2080
- selected.geometry.type &&
2081
- selected.geometry.type === "Point" &&
2082
- selected.geometry.coordinates) {
2083
- flyOptions.center = selected.geometry.coordinates;
2084
- }
2085
- if (this._map) {
2086
- this._map.flyTo(flyOptions);
2087
- }
2069
+ }
2070
+ else if (selected.bbox) {
2071
+ const bbox = selected.bbox;
2072
+ flyOptions = extend({}, this.options.flyTo);
2073
+ if (this._map) {
2074
+ this._map.fitBounds([
2075
+ [bbox[0], bbox[1]],
2076
+ [bbox[2], bbox[3]],
2077
+ ], flyOptions);
2088
2078
  }
2089
2079
  }
2090
- if (this.options.marker && this._maplibregl) {
2091
- this._handleMarker(selected);
2080
+ else {
2081
+ const defaultFlyOptions = {
2082
+ zoom: this.options.zoom,
2083
+ };
2084
+ flyOptions = extend({}, defaultFlyOptions, this.options.flyTo);
2085
+ // ensure that center is not overriden by custom options
2086
+ if (selected.center) {
2087
+ flyOptions.center = selected.center;
2088
+ }
2089
+ else if (((_a = selected.geometry) === null || _a === void 0 ? void 0 : _a.type) === "Point" &&
2090
+ selected.geometry.coordinates) {
2091
+ flyOptions.center = selected.geometry.coordinates;
2092
+ }
2093
+ if (this._map) {
2094
+ this._map.flyTo(flyOptions);
2095
+ }
2092
2096
  }
2093
- // After selecting a feature, re-focus the textarea and set
2094
- // cursor at start, and reset the selected feature.
2095
- this._inputEl.focus();
2096
- this._inputEl.scrollLeft = 0;
2097
- this._inputEl.setSelectionRange(0, 0);
2098
- this.lastSelected = JSON.stringify(selected);
2099
- this._typeahead.selected = null; // reset selection current selection value and set it to last selected
2100
- this._eventEmitter.emit("result", { result: selected });
2101
2097
  }
2098
+ if (this.options.marker && this._maplibregl) {
2099
+ this._handleMarker(selected);
2100
+ }
2101
+ // After selecting a feature, re-focus the textarea and set
2102
+ // cursor at start, and reset the selected feature.
2103
+ this._inputEl.focus();
2104
+ this._inputEl.scrollLeft = 0;
2105
+ this._inputEl.setSelectionRange(0, 0);
2106
+ this.lastSelected = JSON.stringify(selected);
2107
+ this._typeahead.selected = null; // reset selection current selection value and set it to last selected
2108
+ this._eventEmitter.emit("result", { result: selected });
2102
2109
  }
2103
2110
  _getConfigForRequest() {
2104
2111
  // Possible config proprerties to pass to client
@@ -2230,19 +2237,19 @@
2230
2237
  if (this.options.filter && res.features.length) {
2231
2238
  res.features = res.features.filter(this.options.filter);
2232
2239
  }
2233
- let results = [];
2240
+ let typeaheadData = [];
2234
2241
  if ('suggestions' in res) {
2235
- results = res.suggestions;
2242
+ typeaheadData = res.suggestions;
2236
2243
  }
2237
2244
  else if ('place' in res) {
2238
- results = [res.place];
2245
+ typeaheadData = Array.isArray(res.place) ? res.place : [res.place];
2239
2246
  }
2240
2247
  else {
2241
- results = res.features;
2248
+ typeaheadData = res.features;
2242
2249
  }
2243
- if (results.length) {
2250
+ if (typeaheadData.length) {
2244
2251
  this._clearEl.style.display = "block";
2245
- this._typeahead.update(results);
2252
+ this._typeahead.update(typeaheadData);
2246
2253
  if ((!this.options.showResultsWhileTyping || isSuggestion) &&
2247
2254
  this.options.showResultMarkers &&
2248
2255
  (res.features.length > 0 || 'place' in res)) {
@@ -2392,6 +2399,7 @@
2392
2399
  * Fits the map to the current bounds for the searched results
2393
2400
  */
2394
2401
  _fitBoundsForMarkers() {
2402
+ var _a;
2395
2403
  if (this._typeahead.data.length < 1)
2396
2404
  return;
2397
2405
  // Filter out suggestions and restrict to limit
@@ -2407,7 +2415,9 @@
2407
2415
  const flyOptions = extend({}, defaultFlyOptions, this.options.flyTo);
2408
2416
  const bounds = new this._maplibregl.LngLatBounds();
2409
2417
  for (const feature of results) {
2410
- bounds.extend(feature.geometry.coordinates);
2418
+ if (('geometry' in feature) && (((_a = feature.geometry) === null || _a === void 0 ? void 0 : _a.type) === "Point")) {
2419
+ bounds.extend(feature.geometry.coordinates);
2420
+ }
2411
2421
  }
2412
2422
  this._map.fitBounds(bounds, flyOptions);
2413
2423
  }
@@ -2525,9 +2535,9 @@
2525
2535
  * @param placeholder - the text to use as the input element's placeholder
2526
2536
  */
2527
2537
  setPlaceholder(placeholder) {
2528
- this.placeholder = placeholder ? placeholder : this.options.placeholder || this._localize("placeholder");
2529
- this._inputEl.placeholder = this.placeholder;
2530
- this._inputEl.setAttribute("aria-label", this.placeholder);
2538
+ this.options.placeholder = placeholder ? placeholder : this.options.placeholder || this._localize("placeholder");
2539
+ this._inputEl.placeholder = this.options.placeholder;
2540
+ this._inputEl.setAttribute("aria-label", this.options.placeholder);
2531
2541
  return this;
2532
2542
  }
2533
2543
  /**
@@ -2643,6 +2653,7 @@
2643
2653
  * @param selected - the selected geojson feature
2644
2654
  */
2645
2655
  _handleMarker(selected) {
2656
+ var _a;
2646
2657
  // clean up any old marker that might be present
2647
2658
  if (!this._map) {
2648
2659
  return;
@@ -2653,7 +2664,7 @@
2653
2664
  };
2654
2665
  const markerOptions = extend({}, defaultMarkerOptions, this.options.marker);
2655
2666
  this.mapMarker = new this._maplibregl.Marker(markerOptions);
2656
- let popup;
2667
+ let popup = null;
2657
2668
  if (this.options.popup) {
2658
2669
  const defaultPopupOptions = {};
2659
2670
  const popupOptions = extend({}, defaultPopupOptions, this.options.popup);
@@ -2664,9 +2675,7 @@
2664
2675
  if (this.options.popup)
2665
2676
  this.mapMarker.setPopup(popup);
2666
2677
  }
2667
- else if (selected.geometry &&
2668
- selected.geometry.type &&
2669
- selected.geometry.type === "Point" &&
2678
+ else if (((_a = selected.geometry) === null || _a === void 0 ? void 0 : _a.type) === "Point" &&
2670
2679
  selected.geometry.coordinates) {
2671
2680
  this.mapMarker.setLngLat(selected.geometry.coordinates).addTo(this._map);
2672
2681
  if (this.options.popup)
@@ -2743,13 +2752,7 @@
2743
2752
  }
2744
2753
  /**
2745
2754
  * Subscribe to events that happen within the plugin.
2746
- * @param type - name of event. Available events and the data passed into their respective event objects are:
2747
- *
2748
- * - __clear__ `Emitted when the input is cleared`
2749
- * - __loading__ `{ query } Emitted when the geocoder is looking up a query`
2750
- * - __results__ `{ results } Fired when the geocoder returns a response`
2751
- * - __result__ `{ result } Fired when input is set`
2752
- * - __error__ `{ error } Error as string`
2755
+ * @param type - name of event. Check out the {@link MaplibreGeocoderEventTypeMap} for a list of available events.
2753
2756
  * @param fn - function that's called when the event is emitted.
2754
2757
  */
2755
2758
  on(type, fn) {
@@ -2758,14 +2761,7 @@
2758
2761
  }
2759
2762
  /**
2760
2763
  * Subscribe to events that happen within the plugin only once.
2761
- * @param type - Event name.
2762
- * Available events and the data passed into their respective event objects are:
2763
- *
2764
- * - __clear__ `Emitted when the input is cleared`
2765
- * - __loading__ `{ query } Emitted when the geocoder is looking up a query`
2766
- * - __results__ `{ results } Fired when the geocoder returns a response`
2767
- * - __result__ `{ result } Fired when input is set`
2768
- * - __error__ `{ error } Error as string`
2764
+ * @param type - Event name. Check out the {@link MaplibreGeocoderEventTypeMap} for a list of available events.
2769
2765
  * @returns a Promise that resolves when the event is emitted.
2770
2766
  */
2771
2767
  once(type) {