@nextgis/geocoder 1.18.17 → 1.18.19

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.
@@ -1,2 +1,2 @@
1
- class e extends Error{constructor(){super(),this.name="CancelError",Object.setPrototypeOf(this,e.prototype)}}class t{constructor(e={}){this.options=e,this._promises=new Map}get isLoaded(){return this._promises.size>0}remove(e){this._promises.has(e)&&(this._promises.delete(e),this._onStop())}get(e){return this._promises.get(e)}add(e,t){const r=t||e,n=this._promises.get(r);return this.options.onStart&&!this.isLoaded&&this.options.onStart(),n||(this._promises.set(r,e),e.finally((()=>{this.remove(r)})),e)}abort(){this.isLoaded&&(this._promises.forEach((e=>{e.cancel&&e.cancel()})),this._promises.clear(),this._onStop())}waitFunc(e,t=""){const r=this.get(t=t||e.name);return r||this.add(e(),t)}WaitForMe(e=""){const t=this.get.bind(this),r=this.add.bind(this);return function(n,s,o){const i=o.value;return e=e||s,o.value=function(...n){const s=t(e);if(s)return s;return r(i.apply(this,n),e)},o}}GetOrCreateDecorator(e=""){return this.WaitForMe(e)}_onStop(){this.options.onStop&&!this.isLoaded&&this.options.onStop()}}class r extends Error{constructor(){super(),this.name="TimeoutError",Object.setPrototypeOf(this,r.prototype)}}const n=(e,t,r,n)=>{try{e(r(n))}catch(s){t(s)}};let s=0;class o{constructor(t,n){this.id=s++,this._isCanceled=!1,this._isPending=!0,this._cancelHandlers=[],this._children=[],this._cancelPromise=new Promise(((t,r)=>{this._setCanceledCallback=r=>t(r||new e)}));const i=[this._cancelPromise,new Promise(((e,r)=>t((t=>{t instanceof o?this.attach(t):this._isPending=!1,e(t)}),(e=>{this._isPending=!1,r(e)}),(e=>{if(!this._isPending)throw new Error("The `onCancel` handler was attached after the promise settled.");this._cancelHandlers.push(e)}))))];n&&i.push(new Promise(((e,t)=>{setTimeout((()=>{if(this._isPending)try{this.cancel()}finally{t(new r)}}),n)}))),this._promise=Promise.race(i)}static createControl(e){return new t(e)}static resolve(e){return new o((t=>t(e)))}static reject(e){return new o(((t,r)=>r(e)))}static all(e){return new o(((t,r)=>{Promise.all(e).then(t).catch(r)})).catch((t=>{if(t instanceof this.CancelError)for(const r of e){"cancel"in r&&r.cancel()}throw t}))}attach(e){this._isCanceled?e.cancel():this._children.push(e)}then(e,t){const r=new o(((r,s)=>{if(this._promise){const o=e=>{t?n(r,s,t,e):s(e)};this._promise.then((t=>{this._isCanceled?o(t):e?n(r,s,e,t):r(t)}),o)}}));return r._parentPromise=this,this._children.push(r),r}catch(t){return this._isCanceled&&t&&t(new e),this.then(void 0,t)}finally(t){return this._promise?this._promise.finally(t):Promise.reject(this._isCanceled?new e:t)}cancel(){if(this._isCanceled||!this._isPending)return this;this._isCanceled=!0;const e=this._getTopParent();if(e&&e.cancel(),this._children&&this._children.forEach((e=>e.cancel())),this._isPending){if(this._cancelHandlers.length)try{for(const e of this._cancelHandlers)e()}catch(t){}this._setCanceledCallback&&this._setCanceledCallback()}return this._destroy(),this}_getTopParent(){let e=this._parentPromise,t=!!e;for(;t;)e&&e._parentPromise?(e=e._parentPromise,t=!!e):t=!1;return e}_destroy(){this._setCanceledCallback=void 0,this._cancelPromise=void 0,this._promise=void 0}}o.CancelError=e,o.TimeoutError=r,o.PromiseControl=t,Object.setPrototypeOf(o.prototype,Promise.prototype);var i=o;function c(e){return null!=e}function a(e){return"string"==typeof e?!!e:c(e)}function u(e,t,r,n){if(e instanceof Array)return t instanceof Array&&t.sort().join("")===e.sort().join("");if(e instanceof Date)return t instanceof Date&&""+e==""+t;if(e instanceof Function){if(!(t instanceof Function))return!1}else if(e instanceof Object)return t instanceof Object&&(e===r?t===n:h(e,t));return e===t}function h(e,t){const r=Object.keys(e).sort(),n=Object.keys(t).sort();if(r.length!==n.length)return!1;if(r.join("")!==n.join(""))return!1;for(let s=0;s<r.length;s++){if(!u(e[r[s]],t[n[s]],e,t))return!1}return!0}function l(e){const t={};return Object.keys(e).forEach((r=>{e[r]instanceof Array||e[r]!==Object(e[r])?void 0!==e[r]&&(t[r]=e[r]):t[r]=l(e[r])})),t}function f(e){return e.replace(/([^:]\/)\/+/g,"$1")}class p{constructor(e){e&&function(e,...t){for(const r of t)for(const t of Object.getOwnPropertyNames(r))e[t]=r[t]}(this,e)}}let d=0;class m extends p{constructor(e){super(e),this.providers=[],e&&e.providers&&(this.providers=e.providers)}abort(){this.providers.forEach((e=>{e.abort&&e.abort()}))}async*search(e){for(const r of this.providers)try{const t=r.search(e);for await(const e of t)yield{...e,provider:r,_id:d++}}catch(t){}}result(e){return e.provider?e.provider.result(e):i.resolve(void 0)}async*reverse(e){for(const r of this.providers)if(r.reverse)try{const t=r.reverse(e);for await(const e of t)yield{...e,provider:r,_id:d++}}catch(t){}}async reverseGeocodeFirstResult(e){for(const r of this.providers)if("function"==typeof r.reverse)try{for await(const t of r.reverse(e))return t}catch(t){console.error("Error in reverse geocoding:",t)}}}class y extends p{}var g,v={exports:{}},_="object"==typeof Reflect?Reflect:null,w=_&&"function"==typeof _.apply?_.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};g=_&&"function"==typeof _.ownKeys?_.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var b=Number.isNaN||function(e){return e!=e};function O(){O.init.call(this)}v.exports=O,v.exports.once=function(e,t){return new Promise((function(r,n){function s(r){e.removeListener(t,o),n(r)}function o(){"function"==typeof e.removeListener&&e.removeListener("error",s),r([].slice.call(arguments))}q(e,t,o,{once:!0}),"error"!==t&&function(e,t,r){"function"==typeof e.on&&q(e,"error",t,r)}(e,s,{once:!0})}))},O.EventEmitter=O,O.prototype._events=void 0,O.prototype._eventsCount=0,O.prototype._maxListeners=void 0;var x=10;function E(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function R(e){return void 0===e._maxListeners?O.defaultMaxListeners:e._maxListeners}function C(e,t,r,n){var s,o,i,c;if(E(r),void 0===(o=e._events)?(o=e._events=Object.create(null),e._eventsCount=0):(void 0!==o.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),o=e._events),i=o[t]),void 0===i)i=o[t]=r,++e._eventsCount;else if("function"==typeof i?i=o[t]=n?[r,i]:[i,r]:n?i.unshift(r):i.push(r),(s=R(e))>0&&i.length>s&&!i.warned){i.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=i.length,c=a,console&&console.warn&&console.warn(c)}return e}function L(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function P(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},s=L.bind(n);return s.listener=r,n.wrapFn=s,s}function j(e,t,r){var n=e._events;if(void 0===n)return[];var s=n[t];return void 0===s?[]:"function"==typeof s?r?[s.listener||s]:[s]:r?function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(s):k(s,s.length)}function I(e){var t=this._events;if(void 0!==t){var r=t[e];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function k(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function q(e,t,r,n){if("function"==typeof e.on)n.once?e.once(t,r):e.on(t,r);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function s(o){n.once&&e.removeEventListener(t,s),r(o)}))}}Object.defineProperty(O,"defaultMaxListeners",{enumerable:!0,get:function(){return x},set:function(e){if("number"!=typeof e||e<0||b(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");x=e}}),O.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},O.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||b(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},O.prototype.getMaxListeners=function(){return R(this)},O.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var n="error"===e,s=this._events;if(void 0!==s)n=n&&void 0===s.error;else if(!n)return!1;if(n){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var i=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw i.context=o,i}var c=s[e];if(void 0===c)return!1;if("function"==typeof c)w(c,this,t);else{var a=c.length,u=k(c,a);for(r=0;r<a;++r)w(u[r],this,t)}return!0},O.prototype.on=O.prototype.addListener=function(e,t){return C(this,e,t,!1)},O.prototype.prependListener=function(e,t){return C(this,e,t,!0)},O.prototype.once=function(e,t){return E(t),this.on(e,P(this,e,t)),this},O.prototype.prependOnceListener=function(e,t){return E(t),this.prependListener(e,P(this,e,t)),this},O.prototype.removeListener=function(e,t){var r,n,s,o,i;if(E(t),void 0===(n=this._events))return this;if(void 0===(r=n[e]))return this;if(r===t||r.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(s=-1,o=r.length-1;o>=0;o--)if(r[o]===t||r[o].listener===t){i=r[o].listener,s=o;break}if(s<0)return this;0===s?r.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(r,s),1===r.length&&(n[e]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",e,i||t)}return this},O.prototype.off=O.prototype.removeListener,O.prototype.removeAllListeners=function(e){var t,r,n;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete r[e]),this;if(0===arguments.length){var s,o=Object.keys(r);for(n=0;n<o.length;++n)"removeListener"!==(s=o[n])&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(void 0!==t)for(n=t.length-1;n>=0;n--)this.removeListener(e,t[n]);return this},O.prototype.listeners=function(e){return j(this,e,!0)},O.prototype.rawListeners=function(e){return j(this,e,!1)},O.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):I.call(e,t)},O.prototype.listenerCount=I,O.prototype.eventNames=function(){return this._eventsCount>0?g(this._events):[]};class T{constructor(e={}){var t;this.cache=[];const r=null!==(t=e.namespace)&&void 0!==t?t:"default";return T.instance[r]?T.instance[r]:(T.instance[r]=this,this)}clean(){this.cache.length=0}all(){return this.cache}addFull(e,t,r){return this.add(e,t,r,!0)}add(e,t,r,n){const s=this._find(e,r);if(s)return s.value;{let s;s=t instanceof Function?t():t;const o=r&&JSON.parse(JSON.stringify(l(r))),i={key:e,value:s,props:o,options:o};return n&&!a(s)?s:(this.cache.push(i),s instanceof Promise?(s.catch((t=>{throw this.delete(e,r),t})),n&&s.then((t=>(a(t)||this.delete(e,r),t))),s):s)}}match(e,t){const r=this._find(e,t);if(r)return r.value}matchAll(e,t){return e?this.cache.filter((r=>this._filter(r,e,t))).map((e=>e.value)):this.cache.map((e=>e.value))}delete(e,t){let r=[];"string"==typeof e?r=this.cache.filter((r=>this._filter(r,e,t))):r.push(e);for(const n of r){const e=this.cache.indexOf(n);this.cache.splice(e,1)}}_find(e,t){return this.cache.find((r=>this._filter(r,e,t)))}_filter(e,t,r){if(e.key===t){if(r){return h(e.props||e.options||{},l(r))}return!0}return!1}}T.instance={};var S=T;class A extends Error{constructor(e){super(),this.name="NetworkError",Object.setPrototypeOf(this,A.prototype),this.message=`Unable to request ${e}.\n Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`}}class F extends Error{constructor(e){super(),this.name="NgwError",Object.assign(this,e),Object.setPrototypeOf(this,F.prototype)}}function N(e){return"[object Object]"===Object.prototype.toString.call(e)}let U;U=(e,t,r={},n,s)=>{r.method=r.method||"GET";const o=new XMLHttpRequest;o.open(r.method||"GET",e,!0),"blob"===r.responseType&&(o.responseType=r.responseType);const i=()=>{try{return JSON.parse(o.responseText)}catch(e){return o.responseText}};o.onload=()=>{-1!==[401,403,404,422,500].indexOf(o.status)&&n(new F(i())),((e=!1)=>{const s=e?n:t;"blob"===r.responseType?s(o.response):o.responseText?s(i()):n({message:""})})()},o.onerror=t=>{n(0===o.status?new A(e):t)},o.upload.onprogress=function(e){if(e.lengthComputable){r.onProgress&&r.onProgress(e.loaded/e.total*100,e)}};const c=r.headers;if(c)for(const u in c){const e=c[u];"string"==typeof e&&o.setRequestHeader(u,e)}let a;if(void 0!==r.withCredentials&&(o.withCredentials=r.withCredentials),r.file){if(a=new FormData,a.append("file",r.file),r.data)for(const u in r.data)a.append(u,a[u])}else a=r.data?"string"==typeof r.data?r.data:JSON.stringify(r.data):null;s&&s((()=>{o.abort()})),o.send(a)};const $=/\{ *([\w_-]+) *\}/g;function M(e,t){return e.replace($,((e,r)=>{let n=t[r];if(void 0===n)throw new Error("No value provided for letiable "+e);return"function"==typeof n&&(n=n(t)),n}))}class H extends F{constructor(e){super(e),this.name="ResourceNotFoundError",this.exception="nextgisweb.resource.exception.ResourceNotFound",Object.setPrototypeOf(this,H.prototype)}}class B extends F{constructor(e){super(e),this.name="InsufficientPermissionsError",this.exception="nextgisweb.core.exception.InsufficientPermissions",Object.setPrototypeOf(this,B.prototype)}}const G=[];function D(e){G.push(e)}const z=["description"];function J(e,t=""){t=t?t+"__":"";const r={};for(const[n,s]of Object.entries(e))if(-1===z.indexOf(n))if(N(s))if("owner_user"===n){const e=J(s,n);Object.assign(r,e)}else"parent"===n&&"id"in s&&(r.parent_id=s.id);else c(s)&&(r[t+n]=s);return r}class Q{constructor(e){this.connector=e,this.cache=new S}getOne(e,t){const r=new S,n={},s={...t,cache:!1};"string"==typeof e?n.keyname=e:"number"==typeof e?n.id=e:N(e)&&(void 0!==e.id?n.id=e.id:e.keyname&&(n.keyname=e.keyname));return r.addFull("resource",(()=>"string"==typeof e?this._fetchResourceBy({keyname:e},s):"number"==typeof e?this._fetchResourceById(e,s):N(e)?this._fetchResourceBy(e,s):i.resolve(void 0)),n)}getOneOrFail(e,t){return this.getOne(e,t).then((e=>{if(e)return e;throw new H}))}getId(e,t){return"number"==typeof e?i.resolve(e):"string"==typeof e||N(e)?this.getOne(e,t).then((e=>{if(e)return e.resource.id})):i.resolve(void 0)}getIdOrFail(e,t){return this.getId(e,t).then((e=>{if(void 0===e)throw new Error;return e}))}getMany(e,t){return this._resourceCacheFilter(e).then((r=>{if(!r.length){const r={};return e.keyname?r.keyname=e.keyname:Object.assign(r,J(e)),this.connector.get("resource.search",t,{serialization:"full",...r}).then((e=>{if(e)for(const t of e)this.cache.add("resource.item",i.resolve(t),{id:t.resource.id});return e}))}return r}))}getParent(e,t){return this.getOne(e,t).then((e=>e?this.getOne(e.resource.parent.id,t):i.resolve(void 0)))}getChildrenOf(e,t){return this.getIdOrFail(e).then((e=>this._getChildrenOf(e,t)))}update(e,t){return this.getId(e).then((e=>{if(void 0!==e)return this.connector.put("resource.item",{data:t},{id:e})}))}delete(e){return this.getId(e).then((e=>{if(void 0!==e)return this.connector.delete("resource.item",null,{id:e}).then((()=>{this._cleanResourceItemCache(e)}))}))}_getChildrenOf(e,t,r=[]){return this.connector.get("resource.collection",{cache:!0,...t},{parent:e}).then((e=>{const n=[];for(const s of e)this.cache.add("resource.item",i.resolve(s),{id:s.resource.id}),r.push(s),(null==t?void 0:t.recursive)&&s.resource.children&&n.push(this._getChildrenOf(s.resource.id,t,r));return n.length?i.all(n).then((()=>r)):r}))}async _cleanResourceItemCache(e){const t=this.cache.all(),r=[];for(const n of t){const t=n.options&&n.options.id;if(["resource.item","resource"].includes(n.key)&&void 0!==t)if("number"==typeof t)t===e&&r.push(n);else{await this.getId(t)===e&&r.push(n)}}for(const n of r)this.cache.delete(n)}_fetchResourceById(e,t){return this.cache.add("resource.item",(()=>this.connector.get("resource.item",t,{id:e})),{id:e}).catch((e=>{if(!(e instanceof H))throw e}))}_fetchResourceBy(e,t){return this.getMany(e,t).then((e=>e[0]))}_resourceCacheFilter(e){return i.all(this.cache.matchAll("resource.item")).then((t=>(t.filter((t=>{if(t)return e.keyname&&t.resource.keyname?e.keyname===t.resource.keyname:c(e.id)&&c(t.resource.id)?e.id===t.resource.id:h(e,t.resource)})),[])))}}let W=0;class K{constructor(e){this.options=e,this.id=W++,this.emitter=new v.exports.EventEmitter,this.routeStr="/api/component/pyramid/route",this.activeRequests=[];const t=function(e){return G.find((t=>{if(t.options.baseUrl===e.baseUrl){if(!e.auth)return!0;if(t.options.auth)return h(t.options.auth,e.auth)}}))}(e);if(t)return t;this.options.route&&(this.routeStr=this.options.route),this.options.requestTransform&&(this.requestTransform=this.options.requestTransform),this.resources=new Q(this),D(this)}static create(e){return new this(e)}setRequestTransform(e){this.requestTransform=e}setNgw(e){this.logout(),this.options.baseUrl=e,D(this)}connect(){const e=new S,t=this.options.auth;return e.add("route",(()=>new i(((e,r)=>{const n=()=>this.makeQuery(this.routeStr,{},{}).then((t=>{e(t)})).catch((e=>{r(e)}));if(t){const{login:e,password:s}=t;if(e&&s)return this._login({login:e,password:s}).then((()=>n())).catch((e=>r(e)))}return n()}))),{id:this.id,auth:t,baseUrl:this.options.baseUrl})}login(e,t){return this.logout(),D(this),this._login(e,t)}logout(){this.abort(),function(e){const t=G.indexOf(e);-1!==t&&G.splice(t,1)}(this),this.options.auth=void 0,this.user=void 0,this.emitter.emit("logout"),this.resources.cache.clean()}getUserInfo(e,t){if(this.user&&this.user.id)return i.resolve(this.user);e&&(this.options.auth=e);const r={headers:this.getAuthorizationHeaders(e),...t};return this.makeQuery("/api/component/auth/current_user",{},r)}getAuthorizationHeaders(e){const t=this.makeClientId(e);if(t)return{Authorization:"Basic "+t}}makeClientId(e){if(e=e||this.options.auth){const{login:t,password:r}=e,n=unescape(encodeURIComponent(`${t}:${r}`));return window.btoa(n)}}abort(){for(const e of this.activeRequests)e.cancel();this.activeRequests=[]}getActiveApiRequests(){return[...this.activeRequests]}apiRequest(e,t={},r={}){var n,s;const{method:o,headers:c,withCredentials:a,responseType:u}=r,h=l(t=null!==(n=r.params)&&void 0!==n?n:t),f=()=>function(e){const t=e.params;return new i(((r,n)=>{e.connector.connect().then((s=>{let o=s&&s[e.name];if(o){o=[...o];let s=o.shift();if(o.length){const e={};for(let r=0;r<o.length;r++){const n=o[r];if(e[r]="{"+n+"}",void 0===t[n])throw new Error("`"+n+"` url api argument is not specified")}s&&(s=M(s,e))}if(t){const e=[],r=t.paramList;Array.isArray(r)&&(delete t.paramList,r.forEach((t=>{e.push(`${t[0]}=${t[1]}`)})));for(const n in t)-1===o.indexOf(n)&&e.push(`${n}=${t[n]}`);e.length&&(s=s+"?"+e.join("&"))}s?r(e.connector.makeQuery(s,t,e.requestOptions)):n(new Error("request url is not set"))}else r(void 0)})).catch((e=>{n(e)}))}))}({name:e,params:h,requestOptions:r,connector:this});if(r.cache&&"GET"===o){return(new S).add(e,f,{params:h,...l({headers:c,withCredentials:a,responseType:u,baseUrl:this.options.baseUrl,userId:null===(s=this.user)||void 0===s?void 0:s.id})})}return f()}post(e,t,r){return(t=t||{}).method="POST",this.apiRequest(e,r,t)}get(e,t,r){return(t=t||{}).method="GET",this.apiRequest(e,r,t)}patch(e,t,r){return(t=t||{}).method="PATCH",this.apiRequest(e,r,t)}put(e,t,r){return(t=t||{}).method="PUT",this.apiRequest(e,r,t)}delete(e,t,r){return(t=t||{}).method="DELETE",this.apiRequest(e,r,t)}makeQuery(e,t,r={}){if(e=(this.options.baseUrl?this.options.baseUrl:"")+e)return t&&(e=M(e,t)),e=encodeURI(f(e)),this._loadData(e,r);throw new Error("Empty `url` not allowed")}getResource(e,t){return this.resources.getOne(e,t)}getResourceOrFail(e,t){return this.resources.getOneOrFail(e,t)}getResourceBy(e){return this.resources.getOne(e)}getResourceByKeyname(e){return this.resources.getOne(e)}getResourceById(e){return this.resources.getOne(e)}getResourceId(e,t){return this.resources.getId(e,t)}getResourceIdOrFail(e,t){return this.resources.getIdOrFail(e,t)}getResourcesBy(e,t){return this.resources.getMany(e,t)}getResourceParent(e,t){return this.resources.getParent(e,t)}getResourceChildren(e,t){return this.resources.getChildrenOf(e,t)}updateResource(e,t){return this.resources.update(e,t)}deleteResource(e){return this.resources.delete(e)}_loadData(e,t){t.responseType=t.responseType||"json";const r=new i(((r,n,s)=>{if(this.user&&((t=t||{}).headers={...this.getAuthorizationHeaders(),...t.headers}),this.requestTransform){const[r,n]=this.requestTransform(e,t);e=r,t=n}U(e,r,t,n,s)})).then((e=>(this._cleanActiveRequests(r),e))).catch((e=>{if(this._cleanActiveRequests(r),e instanceof i.CancelError);else{const t=this._handleHttpError(e);if(t)throw t}}));return t.signal&&"function"==typeof t.signal.addEventListener&&t.signal.addEventListener("abort",(()=>{r.cancel(),this._cleanActiveRequests(r)})),this.activeRequests.push(r),r}_login(e,t){return this.getUserInfo(e,t).then((e=>(this.user=e,this.emitter.emit("login",e),e))).catch((e=>{throw this.emitter.emit("login:error",e),e}))}_cleanActiveRequests(e){const t=this.activeRequests.indexOf(e);-1!==t&&this.activeRequests.splice(t,1)}_handleHttpError(e){if(e&&e instanceof F){if("nextgisweb.resource.exception.ResourceNotFound"===e.exception)throw new H(e);if("nextgisweb.core.exception.InsufficientPermissions"===e.exception)throw new B(e)}return e}}K.errors={NgwError:F,ResourceNotFoundError:H};var X=K;function V(e,t,r){if((t=String(t))===(e=String(e)))return!0;if(r&&t.toUpperCase()===e.toUpperCase())return!0;const n=`^${s=t,s.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")}$`.replace(/%/g,".*").replace("_",".");var s;return null!==new RegExp(n,r?"i":"").exec(e)}const Y={gt:(e,t)=>e>t,lt:(e,t)=>e<t,ge:(e,t)=>e>=t,le:(e,t)=>e<=t,eq:(e,t)=>e===t,ne:(e,t)=>e!==t,in:(e,t)=>-1!==t.indexOf(e),notin:(e,t)=>-1===t.indexOf(e),like:(e,t)=>V(e,t),ilike:(e,t)=>V(e,t,!0)};function Z(e){return 3===e.length&&"string"==typeof e[0]&&"string"==typeof e[1]}function ee(e,t){const r="string"==typeof t[0]?t[0]:"all",n=t=>{if(Z(t)){const[r,n,s]=t,o=Y[n];if(o){if(("like"===n||"ilike"===n)&&"string"==typeof r){let t="";const n=r.replace(/^%?(\w+)%?$/,((n,o)=>(t=e[o],r.replace(o,s))));return o(t,n)}return o(e[r],s)}return!1}return ee(e,t)},s=t.filter((e=>Array.isArray(e)));return"any"===r?s.some(n):s.every(n)}const te={srs:4326,geom_format:"geojson"};function re(e){const t=se(e);return i.all(t).then((t=>{const r=[],n=[];for(const e of t)for(const t of e)r.includes(t.id)||(n.push(t),r.push(t.id));return e.offset||e.limit?n.splice(void 0!==e.offset?e.offset:0,void 0!==e.limit?e.limit:n.length):n}))}function ne(e){const[t,r,n]=e;let s="",o="";return[`${"id"!==t?"fld_":""}${String(t).trim().replace(/^(%?)(.+?)(%?)$/,((e,t,r,n)=>(s=t,o=n,r)))}__${r}`,s+n+o]}function se(e,t=[],r=[]){const{filters:n}=e,s="string"==typeof n[0]?n[0]:"all",o=n.filter((e=>Array.isArray(e)));if("any"===s)for(const i of o)Z(i)?t.push(ie({...e,paramList:[...r,ne(i)]})):se({...e,filters:i},t,[...r]);else if("all"===s){const n=[],s=[];for(const e of o)Z(e)?n.push(ne(e)):s.push(e);if(s.length)for(const o of s)se({...e,filters:o},t,[...r,...n]);else t.push(ie({...e,paramList:[...r,...n]}))}return t}function oe(e){return`POLYGON((${e.map((([e,t])=>{const[r,n]=function(e,t){t=t>85.06?85.06:t<-85.06?-85.06:t;const r=20037508.34*e/180;let n=Math.log(Math.tan((90+t)*Math.PI/360))/(Math.PI/180);return n=20037508.34*n/180,[r,n]}(e,t).map((e=>function(e,t){const r=t?Number("1e+"+t):1;return Math.round((e+Number.EPSILON)*r)/r}(e)));return r+" "+n})).join(", ")}))`}function ie(e){const t={...te},{limit:r,cache:n,signal:s,offset:o,orderBy:i,paramList:a,connector:u,geomFormat:h,intersects:l,resourceId:f}=e;if(r?r!==Number.POSITIVE_INFINITY&&(t.limit=r):t.limit=7e3,o&&(t.offset=o),h&&(t.geom_format=h),function(e,t){const{extensions:r,geom:n,fields:s,srs:o,ilike:i,like:a}=t;let u=r?r.join(","):"";"*"!==u&&(e.extensions=u),void 0!==s&&(e.fields=Array.isArray(s)?s.join(","):""),void 0!==n&&(e.geom=n?"yes":"no",n||(delete e.srs,delete e.geom_format)),c(i)?e.ilike=i:c(a)&&(e.like=a),c(o)&&(e.srs=o)}(t,e),i&&(t.order_by=i.join(",")),Array.isArray(l)){const e=(p=l,Array.isArray(p)&&4===p.length&&p.every((e=>"number"==typeof e))?function(e){const t=[e[0],e[1]];return[t,[e[2],e[1]],[e[2],e[3]],[e[0],e[3]],t]}(l):l);t.intersects=oe(e)}else"string"==typeof l&&(t.intersects=l);var p;a&&(t.paramList=a);const d={id:f,...t};return u.get("feature_layer.feature.collection",{cache:n,signal:s},d)}function ce(e){const t=e.filters;return t?re({...e,filters:t}).then((r=>{var n;return(null!==(n=e.clientFilterValidate)&&void 0!==n?n:ae(t))&&(r=r.filter((e=>ee(function(e){let t;for(t in e){const r=e[t];if("[object Object]"===Object.prototype.toString.call(r)){const n=r;if(c(n.year)&&c(n.month)&&c(n.day)){const r=[n.year,n.month-1,n.day];"hour"in n&&[n.hour,n.minute,n.second].forEach((e=>{r.push(e)})),e[t]=new Date(...r).toISOString()}}else"id"===t&&"string"==typeof r&&(e[t]=r.split(",").map(Number))}return e}({...e.fields,id:e.id}),t)))),r})):ie(e)}function ae(e){if("any"===e[0])return!0;for(let t=1;t<e.length;t++){const r=e[t];if("[object Array]"===Object.prototype.toString.call(r)){if(ae(r))return!0}}return!1}class ue extends y{constructor(e){var t;if(super(e),this.searchResources=[],this._abortControllers=[],!e.searchUrl&&!(null===(t=e.connectorOptions)||void 0===t?void 0:t.baseUrl))throw new Error("The `searchUrl` of `connectorOptions.baseUrl` are required");this.connector=e.connector||new X({baseUrl:this.searchUrl,...e.connectorOptions}),this.searchResources=e.searchResources}abort(){this._abortControllers.forEach((e=>{e.abort()})),this._abortControllers.length=0}async*search(e){var t,r;const n=this._makeSignal();for(const o of this.searchResources){if(n.aborted)break;const{searchMethod:i}=o,c=null!==(t=o.limit)&&void 0!==t?t:ue.limit,a=null!==(r=o.id)&&void 0!==r?r:o.resourceId;try{const t=await this.connector.getResourceOrFail(a,{cache:!0}),r={connector:this.connector,resourceId:a,signal:n,limit:c};"like"===i?r.like=e:r.ilike=e;const s=ce(r),u=await s;for(const n of this._items({entries:u,query:e,config:o,resourceItem:t}))n.result=()=>this.result(n),yield n}catch(s){s&&"name"in s&&"CancelError"!==s.name&&console.warn(s)}}}result(e){const t=this._makeSignal();return this.connector.get("feature_layer.feature.item_extent",{signal:t},{id:e.resourceId,fid:e.featureId}).then((t=>{const r=t.extent;return{text:e.text,extent:[r.minLon,r.minLat,r.maxLon,r.maxLat]}}))}async*reverse(e){throw new Error("Not implemented")}_makeSignal(){const e=new AbortController;return this._abortControllers.push(e),e.signal}_items({entries:e,query:t,config:r,resourceItem:n}){var s;const o=[];let i;n.feature_layer&&(i=null===(s=n.feature_layer.fields.find((e=>e.label_field)))||void 0===s?void 0:s.keyname);const c=this.searchResources.find((e=>{var t;return null!==(t=e.id)&&void 0!==t?t:e.resourceId===n.resource.id}));return c&&e.forEach((e=>{let s=i?e.fields[i]:e.id;r.renderSearch?s=r.renderSearch({item:e,resourceItem:n}):i&&(s=e.fields[i]),o.push({query:t,text:s,featureId:e.id,resourceId:n.resource.id,item:e,resourceItem:n})})),o}}ue.limit=300;class he extends y{constructor(e){super(e),this.searchUrl="https://nominatim.openstreetmap.org",this._requests=[]}abort(){this._requests.forEach((e=>e.cancel())),this._requests=[]}async*search(e){const t=f(`${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${e}`),r=new i(((r,n,s)=>{const o=new XMLHttpRequest;o.open("GET",t,!0),o.onload=()=>{try{const t=JSON.parse(o.responseText).features.map((t=>({geom:t,extent:t.bbox,text:t.properties&&t.properties.display_name,query:e})));r(t)}catch(t){n(t)}},o.onerror=e=>{n(e)},s((()=>{o.abort()})),o.send()})).catch((e=>{throw e}));this._requests.push(r);const n=await r;if(n)for(const s of n)s.result=()=>this.result(s),yield s}result(e){return i.resolve({text:e.text,extent:e.extent||[],geom:e.geom})}async*reverse(e){const[t,r]=e,n=f(`${this.searchUrl}/reverse?format=geojson&lat=${r}&lon=${t}`),s=new i(((e,s,o)=>{const i=new XMLHttpRequest;i.open("GET",n,!0),i.onload=()=>{try{const n=JSON.parse(i.responseText).features[0];e({geom:n,extent:n.bbox,text:n.properties&&n.properties.display_name,query:`${r}, ${t}`})}catch(n){s(n)}},i.onerror=e=>{s(e)},o((()=>{i.abort()})),i.send()})).catch((e=>{throw e}));this._requests.push(s);const o=await s;o&&(o.result=()=>this.result(o),yield o)}}function le(e){return new m(e)}export{y as BaseProvider,m as Geocoder,ue as NgwProvider,he as NominatimProvider,le as create};
1
+ class e extends Error{constructor(){super(),this.name="CancelError",Object.setPrototypeOf(this,e.prototype)}}class t{constructor(e={}){this.options=e,this._promises=new Map}get isLoaded(){return this._promises.size>0}remove(e){this._promises.has(e)&&(this._promises.delete(e),this._onStop())}get(e){return this._promises.get(e)}add(e,t){const r=t||e,n=this._promises.get(r);return this.options.onStart&&!this.isLoaded&&this.options.onStart(),n||(this._promises.set(r,e),e.finally((()=>{this.remove(r)})),e)}abort(){this.isLoaded&&(this._promises.forEach((e=>{e.cancel&&e.cancel()})),this._promises.clear(),this._onStop())}waitFunc(e,t=""){const r=this.get(t=t||e.name);return r||this.add(e(),t)}WaitForMe(e=""){const t=this.get.bind(this),r=this.add.bind(this);return function(n,s,o){const i=o.value;return e=e||s,o.value=function(...n){const s=t(e);if(s)return s;return r(i.apply(this,n),e)},o}}GetOrCreateDecorator(e=""){return this.WaitForMe(e)}_onStop(){this.options.onStop&&!this.isLoaded&&this.options.onStop()}}class r extends Error{constructor(){super(),this.name="TimeoutError",Object.setPrototypeOf(this,r.prototype)}}const n=(e,t,r,n)=>{try{e(r(n))}catch(s){t(s)}};let s=0;class o{constructor(t,n){this.id=s++,this._isCanceled=!1,this._isPending=!0,this._cancelHandlers=[],this._children=[],this._cancelPromise=new Promise(((t,r)=>{this._setCanceledCallback=r=>t(r||new e)}));const i=[this._cancelPromise,new Promise(((e,r)=>t((t=>{t instanceof o?this.attach(t):this._isPending=!1,e(t)}),(e=>{this._isPending=!1,r(e)}),(e=>{if(!this._isPending)throw new Error("The `onCancel` handler was attached after the promise settled.");this._cancelHandlers.push(e)}))))];n&&i.push(new Promise(((e,t)=>{setTimeout((()=>{if(this._isPending)try{this.cancel()}finally{t(new r)}}),n)}))),this._promise=Promise.race(i)}static createControl(e){return new t(e)}static resolve(e){return new o((t=>t(e)))}static reject(e){return new o(((t,r)=>r(e)))}static all(e){return new o(((t,r)=>{Promise.all(e).then(t).catch(r)})).catch((t=>{if(t instanceof this.CancelError)for(const r of e){"cancel"in r&&r.cancel()}throw t}))}attach(e){this._isCanceled?e.cancel():this._children.push(e)}then(e,t){const r=new o(((r,s)=>{if(this._promise){const o=e=>{t?n(r,s,t,e):s(e)};this._promise.then((t=>{this._isCanceled?o(t):e?n(r,s,e,t):r(t)}),o)}}));return r._parentPromise=this,this._children.push(r),r}catch(t){return this._isCanceled&&t&&t(new e),this.then(void 0,t)}finally(t){return this._promise?this._promise.finally(t):Promise.reject(this._isCanceled?new e:t)}cancel(){if(this._isCanceled||!this._isPending)return this;this._isCanceled=!0;const e=this._getTopParent();if(e&&e.cancel(),this._children&&this._children.forEach((e=>e.cancel())),this._isPending){if(this._cancelHandlers.length)try{for(const e of this._cancelHandlers)e()}catch(t){}this._setCanceledCallback&&this._setCanceledCallback()}return this._destroy(),this}_getTopParent(){let e=this._parentPromise,t=!!e;for(;t;)e&&e._parentPromise?(e=e._parentPromise,t=!!e):t=!1;return e}_destroy(){this._setCanceledCallback=void 0,this._cancelPromise=void 0,this._promise=void 0}}o.CancelError=e,o.TimeoutError=r,o.PromiseControl=t,Object.setPrototypeOf(o.prototype,Promise.prototype);var i=o;function c(e){return null!=e}function a(e){return"string"==typeof e?!!e:c(e)}function u(e,t,r,n){if(e instanceof Array)return t instanceof Array&&t.sort().join("")===e.sort().join("");if(e instanceof Date)return t instanceof Date&&""+e==""+t;if(e instanceof Function){if(!(t instanceof Function))return!1}else if(e instanceof Object)return t instanceof Object&&(e===r?t===n:h(e,t));return e===t}function h(e,t){const r=Object.keys(e).sort(),n=Object.keys(t).sort();if(r.length!==n.length)return!1;if(r.join("")!==n.join(""))return!1;for(let s=0;s<r.length;s++){if(!u(e[r[s]],t[n[s]],e,t))return!1}return!0}function l(e){const t={};return Object.keys(e).forEach((r=>{e[r]instanceof Array||e[r]!==Object(e[r])?void 0!==e[r]&&(t[r]=e[r]):t[r]=l(e[r])})),t}function f(e){return e.replace(/([^:]\/)\/+/g,"$1")}class p{constructor(e){e&&function(e,...t){for(const r of t)for(const t of Object.getOwnPropertyNames(r))e[t]=r[t]}(this,e)}}let d=0;class m extends p{constructor(e){super(e),this.providers=[],e&&e.providers&&(this.providers=e.providers)}abort(){this.providers.forEach((e=>{e.abort&&e.abort()}))}async*search(e){this.abort();let t=!0;const r=[];for(const s of this.providers)try{const r=s.search(e);for await(const e of r)t=!1,yield{...e,provider:s,_id:d++}}catch(n){"CancelError"!==n.name&&r.push(n)}if(t&&r.length)throw new Error(`All providers failed: ${r.map((e=>e.message)).join("; ")}`)}result(e){return e.provider?e.provider.result(e):i.resolve(void 0)}async*reverse(e){for(const r of this.providers)if(r.reverse)try{const t=r.reverse(e);for await(const e of t)yield{...e,provider:r,_id:d++}}catch(t){}}async reverseGeocodeFirstResult(e){for(const r of this.providers)if("function"==typeof r.reverse)try{for await(const t of r.reverse(e))return t}catch(t){console.error("Error in reverse geocoding:",t)}}}class y extends p{}var g,v={exports:{}},_="object"==typeof Reflect?Reflect:null,w=_&&"function"==typeof _.apply?_.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};g=_&&"function"==typeof _.ownKeys?_.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var b=Number.isNaN||function(e){return e!=e};function O(){O.init.call(this)}v.exports=O,v.exports.once=function(e,t){return new Promise((function(r,n){function s(r){e.removeListener(t,o),n(r)}function o(){"function"==typeof e.removeListener&&e.removeListener("error",s),r([].slice.call(arguments))}q(e,t,o,{once:!0}),"error"!==t&&function(e,t,r){"function"==typeof e.on&&q(e,"error",t,r)}(e,s,{once:!0})}))},O.EventEmitter=O,O.prototype._events=void 0,O.prototype._eventsCount=0,O.prototype._maxListeners=void 0;var x=10;function E(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function C(e){return void 0===e._maxListeners?O.defaultMaxListeners:e._maxListeners}function R(e,t,r,n){var s,o,i,c;if(E(r),void 0===(o=e._events)?(o=e._events=Object.create(null),e._eventsCount=0):(void 0!==o.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),o=e._events),i=o[t]),void 0===i)i=o[t]=r,++e._eventsCount;else if("function"==typeof i?i=o[t]=n?[r,i]:[i,r]:n?i.unshift(r):i.push(r),(s=C(e))>0&&i.length>s&&!i.warned){i.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=i.length,c=a,console&&console.warn&&console.warn(c)}return e}function L(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function P(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},s=L.bind(n);return s.listener=r,n.wrapFn=s,s}function j(e,t,r){var n=e._events;if(void 0===n)return[];var s=n[t];return void 0===s?[]:"function"==typeof s?r?[s.listener||s]:[s]:r?function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(s):k(s,s.length)}function I(e){var t=this._events;if(void 0!==t){var r=t[e];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function k(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function q(e,t,r,n){if("function"==typeof e.on)n.once?e.once(t,r):e.on(t,r);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function s(o){n.once&&e.removeEventListener(t,s),r(o)}))}}Object.defineProperty(O,"defaultMaxListeners",{enumerable:!0,get:function(){return x},set:function(e){if("number"!=typeof e||e<0||b(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");x=e}}),O.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},O.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||b(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},O.prototype.getMaxListeners=function(){return C(this)},O.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var n="error"===e,s=this._events;if(void 0!==s)n=n&&void 0===s.error;else if(!n)return!1;if(n){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var i=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw i.context=o,i}var c=s[e];if(void 0===c)return!1;if("function"==typeof c)w(c,this,t);else{var a=c.length,u=k(c,a);for(r=0;r<a;++r)w(u[r],this,t)}return!0},O.prototype.on=O.prototype.addListener=function(e,t){return R(this,e,t,!1)},O.prototype.prependListener=function(e,t){return R(this,e,t,!0)},O.prototype.once=function(e,t){return E(t),this.on(e,P(this,e,t)),this},O.prototype.prependOnceListener=function(e,t){return E(t),this.prependListener(e,P(this,e,t)),this},O.prototype.removeListener=function(e,t){var r,n,s,o,i;if(E(t),void 0===(n=this._events))return this;if(void 0===(r=n[e]))return this;if(r===t||r.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(s=-1,o=r.length-1;o>=0;o--)if(r[o]===t||r[o].listener===t){i=r[o].listener,s=o;break}if(s<0)return this;0===s?r.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(r,s),1===r.length&&(n[e]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",e,i||t)}return this},O.prototype.off=O.prototype.removeListener,O.prototype.removeAllListeners=function(e){var t,r,n;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete r[e]),this;if(0===arguments.length){var s,o=Object.keys(r);for(n=0;n<o.length;++n)"removeListener"!==(s=o[n])&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(void 0!==t)for(n=t.length-1;n>=0;n--)this.removeListener(e,t[n]);return this},O.prototype.listeners=function(e){return j(this,e,!0)},O.prototype.rawListeners=function(e){return j(this,e,!1)},O.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):I.call(e,t)},O.prototype.listenerCount=I,O.prototype.eventNames=function(){return this._eventsCount>0?g(this._events):[]};class T{constructor(e={}){var t;this.cache=[];const r=null!==(t=e.namespace)&&void 0!==t?t:"default";return T.instance[r]?T.instance[r]:(T.instance[r]=this,this)}clean(){this.cache.length=0}all(){return this.cache}addFull(e,t,r){return this.add(e,t,r,!0)}add(e,t,r,n){const s=this._find(e,r);if(s)return s.value;{let s;s=t instanceof Function?t():t;const o=r&&JSON.parse(JSON.stringify(l(r))),i={key:e,value:s,props:o,options:o};return n&&!a(s)?s:(this.cache.push(i),s instanceof Promise?(s.catch((t=>{throw this.delete(e,r),t})),n&&s.then((t=>(a(t)||this.delete(e,r),t))),s):s)}}match(e,t){const r=this._find(e,t);if(r)return r.value}matchAll(e,t){return e?this.cache.filter((r=>this._filter(r,e,t))).map((e=>e.value)):this.cache.map((e=>e.value))}delete(e,t){let r=[];"string"==typeof e?r=this.cache.filter((r=>this._filter(r,e,t))):r.push(e);for(const n of r){const e=this.cache.indexOf(n);this.cache.splice(e,1)}}_find(e,t){return this.cache.find((r=>this._filter(r,e,t)))}_filter(e,t,r){if(e.key===t){if(r){return h(e.props||e.options||{},l(r))}return!0}return!1}}T.instance={};var A=T;class S extends Error{constructor(e){super(),this.name="NetworkError",Object.setPrototypeOf(this,S.prototype),this.message=`Unable to request ${e}.\n Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`}}class F extends Error{constructor(e){super(),this.name="NgwError",Object.assign(this,e),Object.setPrototypeOf(this,F.prototype)}}function N(e){return"[object Object]"===Object.prototype.toString.call(e)}let U;U=(e,t,r={},n,s)=>{r.method=r.method||"GET";const o=new XMLHttpRequest;o.open(r.method||"GET",e,!0),"blob"===r.responseType&&(o.responseType=r.responseType);const i=()=>{try{return JSON.parse(o.responseText)}catch(e){return o.responseText}};o.onload=()=>{-1!==[401,403,404,422,500].indexOf(o.status)&&n(new F(i())),((e=!1)=>{const s=e?n:t;"blob"===r.responseType?s(o.response):o.responseText?s(i()):n({message:""})})()},o.onerror=t=>{n(0===o.status?new S(e):t)},o.upload.onprogress=function(e){if(e.lengthComputable){r.onProgress&&r.onProgress(e.loaded/e.total*100,e)}};const c=r.headers;if(c)for(const u in c){const e=c[u];"string"==typeof e&&o.setRequestHeader(u,e)}let a;if(void 0!==r.withCredentials&&(o.withCredentials=r.withCredentials),r.file){if(a=new FormData,a.append("file",r.file),r.data)for(const u in r.data)a.append(u,a[u])}else a=r.data?"string"==typeof r.data?r.data:JSON.stringify(r.data):null;s&&s((()=>{o.abort()})),o.send(a)};const $=/\{ *([\w_-]+) *\}/g;function M(e,t){return e.replace($,((e,r)=>{let n=t[r];if(void 0===n)throw new Error("No value provided for letiable "+e);return"function"==typeof n&&(n=n(t)),n}))}class H extends F{constructor(e){super(e),this.name="ResourceNotFoundError",this.exception="nextgisweb.resource.exception.ResourceNotFound",Object.setPrototypeOf(this,H.prototype)}}class B extends F{constructor(e){super(e),this.name="InsufficientPermissionsError",this.exception="nextgisweb.core.exception.InsufficientPermissions",Object.setPrototypeOf(this,B.prototype)}}const G=[];function D(e){G.push(e)}const z=["description"];function J(e,t=""){t=t?t+"__":"";const r={};for(const[n,s]of Object.entries(e))if(-1===z.indexOf(n))if(N(s))if("owner_user"===n){const e=J(s,n);Object.assign(r,e)}else"parent"===n&&"id"in s&&(r.parent_id=s.id);else c(s)&&(r[t+n]=s);return r}class Q{constructor(e){this.connector=e,this.cache=new A}getOne(e,t){const r=new A,n={},s={...t,cache:!1};"string"==typeof e?n.keyname=e:"number"==typeof e?n.id=e:N(e)&&(void 0!==e.id?n.id=e.id:e.keyname&&(n.keyname=e.keyname));return r.addFull("resource",(()=>"string"==typeof e?this._fetchResourceBy({keyname:e},s):"number"==typeof e?this._fetchResourceById(e,s):N(e)?this._fetchResourceBy(e,s):i.resolve(void 0)),n)}getOneOrFail(e,t){return this.getOne(e,t).then((e=>{if(e)return e;throw new H}))}getId(e,t){return"number"==typeof e?i.resolve(e):"string"==typeof e||N(e)?this.getOne(e,t).then((e=>{if(e)return e.resource.id})):i.resolve(void 0)}getIdOrFail(e,t){return this.getId(e,t).then((e=>{if(void 0===e)throw new Error;return e}))}getMany(e,t){return this._resourceCacheFilter(e).then((r=>{if(!r.length){const r={};return e.keyname?r.keyname=e.keyname:Object.assign(r,J(e)),this.connector.get("resource.search",t,{serialization:"full",...r}).then((e=>{if(e)for(const t of e)this.cache.add("resource.item",i.resolve(t),{id:t.resource.id});return e}))}return r}))}getParent(e,t){return this.getOne(e,t).then((e=>e?this.getOne(e.resource.parent.id,t):i.resolve(void 0)))}getChildrenOf(e,t){return this.getIdOrFail(e).then((e=>this._getChildrenOf(e,t)))}update(e,t){return this.getId(e).then((e=>{if(void 0!==e)return this.connector.put("resource.item",{data:t},{id:e})}))}delete(e){return this.getId(e).then((e=>{if(void 0!==e)return this.connector.delete("resource.item",null,{id:e}).then((()=>{this._cleanResourceItemCache(e)}))}))}_getChildrenOf(e,t,r=[]){return this.connector.get("resource.collection",{cache:!0,...t},{parent:e}).then((e=>{const n=[];for(const s of e)this.cache.add("resource.item",i.resolve(s),{id:s.resource.id}),r.push(s),(null==t?void 0:t.recursive)&&s.resource.children&&n.push(this._getChildrenOf(s.resource.id,t,r));return n.length?i.all(n).then((()=>r)):r}))}async _cleanResourceItemCache(e){const t=this.cache.all(),r=[];for(const n of t){const t=n.options&&n.options.id;if(["resource.item","resource"].includes(n.key)&&void 0!==t)if("number"==typeof t)t===e&&r.push(n);else{await this.getId(t)===e&&r.push(n)}}for(const n of r)this.cache.delete(n)}_fetchResourceById(e,t){return this.cache.add("resource.item",(()=>this.connector.get("resource.item",t,{id:e})),{id:e}).catch((e=>{if(!(e instanceof H))throw e}))}_fetchResourceBy(e,t){return this.getMany(e,t).then((e=>e[0]))}_resourceCacheFilter(e){return i.all(this.cache.matchAll("resource.item")).then((t=>(t.filter((t=>{if(t)return e.keyname&&t.resource.keyname?e.keyname===t.resource.keyname:c(e.id)&&c(t.resource.id)?e.id===t.resource.id:h(e,t.resource)})),[])))}}let W=0;class K{constructor(e){this.options=e,this.id=W++,this.emitter=new v.exports.EventEmitter,this.routeStr="/api/component/pyramid/route",this.activeRequests=[];const t=function(e){return G.find((t=>{if(t.options.baseUrl===e.baseUrl){if(!e.auth)return!0;if(t.options.auth)return h(t.options.auth,e.auth)}}))}(e);if(t)return t;this.options.route&&(this.routeStr=this.options.route),this.options.requestTransform&&(this.requestTransform=this.options.requestTransform),this.resources=new Q(this),D(this)}static create(e){return new this(e)}setRequestTransform(e){this.requestTransform=e}setNgw(e){this.logout(),this.options.baseUrl=e,D(this)}connect(){const e=new A,t=this.options.auth;return e.add("route",(()=>new i(((e,r)=>{const n=()=>this.makeQuery(this.routeStr,{},{}).then((t=>{e(t)})).catch((e=>{r(e)}));if(t){const{login:e,password:s}=t;if(e&&s)return this._login({login:e,password:s}).then((()=>n())).catch((e=>r(e)))}return n()}))),{id:this.id,auth:t,baseUrl:this.options.baseUrl})}login(e,t){return this.logout(),D(this),this._login(e,t)}logout(){this.abort(),function(e){const t=G.indexOf(e);-1!==t&&G.splice(t,1)}(this),this.options.auth=void 0,this.user=void 0,this.emitter.emit("logout"),this.resources.cache.clean()}getUserInfo(e,t){if(this.user&&this.user.id)return i.resolve(this.user);e&&(this.options.auth=e);const r={headers:this.getAuthorizationHeaders(e),...t};return this.makeQuery("/api/component/auth/current_user",{},r)}getAuthorizationHeaders(e){const t=this.makeClientId(e);if(t)return{Authorization:"Basic "+t}}makeClientId(e){if(e=e||this.options.auth){const{login:t,password:r}=e,n=unescape(encodeURIComponent(`${t}:${r}`));return window.btoa(n)}}abort(){for(const e of this.activeRequests)e.cancel();this.activeRequests=[]}getActiveApiRequests(){return[...this.activeRequests]}apiRequest(e,t={},r={}){var n,s;const{method:o,headers:c,withCredentials:a,responseType:u}=r,h=l(t=null!==(n=r.params)&&void 0!==n?n:t),f=()=>function(e){const t=e.params;return new i(((r,n)=>{e.connector.connect().then((s=>{let o=s&&s[e.name];if(o){o=[...o];let s=o.shift();if(o.length){const e={};for(let r=0;r<o.length;r++){const n=o[r];if(e[r]="{"+n+"}",void 0===t[n])throw new Error("`"+n+"` url api argument is not specified")}s&&(s=M(s,e))}if(t){const e=[],r=t.paramList;Array.isArray(r)&&(delete t.paramList,r.forEach((t=>{e.push(`${t[0]}=${t[1]}`)})));for(const n in t)-1===o.indexOf(n)&&e.push(`${n}=${t[n]}`);e.length&&(s=s+"?"+e.join("&"))}s?r(e.connector.makeQuery(s,t,e.requestOptions)):n(new Error("request url is not set"))}else r(void 0)})).catch((e=>{n(e)}))}))}({name:e,params:h,requestOptions:r,connector:this});if(r.cache&&"GET"===o){return(new A).add(e,f,{params:h,...l({headers:c,withCredentials:a,responseType:u,baseUrl:this.options.baseUrl,userId:null===(s=this.user)||void 0===s?void 0:s.id})})}return f()}post(e,t,r){return(t=t||{}).method="POST",this.apiRequest(e,r,t)}get(e,t,r){return(t=t||{}).method="GET",this.apiRequest(e,r,t)}patch(e,t,r){return(t=t||{}).method="PATCH",this.apiRequest(e,r,t)}put(e,t,r){return(t=t||{}).method="PUT",this.apiRequest(e,r,t)}delete(e,t,r){return(t=t||{}).method="DELETE",this.apiRequest(e,r,t)}makeQuery(e,t,r={}){if(e=(this.options.baseUrl?this.options.baseUrl:"")+e)return t&&(e=M(e,t)),e=encodeURI(f(e)),this._loadData(e,r);throw new Error("Empty `url` not allowed")}getResource(e,t){return this.resources.getOne(e,t)}getResourceOrFail(e,t){return this.resources.getOneOrFail(e,t)}getResourceBy(e){return this.resources.getOne(e)}getResourceByKeyname(e){return this.resources.getOne(e)}getResourceById(e){return this.resources.getOne(e)}getResourceId(e,t){return this.resources.getId(e,t)}getResourceIdOrFail(e,t){return this.resources.getIdOrFail(e,t)}getResourcesBy(e,t){return this.resources.getMany(e,t)}getResourceParent(e,t){return this.resources.getParent(e,t)}getResourceChildren(e,t){return this.resources.getChildrenOf(e,t)}updateResource(e,t){return this.resources.update(e,t)}deleteResource(e){return this.resources.delete(e)}_loadData(e,t){t.responseType=t.responseType||"json";const r=new i(((r,n,s)=>{if(this.user&&((t=t||{}).headers={...this.getAuthorizationHeaders(),...t.headers}),this.requestTransform){const[r,n]=this.requestTransform(e,t);e=r,t=n}U(e,r,t,n,s)})).then((e=>(this._cleanActiveRequests(r),e))).catch((e=>{if(this._cleanActiveRequests(r),e instanceof i.CancelError);else{const t=this._handleHttpError(e);if(t)throw t}}));return t.signal&&"function"==typeof t.signal.addEventListener&&t.signal.addEventListener("abort",(()=>{r.cancel(),this._cleanActiveRequests(r)})),this.activeRequests.push(r),r}_login(e,t){return this.getUserInfo(e,t).then((e=>(this.user=e,this.emitter.emit("login",e),e))).catch((e=>{throw this.emitter.emit("login:error",e),e}))}_cleanActiveRequests(e){const t=this.activeRequests.indexOf(e);-1!==t&&this.activeRequests.splice(t,1)}_handleHttpError(e){if(e&&e instanceof F){if("nextgisweb.resource.exception.ResourceNotFound"===e.exception)throw new H(e);if("nextgisweb.core.exception.InsufficientPermissions"===e.exception)throw new B(e)}return e}}K.errors={NgwError:F,ResourceNotFoundError:H};var X=K;function V(e,t,r){if((t=String(t))===(e=String(e)))return!0;if(r&&t.toUpperCase()===e.toUpperCase())return!0;const n=`^${s=t,s.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")}$`.replace(/%/g,".*").replace("_",".");var s;return null!==new RegExp(n,r?"i":"").exec(e)}const Y={gt:(e,t)=>e>t,lt:(e,t)=>e<t,ge:(e,t)=>e>=t,le:(e,t)=>e<=t,eq:(e,t)=>e===t,ne:(e,t)=>e!==t,in:(e,t)=>-1!==t.indexOf(e),notin:(e,t)=>-1===t.indexOf(e),like:(e,t)=>V(e,t),ilike:(e,t)=>V(e,t,!0)};function Z(e){return 3===e.length&&"string"==typeof e[0]&&"string"==typeof e[1]}function ee(e,t){const r="string"==typeof t[0]?t[0]:"all",n=t=>{if(Z(t)){const[r,n,s]=t,o=Y[n];if(o){if(("like"===n||"ilike"===n)&&"string"==typeof r){let t="";const n=r.replace(/^%?(\w+)%?$/,((n,o)=>(t=e[o],r.replace(o,s))));return o(t,n)}return o(e[r],s)}return!1}return ee(e,t)},s=t.filter((e=>Array.isArray(e)));return"any"===r?s.some(n):s.every(n)}const te={srs:4326,geom_format:"geojson"};function re(e){const t=se(e);return i.all(t).then((t=>{const r=[],n=[];for(const e of t)for(const t of e)r.includes(t.id)||(n.push(t),r.push(t.id));return e.offset||e.limit?n.splice(void 0!==e.offset?e.offset:0,void 0!==e.limit?e.limit:n.length):n}))}function ne(e){const[t,r,n]=e;let s="",o="";return[`${"id"!==t?"fld_":""}${String(t).trim().replace(/^(%?)(.+?)(%?)$/,((e,t,r,n)=>(s=t,o=n,r)))}__${r}`,s+n+o]}function se(e,t=[],r=[]){const{filters:n}=e,s="string"==typeof n[0]?n[0]:"all",o=n.filter((e=>Array.isArray(e)));if("any"===s)for(const i of o)Z(i)?t.push(ie({...e,paramList:[...r,ne(i)]})):se({...e,filters:i},t,[...r]);else if("all"===s){const n=[],s=[];for(const e of o)Z(e)?n.push(ne(e)):s.push(e);if(s.length)for(const o of s)se({...e,filters:o},t,[...r,...n]);else t.push(ie({...e,paramList:[...r,...n]}))}return t}function oe(e){return`POLYGON((${e.map((([e,t])=>{const[r,n]=function(e,t){t=t>85.06?85.06:t<-85.06?-85.06:t;const r=20037508.34*e/180;let n=Math.log(Math.tan((90+t)*Math.PI/360))/(Math.PI/180);return n=20037508.34*n/180,[r,n]}(e,t).map((e=>function(e,t){const r=t?Number("1e+"+t):1;return Math.round((e+Number.EPSILON)*r)/r}(e)));return r+" "+n})).join(", ")}))`}function ie(e){const t={...te},{limit:r,cache:n,signal:s,offset:o,orderBy:i,paramList:a,connector:u,geomFormat:h,intersects:l,resourceId:f}=e;if(r?r!==Number.POSITIVE_INFINITY&&(t.limit=r):t.limit=7e3,o&&(t.offset=o),h&&(t.geom_format=h),function(e,t){const{extensions:r,geom:n,fields:s,srs:o,ilike:i,like:a}=t;let u=r?r.join(","):"";"*"!==u&&(e.extensions=u),void 0!==s&&(e.fields=Array.isArray(s)?s.join(","):""),void 0!==n&&(e.geom=n?"yes":"no",n||(delete e.srs,delete e.geom_format)),c(i)?e.ilike=i:c(a)&&(e.like=a),c(o)&&(e.srs=o)}(t,e),i&&(t.order_by=i.join(",")),Array.isArray(l)){const e=(p=l,Array.isArray(p)&&4===p.length&&p.every((e=>"number"==typeof e))?function(e){const t=[e[0],e[1]];return[t,[e[2],e[1]],[e[2],e[3]],[e[0],e[3]],t]}(l):l);t.intersects=oe(e)}else"string"==typeof l&&(t.intersects=l);var p;a&&(t.paramList=a);const d={id:f,...t};return u.get("feature_layer.feature.collection",{cache:n,signal:s},d)}function ce(e){const t=e.filters;return t?re({...e,filters:t}).then((r=>{var n;return(null!==(n=e.clientFilterValidate)&&void 0!==n?n:ae(t))&&(r=r.filter((e=>ee(function(e){let t;for(t in e){const r=e[t];if("[object Object]"===Object.prototype.toString.call(r)){const n=r;if(c(n.year)&&c(n.month)&&c(n.day)){const r=[n.year,n.month-1,n.day];"hour"in n&&[n.hour,n.minute,n.second].forEach((e=>{r.push(e)})),e[t]=new Date(...r).toISOString()}}else"id"===t&&"string"==typeof r&&(e[t]=r.split(",").map(Number))}return e}({...e.fields,id:e.id}),t)))),r})):ie(e)}function ae(e){if("any"===e[0])return!0;for(let t=1;t<e.length;t++){const r=e[t];if("[object Array]"===Object.prototype.toString.call(r)){if(ae(r))return!0}}return!1}class ue extends y{constructor(e){var t;if(super(e),this.searchResources=[],this._abortControllers=[],!e.searchUrl&&!(null===(t=e.connectorOptions)||void 0===t?void 0:t.baseUrl))throw new Error("The `searchUrl` of `connectorOptions.baseUrl` are required");this.connector=e.connector||new X({baseUrl:this.searchUrl,...e.connectorOptions}),this.searchResources=e.searchResources}abort(){this._abortControllers.forEach((e=>{e.abort()})),this._abortControllers.length=0}async*search(e){var t,r;const n=this._makeSignal();for(const o of this.searchResources){if(n.aborted)break;const{searchMethod:i}=o,c=null!==(t=o.limit)&&void 0!==t?t:ue.limit,a=null!==(r=o.id)&&void 0!==r?r:o.resourceId;try{const t=await this.connector.getResourceOrFail(a,{cache:!0}),r={connector:this.connector,resourceId:a,signal:n,limit:c};"like"===i?r.like=e:r.ilike=e;const s=ce(r),u=await s;for(const n of this._items({entries:u,query:e,config:o,resourceItem:t}))n.result=()=>this.result(n),yield n}catch(s){s&&"name"in s&&"CancelError"!==s.name&&console.warn(s)}}}result(e){const t=this._makeSignal();return this.connector.get("feature_layer.feature.item_extent",{signal:t},{id:e.resourceId,fid:e.featureId}).then((t=>{const r=t.extent;return{text:e.text,extent:[r.minLon,r.minLat,r.maxLon,r.maxLat]}}))}async*reverse(e){throw new Error("Not implemented")}_makeSignal(){const e=new AbortController;return this._abortControllers.push(e),e.signal}_items({entries:e,query:t,config:r,resourceItem:n}){var s;const o=[];let i;n.feature_layer&&(i=null===(s=n.feature_layer.fields.find((e=>e.label_field)))||void 0===s?void 0:s.keyname);const c=this.searchResources.find((e=>{var t;return null!==(t=e.id)&&void 0!==t?t:e.resourceId===n.resource.id}));return c&&e.forEach((e=>{let s=i?e.fields[i]:e.id;r.renderSearch?s=r.renderSearch({item:e,resourceItem:n}):i&&(s=e.fields[i]),o.push({query:t,text:s,featureId:e.id,resourceId:n.resource.id,item:e,resourceItem:n})})),o}}ue.limit=300;class he extends y{constructor(e){super(e),this.searchUrl="https://nominatim.openstreetmap.org",this._requests=[]}abort(){this._requests.forEach((e=>e.cancel())),this._requests=[]}async*search(e){const t=f(`${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${e}`),r=new i(((r,n,s)=>{const o=new XMLHttpRequest;o.open("GET",t,!0),o.onload=()=>{try{const t=JSON.parse(o.responseText).features.map((t=>({geom:t,extent:t.bbox,text:t.properties&&t.properties.display_name,query:e})));r(t)}catch(t){n(t)}},o.onerror=e=>{n(e)},s((()=>{o.abort()})),o.send()})).catch((e=>{throw e}));this._requests.push(r);const n=await r;if(n)for(const s of n)s.result=()=>this.result(s),yield s}result(e){return i.resolve({text:e.text,extent:e.extent||[],geom:e.geom})}async*reverse(e){const[t,r]=e,n=f(`${this.searchUrl}/reverse?format=geojson&lat=${r}&lon=${t}`),s=new i(((e,s,o)=>{const i=new XMLHttpRequest;i.open("GET",n,!0),i.onload=()=>{try{const n=JSON.parse(i.responseText).features[0];e({geom:n,extent:n.bbox,text:n.properties&&n.properties.display_name,query:`${r}, ${t}`})}catch(n){s(n)}},i.onerror=e=>{s(e)},o((()=>{i.abort()})),i.send()})).catch((e=>{throw e}));this._requests.push(s);const o=await s;o&&(o.result=()=>this.result(o),yield o)}}function le(e){return new m(e)}export{y as BaseProvider,m as Geocoder,ue as NgwProvider,he as NominatimProvider,le as create};
2
2
  //# sourceMappingURL=geocoder.esm-browser.prod.js.map